@tanstack/db 0.5.11 → 0.5.12

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 (221) hide show
  1. package/dist/cjs/SortedMap.cjs +40 -26
  2. package/dist/cjs/SortedMap.cjs.map +1 -1
  3. package/dist/cjs/SortedMap.d.cts +10 -15
  4. package/dist/cjs/collection/change-events.cjs.map +1 -1
  5. package/dist/cjs/collection/changes.cjs.map +1 -1
  6. package/dist/cjs/collection/events.cjs.map +1 -1
  7. package/dist/cjs/collection/events.d.cts +12 -4
  8. package/dist/cjs/collection/index.cjs +2 -1
  9. package/dist/cjs/collection/index.cjs.map +1 -1
  10. package/dist/cjs/collection/indexes.cjs.map +1 -1
  11. package/dist/cjs/collection/lifecycle.cjs.map +1 -1
  12. package/dist/cjs/collection/mutations.cjs +5 -2
  13. package/dist/cjs/collection/mutations.cjs.map +1 -1
  14. package/dist/cjs/collection/state.cjs +6 -5
  15. package/dist/cjs/collection/state.cjs.map +1 -1
  16. package/dist/cjs/collection/state.d.cts +4 -1
  17. package/dist/cjs/collection/subscription.cjs +60 -53
  18. package/dist/cjs/collection/subscription.cjs.map +1 -1
  19. package/dist/cjs/collection/subscription.d.cts +18 -4
  20. package/dist/cjs/collection/sync.cjs.map +1 -1
  21. package/dist/cjs/errors.cjs +9 -0
  22. package/dist/cjs/errors.cjs.map +1 -1
  23. package/dist/cjs/errors.d.cts +3 -0
  24. package/dist/cjs/event-emitter.cjs.map +1 -1
  25. package/dist/cjs/index.cjs +2 -0
  26. package/dist/cjs/index.cjs.map +1 -1
  27. package/dist/cjs/index.d.cts +1 -1
  28. package/dist/cjs/indexes/auto-index.cjs.map +1 -1
  29. package/dist/cjs/indexes/base-index.cjs.map +1 -1
  30. package/dist/cjs/indexes/btree-index.cjs +8 -6
  31. package/dist/cjs/indexes/btree-index.cjs.map +1 -1
  32. package/dist/cjs/indexes/lazy-index.cjs.map +1 -1
  33. package/dist/cjs/indexes/reverse-index.cjs.map +1 -1
  34. package/dist/cjs/local-only.cjs.map +1 -1
  35. package/dist/cjs/local-storage.cjs.map +1 -1
  36. package/dist/cjs/optimistic-action.cjs.map +1 -1
  37. package/dist/cjs/paced-mutations.cjs.map +1 -1
  38. package/dist/cjs/proxy.cjs.map +1 -1
  39. package/dist/cjs/query/builder/functions.cjs.map +1 -1
  40. package/dist/cjs/query/builder/index.cjs.map +1 -1
  41. package/dist/cjs/query/builder/ref-proxy.cjs.map +1 -1
  42. package/dist/cjs/query/compiler/evaluators.cjs.map +1 -1
  43. package/dist/cjs/query/compiler/expressions.cjs.map +1 -1
  44. package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
  45. package/dist/cjs/query/compiler/index.cjs.map +1 -1
  46. package/dist/cjs/query/compiler/joins.cjs.map +1 -1
  47. package/dist/cjs/query/compiler/order-by.cjs +91 -38
  48. package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
  49. package/dist/cjs/query/compiler/order-by.d.cts +6 -2
  50. package/dist/cjs/query/compiler/select.cjs.map +1 -1
  51. package/dist/cjs/query/expression-helpers.cjs.map +1 -1
  52. package/dist/cjs/query/index.d.cts +1 -1
  53. package/dist/cjs/query/ir.cjs.map +1 -1
  54. package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
  55. package/dist/cjs/query/live/collection-registry.cjs.map +1 -1
  56. package/dist/cjs/query/live/collection-subscriber.cjs +30 -15
  57. package/dist/cjs/query/live/collection-subscriber.cjs.map +1 -1
  58. package/dist/cjs/query/live/internal.cjs.map +1 -1
  59. package/dist/cjs/query/live-query-collection.cjs.map +1 -1
  60. package/dist/cjs/query/optimizer.cjs.map +1 -1
  61. package/dist/cjs/query/predicate-utils.cjs +19 -2
  62. package/dist/cjs/query/predicate-utils.cjs.map +1 -1
  63. package/dist/cjs/query/predicate-utils.d.cts +32 -1
  64. package/dist/cjs/query/subset-dedupe.cjs.map +1 -1
  65. package/dist/cjs/scheduler.cjs.map +1 -1
  66. package/dist/cjs/strategies/debounceStrategy.cjs.map +1 -1
  67. package/dist/cjs/strategies/queueStrategy.cjs.map +1 -1
  68. package/dist/cjs/strategies/throttleStrategy.cjs.map +1 -1
  69. package/dist/cjs/transactions.cjs.map +1 -1
  70. package/dist/cjs/types.d.cts +43 -5
  71. package/dist/cjs/utils/browser-polyfills.cjs.map +1 -1
  72. package/dist/cjs/utils/btree.cjs.map +1 -1
  73. package/dist/cjs/utils/comparison.cjs.map +1 -1
  74. package/dist/cjs/utils/cursor.cjs +39 -0
  75. package/dist/cjs/utils/cursor.cjs.map +1 -0
  76. package/dist/cjs/utils/cursor.d.cts +18 -0
  77. package/dist/cjs/utils/index-optimization.cjs.map +1 -1
  78. package/dist/cjs/utils.cjs.map +1 -1
  79. package/dist/esm/SortedMap.d.ts +10 -15
  80. package/dist/esm/SortedMap.js +40 -26
  81. package/dist/esm/SortedMap.js.map +1 -1
  82. package/dist/esm/collection/change-events.js.map +1 -1
  83. package/dist/esm/collection/changes.js.map +1 -1
  84. package/dist/esm/collection/events.d.ts +12 -4
  85. package/dist/esm/collection/events.js.map +1 -1
  86. package/dist/esm/collection/index.js +2 -1
  87. package/dist/esm/collection/index.js.map +1 -1
  88. package/dist/esm/collection/indexes.js.map +1 -1
  89. package/dist/esm/collection/lifecycle.js.map +1 -1
  90. package/dist/esm/collection/mutations.js +6 -3
  91. package/dist/esm/collection/mutations.js.map +1 -1
  92. package/dist/esm/collection/state.d.ts +4 -1
  93. package/dist/esm/collection/state.js +6 -5
  94. package/dist/esm/collection/state.js.map +1 -1
  95. package/dist/esm/collection/subscription.d.ts +18 -4
  96. package/dist/esm/collection/subscription.js +61 -54
  97. package/dist/esm/collection/subscription.js.map +1 -1
  98. package/dist/esm/collection/sync.js.map +1 -1
  99. package/dist/esm/errors.d.ts +3 -0
  100. package/dist/esm/errors.js +9 -0
  101. package/dist/esm/errors.js.map +1 -1
  102. package/dist/esm/event-emitter.js.map +1 -1
  103. package/dist/esm/index.d.ts +1 -1
  104. package/dist/esm/index.js +4 -2
  105. package/dist/esm/indexes/auto-index.js.map +1 -1
  106. package/dist/esm/indexes/base-index.js.map +1 -1
  107. package/dist/esm/indexes/btree-index.js +8 -6
  108. package/dist/esm/indexes/btree-index.js.map +1 -1
  109. package/dist/esm/indexes/lazy-index.js.map +1 -1
  110. package/dist/esm/indexes/reverse-index.js.map +1 -1
  111. package/dist/esm/local-only.js.map +1 -1
  112. package/dist/esm/local-storage.js.map +1 -1
  113. package/dist/esm/optimistic-action.js.map +1 -1
  114. package/dist/esm/paced-mutations.js.map +1 -1
  115. package/dist/esm/proxy.js.map +1 -1
  116. package/dist/esm/query/builder/functions.js.map +1 -1
  117. package/dist/esm/query/builder/index.js.map +1 -1
  118. package/dist/esm/query/builder/ref-proxy.js.map +1 -1
  119. package/dist/esm/query/compiler/evaluators.js.map +1 -1
  120. package/dist/esm/query/compiler/expressions.js.map +1 -1
  121. package/dist/esm/query/compiler/group-by.js.map +1 -1
  122. package/dist/esm/query/compiler/index.js.map +1 -1
  123. package/dist/esm/query/compiler/joins.js.map +1 -1
  124. package/dist/esm/query/compiler/order-by.d.ts +6 -2
  125. package/dist/esm/query/compiler/order-by.js +91 -38
  126. package/dist/esm/query/compiler/order-by.js.map +1 -1
  127. package/dist/esm/query/compiler/select.js.map +1 -1
  128. package/dist/esm/query/expression-helpers.js.map +1 -1
  129. package/dist/esm/query/index.d.ts +1 -1
  130. package/dist/esm/query/ir.js.map +1 -1
  131. package/dist/esm/query/live/collection-config-builder.js.map +1 -1
  132. package/dist/esm/query/live/collection-registry.js.map +1 -1
  133. package/dist/esm/query/live/collection-subscriber.js +30 -15
  134. package/dist/esm/query/live/collection-subscriber.js.map +1 -1
  135. package/dist/esm/query/live/internal.js.map +1 -1
  136. package/dist/esm/query/live-query-collection.js.map +1 -1
  137. package/dist/esm/query/optimizer.js.map +1 -1
  138. package/dist/esm/query/predicate-utils.d.ts +32 -1
  139. package/dist/esm/query/predicate-utils.js +19 -2
  140. package/dist/esm/query/predicate-utils.js.map +1 -1
  141. package/dist/esm/query/subset-dedupe.js.map +1 -1
  142. package/dist/esm/scheduler.js.map +1 -1
  143. package/dist/esm/strategies/debounceStrategy.js.map +1 -1
  144. package/dist/esm/strategies/queueStrategy.js.map +1 -1
  145. package/dist/esm/strategies/throttleStrategy.js.map +1 -1
  146. package/dist/esm/transactions.js.map +1 -1
  147. package/dist/esm/types.d.ts +43 -5
  148. package/dist/esm/utils/browser-polyfills.js.map +1 -1
  149. package/dist/esm/utils/btree.js.map +1 -1
  150. package/dist/esm/utils/comparison.js.map +1 -1
  151. package/dist/esm/utils/cursor.d.ts +18 -0
  152. package/dist/esm/utils/cursor.js +39 -0
  153. package/dist/esm/utils/cursor.js.map +1 -0
  154. package/dist/esm/utils/index-optimization.js.map +1 -1
  155. package/dist/esm/utils.js.map +1 -1
  156. package/package.json +30 -28
  157. package/src/SortedMap.ts +50 -31
  158. package/src/collection/change-events.ts +20 -20
  159. package/src/collection/changes.ts +12 -12
  160. package/src/collection/events.ts +20 -10
  161. package/src/collection/index.ts +47 -46
  162. package/src/collection/indexes.ts +14 -14
  163. package/src/collection/lifecycle.ts +16 -16
  164. package/src/collection/mutations.ts +25 -20
  165. package/src/collection/state.ts +43 -36
  166. package/src/collection/subscription.ts +114 -83
  167. package/src/collection/sync.ts +13 -13
  168. package/src/duplicate-instance-check.ts +1 -1
  169. package/src/errors.ts +49 -40
  170. package/src/event-emitter.ts +5 -5
  171. package/src/index.ts +21 -21
  172. package/src/indexes/auto-index.ts +11 -11
  173. package/src/indexes/base-index.ts +13 -13
  174. package/src/indexes/btree-index.ts +21 -17
  175. package/src/indexes/index-options.ts +3 -3
  176. package/src/indexes/lazy-index.ts +8 -8
  177. package/src/indexes/reverse-index.ts +5 -5
  178. package/src/local-only.ts +12 -12
  179. package/src/local-storage.ts +17 -17
  180. package/src/optimistic-action.ts +5 -5
  181. package/src/paced-mutations.ts +6 -6
  182. package/src/proxy.ts +43 -43
  183. package/src/query/builder/functions.ts +28 -28
  184. package/src/query/builder/index.ts +22 -22
  185. package/src/query/builder/ref-proxy.ts +4 -4
  186. package/src/query/builder/types.ts +8 -8
  187. package/src/query/compiler/evaluators.ts +9 -9
  188. package/src/query/compiler/expressions.ts +6 -6
  189. package/src/query/compiler/group-by.ts +24 -24
  190. package/src/query/compiler/index.ts +44 -44
  191. package/src/query/compiler/joins.ts +37 -37
  192. package/src/query/compiler/order-by.ts +170 -77
  193. package/src/query/compiler/select.ts +13 -13
  194. package/src/query/compiler/types.ts +2 -2
  195. package/src/query/expression-helpers.ts +16 -16
  196. package/src/query/index.ts +10 -9
  197. package/src/query/ir.ts +13 -13
  198. package/src/query/live/collection-config-builder.ts +53 -53
  199. package/src/query/live/collection-registry.ts +6 -6
  200. package/src/query/live/collection-subscriber.ts +87 -48
  201. package/src/query/live/internal.ts +1 -1
  202. package/src/query/live/types.ts +4 -4
  203. package/src/query/live-query-collection.ts +15 -15
  204. package/src/query/optimizer.ts +29 -29
  205. package/src/query/predicate-utils.ts +105 -50
  206. package/src/query/subset-dedupe.ts +6 -6
  207. package/src/scheduler.ts +3 -3
  208. package/src/strategies/debounceStrategy.ts +6 -6
  209. package/src/strategies/index.ts +4 -4
  210. package/src/strategies/queueStrategy.ts +5 -5
  211. package/src/strategies/throttleStrategy.ts +6 -6
  212. package/src/strategies/types.ts +2 -2
  213. package/src/transactions.ts +9 -9
  214. package/src/types.ts +51 -12
  215. package/src/utils/array-utils.ts +1 -1
  216. package/src/utils/browser-polyfills.ts +2 -2
  217. package/src/utils/btree.ts +22 -22
  218. package/src/utils/comparison.ts +3 -3
  219. package/src/utils/cursor.ts +78 -0
  220. package/src/utils/index-optimization.ts +14 -14
  221. package/src/utils.ts +4 -4
