@powersync/common 1.27.0 → 1.28.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.
@@ -155,7 +155,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
155
155
  /**
156
156
  * Wait for the first sync operation to complete.
157
157
  *
158
- * @argument request Either an abort signal (after which the promise will complete regardless of
158
+ * @param request Either an abort signal (after which the promise will complete regardless of
159
159
  * whether a full sync was completed) or an object providing an abort signal and a priority target.
160
160
  * When a priority target is set, the promise may complete when all buckets with the given (or higher)
161
161
  * priorities have been synchronized. This can be earlier than a complete sync.
@@ -183,6 +183,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
183
183
  * Cannot be used while connected - this should only be called before {@link AbstractPowerSyncDatabase.connect}.
184
184
  */
185
185
  updateSchema(schema: Schema): Promise<void>;
186
+ get logger(): Logger.ILogger;
186
187
  /**
187
188
  * Wait for initialization to complete.
188
189
  * While initializing is automatic, this helps to catch and report initialization errors.
@@ -222,7 +223,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
222
223
  */
223
224
  getUploadQueueStats(includeSize?: boolean): Promise<UploadQueueStats>;
224
225
  /**
225
- * Get a batch of crud data to upload.
226
+ * Get a batch of CRUD data to upload.
226
227
  *
227
228
  * Returns null if there is no data to upload.
228
229
  *
@@ -237,6 +238,9 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
237
238
  * This method does include transaction ids in the result, but does not group
238
239
  * data by transaction. One batch may contain data from multiple transactions,
239
240
  * and a single transaction may be split over multiple batches.
241
+ *
242
+ * @param limit Maximum number of CRUD entries to include in the batch
243
+ * @returns A batch of CRUD operations to upload, or null if there are none
240
244
  */
241
245
  getCrudBatch(limit?: number): Promise<CrudBatch | null>;
242
246
  /**
@@ -251,37 +255,71 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
251
255
  *
252
256
  * Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
253
257
  * All data for the transaction is loaded into memory.
258
+ *
259
+ * @returns A transaction of CRUD operations to upload, or null if there are none
254
260
  */
255
261
  getNextCrudTransaction(): Promise<CrudTransaction | null>;
256
262
  /**
257
263
  * Get an unique client id for this database.
258
264
  *
259
265
  * The id is not reset when the database is cleared, only when the database is deleted.
266
+ *
267
+ * @returns A unique identifier for the database instance
260
268
  */
261
269
  getClientId(): Promise<string>;
262
270
  private handleCrudCheckpoint;
263
271
  /**
264
- * Execute a write (INSERT/UPDATE/DELETE) query
272
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
265
273
  * and optionally return results.
274
+ *
275
+ * @param sql The SQL query to execute
276
+ * @param parameters Optional array of parameters to bind to the query
277
+ * @returns The query result as an object with structured key-value pairs
266
278
  */
267
279
  execute(sql: string, parameters?: any[]): Promise<QueryResult>;
280
+ /**
281
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
282
+ * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
283
+ *
284
+ * @param sql The SQL query to execute
285
+ * @param parameters Optional array of parameters to bind to the query
286
+ * @returns The raw query result from the underlying database as a nested array of raw values, where each row is
287
+ * represented as an array of column values without field names.
288
+ */
268
289
  executeRaw(sql: string, parameters?: any[]): Promise<any[][]>;
269
290
  /**
270
291
  * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
271
292
  * and optionally return results.
272
293
  * This is faster than executing separately with each parameter set.
294
+ *
295
+ * @param sql The SQL query to execute
296
+ * @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
297
+ * @returns The query result
273
298
  */
274
299
  executeBatch(sql: string, parameters?: any[][]): Promise<QueryResult>;
275
300
  /**
276
301
  * Execute a read-only query and return results.
302
+ *
303
+ * @param sql The SQL query to execute
304
+ * @param parameters Optional array of parameters to bind to the query
305
+ * @returns An array of results
277
306
  */
278
307
  getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
279
308
  /**
280
309
  * Execute a read-only query and return the first result, or null if the ResultSet is empty.
310
+ *
311
+ * @param sql The SQL query to execute
312
+ * @param parameters Optional array of parameters to bind to the query
313
+ * @returns The first result if found, or null if no results are returned
281
314
  */
282
315
  getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
283
316
  /**
284
317
  * Execute a read-only query and return the first result, error if the ResultSet is empty.
318
+ *
319
+ * @param sql The SQL query to execute
320
+ * @param parameters Optional array of parameters to bind to the query
321
+ * @returns The first result matching the query
322
+ * @throws Error if no rows are returned
285
323
  */
