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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/dist/bundle.cjs +14470 -0
  2. package/dist/bundle.cjs.map +1 -0
  3. package/dist/bundle.mjs +14379 -0
  4. package/dist/bundle.mjs.map +1 -0
  5. package/dist/bundle.node.cjs +11948 -0
  6. package/dist/bundle.node.cjs.map +1 -0
  7. package/dist/bundle.node.mjs +11857 -0
  8. package/dist/bundle.node.mjs.map +1 -0
  9. package/dist/index.d.cts +4272 -0
  10. package/lib/attachments/AttachmentContext.d.ts +86 -0
  11. package/lib/attachments/AttachmentContext.js +229 -0
  12. package/lib/attachments/AttachmentContext.js.map +1 -0
  13. package/lib/attachments/AttachmentErrorHandler.d.ts +31 -0
  14. package/lib/attachments/AttachmentErrorHandler.js +2 -0
  15. package/lib/attachments/AttachmentErrorHandler.js.map +1 -0
  16. package/lib/attachments/AttachmentQueue.d.ts +149 -0
  17. package/lib/attachments/AttachmentQueue.js +362 -0
  18. package/lib/attachments/AttachmentQueue.js.map +1 -0
  19. package/lib/attachments/AttachmentService.d.ts +29 -0
  20. package/lib/attachments/AttachmentService.js +56 -0
  21. package/lib/attachments/AttachmentService.js.map +1 -0
  22. package/lib/attachments/LocalStorageAdapter.d.ts +62 -0
  23. package/lib/attachments/LocalStorageAdapter.js +6 -0
  24. package/lib/attachments/LocalStorageAdapter.js.map +1 -0
  25. package/lib/attachments/RemoteStorageAdapter.d.ts +27 -0
  26. package/lib/attachments/RemoteStorageAdapter.js +2 -0
  27. package/lib/attachments/RemoteStorageAdapter.js.map +1 -0
  28. package/lib/attachments/Schema.d.ts +50 -0
  29. package/lib/attachments/Schema.js +62 -0
  30. package/lib/attachments/Schema.js.map +1 -0
  31. package/lib/attachments/SyncingService.d.ts +62 -0
  32. package/lib/attachments/SyncingService.js +168 -0
  33. package/lib/attachments/SyncingService.js.map +1 -0
  34. package/lib/attachments/WatchedAttachmentItem.d.ts +17 -0
  35. package/lib/attachments/WatchedAttachmentItem.js +2 -0
  36. package/lib/attachments/WatchedAttachmentItem.js.map +1 -0
  37. package/lib/client/AbstractPowerSyncDatabase.d.ts +615 -0
  38. package/lib/client/AbstractPowerSyncDatabase.js +983 -0
  39. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -0
  40. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +22 -0
  41. package/lib/client/AbstractPowerSyncOpenFactory.js +25 -0
  42. package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -0
  43. package/lib/client/ConnectionManager.d.ts +112 -0
  44. package/lib/client/ConnectionManager.js +294 -0
  45. package/lib/client/ConnectionManager.js.map +1 -0
  46. package/lib/client/CustomQuery.d.ts +22 -0
  47. package/lib/client/CustomQuery.js +43 -0
  48. package/lib/client/CustomQuery.js.map +1 -0
  49. package/lib/client/Query.d.ts +97 -0
  50. package/lib/client/Query.js +2 -0
  51. package/lib/client/Query.js.map +1 -0
  52. package/lib/client/SQLOpenFactory.d.ts +42 -0
  53. package/lib/client/SQLOpenFactory.js +20 -0
  54. package/lib/client/SQLOpenFactory.js.map +1 -0
  55. package/lib/client/compilableQueryWatch.d.ts +7 -0
  56. package/lib/client/compilableQueryWatch.js +38 -0
  57. package/lib/client/compilableQueryWatch.js.map +1 -0
  58. package/lib/client/connection/PowerSyncBackendConnector.d.ts +23 -0
  59. package/lib/client/connection/PowerSyncBackendConnector.js +2 -0
  60. package/lib/client/connection/PowerSyncBackendConnector.js.map +1 -0
  61. package/lib/client/connection/PowerSyncCredentials.d.ts +5 -0
  62. package/lib/client/connection/PowerSyncCredentials.js +2 -0
  63. package/lib/client/connection/PowerSyncCredentials.js.map +1 -0
  64. package/lib/client/constants.d.ts +1 -0
  65. package/lib/client/constants.js +2 -0
  66. package/lib/client/constants.js.map +1 -0
  67. package/lib/client/runOnSchemaChange.d.ts +2 -0
  68. package/lib/client/runOnSchemaChange.js +24 -0
  69. package/lib/client/runOnSchemaChange.js.map +1 -0
  70. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +102 -0
  71. package/lib/client/sync/bucket/BucketStorageAdapter.js +19 -0
  72. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
  73. package/lib/client/sync/bucket/CrudBatch.d.ts +31 -0
  74. package/lib/client/sync/bucket/CrudBatch.js +26 -0
  75. package/lib/client/sync/bucket/CrudBatch.js.map +1 -0
  76. package/lib/client/sync/bucket/CrudEntry.d.ts +95 -0
  77. package/lib/client/sync/bucket/CrudEntry.js +110 -0
  78. package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
  79. package/lib/client/sync/bucket/CrudTransaction.d.ts +29 -0
  80. package/lib/client/sync/bucket/CrudTransaction.js +25 -0
  81. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -0
  82. package/lib/client/sync/bucket/OpType.d.ts +16 -0
  83. package/lib/client/sync/bucket/OpType.js +23 -0
  84. package/lib/client/sync/bucket/OpType.js.map +1 -0
  85. package/lib/client/sync/bucket/OplogEntry.d.ts +23 -0
  86. package/lib/client/sync/bucket/OplogEntry.js +36 -0
  87. package/lib/client/sync/bucket/OplogEntry.js.map +1 -0
  88. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +61 -0
  89. package/lib/client/sync/bucket/SqliteBucketStorage.js +324 -0
  90. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
  91. package/lib/client/sync/bucket/SyncDataBatch.d.ts +6 -0
  92. package/lib/client/sync/bucket/SyncDataBatch.js +12 -0
  93. package/lib/client/sync/bucket/SyncDataBatch.js.map +1 -0
  94. package/lib/client/sync/bucket/SyncDataBucket.d.ts +40 -0
  95. package/lib/client/sync/bucket/SyncDataBucket.js +40 -0
  96. package/lib/client/sync/bucket/SyncDataBucket.js.map +1 -0
  97. package/lib/client/sync/stream/AbstractRemote.d.ts +140 -0
  98. package/lib/client/sync/stream/AbstractRemote.js +506 -0
  99. package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
  100. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +240 -0
  101. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +990 -0
  102. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
  103. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
  104. package/lib/client/sync/stream/WebsocketClientTransport.js +61 -0
  105. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
  106. package/lib/client/sync/stream/core-instruction.d.ts +72 -0
  107. package/lib/client/sync/stream/core-instruction.js +27 -0
  108. package/lib/client/sync/stream/core-instruction.js.map +1 -0
  109. package/lib/client/sync/stream/streaming-sync-types.d.ts +143 -0
  110. package/lib/client/sync/stream/streaming-sync-types.js +26 -0
  111. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -0
  112. package/lib/client/sync/sync-streams.d.ts +98 -0
  113. package/lib/client/sync/sync-streams.js +2 -0
  114. package/lib/client/sync/sync-streams.js.map +1 -0
  115. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
  116. package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
  117. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
  118. package/lib/client/triggers/TriggerManager.d.ts +459 -0
  119. package/lib/client/triggers/TriggerManager.js +11 -0
  120. package/lib/client/triggers/TriggerManager.js.map +1 -0
  121. package/lib/client/triggers/TriggerManagerImpl.d.ts +39 -0
  122. package/lib/client/triggers/TriggerManagerImpl.js +393 -0
  123. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
  124. package/lib/client/triggers/sanitizeSQL.d.ts +34 -0
  125. package/lib/client/triggers/sanitizeSQL.js +69 -0
  126. package/lib/client/triggers/sanitizeSQL.js.map +1 -0
  127. package/lib/client/watched/GetAllQuery.d.ts +32 -0
  128. package/lib/client/watched/GetAllQuery.js +25 -0
  129. package/lib/client/watched/GetAllQuery.js.map +1 -0
  130. package/lib/client/watched/WatchedQuery.d.ts +100 -0
  131. package/lib/client/watched/WatchedQuery.js +14 -0
  132. package/lib/client/watched/WatchedQuery.js.map +1 -0
  133. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +68 -0
  134. package/lib/client/watched/processors/AbstractQueryProcessor.js +151 -0
  135. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -0
  136. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +121 -0
  137. package/lib/client/watched/processors/DifferentialQueryProcessor.js +173 -0
  138. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -0
  139. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +33 -0
  140. package/lib/client/watched/processors/OnChangeQueryProcessor.js +83 -0
  141. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -0
  142. package/lib/client/watched/processors/comparators.d.ts +30 -0
  143. package/lib/client/watched/processors/comparators.js +35 -0
  144. package/lib/client/watched/processors/comparators.js.map +1 -0
  145. package/lib/db/ConnectionClosedError.d.ts +10 -0
  146. package/lib/db/ConnectionClosedError.js +21 -0
  147. package/lib/db/ConnectionClosedError.js.map +1 -0
  148. package/lib/db/DBAdapter.d.ts +115 -0
  149. package/lib/db/DBAdapter.js +20 -0
  150. package/lib/db/DBAdapter.js.map +1 -0
  151. package/lib/db/crud/SyncProgress.d.ts +68 -0
  152. package/lib/db/crud/SyncProgress.js +61 -0
  153. package/lib/db/crud/SyncProgress.js.map +1 -0
  154. package/lib/db/crud/SyncStatus.d.ts +195 -0
  155. package/lib/db/crud/SyncStatus.js +250 -0
  156. package/lib/db/crud/SyncStatus.js.map +1 -0
  157. package/lib/db/crud/UploadQueueStatus.d.ts +20 -0
  158. package/lib/db/crud/UploadQueueStatus.js +25 -0
  159. package/lib/db/crud/UploadQueueStatus.js.map +1 -0
  160. package/lib/db/schema/Column.d.ts +30 -0
  161. package/lib/db/schema/Column.js +43 -0
  162. package/lib/db/schema/Column.js.map +1 -0
  163. package/lib/db/schema/Index.d.ts +22 -0
  164. package/lib/db/schema/Index.js +30 -0
  165. package/lib/db/schema/Index.js.map +1 -0
  166. package/lib/db/schema/IndexedColumn.d.ts +19 -0
  167. package/lib/db/schema/IndexedColumn.js +30 -0
  168. package/lib/db/schema/IndexedColumn.js.map +1 -0
  169. package/lib/db/schema/RawTable.d.ts +61 -0
  170. package/lib/db/schema/RawTable.js +33 -0
  171. package/lib/db/schema/RawTable.js.map +1 -0
  172. package/lib/db/schema/Schema.d.ts +54 -0
  173. package/lib/db/schema/Schema.js +61 -0
  174. package/lib/db/schema/Schema.js.map +1 -0
  175. package/lib/db/schema/Table.d.ts +157 -0
  176. package/lib/db/schema/Table.js +208 -0
  177. package/lib/db/schema/Table.js.map +1 -0
  178. package/lib/db/schema/TableV2.d.ts +9 -0
  179. package/lib/db/schema/TableV2.js +9 -0
  180. package/lib/db/schema/TableV2.js.map +1 -0
  181. package/lib/index.d.ts +62 -0
  182. package/lib/index.js +63 -0
  183. package/lib/index.js.map +1 -0
  184. package/lib/types/types.d.ts +8 -0
  185. package/lib/types/types.js +2 -0
  186. package/lib/types/types.js.map +1 -0
  187. package/lib/utils/AbortOperation.d.ts +9 -0
  188. package/lib/utils/AbortOperation.js +19 -0
  189. package/lib/utils/AbortOperation.js.map +1 -0
  190. package/lib/utils/BaseObserver.d.ts +18 -0
  191. package/lib/utils/BaseObserver.js +27 -0
  192. package/lib/utils/BaseObserver.js.map +1 -0
  193. package/lib/utils/ControlledExecutor.d.ts +25 -0
  194. package/lib/utils/ControlledExecutor.js +51 -0
  195. package/lib/utils/ControlledExecutor.js.map +1 -0
  196. package/lib/utils/DataStream.d.ts +62 -0
  197. package/lib/utils/DataStream.js +169 -0
  198. package/lib/utils/DataStream.js.map +1 -0
  199. package/lib/utils/Logger.d.ts +31 -0
  200. package/lib/utils/Logger.js +37 -0
  201. package/lib/utils/Logger.js.map +1 -0
  202. package/lib/utils/MetaBaseObserver.d.ts +29 -0
  203. package/lib/utils/MetaBaseObserver.js +51 -0
  204. package/lib/utils/MetaBaseObserver.js.map +1 -0
  205. package/lib/utils/async.d.ts +23 -0
  206. package/lib/utils/async.js +55 -0
  207. package/lib/utils/async.js.map +1 -0
  208. package/lib/utils/mutex.d.ts +7 -0
  209. package/lib/utils/mutex.js +29 -0
  210. package/lib/utils/mutex.js.map +1 -0
  211. package/lib/utils/parseQuery.d.ts +6 -0
  212. package/lib/utils/parseQuery.js +17 -0
  213. package/lib/utils/parseQuery.js.map +1 -0
  214. package/package.json +1 -1
