@devrev/ts-adaas 1.11.1-beta.8 → 1.12.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/dist/common/install-initial-domain-mapping.d.ts.map +1 -1
- package/dist/common/install-initial-domain-mapping.js +1 -1
- package/dist/logger/logger.constants.d.ts +6 -0
- package/dist/logger/logger.constants.d.ts.map +1 -0
- package/dist/logger/logger.constants.js +13 -0
- package/dist/logger/logger.d.ts +70 -5
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -1
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +105 -33
- package/dist/logger/logger.test.js +427 -192
- package/dist/types/workers.d.ts +1 -0
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/workers/create-worker.d.ts.map +1 -1
- package/dist/workers/create-worker.js +2 -7
- package/dist/workers/spawn.d.ts +2 -2
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +31 -20
- package/dist/workers/worker.js +3 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-initial-domain-mapping.d.ts","sourceRoot":"","sources":["../../src/common/install-initial-domain-mapping.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,YAAY,EACnB,wBAAwB,EAAE,oBAAoB,GAC7C,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"install-initial-domain-mapping.d.ts","sourceRoot":"","sources":["../../src/common/install-initial-domain-mapping.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,YAAY,EACnB,wBAAwB,EAAE,oBAAoB,GAC7C,OAAO,CAAC,IAAI,CAAC,CA0Ff"}
|
|
@@ -54,5 +54,5 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
|
|
|
54
54
|
Authorization: devrevToken,
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
|
-
console.log(
|
|
57
|
+
console.log('Successfully installed initial domain mapping', initialDomainMappingInstallResponse.data);
|
|
58
58
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InspectOptions } from 'node:util';
|
|
2
|
+
export declare const MAX_LOG_STRING_LENGTH = 10000;
|
|
3
|
+
export declare const MAX_LOG_DEPTH = 10;
|
|
4
|
+
export declare const MAX_LOG_ARRAY_LENGTH = 100;
|
|
5
|
+
export declare const INSPECT_OPTIONS: InspectOptions;
|
|
6
|
+
//# sourceMappingURL=logger.constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.constants.d.ts","sourceRoot":"","sources":["../../src/logger/logger.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,eAAO,MAAM,eAAe,EAAE,cAM7B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INSPECT_OPTIONS = exports.MAX_LOG_ARRAY_LENGTH = exports.MAX_LOG_DEPTH = exports.MAX_LOG_STRING_LENGTH = void 0;
|
|
4
|
+
exports.MAX_LOG_STRING_LENGTH = 10000;
|
|
5
|
+
exports.MAX_LOG_DEPTH = 10;
|
|
6
|
+
exports.MAX_LOG_ARRAY_LENGTH = 100;
|
|
7
|
+
exports.INSPECT_OPTIONS = {
|
|
8
|
+
compact: false,
|
|
9
|
+
breakLength: Infinity,
|
|
10
|
+
depth: exports.MAX_LOG_DEPTH,
|
|
11
|
+
maxArrayLength: exports.MAX_LOG_ARRAY_LENGTH,
|
|
12
|
+
maxStringLength: exports.MAX_LOG_STRING_LENGTH,
|
|
13
|
+
};
|
package/dist/logger/logger.d.ts
CHANGED
|
@@ -1,23 +1,88 @@
|
|
|
1
|
-
import { Console } from 'node:console';
|
|
2
1
|
import { AxiosError } from 'axios';
|
|
2
|
+
import { Console } from 'node:console';
|
|
3
3
|
import { AxiosErrorResponse, LoggerFactoryInterface, LogLevel, PrintableState } from './logger.interfaces';
|
|
4
|
+
/**
|
|
5
|
+
* Custom logger that extends Node.js Console with context-aware logging.
|
|
6
|
+
* Handles local development, main thread, and worker thread logging differently.
|
|
7
|
+
*/
|
|
4
8
|
export declare class Logger extends Console {
|
|
5
9
|
private originalConsole;
|
|
6
10
|
private options?;
|
|
7
11
|
private tags;
|
|
8
12
|
constructor({ event, options }: LoggerFactoryInterface);
|
|
13
|
+
/**
|
|
14
|
+
* Converts any value to a string using `util.inspect()` for complex types.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The value to convert
|
|
17
|
+
* @returns String representation of the value
|
|
18
|
+
*/
|
|
9
19
|
private valueToString;
|
|
10
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Truncates a message if it exceeds the maximum allowed length.
|
|
22
|
+
* Adds a suffix indicating how many characters were omitted.
|
|
23
|
+
*
|
|
24
|
+
* @param message - The message to truncate
|
|
25
|
+
* @returns Truncated message or original if within limits
|
|
26
|
+
*/
|
|
27
|
+
private truncateMessage;
|
|
28
|
+
/**
|
|
29
|
+
* Logs a pre-formatted message string to the console.
|
|
30
|
+
* In production mode, wraps the message with JSON formatting and event context tags.
|
|
31
|
+
* In local development mode, logs the message directly without JSON wrapping.
|
|
32
|
+
* This is useful when you need to log already-stringified content.
|
|
33
|
+
*
|
|
34
|
+
* @param message - The pre-formatted message string to log
|
|
35
|
+
* @param level - Log level (info, warn, error)
|
|
36
|
+
*/
|
|
37
|
+
logFn(message: string, level: LogLevel): void;
|
|
38
|
+
/**
|
|
39
|
+
* Stringifies and logs arguments to the appropriate destination.
|
|
40
|
+
* On main thread, converts arguments to strings and calls logFn.
|
|
41
|
+
* In worker threads, forwards stringified arguments to the main thread for processing.
|
|
42
|
+
* All arguments are converted to strings using util.inspect and joined with spaces.
|
|
43
|
+
*
|
|
44
|
+
* @param args - Values to log (will be stringified and truncated if needed)
|
|
45
|
+
* @param level - Log level (info, warn, error)
|
|
46
|
+
*/
|
|
47
|
+
private stringifyAndLog;
|
|
11
48
|
log(...args: unknown[]): void;
|
|
12
49
|
info(...args: unknown[]): void;
|
|
13
50
|
warn(...args: unknown[]): void;
|
|
14
51
|
error(...args: unknown[]): void;
|
|
15
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts a state object into a printable format where arrays are summarized.
|
|
55
|
+
* Arrays show their length, first item, and last item instead of all elements.
|
|
56
|
+
* Objects are recursively processed and primitives are returned as-is.
|
|
57
|
+
*
|
|
58
|
+
* @param state - State object to convert
|
|
59
|
+
* @returns Printable representation with summarized arrays
|
|
60
|
+
*/
|
|
16
61
|
export declare function getPrintableState(state: Record<string, any>): PrintableState;
|
|
17
62
|
/**
|
|
18
|
-
*
|
|
63
|
+
* Serializes an error into a structured format.
|
|
64
|
+
* Automatically detects and formats Axios errors with HTTP details.
|
|
65
|
+
* Returns other error types as-is.
|
|
66
|
+
*
|
|
67
|
+
* @param error - Error to serialize
|
|
68
|
+
* @returns Serialized error or original if not an Axios error
|
|
69
|
+
*/
|
|
70
|
+
export declare function serializeError(error: unknown): unknown;
|
|
71
|
+
/**
|
|
72
|
+
* Serializes an Axios error into a structured format with HTTP request/response details.
|
|
73
|
+
* Extracts method, URL, parameters, status code, headers, and data.
|
|
74
|
+
* Includes CORS/network failure indicator when no response is available.
|
|
75
|
+
*
|
|
76
|
+
* @param error - Axios error to serialize
|
|
77
|
+
* @returns Structured object with error details
|
|
19
78
|
*/
|
|
20
|
-
export declare function formatAxiosError(error: AxiosError): object;
|
|
21
|
-
export declare const serializeError: (error: unknown) => unknown;
|
|
22
79
|
export declare function serializeAxiosError(error: AxiosError): AxiosErrorResponse;
|
|
80
|
+
/**
|
|
81
|
+
* Formats an Axios error to a printable format.
|
|
82
|
+
*
|
|
83
|
+
* @param error - Axios error to format
|
|
84
|
+
* @returns Formatted error object
|
|
85
|
+
* @deprecated Use {@link serializeAxiosError} instead
|
|
86
|
+
*/
|
|
87
|
+
export declare function formatAxiosError(error: AxiosError): object;
|
|
23
88
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQvC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,qBAAa,MAAO,SAAQ,OAAO;IACjC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,OAAO,CAAC,CAAuB;IACvC,OAAO,CAAC,IAAI,CAAa;gBAEb,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sBAAsB;IAUtD;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IASvB;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAa7C;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAcd,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI7B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAGzC;AAED;;;;;;;GAOG;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,cAAc,CAqB5E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKtD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RawAxiosResponseHeaders } from 'axios';
|
|
2
|
-
import { AirdropEvent } from '../types/extraction';
|
|
2
|
+
import { AirdropEvent, EventContext } from '../types/extraction';
|
|
3
3
|
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
4
|
export interface LoggerFactoryInterface {
|
|
5
5
|
event: AirdropEvent;
|
|
@@ -36,4 +36,7 @@ export interface AxiosErrorResponse {
|
|
|
36
36
|
code?: string;
|
|
37
37
|
message?: string;
|
|
38
38
|
}
|
|
39
|
+
export interface LoggerTags extends EventContext {
|
|
40
|
+
sdk_version: string;
|
|
41
|
+
}
|
|
39
42
|
//# sourceMappingURL=logger.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,CAAC,EAAE,GAAG,CAAC;IAEhB,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAE7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,cAAc,GAAG,cAAc,CAAC;CACtD;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAE3B,MAAM,EAAE,GAAG,CAAC;QACZ,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;KACzB,CAAC;IACF,YAAY,EAAE,OAAO,CAAC;IACtB,sBAAsB,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,uBAAuB,CAAC;QACjC,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/logger/logger.js
CHANGED
|
@@ -1,65 +1,121 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Logger = void 0;
|
|
4
4
|
exports.getPrintableState = getPrintableState;
|
|
5
|
-
exports.
|
|
5
|
+
exports.serializeError = serializeError;
|
|
6
6
|
exports.serializeAxiosError = serializeAxiosError;
|
|
7
|
+
exports.formatAxiosError = formatAxiosError;
|
|
8
|
+
const axios_1 = require("axios");
|
|
7
9
|
const node_console_1 = require("node:console");
|
|
8
10
|
const node_util_1 = require("node:util");
|
|
9
|
-
const
|
|
11
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
12
|
+
const constants_1 = require("../common/constants");
|
|
13
|
+
const workers_1 = require("../types/workers");
|
|
14
|
+
const logger_constants_1 = require("./logger.constants");
|
|
10
15
|
const logger_interfaces_1 = require("./logger.interfaces");
|
|
16
|
+
/**
|
|
17
|
+
* Custom logger that extends Node.js Console with context-aware logging.
|
|
18
|
+
* Handles local development, main thread, and worker thread logging differently.
|
|
19
|
+
*/
|
|
11
20
|
class Logger extends node_console_1.Console {
|
|
12
21
|
constructor({ event, options }) {
|
|
13
22
|
super(process.stdout, process.stderr);
|
|
14
23
|
this.originalConsole = console;
|
|
15
24
|
this.options = options;
|
|
16
|
-
this.tags = Object.assign(Object.assign({}, event.payload.event_context), {
|
|
25
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION });
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts any value to a string using `util.inspect()` for complex types.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The value to convert
|
|
31
|
+
* @returns String representation of the value
|
|
32
|
+
*/
|
|
18
33
|
valueToString(value) {
|
|
19
34
|
if (typeof value === 'string') {
|
|
20
35
|
return value;
|
|
21
36
|
}
|
|
22
|
-
|
|
23
|
-
return (0, node_util_1.inspect)(value, {
|
|
24
|
-
compact: true,
|
|
25
|
-
depth: Infinity,
|
|
26
|
-
maxArrayLength: Infinity,
|
|
27
|
-
maxStringLength: Infinity,
|
|
28
|
-
breakLength: Infinity,
|
|
29
|
-
});
|
|
37
|
+
return (0, node_util_1.inspect)(value, logger_constants_1.INSPECT_OPTIONS);
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Truncates a message if it exceeds the maximum allowed length.
|
|
41
|
+
* Adds a suffix indicating how many characters were omitted.
|
|
42
|
+
*
|
|
43
|
+
* @param message - The message to truncate
|
|
44
|
+
* @returns Truncated message or original if within limits
|
|
45
|
+
*/
|
|
46
|
+
truncateMessage(message) {
|
|
47
|
+
if (message.length > logger_constants_1.MAX_LOG_STRING_LENGTH) {
|
|
48
|
+
return `${message.substring(0, logger_constants_1.MAX_LOG_STRING_LENGTH)}... ${message.length - logger_constants_1.MAX_LOG_STRING_LENGTH} more characters`;
|
|
49
|
+
}
|
|
50
|
+
return message;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Logs a pre-formatted message string to the console.
|
|
54
|
+
* In production mode, wraps the message with JSON formatting and event context tags.
|
|
55
|
+
* In local development mode, logs the message directly without JSON wrapping.
|
|
56
|
+
* This is useful when you need to log already-stringified content.
|
|
57
|
+
*
|
|
58
|
+
* @param message - The pre-formatted message string to log
|
|
59
|
+
* @param level - Log level (info, warn, error)
|
|
60
|
+
*/
|
|
61
|
+
logFn(message, level) {
|
|
32
62
|
var _a;
|
|
33
63
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
34
|
-
this.originalConsole[level](
|
|
64
|
+
this.originalConsole[level](message);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const logObject = Object.assign({ message }, this.tags);
|
|
68
|
+
this.originalConsole[level](JSON.stringify(logObject));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stringifies and logs arguments to the appropriate destination.
|
|
72
|
+
* On main thread, converts arguments to strings and calls logFn.
|
|
73
|
+
* In worker threads, forwards stringified arguments to the main thread for processing.
|
|
74
|
+
* All arguments are converted to strings using util.inspect and joined with spaces.
|
|
75
|
+
*
|
|
76
|
+
* @param args - Values to log (will be stringified and truncated if needed)
|
|
77
|
+
* @param level - Log level (info, warn, error)
|
|
78
|
+
*/
|
|
79
|
+
stringifyAndLog(args, level) {
|
|
80
|
+
let stringifiedArgs = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
81
|
+
stringifiedArgs = this.truncateMessage(stringifiedArgs);
|
|
82
|
+
if (node_worker_threads_1.isMainThread) {
|
|
83
|
+
this.logFn(stringifiedArgs, level);
|
|
35
84
|
}
|
|
36
85
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
86
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
87
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
88
|
+
payload: { stringifiedArgs, level },
|
|
89
|
+
});
|
|
40
90
|
}
|
|
41
91
|
}
|
|
42
92
|
log(...args) {
|
|
43
|
-
this.
|
|
93
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.INFO);
|
|
44
94
|
}
|
|
45
95
|
info(...args) {
|
|
46
|
-
this.
|
|
96
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.INFO);
|
|
47
97
|
}
|
|
48
98
|
warn(...args) {
|
|
49
|
-
this.
|
|
99
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.WARN);
|
|
50
100
|
}
|
|
51
101
|
error(...args) {
|
|
52
|
-
this.
|
|
102
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.ERROR);
|
|
53
103
|
}
|
|
54
104
|
}
|
|
55
105
|
exports.Logger = Logger;
|
|
56
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Converts a state object into a printable format where arrays are summarized.
|
|
108
|
+
* Arrays show their length, first item, and last item instead of all elements.
|
|
109
|
+
* Objects are recursively processed and primitives are returned as-is.
|
|
110
|
+
*
|
|
111
|
+
* @param state - State object to convert
|
|
112
|
+
* @returns Printable representation with summarized arrays
|
|
113
|
+
*/
|
|
57
114
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
115
|
function getPrintableState(state) {
|
|
59
116
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
117
|
function processValue(value) {
|
|
61
118
|
if (Array.isArray(value)) {
|
|
62
|
-
// If the value is an array, summarize it
|
|
63
119
|
return {
|
|
64
120
|
type: 'array',
|
|
65
121
|
length: value.length,
|
|
@@ -68,32 +124,38 @@ function getPrintableState(state) {
|
|
|
68
124
|
};
|
|
69
125
|
}
|
|
70
126
|
else if (typeof value === 'object' && value !== null) {
|
|
71
|
-
// If the value is an object, recursively process its properties
|
|
72
127
|
const processedObject = {};
|
|
73
128
|
for (const key in value) {
|
|
74
129
|
processedObject[key] = processValue(value[key]);
|
|
75
130
|
}
|
|
76
131
|
return processedObject;
|
|
77
132
|
}
|
|
78
|
-
// For primitive types, return the value as is
|
|
79
133
|
return value;
|
|
80
134
|
}
|
|
81
|
-
// Process the state object directly since it's guaranteed to be an object
|
|
82
135
|
return processValue(state);
|
|
83
136
|
}
|
|
84
137
|
/**
|
|
85
|
-
*
|
|
138
|
+
* Serializes an error into a structured format.
|
|
139
|
+
* Automatically detects and formats Axios errors with HTTP details.
|
|
140
|
+
* Returns other error types as-is.
|
|
141
|
+
*
|
|
142
|
+
* @param error - Error to serialize
|
|
143
|
+
* @returns Serialized error or original if not an Axios error
|
|
86
144
|
*/
|
|
87
|
-
function
|
|
88
|
-
return serializeAxiosError(error);
|
|
89
|
-
}
|
|
90
|
-
const serializeError = (error) => {
|
|
145
|
+
function serializeError(error) {
|
|
91
146
|
if ((0, axios_1.isAxiosError)(error)) {
|
|
92
147
|
return serializeAxiosError(error);
|
|
93
148
|
}
|
|
94
149
|
return error;
|
|
95
|
-
}
|
|
96
|
-
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Serializes an Axios error into a structured format with HTTP request/response details.
|
|
153
|
+
* Extracts method, URL, parameters, status code, headers, and data.
|
|
154
|
+
* Includes CORS/network failure indicator when no response is available.
|
|
155
|
+
*
|
|
156
|
+
* @param error - Axios error to serialize
|
|
157
|
+
* @returns Structured object with error details
|
|
158
|
+
*/
|
|
97
159
|
function serializeAxiosError(error) {
|
|
98
160
|
var _a, _b, _c;
|
|
99
161
|
const serializedAxiosError = {
|
|
@@ -119,3 +181,13 @@ function serializeAxiosError(error) {
|
|
|
119
181
|
}
|
|
120
182
|
return serializedAxiosError;
|
|
121
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Formats an Axios error to a printable format.
|
|
186
|
+
*
|
|
187
|
+
* @param error - Axios error to format
|
|
188
|
+
* @returns Formatted error object
|
|
189
|
+
* @deprecated Use {@link serializeAxiosError} instead
|
|
190
|
+
*/
|
|
191
|
+
function formatAxiosError(error) {
|
|
192
|
+
return serializeAxiosError(error);
|
|
193
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_util_1 = require("node:util");
|
|
4
|
+
const constants_1 = require("../common/constants");
|
|
4
5
|
const test_helpers_1 = require("../tests/test-helpers");
|
|
5
6
|
const extraction_1 = require("../types/extraction");
|
|
6
7
|
const logger_1 = require("./logger");
|
|
8
|
+
const logger_constants_1 = require("./logger.constants");
|
|
7
9
|
// Mock console methods
|
|
8
10
|
const mockConsoleInfo = jest.spyOn(console, 'info').mockImplementation();
|
|
9
11
|
const mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
|
|
10
12
|
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
|
|
11
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
12
13
|
// Mock worker_threads
|
|
13
14
|
jest.mock('node:worker_threads', () => ({
|
|
14
15
|
isMainThread: true,
|
|
@@ -45,210 +46,444 @@ describe(logger_1.Logger.name, () => {
|
|
|
45
46
|
afterAll(() => {
|
|
46
47
|
jest.restoreAllMocks();
|
|
47
48
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
49
|
+
it('should initialize with event context and SDK version in tags', () => {
|
|
50
|
+
// Arrange & Act
|
|
51
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
52
|
+
// Assert
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
const tags = logger.tags;
|
|
55
|
+
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION }));
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
logger.info(message);
|
|
66
|
-
const expectedLogObject = Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
67
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(expectedLogObject));
|
|
68
|
-
});
|
|
69
|
-
it('should log single object message with JSON stringify', () => {
|
|
70
|
-
const data = { id: 123, name: 'test' };
|
|
71
|
-
logger.info(data);
|
|
72
|
-
const expectedMessage = (0, node_util_1.inspect)(data, {
|
|
73
|
-
compact: true,
|
|
74
|
-
depth: Infinity,
|
|
75
|
-
maxArrayLength: Infinity,
|
|
76
|
-
maxStringLength: Infinity,
|
|
77
|
-
breakLength: Infinity,
|
|
78
|
-
});
|
|
79
|
-
const expectedLogObject = Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
80
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(expectedLogObject));
|
|
81
|
-
});
|
|
82
|
-
it('should log multiple arguments joined with space', () => {
|
|
83
|
-
const text = 'Successfully fetched';
|
|
84
|
-
const data = { count: 42 };
|
|
85
|
-
logger.info(text, data);
|
|
86
|
-
const expectedDataMessage = (0, node_util_1.inspect)(data, {
|
|
87
|
-
compact: true,
|
|
88
|
-
depth: Infinity,
|
|
89
|
-
maxArrayLength: Infinity,
|
|
90
|
-
maxStringLength: Infinity,
|
|
91
|
-
breakLength: Infinity,
|
|
92
|
-
});
|
|
93
|
-
const expectedLogObject = Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
94
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(expectedLogObject));
|
|
95
|
-
});
|
|
96
|
-
it('should handle mixed string and object arguments', () => {
|
|
97
|
-
const text1 = 'Processing';
|
|
98
|
-
const data = { id: 123 };
|
|
99
|
-
const text2 = 'completed';
|
|
100
|
-
logger.info(text1, data, text2);
|
|
101
|
-
const expectedDataMessage = (0, node_util_1.inspect)(data, {
|
|
102
|
-
compact: true,
|
|
103
|
-
depth: Infinity,
|
|
104
|
-
maxArrayLength: Infinity,
|
|
105
|
-
maxStringLength: Infinity,
|
|
106
|
-
breakLength: Infinity,
|
|
107
|
-
});
|
|
108
|
-
const expectedLogObject = Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
109
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(expectedLogObject));
|
|
110
|
-
});
|
|
57
|
+
it('should log string message as JSON with event context tags in production mode', () => {
|
|
58
|
+
// Arrange
|
|
59
|
+
const message = 'Worker is online. Started processing the task.';
|
|
60
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
61
|
+
// Act
|
|
62
|
+
logger.info(message);
|
|
63
|
+
// Assert
|
|
64
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
111
65
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
logger.info(message, data);
|
|
122
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(message, data);
|
|
123
|
-
});
|
|
66
|
+
it('should log object message using inspect with proper formatting in production mode', () => {
|
|
67
|
+
// Arrange
|
|
68
|
+
const data = { id: 123, name: 'test' };
|
|
69
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
70
|
+
const expectedMessage = (0, node_util_1.inspect)(data, logger_constants_1.INSPECT_OPTIONS);
|
|
71
|
+
// Act
|
|
72
|
+
logger.info(data);
|
|
73
|
+
// Assert
|
|
74
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
124
75
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
it('should call console.warn for warn level', () => {
|
|
136
|
-
logger.warn('test warning');
|
|
137
|
-
expect(mockConsoleWarn).toHaveBeenCalled();
|
|
138
|
-
});
|
|
139
|
-
it('should call console.error for error level', () => {
|
|
140
|
-
logger.error('test error');
|
|
141
|
-
expect(mockConsoleError).toHaveBeenCalled();
|
|
142
|
-
});
|
|
143
|
-
it('should call console.info for log level', () => {
|
|
144
|
-
logger.log('test log');
|
|
145
|
-
expect(mockConsoleInfo).toHaveBeenCalled();
|
|
146
|
-
});
|
|
76
|
+
it('should join multiple arguments with space when logging in production mode', () => {
|
|
77
|
+
// Arrange
|
|
78
|
+
const text = 'Successfully fetched';
|
|
79
|
+
const data = { count: 42 };
|
|
80
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
81
|
+
const expectedDataMessage = (0, node_util_1.inspect)(data, logger_constants_1.INSPECT_OPTIONS);
|
|
82
|
+
// Act
|
|
83
|
+
logger.info(text, data);
|
|
84
|
+
// Assert
|
|
85
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
147
86
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
87
|
+
it('should log mixed string and object arguments joined with spaces in production mode', () => {
|
|
88
|
+
// Arrange
|
|
89
|
+
const text1 = 'Processing';
|
|
90
|
+
const data = { id: 123 };
|
|
91
|
+
const text2 = 'completed';
|
|
92
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
93
|
+
const expectedDataMessage = (0, node_util_1.inspect)(data, logger_constants_1.INSPECT_OPTIONS);
|
|
94
|
+
// Act
|
|
95
|
+
logger.info(text1, data, text2);
|
|
96
|
+
// Assert
|
|
97
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
98
|
+
});
|
|
99
|
+
it('should log directly without JSON wrapping in local development mode', () => {
|
|
100
|
+
// Arrange
|
|
101
|
+
const message = 'Test message';
|
|
102
|
+
const data = { test: true };
|
|
103
|
+
mockOptions.isLocalDevelopment = true;
|
|
104
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
105
|
+
const expectedDataMessage = (0, node_util_1.inspect)(data, logger_constants_1.INSPECT_OPTIONS);
|
|
106
|
+
// Act
|
|
107
|
+
logger.info(message, data);
|
|
108
|
+
// Assert
|
|
109
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(`${message} ${expectedDataMessage}`);
|
|
110
|
+
});
|
|
111
|
+
it('should truncate long strings and show remaining character count', () => {
|
|
112
|
+
// Arrange
|
|
113
|
+
const longString = 'C'.repeat(20000);
|
|
114
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
115
|
+
const expectedTruncatedMessage = `${longString.substring(0, logger_constants_1.MAX_LOG_STRING_LENGTH)}... ${20000 - logger_constants_1.MAX_LOG_STRING_LENGTH} more characters`;
|
|
116
|
+
// Act
|
|
117
|
+
logger.info(longString);
|
|
118
|
+
// Assert
|
|
119
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
120
|
+
const logObject = JSON.parse(callArgs);
|
|
121
|
+
expect(logObject.message).toBe(expectedTruncatedMessage);
|
|
122
|
+
});
|
|
123
|
+
it('should not truncate strings shorter than maximum length', () => {
|
|
124
|
+
// Arrange
|
|
125
|
+
const shortString = 'Short message';
|
|
126
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
127
|
+
// Act
|
|
128
|
+
logger.info(shortString);
|
|
129
|
+
// Assert
|
|
130
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
131
|
+
const logObject = JSON.parse(callArgs);
|
|
132
|
+
expect(logObject.message).toBe(shortString);
|
|
133
|
+
});
|
|
134
|
+
it('[edge] should not truncate message exactly at maximum length', () => {
|
|
135
|
+
// Arrange
|
|
136
|
+
const messageAtLimit = 'A'.repeat(logger_constants_1.MAX_LOG_STRING_LENGTH);
|
|
137
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
138
|
+
// Act
|
|
139
|
+
logger.info(messageAtLimit);
|
|
140
|
+
// Assert
|
|
141
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
142
|
+
const logObject = JSON.parse(callArgs);
|
|
143
|
+
expect(logObject.message).toBe(messageAtLimit);
|
|
144
|
+
expect(logObject.message.length).toBe(logger_constants_1.MAX_LOG_STRING_LENGTH);
|
|
145
|
+
});
|
|
146
|
+
it('[edge] should truncate message one character over maximum length', () => {
|
|
147
|
+
// Arrange
|
|
148
|
+
const messageOverLimit = 'B'.repeat(logger_constants_1.MAX_LOG_STRING_LENGTH + 1);
|
|
149
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
150
|
+
const expectedMessage = `${messageOverLimit.substring(0, logger_constants_1.MAX_LOG_STRING_LENGTH)}... 1 more characters`;
|
|
151
|
+
// Act
|
|
152
|
+
logger.info(messageOverLimit);
|
|
153
|
+
// Assert
|
|
154
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
155
|
+
const logObject = JSON.parse(callArgs);
|
|
156
|
+
expect(logObject.message).toBe(expectedMessage);
|
|
157
|
+
});
|
|
158
|
+
it('[edge] should handle empty string without truncation', () => {
|
|
159
|
+
// Arrange
|
|
160
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
161
|
+
// Act
|
|
162
|
+
logger.info('');
|
|
163
|
+
// Assert
|
|
164
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
165
|
+
const logObject = JSON.parse(callArgs);
|
|
166
|
+
expect(logObject.message).toBe('');
|
|
167
|
+
});
|
|
168
|
+
it('[edge] should show correct character count for very long messages', () => {
|
|
169
|
+
// Arrange
|
|
170
|
+
const veryLongString = 'X'.repeat(50000);
|
|
171
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
172
|
+
const expectedCharactersRemaining = 50000 - logger_constants_1.MAX_LOG_STRING_LENGTH;
|
|
173
|
+
const expectedMessage = `${veryLongString.substring(0, logger_constants_1.MAX_LOG_STRING_LENGTH)}... ${expectedCharactersRemaining} more characters`;
|
|
174
|
+
// Act
|
|
175
|
+
logger.info(veryLongString);
|
|
176
|
+
// Assert
|
|
177
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
178
|
+
const logObject = JSON.parse(callArgs);
|
|
179
|
+
expect(logObject.message).toBe(expectedMessage);
|
|
180
|
+
expect(logObject.message).toContain('40000 more characters');
|
|
181
|
+
});
|
|
182
|
+
it('should stringify string arguments and join them with spaces', () => {
|
|
183
|
+
// Arrange
|
|
184
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
185
|
+
// Act
|
|
186
|
+
logger.info('Message 1', 'Message 2');
|
|
187
|
+
// Assert
|
|
188
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
189
|
+
const logObject = JSON.parse(callArgs);
|
|
190
|
+
expect(logObject.message).toBe('Message 1 Message 2');
|
|
191
|
+
});
|
|
192
|
+
it('should stringify object arguments using util.inspect', () => {
|
|
193
|
+
// Arrange
|
|
194
|
+
const data = { id: 123 };
|
|
195
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
196
|
+
const expectedMessage = (0, node_util_1.inspect)(data, logger_constants_1.INSPECT_OPTIONS);
|
|
197
|
+
// Act
|
|
198
|
+
logger.info(data);
|
|
199
|
+
// Assert
|
|
200
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
201
|
+
const logObject = JSON.parse(callArgs);
|
|
202
|
+
expect(logObject.message).toBe(expectedMessage);
|
|
203
|
+
});
|
|
204
|
+
it('should call info method for log level', () => {
|
|
205
|
+
// Arrange
|
|
206
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
207
|
+
// Act
|
|
208
|
+
logger.log('test log');
|
|
209
|
+
// Assert
|
|
210
|
+
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
211
|
+
});
|
|
212
|
+
it('should call info method for info level', () => {
|
|
213
|
+
// Arrange
|
|
214
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
215
|
+
// Act
|
|
216
|
+
logger.info('test info');
|
|
217
|
+
// Assert
|
|
218
|
+
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
219
|
+
});
|
|
220
|
+
it('should call warn method for warn level', () => {
|
|
221
|
+
// Arrange
|
|
222
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
223
|
+
// Act
|
|
224
|
+
logger.warn('test warning');
|
|
225
|
+
// Assert
|
|
226
|
+
expect(mockConsoleWarn).toHaveBeenCalledTimes(1);
|
|
227
|
+
});
|
|
228
|
+
it('should call error method for error level', () => {
|
|
229
|
+
// Arrange
|
|
230
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
231
|
+
// Act
|
|
232
|
+
logger.error('test error');
|
|
233
|
+
// Assert
|
|
234
|
+
expect(mockConsoleError).toHaveBeenCalledTimes(1);
|
|
235
|
+
});
|
|
236
|
+
it('[edge] should log empty string as valid message with tags', () => {
|
|
237
|
+
// Arrange
|
|
238
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
239
|
+
// Act
|
|
240
|
+
logger.info('');
|
|
241
|
+
// Assert
|
|
242
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
243
|
+
const logObject = JSON.parse(callArgs);
|
|
244
|
+
expect(logObject.message).toBe('');
|
|
245
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
246
|
+
});
|
|
247
|
+
it('[edge] should handle null and undefined values in log arguments', () => {
|
|
248
|
+
// Arrange
|
|
249
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
250
|
+
// Act
|
|
251
|
+
logger.info('test', null, undefined);
|
|
252
|
+
// Assert
|
|
253
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
254
|
+
const logObject = JSON.parse(callArgs);
|
|
255
|
+
expect(logObject.message).toBe('test null undefined');
|
|
256
|
+
});
|
|
257
|
+
it('[edge] should handle deeply nested objects with inspect', () => {
|
|
258
|
+
// Arrange
|
|
259
|
+
const complexObject = {
|
|
260
|
+
level1: {
|
|
261
|
+
level2: {
|
|
262
|
+
array: [1, 2, 3],
|
|
263
|
+
string: 'nested',
|
|
179
264
|
},
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
});
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
268
|
+
const expectedMessage = (0, node_util_1.inspect)(complexObject, logger_constants_1.INSPECT_OPTIONS);
|
|
269
|
+
// Act
|
|
270
|
+
logger.info(complexObject);
|
|
271
|
+
// Assert
|
|
272
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
273
|
+
const logObject = JSON.parse(callArgs);
|
|
274
|
+
expect(logObject.message).toBe(expectedMessage);
|
|
275
|
+
});
|
|
276
|
+
it('[edge] should handle circular references in objects', () => {
|
|
277
|
+
// Arrange
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
+
const circularObject = { name: 'test' };
|
|
280
|
+
circularObject.self = circularObject;
|
|
281
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
282
|
+
// Act & Assert
|
|
283
|
+
expect(() => logger.info(circularObject)).not.toThrow();
|
|
284
|
+
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
197
285
|
});
|
|
198
286
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
type: 'array',
|
|
213
|
-
length: 1000,
|
|
214
|
-
firstItem: 0,
|
|
215
|
-
lastItem: 999,
|
|
216
|
-
},
|
|
217
|
-
nested_object: {
|
|
218
|
-
nested_key: 'nested_value',
|
|
219
|
-
nested_array: {
|
|
287
|
+
describe(logger_1.getPrintableState.name, () => {
|
|
288
|
+
it('should convert arrays to summary objects with type, length, and boundary items', () => {
|
|
289
|
+
// Arrange
|
|
290
|
+
const state = {
|
|
291
|
+
test_key: 'test_value',
|
|
292
|
+
big_array: Array.from({ length: 1000 }, (_, index) => index),
|
|
293
|
+
};
|
|
294
|
+
// Act
|
|
295
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
296
|
+
// Assert
|
|
297
|
+
expect(printableState).toEqual({
|
|
298
|
+
test_key: 'test_value',
|
|
299
|
+
big_array: {
|
|
220
300
|
type: 'array',
|
|
221
301
|
length: 1000,
|
|
222
302
|
firstItem: 0,
|
|
223
303
|
lastItem: 999,
|
|
224
304
|
},
|
|
225
|
-
}
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
it('should recursively process nested objects and arrays', () => {
|
|
308
|
+
// Arrange
|
|
309
|
+
const state = {
|
|
310
|
+
test_key: 'test_value',
|
|
311
|
+
nested_object: {
|
|
312
|
+
nested_key: 'nested_value',
|
|
313
|
+
nested_array: Array.from({ length: 1000 }, (_, index) => index),
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
// Act
|
|
317
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
318
|
+
// Assert
|
|
319
|
+
expect(printableState).toEqual({
|
|
320
|
+
test_key: 'test_value',
|
|
321
|
+
nested_object: {
|
|
322
|
+
nested_key: 'nested_value',
|
|
323
|
+
nested_array: {
|
|
324
|
+
type: 'array',
|
|
325
|
+
length: 1000,
|
|
326
|
+
firstItem: 0,
|
|
327
|
+
lastItem: 999,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
it('should preserve primitive values without modification', () => {
|
|
333
|
+
// Arrange
|
|
334
|
+
const state = {
|
|
335
|
+
string_key: 'string_value',
|
|
336
|
+
number_key: 42,
|
|
337
|
+
boolean_key: true,
|
|
338
|
+
null_key: null,
|
|
339
|
+
};
|
|
340
|
+
// Act
|
|
341
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
342
|
+
// Assert
|
|
343
|
+
expect(printableState).toEqual(state);
|
|
344
|
+
});
|
|
345
|
+
it('[edge] should handle empty arrays with no first or last items', () => {
|
|
346
|
+
// Arrange
|
|
347
|
+
const state = {
|
|
348
|
+
empty_array: [],
|
|
349
|
+
};
|
|
350
|
+
// Act
|
|
351
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
352
|
+
// Assert
|
|
353
|
+
expect(printableState).toEqual({
|
|
354
|
+
empty_array: {
|
|
355
|
+
type: 'array',
|
|
356
|
+
length: 0,
|
|
357
|
+
firstItem: undefined,
|
|
358
|
+
lastItem: undefined,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
it('[edge] should handle single-item arrays with same first and last item', () => {
|
|
363
|
+
// Arrange
|
|
364
|
+
const state = {
|
|
365
|
+
single_item_array: [42],
|
|
366
|
+
};
|
|
367
|
+
// Act
|
|
368
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
369
|
+
// Assert
|
|
370
|
+
expect(printableState).toEqual({
|
|
371
|
+
single_item_array: {
|
|
372
|
+
type: 'array',
|
|
373
|
+
length: 1,
|
|
374
|
+
firstItem: 42,
|
|
375
|
+
lastItem: undefined,
|
|
376
|
+
},
|
|
377
|
+
});
|
|
226
378
|
});
|
|
227
379
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
380
|
+
describe(logger_1.serializeAxiosError.name, () => {
|
|
381
|
+
it('should serialize Axios error with response data', () => {
|
|
382
|
+
// Arrange
|
|
383
|
+
const error = {
|
|
384
|
+
response: {
|
|
385
|
+
status: 500,
|
|
386
|
+
statusText: 'Internal Server Error',
|
|
387
|
+
data: 'Internal server error',
|
|
388
|
+
headers: { 'content-type': 'application/json' },
|
|
389
|
+
},
|
|
390
|
+
config: {
|
|
391
|
+
method: 'GET',
|
|
392
|
+
url: '/api/test',
|
|
393
|
+
params: { id: 123 },
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
// Act
|
|
397
|
+
const formattedError = (0, logger_1.serializeAxiosError)(error);
|
|
398
|
+
// Assert
|
|
399
|
+
expect(formattedError).toEqual({
|
|
400
|
+
config: {
|
|
401
|
+
method: 'GET',
|
|
402
|
+
params: { id: 123 },
|
|
403
|
+
url: '/api/test',
|
|
404
|
+
},
|
|
405
|
+
isAxiosError: true,
|
|
406
|
+
isCorsOrNoNetworkError: false,
|
|
407
|
+
response: {
|
|
408
|
+
data: 'Internal server error',
|
|
409
|
+
headers: { 'content-type': 'application/json' },
|
|
410
|
+
status: 500,
|
|
411
|
+
statusText: 'Internal Server Error',
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
it('should serialize Axios error without response as CORS or network error', () => {
|
|
416
|
+
// Arrange
|
|
417
|
+
const error = {
|
|
418
|
+
code: 'ERR_NETWORK',
|
|
419
|
+
message: 'Network Error',
|
|
420
|
+
config: {
|
|
421
|
+
method: 'POST',
|
|
422
|
+
url: '/api/create',
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
// Act
|
|
426
|
+
const formattedError = (0, logger_1.serializeAxiosError)(error);
|
|
427
|
+
// Assert
|
|
428
|
+
expect(formattedError).toEqual({
|
|
429
|
+
config: {
|
|
430
|
+
method: 'POST',
|
|
431
|
+
params: undefined,
|
|
432
|
+
url: '/api/create',
|
|
433
|
+
},
|
|
434
|
+
isAxiosError: true,
|
|
435
|
+
isCorsOrNoNetworkError: true,
|
|
436
|
+
code: 'ERR_NETWORK',
|
|
437
|
+
message: 'Network Error',
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
it('[edge] should handle Axios error with minimal config information', () => {
|
|
441
|
+
// Arrange
|
|
442
|
+
const error = {
|
|
443
|
+
response: {
|
|
444
|
+
status: 404,
|
|
445
|
+
data: 'Not Found',
|
|
446
|
+
},
|
|
447
|
+
config: {},
|
|
448
|
+
};
|
|
449
|
+
// Act
|
|
450
|
+
const formattedError = (0, logger_1.serializeAxiosError)(error);
|
|
451
|
+
// Assert
|
|
452
|
+
expect(formattedError).toEqual({
|
|
453
|
+
config: {
|
|
454
|
+
method: undefined,
|
|
455
|
+
params: undefined,
|
|
456
|
+
url: undefined,
|
|
457
|
+
},
|
|
458
|
+
isAxiosError: true,
|
|
459
|
+
isCorsOrNoNetworkError: false,
|
|
460
|
+
response: {
|
|
461
|
+
data: 'Not Found',
|
|
462
|
+
headers: undefined,
|
|
463
|
+
status: 404,
|
|
464
|
+
statusText: undefined,
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
it('[edge] should handle Axios error with no config', () => {
|
|
469
|
+
// Arrange
|
|
470
|
+
const error = {
|
|
471
|
+
code: 'ERR_TIMEOUT',
|
|
472
|
+
message: 'Request timeout',
|
|
473
|
+
};
|
|
474
|
+
// Act
|
|
475
|
+
const formattedError = (0, logger_1.serializeAxiosError)(error);
|
|
476
|
+
// Assert
|
|
477
|
+
expect(formattedError).toEqual({
|
|
478
|
+
config: {
|
|
479
|
+
method: undefined,
|
|
480
|
+
params: undefined,
|
|
481
|
+
url: undefined,
|
|
482
|
+
},
|
|
483
|
+
isAxiosError: true,
|
|
484
|
+
isCorsOrNoNetworkError: true,
|
|
485
|
+
code: 'ERR_TIMEOUT',
|
|
486
|
+
message: 'Request timeout',
|
|
487
|
+
});
|
|
253
488
|
});
|
|
254
489
|
});
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CAAC,cAAc;IACpD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CAAC,cAAc;IACpD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACnD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB,CAAC,cAAc;IACnD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CAAC,cAAc;IAClD,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CACxC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB,CAAC,cAAc;IAClD,IAAI,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,SAAS,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E;AAED;;GAEG;AACH,oBAAY,WAAW;IACrB,aAAa,YAAY;IACzB,YAAY,WAAW;IACvB,WAAW,UAAU;IACrB,UAAU,SAAS;CACpB;AAED;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,oBAAoB,SAAS;IAC7B,iBAAiB,SAAS;IAC1B,gBAAgB,QAAQ;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;IACnD,OAAO,EAAE;QACP,SAAS,EAAE,kBAAkB,GAAG,eAAe,CAAC;KACjD,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,oBAAoB,CAAC,iBAAiB,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,cAAc;IACxC,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAE3D,iBAAe,YAAY,CAAC,cAAc,EACxC,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -2,26 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createWorker = createWorker;
|
|
4
4
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
5
|
-
const logger_1 = require("../logger/logger");
|
|
6
5
|
const workers_1 = require("../types/workers");
|
|
7
6
|
async function createWorker(workerData) {
|
|
8
7
|
return new Promise((resolve, reject) => {
|
|
9
8
|
if (node_worker_threads_1.isMainThread) {
|
|
10
|
-
const logger = new logger_1.Logger({
|
|
11
|
-
event: workerData.event,
|
|
12
|
-
options: workerData.options,
|
|
13
|
-
});
|
|
14
9
|
const workerFile = __dirname + '/worker.js';
|
|
15
10
|
const worker = new node_worker_threads_1.Worker(workerFile, {
|
|
16
11
|
workerData,
|
|
17
12
|
});
|
|
18
13
|
worker.on(workers_1.WorkerEvent.WorkerError, (error) => {
|
|
19
|
-
|
|
14
|
+
console.error('Worker error', error);
|
|
20
15
|
reject(error);
|
|
21
16
|
});
|
|
22
17
|
worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
|
|
23
18
|
resolve(worker);
|
|
24
|
-
|
|
19
|
+
console.info('Worker is online. Started processing the task with event type: ' +
|
|
25
20
|
workerData.event.payload.event_type +
|
|
26
21
|
'.');
|
|
27
22
|
});
|
package/dist/workers/spawn.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export declare class Spawn {
|
|
|
19
19
|
private softTimeoutTimer;
|
|
20
20
|
private hardTimeoutTimer;
|
|
21
21
|
private memoryMonitoringInterval;
|
|
22
|
-
private logger;
|
|
23
22
|
private resolve;
|
|
24
|
-
|
|
23
|
+
private originalConsole;
|
|
24
|
+
constructor({ event, worker, options, resolve, originalConsole, }: SpawnInterface);
|
|
25
25
|
private clearTimeouts;
|
|
26
26
|
private exitFromMainThread;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAyEvD;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,wBAAwB,CAA6C;IAC7E,OAAO,CAAC,OAAO,CAA4C;IAC3D,OAAO,CAAC,eAAe,CAAU;gBACrB,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,cAAc;IA+FjB,OAAO,CAAC,aAAa;YAYP,kBAAkB;CAiCjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -72,19 +72,21 @@ function getWorkerPath({ event, connectorWorkerPath, }) {
|
|
|
72
72
|
* @returns {Promise<Spawn>} - A new instance of Spawn class
|
|
73
73
|
*/
|
|
74
74
|
async function spawn({ event, initialState, workerPath, initialDomainMapping, options, }) {
|
|
75
|
-
const logger = new logger_1.Logger({ event, options });
|
|
76
|
-
const script = getWorkerPath({
|
|
77
|
-
event,
|
|
78
|
-
connectorWorkerPath: workerPath,
|
|
79
|
-
});
|
|
80
75
|
if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
|
|
81
|
-
|
|
76
|
+
console.log('Snap-in is running in local development mode.');
|
|
82
77
|
}
|
|
83
78
|
// read the command line arguments to check if the local flag is passed
|
|
84
79
|
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
|
|
85
80
|
if (argv._.includes('local')) {
|
|
86
81
|
options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
|
|
87
82
|
}
|
|
83
|
+
const originalConsole = console;
|
|
84
|
+
// eslint-disable-next-line no-global-assign
|
|
85
|
+
console = new logger_1.Logger({ event, options });
|
|
86
|
+
const script = getWorkerPath({
|
|
87
|
+
event,
|
|
88
|
+
connectorWorkerPath: workerPath,
|
|
89
|
+
});
|
|
88
90
|
if (script) {
|
|
89
91
|
try {
|
|
90
92
|
const worker = await (0, create_worker_1.createWorker)({
|
|
@@ -100,16 +102,19 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
100
102
|
worker,
|
|
101
103
|
options,
|
|
102
104
|
resolve,
|
|
105
|
+
originalConsole,
|
|
103
106
|
});
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
catch (error) {
|
|
107
|
-
|
|
110
|
+
console.error('Worker error while processing task', error);
|
|
111
|
+
// eslint-disable-next-line no-global-assign
|
|
112
|
+
console = originalConsole;
|
|
108
113
|
return Promise.reject(error);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
else {
|
|
112
|
-
|
|
117
|
+
console.error('Script was not found for event type: ' + event.payload.event_type + '.');
|
|
113
118
|
try {
|
|
114
119
|
await (0, control_protocol_1.emit)({
|
|
115
120
|
event,
|
|
@@ -124,25 +129,28 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
131
|
catch (error) {
|
|
127
|
-
|
|
132
|
+
console.error('Error while emitting event.', (0, logger_1.serializeError)(error));
|
|
128
133
|
return Promise.reject(error);
|
|
129
134
|
}
|
|
135
|
+
finally {
|
|
136
|
+
// eslint-disable-next-line no-global-assign
|
|
137
|
+
console = originalConsole;
|
|
138
|
+
}
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
class Spawn {
|
|
133
|
-
constructor({ event, worker, options, resolve }) {
|
|
142
|
+
constructor({ event, worker, options, resolve, originalConsole, }) {
|
|
134
143
|
this.defaultLambdaTimeout = constants_1.DEFAULT_LAMBDA_TIMEOUT;
|
|
144
|
+
this.originalConsole = originalConsole || console;
|
|
135
145
|
this.alreadyEmitted = false;
|
|
136
146
|
this.event = event;
|
|
137
|
-
this.logger = new logger_1.Logger({ event, options });
|
|
138
147
|
this.lambdaTimeout = (options === null || options === void 0 ? void 0 : options.timeout)
|
|
139
148
|
? Math.min(options.timeout, this.defaultLambdaTimeout)
|
|
140
149
|
: this.defaultLambdaTimeout;
|
|
141
150
|
this.resolve = resolve;
|
|
142
|
-
console.log('Event in main thread', event);
|
|
143
151
|
// If soft timeout is reached, send a message to the worker to gracefully exit.
|
|
144
152
|
this.softTimeoutTimer = setTimeout(() => void (async () => {
|
|
145
|
-
|
|
153
|
+
console.log('SOFT TIMEOUT: Sending a message to the worker to gracefully exit.');
|
|
146
154
|
if (worker) {
|
|
147
155
|
worker.postMessage({
|
|
148
156
|
subject: workers_1.WorkerMessageSubject.WorkerMessageExit,
|
|
@@ -155,7 +163,7 @@ class Spawn {
|
|
|
155
163
|
})(), this.lambdaTimeout);
|
|
156
164
|
// If hard timeout is reached, that means the worker did not exit in time. Terminate the worker.
|
|
157
165
|
this.hardTimeoutTimer = setTimeout(() => void (async () => {
|
|
158
|
-
|
|
166
|
+
console.error('HARD TIMEOUT: Worker did not exit in time. Terminating the worker.');
|
|
159
167
|
if (worker) {
|
|
160
168
|
await worker.terminate();
|
|
161
169
|
}
|
|
@@ -167,7 +175,7 @@ class Spawn {
|
|
|
167
175
|
// If worker exits with process.exit(code), clear the timeouts and exit from
|
|
168
176
|
// main thread.
|
|
169
177
|
worker.on(workers_1.WorkerEvent.WorkerExit, (code) => void (async () => {
|
|
170
|
-
|
|
178
|
+
console.info('Worker exited with exit code: ' + code + '.');
|
|
171
179
|
this.clearTimeouts();
|
|
172
180
|
await this.exitFromMainThread();
|
|
173
181
|
})());
|
|
@@ -176,13 +184,14 @@ class Spawn {
|
|
|
176
184
|
// Since it is not possible to log from the worker thread, we need to log
|
|
177
185
|
// from the main thread.
|
|
178
186
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
179
|
-
const
|
|
187
|
+
const stringifiedArgs = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.stringifiedArgs;
|
|
180
188
|
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
181
|
-
|
|
189
|
+
// Args are already sanitized in the worker thread, skip double sanitization
|
|
190
|
+
console.logFn(stringifiedArgs, level);
|
|
182
191
|
}
|
|
183
192
|
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
184
193
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
185
|
-
|
|
194
|
+
console.info('Worker has emitted message to ADaaS.');
|
|
186
195
|
this.alreadyEmitted = true;
|
|
187
196
|
}
|
|
188
197
|
});
|
|
@@ -191,12 +200,12 @@ class Spawn {
|
|
|
191
200
|
try {
|
|
192
201
|
const memoryInfo = (0, helpers_2.getMemoryUsage)();
|
|
193
202
|
if (memoryInfo) {
|
|
194
|
-
|
|
203
|
+
console.info(memoryInfo.formattedMessage);
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
206
|
catch (error) {
|
|
198
207
|
// If memory monitoring fails, log the warning and clear the interval to prevent further issues
|
|
199
|
-
|
|
208
|
+
console.warn('Memory monitoring failed, stopping logging of memory usage interval', error);
|
|
200
209
|
if (this.memoryMonitoringInterval) {
|
|
201
210
|
clearInterval(this.memoryMonitoringInterval);
|
|
202
211
|
this.memoryMonitoringInterval = undefined;
|
|
@@ -217,6 +226,8 @@ class Spawn {
|
|
|
217
226
|
}
|
|
218
227
|
async exitFromMainThread() {
|
|
219
228
|
this.clearTimeouts();
|
|
229
|
+
// eslint-disable-next-line no-global-assign
|
|
230
|
+
console = this.originalConsole;
|
|
220
231
|
if (this.alreadyEmitted) {
|
|
221
232
|
this.resolve();
|
|
222
233
|
return;
|
package/dist/workers/worker.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { workerData } = require('worker_threads');
|
|
3
3
|
require('ts-node').register();
|
|
4
|
+
const { Logger } = require('../logger/logger');
|
|
5
|
+
// eslint-disable-next-line no-global-assign
|
|
6
|
+
console = new Logger({ event: workerData.event, options: workerData.options });
|
|
4
7
|
require(workerData.workerPath);
|