@devrev/ts-adaas 1.12.2 → 1.12.3-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/logger/logger.context.d.ts +5 -0
- package/dist/logger/logger.context.d.ts.map +1 -0
- package/dist/logger/logger.context.js +27 -0
- package/dist/logger/logger.d.ts +6 -1
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -3
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +22 -6
- package/dist/logger/logger.test.js +71 -10
- package/dist/logger/logger.worker-fixture.d.ts +2 -0
- package/dist/logger/logger.worker-fixture.d.ts.map +1 -0
- package/dist/logger/logger.worker-fixture.js +10 -0
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.js +3 -2
- package/dist/tests/backwards-compatibility/backwards-compatibility.test.js +17 -2
- package/dist/types/workers.d.ts +13 -1
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/workers/process-task.d.ts.map +1 -1
- package/dist/workers/process-task.js +37 -34
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +4 -2
- package/dist/workers/worker-adapter.d.ts.map +1 -1
- package/dist/workers/worker-adapter.js +2 -2
- package/dist/workers/worker-adapter.test.js +7 -0
- package/dist/workers/worker.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function ensureSdkLogContext(defaultValue?: boolean): void;
|
|
2
|
+
export declare function runWithUserLogContext<T>(fn: () => T): T;
|
|
3
|
+
export declare function runWithSdkLogContext<T>(fn: () => T): T;
|
|
4
|
+
export declare function getSdkLogContextValue(defaultValue: boolean): boolean;
|
|
5
|
+
//# sourceMappingURL=logger.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.context.d.ts","sourceRoot":"","sources":["../../src/logger/logger.context.ts"],"names":[],"mappings":"AAIA,wBAAgB,mBAAmB,CAAC,YAAY,UAAO,GAAG,IAAI,CAK7D;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEvD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtD;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAMpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureSdkLogContext = ensureSdkLogContext;
|
|
4
|
+
exports.runWithUserLogContext = runWithUserLogContext;
|
|
5
|
+
exports.runWithSdkLogContext = runWithSdkLogContext;
|
|
6
|
+
exports.getSdkLogContextValue = getSdkLogContextValue;
|
|
7
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
8
|
+
const sdkLogContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
9
|
+
function ensureSdkLogContext(defaultValue = true) {
|
|
10
|
+
const storeValue = sdkLogContext.getStore();
|
|
11
|
+
if (typeof storeValue !== 'boolean') {
|
|
12
|
+
sdkLogContext.enterWith(defaultValue);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function runWithUserLogContext(fn) {
|
|
16
|
+
return sdkLogContext.run(false, fn);
|
|
17
|
+
}
|
|
18
|
+
function runWithSdkLogContext(fn) {
|
|
19
|
+
return sdkLogContext.run(true, fn);
|
|
20
|
+
}
|
|
21
|
+
function getSdkLogContextValue(defaultValue) {
|
|
22
|
+
const storeValue = sdkLogContext.getStore();
|
|
23
|
+
if (typeof storeValue === 'boolean') {
|
|
24
|
+
return storeValue;
|
|
25
|
+
}
|
|
26
|
+
return defaultValue;
|
|
27
|
+
}
|
package/dist/logger/logger.d.ts
CHANGED
|
@@ -33,8 +33,9 @@ export declare class Logger extends Console {
|
|
|
33
33
|
*
|
|
34
34
|
* @param message - The pre-formatted message string to log
|
|
35
35
|
* @param level - Log level (info, warn, error)
|
|
36
|
+
* @param sdkLog - Flag indicating if the log originated from the SDK
|
|
36
37
|
*/
|
|
37
|
-
logFn(message: string, level: LogLevel): void;
|
|
38
|
+
logFn(message: string, level: LogLevel, sdkLog?: boolean): void;
|
|
38
39
|
/**
|
|
39
40
|
* Stringifies and logs arguments to the appropriate destination.
|
|
40
41
|
* On main thread, converts arguments to strings and calls logFn.
|
|
@@ -49,6 +50,10 @@ export declare class Logger extends Console {
|
|
|
49
50
|
info(...args: unknown[]): void;
|
|
50
51
|
warn(...args: unknown[]): void;
|
|
51
52
|
error(...args: unknown[]): void;
|
|
53
|
+
sdkInfo(...args: unknown[]): void;
|
|
54
|
+
sdkWarn(...args: unknown[]): void;
|
|
55
|
+
sdkError(...args: unknown[]): void;
|
|
56
|
+
private getSdkLogFlag;
|
|
52
57
|
}
|
|
53
58
|
/**
|
|
54
59
|
* Converts a state object into a printable format where arrays are summarized.
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AASvC,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,EAA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import { WorkerAdapterOptions } from '../types/workers';
|
|
1
|
+
import type { RawAxiosResponseHeaders } from 'axios';
|
|
2
|
+
import type { AirdropEvent, EventContext } from '../types/extraction';
|
|
3
|
+
import type { WorkerAdapterOptions } from '../types/workers';
|
|
4
4
|
export interface LoggerFactoryInterface {
|
|
5
5
|
event: AirdropEvent;
|
|
6
6
|
options?: WorkerAdapterOptions;
|
|
@@ -38,5 +38,6 @@ export interface AxiosErrorResponse {
|
|
|
38
38
|
}
|
|
39
39
|
export interface LoggerTags extends EventContext {
|
|
40
40
|
sdk_version: string;
|
|
41
|
+
sdk_log: boolean;
|
|
41
42
|
}
|
|
42
43
|
//# 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;
|
|
1
|
+
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,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;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/logger/logger.js
CHANGED
|
@@ -12,6 +12,7 @@ const node_worker_threads_1 = require("node:worker_threads");
|
|
|
12
12
|
const constants_1 = require("../common/constants");
|
|
13
13
|
const workers_1 = require("../types/workers");
|
|
14
14
|
const logger_constants_1 = require("./logger.constants");
|
|
15
|
+
const logger_context_1 = require("./logger.context");
|
|
15
16
|
const logger_interfaces_1 = require("./logger.interfaces");
|
|
16
17
|
/**
|
|
17
18
|
* Custom logger that extends Node.js Console with context-aware logging.
|
|
@@ -20,9 +21,10 @@ const logger_interfaces_1 = require("./logger.interfaces");
|
|
|
20
21
|
class Logger extends node_console_1.Console {
|
|
21
22
|
constructor({ event, options }) {
|
|
22
23
|
super(process.stdout, process.stderr);
|
|
24
|
+
(0, logger_context_1.ensureSdkLogContext)();
|
|
23
25
|
this.originalConsole = console;
|
|
24
26
|
this.options = options;
|
|
25
|
-
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION });
|
|
27
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true });
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Converts any value to a string using `util.inspect()` for complex types.
|
|
@@ -57,14 +59,15 @@ class Logger extends node_console_1.Console {
|
|
|
57
59
|
*
|
|
58
60
|
* @param message - The pre-formatted message string to log
|
|
59
61
|
* @param level - Log level (info, warn, error)
|
|
62
|
+
* @param sdkLog - Flag indicating if the log originated from the SDK
|
|
60
63
|
*/
|
|
61
|
-
logFn(message, level) {
|
|
64
|
+
logFn(message, level, sdkLog = this.getSdkLogFlag()) {
|
|
62
65
|
var _a;
|
|
63
66
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
64
67
|
this.originalConsole[level](message);
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
|
-
const logObject = Object.assign({ message }, this.tags);
|
|
70
|
+
const logObject = Object.assign(Object.assign({ message }, this.tags), { sdk_log: sdkLog });
|
|
68
71
|
this.originalConsole[level](JSON.stringify(logObject));
|
|
69
72
|
}
|
|
70
73
|
/**
|
|
@@ -76,16 +79,17 @@ class Logger extends node_console_1.Console {
|
|
|
76
79
|
* @param args - Values to log (will be stringified and truncated if needed)
|
|
77
80
|
* @param level - Log level (info, warn, error)
|
|
78
81
|
*/
|
|
79
|
-
stringifyAndLog(args, level) {
|
|
82
|
+
stringifyAndLog(args, level, sdkOverride) {
|
|
80
83
|
let stringifiedArgs = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
81
84
|
stringifiedArgs = this.truncateMessage(stringifiedArgs);
|
|
85
|
+
const sdkLogFlag = typeof sdkOverride === 'boolean' ? sdkOverride : this.getSdkLogFlag();
|
|
82
86
|
if (node_worker_threads_1.isMainThread) {
|
|
83
|
-
this.logFn(stringifiedArgs, level);
|
|
87
|
+
this.logFn(stringifiedArgs, level, sdkLogFlag);
|
|
84
88
|
}
|
|
85
89
|
else {
|
|
86
90
|
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
87
91
|
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
88
|
-
payload: { stringifiedArgs, level },
|
|
92
|
+
payload: { stringifiedArgs, level, sdk_log: sdkLogFlag },
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
95
|
}
|
|
@@ -101,6 +105,18 @@ class Logger extends node_console_1.Console {
|
|
|
101
105
|
error(...args) {
|
|
102
106
|
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.ERROR);
|
|
103
107
|
}
|
|
108
|
+
sdkInfo(...args) {
|
|
109
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.INFO, true);
|
|
110
|
+
}
|
|
111
|
+
sdkWarn(...args) {
|
|
112
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.WARN, true);
|
|
113
|
+
}
|
|
114
|
+
sdkError(...args) {
|
|
115
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.ERROR, true);
|
|
116
|
+
}
|
|
117
|
+
getSdkLogFlag() {
|
|
118
|
+
return (0, logger_context_1.getSdkLogContextValue)(this.tags.sdk_log);
|
|
119
|
+
}
|
|
104
120
|
}
|
|
105
121
|
exports.Logger = Logger;
|
|
106
122
|
/**
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
3
7
|
const node_util_1 = require("node:util");
|
|
8
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
4
9
|
const constants_1 = require("../common/constants");
|
|
5
10
|
const test_helpers_1 = require("../tests/test-helpers");
|
|
6
11
|
const extraction_1 = require("../types/extraction");
|
|
12
|
+
const workers_1 = require("../types/workers");
|
|
7
13
|
const logger_1 = require("./logger");
|
|
8
14
|
const logger_constants_1 = require("./logger.constants");
|
|
15
|
+
const logger_interfaces_1 = require("./logger.interfaces");
|
|
9
16
|
// Mock console methods
|
|
10
17
|
const mockConsoleInfo = jest.spyOn(console, 'info').mockImplementation();
|
|
11
18
|
const mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
|
|
12
19
|
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
|
|
13
|
-
// Mock worker_threads
|
|
14
|
-
jest.mock('node:worker_threads', () =>
|
|
15
|
-
|
|
16
|
-
parentPort: null
|
|
17
|
-
})
|
|
20
|
+
// Mock worker_threads for main-thread specific behavior but keep actual Worker implementation
|
|
21
|
+
jest.mock('node:worker_threads', () => {
|
|
22
|
+
const actual = jest.requireActual('node:worker_threads');
|
|
23
|
+
return Object.assign(Object.assign({}, actual), { isMainThread: true, parentPort: null });
|
|
24
|
+
});
|
|
18
25
|
describe(logger_1.Logger.name, () => {
|
|
19
26
|
let mockEvent;
|
|
20
27
|
let mockOptions;
|
|
@@ -52,7 +59,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
52
59
|
// Assert
|
|
53
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
61
|
const tags = logger.tags;
|
|
55
|
-
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION }));
|
|
62
|
+
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true }));
|
|
56
63
|
});
|
|
57
64
|
it('should log string message as JSON with event context tags in production mode', () => {
|
|
58
65
|
// Arrange
|
|
@@ -61,7 +68,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
61
68
|
// Act
|
|
62
69
|
logger.info(message);
|
|
63
70
|
// Assert
|
|
64
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
71
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true })));
|
|
65
72
|
});
|
|
66
73
|
it('should log object message using inspect with proper formatting in production mode', () => {
|
|
67
74
|
// Arrange
|
|
@@ -71,7 +78,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
71
78
|
// Act
|
|
72
79
|
logger.info(data);
|
|
73
80
|
// Assert
|
|
74
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
81
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true })));
|
|
75
82
|
});
|
|
76
83
|
it('should join multiple arguments with space when logging in production mode', () => {
|
|
77
84
|
// Arrange
|
|
@@ -82,7 +89,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
82
89
|
// Act
|
|
83
90
|
logger.info(text, data);
|
|
84
91
|
// Assert
|
|
85
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
92
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true })));
|
|
86
93
|
});
|
|
87
94
|
it('should log mixed string and object arguments joined with spaces in production mode', () => {
|
|
88
95
|
// Arrange
|
|
@@ -94,7 +101,60 @@ describe(logger_1.Logger.name, () => {
|
|
|
94
101
|
// Act
|
|
95
102
|
logger.info(text1, data, text2);
|
|
96
103
|
// 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 })));
|
|
104
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, sdk_log: true })));
|
|
105
|
+
});
|
|
106
|
+
async function runWorkerLog(mode) {
|
|
107
|
+
const workerScriptPath = node_path_1.default.join(__dirname, 'logger.worker-fixture.js');
|
|
108
|
+
const worker = new node_worker_threads_1.Worker(workerScriptPath, {
|
|
109
|
+
workerData: {
|
|
110
|
+
event: mockEvent,
|
|
111
|
+
options: mockOptions,
|
|
112
|
+
message: 'Worker log',
|
|
113
|
+
mode,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
const logMessage = await new Promise((resolve, reject) => {
|
|
118
|
+
function cleanup() {
|
|
119
|
+
worker.off('message', handleMessage);
|
|
120
|
+
worker.off('exit', handleExit);
|
|
121
|
+
worker.off('error', handleError);
|
|
122
|
+
}
|
|
123
|
+
function handleMessage(message) {
|
|
124
|
+
const typedMessage = message;
|
|
125
|
+
if ((typedMessage === null || typedMessage === void 0 ? void 0 : typedMessage.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
126
|
+
cleanup();
|
|
127
|
+
resolve(typedMessage);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function handleExit(code) {
|
|
131
|
+
cleanup();
|
|
132
|
+
reject(new Error(`Worker exited before emitting log. Exit code: ${code.toString()}`));
|
|
133
|
+
}
|
|
134
|
+
function handleError(error) {
|
|
135
|
+
cleanup();
|
|
136
|
+
reject(error);
|
|
137
|
+
}
|
|
138
|
+
worker.on('message', handleMessage);
|
|
139
|
+
worker.once('exit', handleExit);
|
|
140
|
+
worker.once('error', handleError);
|
|
141
|
+
});
|
|
142
|
+
return logMessage;
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
await worker.terminate();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
it('should set sdk_log to false for worker thread logs', async () => {
|
|
149
|
+
const logMessage = await runWorkerLog('user');
|
|
150
|
+
expect(logMessage.payload.sdk_log).toBe(false);
|
|
151
|
+
expect(logMessage.payload.level).toBe(logger_interfaces_1.LogLevel.INFO);
|
|
152
|
+
expect(logMessage.payload.stringifiedArgs).toContain('Worker log');
|
|
153
|
+
});
|
|
154
|
+
it('should keep sdk_log true for SDK logs inside worker thread', async () => {
|
|
155
|
+
const logMessage = await runWorkerLog('sdk');
|
|
156
|
+
expect(logMessage.payload.sdk_log).toBe(true);
|
|
157
|
+
expect(logMessage.payload.stringifiedArgs).toContain('Worker log');
|
|
98
158
|
});
|
|
99
159
|
it('should log directly without JSON wrapping in local development mode', () => {
|
|
100
160
|
// Arrange
|
|
@@ -243,6 +303,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
243
303
|
const logObject = JSON.parse(callArgs);
|
|
244
304
|
expect(logObject.message).toBe('');
|
|
245
305
|
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
306
|
+
expect(logObject.sdk_log).toBe(true);
|
|
246
307
|
});
|
|
247
308
|
it('[edge] should handle null and undefined values in log arguments', () => {
|
|
248
309
|
// Arrange
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.worker-fixture.d.ts","sourceRoot":"","sources":["../../src/logger/logger.worker-fixture.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { workerData } = require('node:worker_threads');
|
|
3
|
+
require('ts-node/register');
|
|
4
|
+
const { Logger } = require('./logger');
|
|
5
|
+
const { runWithUserLogContext } = require('./logger.context');
|
|
6
|
+
console = new Logger({ event: workerData.event, options: workerData.options });
|
|
7
|
+
const runner = workerData.mode === 'sdk' ? (fn) => fn() : runWithUserLogContext;
|
|
8
|
+
runner(() => {
|
|
9
|
+
console.log(workerData.message);
|
|
10
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state/state.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,YAAY,EAIZ,cAAc,EACf,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state/state.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,YAAY,EAIZ,cAAc,EACf,MAAM,oBAAoB,CAAC;AAG5B,wBAAsB,kBAAkB,CAAC,cAAc,EAAE,EACvD,KAAK,EACL,YAAY,EACZ,oBAAoB,EACpB,OAAO,GACR,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CA0DjE;AAED,qBAAa,KAAK,CAAC,cAAc;IAC/B,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAS;gBAEd,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC;IAenE,IAAI,KAAK,IAAI,YAAY,CAAC,cAAc,CAAC,CAExC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,cAAc,CAAC,EAE5C;IAED;;;;OAIG;IACG,IAAI,CAAC,YAAY,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCvD;;;OAGG;IACG,SAAS,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,cAAc,CAAC;IAwCpD;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAkBpC"}
|
package/dist/state/state.js
CHANGED
|
@@ -14,6 +14,7 @@ const logger_1 = require("../logger/logger");
|
|
|
14
14
|
const common_1 = require("../types/common");
|
|
15
15
|
const extraction_1 = require("../types/extraction");
|
|
16
16
|
const state_interfaces_1 = require("./state.interfaces");
|
|
17
|
+
const logger_context_1 = require("../logger/logger.context");
|
|
17
18
|
async function createAdapterState({ event, initialState, initialDomainMapping, options, }) {
|
|
18
19
|
// Deep clone the initial state to avoid mutating the original state
|
|
19
20
|
const deepCloneInitialState = structuredClone(initialState);
|
|
@@ -95,7 +96,7 @@ class State {
|
|
|
95
96
|
throw new Error(`Failed to parse state. ${error}`);
|
|
96
97
|
}
|
|
97
98
|
this.state = parsedState;
|
|
98
|
-
console.log('State fetched successfully. Current state', (0, logger_1.getPrintableState)(this.state));
|
|
99
|
+
(0, logger_context_1.runWithUserLogContext)(() => console.log('State fetched successfully. Current state', (0, logger_1.getPrintableState)(this.state)));
|
|
99
100
|
}
|
|
100
101
|
catch (error) {
|
|
101
102
|
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
@@ -137,7 +138,7 @@ class State {
|
|
|
137
138
|
request_id: this.requestId,
|
|
138
139
|
},
|
|
139
140
|
});
|
|
140
|
-
console.log('State updated successfully to', (0, logger_1.getPrintableState)(this.state));
|
|
141
|
+
(0, logger_context_1.runWithUserLogContext)(() => console.log('State updated successfully to', (0, logger_1.getPrintableState)(this.state)));
|
|
141
142
|
}
|
|
142
143
|
catch (error) {
|
|
143
144
|
console.error('Failed to update the state.', (0, logger_1.serializeError)(error));
|
|
@@ -367,14 +367,29 @@ describe('Backwards Compatibility', () => {
|
|
|
367
367
|
});
|
|
368
368
|
// Verify that the type alias is the same as the current type alias
|
|
369
369
|
describe('should verify type aliases are the same as the current type aliases', () => {
|
|
370
|
+
const normalizeTypeText = (text) => text.replace(/\s/g, '');
|
|
371
|
+
const getUnionMembers = (text) => normalizeTypeText(text)
|
|
372
|
+
.split('|')
|
|
373
|
+
.map((member) => member.trim())
|
|
374
|
+
.filter(Boolean);
|
|
370
375
|
for (const newType of newTypes) {
|
|
371
376
|
const currentType = currentTypes.find((t) => t.name === newType.name);
|
|
372
377
|
if (!currentType) {
|
|
373
378
|
continue;
|
|
374
379
|
}
|
|
375
380
|
it(`Type ${newType.name} should have the same type as the current type`, () => {
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
const currentTypeText = normalizeTypeText(currentType.typeExcerpt.text);
|
|
382
|
+
const newTypeText = normalizeTypeText(newType.typeExcerpt.text);
|
|
383
|
+
if (currentTypeText.includes('|')) {
|
|
384
|
+
const currentUnionMembers = getUnionMembers(currentType.typeExcerpt.text);
|
|
385
|
+
const newUnionMembers = new Set(getUnionMembers(newType.typeExcerpt.text));
|
|
386
|
+
expect(!!currentUnionMembers.length).toBe(true);
|
|
387
|
+
for (const member of currentUnionMembers) {
|
|
388
|
+
expect(newUnionMembers.has(member)).toBe(true);
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
expect(newTypeText).toEqual(currentTypeText);
|
|
378
393
|
});
|
|
379
394
|
}
|
|
380
395
|
});
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Worker } from 'worker_threads';
|
|
2
|
+
import type { LogLevel } from '../logger/logger.interfaces';
|
|
2
3
|
import { State } from '../state/state';
|
|
3
4
|
import { WorkerAdapter } from '../workers/worker-adapter';
|
|
4
5
|
import { AirdropEvent, ExtractorEventType } from './extraction';
|
|
@@ -116,10 +117,21 @@ export interface WorkerMessageEmitted {
|
|
|
116
117
|
export interface WorkerMessageExit {
|
|
117
118
|
subject: WorkerMessageSubject.WorkerMessageExit;
|
|
118
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* WorkerMessageLog interface represents the structure of the worker log message.
|
|
122
|
+
*/
|
|
123
|
+
export interface WorkerMessageLog {
|
|
124
|
+
subject: WorkerMessageSubject.WorkerMessageLog;
|
|
125
|
+
payload: {
|
|
126
|
+
stringifiedArgs: string;
|
|
127
|
+
level: LogLevel;
|
|
128
|
+
sdk_log?: boolean;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
119
131
|
/**
|
|
120
132
|
* WorkerMessage represents the structure of the worker message.
|
|
121
133
|
*/
|
|
122
|
-
export type WorkerMessage = WorkerMessageEmitted | WorkerMessageExit;
|
|
134
|
+
export type WorkerMessage = WorkerMessageEmitted | WorkerMessageExit | WorkerMessageLog;
|
|
123
135
|
/**
|
|
124
136
|
* WorkerData represents the structure of the worker data object.
|
|
125
137
|
*/
|
|
@@ -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,E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KAAK,EAAE,QAAQ,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,oBAAoB,GACpB,iBAAiB,GACjB,gBAAgB,CAAC;AAErB;;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":"process-task.d.ts","sourceRoot":"","sources":["../../src/workers/process-task.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/workers/process-task.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAG1B,wBAAgB,WAAW,CAAC,cAAc,EAAE,EAC1C,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,cAAc,CAAC,QA2DtC"}
|
|
@@ -3,48 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processTask = processTask;
|
|
4
4
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
5
5
|
const logger_1 = require("../logger/logger");
|
|
6
|
+
const logger_context_1 = require("../logger/logger.context");
|
|
6
7
|
const state_1 = require("../state/state");
|
|
7
8
|
const workers_1 = require("../types/workers");
|
|
8
9
|
const worker_adapter_1 = require("./worker-adapter");
|
|
9
10
|
function processTask({ task, onTimeout, }) {
|
|
10
11
|
if (!node_worker_threads_1.isMainThread) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
initialState,
|
|
22
|
-
initialDomainMapping,
|
|
23
|
-
options,
|
|
24
|
-
});
|
|
25
|
-
if (node_worker_threads_1.parentPort && node_worker_threads_1.workerData.event) {
|
|
26
|
-
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
12
|
+
(0, logger_context_1.runWithSdkLogContext)(() => {
|
|
13
|
+
void (async () => {
|
|
14
|
+
try {
|
|
15
|
+
const event = node_worker_threads_1.workerData.event;
|
|
16
|
+
const initialState = node_worker_threads_1.workerData.initialState;
|
|
17
|
+
const initialDomainMapping = node_worker_threads_1.workerData.initialDomainMapping;
|
|
18
|
+
const options = node_worker_threads_1.workerData.options;
|
|
19
|
+
// eslint-disable-next-line no-global-assign
|
|
20
|
+
console = new logger_1.Logger({ event, options });
|
|
21
|
+
const adapterState = await (0, state_1.createAdapterState)({
|
|
27
22
|
event,
|
|
28
|
-
|
|
23
|
+
initialState,
|
|
24
|
+
initialDomainMapping,
|
|
29
25
|
options,
|
|
30
26
|
});
|
|
31
|
-
node_worker_threads_1.parentPort.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
if (node_worker_threads_1.parentPort && node_worker_threads_1.workerData.event) {
|
|
28
|
+
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
29
|
+
event,
|
|
30
|
+
adapterState,
|
|
31
|
+
options,
|
|
32
|
+
});
|
|
33
|
+
node_worker_threads_1.parentPort.on(workers_1.WorkerEvent.WorkerMessage, (message) => void (async () => {
|
|
34
|
+
if (message.subject === workers_1.WorkerMessageSubject.WorkerMessageExit) {
|
|
35
|
+
console.log('Worker received message to gracefully exit. Setting isTimeout flag and executing onTimeout function.');
|
|
36
|
+
adapter.handleTimeout();
|
|
37
|
+
await (0, logger_context_1.runWithUserLogContext)(async () => onTimeout({ adapter }));
|
|
38
|
+
console.log('Finished executing onTimeout function. Exiting worker.');
|
|
39
|
+
process.exit(0);
|
|
40
|
+
}
|
|
41
|
+
})());
|
|
42
|
+
await (0, logger_context_1.runWithUserLogContext)(async () => task({ adapter }));
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
})
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error('Error while processing task.', (0, logger_1.serializeError)(error));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
});
|
|
49
52
|
}
|
|
50
53
|
}
|
|
@@ -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,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;IACjC,OAAO,CAAC,MAAM,CAAS;gBACX,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,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;IACjC,OAAO,CAAC,MAAM,CAAS;gBACX,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,cAAc;IAkGjB,OAAO,CAAC,aAAa;YAYP,kBAAkB;CAiCjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -181,14 +181,16 @@ class Spawn {
|
|
|
181
181
|
await this.exitFromMainThread();
|
|
182
182
|
})());
|
|
183
183
|
worker.on(workers_1.WorkerEvent.WorkerMessage, (message) => {
|
|
184
|
-
var _a, _b;
|
|
184
|
+
var _a, _b, _c, _d;
|
|
185
185
|
// Since logs from the worker thread are handled differently in snap-in
|
|
186
186
|
// platform, we need to catch the log messages from worker thread and log
|
|
187
187
|
// them in main thread.
|
|
188
188
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
189
189
|
const stringifiedArgs = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.stringifiedArgs;
|
|
190
190
|
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
191
|
-
|
|
191
|
+
const sdkLog = (_d = (_c = message.payload) === null || _c === void 0 ? void 0 : _c.sdk_log) !== null && _d !== void 0 ? _d : false;
|
|
192
|
+
// Args are already sanitized in the worker thread, skip double sanitization
|
|
193
|
+
this.logger.logFn(stringifiedArgs, level, sdkLog);
|
|
192
194
|
}
|
|
193
195
|
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
194
196
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-adapter.d.ts","sourceRoot":"","sources":["../../src/workers/worker-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-adapter.d.ts","sourceRoot":"","sources":["../../src/workers/worker-adapter.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kCAAkC,EAClC,yCAAyC,EACzC,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAC1B,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B,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAsHzC"}
|
|
@@ -124,7 +124,7 @@ class WorkerAdapter {
|
|
|
124
124
|
}
|
|
125
125
|
// We want to upload all the repos before emitting the event, except for the external sync units done event
|
|
126
126
|
if (newEventType !== extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsDone) {
|
|
127
|
-
console.
|
|
127
|
+
console.sdkInfo(`Uploading all repos before emitting event with event type: ${newEventType}.`);
|
|
128
128
|
try {
|
|
129
129
|
await this.uploadAllRepos();
|
|
130
130
|
}
|
|
@@ -143,7 +143,7 @@ class WorkerAdapter {
|
|
|
143
143
|
}
|
|
144
144
|
// We want to save the state every time we emit an event, except for the start and delete events
|
|
145
145
|
if (!constants_1.STATELESS_EVENT_TYPES.includes(this.event.payload.event_type)) {
|
|
146
|
-
console.
|
|
146
|
+
console.sdkInfo(`Saving state before emitting event with event type: ${newEventType}.`);
|
|
147
147
|
try {
|
|
148
148
|
await this.adapterState.postState(this.state);
|
|
149
149
|
}
|
|
@@ -30,6 +30,13 @@ jest.mock('../attachments-streaming/attachments-streaming-pool', () => {
|
|
|
30
30
|
}),
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
|
+
const mockSdkInfo = jest.fn();
|
|
34
|
+
beforeAll(() => {
|
|
35
|
+
console.sdkInfo = mockSdkInfo;
|
|
36
|
+
});
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
mockSdkInfo.mockReset();
|
|
39
|
+
});
|
|
33
40
|
describe(worker_adapter_1.WorkerAdapter.name, () => {
|
|
34
41
|
let adapter;
|
|
35
42
|
let mockEvent;
|
package/dist/workers/worker.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
const { workerData } = require('worker_threads');
|
|
3
3
|
require('ts-node').register();
|
|
4
4
|
const { Logger } = require('../logger/logger');
|
|
5
|
-
|
|
5
|
+
const { runWithUserLogContext } = require('../logger/logger.context');
|
|
6
6
|
console = new Logger({ event: workerData.event, options: workerData.options });
|
|
7
|
-
|
|
7
|
+
runWithUserLogContext(() => {
|
|
8
|
+
require(workerData.workerPath);
|
|
9
|
+
});
|