@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.
- package/dist/cjs/SortedMap.cjs +40 -26
- package/dist/cjs/SortedMap.cjs.map +1 -1
- package/dist/cjs/SortedMap.d.cts +10 -15
- package/dist/cjs/collection/change-events.cjs +1 -1
- package/dist/cjs/collection/change-events.cjs.map +1 -1
- package/dist/cjs/collection/changes.cjs.map +1 -1
- package/dist/cjs/collection/events.cjs.map +1 -1
- package/dist/cjs/collection/events.d.cts +12 -4
- package/dist/cjs/collection/index.cjs +2 -1
- package/dist/cjs/collection/index.cjs.map +1 -1
- package/dist/cjs/collection/indexes.cjs.map +1 -1
- package/dist/cjs/collection/lifecycle.cjs.map +1 -1
- package/dist/cjs/collection/mutations.cjs +5 -2
- package/dist/cjs/collection/mutations.cjs.map +1 -1
- package/dist/cjs/collection/state.cjs +6 -5
- package/dist/cjs/collection/state.cjs.map +1 -1
- package/dist/cjs/collection/state.d.cts +4 -1
- package/dist/cjs/collection/subscription.cjs +60 -53
- package/dist/cjs/collection/subscription.cjs.map +1 -1
- package/dist/cjs/collection/subscription.d.cts +18 -4
- package/dist/cjs/collection/sync.cjs.map +1 -1
- package/dist/cjs/errors.cjs +9 -0
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/errors.d.cts +3 -0
- package/dist/cjs/event-emitter.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/cjs/indexes/auto-index.cjs.map +1 -1
- package/dist/cjs/indexes/base-index.cjs.map +1 -1
- package/dist/cjs/indexes/btree-index.cjs +8 -6
- package/dist/cjs/indexes/btree-index.cjs.map +1 -1
- package/dist/cjs/indexes/lazy-index.cjs.map +1 -1
- package/dist/cjs/indexes/reverse-index.cjs.map +1 -1
- package/dist/cjs/local-only.cjs.map +1 -1
- package/dist/cjs/local-storage.cjs.map +1 -1
- package/dist/cjs/optimistic-action.cjs.map +1 -1
- package/dist/cjs/paced-mutations.cjs.map +1 -1
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/query/builder/functions.cjs.map +1 -1
- package/dist/cjs/query/builder/index.cjs.map +1 -1
- package/dist/cjs/query/builder/ref-proxy.cjs.map +1 -1
- package/dist/cjs/query/compiler/evaluators.cjs.map +1 -1
- package/dist/cjs/query/compiler/expressions.cjs.map +1 -1
- package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/index.cjs.map +1 -1
- package/dist/cjs/query/compiler/joins.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.cjs +91 -38
- package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.d.cts +6 -2
- package/dist/cjs/query/compiler/select.cjs.map +1 -1
- package/dist/cjs/query/expression-helpers.cjs.map +1 -1
- package/dist/cjs/query/index.d.cts +1 -1
- package/dist/cjs/query/ir.cjs.map +1 -1
- package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
- package/dist/cjs/query/live/collection-registry.cjs.map +1 -1
- package/dist/cjs/query/live/collection-subscriber.cjs +30 -15
- package/dist/cjs/query/live/collection-subscriber.cjs.map +1 -1
- package/dist/cjs/query/live/internal.cjs.map +1 -1
- package/dist/cjs/query/live-query-collection.cjs.map +1 -1
- package/dist/cjs/query/optimizer.cjs.map +1 -1
- package/dist/cjs/query/predicate-utils.cjs +19 -2
- package/dist/cjs/query/predicate-utils.cjs.map +1 -1
- package/dist/cjs/query/predicate-utils.d.cts +32 -1
- package/dist/cjs/query/subset-dedupe.cjs.map +1 -1
- package/dist/cjs/scheduler.cjs.map +1 -1
- package/dist/cjs/strategies/debounceStrategy.cjs.map +1 -1
- package/dist/cjs/strategies/queueStrategy.cjs.map +1 -1
- package/dist/cjs/strategies/throttleStrategy.cjs.map +1 -1
- package/dist/cjs/transactions.cjs.map +1 -1
- package/dist/cjs/types.d.cts +43 -5
- package/dist/cjs/utils/browser-polyfills.cjs.map +1 -1
- package/dist/cjs/utils/btree.cjs.map +1 -1
- package/dist/cjs/utils/comparison.cjs.map +1 -1
- package/dist/cjs/utils/cursor.cjs +39 -0
- package/dist/cjs/utils/cursor.cjs.map +1 -0
- package/dist/cjs/utils/cursor.d.cts +18 -0
- package/dist/cjs/utils/index-optimization.cjs.map +1 -1
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/SortedMap.d.ts +10 -15
- package/dist/esm/SortedMap.js +40 -26
- package/dist/esm/SortedMap.js.map +1 -1
- package/dist/esm/collection/change-events.js +1 -1
- package/dist/esm/collection/change-events.js.map +1 -1
- package/dist/esm/collection/changes.js.map +1 -1
- package/dist/esm/collection/events.d.ts +12 -4
- package/dist/esm/collection/events.js.map +1 -1
- package/dist/esm/collection/index.js +2 -1
- package/dist/esm/collection/index.js.map +1 -1
- package/dist/esm/collection/indexes.js.map +1 -1
- package/dist/esm/collection/lifecycle.js.map +1 -1
- package/dist/esm/collection/mutations.js +6 -3
- package/dist/esm/collection/mutations.js.map +1 -1
- package/dist/esm/collection/state.d.ts +4 -1
- package/dist/esm/collection/state.js +6 -5
- package/dist/esm/collection/state.js.map +1 -1
- package/dist/esm/collection/subscription.d.ts +18 -4
- package/dist/esm/collection/subscription.js +61 -54
- package/dist/esm/collection/subscription.js.map +1 -1
- package/dist/esm/collection/sync.js.map +1 -1
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.js +9 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/event-emitter.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/indexes/auto-index.js.map +1 -1
- package/dist/esm/indexes/base-index.js.map +1 -1
- package/dist/esm/indexes/btree-index.js +8 -6
- package/dist/esm/indexes/btree-index.js.map +1 -1
- package/dist/esm/indexes/lazy-index.js.map +1 -1
- package/dist/esm/indexes/reverse-index.js.map +1 -1
- package/dist/esm/local-only.js.map +1 -1
- package/dist/esm/local-storage.js.map +1 -1
- package/dist/esm/optimistic-action.js.map +1 -1
- package/dist/esm/paced-mutations.js.map +1 -1
- package/dist/esm/proxy.js.map +1 -1
- package/dist/esm/query/builder/functions.js.map +1 -1
- package/dist/esm/query/builder/index.js.map +1 -1
- package/dist/esm/query/builder/ref-proxy.js.map +1 -1
- package/dist/esm/query/compiler/evaluators.js.map +1 -1
- package/dist/esm/query/compiler/expressions.js.map +1 -1
- package/dist/esm/query/compiler/group-by.js.map +1 -1
- package/dist/esm/query/compiler/index.js.map +1 -1
- package/dist/esm/query/compiler/joins.js.map +1 -1
- package/dist/esm/query/compiler/order-by.d.ts +6 -2
- package/dist/esm/query/compiler/order-by.js +91 -38
- package/dist/esm/query/compiler/order-by.js.map +1 -1
- package/dist/esm/query/compiler/select.js.map +1 -1
- package/dist/esm/query/expression-helpers.js.map +1 -1
- package/dist/esm/query/index.d.ts +1 -1
- package/dist/esm/query/ir.js.map +1 -1
- package/dist/esm/query/live/collection-config-builder.js.map +1 -1
- package/dist/esm/query/live/collection-registry.js.map +1 -1
- package/dist/esm/query/live/collection-subscriber.js +30 -15
- package/dist/esm/query/live/collection-subscriber.js.map +1 -1
- package/dist/esm/query/live/internal.js.map +1 -1
- package/dist/esm/query/live-query-collection.js.map +1 -1
- package/dist/esm/query/optimizer.js.map +1 -1
- package/dist/esm/query/predicate-utils.d.ts +32 -1
- package/dist/esm/query/predicate-utils.js +19 -2
- package/dist/esm/query/predicate-utils.js.map +1 -1
- package/dist/esm/query/subset-dedupe.js.map +1 -1
- package/dist/esm/scheduler.js.map +1 -1
- package/dist/esm/strategies/debounceStrategy.js.map +1 -1
- package/dist/esm/strategies/queueStrategy.js.map +1 -1
- package/dist/esm/strategies/throttleStrategy.js.map +1 -1
- package/dist/esm/transactions.js.map +1 -1
- package/dist/esm/types.d.ts +43 -5
- package/dist/esm/utils/browser-polyfills.js.map +1 -1
- package/dist/esm/utils/btree.js.map +1 -1
- package/dist/esm/utils/comparison.js.map +1 -1
- package/dist/esm/utils/cursor.d.ts +18 -0
- package/dist/esm/utils/cursor.js +39 -0
- package/dist/esm/utils/cursor.js.map +1 -0
- package/dist/esm/utils/index-optimization.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +30 -28
- package/src/SortedMap.ts +50 -31
- package/src/collection/change-events.ts +23 -21
- package/src/collection/changes.ts +12 -12
- package/src/collection/events.ts +20 -10
- package/src/collection/index.ts +47 -46
- package/src/collection/indexes.ts +14 -14
- package/src/collection/lifecycle.ts +16 -16
- package/src/collection/mutations.ts +25 -20
- package/src/collection/state.ts +43 -36
- package/src/collection/subscription.ts +114 -83
- package/src/collection/sync.ts +13 -13
- package/src/duplicate-instance-check.ts +1 -1
- package/src/errors.ts +49 -40
- package/src/event-emitter.ts +5 -5
- package/src/index.ts +21 -20
- package/src/indexes/auto-index.ts +11 -11
- package/src/indexes/base-index.ts +13 -13
- package/src/indexes/btree-index.ts +21 -17
- package/src/indexes/index-options.ts +3 -3
- package/src/indexes/lazy-index.ts +8 -8
- package/src/indexes/reverse-index.ts +5 -5
- package/src/local-only.ts +12 -12
- package/src/local-storage.ts +17 -17
- package/src/optimistic-action.ts +5 -5
- package/src/paced-mutations.ts +6 -6
- package/src/proxy.ts +43 -43
- package/src/query/builder/functions.ts +28 -28
- package/src/query/builder/index.ts +22 -22
- package/src/query/builder/ref-proxy.ts +4 -4
- package/src/query/builder/types.ts +8 -8
- package/src/query/compiler/evaluators.ts +9 -9
- package/src/query/compiler/expressions.ts +6 -6
- package/src/query/compiler/group-by.ts +24 -24
- package/src/query/compiler/index.ts +44 -44
- package/src/query/compiler/joins.ts +37 -37
- package/src/query/compiler/order-by.ts +170 -77
- package/src/query/compiler/select.ts +13 -13
- package/src/query/compiler/types.ts +2 -2
- package/src/query/expression-helpers.ts +16 -16
- package/src/query/index.ts +10 -9
- package/src/query/ir.ts +13 -13
- package/src/query/live/collection-config-builder.ts +53 -53
- package/src/query/live/collection-registry.ts +6 -6
- package/src/query/live/collection-subscriber.ts +87 -48
- package/src/query/live/internal.ts +1 -1
- package/src/query/live/types.ts +4 -4
- package/src/query/live-query-collection.ts +15 -15
- package/src/query/optimizer.ts +29 -29
- package/src/query/predicate-utils.ts +105 -50
- package/src/query/subset-dedupe.ts +6 -6
- package/src/scheduler.ts +3 -3
- package/src/strategies/debounceStrategy.ts +6 -6
- package/src/strategies/index.ts +4 -4
- package/src/strategies/queueStrategy.ts +5 -5
- package/src/strategies/throttleStrategy.ts +6 -6
- package/src/strategies/types.ts +2 -2
- package/src/transactions.ts +9 -9
- package/src/types.ts +51 -12
- package/src/utils/array-utils.ts +1 -1
- package/src/utils/browser-polyfills.ts +2 -2
- package/src/utils/btree.ts +22 -22
- package/src/utils/comparison.ts +3 -3
- package/src/utils/cursor.ts +78 -0
- package/src/utils/index-optimization.ts +14 -14
- 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
|
|
6
|
-
import type { Collection, CollectionImpl } from
|
|
7
|
-
import type { NamespacedRow } from
|
|
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
|
|
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
|
|
2
|
-
import { compileQuery } from
|
|
3
|
-
import { buildQuery, getQueryIR } from
|
|
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
|
|
8
|
-
import { transactionScopedScheduler } from
|
|
9
|
-
import { getActiveTransaction } from
|
|
10
|
-
import { CollectionSubscriber } from
|
|
11
|
-
import { getCollectionBuilder } from
|
|
12
|
-
import { LIVE_QUERY_INTERNAL } from
|
|
13
|
-
import type { LiveQueryInternalUtils } from
|
|
14
|
-
import type { WindowOptions } from
|
|
15
|
-
import type { SchedulerContextId } from
|
|
16
|
-
import type { CollectionSubscription } from
|
|
17
|
-
import type { RootStreamBuilder } from
|
|
18
|
-
import type { OrderByOptimizationInfo } from
|
|
19
|
-
import type { Collection } from
|
|
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
|
|
28
|
-
import type { Context, GetResult } from
|
|
29
|
-
import type { BasicExpression, QueryIR } from
|
|
30
|
-
import type { LazyCollectionCallbacks } from
|
|
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
|
|
37
|
-
import type { AllCollectionEvents } from
|
|
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
|
|
2
|
-
import type { Collection } from
|
|
3
|
-
import type { CollectionConfigBuilder } from
|
|
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
|
}
|