@tanstack/db 0.5.10 → 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 (224) 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 +1 -1
  5. package/dist/cjs/collection/change-events.cjs.map +1 -1
  6. package/dist/cjs/collection/changes.cjs.map +1 -1
  7. package/dist/cjs/collection/events.cjs.map +1 -1
  8. package/dist/cjs/collection/events.d.cts +12 -4
  9. package/dist/cjs/collection/index.cjs +2 -1
  10. package/dist/cjs/collection/index.cjs.map +1 -1
  11. package/dist/cjs/collection/indexes.cjs.map +1 -1
  12. package/dist/cjs/collection/lifecycle.cjs.map +1 -1
  13. package/dist/cjs/collection/mutations.cjs +5 -2
  14. package/dist/cjs/collection/mutations.cjs.map +1 -1
  15. package/dist/cjs/collection/state.cjs +6 -5
  16. package/dist/cjs/collection/state.cjs.map +1 -1
  17. package/dist/cjs/collection/state.d.cts +4 -1
  18. package/dist/cjs/collection/subscription.cjs +60 -53
  19. package/dist/cjs/collection/subscription.cjs.map +1 -1
  20. package/dist/cjs/collection/subscription.d.cts +18 -4
  21. package/dist/cjs/collection/sync.cjs.map +1 -1
  22. package/dist/cjs/errors.cjs +9 -0
  23. package/dist/cjs/errors.cjs.map +1 -1
  24. package/dist/cjs/errors.d.cts +3 -0
  25. package/dist/cjs/event-emitter.cjs.map +1 -1
  26. package/dist/cjs/index.cjs +4 -0
  27. package/dist/cjs/index.cjs.map +1 -1
  28. package/dist/cjs/index.d.cts +2 -1
  29. package/dist/cjs/indexes/auto-index.cjs.map +1 -1
  30. package/dist/cjs/indexes/base-index.cjs.map +1 -1
  31. package/dist/cjs/indexes/btree-index.cjs +8 -6
  32. package/dist/cjs/indexes/btree-index.cjs.map +1 -1
  33. package/dist/cjs/indexes/lazy-index.cjs.map +1 -1
  34. package/dist/cjs/indexes/reverse-index.cjs.map +1 -1
  35. package/dist/cjs/local-only.cjs.map +1 -1
  36. package/dist/cjs/local-storage.cjs.map +1 -1
  37. package/dist/cjs/optimistic-action.cjs.map +1 -1
  38. package/dist/cjs/paced-mutations.cjs.map +1 -1
  39. package/dist/cjs/proxy.cjs.map +1 -1
  40. package/dist/cjs/query/builder/functions.cjs.map +1 -1
  41. package/dist/cjs/query/builder/index.cjs.map +1 -1
  42. package/dist/cjs/query/builder/ref-proxy.cjs.map +1 -1
  43. package/dist/cjs/query/compiler/evaluators.cjs.map +1 -1
  44. package/dist/cjs/query/compiler/expressions.cjs.map +1 -1
  45. package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
  46. package/dist/cjs/query/compiler/index.cjs.map +1 -1
  47. package/dist/cjs/query/compiler/joins.cjs.map +1 -1
  48. package/dist/cjs/query/compiler/order-by.cjs +91 -38
  49. package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
  50. package/dist/cjs/query/compiler/order-by.d.cts +6 -2
  51. package/dist/cjs/query/compiler/select.cjs.map +1 -1
  52. package/dist/cjs/query/expression-helpers.cjs.map +1 -1
  53. package/dist/cjs/query/index.d.cts +1 -1
  54. package/dist/cjs/query/ir.cjs.map +1 -1
  55. package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
  56. package/dist/cjs/query/live/collection-registry.cjs.map +1 -1
  57. package/dist/cjs/query/live/collection-subscriber.cjs +30 -15
  58. package/dist/cjs/query/live/collection-subscriber.cjs.map +1 -1
  59. package/dist/cjs/query/live/internal.cjs.map +1 -1
  60. package/dist/cjs/query/live-query-collection.cjs.map +1 -1
  61. package/dist/cjs/query/optimizer.cjs.map +1 -1
  62. package/dist/cjs/query/predicate-utils.cjs +19 -2
  63. package/dist/cjs/query/predicate-utils.cjs.map +1 -1
  64. package/dist/cjs/query/predicate-utils.d.cts +32 -1
  65. package/dist/cjs/query/subset-dedupe.cjs.map +1 -1
  66. package/dist/cjs/scheduler.cjs.map +1 -1
  67. package/dist/cjs/strategies/debounceStrategy.cjs.map +1 -1
  68. package/dist/cjs/strategies/queueStrategy.cjs.map +1 -1
  69. package/dist/cjs/strategies/throttleStrategy.cjs.map +1 -1
  70. package/dist/cjs/transactions.cjs.map +1 -1
  71. package/dist/cjs/types.d.cts +43 -5
  72. package/dist/cjs/utils/browser-polyfills.cjs.map +1 -1
  73. package/dist/cjs/utils/btree.cjs.map +1 -1
  74. package/dist/cjs/utils/comparison.cjs.map +1 -1
  75. package/dist/cjs/utils/cursor.cjs +39 -0
  76. package/dist/cjs/utils/cursor.cjs.map +1 -0
  77. package/dist/cjs/utils/cursor.d.cts +18 -0
  78. package/dist/cjs/utils/index-optimization.cjs.map +1 -1
  79. package/dist/cjs/utils.cjs.map +1 -1
  80. package/dist/esm/SortedMap.d.ts +10 -15
  81. package/dist/esm/SortedMap.js +40 -26
  82. package/dist/esm/SortedMap.js.map +1 -1
  83. package/dist/esm/collection/change-events.js +1 -1
  84. package/dist/esm/collection/change-events.js.map +1 -1
  85. package/dist/esm/collection/changes.js.map +1 -1
  86. package/dist/esm/collection/events.d.ts +12 -4
  87. package/dist/esm/collection/events.js.map +1 -1
  88. package/dist/esm/collection/index.js +2 -1
  89. package/dist/esm/collection/index.js.map +1 -1
  90. package/dist/esm/collection/indexes.js.map +1 -1
  91. package/dist/esm/collection/lifecycle.js.map +1 -1
  92. package/dist/esm/collection/mutations.js +6 -3
  93. package/dist/esm/collection/mutations.js.map +1 -1
  94. package/dist/esm/collection/state.d.ts +4 -1
  95. package/dist/esm/collection/state.js +6 -5
  96. package/dist/esm/collection/state.js.map +1 -1
  97. package/dist/esm/collection/subscription.d.ts +18 -4
  98. package/dist/esm/collection/subscription.js +61 -54
  99. package/dist/esm/collection/subscription.js.map +1 -1
  100. package/dist/esm/collection/sync.js.map +1 -1
  101. package/dist/esm/errors.d.ts +3 -0
  102. package/dist/esm/errors.js +9 -0
  103. package/dist/esm/errors.js.map +1 -1
  104. package/dist/esm/event-emitter.js.map +1 -1
  105. package/dist/esm/index.d.ts +2 -1
  106. package/dist/esm/index.js +6 -2
  107. package/dist/esm/index.js.map +1 -1
  108. package/dist/esm/indexes/auto-index.js.map +1 -1
  109. package/dist/esm/indexes/base-index.js.map +1 -1
  110. package/dist/esm/indexes/btree-index.js +8 -6
  111. package/dist/esm/indexes/btree-index.js.map +1 -1
  112. package/dist/esm/indexes/lazy-index.js.map +1 -1
  113. package/dist/esm/indexes/reverse-index.js.map +1 -1
  114. package/dist/esm/local-only.js.map +1 -1
  115. package/dist/esm/local-storage.js.map +1 -1
  116. package/dist/esm/optimistic-action.js.map +1 -1
  117. package/dist/esm/paced-mutations.js.map +1 -1
  118. package/dist/esm/proxy.js.map +1 -1
  119. package/dist/esm/query/builder/functions.js.map +1 -1
  120. package/dist/esm/query/builder/index.js.map +1 -1
  121. package/dist/esm/query/builder/ref-proxy.js.map +1 -1
  122. package/dist/esm/query/compiler/evaluators.js.map +1 -1
  123. package/dist/esm/query/compiler/expressions.js.map +1 -1
  124. package/dist/esm/query/compiler/group-by.js.map +1 -1
  125. package/dist/esm/query/compiler/index.js.map +1 -1
  126. package/dist/esm/query/compiler/joins.js.map +1 -1
  127. package/dist/esm/query/compiler/order-by.d.ts +6 -2
  128. package/dist/esm/query/compiler/order-by.js +91 -38
  129. package/dist/esm/query/compiler/order-by.js.map +1 -1
  130. package/dist/esm/query/compiler/select.js.map +1 -1
  131. package/dist/esm/query/expression-helpers.js.map +1 -1
  132. package/dist/esm/query/index.d.ts +1 -1
  133. package/dist/esm/query/ir.js.map +1 -1
  134. package/dist/esm/query/live/collection-config-builder.js.map +1 -1
  135. package/dist/esm/query/live/collection-registry.js.map +1 -1
  136. package/dist/esm/query/live/collection-subscriber.js +30 -15
  137. package/dist/esm/query/live/collection-subscriber.js.map +1 -1
  138. package/dist/esm/query/live/internal.js.map +1 -1
  139. package/dist/esm/query/live-query-collection.js.map +1 -1
  140. package/dist/esm/query/optimizer.js.map +1 -1
  141. package/dist/esm/query/predicate-utils.d.ts +32 -1
  142. package/dist/esm/query/predicate-utils.js +19 -2
  143. package/dist/esm/query/predicate-utils.js.map +1 -1
  144. package/dist/esm/query/subset-dedupe.js.map +1 -1
  145. package/dist/esm/scheduler.js.map +1 -1
  146. package/dist/esm/strategies/debounceStrategy.js.map +1 -1
  147. package/dist/esm/strategies/queueStrategy.js.map +1 -1
  148. package/dist/esm/strategies/throttleStrategy.js.map +1 -1
  149. package/dist/esm/transactions.js.map +1 -1
  150. package/dist/esm/types.d.ts +43 -5
  151. package/dist/esm/utils/browser-polyfills.js.map +1 -1
  152. package/dist/esm/utils/btree.js.map +1 -1
  153. package/dist/esm/utils/comparison.js.map +1 -1
  154. package/dist/esm/utils/cursor.d.ts +18 -0
  155. package/dist/esm/utils/cursor.js +39 -0
  156. package/dist/esm/utils/cursor.js.map +1 -0
  157. package/dist/esm/utils/index-optimization.js.map +1 -1
  158. package/dist/esm/utils.js.map +1 -1
  159. package/package.json +30 -28
  160. package/src/SortedMap.ts +50 -31
  161. package/src/collection/change-events.ts +23 -21
  162. package/src/collection/changes.ts +12 -12
  163. package/src/collection/events.ts +20 -10
  164. package/src/collection/index.ts +47 -46
  165. package/src/collection/indexes.ts +14 -14
  166. package/src/collection/lifecycle.ts +16 -16
  167. package/src/collection/mutations.ts +25 -20
  168. package/src/collection/state.ts +43 -36
  169. package/src/collection/subscription.ts +114 -83
  170. package/src/collection/sync.ts +13 -13
  171. package/src/duplicate-instance-check.ts +1 -1
  172. package/src/errors.ts +49 -40
  173. package/src/event-emitter.ts +5 -5
  174. package/src/index.ts +21 -20
  175. package/src/indexes/auto-index.ts +11 -11
  176. package/src/indexes/base-index.ts +13 -13
  177. package/src/indexes/btree-index.ts +21 -17
  178. package/src/indexes/index-options.ts +3 -3
  179. package/src/indexes/lazy-index.ts +8 -8
  180. package/src/indexes/reverse-index.ts +5 -5
  181. package/src/local-only.ts +12 -12
  182. package/src/local-storage.ts +17 -17
  183. package/src/optimistic-action.ts +5 -5
  184. package/src/paced-mutations.ts +6 -6
  185. package/src/proxy.ts +43 -43
  186. package/src/query/builder/functions.ts +28 -28
  187. package/src/query/builder/index.ts +22 -22
  188. package/src/query/builder/ref-proxy.ts +4 -4
  189. package/src/query/builder/types.ts +8 -8
  190. package/src/query/compiler/evaluators.ts +9 -9
  191. package/src/query/compiler/expressions.ts +6 -6
  192. package/src/query/compiler/group-by.ts +24 -24
  193. package/src/query/compiler/index.ts +44 -44
  194. package/src/query/compiler/joins.ts +37 -37
  195. package/src/query/compiler/order-by.ts +170 -77
  196. package/src/query/compiler/select.ts +13 -13
  197. package/src/query/compiler/types.ts +2 -2
  198. package/src/query/expression-helpers.ts +16 -16
  199. package/src/query/index.ts +10 -9
  200. package/src/query/ir.ts +13 -13
  201. package/src/query/live/collection-config-builder.ts +53 -53
  202. package/src/query/live/collection-registry.ts +6 -6
  203. package/src/query/live/collection-subscriber.ts +87 -48
  204. package/src/query/live/internal.ts +1 -1
  205. package/src/query/live/types.ts +4 -4
  206. package/src/query/live-query-collection.ts +15 -15
  207. package/src/query/optimizer.ts +29 -29
  208. package/src/query/predicate-utils.ts +105 -50
  209. package/src/query/subset-dedupe.ts +6 -6
  210. package/src/scheduler.ts +3 -3
  211. package/src/strategies/debounceStrategy.ts +6 -6
  212. package/src/strategies/index.ts +4 -4
  213. package/src/strategies/queueStrategy.ts +5 -5
  214. package/src/strategies/throttleStrategy.ts +6 -6
  215. package/src/strategies/types.ts +2 -2
  216. package/src/transactions.ts +9 -9
  217. package/src/types.ts +51 -12
  218. package/src/utils/array-utils.ts +1 -1
  219. package/src/utils/browser-polyfills.ts +2 -2
  220. package/src/utils/btree.ts +22 -22
  221. package/src/utils/comparison.ts +3 -3
  222. package/src/utils/cursor.ts +78 -0
  223. package/src/utils/index-optimization.ts +14 -14
  224. package/src/utils.ts +4 -4
