@powersync/common 1.57.2 → 2.0.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 (219) hide show
  1. package/lib/attachments/AttachmentContext.d.ts +5 -5
  2. package/lib/attachments/AttachmentContext.js +6 -2
  3. package/lib/attachments/AttachmentContext.js.map +1 -1
  4. package/lib/attachments/AttachmentQueue.d.ts +6 -6
  5. package/lib/attachments/AttachmentQueue.js +9 -8
  6. package/lib/attachments/AttachmentQueue.js.map +1 -1
  7. package/lib/attachments/AttachmentService.d.ts +3 -3
  8. package/lib/attachments/AttachmentService.js +4 -3
  9. package/lib/attachments/AttachmentService.js.map +1 -1
  10. package/lib/attachments/Schema.d.ts +2 -2
  11. package/lib/attachments/SyncingService.d.ts +2 -2
  12. package/lib/attachments/SyncingService.js +21 -6
  13. package/lib/attachments/SyncingService.js.map +1 -1
  14. package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
  15. package/lib/client/CommonPowerSyncDatabase.js +2 -0
  16. package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
  17. package/lib/client/SQLOpenFactory.d.ts +35 -13
  18. package/lib/client/SQLOpenFactory.js +1 -25
  19. package/lib/client/SQLOpenFactory.js.map +1 -1
  20. package/lib/client/compilableQueryWatch.d.ts +2 -2
  21. package/lib/client/compilableQueryWatch.js +1 -2
  22. package/lib/client/compilableQueryWatch.js.map +1 -1
  23. package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
  24. package/lib/client/runOnSchemaChange.d.ts +2 -2
  25. package/lib/client/runOnSchemaChange.js.map +1 -1
  26. package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
  27. package/lib/client/sync/bucket/CrudEntry.js +0 -99
  28. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  29. package/lib/client/sync/options.d.ts +65 -0
  30. package/lib/client/sync/options.js +25 -0
  31. package/lib/client/sync/options.js.map +1 -0
  32. package/lib/client/sync/sync-streams.d.ts +1 -1
  33. package/lib/client/triggers/TriggerManager.d.ts +9 -38
  34. package/lib/client/watched/GetAllQuery.d.ts +3 -3
  35. package/lib/client/watched/GetAllQuery.js +1 -1
  36. package/lib/client/watched/GetAllQuery.js.map +1 -1
  37. package/lib/client/watched/WatchedQuery.d.ts +2 -10
  38. package/lib/client/watched/WatchedQuery.js +0 -11
  39. package/lib/client/watched/WatchedQuery.js.map +1 -1
  40. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
  41. package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
  42. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  43. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
  44. package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
  45. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  46. package/lib/db/DBAdapter.d.ts +72 -154
  47. package/lib/db/DBAdapter.js +70 -108
  48. package/lib/db/DBAdapter.js.map +1 -1
  49. package/lib/db/QueryResult.d.ts +104 -0
  50. package/lib/db/QueryResult.js +96 -0
  51. package/lib/db/QueryResult.js.map +1 -0
  52. package/lib/db/crud/SyncProgress.d.ts +1 -13
  53. package/lib/db/crud/SyncProgress.js +1 -62
  54. package/lib/db/crud/SyncProgress.js.map +1 -1
  55. package/lib/db/crud/SyncStatus.d.ts +32 -66
  56. package/lib/db/crud/SyncStatus.js +1 -253
  57. package/lib/db/crud/SyncStatus.js.map +1 -1
  58. package/lib/db/schema/Column.d.ts +0 -7
  59. package/lib/db/schema/Column.js +0 -7
  60. package/lib/db/schema/Column.js.map +1 -1
  61. package/lib/db/schema/Index.d.ts +2 -6
  62. package/lib/db/schema/Index.js +1 -4
  63. package/lib/db/schema/Index.js.map +1 -1
  64. package/lib/db/schema/IndexedColumn.d.ts +2 -6
  65. package/lib/db/schema/IndexedColumn.js +1 -4
  66. package/lib/db/schema/IndexedColumn.js.map +1 -1
  67. package/lib/db/schema/Schema.d.ts +4 -28
  68. package/lib/db/schema/Schema.js.map +1 -1
  69. package/lib/db/schema/Table.d.ts +50 -96
  70. package/lib/db/schema/Table.js +83 -91
  71. package/lib/db/schema/Table.js.map +1 -1
  72. package/lib/index.d.ts +5 -21
  73. package/lib/index.js +5 -22
  74. package/lib/index.js.map +1 -1
  75. package/lib/utils/BaseObserver.d.ts +1 -1
  76. package/lib/utils/BaseObserver.js +1 -1
  77. package/lib/utils/Logger.d.ts +52 -23
  78. package/lib/utils/Logger.js +35 -33
  79. package/lib/utils/Logger.js.map +1 -1
  80. package/lib/utils/MetaBaseObserver.d.ts +11 -11
  81. package/lib/utils/MetaBaseObserver.js +1 -50
  82. package/lib/utils/MetaBaseObserver.js.map +1 -1
  83. package/lib/utils/mutex.d.ts +3 -53
  84. package/lib/utils/mutex.js +1 -156
  85. package/lib/utils/mutex.js.map +1 -1
  86. package/package.json +8 -45
  87. package/src/attachments/AttachmentContext.ts +11 -10
  88. package/src/attachments/AttachmentQueue.ts +15 -14
  89. package/src/attachments/AttachmentService.ts +7 -6
  90. package/src/attachments/Schema.ts +2 -2
  91. package/src/attachments/SyncingService.ts +23 -9
  92. package/src/client/CommonPowerSyncDatabase.ts +540 -0
  93. package/src/client/SQLOpenFactory.ts +38 -22
  94. package/src/client/compilableQueryWatch.ts +3 -4
  95. package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
  96. package/src/client/runOnSchemaChange.ts +2 -2
  97. package/src/client/sync/bucket/CrudEntry.ts +4 -104
  98. package/src/client/sync/options.ts +77 -0
  99. package/src/client/sync/sync-streams.ts +1 -1
  100. package/src/client/triggers/TriggerManager.ts +10 -41
  101. package/src/client/watched/GetAllQuery.ts +3 -3
  102. package/src/client/watched/WatchedQuery.ts +2 -15
  103. package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
  104. package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
  105. package/src/db/DBAdapter.ts +141 -226
  106. package/src/db/QueryResult.ts +195 -0
  107. package/src/db/crud/SyncProgress.ts +2 -42
  108. package/src/db/crud/SyncStatus.ts +45 -220
  109. package/src/db/schema/Column.ts +0 -8
  110. package/src/db/schema/Index.ts +3 -6
  111. package/src/db/schema/IndexedColumn.ts +3 -6
  112. package/src/db/schema/Schema.ts +4 -4
  113. package/src/db/schema/Table.ts +111 -186
  114. package/src/index.ts +5 -21
  115. package/src/utils/BaseObserver.ts +1 -1
  116. package/src/utils/Logger.ts +80 -42
  117. package/src/utils/MetaBaseObserver.ts +14 -60
  118. package/src/utils/mutex.ts +4 -201
  119. package/dist/bundle.cjs +0 -14393
  120. package/dist/bundle.cjs.map +0 -1
  121. package/dist/bundle.mjs +0 -14312
  122. package/dist/bundle.mjs.map +0 -1
  123. package/dist/bundle.node.cjs +0 -12024
  124. package/dist/bundle.node.cjs.map +0 -1
  125. package/dist/bundle.node.mjs +0 -11943
  126. package/dist/bundle.node.mjs.map +0 -1
  127. package/dist/index.d.cts +0 -4651
  128. package/legacy/sync_protocol.d.ts +0 -103
  129. package/lib/client/AbstractPowerSyncDatabase.js +0 -990
  130. package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
  131. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
  132. package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
  133. package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
  134. package/lib/client/ConnectionManager.d.ts +0 -115
  135. package/lib/client/ConnectionManager.js +0 -294
  136. package/lib/client/ConnectionManager.js.map +0 -1
  137. package/lib/client/CustomQuery.d.ts +0 -22
  138. package/lib/client/CustomQuery.js +0 -43
  139. package/lib/client/CustomQuery.js.map +0 -1
  140. package/lib/client/constants.d.ts +0 -4
  141. package/lib/client/constants.js +0 -5
  142. package/lib/client/constants.js.map +0 -1
  143. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
  144. package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
  145. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
  146. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
  147. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
  148. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
  149. package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
  150. package/lib/client/sync/stream/AbstractRemote.js +0 -508
  151. package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
  152. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
  153. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -705
  154. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
  155. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
  156. package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
  157. package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
  158. package/lib/client/sync/stream/core-instruction.d.ts +0 -77
  159. package/lib/client/sync/stream/core-instruction.js +0 -30
  160. package/lib/client/sync/stream/core-instruction.js.map +0 -1
  161. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
  162. package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
  163. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
  164. package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
  165. package/lib/client/triggers/TriggerManagerImpl.js +0 -410
  166. package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
  167. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
  168. package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
  169. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
  170. package/lib/db/ConnectionClosedError.d.ts +0 -12
  171. package/lib/db/ConnectionClosedError.js +0 -23
  172. package/lib/db/ConnectionClosedError.js.map +0 -1
  173. package/lib/db/schema/TableV2.d.ts +0 -11
  174. package/lib/db/schema/TableV2.js +0 -11
  175. package/lib/db/schema/TableV2.js.map +0 -1
  176. package/lib/utils/AbortOperation.d.ts +0 -11
  177. package/lib/utils/AbortOperation.js +0 -21
  178. package/lib/utils/AbortOperation.js.map +0 -1
  179. package/lib/utils/ControlledExecutor.d.ts +0 -31
  180. package/lib/utils/ControlledExecutor.js +0 -54
  181. package/lib/utils/ControlledExecutor.js.map +0 -1
  182. package/lib/utils/async.d.ts +0 -46
  183. package/lib/utils/async.js +0 -147
  184. package/lib/utils/async.js.map +0 -1
  185. package/lib/utils/compatibility.d.ts +0 -8
  186. package/lib/utils/compatibility.js +0 -9
  187. package/lib/utils/compatibility.js.map +0 -1
  188. package/lib/utils/parseQuery.d.ts +0 -12
  189. package/lib/utils/parseQuery.js +0 -20
  190. package/lib/utils/parseQuery.js.map +0 -1
  191. package/lib/utils/queue.d.ts +0 -16
  192. package/lib/utils/queue.js +0 -42
  193. package/lib/utils/queue.js.map +0 -1
  194. package/lib/utils/stream_transform.d.ts +0 -41
  195. package/lib/utils/stream_transform.js +0 -211
  196. package/lib/utils/stream_transform.js.map +0 -1
  197. package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
  198. package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
  199. package/src/client/ConnectionManager.ts +0 -405
  200. package/src/client/CustomQuery.ts +0 -56
  201. package/src/client/constants.ts +0 -4
  202. package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
  203. package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
  204. package/src/client/sync/stream/AbstractRemote.ts +0 -648
  205. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
  206. package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
  207. package/src/client/sync/stream/core-instruction.ts +0 -109
  208. package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
  209. package/src/client/triggers/TriggerManagerImpl.ts +0 -501
  210. package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
  211. package/src/db/ConnectionClosedError.ts +0 -25
  212. package/src/db/schema/TableV2.ts +0 -11
  213. package/src/utils/AbortOperation.ts +0 -19
  214. package/src/utils/ControlledExecutor.ts +0 -78
  215. package/src/utils/async.ts +0 -185
  216. package/src/utils/compatibility.ts +0 -9
  217. package/src/utils/parseQuery.ts +0 -31
  218. package/src/utils/queue.ts +0 -48
  219. package/src/utils/stream_transform.ts +0 -260
