@powersync/common 1.53.1 → 1.54.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.
Files changed (217) hide show
  1. package/dist/bundle.cjs +560 -353
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +560 -353
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +560 -353
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +560 -353
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +733 -198
  10. package/lib/attachments/AttachmentContext.d.ts +7 -6
  11. package/lib/attachments/AttachmentContext.js +2 -1
  12. package/lib/attachments/AttachmentContext.js.map +1 -1
  13. package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
  14. package/lib/attachments/AttachmentQueue.d.ts +61 -20
  15. package/lib/attachments/AttachmentQueue.js +16 -18
  16. package/lib/attachments/AttachmentQueue.js.map +1 -1
  17. package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
  18. package/lib/attachments/LocalStorageAdapter.js +3 -0
  19. package/lib/attachments/LocalStorageAdapter.js.map +1 -1
  20. package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
  21. package/lib/attachments/Schema.d.ts +12 -4
  22. package/lib/attachments/Schema.js +8 -3
  23. package/lib/attachments/Schema.js.map +1 -1
  24. package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
  25. package/lib/client/AbstractPowerSyncDatabase.d.ts +110 -58
  26. package/lib/client/AbstractPowerSyncDatabase.js +59 -48
  27. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  28. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +6 -0
  29. package/lib/client/AbstractPowerSyncOpenFactory.js +3 -0
  30. package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -1
  31. package/lib/client/ConnectionManager.d.ts +4 -1
  32. package/lib/client/ConnectionManager.js +1 -1
  33. package/lib/client/ConnectionManager.js.map +1 -1
  34. package/lib/client/Query.d.ts +9 -0
  35. package/lib/client/SQLOpenFactory.d.ts +12 -0
  36. package/lib/client/SQLOpenFactory.js +6 -0
  37. package/lib/client/SQLOpenFactory.js.map +1 -1
  38. package/lib/client/compilableQueryWatch.d.ts +6 -0
  39. package/lib/client/compilableQueryWatch.js +3 -0
  40. package/lib/client/compilableQueryWatch.js.map +1 -1
  41. package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -0
  42. package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
  43. package/lib/client/constants.d.ts +3 -0
  44. package/lib/client/constants.js +3 -0
  45. package/lib/client/constants.js.map +1 -1
  46. package/lib/client/runOnSchemaChange.d.ts +3 -0
  47. package/lib/client/runOnSchemaChange.js +3 -0
  48. package/lib/client/runOnSchemaChange.js.map +1 -1
  49. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +12 -0
  50. package/lib/client/sync/bucket/BucketStorageAdapter.js +6 -0
  51. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
  52. package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
  53. package/lib/client/sync/bucket/CrudBatch.js +2 -0
  54. package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
  55. package/lib/client/sync/bucket/CrudEntry.d.ts +9 -0
  56. package/lib/client/sync/bucket/CrudEntry.js +4 -0
  57. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  58. package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
  59. package/lib/client/sync/bucket/CrudTransaction.js +3 -0
  60. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
  61. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +3 -0
  62. package/lib/client/sync/bucket/SqliteBucketStorage.js +3 -0
  63. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
  64. package/lib/client/sync/stream/AbstractRemote.d.ts +30 -1
  65. package/lib/client/sync/stream/AbstractRemote.js +15 -1
  66. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  67. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +61 -14
  68. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +60 -47
  69. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  70. package/lib/client/sync/stream/JsonValue.d.ts +3 -0
  71. package/lib/client/sync/stream/WebsocketClientTransport.js +2 -1
  72. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -1
  73. package/lib/client/sync/sync-streams.d.ts +22 -7
  74. package/lib/client/triggers/TriggerManager.d.ts +19 -18
  75. package/lib/client/triggers/TriggerManager.js +2 -1
  76. package/lib/client/triggers/TriggerManager.js.map +1 -1
  77. package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
  78. package/lib/client/triggers/TriggerManagerImpl.js +3 -3
  79. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
  80. package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
  81. package/lib/client/triggers/sanitizeSQL.js +4 -0
  82. package/lib/client/triggers/sanitizeSQL.js.map +1 -1
  83. package/lib/client/watched/GetAllQuery.d.ts +4 -0
  84. package/lib/client/watched/GetAllQuery.js +2 -0
  85. package/lib/client/watched/GetAllQuery.js.map +1 -1
  86. package/lib/client/watched/WatchedQuery.d.ts +24 -2
  87. package/lib/client/watched/WatchedQuery.js +9 -0
  88. package/lib/client/watched/WatchedQuery.js.map +1 -1
  89. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -1
  90. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -1
  91. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +20 -0
  92. package/lib/client/watched/processors/DifferentialQueryProcessor.js +4 -0
  93. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  94. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -0
  95. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  96. package/lib/client/watched/processors/comparators.d.ts +8 -0
  97. package/lib/client/watched/processors/comparators.js +4 -0
  98. package/lib/client/watched/processors/comparators.js.map +1 -1
  99. package/lib/db/ConnectionClosedError.d.ts +2 -0
  100. package/lib/db/ConnectionClosedError.js +2 -0
  101. package/lib/db/ConnectionClosedError.js.map +1 -1
  102. package/lib/db/DBAdapter.d.ts +56 -6
  103. package/lib/db/DBAdapter.js +15 -3
  104. package/lib/db/DBAdapter.js.map +1 -1
  105. package/lib/db/crud/SyncProgress.d.ts +6 -1
  106. package/lib/db/crud/SyncProgress.js +2 -0
  107. package/lib/db/crud/SyncProgress.js.map +1 -1
  108. package/lib/db/crud/SyncStatus.d.ts +36 -38
  109. package/lib/db/crud/SyncStatus.js +19 -14
  110. package/lib/db/crud/SyncStatus.js.map +1 -1
  111. package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
  112. package/lib/db/crud/UploadQueueStatus.js +3 -0
  113. package/lib/db/crud/UploadQueueStatus.js.map +1 -1
  114. package/lib/db/schema/Column.d.ts +28 -0
  115. package/lib/db/schema/Column.js +16 -3
  116. package/lib/db/schema/Column.js.map +1 -1
  117. package/lib/db/schema/Index.d.ts +9 -0
  118. package/lib/db/schema/Index.js +6 -0
  119. package/lib/db/schema/Index.js.map +1 -1
  120. package/lib/db/schema/IndexedColumn.d.ts +9 -0
  121. package/lib/db/schema/IndexedColumn.js +6 -0
  122. package/lib/db/schema/IndexedColumn.js.map +1 -1
  123. package/lib/db/schema/RawTable.d.ts +7 -1
  124. package/lib/db/schema/Schema.d.ts +6 -1
  125. package/lib/db/schema/Schema.js +3 -1
  126. package/lib/db/schema/Schema.js.map +1 -1
  127. package/lib/db/schema/Table.d.ts +27 -3
  128. package/lib/db/schema/Table.js +9 -0
  129. package/lib/db/schema/Table.js.map +1 -1
  130. package/lib/db/schema/TableV2.d.ts +2 -0
  131. package/lib/db/schema/TableV2.js +2 -0
  132. package/lib/db/schema/TableV2.js.map +1 -1
  133. package/lib/index.d.ts +1 -1
  134. package/lib/types/types.d.ts +6 -0
  135. package/lib/utils/AbortOperation.d.ts +2 -0
  136. package/lib/utils/AbortOperation.js +2 -0
  137. package/lib/utils/AbortOperation.js.map +1 -1
  138. package/lib/utils/BaseObserver.d.ts +12 -0
  139. package/lib/utils/BaseObserver.js +3 -0
  140. package/lib/utils/BaseObserver.js.map +1 -1
  141. package/lib/utils/ControlledExecutor.d.ts +6 -0
  142. package/lib/utils/ControlledExecutor.js +3 -0
  143. package/lib/utils/ControlledExecutor.js.map +1 -1
  144. package/lib/utils/Logger.d.ts +9 -0
  145. package/lib/utils/Logger.js +6 -0
  146. package/lib/utils/Logger.js.map +1 -1
  147. package/lib/utils/async.d.ts +13 -7
  148. package/lib/utils/async.js +38 -24
  149. package/lib/utils/async.js.map +1 -1
  150. package/lib/utils/mutex.d.ts +8 -0
  151. package/lib/utils/mutex.js +3 -0
  152. package/lib/utils/mutex.js.map +1 -1
  153. package/lib/utils/parseQuery.d.ts +6 -0
  154. package/lib/utils/parseQuery.js +3 -0
  155. package/lib/utils/parseQuery.js.map +1 -1
  156. package/lib/utils/stream_transform.d.ts +3 -1
  157. package/lib/utils/stream_transform.js.map +1 -1
  158. package/package.json +3 -2
  159. package/src/attachments/AttachmentContext.ts +7 -6
  160. package/src/attachments/AttachmentErrorHandler.ts +6 -6
  161. package/src/attachments/AttachmentQueue.ts +71 -23
  162. package/src/attachments/LocalStorageAdapter.ts +14 -8
  163. package/src/attachments/README.md +2 -0
  164. package/src/attachments/RemoteStorageAdapter.ts +4 -4
  165. package/src/attachments/Schema.ts +12 -4
  166. package/src/attachments/WatchedAttachmentItem.ts +3 -1
  167. package/src/client/AbstractPowerSyncDatabase.ts +117 -62
  168. package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
  169. package/src/client/ConnectionManager.ts +4 -1
  170. package/src/client/Query.ts +9 -0
  171. package/src/client/SQLOpenFactory.ts +12 -0
  172. package/src/client/compilableQueryWatch.ts +6 -0
  173. package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
  174. package/src/client/connection/PowerSyncCredentials.ts +3 -0
  175. package/src/client/constants.ts +3 -0
  176. package/src/client/runOnSchemaChange.ts +3 -0
  177. package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
  178. package/src/client/sync/bucket/CrudBatch.ts +2 -0
  179. package/src/client/sync/bucket/CrudEntry.ts +9 -0
  180. package/src/client/sync/bucket/CrudTransaction.ts +3 -0
  181. package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
  182. package/src/client/sync/stream/AbstractRemote.ts +30 -1
  183. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +86 -59
  184. package/src/client/sync/stream/JsonValue.ts +3 -0
  185. package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
  186. package/src/client/sync/sync-streams.ts +22 -9
  187. package/src/client/triggers/TriggerManager.ts +19 -18
  188. package/src/client/triggers/TriggerManagerImpl.ts +5 -5
  189. package/src/client/triggers/sanitizeSQL.ts +5 -0
  190. package/src/client/watched/GetAllQuery.ts +5 -1
  191. package/src/client/watched/WatchedQuery.ts +24 -2
  192. package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
  193. package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
  194. package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
  195. package/src/client/watched/processors/comparators.ts +8 -0
  196. package/src/db/ConnectionClosedError.ts +2 -0
  197. package/src/db/DBAdapter.ts +58 -6
  198. package/src/db/crud/SyncProgress.ts +6 -1
  199. package/src/db/crud/SyncStatus.ts +40 -21
  200. package/src/db/crud/UploadQueueStatus.ts +3 -0
  201. package/src/db/schema/Column.ts +28 -3
  202. package/src/db/schema/Index.ts +9 -0
  203. package/src/db/schema/IndexedColumn.ts +9 -0
  204. package/src/db/schema/RawTable.ts +7 -1
  205. package/src/db/schema/Schema.ts +8 -3
  206. package/src/db/schema/Table.ts +30 -5
  207. package/src/db/schema/TableV2.ts +2 -0
  208. package/src/index.ts +1 -1
  209. package/src/types/types.ts +6 -0
  210. package/src/utils/AbortOperation.ts +2 -0
  211. package/src/utils/BaseObserver.ts +12 -0
  212. package/src/utils/ControlledExecutor.ts +6 -0
  213. package/src/utils/Logger.ts +9 -0
  214. package/src/utils/async.ts +51 -24
  215. package/src/utils/mutex.ts +12 -0
  216. package/src/utils/parseQuery.ts +6 -0
  217. package/src/utils/stream_transform.ts +3 -1
