@devrev/airsync-sdk 2.0.0-beta.0 → 2.0.0-beta.10
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 +7 -21
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +7 -1
- 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 +70 -33
- package/dist/common/constants.d.ts +15 -12
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -34
- package/dist/common/helpers.d.ts +3 -27
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -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/http/{axios-client-internal.js → client.js} +7 -4
- package/dist/http/errors.d.ts +8 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +31 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -28
- package/dist/logger/logger.d.ts +13 -70
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -7
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +67 -92
- package/dist/mappers/mappers.d.ts +10 -43
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +173 -0
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +1 -10
- package/dist/mappers/mappers.js +32 -46
- package/dist/multithreading/adapters/base-adapter.d.ts +39 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.js +212 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts +49 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +375 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts +26 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +12 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +279 -0
- package/dist/multithreading/emit.d.ts +11 -0
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/multithreading/emit.js +25 -0
- package/dist/multithreading/process-task.d.ts +6 -1
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +124 -51
- package/dist/multithreading/spawn/spawn.d.ts +11 -11
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +12 -11
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +142 -77
- package/dist/multithreading/spawn/spawn.js +74 -75
- package/dist/multithreading/worker.js +16 -5
- package/dist/repo/repo.d.ts +14 -5
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.helpers.d.ts +6 -0
- package/dist/repo/repo.helpers.d.ts.map +1 -0
- package/dist/repo/repo.helpers.js +16 -0
- package/dist/repo/repo.interfaces.d.ts +11 -20
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +36 -22
- package/dist/state/base-state.d.ts +58 -0
- package/dist/state/base-state.d.ts.map +1 -0
- package/dist/state/base-state.js +242 -0
- package/dist/state/extraction-state.d.ts +14 -0
- package/dist/state/extraction-state.d.ts.map +1 -0
- package/dist/state/extraction-state.js +140 -0
- package/dist/state/install-initial-domain-mapping.d.ts +4 -0
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/{common → state}/install-initial-domain-mapping.js +5 -7
- package/dist/state/loading-state.d.ts +8 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +29 -0
- package/dist/state/state.d.ts +3 -29
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +36 -10
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +17 -1
- package/dist/state/state.js +9 -164
- package/dist/state/time-value-resolver.d.ts +17 -0
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/state/time-value-resolver.js +110 -0
- package/dist/testing/mock-event.d.ts +10 -0
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/testing/mock-event.js +96 -0
- package/dist/testing/mock-server.d.ts +31 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts +54 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.js +4 -0
- package/dist/testing/mock-server.js +297 -0
- package/dist/testing/test-adapters.d.ts +22 -0
- package/dist/testing/test-adapters.d.ts.map +1 -0
- package/dist/testing/test-adapters.js +32 -0
- package/dist/types/common.d.ts +4 -37
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +2 -17
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +28 -0
- package/dist/types/external-domain-metadata.d.ts +197 -0
- package/dist/types/external-domain-metadata.d.ts.map +1 -0
- package/dist/types/extraction.d.ts +135 -278
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +46 -133
- package/dist/types/loading.d.ts +15 -55
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -23
- package/dist/types/workers.d.ts +70 -103
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -6
- package/dist/uploader/uploader.d.ts +10 -61
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +7 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +80 -30
- package/dist/uploader/uploader.interfaces.d.ts +19 -54
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +72 -124
- package/docs/MIGRATION.md +696 -0
- package/package.json +37 -20
- 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 -267
- package/dist/common/control-protocol.d.ts +0 -10
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/control-protocol.js +0 -31
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/errors.js +0 -4
- package/dist/common/event-type-translation.d.ts +0 -24
- package/dist/common/event-type-translation.d.ts.map +0 -1
- package/dist/common/event-type-translation.js +0 -117
- package/dist/common/install-initial-domain-mapping.d.ts +0 -4
- 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 -207
- package/dist/deprecated/adapter/index.d.ts +0 -62
- package/dist/deprecated/adapter/index.d.ts.map +0 -1
- package/dist/deprecated/adapter/index.js +0 -151
- package/dist/deprecated/common/helpers.d.ts +0 -7
- package/dist/deprecated/common/helpers.d.ts.map +0 -1
- package/dist/deprecated/common/helpers.js +0 -47
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +0 -38
- package/dist/deprecated/demo-extractor/index.d.ts +0 -18
- package/dist/deprecated/demo-extractor/index.d.ts.map +0 -1
- package/dist/deprecated/demo-extractor/index.js +0 -161
- package/dist/deprecated/http/client.d.ts +0 -22
- package/dist/deprecated/http/client.d.ts.map +0 -1
- package/dist/deprecated/http/client.js +0 -161
- package/dist/deprecated/uploader/index.d.ts +0 -35
- package/dist/deprecated/uploader/index.d.ts.map +0 -1
- package/dist/deprecated/uploader/index.js +0 -161
- 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 -154
- 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 -57
- 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 -3
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -18
- package/dist/http/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- 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 -490
- package/dist/mappers/mappers.interface.d.ts +0 -294
- 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 -107
- 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 -89
- 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/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 -127
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
- 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 -747
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
- 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 -131
- 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 -224
- 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 -70
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- 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 -267
- 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 -589
- /package/dist/{http/types.js → types/external-domain-metadata.js} +0 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractionAdapter = void 0;
|
|
4
|
+
const attachments_streaming_pool_1 = require("../../attachments-streaming/attachments-streaming-pool");
|
|
5
|
+
const constants_1 = require("../../common/constants");
|
|
6
|
+
const logger_1 = require("../../logger/logger");
|
|
7
|
+
const repo_1 = require("../../repo/repo");
|
|
8
|
+
const extraction_1 = require("../../types/extraction");
|
|
9
|
+
const uploader_helpers_1 = require("../../uploader/uploader.helpers");
|
|
10
|
+
const base_adapter_1 = require("./base-adapter");
|
|
11
|
+
/** Adapter passed to extraction tasks (repos, artifacts, attachment streaming). @public */
|
|
12
|
+
class ExtractionAdapter extends base_adapter_1.BaseAdapter {
|
|
13
|
+
/** @internal */
|
|
14
|
+
constructor(params) {
|
|
15
|
+
super(params);
|
|
16
|
+
this.repos = [];
|
|
17
|
+
this.currentEventDataLength = 0;
|
|
18
|
+
this._artifacts = [];
|
|
19
|
+
}
|
|
20
|
+
/** Defaults to true if the scope is empty or the item type is not listed. */
|
|
21
|
+
shouldExtract(itemType) {
|
|
22
|
+
const scope = this.extractionScope;
|
|
23
|
+
if (Object.keys(scope).length === 0)
|
|
24
|
+
return true;
|
|
25
|
+
if (!(itemType in scope))
|
|
26
|
+
return true;
|
|
27
|
+
return scope[itemType].extract;
|
|
28
|
+
}
|
|
29
|
+
initializeRepos(repos) {
|
|
30
|
+
const existingSsorRepo = this.repos.find((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT);
|
|
31
|
+
this.repos = repos.map((repo) => this.createRepo(repo));
|
|
32
|
+
if (existingSsorRepo &&
|
|
33
|
+
!this.repos.some((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT)) {
|
|
34
|
+
this.repos.push(existingSsorRepo);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
createRepo(repo) {
|
|
38
|
+
const shouldNormalize = repo.itemType !== constants_1.AirSyncDefaultItemTypes.EXTERNAL_DOMAIN_METADATA &&
|
|
39
|
+
repo.itemType !== constants_1.SSOR_ATTACHMENT;
|
|
40
|
+
const isDeferred = this.isDeferredRepo(repo.itemType);
|
|
41
|
+
return new repo_1.Repo(Object.assign(Object.assign({ event: this.event, itemType: repo.itemType }, (shouldNormalize && { normalize: repo.normalize })), { skipConfirmation: repo.itemType === constants_1.AirSyncDefaultItemTypes.EXTERNAL_SYNC_UNITS, onUpload: (artifact) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (isDeferred) {
|
|
44
|
+
const toDevRev = this.adapterState.sdkState.toDevRev;
|
|
45
|
+
if (toDevRev) {
|
|
46
|
+
(_a = toDevRev.deferredSsorArtifacts) !== null && _a !== void 0 ? _a : (toDevRev.deferredSsorArtifacts = []);
|
|
47
|
+
toDevRev.deferredSsorArtifacts.push(artifact);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.lastExtractedItemType = repo.itemType;
|
|
52
|
+
// Artifact ids are kept in state for later attachment streaming
|
|
53
|
+
if (repo.itemType === constants_1.AirSyncDefaultItemTypes.ATTACHMENTS) {
|
|
54
|
+
(_b = this.adapterState.sdkState.toDevRev) === null || _b === void 0 ? void 0 : _b.attachmentsMetadata.artifactIds.push(artifact.id);
|
|
55
|
+
}
|
|
56
|
+
// Track size of artifact objects that go in the SQS message; flip
|
|
57
|
+
// isTimeout once the threshold is exceeded to force an early emit.
|
|
58
|
+
this.currentEventDataLength += Buffer.byteLength(JSON.stringify(artifact), 'utf8');
|
|
59
|
+
if (this.currentEventDataLength > constants_1.EVENT_SIZE_THRESHOLD_BYTES &&
|
|
60
|
+
!this.isTimeout) {
|
|
61
|
+
this.isTimeout = true;
|
|
62
|
+
}
|
|
63
|
+
}, options: Object.assign(Object.assign({}, this.options), repo.overriddenOptions) }));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* SSOR attachments created outside the attachments phase are held in state
|
|
67
|
+
* and reported with ATTACHMENT_EXTRACTION_DONE instead of the current event.
|
|
68
|
+
*/
|
|
69
|
+
isDeferredRepo(itemType) {
|
|
70
|
+
return itemType === constants_1.SSOR_ATTACHMENT && !this.isAttachmentsPhase();
|
|
71
|
+
}
|
|
72
|
+
isAttachmentsPhase() {
|
|
73
|
+
const eventType = this.event.payload.event_type;
|
|
74
|
+
return (eventType === extraction_1.EventType.StartExtractingAttachments ||
|
|
75
|
+
eventType === extraction_1.EventType.ContinueExtractingAttachments);
|
|
76
|
+
}
|
|
77
|
+
getOrCreateSsorRepo() {
|
|
78
|
+
let repo = this.repos.find((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT);
|
|
79
|
+
if (!repo) {
|
|
80
|
+
repo = this.createRepo({ itemType: constants_1.SSOR_ATTACHMENT });
|
|
81
|
+
this.repos.push(repo);
|
|
82
|
+
}
|
|
83
|
+
return repo;
|
|
84
|
+
}
|
|
85
|
+
getRepo(itemType) {
|
|
86
|
+
const repo = this.repos.find((repo) => repo.itemType === itemType);
|
|
87
|
+
if (!repo) {
|
|
88
|
+
console.error(`Repo for item type ${itemType} not found.`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
return repo;
|
|
92
|
+
}
|
|
93
|
+
/** Artifacts uploaded so far that the next emit will report. */
|
|
94
|
+
get artifacts() {
|
|
95
|
+
return this._artifacts;
|
|
96
|
+
}
|
|
97
|
+
addArtifacts(artifacts) {
|
|
98
|
+
this._artifacts = this._artifacts
|
|
99
|
+
.concat(artifacts)
|
|
100
|
+
.filter((value, index, self) => self.indexOf(value) === index);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Per-record-type counts for sync-duration estimation. Set during the
|
|
104
|
+
* metadata phase; the SDK attaches them to the metadata-done event.
|
|
105
|
+
*/
|
|
106
|
+
get preExtractionItemCounts() {
|
|
107
|
+
return this._preExtractionItemCounts;
|
|
108
|
+
}
|
|
109
|
+
set preExtractionItemCounts(counts) {
|
|
110
|
+
this._preExtractionItemCounts = counts;
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
async beforeEmit(newEventType) {
|
|
114
|
+
var _a;
|
|
115
|
+
console.log(`Uploading all repos before emitting event with event type: ${newEventType}.`);
|
|
116
|
+
await this.uploadAllRepos();
|
|
117
|
+
// When the full extraction cycle completes, commit the extraction window
|
|
118
|
+
// boundaries so subsequent incremental syncs can resume from them.
|
|
119
|
+
if (newEventType === extraction_1.ExtractorEventType.AttachmentExtractionDone) {
|
|
120
|
+
const sdkState = this.adapterState.sdkState;
|
|
121
|
+
// Released before the state save so they're never reported twice.
|
|
122
|
+
const toDevRev = sdkState.toDevRev;
|
|
123
|
+
if ((_a = toDevRev === null || toDevRev === void 0 ? void 0 : toDevRev.deferredSsorArtifacts) === null || _a === void 0 ? void 0 : _a.length) {
|
|
124
|
+
this.addArtifacts(toDevRev.deferredSsorArtifacts);
|
|
125
|
+
toDevRev.deferredSsorArtifacts = [];
|
|
126
|
+
}
|
|
127
|
+
console.log(`Overwriting lastSuccessfulSyncStarted with lastSyncStarted (${sdkState.lastSyncStarted}).`);
|
|
128
|
+
sdkState.lastSuccessfulSyncStarted = sdkState.lastSyncStarted;
|
|
129
|
+
sdkState.lastSyncStarted = '';
|
|
130
|
+
sdkState.pendingWorkersOldest = '';
|
|
131
|
+
sdkState.pendingWorkersNewest = '';
|
|
132
|
+
// Expand boundaries: workersOldest keeps the earliest timestamp seen,
|
|
133
|
+
// workersNewest the latest.
|
|
134
|
+
const extractionStart = this.event.payload.event_context.extract_from;
|
|
135
|
+
const extractionEnd = this.event.payload.event_context.extract_to;
|
|
136
|
+
if (extractionStart &&
|
|
137
|
+
(!sdkState.workersOldest || extractionStart < sdkState.workersOldest)) {
|
|
138
|
+
console.log(`Updating workersOldest from '${sdkState.workersOldest}' to '${extractionStart}'.`);
|
|
139
|
+
sdkState.workersOldest = extractionStart;
|
|
140
|
+
}
|
|
141
|
+
if (extractionEnd &&
|
|
142
|
+
(!sdkState.workersNewest || extractionEnd > sdkState.workersNewest)) {
|
|
143
|
+
console.log(`Updating workersNewest from '${sdkState.workersNewest}' to '${extractionEnd}'.`);
|
|
144
|
+
sdkState.workersNewest = extractionEnd;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** @internal */
|
|
149
|
+
buildEmitPayload(newEventType) {
|
|
150
|
+
const isExtractionEvent = Object.values(extraction_1.ExtractorEventType).includes(newEventType);
|
|
151
|
+
if (!isExtractionEvent) {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
const payload = { artifacts: [...this._artifacts] };
|
|
155
|
+
if (newEventType === extraction_1.ExtractorEventType.MetadataExtractionDone &&
|
|
156
|
+
this._preExtractionItemCounts) {
|
|
157
|
+
payload.pre_extraction_item_counts = this._preExtractionItemCounts;
|
|
158
|
+
}
|
|
159
|
+
return payload;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @internal
|
|
163
|
+
* Attaches the last-extracted item type and its created/modified date ranges
|
|
164
|
+
* to data/attachment done/progress events, mirroring the metadata v1 sent.
|
|
165
|
+
*/
|
|
166
|
+
buildWorkerMetadata(newEventType) {
|
|
167
|
+
if (newEventType !== extraction_1.ExtractorEventType.DataExtractionDone &&
|
|
168
|
+
newEventType !== extraction_1.ExtractorEventType.DataExtractionProgress &&
|
|
169
|
+
newEventType !== extraction_1.ExtractorEventType.AttachmentExtractionDone &&
|
|
170
|
+
newEventType !== extraction_1.ExtractorEventType.AttachmentExtractionProgress) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
const repo = this.lastExtractedItemType
|
|
174
|
+
? this.repos.find((r) => r.itemType === this.lastExtractedItemType)
|
|
175
|
+
: undefined;
|
|
176
|
+
if (!repo) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
item_type: repo.itemType,
|
|
181
|
+
newest_created_date: this.toRfc3339Timestamp(repo.dateRanges.creationDate.newest),
|
|
182
|
+
oldest_created_date: this.toRfc3339Timestamp(repo.dateRanges.creationDate.oldest),
|
|
183
|
+
newest_modified_date: this.toRfc3339Timestamp(repo.dateRanges.modifiedDate.newest),
|
|
184
|
+
oldest_modified_date: this.toRfc3339Timestamp(repo.dateRanges.modifiedDate.oldest),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
toRfc3339Timestamp(ms) {
|
|
188
|
+
if (ms === undefined || !Number.isFinite(ms)) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
return new Date(ms).toISOString();
|
|
192
|
+
}
|
|
193
|
+
/** @internal */
|
|
194
|
+
afterEmit() {
|
|
195
|
+
this._artifacts = [];
|
|
196
|
+
}
|
|
197
|
+
async uploadAllRepos() {
|
|
198
|
+
for (const repo of this.repos) {
|
|
199
|
+
await repo.upload();
|
|
200
|
+
if (!this.isDeferredRepo(repo.itemType)) {
|
|
201
|
+
this.addArtifacts(repo.uploadedArtifacts);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
beforeErrorEmit() {
|
|
207
|
+
// Report artifacts that uploaded before the failure so they aren't orphaned.
|
|
208
|
+
for (const repo of this.repos) {
|
|
209
|
+
if (!this.isDeferredRepo(repo.itemType)) {
|
|
210
|
+
this.addArtifacts(repo.uploadedArtifacts);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Streams one attachment into DevRev. Usable in any extraction phase; SSOR
|
|
216
|
+
* records created outside the attachments phase are reported with
|
|
217
|
+
* ATTACHMENT_EXTRACTION_DONE.
|
|
218
|
+
*/
|
|
219
|
+
async processAttachment(attachment, stream) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
const response = await stream({
|
|
222
|
+
item: attachment,
|
|
223
|
+
event: this.event,
|
|
224
|
+
});
|
|
225
|
+
if (response.status !== 'success') {
|
|
226
|
+
return response;
|
|
227
|
+
}
|
|
228
|
+
const { httpStream } = response;
|
|
229
|
+
const fileType = attachment.content_type ||
|
|
230
|
+
((_a = httpStream.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) ||
|
|
231
|
+
'application/octet-stream';
|
|
232
|
+
const contentLength = (_b = httpStream.headers['content-length']) === null || _b === void 0 ? void 0 : _b.toString();
|
|
233
|
+
const fileSize = contentLength ? parseInt(contentLength) : undefined;
|
|
234
|
+
const { error: artifactUrlError, response: artifactUrlResponse } = await this.uploader.getArtifactUploadUrl(attachment.file_name, fileType, fileSize);
|
|
235
|
+
if (artifactUrlError) {
|
|
236
|
+
(0, uploader_helpers_1.destroyHttpStream)(httpStream);
|
|
237
|
+
return {
|
|
238
|
+
status: 'error',
|
|
239
|
+
error: {
|
|
240
|
+
message: `Error while preparing artifact for attachment ID ${attachment.id}. Skipping attachment. ${(0, logger_1.serializeError)(artifactUrlError)}`,
|
|
241
|
+
fileSize,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const { error: uploadedArtifactError } = await this.uploader.streamArtifact(artifactUrlResponse, httpStream);
|
|
246
|
+
if (uploadedArtifactError) {
|
|
247
|
+
(0, uploader_helpers_1.destroyHttpStream)(httpStream);
|
|
248
|
+
return {
|
|
249
|
+
status: 'error',
|
|
250
|
+
error: {
|
|
251
|
+
message: `Error while streaming to artifact for attachment ID ${attachment.id}. Skipping attachment. ` +
|
|
252
|
+
(0, logger_1.serializeError)(uploadedArtifactError),
|
|
253
|
+
fileSize,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const { error: confirmArtifactUploadError } = await this.uploader.confirmArtifactUpload(artifactUrlResponse.artifact_id);
|
|
258
|
+
if (confirmArtifactUploadError) {
|
|
259
|
+
return {
|
|
260
|
+
status: 'error',
|
|
261
|
+
error: {
|
|
262
|
+
message: `Error while confirming upload for attachment ID ${attachment.id}. ` +
|
|
263
|
+
(0, logger_1.serializeError)(confirmArtifactUploadError),
|
|
264
|
+
fileSize,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const ssorAttachment = {
|
|
269
|
+
id: {
|
|
270
|
+
devrev: artifactUrlResponse.artifact_id,
|
|
271
|
+
external: attachment.id,
|
|
272
|
+
},
|
|
273
|
+
parent_id: {
|
|
274
|
+
external: attachment.parent_id,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
if (attachment.author_id) {
|
|
278
|
+
ssorAttachment.actor_id = {
|
|
279
|
+
external: attachment.author_id,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// Set inline flag only if it is explicitly set on the attachment.
|
|
283
|
+
if (attachment.inline === true) {
|
|
284
|
+
ssorAttachment.inline = true;
|
|
285
|
+
}
|
|
286
|
+
else if (attachment.inline === false) {
|
|
287
|
+
ssorAttachment.inline = false;
|
|
288
|
+
}
|
|
289
|
+
if (this.isTimeout) {
|
|
290
|
+
(0, uploader_helpers_1.destroyHttpStream)(httpStream);
|
|
291
|
+
return { status: 'success' };
|
|
292
|
+
}
|
|
293
|
+
await this.getOrCreateSsorRepo().push([ssorAttachment]);
|
|
294
|
+
return { status: 'success' };
|
|
295
|
+
}
|
|
296
|
+
async streamAttachments({ stream, processors, batchSize = 1, }) {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
if (batchSize <= 0) {
|
|
299
|
+
console.warn(`The specified batch size (${batchSize}) is invalid. Using 1 instead.`);
|
|
300
|
+
batchSize = 1;
|
|
301
|
+
}
|
|
302
|
+
if (batchSize > 50) {
|
|
303
|
+
console.warn(`The specified batch size (${batchSize}) is too large. Using 50 instead.`);
|
|
304
|
+
batchSize = 50;
|
|
305
|
+
}
|
|
306
|
+
this.initializeRepos([{ itemType: constants_1.SSOR_ATTACHMENT }]);
|
|
307
|
+
const attachmentsMetadata = (_a = this.adapterState.sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.attachmentsMetadata;
|
|
308
|
+
if (!((_b = attachmentsMetadata === null || attachmentsMetadata === void 0 ? void 0 : attachmentsMetadata.artifactIds) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
309
|
+
console.log(`No attachments metadata artifact IDs found in state.`);
|
|
310
|
+
return { status: 'success' };
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.log(`Found ${attachmentsMetadata.artifactIds.length} attachments metadata artifact IDs in state.`);
|
|
314
|
+
}
|
|
315
|
+
while (attachmentsMetadata.artifactIds.length > 0) {
|
|
316
|
+
const attachmentsMetadataArtifactId = attachmentsMetadata.artifactIds[0];
|
|
317
|
+
console.log(`Started processing attachments for attachments metadata artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
318
|
+
const { attachments, error } = await this.uploader.getAttachmentsFromArtifactId({
|
|
319
|
+
artifact: attachmentsMetadataArtifactId,
|
|
320
|
+
});
|
|
321
|
+
if (error) {
|
|
322
|
+
console.error(`Failed to get attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
323
|
+
return { status: 'error', error };
|
|
324
|
+
}
|
|
325
|
+
if (!attachments || attachments.length === 0) {
|
|
326
|
+
console.warn(`No attachments found for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
327
|
+
attachmentsMetadata.artifactIds.shift();
|
|
328
|
+
attachmentsMetadata.lastProcessed = 0;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
console.log(`Found ${attachments.length} attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
332
|
+
let response;
|
|
333
|
+
if (processors) {
|
|
334
|
+
console.log(`Using custom processors for attachments.`);
|
|
335
|
+
const reducer = processors.reducer;
|
|
336
|
+
const iterator = processors.iterator;
|
|
337
|
+
const reducedAttachments = reducer({
|
|
338
|
+
attachments,
|
|
339
|
+
adapter: this,
|
|
340
|
+
batchSize,
|
|
341
|
+
});
|
|
342
|
+
response = await iterator({
|
|
343
|
+
reducedAttachments,
|
|
344
|
+
adapter: this,
|
|
345
|
+
stream,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
console.log(`Using attachments streaming pool for attachments streaming.`);
|
|
350
|
+
const attachmentsPool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
351
|
+
adapter: this,
|
|
352
|
+
attachments,
|
|
353
|
+
batchSize,
|
|
354
|
+
stream,
|
|
355
|
+
});
|
|
356
|
+
response = await attachmentsPool.streamAll();
|
|
357
|
+
}
|
|
358
|
+
if (response.status !== 'success') {
|
|
359
|
+
return response;
|
|
360
|
+
}
|
|
361
|
+
if (this.isTimeout) {
|
|
362
|
+
console.log(`Timeout detected after processing attachments for artifact ID: ${attachmentsMetadataArtifactId}. Returning progress to allow continuation.`);
|
|
363
|
+
return { status: 'progress' };
|
|
364
|
+
}
|
|
365
|
+
console.log(`Finished processing all attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
366
|
+
attachmentsMetadata.artifactIds.shift();
|
|
367
|
+
attachmentsMetadata.lastProcessed = 0;
|
|
368
|
+
if (attachmentsMetadata.lastProcessedAttachmentsIdsList) {
|
|
369
|
+
attachmentsMetadata.lastProcessedAttachmentsIdsList.length = 0;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return { status: 'success' };
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.ExtractionAdapter = ExtractionAdapter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ExternalSystemAttachment, ExternalSystemLoadingFunction, ItemTypesToLoadParams, LoaderReport } from '../../types/loading';
|
|
2
|
+
import { TaskResult } from '../../types/workers';
|
|
3
|
+
import { BaseAdapter } from './base-adapter';
|
|
4
|
+
/** Adapter passed to loading tasks (item/attachment loading, loader reports). @public */
|
|
5
|
+
export declare class LoadingAdapter<ConnectorState> extends BaseAdapter<ConnectorState> {
|
|
6
|
+
private loaderReports;
|
|
7
|
+
private _processedFiles;
|
|
8
|
+
get reports(): LoaderReport[];
|
|
9
|
+
get processedFiles(): string[];
|
|
10
|
+
loadItemTypes({ itemTypesToLoad, }: ItemTypesToLoadParams): Promise<TaskResult>;
|
|
11
|
+
loadAttachments({ create, }: {
|
|
12
|
+
create: ExternalSystemLoadingFunction<ExternalSystemAttachment>;
|
|
13
|
+
}): Promise<TaskResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Walks the transformer files in `fromDevRev.filesToLoad`, resuming from
|
|
16
|
+
* each file's `lineToProcess`. `getLoader` returns undefined when a file has
|
|
17
|
+
* an item type the connector can't load, which fails the phase.
|
|
18
|
+
*/
|
|
19
|
+
private loadFiles;
|
|
20
|
+
private getLoaderBatches;
|
|
21
|
+
private loadItem;
|
|
22
|
+
/** Maps a non-success connector response to a delay or a failed report. */
|
|
23
|
+
private toFailedLoad;
|
|
24
|
+
private loadAttachment;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=loading-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/loading-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,wBAAwB,EAGxB,6BAA6B,EAE7B,qBAAqB,EAGrB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAM7C,yFAAyF;AACzF,qBAAa,cAAc,CACzB,cAAc,CACd,SAAQ,WAAW,CAAC,cAAc,CAAC;IACnC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,eAAe,CAAW;IAalC,IAAI,OAAO,IAAI,YAAY,EAAE,CAE5B;IAED,IAAI,cAAc,IAAI,MAAM,EAAE,CAE7B;IA2BK,aAAa,CAAC,EAClB,eAAe,GAChB,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8BxC,eAAe,CAAC,EACpB,MAAM,GACP,EAAE;QACD,MAAM,EAAE,6BAA6B,CAAC,wBAAwB,CAAC,CAAC;KACjE,GAAG,OAAO,CAAC,UAAU,CAAC;IAavB;;;;OAIG;YACW,SAAS;YAiFT,gBAAgB;YAuBhB,QAAQ;IA+HtB,2EAA2E;IAC3E,OAAO,CAAC,YAAY;YAwBN,cAAc;CA2C7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FileToLoad, LoaderReport, StatsFileObject } from '../../types/loading';
|
|
2
|
+
/** Filters the stats file to supported item types, ordered by their position in supportedItemTypes. */
|
|
3
|
+
export declare function getFilesToLoad({ supportedItemTypes, statsFile, }: {
|
|
4
|
+
supportedItemTypes: string[];
|
|
5
|
+
statsFile: StatsFileObject[];
|
|
6
|
+
}): FileToLoad[];
|
|
7
|
+
/** Merges a report into the loader reports, summing counts per item type. */
|
|
8
|
+
export declare function addReportToLoaderReport({ loaderReports, report, }: {
|
|
9
|
+
loaderReports: LoaderReport[];
|
|
10
|
+
report: LoaderReport;
|
|
11
|
+
}): LoaderReport[];
|
|
12
|
+
//# sourceMappingURL=loading-adapter.helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading-adapter.helpers.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/loading-adapter.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B,uGAAuG;AACvG,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,6EAA6E;AAC7E,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"}
|
|
@@ -3,12 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFilesToLoad = getFilesToLoad;
|
|
4
4
|
exports.addReportToLoaderReport = addReportToLoaderReport;
|
|
5
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
|
-
*/
|
|
6
|
+
/** Filters the stats file to supported item types, ordered by their position in supportedItemTypes. */
|
|
12
7
|
function getFilesToLoad({ supportedItemTypes, statsFile, }) {
|
|
13
8
|
const filesToLoad = [];
|
|
14
9
|
if (supportedItemTypes.length === 0 || statsFile.length === 0) {
|
|
@@ -32,12 +27,7 @@ function getFilesToLoad({ supportedItemTypes, statsFile, }) {
|
|
|
32
27
|
}
|
|
33
28
|
return filesToLoad;
|
|
34
29
|
}
|
|
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
|
-
*/
|
|
30
|
+
/** Merges a report into the loader reports, summing counts per item type. */
|
|
41
31
|
function addReportToLoaderReport({ loaderReports, report, }) {
|
|
42
32
|
const existingReport = loaderReports.find((loaderReport) => loaderReport.item_type === report.item_type);
|
|
43
33
|
if (existingReport) {
|