@@ -1,177 +1,2 @@
1
- import { AbstractQueryProcessor } from './AbstractQueryProcessor.js';
2
- /**
3
- * An empty differential result set.
4
- * This is used as the initial state for differential incrementally watched queries.
5
- *
6
- * @internal
7
- */
8
- export const EMPTY_DIFFERENTIAL = {
9
- added: [],
10
- all: [],
11
- removed: [],
12
- updated: [],
13
- unchanged: []
14
- };
15
- /**
16
- * Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
17
- * It keys items by their `id` property if available, alternatively it uses JSON stringification
18
- * of the entire item for the key and comparison.
19
- *
20
- * @internal
21
- */
22
- export const DEFAULT_ROW_COMPARATOR = {
23
- keyBy: (item) => {
24
- if (item && typeof item == 'object' && typeof item['id'] == 'string') {
25
- return item['id'];
26
- }
27
- return JSON.stringify(item);
28
- },
29
- compareBy: (item) => JSON.stringify(item)
30
- };
31
- /**
32
- * Uses the PowerSync onChange event to trigger watched queries.
33
- * Results are emitted on every change of the relevant tables.
34
- * @internal
35
- */
36
- export class DifferentialQueryProcessor extends AbstractQueryProcessor {
37
- options;
38
- comparator;
39
- constructor(options) {
40
- super(options);
41
- this.options = options;
42
- this.comparator = options.rowComparator ?? DEFAULT_ROW_COMPARATOR;
43
- }
44
- /*
45
- * @returns If the sets are equal
46
- */
47
- differentiate(current, previousMap) {
48
- const { keyBy, compareBy } = this.comparator;
49
- let hasChanged = false;
50
- const currentMap = new Map();
51
- const removedTracker = new Set(previousMap.keys());
52
- // Allow mutating to populate the data temporarily.
53
- const diff = {
54
- all: [],
55
- added: [],
56
- removed: [],
57
- updated: [],
58
- unchanged: []
59
- };
60
- /**
61
- * Looping over the current result set array is important to preserve
62
- * the ordering of the result set.
63
- * We can replace items in the current array with previous object references if they are equal.
64
- */
65
- for (const item of current) {
66
- const key = keyBy(item);
67
- const hash = compareBy(item);
68
- currentMap.set(key, { hash, item });
69
- const previousItem = previousMap.get(key);
70
- if (!previousItem) {
71
- // New item
72
- hasChanged = true;
73
- diff.added.push(item);
74
- diff.all.push(item);
75
- }
76
- else {
77
- // Existing item
78
- if (hash == previousItem.hash) {
79
- diff.unchanged.push(previousItem.item);
80
- // Use the previous object reference
81
- diff.all.push(previousItem.item);
82
- // update the map to preserve the reference
83
- currentMap.set(key, previousItem);
84
- }
85
- else {
86
- hasChanged = true;
87
- diff.updated.push({ current: item, previous: previousItem.item });
88
- // Use the new reference
89
- diff.all.push(item);
90
- }
91
- }
92
- // The item is present, we don't consider it removed
93
- removedTracker.delete(key);
94
- }
95
- diff.removed = Array.from(removedTracker).map((key) => previousMap.get(key).item);
96
- hasChanged = hasChanged || diff.removed.length > 0;
97
- return {
98
- diff,
99
- hasChanged,
100
- map: currentMap
101
- };
102
- }
103
- async linkQuery(options) {
104
- const { db, watchOptions } = this.options;
105
- const { abortSignal } = options;
106
- const compiledQuery = watchOptions.query.compile();
107
- const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
108
- tables: options.settings.triggerOnTables
109
- });
110
- let currentMap = new Map();
111
- // populate the currentMap from the placeholder data
112
- this.state.data.forEach((item) => {
113
- currentMap.set(this.comparator.keyBy(item), {
114
- hash: this.comparator.compareBy(item),
115
- item
116
- });
117
- });
118
- db.onChangeWithCallback({
119
- onChange: async () => {
120
- if (this.closed || abortSignal.aborted) {
121
- return;
122
- }
123
- // This fires for each change of the relevant tables
124
- try {
125
- if (this.reportFetching && !this.state.isFetching) {
126
- await this.updateState({ isFetching: true });
127
- }
128
- const partialStateUpdate = {};
129
- // Always run the query if an underlying table has changed
130
- const result = await watchOptions.query.execute({
131
- sql: compiledQuery.sql,
132
- // Allows casting from ReadOnlyArray[unknown] to Array<unknown>
133
- // This allows simpler compatibility with PowerSync queries
134
- parameters: [...compiledQuery.parameters],
135
- db: this.options.db
136
- });
137
- if (abortSignal.aborted) {
138
- return;
139
- }
140
- if (this.reportFetching) {
141
- partialStateUpdate.isFetching = false;
142
- }
143
- if (this.state.isLoading) {
144
- partialStateUpdate.isLoading = false;
145
- }
146
- const { diff, hasChanged, map } = this.differentiate(result, currentMap);
147
- // Update for future comparisons
148
- currentMap = map;
149
- if (hasChanged) {
150
- await this.iterateAsyncListenersWithError((l) => l.onDiff?.(diff));
151
- Object.assign(partialStateUpdate, {
152
- data: diff.all
153
- });
154
- }
155
- if (this.state.error) {
156
- partialStateUpdate.error = null;
157
- }
158
- if (Object.keys(partialStateUpdate).length > 0) {
159
- await this.updateState(partialStateUpdate);
160
- }
161
- }
162
- catch (error) {
163
- await this.updateState({ error });
164
- }
165
- },
166
- onError: async (error) => {
167
- await this.updateState({ error });
168
- }
169
- }, {
170
- signal: abortSignal,
171
- tables,
172
- throttleMs: watchOptions.throttleMs,
173
- triggerImmediate: true // used to emit the initial state
174
- });
175
- }
176
- }
1
+ export {};
177
2
  //# sourceMappingURL=DifferentialQueryProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DifferentialQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/DifferentialQueryProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EAIvB,MAAM,6BAA6B,CAAC;AAuHrC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,EAAE;CACd,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA4C;IAC7E,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ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,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACvB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACpC,CAAC;SACF,EACD;YACE,MAAM,EAAE,WAAW;YACnB,MAAM;YACN,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,gBAAgB,EAAE,IAAI,CAAC,iCAAiC;SACzD,CACF,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"DifferentialQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/DifferentialQueryProcessor.ts"],"names":[],"mappings":""}
