@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630144038

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 (263) hide show
  1. package/lib/attachments/AttachmentContext.d.ts +9 -8
  2. package/lib/attachments/AttachmentContext.js +8 -3
  3. package/lib/attachments/AttachmentContext.js.map +1 -1
  4. package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
  5. package/lib/attachments/AttachmentQueue.d.ts +85 -36
  6. package/lib/attachments/AttachmentQueue.js +19 -21
  7. package/lib/attachments/AttachmentQueue.js.map +1 -1
  8. package/lib/attachments/AttachmentService.d.ts +3 -3
  9. package/lib/attachments/AttachmentService.js +4 -3
  10. package/lib/attachments/AttachmentService.js.map +1 -1
  11. package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
  12. package/lib/attachments/LocalStorageAdapter.js +3 -0
  13. package/lib/attachments/LocalStorageAdapter.js.map +1 -1
  14. package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
  15. package/lib/attachments/Schema.d.ts +14 -6
  16. package/lib/attachments/Schema.js +8 -3
  17. package/lib/attachments/Schema.js.map +1 -1
  18. package/lib/attachments/SyncingService.d.ts +2 -2
  19. package/lib/attachments/SyncingService.js +8 -3
  20. package/lib/attachments/SyncingService.js.map +1 -1
  21. package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
  22. package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
  23. package/lib/client/CommonPowerSyncDatabase.js +2 -0
  24. package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
  25. package/lib/client/Query.d.ts +9 -0
  26. package/lib/client/SQLOpenFactory.d.ts +44 -10
  27. package/lib/client/SQLOpenFactory.js +1 -19
  28. package/lib/client/SQLOpenFactory.js.map +1 -1
  29. package/lib/client/compilableQueryWatch.d.ts +8 -2
  30. package/lib/client/compilableQueryWatch.js +4 -2
  31. package/lib/client/compilableQueryWatch.js.map +1 -1
  32. package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
  33. package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
  34. package/lib/client/runOnSchemaChange.d.ts +5 -2
  35. package/lib/client/runOnSchemaChange.js +3 -0
  36. package/lib/client/runOnSchemaChange.js.map +1 -1
  37. package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
  38. package/lib/client/sync/bucket/CrudBatch.js +2 -0
  39. package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
  40. package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
  41. package/lib/client/sync/bucket/CrudEntry.js +2 -97
  42. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  43. package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
  44. package/lib/client/sync/bucket/CrudTransaction.js +3 -0
  45. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
  46. package/lib/client/sync/options.d.ts +65 -0
  47. package/lib/client/sync/options.js +25 -0
  48. package/lib/client/sync/options.js.map +1 -0
  49. package/lib/client/sync/stream/JsonValue.d.ts +3 -0
  50. package/lib/client/sync/sync-streams.d.ts +23 -8
  51. package/lib/client/triggers/TriggerManager.d.ts +28 -56
  52. package/lib/client/triggers/TriggerManager.js +2 -1
  53. package/lib/client/triggers/TriggerManager.js.map +1 -1
  54. package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
  55. package/lib/client/triggers/sanitizeSQL.js +4 -0
  56. package/lib/client/triggers/sanitizeSQL.js.map +1 -1
  57. package/lib/client/watched/GetAllQuery.d.ts +7 -3
  58. package/lib/client/watched/GetAllQuery.js +3 -1
  59. package/lib/client/watched/GetAllQuery.js.map +1 -1
  60. package/lib/client/watched/WatchedQuery.d.ts +20 -6
  61. package/lib/client/watched/WatchedQuery.js +3 -5
  62. package/lib/client/watched/WatchedQuery.js.map +1 -1
  63. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
  64. package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
  65. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  66. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
  67. package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
  68. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  69. package/lib/client/watched/processors/comparators.d.ts +8 -0
  70. package/lib/client/watched/processors/comparators.js +4 -0
  71. package/lib/client/watched/processors/comparators.js.map +1 -1
  72. package/lib/db/DBAdapter.d.ts +90 -113
  73. package/lib/db/DBAdapter.js +70 -89
  74. package/lib/db/DBAdapter.js.map +1 -1
  75. package/lib/db/QueryResult.d.ts +104 -0
  76. package/lib/db/QueryResult.js +96 -0
  77. package/lib/db/QueryResult.js.map +1 -0
  78. package/lib/db/crud/SyncProgress.d.ts +7 -14
  79. package/lib/db/crud/SyncProgress.js +1 -60
  80. package/lib/db/crud/SyncProgress.js.map +1 -1
  81. package/lib/db/crud/SyncStatus.d.ts +54 -91
  82. package/lib/db/crud/SyncStatus.js +1 -245
  83. package/lib/db/crud/SyncStatus.js.map +1 -1
  84. package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
  85. package/lib/db/crud/UploadQueueStatus.js +3 -0
  86. package/lib/db/crud/UploadQueueStatus.js.map +1 -1
  87. package/lib/db/schema/Column.d.ts +22 -1
  88. package/lib/db/schema/Column.js +10 -4
  89. package/lib/db/schema/Column.js.map +1 -1
  90. package/lib/db/schema/Index.d.ts +8 -3
  91. package/lib/db/schema/Index.js +4 -1
  92. package/lib/db/schema/Index.js.map +1 -1
  93. package/lib/db/schema/IndexedColumn.d.ts +8 -3
  94. package/lib/db/schema/IndexedColumn.js +4 -1
  95. package/lib/db/schema/IndexedColumn.js.map +1 -1
  96. package/lib/db/schema/RawTable.d.ts +7 -1
  97. package/lib/db/schema/Schema.d.ts +10 -29
  98. package/lib/db/schema/Schema.js +3 -1
  99. package/lib/db/schema/Schema.js.map +1 -1
  100. package/lib/db/schema/Table.d.ts +69 -91
  101. package/lib/db/schema/Table.js +88 -87
  102. package/lib/db/schema/Table.js.map +1 -1
  103. package/lib/index.d.ts +6 -22
  104. package/lib/index.js +5 -22
  105. package/lib/index.js.map +1 -1
  106. package/lib/types/types.d.ts +6 -0
  107. package/lib/utils/BaseObserver.d.ts +12 -0
  108. package/lib/utils/BaseObserver.js +3 -0
  109. package/lib/utils/BaseObserver.js.map +1 -1
  110. package/lib/utils/Logger.d.ts +60 -22
  111. package/lib/utils/Logger.js +38 -30
  112. package/lib/utils/Logger.js.map +1 -1
  113. package/lib/utils/MetaBaseObserver.d.ts +11 -11
  114. package/lib/utils/MetaBaseObserver.js +1 -50
  115. package/lib/utils/MetaBaseObserver.js.map +1 -1
  116. package/lib/utils/mutex.d.ts +3 -45
  117. package/lib/utils/mutex.js +1 -153
  118. package/lib/utils/mutex.js.map +1 -1
  119. package/package.json +9 -46
  120. package/src/attachments/AttachmentContext.ts +15 -13
  121. package/src/attachments/AttachmentErrorHandler.ts +6 -6
  122. package/src/attachments/AttachmentQueue.ts +99 -42
  123. package/src/attachments/AttachmentService.ts +7 -6
  124. package/src/attachments/LocalStorageAdapter.ts +14 -8
  125. package/src/attachments/README.md +2 -0
  126. package/src/attachments/RemoteStorageAdapter.ts +4 -4
  127. package/src/attachments/Schema.ts +14 -6
  128. package/src/attachments/SyncingService.ts +10 -6
  129. package/src/attachments/WatchedAttachmentItem.ts +3 -1
  130. package/src/client/CommonPowerSyncDatabase.ts +540 -0
  131. package/src/client/Query.ts +9 -0
  132. package/src/client/SQLOpenFactory.ts +47 -19
  133. package/src/client/compilableQueryWatch.ts +9 -4
  134. package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
  135. package/src/client/connection/PowerSyncCredentials.ts +3 -0
  136. package/src/client/runOnSchemaChange.ts +5 -2
  137. package/src/client/sync/bucket/CrudBatch.ts +2 -0
  138. package/src/client/sync/bucket/CrudEntry.ts +10 -101
  139. package/src/client/sync/bucket/CrudTransaction.ts +3 -0
  140. package/src/client/sync/options.ts +77 -0
  141. package/src/client/sync/stream/JsonValue.ts +3 -0
  142. package/src/client/sync/sync-streams.ts +23 -10
  143. package/src/client/triggers/TriggerManager.ts +29 -59
  144. package/src/client/triggers/sanitizeSQL.ts +5 -0
  145. package/src/client/watched/GetAllQuery.ts +8 -4
  146. package/src/client/watched/WatchedQuery.ts +20 -11
  147. package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
  148. package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
  149. package/src/client/watched/processors/comparators.ts +8 -0
  150. package/src/db/DBAdapter.ts +160 -175
  151. package/src/db/QueryResult.ts +195 -0
  152. package/src/db/crud/SyncProgress.ts +8 -43
  153. package/src/db/crud/SyncStatus.ts +66 -216
  154. package/src/db/crud/UploadQueueStatus.ts +3 -0
  155. package/src/db/schema/Column.ts +22 -5
  156. package/src/db/schema/Index.ts +9 -3
  157. package/src/db/schema/IndexedColumn.ts +9 -3
  158. package/src/db/schema/RawTable.ts +7 -1
  159. package/src/db/schema/Schema.ts +12 -7
  160. package/src/db/schema/Table.ts +130 -180
  161. package/src/index.ts +6 -22
  162. package/src/types/types.ts +6 -0
  163. package/src/utils/BaseObserver.ts +12 -0
  164. package/src/utils/Logger.ts +86 -31
  165. package/src/utils/MetaBaseObserver.ts +14 -60
  166. package/src/utils/mutex.ts +4 -189
  167. package/dist/bundle.cjs +0 -14136
  168. package/dist/bundle.cjs.map +0 -1
  169. package/dist/bundle.mjs +0 -14056
  170. package/dist/bundle.mjs.map +0 -1
  171. package/dist/bundle.node.cjs +0 -11613
  172. package/dist/bundle.node.cjs.map +0 -1
  173. package/dist/bundle.node.mjs +0 -11533
  174. package/dist/bundle.node.mjs.map +0 -1
  175. package/dist/index.d.cts +0 -4052
  176. package/legacy/sync_protocol.d.ts +0 -103
  177. package/lib/client/AbstractPowerSyncDatabase.js +0 -987
  178. package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
  179. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
  180. package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
  181. package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
  182. package/lib/client/ConnectionManager.d.ts +0 -112
  183. package/lib/client/ConnectionManager.js +0 -294
  184. package/lib/client/ConnectionManager.js.map +0 -1
  185. package/lib/client/CustomQuery.d.ts +0 -22
  186. package/lib/client/CustomQuery.js +0 -43
  187. package/lib/client/CustomQuery.js.map +0 -1
  188. package/lib/client/constants.d.ts +0 -1
  189. package/lib/client/constants.js +0 -2
  190. package/lib/client/constants.js.map +0 -1
  191. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
  192. package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
  193. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
  194. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
  195. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
  196. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
  197. package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
  198. package/lib/client/sync/stream/AbstractRemote.js +0 -473
  199. package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
  200. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
  201. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
  202. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
  203. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
  204. package/lib/client/sync/stream/WebsocketClientTransport.js +0 -61
  205. package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
  206. package/lib/client/sync/stream/core-instruction.d.ts +0 -71
  207. package/lib/client/sync/stream/core-instruction.js +0 -27
  208. package/lib/client/sync/stream/core-instruction.js.map +0 -1
  209. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
  210. package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
  211. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
  212. package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
  213. package/lib/client/triggers/TriggerManagerImpl.js +0 -405
  214. package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
  215. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
  216. package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
  217. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
  218. package/lib/db/ConnectionClosedError.d.ts +0 -10
  219. package/lib/db/ConnectionClosedError.js +0 -21
  220. package/lib/db/ConnectionClosedError.js.map +0 -1
  221. package/lib/db/schema/TableV2.d.ts +0 -9
  222. package/lib/db/schema/TableV2.js +0 -9
  223. package/lib/db/schema/TableV2.js.map +0 -1
  224. package/lib/utils/AbortOperation.d.ts +0 -9
  225. package/lib/utils/AbortOperation.js +0 -19
  226. package/lib/utils/AbortOperation.js.map +0 -1
  227. package/lib/utils/ControlledExecutor.d.ts +0 -25
  228. package/lib/utils/ControlledExecutor.js +0 -51
  229. package/lib/utils/ControlledExecutor.js.map +0 -1
  230. package/lib/utils/async.d.ts +0 -14
  231. package/lib/utils/async.js +0 -46
  232. package/lib/utils/async.js.map +0 -1
  233. package/lib/utils/parseQuery.d.ts +0 -6
  234. package/lib/utils/parseQuery.js +0 -17
  235. package/lib/utils/parseQuery.js.map +0 -1
  236. package/lib/utils/queue.d.ts +0 -16
  237. package/lib/utils/queue.js +0 -42
  238. package/lib/utils/queue.js.map +0 -1
  239. package/lib/utils/stream_transform.d.ts +0 -39
  240. package/lib/utils/stream_transform.js +0 -206
  241. package/lib/utils/stream_transform.js.map +0 -1
  242. package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
  243. package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
  244. package/src/client/ConnectionManager.ts +0 -402
  245. package/src/client/CustomQuery.ts +0 -56
  246. package/src/client/constants.ts +0 -1
  247. package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
  248. package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
  249. package/src/client/sync/stream/AbstractRemote.ts +0 -602
  250. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
  251. package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
  252. package/src/client/sync/stream/core-instruction.ts +0 -98
  253. package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
  254. package/src/client/triggers/TriggerManagerImpl.ts +0 -496
  255. package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
  256. package/src/db/ConnectionClosedError.ts +0 -23
  257. package/src/db/schema/TableV2.ts +0 -9
  258. package/src/utils/AbortOperation.ts +0 -17
  259. package/src/utils/ControlledExecutor.ts +0 -72
  260. package/src/utils/async.ts +0 -50
  261. package/src/utils/parseQuery.ts +0 -25
  262. package/src/utils/queue.ts +0 -48
  263. package/src/utils/stream_transform.ts +0 -252
