@powersync/common 2.5.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.
@@ -191,7 +191,10 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
191
191
  */
192
192
  init(): Promise<void>;
193
193
  /**
194
- * Connects to stream of events from the PowerSync instance.
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>;
197
200
  /**
@@ -220,6 +223,13 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
220
223
  * would be empty.
221
224
  *
222
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.
223
233
  */
224
234
  disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
225
235
  /**
@@ -260,7 +270,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
260
270
  *
261
271
  * Returns null if there is no data to upload.
262
272
  *
263
- * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
273
+ * Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
264
274
  *
265
275
  * Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
266
276
  * requesting the next batch.
@@ -281,7 +291,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
281
291
  *
282
292
  * Returns null if there is no data to upload.
283
293
  *
284
- * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
294
+ * Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
285
295
  *
286
296
  * Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
287
297
  * requesting the next transaction.
@@ -295,7 +305,8 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
295
305
  /**
296
306
  * Returns an async iterator of completed transactions with local writes against the database.
297
307
  *
298
- * This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
308
+ * This is typically used from your {@link MutationUploader} (or the `uploadData()` method of a
309
+ * {@link PowerSyncBackendConnector}). Each entry emitted by the
299
310
  * returned iterator is a full transaction containing all local writes made while that transaction was active.
300
311
  *
301
312
  * Unlike {@link CommonPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
@@ -9,7 +9,8 @@ export interface PostCustomCheckpoints {
9
9
  *
10
10
  * This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
11
11
  * and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
12
- * are used. In any other case, this method should not be present on backend connectors.
12
+ * are used. In any other case, don't implement this method on your {@link Authenticator} or
13
+ * {@link PowerSyncBackendConnector}.
13
14
  *
14
15
  * @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
15
16
  * @param clientId - The PowerSync client ID for the current device.
@@ -18,6 +19,13 @@ export interface PostCustomCheckpoints {
18
19
  postCheckpointRequest?(clientId: string, requestId: string, signal?: AbortSignal): Promise<string>;
19
20
  }
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
+ *
21
29
  * @public
22
30
  */
23
31
  export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
@@ -50,16 +58,17 @@ export interface Authenticator extends PostCustomCheckpoints {
50
58
  /**
51
59
  * Obtain a token used to authenticate against a PowerSync service.
52
60
  *
61
+ * Cache the token in your authenticator, since the SDK may call this method several times while connected.
62
+ *
53
63
  * @param options - Options, including an abort signal completing when the SDK is no longer interested in these
54
64
  * credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
55
- * @returns A promise resolving to PowerSync credentials. It may reject when credentials could not be resolved.
65
+ * @returns A promise resolving to the token (a JWT). It may reject when the token could not be resolved.
56
66
  */
57
67
  resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
58
68
  /**
59
- * Invoked by the SDK when the PowerSync service has rejected credentials previously returned by
60
- * {@link Authenticator.resolveCredentials}.
69
+ * Called by the SDK when the token is about to expire, has expired, or has been rejected by the PowerSync Service.
61
70
  *
62
- * Subsequent calls to {@link Authenticator.resolveCredentials} should return new credentials in this case.
71
+ * Subsequent calls to {@link Authenticator.resolveCredentials} should return a new token.
63
72
  */
64
73
  invalidateCredentials?(): void;
65
74
  }
@@ -31,14 +31,12 @@ export interface SyncOptions {
31
31
  */
32
32
  includeDefaultStreams?: boolean;
33
33
  /**
34
- * Delay for retrying sync streaming operations
35
- * from the PowerSync backend after an error occurs.
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.
36
36
  */
37
37
  retryDelayMs?: number;
38
38
  /**
39
- * Backend Connector CRUD operations are throttled
40
- * to occur at most every `crudUploadThrottleMs`
41
- * milliseconds.
39
+ * Uploads of local mutations are throttled to occur at most every `crudUploadThrottleMs` milliseconds.
42
40
  */
43
41
  crudUploadThrottleMs?: number;
44
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/sync/options.ts"],"names":[],"mappings":"AA0GA;;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"}
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
  /**
@@ -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
  /**
@@ -16,25 +16,25 @@ export interface TableOrRawTableOptions {
16
16
  interface SharedTableOptions extends TableOrRawTableOptions {
17
17
  viewName?: string;
18
18
  /**
19
- * Marks this table as a direct, managed table.
19
+ * Marks this table as a managed table.
20
20
  *
21
21
  * Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
22
22
  * a JSON store.
23
23
  *
24
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 JSON-based views, and mutations are consistently tracked as pending uploads.
25
+ * You can query managed tables like managed views, and mutations are consistently tracked as pending uploads.
26
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
27
  *
28
- * Direct tables can't use a {@link ResolvedTableOptions.viewName}.
28
+ * Managed tables can't use a {@link ResolvedTableOptions.viewName}.
29
29
  *
30
- * @alpha Direct tables are currently in alpha.
30
+ * @beta Managed tables are currently in beta.
31
31
  */
32
32
  direct?: boolean;
33
33
  }
34
34
  /** Whether to include previous column values when PowerSync tracks local changes.
35
35
  *
36
- * Including old values may be helpful for some backend connector implementations, which is
37
- * why it can be enabled on per-table or per-columm basis.
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.
38
38
  *
39
39
  * @public
40
40
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -215,7 +215,10 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
215
215
  init(): Promise<void>;
216
216
 
217
217
  /**
218
- * Connects to stream of events from the PowerSync instance.
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
 
@@ -247,6 +250,13 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
247
250
  * would be empty.
248
251
  *
249
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.
250
260
  */
