lesgo 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Lesgo!
|
|
1
|
+
# Lesgo! Framework
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
[](https://coveralls.io/github/reflex-media/lesgo-framework?branch=master)
|
|
@@ -13,22 +13,22 @@ This framework uses Jest test framework for unit testing.
|
|
|
13
13
|
|
|
14
14
|
All test files exist in the respective `src/**/__tests__/*.test.ts` directory.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### Install dependencies
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
|
|
19
|
+
npm ci
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### Run test
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
|
|
25
|
+
npm test
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Run code coverage report
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
|
|
31
|
+
npm run coverage
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
View the generated html report in `coverage/index.html`.
|
|
@@ -40,4 +40,3 @@ Declare testing environment configurations in `jest.setup.ts` directory.
|
|
|
40
40
|
## Contributing
|
|
41
41
|
|
|
42
42
|
You may contribute to the core framework by submitting a PR to the `develop` branch. Refer to the official [Docs](https://reflex-media.github.io/lesgo-docs/stable/prologue/contribution-guide/) for more information.
|
|
43
|
-
|
|
@@ -42,5 +42,12 @@ export default class LoggerService {
|
|
|
42
42
|
};
|
|
43
43
|
refineMessagePerTransport(transportName: string, message: any): any;
|
|
44
44
|
getTransportByName(transportName: string): Transport | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Sanitizes an object for JSON serialization by:
|
|
47
|
+
* - Replacing functions with a string representation (similar to console.log behavior)
|
|
48
|
+
* - Handling circular references
|
|
49
|
+
* - Preserving other values
|
|
50
|
+
*/
|
|
51
|
+
sanitizeForJson(obj: any, seen?: WeakSet<object>): any;
|
|
45
52
|
}
|
|
46
53
|
export {};
|
|
@@ -58,7 +58,8 @@ export default class LoggerService {
|
|
|
58
58
|
if (!this.checkIsLogRequired('console', level)) return null;
|
|
59
59
|
const refinedMessage = this.refineMessagePerTransport('console', message);
|
|
60
60
|
const consoleFunc = level === 'notice' ? 'log' : level;
|
|
61
|
-
|
|
61
|
+
const sanitizedMessage = this.sanitizeForJson(refinedMessage);
|
|
62
|
+
return console[consoleFunc](JSON.stringify(sanitizedMessage));
|
|
62
63
|
}
|
|
63
64
|
checkIsLogRequired(transportName, level) {
|
|
64
65
|
const transport = this.getTransportByName(transportName);
|
|
@@ -117,4 +118,54 @@ export default class LoggerService {
|
|
|
117
118
|
transport => transport.logType === transportName
|
|
118
119
|
);
|
|
119
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Sanitizes an object for JSON serialization by:
|
|
123
|
+
* - Replacing functions with a string representation (similar to console.log behavior)
|
|
124
|
+
* - Handling circular references
|
|
125
|
+
* - Preserving other values
|
|
126
|
+
*/
|
|
127
|
+
sanitizeForJson(obj, seen = new WeakSet()) {
|
|
128
|
+
// Handle null and undefined
|
|
129
|
+
if (obj === null || obj === undefined) {
|
|
130
|
+
return obj;
|
|
131
|
+
}
|
|
132
|
+
// Handle functions - replace with string representation like console.log does
|
|
133
|
+
if (typeof obj === 'function') {
|
|
134
|
+
const funcName = obj.name || 'anonymous';
|
|
135
|
+
return `[Function: ${funcName}]`;
|
|
136
|
+
}
|
|
137
|
+
// Handle primitives
|
|
138
|
+
if (typeof obj !== 'object') {
|
|
139
|
+
return obj;
|
|
140
|
+
}
|
|
141
|
+
// Handle circular references
|
|
142
|
+
if (seen.has(obj)) {
|
|
143
|
+
return '[Circular]';
|
|
144
|
+
}
|
|
145
|
+
// Handle Date objects
|
|
146
|
+
if (obj instanceof Date) {
|
|
147
|
+
return obj.toISOString();
|
|
148
|
+
}
|
|
149
|
+
// Handle arrays
|
|
150
|
+
if (Array.isArray(obj)) {
|
|
151
|
+
seen.add(obj);
|
|
152
|
+
return obj.map(item => this.sanitizeForJson(item, seen));
|
|
153
|
+
}
|
|
154
|
+
// Handle objects
|
|
155
|
+
seen.add(obj);
|
|
156
|
+
const sanitized = {};
|
|
157
|
+
for (const key in obj) {
|
|
158
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
159
|
+
try {
|
|
160
|
+
sanitized[key] = this.sanitizeForJson(obj[key], seen);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
// If we can't serialize a property, replace it with error message
|
|
163
|
+
sanitized[key] = `[Error: ${
|
|
164
|
+
error instanceof Error ? error.message : 'Unknown error'
|
|
165
|
+
}]`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return sanitized;
|
|
170
|
+
}
|
|
120
171
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lesgo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Core framework for lesgo node.js serverless framework.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
"bin"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"pretest": "eslint 'src/**/*.{ts,tsx}'",
|
|
22
|
+
"pretest": "npm run type-check && eslint 'src/**/*.{ts,tsx}'",
|
|
23
23
|
"test": "jest",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
25
|
+
"type-check:watch": "tsc --noEmit --watch",
|
|
24
26
|
"coverage": "jest --coverage",
|
|
25
27
|
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
|
|
26
28
|
"lint": "eslint 'src/**/*.{ts,tsx}' --quiet",
|
|
@@ -28,6 +30,7 @@
|
|
|
28
30
|
"lint-fix": "eslint 'src/**/*.{js,ts,jsx,tsx}' --fix",
|
|
29
31
|
"format": "prettier --write 'dist/**/*.js'",
|
|
30
32
|
"build": "tsc && npm run format && npm run lint:dist",
|
|
33
|
+
"prepare": "husky install",
|
|
31
34
|
"prepublishOnly": "npm run build"
|
|
32
35
|
},
|
|
33
36
|
"bin": {
|
|
@@ -163,11 +166,6 @@
|
|
|
163
166
|
"require": "./dist/utils/cache/redis/index.js"
|
|
164
167
|
}
|
|
165
168
|
},
|
|
166
|
-
"husky": {
|
|
167
|
-
"hooks": {
|
|
168
|
-
"pre-commit": "lint-staged"
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
169
|
"lint-staged": {
|
|
172
170
|
"*.{js,ts,jsx,tsx}": [
|
|
173
171
|
"prettier --write",
|
|
@@ -180,7 +178,7 @@
|
|
|
180
178
|
"node": ">=20.17.0"
|
|
181
179
|
},
|
|
182
180
|
"peerDependencies": {
|
|
183
|
-
"serverless": "^
|
|
181
|
+
"serverless": "^4.0.0"
|
|
184
182
|
},
|
|
185
183
|
"sideEffects": false
|
|
186
184
|
}
|