package/src/query/ir.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  This is the intermediate representation of the query.
3
3
  */
4
4
 
5
- import type { CompareOptions } from "./builder/types"
6
- import type { Collection, CollectionImpl } from "../collection/index.js"
7
- import type { NamespacedRow } from "../types"
5
+ import type { CompareOptions } from './builder/types'
6
+ import type { Collection, CollectionImpl } from '../collection/index.js'
7
+ import type { NamespacedRow } from '../types'
8
8
 
9
9
  export interface QueryIR {
10
10
  from: From
@@ -73,7 +73,7 @@ export class CollectionRef extends BaseExpression {
73
73
  public type = `collectionRef` as const
74
74
  constructor(
75
75
  public collection: CollectionImpl,
76
- public alias: string
76
+ public alias: string,
77
77
  ) {
78
78
  super()
79
79
  }
@@ -83,7 +83,7 @@ export class QueryRef extends BaseExpression {
83
83
  public type = `queryRef` as const
84
84
  constructor(
85
85
  public query: QueryIR,
86
- public alias: string
86
+ public alias: string,
87
87
  ) {
88
88
  super()
89
89
  }
@@ -92,7 +92,7 @@ export class QueryRef extends BaseExpression {
92
92
  export class PropRef<T = any> extends BaseExpression<T> {
93
93
  public type = `ref` as const
94
94
  constructor(
95
- public path: Array<string> // path to the property in the collection, with the alias as the first element
95
+ public path: Array<string>, // path to the property in the collection, with the alias as the first element
96
96
  ) {
97
97
  super()
98
98
  }
@@ -101,7 +101,7 @@ export class PropRef<T = any> extends BaseExpression<T> {
101
101
  export class Value<T = any> extends BaseExpression<T> {
102
102
  public type = `val` as const
103
103
  constructor(
104
- public value: T // any js value
104
+ public value: T, // any js value
105
105
  ) {
106
106
  super()
107
107
  }
@@ -111,7 +111,7 @@ export class Func<T = any> extends BaseExpression<T> {
111
111
  public type = `func` as const
112
112
  constructor(
113
113
  public name: string, // such as eq, gt, lt, upper, lower, etc.
114
- public args: Array<BasicExpression>
114
+ public args: Array<BasicExpression>,
115
115
  ) {
116
116
  super()
117
117
  }
@@ -126,7 +126,7 @@ export class Aggregate<T = any> extends BaseExpression<T> {
126
126
  public type = `agg` as const
127
127
  constructor(
128
128
  public name: string, // such as count, avg, sum, min, max, etc.
129
- public args: Array<BasicExpression>
129
+ public args: Array<BasicExpression>,
130
130
  ) {
131
131
  super()
132
132
  }
@@ -163,7 +163,7 @@ export function getWhereExpression(where: Where): BasicExpression<boolean> {
163
163
  * HAVING clauses can contain aggregates, unlike regular WHERE clauses
164
164
  */
165
165
  export function getHavingExpression(
166
- having: Having
166
+ having: Having,
167
167
  ): BasicExpression | Aggregate {
168
168
  return typeof having === `object` && `expression` in having
169
169
  ? having.expression
@@ -185,14 +185,14 @@ export function isResidualWhere(where: Where): boolean {
185
185
  * Create a residual Where clause from an expression
186
186
  */
187
187
  export function createResidualWhere(
188
- expression: BasicExpression<boolean>
188
+ expression: BasicExpression<boolean>,
189
189
  ): Where {
190
190
  return { expression, residual: true }
191
191
  }
192
192
 
193
193
  function getRefFromAlias(
194
194
  query: QueryIR,
195
- alias: string
195
+ alias: string,
196
196
  ): CollectionRef | QueryRef | void {
197
197
  if (query.from.alias === alias) {
198
198
  return query.from
@@ -213,7 +213,7 @@ function getRefFromAlias(
213
213
  export function followRef(
214
214
  query: QueryIR,
215
215
  ref: PropRef<any>,
216
- collection: Collection
216
+ collection: Collection,
217
217
  ): { collection: Collection; path: Array<string> } | void {
218
218
  if (ref.path.length === 0) {
219
219
  return
@@ -1,22 +1,22 @@
1
- import { D2, output } from "@tanstack/db-ivm"
2
- import { compileQuery } from "../compiler/index.js"
3
- import { buildQuery, getQueryIR } from "../builder/index.js"
1
+ import { D2, output } from '@tanstack/db-ivm'
2
+ import { compileQuery } from '../compiler/index.js'
3
+ import { buildQuery, getQueryIR } from '../builder/index.js'
4
4
  import {
5
5
  MissingAliasInputsError,
6
6
  SetWindowRequiresOrderByError,
7
- } from "../../errors.js"
8
- import { transactionScopedScheduler } from "../../scheduler.js"
9
- import { getActiveTransaction } from "../../transactions.js"
10
- import { CollectionSubscriber } from "./collection-subscriber.js"
11
- import { getCollectionBuilder } from "./collection-registry.js"
12
- import { LIVE_QUERY_INTERNAL } from "./internal.js"
13
- import type { LiveQueryInternalUtils } from "./internal.js"
14
- import type { WindowOptions } from "../compiler/index.js"
15
- import type { SchedulerContextId } from "../../scheduler.js"
16
- import type { CollectionSubscription } from "../../collection/subscription.js"
17
- import type { RootStreamBuilder } from "@tanstack/db-ivm"
18
- import type { OrderByOptimizationInfo } from "../compiler/order-by.js"
19
- import type { Collection } from "../../collection/index.js"
7
+ } from '../../errors.js'
8
+ import { transactionScopedScheduler } from '../../scheduler.js'
9
+ import { getActiveTransaction } from '../../transactions.js'
10
+ import { CollectionSubscriber } from './collection-subscriber.js'
11
+ import { getCollectionBuilder } from './collection-registry.js'
12
+ import { LIVE_QUERY_INTERNAL } from './internal.js'
13
+ import type { LiveQueryInternalUtils } from './internal.js'
14
+ import type { WindowOptions } from '../compiler/index.js'
15
+ import type { SchedulerContextId } from '../../scheduler.js'
16
+ import type { CollectionSubscription } from '../../collection/subscription.js'
17
+ import type { RootStreamBuilder } from '@tanstack/db-ivm'
18
+ import type { OrderByOptimizationInfo } from '../compiler/order-by.js'
19
+ import type { Collection } from '../../collection/index.js'
20
20
  import type {
21
21
  CollectionConfigSingleRowOption,
22
22
  KeyedStream,
@@ -24,17 +24,17 @@ import type {
24
24
  StringCollationConfig,
25
25
  SyncConfig,
26
26
  UtilsRecord,
27
- } from "../../types.js"
28
- import type { Context, GetResult } from "../builder/types.js"
29
- import type { BasicExpression, QueryIR } from "../ir.js"
30
- import type { LazyCollectionCallbacks } from "../compiler/joins.js"
27
+ } from '../../types.js'
28
+ import type { Context, GetResult } from '../builder/types.js'
29
+ import type { BasicExpression, QueryIR } from '../ir.js'
30
+ import type { LazyCollectionCallbacks } from '../compiler/joins.js'
31
31
  import type {
32
32
  Changes,
33
33
  FullSyncState,
34
34
  LiveQueryCollectionConfig,
35
35
  SyncState,
36
- } from "./types.js"
37
- import type { AllCollectionEvents } from "../../collection/events.js"
36
+ } from './types.js'
37
+ import type { AllCollectionEvents } from '../../collection/events.js'
38
38
 
39
39
  export type LiveQueryCollectionUtils = UtilsRecord & {
40
40
  getRunCount: () => number
@@ -146,7 +146,7 @@ export class CollectionConfigBuilder<
146
146
  optimizableOrderByCollections: Record<string, OrderByOptimizationInfo> = {}
147
147
 
148
148
  constructor(
149
- private readonly config: LiveQueryCollectionConfig<TContext, TResult>
149
+ private readonly config: LiveQueryCollectionConfig<TContext, TResult>,
150
150
  ) {
151
151
  // Generate a unique ID if not provided
152
152
  this.id = config.id || `live-query-${++liveQueryCollectionCounter}`
@@ -252,7 +252,7 @@ export class CollectionConfigBuilder<
252
252
  unsubscribe()
253
253
  resolve()
254
254
  }
255
- }
255
+ },
256
256
  )
257
257
  })
258
258
  }
@@ -318,7 +318,7 @@ export class CollectionConfigBuilder<
318
318
  // Should only be called when sync is active
319
319
  if (!this.currentSyncConfig || !this.currentSyncState) {
320
320
  throw new Error(
321
- `maybeRunGraph called without active sync session. This should not happen.`
321
+ `maybeRunGraph called without active sync session. This should not happen.`,
322
322
  )
323
323
  }
324
324
 
@@ -380,7 +380,7 @@ export class CollectionConfigBuilder<
380
380
  jobId?: unknown
381
381
  alias?: string
382
382
  dependencies?: Array<CollectionConfigBuilder<any, any>>
383
- }
383
+ },
384
384
  ) {
385
385
  const contextId = options?.contextId ?? getActiveTransaction()?.id
386
386
  // Use the builder instance as the job ID for deduplication. This is memory-safe
@@ -422,7 +422,7 @@ export class CollectionConfigBuilder<
422
422
 
423
423
  if (!this.currentSyncConfig || !this.currentSyncState) {
424
424
  throw new Error(
425
- `scheduleGraphRun called without active sync session. This should not happen.`
425
+ `scheduleGraphRun called without active sync session. This should not happen.`,
426
426
  )
427
427
  }
428
428
 
@@ -479,7 +479,7 @@ export class CollectionConfigBuilder<
479
479
  */
480
480
  private executeGraphRun(
481
481
  contextId?: SchedulerContextId,
482
- pendingParam?: PendingGraphRun
482
+ pendingParam?: PendingGraphRun,
483
483
  ): void {
484
484
  // Get pending state: either from parameter (no context) or from map (with context)
485
485
  // Remove from map BEFORE checking sync state to prevent leaking entries when sync ends
@@ -554,7 +554,7 @@ export class CollectionConfigBuilder<
554
554
  // Extend the pipeline such that it applies the incoming changes to the collection
555
555
  const fullSyncState = this.extendPipelineWithChangeProcessing(
556
556
  config,
557
- syncState
557
+ syncState,
558
558
  )
559
559
  this.currentSyncState = fullSyncState
560
560
 
@@ -563,12 +563,12 @@ export class CollectionConfigBuilder<
563
563
  this.unsubscribeFromSchedulerClears = transactionScopedScheduler.onClear(
564
564
  (contextId) => {
565
565
  this.clearPendingGraphRun(contextId)
566
- }
566
+ },
567
567
  )
568
568
 
569
569
  const loadSubsetDataCallbacks = this.subscribeToAllCollections(
570
570
  config,
571
- fullSyncState
571
+ fullSyncState,
572
572
  )
573
573
 
574
574
  this.maybeRunGraphFn = () => this.scheduleGraphRun(loadSubsetDataCallbacks)
@@ -603,7 +603,7 @@ export class CollectionConfigBuilder<
603
603
  // Clear subscription references to prevent memory leaks
604
604
  // Note: Individual subscriptions are already unsubscribed via unsubscribeCallbacks
605
605
  Object.keys(this.subscriptions).forEach(
606
- (key) => delete this.subscriptions[key]
606
+ (key) => delete this.subscriptions[key],
607
607
  )
608
608
  this.compiledAliasToCollectionId = {}
609
609
 
@@ -623,7 +623,7 @@ export class CollectionConfigBuilder<
623
623
  Object.keys(this.collectionByAlias).map((alias) => [
624
624
  alias,
625
625
  this.graphCache!.newInput<any>(),
626
- ])
626
+ ]),
627
627
  )
628
628
 
629
629
  const compilation = compileQuery(
@@ -636,7 +636,7 @@ export class CollectionConfigBuilder<
636
636
  this.optimizableOrderByCollections,
637
637
  (windowFn: (options: WindowOptions) => void) => {
638
638
  this.windowFn = windowFn
639
- }
639
+ },
640
640
  )
641
641
 
642
642
  this.pipelineCache = compilation.pipeline
@@ -647,7 +647,7 @@ export class CollectionConfigBuilder<
647
647
  // This should never happen since all aliases come from user declarations,
648
648
  // but catch it early if the assumption is violated in the future.
649
649
  const missingAliases = Object.keys(this.compiledAliasToCollectionId).filter(
650
- (alias) => !Object.hasOwn(this.inputsCache!, alias)
650
+ (alias) => !Object.hasOwn(this.inputsCache!, alias),
651
651
  )
652
652
  if (missingAliases.length > 0) {
653
653
  throw new MissingAliasInputsError(missingAliases)
@@ -667,7 +667,7 @@ export class CollectionConfigBuilder<
667
667
 
668
668
  private extendPipelineWithChangeProcessing(
669
669
  config: SyncMethods<TResult>,
670
- syncState: SyncState
670
+ syncState: SyncState,
671
671
  ): FullSyncState {
672
672
  const { begin, commit } = config
673
673
  const { graph, inputs, pipeline } = this.maybeCompileBasePipeline()
@@ -681,11 +681,11 @@ export class CollectionConfigBuilder<
681
681
  messages
682
682
  .reduce(
683
683
  accumulateChanges<TResult>,
684
- new Map<unknown, Changes<TResult>>()
684
+ new Map<unknown, Changes<TResult>>(),
685
685
  )
686
686
  .forEach(this.applyChanges.bind(this, config))
687
687
  commit()
688
- })
688
+ }),
689
689
  )
690
690
 
691
691
  graph.finalize()
@@ -706,7 +706,7 @@ export class CollectionConfigBuilder<
706
706
  value: TResult
707
707
  orderByIndex: string | undefined
708
708
  },