@@ -1,6 +1,4 @@
1
1
  import { WatchCompatibleQuery, WatchedQuery, WatchedQueryOptions } from '../WatchedQuery.js';
2
- import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
3
- import { WatchedQueryComparator } from './comparators.js';
4
2
  /**
5
3
  * Settings for {@link WatchedQuery} instances created via {@link Query#watch}.
6
4
  *
@@ -15,23 +13,3 @@ export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
15
13
  * @public
16
14
  */
17
15
  export type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
18
- /**
19
- * @internal
20
- */
21
- export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
22
- comparator?: WatchedQueryComparator<Data>;
23
- }
24
- /**
25
- * Uses the PowerSync onChange event to trigger watched queries.
26
- * Results are emitted on every change of the relevant tables.
27
- * @internal
28
- */
29
- export declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
30
- protected options: OnChangeQueryProcessorOptions<Data>;
31
- constructor(options: OnChangeQueryProcessorOptions<Data>);
32
- /**
33
- * @returns If the sets are equal
34
- */
35
- protected checkEquality(current: Data, previous: Data): boolean;
36
- protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
37
- }
@@ -1,83 +1,2 @@
1
- import { AbstractQueryProcessor } from './AbstractQueryProcessor.js';
2
- /**
3
- * Uses the PowerSync onChange event to trigger watched queries.
4
- * Results are emitted on every change of the relevant tables.
5
- * @internal
6
- */
7
- export class OnChangeQueryProcessor extends AbstractQueryProcessor {
8
- options;
9
- constructor(options) {
10
- super(options);
11
- this.options = options;
12
- }
13
- /**
14
- * @returns If the sets are equal
15
- */
16
- checkEquality(current, previous) {
17
- // Use the provided comparator if available. Assume values are unique if not available.
18
- return this.options.comparator?.checkEquality?.(current, previous) ?? false;
19
- }
20
- async linkQuery(options) {
21
- const { db, watchOptions } = this.options;
22
- const { abortSignal } = options;
23
- const compiledQuery = watchOptions.query.compile();
24
- const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
25
- tables: options.settings.triggerOnTables
26
- });
27
- db.onChangeWithCallback({
28
- onChange: async () => {
29
- if (this.closed || abortSignal.aborted) {
30
- return;
31
- }
32
- // This fires for each change of the relevant tables
33
- try {
34
- if (this.reportFetching && !this.state.isFetching) {
35
- await this.updateState({ isFetching: true });
36
- }
37
- const partialStateUpdate = {};
38
- // Always run the query if an underlying table has changed
39
- const result = await watchOptions.query.execute({
40
- sql: compiledQuery.sql,
41
- // Allows casting from ReadOnlyArray[unknown] to Array<unknown>
42
- // This allows simpler compatibility with PowerSync queries
43
- parameters: [...compiledQuery.parameters],
44
- db: this.options.db
45
- });
46
- if (abortSignal.aborted) {
47
- return;
48
- }
49
- if (this.reportFetching) {
50
- partialStateUpdate.isFetching = false;
51
- }
52
- if (this.state.isLoading) {
53
- partialStateUpdate.isLoading = false;
54
- }
55
- // Check if the result has changed
56
- if (!this.checkEquality(result, this.state.data)) {
57
- Object.assign(partialStateUpdate, {
58
- data: result
59
- });
60
- }
61
- if (this.state.error) {
62
- partialStateUpdate.error = null;
63
- }
64
- if (Object.keys(partialStateUpdate).length > 0) {
65
- await this.updateState(partialStateUpdate);
66
- }
67
- }
68
- catch (error) {
69
- await this.updateState({ error });
70
- }
71
- },
72
- onError: async (error) => {
73
- await this.updateState({ error });
74
- }
75
- }, {
76
- signal: abortSignal,
77
- tables,
78
- throttleMs: watchOptions.throttleMs,
79
- triggerImmediate: true // used to emit the initial state
80
- });
81
- }
82
- }
1
+ export {};
83
2
  //# sourceMappingURL=OnChangeQueryProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/OnChangeQueryProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EAIvB,MAAM,6BAA6B,CAAC;AA6BrC;;;;GAIG;AACH,MAAM,OAAO,sBAA6B,SAAQ,sBAAwD;IAClF;IAAtB,YAAsB,OAA4C;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QADK,YAAO,GAAP,OAAO,CAAqC;IAElE,CAAC;IAED;;OAEG;IACO,aAAa,CAAC,OAAa,EAAE,QAAc;QACnD,uFAAuF;QACvF,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,KAAK,CAAC;IAC9E,CAAC;IAES,KAAK,CAAC,SAAS,CAAC,OAA+B;QACvD,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAEhC,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,UAAmB,EAAE;YAC1F,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,eA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AI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;wBACrB,kBAAkB,CAAC,KAAK,GAAG,IAAI,CAAC;oBAClC,CAAC;oBAED,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC/C,MAAM,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;oBAC7C,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACvB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACpC,CAAC;SACF,EACD;YACE,MAAM,EAAE,WAAW;YACnB,MAAM;YACN,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,gBAAgB,EAAE,IAAI,CAAC,iCAAiC;SACzD,CACF,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/OnChangeQueryProcessor.ts"],"names":[],"mappings":""}
