@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,14 +1,20 @@
|
|
|
1
1
|
import { CompilableQuery } from './../types/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonPowerSyncDatabase, SQLWatchOptions } from './CommonPowerSyncDatabase.js';
|
|
3
3
|
import { runOnSchemaChange } from './runOnSchemaChange.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
5
8
|
export interface CompilableQueryWatchHandler<T> {
|
|
6
9
|
onResult: (results: T[]) => void;
|
|
7
10
|
onError?: (error: Error) => void;
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
10
16
|
export function compilableQueryWatch<T>(
|
|
11
|
-
db:
|
|
17
|
+
db: CommonPowerSyncDatabase,
|
|
12
18
|
query: CompilableQuery<T>,
|
|
13
19
|
handler: CompilableQueryWatchHandler<T>,
|
|
14
20
|
options?: SQLWatchOptions
|
|
@@ -36,8 +42,7 @@ export function compilableQueryWatch<T>(
|
|
|
36
42
|
} catch (error: any) {
|
|
37
43
|
onError(error);
|
|
38
44
|
}
|
|
39
|
-
}
|
|
40
|
-
onError
|
|
45
|
+
}
|
|
41
46
|
},
|
|
42
47
|
{
|
|
43
48
|
...(options ?? {}),
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { PowerSyncCredentials } from './PowerSyncCredentials.js';
|
|
2
|
-
import
|
|
2
|
+
import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export interface PowerSyncBackendConnector {
|
|
5
8
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
6
9
|
* which is used to authenticate against the PowerSync service.
|
|
@@ -17,9 +20,9 @@ export interface PowerSyncBackendConnector {
|
|
|
17
20
|
|
|
18
21
|
/** Upload local changes to the app backend.
|
|
19
22
|
*
|
|
20
|
-
* Use {@link
|
|
23
|
+
* Use {@link CommonPowerSyncDatabase.getCrudBatch} to get a batch of changes to upload.
|
|
21
24
|
*
|
|
22
25
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
23
26
|
*/
|
|
24
|
-
uploadData: (database:
|
|
27
|
+
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
25
28
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonPowerSyncDatabase, SQLWatchOptions } from './CommonPowerSyncDatabase.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
3
6
|
export function runOnSchemaChange(
|
|
4
7
|
callback: (signal: AbortSignal) => void,
|
|
5
|
-
db:
|
|
8
|
+
db: CommonPowerSyncDatabase,
|
|
6
9
|
options?: SQLWatchOptions
|
|
7
10
|
): void {
|
|
8
11
|
const triggerWatchedQuery = () => {
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* 64-bit unsigned integer stored as a string in base-10.
|
|
3
3
|
*
|
|
4
4
|
* Not sortable as a string.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
5
7
|
*/
|
|
6
8
|
export type OpId = string;
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Type of local change.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
10
14
|
*/
|
|
11
15
|
export enum UpdateType {
|
|
12
16
|
/** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
|
|
@@ -17,39 +21,12 @@ export enum UpdateType {
|
|
|
17
21
|
DELETE = 'DELETE'
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
export type CrudEntryJSON = {
|
|
21
|
-
id: string;
|
|
22
|
-
data: string;
|
|
23
|
-
tx_id?: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type CrudEntryDataJSON = {
|
|
27
|
-
data: Record<string, any>;
|
|
28
|
-
old?: Record<string, any>;
|
|
29
|
-
op: UpdateType;
|
|
30
|
-
type: string;
|
|
31
|
-
id: string;
|
|
32
|
-
metadata?: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The output JSON seems to be a third type of JSON, not the same as the input JSON.
|
|
37
|
-
*/
|
|
38
|
-
type CrudEntryOutputJSON = {
|
|
39
|
-
op_id: number;
|
|
40
|
-
op: UpdateType;
|
|
41
|
-
type: string;
|
|
42
|
-
id: string;
|
|
43
|
-
tx_id?: number;
|
|
44
|
-
data?: Record<string, any>;
|
|
45
|
-
old?: Record<string, any>;
|
|
46
|
-
metadata?: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
24
|
/**
|
|
50
25
|
* A single client-side change.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
51
28
|
*/
|
|
52
|
-
export
|
|
29
|
+
export interface CrudEntry {
|
|
53
30
|
/**
|
|
54
31
|
* Auto-incrementing client-side id.
|
|
55
32
|
*/
|
|
@@ -90,83 +67,15 @@ export class CrudEntry {
|
|
|
90
67
|
*/
|
|
91
68
|
metadata?: string;
|
|
92
69
|
|
|
93
|
-
static fromRow(dbRow: CrudEntryJSON) {
|
|
94
|
-
const data: CrudEntryDataJSON = JSON.parse(dbRow.data);
|
|
95
|
-
return new CrudEntry(
|
|
96
|
-
parseInt(dbRow.id),
|
|
97
|
-
data.op,
|
|
98
|
-
data.type,
|
|
99
|
-
data.id,
|
|
100
|
-
dbRow.tx_id,
|
|
101
|
-
data.data,
|
|
102
|
-
data.old,
|
|
103
|
-
data.metadata
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
constructor(
|
|
108
|
-
clientId: number,
|
|
109
|
-
op: UpdateType,
|
|
110
|
-
table: string,
|
|
111
|
-
id: string,
|
|
112
|
-
transactionId?: number,
|
|
113
|
-
opData?: Record<string, any>,
|
|
114
|
-
previousValues?: Record<string, any>,
|
|
115
|
-
metadata?: string
|
|
116
|
-
) {
|
|
117
|
-
this.clientId = clientId;
|
|
118
|
-
this.id = id;
|
|
119
|
-
this.op = op;
|
|
120
|
-
this.opData = opData;
|
|
121
|
-
this.table = table;
|
|
122
|
-
this.transactionId = transactionId;
|
|
123
|
-
this.previousValues = previousValues;
|
|
124
|
-
this.metadata = metadata;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
70
|
/**
|
|
128
71
|
* Converts the change to JSON format.
|
|
129
72
|
*/
|
|
130
|
-
toJSON():
|
|
131
|
-
return {
|
|
132
|
-
op_id: this.clientId,
|
|
133
|
-
op: this.op,
|
|
134
|
-
type: this.table,
|
|
135
|
-
id: this.id,
|
|
136
|
-
tx_id: this.transactionId,
|
|
137
|
-
data: this.opData,
|
|
138
|
-
old: this.previousValues,
|
|
139
|
-
metadata: this.metadata
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
equals(entry: CrudEntry) {
|
|
144
|
-
return JSON.stringify(this.toComparisonArray()) == JSON.stringify(entry.toComparisonArray());
|
|
145
|
-
}
|
|
73
|
+
toJSON(): unknown;
|
|
146
74
|
|
|
147
|
-
|
|
148
|
-
* The hash code for this object.
|
|
149
|
-
* @deprecated This should not be necessary in the JS SDK.
|
|
150
|
-
* Use the @see CrudEntry#equals method instead.
|
|
151
|
-
* TODO remove in the next major release.
|
|
152
|
-
*/
|
|
153
|
-
hashCode() {
|
|
154
|
-
return JSON.stringify(this.toComparisonArray());
|
|
155
|
-
}
|
|
75
|
+
equals(entry: CrudEntry): boolean;
|
|
156
76
|
|
|
157
77
|
/**
|
|
158
78
|
* Generates an array for use in deep comparison operations
|
|
159
79
|
*/
|
|
160
|
-
toComparisonArray()
|
|
161
|
-
return [
|
|
162
|
-
this.transactionId,
|
|
163
|
-
this.clientId,
|
|
164
|
-
this.op,
|
|
165
|
-
this.table,
|
|
166
|
-
this.id,
|
|
167
|
-
this.opData,
|
|
168
|
-
this.previousValues,
|
|
169
|
-
this.metadata
|
|
170
|
-
];
|
|
171
|
-
}
|
|
80
|
+
toComparisonArray(): unknown[];
|
|
172
81
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { StreamingSyncRequestParameterType } from './stream/JsonValue.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options that affect how the PowerSync SDK connects to the PowerSync Service.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface SyncOptions {
|
|
9
|
+
// Note: When adding new fields to this interface, consider that these objects need to be serializable.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A set of metadata to be included in service logs.
|
|
13
|
+
*/
|
|
14
|
+
appMetadata?: Record<string, string>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
|
|
18
|
+
*/
|
|
19
|
+
params?: Record<string, StreamingSyncRequestParameterType>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The connection method to use when streaming updates from
|
|
23
|
+
* the PowerSync backend instance.
|
|
24
|
+
*
|
|
25
|
+
* The default value is SDK-specific. {@link SyncStreamConnectionMethod.HTTP} is the preferred implementation and used
|
|
26
|
+
* by default, except for React Native apps without Expo. Those don't support streaming HTTP responses, which is why
|
|
27
|
+
* {@link SyncStreamConnectionMethod.WEB_SOCKET} is used as a workaround.
|
|
28
|
+
*/
|
|
29
|
+
connectionMethod?: SyncStreamConnectionMethod;
|
|
30
|
+
|
|
31
|
+
fetchStrategy?: FetchStrategy;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether to include streams that have `auto_subscribe: true` in their definition.
|
|
35
|
+
*
|
|
36
|
+
* This defaults to `true`.
|
|
37
|
+
*/
|
|
38
|
+
includeDefaultStreams?: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delay for retrying sync streaming operations
|
|
42
|
+
* from the PowerSync backend after an error occurs.
|
|
43
|
+
*/
|
|
44
|
+
retryDelayMs?: number;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Backend Connector CRUD operations are throttled
|
|
48
|
+
* to occur at most every `crudUploadThrottleMs`
|
|
49
|
+
* milliseconds.
|
|
50
|
+
*/
|
|
51
|
+
crudUploadThrottleMs?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export enum SyncStreamConnectionMethod {
|
|
58
|
+
HTTP = 'http',
|
|
59
|
+
WEB_SOCKET = 'web-socket'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export enum FetchStrategy {
|
|
66
|
+
/**
|
|
67
|
+
* Queues multiple sync events before processing, reducing round-trips.
|
|
68
|
+
* This comes at the cost of more processing overhead, which may cause ACK timeouts on older/weaker devices for big enough datasets.
|
|
69
|
+
*/
|
|
70
|
+
Buffered = 'buffered',
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Processes each sync event immediately before requesting the next.
|
|
74
|
+
* This reduces processing overhead and improves real-time responsiveness.
|
|
75
|
+
*/
|
|
76
|
+
Sequential = 'sequential'
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
|
|
2
|
+
|
|
3
|
+
interface JSONObject {
|
|
4
|
+
[key: string]: JSONValue;
|
|
5
|
+
}
|
|
6
|
+
type JSONArray = JSONValue[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type StreamingSyncRequestParameterType = JSONValue;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* A description of a sync stream, consisting of its {@link name} and the
|
|
2
|
+
* A description of a sync stream, consisting of its {@link SyncStreamDescription.name} and the
|
|
3
|
+
* {@link SyncStreamDescription.parameters} used when subscribing.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
5
6
|
*/
|
|
6
7
|
export interface SyncStreamDescription {
|
|
7
8
|
/**
|
|
@@ -21,6 +22,8 @@ export interface SyncStreamDescription {
|
|
|
21
22
|
* Information about a subscribed sync stream.
|
|
22
23
|
*
|
|
23
24
|
* This includes the {@link SyncStreamDescription}, along with information about the current sync status.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
24
27
|
*/
|
|
25
28
|
export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
26
29
|
active: boolean;
|
|
@@ -28,15 +31,17 @@ export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
28
31
|
* Whether this stream subscription is included by default, regardless of whether the stream has explicitly been
|
|
29
32
|
* subscribed to or not.
|
|
30
33
|
*
|
|
31
|
-
* It's possible for both {@link isDefault} and
|
|
32
|
-
*
|
|
34
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
35
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
36
|
+
* default stream was subscribed explicitly.
|
|
33
37
|
*/
|
|
34
38
|
isDefault: boolean;
|
|
35
39
|
/**
|
|
36
40
|
* Whether this stream has been subscribed to explicitly.
|
|
37
41
|
*
|
|
38
|
-
* It's possible for both {@link isDefault} and
|
|
39
|
-
*
|
|
42
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
43
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
44
|
+
* default stream was subscribed explicitly.
|
|
40
45
|
*/
|
|
41
46
|
hasExplicitSubscription: boolean;
|
|
42
47
|
/**
|
|
@@ -49,11 +54,14 @@ export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
49
54
|
*/
|
|
50
55
|
hasSynced: boolean;
|
|
51
56
|
/**
|
|
52
|
-
* If {@link hasSynced} is true, the last time data from this stream has been synced.
|
|
57
|
+
* If {@link SyncSubscriptionDescription.hasSynced} is true, the last time data from this stream has been synced.
|
|
53
58
|
*/
|
|
54
59
|
lastSyncedAt: Date | null;
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
57
65
|
export interface SyncStreamSubscribeOptions {
|
|
58
66
|
/**
|
|
59
67
|
* A "time to live" for this stream subscription, in seconds.
|
|
@@ -73,7 +81,9 @@ export interface SyncStreamSubscribeOptions {
|
|
|
73
81
|
/**
|
|
74
82
|
* A handle to a {@link SyncStreamDescription} that allows subscribing to the stream.
|
|
75
83
|
*
|
|
76
|
-
* To obtain an instance of {@link SyncStream}, call {@link
|
|
84
|
+
* To obtain an instance of {@link SyncStream}, call {@link CommonPowerSyncDatabase.syncStream}.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
77
87
|
*/
|
|
78
88
|
export interface SyncStream extends SyncStreamDescription {
|
|
79
89
|
/**
|
|
@@ -82,7 +92,7 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
82
92
|
* You should keep a reference to the returned {@link SyncStreamSubscription} object along as you need data for that
|
|
83
93
|
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
84
94
|
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
85
|
-
* eventually evict the stream (unless {@link subscribe} is called again).
|
|
95
|
+
* eventually evict the stream (unless {@link SyncStream.subscribe} is called again).
|
|
86
96
|
*/
|
|
87
97
|
subscribe(options?: SyncStreamSubscribeOptions): Promise<SyncStreamSubscription>;
|
|
88
98
|
|
|
@@ -94,6 +104,9 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
94
104
|
unsubscribeAll(): Promise<void>;
|
|
95
105
|
}
|
|
96
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
97
110
|
export interface SyncStreamSubscription extends SyncStreamDescription {
|
|
98
111
|
/**
|
|
99
112
|
* A promise that resolves once data from in this sync stream has been synced and applied.
|
|
@@ -2,7 +2,8 @@ import { LockContext } from '../../db/DBAdapter.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* SQLite operations to track changes for with {@link TriggerManager}
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* @experimental @alpha
|
|
6
7
|
*/
|
|
7
8
|
export enum DiffTriggerOperation {
|
|
8
9
|
INSERT = 'INSERT',
|
|
@@ -11,7 +12,7 @@ export enum DiffTriggerOperation {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* @experimental
|
|
15
|
+
* @experimental @alpha
|
|
15
16
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
16
17
|
* This is the base record structure for all diff records.
|
|
17
18
|
*
|
|
@@ -42,7 +43,7 @@ export interface BaseTriggerDiffRecord<TOperationId extends string | number = nu
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* @experimental
|
|
46
|
+
* @experimental @alpha
|
|
46
47
|
* Represents a diff record for a SQLite UPDATE operation.
|
|
47
48
|
* This record contains the new value and optionally the previous value.
|
|
48
49
|
* Values are stored as JSON strings.
|
|
@@ -62,7 +63,7 @@ export interface TriggerDiffUpdateRecord<
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
|
-
* @experimental
|
|
66
|
+
* @experimental @alpha
|
|
66
67
|
* Represents a diff record for a SQLite INSERT operation.
|
|
67
68
|
* This record contains the new value represented as a JSON string.
|
|
68
69
|
*/
|
|
@@ -77,7 +78,7 @@ export interface TriggerDiffInsertRecord<
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* @experimental
|
|
81
|
+
* @experimental @alpha
|
|
81
82
|
* Represents a diff record for a SQLite DELETE operation.
|
|
82
83
|
* This record contains the new value represented as a JSON string.
|
|
83
84
|
*/
|
|
@@ -92,7 +93,7 @@ export interface TriggerDiffDeleteRecord<
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
|
-
* @experimental
|
|
96
|
+
* @experimental @alpha
|
|
96
97
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
97
98
|
* This is the record structure for all diff records.
|
|
98
99
|
*
|
|
@@ -121,7 +122,7 @@ export type TriggerDiffRecord<TOperationId extends string | number = number> =
|
|
|
121
122
|
| TriggerDiffDeleteRecord<TOperationId>;
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
|
-
* @experimental
|
|
125
|
+
* @experimental @alpha
|
|
125
126
|
* Querying the DIFF table directly with {@link TriggerDiffHandlerContext#withExtractedDiff} will return records
|
|
126
127
|
* with the tracked columns extracted from the JSON value.
|
|
127
128
|
* This type represents the structure of such records.
|
|
@@ -150,7 +151,7 @@ export type ExtractedTriggerDiffRecord<T, TOperationId extends string | number =
|
|
|
150
151
|
};
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
|
-
* @experimental
|
|
154
|
+
* @experimental @alpha
|
|
154
155
|
* Hooks used in the creation of a table diff trigger.
|
|
155
156
|
*/
|
|
156
157
|
export interface TriggerCreationHooks {
|
|
@@ -162,9 +163,10 @@ export interface TriggerCreationHooks {
|
|
|
162
163
|
|
|
163
164
|
/**
|
|
164
165
|
* Common interface for options used in creating a diff trigger.
|
|
166
|
+
*
|
|
167
|
+
* @alpha @experimental
|
|
165
168
|
*/
|
|
166
|
-
|
|
167
|
-
interface BaseCreateDiffTriggerOptions {
|
|
169
|
+
export interface BaseCreateDiffTriggerOptions {
|
|
168
170
|
/**
|
|
169
171
|
* PowerSync source table/view to trigger and track changes from.
|
|
170
172
|
* This should be present in the PowerSync database's schema.
|
|
@@ -187,16 +189,18 @@ interface BaseCreateDiffTriggerOptions {
|
|
|
187
189
|
* The row id is available in the `id` column.
|
|
188
190
|
*
|
|
189
191
|
* NB! The WHEN clauses here are added directly to the SQLite trigger creation SQL.
|
|
190
|
-
* Any user input strings here should be sanitized externally. The {@link when} string
|
|
191
|
-
* some basic sanitization, extra external sanitization is recommended.
|
|
192
|
+
* Any user input strings here should be sanitized externally. The {@link BaseCreateDiffTriggerOptions.when} string
|
|
193
|
+
* template function performs some basic sanitization, extra external sanitization is recommended.
|
|
192
194
|
*
|
|
193
195
|
* @example
|
|
196
|
+
* ```JavaScript
|
|
194
197
|
* {
|
|
195
198
|
* 'INSERT': sanitizeSQL`json_extract(NEW.data, '$.list_id') = ${sanitizeUUID(list.id)}`,
|
|
196
199
|
* 'INSERT': `TRUE`,
|
|
197
200
|
* 'UPDATE': sanitizeSQL`NEW.id = 'abcd' AND json_extract(NEW.data, '$.status') = 'active'`,
|
|
198
201
|
* 'DELETE': sanitizeSQL`json_extract(OLD.data, '$.list_id') = 'abcd'`
|
|
199
202
|
* }
|
|
203
|
+
* ```
|
|
200
204
|
*/
|
|
201
205
|
when: Partial<Record<DiffTriggerOperation, string>>;
|
|
202
206
|
|
|
@@ -213,7 +217,7 @@ interface BaseCreateDiffTriggerOptions {
|
|
|
213
217
|
}
|
|
214
218
|
|
|
215
219
|
/**
|
|
216
|
-
* @experimental
|
|
220
|
+
* @experimental @alpha
|
|
217
221
|
* Options for {@link TriggerManager#createDiffTrigger}.
|
|
218
222
|
*/
|
|
219
223
|
export interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -232,7 +236,7 @@ export interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
/**
|
|
235
|
-
* @experimental
|
|
239
|
+
* @experimental @alpha
|
|
236
240
|
* Options for {@link TriggerRemoveCallback}.
|
|
237
241
|
*/
|
|
238
242
|
export interface TriggerRemoveCallbackOptions {
|
|
@@ -240,12 +244,12 @@ export interface TriggerRemoveCallbackOptions {
|
|
|
240
244
|
}
|
|
241
245
|
|
|
242
246
|
/**
|
|
243
|
-
* @experimental
|
|
247
|
+
* @experimental @alpha
|
|
244
248
|
* Callback to drop a trigger after it has been created.
|
|
245
249
|
*/
|
|
246
250
|
export type TriggerRemoveCallback = (options?: TriggerRemoveCallbackOptions) => Promise<void>;
|
|
247
251
|
/**
|
|
248
|
-
* @experimental
|
|
252
|
+
* @experimental @alpha
|
|
249
253
|
* Options for {@link TriggerDiffHandlerContext#withDiff}.
|
|
250
254
|
*/
|
|
251
255
|
export interface WithDiffOptions {
|
|
@@ -260,10 +264,12 @@ export interface WithDiffOptions {
|
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
/**
|
|
263
|
-
* @experimental
|
|
267
|
+
* @experimental @alpha
|
|
264
268
|
* Context for the `onChange` handler provided to {@link TriggerManager#trackTableDiff}.
|
|
265
269
|
*/
|
|
266
|
-
export interface TriggerDiffHandlerContext
|
|
270
|
+
export interface TriggerDiffHandlerContext {
|
|
271
|
+
context: LockContext;
|
|
272
|
+
|
|
267
273
|
/**
|
|
268
274
|
* The name of the temporary destination table created by the trigger.
|
|
269
275
|
*/
|
|
@@ -317,7 +323,7 @@ export interface TriggerDiffHandlerContext extends LockContext {
|
|
|
317
323
|
* Allows querying the database with access to the table containing diff records.
|
|
318
324
|
* The diff table is accessible via the `DIFF` accessor.
|
|
319
325
|
*
|
|
320
|
-
* This is similar to {@link withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
326
|
+
* This is similar to {@link TriggerDiffHandlerContext#withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
321
327
|
* data is aliased as `__` columns to avoid column conflicts.
|
|
322
328
|
*
|
|
323
329
|
* For {@link DiffTriggerOperation#DELETE} operations the previous_value columns are extracted for convenience.
|
|
@@ -349,7 +355,7 @@ export interface TriggerDiffHandlerContext extends LockContext {
|
|
|
349
355
|
}
|
|
350
356
|
|
|
351
357
|
/**
|
|
352
|
-
* @experimental
|
|
358
|
+
* @experimental @alpha
|
|
353
359
|
* Options for tracking changes to a table with {@link TriggerManager#trackTableDiff}.
|
|
354
360
|
*/
|
|
355
361
|
export interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -361,14 +367,13 @@ export interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
|
361
367
|
onChange: (context: TriggerDiffHandlerContext) => Promise<void>;
|
|
362
368
|
|
|
363
369
|
/**
|
|
364
|
-
* The minimum interval, in milliseconds, between {@link onChange} invocations.
|
|
365
|
-
* @default {@link DEFAULT_WATCH_THROTTLE_MS}
|
|
370
|
+
* The minimum interval, in milliseconds, between {@link TrackDiffOptions.onChange} invocations.
|
|
366
371
|
*/
|
|
367
372
|
throttleMs?: number;
|
|
368
373
|
}
|
|
369
374
|
|
|
370
375
|
/**
|
|
371
|
-
* @experimental
|
|
376
|
+
* @experimental @alpha
|
|
372
377
|
*/
|
|
373
378
|
export interface TriggerManager {
|
|
374
379
|
/**
|
|
@@ -417,7 +422,7 @@ export interface TriggerManager {
|
|
|
417
422
|
/**
|
|
418
423
|
* @experimental
|
|
419
424
|
* Tracks changes for a table. Triggering a provided handler on changes.
|
|
420
|
-
* Uses {@link createDiffTrigger} internally to create a temporary destination table.
|
|
425
|
+
* Uses {@link TriggerManager.createDiffTrigger} internally to create a temporary destination table.
|
|
421
426
|
*
|
|
422
427
|
* @returns A callback to cleanup the trigger and stop tracking changes.
|
|
423
428
|
*
|
|
@@ -471,38 +476,3 @@ export interface TriggerManager {
|
|
|
471
476
|
*/
|
|
472
477
|
trackTableDiff(options: TrackDiffOptions): Promise<TriggerRemoveCallback>;
|
|
473
478
|
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* @experimental
|
|
477
|
-
* @internal
|
|
478
|
-
* Manages claims on persisted SQLite triggers and destination tables to enable proper cleanup
|
|
479
|
-
* when they are no longer actively in use.
|
|
480
|
-
*
|
|
481
|
-
* When using persisted triggers (especially for OPFS multi-tab scenarios), we need a reliable way to determine which resources are still actively in use across different connections/tabs so stale resources can be safely cleaned up without interfering with active triggers.
|
|
482
|
-
*
|
|
483
|
-
* A cleanup process runs
|
|
484
|
-
* on database creation (and every 2 minutes) that:
|
|
485
|
-
* 1. Queries for existing managed persisted resources
|
|
486
|
-
* 2. Checks with the claim manager if any consumer is actively using those resources
|
|
487
|
-
* 3. Deletes unused resources
|
|
488
|
-
*/
|
|
489
|
-
|
|
490
|
-
export interface TriggerClaimManager {
|
|
491
|
-
/**
|
|
492
|
-
* Obtains or marks a claim on a certain identifier.
|
|
493
|
-
* @returns a callback to release the claim.
|
|
494
|
-
*/
|
|
495
|
-
obtainClaim: (identifier: string) => Promise<() => Promise<void>>;
|
|
496
|
-
/**
|
|
497
|
-
* Checks if a claim is present for an identifier.
|
|
498
|
-
*/
|
|
499
|
-
checkClaim: (identifier: string) => Promise<boolean>;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* @experimental
|
|
504
|
-
* @internal
|
|
505
|
-
*/
|
|
506
|
-
export interface TriggerManagerConfig {
|
|
507
|
-
claimManager: TriggerClaimManager;
|
|
508
|
-
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
function sanitizeString(input: string): string {
|
|
2
2
|
return `'${input.replace(/'/g, "''")}'`;
|
|
3
3
|
}
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Helper function for sanitizing UUID input strings.
|
|
6
7
|
* Typically used with {@link sanitizeSQL}.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
7
10
|
*/
|
|
8
11
|
export function sanitizeUUID(uuid: string): string {
|
|
9
12
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
@@ -41,6 +44,8 @@ export function sanitizeUUID(uuid: string): string {
|
|
|
41
44
|
* // Incorrect:
|
|
42
45
|
* sanitizeSQL`New.id = '${myID}'` // Produces double quotes: New.id = ''O''Reilly''
|
|
43
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* @alpha
|
|
44
49
|
*/
|
|
45
50
|
export function sanitizeSQL(strings: TemplateStringsArray, ...values: any[]): string {
|
|
46
51
|
let result = '';
|