@powersync/common 0.0.0-dev-20250922104723 → 0.0.0-dev-20250922105207
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.
- package/dist/bundle.cjs +4 -4
- package/dist/bundle.mjs +5 -5
- package/dist/index.d.cts +845 -1054
- package/lib/client/AbstractPowerSyncDatabase.d.ts +4 -16
- package/lib/client/AbstractPowerSyncDatabase.js +26 -36
- package/lib/client/ConnectionManager.d.ts +2 -26
- package/lib/client/ConnectionManager.js +2 -114
- package/lib/client/SQLOpenFactory.d.ts +2 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +1 -9
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -1
- package/lib/client/sync/stream/AbstractRemote.js +0 -3
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +3 -24
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +39 -54
- package/lib/client/sync/stream/core-instruction.d.ts +1 -20
- package/lib/client/sync/stream/core-instruction.js +1 -26
- package/lib/client/triggers/TriggerManager.d.ts +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +0 -2
- package/lib/client/watched/WatchedQuery.js +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -2
- package/lib/client/watched/processors/AbstractQueryProcessor.js +15 -30
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -7
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -7
- package/lib/db/crud/SyncStatus.d.ts +1 -37
- package/lib/db/crud/SyncStatus.js +0 -61
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +1 -1
- package/lib/client/sync/sync-streams.d.ts +0 -98
- package/lib/client/sync/sync-streams.js +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -357,7 +357,6 @@ interface Checkpoint {
|
|
|
357
357
|
last_op_id: OpId;
|
|
358
358
|
buckets: BucketChecksum[];
|
|
359
359
|
write_checkpoint?: string;
|
|
360
|
-
streams?: any[];
|
|
361
360
|
}
|
|
362
361
|
interface BucketState {
|
|
363
362
|
bucket: string;
|
|
@@ -391,12 +390,6 @@ interface BucketChecksum {
|
|
|
391
390
|
* Count of operations - informational only.
|
|
392
391
|
*/
|
|
393
392
|
count?: number;
|
|
394
|
-
/**
|
|
395
|
-
* The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
|
|
396
|
-
* this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
|
|
397
|
-
* present.
|
|
398
|
-
*/
|
|
399
|
-
subscriptions?: any;
|
|
400
393
|
}
|
|
401
394
|
declare enum PSInternalTable {
|
|
402
395
|
DATA = "ps_data",
|
|
@@ -411,8 +404,7 @@ declare enum PowerSyncControlCommand {
|
|
|
411
404
|
STOP = "stop",
|
|
412
405
|
START = "start",
|
|
413
406
|
NOTIFY_TOKEN_REFRESHED = "refreshed_token",
|
|
414
|
-
NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload"
|
|
415
|
-
UPDATE_SUBSCRIPTIONS = "update_subscriptions"
|
|
407
|
+
NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload"
|
|
416
408
|
}
|
|
417
409
|
interface BucketStorageListener extends BaseListener {
|
|
418
410
|
crudUpdate: () => void;
|
|
@@ -584,20 +576,6 @@ interface CrudResponse {
|
|
|
584
576
|
checkpoint?: OpId;
|
|
585
577
|
}
|
|
586
578
|
|
|
587
|
-
interface CoreStreamSubscription {
|
|
588
|
-
progress: {
|
|
589
|
-
total: number;
|
|
590
|
-
downloaded: number;
|
|
591
|
-
};
|
|
592
|
-
name: string;
|
|
593
|
-
parameters: any;
|
|
594
|
-
priority: number | null;
|
|
595
|
-
active: boolean;
|
|
596
|
-
is_default: boolean;
|
|
597
|
-
has_explicit_subscription: boolean;
|
|
598
|
-
expires_at: number | null;
|
|
599
|
-
last_synced_at: number | null;
|
|
600
|
-
}
|
|
601
579
|
interface BucketProgress {
|
|
602
580
|
priority: number;
|
|
603
581
|
at_last: number;
|
|
@@ -605,1172 +583,1020 @@ interface BucketProgress {
|
|
|
605
583
|
target_count: number;
|
|
606
584
|
}
|
|
607
585
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Close the stream if any consumer throws an error
|
|
612
|
-
*/
|
|
613
|
-
closeOnError?: boolean;
|
|
614
|
-
pressure?: {
|
|
615
|
-
highWaterMark?: number;
|
|
616
|
-
lowWaterMark?: number;
|
|
617
|
-
};
|
|
618
|
-
logger?: ILogger;
|
|
619
|
-
};
|
|
620
|
-
type DataStreamCallback<Data extends any = any> = (data: Data) => Promise<void>;
|
|
621
|
-
interface DataStreamListener<Data extends any = any> extends BaseListener {
|
|
622
|
-
data: (data: Data) => Promise<void>;
|
|
623
|
-
closed: () => void;
|
|
624
|
-
error: (error: Error) => void;
|
|
625
|
-
highWater: () => Promise<void>;
|
|
626
|
-
lowWater: () => Promise<void>;
|
|
627
|
-
}
|
|
628
|
-
declare const DEFAULT_PRESSURE_LIMITS: {
|
|
629
|
-
highWater: number;
|
|
630
|
-
lowWater: number;
|
|
631
|
-
};
|
|
586
|
+
/** @internal */
|
|
587
|
+
type InternalProgressInformation = Record<string, BucketProgress>;
|
|
632
588
|
/**
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
589
|
+
* Information about a progressing download made by the PowerSync SDK.
|
|
590
|
+
*
|
|
591
|
+
* To obtain these values, use {@link SyncProgress}, available through
|
|
592
|
+
* {@link SyncStatus#downloadProgress}.
|
|
636
593
|
*/
|
|
637
|
-
|
|
638
|
-
protected options?: DataStreamOptions<ParsedData, SourceData> | undefined;
|
|
639
|
-
dataQueue: SourceData[];
|
|
640
|
-
protected isClosed: boolean;
|
|
641
|
-
protected processingPromise: Promise<void> | null;
|
|
642
|
-
protected notifyDataAdded: (() => void) | null;
|
|
643
|
-
protected logger: ILogger;
|
|
644
|
-
protected mapLine: (line: SourceData) => ParsedData;
|
|
645
|
-
constructor(options?: DataStreamOptions<ParsedData, SourceData> | undefined);
|
|
646
|
-
get highWatermark(): number;
|
|
647
|
-
get lowWatermark(): number;
|
|
648
|
-
get closed(): boolean;
|
|
649
|
-
close(): Promise<void>;
|
|
650
|
-
/**
|
|
651
|
-
* Enqueues data for the consumers to read
|
|
652
|
-
*/
|
|
653
|
-
enqueueData(data: SourceData): void;
|
|
654
|
-
/**
|
|
655
|
-
* Reads data once from the data stream
|
|
656
|
-
* @returns a Data payload or Null if the stream closed.
|
|
657
|
-
*/
|
|
658
|
-
read(): Promise<ParsedData | null>;
|
|
594
|
+
interface ProgressWithOperations {
|
|
659
595
|
/**
|
|
660
|
-
*
|
|
596
|
+
* The total amount of operations to download for the current sync iteration
|
|
597
|
+
* to complete.
|
|
661
598
|
*/
|
|
662
|
-
|
|
663
|
-
protected processQueue(): Promise<void> | undefined;
|
|
664
|
-
protected hasDataReader(): boolean;
|
|
665
|
-
protected _processQueue(): Promise<void>;
|
|
666
|
-
protected iterateAsyncErrored(cb: (l: Partial<DataStreamListener<ParsedData>>) => Promise<void>): Promise<void>;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
interface PowerSyncCredentials {
|
|
670
|
-
endpoint: string;
|
|
671
|
-
token: string;
|
|
672
|
-
expiresAt?: Date;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
type BSONImplementation = typeof BSON;
|
|
676
|
-
type RemoteConnector = {
|
|
677
|
-
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
678
|
-
invalidateCredentials?: () => void;
|
|
679
|
-
};
|
|
680
|
-
declare const DEFAULT_REMOTE_LOGGER: Logger.ILogger;
|
|
681
|
-
type SyncStreamOptions = {
|
|
682
|
-
path: string;
|
|
683
|
-
data: StreamingSyncRequest;
|
|
684
|
-
headers?: Record<string, string>;
|
|
685
|
-
abortSignal?: AbortSignal;
|
|
686
|
-
fetchOptions?: Request;
|
|
687
|
-
};
|
|
688
|
-
declare enum FetchStrategy {
|
|
599
|
+
totalOperations: number;
|
|
689
600
|
/**
|
|
690
|
-
*
|
|
691
|
-
* This comes at the cost of more processing overhead, which may cause ACK timeouts on older/weaker devices for big enough datasets.
|
|
601
|
+
* The amount of operations that have already been downloaded.
|
|
692
602
|
*/
|
|
693
|
-
|
|
603
|
+
downloadedOperations: number;
|
|
694
604
|
/**
|
|
695
|
-
*
|
|
696
|
-
*
|
|
605
|
+
* Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
|
|
606
|
+
*
|
|
607
|
+
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
608
|
+
*
|
|
609
|
+
* When this number reaches `1.0`, all changes have been received from the sync service.
|
|
610
|
+
* Actually applying these changes happens before the `downloadProgress` field is cleared from
|
|
611
|
+
* {@link SyncStatus}, so progress can stay at `1.0` for a short while before completing.
|
|
697
612
|
*/
|
|
698
|
-
|
|
613
|
+
downloadedFraction: number;
|
|
699
614
|
}
|
|
700
|
-
type SocketSyncStreamOptions = SyncStreamOptions & {
|
|
701
|
-
fetchStrategy: FetchStrategy;
|
|
702
|
-
};
|
|
703
|
-
type FetchImplementation = typeof fetch;
|
|
704
615
|
/**
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* which
|
|
616
|
+
* Provides realtime progress on how PowerSync is downloading rows.
|
|
617
|
+
*
|
|
618
|
+
* The progress until the next complete sync is available through the fields on {@link ProgressWithOperations},
|
|
619
|
+
* which this class implements.
|
|
620
|
+
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
|
|
621
|
+
* a specific priority (instead of the progress for the entire download).
|
|
622
|
+
*
|
|
623
|
+
* The reported progress always reflects the status towards the end of a sync iteration (after
|
|
624
|
+
* which a consistent snapshot of all buckets is available locally).
|
|
625
|
+
*
|
|
626
|
+
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
|
|
627
|
+
* operation takes place between syncs), it's possible for the returned numbers to be slightly
|
|
628
|
+
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
|
|
629
|
+
* The information returned is good enough to build progress bars, but not exact enough to track
|
|
630
|
+
* individual download counts.
|
|
631
|
+
*
|
|
632
|
+
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
633
|
+
* to be updated one-by-one.
|
|
709
634
|
*/
|
|
710
|
-
declare class
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
* `http(s)://` to the corresponding WebSocket variant
|
|
717
|
-
* e.g. `ws(s)://`
|
|
718
|
-
*/
|
|
719
|
-
socketUrlTransformer: (url: string) => string;
|
|
635
|
+
declare class SyncProgress implements ProgressWithOperations {
|
|
636
|
+
protected internal: InternalProgressInformation;
|
|
637
|
+
totalOperations: number;
|
|
638
|
+
downloadedOperations: number;
|
|
639
|
+
downloadedFraction: number;
|
|
640
|
+
constructor(internal: InternalProgressInformation);
|
|
720
641
|
/**
|
|
721
|
-
*
|
|
722
|
-
*
|
|
723
|
-
*
|
|
642
|
+
* Returns download progress towards all data up until the specified priority being received.
|
|
643
|
+
*
|
|
644
|
+
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
645
|
+
* to be downloaded in total and how many of them have already been received.
|
|
724
646
|
*/
|
|
725
|
-
|
|
647
|
+
untilPriority(priority: number): ProgressWithOperations;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
type SyncDataFlowStatus = Partial<{
|
|
651
|
+
downloading: boolean;
|
|
652
|
+
uploading: boolean;
|
|
726
653
|
/**
|
|
727
|
-
*
|
|
654
|
+
* Error during downloading (including connecting).
|
|
728
655
|
*
|
|
729
|
-
*
|
|
730
|
-
* `cache`, or any other fetch-compatible options.
|
|
656
|
+
* Cleared on the next successful data download.
|
|
731
657
|
*/
|
|
732
|
-
|
|
733
|
-
};
|
|
734
|
-
declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
|
|
735
|
-
declare abstract class AbstractRemote {
|
|
736
|
-
protected connector: RemoteConnector;
|
|
737
|
-
protected logger: ILogger;
|
|
738
|
-
protected credentials: PowerSyncCredentials | null;
|
|
739
|
-
protected options: AbstractRemoteOptions;
|
|
740
|
-
constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
|
|
658
|
+
downloadError?: Error;
|
|
741
659
|
/**
|
|
742
|
-
*
|
|
743
|
-
*
|
|
660
|
+
* Error during uploading.
|
|
661
|
+
* Cleared on the next successful upload.
|
|
744
662
|
*/
|
|
745
|
-
|
|
663
|
+
uploadError?: Error;
|
|
746
664
|
/**
|
|
747
|
-
*
|
|
748
|
-
* available.
|
|
665
|
+
* Internal information about how far we are downloading operations in buckets.
|
|
749
666
|
*
|
|
750
|
-
*
|
|
667
|
+
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
751
668
|
*/
|
|
752
|
-
|
|
669
|
+
downloadProgress: InternalProgressInformation | null;
|
|
670
|
+
}>;
|
|
671
|
+
interface SyncPriorityStatus {
|
|
672
|
+
priority: number;
|
|
673
|
+
lastSyncedAt?: Date;
|
|
674
|
+
hasSynced?: boolean;
|
|
675
|
+
}
|
|
676
|
+
type SyncStatusOptions = {
|
|
677
|
+
connected?: boolean;
|
|
678
|
+
connecting?: boolean;
|
|
679
|
+
dataFlow?: SyncDataFlowStatus;
|
|
680
|
+
lastSyncedAt?: Date;
|
|
681
|
+
hasSynced?: boolean;
|
|
682
|
+
priorityStatusEntries?: SyncPriorityStatus[];
|
|
683
|
+
};
|
|
684
|
+
declare class SyncStatus {
|
|
685
|
+
protected options: SyncStatusOptions;
|
|
686
|
+
constructor(options: SyncStatusOptions);
|
|
753
687
|
/**
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* Until this call succeeds, `getCredentials` will still return the
|
|
757
|
-
* old credentials.
|
|
688
|
+
* Indicates if the client is currently connected to the PowerSync service.
|
|
758
689
|
*
|
|
759
|
-
*
|
|
690
|
+
* @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
|
|
760
691
|
*/
|
|
761
|
-
|
|
692
|
+
get connected(): boolean;
|
|
762
693
|
/**
|
|
763
|
-
*
|
|
694
|
+
* Indicates if the client is in the process of establishing a connection to the PowerSync service.
|
|
764
695
|
*
|
|
765
|
-
*
|
|
766
|
-
* values.
|
|
696
|
+
* @returns {boolean} True if connecting, false otherwise. Defaults to false if not specified.
|
|
767
697
|
*/
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
*
|
|
698
|
+
get connecting(): boolean;
|
|
699
|
+
/**
|
|
700
|
+
* Time that a last sync has fully completed, if any.
|
|
701
|
+
* This timestamp is reset to null after a restart of the PowerSync service.
|
|
771
702
|
*
|
|
772
|
-
*
|
|
703
|
+
* @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
|
|
773
704
|
*/
|
|
774
|
-
|
|
775
|
-
getUserAgent(): string;
|
|
776
|
-
protected buildRequest(path: string): Promise<{
|
|
777
|
-
url: string;
|
|
778
|
-
headers: {
|
|
779
|
-
'content-type': string;
|
|
780
|
-
Authorization: string;
|
|
781
|
-
'x-user-agent': string;
|
|
782
|
-
};
|
|
783
|
-
}>;
|
|
784
|
-
post(path: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
785
|
-
get(path: string, headers?: Record<string, string>): Promise<any>;
|
|
705
|
+
get lastSyncedAt(): Date | undefined;
|
|
786
706
|
/**
|
|
787
|
-
*
|
|
707
|
+
* Indicates whether there has been at least one full sync completed since initialization.
|
|
708
|
+
*
|
|
709
|
+
* @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
|
|
710
|
+
* or undefined when the state is still being loaded from the database.
|
|
788
711
|
*/
|
|
789
|
-
|
|
790
|
-
protected createSocket(url: string): WebSocket;
|
|
712
|
+
get hasSynced(): boolean | undefined;
|
|
791
713
|
/**
|
|
792
|
-
*
|
|
714
|
+
* Provides the current data flow status regarding uploads and downloads.
|
|
793
715
|
*
|
|
794
|
-
* @
|
|
795
|
-
*
|
|
796
|
-
*
|
|
716
|
+
* @returns {SyncDataFlowStatus} An object containing:
|
|
717
|
+
* - downloading: True if actively downloading changes (only when connected is also true)
|
|
718
|
+
* - uploading: True if actively uploading changes
|
|
719
|
+
* Defaults to {downloading: false, uploading: false} if not specified.
|
|
797
720
|
*/
|
|
798
|
-
|
|
721
|
+
get dataFlowStatus(): Partial<{
|
|
722
|
+
downloading: boolean;
|
|
723
|
+
uploading: boolean;
|
|
724
|
+
/**
|
|
725
|
+
* Error during downloading (including connecting).
|
|
726
|
+
*
|
|
727
|
+
* Cleared on the next successful data download.
|
|
728
|
+
*/
|
|
729
|
+
downloadError?: Error;
|
|
730
|
+
/**
|
|
731
|
+
* Error during uploading.
|
|
732
|
+
* Cleared on the next successful upload.
|
|
733
|
+
*/
|
|
734
|
+
uploadError?: Error;
|
|
735
|
+
/**
|
|
736
|
+
* Internal information about how far we are downloading operations in buckets.
|
|
737
|
+
*
|
|
738
|
+
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
739
|
+
*/
|
|
740
|
+
downloadProgress: InternalProgressInformation | null;
|
|
741
|
+
}>;
|
|
799
742
|
/**
|
|
800
|
-
*
|
|
743
|
+
* Provides sync status information for all bucket priorities, sorted by priority (highest first).
|
|
744
|
+
*
|
|
745
|
+
* @returns {SyncPriorityStatus[]} An array of status entries for different sync priority levels,
|
|
746
|
+
* sorted with highest priorities (lower numbers) first.
|
|
801
747
|
*/
|
|
802
|
-
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
declare enum LockType {
|
|
806
|
-
CRUD = "crud",
|
|
807
|
-
SYNC = "sync"
|
|
808
|
-
}
|
|
809
|
-
declare enum SyncStreamConnectionMethod {
|
|
810
|
-
HTTP = "http",
|
|
811
|
-
WEB_SOCKET = "web-socket"
|
|
812
|
-
}
|
|
813
|
-
declare enum SyncClientImplementation {
|
|
748
|
+
get priorityStatusEntries(): SyncPriorityStatus[];
|
|
814
749
|
/**
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
* This is the default option.
|
|
750
|
+
* A realtime progress report on how many operations have been downloaded and
|
|
751
|
+
* how many are necessary in total to complete the next sync iteration.
|
|
818
752
|
*
|
|
819
|
-
*
|
|
820
|
-
* {@link DEFAULT_SYNC_CLIENT_IMPLEMENTATION} or omit the option. The explicit choice to use
|
|
821
|
-
* the JavaScript-based sync implementation will be removed from a future version of the SDK.
|
|
753
|
+
* This field is only set when {@link SyncDataFlowStatus#downloading} is also true.
|
|
822
754
|
*/
|
|
823
|
-
|
|
755
|
+
get downloadProgress(): SyncProgress | null;
|
|
824
756
|
/**
|
|
825
|
-
*
|
|
826
|
-
*
|
|
757
|
+
* Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
|
|
758
|
+
* for a specific bucket priority level.
|
|
827
759
|
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
760
|
+
* When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
|
|
761
|
+
* buckets first. When a consistent view over all buckets for all priorities up until the given priority is
|
|
762
|
+
* reached, PowerSync makes data from those buckets available before lower-priority buckets have finished
|
|
763
|
+
* syncing.
|
|
831
764
|
*
|
|
832
|
-
*
|
|
765
|
+
* This method returns the status for the requested priority or the next higher priority level that has
|
|
766
|
+
* status information available. This is because when PowerSync makes data for a given priority available,
|
|
767
|
+
* all buckets in higher-priorities are guaranteed to be consistent with that checkpoint.
|
|
833
768
|
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
* databases, the PowerSync SDK will migrate the format automatically.
|
|
837
|
-
* Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
|
|
838
|
-
* the version introducing {@link RUST} as an option) also supports the new format, so you can switch
|
|
839
|
-
* back to {@link JAVASCRIPT} later.
|
|
769
|
+
* For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
|
|
770
|
+
* with a priority of 1 may return information for priority level 3.
|
|
840
771
|
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
* can lead to sync issues.
|
|
844
|
-
*/
|
|
845
|
-
RUST = "rust"
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* The default {@link SyncClientImplementation} to use.
|
|
849
|
-
*
|
|
850
|
-
* Please use this field instead of {@link SyncClientImplementation.JAVASCRIPT} directly. A future version
|
|
851
|
-
* of the PowerSync SDK will enable {@link SyncClientImplementation.RUST} by default and remove the JavaScript
|
|
852
|
-
* option.
|
|
853
|
-
*/
|
|
854
|
-
declare const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.JAVASCRIPT;
|
|
855
|
-
/**
|
|
856
|
-
* Abstract Lock to be implemented by various JS environments
|
|
857
|
-
*/
|
|
858
|
-
interface LockOptions<T> {
|
|
859
|
-
callback: () => Promise<T>;
|
|
860
|
-
type: LockType;
|
|
861
|
-
signal?: AbortSignal;
|
|
862
|
-
}
|
|
863
|
-
interface AbstractStreamingSyncImplementationOptions extends RequiredAdditionalConnectionOptions {
|
|
864
|
-
adapter: BucketStorageAdapter;
|
|
865
|
-
subscriptions: SubscribedStream[];
|
|
866
|
-
uploadCrud: () => Promise<void>;
|
|
867
|
-
/**
|
|
868
|
-
* An identifier for which PowerSync DB this sync implementation is
|
|
869
|
-
* linked to. Most commonly DB name, but not restricted to DB name.
|
|
870
|
-
*/
|
|
871
|
-
identifier?: string;
|
|
872
|
-
logger?: ILogger;
|
|
873
|
-
remote: AbstractRemote;
|
|
874
|
-
}
|
|
875
|
-
interface StreamingSyncImplementationListener extends BaseListener {
|
|
876
|
-
/**
|
|
877
|
-
* Triggered whenever a status update has been attempted to be made or
|
|
878
|
-
* refreshed.
|
|
772
|
+
* @param {number} priority The bucket priority for which the status should be reported
|
|
773
|
+
* @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
|
|
879
774
|
*/
|
|
880
|
-
|
|
775
|
+
statusForPriority(priority: number): SyncPriorityStatus;
|
|
881
776
|
/**
|
|
882
|
-
*
|
|
777
|
+
* Compares this SyncStatus instance with another to determine if they are equal.
|
|
778
|
+
* Equality is determined by comparing the serialized JSON representation of both instances.
|
|
779
|
+
*
|
|
780
|
+
* @param {SyncStatus} status The SyncStatus instance to compare against
|
|
781
|
+
* @returns {boolean} True if the instances are considered equal, false otherwise
|
|
883
782
|
*/
|
|
884
|
-
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* Configurable options to be used when connecting to the PowerSync
|
|
888
|
-
* backend instance.
|
|
889
|
-
*/
|
|
890
|
-
type PowerSyncConnectionOptions = Omit<InternalConnectionOptions, 'serializedSchema'>;
|
|
891
|
-
interface InternalConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {
|
|
892
|
-
}
|
|
893
|
-
/** @internal */
|
|
894
|
-
interface BaseConnectionOptions {
|
|
783
|
+
isEqual(status: SyncStatus): boolean;
|
|
895
784
|
/**
|
|
896
|
-
*
|
|
897
|
-
*
|
|
785
|
+
* Creates a human-readable string representation of the current sync status.
|
|
786
|
+
* Includes information about connection state, sync completion, and data flow.
|
|
898
787
|
*
|
|
899
|
-
*
|
|
900
|
-
* since the ({@link SyncClientImplementation.RUST}) implementation is experimental at the moment.
|
|
788
|
+
* @returns {string} A string representation of the sync status
|
|
901
789
|
*/
|
|
902
|
-
|
|
790
|
+
getMessage(): string;
|
|
903
791
|
/**
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
792
|
+
* Serializes the SyncStatus instance to a plain object.
|
|
793
|
+
*
|
|
794
|
+
* @returns {SyncStatusOptions} A plain object representation of the sync status
|
|
907
795
|
*/
|
|
908
|
-
|
|
796
|
+
toJSON(): SyncStatusOptions;
|
|
797
|
+
private static comparePriorities;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
declare class UploadQueueStats {
|
|
909
801
|
/**
|
|
910
|
-
*
|
|
802
|
+
* Number of records in the upload queue.
|
|
911
803
|
*/
|
|
912
|
-
|
|
804
|
+
count: number;
|
|
913
805
|
/**
|
|
914
|
-
*
|
|
806
|
+
* Size of the upload queue in bytes.
|
|
915
807
|
*/
|
|
916
|
-
|
|
808
|
+
size: number | null;
|
|
809
|
+
constructor(
|
|
917
810
|
/**
|
|
918
|
-
*
|
|
919
|
-
*
|
|
920
|
-
* This defaults to `true`.
|
|
811
|
+
* Number of records in the upload queue.
|
|
921
812
|
*/
|
|
922
|
-
|
|
813
|
+
count: number,
|
|
923
814
|
/**
|
|
924
|
-
*
|
|
815
|
+
* Size of the upload queue in bytes.
|
|
925
816
|
*/
|
|
926
|
-
|
|
817
|
+
size?: number | null);
|
|
818
|
+
toString(): string;
|
|
927
819
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
*/
|
|
934
|
-
retryDelayMs?: number;
|
|
935
|
-
/**
|
|
936
|
-
* Backend Connector CRUD operations are throttled
|
|
937
|
-
* to occur at most every `crudUploadThrottleMs`
|
|
938
|
-
* milliseconds.
|
|
939
|
-
*/
|
|
940
|
-
crudUploadThrottleMs?: number;
|
|
820
|
+
|
|
821
|
+
declare enum ColumnType {
|
|
822
|
+
TEXT = "TEXT",
|
|
823
|
+
INTEGER = "INTEGER",
|
|
824
|
+
REAL = "REAL"
|
|
941
825
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
826
|
+
interface ColumnOptions {
|
|
827
|
+
name: string;
|
|
828
|
+
type?: ColumnType;
|
|
945
829
|
}
|
|
946
|
-
|
|
830
|
+
type BaseColumnType<T extends number | string | null> = {
|
|
831
|
+
type: ColumnType;
|
|
832
|
+
};
|
|
833
|
+
type ColumnsType = Record<string, BaseColumnType<any>>;
|
|
834
|
+
type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
|
|
835
|
+
declare const MAX_AMOUNT_OF_COLUMNS = 1999;
|
|
836
|
+
declare const column: {
|
|
837
|
+
text: BaseColumnType<string | null>;
|
|
838
|
+
integer: BaseColumnType<number | null>;
|
|
839
|
+
real: BaseColumnType<number | null>;
|
|
840
|
+
};
|
|
841
|
+
declare class Column {
|
|
842
|
+
protected options: ColumnOptions;
|
|
843
|
+
constructor(options: ColumnOptions);
|
|
844
|
+
get name(): string;
|
|
845
|
+
get type(): ColumnType | undefined;
|
|
846
|
+
toJSON(): {
|
|
847
|
+
name: string;
|
|
848
|
+
type: ColumnType | undefined;
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* A pending variant of a {@link RawTable} that doesn't have a name (because it would be inferred when creating the
|
|
854
|
+
* schema).
|
|
855
|
+
*/
|
|
856
|
+
type RawTableType = {
|
|
947
857
|
/**
|
|
948
|
-
*
|
|
858
|
+
* The statement to run when PowerSync detects that a row needs to be inserted or updated.
|
|
949
859
|
*/
|
|
950
|
-
|
|
860
|
+
put: PendingStatement;
|
|
951
861
|
/**
|
|
952
|
-
*
|
|
953
|
-
* @throws if not connected or if abort is not controlled internally
|
|
862
|
+
* The statement to run when PowerSync detects that a row needs to be deleted.
|
|
954
863
|
*/
|
|
955
|
-
|
|
956
|
-
getWriteCheckpoint: () => Promise<string>;
|
|
957
|
-
hasCompletedSync: () => Promise<boolean>;
|
|
958
|
-
isConnected: boolean;
|
|
959
|
-
lastSyncedAt?: Date;
|
|
960
|
-
syncStatus: SyncStatus;
|
|
961
|
-
triggerCrudUpload: () => void;
|
|
962
|
-
waitForReady(): Promise<void>;
|
|
963
|
-
waitForStatus(status: SyncStatusOptions): Promise<void>;
|
|
964
|
-
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
965
|
-
updateSubscriptions(subscriptions: SubscribedStream[]): void;
|
|
966
|
-
}
|
|
967
|
-
declare const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
|
|
968
|
-
declare const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
969
|
-
declare const DEFAULT_STREAMING_SYNC_OPTIONS: {
|
|
970
|
-
retryDelayMs: number;
|
|
971
|
-
crudUploadThrottleMs: number;
|
|
972
|
-
};
|
|
973
|
-
type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
|
|
974
|
-
declare const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions;
|
|
975
|
-
type SubscribedStream = {
|
|
976
|
-
name: string;
|
|
977
|
-
params: Record<string, any> | null;
|
|
864
|
+
delete: PendingStatement;
|
|
978
865
|
};
|
|
979
|
-
declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
|
|
980
|
-
protected _lastSyncedAt: Date | null;
|
|
981
|
-
protected options: AbstractStreamingSyncImplementationOptions;
|
|
982
|
-
protected abortController: AbortController | null;
|
|
983
|
-
protected uploadAbortController: AbortController | null;
|
|
984
|
-
protected crudUpdateListener?: () => void;
|
|
985
|
-
protected streamingSyncPromise?: Promise<void>;
|
|
986
|
-
protected logger: ILogger;
|
|
987
|
-
private activeStreams;
|
|
988
|
-
private isUploadingCrud;
|
|
989
|
-
private notifyCompletedUploads?;
|
|
990
|
-
private handleActiveStreamsChange?;
|
|
991
|
-
syncStatus: SyncStatus;
|
|
992
|
-
triggerCrudUpload: () => void;
|
|
993
|
-
constructor(options: AbstractStreamingSyncImplementationOptions);
|
|
994
|
-
waitForReady(): Promise<void>;
|
|
995
|
-
waitForStatus(status: SyncStatusOptions): Promise<void>;
|
|
996
|
-
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
997
|
-
get lastSyncedAt(): Date | undefined;
|
|
998
|
-
get isConnected(): boolean;
|
|
999
|
-
dispose(): Promise<void>;
|
|
1000
|
-
abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
|
|
1001
|
-
hasCompletedSync(): Promise<boolean>;
|
|
1002
|
-
getWriteCheckpoint(): Promise<string>;
|
|
1003
|
-
protected _uploadAllCrud(): Promise<void>;
|
|
1004
|
-
connect(options?: PowerSyncConnectionOptions): Promise<void>;
|
|
1005
|
-
disconnect(): Promise<void>;
|
|
1006
|
-
/**
|
|
1007
|
-
* @deprecated use [connect instead]
|
|
1008
|
-
*/
|
|
1009
|
-
streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
|
|
1010
|
-
private collectLocalBucketState;
|
|
1011
|
-
/**
|
|
1012
|
-
* Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
|
|
1013
|
-
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
1014
|
-
* While this is not a problem as long as it's done consistently, it causes issues when a database
|
|
1015
|
-
* created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
|
|
1016
|
-
* is enabled.
|
|
1017
|
-
*
|
|
1018
|
-
* So, we add a migration from the old key format (with quotes) to the new one (no quotes). The
|
|
1019
|
-
* migration is only triggered when necessary (for now). The function returns whether the new format
|
|
1020
|
-
* should be used, so that the JS SDK is able to write to updated databases.
|
|
1021
|
-
*
|
|
1022
|
-
* @param requireFixedKeyFormat Whether we require the new format or also support the old one.
|
|
1023
|
-
* The Rust client requires the new subkey format.
|
|
1024
|
-
* @returns Whether the database is now using the new, fixed subkey format.
|
|
1025
|
-
*/
|
|
1026
|
-
private requireKeyFormat;
|
|
1027
|
-
protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<RustIterationResult | null>;
|
|
1028
|
-
private legacyStreamingSyncIteration;
|
|
1029
|
-
private rustSyncIteration;
|
|
1030
|
-
private updateSyncStatusForStartingCheckpoint;
|
|
1031
|
-
private applyCheckpoint;
|
|
1032
|
-
protected updateSyncStatus(options: SyncStatusOptions): void;
|
|
1033
|
-
private delayRetry;
|
|
1034
|
-
updateSubscriptions(subscriptions: SubscribedStream[]): void;
|
|
1035
|
-
}
|
|
1036
|
-
interface RustIterationResult {
|
|
1037
|
-
immediateRestart: boolean;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/** @internal */
|
|
1041
|
-
type InternalProgressInformation = Record<string, BucketProgress>;
|
|
1042
866
|
/**
|
|
1043
|
-
*
|
|
867
|
+
* A parameter to use as part of {@link PendingStatement}.
|
|
1044
868
|
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
869
|
+
* For delete statements, only the `"Id"` value is supported - the sync client will replace it with the id of the row to
|
|
870
|
+
* be synced.
|
|
871
|
+
*
|
|
872
|
+
* For insert and replace operations, the values of columns in the table are available as parameters through
|
|
873
|
+
* `{Column: 'name'}`.
|
|
1047
874
|
*/
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
* to complete.
|
|
1052
|
-
*/
|
|
1053
|
-
totalOperations: number;
|
|
1054
|
-
/**
|
|
1055
|
-
* The amount of operations that have already been downloaded.
|
|
1056
|
-
*/
|
|
1057
|
-
downloadedOperations: number;
|
|
1058
|
-
/**
|
|
1059
|
-
* Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
|
|
1060
|
-
*
|
|
1061
|
-
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
1062
|
-
*
|
|
1063
|
-
* When this number reaches `1.0`, all changes have been received from the sync service.
|
|
1064
|
-
* Actually applying these changes happens before the `downloadProgress` field is cleared from
|
|
1065
|
-
* {@link SyncStatus}, so progress can stay at `1.0` for a short while before completing.
|
|
1066
|
-
*/
|
|
1067
|
-
downloadedFraction: number;
|
|
1068
|
-
}
|
|
875
|
+
type PendingStatementParameter = 'Id' | {
|
|
876
|
+
Column: string;
|
|
877
|
+
};
|
|
1069
878
|
/**
|
|
1070
|
-
*
|
|
879
|
+
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
880
|
+
*/
|
|
881
|
+
type PendingStatement = {
|
|
882
|
+
sql: string;
|
|
883
|
+
params: PendingStatementParameter[];
|
|
884
|
+
};
|
|
885
|
+
/**
|
|
886
|
+
* Instructs PowerSync to sync data into a "raw" table.
|
|
1071
887
|
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1074
|
-
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
|
|
1075
|
-
* a specific priority (instead of the progress for the entire download).
|
|
888
|
+
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
889
|
+
* using client-side table and column constraints.
|
|
1076
890
|
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
891
|
+
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
892
|
+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
893
|
+
* using raw tables.
|
|
1079
894
|
*
|
|
1080
|
-
*
|
|
1081
|
-
* operation takes place between syncs), it's possible for the returned numbers to be slightly
|
|
1082
|
-
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
|
|
1083
|
-
* The information returned is good enough to build progress bars, but not exact enough to track
|
|
1084
|
-
* individual download counts.
|
|
895
|
+
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1085
896
|
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
897
|
+
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
898
|
+
* stability guarantees.
|
|
1088
899
|
*/
|
|
1089
|
-
declare class
|
|
1090
|
-
protected internal: InternalProgressInformation;
|
|
1091
|
-
totalOperations: number;
|
|
1092
|
-
downloadedOperations: number;
|
|
1093
|
-
downloadedFraction: number;
|
|
1094
|
-
constructor(internal: InternalProgressInformation);
|
|
900
|
+
declare class RawTable implements RawTableType {
|
|
1095
901
|
/**
|
|
1096
|
-
*
|
|
902
|
+
* The name of the table.
|
|
1097
903
|
*
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
904
|
+
* This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
|
|
905
|
+
* another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
|
|
906
|
+
* appears in the source / backend database) are to be handled specially.
|
|
1100
907
|
*/
|
|
1101
|
-
|
|
908
|
+
name: string;
|
|
909
|
+
put: PendingStatement;
|
|
910
|
+
delete: PendingStatement;
|
|
911
|
+
constructor(name: string, type: RawTableType);
|
|
1102
912
|
}
|
|
1103
913
|
|
|
1104
|
-
|
|
1105
|
-
* A description of a sync stream, consisting of its {@link name} and the {@link parameters} used when subscribing.
|
|
1106
|
-
*/
|
|
1107
|
-
interface SyncStreamDescription {
|
|
1108
|
-
/**
|
|
1109
|
-
* The name of the stream as it appears in the stream definition for the PowerSync service.
|
|
1110
|
-
*/
|
|
914
|
+
interface IndexColumnOptions {
|
|
1111
915
|
name: string;
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
916
|
+
ascending?: boolean;
|
|
917
|
+
}
|
|
918
|
+
declare const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions>;
|
|
919
|
+
declare class IndexedColumn {
|
|
920
|
+
protected options: IndexColumnOptions;
|
|
921
|
+
static createAscending(column: string): IndexedColumn;
|
|
922
|
+
constructor(options: IndexColumnOptions);
|
|
923
|
+
get name(): string;
|
|
924
|
+
get ascending(): boolean | undefined;
|
|
925
|
+
toJSON(table: Table): {
|
|
926
|
+
name: string;
|
|
927
|
+
ascending: boolean | undefined;
|
|
928
|
+
type: ColumnType;
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
interface IndexOptions {
|
|
933
|
+
name: string;
|
|
934
|
+
columns?: IndexedColumn[];
|
|
935
|
+
}
|
|
936
|
+
declare const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions>;
|
|
937
|
+
declare class Index {
|
|
938
|
+
protected options: IndexOptions;
|
|
939
|
+
static createAscending(options: IndexOptions, columnNames: string[]): Index;
|
|
940
|
+
constructor(options: IndexOptions);
|
|
941
|
+
get name(): string;
|
|
942
|
+
get columns(): IndexedColumn[];
|
|
943
|
+
toJSON(table: Table): {
|
|
944
|
+
name: string;
|
|
945
|
+
columns: {
|
|
946
|
+
name: string;
|
|
947
|
+
ascending: boolean | undefined;
|
|
948
|
+
type: ColumnType;
|
|
949
|
+
}[];
|
|
950
|
+
};
|
|
1118
951
|
}
|
|
952
|
+
|
|
1119
953
|
/**
|
|
1120
|
-
|
|
954
|
+
Generate a new table from the columns and indexes
|
|
955
|
+
@deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
|
|
956
|
+
This will be removed in the next major release.
|
|
957
|
+
*/
|
|
958
|
+
declare class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
interface SharedTableOptions {
|
|
962
|
+
localOnly?: boolean;
|
|
963
|
+
insertOnly?: boolean;
|
|
964
|
+
viewName?: string;
|
|
965
|
+
trackPrevious?: boolean | TrackPreviousOptions;
|
|
966
|
+
trackMetadata?: boolean;
|
|
967
|
+
ignoreEmptyUpdates?: boolean;
|
|
968
|
+
}
|
|
969
|
+
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
1121
970
|
*
|
|
1122
|
-
*
|
|
971
|
+
* Including old values may be helpful for some backend connector implementations, which is
|
|
972
|
+
* why it can be enabled on per-table or per-columm basis.
|
|
1123
973
|
*/
|
|
1124
|
-
interface
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
*
|
|
1130
|
-
* It's possible for both {@link isDefault} and {@link hasExplicitSubscription} to be true at the same time - this
|
|
1131
|
-
* happens when a default stream was subscribed explicitly.
|
|
1132
|
-
*/
|
|
1133
|
-
isDefault: boolean;
|
|
1134
|
-
/**
|
|
1135
|
-
* Whether this stream has been subscribed to explicitly.
|
|
1136
|
-
*
|
|
1137
|
-
* It's possible for both {@link isDefault} and {@link hasExplicitSubscription} to be true at the same time - this
|
|
1138
|
-
* happens when a default stream was subscribed explicitly.
|
|
1139
|
-
*/
|
|
1140
|
-
hasExplicitSubscription: boolean;
|
|
1141
|
-
/**
|
|
1142
|
-
* For sync streams that have a time-to-live, the current time at which the stream would expire if not subscribed to
|
|
1143
|
-
* again.
|
|
1144
|
-
*/
|
|
1145
|
-
expiresAt: Date | null;
|
|
1146
|
-
/**
|
|
1147
|
-
* Whether this stream subscription has been synced at least once.
|
|
1148
|
-
*/
|
|
1149
|
-
hasSynced: boolean;
|
|
1150
|
-
/**
|
|
1151
|
-
* If {@link hasSynced} is true, the last time data from this stream has been synced.
|
|
1152
|
-
*/
|
|
1153
|
-
lastSyncedAt: Date | null;
|
|
974
|
+
interface TrackPreviousOptions {
|
|
975
|
+
/** When defined, a list of column names for which old values should be tracked. */
|
|
976
|
+
columns?: string[];
|
|
977
|
+
/** When enabled, only include values that have actually been changed by an update. */
|
|
978
|
+
onlyWhenChanged?: boolean;
|
|
1154
979
|
}
|
|
1155
|
-
interface
|
|
1156
|
-
/**
|
|
1157
|
-
* A "time to live" for this stream subscription, in seconds.
|
|
1158
|
-
*
|
|
1159
|
-
* The TTL control when a stream gets evicted after not having an active {@link SyncStreamSubscription} object
|
|
1160
|
-
* attached to it.
|
|
1161
|
-
*/
|
|
1162
|
-
ttl?: number;
|
|
980
|
+
interface TableOptions extends SharedTableOptions {
|
|
1163
981
|
/**
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1166
|
-
* For details on priorities, see [priotized sync](https://docs.powersync.com/usage/use-case-examples/prioritized-sync).
|
|
982
|
+
* The synced table name, matching sync rules
|
|
1167
983
|
*/
|
|
1168
|
-
|
|
984
|
+
name: string;
|
|
985
|
+
columns: Column[];
|
|
986
|
+
indexes?: Index[];
|
|
1169
987
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
988
|
+
type RowType<T extends TableV2<any>> = {
|
|
989
|
+
[K in keyof T['columnMap']]: ExtractColumnValueType<T['columnMap'][K]>;
|
|
990
|
+
} & {
|
|
991
|
+
id: string;
|
|
992
|
+
};
|
|
993
|
+
type IndexShorthand = Record<string, string[]>;
|
|
994
|
+
interface TableV2Options extends SharedTableOptions {
|
|
995
|
+
indexes?: IndexShorthand;
|
|
996
|
+
}
|
|
997
|
+
declare const DEFAULT_TABLE_OPTIONS: {
|
|
998
|
+
indexes: never[];
|
|
999
|
+
insertOnly: boolean;
|
|
1000
|
+
localOnly: boolean;
|
|
1001
|
+
trackPrevious: boolean;
|
|
1002
|
+
trackMetadata: boolean;
|
|
1003
|
+
ignoreEmptyUpdates: boolean;
|
|
1004
|
+
};
|
|
1005
|
+
declare const InvalidSQLCharacters: RegExp;
|
|
1006
|
+
declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
1007
|
+
protected options: TableOptions;
|
|
1008
|
+
protected _mappedColumns: Columns;
|
|
1009
|
+
static createLocalOnly(options: TableOptions): Table<ColumnsType>;
|
|
1010
|
+
static createInsertOnly(options: TableOptions): Table<ColumnsType>;
|
|
1176
1011
|
/**
|
|
1177
|
-
*
|
|
1012
|
+
* Create a table.
|
|
1013
|
+
* @deprecated This was only only included for TableV2 and is no longer necessary.
|
|
1014
|
+
* Prefer to use new Table() directly.
|
|
1178
1015
|
*
|
|
1179
|
-
*
|
|
1180
|
-
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
1181
|
-
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
1182
|
-
* eventually evict the stream (unless {@link subscribe} is called again).
|
|
1016
|
+
* TODO remove in the next major release.
|
|
1183
1017
|
*/
|
|
1184
|
-
|
|
1018
|
+
static createTable(name: string, table: Table): Table<ColumnsType>;
|
|
1185
1019
|
/**
|
|
1186
|
-
*
|
|
1020
|
+
* Creates a new Table instance.
|
|
1187
1021
|
*
|
|
1188
|
-
* This
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
*
|
|
1022
|
+
* This constructor supports two different versions:
|
|
1023
|
+
* 1. New constructor: Using a Columns object and an optional TableV2Options object
|
|
1024
|
+
* 2. Deprecated constructor: Using a TableOptions object (will be removed in the next major release)
|
|
1025
|
+
*
|
|
1026
|
+
* @constructor
|
|
1027
|
+
* @param {Columns | TableOptions} optionsOrColumns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax)
|
|
1028
|
+
* @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```javascript
|
|
1032
|
+
* // New Constructor
|
|
1033
|
+
* const table = new Table(
|
|
1034
|
+
* {
|
|
1035
|
+
* name: column.text,
|
|
1036
|
+
* age: column.integer
|
|
1037
|
+
* },
|
|
1038
|
+
* { indexes: { nameIndex: ['name'] } }
|
|
1039
|
+
* );
|
|
1040
|
+
*```
|
|
1041
|
+
*
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```javascript
|
|
1045
|
+
* // Deprecated Constructor
|
|
1046
|
+
* const table = new Table({
|
|
1047
|
+
* name: 'users',
|
|
1048
|
+
* columns: [
|
|
1049
|
+
* new Column({ name: 'name', type: ColumnType.TEXT }),
|
|
1050
|
+
* new Column({ name: 'age', type: ColumnType.INTEGER })
|
|
1051
|
+
* ]
|
|
1052
|
+
* });
|
|
1053
|
+
*```
|
|
1195
1054
|
*/
|
|
1196
|
-
|
|
1055
|
+
constructor(columns: Columns, options?: TableV2Options);
|
|
1197
1056
|
/**
|
|
1198
|
-
*
|
|
1057
|
+
* @deprecated This constructor will be removed in the next major release.
|
|
1058
|
+
* Use the new constructor shown below instead as this does not show types.
|
|
1059
|
+
* @example
|
|
1060
|
+
* <caption>Use this instead</caption>
|
|
1061
|
+
* ```javascript
|
|
1062
|
+
* const table = new Table(
|
|
1063
|
+
* {
|
|
1064
|
+
* name: column.text,
|
|
1065
|
+
* age: column.integer
|
|
1066
|
+
* },
|
|
1067
|
+
* { indexes: { nameIndex: ['name'] } }
|
|
1068
|
+
* );
|
|
1069
|
+
*```
|
|
1199
1070
|
*/
|
|
1200
|
-
|
|
1071
|
+
constructor(options: TableOptions);
|
|
1072
|
+
copyWithName(name: string): Table;
|
|
1073
|
+
private isTableV1;
|
|
1074
|
+
private initTableV1;
|
|
1075
|
+
private initTableV2;
|
|
1076
|
+
private applyDefaultOptions;
|
|
1077
|
+
get name(): string;
|
|
1078
|
+
get viewNameOverride(): string | undefined;
|
|
1079
|
+
get viewName(): string;
|
|
1080
|
+
get columns(): Column[];
|
|
1081
|
+
get columnMap(): Columns;
|
|
1082
|
+
get indexes(): Index[];
|
|
1083
|
+
get localOnly(): boolean;
|
|
1084
|
+
get insertOnly(): boolean;
|
|
1085
|
+
get trackPrevious(): boolean | TrackPreviousOptions;
|
|
1086
|
+
get trackMetadata(): boolean;
|
|
1087
|
+
get ignoreEmptyUpdates(): boolean;
|
|
1088
|
+
get internalName(): string;
|
|
1089
|
+
get validName(): boolean;
|
|
1090
|
+
validate(): void;
|
|
1091
|
+
toJSON(): {
|
|
1092
|
+
name: string;
|
|
1093
|
+
view_name: string;
|
|
1094
|
+
local_only: boolean;
|
|
1095
|
+
insert_only: boolean;
|
|
1096
|
+
include_old: any;
|
|
1097
|
+
include_old_only_when_changed: boolean;
|
|
1098
|
+
include_metadata: boolean;
|
|
1099
|
+
ignore_empty_update: boolean;
|
|
1100
|
+
columns: {
|
|
1101
|
+
name: string;
|
|
1102
|
+
type: ColumnType | undefined;
|
|
1103
|
+
}[];
|
|
1104
|
+
indexes: {
|
|
1105
|
+
name: string;
|
|
1106
|
+
columns: {
|
|
1107
|
+
name: string;
|
|
1108
|
+
ascending: boolean | undefined;
|
|
1109
|
+
type: ColumnType;
|
|
1110
|
+
}[];
|
|
1111
|
+
}[];
|
|
1112
|
+
};
|
|
1201
1113
|
}
|
|
1202
1114
|
|
|
1203
|
-
type
|
|
1204
|
-
|
|
1205
|
-
|
|
1115
|
+
type SchemaType = Record<string, Table<any>>;
|
|
1116
|
+
type SchemaTableType<S extends SchemaType> = {
|
|
1117
|
+
[K in keyof S]: RowType<S[K]>;
|
|
1118
|
+
};
|
|
1119
|
+
/**
|
|
1120
|
+
* A schema is a collection of tables. It is used to define the structure of a database.
|
|
1121
|
+
*/
|
|
1122
|
+
declare class Schema<S extends SchemaType = SchemaType> {
|
|
1123
|
+
readonly types: SchemaTableType<S>;
|
|
1124
|
+
readonly props: S;
|
|
1125
|
+
readonly tables: Table[];
|
|
1126
|
+
readonly rawTables: RawTable[];
|
|
1127
|
+
constructor(tables: Table[] | S);
|
|
1206
1128
|
/**
|
|
1207
|
-
*
|
|
1129
|
+
* Adds raw tables to this schema. Raw tables are identified by their name, but entirely managed by the application
|
|
1130
|
+
* developer instead of automatically by PowerSync.
|
|
1131
|
+
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1132
|
+
* using client-side table and column constraints.
|
|
1133
|
+
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1208
1134
|
*
|
|
1209
|
-
*
|
|
1135
|
+
* @param tables An object of (table name, raw table definition) entries.
|
|
1136
|
+
* @experimental Note that the raw tables API is still experimental and may change in the future.
|
|
1210
1137
|
*/
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1138
|
+
withRawTables(tables: Record<string, RawTableType>): void;
|
|
1139
|
+
validate(): void;
|
|
1140
|
+
toJSON(): {
|
|
1141
|
+
tables: {
|
|
1142
|
+
name: string;
|
|
1143
|
+
view_name: string;
|
|
1144
|
+
local_only: boolean;
|
|
1145
|
+
insert_only: boolean;
|
|
1146
|
+
include_old: any;
|
|
1147
|
+
include_old_only_when_changed: boolean;
|
|
1148
|
+
include_metadata: boolean;
|
|
1149
|
+
ignore_empty_update: boolean;
|
|
1150
|
+
columns: {
|
|
1151
|
+
name: string;
|
|
1152
|
+
type: ColumnType | undefined;
|
|
1153
|
+
}[];
|
|
1154
|
+
indexes: {
|
|
1155
|
+
name: string;
|
|
1156
|
+
columns: {
|
|
1157
|
+
name: string;
|
|
1158
|
+
ascending: boolean | undefined;
|
|
1159
|
+
type: ColumnType;
|
|
1160
|
+
}[];
|
|
1161
|
+
}[];
|
|
1162
|
+
}[];
|
|
1163
|
+
raw_tables: RawTable[];
|
|
1164
|
+
};
|
|
1165
|
+
private convertToClassicTables;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
interface PowerSyncCredentials {
|
|
1169
|
+
endpoint: string;
|
|
1170
|
+
token: string;
|
|
1171
|
+
expiresAt?: Date;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
interface PowerSyncBackendConnector {
|
|
1175
|
+
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
1176
|
+
* which is used to authenticate against the PowerSync service.
|
|
1177
|
+
*
|
|
1178
|
+
* This should always fetch a fresh set of credentials - don't use cached
|
|
1179
|
+
* values.
|
|
1180
|
+
*
|
|
1181
|
+
* Return null if the user is not signed in. Throw an error if credentials
|
|
1182
|
+
* cannot be fetched due to a network error or other temporary error.
|
|
1183
|
+
*
|
|
1184
|
+
* This token is kept for the duration of a sync connection.
|
|
1215
1185
|
*/
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* Internal information about how far we are downloading operations in buckets.
|
|
1186
|
+
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
1187
|
+
/** Upload local changes to the app backend.
|
|
1219
1188
|
*
|
|
1220
|
-
*
|
|
1189
|
+
* Use {@link AbstractPowerSyncDatabase.getCrudBatch} to get a batch of changes to upload.
|
|
1190
|
+
*
|
|
1191
|
+
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
1221
1192
|
*/
|
|
1222
|
-
|
|
1223
|
-
internalStreamSubscriptions: CoreStreamSubscription[] | null;
|
|
1224
|
-
}>;
|
|
1225
|
-
interface SyncPriorityStatus {
|
|
1226
|
-
priority: number;
|
|
1227
|
-
lastSyncedAt?: Date;
|
|
1228
|
-
hasSynced?: boolean;
|
|
1193
|
+
uploadData: (database: AbstractPowerSyncDatabase) => Promise<void>;
|
|
1229
1194
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
dataFlow?: SyncDataFlowStatus;
|
|
1234
|
-
lastSyncedAt?: Date;
|
|
1235
|
-
hasSynced?: boolean;
|
|
1236
|
-
priorityStatusEntries?: SyncPriorityStatus[];
|
|
1237
|
-
clientImplementation?: SyncClientImplementation;
|
|
1238
|
-
};
|
|
1239
|
-
declare class SyncStatus {
|
|
1240
|
-
protected options: SyncStatusOptions;
|
|
1241
|
-
constructor(options: SyncStatusOptions);
|
|
1195
|
+
|
|
1196
|
+
type DataStreamOptions<ParsedData, SourceData> = {
|
|
1197
|
+
mapLine?: (line: SourceData) => ParsedData;
|
|
1242
1198
|
/**
|
|
1243
|
-
*
|
|
1244
|
-
* implementation).
|
|
1245
|
-
*
|
|
1246
|
-
* This information is only available after a connection has been requested.
|
|
1199
|
+
* Close the stream if any consumer throws an error
|
|
1247
1200
|
*/
|
|
1248
|
-
|
|
1201
|
+
closeOnError?: boolean;
|
|
1202
|
+
pressure?: {
|
|
1203
|
+
highWaterMark?: number;
|
|
1204
|
+
lowWaterMark?: number;
|
|
1205
|
+
};
|
|
1206
|
+
logger?: ILogger;
|
|
1207
|
+
};
|
|
1208
|
+
type DataStreamCallback<Data extends any = any> = (data: Data) => Promise<void>;
|
|
1209
|
+
interface DataStreamListener<Data extends any = any> extends BaseListener {
|
|
1210
|
+
data: (data: Data) => Promise<void>;
|
|
1211
|
+
closed: () => void;
|
|
1212
|
+
error: (error: Error) => void;
|
|
1213
|
+
highWater: () => Promise<void>;
|
|
1214
|
+
lowWater: () => Promise<void>;
|
|
1215
|
+
}
|
|
1216
|
+
declare const DEFAULT_PRESSURE_LIMITS: {
|
|
1217
|
+
highWater: number;
|
|
1218
|
+
lowWater: number;
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* A very basic implementation of a data stream with backpressure support which does not use
|
|
1222
|
+
* native JS streams or async iterators.
|
|
1223
|
+
* This is handy for environments such as React Native which need polyfills for the above.
|
|
1224
|
+
*/
|
|
1225
|
+
declare class DataStream<ParsedData, SourceData = any> extends BaseObserver<DataStreamListener<ParsedData>> {
|
|
1226
|
+
protected options?: DataStreamOptions<ParsedData, SourceData> | undefined;
|
|
1227
|
+
dataQueue: SourceData[];
|
|
1228
|
+
protected isClosed: boolean;
|
|
1229
|
+
protected processingPromise: Promise<void> | null;
|
|
1230
|
+
protected notifyDataAdded: (() => void) | null;
|
|
1231
|
+
protected logger: ILogger;
|
|
1232
|
+
protected mapLine: (line: SourceData) => ParsedData;
|
|
1233
|
+
constructor(options?: DataStreamOptions<ParsedData, SourceData> | undefined);
|
|
1234
|
+
get highWatermark(): number;
|
|
1235
|
+
get lowWatermark(): number;
|
|
1236
|
+
get closed(): boolean;
|
|
1237
|
+
close(): Promise<void>;
|
|
1249
1238
|
/**
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
* @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
|
|
1239
|
+
* Enqueues data for the consumers to read
|
|
1253
1240
|
*/
|
|
1254
|
-
|
|
1241
|
+
enqueueData(data: SourceData): void;
|
|
1255
1242
|
/**
|
|
1256
|
-
*
|
|
1257
|
-
*
|
|
1258
|
-
* @returns {boolean} True if connecting, false otherwise. Defaults to false if not specified.
|
|
1243
|
+
* Reads data once from the data stream
|
|
1244
|
+
* @returns a Data payload or Null if the stream closed.
|
|
1259
1245
|
*/
|
|
1260
|
-
|
|
1246
|
+
read(): Promise<ParsedData | null>;
|
|
1261
1247
|
/**
|
|
1262
|
-
*
|
|
1263
|
-
* This timestamp is reset to null after a restart of the PowerSync service.
|
|
1264
|
-
*
|
|
1265
|
-
* @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
|
|
1248
|
+
* Executes a callback for each data item in the stream
|
|
1266
1249
|
*/
|
|
1267
|
-
|
|
1250
|
+
forEach(callback: DataStreamCallback<ParsedData>): () => void;
|
|
1251
|
+
protected processQueue(): Promise<void> | undefined;
|
|
1252
|
+
protected hasDataReader(): boolean;
|
|
1253
|
+
protected _processQueue(): Promise<void>;
|
|
1254
|
+
protected iterateAsyncErrored(cb: (l: Partial<DataStreamListener<ParsedData>>) => Promise<void>): Promise<void>;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
type BSONImplementation = typeof BSON;
|
|
1258
|
+
type RemoteConnector = {
|
|
1259
|
+
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
1260
|
+
invalidateCredentials?: () => void;
|
|
1261
|
+
};
|
|
1262
|
+
declare const DEFAULT_REMOTE_LOGGER: Logger.ILogger;
|
|
1263
|
+
type SyncStreamOptions = {
|
|
1264
|
+
path: string;
|
|
1265
|
+
data: StreamingSyncRequest;
|
|
1266
|
+
headers?: Record<string, string>;
|
|
1267
|
+
abortSignal?: AbortSignal;
|
|
1268
|
+
fetchOptions?: Request;
|
|
1269
|
+
};
|
|
1270
|
+
declare enum FetchStrategy {
|
|
1268
1271
|
/**
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
* @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
|
|
1272
|
-
* or undefined when the state is still being loaded from the database.
|
|
1272
|
+
* Queues multiple sync events before processing, reducing round-trips.
|
|
1273
|
+
* This comes at the cost of more processing overhead, which may cause ACK timeouts on older/weaker devices for big enough datasets.
|
|
1273
1274
|
*/
|
|
1274
|
-
|
|
1275
|
+
Buffered = "buffered",
|
|
1275
1276
|
/**
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
* @returns {SyncDataFlowStatus} An object containing:
|
|
1279
|
-
* - downloading: True if actively downloading changes (only when connected is also true)
|
|
1280
|
-
* - uploading: True if actively uploading changes
|
|
1281
|
-
* Defaults to {downloading: false, uploading: false} if not specified.
|
|
1277
|
+
* Processes each sync event immediately before requesting the next.
|
|
1278
|
+
* This reduces processing overhead and improves real-time responsiveness.
|
|
1282
1279
|
*/
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
*
|
|
1300
|
-
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
|
|
1301
|
-
*/
|
|
1302
|
-
downloadProgress: InternalProgressInformation | null;
|
|
1303
|
-
internalStreamSubscriptions: CoreStreamSubscription[] | null;
|
|
1304
|
-
}>;
|
|
1280
|
+
Sequential = "sequential"
|
|
1281
|
+
}
|
|
1282
|
+
type SocketSyncStreamOptions = SyncStreamOptions & {
|
|
1283
|
+
fetchStrategy: FetchStrategy;
|
|
1284
|
+
};
|
|
1285
|
+
type FetchImplementation = typeof fetch;
|
|
1286
|
+
/**
|
|
1287
|
+
* Class wrapper for providing a fetch implementation.
|
|
1288
|
+
* The class wrapper is used to distinguish the fetchImplementation
|
|
1289
|
+
* option in [AbstractRemoteOptions] from the general fetch method
|
|
1290
|
+
* which is typeof "function"
|
|
1291
|
+
*/
|
|
1292
|
+
declare class FetchImplementationProvider {
|
|
1293
|
+
getFetch(): FetchImplementation;
|
|
1294
|
+
}
|
|
1295
|
+
type AbstractRemoteOptions = {
|
|
1305
1296
|
/**
|
|
1306
|
-
*
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1309
|
-
* included streams yet.
|
|
1310
|
-
*
|
|
1311
|
-
* @experimental Sync streams are currently in alpha.
|
|
1297
|
+
* Transforms the PowerSync base URL which might contain
|
|
1298
|
+
* `http(s)://` to the corresponding WebSocket variant
|
|
1299
|
+
* e.g. `ws(s)://`
|
|
1312
1300
|
*/
|
|
1313
|
-
|
|
1301
|
+
socketUrlTransformer: (url: string) => string;
|
|
1314
1302
|
/**
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
*
|
|
1303
|
+
* Optionally provide the fetch implementation to use.
|
|
1304
|
+
* Note that this usually needs to be bound to the global scope.
|
|
1305
|
+
* Binding should be done before passing here.
|
|
1318
1306
|
*/
|
|
1319
|
-
|
|
1307
|
+
fetchImplementation: FetchImplementation | FetchImplementationProvider;
|
|
1320
1308
|
/**
|
|
1321
|
-
*
|
|
1309
|
+
* Optional options to pass directly to all `fetch` calls.
|
|
1322
1310
|
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1311
|
+
* This can include fields such as `dispatcher` (e.g. for proxy support),
|
|
1312
|
+
* `cache`, or any other fetch-compatible options.
|
|
1325
1313
|
*/
|
|
1326
|
-
|
|
1314
|
+
fetchOptions?: {};
|
|
1315
|
+
};
|
|
1316
|
+
declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
|
|
1317
|
+
declare abstract class AbstractRemote {
|
|
1318
|
+
protected connector: RemoteConnector;
|
|
1319
|
+
protected logger: ILogger;
|
|
1320
|
+
protected credentials: PowerSyncCredentials | null;
|
|
1321
|
+
protected options: AbstractRemoteOptions;
|
|
1322
|
+
constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
|
|
1327
1323
|
/**
|
|
1328
|
-
*
|
|
1329
|
-
*
|
|
1330
|
-
*
|
|
1331
|
-
* This field is only set when {@link SyncDataFlowStatus#downloading} is also true.
|
|
1324
|
+
* @returns a fetch implementation (function)
|
|
1325
|
+
* which can be called to perform fetch requests
|
|
1332
1326
|
*/
|
|
1333
|
-
get
|
|
1327
|
+
get fetch(): FetchImplementation;
|
|
1334
1328
|
/**
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
* When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
|
|
1339
|
-
* buckets first. When a consistent view over all buckets for all priorities up until the given priority is
|
|
1340
|
-
* reached, PowerSync makes data from those buckets available before lower-priority buckets have finished
|
|
1341
|
-
* syncing.
|
|
1342
|
-
*
|
|
1343
|
-
* This method returns the status for the requested priority or the next higher priority level that has
|
|
1344
|
-
* status information available. This is because when PowerSync makes data for a given priority available,
|
|
1345
|
-
* all buckets in higher-priorities are guaranteed to be consistent with that checkpoint.
|
|
1346
|
-
*
|
|
1347
|
-
* For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
|
|
1348
|
-
* with a priority of 1 may return information for priority level 3.
|
|
1329
|
+
* Get credentials currently cached, or fetch new credentials if none are
|
|
1330
|
+
* available.
|
|
1349
1331
|
*
|
|
1350
|
-
*
|
|
1351
|
-
* @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
|
|
1332
|
+
* These credentials may have expired already.
|
|
1352
1333
|
*/
|
|
1353
|
-
|
|
1334
|
+
getCredentials(): Promise<PowerSyncCredentials | null>;
|
|
1354
1335
|
/**
|
|
1355
|
-
*
|
|
1356
|
-
* Equality is determined by comparing the serialized JSON representation of both instances.
|
|
1336
|
+
* Fetch a new set of credentials and cache it.
|
|
1357
1337
|
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*/
|
|
1361
|
-
isEqual(status: SyncStatus): boolean;
|
|
1362
|
-
/**
|
|
1363
|
-
* Creates a human-readable string representation of the current sync status.
|
|
1364
|
-
* Includes information about connection state, sync completion, and data flow.
|
|
1338
|
+
* Until this call succeeds, `getCredentials` will still return the
|
|
1339
|
+
* old credentials.
|
|
1365
1340
|
*
|
|
1366
|
-
*
|
|
1341
|
+
* This may be called before the current credentials have expired.
|
|
1367
1342
|
*/
|
|
1368
|
-
|
|
1343
|
+
prefetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
1369
1344
|
/**
|
|
1370
|
-
*
|
|
1345
|
+
* Get credentials for PowerSync.
|
|
1371
1346
|
*
|
|
1372
|
-
*
|
|
1347
|
+
* This should always fetch a fresh set of credentials - don't use cached
|
|
1348
|
+
* values.
|
|
1373
1349
|
*/
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
*/
|
|
1380
|
-
interface SyncStreamStatus {
|
|
1381
|
-
progress: ProgressWithOperations | null;
|
|
1382
|
-
subscription: SyncSubscriptionDescription;
|
|
1383
|
-
priority: number | null;
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
declare class UploadQueueStats {
|
|
1387
|
-
/**
|
|
1388
|
-
* Number of records in the upload queue.
|
|
1350
|
+
fetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
1351
|
+
/***
|
|
1352
|
+
* Immediately invalidate credentials.
|
|
1353
|
+
*
|
|
1354
|
+
* This may be called when the current credentials have expired.
|
|
1389
1355
|
*/
|
|
1390
|
-
|
|
1356
|
+
invalidateCredentials(): void;
|
|
1357
|
+
getUserAgent(): string;
|
|
1358
|
+
protected buildRequest(path: string): Promise<{
|
|
1359
|
+
url: string;
|
|
1360
|
+
headers: {
|
|
1361
|
+
'content-type': string;
|
|
1362
|
+
Authorization: string;
|
|
1363
|
+
'x-user-agent': string;
|
|
1364
|
+
};
|
|
1365
|
+
}>;
|
|
1366
|
+
post(path: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
1367
|
+
get(path: string, headers?: Record<string, string>): Promise<any>;
|
|
1391
1368
|
/**
|
|
1392
|
-
*
|
|
1369
|
+
* Provides a BSON implementation. The import nature of this varies depending on the platform
|
|
1393
1370
|
*/
|
|
1394
|
-
|
|
1395
|
-
|
|
1371
|
+
abstract getBSON(): Promise<BSONImplementation>;
|
|
1372
|
+
protected createSocket(url: string): WebSocket;
|
|
1396
1373
|
/**
|
|
1397
|
-
*
|
|
1374
|
+
* Returns a data stream of sync line data.
|
|
1375
|
+
*
|
|
1376
|
+
* @param map Maps received payload frames to the typed event value.
|
|
1377
|
+
* @param bson A BSON encoder and decoder. When set, the data stream will be requested with a BSON payload
|
|
1378
|
+
* (required for compatibility with older sync services).
|
|
1398
1379
|
*/
|
|
1399
|
-
|
|
1380
|
+
socketStreamRaw<T>(options: SocketSyncStreamOptions, map: (buffer: Uint8Array) => T, bson?: typeof BSON): Promise<DataStream<T>>;
|
|
1400
1381
|
/**
|
|
1401
|
-
*
|
|
1382
|
+
* Connects to the sync/stream http endpoint, mapping and emitting each received string line.
|
|
1402
1383
|
*/
|
|
1403
|
-
|
|
1404
|
-
toString(): string;
|
|
1384
|
+
postStreamRaw<T>(options: SyncStreamOptions, mapLine: (line: string) => T): Promise<DataStream<T>>;
|
|
1405
1385
|
}
|
|
1406
1386
|
|
|
1407
|
-
declare enum
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
REAL = "REAL"
|
|
1411
|
-
}
|
|
1412
|
-
interface ColumnOptions {
|
|
1413
|
-
name: string;
|
|
1414
|
-
type?: ColumnType;
|
|
1387
|
+
declare enum LockType {
|
|
1388
|
+
CRUD = "crud",
|
|
1389
|
+
SYNC = "sync"
|
|
1415
1390
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
type ColumnsType = Record<string, BaseColumnType<any>>;
|
|
1420
|
-
type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
|
|
1421
|
-
declare const MAX_AMOUNT_OF_COLUMNS = 1999;
|
|
1422
|
-
declare const column: {
|
|
1423
|
-
text: BaseColumnType<string | null>;
|
|
1424
|
-
integer: BaseColumnType<number | null>;
|
|
1425
|
-
real: BaseColumnType<number | null>;
|
|
1426
|
-
};
|
|
1427
|
-
declare class Column {
|
|
1428
|
-
protected options: ColumnOptions;
|
|
1429
|
-
constructor(options: ColumnOptions);
|
|
1430
|
-
get name(): string;
|
|
1431
|
-
get type(): ColumnType | undefined;
|
|
1432
|
-
toJSON(): {
|
|
1433
|
-
name: string;
|
|
1434
|
-
type: ColumnType | undefined;
|
|
1435
|
-
};
|
|
1391
|
+
declare enum SyncStreamConnectionMethod {
|
|
1392
|
+
HTTP = "http",
|
|
1393
|
+
WEB_SOCKET = "web-socket"
|
|
1436
1394
|
}
|
|
1437
|
-
|
|
1438
|
-
/**
|
|
1439
|
-
* A pending variant of a {@link RawTable} that doesn't have a name (because it would be inferred when creating the
|
|
1440
|
-
* schema).
|
|
1441
|
-
*/
|
|
1442
|
-
type RawTableType = {
|
|
1443
|
-
/**
|
|
1444
|
-
* The statement to run when PowerSync detects that a row needs to be inserted or updated.
|
|
1445
|
-
*/
|
|
1446
|
-
put: PendingStatement;
|
|
1395
|
+
declare enum SyncClientImplementation {
|
|
1447
1396
|
/**
|
|
1448
|
-
*
|
|
1397
|
+
* Decodes and handles sync lines received from the sync service in JavaScript.
|
|
1398
|
+
*
|
|
1399
|
+
* This is the default option.
|
|
1400
|
+
*
|
|
1401
|
+
* @deprecated Don't use {@link SyncClientImplementation.JAVASCRIPT} directly. Instead, use
|
|
1402
|
+
* {@link DEFAULT_SYNC_CLIENT_IMPLEMENTATION} or omit the option. The explicit choice to use
|
|
1403
|
+
* the JavaScript-based sync implementation will be removed from a future version of the SDK.
|
|
1449
1404
|
*/
|
|
1450
|
-
|
|
1451
|
-
};
|
|
1452
|
-
/**
|
|
1453
|
-
* A parameter to use as part of {@link PendingStatement}.
|
|
1454
|
-
*
|
|
1455
|
-
* For delete statements, only the `"Id"` value is supported - the sync client will replace it with the id of the row to
|
|
1456
|
-
* be synced.
|
|
1457
|
-
*
|
|
1458
|
-
* For insert and replace operations, the values of columns in the table are available as parameters through
|
|
1459
|
-
* `{Column: 'name'}`.
|
|
1460
|
-
*/
|
|
1461
|
-
type PendingStatementParameter = 'Id' | {
|
|
1462
|
-
Column: string;
|
|
1463
|
-
};
|
|
1464
|
-
/**
|
|
1465
|
-
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
1466
|
-
*/
|
|
1467
|
-
type PendingStatement = {
|
|
1468
|
-
sql: string;
|
|
1469
|
-
params: PendingStatementParameter[];
|
|
1470
|
-
};
|
|
1471
|
-
/**
|
|
1472
|
-
* Instructs PowerSync to sync data into a "raw" table.
|
|
1473
|
-
*
|
|
1474
|
-
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1475
|
-
* using client-side table and column constraints.
|
|
1476
|
-
*
|
|
1477
|
-
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
1478
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
1479
|
-
* using raw tables.
|
|
1480
|
-
*
|
|
1481
|
-
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1482
|
-
*
|
|
1483
|
-
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
1484
|
-
* stability guarantees.
|
|
1485
|
-
*/
|
|
1486
|
-
declare class RawTable implements RawTableType {
|
|
1405
|
+
JAVASCRIPT = "js",
|
|
1487
1406
|
/**
|
|
1488
|
-
*
|
|
1407
|
+
* This implementation offloads the sync line decoding and handling into the PowerSync
|
|
1408
|
+
* core extension.
|
|
1489
1409
|
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1410
|
+
* @experimental
|
|
1411
|
+
* While this implementation is more performant than {@link SyncClientImplementation.JAVASCRIPT},
|
|
1412
|
+
* it has seen less real-world testing and is marked as __experimental__ at the moment.
|
|
1413
|
+
*
|
|
1414
|
+
* ## Compatibility warning
|
|
1415
|
+
*
|
|
1416
|
+
* The Rust sync client stores sync data in a format that is slightly different than the one used
|
|
1417
|
+
* by the old {@link JAVASCRIPT} implementation. When adopting the {@link RUST} client on existing
|
|
1418
|
+
* databases, the PowerSync SDK will migrate the format automatically.
|
|
1419
|
+
* Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
|
|
1420
|
+
* the version introducing {@link RUST} as an option) also supports the new format, so you can switch
|
|
1421
|
+
* back to {@link JAVASCRIPT} later.
|
|
1422
|
+
*
|
|
1423
|
+
* __However__: Upgrading the SDK version, then adopting {@link RUST} as a sync client and later
|
|
1424
|
+
* downgrading the SDK to an older version (necessarily using the JavaScript-based implementation then)
|
|
1425
|
+
* can lead to sync issues.
|
|
1493
1426
|
*/
|
|
1494
|
-
|
|
1495
|
-
put: PendingStatement;
|
|
1496
|
-
delete: PendingStatement;
|
|
1497
|
-
constructor(name: string, type: RawTableType);
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
interface IndexColumnOptions {
|
|
1501
|
-
name: string;
|
|
1502
|
-
ascending?: boolean;
|
|
1503
|
-
}
|
|
1504
|
-
declare const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions>;
|
|
1505
|
-
declare class IndexedColumn {
|
|
1506
|
-
protected options: IndexColumnOptions;
|
|
1507
|
-
static createAscending(column: string): IndexedColumn;
|
|
1508
|
-
constructor(options: IndexColumnOptions);
|
|
1509
|
-
get name(): string;
|
|
1510
|
-
get ascending(): boolean | undefined;
|
|
1511
|
-
toJSON(table: Table): {
|
|
1512
|
-
name: string;
|
|
1513
|
-
ascending: boolean | undefined;
|
|
1514
|
-
type: ColumnType;
|
|
1515
|
-
};
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
interface IndexOptions {
|
|
1519
|
-
name: string;
|
|
1520
|
-
columns?: IndexedColumn[];
|
|
1521
|
-
}
|
|
1522
|
-
declare const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions>;
|
|
1523
|
-
declare class Index {
|
|
1524
|
-
protected options: IndexOptions;
|
|
1525
|
-
static createAscending(options: IndexOptions, columnNames: string[]): Index;
|
|
1526
|
-
constructor(options: IndexOptions);
|
|
1527
|
-
get name(): string;
|
|
1528
|
-
get columns(): IndexedColumn[];
|
|
1529
|
-
toJSON(table: Table): {
|
|
1530
|
-
name: string;
|
|
1531
|
-
columns: {
|
|
1532
|
-
name: string;
|
|
1533
|
-
ascending: boolean | undefined;
|
|
1534
|
-
type: ColumnType;
|
|
1535
|
-
}[];
|
|
1536
|
-
};
|
|
1427
|
+
RUST = "rust"
|
|
1537
1428
|
}
|
|
1538
|
-
|
|
1539
1429
|
/**
|
|
1540
|
-
|
|
1541
|
-
@deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
|
|
1542
|
-
This will be removed in the next major release.
|
|
1543
|
-
*/
|
|
1544
|
-
declare class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
interface SharedTableOptions {
|
|
1548
|
-
localOnly?: boolean;
|
|
1549
|
-
insertOnly?: boolean;
|
|
1550
|
-
viewName?: string;
|
|
1551
|
-
trackPrevious?: boolean | TrackPreviousOptions;
|
|
1552
|
-
trackMetadata?: boolean;
|
|
1553
|
-
ignoreEmptyUpdates?: boolean;
|
|
1554
|
-
}
|
|
1555
|
-
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
1430
|
+
* The default {@link SyncClientImplementation} to use.
|
|
1556
1431
|
*
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1432
|
+
* Please use this field instead of {@link SyncClientImplementation.JAVASCRIPT} directly. A future version
|
|
1433
|
+
* of the PowerSync SDK will enable {@link SyncClientImplementation.RUST} by default and remove the JavaScript
|
|
1434
|
+
* option.
|
|
1559
1435
|
*/
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1436
|
+
declare const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.JAVASCRIPT;
|
|
1437
|
+
/**
|
|
1438
|
+
* Abstract Lock to be implemented by various JS environments
|
|
1439
|
+
*/
|
|
1440
|
+
interface LockOptions<T> {
|
|
1441
|
+
callback: () => Promise<T>;
|
|
1442
|
+
type: LockType;
|
|
1443
|
+
signal?: AbortSignal;
|
|
1565
1444
|
}
|
|
1566
|
-
interface
|
|
1445
|
+
interface AbstractStreamingSyncImplementationOptions extends AdditionalConnectionOptions {
|
|
1446
|
+
adapter: BucketStorageAdapter;
|
|
1447
|
+
uploadCrud: () => Promise<void>;
|
|
1567
1448
|
/**
|
|
1568
|
-
*
|
|
1449
|
+
* An identifier for which PowerSync DB this sync implementation is
|
|
1450
|
+
* linked to. Most commonly DB name, but not restricted to DB name.
|
|
1569
1451
|
*/
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
}
|
|
1574
|
-
type RowType<T extends TableV2<any>> = {
|
|
1575
|
-
[K in keyof T['columnMap']]: ExtractColumnValueType<T['columnMap'][K]>;
|
|
1576
|
-
} & {
|
|
1577
|
-
id: string;
|
|
1578
|
-
};
|
|
1579
|
-
type IndexShorthand = Record<string, string[]>;
|
|
1580
|
-
interface TableV2Options extends SharedTableOptions {
|
|
1581
|
-
indexes?: IndexShorthand;
|
|
1452
|
+
identifier?: string;
|
|
1453
|
+
logger?: ILogger;
|
|
1454
|
+
remote: AbstractRemote;
|
|
1582
1455
|
}
|
|
1583
|
-
|
|
1584
|
-
indexes: never[];
|
|
1585
|
-
insertOnly: boolean;
|
|
1586
|
-
localOnly: boolean;
|
|
1587
|
-
trackPrevious: boolean;
|
|
1588
|
-
trackMetadata: boolean;
|
|
1589
|
-
ignoreEmptyUpdates: boolean;
|
|
1590
|
-
};
|
|
1591
|
-
declare const InvalidSQLCharacters: RegExp;
|
|
1592
|
-
declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
1593
|
-
protected options: TableOptions;
|
|
1594
|
-
protected _mappedColumns: Columns;
|
|
1595
|
-
static createLocalOnly(options: TableOptions): Table<ColumnsType>;
|
|
1596
|
-
static createInsertOnly(options: TableOptions): Table<ColumnsType>;
|
|
1597
|
-
/**
|
|
1598
|
-
* Create a table.
|
|
1599
|
-
* @deprecated This was only only included for TableV2 and is no longer necessary.
|
|
1600
|
-
* Prefer to use new Table() directly.
|
|
1601
|
-
*
|
|
1602
|
-
* TODO remove in the next major release.
|
|
1603
|
-
*/
|
|
1604
|
-
static createTable(name: string, table: Table): Table<ColumnsType>;
|
|
1456
|
+
interface StreamingSyncImplementationListener extends BaseListener {
|
|
1605
1457
|
/**
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
* This constructor supports two different versions:
|
|
1609
|
-
* 1. New constructor: Using a Columns object and an optional TableV2Options object
|
|
1610
|
-
* 2. Deprecated constructor: Using a TableOptions object (will be removed in the next major release)
|
|
1611
|
-
*
|
|
1612
|
-
* @constructor
|
|
1613
|
-
* @param {Columns | TableOptions} optionsOrColumns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax)
|
|
1614
|
-
* @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax
|
|
1615
|
-
*
|
|
1616
|
-
* @example
|
|
1617
|
-
* ```javascript
|
|
1618
|
-
* // New Constructor
|
|
1619
|
-
* const table = new Table(
|
|
1620
|
-
* {
|
|
1621
|
-
* name: column.text,
|
|
1622
|
-
* age: column.integer
|
|
1623
|
-
* },
|
|
1624
|
-
* { indexes: { nameIndex: ['name'] } }
|
|
1625
|
-
* );
|
|
1626
|
-
*```
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
* @example
|
|
1630
|
-
* ```javascript
|
|
1631
|
-
* // Deprecated Constructor
|
|
1632
|
-
* const table = new Table({
|
|
1633
|
-
* name: 'users',
|
|
1634
|
-
* columns: [
|
|
1635
|
-
* new Column({ name: 'name', type: ColumnType.TEXT }),
|
|
1636
|
-
* new Column({ name: 'age', type: ColumnType.INTEGER })
|
|
1637
|
-
* ]
|
|
1638
|
-
* });
|
|
1639
|
-
*```
|
|
1458
|
+
* Triggered whenever a status update has been attempted to be made or
|
|
1459
|
+
* refreshed.
|
|
1640
1460
|
*/
|
|
1641
|
-
|
|
1461
|
+
statusUpdated?: ((statusUpdate: SyncStatusOptions) => void) | undefined;
|
|
1642
1462
|
/**
|
|
1643
|
-
*
|
|
1644
|
-
* Use the new constructor shown below instead as this does not show types.
|
|
1645
|
-
* @example
|
|
1646
|
-
* <caption>Use this instead</caption>
|
|
1647
|
-
* ```javascript
|
|
1648
|
-
* const table = new Table(
|
|
1649
|
-
* {
|
|
1650
|
-
* name: column.text,
|
|
1651
|
-
* age: column.integer
|
|
1652
|
-
* },
|
|
1653
|
-
* { indexes: { nameIndex: ['name'] } }
|
|
1654
|
-
* );
|
|
1655
|
-
*```
|
|
1463
|
+
* Triggers whenever the status' members have changed in value
|
|
1656
1464
|
*/
|
|
1657
|
-
|
|
1658
|
-
copyWithName(name: string): Table;
|
|
1659
|
-
private isTableV1;
|
|
1660
|
-
private initTableV1;
|
|
1661
|
-
private initTableV2;
|
|
1662
|
-
private applyDefaultOptions;
|
|
1663
|
-
get name(): string;
|
|
1664
|
-
get viewNameOverride(): string | undefined;
|
|
1665
|
-
get viewName(): string;
|
|
1666
|
-
get columns(): Column[];
|
|
1667
|
-
get columnMap(): Columns;
|
|
1668
|
-
get indexes(): Index[];
|
|
1669
|
-
get localOnly(): boolean;
|
|
1670
|
-
get insertOnly(): boolean;
|
|
1671
|
-
get trackPrevious(): boolean | TrackPreviousOptions;
|
|
1672
|
-
get trackMetadata(): boolean;
|
|
1673
|
-
get ignoreEmptyUpdates(): boolean;
|
|
1674
|
-
get internalName(): string;
|
|
1675
|
-
get validName(): boolean;
|
|
1676
|
-
validate(): void;
|
|
1677
|
-
toJSON(): {
|
|
1678
|
-
name: string;
|
|
1679
|
-
view_name: string;
|
|
1680
|
-
local_only: boolean;
|
|
1681
|
-
insert_only: boolean;
|
|
1682
|
-
include_old: any;
|
|
1683
|
-
include_old_only_when_changed: boolean;
|
|
1684
|
-
include_metadata: boolean;
|
|
1685
|
-
ignore_empty_update: boolean;
|
|
1686
|
-
columns: {
|
|
1687
|
-
name: string;
|
|
1688
|
-
type: ColumnType | undefined;
|
|
1689
|
-
}[];
|
|
1690
|
-
indexes: {
|
|
1691
|
-
name: string;
|
|
1692
|
-
columns: {
|
|
1693
|
-
name: string;
|
|
1694
|
-
ascending: boolean | undefined;
|
|
1695
|
-
type: ColumnType;
|
|
1696
|
-
}[];
|
|
1697
|
-
}[];
|
|
1698
|
-
};
|
|
1465
|
+
statusChanged?: ((status: SyncStatus) => void) | undefined;
|
|
1699
1466
|
}
|
|
1700
|
-
|
|
1701
|
-
type SchemaType = Record<string, Table<any>>;
|
|
1702
|
-
type SchemaTableType<S extends SchemaType> = {
|
|
1703
|
-
[K in keyof S]: RowType<S[K]>;
|
|
1704
|
-
};
|
|
1705
1467
|
/**
|
|
1706
|
-
*
|
|
1468
|
+
* Configurable options to be used when connecting to the PowerSync
|
|
1469
|
+
* backend instance.
|
|
1707
1470
|
*/
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
constructor(tables: Table[] | S);
|
|
1471
|
+
type PowerSyncConnectionOptions = Omit<InternalConnectionOptions, 'serializedSchema'>;
|
|
1472
|
+
interface InternalConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {
|
|
1473
|
+
}
|
|
1474
|
+
/** @internal */
|
|
1475
|
+
interface BaseConnectionOptions {
|
|
1714
1476
|
/**
|
|
1715
|
-
*
|
|
1716
|
-
*
|
|
1717
|
-
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1718
|
-
* using client-side table and column constraints.
|
|
1719
|
-
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1477
|
+
* Whether to use a JavaScript implementation to handle received sync lines from the sync
|
|
1478
|
+
* service, or whether this work should be offloaded to the PowerSync core extension.
|
|
1720
1479
|
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1480
|
+
* This defaults to the JavaScript implementation ({@link SyncClientImplementation.JAVASCRIPT})
|
|
1481
|
+
* since the ({@link SyncClientImplementation.RUST}) implementation is experimental at the moment.
|
|
1723
1482
|
*/
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
name: string;
|
|
1744
|
-
ascending: boolean | undefined;
|
|
1745
|
-
type: ColumnType;
|
|
1746
|
-
}[];
|
|
1747
|
-
}[];
|
|
1748
|
-
}[];
|
|
1749
|
-
raw_tables: RawTable[];
|
|
1750
|
-
};
|
|
1751
|
-
private convertToClassicTables;
|
|
1483
|
+
clientImplementation?: SyncClientImplementation;
|
|
1484
|
+
/**
|
|
1485
|
+
* The connection method to use when streaming updates from
|
|
1486
|
+
* the PowerSync backend instance.
|
|
1487
|
+
* Defaults to a HTTP streaming connection.
|
|
1488
|
+
*/
|
|
1489
|
+
connectionMethod?: SyncStreamConnectionMethod;
|
|
1490
|
+
/**
|
|
1491
|
+
* The fetch strategy to use when streaming updates from the PowerSync backend instance.
|
|
1492
|
+
*/
|
|
1493
|
+
fetchStrategy?: FetchStrategy;
|
|
1494
|
+
/**
|
|
1495
|
+
* These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
|
|
1496
|
+
*/
|
|
1497
|
+
params?: Record<string, StreamingSyncRequestParameterType>;
|
|
1498
|
+
/**
|
|
1499
|
+
* The serialized schema - mainly used to forward information about raw tables to the sync client.
|
|
1500
|
+
*/
|
|
1501
|
+
serializedSchema?: any;
|
|
1752
1502
|
}
|
|
1753
|
-
|
|
1754
|
-
interface
|
|
1755
|
-
/**
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
* This should always fetch a fresh set of credentials - don't use cached
|
|
1759
|
-
* values.
|
|
1760
|
-
*
|
|
1761
|
-
* Return null if the user is not signed in. Throw an error if credentials
|
|
1762
|
-
* cannot be fetched due to a network error or other temporary error.
|
|
1763
|
-
*
|
|
1764
|
-
* This token is kept for the duration of a sync connection.
|
|
1503
|
+
/** @internal */
|
|
1504
|
+
interface AdditionalConnectionOptions {
|
|
1505
|
+
/**
|
|
1506
|
+
* Delay for retrying sync streaming operations
|
|
1507
|
+
* from the PowerSync backend after an error occurs.
|
|
1765
1508
|
*/
|
|
1766
|
-
|
|
1767
|
-
/**
|
|
1509
|
+
retryDelayMs?: number;
|
|
1510
|
+
/**
|
|
1511
|
+
* Backend Connector CRUD operations are throttled
|
|
1512
|
+
* to occur at most every `crudUploadThrottleMs`
|
|
1513
|
+
* milliseconds.
|
|
1514
|
+
*/
|
|
1515
|
+
crudUploadThrottleMs?: number;
|
|
1516
|
+
}
|
|
1517
|
+
/** @internal */
|
|
1518
|
+
type RequiredAdditionalConnectionOptions = Required<AdditionalConnectionOptions>;
|
|
1519
|
+
interface StreamingSyncImplementation extends BaseObserverInterface<StreamingSyncImplementationListener>, Disposable {
|
|
1520
|
+
/**
|
|
1521
|
+
* Connects to the sync service
|
|
1522
|
+
*/
|
|
1523
|
+
connect(options?: InternalConnectionOptions): Promise<void>;
|
|
1524
|
+
/**
|
|
1525
|
+
* Disconnects from the sync services.
|
|
1526
|
+
* @throws if not connected or if abort is not controlled internally
|
|
1527
|
+
*/
|
|
1528
|
+
disconnect(): Promise<void>;
|
|
1529
|
+
getWriteCheckpoint: () => Promise<string>;
|
|
1530
|
+
hasCompletedSync: () => Promise<boolean>;
|
|
1531
|
+
isConnected: boolean;
|
|
1532
|
+
lastSyncedAt?: Date;
|
|
1533
|
+
syncStatus: SyncStatus;
|
|
1534
|
+
triggerCrudUpload: () => void;
|
|
1535
|
+
waitForReady(): Promise<void>;
|
|
1536
|
+
waitForStatus(status: SyncStatusOptions): Promise<void>;
|
|
1537
|
+
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
1538
|
+
}
|
|
1539
|
+
declare const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
|
|
1540
|
+
declare const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
1541
|
+
declare const DEFAULT_STREAMING_SYNC_OPTIONS: {
|
|
1542
|
+
retryDelayMs: number;
|
|
1543
|
+
crudUploadThrottleMs: number;
|
|
1544
|
+
};
|
|
1545
|
+
type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
|
|
1546
|
+
declare const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions;
|
|
1547
|
+
declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
|
|
1548
|
+
protected _lastSyncedAt: Date | null;
|
|
1549
|
+
protected options: AbstractStreamingSyncImplementationOptions;
|
|
1550
|
+
protected abortController: AbortController | null;
|
|
1551
|
+
protected uploadAbortController: AbortController | null;
|
|
1552
|
+
protected crudUpdateListener?: () => void;
|
|
1553
|
+
protected streamingSyncPromise?: Promise<void>;
|
|
1554
|
+
protected logger: ILogger;
|
|
1555
|
+
private isUploadingCrud;
|
|
1556
|
+
private notifyCompletedUploads?;
|
|
1557
|
+
syncStatus: SyncStatus;
|
|
1558
|
+
triggerCrudUpload: () => void;
|
|
1559
|
+
constructor(options: AbstractStreamingSyncImplementationOptions);
|
|
1560
|
+
waitForReady(): Promise<void>;
|
|
1561
|
+
waitForStatus(status: SyncStatusOptions): Promise<void>;
|
|
1562
|
+
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
1563
|
+
get lastSyncedAt(): Date | undefined;
|
|
1564
|
+
get isConnected(): boolean;
|
|
1565
|
+
dispose(): Promise<void>;
|
|
1566
|
+
abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
|
|
1567
|
+
hasCompletedSync(): Promise<boolean>;
|
|
1568
|
+
getWriteCheckpoint(): Promise<string>;
|
|
1569
|
+
protected _uploadAllCrud(): Promise<void>;
|
|
1570
|
+
connect(options?: PowerSyncConnectionOptions): Promise<void>;
|
|
1571
|
+
disconnect(): Promise<void>;
|
|
1572
|
+
/**
|
|
1573
|
+
* @deprecated use [connect instead]
|
|
1574
|
+
*/
|
|
1575
|
+
streamingSync(signal?: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
|
|
1576
|
+
private collectLocalBucketState;
|
|
1577
|
+
/**
|
|
1578
|
+
* Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
|
|
1579
|
+
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
1580
|
+
* While this is not a problem as long as it's done consistently, it causes issues when a database
|
|
1581
|
+
* created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
|
|
1582
|
+
* is enabled.
|
|
1768
1583
|
*
|
|
1769
|
-
*
|
|
1584
|
+
* So, we add a migration from the old key format (with quotes) to the new one (no quotes). The
|
|
1585
|
+
* migration is only triggered when necessary (for now). The function returns whether the new format
|
|
1586
|
+
* should be used, so that the JS SDK is able to write to updated databases.
|
|
1770
1587
|
*
|
|
1771
|
-
*
|
|
1588
|
+
* @param requireFixedKeyFormat Whether we require the new format or also support the old one.
|
|
1589
|
+
* The Rust client requires the new subkey format.
|
|
1590
|
+
* @returns Whether the database is now using the new, fixed subkey format.
|
|
1772
1591
|
*/
|
|
1773
|
-
|
|
1592
|
+
private requireKeyFormat;
|
|
1593
|
+
protected streamingSyncIteration(signal: AbortSignal, options?: PowerSyncConnectionOptions): Promise<void>;
|
|
1594
|
+
private legacyStreamingSyncIteration;
|
|
1595
|
+
private rustSyncIteration;
|
|
1596
|
+
private updateSyncStatusForStartingCheckpoint;
|
|
1597
|
+
private applyCheckpoint;
|
|
1598
|
+
protected updateSyncStatus(options: SyncStatusOptions): void;
|
|
1599
|
+
private delayRetry;
|
|
1774
1600
|
}
|
|
1775
1601
|
|
|
1776
1602
|
/**
|
|
@@ -1784,24 +1610,11 @@ interface ConnectionManagerSyncImplementationResult {
|
|
|
1784
1610
|
*/
|
|
1785
1611
|
onDispose: () => Promise<void> | void;
|
|
1786
1612
|
}
|
|
1787
|
-
/**
|
|
1788
|
-
* The subset of {@link AbstractStreamingSyncImplementationOptions} managed by the connection manager.
|
|
1789
|
-
*
|
|
1790
|
-
* @internal
|
|
1791
|
-
*/
|
|
1792
|
-
interface CreateSyncImplementationOptions extends AdditionalConnectionOptions {
|
|
1793
|
-
subscriptions: SubscribedStream[];
|
|
1794
|
-
}
|
|
1795
|
-
interface InternalSubscriptionAdapter {
|
|
1796
|
-
firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
|
|
1797
|
-
resolveOfflineSyncStatus(): Promise<void>;
|
|
1798
|
-
rustSubscriptionsCommand(payload: any): Promise<void>;
|
|
1799
|
-
}
|
|
1800
1613
|
/**
|
|
1801
1614
|
* @internal
|
|
1802
1615
|
*/
|
|
1803
1616
|
interface ConnectionManagerOptions {
|
|
1804
|
-
createSyncImplementation(connector: PowerSyncBackendConnector, options:
|
|
1617
|
+
createSyncImplementation(connector: PowerSyncBackendConnector, options: InternalConnectionOptions): Promise<ConnectionManagerSyncImplementationResult>;
|
|
1805
1618
|
logger: ILogger;
|
|
1806
1619
|
}
|
|
1807
1620
|
type StoredConnectionOptions = {
|
|
@@ -1847,12 +1660,6 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
|
|
|
1847
1660
|
* is disposed.
|
|
1848
1661
|
*/
|
|
1849
1662
|
protected syncDisposer: (() => Promise<void> | void) | null;
|
|
1850
|
-
/**
|
|
1851
|
-
* Subscriptions managed in this connection manager.
|
|
1852
|
-
*
|
|
1853
|
-
* On the web, these local subscriptions are merged across tabs by a shared worker.
|
|
1854
|
-
*/
|
|
1855
|
-
private locallyActiveSubscriptions;
|
|
1856
1663
|
constructor(options: ConnectionManagerOptions);
|
|
1857
1664
|
get logger(): ILogger;
|
|
1858
1665
|
close(): Promise<void>;
|
|
@@ -1866,9 +1673,6 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
|
|
|
1866
1673
|
disconnect(): Promise<void>;
|
|
1867
1674
|
protected disconnectInternal(): Promise<void>;
|
|
1868
1675
|
protected performDisconnect(): Promise<void>;
|
|
1869
|
-
stream(adapter: InternalSubscriptionAdapter, name: string, parameters: Record<string, any> | null): SyncStream;
|
|
1870
|
-
private get activeStreams();
|
|
1871
|
-
private subscriptionsMayHaveChanged;
|
|
1872
1676
|
}
|
|
1873
1677
|
|
|
1874
1678
|
/**
|
|
@@ -2003,14 +1807,12 @@ declare enum WatchedQueryListenerEvent {
|
|
|
2003
1807
|
ON_DATA = "onData",
|
|
2004
1808
|
ON_ERROR = "onError",
|
|
2005
1809
|
ON_STATE_CHANGE = "onStateChange",
|
|
2006
|
-
SETTINGS_WILL_UPDATE = "settingsWillUpdate",
|
|
2007
1810
|
CLOSED = "closed"
|
|
2008
1811
|
}
|
|
2009
1812
|
interface WatchedQueryListener<Data> extends BaseListener {
|
|
2010
1813
|
[WatchedQueryListenerEvent.ON_DATA]?: (data: Data) => void | Promise<void>;
|
|
2011
1814
|
[WatchedQueryListenerEvent.ON_ERROR]?: (error: Error) => void | Promise<void>;
|
|
2012
1815
|
[WatchedQueryListenerEvent.ON_STATE_CHANGE]?: (state: WatchedQueryState<Data>) => void | Promise<void>;
|
|
2013
|
-
[WatchedQueryListenerEvent.SETTINGS_WILL_UPDATE]?: () => void;
|
|
2014
1816
|
[WatchedQueryListenerEvent.CLOSED]?: () => void | Promise<void>;
|
|
2015
1817
|
}
|
|
2016
1818
|
declare const DEFAULT_WATCH_THROTTLE_MS = 30;
|
|
@@ -2076,7 +1878,6 @@ declare abstract class AbstractQueryProcessor<Data = unknown[], Settings extends
|
|
|
2076
1878
|
constructor(options: AbstractQueryProcessorOptions<Data, Settings>);
|
|
2077
1879
|
protected constructInitialState(): WatchedQueryState<Data>;
|
|
2078
1880
|
protected get reportFetching(): boolean;
|
|
2079
|
-
protected updateSettingsInternal(settings: Settings, signal: AbortSignal): Promise<void>;
|
|
2080
1881
|
/**
|
|
2081
1882
|
* Updates the underlying query.
|
|
2082
1883
|
*/
|
|
@@ -2090,7 +1891,7 @@ declare abstract class AbstractQueryProcessor<Data = unknown[], Settings extends
|
|
|
2090
1891
|
/**
|
|
2091
1892
|
* Configures base DB listeners and links the query to listeners.
|
|
2092
1893
|
*/
|
|
2093
|
-
protected init(
|
|
1894
|
+
protected init(): Promise<void>;
|
|
2094
1895
|
close(): Promise<void>;
|
|
2095
1896
|
/**
|
|
2096
1897
|
* Runs a callback and reports errors to the error listeners.
|
|
@@ -2368,6 +2169,7 @@ interface SQLOpenOptions {
|
|
|
2368
2169
|
* debugMode: process.env.NODE_ENV !== 'production'
|
|
2369
2170
|
*/
|
|
2370
2171
|
debugMode?: boolean;
|
|
2172
|
+
logger?: ILogger;
|
|
2371
2173
|
}
|
|
2372
2174
|
interface SQLOpenFactory {
|
|
2373
2175
|
/**
|
|
@@ -2740,7 +2542,7 @@ interface TriggerManager {
|
|
|
2740
2542
|
* },
|
|
2741
2543
|
* onChange: async (context) => {
|
|
2742
2544
|
* // Fetches the todo records that were inserted during this diff
|
|
2743
|
-
* const newTodos = await context.
|
|
2545
|
+
* const newTodos = await context.getAll<Database['todos']>(`
|
|
2744
2546
|
* SELECT
|
|
2745
2547
|
* todos.*
|
|
2746
2548
|
* FROM
|
|
@@ -2891,7 +2693,6 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2891
2693
|
protected bucketStorageAdapter: BucketStorageAdapter;
|
|
2892
2694
|
protected _isReadyPromise: Promise<void>;
|
|
2893
2695
|
protected connectionManager: ConnectionManager;
|
|
2894
|
-
private subscriptions;
|
|
2895
2696
|
get syncStreamImplementation(): StreamingSyncImplementation | null;
|
|
2896
2697
|
protected _schema: Schema;
|
|
2897
2698
|
private _database;
|
|
@@ -2927,7 +2728,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2927
2728
|
* Opens the DBAdapter given open options using a default open factory
|
|
2928
2729
|
*/
|
|
2929
2730
|
protected abstract openDBAdapter(options: PowerSyncDatabaseOptionsWithSettings): DBAdapter;
|
|
2930
|
-
protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options:
|
|
2731
|
+
protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: RequiredAdditionalConnectionOptions): StreamingSyncImplementation;
|
|
2931
2732
|
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
|
|
2932
2733
|
/**
|
|
2933
2734
|
* @returns A promise which will resolve once initialization is completed.
|
|
@@ -2946,7 +2747,6 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2946
2747
|
signal?: AbortSignal;
|
|
2947
2748
|
priority?: number;
|
|
2948
2749
|
}): Promise<void>;
|
|
2949
|
-
private waitForStatus;
|
|
2950
2750
|
/**
|
|
2951
2751
|
* Allows for extended implementations to execute custom initialization
|
|
2952
2752
|
* logic as part of the total init process
|
|
@@ -2958,7 +2758,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2958
2758
|
*/
|
|
2959
2759
|
protected initialize(): Promise<void>;
|
|
2960
2760
|
private _loadVersion;
|
|
2961
|
-
protected
|
|
2761
|
+
protected updateHasSynced(): Promise<void>;
|
|
2962
2762
|
/**
|
|
2963
2763
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
2964
2764
|
*
|
|
@@ -2970,7 +2770,7 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
2970
2770
|
* While initializing is automatic, this helps to catch and report initialization errors.
|
|
2971
2771
|
*/
|
|
2972
2772
|
init(): Promise<void>;
|
|
2973
|
-
|
|
2773
|
+
resolvedConnectionOptions(options?: PowerSyncConnectionOptions): RequiredAdditionalConnectionOptions;
|
|
2974
2774
|
/**
|
|
2975
2775
|
* @deprecated Use {@link AbstractPowerSyncDatabase#close} instead.
|
|
2976
2776
|
* Clears all listeners registered by {@link AbstractPowerSyncDatabase#registerListener}.
|
|
@@ -3000,15 +2800,6 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3000
2800
|
* To preserve data in local-only tables, set clearLocal to false.
|
|
3001
2801
|
*/
|
|
3002
2802
|
disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
|
|
3003
|
-
/**
|
|
3004
|
-
* Create a sync stream to query its status or to subscribe to it.
|
|
3005
|
-
*
|
|
3006
|
-
* @param name The name of the stream to subscribe to.
|
|
3007
|
-
* @param params Optional parameters for the stream subscription.
|
|
3008
|
-
* @returns A {@link SyncStream} instance that can be subscribed to.
|
|
3009
|
-
* @experimental Sync streams are currently in alpha.
|
|
3010
|
-
*/
|
|
3011
|
-
syncStream(name: string, params?: Record<string, any>): SyncStream;
|
|
3012
2803
|
/**
|
|
3013
2804
|
* Close the database, releasing resources.
|
|
3014
2805
|
*
|
|
@@ -3575,4 +3366,4 @@ interface ParsedQuery {
|
|
|
3575
3366
|
declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
|
|
3576
3367
|
|
|
3577
3368
|
export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, 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_PRESSURE_LIMITS, 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, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, Table, TableV2, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
|
|
3578
|
-
export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, 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, ContinueCheckpointRequest, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions,
|
|
3369
|
+
export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, 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, ContinueCheckpointRequest, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions, CrudRequest, CrudResponse, CrudUploadNotification, DBAdapter, DBAdapterListener, DBGetUtils, DBLockOptions, DataStreamCallback, DataStreamListener, DataStreamOptions, DifferentialQueryProcessorOptions, DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQueryListener, DifferentialWatchedQueryOptions, DifferentialWatchedQuerySettings, DisconnectAndClearOptions, Disposable, ExtractColumnValueType, ExtractedTriggerDiffRecord, FetchImplementation, GetAllQueryOptions, IndexColumnOptions, IndexOptions, IndexShorthand, InternalConnectionOptions, LinkQueryOptions, LockContext, LockOptions, MutableWatchedQueryState, OnChangeQueryProcessorOptions, OpId, OpTypeJSON, OplogEntryJSON, ParsedQuery, PowerSyncBackendConnector, PowerSyncCloseOptions, PowerSyncConnectionOptions, PowerSyncCredentials, PowerSyncDBListener, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, PowerSyncOpenFactoryOptions, ProgressWithOperations, Query, QueryParam, QueryResult, RemoteConnector, RequiredAdditionalConnectionOptions, RequiredPowerSyncConnectionOptions, RowType, SQLOnChangeOptions, SQLOpenFactory, SQLOpenOptions, SQLWatchOptions, SavedProgress, SchemaTableType, SocketSyncStreamOptions, StandardWatchedQuery, StandardWatchedQueryOptions, StreamingSyncCheckpoint, StreamingSyncCheckpointComplete, StreamingSyncCheckpointDiff, StreamingSyncCheckpointPartiallyComplete, StreamingSyncDataJSON, StreamingSyncImplementation, StreamingSyncImplementationListener, StreamingSyncKeepalive, StreamingSyncLine, StreamingSyncLineOrCrudUploadComplete, StreamingSyncRequest, StreamingSyncRequestParameterType, SyncDataBucketJSON, SyncDataFlowStatus, SyncLocalDatabaseResult, SyncNewCheckpointRequest, SyncPriorityStatus, SyncRequest, SyncResponse, SyncStatusOptions, SyncStreamOptions, TableOptions, TableUpdateOperation, TableV2Options, TrackDiffOptions, TrackPreviousOptions, Transaction, TriggerCreationHooks, TriggerDiffDeleteRecord, TriggerDiffHandlerContext, TriggerDiffInsertRecord, TriggerDiffRecord, TriggerDiffUpdateRecord, TriggerManager, TriggerRemoveCallback, UpdateNotification, WatchCompatibleQuery, WatchExecuteOptions, WatchHandler, WatchOnChangeEvent, WatchOnChangeHandler, WatchedQuery, WatchedQueryComparator, WatchedQueryDifferential, WatchedQueryListener, WatchedQueryOptions, WatchedQueryRowDifferential, WatchedQuerySettings, WatchedQueryState };
|