@powersync/common 1.51.0 → 1.53.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.
Files changed (91) hide show
  1. package/dist/bundle.cjs +510 -1129
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +511 -1116
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +508 -1129
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +509 -1116
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +73 -433
  10. package/legacy/sync_protocol.d.ts +103 -0
  11. package/lib/client/AbstractPowerSyncDatabase.js +3 -3
  12. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  13. package/lib/client/ConnectionManager.js +1 -1
  14. package/lib/client/ConnectionManager.js.map +1 -1
  15. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +6 -64
  16. package/lib/client/sync/bucket/BucketStorageAdapter.js +4 -0
  17. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
  18. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +1 -28
  19. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
  20. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
  21. package/lib/client/sync/stream/AbstractRemote.d.ts +29 -18
  22. package/lib/client/sync/stream/AbstractRemote.js +155 -188
  23. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  24. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +13 -35
  25. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +150 -448
  26. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  27. package/lib/client/sync/stream/JsonValue.d.ts +7 -0
  28. package/lib/client/sync/stream/JsonValue.js +2 -0
  29. package/lib/client/sync/stream/JsonValue.js.map +1 -0
  30. package/lib/client/sync/stream/core-instruction.d.ts +14 -9
  31. package/lib/client/sync/stream/core-instruction.js +3 -0
  32. package/lib/client/sync/stream/core-instruction.js.map +1 -1
  33. package/lib/db/DBAdapter.d.ts +9 -0
  34. package/lib/db/DBAdapter.js +8 -1
  35. package/lib/db/DBAdapter.js.map +1 -1
  36. package/lib/db/crud/SyncStatus.d.ts +3 -4
  37. package/lib/db/crud/SyncStatus.js +0 -4
  38. package/lib/db/crud/SyncStatus.js.map +1 -1
  39. package/lib/db/schema/RawTable.d.ts +0 -5
  40. package/lib/db/schema/Schema.d.ts +0 -2
  41. package/lib/db/schema/Schema.js +0 -2
  42. package/lib/db/schema/Schema.js.map +1 -1
  43. package/lib/index.d.ts +2 -6
  44. package/lib/index.js +1 -6
  45. package/lib/index.js.map +1 -1
  46. package/lib/utils/async.d.ts +0 -9
  47. package/lib/utils/async.js +0 -9
  48. package/lib/utils/async.js.map +1 -1
  49. package/lib/utils/stream_transform.d.ts +39 -0
  50. package/lib/utils/stream_transform.js +206 -0
  51. package/lib/utils/stream_transform.js.map +1 -0
  52. package/package.json +15 -10
  53. package/src/client/AbstractPowerSyncDatabase.ts +3 -3
  54. package/src/client/ConnectionManager.ts +1 -1
  55. package/src/client/sync/bucket/BucketStorageAdapter.ts +6 -71
  56. package/src/client/sync/bucket/SqliteBucketStorage.ts +1 -197
  57. package/src/client/sync/stream/AbstractRemote.ts +183 -229
  58. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +181 -510
  59. package/src/client/sync/stream/JsonValue.ts +8 -0
  60. package/src/client/sync/stream/core-instruction.ts +15 -5
  61. package/src/db/DBAdapter.ts +20 -2
  62. package/src/db/crud/SyncStatus.ts +4 -5
  63. package/src/db/schema/RawTable.ts +0 -5
  64. package/src/db/schema/Schema.ts +0 -2
  65. package/src/index.ts +2 -6
  66. package/src/utils/async.ts +0 -11
  67. package/src/utils/stream_transform.ts +252 -0
  68. package/lib/client/sync/bucket/OpType.d.ts +0 -16
  69. package/lib/client/sync/bucket/OpType.js +0 -23
  70. package/lib/client/sync/bucket/OpType.js.map +0 -1
  71. package/lib/client/sync/bucket/OplogEntry.d.ts +0 -23
  72. package/lib/client/sync/bucket/OplogEntry.js +0 -36
  73. package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
  74. package/lib/client/sync/bucket/SyncDataBatch.d.ts +0 -6
  75. package/lib/client/sync/bucket/SyncDataBatch.js +0 -12
  76. package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
  77. package/lib/client/sync/bucket/SyncDataBucket.d.ts +0 -40
  78. package/lib/client/sync/bucket/SyncDataBucket.js +0 -40
  79. package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
  80. package/lib/client/sync/stream/streaming-sync-types.d.ts +0 -143
  81. package/lib/client/sync/stream/streaming-sync-types.js +0 -26
  82. package/lib/client/sync/stream/streaming-sync-types.js.map +0 -1
  83. package/lib/utils/DataStream.d.ts +0 -62
  84. package/lib/utils/DataStream.js +0 -169
  85. package/lib/utils/DataStream.js.map +0 -1
  86. package/src/client/sync/bucket/OpType.ts +0 -23
  87. package/src/client/sync/bucket/OplogEntry.ts +0 -50
  88. package/src/client/sync/bucket/SyncDataBatch.ts +0 -11
  89. package/src/client/sync/bucket/SyncDataBucket.ts +0 -49
  90. package/src/client/sync/stream/streaming-sync-types.ts +0 -210
  91. package/src/utils/DataStream.ts +0 -222
@@ -3,7 +3,7 @@ import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus.js';
3
3
  import { BaseListener, BaseObserver, BaseObserverInterface, Disposable } from '../../../utils/BaseObserver.js';
4
4
  import { BucketStorageAdapter } from '../bucket/BucketStorageAdapter.js';
5
5
  import { AbstractRemote, FetchStrategy } from './AbstractRemote.js';
6
- import { StreamingSyncRequestParameterType } from './streaming-sync-types.js';
6
+ import { StreamingSyncRequestParameterType } from './JsonValue.js';
7
7
  export declare enum LockType {
8
8
  CRUD = "crud",
9
9
  SYNC = "sync"
@@ -13,35 +13,21 @@ export declare enum SyncStreamConnectionMethod {
13
13
  WEB_SOCKET = "web-socket"
14
14
  }
15
15
  export declare enum SyncClientImplementation {
16
- /**
17
- * Decodes and handles sync lines received from the sync service in JavaScript.
18
- *
19
- * This is the default option.
20
- *
21
- * @deprecated We recommend the {@link RUST} client implementation for all apps. If you have issues with
22
- * the Rust client, please file an issue or reach out to us. The JavaScript client will be removed in a future
23
- * version of the PowerSync SDK.
24
- */
25
- JAVASCRIPT = "js",
26
16
  /**
27
17
  * This implementation offloads the sync line decoding and handling into the PowerSync
28
18
  * core extension.
29
19
  *
30
- * This option is more performant than the {@link JAVASCRIPT} client, enabled by default and the
31
- * recommended client implementation for all apps.
20
+ * This is the only option, as an older JavaScript client implementation has been removed from the SDK.
32
21
  *
33
22
  * ## Compatibility warning
34
23
  *
35
24
  * The Rust sync client stores sync data in a format that is slightly different than the one used
36
- * by the old {@link JAVASCRIPT} implementation. When adopting the {@link RUST} client on existing
37
- * databases, the PowerSync SDK will migrate the format automatically.
38
- * Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
39
- * the version introducing {@link RUST} as an option) also supports the new format, so you can switch
40
- * back to {@link JAVASCRIPT} later.
25
+ * by the old JavaScript client. When adopting the {@link RUST} client on existing databases, the PowerSync SDK will
26
+ * migrate the format automatically.
41
27
  *
42
- * __However__: Upgrading the SDK version, then adopting {@link RUST} as a sync client and later
43
- * downgrading the SDK to an older version (necessarily using the JavaScript-based implementation then)
44
- * can lead to sync issues.
28
+ * SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
29
+ * implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
30
+ * possible anymore. Problematic SDK versions have been released before 2025-06-09.
45
31
  */
46
32
  RUST = "rust"
47
33
  }
@@ -94,11 +80,7 @@ export interface BaseConnectionOptions {
94
80
  */
95
81
  appMetadata?: Record<string, string>;
96
82
  /**
97
- * Whether to use a JavaScript implementation to handle received sync lines from the sync
98
- * service, or whether this work should be offloaded to the PowerSync core extension.
99
- *
100
- * This defaults to the JavaScript implementation ({@link SyncClientImplementation.JAVASCRIPT})
101
- * since the ({@link SyncClientImplementation.RUST}) implementation is experimental at the moment.
83
+ * @deprecated The Rust sync client is used unconditionally, so this option can't be configured.
102
84
  */
103
85
  clientImplementation?: SyncClientImplementation;
104
86
  /**
@@ -155,15 +137,14 @@ export interface StreamingSyncImplementation extends BaseObserverInterface<Strea
155
137
  */
156
138
  disconnect(): Promise<void>;
157
139
  getWriteCheckpoint: () => Promise<string>;
158
- hasCompletedSync: () => Promise<boolean>;
159
140
  isConnected: boolean;
160
- lastSyncedAt?: Date;
161
141
  syncStatus: SyncStatus;
162
142
  triggerCrudUpload: () => void;
163
143
  waitForReady(): Promise<void>;
164
144
  waitForStatus(status: SyncStatusOptions): Promise<void>;
165
145
  waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
166
146
  updateSubscriptions(subscriptions: SubscribedStream[]): void;
147
+ markConnectionMayHaveChanged(): void;
167
148
  }
168
149
  export declare const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
169
150
  export declare const DEFAULT_RETRY_DELAY_MS = 5000;
@@ -178,14 +159,14 @@ export type SubscribedStream = {
178
159
  params: Record<string, any> | null;
179
160
  };
180
161
  export declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
181
- protected _lastSyncedAt: Date | null;
182
162
  protected options: AbstractStreamingSyncImplementationOptions;
183
163
  protected abortController: AbortController | null;
184
- protected uploadAbortController: AbortController | null;
164
+ protected uploadAbortController: AbortController | undefined;
185
165
  protected crudUpdateListener?: () => void;
186
166
  protected streamingSyncPromise?: Promise<void>;
187
167
  protected logger: ILogger;
188
168
  private activeStreams;
169
+ private connectionMayHaveChanged;
189
170
  private isUploadingCrud;
190
171
  private notifyCompletedUploads?;
191
172
  private handleActiveStreamsChange?;
@@ -199,7 +180,6 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
199
180
  get isConnected(): boolean;
200
181
  dispose(): Promise<void>;
201
182
  abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
202
- hasCompletedSync(): Promise<boolean>;
203
183
  getWriteCheckpoint(): Promise<string>;
204
184
  protected _uploadAllCrud(): Promise<void>;
205
185
  connect(options?: PowerSyncConnectionOptions): Promise<void>;
@@ -208,7 +188,7 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
208
188
  * @deprecated use [connect instead]
209
189
  */
210
190
  streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
211
- private collectLocalBucketState;
191
+ markConnectionMayHaveChanged(): void;
212
192
  /**
213
193
  * Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
214
194
  * Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
@@ -226,10 +206,8 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
226
206
  */
227
207
  private requireKeyFormat;
228
208
  protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<RustIterationResult | null>;
229
- private legacyStreamingSyncIteration;
209
+ private receiveSyncLines;
230
210
  private rustSyncIteration;
231
- private updateSyncStatusForStartingCheckpoint;
232
- private applyCheckpoint;
233
211
  protected updateSyncStatus(options: SyncStatusOptions): void;
234
212
  private delayRetry;
235
213
  updateSubscriptions(subscriptions: SubscribedStream[]): void;