@devrev/airsync-sdk 2.0.0-beta.4 → 2.0.0-beta.5
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/MIGRATION.md +1028 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +2 -2
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +47 -21
- package/dist/common/constants.d.ts +3 -5
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +4 -6
- package/dist/common/helpers.d.ts +3 -21
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -15
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +4 -8
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -18
- package/dist/logger/logger.d.ts +8 -63
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +0 -1
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +14 -93
- package/dist/mappers/mappers.d.ts +2 -40
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +35 -154
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.js +1 -10
- package/dist/mappers/mappers.js +2 -40
- package/dist/multithreading/adapters/base-adapter.d.ts +19 -36
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/base-adapter.js +73 -71
- package/dist/multithreading/adapters/extraction-adapter.d.ts +12 -24
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/extraction-adapter.js +199 -200
- package/dist/multithreading/adapters/loading-adapter.d.ts +1 -6
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +2 -12
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.js +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +292 -314
- package/dist/multithreading/emit.d.ts +3 -2
- package/dist/multithreading/emit.d.ts.map +1 -1
- package/dist/multithreading/emit.js +3 -5
- package/dist/multithreading/process-task.d.ts +2 -12
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +45 -59
- package/dist/multithreading/spawn/spawn.d.ts +3 -9
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +6 -25
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +7 -49
- package/dist/multithreading/spawn/spawn.js +18 -33
- package/dist/multithreading/worker.js +2 -4
- package/dist/repo/repo.d.ts +10 -0
- 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 +4 -16
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +23 -8
- package/dist/state/base-state.d.ts +14 -36
- package/dist/state/base-state.d.ts.map +1 -1
- package/dist/state/base-state.js +16 -38
- package/dist/state/extraction-state.d.ts +4 -19
- package/dist/state/extraction-state.d.ts.map +1 -1
- package/dist/state/extraction-state.js +6 -23
- package/dist/state/install-initial-domain-mapping.d.ts +1 -1
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -1
- package/dist/state/install-initial-domain-mapping.js +1 -3
- package/dist/state/loading-state.d.ts +1 -11
- package/dist/state/loading-state.d.ts.map +1 -1
- package/dist/state/loading-state.js +2 -12
- package/dist/state/state.d.ts +2 -2
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +10 -24
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +9 -11
- package/dist/state/state.js +3 -3
- package/dist/state/time-value-resolver.d.ts +7 -36
- package/dist/state/time-value-resolver.d.ts.map +1 -1
- package/dist/state/time-value-resolver.js +7 -40
- package/dist/testing/mock-event.d.ts +2 -10
- package/dist/testing/mock-event.d.ts.map +1 -1
- package/dist/testing/mock-event.js +3 -11
- package/dist/testing/mock-server.d.ts +4 -27
- package/dist/testing/mock-server.d.ts.map +1 -1
- package/dist/testing/mock-server.interfaces.d.ts +10 -35
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -1
- package/dist/testing/mock-server.js +19 -36
- package/dist/types/common.d.ts +1 -12
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +1 -6
- package/dist/types/external-domain-metadata.d.ts +30 -171
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +35 -120
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +5 -31
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/workers.d.ts +18 -116
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +0 -6
- package/dist/uploader/uploader.d.ts +6 -58
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +4 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +64 -30
- package/dist/uploader/uploader.interfaces.d.ts +15 -25
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +18 -84
- package/package.json +6 -4
package/dist/mappers/mappers.js
CHANGED
|
@@ -2,24 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Mappers = void 0;
|
|
4
4
|
const client_1 = require("../http/client");
|
|
5
|
-
/**
|
|
6
|
-
* Manages sync mapper records that link external system items to DevRev items.
|
|
7
|
-
*
|
|
8
|
-
* Used for tracking relationships between external and DevRev entities during sync operations.
|
|
9
|
-
*/
|
|
5
|
+
/** Manages sync mapper records that link external system items to DevRev items. */
|
|
10
6
|
class Mappers {
|
|
11
7
|
constructor({ event }) {
|
|
12
8
|
this.devrevApiEndpoint = event.execution_metadata.devrev_endpoint;
|
|
13
9
|
this.devrevApiToken = event.context.secrets.service_account_token;
|
|
14
10
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves a sync mapper record by DevRev ID.
|
|
17
|
-
*
|
|
18
|
-
* Used to find the mapping when you know the DevRev ID and want to find the external system ID.
|
|
19
|
-
*
|
|
20
|
-
* @param params - Query parameters of type MappersGetByTargetIdParams
|
|
21
|
-
* @returns Promise resolving to the sync mapper record
|
|
22
|
-
*/
|
|
23
11
|
async getByTargetId(params) {
|
|
24
12
|
const { sync_unit, target } = params;
|
|
25
13
|
const response = await client_1.axiosClient.get(`${this.devrevApiEndpoint}/internal/airdrop.sync-mapper-record.get-by-target`, {
|
|
@@ -30,14 +18,6 @@ class Mappers {
|
|
|
30
18
|
});
|
|
31
19
|
return response.data;
|
|
32
20
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Retrieves a sync mapper record by external system ID.
|
|
35
|
-
*
|
|
36
|
-
* Used to find the mapping when you know the external system ID and want to find the DevRev ID.
|
|
37
|
-
*
|
|
38
|
-
* @param params - Query parameters of type MappersGetByExternalIdParams
|
|
39
|
-
* @returns Promise resolving to the sync mapper record
|
|
40
|
-
*/
|
|
41
21
|
async getByExternalId(params) {
|
|
42
22
|
const { sync_unit, external_id, target_type } = params;
|
|
43
23
|
const response = await client_1.axiosClient.get(`${this.devrevApiEndpoint}/internal/airdrop.sync-mapper-record.get-by-external-id`, {
|
|
@@ -48,16 +28,7 @@ class Mappers {
|
|
|
48
28
|
});
|
|
49
29
|
return response.data;
|
|
50
30
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Creates a new sync mapper record to establish a relationship between external system
|
|
53
|
-
* entities and DevRev entities.
|
|
54
|
-
*
|
|
55
|
-
* This is called after importing an item from external system to DevRev to record
|
|
56
|
-
* the mapping for future synchronization operations.
|
|
57
|
-
*
|
|
58
|
-
* @param params - Creation parameters of type MappersCreateParams
|
|
59
|
-
* @returns Promise resolving to the created sync mapper record
|
|
60
|
-
*/
|
|
31
|
+
/** Called after importing an item to DevRev to record the mapping for future syncs. */
|
|
61
32
|
async create(params) {
|
|
62
33
|
const response = await client_1.axiosClient.post(`${this.devrevApiEndpoint}/internal/airdrop.sync-mapper-record.create`, params, {
|
|
63
34
|
headers: {
|
|
@@ -66,15 +37,6 @@ class Mappers {
|
|
|
66
37
|
});
|
|
67
38
|
return response.data;
|
|
68
39
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Updates an existing sync mapper record.
|
|
71
|
-
*
|
|
72
|
-
* Used to modify existing mappings when external system entities change or when
|
|
73
|
-
* additional DevRev entities need to be associated.
|
|
74
|
-
*
|
|
75
|
-
* @param params - Update parameters of type MappersUpdateParams
|
|
76
|
-
* @returns Promise resolving to the updated sync mapper record
|
|
77
|
-
*/
|
|
78
40
|
async update(params) {
|
|
79
41
|
const response = await client_1.axiosClient.post(`${this.devrevApiEndpoint}/internal/airdrop.sync-mapper-record.update`, params, {
|
|
80
42
|
headers: {
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { BaseState } from '../../state/state';
|
|
2
2
|
import { SdkState } from '../../state/state.interfaces';
|
|
3
|
-
import { AirSyncEvent, EventData, ExtractorEventType } from '../../types/extraction';
|
|
3
|
+
import { AirSyncEvent, EventData, ExtractorEventType, WorkerMetadata } from '../../types/extraction';
|
|
4
4
|
import { LoaderEventType } from '../../types/loading';
|
|
5
5
|
import { TaskResult, WorkerAdapterOptions } from '../../types/workers';
|
|
6
6
|
import { Uploader } from '../../uploader/uploader';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* (`ExtractionAdapter`, `LoadingAdapter`) implement the abstract hooks to inject
|
|
11
|
-
* their own pre-emit work and event payload shaping.
|
|
12
|
-
*
|
|
13
|
-
* @typeParam ConnectorState - the connector-owned state shape
|
|
8
|
+
* Shared state/behavior for both sync modes; owns the `emit` control-protocol
|
|
9
|
+
* flow as a template method with mode-specific hooks.
|
|
14
10
|
*/
|
|
15
11
|
export declare abstract class BaseAdapter<ConnectorState> {
|
|
16
12
|
readonly event: AirSyncEvent;
|
|
17
13
|
readonly options?: WorkerAdapterOptions;
|
|
18
|
-
isTimeout: boolean;
|
|
19
14
|
hasWorkerEmitted: boolean;
|
|
15
|
+
private _isTimeout;
|
|
16
|
+
private resolveTimeoutSignal;
|
|
17
|
+
readonly timeoutSignal: Promise<void>;
|
|
20
18
|
protected adapterState: BaseState<ConnectorState>;
|
|
21
19
|
protected uploader: Uploader;
|
|
22
20
|
constructor({ event, adapterState, options, }: {
|
|
@@ -24,48 +22,33 @@ export declare abstract class BaseAdapter<ConnectorState> {
|
|
|
24
22
|
adapterState: BaseState<ConnectorState>;
|
|
25
23
|
options?: WorkerAdapterOptions;
|
|
26
24
|
});
|
|
25
|
+
get isTimeout(): boolean;
|
|
26
|
+
set isTimeout(value: boolean);
|
|
27
27
|
/** Connector-owned state exposed to snap-in code. */
|
|
28
28
|
get state(): ConnectorState;
|
|
29
29
|
set state(value: ConnectorState);
|
|
30
|
-
/** SDK-internal bookkeeping state
|
|
30
|
+
/** SDK-internal bookkeeping state; not for connector use. */
|
|
31
31
|
get sdkState(): SdkState;
|
|
32
32
|
get extractionScope(): import("../../types/workers").ExtractionScope;
|
|
33
33
|
postState(): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Pre-emit hook run before any state is persisted or the event is sent.
|
|
36
|
-
* Extraction uploads pending repos and updates extraction boundaries here;
|
|
37
|
-
* loading has nothing to do. Throwing aborts the emit (the caller signals
|
|
38
|
-
* worker exit).
|
|
39
|
-
*/
|
|
34
|
+
/** Pre-emit hook, runs before state is persisted. Throwing aborts the emit. */
|
|
40
35
|
protected abstract beforeEmit(newEventType: ExtractorEventType | LoaderEventType): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Builds the mode-specific extras merged into the emitted event payload
|
|
43
|
-
* (extraction: artifacts; loading: reports + processed files).
|
|
44
|
-
*/
|
|
36
|
+
/** Mode-specific extras merged into the emitted event payload. */
|
|
45
37
|
protected abstract buildEmitPayload(newEventType: ExtractorEventType | LoaderEventType): EventData;
|
|
46
38
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
39
|
+
* Mode-specific worker metadata merged into the emitted event. The library
|
|
40
|
+
* version and state-date range are added centrally in `emit`, so subclasses
|
|
41
|
+
* only contribute their own statistics.
|
|
49
42
|
*/
|
|
43
|
+
protected buildWorkerMetadata(newEventType: ExtractorEventType | LoaderEventType): WorkerMetadata | undefined;
|
|
44
|
+
/** Post-emit hook, runs after the event has been sent successfully. */
|
|
50
45
|
protected abstract afterEmit(newEventType: ExtractorEventType | LoaderEventType): void;
|
|
51
46
|
/**
|
|
52
|
-
* Maps a {@link TaskResult}
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* This is the SDK-internal bridge between the return-based connector contract
|
|
56
|
-
* and the control protocol; it is invoked by the worker driver, not by
|
|
57
|
-
* connectors. Connectors signal outcomes by returning a `TaskResult`, never by
|
|
58
|
-
* calling `emit` directly.
|
|
59
|
-
*
|
|
60
|
-
* @param result - The status the worker reported for the current phase.
|
|
47
|
+
* Maps a {@link TaskResult} to the phase-appropriate platform event and emits
|
|
48
|
+
* it exactly once. Invoked by the worker driver, not by connectors —
|
|
49
|
+
* connectors signal outcomes by returning a `TaskResult`, never by emitting.
|
|
61
50
|
*/
|
|
62
51
|
emitFromResult(result: TaskResult): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Emits an event to the platform.
|
|
65
|
-
*
|
|
66
|
-
* @param newEventType - The event type to be emitted
|
|
67
|
-
* @param data - The data to be sent with the event
|
|
68
|
-
*/
|
|
69
52
|
protected emit(newEventType: ExtractorEventType | LoaderEventType, data?: EventData): Promise<void>;
|
|
70
53
|
}
|
|
71
54
|
//# sourceMappingURL=base-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/base-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/base-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,UAAU,EACV,oBAAoB,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAInD;;;GAGG;AACH,8BAAsB,WAAW,CAAC,cAAc;IAC9C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IACxC,gBAAgB,EAAE,OAAO,CAAC;IAE1B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,oBAAoB,CAAc;IAC1C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,CAElC;IAEH,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAClD,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC;gBAEjB,EACV,KAAK,EACL,YAAY,EACZ,OAAO,GACR,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;QACxC,OAAO,CAAC,EAAE,oBAAoB,CAAC;KAChC;IAWD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAK3B;IAED,qDAAqD;IACrD,IAAI,KAAK,IAAI,cAAc,CAE1B;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,cAAc,EAE9B;IAED,6DAA6D;IAC7D,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED,IAAI,eAAe,kDAElB;IAEK,SAAS;IAIf,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,CAAC,UAAU,CAC3B,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,OAAO,CAAC,IAAI,CAAC;IAEhB,kEAAkE;IAClE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CACjC,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,SAAS;IAEZ;;;;OAIG;IACH,SAAS,CAAC,mBAAmB,CAE3B,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,cAAc,GAAG,SAAS;IAI7B,uEAAuE;IACvE,SAAS,CAAC,QAAQ,CAAC,SAAS,CAC1B,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,IAAI;IAEP;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;cAoBvC,IAAI,CAClB,YAAY,EAAE,kBAAkB,GAAG,eAAe,EAClD,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,IAAI,CAAC;CAgEjB"}
|
|
@@ -3,31 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseAdapter = void 0;
|
|
4
4
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
5
5
|
const constants_1 = require("../../common/constants");
|
|
6
|
-
const emit_1 = require("../emit");
|
|
7
6
|
const logger_1 = require("../../logger/logger");
|
|
8
7
|
const workers_1 = require("../../types/workers");
|
|
9
8
|
const uploader_1 = require("../../uploader/uploader");
|
|
9
|
+
const emit_1 = require("../emit");
|
|
10
10
|
const spawn_helpers_1 = require("../spawn/spawn.helpers");
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* (`ExtractionAdapter`, `LoadingAdapter`) implement the abstract hooks to inject
|
|
15
|
-
* their own pre-emit work and event payload shaping.
|
|
16
|
-
*
|
|
17
|
-
* @typeParam ConnectorState - the connector-owned state shape
|
|
12
|
+
* Shared state/behavior for both sync modes; owns the `emit` control-protocol
|
|
13
|
+
* flow as a template method with mode-specific hooks.
|
|
18
14
|
*/
|
|
19
15
|
class BaseAdapter {
|
|
20
16
|
constructor({ event, adapterState, options, }) {
|
|
17
|
+
this._isTimeout = false;
|
|
18
|
+
this.timeoutSignal = new Promise((resolve) => {
|
|
19
|
+
this.resolveTimeoutSignal = resolve;
|
|
20
|
+
});
|
|
21
21
|
this.event = event;
|
|
22
22
|
this.options = options;
|
|
23
23
|
this.adapterState = adapterState;
|
|
24
24
|
this.hasWorkerEmitted = false;
|
|
25
|
-
this.isTimeout = false;
|
|
26
25
|
this.uploader = new uploader_1.Uploader({
|
|
27
26
|
event,
|
|
28
27
|
options,
|
|
29
28
|
});
|
|
30
29
|
}
|
|
30
|
+
get isTimeout() {
|
|
31
|
+
return this._isTimeout;
|
|
32
|
+
}
|
|
33
|
+
set isTimeout(value) {
|
|
34
|
+
this._isTimeout = value;
|
|
35
|
+
if (value) {
|
|
36
|
+
this.resolveTimeoutSignal();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
/** Connector-owned state exposed to snap-in code. */
|
|
32
40
|
get state() {
|
|
33
41
|
return this.adapterState.state;
|
|
@@ -35,7 +43,7 @@ class BaseAdapter {
|
|
|
35
43
|
set state(value) {
|
|
36
44
|
this.adapterState.state = value;
|
|
37
45
|
}
|
|
38
|
-
/** SDK-internal bookkeeping state
|
|
46
|
+
/** SDK-internal bookkeeping state; not for connector use. */
|
|
39
47
|
get sdkState() {
|
|
40
48
|
return this.adapterState.sdkState;
|
|
41
49
|
}
|
|
@@ -43,20 +51,22 @@ class BaseAdapter {
|
|
|
43
51
|
return this.adapterState.extractionScope;
|
|
44
52
|
}
|
|
45
53
|
async postState() {
|
|
46
|
-
|
|
47
|
-
await this.adapterState.postState();
|
|
48
|
-
});
|
|
54
|
+
await this.adapterState.postState();
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
* Mode-specific worker metadata merged into the emitted event. The library
|
|
58
|
+
* version and state-date range are added centrally in `emit`, so subclasses
|
|
59
|
+
* only contribute their own statistics.
|
|
60
|
+
*/
|
|
61
|
+
buildWorkerMetadata(
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
|
+
newEventType) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Maps a {@link TaskResult} to the phase-appropriate platform event and emits
|
|
68
|
+
* it exactly once. Invoked by the worker driver, not by connectors —
|
|
69
|
+
* connectors signal outcomes by returning a `TaskResult`, never by emitting.
|
|
60
70
|
*/
|
|
61
71
|
async emitFromResult(result) {
|
|
62
72
|
const { eventType, illegal } = (0, spawn_helpers_1.getEventTypeForResult)(this.event.payload.event_type, result.status);
|
|
@@ -74,65 +84,57 @@ class BaseAdapter {
|
|
|
74
84
|
}
|
|
75
85
|
await this.emit(eventType, data);
|
|
76
86
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Emits an event to the platform.
|
|
79
|
-
*
|
|
80
|
-
* @param newEventType - The event type to be emitted
|
|
81
|
-
* @param data - The data to be sent with the event
|
|
82
|
-
*/
|
|
83
87
|
async emit(newEventType, data) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
var _a;
|
|
89
|
+
if (this.hasWorkerEmitted) {
|
|
90
|
+
console.warn(`Trying to emit event with event type: ${newEventType}. Ignoring emit request because it has already been emitted.`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await this.beforeEmit(newEventType);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error('Error while preparing to emit event', error);
|
|
98
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
99
|
+
this.hasWorkerEmitted = true;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// Save state on every emit, except for start and delete events
|
|
103
|
+
if (!constants_1.STATELESS_EVENT_TYPES.includes(this.event.payload.event_type)) {
|
|
104
|
+
console.log(`Saving state before emitting event with event type: ${newEventType}.`);
|
|
90
105
|
try {
|
|
91
|
-
await this.
|
|
106
|
+
await this.adapterState.postState();
|
|
92
107
|
}
|
|
93
108
|
catch (error) {
|
|
94
|
-
console.error('Error while
|
|
109
|
+
console.error('Error while posting state', error);
|
|
95
110
|
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
96
111
|
this.hasWorkerEmitted = true;
|
|
97
112
|
return;
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await this.adapterState.postState();
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
console.error('Error while posting state', error);
|
|
107
|
-
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
108
|
-
this.hasWorkerEmitted = true;
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
// Always prune error messages to make them shorter before emit
|
|
114
|
-
if ((_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.message) {
|
|
115
|
-
data.error.message = (0, logger_1.truncateMessage)(data.error.message);
|
|
116
|
-
}
|
|
117
|
-
await (0, emit_1.emit)({
|
|
118
|
-
eventType: newEventType,
|
|
119
|
-
event: this.event,
|
|
120
|
-
data: Object.assign(Object.assign({}, data), this.buildEmitPayload(newEventType)),
|
|
121
|
-
});
|
|
122
|
-
const message = {
|
|
123
|
-
subject: workers_1.WorkerMessageSubject.WorkerMessageEmitted,
|
|
124
|
-
payload: { eventType: newEventType },
|
|
125
|
-
};
|
|
126
|
-
this.afterEmit(newEventType);
|
|
127
|
-
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(message);
|
|
128
|
-
this.hasWorkerEmitted = true;
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
console.error(`Error while emitting event with event type: ${newEventType}.`, (0, logger_1.serializeError)(error));
|
|
132
|
-
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
133
|
-
this.hasWorkerEmitted = true;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
if ((_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.message) {
|
|
117
|
+
data.error.message = (0, logger_1.truncateMessage)(data.error.message);
|
|
134
118
|
}
|
|
135
|
-
|
|
119
|
+
await (0, emit_1.emit)({
|
|
120
|
+
eventType: newEventType,
|
|
121
|
+
event: this.event,
|
|
122
|
+
data: Object.assign(Object.assign({}, data), this.buildEmitPayload(newEventType)),
|
|
123
|
+
worker_metadata: this.buildWorkerMetadata(newEventType),
|
|
124
|
+
});
|
|
125
|
+
const message = {
|
|
126
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageEmitted,
|
|
127
|
+
payload: { eventType: newEventType },
|
|
128
|
+
};
|
|
129
|
+
this.afterEmit(newEventType);
|
|
130
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(message);
|
|
131
|
+
this.hasWorkerEmitted = true;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(`Error while emitting event with event type: ${newEventType}.`, (0, logger_1.serializeError)(error));
|
|
135
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
136
|
+
this.hasWorkerEmitted = true;
|
|
137
|
+
}
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
exports.BaseAdapter = BaseAdapter;
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import { Repo } from '../../repo/repo';
|
|
2
2
|
import { NormalizedAttachment, RepoInterface } from '../../repo/repo.interfaces';
|
|
3
|
-
import { AirSyncEvent, EventData, ExternalSystemAttachmentProcessors, ExternalSystemAttachmentStreamingFunction, ExtractorEventType, ProcessAttachmentReturnType } from '../../types/extraction';
|
|
4
|
-
import { LoaderEventType } from '../../types/loading';
|
|
5
3
|
import { BaseState } from '../../state/state';
|
|
4
|
+
import { AirSyncEvent, EventData, ExternalSystemAttachmentProcessors, ExternalSystemAttachmentStreamingFunction, ExtractorEventType, ProcessAttachmentReturnType, WorkerMetadata } from '../../types/extraction';
|
|
5
|
+
import { LoaderEventType } from '../../types/loading';
|
|
6
6
|
import { TaskResult, WorkerAdapterOptions } from '../../types/workers';
|
|
7
7
|
import { Artifact } from '../../uploader/uploader.interfaces';
|
|
8
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 uploads
|
|
12
|
-
* pending repos and updates the extraction boundaries before emitting.
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
9
|
+
/** Adapter passed to extraction tasks (repos, artifacts, attachment streaming). @public */
|
|
16
10
|
export declare class ExtractionAdapter<ConnectorState> extends BaseAdapter<ConnectorState> {
|
|
17
11
|
private _artifacts;
|
|
18
12
|
private repos;
|
|
13
|
+
private lastExtractedItemType?;
|
|
19
14
|
private currentEventDataLength;
|
|
20
15
|
constructor(params: {
|
|
21
16
|
event: AirSyncEvent;
|
|
22
17
|
adapterState: BaseState<ConnectorState>;
|
|
23
18
|
options?: WorkerAdapterOptions;
|
|
24
19
|
});
|
|
25
|
-
/**
|
|
26
|
-
* Returns whether the given item type should be extracted.
|
|
27
|
-
* Defaults to true if the scope is empty or the item type is not listed.
|
|
28
|
-
*/
|
|
20
|
+
/** Defaults to true if the scope is empty or the item type is not listed. */
|
|
29
21
|
shouldExtract(itemType: string): boolean;
|
|
30
22
|
initializeRepos(repos: RepoInterface[]): void;
|
|
31
23
|
getRepo(itemType: string): Repo | undefined;
|
|
@@ -33,21 +25,17 @@ export declare class ExtractionAdapter<ConnectorState> extends BaseAdapter<Conne
|
|
|
33
25
|
set artifacts(artifacts: Artifact[]);
|
|
34
26
|
protected beforeEmit(newEventType: ExtractorEventType | LoaderEventType): Promise<void>;
|
|
35
27
|
protected buildEmitPayload(newEventType: ExtractorEventType | LoaderEventType): EventData;
|
|
28
|
+
/**
|
|
29
|
+
* Attaches the last-extracted item type and its created/modified date ranges
|
|
30
|
+
* to data/attachment done/progress events, mirroring the metadata v1 sent.
|
|
31
|
+
*/
|
|
32
|
+
protected buildWorkerMetadata(newEventType: ExtractorEventType | LoaderEventType): WorkerMetadata | undefined;
|
|
33
|
+
private toRfc3339Timestamp;
|
|
36
34
|
protected afterEmit(): void;
|
|
37
35
|
uploadAllRepos(): Promise<void>;
|
|
38
36
|
processAttachment(attachment: NormalizedAttachment, stream: ExternalSystemAttachmentStreamingFunction): Promise<ProcessAttachmentReturnType>;
|
|
39
|
-
/**
|
|
40
|
-
* Destroys a stream to prevent memory leaks.
|
|
41
|
-
* @param httpStream - The axios response stream to destroy
|
|
42
|
-
*/
|
|
37
|
+
/** Destroys a stream to prevent memory leaks. */
|
|
43
38
|
private destroyHttpStream;
|
|
44
|
-
/**
|
|
45
|
-
* Streams the attachments to the DevRev platform.
|
|
46
|
-
* The attachments are streamed to the platform and the artifact information is returned.
|
|
47
|
-
* @param params - The parameters to stream the attachments
|
|
48
|
-
* @returns The response object containing the ssorAttachment artifact information
|
|
49
|
-
* or error information if there was an error
|
|
50
|
-
*/
|
|
51
39
|
streamAttachments<NewBatch>({ stream, processors, batchSize, }: {
|
|
52
40
|
stream: ExternalSystemAttachmentStreamingFunction;
|
|
53
41
|
processors?: ExternalSystemAttachmentProcessors<ConnectorState, NormalizedAttachment[], NewBatch>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extraction-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/extraction-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extraction-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/extraction-adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kCAAkC,EAClC,yCAAyC,EACzC,kBAAkB,EAElB,2BAA2B,EAC3B,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAkB,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,2FAA2F;AAC3F,qBAAa,iBAAiB,CAC5B,cAAc,CACd,SAAQ,WAAW,CAAC,cAAc,CAAC;IACnC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,qBAAqB,CAAC,CAAS;IACvC,OAAO,CAAC,sBAAsB,CAAa;gBAE/B,MAAM,EAAE;QAClB,KAAK,EAAE,YAAY,CAAC;QACpB,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;QACxC,OAAO,CAAC,EAAE,oBAAoB,CAAC;KAChC;IAKD,6EAA6E;IAC7E,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAOxC,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE;IA0CtC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAW3C,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;;;OAGG;cACgB,mBAAmB,CACpC,YAAY,EAAE,kBAAkB,GAAG,eAAe,GACjD,cAAc,GAAG,SAAS;IAmC7B,OAAO,CAAC,kBAAkB;IAQ1B,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;IA2GvC,iDAAiD;IACjD,OAAO,CAAC,iBAAiB;IAcnB,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,UAAU,CAAC;CA8HxB"}
|