@powersync/common 1.53.1 → 1.54.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 +560 -353
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +560 -353
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +560 -353
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +560 -353
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +733 -198
- 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 +61 -20
- 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 -58
- package/lib/client/AbstractPowerSyncDatabase.js +59 -48
- 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 +15 -1
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +61 -14
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +60 -47
- 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 +13 -7
- package/lib/utils/async.js +38 -24
- package/lib/utils/async.js.map +1 -1
- 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 -2
- package/src/attachments/AttachmentContext.ts +7 -6
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +71 -23
- 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 +117 -62
- 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 +30 -1
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +86 -59
- 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 +51 -24
- package/src/utils/mutex.ts +12 -0
- package/src/utils/parseQuery.ts +6 -0
- package/src/utils/stream_transform.ts +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,13 +2,25 @@ import Logger, { ILogger, ILogLevel } from 'js-logger';
|
|
|
2
2
|
export { GlobalLogger, ILogHandler, ILogLevel, ILogger, ILoggerOpts } from 'js-logger';
|
|
3
3
|
import { fetch } from 'cross-fetch';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
5
8
|
interface Disposable {
|
|
6
9
|
dispose: () => Promise<void> | void;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
8
14
|
type BaseListener = Record<string, ((...event: any) => any) | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
9
18
|
interface BaseObserverInterface<T extends BaseListener> {
|
|
10
19
|
registerListener(listener: Partial<T>): () => void;
|
|
11
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
12
24
|
declare class BaseObserver<T extends BaseListener = BaseListener> implements BaseObserverInterface<T> {
|
|
13
25
|
protected listeners: Set<Partial<T>>;
|
|
14
26
|
constructor();
|
|
@@ -32,6 +44,8 @@ declare class BaseObserver<T extends BaseListener = BaseListener> implements Bas
|
|
|
32
44
|
*/
|
|
33
45
|
/**
|
|
34
46
|
* Object returned by SQL Query executions.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
35
49
|
*/
|
|
36
50
|
type QueryResult = {
|
|
37
51
|
/** Represents the auto-generated row id if applicable. */
|
|
@@ -51,12 +65,15 @@ type QueryResult = {
|
|
|
51
65
|
/** The length of the dataset */
|
|
52
66
|
length: number;
|
|
53
67
|
/** A convenience function to acess the index based the row object
|
|
54
|
-
* @param idx the row index
|
|
68
|
+
* @param idx - the row index
|
|
55
69
|
* @returns the row structure identified by column names
|
|
56
70
|
*/
|
|
57
71
|
item: (idx: number) => any;
|
|
58
72
|
};
|
|
59
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
60
77
|
interface DBGetUtils {
|
|
61
78
|
/** Execute a read-only query and return results. */
|
|
62
79
|
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
@@ -65,6 +82,9 @@ interface DBGetUtils {
|
|
|
65
82
|
/** Execute a read-only query and return the first result, error if the ResultSet is empty. */
|
|
66
83
|
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
67
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
68
88
|
interface SqlExecutor {
|
|
69
89
|
/** Execute a single write statement. */
|
|
70
90
|
execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
|
|
@@ -76,15 +96,22 @@ interface SqlExecutor {
|
|
|
76
96
|
*
|
|
77
97
|
* Example result:
|
|
78
98
|
*
|
|
79
|
-
* ```
|
|
99
|
+
* ```JavaScript
|
|
100
|
+
* [ [ '1', 'list 1', '33', 'Post content', '1' ] ]
|
|
101
|
+
* ```
|
|
80
102
|
*
|
|
81
103
|
* Where as `execute`'s `rows._array` would have been:
|
|
82
104
|
*
|
|
83
|
-
* ```
|
|
105
|
+
* ```JavaScript
|
|
106
|
+
* [ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]
|
|
107
|
+
* ```
|
|
84
108
|
*/
|
|
85
109
|
executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
|
|
86
110
|
executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
|
|
87
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
88
115
|
interface LockContext extends SqlExecutor, DBGetUtils {
|
|
89
116
|
/**
|
|
90
117
|
* How the connection has been opened.
|
|
@@ -97,7 +124,9 @@ interface LockContext extends SqlExecutor, DBGetUtils {
|
|
|
97
124
|
connectionType?: 'writer' | 'queryOnly' | 'readOnly';
|
|
98
125
|
}
|
|
99
126
|
/**
|
|
100
|
-
* Implements {@link DBGetUtils} on a {@link
|
|
127
|
+
* Implements {@link DBGetUtils} on a {@link SqlExecutor}.
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
101
130
|
*/
|
|
102
131
|
declare function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omit<SqlExecutor, 'executeBatch'>>(Base: TBase): {
|
|
103
132
|
new (...args: any[]): {
|
|
@@ -109,6 +138,9 @@ declare function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Om
|
|
|
109
138
|
executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
|
|
110
139
|
};
|
|
111
140
|
} & TBase;
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
112
144
|
interface Transaction extends LockContext {
|
|
113
145
|
/** Commit multiple changes to the local DB using the Transaction context. */
|
|
114
146
|
commit: () => Promise<QueryResult>;
|
|
@@ -117,27 +149,40 @@ interface Transaction extends LockContext {
|
|
|
117
149
|
}
|
|
118
150
|
/**
|
|
119
151
|
* Update table operation numbers from SQLite
|
|
152
|
+
*
|
|
153
|
+
* @public
|
|
120
154
|
*/
|
|
121
155
|
declare enum RowUpdateType {
|
|
122
156
|
SQLITE_INSERT = 18,
|
|
123
157
|
SQLITE_DELETE = 9,
|
|
124
158
|
SQLITE_UPDATE = 23
|
|
125
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
126
163
|
interface TableUpdateOperation {
|
|
127
164
|
opType: RowUpdateType;
|
|
128
165
|
rowId: number;
|
|
129
166
|
}
|
|
130
167
|
/**
|
|
131
168
|
* Notification of an update to one or more tables, for the purpose of realtime change notifications.
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
132
171
|
*/
|
|
133
172
|
interface UpdateNotification extends TableUpdateOperation {
|
|
134
173
|
table: string;
|
|
135
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
136
178
|
interface BatchedUpdateNotification {
|
|
137
179
|
rawUpdates: UpdateNotification[];
|
|
138
180
|
tables: string[];
|
|
139
181
|
groupedUpdates: Record<string, TableUpdateOperation[]>;
|
|
140
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
141
186
|
interface DBAdapterListener extends BaseListener {
|
|
142
187
|
/**
|
|
143
188
|
* Listener for table updates.
|
|
@@ -147,9 +192,15 @@ interface DBAdapterListener extends BaseListener {
|
|
|
147
192
|
*/
|
|
148
193
|
tablesUpdated: (updateNotification: BatchedUpdateNotification | UpdateNotification) => void;
|
|
149
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* @public
|
|
197
|
+
*/
|
|
150
198
|
interface DBLockOptions {
|
|
151
199
|
timeoutMs?: number;
|
|
152
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
153
204
|
interface ConnectionPool extends BaseObserverInterface<DBAdapterListener> {
|
|
154
205
|
name: string;
|
|
155
206
|
close: () => void | Promise<void>;
|
|
@@ -160,13 +211,18 @@ interface ConnectionPool extends BaseObserverInterface<DBAdapterListener> {
|
|
|
160
211
|
*/
|
|
161
212
|
refreshSchema: () => Promise<void>;
|
|
162
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
163
217
|
interface DBAdapter extends ConnectionPool, SqlExecutor, DBGetUtils {
|
|
164
218
|
readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
165
219
|
writeTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
166
220
|
}
|
|
167
221
|
/**
|
|
168
|
-
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool
|
|
169
|
-
* {@link ConnectionPool
|
|
222
|
+
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool#readLock} and
|
|
223
|
+
* {@link ConnectionPool#writeLock}.
|
|
224
|
+
*
|
|
225
|
+
* @internal
|
|
170
226
|
*/
|
|
171
227
|
declare function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase): {
|
|
172
228
|
new (...args: any[]): {
|
|
@@ -189,17 +245,27 @@ declare function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => Con
|
|
|
189
245
|
registerListener(listener: Partial<DBAdapterListener>): () => void;
|
|
190
246
|
};
|
|
191
247
|
} & TBase;
|
|
248
|
+
/**
|
|
249
|
+
* @internal
|
|
250
|
+
*/
|
|
192
251
|
declare function isBatchedUpdateNotification(update: BatchedUpdateNotification | UpdateNotification): update is BatchedUpdateNotification;
|
|
252
|
+
/**
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
193
255
|
declare function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification): string[];
|
|
194
256
|
|
|
195
257
|
/**
|
|
196
258
|
* 64-bit unsigned integer stored as a string in base-10.
|
|
197
259
|
*
|
|
198
260
|
* Not sortable as a string.
|
|
261
|
+
*
|
|
262
|
+
* @public
|
|
199
263
|
*/
|
|
200
264
|
type OpId = string;
|
|
201
265
|
/**
|
|
202
266
|
* Type of local change.
|
|
267
|
+
*
|
|
268
|
+
* @public
|
|
203
269
|
*/
|
|
204
270
|
declare enum UpdateType {
|
|
205
271
|
/** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
|
|
@@ -209,6 +275,9 @@ declare enum UpdateType {
|
|
|
209
275
|
/** Delete existing row. Contains the id. Generated by DELETE statements. */
|
|
210
276
|
DELETE = "DELETE"
|
|
211
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* @internal
|
|
280
|
+
*/
|
|
212
281
|
type CrudEntryJSON = {
|
|
213
282
|
id: string;
|
|
214
283
|
data: string;
|
|
@@ -229,6 +298,8 @@ type CrudEntryOutputJSON = {
|
|
|
229
298
|
};
|
|
230
299
|
/**
|
|
231
300
|
* A single client-side change.
|
|
301
|
+
*
|
|
302
|
+
* @public
|
|
232
303
|
*/
|
|
233
304
|
declare class CrudEntry {
|
|
234
305
|
/**
|
|
@@ -289,6 +360,8 @@ declare class CrudEntry {
|
|
|
289
360
|
|
|
290
361
|
/**
|
|
291
362
|
* A batch of client-side changes.
|
|
363
|
+
*
|
|
364
|
+
* @public
|
|
292
365
|
*/
|
|
293
366
|
declare class CrudBatch {
|
|
294
367
|
/**
|
|
@@ -318,6 +391,9 @@ declare class CrudBatch {
|
|
|
318
391
|
complete: (writeCheckpoint?: string) => Promise<void>);
|
|
319
392
|
}
|
|
320
393
|
|
|
394
|
+
/**
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
321
397
|
declare enum PSInternalTable {
|
|
322
398
|
DATA = "ps_data",
|
|
323
399
|
CRUD = "ps_crud",
|
|
@@ -325,6 +401,9 @@ declare enum PSInternalTable {
|
|
|
325
401
|
OPLOG = "ps_oplog",
|
|
326
402
|
UNTYPED = "ps_untyped"
|
|
327
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* @internal
|
|
406
|
+
*/
|
|
328
407
|
declare enum PowerSyncControlCommand {
|
|
329
408
|
PROCESS_TEXT_LINE = "line_text",
|
|
330
409
|
PROCESS_BSON_LINE = "line_binary",
|
|
@@ -338,9 +417,15 @@ declare enum PowerSyncControlCommand {
|
|
|
338
417
|
*/
|
|
339
418
|
CONNECTION_STATE = "connection"
|
|
340
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* @internal
|
|
422
|
+
*/
|
|
341
423
|
interface BucketStorageListener extends BaseListener {
|
|
342
424
|
crudUpdate: () => void;
|
|
343
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* @internal
|
|
428
|
+
*/
|
|
344
429
|
interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
|
|
345
430
|
init(): Promise<void>;
|
|
346
431
|
hasMigratedSubkeys(): Promise<boolean>;
|
|
@@ -360,6 +445,9 @@ interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListen
|
|
|
360
445
|
control(op: PowerSyncControlCommand, payload: string | Uint8Array | null): Promise<string>;
|
|
361
446
|
}
|
|
362
447
|
|
|
448
|
+
/**
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
363
451
|
interface PowerSyncCredentials {
|
|
364
452
|
endpoint: string;
|
|
365
453
|
token: string;
|
|
@@ -370,17 +458,28 @@ interface PowerSyncCredentials {
|
|
|
370
458
|
* An async iterator that can't be cancelled.
|
|
371
459
|
*
|
|
372
460
|
* To keep data flow simple, we always pass an explicit cancellation token when subscribing to async streams. Once the
|
|
373
|
-
*
|
|
461
|
+
* `AbortSignal` aborts, iterators are supposed to clean up and then emit a final `{done: true}` event. This means
|
|
374
462
|
* that there's no way to distinguish between streams that have completed normally and streams that have been cancelled,
|
|
375
463
|
* but that is acceptable for our uses of this.
|
|
464
|
+
*
|
|
465
|
+
* @internal
|
|
376
466
|
*/
|
|
377
467
|
type SimpleAsyncIterator<T> = Pick<AsyncIterator<T>, 'next'>;
|
|
378
468
|
|
|
469
|
+
/**
|
|
470
|
+
* @internal
|
|
471
|
+
*/
|
|
379
472
|
type RemoteConnector = {
|
|
380
473
|
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
381
474
|
invalidateCredentials?: () => void;
|
|
382
475
|
};
|
|
476
|
+
/**
|
|
477
|
+
* @internal
|
|
478
|
+
*/
|
|
383
479
|
declare const DEFAULT_REMOTE_LOGGER: Logger.ILogger;
|
|
480
|
+
/**
|
|
481
|
+
* @internal
|
|
482
|
+
*/
|
|
384
483
|
type SyncStreamOptions = {
|
|
385
484
|
path: string;
|
|
386
485
|
data: unknown;
|
|
@@ -388,6 +487,9 @@ type SyncStreamOptions = {
|
|
|
388
487
|
abortSignal: AbortSignal;
|
|
389
488
|
fetchOptions?: Request;
|
|
390
489
|
};
|
|
490
|
+
/**
|
|
491
|
+
* @public
|
|
492
|
+
*/
|
|
391
493
|
declare enum FetchStrategy {
|
|
392
494
|
/**
|
|
393
495
|
* Queues multiple sync events before processing, reducing round-trips.
|
|
@@ -400,19 +502,30 @@ declare enum FetchStrategy {
|
|
|
400
502
|
*/
|
|
401
503
|
Sequential = "sequential"
|
|
402
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* @internal
|
|
507
|
+
*/
|
|
403
508
|
type SocketSyncStreamOptions = SyncStreamOptions & {
|
|
404
509
|
fetchStrategy: FetchStrategy;
|
|
405
510
|
};
|
|
511
|
+
/**
|
|
512
|
+
* @internal
|
|
513
|
+
*/
|
|
406
514
|
type FetchImplementation = typeof fetch;
|
|
407
515
|
/**
|
|
408
516
|
* Class wrapper for providing a fetch implementation.
|
|
409
517
|
* The class wrapper is used to distinguish the fetchImplementation
|
|
410
518
|
* option in [AbstractRemoteOptions] from the general fetch method
|
|
411
519
|
* which is typeof "function"
|
|
520
|
+
*
|
|
521
|
+
* @internal
|
|
412
522
|
*/
|
|
413
523
|
declare class FetchImplementationProvider {
|
|
414
524
|
getFetch(): FetchImplementation;
|
|
415
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* @internal
|
|
528
|
+
*/
|
|
416
529
|
type AbstractRemoteOptions = {
|
|
417
530
|
/**
|
|
418
531
|
* Transforms the PowerSync base URL which might contain
|
|
@@ -434,7 +547,13 @@ type AbstractRemoteOptions = {
|
|
|
434
547
|
*/
|
|
435
548
|
fetchOptions?: {};
|
|
436
549
|
};
|
|
550
|
+
/**
|
|
551
|
+
* @internal
|
|
552
|
+
*/
|
|
437
553
|
declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
|
|
554
|
+
/**
|
|
555
|
+
* @internal
|
|
556
|
+
*/
|
|
438
557
|
declare abstract class AbstractRemote {
|
|
439
558
|
protected connector: RemoteConnector;
|
|
440
559
|
protected logger: ILogger;
|
|
@@ -519,7 +638,7 @@ declare abstract class AbstractRemote {
|
|
|
519
638
|
* Posts a `/sync/stream` request.
|
|
520
639
|
*
|
|
521
640
|
* Depending on the `Content-Type` of the response, this returns strings for sync lines or encoded BSON documents as
|
|
522
|
-
*
|
|
641
|
+
* `Uint8Array`s.
|
|
523
642
|
*/
|
|
524
643
|
fetchStream(options: SyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array | string>>;
|
|
525
644
|
}
|
|
@@ -529,16 +648,29 @@ interface JSONObject {
|
|
|
529
648
|
[key: string]: JSONValue;
|
|
530
649
|
}
|
|
531
650
|
type JSONArray = JSONValue[];
|
|
651
|
+
/**
|
|
652
|
+
* @public
|
|
653
|
+
*/
|
|
532
654
|
type StreamingSyncRequestParameterType = JSONValue;
|
|
533
655
|
|
|
656
|
+
/**
|
|
657
|
+
* @internal
|
|
658
|
+
*/
|
|
534
659
|
declare enum LockType {
|
|
535
660
|
CRUD = "crud",
|
|
536
661
|
SYNC = "sync"
|
|
537
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* @public
|
|
665
|
+
*/
|
|
538
666
|
declare enum SyncStreamConnectionMethod {
|
|
539
667
|
HTTP = "http",
|
|
540
668
|
WEB_SOCKET = "web-socket"
|
|
541
669
|
}
|
|
670
|
+
/**
|
|
671
|
+
* @deprecated Deprecated since {@link SyncClientImplementation.RUST} is the only option.
|
|
672
|
+
* @public
|
|
673
|
+
*/
|
|
542
674
|
declare enum SyncClientImplementation {
|
|
543
675
|
/**
|
|
544
676
|
* This implementation offloads the sync line decoding and handling into the PowerSync
|
|
@@ -549,8 +681,8 @@ declare enum SyncClientImplementation {
|
|
|
549
681
|
* ## Compatibility warning
|
|
550
682
|
*
|
|
551
683
|
* The Rust sync client stores sync data in a format that is slightly different than the one used
|
|
552
|
-
* by the old JavaScript client. When adopting the {@link RUST} client on existing databases,
|
|
553
|
-
* migrate the format automatically.
|
|
684
|
+
* by the old JavaScript client. When adopting the {@link SyncClientImplementation.RUST} client on existing databases,
|
|
685
|
+
* the PowerSync SDK will migrate the format automatically.
|
|
554
686
|
*
|
|
555
687
|
* SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
|
|
556
688
|
* implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
|
|
@@ -560,16 +692,24 @@ declare enum SyncClientImplementation {
|
|
|
560
692
|
}
|
|
561
693
|
/**
|
|
562
694
|
* The default {@link SyncClientImplementation} to use, {@link SyncClientImplementation.RUST}.
|
|
695
|
+
*
|
|
696
|
+
* @deprecated Deprecated since {@link SyncClientImplementation.RUST} is the only option.
|
|
697
|
+
* @public
|
|
563
698
|
*/
|
|
564
699
|
declare const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.RUST;
|
|
565
700
|
/**
|
|
566
701
|
* Abstract Lock to be implemented by various JS environments
|
|
702
|
+
*
|
|
703
|
+
* @internal
|
|
567
704
|
*/
|
|
568
705
|
interface LockOptions<T> {
|
|
569
706
|
callback: () => Promise<T>;
|
|
570
707
|
type: LockType;
|
|
571
708
|
signal?: AbortSignal;
|
|
572
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* @internal
|
|
712
|
+
*/
|
|
573
713
|
interface AbstractStreamingSyncImplementationOptions extends RequiredAdditionalConnectionOptions {
|
|
574
714
|
adapter: BucketStorageAdapter;
|
|
575
715
|
subscriptions: SubscribedStream[];
|
|
@@ -582,6 +722,9 @@ interface AbstractStreamingSyncImplementationOptions extends RequiredAdditionalC
|
|
|
582
722
|
logger?: ILogger;
|
|
583
723
|
remote: AbstractRemote;
|
|
584
724
|
}
|
|
725
|
+
/**
|
|
726
|
+
* @internal
|
|
727
|
+
*/
|
|
585
728
|
interface StreamingSyncImplementationListener extends BaseListener {
|
|
586
729
|
/**
|
|
587
730
|
* Triggered whenever a status update has been attempted to be made or
|
|
@@ -596,11 +739,16 @@ interface StreamingSyncImplementationListener extends BaseListener {
|
|
|
596
739
|
/**
|
|
597
740
|
* Configurable options to be used when connecting to the PowerSync
|
|
598
741
|
* backend instance.
|
|
742
|
+
*
|
|
743
|
+
* @public
|
|
599
744
|
*/
|
|
600
745
|
type PowerSyncConnectionOptions = Omit<InternalConnectionOptions, 'serializedSchema'>;
|
|
746
|
+
/**
|
|
747
|
+
* @internal
|
|
748
|
+
*/
|
|
601
749
|
interface InternalConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {
|
|
602
750
|
}
|
|
603
|
-
/** @
|
|
751
|
+
/** @public */
|
|
604
752
|
interface BaseConnectionOptions {
|
|
605
753
|
/**
|
|
606
754
|
* A set of metadata to be included in service logs.
|
|
@@ -653,6 +801,9 @@ interface AdditionalConnectionOptions {
|
|
|
653
801
|
interface RequiredAdditionalConnectionOptions extends Required<AdditionalConnectionOptions> {
|
|
654
802
|
subscriptions: SubscribedStream[];
|
|
655
803
|
}
|
|
804
|
+
/**
|
|
805
|
+
* @internal
|
|
806
|
+
*/
|
|
656
807
|
interface StreamingSyncImplementation extends BaseObserverInterface<StreamingSyncImplementationListener>, Disposable {
|
|
657
808
|
/**
|
|
658
809
|
* Connects to the sync service
|
|
@@ -673,33 +824,53 @@ interface StreamingSyncImplementation extends BaseObserverInterface<StreamingSyn
|
|
|
673
824
|
updateSubscriptions(subscriptions: SubscribedStream[]): void;
|
|
674
825
|
markConnectionMayHaveChanged(): void;
|
|
675
826
|
}
|
|
827
|
+
/**
|
|
828
|
+
* @internal
|
|
829
|
+
*/
|
|
676
830
|
declare const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
|
|
831
|
+
/**
|
|
832
|
+
* @internal
|
|
833
|
+
*/
|
|
677
834
|
declare const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
835
|
+
/**
|
|
836
|
+
* @internal
|
|
837
|
+
*/
|
|
678
838
|
declare const DEFAULT_STREAMING_SYNC_OPTIONS: {
|
|
679
839
|
retryDelayMs: number;
|
|
680
840
|
crudUploadThrottleMs: number;
|
|
681
841
|
};
|
|
842
|
+
/**
|
|
843
|
+
* @internal
|
|
844
|
+
*/
|
|
682
845
|
type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
|
|
846
|
+
/**
|
|
847
|
+
* @internal
|
|
848
|
+
*/
|
|
683
849
|
declare const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions;
|
|
850
|
+
/**
|
|
851
|
+
* @internal
|
|
852
|
+
*/
|
|
684
853
|
type SubscribedStream = {
|
|
685
854
|
name: string;
|
|
686
855
|
params: Record<string, any> | null;
|
|
687
856
|
};
|
|
857
|
+
/**
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
688
860
|
declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
|
|
689
861
|
protected options: AbstractStreamingSyncImplementationOptions;
|
|
690
862
|
protected abortController: AbortController | null;
|
|
691
|
-
protected uploadAbortController: AbortController | undefined;
|
|
692
863
|
protected crudUpdateListener?: () => void;
|
|
693
|
-
protected streamingSyncPromise?: Promise<void>;
|
|
864
|
+
protected streamingSyncPromise?: Promise<[void, void]>;
|
|
694
865
|
protected logger: ILogger;
|
|
695
866
|
private activeStreams;
|
|
696
867
|
private connectionMayHaveChanged;
|
|
697
|
-
private
|
|
868
|
+
private crudUploadNotifier;
|
|
698
869
|
private notifyCompletedUploads?;
|
|
699
870
|
private handleActiveStreamsChange?;
|
|
700
871
|
syncStatus: SyncStatus;
|
|
701
|
-
triggerCrudUpload: () => void;
|
|
702
872
|
constructor(options: AbstractStreamingSyncImplementationOptions);
|
|
873
|
+
triggerCrudUpload(): void;
|
|
703
874
|
waitForReady(): Promise<void>;
|
|
704
875
|
waitForStatus(status: SyncStatusOptions): Promise<void>;
|
|
705
876
|
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
@@ -708,16 +879,14 @@ declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<
|
|
|
708
879
|
dispose(): Promise<void>;
|
|
709
880
|
abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
|
|
710
881
|
getWriteCheckpoint(): Promise<string>;
|
|
711
|
-
|
|
882
|
+
private crudUploadLoop;
|
|
883
|
+
private _uploadAllCrud;
|
|
712
884
|
connect(options?: PowerSyncConnectionOptions): Promise<void>;
|
|
713
885
|
disconnect(): Promise<void>;
|
|
714
|
-
|
|
715
|
-
* @deprecated use [connect instead]
|
|
716
|
-
*/
|
|
717
|
-
streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
|
|
886
|
+
private streamingSync;
|
|
718
887
|
markConnectionMayHaveChanged(): void;
|
|
719
888
|
/**
|
|
720
|
-
* Older versions of the JS SDK used to encode subkeys as JSON in
|
|
889
|
+
* Older versions of the JS SDK used to encode subkeys as JSON in `OplogEntry.toJSON`.
|
|
721
890
|
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
722
891
|
* While this is not a problem as long as it's done consistently, it causes issues when a database
|
|
723
892
|
* created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
|
|
@@ -727,7 +896,7 @@ declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<
|
|
|
727
896
|
* migration is only triggered when necessary (for now). The function returns whether the new format
|
|
728
897
|
* should be used, so that the JS SDK is able to write to updated databases.
|
|
729
898
|
*
|
|
730
|
-
* @param requireFixedKeyFormat Whether we require the new format or also support the old one.
|
|
899
|
+
* @param requireFixedKeyFormat - Whether we require the new format or also support the old one.
|
|
731
900
|
* The Rust client requires the new subkey format.
|
|
732
901
|
* @returns Whether the database is now using the new, fixed subkey format.
|
|
733
902
|
*/
|
|
@@ -765,7 +934,10 @@ interface BucketProgress {
|
|
|
765
934
|
}
|
|
766
935
|
|
|
767
936
|
/**
|
|
768
|
-
* A description of a sync stream, consisting of its {@link name} and the
|
|
937
|
+
* A description of a sync stream, consisting of its {@link SyncStreamDescription.name} and the
|
|
938
|
+
* {@link SyncStreamDescription.parameters} used when subscribing.
|
|
939
|
+
*
|
|
940
|
+
* @public
|
|
769
941
|
*/
|
|
770
942
|
interface SyncStreamDescription {
|
|
771
943
|
/**
|
|
@@ -783,6 +955,8 @@ interface SyncStreamDescription {
|
|
|
783
955
|
* Information about a subscribed sync stream.
|
|
784
956
|
*
|
|
785
957
|
* This includes the {@link SyncStreamDescription}, along with information about the current sync status.
|
|
958
|
+
*
|
|
959
|
+
* @public
|
|
786
960
|
*/
|
|
787
961
|
interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
788
962
|
active: boolean;
|
|
@@ -790,15 +964,17 @@ interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
790
964
|
* Whether this stream subscription is included by default, regardless of whether the stream has explicitly been
|
|
791
965
|
* subscribed to or not.
|
|
792
966
|
*
|
|
793
|
-
* It's possible for both {@link isDefault} and
|
|
794
|
-
*
|
|
967
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
968
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
969
|
+
* default stream was subscribed explicitly.
|
|
795
970
|
*/
|
|
796
971
|
isDefault: boolean;
|
|
797
972
|
/**
|
|
798
973
|
* Whether this stream has been subscribed to explicitly.
|
|
799
974
|
*
|
|
800
|
-
* It's possible for both {@link isDefault} and
|
|
801
|
-
*
|
|
975
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
976
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
977
|
+
* default stream was subscribed explicitly.
|
|
802
978
|
*/
|
|
803
979
|
hasExplicitSubscription: boolean;
|
|
804
980
|
/**
|
|
@@ -811,10 +987,13 @@ interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
811
987
|
*/
|
|
812
988
|
hasSynced: boolean;
|
|
813
989
|
/**
|
|
814
|
-
* If {@link hasSynced} is true, the last time data from this stream has been synced.
|
|
990
|
+
* If {@link SyncSubscriptionDescription.hasSynced} is true, the last time data from this stream has been synced.
|
|
815
991
|
*/
|
|
816
992
|
lastSyncedAt: Date | null;
|
|
817
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* @public
|
|
996
|
+
*/
|
|
818
997
|
interface SyncStreamSubscribeOptions {
|
|
819
998
|
/**
|
|
820
999
|
* A "time to live" for this stream subscription, in seconds.
|
|
@@ -834,6 +1013,8 @@ interface SyncStreamSubscribeOptions {
|
|
|
834
1013
|
* A handle to a {@link SyncStreamDescription} that allows subscribing to the stream.
|
|
835
1014
|
*
|
|
836
1015
|
* To obtain an instance of {@link SyncStream}, call {@link AbstractPowerSyncDatabase.syncStream}.
|
|
1016
|
+
*
|
|
1017
|
+
* @public
|
|
837
1018
|
*/
|
|
838
1019
|
interface SyncStream extends SyncStreamDescription {
|
|
839
1020
|
/**
|
|
@@ -842,7 +1023,7 @@ interface SyncStream extends SyncStreamDescription {
|
|
|
842
1023
|
* You should keep a reference to the returned {@link SyncStreamSubscription} object along as you need data for that
|
|
843
1024
|
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
844
1025
|
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
845
|
-
* eventually evict the stream (unless {@link subscribe} is called again).
|
|
1026
|
+
* eventually evict the stream (unless {@link SyncStream.subscribe} is called again).
|
|
846
1027
|
*/
|
|
847
1028
|
subscribe(options?: SyncStreamSubscribeOptions): Promise<SyncStreamSubscription>;
|
|
848
1029
|
/**
|
|
@@ -852,6 +1033,9 @@ interface SyncStream extends SyncStreamDescription {
|
|
|
852
1033
|
*/
|
|
853
1034
|
unsubscribeAll(): Promise<void>;
|
|
854
1035
|
}
|
|
1036
|
+
/**
|
|
1037
|
+
* @public
|
|
1038
|
+
*/
|
|
855
1039
|
interface SyncStreamSubscription extends SyncStreamDescription {
|
|
856
1040
|
/**
|
|
857
1041
|
* A promise that resolves once data from in this sync stream has been synced and applied.
|
|
@@ -870,6 +1054,8 @@ type InternalProgressInformation = Record<string, BucketProgress>;
|
|
|
870
1054
|
*
|
|
871
1055
|
* To obtain these values, use {@link SyncProgress}, available through
|
|
872
1056
|
* {@link SyncStatus#downloadProgress}.
|
|
1057
|
+
*
|
|
1058
|
+
* @public
|
|
873
1059
|
*/
|
|
874
1060
|
interface ProgressWithOperations {
|
|
875
1061
|
/**
|
|
@@ -882,7 +1068,8 @@ interface ProgressWithOperations {
|
|
|
882
1068
|
*/
|
|
883
1069
|
downloadedOperations: number;
|
|
884
1070
|
/**
|
|
885
|
-
* Relative progress, as {@link downloadedOperations} of
|
|
1071
|
+
* Relative progress, as {@link ProgressWithOperations.downloadedOperations} of
|
|
1072
|
+
* {@link ProgressWithOperations.totalOperations}.
|
|
886
1073
|
*
|
|
887
1074
|
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
888
1075
|
*
|
|
@@ -911,6 +1098,8 @@ interface ProgressWithOperations {
|
|
|
911
1098
|
*
|
|
912
1099
|
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
913
1100
|
* to be updated one-by-one.
|
|
1101
|
+
*
|
|
1102
|
+
* @public
|
|
914
1103
|
*/
|
|
915
1104
|
declare class SyncProgress implements ProgressWithOperations {
|
|
916
1105
|
protected internal: InternalProgressInformation;
|
|
@@ -927,6 +1116,9 @@ declare class SyncProgress implements ProgressWithOperations {
|
|
|
927
1116
|
untilPriority(priority: number): ProgressWithOperations;
|
|
928
1117
|
}
|
|
929
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
930
1122
|
type SyncDataFlowStatus = Partial<{
|
|
931
1123
|
downloading: boolean;
|
|
932
1124
|
uploading: boolean;
|
|
@@ -944,16 +1136,25 @@ type SyncDataFlowStatus = Partial<{
|
|
|
944
1136
|
/**
|
|
945
1137
|
* Internal information about how far we are downloading operations in buckets.
|
|
946
1138
|
*
|
|
947
|
-
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
1139
|
+
* @internal Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
948
1140
|
*/
|
|
949
1141
|
downloadProgress: InternalProgressInformation | null;
|
|
1142
|
+
/**
|
|
1143
|
+
* @internal
|
|
1144
|
+
*/
|
|
950
1145
|
internalStreamSubscriptions: CoreStreamSubscription[] | null;
|
|
951
1146
|
}>;
|
|
1147
|
+
/**
|
|
1148
|
+
* @public
|
|
1149
|
+
*/
|
|
952
1150
|
interface SyncPriorityStatus {
|
|
953
1151
|
priority: number;
|
|
954
1152
|
lastSyncedAt?: Date;
|
|
955
1153
|
hasSynced?: boolean;
|
|
956
1154
|
}
|
|
1155
|
+
/**
|
|
1156
|
+
* @internal
|
|
1157
|
+
*/
|
|
957
1158
|
type SyncStatusOptions = {
|
|
958
1159
|
connected?: boolean;
|
|
959
1160
|
connecting?: boolean;
|
|
@@ -966,6 +1167,9 @@ type SyncStatusOptions = {
|
|
|
966
1167
|
*/
|
|
967
1168
|
clientImplementation?: SyncClientImplementation;
|
|
968
1169
|
};
|
|
1170
|
+
/**
|
|
1171
|
+
* @public
|
|
1172
|
+
*/
|
|
969
1173
|
declare class SyncStatus {
|
|
970
1174
|
protected options: SyncStatusOptions;
|
|
971
1175
|
constructor(options: SyncStatusOptions);
|
|
@@ -974,64 +1178,45 @@ declare class SyncStatus {
|
|
|
974
1178
|
* implementation).
|
|
975
1179
|
*
|
|
976
1180
|
* This information is only available after a connection has been requested.
|
|
1181
|
+
*
|
|
1182
|
+
* @deprecated This always returns the Rust client (the only option).
|
|
977
1183
|
*/
|
|
978
1184
|
get clientImplementation(): SyncClientImplementation | undefined;
|
|
979
1185
|
/**
|
|
980
1186
|
* Indicates if the client is currently connected to the PowerSync service.
|
|
981
1187
|
*
|
|
982
|
-
* @returns
|
|
1188
|
+
* @returns True if connected, false otherwise. Defaults to false if not specified.
|
|
983
1189
|
*/
|
|
984
1190
|
get connected(): boolean;
|
|
985
1191
|
/**
|
|
986
1192
|
* Indicates if the client is in the process of establishing a connection to the PowerSync service.
|
|
987
1193
|
*
|
|
988
|
-
* @returns
|
|
1194
|
+
* @returns True if connecting, false otherwise. Defaults to false if not specified.
|
|
989
1195
|
*/
|
|
990
1196
|
get connecting(): boolean;
|
|
991
1197
|
/**
|
|
992
1198
|
* Time that a last sync has fully completed, if any.
|
|
993
1199
|
* This timestamp is reset to null after a restart of the PowerSync service.
|
|
994
1200
|
*
|
|
995
|
-
* @returns
|
|
1201
|
+
* @returns The timestamp of the last successful sync, or undefined if no sync has completed.
|
|
996
1202
|
*/
|
|
997
1203
|
get lastSyncedAt(): Date | undefined;
|
|
998
1204
|
/**
|
|
999
1205
|
* Indicates whether there has been at least one full sync completed since initialization.
|
|
1000
1206
|
*
|
|
1001
|
-
* @returns
|
|
1207
|
+
* @returns True if at least one sync has completed, false if no sync has completed,
|
|
1002
1208
|
* or undefined when the state is still being loaded from the database.
|
|
1003
1209
|
*/
|
|
1004
1210
|
get hasSynced(): boolean | undefined;
|
|
1005
1211
|
/**
|
|
1006
1212
|
* Provides the current data flow status regarding uploads and downloads.
|
|
1007
1213
|
*
|
|
1008
|
-
* @returns
|
|
1214
|
+
* @returns An object containing:
|
|
1009
1215
|
* - downloading: True if actively downloading changes (only when connected is also true)
|
|
1010
1216
|
* - uploading: True if actively uploading changes
|
|
1011
|
-
* Defaults to {downloading: false, uploading: false} if not specified.
|
|
1217
|
+
* Defaults to `{downloading: false, uploading: false}` if not specified.
|
|
1012
1218
|
*/
|
|
1013
|
-
get dataFlowStatus():
|
|
1014
|
-
downloading: boolean;
|
|
1015
|
-
uploading: boolean;
|
|
1016
|
-
/**
|
|
1017
|
-
* Error during downloading (including connecting).
|
|
1018
|
-
*
|
|
1019
|
-
* Cleared on the next successful data download.
|
|
1020
|
-
*/
|
|
1021
|
-
downloadError?: Error;
|
|
1022
|
-
/**
|
|
1023
|
-
* Error during uploading.
|
|
1024
|
-
* Cleared on the next successful upload.
|
|
1025
|
-
*/
|
|
1026
|
-
uploadError?: Error;
|
|
1027
|
-
/**
|
|
1028
|
-
* Internal information about how far we are downloading operations in buckets.
|
|
1029
|
-
*
|
|
1030
|
-
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
1031
|
-
*/
|
|
1032
|
-
downloadProgress: InternalProgressInformation | null;
|
|
1033
|
-
internalStreamSubscriptions: CoreStreamSubscription[] | null;
|
|
1034
|
-
}>;
|
|
1219
|
+
get dataFlowStatus(): SyncDataFlowStatus;
|
|
1035
1220
|
/**
|
|
1036
1221
|
* All sync streams currently being tracked in teh database.
|
|
1037
1222
|
*
|
|
@@ -1040,13 +1225,13 @@ declare class SyncStatus {
|
|
|
1040
1225
|
*/
|
|
1041
1226
|
get syncStreams(): SyncStreamStatus[] | undefined;
|
|
1042
1227
|
/**
|
|
1043
|
-
* If the `stream` appears in {@link syncStreams}, returns the current status for that stream.
|
|
1228
|
+
* If the `stream` appears in {@link SyncStatus.syncStreams}, returns the current status for that stream.
|
|
1044
1229
|
*/
|
|
1045
1230
|
forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
|
|
1046
1231
|
/**
|
|
1047
1232
|
* Provides sync status information for all bucket priorities, sorted by priority (highest first).
|
|
1048
1233
|
*
|
|
1049
|
-
* @returns
|
|
1234
|
+
* @returns An array of status entries for different sync priority levels,
|
|
1050
1235
|
* sorted with highest priorities (lower numbers) first.
|
|
1051
1236
|
*/
|
|
1052
1237
|
get priorityStatusEntries(): SyncPriorityStatus[];
|
|
@@ -1073,29 +1258,29 @@ declare class SyncStatus {
|
|
|
1073
1258
|
* For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
|
|
1074
1259
|
* with a priority of 1 may return information for priority level 3.
|
|
1075
1260
|
*
|
|
1076
|
-
* @param
|
|
1077
|
-
* @returns
|
|
1261
|
+
* @param priority - The bucket priority for which the status should be reported
|
|
1262
|
+
* @returns Status information for the requested priority level or the next higher level with available status
|
|
1078
1263
|
*/
|
|
1079
1264
|
statusForPriority(priority: number): SyncPriorityStatus;
|
|
1080
1265
|
/**
|
|
1081
1266
|
* Compares this SyncStatus instance with another to determine if they are equal.
|
|
1082
1267
|
* Equality is determined by comparing the serialized JSON representation of both instances.
|
|
1083
1268
|
*
|
|
1084
|
-
* @param
|
|
1085
|
-
* @returns
|
|
1269
|
+
* @param status - The SyncStatus instance to compare against
|
|
1270
|
+
* @returns True if the instances are considered equal, false otherwise
|
|
1086
1271
|
*/
|
|
1087
1272
|
isEqual(status: SyncStatus): boolean;
|
|
1088
1273
|
/**
|
|
1089
1274
|
* Creates a human-readable string representation of the current sync status.
|
|
1090
1275
|
* Includes information about connection state, sync completion, and data flow.
|
|
1091
1276
|
*
|
|
1092
|
-
* @returns
|
|
1277
|
+
* @returns A string representation of the sync status
|
|
1093
1278
|
*/
|
|
1094
1279
|
getMessage(): string;
|
|
1095
1280
|
/**
|
|
1096
1281
|
* Serializes the SyncStatus instance to a plain object.
|
|
1097
1282
|
*
|
|
1098
|
-
* @returns
|
|
1283
|
+
* @returns A plain object representation of the sync status
|
|
1099
1284
|
*/
|
|
1100
1285
|
toJSON(): SyncStatusOptions;
|
|
1101
1286
|
/**
|
|
@@ -1111,6 +1296,8 @@ declare class SyncStatus {
|
|
|
1111
1296
|
}
|
|
1112
1297
|
/**
|
|
1113
1298
|
* Information about a sync stream subscription.
|
|
1299
|
+
*
|
|
1300
|
+
* @public
|
|
1114
1301
|
*/
|
|
1115
1302
|
interface SyncStreamStatus {
|
|
1116
1303
|
progress: ProgressWithOperations | null;
|
|
@@ -1118,6 +1305,9 @@ interface SyncStreamStatus {
|
|
|
1118
1305
|
priority: number | null;
|
|
1119
1306
|
}
|
|
1120
1307
|
|
|
1308
|
+
/**
|
|
1309
|
+
* @public
|
|
1310
|
+
*/
|
|
1121
1311
|
declare class UploadQueueStats {
|
|
1122
1312
|
/**
|
|
1123
1313
|
* Number of records in the upload queue.
|
|
@@ -1139,26 +1329,54 @@ declare class UploadQueueStats {
|
|
|
1139
1329
|
toString(): string;
|
|
1140
1330
|
}
|
|
1141
1331
|
|
|
1332
|
+
/**
|
|
1333
|
+
* @see https://www.sqlite.org/lang_expr.html#castexpr
|
|
1334
|
+
* @public
|
|
1335
|
+
*/
|
|
1142
1336
|
declare enum ColumnType {
|
|
1143
1337
|
TEXT = "TEXT",
|
|
1144
1338
|
INTEGER = "INTEGER",
|
|
1145
1339
|
REAL = "REAL"
|
|
1146
1340
|
}
|
|
1341
|
+
/**
|
|
1342
|
+
* @public
|
|
1343
|
+
*/
|
|
1147
1344
|
interface ColumnOptions {
|
|
1148
1345
|
name: string;
|
|
1149
1346
|
type?: ColumnType;
|
|
1150
1347
|
}
|
|
1348
|
+
/**
|
|
1349
|
+
* @public
|
|
1350
|
+
*/
|
|
1151
1351
|
type BaseColumnType<T extends number | string | null> = {
|
|
1152
1352
|
type: ColumnType;
|
|
1153
1353
|
};
|
|
1354
|
+
/**
|
|
1355
|
+
* @public
|
|
1356
|
+
*/
|
|
1154
1357
|
type ColumnsType = Record<string, BaseColumnType<any>>;
|
|
1358
|
+
/**
|
|
1359
|
+
* @public
|
|
1360
|
+
*/
|
|
1155
1361
|
type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
|
|
1362
|
+
/**
|
|
1363
|
+
* powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
|
|
1364
|
+
* In earlier versions this was limited to 63.
|
|
1365
|
+
*
|
|
1366
|
+
* @internal
|
|
1367
|
+
*/
|
|
1156
1368
|
declare const MAX_AMOUNT_OF_COLUMNS = 1999;
|
|
1369
|
+
/**
|
|
1370
|
+
* @public
|
|
1371
|
+
*/
|
|
1157
1372
|
declare const column: {
|
|
1158
1373
|
text: BaseColumnType<string | null>;
|
|
1159
1374
|
integer: BaseColumnType<number | null>;
|
|
1160
1375
|
real: BaseColumnType<number | null>;
|
|
1161
1376
|
};
|
|
1377
|
+
/**
|
|
1378
|
+
* @public
|
|
1379
|
+
*/
|
|
1162
1380
|
declare class Column {
|
|
1163
1381
|
protected options: ColumnOptions;
|
|
1164
1382
|
constructor(options: ColumnOptions);
|
|
@@ -1170,11 +1388,20 @@ declare class Column {
|
|
|
1170
1388
|
};
|
|
1171
1389
|
}
|
|
1172
1390
|
|
|
1391
|
+
/**
|
|
1392
|
+
* @public
|
|
1393
|
+
*/
|
|
1173
1394
|
interface IndexColumnOptions {
|
|
1174
1395
|
name: string;
|
|
1175
1396
|
ascending?: boolean;
|
|
1176
1397
|
}
|
|
1398
|
+
/**
|
|
1399
|
+
* @internal
|
|
1400
|
+
*/
|
|
1177
1401
|
declare const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions>;
|
|
1402
|
+
/**
|
|
1403
|
+
* @public
|
|
1404
|
+
*/
|
|
1178
1405
|
declare class IndexedColumn {
|
|
1179
1406
|
protected options: IndexColumnOptions;
|
|
1180
1407
|
static createAscending(column: string): IndexedColumn;
|
|
@@ -1188,11 +1415,20 @@ declare class IndexedColumn {
|
|
|
1188
1415
|
};
|
|
1189
1416
|
}
|
|
1190
1417
|
|
|
1418
|
+
/**
|
|
1419
|
+
* @public
|
|
1420
|
+
*/
|
|
1191
1421
|
interface IndexOptions {
|
|
1192
1422
|
name: string;
|
|
1193
1423
|
columns?: IndexedColumn[];
|
|
1194
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* @internal
|
|
1427
|
+
*/
|
|
1195
1428
|
declare const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions>;
|
|
1429
|
+
/**
|
|
1430
|
+
* @public
|
|
1431
|
+
*/
|
|
1196
1432
|
declare class Index {
|
|
1197
1433
|
protected options: IndexOptions;
|
|
1198
1434
|
static createAscending(options: IndexOptions, columnNames: string[]): Index;
|
|
@@ -1213,12 +1449,16 @@ declare class Index {
|
|
|
1213
1449
|
Generate a new table from the columns and indexes
|
|
1214
1450
|
@deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
|
|
1215
1451
|
This will be removed in the next major release.
|
|
1452
|
+
|
|
1453
|
+
@public
|
|
1216
1454
|
*/
|
|
1217
1455
|
declare class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {
|
|
1218
1456
|
}
|
|
1219
1457
|
|
|
1220
1458
|
/**
|
|
1221
1459
|
* Options that apply both to JSON-based tables and raw tables.
|
|
1460
|
+
*
|
|
1461
|
+
* @public
|
|
1222
1462
|
*/
|
|
1223
1463
|
interface TableOrRawTableOptions {
|
|
1224
1464
|
localOnly?: boolean;
|
|
@@ -1234,6 +1474,8 @@ interface SharedTableOptions extends TableOrRawTableOptions {
|
|
|
1234
1474
|
*
|
|
1235
1475
|
* Including old values may be helpful for some backend connector implementations, which is
|
|
1236
1476
|
* why it can be enabled on per-table or per-columm basis.
|
|
1477
|
+
*
|
|
1478
|
+
* @public
|
|
1237
1479
|
*/
|
|
1238
1480
|
interface TrackPreviousOptions {
|
|
1239
1481
|
/** When defined, a list of column names for which old values should be tracked. */
|
|
@@ -1241,6 +1483,9 @@ interface TrackPreviousOptions {
|
|
|
1241
1483
|
/** When enabled, only include values that have actually been changed by an update. */
|
|
1242
1484
|
onlyWhenChanged?: boolean;
|
|
1243
1485
|
}
|
|
1486
|
+
/**
|
|
1487
|
+
* @public
|
|
1488
|
+
*/
|
|
1244
1489
|
interface TableOptions extends SharedTableOptions {
|
|
1245
1490
|
/**
|
|
1246
1491
|
* The synced table name, matching sync rules
|
|
@@ -1249,15 +1494,27 @@ interface TableOptions extends SharedTableOptions {
|
|
|
1249
1494
|
columns: Column[];
|
|
1250
1495
|
indexes?: Index[];
|
|
1251
1496
|
}
|
|
1497
|
+
/**
|
|
1498
|
+
* @public
|
|
1499
|
+
*/
|
|
1252
1500
|
type RowType<T extends TableV2<any>> = {
|
|
1253
1501
|
[K in keyof T['columnMap']]: ExtractColumnValueType<T['columnMap'][K]>;
|
|
1254
1502
|
} & {
|
|
1255
1503
|
id: string;
|
|
1256
1504
|
};
|
|
1505
|
+
/**
|
|
1506
|
+
* @public
|
|
1507
|
+
*/
|
|
1257
1508
|
type IndexShorthand = Record<string, string[]>;
|
|
1509
|
+
/**
|
|
1510
|
+
* @public
|
|
1511
|
+
*/
|
|
1258
1512
|
interface TableV2Options extends SharedTableOptions {
|
|
1259
1513
|
indexes?: IndexShorthand;
|
|
1260
1514
|
}
|
|
1515
|
+
/**
|
|
1516
|
+
* @internal
|
|
1517
|
+
*/
|
|
1261
1518
|
declare const DEFAULT_TABLE_OPTIONS: {
|
|
1262
1519
|
indexes: never[];
|
|
1263
1520
|
insertOnly: boolean;
|
|
@@ -1266,7 +1523,13 @@ declare const DEFAULT_TABLE_OPTIONS: {
|
|
|
1266
1523
|
trackMetadata: boolean;
|
|
1267
1524
|
ignoreEmptyUpdates: boolean;
|
|
1268
1525
|
};
|
|
1526
|
+
/**
|
|
1527
|
+
* @internal
|
|
1528
|
+
*/
|
|
1269
1529
|
declare const InvalidSQLCharacters: RegExp;
|
|
1530
|
+
/**
|
|
1531
|
+
* @public
|
|
1532
|
+
*/
|
|
1270
1533
|
declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
1271
1534
|
protected options: TableOptions;
|
|
1272
1535
|
protected _mappedColumns: Columns;
|
|
@@ -1287,9 +1550,8 @@ declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
1287
1550
|
* 1. New constructor: Using a Columns object and an optional TableV2Options object
|
|
1288
1551
|
* 2. Deprecated constructor: Using a TableOptions object (will be removed in the next major release)
|
|
1289
1552
|
*
|
|
1290
|
-
* @
|
|
1291
|
-
* @param
|
|
1292
|
-
* @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax
|
|
1553
|
+
* @param columns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax)
|
|
1554
|
+
* @param options - Optional configuration options for V2 syntax
|
|
1293
1555
|
*
|
|
1294
1556
|
* @example
|
|
1295
1557
|
* ```javascript
|
|
@@ -1383,8 +1645,10 @@ declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
1383
1645
|
* using client-side table and column constraints.
|
|
1384
1646
|
*
|
|
1385
1647
|
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
1386
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables
|
|
1648
|
+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables} for details and an example on
|
|
1387
1649
|
* using raw tables.
|
|
1650
|
+
*
|
|
1651
|
+
* @public
|
|
1388
1652
|
*/
|
|
1389
1653
|
type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
|
|
1390
1654
|
interface RawTableTypeWithStatements {
|
|
@@ -1440,12 +1704,16 @@ interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
|
|
|
1440
1704
|
* `{Column: 'name'}`.
|
|
1441
1705
|
* The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
|
|
1442
1706
|
* covered by a `Column` parameter.
|
|
1707
|
+
*
|
|
1708
|
+
* @public
|
|
1443
1709
|
*/
|
|
1444
1710
|
type PendingStatementParameter = 'Id' | {
|
|
1445
1711
|
Column: string;
|
|
1446
1712
|
} | 'Rest';
|
|
1447
1713
|
/**
|
|
1448
1714
|
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
1715
|
+
*
|
|
1716
|
+
* @public
|
|
1449
1717
|
*/
|
|
1450
1718
|
type PendingStatement = {
|
|
1451
1719
|
sql: string;
|
|
@@ -1467,11 +1735,16 @@ type RawTable<T extends RawTableType = RawTableType> = T & {
|
|
|
1467
1735
|
};
|
|
1468
1736
|
|
|
1469
1737
|
type SchemaType = Record<string, Table<any>>;
|
|
1738
|
+
/**
|
|
1739
|
+
* @public
|
|
1740
|
+
*/
|
|
1470
1741
|
type SchemaTableType<S extends SchemaType> = {
|
|
1471
1742
|
[K in keyof S]: RowType<S[K]>;
|
|
1472
1743
|
};
|
|
1473
1744
|
/**
|
|
1474
1745
|
* A schema is a collection of tables. It is used to define the structure of a database.
|
|
1746
|
+
*
|
|
1747
|
+
* @public
|
|
1475
1748
|
*/
|
|
1476
1749
|
declare class Schema<S extends SchemaType = SchemaType> {
|
|
1477
1750
|
readonly types: SchemaTableType<S>;
|
|
@@ -1485,7 +1758,7 @@ declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
1485
1758
|
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1486
1759
|
* using client-side table and column constraints.
|
|
1487
1760
|
*
|
|
1488
|
-
* @param tables An object of (table name, raw table definition) entries.
|
|
1761
|
+
* @param tables - An object of (table name, raw table definition) entries.
|
|
1489
1762
|
*/
|
|
1490
1763
|
withRawTables(tables: Record<string, RawTableType>): void;
|
|
1491
1764
|
validate(): void;
|
|
@@ -1523,6 +1796,9 @@ declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
1523
1796
|
static rawTableToJson(table: RawTable): unknown;
|
|
1524
1797
|
}
|
|
1525
1798
|
|
|
1799
|
+
/**
|
|
1800
|
+
* @public
|
|
1801
|
+
*/
|
|
1526
1802
|
interface PowerSyncBackendConnector {
|
|
1527
1803
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
1528
1804
|
* which is used to authenticate against the PowerSync service.
|
|
@@ -1564,6 +1840,9 @@ interface ConnectionManagerSyncImplementationResult {
|
|
|
1564
1840
|
interface CreateSyncImplementationOptions extends AdditionalConnectionOptions {
|
|
1565
1841
|
subscriptions: SubscribedStream[];
|
|
1566
1842
|
}
|
|
1843
|
+
/**
|
|
1844
|
+
* @internal
|
|
1845
|
+
*/
|
|
1567
1846
|
interface InternalSubscriptionAdapter {
|
|
1568
1847
|
firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
|
|
1569
1848
|
resolveOfflineSyncStatus(): Promise<void>;
|
|
@@ -1635,7 +1914,7 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
|
|
|
1635
1914
|
/**
|
|
1636
1915
|
* Close the sync connection.
|
|
1637
1916
|
*
|
|
1638
|
-
* Use {@link connect} to connect again.
|
|
1917
|
+
* Use {@link ConnectionManager.connect} to connect again.
|
|
1639
1918
|
*/
|
|
1640
1919
|
disconnect(): Promise<void>;
|
|
1641
1920
|
protected disconnectInternal(): Promise<void>;
|
|
@@ -1655,12 +1934,16 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
|
|
|
1655
1934
|
* A basic comparator for incrementally watched queries. This performs a single comparison which
|
|
1656
1935
|
* determines if the result set has changed. The {@link WatchedQuery} will only emit the new result
|
|
1657
1936
|
* if a change has been detected.
|
|
1937
|
+
*
|
|
1938
|
+
* @public
|
|
1658
1939
|
*/
|
|
1659
1940
|
interface WatchedQueryComparator<Data> {
|
|
1660
1941
|
checkEquality: (current: Data, previous: Data) => boolean;
|
|
1661
1942
|
}
|
|
1662
1943
|
/**
|
|
1663
1944
|
* Options for {@link ArrayComparator}
|
|
1945
|
+
*
|
|
1946
|
+
* @public
|
|
1664
1947
|
*/
|
|
1665
1948
|
type ArrayComparatorOptions<ItemType> = {
|
|
1666
1949
|
/**
|
|
@@ -1671,6 +1954,8 @@ type ArrayComparatorOptions<ItemType> = {
|
|
|
1671
1954
|
/**
|
|
1672
1955
|
* An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
|
|
1673
1956
|
* result has changes without necessarily processing all items in the result.
|
|
1957
|
+
*
|
|
1958
|
+
* @public
|
|
1674
1959
|
*/
|
|
1675
1960
|
declare class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemType[]> {
|
|
1676
1961
|
protected options: ArrayComparatorOptions<ItemType>;
|
|
@@ -1679,13 +1964,21 @@ declare class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemTy
|
|
|
1679
1964
|
}
|
|
1680
1965
|
/**
|
|
1681
1966
|
* Watched query comparator that always reports changed result sets.
|
|
1967
|
+
*
|
|
1968
|
+
* @public
|
|
1682
1969
|
*/
|
|
1683
1970
|
declare const FalsyComparator: WatchedQueryComparator<unknown>;
|
|
1684
1971
|
|
|
1972
|
+
/**
|
|
1973
|
+
* @public
|
|
1974
|
+
*/
|
|
1685
1975
|
interface CompilableQuery<T> {
|
|
1686
1976
|
execute(): Promise<T[]>;
|
|
1687
1977
|
compile(): CompiledQuery;
|
|
1688
1978
|
}
|
|
1979
|
+
/**
|
|
1980
|
+
* @public
|
|
1981
|
+
*/
|
|
1689
1982
|
interface CompiledQuery {
|
|
1690
1983
|
readonly sql: string;
|
|
1691
1984
|
readonly parameters: ReadonlyArray<unknown>;
|
|
@@ -1722,6 +2015,8 @@ declare class MetaBaseObserver<Listener extends BaseListener> extends BaseObserv
|
|
|
1722
2015
|
|
|
1723
2016
|
/**
|
|
1724
2017
|
* State for {@link WatchedQuery} instances.
|
|
2018
|
+
*
|
|
2019
|
+
* @public
|
|
1725
2020
|
*/
|
|
1726
2021
|
interface WatchedQueryState<Data> {
|
|
1727
2022
|
/**
|
|
@@ -1749,6 +2044,8 @@ interface WatchedQueryState<Data> {
|
|
|
1749
2044
|
}
|
|
1750
2045
|
/**
|
|
1751
2046
|
* Options provided to the `execute` method of a {@link WatchCompatibleQuery}.
|
|
2047
|
+
*
|
|
2048
|
+
* @public
|
|
1752
2049
|
*/
|
|
1753
2050
|
interface WatchExecuteOptions {
|
|
1754
2051
|
sql: string;
|
|
@@ -1756,13 +2053,16 @@ interface WatchExecuteOptions {
|
|
|
1756
2053
|
db: AbstractPowerSyncDatabase;
|
|
1757
2054
|
}
|
|
1758
2055
|
/**
|
|
1759
|
-
*
|
|
1760
|
-
*
|
|
2056
|
+
*
|
|
2057
|
+
* @public
|
|
1761
2058
|
*/
|
|
1762
2059
|
interface WatchCompatibleQuery<ResultType> {
|
|
1763
2060
|
execute(options: WatchExecuteOptions): Promise<ResultType>;
|
|
1764
2061
|
compile(): CompiledQuery;
|
|
1765
2062
|
}
|
|
2063
|
+
/**
|
|
2064
|
+
* @public
|
|
2065
|
+
*/
|
|
1766
2066
|
interface WatchedQueryOptions {
|
|
1767
2067
|
/** The minimum interval between queries. */
|
|
1768
2068
|
throttleMs?: number;
|
|
@@ -1779,6 +2079,9 @@ interface WatchedQueryOptions {
|
|
|
1779
2079
|
*/
|
|
1780
2080
|
triggerOnTables?: string[];
|
|
1781
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @public
|
|
2084
|
+
*/
|
|
1782
2085
|
declare enum WatchedQueryListenerEvent {
|
|
1783
2086
|
ON_DATA = "onData",
|
|
1784
2087
|
ON_ERROR = "onError",
|
|
@@ -1786,6 +2089,9 @@ declare enum WatchedQueryListenerEvent {
|
|
|
1786
2089
|
SETTINGS_WILL_UPDATE = "settingsWillUpdate",
|
|
1787
2090
|
CLOSED = "closed"
|
|
1788
2091
|
}
|
|
2092
|
+
/**
|
|
2093
|
+
* @public
|
|
2094
|
+
*/
|
|
1789
2095
|
interface WatchedQueryListener<Data> extends BaseListener {
|
|
1790
2096
|
[WatchedQueryListenerEvent.ON_DATA]?: (data: Data) => void | Promise<void>;
|
|
1791
2097
|
[WatchedQueryListenerEvent.ON_ERROR]?: (error: Error) => void | Promise<void>;
|
|
@@ -1793,8 +2099,17 @@ interface WatchedQueryListener<Data> extends BaseListener {
|
|
|
1793
2099
|
[WatchedQueryListenerEvent.SETTINGS_WILL_UPDATE]?: () => void;
|
|
1794
2100
|
[WatchedQueryListenerEvent.CLOSED]?: () => void | Promise<void>;
|
|
1795
2101
|
}
|
|
2102
|
+
/**
|
|
2103
|
+
* @internal
|
|
2104
|
+
*/
|
|
1796
2105
|
declare const DEFAULT_WATCH_THROTTLE_MS = 30;
|
|
2106
|
+
/**
|
|
2107
|
+
* @internal
|
|
2108
|
+
*/
|
|
1797
2109
|
declare const DEFAULT_WATCH_QUERY_OPTIONS: WatchedQueryOptions;
|
|
2110
|
+
/**
|
|
2111
|
+
* @public
|
|
2112
|
+
*/
|
|
1798
2113
|
interface WatchedQuery<Data = unknown, Settings extends WatchedQueryOptions = WatchedQueryOptions, Listener extends WatchedQueryListener<Data> = WatchedQueryListener<Data>> extends MetaBaseObserverInterface<Listener> {
|
|
1799
2114
|
/**
|
|
1800
2115
|
* Current state of the watched query.
|
|
@@ -1863,7 +2178,7 @@ declare abstract class AbstractQueryProcessor<Data = unknown[], Settings extends
|
|
|
1863
2178
|
updateSettings(settings: Settings): Promise<void>;
|
|
1864
2179
|
/**
|
|
1865
2180
|
* This method is used to link a query to the subscribers of this listener class.
|
|
1866
|
-
* This method should perform actual query watching and report results via {@link updateState} method.
|
|
2181
|
+
* This method should perform actual query watching and report results via {@link AbstractQueryProcessor.updateState} method.
|
|
1867
2182
|
*/
|
|
1868
2183
|
protected abstract linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
|
|
1869
2184
|
protected updateState(update: Partial<MutableWatchedQueryState<Data>>): Promise<void>;
|
|
@@ -1885,6 +2200,8 @@ declare abstract class AbstractQueryProcessor<Data = unknown[], Settings extends
|
|
|
1885
2200
|
/**
|
|
1886
2201
|
* Represents an updated row in a differential watched query.
|
|
1887
2202
|
* It contains both the current and previous state of the row.
|
|
2203
|
+
*
|
|
2204
|
+
* @public
|
|
1888
2205
|
*/
|
|
1889
2206
|
interface WatchedQueryRowDifferential<RowType> {
|
|
1890
2207
|
readonly current: RowType;
|
|
@@ -1893,6 +2210,8 @@ interface WatchedQueryRowDifferential<RowType> {
|
|
|
1893
2210
|
/**
|
|
1894
2211
|
* Represents the result of a watched query that has been diffed.
|
|
1895
2212
|
* {@link DifferentialWatchedQueryState#diff} is of the {@link WatchedQueryDifferential} form.
|
|
2213
|
+
*
|
|
2214
|
+
* @public
|
|
1896
2215
|
*/
|
|
1897
2216
|
interface WatchedQueryDifferential<RowType> {
|
|
1898
2217
|
readonly added: ReadonlyArray<Readonly<RowType>>;
|
|
@@ -1917,6 +2236,8 @@ interface WatchedQueryDifferential<RowType> {
|
|
|
1917
2236
|
}
|
|
1918
2237
|
/**
|
|
1919
2238
|
* Row comparator for differentially watched queries which keys and compares items in the result set.
|
|
2239
|
+
*
|
|
2240
|
+
* @public
|
|
1920
2241
|
*/
|
|
1921
2242
|
interface DifferentialWatchedQueryComparator<RowType> {
|
|
1922
2243
|
/**
|
|
@@ -1930,6 +2251,8 @@ interface DifferentialWatchedQueryComparator<RowType> {
|
|
|
1930
2251
|
}
|
|
1931
2252
|
/**
|
|
1932
2253
|
* Options for building a differential watched query with the {@link Query} builder.
|
|
2254
|
+
*
|
|
2255
|
+
* @public
|
|
1933
2256
|
*/
|
|
1934
2257
|
interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
1935
2258
|
/**
|
|
@@ -1946,6 +2269,8 @@ interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
|
1946
2269
|
}
|
|
1947
2270
|
/**
|
|
1948
2271
|
* Settings for differential incremental watched queries using.
|
|
2272
|
+
*
|
|
2273
|
+
* @public
|
|
1949
2274
|
*/
|
|
1950
2275
|
interface DifferentialWatchedQuerySettings<RowType> extends DifferentialWatchedQueryOptions<RowType> {
|
|
1951
2276
|
/**
|
|
@@ -1953,9 +2278,15 @@ interface DifferentialWatchedQuerySettings<RowType> extends DifferentialWatchedQ
|
|
|
1953
2278
|
*/
|
|
1954
2279
|
query: WatchCompatibleQuery<RowType[]>;
|
|
1955
2280
|
}
|
|
2281
|
+
/**
|
|
2282
|
+
* @public
|
|
2283
|
+
*/
|
|
1956
2284
|
interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
|
|
1957
2285
|
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
1958
2286
|
}
|
|
2287
|
+
/**
|
|
2288
|
+
* @public
|
|
2289
|
+
*/
|
|
1959
2290
|
type DifferentialWatchedQuery<RowType> = WatchedQuery<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>, DifferentialWatchedQueryListener<RowType>>;
|
|
1960
2291
|
/**
|
|
1961
2292
|
* @internal
|
|
@@ -1970,6 +2301,8 @@ type DataHashMap<RowType> = Map<string, {
|
|
|
1970
2301
|
/**
|
|
1971
2302
|
* An empty differential result set.
|
|
1972
2303
|
* This is used as the initial state for differential incrementally watched queries.
|
|
2304
|
+
*
|
|
2305
|
+
* @internal
|
|
1973
2306
|
*/
|
|
1974
2307
|
declare const EMPTY_DIFFERENTIAL: {
|
|
1975
2308
|
added: never[];
|
|
@@ -1982,6 +2315,8 @@ declare const EMPTY_DIFFERENTIAL: {
|
|
|
1982
2315
|
* Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
|
|
1983
2316
|
* It keys items by their `id` property if available, alternatively it uses JSON stringification
|
|
1984
2317
|
* of the entire item for the key and comparison.
|
|
2318
|
+
*
|
|
2319
|
+
* @internal
|
|
1985
2320
|
*/
|
|
1986
2321
|
declare const DEFAULT_ROW_COMPARATOR: DifferentialWatchedQueryComparator<any>;
|
|
1987
2322
|
/**
|
|
@@ -2003,12 +2338,16 @@ declare class DifferentialQueryProcessor<RowType> extends AbstractQueryProcessor
|
|
|
2003
2338
|
|
|
2004
2339
|
/**
|
|
2005
2340
|
* Settings for {@link WatchedQuery} instances created via {@link Query#watch}.
|
|
2341
|
+
*
|
|
2342
|
+
* @public
|
|
2006
2343
|
*/
|
|
2007
2344
|
interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
|
|
2008
2345
|
query: WatchCompatibleQuery<DataType>;
|
|
2009
2346
|
}
|
|
2010
2347
|
/**
|
|
2011
2348
|
* {@link WatchedQuery} returned from {@link Query#watch}.
|
|
2349
|
+
*
|
|
2350
|
+
* @public
|
|
2012
2351
|
*/
|
|
2013
2352
|
type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
|
|
2014
2353
|
/**
|
|
@@ -2034,11 +2373,15 @@ declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data,
|
|
|
2034
2373
|
|
|
2035
2374
|
/**
|
|
2036
2375
|
* Query parameters for {@link ArrayQueryDefinition#parameters}
|
|
2376
|
+
*
|
|
2377
|
+
* @public
|
|
2037
2378
|
*/
|
|
2038
2379
|
type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
|
|
2039
2380
|
/**
|
|
2040
2381
|
* Options for building a query with {@link AbstractPowerSyncDatabase#query}.
|
|
2041
2382
|
* This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
|
|
2383
|
+
*
|
|
2384
|
+
* @public
|
|
2042
2385
|
*/
|
|
2043
2386
|
interface ArrayQueryDefinition<RowType = unknown> {
|
|
2044
2387
|
sql: string;
|
|
@@ -2057,6 +2400,8 @@ interface ArrayQueryDefinition<RowType = unknown> {
|
|
|
2057
2400
|
}
|
|
2058
2401
|
/**
|
|
2059
2402
|
* Options for {@link Query#watch}.
|
|
2403
|
+
*
|
|
2404
|
+
* @public
|
|
2060
2405
|
*/
|
|
2061
2406
|
interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
2062
2407
|
/**
|
|
@@ -2081,6 +2426,9 @@ interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
|
2081
2426
|
*/
|
|
2082
2427
|
placeholderData?: RowType[];
|
|
2083
2428
|
}
|
|
2429
|
+
/**
|
|
2430
|
+
* @public
|
|
2431
|
+
*/
|
|
2084
2432
|
interface Query<RowType> {
|
|
2085
2433
|
/**
|
|
2086
2434
|
* Creates a {@link WatchedQuery} which watches and emits results of the linked query.
|
|
@@ -2126,6 +2474,9 @@ interface Query<RowType> {
|
|
|
2126
2474
|
differentialWatch(options?: DifferentialWatchedQueryOptions<RowType>): DifferentialWatchedQuery<RowType>;
|
|
2127
2475
|
}
|
|
2128
2476
|
|
|
2477
|
+
/**
|
|
2478
|
+
* @public
|
|
2479
|
+
*/
|
|
2129
2480
|
interface SQLOpenOptions {
|
|
2130
2481
|
/**
|
|
2131
2482
|
* Filename for the database.
|
|
@@ -2149,6 +2500,9 @@ interface SQLOpenOptions {
|
|
|
2149
2500
|
*/
|
|
2150
2501
|
debugMode?: boolean;
|
|
2151
2502
|
}
|
|
2503
|
+
/**
|
|
2504
|
+
* @public
|
|
2505
|
+
*/
|
|
2152
2506
|
interface SQLOpenFactory {
|
|
2153
2507
|
/**
|
|
2154
2508
|
* Opens a connection adapter to a SQLite DB
|
|
@@ -2157,17 +2511,26 @@ interface SQLOpenFactory {
|
|
|
2157
2511
|
}
|
|
2158
2512
|
/**
|
|
2159
2513
|
* Tests if the input is a {@link SQLOpenOptions}
|
|
2514
|
+
*
|
|
2515
|
+
* @internal
|
|
2160
2516
|
*/
|
|
2161
2517
|
declare const isSQLOpenOptions: (test: any) => test is SQLOpenOptions;
|
|
2162
2518
|
/**
|
|
2163
2519
|
* Tests if input is a {@link SQLOpenFactory}
|
|
2520
|
+
*
|
|
2521
|
+
* @internal
|
|
2164
2522
|
*/
|
|
2165
2523
|
declare const isSQLOpenFactory: (test: any) => test is SQLOpenFactory;
|
|
2166
2524
|
/**
|
|
2167
2525
|
* Tests if input is a {@link DBAdapter}
|
|
2526
|
+
*
|
|
2527
|
+
* @internal
|
|
2168
2528
|
*/
|
|
2169
2529
|
declare const isDBAdapter: (test: any) => test is DBAdapter;
|
|
2170
2530
|
|
|
2531
|
+
/**
|
|
2532
|
+
* @public
|
|
2533
|
+
*/
|
|
2171
2534
|
declare class CrudTransaction extends CrudBatch {
|
|
2172
2535
|
/**
|
|
2173
2536
|
* List of client-side changes.
|
|
@@ -2198,7 +2561,8 @@ declare class CrudTransaction extends CrudBatch {
|
|
|
2198
2561
|
|
|
2199
2562
|
/**
|
|
2200
2563
|
* SQLite operations to track changes for with {@link TriggerManager}
|
|
2201
|
-
*
|
|
2564
|
+
*
|
|
2565
|
+
* @experimental @alpha
|
|
2202
2566
|
*/
|
|
2203
2567
|
declare enum DiffTriggerOperation {
|
|
2204
2568
|
INSERT = "INSERT",
|
|
@@ -2206,7 +2570,7 @@ declare enum DiffTriggerOperation {
|
|
|
2206
2570
|
DELETE = "DELETE"
|
|
2207
2571
|
}
|
|
2208
2572
|
/**
|
|
2209
|
-
* @experimental
|
|
2573
|
+
* @experimental @alpha
|
|
2210
2574
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
2211
2575
|
* This is the base record structure for all diff records.
|
|
2212
2576
|
*
|
|
@@ -2235,7 +2599,7 @@ interface BaseTriggerDiffRecord<TOperationId extends string | number = number> {
|
|
|
2235
2599
|
timestamp: string;
|
|
2236
2600
|
}
|
|
2237
2601
|
/**
|
|
2238
|
-
* @experimental
|
|
2602
|
+
* @experimental @alpha
|
|
2239
2603
|
* Represents a diff record for a SQLite UPDATE operation.
|
|
2240
2604
|
* This record contains the new value and optionally the previous value.
|
|
2241
2605
|
* Values are stored as JSON strings.
|
|
@@ -2252,7 +2616,7 @@ interface TriggerDiffUpdateRecord<TOperationId extends string | number = number>
|
|
|
2252
2616
|
previous_value: string;
|
|
2253
2617
|
}
|
|
2254
2618
|
/**
|
|
2255
|
-
* @experimental
|
|
2619
|
+
* @experimental @alpha
|
|
2256
2620
|
* Represents a diff record for a SQLite INSERT operation.
|
|
2257
2621
|
* This record contains the new value represented as a JSON string.
|
|
2258
2622
|
*/
|
|
@@ -2264,7 +2628,7 @@ interface TriggerDiffInsertRecord<TOperationId extends string | number = number>
|
|
|
2264
2628
|
value: string;
|
|
2265
2629
|
}
|
|
2266
2630
|
/**
|
|
2267
|
-
* @experimental
|
|
2631
|
+
* @experimental @alpha
|
|
2268
2632
|
* Represents a diff record for a SQLite DELETE operation.
|
|
2269
2633
|
* This record contains the new value represented as a JSON string.
|
|
2270
2634
|
*/
|
|
@@ -2276,7 +2640,7 @@ interface TriggerDiffDeleteRecord<TOperationId extends string | number = number>
|
|
|
2276
2640
|
value: string;
|
|
2277
2641
|
}
|
|
2278
2642
|
/**
|
|
2279
|
-
* @experimental
|
|
2643
|
+
* @experimental @alpha
|
|
2280
2644
|
* Diffs created by {@link TriggerManager#createDiffTrigger} are stored in a temporary table.
|
|
2281
2645
|
* This is the record structure for all diff records.
|
|
2282
2646
|
*
|
|
@@ -2301,7 +2665,7 @@ interface TriggerDiffDeleteRecord<TOperationId extends string | number = number>
|
|
|
2301
2665
|
*/
|
|
2302
2666
|
type TriggerDiffRecord<TOperationId extends string | number = number> = TriggerDiffUpdateRecord<TOperationId> | TriggerDiffInsertRecord<TOperationId> | TriggerDiffDeleteRecord<TOperationId>;
|
|
2303
2667
|
/**
|
|
2304
|
-
* @experimental
|
|
2668
|
+
* @experimental @alpha
|
|
2305
2669
|
* Querying the DIFF table directly with {@link TriggerDiffHandlerContext#withExtractedDiff} will return records
|
|
2306
2670
|
* with the tracked columns extracted from the JSON value.
|
|
2307
2671
|
* This type represents the structure of such records.
|
|
@@ -2329,7 +2693,7 @@ type ExtractedTriggerDiffRecord<T, TOperationId extends string | number = number
|
|
|
2329
2693
|
__previous_value?: string;
|
|
2330
2694
|
};
|
|
2331
2695
|
/**
|
|
2332
|
-
* @experimental
|
|
2696
|
+
* @experimental @alpha
|
|
2333
2697
|
* Hooks used in the creation of a table diff trigger.
|
|
2334
2698
|
*/
|
|
2335
2699
|
interface TriggerCreationHooks {
|
|
@@ -2385,7 +2749,7 @@ interface BaseCreateDiffTriggerOptions {
|
|
|
2385
2749
|
useStorage?: boolean;
|
|
2386
2750
|
}
|
|
2387
2751
|
/**
|
|
2388
|
-
* @experimental
|
|
2752
|
+
* @experimental @alpha
|
|
2389
2753
|
* Options for {@link TriggerManager#createDiffTrigger}.
|
|
2390
2754
|
*/
|
|
2391
2755
|
interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -2402,19 +2766,19 @@ interface CreateDiffTriggerOptions extends BaseCreateDiffTriggerOptions {
|
|
|
2402
2766
|
setupContext?: LockContext;
|
|
2403
2767
|
}
|
|
2404
2768
|
/**
|
|
2405
|
-
* @experimental
|
|
2769
|
+
* @experimental @alpha
|
|
2406
2770
|
* Options for {@link TriggerRemoveCallback}.
|
|
2407
2771
|
*/
|
|
2408
2772
|
interface TriggerRemoveCallbackOptions {
|
|
2409
2773
|
context?: LockContext;
|
|
2410
2774
|
}
|
|
2411
2775
|
/**
|
|
2412
|
-
* @experimental
|
|
2776
|
+
* @experimental @alpha
|
|
2413
2777
|
* Callback to drop a trigger after it has been created.
|
|
2414
2778
|
*/
|
|
2415
2779
|
type TriggerRemoveCallback = (options?: TriggerRemoveCallbackOptions) => Promise<void>;
|
|
2416
2780
|
/**
|
|
2417
|
-
* @experimental
|
|
2781
|
+
* @experimental @alpha
|
|
2418
2782
|
* Options for {@link TriggerDiffHandlerContext#withDiff}.
|
|
2419
2783
|
*/
|
|
2420
2784
|
interface WithDiffOptions {
|
|
@@ -2428,7 +2792,7 @@ interface WithDiffOptions {
|
|
|
2428
2792
|
castOperationIdAsText?: boolean;
|
|
2429
2793
|
}
|
|
2430
2794
|
/**
|
|
2431
|
-
* @experimental
|
|
2795
|
+
* @experimental @alpha
|
|
2432
2796
|
* Context for the `onChange` handler provided to {@link TriggerManager#trackTableDiff}.
|
|
2433
2797
|
*/
|
|
2434
2798
|
interface TriggerDiffHandlerContext extends LockContext {
|
|
@@ -2483,7 +2847,7 @@ interface TriggerDiffHandlerContext extends LockContext {
|
|
|
2483
2847
|
* Allows querying the database with access to the table containing diff records.
|
|
2484
2848
|
* The diff table is accessible via the `DIFF` accessor.
|
|
2485
2849
|
*
|
|
2486
|
-
* This is similar to {@link withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
2850
|
+
* This is similar to {@link TriggerDiffHandlerContext#withDiff} but extracts the row columns from the tracked JSON value. The diff operation
|
|
2487
2851
|
* data is aliased as `__` columns to avoid column conflicts.
|
|
2488
2852
|
*
|
|
2489
2853
|
* For {@link DiffTriggerOperation#DELETE} operations the previous_value columns are extracted for convenience.
|
|
@@ -2514,7 +2878,7 @@ interface TriggerDiffHandlerContext extends LockContext {
|
|
|
2514
2878
|
withExtractedDiff: <T = any>(query: string, params?: ReadonlyArray<Readonly<any>>) => Promise<T[]>;
|
|
2515
2879
|
}
|
|
2516
2880
|
/**
|
|
2517
|
-
* @experimental
|
|
2881
|
+
* @experimental @alpha
|
|
2518
2882
|
* Options for tracking changes to a table with {@link TriggerManager#trackTableDiff}.
|
|
2519
2883
|
*/
|
|
2520
2884
|
interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
@@ -2525,13 +2889,13 @@ interface TrackDiffOptions extends BaseCreateDiffTriggerOptions {
|
|
|
2525
2889
|
*/
|
|
2526
2890
|
onChange: (context: TriggerDiffHandlerContext) => Promise<void>;
|
|
2527
2891
|
/**
|
|
2528
|
-
* The minimum interval, in milliseconds, between {@link onChange} invocations.
|
|
2892
|
+
* The minimum interval, in milliseconds, between {@link TrackDiffOptions.onChange} invocations.
|
|
2529
2893
|
* @default {@link DEFAULT_WATCH_THROTTLE_MS}
|
|
2530
2894
|
*/
|
|
2531
2895
|
throttleMs?: number;
|
|
2532
2896
|
}
|
|
2533
2897
|
/**
|
|
2534
|
-
* @experimental
|
|
2898
|
+
* @experimental @alpha
|
|
2535
2899
|
*/
|
|
2536
2900
|
interface TriggerManager {
|
|
2537
2901
|
/**
|
|
@@ -2579,7 +2943,7 @@ interface TriggerManager {
|
|
|
2579
2943
|
/**
|
|
2580
2944
|
* @experimental
|
|
2581
2945
|
* Tracks changes for a table. Triggering a provided handler on changes.
|
|
2582
|
-
* Uses {@link createDiffTrigger} internally to create a temporary destination table.
|
|
2946
|
+
* Uses {@link TriggerManager.createDiffTrigger} internally to create a temporary destination table.
|
|
2583
2947
|
*
|
|
2584
2948
|
* @returns A callback to cleanup the trigger and stop tracking changes.
|
|
2585
2949
|
*
|
|
@@ -2685,7 +3049,7 @@ declare class TriggerManagerImpl implements TriggerManager {
|
|
|
2685
3049
|
protected isDisposed: boolean;
|
|
2686
3050
|
constructor(options: TriggerManagerImplOptions);
|
|
2687
3051
|
protected get db(): AbstractPowerSyncDatabase;
|
|
2688
|
-
protected getUUID(): Promise<string>;
|
|
3052
|
+
protected getUUID(ctx?: LockContext): Promise<string>;
|
|
2689
3053
|
protected removeTriggers(tx: LockContext, triggerIds: string[]): Promise<void>;
|
|
2690
3054
|
dispose(): void;
|
|
2691
3055
|
/**
|
|
@@ -2701,6 +3065,9 @@ declare class TriggerManagerImpl implements TriggerManager {
|
|
|
2701
3065
|
trackTableDiff(options: TrackDiffOptions): Promise<TriggerRemoveCallback>;
|
|
2702
3066
|
}
|
|
2703
3067
|
|
|
3068
|
+
/**
|
|
3069
|
+
* @internal
|
|
3070
|
+
*/
|
|
2704
3071
|
type UnlockFn = () => void;
|
|
2705
3072
|
/**
|
|
2706
3073
|
* An asynchronous semaphore implementation with associated items per lease.
|
|
@@ -2747,23 +3114,38 @@ declare class Mutex {
|
|
|
2747
3114
|
}
|
|
2748
3115
|
/**
|
|
2749
3116
|
* Creates a signal aborting after the set timeout.
|
|
3117
|
+
*
|
|
3118
|
+
* @internal
|
|
2750
3119
|
*/
|
|
2751
3120
|
declare function timeoutSignal(timeout: number): AbortSignal;
|
|
3121
|
+
/**
|
|
3122
|
+
* @internal
|
|
3123
|
+
*/
|
|
2752
3124
|
declare function timeoutSignal(timeout?: number): AbortSignal | undefined;
|
|
2753
3125
|
|
|
3126
|
+
/**
|
|
3127
|
+
* @public
|
|
3128
|
+
*/
|
|
2754
3129
|
interface DisconnectAndClearOptions {
|
|
2755
3130
|
/** When set to false, data in local-only tables is preserved. */
|
|
2756
3131
|
clearLocal?: boolean;
|
|
2757
3132
|
}
|
|
3133
|
+
/**
|
|
3134
|
+
* @public
|
|
3135
|
+
*/
|
|
2758
3136
|
interface BasePowerSyncDatabaseOptions extends AdditionalConnectionOptions {
|
|
2759
3137
|
/** Schema used for the local database. */
|
|
2760
3138
|
schema: Schema;
|
|
2761
3139
|
/**
|
|
2762
|
-
* @deprecated Use {@link retryDelayMs} instead as this will be removed in future
|
|
3140
|
+
* @deprecated Use {@link AdditionalConnectionOptions.retryDelayMs} instead as this will be removed in future
|
|
3141
|
+
* releases.
|
|
2763
3142
|
*/
|
|
2764
3143
|
retryDelay?: number;
|
|
2765
3144
|
logger?: ILogger;
|
|
2766
3145
|
}
|
|
3146
|
+
/**
|
|
3147
|
+
* @public
|
|
3148
|
+
*/
|
|
2767
3149
|
interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
|
|
2768
3150
|
/**
|
|
2769
3151
|
* Source for a SQLite database connection.
|
|
@@ -2774,22 +3156,35 @@ interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
|
|
|
2774
3156
|
*/
|
|
2775
3157
|
database: DBAdapter | SQLOpenFactory | SQLOpenOptions;
|
|
2776
3158
|
}
|
|
3159
|
+
/**
|
|
3160
|
+
* @public
|
|
3161
|
+
*/
|
|
2777
3162
|
interface PowerSyncDatabaseOptionsWithDBAdapter extends BasePowerSyncDatabaseOptions {
|
|
2778
3163
|
database: DBAdapter;
|
|
2779
3164
|
}
|
|
3165
|
+
/**
|
|
3166
|
+
* @public
|
|
3167
|
+
*/
|
|
2780
3168
|
interface PowerSyncDatabaseOptionsWithOpenFactory extends BasePowerSyncDatabaseOptions {
|
|
2781
3169
|
database: SQLOpenFactory;
|
|
2782
3170
|
}
|
|
3171
|
+
/**
|
|
3172
|
+
* @public
|
|
3173
|
+
*/
|
|
2783
3174
|
interface PowerSyncDatabaseOptionsWithSettings extends BasePowerSyncDatabaseOptions {
|
|
2784
3175
|
database: SQLOpenOptions;
|
|
2785
3176
|
}
|
|
3177
|
+
/**
|
|
3178
|
+
* @public
|
|
3179
|
+
*/
|
|
2786
3180
|
interface SQLOnChangeOptions {
|
|
2787
3181
|
signal?: AbortSignal;
|
|
2788
3182
|
tables?: string[];
|
|
2789
3183
|
/** The minimum interval between queries. */
|
|
2790
3184
|
throttleMs?: number;
|
|
2791
3185
|
/**
|
|
2792
|
-
* @deprecated All tables specified in {@link tables} will be watched, including PowerSync tables
|
|
3186
|
+
* @deprecated All tables specified in {@link SQLOnChangeOptions.tables} will be watched, including PowerSync tables
|
|
3187
|
+
* with prefixes.
|
|
2793
3188
|
*
|
|
2794
3189
|
* Allows for watching any SQL table
|
|
2795
3190
|
* by not removing PowerSync table name prefixes
|
|
@@ -2800,6 +3195,9 @@ interface SQLOnChangeOptions {
|
|
|
2800
3195
|
*/
|
|
2801
3196
|
triggerImmediate?: boolean;
|
|
2802
3197
|
}
|
|
3198
|
+
/**
|
|
3199
|
+
* @public
|
|
3200
|
+
*/
|
|
2803
3201
|
interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
2804
3202
|
/**
|
|
2805
3203
|
* Optional comparator which will be used to compare the results of the query.
|
|
@@ -2807,23 +3205,38 @@ interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
|
2807
3205
|
*/
|
|
2808
3206
|
comparator?: WatchedQueryComparator<QueryResult>;
|
|
2809
3207
|
}
|
|
3208
|
+
/**
|
|
3209
|
+
* @public
|
|
3210
|
+
*/
|
|
2810
3211
|
interface WatchOnChangeEvent {
|
|
2811
3212
|
changedTables: string[];
|
|
2812
3213
|
}
|
|
3214
|
+
/**
|
|
3215
|
+
* @public
|
|
3216
|
+
*/
|
|
2813
3217
|
interface WatchHandler {
|
|
2814
3218
|
onResult: (results: QueryResult) => void;
|
|
2815
3219
|
onError?: (error: Error) => void;
|
|
2816
3220
|
}
|
|
3221
|
+
/**
|
|
3222
|
+
* @public
|
|
3223
|
+
*/
|
|
2817
3224
|
interface WatchOnChangeHandler {
|
|
2818
3225
|
onChange: (event: WatchOnChangeEvent) => Promise<void> | void;
|
|
2819
3226
|
onError?: (error: Error) => void;
|
|
2820
3227
|
}
|
|
3228
|
+
/**
|
|
3229
|
+
* @public
|
|
3230
|
+
*/
|
|
2821
3231
|
interface PowerSyncDBListener extends StreamingSyncImplementationListener {
|
|
2822
3232
|
initialized: () => void;
|
|
2823
3233
|
schemaChanged: (schema: Schema) => void;
|
|
2824
3234
|
closing: () => Promise<void> | void;
|
|
2825
3235
|
closed: () => Promise<void> | void;
|
|
2826
3236
|
}
|
|
3237
|
+
/**
|
|
3238
|
+
* @public
|
|
3239
|
+
*/
|
|
2827
3240
|
interface PowerSyncCloseOptions {
|
|
2828
3241
|
/**
|
|
2829
3242
|
* Disconnect the sync stream client if connected.
|
|
@@ -2832,16 +3245,27 @@ interface PowerSyncCloseOptions {
|
|
|
2832
3245
|
*/
|
|
2833
3246
|
disconnect?: boolean;
|
|
2834
3247
|
}
|
|
3248
|
+
/**
|
|
3249
|
+
* @internal
|
|
3250
|
+
*/
|
|
2835
3251
|
declare const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions;
|
|
3252
|
+
/**
|
|
3253
|
+
* @internal
|
|
3254
|
+
*/
|
|
2836
3255
|
declare const DEFAULT_POWERSYNC_DB_OPTIONS: {
|
|
2837
3256
|
retryDelayMs: number;
|
|
2838
3257
|
crudUploadThrottleMs: number;
|
|
2839
3258
|
};
|
|
3259
|
+
/**
|
|
3260
|
+
* @internal
|
|
3261
|
+
*/
|
|
2840
3262
|
declare const DEFAULT_CRUD_BATCH_LIMIT = 100;
|
|
2841
3263
|
/**
|
|
2842
3264
|
* Requesting nested or recursive locks can block the application in some circumstances.
|
|
2843
3265
|
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
2844
3266
|
* be obtained.
|
|
3267
|
+
*
|
|
3268
|
+
* @internal
|
|
2845
3269
|
*/
|
|
2846
3270
|
declare const DEFAULT_LOCK_TIMEOUT_MS = 120000;
|
|
2847
3271
|
/**
|
|
@@ -2849,6 +3273,9 @@ declare const DEFAULT_LOCK_TIMEOUT_MS = 120000;
|
|
|
2849
3273
|
* @internal
|
|
2850
3274
|
*/
|
|
2851
3275
|
declare const isPowerSyncDatabaseOptionsWithSettings: (test: any) => test is PowerSyncDatabaseOptionsWithSettings;
|
|
3276
|
+
/**
|
|
3277
|
+
* @public
|
|
3278
|
+
*/
|
|
2852
3279
|
declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDBListener> {
|
|
2853
3280
|
protected options: PowerSyncDatabaseOptions;
|
|
2854
3281
|
/**
|
|
@@ -2927,7 +3354,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2927
3354
|
/**
|
|
2928
3355
|
* Wait for the first sync operation to complete.
|
|
2929
3356
|
*
|
|
2930
|
-
* @param request Either an abort signal (after which the promise will complete regardless of
|
|
3357
|
+
* @param request - Either an abort signal (after which the promise will complete regardless of
|
|
2931
3358
|
* whether a full sync was completed) or an object providing an abort signal and a priority target.
|
|
2932
3359
|
* When a priority target is set, the promise may complete when all buckets with the given (or higher)
|
|
2933
3360
|
* priorities have been synchronized. This can be earlier than a complete sync.
|
|
@@ -2982,7 +3409,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2982
3409
|
/**
|
|
2983
3410
|
* Close the sync connection.
|
|
2984
3411
|
*
|
|
2985
|
-
* Use {@link connect} to connect again.
|
|
3412
|
+
* Use {@link AbstractPowerSyncDatabase.connect} to connect again.
|
|
2986
3413
|
*/
|
|
2987
3414
|
disconnect(): Promise<void>;
|
|
2988
3415
|
/**
|
|
@@ -2997,8 +3424,8 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2997
3424
|
/**
|
|
2998
3425
|
* Create a sync stream to query its status or to subscribe to it.
|
|
2999
3426
|
*
|
|
3000
|
-
* @param name The name of the stream to subscribe to.
|
|
3001
|
-
* @param params Optional parameters for the stream subscription.
|
|
3427
|
+
* @param name - The name of the stream to subscribe to.
|
|
3428
|
+
* @param params - Optional parameters for the stream subscription.
|
|
3002
3429
|
* @returns A {@link SyncStream} instance that can be subscribed to.
|
|
3003
3430
|
* @experimental Sync streams are currently in alpha.
|
|
3004
3431
|
*/
|
|
@@ -3026,14 +3453,14 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3026
3453
|
* Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
|
|
3027
3454
|
* requesting the next batch.
|
|
3028
3455
|
*
|
|
3029
|
-
* Use
|
|
3456
|
+
* Use the `limit` parameter to specify the maximum number of updates to return in a single
|
|
3030
3457
|
* batch.
|
|
3031
3458
|
*
|
|
3032
3459
|
* This method does include transaction ids in the result, but does not group
|
|
3033
3460
|
* data by transaction. One batch may contain data from multiple transactions,
|
|
3034
3461
|
* and a single transaction may be split over multiple batches.
|
|
3035
3462
|
*
|
|
3036
|
-
* @param limit Maximum number of CRUD entries to include in the batch
|
|
3463
|
+
* @param limit - Maximum number of CRUD entries to include in the batch
|
|
3037
3464
|
* @returns A batch of CRUD operations to upload, or null if there are none
|
|
3038
3465
|
*/
|
|
3039
3466
|
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
@@ -3047,7 +3474,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3047
3474
|
* Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
|
|
3048
3475
|
* requesting the next transaction.
|
|
3049
3476
|
*
|
|
3050
|
-
* Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
|
|
3477
|
+
* Unlike {@link AbstractPowerSyncDatabase.getCrudBatch}, this only returns data from a single transaction at a time.
|
|
3051
3478
|
* All data for the transaction is loaded into memory.
|
|
3052
3479
|
*
|
|
3053
3480
|
* @returns A transaction of CRUD operations to upload, or null if there are none
|
|
@@ -3059,7 +3486,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3059
3486
|
* This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
|
|
3060
3487
|
* returned iterator is a full transaction containing all local writes made while that transaction was active.
|
|
3061
3488
|
*
|
|
3062
|
-
* Unlike {@link getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
3489
|
+
* Unlike {@link AbstractPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
3063
3490
|
* {@link CrudTransaction.complete}d yet, this iterator can be used to receive multiple transactions. Calling
|
|
3064
3491
|
* {@link CrudTransaction.complete} will mark that and all prior transactions emitted by the iterator as completed.
|
|
3065
3492
|
*
|
|
@@ -3102,8 +3529,8 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3102
3529
|
* the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
|
|
3103
3530
|
* Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
|
|
3104
3531
|
*
|
|
3105
|
-
* @param sql The SQL query to execute
|
|
3106
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3532
|
+
* @param sql - The SQL query to execute
|
|
3533
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3107
3534
|
* @returns The query result as an object with structured key-value pairs
|
|
3108
3535
|
*/
|
|
3109
3536
|
execute(sql: string, parameters?: any[]): Promise<QueryResult>;
|
|
@@ -3111,8 +3538,8 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3111
3538
|
* Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
|
|
3112
3539
|
* This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
|
|
3113
3540
|
*
|
|
3114
|
-
* @param sql The SQL query to execute
|
|
3115
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3541
|
+
* @param sql - The SQL query to execute
|
|
3542
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3116
3543
|
* @returns The raw query result from the underlying database as a nested array of raw values, where each row is
|
|
3117
3544
|
* represented as an array of column values without field names.
|
|
3118
3545
|
*/
|
|
@@ -3122,53 +3549,53 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3122
3549
|
* and optionally return results.
|
|
3123
3550
|
* This is faster than executing separately with each parameter set.
|
|
3124
3551
|
*
|
|
3125
|
-
* @param sql The SQL query to execute
|
|
3126
|
-
* @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
3552
|
+
* @param sql - The SQL query to execute
|
|
3553
|
+
* @param parameters - Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
3127
3554
|
* @returns The query result
|
|
3128
3555
|
*/
|
|
3129
3556
|
executeBatch(sql: string, parameters?: any[][]): Promise<QueryResult>;
|
|
3130
3557
|
/**
|
|
3131
3558
|
* Execute a read-only query and return results.
|
|
3132
3559
|
*
|
|
3133
|
-
* @param sql The SQL query to execute
|
|
3134
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3560
|
+
* @param sql - The SQL query to execute
|
|
3561
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3135
3562
|
* @returns An array of results
|
|
3136
3563
|
*/
|
|
3137
3564
|
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
3138
3565
|
/**
|
|
3139
3566
|
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
|
|
3140
3567
|
*
|
|
3141
|
-
* @param sql The SQL query to execute
|
|
3142
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3568
|
+
* @param sql - The SQL query to execute
|
|
3569
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3143
3570
|
* @returns The first result if found, or null if no results are returned
|
|
3144
3571
|
*/
|
|
3145
3572
|
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
3146
3573
|
/**
|
|
3147
3574
|
* Execute a read-only query and return the first result, error if the ResultSet is empty.
|
|
3148
3575
|
*
|
|
3149
|
-
* @param sql The SQL query to execute
|
|
3150
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3576
|
+
* @param sql - The SQL query to execute
|
|
3577
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3151
3578
|
* @returns The first result matching the query
|
|
3152
3579
|
* @throws Error if no rows are returned
|
|
3153
3580
|
*/
|
|
3154
3581
|
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
3155
3582
|
/**
|
|
3156
3583
|
* Takes a read lock, without starting a transaction.
|
|
3157
|
-
* In most cases, {@link readTransaction} should be used instead.
|
|
3584
|
+
* In most cases, {@link AbstractPowerSyncDatabase.readTransaction} should be used instead.
|
|
3158
3585
|
*/
|
|
3159
|
-
readLock<T>(callback: (db:
|
|
3586
|
+
readLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
3160
3587
|
/**
|
|
3161
3588
|
* Takes a global lock, without starting a transaction.
|
|
3162
|
-
* In most cases, {@link writeTransaction} should be used instead.
|
|
3589
|
+
* In most cases, {@link AbstractPowerSyncDatabase.writeTransaction} should be used instead.
|
|
3163
3590
|
*/
|
|
3164
|
-
writeLock<T>(callback: (db:
|
|
3591
|
+
writeLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
3165
3592
|
/**
|
|
3166
3593
|
* Open a read-only transaction.
|
|
3167
3594
|
* Read transactions can run concurrently to a write transaction.
|
|
3168
3595
|
* Changes from any write transaction are not visible to read transactions started before it.
|
|
3169
3596
|
*
|
|
3170
|
-
* @param callback Function to execute within the transaction
|
|
3171
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
3597
|
+
* @param callback - Function to execute within the transaction
|
|
3598
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
3172
3599
|
* @returns The result of the callback
|
|
3173
3600
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
3174
3601
|
*/
|
|
@@ -3178,15 +3605,15 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3178
3605
|
* This takes a global lock - only one write transaction can execute against the database at a time.
|
|
3179
3606
|
* Statements within the transaction must be done on the provided {@link Transaction} interface.
|
|
3180
3607
|
*
|
|
3181
|
-
* @param callback Function to execute within the transaction
|
|
3182
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
3608
|
+
* @param callback - Function to execute within the transaction
|
|
3609
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
3183
3610
|
* @returns The result of the callback
|
|
3184
3611
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
3185
3612
|
*/
|
|
3186
3613
|
writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
|
|
3187
3614
|
/**
|
|
3188
|
-
* This version of `watch` uses
|
|
3189
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link watchWithCallback}.
|
|
3615
|
+
* This version of `watch` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator}.
|
|
3616
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.watchWithCallback}.
|
|
3190
3617
|
*
|
|
3191
3618
|
* @example
|
|
3192
3619
|
* ```javascript
|
|
@@ -3202,7 +3629,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3202
3629
|
*/
|
|
3203
3630
|
watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
3204
3631
|
/**
|
|
3205
|
-
* See {@link watchWithCallback}.
|
|
3632
|
+
* See {@link AbstractPowerSyncDatabase.watchWithCallback}.
|
|
3206
3633
|
*
|
|
3207
3634
|
* @example
|
|
3208
3635
|
* ```javascript
|
|
@@ -3256,25 +3683,25 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3256
3683
|
customQuery<RowType>(query: WatchCompatibleQuery<RowType[]>): Query<RowType>;
|
|
3257
3684
|
/**
|
|
3258
3685
|
* Execute a read query every time the source tables are modified.
|
|
3259
|
-
* Use {@link
|
|
3686
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
3260
3687
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
3261
3688
|
*
|
|
3262
3689
|
* Note that the `onChange` callback member of the handler is required.
|
|
3263
3690
|
*
|
|
3264
|
-
* @param sql The SQL query to execute
|
|
3265
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3266
|
-
* @param handler Callbacks for handling results and errors
|
|
3267
|
-
* @param options Options for configuring watch behavior
|
|
3691
|
+
* @param sql - The SQL query to execute
|
|
3692
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3693
|
+
* @param handler - Callbacks for handling results and errors
|
|
3694
|
+
* @param options - Options for configuring watch behavior
|
|
3268
3695
|
*/
|
|
3269
3696
|
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
3270
3697
|
/**
|
|
3271
3698
|
* Execute a read query every time the source tables are modified.
|
|
3272
|
-
* Use {@link
|
|
3699
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
3273
3700
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
3274
3701
|
*
|
|
3275
|
-
* @param sql The SQL query to execute
|
|
3276
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
3277
|
-
* @param options Options for configuring watch behavior
|
|
3702
|
+
* @param sql - The SQL query to execute
|
|
3703
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
3704
|
+
* @param options - Options for configuring watch behavior
|
|
3278
3705
|
* @returns An AsyncIterable that yields QueryResults whenever the data changes
|
|
3279
3706
|
*/
|
|
3280
3707
|
watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
@@ -3283,15 +3710,15 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3283
3710
|
* If tables are specified in the options, those are used directly.
|
|
3284
3711
|
* Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
|
|
3285
3712
|
*
|
|
3286
|
-
* @param sql The SQL query to analyze
|
|
3287
|
-
* @param parameters Optional parameters for the SQL query
|
|
3288
|
-
* @param options Optional watch options that may contain explicit table list
|
|
3713
|
+
* @param sql - The SQL query to analyze
|
|
3714
|
+
* @param parameters - Optional parameters for the SQL query
|
|
3715
|
+
* @param options - Optional watch options that may contain explicit table list
|
|
3289
3716
|
* @returns Array of table names that the query depends on
|
|
3290
3717
|
*/
|
|
3291
3718
|
resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]>;
|
|
3292
3719
|
/**
|
|
3293
|
-
* This version of `onChange` uses
|
|
3294
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link onChangeWithCallback}.
|
|
3720
|
+
* This version of `onChange` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithAsyncGenerator}.
|
|
3721
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
|
|
3295
3722
|
*
|
|
3296
3723
|
* @example
|
|
3297
3724
|
* ```javascript
|
|
@@ -3304,7 +3731,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3304
3731
|
*/
|
|
3305
3732
|
onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
3306
3733
|
/**
|
|
3307
|
-
* See {@link onChangeWithCallback}.
|
|
3734
|
+
* See {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
|
|
3308
3735
|
*
|
|
3309
3736
|
* @example
|
|
3310
3737
|
* ```javascript
|
|
@@ -3321,36 +3748,36 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3321
3748
|
/**
|
|
3322
3749
|
* Invoke the provided callback on any changes to any of the specified tables.
|
|
3323
3750
|
*
|
|
3324
|
-
* This is preferred over {@link watchWithCallback} when multiple queries need to be performed
|
|
3751
|
+
* This is preferred over {@link AbstractPowerSyncDatabase.watchWithCallback} when multiple queries need to be performed
|
|
3325
3752
|
* together when data is changed.
|
|
3326
3753
|
*
|
|
3327
3754
|
* Note that the `onChange` callback member of the handler is required.
|
|
3328
3755
|
*
|
|
3329
|
-
* @param handler Callbacks for handling change events and errors
|
|
3330
|
-
* @param options Options for configuring watch behavior
|
|
3756
|
+
* @param handler - Callbacks for handling change events and errors
|
|
3757
|
+
* @param options - Options for configuring watch behavior
|
|
3331
3758
|
* @returns A dispose function to stop watching for changes
|
|
3332
3759
|
*/
|
|
3333
3760
|
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
|
|
3334
3761
|
/**
|
|
3335
3762
|
* Create a Stream of changes to any of the specified tables.
|
|
3336
3763
|
*
|
|
3337
|
-
* This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be
|
|
3338
|
-
* together when data is changed.
|
|
3764
|
+
* This is preferred over {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator} when multiple queries need to be
|
|
3765
|
+
* performed together when data is changed.
|
|
3339
3766
|
*
|
|
3340
3767
|
* Note: do not declare this as `async *onChange` as it will not work in React Native.
|
|
3341
3768
|
*
|
|
3342
|
-
* @param options Options for configuring watch behavior
|
|
3769
|
+
* @param options - Options for configuring watch behavior
|
|
3343
3770
|
* @returns An AsyncIterable that yields change events whenever the specified tables change
|
|
3344
3771
|
*/
|
|
3345
3772
|
onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
3346
3773
|
private handleTableChanges;
|
|
3347
3774
|
private processTableUpdates;
|
|
3348
|
-
/**
|
|
3349
|
-
* @ignore
|
|
3350
|
-
*/
|
|
3351
3775
|
private executeReadOnly;
|
|
3352
3776
|
}
|
|
3353
3777
|
|
|
3778
|
+
/**
|
|
3779
|
+
* @public
|
|
3780
|
+
*/
|
|
3354
3781
|
declare const LogLevel: {
|
|
3355
3782
|
TRACE: Logger.ILogLevel;
|
|
3356
3783
|
DEBUG: Logger.ILogLevel;
|
|
@@ -3360,6 +3787,9 @@ declare const LogLevel: {
|
|
|
3360
3787
|
ERROR: Logger.ILogLevel;
|
|
3361
3788
|
OFF: Logger.ILogLevel;
|
|
3362
3789
|
};
|
|
3790
|
+
/**
|
|
3791
|
+
* @public
|
|
3792
|
+
*/
|
|
3363
3793
|
interface CreateLoggerOptions {
|
|
3364
3794
|
logLevel?: ILogLevel;
|
|
3365
3795
|
}
|
|
@@ -3370,6 +3800,7 @@ interface CreateLoggerOptions {
|
|
|
3370
3800
|
* across all loggers created with `createLogger`. Adjusting settings on this
|
|
3371
3801
|
* base logger affects all loggers derived from it unless explicitly overridden.
|
|
3372
3802
|
*
|
|
3803
|
+
* @public
|
|
3373
3804
|
*/
|
|
3374
3805
|
declare function createBaseLogger(): typeof Logger;
|
|
3375
3806
|
/**
|
|
@@ -3378,14 +3809,21 @@ declare function createBaseLogger(): typeof Logger;
|
|
|
3378
3809
|
* Named loggers allow specific modules or areas of your application to have
|
|
3379
3810
|
* their own logging levels and behaviors. These loggers inherit configuration
|
|
3380
3811
|
* from the base logger by default but can override settings independently.
|
|
3812
|
+
*
|
|
3813
|
+
* @public
|
|
3381
3814
|
*/
|
|
3382
3815
|
declare function createLogger(name: string, options?: CreateLoggerOptions): ILogger;
|
|
3383
3816
|
|
|
3817
|
+
/**
|
|
3818
|
+
* The default name of the local table storing attachment data.
|
|
3819
|
+
*
|
|
3820
|
+
* @alpha
|
|
3821
|
+
*/
|
|
3384
3822
|
declare const ATTACHMENT_TABLE = "attachments";
|
|
3385
3823
|
/**
|
|
3386
3824
|
* AttachmentRecord represents an attachment in the local database.
|
|
3387
3825
|
*
|
|
3388
|
-
* @
|
|
3826
|
+
* @alpha
|
|
3389
3827
|
*/
|
|
3390
3828
|
interface AttachmentRecord {
|
|
3391
3829
|
id: string;
|
|
@@ -3404,13 +3842,13 @@ interface AttachmentRecord {
|
|
|
3404
3842
|
* @param row - The database row object
|
|
3405
3843
|
* @returns The corresponding AttachmentRecord
|
|
3406
3844
|
*
|
|
3407
|
-
* @
|
|
3845
|
+
* @alpha
|
|
3408
3846
|
*/
|
|
3409
3847
|
declare function attachmentFromSql(row: any): AttachmentRecord;
|
|
3410
3848
|
/**
|
|
3411
3849
|
* AttachmentState represents the current synchronization state of an attachment.
|
|
3412
3850
|
*
|
|
3413
|
-
* @
|
|
3851
|
+
* @alpha
|
|
3414
3852
|
*/
|
|
3415
3853
|
declare enum AttachmentState {
|
|
3416
3854
|
QUEUED_UPLOAD = 0,// Attachment to be uploaded
|
|
@@ -3419,12 +3857,15 @@ declare enum AttachmentState {
|
|
|
3419
3857
|
SYNCED = 3,// Attachment has been synced
|
|
3420
3858
|
ARCHIVED = 4
|
|
3421
3859
|
}
|
|
3860
|
+
/**
|
|
3861
|
+
* @alpha
|
|
3862
|
+
*/
|
|
3422
3863
|
interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {
|
|
3423
3864
|
}
|
|
3424
3865
|
/**
|
|
3425
3866
|
* AttachmentTable defines the schema for the attachment queue table.
|
|
3426
3867
|
*
|
|
3427
|
-
* @
|
|
3868
|
+
* @alpha
|
|
3428
3869
|
*/
|
|
3429
3870
|
declare class AttachmentTable extends Table {
|
|
3430
3871
|
constructor(options?: AttachmentTableOptions);
|
|
@@ -3436,17 +3877,18 @@ declare class AttachmentTable extends Table {
|
|
|
3436
3877
|
* Provides methods to query, insert, update, and delete attachment records with
|
|
3437
3878
|
* proper transaction management through PowerSync.
|
|
3438
3879
|
*
|
|
3439
|
-
* @
|
|
3880
|
+
* @experimental
|
|
3881
|
+
* @alpha
|
|
3440
3882
|
*/
|
|
3441
3883
|
declare class AttachmentContext {
|
|
3442
3884
|
/** PowerSync database instance for executing queries */
|
|
3443
|
-
db: AbstractPowerSyncDatabase;
|
|
3885
|
+
readonly db: AbstractPowerSyncDatabase;
|
|
3444
3886
|
/** Name of the database table storing attachment records */
|
|
3445
|
-
tableName: string;
|
|
3887
|
+
readonly tableName: string;
|
|
3446
3888
|
/** Logger instance for diagnostic information */
|
|
3447
|
-
logger: ILogger;
|
|
3889
|
+
readonly logger: ILogger;
|
|
3448
3890
|
/** Maximum number of archived attachments to keep before cleanup */
|
|
3449
|
-
archivedCacheLimit: number;
|
|
3891
|
+
readonly archivedCacheLimit: number;
|
|
3450
3892
|
/**
|
|
3451
3893
|
* Creates a new AttachmentContext instance.
|
|
3452
3894
|
*
|
|
@@ -3523,28 +3965,34 @@ declare class AttachmentContext {
|
|
|
3523
3965
|
interface AttachmentErrorHandler {
|
|
3524
3966
|
/**
|
|
3525
3967
|
* Handles a download error for a specific attachment.
|
|
3526
|
-
* @param attachment The attachment that failed to download
|
|
3527
|
-
* @param error The error encountered during the download
|
|
3968
|
+
* @param attachment - The attachment that failed to download
|
|
3969
|
+
* @param error - The error encountered during the download
|
|
3528
3970
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3529
3971
|
*/
|
|
3530
3972
|
onDownloadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3531
3973
|
/**
|
|
3532
3974
|
* Handles an upload error for a specific attachment.
|
|
3533
|
-
* @param attachment The attachment that failed to upload
|
|
3534
|
-
* @param error The error encountered during the upload
|
|
3975
|
+
* @param attachment - The attachment that failed to upload
|
|
3976
|
+
* @param error - The error encountered during the upload
|
|
3535
3977
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3536
3978
|
*/
|
|
3537
3979
|
onUploadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3538
3980
|
/**
|
|
3539
3981
|
* Handles a delete error for a specific attachment.
|
|
3540
|
-
* @param attachment The attachment that failed to delete
|
|
3541
|
-
* @param error The error encountered during the delete
|
|
3982
|
+
* @param attachment - The attachment that failed to delete
|
|
3983
|
+
* @param error - The error encountered during the delete
|
|
3542
3984
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3543
3985
|
*/
|
|
3544
3986
|
onDeleteError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3545
3987
|
}
|
|
3546
3988
|
|
|
3989
|
+
/**
|
|
3990
|
+
* @alpha
|
|
3991
|
+
*/
|
|
3547
3992
|
type AttachmentData = ArrayBuffer | string;
|
|
3993
|
+
/**
|
|
3994
|
+
* @alpha
|
|
3995
|
+
*/
|
|
3548
3996
|
declare enum EncodingType {
|
|
3549
3997
|
UTF8 = "utf8",
|
|
3550
3998
|
Base64 = "base64"
|
|
@@ -3559,36 +4007,36 @@ declare enum EncodingType {
|
|
|
3559
4007
|
interface LocalStorageAdapter {
|
|
3560
4008
|
/**
|
|
3561
4009
|
* Saves data to a local file.
|
|
3562
|
-
* @param filePath Path where the file will be stored
|
|
3563
|
-
* @param data Data to store (ArrayBuffer, Blob, or string)
|
|
4010
|
+
* @param filePath - Path where the file will be stored
|
|
4011
|
+
* @param data - Data to store (ArrayBuffer, Blob, or string)
|
|
3564
4012
|
* @returns Number of bytes written
|
|
3565
4013
|
*/
|
|
3566
4014
|
saveFile(filePath: string, data: AttachmentData): Promise<number>;
|
|
3567
4015
|
/**
|
|
3568
4016
|
* Retrieves file data as an ArrayBuffer.
|
|
3569
|
-
* @param filePath Path where the file is stored
|
|
4017
|
+
* @param filePath - Path where the file is stored
|
|
3570
4018
|
* @returns ArrayBuffer containing the file data
|
|
3571
4019
|
*/
|
|
3572
4020
|
readFile(filePath: string): Promise<ArrayBuffer>;
|
|
3573
4021
|
/**
|
|
3574
4022
|
* Deletes the file at the given path.
|
|
3575
|
-
* @param filePath Path where the file is stored
|
|
4023
|
+
* @param filePath - Path where the file is stored
|
|
3576
4024
|
*/
|
|
3577
4025
|
deleteFile(filePath: string): Promise<void>;
|
|
3578
4026
|
/**
|
|
3579
4027
|
* Checks if a file exists at the given path.
|
|
3580
|
-
* @param filePath Path where the file is stored
|
|
4028
|
+
* @param filePath - Path where the file is stored
|
|
3581
4029
|
* @returns True if the file exists, false otherwise
|
|
3582
4030
|
*/
|
|
3583
4031
|
fileExists(filePath: string): Promise<boolean>;
|
|
3584
4032
|
/**
|
|
3585
4033
|
* Creates a directory at the specified path.
|
|
3586
|
-
* @param path The full path to the directory
|
|
4034
|
+
* @param path - The full path to the directory
|
|
3587
4035
|
*/
|
|
3588
4036
|
makeDir(path: string): Promise<void>;
|
|
3589
4037
|
/**
|
|
3590
4038
|
* Removes a directory at the specified path.
|
|
3591
|
-
* @param path The full path to the directory
|
|
4039
|
+
* @param path - The full path to the directory
|
|
3592
4040
|
*/
|
|
3593
4041
|
rmDir(path: string): Promise<void>;
|
|
3594
4042
|
/**
|
|
@@ -3601,7 +4049,7 @@ interface LocalStorageAdapter {
|
|
|
3601
4049
|
clear(): Promise<void>;
|
|
3602
4050
|
/**
|
|
3603
4051
|
* Returns the file path for the provided filename in the storage directory.
|
|
3604
|
-
* @param filename The filename to get the path for
|
|
4052
|
+
* @param filename - The filename to get the path for
|
|
3605
4053
|
* @returns The full file path
|
|
3606
4054
|
*/
|
|
3607
4055
|
getLocalUri(filename: string): string;
|
|
@@ -3617,19 +4065,19 @@ interface LocalStorageAdapter {
|
|
|
3617
4065
|
interface RemoteStorageAdapter {
|
|
3618
4066
|
/**
|
|
3619
4067
|
* Uploads a file to remote storage.
|
|
3620
|
-
* @param fileData The binary content of the file to upload
|
|
3621
|
-
* @param attachment The associated attachment metadata
|
|
4068
|
+
* @param fileData - The binary content of the file to upload
|
|
4069
|
+
* @param attachment - The associated attachment metadata
|
|
3622
4070
|
*/
|
|
3623
4071
|
uploadFile(fileData: ArrayBuffer, attachment: AttachmentRecord): Promise<void>;
|
|
3624
4072
|
/**
|
|
3625
4073
|
* Downloads a file from remote storage.
|
|
3626
|
-
* @param attachment The attachment describing the file to download
|
|
4074
|
+
* @param attachment - The attachment describing the file to download
|
|
3627
4075
|
* @returns The binary data of the downloaded file
|
|
3628
4076
|
*/
|
|
3629
4077
|
downloadFile(attachment: AttachmentRecord): Promise<ArrayBuffer>;
|
|
3630
4078
|
/**
|
|
3631
4079
|
* Deletes a file from remote storage.
|
|
3632
|
-
* @param attachment The attachment describing the file to delete
|
|
4080
|
+
* @param attachment - The attachment describing the file to delete
|
|
3633
4081
|
*/
|
|
3634
4082
|
deleteFile(attachment: AttachmentRecord): Promise<void>;
|
|
3635
4083
|
}
|
|
@@ -3638,18 +4086,20 @@ interface RemoteStorageAdapter {
|
|
|
3638
4086
|
* WatchedAttachmentItem represents an attachment reference in your application's data model.
|
|
3639
4087
|
* Use either filename OR fileExtension (not both).
|
|
3640
4088
|
*
|
|
3641
|
-
* @
|
|
4089
|
+
* @alpha
|
|
3642
4090
|
*/
|
|
3643
4091
|
type WatchedAttachmentItem = {
|
|
3644
4092
|
id: string;
|
|
3645
4093
|
filename: string;
|
|
3646
4094
|
fileExtension?: never;
|
|
3647
4095
|
metaData?: string;
|
|
4096
|
+
mediaType?: string;
|
|
3648
4097
|
} | {
|
|
3649
4098
|
id: string;
|
|
3650
4099
|
fileExtension: string;
|
|
3651
4100
|
filename?: never;
|
|
3652
4101
|
metaData?: string;
|
|
4102
|
+
mediaType?: string;
|
|
3653
4103
|
};
|
|
3654
4104
|
|
|
3655
4105
|
/**
|
|
@@ -3661,7 +4111,7 @@ type WatchedAttachmentItem = {
|
|
|
3661
4111
|
* @experimental
|
|
3662
4112
|
* @alpha This is currently experimental and may change without a major version bump.
|
|
3663
4113
|
*/
|
|
3664
|
-
declare class AttachmentQueue {
|
|
4114
|
+
declare class AttachmentQueue implements AttachmentQueue {
|
|
3665
4115
|
/** Timer for periodic synchronization operations */
|
|
3666
4116
|
private periodicSyncTimer?;
|
|
3667
4117
|
/** Service for synchronizing attachments between local and remote storage */
|
|
@@ -3708,27 +4158,47 @@ declare class AttachmentQueue {
|
|
|
3708
4158
|
* Creates a new AttachmentQueue instance.
|
|
3709
4159
|
*
|
|
3710
4160
|
* @param options - Configuration options
|
|
3711
|
-
* @param options.db - PowerSync database instance
|
|
3712
|
-
* @param options.remoteStorage - Remote storage adapter for upload/download operations
|
|
3713
|
-
* @param options.localStorage - Local storage adapter for file persistence
|
|
3714
|
-
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
|
|
3715
|
-
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
3716
|
-
* @param options.logger - Logger instance. Defaults to db.logger
|
|
3717
|
-
* @param options.syncIntervalMs - Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
3718
|
-
* @param options.syncThrottleDuration - Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
3719
|
-
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
|
|
3720
|
-
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
|
|
3721
4161
|
*/
|
|
3722
4162
|
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName, syncIntervalMs, syncThrottleDuration, downloadAttachments, archivedCacheLimit, errorHandler }: {
|
|
4163
|
+
/**
|
|
4164
|
+
* PowerSync database instance
|
|
4165
|
+
*/
|
|
3723
4166
|
db: AbstractPowerSyncDatabase;
|
|
4167
|
+
/**
|
|
4168
|
+
* Remote storage adapter for upload/download operations
|
|
4169
|
+
*/
|
|
3724
4170
|
remoteStorage: RemoteStorageAdapter;
|
|
4171
|
+
/**
|
|
4172
|
+
* Local storage adapter for file persistence
|
|
4173
|
+
*/
|
|
3725
4174
|
localStorage: LocalStorageAdapter;
|
|
4175
|
+
/**
|
|
4176
|
+
* Callback for monitoring attachment changes in your data model
|
|
4177
|
+
*/
|
|
3726
4178
|
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
4179
|
+
/**
|
|
4180
|
+
* Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
4181
|
+
*/
|
|
3727
4182
|
tableName?: string;
|
|
4183
|
+
/**
|
|
4184
|
+
* Logger instance. Defaults to db.logger
|
|
4185
|
+
*/
|
|
3728
4186
|
logger?: ILogger;
|
|
4187
|
+
/**
|
|
4188
|
+
* Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
4189
|
+
*/
|
|
3729
4190
|
syncIntervalMs?: number;
|
|
4191
|
+
/**
|
|
4192
|
+
* Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
4193
|
+
*/
|
|
3730
4194
|
syncThrottleDuration?: number;
|
|
4195
|
+
/**
|
|
4196
|
+
* Whether to automatically download remote attachments. Default: true
|
|
4197
|
+
*/
|
|
3731
4198
|
downloadAttachments?: boolean;
|
|
4199
|
+
/**
|
|
4200
|
+
* Maximum archived attachments before cleanup. Default: 100
|
|
4201
|
+
*/
|
|
3732
4202
|
archivedCacheLimit?: number;
|
|
3733
4203
|
errorHandler?: AttachmentErrorHandler;
|
|
3734
4204
|
});
|
|
@@ -3762,25 +4232,45 @@ declare class AttachmentQueue {
|
|
|
3762
4232
|
* Clears the periodic sync timer and closes all active attachment watchers.
|
|
3763
4233
|
*/
|
|
3764
4234
|
stopSync(): Promise<void>;
|
|
4235
|
+
/**
|
|
4236
|
+
* Provides an {@link AttachmentContext} to a callback.
|
|
4237
|
+
*
|
|
4238
|
+
* The callback runs while the attachment queue mutex is held. Do not call
|
|
4239
|
+
* other {@link AttachmentQueue} methods from within the callback, as they may
|
|
4240
|
+
* attempt to acquire the same mutex and block indefinitely.
|
|
4241
|
+
*/
|
|
4242
|
+
withAttachmentContext<T>(callback: (context: AttachmentContext) => Promise<T>): Promise<T>;
|
|
3765
4243
|
/**
|
|
3766
4244
|
* Saves a file to local storage and queues it for upload to remote storage.
|
|
3767
4245
|
*
|
|
3768
4246
|
* @param options - File save options
|
|
3769
|
-
* @param options.data - The file data as ArrayBuffer, Blob, or base64 string
|
|
3770
|
-
* @param options.fileExtension - File extension (e.g., 'jpg', 'pdf')
|
|
3771
|
-
* @param options.mediaType - MIME type of the file (e.g., 'image/jpeg')
|
|
3772
|
-
* @param options.metaData - Optional metadata to associate with the attachment
|
|
3773
|
-
* @param options.id - Optional custom ID. If not provided, a UUID will be generated
|
|
3774
|
-
* @param options.updateHook - Optional callback to execute additional database operations
|
|
3775
|
-
* within the same transaction as the attachment creation
|
|
3776
4247
|
* @returns Promise resolving to the created attachment record
|
|
3777
4248
|
*/
|
|
3778
4249
|
saveFile({ data, fileExtension, mediaType, metaData, id, updateHook }: {
|
|
4250
|
+
/**
|
|
4251
|
+
* The file data as ArrayBuffer, Blob, or base64 string
|
|
4252
|
+
*/
|
|
3779
4253
|
data: AttachmentData;
|
|
4254
|
+
/**
|
|
4255
|
+
* File extension (e.g., 'jpg', 'pdf')
|
|
4256
|
+
*/
|
|
3780
4257
|
fileExtension: string;
|
|
4258
|
+
/**
|
|
4259
|
+
* MIME type of the file (e.g., 'image/jpeg')
|
|
4260
|
+
*/
|
|
3781
4261
|
mediaType?: string;
|
|
4262
|
+
/**
|
|
4263
|
+
* Optional metadata to associate with the attachment
|
|
4264
|
+
*/
|
|
3782
4265
|
metaData?: string;
|
|
4266
|
+
/**
|
|
4267
|
+
* Optional custom ID. If not provided, a UUID will be generated
|
|
4268
|
+
*/
|
|
3783
4269
|
id?: string;
|
|
4270
|
+
/**
|
|
4271
|
+
* Optional callback to execute additional database operations within the same transaction as the attachment
|
|
4272
|
+
* creation.
|
|
4273
|
+
*/
|
|
3784
4274
|
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
3785
4275
|
}): Promise<AttachmentRecord>;
|
|
3786
4276
|
deleteFile({ id, updateHook }: {
|
|
@@ -3882,10 +4372,16 @@ declare class SyncingService {
|
|
|
3882
4372
|
deleteArchivedAttachments(context: AttachmentContext): Promise<boolean>;
|
|
3883
4373
|
}
|
|
3884
4374
|
|
|
4375
|
+
/**
|
|
4376
|
+
* @internal
|
|
4377
|
+
*/
|
|
3885
4378
|
interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions>, SQLOpenOptions {
|
|
3886
4379
|
/** Schema used for the local database. */
|
|
3887
4380
|
schema: Schema;
|
|
3888
4381
|
}
|
|
4382
|
+
/**
|
|
4383
|
+
* @internal
|
|
4384
|
+
*/
|
|
3889
4385
|
declare abstract class AbstractPowerSyncDatabaseOpenFactory {
|
|
3890
4386
|
protected options: PowerSyncOpenFactoryOptions;
|
|
3891
4387
|
constructor(options: PowerSyncOpenFactoryOptions);
|
|
@@ -3901,16 +4397,31 @@ declare abstract class AbstractPowerSyncDatabaseOpenFactory {
|
|
|
3901
4397
|
getInstance(): AbstractPowerSyncDatabase;
|
|
3902
4398
|
}
|
|
3903
4399
|
|
|
4400
|
+
/**
|
|
4401
|
+
* @public
|
|
4402
|
+
*/
|
|
3904
4403
|
interface CompilableQueryWatchHandler<T> {
|
|
3905
4404
|
onResult: (results: T[]) => void;
|
|
3906
4405
|
onError?: (error: Error) => void;
|
|
3907
4406
|
}
|
|
4407
|
+
/**
|
|
4408
|
+
* @public
|
|
4409
|
+
*/
|
|
3908
4410
|
declare function compilableQueryWatch<T>(db: AbstractPowerSyncDatabase, query: CompilableQuery<T>, handler: CompilableQueryWatchHandler<T>, options?: SQLWatchOptions): void;
|
|
3909
4411
|
|
|
4412
|
+
/**
|
|
4413
|
+
* @internal
|
|
4414
|
+
*/
|
|
3910
4415
|
declare const MAX_OP_ID = "9223372036854775807";
|
|
3911
4416
|
|
|
4417
|
+
/**
|
|
4418
|
+
* @internal
|
|
4419
|
+
*/
|
|
3912
4420
|
declare function runOnSchemaChange(callback: (signal: AbortSignal) => void, db: AbstractPowerSyncDatabase, options?: SQLWatchOptions): void;
|
|
3913
4421
|
|
|
4422
|
+
/**
|
|
4423
|
+
* @internal
|
|
4424
|
+
*/
|
|
3914
4425
|
declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
|
|
3915
4426
|
private db;
|
|
3916
4427
|
private logger;
|
|
@@ -3944,6 +4455,8 @@ declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> im
|
|
|
3944
4455
|
* Thrown when an underlying database connection is closed.
|
|
3945
4456
|
* This is particularly relevant when worker connections are marked as closed while
|
|
3946
4457
|
* operations are still in progress.
|
|
4458
|
+
*
|
|
4459
|
+
* @internal
|
|
3947
4460
|
*/
|
|
3948
4461
|
declare class ConnectionClosedError extends Error {
|
|
3949
4462
|
static NAME: string;
|
|
@@ -3960,6 +4473,8 @@ declare const MEMORY_TRIGGER_CLAIM_MANAGER: TriggerClaimManager;
|
|
|
3960
4473
|
/**
|
|
3961
4474
|
* Helper function for sanitizing UUID input strings.
|
|
3962
4475
|
* Typically used with {@link sanitizeSQL}.
|
|
4476
|
+
*
|
|
4477
|
+
* @alpha
|
|
3963
4478
|
*/
|
|
3964
4479
|
declare function sanitizeUUID(uuid: string): string;
|
|
3965
4480
|
/**
|
|
@@ -3989,11 +4504,15 @@ declare function sanitizeUUID(uuid: string): string;
|
|
|
3989
4504
|
* // Incorrect:
|
|
3990
4505
|
* sanitizeSQL`New.id = '${myID}'` // Produces double quotes: New.id = ''O''Reilly''
|
|
3991
4506
|
* ```
|
|
4507
|
+
*
|
|
4508
|
+
* @alpha
|
|
3992
4509
|
*/
|
|
3993
4510
|
declare function sanitizeSQL(strings: TemplateStringsArray, ...values: any[]): string;
|
|
3994
4511
|
|
|
3995
4512
|
/**
|
|
3996
4513
|
* Options for {@link GetAllQuery}.
|
|
4514
|
+
*
|
|
4515
|
+
* @public
|
|
3997
4516
|
*/
|
|
3998
4517
|
type GetAllQueryOptions<RowType = unknown> = {
|
|
3999
4518
|
sql: string;
|
|
@@ -4012,6 +4531,8 @@ type GetAllQueryOptions<RowType = unknown> = {
|
|
|
4012
4531
|
};
|
|
4013
4532
|
/**
|
|
4014
4533
|
* Performs a {@link AbstractPowerSyncDatabase.getAll} operation for a watched query.
|
|
4534
|
+
*
|
|
4535
|
+
* @public
|
|
4015
4536
|
*/
|
|
4016
4537
|
declare class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<RowType[]> {
|
|
4017
4538
|
protected options: GetAllQueryOptions<RowType>;
|
|
@@ -4026,12 +4547,17 @@ declare class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<Row
|
|
|
4026
4547
|
* Calls to Abortcontroller.abort(reason: any) will result in the
|
|
4027
4548
|
* `reason` being thrown. This is not necessarily an error,
|
|
4028
4549
|
* but extends error for better logging purposes.
|
|
4550
|
+
*
|
|
4551
|
+
* @internal
|
|
4029
4552
|
*/
|
|
4030
4553
|
declare class AbortOperation extends Error {
|
|
4031
4554
|
protected reason: string;
|
|
4032
4555
|
constructor(reason: string);
|
|
4033
4556
|
}
|
|
4034
4557
|
|
|
4558
|
+
/**
|
|
4559
|
+
* @internal
|
|
4560
|
+
*/
|
|
4035
4561
|
interface ControlledExecutorOptions {
|
|
4036
4562
|
/**
|
|
4037
4563
|
* If throttling is enabled, it ensures only one task runs at a time,
|
|
@@ -4040,6 +4566,9 @@ interface ControlledExecutorOptions {
|
|
|
4040
4566
|
*/
|
|
4041
4567
|
throttleEnabled?: boolean;
|
|
4042
4568
|
}
|
|
4569
|
+
/**
|
|
4570
|
+
* @internal
|
|
4571
|
+
*/
|
|
4043
4572
|
declare class ControlledExecutor<T> {
|
|
4044
4573
|
private task;
|
|
4045
4574
|
/**
|
|
@@ -4058,10 +4587,16 @@ declare class ControlledExecutor<T> {
|
|
|
4058
4587
|
private execute;
|
|
4059
4588
|
}
|
|
4060
4589
|
|
|
4590
|
+
/**
|
|
4591
|
+
* @internal
|
|
4592
|
+
*/
|
|
4061
4593
|
interface ParsedQuery {
|
|
4062
4594
|
sqlStatement: string;
|
|
4063
4595
|
parameters: any[];
|
|
4064
4596
|
}
|
|
4597
|
+
/**
|
|
4598
|
+
* @internal
|
|
4599
|
+
*/
|
|
4065
4600
|
declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
|
|
4066
4601
|
|
|
4067
4602
|
export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DBAdapterDefaultMixin, DBGetUtilsDefaultMixin, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, Mutex, OnChangeQueryProcessor, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, Semaphore, SqliteBucketStorage, SyncClientImplementation, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID, timeoutSignal };
|