@powersync/common 0.0.0-dev-20260503073249 → 0.0.0-dev-20260504100448

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 (57) hide show
  1. package/dist/bundle.cjs +14 -659
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +15 -648
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +14 -659
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +15 -648
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +19 -358
  10. package/legacy/sync_protocol.d.ts +103 -0
  11. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +1 -63
  12. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
  13. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +1 -28
  14. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
  15. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
  16. package/lib/client/sync/stream/AbstractRemote.d.ts +2 -12
  17. package/lib/client/sync/stream/AbstractRemote.js +3 -13
  18. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  19. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +9 -35
  20. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +11 -338
  21. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  22. package/lib/client/sync/stream/JsonValue.d.ts +7 -0
  23. package/lib/client/sync/stream/JsonValue.js +2 -0
  24. package/lib/client/sync/stream/JsonValue.js.map +1 -0
  25. package/lib/client/sync/stream/core-instruction.d.ts +1 -2
  26. package/lib/client/sync/stream/core-instruction.js.map +1 -1
  27. package/lib/index.d.ts +1 -5
  28. package/lib/index.js +1 -5
  29. package/lib/index.js.map +1 -1
  30. package/package.json +7 -4
  31. package/src/client/sync/bucket/BucketStorageAdapter.ts +1 -70
  32. package/src/client/sync/bucket/SqliteBucketStorage.ts +1 -197
  33. package/src/client/sync/stream/AbstractRemote.ts +5 -27
  34. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +22 -402
  35. package/src/client/sync/stream/JsonValue.ts +8 -0
  36. package/src/client/sync/stream/core-instruction.ts +1 -2
  37. package/src/index.ts +1 -5
  38. package/lib/client/sync/bucket/OpType.d.ts +0 -16
  39. package/lib/client/sync/bucket/OpType.js +0 -23
  40. package/lib/client/sync/bucket/OpType.js.map +0 -1
  41. package/lib/client/sync/bucket/OplogEntry.d.ts +0 -23
  42. package/lib/client/sync/bucket/OplogEntry.js +0 -36
  43. package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
  44. package/lib/client/sync/bucket/SyncDataBatch.d.ts +0 -6
  45. package/lib/client/sync/bucket/SyncDataBatch.js +0 -12
  46. package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
  47. package/lib/client/sync/bucket/SyncDataBucket.d.ts +0 -40
  48. package/lib/client/sync/bucket/SyncDataBucket.js +0 -40
  49. package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
  50. package/lib/client/sync/stream/streaming-sync-types.d.ts +0 -143
  51. package/lib/client/sync/stream/streaming-sync-types.js +0 -26
  52. package/lib/client/sync/stream/streaming-sync-types.js.map +0 -1
  53. package/src/client/sync/bucket/OpType.ts +0 -23
  54. package/src/client/sync/bucket/OplogEntry.ts +0 -50
  55. package/src/client/sync/bucket/SyncDataBatch.ts +0 -11
  56. package/src/client/sync/bucket/SyncDataBucket.ts +0 -49
  57. package/src/client/sync/stream/streaming-sync-types.ts +0 -210
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  import Logger, { ILogger, ILogLevel } from 'js-logger';
2
2
  export { GlobalLogger, ILogHandler, ILogLevel, ILogger, ILoggerOpts } from 'js-logger';
3
- import { BSON } from 'bson';
4
3
  import { fetch } from 'cross-fetch';
5
4
 
6
5
  interface Disposable {
@@ -310,139 +309,6 @@ declare class CrudBatch {
310
309
  complete: (writeCheckpoint?: string) => Promise<void>);
311
310
  }
312
311
 