@@ -0,0 +1,97 @@
1
+ import { WatchedQueryComparator } from './watched/processors/comparators.js';
2
+ import { DifferentialWatchedQuery, DifferentialWatchedQueryOptions } from './watched/processors/DifferentialQueryProcessor.js';
3
+ import { StandardWatchedQuery } from './watched/processors/OnChangeQueryProcessor.js';
4
+ import { WatchedQueryOptions } from './watched/WatchedQuery.js';
5
+ /**
6
+ * Query parameters for {@link ArrayQueryDefinition#parameters}
7
+ */
8
+ export type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
9
+ /**
10
+ * Options for building a query with {@link AbstractPowerSyncDatabase#query}.
11
+ * This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
12
+ */
13
+ export interface ArrayQueryDefinition<RowType = unknown> {
14
+ sql: string;
15
+ parameters?: ReadonlyArray<Readonly<QueryParam>>;
16
+ /**
17
+ * Maps the raw SQLite row to a custom typed object.
18
+ * @example
19
+ * ```javascript
20
+ * mapper: (row) => ({
21
+ * ...row,
22
+ * created_at: new Date(row.created_at as string),
23
+ * })
24
+ * ```
25
+ */
26
+ mapper?: (row: Record<string, unknown>) => RowType;
27
+ }
28
+ /**
29
+ * Options for {@link Query#watch}.
30
+ */
31
+ export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
32
+ /**
33
+ * The underlying watched query implementation (re)evaluates the query on any SQLite table change.
34
+ *
35
+ * Providing this optional comparator can be used to filter duplicate result set emissions when the result set is unchanged.
36
+ * The comparator compares the previous and current result set.
37
+ *
38
+ * For an efficient comparator see {@link ArrayComparator}.
39
+ *
40
+ * @example
41
+ * ```javascript
42
+ * comparator: new ArrayComparator({
43
+ * compareBy: (item) => JSON.stringify(item)
44
+ * })
45
+ * ```
46
+ */
47
+ comparator?: WatchedQueryComparator<RowType[]>;
48
+ /**
49
+ * The initial data state reported while the query is loading for the first time.
50
+ * @default []
51
+ */
52
+ placeholderData?: RowType[];
53
+ }
54
+ export interface Query<RowType> {
55
+ /**
56
+ * Creates a {@link WatchedQuery} which watches and emits results of the linked query.
57
+ *
58
+ * By default the returned watched query will emit changes whenever a change to the underlying SQLite tables is made.
59
+ * These changes might not be relevant to the query, but the query will emit a new result set.
60
+ *
61
+ * A {@link StandardWatchedQueryOptions#comparator} can be provided to limit the data emissions. The watched query will still
62
+ * query the underlying DB on underlying table changes, but the result will only be emitted if the comparator detects a change in the results.
63
+ *
64
+ * The comparator in this method is optimized and returns early as soon as it detects a change. Each data emission will correlate to a change in the result set,
65
+ * but note that the result set will not maintain internal object references to the previous result set. If internal object references are needed,
66
+ * consider using {@link Query#differentialWatch} instead.
67
+ */
68
+ watch(options?: StandardWatchedQueryOptions<RowType>): StandardWatchedQuery<ReadonlyArray<Readonly<RowType>>>;
69
+ /**
70
+ * Creates a {@link WatchedQuery} which watches and emits results of the linked query.
71
+ *
72
+ * This query method watches for changes in the underlying SQLite tables and runs the query on each table change.
73
+ * The difference between the current and previous result set is computed.
74
+ * The watched query will not emit changes if the result set is identical to the previous result set.
75
+ *
76
+ * If the result set is different, the watched query will emit the new result set and emit a detailed diff of the changes via the `onData` and `onDiff` listeners.
77
+ *
78
+ * The deep differentiation allows maintaining result set object references between result emissions.
79
+ * The {@link DifferentialWatchedQuery#state} `data` array will contain the previous row references for unchanged rows.
80
+ *
81
+ * @example
82
+ * ```javascript
83
+ * const watchedLists = powerSync.query({sql: 'SELECT * FROM lists'})
84
+ * .differentialWatch();
85
+ *
86
+ * const disposeListener = watchedLists.registerListener({
87
+ * onData: (lists) => {
88
+ * console.log('The latest result set for the query is', lists);
89
+ * },
90
+ * onDiff: (diff) => {
91
+ * console.log('The lists result set has changed since the last emission', diff.added, diff.removed, diff.updated, diff.all)
92
+ * }
93
+ * })
94
+ * ```
95
+ */
96
+ differentialWatch(options?: DifferentialWatchedQueryOptions<RowType>): DifferentialWatchedQuery<RowType>;
97
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Query.js","sourceRoot":"","sources":["../../src/client/Query.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { DBAdapter } from '../db/DBAdapter.js';
2
+ export interface SQLOpenOptions {
3
+ /**
4
+ * Filename for the database.
5
+ */
6
+ dbFilename: string;
7
+ /**
8
+ * Directory where the database file is located.
9
+ *
10
+ * When set, the directory must exist when the database is opened, it will
11
+ * not be created automatically.
12
+ */
13
+ dbLocation?: string;
14
+ /**
15
+ * Enable debugMode to log queries to the performance timeline.
16
+ *
17
+ * Defaults to false.
18
+ *
19
+ * To enable in development builds, use:
20
+ *
21
+ * debugMode: process.env.NODE_ENV !== 'production'
22
+ */
23
+ debugMode?: boolean;
24
+ }
25
+ export interface SQLOpenFactory {
26
+ /**
27
+ * Opens a connection adapter to a SQLite DB
28
+ */
29
+ openDB(): DBAdapter;
30
+ }
31
+ /**
32
+ * Tests if the input is a {@link SQLOpenOptions}
33
+ */
34
+ export declare const isSQLOpenOptions: (test: any) => test is SQLOpenOptions;
35
+ /**
36
+ * Tests if input is a {@link SQLOpenFactory}
37
+ */
38
+ export declare const isSQLOpenFactory: (test: any) => test is SQLOpenFactory;
39
+ /**
40
+ * Tests if input is a {@link DBAdapter}
41
+ */
42
+ export declare const isDBAdapter: (test: any) => test is DBAdapter;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Tests if the input is a {@link SQLOpenOptions}
3
+ */
4
+ export const isSQLOpenOptions = (test) => {
5
+ // typeof null is `object`, but you cannot use the `in` operator on `null.
6
+ return test && typeof test == 'object' && 'dbFilename' in test;
7
+ };
8
+ /**
9
+ * Tests if input is a {@link SQLOpenFactory}
10
+ */
11
+ export const isSQLOpenFactory = (test) => {
12
+ return typeof test?.openDB == 'function';
13
+ };
14
+ /**
15
+ * Tests if input is a {@link DBAdapter}
16
+ */
17
+ export const isDBAdapter = (test) => {
18
+ return typeof test?.writeTransaction == 'function';
19
+ };
20
+ //# sourceMappingURL=SQLOpenFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLOpenFactory.js","sourceRoot":"","sources":["../../src/client/SQLOpenFactory.ts"],"names":[],"mappings":"AAkCA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAS,EAA0B,EAAE;IACpE,0EAA0E;IAC1E,OAAO,IAAI,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,YAAY,IAAI,IAAI,CAAC;AACjE,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAS,EAA0B,EAAE;IACpE,OAAO,OAAO,IAAI,EAAE,MAAM,IAAI,UAAU,CAAC;AAC3C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAS,EAAqB,EAAE;IAC1D,OAAO,OAAO,IAAI,EAAE,gBAAgB,IAAI,UAAU,CAAC;AACrD,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { CompilableQuery } from './../types/types.js';
2
+ import { AbstractPowerSyncDatabase, SQLWatchOptions } from './AbstractPowerSyncDatabase.js';
3
+ export interface CompilableQueryWatchHandler<T> {
4
+ onResult: (results: T[]) => void;
5
+ onError?: (error: Error) => void;
6
+ }
7
+ export declare function compilableQueryWatch<T>(db: AbstractPowerSyncDatabase, query: CompilableQuery<T>, handler: CompilableQueryWatchHandler<T>, options?: SQLWatchOptions): void;
@@ -0,0 +1,38 @@
1
+ import { runOnSchemaChange } from './runOnSchemaChange.js';
2
+ export function compilableQueryWatch(db, query, handler, options) {
3
+ const { onResult, onError = (e) => { } } = handler ?? {};
4
+ if (!onResult) {
5
+ throw new Error('onResult is required');
6
+ }
7
+ const watchQuery = async (abortSignal) => {
8
+ try {
9
+ const toSql = query.compile();
10
+ const resolvedTables = await db.resolveTables(toSql.sql, toSql.parameters, options);
11
+ // Fetch initial data
12
+ const result = await query.execute();
13
+ onResult(result);
14
+ db.onChangeWithCallback({
15
+ onChange: async () => {
16
+ try {
17
+ const result = await query.execute();
18
+ onResult(result);
19
+ }
20
+ catch (error) {
21
+ onError(error);
22
+ }
23
+ },
24
+ onError
25
+ }, {
26
+ ...(options ?? {}),
27
+ tables: resolvedTables,
28
+ // Override the abort signal since we intercept it
29
+ signal: abortSignal
30
+ });
31
+ }
32
+ catch (error) {
33
+ onError(error);
34
+ }
35
+ };
36
+ runOnSchemaChange(watchQuery, db, options);
37
+ }
38
+ //# sourceMappingURL=compilableQueryWatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilableQueryWatch.js","sourceRoot":"","sources":["../../src/client/compilableQueryWatch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAO3D,MAAM,UAAU,oBAAoB,CAClC,EAA6B,EAC7B,KAAyB,EACzB,OAAuC,EACvC,OAAyB;IAEzB,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,CAAC,CAAQ,EAAE,EAAE,GAAE,CAAC,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,EAAE,WAAwB,EAAE,EAAE;QACpD,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;YAC9B,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,UAAgB,EAAE,OAAO,CAAC,CAAC;YAE1F,qBAAqB;YACrB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;YACrC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAEjB,EAAE,CAAC,oBAAoB,CACrB;gBACE,QAAQ,EAAE,KAAK,IAAI,EAAE;oBACnB,IAAI,CAAC;wBACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;wBACrC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACnB,CAAC;oBAAC,OAAO,KAAU,EAAE,CAAC;wBACpB,OAAO,CAAC,KAAK,CAAC,CAAC;oBACjB,CAAC;gBACH,CAAC;gBACD,OAAO;aACR,EACD;gBACE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;gBAClB,MAAM,EAAE,cAAc;gBACtB,kDAAkD;gBAClD,MAAM,EAAE,WAAW;aACpB,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;IAEF,iBAAiB,CAAC,UAAU,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { PowerSyncCredentials } from './PowerSyncCredentials.js';
2
+ import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';
3
+ export interface PowerSyncBackendConnector {
4
+ /** Allows the PowerSync client to retrieve an authentication token from your backend
5
+ * which is used to authenticate against the PowerSync service.
6
+ *
7
+ * This should always fetch a fresh set of credentials - don't use cached
8
+ * values.
9
+ *
10
+ * Return null if the user is not signed in. Throw an error if credentials
11
+ * cannot be fetched due to a network error or other temporary error.
12
+ *
13
+ * This token is kept for the duration of a sync connection.
14
+ */
15
+ fetchCredentials: () => Promise<PowerSyncCredentials | null>;
16
+ /** Upload local changes to the app backend.
17
+ *
18
+ * Use {@link AbstractPowerSyncDatabase.getCrudBatch} to get a batch of changes to upload.
19
+ *
20
+ * Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
21
+ */
22
+ uploadData: (database: AbstractPowerSyncDatabase) => Promise<void>;
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PowerSyncBackendConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncBackendConnector.js","sourceRoot":"","sources":["../../../src/client/connection/PowerSyncBackendConnector.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export interface PowerSyncCredentials {
2
+ endpoint: string;
3
+ token: string;
4
+ expiresAt?: Date;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PowerSyncCredentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncCredentials.js","sourceRoot":"","sources":["../../../src/client/connection/PowerSyncCredentials.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare const MAX_OP_ID = "9223372036854775807";
@@ -0,0 +1,2 @@
1
+ export const MAX_OP_ID = '9223372036854775807';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { AbstractPowerSyncDatabase, SQLWatchOptions } from './AbstractPowerSyncDatabase.js';
2
+ export declare function runOnSchemaChange(callback: (signal: AbortSignal) => void, db: AbstractPowerSyncDatabase, options?: SQLWatchOptions): void;
@@ -0,0 +1,24 @@
1
+ export function runOnSchemaChange(callback, db, options) {
2
+ const triggerWatchedQuery = () => {
3
+ const abortController = new AbortController();
4
+ let disposeSchemaListener = null;
5
+ const stopWatching = () => {
6
+ abortController.abort('Abort triggered');
7
+ disposeSchemaListener?.();
8
+ disposeSchemaListener = null;
9
+ // Stop listening to upstream abort for this watch
10
+ options?.signal?.removeEventListener('abort', stopWatching);
11
+ };
12
+ options?.signal?.addEventListener('abort', stopWatching);
13
+ disposeSchemaListener = db.registerListener({
14
+ schemaChanged: async () => {
15
+ stopWatching();
16
+ // Re trigger the watched query (recursively), setTimeout ensures that we don't modify the list of listeners while iterating through them
17
+ setTimeout(() => triggerWatchedQuery(), 0);
18
+ }
19
+ });
20
+ callback(abortController.signal);
21
+ };
22
+ triggerWatchedQuery();
23
+ }
24
+ //# sourceMappingURL=runOnSchemaChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runOnSchemaChange.js","sourceRoot":"","sources":["../../src/client/runOnSchemaChange.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAC/B,QAAuC,EACvC,EAA6B,EAC7B,OAAyB;IAEzB,MAAM,mBAAmB,GAAG,GAAG,EAAE;QAC/B,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,IAAI,qBAAqB,GAAwB,IAAI,CAAC;QACtD,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,eAAe,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACzC,qBAAqB,EAAE,EAAE,CAAC;YAC1B,qBAAqB,GAAG,IAAI,CAAC;YAC7B,kDAAkD;YAClD,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC,CAAC;QAEF,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACzD,qBAAqB,GAAG,EAAE,CAAC,gBAAgB,CAAC;YAC1C,aAAa,EAAE,KAAK,IAAI,EAAE;gBACxB,YAAY,EAAE,CAAC;gBACf,yIAAyI;gBACzI,UAAU,CAAC,GAAG,EAAE,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC,CAAC;QACH,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,mBAAmB,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { BaseListener, BaseObserverInterface, Disposable } from '../../../utils/BaseObserver.js';
2
+ import { CrudBatch } from './CrudBatch.js';
3
+ import { CrudEntry, OpId } from './CrudEntry.js';
4
+ import { SyncDataBatch } from './SyncDataBatch.js';
5
+ export interface BucketDescription {
6
+ name: string;
7
+ priority: number;
8
+ }
9
+ export interface Checkpoint {
10
+ last_op_id: OpId;
11
+ buckets: BucketChecksum[];
12
+ write_checkpoint?: string;
13
+ streams?: any[];
14
+ }
15
+ export interface BucketState {
16
+ bucket: string;
17
+ op_id: string;
18
+ }
19
+ export interface ChecksumCache {
20
+ checksums: Map<string, {
21
+ checksum: BucketChecksum;
22
+ last_op_id: OpId;
23
+ }>;
24
+ lastOpId: OpId;
25
+ }
26
+ export interface SyncLocalDatabaseResult {
27
+ ready: boolean;
28
+ checkpointValid: boolean;
29
+ checkpointFailures?: string[];
30
+ }
31
+ export type SavedProgress = {
32
+ atLast: number;
33
+ sinceLast: number;
34
+ };
35
+ export type BucketOperationProgress = Record<string, SavedProgress>;
36
+ export interface BucketChecksum {
37
+ bucket: string;
38
+ priority?: number;
39
+ /**
40
+ * 32-bit unsigned hash.
41
+ */
42
+ checksum: number;
43
+ /**
44
+ * Count of operations - informational only.
45
+ */
46
+ count?: number;
47
+ /**
48
+ * The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
49
+ * this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
50
+ * present.
51
+ */
52
+ subscriptions?: any;
53
+ }
54
+ export declare enum PSInternalTable {
55
+ DATA = "ps_data",
56
+ CRUD = "ps_crud",
57
+ BUCKETS = "ps_buckets",
58
+ OPLOG = "ps_oplog",
59
+ UNTYPED = "ps_untyped"
60
+ }
61
+ export declare enum PowerSyncControlCommand {
62
+ PROCESS_TEXT_LINE = "line_text",
63
+ PROCESS_BSON_LINE = "line_binary",
64
+ STOP = "stop",
65
+ START = "start",
66
+ NOTIFY_TOKEN_REFRESHED = "refreshed_token",
67
+ NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload",
68
+ UPDATE_SUBSCRIPTIONS = "update_subscriptions"
69
+ }
70
+ export interface BucketStorageListener extends BaseListener {
71
+ crudUpdate: () => void;
72
+ }
73
+ export interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
74
+ init(): Promise<void>;
75
+ saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
76
+ removeBuckets(buckets: string[]): Promise<void>;
77
+ setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
78
+ startSession(): void;
79
+ getBucketStates(): Promise<BucketState[]>;
80
+ getBucketOperationProgress(): Promise<BucketOperationProgress>;
81
+ hasMigratedSubkeys(): Promise<boolean>;
82
+ migrateToFixedSubkeys(): Promise<void>;
83
+ syncLocalDatabase(checkpoint: Checkpoint, priority?: number): Promise<{
84
+ checkpointValid: boolean;
85
+ ready: boolean;
86
+ failures?: any[];
87
+ }>;
88
+ nextCrudItem(): Promise<CrudEntry | undefined>;
89
+ hasCrud(): Promise<boolean>;
90
+ getCrudBatch(limit?: number): Promise<CrudBatch | null>;
91
+ hasCompletedSync(): Promise<boolean>;
92
+ updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
93
+ getMaxOpId(): string;
94
+ /**
95
+ * Get an unique client id.
96
+ */
97
+ getClientId(): Promise<string>;
98
+ /**
99
+ * Invokes the `powersync_control` function for the sync client.
100
+ */
101
+ control(op: PowerSyncControlCommand, payload: string | Uint8Array | null): Promise<string>;
102
+ }
@@ -0,0 +1,19 @@
1
+ export var PSInternalTable;
2
+ (function (PSInternalTable) {
3
+ PSInternalTable["DATA"] = "ps_data";
4
+ PSInternalTable["CRUD"] = "ps_crud";
5
+ PSInternalTable["BUCKETS"] = "ps_buckets";
6
+ PSInternalTable["OPLOG"] = "ps_oplog";
7
+ PSInternalTable["UNTYPED"] = "ps_untyped";
8
+ })(PSInternalTable || (PSInternalTable = {}));
9
+ export var PowerSyncControlCommand;
10
+ (function (PowerSyncControlCommand) {
11
+ PowerSyncControlCommand["PROCESS_TEXT_LINE"] = "line_text";
12
+ PowerSyncControlCommand["PROCESS_BSON_LINE"] = "line_binary";
13
+ PowerSyncControlCommand["STOP"] = "stop";
14
+ PowerSyncControlCommand["START"] = "start";
15
+ PowerSyncControlCommand["NOTIFY_TOKEN_REFRESHED"] = "refreshed_token";
16
+ PowerSyncControlCommand["NOTIFY_CRUD_UPLOAD_COMPLETED"] = "completed_upload";
17
+ PowerSyncControlCommand["UPDATE_SUBSCRIPTIONS"] = "update_subscriptions";
18
+ })(PowerSyncControlCommand || (PowerSyncControlCommand = {}));
19
+ //# sourceMappingURL=BucketStorageAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BucketStorageAdapter.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/BucketStorageAdapter.ts"],"names":[],"mappings":"AA4DA,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,mCAAgB,CAAA;IAChB,yCAAsB,CAAA;IACtB,qCAAkB,CAAA;IAClB,yCAAsB,CAAA;AACxB,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAN,IAAY,uBAQX;AARD,WAAY,uBAAuB;IACjC,0DAA+B,CAAA;IAC/B,4DAAiC,CAAA;IACjC,wCAAa,CAAA;IACb,0CAAe,CAAA;IACf,qEAA0C,CAAA;IAC1C,4EAAiD,CAAA;IACjD,wEAA6C,CAAA;AAC/C,CAAC,EARW,uBAAuB,KAAvB,uBAAuB,QAQlC"}
@@ -0,0 +1,31 @@
1
+ import { CrudEntry } from './CrudEntry.js';
2
+ /**
3
+ * A batch of client-side changes.
4
+ */
5
+ export declare class CrudBatch {
6
+ /**
7
+ * List of client-side changes.
8
+ */
9
+ crud: CrudEntry[];
10
+ /**
11
+ * true if there are more changes in the local queue.
12
+ */
13
+ haveMore: boolean;
14
+ /**
15
+ * Call to remove the changes from the local queue, once successfully uploaded.
16
+ */
17
+ complete: (writeCheckpoint?: string) => Promise<void>;
18
+ constructor(
19
+ /**
20
+ * List of client-side changes.
21
+ */
22
+ crud: CrudEntry[],
23
+ /**
24
+ * true if there are more changes in the local queue.
25
+ */
26
+ haveMore: boolean,
27
+ /**
28
+ * Call to remove the changes from the local queue, once successfully uploaded.
29
+ */
30
+ complete: (writeCheckpoint?: string) => Promise<void>);
31
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A batch of client-side changes.
3
+ */
4
+ export class CrudBatch {
5
+ crud;
6
+ haveMore;
7
+ complete;
8
+ constructor(
9
+ /**
10
+ * List of client-side changes.
11
+ */
12
+ crud,
13
+ /**
14
+ * true if there are more changes in the local queue.
15
+ */
16
+ haveMore,
17
+ /**
18
+ * Call to remove the changes from the local queue, once successfully uploaded.
19
+ */
20
+ complete) {
21
+ this.crud = crud;
22
+ this.haveMore = haveMore;
23
+ this.complete = complete;
24
+ }
25
+ }
26
+ //# sourceMappingURL=CrudBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudBatch.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/CrudBatch.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,SAAS;IAKX;IAIA;IAIA;IAZT;IACE;;OAEG;IACI,IAAiB;IACxB;;OAEG;IACI,QAAiB;IACxB;;OAEG;IACI,QAAqD;QARrD,SAAI,GAAJ,IAAI,CAAa;QAIjB,aAAQ,GAAR,QAAQ,CAAS;QAIjB,aAAQ,GAAR,QAAQ,CAA6C;IAC3D,CAAC;CACL"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * 64-bit unsigned integer stored as a string in base-10.
3
+ *
4
+ * Not sortable as a string.
5
+ */
6
+ export type OpId = string;
7
+ /**
8
+ * Type of local change.
9
+ */
10
+ export declare enum UpdateType {
11
+ /** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
12
+ PUT = "PUT",
13
+ /** Update existing row. Contains the id, and value of each changed column. Generated by UPDATE statements. */
14
+ PATCH = "PATCH",
15
+ /** Delete existing row. Contains the id. Generated by DELETE statements. */
16
+ DELETE = "DELETE"
17
+ }
18
+ export type CrudEntryJSON = {
19
+ id: string;
20
+ data: string;
21
+ tx_id?: number;
22
+ };
23
+ /**
24
+ * The output JSON seems to be a third type of JSON, not the same as the input JSON.
25
+ */
26
+ type CrudEntryOutputJSON = {
27
+ op_id: number;
28
+ op: UpdateType;
29
+ type: string;
30
+ id: string;
31
+ tx_id?: number;
32
+ data?: Record<string, any>;
33
+ old?: Record<string, any>;
34
+ metadata?: string;
35
+ };
36
+ /**
37
+ * A single client-side change.
38
+ */
39
+ export declare class CrudEntry {
40
+ /**
41
+ * Auto-incrementing client-side id.
42
+ */
43
+ clientId: number;
44
+ /**
45
+ * ID of the changed row.
46
+ */
47
+ id: string;
48
+ /**
49
+ * Type of change.
50
+ */
51
+ op: UpdateType;
52
+ /**
53
+ * Data associated with the change.
54
+ */
55
+ opData?: Record<string, any>;
56
+ /**
57
+ * For tables where the `trackPreviousValues` option has been enabled, this tracks previous values for
58
+ * `UPDATE` and `DELETE` statements.
59
+ */
60
+ previousValues?: Record<string, any>;
61
+ /**
62
+ * Table that contained the change.
63
+ */
64
+ table: string;
65
+ /**
66
+ * Auto-incrementing transaction id. This is the same for all operations within the same transaction.
67
+ */
68
+ transactionId?: number;
69
+ /**
70
+ * Client-side metadata attached with this write.
71
+ *
72
+ * This field is only available when the `trackMetadata` option was set to `true` when creating a table
73
+ * and the insert or update statement set the `_metadata` column.
74
+ */
75
+ metadata?: string;
76
+ static fromRow(dbRow: CrudEntryJSON): CrudEntry;
77
+ constructor(clientId: number, op: UpdateType, table: string, id: string, transactionId?: number, opData?: Record<string, any>, previousValues?: Record<string, any>, metadata?: string);
78
+ /**
79
+ * Converts the change to JSON format.
80
+ */
81
+ toJSON(): CrudEntryOutputJSON;
82
+ equals(entry: CrudEntry): boolean;
83
+ /**
84
+ * The hash code for this object.
85
+ * @deprecated This should not be necessary in the JS SDK.
86
+ * Use the @see CrudEntry#equals method instead.
87
+ * TODO remove in the next major release.
88
+ */
89
+ hashCode(): string;
90
+ /**
91
+ * Generates an array for use in deep comparison operations
92
+ */
93
+ toComparisonArray(): (string | number | Record<string, any> | undefined)[];
94
+ }
95
+ export {};