@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.3
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 +0 -4
- package/dist/airsync-sdk.d.ts +2059 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +2 -1
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +8 -2
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +27 -16
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +246 -27
- package/dist/common/constants.d.ts +16 -5
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -6
- package/dist/common/control-protocol.d.ts +2 -2
- package/dist/common/control-protocol.d.ts.map +1 -1
- package/dist/common/control-protocol.js +1 -5
- package/dist/common/helpers.d.ts +8 -0
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +15 -0
- package/dist/common/install-initial-domain-mapping.d.ts +2 -2
- package/dist/common/install-initial-domain-mapping.test.js +5 -2
- package/dist/common/test-utils.d.ts +19 -0
- package/dist/common/test-utils.d.ts.map +1 -0
- package/dist/common/test-utils.js +101 -0
- package/dist/common/time-value-resolver.d.ts +47 -0
- package/dist/common/time-value-resolver.d.ts.map +1 -0
- package/dist/common/time-value-resolver.js +141 -0
- package/dist/common/time-value-resolver.test.d.ts +2 -0
- package/dist/common/time-value-resolver.test.d.ts.map +1 -0
- package/dist/common/time-value-resolver.test.js +268 -0
- package/dist/http/axios-client-internal.d.ts.map +1 -1
- package/dist/http/axios-client-internal.js +7 -0
- package/dist/http/axios-client-internal.test.js +21 -0
- package/dist/http/axios-client.d.ts.map +1 -1
- package/dist/http/axios-client.js +6 -3
- package/dist/http/index.d.ts +0 -1
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +0 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -13
- package/dist/logger/logger.d.ts +1 -17
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +2 -2
- package/dist/logger/logger.js +35 -27
- package/dist/logger/logger.test.js +66 -19
- package/dist/mappers/mappers.interface.d.ts +5 -5
- package/dist/mappers/mappers.interface.js +3 -3
- package/dist/mappers/mappers.test.js +8 -10
- package/dist/mock-server/mock-server.d.ts +47 -0
- package/dist/mock-server/mock-server.d.ts.map +1 -0
- package/dist/mock-server/mock-server.interfaces.d.ts +73 -0
- package/dist/mock-server/mock-server.interfaces.d.ts.map +1 -0
- package/dist/mock-server/mock-server.interfaces.js +4 -0
- package/dist/mock-server/mock-server.js +278 -0
- package/dist/multithreading/adapters/base-adapter.d.ts +56 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.emit.test.d.ts +2 -0
- package/dist/multithreading/adapters/base-adapter.emit.test.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.emit.test.js +403 -0
- package/dist/multithreading/adapters/base-adapter.js +105 -0
- package/dist/multithreading/adapters/extraction-adapter.artifacts.test.d.ts +2 -0
- package/dist/multithreading/adapters/extraction-adapter.artifacts.test.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.artifacts.test.js → adapters/extraction-adapter.artifacts.test.js} +53 -5
- package/dist/multithreading/adapters/extraction-adapter.d.ts +58 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +325 -0
- package/dist/multithreading/adapters/extraction-adapter.test.d.ts +2 -0
- package/dist/multithreading/adapters/extraction-adapter.test.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.test.js +789 -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.helpers.test.d.ts +2 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.test.js → adapters/loading-adapter.helpers.test.js} +26 -26
- package/dist/multithreading/adapters/loading-adapter.js +461 -0
- package/dist/multithreading/adapters/loading-adapter.test.d.ts +2 -0
- package/dist/multithreading/adapters/loading-adapter.test.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.test.js +589 -0
- package/dist/multithreading/adapters/serialization.test.d.ts +2 -0
- package/dist/multithreading/adapters/serialization.test.d.ts.map +1 -0
- package/dist/multithreading/adapters/serialization.test.js +71 -0
- package/dist/multithreading/create-worker.test.js +36 -17
- 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 +97 -82
- package/dist/multithreading/process-task.test.d.ts +2 -0
- package/dist/multithreading/process-task.test.d.ts.map +1 -0
- package/dist/multithreading/process-task.test.js +146 -0
- package/dist/multithreading/spawn/spawn.d.ts +3 -3
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +6 -14
- package/dist/multithreading/spawn/spawn.helpers.test.js +8 -8
- package/dist/multithreading/spawn/spawn.js +20 -25
- package/dist/multithreading/spawn/spawn.test.d.ts +2 -0
- package/dist/multithreading/spawn/spawn.test.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.test.js +232 -0
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.interfaces.d.ts +4 -2
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +4 -3
- package/dist/repo/repo.test.js +60 -7
- 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/loading-state.d.ts +19 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +40 -0
- package/dist/state/state.extract-window.test.d.ts +2 -0
- package/dist/state/state.extract-window.test.d.ts.map +1 -0
- package/dist/state/state.extract-window.test.js +163 -0
- package/dist/state/state.interfaces.d.ts +44 -27
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +18 -5
- package/dist/state/state.pending-boundaries.test.d.ts +2 -0
- package/dist/state/state.pending-boundaries.test.d.ts.map +1 -0
- package/dist/state/state.pending-boundaries.test.js +189 -0
- package/dist/state/state.post-state.test.d.ts +2 -0
- package/dist/state/state.post-state.test.d.ts.map +1 -0
- package/dist/state/state.post-state.test.js +78 -0
- package/dist/state/state.test.js +135 -88
- package/dist/state/state.time-value-resolution.test.d.ts +2 -0
- package/dist/state/state.time-value-resolution.test.d.ts.map +1 -0
- package/dist/state/state.time-value-resolution.test.js +175 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/common.d.ts +0 -25
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +1 -11
- package/dist/types/external-domain-metadata.d.ts +20 -1
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +92 -221
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +56 -124
- package/dist/types/extraction.test.js +69 -43
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -3
- package/dist/types/loading.d.ts +4 -24
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -22
- package/dist/types/workers.d.ts +47 -29
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -0
- package/dist/uploader/uploader.d.ts +1 -0
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.test.js +0 -11
- package/dist/uploader/uploader.interfaces.d.ts +3 -3
- package/dist/uploader/uploader.js +53 -20
- package/dist/uploader/uploader.test.js +22 -10
- package/package.json +10 -13
- 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/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/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- 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.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.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.js +0 -745
- 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/state/state.d.ts +0 -30
- package/dist/state/state.d.ts.map +0 -1
- package/dist/state/state.js +0 -166
- /package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Repo } from '../../repo/repo';
|
|
2
|
+
import { NormalizedAttachment, RepoInterface } from '../../repo/repo.interfaces';
|
|
3
|
+
import { ExtractionState } from '../../state/extraction-state';
|
|
4
|
+
import { AirSyncEvent, ExternalSystemAttachmentProcessors, ExternalSystemAttachmentStreamingFunction, ExtractorEventType, EventData, ProcessAttachmentReturnType, StreamAttachmentsReturnType } from '../../types/extraction';
|
|
5
|
+
import { LoaderEventType } from '../../types/loading';
|
|
6
|
+
import { WorkerAdapterOptions } from '../../types/workers';
|
|
7
|
+
import { Artifact } from '../../uploader/uploader.interfaces';
|
|
8
|
+
import { BaseAdapter } from './base-adapter';
|
|
9
|
+
/**
|
|
10
|
+
* ExtractionAdapter is the adapter passed to extraction tasks. It exposes the
|
|
11
|
+
* extraction surface (repos, artifacts, attachment streaming) and updates the
|
|
12
|
+
* extraction boundaries before emitting.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare class ExtractionAdapter<ConnectorState> extends BaseAdapter<ConnectorState, ExtractionState<ConnectorState>> {
|
|
17
|
+
private _artifacts;
|
|
18
|
+
private repos;
|
|
19
|
+
private currentEventDataLength;
|
|
20
|
+
constructor(params: {
|
|
21
|
+
event: AirSyncEvent;
|
|
22
|
+
adapterState: ExtractionState<ConnectorState>;
|
|
23
|
+
options?: WorkerAdapterOptions;
|
|
24
|
+
});
|
|
25
|
+
get extractionScope(): import("../../types/workers").ExtractionScope;
|
|
26
|
+
/**
|
|
27
|
+
* Returns whether the given item type should be extracted.
|
|
28
|
+
* Defaults to true if the scope is empty or the item type is not listed.
|
|
29
|
+
*/
|
|
30
|
+
shouldExtract(itemType: string): boolean;
|
|
31
|
+
initializeRepos(repos: RepoInterface[]): void;
|
|
32
|
+
getRepo(itemType: string): Repo | undefined;
|
|
33
|
+
get artifacts(): Artifact[];
|
|
34
|
+
set artifacts(artifacts: Artifact[]);
|
|
35
|
+
protected beforeEmit(newEventType: ExtractorEventType | LoaderEventType): Promise<void>;
|
|
36
|
+
protected buildEmitPayload(newEventType: ExtractorEventType | LoaderEventType): EventData;
|
|
37
|
+
protected afterEmit(): void;
|
|
38
|
+
uploadAllRepos(): Promise<void>;
|
|
39
|
+
processAttachment(attachment: NormalizedAttachment, stream: ExternalSystemAttachmentStreamingFunction): Promise<ProcessAttachmentReturnType>;
|
|
40
|
+
/**
|
|
41
|
+
* Destroys a stream to prevent memory leaks.
|
|
42
|
+
* @param httpStream - The axios response stream to destroy
|
|
43
|
+
*/
|
|
44
|
+
private destroyHttpStream;
|
|
45
|
+
/**
|
|
46
|
+
* Streams the attachments to the DevRev platform.
|
|
47
|
+
* The attachments are streamed to the platform and the artifact information is returned.
|
|
48
|
+
* @param params - The parameters to stream the attachments
|
|
49
|
+
* @returns The response object containing the ssorAttachment artifact information
|
|
50
|
+
* or error information if there was an error
|
|
51
|
+
*/
|
|
52
|
+
streamAttachments<NewBatch>({ stream, processors, batchSize, }: {
|
|
53
|
+
stream: ExternalSystemAttachmentStreamingFunction;
|
|
54
|
+
processors?: ExternalSystemAttachmentProcessors<ConnectorState, NormalizedAttachment[], NewBatch>;
|
|
55
|
+
batchSize?: number;
|
|
56
|
+
}): Promise<StreamAttachmentsReturnType>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=extraction-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/extraction-adapter.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,kCAAkC,EAClC,yCAAyC,EACzC,kBAAkB,EAClB,SAAS,EACT,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAkB,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;GAMG;AACH,qBAAa,iBAAiB,CAAC,cAAc,CAAE,SAAQ,WAAW,CAChE,cAAc,EACd,eAAe,CAAC,cAAc,CAAC,CAChC;IACC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,sBAAsB,CAAa;gBAE/B,MAAM,EAAE;QAClB,KAAK,EAAE,YAAY,CAAC;QACpB,YAAY,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC;QAC9C,OAAO,CAAC,EAAE,oBAAoB,CAAC;KAChC;IAKD,IAAI,eAAe,kDAElB;IAED;;;OAGG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAOxC,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE;IAuCtC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAa3C,IAAI,SAAS,IAAI,QAAQ,EAAE,CAE1B;IAED,IAAI,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,EAIlC;cAEe,UAAU,CACxB,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,OAAO,CAAC,IAAI,CAAC;IAyChB,SAAS,CAAC,gBAAgB,CACxB,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,SAAS;IAOZ,SAAS,CAAC,SAAS,IAAI,IAAI;IAIrB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAU/B,iBAAiB,CACrB,UAAU,EAAE,oBAAoB,EAChC,MAAM,EAAE,yCAAyC,GAChD,OAAO,CAAC,2BAA2B,CAAC;IA+GvC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;;;OAMG;IACG,iBAAiB,CAAC,QAAQ,EAAE,EAChC,MAAM,EACN,UAAU,EACV,SAAa,GACd,EAAE;QACD,MAAM,EAAE,yCAAyC,CAAC;QAClD,UAAU,CAAC,EAAE,kCAAkC,CAC7C,cAAc,EACd,oBAAoB,EAAE,EACtB,QAAQ,CACT,CAAC;QACF,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAyIzC"}
|
|
@@ -0,0 +1,325 @@
|
|
|
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 logger_context_1 = require("../../logger/logger.context");
|
|
8
|
+
const repo_1 = require("../../repo/repo");
|
|
9
|
+
const extraction_1 = require("../../types/extraction");
|
|
10
|
+
const base_adapter_1 = require("./base-adapter");
|
|
11
|
+
/**
|
|
12
|
+
* ExtractionAdapter is the adapter passed to extraction tasks. It exposes the
|
|
13
|
+
* extraction surface (repos, artifacts, attachment streaming) and updates the
|
|
14
|
+
* extraction boundaries before emitting.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
class ExtractionAdapter extends base_adapter_1.BaseAdapter {
|
|
19
|
+
constructor(params) {
|
|
20
|
+
super(params);
|
|
21
|
+
this.repos = [];
|
|
22
|
+
this.currentEventDataLength = 0;
|
|
23
|
+
this._artifacts = [];
|
|
24
|
+
}
|
|
25
|
+
get extractionScope() {
|
|
26
|
+
return this.adapterState.extractionScope;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns whether the given item type should be extracted.
|
|
30
|
+
* Defaults to true if the scope is empty or the item type is not listed.
|
|
31
|
+
*/
|
|
32
|
+
shouldExtract(itemType) {
|
|
33
|
+
const scope = this.extractionScope;
|
|
34
|
+
if (Object.keys(scope).length === 0)
|
|
35
|
+
return true;
|
|
36
|
+
if (!(itemType in scope))
|
|
37
|
+
return true;
|
|
38
|
+
return scope[itemType].extract;
|
|
39
|
+
}
|
|
40
|
+
initializeRepos(repos) {
|
|
41
|
+
this.repos = repos.map((repo) => {
|
|
42
|
+
const shouldNormalize = repo.itemType !== constants_1.AirSyncDefaultItemTypes.EXTERNAL_DOMAIN_METADATA &&
|
|
43
|
+
repo.itemType !== constants_1.SSOR_ATTACHMENT;
|
|
44
|
+
return new repo_1.Repo(Object.assign(Object.assign({ event: this.event, itemType: repo.itemType }, (shouldNormalize && { normalize: repo.normalize })), { onUpload: (artifact) => {
|
|
45
|
+
var _a;
|
|
46
|
+
// We need to store artifacts ids in state for later use when streaming attachments
|
|
47
|
+
if (repo.itemType === constants_1.AirSyncDefaultItemTypes.ATTACHMENTS) {
|
|
48
|
+
(_a = this.adapterState.sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.attachmentsMetadata.artifactIds.push(artifact.id);
|
|
49
|
+
}
|
|
50
|
+
// Calculate size of the entire artifact object that goes in the SQS message
|
|
51
|
+
this.currentEventDataLength += Buffer.byteLength(JSON.stringify(artifact), 'utf8');
|
|
52
|
+
if (this.currentEventDataLength > constants_1.EVENT_SIZE_THRESHOLD_BYTES &&
|
|
53
|
+
!this.isTimeout) {
|
|
54
|
+
this.isTimeout = true;
|
|
55
|
+
}
|
|
56
|
+
}, options: Object.assign(Object.assign({}, this.options), repo.overridenOptions) }));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getRepo(itemType) {
|
|
60
|
+
return (0, logger_context_1.runWithSdkLogContext)(() => {
|
|
61
|
+
const repo = this.repos.find((repo) => repo.itemType === itemType);
|
|
62
|
+
if (!repo) {
|
|
63
|
+
console.error(`Repo for item type ${itemType} not found.`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
return repo;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
get artifacts() {
|
|
70
|
+
return this._artifacts;
|
|
71
|
+
}
|
|
72
|
+
set artifacts(artifacts) {
|
|
73
|
+
this._artifacts = this._artifacts
|
|
74
|
+
.concat(artifacts)
|
|
75
|
+
.filter((value, index, self) => self.indexOf(value) === index);
|
|
76
|
+
}
|
|
77
|
+
async beforeEmit(newEventType) {
|
|
78
|
+
// Upload all repos before emitting the event
|
|
79
|
+
console.log(`Uploading all repos before emitting event with event type: ${newEventType}.`);
|
|
80
|
+
await this.uploadAllRepos();
|
|
81
|
+
if (newEventType === extraction_1.ExtractorEventType.AttachmentExtractionDone) {
|
|
82
|
+
const sdkState = this.adapterState.sdkState;
|
|
83
|
+
// Clear pending extraction boundaries now that the cycle is complete
|
|
84
|
+
sdkState.pendingWorkersOldest = '';
|
|
85
|
+
sdkState.pendingWorkersNewest = '';
|
|
86
|
+
// Update workersOldest and workersNewest boundaries from resolved extraction timestamps.
|
|
87
|
+
// Expand boundaries: workersOldest gets the earliest timestamp, workersNewest gets the latest.
|
|
88
|
+
const extractionStart = this.event.payload.event_context.extract_from;
|
|
89
|
+
const extractionEnd = this.event.payload.event_context.extract_to;
|
|
90
|
+
if (extractionStart &&
|
|
91
|
+
(!sdkState.workersOldest || extractionStart < sdkState.workersOldest)) {
|
|
92
|
+
console.log(`Updating workersOldest from '${sdkState.workersOldest}' to '${extractionStart}'.`);
|
|
93
|
+
sdkState.workersOldest = extractionStart;
|
|
94
|
+
}
|
|
95
|
+
if (extractionEnd &&
|
|
96
|
+
(!sdkState.workersNewest || extractionEnd > sdkState.workersNewest)) {
|
|
97
|
+
console.log(`Updating workersNewest from '${sdkState.workersNewest}' to '${extractionEnd}'.`);
|
|
98
|
+
sdkState.workersNewest = extractionEnd;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
buildEmitPayload(newEventType) {
|
|
103
|
+
const isExtractionEvent = Object.values(extraction_1.ExtractorEventType).includes(newEventType);
|
|
104
|
+
return isExtractionEvent ? { artifacts: this.artifacts } : {};
|
|
105
|
+
}
|
|
106
|
+
afterEmit() {
|
|
107
|
+
this.artifacts = [];
|
|
108
|
+
}
|
|
109
|
+
async uploadAllRepos() {
|
|
110
|
+
for (const repo of this.repos) {
|
|
111
|
+
const error = await repo.upload();
|
|
112
|
+
this.artifacts.push(...repo.uploadedArtifacts);
|
|
113
|
+
if (error) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async processAttachment(attachment, stream) {
|
|
119
|
+
return (0, logger_context_1.runWithSdkLogContext)(async () => {
|
|
120
|
+
var _a, _b, _c;
|
|
121
|
+
const { httpStream, delay, error } = await (0, logger_context_1.runWithUserLogContext)(async () => stream({
|
|
122
|
+
item: attachment,
|
|
123
|
+
event: this.event,
|
|
124
|
+
}));
|
|
125
|
+
if (error) {
|
|
126
|
+
return { error };
|
|
127
|
+
}
|
|
128
|
+
else if (delay) {
|
|
129
|
+
return { delay };
|
|
130
|
+
}
|
|
131
|
+
if (httpStream) {
|
|
132
|
+
const fileType = attachment.content_type ||
|
|
133
|
+
((_a = httpStream.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) ||
|
|
134
|
+
'application/octet-stream';
|
|
135
|
+
const contentLength = (_b = httpStream.headers['content-length']) === null || _b === void 0 ? void 0 : _b.toString();
|
|
136
|
+
const fileSize = contentLength ? parseInt(contentLength) : undefined;
|
|
137
|
+
// Get upload URL
|
|
138
|
+
const { error: artifactUrlError, response: artifactUrlResponse } = await this.uploader.getArtifactUploadUrl(attachment.file_name, fileType, fileSize);
|
|
139
|
+
if (artifactUrlError) {
|
|
140
|
+
this.destroyHttpStream(httpStream);
|
|
141
|
+
return {
|
|
142
|
+
error: {
|
|
143
|
+
message: `Error while preparing artifact for attachment ID ${attachment.id}. Skipping attachment. ${(0, logger_1.serializeError)(artifactUrlError)}`,
|
|
144
|
+
fileSize: fileSize,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// Stream attachment
|
|
149
|
+
const { error: uploadedArtifactError } = await this.uploader.streamArtifact(artifactUrlResponse, httpStream);
|
|
150
|
+
if (uploadedArtifactError) {
|
|
151
|
+
this.destroyHttpStream(httpStream);
|
|
152
|
+
return {
|
|
153
|
+
error: {
|
|
154
|
+
message: `Error while streaming to artifact for attachment ID ${attachment.id}. Skipping attachment. ` +
|
|
155
|
+
(0, logger_1.serializeError)(uploadedArtifactError),
|
|
156
|
+
fileSize: fileSize,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Confirm attachment upload
|
|
161
|
+
const { error: confirmArtifactUploadError } = await this.uploader.confirmArtifactUpload(artifactUrlResponse.artifact_id);
|
|
162
|
+
if (confirmArtifactUploadError) {
|
|
163
|
+
return {
|
|
164
|
+
error: {
|
|
165
|
+
message: `Error while confirming upload for attachment ID ${attachment.id}. ` +
|
|
166
|
+
(0, logger_1.serializeError)(confirmArtifactUploadError),
|
|
167
|
+
fileSize: fileSize,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const ssorAttachment = {
|
|
172
|
+
id: {
|
|
173
|
+
devrev: artifactUrlResponse.artifact_id,
|
|
174
|
+
external: attachment.id,
|
|
175
|
+
},
|
|
176
|
+
parent_id: {
|
|
177
|
+
external: attachment.parent_id,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
if (attachment.author_id) {
|
|
181
|
+
ssorAttachment.actor_id = {
|
|
182
|
+
external: attachment.author_id,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// This will set inline flag in ssor_attachment only if it is explicity
|
|
186
|
+
// set in the attachment object.
|
|
187
|
+
if (attachment.inline === true) {
|
|
188
|
+
ssorAttachment.inline = true;
|
|
189
|
+
}
|
|
190
|
+
else if (attachment.inline === false) {
|
|
191
|
+
ssorAttachment.inline = false;
|
|
192
|
+
}
|
|
193
|
+
await ((_c = this.getRepo('ssor_attachment')) === null || _c === void 0 ? void 0 : _c.push([ssorAttachment]));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
error: {
|
|
198
|
+
message: `Error while opening attachment stream. Skipping attachment.`,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Destroys a stream to prevent memory leaks.
|
|
205
|
+
* @param httpStream - The axios response stream to destroy
|
|
206
|
+
*/
|
|
207
|
+
destroyHttpStream(httpStream) {
|
|
208
|
+
try {
|
|
209
|
+
if (httpStream && httpStream.data) {
|
|
210
|
+
if (typeof httpStream.data.destroy === 'function') {
|
|
211
|
+
httpStream.data.destroy();
|
|
212
|
+
}
|
|
213
|
+
else if (typeof httpStream.data.close === 'function') {
|
|
214
|
+
httpStream.data.close();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.warn('Error while destroying HTTP stream:', error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Streams the attachments to the DevRev platform.
|
|
224
|
+
* The attachments are streamed to the platform and the artifact information is returned.
|
|
225
|
+
* @param params - The parameters to stream the attachments
|
|
226
|
+
* @returns The response object containing the ssorAttachment artifact information
|
|
227
|
+
* or error information if there was an error
|
|
228
|
+
*/
|
|
229
|
+
async streamAttachments({ stream, processors, batchSize = 1, // By default, we want to stream one attachment at a time
|
|
230
|
+
}) {
|
|
231
|
+
return (0, logger_context_1.runWithSdkLogContext)(async () => {
|
|
232
|
+
var _a, _b;
|
|
233
|
+
if (batchSize <= 0) {
|
|
234
|
+
console.warn(`The specified batch size (${batchSize}) is invalid. Using 1 instead.`);
|
|
235
|
+
batchSize = 1;
|
|
236
|
+
}
|
|
237
|
+
if (batchSize > 50) {
|
|
238
|
+
console.warn(`The specified batch size (${batchSize}) is too large. Using 50 instead.`);
|
|
239
|
+
batchSize = 50;
|
|
240
|
+
}
|
|
241
|
+
const repos = [
|
|
242
|
+
{
|
|
243
|
+
itemType: 'ssor_attachment',
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
this.initializeRepos(repos);
|
|
247
|
+
const attachmentsMetadata = (_a = this.adapterState.sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.attachmentsMetadata;
|
|
248
|
+
// If there are no attachments metadata artifact IDs in state, finish here
|
|
249
|
+
if (!((_b = attachmentsMetadata === null || attachmentsMetadata === void 0 ? void 0 : attachmentsMetadata.artifactIds) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
250
|
+
console.log(`No attachments metadata artifact IDs found in state.`);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
console.log(`Found ${attachmentsMetadata.artifactIds.length} attachments metadata artifact IDs in state.`);
|
|
255
|
+
}
|
|
256
|
+
// Loop through the attachments metadata artifact IDs
|
|
257
|
+
while (attachmentsMetadata.artifactIds.length > 0) {
|
|
258
|
+
const attachmentsMetadataArtifactId = attachmentsMetadata.artifactIds[0];
|
|
259
|
+
console.log(`Started processing attachments for attachments metadata artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
260
|
+
const { attachments, error } = await this.uploader.getAttachmentsFromArtifactId({
|
|
261
|
+
artifact: attachmentsMetadataArtifactId,
|
|
262
|
+
});
|
|
263
|
+
if (error) {
|
|
264
|
+
console.error(`Failed to get attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
265
|
+
return { error };
|
|
266
|
+
}
|
|
267
|
+
if (!attachments || attachments.length === 0) {
|
|
268
|
+
console.warn(`No attachments found for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
269
|
+
// Remove empty artifact and reset lastProcessed
|
|
270
|
+
attachmentsMetadata.artifactIds.shift();
|
|
271
|
+
attachmentsMetadata.lastProcessed = 0;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
console.log(`Found ${attachments.length} attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
275
|
+
let response;
|
|
276
|
+
if (processors) {
|
|
277
|
+
console.log(`Using custom processors for attachments.`);
|
|
278
|
+
const reducer = processors.reducer;
|
|
279
|
+
const iterator = processors.iterator;
|
|
280
|
+
const reducedAttachments = (0, logger_context_1.runWithUserLogContext)(() => reducer({
|
|
281
|
+
attachments,
|
|
282
|
+
adapter: this,
|
|
283
|
+
batchSize,
|
|
284
|
+
}));
|
|
285
|
+
response = await (0, logger_context_1.runWithUserLogContext)(async () => {
|
|
286
|
+
return await iterator({
|
|
287
|
+
reducedAttachments,
|
|
288
|
+
adapter: this,
|
|
289
|
+
stream,
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
console.log(`Using attachments streaming pool for attachments streaming.`);
|
|
295
|
+
const attachmentsPool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
296
|
+
adapter: this,
|
|
297
|
+
attachments,
|
|
298
|
+
attachmentsMetadata,
|
|
299
|
+
batchSize,
|
|
300
|
+
stream,
|
|
301
|
+
});
|
|
302
|
+
response = await attachmentsPool.streamAll();
|
|
303
|
+
}
|
|
304
|
+
if ((response === null || response === void 0 ? void 0 : response.delay) || (response === null || response === void 0 ? void 0 : response.error)) {
|
|
305
|
+
return response;
|
|
306
|
+
}
|
|
307
|
+
// On timeout, emit progress and exit to allow continuation.
|
|
308
|
+
if (this.isTimeout) {
|
|
309
|
+
console.log(`Timeout detected after processing attachments for artifact ID: ${attachmentsMetadataArtifactId}. Emitting progress to allow continuation.`);
|
|
310
|
+
await this.emit(extraction_1.ExtractorEventType.AttachmentExtractionProgress);
|
|
311
|
+
process.exit(0);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
console.log(`Finished processing all attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
|
|
315
|
+
attachmentsMetadata.artifactIds.shift();
|
|
316
|
+
attachmentsMetadata.lastProcessed = 0;
|
|
317
|
+
if (attachmentsMetadata.lastProcessedAttachmentsIdsList) {
|
|
318
|
+
attachmentsMetadata.lastProcessedAttachmentsIdsList.length = 0;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
exports.ExtractionAdapter = ExtractionAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-adapter.test.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/extraction-adapter.test.ts"],"names":[],"mappings":""}
|