251
261
  disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
252
262
 
@@ -292,7 +302,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
292
302
  *
293
303
  * Returns null if there is no data to upload.
294
304
  *
295
- * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
305
+ * Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
296
306
  *
297
307
  * Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
298
308
  * requesting the next batch.
@@ -314,7 +324,7 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
314
324
  *
315
325
  * Returns null if there is no data to upload.
316
326
  *
317
- * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
327
+ * Use this from your {@link MutationUploader} (or the `uploadData()` method of a {@link PowerSyncBackendConnector}).
318
328
  *
319
329
  * Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
320
330
  * requesting the next transaction.
@@ -329,7 +339,8 @@ export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSync
329
339
  /**
330
340
  * Returns an async iterator of completed transactions with local writes against the database.
331
341
  *
332
- * This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
342
+ * This is typically used from your {@link MutationUploader} (or the `uploadData()` method of a
343
+ * {@link PowerSyncBackendConnector}). Each entry emitted by the
333
344
  * returned iterator is a full transaction containing all local writes made while that transaction was active.
334
345
  *
335
346
  * Unlike {@link CommonPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
@@ -10,7 +10,8 @@ export interface PostCustomCheckpoints {
10
10
  *
11
11
  * This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
12
12
  * and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
13
- * are used. In any other case, this method should not be present on backend connectors.
13
+ * are used. In any other case, don't implement this method on your {@link Authenticator} or
14
+ * {@link PowerSyncBackendConnector}.
14
15
  *
15
16
  * @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
16
17
  * @param clientId - The PowerSync client ID for the current device.
@@ -20,6 +21,13 @@ export interface PostCustomCheckpoints {
20
21
  }
21
22
 
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
+ *
23
31
  * @public
24
32
  */
25
33
  export interface PowerSyncBackendConnector extends PostCustomCheckpoints {
@@ -54,17 +62,18 @@ export interface Authenticator extends PostCustomCheckpoints {
54
62
  /**
55
63
  * Obtain a token used to authenticate against a PowerSync service.
56
64
  *
65
+ * Cache the token in your authenticator, since the SDK may call this method several times while connected.
66
+ *
57
67
  * @param options - Options, including an abort signal completing when the SDK is no longer interested in these
58
68
  * credentials. Supported authenticators can reject the promise with the `AbortSignal.reason` when aborted.
59
- * @returns A promise resolving to PowerSync credentials. It may reject when credentials could not be resolved.
69
+ * @returns A promise resolving to the token (a JWT). It may reject when the token could not be resolved.
60
70
  */
61
71
  resolveCredentials(options: ResolveCredentialsOptions): Promise<string>;
62
72
 
63
73
  /**
64
- * Invoked by the SDK when the PowerSync service has rejected credentials previously returned by
65
- * {@link Authenticator.resolveCredentials}.
74
+ * Called by the SDK when the token is about to expire, has expired, or has been rejected by the PowerSync Service.
66
75
  *
67
- * Subsequent calls to {@link Authenticator.resolveCredentials} should return new credentials in this case.
76
+ * Subsequent calls to {@link Authenticator.resolveCredentials} should return a new token.
68
77
  */
69
78
  invalidateCredentials?(): void;
70
79
  }
@@ -39,15 +39,13 @@ export interface SyncOptions {
39
39
  includeDefaultStreams?: boolean;
40
40
 
41
41
  /**
42
- * Delay for retrying sync streaming operations
43
- * from the PowerSync backend after an error occurs.
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.
44
44
  */
45
45
  retryDelayMs?: number;
46
46
 
47
47
  /**
48
- * Backend Connector CRUD operations are throttled
49
- * to occur at most every `crudUploadThrottleMs`
50
- * milliseconds.
48
+ * Uploads of local mutations are throttled to occur at most every `crudUploadThrottleMs` milliseconds.
51
49
  */
52
50
  crudUploadThrottleMs?: number;
53
51
 
@@ -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
 
@@ -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
 
@@ -25,26 +25,26 @@ export interface TableOrRawTableOptions {
25
25
  interface SharedTableOptions extends TableOrRawTableOptions {
26
26
  viewName?: string;
27
27
  /**
28
- * Marks this table as a direct, managed table.
28
+ * Marks this table as a managed table.
29
29
  *
30
30
  * Enabling this flag makes PowerSync store data directly as SQLite rows instead of using an intermediate view around
31
31
  * a JSON store.
32
32
  *
33
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 JSON-based views, and mutations are consistently tracked as pending uploads.
34
+ * You can query managed tables like managed views, and mutations are consistently tracked as pending uploads.
35
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
36
  *
37
- * Direct tables can't use a {@link ResolvedTableOptions.viewName}.
37
+ * Managed tables can't use a {@link ResolvedTableOptions.viewName}.
38
38
  *
39
- * @alpha Direct tables are currently in alpha.
39
+ * @beta Managed tables are currently in beta.
40
40
  */
41
41
  direct?: boolean;
42
42
  }
43
43
 
44
44
  /** Whether to include previous column values when PowerSync tracks local changes.
45
45
  *
46
- * Including old values may be helpful for some backend connector implementations, which is
47
- * why it can be enabled on per-table or per-columm basis.
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.
48
48
  *
49
49
  * @public
50
50
  */