@devrev/airsync-sdk 2.0.0-beta.3 → 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/README.md +5 -11
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +7 -9
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +2 -7
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +54 -56
- package/dist/common/constants.d.ts +4 -5
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +6 -7
- package/dist/common/helpers.d.ts +3 -35
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +5 -50
- 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} +4 -8
- package/dist/index.d.ts +24 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -32
- package/dist/logger/logger.d.ts +12 -53
- 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 +36 -68
- package/dist/mappers/mappers.d.ts +7 -46
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +175 -0
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +4 -13
- package/dist/mappers/mappers.js +11 -45
- package/dist/multithreading/adapters/base-adapter.d.ts +30 -32
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/base-adapter.js +97 -62
- package/dist/multithreading/adapters/extraction-adapter.d.ts +16 -29
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/extraction-adapter.js +203 -206
- package/dist/multithreading/adapters/loading-adapter.d.ts +8 -13
- 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 +294 -346
- package/dist/multithreading/emit.d.ts +11 -0
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/{common/control-protocol.js → multithreading/emit.js} +5 -7
- 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 +46 -43
- 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 +12 -11
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +128 -20
- package/dist/multithreading/spawn/spawn.js +24 -39
- package/dist/multithreading/worker.js +1 -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 +16 -38
- package/dist/state/base-state.d.ts.map +1 -1
- package/dist/state/base-state.js +19 -41
- package/dist/state/extraction-state.d.ts +6 -21
- package/dist/state/extraction-state.d.ts.map +1 -1
- package/dist/state/extraction-state.js +8 -25
- package/dist/{common → state}/install-initial-domain-mapping.d.ts +1 -1
- 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 +3 -14
- package/dist/state/loading-state.d.ts.map +1 -1
- package/dist/state/loading-state.js +3 -14
- package/dist/state/state.d.ts +4 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.interfaces.d.ts +33 -37
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +16 -11
- package/dist/state/state.js +11 -0
- package/dist/state/time-value-resolver.d.ts +17 -0
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/{common → state}/time-value-resolver.js +9 -41
- package/dist/testing/mock-event.d.ts +10 -0
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/{common/test-utils.js → testing/mock-event.js} +17 -14
- package/dist/testing/mock-server.d.ts +29 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts +48 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/{mock-server → testing}/mock-server.js +21 -33
- 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/errors.d.ts +9 -0
- package/dist/types/errors.d.ts.map +1 -0
- 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 +64 -94
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +6 -34
- package/dist/types/loading.d.ts +1 -2
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +0 -1
- package/dist/types/workers.d.ts +39 -94
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +0 -6
- package/dist/uploader/uploader.d.ts +8 -59
- 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 +23 -89
- package/package.json +8 -6
- package/dist/airsync-sdk.d.ts +0 -2059
- 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 -540
- package/dist/common/control-protocol.d.ts +0 -10
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.js +0 -211
- package/dist/common/test-utils.d.ts +0 -19
- package/dist/common/test-utils.d.ts.map +0 -1
- package/dist/common/time-value-resolver.d.ts +0 -47
- package/dist/common/time-value-resolver.d.ts.map +0 -1
- package/dist/common/time-value-resolver.test.d.ts +0 -2
- package/dist/common/time-value-resolver.test.d.ts.map +0 -1
- package/dist/common/time-value-resolver.test.js +0 -268
- package/dist/http/axios-client-internal.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.d.ts +0 -2
- package/dist/http/axios-client-internal.test.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.js +0 -175
- package/dist/http/axios-client.d.ts +0 -27
- package/dist/http/axios-client.d.ts.map +0 -1
- package/dist/http/axios-client.js +0 -60
- package/dist/http/constants.d.ts +0 -4
- package/dist/http/constants.d.ts.map +0 -1
- package/dist/http/constants.js +0 -6
- package/dist/http/index.d.ts +0 -2
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -17
- package/dist/logger/logger.constants.d.ts +0 -6
- package/dist/logger/logger.constants.d.ts.map +0 -1
- package/dist/logger/logger.constants.js +0 -13
- package/dist/logger/logger.context.d.ts +0 -58
- package/dist/logger/logger.context.d.ts.map +0 -1
- package/dist/logger/logger.context.js +0 -86
- package/dist/logger/logger.test.d.ts +0 -2
- package/dist/logger/logger.test.d.ts.map +0 -1
- package/dist/logger/logger.test.js +0 -537
- package/dist/mappers/mappers.interface.d.ts +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 -105
- package/dist/mock-server/mock-server.d.ts +0 -47
- package/dist/mock-server/mock-server.d.ts.map +0 -1
- package/dist/mock-server/mock-server.interfaces.d.ts +0 -73
- package/dist/mock-server/mock-server.interfaces.d.ts.map +0 -1
- package/dist/multithreading/adapters/base-adapter.emit.test.d.ts +0 -2
- package/dist/multithreading/adapters/base-adapter.emit.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/base-adapter.emit.test.js +0 -403
- package/dist/multithreading/adapters/extraction-adapter.artifacts.test.d.ts +0 -2
- package/dist/multithreading/adapters/extraction-adapter.artifacts.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/extraction-adapter.artifacts.test.js +0 -175
- package/dist/multithreading/adapters/extraction-adapter.test.d.ts +0 -2
- package/dist/multithreading/adapters/extraction-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/extraction-adapter.test.js +0 -789
- package/dist/multithreading/adapters/loading-adapter.helpers.test.d.ts +0 -2
- package/dist/multithreading/adapters/loading-adapter.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.test.js +0 -514
- package/dist/multithreading/adapters/loading-adapter.test.d.ts +0 -2
- package/dist/multithreading/adapters/loading-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/loading-adapter.test.js +0 -589
- package/dist/multithreading/adapters/serialization.test.d.ts +0 -2
- package/dist/multithreading/adapters/serialization.test.d.ts.map +0 -1
- package/dist/multithreading/adapters/serialization.test.js +0 -71
- package/dist/multithreading/create-worker.test.d.ts +0 -2
- package/dist/multithreading/create-worker.test.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.js +0 -108
- package/dist/multithreading/process-task.test.d.ts +0 -2
- package/dist/multithreading/process-task.test.d.ts.map +0 -1
- package/dist/multithreading/process-task.test.js +0 -146
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
- package/dist/multithreading/spawn/spawn.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.test.js +0 -232
- package/dist/repo/repo.test.d.ts +0 -2
- package/dist/repo/repo.test.d.ts.map +0 -1
- package/dist/repo/repo.test.js +0 -184
- package/dist/state/state.extract-window.test.d.ts +0 -2
- package/dist/state/state.extract-window.test.d.ts.map +0 -1
- package/dist/state/state.extract-window.test.js +0 -163
- package/dist/state/state.pending-boundaries.test.d.ts +0 -2
- package/dist/state/state.pending-boundaries.test.d.ts.map +0 -1
- package/dist/state/state.pending-boundaries.test.js +0 -189
- package/dist/state/state.post-state.test.d.ts +0 -2
- package/dist/state/state.post-state.test.d.ts.map +0 -1
- package/dist/state/state.post-state.test.js +0 -78
- 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 -271
- package/dist/state/state.time-value-resolution.test.d.ts +0 -2
- package/dist/state/state.time-value-resolution.test.d.ts.map +0 -1
- package/dist/state/state.time-value-resolution.test.js +0 -175
- package/dist/tsdoc-metadata.json +0 -11
- package/dist/types/extraction.test.d.ts +0 -2
- package/dist/types/extraction.test.d.ts.map +0 -1
- package/dist/types/extraction.test.js +0 -96
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -21
- package/dist/uploader/uploader.helpers.test.d.ts +0 -2
- package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
- package/dist/uploader/uploader.helpers.test.js +0 -256
- package/dist/uploader/uploader.test.d.ts +0 -2
- package/dist/uploader/uploader.test.d.ts.map +0 -1
- package/dist/uploader/uploader.test.js +0 -601
- /package/dist/{mock-server → testing}/mock-server.interfaces.js +0 -0
- /package/dist/{common → types}/errors.js +0 -0
|
@@ -5,26 +5,15 @@ exports.createLoadingState = createLoadingState;
|
|
|
5
5
|
const constants_1 = require("../common/constants");
|
|
6
6
|
const base_state_1 = require("./base-state");
|
|
7
7
|
const state_interfaces_1 = require("./state.interfaces");
|
|
8
|
-
/**
|
|
9
|
-
* LoadingState is the per-mode state for loading workers. It narrows `sdkState`
|
|
10
|
-
* to `LoadingSdkState` (files-to-load bookkeeping) on top of the shared
|
|
11
|
-
* lifecycle provided by `BaseState`.
|
|
12
|
-
*/
|
|
8
|
+
/** State for loading workers: seeds loading SDK state; no extraction-window resolution. */
|
|
13
9
|
class LoadingState extends base_state_1.BaseState {
|
|
14
10
|
constructor(params) {
|
|
15
|
-
super(params, state_interfaces_1.
|
|
11
|
+
super(params, state_interfaces_1.loadingSdkState);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
14
|
exports.LoadingState = LoadingState;
|
|
19
|
-
/**
|
|
20
|
-
* Creates and initializes a `LoadingState` for a loading worker.
|
|
21
|
-
*
|
|
22
|
-
* For non-stateless events this fetches/migrates persisted state and installs
|
|
23
|
-
* the initial domain mapping if the snap-in version changed. Loading has no
|
|
24
|
-
* extraction-window resolution, so the factory is otherwise minimal.
|
|
25
|
-
*/
|
|
26
15
|
async function createLoadingState({ event, initialState, initialDomainMapping, options, }) {
|
|
27
|
-
//
|
|
16
|
+
// Clone so the caller's initialState is never mutated.
|
|
28
17
|
const deepCloneInitialState = structuredClone(initialState);
|
|
29
18
|
const state = new LoadingState({
|
|
30
19
|
event,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -2,40 +2,17 @@ import { InitialDomainMapping } from '../types/common';
|
|
|
2
2
|
import { AirSyncEvent } from '../types/extraction';
|
|
3
3
|
import { FileToLoad } from '../types/loading';
|
|
4
4
|
import { WorkerAdapterOptions } from '../types/workers';
|
|
5
|
-
|
|
6
|
-
* BaseSdkState holds SDK bookkeeping common to every sync mode.
|
|
7
|
-
*/
|
|
8
|
-
export interface BaseSdkState {
|
|
9
|
-
snapInVersionId?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* ExtractionSdkState holds SDK bookkeeping owned by the extraction modes.
|
|
13
|
-
*/
|
|
14
|
-
export interface ExtractionSdkState extends BaseSdkState {
|
|
15
|
-
/** The pending (not yet committed) oldest extraction boundary (ISO 8601 timestamp).
|
|
16
|
-
* Set on StartExtractingMetadata, reused across subsequent phases, cleared on AttachmentExtractionDone. */
|
|
5
|
+
export interface SdkState {
|
|
17
6
|
pendingWorkersOldest?: string;
|
|
18
|
-
/** The pending (not yet committed) newest extraction boundary (ISO 8601 timestamp).
|
|
19
|
-
* Set on StartExtractingMetadata, reused across subsequent phases, cleared on AttachmentExtractionDone. */
|
|
20
7
|
pendingWorkersNewest?: string;
|
|
21
|
-
/** The oldest point of extraction (ISO 8601 timestamp). */
|
|
22
8
|
workersOldest?: string;
|
|
23
|
-
/** The newest point of extraction (ISO 8601 timestamp). */
|
|
24
9
|
workersNewest?: string;
|
|
25
10
|
toDevRev?: ToDevRev;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* LoadingSdkState holds SDK bookkeeping owned by the loading modes.
|
|
29
|
-
*/
|
|
30
|
-
export interface LoadingSdkState extends BaseSdkState {
|
|
31
11
|
fromDevRev?: FromDevRev;
|
|
12
|
+
snapInVersionId?: string;
|
|
32
13
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
* bookkeeping are stored as disjoint sub-objects so SDK internals stay
|
|
36
|
-
* encapsulated and never collide with connector keys.
|
|
37
|
-
*/
|
|
38
|
-
export interface AdapterStateEnvelope<ConnectorState, SdkState extends BaseSdkState> {
|
|
14
|
+
/** v2 on-disk state shape: SDK bookkeeping kept disjoint from connector keys. */
|
|
15
|
+
export interface AdapterStateEnvelope<ConnectorState> {
|
|
39
16
|
connectorState: ConnectorState;
|
|
40
17
|
sdkState: SdkState;
|
|
41
18
|
}
|
|
@@ -46,12 +23,15 @@ export interface ToDevRev {
|
|
|
46
23
|
lastProcessedAttachmentsIdsList?: ProcessedAttachment[];
|
|
47
24
|
};
|
|
48
25
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
export declare enum ProcessedAttachmentStatus {
|
|
27
|
+
Success = "success",
|
|
28
|
+
Failed = "failed"
|
|
29
|
+
}
|
|
30
|
+
/** id + parent_id identify an attachment for SDK-side deduplication. */
|
|
52
31
|
export interface ProcessedAttachment {
|
|
53
32
|
id: string;
|
|
54
33
|
parent_id: string;
|
|
34
|
+
status: ProcessedAttachmentStatus;
|
|
55
35
|
}
|
|
56
36
|
export interface FromDevRev {
|
|
57
37
|
filesToLoad: FileToLoad[];
|
|
@@ -62,14 +42,30 @@ export interface StateInterface<ConnectorState> {
|
|
|
62
42
|
initialDomainMapping?: InitialDomainMapping;
|
|
63
43
|
options?: WorkerAdapterOptions;
|
|
64
44
|
}
|
|
65
|
-
export declare const
|
|
66
|
-
|
|
45
|
+
export declare const extractionSdkState: {
|
|
46
|
+
pendingWorkersOldest: string;
|
|
47
|
+
pendingWorkersNewest: string;
|
|
48
|
+
workersOldest: string;
|
|
49
|
+
workersNewest: string;
|
|
50
|
+
snapInVersionId: string;
|
|
51
|
+
toDevRev: {
|
|
52
|
+
attachmentsMetadata: {
|
|
53
|
+
artifactIds: never[];
|
|
54
|
+
lastProcessed: number;
|
|
55
|
+
lastProcessedAttachmentsIdsList: never[];
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare const loadingSdkState: {
|
|
60
|
+
snapInVersionId: string;
|
|
61
|
+
fromDevRev: {
|
|
62
|
+
filesToLoad: never[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
67
65
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* `{ connectorState, sdkState }` envelope: keys in this set go to `sdkState`,
|
|
72
|
-
* everything else is connector state.
|
|
66
|
+
* SDK-owned top-level state keys, used to split a flat v1 blob during migration.
|
|
67
|
+
* `lastSyncStarted` / `lastSuccessfulSyncStarted` are no longer on `SdkState` but
|
|
68
|
+
* stay listed so v1 blobs carrying them don't leak them into connector state.
|
|
73
69
|
*/
|
|
74
70
|
export declare const V1_SDK_STATE_KEYS: ReadonlySet<string>;
|
|
75
71
|
//# sourceMappingURL=state.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.interfaces.d.ts","sourceRoot":"","sources":["../../src/state/state.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"state.interfaces.d.ts","sourceRoot":"","sources":["../../src/state/state.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,QAAQ;IAGvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,iFAAiF;AACjF,MAAM,WAAW,oBAAoB,CAAC,cAAc;IAClD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,mBAAmB,EAAE;QACnB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,+BAA+B,CAAC,EAAE,mBAAmB,EAAE,CAAC;KACzD,CAAC;CACH;AAED,oBAAY,yBAAyB;IACnC,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB;AAED,wEAAwE;AACxE,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc,CAAC,cAAc;IAC5C,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,cAAc,CAAC;IAC7B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAa9B,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;CAK3B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAKhD,CAAC"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.V1_SDK_STATE_KEYS = exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.V1_SDK_STATE_KEYS = exports.loadingSdkState = exports.extractionSdkState = exports.ProcessedAttachmentStatus = void 0;
|
|
4
|
+
var ProcessedAttachmentStatus;
|
|
5
|
+
(function (ProcessedAttachmentStatus) {
|
|
6
|
+
ProcessedAttachmentStatus["Success"] = "success";
|
|
7
|
+
ProcessedAttachmentStatus["Failed"] = "failed";
|
|
8
|
+
})(ProcessedAttachmentStatus || (exports.ProcessedAttachmentStatus = ProcessedAttachmentStatus = {}));
|
|
9
|
+
exports.extractionSdkState = {
|
|
6
10
|
pendingWorkersOldest: '',
|
|
7
11
|
pendingWorkersNewest: '',
|
|
8
12
|
workersOldest: '',
|
|
9
13
|
workersNewest: '',
|
|
14
|
+
snapInVersionId: '',
|
|
10
15
|
toDevRev: {
|
|
11
16
|
attachmentsMetadata: {
|
|
12
17
|
artifactIds: [],
|
|
@@ -15,20 +20,20 @@ exports.initialExtractionSdkState = {
|
|
|
15
20
|
},
|
|
16
21
|
},
|
|
17
22
|
};
|
|
18
|
-
exports.
|
|
23
|
+
exports.loadingSdkState = {
|
|
19
24
|
snapInVersionId: '',
|
|
20
25
|
fromDevRev: {
|
|
21
26
|
filesToLoad: [],
|
|
22
27
|
},
|
|
23
28
|
};
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* `{ connectorState, sdkState }` envelope: keys in this set go to `sdkState`,
|
|
29
|
-
* everything else is connector state.
|
|
30
|
+
* SDK-owned top-level state keys, used to split a flat v1 blob during migration.
|
|
31
|
+
* `lastSyncStarted` / `lastSuccessfulSyncStarted` are no longer on `SdkState` but
|
|
32
|
+
* stay listed so v1 blobs carrying them don't leak them into connector state.
|
|
30
33
|
*/
|
|
31
34
|
exports.V1_SDK_STATE_KEYS = new Set([
|
|
32
|
-
...Object.keys(exports.
|
|
33
|
-
...Object.keys(exports.
|
|
35
|
+
...Object.keys(exports.extractionSdkState),
|
|
36
|
+
...Object.keys(exports.loadingSdkState),
|
|
37
|
+
'lastSyncStarted',
|
|
38
|
+
'lastSuccessfulSyncStarted',
|
|
34
39
|
]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoadingState = exports.createLoadingState = exports.ExtractionState = exports.createExtractionState = exports.BaseState = void 0;
|
|
4
|
+
var base_state_1 = require("./base-state");
|
|
5
|
+
Object.defineProperty(exports, "BaseState", { enumerable: true, get: function () { return base_state_1.BaseState; } });
|
|
6
|
+
var extraction_state_1 = require("./extraction-state");
|
|
7
|
+
Object.defineProperty(exports, "createExtractionState", { enumerable: true, get: function () { return extraction_state_1.createExtractionState; } });
|
|
8
|
+
Object.defineProperty(exports, "ExtractionState", { enumerable: true, get: function () { return extraction_state_1.ExtractionState; } });
|
|
9
|
+
var loading_state_1 = require("./loading-state");
|
|
10
|
+
Object.defineProperty(exports, "createLoadingState", { enumerable: true, get: function () { return loading_state_1.createLoadingState; } });
|
|
11
|
+
Object.defineProperty(exports, "LoadingState", { enumerable: true, get: function () { return loading_state_1.LoadingState; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SdkState } from '../state/state.interfaces';
|
|
2
|
+
import { TimeUnit, TimeValue } from '../types/extraction';
|
|
3
|
+
/** Parses a shorthand duration (e.g. '100ns', '500ms', '5m', '2h'); units are the `TimeUnit` values. */
|
|
4
|
+
export declare function parseDuration(shorthand: string): {
|
|
5
|
+
value: number;
|
|
6
|
+
unit: TimeUnit;
|
|
7
|
+
};
|
|
8
|
+
/** Adds/subtracts a shorthand duration to/from an ISO 8601 timestamp. */
|
|
9
|
+
export declare function applyDuration(baseTimestamp: string, duration: string, operation: 'add' | 'subtract'): string;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a TimeValue into a concrete ISO 8601 timestamp. WORKERS_* types
|
|
12
|
+
* read the boundaries from state and fall back to UNBOUNDED when unset
|
|
13
|
+
* (backwards compatibility with old state); *_WINDOW types apply the duration
|
|
14
|
+
* in `timeValue.value` to the boundary.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveTimeValue(timeValue: TimeValue, state: SdkState): string;
|
|
17
|
+
//# sourceMappingURL=time-value-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-value-resolver.d.ts","sourceRoot":"","sources":["../../src/state/time-value-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAiB,MAAM,qBAAqB,CAAC;AAEzE,wGAAwG;AACxG,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB,CAcA;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,KAAK,GAAG,UAAU,GAC5B,MAAM,CA6BR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,QAAQ,GACd,MAAM,CAqER"}
|
|
@@ -3,20 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseDuration = parseDuration;
|
|
4
4
|
exports.applyDuration = applyDuration;
|
|
5
5
|
exports.resolveTimeValue = resolveTimeValue;
|
|
6
|
+
const constants_1 = require("../common/constants");
|
|
6
7
|
const extraction_1 = require("../types/extraction");
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Parses a shorthand duration string into its numeric value and unit.
|
|
10
|
-
* Supported units:
|
|
11
|
-
* - 'ns' for nanoseconds
|
|
12
|
-
* - 'us' or 'µs' for microseconds
|
|
13
|
-
* - 'ms' for milliseconds
|
|
14
|
-
* - 's' for seconds
|
|
15
|
-
* - 'm' for minutes
|
|
16
|
-
* - 'h' for hours
|
|
17
|
-
*
|
|
18
|
-
* @throws Error if the format is invalid
|
|
19
|
-
*/
|
|
8
|
+
/** Parses a shorthand duration (e.g. '100ns', '500ms', '5m', '2h'); units are the `TimeUnit` values. */
|
|
20
9
|
function parseDuration(shorthand) {
|
|
21
10
|
const validUnits = Object.values(extraction_1.TimeUnit).join('|');
|
|
22
11
|
const match = shorthand.match(new RegExp(`^(\\d+(?:\\.\\d+)?)(${validUnits})$`));
|
|
@@ -28,14 +17,7 @@ function parseDuration(shorthand) {
|
|
|
28
17
|
unit: match[2],
|
|
29
18
|
};
|
|
30
19
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Applies a shorthand duration to a base ISO 8601 timestamp.
|
|
33
|
-
*
|
|
34
|
-
* @param baseTimestamp - ISO 8601 timestamp to apply duration to
|
|
35
|
-
* @param duration - Shorthand duration string (e.g. '100ns', '500ms', '30s', '5m', '2h')
|
|
36
|
-
* @param operation - Whether to 'add' or 'subtract' the duration
|
|
37
|
-
* @returns ISO 8601 timestamp with the duration applied
|
|
38
|
-
*/
|
|
20
|
+
/** Adds/subtracts a shorthand duration to/from an ISO 8601 timestamp. */
|
|
39
21
|
function applyDuration(baseTimestamp, duration, operation) {
|
|
40
22
|
const { value, unit } = parseDuration(duration);
|
|
41
23
|
const date = new Date(baseTimestamp);
|
|
@@ -65,22 +47,10 @@ function applyDuration(baseTimestamp, duration, operation) {
|
|
|
65
47
|
return date.toISOString();
|
|
66
48
|
}
|
|
67
49
|
/**
|
|
68
|
-
* Resolves a TimeValue into a concrete ISO 8601 timestamp
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* - NOW: Returns the current time as ISO 8601
|
|
73
|
-
* - UNBOUNDED: Returns UNBOUNDED_DATE_TIME_VALUE ('1970-01-01T00:00:00.000Z')
|
|
74
|
-
* - WORKERS_OLDEST: Returns workersOldest from state, or throws if not set
|
|
75
|
-
* - WORKERS_NEWEST: Returns workersNewest from state, or throws if not set
|
|
76
|
-
* - WORKERS_OLDEST_MINUS_WINDOW: Subtracts duration from workersOldest, or throws if not set
|
|
77
|
-
* - WORKERS_NEWEST_PLUS_WINDOW: Adds duration to workersNewest, or throws if not set
|
|
78
|
-
*
|
|
79
|
-
* @param timeValue - The TimeValue to resolve
|
|
80
|
-
* @param state - The current SDK state containing workersOldest and workersNewest
|
|
81
|
-
* @returns Resolved ISO 8601 timestamp string
|
|
82
|
-
* @throws Error if required TimeValue.value is missing for ABSOLUTE or *_WINDOW types
|
|
83
|
-
* @throws Error if workersOldest/workersNewest is not set in state for WORKERS_* types
|
|
50
|
+
* Resolves a TimeValue into a concrete ISO 8601 timestamp. WORKERS_* types
|
|
51
|
+
* read the boundaries from state and fall back to UNBOUNDED when unset
|
|
52
|
+
* (backwards compatibility with old state); *_WINDOW types apply the duration
|
|
53
|
+
* in `timeValue.value` to the boundary.
|
|
84
54
|
*/
|
|
85
55
|
function resolveTimeValue(timeValue, state) {
|
|
86
56
|
switch (timeValue.type) {
|
|
@@ -104,14 +74,13 @@ function resolveTimeValue(timeValue, state) {
|
|
|
104
74
|
}
|
|
105
75
|
case extraction_1.TimeValueType.WORKERS_OLDEST: {
|
|
106
76
|
if (!state.workersOldest) {
|
|
107
|
-
// To support backwards-compatibility for the old state
|
|
108
77
|
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
109
78
|
}
|
|
110
79
|
return state.workersOldest;
|
|
111
80
|
}
|
|
112
81
|
case extraction_1.TimeValueType.WORKERS_NEWEST: {
|
|
113
82
|
if (!state.workersNewest) {
|
|
114
|
-
|
|
83
|
+
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
115
84
|
}
|
|
116
85
|
return state.workersNewest;
|
|
117
86
|
}
|
|
@@ -120,7 +89,6 @@ function resolveTimeValue(timeValue, state) {
|
|
|
120
89
|
throw new Error("TimeValue of type WORKERS_OLDEST_MINUS_WINDOW must have a value (duration, e.g. '30s', '5m', '2h').");
|
|
121
90
|
}
|
|
122
91
|
if (!state.workersOldest) {
|
|
123
|
-
// To support backwards-compatibility for the old state
|
|
124
92
|
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
125
93
|
}
|
|
126
94
|
return applyDuration(state.workersOldest, timeValue.value, 'subtract');
|
|
@@ -130,7 +98,7 @@ function resolveTimeValue(timeValue, state) {
|
|
|
130
98
|
throw new Error("TimeValue of type WORKERS_NEWEST_PLUS_WINDOW must have a value (duration, e.g. '30s', '5m', '2h').");
|
|
131
99
|
}
|
|
132
100
|
if (!state.workersNewest) {
|
|
133
|
-
|
|
101
|
+
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
134
102
|
}
|
|
135
103
|
return applyDuration(state.workersNewest, timeValue.value, 'add');
|
|
136
104
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AirSyncEvent } from '../types/extraction';
|
|
2
|
+
export type DeepPartial<T> = {
|
|
3
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Creates a mock AirSyncEvent for testing. `callback_url`, `worker_data_url`,
|
|
7
|
+
* and `devrev_endpoint` derive from `mockServerUrl` unless explicitly overridden.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMockEvent(mockServerUrl?: string, overrides?: DeepPartial<AirSyncEvent>): AirSyncEvent;
|
|
10
|
+
//# sourceMappingURL=mock-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-event.d.ts","sourceRoot":"","sources":["../../src/testing/mock-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,MAAM,qBAAqB,CAAC;AAI9D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AAiCF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,aAAa,GAAE,MAAgC,EAC/C,SAAS,GAAE,WAAW,CAAC,YAAY,CAAM,GACxC,YAAY,CA+Ed"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MOCK_SERVER_DEFAULT_URL = void 0;
|
|
4
3
|
exports.createMockEvent = createMockEvent;
|
|
5
4
|
const extraction_1 = require("../types/extraction");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Deep merges source into target. Arrays and primitives from source replace
|
|
9
|
-
* those in target; plain objects are merged recursively.
|
|
10
|
-
*/
|
|
5
|
+
const mock_server_1 = require("./mock-server");
|
|
6
|
+
/** Arrays and primitives from source replace target's; plain objects merge recursively. */
|
|
11
7
|
function deepMerge(target, source) {
|
|
12
8
|
const result = Object.assign({}, target);
|
|
13
9
|
for (const key of Object.keys(source)) {
|
|
@@ -28,15 +24,10 @@ function deepMerge(target, source) {
|
|
|
28
24
|
return result;
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
|
-
* Creates a mock AirSyncEvent for testing.
|
|
32
|
-
*
|
|
33
|
-
* @param mockServerUrl - Base URL for the mock server. Defaults to {@link MOCK_SERVER_DEFAULT_URL}.
|
|
34
|
-
* The `callback_url`, `worker_data_url`, and `devrev_endpoint` fields are
|
|
35
|
-
* derived from this value unless explicitly overridden.
|
|
36
|
-
* @param overrides - Deep partial of AirSyncEvent. Any provided fields are
|
|
37
|
-
* deep-merged on top of the defaults.
|
|
27
|
+
* Creates a mock AirSyncEvent for testing. `callback_url`, `worker_data_url`,
|
|
28
|
+
* and `devrev_endpoint` derive from `mockServerUrl` unless explicitly overridden.
|
|
38
29
|
*/
|
|
39
|
-
function createMockEvent(mockServerUrl =
|
|
30
|
+
function createMockEvent(mockServerUrl = mock_server_1.MOCK_SERVER_DEFAULT_URL, overrides = {}) {
|
|
40
31
|
var _a, _b, _c, _d;
|
|
41
32
|
const base = {
|
|
42
33
|
context: {
|
|
@@ -45,6 +36,10 @@ function createMockEvent(mockServerUrl = exports.MOCK_SERVER_DEFAULT_URL, overri
|
|
|
45
36
|
},
|
|
46
37
|
snap_in_version_id: 'test_snap_in_version_id',
|
|
47
38
|
snap_in_id: 'test_snap_in_id',
|
|
39
|
+
user_id: 'test_user_id',
|
|
40
|
+
dev_oid: 'test_dev_oid',
|
|
41
|
+
source_id: 'test_source_id',
|
|
42
|
+
service_account_id: 'test_service_account_id',
|
|
48
43
|
},
|
|
49
44
|
payload: {
|
|
50
45
|
connection_data: {
|
|
@@ -55,12 +50,17 @@ function createMockEvent(mockServerUrl = exports.MOCK_SERVER_DEFAULT_URL, overri
|
|
|
55
50
|
},
|
|
56
51
|
event_context: {
|
|
57
52
|
callback_url: `${mockServerUrl}/callback_url`,
|
|
53
|
+
dev_org: 'test_dev_org',
|
|
58
54
|
dev_oid: 'test_dev_oid',
|
|
59
55
|
dev_org_id: 'test_dev_org_id',
|
|
56
|
+
dev_user: 'test_dev_user',
|
|
57
|
+
dev_user_id: 'test_dev_user_id',
|
|
60
58
|
dev_uid: 'test_dev_uid',
|
|
61
59
|
event_type_adaas: 'test_event_type_adaas',
|
|
60
|
+
external_sync_unit: 'test_external_sync_unit',
|
|
62
61
|
external_sync_unit_id: 'test_external_sync_unit_id',
|
|
63
62
|
external_sync_unit_name: 'test_external_sync_unit_name',
|
|
63
|
+
external_system: 'test_external_system',
|
|
64
64
|
external_system_id: 'test_external_system_id',
|
|
65
65
|
external_system_name: 'test_external_system_name',
|
|
66
66
|
external_system_type: 'test_external_system_type',
|
|
@@ -72,9 +72,12 @@ function createMockEvent(mockServerUrl = exports.MOCK_SERVER_DEFAULT_URL, overri
|
|
|
72
72
|
sequence_version: 'test_sequence_version',
|
|
73
73
|
snap_in_slug: 'test_snap_in_slug',
|
|
74
74
|
snap_in_version_id: 'test_snap_in_version_id',
|
|
75
|
+
sync_run: 'test_sync_run',
|
|
76
|
+
sync_run_id: 'test_sync_run_id',
|
|
75
77
|
sync_tier: 'test_sync_tier',
|
|
76
78
|
sync_unit: 'test_sync_unit',
|
|
77
79
|
sync_unit_id: 'test_sync_unit_id',
|
|
80
|
+
uuid: 'test_uuid',
|
|
78
81
|
worker_data_url: `${mockServerUrl}/worker_data_url`,
|
|
79
82
|
},
|
|
80
83
|
event_type: extraction_1.EventType.StartExtractingData,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RequestInfo, RouteConfig } from './mock-server.interfaces';
|
|
2
|
+
export declare const MOCK_SERVER_DEFAULT_URL = "http://localhost:0";
|
|
3
|
+
/**
|
|
4
|
+
* Mocks internal AirSync endpoints in tests, with per-test route
|
|
5
|
+
* configuration to simulate different response scenarios.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MockServer {
|
|
8
|
+
private server;
|
|
9
|
+
private internalPort;
|
|
10
|
+
port: number;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
private routeHandlers;
|
|
13
|
+
private requests;
|
|
14
|
+
private requestCounts;
|
|
15
|
+
constructor(port?: number);
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
stop(): Promise<void>;
|
|
18
|
+
private handleRequest;
|
|
19
|
+
/** Falls back to { success: true } for routes not explicitly set. */
|
|
20
|
+
private defaultRouteHandler;
|
|
21
|
+
private getRouteKey;
|
|
22
|
+
setRoute(config: RouteConfig): void;
|
|
23
|
+
/** Restores default handlers and clears request tracking data. */
|
|
24
|
+
resetRoutes(): void;
|
|
25
|
+
getLastRequest(): RequestInfo | undefined;
|
|
26
|
+
getRequestCount(method: string, path: string): number;
|
|
27
|
+
getRequests(method: string, path: string): RequestInfo[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=mock-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-server.d.ts","sourceRoot":"","sources":["../../src/testing/mock-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,WAAW,EACX,WAAW,EAEZ,MAAM,0BAA0B,CAAC;AAIlC,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAsE5D;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,YAAY,CAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,aAAa,CAA4B;gBAErC,IAAI,GAAE,MAAiC;IAMtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAkBpB,aAAa;IA+B3B,qEAAqE;IACrE,OAAO,CAAC,mBAAmB;IA6B3B,OAAO,CAAC,WAAW;IAIZ,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IA8E1C,kEAAkE;IAC3D,WAAW,IAAI,IAAI;IAMnB,cAAc,IAAI,WAAW,GAAG,SAAS;IAOzC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAIrD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE;CAQhE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
export declare const DEFAULT_MOCK_SERVER_PORT = 3001;
|
|
3
|
+
export interface ParsedRequest extends IncomingMessage {
|
|
4
|
+
/** URL path without query string */
|
|
5
|
+
path: string;
|
|
6
|
+
/** Parsed JSON body (if any) */
|
|
7
|
+
body?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface MockResponse extends ServerResponse {
|
|
10
|
+
set(headers: Record<string, string>): MockResponse;
|
|
11
|
+
status(code: number): MockResponse;
|
|
12
|
+
json(data: unknown): void;
|
|
13
|
+
buffer(data: Buffer): void;
|
|
14
|
+
send(): void;
|
|
15
|
+
}
|
|
16
|
+
/** Simulates failures before succeeding. */
|
|
17
|
+
export interface RetryConfig {
|
|
18
|
+
/** Failures before success (default: 4) */
|
|
19
|
+
failureCount?: number;
|
|
20
|
+
/** Status code during failures (default: 500) */
|
|
21
|
+
errorStatus?: number;
|
|
22
|
+
errorBody?: unknown;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
/** Delay in ms before each failure response */
|
|
25
|
+
delay?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface RouteConfig {
|
|
28
|
+
path: string;
|
|
29
|
+
method: string;
|
|
30
|
+
status: number;
|
|
31
|
+
body?: unknown;
|
|
32
|
+
/** Raw binary body, e.g. gzipped JSONL (takes precedence over `body`) */
|
|
33
|
+
bodyBuffer?: Buffer;
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
retry?: RetryConfig;
|
|
36
|
+
/** Delay in ms before sending the response */
|
|
37
|
+
delay?: number;
|
|
38
|
+
}
|
|
39
|
+
export type RouteHandler = (req: ParsedRequest, res: MockResponse) => unknown;
|
|
40
|
+
export interface RequestInfo {
|
|
41
|
+
method: string;
|
|
42
|
+
url: string;
|
|
43
|
+
body?: unknown;
|
|
44
|
+
}
|
|
45
|
+
export type RouteHandlers = Map<string, RouteHandler>;
|
|
46
|
+
/** Request counts per route. */
|
|
47
|
+
export type RequestCounts = Map<string, number>;
|
|
48
|
+
//# sourceMappingURL=mock-server.interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-server.interfaces.d.ts","sourceRoot":"","sources":["../../src/testing/mock-server.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEvD,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IACnD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,IAAI,IAAI,CAAC;CACd;AAED,4CAA4C;AAC5C,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC;AAE9E,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEtD,gCAAgC;AAChC,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockServer = void 0;
|
|
3
|
+
exports.MockServer = exports.MOCK_SERVER_DEFAULT_URL = void 0;
|
|
4
4
|
const http_1 = require("http");
|
|
5
5
|
const mock_server_interfaces_1 = require("./mock-server.interfaces");
|
|
6
|
+
// Port 0 lets the OS assign a free port at listen time; tests read the
|
|
7
|
+
// resolved URL from `mockServer.baseUrl`.
|
|
8
|
+
exports.MOCK_SERVER_DEFAULT_URL = 'http://localhost:0';
|
|
6
9
|
const MAX_BODY_SIZE = 10 * 1024 * 1024; // 10mb
|
|
7
|
-
/**
|
|
8
|
-
* Parses the JSON body from an incoming request.
|
|
9
|
-
*/
|
|
10
10
|
async function parseJsonBody(req) {
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
12
12
|
const chunks = [];
|
|
@@ -36,9 +36,6 @@ async function parseJsonBody(req) {
|
|
|
36
36
|
req.on('error', reject);
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Wraps a ServerResponse with helper methods (status, json, set, send).
|
|
41
|
-
*/
|
|
42
39
|
function wrapResponse(res) {
|
|
43
40
|
const mock = res;
|
|
44
41
|
let statusCode = 200;
|
|
@@ -56,6 +53,10 @@ function wrapResponse(res) {
|
|
|
56
53
|
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
57
54
|
res.end(JSON.stringify(data));
|
|
58
55
|
};
|
|
56
|
+
mock.buffer = (data) => {
|
|
57
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/octet-stream' });
|
|
58
|
+
res.end(data);
|
|
59
|
+
};
|
|
59
60
|
mock.send = () => {
|
|
60
61
|
res.writeHead(statusCode);
|
|
61
62
|
res.end();
|
|
@@ -63,9 +64,8 @@ function wrapResponse(res) {
|
|
|
63
64
|
return mock;
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Supports per-test route configuration to simulate different response scenarios.
|
|
67
|
+
* Mocks internal AirSync endpoints in tests, with per-test route
|
|
68
|
+
* configuration to simulate different response scenarios.
|
|
69
69
|
*/
|
|
70
70
|
class MockServer {
|
|
71
71
|
constructor(port = mock_server_interfaces_1.DEFAULT_MOCK_SERVER_PORT) {
|
|
@@ -134,10 +134,7 @@ class MockServer {
|
|
|
134
134
|
this.defaultRouteHandler(req, res);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Default route handler for the mock server. Returns { success: true } for
|
|
139
|
-
* routes that are not explicitly set.
|
|
140
|
-
*/
|
|
137
|
+
/** Falls back to { success: true } for routes not explicitly set. */
|
|
141
138
|
defaultRouteHandler(req, res) {
|
|
142
139
|
if (req.method === 'GET' && req.path === '/worker_data_url.get') {
|
|
143
140
|
res.status(200).json({
|
|
@@ -170,11 +167,8 @@ class MockServer {
|
|
|
170
167
|
getRouteKey(method, path) {
|
|
171
168
|
return `${method.toUpperCase()}:${path}`;
|
|
172
169
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Configures a route to return a specific status code and optional response body.
|
|
175
|
-
*/
|
|
176
170
|
setRoute(config) {
|
|
177
|
-
const { path, method, status, body, retry, headers, delay } = config;
|
|
171
|
+
const { path, method, status, body, bodyBuffer, retry, headers, delay } = config;
|
|
178
172
|
const key = this.getRouteKey(method, path);
|
|
179
173
|
if (retry) {
|
|
180
174
|
this.requestCounts.set(key, 0);
|
|
@@ -212,7 +206,10 @@ class MockServer {
|
|
|
212
206
|
if (headers) {
|
|
213
207
|
res.set(headers);
|
|
214
208
|
}
|
|
215
|
-
if (
|
|
209
|
+
if (bodyBuffer !== undefined) {
|
|
210
|
+
res.status(status).buffer(bodyBuffer);
|
|
211
|
+
}
|
|
212
|
+
else if (body !== undefined) {
|
|
216
213
|
res.status(status).json(body);
|
|
217
214
|
}
|
|
218
215
|
else {
|
|
@@ -224,7 +221,10 @@ class MockServer {
|
|
|
224
221
|
if (headers) {
|
|
225
222
|
res.set(headers);
|
|
226
223
|
}
|
|
227
|
-
if (
|
|
224
|
+
if (bodyBuffer !== undefined) {
|
|
225
|
+
res.status(status).buffer(bodyBuffer);
|
|
226
|
+
}
|
|
227
|
+
else if (body !== undefined) {
|
|
228
228
|
res.status(status).json(body);
|
|
229
229
|
}
|
|
230
230
|
else {
|
|
@@ -242,33 +242,21 @@ class MockServer {
|
|
|
242
242
|
sendResponse(delay);
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Resets all custom route handlers, restoring all default handlers.
|
|
247
|
-
* Also clears request tracking data.
|
|
248
|
-
*/
|
|
245
|
+
/** Restores default handlers and clears request tracking data. */
|
|
249
246
|
resetRoutes() {
|
|
250
247
|
this.routeHandlers.clear();
|
|
251
248
|
this.requestCounts.clear();
|
|
252
249
|
this.requests = [];
|
|
253
250
|
}
|
|
254
|
-
/**
|
|
255
|
-
* Returns the most recent request or undefined if no requests exist.
|
|
256
|
-
*/
|
|
257
251
|
getLastRequest() {
|
|
258
252
|
if (this.requests.length === 0) {
|
|
259
253
|
return undefined;
|
|
260
254
|
}
|
|
261
255
|
return this.requests[this.requests.length - 1];
|
|
262
256
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Gets the number of requests made to a specific endpoint.
|
|
265
|
-
*/
|
|
266
257
|
getRequestCount(method, path) {
|
|
267
258
|
return this.getRequests(method, path).length;
|
|
268
259
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Gets all requests made to a specific endpoint.
|
|
271
|
-
*/
|
|
272
260
|
getRequests(method, path) {
|
|
273
261
|
const pathWithoutQuery = path.split('?')[0];
|
|
274
262
|
return this.requests.filter((req) => req.method.toUpperCase() === method.toUpperCase() &&
|