@devrev/ts-adaas 1.0.4 → 1.1.1
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 +8 -0
- package/dist/common/constants.d.ts +2 -0
- package/dist/common/constants.js +14 -2
- package/dist/common/control-protocol.d.ts +2 -1
- package/dist/common/helpers.d.ts +15 -3
- package/dist/common/helpers.js +68 -3
- package/dist/logger/logger.test.js +3 -0
- package/dist/mappers/mappers.d.ts +10 -0
- package/dist/mappers/mappers.interface.d.ts +85 -0
- package/dist/mappers/mappers.interface.js +9 -0
- package/dist/mappers/mappers.js +37 -0
- package/dist/state/state.d.ts +1 -0
- package/dist/state/state.interfaces.d.ts +8 -5
- package/dist/state/state.interfaces.js +1 -0
- package/dist/state/state.js +21 -12
- package/dist/tests/from_devrev/loading.test.d.ts +1 -0
- package/dist/tests/from_devrev/loading.test.js +146 -0
- package/dist/tests/test-helpers.js +12 -6
- package/dist/types/extraction.d.ts +42 -9
- package/dist/types/extraction.js +21 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +5 -1
- package/dist/types/loading.d.ts +95 -0
- package/dist/types/loading.js +21 -0
- package/dist/types/workers.d.ts +2 -1
- package/dist/uploader/uploader.d.ts +4 -0
- package/dist/uploader/uploader.interfaces.d.ts +9 -0
- package/dist/uploader/uploader.js +20 -0
- package/dist/workers/create-worker.js +2 -2
- package/dist/workers/default-workers/data-loading.d.ts +1 -0
- package/dist/workers/default-workers/data-loading.js +19 -0
- package/dist/workers/default-workers/loader-state-deletion.d.ts +1 -0
- package/dist/workers/default-workers/loader-state-deletion.js +15 -0
- package/dist/workers/spawn.js +23 -8
- package/dist/workers/worker-adapter.d.ts +14 -1
- package/dist/workers/worker-adapter.js +330 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Release Notes
|
|
4
4
|
|
|
5
|
+
#### v1.1.1
|
|
6
|
+
|
|
7
|
+
- Added default workers for loading deletion events.
|
|
8
|
+
|
|
9
|
+
#### v1.1.0
|
|
10
|
+
|
|
11
|
+
- Support for sync from DevRev to external system. Known limitations: no support for loading attachments.
|
|
12
|
+
|
|
5
13
|
#### v1.0.4
|
|
6
14
|
|
|
7
15
|
- Fix logging from worker threads.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { EventType } from '../types/extraction';
|
|
2
2
|
export declare const STATELESS_EVENT_TYPES: EventType[];
|
|
3
|
+
export declare const ALLOWED_EXTRACTION_EVENT_TYPES: EventType[];
|
|
4
|
+
export declare const ALLOWED_LOADING_EVENT_TYPES: EventType[];
|
|
3
5
|
export declare const ALLOWED_EVENT_TYPES: EventType[];
|
|
4
6
|
export declare const ARTIFACT_BATCH_SIZE = 2000;
|
|
5
7
|
export declare const MAX_DEVREV_ARTIFACT_SIZE = 536870912;
|
package/dist/common/constants.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
|
|
3
|
+
exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
|
|
4
4
|
const extraction_1 = require("../types/extraction");
|
|
5
5
|
exports.STATELESS_EVENT_TYPES = [
|
|
6
6
|
extraction_1.EventType.ExtractionExternalSyncUnitsStart,
|
|
7
7
|
extraction_1.EventType.ExtractionMetadataStart,
|
|
8
8
|
extraction_1.EventType.ExtractionDataDelete,
|
|
9
9
|
extraction_1.EventType.ExtractionAttachmentsDelete,
|
|
10
|
+
extraction_1.EventType.StartDeletingLoaderState,
|
|
11
|
+
extraction_1.EventType.StartDeletingLoaderAttachmentsState,
|
|
10
12
|
];
|
|
11
|
-
exports.
|
|
13
|
+
exports.ALLOWED_EXTRACTION_EVENT_TYPES = [
|
|
12
14
|
extraction_1.EventType.ExtractionExternalSyncUnitsStart,
|
|
13
15
|
extraction_1.EventType.ExtractionMetadataStart,
|
|
14
16
|
extraction_1.EventType.ExtractionDataStart,
|
|
@@ -18,6 +20,16 @@ exports.ALLOWED_EVENT_TYPES = [
|
|
|
18
20
|
extraction_1.EventType.ExtractionAttachmentsContinue,
|
|
19
21
|
extraction_1.EventType.ExtractionAttachmentsDelete,
|
|
20
22
|
];
|
|
23
|
+
exports.ALLOWED_LOADING_EVENT_TYPES = [
|
|
24
|
+
extraction_1.EventType.StartLoadingData,
|
|
25
|
+
extraction_1.EventType.ContinueLoadingData,
|
|
26
|
+
extraction_1.EventType.StartDeletingLoaderState,
|
|
27
|
+
extraction_1.EventType.StartDeletingLoaderAttachmentsState,
|
|
28
|
+
];
|
|
29
|
+
exports.ALLOWED_EVENT_TYPES = [
|
|
30
|
+
...exports.ALLOWED_EXTRACTION_EVENT_TYPES,
|
|
31
|
+
...exports.ALLOWED_LOADING_EVENT_TYPES,
|
|
32
|
+
];
|
|
21
33
|
exports.ARTIFACT_BATCH_SIZE = 2000;
|
|
22
34
|
exports.MAX_DEVREV_ARTIFACT_SIZE = 536870912; // 512MB
|
|
23
35
|
exports.AIRDROP_DEFAULT_ITEM_TYPES = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AirdropEvent, EventData, ExtractorEventType } from '../types/extraction';
|
|
2
|
+
import { LoaderEventType } from '../types/loading';
|
|
2
3
|
export interface EmitInterface {
|
|
3
4
|
event: AirdropEvent;
|
|
4
|
-
eventType: ExtractorEventType;
|
|
5
|
+
eventType: ExtractorEventType | LoaderEventType;
|
|
5
6
|
data?: EventData;
|
|
6
7
|
}
|
|
7
8
|
export declare const emit: ({ event, eventType, data, }: EmitInterface) => Promise<void | Error>;
|
package/dist/common/helpers.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import { EventType, ExtractorEventType } from '../types/extraction';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AirdropEvent, EventType, ExtractorEventType } from '../types/extraction';
|
|
2
|
+
import { FileToLoad, ItemTypeToLoad, LoaderEventType, LoaderReport, StatsFileObject } from '../types/loading';
|
|
3
|
+
export declare function getTimeoutErrorEventType(eventType: EventType): {
|
|
4
|
+
eventType: ExtractorEventType | LoaderEventType;
|
|
4
5
|
} | null;
|
|
6
|
+
export declare function getSyncDirection({ event }: {
|
|
7
|
+
event: AirdropEvent;
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function getFilesToLoad({ itemTypesToLoad, statsFile, }: {
|
|
10
|
+
itemTypesToLoad: ItemTypeToLoad[];
|
|
11
|
+
statsFile: StatsFileObject[];
|
|
12
|
+
}): FileToLoad[];
|
|
13
|
+
export declare function addReportToLoaderReport({ loaderReports, report, }: {
|
|
14
|
+
loaderReports: LoaderReport[];
|
|
15
|
+
report: LoaderReport;
|
|
16
|
+
}): LoaderReport[];
|
package/dist/common/helpers.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getTimeoutErrorEventType = getTimeoutErrorEventType;
|
|
4
|
+
exports.getSyncDirection = getSyncDirection;
|
|
5
|
+
exports.getFilesToLoad = getFilesToLoad;
|
|
6
|
+
exports.addReportToLoaderReport = addReportToLoaderReport;
|
|
4
7
|
const extraction_1 = require("../types/extraction");
|
|
5
|
-
|
|
8
|
+
const loading_1 = require("../types/loading");
|
|
9
|
+
function getTimeoutErrorEventType(eventType) {
|
|
6
10
|
switch (eventType) {
|
|
7
11
|
case extraction_1.EventType.ExtractionMetadataStart:
|
|
8
12
|
return {
|
|
@@ -30,9 +34,70 @@ function getErrorExtractorEventType(eventType) {
|
|
|
30
34
|
return {
|
|
31
35
|
eventType: extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsError,
|
|
32
36
|
};
|
|
37
|
+
case extraction_1.EventType.StartLoadingData:
|
|
38
|
+
case extraction_1.EventType.ContinueLoadingData:
|
|
39
|
+
return {
|
|
40
|
+
eventType: loading_1.LoaderEventType.DataLoadingError,
|
|
41
|
+
};
|
|
42
|
+
case extraction_1.EventType.StartDeletingLoaderState:
|
|
43
|
+
case extraction_1.EventType.StartDeletingLoaderAttachmentsState:
|
|
44
|
+
return {
|
|
45
|
+
eventType: loading_1.LoaderEventType.LoaderStateDeletionError,
|
|
46
|
+
};
|
|
33
47
|
default:
|
|
34
|
-
console.error('Event type not recognized in
|
|
48
|
+
console.error('Event type not recognized in getTimeoutErrorEventType function: ' +
|
|
35
49
|
eventType);
|
|
36
50
|
return null;
|
|
37
51
|
}
|
|
38
52
|
}
|
|
53
|
+
function getSyncDirection({ event }) {
|
|
54
|
+
return event.payload.event_context.mode;
|
|
55
|
+
}
|
|
56
|
+
function getFilesToLoad({ itemTypesToLoad, statsFile, }) {
|
|
57
|
+
const filesToLoad = [];
|
|
58
|
+
if (itemTypesToLoad.length === 0 || statsFile.length === 0) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const supportedItemTypes = itemTypesToLoad.map((itemTypeToLoad) => itemTypeToLoad.itemType);
|
|
62
|
+
const filteredStatsFile = statsFile.filter((file) => supportedItemTypes.includes(file.item_type));
|
|
63
|
+
const orderedFiles = filteredStatsFile.sort((a, b) => {
|
|
64
|
+
const aIndex = supportedItemTypes.indexOf(a.item_type);
|
|
65
|
+
const bIndex = supportedItemTypes.indexOf(b.item_type);
|
|
66
|
+
return aIndex - bIndex;
|
|
67
|
+
});
|
|
68
|
+
for (const file of orderedFiles) {
|
|
69
|
+
filesToLoad.push({
|
|
70
|
+
id: file.id,
|
|
71
|
+
file_name: file.file_name,
|
|
72
|
+
itemType: file.item_type,
|
|
73
|
+
count: parseInt(file.count),
|
|
74
|
+
completed: false,
|
|
75
|
+
lineToProcess: 0,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return filesToLoad;
|
|
79
|
+
}
|
|
80
|
+
function addReportToLoaderReport({ loaderReports, report, }) {
|
|
81
|
+
const existingReport = loaderReports.find((loaderReport) => loaderReport.item_type === report.item_type);
|
|
82
|
+
if (existingReport) {
|
|
83
|
+
existingReport[loading_1.ActionType.CREATED] = existingReport[loading_1.ActionType.CREATED]
|
|
84
|
+
? report[loading_1.ActionType.CREATED]
|
|
85
|
+
? existingReport[loading_1.ActionType.CREATED] + report[loading_1.ActionType.CREATED]
|
|
86
|
+
: existingReport[loading_1.ActionType.CREATED]
|
|
87
|
+
: report[loading_1.ActionType.CREATED];
|
|
88
|
+
existingReport[loading_1.ActionType.UPDATED] = existingReport[loading_1.ActionType.UPDATED]
|
|
89
|
+
? report[loading_1.ActionType.UPDATED]
|
|
90
|
+
? existingReport[loading_1.ActionType.UPDATED] + report[loading_1.ActionType.UPDATED]
|
|
91
|
+
: existingReport[loading_1.ActionType.UPDATED]
|
|
92
|
+
: report[loading_1.ActionType.UPDATED];
|
|
93
|
+
existingReport[loading_1.ActionType.FAILED] = existingReport[loading_1.ActionType.FAILED]
|
|
94
|
+
? report[loading_1.ActionType.FAILED]
|
|
95
|
+
? existingReport[loading_1.ActionType.FAILED] + report[loading_1.ActionType.FAILED]
|
|
96
|
+
: existingReport[loading_1.ActionType.FAILED]
|
|
97
|
+
: report[loading_1.ActionType.FAILED];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
loaderReports.push(report);
|
|
101
|
+
}
|
|
102
|
+
return loaderReports;
|
|
103
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { MappersFactoryInterface, MappersCreateParams, MappersCreateResponse, MappersGetByTargetIdParams, MappersGetByTargetIdResponse, MappersUpdateParams, MappersUpdateResponse } from './mappers.interface';
|
|
3
|
+
export declare class Mappers {
|
|
4
|
+
private endpoint;
|
|
5
|
+
private token;
|
|
6
|
+
constructor({ event }: MappersFactoryInterface);
|
|
7
|
+
getByTargetId(params: MappersGetByTargetIdParams): Promise<AxiosResponse<MappersGetByTargetIdResponse>>;
|
|
8
|
+
create(params: MappersCreateParams): Promise<AxiosResponse<MappersCreateResponse>>;
|
|
9
|
+
update(params: MappersUpdateParams): Promise<AxiosResponse<MappersUpdateResponse>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AirdropEvent } from '../types';
|
|
2
|
+
import { DonV2 } from '../types/loading';
|
|
3
|
+
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
|
+
export interface MappersFactoryInterface {
|
|
5
|
+
event: AirdropEvent;
|
|
6
|
+
options?: WorkerAdapterOptions;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateSyncMapperRecordParams {
|
|
9
|
+
external_ids: {
|
|
10
|
+
add: string[];
|
|
11
|
+
};
|
|
12
|
+
secondary_ids?: Record<string, string>;
|
|
13
|
+
targets: {
|
|
14
|
+
add: DonV2[];
|
|
15
|
+
};
|
|
16
|
+
status: SyncMapperRecordStatus;
|
|
17
|
+
input_files?: {
|
|
18
|
+
add: string[];
|
|
19
|
+
};
|
|
20
|
+
external_versions?: {
|
|
21
|
+
add: SyncMapperRecordExternalVersion[];
|
|
22
|
+
};
|
|
23
|
+
extra_data?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SyncMapperRecord {
|
|
26
|
+
id: DonV2;
|
|
27
|
+
external_ids: string[];
|
|
28
|
+
secondary_ids?: Record<string, string>;
|
|
29
|
+
targets: DonV2[];
|
|
30
|
+
status: SyncMapperRecordStatus;
|
|
31
|
+
input_files?: string[];
|
|
32
|
+
external_versions?: SyncMapperRecordExternalVersion[];
|
|
33
|
+
extra_data?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface MappersGetByTargetIdParams {
|
|
36
|
+
sync_unit: DonV2;
|
|
37
|
+
target: DonV2;
|
|
38
|
+
}
|
|
39
|
+
export interface MappersGetByTargetIdResponse {
|
|
40
|
+
sync_mapper_record: SyncMapperRecord;
|
|
41
|
+
}
|
|
42
|
+
export interface MappersCreateParams {
|
|
43
|
+
sync_unit: DonV2;
|
|
44
|
+
external_ids: string[];
|
|
45
|
+
secondary_ids?: Record<string, string>;
|
|
46
|
+
targets: DonV2[];
|
|
47
|
+
status: SyncMapperRecordStatus;
|
|
48
|
+
input_files?: string[];
|
|
49
|
+
external_versions?: SyncMapperRecordExternalVersion[];
|
|
50
|
+
extra_data?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface MappersCreateResponse {
|
|
53
|
+
sync_mapper_record: SyncMapperRecord;
|
|
54
|
+
}
|
|
55
|
+
export interface MappersUpdateParams {
|
|
56
|
+
id: DonV2;
|
|
57
|
+
sync_unit: DonV2;
|
|
58
|
+
external_ids: {
|
|
59
|
+
add: string[];
|
|
60
|
+
};
|
|
61
|
+
secondary_ids?: Record<string, string>;
|
|
62
|
+
targets: {
|
|
63
|
+
add: DonV2[];
|
|
64
|
+
};
|
|
65
|
+
status: SyncMapperRecordStatus;
|
|
66
|
+
input_files?: {
|
|
67
|
+
add: string[];
|
|
68
|
+
};
|
|
69
|
+
external_versions?: {
|
|
70
|
+
add: SyncMapperRecordExternalVersion[];
|
|
71
|
+
};
|
|
72
|
+
extra_data?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface MappersUpdateResponse {
|
|
75
|
+
sync_mapper_record: SyncMapperRecord;
|
|
76
|
+
}
|
|
77
|
+
export declare enum SyncMapperRecordStatus {
|
|
78
|
+
OPERATIONAL = "operational",
|
|
79
|
+
FILTERED = "filtered",
|
|
80
|
+
IGNORED = "ignored"
|
|
81
|
+
}
|
|
82
|
+
export interface SyncMapperRecordExternalVersion {
|
|
83
|
+
recipe_version: number;
|
|
84
|
+
modified_date: string;
|
|
85
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncMapperRecordStatus = void 0;
|
|
4
|
+
var SyncMapperRecordStatus;
|
|
5
|
+
(function (SyncMapperRecordStatus) {
|
|
6
|
+
SyncMapperRecordStatus["OPERATIONAL"] = "operational";
|
|
7
|
+
SyncMapperRecordStatus["FILTERED"] = "filtered";
|
|
8
|
+
SyncMapperRecordStatus["IGNORED"] = "ignored";
|
|
9
|
+
})(SyncMapperRecordStatus || (exports.SyncMapperRecordStatus = SyncMapperRecordStatus = {}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Mappers = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class Mappers {
|
|
9
|
+
constructor({ event }) {
|
|
10
|
+
this.endpoint = event.execution_metadata.devrev_endpoint;
|
|
11
|
+
this.token = event.context.secrets.service_account_token;
|
|
12
|
+
}
|
|
13
|
+
async getByTargetId(params) {
|
|
14
|
+
const { sync_unit, target } = params;
|
|
15
|
+
return axios_1.default.get(`${this.endpoint}/internal/airdrop.sync-mapper-record.get-by-target`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: this.token,
|
|
18
|
+
},
|
|
19
|
+
params: { sync_unit, target },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async create(params) {
|
|
23
|
+
return axios_1.default.post(`${this.endpoint}/internal/airdrop.sync-mapper-record.create`, params, {
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: this.token,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async update(params) {
|
|
30
|
+
return axios_1.default.post(`${this.endpoint}/internal/airdrop.sync-mapper-record.update`, params, {
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: this.token,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Mappers = Mappers;
|
package/dist/state/state.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AdapterState, StateInterface } from './state.interfaces';
|
|
|
3
3
|
export declare function createAdapterState<ConnectorState>({ event, initialState, options, }: StateInterface<ConnectorState>): Promise<State<ConnectorState>>;
|
|
4
4
|
export declare class State<ConnectorState> {
|
|
5
5
|
private _state;
|
|
6
|
+
private initialSdkState;
|
|
6
7
|
private event;
|
|
7
8
|
private workerUrl;
|
|
8
9
|
private devrevToken;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { AirdropEvent } from '../types/extraction';
|
|
2
|
+
import { FileToLoad } from '../types/loading';
|
|
2
3
|
import { WorkerAdapterOptions } from '../types/workers';
|
|
3
|
-
|
|
4
|
-
* AdapterState is an interface that defines the structure of the adapter state that is used by the external extractor. It extends the connector state with additional fields: lastSyncStarted, lastSuccessfulSyncStarted, and attachmentsMetadata.
|
|
5
|
-
*/
|
|
6
|
-
export type AdapterState<ConnectorState> = ConnectorState & {
|
|
4
|
+
export interface SdkState {
|
|
7
5
|
lastSyncStarted?: string;
|
|
8
6
|
lastSuccessfulSyncStarted?: string;
|
|
9
7
|
toDevRev?: ToDevRev;
|
|
10
8
|
fromDevRev?: FromDevRev;
|
|
11
|
-
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* AdapterState is an interface that defines the structure of the adapter state that is used by the external extractor. It extends the connector state with additional fields: lastSyncStarted, lastSuccessfulSyncStarted, and attachmentsMetadata.
|
|
12
|
+
*/
|
|
13
|
+
export type AdapterState<ConnectorState> = ConnectorState & SdkState;
|
|
12
14
|
export interface ToDevRev {
|
|
13
15
|
attachmentsMetadata: {
|
|
14
16
|
artifactIds: string[];
|
|
@@ -16,6 +18,7 @@ export interface ToDevRev {
|
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export interface FromDevRev {
|
|
21
|
+
filesToLoad: FileToLoad[];
|
|
19
22
|
}
|
|
20
23
|
export interface StateInterface<ConnectorState> {
|
|
21
24
|
event: AirdropEvent;
|
package/dist/state/state.js
CHANGED
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.State = void 0;
|
|
7
7
|
exports.createAdapterState = createAdapterState;
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const extraction_1 = require("../types/extraction");
|
|
9
10
|
const constants_1 = require("../common/constants");
|
|
10
11
|
const logger_1 = require("../logger/logger");
|
|
12
|
+
const helpers_1 = require("../common/helpers");
|
|
11
13
|
async function createAdapterState({ event, initialState, options, }) {
|
|
12
14
|
const newInitialState = structuredClone(initialState);
|
|
13
15
|
const as = new State({
|
|
@@ -22,12 +24,24 @@ async function createAdapterState({ event, initialState, options, }) {
|
|
|
22
24
|
}
|
|
23
25
|
class State {
|
|
24
26
|
constructor({ event, initialState }) {
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
this.initialSdkState =
|
|
28
|
+
(0, helpers_1.getSyncDirection)({ event }) === extraction_1.SyncMode.LOADING
|
|
29
|
+
? {
|
|
30
|
+
fromDevRev: {
|
|
31
|
+
filesToLoad: [],
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
lastSyncStarted: new Date().toISOString(),
|
|
36
|
+
lastSuccessfulSyncStarted: '',
|
|
37
|
+
toDevRev: {
|
|
38
|
+
attachmentsMetadata: {
|
|
39
|
+
artifactIds: [],
|
|
40
|
+
lastProcessed: 0,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
this._state = Object.assign(Object.assign({}, initialState), this.initialSdkState);
|
|
31
45
|
this.event = event;
|
|
32
46
|
this.workerUrl = event.payload.event_context.worker_data_url;
|
|
33
47
|
this.devrevToken = event.context.secrets.service_account_token;
|
|
@@ -94,12 +108,7 @@ class State {
|
|
|
94
108
|
}
|
|
95
109
|
catch (error) {
|
|
96
110
|
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
97
|
-
const state = Object.assign(Object.assign({}, initialState),
|
|
98
|
-
attachmentsMetadata: {
|
|
99
|
-
artifactIds: [],
|
|
100
|
-
lastProcessed: 0,
|
|
101
|
-
},
|
|
102
|
-
}, fromDevRev: {} });
|
|
111
|
+
const state = Object.assign(Object.assign({}, initialState), this.initialSdkState);
|
|
103
112
|
this.state = state;
|
|
104
113
|
console.log('State not found, returning initial state. Current state:', (0, logger_1.getPrintableState)(this.state));
|
|
105
114
|
await this.postState(this.state);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helpers_1 = require("../../common/helpers");
|
|
4
|
+
describe('getFilesToLoad', () => {
|
|
5
|
+
let statsFile;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
statsFile = [
|
|
8
|
+
{
|
|
9
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/2',
|
|
10
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
11
|
+
item_type: 'issues',
|
|
12
|
+
count: '79',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/5',
|
|
16
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
17
|
+
item_type: 'comments',
|
|
18
|
+
count: '1079',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/9',
|
|
22
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
23
|
+
item_type: 'issues',
|
|
24
|
+
count: '1921',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/14',
|
|
28
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
29
|
+
item_type: 'comments',
|
|
30
|
+
count: '921',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
34
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
35
|
+
item_type: 'attachments',
|
|
36
|
+
count: '50',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
40
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
41
|
+
item_type: 'unknown',
|
|
42
|
+
count: '50',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
46
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
47
|
+
item_type: 'issues',
|
|
48
|
+
count: '32',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
it('should return an empty array if statsFile is empty', () => {
|
|
53
|
+
statsFile = [];
|
|
54
|
+
const itemTypesToLoad = [];
|
|
55
|
+
const result = (0, helpers_1.getFilesToLoad)({ itemTypesToLoad, statsFile });
|
|
56
|
+
expect(result).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
it('should return an empty array if itemTypesToLoad is empty', () => {
|
|
59
|
+
const itemTypesToLoad = [];
|
|
60
|
+
const result = (0, helpers_1.getFilesToLoad)({ itemTypesToLoad, statsFile });
|
|
61
|
+
expect(result).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
it('should return an empty array if statsFile has no matching items', () => {
|
|
64
|
+
const itemTypesToLoad = [
|
|
65
|
+
{ itemType: 'users', create: jest.fn(), update: jest.fn() },
|
|
66
|
+
];
|
|
67
|
+
const result = (0, helpers_1.getFilesToLoad)({ itemTypesToLoad, statsFile });
|
|
68
|
+
expect(result).toEqual([]);
|
|
69
|
+
});
|
|
70
|
+
it('should filter out files not in itemTypesToLoad and order them by itemTypesToLoad', () => {
|
|
71
|
+
const itemTypesToLoad = [
|
|
72
|
+
{ itemType: 'attachments', create: jest.fn(), update: jest.fn() },
|
|
73
|
+
{ itemType: 'issues', create: jest.fn(), update: jest.fn() },
|
|
74
|
+
];
|
|
75
|
+
const result = (0, helpers_1.getFilesToLoad)({ itemTypesToLoad, statsFile });
|
|
76
|
+
expect(result).toEqual([
|
|
77
|
+
{
|
|
78
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
79
|
+
itemType: 'attachments',
|
|
80
|
+
count: 50,
|
|
81
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
82
|
+
completed: false,
|
|
83
|
+
lineToProcess: 0,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/2',
|
|
87
|
+
itemType: 'issues',
|
|
88
|
+
count: 79,
|
|
89
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
90
|
+
completed: false,
|
|
91
|
+
lineToProcess: 0,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/9',
|
|
95
|
+
itemType: 'issues',
|
|
96
|
+
count: 1921,
|
|
97
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
98
|
+
completed: false,
|
|
99
|
+
lineToProcess: 0,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
103
|
+
itemType: 'issues',
|
|
104
|
+
count: 32,
|
|
105
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
106
|
+
completed: false,
|
|
107
|
+
lineToProcess: 0,
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
it('should ignore files with unrecognized item types in statsFile', () => {
|
|
112
|
+
const itemTypesToLoad = [
|
|
113
|
+
{ itemType: 'issues', create: jest.fn(), update: jest.fn() },
|
|
114
|
+
];
|
|
115
|
+
const result = (0, helpers_1.getFilesToLoad)({
|
|
116
|
+
itemTypesToLoad,
|
|
117
|
+
statsFile,
|
|
118
|
+
});
|
|
119
|
+
expect(result).toEqual([
|
|
120
|
+
{
|
|
121
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/2',
|
|
122
|
+
itemType: 'issues',
|
|
123
|
+
count: 79,
|
|
124
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
125
|
+
completed: false,
|
|
126
|
+
lineToProcess: 0,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/9',
|
|
130
|
+
itemType: 'issues',
|
|
131
|
+
count: 1921,
|
|
132
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
133
|
+
completed: false,
|
|
134
|
+
lineToProcess: 0,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'don:core:dvrv-us-1:devo/1:artifact/99',
|
|
138
|
+
itemType: 'issues',
|
|
139
|
+
count: 32,
|
|
140
|
+
file_name: 'transformer_issues_X.json.gz',
|
|
141
|
+
completed: false,
|
|
142
|
+
lineToProcess: 0,
|
|
143
|
+
},
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -17,21 +17,27 @@ function createEvent({ eventType, externalSyncUnits = [], progress, error, delay
|
|
|
17
17
|
key: 'test_key',
|
|
18
18
|
key_type: 'test_key_type',
|
|
19
19
|
}, event_context: {
|
|
20
|
-
mode: 'test_mode',
|
|
21
20
|
callback_url: 'test_callback_url',
|
|
21
|
+
dev_org: 'test_dev_org',
|
|
22
22
|
dev_org_id: 'test_dev_org_id',
|
|
23
|
+
dev_user: 'test_dev_user',
|
|
23
24
|
dev_user_id: 'test_dev_user_id',
|
|
25
|
+
external_sync_unit: 'test_external_sync_unit',
|
|
24
26
|
external_sync_unit_id: 'test_external_sync_unit_id',
|
|
25
|
-
|
|
26
|
-
sync_run_id: 'test_sync_run_id',
|
|
27
|
-
external_system_id: 'test_external_system_id',
|
|
28
|
-
uuid: 'test_uuid',
|
|
29
|
-
worker_data_url: 'test_worker_data_url',
|
|
27
|
+
external_sync_unit_name: 'test_external_sync_unit_name',
|
|
30
28
|
external_system: 'test_external_system',
|
|
31
29
|
external_system_type: 'test_external_system_type',
|
|
32
30
|
import_slug: 'test_import_slug',
|
|
31
|
+
mode: 'test_mode',
|
|
32
|
+
request_id: 'test_request_id',
|
|
33
33
|
snap_in_slug: 'test_snap_in_slug',
|
|
34
|
+
sync_run: 'test_sync_run',
|
|
35
|
+
sync_run_id: 'test_sync_run_id',
|
|
34
36
|
sync_tier: 'test_sync_tier',
|
|
37
|
+
sync_unit: 'test_sync_unit',
|
|
38
|
+
sync_unit_id: 'test_sync_unit_id',
|
|
39
|
+
uuid: 'test_uuid',
|
|
40
|
+
worker_data_url: 'test_worker_data_url',
|
|
35
41
|
}, event_type: eventType, event_data: {
|
|
36
42
|
external_sync_units: externalSyncUnits,
|
|
37
43
|
progress,
|