286
324
  get<T>(sql: string, parameters?: any[]): Promise<T>;
287
325
  /**
@@ -298,12 +336,22 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
298
336
  * Open a read-only transaction.
299
337
  * Read transactions can run concurrently to a write transaction.
300
338
  * Changes from any write transaction are not visible to read transactions started before it.
339
+ *
340
+ * @param callback Function to execute within the transaction
341
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
342
+ * @returns The result of the callback
343
+ * @throws Error if the lock cannot be obtained within the timeout period
301
344
  */
302
345
  readTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
303
346
  /**
304
347
  * Open a read-write transaction.
305
348
  * This takes a global lock - only one write transaction can execute against the database at a time.
306
349
  * Statements within the transaction must be done on the provided {@link Transaction} interface.
350
+ *
351
+ * @param callback Function to execute within the transaction
352
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
353
+ * @returns The result of the callback
354
+ * @throws Error if the lock cannot be obtained within the timeout period
307
355
  */
308
356
  writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
309
357
  /**
@@ -346,14 +394,34 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
346
394
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
347
395
  *
348
396
  * Note that the `onChange` callback member of the handler is required.
397
+ *
398
+ * @param sql The SQL query to execute
399
+ * @param parameters Optional array of parameters to bind to the query
400
+ * @param handler Callbacks for handling results and errors
401
+ * @param options Options for configuring watch behavior
349
402
  */
350
403
  watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
351
404
  /**
352
405
  * Execute a read query every time the source tables are modified.
353
406
  * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
354
407
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
408
+ *
409
+ * @param sql The SQL query to execute
410
+ * @param parameters Optional array of parameters to bind to the query
411
+ * @param options Options for configuring watch behavior
412
+ * @returns An AsyncIterable that yields QueryResults whenever the data changes
355
413
  */
356
414
  watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
415
+ /**
416
+ * Resolves the list of tables that are used in a SQL query.
417
+ * If tables are specified in the options, those are used directly.
418
+ * Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
419
+ *
420
+ * @param sql The SQL query to analyze
421
+ * @param parameters Optional parameters for the SQL query
422
+ * @param options Optional watch options that may contain explicit table list
423
+ * @returns Array of table names that the query depends on
424
+ */
357
425
  resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]>;
358
426
  /**
359
427
  * This version of `onChange` uses {@link AsyncGenerator}, for documentation see {@link onChangeWithAsyncGenerator}.
@@ -392,7 +460,9 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
392
460
  *
393
461
  * Note that the `onChange` callback member of the handler is required.
394
462
  *
395
- * Returns dispose function to stop watching.
463
+ * @param handler Callbacks for handling change events and errors
464
+ * @param options Options for configuring watch behavior
465
+ * @returns A dispose function to stop watching for changes
396
466
  */
397
467
  onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLWatchOptions): () => void;
398
468
  /**
@@ -401,7 +471,10 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
401
471
  * This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be performed
402
472
  * together when data is changed.
403
473
  *
404
- * Note, do not declare this as `async *onChange` as it will not work in React Native
474
+ * Note: do not declare this as `async *onChange` as it will not work in React Native.
475
+ *
476
+ * @param options Options for configuring watch behavior
477
+ * @returns An AsyncIterable that yields change events whenever the specified tables change
405
478
  */
406
479
  onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent>;
407
480
  private handleTableChanges;
@@ -7,7 +7,7 @@ import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
7
7
  import { BaseObserver } from '../utils/BaseObserver.js';
8
8
  import { ControlledExecutor } from '../utils/ControlledExecutor.js';
9
9
  import { mutexRunExclusive } from '../utils/mutex.js';
