@powersync/common 1.53.2 → 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 (213) hide show
  1. package/dist/bundle.cjs +548 -345
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +548 -345
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +548 -345
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +548 -345
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +727 -189
  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 +55 -5
  68. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +32 -4
  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/mutex.d.ts +8 -0
  148. package/lib/utils/mutex.js +3 -0
  149. package/lib/utils/mutex.js.map +1 -1
  150. package/lib/utils/parseQuery.d.ts +6 -0
  151. package/lib/utils/parseQuery.js +3 -0
  152. package/lib/utils/parseQuery.js.map +1 -1
  153. package/lib/utils/stream_transform.d.ts +3 -1
  154. package/lib/utils/stream_transform.js.map +1 -1
  155. package/package.json +3 -2
  156. package/src/attachments/AttachmentContext.ts +7 -6
  157. package/src/attachments/AttachmentErrorHandler.ts +6 -6
  158. package/src/attachments/AttachmentQueue.ts +71 -23
  159. package/src/attachments/LocalStorageAdapter.ts +14 -8
  160. package/src/attachments/README.md +2 -0
  161. package/src/attachments/RemoteStorageAdapter.ts +4 -4
  162. package/src/attachments/Schema.ts +12 -4
  163. package/src/attachments/WatchedAttachmentItem.ts +3 -1
  164. package/src/client/AbstractPowerSyncDatabase.ts +117 -62
  165. package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
  166. package/src/client/ConnectionManager.ts +4 -1
  167. package/src/client/Query.ts +9 -0
  168. package/src/client/SQLOpenFactory.ts +12 -0
  169. package/src/client/compilableQueryWatch.ts +6 -0
  170. package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
  171. package/src/client/connection/PowerSyncCredentials.ts +3 -0
  172. package/src/client/constants.ts +3 -0
  173. package/src/client/runOnSchemaChange.ts +3 -0
  174. package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
  175. package/src/client/sync/bucket/CrudBatch.ts +2 -0
  176. package/src/client/sync/bucket/CrudEntry.ts +9 -0
  177. package/src/client/sync/bucket/CrudTransaction.ts +3 -0
  178. package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
  179. package/src/client/sync/stream/AbstractRemote.ts +30 -1
  180. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +55 -5
  181. package/src/client/sync/stream/JsonValue.ts +3 -0
  182. package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
  183. package/src/client/sync/sync-streams.ts +22 -9
  184. package/src/client/triggers/TriggerManager.ts +19 -18
  185. package/src/client/triggers/TriggerManagerImpl.ts +5 -5
  186. package/src/client/triggers/sanitizeSQL.ts +5 -0
  187. package/src/client/watched/GetAllQuery.ts +5 -1
  188. package/src/client/watched/WatchedQuery.ts +24 -2
  189. package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
  190. package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
  191. package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
  192. package/src/client/watched/processors/comparators.ts +8 -0
  193. package/src/db/ConnectionClosedError.ts +2 -0
  194. package/src/db/DBAdapter.ts +58 -6
  195. package/src/db/crud/SyncProgress.ts +6 -1
  196. package/src/db/crud/SyncStatus.ts +40 -21
  197. package/src/db/crud/UploadQueueStatus.ts +3 -0
  198. package/src/db/schema/Column.ts +28 -3
  199. package/src/db/schema/Index.ts +9 -0
  200. package/src/db/schema/IndexedColumn.ts +9 -0
  201. package/src/db/schema/RawTable.ts +7 -1
  202. package/src/db/schema/Schema.ts +8 -3
  203. package/src/db/schema/Table.ts +30 -5
  204. package/src/db/schema/TableV2.ts +2 -0
  205. package/src/index.ts +1 -1
  206. package/src/types/types.ts +6 -0
  207. package/src/utils/AbortOperation.ts +2 -0
  208. package/src/utils/BaseObserver.ts +12 -0
  209. package/src/utils/ControlledExecutor.ts +6 -0
  210. package/src/utils/Logger.ts +9 -0
  211. package/src/utils/mutex.ts +12 -0
  212. package/src/utils/parseQuery.ts +6 -0
  213. package/src/utils/stream_transform.ts +3 -1
@@ -1,9 +1,12 @@
1
1
  function sanitizeString(input: string): string {
2
2
  return `'${input.replace(/'/g, "''")}'`;
3
3
  }
4
+
4
5
  /**
5
6
  * Helper function for sanitizing UUID input strings.
6
7
  * Typically used with {@link sanitizeSQL}.
8
+ *
9
+ * @alpha
7
10
  */
