@powersync/common 0.0.0-dev-20260503073249 → 0.0.0-dev-20260630141119
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 +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- 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/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.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/stream/JsonValue.d.ts +10 -0
- package/lib/client/sync/stream/JsonValue.js +2 -0
- package/lib/client/sync/stream/JsonValue.js.map +1 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- 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 +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +7 -27
- package/lib/index.js +6 -27
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- 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 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +8 -42
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +11 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +7 -27
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14781
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14689
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -12258
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -12166
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4391
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- 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 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -102
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/OpType.d.ts +0 -16
- package/lib/client/sync/bucket/OpType.js +0 -23
- package/lib/client/sync/bucket/OpType.js.map +0 -1
- package/lib/client/sync/bucket/OplogEntry.d.ts +0 -23
- package/lib/client/sync/bucket/OplogEntry.js +0 -36
- package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -61
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -324
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBatch.d.ts +0 -6
- package/lib/client/sync/bucket/SyncDataBatch.js +0 -12
- package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBucket.d.ts +0 -40
- package/lib/client/sync/bucket/SyncDataBucket.js +0 -40
- package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -161
- package/lib/client/sync/stream/AbstractRemote.js +0 -483
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -244
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -990
- 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 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -72
- package/lib/client/sync/stream/core-instruction.js +0 -27
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/sync/stream/streaming-sync-types.d.ts +0 -143
- package/lib/client/sync/stream/streaming-sync-types.js +0 -26
- package/lib/client/sync/stream/streaming-sync-types.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 -405
- 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 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- 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 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -118
- package/src/client/sync/bucket/OpType.ts +0 -23
- package/src/client/sync/bucket/OplogEntry.ts +0 -50
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -395
- package/src/client/sync/bucket/SyncDataBatch.ts +0 -11
- package/src/client/sync/bucket/SyncDataBucket.ts +0 -49
- package/src/client/sync/stream/AbstractRemote.ts +0 -624
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -1285
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -99
- package/src/client/sync/stream/streaming-sync-types.ts +0 -210
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
|
@@ -1,80 +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 = (ev: ErrorEvent) => {
|
|
46
|
-
removeListeners();
|
|
47
|
-
// We add a default error in that case.
|
|
48
|
-
if (ev.error != null) {
|
|
49
|
-
// undici typically provides an error object
|
|
50
|
-
reject(ev.error);
|
|
51
|
-
} else if (ev.message != null) {
|
|
52
|
-
// React Native typically does not provide an error object, but does provide a message
|
|
53
|
-
reject(new Error(`Failed to create websocket connection: ${ev.message}`));
|
|
54
|
-
} else {
|
|
55
|
-
// Browsers often provide no details at all
|
|
56
|
-
reject(new Error(`Failed to create websocket connection to ${this.url}`));
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* In some cases, such as React Native iOS, the WebSocket connection may close immediately after opening
|
|
62
|
-
* without and error. In such cases, we need to handle the close event to reject the promise.
|
|
63
|
-
*/
|
|
64
|
-
const closeListener = () => {
|
|
65
|
-
removeListeners();
|
|
66
|
-
reject(new Error('WebSocket connection closed while opening'));
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
removeListeners = () => {
|
|
70
|
-
websocket.removeEventListener('open', openListener);
|
|
71
|
-
websocket.removeEventListener('error', errorListener);
|
|
72
|
-
websocket.removeEventListener('close', closeListener);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
websocket.addEventListener('open', openListener);
|
|
76
|
-
websocket.addEventListener('error', errorListener);
|
|
77
|
-
websocket.addEventListener('close', closeListener);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { StreamingSyncRequest } from './streaming-sync-types.js';
|
|
2
|
-
import * as sync_status from '../../../db/crud/SyncStatus.js';
|
|
3
|
-
import { FULL_SYNC_PRIORITY } from '../../../db/crud/SyncProgress.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An internal instruction emitted by the sync client in the core extension in response to the JS
|
|
7
|
-
* SDK passing sync data into the extension.
|
|
8
|
-
*/
|
|
9
|
-
export type Instruction =
|
|
10
|
-
| { LogLine: LogLine }
|
|
11
|
-
| { UpdateSyncStatus: UpdateSyncStatus }
|
|
12
|
-
| { EstablishSyncStream: EstablishSyncStream }
|
|
13
|
-
| { FetchCredentials: FetchCredentials }
|
|
14
|
-
| { CloseSyncStream: { hide_disconnect: boolean } }
|
|
15
|
-
| { FlushFileSystem: any }
|
|
16
|
-
| { DidCompleteSync: any };
|
|
17
|
-
|
|
18
|
-
export interface LogLine {
|
|
19
|
-
severity: 'DEBUG' | 'INFO' | 'WARNING';
|
|
20
|
-
line: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface EstablishSyncStream {
|
|
24
|
-
request: StreamingSyncRequest;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface UpdateSyncStatus {
|
|
28
|
-
status: CoreSyncStatus;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface CoreSyncStatus {
|
|
32
|
-
connected: boolean;
|
|
33
|
-
connecting: boolean;
|
|
34
|
-
priority_status: SyncPriorityStatus[];
|
|
35
|
-
downloading: DownloadProgress | null;
|
|
36
|
-
streams: CoreStreamSubscription[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/// An `ActiveStreamSubscription` from the core extension + serialized progress information.
|
|
40
|
-
export interface CoreStreamSubscription {
|
|
41
|
-
progress: { total: number; downloaded: number };
|
|
42
|
-
name: string;
|
|
43
|
-
parameters: any;
|
|
44
|
-
priority: number | null;
|
|
45
|
-
active: boolean;
|
|
46
|
-
is_default: boolean;
|
|
47
|
-
has_explicit_subscription: boolean;
|
|
48
|
-
expires_at: number | null;
|
|
49
|
-
last_synced_at: number | null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface SyncPriorityStatus {
|
|
53
|
-
priority: number;
|
|
54
|
-
last_synced_at: number | number;
|
|
55
|
-
has_synced: boolean | null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface DownloadProgress {
|
|
59
|
-
buckets: Record<string, BucketProgress>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface BucketProgress {
|
|
63
|
-
priority: number;
|
|
64
|
-
at_last: number;
|
|
65
|
-
since_last: number;
|
|
66
|
-
target_count: number;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface FetchCredentials {
|
|
70
|
-
did_expire: boolean;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function priorityToJs(status: SyncPriorityStatus): sync_status.SyncPriorityStatus {
|
|
74
|
-
return {
|
|
75
|
-
priority: status.priority,
|
|
76
|
-
hasSynced: status.has_synced ?? undefined,
|
|
77
|
-
lastSyncedAt: status.last_synced_at != null ? new Date(status.last_synced_at * 1000) : undefined
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function coreStatusToJs(status: CoreSyncStatus): sync_status.SyncStatusOptions {
|
|
82
|
-
const coreCompleteSync = status.priority_status.find((s) => s.priority == FULL_SYNC_PRIORITY);
|
|
83
|
-
const completeSync = coreCompleteSync != null ? priorityToJs(coreCompleteSync) : null;
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
connected: status.connected,
|
|
87
|
-
connecting: status.connecting,
|
|
88
|
-
dataFlow: {
|
|
89
|
-
// We expose downloading as a boolean field, the core extension reports download information as a nullable
|
|
90
|
-
// download status. When that status is non-null, a download is in progress.
|
|
91
|
-
downloading: status.downloading != null,
|
|
92
|
-
downloadProgress: status.downloading?.buckets,
|
|
93
|
-
internalStreamSubscriptions: status.streams
|
|
94
|
-
},
|
|
95
|
-
lastSyncedAt: completeSync?.lastSyncedAt,
|
|
96
|
-
hasSynced: completeSync?.hasSynced,
|
|
97
|
-
priorityStatusEntries: status.priority_status.map(priorityToJs)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { BucketChecksum, Checkpoint } from '../bucket/BucketStorageAdapter.js';
|
|
2
|
-
import { CrudEntry, OpId } from '../bucket/CrudEntry.js';
|
|
3
|
-
import { SyncDataBucketJSON } from '../bucket/SyncDataBucket.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* For sync2.json
|
|
7
|
-
*/
|
|
8
|
-
export interface ContinueCheckpointRequest {
|
|
9
|
-
/**
|
|
10
|
-
* Existing bucket states. Only these buckets are synchronized.
|
|
11
|
-
*/
|
|
12
|
-
buckets: BucketRequest[];
|
|
13
|
-
|
|
14
|
-
checkpoint_token: string;
|
|
15
|
-
|
|
16
|
-
limit?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface SyncNewCheckpointRequest {
|
|
20
|
-
/**
|
|
21
|
-
* Existing bucket states. Used if include_data is specified.
|
|
22
|
-
*/
|
|
23
|
-
buckets?: BucketRequest[];
|
|
24
|
-
|
|
25
|
-
request_checkpoint: {
|
|
26
|
-
/**
|
|
27
|
-
* Whether or not to include an initial data request.
|
|
28
|
-
*/
|
|
29
|
-
include_data: boolean;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Whether or not to compute a checksum.
|
|
33
|
-
*/
|
|
34
|
-
include_checksum: boolean;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
limit?: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type SyncRequest = ContinueCheckpointRequest | SyncNewCheckpointRequest;
|
|
41
|
-
|
|
42
|
-
export interface SyncResponse {
|
|
43
|
-
/**
|
|
44
|
-
* Data for the buckets returned. May not have an an entry for each bucket in the request.
|
|
45
|
-
*/
|
|
46
|
-
data?: SyncDataBucketJSON[];
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* True if the response limit has been reached, and another request must be made.
|
|
50
|
-
*/
|
|
51
|
-
has_more: boolean;
|
|
52
|
-
|
|
53
|
-
checkpoint_token?: string;
|
|
54
|
-
|
|
55
|
-
checkpoint?: Checkpoint;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
|
|
59
|
-
|
|
60
|
-
interface JSONObject {
|
|
61
|
-
[key: string]: JSONValue;
|
|
62
|
-
}
|
|
63
|
-
type JSONArray = JSONValue[];
|
|
64
|
-
|
|
65
|
-
export type StreamingSyncRequestParameterType = JSONValue;
|
|
66
|
-
|
|
67
|
-
export interface StreamingSyncRequest {
|
|
68
|
-
/**
|
|
69
|
-
* Existing bucket states.
|
|
70
|
-
*/
|
|
71
|
-
buckets?: BucketRequest[];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* If specified, limit the response to only include these buckets.
|
|
75
|
-
*/
|
|
76
|
-
only?: string[];
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Whether or not to compute a checksum for each checkpoint
|
|
80
|
-
*/
|
|
81
|
-
include_checksum: boolean;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Changes the response to stringified data in each OplogEntry
|
|
85
|
-
*/
|
|
86
|
-
raw_data: boolean;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Client parameters to be passed to the sync rules.
|
|
90
|
-
*/
|
|
91
|
-
parameters?: Record<string, StreamingSyncRequestParameterType>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Application metadata to be included in service logs.
|
|
95
|
-
*/
|
|
96
|
-
app_metadata?: Record<string, string>;
|
|
97
|
-
|
|
98
|
-
client_id?: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface StreamingSyncCheckpoint {
|
|
102
|
-
checkpoint: Checkpoint;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface StreamingSyncCheckpointDiff {
|
|
106
|
-
checkpoint_diff: {
|
|
107
|
-
last_op_id: OpId;
|
|
108
|
-
updated_buckets: BucketChecksum[];
|
|
109
|
-
removed_buckets: string[];
|
|
110
|
-
write_checkpoint?: string;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface StreamingSyncDataJSON {
|
|
115
|
-
data: SyncDataBucketJSON;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface StreamingSyncCheckpointComplete {
|
|
119
|
-
checkpoint_complete: {
|
|
120
|
-
last_op_id: OpId;
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface StreamingSyncCheckpointPartiallyComplete {
|
|
125
|
-
partial_checkpoint_complete: {
|
|
126
|
-
priority: number;
|
|
127
|
-
last_op_id: OpId;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface StreamingSyncKeepalive {
|
|
132
|
-
/** If specified, token expires in this many seconds. */
|
|
133
|
-
token_expires_in: number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export type StreamingSyncLine =
|
|
137
|
-
| StreamingSyncDataJSON
|
|
138
|
-
| StreamingSyncCheckpoint
|
|
139
|
-
| StreamingSyncCheckpointDiff
|
|
140
|
-
| StreamingSyncCheckpointComplete
|
|
141
|
-
| StreamingSyncCheckpointPartiallyComplete
|
|
142
|
-
| StreamingSyncKeepalive;
|
|
143
|
-
|
|
144
|
-
export type CrudUploadNotification = { crud_upload_completed: null };
|
|
145
|
-
|
|
146
|
-
export type StreamingSyncLineOrCrudUploadComplete = StreamingSyncLine | CrudUploadNotification;
|
|
147
|
-
|
|
148
|
-
export interface BucketRequest {
|
|
149
|
-
name: string;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Base-10 number. Sync all data from this bucket with op_id > after.
|
|
153
|
-
*/
|
|
154
|
-
after: OpId;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function isStreamingSyncData(line: StreamingSyncLine): line is StreamingSyncDataJSON {
|
|
158
|
-
return (line as StreamingSyncDataJSON).data != null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function isStreamingKeepalive(line: StreamingSyncLine): line is StreamingSyncKeepalive {
|
|
162
|
-
return (line as StreamingSyncKeepalive).token_expires_in != null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function isStreamingSyncCheckpoint(line: StreamingSyncLine): line is StreamingSyncCheckpoint {
|
|
166
|
-
return (line as StreamingSyncCheckpoint).checkpoint != null;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function isStreamingSyncCheckpointComplete(line: StreamingSyncLine): line is StreamingSyncCheckpointComplete {
|
|
170
|
-
return (line as StreamingSyncCheckpointComplete).checkpoint_complete != null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function isStreamingSyncCheckpointPartiallyComplete(
|
|
174
|
-
line: StreamingSyncLine
|
|
175
|
-
): line is StreamingSyncCheckpointPartiallyComplete {
|
|
176
|
-
return (line as StreamingSyncCheckpointPartiallyComplete).partial_checkpoint_complete != null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function isStreamingSyncCheckpointDiff(line: StreamingSyncLine): line is StreamingSyncCheckpointDiff {
|
|
180
|
-
return (line as StreamingSyncCheckpointDiff).checkpoint_diff != null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function isContinueCheckpointRequest(request: SyncRequest): request is ContinueCheckpointRequest {
|
|
184
|
-
return (
|
|
185
|
-
Array.isArray((request as ContinueCheckpointRequest).buckets) &&
|
|
186
|
-
typeof (request as ContinueCheckpointRequest).checkpoint_token == 'string'
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function isSyncNewCheckpointRequest(request: SyncRequest): request is SyncNewCheckpointRequest {
|
|
191
|
-
return typeof (request as SyncNewCheckpointRequest).request_checkpoint == 'object';
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* For crud.json
|
|
196
|
-
*/
|
|
197
|
-
export interface CrudRequest {
|
|
198
|
-
data: CrudEntry[];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export interface CrudResponse {
|
|
202
|
-
/**
|
|
203
|
-
* A sync response with a checkpoint >= this checkpoint would contain all the changes in this request.
|
|
204
|
-
*
|
|
205
|
-
* Any earlier checkpoint may or may not contain these changes.
|
|
206
|
-
*
|
|
207
|
-
* May be empty when the request contains no ops.
|
|
208
|
-
*/
|
|
209
|
-
checkpoint?: OpId;
|
|
210
|
-
}
|
|
@@ -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
|
-
};
|