@devrev/ts-adaas 1.11.0 → 1.11.1-beta.1
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 +8 -4
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +37 -44
- package/dist/tests/backwards-compatibility/backwards-compatibility.test.d.ts.map +1 -1
- package/dist/tests/backwards-compatibility/backwards-compatibility.test.js +8 -3
- package/dist/workers/create-worker.js +1 -1
- package/dist/workers/process-task.d.ts.map +1 -1
- package/dist/workers/process-task.js +31 -25
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +4 -10
- package/package.json +1 -1
package/dist/logger/logger.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AxiosError, RawAxiosResponseHeaders } from 'axios';
|
|
|
4
4
|
export declare class Logger extends Console {
|
|
5
5
|
private options?;
|
|
6
6
|
private tags;
|
|
7
|
+
private originalConsole;
|
|
7
8
|
constructor({ event, options }: LoggerFactoryInterface);
|
|
8
9
|
private valueToString;
|
|
9
10
|
logFn(args: unknown[], level: LogLevel): void;
|
|
@@ -18,7 +19,7 @@ export declare function getPrintableState(state: Record<string, any>): Printable
|
|
|
18
19
|
*/
|
|
19
20
|
export declare function formatAxiosError(error: AxiosError): object;
|
|
20
21
|
export declare const serializeError: (error: unknown) => unknown;
|
|
21
|
-
export
|
|
22
|
+
export interface AxiosErrorResponse {
|
|
22
23
|
config: {
|
|
23
24
|
method: string | undefined;
|
|
24
25
|
params: any;
|
|
@@ -26,11 +27,14 @@ export declare function serializeAxiosError(error: AxiosError): {
|
|
|
26
27
|
};
|
|
27
28
|
isAxiosError: boolean;
|
|
28
29
|
isCorsOrNoNetworkError: boolean;
|
|
29
|
-
response
|
|
30
|
+
response?: {
|
|
30
31
|
data: unknown;
|
|
31
32
|
headers: RawAxiosResponseHeaders;
|
|
32
33
|
status: number;
|
|
33
34
|
statusText: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
35
|
+
};
|
|
36
|
+
code?: string;
|
|
37
|
+
message?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function serializeAxiosError(error: AxiosError): AxiosErrorResponse;
|
|
36
40
|
//# 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,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EACL,sBAAsB,EACtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EACL,sBAAsB,EACtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAgB,MAAM,OAAO,CAAC;AAI1E,qBAAa,MAAO,SAAQ,OAAO;IACjC,OAAO,CAAC,OAAO,CAAC,CAAuB;IACvC,OAAO,CAAC,IAAI,CAAqC;IACjD,OAAO,CAAC,eAAe,CAAU;gBAErB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sBAAsB;IAUtD,OAAO,CAAC,aAAa;IAYrB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IA2BpC,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,CA2B5E;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,YAK5C,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,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,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE"}
|
package/dist/logger/logger.js
CHANGED
|
@@ -7,12 +7,11 @@ exports.serializeAxiosError = serializeAxiosError;
|
|
|
7
7
|
const node_console_1 = require("node:console");
|
|
8
8
|
const node_util_1 = require("node:util");
|
|
9
9
|
const logger_interfaces_1 = require("./logger.interfaces");
|
|
10
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
11
|
-
const workers_1 = require("../types/workers");
|
|
12
10
|
const axios_1 = require("axios");
|
|
13
11
|
class Logger extends node_console_1.Console {
|
|
14
12
|
constructor({ event, options }) {
|
|
15
13
|
super(process.stdout, process.stderr);
|
|
14
|
+
this.originalConsole = console; // Store original console before replacement
|
|
16
15
|
this.options = options;
|
|
17
16
|
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_oid });
|
|
18
17
|
}
|
|
@@ -28,36 +27,27 @@ class Logger extends node_console_1.Console {
|
|
|
28
27
|
}
|
|
29
28
|
logFn(args, level) {
|
|
30
29
|
var _a;
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
31
|
+
// Use original console methods to avoid circular reference
|
|
32
|
+
this.originalConsole[level](...args);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
let message;
|
|
36
|
+
if (args.length === 1 && typeof args[0] === 'string') {
|
|
37
|
+
// Single string argument - use directly
|
|
38
|
+
message = args[0];
|
|
39
|
+
}
|
|
40
|
+
else if (args.length === 1) {
|
|
41
|
+
// Single non-string argument - convert to string properly
|
|
42
|
+
message = this.valueToString(args[0]);
|
|
34
43
|
}
|
|
35
44
|
else {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Single string argument - use directly
|
|
39
|
-
message = args[0];
|
|
40
|
-
}
|
|
41
|
-
else if (args.length === 1) {
|
|
42
|
-
// Single non-string argument - convert to string properly
|
|
43
|
-
message = this.valueToString(args[0]);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// Multiple arguments - create a readable format
|
|
47
|
-
message = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
48
|
-
}
|
|
49
|
-
const logObject = Object.assign({ message }, this.tags);
|
|
50
|
-
console[level](JSON.stringify(logObject));
|
|
45
|
+
// Multiple arguments - create a readable format
|
|
46
|
+
message = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
51
47
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
56
|
-
payload: {
|
|
57
|
-
args: args.map((arg) => this.valueToString(arg)),
|
|
58
|
-
level,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
48
|
+
const logObject = Object.assign({ message }, this.tags);
|
|
49
|
+
// Use original console methods to avoid circular reference
|
|
50
|
+
this.originalConsole[level](JSON.stringify(logObject));
|
|
61
51
|
}
|
|
62
52
|
}
|
|
63
53
|
log(...args) {
|
|
@@ -119,23 +109,26 @@ const serializeError = (error) => {
|
|
|
119
109
|
exports.serializeError = serializeError;
|
|
120
110
|
function serializeAxiosError(error) {
|
|
121
111
|
var _a, _b, _c;
|
|
122
|
-
const
|
|
123
|
-
|
|
112
|
+
const serializedAxiosError = {
|
|
113
|
+
config: {
|
|
114
|
+
method: (_a = error.config) === null || _a === void 0 ? void 0 : _a.method,
|
|
115
|
+
params: (_b = error.config) === null || _b === void 0 ? void 0 : _b.params,
|
|
116
|
+
url: (_c = error.config) === null || _c === void 0 ? void 0 : _c.url,
|
|
117
|
+
},
|
|
118
|
+
isAxiosError: true,
|
|
119
|
+
isCorsOrNoNetworkError: !error.response,
|
|
120
|
+
};
|
|
121
|
+
if (error.response) {
|
|
122
|
+
serializedAxiosError.response = {
|
|
124
123
|
data: error.response.data,
|
|
125
124
|
headers: error.response.headers,
|
|
126
125
|
status: error.response.status,
|
|
127
126
|
statusText: error.response.statusText,
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
config,
|
|
137
|
-
isAxiosError: true,
|
|
138
|
-
isCorsOrNoNetworkError: !error.response,
|
|
139
|
-
response,
|
|
140
|
-
};
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
serializedAxiosError.code = error.code;
|
|
131
|
+
serializedAxiosError.message = error.message;
|
|
132
|
+
}
|
|
133
|
+
return serializedAxiosError;
|
|
141
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backwards-compatibility.test.d.ts","sourceRoot":"","sources":["../../../src/tests/backwards-compatibility/backwards-compatibility.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,cAAc,EAGd,WAAW,EAEX,kBAAkB,EAKnB,MAAM,gCAAgC,CAAC;AAgBxC,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,cAAc,GAAG,kBAAkB,EAAE,eAAe,EAAE,WAAW,GAAG,cAAc,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"backwards-compatibility.test.d.ts","sourceRoot":"","sources":["../../../src/tests/backwards-compatibility/backwards-compatibility.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,cAAc,EAGd,WAAW,EAEX,kBAAkB,EAKnB,MAAM,gCAAgC,CAAC;AAgBxC,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,cAAc,GAAG,kBAAkB,EAAE,eAAe,EAAE,WAAW,GAAG,cAAc,GAAG,kBAAkB,QAmD5K"}
|
|
@@ -23,9 +23,14 @@ function checkFunctionCompatibility(newFunction, currentFunction) {
|
|
|
23
23
|
// This check fails if it's a constructor, as those don't have a return type
|
|
24
24
|
if (currentFunction instanceof api_extractor_model_1.ApiFunction && newFunction instanceof api_extractor_model_1.ApiFunction) {
|
|
25
25
|
if (!((_a = currentFunction.returnTypeExcerpt) === null || _a === void 0 ? void 0 : _a.isEmpty)) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (newFunction.returnTypeExcerpt.text != currentFunction.returnTypeExcerpt.text) {
|
|
27
|
+
// This will pass, if the new implementation is an object and the current one is not specified or a hard-coded type.
|
|
28
|
+
if (!(currentFunction.returnTypeExcerpt.text.split(" ").length != 1 && newFunction.returnTypeExcerpt.text.split(" ").length == 1)) {
|
|
29
|
+
it(`Function ${newFunction.displayName} should have the same return type as the current function`, () => {
|
|
30
|
+
expect(newFunction.returnTypeExcerpt.text).toEqual(currentFunction.returnTypeExcerpt.text);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
it(`Function ${newFunction.displayName} should have all new parameters as optional`, () => {
|
|
@@ -17,7 +17,7 @@ async function createWorker(workerData) {
|
|
|
17
17
|
});
|
|
18
18
|
worker.on(workers_1.WorkerEvent.WorkerError, (error) => {
|
|
19
19
|
logger.error('Worker error', error);
|
|
20
|
-
reject();
|
|
20
|
+
reject(error);
|
|
21
21
|
});
|
|
22
22
|
worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
|
|
23
23
|
resolve(worker);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/workers/process-task.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,wBAAgB,WAAW,CAAC,cAAc,EAAE,EAC1C,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/workers/process-task.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,wBAAgB,WAAW,CAAC,cAAc,EAAE,EAC1C,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,cAAc,CAAC,QAgDtC"}
|
|
@@ -9,34 +9,40 @@ const logger_1 = require("../logger/logger");
|
|
|
9
9
|
function processTask({ task, onTimeout, }) {
|
|
10
10
|
if (!node_worker_threads_1.isMainThread) {
|
|
11
11
|
void (async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
initialState,
|
|
20
|
-
initialDomainMapping,
|
|
21
|
-
options,
|
|
22
|
-
});
|
|
23
|
-
if (node_worker_threads_1.parentPort && node_worker_threads_1.workerData.event) {
|
|
24
|
-
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
12
|
+
try {
|
|
13
|
+
const event = node_worker_threads_1.workerData.event;
|
|
14
|
+
const initialState = node_worker_threads_1.workerData.initialState;
|
|
15
|
+
const initialDomainMapping = node_worker_threads_1.workerData.initialDomainMapping;
|
|
16
|
+
const options = node_worker_threads_1.workerData.options;
|
|
17
|
+
console = new logger_1.Logger({ event, options });
|
|
18
|
+
const adapterState = await (0, state_1.createAdapterState)({
|
|
25
19
|
event,
|
|
26
|
-
|
|
20
|
+
initialState,
|
|
21
|
+
initialDomainMapping,
|
|
27
22
|
options,
|
|
28
23
|
});
|
|
29
|
-
node_worker_threads_1.parentPort.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
if (node_worker_threads_1.parentPort && node_worker_threads_1.workerData.event) {
|
|
25
|
+
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
26
|
+
event,
|
|
27
|
+
adapterState,
|
|
28
|
+
options,
|
|
29
|
+
});
|
|
30
|
+
node_worker_threads_1.parentPort.on(workers_1.WorkerEvent.WorkerMessage, async (message) => {
|
|
31
|
+
if (message.subject === workers_1.WorkerMessageSubject.WorkerMessageExit) {
|
|
32
|
+
console.log('Worker received message to gracefully exit. Setting isTimeout flag and executing onTimeout function.');
|
|
33
|
+
adapter.handleTimeout();
|
|
34
|
+
await onTimeout({ adapter });
|
|
35
|
+
console.log('Finished executing onTimeout function. Exiting worker.');
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
await task({ adapter });
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('Error while processing task.', (0, logger_1.serializeError)(error));
|
|
45
|
+
process.exit(1);
|
|
40
46
|
}
|
|
41
47
|
})();
|
|
42
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,qBAAqB,EACrB,cAAc,EACf,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":"AAYA,OAAO,EAIL,qBAAqB,EACrB,cAAc,EACf,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,CAmEvD;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,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA4C;gBAE/C,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,cAAc;IAyE/D,OAAO,CAAC,aAAa;YAYP,kBAAkB;CA6BjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -105,10 +105,11 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
105
105
|
}
|
|
106
106
|
catch (error) {
|
|
107
107
|
logger.error('Worker error while processing task', error);
|
|
108
|
+
return Promise.reject(error);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
|
-
|
|
112
|
+
logger.error('Script was not found for event type: ' + event.payload.event_type + '.');
|
|
112
113
|
try {
|
|
113
114
|
await (0, control_protocol_1.emit)({
|
|
114
115
|
event,
|
|
@@ -123,7 +124,8 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
126
|
catch (error) {
|
|
126
|
-
|
|
127
|
+
logger.error('Error while emitting event.', (0, logger_1.serializeError)(error));
|
|
128
|
+
return Promise.reject(error);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
}
|
|
@@ -168,14 +170,6 @@ class Spawn {
|
|
|
168
170
|
await this.exitFromMainThread();
|
|
169
171
|
});
|
|
170
172
|
worker.on(workers_1.WorkerEvent.WorkerMessage, async (message) => {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
// Since it is not possible to log from the worker thread, we need to log
|
|
173
|
-
// from the main thread.
|
|
174
|
-
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
175
|
-
const args = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.args;
|
|
176
|
-
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
177
|
-
this.logger.logFn(args, level);
|
|
178
|
-
}
|
|
179
173
|
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
180
174
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
181
175
|
this.logger.info('Worker has emitted message to ADaaS.');
|