@devrev/airsync-sdk 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +16 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +9 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.js +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.js +97 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +267 -0
- package/dist/common/constants.d.ts +25 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +58 -0
- package/dist/common/control-protocol.d.ts +10 -0
- package/dist/common/control-protocol.d.ts.map +1 -0
- package/dist/common/control-protocol.js +31 -0
- package/dist/common/errors.d.ts +6 -0
- package/dist/common/errors.d.ts.map +1 -0
- package/dist/common/errors.js +4 -0
- package/dist/common/event-type-translation.d.ts +24 -0
- package/dist/common/event-type-translation.d.ts.map +1 -0
- package/dist/common/event-type-translation.js +117 -0
- package/dist/common/helpers.d.ts +41 -0
- package/dist/common/helpers.d.ts.map +1 -0
- package/dist/common/helpers.js +124 -0
- package/dist/common/install-initial-domain-mapping.d.ts +4 -0
- package/dist/common/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.js +58 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts +2 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.test.js +207 -0
- package/dist/deprecated/adapter/index.d.ts +62 -0
- package/dist/deprecated/adapter/index.d.ts.map +1 -0
- package/dist/deprecated/adapter/index.js +151 -0
- package/dist/deprecated/common/helpers.d.ts +7 -0
- package/dist/deprecated/common/helpers.d.ts.map +1 -0
- package/dist/deprecated/common/helpers.js +47 -0
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +38 -0
- package/dist/deprecated/demo-extractor/index.d.ts +18 -0
- package/dist/deprecated/demo-extractor/index.d.ts.map +1 -0
- package/dist/deprecated/demo-extractor/index.js +161 -0
- package/dist/deprecated/http/client.d.ts +22 -0
- package/dist/deprecated/http/client.d.ts.map +1 -0
- package/dist/deprecated/http/client.js +161 -0
- package/dist/deprecated/uploader/index.d.ts +35 -0
- package/dist/deprecated/uploader/index.d.ts.map +1 -0
- package/dist/deprecated/uploader/index.js +161 -0
- package/dist/http/axios-client-internal.d.ts +3 -0
- package/dist/http/axios-client-internal.d.ts.map +1 -0
- package/dist/http/axios-client-internal.js +66 -0
- package/dist/http/axios-client-internal.test.d.ts +2 -0
- package/dist/http/axios-client-internal.test.d.ts.map +1 -0
- package/dist/http/axios-client-internal.test.js +154 -0
- package/dist/http/axios-client.d.ts +27 -0
- package/dist/http/axios-client.d.ts.map +1 -0
- package/dist/http/axios-client.js +57 -0
- package/dist/http/constants.d.ts +4 -0
- package/dist/http/constants.d.ts.map +1 -0
- package/dist/http/constants.js +6 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +18 -0
- package/dist/http/types.d.ts +17 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- 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.context.d.ts +58 -0
- package/dist/logger/logger.context.d.ts.map +1 -0
- package/dist/logger/logger.context.js +86 -0
- package/dist/logger/logger.d.ts +89 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.d.ts +43 -0
- package/dist/logger/logger.interfaces.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.js +9 -0
- package/dist/logger/logger.js +196 -0
- package/dist/logger/logger.test.d.ts +2 -0
- package/dist/logger/logger.test.d.ts.map +1 -0
- package/dist/logger/logger.test.js +490 -0
- package/dist/mappers/mappers.d.ts +52 -0
- package/dist/mappers/mappers.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.d.ts +294 -0
- package/dist/mappers/mappers.interface.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.js +48 -0
- package/dist/mappers/mappers.js +83 -0
- package/dist/mappers/mappers.test.d.ts +2 -0
- package/dist/mappers/mappers.test.d.ts.map +1 -0
- package/dist/mappers/mappers.test.js +107 -0
- package/dist/multithreading/create-worker.d.ts +5 -0
- package/dist/multithreading/create-worker.d.ts.map +1 -0
- package/dist/multithreading/create-worker.js +28 -0
- package/dist/multithreading/create-worker.test.d.ts +2 -0
- package/dist/multithreading/create-worker.test.d.ts.map +1 -0
- package/dist/multithreading/create-worker.test.js +89 -0
- package/dist/multithreading/process-task.d.ts +3 -0
- package/dist/multithreading/process-task.d.ts.map +1 -0
- package/dist/multithreading/process-task.js +58 -0
- package/dist/multithreading/spawn/spawn.d.ts +30 -0
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts +21 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.js +114 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +2 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.test.js +293 -0
- package/dist/multithreading/spawn/spawn.js +249 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +127 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +91 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +22 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.js +64 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +514 -0
- package/dist/multithreading/worker-adapter/worker-adapter.js +747 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +483 -0
- package/dist/multithreading/worker.d.ts +2 -0
- package/dist/multithreading/worker.d.ts.map +1 -0
- package/dist/multithreading/worker.js +9 -0
- package/dist/repo/repo.d.ts +18 -0
- package/dist/repo/repo.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.d.ts +46 -0
- package/dist/repo/repo.interfaces.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.js +2 -0
- package/dist/repo/repo.js +75 -0
- package/dist/repo/repo.test.d.ts +2 -0
- package/dist/repo/repo.test.d.ts.map +1 -0
- package/dist/repo/repo.test.js +131 -0
- package/dist/state/state.d.ts +30 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.interfaces.d.ts +51 -0
- package/dist/state/state.interfaces.d.ts.map +1 -0
- package/dist/state/state.interfaces.js +21 -0
- package/dist/state/state.js +166 -0
- package/dist/state/state.test.d.ts +2 -0
- package/dist/state/state.test.d.ts.map +1 -0
- package/dist/state/state.test.js +224 -0
- package/dist/types/common.d.ts +50 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +25 -0
- package/dist/types/extraction.d.ts +417 -0
- package/dist/types/extraction.d.ts.map +1 -0
- package/dist/types/extraction.js +170 -0
- package/dist/types/extraction.test.d.ts +2 -0
- package/dist/types/extraction.test.d.ts.map +1 -0
- package/dist/types/extraction.test.js +70 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/loading.d.ts +147 -0
- package/dist/types/loading.d.ts.map +1 -0
- package/dist/types/loading.js +48 -0
- package/dist/types/workers.d.ts +161 -0
- package/dist/types/workers.d.ts.map +1 -0
- package/dist/types/workers.js +22 -0
- package/dist/uploader/uploader.d.ts +92 -0
- package/dist/uploader/uploader.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.d.ts +33 -0
- package/dist/uploader/uploader.helpers.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.js +139 -0
- package/dist/uploader/uploader.helpers.test.d.ts +2 -0
- package/dist/uploader/uploader.helpers.test.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.test.js +267 -0
- package/dist/uploader/uploader.interfaces.d.ts +95 -0
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -0
- package/dist/uploader/uploader.interfaces.js +2 -0
- package/dist/uploader/uploader.js +305 -0
- package/dist/uploader/uploader.test.d.ts +2 -0
- package/dist/uploader/uploader.test.d.ts.map +1 -0
- package/dist/uploader/uploader.test.js +589 -0
- package/package.json +60 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Spawn = void 0;
|
|
7
|
+
exports.spawn = spawn;
|
|
8
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
9
|
+
const helpers_1 = require("yargs/helpers");
|
|
10
|
+
const control_protocol_1 = require("../../common/control-protocol");
|
|
11
|
+
const event_type_translation_1 = require("../../common/event-type-translation");
|
|
12
|
+
const helpers_2 = require("../../common/helpers");
|
|
13
|
+
const logger_1 = require("../../logger/logger");
|
|
14
|
+
const extraction_1 = require("../../types/extraction");
|
|
15
|
+
const workers_1 = require("../../types/workers");
|
|
16
|
+
const constants_1 = require("../../common/constants");
|
|
17
|
+
const create_worker_1 = require("../create-worker");
|
|
18
|
+
const spawn_helpers_1 = require("./spawn.helpers");
|
|
19
|
+
function getWorkerPath({ event, workerBasePath, }) {
|
|
20
|
+
let path = null;
|
|
21
|
+
switch (event.payload.event_type) {
|
|
22
|
+
case extraction_1.EventType.StartExtractingExternalSyncUnits:
|
|
23
|
+
path = '/workers/external-sync-units-extraction';
|
|
24
|
+
break;
|
|
25
|
+
case extraction_1.EventType.StartExtractingMetadata:
|
|
26
|
+
path = '/workers/metadata-extraction';
|
|
27
|
+
break;
|
|
28
|
+
case extraction_1.EventType.StartExtractingData:
|
|
29
|
+
case extraction_1.EventType.ContinueExtractingData:
|
|
30
|
+
path = '/workers/data-extraction';
|
|
31
|
+
break;
|
|
32
|
+
case extraction_1.EventType.StartExtractingAttachments:
|
|
33
|
+
case extraction_1.EventType.ContinueExtractingAttachments:
|
|
34
|
+
path = '/workers/attachments-extraction';
|
|
35
|
+
break;
|
|
36
|
+
case extraction_1.EventType.StartLoadingData:
|
|
37
|
+
case extraction_1.EventType.ContinueLoadingData:
|
|
38
|
+
path = '/workers/load-data';
|
|
39
|
+
break;
|
|
40
|
+
case extraction_1.EventType.StartLoadingAttachments:
|
|
41
|
+
case extraction_1.EventType.ContinueLoadingAttachments:
|
|
42
|
+
path = '/workers/load-attachments';
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return path ? workerBasePath + path : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new instance of Spawn class.
|
|
49
|
+
* Spawn class is responsible for spawning a new worker thread and managing the lifecycle of the worker.
|
|
50
|
+
* The class provides utilities to emit control events to the platform and exit the worker gracefully.
|
|
51
|
+
* In case of lambda timeout, the class emits a lambda timeout event to the platform.
|
|
52
|
+
* @param {SpawnFactoryInterface} options - The options to create a new instance of Spawn class
|
|
53
|
+
* @param {AirdropEvent} options.event - The event object received from the platform
|
|
54
|
+
* @param {object} options.initialState - The initial state of the adapter
|
|
55
|
+
* @param {string} [options.workerPath] Remove getWorkerPath function and use baseWorkerPath: __dirname instead of workerPath
|
|
56
|
+
* @param {string} [options.baseWorkerPath] - The base path for the worker files, usually `__dirname`
|
|
57
|
+
* @returns {Promise<Spawn>} - A new instance of Spawn class
|
|
58
|
+
*/
|
|
59
|
+
async function spawn({ event, initialState, workerPath, initialDomainMapping, options, baseWorkerPath, }) {
|
|
60
|
+
// Translate incoming event type for backwards compatibility. This allows the
|
|
61
|
+
// SDK to accept both old and new event type formats. Then update the event with the translated event type.
|
|
62
|
+
const originalEventType = event.payload.event_type;
|
|
63
|
+
const translatedEventType = (0, event_type_translation_1.translateIncomingEventType)(event.payload.event_type);
|
|
64
|
+
event.payload.event_type = translatedEventType;
|
|
65
|
+
// Read the command line arguments to check if the local flag is passed.
|
|
66
|
+
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
|
|
67
|
+
if (argv._.includes('local')) {
|
|
68
|
+
options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
|
|
69
|
+
}
|
|
70
|
+
const originalConsole = console;
|
|
71
|
+
// eslint-disable-next-line no-global-assign
|
|
72
|
+
console = new logger_1.Logger({ event, options });
|
|
73
|
+
if (translatedEventType !== originalEventType) {
|
|
74
|
+
console.log(`Event type translated from ${originalEventType} to ${translatedEventType}.`);
|
|
75
|
+
}
|
|
76
|
+
if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
|
|
77
|
+
console.log('Snap-in is running in local development mode.');
|
|
78
|
+
}
|
|
79
|
+
let script = null;
|
|
80
|
+
if (workerPath != null) {
|
|
81
|
+
script = workerPath;
|
|
82
|
+
}
|
|
83
|
+
else if (baseWorkerPath != null &&
|
|
84
|
+
(options === null || options === void 0 ? void 0 : options.workerPathOverrides) != null &&
|
|
85
|
+
options.workerPathOverrides[translatedEventType] != null) {
|
|
86
|
+
script =
|
|
87
|
+
baseWorkerPath +
|
|
88
|
+
options.workerPathOverrides[translatedEventType];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
script = getWorkerPath({
|
|
92
|
+
event,
|
|
93
|
+
workerBasePath: baseWorkerPath !== null && baseWorkerPath !== void 0 ? baseWorkerPath : __dirname,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// If a script is found for the event type, spawn a new worker.
|
|
97
|
+
if (script) {
|
|
98
|
+
try {
|
|
99
|
+
const worker = await (0, create_worker_1.createWorker)({
|
|
100
|
+
event,
|
|
101
|
+
initialState,
|
|
102
|
+
workerPath: script,
|
|
103
|
+
initialDomainMapping,
|
|
104
|
+
options,
|
|
105
|
+
});
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
new Spawn({
|
|
108
|
+
event,
|
|
109
|
+
worker,
|
|
110
|
+
options,
|
|
111
|
+
resolve,
|
|
112
|
+
originalConsole,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Worker error while processing task', error);
|
|
118
|
+
// eslint-disable-next-line no-global-assign
|
|
119
|
+
console = originalConsole;
|
|
120
|
+
return Promise.reject(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const { eventType } = (0, spawn_helpers_1.getNoScriptEventType)(event.payload.event_type);
|
|
125
|
+
await (0, control_protocol_1.emit)({
|
|
126
|
+
event,
|
|
127
|
+
eventType,
|
|
128
|
+
});
|
|
129
|
+
// eslint-disable-next-line no-global-assign
|
|
130
|
+
console = originalConsole;
|
|
131
|
+
return Promise.resolve();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class Spawn {
|
|
135
|
+
constructor({ event, worker, options, resolve, originalConsole, }) {
|
|
136
|
+
this.defaultLambdaTimeout = constants_1.DEFAULT_LAMBDA_TIMEOUT;
|
|
137
|
+
this.originalConsole = originalConsole || console;
|
|
138
|
+
this.logger = console;
|
|
139
|
+
this.alreadyEmitted = false;
|
|
140
|
+
this.event = event;
|
|
141
|
+
this.lambdaTimeout = (options === null || options === void 0 ? void 0 : options.timeout)
|
|
142
|
+
? Math.min(options.timeout, this.defaultLambdaTimeout)
|
|
143
|
+
: this.defaultLambdaTimeout;
|
|
144
|
+
this.resolve = resolve;
|
|
145
|
+
// If soft timeout is reached, send a message to the worker to gracefully exit.
|
|
146
|
+
this.softTimeoutTimer = setTimeout(() => void (async () => {
|
|
147
|
+
console.log('SOFT TIMEOUT: Sending a message to the worker to gracefully exit.');
|
|
148
|
+
if (worker) {
|
|
149
|
+
worker.postMessage({
|
|
150
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageExit,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log('Worker does not exist. Exiting from main thread.');
|
|
155
|
+
await this.exitFromMainThread();
|
|
156
|
+
}
|
|
157
|
+
})(), this.lambdaTimeout);
|
|
158
|
+
// If hard timeout is reached, that means the worker did not exit in time. Terminate the worker.
|
|
159
|
+
this.hardTimeoutTimer = setTimeout(() => void (async () => {
|
|
160
|
+
console.error('HARD TIMEOUT: Worker did not exit in time. Terminating the worker.');
|
|
161
|
+
if (worker) {
|
|
162
|
+
await worker.terminate();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
console.log('Worker does not exist. Exiting from main thread.');
|
|
166
|
+
await this.exitFromMainThread();
|
|
167
|
+
}
|
|
168
|
+
})(), this.lambdaTimeout * constants_1.HARD_TIMEOUT_MULTIPLIER);
|
|
169
|
+
// If worker exits with process.exit(code), clear the timeouts and exit from
|
|
170
|
+
// main thread.
|
|
171
|
+
worker.on(workers_1.WorkerEvent.WorkerExit, (code) => void (async () => {
|
|
172
|
+
console.info('Worker exited with exit code: ' + code + '.');
|
|
173
|
+
this.clearTimeouts();
|
|
174
|
+
await this.exitFromMainThread();
|
|
175
|
+
})());
|
|
176
|
+
worker.on(workers_1.WorkerEvent.WorkerMessage, (message) => {
|
|
177
|
+
var _a, _b, _c, _d;
|
|
178
|
+
// Since logs from the worker thread are handled differently in snap-in
|
|
179
|
+
// platform, we need to catch the log messages from worker thread and log
|
|
180
|
+
// them in main thread.
|
|
181
|
+
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
182
|
+
const stringifiedArgs = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.stringifiedArgs;
|
|
183
|
+
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
184
|
+
const isSdkLog = (_d = (_c = message.payload) === null || _c === void 0 ? void 0 : _c.isSdkLog) !== null && _d !== void 0 ? _d : false;
|
|
185
|
+
this.logger.logFn(stringifiedArgs, level, isSdkLog);
|
|
186
|
+
}
|
|
187
|
+
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
188
|
+
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
189
|
+
console.info('Worker has emitted message to ADaaS.');
|
|
190
|
+
this.alreadyEmitted = true;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
// Log memory usage every 30 seconds
|
|
194
|
+
this.memoryMonitoringInterval = setInterval(() => {
|
|
195
|
+
try {
|
|
196
|
+
const memoryInfo = (0, helpers_2.getMemoryUsage)();
|
|
197
|
+
if (memoryInfo) {
|
|
198
|
+
console.info(memoryInfo.formattedMessage);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
// If memory monitoring fails, log the warning and clear the interval to prevent further issues
|
|
203
|
+
console.warn('Memory monitoring failed, stopping logging of memory usage interval', error);
|
|
204
|
+
if (this.memoryMonitoringInterval) {
|
|
205
|
+
clearInterval(this.memoryMonitoringInterval);
|
|
206
|
+
this.memoryMonitoringInterval = undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}, constants_1.MEMORY_LOG_INTERVAL);
|
|
210
|
+
}
|
|
211
|
+
clearTimeouts() {
|
|
212
|
+
if (this.softTimeoutTimer) {
|
|
213
|
+
clearTimeout(this.softTimeoutTimer);
|
|
214
|
+
}
|
|
215
|
+
if (this.hardTimeoutTimer) {
|
|
216
|
+
clearTimeout(this.hardTimeoutTimer);
|
|
217
|
+
}
|
|
218
|
+
if (this.memoryMonitoringInterval) {
|
|
219
|
+
clearInterval(this.memoryMonitoringInterval);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async exitFromMainThread() {
|
|
223
|
+
this.clearTimeouts();
|
|
224
|
+
// eslint-disable-next-line no-global-assign
|
|
225
|
+
console = this.originalConsole;
|
|
226
|
+
if (this.alreadyEmitted) {
|
|
227
|
+
this.resolve();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.alreadyEmitted = true;
|
|
231
|
+
const { eventType } = (0, spawn_helpers_1.getTimeoutErrorEventType)(this.event.payload.event_type);
|
|
232
|
+
try {
|
|
233
|
+
await (0, control_protocol_1.emit)({
|
|
234
|
+
eventType,
|
|
235
|
+
event: this.event,
|
|
236
|
+
data: {
|
|
237
|
+
error: {
|
|
238
|
+
message: 'Worker exited the process without emitting an event. Check other logs for more information.',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
this.resolve();
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
console.error('Error while emitting event.', (0, logger_1.serializeError)(error));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.Spawn = Spawn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-adapter.artifacts.test.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.artifacts.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const state_1 = require("../../state/state");
|
|
4
|
+
const test_helpers_1 = require("../../tests/test-helpers");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const worker_adapter_1 = require("./worker-adapter");
|
|
7
|
+
// 1. Create a mock function for the method you want to override.
|
|
8
|
+
const mockUpload = (itemType, objects) => {
|
|
9
|
+
return {
|
|
10
|
+
error: null,
|
|
11
|
+
artifact: {
|
|
12
|
+
id: `artifact-${itemType}-${Math.random().toString(36).substring(2, 15)}`,
|
|
13
|
+
item_type: itemType,
|
|
14
|
+
item_count: objects.length,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
// 2. Mock the entire 'uploader' module.
|
|
19
|
+
// The factory function () => { ... } returns the mock implementation.
|
|
20
|
+
jest.mock('../../uploader/uploader', () => {
|
|
21
|
+
return {
|
|
22
|
+
// The mocked Uploader class
|
|
23
|
+
Uploader: jest.fn().mockImplementation(() => {
|
|
24
|
+
// The constructor of the mocked Uploader returns an object
|
|
25
|
+
// with the methods you want to control.
|
|
26
|
+
return {
|
|
27
|
+
upload: mockUpload,
|
|
28
|
+
};
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
function checkArtifactOrder(artifacts, expectedOrder) {
|
|
33
|
+
let outerIndex = 0;
|
|
34
|
+
for (const artifact of artifacts) {
|
|
35
|
+
try {
|
|
36
|
+
// Always increase outer index. If items are out of order, the array will overflow and exception will be thrown
|
|
37
|
+
while (artifact.item_type != expectedOrder[outerIndex].itemType) {
|
|
38
|
+
outerIndex++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error('Error finding artifact type in repos:', e);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
describe('Artifact ordering when artifacts overflow batch sizes in repositories', () => {
|
|
49
|
+
let testAdapter;
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
// Create a fresh adapter instance for this test to avoid mocking conflicts
|
|
52
|
+
const mockEvent = (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart });
|
|
53
|
+
const mockAdapterState = new state_1.State({
|
|
54
|
+
event: mockEvent,
|
|
55
|
+
initialState: { attachments: { completed: false } },
|
|
56
|
+
});
|
|
57
|
+
testAdapter = new worker_adapter_1.WorkerAdapter({
|
|
58
|
+
event: mockEvent,
|
|
59
|
+
adapterState: mockAdapterState,
|
|
60
|
+
options: {
|
|
61
|
+
batchSize: 50,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should maintain artifact ordering when repo ItemTypeA has items below batch size and repo ItemTypeB has items above batch size', async () => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const repos = [{ itemType: 'ItemTypeA' }, { itemType: 'ItemTypeB' }];
|
|
68
|
+
// Initialize repos
|
|
69
|
+
testAdapter.initializeRepos(repos);
|
|
70
|
+
await ((_a = testAdapter.getRepo('ItemTypeA')) === null || _a === void 0 ? void 0 : _a.push((0, test_helpers_1.createItems)(5)));
|
|
71
|
+
await ((_b = testAdapter.getRepo('ItemTypeB')) === null || _b === void 0 ? void 0 : _b.push((0, test_helpers_1.createItems)(105)));
|
|
72
|
+
await testAdapter.uploadAllRepos();
|
|
73
|
+
const artifacts = testAdapter.artifacts;
|
|
74
|
+
expect(artifacts.length).toBe(4);
|
|
75
|
+
expect(checkArtifactOrder(artifacts, repos)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('should work with more than 2 repos', async () => {
|
|
78
|
+
var _a, _b, _c, _d;
|
|
79
|
+
const repos = [
|
|
80
|
+
{ itemType: 'ItemTypeA' },
|
|
81
|
+
{ itemType: 'ItemTypeB' },
|
|
82
|
+
{ itemType: 'ItemTypeC' },
|
|
83
|
+
{ itemType: 'ItemTypeD' },
|
|
84
|
+
];
|
|
85
|
+
// Initialize repos
|
|
86
|
+
testAdapter.initializeRepos(repos);
|
|
87
|
+
await ((_a = testAdapter.getRepo('ItemTypeA')) === null || _a === void 0 ? void 0 : _a.push((0, test_helpers_1.createItems)(101)));
|
|
88
|
+
await ((_b = testAdapter.getRepo('ItemTypeB')) === null || _b === void 0 ? void 0 : _b.push((0, test_helpers_1.createItems)(102)));
|
|
89
|
+
await ((_c = testAdapter.getRepo('ItemTypeC')) === null || _c === void 0 ? void 0 : _c.push((0, test_helpers_1.createItems)(103)));
|
|
90
|
+
await ((_d = testAdapter.getRepo('ItemTypeD')) === null || _d === void 0 ? void 0 : _d.push((0, test_helpers_1.createItems)(104)));
|
|
91
|
+
await testAdapter.uploadAllRepos();
|
|
92
|
+
const artifacts = testAdapter.artifacts;
|
|
93
|
+
expect(artifacts.length).toBe(12);
|
|
94
|
+
expect(checkArtifactOrder(artifacts, repos)).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
it('should maintain order with multiple pushes and uploads', async () => {
|
|
97
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
98
|
+
const repos = [{ itemType: 'ItemTypeA' }, { itemType: 'ItemTypeB' }];
|
|
99
|
+
// Initialize repos
|
|
100
|
+
testAdapter.initializeRepos(repos);
|
|
101
|
+
await ((_a = testAdapter.getRepo('ItemTypeA')) === null || _a === void 0 ? void 0 : _a.push((0, test_helpers_1.createItems)(101)));
|
|
102
|
+
await ((_b = testAdapter.getRepo('ItemTypeB')) === null || _b === void 0 ? void 0 : _b.push((0, test_helpers_1.createItems)(102)));
|
|
103
|
+
await ((_c = testAdapter.getRepo('ItemTypeA')) === null || _c === void 0 ? void 0 : _c.push((0, test_helpers_1.createItems)(101)));
|
|
104
|
+
await ((_d = testAdapter.getRepo('ItemTypeB')) === null || _d === void 0 ? void 0 : _d.push((0, test_helpers_1.createItems)(102)));
|
|
105
|
+
await ((_e = testAdapter.getRepo('ItemTypeA')) === null || _e === void 0 ? void 0 : _e.upload());
|
|
106
|
+
await ((_f = testAdapter.getRepo('ItemTypeB')) === null || _f === void 0 ? void 0 : _f.upload());
|
|
107
|
+
await ((_g = testAdapter.getRepo('ItemTypeA')) === null || _g === void 0 ? void 0 : _g.push((0, test_helpers_1.createItems)(101)));
|
|
108
|
+
await ((_h = testAdapter.getRepo('ItemTypeB')) === null || _h === void 0 ? void 0 : _h.push((0, test_helpers_1.createItems)(102)));
|
|
109
|
+
await ((_j = testAdapter.getRepo('ItemTypeA')) === null || _j === void 0 ? void 0 : _j.push((0, test_helpers_1.createItems)(101)));
|
|
110
|
+
await ((_k = testAdapter.getRepo('ItemTypeB')) === null || _k === void 0 ? void 0 : _k.push((0, test_helpers_1.createItems)(102)));
|
|
111
|
+
await testAdapter.uploadAllRepos();
|
|
112
|
+
const artifacts = testAdapter.artifacts;
|
|
113
|
+
expect(artifacts.length).toBe(20);
|
|
114
|
+
expect(checkArtifactOrder(artifacts, repos)).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
it('should not count artifacts if 0 items are pushed to the repo', async () => {
|
|
117
|
+
var _a;
|
|
118
|
+
const repos = [{ itemType: 'ItemTypeA' }];
|
|
119
|
+
// Initialize repos
|
|
120
|
+
testAdapter.initializeRepos(repos);
|
|
121
|
+
await ((_a = testAdapter.getRepo('ItemTypeA')) === null || _a === void 0 ? void 0 : _a.push([]));
|
|
122
|
+
await testAdapter.uploadAllRepos();
|
|
123
|
+
const artifacts = testAdapter.artifacts;
|
|
124
|
+
expect(artifacts.length).toBe(0);
|
|
125
|
+
expect(checkArtifactOrder(artifacts, repos)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Mappers } from '../../mappers/mappers';
|
|
2
|
+
import { Repo } from '../../repo/repo';
|
|
3
|
+
import { NormalizedAttachment, RepoInterface } from '../../repo/repo.interfaces';
|
|
4
|
+
import { AdapterState } from '../../state/state.interfaces';
|
|
5
|
+
import { AirdropEvent, EventData, ExternalSystemAttachmentProcessors, ExternalSystemAttachmentStreamingFunction, ExtractorEventType, ProcessAttachmentReturnType, StreamAttachmentsReturnType } from '../../types/extraction';
|
|
6
|
+
import { ExternalSystemAttachment, ExternalSystemItem, ExternalSystemLoadingFunction, FileToLoad, ItemTypesToLoadParams, ItemTypeToLoad, LoaderEventType, LoaderReport, LoadItemResponse, LoadItemTypesResponse } from '../../types/loading';
|
|
7
|
+
import { WorkerAdapterInterface, WorkerAdapterOptions } from '../../types/workers';
|
|
8
|
+
import { Artifact } from '../../uploader/uploader.interfaces';
|
|
9
|
+
export declare function createWorkerAdapter<ConnectorState>({ event, adapterState, options, }: WorkerAdapterInterface<ConnectorState>): WorkerAdapter<ConnectorState>;
|
|
10
|
+
/**
|
|
11
|
+
* WorkerAdapter class is used to interact with Airdrop platform. It is passed to the snap-in
|
|
12
|
+
* as parameter in processTask and onTimeout functions. The class provides
|
|
13
|
+
* utilities to emit control events to the platform, update the state of the connector,
|
|
14
|
+
* and upload artifacts to the platform.
|
|
15
|
+
* @class WorkerAdapter
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param options - The options to create a new instance of WorkerAdapter class
|
|
18
|
+
* @param event - The event object received from the platform
|
|
19
|
+
* @param initialState - The initial state of the adapter
|
|
20
|
+
* @param isLocalDevelopment - A flag to indicate if the adapter is being used in local development
|
|
21
|
+
* @param workerPath - The path to the worker file
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare class WorkerAdapter<ConnectorState> {
|
|
26
|
+
readonly event: AirdropEvent;
|
|
27
|
+
readonly options?: WorkerAdapterOptions;
|
|
28
|
+
isTimeout: boolean;
|
|
29
|
+
private adapterState;
|
|
30
|
+
private _artifacts;
|
|
31
|
+
private hasWorkerEmitted;
|
|
32
|
+
private repos;
|
|
33
|
+
private loaderReports;
|
|
34
|
+
private _processedFiles;
|
|
35
|
+
private _mappers;
|
|
36
|
+
private uploader;
|
|
37
|
+
constructor({ event, adapterState, options, }: WorkerAdapterInterface<ConnectorState>);
|
|
38
|
+
get state(): AdapterState<ConnectorState>;
|
|
39
|
+
set state(value: AdapterState<ConnectorState>);
|
|
40
|
+
get reports(): LoaderReport[];
|
|
41
|
+
get processedFiles(): string[];
|
|
42
|
+
get mappers(): Mappers;
|
|
43
|
+
initializeRepos(repos: RepoInterface[]): void;
|
|
44
|
+
getRepo(itemType: string): Repo | undefined;
|
|
45
|
+
postState(): Promise<void>;
|
|
46
|
+
get artifacts(): Artifact[];
|
|
47
|
+
set artifacts(artifacts: Artifact[]);
|
|
48
|
+
/**
|
|
49
|
+
* Emits an event to the platform.
|
|
50
|
+
*
|
|
51
|
+
* @param newEventType - The event type to be emitted
|
|
52
|
+
* @param data - The data to be sent with the event
|
|
53
|
+
*/
|
|
54
|
+
emit(newEventType: ExtractorEventType | LoaderEventType, data?: EventData): Promise<void>;
|
|
55
|
+
uploadAllRepos(): Promise<void>;
|
|
56
|
+
handleTimeout(): void;
|
|
57
|
+
loadItemTypes({ itemTypesToLoad, }: ItemTypesToLoadParams): Promise<LoadItemTypesResponse>;
|
|
58
|
+
getLoaderBatches({ supportedItemTypes, }: {
|
|
59
|
+
supportedItemTypes: string[];
|
|
60
|
+
}): Promise<FileToLoad[]>;
|
|
61
|
+
loadAttachments({ create, }: {
|
|
62
|
+
create: ExternalSystemLoadingFunction<ExternalSystemAttachment>;
|
|
63
|
+
}): Promise<LoadItemTypesResponse>;
|
|
64
|
+
loadItem({ item, itemTypeToLoad, }: {
|
|
65
|
+
item: ExternalSystemItem;
|
|
66
|
+
itemTypeToLoad: ItemTypeToLoad;
|
|
67
|
+
}): Promise<LoadItemResponse>;
|
|
68
|
+
processAttachment(attachment: NormalizedAttachment, stream: ExternalSystemAttachmentStreamingFunction): Promise<ProcessAttachmentReturnType>;
|
|
69
|
+
/**
|
|
70
|
+
* Destroys a stream to prevent memory leaks.
|
|
71
|
+
* @param httpStream - The axios response stream to destroy
|
|
72
|
+
*/
|
|
73
|
+
private destroyHttpStream;
|
|
74
|
+
loadAttachment({ item, create, }: {
|
|
75
|
+
item: ExternalSystemAttachment;
|
|
76
|
+
create: ExternalSystemLoadingFunction<ExternalSystemAttachment>;
|
|
77
|
+
}): Promise<LoadItemResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Streams the attachments to the DevRev platform.
|
|
80
|
+
* The attachments are streamed to the platform and the artifact information is returned.
|
|
81
|
+
* @param params - The parameters to stream the attachments
|
|
82
|
+
* @returns The response object containing the ssorAttachment artifact information
|
|
83
|
+
* or error information if there was an error
|
|
84
|
+
*/
|
|
85
|
+
streamAttachments<NewBatch>({ stream, processors, batchSize, }: {
|
|
86
|
+
stream: ExternalSystemAttachmentStreamingFunction;
|
|
87
|
+
processors?: ExternalSystemAttachmentProcessors<ConnectorState, NormalizedAttachment[], NewBatch>;
|
|
88
|
+
batchSize?: number;
|
|
89
|
+
}): Promise<StreamAttachmentsReturnType>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=worker-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FileToLoad, LoaderReport, StatsFileObject } from '../../types/loading';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the files to load for the loader.
|
|
4
|
+
* @param {string[]} supportedItemTypes - The supported item types
|
|
5
|
+
* @param {StatsFileObject[]} statsFile - The stats file
|
|
6
|
+
* @returns {FileToLoad[]} The files to load
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFilesToLoad({ supportedItemTypes, statsFile, }: {
|
|
9
|
+
supportedItemTypes: string[];
|
|
10
|
+
statsFile: StatsFileObject[];
|
|
11
|
+
}): FileToLoad[];
|
|
12
|
+
/**
|
|
13
|
+
* Adds a report to the loader report.
|
|
14
|
+
* @param {LoaderReport[]} loaderReports - The loader reports
|
|
15
|
+
* @param {LoaderReport} report - The report to add
|
|
16
|
+
* @returns {LoaderReport[]} The updated loader reports
|
|
17
|
+
*/
|
|
18
|
+
export declare function addReportToLoaderReport({ loaderReports, report, }: {
|
|
19
|
+
loaderReports: LoaderReport[];
|
|
20
|
+
report: LoaderReport;
|
|
21
|
+
}): LoaderReport[];
|
|
22
|
+
//# sourceMappingURL=worker-adapter.helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-adapter.helpers.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAC7B,kBAAkB,EAClB,SAAS,GACV,EAAE;IACD,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,SAAS,EAAE,eAAe,EAAE,CAAC;CAC9B,GAAG,UAAU,EAAE,CA8Bf;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,aAAa,EACb,MAAM,GACP,EAAE;IACD,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,MAAM,EAAE,YAAY,CAAC;CACtB,GAAG,YAAY,EAAE,CA4BjB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilesToLoad = getFilesToLoad;
|
|
4
|
+
exports.addReportToLoaderReport = addReportToLoaderReport;
|
|
5
|
+
const loading_1 = require("../../types/loading");
|
|
6
|
+
/**
|
|
7
|
+
* Gets the files to load for the loader.
|
|
8
|
+
* @param {string[]} supportedItemTypes - The supported item types
|
|
9
|
+
* @param {StatsFileObject[]} statsFile - The stats file
|
|
10
|
+
* @returns {FileToLoad[]} The files to load
|
|
11
|
+
*/
|
|
12
|
+
function getFilesToLoad({ supportedItemTypes, statsFile, }) {
|
|
13
|
+
const filesToLoad = [];
|
|
14
|
+
if (supportedItemTypes.length === 0 || statsFile.length === 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const filteredStatsFile = statsFile.filter((file) => supportedItemTypes.includes(file.item_type));
|
|
18
|
+
const orderedFiles = filteredStatsFile.sort((a, b) => {
|
|
19
|
+
const aIndex = supportedItemTypes.indexOf(a.item_type);
|
|
20
|
+
const bIndex = supportedItemTypes.indexOf(b.item_type);
|
|
21
|
+
return aIndex - bIndex;
|
|
22
|
+
});
|
|
23
|
+
for (const file of orderedFiles) {
|
|
24
|
+
filesToLoad.push({
|
|
25
|
+
id: file.id,
|
|
26
|
+
file_name: file.file_name,
|
|
27
|
+
itemType: file.item_type,
|
|
28
|
+
count: parseInt(file.count),
|
|
29
|
+
completed: false,
|
|
30
|
+
lineToProcess: 0,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return filesToLoad;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Adds a report to the loader report.
|
|
37
|
+
* @param {LoaderReport[]} loaderReports - The loader reports
|
|
38
|
+
* @param {LoaderReport} report - The report to add
|
|
39
|
+
* @returns {LoaderReport[]} The updated loader reports
|
|
40
|
+
*/
|
|
41
|
+
function addReportToLoaderReport({ loaderReports, report, }) {
|
|
42
|
+
const existingReport = loaderReports.find((loaderReport) => loaderReport.item_type === report.item_type);
|
|
43
|
+
if (existingReport) {
|
|
44
|
+
existingReport[loading_1.ActionType.CREATED] = existingReport[loading_1.ActionType.CREATED]
|
|
45
|
+
? report[loading_1.ActionType.CREATED]
|
|
46
|
+
? existingReport[loading_1.ActionType.CREATED] + report[loading_1.ActionType.CREATED]
|
|
47
|
+
: existingReport[loading_1.ActionType.CREATED]
|
|
48
|
+
: report[loading_1.ActionType.CREATED];
|
|
49
|
+
existingReport[loading_1.ActionType.UPDATED] = existingReport[loading_1.ActionType.UPDATED]
|
|
50
|
+
? report[loading_1.ActionType.UPDATED]
|
|
51
|
+
? existingReport[loading_1.ActionType.UPDATED] + report[loading_1.ActionType.UPDATED]
|
|
52
|
+
: existingReport[loading_1.ActionType.UPDATED]
|
|
53
|
+
: report[loading_1.ActionType.UPDATED];
|
|
54
|
+
existingReport[loading_1.ActionType.FAILED] = existingReport[loading_1.ActionType.FAILED]
|
|
55
|
+
? report[loading_1.ActionType.FAILED]
|
|
56
|
+
? existingReport[loading_1.ActionType.FAILED] + report[loading_1.ActionType.FAILED]
|
|
57
|
+
: existingReport[loading_1.ActionType.FAILED]
|
|
58
|
+
: report[loading_1.ActionType.FAILED];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
loaderReports.push(report);
|
|
62
|
+
}
|
|
63
|
+
return loaderReports;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-adapter.helpers.test.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.helpers.test.ts"],"names":[],"mappings":""}
|