@powersync/common 0.0.0-dev-20260202162549 → 0.0.0-dev-20260216124709

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/dist/bundle.cjs +14470 -0
  2. package/dist/bundle.cjs.map +1 -0
  3. package/dist/bundle.mjs +14379 -0
  4. package/dist/bundle.mjs.map +1 -0
  5. package/dist/bundle.node.cjs +11948 -0
  6. package/dist/bundle.node.cjs.map +1 -0
  7. package/dist/bundle.node.mjs +11857 -0
  8. package/dist/bundle.node.mjs.map +1 -0
  9. package/dist/index.d.cts +4272 -0
  10. package/lib/attachments/AttachmentContext.d.ts +86 -0
  11. package/lib/attachments/AttachmentContext.js +229 -0
  12. package/lib/attachments/AttachmentContext.js.map +1 -0
  13. package/lib/attachments/AttachmentErrorHandler.d.ts +31 -0
  14. package/lib/attachments/AttachmentErrorHandler.js +2 -0
  15. package/lib/attachments/AttachmentErrorHandler.js.map +1 -0
  16. package/lib/attachments/AttachmentQueue.d.ts +149 -0
  17. package/lib/attachments/AttachmentQueue.js +362 -0
  18. package/lib/attachments/AttachmentQueue.js.map +1 -0
  19. package/lib/attachments/AttachmentService.d.ts +29 -0
  20. package/lib/attachments/AttachmentService.js +56 -0
  21. package/lib/attachments/AttachmentService.js.map +1 -0
  22. package/lib/attachments/LocalStorageAdapter.d.ts +62 -0
  23. package/lib/attachments/LocalStorageAdapter.js +6 -0
  24. package/lib/attachments/LocalStorageAdapter.js.map +1 -0
  25. package/lib/attachments/RemoteStorageAdapter.d.ts +27 -0
  26. package/lib/attachments/RemoteStorageAdapter.js +2 -0
  27. package/lib/attachments/RemoteStorageAdapter.js.map +1 -0
  28. package/lib/attachments/Schema.d.ts +50 -0
  29. package/lib/attachments/Schema.js +62 -0
  30. package/lib/attachments/Schema.js.map +1 -0
  31. package/lib/attachments/SyncingService.d.ts +62 -0
  32. package/lib/attachments/SyncingService.js +168 -0
  33. package/lib/attachments/SyncingService.js.map +1 -0
  34. package/lib/attachments/WatchedAttachmentItem.d.ts +17 -0
  35. package/lib/attachments/WatchedAttachmentItem.js +2 -0
  36. package/lib/attachments/WatchedAttachmentItem.js.map +1 -0
  37. package/lib/client/AbstractPowerSyncDatabase.d.ts +615 -0
  38. package/lib/client/AbstractPowerSyncDatabase.js +983 -0
  39. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -0
  40. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +22 -0
  41. package/lib/client/AbstractPowerSyncOpenFactory.js +25 -0
  42. package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -0
  43. package/lib/client/ConnectionManager.d.ts +112 -0
  44. package/lib/client/ConnectionManager.js +294 -0
  45. package/lib/client/ConnectionManager.js.map +1 -0
  46. package/lib/client/CustomQuery.d.ts +22 -0
  47. package/lib/client/CustomQuery.js +43 -0
  48. package/lib/client/CustomQuery.js.map +1 -0
  49. package/lib/client/Query.d.ts +97 -0
  50. package/lib/client/Query.js +2 -0
  51. package/lib/client/Query.js.map +1 -0
  52. package/lib/client/SQLOpenFactory.d.ts +42 -0
  53. package/lib/client/SQLOpenFactory.js +20 -0
  54. package/lib/client/SQLOpenFactory.js.map +1 -0
  55. package/lib/client/compilableQueryWatch.d.ts +7 -0
  56. package/lib/client/compilableQueryWatch.js +38 -0
  57. package/lib/client/compilableQueryWatch.js.map +1 -0
  58. package/lib/client/connection/PowerSyncBackendConnector.d.ts +23 -0
  59. package/lib/client/connection/PowerSyncBackendConnector.js +2 -0
  60. package/lib/client/connection/PowerSyncBackendConnector.js.map +1 -0
  61. package/lib/client/connection/PowerSyncCredentials.d.ts +5 -0
  62. package/lib/client/connection/PowerSyncCredentials.js +2 -0
  63. package/lib/client/connection/PowerSyncCredentials.js.map +1 -0
  64. package/lib/client/constants.d.ts +1 -0
  65. package/lib/client/constants.js +2 -0
  66. package/lib/client/constants.js.map +1 -0
  67. package/lib/client/runOnSchemaChange.d.ts +2 -0
  68. package/lib/client/runOnSchemaChange.js +24 -0
  69. package/lib/client/runOnSchemaChange.js.map +1 -0
  70. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +102 -0
  71. package/lib/client/sync/bucket/BucketStorageAdapter.js +19 -0
  72. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
  73. package/lib/client/sync/bucket/CrudBatch.d.ts +31 -0
  74. package/lib/client/sync/bucket/CrudBatch.js +26 -0
  75. package/lib/client/sync/bucket/CrudBatch.js.map +1 -0
  76. package/lib/client/sync/bucket/CrudEntry.d.ts +95 -0
  77. package/lib/client/sync/bucket/CrudEntry.js +110 -0
  78. package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
  79. package/lib/client/sync/bucket/CrudTransaction.d.ts +29 -0
  80. package/lib/client/sync/bucket/CrudTransaction.js +25 -0
  81. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -0
  82. package/lib/client/sync/bucket/OpType.d.ts +16 -0
  83. package/lib/client/sync/bucket/OpType.js +23 -0
  84. package/lib/client/sync/bucket/OpType.js.map +1 -0
  85. package/lib/client/sync/bucket/OplogEntry.d.ts +23 -0
  86. package/lib/client/sync/bucket/OplogEntry.js +36 -0
  87. package/lib/client/sync/bucket/OplogEntry.js.map +1 -0
  88. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +61 -0
  89. package/lib/client/sync/bucket/SqliteBucketStorage.js +324 -0
  90. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
  91. package/lib/client/sync/bucket/SyncDataBatch.d.ts +6 -0
  92. package/lib/client/sync/bucket/SyncDataBatch.js +12 -0
  93. package/lib/client/sync/bucket/SyncDataBatch.js.map +1 -0
  94. package/lib/client/sync/bucket/SyncDataBucket.d.ts +40 -0
  95. package/lib/client/sync/bucket/SyncDataBucket.js +40 -0
  96. package/lib/client/sync/bucket/SyncDataBucket.js.map +1 -0
  97. package/lib/client/sync/stream/AbstractRemote.d.ts +140 -0
  98. package/lib/client/sync/stream/AbstractRemote.js +506 -0
  99. package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
  100. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +240 -0
  101. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +990 -0
  102. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
  103. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
  104. package/lib/client/sync/stream/WebsocketClientTransport.js +61 -0
  105. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
  106. package/lib/client/sync/stream/core-instruction.d.ts +72 -0
  107. package/lib/client/sync/stream/core-instruction.js +27 -0
  108. package/lib/client/sync/stream/core-instruction.js.map +1 -0
  109. package/lib/client/sync/stream/streaming-sync-types.d.ts +143 -0
  110. package/lib/client/sync/stream/streaming-sync-types.js +26 -0
  111. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -0
  112. package/lib/client/sync/sync-streams.d.ts +98 -0
  113. package/lib/client/sync/sync-streams.js +2 -0
  114. package/lib/client/sync/sync-streams.js.map +1 -0
  115. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
  116. package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
  117. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
  118. package/lib/client/triggers/TriggerManager.d.ts +459 -0
  119. package/lib/client/triggers/TriggerManager.js +11 -0
  120. package/lib/client/triggers/TriggerManager.js.map +1 -0
  121. package/lib/client/triggers/TriggerManagerImpl.d.ts +39 -0
  122. package/lib/client/triggers/TriggerManagerImpl.js +393 -0
  123. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
  124. package/lib/client/triggers/sanitizeSQL.d.ts +34 -0
  125. package/lib/client/triggers/sanitizeSQL.js +69 -0
  126. package/lib/client/triggers/sanitizeSQL.js.map +1 -0
  127. package/lib/client/watched/GetAllQuery.d.ts +32 -0
  128. package/lib/client/watched/GetAllQuery.js +25 -0
  129. package/lib/client/watched/GetAllQuery.js.map +1 -0
  130. package/lib/client/watched/WatchedQuery.d.ts +100 -0
  131. package/lib/client/watched/WatchedQuery.js +14 -0
  132. package/lib/client/watched/WatchedQuery.js.map +1 -0
  133. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +68 -0
  134. package/lib/client/watched/processors/AbstractQueryProcessor.js +151 -0
  135. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -0
  136. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +121 -0
  137. package/lib/client/watched/processors/DifferentialQueryProcessor.js +173 -0
  138. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -0
  139. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +33 -0
  140. package/lib/client/watched/processors/OnChangeQueryProcessor.js +83 -0
  141. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -0
  142. package/lib/client/watched/processors/comparators.d.ts +30 -0
  143. package/lib/client/watched/processors/comparators.js +35 -0
  144. package/lib/client/watched/processors/comparators.js.map +1 -0
  145. package/lib/db/ConnectionClosedError.d.ts +10 -0
  146. package/lib/db/ConnectionClosedError.js +21 -0
  147. package/lib/db/ConnectionClosedError.js.map +1 -0
  148. package/lib/db/DBAdapter.d.ts +115 -0
  149. package/lib/db/DBAdapter.js +20 -0
  150. package/lib/db/DBAdapter.js.map +1 -0
  151. package/lib/db/crud/SyncProgress.d.ts +68 -0
  152. package/lib/db/crud/SyncProgress.js +61 -0
  153. package/lib/db/crud/SyncProgress.js.map +1 -0
  154. package/lib/db/crud/SyncStatus.d.ts +195 -0
  155. package/lib/db/crud/SyncStatus.js +250 -0
  156. package/lib/db/crud/SyncStatus.js.map +1 -0
  157. package/lib/db/crud/UploadQueueStatus.d.ts +20 -0
  158. package/lib/db/crud/UploadQueueStatus.js +25 -0
  159. package/lib/db/crud/UploadQueueStatus.js.map +1 -0
  160. package/lib/db/schema/Column.d.ts +30 -0
  161. package/lib/db/schema/Column.js +43 -0
  162. package/lib/db/schema/Column.js.map +1 -0
  163. package/lib/db/schema/Index.d.ts +22 -0
  164. package/lib/db/schema/Index.js +30 -0
  165. package/lib/db/schema/Index.js.map +1 -0
  166. package/lib/db/schema/IndexedColumn.d.ts +19 -0
  167. package/lib/db/schema/IndexedColumn.js +30 -0
  168. package/lib/db/schema/IndexedColumn.js.map +1 -0
  169. package/lib/db/schema/RawTable.d.ts +61 -0
  170. package/lib/db/schema/RawTable.js +33 -0
  171. package/lib/db/schema/RawTable.js.map +1 -0
  172. package/lib/db/schema/Schema.d.ts +54 -0
  173. package/lib/db/schema/Schema.js +61 -0
  174. package/lib/db/schema/Schema.js.map +1 -0
  175. package/lib/db/schema/Table.d.ts +157 -0
  176. package/lib/db/schema/Table.js +208 -0
  177. package/lib/db/schema/Table.js.map +1 -0
  178. package/lib/db/schema/TableV2.d.ts +9 -0
  179. package/lib/db/schema/TableV2.js +9 -0
  180. package/lib/db/schema/TableV2.js.map +1 -0
  181. package/lib/index.d.ts +62 -0
  182. package/lib/index.js +63 -0
  183. package/lib/index.js.map +1 -0
  184. package/lib/types/types.d.ts +8 -0
  185. package/lib/types/types.js +2 -0
  186. package/lib/types/types.js.map +1 -0
  187. package/lib/utils/AbortOperation.d.ts +9 -0
  188. package/lib/utils/AbortOperation.js +19 -0
  189. package/lib/utils/AbortOperation.js.map +1 -0
  190. package/lib/utils/BaseObserver.d.ts +18 -0
  191. package/lib/utils/BaseObserver.js +27 -0
  192. package/lib/utils/BaseObserver.js.map +1 -0
  193. package/lib/utils/ControlledExecutor.d.ts +25 -0
  194. package/lib/utils/ControlledExecutor.js +51 -0
  195. package/lib/utils/ControlledExecutor.js.map +1 -0
  196. package/lib/utils/DataStream.d.ts +62 -0
  197. package/lib/utils/DataStream.js +169 -0
  198. package/lib/utils/DataStream.js.map +1 -0
  199. package/lib/utils/Logger.d.ts +31 -0
  200. package/lib/utils/Logger.js +37 -0
  201. package/lib/utils/Logger.js.map +1 -0
  202. package/lib/utils/MetaBaseObserver.d.ts +29 -0
  203. package/lib/utils/MetaBaseObserver.js +51 -0
  204. package/lib/utils/MetaBaseObserver.js.map +1 -0
  205. package/lib/utils/async.d.ts +23 -0
  206. package/lib/utils/async.js +55 -0
  207. package/lib/utils/async.js.map +1 -0
  208. package/lib/utils/mutex.d.ts +7 -0
  209. package/lib/utils/mutex.js +29 -0
  210. package/lib/utils/mutex.js.map +1 -0
  211. package/lib/utils/parseQuery.d.ts +6 -0
  212. package/lib/utils/parseQuery.js +17 -0
  213. package/lib/utils/parseQuery.js.map +1 -0
  214. package/package.json +1 -1