@@ -2,148 +2,100 @@
2
2
  * Set of generic interfaces to allow PowerSync compatibility with
3
3
  * different SQLite DB implementations.
4
4
  */
5
- import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver.js';
5
+ import { BaseListener, BaseObserver } from '../utils/BaseObserver.js';
6
+ import { QueryResult, RawQueryResult, SqliteRecord } from './QueryResult.js';
6
7
  /**
7
- * TODO most of these types could be exported to a common `types` package
8
- * which is used by the DB adapter libraries as well.
9
- */
10
- /**
11
- * Object returned by SQL Query executions.
12
- *
13
8
  * @public
14
9
  */
15
- export type QueryResult = {
16
- /** Represents the auto-generated row id if applicable. */
17
- insertId?: number;
10
+ export interface DBGetUtils {
18
11
  /**
19
- * Number of affected rows reported by SQLite for a write query.
12
+ * Execute a read-only query and return results.
20
13
  *
21
- * When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
22
- * `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
23
- * Use a `RETURNING` clause and inspect `rows` when you need to confirm which rows changed.
14
+ * @param sql - The SQL query to execute
15
+ * @param parameters - Optional array of parameters to bind to the query
16
+ * @returns An array of results
24
17
  */
25
- rowsAffected: number;
26
- /** if status is undefined or 0 this object will contain the query results */
27
- rows?: {
28
- /** Raw array with all dataset */
29
- _array: any[];
30
- /** The length of the dataset */
31
- length: number;
32
- /** A convenience function to acess the index based the row object
33
- * @param idx - the row index
34
- * @returns the row structure identified by column names
35
- */
36
- item: (idx: number) => any;
37
- };
38
- };
39
- /**
40
- * @public
41
- */
42
- export interface DBGetUtils {
43
- /** Execute a read-only query and return results. */
44
18
  getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
45
- /** Execute a read-only query and return the first result, or null if the ResultSet is empty. */
19
+ /**
20
+ * Execute a read-only query and return the first result, or null if the ResultSet is empty.
21
+ *
22
+ * @param sql - The SQL query to execute
23
+ * @param parameters - Optional array of parameters to bind to the query
24
+ * @returns The first result if found, or null if no results are returned
25
+ */
46
26
  getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
47
- /** Execute a read-only query and return the first result, error if the ResultSet is empty. */
27
+ /**
28
+ * Execute a read-only query and return the first result, error if the ResultSet is empty.
29
+ *
30
+ * @param sql - The SQL query to execute
31
+ * @param parameters - Optional array of parameters to bind to the query
32
+ * @returns The first result matching the query
33
+ * @throws Error if no rows are returned
34
+ */
48
35
  get<T>(sql: string, parameters?: any[]): Promise<T>;
49
36
  }
50
37
  /**
51
38
  * @public
52
39
  */
53
40
  export interface SqlExecutor {
54
- /** Execute a single write statement. */
55
- execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
56
41
  /**
57
- * Execute a single write statement and return raw results.
58
- * Unlike `execute`, which returns an object with structured key-value pairs,
59
- * `executeRaw` returns a nested array of raw values, where each row is
60
- * represented as an array of column values without field names.
61
- *
62
- * Example result:
42
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
43
+ * and optionally return results.
63
44
  *
64
- * ```JavaScript
65
- * [ [ '1', 'list 1', '33', 'Post content', '1' ] ]
66
- * ```
45
+ * When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
46
+ * the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
47
+ * Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
67
48
  *
68
- * Where as `execute`'s `rows._array` would have been:
49
+ * @param sql - The SQL query to execute
50
+ * @param parameters - Optional array of parameters to bind to the query
51
+ * @returns The query result as an object with structured key-value pairs
52
+ */
53
+ execute: <T = SqliteRecord>(query: string, params?: any[] | undefined) => Promise<QueryResult<T>>;
54
+ /**
55
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
56
+ * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
69
57
  *
70
- * ```JavaScript
71
- * [ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]
72
- * ```
58
+ * @param sql - The SQL query to execute
59
+ * @param parameters - Optional array of parameters to bind to the query
60
+ * @returns The {@link RawQueryResult} representing each row as an array.
73
61
  */
74
- executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
75
- executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
76
- }
77
- /**
78
- * @public
79
- */
80
- export interface LockContext extends SqlExecutor, DBGetUtils {
62
+ executeRaw: (query: string, params?: any[] | undefined) => Promise<RawQueryResult>;
81
63
  /**
82
- * How the connection has been opened.
64
+ * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
65
+ * and optionally return results.
66
+ * This is faster than executing separately with each parameter set.
83
67
  *
84
- * `writer` indicates that the lock context is capable of writing to the database.
85
- * `queryOnly` indicates that the lock context has been opened in a readwrite mode, but a `PRAGMA query_only = TRUE`
86
- * disabled writes.
87
- * `readOnly` indicates that the lock context has been opened by passing `SQLITE_OPEN_READONLY` to `sqlite3_open_v2`.
68
+ * @param sql - The SQL query to execute
69
+ * @param parameters - Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
70
+ * @returns The query result
88
71
  */
89
- connectionType?: 'writer' | 'queryOnly' | 'readOnly';
72
+ executeBatch: (query: string, params?: any[][]) => Promise<QueryResult<never>>;
90
73
  }
91
74
  /**
92
- * Implements {@link DBGetUtils} on a {@link SqlExecutor}.
93
- *
94
- * @internal
75
+ * @public
95
76
  */
96
- export declare function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omit<SqlExecutor, 'executeBatch'>>(Base: TBase): {
97
- new (...args: any[]): {
98
- getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
99
- getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
100
- get<T>(sql: string, parameters?: any[]): Promise<T>;
101
- executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
102
- execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
103
- executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
104
- };
105
- } & TBase;
77
+ export declare abstract class LockContext implements SqlExecutor, DBGetUtils {
78
+ abstract executeRaw<T>(query: string, params?: any[] | undefined): Promise<RawQueryResult>;
79
+ getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
80
+ getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
81
+ get<T>(sql: string, parameters?: any[]): Promise<T>;
82
+ execute<T = SqliteRecord>(query: string, params?: any[] | undefined): Promise<QueryResult<T>>;
83
+ executeBatch(query: string, params?: any[][]): Promise<QueryResult<never>>;
84
+ }
106
85
  /**
107
86
  * @public
108
87
  */
109
88
  export interface Transaction extends LockContext {
110
89
  /** Commit multiple changes to the local DB using the Transaction context. */
111
- commit: () => Promise<QueryResult>;
90
+ commit: () => Promise<void>;
112
91
  /** Roll back multiple attempted changes using the Transaction context. */
113
- rollback: () => Promise<QueryResult>;
114
- }
115
- /**
116
- * Update table operation numbers from SQLite
117
- *
118
- * @public
119
- */
120
- export declare enum RowUpdateType {
121
- SQLITE_INSERT = 18,
122
- SQLITE_DELETE = 9,
123
- SQLITE_UPDATE = 23
124
- }
125
- /**
126
- * @public
127
- */
128
- export interface TableUpdateOperation {
129
- opType: RowUpdateType;
130
- rowId: number;
131
- }
132
- /**
133
- * Notification of an update to one or more tables, for the purpose of realtime change notifications.
134
- *
135
- * @public
136
- */
137
- export interface UpdateNotification extends TableUpdateOperation {
138
- table: string;
92
+ rollback: () => Promise<void>;
139
93
  }
140
94
  /**
141
95
  * @public
142
96
  */
143
97
  export interface BatchedUpdateNotification {
144
- rawUpdates: UpdateNotification[];
145
98
  tables: string[];
146
- groupedUpdates: Record<string, TableUpdateOperation[]>;
147
99
  }
148
100
  /**
149
101
  * @public
@@ -155,7 +107,7 @@ export interface DBAdapterListener extends BaseListener {
155
107
  * without the need for a major version bump
156
108
  * The DB adapter can also batch update notifications if supported.
157
109
  */
158
- tablesUpdated: (updateNotification: BatchedUpdateNotification | UpdateNotification) => void;
110
+ tablesUpdated: (updateNotification: BatchedUpdateNotification) => void;
159
111
  }