709
- key: unknown
709
+ key: unknown,
710
710
  ) {
711
711
  const { write, collection } = config
712
712
  const { deletes, inserts, value, orderByIndex } = changes
@@ -745,7 +745,7 @@ export class CollectionConfigBuilder<
745
745
  })
746
746
  } else {
747
747
  throw new Error(
748
- `Could not apply changes: ${JSON.stringify(changes)}. This should never happen.`
748
+ `Could not apply changes: ${JSON.stringify(changes)}. This should never happen.`,
749
749
  )
750
750
  }
751
751
  }
@@ -756,14 +756,14 @@ export class CollectionConfigBuilder<
756
756
  private handleSourceStatusChange(
757
757
  config: SyncMethods<TResult>,
758
758
  collectionId: string,
759
- event: AllCollectionEvents[`status:change`]
759
+ event: AllCollectionEvents[`status:change`],
760
760
  ) {
761
761
  const { status } = event
762
762
 
763
763
  // Handle error state - any source collection in error puts live query in error
764
764
  if (status === `error`) {
765
765
  this.transitionToError(
766
- `Source collection '${collectionId}' entered error state`
766
+ `Source collection '${collectionId}' entered error state`,
767
767
  )
768
768
  return
769
769
  }
@@ -773,7 +773,7 @@ export class CollectionConfigBuilder<
773
773
  if (status === `cleaned-up`) {
774
774
  this.transitionToError(
775
775
  `Source collection '${collectionId}' was manually cleaned up while live query '${this.id}' depends on it. ` +
776
- `Live queries prevent automatic GC, so this was likely a manual cleanup() call.`
776
+ `Live queries prevent automatic GC, so this was likely a manual cleanup() call.`,
777
777
  )
778
778
  return
779
779
  }
@@ -814,7 +814,7 @@ export class CollectionConfigBuilder<
814
814
 
815
815
  private allCollectionsReady() {
816
816
  return Object.values(this.collections).every((collection) =>
817
- collection.isReady()
817
+ collection.isReady(),
818
818
  )
819
819
  }
820
820
 
@@ -825,14 +825,14 @@ export class CollectionConfigBuilder<
825
825
  */
826
826
  private subscribeToAllCollections(
827
827
  config: SyncMethods<TResult>,
828
- syncState: FullSyncState
828
+ syncState: FullSyncState,
829
829
  ) {
830
830
  // Use compiled aliases as the source of truth - these include all aliases from the query
831
831
  // including those from subqueries, which may not be in collectionByAlias
832
832
  const compiledAliases = Object.entries(this.compiledAliasToCollectionId)
833
833
  if (compiledAliases.length === 0) {
834
834
  throw new Error(
835
- `Compiler returned no alias metadata for query '${this.id}'. This should not happen; please report.`
835
+ `Compiler returned no alias metadata for query '${this.id}'. This should not happen; please report.`,
836
836
  )
837
837
  }
838
838
 
@@ -857,7 +857,7 @@ export class CollectionConfigBuilder<
857
857
  alias,
858
858
  collectionId,
859
859
  collection,
860
- this
860
+ this,
861
861
  )
862
862
 
863
863
  // Subscribe to status changes for status flow
@@ -874,7 +874,7 @@ export class CollectionConfigBuilder<
874
874
  // Create a callback for loading more data if needed (used by OrderBy optimization)
875
875
  const loadMore = collectionSubscriber.loadMoreIfNeeded.bind(
876
876
  collectionSubscriber,
877
- subscription
877
+ subscription,
878
878
  )
879
879
 
880
880
  return loadMore
@@ -900,7 +900,7 @@ export class CollectionConfigBuilder<
900
900
  }
