@powersync/common 1.53.2 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +922 -772
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +922 -772
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +923 -619
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +923 -619
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +749 -205
- package/lib/attachments/AttachmentContext.d.ts +7 -6
- package/lib/attachments/AttachmentContext.js +2 -1
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +82 -33
- package/lib/attachments/AttachmentQueue.js +16 -18
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +12 -4
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/AbstractPowerSyncDatabase.d.ts +110 -60
- package/lib/client/AbstractPowerSyncDatabase.js +77 -74
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +6 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js +3 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -1
- package/lib/client/ConnectionManager.d.ts +4 -1
- package/lib/client/ConnectionManager.js +1 -1
- package/lib/client/ConnectionManager.js.map +1 -1
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +12 -0
- package/lib/client/SQLOpenFactory.js +6 -0
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +6 -0
- package/lib/client/compilableQueryWatch.js +3 -0
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -0
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/constants.d.ts +3 -0
- package/lib/client/constants.js +3 -0
- package/lib/client/constants.js.map +1 -1
- package/lib/client/runOnSchemaChange.d.ts +3 -0
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +12 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js +6 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -0
- package/lib/client/sync/bucket/CrudEntry.js +4 -0
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +30 -1
- package/lib/client/sync/stream/AbstractRemote.js +59 -27
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +55 -5
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +32 -4
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js +2 -1
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -1
- package/lib/client/sync/sync-streams.d.ts +22 -7
- package/lib/client/triggers/TriggerManager.d.ts +19 -18
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
- package/lib/client/triggers/TriggerManagerImpl.js +3 -3
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +4 -0
- package/lib/client/watched/GetAllQuery.js +2 -0
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +24 -2
- package/lib/client/watched/WatchedQuery.js +9 -0
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +20 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +4 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -0
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/ConnectionClosedError.d.ts +2 -0
- package/lib/db/ConnectionClosedError.js +2 -0
- package/lib/db/ConnectionClosedError.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +56 -6
- package/lib/db/DBAdapter.js +15 -3
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/crud/SyncProgress.d.ts +6 -1
- package/lib/db/crud/SyncProgress.js +2 -0
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +36 -38
- package/lib/db/crud/SyncStatus.js +19 -14
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +28 -0
- package/lib/db/schema/Column.js +16 -3
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +9 -0
- package/lib/db/schema/Index.js +6 -0
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +9 -0
- package/lib/db/schema/IndexedColumn.js +6 -0
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +6 -1
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +27 -3
- package/lib/db/schema/Table.js +9 -0
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/db/schema/TableV2.d.ts +2 -0
- package/lib/db/schema/TableV2.js +2 -0
- package/lib/db/schema/TableV2.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/AbortOperation.d.ts +2 -0
- package/lib/utils/AbortOperation.js +2 -0
- package/lib/utils/AbortOperation.js.map +1 -1
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/ControlledExecutor.d.ts +6 -0
- package/lib/utils/ControlledExecutor.js +3 -0
- package/lib/utils/ControlledExecutor.js.map +1 -1
- package/lib/utils/Logger.d.ts +9 -0
- package/lib/utils/Logger.js +6 -0
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/async.d.ts +26 -0
- package/lib/utils/async.js +114 -27
- package/lib/utils/async.js.map +1 -1
- package/lib/utils/compatibility.d.ts +8 -0
- package/lib/utils/compatibility.js +9 -0
- package/lib/utils/compatibility.js.map +1 -0
- package/lib/utils/mutex.d.ts +8 -0
- package/lib/utils/mutex.js +3 -0
- package/lib/utils/mutex.js.map +1 -1
- package/lib/utils/parseQuery.d.ts +6 -0
- package/lib/utils/parseQuery.js +3 -0
- package/lib/utils/parseQuery.js.map +1 -1
- package/lib/utils/stream_transform.d.ts +3 -1
- package/lib/utils/stream_transform.js.map +1 -1
- package/package.json +3 -3
- package/src/attachments/AttachmentContext.ts +7 -6
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +93 -35
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +12 -4
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/AbstractPowerSyncDatabase.ts +135 -91
- package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
- package/src/client/ConnectionManager.ts +4 -1
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +12 -0
- package/src/client/compilableQueryWatch.ts +6 -0
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/constants.ts +3 -0
- package/src/client/runOnSchemaChange.ts +3 -0
- package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +9 -0
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
- package/src/client/sync/stream/AbstractRemote.ts +76 -34
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +55 -5
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
- package/src/client/sync/sync-streams.ts +22 -9
- package/src/client/triggers/TriggerManager.ts +19 -18
- package/src/client/triggers/TriggerManagerImpl.ts +5 -5
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +5 -1
- package/src/client/watched/WatchedQuery.ts +24 -2
- package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/ConnectionClosedError.ts +2 -0
- package/src/db/DBAdapter.ts +58 -6
- package/src/db/crud/SyncProgress.ts +6 -1
- package/src/db/crud/SyncStatus.ts +40 -21
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +28 -3
- package/src/db/schema/Index.ts +9 -0
- package/src/db/schema/IndexedColumn.ts +9 -0
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +8 -3
- package/src/db/schema/Table.ts +30 -5
- package/src/db/schema/TableV2.ts +2 -0
- package/src/index.ts +1 -1
- package/src/types/types.ts +6 -0
- package/src/utils/AbortOperation.ts +2 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/ControlledExecutor.ts +6 -0
- package/src/utils/Logger.ts +9 -0
- package/src/utils/async.ts +136 -28
- package/src/utils/compatibility.ts +9 -0
- package/src/utils/mutex.ts +12 -0
- package/src/utils/parseQuery.ts +6 -0
- package/src/utils/stream_transform.ts +3 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DBAdapter } from '../db/DBAdapter.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
3
6
|
export interface SQLOpenOptions {
|
|
4
7
|
/**
|
|
5
8
|
* Filename for the database.
|
|
@@ -25,6 +28,9 @@ export interface SQLOpenOptions {
|
|
|
25
28
|
debugMode?: boolean;
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
28
34
|
export interface SQLOpenFactory {
|
|
29
35
|
/**
|
|
30
36
|
* Opens a connection adapter to a SQLite DB
|
|
@@ -34,6 +40,8 @@ export interface SQLOpenFactory {
|
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
42
|
* Tests if the input is a {@link SQLOpenOptions}
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
37
45
|
*/
|
|
38
46
|
export const isSQLOpenOptions = (test: any): test is SQLOpenOptions => {
|
|
39
47
|
// typeof null is `object`, but you cannot use the `in` operator on `null.
|
|
@@ -42,6 +50,8 @@ export const isSQLOpenOptions = (test: any): test is SQLOpenOptions => {
|
|
|
42
50
|
|
|
43
51
|
/**
|
|
44
52
|
* Tests if input is a {@link SQLOpenFactory}
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
45
55
|
*/
|
|
46
56
|
export const isSQLOpenFactory = (test: any): test is SQLOpenFactory => {
|
|
47
57
|
return typeof test?.openDB == 'function';
|
|
@@ -49,6 +59,8 @@ export const isSQLOpenFactory = (test: any): test is SQLOpenFactory => {
|
|
|
49
59
|
|
|
50
60
|
/**
|
|
51
61
|
* Tests if input is a {@link DBAdapter}
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
52
64
|
*/
|
|
53
65
|
export const isDBAdapter = (test: any): test is DBAdapter => {
|
|
54
66
|
return typeof test?.writeTransaction == 'function';
|
|
@@ -2,11 +2,17 @@ import { CompilableQuery } from './../types/types.js';
|
|
|
2
2
|
import { AbstractPowerSyncDatabase, SQLWatchOptions } from './AbstractPowerSyncDatabase.js';
|
|
3
3
|
import { runOnSchemaChange } from './runOnSchemaChange.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
5
8
|
export interface CompilableQueryWatchHandler<T> {
|
|
6
9
|
onResult: (results: T[]) => void;
|
|
7
10
|
onError?: (error: Error) => void;
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
10
16
|
export function compilableQueryWatch<T>(
|
|
11
17
|
db: AbstractPowerSyncDatabase,
|
|
12
18
|
query: CompilableQuery<T>,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { PowerSyncCredentials } from './PowerSyncCredentials.js';
|
|
2
2
|
import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export interface PowerSyncBackendConnector {
|
|
5
8
|
/** Allows the PowerSync client to retrieve an authentication token from your backend
|
|
6
9
|
* which is used to authenticate against the PowerSync service.
|
package/src/client/constants.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { BaseListener, BaseObserverInterface, Disposable } from '../../../utils/
|
|
|
2
2
|
import { CrudBatch } from './CrudBatch.js';
|
|
3
3
|
import { CrudEntry } from './CrudEntry.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
export enum PSInternalTable {
|
|
6
9
|
DATA = 'ps_data',
|
|
7
10
|
CRUD = 'ps_crud',
|
|
@@ -10,6 +13,9 @@ export enum PSInternalTable {
|
|
|
10
13
|
UNTYPED = 'ps_untyped'
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
13
19
|
export enum PowerSyncControlCommand {
|
|
14
20
|
PROCESS_TEXT_LINE = 'line_text',
|
|
15
21
|
PROCESS_BSON_LINE = 'line_binary',
|
|
@@ -24,10 +30,16 @@ export enum PowerSyncControlCommand {
|
|
|
24
30
|
CONNECTION_STATE = 'connection'
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
27
36
|
export interface BucketStorageListener extends BaseListener {
|
|
28
37
|
crudUpdate: () => void;
|
|
29
38
|
}
|
|
30
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
31
43
|
export interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
|
|
32
44
|
init(): Promise<void>;
|
|
33
45
|
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* 64-bit unsigned integer stored as a string in base-10.
|
|
3
3
|
*
|
|
4
4
|
* Not sortable as a string.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
5
7
|
*/
|
|
6
8
|
export type OpId = string;
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Type of local change.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
10
14
|
*/
|
|
11
15
|
export enum UpdateType {
|
|
12
16
|
/** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
|
|
@@ -17,6 +21,9 @@ export enum UpdateType {
|
|
|
17
21
|
DELETE = 'DELETE'
|
|
18
22
|
}
|
|
19
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
20
27
|
export type CrudEntryJSON = {
|
|
21
28
|
id: string;
|
|
22
29
|
data: string;
|
|
@@ -48,6 +55,8 @@ type CrudEntryOutputJSON = {
|
|
|
48
55
|
|
|
49
56
|
/**
|
|
50
57
|
* A single client-side change.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
51
60
|
*/
|
|
52
61
|
export class CrudEntry {
|
|
53
62
|
/**
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
import { CrudBatch } from './CrudBatch.js';
|
|
12
12
|
import { CrudEntry, CrudEntryJSON } from './CrudEntry.js';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
14
17
|
export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
|
|
15
18
|
public tableNames: Set<string>;
|
|
16
19
|
private updateListener: () => void;
|
|
@@ -9,11 +9,14 @@ import {
|
|
|
9
9
|
doneResult,
|
|
10
10
|
extractBsonObjects,
|
|
11
11
|
extractJsonLines,
|
|
12
|
-
SimpleAsyncIterator
|
|
12
|
+
SimpleAsyncIterator,
|
|
13
|
+
valueResult
|
|
13
14
|
} from '../../../utils/stream_transform.js';
|
|
14
|
-
import {
|
|
15
|
-
import type { Queue } from 'event-iterator/lib/event-iterator.js';
|
|
15
|
+
import { EventQueue } from '../../../utils/async.js';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
17
20
|
export type RemoteConnector = {
|
|
18
21
|
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
19
22
|
invalidateCredentials?: () => void;
|
|
@@ -36,8 +39,14 @@ const SOCKET_TIMEOUT_MS = 30_000;
|
|
|
36
39
|
// significantly. Therefore this is longer than the socket timeout.
|
|
37
40
|
const KEEP_ALIVE_LIFETIME_MS = 90_000;
|
|
38
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
39
45
|
export const DEFAULT_REMOTE_LOGGER = Logger.get('PowerSyncRemote');
|
|
40
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
41
50
|
export type SyncStreamOptions = {
|
|
42
51
|
path: string;
|
|
43
52
|
data: unknown;
|
|
@@ -46,6 +55,9 @@ export type SyncStreamOptions = {
|
|
|
46
55
|
fetchOptions?: Request;
|
|
47
56
|
};
|
|
48
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
49
61
|
export enum FetchStrategy {
|
|
50
62
|
/**
|
|
51
63
|
* Queues multiple sync events before processing, reducing round-trips.
|
|
@@ -60,10 +72,16 @@ export enum FetchStrategy {
|
|
|
60
72
|
Sequential = 'sequential'
|
|
61
73
|
}
|
|
62
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
63
78
|
export type SocketSyncStreamOptions = SyncStreamOptions & {
|
|
64
79
|
fetchStrategy: FetchStrategy;
|
|
65
80
|
};
|
|
66
81
|
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
67
85
|
export type FetchImplementation = typeof fetch;
|
|
68
86
|
|
|
69
87
|
/**
|
|
@@ -71,6 +89,8 @@ export type FetchImplementation = typeof fetch;
|
|
|
71
89
|
* The class wrapper is used to distinguish the fetchImplementation
|
|
72
90
|
* option in [AbstractRemoteOptions] from the general fetch method
|
|
73
91
|
* which is typeof "function"
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
74
94
|
*/
|
|
75
95
|
export class FetchImplementationProvider {
|
|
76
96
|
getFetch(): FetchImplementation {
|
|
@@ -78,6 +98,9 @@ export class FetchImplementationProvider {
|
|
|
78
98
|
}
|
|
79
99
|
}
|
|
80
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
81
104
|
export type AbstractRemoteOptions = {
|
|
82
105
|
/**
|
|
83
106
|
* Transforms the PowerSync base URL which might contain
|
|
@@ -102,6 +125,9 @@ export type AbstractRemoteOptions = {
|
|
|
102
125
|
fetchOptions?: {};
|
|
103
126
|
};
|
|
104
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
105
131
|
export const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions = {
|
|
106
132
|
socketUrlTransformer: (url) =>
|
|
107
133
|
url.replace(/^https?:\/\//, function (match) {
|
|
@@ -111,6 +137,9 @@ export const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions = {
|
|
|
111
137
|
fetchOptions: {}
|
|
112
138
|
};
|
|
113
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @internal
|
|
142
|
+
*/
|
|
114
143
|
export abstract class AbstractRemote {
|
|
115
144
|
protected credentials: PowerSyncCredentials | null = null;
|
|
116
145
|
protected options: AbstractRemoteOptions;
|
|
@@ -300,8 +329,19 @@ export abstract class AbstractRemote {
|
|
|
300
329
|
let pendingSocket: WebSocket | null = null;
|
|
301
330
|
let keepAliveTimeout: any;
|
|
302
331
|
let rsocket: RSocket | null = null;
|
|
303
|
-
let
|
|
332
|
+
let paused = false;
|
|
333
|
+
const queue = new EventQueue<Uint8Array | null>({
|
|
334
|
+
eventDelivered: () => {
|
|
335
|
+
if (queue.countOutstandingEvents <= SYNC_QUEUE_REQUEST_LOW_WATER) {
|
|
336
|
+
paused = false;
|
|
337
|
+
requestMore();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
304
341
|
let didClose = false;
|
|
342
|
+
let connectionEstablished = false;
|
|
343
|
+
let pendingEventsCount = syncQueueRequestSize;
|
|
344
|
+
let res: Requestable | null = null;
|
|
305
345
|
|
|
306
346
|
const abortRequest = () => {
|
|
307
347
|
if (didClose) {
|
|
@@ -319,11 +359,26 @@ export abstract class AbstractRemote {
|
|
|
319
359
|
rsocket.close();
|
|
320
360
|
}
|
|
321
361
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
362
|
+
// Send a bogus event to the queue to ensure a pending listener gets woken up. We check for didClose and would
|
|
363
|
+
// return a doneEvent.
|
|
364
|
+
queue.notify(null);
|
|
325
365
|
};
|
|
326
366
|
|
|
367
|
+
function push(event: Uint8Array) {
|
|
368
|
+
queue.notify(event);
|
|
369
|
+
if (queue.countOutstandingEvents >= SYNC_QUEUE_REQUEST_HIGH_WATER) {
|
|
370
|
+
paused = true;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function requestMore() {
|
|
375
|
+
const delta = syncQueueRequestSize - pendingEventsCount;
|
|
376
|
+
if (!paused && delta > 0) {
|
|
377
|
+
res?.request(delta);
|
|
378
|
+
pendingEventsCount = syncQueueRequestSize;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
327
382
|
// Handle upstream abort
|
|
328
383
|
if (options.abortSignal.aborted) {
|
|
329
384
|
throw new AbortOperation('Connection request aborted');
|
|
@@ -384,31 +439,18 @@ export abstract class AbstractRemote {
|
|
|
384
439
|
rsocket.onClose(() => (rsocket = null));
|
|
385
440
|
|
|
386
441
|
return await new Promise((resolve, reject) => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
let res: Requestable | null = null;
|
|
391
|
-
|
|
392
|
-
function requestMore() {
|
|
393
|
-
const delta = syncQueueRequestSize - pendingEventsCount;
|
|
394
|
-
if (!paused && delta > 0) {
|
|
395
|
-
res?.request(delta);
|
|
396
|
-
pendingEventsCount = syncQueueRequestSize;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const events = new EventIterator<Uint8Array>(
|
|
401
|
-
(q) => {
|
|
402
|
-
queue = q;
|
|
442
|
+
const queueAsIterator: SimpleAsyncIterator<Uint8Array> = {
|
|
443
|
+
next: async () => {
|
|
444
|
+
if (didClose) return doneResult;
|
|
403
445
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
446
|
+
const notification = await queue.waitForEvent(options.abortSignal);
|
|
447
|
+
if (didClose) {
|
|
448
|
+
return doneResult;
|
|
449
|
+
} else {
|
|
450
|
+
return valueResult(notification!);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
};
|
|
412
454
|
|
|
413
455
|
res = rsocket!.requestStream(
|
|
414
456
|
{
|
|
@@ -447,12 +489,12 @@ export abstract class AbstractRemote {
|
|
|
447
489
|
// The connection is active
|
|
448
490
|
if (!connectionEstablished) {
|
|
449
491
|
connectionEstablished = true;
|
|
450
|
-
resolve(
|
|
492
|
+
resolve(queueAsIterator);
|
|
451
493
|
}
|
|
452
494
|
const { data } = payload;
|
|
453
495
|
|
|
454
496
|
if (data) {
|
|
455
|
-
|
|
497
|
+
push(data);
|
|
456
498
|
}
|
|
457
499
|
|
|
458
500
|
// Less events are now pending
|
|
@@ -589,7 +631,7 @@ export abstract class AbstractRemote {
|
|
|
589
631
|
* Posts a `/sync/stream` request.
|
|
590
632
|
*
|
|
591
633
|
* Depending on the `Content-Type` of the response, this returns strings for sync lines or encoded BSON documents as
|
|
592
|
-
*
|
|
634
|
+
* `Uint8Array`s.
|
|
593
635
|
*/
|
|
594
636
|
async fetchStream(options: SyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array | string>> {
|
|
595
637
|
const { isBson, stream } = await this.fetchStreamRaw(options);
|
|
@@ -22,16 +22,26 @@ import {
|
|
|
22
22
|
import { asyncNotifier } from '../../../utils/async.js';
|
|
23
23
|
import { StreamingSyncRequestParameterType } from './JsonValue.js';
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
25
28
|
export enum LockType {
|
|
26
29
|
CRUD = 'crud',
|
|
27
30
|
SYNC = 'sync'
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
30
36
|
export enum SyncStreamConnectionMethod {
|
|
31
37
|
HTTP = 'http',
|
|
32
38
|
WEB_SOCKET = 'web-socket'
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Deprecated since {@link SyncClientImplementation.RUST} is the only option.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
35
45
|
export enum SyncClientImplementation {
|
|
36
46
|
/**
|
|
37
47
|
* This implementation offloads the sync line decoding and handling into the PowerSync
|
|
@@ -42,8 +52,8 @@ export enum SyncClientImplementation {
|
|
|
42
52
|
* ## Compatibility warning
|
|
43
53
|
*
|
|
44
54
|
* The Rust sync client stores sync data in a format that is slightly different than the one used
|
|
45
|
-
* by the old JavaScript client. When adopting the {@link RUST} client on existing databases,
|
|
46
|
-
* migrate the format automatically.
|
|
55
|
+
* by the old JavaScript client. When adopting the {@link SyncClientImplementation.RUST} client on existing databases,
|
|
56
|
+
* the PowerSync SDK will migrate the format automatically.
|
|
47
57
|
*
|
|
48
58
|
* SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
|
|
49
59
|
* implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
|
|
@@ -54,11 +64,16 @@ export enum SyncClientImplementation {
|
|
|
54
64
|
|
|
55
65
|
/**
|
|
56
66
|
* The default {@link SyncClientImplementation} to use, {@link SyncClientImplementation.RUST}.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Deprecated since {@link SyncClientImplementation.RUST} is the only option.
|
|
69
|
+
* @public
|
|
57
70
|
*/
|
|
58
71
|
export const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.RUST;
|
|
59
72
|
|
|
60
73
|
/**
|
|
61
74
|
* Abstract Lock to be implemented by various JS environments
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
62
77
|
*/
|
|
63
78
|
export interface LockOptions<T> {
|
|
64
79
|
callback: () => Promise<T>;
|
|
@@ -66,6 +81,9 @@ export interface LockOptions<T> {
|
|
|
66
81
|
signal?: AbortSignal;
|
|
67
82
|
}
|
|
68
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
69
87
|
export interface AbstractStreamingSyncImplementationOptions extends RequiredAdditionalConnectionOptions {
|
|
70
88
|
adapter: BucketStorageAdapter;
|
|
71
89
|
subscriptions: SubscribedStream[];
|
|
@@ -79,6 +97,9 @@ export interface AbstractStreamingSyncImplementationOptions extends RequiredAddi
|
|
|
79
97
|
remote: AbstractRemote;
|
|
80
98
|
}
|
|
81
99
|
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
82
103
|
export interface StreamingSyncImplementationListener extends BaseListener {
|
|
83
104
|
/**
|
|
84
105
|
* Triggered whenever a status update has been attempted to be made or
|
|
@@ -94,12 +115,17 @@ export interface StreamingSyncImplementationListener extends BaseListener {
|
|
|
94
115
|
/**
|
|
95
116
|
* Configurable options to be used when connecting to the PowerSync
|
|
96
117
|
* backend instance.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
97
120
|
*/
|
|
98
121
|
export type PowerSyncConnectionOptions = Omit<InternalConnectionOptions, 'serializedSchema'>;
|
|
99
122
|
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
100
126
|
export interface InternalConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {}
|
|
101
127
|
|
|
102
|
-
/** @
|
|
128
|
+
/** @public */
|
|
103
129
|
export interface BaseConnectionOptions {
|
|
104
130
|
/**
|
|
105
131
|
* A set of metadata to be included in service logs.
|
|
@@ -161,6 +187,9 @@ export interface RequiredAdditionalConnectionOptions extends Required<Additional
|
|
|
161
187
|
subscriptions: SubscribedStream[];
|
|
162
188
|
}
|
|
163
189
|
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
164
193
|
export interface StreamingSyncImplementation
|
|
165
194
|
extends BaseObserverInterface<StreamingSyncImplementationListener>, Disposable {
|
|
166
195
|
/**
|
|
@@ -183,16 +212,31 @@ export interface StreamingSyncImplementation
|
|
|
183
212
|
markConnectionMayHaveChanged(): void;
|
|
184
213
|
}
|
|
185
214
|
|
|
215
|
+
/**
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
186
218
|
export const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
|
|
219
|
+
/**
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
187
222
|
export const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
188
223
|
|
|
224
|
+
/**
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
189
227
|
export const DEFAULT_STREAMING_SYNC_OPTIONS = {
|
|
190
228
|
retryDelayMs: DEFAULT_RETRY_DELAY_MS,
|
|
191
229
|
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
|
|
192
230
|
};
|
|
193
231
|
|
|
232
|
+
/**
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
194
235
|
export type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
|
|
195
236
|
|
|
237
|
+
/**
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
196
240
|
export const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions = {
|
|
197
241
|
appMetadata: {},
|
|
198
242
|
connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
|
|
@@ -203,11 +247,17 @@ export const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptio
|
|
|
203
247
|
includeDefaultStreams: true
|
|
204
248
|
};
|
|
205
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @internal
|
|
252
|
+
*/
|
|
206
253
|
export type SubscribedStream = {
|
|
207
254
|
name: string;
|
|
208
255
|
params: Record<string, any> | null;
|
|
209
256
|
};
|
|
210
257
|
|
|
258
|
+
/**
|
|
259
|
+
* @internal
|
|
260
|
+
*/
|
|
211
261
|
export abstract class AbstractStreamingSyncImplementation
|
|
212
262
|
extends BaseObserver<StreamingSyncImplementationListener>
|
|
213
263
|
implements StreamingSyncImplementation
|
|
@@ -570,7 +620,7 @@ The next upload iteration will be delayed.`);
|
|
|
570
620
|
}
|
|
571
621
|
|
|
572
622
|
/**
|
|
573
|
-
* Older versions of the JS SDK used to encode subkeys as JSON in
|
|
623
|
+
* Older versions of the JS SDK used to encode subkeys as JSON in `OplogEntry.toJSON`.
|
|
574
624
|
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
575
625
|
* While this is not a problem as long as it's done consistently, it causes issues when a database
|
|
576
626
|
* created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
|
|
@@ -580,7 +630,7 @@ The next upload iteration will be delayed.`);
|
|
|
580
630
|
* migration is only triggered when necessary (for now). The function returns whether the new format
|
|
581
631
|
* should be used, so that the JS SDK is able to write to updated databases.
|
|
582
632
|
*
|
|
583
|
-
* @param requireFixedKeyFormat Whether we require the new format or also support the old one.
|
|
633
|
+
* @param requireFixedKeyFormat - Whether we require the new format or also support the old one.
|
|
584
634
|
* The Rust client requires the new subkey format.
|
|
585
635
|
* @returns Whether the database is now using the new, fixed subkey format.
|
|
586
636
|
*/
|
|
@@ -42,7 +42,9 @@ export class WebsocketClientTransport implements ClientTransport {
|
|
|
42
42
|
resolve(new WebsocketDuplexConnection(websocket, new Deserializer(), multiplexerDemultiplexerFactory));
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const errorListener = (
|
|
45
|
+
const errorListener = (event: Event) => {
|
|
46
|
+
const ev = event as ErrorEvent;
|
|
47
|
+
|
|
46
48
|
removeListeners();
|
|
47
49
|
// We add a default error in that case.
|
|
48
50
|
if (ev.error != null) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* A description of a sync stream, consisting of its {@link name} and the
|
|
2
|
+
* A description of a sync stream, consisting of its {@link SyncStreamDescription.name} and the
|
|
3
|
+
* {@link SyncStreamDescription.parameters} used when subscribing.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
5
6
|
*/
|
|
6
7
|
export interface SyncStreamDescription {
|
|
7
8
|
/**
|
|
@@ -21,6 +22,8 @@ export interface SyncStreamDescription {
|
|
|
21
22
|
* Information about a subscribed sync stream.
|
|
22
23
|
*
|
|
23
24
|
* This includes the {@link SyncStreamDescription}, along with information about the current sync status.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
24
27
|
*/
|
|
25
28
|
export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
26
29
|
active: boolean;
|
|
@@ -28,15 +31,17 @@ export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
28
31
|
* Whether this stream subscription is included by default, regardless of whether the stream has explicitly been
|
|
29
32
|
* subscribed to or not.
|
|
30
33
|
*
|
|
31
|
-
* It's possible for both {@link isDefault} and
|
|
32
|
-
*
|
|
34
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
35
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
36
|
+
* default stream was subscribed explicitly.
|
|
33
37
|
*/
|
|
34
38
|
isDefault: boolean;
|
|
35
39
|
/**
|
|
36
40
|
* Whether this stream has been subscribed to explicitly.
|
|
37
41
|
*
|
|
38
|
-
* It's possible for both {@link isDefault} and
|
|
39
|
-
*
|
|
42
|
+
* It's possible for both {@link SyncSubscriptionDescription.isDefault} and
|
|
43
|
+
* {@link SyncSubscriptionDescription.hasExplicitSubscription} to be true at the same time - this happens when a
|
|
44
|
+
* default stream was subscribed explicitly.
|
|
40
45
|
*/
|
|
41
46
|
hasExplicitSubscription: boolean;
|
|
42
47
|
/**
|
|
@@ -49,11 +54,14 @@ export interface SyncSubscriptionDescription extends SyncStreamDescription {
|
|
|
49
54
|
*/
|
|
50
55
|
hasSynced: boolean;
|
|
51
56
|
/**
|
|
52
|
-
* If {@link hasSynced} is true, the last time data from this stream has been synced.
|
|
57
|
+
* If {@link SyncSubscriptionDescription.hasSynced} is true, the last time data from this stream has been synced.
|
|
53
58
|
*/
|
|
54
59
|
lastSyncedAt: Date | null;
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
57
65
|
export interface SyncStreamSubscribeOptions {
|
|
58
66
|
/**
|
|
59
67
|
* A "time to live" for this stream subscription, in seconds.
|
|
@@ -74,6 +82,8 @@ export interface SyncStreamSubscribeOptions {
|
|
|
74
82
|
* A handle to a {@link SyncStreamDescription} that allows subscribing to the stream.
|
|
75
83
|
*
|
|
76
84
|
* To obtain an instance of {@link SyncStream}, call {@link AbstractPowerSyncDatabase.syncStream}.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
77
87
|
*/
|
|
78
88
|
export interface SyncStream extends SyncStreamDescription {
|
|
79
89
|
/**
|
|
@@ -82,7 +92,7 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
82
92
|
* You should keep a reference to the returned {@link SyncStreamSubscription} object along as you need data for that
|
|
83
93
|
* stream. As soon as {@link SyncStreamSubscription.unsubscribe} is called for all subscriptions on this stream
|
|
84
94
|
* (including subscriptions created on other tabs), the {@link SyncStreamSubscribeOptions.ttl} starts ticking and will
|
|
85
|
-
* eventually evict the stream (unless {@link subscribe} is called again).
|
|
95
|
+
* eventually evict the stream (unless {@link SyncStream.subscribe} is called again).
|
|
86
96
|
*/
|
|
87
97
|
subscribe(options?: SyncStreamSubscribeOptions): Promise<SyncStreamSubscription>;
|
|
88
98
|
|
|
@@ -94,6 +104,9 @@ export interface SyncStream extends SyncStreamDescription {
|
|
|
94
104
|
unsubscribeAll(): Promise<void>;
|
|
95
105
|
}
|
|
96
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
97
110
|
export interface SyncStreamSubscription extends SyncStreamDescription {
|
|
98
111
|
/**
|
|
99
112
|
* A promise that resolves once data from in this sync stream has been synced and applied.
|