@@ -0,0 +1,615 @@
1
+ import { Mutex } from 'async-mutex';
2
+ import { ILogger } from 'js-logger';
3
+ import { DBAdapter, QueryResult, Transaction } from '../db/DBAdapter.js';
4
+ import { SyncStatus } from '../db/crud/SyncStatus.js';
5
+ import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
6
+ import { Schema } from '../db/schema/Schema.js';
7
+ import { BaseObserver } from '../utils/BaseObserver.js';
8
+ import { ConnectionManager, CreateSyncImplementationOptions } from './ConnectionManager.js';
9
+ import { ArrayQueryDefinition, Query } from './Query.js';
10
+ import { SQLOpenFactory, SQLOpenOptions } from './SQLOpenFactory.js';
11
+ import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
12
+ import { BucketStorageAdapter } from './sync/bucket/BucketStorageAdapter.js';
13
+ import { CrudBatch } from './sync/bucket/CrudBatch.js';
14
+ import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
15
+ import { InternalConnectionOptions, StreamingSyncImplementation, StreamingSyncImplementationListener, type AdditionalConnectionOptions, type PowerSyncConnectionOptions, type RequiredAdditionalConnectionOptions } from './sync/stream/AbstractStreamingSyncImplementation.js';
16
+ import { SyncStream } from './sync/sync-streams.js';
17
+ import { TriggerManager, TriggerManagerConfig } from './triggers/TriggerManager.js';
18
+ import { TriggerManagerImpl } from './triggers/TriggerManagerImpl.js';
19
+ import { WatchCompatibleQuery } from './watched/WatchedQuery.js';
20
+ import { WatchedQueryComparator } from './watched/processors/comparators.js';
21
+ export interface DisconnectAndClearOptions {
22
+ /** When set to false, data in local-only tables is preserved. */
23
+ clearLocal?: boolean;
24
+ }
25
+ export interface BasePowerSyncDatabaseOptions extends AdditionalConnectionOptions {
26
+ /** Schema used for the local database. */
27
+ 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;
52
+ }
53
+ export interface SQLOnChangeOptions {
54
+ signal?: AbortSignal;
55
+ tables?: string[];
56
+ /** The minimum interval between queries. */
57
+ 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
+ /**
66
+ * Emits an empty result set immediately
67
+ */
68
+ triggerImmediate?: boolean;
69
+ }
70
+ export interface SQLWatchOptions extends SQLOnChangeOptions {
71
+ /**
72
+ * Optional comparator which will be used to compare the results of the query.
73
+ * The watched query will only yield results if the comparator returns false.
74
+ */
75
+ comparator?: WatchedQueryComparator<QueryResult>;
76
+ }
77
+ export interface WatchOnChangeEvent {
78
+ changedTables: string[];
79
+ }
80
+ export interface WatchHandler {
81
+ onResult: (results: QueryResult) => void;
82
+ onError?: (error: Error) => void;
83
+ }
84
+ export interface WatchOnChangeHandler {
85
+ onChange: (event: WatchOnChangeEvent) => Promise<void> | void;
86
+ onError?: (error: Error) => void;
87
+ }
88
+ export interface PowerSyncDBListener extends StreamingSyncImplementationListener {
89
+ initialized: () => void;
90
+ schemaChanged: (schema: Schema) => void;
91
+ closing: () => Promise<void> | void;
92
+ closed: () => Promise<void> | void;
93
+ }
94
+ export interface PowerSyncCloseOptions {
95
+ /**
96
+ * Disconnect the sync stream client if connected.
97
+ * This is usually true, but can be false for Web when using
98
+ * multiple tabs and a shared sync provider.
99
+ */
100
+ disconnect?: boolean;
101
+ }
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
+ /**
109
+ * Requesting nested or recursive locks can block the application in some circumstances.
110
+ * This default lock timeout will act as a failsafe to throw an error if a lock cannot
111
+ * be obtained.
112
+ */
113
+ export declare const DEFAULT_LOCK_TIMEOUT_MS = 120000;
114
+ /**
115
+ * Tests if the input is a {@link PowerSyncDatabaseOptionsWithSettings}
116
+ * @internal
117
+ */
118
+ export declare const isPowerSyncDatabaseOptionsWithSettings: (test: any) => test is PowerSyncDatabaseOptionsWithSettings;
119
+ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDBListener> {
120
+ protected options: PowerSyncDatabaseOptions;
121
+ /**
122
+ * Returns true if the connection is closed.
123
+ */
124
+ closed: boolean;
125
+ ready: boolean;
126
+ /**
127
+ * Current connection status.
128
+ */
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;
142
+ /**
143
+ * The resolved connection options used to connect to the PowerSync service.
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
153
+ * Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
154
+ */
155
+ readonly triggers: TriggerManager;
156
+ protected triggersImpl: TriggerManagerImpl;
157
+ logger: ILogger;
158
+ constructor(options: PowerSyncDatabaseOptionsWithDBAdapter);
159
+ constructor(options: PowerSyncDatabaseOptionsWithOpenFactory);
160
+ constructor(options: PowerSyncDatabaseOptionsWithSettings);
161
+ constructor(options: PowerSyncDatabaseOptions);
162
+ /**
163
+ * Schema used for the local database.
164
+ */
165
+ get schema(): Schema<{
166
+ [x: string]: import("../index.js").Table<any>;
167
+ }>;
168
+ /**
169
+ * The underlying database.
170
+ *
171
+ * For the most part, behavior is the same whether querying on the underlying database, or on {@link AbstractPowerSyncDatabase}.
172
+ */
173
+ get database(): DBAdapter;
174
+ /**
175
+ * Whether a connection to the PowerSync service is currently open.
176
+ */
177
+ get connected(): boolean;
178
+ 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
+ /**
191
+ * @returns A promise which will resolve once initialization is completed.
192
+ */
193
+ waitForReady(): Promise<void>;
194
+ /**
195
+ * Wait for the first sync operation to complete.
196
+ *
197
+ * @param request Either an abort signal (after which the promise will complete regardless of
198
+ * whether a full sync was completed) or an object providing an abort signal and a priority target.
199
+ * When a priority target is set, the promise may complete when all buckets with the given (or higher)
200
+ * priorities have been synchronized. This can be earlier than a complete sync.
201
+ * @returns A promise which will resolve once the first full sync has completed.
202
+ */
203
+ waitForFirstSync(request?: AbortSignal | {
204
+ signal?: AbortSignal;
205
+ priority?: number;
206
+ }): Promise<void>;
207
+ /**
208
+ * Waits for the first sync status for which the `status` callback returns a truthy value.
209
+ */
210
+ 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
+ /**
224
+ * 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
+ *
226
+ * Cannot be used while connected - this should only be called before {@link AbstractPowerSyncDatabase.connect}.
227
+ */
228
+ updateSchema(schema: Schema): Promise<void>;
229
+ /**
230
+ * Wait for initialization to complete.
231
+ * While initializing is automatic, this helps to catch and report initialization errors.
232
+ */
233
+ 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
+ /**
246
+ * Connects to stream of events from the PowerSync instance.
247
+ */
248
+ connect(connector: PowerSyncBackendConnector, options?: PowerSyncConnectionOptions): Promise<void>;
249
+ /**
250
+ * Close the sync connection.
251
+ *
252
+ * Use {@link connect} to connect again.
253
+ */
254
+ disconnect(): Promise<void>;
255
+ /**
256
+ * Disconnect and clear the database.
257
+ * Use this when logging out.
258
+ * The database can still be queried after this is called, but the tables
259
+ * would be empty.
260
+ *
261
+ * To preserve data in local-only tables, set clearLocal to false.
262
+ */
263
+ disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
264
+ /**
265
+ * Create a sync stream to query its status or to subscribe to it.
266
+ *
267
+ * @param name The name of the stream to subscribe to.
268
+ * @param params Optional parameters for the stream subscription.
269
+ * @returns A {@link SyncStream} instance that can be subscribed to.
270
+ * @experimental Sync streams are currently in alpha.
271
+ */
272
+ syncStream(name: string, params?: Record<string, any>): SyncStream;
273
+ /**
274
+ * Close the database, releasing resources.
275
+ *
276
+ * Also disconnects any active connection.
277
+ *
278
+ * Once close is called, this connection cannot be used again - a new one
279
+ * must be constructed.
280
+ */
281
+ close(options?: PowerSyncCloseOptions): Promise<void>;
282
+ /**
283
+ * Get upload queue size estimate and count.
284
+ */
285
+ getUploadQueueStats(includeSize?: boolean): Promise<UploadQueueStats>;
286
+ /**
287
+ * Get a batch of CRUD data to upload.
288
+ *
289
+ * Returns null if there is no data to upload.
290
+ *
291
+ * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
292
+ *
293
+ * Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
294
+ * requesting the next batch.
295
+ *
296
+ * Use {@link limit} to specify the maximum number of updates to return in a single
297
+ * batch.
298
+ *
299
+ * This method does include transaction ids in the result, but does not group
300
+ * data by transaction. One batch may contain data from multiple transactions,
301
+ * and a single transaction may be split over multiple batches.
302
+ *
303
+ * @param limit Maximum number of CRUD entries to include in the batch
304
+ * @returns A batch of CRUD operations to upload, or null if there are none
305
+ */
306
+ getCrudBatch(limit?: number): Promise<CrudBatch | null>;
307
+ /**
308
+ * Get the next recorded transaction to upload.
309
+ *
310
+ * Returns null if there is no data to upload.
311
+ *
312
+ * Use this from the {@link PowerSyncBackendConnector.uploadData} callback.
313
+ *
314
+ * Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
315
+ * requesting the next transaction.
316
+ *
317
+ * Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
318
+ * All data for the transaction is loaded into memory.
319
+ *
320
+ * @returns A transaction of CRUD operations to upload, or null if there are none
321
+ */
322
+ getNextCrudTransaction(): Promise<CrudTransaction | null>;
323
+ /**
324
+ * Returns an async iterator of completed transactions with local writes against the database.
325
+ *
326
+ * This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
327
+ * returned iterator is a full transaction containing all local writes made while that transaction was active.
328
+ *
329
+ * Unlike {@link getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
330
+ * {@link CrudTransaction.complete}d yet, this iterator can be used to receive multiple transactions. Calling
331
+ * {@link CrudTransaction.complete} will mark that and all prior transactions emitted by the iterator as completed.
332
+ *
333
+ * This can be used to upload multiple transactions in a single batch, e.g with:
334
+ *
335
+ * ```JavaScript
336
+ * let lastTransaction = null;
337
+ * let batch = [];
338
+ *
339
+ * for await (const transaction of database.getCrudTransactions()) {
340
+ * batch.push(...transaction.crud);
341
+ * lastTransaction = transaction;
342
+ *
343
+ * if (batch.length > 10) {
344
+ * break;
345
+ * }
346
+ * }
347
+ * ```
348
+ *
349
+ * If there is no local data to upload, the async iterator complete without emitting any items.
350
+ *
351
+ * Note that iterating over async iterables requires a [polyfill](https://github.com/powersync-ja/powersync-js/tree/main/packages/react-native#babel-plugins-watched-queries)
352
+ * for React Native.
353
+ */
354
+ getCrudTransactions(): AsyncIterable<CrudTransaction, null>;
355
+ /**
356
+ * Get an unique client id for this database.
357
+ *
358
+ * The id is not reset when the database is cleared, only when the database is deleted.
359
+ *
360
+ * @returns A unique identifier for the database instance
361
+ */
362
+ getClientId(): Promise<string>;
363
+ private handleCrudCheckpoint;
364
+ /**
365
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
366
+ * and optionally return results.
367
+ *
368
+ * @param sql The SQL query to execute
369
+ * @param parameters Optional array of parameters to bind to the query
370
+ * @returns The query result as an object with structured key-value pairs
371
+ */
372
+ execute(sql: string, parameters?: any[]): Promise<QueryResult>;
373
+ /**
374
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
375
+ * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
376
+ *
377
+ * @param sql The SQL query to execute
378
+ * @param parameters Optional array of parameters to bind to the query
379
+ * @returns The raw query result from the underlying database as a nested array of raw values, where each row is
380
+ * represented as an array of column values without field names.
381
+ */
382
+ executeRaw(sql: string, parameters?: any[]): Promise<any[][]>;
383
+ /**
384
+ * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
385
+ * and optionally return results.
386
+ * This is faster than executing separately with each parameter set.
387
+ *
388
+ * @param sql The SQL query to execute
389
+ * @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
390
+ * @returns The query result
391
+ */
392
+ executeBatch(sql: string, parameters?: any[][]): Promise<QueryResult>;
393
+ /**
394
+ * Execute a read-only query and return results.
395
+ *
396
+ * @param sql The SQL query to execute
397
+ * @param parameters Optional array of parameters to bind to the query
398
+ * @returns An array of results
399
+ */
400
+ getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
401
+ /**
402
+ * Execute a read-only query and return the first result, or null if the ResultSet is empty.
403
+ *
404
+ * @param sql The SQL query to execute
405
+ * @param parameters Optional array of parameters to bind to the query
406
+ * @returns The first result if found, or null if no results are returned
407
+ */
408
+ getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
409
+ /**
410
+ * Execute a read-only query and return the first result, error if the ResultSet is empty.
411
+ *
412
+ * @param sql The SQL query to execute
413
+ * @param parameters Optional array of parameters to bind to the query
414
+ * @returns The first result matching the query
415
+ * @throws Error if no rows are returned
416
+ */
417
+ get<T>(sql: string, parameters?: any[]): Promise<T>;
418
+ /**
419
+ * Takes a read lock, without starting a transaction.
420
+ * In most cases, {@link readTransaction} should be used instead.
421
+ */
422
+ readLock<T>(callback: (db: DBAdapter) => Promise<T>): Promise<T>;
423
+ /**
424
+ * Takes a global lock, without starting a transaction.
425
+ * In most cases, {@link writeTransaction} should be used instead.
426
+ */
427
+ writeLock<T>(callback: (db: DBAdapter) => Promise<T>): Promise<T>;
428
+ /**
429
+ * Open a read-only transaction.
430
+ * Read transactions can run concurrently to a write transaction.
431
+ * Changes from any write transaction are not visible to read transactions started before it.
432
+ *
433
+ * @param callback Function to execute within the transaction
434
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
435
+ * @returns The result of the callback
436
+ * @throws Error if the lock cannot be obtained within the timeout period
437
+ */
438
+ readTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
439
+ /**
440
+ * Open a read-write transaction.
441
+ * This takes a global lock - only one write transaction can execute against the database at a time.
442
+ * Statements within the transaction must be done on the provided {@link Transaction} interface.
443
+ *
444
+ * @param callback Function to execute within the transaction
445
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
446
+ * @returns The result of the callback
447
+ * @throws Error if the lock cannot be obtained within the timeout period
448
+ */
449
+ writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, lockTimeout?: number): Promise<T>;
450
+ /**
451
+ * This version of `watch` uses {@link AsyncGenerator}, for documentation see {@link watchWithAsyncGenerator}.
452
+ * Can be overloaded to use a callback handler instead, for documentation see {@link watchWithCallback}.
453
+ *
454
+ * @example
455
+ * ```javascript
456
+ * async *attachmentIds() {
457
+ * for await (const result of this.powersync.watch(
458
+ * `SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL`,
459
+ * []
460
+ * )) {
461
+ * yield result.rows?._array.map((r) => r.id) ?? [];
462
+ * }
463
+ * }
464
+ * ```
465
+ */
466
+ watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
467
+ /**
468
+ * See {@link watchWithCallback}.
469
+ *
470
+ * @example
471
+ * ```javascript
472
+ * onAttachmentIdsChange(onResult) {
473
+ * this.powersync.watch(
474
+ * `SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL`,
475
+ * [],
476
+ * {
477
+ * onResult: (result) => onResult(result.rows?._array.map((r) => r.id) ?? [])
478
+ * }
479
+ * );
480
+ * }
481
+ * ```
482
+ */
483
+ watch(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
484
+ /**
485
+ * Allows defining a query which can be used to build a {@link WatchedQuery}.
486
+ * The defined query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
487
+ * An optional mapper function can be provided to transform the results.
488
+ *
489
+ * @example
490
+ * ```javascript
491
+ * const watchedTodos = powersync.query({
492
+ * sql: `SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL`,
493
+ * parameters: [],
494
+ * mapper: (row) => ({
495
+ * ...row,
496
+ * created_at: new Date(row.created_at as string)
497
+ * })
498
+ * })
499
+ * .watch()
500
+ * // OR use .differentialWatch() for fine-grained watches.
501
+ * ```
502
+ */
503
+ query<RowType>(query: ArrayQueryDefinition<RowType>): Query<RowType>;
504
+ /**
505
+ * Allows building a {@link WatchedQuery} using an existing {@link WatchCompatibleQuery}.
506
+ * The watched query will use the provided {@link WatchCompatibleQuery.execute} method to query results.
507
+ *
508
+ * @example
509
+ * ```javascript
510
+ *
511
+ * // Potentially a query from an ORM like Drizzle
512
+ * const query = db.select().from(lists);
513
+ *
514
+ * const watchedTodos = powersync.customQuery(query)
515
+ * .watch()
516
+ * // OR use .differentialWatch() for fine-grained watches.
517
+ * ```
518
+ */
519
+ customQuery<RowType>(query: WatchCompatibleQuery<RowType[]>): Query<RowType>;
520
+ /**
521
+ * Execute a read query every time the source tables are modified.
522
+ * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
523
+ * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
524
+ *
525
+ * Note that the `onChange` callback member of the handler is required.
526
+ *
527
+ * @param sql The SQL query to execute
528
+ * @param parameters Optional array of parameters to bind to the query
529
+ * @param handler Callbacks for handling results and errors
530
+ * @param options Options for configuring watch behavior
531
+ */
532
+ watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void;
533
+ /**
534
+ * Execute a read query every time the source tables are modified.
535
+ * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
536
+ * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
537
+ *
538
+ * @param sql The SQL query to execute
539
+ * @param parameters Optional array of parameters to bind to the query
540
+ * @param options Options for configuring watch behavior
541
+ * @returns An AsyncIterable that yields QueryResults whenever the data changes
542
+ */
543
+ watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
544
+ /**
545
+ * Resolves the list of tables that are used in a SQL query.
546
+ * If tables are specified in the options, those are used directly.
547
+ * Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
548
+ *
549
+ * @param sql The SQL query to analyze
550
+ * @param parameters Optional parameters for the SQL query
551
+ * @param options Optional watch options that may contain explicit table list
552
+ * @returns Array of table names that the query depends on
553
+ */
554
+ resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]>;
555
+ /**
556
+ * This version of `onChange` uses {@link AsyncGenerator}, for documentation see {@link onChangeWithAsyncGenerator}.
557
+ * Can be overloaded to use a callback handler instead, for documentation see {@link onChangeWithCallback}.
558
+ *
559
+ * @example
560
+ * ```javascript
561
+ * async monitorChanges() {
562
+ * for await (const event of this.powersync.onChange({tables: ['todos']})) {
563
+ * console.log('Detected change event:', event);
564
+ * }
565
+ * }
566
+ * ```
567
+ */
568
+ onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
569
+ /**
570
+ * See {@link onChangeWithCallback}.
571
+ *
572
+ * @example
573
+ * ```javascript
574
+ * monitorChanges() {
575
+ * this.powersync.onChange({
576
+ * onChange: (event) => {
577
+ * console.log('Change detected:', event);
578
+ * }
579
+ * }, { tables: ['todos'] });
580
+ * }
581
+ * ```
582
+ */
583
+ onChange(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
584
+ /**
585
+ * Invoke the provided callback on any changes to any of the specified tables.
586
+ *
587
+ * This is preferred over {@link watchWithCallback} when multiple queries need to be performed
588
+ * together when data is changed.
589
+ *
590
+ * Note that the `onChange` callback member of the handler is required.
591
+ *
592
+ * @param handler Callbacks for handling change events and errors
593
+ * @param options Options for configuring watch behavior
594
+ * @returns A dispose function to stop watching for changes
595
+ */
596
+ onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void;
597
+ /**
598
+ * Create a Stream of changes to any of the specified tables.
599
+ *
600
+ * This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be performed
601
+ * together when data is changed.
602
+ *
603
+ * Note: do not declare this as `async *onChange` as it will not work in React Native.
604
+ *
605
+ * @param options Options for configuring watch behavior
606
+ * @returns An AsyncIterable that yields change events whenever the specified tables change
607
+ */
608
+ onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent>;
609
+ private handleTableChanges;
610
+ private processTableUpdates;
611
+ /**
612
+ * @ignore
613
+ */
614
+ private executeReadOnly;
615
+ }