901
901
 
902
902
  function buildQueryFromConfig<TContext extends Context>(
903
- config: LiveQueryCollectionConfig<any, any>
903
+ config: LiveQueryCollectionConfig<any, any>,
904
904
  ) {
905
905
  // Build the query using the provided query builder function or instance
906
906
  if (typeof config.query === `function`) {
@@ -910,7 +910,7 @@ function buildQueryFromConfig<TContext extends Context>(
910
910
  }
911
911
 
912
912
  function createOrderByComparator<T extends object>(
913
- orderByIndices: WeakMap<object, string>
913
+ orderByIndices: WeakMap<object, string>,
914
914
  ) {
915
915
  return (val1: T, val2: T): number => {
916
916
  // Use the orderBy index stored in the WeakMap
@@ -939,7 +939,7 @@ function createOrderByComparator<T extends object>(
939
939
  * Maps collections by their ID (not alias) as expected by the compiler
940
940
  */
941
941
  function extractCollectionsFromQuery(
942
- query: any
942
+ query: any,
943
943
  ): Record<string, Collection<any, any, any>> {
944
944
  const collections: Record<string, any> = {}
945
945
 
@@ -991,7 +991,7 @@ function extractCollectionFromSource(query: any): Collection<any, any, any> {
991
991
  }
992
992
 
993
993
  throw new Error(
994
- `Failed to extract collection. Invalid FROM clause: ${JSON.stringify(query)}`
994
+ `Failed to extract collection. Invalid FROM clause: ${JSON.stringify(query)}`,
995
995
  )
996
996
  }
997
997
 
@@ -1059,7 +1059,7 @@ function accumulateChanges<T>(
1059
1059
  [[key, tupleData], multiplicity]: [
1060
1060
  [unknown, [any, string | undefined]],
1061
1061
  number,
1062
- ]
1062
+ ],
1063
1063
  ) {
1064
1064
  // All queries now consistently return [value, orderByIndex] format
1065
1065
  // where orderByIndex is undefined for queries without ORDER BY
@@ -1,6 +1,6 @@
1
- import { LIVE_QUERY_INTERNAL } from "./internal.js"
2
- import type { Collection } from "../../collection/index.js"
3
- import type { CollectionConfigBuilder } from "./collection-config-builder.js"
1
+ import { LIVE_QUERY_INTERNAL } from './internal.js'
2
+ import type { Collection } from '../../collection/index.js'
3
+ import type { CollectionConfigBuilder } from './collection-config-builder.js'
4
4
 
5
5
  const collectionBuilderRegistry = new WeakMap<
6
6
  Collection<any, any, any>,
@@ -14,7 +14,7 @@ const collectionBuilderRegistry = new WeakMap<
14
14
  * @returns The attached builder, or `undefined` if none exists
15
15
  */
16
16
  export function getBuilderFromConfig(
17
- config: object
17
+ config: object,
18
18
  ): CollectionConfigBuilder<any, any> | undefined {
19
19
  return (config as any).utils?.[LIVE_QUERY_INTERNAL]?.getBuilder?.()
20
20
  }
@@ -29,7 +29,7 @@ export function getBuilderFromConfig(
29
29
  */
30
30
  export function registerCollectionBuilder(
31
31
  collection: Collection<any, any, any>,
32
- builder: CollectionConfigBuilder<any, any>
32
+ builder: CollectionConfigBuilder<any, any>,
33
33
  ): void {
34
34
  collectionBuilderRegistry.set(collection, builder)
35
35
  }
@@ -42,7 +42,7 @@ export function registerCollectionBuilder(
42
42
  * @returns The registered builder, or `undefined` if none exists
43
43
  */
44
44
  export function getCollectionBuilder(
45
- collection: Collection<any, any, any>
45
+ collection: Collection<any, any, any>,
46
46
  ): CollectionConfigBuilder<any, any> | undefined {
47
47
  return collectionBuilderRegistry.get(collection)
48
48
  }