@powersync/shared-internals 0.0.0-tmp.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/LICENSE +201 -0
- package/README.md +5 -0
- package/dist/bundle.cjs +11787 -0
- package/dist/bundle.cjs.map +1 -0
- package/dist/bundle.mjs +11757 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/bundle.node.cjs +9418 -0
- package/dist/bundle.node.cjs.map +1 -0
- package/dist/bundle.node.mjs +9388 -0
- package/dist/bundle.node.mjs.map +1 -0
- package/dist/index.d.cts +1159 -0
- package/dist/websockets.mjs +7558 -0
- package/dist/websockets.mjs.map +1 -0
- package/dist/websockets.node.mjs +5189 -0
- package/dist/websockets.node.mjs.map +1 -0
- package/legacy/sync_protocol.d.ts +103 -0
- package/lib/client/BasePowerSyncDatabase.d.ts +147 -0
- package/lib/client/BasePowerSyncDatabase.js +622 -0
- package/lib/client/BasePowerSyncDatabase.js.map +1 -0
- package/lib/client/ConnectionManager.d.ts +116 -0
- package/lib/client/ConnectionManager.js +306 -0
- package/lib/client/ConnectionManager.js.map +1 -0
- package/lib/client/CustomQuery.d.ts +21 -0
- package/lib/client/CustomQuery.js +43 -0
- package/lib/client/CustomQuery.js.map +1 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +42 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js +23 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
- package/lib/client/sync/bucket/CrudEntry.d.ts +46 -0
- package/lib/client/sync/bucket/CrudEntry.js +60 -0
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +33 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js +166 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
- package/lib/client/sync/options.d.ts +9 -0
- package/lib/client/sync/options.js +16 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/stream/AbstractRemote.d.ts +125 -0
- package/lib/client/sync/stream/AbstractRemote.js +265 -0
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +138 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +611 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
- package/lib/client/sync/stream/WebSocketSupport.d.ts +26 -0
- package/lib/client/sync/stream/WebSocketSupport.js +198 -0
- package/lib/client/sync/stream/WebSocketSupport.js.map +1 -0
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js +62 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
- package/lib/client/sync/stream/core-instruction.d.ts +75 -0
- package/lib/client/sync/stream/core-instruction.js +4 -0
- package/lib/client/sync/stream/core-instruction.js.map +1 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
- package/lib/client/triggers/TriggerManagerImpl.d.ts +68 -0
- package/lib/client/triggers/TriggerManagerImpl.js +415 -0
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
- package/lib/client/watched/AbstractQueryProcessor.d.ts +68 -0
- package/lib/client/watched/AbstractQueryProcessor.js +155 -0
- package/lib/client/watched/AbstractQueryProcessor.js.map +1 -0
- package/lib/client/watched/DifferentialQueryProcessor.d.ts +50 -0
- package/lib/client/watched/DifferentialQueryProcessor.js +174 -0
- package/lib/client/watched/DifferentialQueryProcessor.js.map +1 -0
- package/lib/client/watched/OnChangeQueryProcessor.d.ts +22 -0
- package/lib/client/watched/OnChangeQueryProcessor.js +80 -0
- package/lib/client/watched/OnChangeQueryProcessor.js.map +1 -0
- package/lib/client/watched/WatchedQuery.d.ts +9 -0
- package/lib/client/watched/WatchedQuery.js +12 -0
- package/lib/client/watched/WatchedQuery.js.map +1 -0
- package/lib/constants.d.ts +5 -0
- package/lib/constants.js +6 -0
- package/lib/constants.js.map +1 -0
- package/lib/db/ConnectionClosedError.d.ts +12 -0
- package/lib/db/ConnectionClosedError.js +23 -0
- package/lib/db/ConnectionClosedError.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +10 -0
- package/lib/db/crud/SyncProgress.js +33 -0
- package/lib/db/crud/SyncProgress.js.map +1 -0
- package/lib/db/crud/SyncStatus.d.ts +48 -0
- package/lib/db/crud/SyncStatus.js +178 -0
- package/lib/db/crud/SyncStatus.js.map +1 -0
- package/lib/db/openDatabase.d.ts +7 -0
- package/lib/db/openDatabase.js +22 -0
- package/lib/db/openDatabase.js.map +1 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/AbortOperation.d.ts +11 -0
- package/lib/utils/AbortOperation.js +21 -0
- package/lib/utils/AbortOperation.js.map +1 -0
- package/lib/utils/ControlledExecutor.d.ts +31 -0
- package/lib/utils/ControlledExecutor.js +54 -0
- package/lib/utils/ControlledExecutor.js.map +1 -0
- package/lib/utils/MetaBaseObserver.d.ts +11 -0
- package/lib/utils/MetaBaseObserver.js +51 -0
- package/lib/utils/MetaBaseObserver.js.map +1 -0
- package/lib/utils/async.d.ts +46 -0
- package/lib/utils/async.js +147 -0
- package/lib/utils/async.js.map +1 -0
- 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 +42 -0
- package/lib/utils/mutex.js +150 -0
- package/lib/utils/mutex.js.map +1 -0
- package/lib/utils/parseQuery.d.ts +12 -0
- package/lib/utils/parseQuery.js +20 -0
- package/lib/utils/parseQuery.js.map +1 -0
- package/lib/utils/queue.d.ts +16 -0
- package/lib/utils/queue.js +42 -0
- package/lib/utils/queue.js.map +1 -0
- package/lib/utils/stream_transform.d.ts +41 -0
- package/lib/utils/stream_transform.js +211 -0
- package/lib/utils/stream_transform.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +4 -0
- package/lib/version.js.map +1 -0
- package/package.json +65 -0
- package/src/client/BasePowerSyncDatabase.ts +853 -0
- package/src/client/ConnectionManager.ts +419 -0
- package/src/client/CustomQuery.ts +60 -0
- package/src/client/sync/bucket/BucketStorageAdapter.ts +51 -0
- package/src/client/sync/bucket/CrudEntry.ts +116 -0
- package/src/client/sync/bucket/SqliteBucketStorage.ts +213 -0
- package/src/client/sync/options.ts +24 -0
- package/src/client/sync/stream/AbstractRemote.ts +369 -0
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +795 -0
- package/src/client/sync/stream/WebSocketSupport.ts +259 -0
- package/src/client/sync/stream/WebsocketClientTransport.ts +82 -0
- package/src/client/sync/stream/core-instruction.ts +78 -0
- package/src/client/triggers/MemoryTriggerClaimManager.ts +25 -0
- package/src/client/triggers/TriggerManagerImpl.ts +538 -0
- package/src/client/watched/AbstractQueryProcessor.ts +231 -0
- package/src/client/watched/DifferentialQueryProcessor.ts +226 -0
- package/src/client/watched/OnChangeQueryProcessor.ts +108 -0
- package/src/client/watched/WatchedQuery.ts +14 -0
- package/src/constants.ts +6 -0
- package/src/db/ConnectionClosedError.ts +25 -0
- package/src/db/crud/SyncProgress.ts +39 -0
- package/src/db/crud/SyncStatus.ts +234 -0
- package/src/db/openDatabase.ts +23 -0
- package/src/index.ts +24 -0
- package/src/utils/AbortOperation.ts +19 -0
- package/src/utils/ControlledExecutor.ts +78 -0
- package/src/utils/MetaBaseObserver.ts +65 -0
- package/src/utils/async.ts +185 -0
- package/src/utils/compatibility.ts +9 -0
- package/src/utils/mutex.ts +186 -0
- package/src/utils/parseQuery.ts +31 -0
- package/src/utils/queue.ts +48 -0
- package/src/utils/stream_transform.ts +260 -0
- package/src/version.ts +3 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
import * as _powersync_common from '@powersync/common';
|
|
2
|
+
import { BaseObserverInterface, BaseListener, Disposable, CrudEntry, CrudBatch, SyncStatus, SyncDataFlowStatus, SyncStreamStatus, SyncStreamDescription, SyncPriorityStatus as SyncPriorityStatus$1, SyncProgress, PowerSyncCredentials, PowerSyncLogger, FetchStrategy, SyncOptions, BaseObserver, PowerSyncBackendConnector, SyncStream, TriggerManager, Schema, LockContext, DiffTriggerOperation, CreateDiffTriggerOptions, TriggerRemoveCallbackOptions, TrackDiffOptions, TriggerRemoveCallback, BasePowerSyncDatabaseOptions, PowerSyncDBListener, CommonPowerSyncDatabase, DBAdapter, DisconnectAndClearOptions, PowerSyncCloseOptions, UploadQueueStats, CrudTransaction, QueryResult, Transaction, SQLWatchOptions, WatchHandler, ArrayQueryDefinition, Query, WatchCompatibleQuery, SQLOnChangeOptions, WatchOnChangeEvent, WatchOnChangeHandler, UpdateType, SQLOpenOptions, DatabaseSource, MetaBaseObserverInterface, ListenerCounts, ListenerMetaManager, MetaListener, WatchedQueryOptions, WatchedQueryListener, WatchedQuery, WatchedQueryState, DifferentialWatchedQueryComparator, DifferentialWatchedQuerySettings, DifferentialWatchedQuery, WatchedQueryDifferential, WatchedQuerySettings, WatchedQueryComparator, CompilableQuery } from '@powersync/common';
|
|
3
|
+
import { fetch } from 'cross-fetch';
|
|
4
|
+
|
|
5
|
+
declare enum PSInternalTable {
|
|
6
|
+
DATA = "ps_data",
|
|
7
|
+
CRUD = "ps_crud",
|
|
8
|
+
BUCKETS = "ps_buckets",
|
|
9
|
+
OPLOG = "ps_oplog",
|
|
10
|
+
UNTYPED = "ps_untyped"
|
|
11
|
+
}
|
|
12
|
+
declare enum PowerSyncControlCommand {
|
|
13
|
+
PROCESS_TEXT_LINE = "line_text",
|
|
14
|
+
PROCESS_BSON_LINE = "line_binary",
|
|
15
|
+
STOP = "stop",
|
|
16
|
+
START = "start",
|
|
17
|
+
NOTIFY_TOKEN_REFRESHED = "refreshed_token",
|
|
18
|
+
NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload",
|
|
19
|
+
UPDATE_SUBSCRIPTIONS = "update_subscriptions",
|
|
20
|
+
/**
|
|
21
|
+
* An `established` or `end` event for response streams.
|
|
22
|
+
*/
|
|
23
|
+
CONNECTION_STATE = "connection"
|
|
24
|
+
}
|
|
25
|
+
interface BucketStorageListener extends BaseListener {
|
|
26
|
+
crudUpdate: () => void;
|
|
27
|
+
}
|
|
28
|
+
interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
|
|
29
|
+
init(): Promise<void>;
|
|
30
|
+
hasMigratedSubkeys(): Promise<boolean>;
|
|
31
|
+
migrateToFixedSubkeys(): Promise<void>;
|
|
32
|
+
nextCrudItem(): Promise<CrudEntry | undefined>;
|
|
33
|
+
hasCrud(): Promise<boolean>;
|
|
34
|
+
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
35
|
+
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
|
|
36
|
+
getMaxOpId(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get an unique client id.
|
|
39
|
+
*/
|
|
40
|
+
getClientId(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Invokes the `powersync_control` function for the sync client.
|
|
43
|
+
*/
|
|
44
|
+
control(op: PowerSyncControlCommand, payload: string | Uint8Array | null): Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* An internal instruction emitted by the sync client in the core extension in response to the JS
|
|
49
|
+
* SDK passing sync data into the extension.
|
|
50
|
+
*/
|
|
51
|
+
type Instruction = InterruptingInstruction | NonInterruptingInstruction;
|
|
52
|
+
type InterruptingInstruction = {
|
|
53
|
+
EstablishSyncStream: EstablishSyncStream;
|
|
54
|
+
} | {
|
|
55
|
+
CloseSyncStream: {
|
|
56
|
+
hide_disconnect: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* An {@link Instruction} that doesn't start or stop a sync iteration.
|
|
61
|
+
*/
|
|
62
|
+
type NonInterruptingInstruction = {
|
|
63
|
+
LogLine: LogLine;
|
|
64
|
+
} | {
|
|
65
|
+
UpdateSyncStatus: UpdateSyncStatus;
|
|
66
|
+
} | {
|
|
67
|
+
FetchCredentials: FetchCredentials;
|
|
68
|
+
} | {
|
|
69
|
+
FlushFileSystem: any;
|
|
70
|
+
} | {
|
|
71
|
+
DidCompleteSync: any;
|
|
72
|
+
};
|
|
73
|
+
interface LogLine {
|
|
74
|
+
severity: 'DEBUG' | 'INFO' | 'WARNING';
|
|
75
|
+
line: string;
|
|
76
|
+
}
|
|
77
|
+
interface EstablishSyncStream {
|
|
78
|
+
request: unknown;
|
|
79
|
+
}
|
|
80
|
+
interface UpdateSyncStatus {
|
|
81
|
+
status: CoreSyncStatus;
|
|
82
|
+
}
|
|
83
|
+
interface CoreSyncStatus {
|
|
84
|
+
connected: boolean;
|
|
85
|
+
connecting: boolean;
|
|
86
|
+
priority_status: SyncPriorityStatus[];
|
|
87
|
+
downloading: DownloadProgress | null;
|
|
88
|
+
streams: CoreStreamSubscription[];
|
|
89
|
+
}
|
|
90
|
+
interface CoreStreamSubscription {
|
|
91
|
+
progress: {
|
|
92
|
+
total: number;
|
|
93
|
+
downloaded: number;
|
|
94
|
+
};
|
|
95
|
+
name: string;
|
|
96
|
+
parameters: any;
|
|
97
|
+
priority: number | null;
|
|
98
|
+
active: boolean;
|
|
99
|
+
is_default: boolean;
|
|
100
|
+
has_explicit_subscription: boolean;
|
|
101
|
+
expires_at: number | null;
|
|
102
|
+
last_synced_at: number | null;
|
|
103
|
+
}
|
|
104
|
+
interface SyncPriorityStatus {
|
|
105
|
+
priority: number;
|
|
106
|
+
last_synced_at: number | number;
|
|
107
|
+
has_synced: boolean | null;
|
|
108
|
+
}
|
|
109
|
+
interface DownloadProgress {
|
|
110
|
+
buckets: Record<string, BucketProgress>;
|
|
111
|
+
}
|
|
112
|
+
interface BucketProgress {
|
|
113
|
+
priority: number;
|
|
114
|
+
at_last: number;
|
|
115
|
+
since_last: number;
|
|
116
|
+
target_count: number;
|
|
117
|
+
}
|
|
118
|
+
interface FetchCredentials {
|
|
119
|
+
did_expire: boolean;
|
|
120
|
+
}
|
|
121
|
+
declare function isInterruptingInstruction(instruction: Instruction): instruction is InterruptingInstruction;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The {@link SyncStatus} subset not managed by the Rust client in {@link CoreSyncStatus}.
|
|
125
|
+
*
|
|
126
|
+
* This includes the upload state and JS errors.
|
|
127
|
+
*/
|
|
128
|
+
interface JavaScriptSyncState {
|
|
129
|
+
uploading?: boolean;
|
|
130
|
+
downloadError?: Error;
|
|
131
|
+
uploadError?: Error;
|
|
132
|
+
}
|
|
133
|
+
declare class SyncStatusSnapshot implements SyncStatus {
|
|
134
|
+
readonly core: CoreSyncStatus | null;
|
|
135
|
+
readonly jsState: JavaScriptSyncState;
|
|
136
|
+
constructor(core: CoreSyncStatus | null, jsState: JavaScriptSyncState);
|
|
137
|
+
get connected(): boolean;
|
|
138
|
+
get connecting(): boolean;
|
|
139
|
+
get downloading(): boolean;
|
|
140
|
+
get uploading(): boolean;
|
|
141
|
+
get downloadError(): Error | undefined;
|
|
142
|
+
get uploadError(): Error | undefined;
|
|
143
|
+
get dataFlowStatus(): SyncDataFlowStatus;
|
|
144
|
+
get lastSyncedAt(): Date | undefined;
|
|
145
|
+
get hasSynced(): boolean | undefined;
|
|
146
|
+
get syncStreams(): SyncStreamStatus[] | undefined;
|
|
147
|
+
forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
|
|
148
|
+
get priorityStatusEntries(): SyncPriorityStatus$1[] | undefined;
|
|
149
|
+
get downloadProgress(): SyncProgress | null;
|
|
150
|
+
statusForPriority(priority: number): SyncPriorityStatus$1 | undefined;
|
|
151
|
+
isEqual(status: SyncStatus): boolean;
|
|
152
|
+
getMessage(): string;
|
|
153
|
+
/**
|
|
154
|
+
* Serializes the SyncStatus instance to a plain object.
|
|
155
|
+
*
|
|
156
|
+
* @returns A plain object representation of the sync status
|
|
157
|
+
*/
|
|
158
|
+
toJSON(): SyncStatusJson;
|
|
159
|
+
/**
|
|
160
|
+
* Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
|
|
161
|
+
* This explicitly serializes errors in the SyncStatus.
|
|
162
|
+
*/
|
|
163
|
+
serializeError(error?: Error): Error | undefined;
|
|
164
|
+
}
|
|
165
|
+
interface SyncStatusJson {
|
|
166
|
+
core: CoreSyncStatus | null;
|
|
167
|
+
dataFlow: JavaScriptSyncState;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* An async iterator that can't be cancelled.
|
|
172
|
+
*
|
|
173
|
+
* To keep data flow simple, we always pass an explicit cancellation token when subscribing to async streams. Once the
|
|
174
|
+
* `AbortSignal` aborts, iterators are supposed to clean up and then emit a final `{done: true}` event. This means
|
|
175
|
+
* that there's no way to distinguish between streams that have completed normally and streams that have been cancelled,
|
|
176
|
+
* but that is acceptable for our uses of this.
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
type SimpleAsyncIterator<T> = Pick<AsyncIterator<T>, 'next'>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
type RemoteConnector = {
|
|
186
|
+
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
|
|
187
|
+
invalidateCredentials?: () => void;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
type SyncStreamOptions = {
|
|
193
|
+
path: string;
|
|
194
|
+
data: unknown;
|
|
195
|
+
headers?: Record<string, string>;
|
|
196
|
+
abortSignal: AbortSignal;
|
|
197
|
+
fetchOptions?: Request;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
type FetchImplementation = typeof fetch;
|
|
203
|
+
/**
|
|
204
|
+
* Class wrapper for providing a fetch implementation.
|
|
205
|
+
* The class wrapper is used to distinguish the fetchImplementation
|
|
206
|
+
* option in [AbstractRemoteOptions] from the general fetch method
|
|
207
|
+
* which is typeof "function"
|
|
208
|
+
*
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
declare class FetchImplementationProvider {
|
|
212
|
+
getFetch(): FetchImplementation;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @internal
|
|
216
|
+
*/
|
|
217
|
+
type AbstractRemoteOptions = {
|
|
218
|
+
/**
|
|
219
|
+
* Transforms the PowerSync base URL which might contain
|
|
220
|
+
* `http(s)://` to the corresponding WebSocket variant
|
|
221
|
+
* e.g. `ws(s)://`
|
|
222
|
+
*/
|
|
223
|
+
socketUrlTransformer: (url: string) => string;
|
|
224
|
+
/**
|
|
225
|
+
* Optionally provide the fetch implementation to use.
|
|
226
|
+
* Note that this usually needs to be bound to the global scope.
|
|
227
|
+
* Binding should be done before passing here.
|
|
228
|
+
*/
|
|
229
|
+
fetchImplementation: FetchImplementation | FetchImplementationProvider;
|
|
230
|
+
/**
|
|
231
|
+
* Optional options to pass directly to all `fetch` calls.
|
|
232
|
+
*
|
|
233
|
+
* This can include fields such as `dispatcher` (e.g. for proxy support),
|
|
234
|
+
* `cache`, or any other fetch-compatible options.
|
|
235
|
+
*/
|
|
236
|
+
fetchOptions?: {};
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* @internal
|
|
240
|
+
*/
|
|
241
|
+
interface SocketSyncStreamOptions {
|
|
242
|
+
path: string;
|
|
243
|
+
fetchStrategy: FetchStrategy;
|
|
244
|
+
abortSignal: AbortSignal;
|
|
245
|
+
data: unknown;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
|
|
251
|
+
/**
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
declare abstract class AbstractRemote {
|
|
255
|
+
protected connector: RemoteConnector;
|
|
256
|
+
protected logger: PowerSyncLogger;
|
|
257
|
+
protected credentials: PowerSyncCredentials | null;
|
|
258
|
+
protected options: AbstractRemoteOptions;
|
|
259
|
+
constructor(connector: RemoteConnector, logger: PowerSyncLogger, options?: Partial<AbstractRemoteOptions>);
|
|
260
|
+
/**
|
|
261
|
+
* @returns a fetch implementation (function)
|
|
262
|
+
* which can be called to perform fetch requests
|
|
263
|
+
*/
|
|
264
|
+
get fetch(): FetchImplementation;
|
|
265
|
+
/**
|
|
266
|
+
* Get credentials currently cached, or fetch new credentials if none are
|
|
267
|
+
* available.
|
|
268
|
+
*
|
|
269
|
+
* These credentials may have expired already.
|
|
270
|
+
*/
|
|
271
|
+
getCredentials(): Promise<PowerSyncCredentials | null>;
|
|
272
|
+
/**
|
|
273
|
+
* Fetch a new set of credentials and cache it.
|
|
274
|
+
*
|
|
275
|
+
* Until this call succeeds, `getCredentials` will still return the
|
|
276
|
+
* old credentials.
|
|
277
|
+
*
|
|
278
|
+
* This may be called before the current credentials have expired.
|
|
279
|
+
*/
|
|
280
|
+
prefetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
281
|
+
/**
|
|
282
|
+
* Get credentials for PowerSync.
|
|
283
|
+
*
|
|
284
|
+
* This should always fetch a fresh set of credentials - don't use cached
|
|
285
|
+
* values.
|
|
286
|
+
*/
|
|
287
|
+
fetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
288
|
+
/***
|
|
289
|
+
* Immediately invalidate credentials.
|
|
290
|
+
*
|
|
291
|
+
* This may be called when the current credentials have expired.
|
|
292
|
+
*/
|
|
293
|
+
invalidateCredentials(): void;
|
|
294
|
+
getUserAgent(): string;
|
|
295
|
+
protected buildRequest(path: string): Promise<{
|
|
296
|
+
url: string;
|
|
297
|
+
headers: {
|
|
298
|
+
'content-type': string;
|
|
299
|
+
Authorization: string;
|
|
300
|
+
'x-user-agent': string;
|
|
301
|
+
};
|
|
302
|
+
}>;
|
|
303
|
+
post(path: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
304
|
+
get(path: string, headers?: Record<string, string>): Promise<any>;
|
|
305
|
+
/**
|
|
306
|
+
* @returns A text decoder decoding UTF-8. This is a method to allow patching it for Hermes which doesn't support the
|
|
307
|
+
* builtin, without forcing us to bundle a polyfill with `@powersync/common`.
|
|
308
|
+
*/
|
|
309
|
+
createTextDecoder(): TextDecoder;
|
|
310
|
+
protected createSocket(url: string): WebSocket;
|
|
311
|
+
/**
|
|
312
|
+
* Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
|
|
313
|
+
*
|
|
314
|
+
* The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
|
|
315
|
+
*/
|
|
316
|
+
socketStreamRaw(options: SocketSyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array>>;
|
|
317
|
+
/**
|
|
318
|
+
* @returns Whether the HTTP implementation on this platform can receive streamed binary responses. This is true on
|
|
319
|
+
* all platforms except React Native (who would have guessed...), where we must not request BSON responses.
|
|
320
|
+
*
|
|
321
|
+
* @see https://github.com/react-native-community/fetch?tab=readme-ov-file#motivation
|
|
322
|
+
*/
|
|
323
|
+
protected get supportsStreamingBinaryResponses(): boolean;
|
|
324
|
+
/**
|
|
325
|
+
* Posts a `/sync/stream` request, asserts that it completes successfully and returns the streaming response as an
|
|
326
|
+
* async iterator of byte blobs.
|
|
327
|
+
*
|
|
328
|
+
* To cancel the async iterator, use the abort signal from {@link SyncStreamOptions} passed to this method.
|
|
329
|
+
*/
|
|
330
|
+
protected fetchStreamRaw(options: SyncStreamOptions): Promise<{
|
|
331
|
+
isBson: boolean;
|
|
332
|
+
stream: SimpleAsyncIterator<Uint8Array>;
|
|
333
|
+
}>;
|
|
334
|
+
/**
|
|
335
|
+
* Posts a `/sync/stream` request.
|
|
336
|
+
*
|
|
337
|
+
* Depending on the `Content-Type` of the response, this returns strings for sync lines or encoded BSON documents as
|
|
338
|
+
* `Uint8Array`s.
|
|
339
|
+
*/
|
|
340
|
+
fetchStream(options: SyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array | string>>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @internal
|
|
345
|
+
*/
|
|
346
|
+
type ResolvedSyncOptions = Required<SyncOptions>;
|
|
347
|
+
/**
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
350
|
+
declare function resolveSyncOptions(options: SyncOptions): ResolvedSyncOptions;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @internal
|
|
354
|
+
*/
|
|
355
|
+
declare enum LockType {
|
|
356
|
+
CRUD = "crud",
|
|
357
|
+
SYNC = "sync"
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Abstract Lock to be implemented by various JS environments
|
|
361
|
+
*
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
interface LockOptions<T> {
|
|
365
|
+
callback: () => Promise<T>;
|
|
366
|
+
type: LockType;
|
|
367
|
+
signal?: AbortSignal;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* @internal
|
|
371
|
+
*/
|
|
372
|
+
interface AbstractStreamingSyncImplementationOptions {
|
|
373
|
+
adapter: BucketStorageAdapter;
|
|
374
|
+
subscriptions: SubscribedStream[];
|
|
375
|
+
uploadCrud: () => Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* An identifier for which PowerSync DB this sync implementation is
|
|
378
|
+
* linked to. Most commonly DB name, but not restricted to DB name.
|
|
379
|
+
*/
|
|
380
|
+
identifier?: string;
|
|
381
|
+
logger: PowerSyncLogger;
|
|
382
|
+
remote: AbstractRemote;
|
|
383
|
+
/**
|
|
384
|
+
* The serialized schema - mainly used to forward information about raw tables to the sync client.
|
|
385
|
+
*/
|
|
386
|
+
serializedSchema: any;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
interface StreamingSyncImplementationListener extends BaseListener {
|
|
392
|
+
/**
|
|
393
|
+
* Triggers whenever the status' members have changed in value
|
|
394
|
+
*/
|
|
395
|
+
statusChanged?: ((status: SyncStatusSnapshot) => void) | undefined;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* @internal
|
|
399
|
+
*/
|
|
400
|
+
interface StreamingSyncImplementation extends BaseObserverInterface<StreamingSyncImplementationListener>, Disposable {
|
|
401
|
+
/**
|
|
402
|
+
* Connects to the sync service
|
|
403
|
+
*/
|
|
404
|
+
connect(options: ResolvedSyncOptions): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Disconnects from the sync services.
|
|
407
|
+
* @throws if not connected or if abort is not controlled internally
|
|
408
|
+
*/
|
|
409
|
+
disconnect(): Promise<void>;
|
|
410
|
+
getWriteCheckpoint: () => Promise<string>;
|
|
411
|
+
isConnected: boolean;
|
|
412
|
+
triggerCrudUpload: () => void;
|
|
413
|
+
waitForReady(): Promise<void>;
|
|
414
|
+
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
415
|
+
updateSubscriptions(subscriptions: SubscribedStream[]): void;
|
|
416
|
+
markConnectionMayHaveChanged(): void;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* @internal
|
|
420
|
+
*/
|
|
421
|
+
type SubscribedStream = {
|
|
422
|
+
name: string;
|
|
423
|
+
params: Record<string, any> | null;
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* @internal
|
|
427
|
+
*/
|
|
428
|
+
declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
|
|
429
|
+
protected options: AbstractStreamingSyncImplementationOptions;
|
|
430
|
+
protected abortController: AbortController | null;
|
|
431
|
+
protected crudUpdateListener?: () => void;
|
|
432
|
+
protected streamingSyncPromise?: Promise<[void, void]>;
|
|
433
|
+
protected logger: PowerSyncLogger;
|
|
434
|
+
private activeStreams;
|
|
435
|
+
private connectionMayHaveChanged;
|
|
436
|
+
private crudUploadNotifier;
|
|
437
|
+
private notifyCompletedUploads?;
|
|
438
|
+
private handleActiveStreamsChange?;
|
|
439
|
+
syncStatus: SyncStatusSnapshot;
|
|
440
|
+
constructor(options: AbstractStreamingSyncImplementationOptions);
|
|
441
|
+
triggerCrudUpload(): void;
|
|
442
|
+
waitForReady(): Promise<void>;
|
|
443
|
+
waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
|
|
444
|
+
get lastSyncedAt(): Date | undefined;
|
|
445
|
+
get isConnected(): boolean;
|
|
446
|
+
dispose(): Promise<void>;
|
|
447
|
+
abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
|
|
448
|
+
getWriteCheckpoint(): Promise<string>;
|
|
449
|
+
private crudUploadLoop;
|
|
450
|
+
private _uploadAllCrud;
|
|
451
|
+
connect(options: ResolvedSyncOptions): Promise<void>;
|
|
452
|
+
disconnect(): Promise<void>;
|
|
453
|
+
private markAsDisconnected;
|
|
454
|
+
private streamingSync;
|
|
455
|
+
markConnectionMayHaveChanged(): void;
|
|
456
|
+
/**
|
|
457
|
+
* Older versions of the JS SDK used to encode subkeys as JSON in `OplogEntry.toJSON`.
|
|
458
|
+
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
459
|
+
* While this is not a problem as long as it's done consistently, it causes issues when a database
|
|
460
|
+
* created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client
|
|
461
|
+
* is enabled.
|
|
462
|
+
*
|
|
463
|
+
* So, we add a migration from the old key format (with quotes) to the new one (no quotes). The
|
|
464
|
+
* migration is only triggered when necessary (for now). The function returns whether the new format
|
|
465
|
+
* should be used, so that the JS SDK is able to write to updated databases.
|
|
466
|
+
*
|
|
467
|
+
* @param requireFixedKeyFormat - Whether we require the new format or also support the old one.
|
|
468
|
+
* The Rust client requires the new subkey format.
|
|
469
|
+
* @returns Whether the database is now using the new, fixed subkey format.
|
|
470
|
+
*/
|
|
471
|
+
private requireKeyFormat;
|
|
472
|
+
protected streamingSyncIteration(signal: AbortSignal, options: ResolvedSyncOptions): Promise<RustIterationResult | null>;
|
|
473
|
+
private receiveSyncLines;
|
|
474
|
+
private rustSyncIteration;
|
|
475
|
+
protected updateSyncStatus(core: CoreSyncStatus | null, jsState?: JavaScriptSyncState): void;
|
|
476
|
+
protected updateJsSyncState(state: JavaScriptSyncState): void;
|
|
477
|
+
private delayRetry;
|
|
478
|
+
updateSubscriptions(subscriptions: SubscribedStream[]): void;
|
|
479
|
+
}
|
|
480
|
+
interface RustIterationResult {
|
|
481
|
+
immediateRestart: boolean;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @internal
|
|
486
|
+
*/
|
|
487
|
+
interface ConnectionManagerSyncImplementationResult {
|
|
488
|
+
sync: StreamingSyncImplementation;
|
|
489
|
+
/**
|
|
490
|
+
* Additional cleanup function which is called after the sync stream implementation
|
|
491
|
+
* is disposed.
|
|
492
|
+
*/
|
|
493
|
+
onDispose: () => Promise<void> | void;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* The subset of {@link AbstractStreamingSyncImplementationOptions} managed by the connection manager.
|
|
497
|
+
*
|
|
498
|
+
* @internal
|
|
499
|
+
*/
|
|
500
|
+
interface CreateSyncImplementationOptions {
|
|
501
|
+
subscriptions: SubscribedStream[];
|
|
502
|
+
serializedSchema: any;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* @internal
|
|
506
|
+
*/
|
|
507
|
+
interface InternalSubscriptionAdapter {
|
|
508
|
+
firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
|
|
509
|
+
resolveOfflineSyncStatus(): Promise<void>;
|
|
510
|
+
rustSubscriptionsCommand(payload: any): Promise<void>;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* @internal
|
|
514
|
+
*/
|
|
515
|
+
interface ConnectionManagerOptions {
|
|
516
|
+
createSyncImplementation(connector: PowerSyncBackendConnector, options: CreateSyncImplementationOptions): Promise<ConnectionManagerSyncImplementationResult>;
|
|
517
|
+
logger: PowerSyncLogger;
|
|
518
|
+
}
|
|
519
|
+
type StoredConnectionOptions = {
|
|
520
|
+
connector: PowerSyncBackendConnector;
|
|
521
|
+
options: ResolvedSyncOptions;
|
|
522
|
+
schema: any;
|
|
523
|
+
};
|
|
524
|
+
/**
|
|
525
|
+
* @internal
|
|
526
|
+
*/
|
|
527
|
+
interface ConnectionManagerListener extends BaseListener {
|
|
528
|
+
syncStreamCreated: (sync: StreamingSyncImplementation) => void;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* @internal
|
|
532
|
+
*/
|
|
533
|
+
declare class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
|
|
534
|
+
protected options: ConnectionManagerOptions;
|
|
535
|
+
/**
|
|
536
|
+
* Tracks active connection attempts
|
|
537
|
+
*/
|
|
538
|
+
protected connectingPromise: Promise<void> | null;
|
|
539
|
+
/**
|
|
540
|
+
* Tracks actively instantiating a streaming sync implementation.
|
|
541
|
+
*/
|
|
542
|
+
protected syncStreamInitPromise: Promise<void> | null;
|
|
543
|
+
/**
|
|
544
|
+
* Active disconnect operation. Calling disconnect multiple times
|
|
545
|
+
* will resolve to the same operation.
|
|
546
|
+
*/
|
|
547
|
+
protected disconnectingPromise: Promise<void> | null;
|
|
548
|
+
/**
|
|
549
|
+
* Tracks the last parameters supplied to `connect` calls.
|
|
550
|
+
* Calling `connect` multiple times in succession will result in:
|
|
551
|
+
* - 1 pending connection operation which will be aborted.
|
|
552
|
+
* - updating the last set of parameters while waiting for the pending
|
|
553
|
+
* attempt to be aborted
|
|
554
|
+
* - internally connecting with the last set of parameters
|
|
555
|
+
*/
|
|
556
|
+
protected pendingConnectionOptions: StoredConnectionOptions | null;
|
|
557
|
+
private currentOptions;
|
|
558
|
+
syncStreamImplementation: StreamingSyncImplementation | null;
|
|
559
|
+
/**
|
|
560
|
+
* Additional cleanup function which is called after the sync stream implementation
|
|
561
|
+
* is disposed.
|
|
562
|
+
*/
|
|
563
|
+
protected syncDisposer: (() => Promise<void> | void) | null;
|
|
564
|
+
/**
|
|
565
|
+
* Subscriptions managed in this connection manager.
|
|
566
|
+
*
|
|
567
|
+
* On the web, these local subscriptions are merged across tabs by a shared worker.
|
|
568
|
+
*/
|
|
569
|
+
private locallyActiveSubscriptions;
|
|
570
|
+
constructor(options: ConnectionManagerOptions);
|
|
571
|
+
get connector(): PowerSyncBackendConnector | null;
|
|
572
|
+
get connectionOptions(): Required<SyncOptions> | null;
|
|
573
|
+
get logger(): PowerSyncLogger;
|
|
574
|
+
close(): Promise<void>;
|
|
575
|
+
connect(connector: PowerSyncBackendConnector, options: SyncOptions, serializedSchema: any): Promise<void>;
|
|
576
|
+
protected connectInternal(): Promise<void>;
|
|
577
|
+
/**
|
|
578
|
+
* Close the sync connection.
|
|
579
|
+
*
|
|
580
|
+
* Use {@link ConnectionManager.connect} to connect again.
|
|
581
|
+
*/
|
|
582
|
+
disconnect(): Promise<void>;
|
|
583
|
+
protected disconnectInternal(): Promise<void>;
|
|
584
|
+
protected performDisconnect(): Promise<void>;
|
|
585
|
+
stream(adapter: InternalSubscriptionAdapter, name: string, parameters: Record<string, any> | null): SyncStream;
|
|
586
|
+
/**
|
|
587
|
+
* @internal exposed for testing
|
|
588
|
+
*/
|
|
589
|
+
get activeStreams(): {
|
|
590
|
+
name: string;
|
|
591
|
+
params: Record<string, any> | null;
|
|
592
|
+
}[];
|
|
593
|
+
private subscriptionsMayHaveChanged;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
type UnlockFn = () => void;
|
|
597
|
+
/**
|
|
598
|
+
* An asynchronous semaphore implementation with associated items per lease.
|
|
599
|
+
*/
|
|
600
|
+
declare class Semaphore<T> {
|
|
601
|
+
private readonly available;
|
|
602
|
+
readonly size: number;
|
|
603
|
+
private firstWaiter?;
|
|
604
|
+
private lastWaiter?;
|
|
605
|
+
constructor(elements: Iterable<T>);
|
|
606
|
+
private addWaiter;
|
|
607
|
+
private deactivateWaiter;
|
|
608
|
+
private requestPermits;
|
|
609
|
+
/**
|
|
610
|
+
* Requests a single item from the pool.
|
|
611
|
+
*
|
|
612
|
+
* The returned `release` callback must be invoked to return the item into the pool.
|
|
613
|
+
*/
|
|
614
|
+
requestOne(abort?: AbortSignal): Promise<{
|
|
615
|
+
item: T;
|
|
616
|
+
release: UnlockFn;
|
|
617
|
+
}>;
|
|
618
|
+
/**
|
|
619
|
+
* Requests access to all items from the pool.
|
|
620
|
+
*
|
|
621
|
+
* The returned `release` callback must be invoked to return items into the pool.
|
|
622
|
+
*/
|
|
623
|
+
requestAll(abort?: AbortSignal): Promise<{
|
|
624
|
+
items: T[];
|
|
625
|
+
release: UnlockFn;
|
|
626
|
+
}>;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* An asynchronous mutex implementation.
|
|
630
|
+
*/
|
|
631
|
+
declare class Mutex {
|
|
632
|
+
private inner;
|
|
633
|
+
acquire(abort?: AbortSignal): Promise<UnlockFn>;
|
|
634
|
+
runExclusive<T>(fn: () => PromiseLike<T> | T, abort?: AbortSignal): Promise<T>;
|
|
635
|
+
}
|
|
636
|
+
declare function timeoutSignal(timeout: number): AbortSignal;
|
|
637
|
+
declare function timeoutSignal(timeout?: number): AbortSignal | undefined;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* @experimental
|
|
641
|
+
* @internal
|
|
642
|
+
*/
|
|
643
|
+
interface TriggerManagerConfig {
|
|
644
|
+
claimManager: TriggerClaimManager;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* @experimental
|
|
648
|
+
* Manages claims on persisted SQLite triggers and destination tables to enable proper cleanup
|
|
649
|
+
* when they are no longer actively in use.
|
|
650
|
+
*
|
|
651
|
+
* When using persisted triggers (especially for OPFS multi-tab scenarios), we need a reliable way to determine which resources are still actively in use across different connections/tabs so stale resources can be safely cleaned up without interfering with active triggers.
|
|
652
|
+
*
|
|
653
|
+
* A cleanup process runs
|
|
654
|
+
* on database creation (and every 2 minutes) that:
|
|
655
|
+
* 1. Queries for existing managed persisted resources
|
|
656
|
+
* 2. Checks with the claim manager if any consumer is actively using those resources
|
|
657
|
+
* 3. Deletes unused resources
|
|
658
|
+
*/
|
|
659
|
+
interface TriggerClaimManager {
|
|
660
|
+
/**
|
|
661
|
+
* Obtains or marks a claim on a certain identifier.
|
|
662
|
+
* @returns a callback to release the claim.
|
|
663
|
+
*/
|
|
664
|
+
obtainClaim: (identifier: string) => Promise<() => Promise<void>>;
|
|
665
|
+
/**
|
|
666
|
+
* Checks if a claim is present for an identifier.
|
|
667
|
+
*/
|
|
668
|
+
checkClaim: (identifier: string) => Promise<boolean>;
|
|
669
|
+
}
|
|
670
|
+
type TriggerManagerImplOptions = TriggerManagerConfig & {
|
|
671
|
+
db: BasePowerSyncDatabase;
|
|
672
|
+
schema: Schema;
|
|
673
|
+
};
|
|
674
|
+
type TriggerManagerImplConfiguration = {
|
|
675
|
+
useStorageByDefault: boolean;
|
|
676
|
+
};
|
|
677
|
+
declare const DEFAULT_TRIGGER_MANAGER_CONFIGURATION: TriggerManagerImplConfiguration;
|
|
678
|
+
/**
|
|
679
|
+
* @internal
|
|
680
|
+
* @experimental
|
|
681
|
+
*/
|
|
682
|
+
declare class TriggerManagerImpl implements TriggerManager {
|
|
683
|
+
protected options: TriggerManagerImplOptions;
|
|
684
|
+
protected schema: Schema;
|
|
685
|
+
protected defaultConfig: TriggerManagerImplConfiguration;
|
|
686
|
+
protected cleanupTimeout: ReturnType<typeof setTimeout> | null;
|
|
687
|
+
protected isDisposed: boolean;
|
|
688
|
+
constructor(options: TriggerManagerImplOptions);
|
|
689
|
+
protected get db(): BasePowerSyncDatabase<_powersync_common.BasePowerSyncDatabaseOptions>;
|
|
690
|
+
protected getUUID(ctx?: LockContext): Promise<string>;
|
|
691
|
+
protected removeTriggers(tx: LockContext, triggerIds: string[]): Promise<void>;
|
|
692
|
+
dispose(): void;
|
|
693
|
+
/**
|
|
694
|
+
* Updates default config settings for platform specific use-cases.
|
|
695
|
+
*/
|
|
696
|
+
updateDefaults(config: TriggerManagerImplConfiguration): void;
|
|
697
|
+
protected generateTriggerName(operation: DiffTriggerOperation, destinationTable: string, triggerId: string): string;
|
|
698
|
+
/**
|
|
699
|
+
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
700
|
+
*/
|
|
701
|
+
cleanupResources(): Promise<void>;
|
|
702
|
+
createDiffTrigger(options: CreateDiffTriggerOptions): Promise<(options?: TriggerRemoveCallbackOptions) => Promise<void>>;
|
|
703
|
+
trackTableDiff(options: TrackDiffOptions): Promise<TriggerRemoveCallback>;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* @internal
|
|
708
|
+
*/
|
|
709
|
+
declare const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions;
|
|
710
|
+
/**
|
|
711
|
+
* Requesting nested or recursive locks can block the application in some circumstances.
|
|
712
|
+
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
713
|
+
* be obtained.
|
|
714
|
+
*
|
|
715
|
+
* @internal
|
|
716
|
+
*/
|
|
717
|
+
declare const DEFAULT_LOCK_TIMEOUT_MS = 120000;
|
|
718
|
+
declare abstract class BasePowerSyncDatabase<Options extends BasePowerSyncDatabaseOptions = BasePowerSyncDatabaseOptions> extends BaseObserver<PowerSyncDBListener> implements CommonPowerSyncDatabase {
|
|
719
|
+
protected options: Options;
|
|
720
|
+
closed: boolean;
|
|
721
|
+
ready: boolean;
|
|
722
|
+
currentStatus: SyncStatusSnapshot;
|
|
723
|
+
sdkVersion: string;
|
|
724
|
+
protected bucketStorageAdapter: BucketStorageAdapter;
|
|
725
|
+
protected _isReadyPromise: Promise<void>;
|
|
726
|
+
protected connectionManager: ConnectionManager;
|
|
727
|
+
private subscriptions;
|
|
728
|
+
get syncStreamImplementation(): StreamingSyncImplementation | null;
|
|
729
|
+
/**
|
|
730
|
+
* The connector used to connect to the PowerSync service.
|
|
731
|
+
*
|
|
732
|
+
* @returns The connector used to connect to the PowerSync service or null if `connect()` has not been called.
|
|
733
|
+
*/
|
|
734
|
+
get connector(): PowerSyncBackendConnector | null;
|
|
735
|
+
/**
|
|
736
|
+
* The resolved connection options used to connect to the PowerSync service.
|
|
737
|
+
*
|
|
738
|
+
* @returns The resolved connection options used to connect to the PowerSync service or null if `connect()` has not been called.
|
|
739
|
+
*/
|
|
740
|
+
get connectionOptions(): Required<SyncOptions> | null;
|
|
741
|
+
protected _schema: Schema;
|
|
742
|
+
private _database;
|
|
743
|
+
protected runExclusiveMutex: Mutex;
|
|
744
|
+
/**
|
|
745
|
+
* @experimental
|
|
746
|
+
* Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
|
|
747
|
+
*/
|
|
748
|
+
readonly triggers: TriggerManager;
|
|
749
|
+
protected triggersImpl: TriggerManagerImpl;
|
|
750
|
+
logger: PowerSyncLogger;
|
|
751
|
+
constructor(options: Options);
|
|
752
|
+
get schema(): Schema<{
|
|
753
|
+
[x: string]: _powersync_common.Table<any>;
|
|
754
|
+
}>;
|
|
755
|
+
/**
|
|
756
|
+
* The underlying database.
|
|
757
|
+
*
|
|
758
|
+
* For the most part, behavior is the same whether querying on the underlying database, or on {@link AbstractPowerSyncDatabase}.
|
|
759
|
+
*/
|
|
760
|
+
get database(): DBAdapter;
|
|
761
|
+
/**
|
|
762
|
+
* Whether a connection to the PowerSync service is currently open.
|
|
763
|
+
*/
|
|
764
|
+
get connected(): boolean;
|
|
765
|
+
get connecting(): boolean;
|
|
766
|
+
/**
|
|
767
|
+
* Opens the DBAdapter given open options using a default open factory
|
|
768
|
+
*/
|
|
769
|
+
protected abstract openDBAdapter(): DBAdapter;
|
|
770
|
+
/**
|
|
771
|
+
* Generates a base configuration for {@link TriggerManagerImpl}.
|
|
772
|
+
* Implementations should override this if necessary.
|
|
773
|
+
*/
|
|
774
|
+
protected generateTriggerManagerConfig(): TriggerManagerConfig;
|
|
775
|
+
protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: CreateSyncImplementationOptions): StreamingSyncImplementation;
|
|
776
|
+
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
|
|
777
|
+
waitForReady(): Promise<void>;
|
|
778
|
+
waitForFirstSync(request?: AbortSignal | {
|
|
779
|
+
signal?: AbortSignal;
|
|
780
|
+
priority?: number;
|
|
781
|
+
}): Promise<void>;
|
|
782
|
+
waitForStatus(predicate: (status: SyncStatus) => any, signal?: AbortSignal): Promise<void>;
|
|
783
|
+
/**
|
|
784
|
+
* Allows for extended implementations to execute custom initialization
|
|
785
|
+
* logic as part of the total init process
|
|
786
|
+
*/
|
|
787
|
+
protected abstract _initialize(): Promise<void>;
|
|
788
|
+
/**
|
|
789
|
+
* Entry point for executing initialization logic.
|
|
790
|
+
* This is to be automatically executed in the constructor.
|
|
791
|
+
*/
|
|
792
|
+
protected initialize(): Promise<void>;
|
|
793
|
+
protected loadVersion(): Promise<void>;
|
|
794
|
+
protected resolveOfflineSyncStatus(): Promise<void>;
|
|
795
|
+
updateSchema(schema: Schema): Promise<void>;
|
|
796
|
+
init(): Promise<void>;
|
|
797
|
+
/**
|
|
798
|
+
* @deprecated Use {@link AbstractPowerSyncDatabase#close} instead.
|
|
799
|
+
* Clears all listeners registered by {@link AbstractPowerSyncDatabase#registerListener}.
|
|
800
|
+
*/
|
|
801
|
+
dispose(): void;
|
|
802
|
+
/**
|
|
803
|
+
* Locking mechanism for exclusively running critical portions of connect/disconnect operations.
|
|
804
|
+
* Locking here is mostly only important on web for multiple tab scenarios.
|
|
805
|
+
*/
|
|
806
|
+
protected runExclusive<T>(callback: () => Promise<T>): Promise<T>;
|
|
807
|
+
connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
|
|
808
|
+
disconnect(): Promise<void>;
|
|
809
|
+
disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
|
|
810
|
+
syncStream(name: string, params?: Record<string, any>): SyncStream;
|
|
811
|
+
close(options?: PowerSyncCloseOptions): Promise<void>;
|
|
812
|
+
getUploadQueueStats(includeSize?: boolean): Promise<UploadQueueStats>;
|
|
813
|
+
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
814
|
+
getNextCrudTransaction(): Promise<CrudTransaction | null>;
|
|
815
|
+
getCrudTransactions(): AsyncIterable<CrudTransaction, null>;
|
|
816
|
+
getClientId(): Promise<string>;
|
|
817
|
+
private handleCrudCheckpoint;
|
|
818
|
+
execute(sql: string, parameters?: any[]): Promise<QueryResult>;
|
|
819
|
+
executeRaw(sql: string, parameters?: any[]): Promise<any[][]>;
|
|
820
|
+
executeBatch(sql: string, parameters?: any[][]): Promise<QueryResult>;
|
|
821
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
822
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
823
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
824
|
+
readLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
825
|
+
writeLock<T>(callback: (db: LockContext) => Promise<T>): Promise<T>;
|
|
826
|
+
readTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
|
|
827
|
+
writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
|
|
828
|
+
watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
829
|
+
watch(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
830
|
+
query<RowType>(query: ArrayQueryDefinition<RowType>): Query<RowType>;
|
|
831
|
+
customQuery<RowType>(query: WatchCompatibleQuery<RowType[]>): Query<RowType>;
|
|
832
|
+
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
833
|
+
watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
|
|
834
|
+
resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]>;
|
|
835
|
+
onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
836
|
+
onChange(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
|
|
837
|
+
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
|
|
838
|
+
onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent>;
|
|
839
|
+
createMutex(): Mutex;
|
|
840
|
+
private handleTableChanges;
|
|
841
|
+
private processTableUpdates;
|
|
842
|
+
private executeReadOnly;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* @internal
|
|
847
|
+
*/
|
|
848
|
+
type CrudEntryJSON = {
|
|
849
|
+
id: string;
|
|
850
|
+
data: string;
|
|
851
|
+
tx_id?: number;
|
|
852
|
+
};
|
|
853
|
+
/**
|
|
854
|
+
* The output JSON seems to be a third type of JSON, not the same as the input JSON.
|
|
855
|
+
*/
|
|
856
|
+
type CrudEntryOutputJSON = {
|
|
857
|
+
op_id: number;
|
|
858
|
+
op: UpdateType;
|
|
859
|
+
type: string;
|
|
860
|
+
id: string;
|
|
861
|
+
tx_id?: number;
|
|
862
|
+
data?: Record<string, any>;
|
|
863
|
+
old?: Record<string, any>;
|
|
864
|
+
metadata?: string;
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* A single client-side change.
|
|
868
|
+
*
|
|
869
|
+
* @public
|
|
870
|
+
*/
|
|
871
|
+
declare class CrudEntryImpl implements CrudEntry {
|
|
872
|
+
clientId: number;
|
|
873
|
+
id: string;
|
|
874
|
+
op: UpdateType;
|
|
875
|
+
opData?: Record<string, any>;
|
|
876
|
+
previousValues?: Record<string, any>;
|
|
877
|
+
table: string;
|
|
878
|
+
transactionId?: number;
|
|
879
|
+
metadata?: string;
|
|
880
|
+
static fromRow(dbRow: CrudEntryJSON): CrudEntry;
|
|
881
|
+
constructor(clientId: number, op: UpdateType, table: string, id: string, transactionId?: number, opData?: Record<string, any>, previousValues?: Record<string, any>, metadata?: string);
|
|
882
|
+
toJSON(): CrudEntryOutputJSON;
|
|
883
|
+
equals(entry: CrudEntry): boolean;
|
|
884
|
+
/**
|
|
885
|
+
* Generates an array for use in deep comparison operations
|
|
886
|
+
*/
|
|
887
|
+
toComparisonArray(): unknown[];
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* @internal
|
|
892
|
+
*/
|
|
893
|
+
declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
|
|
894
|
+
private db;
|
|
895
|
+
private logger;
|
|
896
|
+
tableNames: Set<string>;
|
|
897
|
+
private updateListener;
|
|
898
|
+
private _clientId?;
|
|
899
|
+
constructor(db: DBAdapter, logger: PowerSyncLogger);
|
|
900
|
+
init(): Promise<void>;
|
|
901
|
+
dispose(): Promise<void>;
|
|
902
|
+
_getClientId(): Promise<string>;
|
|
903
|
+
getClientId(): Promise<string>;
|
|
904
|
+
getMaxOpId(): string;
|
|
905
|
+
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
|
|
906
|
+
nextCrudItem(): Promise<CrudEntry | undefined>;
|
|
907
|
+
hasCrud(): Promise<boolean>;
|
|
908
|
+
/**
|
|
909
|
+
* Get a batch of objects to send to the server.
|
|
910
|
+
* When the objects are successfully sent to the server, call .complete()
|
|
911
|
+
*/
|
|
912
|
+
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
913
|
+
writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, options?: {
|
|
914
|
+
timeoutMs: number;
|
|
915
|
+
}): Promise<T>;
|
|
916
|
+
control(op: PowerSyncControlCommand, payload: string | Uint8Array | ArrayBuffer | null): Promise<string>;
|
|
917
|
+
hasMigratedSubkeys(): Promise<boolean>;
|
|
918
|
+
migrateToFixedSubkeys(): Promise<void>;
|
|
919
|
+
static _subkeyMigrationKey: string;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Thrown when an underlying database connection is closed.
|
|
924
|
+
* This is particularly relevant when worker connections are marked as closed while
|
|
925
|
+
* operations are still in progress.
|
|
926
|
+
*
|
|
927
|
+
* @internal
|
|
928
|
+
*/
|
|
929
|
+
declare class ConnectionClosedError extends Error {
|
|
930
|
+
static NAME: string;
|
|
931
|
+
static MATCHES(input: any): boolean;
|
|
932
|
+
constructor(message: string);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Internal helper to turn a {@link DatabaseSource} into an opened {@link DBAdapter}.
|
|
937
|
+
*
|
|
938
|
+
* @internal
|
|
939
|
+
*/
|
|
940
|
+
declare function openDatabase<T extends SQLOpenOptions>(source: DatabaseSource<T>, defaultFactory: (options: T) => DBAdapter): DBAdapter;
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* @internal
|
|
944
|
+
* @experimental
|
|
945
|
+
*/
|
|
946
|
+
declare const MEMORY_TRIGGER_CLAIM_MANAGER: TriggerClaimManager;
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* A BaseObserver that tracks the counts of listeners for each event type.
|
|
950
|
+
*/
|
|
951
|
+
declare class MetaBaseObserver<Listener extends BaseListener> extends BaseObserver<Listener> implements MetaBaseObserverInterface<Listener> {
|
|
952
|
+
protected get listenerCounts(): ListenerCounts<Listener>;
|
|
953
|
+
get listenerMeta(): ListenerMetaManager<Listener>;
|
|
954
|
+
protected metaListener: BaseObserver<MetaListener<Listener>>;
|
|
955
|
+
constructor();
|
|
956
|
+
registerListener(listener: Partial<Listener>): () => void;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* @internal
|
|
961
|
+
*/
|
|
962
|
+
interface AbstractQueryProcessorOptions<Data, Settings extends WatchedQueryOptions = WatchedQueryOptions> {
|
|
963
|
+
db: BasePowerSyncDatabase;
|
|
964
|
+
watchOptions: Settings;
|
|
965
|
+
placeholderData: Data;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* @internal
|
|
969
|
+
*/
|
|
970
|
+
interface LinkQueryOptions<Data, Settings extends WatchedQueryOptions = WatchedQueryOptions> {
|
|
971
|
+
abortSignal: AbortSignal;
|
|
972
|
+
settings: Settings;
|
|
973
|
+
}
|
|
974
|
+
type MutableDeep<T> = T extends ReadonlyArray<infer U> ? U[] : T;
|
|
975
|
+
/**
|
|
976
|
+
* @internal Mutable version of {@link WatchedQueryState}.
|
|
977
|
+
* This is used internally to allow updates to the state.
|
|
978
|
+
*/
|
|
979
|
+
type MutableWatchedQueryState<Data> = {
|
|
980
|
+
-readonly [P in keyof WatchedQueryState<Data>]: MutableDeep<WatchedQueryState<Data>[P]>;
|
|
981
|
+
};
|
|
982
|
+
type WatchedQueryProcessorListener<Data> = WatchedQueryListener<Data>;
|
|
983
|
+
/**
|
|
984
|
+
* Performs underlying watching and yields a stream of results.
|
|
985
|
+
* @internal
|
|
986
|
+
*/
|
|
987
|
+
declare abstract class AbstractQueryProcessor<Data = unknown[], Settings extends WatchedQueryOptions = WatchedQueryOptions> extends MetaBaseObserver<WatchedQueryProcessorListener<Data>> implements WatchedQuery<Data, Settings> {
|
|
988
|
+
protected options: AbstractQueryProcessorOptions<Data, Settings>;
|
|
989
|
+
readonly state: WatchedQueryState<Data>;
|
|
990
|
+
protected abortController: AbortController;
|
|
991
|
+
protected initialized: Promise<void>;
|
|
992
|
+
protected _closed: boolean;
|
|
993
|
+
protected disposeListeners: (() => void) | null;
|
|
994
|
+
get closed(): boolean;
|
|
995
|
+
constructor(options: AbstractQueryProcessorOptions<Data, Settings>);
|
|
996
|
+
protected constructInitialState(): WatchedQueryState<Data>;
|
|
997
|
+
protected get reportFetching(): boolean;
|
|
998
|
+
protected updateSettingsInternal(settings: Settings, signal: AbortSignal): Promise<void>;
|
|
999
|
+
/**
|
|
1000
|
+
* Updates the underlying query.
|
|
1001
|
+
*/
|
|
1002
|
+
updateSettings(settings: Settings): Promise<void>;
|
|
1003
|
+
/**
|
|
1004
|
+
* This method is used to link a query to the subscribers of this listener class.
|
|
1005
|
+
* This method should perform actual query watching and report results via {@link AbstractQueryProcessor.updateState} method.
|
|
1006
|
+
*/
|
|
1007
|
+
protected abstract linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
|
|
1008
|
+
protected updateState(update: Partial<MutableWatchedQueryState<Data>>): Promise<void>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Configures base DB listeners and links the query to listeners.
|
|
1011
|
+
*/
|
|
1012
|
+
protected init(signal: AbortSignal): Promise<void>;
|
|
1013
|
+
close(): Promise<void>;
|
|
1014
|
+
/**
|
|
1015
|
+
* Runs a callback and reports errors to the error listeners.
|
|
1016
|
+
*/
|
|
1017
|
+
protected runWithReporting<T>(callback: () => Promise<T>): Promise<void>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Iterate listeners and reports errors to onError handlers.
|
|
1020
|
+
*/
|
|
1021
|
+
protected iterateAsyncListenersWithError(callback: (listener: Partial<WatchedQueryProcessorListener<Data>>) => Promise<void> | void): Promise<void>;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* @internal
|
|
1026
|
+
*/
|
|
1027
|
+
interface DifferentialQueryProcessorOptions<RowType> extends AbstractQueryProcessorOptions<RowType[], DifferentialWatchedQuerySettings<RowType>> {
|
|
1028
|
+
rowComparator?: DifferentialWatchedQueryComparator<RowType>;
|
|
1029
|
+
}
|
|
1030
|
+
type DataHashMap<RowType> = Map<string, {
|
|
1031
|
+
hash: string;
|
|
1032
|
+
item: RowType;
|
|
1033
|
+
}>;
|
|
1034
|
+
/**
|
|
1035
|
+
* An empty differential result set.
|
|
1036
|
+
* This is used as the initial state for differential incrementally watched queries.
|
|
1037
|
+
*
|
|
1038
|
+
* @internal
|
|
1039
|
+
*/
|
|
1040
|
+
declare const EMPTY_DIFFERENTIAL: {
|
|
1041
|
+
added: never[];
|
|
1042
|
+
all: never[];
|
|
1043
|
+
removed: never[];
|
|
1044
|
+
updated: never[];
|
|
1045
|
+
unchanged: never[];
|
|
1046
|
+
};
|
|
1047
|
+
/**
|
|
1048
|
+
* Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
|
|
1049
|
+
* It keys items by their `id` property if available, alternatively it uses JSON stringification
|
|
1050
|
+
* of the entire item for the key and comparison.
|
|
1051
|
+
*
|
|
1052
|
+
* @internal
|
|
1053
|
+
*/
|
|
1054
|
+
declare const DEFAULT_ROW_COMPARATOR: DifferentialWatchedQueryComparator<any>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Uses the PowerSync onChange event to trigger watched queries.
|
|
1057
|
+
* Results are emitted on every change of the relevant tables.
|
|
1058
|
+
* @internal
|
|
1059
|
+
*/
|
|
1060
|
+
declare class DifferentialQueryProcessor<RowType> extends AbstractQueryProcessor<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>> implements DifferentialWatchedQuery<RowType> {
|
|
1061
|
+
protected options: DifferentialQueryProcessorOptions<RowType>;
|
|
1062
|
+
protected comparator: DifferentialWatchedQueryComparator<RowType>;
|
|
1063
|
+
constructor(options: DifferentialQueryProcessorOptions<RowType>);
|
|
1064
|
+
protected differentiate(current: RowType[], previousMap: DataHashMap<RowType>): {
|
|
1065
|
+
diff: WatchedQueryDifferential<RowType>;
|
|
1066
|
+
map: DataHashMap<RowType>;
|
|
1067
|
+
hasChanged: boolean;
|
|
1068
|
+
};
|
|
1069
|
+
protected linkQuery(options: LinkQueryOptions<WatchedQueryDifferential<RowType>>): Promise<void>;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* @internal
|
|
1074
|
+
*/
|
|
1075
|
+
interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
|
|
1076
|
+
comparator?: WatchedQueryComparator<Data>;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Uses the PowerSync onChange event to trigger watched queries.
|
|
1080
|
+
* Results are emitted on every change of the relevant tables.
|
|
1081
|
+
* @internal
|
|
1082
|
+
*/
|
|
1083
|
+
declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
|
|
1084
|
+
protected options: OnChangeQueryProcessorOptions<Data>;
|
|
1085
|
+
constructor(options: OnChangeQueryProcessorOptions<Data>);
|
|
1086
|
+
/**
|
|
1087
|
+
* @returns If the sets are equal
|
|
1088
|
+
*/
|
|
1089
|
+
protected checkEquality(current: Data, previous: Data): boolean;
|
|
1090
|
+
protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Calls to Abortcontroller.abort(reason: any) will result in the
|
|
1095
|
+
* `reason` being thrown. This is not necessarily an error,
|
|
1096
|
+
* but extends error for better logging purposes.
|
|
1097
|
+
*
|
|
1098
|
+
* @internal
|
|
1099
|
+
*/
|
|
1100
|
+
declare class AbortOperation extends Error {
|
|
1101
|
+
protected reason: string;
|
|
1102
|
+
constructor(reason: string);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Some JavaScript engines, in particular older versions of React Native, don't support Symbol.asyncIterator.
|
|
1107
|
+
*
|
|
1108
|
+
* For those, users relying on async generators typically lower them with a transpiler and [this polyfill](https://github.com/Azure/azure-sdk-for-js/blob/%40azure/core-asynciterator-polyfill_1.0.2/sdk/core/core-asynciterator-polyfill/src/index.ts#L4-L6).
|
|
1109
|
+
* This definition is compatible with that polyfill, so transpiled apps can use async iterables created by the PowerSync
|
|
1110
|
+
* SDK.
|
|
1111
|
+
*/
|
|
1112
|
+
declare const symbolAsyncIterator: typeof Symbol.asyncIterator;
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* @internal
|
|
1116
|
+
*/
|
|
1117
|
+
interface ControlledExecutorOptions {
|
|
1118
|
+
/**
|
|
1119
|
+
* If throttling is enabled, it ensures only one task runs at a time,
|
|
1120
|
+
* and only one additional task can be scheduled to run after the current task completes. The pending task will be overwritten by the latest task.
|
|
1121
|
+
* Enabled by default.
|
|
1122
|
+
*/
|
|
1123
|
+
throttleEnabled?: boolean;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* @internal
|
|
1127
|
+
*/
|
|
1128
|
+
declare class ControlledExecutor<T> {
|
|
1129
|
+
private task;
|
|
1130
|
+
/**
|
|
1131
|
+
* Represents the currently running task, which could be a Promise or undefined if no task is running.
|
|
1132
|
+
*/
|
|
1133
|
+
private runningTask;
|
|
1134
|
+
private pendingTaskParam;
|
|
1135
|
+
/**
|
|
1136
|
+
* Flag to determine if throttling is enabled, which controls whether tasks are queued or run immediately.
|
|
1137
|
+
*/
|
|
1138
|
+
private isThrottling;
|
|
1139
|
+
private closed;
|
|
1140
|
+
constructor(task: (param: T) => Promise<void> | void, options?: ControlledExecutorOptions);
|
|
1141
|
+
schedule(param: T): void;
|
|
1142
|
+
dispose(): void;
|
|
1143
|
+
private execute;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* @internal
|
|
1148
|
+
*/
|
|
1149
|
+
interface ParsedQuery {
|
|
1150
|
+
sqlStatement: string;
|
|
1151
|
+
parameters: any[];
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* @internal
|
|
1155
|
+
*/
|
|
1156
|
+
declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
|
|
1157
|
+
|
|
1158
|
+
export { AbortOperation, AbstractRemote, AbstractStreamingSyncImplementation, BasePowerSyncDatabase, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudEntryImpl, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_REMOTE_OPTIONS, DEFAULT_ROW_COMPARATOR, DEFAULT_TRIGGER_MANAGER_CONFIGURATION, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FetchImplementationProvider, LockType, MEMORY_TRIGGER_CLAIM_MANAGER, Mutex, OnChangeQueryProcessor, PSInternalTable, PowerSyncControlCommand, Semaphore, SqliteBucketStorage, SyncStatusSnapshot, TriggerManagerImpl, isInterruptingInstruction, openDatabase, parseQuery, resolveSyncOptions, symbolAsyncIterator, timeoutSignal };
|
|
1159
|
+
export type { AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, BucketProgress, BucketStorageAdapter, BucketStorageListener, ConnectionManagerListener, ConnectionManagerOptions, ConnectionManagerSyncImplementationResult, ControlledExecutorOptions, CoreStreamSubscription, CoreSyncStatus, CreateSyncImplementationOptions, CrudEntryJSON, DifferentialQueryProcessorOptions, DownloadProgress, EstablishSyncStream, FetchCredentials, FetchImplementation, Instruction, InternalSubscriptionAdapter, InterruptingInstruction, JavaScriptSyncState, LockOptions, LogLine, NonInterruptingInstruction, OnChangeQueryProcessorOptions, ParsedQuery, RemoteConnector, ResolvedSyncOptions, SimpleAsyncIterator, SocketSyncStreamOptions, StreamingSyncImplementation, StreamingSyncImplementationListener, SubscribedStream, SyncPriorityStatus, SyncStatusJson, SyncStreamOptions, TriggerClaimManager, TriggerManagerConfig, TriggerManagerImplConfiguration, TriggerManagerImplOptions, UnlockFn, UpdateSyncStatus };
|