@@ -1,5 +1,5 @@
1
- import { distinct, filter, map } from "@tanstack/db-ivm"
2
- import { optimizeQuery } from "../optimizer.js"
1
+ import { distinct, filter, map } from '@tanstack/db-ivm'
2
+ import { optimizeQuery } from '../optimizer.js'
3
3
  import {
4
4
  CollectionInputNotFoundError,
5
5
  DistinctRequiresSelectError,
@@ -7,31 +7,31 @@ import {
7
7
  HavingRequiresGroupByError,
8
8
  LimitOffsetRequireOrderByError,
9
9
  UnsupportedFromTypeError,
10
- } from "../../errors.js"
11
- import { PropRef, Value as ValClass, getWhereExpression } from "../ir.js"
12
- import { compileExpression, toBooleanPredicate } from "./evaluators.js"
13
- import { processJoins } from "./joins.js"
14
- import { processGroupBy } from "./group-by.js"
15
- import { processOrderBy } from "./order-by.js"
16
- import { processSelect } from "./select.js"
17
- import type { CollectionSubscription } from "../../collection/subscription.js"
18
- import type { OrderByOptimizationInfo } from "./order-by.js"
10
+ } from '../../errors.js'
11
+ import { PropRef, Value as ValClass, getWhereExpression } from '../ir.js'
12
+ import { compileExpression, toBooleanPredicate } from './evaluators.js'
13
+ import { processJoins } from './joins.js'
14
+ import { processGroupBy } from './group-by.js'
15
+ import { processOrderBy } from './order-by.js'
16
+ import { processSelect } from './select.js'
17
+ import type { CollectionSubscription } from '../../collection/subscription.js'
18
+ import type { OrderByOptimizationInfo } from './order-by.js'
19
19
  import type {
20
20
  BasicExpression,
21
21
  CollectionRef,
22
22
  QueryIR,
23
23
  QueryRef,
24
- } from "../ir.js"
25
- import type { LazyCollectionCallbacks } from "./joins.js"
26
- import type { Collection } from "../../collection/index.js"
24
+ } from '../ir.js'
25
+ import type { LazyCollectionCallbacks } from './joins.js'
26
+ import type { Collection } from '../../collection/index.js'
27
27
  import type {
28
28
  KeyedStream,
29
29
  NamespacedAndKeyedStream,
30
30
  ResultStream,
31
- } from "../../types.js"
32
- import type { QueryCache, QueryMapping, WindowOptions } from "./types.js"
31
+ } from '../../types.js'
32
+ import type { QueryCache, QueryMapping, WindowOptions } from './types.js'
33
33
 