10
- import { throttleTrailing } from '../utils/throttle.js';
10
+ import { throttleTrailing } from '../utils/async.js';
11
11
  import { isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory.js';
12
12
  import { runOnSchemaChange } from './runOnSchemaChange.js';
13
13
  import { PSInternalTable } from './sync/bucket/BucketStorageAdapter.js';
@@ -133,7 +133,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
133
133
  /**
134
134
  * Wait for the first sync operation to complete.
135
135
  *
136
- * @argument request Either an abort signal (after which the promise will complete regardless of
136
+ * @param request Either an abort signal (after which the promise will complete regardless of
137
137
  * whether a full sync was completed) or an object providing an abort signal and a priority target.
138
138
  * When a priority target is set, the promise may complete when all buckets with the given (or higher)
139
139
  * priorities have been synchronized. This can be earlier than a complete sync.
@@ -250,6 +250,9 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
250
250
  await this.database.refreshSchema();
251
251
  this.iterateListeners(async (cb) => cb.schemaChanged?.(schema));
252
252
  }
253
+ get logger() {
254
+ return this.options.logger;
255
+ }
253
256
  /**
254
257
  * Wait for initialization to complete.
255
258
  * While initializing is automatic, this helps to catch and report initialization errors.
@@ -260,6 +263,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
260
263
  // Use the options passed in during connect, or fallback to the options set during database creation or fallback to the default options
261
264
  resolvedConnectionOptions(options) {
262
265
  return {
266
+ ...options,
263
267
  retryDelayMs: options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay ?? DEFAULT_RETRY_DELAY_MS,
264
268
  crudUploadThrottleMs: options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs ?? DEFAULT_CRUD_UPLOAD_THROTTLE_MS
265
269
  };
@@ -274,11 +278,8 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
274
278
  if (this.closed) {
275
279
  throw new Error('Cannot connect using a closed client');
276
280
  }
277
- const { retryDelayMs, crudUploadThrottleMs } = this.resolvedConnectionOptions(options);
278
- this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, {
279
- retryDelayMs,
280
- crudUploadThrottleMs
281
- });
281
+ const resolvedConnectOptions = this.resolvedConnectionOptions(options);
282
+ this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, resolvedConnectOptions);
282
283
  this.syncStatusListenerDisposer = this.syncStreamImplementation.registerListener({
283
284
  statusChanged: (status) => {
284
285
  this.currentStatus = new SyncStatus({
@@ -363,7 +364,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
363
364
  });
364
365
  }
365
366
  /**
366
- * Get a batch of crud data to upload.
367
+ * Get a batch of CRUD data to upload.
367
368
  *
368
369
  * Returns null if there is no data to upload.
369
370
  *
@@ -378,6 +379,9 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
378
379
  * This method does include transaction ids in the result, but does not group
379
380
  * data by transaction. One batch may contain data from multiple transactions,
380
381
  * and a single transaction may be split over multiple batches.
382
+ *
383
+ * @param limit Maximum number of CRUD entries to include in the batch
384
+ * @returns A batch of CRUD operations to upload, or null if there are none
381
385
  */
382
386
  async getCrudBatch(limit = DEFAULT_CRUD_BATCH_LIMIT) {
383
387
  const result = await this.getAll(`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT ?`, [limit + 1]);
@@ -405,6 +409,8 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
405
409
  *
406
410
  * Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
407
411
  * All data for the transaction is loaded into memory.
412
+ *
413
+ * @returns A transaction of CRUD operations to upload, or null if there are none
408
414
  */
409
415
  async getNextCrudTransaction() {
410
416
  return await this.readTransaction(async (tx) => {
@@ -429,6 +435,8 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
429
435
  * Get an unique client id for this database.
430
436
  *
431
437
  * The id is not reset when the database is cleared, only when the database is deleted.
438
+ *
439
+ * @returns A unique identifier for the database instance
432
440
  */
433
441
  async getClientId() {
434
442
  return this.bucketStorageAdapter.getClientId();
@@ -452,13 +460,26 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
452
460
  });
453
461
  }
454
462
  /**
455
- * Execute a write (INSERT/UPDATE/DELETE) query
463
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
456
464
  * and optionally return results.
465
+ *
466
+ * @param sql The SQL query to execute
467
+ * @param parameters Optional array of parameters to bind to the query
468
+ * @returns The query result as an object with structured key-value pairs
457
469
  */
458
470
  async execute(sql, parameters) {
459
471
  await this.waitForReady();
460
472
  return this.database.execute(sql, parameters);
461
473
  }
474
+ /**
475
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
476
+ * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
477
+ *
478
+ * @param sql The SQL query to execute
479
+ * @param parameters Optional array of parameters to bind to the query
480
+ * @returns The raw query result from the underlying database as a nested array of raw values, where each row is
481
+ * represented as an array of column values without field names.
482
+ */
462
483
  async executeRaw(sql, parameters) {
463
484
  await this.waitForReady();
464
485
  return this.database.executeRaw(sql, parameters);
@@ -467,6 +488,10 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
467
488
  * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
468
489
  * and optionally return results.
469
490
  * This is faster than executing separately with each parameter set.
491
+ *
492
+ * @param sql The SQL query to execute
493
+ * @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
494
+ * @returns The query result
470
495
  */
471
496
  async executeBatch(sql, parameters) {
472
497
  await this.waitForReady();
@@ -474,6 +499,10 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
474
499
  }
475
500
  /**
476
501
  * Execute a read-only query and return results.
502
+ *
503
+ * @param sql The SQL query to execute
504
+ * @param parameters Optional array of parameters to bind to the query
505
+ * @returns An array of results
477
506
  */
478
507
  async getAll(sql, parameters) {
479
508
  await this.waitForReady();
@@ -481,6 +510,10 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
481
510
  }
482
511
  /**
483
512
  * Execute a read-only query and return the first result, or null if the ResultSet is empty.
513
+ *
514
+ * @param sql The SQL query to execute
515
+ * @param parameters Optional array of parameters to bind to the query
516
+ * @returns The first result if found, or null if no results are returned
484
517
  */
485
518
  async getOptional(sql, parameters) {
486
519
  await this.waitForReady();
@@ -488,6 +521,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
488
521
  }
489
522
  /**
490
523
  * Execute a read-only query and return the first result, error if the ResultSet is empty.
524
+ *
525
+ * @param sql The SQL query to execute
526
+ * @param parameters Optional array of parameters to bind to the query
527
+ * @returns The first result matching the query
528
+ * @throws Error if no rows are returned
491
529
  */
492
530
  async get(sql, parameters) {
493
531
  await this.waitForReady();
@@ -516,6 +554,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
516
554
  * Open a read-only transaction.
517
555
  * Read transactions can run concurrently to a write transaction.
518
556
  * Changes from any write transaction are not visible to read transactions started before it.
557
+ *
558
+ * @param callback Function to execute within the transaction
559
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
560
+ * @returns The result of the callback
561
+ * @throws Error if the lock cannot be obtained within the timeout period
519
562
  */
520
563
  async readTransaction(callback, lockTimeout = DEFAULT_LOCK_TIMEOUT_MS) {
521
564
  await this.waitForReady();
@@ -529,6 +572,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
529
572
  * Open a read-write transaction.
530
573
  * This takes a global lock - only one write transaction can execute against the database at a time.
531
574
  * Statements within the transaction must be done on the provided {@link Transaction} interface.
575
+ *
576
+ * @param callback Function to execute within the transaction
577
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
578
+ * @returns The result of the callback
579
+ * @throws Error if the lock cannot be obtained within the timeout period
532
580
  */
533
581
  async writeTransaction(callback, lockTimeout = DEFAULT_LOCK_TIMEOUT_MS) {
534
582
  await this.waitForReady();
@@ -553,6 +601,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
553
601
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
554
602
  *
555
603
  * Note that the `onChange` callback member of the handler is required.
604
+ *
605
+ * @param sql The SQL query to execute
606
+ * @param parameters Optional array of parameters to bind to the query
607
+ * @param handler Callbacks for handling results and errors
608
+ * @param options Options for configuring watch behavior
556
609
  */
557
610
  watchWithCallback(sql, parameters, handler, options) {
558
611
  const { onResult, onError = (e) => this.options.logger?.error(e) } = handler ?? {};
@@ -593,6 +646,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
593
646
  * Execute a read query every time the source tables are modified.
594
647
  * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
595
648
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
649
+ *
650
+ * @param sql The SQL query to execute
651
+ * @param parameters Optional array of parameters to bind to the query
652
+ * @param options Options for configuring watch behavior
653
+ * @returns An AsyncIterable that yields QueryResults whenever the data changes
596
654
  */
597
655
  watchWithAsyncGenerator(sql, parameters, options) {
598
656
  return new EventIterator((eventOptions) => {
@@ -610,6 +668,16 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
610
668
  });
611
669
  });
612
670
  }
671
+ /**
672
+ * Resolves the list of tables that are used in a SQL query.
673
+ * If tables are specified in the options, those are used directly.
674
+ * Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
675
+ *
676
+ * @param sql The SQL query to analyze
677
+ * @param parameters Optional parameters for the SQL query
678
+ * @param options Optional watch options that may contain explicit table list
679
+ * @returns Array of table names that the query depends on
680
+ */
613
681
  async resolveTables(sql, parameters, options) {
614
682
  const resolvedTables = options?.tables ? [...options.tables] : [];
615
683
  if (!options?.tables) {
@@ -641,7 +709,9 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
641
709
  *
642
710
  * Note that the `onChange` callback member of the handler is required.
643
711
  *
644
- * Returns dispose function to stop watching.
712
+ * @param handler Callbacks for handling change events and errors
713
+ * @param options Options for configuring watch behavior
714
+ * @returns A dispose function to stop watching for changes
645
715
  */
646
716
  onChangeWithCallback(handler, options) {
647
717
  const { onChange, onError = (e) => this.options.logger?.error(e) } = handler ?? {};
@@ -683,7 +753,10 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
683
753
  * This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be performed
684
754
  * together when data is changed.
685
755
  *
686
- * Note, do not declare this as `async *onChange` as it will not work in React Native
756
+ * Note: do not declare this as `async *onChange` as it will not work in React Native.
757
+ *
758
+ * @param options Options for configuring watch behavior
759
+ * @returns An AsyncIterable that yields change events whenever the specified tables change
687
760
  */
688
761
  onChangeWithAsyncGenerator(options) {
689
762
  const resolvedOptions = options ?? {};
@@ -54,6 +54,13 @@ export type AbstractRemoteOptions = {
54
54
  * Binding should be done before passing here.
55
55
  */
56
56
  fetchImplementation: FetchImplementation | FetchImplementationProvider;
57
+ /**
58
+ * Optional options to pass directly to all `fetch` calls.
59
+ *
60
+ * This can include fields such as `dispatcher` (e.g. for proxy support),
61
+ * `cache`, or any other fetch-compatible options.
62
+ */
63
+ fetchOptions?: {};
57
64
  };
58
65
  export declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
59
66
  export declare abstract class AbstractRemote {
@@ -84,6 +91,7 @@ export declare abstract class AbstractRemote {
84
91
  * Provides a BSON implementation. The import nature of this varies depending on the platform
85
92
  */
86
93
  abstract getBSON(): Promise<BSONImplementation>;
94
+ protected createSocket(url: string): WebSocket;
87
95
  /**
88
96
  * Connects to the sync/stream websocket endpoint
89
97
  */
@@ -44,7 +44,8 @@ export const DEFAULT_REMOTE_OPTIONS = {
44
44
  socketUrlTransformer: (url) => url.replace(/^https?:\/\//, function (match) {
45
45
  return match === 'https://' ? 'wss://' : 'ws://';
46
46
  }),
47
- fetchImplementation: new FetchImplementationProvider()
47
+ fetchImplementation: new FetchImplementationProvider(),
48
+ fetchOptions: {}
48
49
  };
49
50
  export class AbstractRemote {
50
51
  connector;
@@ -153,6 +154,9 @@ export class AbstractRemote {
153
154
  }
154
155
  return res;
155
156
  }
157
+ createSocket(url) {
158
+ return new WebSocket(url);
159
+ }
156
160
  /**
157
161
  * Connects to the sync/stream websocket endpoint
158
162
  */
@@ -167,7 +171,8 @@ export class AbstractRemote {
167
171
  const userAgent = this.getUserAgent();
168
172
  const connector = new RSocketConnector({
169
173
  transport: new WebsocketClientTransport({
170
- url: this.options.socketUrlTransformer(request.url)
174
+ url: this.options.socketUrlTransformer(request.url),
175
+ wsCreator: (url) => this.createSocket(url)
171
176
  }),
172
177
  setup: {
173
178
  keepAlive: KEEP_ALIVE_MS,
@@ -318,6 +323,7 @@ export class AbstractRemote {
318
323
  body: JSON.stringify(data),
319
324
  signal: controller.signal,
320
325
  cache: 'no-store',
326
+ ...(this.options.fetchOptions ?? {}),
321
327
  ...options.fetchOptions
322
328
  }).catch((ex) => {
323
329
  if (ex.name == 'AbortError') {
@@ -116,6 +116,7 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
116
116
  protected abortController: AbortController | null;
117
117
  protected crudUpdateListener?: () => void;
118
118
  protected streamingSyncPromise?: Promise<void>;
119
+ private pendingCrudUpload?;
119
120
  syncStatus: SyncStatus;
120
121
  triggerCrudUpload: () => void;
121
122
  constructor(options: AbstractStreamingSyncImplementationOptions);
@@ -137,9 +138,8 @@ export declare abstract class AbstractStreamingSyncImplementation extends BaseOb
137
138
  */
138
139
  streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
139
140
  private collectLocalBucketState;
140
- protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<{
141
- retry?: boolean;
142
- }>;
141
+ protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
142
+ private applyCheckpoint;
143
143
  protected updateSyncStatus(options: SyncStatusOptions): void;
144
144
  private delayRetry;
145
145
  }