@powersync/common 2.4.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/CommonPowerSyncDatabase.d.ts +32 -8
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +85 -8
- package/lib/client/sync/options.d.ts +39 -5
- package/lib/client/sync/options.js.map +1 -1
- package/lib/client/sync/sync-streams.d.ts +3 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +4 -0
- package/lib/db/DBAdapter.js +4 -3
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +2 -2
- package/lib/db/schema/Table.d.ts +20 -3
- package/lib/db/schema/Table.js +10 -2
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/CommonPowerSyncDatabase.ts +33 -8
- package/src/client/connection/PowerSyncBackendConnector.ts +90 -8
- package/src/client/sync/options.ts +42 -5
- package/src/client/sync/sync-streams.ts +3 -0
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +4 -0
- package/src/db/DBAdapter.ts +6 -4
- package/src/db/crud/SyncStatus.ts +2 -2
- package/src/db/schema/Table.ts +29 -4
- package/src/index.ts +3 -1
|
@@ -7,7 +7,7 @@ import { PowerSyncLogger } from '../utils/Logger.js';
|
|
|
7
7
|
import { DatabaseSource } from './SQLOpenFactory.js';
|
|
8
8
|
import { TriggerManager } from './triggers/TriggerManager.js';
|
|
9
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
|
|
10
|
-
import { SyncOptions } from './sync/options.js';
|
|
10
|
+
import { DownloadOptions, SyncOptions, UploadOptions } from './sync/options.js';
|
|
11
11
|
import { SyncStream } from './sync/sync-streams.js';
|
|
12
12
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
13
13
|
import { CrudBatch } from './sync/bucket/CrudBatch.js';
|
|
@@ -28,7 +28,7 @@ export interface DisconnectAndClearOptions {
|
|
|
28
28
|
/**
|
|
29
29
|
* A [soft] clear deletes publicly visible tables, but keeps internal copies of data synced in the database.
|
|
30
30
|
*
|
|
31
|
-
* This usually means that if {@link CommonPowerSyncDatabase
|
|
31
|
+
* This usually means that if {@link CommonPowerSyncDatabase.(connect:1)} is later called again with a JWT from the same
|
|
32
32
|
* user, the first sync is very fast because all internal data is still available. When a different user logs in, no
|
|
33
33
|
* old data would be visible at any point. Using soft deletes is recommended where it's not a security issue that old
|
|
34
34
|
* data could be reconstructed from internal database tables.
|
|
@@ -182,7 +182,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
182
182
|
/**
|
|
183
183
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
184
184
|
*
|
|
185
|
-
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.connect}.
|
|
185
|
+
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.(connect:1)}.
|
|
186
186
|
*/
|
|
187
187
|
updateSchema(schema: Schema): Promise<void>;
|
|
188
188
|
/**
|
|
@@ -191,13 +191,29 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
191
191
|
*/
|
|
192
192
|
init(): Promise<void>;
|
|
193
193
|
/**
|
|
194
|
-
* Connects
|
|
194
|
+
* Connects this PowerSync database with a {@link PowerSyncBackendConnector}, the previous way to connect.
|
|
195
|
+
*
|
|
196
|
+
* Use an {@link Authenticator} and a {@link MutationUploader} instead: pass {@link DownloadOptions} and
|
|
197
|
+
* {@link UploadOptions} to `connect()`. We plan to deprecate backend connectors in a future release.
|
|
195
198
|
*/
|
|
196
199
|
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Connects this PowerSync database for downloading rows from your source database, uploading local mutations to your
|
|
202
|
+
* backend, or both.
|
|
203
|
+
*
|
|
204
|
+
* For downloads, {@link DownloadOptions} need to be provided. This includes the URL of the PowerSync service to
|
|
205
|
+
* connect to and a callback responsible for obtaining an authentication token.
|
|
206
|
+
* For uploads, {@link UploadOptions} provides a callback responsible for uploading local mutations to your backend.
|
|
207
|
+
*
|
|
208
|
+
* A single connect call can provide both download and upload options. Each call overrides all previous options. In
|
|
209
|
+
* particular, first calling connect with download options only and then again with upload options does not keep the
|
|
210
|
+
* download active. Provide both options in one call to sync both ways.
|
|
211
|
+
*/
|
|
212
|
+
connect(options: SyncOptions & (DownloadOptions | UploadOptions)): Promise<void>;
|
|
197
213
|
/**
|
|
198
214
|
* Close the sync connection.
|
|
199
215
|
*
|
|
200
|
-
* Use {@link CommonPowerSyncDatabase.connect} to connect again.
|
|
216
|
+
* Use {@link CommonPowerSyncDatabase.(connect:1)} to connect again.
|
|
201
217
|
*/
|
|
202
218
|
disconnect(): Promise<void>;
|
|
203
219
|
/**
|
|
@@ -207,6 +223,13 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
207
223
|
* would be empty.
|
|
208
224
|
*
|
|
209
225
|
* To preserve data in local-only tables, set clearLocal to false.
|
|
226
|
+
*
|
|
227
|
+
* This also clears all Sync Stream subscriptions. `SyncStreamSubscription` instances created before a clear
|
|
228
|
+
* are no longer requested when connecting again, even if they haven't been unsubscribed. To keep syncing a stream,
|
|
229
|
+
* call {@link SyncStream.subscribe} again after the clear and before calling `connect()`.
|
|
230
|
+
*
|
|
231
|
+
* The same applies to checkpoint requests. {@link CheckpointRequest} instances created before a clear should be
|
|
232
|
+
* discarded and requested again.
|
|
210
233
|
*/
|
|
211
234
|
disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
|
|
212
235
|
/**
|
|
@@ -247,7 +270,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
247
270
|
*
|
|
248
271
|
* Returns null if there is no data to upload.
|
|
249
272
|
*
|
|
250
|
-
* Use this from the {@link PowerSyncBackendConnector
|
|
273
|
+
* Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
251
274
|
*
|
|
252
275
|
* Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
|
|
253
276
|
* requesting the next batch.
|
|
@@ -268,7 +291,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
268
291
|
*
|
|
269
292
|
* Returns null if there is no data to upload.
|
|
270
293
|
*
|
|
271
|
-
* Use this from the {@link PowerSyncBackendConnector
|
|
294
|
+
* Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
272
295
|
*
|
|
273
296
|
* Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
|
|
274
297
|
* requesting the next transaction.
|
|
@@ -282,7 +305,8 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
282
305
|
/**
|
|
283
306
|
* Returns an async iterator of completed transactions with local writes against the database.
|
|
284
307
|
*
|
|
285
|
-
* This is typically used from
|
|
308
|
+
* This is typically used from your {@link MutationUploader} (or the `uploadData()` method of a
|
|
309
|
+
* {@link PowerSyncBackendConnector}). Each entry emitted by the
|
|
286
310
|
* returned iterator is a full transaction containing all local writes made while that transaction was active.
|
|
287
311
|
*
|
|
288
312
|
* Unlike {@link CommonPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
@@ -3,7 +3,32 @@ import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface PostCustomCheckpoints {
|
|
7
|
+
/**
|
|
8
|
+
* Posts a client-generated checkpoint request to the backend and returns the effective checkpoint request state.
|
|
9
|
+
*
|
|
10
|
+
* This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
|
|
11
|
+
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
12
|
+
* are used. In any other case, don't implement this method on your {@link Authenticator} or
|
|
13
|
+
* {@link PowerSyncBackendConnector}.
|
|
14
|
+
*
|
|
15
|
+
* @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
|
|
16
|
+
* @param clientId - The PowerSync client ID for the current device.
|
|
17
|
+
* @param signal - An optional abort signal that completes when the checkpoint is no longer necessary.
|
|
18
|
+
*/
|
|
19
|
+
postCheckpointRequest?(clientId: string, requestId: string, signal?: AbortSignal): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A backend connector is the previous way to connect: a single object that both provides authentication tokens and
|
|
23
|
+
* uploads local mutations.
|
|
24
|
+
*
|
|
25
|
+
* Use an {@link Authenticator} and a {@link MutationUploader} instead, and pass them to `connect()` with
|
|
26
|
+
* {@link DownloadOptions} and {@link UploadOptions}. They keep authentication and uploads separate, and you can connect
|
|
27
|
+
* for downloads or uploads only. We plan to deprecate backend connectors in a future release.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
|
|
7
32
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
8
33
|
* which is used to authenticate against the PowerSync service.
|
|
9
34
|
*
|
|
@@ -23,15 +48,67 @@ export interface PowerSyncBackendConnector {
|
|
|
23
48
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
24
49
|
*/
|
|
25
50
|
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Authenticates the PowerSync SDK against a PowerSync service, allowing it to download changes.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export interface Authenticator extends PostCustomCheckpoints {
|
|
26
58
|
/**
|
|
27
|
-
*
|
|
59
|
+
* Obtain a token used to authenticate against a PowerSync service.
|
|
28
60
|
*
|
|
29
|
-
*
|
|
30
|
-
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
31
|
-
* are used. In any other case, this method should not be present on backend connectors.
|
|
61
|
+
* Cache the token in your authenticator, since the SDK may call this method several times while connected.
|
|
32
62
|
*
|
|
33
|
-
* @param
|
|
34
|
-
*
|
|
63
|
+
* @param options - Options, including an abort signal completing when the SDK is no longer interested in these
|
|
64
|
+
* credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
|
|
65
|
+
* @returns A promise resolving to the token (a JWT). It may reject when the token could not be resolved.
|
|
66
|
+
*/
|
|
67
|
+
resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Called by the SDK when the token is about to expire, has expired, or has been rejected by the PowerSync Service.
|
|
70
|
+
*
|
|
71
|
+
* Subsequent calls to {@link Authenticator.resolveCredentials} should return a new token.
|
|
72
|
+
*/
|
|
73
|
+
invalidateCredentials?(): void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The signature of a function uploading local mutations to a backend.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export type MutationUploader = (options: UploadMutationsOptions) => Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Base interface for options with an abort signal.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface HasAbortSignal {
|
|
87
|
+
/**
|
|
88
|
+
* An optional abort signal, owned by the SDK.
|
|
89
|
+
*
|
|
90
|
+
* This signal completes when the SDK is no longer interested in the operation is triggered, e.g. because
|
|
91
|
+
* {@link CommonPowerSyncDatabase.disconnect} was called.
|
|
92
|
+
* Compatible {@link Authenticator} and {@link MutationUploader} implementations may use this to abort their work, but
|
|
93
|
+
* this is not required.
|
|
94
|
+
*/
|
|
95
|
+
abort?: AbortSignal;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Options passed to {@link Authenticator.resolveCredentials}.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export interface ResolveCredentialsOptions extends HasAbortSignal {
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Options passed to {@link MutationUploader}.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export interface UploadMutationsOptions extends HasAbortSignal {
|
|
110
|
+
/**
|
|
111
|
+
* The database on which {@link CommonPowerSyncDatabase.(connect:1)} has been called, for convenience.
|
|
35
112
|
*/
|
|
36
|
-
|
|
113
|
+
database: CommonPowerSyncDatabase;
|
|
37
114
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Authenticator, MutationUploader } from '../connection/PowerSyncBackendConnector.js';
|
|
1
2
|
import { StreamingSyncRequestParameterType } from './stream/JsonValue.js';
|
|
2
3
|
/**
|
|
3
4
|
* Options that affect how the PowerSync SDK connects to the PowerSync Service.
|
|
@@ -30,20 +31,27 @@ export interface SyncOptions {
|
|
|
30
31
|
*/
|
|
31
32
|
includeDefaultStreams?: boolean;
|
|
32
33
|
/**
|
|
33
|
-
* Delay for retrying sync streaming operations
|
|
34
|
-
*
|
|
34
|
+
* Delay, in milliseconds, for retrying sync streaming operations from the PowerSync backend or uploads of local
|
|
35
|
+
* mutations after an error occurs. This defaults to 5 seconds.
|
|
35
36
|
*/
|
|
36
37
|
retryDelayMs?: number;
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
* to occur at most every `crudUploadThrottleMs`
|
|
40
|
-
* milliseconds.
|
|
39
|
+
* Uploads of local mutations are throttled to occur at most every `crudUploadThrottleMs` milliseconds.
|
|
41
40
|
*/
|
|
42
41
|
crudUploadThrottleMs?: number;
|
|
43
42
|
/**
|
|
44
43
|
* The mode used to request checkpoints from the service (used after uploading local data).
|
|
45
44
|
*/
|
|
46
45
|
checkpointMode?: CheckpointMode;
|
|
46
|
+
/**
|
|
47
|
+
* How long to wait for the PowerSync Service to respond, in milliseconds. This defaults to 30 seconds.
|
|
48
|
+
*
|
|
49
|
+
* For checkpoint requests, this limits the whole request. For the sync stream over HTTP, this limits the time until
|
|
50
|
+
* the response starts, not how long the stream stays open. WebSocket connections use their own timeouts.
|
|
51
|
+
*
|
|
52
|
+
* A request that takes longer fails and is retried after {@link SyncOptions.retryDelayMs}.
|
|
53
|
+
*/
|
|
54
|
+
connectTimeoutMs?: number;
|
|
47
55
|
/**
|
|
48
56
|
* Enables the core extension's diagnostics event stream: detailed per-bucket download stats,
|
|
49
57
|
* including each bucket's `target_count`, and inferred column types. Off by default.
|
|
@@ -53,6 +61,32 @@ export interface SyncOptions {
|
|
|
53
61
|
*/
|
|
54
62
|
diagnostics?: boolean;
|
|
55
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Options required when connecting a PowerSync database for downloads.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface DownloadOptions {
|
|
70
|
+
/**
|
|
71
|
+
* The hostname of the PowerSync service to connect to.
|
|
72
|
+
*/
|
|
73
|
+
powerSyncEndpoint: string;
|
|
74
|
+
/**
|
|
75
|
+
* The authenticator responsible for providing authentication tokens to the PowerSync service.
|
|
76
|
+
*/
|
|
77
|
+
authenticator: Authenticator;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Options required when connecting a PowerSync database for uploads.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export interface UploadOptions {
|
|
85
|
+
/**
|
|
86
|
+
* The function responsible for uploading local mutations.
|
|
87
|
+
*/
|
|
88
|
+
upload: MutationUploader;
|
|
89
|
+
}
|
|
56
90
|
/**
|
|
57
91
|
* @public
|
|
58
92
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/sync/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/sync/options.ts"],"names":[],"mappings":"AAwGA;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,2CAAa,CAAA;IACb,uDAAyB,CAAA;AAC3B,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB;;;OAGG;IACH,sCAAqB,CAAA;IAErB;;;OAGG;IACH,0CAAyB,CAAA;AAC3B,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB"}
|
|
@@ -89,6 +89,9 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
89
89
|
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
90
90
|
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
91
91
|
* eventually evict the stream (unless {@link SyncStream.subscribe} is called again).
|
|
92
|
+
*
|
|
93
|
+
* Subscriptions do not survive {@link CommonPowerSyncDatabase.disconnectAndClear}. After a clear, call `subscribe()`
|
|
94
|
+
* again for streams that should keep syncing, before calling `connect()`.
|
|
92
95
|
*/
|
|
93
96
|
subscribe(options?: SyncStreamSubscribeOptions): Promise<SyncStreamSubscription>;
|
|
94
97
|
/**
|
|
@@ -83,6 +83,10 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
|
|
|
83
83
|
* @public
|
|
84
84
|
*/
|
|
85
85
|
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
|
|
86
|
+
/**
|
|
87
|
+
* Called when the result set has changed.
|
|
88
|
+
* This also fires if rows have only been reordered, in which case `added`, `removed` and `updated` are empty.
|
|
89
|
+
*/
|
|
86
90
|
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
87
91
|
}
|
|
88
92
|
/**
|
package/lib/db/DBAdapter.js
CHANGED
|
@@ -106,18 +106,19 @@ class TransactionImplementation extends LockContext {
|
|
|
106
106
|
}
|
|
107
107
|
static async runWith(ctx, fn) {
|
|
108
108
|
let tx = new TransactionImplementation(ctx);
|
|
109
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
109
110
|
try {
|
|
110
|
-
await ctx.execute('BEGIN IMMEDIATE');
|
|
111
111
|
const result = await fn(tx);
|
|
112
112
|
await tx.commit();
|
|
113
113
|
return result;
|
|
114
114
|
}
|
|
115
115
|
catch (ex) {
|
|
116
|
+
tx.finalized = true;
|
|
116
117
|
try {
|
|
117
|
-
await
|
|
118
|
+
await ctx.execute('ROLLBACK');
|
|
118
119
|
}
|
|
119
120
|
catch (ex2) {
|
|
120
|
-
// In rare cases, a rollback may fail.
|
|
121
|
+
// In rare cases, a rollback may fail (e.g. if user code invoked commit() and then threw afterwards).
|
|
121
122
|
// Safe to ignore.
|
|
122
123
|
}
|
|
123
124
|
throw ex;
|
package/lib/db/DBAdapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBAdapter.js","sourceRoot":"","sources":["../../src/db/DBAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAEL,kBAAkB,EAClB,sBAAsB,EAGvB,MAAM,kBAAkB,CAAC;AAyE1B;;GAEG;AACH,MAAM,OAAgB,WAAW;IAG/B,KAAK,CAAC,MAAM,CAAI,GAAW,EAAE,UAAkB;QAC7C,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,UAAU,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CAAI,GAAW,EAAE,UAAkB;QAClD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAA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C;QACtB,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAI,KAAa,EAAE,MAA0B;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,MAA0B;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,MAAgB;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAmC;QAC3E,IAAI,EAAE,GAAG,IAAI,yBAAyB,CAAC,GAAG,CAAC,CAAC;QAE5C,MAAM,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAErC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC;YAEpB,IAAI,CAAC;gBACH,MAAM,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,qGAAqG;gBACrG,kBAAkB;YACpB,CAAC;YACD,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;CACF"}
|
|
@@ -48,8 +48,8 @@ export interface SyncStatus {
|
|
|
48
48
|
*/
|
|
49
49
|
get downloading(): boolean;
|
|
50
50
|
/**
|
|
51
|
-
* Whether the PowerSync SDK is currently uploading local mutations through the configured
|
|
52
|
-
* {@link PowerSyncBackendConnector}.
|
|
51
|
+
* Whether the PowerSync SDK is currently uploading local mutations through the configured {@link MutationUploader}
|
|
52
|
+
* (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
53
53
|
*/
|
|
54
54
|
get uploading(): boolean;
|
|
55
55
|
/**
|
package/lib/db/schema/Table.d.ts
CHANGED
|
@@ -15,11 +15,26 @@ export interface TableOrRawTableOptions {
|
|
|
15
15
|
}
|
|
16
16
|
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
17
17
|
viewName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Marks this table as a managed table.
|
|
20
|
+
*
|
|
21
|
+
* Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
|
|
22
|
+
* a JSON store.
|
|
23
|
+
*
|
|
24
|
+
* The table is still managed by the PowerSync SDK, which is responsible for creating, altering and dropping them.
|
|
25
|
+
* You can query managed tables like managed views, and mutations are consistently tracked as pending uploads.
|
|
26
|
+
* For more information on managed tables, see [the documentation](https://docs.powersync.com/client-sdks/advanced/performance-optimization#managed-views-vs-managed-tables).
|
|
27
|
+
*
|
|
28
|
+
* Managed tables can't use a {@link ResolvedTableOptions.viewName}.
|
|
29
|
+
*
|
|
30
|
+
* @beta Managed tables are currently in beta.
|
|
31
|
+
*/
|
|
32
|
+
direct?: boolean;
|
|
18
33
|
}
|
|
19
34
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
20
35
|
*
|
|
21
|
-
* Including old values may be helpful for some
|
|
22
|
-
* why it can be enabled on per-table or per-
|
|
36
|
+
* Including old values may be helpful for some mutation uploader implementations, which is
|
|
37
|
+
* why it can be enabled on per-table or per-column basis.
|
|
23
38
|
*
|
|
24
39
|
* @public
|
|
25
40
|
*/
|
|
@@ -78,6 +93,7 @@ export declare class ResolvedTable {
|
|
|
78
93
|
get trackPrevious(): boolean | TrackPreviousOptions;
|
|
79
94
|
get trackMetadata(): boolean;
|
|
80
95
|
get ignoreEmptyUpdates(): boolean;
|
|
96
|
+
get direct(): boolean | undefined;
|
|
81
97
|
get internalName(): string;
|
|
82
98
|
get validName(): boolean;
|
|
83
99
|
validate(): void;
|
|
@@ -89,7 +105,7 @@ export declare class ResolvedTable {
|
|
|
89
105
|
include_metadata: boolean | undefined;
|
|
90
106
|
ignore_empty_update: boolean | undefined;
|
|
91
107
|
name: string;
|
|
92
|
-
view_name: string;
|
|
108
|
+
view_name: string | undefined;
|
|
93
109
|
columns: {
|
|
94
110
|
name: string;
|
|
95
111
|
type: import("./Column.js").ColumnType | undefined;
|
|
@@ -102,6 +118,7 @@ export declare class ResolvedTable {
|
|
|
102
118
|
type: import("./Column.js").ColumnType;
|
|
103
119
|
}[];
|
|
104
120
|
}[];
|
|
121
|
+
direct: boolean | undefined;
|
|
105
122
|
};
|
|
106
123
|
private applyDefaultOptions;
|
|
107
124
|
}
|
package/lib/db/schema/Table.js
CHANGED
|
@@ -59,6 +59,9 @@ export class ResolvedTable {
|
|
|
59
59
|
get ignoreEmptyUpdates() {
|
|
60
60
|
return this.options.ignoreEmptyUpdates;
|
|
61
61
|
}
|
|
62
|
+
get direct() {
|
|
63
|
+
return this.options.direct;
|
|
64
|
+
}
|
|
62
65
|
get internalName() {
|
|
63
66
|
if (this.options.localOnly) {
|
|
64
67
|
return `ps_data_local__${this.name}`;
|
|
@@ -120,13 +123,17 @@ export class ResolvedTable {
|
|
|
120
123
|
}
|
|
121
124
|
indexNames.add(index.name);
|
|
122
125
|
}
|
|
126
|
+
if (this.direct && this.viewNameOverride != null) {
|
|
127
|
+
throw new Error(`Direct table ${this.name} can't use a view name override`);
|
|
128
|
+
}
|
|
123
129
|
}
|
|
124
130
|
toJSON() {
|
|
125
131
|
return {
|
|
126
132
|
name: this.name,
|
|
127
|
-
view_name: this.
|
|
133
|
+
view_name: this.viewNameOverride,
|
|
128
134
|
columns: this.columns.map((c) => c.toJSON()),
|
|
129
135
|
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
136
|
+
direct: this.direct,
|
|
130
137
|
...encodeTableOptions(this)
|
|
131
138
|
};
|
|
132
139
|
}
|
|
@@ -197,7 +204,8 @@ export class Table extends ResolvedTable {
|
|
|
197
204
|
localOnly: options?.localOnly,
|
|
198
205
|
trackPrevious: options?.trackPrevious,
|
|
199
206
|
trackMetadata: options?.trackMetadata,
|
|
200
|
-
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
207
|
+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates,
|
|
208
|
+
direct: options?.direct
|
|
201
209
|
};
|
|
202
210
|
}
|
|
203
211
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAgFnC,MAAM,qBAAqB,GAAG;IAC5B,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,KAAK;IACpB,kBAAkB,EAAE,KAAK;CAC1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CAAC,CAAC,IAAI,aAAa,CAAC;oBAChB,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;oBAC3C,SAAS,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,GAAG,CAAC;iBAChD,CAAC;gBACJ,CAAC,CAAC,mBAAmB,CACxB;SACF,CAAC,CACL,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,gBAAgB;YACzB,QAAQ,EAAE,OAAO,EAAE,QAAQ;YAC3B,UAAU,EAAE,OAAO,EAAE,UAAU;YAC/B,SAAS,EAAE,OAAO,EAAE,SAAS;YAC7B,aAAa,EAAE,OAAO,EAAE,aAAa;YACrC,aAAa,EAAE,OAAO,EAAE,aAAa;YACrC,kBAAkB,EAAE,OAAO,EAAE,kBAAkB;YAC/C,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC;IACJ,CAAC;CACF"}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * from './client/sync/bucket/CrudTransaction.js';
|
|
|
17
17
|
export * from './client/sync/CheckpointRequest.js';
|
|
18
18
|
export * from './client/sync/stream/JsonValue.js';
|
|
19
19
|
export * from './client/sync/sync-streams.js';
|
|
20
|
-
export { SyncOptions, SyncStreamConnectionMethod, FetchStrategy, CheckpointMode, CheckpointRequestsOptions } from './client/sync/options.js';
|
|
20
|
+
export { SyncOptions, SyncStreamConnectionMethod, FetchStrategy, CheckpointMode, CheckpointRequestsOptions, DownloadOptions, UploadOptions } from './client/sync/options.js';
|
|
21
21
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|
|
22
22
|
export * from './db/crud/SyncStatus.js';
|
|
23
23
|
export * from './db/crud/UploadQueueStatus.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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AAC;AAC9C,OAAO,EAEL,0BAA0B,EAC1B,aAAa,EAKd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,kCAAkC,CAAC;AAGjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAElC,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ import { PowerSyncLogger } from '../utils/Logger.js';
|
|
|
7
7
|
import { DatabaseSource } from './SQLOpenFactory.js';
|
|
8
8
|
import { TriggerManager } from './triggers/TriggerManager.js';
|
|
9
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
|
|
10
|
-
import { SyncOptions } from './sync/options.js';
|
|
10
|
+
import { DownloadOptions, SyncOptions, UploadOptions } from './sync/options.js';
|
|
11
11
|
import { SyncStream } from './sync/sync-streams.js';
|
|
12
12
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
13
13
|
import { CrudBatch } from './sync/bucket/CrudBatch.js';
|
|
@@ -29,7 +29,7 @@ export interface DisconnectAndClearOptions {
|
|
|
29
29
|
/**
|
|
30
30
|
* A [soft] clear deletes publicly visible tables, but keeps internal copies of data synced in the database.
|
|
31
31
|
*
|
|
32
|
-
* This usually means that if {@link CommonPowerSyncDatabase
|
|
32
|
+
* This usually means that if {@link CommonPowerSyncDatabase.(connect:1)} is later called again with a JWT from the same
|
|
33
33
|
* user, the first sync is very fast because all internal data is still available. When a different user logs in, no
|
|
34
34
|
* old data would be visible at any point. Using soft deletes is recommended where it's not a security issue that old
|
|
35
35
|
* data could be reconstructed from internal database tables.
|
|
@@ -204,7 +204,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
204
204
|
/**
|
|
205
205
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
206
206
|
*
|
|
207
|
-
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.connect}.
|
|
207
|
+
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.(connect:1)}.
|
|
208
208
|
*/
|
|
209
209
|
updateSchema(schema: Schema): Promise<void>;
|
|
210
210
|
|
|
@@ -215,14 +215,31 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
215
215
|
init(): Promise<void>;
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
* Connects
|
|
218
|
+
* Connects this PowerSync database with a {@link PowerSyncBackendConnector}, the previous way to connect.
|
|
219
|
+
*
|
|
220
|
+
* Use an {@link Authenticator} and a {@link MutationUploader} instead: pass {@link DownloadOptions} and
|
|
221
|
+
* {@link UploadOptions} to `connect()`. We plan to deprecate backend connectors in a future release.
|
|
219
222
|
*/
|
|
220
223
|
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
221
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Connects this PowerSync database for downloading rows from your source database, uploading local mutations to your
|
|
227
|
+
* backend, or both.
|
|
228
|
+
*
|
|
229
|
+
* For downloads, {@link DownloadOptions} need to be provided. This includes the URL of the PowerSync service to
|
|
230
|
+
* connect to and a callback responsible for obtaining an authentication token.
|
|
231
|
+
* For uploads, {@link UploadOptions} provides a callback responsible for uploading local mutations to your backend.
|
|
232
|
+
*
|
|
233
|
+
* A single connect call can provide both download and upload options. Each call overrides all previous options. In
|
|
234
|
+
* particular, first calling connect with download options only and then again with upload options does not keep the
|
|
235
|
+
* download active. Provide both options in one call to sync both ways.
|
|
236
|
+
*/
|
|
237
|
+
connect(options: SyncOptions & (DownloadOptions | UploadOptions)): Promise<void>;
|
|
238
|
+
|
|
222
239
|
/**
|
|
223
240
|
* Close the sync connection.
|
|
224
241
|
*
|
|
225
|
-
* Use {@link CommonPowerSyncDatabase.connect} to connect again.
|
|
242
|
+
* Use {@link CommonPowerSyncDatabase.(connect:1)} to connect again.
|
|
226
243
|
*/
|
|
227
244
|
disconnect(): Promise<void>;
|
|
228
245
|
|
|
@@ -233,6 +250,13 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
233
250
|
* would be empty.
|
|
234
251
|
*
|
|
235
252
|
* To preserve data in local-only tables, set clearLocal to false.
|
|
253
|
+
*
|
|
254
|
+
* This also clears all Sync Stream subscriptions. `SyncStreamSubscription` instances created before a clear
|
|
255
|
+
* are no longer requested when connecting again, even if they haven't been unsubscribed. To keep syncing a stream,
|
|
256
|
+
* call {@link SyncStream.subscribe} again after the clear and before calling `connect()`.
|
|
257
|
+
*
|
|
258
|
+
* The same applies to checkpoint requests. {@link CheckpointRequest} instances created before a clear should be
|
|
259
|
+
* discarded and requested again.
|
|
236
260
|
*/
|
|
237
261
|
disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
|
|
238
262
|
|
|
@@ -278,7 +302,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
278
302
|
*
|
|
279
303
|
* Returns null if there is no data to upload.
|
|
280
304
|
*
|
|
281
|
-
* Use this from the {@link PowerSyncBackendConnector
|
|
305
|
+
* Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
282
306
|
*
|
|
283
307
|
* Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
|
|
284
308
|
* requesting the next batch.
|
|
@@ -300,7 +324,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
300
324
|
*
|
|
301
325
|
* Returns null if there is no data to upload.
|
|
302
326
|
*
|
|
303
|
-
* Use this from the {@link PowerSyncBackendConnector
|
|
327
|
+
* Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
304
328
|
*
|
|
305
329
|
* Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
|
|
306
330
|
* requesting the next transaction.
|
|
@@ -315,7 +339,8 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
|
|
|
315
339
|
/**
|
|
316
340
|
* Returns an async iterator of completed transactions with local writes against the database.
|
|
317
341
|
*
|
|
318
|
-
* This is typically used from
|
|
342
|
+
* This is typically used from your {@link MutationUploader} (or the `uploadData()` method of a
|
|
343
|
+
* {@link PowerSyncBackendConnector}). Each entry emitted by the
|
|
319
344
|
* returned iterator is a full transaction containing all local writes made while that transaction was active.
|
|
320
345
|
*
|
|
321
346
|
* Unlike {@link CommonPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
@@ -4,7 +4,33 @@ import { CommonPowerSyncDatabase } from '../CommonPowerSyncDatabase.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface PostCustomCheckpoints {
|
|
8
|
+
/**
|
|
9
|
+
* Posts a client-generated checkpoint request to the backend and returns the effective checkpoint request state.
|
|
10
|
+
*
|
|
11
|
+
* This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
|
|
12
|
+
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
13
|
+
* are used. In any other case, don't implement this method on your {@link Authenticator} or
|
|
14
|
+
* {@link PowerSyncBackendConnector}.
|
|
15
|
+
*
|
|
16
|
+
* @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
|
|
17
|
+
* @param clientId - The PowerSync client ID for the current device.
|
|
18
|
+
* @param signal - An optional abort signal that completes when the checkpoint is no longer necessary.
|
|
19
|
+
*/
|
|
20
|
+
postCheckpointRequest?(clientId: string, requestId: string, signal?: AbortSignal): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A backend connector is the previous way to connect: a single object that both provides authentication tokens and
|
|
25
|
+
* uploads local mutations.
|
|
26
|
+
*
|
|
27
|
+
* Use an {@link Authenticator} and a {@link MutationUploader} instead, and pass them to `connect()` with
|
|
28
|
+
* {@link DownloadOptions} and {@link UploadOptions}. They keep authentication and uploads separate, and you can connect
|
|
29
|
+
* for downloads or uploads only. We plan to deprecate backend connectors in a future release.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
|
|
8
34
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
9
35
|
* which is used to authenticate against the PowerSync service.
|
|
10
36
|
*
|
|
@@ -25,16 +51,72 @@ export interface PowerSyncBackendConnector {
|
|
|
25
51
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
26
52
|
*/
|
|
27
53
|
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
54
|
+
}
|
|
28
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Authenticates the PowerSync SDK against a PowerSync service, allowing it to download changes.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export interface Authenticator extends PostCustomCheckpoints {
|
|
29
62
|
/**
|
|
30
|
-
*
|
|
63
|
+
* Obtain a token used to authenticate against a PowerSync service.
|
|
31
64
|
*
|
|
32
|
-
*
|
|
33
|
-
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
34
|
-
* are used. In any other case, this method should not be present on backend connectors.
|
|
65
|
+
* Cache the token in your authenticator, since the SDK may call this method several times while connected.
|
|
35
66
|
*
|
|
36
|
-
* @param
|
|
37
|
-
*
|
|
67
|
+
* @param options - Options, including an abort signal completing when the SDK is no longer interested in these
|
|
68
|
+
* credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
|
|
69
|
+
* @returns A promise resolving to the token (a JWT). It may reject when the token could not be resolved.
|
|
70
|
+
*/
|
|
71
|
+
resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Called by the SDK when the token is about to expire, has expired, or has been rejected by the PowerSync Service.
|
|
75
|
+
*
|
|
76
|
+
* Subsequent calls to {@link Authenticator.resolveCredentials} should return a new token.
|
|
77
|
+
*/
|
|
78
|
+
invalidateCredentials?(): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The signature of a function uploading local mutations to a backend.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export type MutationUploader = (options: UploadMutationsOptions) => Promise<void>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Base interface for options with an abort signal.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export interface HasAbortSignal {
|
|
94
|
+
/**
|
|
95
|
+
* An optional abort signal, owned by the SDK.
|
|
96
|
+
*
|
|
97
|
+
* This signal completes when the SDK is no longer interested in the operation is triggered, e.g. because
|
|
98
|
+
* {@link CommonPowerSyncDatabase.disconnect} was called.
|
|
99
|
+
* Compatible {@link Authenticator} and {@link MutationUploader} implementations may use this to abort their work, but
|
|
100
|
+
* this is not required.
|
|
101
|
+
*/
|
|
102
|
+
abort?: AbortSignal;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Options passed to {@link Authenticator.resolveCredentials}.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
export interface ResolveCredentialsOptions extends HasAbortSignal {}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Options passed to {@link MutationUploader}.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export interface UploadMutationsOptions extends HasAbortSignal {
|
|
118
|
+
/**
|
|
119
|
+
* The database on which {@link CommonPowerSyncDatabase.(connect:1)} has been called, for convenience.
|
|
38
120
|
*/
|
|
39
|
-
|
|
121
|
+
database: CommonPowerSyncDatabase;
|
|
40
122
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Authenticator, MutationUploader } from '../connection/PowerSyncBackendConnector.js';
|
|
1
2
|
import { StreamingSyncRequestParameterType } from './stream/JsonValue.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -38,15 +39,13 @@ export interface SyncOptions {
|
|
|
38
39
|
includeDefaultStreams?: boolean;
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
|
-
* Delay for retrying sync streaming operations
|
|
42
|
-
*
|
|
42
|
+
* Delay, in milliseconds, for retrying sync streaming operations from the PowerSync backend or uploads of local
|
|
43
|
+
* mutations after an error occurs. This defaults to 5 seconds.
|
|
43
44
|
*/
|
|
44
45
|
retryDelayMs?: number;
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* to occur at most every `crudUploadThrottleMs`
|
|
49
|
-
* milliseconds.
|
|
48
|
+
* Uploads of local mutations are throttled to occur at most every `crudUploadThrottleMs` milliseconds.
|
|
50
49
|
*/
|
|
51
50
|
crudUploadThrottleMs?: number;
|
|
52
51
|
|
|
@@ -55,6 +54,16 @@ export interface SyncOptions {
|
|
|
55
54
|
*/
|
|
56
55
|
checkpointMode?: CheckpointMode;
|
|
57
56
|
|
|
57
|
+
/**
|
|
58
|
+
* How long to wait for the PowerSync Service to respond, in milliseconds. This defaults to 30 seconds.
|
|
59
|
+
*
|
|
60
|
+
* For checkpoint requests, this limits the whole request. For the sync stream over HTTP, this limits the time until
|
|
61
|
+
* the response starts, not how long the stream stays open. WebSocket connections use their own timeouts.
|
|
62
|
+
*
|
|
63
|
+
* A request that takes longer fails and is retried after {@link SyncOptions.retryDelayMs}.
|
|
64
|
+
*/
|
|
65
|
+
connectTimeoutMs?: number;
|
|
66
|
+
|
|
58
67
|
/**
|
|
59
68
|
* Enables the core extension's diagnostics event stream: detailed per-bucket download stats,
|
|
60
69
|
* including each bucket's `target_count`, and inferred column types. Off by default.
|
|
@@ -65,6 +74,34 @@ export interface SyncOptions {
|
|
|
65
74
|
diagnostics?: boolean;
|
|
66
75
|
}
|
|
67
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Options required when connecting a PowerSync database for downloads.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export interface DownloadOptions {
|
|
83
|
+
/**
|
|
84
|
+
* The hostname of the PowerSync service to connect to.
|
|
85
|
+
*/
|
|
86
|
+
powerSyncEndpoint: string;
|
|
87
|
+
/**
|
|
88
|
+
* The authenticator responsible for providing authentication tokens to the PowerSync service.
|
|
89
|
+
*/
|
|
90
|
+
authenticator: Authenticator;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Options required when connecting a PowerSync database for uploads.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export interface UploadOptions {
|
|
99
|
+
/**
|
|
100
|
+
* The function responsible for uploading local mutations.
|
|
101
|
+
*/
|
|
102
|
+
upload: MutationUploader;
|
|
103
|
+
}
|
|
104
|
+
|
|
68
105
|
/**
|
|
69
106
|
* @public
|
|
70
107
|
*/
|
|
@@ -93,6 +93,9 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
93
93
|
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
94
94
|
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
95
95
|
* eventually evict the stream (unless {@link SyncStream.subscribe} is called again).
|
|
96
|
+
*
|
|
97
|
+
* Subscriptions do not survive {@link CommonPowerSyncDatabase.disconnectAndClear}. After a clear, call `subscribe()`
|
|
98
|
+
* again for streams that should keep syncing, before calling `connect()`.
|
|
96
99
|
*/
|
|
97
100
|
subscribe(options?: SyncStreamSubscribeOptions): Promise<SyncStreamSubscription>;
|
|
98
101
|
|
|
@@ -92,6 +92,10 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
|
|
|
92
92
|
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<
|
|
93
93
|
ReadonlyArray<Readonly<RowType>>
|
|
94
94
|
> {
|
|
95
|
+
/**
|
|
96
|
+
* Called when the result set has changed.
|
|
97
|
+
* This also fires if rows have only been reordered, in which case `added`, `removed` and `updated` are empty.
|
|
98
|
+
*/
|
|
95
99
|
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
|
|
96
100
|
}
|
|
97
101
|
|
package/src/db/DBAdapter.ts
CHANGED
|
@@ -258,17 +258,19 @@ class TransactionImplementation extends LockContext {
|
|
|
258
258
|
static async runWith<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {
|
|
259
259
|
let tx = new TransactionImplementation(ctx);
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
await ctx.execute('BEGIN IMMEDIATE');
|
|
261
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
263
262
|
|
|
263
|
+
try {
|
|
264
264
|
const result = await fn(tx);
|
|
265
265
|
await tx.commit();
|
|
266
266
|
return result;
|
|
267
267
|
} catch (ex) {
|
|
268
|
+
tx.finalized = true;
|
|
269
|
+
|
|
268
270
|
try {
|
|
269
|
-
await
|
|
271
|
+
await ctx.execute('ROLLBACK');
|
|
270
272
|
} catch (ex2) {
|
|
271
|
-
// In rare cases, a rollback may fail.
|
|
273
|
+
// In rare cases, a rollback may fail (e.g. if user code invoked commit() and then threw afterwards).
|
|
272
274
|
// Safe to ignore.
|
|
273
275
|
}
|
|
274
276
|
throw ex;
|
|
@@ -54,8 +54,8 @@ export interface SyncStatus {
|
|
|
54
54
|
get downloading(): boolean;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Whether the PowerSync SDK is currently uploading local mutations through the configured
|
|
58
|
-
* {@link PowerSyncBackendConnector}.
|
|
57
|
+
* Whether the PowerSync SDK is currently uploading local mutations through the configured {@link MutationUploader}
|
|
58
|
+
* (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
|
|
59
59
|
*/
|
|
60
60
|
get uploading(): boolean;
|
|
61
61
|
|
package/src/db/schema/Table.ts
CHANGED
|
@@ -24,12 +24,27 @@ export interface TableOrRawTableOptions {
|
|
|
24
24
|
|
|
25
25
|
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
26
26
|
viewName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Marks this table as a managed table.
|
|
29
|
+
*
|
|
30
|
+
* Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
|
|
31
|
+
* a JSON store.
|
|
32
|
+
*
|
|
33
|
+
* The table is still managed by the PowerSync SDK, which is responsible for creating, altering and dropping them.
|
|
34
|
+
* You can query managed tables like managed views, and mutations are consistently tracked as pending uploads.
|
|
35
|
+
* For more information on managed tables, see [the documentation](https://docs.powersync.com/client-sdks/advanced/performance-optimization#managed-views-vs-managed-tables).
|
|
36
|
+
*
|
|
37
|
+
* Managed tables can't use a {@link ResolvedTableOptions.viewName}.
|
|
38
|
+
*
|
|
39
|
+
* @beta Managed tables are currently in beta.
|
|
40
|
+
*/
|
|
41
|
+
direct?: boolean;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
30
45
|
*
|
|
31
|
-
* Including old values may be helpful for some
|
|
32
|
-
* why it can be enabled on per-table or per-
|
|
46
|
+
* Including old values may be helpful for some mutation uploader implementations, which is
|
|
47
|
+
* why it can be enabled on per-table or per-column basis.
|
|
33
48
|
*
|
|
34
49
|
* @public
|
|
35
50
|
*/
|
|
@@ -135,6 +150,10 @@ export class ResolvedTable {
|
|
|
135
150
|
return this.options.ignoreEmptyUpdates!;
|
|
136
151
|
}
|
|
137
152
|
|
|
153
|
+
get direct() {
|
|
154
|
+
return this.options.direct;
|
|
155
|
+
}
|
|
156
|
+
|
|
138
157
|
get internalName() {
|
|
139
158
|
if (this.options.localOnly) {
|
|
140
159
|
return `ps_data_local__${this.name}`;
|
|
@@ -206,14 +225,19 @@ export class ResolvedTable {
|
|
|
206
225
|
|
|
207
226
|
indexNames.add(index.name);
|
|
208
227
|
}
|
|
228
|
+
|
|
229
|
+
if (this.direct && this.viewNameOverride != null) {
|
|
230
|
+
throw new Error(`Direct table ${this.name} can't use a view name override`);
|
|
231
|
+
}
|
|
209
232
|
}
|
|
210
233
|
|
|
211
234
|
toJSON() {
|
|
212
235
|
return {
|
|
213
236
|
name: this.name,
|
|
214
|
-
view_name: this.
|
|
237
|
+
view_name: this.viewNameOverride,
|
|
215
238
|
columns: this.columns.map((c) => c.toJSON()),
|
|
216
239
|
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
240
|
+
direct: this.direct,
|
|
217
241
|
...encodeTableOptions(this)
|
|
218
242
|
};
|
|
219
243
|
}
|
|
@@ -303,7 +327,8 @@ export class Table<Columns extends ColumnsType = ColumnsType> extends ResolvedTa
|
|
|
303
327
|
localOnly: options?.localOnly,
|
|
304
328
|
trackPrevious: options?.trackPrevious,
|
|
305
329
|
trackMetadata: options?.trackMetadata,
|
|
306
|
-
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
|
|
330
|
+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates,
|
|
331
|
+
direct: options?.direct
|
|
307
332
|
};
|
|
308
333
|
}
|
|
309
334
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,9 @@ export {
|
|
|
23
23
|
SyncStreamConnectionMethod,
|
|
24
24
|
FetchStrategy,
|
|
25
25
|
CheckpointMode,
|
|
26
|
-
CheckpointRequestsOptions
|
|
26
|
+
CheckpointRequestsOptions,
|
|
27
|
+
DownloadOptions,
|
|
28
|
+
UploadOptions
|
|
27
29
|
} from './client/sync/options.js';
|
|
28
30
|
|
|
29
31
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|