34
- export type { WindowOptions } from "./types.js"
34
+ export type { WindowOptions } from './types.js'
35
35
 
36
36
  /**
37
37
  * Result of query compilation including both the pipeline and source-specific WHERE clauses
@@ -92,7 +92,7 @@ export function compileQuery(
92
92
  optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>,
93
93
  setWindowFn: (windowFn: (options: WindowOptions) => void) => void,
94
94
  cache: QueryCache = new WeakMap(),
95
- queryMapping: QueryMapping = new WeakMap()
95
+ queryMapping: QueryMapping = new WeakMap(),
96
96
  ): CompilationResult {
97
97
  // Check if the original raw query has already been compiled
98
98
  const cachedResult = cache.get(rawQuery)
@@ -147,7 +147,7 @@ export function compileQuery(
147
147
  cache,
148
148
  queryMapping,
149
149
  aliasToCollectionId,
150
- aliasRemapping
150
+ aliasRemapping,
151
151
  )
152
152
  sources[mainSource] = mainInput
153
153
 
@@ -160,7 +160,7 @@ export function compileQuery(
160
160
  Record<string, typeof row>,
161
161
  ]
162
162
  return ret
163
- })
163
+ }),
164
164
  )
165
165
 
166
166
  // Process JOIN clauses if they exist
@@ -183,7 +183,7 @@ export function compileQuery(
183
183
  rawQuery,
184
184
  compileQuery,
185
185
  aliasToCollectionId,
186
- aliasRemapping
186
+ aliasRemapping,
187
187
  )
188
188
  }
189
189
 
@@ -196,7 +196,7 @@ export function compileQuery(
196
196
  pipeline = pipeline.pipe(
197
197
  filter(([_key, namespacedRow]) => {
198
198
  return toBooleanPredicate(compiledWhere(namespacedRow))
199
- })
199
+ }),
200
200
  )
201
201
  }
202
202
  }
@@ -207,7 +207,7 @@ export function compileQuery(
207
207
  pipeline = pipeline.pipe(
208
208
  filter(([_key, namespacedRow]) => {
209
209
  return toBooleanPredicate(fnWhere(namespacedRow))
210
- })
210
+ }),
211
211
  )
212
212
  }
213
213
  }
@@ -230,7 +230,7 @@ export function compileQuery(
230
230
  __select_results: selectResults,
231
231
  },
232
232
  ] as [string, typeof namespacedRow & { __select_results: any }]
233
- })
233
+ }),
234
234
  )
235
235
  } else if (query.select) {
236
236
  pipeline = processSelect(pipeline, query.select, allInputs)
@@ -250,7 +250,7 @@ export function compileQuery(
250
250
  __select_results: selectResults,
251
251
  },
252
252
  ] as [string, typeof namespacedRow & { __select_results: any }]
253
- })
253
+ }),
254
254
  )
255
255
  }
256
256
 
@@ -261,12 +261,12 @@ export function compileQuery(
261
261
  query.groupBy,
262
262
  query.having,
263
263
  query.select,
264
- query.fnHaving
264
+ query.fnHaving,
265
265
  )
266
266
  } else if (query.select) {
267
267
  // Check if SELECT contains aggregates but no GROUP BY (implicit single-group aggregation)
268
268
  const hasAggregates = Object.values(query.select).some(
269
- (expr) => expr.type === `agg`
269
+ (expr) => expr.type === `agg`,
270
270
  )
271
271
  if (hasAggregates) {
272
272
  // Handle implicit single-group aggregation
@@ -275,7 +275,7 @@ export function compileQuery(
275
275
  [], // Empty group by means single group
276
276
  query.having,
277
277
  query.select,
278
- query.fnHaving
278
+ query.fnHaving,
279
279
  )
280
280
  }
281
281
  }
@@ -303,7 +303,7 @@ export function compileQuery(
303
303
  pipeline = pipeline.pipe(
304
304
  filter(([_key, namespacedRow]) => {
305
305
  return fnHaving(namespacedRow)
306
- })
306
+ }),
307
307
  )
308
308
  }
309
309
  }
@@ -324,7 +324,7 @@ export function compileQuery(
324
324
  optimizableOrderByCollections,
325
325
  setWindowFn,
326
326
  query.limit,
327
- query.offset
327
+ query.offset,
328
328
  )
329
329
 
330
330
  // Final step: extract the __select_results and include orderBy index
@@ -334,7 +334,7 @@ export function compileQuery(
334
334
  const raw = (row as any).__select_results
335
335
  const finalResults = unwrapValue(raw)
336
336
  return [key, [finalResults, orderByIndex]] as [unknown, [any, string]]
337
- })
337
+ }),
338
338
  )
339
339
 
340
340
  const result = resultPipeline
@@ -364,7 +364,7 @@ export function compileQuery(
364
364
  unknown,
365
365
  [any, string | undefined],
366
366
  ]
367
- })
367
+ }),
368
368
  )
369
369
 
370
370
  const result = resultPipeline
@@ -413,7 +413,7 @@ function collectDirectCollectionAliases(query: QueryIR): Set<string> {
413
413
  */
