@devrev/airsync-sdk 2.0.0-beta.2 → 2.0.0-beta.4
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 +5 -11
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +1 -8
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +4 -3
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +11 -39
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +2 -1
- package/dist/common/helpers.d.ts +0 -14
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +0 -36
- package/dist/http/{axios-client-internal.d.ts → client.d.ts} +1 -1
- package/dist/http/client.d.ts.map +1 -0
- package/dist/index.d.ts +25 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -30
- package/dist/logger/logger.d.ts +14 -0
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +55 -8
- package/dist/mappers/mappers.d.ts +9 -10
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/{mappers.interface.d.ts → mappers.interfaces.d.ts} +5 -5
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +3 -3
- package/dist/mappers/mappers.js +13 -9
- package/dist/multithreading/adapters/base-adapter.d.ts +71 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.js +138 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts +57 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +323 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts +44 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.d.ts → adapters/loading-adapter.helpers.d.ts} +1 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.js +431 -0
- package/dist/{common/control-protocol.d.ts → multithreading/emit.d.ts} +1 -1
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/{common/control-protocol.js → multithreading/emit.js} +3 -3
- package/dist/multithreading/process-task.d.ts +16 -1
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +115 -50
- package/dist/multithreading/spawn/spawn.helpers.d.ts +23 -3
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +152 -2
- package/dist/multithreading/spawn/spawn.js +7 -7
- package/dist/multithreading/worker.js +1 -2
- package/dist/repo/repo.js +2 -2
- package/dist/state/base-state.d.ts +75 -0
- package/dist/state/base-state.d.ts.map +1 -0
- package/dist/state/base-state.js +261 -0
- package/dist/state/extraction-state.d.ts +29 -0
- package/dist/state/extraction-state.d.ts.map +1 -0
- package/dist/state/extraction-state.js +122 -0
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/{common → state}/install-initial-domain-mapping.js +4 -4
- package/dist/state/loading-state.d.ts +18 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +39 -0
- package/dist/state/state.d.ts +3 -35
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +20 -3
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +19 -1
- package/dist/state/state.js +9 -263
- package/dist/{common → state}/time-value-resolver.d.ts +4 -5
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/{common → state}/time-value-resolver.js +9 -8
- package/dist/{common/test-utils.d.ts → testing/mock-event.d.ts} +1 -2
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/{common/test-utils.js → testing/mock-event.js} +14 -3
- package/dist/{mock-server → testing}/mock-server.d.ts +5 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/{mock-server → testing}/mock-server.js +6 -1
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/extraction.d.ts +73 -18
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +4 -6
- package/dist/types/loading.d.ts +1 -2
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +0 -1
- package/dist/types/workers.d.ts +64 -20
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/uploader/uploader.d.ts +5 -4
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.d.ts +1 -1
- package/dist/uploader/uploader.js +10 -10
- package/package.json +3 -3
- package/dist/airsync-sdk.d.ts +0 -1802
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +0 -2
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +0 -1
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +0 -516
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.js +0 -211
- package/dist/common/test-utils.d.ts.map +0 -1
- package/dist/common/time-value-resolver.d.ts.map +0 -1
- package/dist/common/time-value-resolver.test.d.ts +0 -2
- package/dist/common/time-value-resolver.test.d.ts.map +0 -1
- package/dist/common/time-value-resolver.test.js +0 -268
- package/dist/http/axios-client-internal.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.d.ts +0 -2
- package/dist/http/axios-client-internal.test.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.js +0 -175
- package/dist/http/axios-client.d.ts +0 -27
- package/dist/http/axios-client.d.ts.map +0 -1
- package/dist/http/axios-client.js +0 -60
- package/dist/http/constants.d.ts +0 -4
- package/dist/http/constants.d.ts.map +0 -1
- package/dist/http/constants.js +0 -6
- package/dist/http/index.d.ts +0 -2
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -17
- package/dist/logger/logger.constants.d.ts +0 -6
- package/dist/logger/logger.constants.d.ts.map +0 -1
- package/dist/logger/logger.constants.js +0 -13
- package/dist/logger/logger.context.d.ts +0 -58
- package/dist/logger/logger.context.d.ts.map +0 -1
- package/dist/logger/logger.context.js +0 -86
- package/dist/logger/logger.test.d.ts +0 -2
- package/dist/logger/logger.test.d.ts.map +0 -1
- package/dist/logger/logger.test.js +0 -537
- package/dist/mappers/mappers.interface.d.ts.map +0 -1
- package/dist/mappers/mappers.test.d.ts +0 -2
- package/dist/mappers/mappers.test.d.ts.map +0 -1
- package/dist/mappers/mappers.test.js +0 -105
- package/dist/mock-server/mock-server.d.ts.map +0 -1
- package/dist/mock-server/mock-server.interfaces.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.d.ts +0 -2
- package/dist/multithreading/create-worker.test.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.js +0 -108
- package/dist/multithreading/process-task.test.d.ts +0 -2
- package/dist/multithreading/process-task.test.d.ts.map +0 -1
- package/dist/multithreading/process-task.test.js +0 -146
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
- package/dist/multithreading/spawn/spawn.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.test.js +0 -232
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -175
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -97
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.js +0 -390
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.js +0 -799
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
- package/dist/multithreading/worker-adapter/worker-adapter.js +0 -846
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.js +0 -596
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.js +0 -71
- package/dist/repo/repo.test.d.ts +0 -2
- package/dist/repo/repo.test.d.ts.map +0 -1
- package/dist/repo/repo.test.js +0 -184
- package/dist/state/state.extract-window.test.d.ts +0 -2
- package/dist/state/state.extract-window.test.d.ts.map +0 -1
- package/dist/state/state.extract-window.test.js +0 -163
- package/dist/state/state.pending-boundaries.test.d.ts +0 -2
- package/dist/state/state.pending-boundaries.test.d.ts.map +0 -1
- package/dist/state/state.pending-boundaries.test.js +0 -189
- package/dist/state/state.post-state.test.d.ts +0 -2
- package/dist/state/state.post-state.test.d.ts.map +0 -1
- package/dist/state/state.post-state.test.js +0 -77
- package/dist/state/state.test.d.ts +0 -2
- package/dist/state/state.test.d.ts.map +0 -1
- package/dist/state/state.test.js +0 -268
- package/dist/state/state.time-value-resolution.test.d.ts +0 -2
- package/dist/state/state.time-value-resolution.test.d.ts.map +0 -1
- package/dist/state/state.time-value-resolution.test.js +0 -175
- package/dist/tsdoc-metadata.json +0 -11
- package/dist/types/extraction.test.d.ts +0 -2
- package/dist/types/extraction.test.d.ts.map +0 -1
- package/dist/types/extraction.test.js +0 -96
- package/dist/types/index.d.ts +0 -11
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -21
- package/dist/uploader/uploader.helpers.test.d.ts +0 -2
- package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
- package/dist/uploader/uploader.helpers.test.js +0 -256
- package/dist/uploader/uploader.test.d.ts +0 -2
- package/dist/uploader/uploader.test.d.ts.map +0 -1
- package/dist/uploader/uploader.test.js +0 -601
- /package/dist/http/{axios-client-internal.js → client.js} +0 -0
- /package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +0 -0
- /package/dist/{common → state}/install-initial-domain-mapping.d.ts +0 -0
- /package/dist/{mock-server → testing}/mock-server.interfaces.d.ts +0 -0
- /package/dist/{mock-server → testing}/mock-server.interfaces.js +0 -0
- /package/dist/{common → types}/errors.js +0 -0
|
@@ -0,0 +1,431 @@
|
|
|
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.LoadingAdapter = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const logger_1 = require("../../logger/logger");
|
|
9
|
+
const mappers_1 = require("../../mappers/mappers");
|
|
10
|
+
const mappers_interfaces_1 = require("../../mappers/mappers.interfaces");
|
|
11
|
+
const extraction_1 = require("../../types/extraction");
|
|
12
|
+
const loading_1 = require("../../types/loading");
|
|
13
|
+
const base_adapter_1 = require("./base-adapter");
|
|
14
|
+
const loading_adapter_helpers_1 = require("./loading-adapter.helpers");
|
|
15
|
+
/**
|
|
16
|
+
* LoadingAdapter is the adapter passed to loading tasks. It exposes the loading
|
|
17
|
+
* surface (item/attachment loading, mappers, loader reports).
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class LoadingAdapter extends base_adapter_1.BaseAdapter {
|
|
22
|
+
constructor(params) {
|
|
23
|
+
super(params);
|
|
24
|
+
this.loaderReports = [];
|
|
25
|
+
this._processedFiles = [];
|
|
26
|
+
this._mappers = new mappers_1.Mappers({
|
|
27
|
+
event: params.event,
|
|
28
|
+
options: params.options,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
get reports() {
|
|
32
|
+
return this.loaderReports;
|
|
33
|
+
}
|
|
34
|
+
get processedFiles() {
|
|
35
|
+
return this._processedFiles;
|
|
36
|
+
}
|
|
37
|
+
get mappers() {
|
|
38
|
+
return this._mappers;
|
|
39
|
+
}
|
|
40
|
+
async beforeEmit() {
|
|
41
|
+
// Loading has no pre-emit work (no repos, no extraction boundaries).
|
|
42
|
+
}
|
|
43
|
+
buildEmitPayload(newEventType) {
|
|
44
|
+
const isLoaderEvent = Object.values(loading_1.LoaderEventType).includes(newEventType);
|
|
45
|
+
return isLoaderEvent
|
|
46
|
+
? {
|
|
47
|
+
reports: this.reports,
|
|
48
|
+
processed_files: this.processedFiles,
|
|
49
|
+
}
|
|
50
|
+
: {};
|
|
51
|
+
}
|
|
52
|
+
afterEmit() {
|
|
53
|
+
// Loading keeps its accumulated reports/processed files across emits.
|
|
54
|
+
}
|
|
55
|
+
async loadItemTypes({ itemTypesToLoad, }) {
|
|
56
|
+
return (0, logger_1.runWithSdkLogContext)(async () => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartLoadingData) {
|
|
59
|
+
const itemTypes = itemTypesToLoad.map((itemTypeToLoad) => itemTypeToLoad.itemType);
|
|
60
|
+
if (!itemTypes.length) {
|
|
61
|
+
console.warn('No item types to load, returning.');
|
|
62
|
+
return { status: 'success' };
|
|
63
|
+
}
|
|
64
|
+
const filesToLoad = await this.getLoaderBatches({
|
|
65
|
+
supportedItemTypes: itemTypes,
|
|
66
|
+
});
|
|
67
|
+
this.sdkState.fromDevRev = {
|
|
68
|
+
filesToLoad,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (!this.sdkState.fromDevRev ||
|
|
72
|
+
!this.sdkState.fromDevRev.filesToLoad.length) {
|
|
73
|
+
console.warn('No files to load, returning.');
|
|
74
|
+
return { status: 'success' };
|
|
75
|
+
}
|
|
76
|
+
console.log('Files to load in state', (_a = this.sdkState.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad);
|
|
77
|
+
try {
|
|
78
|
+
for (const fileToLoad of this.sdkState.fromDevRev.filesToLoad) {
|
|
79
|
+
const itemTypeToLoad = itemTypesToLoad.find((itemTypeToLoad) => itemTypeToLoad.itemType === fileToLoad.itemType);
|
|
80
|
+
if (!itemTypeToLoad) {
|
|
81
|
+
console.error(`Item type to load not found for item type: ${fileToLoad.itemType}.`);
|
|
82
|
+
return {
|
|
83
|
+
status: 'error',
|
|
84
|
+
error: {
|
|
85
|
+
message: `Item type to load not found for item type: ${fileToLoad.itemType}.`,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (!fileToLoad.completed) {
|
|
90
|
+
const { response, error: transformerFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
91
|
+
artifactId: fileToLoad.id,
|
|
92
|
+
isGzipped: true,
|
|
93
|
+
});
|
|
94
|
+
if (transformerFileError) {
|
|
95
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
96
|
+
return {
|
|
97
|
+
status: 'error',
|
|
98
|
+
error: {
|
|
99
|
+
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const transformerFile = response;
|
|
104
|
+
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
105
|
+
if (this.isTimeout) {
|
|
106
|
+
console.log('Timeout detected during data loading. Returning progress to allow continuation.');
|
|
107
|
+
return { status: 'progress' };
|
|
108
|
+
}
|
|
109
|
+
const { report, rateLimit } = await this.loadItem({
|
|
110
|
+
item: transformerFile[i],
|
|
111
|
+
itemTypeToLoad,
|
|
112
|
+
});
|
|
113
|
+
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
114
|
+
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
115
|
+
}
|
|
116
|
+
if (report) {
|
|
117
|
+
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
118
|
+
loaderReports: this.loaderReports,
|
|
119
|
+
report,
|
|
120
|
+
});
|
|
121
|
+
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
fileToLoad.completed = true;
|
|
125
|
+
this._processedFiles.push(fileToLoad.id);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error('Error during data loading.', (0, logger_1.serializeError)(error));
|
|
131
|
+
return {
|
|
132
|
+
status: 'error',
|
|
133
|
+
error: {
|
|
134
|
+
message: `Error during data loading. ${(0, logger_1.serializeError)(error)}`,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return { status: 'success' };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async getLoaderBatches({ supportedItemTypes, }) {
|
|
142
|
+
return (0, logger_1.runWithSdkLogContext)(async () => {
|
|
143
|
+
var _a;
|
|
144
|
+
const statsFileArtifactId = (_a = this.event.payload.event_data) === null || _a === void 0 ? void 0 : _a.stats_file;
|
|
145
|
+
if (statsFileArtifactId) {
|
|
146
|
+
const { response, error: statsFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
147
|
+
artifactId: statsFileArtifactId,
|
|
148
|
+
});
|
|
149
|
+
const statsFile = response;
|
|
150
|
+
if (statsFileError || statsFile.length === 0) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
const filesToLoad = (0, loading_adapter_helpers_1.getFilesToLoad)({
|
|
154
|
+
supportedItemTypes,
|
|
155
|
+
statsFile,
|
|
156
|
+
});
|
|
157
|
+
return filesToLoad;
|
|
158
|
+
}
|
|
159
|
+
return [];
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async loadAttachments({ create, }) {
|
|
163
|
+
return (0, logger_1.runWithSdkLogContext)(async () => {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartLoadingAttachments) {
|
|
166
|
+
this.sdkState.fromDevRev = {
|
|
167
|
+
filesToLoad: await this.getLoaderBatches({
|
|
168
|
+
supportedItemTypes: ['attachment'],
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (!this.sdkState.fromDevRev ||
|
|
173
|
+
((_a = this.sdkState.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad.length) === 0) {
|
|
174
|
+
console.log('No files to load, returning.');
|
|
175
|
+
return { status: 'success' };
|
|
176
|
+
}
|
|
177
|
+
const filesToLoad = (_b = this.sdkState.fromDevRev) === null || _b === void 0 ? void 0 : _b.filesToLoad;
|
|
178
|
+
try {
|
|
179
|
+
for (const fileToLoad of filesToLoad) {
|
|
180
|
+
if (!fileToLoad.completed) {
|
|
181
|
+
const { response, error: transformerFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
182
|
+
artifactId: fileToLoad.id,
|
|
183
|
+
isGzipped: true,
|
|
184
|
+
});
|
|
185
|
+
const transformerFile = response;
|
|
186
|
+
if (transformerFileError) {
|
|
187
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
188
|
+
return {
|
|
189
|
+
status: 'error',
|
|
190
|
+
error: {
|
|
191
|
+
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
196
|
+
if (this.isTimeout) {
|
|
197
|
+
console.log('Timeout detected during attachment loading. Returning progress to allow continuation.');
|
|
198
|
+
return { status: 'progress' };
|
|
199
|
+
}
|
|
200
|
+
const { report, rateLimit } = await this.loadAttachment({
|
|
201
|
+
item: transformerFile[i],
|
|
202
|
+
create,
|
|
203
|
+
});
|
|
204
|
+
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
205
|
+
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
206
|
+
}
|
|
207
|
+
if (report) {
|
|
208
|
+
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
209
|
+
loaderReports: this.loaderReports,
|
|
210
|
+
report,
|
|
211
|
+
});
|
|
212
|
+
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
fileToLoad.completed = true;
|
|
216
|
+
this._processedFiles.push(fileToLoad.id);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.error('Error during attachment loading.', (0, logger_1.serializeError)(error));
|
|
222
|
+
return {
|
|
223
|
+
status: 'error',
|
|
224
|
+
error: {
|
|
225
|
+
message: `Error during attachment loading. ${(0, logger_1.serializeError)(error)}`,
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return { status: 'success' };
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async loadItem({ item, itemTypeToLoad, }) {
|
|
233
|
+
return (0, logger_1.runWithSdkLogContext)(async () => {
|
|
234
|
+
var _a;
|
|
235
|
+
const devrevId = item.id.devrev;
|
|
236
|
+
try {
|
|
237
|
+
const syncMapperRecord = await this._mappers.getByTargetId({
|
|
238
|
+
sync_unit: this.event.payload.event_context.sync_unit,
|
|
239
|
+
target: devrevId,
|
|
240
|
+
});
|
|
241
|
+
if (!syncMapperRecord) {
|
|
242
|
+
console.warn('Failed to get sync mapper record from response.');
|
|
243
|
+
return {
|
|
244
|
+
error: {
|
|
245
|
+
message: 'Failed to get sync mapper record from response.',
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
// Update item in external system
|
|
250
|
+
const { id, modifiedDate, delay, error } = await (0, logger_1.runWithUserLogContext)(async () => {
|
|
251
|
+
return await itemTypeToLoad.update({
|
|
252
|
+
item,
|
|
253
|
+
mappers: this._mappers,
|
|
254
|
+
event: this.event,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
if (id) {
|
|
258
|
+
try {
|
|
259
|
+
const syncMapperRecordUpdate = await this._mappers.update(Object.assign(Object.assign({ id: syncMapperRecord.sync_mapper_record.id, sync_unit: this.event.payload.event_context.sync_unit, status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL }, (modifiedDate && {
|
|
260
|
+
external_versions: {
|
|
261
|
+
add: [
|
|
262
|
+
{
|
|
263
|
+
modified_date: modifiedDate,
|
|
264
|
+
recipe_version: 0,
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
})), { external_ids: {
|
|
269
|
+
add: [id],
|
|
270
|
+
}, targets: {
|
|
271
|
+
add: [devrevId],
|
|
272
|
+
} }));
|
|
273
|
+
console.log('Successfully updated sync mapper record.', syncMapperRecordUpdate);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
console.warn('Failed to update sync mapper record.', (0, logger_1.serializeError)(error));
|
|
277
|
+
return {
|
|
278
|
+
error: {
|
|
279
|
+
message: 'Failed to update sync mapper record' + (0, logger_1.serializeError)(error),
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
report: {
|
|
285
|
+
item_type: itemTypeToLoad.itemType,
|
|
286
|
+
[loading_1.ActionType.UPDATED]: 1,
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
else if (delay) {
|
|
291
|
+
console.log(`Rate limited while updating item in external system, delaying for ${delay} seconds.`);
|
|
292
|
+
return {
|
|
293
|
+
rateLimit: {
|
|
294
|
+
delay,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
console.warn('Failed to update item in external system', error);
|
|
300
|
+
return {
|
|
301
|
+
report: {
|
|
302
|
+
item_type: itemTypeToLoad.itemType,
|
|
303
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
// TODO: Update mapper (optional)
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
311
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
312
|
+
// Create item in external system if mapper record not found
|
|
313
|
+
const { id, modifiedDate, delay, error } = await (0, logger_1.runWithUserLogContext)(async () => {
|
|
314
|
+
return await itemTypeToLoad.create({
|
|
315
|
+
item,
|
|
316
|
+
mappers: this._mappers,
|
|
317
|
+
event: this.event,
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
if (id) {
|
|
321
|
+
// Create mapper
|
|
322
|
+
try {
|
|
323
|
+
const syncMapperRecordCreate = await this._mappers.create(Object.assign({ sync_unit: this.event.payload.event_context.sync_unit, status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL, external_ids: [id], targets: [devrevId] }, (modifiedDate && {
|
|
324
|
+
external_versions: [
|
|
325
|
+
{
|
|
326
|
+
modified_date: modifiedDate,
|
|
327
|
+
recipe_version: 0,
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
})));
|
|
331
|
+
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
332
|
+
return {
|
|
333
|
+
report: {
|
|
334
|
+
item_type: itemTypeToLoad.itemType,
|
|
335
|
+
[loading_1.ActionType.CREATED]: 1,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
341
|
+
return {
|
|
342
|
+
error: {
|
|
343
|
+
message: 'Failed to create sync mapper record. ' +
|
|
344
|
+
(0, logger_1.serializeError)(error),
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else if (delay) {
|
|
350
|
+
return {
|
|
351
|
+
rateLimit: {
|
|
352
|
+
delay,
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
console.warn('Failed to create item in external system.', (0, logger_1.serializeError)(error));
|
|
358
|
+
return {
|
|
359
|
+
report: {
|
|
360
|
+
item_type: itemTypeToLoad.itemType,
|
|
361
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
|
|
368
|
+
return {
|
|
369
|
+
error: {
|
|
370
|
+
message: error.message,
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
|
|
376
|
+
return {
|
|
377
|
+
error: {
|
|
378
|
+
message: 'Failed to get sync mapper record. ' + (0, logger_1.serializeError)(error),
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
async loadAttachment({ item, create, }) {
|
|
385
|
+
return (0, logger_1.runWithSdkLogContext)(async () => {
|
|
386
|
+
// Create item
|
|
387
|
+
const { id, delay, error } = await (0, logger_1.runWithUserLogContext)(async () => create({
|
|
388
|
+
item,
|
|
389
|
+
mappers: this._mappers,
|
|
390
|
+
event: this.event,
|
|
391
|
+
}));
|
|
392
|
+
if (delay) {
|
|
393
|
+
return {
|
|
394
|
+
rateLimit: {
|
|
395
|
+
delay,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
else if (id) {
|
|
400
|
+
try {
|
|
401
|
+
const syncMapperRecordCreate = await this._mappers.create({
|
|
402
|
+
sync_unit: this.event.payload.event_context.sync_unit,
|
|
403
|
+
external_ids: [id],
|
|
404
|
+
targets: [item.reference_id],
|
|
405
|
+
status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL,
|
|
406
|
+
});
|
|
407
|
+
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
report: {
|
|
414
|
+
item_type: 'attachment',
|
|
415
|
+
[loading_1.ActionType.CREATED]: 1,
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
console.warn('Failed to create attachment in external system', error);
|
|
421
|
+
return {
|
|
422
|
+
report: {
|
|
423
|
+
item_type: 'attachment',
|
|
424
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
exports.LoadingAdapter = LoadingAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/multithreading/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,kBAAkB,GAAG,eAAe,CAAC;IAChD,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,eAAO,MAAM,IAAI,GAAU,6BAIxB,aAAa,KAAG,OAAO,CAAC,aAAa,CA4BvC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.emit = void 0;
|
|
4
|
-
const
|
|
5
|
-
const constants_1 = require("
|
|
4
|
+
const client_1 = require("../http/client");
|
|
5
|
+
const constants_1 = require("../common/constants");
|
|
6
6
|
const emit = async ({ event, eventType, data, }) => {
|
|
7
7
|
const newEvent = {
|
|
8
8
|
event_type: eventType,
|
|
@@ -13,7 +13,7 @@ const emit = async ({ event, eventType, data, }) => {
|
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
15
|
console.info('Emitting event', newEvent);
|
|
16
|
-
return
|
|
16
|
+
return client_1.axiosClient.post(event.payload.event_context.callback_url, Object.assign({}, newEvent), {
|
|
17
17
|
headers: {
|
|
18
18
|
Accept: 'application/json, text/plain, */*',
|
|
19
19
|
Authorization: event.context.secrets.service_account_token,
|
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
import { ProcessTaskInterface } from '../types/workers';
|
|
2
|
-
|
|
2
|
+
import { ExtractionAdapter } from './adapters/extraction-adapter';
|
|
3
|
+
import { LoadingAdapter } from './adapters/loading-adapter';
|
|
4
|
+
/**
|
|
5
|
+
* Entry point for an extraction worker. Builds an {@link ExtractionAdapter} and
|
|
6
|
+
* runs the provided task against it.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function processExtractionTask<ConnectorState>({ task, onTimeout, }: ProcessTaskInterface<ExtractionAdapter<ConnectorState>>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Entry point for a loading worker. Builds a {@link LoadingAdapter} and runs the
|
|
13
|
+
* provided task against it.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare function processLoadingTask<ConnectorState>({ task, onTimeout, }: ProcessTaskInterface<LoadingAdapter<ConnectorState>>): void;
|
|
3
18
|
//# sourceMappingURL=process-task.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/multithreading/process-task.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/multithreading/process-task.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,oBAAoB,EAIrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAoE5D;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,EACpD,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,QA6BzD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,EACjD,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,QA6BtD"}
|
|
@@ -1,60 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.processExtractionTask = processExtractionTask;
|
|
4
|
+
exports.processLoadingTask = processLoadingTask;
|
|
4
5
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
5
6
|
const logger_1 = require("../logger/logger");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const extraction_state_1 = require("../state/extraction-state");
|
|
8
|
+
const loading_state_1 = require("../state/loading-state");
|
|
8
9
|
const workers_1 = require("../types/workers");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
console.log('Timeout received. Waiting for the task to finish.');
|
|
39
|
-
adapter.isTimeout = true;
|
|
40
|
-
});
|
|
41
|
-
await (0, logger_context_1.runWithUserLogContext)(async () => task({ adapter }));
|
|
42
|
-
if (adapter.isTimeout && !adapter.hasWorkerEmitted) {
|
|
43
|
-
await (0, logger_context_1.runWithUserLogContext)(async () => onTimeout({ adapter }));
|
|
10
|
+
const extraction_adapter_1 = require("./adapters/extraction-adapter");
|
|
11
|
+
const loading_adapter_1 = require("./adapters/loading-adapter");
|
|
12
|
+
/**
|
|
13
|
+
* Shared worker-thread driver. Builds the logger context, runs the task and
|
|
14
|
+
* (on timeout) the onTimeout callback against the provided adapter, maps the
|
|
15
|
+
* returned {@link TaskResult} to a platform event and emits it exactly once,
|
|
16
|
+
* and wires the error/exit plumbing.
|
|
17
|
+
*
|
|
18
|
+
* The adapter is constructed by the caller so each entry point can build its
|
|
19
|
+
* own typed adapter.
|
|
20
|
+
*
|
|
21
|
+
* If `onTimeout` is omitted, the SDK emits a phase-appropriate default on
|
|
22
|
+
* timeout: `progress` (resumable phases) or `error` (non-resumable phases) is
|
|
23
|
+
* handled by the status->event mapping when we emit a `progress` result.
|
|
24
|
+
*
|
|
25
|
+
* On timeout the timeout outcome always wins: once the soft timeout has fired,
|
|
26
|
+
* the SDK emits the `onTimeout` result (or the default `progress`) and ignores
|
|
27
|
+
* whatever the task returned, because a phase that ran out of time must hand off
|
|
28
|
+
* for continuation rather than report itself complete.
|
|
29
|
+
*/
|
|
30
|
+
async function runWorkerTask(buildAdapter, { task, onTimeout }) {
|
|
31
|
+
await (0, logger_1.runWithSdkLogContext)(async () => {
|
|
32
|
+
try {
|
|
33
|
+
const adapter = await buildAdapter();
|
|
34
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.on(workers_1.WorkerEvent.WorkerMessage, (message) => {
|
|
35
|
+
if (message.subject !== workers_1.WorkerMessageSubject.WorkerMessageExit) {
|
|
36
|
+
return;
|
|
44
37
|
}
|
|
45
|
-
|
|
38
|
+
console.log('Timeout received. Waiting for the task to finish.');
|
|
39
|
+
adapter.isTimeout = true;
|
|
40
|
+
});
|
|
41
|
+
let result = await (0, logger_1.runWithUserLogContext)(async () => task({ adapter }));
|
|
42
|
+
// If the soft timeout fired, the timeout outcome wins regardless of what
|
|
43
|
+
// the task returned: hand off via onTimeout (or the default progress
|
|
44
|
+
// result) so the phase continues in a fresh invocation.
|
|
45
|
+
if (adapter.isTimeout) {
|
|
46
|
+
result = onTimeout
|
|
47
|
+
? await (0, logger_1.runWithUserLogContext)(async () => onTimeout({ adapter }))
|
|
48
|
+
: { status: 'progress' };
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
await adapter.emitFromResult(result);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
(0, logger_1.runWithUserLogContext)(() => {
|
|
55
|
+
const errorMessage = `Error while processing task. ${(0, logger_1.serializeError)(error)}`;
|
|
56
|
+
console.error(errorMessage);
|
|
57
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
58
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageFailed,
|
|
59
|
+
payload: { message: errorMessage },
|
|
56
60
|
});
|
|
57
|
-
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Entry point for an extraction worker. Builds an {@link ExtractionAdapter} and
|
|
68
|
+
* runs the provided task against it.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
function processExtractionTask({ task, onTimeout, }) {
|
|
73
|
+
if (node_worker_threads_1.isMainThread) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
void runWorkerTask(async () => {
|
|
77
|
+
const event = node_worker_threads_1.workerData.event;
|
|
78
|
+
const initialState = node_worker_threads_1.workerData.initialState;
|
|
79
|
+
const initialDomainMapping = node_worker_threads_1.workerData.initialDomainMapping;
|
|
80
|
+
const options = node_worker_threads_1.workerData.options;
|
|
81
|
+
// eslint-disable-next-line no-global-assign
|
|
82
|
+
console = new logger_1.Logger({ event, options });
|
|
83
|
+
const adapterState = await (0, extraction_state_1.createExtractionState)({
|
|
84
|
+
event,
|
|
85
|
+
initialState,
|
|
86
|
+
initialDomainMapping,
|
|
87
|
+
options,
|
|
88
|
+
});
|
|
89
|
+
return new extraction_adapter_1.ExtractionAdapter({
|
|
90
|
+
event,
|
|
91
|
+
adapterState,
|
|
92
|
+
options,
|
|
93
|
+
});
|
|
94
|
+
}, { task, onTimeout });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Entry point for a loading worker. Builds a {@link LoadingAdapter} and runs the
|
|
98
|
+
* provided task against it.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
function processLoadingTask({ task, onTimeout, }) {
|
|
103
|
+
if (node_worker_threads_1.isMainThread) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
void runWorkerTask(async () => {
|
|
107
|
+
const event = node_worker_threads_1.workerData.event;
|
|
108
|
+
const initialState = node_worker_threads_1.workerData.initialState;
|
|
109
|
+
const initialDomainMapping = node_worker_threads_1.workerData.initialDomainMapping;
|
|
110
|
+
const options = node_worker_threads_1.workerData.options;
|
|
111
|
+
// eslint-disable-next-line no-global-assign
|
|
112
|
+
console = new logger_1.Logger({ event, options });
|
|
113
|
+
const adapterState = await (0, loading_state_1.createLoadingState)({
|
|
114
|
+
event,
|
|
115
|
+
initialState,
|
|
116
|
+
initialDomainMapping,
|
|
117
|
+
options,
|
|
118
|
+
});
|
|
119
|
+
return new loading_adapter_1.LoadingAdapter({
|
|
120
|
+
event,
|
|
121
|
+
adapterState,
|
|
122
|
+
options,
|
|
58
123
|
});
|
|
59
|
-
})
|
|
124
|
+
}, { task, onTimeout });
|
|
60
125
|
}
|