@devrev/ts-adaas 1.11.1-beta.16 → 1.11.1-beta.18
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.d.ts +0 -1
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +0 -1
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +18 -23
- package/dist/logger/logger.test.js +21 -55
- package/dist/types/workers.d.ts +1 -0
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/workers/spawn.d.ts +2 -1
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +22 -8
- package/dist/workers/worker.js +5 -0
- package/package.json +1 -1
package/dist/logger/logger.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare class Logger extends Console {
|
|
|
7
7
|
private tags;
|
|
8
8
|
constructor({ event, options }: LoggerFactoryInterface);
|
|
9
9
|
private valueToString;
|
|
10
|
-
logWithTags(stringifiedArgs: string, level: LogLevel): void;
|
|
11
10
|
logFn(args: unknown[], level: LogLevel): void;
|
|
12
11
|
log(...args: unknown[]): void;
|
|
13
12
|
info(...args: unknown[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAG1E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,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;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAG1E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,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,OAAO,CAAC,aAAa;IAYrB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IA0BpC,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;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,cAAc,CAyB5E;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,YAK5C,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OA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,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
|
@@ -14,46 +14,41 @@ const logger_interfaces_1 = require("./logger.interfaces");
|
|
|
14
14
|
class Logger extends node_console_1.Console {
|
|
15
15
|
constructor({ event, options }) {
|
|
16
16
|
super(process.stdout, process.stderr);
|
|
17
|
-
this.originalConsole =
|
|
17
|
+
this.originalConsole = console;
|
|
18
18
|
this.options = options;
|
|
19
|
-
this.tags = Object.assign(Object.assign({}, event.payload.event_context), {
|
|
19
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION });
|
|
20
20
|
}
|
|
21
21
|
valueToString(value) {
|
|
22
22
|
if (typeof value === 'string') {
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
|
-
// Use Node.js built-in inspect for everything including errors
|
|
25
|
+
// Use Node.js built-in inspect for everything including errors, functions, symbols, circular refs
|
|
26
26
|
return (0, node_util_1.inspect)(value, {
|
|
27
27
|
compact: false,
|
|
28
|
-
depth:
|
|
29
|
-
maxArrayLength: 100,
|
|
30
|
-
maxStringLength: 10000,
|
|
28
|
+
depth: Infinity,
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
|
-
|
|
31
|
+
logFn(args, level) {
|
|
34
32
|
var _a;
|
|
33
|
+
// Worker thread sends the log to the main thread to log it
|
|
34
|
+
if (!node_worker_threads_1.isMainThread && node_worker_threads_1.parentPort) {
|
|
35
|
+
const sanitizedArgs = args.map((arg) => this.valueToString(arg));
|
|
36
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
37
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
38
|
+
payload: { args: sanitizedArgs, level },
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Main thread logs the log normally
|
|
35
43
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
36
|
-
this.originalConsole[level](
|
|
44
|
+
this.originalConsole[level](...args);
|
|
37
45
|
}
|
|
38
46
|
else {
|
|
39
|
-
const
|
|
47
|
+
const message = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
48
|
+
const logObject = Object.assign({ message }, this.tags);
|
|
40
49
|
this.originalConsole[level](JSON.stringify(logObject));
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
|
-
logFn(args, level) {
|
|
44
|
-
const stringifiedArgs = args
|
|
45
|
-
.map((arg) => this.valueToString(arg))
|
|
46
|
-
.join(' ');
|
|
47
|
-
if (node_worker_threads_1.isMainThread) {
|
|
48
|
-
this.logWithTags(stringifiedArgs, level);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
52
|
-
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
53
|
-
payload: { stringifiedArgs, level },
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
52
|
log(...args) {
|
|
58
53
|
this.logFn(args, logger_interfaces_1.LogLevel.INFO);
|
|
59
54
|
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_console_1 = require("node:console");
|
|
4
3
|
const node_util_1 = require("node:util");
|
|
5
4
|
const constants_1 = require("../common/constants");
|
|
6
5
|
const test_helpers_1 = require("../tests/test-helpers");
|
|
7
6
|
const extraction_1 = require("../types/extraction");
|
|
8
7
|
const logger_1 = require("./logger");
|
|
9
|
-
// Mock
|
|
10
|
-
const mockConsoleInfo = jest
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const mockConsoleWarn = jest
|
|
14
|
-
.spyOn(node_console_1.Console.prototype, 'warn')
|
|
15
|
-
.mockImplementation();
|
|
16
|
-
const mockConsoleError = jest
|
|
17
|
-
.spyOn(node_console_1.Console.prototype, 'error')
|
|
18
|
-
.mockImplementation();
|
|
8
|
+
// Mock console methods
|
|
9
|
+
const mockConsoleInfo = jest.spyOn(console, 'info').mockImplementation();
|
|
10
|
+
const mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
|
|
11
|
+
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
|
|
19
12
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
20
13
|
// Mock worker_threads
|
|
21
14
|
jest.mock('node:worker_threads', () => ({
|
|
@@ -54,12 +47,12 @@ describe(logger_1.Logger.name, () => {
|
|
|
54
47
|
jest.restoreAllMocks();
|
|
55
48
|
});
|
|
56
49
|
describe('constructor', () => {
|
|
57
|
-
it('should initialize logger with event context
|
|
50
|
+
it('should initialize logger with event context and sdk_version', () => {
|
|
58
51
|
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
59
52
|
// Access private property for testing
|
|
60
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
54
|
const tags = logger.tags;
|
|
62
|
-
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), {
|
|
55
|
+
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION }));
|
|
63
56
|
});
|
|
64
57
|
});
|
|
65
58
|
describe('production logging', () => {
|
|
@@ -71,10 +64,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
71
64
|
it('should log single string message without backslashes', () => {
|
|
72
65
|
const message = 'Worker is online. Started processing the task.';
|
|
73
66
|
logger.info(message);
|
|
74
|
-
|
|
75
|
-
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
76
|
-
const actualLogObject = JSON.parse(actualCall);
|
|
77
|
-
expect(actualLogObject).toEqual(expectedLogObject);
|
|
67
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
78
68
|
});
|
|
79
69
|
it('should log single object message with JSON stringify', () => {
|
|
80
70
|
const data = { id: 123, name: 'test' };
|
|
@@ -82,13 +72,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
82
72
|
const expectedMessage = (0, node_util_1.inspect)(data, {
|
|
83
73
|
compact: false,
|
|
84
74
|
depth: Infinity,
|
|
85
|
-
maxArrayLength: Infinity,
|
|
86
|
-
maxStringLength: Infinity,
|
|
87
75
|
});
|
|
88
|
-
|
|
89
|
-
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
90
|
-
const actualLogObject = JSON.parse(actualCall);
|
|
91
|
-
expect(actualLogObject).toEqual(expectedLogObject);
|
|
76
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
92
77
|
});
|
|
93
78
|
it('should log multiple arguments joined with space', () => {
|
|
94
79
|
const text = 'Successfully fetched';
|
|
@@ -97,13 +82,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
97
82
|
const expectedDataMessage = (0, node_util_1.inspect)(data, {
|
|
98
83
|
compact: false,
|
|
99
84
|
depth: Infinity,
|
|
100
|
-
maxArrayLength: Infinity,
|
|
101
|
-
maxStringLength: Infinity,
|
|
102
85
|
});
|
|
103
|
-
|
|
104
|
-
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
105
|
-
const actualLogObject = JSON.parse(actualCall);
|
|
106
|
-
expect(actualLogObject).toEqual(expectedLogObject);
|
|
86
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
107
87
|
});
|
|
108
88
|
it('should handle mixed string and object arguments', () => {
|
|
109
89
|
const text1 = 'Processing';
|
|
@@ -113,13 +93,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
113
93
|
const expectedDataMessage = (0, node_util_1.inspect)(data, {
|
|
114
94
|
compact: false,
|
|
115
95
|
depth: Infinity,
|
|
116
|
-
maxArrayLength: Infinity,
|
|
117
|
-
maxStringLength: Infinity,
|
|
118
96
|
});
|
|
119
|
-
|
|
120
|
-
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
121
|
-
const actualLogObject = JSON.parse(actualCall);
|
|
122
|
-
expect(actualLogObject).toEqual(expectedLogObject);
|
|
97
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
123
98
|
});
|
|
124
99
|
});
|
|
125
100
|
describe('local development logging', () => {
|
|
@@ -132,14 +107,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
132
107
|
const message = 'Test message';
|
|
133
108
|
const data = { test: true };
|
|
134
109
|
logger.info(message, data);
|
|
135
|
-
|
|
136
|
-
const expectedMessage = `${message} ${(0, node_util_1.inspect)(data, {
|
|
137
|
-
compact: false,
|
|
138
|
-
depth: Infinity,
|
|
139
|
-
maxArrayLength: Infinity,
|
|
140
|
-
maxStringLength: Infinity,
|
|
141
|
-
})}`;
|
|
142
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(expectedMessage);
|
|
110
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(message, data);
|
|
143
111
|
});
|
|
144
112
|
});
|
|
145
113
|
describe('log levels', () => {
|
|
@@ -174,20 +142,20 @@ describe(logger_1.Logger.name, () => {
|
|
|
174
142
|
it('[edge] should handle empty string message', () => {
|
|
175
143
|
logger.info('');
|
|
176
144
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
177
|
-
const
|
|
178
|
-
const logObject = JSON.parse(
|
|
145
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
146
|
+
const logObject = JSON.parse(callArgs);
|
|
179
147
|
expect(logObject.message).toBe('');
|
|
180
|
-
expect(logObject.
|
|
148
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
181
149
|
expect(logObject.request_id).toBe(mockEvent.payload.event_context.request_id);
|
|
182
150
|
});
|
|
183
151
|
it('[edge] should handle null and undefined values', () => {
|
|
184
152
|
logger.info('test', null, undefined);
|
|
185
153
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
186
|
-
const
|
|
187
|
-
const logObject = JSON.parse(
|
|
154
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
155
|
+
const logObject = JSON.parse(callArgs);
|
|
188
156
|
// inspect shows 'null' and 'undefined' as strings
|
|
189
157
|
expect(logObject.message).toBe('test null undefined');
|
|
190
|
-
expect(logObject.
|
|
158
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
191
159
|
});
|
|
192
160
|
it('[edge] should handle complex nested objects', () => {
|
|
193
161
|
const complexObject = {
|
|
@@ -200,17 +168,15 @@ describe(logger_1.Logger.name, () => {
|
|
|
200
168
|
};
|
|
201
169
|
logger.info(complexObject);
|
|
202
170
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
203
|
-
const
|
|
204
|
-
const logObject = JSON.parse(
|
|
205
|
-
// The logger uses inspect() with
|
|
171
|
+
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
172
|
+
const logObject = JSON.parse(callArgs);
|
|
173
|
+
// The logger uses inspect() with formatting, not JSON.stringify()
|
|
206
174
|
const expectedMessage = require('util').inspect(complexObject, {
|
|
207
175
|
compact: false,
|
|
208
176
|
depth: Infinity,
|
|
209
|
-
maxArrayLength: Infinity,
|
|
210
|
-
maxStringLength: Infinity,
|
|
211
177
|
});
|
|
212
178
|
expect(logObject.message).toBe(expectedMessage);
|
|
213
|
-
expect(logObject.
|
|
179
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
214
180
|
expect(typeof logObject.callback_url).toBe('string');
|
|
215
181
|
});
|
|
216
182
|
});
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":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AAK,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"}
|
package/dist/workers/spawn.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export declare class Spawn {
|
|
|
20
20
|
private hardTimeoutTimer;
|
|
21
21
|
private memoryMonitoringInterval;
|
|
22
22
|
private resolve;
|
|
23
|
-
|
|
23
|
+
private originalConsole;
|
|
24
|
+
constructor({ event, worker, options, resolve, originalConsole, }: SpawnInterface);
|
|
24
25
|
private clearTimeouts;
|
|
25
26
|
private exitFromMainThread;
|
|
26
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,CA4EvD;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;gBAErB,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,cAAc;IA8FjB,OAAO,CAAC,aAAa;YAYP,kBAAkB;CAgCjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -72,10 +72,7 @@ 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
|
|
76
|
-
if (argv._.includes('local')) {
|
|
77
|
-
options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
|
|
78
|
-
}
|
|
75
|
+
const originalConsole = console;
|
|
79
76
|
// eslint-disable-next-line no-global-assign
|
|
80
77
|
console = new logger_1.Logger({ event, options });
|
|
81
78
|
const script = getWorkerPath({
|
|
@@ -83,7 +80,12 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
83
80
|
connectorWorkerPath: workerPath,
|
|
84
81
|
});
|
|
85
82
|
if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
|
|
86
|
-
console.warn('
|
|
83
|
+
console.warn('WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.');
|
|
84
|
+
}
|
|
85
|
+
// read the command line arguments to check if the local flag is passed
|
|
86
|
+
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
|
|
87
|
+
if (argv._.includes('local')) {
|
|
88
|
+
options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
|
|
87
89
|
}
|
|
88
90
|
if (script) {
|
|
89
91
|
try {
|
|
@@ -100,11 +102,14 @@ 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
|
}
|
|
@@ -127,10 +132,14 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
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;
|
|
135
144
|
this.alreadyEmitted = false;
|
|
136
145
|
this.event = event;
|
|
@@ -138,6 +147,7 @@ class Spawn {
|
|
|
138
147
|
? Math.min(options.timeout, this.defaultLambdaTimeout)
|
|
139
148
|
: this.defaultLambdaTimeout;
|
|
140
149
|
this.resolve = resolve;
|
|
150
|
+
this.originalConsole = originalConsole;
|
|
141
151
|
// If soft timeout is reached, send a message to the worker to gracefully exit.
|
|
142
152
|
this.softTimeoutTimer = setTimeout(() => void (async () => {
|
|
143
153
|
console.log('SOFT TIMEOUT: Sending a message to the worker to gracefully exit.');
|
|
@@ -171,10 +181,12 @@ class Spawn {
|
|
|
171
181
|
})());
|
|
172
182
|
worker.on(workers_1.WorkerEvent.WorkerMessage, (message) => {
|
|
173
183
|
var _a, _b;
|
|
184
|
+
// Since it is not possible to log from the worker thread, we need to log
|
|
185
|
+
// from the main thread.
|
|
174
186
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
175
|
-
const
|
|
187
|
+
const args = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.args;
|
|
176
188
|
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
177
|
-
console.
|
|
189
|
+
console.logFn(args, level);
|
|
178
190
|
}
|
|
179
191
|
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
180
192
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
@@ -213,6 +225,8 @@ class Spawn {
|
|
|
213
225
|
}
|
|
214
226
|
async exitFromMainThread() {
|
|
215
227
|
this.clearTimeouts();
|
|
228
|
+
// eslint-disable-next-line no-global-assign
|
|
229
|
+
console = this.originalConsole;
|
|
216
230
|
if (this.alreadyEmitted) {
|
|
217
231
|
this.resolve();
|
|
218
232
|
return;
|
package/dist/workers/worker.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { workerData } = require('worker_threads');
|
|
3
3
|
require('ts-node').register();
|
|
4
|
+
// Override console with Logger instance
|
|
5
|
+
const { Logger } = require('../logger/logger');
|
|
6
|
+
// eslint-disable-next-line no-global-assign
|
|
7
|
+
console = new Logger({ event: workerData.event, options: workerData.options });
|
|
8
|
+
// Now load the actual worker with console already overridden
|
|
4
9
|
require(workerData.workerPath);
|
package/package.json
CHANGED