414
414
  function validateQueryStructure(
415
415
  query: QueryIR,
416
- parentCollectionAliases: Set<string> = new Set()
416
+ parentCollectionAliases: Set<string> = new Set(),
417
417
  ): void {
418
418
  // Collect direct collection aliases from this query level
419
419
  const currentLevelAliases = collectDirectCollectionAliases(query)
@@ -423,7 +423,7 @@ function validateQueryStructure(
423
423
  if (parentCollectionAliases.has(alias)) {
424
424
  throw new DuplicateAliasInSubqueryError(
425
425
  alias,
426
- Array.from(parentCollectionAliases)
426
+ Array.from(parentCollectionAliases),
427
427
  )
428
428
  }
429
429
  }
@@ -465,7 +465,7 @@ function processFrom(
465
465
  cache: QueryCache,
466
466
  queryMapping: QueryMapping,
467
467
  aliasToCollectionId: Record<string, string>,
468
- aliasRemapping: Record<string, string>
468
+ aliasRemapping: Record<string, string>,
469
469
  ): { alias: string; input: KeyedStream; collectionId: string } {
470
470
  switch (from.type) {
471
471
  case `collectionRef`: {
@@ -474,7 +474,7 @@ function processFrom(
474
474
  throw new CollectionInputNotFoundError(
475
475
  from.alias,
476
476
  from.collection.id,
477
- Object.keys(allInputs)
477
+ Object.keys(allInputs),
478
478
  )
479
479
  }
480
480
  aliasToCollectionId[from.alias] = from.collection.id
@@ -495,7 +495,7 @@ function processFrom(
495
495
  optimizableOrderByCollections,
496
496
  setWindowFn,
497
497
  cache,
498
- queryMapping
498
+ queryMapping,
499
499
  )
500
500
 
501
501
  // Pull up alias mappings from subquery to parent scope.
@@ -519,7 +519,7 @@ function processFrom(
519
519
  const innerAlias = Object.keys(subQueryResult.aliasToCollectionId).find(
520
520
  (alias) =>
521
521
  subQueryResult.aliasToCollectionId[alias] ===
522
- subQueryResult.collectionId
522
+ subQueryResult.collectionId,
523
523
  )
524
524
  if (innerAlias && innerAlias !== from.alias) {
525
525
  aliasRemapping[from.alias] = innerAlias
@@ -536,7 +536,7 @@ function processFrom(
536
536
  // Unwrap Value expressions that might have leaked through as the entire row
537
537
  const unwrapped = unwrapValue(value)
538
538
  return [key, unwrapped] as [unknown, any]
539
- })
539
+ }),
540
540
  )
541
541
 
542
542
  return {
@@ -571,7 +571,7 @@ function unwrapValue(value: any): any {
571
571
  function mapNestedQueries(
572
572
  optimizedQuery: QueryIR,
573
573
  originalQuery: QueryIR,
574
- queryMapping: QueryMapping
574
+ queryMapping: QueryMapping,
575
575
  ): void {
576
576
  // Map the FROM clause if it's a QueryRef
577
577
  if (
@@ -583,7 +583,7 @@ function mapNestedQueries(
583
583
  mapNestedQueries(
584
584
  optimizedQuery.from.query,
585
585
  originalQuery.from.query,
586
- queryMapping
586
+ queryMapping,
587
587
  )
588
588
  }
589
589
 
@@ -606,7 +606,7 @@ function mapNestedQueries(
606
606
  mapNestedQueries(
607
607
  optimizedJoin.from.query,
608
608
  originalJoin.from.query,
609
- queryMapping
609
+ queryMapping,
610
610
  )
611
611
  }
612
612
  }
@@ -615,7 +615,7 @@ function mapNestedQueries(
615
615
 
616
616
  function getRefFromAlias(
617
617
  query: QueryIR,
618
- alias: string
618
+ alias: string,
619
619
  ): CollectionRef | QueryRef | void {
620
620
  if (query.from.alias === alias) {
621
621
  return query.from
@@ -636,7 +636,7 @@ function getRefFromAlias(
636
636
  export function followRef(
637
637
  query: QueryIR,
638
638
  ref: PropRef<any>,
639
- collection: Collection
639
+ collection: Collection,
640
640
  ): { collection: Collection; path: Array<string> } | void {
641
641
  if (ref.path.length === 0) {
642
642
  return
@@ -1,4 +1,4 @@
1
- import { filter, join as joinOperator, map, tap } from "@tanstack/db-ivm"
1
+ import { filter, join as joinOperator, map, tap } from '@tanstack/db-ivm'
2
2
  import {
3
3
  CollectionInputNotFoundError,
4
4
  InvalidJoinCondition,
@@ -10,29 +10,29 @@ import {
10
10
  SubscriptionNotFoundError,
11
11
  UnsupportedJoinSourceTypeError,
12
12
  UnsupportedJoinTypeError,
13
- } from "../../errors.js"
14
- import { ensureIndexForField } from "../../indexes/auto-index.js"
15
- import { PropRef, followRef } from "../ir.js"
16
- import { inArray } from "../builder/functions.js"
17
- import { compileExpression } from "./evaluators.js"
18
- import type { CompileQueryFn } from "./index.js"
19
- import type { OrderByOptimizationInfo } from "./order-by.js"
13
+ } from '../../errors.js'
14
+ import { ensureIndexForField } from '../../indexes/auto-index.js'
15
+ import { PropRef, followRef } from '../ir.js'
16
+ import { inArray } from '../builder/functions.js'
17
+ import { compileExpression } from './evaluators.js'
18
+ import type { CompileQueryFn } from './index.js'
19
+ import type { OrderByOptimizationInfo } from './order-by.js'
20
20
  import type {
21
21
  BasicExpression,
22
22
  CollectionRef,
23
23
  JoinClause,
24
24
  QueryIR,
25
25
  QueryRef,
26
- } from "../ir.js"
27
- import type { IStreamBuilder, JoinType } from "@tanstack/db-ivm"
28
- import type { Collection } from "../../collection/index.js"
26
+ } from '../ir.js'
27
+ import type { IStreamBuilder, JoinType } from '@tanstack/db-ivm'
28
+ import type { Collection } from '../../collection/index.js'
29
29
  import type {
30
30
  KeyedStream,
31
31
  NamespacedAndKeyedStream,
32
32
  NamespacedRow,
33
- } from "../../types.js"
34
- import type { QueryCache, QueryMapping, WindowOptions } from "./types.js"
35
- import type { CollectionSubscription } from "../../collection/subscription.js"
33
+ } from '../../types.js'
34
+ import type { QueryCache, QueryMapping, WindowOptions } from './types.js'
35
+ import type { CollectionSubscription } from '../../collection/subscription.js'
36
36
 
37
37
  /** Function type for loading specific keys into a lazy collection */
38
38
  export type LoadKeysFn = (key: Set<string | number>) => void
@@ -65,7 +65,7 @@ export function processJoins(
65
65
  rawQuery: QueryIR,
66
66
  onCompileSubquery: CompileQueryFn,
67
67
  aliasToCollectionId: Record<string, string>,
68
- aliasRemapping: Record<string, string>
68
+ aliasRemapping: Record<string, string>,
69
69
  ): NamespacedAndKeyedStream {
70
70
  let resultPipeline = pipeline
71
71
 
@@ -88,7 +88,7 @@ export function processJoins(
88
88
  rawQuery,
89
89
  onCompileSubquery,
90
90
  aliasToCollectionId,
91
- aliasRemapping
91
+ aliasRemapping,
92
92
  )
93
93
  }
94
94
 
@@ -117,7 +117,7 @@ function processJoin(
117
117
  rawQuery: QueryIR,
118
118
  onCompileSubquery: CompileQueryFn,
119
119
  aliasToCollectionId: Record<string, string>,
120
- aliasRemapping: Record<string, string>
120
+ aliasRemapping: Record<string, string>,
121
121
  ): NamespacedAndKeyedStream {
122
122
  const isCollectionRef = joinClause.from.type === `collectionRef`
123
123
 
@@ -139,7 +139,7 @@ function processJoin(
139
139
  queryMapping,
140
140
  onCompileSubquery,
141
141
  aliasToCollectionId,
142
- aliasRemapping
142
+ aliasRemapping,
143
143
  )
144
144
 
145
145
  // Add the joined source to the sources map
@@ -164,7 +164,7 @@ function processJoin(
164
164
  const { activeSource, lazySource } = getActiveAndLazySources(
165
165
  joinClause.type,
166
166
  mainCollection,
167
- joinedCollection
167
+ joinedCollection,
168
168
  )
169
169
 
170
170
  // Analyze which source each expression refers to and swap if necessary
@@ -173,7 +173,7 @@ function processJoin(
173
173
  joinClause.left,
174
174
  joinClause.right,
175
175
  availableSources,
176
- joinedSource
176
+ joinedSource,
177
177
  )
178
178
 
179
179
  // Pre-compile the join expressions
@@ -191,7 +191,7 @@ function processJoin(
191
191
  unknown,
192
192
  [string, typeof namespacedRow],
193
193
  ]
194
- })
194
+ }),
195
195
  )
196
196
 
197
197
  // Prepare the joined pipeline
@@ -208,7 +208,7 @@ function processJoin(
208
208
  unknown,
209
209
  [string, typeof namespacedRow],
210
210
  ]
211
- })
211
+ }),
212
212
  )
213
213
 
214
214
  // Apply the join operation
@@ -255,7 +255,7 @@ function processJoin(
255
255
  const followRefResult = followRef(
256
256
  rawQuery,
257
257
  lazySourceJoinExpr,
258
- lazySource
258
+ lazySource,
259
259
  )!
260
260
  const followRefCollection = followRefResult.collection
261
261
 
@@ -264,7 +264,7 @@ function processJoin(
264
264
  ensureIndexForField(
265
265
  fieldName,
266
266
  followRefResult.path,
267
- followRefCollection
267
+ followRefCollection,
268
268
  )
269
269
  }
270
270
 
@@ -288,7 +288,7 @@ function processJoin(
288
288
  resolvedAlias,
289
289
  lazyAlias,
290
290
  lazySource.id,
291
- Object.keys(subscriptions)
291
+ Object.keys(subscriptions),
292
292
  )
293
293
  }
294
294
 
@@ -309,7 +309,7 @@ function processJoin(
309
309
  // Snapshot wasn't sent because it could not be loaded from the indexes
310
310
  lazySourceSubscription.requestSnapshot()
311
311
  }
312
- })
312
+ }),
313
313
  )
