@tanstack/db 0.5.33 → 0.6.1
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/collection/change-events.cjs.map +1 -1
- package/dist/cjs/collection/change-events.d.cts +3 -2
- package/dist/cjs/collection/changes.cjs +13 -4
- package/dist/cjs/collection/changes.cjs.map +1 -1
- package/dist/cjs/collection/changes.d.cts +10 -1
- package/dist/cjs/collection/cleanup-queue.cjs +89 -0
- package/dist/cjs/collection/cleanup-queue.cjs.map +1 -0
- package/dist/cjs/collection/cleanup-queue.d.cts +30 -0
- package/dist/cjs/collection/events.cjs +14 -0
- package/dist/cjs/collection/events.cjs.map +1 -1
- package/dist/cjs/collection/events.d.cts +39 -1
- package/dist/cjs/collection/index.cjs +66 -28
- package/dist/cjs/collection/index.cjs.map +1 -1
- package/dist/cjs/collection/index.d.cts +49 -36
- package/dist/cjs/collection/indexes.cjs +211 -62
- package/dist/cjs/collection/indexes.cjs.map +1 -1
- package/dist/cjs/collection/indexes.d.cts +27 -17
- package/dist/cjs/collection/lifecycle.cjs +5 -22
- package/dist/cjs/collection/lifecycle.cjs.map +1 -1
- package/dist/cjs/collection/lifecycle.d.cts +0 -1
- package/dist/cjs/collection/mutations.cjs +18 -0
- package/dist/cjs/collection/mutations.cjs.map +1 -1
- package/dist/cjs/collection/mutations.d.cts +1 -0
- package/dist/cjs/collection/state.cjs +381 -53
- package/dist/cjs/collection/state.cjs.map +1 -1
- package/dist/cjs/collection/state.d.cts +65 -1
- package/dist/cjs/collection/subscription.cjs +6 -0
- package/dist/cjs/collection/subscription.cjs.map +1 -1
- package/dist/cjs/collection/subscription.d.cts +4 -0
- package/dist/cjs/collection/sync.cjs +108 -1
- package/dist/cjs/collection/sync.cjs.map +1 -1
- package/dist/cjs/collection/sync.d.cts +2 -0
- package/dist/cjs/collection/transaction-metadata.cjs +5 -0
- package/dist/cjs/collection/transaction-metadata.cjs.map +1 -0
- package/dist/cjs/collection/transaction-metadata.d.cts +1 -0
- package/dist/cjs/errors.cjs +8 -0
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/errors.d.cts +3 -0
- package/dist/cjs/index.cjs +22 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +11 -3
- package/dist/cjs/indexes/auto-index.cjs +13 -6
- package/dist/cjs/indexes/auto-index.cjs.map +1 -1
- package/dist/cjs/indexes/base-index.cjs +0 -3
- package/dist/cjs/indexes/base-index.cjs.map +1 -1
- package/dist/cjs/indexes/base-index.d.cts +2 -6
- package/dist/cjs/indexes/basic-index.cjs +361 -0
- package/dist/cjs/indexes/basic-index.cjs.map +1 -0
- package/dist/cjs/indexes/basic-index.d.cts +102 -0
- package/dist/cjs/indexes/btree-index.cjs.map +1 -1
- package/dist/cjs/indexes/btree-index.d.cts +1 -1
- package/dist/cjs/indexes/index-options.d.cts +8 -9
- package/dist/cjs/indexes/index-registry.cjs +89 -0
- package/dist/cjs/indexes/index-registry.cjs.map +1 -0
- package/dist/cjs/indexes/index-registry.d.cts +61 -0
- package/dist/cjs/local-only.cjs +5 -0
- package/dist/cjs/local-only.cjs.map +1 -1
- package/dist/cjs/query/builder/functions.cjs +27 -11
- package/dist/cjs/query/builder/functions.cjs.map +1 -1
- package/dist/cjs/query/builder/functions.d.cts +25 -3
- package/dist/cjs/query/builder/index.cjs +200 -39
- package/dist/cjs/query/builder/index.cjs.map +1 -1
- package/dist/cjs/query/builder/index.d.cts +4 -3
- package/dist/cjs/query/builder/ref-proxy.cjs.map +1 -1
- package/dist/cjs/query/builder/ref-proxy.d.cts +14 -3
- package/dist/cjs/query/builder/types.d.cts +84 -19
- package/dist/cjs/query/compiler/evaluators.cjs +51 -0
- package/dist/cjs/query/compiler/evaluators.cjs.map +1 -1
- package/dist/cjs/query/compiler/group-by.cjs +100 -28
- package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/group-by.d.cts +4 -2
- package/dist/cjs/query/compiler/index.cjs +283 -11
- package/dist/cjs/query/compiler/index.cjs.map +1 -1
- package/dist/cjs/query/compiler/index.d.cts +30 -2
- package/dist/cjs/query/compiler/order-by.cjs +29 -10
- package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.d.cts +1 -1
- package/dist/cjs/query/compiler/select.cjs +8 -0
- package/dist/cjs/query/compiler/select.cjs.map +1 -1
- package/dist/cjs/query/index.d.cts +2 -1
- package/dist/cjs/query/ir.cjs +18 -1
- package/dist/cjs/query/ir.cjs.map +1 -1
- package/dist/cjs/query/ir.d.cts +21 -1
- package/dist/cjs/query/live/collection-config-builder.cjs +501 -5
- package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
- package/dist/cjs/query/live/collection-config-builder.d.cts +7 -0
- package/dist/cjs/query/live/types.d.cts +3 -3
- package/dist/cjs/query/live/utils.cjs +43 -3
- package/dist/cjs/query/live/utils.cjs.map +1 -1
- package/dist/cjs/query/live/utils.d.cts +1 -0
- package/dist/cjs/query/live-query-collection.cjs.map +1 -1
- package/dist/cjs/query/live-query-collection.d.cts +9 -6
- package/dist/cjs/query/query-once.cjs.map +1 -1
- package/dist/cjs/query/query-once.d.cts +7 -5
- package/dist/cjs/query/subset-dedupe.cjs +9 -3
- package/dist/cjs/query/subset-dedupe.cjs.map +1 -1
- package/dist/cjs/types.d.cts +42 -8
- package/dist/cjs/utils/array-utils.cjs +27 -0
- package/dist/cjs/utils/array-utils.cjs.map +1 -0
- package/dist/cjs/utils/array-utils.d.cts +16 -0
- package/dist/cjs/utils/comparison.cjs +11 -0
- package/dist/cjs/utils/comparison.cjs.map +1 -1
- package/dist/cjs/utils/index-optimization.cjs +4 -0
- package/dist/cjs/utils/index-optimization.cjs.map +1 -1
- package/dist/cjs/utils.cjs +7 -9
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +6 -1
- package/dist/cjs/virtual-props.cjs +33 -0
- package/dist/cjs/virtual-props.cjs.map +1 -0
- package/dist/cjs/virtual-props.d.cts +196 -0
- package/dist/esm/collection/change-events.d.ts +3 -2
- package/dist/esm/collection/change-events.js.map +1 -1
- package/dist/esm/collection/changes.d.ts +10 -1
- package/dist/esm/collection/changes.js +13 -4
- package/dist/esm/collection/changes.js.map +1 -1
- package/dist/esm/collection/cleanup-queue.d.ts +30 -0
- package/dist/esm/collection/cleanup-queue.js +89 -0
- package/dist/esm/collection/cleanup-queue.js.map +1 -0
- package/dist/esm/collection/events.d.ts +39 -1
- package/dist/esm/collection/events.js +14 -0
- package/dist/esm/collection/events.js.map +1 -1
- package/dist/esm/collection/index.d.ts +49 -36
- package/dist/esm/collection/index.js +67 -29
- package/dist/esm/collection/index.js.map +1 -1
- package/dist/esm/collection/indexes.d.ts +27 -17
- package/dist/esm/collection/indexes.js +211 -62
- package/dist/esm/collection/indexes.js.map +1 -1
- package/dist/esm/collection/lifecycle.d.ts +0 -1
- package/dist/esm/collection/lifecycle.js +5 -22
- package/dist/esm/collection/lifecycle.js.map +1 -1
- package/dist/esm/collection/mutations.d.ts +1 -0
- package/dist/esm/collection/mutations.js +18 -0
- package/dist/esm/collection/mutations.js.map +1 -1
- package/dist/esm/collection/state.d.ts +65 -1
- package/dist/esm/collection/state.js +381 -53
- package/dist/esm/collection/state.js.map +1 -1
- package/dist/esm/collection/subscription.d.ts +4 -0
- package/dist/esm/collection/subscription.js +6 -0
- package/dist/esm/collection/subscription.js.map +1 -1
- package/dist/esm/collection/sync.d.ts +2 -0
- package/dist/esm/collection/sync.js +108 -1
- package/dist/esm/collection/sync.js.map +1 -1
- package/dist/esm/collection/transaction-metadata.d.ts +1 -0
- package/dist/esm/collection/transaction-metadata.js +5 -0
- package/dist/esm/collection/transaction-metadata.js.map +1 -0
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.js +8 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +11 -3
- package/dist/esm/index.js +25 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/indexes/auto-index.js +13 -6
- package/dist/esm/indexes/auto-index.js.map +1 -1
- package/dist/esm/indexes/base-index.d.ts +2 -6
- package/dist/esm/indexes/base-index.js +1 -4
- package/dist/esm/indexes/base-index.js.map +1 -1
- package/dist/esm/indexes/basic-index.d.ts +102 -0
- package/dist/esm/indexes/basic-index.js +361 -0
- package/dist/esm/indexes/basic-index.js.map +1 -0
- package/dist/esm/indexes/btree-index.d.ts +1 -1
- package/dist/esm/indexes/btree-index.js.map +1 -1
- package/dist/esm/indexes/index-options.d.ts +8 -9
- package/dist/esm/indexes/index-registry.d.ts +61 -0
- package/dist/esm/indexes/index-registry.js +89 -0
- package/dist/esm/indexes/index-registry.js.map +1 -0
- package/dist/esm/local-only.js +5 -0
- package/dist/esm/local-only.js.map +1 -1
- package/dist/esm/query/builder/functions.d.ts +25 -3
- package/dist/esm/query/builder/functions.js +27 -11
- package/dist/esm/query/builder/functions.js.map +1 -1
- package/dist/esm/query/builder/index.d.ts +4 -3
- package/dist/esm/query/builder/index.js +201 -40
- package/dist/esm/query/builder/index.js.map +1 -1
- package/dist/esm/query/builder/ref-proxy.d.ts +14 -3
- package/dist/esm/query/builder/ref-proxy.js.map +1 -1
- package/dist/esm/query/builder/types.d.ts +84 -19
- package/dist/esm/query/compiler/evaluators.js +51 -0
- package/dist/esm/query/compiler/evaluators.js.map +1 -1
- package/dist/esm/query/compiler/group-by.d.ts +4 -2
- package/dist/esm/query/compiler/group-by.js +101 -29
- package/dist/esm/query/compiler/group-by.js.map +1 -1
- package/dist/esm/query/compiler/index.d.ts +30 -2
- package/dist/esm/query/compiler/index.js +285 -13
- package/dist/esm/query/compiler/index.js.map +1 -1
- package/dist/esm/query/compiler/order-by.d.ts +1 -1
- package/dist/esm/query/compiler/order-by.js +30 -11
- package/dist/esm/query/compiler/order-by.js.map +1 -1
- package/dist/esm/query/compiler/select.js +8 -0
- package/dist/esm/query/compiler/select.js.map +1 -1
- package/dist/esm/query/index.d.ts +2 -1
- package/dist/esm/query/ir.d.ts +21 -1
- package/dist/esm/query/ir.js +18 -1
- package/dist/esm/query/ir.js.map +1 -1
- package/dist/esm/query/live/collection-config-builder.d.ts +7 -0
- package/dist/esm/query/live/collection-config-builder.js +503 -7
- package/dist/esm/query/live/collection-config-builder.js.map +1 -1
- package/dist/esm/query/live/types.d.ts +3 -3
- package/dist/esm/query/live/utils.d.ts +1 -0
- package/dist/esm/query/live/utils.js +43 -3
- package/dist/esm/query/live/utils.js.map +1 -1
- package/dist/esm/query/live-query-collection.d.ts +9 -6
- package/dist/esm/query/live-query-collection.js.map +1 -1
- package/dist/esm/query/query-once.d.ts +7 -5
- package/dist/esm/query/query-once.js.map +1 -1
- package/dist/esm/query/subset-dedupe.js +9 -3
- package/dist/esm/query/subset-dedupe.js.map +1 -1
- package/dist/esm/types.d.ts +42 -8
- package/dist/esm/utils/array-utils.d.ts +16 -0
- package/dist/esm/utils/array-utils.js +27 -0
- package/dist/esm/utils/array-utils.js.map +1 -0
- package/dist/esm/utils/comparison.js +11 -0
- package/dist/esm/utils/comparison.js.map +1 -1
- package/dist/esm/utils/index-optimization.js +4 -0
- package/dist/esm/utils/index-optimization.js.map +1 -1
- package/dist/esm/utils.d.ts +6 -1
- package/dist/esm/utils.js +7 -9
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/virtual-props.d.ts +196 -0
- package/dist/esm/virtual-props.js +33 -0
- package/dist/esm/virtual-props.js.map +1 -0
- package/package.json +4 -3
- package/skills/db-core/SKILL.md +4 -2
- package/skills/db-core/collection-setup/SKILL.md +30 -11
- package/skills/db-core/collection-setup/references/electric-adapter.md +1 -1
- package/skills/db-core/collection-setup/references/powersync-adapter.md +4 -0
- package/skills/db-core/collection-setup/references/query-adapter.md +32 -0
- package/skills/db-core/custom-adapter/SKILL.md +58 -9
- package/skills/db-core/live-queries/SKILL.md +162 -2
- package/skills/db-core/mutations-optimistic/SKILL.md +1 -1
- package/skills/db-core/persistence/SKILL.md +241 -0
- package/skills/meta-framework/SKILL.md +1 -1
- package/src/collection/change-events.ts +13 -9
- package/src/collection/changes.ts +30 -7
- package/src/collection/cleanup-queue.ts +105 -0
- package/src/collection/events.ts +65 -0
- package/src/collection/index.ts +110 -45
- package/src/collection/indexes.ts +283 -76
- package/src/collection/lifecycle.ts +5 -26
- package/src/collection/mutations.ts +21 -0
- package/src/collection/state.ts +545 -71
- package/src/collection/subscription.ts +7 -0
- package/src/collection/sync.ts +137 -0
- package/src/collection/transaction-metadata.ts +1 -0
- package/src/errors.ts +9 -0
- package/src/index.ts +46 -3
- package/src/indexes/auto-index.ts +18 -8
- package/src/indexes/base-index.ts +2 -10
- package/src/indexes/basic-index.ts +507 -0
- package/src/indexes/btree-index.ts +1 -1
- package/src/indexes/index-options.ts +17 -37
- package/src/indexes/index-registry.ts +174 -0
- package/src/local-only.ts +7 -0
- package/src/query/builder/functions.ts +84 -7
- package/src/query/builder/index.ts +329 -9
- package/src/query/builder/ref-proxy.ts +22 -4
- package/src/query/builder/types.ts +257 -62
- package/src/query/compiler/evaluators.ts +57 -0
- package/src/query/compiler/group-by.ts +156 -35
- package/src/query/compiler/index.ts +445 -15
- package/src/query/compiler/order-by.ts +51 -12
- package/src/query/compiler/select.ts +9 -0
- package/src/query/index.ts +7 -0
- package/src/query/ir.ts +23 -2
- package/src/query/live/collection-config-builder.ts +809 -9
- package/src/query/live/types.ts +10 -4
- package/src/query/live/utils.ts +64 -3
- package/src/query/live-query-collection.ts +43 -18
- package/src/query/query-once.ts +31 -12
- package/src/query/subset-dedupe.ts +11 -7
- package/src/types.ts +49 -9
- package/src/utils/array-utils.ts +49 -0
- package/src/utils/comparison.ts +14 -0
- package/src/utils/index-optimization.ts +4 -0
- package/src/utils.ts +12 -9
- package/src/virtual-props.ts +282 -0
- package/dist/cjs/indexes/lazy-index.cjs +0 -190
- package/dist/cjs/indexes/lazy-index.cjs.map +0 -1
- package/dist/cjs/indexes/lazy-index.d.cts +0 -96
- package/dist/esm/indexes/lazy-index.d.ts +0 -96
- package/dist/esm/indexes/lazy-index.js +0 -190
- package/dist/esm/indexes/lazy-index.js.map +0 -1
- package/src/indexes/lazy-index.ts +0 -251
|
@@ -57,6 +57,7 @@ export declare class CollectionConfigBuilder<TContext extends Context, TResult e
|
|
|
57
57
|
private inputsCache;
|
|
58
58
|
private pipelineCache;
|
|
59
59
|
sourceWhereClausesCache: Map<string, BasicExpression<boolean>> | undefined;
|
|
60
|
+
private includesCache;
|
|
60
61
|
readonly subscriptions: Record<string, CollectionSubscription>;
|
|
61
62
|
lazySourcesCallbacks: Record<string, LazyCollectionCallbacks>;
|
|
62
63
|
readonly lazySources: Set<string>;
|
|
@@ -141,6 +142,12 @@ export declare class CollectionConfigBuilder<TContext extends Context, TResult e
|
|
|
141
142
|
private compileBasePipeline;
|
|
142
143
|
private maybeCompileBasePipeline;
|
|
143
144
|
private extendPipelineWithChangeProcessing;
|
|
145
|
+
/**
|
|
146
|
+
* Sets up output callbacks for includes child pipelines.
|
|
147
|
+
* Each includes entry gets its own output callback that accumulates child changes,
|
|
148
|
+
* and a child registry that maps correlation key → child Collection.
|
|
149
|
+
*/
|
|
150
|
+
private setupIncludesOutput;
|
|
144
151
|
private applyChanges;
|
|
145
152
|
/**
|
|
146
153
|
* Handle status changes from source collections
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { D2, output } from "@tanstack/db-ivm";
|
|
2
|
-
import { compileQuery } from "../compiler/index.js";
|
|
1
|
+
import { D2, output, serializeValue } from "@tanstack/db-ivm";
|
|
2
|
+
import { compileQuery, INCLUDES_ROUTING } from "../compiler/index.js";
|
|
3
|
+
import { createCollection } from "../../collection/index.js";
|
|
3
4
|
import { SetWindowRequiresOrderByError, MissingAliasInputsError } from "../../errors.js";
|
|
4
5
|
import { transactionScopedScheduler } from "../../scheduler.js";
|
|
5
6
|
import { getActiveTransaction } from "../../transactions.js";
|
|
@@ -25,7 +26,10 @@ class CollectionConfigBuilder {
|
|
|
25
26
|
this.lazySources = /* @__PURE__ */ new Set();
|
|
26
27
|
this.optimizableOrderByCollections = {};
|
|
27
28
|
this.id = config.id || `live-query-${++liveQueryCollectionCounter}`;
|
|
28
|
-
this.query = buildQueryFromConfig(
|
|
29
|
+
this.query = buildQueryFromConfig({
|
|
30
|
+
query: config.query,
|
|
31
|
+
requireObjectResult: true
|
|
32
|
+
});
|
|
29
33
|
this.collections = extractCollectionsFromQuery(this.query);
|
|
30
34
|
const collectionAliasesById = extractCollectionAliases(this.query);
|
|
31
35
|
this.collectionByAlias = {};
|
|
@@ -360,6 +364,7 @@ class CollectionConfigBuilder {
|
|
|
360
364
|
this.inputsCache = void 0;
|
|
361
365
|
this.pipelineCache = void 0;
|
|
362
366
|
this.sourceWhereClausesCache = void 0;
|
|
367
|
+
this.includesCache = void 0;
|
|
363
368
|
this.lazySources.clear();
|
|
364
369
|
this.optimizableOrderByCollections = {};
|
|
365
370
|
this.lazySourcesCallbacks = {};
|
|
@@ -397,6 +402,7 @@ class CollectionConfigBuilder {
|
|
|
397
402
|
this.pipelineCache = compilation.pipeline;
|
|
398
403
|
this.sourceWhereClausesCache = compilation.sourceWhereClauses;
|
|
399
404
|
this.compiledAliasToCollectionId = compilation.aliasToCollectionId;
|
|
405
|
+
this.includesCache = compilation.includes;
|
|
400
406
|
const missingAliases = Object.keys(this.compiledAliasToCollectionId).filter(
|
|
401
407
|
(alias) => !Object.hasOwn(this.inputsCache, alias)
|
|
402
408
|
);
|
|
@@ -425,8 +431,14 @@ class CollectionConfigBuilder {
|
|
|
425
431
|
messages.reduce(accumulateChanges, pendingChanges);
|
|
426
432
|
})
|
|
427
433
|
);
|
|
434
|
+
const includesState = this.setupIncludesOutput(
|
|
435
|
+
this.includesCache,
|
|
436
|
+
syncState
|
|
437
|
+
);
|
|
428
438
|
syncState.flushPendingChanges = () => {
|
|
429
|
-
|
|
439
|
+
const hasParentChanges = pendingChanges.size > 0;
|
|
440
|
+
const hasChildChanges = hasPendingIncludesChanges(includesState);
|
|
441
|
+
if (!hasParentChanges && !hasChildChanges) {
|
|
430
442
|
return;
|
|
431
443
|
}
|
|
432
444
|
let changesToApply = pendingChanges;
|
|
@@ -450,10 +462,19 @@ class CollectionConfigBuilder {
|
|
|
450
462
|
}
|
|
451
463
|
changesToApply = merged;
|
|
452
464
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
465
|
+
if (hasParentChanges) {
|
|
466
|
+
begin();
|
|
467
|
+
changesToApply.forEach(this.applyChanges.bind(this, config));
|
|
468
|
+
commit();
|
|
469
|
+
}
|
|
456
470
|
pendingChanges = /* @__PURE__ */ new Map();
|
|
471
|
+
flushIncludesState(
|
|
472
|
+
includesState,
|
|
473
|
+
config.collection,
|
|
474
|
+
this.id,
|
|
475
|
+
hasParentChanges ? changesToApply : null,
|
|
476
|
+
config
|
|
477
|
+
);
|
|
457
478
|
};
|
|
458
479
|
graph.finalize();
|
|
459
480
|
syncState.graph = graph;
|
|
@@ -461,6 +482,65 @@ class CollectionConfigBuilder {
|
|
|
461
482
|
syncState.pipeline = pipeline;
|
|
462
483
|
return syncState;
|
|
463
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Sets up output callbacks for includes child pipelines.
|
|
487
|
+
* Each includes entry gets its own output callback that accumulates child changes,
|
|
488
|
+
* and a child registry that maps correlation key → child Collection.
|
|
489
|
+
*/
|
|
490
|
+
setupIncludesOutput(includesEntries, syncState) {
|
|
491
|
+
if (!includesEntries || includesEntries.length === 0) {
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
return includesEntries.map((entry) => {
|
|
495
|
+
const state = {
|
|
496
|
+
fieldName: entry.fieldName,
|
|
497
|
+
childCorrelationField: entry.childCorrelationField,
|
|
498
|
+
hasOrderBy: entry.hasOrderBy,
|
|
499
|
+
materialization: entry.materialization,
|
|
500
|
+
scalarField: entry.scalarField,
|
|
501
|
+
childRegistry: /* @__PURE__ */ new Map(),
|
|
502
|
+
pendingChildChanges: /* @__PURE__ */ new Map(),
|
|
503
|
+
correlationToParentKeys: /* @__PURE__ */ new Map()
|
|
504
|
+
};
|
|
505
|
+
entry.pipeline.pipe(
|
|
506
|
+
output((data) => {
|
|
507
|
+
const messages = data.getInner();
|
|
508
|
+
syncState.messagesCount += messages.length;
|
|
509
|
+
for (const [[childKey, tupleData], multiplicity] of messages) {
|
|
510
|
+
const [childResult, _orderByIndex, correlationKey, parentContext] = tupleData;
|
|
511
|
+
const routingKey = computeRoutingKey(correlationKey, parentContext);
|
|
512
|
+
let byChild = state.pendingChildChanges.get(routingKey);
|
|
513
|
+
if (!byChild) {
|
|
514
|
+
byChild = /* @__PURE__ */ new Map();
|
|
515
|
+
state.pendingChildChanges.set(routingKey, byChild);
|
|
516
|
+
}
|
|
517
|
+
const existing = byChild.get(childKey) || {
|
|
518
|
+
deletes: 0,
|
|
519
|
+
inserts: 0,
|
|
520
|
+
value: childResult,
|
|
521
|
+
orderByIndex: _orderByIndex
|
|
522
|
+
};
|
|
523
|
+
if (multiplicity < 0) {
|
|
524
|
+
existing.deletes += Math.abs(multiplicity);
|
|
525
|
+
} else if (multiplicity > 0) {
|
|
526
|
+
existing.inserts += multiplicity;
|
|
527
|
+
existing.value = childResult;
|
|
528
|
+
}
|
|
529
|
+
byChild.set(childKey, existing);
|
|
530
|
+
}
|
|
531
|
+
})
|
|
532
|
+
);
|
|
533
|
+
if (entry.childCompilationResult.includes) {
|
|
534
|
+
state.nestedSetups = setupNestedPipelines(
|
|
535
|
+
entry.childCompilationResult.includes,
|
|
536
|
+
syncState
|
|
537
|
+
);
|
|
538
|
+
state.nestedRoutingIndex = /* @__PURE__ */ new Map();
|
|
539
|
+
state.nestedRoutingReverseIndex = /* @__PURE__ */ new Map();
|
|
540
|
+
}
|
|
541
|
+
return state;
|
|
542
|
+
});
|
|
543
|
+
}
|
|
464
544
|
applyChanges(config, changes, key) {
|
|
465
545
|
const { write, collection } = config;
|
|
466
546
|
const { deletes, inserts, value, orderByIndex } = changes;
|
|
@@ -604,6 +684,422 @@ function createOrderByComparator(orderByIndices) {
|
|
|
604
684
|
return 0;
|
|
605
685
|
};
|
|
606
686
|
}
|
|
687
|
+
function materializesInline(state) {
|
|
688
|
+
return state.materialization !== `collection`;
|
|
689
|
+
}
|
|
690
|
+
function materializeIncludedValue(state, entry) {
|
|
691
|
+
if (!entry) {
|
|
692
|
+
if (state.materialization === `array`) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
695
|
+
if (state.materialization === `concat`) {
|
|
696
|
+
return ``;
|
|
697
|
+
}
|
|
698
|
+
return void 0;
|
|
699
|
+
}
|
|
700
|
+
if (state.materialization === `collection`) {
|
|
701
|
+
return entry.collection;
|
|
702
|
+
}
|
|
703
|
+
const rows = [...entry.collection.toArray];
|
|
704
|
+
const values = state.scalarField ? rows.map((row) => row?.[state.scalarField]) : rows;
|
|
705
|
+
if (state.materialization === `array`) {
|
|
706
|
+
return values;
|
|
707
|
+
}
|
|
708
|
+
return values.map((value) => String(value ?? ``)).join(``);
|
|
709
|
+
}
|
|
710
|
+
function setupNestedPipelines(includes, syncState) {
|
|
711
|
+
return includes.map((entry) => {
|
|
712
|
+
const buffer = /* @__PURE__ */ new Map();
|
|
713
|
+
entry.pipeline.pipe(
|
|
714
|
+
output((data) => {
|
|
715
|
+
const messages = data.getInner();
|
|
716
|
+
syncState.messagesCount += messages.length;
|
|
717
|
+
for (const [[childKey, tupleData], multiplicity] of messages) {
|
|
718
|
+
const [childResult, _orderByIndex, correlationKey, parentContext] = tupleData;
|
|
719
|
+
const routingKey = computeRoutingKey(correlationKey, parentContext);
|
|
720
|
+
let byChild = buffer.get(routingKey);
|
|
721
|
+
if (!byChild) {
|
|
722
|
+
byChild = /* @__PURE__ */ new Map();
|
|
723
|
+
buffer.set(routingKey, byChild);
|
|
724
|
+
}
|
|
725
|
+
const existing = byChild.get(childKey) || {
|
|
726
|
+
deletes: 0,
|
|
727
|
+
inserts: 0,
|
|
728
|
+
value: childResult,
|
|
729
|
+
orderByIndex: _orderByIndex
|
|
730
|
+
};
|
|
731
|
+
if (multiplicity < 0) {
|
|
732
|
+
existing.deletes += Math.abs(multiplicity);
|
|
733
|
+
} else if (multiplicity > 0) {
|
|
734
|
+
existing.inserts += multiplicity;
|
|
735
|
+
existing.value = childResult;
|
|
736
|
+
}
|
|
737
|
+
byChild.set(childKey, existing);
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
);
|
|
741
|
+
const setup = {
|
|
742
|
+
compilationResult: entry,
|
|
743
|
+
buffer
|
|
744
|
+
};
|
|
745
|
+
if (entry.childCompilationResult.includes) {
|
|
746
|
+
setup.nestedSetups = setupNestedPipelines(
|
|
747
|
+
entry.childCompilationResult.includes,
|
|
748
|
+
syncState
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
return setup;
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
function createPerEntryIncludesStates(setups) {
|
|
755
|
+
return setups.map((setup) => {
|
|
756
|
+
const state = {
|
|
757
|
+
fieldName: setup.compilationResult.fieldName,
|
|
758
|
+
childCorrelationField: setup.compilationResult.childCorrelationField,
|
|
759
|
+
hasOrderBy: setup.compilationResult.hasOrderBy,
|
|
760
|
+
materialization: setup.compilationResult.materialization,
|
|
761
|
+
scalarField: setup.compilationResult.scalarField,
|
|
762
|
+
childRegistry: /* @__PURE__ */ new Map(),
|
|
763
|
+
pendingChildChanges: /* @__PURE__ */ new Map(),
|
|
764
|
+
correlationToParentKeys: /* @__PURE__ */ new Map()
|
|
765
|
+
};
|
|
766
|
+
if (setup.nestedSetups) {
|
|
767
|
+
state.nestedSetups = setup.nestedSetups;
|
|
768
|
+
state.nestedRoutingIndex = /* @__PURE__ */ new Map();
|
|
769
|
+
state.nestedRoutingReverseIndex = /* @__PURE__ */ new Map();
|
|
770
|
+
}
|
|
771
|
+
return state;
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
function drainNestedBuffers(state) {
|
|
775
|
+
const dirtyCorrelationKeys = /* @__PURE__ */ new Set();
|
|
776
|
+
if (!state.nestedSetups) return dirtyCorrelationKeys;
|
|
777
|
+
for (let i = 0; i < state.nestedSetups.length; i++) {
|
|
778
|
+
const setup = state.nestedSetups[i];
|
|
779
|
+
const toDelete = [];
|
|
780
|
+
for (const [nestedCorrelationKey, childChanges] of setup.buffer) {
|
|
781
|
+
const parentCorrelationKey = state.nestedRoutingIndex.get(nestedCorrelationKey);
|
|
782
|
+
if (parentCorrelationKey === void 0) {
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
const entry = state.childRegistry.get(parentCorrelationKey);
|
|
786
|
+
if (!entry || !entry.includesStates) {
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
const entryState = entry.includesStates[i];
|
|
790
|
+
for (const [childKey, changes] of childChanges) {
|
|
791
|
+
let byChild = entryState.pendingChildChanges.get(nestedCorrelationKey);
|
|
792
|
+
if (!byChild) {
|
|
793
|
+
byChild = /* @__PURE__ */ new Map();
|
|
794
|
+
entryState.pendingChildChanges.set(nestedCorrelationKey, byChild);
|
|
795
|
+
}
|
|
796
|
+
const existing = byChild.get(childKey);
|
|
797
|
+
if (existing) {
|
|
798
|
+
existing.inserts += changes.inserts;
|
|
799
|
+
existing.deletes += changes.deletes;
|
|
800
|
+
if (changes.inserts > 0) {
|
|
801
|
+
existing.value = changes.value;
|
|
802
|
+
if (changes.orderByIndex !== void 0) {
|
|
803
|
+
existing.orderByIndex = changes.orderByIndex;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
} else {
|
|
807
|
+
byChild.set(childKey, { ...changes });
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
dirtyCorrelationKeys.add(parentCorrelationKey);
|
|
811
|
+
toDelete.push(nestedCorrelationKey);
|
|
812
|
+
}
|
|
813
|
+
for (const key of toDelete) {
|
|
814
|
+
setup.buffer.delete(key);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return dirtyCorrelationKeys;
|
|
818
|
+
}
|
|
819
|
+
function updateRoutingIndex(state, correlationKey, childChanges) {
|
|
820
|
+
if (!state.nestedSetups) return;
|
|
821
|
+
for (const setup of state.nestedSetups) {
|
|
822
|
+
for (const [, change] of childChanges) {
|
|
823
|
+
if (change.inserts > 0) {
|
|
824
|
+
const nestedRouting = change.value[INCLUDES_ROUTING]?.[setup.compilationResult.fieldName];
|
|
825
|
+
const nestedCorrelationKey = nestedRouting?.correlationKey;
|
|
826
|
+
const nestedParentContext = nestedRouting?.parentContext ?? null;
|
|
827
|
+
const nestedRoutingKey = computeRoutingKey(
|
|
828
|
+
nestedCorrelationKey,
|
|
829
|
+
nestedParentContext
|
|
830
|
+
);
|
|
831
|
+
if (nestedCorrelationKey != null) {
|
|
832
|
+
state.nestedRoutingIndex.set(nestedRoutingKey, correlationKey);
|
|
833
|
+
let reverseSet = state.nestedRoutingReverseIndex.get(correlationKey);
|
|
834
|
+
if (!reverseSet) {
|
|
835
|
+
reverseSet = /* @__PURE__ */ new Set();
|
|
836
|
+
state.nestedRoutingReverseIndex.set(correlationKey, reverseSet);
|
|
837
|
+
}
|
|
838
|
+
reverseSet.add(nestedRoutingKey);
|
|
839
|
+
}
|
|
840
|
+
} else if (change.deletes > 0 && change.inserts === 0) {
|
|
841
|
+
const nestedRouting2 = change.value[INCLUDES_ROUTING]?.[setup.compilationResult.fieldName];
|
|
842
|
+
const nestedCorrelationKey = nestedRouting2?.correlationKey;
|
|
843
|
+
const nestedParentContext2 = nestedRouting2?.parentContext ?? null;
|
|
844
|
+
const nestedRoutingKey = computeRoutingKey(
|
|
845
|
+
nestedCorrelationKey,
|
|
846
|
+
nestedParentContext2
|
|
847
|
+
);
|
|
848
|
+
if (nestedCorrelationKey != null) {
|
|
849
|
+
state.nestedRoutingIndex.delete(nestedRoutingKey);
|
|
850
|
+
const reverseSet = state.nestedRoutingReverseIndex.get(correlationKey);
|
|
851
|
+
if (reverseSet) {
|
|
852
|
+
reverseSet.delete(nestedRoutingKey);
|
|
853
|
+
if (reverseSet.size === 0) {
|
|
854
|
+
state.nestedRoutingReverseIndex.delete(correlationKey);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function cleanRoutingIndexOnDelete(state, correlationKey) {
|
|
863
|
+
if (!state.nestedRoutingReverseIndex) return;
|
|
864
|
+
const nestedKeys = state.nestedRoutingReverseIndex.get(correlationKey);
|
|
865
|
+
if (nestedKeys) {
|
|
866
|
+
for (const nestedKey of nestedKeys) {
|
|
867
|
+
state.nestedRoutingIndex.delete(nestedKey);
|
|
868
|
+
}
|
|
869
|
+
state.nestedRoutingReverseIndex.delete(correlationKey);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function hasNestedBufferChanges(setups) {
|
|
873
|
+
for (const setup of setups) {
|
|
874
|
+
if (setup.buffer.size > 0) return true;
|
|
875
|
+
if (setup.nestedSetups && hasNestedBufferChanges(setup.nestedSetups))
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
function computeRoutingKey(correlationKey, parentContext) {
|
|
881
|
+
if (parentContext == null) return correlationKey;
|
|
882
|
+
return JSON.stringify([correlationKey, parentContext]);
|
|
883
|
+
}
|
|
884
|
+
function createChildCollectionEntry(parentId, fieldName, correlationKey, hasOrderBy, nestedSetups) {
|
|
885
|
+
const resultKeys = /* @__PURE__ */ new WeakMap();
|
|
886
|
+
const orderByIndices = hasOrderBy ? /* @__PURE__ */ new WeakMap() : null;
|
|
887
|
+
let syncMethods = null;
|
|
888
|
+
const compare = orderByIndices ? createOrderByComparator(orderByIndices) : void 0;
|
|
889
|
+
const collection = createCollection({
|
|
890
|
+
id: `__child-collection:${parentId}-${fieldName}-${serializeValue(correlationKey)}`,
|
|
891
|
+
getKey: (item) => resultKeys.get(item),
|
|
892
|
+
compare,
|
|
893
|
+
sync: {
|
|
894
|
+
rowUpdateMode: `full`,
|
|
895
|
+
sync: (methods) => {
|
|
896
|
+
syncMethods = methods;
|
|
897
|
+
return () => {
|
|
898
|
+
syncMethods = null;
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
startSync: true
|
|
903
|
+
});
|
|
904
|
+
const entry = {
|
|
905
|
+
collection,
|
|
906
|
+
get syncMethods() {
|
|
907
|
+
return syncMethods;
|
|
908
|
+
},
|
|
909
|
+
resultKeys,
|
|
910
|
+
orderByIndices
|
|
911
|
+
};
|
|
912
|
+
if (nestedSetups) {
|
|
913
|
+
entry.includesStates = createPerEntryIncludesStates(nestedSetups);
|
|
914
|
+
}
|
|
915
|
+
return entry;
|
|
916
|
+
}
|
|
917
|
+
function flushIncludesState(includesState, parentCollection, parentId, parentChanges, parentSyncMethods) {
|
|
918
|
+
for (const state of includesState) {
|
|
919
|
+
if (parentChanges) {
|
|
920
|
+
for (const [parentKey, changes] of parentChanges) {
|
|
921
|
+
if (changes.inserts > 0) {
|
|
922
|
+
const parentResult = changes.value;
|
|
923
|
+
const routing = parentResult[INCLUDES_ROUTING]?.[state.fieldName];
|
|
924
|
+
const correlationKey = routing?.correlationKey;
|
|
925
|
+
const parentContext = routing?.parentContext ?? null;
|
|
926
|
+
const routingKey = computeRoutingKey(correlationKey, parentContext);
|
|
927
|
+
if (correlationKey != null) {
|
|
928
|
+
if (!state.childRegistry.has(routingKey)) {
|
|
929
|
+
const entry = createChildCollectionEntry(
|
|
930
|
+
parentId,
|
|
931
|
+
state.fieldName,
|
|
932
|
+
routingKey,
|
|
933
|
+
state.hasOrderBy,
|
|
934
|
+
state.nestedSetups
|
|
935
|
+
);
|
|
936
|
+
state.childRegistry.set(routingKey, entry);
|
|
937
|
+
}
|
|
938
|
+
let parentKeys = state.correlationToParentKeys.get(routingKey);
|
|
939
|
+
if (!parentKeys) {
|
|
940
|
+
parentKeys = /* @__PURE__ */ new Set();
|
|
941
|
+
state.correlationToParentKeys.set(routingKey, parentKeys);
|
|
942
|
+
}
|
|
943
|
+
parentKeys.add(parentKey);
|
|
944
|
+
const childValue = materializeIncludedValue(
|
|
945
|
+
state,
|
|
946
|
+
state.childRegistry.get(routingKey)
|
|
947
|
+
);
|
|
948
|
+
parentResult[state.fieldName] = childValue;
|
|
949
|
+
const storedParent = parentCollection.get(parentKey);
|
|
950
|
+
if (storedParent && storedParent !== parentResult) {
|
|
951
|
+
storedParent[state.fieldName] = childValue;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const affectedCorrelationKeys = materializesInline(state) ? new Set(state.pendingChildChanges.keys()) : null;
|
|
958
|
+
const entriesWithChildChanges = /* @__PURE__ */ new Map();
|
|
959
|
+
if (state.pendingChildChanges.size > 0) {
|
|
960
|
+
for (const [correlationKey, childChanges] of state.pendingChildChanges) {
|
|
961
|
+
let entry = state.childRegistry.get(correlationKey);
|
|
962
|
+
if (!entry) {
|
|
963
|
+
entry = createChildCollectionEntry(
|
|
964
|
+
parentId,
|
|
965
|
+
state.fieldName,
|
|
966
|
+
correlationKey,
|
|
967
|
+
state.hasOrderBy,
|
|
968
|
+
state.nestedSetups
|
|
969
|
+
);
|
|
970
|
+
state.childRegistry.set(correlationKey, entry);
|
|
971
|
+
}
|
|
972
|
+
if (state.materialization === `collection`) {
|
|
973
|
+
attachChildCollectionToParent(
|
|
974
|
+
parentCollection,
|
|
975
|
+
state.fieldName,
|
|
976
|
+
correlationKey,
|
|
977
|
+
state.correlationToParentKeys,
|
|
978
|
+
entry.collection
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
if (entry.syncMethods) {
|
|
982
|
+
entry.syncMethods.begin();
|
|
983
|
+
for (const [childKey, change] of childChanges) {
|
|
984
|
+
entry.resultKeys.set(change.value, childKey);
|
|
985
|
+
if (entry.orderByIndices && change.orderByIndex !== void 0) {
|
|
986
|
+
entry.orderByIndices.set(change.value, change.orderByIndex);
|
|
987
|
+
}
|
|
988
|
+
if (change.inserts > 0 && change.deletes === 0) {
|
|
989
|
+
entry.syncMethods.write({ value: change.value, type: `insert` });
|
|
990
|
+
} else if (change.inserts > change.deletes || change.inserts === change.deletes && entry.syncMethods.collection.has(
|
|
991
|
+
entry.syncMethods.collection.getKeyFromItem(change.value)
|
|
992
|
+
)) {
|
|
993
|
+
entry.syncMethods.write({ value: change.value, type: `update` });
|
|
994
|
+
} else if (change.deletes > 0) {
|
|
995
|
+
entry.syncMethods.write({ value: change.value, type: `delete` });
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
entry.syncMethods.commit();
|
|
999
|
+
}
|
|
1000
|
+
updateRoutingIndex(state, correlationKey, childChanges);
|
|
1001
|
+
entriesWithChildChanges.set(correlationKey, { entry, childChanges });
|
|
1002
|
+
}
|
|
1003
|
+
state.pendingChildChanges.clear();
|
|
1004
|
+
}
|
|
1005
|
+
const dirtyFromBuffers = drainNestedBuffers(state);
|
|
1006
|
+
for (const [, { entry, childChanges }] of entriesWithChildChanges) {
|
|
1007
|
+
if (entry.includesStates) {
|
|
1008
|
+
flushIncludesState(
|
|
1009
|
+
entry.includesStates,
|
|
1010
|
+
entry.collection,
|
|
1011
|
+
entry.collection.id,
|
|
1012
|
+
childChanges,
|
|
1013
|
+
entry.syncMethods
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
for (const correlationKey of dirtyFromBuffers) {
|
|
1018
|
+
if (entriesWithChildChanges.has(correlationKey)) continue;
|
|
1019
|
+
const entry = state.childRegistry.get(correlationKey);
|
|
1020
|
+
if (entry?.includesStates) {
|
|
1021
|
+
flushIncludesState(
|
|
1022
|
+
entry.includesStates,
|
|
1023
|
+
entry.collection,
|
|
1024
|
+
entry.collection.id,
|
|
1025
|
+
null,
|
|
1026
|
+
entry.syncMethods
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
const inlineReEmitKeys = materializesInline(state) ? /* @__PURE__ */ new Set([...affectedCorrelationKeys || [], ...dirtyFromBuffers]) : null;
|
|
1031
|
+
if (parentSyncMethods && inlineReEmitKeys && inlineReEmitKeys.size > 0) {
|
|
1032
|
+
const events = [];
|
|
1033
|
+
for (const correlationKey of inlineReEmitKeys) {
|
|
1034
|
+
const parentKeys = state.correlationToParentKeys.get(correlationKey);
|
|
1035
|
+
if (!parentKeys) continue;
|
|
1036
|
+
const entry = state.childRegistry.get(correlationKey);
|
|
1037
|
+
for (const parentKey of parentKeys) {
|
|
1038
|
+
const item = parentCollection.get(parentKey);
|
|
1039
|
+
if (item) {
|
|
1040
|
+
const key = parentSyncMethods.collection.getKeyFromItem(item);
|
|
1041
|
+
const previousValue = { ...item };
|
|
1042
|
+
item[state.fieldName] = materializeIncludedValue(state, entry);
|
|
1043
|
+
events.push({
|
|
1044
|
+
type: `update`,
|
|
1045
|
+
key,
|
|
1046
|
+
value: item,
|
|
1047
|
+
previousValue
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
if (events.length > 0) {
|
|
1053
|
+
const changesManager = parentCollection._changes;
|
|
1054
|
+
changesManager.emitEvents(events, true);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (parentChanges) {
|
|
1058
|
+
for (const [parentKey, changes] of parentChanges) {
|
|
1059
|
+
if (changes.deletes > 0 && changes.inserts === 0) {
|
|
1060
|
+
const routing = changes.value[INCLUDES_ROUTING]?.[state.fieldName];
|
|
1061
|
+
const correlationKey = routing?.correlationKey;
|
|
1062
|
+
const parentContext = routing?.parentContext ?? null;
|
|
1063
|
+
const routingKey = computeRoutingKey(correlationKey, parentContext);
|
|
1064
|
+
if (correlationKey != null) {
|
|
1065
|
+
const parentKeys = state.correlationToParentKeys.get(routingKey);
|
|
1066
|
+
if (parentKeys) {
|
|
1067
|
+
parentKeys.delete(parentKey);
|
|
1068
|
+
if (parentKeys.size === 0) {
|
|
1069
|
+
cleanRoutingIndexOnDelete(state, routingKey);
|
|
1070
|
+
state.childRegistry.delete(routingKey);
|
|
1071
|
+
state.correlationToParentKeys.delete(routingKey);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if (parentChanges) {
|
|
1080
|
+
for (const [, changes] of parentChanges) {
|
|
1081
|
+
delete changes.value[INCLUDES_ROUTING];
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
function hasPendingIncludesChanges(states) {
|
|
1086
|
+
for (const state of states) {
|
|
1087
|
+
if (state.pendingChildChanges.size > 0) return true;
|
|
1088
|
+
if (state.nestedSetups && hasNestedBufferChanges(state.nestedSetups))
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
function attachChildCollectionToParent(parentCollection, fieldName, correlationKey, correlationToParentKeys, childCollection) {
|
|
1094
|
+
const parentKeys = correlationToParentKeys.get(correlationKey);
|
|
1095
|
+
if (!parentKeys) return;
|
|
1096
|
+
for (const parentKey of parentKeys) {
|
|
1097
|
+
const item = parentCollection.get(parentKey);
|
|
1098
|
+
if (item) {
|
|
1099
|
+
item[fieldName] = childCollection;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
607
1103
|
function accumulateChanges(acc, [[key, tupleData], multiplicity]) {
|
|
608
1104
|
const [value, orderByIndex] = tupleData;
|
|
609
1105
|
const changes = acc.get(key) || {
|