@@ -1,173 +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
- export const EMPTY_DIFFERENTIAL = {
7
- added: [],
8
- all: [],
9
- removed: [],
10
- updated: [],
11
- unchanged: []
12
- };
13
- /**
14
- * Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
15
- * It keys items by their `id` property if available, alternatively it uses JSON stringification
16
- * of the entire item for the key and comparison.
17
- */
18
- export const DEFAULT_ROW_COMPARATOR = {
19
- keyBy: (item) => {
20
- if (item && typeof item == 'object' && typeof item['id'] == 'string') {
21
- return item['id'];
22
- }
23
- return JSON.stringify(item);
24
- },
25
- compareBy: (item) => JSON.stringify(item)
26
- };
27
- /**
28
- * Uses the PowerSync onChange event to trigger watched queries.
29
- * Results are emitted on every change of the relevant tables.
30
- * @internal
31
- */
32
- export class DifferentialQueryProcessor extends AbstractQueryProcessor {
33
- options;
34
- comparator;
35
- constructor(options) {
36
- super(options);
37
- this.options = options;
38
- this.comparator = options.rowComparator ?? DEFAULT_ROW_COMPARATOR;
39
- }
40
- /*
41
- * @returns If the sets are equal
42
- */
43
- differentiate(current, previousMap) {
44
- const { keyBy, compareBy } = this.comparator;
45
- let hasChanged = false;
46
- const currentMap = new Map();
47
- const removedTracker = new Set(previousMap.keys());
48
- // Allow mutating to populate the data temporarily.
49
- const diff = {
50
- all: [],
51
- added: [],
52
- removed: [],
53
- updated: [],
54
- unchanged: []
55
- };
56
- /**
57
- * Looping over the current result set array is important to preserve
58
- * the ordering of the result set.
59
- * We can replace items in the current array with previous object references if they are equal.
60
- */
61
- for (const item of current) {
62
- const key = keyBy(item);
63
- const hash = compareBy(item);
64
- currentMap.set(key, { hash, item });
65
- const previousItem = previousMap.get(key);
66
- if (!previousItem) {
67
- // New item
68
- hasChanged = true;
69
- diff.added.push(item);
70
- diff.all.push(item);
71
- }
72
- else {
73
- // Existing item
74
- if (hash == previousItem.hash) {
75
- diff.unchanged.push(previousItem.item);
76
- // Use the previous object reference
77
- diff.all.push(previousItem.item);
78
- // update the map to preserve the reference
79
- currentMap.set(key, previousItem);
80
- }
81
- else {
82
- hasChanged = true;
83
- diff.updated.push({ current: item, previous: previousItem.item });
84
- // Use the new reference
85
- diff.all.push(item);
86
- }
87
- }
88
- // The item is present, we don't consider it removed
89
- removedTracker.delete(key);
90
- }
91
- diff.removed = Array.from(removedTracker).map((key) => previousMap.get(key).item);
92
- hasChanged = hasChanged || diff.removed.length > 0;
93
- return {
94
- diff,
95
- hasChanged,
96
- map: currentMap
97
- };
98
- }
99
- async linkQuery(options) {
100
- const { db, watchOptions } = this.options;
101
- const { abortSignal } = options;
102
- const compiledQuery = watchOptions.query.compile();
103
- const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
104
- tables: options.settings.triggerOnTables
105
- });
106
- let currentMap = new Map();
107
- // populate the currentMap from the placeholder data
108
- this.state.data.forEach((item) => {
109
- currentMap.set(this.comparator.keyBy(item), {
110
- hash: this.comparator.compareBy(item),
111
- item
112
- });
113
- });
114
- db.onChangeWithCallback({
115
- onChange: async () => {
116
- if (this.closed || abortSignal.aborted) {
117
- return;
118
- }
119
- // This fires for each change of the relevant tables
120
- try {
121
- if (this.reportFetching && !this.state.isFetching) {
122
- await this.updateState({ isFetching: true });
123
- }
124
- const partialStateUpdate = {};
125
- // Always run the query if an underlying table has changed
126
- const result = await watchOptions.query.execute({
127
- sql: compiledQuery.sql,
128
- // Allows casting from ReadOnlyArray[unknown] to Array<unknown>
129
- // This allows simpler compatibility with PowerSync queries
130
- parameters: [...compiledQuery.parameters],
131
- db: this.options.db
132
- });
133
- if (abortSignal.aborted) {
134
- return;
135
- }
136
- if (this.reportFetching) {
137
- partialStateUpdate.isFetching = false;
138
- }
139
- if (this.state.isLoading) {
140
- partialStateUpdate.isLoading = false;
141
- }
142
- const { diff, hasChanged, map } = this.differentiate(result, currentMap);
143
- // Update for future comparisons
144
- currentMap = map;
145
- if (hasChanged) {
146
- await this.iterateAsyncListenersWithError((l) => l.onDiff?.(diff));
147
- Object.assign(partialStateUpdate, {
148
- data: diff.all
149
- });
150
- }
151
- if (this.state.error) {
152
- partialStateUpdate.error = null;
153
- }
154
- if (Object.keys(partialStateUpdate).length > 0) {
155
- await this.updateState(partialStateUpdate);
156
- }
157
- }
158
- catch (error) {
159
- await this.updateState({ error });
160
- }
161
- },
162
- onError: async (error) => {
163
- await this.updateState({ error });
164
- }
165
- }, {
166
- signal: abortSignal,
167
- tables,
168
- throttleMs: watchOptions.throttleMs,
169
- triggerImmediate: true // used to emit the initial state
170
- });
171
- }
172
- }
1
+ export {};
173
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;AAoGrC;;;GAGG;AACH,MAAM,CAAC,MAA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AI,EAAE,IAAI,CAAC,GAAG;yBACf,CAAC,CAAC;oBACL,CAAC;oBAED,IAAI,IAAI,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,KAAK,EAAE,CAAC;oBACf,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,33 +1,15 @@
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}.
4
+ *
5
+ * @public
6
6
  */