314
314
 
315
315
  if (activeSource === `main`) {
@@ -322,7 +322,7 @@ function processJoin(
322
322
 
323
323
  return mainPipeline.pipe(
324
324
  joinOperator(joinedPipeline, joinClause.type as JoinType),
325
- processJoinResults(joinClause.type)
325
+ processJoinResults(joinClause.type),
326
326
  )
327
327
  }
328
328
 
@@ -334,11 +334,11 @@ function analyzeJoinExpressions(
334
334
  left: BasicExpression,
335
335
  right: BasicExpression,
336
336
  allAvailableSourceAliases: Array<string>,
337
- joinedSource: string
337
+ joinedSource: string,
338
338
  ): { mainExpr: BasicExpression; joinedExpr: BasicExpression } {
339
339
  // Filter out the joined source alias from the available source aliases
340
340
  const availableSources = allAvailableSourceAliases.filter(
341
- (alias) => alias !== joinedSource
341
+ (alias) => alias !== joinedSource,
342
342
  )
343
343
 
344
344
  const leftSourceAlias = getSourceAliasFromExpression(left)
@@ -430,7 +430,7 @@ function processJoinSource(
430
430
  queryMapping: QueryMapping,
431
431
  onCompileSubquery: CompileQueryFn,
432
432
  aliasToCollectionId: Record<string, string>,
433
- aliasRemapping: Record<string, string>
433
+ aliasRemapping: Record<string, string>,
434
434
  ): { alias: string; input: KeyedStream; collectionId: string } {
435
435
  switch (from.type) {
436
436
  case `collectionRef`: {
@@ -439,7 +439,7 @@ function processJoinSource(
439
439
  throw new CollectionInputNotFoundError(
440
440
  from.alias,
441
441
  from.collection.id,
442
- Object.keys(allInputs)
442
+ Object.keys(allInputs),
443
443
  )
444
444
  }
445
445
  aliasToCollectionId[from.alias] = from.collection.id
@@ -460,7 +460,7 @@ function processJoinSource(
460
460
  optimizableOrderByCollections,
461
461
  setWindowFn,
462
462
  cache,
463
- queryMapping
463
+ queryMapping,
464
464
  )
465
465
 
466
466
  // Pull up alias mappings from subquery to parent scope.
@@ -483,7 +483,7 @@ function processJoinSource(
483
483
  const innerAlias = Object.keys(subQueryResult.aliasToCollectionId).find(
484
484
  (alias) =>
485
485
  subQueryResult.aliasToCollectionId[alias] ===
486
- subQueryResult.collectionId
486
+ subQueryResult.collectionId,
487
487
  )
488
488
  if (innerAlias && innerAlias !== from.alias) {
489
489
  aliasRemapping[from.alias] = innerAlias
@@ -498,7 +498,7 @@ function processJoinSource(
498
498
  map((data: any) => {
499
499
  const [key, [value, _orderByIndex]] = data
500
500
  return [key, value] as [unknown, any]
501
- })
501
+ }),
502
502
  )
503
503
 
504
504
  return {
@@ -525,7 +525,7 @@ function processJoinResults(joinType: string) {
525
525
  [string, NamespacedRow] | undefined,
526
526
  ],
527
527
  ]
528
- >
528
+ >,
529
529
  ): NamespacedAndKeyedStream {
530
530
  return pipeline.pipe(
531
531
  // Process the join result and handle nulls
@@ -574,7 +574,7 @@ function processJoinResults(joinType: string) {
574
574
  const resultKey = `[${mainKey},${joinedKey}]`
575
575
 
576
576
  return [resultKey, mergedNamespacedRow] as [string, NamespacedRow]
577
- })
577
+ }),
578
578
  )
579
579
  }
580
580
  }
@@ -592,7 +592,7 @@ function processJoinResults(joinType: string) {
592
592
  function getActiveAndLazySources(
593
593
  joinType: JoinClause[`type`],
594
594
  leftCollection: Collection,
595
- rightCollection: Collection
595
+ rightCollection: Collection,
596
596
  ):
597
597
  | { activeSource: `main` | `joined`; lazySource: Collection }
598
598
  | { activeSource: undefined; lazySource: undefined } {