@powersync/common 1.53.2 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +922 -772
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +922 -772
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +923 -619
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +923 -619
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +749 -205
- package/lib/attachments/AttachmentContext.d.ts +7 -6
- package/lib/attachments/AttachmentContext.js +2 -1
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +82 -33
- package/lib/attachments/AttachmentQueue.js +16 -18
- package/lib/attachments/AttachmentQueue.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 +12 -4
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/AbstractPowerSyncDatabase.d.ts +110 -60
- package/lib/client/AbstractPowerSyncDatabase.js +77 -74
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +6 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js +3 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -1
- package/lib/client/ConnectionManager.d.ts +4 -1
- package/lib/client/ConnectionManager.js +1 -1
- package/lib/client/ConnectionManager.js.map +1 -1
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +12 -0
- package/lib/client/SQLOpenFactory.js +6 -0
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +6 -0
- package/lib/client/compilableQueryWatch.js +3 -0
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -0
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/constants.d.ts +3 -0
- package/lib/client/constants.js +3 -0
- package/lib/client/constants.js.map +1 -1
- package/lib/client/runOnSchemaChange.d.ts +3 -0
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +12 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js +6 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.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 -0
- package/lib/client/sync/bucket/CrudEntry.js +4 -0
- 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/bucket/SqliteBucketStorage.d.ts +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +30 -1
- package/lib/client/sync/stream/AbstractRemote.js +59 -27
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +55 -5
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +32 -4
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js +2 -1
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -1
- package/lib/client/sync/sync-streams.d.ts +22 -7
- package/lib/client/triggers/TriggerManager.d.ts +19 -18
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
- package/lib/client/triggers/TriggerManagerImpl.js +3 -3
- package/lib/client/triggers/TriggerManagerImpl.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 +4 -0
- package/lib/client/watched/GetAllQuery.js +2 -0
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +24 -2
- package/lib/client/watched/WatchedQuery.js +9 -0
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +20 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +4 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -0
- 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/ConnectionClosedError.d.ts +2 -0
- package/lib/db/ConnectionClosedError.js +2 -0
- package/lib/db/ConnectionClosedError.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +56 -6
- package/lib/db/DBAdapter.js +15 -3
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/crud/SyncProgress.d.ts +6 -1
- package/lib/db/crud/SyncProgress.js +2 -0
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +36 -38
- package/lib/db/crud/SyncStatus.js +19 -14
- 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 +28 -0
- package/lib/db/schema/Column.js +16 -3
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +9 -0
- package/lib/db/schema/Index.js +6 -0
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +9 -0
- package/lib/db/schema/IndexedColumn.js +6 -0
- 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 +6 -1
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +27 -3
- package/lib/db/schema/Table.js +9 -0
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/db/schema/TableV2.d.ts +2 -0
- package/lib/db/schema/TableV2.js +2 -0
- package/lib/db/schema/TableV2.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/AbortOperation.d.ts +2 -0
- package/lib/utils/AbortOperation.js +2 -0
- package/lib/utils/AbortOperation.js.map +1 -1
- 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/ControlledExecutor.d.ts +6 -0
- package/lib/utils/ControlledExecutor.js +3 -0
- package/lib/utils/ControlledExecutor.js.map +1 -1
- package/lib/utils/Logger.d.ts +9 -0
- package/lib/utils/Logger.js +6 -0
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/async.d.ts +26 -0
- package/lib/utils/async.js +114 -27
- package/lib/utils/async.js.map +1 -1
- package/lib/utils/compatibility.d.ts +8 -0
- package/lib/utils/compatibility.js +9 -0
- package/lib/utils/compatibility.js.map +1 -0
- package/lib/utils/mutex.d.ts +8 -0
- package/lib/utils/mutex.js +3 -0
- package/lib/utils/mutex.js.map +1 -1
- package/lib/utils/parseQuery.d.ts +6 -0
- package/lib/utils/parseQuery.js +3 -0
- package/lib/utils/parseQuery.js.map +1 -1
- package/lib/utils/stream_transform.d.ts +3 -1
- package/lib/utils/stream_transform.js.map +1 -1
- package/package.json +3 -3
- package/src/attachments/AttachmentContext.ts +7 -6
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +93 -35
- 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 +12 -4
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/AbstractPowerSyncDatabase.ts +135 -91
- package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
- package/src/client/ConnectionManager.ts +4 -1
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +12 -0
- package/src/client/compilableQueryWatch.ts +6 -0
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/constants.ts +3 -0
- package/src/client/runOnSchemaChange.ts +3 -0
- package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +9 -0
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
- package/src/client/sync/stream/AbstractRemote.ts +76 -34
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +55 -5
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
- package/src/client/sync/sync-streams.ts +22 -9
- package/src/client/triggers/TriggerManager.ts +19 -18
- package/src/client/triggers/TriggerManagerImpl.ts +5 -5
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +5 -1
- package/src/client/watched/WatchedQuery.ts +24 -2
- package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/ConnectionClosedError.ts +2 -0
- package/src/db/DBAdapter.ts +58 -6
- package/src/db/crud/SyncProgress.ts +6 -1
- package/src/db/crud/SyncStatus.ts +40 -21
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +28 -3
- package/src/db/schema/Index.ts +9 -0
- package/src/db/schema/IndexedColumn.ts +9 -0
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +8 -3
- package/src/db/schema/Table.ts +30 -5
- package/src/db/schema/TableV2.ts +2 -0
- package/src/index.ts +1 -1
- package/src/types/types.ts +6 -0
- package/src/utils/AbortOperation.ts +2 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/ControlledExecutor.ts +6 -0
- package/src/utils/Logger.ts +9 -0
- package/src/utils/async.ts +136 -28
- package/src/utils/compatibility.ts +9 -0
- package/src/utils/mutex.ts +12 -0
- package/src/utils/parseQuery.ts +6 -0
- package/src/utils/stream_transform.ts +3 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EventIterator } from 'event-iterator';
|
|
2
1
|
import Logger, { ILogger } from 'js-logger';
|
|
3
2
|
import {
|
|
4
3
|
BatchedUpdateNotification,
|
|
5
4
|
DBAdapter,
|
|
5
|
+
LockContext,
|
|
6
6
|
QueryResult,
|
|
7
7
|
Transaction,
|
|
8
8
|
UpdateNotification,
|
|
@@ -13,7 +13,7 @@ import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
|
13
13
|
import { Schema } from '../db/schema/Schema.js';
|
|
14
14
|
import { BaseObserver } from '../utils/BaseObserver.js';
|
|
15
15
|
import { ControlledExecutor } from '../utils/ControlledExecutor.js';
|
|
16
|
-
import { throttleTrailing } from '../utils/async.js';
|
|
16
|
+
import { EventQueue, throttleTrailing } from '../utils/async.js';
|
|
17
17
|
import {
|
|
18
18
|
ConnectionManager,
|
|
19
19
|
CreateSyncImplementationOptions,
|
|
@@ -46,22 +46,33 @@ import { DEFAULT_WATCH_THROTTLE_MS, WatchCompatibleQuery } from './watched/Watch
|
|
|
46
46
|
import { OnChangeQueryProcessor } from './watched/processors/OnChangeQueryProcessor.js';
|
|
47
47
|
import { WatchedQueryComparator } from './watched/processors/comparators.js';
|
|
48
48
|
import { Mutex } from '../utils/mutex.js';
|
|
49
|
+
import { symbolAsyncIterator } from '../utils/compatibility.js';
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
50
54
|
export interface DisconnectAndClearOptions {
|
|
51
55
|
/** When set to false, data in local-only tables is preserved. */
|
|
52
56
|
clearLocal?: boolean;
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
55
62
|
export interface BasePowerSyncDatabaseOptions extends AdditionalConnectionOptions {
|
|
56
63
|
/** Schema used for the local database. */
|
|
57
64
|
schema: Schema;
|
|
58
65
|
/**
|
|
59
|
-
* @deprecated Use {@link retryDelayMs} instead as this will be removed in future
|
|
66
|
+
* @deprecated Use {@link AdditionalConnectionOptions.retryDelayMs} instead as this will be removed in future
|
|
67
|
+
* releases.
|
|
60
68
|
*/
|
|
61
69
|
retryDelay?: number;
|
|
62
70
|
logger?: ILogger;
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
65
76
|
export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
|
|
66
77
|
/**
|
|
67
78
|
* Source for a SQLite database connection.
|
|
@@ -73,23 +84,38 @@ export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
|
|
|
73
84
|
database: DBAdapter | SQLOpenFactory | SQLOpenOptions;
|
|
74
85
|
}
|
|
75
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
76
90
|
export interface PowerSyncDatabaseOptionsWithDBAdapter extends BasePowerSyncDatabaseOptions {
|
|
77
91
|
database: DBAdapter;
|
|
78
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
79
97
|
export interface PowerSyncDatabaseOptionsWithOpenFactory extends BasePowerSyncDatabaseOptions {
|
|
80
98
|
database: SQLOpenFactory;
|
|
81
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
82
104
|
export interface PowerSyncDatabaseOptionsWithSettings extends BasePowerSyncDatabaseOptions {
|
|
83
105
|
database: SQLOpenOptions;
|
|
84
106
|
}
|
|
85
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
86
111
|
export interface SQLOnChangeOptions {
|
|
87
112
|
signal?: AbortSignal;
|
|
88
113
|
tables?: string[];
|
|
89
114
|
/** The minimum interval between queries. */
|
|
90
115
|
throttleMs?: number;
|
|
91
116
|
/**
|
|
92
|
-
* @deprecated All tables specified in {@link tables} will be watched, including PowerSync tables
|
|
117
|
+
* @deprecated All tables specified in {@link SQLOnChangeOptions.tables} will be watched, including PowerSync tables
|
|
118
|
+
* with prefixes.
|
|
93
119
|
*
|
|
94
120
|
* Allows for watching any SQL table
|
|
95
121
|
* by not removing PowerSync table name prefixes
|
|
@@ -101,6 +127,9 @@ export interface SQLOnChangeOptions {
|
|
|
101
127
|
triggerImmediate?: boolean;
|
|
102
128
|
}
|
|
103
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
104
133
|
export interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
105
134
|
/**
|
|
106
135
|
* Optional comparator which will be used to compare the results of the query.
|
|
@@ -109,20 +138,32 @@ export interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
|
109
138
|
comparator?: WatchedQueryComparator<QueryResult>;
|
|
110
139
|
}
|
|
111
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
112
144
|
export interface WatchOnChangeEvent {
|
|
113
145
|
changedTables: string[];
|
|
114
146
|
}
|
|
115
147
|
|
|
148
|
+
/**
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
116
151
|
export interface WatchHandler {
|
|
117
152
|
onResult: (results: QueryResult) => void;
|
|
118
153
|
onError?: (error: Error) => void;
|
|
119
154
|
}
|
|
120
155
|
|
|
156
|
+
/**
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
121
159
|
export interface WatchOnChangeHandler {
|
|
122
160
|
onChange: (event: WatchOnChangeEvent) => Promise<void> | void;
|
|
123
161
|
onError?: (error: Error) => void;
|
|
124
162
|
}
|
|
125
163
|
|
|
164
|
+
/**
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
126
167
|
export interface PowerSyncDBListener extends StreamingSyncImplementationListener {
|
|
127
168
|
initialized: () => void;
|
|
128
169
|
schemaChanged: (schema: Schema) => void;
|
|
@@ -130,6 +171,9 @@ export interface PowerSyncDBListener extends StreamingSyncImplementationListener
|
|
|
130
171
|
closed: () => Promise<void> | void;
|
|
131
172
|
}
|
|
132
173
|
|
|
174
|
+
/**
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
133
177
|
export interface PowerSyncCloseOptions {
|
|
134
178
|
/**
|
|
135
179
|
* Disconnect the sync stream client if connected.
|
|
@@ -145,21 +189,32 @@ const DEFAULT_DISCONNECT_CLEAR_OPTIONS: DisconnectAndClearOptions = {
|
|
|
145
189
|
clearLocal: true
|
|
146
190
|
};
|
|
147
191
|
|
|
192
|
+
/**
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
148
195
|
export const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions = {
|
|
149
196
|
disconnect: true
|
|
150
197
|
};
|
|
151
198
|
|
|
199
|
+
/**
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
152
202
|
export const DEFAULT_POWERSYNC_DB_OPTIONS = {
|
|
153
203
|
retryDelayMs: 5000,
|
|
154
204
|
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
|
|
155
205
|
};
|
|
156
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
157
210
|
export const DEFAULT_CRUD_BATCH_LIMIT = 100;
|
|
158
211
|
|
|
159
212
|
/**
|
|
160
213
|
* Requesting nested or recursive locks can block the application in some circumstances.
|
|
161
214
|
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
162
215
|
* be obtained.
|
|
216
|
+
*
|
|
217
|
+
* @internal
|
|
163
218
|
*/
|
|
164
219
|
export const DEFAULT_LOCK_TIMEOUT_MS = 120_000; // 2 mins
|
|
165
220
|
|
|
@@ -171,6 +226,9 @@ export const isPowerSyncDatabaseOptionsWithSettings = (test: any): test is Power
|
|
|
171
226
|
return typeof test == 'object' && isSQLOpenOptions(test.database);
|
|
172
227
|
};
|
|
173
228
|
|
|
229
|
+
/**
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
174
232
|
export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDBListener> {
|
|
175
233
|
/**
|
|
176
234
|
* Returns true if the connection is closed.
|
|
@@ -368,7 +426,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
368
426
|
/**
|
|
369
427
|
* Wait for the first sync operation to complete.
|
|
370
428
|
*
|
|
371
|
-
* @param request Either an abort signal (after which the promise will complete regardless of
|
|
429
|
+
* @param request - Either an abort signal (after which the promise will complete regardless of
|
|
372
430
|
* whether a full sync was completed) or an object providing an abort signal and a priority target.
|
|
373
431
|
* When a priority target is set, the promise may complete when all buckets with the given (or higher)
|
|
374
432
|
* priorities have been synchronized. This can be earlier than a complete sync.
|
|
@@ -442,7 +500,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
442
500
|
try {
|
|
443
501
|
const { version } = await this.database.get<{ version: string }>('SELECT powersync_rs_version() as version');
|
|
444
502
|
this.sdkVersion = version;
|
|
445
|
-
} catch (e) {
|
|
503
|
+
} catch (e: any) {
|
|
446
504
|
throw new Error(`The powersync extension is not loaded correctly. Details: ${e.message}`);
|
|
447
505
|
}
|
|
448
506
|
let versionInts: number[];
|
|
@@ -450,7 +508,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
450
508
|
versionInts = this.sdkVersion!.split(/[.\/]/)
|
|
451
509
|
.slice(0, 3)
|
|
452
510
|
.map((n) => parseInt(n));
|
|
453
|
-
} catch (e) {
|
|
511
|
+
} catch (e: any) {
|
|
454
512
|
throw new Error(
|
|
455
513
|
`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`
|
|
456
514
|
);
|
|
@@ -554,7 +612,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
554
612
|
/**
|
|
555
613
|
* Close the sync connection.
|
|
556
614
|
*
|
|
557
|
-
* Use {@link connect} to connect again.
|
|
615
|
+
* Use {@link AbstractPowerSyncDatabase.connect} to connect again.
|
|
558
616
|
*/
|
|
559
617
|
async disconnect() {
|
|
560
618
|
return this.connectionManager.disconnect();
|
|
@@ -586,8 +644,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
586
644
|
/**
|
|
587
645
|
* Create a sync stream to query its status or to subscribe to it.
|
|
588
646
|
*
|
|
589
|
-
* @param name The name of the stream to subscribe to.
|
|
590
|
-
* @param params Optional parameters for the stream subscription.
|
|
647
|
+
* @param name - The name of the stream to subscribe to.
|
|
648
|
+
* @param params - Optional parameters for the stream subscription.
|
|
591
649
|
* @returns A {@link SyncStream} instance that can be subscribed to.
|
|
592
650
|
* @experimental Sync streams are currently in alpha.
|
|
593
651
|
*/
|
|
@@ -655,14 +713,14 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
655
713
|
* Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
|
|
656
714
|
* requesting the next batch.
|
|
657
715
|
*
|
|
658
|
-
* Use
|
|
716
|
+
* Use the `limit` parameter to specify the maximum number of updates to return in a single
|
|
659
717
|
* batch.
|
|
660
718
|
*
|
|
661
719
|
* This method does include transaction ids in the result, but does not group
|
|
662
720
|
* data by transaction. One batch may contain data from multiple transactions,
|
|
663
721
|
* and a single transaction may be split over multiple batches.
|
|
664
722
|
*
|
|
665
|
-
* @param limit Maximum number of CRUD entries to include in the batch
|
|
723
|
+
* @param limit - Maximum number of CRUD entries to include in the batch
|
|
666
724
|
* @returns A batch of CRUD operations to upload, or null if there are none
|
|
667
725
|
*/
|
|
668
726
|
async getCrudBatch(limit: number = DEFAULT_CRUD_BATCH_LIMIT): Promise<CrudBatch | null> {
|
|
@@ -698,13 +756,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
698
756
|
* Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
|
|
699
757
|
* requesting the next transaction.
|
|
700
758
|
*
|
|
701
|
-
* Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
|
|
759
|
+
* Unlike {@link AbstractPowerSyncDatabase.getCrudBatch}, this only returns data from a single transaction at a time.
|
|
702
760
|
* All data for the transaction is loaded into memory.
|
|
703
761
|
*
|
|
704
762
|
* @returns A transaction of CRUD operations to upload, or null if there are none
|
|
705
763
|
*/
|
|
706
764
|
async getNextCrudTransaction(): Promise<CrudTransaction | null> {
|
|
707
|
-
const iterator = this.getCrudTransactions()[
|
|
765
|
+
const iterator = this.getCrudTransactions()[symbolAsyncIterator]();
|
|
708
766
|
return (await iterator.next()).value;
|
|
709
767
|
}
|
|
710
768
|
|
|
@@ -714,7 +772,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
714
772
|
* This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
|
|
715
773
|
* returned iterator is a full transaction containing all local writes made while that transaction was active.
|
|
716
774
|
*
|
|
717
|
-
* Unlike {@link getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
775
|
+
* Unlike {@link AbstractPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
718
776
|
* {@link CrudTransaction.complete}d yet, this iterator can be used to receive multiple transactions. Calling
|
|
719
777
|
* {@link CrudTransaction.complete} will mark that and all prior transactions emitted by the iterator as completed.
|
|
720
778
|
*
|
|
@@ -741,7 +799,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
|
|
|
741
799
|
*/
|
|
742
800
|
getCrudTransactions(): AsyncIterable<CrudTransaction, null> {
|
|
743
801
|
return {
|
|
744
|
-
[
|
|
802
|
+
[symbolAsyncIterator]: () => {
|
|
745
803
|
let lastCrudItemId = -1;
|
|
746
804
|
const sql = `
|
|
747
805
|
WITH RECURSIVE crud_entries AS (
|
|
@@ -817,8 +875,8 @@ SELECT * FROM crud_entries;
|
|
|
817
875
|
* the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
|
|
818
876
|
* Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
|
|
819
877
|
*
|
|
820
|
-
* @param sql The SQL query to execute
|
|
821
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
878
|
+
* @param sql - The SQL query to execute
|
|
879
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
822
880
|
* @returns The query result as an object with structured key-value pairs
|
|
823
881
|
*/
|
|
824
882
|
async execute(sql: string, parameters?: any[]) {
|
|
@@ -829,8 +887,8 @@ SELECT * FROM crud_entries;
|
|
|
829
887
|
* Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
|
|
830
888
|
* This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
|
|
831
889
|
*
|
|
832
|
-
* @param sql The SQL query to execute
|
|
833
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
890
|
+
* @param sql - The SQL query to execute
|
|
891
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
834
892
|
* @returns The raw query result from the underlying database as a nested array of raw values, where each row is
|
|
835
893
|
* represented as an array of column values without field names.
|
|
836
894
|
*/
|
|
@@ -844,8 +902,8 @@ SELECT * FROM crud_entries;
|
|
|
844
902
|
* and optionally return results.
|
|
845
903
|
* This is faster than executing separately with each parameter set.
|
|
846
904
|
*
|
|
847
|
-
* @param sql The SQL query to execute
|
|
848
|
-
* @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
905
|
+
* @param sql - The SQL query to execute
|
|
906
|
+
* @param parameters - Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
849
907
|
* @returns The query result
|
|
850
908
|
*/
|
|
851
909
|
async executeBatch(sql: string, parameters?: any[][]) {
|
|
@@ -856,8 +914,8 @@ SELECT * FROM crud_entries;
|
|
|
856
914
|
/**
|
|
857
915
|
* Execute a read-only query and return results.
|
|
858
916
|
*
|
|
859
|
-
* @param sql The SQL query to execute
|
|
860
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
917
|
+
* @param sql - The SQL query to execute
|
|
918
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
861
919
|
* @returns An array of results
|
|
862
920
|
*/
|
|
863
921
|
async getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
|
|
@@ -868,8 +926,8 @@ SELECT * FROM crud_entries;
|
|
|
868
926
|
/**
|
|
869
927
|
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
|
|
870
928
|
*
|
|
871
|
-
* @param sql The SQL query to execute
|
|
872
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
929
|
+
* @param sql - The SQL query to execute
|
|
930
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
873
931
|
* @returns The first result if found, or null if no results are returned
|
|
874
932
|
*/
|
|
875
933
|
async getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {
|
|
@@ -880,8 +938,8 @@ SELECT * FROM crud_entries;
|
|
|
880
938
|
/**
|
|
881
939
|
* Execute a read-only query and return the first result, error if the ResultSet is empty.
|
|
882
940
|
*
|
|
883
|
-
* @param sql The SQL query to execute
|
|
884
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
941
|
+
* @param sql - The SQL query to execute
|
|
942
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
885
943
|
* @returns The first result matching the query
|
|
886
944
|
* @throws Error if no rows are returned
|
|
887
945
|
*/
|
|
@@ -892,18 +950,18 @@ SELECT * FROM crud_entries;
|
|
|
892
950
|
|
|
893
951
|
/**
|
|
894
952
|
* Takes a read lock, without starting a transaction.
|
|
895
|
-
* In most cases, {@link readTransaction} should be used instead.
|
|
953
|
+
* In most cases, {@link AbstractPowerSyncDatabase.readTransaction} should be used instead.
|
|
896
954
|
*/
|
|
897
|
-
async readLock<T>(callback: (db:
|
|
955
|
+
async readLock<T>(callback: (db: LockContext) => Promise<T>) {
|
|
898
956
|
await this.waitForReady();
|
|
899
957
|
return this.database.readLock(callback);
|
|
900
958
|
}
|
|
901
959
|
|
|
902
960
|
/**
|
|
903
961
|
* Takes a global lock, without starting a transaction.
|
|
904
|
-
* In most cases, {@link writeTransaction} should be used instead.
|
|
962
|
+
* In most cases, {@link AbstractPowerSyncDatabase.writeTransaction} should be used instead.
|
|
905
963
|
*/
|
|
906
|
-
async writeLock<T>(callback: (db:
|
|
964
|
+
async writeLock<T>(callback: (db: LockContext) => Promise<T>) {
|
|
907
965
|
await this.waitForReady();
|
|
908
966
|
return this.database.writeLock(callback);
|
|
909
967
|
}
|
|
@@ -913,8 +971,8 @@ SELECT * FROM crud_entries;
|
|
|
913
971
|
* Read transactions can run concurrently to a write transaction.
|
|
914
972
|
* Changes from any write transaction are not visible to read transactions started before it.
|
|
915
973
|
*
|
|
916
|
-
* @param callback Function to execute within the transaction
|
|
917
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
974
|
+
* @param callback - Function to execute within the transaction
|
|
975
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
918
976
|
* @returns The result of the callback
|
|
919
977
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
920
978
|
*/
|
|
@@ -938,8 +996,8 @@ SELECT * FROM crud_entries;
|
|
|
938
996
|
* This takes a global lock - only one write transaction can execute against the database at a time.
|
|
939
997
|
* Statements within the transaction must be done on the provided {@link Transaction} interface.
|
|
940
998
|
*
|
|
941
|
-
* @param callback Function to execute within the transaction
|
|
942
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
999
|
+
* @param callback - Function to execute within the transaction
|
|
1000
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
943
1001
|
* @returns The result of the callback
|
|
944
1002
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
945
1003
|
*/
|
|
@@ -959,8 +1017,8 @@ SELECT * FROM crud_entries;
|
|
|
959
1017
|
}
|
|
960
1018
|
|
|
961
1019
|
/**
|
|
962
|
-
* This version of `watch` uses
|
|
963
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link watchWithCallback}.
|
|
1020
|
+
* This version of `watch` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator}.
|
|
1021
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.watchWithCallback}.
|
|
964
1022
|
*
|
|
965
1023
|
* @example
|
|
966
1024
|
* ```javascript
|
|
@@ -976,7 +1034,7 @@ SELECT * FROM crud_entries;
|
|
|
976
1034
|
*/
|
|
977
1035
|
watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
978
1036
|
/**
|
|
979
|
-
* See {@link watchWithCallback}.
|
|
1037
|
+
* See {@link AbstractPowerSyncDatabase.watchWithCallback}.
|
|
980
1038
|
*
|
|
981
1039
|
* @example
|
|
982
1040
|
* ```javascript
|
|
@@ -1037,7 +1095,7 @@ SELECT * FROM crud_entries;
|
|
|
1037
1095
|
parameters
|
|
1038
1096
|
}),
|
|
1039
1097
|
execute: async ({ sql, parameters }) => {
|
|
1040
|
-
const result = await this.getAll(sql, parameters);
|
|
1098
|
+
const result = await this.getAll<Record<string, any>>(sql, parameters);
|
|
1041
1099
|
return mapper ? result.map(mapper) : (result as RowType[]);
|
|
1042
1100
|
}
|
|
1043
1101
|
};
|
|
@@ -1068,15 +1126,15 @@ SELECT * FROM crud_entries;
|
|
|
1068
1126
|
|
|
1069
1127
|
/**
|
|
1070
1128
|
* Execute a read query every time the source tables are modified.
|
|
1071
|
-
* Use {@link
|
|
1129
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
1072
1130
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
1073
1131
|
*
|
|
1074
1132
|
* Note that the `onChange` callback member of the handler is required.
|
|
1075
1133
|
*
|
|
1076
|
-
* @param sql The SQL query to execute
|
|
1077
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
1078
|
-
* @param handler Callbacks for handling results and errors
|
|
1079
|
-
* @param options Options for configuring watch behavior
|
|
1134
|
+
* @param sql - The SQL query to execute
|
|
1135
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
1136
|
+
* @param handler - Callbacks for handling results and errors
|
|
1137
|
+
* @param options - Options for configuring watch behavior
|
|
1080
1138
|
*/
|
|
1081
1139
|
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void {
|
|
1082
1140
|
const { onResult, onError = (e: Error) => this.logger.error(e) } = handler ?? {};
|
|
@@ -1090,7 +1148,7 @@ SELECT * FROM crud_entries;
|
|
|
1090
1148
|
const watchedQuery = new OnChangeQueryProcessor({
|
|
1091
1149
|
db: this,
|
|
1092
1150
|
comparator,
|
|
1093
|
-
placeholderData: null,
|
|
1151
|
+
placeholderData: null as unknown as QueryResult, // FIXME
|
|
1094
1152
|
watchOptions: {
|
|
1095
1153
|
query: {
|
|
1096
1154
|
compile: () => ({
|
|
@@ -1126,31 +1184,27 @@ SELECT * FROM crud_entries;
|
|
|
1126
1184
|
|
|
1127
1185
|
/**
|
|
1128
1186
|
* Execute a read query every time the source tables are modified.
|
|
1129
|
-
* Use {@link
|
|
1187
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
1130
1188
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
1131
1189
|
*
|
|
1132
|
-
* @param sql The SQL query to execute
|
|
1133
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
1134
|
-
* @param options Options for configuring watch behavior
|
|
1190
|
+
* @param sql - The SQL query to execute
|
|
1191
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
1192
|
+
* @param options - Options for configuring watch behavior
|
|
1135
1193
|
* @returns An AsyncIterable that yields QueryResults whenever the data changes
|
|
1136
1194
|
*/
|
|
1137
1195
|
watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult> {
|
|
1138
|
-
return
|
|
1196
|
+
return EventQueue.queueBasedAsyncIterable((queue, abort) => {
|
|
1139
1197
|
const handler: WatchHandler = {
|
|
1140
1198
|
onResult: (result) => {
|
|
1141
|
-
|
|
1199
|
+
queue.notify(result);
|
|
1142
1200
|
},
|
|
1143
1201
|
onError: (error) => {
|
|
1144
|
-
|
|
1202
|
+
queue.notifyError(error);
|
|
1145
1203
|
}
|
|
1146
1204
|
};
|
|
1147
1205
|
|
|
1148
|
-
this.watchWithCallback(sql, parameters, handler, options);
|
|
1149
|
-
|
|
1150
|
-
options?.signal?.addEventListener('abort', () => {
|
|
1151
|
-
eventOptions.stop();
|
|
1152
|
-
});
|
|
1153
|
-
});
|
|
1206
|
+
this.watchWithCallback(sql, parameters, handler, { ...options, signal: abort });
|
|
1207
|
+
}, options?.signal);
|
|
1154
1208
|
}
|
|
1155
1209
|
|
|
1156
1210
|
/**
|
|
@@ -1158,9 +1212,9 @@ SELECT * FROM crud_entries;
|
|
|
1158
1212
|
* If tables are specified in the options, those are used directly.
|
|
1159
1213
|
* Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
|
|
1160
1214
|
*
|
|
1161
|
-
* @param sql The SQL query to analyze
|
|
1162
|
-
* @param parameters Optional parameters for the SQL query
|
|
1163
|
-
* @param options Optional watch options that may contain explicit table list
|
|
1215
|
+
* @param sql - The SQL query to analyze
|
|
1216
|
+
* @param parameters - Optional parameters for the SQL query
|
|
1217
|
+
* @param options - Optional watch options that may contain explicit table list
|
|
1164
1218
|
* @returns Array of table names that the query depends on
|
|
1165
1219
|
*/
|
|
1166
1220
|
async resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]> {
|
|
@@ -1183,8 +1237,8 @@ SELECT * FROM crud_entries;
|
|
|
1183
1237
|
}
|
|
1184
1238
|
|
|
1185
1239
|
/**
|
|
1186
|
-
* This version of `onChange` uses
|
|
1187
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link onChangeWithCallback}.
|
|
1240
|
+
* This version of `onChange` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithAsyncGenerator}.
|
|
1241
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
|
|
1188
1242
|
*
|
|
1189
1243
|
* @example
|
|
1190
1244
|
* ```javascript
|
|
@@ -1197,7 +1251,7 @@ SELECT * FROM crud_entries;
|
|
|
1197
1251
|
*/
|
|
1198
1252
|
onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
1199
1253
|
/**
|
|
1200
|
-
* See {@link onChangeWithCallback}.
|
|
1254
|
+
* See {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
|
|
1201
1255
|
*
|
|
1202
1256
|
* @example
|
|
1203
1257
|
* ```javascript
|
|
@@ -1230,13 +1284,13 @@ SELECT * FROM crud_entries;
|
|
|
1230
1284
|
/**
|
|
1231
1285
|
* Invoke the provided callback on any changes to any of the specified tables.
|
|
1232
1286
|
*
|
|
1233
|
-
* This is preferred over {@link watchWithCallback} when multiple queries need to be performed
|
|
1287
|
+
* This is preferred over {@link AbstractPowerSyncDatabase.watchWithCallback} when multiple queries need to be performed
|
|
1234
1288
|
* together when data is changed.
|
|
1235
1289
|
*
|
|
1236
1290
|
* Note that the `onChange` callback member of the handler is required.
|
|
1237
1291
|
*
|
|
1238
|
-
* @param handler Callbacks for handling change events and errors
|
|
1239
|
-
* @param options Options for configuring watch behavior
|
|
1292
|
+
* @param handler - Callbacks for handling change events and errors
|
|
1293
|
+
* @param options - Options for configuring watch behavior
|
|
1240
1294
|
* @returns A dispose function to stop watching for changes
|
|
1241
1295
|
*/
|
|
1242
1296
|
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void {
|
|
@@ -1275,7 +1329,7 @@ SELECT * FROM crud_entries;
|
|
|
1275
1329
|
try {
|
|
1276
1330
|
this.processTableUpdates(update, changedTables);
|
|
1277
1331
|
flushTableUpdates();
|
|
1278
|
-
} catch (error) {
|
|
1332
|
+
} catch (error: any) {
|
|
1279
1333
|
onError?.(error);
|
|
1280
1334
|
}
|
|
1281
1335
|
}
|
|
@@ -1292,37 +1346,30 @@ SELECT * FROM crud_entries;
|
|
|
1292
1346
|
/**
|
|
1293
1347
|
* Create a Stream of changes to any of the specified tables.
|
|
1294
1348
|
*
|
|
1295
|
-
* This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be
|
|
1296
|
-
* together when data is changed.
|
|
1297
|
-
*
|
|
1298
|
-
* Note: do not declare this as `async *onChange` as it will not work in React Native.
|
|
1349
|
+
* This is preferred over {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator} when multiple queries need to be
|
|
1350
|
+
* performed together when data is changed.
|
|
1299
1351
|
*
|
|
1300
|
-
* @param options Options for configuring watch behavior
|
|
1352
|
+
* @param options - Options for configuring watch behavior
|
|
1301
1353
|
* @returns An AsyncIterable that yields change events whenever the specified tables change
|
|
1302
1354
|
*/
|
|
1355
|
+
// Note: do not declare this as `async *onChange` as it will not work in React Native.
|
|
1303
1356
|
onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent> {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
return new EventIterator<WatchOnChangeEvent>((eventOptions) => {
|
|
1307
|
-
const dispose = this.onChangeWithCallback(
|
|
1357
|
+
return EventQueue.queueBasedAsyncIterable((queue, abort) => {
|
|
1358
|
+
this.onChangeWithCallback(
|
|
1308
1359
|
{
|
|
1309
1360
|
onChange: (event): void => {
|
|
1310
|
-
|
|
1361
|
+
queue.notify(event);
|
|
1311
1362
|
},
|
|
1312
1363
|
onError: (error) => {
|
|
1313
|
-
|
|
1364
|
+
queue.notifyError(error);
|
|
1314
1365
|
}
|
|
1315
1366
|
},
|
|
1316
|
-
options
|
|
1367
|
+
{ ...options, signal: abort }
|
|
1317
1368
|
);
|
|
1318
1369
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
});
|
|
1323
|
-
|
|
1324
|
-
return () => dispose();
|
|
1325
|
-
});
|
|
1370
|
+
// Note: We don't have to track the dispose function returned by onChangeWithCallback, it cleans up
|
|
1371
|
+
// after the abort signal completes.
|
|
1372
|
+
}, options?.signal);
|
|
1326
1373
|
}
|
|
1327
1374
|
|
|
1328
1375
|
private handleTableChanges(
|
|
@@ -1352,9 +1399,6 @@ SELECT * FROM crud_entries;
|
|
|
1352
1399
|
}
|
|
1353
1400
|
}
|
|
1354
1401
|
|
|
1355
|
-
/**
|
|
1356
|
-
* @ignore
|
|
1357
|
-
*/
|
|
1358
1402
|
private async executeReadOnly(sql: string, params?: any[]) {
|
|
1359
1403
|
await this.waitForReady();
|
|
1360
1404
|
return this.database.readLock((tx) => tx.execute(sql, params));
|
|
@@ -4,11 +4,17 @@ import { Schema } from '../db/schema/Schema.js';
|
|
|
4
4
|
import { AbstractPowerSyncDatabase, PowerSyncDatabaseOptions } from './AbstractPowerSyncDatabase.js';
|
|
5
5
|
import { SQLOpenOptions } from './SQLOpenFactory.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions>, SQLOpenOptions {
|
|
8
11
|
/** Schema used for the local database. */
|
|
9
12
|
schema: Schema;
|
|
10
13
|
}
|
|
11
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
12
18
|
export abstract class AbstractPowerSyncDatabaseOpenFactory {
|
|
13
19
|
constructor(protected options: PowerSyncOpenFactoryOptions) {
|
|
14
20
|
options.logger = options.logger ?? Logger.get(`PowerSync ${this.options.dbFilename}`);
|
|
@@ -36,6 +36,9 @@ export interface CreateSyncImplementationOptions extends AdditionalConnectionOpt
|
|
|
36
36
|
subscriptions: SubscribedStream[];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
39
42
|
export interface InternalSubscriptionAdapter {
|
|
40
43
|
firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
|
|
41
44
|
resolveOfflineSyncStatus(): Promise<void>;
|
|
@@ -243,7 +246,7 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
|
|
|
243
246
|
/**
|
|
244
247
|
* Close the sync connection.
|
|
245
248
|
*
|
|
246
|
-
* Use {@link connect} to connect again.
|
|
249
|
+
* Use {@link ConnectionManager.connect} to connect again.
|
|
247
250
|
*/
|
|
248
251
|
async disconnect() {
|
|
249
252
|
// This will help abort pending connects
|
package/src/client/Query.ts
CHANGED
|
@@ -8,12 +8,16 @@ import { WatchedQueryOptions } from './watched/WatchedQuery.js';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Query parameters for {@link ArrayQueryDefinition#parameters}
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
11
13
|
*/
|
|
12
14
|
export type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Options for building a query with {@link AbstractPowerSyncDatabase#query}.
|
|
16
18
|
* This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
17
21
|
*/
|
|
18
22
|
export interface ArrayQueryDefinition<RowType = unknown> {
|
|
19
23
|
sql: string;
|
|
@@ -33,6 +37,8 @@ export interface ArrayQueryDefinition<RowType = unknown> {
|
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* Options for {@link Query#watch}.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
36
42
|
*/
|
|
37
43
|
export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
38
44
|
/**
|
|
@@ -59,6 +65,9 @@ export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOption
|
|
|
59
65
|
placeholderData?: RowType[];
|
|
60
66
|
}
|
|
61
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
62
71
|
export interface Query<RowType> {
|
|
63
72
|
/**
|
|
64
73
|
* Creates a {@link WatchedQuery} which watches and emits results of the linked query.
|