@@ -3,6 +3,7 @@ import Logger, { ILogger } from 'js-logger';
3
3
  import {
4
4
  BatchedUpdateNotification,
5
5
  DBAdapter,
6
+ LockContext,
6
7
  QueryResult,
7
8
  Transaction,
8
9
  UpdateNotification,
@@ -47,21 +48,31 @@ import { OnChangeQueryProcessor } from './watched/processors/OnChangeQueryProces
47
48
  import { WatchedQueryComparator } from './watched/processors/comparators.js';
48
49
  import { Mutex } from '../utils/mutex.js';
49
50
 
51
+ /**
52
+ * @public
53
+ */
50
54
  export interface DisconnectAndClearOptions {
51
55
  /** When set to false, data in local-only tables is preserved. */
52
56
  clearLocal?: boolean;
53
57
  }
54
58
 
59
+ /**
60
+ * @public
61
+ */
55
62
  export interface BasePowerSyncDatabaseOptions extends AdditionalConnectionOptions {
56
63
  /** Schema used for the local database. */
57
64
  schema: Schema;
58
65
  /**
59
- * @deprecated Use {@link retryDelayMs} instead as this will be removed in future releases.
66
+ * @deprecated Use {@link AdditionalConnectionOptions.retryDelayMs} instead as this will be removed in future
67
+ * releases.
60
68
  */
61
69
  retryDelay?: number;
62
70
  logger?: ILogger;
63
71
  }
64
72
 
73
+ /**
74
+ * @public
75
+ */
65
76
  export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
66
77
  /**
67
78
  * Source for a SQLite database connection.
@@ -73,23 +84,38 @@ export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
73
84
  database: DBAdapter | SQLOpenFactory | SQLOpenOptions;
74
85
  }
75
86
 
87
+ /**
88
+ * @public
89
+ */
76
90
  export interface PowerSyncDatabaseOptionsWithDBAdapter extends BasePowerSyncDatabaseOptions {
77
91
  database: DBAdapter;
78
92
  }
93
+
94
+ /**
95
+ * @public
96
+ */
79
97
  export interface PowerSyncDatabaseOptionsWithOpenFactory extends BasePowerSyncDatabaseOptions {
80
98
  database: SQLOpenFactory;
81
99
  }
100
+
101
+ /**
102
+ * @public
103
+ */
82
104
  export interface PowerSyncDatabaseOptionsWithSettings extends BasePowerSyncDatabaseOptions {
83
105
  database: SQLOpenOptions;
84
106
  }
85
107
 
108
+ /**
109
+ * @public
110
+ */
86
111
  export interface SQLOnChangeOptions {
87
112
  signal?: AbortSignal;
88
113
  tables?: string[];
89
114
  /** The minimum interval between queries. */
90
115
  throttleMs?: number;
91
116
  /**
92
- * @deprecated All tables specified in {@link tables} will be watched, including PowerSync tables with prefixes.
117
+ * @deprecated All tables specified in {@link SQLOnChangeOptions.tables} will be watched, including PowerSync tables
118
+ * with prefixes.
93
119
  *
94
120
  * Allows for watching any SQL table
95
121
  * by not removing PowerSync table name prefixes
@@ -101,6 +127,9 @@ export interface SQLOnChangeOptions {
101
127
  triggerImmediate?: boolean;
102
128
  }
103
129
 
130
+ /**
131
+ * @public
132
+ */
104
133
  export interface SQLWatchOptions extends SQLOnChangeOptions {
105
134
  /**
106
135
  * Optional comparator which will be used to compare the results of the query.
@@ -109,20 +138,32 @@ export interface SQLWatchOptions extends SQLOnChangeOptions {
109
138
  comparator?: WatchedQueryComparator<QueryResult>;
110
139
  }
111
140
 
141
+ /**
142
+ * @public
143
+ */
112
144
  export interface WatchOnChangeEvent {
113
145
  changedTables: string[];
114
146
  }
115
147
 
148
+ /**
149
+ * @public
150
+ */
116
151
  export interface WatchHandler {
117
152
  onResult: (results: QueryResult) => void;
118
153
  onError?: (error: Error) => void;
119
154
  }
120
155
 
156
+ /**
157
+ * @public
158
+ */
121
159
  export interface WatchOnChangeHandler {
122
160
  onChange: (event: WatchOnChangeEvent) => Promise<void> | void;
123
161
  onError?: (error: Error) => void;
124
162
  }
125
163
 
164
+ /**
165
+ * @public
166
+ */
126
167
  export interface PowerSyncDBListener extends StreamingSyncImplementationListener {
127
168
  initialized: () => void;
128
169
  schemaChanged: (schema: Schema) => void;
@@ -130,6 +171,9 @@ export interface PowerSyncDBListener extends StreamingSyncImplementationListener
130
171
  closed: () => Promise<void> | void;
131
172
  }
132
173
 
174
+ /**
175
+ * @public
176
+ */
133
177
  export interface PowerSyncCloseOptions {
134
178
  /**
135
179
  * Disconnect the sync stream client if connected.
@@ -145,21 +189,32 @@ const DEFAULT_DISCONNECT_CLEAR_OPTIONS: DisconnectAndClearOptions = {
145
189
  clearLocal: true
146
190
  };
147
191
 
192
+ /**
193
+ * @internal
194
+ */
148
195
  export const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions = {
149
196
  disconnect: true
150
197
  };
151
198
 
199
+ /**
200
+ * @internal
201
+ */
152
202
  export const DEFAULT_POWERSYNC_DB_OPTIONS = {
153
203
  retryDelayMs: 5000,
154
204
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
155
205
  };
156
206
 
207
+ /**
208
+ * @internal
209
+ */
157
210
  export const DEFAULT_CRUD_BATCH_LIMIT = 100;
158
211
 
159
212
  /**
160
213
  * Requesting nested or recursive locks can block the application in some circumstances.
161
214
  * This default lock timeout will act as a failsafe to throw an error if a lock cannot
162
215
  * be obtained.
216
+ *
217
+ * @internal
163
218
  */
164
219
  export const DEFAULT_LOCK_TIMEOUT_MS = 120_000; // 2 mins
165
220
 
@@ -171,6 +226,9 @@ export const isPowerSyncDatabaseOptionsWithSettings = (test: any): test is Power
171
226
  return typeof test == 'object' && isSQLOpenOptions(test.database);
172
227
  };
173
228
 
229
+ /**
230
+ * @public
231
+ */
174
232
  export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDBListener> {
175
233
  /**
176
234
  * Returns true if the connection is closed.
@@ -368,7 +426,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
368
426
  /**
369
427
  * Wait for the first sync operation to complete.
370
428
  *
371
- * @param request Either an abort signal (after which the promise will complete regardless of
429
+ * @param request - Either an abort signal (after which the promise will complete regardless of
372
430
  * whether a full sync was completed) or an object providing an abort signal and a priority target.
373
431
  * When a priority target is set, the promise may complete when all buckets with the given (or higher)
374
432
  * priorities have been synchronized. This can be earlier than a complete sync.
@@ -442,7 +500,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
442
500
  try {
443
501
  const { version } = await this.database.get<{ version: string }>('SELECT powersync_rs_version() as version');
444
502
  this.sdkVersion = version;
445
- } catch (e) {
503
+ } catch (e: any) {
446
504
  throw new Error(`The powersync extension is not loaded correctly. Details: ${e.message}`);
447
505
  }
448
506
  let versionInts: number[];
@@ -450,7 +508,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
450
508
  versionInts = this.sdkVersion!.split(/[.\/]/)
451
509
  .slice(0, 3)
452
510
  .map((n) => parseInt(n));
453
- } catch (e) {
511
+ } catch (e: any) {
454
512
  throw new Error(
455
513
  `Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`
456
514
  );
@@ -554,7 +612,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
554
612
  /**
555
613
  * Close the sync connection.
556
614
  *
557
- * Use {@link connect} to connect again.
615
+ * Use {@link AbstractPowerSyncDatabase.connect} to connect again.
558
616
  */
559
617
  async disconnect() {
560
618
  return this.connectionManager.disconnect();
@@ -586,8 +644,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
586
644
  /**
587
645
  * Create a sync stream to query its status or to subscribe to it.
588
646
  *
589
- * @param name The name of the stream to subscribe to.
590
- * @param params Optional parameters for the stream subscription.
647
+ * @param name - The name of the stream to subscribe to.
648
+ * @param params - Optional parameters for the stream subscription.
591
649
  * @returns A {@link SyncStream} instance that can be subscribed to.
592
650
  * @experimental Sync streams are currently in alpha.
593
651
  */
@@ -655,14 +713,14 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
655
713
  * Once the data have been successfully uploaded, call {@link CrudBatch.complete} before
656
714
  * requesting the next batch.
657
715
  *
658
- * Use {@link limit} to specify the maximum number of updates to return in a single
716
+ * Use the `limit` parameter to specify the maximum number of updates to return in a single
659
717
  * batch.
660
718
  *
661
719
  * This method does include transaction ids in the result, but does not group
662
720
  * data by transaction. One batch may contain data from multiple transactions,
663
721
  * and a single transaction may be split over multiple batches.
664
722
  *
665
- * @param limit Maximum number of CRUD entries to include in the batch
723
+ * @param limit - Maximum number of CRUD entries to include in the batch
666
724
  * @returns A batch of CRUD operations to upload, or null if there are none
667
725
  */
668
726
  async getCrudBatch(limit: number = DEFAULT_CRUD_BATCH_LIMIT): Promise<CrudBatch | null> {
@@ -698,7 +756,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
698
756
  * Once the data have been successfully uploaded, call {@link CrudTransaction.complete} before
699
757
  * requesting the next transaction.
700
758
  *
701
- * Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
759
+ * Unlike {@link AbstractPowerSyncDatabase.getCrudBatch}, this only returns data from a single transaction at a time.
702
760
  * All data for the transaction is loaded into memory.
703
761
  *
704
762
  * @returns A transaction of CRUD operations to upload, or null if there are none
@@ -714,7 +772,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
714
772
  * This is typically used from the {@link PowerSyncBackendConnector.uploadData} callback. Each entry emitted by the
715
773
  * returned iterator is a full transaction containing all local writes made while that transaction was active.
716
774
  *
717
- * Unlike {@link getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
775
+ * Unlike {@link AbstractPowerSyncDatabase.getNextCrudTransaction}, which always returns the oldest transaction that hasn't been
718
776
  * {@link CrudTransaction.complete}d yet, this iterator can be used to receive multiple transactions. Calling
719
777
  * {@link CrudTransaction.complete} will mark that and all prior transactions emitted by the iterator as completed.
720
778
  *
@@ -817,8 +875,8 @@ SELECT * FROM crud_entries;
817
875
  * the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
818
876
  * Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
819
877
  *
820
- * @param sql The SQL query to execute
821
- * @param parameters Optional array of parameters to bind to the query
878
+ * @param sql - The SQL query to execute
879
+ * @param parameters - Optional array of parameters to bind to the query
822
880
  * @returns The query result as an object with structured key-value pairs
823
881
  */
824
882
  async execute(sql: string, parameters?: any[]) {
@@ -829,8 +887,8 @@ SELECT * FROM crud_entries;
829
887
  * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
830
888
  * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
831
889
  *
832
- * @param sql The SQL query to execute
833
- * @param parameters Optional array of parameters to bind to the query
890
+ * @param sql - The SQL query to execute
891
+ * @param parameters - Optional array of parameters to bind to the query
834
892
  * @returns The raw query result from the underlying database as a nested array of raw values, where each row is
835
893
  * represented as an array of column values without field names.
836
894
  */
@@ -844,8 +902,8 @@ SELECT * FROM crud_entries;
844
902
  * and optionally return results.
845
903
  * This is faster than executing separately with each parameter set.
846
904
  *
847
- * @param sql The SQL query to execute
848
- * @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
905
+ * @param sql - The SQL query to execute
906
+ * @param parameters - Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
849
907
  * @returns The query result
850
908
  */
851
909
  async executeBatch(sql: string, parameters?: any[][]) {
@@ -856,8 +914,8 @@ SELECT * FROM crud_entries;
856
914
  /**
857
915
  * Execute a read-only query and return results.
858
916
  *
859
- * @param sql The SQL query to execute
860
- * @param parameters Optional array of parameters to bind to the query
917
+ * @param sql - The SQL query to execute
918
+ * @param parameters - Optional array of parameters to bind to the query
861
919
  * @returns An array of results
862
920
  */
863
921
  async getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
@@ -868,8 +926,8 @@ SELECT * FROM crud_entries;
868
926
  /**
869
927
  * Execute a read-only query and return the first result, or null if the ResultSet is empty.
870
928
  *
871
- * @param sql The SQL query to execute
872
- * @param parameters Optional array of parameters to bind to the query
929
+ * @param sql - The SQL query to execute
930
+ * @param parameters - Optional array of parameters to bind to the query
873
931
  * @returns The first result if found, or null if no results are returned
874
932
  */
875
933
  async getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {
@@ -880,8 +938,8 @@ SELECT * FROM crud_entries;
880
938
  /**
881
939
  * Execute a read-only query and return the first result, error if the ResultSet is empty.
882
940
  *
883
- * @param sql The SQL query to execute
884
- * @param parameters Optional array of parameters to bind to the query
941
+ * @param sql - The SQL query to execute
942
+ * @param parameters - Optional array of parameters to bind to the query
885
943
  * @returns The first result matching the query
886
944
  * @throws Error if no rows are returned
887
945
  */
@@ -892,18 +950,18 @@ SELECT * FROM crud_entries;
892
950
 
893
951
  /**
894
952
  * Takes a read lock, without starting a transaction.
895
- * In most cases, {@link readTransaction} should be used instead.
953
+ * In most cases, {@link AbstractPowerSyncDatabase.readTransaction} should be used instead.
896
954
  */
897
- async readLock<T>(callback: (db: DBAdapter) => Promise<T>) {
955
+ async readLock<T>(callback: (db: LockContext) => Promise<T>) {
898
956
  await this.waitForReady();
899
957
  return this.database.readLock(callback);
900
958
  }
901
959
 
902
960
  /**
903
961
  * Takes a global lock, without starting a transaction.
904
- * In most cases, {@link writeTransaction} should be used instead.
962
+ * In most cases, {@link AbstractPowerSyncDatabase.writeTransaction} should be used instead.
905
963
  */
906
- async writeLock<T>(callback: (db: DBAdapter) => Promise<T>) {
964
+ async writeLock<T>(callback: (db: LockContext) => Promise<T>) {
907
965
  await this.waitForReady();
908
966
  return this.database.writeLock(callback);
909
967
  }
@@ -913,8 +971,8 @@ SELECT * FROM crud_entries;
913
971
  * Read transactions can run concurrently to a write transaction.
914
972
  * Changes from any write transaction are not visible to read transactions started before it.
915
973
  *
916
- * @param callback Function to execute within the transaction
917
- * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
974
+ * @param callback - Function to execute within the transaction
975
+ * @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
918
976
  * @returns The result of the callback
919
977
  * @throws Error if the lock cannot be obtained within the timeout period
920
978
  */
@@ -938,8 +996,8 @@ SELECT * FROM crud_entries;
938
996
  * This takes a global lock - only one write transaction can execute against the database at a time.
939
997
  * Statements within the transaction must be done on the provided {@link Transaction} interface.
940
998
  *
941
- * @param callback Function to execute within the transaction
942
- * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
999
+ * @param callback - Function to execute within the transaction
1000
+ * @param lockTimeout - Time in milliseconds to wait for a lock before throwing an error
943
1001
  * @returns The result of the callback
944
1002
  * @throws Error if the lock cannot be obtained within the timeout period
945
1003
  */
@@ -959,8 +1017,8 @@ SELECT * FROM crud_entries;
959
1017
  }
960
1018
 
961
1019
  /**
962
- * This version of `watch` uses {@link AsyncGenerator}, for documentation see {@link watchWithAsyncGenerator}.
963
- * Can be overloaded to use a callback handler instead, for documentation see {@link watchWithCallback}.
1020
+ * This version of `watch` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator}.
1021
+ * Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.watchWithCallback}.
964
1022
  *
965
1023
  * @example
966
1024
  * ```javascript
@@ -976,7 +1034,7 @@ SELECT * FROM crud_entries;
976
1034
  */
977
1035
  watch(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult>;
978
1036
  /**
979
- * See {@link watchWithCallback}.
1037
+ * See {@link AbstractPowerSyncDatabase.watchWithCallback}.
980
1038
  *
981
1039
  * @example
982
1040
  * ```javascript
@@ -1037,7 +1095,7 @@ SELECT * FROM crud_entries;
1037
1095
  parameters
1038
1096
  }),
1039
1097
  execute: async ({ sql, parameters }) => {
1040
- const result = await this.getAll(sql, parameters);
1098
+ const result = await this.getAll<Record<string, any>>(sql, parameters);
1041
1099
  return mapper ? result.map(mapper) : (result as RowType[]);
1042
1100
  }
1043
1101
  };
@@ -1068,15 +1126,15 @@ SELECT * FROM crud_entries;
1068
1126
 
1069
1127
  /**
1070
1128
  * Execute a read query every time the source tables are modified.
1071
- * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
1129
+ * Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
1072
1130
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
1073
1131
  *
1074
1132
  * Note that the `onChange` callback member of the handler is required.
1075
1133
  *
1076
- * @param sql The SQL query to execute
1077
- * @param parameters Optional array of parameters to bind to the query
1078
- * @param handler Callbacks for handling results and errors
1079
- * @param options Options for configuring watch behavior
1134
+ * @param sql - The SQL query to execute
1135
+ * @param parameters - Optional array of parameters to bind to the query
1136
+ * @param handler - Callbacks for handling results and errors
1137
+ * @param options - Options for configuring watch behavior
1080
1138
  */
1081
1139
  watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void {
1082
1140
  const { onResult, onError = (e: Error) => this.logger.error(e) } = handler ?? {};
@@ -1090,7 +1148,7 @@ SELECT * FROM crud_entries;
1090
1148
  const watchedQuery = new OnChangeQueryProcessor({
1091
1149
  db: this,
1092
1150
  comparator,
1093
- placeholderData: null,
1151
+ placeholderData: null as unknown as QueryResult, // FIXME
1094
1152
  watchOptions: {
1095
1153
  query: {
1096
1154
  compile: () => ({
@@ -1126,12 +1184,12 @@ SELECT * FROM crud_entries;
1126
1184
 
1127
1185
  /**
1128
1186
  * Execute a read query every time the source tables are modified.
1129
- * Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
1187
+ * Use {@link SQLOnChangeOptions.throttleMs} to specify the minimum interval between queries.
1130
1188
  * Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
1131
1189
  *
1132
- * @param sql The SQL query to execute
1133
- * @param parameters Optional array of parameters to bind to the query
1134
- * @param options Options for configuring watch behavior
1190
+ * @param sql - The SQL query to execute
1191
+ * @param parameters - Optional array of parameters to bind to the query
1192
+ * @param options - Options for configuring watch behavior
1135
1193
  * @returns An AsyncIterable that yields QueryResults whenever the data changes
1136
1194
  */
1137
1195
  watchWithAsyncGenerator(sql: string, parameters?: any[], options?: SQLWatchOptions): AsyncIterable<QueryResult> {
@@ -1158,9 +1216,9 @@ SELECT * FROM crud_entries;
1158
1216
  * If tables are specified in the options, those are used directly.
1159
1217
  * Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
1160
1218
  *
1161
- * @param sql The SQL query to analyze
1162
- * @param parameters Optional parameters for the SQL query
1163
- * @param options Optional watch options that may contain explicit table list
1219
+ * @param sql - The SQL query to analyze
1220
+ * @param parameters - Optional parameters for the SQL query
1221
+ * @param options - Optional watch options that may contain explicit table list
1164
1222
  * @returns Array of table names that the query depends on
1165
1223
  */
1166
1224
  async resolveTables(sql: string, parameters?: any[], options?: SQLWatchOptions): Promise<string[]> {
@@ -1183,8 +1241,8 @@ SELECT * FROM crud_entries;
1183
1241
  }
1184
1242
 
1185
1243
  /**
1186
- * This version of `onChange` uses {@link AsyncGenerator}, for documentation see {@link onChangeWithAsyncGenerator}.
1187
- * Can be overloaded to use a callback handler instead, for documentation see {@link onChangeWithCallback}.
1244
+ * This version of `onChange` uses `AsyncGenerator`, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithAsyncGenerator}.
1245
+ * Can be overloaded to use a callback handler instead, for documentation see {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
1188
1246
  *
1189
1247
  * @example
1190
1248
  * ```javascript
@@ -1197,7 +1255,7 @@ SELECT * FROM crud_entries;
1197
1255
  */
1198
1256
  onChange(options?: SQLOnChangeOptions): AsyncIterable<WatchOnChangeEvent>;
1199
1257
  /**
1200
- * See {@link onChangeWithCallback}.
1258
+ * See {@link AbstractPowerSyncDatabase.onChangeWithCallback}.
1201
1259
  *
1202
1260
  * @example
1203
1261
  * ```javascript
@@ -1230,13 +1288,13 @@ SELECT * FROM crud_entries;
1230
1288
  /**
1231
1289
  * Invoke the provided callback on any changes to any of the specified tables.
1232
1290
  *
1233
- * This is preferred over {@link watchWithCallback} when multiple queries need to be performed
1291
+ * This is preferred over {@link AbstractPowerSyncDatabase.watchWithCallback} when multiple queries need to be performed
1234
1292
  * together when data is changed.
1235
1293
  *
1236
1294
  * Note that the `onChange` callback member of the handler is required.
1237
1295
  *
1238
- * @param handler Callbacks for handling change events and errors
1239
- * @param options Options for configuring watch behavior
1296
+ * @param handler - Callbacks for handling change events and errors
1297
+ * @param options - Options for configuring watch behavior
1240
1298
  * @returns A dispose function to stop watching for changes
1241
1299
  */
1242
1300
  onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void {
@@ -1275,7 +1333,7 @@ SELECT * FROM crud_entries;
1275
1333
  try {
1276
1334
  this.processTableUpdates(update, changedTables);
1277
1335
  flushTableUpdates();
1278
- } catch (error) {
1336
+ } catch (error: any) {
1279
1337
  onError?.(error);
1280
1338
  }
1281
1339
  }
@@ -1292,12 +1350,12 @@ SELECT * FROM crud_entries;
1292
1350
  /**
1293
1351
  * Create a Stream of changes to any of the specified tables.
1294
1352
  *
1295
- * This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be performed
1296
- * together when data is changed.
1353
+ * This is preferred over {@link AbstractPowerSyncDatabase.watchWithAsyncGenerator} when multiple queries need to be
1354
+ * performed together when data is changed.
1297
1355
  *
1298
1356
  * Note: do not declare this as `async *onChange` as it will not work in React Native.
1299
1357
  *
1300
- * @param options Options for configuring watch behavior
1358
+ * @param options - Options for configuring watch behavior
1301
1359
  * @returns An AsyncIterable that yields change events whenever the specified tables change
1302
1360
  */
1303
1361
  onChangeWithAsyncGenerator(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent> {
@@ -1352,9 +1410,6 @@ SELECT * FROM crud_entries;
1352
1410
  }
1353
1411
  }
1354
1412
 
1355
- /**
1356
- * @ignore
1357
- */
1358
1413
  private async executeReadOnly(sql: string, params?: any[]) {
1359
1414
  await this.waitForReady();
1360
1415
  return this.database.readLock((tx) => tx.execute(sql, params));
@@ -4,11 +4,17 @@ import { Schema } from '../db/schema/Schema.js';
4
4
  import { AbstractPowerSyncDatabase, PowerSyncDatabaseOptions } from './AbstractPowerSyncDatabase.js';
5
5
  import { SQLOpenOptions } from './SQLOpenFactory.js';
6
6
 
7
+ /**
8
+ * @internal
9
+ */
7
10
  export interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions>, SQLOpenOptions {
8
11
  /** Schema used for the local database. */
9
12
  schema: Schema;
10
13
  }
11
14
 
15
+ /**
16
+ * @internal
17
+ */
12
18
  export abstract class AbstractPowerSyncDatabaseOpenFactory {
13
19
  constructor(protected options: PowerSyncOpenFactoryOptions) {
14
20
  options.logger = options.logger ?? Logger.get(`PowerSync ${this.options.dbFilename}`);
@@ -36,6 +36,9 @@ export interface CreateSyncImplementationOptions extends AdditionalConnectionOpt
36
36
  subscriptions: SubscribedStream[];
37
37
  }
38
38
 
39
+ /**
40
+ * @internal
41
+ */
39
42
  export interface InternalSubscriptionAdapter {
40
43
  firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
41
44
  resolveOfflineSyncStatus(): Promise<void>;
@@ -243,7 +246,7 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
243
246
  /**
244
247
  * Close the sync connection.
245
248
  *
246
- * Use {@link connect} to connect again.
249
+ * Use {@link ConnectionManager.connect} to connect again.
247
250
  */
248
251
  async disconnect() {
249
252
  // This will help abort pending connects
@@ -8,12 +8,16 @@ import { WatchedQueryOptions } from './watched/WatchedQuery.js';
8
8
 
9
9
  /**
10
10
  * Query parameters for {@link ArrayQueryDefinition#parameters}
11
+ *
12
+ * @public
11
13
  */
12
14
  export type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
13
15
 
14
16
  /**
15
17
  * Options for building a query with {@link AbstractPowerSyncDatabase#query}.
16
18
  * This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
19
+ *
20
+ * @public
17
21
  */
18
22
  export interface ArrayQueryDefinition<RowType = unknown> {
19
23
  sql: string;
@@ -33,6 +37,8 @@ export interface ArrayQueryDefinition<RowType = unknown> {
33
37
 
34
38
  /**
35
39
  * Options for {@link Query#watch}.
40
+ *
41
+ * @public
36
42
  */
37
43
  export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
38
44
  /**
@@ -59,6 +65,9 @@ export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOption
59
65
  placeholderData?: RowType[];
60
66
  }
61
67
 
68
+ /**
69
+ * @public
70
+ */
62
71
  export interface Query<RowType> {
63
72
  /**
64
73
  * Creates a {@link WatchedQuery} which watches and emits results of the linked query.
@@ -1,5 +1,8 @@
1
1
  import { DBAdapter } from '../db/DBAdapter.js';
2
2
 
3
+ /**
4
+ * @public
5
+ */
3
6
  export interface SQLOpenOptions {
4
7
  /**
5
8
  * Filename for the database.
@@ -25,6 +28,9 @@ export interface SQLOpenOptions {
25
28
  debugMode?: boolean;
26
29
  }
27
30
 
31
+ /**
32
+ * @public
33
+ */
28
34
  export interface SQLOpenFactory {
29
35
  /**
30
36
  * Opens a connection adapter to a SQLite DB
@@ -34,6 +40,8 @@ export interface SQLOpenFactory {
34
40
 
35
41
  /**
36
42
  * Tests if the input is a {@link SQLOpenOptions}
43
+ *
44
+ * @internal
37
45
  */
38
46
  export const isSQLOpenOptions = (test: any): test is SQLOpenOptions => {
39
47
  // typeof null is `object`, but you cannot use the `in` operator on `null.
@@ -42,6 +50,8 @@ export const isSQLOpenOptions = (test: any): test is SQLOpenOptions => {
42
50
 
43
51
  /**
44
52
  * Tests if input is a {@link SQLOpenFactory}
53
+ *
54
+ * @internal
45
55
  */
46
56
  export const isSQLOpenFactory = (test: any): test is SQLOpenFactory => {
47
57
  return typeof test?.openDB == 'function';
@@ -49,6 +59,8 @@ export const isSQLOpenFactory = (test: any): test is SQLOpenFactory => {
49
59
 
50
60
  /**
51
61
  * Tests if input is a {@link DBAdapter}
62
+ *
63
+ * @internal
52
64
  */
53
65
  export const isDBAdapter = (test: any): test is DBAdapter => {
54
66
  return typeof test?.writeTransaction == 'function';
@@ -2,11 +2,17 @@ import { CompilableQuery } from './../types/types.js';
2
2
  import { AbstractPowerSyncDatabase, SQLWatchOptions } from './AbstractPowerSyncDatabase.js';
3
3
  import { runOnSchemaChange } from './runOnSchemaChange.js';
4
4
 
5
+ /**
6
+ * @public
7
+ */
5
8
  export interface CompilableQueryWatchHandler<T> {
6
9
  onResult: (results: T[]) => void;
7
10
  onError?: (error: Error) => void;
8
11
  }
9
12
 
13
+ /**
14
+ * @public
15
+ */
10
16
  export function compilableQueryWatch<T>(
11
17
  db: AbstractPowerSyncDatabase,
12
18
  query: CompilableQuery<T>,
@@ -1,6 +1,9 @@
1
1
  import { PowerSyncCredentials } from './PowerSyncCredentials.js';
2
2
  import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
3
3
 
4
+ /**
5
+ * @public
6
+ */
4
7
  export interface PowerSyncBackendConnector {
5
8
  /** Allows the PowerSync client to retrieve an authentication token from your backend
6
9
  * which is used to authenticate against the PowerSync service.
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
1
4
  export interface PowerSyncCredentials {
2
5
  endpoint: string;
3
6
  token: string;
@@ -1 +1,4 @@
1
+ /**
2
+ * @internal
3
+ */
1
4
  export const MAX_OP_ID = '9223372036854775807';