8
11
  export function sanitizeUUID(uuid: string): string {
9
12
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
@@ -41,6 +44,8 @@ export function sanitizeUUID(uuid: string): string {
41
44
  * // Incorrect:
42
45
  * sanitizeSQL`New.id = '${myID}'` // Produces double quotes: New.id = ''O''Reilly''
43
46
  * ```
47
+ *
48
+ * @alpha
44
49
  */
45
50
  export function sanitizeSQL(strings: TemplateStringsArray, ...values: any[]): string {
46
51
  let result = '';
@@ -4,6 +4,8 @@ import { WatchCompatibleQuery } from './WatchedQuery.js';
4
4
 
5
5
  /**
6
6
  * Options for {@link GetAllQuery}.
7
+ *
8
+ * @public
7
9
  */
8
10
  export type GetAllQueryOptions<RowType = unknown> = {
9
11
  sql: string;
@@ -23,6 +25,8 @@ export type GetAllQueryOptions<RowType = unknown> = {
23
25
 
24
26
  /**
25
27
  * Performs a {@link AbstractPowerSyncDatabase.getAll} operation for a watched query.
28
+ *
29
+ * @public
26
30
  */
27
31
  export class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<RowType[]> {
28
32
  constructor(protected options: GetAllQueryOptions<RowType>) {}
@@ -37,7 +41,7 @@ export class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<RowT
37
41
  async execute(options: { db: AbstractPowerSyncDatabase }): Promise<RowType[]> {
38
42
  const { db } = options;
39
43
  const { sql, parameters = [] } = this.compile();
40
- const rawResult = await db.getAll<unknown>(sql, [...parameters]);
44
+ const rawResult = await db.getAll<Record<string, unknown>>(sql, [...parameters]);
41
45
  if (this.options.mapper) {
42
46
  return rawResult.map(this.options.mapper);
43
47
  }
@@ -5,6 +5,8 @@ import { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
5
5
 
6
6
  /**
7
7
  * State for {@link WatchedQuery} instances.
8
+ *
9
+ * @public
8
10
  */
9
11
  export interface WatchedQueryState<Data> {
10
12
  /**
@@ -33,6 +35,8 @@ export interface WatchedQueryState<Data> {
33
35
 
34
36
  /**
35
37
  * Options provided to the `execute` method of a {@link WatchCompatibleQuery}.
38
+ *
39
+ * @public
36
40
  */
37
41
  export interface WatchExecuteOptions {
38
42
  sql: string;
@@ -41,14 +45,17 @@ export interface WatchExecuteOptions {
41
45
  }
42
46
 
43
47
  /**
44
- * Similar to {@link CompatibleQuery}, except the `execute` method
45
- * does not enforce an Array result type.
48
+ *
49
+ * @public
46
50
  */
47
51
  export interface WatchCompatibleQuery<ResultType> {
48
52
  execute(options: WatchExecuteOptions): Promise<ResultType>;
49
53
  compile(): CompiledQuery;
50
54
  }
51
55
 
56
+ /**
57
+ * @public
58
+ */
52
59
  export interface WatchedQueryOptions {
53
60
  /** The minimum interval between queries. */
54
61
  throttleMs?: number;
@@ -67,6 +74,9 @@ export interface WatchedQueryOptions {
67
74
  triggerOnTables?: string[];
68
75
  }
69
76
 
77
+ /**
78
+ * @public
79
+ */
70
80
  export enum WatchedQueryListenerEvent {
71
81
  ON_DATA = 'onData',
72
82
  ON_ERROR = 'onError',
@@ -75,6 +85,9 @@ export enum WatchedQueryListenerEvent {
75
85
  CLOSED = 'closed'
76
86
  }
77
87
 
88
+ /**
89
+ * @public
90
+ */
78
91
  export interface WatchedQueryListener<Data> extends BaseListener {
79
92
  [WatchedQueryListenerEvent.ON_DATA]?: (data: Data) => void | Promise<void>;
80
93
  [WatchedQueryListenerEvent.ON_ERROR]?: (error: Error) => void | Promise<void>;
@@ -83,13 +96,22 @@ export interface WatchedQueryListener<Data> extends BaseListener {
83
96
  [WatchedQueryListenerEvent.CLOSED]?: () => void | Promise<void>;
84
97
  }
85
98
 
99
+ /**
100
+ * @internal
101
+ */
86
102
  export const DEFAULT_WATCH_THROTTLE_MS = 30;
87
103
 
104
+ /**
105
+ * @internal
106
+ */
88
107
  export const DEFAULT_WATCH_QUERY_OPTIONS: WatchedQueryOptions = {
89
108
  throttleMs: DEFAULT_WATCH_THROTTLE_MS,
90
109
  reportFetching: true
91
110
  };
92
111
 
112
+ /**
113
+ * @public
114
+ */
93
115
  export interface WatchedQuery<
94
116
  Data = unknown,
95
117
  Settings extends WatchedQueryOptions = WatchedQueryOptions,
@@ -45,9 +45,9 @@ type WatchedQueryProcessorListener<Data> = WatchedQueryListener<Data>;
45
45
  * @internal
46
46
  */
47
47
  export abstract class AbstractQueryProcessor<
48
- Data = unknown[],
49
- Settings extends WatchedQueryOptions = WatchedQueryOptions
50
- >
48
+ Data = unknown[],
49
+ Settings extends WatchedQueryOptions = WatchedQueryOptions
50
+ >
51
51
  extends MetaBaseObserver<WatchedQueryProcessorListener<Data>>
52
52
  implements WatchedQuery<Data, Settings>
53
53
  {
@@ -127,7 +127,7 @@ export abstract class AbstractQueryProcessor<
127
127
 
128
128
  /**
129
129
  * This method is used to link a query to the subscribers of this listener class.
130
- * This method should perform actual query watching and report results via {@link updateState} method.
130
+ * This method should perform actual query watching and report results via {@link AbstractQueryProcessor.updateState} method.
131
131
  */
132
132
  protected abstract linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
133
133
 
@@ -199,7 +199,7 @@ export abstract class AbstractQueryProcessor<
199
199
  protected async runWithReporting<T>(callback: () => Promise<T>): Promise<void> {
200
200
  try {
201
201
  await callback();
202
- } catch (error) {
202
+ } catch (error: any) {
203
203
  // This will update the error on the state and iterate error listeners
204
204
  await this.updateState({ error });
205
205
  }
@@ -213,7 +213,7 @@ export abstract class AbstractQueryProcessor<
213
213
  ) {
214
214
  try {
215
215
  await this.iterateAsyncListeners(async (l) => callback(l));
216
- } catch (error) {
216
+ } catch (error: any) {
217
217
  try {
218
218
  await this.iterateAsyncListeners(async (l) => l.onError?.(error));
219
219
  } catch (error) {
@@ -9,6 +9,8 @@ import {
9
9
  /**
10
10
  * Represents an updated row in a differential watched query.
11
11
  * It contains both the current and previous state of the row.
12
+ *
13
+ * @public
12
14
  */
13
15
  export interface WatchedQueryRowDifferential<RowType> {
14
16
  readonly current: RowType;
@@ -18,6 +20,8 @@ export interface WatchedQueryRowDifferential<RowType> {
18
20
  /**
19
21
  * Represents the result of a watched query that has been diffed.
20
22
  * {@link DifferentialWatchedQueryState#diff} is of the {@link WatchedQueryDifferential} form.
23
+ *
24
+ * @public
21
25
  */
22
26
  export interface WatchedQueryDifferential<RowType> {
23
27
  readonly added: ReadonlyArray<Readonly<RowType>>;
@@ -43,6 +47,8 @@ export interface WatchedQueryDifferential<RowType> {
43
47
 
44
48
  /**
45
49
  * Row comparator for differentially watched queries which keys and compares items in the result set.
50
+ *
51
+ * @public
46
52
  */
47
53
  export interface DifferentialWatchedQueryComparator<RowType> {
48
54
  /**
@@ -57,6 +63,8 @@ export interface DifferentialWatchedQueryComparator<RowType> {
57
63
 
58
64
  /**
59
65
  * Options for building a differential watched query with the {@link Query} builder.
66
+ *
67
+ * @public
60
68
  */
61
69
  export interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOptions {
62
70
  /**
@@ -75,6 +83,8 @@ export interface DifferentialWatchedQueryOptions<RowType> extends WatchedQueryOp
75
83
 
76
84
  /**
77
85
  * Settings for differential incremental watched queries using.
86
+ *
87
+ * @public
78
88
  */
79
89
  export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialWatchedQueryOptions<RowType> {
80
90
  /**
@@ -83,11 +93,18 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
83
93
  query: WatchCompatibleQuery<RowType[]>;
84
94
  }
85
95
 
86
- export interface DifferentialWatchedQueryListener<RowType>
87
- extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
96
+ /**
97
+ * @public
98
+ */
99
+ export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<
100
+ ReadonlyArray<Readonly<RowType>>
101
+ > {
88
102
  onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
89
103
  }
90
104
 
105
+ /**
106
+ * @public
107
+ */
91
108
  export type DifferentialWatchedQuery<RowType> = WatchedQuery<
92
109
  ReadonlyArray<Readonly<RowType>>,
93
110
  DifferentialWatchedQuerySettings<RowType>,
@@ -97,8 +114,10 @@ export type DifferentialWatchedQuery<RowType> = WatchedQuery<
97
114
  /**
98
115
  * @internal
99
116
  */
100
- export interface DifferentialQueryProcessorOptions<RowType>
101
- extends AbstractQueryProcessorOptions<RowType[], DifferentialWatchedQuerySettings<RowType>> {
117
+ export interface DifferentialQueryProcessorOptions<RowType> extends AbstractQueryProcessorOptions<
118
+ RowType[],
119
+ DifferentialWatchedQuerySettings<RowType>
120
+ > {
102
121
  rowComparator?: DifferentialWatchedQueryComparator<RowType>;
103
122
  }
104
123
 
@@ -107,6 +126,8 @@ type DataHashMap<RowType> = Map<string, { hash: string; item: RowType }>;
107
126
  /**
108
127
  * An empty differential result set.
109
128
  * This is used as the initial state for differential incrementally watched queries.
129
+ *
130
+ * @internal
110
131
  */
111
132
  export const EMPTY_DIFFERENTIAL = {
112
133
  added: [],
@@ -120,6 +141,8 @@ export const EMPTY_DIFFERENTIAL = {
120
141
  * Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
121
142
  * It keys items by their `id` property if available, alternatively it uses JSON stringification
122
143
  * of the entire item for the key and comparison.
144
+ *
145
+ * @internal
123
146
  */
124
147
  export const DEFAULT_ROW_COMPARATOR: DifferentialWatchedQueryComparator<any> = {
125
148
  keyBy: (item) => {
@@ -286,7 +309,7 @@ export class DifferentialQueryProcessor<RowType>
286
309
  if (Object.keys(partialStateUpdate).length > 0) {
287
310
  await this.updateState(partialStateUpdate);
288
311
  }
289
- } catch (error) {
312
+ } catch (error: any) {
290
313
  await this.updateState({ error });
291
314
  }
292
315
  },
@@ -9,6 +9,8 @@ import { WatchedQueryComparator } from './comparators.js';
9
9
 
10
10
  /**
11
11
  * Settings for {@link WatchedQuery} instances created via {@link Query#watch}.
12
+ *
13
+ * @public
12
14
  */
13
15
  export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
14
16
  query: WatchCompatibleQuery<DataType>;
@@ -16,14 +18,18 @@ export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
16
18
 
17
19
  /**
18
20
  * {@link WatchedQuery} returned from {@link Query#watch}.
21
+ *
22
+ * @public
19
23
  */
20
24
  export type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
21
25
 
22
26
  /**
23
27
  * @internal
24
28
  */
25
- export interface OnChangeQueryProcessorOptions<Data>
26
- extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
29
+ export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<
30
+ Data,
31
+ WatchedQuerySettings<Data>
32
+ > {
27
33
  comparator?: WatchedQueryComparator<Data>;
28
34
  }
29
35
 
@@ -103,7 +109,7 @@ export class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, W
103
109
  if (Object.keys(partialStateUpdate).length > 0) {
104
110
  await this.updateState(partialStateUpdate);
105
111
  }
106
- } catch (error) {
112
+ } catch (error: any) {
107
113
  await this.updateState({ error });
108
114
  }
109
115
  },
@@ -2,6 +2,8 @@
2
2
  * A basic comparator for incrementally watched queries. This performs a single comparison which
3
3
  * determines if the result set has changed. The {@link WatchedQuery} will only emit the new result
4
4
  * if a change has been detected.
5
+ *
6
+ * @public
5
7
  */
6
8
  export interface WatchedQueryComparator<Data> {
7
9
  checkEquality: (current: Data, previous: Data) => boolean;
@@ -9,6 +11,8 @@ export interface WatchedQueryComparator<Data> {
9
11
 
10
12
  /**
11
13
  * Options for {@link ArrayComparator}
14
+ *
15
+ * @public
12
16
  */
13
17
  export type ArrayComparatorOptions<ItemType> = {
14
18
  /**
@@ -20,6 +24,8 @@ export type ArrayComparatorOptions<ItemType> = {
20
24
  /**
21
25
  * An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
22
26
  * result has changes without necessarily processing all items in the result.
27
+ *
28
+ * @public
23
29
  */
24
30
  export class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemType[]> {
25
31
  constructor(protected options: ArrayComparatorOptions<ItemType>) {}
@@ -51,6 +57,8 @@ export class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemTyp
51
57
 
52
58
  /**
53
59
  * Watched query comparator that always reports changed result sets.
60
+ *
61
+ * @public
54
62
  */
55
63
  export const FalsyComparator: WatchedQueryComparator<unknown> = {
56
64
  checkEquality: () => false // Default comparator that always returns false
@@ -2,6 +2,8 @@
2
2
  * Thrown when an underlying database connection is closed.
3
3
  * This is particularly relevant when worker connections are marked as closed while
4
4
  * operations are still in progress.
5
+ *
6
+ * @internal
5
7
  */
6
8
  export class ConnectionClosedError extends Error {
7
9
  static NAME = 'ConnectionClosedError';
@@ -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;