@powersync/common 0.0.0-dev-20250609122429 → 0.0.0-dev-20250625140957

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.
@@ -12,6 +12,48 @@ export declare enum SyncStreamConnectionMethod {
12
12
  HTTP = "http",
13
13
  WEB_SOCKET = "web-socket"
14
14
  }
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 Don't use {@link SyncClientImplementation.JAVASCRIPT} directly. Instead, use
22
+ * {@link DEFAULT_SYNC_CLIENT_IMPLEMENTATION} or omit the option. The explicit choice to use
23
+ * the JavaScript-based sync implementation will be removed from a future version of the SDK.
24
+ */
25
+ JAVASCRIPT = "js",
26
+ /**
27
+ * This implementation offloads the sync line decoding and handling into the PowerSync
28
+ * core extension.
29
+ *
30
+ * @experimental
31
+ * While this implementation is more performant than {@link SyncClientImplementation.JAVASCRIPT},
32
+ * it has seen less real-world testing and is marked as __experimental__ at the moment.
33
+ *
34
+ * ## Compatibility warning
35
+ *
36
+ * The Rust sync client stores sync data in a format that is slightly different than the one used
37
+ * by the old {@link JAVASCRIPT} implementation. When adopting the {@link RUST} client on existing
38
+ * databases, the PowerSync SDK will migrate the format automatically.
39
+ * Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
40
+ * the version introducing {@link RUST} as an option) also supports the new format, so you can switch
41
+ * back to {@link JAVASCRIPT} later.
42
+ *
43
+ * __However__: Upgrading the SDK version, then adopting {@link RUST} as a sync client and later
44
+ * downgrading the SDK to an older version (necessarily using the JavaScript-based implementation then)
45
+ * can lead to sync issues.
46
+ */
47
+ RUST = "rust"
48
+ }
49
+ /**
50
+ * The default {@link SyncClientImplementation} to use.
51
+ *
52
+ * Please use this field instead of {@link SyncClientImplementation.JAVASCRIPT} directly. A future version
53
+ * of the PowerSync SDK will enable {@link SyncClientImplementation.RUST} by default and remove the JavaScript
54
+ * option.
55
+ */
56
+ export declare const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.JAVASCRIPT;
15
57
  /**
16
58
  * Abstract Lock to be implemented by various JS environments
17
59
  */
@@ -50,6 +92,14 @@ export interface PowerSyncConnectionOptions extends BaseConnectionOptions, Addit
50
92
  }
51
93
  /** @internal */
52
94
  export interface BaseConnectionOptions {
95
+ /**
96
+ * Whether to use a JavaScript implementation to handle received sync lines from the sync
97
+ * service, or whether this work should be offloaded to the PowerSync core extension.
98
+ *
99
+ * This defaults to the JavaScript implementation ({@link SyncClientImplementation.JAVASCRIPT})
100
+ * since the ({@link SyncClientImplementation.RUST}) implementation is experimental at the moment.
101
+ */
102
+ clientImplementation?: SyncClientImplementation;
53
103
  /**
54
104
  * The connection method to use when streaming updates from
55
105
  * the PowerSync backend instance.
@@ -117,6 +167,7 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
117
167
  protected crudUpdateListener?: () => void;
118
168
  protected streamingSyncPromise?: Promise<void>;
119
169
  private pendingCrudUpload?;
170
+ private notifyCompletedUploads?;
120
171
  syncStatus: SyncStatus;
121
172
  triggerCrudUpload: () => void;
122
173
  constructor(options: AbstractStreamingSyncImplementationOptions);
@@ -138,7 +189,25 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
138
189
  */
139
190
  streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
140
191
  private collectLocalBucketState;
192
+ /**
193
+ * Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
194
+ * Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
195
+ * While this is not a problem as long as it's done consistently, it causes issues when a database
196
+ * created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
197
+ * is enabled.
198
+ *
199
+ * So, we add a migration from the old key format (with quotes) to the new one (no quotes). The
200
+ * migration is only triggered when necessary (for now). The function returns whether the new format
201
+ * should be used, so that the JS SDK is able to write to updated databases.
202
+ *
203
+ * @param requireFixedKeyFormat Whether we require the new format or also support the old one.
204
+ * The Rust client requires the new subkey format.
205
+ * @returns Whether the database is now using the new, fixed subkey format.
206
+ */
207
+ private requireKeyFormat;
141
208
  protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
209
+ private legacyStreamingSyncIteration;
210
+ private rustSyncIteration;
142
211
  private updateSyncStatusForStartingCheckpoint;
143
212
  private applyCheckpoint;
144
213
  protected updateSyncStatus(options: SyncStatusOptions): void;