@powersync/common 1.57.1 → 2.0.0
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/lib/attachments/AttachmentContext.d.ts +5 -5
- package/lib/attachments/AttachmentContext.js +6 -2
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentQueue.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.js +9 -8
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.js.map +1 -1
- package/lib/attachments/Schema.d.ts +2 -2
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +21 -6
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/SQLOpenFactory.d.ts +35 -13
- package/lib/client/SQLOpenFactory.js +1 -25
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +2 -2
- package/lib/client/compilableQueryWatch.js +1 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
- package/lib/client/runOnSchemaChange.d.ts +2 -2
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
- package/lib/client/sync/bucket/CrudEntry.js +0 -99
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/sync-streams.d.ts +1 -1
- package/lib/client/triggers/TriggerManager.d.ts +9 -38
- package/lib/client/watched/GetAllQuery.d.ts +3 -3
- package/lib/client/watched/GetAllQuery.js +1 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +2 -10
- package/lib/client/watched/WatchedQuery.js +0 -11
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +72 -154
- package/lib/db/DBAdapter.js +70 -108
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +1 -13
- package/lib/db/crud/SyncProgress.js +1 -62
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +32 -66
- package/lib/db/crud/SyncStatus.js +1 -253
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +0 -7
- package/lib/db/schema/Column.js +0 -7
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +2 -6
- package/lib/db/schema/Index.js +1 -4
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +2 -6
- package/lib/db/schema/IndexedColumn.js +1 -4
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/Schema.d.ts +4 -28
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +50 -96
- package/lib/db/schema/Table.js +83 -91
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +5 -21
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/utils/BaseObserver.d.ts +1 -1
- package/lib/utils/BaseObserver.js +1 -1
- package/lib/utils/Logger.d.ts +52 -23
- package/lib/utils/Logger.js +35 -33
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -53
- package/lib/utils/mutex.js +1 -156
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +8 -45
- package/src/attachments/AttachmentContext.ts +11 -10
- package/src/attachments/AttachmentQueue.ts +15 -14
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/Schema.ts +2 -2
- package/src/attachments/SyncingService.ts +23 -9
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/SQLOpenFactory.ts +38 -22
- package/src/client/compilableQueryWatch.ts +3 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
- package/src/client/runOnSchemaChange.ts +2 -2
- package/src/client/sync/bucket/CrudEntry.ts +4 -104
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/sync-streams.ts +1 -1
- package/src/client/triggers/TriggerManager.ts +10 -41
- package/src/client/watched/GetAllQuery.ts +3 -3
- package/src/client/watched/WatchedQuery.ts +2 -15
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
- package/src/db/DBAdapter.ts +141 -226
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +2 -42
- package/src/db/crud/SyncStatus.ts +45 -220
- package/src/db/schema/Column.ts +0 -8
- package/src/db/schema/Index.ts +3 -6
- package/src/db/schema/IndexedColumn.ts +3 -6
- package/src/db/schema/Schema.ts +4 -4
- package/src/db/schema/Table.ts +111 -186
- package/src/index.ts +5 -21
- package/src/utils/BaseObserver.ts +1 -1
- package/src/utils/Logger.ts +80 -34
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -201
- package/dist/bundle.cjs +0 -14390
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14309
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -12021
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11940
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4651
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -990
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -115
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -4
- package/lib/client/constants.js +0 -5
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
- package/lib/client/sync/stream/AbstractRemote.js +0 -505
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -705
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -77
- package/lib/client/sync/stream/core-instruction.js +0 -30
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -410
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -12
- package/lib/db/ConnectionClosedError.js +0 -23
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -11
- package/lib/db/schema/TableV2.js +0 -11
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -11
- package/lib/utils/AbortOperation.js +0 -21
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -31
- package/lib/utils/ControlledExecutor.js +0 -54
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -46
- package/lib/utils/async.js +0 -147
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/compatibility.d.ts +0 -8
- package/lib/utils/compatibility.js +0 -9
- package/lib/utils/compatibility.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -12
- package/lib/utils/parseQuery.js +0 -20
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -41
- package/lib/utils/stream_transform.js +0 -211
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
- package/src/client/ConnectionManager.ts +0 -405
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -4
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
- package/src/client/sync/stream/AbstractRemote.ts +0 -644
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
- package/src/client/sync/stream/core-instruction.ts +0 -109
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -501
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -25
- package/src/db/schema/TableV2.ts +0 -11
- package/src/utils/AbortOperation.ts +0 -19
- package/src/utils/ControlledExecutor.ts +0 -78
- package/src/utils/async.ts +0 -185
- package/src/utils/compatibility.ts +0 -9
- package/src/utils/parseQuery.ts +0 -31
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -260
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapted from rsocket-websocket-client
|
|
3
|
-
* https://github.com/rsocket/rsocket-js/blob/e224cf379e747c4f1ddc4f2fa111854626cc8575/packages/rsocket-websocket-client/src/WebsocketClientTransport.ts#L17
|
|
4
|
-
* This adds additional error handling for React Native iOS.
|
|
5
|
-
* This particularly adds a close listener to handle cases where the WebSocket
|
|
6
|
-
* connection closes immediately after opening without emitting an error.
|
|
7
|
-
*/
|
|
8
|
-
import {
|
|
9
|
-
ClientTransport,
|
|
10
|
-
Closeable,
|
|
11
|
-
Demultiplexer,
|
|
12
|
-
Deserializer,
|
|
13
|
-
DuplexConnection,
|
|
14
|
-
FrameHandler,
|
|
15
|
-
Multiplexer,
|
|
16
|
-
Outbound
|
|
17
|
-
} from 'rsocket-core';
|
|
18
|
-
import { ClientOptions } from 'rsocket-websocket-client';
|
|
19
|
-
import { WebsocketDuplexConnection } from 'rsocket-websocket-client/dist/WebsocketDuplexConnection.js';
|
|
20
|
-
|
|
21
|
-
export class WebsocketClientTransport implements ClientTransport {
|
|
22
|
-
private readonly url: string;
|
|
23
|
-
private readonly factory: (url: string) => WebSocket;
|
|
24
|
-
|
|
25
|
-
constructor(options: ClientOptions) {
|
|
26
|
-
this.url = options.url;
|
|
27
|
-
this.factory = options.wsCreator ?? ((url: string) => new WebSocket(url));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
connect(
|
|
31
|
-
multiplexerDemultiplexerFactory: (outbound: Outbound & Closeable) => Multiplexer & Demultiplexer & FrameHandler
|
|
32
|
-
): Promise<DuplexConnection> {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const websocket = this.factory(this.url);
|
|
35
|
-
|
|
36
|
-
websocket.binaryType = 'arraybuffer';
|
|
37
|
-
|
|
38
|
-
let removeListeners: () => void;
|
|
39
|
-
|
|
40
|
-
const openListener = () => {
|
|
41
|
-
removeListeners();
|
|
42
|
-
resolve(new WebsocketDuplexConnection(websocket, new Deserializer(), multiplexerDemultiplexerFactory));
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const errorListener = (event: Event) => {
|
|
46
|
-
const ev = event as ErrorEvent;
|
|
47
|
-
|
|
48
|
-
removeListeners();
|
|
49
|
-
// We add a default error in that case.
|
|
50
|
-
if (ev.error != null) {
|
|
51
|
-
// undici typically provides an error object
|
|
52
|
-
reject(ev.error);
|
|
53
|
-
} else if (ev.message != null) {
|
|
54
|
-
// React Native typically does not provide an error object, but does provide a message
|
|
55
|
-
reject(new Error(`Failed to create websocket connection: ${ev.message}`));
|
|
56
|
-
} else {
|
|
57
|
-
// Browsers often provide no details at all
|
|
58
|
-
reject(new Error(`Failed to create websocket connection to ${this.url}`));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* In some cases, such as React Native iOS, the WebSocket connection may close immediately after opening
|
|
64
|
-
* without and error. In such cases, we need to handle the close event to reject the promise.
|
|
65
|
-
*/
|
|
66
|
-
const closeListener = () => {
|
|
67
|
-
removeListeners();
|
|
68
|
-
reject(new Error('WebSocket connection closed while opening'));
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
removeListeners = () => {
|
|
72
|
-
websocket.removeEventListener('open', openListener);
|
|
73
|
-
websocket.removeEventListener('error', errorListener);
|
|
74
|
-
websocket.removeEventListener('close', closeListener);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
websocket.addEventListener('open', openListener);
|
|
78
|
-
websocket.addEventListener('error', errorListener);
|
|
79
|
-
websocket.addEventListener('close', closeListener);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as sync_status from '../../../db/crud/SyncStatus.js';
|
|
2
|
-
import { FULL_SYNC_PRIORITY } from '../../../db/crud/SyncProgress.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An internal instruction emitted by the sync client in the core extension in response to the JS
|
|
6
|
-
* SDK passing sync data into the extension.
|
|
7
|
-
*/
|
|
8
|
-
export type Instruction = InterruptingInstruction | NonInterruptingInstruction;
|
|
9
|
-
|
|
10
|
-
export type InterruptingInstruction =
|
|
11
|
-
| { EstablishSyncStream: EstablishSyncStream }
|
|
12
|
-
| { CloseSyncStream: { hide_disconnect: boolean } };
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* An {@link Instruction} that doesn't start or stop a sync iteration.
|
|
16
|
-
*/
|
|
17
|
-
export type NonInterruptingInstruction =
|
|
18
|
-
| { LogLine: LogLine }
|
|
19
|
-
| { UpdateSyncStatus: UpdateSyncStatus }
|
|
20
|
-
| { FetchCredentials: FetchCredentials }
|
|
21
|
-
| { FlushFileSystem: any }
|
|
22
|
-
| { DidCompleteSync: any };
|
|
23
|
-
|
|
24
|
-
export interface LogLine {
|
|
25
|
-
severity: 'DEBUG' | 'INFO' | 'WARNING';
|
|
26
|
-
line: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface EstablishSyncStream {
|
|
30
|
-
request: unknown;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface UpdateSyncStatus {
|
|
34
|
-
status: CoreSyncStatus;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface CoreSyncStatus {
|
|
38
|
-
connected: boolean;
|
|
39
|
-
connecting: boolean;
|
|
40
|
-
priority_status: SyncPriorityStatus[];
|
|
41
|
-
downloading: DownloadProgress | null;
|
|
42
|
-
streams: CoreStreamSubscription[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/// An `ActiveStreamSubscription` from the core extension + serialized progress information.
|
|
46
|
-
export interface CoreStreamSubscription {
|
|
47
|
-
progress: { total: number; downloaded: number };
|
|
48
|
-
name: string;
|
|
49
|
-
parameters: any;
|
|
50
|
-
priority: number | null;
|
|
51
|
-
active: boolean;
|
|
52
|
-
is_default: boolean;
|
|
53
|
-
has_explicit_subscription: boolean;
|
|
54
|
-
expires_at: number | null;
|
|
55
|
-
last_synced_at: number | null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface SyncPriorityStatus {
|
|
59
|
-
priority: number;
|
|
60
|
-
last_synced_at: number | number;
|
|
61
|
-
has_synced: boolean | null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface DownloadProgress {
|
|
65
|
-
buckets: Record<string, BucketProgress>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface BucketProgress {
|
|
69
|
-
priority: number;
|
|
70
|
-
at_last: number;
|
|
71
|
-
since_last: number;
|
|
72
|
-
target_count: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface FetchCredentials {
|
|
76
|
-
did_expire: boolean;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function priorityToJs(status: SyncPriorityStatus): sync_status.SyncPriorityStatus {
|
|
80
|
-
return {
|
|
81
|
-
priority: status.priority,
|
|
82
|
-
hasSynced: status.has_synced ?? undefined,
|
|
83
|
-
lastSyncedAt: status.last_synced_at != null ? new Date(status.last_synced_at * 1000) : undefined
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function coreStatusToJs(status: CoreSyncStatus): sync_status.SyncStatusOptions {
|
|
88
|
-
const coreCompleteSync = status.priority_status.find((s) => s.priority == FULL_SYNC_PRIORITY);
|
|
89
|
-
const completeSync = coreCompleteSync != null ? priorityToJs(coreCompleteSync) : null;
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
connected: status.connected,
|
|
93
|
-
connecting: status.connecting,
|
|
94
|
-
dataFlow: {
|
|
95
|
-
// We expose downloading as a boolean field, the core extension reports download information as a nullable
|
|
96
|
-
// download status. When that status is non-null, a download is in progress.
|
|
97
|
-
downloading: status.downloading != null,
|
|
98
|
-
downloadProgress: status.downloading?.buckets,
|
|
99
|
-
internalStreamSubscriptions: status.streams
|
|
100
|
-
},
|
|
101
|
-
lastSyncedAt: completeSync?.lastSyncedAt,
|
|
102
|
-
hasSynced: completeSync?.hasSynced,
|
|
103
|
-
priorityStatusEntries: status.priority_status.map(priorityToJs)
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function isInterruptingInstruction(instruction: Instruction): instruction is InterruptingInstruction {
|
|
108
|
-
return 'EstablishSyncStream' in instruction || 'CloseSyncStream' in instruction;
|
|
109
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { TriggerClaimManager } from './TriggerManager.js';
|
|
2
|
-
|
|
3
|
-
const CLAIM_STORE = new Map<string, () => Promise<void>>();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
* @experimental
|
|
8
|
-
*/
|
|
9
|
-
export const MEMORY_TRIGGER_CLAIM_MANAGER: TriggerClaimManager = {
|
|
10
|
-
async obtainClaim(identifier: string): Promise<() => Promise<void>> {
|
|
11
|
-
if (CLAIM_STORE.has(identifier)) {
|
|
12
|
-
throw new Error(`A claim is already present for ${identifier}`);
|
|
13
|
-
}
|
|
14
|
-
const release = async () => {
|
|
15
|
-
CLAIM_STORE.delete(identifier);
|
|
16
|
-
};
|
|
17
|
-
CLAIM_STORE.set(identifier, release);
|
|
18
|
-
|
|
19
|
-
return release;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
async checkClaim(identifier: string): Promise<boolean> {
|
|
23
|
-
return CLAIM_STORE.has(identifier);
|
|
24
|
-
}
|
|
25
|
-
};
|