7
7
  export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
8
8
  query: WatchCompatibleQuery<DataType>;
9
9
  }
10
10
  /**
11
11
  * {@link WatchedQuery} returned from {@link Query#watch}.
12
+ *
13
+ * @public
12
14
  */
13
15
  export type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
14
- /**
15
- * @internal
16
- */
17
- export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
18
- comparator?: WatchedQueryComparator<Data>;
19
- }
20
- /**
21
- * Uses the PowerSync onChange event to trigger watched queries.
22
- * Results are emitted on every change of the relevant tables.
23
- * @internal
24
- */
25
- export declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
26
- protected options: OnChangeQueryProcessorOptions<Data>;
27
- constructor(options: OnChangeQueryProcessorOptions<Data>);
28
- /**
29
- * @returns If the sets are equal
30
- */
31
- protected checkEquality(current: Data, previous: Data): boolean;
32
- protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
33
- }
@@ -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;AAuBrC;;;;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,OA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CAAC,cAAc,EAAE,CAAC;wBACxB,kBAAkB,CAAC,UAAU,GAAG,KAAK,CAAC;oBACxC,CAAC;oBAED,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;wBACzB,kBAAkB,CAAC,SAAS,GAAG,KAAK,CAAC;oBACvC,CAAC;oBAED,kCAAkC;oBAClC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;wBACjD,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;4BAChC,IAAI,EAAE,MAAM;yBACb,CAAC,CAAC;oBACL,CAAC;oBAED,IAAI,IAAI,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,KAAK,EAAE,CAAC;oBACf,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,12 +2,16 @@
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;
8
10
  }