160
112
  /**
161
113
  * @public
@@ -166,55 +118,21 @@ export interface DBLockOptions {
166
118
  /**
167
119
  * @public
168
120
  */
169
- export interface ConnectionPool extends BaseObserverInterface<DBAdapterListener> {
170
- name: string;
171
- close: () => void | Promise<void>;
172
- readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
173
- writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
121
+ export declare abstract class DBAdapter extends BaseObserver<DBAdapterListener> implements SqlExecutor, DBGetUtils {
122
+ abstract get name(): string;
123
+ abstract close(): void | Promise<void>;
124
+ abstract readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
125
+ abstract writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
174
126
  /**
175
127
  * This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
176
128
  */
177
- refreshSchema: () => Promise<void>;
178
- }
179
- /**
180
- * @public
181
- */
182
- export interface DBAdapter extends ConnectionPool, SqlExecutor, DBGetUtils {
183
- readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
184
- writeTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
129
+ abstract refreshSchema(): Promise<void>;
130
+ readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
131
+ writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
132
+ getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
133
+ getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
134
+ get<T>(sql: string, parameters?: any[]): Promise<T>;
135
+ execute<T>(query: string, params?: any[]): Promise<QueryResult<T>>;
136
+ executeRaw(query: string, params?: any[]): Promise<RawQueryResult>;
137
+ executeBatch(query: string, params?: any[][]): Promise<QueryResult<never>>;
185
138
  }
186
- /**
187
- * A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool#readLock} and
188
- * {@link ConnectionPool#writeLock}.
189
- *
190
- * @internal
191
- */
192
- export declare function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase): {
193
- new (...args: any[]): {
194
- readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
195
- writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
196
- getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
197
- getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
198
- get<T>(sql: string, parameters?: any[]): Promise<T>;
199
- execute(query: string, params?: any[]): Promise<QueryResult>;
200
- executeRaw(query: string, params?: any[]): Promise<any[][]>;
201
- executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
202
- name: string;
203
- close: () => void | Promise<void>;
204
- readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
205
- writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
206
- /**
207
- * This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
208
- */
209
- refreshSchema: () => Promise<void>;
210
- registerListener(listener: Partial<DBAdapterListener>): () => void;
211
- };
212
- } & TBase;
213
- /**
214
- * @internal
215
- */
216
- export declare function isBatchedUpdateNotification(update: BatchedUpdateNotification | UpdateNotification): update is BatchedUpdateNotification;
217
- /**
218
- * @internal
219
- */
220
- export declare function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification): string[];