@powersync/common 0.0.0-dev-20260504100448 → 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 +3 -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 +6 -22
- package/lib/index.js +5 -22
- 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 +9 -46
- 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 +3 -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 +6 -22
- 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 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- 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 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- 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 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- 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 -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 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- 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,7 +1,8 @@
|
|
|
1
1
|
import { LockContext } from '../../db/DBAdapter.js';
|
|
2
2
|
/**
|
|
3
3
|
* SQLite operations to track changes for with {@link TriggerManager}
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* @experimental @alpha
|
|
5
6
|
*/
|
|
6
7
|
export declare enum DiffTriggerOperation {
|
|
7
8
|
INSERT = "INSERT",
|
|
@@ -9,7 +10,7 @@ export declare enum DiffTriggerOperation {
|
|
|
9
10
|
DELETE = "DELETE"
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
|
-
* @experimental
|
|
13
|
+
* @experimental @alpha
|
|
13
14
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
14
15
|
* This is the base record structure for all diff records.
|
|
15
16
|
*
|
|
@@ -38,7 +39,7 @@ export interface BaseTriggerDiffRecord<TOperationId extends string | number = nu
|
|
|
38
39
|
timestamp: string;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
|
-
* @experimental
|
|
42
|
+
* @experimental @alpha
|
|
42
43
|
* Represents a diff record for a SQLite UPDATE operation.
|
|
43
44
|
* This record contains the new value and optionally the previous value.
|
|
44
45
|
* Values are stored as JSON strings.
|
|
@@ -55,7 +56,7 @@ export interface TriggerDiffUpdateRecord<TOperationId extends string | number =
|
|
|
55
56
|
previous_value: string;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
* @experimental
|
|
59
|
+
* @experimental @alpha
|
|
59
60
|
* Represents a diff record for a SQLite INSERT operation.
|
|
60
61
|
* This record contains the new value represented as a JSON string.
|
|
61
62
|
*/
|
|
@@ -67,7 +68,7 @@ export interface TriggerDiffInsertRecord<TOperationId extends string | number =
|
|
|
67
68
|
value: string;
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
|
-
* @experimental
|
|
71
|
+
* @experimental @alpha
|
|
71
72
|
* Represents a diff record for a SQLite DELETE operation.
|
|
72
73
|
* This record contains the new value represented as a JSON string.
|
|
73
74
|
*/
|
|
@@ -79,7 +80,7 @@ export interface TriggerDiffDeleteRecord<TOperationId extends string | number =
|
|
|
79
80
|
value: string;
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
|
-
* @experimental
|
|
83
|
+
* @experimental @alpha
|
|
83
84
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
84
85
|
* This is the record structure for all diff records.
|
|
85
86
|
*
|
|
@@ -104,7 +105,7 @@ export interface TriggerDiffDeleteRecord<TOperationId extends string | number =
|
|
|
104
105
|
*/
|
|
105
106
|
export type TriggerDiffRecord<TOperationId extends string | number = number> = TriggerDiffUpdateRecord<TOperationId> | TriggerDiffInsertRecord<TOperationId> | TriggerDiffDeleteRecord<TOperationId>;
|
|
106
107
|
/**
|
|
107
|
-
* @experimental
|
|
108
|
+
* @experimental @alpha
|
|
108
109
|
* Querying the DIFF table directly with {@link TriggerDiffHandlerContext#withExtractedDiff} will return records
|
|
109
110
|
* with the tracked columns extracted from the JSON value.
|
|
110
111
|
* This type represents the structure of such records.
|
|
@@ -132,7 +133,7 @@ export type ExtractedTriggerDiffRecord<T, TOperationId extends string | number =
|
|
|
132
133
|
__previous_value?: string;
|
|
133
134
|
};
|
|
134
135
|
/**
|
|
135
|
-
* @experimental
|
|
136
|
+
* @experimental @alpha
|
|
136
137
|
* Hooks used in the creation of a table diff trigger.
|
|
137
138
|
*/
|
|
138
139
|
export interface TriggerCreationHooks {
|
|
@@ -143,8 +144,10 @@ export interface TriggerCreationHooks {
|
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
146
|
* Common interface for options used in creating a diff trigger.
|
|
147
|
+
*
|
|
148
|
+
* @alpha @experimental
|
|
146
149
|
*/
|
|
147
|
-
interface BaseCreateDiffTriggerOptions {
|
|
150
|
+
export interface BaseCreateDiffTriggerOptions {
|
|
148
151
|
/**
|
|
149
152
|
* PowerSync source table/view to trigger and track changes from.
|
|
150
153
|
* This should be present in the PowerSync database's schema.
|
|
@@ -165,16 +168,18 @@ interface BaseCreateDiffTriggerOptions {
|
|
|
165
168
|
* The row id is available in the `id` column.
|
|
166
169
|
*
|
|
167
170
|
* NB! The WHEN clauses here are added directly to the SQLite trigger creation SQL.
|
|
168
|
-
* Any user input strings here should be sanitized externally. The {@link when} string
|
|
169
|
-
* some basic sanitization, extra external sanitization is recommended.
|
|
171
|
+
* Any user input strings here should be sanitized externally. The {@link BaseCreateDiffTriggerOptions.when} string
|
|
172
|
+
* template function performs some basic sanitization, extra external sanitization is recommended.
|
|
170
173
|
*
|
|
171
174
|
* @example
|
|
175
|
+
* ```JavaScript
|
|
172
176
|
* {
|
|
173
177
|
* 'INSERT': sanitizeSQL`json_extract(NEW.data, '$.list_id') = ${sanitizeUUID(list.id)}`,
|
|
174
178
|
* 'INSERT': `TRUE`,
|
|
175
179
|
* 'UPDATE': sanitizeSQL`NEW.id = 'abcd' AND json_extract(NEW.data, '$.status') = 'active'`,
|
|
176
180
|
* 'DELETE': sanitizeSQL`json_extract(OLD.data, '$.list_id') = 'abcd'`
|
|
177
181
|
* }
|
|
182
|
+
* ```
|
|
178
183
|
*/
|
|
179
184
|
when: Partial<Record<DiffTriggerOperation, string>>;
|
|
180
185
|
/**
|
|
@@ -188,7 +193,7 @@ interface BaseCreateDiffTriggerOptions {
|
|
|
188
193
|
useStorage?: boolean;
|
|
189
194
|
}
|
|
190
195
|
/**
|
|
191
|
-
* @experimental
|
|
196
|
+
* @experimental @alpha
|
|
192
197
|
* Options for {@link TriggerManager#createDiffTrigger}.
|
|
193
198
|
*/
|
|
194
199
|
export interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -205,19 +210,19 @@ export interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
|
205
210
|
setupContext?: LockContext;
|
|
206
211
|
}
|
|
207
212
|
/**
|
|
208
|
-
* @experimental
|
|
213
|
+
* @experimental @alpha
|
|
209
214
|
* Options for {@link TriggerRemoveCallback}.
|
|
210
215
|
*/
|
|
211
216
|
export interface TriggerRemoveCallbackOptions {
|
|
212
217
|
context?: LockContext;
|
|
213
218
|
}
|
|
214
219
|
/**
|
|
215
|
-
* @experimental
|
|
220
|
+
* @experimental @alpha
|
|
216
221
|
* Callback to drop a trigger after it has been created.
|
|
217
222
|
*/
|
|
218
223
|
export type TriggerRemoveCallback = (options?: TriggerRemoveCallbackOptions) => Promise<void>;
|
|
219
224
|
/**
|
|
220
|
-
* @experimental
|
|
225
|
+
* @experimental @alpha
|
|
221
226
|
* Options for {@link TriggerDiffHandlerContext#withDiff}.
|
|
222
227
|
*/
|
|
223
228
|
export interface WithDiffOptions {
|
|
@@ -231,10 +236,11 @@ export interface WithDiffOptions {
|
|
|
231
236
|
castOperationIdAsText?: boolean;
|
|
232
237
|
}
|
|
233
238
|
/**
|
|
234
|
-
* @experimental
|
|
239
|
+
* @experimental @alpha
|
|
235
240
|
* Context for the `onChange` handler provided to {@link TriggerManager#trackTableDiff}.
|
|
236
241
|
*/
|
|
237
|
-
export interface TriggerDiffHandlerContext
|
|
242
|
+
export interface TriggerDiffHandlerContext {
|
|
243
|
+
context: LockContext;
|
|
238
244
|
/**
|
|
239
245
|
* The name of the temporary destination table created by the trigger.
|
|
240
246
|
*/
|
|
@@ -286,7 +292,7 @@ export interface TriggerDiffHandlerContext extends LockContext {
|
|
|
286
292
|
* Allows querying the database with access to the table containing diff records.
|
|
287
293
|
* The diff table is accessible via the `DIFF` accessor.
|
|
288
294
|
*
|
|
289
|
-
* This is similar to {@link withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
295
|
+
* This is similar to {@link TriggerDiffHandlerContext#withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
290
296
|
* data is aliased as `__` columns to avoid column conflicts.
|
|
291
297
|
*
|
|
292
298
|
* For {@link DiffTriggerOperation#DELETE} operations the previous_value columns are extracted for convenience.
|
|
@@ -317,7 +323,7 @@ export interface TriggerDiffHandlerContext extends LockContext {
|
|
|
317
323
|
withExtractedDiff: <T = any>(query: string, params?: ReadonlyArray<Readonly<any>>) => Promise<T[]>;
|
|
318
324
|
}
|
|
319
325
|
/**
|
|
320
|
-
* @experimental
|
|
326
|
+
* @experimental @alpha
|
|
321
327
|
* Options for tracking changes to a table with {@link TriggerManager#trackTableDiff}.
|
|
322
328
|
*/
|
|
323
329
|
export interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -328,13 +334,12 @@ export interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
|
328
334
|
*/
|
|
329
335
|
onChange: (context: TriggerDiffHandlerContext) => Promise<void>;
|
|
330
336
|
/**
|
|
331
|
-
* The minimum interval, in milliseconds, between {@link onChange} invocations.
|
|
332
|
-
* @default {@link DEFAULT_WATCH_THROTTLE_MS}
|
|
337
|
+
* The minimum interval, in milliseconds, between {@link TrackDiffOptions.onChange} invocations.
|
|
333
338
|
*/
|
|
334
339
|
throttleMs?: number;
|
|
335
340
|
}
|
|
336
341
|
/**
|
|
337
|
-
* @experimental
|
|
342
|
+
* @experimental @alpha
|
|
338
343
|
*/
|
|
339
344
|
export interface TriggerManager {
|
|
340
345
|
/**
|
|
@@ -382,7 +387,7 @@ export interface TriggerManager {
|
|
|
382
387
|
/**
|
|
383
388
|
* @experimental
|
|
384
389
|
* Tracks changes for a table. Triggering a provided handler on changes.
|
|
385
|
-
* Uses {@link createDiffTrigger} internally to create a temporary destination table.
|
|
390
|
+
* Uses {@link TriggerManager.createDiffTrigger} internally to create a temporary destination table.
|
|
386
391
|
*
|
|
387
392
|
* @returns A callback to cleanup the trigger and stop tracking changes.
|
|
388
393
|
*
|
|
@@ -436,36 +441,3 @@ export interface TriggerManager {
|
|
|
436
441
|
*/
|
|
437
442
|
trackTableDiff(options: TrackDiffOptions): Promise<TriggerRemoveCallback>;
|
|
438
443
|
}
|
|
439
|
-
/**
|
|
440
|
-
* @experimental
|
|
441
|
-
* @internal
|
|
442
|
-
* Manages claims on persisted SQLite triggers and destination tables to enable proper cleanup
|
|
443
|
-
* when they are no longer actively in use.
|
|
444
|
-
*
|
|
445
|
-
* 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.
|
|
446
|
-
*
|
|
447
|
-
* A cleanup process runs
|
|
448
|
-
* on database creation (and every 2 minutes) that:
|
|
449
|
-
* 1. Queries for existing managed persisted resources
|
|
450
|
-
* 2. Checks with the claim manager if any consumer is actively using those resources
|
|
451
|
-
* 3. Deletes unused resources
|
|
452
|
-
*/
|
|
453
|
-
export interface TriggerClaimManager {
|
|
454
|
-
/**
|
|
455
|
-
* Obtains or marks a claim on a certain identifier.
|
|
456
|
-
* @returns a callback to release the claim.
|
|
457
|
-
*/
|
|
458
|
-
obtainClaim: (identifier: string) => Promise<() => Promise<void>>;
|
|
459
|
-
/**
|
|
460
|
-
* Checks if a claim is present for an identifier.
|
|
461
|
-
*/
|
|
462
|
-
checkClaim: (identifier: string) => Promise<boolean>;
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* @experimental
|
|
466
|
-
* @internal
|
|
467
|
-
*/
|
|
468
|
-
export interface TriggerManagerConfig {
|
|
469
|
-
claimManager: TriggerClaimManager;
|
|
470
|
-
}
|
|
471
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TriggerManager.js","sourceRoot":"","sources":["../../../src/client/triggers/TriggerManager.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"TriggerManager.js","sourceRoot":"","sources":["../../../src/client/triggers/TriggerManager.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;AACnB,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helper function for sanitizing UUID input strings.
|
|
3
3
|
* Typically used with {@link sanitizeSQL}.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
4
6
|
*/
|
|
5
7
|
export declare function sanitizeUUID(uuid: string): string;
|
|
6
8
|
/**
|
|
@@ -30,5 +32,7 @@ export declare function sanitizeUUID(uuid: string): string;
|
|
|
30
32
|
* // Incorrect:
|
|
31
33
|
* sanitizeSQL`New.id = '${myID}'` // Produces double quotes: New.id = ''O''Reilly''
|
|
32
34
|
* ```
|
|
35
|
+
*
|
|
36
|
+
* @alpha
|
|
33
37
|
*/
|
|
34
38
|
export declare function sanitizeSQL(strings: TemplateStringsArray, ...values: any[]): string;
|
|
@@ -4,6 +4,8 @@ function sanitizeString(input) {
|
|
|
4
4
|
/**
|
|
5
5
|
* Helper function for sanitizing UUID input strings.
|
|
6
6
|
* Typically used with {@link sanitizeSQL}.
|
|
7
|
+
*
|
|
8
|
+
* @alpha
|
|
7
9
|
*/
|
|
8
10
|
export function sanitizeUUID(uuid) {
|
|
9
11
|
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;
|
|
@@ -40,6 +42,8 @@ export function sanitizeUUID(uuid) {
|
|
|
40
42
|
* // Incorrect:
|
|
41
43
|
* sanitizeSQL`New.id = '${myID}'` // Produces double quotes: New.id = ''O''Reilly''
|
|
42
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* @alpha
|
|
43
47
|
*/
|
|
44
48
|
export function sanitizeSQL(strings, ...values) {
|
|
45
49
|
let result = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeSQL.js","sourceRoot":"","sources":["../../../src/client/triggers/sanitizeSQL.ts"],"names":[],"mappings":"AAAA,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC1C,CAAC;
|
|
1
|
+
{"version":3,"file":"sanitizeSQL.js","sourceRoot":"","sources":["../../../src/client/triggers/sanitizeSQL.ts"],"names":[],"mappings":"AAAA,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,SAAS,GAAG,4EAA4E,CAAC;IAC/F,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,sBAAsB,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,WAAW,CAAC,OAA6B,EAAE,GAAG,MAAa;IACzE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,CAAC;QACd,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,iDAAiD;YACjD,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;iBAAM,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBACzB,MAAM,IAAI,MAAM,CAAC;YACnB,CAAC;iBAAM,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;gBACpC,8DAA8D;gBAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAC1C,MAAM,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CompiledQuery } from '../../types/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
3
3
|
import { WatchCompatibleQuery } from './WatchedQuery.js';
|
|
4
4
|
/**
|
|
5
5
|
* Options for {@link GetAllQuery}.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
6
8
|
*/
|
|
7
9
|
export type GetAllQueryOptions<RowType = unknown> = {
|
|
8
10
|
sql: string;
|
|
@@ -20,13 +22,15 @@ export type GetAllQueryOptions<RowType = unknown> = {
|
|
|
20
22
|
mapper?: (rawRow: Record<string, unknown>) => RowType;
|
|
21
23
|
};
|
|
22
24
|
/**
|
|
23
|
-
* Performs a {@link
|
|
25
|
+
* Performs a {@link DBGetUtils.getAll} operation for a watched query.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
24
28
|
*/
|
|
25
29
|
export declare class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<RowType[]> {
|
|
26
30
|
protected options: GetAllQueryOptions<RowType>;
|
|
27
31
|
constructor(options: GetAllQueryOptions<RowType>);
|
|
28
32
|
compile(): CompiledQuery;
|
|
29
33
|
execute(options: {
|
|
30
|
-
db:
|
|
34
|
+
db: CommonPowerSyncDatabase;
|
|
31
35
|
}): Promise<RowType[]>;
|
|
32
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GetAllQuery.js","sourceRoot":"","sources":["../../../src/client/watched/GetAllQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GetAllQuery.js","sourceRoot":"","sources":["../../../src/client/watched/GetAllQuery.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACA;IAAtB,YAAsB,OAAoC;QAApC,YAAO,GAAP,OAAO,CAA6B;IAAG,CAAC;IAE9D,OAAO;QACL,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YACrB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE;SAC1C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwC;QACpD,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,MAAM,CAA0B,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;QACjF,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,SAAsB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CompiledQuery } from '../../types/types.js';
|
|
2
2
|
import { BaseListener } from '../../utils/BaseObserver.js';
|
|
3
3
|
import { MetaBaseObserverInterface } from '../../utils/MetaBaseObserver.js';
|
|
4
|
-
import {
|
|
4
|
+
import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
5
5
|
/**
|
|
6
6
|
* State for {@link WatchedQuery} instances.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
10
|
export interface WatchedQueryState<Data> {
|
|
9
11
|
/**
|
|
@@ -31,20 +33,25 @@ export interface WatchedQueryState<Data> {
|
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Options provided to the `execute` method of a {@link WatchCompatibleQuery}.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
34
38
|
*/
|
|
35
39
|
export interface WatchExecuteOptions {
|
|
36
40
|
sql: string;
|
|
37
41
|
parameters: any[];
|
|
38
|
-
db:
|
|
42
|
+
db: CommonPowerSyncDatabase;
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
43
47
|
*/
|
|
44
48
|
export interface WatchCompatibleQuery<ResultType> {
|
|
45
49
|
execute(options: WatchExecuteOptions): Promise<ResultType>;
|
|
46
50
|
compile(): CompiledQuery;
|
|
47
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
48
55
|
export interface WatchedQueryOptions {
|
|
49
56
|
/** The minimum interval between queries. */
|
|
50
57
|
throttleMs?: number;
|
|
@@ -61,6 +68,9 @@ export interface WatchedQueryOptions {
|
|
|
61
68
|
*/
|
|
62
69
|
triggerOnTables?: string[];
|
|
63
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
64
74
|
export declare enum WatchedQueryListenerEvent {
|
|
65
75
|
ON_DATA = "onData",
|
|
66
76
|
ON_ERROR = "onError",
|
|
@@ -68,6 +78,9 @@ export declare enum WatchedQueryListenerEvent {
|
|
|
68
78
|
SETTINGS_WILL_UPDATE = "settingsWillUpdate",
|
|
69
79
|
CLOSED = "closed"
|
|
70
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
71
84
|
export interface WatchedQueryListener<Data> extends BaseListener {
|
|
72
85
|
[WatchedQueryListenerEvent.ON_DATA]?: (data: Data) => void | Promise<void>;
|
|
73
86
|
[WatchedQueryListenerEvent.ON_ERROR]?: (error: Error) => void | Promise<void>;
|
|
@@ -75,8 +88,9 @@ export interface WatchedQueryListener<Data> extends BaseListener {
|
|
|
75
88
|
[WatchedQueryListenerEvent.SETTINGS_WILL_UPDATE]?: () => void;
|
|
76
89
|
[WatchedQueryListenerEvent.CLOSED]?: () => void | Promise<void>;
|
|
77
90
|
}
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
/**
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
80
94
|
export interface WatchedQuery<Data = unknown, Settings extends WatchedQueryOptions = WatchedQueryOptions, Listener extends WatchedQueryListener<Data> = WatchedQueryListener<Data>> extends MetaBaseObserverInterface<Listener> {
|
|
81
95
|
/**
|
|
82
96
|
* Current state of the watched query.
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
1
4
|
export var WatchedQueryListenerEvent;
|
|
2
5
|
(function (WatchedQueryListenerEvent) {
|
|
3
6
|
WatchedQueryListenerEvent["ON_DATA"] = "onData";
|
|
@@ -6,9 +9,4 @@ export var WatchedQueryListenerEvent;
|
|
|
6
9
|
WatchedQueryListenerEvent["SETTINGS_WILL_UPDATE"] = "settingsWillUpdate";
|
|
7
10
|
WatchedQueryListenerEvent["CLOSED"] = "closed";
|
|
8
11
|
})(WatchedQueryListenerEvent || (WatchedQueryListenerEvent = {}));
|
|
9
|
-
export const DEFAULT_WATCH_THROTTLE_MS = 30;
|
|
10
|
-
export const DEFAULT_WATCH_QUERY_OPTIONS = {
|
|
11
|
-
throttleMs: DEFAULT_WATCH_THROTTLE_MS,
|
|
12
|
-
reportFetching: true
|
|
13
|
-
};
|
|
14
12
|
//# sourceMappingURL=WatchedQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WatchedQuery.js","sourceRoot":"","sources":["../../../src/client/watched/WatchedQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WatchedQuery.js","sourceRoot":"","sources":["../../../src/client/watched/WatchedQuery.ts"],"names":[],"mappings":"AA4EA;;GAEG;AACH,MAAM,CAAN,IAAY,yBAMX;AAND,WAAY,yBAAyB;IACnC,+CAAkB,CAAA;IAClB,iDAAoB,CAAA;IACpB,8DAAiC,CAAA;IACjC,wEAA2C,CAAA;IAC3C,8CAAiB,CAAA;AACnB,CAAC,EANW,yBAAyB,KAAzB,yBAAyB,QAMpC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { WatchCompatibleQuery, WatchedQuery, WatchedQueryListener, WatchedQueryOptions } from '../WatchedQuery.js';
|
|
2
|
-
import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
|
|
3
2
|
/**
|
|
4
3
|
* Represents an updated row in a differential watched query.
|
|
5
4
|
* It contains both the current and previous state of the row.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
6
7
|
*/
|
|
7
8
|
export interface WatchedQueryRowDifferential<RowType> {
|
|
8
9
|
readonly current: RowType;
|
|
@@ -11,6 +12,8 @@ export interface WatchedQueryRowDifferential<RowType> {
|
|
|
11
12
|
/**
|
|
12
13
|
* Represents the result of a watched query that has been diffed.
|
|
13
14
|
* {@link DifferentialWatchedQueryState#diff} is of the {@link WatchedQueryDifferential} form.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
14
17
|
*/
|
|
15
18
|
export interface WatchedQueryDifferential<RowType> {
|
|
16
19
|
readonly added: ReadonlyArray<Readonly<RowType>>;
|
|
@@ -35,6 +38,8 @@ export interface WatchedQueryDifferential<RowType> {
|
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* Row comparator for differentially watched queries which keys and compares items in the result set.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
38
43
|
*/
|
|
39
44
|
export interface DifferentialWatchedQueryComparator<RowType> {
|
|
40
45
|
/**
|
|
@@ -48,6 +53,8 @@ export interface DifferentialWatchedQueryComparator<RowType> {
|
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Options for building a differential watched query with the {@link Query} builder.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
51
58
|
*/
|
|
52
59
|
export interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
53
60
|
/**
|
|
@@ -58,12 +65,13 @@ export interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOp
|
|
|
58
65
|
* Row comparator used to identify and compare rows in the result set.
|
|
59
66
|
* If not provided, the default comparator will be used which keys items by their `id` property if available,
|
|
60
67
|
* otherwise it uses JSON stringification of the entire item for keying and comparison.
|
|
61
|
-
* @defaultValue {@link DEFAULT_ROW_COMPARATOR}
|
|
62
68
|
*/
|
|
63
69
|
rowComparator?: DifferentialWatchedQueryComparator<RowType>;
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* Settings for differential incremental watched queries using.
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
67
75
|
*/
|
|
68
76
|
export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialWatchedQueryOptions<RowType> {
|
|
69
77
|
/**
|
|
@@ -71,51 +79,13 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
|
|
|
71
79
|
*/
|
|
72
80
|
query: WatchCompatibleQuery<RowType[]>;
|
|
73
81
|
}
|
|
74
|
-
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
|
|
75
|
-
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
export type DifferentialWatchedQuery<RowType> = WatchedQuery<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>, DifferentialWatchedQueryListener<RowType>>;
|
|
78
82
|
/**
|
|
79
|
-
* @
|
|
83
|
+
* @public
|
|
80
84
|
*/
|
|
81
|
-
export interface
|
|
82
|
-
|
|
85
|
+
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
|
|
86
|
+
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
83
87
|
}
|
|
84
|
-
type DataHashMap<RowType> = Map<string, {
|
|
85
|
-
hash: string;
|
|
86
|
-
item: RowType;
|
|
87
|
-
}>;
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
* This is used as the initial state for differential incrementally watched queries.
|
|
89
|
+
* @public
|
|
91
90
|
*/
|
|
92
|
-
export
|
|
93
|
-
added: never[];
|
|
94
|
-
all: never[];
|
|
95
|
-
removed: never[];
|
|
96
|
-
updated: never[];
|
|
97
|
-
unchanged: never[];
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
|
|
101
|
-
* It keys items by their `id` property if available, alternatively it uses JSON stringification
|
|
102
|
-
* of the entire item for the key and comparison.
|
|
103
|
-
*/
|
|
104
|
-
export declare const DEFAULT_ROW_COMPARATOR: DifferentialWatchedQueryComparator<any>;
|
|
105
|
-
/**
|
|
106
|
-
* Uses the PowerSync onChange event to trigger watched queries.
|
|
107
|
-
* Results are emitted on every change of the relevant tables.
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
export declare class DifferentialQueryProcessor<RowType> extends AbstractQueryProcessor<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>> implements DifferentialWatchedQuery<RowType> {
|
|
111
|
-
protected options: DifferentialQueryProcessorOptions<RowType>;
|
|
112
|
-
protected comparator: DifferentialWatchedQueryComparator<RowType>;
|
|
113
|
-
constructor(options: DifferentialQueryProcessorOptions<RowType>);
|
|
114
|
-
protected differentiate(current: RowType[], previousMap: DataHashMap<RowType>): {
|
|
115
|
-
diff: WatchedQueryDifferential<RowType>;
|
|
116
|
-
map: DataHashMap<RowType>;
|
|
117
|
-
hasChanged: boolean;
|
|
118
|
-
};
|
|
119
|
-
protected linkQuery(options: LinkQueryOptions<WatchedQueryDifferential<RowType>>): Promise<void>;
|
|
120
|
-
}
|
|
121
|
-
export {};
|
|
91
|
+
export type DifferentialWatchedQuery<RowType> = WatchedQuery<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>, DifferentialWatchedQueryListener<RowType>>;
|