313
- declare enum OpTypeEnum {
314
- CLEAR = 1,
315
- MOVE = 2,
316
- PUT = 3,
317
- REMOVE = 4
318
- }
319
- type OpTypeJSON = string;
320
- /**
321
- * Used internally for sync buckets.
322
- */
323
- declare class OpType {
324
- value: OpTypeEnum;
325
- static fromJSON(jsonValue: OpTypeJSON): OpType;
326
- constructor(value: OpTypeEnum);
327
- toJSON(): string;
328
- }
329
-
330
- interface OplogEntryJSON {
331
- checksum: number;
332
- data?: string;
333
- object_id?: string;
334
- object_type?: string;
335
- op_id: string;
336
- op: OpTypeJSON;
337
- subkey?: string;
338
- }
339
- declare class OplogEntry {
340
- op_id: OpId;
341
- op: OpType;
342
- checksum: number;
343
- subkey?: string | undefined;
344
- object_type?: string | undefined;
345
- object_id?: string | undefined;
346
- data?: string | undefined;
347
- static fromRow(row: OplogEntryJSON): OplogEntry;
348
- constructor(op_id: OpId, op: OpType, checksum: number, subkey?: string | undefined, object_type?: string | undefined, object_id?: string | undefined, data?: string | undefined);
349
- toJSON(fixedKeyEncoding?: boolean): OplogEntryJSON;
350
- }
351
-
352
- type SyncDataBucketJSON = {
353
- bucket: string;
354
- has_more?: boolean;
355
- after?: string;
356
- next_after?: string;
357
- data: OplogEntryJSON[];
358
- };
359
- declare class SyncDataBucket {
360
- bucket: string;
361
- data: OplogEntry[];
362
- /**
363
- * True if the response does not contain all the data for this bucket, and another request must be made.
364
- */
365
- has_more: boolean;
366
- /**
367
- * The `after` specified in the request.
368
- */
369
- after?: OpId | undefined;
370
- /**
371
- * Use this for the next request.
372
- */
373
- next_after?: OpId | undefined;
374
- static fromRow(row: SyncDataBucketJSON): SyncDataBucket;
375
- constructor(bucket: string, data: OplogEntry[],
376
- /**
377
- * True if the response does not contain all the data for this bucket, and another request must be made.
378
- */
379
- has_more: boolean,
380
- /**
381
- * The `after` specified in the request.
382
- */
383
- after?: OpId | undefined,
384
- /**
385
- * Use this for the next request.
386
- */
387
- next_after?: OpId | undefined);
388
- toJSON(fixedKeyEncoding?: boolean): SyncDataBucketJSON;
389
- }
390
-
391
- declare class SyncDataBatch {
392
- buckets: SyncDataBucket[];
393
- static fromJSON(json: any): SyncDataBatch;
394
- constructor(buckets: SyncDataBucket[]);
395
- }
396
-
397
- interface BucketDescription {
398
- name: string;
399
- priority: number;
400
- }
401
- interface Checkpoint {
402
- last_op_id: OpId;
403
- buckets: BucketChecksum[];
404
- write_checkpoint?: string;
405
- streams?: any[];
406
- }
407
- interface BucketState {
408
- bucket: string;
409
- op_id: string;
410
- }
411
- interface ChecksumCache {
412
- checksums: Map<string, {
413
- checksum: BucketChecksum;
414
- last_op_id: OpId;
415
- }>;
416
- lastOpId: OpId;
417
- }
418
- interface SyncLocalDatabaseResult {
419
- ready: boolean;
420
- checkpointValid: boolean;
421
- checkpointFailures?: string[];
422
- }
423
- type SavedProgress = {
424
- atLast: number;
425
- sinceLast: number;
426
- };
427
- type BucketOperationProgress = Record<string, SavedProgress>;
428
- interface BucketChecksum {
429
- bucket: string;
430
- priority?: number;
431
- /**
432
- * 32-bit unsigned hash.
433
- */
434
- checksum: number;
435
- /**
436
- * Count of operations - informational only.
437
- */
438
- count?: number;
439
- /**
440
- * The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
441
- * this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
442
- * present.
443
- */
444
- subscriptions?: any;
445
- }
446
312
  declare enum PSInternalTable {
447
313
  DATA = "ps_data",
448
314
  CRUD = "ps_crud",
@@ -464,23 +330,11 @@ interface BucketStorageListener extends BaseListener {
464
330
  }
465
331
  interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
466
332
  init(): Promise<void>;
467
- saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
468
- removeBuckets(buckets: string[]): Promise<void>;
469
- setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
470
- startSession(): void;
471
- getBucketStates(): Promise<BucketState[]>;
472
- getBucketOperationProgress(): Promise<BucketOperationProgress>;
473
333
  hasMigratedSubkeys(): Promise<boolean>;
474
334
  migrateToFixedSubkeys(): Promise<void>;
475
- syncLocalDatabase(checkpoint: Checkpoint, priority?: number): Promise<{
476
- checkpointValid: boolean;
477
- ready: boolean;
478
- failures?: any[];
479
- }>;
480
335
  nextCrudItem(): Promise<CrudEntry | undefined>;
481
336
  hasCrud(): Promise<boolean>;
482
337
  getCrudBatch(limit?: number): Promise<CrudBatch | null>;
483
- hasCompletedSync(): Promise<boolean>;
484
338
  updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
485
339
  getMaxOpId(): string;
486
340
  /**
@@ -499,146 +353,6 @@ interface PowerSyncCredentials {
499
353
  expiresAt?: Date;
500
354
  }
501
355
 
502
- /**
503
- * For sync2.json
504
- */
505
- interface ContinueCheckpointRequest {
506
- /**
507
- * Existing bucket states. Only these buckets are synchronized.
508
- */
509
- buckets: BucketRequest[];
510
- checkpoint_token: string;
511
- limit?: number;
512
- }
513
- interface SyncNewCheckpointRequest {
514
- /**
515
- * Existing bucket states. Used if include_data is specified.
516
- */
517
- buckets?: BucketRequest[];
518
- request_checkpoint: {
519
- /**
520
- * Whether or not to include an initial data request.
521
- */
522
- include_data: boolean;
523
- /**
524
- * Whether or not to compute a checksum.
525
- */
526
- include_checksum: boolean;
527
- };
528
- limit?: number;
529
- }
530
- type SyncRequest = ContinueCheckpointRequest | SyncNewCheckpointRequest;
531
- interface SyncResponse {
532
- /**
533
- * Data for the buckets returned. May not have an an entry for each bucket in the request.
534
- */
535
- data?: SyncDataBucketJSON[];
536
- /**
537
- * True if the response limit has been reached, and another request must be made.
538
- */
539
- has_more: boolean;
540
- checkpoint_token?: string;
541
- checkpoint?: Checkpoint;
542
- }
543
- type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
544
- interface JSONObject {
545
- [key: string]: JSONValue;
546
- }
547
- type JSONArray = JSONValue[];
548
- type StreamingSyncRequestParameterType = JSONValue;
549
- interface StreamingSyncRequest {
550
- /**
551
- * Existing bucket states.
552
- */
553
- buckets?: BucketRequest[];
554
- /**
555
- * If specified, limit the response to only include these buckets.
556
- */
557
- only?: string[];
558
- /**
559
- * Whether or not to compute a checksum for each checkpoint
560
- */
561
- include_checksum: boolean;
562
- /**
563
- * Changes the response to stringified data in each OplogEntry
564
- */
565
- raw_data: boolean;
566
- /**
567
- * Client parameters to be passed to the sync rules.
568
- */
569
- parameters?: Record<string, StreamingSyncRequestParameterType>;
570
- /**
571
- * Application metadata to be included in service logs.
572
- */
573
- app_metadata?: Record<string, string>;
574
- client_id?: string;
575
- }
576
- interface StreamingSyncCheckpoint {
577
- checkpoint: Checkpoint;
578
- }
579
- interface StreamingSyncCheckpointDiff {
580
- checkpoint_diff: {
581
- last_op_id: OpId;
582
- updated_buckets: BucketChecksum[];
583
- removed_buckets: string[];
584
- write_checkpoint?: string;
585
- };
586
- }
587
- interface StreamingSyncDataJSON {
588
- data: SyncDataBucketJSON;
589
- }
590
- interface StreamingSyncCheckpointComplete {
591
- checkpoint_complete: {
592
- last_op_id: OpId;
593
- };
594
- }
595
- interface StreamingSyncCheckpointPartiallyComplete {
596
- partial_checkpoint_complete: {
597
- priority: number;
598
- last_op_id: OpId;
599
- };
600
- }
601
- interface StreamingSyncKeepalive {
602
- /** If specified, token expires in this many seconds. */
603
- token_expires_in: number;
604
- }
605
- type StreamingSyncLine = StreamingSyncDataJSON | StreamingSyncCheckpoint | StreamingSyncCheckpointDiff | StreamingSyncCheckpointComplete | StreamingSyncCheckpointPartiallyComplete | StreamingSyncKeepalive;
606
- type CrudUploadNotification = {
607
- crud_upload_completed: null;
608
- };
609
- type StreamingSyncLineOrCrudUploadComplete = StreamingSyncLine | CrudUploadNotification;
610
- interface BucketRequest {
611
- name: string;
612
- /**
613
- * Base-10 number. Sync all data from this bucket with op_id > after.
614
- */
615
- after: OpId;
616
- }
617
- declare function isStreamingSyncData(line: StreamingSyncLine): line is StreamingSyncDataJSON;
618
- declare function isStreamingKeepalive(line: StreamingSyncLine): line is StreamingSyncKeepalive;
619
- declare function isStreamingSyncCheckpoint(line: StreamingSyncLine): line is StreamingSyncCheckpoint;
620
- declare function isStreamingSyncCheckpointComplete(line: StreamingSyncLine): line is StreamingSyncCheckpointComplete;
621
- declare function isStreamingSyncCheckpointPartiallyComplete(line: StreamingSyncLine): line is StreamingSyncCheckpointPartiallyComplete;
622
- declare function isStreamingSyncCheckpointDiff(line: StreamingSyncLine): line is StreamingSyncCheckpointDiff;
623
- declare function isContinueCheckpointRequest(request: SyncRequest): request is ContinueCheckpointRequest;
624
- declare function isSyncNewCheckpointRequest(request: SyncRequest): request is SyncNewCheckpointRequest;
625
- /**
626
- * For crud.json
627
- */
628
- interface CrudRequest {
629
- data: CrudEntry[];
630
- }
631
- interface CrudResponse {
632
- /**
633
- * A sync response with a checkpoint >= this checkpoint would contain all the changes in this request.
634
- *
635
- * Any earlier checkpoint may or may not contain these changes.
636
- *
637
- * May be empty when the request contains no ops.
638
- */
639
- checkpoint?: OpId;
640
- }
641
-
642
356
  /**
643
357
  * An async iterator that can't be cancelled.
644
358
  *
@@ -649,7 +363,6 @@ interface CrudResponse {
649
363
  */
650
364
  type SimpleAsyncIterator<T> = Pick<AsyncIterator<T>, 'next'>;
651
365
 
652
- type BSONImplementation = typeof BSON;
653
366
  type RemoteConnector = {
654
367
  fetchCredentials: () => Promise<PowerSyncCredentials | null>;
655
368
  invalidateCredentials?: () => void;
@@ -657,7 +370,7 @@ type RemoteConnector = {
657
370
  declare const DEFAULT_REMOTE_LOGGER: Logger.ILogger;
658
371
  type SyncStreamOptions = {
659
372
  path: string;
660
- data: StreamingSyncRequest;
373
+ data: unknown;
661
374
  headers?: Record<string, string>;
662
375
  abortSignal: AbortSignal;
663
376
  fetchOptions?: Request;
@@ -760,10 +473,6 @@ declare abstract class AbstractRemote {
760
473
  }>;
761
474
  post(path: string, data: any, headers?: Record<string, string>): Promise<any>;
762
475
  get(path: string, headers?: Record<string, string>): Promise<any>;
763
- /**
764
- * Provides a BSON implementation. The import nature of this varies depending on the platform
765
- */
766
- abstract getBSON(): Promise<BSONImplementation>;
767
476
  /**
768
477
  * @returns A text decoder decoding UTF-8. This is a method to allow patching it for Hermes which doesn't support the
769
478
  * builtin, without forcing us to bundle a polyfill with `@powersync/common`.
@@ -774,11 +483,8 @@ declare abstract class AbstractRemote {
774
483
  * Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
775
484
  *
776
485
  * The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
777
- *
778
- * @param bson A BSON encoder and decoder. When set, the data stream will be requested with a BSON payload
779
- * (required for compatibility with older sync services).
780
486
  */
781
- socketStreamRaw(options: SocketSyncStreamOptions, bson?: typeof BSON): Promise<SimpleAsyncIterator<Uint8Array>>;
487
+ socketStreamRaw(options: SocketSyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array>>;
782
488
  /**
783
489
  * @returns Whether the HTTP implementation on this platform can receive streamed binary responses. This is true on
784
490
  * all platforms except React Native (who would have guessed...), where we must not request BSON responses.
@@ -805,6 +511,13 @@ declare abstract class AbstractRemote {
805
511
  fetchStream(options: SyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array | string>>;
806
512
  }
807
513
 
514
+ type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
515
+ interface JSONObject {
516
+ [key: string]: JSONValue;
517
+ }
518
+ type JSONArray = JSONValue[];
519
+ type StreamingSyncRequestParameterType = JSONValue;
520
+
808
521
  declare enum LockType {
809
522
  CRUD = "crud",
810
523
  SYNC = "sync"
@@ -814,35 +527,21 @@ declare enum SyncStreamConnectionMethod {
814
527
  WEB_SOCKET = "web-socket"
815
528
  }
816
529
  declare enum SyncClientImplementation {
817
- /**
818
- * Decodes and handles sync lines received from the sync service in JavaScript.
819
- *
820
- * This is the default option.
821
- *
822
- * @deprecated We recommend the {@link RUST} client implementation for all apps. If you have issues with
823
- * the Rust client, please file an issue or reach out to us. The JavaScript client will be removed in a future
824
- * version of the PowerSync SDK.
825
- */
826
- JAVASCRIPT = "js",
827
530
  /**
828
531
  * This implementation offloads the sync line decoding and handling into the PowerSync
829
532
  * core extension.
830
533
  *
831
- * This option is more performant than the {@link JAVASCRIPT} client, enabled by default and the
832
- * recommended client implementation for all apps.
534
+ * This is the only option, as an older JavaScript client implementation has been removed from the SDK.
833
535
  *
834
536
  * ## Compatibility warning
835
537
  *
836
538
  * The Rust sync client stores sync data in a format that is slightly different than the one used
837
- * by the old {@link JAVASCRIPT} implementation. When adopting the {@link RUST} client on existing
838
- * databases, the PowerSync SDK will migrate the format automatically.
839
- * Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
840
- * the version introducing {@link RUST} as an option) also supports the new format, so you can switch
841
- * back to {@link JAVASCRIPT} later.
539
+ * by the old JavaScript client. When adopting the {@link RUST} client on existing databases, the PowerSync SDK will
540
+ * migrate the format automatically.
842
541
  *
843
- * __However__: Upgrading the SDK version, then adopting {@link RUST} as a sync client and later
844
- * downgrading the SDK to an older version (necessarily using the JavaScript-based implementation then)
845
- * can lead to sync issues.
542
+ * SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
543
+ * implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
544
+ * possible anymore. Problematic SDK versions have been released before 2025-06-09.
846
545
  */
847
546
  RUST = "rust"
848
547
  }
@@ -895,11 +594,7 @@ interface BaseConnectionOptions {
895
594
  */
896
595
  appMetadata?: Record<string, string>;
897
596
  /**
898
- * Whether to use a JavaScript implementation to handle received sync lines from the sync
899
- * service, or whether this work should be offloaded to the PowerSync core extension.
900
- *
901
- * This defaults to the JavaScript implementation ({@link SyncClientImplementation.JAVASCRIPT})
902
- * since the ({@link SyncClientImplementation.RUST}) implementation is experimental at the moment.
597
+ * @deprecated The Rust sync client is used unconditionally, so this option can't be configured.
903
598
  */
904
599
  clientImplementation?: SyncClientImplementation;
905
600
  /**
@@ -956,9 +651,7 @@ interface StreamingSyncImplementation extends BaseObserverInterface<StreamingSyn
956
651
  */
957
652
  disconnect(): Promise<void>;
958
653
  getWriteCheckpoint: () => Promise<string>;
959
- hasCompletedSync: () => Promise<boolean>;
960
654
  isConnected: boolean;
961
- lastSyncedAt?: Date;
962
655
  syncStatus: SyncStatus;
963
656
  triggerCrudUpload: () => void;
964
657
  waitForReady(): Promise<void>;
@@ -980,10 +673,9 @@ type SubscribedStream = {
980
673
  params: Record<string, any> | null;
981
674
  };
982
675
  declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
983
- protected _lastSyncedAt: Date | null;
984
676
  protected options: AbstractStreamingSyncImplementationOptions;
985
677
  protected abortController: AbortController | null;
986
- protected uploadAbortController: AbortController | null;
678
+ protected uploadAbortController: AbortController | undefined;
987
679
  protected crudUpdateListener?: () => void;
988
680
  protected streamingSyncPromise?: Promise<void>;
989
681
  protected logger: ILogger;
@@ -1002,7 +694,6 @@ declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<
1002
694
  get isConnected(): boolean;
1003
695
  dispose(): Promise<void>;
1004
696
  abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
1005
- hasCompletedSync(): Promise<boolean>;
1006
697
  getWriteCheckpoint(): Promise<string>;
1007
698
  protected _uploadAllCrud(): Promise<void>;
1008
699
  connect(options?: PowerSyncConnectionOptions): Promise<void>;
@@ -1012,7 +703,6 @@ declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<
1012
703
  */
1013
704
  streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
1014
705
  markConnectionMayHaveChanged(): void;
1015
- private collectLocalBucketState;
1016
706
  /**
1017
707
  * Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
1018
708
  * Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
@@ -1031,10 +721,7 @@ declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<
1031
721
  private requireKeyFormat;
1032
722
  protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<RustIterationResult | null>;
1033
723
  private receiveSyncLines;
1034
- private legacyStreamingSyncIteration;
1035
724
  private rustSyncIteration;
1036
- private updateSyncStatusForStartingCheckpoint;
1037
- private applyCheckpoint;
1038
725
  protected updateSyncStatus(options: SyncStatusOptions): void;
1039
726
  private delayRetry;
1040
727
  updateSubscriptions(subscriptions: SubscribedStream[]): void;
@@ -4212,7 +3899,6 @@ declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> im
4212
3899
  private db;
4213
3900
  private logger;
4214
3901
  tableNames: Set<string>;
4215
- private _hasCompletedSync;
4216
3902
  private updateListener;
4217
3903
  private _clientId?;
4218
3904
  constructor(db: DBAdapter, logger?: ILogger);
@@ -4221,27 +3907,6 @@ declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> im
4221
3907
  _getClientId(): Promise<string>;
4222
3908
  getClientId(): Promise<string>;
4223
3909
  getMaxOpId(): string;
4224
- /**
4225
- * Reset any caches.
4226
- */
4227
- startSession(): void;
4228
- getBucketStates(): Promise<BucketState[]>;
4229
- getBucketOperationProgress(): Promise<BucketOperationProgress>;
4230
- saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
4231
- removeBuckets(buckets: string[]): Promise<void>;
4232
- /**
4233
- * Mark a bucket for deletion.
4234
- */
4235
- private deleteBucket;
4236
- hasCompletedSync(): Promise<boolean>;
4237
- syncLocalDatabase(checkpoint: Checkpoint, priority?: number): Promise<SyncLocalDatabaseResult>;
4238
- /**
4239
- * Atomically update the local state to the current checkpoint.
4240
- *
4241
- * This includes creating new tables, dropping old tables, and copying data over from the oplog.
4242
- */
4243
- private updateObjectsFromBuckets;
4244
- validateChecksums(checkpoint: Checkpoint, priority: number | undefined): Promise<SyncLocalDatabaseResult>;
4245
3910
  updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
4246
3911
  nextCrudItem(): Promise<CrudEntry | undefined>;
4247
3912
  hasCrud(): Promise<boolean>;
@@ -4253,10 +3918,6 @@ declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> im
4253
3918
  writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, options?: {
4254
3919
  timeoutMs: number;
4255
3920
  }): Promise<T>;
4256
- /**
4257
- * Set a target checkpoint.
4258
- */
4259
- setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
4260
3921
  control(op: PowerSyncControlCommand, payload: string | Uint8Array | ArrayBuffer | null): Promise<string>;
4261
3922
  hasMigratedSubkeys(): Promise<boolean>;
4262
3923
  migrateToFixedSubkeys(): Promise<void>;
@@ -4387,5 +4048,5 @@ interface ParsedQuery {
4387
4048
  }
4388
4049
  declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
4389
4050
 
4390
- export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DBAdapterDefaultMixin, DBGetUtilsDefaultMixin, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, Mutex, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, Semaphore, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID, timeoutSignal };
4391
- export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, AttachmentData, AttachmentErrorHandler, AttachmentRecord, AttachmentTableOptions, BSONImplementation, BaseColumnType, BaseConnectionOptions, BaseListener, BaseObserverInterface, BasePowerSyncDatabaseOptions, BaseTriggerDiffRecord, BatchedUpdateNotification, BucketChecksum, BucketDescription, BucketOperationProgress, BucketRequest, BucketState, BucketStorageAdapter, BucketStorageListener, Checkpoint, ChecksumCache, ColumnOptions, ColumnsType, CompilableQuery, CompilableQueryWatchHandler, CompiledQuery, ConnectionManagerListener, ConnectionManagerOptions, ConnectionManagerSyncImplementationResult, ConnectionPool, ContinueCheckpointRequest, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions, CreateSyncImplementationOptions, CrudRequest, CrudResponse, CrudUploadNotification, DBAdapter, DBAdapterListener, DBGetUtils, DBLockOptions, DifferentialQueryProcessorOptions, DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQueryListener, DifferentialWatchedQueryOptions, DifferentialWatchedQuerySettings, DisconnectAndClearOptions, Disposable, ExtractColumnValueType, ExtractedTriggerDiffRecord, FetchImplementation, GetAllQueryOptions, IndexColumnOptions, IndexOptions, IndexShorthand, InternalConnectionOptions, InternalSubscriptionAdapter, LinkQueryOptions, LocalStorageAdapter, LockContext, LockOptions, MutableWatchedQueryState, OnChangeQueryProcessorOptions, OpId, OpTypeJSON, OplogEntryJSON, ParsedQuery, PendingStatement, PendingStatementParameter, PowerSyncBackendConnector, PowerSyncCloseOptions, PowerSyncConnectionOptions, PowerSyncCredentials, PowerSyncDBListener, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, PowerSyncOpenFactoryOptions, ProgressWithOperations, Query, QueryParam, QueryResult, RawTableType, RemoteConnector, RemoteStorageAdapter, RequiredAdditionalConnectionOptions, RequiredPowerSyncConnectionOptions, RowType, SQLOnChangeOptions, SQLOpenFactory, SQLOpenOptions, SQLWatchOptions, SavedProgress, SchemaTableType, SimpleAsyncIterator, SocketSyncStreamOptions, SqlExecutor, StandardWatchedQuery, StandardWatchedQueryOptions, StreamingSyncCheckpoint, StreamingSyncCheckpointComplete, StreamingSyncCheckpointDiff, StreamingSyncCheckpointPartiallyComplete, StreamingSyncDataJSON, StreamingSyncImplementation, StreamingSyncImplementationListener, StreamingSyncKeepalive, StreamingSyncLine, StreamingSyncLineOrCrudUploadComplete, StreamingSyncRequest, StreamingSyncRequestParameterType, SubscribedStream, SyncDataBucketJSON, SyncDataFlowStatus, SyncLocalDatabaseResult, SyncNewCheckpointRequest, SyncPriorityStatus, SyncRequest, SyncResponse, SyncStatusOptions, SyncStream, SyncStreamDescription, SyncStreamOptions, SyncStreamStatus, SyncStreamSubscribeOptions, SyncStreamSubscription, SyncSubscriptionDescription, TableOptions, TableOrRawTableOptions, TableUpdateOperation, TableV2Options, TrackDiffOptions, TrackPreviousOptions, Transaction, TriggerClaimManager, TriggerCreationHooks, TriggerDiffDeleteRecord, TriggerDiffHandlerContext, TriggerDiffInsertRecord, TriggerDiffRecord, TriggerDiffUpdateRecord, TriggerManager, TriggerManagerConfig, TriggerRemoveCallback, TriggerRemoveCallbackOptions, UnlockFn, UpdateNotification, WatchCompatibleQuery, WatchExecuteOptions, WatchHandler, WatchOnChangeEvent, WatchOnChangeHandler, WatchedAttachmentItem, WatchedQuery, WatchedQueryComparator, WatchedQueryDifferential, WatchedQueryListener, WatchedQueryOptions, WatchedQueryRowDifferential, WatchedQuerySettings, WatchedQueryState, WithDiffOptions };
4051
+ export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DBAdapterDefaultMixin, DBGetUtilsDefaultMixin, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, Mutex, OnChangeQueryProcessor, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, Semaphore, SqliteBucketStorage, SyncClientImplementation, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID, timeoutSignal };
4052
+ export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, AttachmentData, AttachmentErrorHandler, AttachmentRecord, AttachmentTableOptions, BaseColumnType, BaseConnectionOptions, BaseListener, BaseObserverInterface, BasePowerSyncDatabaseOptions, BaseTriggerDiffRecord, BatchedUpdateNotification, BucketStorageAdapter, BucketStorageListener, ColumnOptions, ColumnsType, CompilableQuery, CompilableQueryWatchHandler, CompiledQuery, ConnectionManagerListener, ConnectionManagerOptions, ConnectionManagerSyncImplementationResult, ConnectionPool, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions, CreateSyncImplementationOptions, DBAdapter, DBAdapterListener, DBGetUtils, DBLockOptions, DifferentialQueryProcessorOptions, DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQueryListener, DifferentialWatchedQueryOptions, DifferentialWatchedQuerySettings, DisconnectAndClearOptions, Disposable, ExtractColumnValueType, ExtractedTriggerDiffRecord, FetchImplementation, GetAllQueryOptions, IndexColumnOptions, IndexOptions, IndexShorthand, InternalConnectionOptions, InternalSubscriptionAdapter, LinkQueryOptions, LocalStorageAdapter, LockContext, LockOptions, MutableWatchedQueryState, OnChangeQueryProcessorOptions, OpId, ParsedQuery, PendingStatement, PendingStatementParameter, PowerSyncBackendConnector, PowerSyncCloseOptions, PowerSyncConnectionOptions, PowerSyncCredentials, PowerSyncDBListener, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, PowerSyncOpenFactoryOptions, ProgressWithOperations, Query, QueryParam, QueryResult, RawTableType, RemoteConnector, RemoteStorageAdapter, RequiredAdditionalConnectionOptions, RequiredPowerSyncConnectionOptions, RowType, SQLOnChangeOptions, SQLOpenFactory, SQLOpenOptions, SQLWatchOptions, SchemaTableType, SimpleAsyncIterator, SocketSyncStreamOptions, SqlExecutor, StandardWatchedQuery, StandardWatchedQueryOptions, StreamingSyncImplementation, StreamingSyncImplementationListener, StreamingSyncRequestParameterType, SubscribedStream, SyncDataFlowStatus, SyncPriorityStatus, SyncStatusOptions, SyncStream, SyncStreamDescription, SyncStreamOptions, SyncStreamStatus, SyncStreamSubscribeOptions, SyncStreamSubscription, SyncSubscriptionDescription, TableOptions, TableOrRawTableOptions, TableUpdateOperation, TableV2Options, TrackDiffOptions, TrackPreviousOptions, Transaction, TriggerClaimManager, TriggerCreationHooks, TriggerDiffDeleteRecord, TriggerDiffHandlerContext, TriggerDiffInsertRecord, TriggerDiffRecord, TriggerDiffUpdateRecord, TriggerManager, TriggerManagerConfig, TriggerRemoveCallback, TriggerRemoveCallbackOptions, UnlockFn, UpdateNotification, WatchCompatibleQuery, WatchExecuteOptions, WatchHandler, WatchOnChangeEvent, WatchOnChangeHandler, WatchedAttachmentItem, WatchedQuery, WatchedQueryComparator, WatchedQueryDifferential, WatchedQueryListener, WatchedQueryOptions, WatchedQueryRowDifferential, WatchedQuerySettings, WatchedQueryState, WithDiffOptions };
@@ -0,0 +1,103 @@
1
+ // TypeScript definitions for sync lines sent by the PowerSync service. These aren't used in the implementation of
2
+ // PowerSync SDKs, but we keep them around for:
3
+ //
4
+ // 1. Tests mocking the PowerSync service.
5
+ // 2. The diagnostic app tracking schema updates and bucket sizes by decoding protocol messages.
6
+ // 3. The nuxt SDK offering DevTools doing the same.
7
+ //
8
+ // Uses 2 and 3 should be replaced with the builtin diagnostic collection of the core extension eventually.
9
+
10
+ export type SyncDataBucketJSON = {
11
+ bucket: string;
12
+ has_more?: boolean;
13
+ after?: string;
14
+ next_after?: string;
15
+ data: OplogEntryJSON[];
16
+ };
17
+ export interface OplogEntryJSON {
18
+ checksum: number;
19
+ data?: string;
20
+ object_id?: string;
21
+ object_type?: string;
22
+ op_id: string;
23
+ op: OpTypeJSON;
24
+ subkey?: string;
25
+ }
26
+ export type OpTypeJSON = 'CLEAR' | 'MOVE' | 'PUT' | 'REMOVE';
27
+
28
+ /**
29
+ * 64-bit unsigned integer stored as a string in base-10.
30
+ *
31
+ * Not sortable as a string.
32
+ */
33
+ export type OpId = string;
34
+
35
+ export interface BucketChecksum {
36
+ bucket: string;
37
+ priority?: number;
38
+ /**
39
+ * 32-bit unsigned hash.
40
+ */
41
+ checksum: number;
42
+
43
+ /**
44
+ * Count of operations - informational only.
45
+ */
46
+ count?: number;
47
+ /**
48
+ * The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
49
+ * this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
50
+ * present.
51
+ */
52
+ subscriptions?: any;
53
+ }
54
+
55
+ export interface Checkpoint {
56
+ last_op_id: OpId;
57
+ buckets: BucketChecksum[];
58
+ write_checkpoint?: string;
59
+ streams?: any[];
60
+ }
61
+
62
+ export interface StreamingSyncCheckpoint {
63
+ checkpoint: Checkpoint;
64
+ }
65
+
66
+ export interface StreamingSyncCheckpointDiff {
67
+ checkpoint_diff: {
68
+ last_op_id: OpId;
69
+ updated_buckets: BucketChecksum[];
70
+ removed_buckets: string[];
71
+ write_checkpoint?: string;
72
+ };
73
+ }
74
+
75
+ export interface StreamingSyncDataJSON {
76
+ data: SyncDataBucketJSON;
77
+ }
78
+
79
+ export interface StreamingSyncCheckpointComplete {
80
+ checkpoint_complete: {
81
+ last_op_id: OpId;
82
+ };
83
+ }
84
+
85
+ export interface StreamingSyncCheckpointPartiallyComplete {
86
+ partial_checkpoint_complete: {
87
+ priority: number;
88
+ last_op_id: OpId;
89
+ };
90
+ }
91
+
92
+ export interface StreamingSyncKeepalive {
93
+ /** If specified, token expires in this many seconds. */
94
+ token_expires_in: number;
95
+ }
96
+
97
+ export type StreamingSyncLine =
98
+ | StreamingSyncDataJSON
99
+ | StreamingSyncCheckpoint
100
+ | StreamingSyncCheckpointDiff
101
+ | StreamingSyncCheckpointComplete
102
+ | StreamingSyncCheckpointPartiallyComplete
103
+ | StreamingSyncKeepalive;