9
11
  /**
10
12
  * Options for {@link ArrayComparator}
13
+ *
14
+ * @public
11
15
  */
12
16
  export type ArrayComparatorOptions<ItemType> = {
13
17
  /**
@@ -18,6 +22,8 @@ export type ArrayComparatorOptions<ItemType> = {
18
22
  /**
19
23
  * An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
20
24
  * result has changes without necessarily processing all items in the result.
25
+ *
26
+ * @public
21
27
  */
22
28
  export declare class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemType[]> {
23
29
  protected options: ArrayComparatorOptions<ItemType>;
@@ -26,5 +32,7 @@ export declare class ArrayComparator<ItemType> implements WatchedQueryComparator
26
32
  }
27
33
  /**
28
34
  * Watched query comparator that always reports changed result sets.
35
+ *
36
+ * @public
29
37
  */
30
38
  export declare const FalsyComparator: WatchedQueryComparator<unknown>;
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
3
3
  * result has changes without necessarily processing all items in the result.
4
+ *
5
+ * @public
4
6
  */
5
7
  export class ArrayComparator {
6
8
  options;
@@ -28,6 +30,8 @@ export class ArrayComparator {
28
30
  }
29
31
  /**
30
32
  * Watched query comparator that always reports changed result sets.
33
+ *
34
+ * @public
31
35
  */
32
36
  export const FalsyComparator = {
33
37
  checkEquality: () => false // Default comparator that always returns false
@@ -1 +1 @@
1
- {"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/comparators.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,OAAO,eAAe;IACJ;IAAtB,YAAsB,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;IAAG,CAAC;IAEnE,aAAa,CAAC,OAAmB,EAAE,QAAoB;QACrD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEnC,sCAAsC;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5C,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;gBACjC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoC;IAC9D,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,+CAA+C;CAC3E,CAAC"}
1
+ {"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/comparators.ts"],"names":[],"mappings":"AAuBA;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACJ;IAAtB,YAAsB,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;IAAG,CAAC;IAEnE,aAAa,CAAC,OAAmB,EAAE,QAAoB;QACrD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEnC,sCAAsC;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5C,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;gBACjC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoC;IAC9D,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,+CAA+C;CAC3E,CAAC"}
@@ -2,110 +2,104 @@
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.
8
+ * @public
9
9
  */
10
- /**
11
- * Object returned by SQL Query executions.
12
- */
13
- export type QueryResult = {
14
- /** Represents the auto-generated row id if applicable. */
15
- insertId?: number;
10
+ export interface DBGetUtils {
16
11
  /**
17
- * Number of affected rows reported by SQLite for a write query.
12
+ * Execute a read-only query and return results.
18
13
  *
19
- * When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
20
- * `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
21
- * 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
22
17
  */
23
- rowsAffected: number;
24
- /** if status is undefined or 0 this object will contain the query results */
25
- rows?: {
26
- /** Raw array with all dataset */
27
- _array: any[];
28
- /** The length of the dataset */
29
- length: number;
30
- /** A convenience function to acess the index based the row object
31
- * @param idx the row index
32
- * @returns the row structure identified by column names
33
- */
34
- item: (idx: number) => any;
35
- };
36
- };
37
- export interface DBGetUtils {
38
- /** Execute a read-only query and return results. */
39
18
  getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
40
- /** 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
+ */
41
26
  getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
42
- /** 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
+ */
43
35
  get<T>(sql: string, parameters?: any[]): Promise<T>;
44
36
  }
37
+ /**
38
+ * @public
39
+ */
45
40
  export interface SqlExecutor {
46
- /** Execute a single write statement. */
47
- execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
48
41
  /**
49
- * Execute a single write statement and return raw results.
50
- * Unlike `execute`, which returns an object with structured key-value pairs,
51
- * `executeRaw` returns a nested array of raw values, where each row is
52
- * represented as an array of column values without field names.
42
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
43
+ * and optionally return results.
53
44
  *
54
- * Example result:
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.
55
48
  *
56
- * ```[ [ '1', 'list 1', '33', 'Post content', '1' ] ]```
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.
57
57
  *
58
- * Where as `execute`'s `rows._array` would have been:
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.
61
+ */
62
+ executeRaw: (query: string, params?: any[] | undefined) => Promise<RawQueryResult>;
63
+ /**
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.
59
67
  *
60
- * ```[ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]```
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
61
71
  */
62
- executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
63
- executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
72
+ executeBatch: (query: string, params?: any[][]) => Promise<QueryResult<never>>;
64
73
  }
65
- export interface LockContext extends SqlExecutor, DBGetUtils {
74
+ /**
75
+ * @public
76
+ */
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>>;
66
84
  }
67
85
  /**
68
- * Implements {@link DBGetUtils} on a {@link SqlRunner}.
86
+ * @public
69
87
  */
70
- export declare function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omit<SqlExecutor, 'executeBatch'>>(Base: TBase): {
71
- new (...args: any[]): {
72
- getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
73
- getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
74
- get<T>(sql: string, parameters?: any[]): Promise<T>;
75
- executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
76
- execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
77
- executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
78
- };
79
- } & TBase;
80
88
  export interface Transaction extends LockContext {
81
89
  /** Commit multiple changes to the local DB using the Transaction context. */
82
- commit: () => Promise<QueryResult>;
90
+ commit: () => Promise<void>;
83
91
  /** Roll back multiple attempted changes using the Transaction context. */
84
- rollback: () => Promise<QueryResult>;
85
- }
86
- /**
87
- * Update table operation numbers from SQLite
88
- */
89
- export declare enum RowUpdateType {
90
- SQLITE_INSERT = 18,
91
- SQLITE_DELETE = 9,
92
- SQLITE_UPDATE = 23
93
- }
94
- export interface TableUpdateOperation {
95
- opType: RowUpdateType;
96
- rowId: number;
92
+ rollback: () => Promise<void>;
97
93
  }
98
94
  /**
99
- * Notification of an update to one or more tables, for the purpose of realtime change notifications.
95
+ * @public
100
96
  */
101
- export interface UpdateNotification extends TableUpdateOperation {
102
- table: string;
103
- }
104
97
  export interface BatchedUpdateNotification {
105
- rawUpdates: UpdateNotification[];
106
98
  tables: string[];
107
- groupedUpdates: Record<string, TableUpdateOperation[]>;
108
99
  }
100
+ /**
101
+ * @public
102
+ */
109
103
  export interface DBAdapterListener extends BaseListener {
110
104
  /**
111
105
  * Listener for table updates.
@@ -113,49 +107,32 @@ export interface DBAdapterListener extends BaseListener {
113
107
  * without the need for a major version bump
114
108
  * The DB adapter can also batch update notifications if supported.
115
109
  */
116
- tablesUpdated: (updateNotification: BatchedUpdateNotification | UpdateNotification) => void;
110
+ tablesUpdated: (updateNotification: BatchedUpdateNotification) => void;
117
111
  }
112
+ /**
113
+ * @public
114
+ */
118
115
  export interface DBLockOptions {
119
116
  timeoutMs?: number;
120
117
  }
121
- export interface ConnectionPool extends BaseObserverInterface<DBAdapterListener> {
122
- name: string;
123
- close: () => void | Promise<void>;
124
- readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
125
- writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
118
+ /**
119
+ * @public
120
+ */
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>;
126
126
  /**
127
127
  * This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
128
128
  */
129
- refreshSchema: () => Promise<void>;
130
- }
131
- export interface DBAdapter extends ConnectionPool, SqlExecutor, DBGetUtils {
132
- readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
133
- 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>>;
134
138
  }
135
- /**
136
- * A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
137
- * {@link ConnectionPool.writeLock}.
138
- */
139
- export declare function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase): {
140
- new (...args: any[]): {
141
- readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
142
- writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
143
- getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
144
- getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
145
- get<T>(sql: string, parameters?: any[]): Promise<T>;
146
- execute(query: string, params?: any[]): Promise<QueryResult>;
147
- executeRaw(query: string, params?: any[]): Promise<any[][]>;
148
- executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
149
- name: string;
150
- close: () => void | Promise<void>;
151
- readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
152
- writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
153
- /**
154
- * This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
155
- */
156
- refreshSchema: () => Promise<void>;
157
- registerListener(listener: Partial<DBAdapterListener>): () => void;
158
- };
159
- } & TBase;
160
- export declare function isBatchedUpdateNotification(update: BatchedUpdateNotification | UpdateNotification): update is BatchedUpdateNotification;
161
- export declare function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification): string[];