@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
@@ -12,6 +12,8 @@ import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver.js';
12
12
 
13
13
  /**
14
14
  * Object returned by SQL Query executions.
15
+ *
16
+ * @public
15
17
  */
16
18
  export type QueryResult = {
17
19
  /** Represents the auto-generated row id if applicable. */
@@ -31,13 +33,16 @@ export type QueryResult = {
31
33
  /** The length of the dataset */
32
34
  length: number;
33
35
  /** A convenience function to acess the index based the row object
34
- * @param idx the row index
36
+ * @param idx - the row index
35
37
  * @returns the row structure identified by column names
36
38
  */
37
39
  item: (idx: number) => any;
38
40
  };
39
41
  };
40
42
 
43
+ /**
44
+ * @public
45
+ */
41
46
  export interface DBGetUtils {
42
47
  /** Execute a read-only query and return results. */
43
48
  getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
@@ -47,6 +52,9 @@ export interface DBGetUtils {
47
52
  get<T>(sql: string, parameters?: any[]): Promise<T>;
48
53
  }
49
54
 
55
+ /**
56
+ * @public
57
+ */
50
58
  export interface SqlExecutor {
51
59
  /** Execute a single write statement. */
52
60
  execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
@@ -58,17 +66,24 @@ export interface SqlExecutor {
58
66
  *
59
67
  * Example result:
60
68
  *
61
- * ```[ [ '1', 'list 1', '33', 'Post content', '1' ] ]```
69
+ * ```JavaScript
70
+ * [ [ '1', 'list 1', '33', 'Post content', '1' ] ]
71
+ * ```
62
72
  *
63
73
  * Where as `execute`'s `rows._array` would have been:
64
74
  *
65
- * ```[ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]```
75
+ * ```JavaScript
76
+ * [ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]
77
+ * ```
66
78
  */
67
79
  executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
68
80
 
69
81
  executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
70
82
  }
71
83
 
84
+ /**
85
+ * @public
86
+ */
72
87
  export interface LockContext extends SqlExecutor, DBGetUtils {
73
88
  /**
74
89
  * How the connection has been opened.
@@ -82,7 +97,9 @@ export interface LockContext extends SqlExecutor, DBGetUtils {
82
97
  }
83
98
 
84
99
  /**
85
- * Implements {@link DBGetUtils} on a {@link SqlRunner}.
100
+ * Implements {@link DBGetUtils} on a {@link SqlExecutor}.
101
+ *
102
+ * @internal
86
103
  */
87
104
  export function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omit<SqlExecutor, 'executeBatch'>>(
88
105
  Base: TBase
@@ -132,6 +149,9 @@ export function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omi
132
149
  };
133
150
  }
134
151
 
152
+ /**
153
+ * @public
154
+ */
135
155
  export interface Transaction extends LockContext {
136
156
  /** Commit multiple changes to the local DB using the Transaction context. */
137
157
  commit: () => Promise<QueryResult>;
@@ -141,29 +161,44 @@ export interface Transaction extends LockContext {
141
161
 
142
162
  /**
143
163
  * Update table operation numbers from SQLite
164
+ *
165
+ * @public
144
166
  */
145
167
  export enum RowUpdateType {
146
168
  SQLITE_INSERT = 18,
147
169
  SQLITE_DELETE = 9,
148
170
  SQLITE_UPDATE = 23
149
171
  }
172
+
173
+ /**
174
+ * @public
175
+ */
150
176
  export interface TableUpdateOperation {
151
177
  opType: RowUpdateType;
152
178
  rowId: number;
153
179
  }
154
180
  /**
155
181
  * Notification of an update to one or more tables, for the purpose of realtime change notifications.
182
+ *
183
+ * @public
156
184
  */
157
185
  export interface UpdateNotification extends TableUpdateOperation {
158
186
  table: string;
159
187
  }
160
188
 
189
+ /**
190
+ * @public
191
+ */
161
192
  export interface BatchedUpdateNotification {
193
+ // TODO (breaking change): Normalize to only including tables
162
194
  rawUpdates: UpdateNotification[];
163
195
  tables: string[];
164
196
  groupedUpdates: Record<string, TableUpdateOperation[]>;
165
197
  }
166
198
 
199
+ /**
200
+ * @public
201
+ */
167
202
  export interface DBAdapterListener extends BaseListener {
168
203
  /**
169
204
  * Listener for table updates.
@@ -174,10 +209,16 @@ export interface DBAdapterListener extends BaseListener {
174
209
  tablesUpdated: (updateNotification: BatchedUpdateNotification | UpdateNotification) => void;
175
210
  }
176
211
 
212
+ /**
213
+ * @public
214
+ */
177
215
  export interface DBLockOptions {
178
216
  timeoutMs?: number;
179
217
  }
180
218
 
219
+ /**
220
+ * @public
221
+ */
181
222
  export interface ConnectionPool extends BaseObserverInterface<DBAdapterListener> {
182
223
  name: string;
183
224
  close: () => void | Promise<void>;
@@ -190,14 +231,19 @@ export interface ConnectionPool extends BaseObserverInterface<DBAdapterListener>
190
231
  refreshSchema: () => Promise<void>;
191
232
  }
192
233
 
234
+ /**
235
+ * @public
236
+ */
193
237
  export interface DBAdapter extends ConnectionPool, SqlExecutor, DBGetUtils {
194
238
  readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
195
239
  writeTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
196
240
  }
197
241
 
198
242
  /**
199
- * A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
200
- * {@link ConnectionPool.writeLock}.
243
+ * A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool#readLock} and
244
+ * {@link ConnectionPool#writeLock}.
245
+ *
246
+ * @internal
201
247
  */
202
248
  export function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase) {
203
249
  return class extends Base implements DBAdapter {
@@ -299,12 +345,18 @@ class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction)
299
345
  }
300
346
  }
301
347
 
348
+ /**
349
+ * @internal
350
+ */
302
351
  export function isBatchedUpdateNotification(
303
352
  update: BatchedUpdateNotification | UpdateNotification
304
353
  ): update is BatchedUpdateNotification {
305
354
  return 'tables' in update;
306
355
  }
307
356
 
357
+ /**
358
+ * @internal
359
+ */
308
360
  export function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification) {
309
361
  return isBatchedUpdateNotification(update) ? update.tables : [update.table];
310
362
  }
@@ -15,6 +15,8 @@ export const FULL_SYNC_PRIORITY = 2147483647;
15
15
  *
16
16
  * To obtain these values, use {@link SyncProgress}, available through
17
17
  * {@link SyncStatus#downloadProgress}.
18
+ *
19
+ * @public
18
20
  */
19
21
  export interface ProgressWithOperations {
20
22
  /**
@@ -28,7 +30,8 @@ export interface ProgressWithOperations {
28
30
  downloadedOperations: number;
29
31
 
30
32
  /**
31
- * Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
33
+ * Relative progress, as {@link ProgressWithOperations.downloadedOperations} of
34
+ * {@link ProgressWithOperations.totalOperations}.
32
35
  *
33
36
  * This will be a number between `0.0` and `1.0` (inclusive).
34
37
  *
@@ -58,6 +61,8 @@ export interface ProgressWithOperations {
58
61
  *
59
62
  * Also note that data is downloaded in bulk, which means that individual counters are unlikely
60
63
  * to be updated one-by-one.
64
+ *
65
+ * @public
61
66
  */
62
67
  export class SyncProgress implements ProgressWithOperations {
63
68
  totalOperations: number;
@@ -3,6 +3,9 @@ import { CoreStreamSubscription } from '../../client/sync/stream/core-instructio
3
3
  import { SyncStreamDescription, SyncSubscriptionDescription } from '../../client/sync/sync-streams.js';
4
4
  import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js';
5
5
 
6
+ /**
7
+ * @public
8
+ */
6
9
  export type SyncDataFlowStatus = Partial<{
7
10
  downloading: boolean;
8
11
  uploading: boolean;
@@ -20,18 +23,27 @@ export type SyncDataFlowStatus = Partial<{
20
23
  /**
21
24
  * Internal information about how far we are downloading operations in buckets.
22
25
  *
23
- * Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
26
+ * @internal Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
24
27
  */
25
28
  downloadProgress: InternalProgressInformation | null;
29
+ /**
30
+ * @internal
31
+ */
26
32
  internalStreamSubscriptions: CoreStreamSubscription[] | null;
27
33
  }>;
28
34
 
35
+ /**
36
+ * @public
37
+ */
29
38
  export interface SyncPriorityStatus {
30
39
  priority: number;
31
40
  lastSyncedAt?: Date;
32
41
  hasSynced?: boolean;
33
42
  }
34
43
 
44
+ /**
45
+ * @internal
46
+ */
35
47
  export type SyncStatusOptions = {
36
48
  connected?: boolean;
37
49
  connecting?: boolean;
@@ -45,6 +57,9 @@ export type SyncStatusOptions = {
45
57
  clientImplementation?: SyncClientImplementation;
46
58
  };
47
59
 
60
+ /**
61
+ * @public
62
+ */
48
63
  export class SyncStatus {
49
64
  constructor(protected options: SyncStatusOptions) {}
50
65
 
@@ -53,6 +68,8 @@ export class SyncStatus {
53
68
  * implementation).
54
69
  *
55
70
  * This information is only available after a connection has been requested.
71
+ *
72
+ * @deprecated This always returns the Rust client (the only option).
56
73
  */
57
74
  get clientImplementation() {
58
75
  return this.options.clientImplementation;
@@ -61,18 +78,18 @@ export class SyncStatus {
61
78
  /**
62
79
  * Indicates if the client is currently connected to the PowerSync service.
63
80
  *
64
- * @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
81
+ * @returns True if connected, false otherwise. Defaults to false if not specified.
65
82
  */
66
- get connected() {
83
+ get connected(): boolean {
67
84
  return this.options.connected ?? false;
68
85
  }
69
86
 
70
87
  /**
71
88
  * Indicates if the client is in the process of establishing a connection to the PowerSync service.
72
89
  *
73
- * @returns {boolean} True if connecting, false otherwise. Defaults to false if not specified.
90
+ * @returns True if connecting, false otherwise. Defaults to false if not specified.
74
91
  */
75
- get connecting() {
92
+ get connecting(): boolean {
76
93
  return this.options.connecting ?? false;
77
94
  }
78
95
 
@@ -80,31 +97,31 @@ export class SyncStatus {
80
97
  * Time that a last sync has fully completed, if any.
81
98
  * This timestamp is reset to null after a restart of the PowerSync service.
82
99
  *
83
- * @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
100
+ * @returns The timestamp of the last successful sync, or undefined if no sync has completed.
84
101
  */
85
- get lastSyncedAt() {
102
+ get lastSyncedAt(): Date | undefined {
86
103
  return this.options.lastSyncedAt;
87
104
  }
88
105
 
89
106
  /**
90
107
  * Indicates whether there has been at least one full sync completed since initialization.
91
108
  *
92
- * @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
109
+ * @returns True if at least one sync has completed, false if no sync has completed,
93
110
  * or undefined when the state is still being loaded from the database.
94
111
  */
95
- get hasSynced() {
112
+ get hasSynced(): boolean | undefined {
96
113
  return this.options.hasSynced;
97
114
  }
98
115
 
99
116
  /**
100
117
  * Provides the current data flow status regarding uploads and downloads.
101
118
  *
102
- * @returns {SyncDataFlowStatus} An object containing:
119
+ * @returns An object containing:
103
120
  * - downloading: True if actively downloading changes (only when connected is also true)
104
121
  * - uploading: True if actively uploading changes
105
- * Defaults to {downloading: false, uploading: false} if not specified.
122
+ * Defaults to `{downloading: false, uploading: false}` if not specified.
106
123
  */
107
- get dataFlowStatus() {
124
+ get dataFlowStatus(): SyncDataFlowStatus {
108
125
  return (
109
126
  this.options.dataFlow ?? {
110
127
  /**
@@ -131,7 +148,7 @@ export class SyncStatus {
131
148
  }
132
149
 
133
150
  /**
134
- * If the `stream` appears in {@link syncStreams}, returns the current status for that stream.
151
+ * If the `stream` appears in {@link SyncStatus.syncStreams}, returns the current status for that stream.
135
152
  */
136
153
  forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined {
137
154
  const asJson = JSON.stringify(stream.parameters);
@@ -145,10 +162,10 @@ export class SyncStatus {
145
162
  /**
146
163
  * Provides sync status information for all bucket priorities, sorted by priority (highest first).
147
164
  *
148
- * @returns {SyncPriorityStatus[]} An array of status entries for different sync priority levels,
165
+ * @returns An array of status entries for different sync priority levels,
149
166
  * sorted with highest priorities (lower numbers) first.
150
167
  */
151
- get priorityStatusEntries() {
168
+ get priorityStatusEntries(): SyncPriorityStatus[] {
152
169
  return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
153
170
  }
154
171
 
@@ -183,8 +200,8 @@ export class SyncStatus {
183
200
  * For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
184
201
  * with a priority of 1 may return information for priority level 3.
185
202
  *
186
- * @param {number} priority The bucket priority for which the status should be reported
187
- * @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
203
+ * @param priority - The bucket priority for which the status should be reported
204
+ * @returns Status information for the requested priority level or the next higher level with available status
188
205
  */
189
206
  statusForPriority(priority: number): SyncPriorityStatus {
190
207
  // priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
@@ -207,8 +224,8 @@ export class SyncStatus {
207
224
  * Compares this SyncStatus instance with another to determine if they are equal.
208
225
  * Equality is determined by comparing the serialized JSON representation of both instances.
209
226
  *
210
- * @param {SyncStatus} status The SyncStatus instance to compare against
211
- * @returns {boolean} True if the instances are considered equal, false otherwise
227
+ * @param status - The SyncStatus instance to compare against
228
+ * @returns True if the instances are considered equal, false otherwise
212
229
  */
213
230
  isEqual(status: SyncStatus) {
214
231
  /**
@@ -233,7 +250,7 @@ export class SyncStatus {
233
250
  * Creates a human-readable string representation of the current sync status.
234
251
  * Includes information about connection state, sync completion, and data flow.
235
252
  *
236
- * @returns {string} A string representation of the sync status
253
+ * @returns A string representation of the sync status
237
254
  */
238
255
  getMessage() {
239
256
  const dataFlow = this.dataFlowStatus;
@@ -243,7 +260,7 @@ export class SyncStatus {
243
260
  /**
244
261
  * Serializes the SyncStatus instance to a plain object.
245
262
  *
246
- * @returns {SyncStatusOptions} A plain object representation of the sync status
263
+ * @returns A plain object representation of the sync status
247
264
  */
248
265
  toJSON(): SyncStatusOptions {
249
266
  return {
@@ -282,6 +299,8 @@ export class SyncStatus {
282
299
 
283
300
  /**
284
301
  * Information about a sync stream subscription.
302
+ *
303
+ * @public
285
304
  */
286
305
  export interface SyncStreamStatus {
287
306
  progress: ProgressWithOperations | null;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
1
4
  export class UploadQueueStats {
2
5
  constructor(
3
6
  /**
@@ -1,21 +1,36 @@
1
- // https://www.sqlite.org/lang_expr.html#castexpr
1
+ /**
2
+ * @see https://www.sqlite.org/lang_expr.html#castexpr
3
+ * @public
4
+ */
2
5
  export enum ColumnType {
3
6
  TEXT = 'TEXT',
4
7
  INTEGER = 'INTEGER',
5
8
  REAL = 'REAL'
6
9
  }
7
10
 
11
+ /**
12
+ * @public
13
+ */
8
14
  export interface ColumnOptions {
9
15
  name: string;
10
16
  type?: ColumnType;
11
17
  }
12
18
 
19
+ /**
20
+ * @public
21
+ */
13
22
  export type BaseColumnType<T extends number | string | null> = {
14
23
  type: ColumnType;
15
24
  };
16
25
 
26
+ /**
27
+ * @public
28
+ */
17
29
  export type ColumnsType = Record<string, BaseColumnType<any>>;
18
30
 
31
+ /**
32
+ * @public
33
+ */
19
34
  export type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
20
35
 
21
36
  const text: BaseColumnType<string | null> = {
@@ -30,16 +45,26 @@ const real: BaseColumnType<number | null> = {
30
45
  type: ColumnType.REAL
31
46
  };
32
47
 
33
- // powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
34
- // In earlier versions this was limited to 63.
48
+ /**
49
+ * powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
50
+ * In earlier versions this was limited to 63.
51
+ *
52
+ * @internal
53
+ */
35
54
  export const MAX_AMOUNT_OF_COLUMNS = 1999;
36
55
 
56
+ /**
57
+ * @public
58
+ */
37
59
  export const column = {
38
60
  text,
39
61
  integer,
40
62
  real
41
63
  };
42
64
 
65
+ /**
66
+ * @public
67
+ */
43
68
  export class Column {
44
69
  constructor(protected options: ColumnOptions) {}
45
70
 
@@ -1,15 +1,24 @@
1
1
  import { IndexedColumn } from './IndexedColumn.js';
2
2
  import { Table } from './Table.js';
3
3
 
4
+ /**
5
+ * @public
6
+ */
4
7
  export interface IndexOptions {
5
8
  name: string;
6
9
  columns?: IndexedColumn[];
7
10
  }
8
11
 
12
+ /**
13
+ * @internal
14
+ */
9
15
  export const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
10
16
  columns: []
11
17
  };
12
18
 
19
+ /**
20
+ * @public
21
+ */
13
22
  export class Index {
14
23
  static createAscending(options: IndexOptions, columnNames: string[]) {
15
24
  return new Index({
@@ -1,15 +1,24 @@
1
1
  import { ColumnType } from './Column.js';
2
2
  import { Table } from './Table.js';
3
3
 
4
+ /**
5
+ * @public
6
+ */
4
7
  export interface IndexColumnOptions {
5
8
  name: string;
6
9
  ascending?: boolean;
7
10
  }
8
11
 
12
+ /**
13
+ * @internal
14
+ */
9
15
  export const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
10
16
  ascending: true
11
17
  };
12
18
 
19
+ /**
20
+ * @public
21
+ */
13
22
  export class IndexedColumn {
14
23
  protected options: IndexColumnOptions;
15
24
 
@@ -7,8 +7,10 @@ import { TableOrRawTableOptions } from './Table.js';
7
7
  * using client-side table and column constraints.
8
8
  *
9
9
  * To collect local writes to raw tables with PowerSync, custom triggers are required. See
10
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
10
+ * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables} for details and an example on
11
11
  * using raw tables.
12
+ *
13
+ * @public
12
14
  */
13
15
  export type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
14
16
 
@@ -70,11 +72,15 @@ interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
70
72
  * `{Column: 'name'}`.
71
73
  * The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
72
74
  * covered by a `Column` parameter.
75
+ *
76
+ * @public
73
77
  */
74
78
  export type PendingStatementParameter = 'Id' | { Column: string } | 'Rest';
75
79
 
76
80
  /**
77
81
  * A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
82
+ *
83
+ * @public
78
84
  */
79
85
  export type PendingStatement = {
80
86
  sql: string;
@@ -4,19 +4,24 @@ import { RowType, Table } from './Table.js';
4
4
 
5
5
  type SchemaType = Record<string, Table<any>>;
6
6
 
7
+ /**
8
+ * @public
9
+ */
7
10
  export type SchemaTableType<S extends SchemaType> = {
8
11
  [K in keyof S]: RowType<S[K]>;
9
12
  };
10
13
 
11
14
  /**
12
15
  * A schema is a collection of tables. It is used to define the structure of a database.
16
+ *
17
+ * @public
13
18
  */
14
19
  export class Schema<S extends SchemaType = SchemaType> {
15
20
  /*
16
21
  Only available when constructing with mapped typed definition columns
17
22
  */
18
- readonly types: SchemaTableType<S>;
19
- readonly props: S;
23
+ readonly types!: SchemaTableType<S>;
24
+ readonly props!: S;
20
25
  readonly tables: Table[];
21
26
  readonly rawTables: RawTable[];
22
27
 
@@ -52,7 +57,7 @@ export class Schema<S extends SchemaType = SchemaType> {
52
57
  * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
53
58
  * using client-side table and column constraints.
54
59
  *
55
- * @param tables An object of (table name, raw table definition) entries.
60
+ * @param tables - An object of (table name, raw table definition) entries.
56
61
  */
57
62
  withRawTables(tables: Record<string, RawTableType>) {
58
63
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
@@ -13,6 +13,8 @@ import { TableV2 } from './TableV2.js';
13
13
 
14
14
  /**
15
15
  * Options that apply both to JSON-based tables and raw tables.
16
+ *
17
+ * @public
16
18
  */
17
19
  export interface TableOrRawTableOptions {
18
20
  localOnly?: boolean;
@@ -30,6 +32,8 @@ interface SharedTableOptions extends TableOrRawTableOptions {
30
32
  *
31
33
  * Including old values may be helpful for some backend connector implementations, which is
32
34
  * why it can be enabled on per-table or per-columm basis.
35
+ *
36
+ * @public
33
37
  */
34
38
  export interface TrackPreviousOptions {
35
39
  /** When defined, a list of column names for which old values should be tracked. */
@@ -38,6 +42,9 @@ export interface TrackPreviousOptions {
38
42
  onlyWhenChanged?: boolean;
39
43
  }
40
44
 
45
+ /**
46
+ * @public
47
+ */
41
48
  export interface TableOptions extends SharedTableOptions {
42
49
  /**
43
50
  * The synced table name, matching sync rules
@@ -47,18 +54,31 @@ export interface TableOptions extends SharedTableOptions {
47
54
  indexes?: Index[];
48
55
  }
49
56
 
57
+ /**
58
+ * @public
59
+ */
50
60
  export type RowType<T extends TableV2<any>> = {
51
61
  [K in keyof T['columnMap']]: ExtractColumnValueType<T['columnMap'][K]>;
52
62
  } & {
53
63
  id: string;
54
64
  };
55
65
 
66
+ /**
67
+ * @public
68
+ */
56
69
  export type IndexShorthand = Record<string, string[]>;
57
70
 
71
+ /**
72
+ * @public
73
+ */
74
+
58
75
  export interface TableV2Options extends SharedTableOptions {
59
76
  indexes?: IndexShorthand;
60
77
  }
61
78
 
79
+ /**
80
+ * @internal
81
+ */
62
82
  export const DEFAULT_TABLE_OPTIONS = {
63
83
  indexes: [],
64
84
  insertOnly: false,
@@ -68,12 +88,18 @@ export const DEFAULT_TABLE_OPTIONS = {
68
88
  ignoreEmptyUpdates: false
69
89
  };
70
90
 
91
+ /**
92
+ * @internal
93
+ */
71
94
  export const InvalidSQLCharacters = /["'%,.#\s[\]]/;
72
95
 
96
+ /**
97
+ * @public
98
+ */
73
99
  export class Table<Columns extends ColumnsType = ColumnsType> {
74
- protected options: TableOptions;
100
+ protected options!: TableOptions;
75
101
 
76
- protected _mappedColumns: Columns;
102
+ protected _mappedColumns!: Columns;
77
103
 
78
104
  static createLocalOnly(options: TableOptions) {
79
105
  return new Table({ ...options, localOnly: true, insertOnly: false });
@@ -108,9 +134,8 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
108
134
  * 1. New constructor: Using a Columns object and an optional TableV2Options object
109
135
  * 2. Deprecated constructor: Using a TableOptions object (will be removed in the next major release)
110
136
  *
111
- * @constructor
112
- * @param {Columns | TableOptions} optionsOrColumns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax)
113
- * @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax
137
+ * @param columns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax)
138
+ * @param options - Optional configuration options for V2 syntax
114
139
  *
115
140
  * @example
116
141
  * ```javascript
@@ -5,5 +5,7 @@ import { Table } from './Table.js';
5
5
  Generate a new table from the columns and indexes
6
6
  @deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
7
7
  This will be removed in the next major release.
8
+
9
+ @public
8
10
  */
9
11
  export class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {}