@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630141119
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/lib/attachments/AttachmentContext.d.ts +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.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 +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.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 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- 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/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.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 +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- 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/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- 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 +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- 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 +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -22
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- 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/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +9 -46
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- 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 +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +6 -22
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -405
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
|
@@ -1,72 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DBAdapter, QueryResult, Transaction } from '../db/DBAdapter.js';
|
|
1
|
+
import { DBAdapter, DBGetUtils, LockContext, SqlExecutor, Transaction } from '../db/DBAdapter.js';
|
|
3
2
|
import { SyncStatus } from '../db/crud/SyncStatus.js';
|
|
4
|
-
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
5
3
|
import { Schema } from '../db/schema/Schema.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
4
|
+
import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver.js';
|
|
5
|
+
import { WatchedQueryComparator } from './watched/processors/comparators.js';
|
|
6
|
+
import { PowerSyncLogger } from '../utils/Logger.js';
|
|
7
|
+
import { DatabaseSource } from './SQLOpenFactory.js';
|
|
8
|
+
import { TriggerManager } from './triggers/TriggerManager.js';
|
|
10
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
|
|
11
|
-
import {
|
|
10
|
+
import { SyncOptions } from './sync/options.js';
|
|
11
|
+
import { SyncStream } from './sync/sync-streams.js';
|
|
12
|
+
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
|
|
12
13
|
import { CrudBatch } from './sync/bucket/CrudBatch.js';
|
|
13
14
|
import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
|
|
14
|
-
import {
|
|
15
|
-
import { SyncStream } from './sync/sync-streams.js';
|
|
16
|
-
import { TriggerManager, TriggerManagerConfig } from './triggers/TriggerManager.js';
|
|
17
|
-
import { TriggerManagerImpl } from './triggers/TriggerManagerImpl.js';
|
|
15
|
+
import { ArrayQueryDefinition, Query } from './Query.js';
|
|
18
16
|
import { WatchCompatibleQuery } from './watched/WatchedQuery.js';
|
|
19
|
-
import { WatchedQueryComparator } from './watched/processors/comparators.js';
|
|
20
17
|
import { Mutex } from '../utils/mutex.js';
|
|
18
|
+
import { QueryResult } from '../db/QueryResult.js';
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
21
22
|
export interface DisconnectAndClearOptions {
|
|
22
23
|
/** When set to false, data in local-only tables is preserved. */
|
|
23
24
|
clearLocal?: boolean;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Options required regardless of how a PowerSync database is opened.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface BasePowerSyncDatabaseOptions {
|
|
26
32
|
/** Schema used for the local database. */
|
|
27
33
|
schema: Schema;
|
|
28
|
-
|
|
29
|
-
* @deprecated Use {@link retryDelayMs} instead as this will be removed in future releases.
|
|
30
|
-
*/
|
|
31
|
-
retryDelay?: number;
|
|
32
|
-
logger?: ILogger;
|
|
33
|
-
}
|
|
34
|
-
export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
|
|
35
|
-
/**
|
|
36
|
-
* Source for a SQLite database connection.
|
|
37
|
-
* This can be either:
|
|
38
|
-
* - A {@link DBAdapter} if providing an instantiated SQLite connection
|
|
39
|
-
* - A {@link SQLOpenFactory} which will be used to open a SQLite connection
|
|
40
|
-
* - {@link SQLOpenOptions} for opening a SQLite connection with a default {@link SQLOpenFactory}
|
|
41
|
-
*/
|
|
42
|
-
database: DBAdapter | SQLOpenFactory | SQLOpenOptions;
|
|
43
|
-
}
|
|
44
|
-
export interface PowerSyncDatabaseOptionsWithDBAdapter extends BasePowerSyncDatabaseOptions {
|
|
45
|
-
database: DBAdapter;
|
|
46
|
-
}
|
|
47
|
-
export interface PowerSyncDatabaseOptionsWithOpenFactory extends BasePowerSyncDatabaseOptions {
|
|
48
|
-
database: SQLOpenFactory;
|
|
49
|
-
}
|
|
50
|
-
export interface PowerSyncDatabaseOptionsWithSettings extends BasePowerSyncDatabaseOptions {
|
|
51
|
-
database: SQLOpenOptions;
|
|
34
|
+
logger?: PowerSyncLogger;
|
|
52
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export type PowerSyncDatabaseOptions = BasePowerSyncDatabaseOptions & DatabaseSource;
|
|
40
|
+
/**
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
53
43
|
export interface SQLOnChangeOptions {
|
|
54
44
|
signal?: AbortSignal;
|
|
55
45
|
tables?: string[];
|
|
56
46
|
/** The minimum interval between queries. */
|
|
57
47
|
throttleMs?: number;
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated All tables specified in {@link tables} will be watched, including PowerSync tables with prefixes.
|
|
60
|
-
*
|
|
61
|
-
* Allows for watching any SQL table
|
|
62
|
-
* by not removing PowerSync table name prefixes
|
|
63
|
-
*/
|
|
64
|
-
rawTableNames?: boolean;
|
|
65
48
|
/**
|
|
66
49
|
* Emits an empty result set immediately
|
|
67
50
|
*/
|
|
68
51
|
triggerImmediate?: boolean;
|
|
69
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
70
56
|
export interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
71
57
|
/**
|
|
72
58
|
* Optional comparator which will be used to compare the results of the query.
|
|
@@ -74,23 +60,38 @@ export interface SQLWatchOptions extends SQLOnChangeOptions {
|
|
|
74
60
|
*/
|
|
75
61
|
comparator?: WatchedQueryComparator<QueryResult>;
|
|
76
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
77
66
|
export interface WatchOnChangeEvent {
|
|
78
67
|
changedTables: string[];
|
|
79
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
80
72
|
export interface WatchHandler {
|
|
81
73
|
onResult: (results: QueryResult) => void;
|
|
82
74
|
onError?: (error: Error) => void;
|
|
83
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
84
79
|
export interface WatchOnChangeHandler {
|
|
85
80
|
onChange: (event: WatchOnChangeEvent) => Promise<void> | void;
|
|
86
|
-
onError?: (error: Error) => void;
|
|
87
81
|
}
|
|
88
|
-
|
|
82
|
+
/**
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export interface PowerSyncDBListener extends BaseListener {
|
|
89
86
|
initialized: () => void;
|
|
90
87
|
schemaChanged: (schema: Schema) => void;
|
|
88
|
+
statusChanged?: (status: SyncStatus) => void;
|
|
91
89
|
closing: () => Promise<void> | void;
|
|
92
90
|
closed: () => Promise<void> | void;
|
|
93
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
94
95
|
export interface PowerSyncCloseOptions {
|
|
95
96
|
/**
|
|
96
97
|
* Disconnect the sync stream client if connected.
|
|
@@ -99,76 +100,45 @@ export interface PowerSyncCloseOptions {
|
|
|
99
100
|
*/
|
|
100
101
|
disconnect?: boolean;
|
|
101
102
|
}
|
|
102
|
-
export declare const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions;
|
|
103
|
-
export declare const DEFAULT_POWERSYNC_DB_OPTIONS: {
|
|
104
|
-
retryDelayMs: number;
|
|
105
|
-
crudUploadThrottleMs: number;
|
|
106
|
-
};
|
|
107
|
-
export declare const DEFAULT_CRUD_BATCH_LIMIT = 100;
|
|
108
103
|
/**
|
|
109
|
-
*
|
|
110
|
-
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
111
|
-
* be obtained.
|
|
104
|
+
* @public
|
|
112
105
|
*/
|
|
113
|
-
export
|
|
106
|
+
export interface PowerSyncDatabaseConstructor<Options> {
|
|
107
|
+
new (options: Options): CommonPowerSyncDatabase;
|
|
108
|
+
}
|
|
114
109
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @
|
|
110
|
+
* @public
|
|
111
|
+
* @deprecated Use {@link CommonPowerSyncDatabase} instead.
|
|
117
112
|
*/
|
|
118
|
-
export
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
export type AbstractPowerSyncDatabase = CommonPowerSyncDatabase;
|
|
114
|
+
/**
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export interface CommonPowerSyncDatabase extends BaseObserverInterface<PowerSyncDBListener>, SqlExecutor, DBGetUtils {
|
|
121
118
|
/**
|
|
122
119
|
* Returns true if the connection is closed.
|
|
123
120
|
*/
|
|
124
|
-
closed: boolean;
|
|
125
|
-
ready: boolean;
|
|
121
|
+
readonly closed: boolean;
|
|
122
|
+
readonly ready: boolean;
|
|
126
123
|
/**
|
|
127
124
|
* Current connection status.
|
|
128
125
|
*/
|
|
129
|
-
currentStatus: SyncStatus;
|
|
130
|
-
sdkVersion: string;
|
|
131
|
-
protected bucketStorageAdapter: BucketStorageAdapter;
|
|
132
|
-
protected _isReadyPromise: Promise<void>;
|
|
133
|
-
protected connectionManager: ConnectionManager;
|
|
134
|
-
private subscriptions;
|
|
135
|
-
get syncStreamImplementation(): StreamingSyncImplementation | null;
|
|
136
|
-
/**
|
|
137
|
-
* The connector used to connect to the PowerSync service.
|
|
138
|
-
*
|
|
139
|
-
* @returns The connector used to connect to the PowerSync service or null if `connect()` has not been called.
|
|
140
|
-
*/
|
|
141
|
-
get connector(): PowerSyncBackendConnector | null;
|
|
126
|
+
readonly currentStatus: SyncStatus;
|
|
127
|
+
readonly sdkVersion: string;
|
|
142
128
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @returns The resolved connection options used to connect to the PowerSync service or null if `connect()` has not been called.
|
|
146
|
-
*/
|
|
147
|
-
get connectionOptions(): InternalConnectionOptions | null;
|
|
148
|
-
protected _schema: Schema;
|
|
149
|
-
private _database;
|
|
150
|
-
protected runExclusiveMutex: Mutex;
|
|
151
|
-
/**
|
|
152
|
-
* @experimental
|
|
129
|
+
* @experimental @alpha
|
|
153
130
|
* Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
|
|
154
131
|
*/
|
|
155
132
|
readonly triggers: TriggerManager;
|
|
156
|
-
|
|
157
|
-
logger: ILogger;
|
|
158
|
-
constructor(options: PowerSyncDatabaseOptionsWithDBAdapter);
|
|
159
|
-
constructor(options: PowerSyncDatabaseOptionsWithOpenFactory);
|
|
160
|
-
constructor(options: PowerSyncDatabaseOptionsWithSettings);
|
|
161
|
-
constructor(options: PowerSyncDatabaseOptions);
|
|
133
|
+
readonly logger: PowerSyncLogger;
|
|
162
134
|
/**
|
|
163
135
|
* Schema used for the local database.
|
|
164
136
|
*/
|
|
165
|
-
|
|
166
|
-
[x: string]: import("../index.js").Table<any>;
|
|
167
|
-
}>;
|
|
137
|
+
readonly schema: Schema;
|
|
168
138
|
/**
|
|
169
139
|
* The underlying database.
|
|
170
140
|
*
|
|
171
|
-
* For the most part, behavior is the same whether querying on the underlying database, or on {@link
|
|
141
|
+
* For the most part, behavior is the same whether querying on the underlying database, or on {@link CommonPowerSyncDatabase}.
|
|
172
142
|
*/
|
|
173
143
|
get database(): DBAdapter;
|
|
174
144
|
/**
|
|
@@ -176,17 +146,6 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
176
146
|
*/
|
|
177
147
|
get connected(): boolean;
|
|
178
148
|
get connecting(): boolean;
|
|
179
|
-
/**
|
|
180
|
-
* Opens the DBAdapter given open options using a default open factory
|
|
181
|
-
*/
|
|
182
|
-
protected abstract openDBAdapter(options: PowerSyncDatabaseOptionsWithSettings): DBAdapter;
|
|
183
|
-
/**
|
|
184
|
-
* Generates a base configuration for {@link TriggerManagerImpl}.
|
|
185
|
-
* Implementations should override this if necessary.
|
|
186
|
-
*/
|
|
187
|
-
protected generateTriggerManagerConfig(): TriggerManagerConfig;
|
|
188
|
-
protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: CreateSyncImplementationOptions & RequiredAdditionalConnectionOptions): StreamingSyncImplementation;
|
|
189
|
-
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
|
|
190
149
|
/**
|
|
191
150
|
* @returns A promise which will resolve once initialization is completed.
|
|
192
151
|
*/
|
|
@@ -194,7 +153,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
194
153
|
/**
|
|
195
154
|
* Wait for the first sync operation to complete.
|
|
196
155
|
*
|
|
197
|
-
* @param request Either an abort signal (after which the promise will complete regardless of
|
|
156
|
+
* @param request - Either an abort signal (after which the promise will complete regardless of
|
|
198
157
|
* whether a full sync was completed) or an object providing an abort signal and a priority target.
|
|
199
158
|
* When a priority target is set, the promise may complete when all buckets with the given (or higher)
|
|
200
159
|
* priorities have been synchronized. This can be earlier than a complete sync.
|
|
@@ -208,22 +167,10 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
208
167
|
* Waits for the first sync status for which the `status` callback returns a truthy value.
|
|
209
168
|
*/
|
|
210
169
|
waitForStatus(predicate: (status: SyncStatus) => any, signal?: AbortSignal): Promise<void>;
|
|
211
|
-
/**
|
|
212
|
-
* Allows for extended implementations to execute custom initialization
|
|
213
|
-
* logic as part of the total init process
|
|
214
|
-
*/
|
|
215
|
-
abstract _initialize(): Promise<void>;
|
|
216
|
-
/**
|
|
217
|
-
* Entry point for executing initialization logic.
|
|
218
|
-
* This is to be automatically executed in the constructor.
|
|
219
|
-
*/
|
|
220
|
-
protected initialize(): Promise<void>;
|
|
221
|
-
protected loadVersion(): Promise<void>;
|
|
222
|
-
protected resolveOfflineSyncStatus(): Promise<void>;
|
|
223
170
|
/**
|
|
224
171
|
* Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor.
|
|
225
172
|
*
|
|
226
|
-
* Cannot be used while connected - this should only be called before {@link
|
|
173
|
+
* Cannot be used while connected - this should only be called before {@link CommonPowerSyncDatabase.connect}.
|
|
227
174
|
*/
|
|
228
175
|
updateSchema(schema: Schema): Promise<void>;
|
|
229
176
|
/**
|
|
@@ -231,25 +178,14 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
231
178
|
* While initializing is automatic, this helps to catch and report initialization errors.
|
|
232
179
|
*/
|
|
233
180
|
init(): Promise<void>;
|
|
234
|
-
protected resolvedConnectionOptions(options: CreateSyncImplementationOptions): CreateSyncImplementationOptions & RequiredAdditionalConnectionOptions;
|
|
235
|
-
/**
|
|
236
|
-
* @deprecated Use {@link AbstractPowerSyncDatabase#close} instead.
|
|
237
|
-
* Clears all listeners registered by {@link AbstractPowerSyncDatabase#registerListener}.
|
|
238
|
-
*/
|
|
239
|
-
dispose(): void;
|
|
240
|
-
/**
|
|
241
|
-
* Locking mechanism for exclusively running critical portions of connect/disconnect operations.
|
|
242
|
-
* Locking here is mostly only important on web for multiple tab scenarios.
|
|
243
|
-
*/
|
|
244
|
-
protected runExclusive<T>(callback: () => Promise<T>): Promise<T>;
|
|
245
181
|
/**
|
|
246
182
|
* Connects to stream of events from the PowerSync instance.
|
|
247
183
|
*/
|
|
248
|
-
connect(connector: PowerSyncBackendConnector, options?:
|
|
184
|
+
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
249
185
|
/**
|
|
250
186
|
* Close the sync connection.
|
|
251
187
|
*
|
|
252
|
-
* Use {@link connect} to connect again.
|
|
188
|
+
* Use {@link CommonPowerSyncDatabase.connect} to connect again.
|
|
253
189
|
*/
|
|
254
190
|
disconnect(): Promise<void>;
|
|
255
191
|
/**
|
|
@@ -264,10 +200,9 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
264
200
|
/**
|
|
265
201
|
* Create a sync stream to query its status or to subscribe to it.
|
|
266
202
|
*
|
|
267
|
-
* @param name The name of the stream to subscribe to.
|
|
268
|
-
* @param params Optional parameters for the stream subscription.
|
|
203
|
+
* @param name - The name of the stream to subscribe to.
|
|
204
|
+
* @param params - Optional parameters for the stream subscription.
|
|
269
205
|
* @returns A {@link SyncStream} instance that can be subscribed to.
|
|
270
|
-
* @experimental Sync streams are currently in alpha.
|
|
271
206
|
*/
|
|
272
207
|
syncStream(name: string, params?: Record<string, any>): SyncStream;
|
|
273
208
|
/**
|
|
@@ -293,14 +228,14 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
293
228
|
* Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
|
|
294
229
|
* requesting the next batch.
|
|
295
230
|
*
|
|
296
|
-
* Use
|
|
231
|
+
* Use the `limit` parameter to specify the maximum number of updates to return in a single
|
|
297
232
|
* batch.
|
|
298
233
|
*
|
|
299
234
|
* This method does include transaction ids in the result, but does not group
|
|
300
235
|
* data by transaction. One batch may contain data from multiple transactions,
|
|
301
236
|
* and a single transaction may be split over multiple batches.
|
|
302
237
|
*
|
|
303
|
-
* @param limit Maximum number of CRUD entries to include in the batch
|
|
238
|
+
* @param limit - Maximum number of CRUD entries to include in the batch
|
|
304
239
|
* @returns A batch of CRUD operations to upload, or null if there are none
|
|
305
240
|
*/
|
|
306
241
|
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
@@ -314,7 +249,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
314
249
|
* Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
|
|
315
250
|
* requesting the next transaction.
|
|
316
251
|
*
|
|
317
|
-
* Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
|
|
252
|
+
* Unlike {@link CommonPowerSyncDatabase.getCrudBatch}, this only returns data from a single transaction at a time.
|
|
318
253
|
* All data for the transaction is loaded into memory.
|
|
319
254
|
*
|
|
320
255
|
* @returns A transaction of CRUD operations to upload, or null if there are none
|
|
@@ -326,7 +261,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
326
261
|
* This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
|
|
327
262
|
* returned iterator is a full transaction containing all local writes made while that transaction was active.
|
|
328
263
|
*
|
|
329
|
-
* Unlike {@link getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
264
|
+
* Unlike {@link CommonPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
|
|
330
265
|
* {@link CrudTransaction.complete}d yet, this iterator can be used to receive multiple transactions. Calling
|
|
331
266
|
* {@link CrudTransaction.complete} will mark that and all prior transactions emitted by the iterator as completed.
|
|
332
267
|
*
|
|
@@ -360,82 +295,23 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
360
295
|
* @returns A unique identifier for the database instance
|
|
361
296
|
*/
|
|
362
297
|
getClientId(): Promise<string>;
|
|
363
|
-
private handleCrudCheckpoint;
|
|
364
|
-
/**
|
|
365
|
-
* Execute a SQL write (INSERT/UPDATE/DELETE) query
|
|
366
|
-
* and optionally return results.
|
|
367
|
-
*
|
|
368
|
-
* When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
|
|
369
|
-
* the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
|
|
370
|
-
* Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
|
|
371
|
-
*
|
|
372
|
-
* @param sql The SQL query to execute
|
|
373
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
374
|
-
* @returns The query result as an object with structured key-value pairs
|
|
375
|
-
*/
|
|
376
|
-
execute(sql: string, parameters?: any[]): Promise<QueryResult>;
|
|
377
|
-
/**
|
|
378
|
-
* Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
|
|
379
|
-
* This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
|
|
380
|
-
*
|
|
381
|
-
* @param sql The SQL query to execute
|
|
382
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
383
|
-
* @returns The raw query result from the underlying database as a nested array of raw values, where each row is
|
|
384
|
-
* represented as an array of column values without field names.
|
|
385
|
-
*/
|
|
386
|
-
executeRaw(sql: string, parameters?: any[]): Promise<any[][]>;
|
|
387
|
-
/**
|
|
388
|
-
* Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
|
|
389
|
-
* and optionally return results.
|
|
390
|
-
* This is faster than executing separately with each parameter set.
|
|
391
|
-
*
|
|
392
|
-
* @param sql The SQL query to execute
|
|
393
|
-
* @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
394
|
-
* @returns The query result
|
|
395
|
-
*/
|
|
396
|
-
executeBatch(sql: string, parameters?: any[][]): Promise<QueryResult>;
|
|
397
|
-
/**
|
|
398
|
-
* Execute a read-only query and return results.
|
|
399
|
-
*
|
|
400
|
-
* @param sql The SQL query to execute
|
|
401
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
402
|
-
* @returns An array of results
|
|
403
|
-
*/
|
|
404
|
-
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
405
|
-
/**
|
|
406
|
-
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
|
|
407
|
-
*
|
|
408
|
-
* @param sql The SQL query to execute
|
|
409
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
410
|
-
* @returns The first result if found, or null if no results are returned
|
|
411
|
-
*/
|
|
412
|
-
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
413
|
-
/**
|
|
414
|
-
* Execute a read-only query and return the first result, error if the ResultSet is empty.
|
|
415
|
-
*
|
|
416
|
-
* @param sql The SQL query to execute
|
|
417
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
418
|
-
* @returns The first result matching the query
|
|
419
|
-
* @throws Error if no rows are returned
|
|
420
|
-
*/
|
|
421
|
-
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
422
298
|
/**
|
|
423
299
|
* Takes a read lock, without starting a transaction.
|
|
424
|
-
* In most cases, {@link readTransaction} should be used instead.
|
|
300
|
+
* In most cases, {@link CommonPowerSyncDatabase.readTransaction} should be used instead.
|
|
425
301
|
*/
|
|
426
|
-
readLock<T>(callback: (db:
|
|
302
|
+
readLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
427
303
|
/**
|
|
428
304
|
* Takes a global lock, without starting a transaction.
|
|
429
|
-
* In most cases, {@link writeTransaction} should be used instead.
|
|
305
|
+
* In most cases, {@link CommonPowerSyncDatabase.writeTransaction} should be used instead.
|
|
430
306
|
*/
|
|
431
|
-
writeLock<T>(callback: (db:
|
|
307
|
+
writeLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
432
308
|
/**
|
|
433
309
|
* Open a read-only transaction.
|
|
434
310
|
* Read transactions can run concurrently to a write transaction.
|
|
435
311
|
* Changes from any write transaction are not visible to read transactions started before it.
|
|
436
312
|
*
|
|
437
|
-
* @param callback Function to execute within the transaction
|
|
438
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
313
|
+
* @param callback - Function to execute within the transaction
|
|
314
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
439
315
|
* @returns The result of the callback
|
|
440
316
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
441
317
|
*/
|
|
@@ -445,15 +321,15 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
445
321
|
* This takes a global lock - only one write transaction can execute against the database at a time.
|
|
446
322
|
* Statements within the transaction must be done on the provided {@link Transaction} interface.
|
|
447
323
|
*
|
|
448
|
-
* @param callback Function to execute within the transaction
|
|
449
|
-
* @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
|
|
324
|
+
* @param callback - Function to execute within the transaction
|
|
325
|
+
* @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
|
|
450
326
|
* @returns The result of the callback
|
|
451
327
|
* @throws Error if the lock cannot be obtained within the timeout period
|
|
452
328
|
*/
|
|
453
329
|
writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
|
|
454
330
|
/**
|
|
455
|
-
* This version of `watch` uses
|
|
456
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link watchWithCallback}.
|
|
331
|
+
* This version of `watch` uses `AsyncGenerator`, for documentation see {@link CommonPowerSyncDatabase.watchWithAsyncGenerator}.
|
|
332
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link CommonPowerSyncDatabase.watchWithCallback}.
|
|
457
333
|
*
|
|
458
334
|
* @example
|
|
459
335
|
* ```javascript
|
|
@@ -469,7 +345,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
469
345
|
*/
|
|
470
346
|
watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
471
347
|
/**
|
|
472
|
-
* See {@link watchWithCallback}.
|
|
348
|
+
* See {@link CommonPowerSyncDatabase.watchWithCallback}.
|
|
473
349
|
*
|
|
474
350
|
* @example
|
|
475
351
|
* ```javascript
|
|
@@ -487,7 +363,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
487
363
|
watch(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
488
364
|
/**
|
|
489
365
|
* Allows defining a query which can be used to build a {@link WatchedQuery}.
|
|
490
|
-
* The defined query will be executed with {@link
|
|
366
|
+
* The defined query will be executed with {@link CommonPowerSyncDatabase#getAll}.
|
|
491
367
|
* An optional mapper function can be provided to transform the results.
|
|
492
368
|
*
|
|
493
369
|
* @example
|
|
@@ -523,25 +399,25 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
523
399
|
customQuery<RowType>(query: WatchCompatibleQuery<RowType[]>): Query<RowType>;
|
|
524
400
|
/**
|
|
525
401
|
* Execute a read query every time the source tables are modified.
|
|
526
|
-
* Use {@link
|
|
402
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
527
403
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
528
404
|
*
|
|
529
405
|
* Note that the `onChange` callback member of the handler is required.
|
|
530
406
|
*
|
|
531
|
-
* @param sql The SQL query to execute
|
|
532
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
533
|
-
* @param handler Callbacks for handling results and errors
|
|
534
|
-
* @param options Options for configuring watch behavior
|
|
407
|
+
* @param sql - The SQL query to execute
|
|
408
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
409
|
+
* @param handler - Callbacks for handling results and errors
|
|
410
|
+
* @param options - Options for configuring watch behavior
|
|
535
411
|
*/
|
|
536
412
|
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
537
413
|
/**
|
|
538
414
|
* Execute a read query every time the source tables are modified.
|
|
539
|
-
* Use {@link
|
|
415
|
+
* Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
|
|
540
416
|
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
|
|
541
417
|
*
|
|
542
|
-
* @param sql The SQL query to execute
|
|
543
|
-
* @param parameters Optional array of parameters to bind to the query
|
|
544
|
-
* @param options Options for configuring watch behavior
|
|
418
|
+
* @param sql - The SQL query to execute
|
|
419
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
420
|
+
* @param options - Options for configuring watch behavior
|
|
545
421
|
* @returns An AsyncIterable that yields QueryResults whenever the data changes
|
|
546
422
|
*/
|
|
547
423
|
watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
@@ -550,15 +426,15 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
550
426
|
* If tables are specified in the options, those are used directly.
|
|
551
427
|
* Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
|
|
552
428
|
*
|
|
553
|
-
* @param sql The SQL query to analyze
|
|
554
|
-
* @param parameters Optional parameters for the SQL query
|
|
555
|
-
* @param options Optional watch options that may contain explicit table list
|
|
429
|
+
* @param sql - The SQL query to analyze
|
|
430
|
+
* @param parameters - Optional parameters for the SQL query
|
|
431
|
+
* @param options - Optional watch options that may contain explicit table list
|
|
556
432
|
* @returns Array of table names that the query depends on
|
|
557
433
|
*/
|
|
558
434
|
resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]>;
|
|
559
435
|
/**
|
|
560
|
-
* This version of `onChange` uses
|
|
561
|
-
* Can be overloaded to use a callback handler instead, for documentation see {@link onChangeWithCallback}.
|
|
436
|
+
* This version of `onChange` uses `AsyncGenerator`, for documentation see {@link CommonPowerSyncDatabase.onChangeWithAsyncGenerator}.
|
|
437
|
+
* Can be overloaded to use a callback handler instead, for documentation see {@link CommonPowerSyncDatabase.onChangeWithCallback}.
|
|
562
438
|
*
|
|
563
439
|
* @example
|
|
564
440
|
* ```javascript
|
|
@@ -571,7 +447,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
571
447
|
*/
|
|
572
448
|
onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
573
449
|
/**
|
|
574
|
-
* See {@link onChangeWithCallback}.
|
|
450
|
+
* See {@link CommonPowerSyncDatabase.onChangeWithCallback}.
|
|
575
451
|
*
|
|
576
452
|
* @example
|
|
577
453
|
* ```javascript
|
|
@@ -588,32 +464,30 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
588
464
|
/**
|
|
589
465
|
* Invoke the provided callback on any changes to any of the specified tables.
|
|
590
466
|
*
|
|
591
|
-
* This is preferred over {@link watchWithCallback} when multiple queries need to be performed
|
|
467
|
+
* This is preferred over {@link CommonPowerSyncDatabase.watchWithCallback} when multiple queries need to be performed
|
|
592
468
|
* together when data is changed.
|
|
593
469
|
*
|
|
594
470
|
* Note that the `onChange` callback member of the handler is required.
|
|
595
471
|
*
|
|
596
|
-
* @param handler Callbacks for handling change events and errors
|
|
597
|
-
* @param options Options for configuring watch behavior
|
|
472
|
+
* @param handler - Callbacks for handling change events and errors
|
|
473
|
+
* @param options - Options for configuring watch behavior
|
|
598
474
|
* @returns A dispose function to stop watching for changes
|
|
599
475
|
*/
|
|
600
476
|
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
|
|
601
477
|
/**
|
|
602
478
|
* Create a Stream of changes to any of the specified tables.
|
|
603
479
|
*
|
|
604
|
-
* This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be
|
|
605
|
-
* together when data is changed.
|
|
480
|
+
* This is preferred over {@link CommonPowerSyncDatabase.watchWithAsyncGenerator} when multiple queries need to be
|
|
481
|
+
* performed together when data is changed.
|
|
606
482
|
*
|
|
607
483
|
* Note: do not declare this as `async *onChange` as it will not work in React Native.
|
|
608
484
|
*
|
|
609
|
-
* @param options Options for configuring watch behavior
|
|
485
|
+
* @param options - Options for configuring watch behavior
|
|
610
486
|
* @returns An AsyncIterable that yields change events whenever the specified tables change
|
|
611
487
|
*/
|
|
612
488
|
onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
613
|
-
private handleTableChanges;
|
|
614
|
-
private processTableUpdates;
|
|
615
489
|
/**
|
|
616
|
-
* @
|
|
490
|
+
* @internal
|
|
617
491
|
*/
|
|
618
|
-
|
|
492
|
+
createMutex(): Mutex;
|
|
619
493
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommonPowerSyncDatabase.js","sourceRoot":"","sources":["../../src/client/CommonPowerSyncDatabase.ts"],"names":[],"mappings":""}
|
package/lib/client/Query.d.ts
CHANGED
|
@@ -4,11 +4,15 @@ import { StandardWatchedQuery } from './watched/processors/OnChangeQueryProcesso
|
|
|
4
4
|
import { WatchedQueryOptions } from './watched/WatchedQuery.js';
|
|
5
5
|
/**
|
|
6
6
|
* Query parameters for {@link ArrayQueryDefinition#parameters}
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
10
|
export type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
|
|
9
11
|
/**
|
|
10
12
|
* Options for building a query with {@link AbstractPowerSyncDatabase#query}.
|
|
11
13
|
* This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
12
16
|
*/
|
|
13
17
|
export interface ArrayQueryDefinition<RowType = unknown> {
|
|
14
18
|
sql: string;
|
|
@@ -27,6 +31,8 @@ export interface ArrayQueryDefinition<RowType = unknown> {
|
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Options for {@link Query#watch}.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
30
36
|
*/
|
|
31
37
|
export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
|
|
32
38
|
/**
|
|
@@ -51,6 +57,9 @@ export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOption
|
|
|
51
57
|
*/
|
|
52
58
|
placeholderData?: RowType[];
|
|
53
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
54
63
|
export interface Query<RowType> {
|
|
55
64
|
/**
|
|
56
65
|
* Creates a {@link WatchedQuery} which watches and emits results of the linked query.
|