@rocicorp/zero 1.3.0-canary.3 → 1.3.1-canary.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/out/analyze-query/src/bin-analyze.js +7 -7
- package/out/analyze-query/src/bin-transform.js +3 -3
- package/out/ast-to-zql/src/bin.js +2 -2
- package/out/shared/src/logging.d.ts.map +1 -1
- package/out/shared/src/logging.js +1 -1
- package/out/shared/src/logging.js.map +1 -1
- package/out/shared/src/options.d.ts.map +1 -1
- package/out/shared/src/options.js +1 -1
- package/out/shared/src/options.js.map +1 -1
- package/out/zero/package.js +89 -91
- package/out/zero/package.js.map +1 -1
- package/out/zero/src/zero-cache-dev.js +1 -1
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero/src/zero-out.js +1 -1
- package/out/zero-cache/src/auth/auth.d.ts.map +1 -1
- package/out/zero-cache/src/auth/auth.js.map +1 -1
- package/out/zero-cache/src/auth/load-permissions.js +2 -2
- package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +14 -5
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/network.d.ts +1 -1
- package/out/zero-cache/src/config/network.d.ts.map +1 -1
- package/out/zero-cache/src/config/network.js +1 -1
- package/out/zero-cache/src/config/network.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +0 -5
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +3 -16
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
- package/out/zero-cache/src/db/lite-tables.js +3 -3
- package/out/zero-cache/src/db/lite-tables.js.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.d.ts +1 -1
- package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.js +13 -13
- package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.d.ts +40 -43
- package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +56 -76
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/observability/events.d.ts.map +1 -1
- package/out/zero-cache/src/observability/events.js +1 -1
- package/out/zero-cache/src/observability/events.js.map +1 -1
- package/out/zero-cache/src/scripts/decommission.js +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +2 -2
- package/out/zero-cache/src/scripts/permissions.js +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.js +3 -3
- package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +11 -26
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/logging.d.ts +3 -1
- package/out/zero-cache/src/server/logging.d.ts.map +1 -1
- package/out/zero-cache/src/server/logging.js +3 -6
- package/out/zero-cache/src/server/logging.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +26 -26
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/mutator.js +2 -4
- package/out/zero-cache/src/server/mutator.js.map +1 -1
- package/out/zero-cache/src/server/otel-log-sink.d.ts.map +1 -1
- package/out/zero-cache/src/server/otel-log-sink.js +2 -0
- package/out/zero-cache/src/server/otel-log-sink.js.map +1 -1
- package/out/zero-cache/src/server/otel-start.d.ts +1 -1
- package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/otel-start.js +3 -7
- package/out/zero-cache/src/server/otel-start.js.map +1 -1
- package/out/zero-cache/src/server/reaper.js +6 -6
- package/out/zero-cache/src/server/reaper.js.map +1 -1
- package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/server/replicator.js +3 -5
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +2 -2
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/server/syncer.js +12 -13
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/server/worker-dispatcher.js +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.js +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js +2 -2
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +1 -4
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +2 -2
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +3 -58
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +51 -208
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +1 -5
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +7 -10
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/replica-monitor.js +2 -2
- package/out/zero-cache/src/services/change-streamer/storer.d.ts +2 -19
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +5 -69
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/heapz.d.ts.map +1 -1
- package/out/zero-cache/src/services/heapz.js +1 -1
- package/out/zero-cache/src/services/heapz.js.map +1 -1
- package/out/zero-cache/src/services/life-cycle.d.ts +1 -2
- package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +7 -10
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts +4 -15
- package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +31 -31
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts +28 -28
- package/out/zero-cache/src/services/replicator/change-processor.js +2 -2
- package/out/zero-cache/src/services/replicator/incremental-sync.js +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.js +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker.js +3 -3
- package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -1
- package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
- package/out/zero-cache/src/services/run-ast.js +2 -2
- package/out/zero-cache/src/services/run-ast.js.map +1 -1
- package/out/zero-cache/src/services/statz.d.ts.map +1 -1
- package/out/zero-cache/src/services/statz.js +2 -2
- package/out/zero-cache/src/services/statz.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +1 -1
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.d.ts +2 -2
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +2 -2
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/inspect-handler.js +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +16 -6
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +37 -29
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js +3 -3
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js +2 -2
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +6 -6
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/profiler.d.ts.map +1 -1
- package/out/zero-cache/src/types/profiler.js.map +1 -1
- package/out/zero-cache/src/types/row-key.d.ts.map +1 -1
- package/out/zero-cache/src/types/row-key.js.map +1 -1
- package/out/zero-cache/src/types/streams.d.ts +1 -1
- package/out/zero-cache/src/types/streams.d.ts.map +1 -1
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/types/websocket-handoff.d.ts +1 -1
- package/out/zero-cache/src/types/websocket-handoff.d.ts.map +1 -1
- package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
- package/out/zero-cache/src/workers/connection.d.ts +1 -1
- package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/mutator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +2 -2
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/crud-impl.d.ts.map +1 -1
- package/out/zero-client/src/client/crud-impl.js +13 -4
- package/out/zero-client/src/client/crud-impl.js.map +1 -1
- package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
- package/out/zero-client/src/client/ivm-branch.js +13 -4
- package/out/zero-client/src/client/ivm-branch.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-protocol/src/error.d.ts.map +1 -1
- package/out/zero-protocol/src/error.js +1 -1
- package/out/zero-protocol/src/error.js.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.js +13 -13
- package/out/zero-solid/src/solid-view.js.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/ivm/array-view.d.ts.map +1 -1
- package/out/zql/src/ivm/array-view.js +1 -26
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/change.d.ts +22 -20
- package/out/zql/src/ivm/change.d.ts.map +1 -1
- package/out/zql/src/ivm/exists.d.ts.map +1 -1
- package/out/zql/src/ivm/exists.js +38 -27
- package/out/zql/src/ivm/exists.js.map +1 -1
- package/out/zql/src/ivm/fan-in.d.ts +2 -3
- package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/fan-in.js.map +1 -1
- package/out/zql/src/ivm/fan-out.d.ts +1 -1
- package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
- package/out/zql/src/ivm/fan-out.js +1 -1
- package/out/zql/src/ivm/fan-out.js.map +1 -1
- package/out/zql/src/ivm/filter-operators.d.ts +3 -3
- package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
- package/out/zql/src/ivm/filter-operators.js.map +1 -1
- package/out/zql/src/ivm/filter-push.d.ts.map +1 -1
- package/out/zql/src/ivm/filter-push.js +7 -7
- package/out/zql/src/ivm/filter-push.js.map +1 -1
- package/out/zql/src/ivm/filter.d.ts +1 -1
- package/out/zql/src/ivm/filter.d.ts.map +1 -1
- package/out/zql/src/ivm/filter.js.map +1 -1
- package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
- package/out/zql/src/ivm/flipped-join.js +58 -49
- package/out/zql/src/ivm/flipped-join.js.map +1 -1
- package/out/zql/src/ivm/join-utils.d.ts +6 -2
- package/out/zql/src/ivm/join-utils.d.ts.map +1 -1
- package/out/zql/src/ivm/join-utils.js +25 -25
- package/out/zql/src/ivm/join-utils.js.map +1 -1
- package/out/zql/src/ivm/join.d.ts.map +1 -1
- package/out/zql/src/ivm/join.js +51 -32
- package/out/zql/src/ivm/join.js.map +1 -1
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +10 -5
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +59 -51
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/push-accumulated.d.ts +2 -3
- package/out/zql/src/ivm/push-accumulated.d.ts.map +1 -1
- package/out/zql/src/ivm/push-accumulated.js +122 -98
- package/out/zql/src/ivm/push-accumulated.js.map +1 -1
- package/out/zql/src/ivm/skip.d.ts +1 -1
- package/out/zql/src/ivm/skip.d.ts.map +1 -1
- package/out/zql/src/ivm/skip.js +2 -2
- package/out/zql/src/ivm/skip.js.map +1 -1
- package/out/zql/src/ivm/source.d.ts +13 -11
- package/out/zql/src/ivm/source.d.ts.map +1 -1
- package/out/zql/src/ivm/take.d.ts.map +1 -1
- package/out/zql/src/ivm/take.js +50 -27
- package/out/zql/src/ivm/take.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts +1 -2
- package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +3 -3
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-out.js +1 -1
- package/out/zql/src/ivm/union-fan-out.js.map +1 -1
- package/out/zql/src/planner/planner-debug.d.ts +2 -2
- package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
- package/out/zql/src/planner/planner-debug.js.map +1 -1
- package/out/zql/src/planner/planner-graph.d.ts +1 -1
- package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
- package/out/zql/src/planner/planner-graph.js.map +1 -1
- package/out/zqlite/src/internal/sql-inline.d.ts.map +1 -1
- package/out/zqlite/src/internal/sql-inline.js.map +1 -1
- package/out/zqlite/src/query-builder.d.ts.map +1 -1
- package/out/zqlite/src/query-builder.js.map +1 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +11 -11
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +93 -95
- package/out/zql/src/ivm/change-index-enum.d.ts +0 -9
- package/out/zql/src/ivm/change-index-enum.d.ts.map +0 -1
- package/out/zql/src/ivm/change-index.d.ts +0 -5
- package/out/zql/src/ivm/change-index.d.ts.map +0 -1
- package/out/zql/src/ivm/change-type-enum.d.ts +0 -9
- package/out/zql/src/ivm/change-type-enum.d.ts.map +0 -1
- package/out/zql/src/ivm/change-type.d.ts +0 -5
- package/out/zql/src/ivm/change-type.d.ts.map +0 -1
- package/out/zql/src/ivm/change.js +0 -33
- package/out/zql/src/ivm/change.js.map +0 -1
- package/out/zql/src/ivm/source-change-index-enum.d.ts +0 -7
- package/out/zql/src/ivm/source-change-index-enum.d.ts.map +0 -1
- package/out/zql/src/ivm/source-change-index.d.ts +0 -5
- package/out/zql/src/ivm/source-change-index.d.ts.map +0 -1
- package/out/zql/src/ivm/source.js +0 -26
- package/out/zql/src/ivm/source.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { assert, unreachable } from "../../../shared/src/asserts.js";
|
|
2
2
|
import { must } from "../../../shared/src/must.js";
|
|
3
3
|
import { emptyArray } from "../../../shared/src/sentinels.js";
|
|
4
|
-
import { makeAddChange, makeChildChange, makeEditChange, makeRemoveChange } from "./change.js";
|
|
5
4
|
//#region ../zql/src/ivm/push-accumulated.ts
|
|
6
5
|
/**
|
|
7
6
|
* # pushAccumulatedChanges
|
|
@@ -76,11 +75,11 @@ function* pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChange
|
|
|
76
75
|
if (accumulatedPushes.length === 0) return;
|
|
77
76
|
const candidatesToPush = /* @__PURE__ */ new Map();
|
|
78
77
|
for (const change of accumulatedPushes) {
|
|
79
|
-
if (fanOutChangeType ===
|
|
80
|
-
const existing = candidatesToPush.get(change
|
|
78
|
+
if (fanOutChangeType === "child" && change.type !== "child") assert(candidatesToPush.has(change.type) === false, () => `Fan-in:child expected at most one ${change.type} when fan-out is of type child`);
|
|
79
|
+
const existing = candidatesToPush.get(change.type);
|
|
81
80
|
let mergedChange = change;
|
|
82
81
|
if (existing) mergedChange = mergeRelationships(existing, change);
|
|
83
|
-
candidatesToPush.set(change
|
|
82
|
+
candidatesToPush.set(change.type, mergedChange);
|
|
84
83
|
}
|
|
85
84
|
accumulatedPushes.length = 0;
|
|
86
85
|
const types = [...candidatesToPush.keys()];
|
|
@@ -95,19 +94,19 @@ function* pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChange
|
|
|
95
94
|
* - Many child changes because other operators may preserve the child change
|
|
96
95
|
*/
|
|
97
96
|
switch (fanOutChangeType) {
|
|
98
|
-
case
|
|
99
|
-
assert(types.length === 1 && types[0] ===
|
|
100
|
-
yield* output.push(addEmptyRelationships(must(candidatesToPush.get(
|
|
97
|
+
case "remove":
|
|
98
|
+
assert(types.length === 1 && types[0] === "remove", "Fan-in:remove expected all removes");
|
|
99
|
+
yield* output.push(addEmptyRelationships(must(candidatesToPush.get("remove"))), pusher);
|
|
101
100
|
return;
|
|
102
|
-
case
|
|
103
|
-
assert(types.length === 1 && types[0] ===
|
|
104
|
-
yield* output.push(addEmptyRelationships(must(candidatesToPush.get(
|
|
101
|
+
case "add":
|
|
102
|
+
assert(types.length === 1 && types[0] === "add", "Fan-in:add expected all adds");
|
|
103
|
+
yield* output.push(addEmptyRelationships(must(candidatesToPush.get("add"))), pusher);
|
|
105
104
|
return;
|
|
106
|
-
case
|
|
107
|
-
assert(types.every((type) => type ===
|
|
108
|
-
const addChange = candidatesToPush.get(
|
|
109
|
-
const removeChange = candidatesToPush.get(
|
|
110
|
-
let editChange = candidatesToPush.get(
|
|
105
|
+
case "edit": {
|
|
106
|
+
assert(types.every((type) => type === "add" || type === "remove" || type === "edit"), "Fan-in:edit expected all adds, removes, or edits");
|
|
107
|
+
const addChange = candidatesToPush.get("add");
|
|
108
|
+
const removeChange = candidatesToPush.get("remove");
|
|
109
|
+
let editChange = candidatesToPush.get("edit");
|
|
111
110
|
if (editChange) {
|
|
112
111
|
if (addChange) editChange = mergeRelationships(editChange, addChange);
|
|
113
112
|
if (removeChange) editChange = mergeRelationships(editChange, removeChange);
|
|
@@ -115,22 +114,26 @@ function* pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChange
|
|
|
115
114
|
return;
|
|
116
115
|
}
|
|
117
116
|
if (addChange && removeChange) {
|
|
118
|
-
yield* output.push(addEmptyRelationships(
|
|
117
|
+
yield* output.push(addEmptyRelationships({
|
|
118
|
+
type: "edit",
|
|
119
|
+
node: addChange.node,
|
|
120
|
+
oldNode: removeChange.node
|
|
121
|
+
}), pusher);
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
121
124
|
yield* output.push(addEmptyRelationships(must(addChange ?? removeChange)), pusher);
|
|
122
125
|
return;
|
|
123
126
|
}
|
|
124
|
-
case
|
|
125
|
-
assert(types.every((type) => type ===
|
|
127
|
+
case "child": {
|
|
128
|
+
assert(types.every((type) => type === "add" || type === "remove" || type === "child"), "Fan-in:child expected all adds, removes, or children");
|
|
126
129
|
assert(types.length <= 2, "Fan-in:child expected at most 2 types on a child change from fan-out");
|
|
127
|
-
const childChange = candidatesToPush.get(
|
|
130
|
+
const childChange = candidatesToPush.get("child");
|
|
128
131
|
if (childChange) {
|
|
129
132
|
yield* output.push(childChange, pusher);
|
|
130
133
|
return;
|
|
131
134
|
}
|
|
132
|
-
const addChange = candidatesToPush.get(
|
|
133
|
-
const removeChange = candidatesToPush.get(
|
|
135
|
+
const addChange = candidatesToPush.get("add");
|
|
136
|
+
const removeChange = candidatesToPush.get("remove");
|
|
134
137
|
assert(addChange === void 0 || removeChange === void 0, "Fan-in:child expected either add or remove, not both");
|
|
135
138
|
yield* output.push(addEmptyRelationships(must(addChange ?? removeChange)), pusher);
|
|
136
139
|
return;
|
|
@@ -142,99 +145,120 @@ function* pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChange
|
|
|
142
145
|
* Puts relationships from `right` into `left` if they don't already exist in `left`.
|
|
143
146
|
*/
|
|
144
147
|
function mergeRelationships(left, right) {
|
|
145
|
-
if (left
|
|
146
|
-
case
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
row: left[1].row,
|
|
155
|
-
relationships: {
|
|
156
|
-
...right[1].relationships,
|
|
157
|
-
...left[1].relationships
|
|
148
|
+
if (left.type === right.type) switch (left.type) {
|
|
149
|
+
case "add": return {
|
|
150
|
+
type: "add",
|
|
151
|
+
node: {
|
|
152
|
+
row: left.node.row,
|
|
153
|
+
relationships: {
|
|
154
|
+
...right.node.relationships,
|
|
155
|
+
...left.node.relationships
|
|
156
|
+
}
|
|
158
157
|
}
|
|
159
|
-
}
|
|
160
|
-
case
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
row: left
|
|
158
|
+
};
|
|
159
|
+
case "remove": return {
|
|
160
|
+
type: "remove",
|
|
161
|
+
node: {
|
|
162
|
+
row: left.node.row,
|
|
164
163
|
relationships: {
|
|
165
|
-
...right
|
|
166
|
-
...left
|
|
164
|
+
...right.node.relationships,
|
|
165
|
+
...left.node.relationships
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
case "edit":
|
|
170
|
+
assert(right.type === "edit", () => `mergeRelationships: when left.type is edit and types match, right.type must be edit, got ${right.type}`);
|
|
171
|
+
return {
|
|
172
|
+
type: "edit",
|
|
173
|
+
node: {
|
|
174
|
+
row: left.node.row,
|
|
175
|
+
relationships: {
|
|
176
|
+
...right.node.relationships,
|
|
177
|
+
...left.node.relationships
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
oldNode: {
|
|
181
|
+
row: left.oldNode.row,
|
|
182
|
+
relationships: {
|
|
183
|
+
...right.oldNode.relationships,
|
|
184
|
+
...left.oldNode.relationships
|
|
185
|
+
}
|
|
167
186
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
187
|
+
};
|
|
188
|
+
case "child":
|
|
189
|
+
assert(right.type === "child", () => `mergeRelationships: when left.type is child and types match, right.type must be child, got ${right.type}`);
|
|
190
|
+
return {
|
|
191
|
+
type: "child",
|
|
192
|
+
node: {
|
|
193
|
+
row: left.node.row,
|
|
194
|
+
relationships: {
|
|
195
|
+
...right.node.relationships,
|
|
196
|
+
...left.node.relationships
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
child: left.child
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
assert(left.type === "edit", () => `mergeRelationships: when types differ, left.type must be edit, got left.type=${left.type}, right.type=${right.type}`);
|
|
203
|
+
switch (right.type) {
|
|
204
|
+
case "add": return {
|
|
205
|
+
type: "edit",
|
|
206
|
+
node: {
|
|
207
|
+
...left.node,
|
|
170
208
|
relationships: {
|
|
171
|
-
...right
|
|
172
|
-
...left
|
|
209
|
+
...right.node.relationships,
|
|
210
|
+
...left.node.relationships
|
|
173
211
|
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
212
|
+
},
|
|
213
|
+
oldNode: left.oldNode
|
|
214
|
+
};
|
|
215
|
+
case "remove": return {
|
|
216
|
+
type: "edit",
|
|
217
|
+
node: left.node,
|
|
218
|
+
oldNode: {
|
|
219
|
+
...left.oldNode,
|
|
179
220
|
relationships: {
|
|
180
|
-
...right
|
|
181
|
-
...left
|
|
221
|
+
...right.node.relationships,
|
|
222
|
+
...left.oldNode.relationships
|
|
182
223
|
}
|
|
183
|
-
}, left[2]);
|
|
184
|
-
}
|
|
185
|
-
assert(left[0] === 2, () => `mergeRelationships: when types differ, left.type must be edit, got left.type=${left[0]}, right.type=${right[0]}`);
|
|
186
|
-
switch (right[0]) {
|
|
187
|
-
case 0: return makeEditChange({
|
|
188
|
-
...left[1],
|
|
189
|
-
relationships: {
|
|
190
|
-
...right[1].relationships,
|
|
191
|
-
...left[1].relationships
|
|
192
224
|
}
|
|
193
|
-
}
|
|
194
|
-
case 1: return makeEditChange(left[1], {
|
|
195
|
-
...left[2],
|
|
196
|
-
relationships: {
|
|
197
|
-
...right[1].relationships,
|
|
198
|
-
...left[2].relationships
|
|
199
|
-
}
|
|
200
|
-
});
|
|
225
|
+
};
|
|
201
226
|
}
|
|
202
227
|
unreachable();
|
|
203
228
|
}
|
|
204
229
|
function makeAddEmptyRelationships(schema) {
|
|
205
230
|
return (change) => {
|
|
206
231
|
if (Object.keys(schema.relationships).length === 0) return change;
|
|
207
|
-
switch (change
|
|
208
|
-
case
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return makeRemoveChange({
|
|
220
|
-
row: change[1].row,
|
|
221
|
-
relationships
|
|
222
|
-
});
|
|
232
|
+
switch (change.type) {
|
|
233
|
+
case "add":
|
|
234
|
+
case "remove": {
|
|
235
|
+
const ret = {
|
|
236
|
+
...change,
|
|
237
|
+
node: {
|
|
238
|
+
...change.node,
|
|
239
|
+
relationships: { ...change.node.relationships }
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
mergeEmpty(ret.node.relationships, Object.keys(schema.relationships));
|
|
243
|
+
return ret;
|
|
223
244
|
}
|
|
224
|
-
case
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
245
|
+
case "edit": {
|
|
246
|
+
const ret = {
|
|
247
|
+
...change,
|
|
248
|
+
node: {
|
|
249
|
+
...change.node,
|
|
250
|
+
relationships: { ...change.node.relationships }
|
|
251
|
+
},
|
|
252
|
+
oldNode: {
|
|
253
|
+
...change.oldNode,
|
|
254
|
+
relationships: { ...change.oldNode.relationships }
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
mergeEmpty(ret.node.relationships, Object.keys(schema.relationships));
|
|
258
|
+
mergeEmpty(ret.oldNode.relationships, Object.keys(schema.relationships));
|
|
259
|
+
return ret;
|
|
236
260
|
}
|
|
237
|
-
case
|
|
261
|
+
case "child": return change;
|
|
238
262
|
}
|
|
239
263
|
};
|
|
240
264
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-accumulated.js","names":[],"sources":["../../../../../zql/src/ivm/push-accumulated.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyArray} from '../../../shared/src/sentinels.ts';\nimport {ChangeIndex} from './change-index.ts';\nimport {ChangeType} from './change-type.ts';\nimport {\n makeAddChange,\n makeChildChange,\n makeEditChange,\n makeRemoveChange,\n type Change,\n} from './change.ts';\nimport type {Node} from './data.ts';\nimport type {InputBase, Output} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * # pushAccumulatedChanges\n *\n * Pushes the changes that were accumulated by\n * [fan-out, fan-in] or [ufo, ufi] sub-graphs.\n *\n * This function is called at the end of the sub-graph.\n *\n * The sub-graphs represents `OR`s.\n *\n * Changes that can enter the subgraphs:\n * 1. child (due to exist joins being above the sub-graph)\n * 2. add\n * 3. remove\n * 4. edit\n *\n * # Changes that can exit into `pushAccumulatedChanges`:\n *\n * ## Child\n * If a `child` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `child` change\n * - stop the `child` change (e.g., filter)\n * - convert it to an `add` or `remove` (e.g., exists filter)\n *\n * ## Add\n * If an `add` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `add` change\n * - hide the change (e.g., filter)\n *\n * ## Remove\n * If a `remove` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `remove` change\n * - hide the change (e.g., filter)\n *\n * ## Edit\n * If an `edit` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `edit` change\n * - convert it to an `add` (e.g., filter where old didn't match but new does)\n * - convert it to a `remove` (e.g., filter where old matched but new doesn't)\n *\n * This results in some invariants:\n * - an add coming in will only create adds coming out\n * - a remove coming in will only create removes coming out\n * - an edit coming in can create adds, removes, and edits coming out\n * - a child coming in can create adds, removes, and children coming out\n *\n * # Return of `pushAccumulatedChanges`\n *\n * This function will only push a single change.\n * Given the above invariants, how is this possible?\n *\n * An add that becomes many `adds` results in a single add\n * as the `add` is the same row across all adds. Branches do not change the row.\n *\n * A remove that becomes many `removes` results in a single remove\n * for the same reason.\n *\n * If a child enters and exits, it takes precedence over all other changes.\n * If a child enters and is converted only to add and remove it exits as an edit.\n * If a child enters and is converted to only add or only remove, it exits as that change.\n *\n * If an edit enters and is converted to add and remove it exits as an edit.\n * If an edit enters and is converted to only add or only remove, it exits as that change.\n * If an edit enters and exits as edits only, it exits as a single edit.\n */\nexport function* pushAccumulatedChanges(\n accumulatedPushes: Change[],\n output: Output,\n pusher: InputBase,\n fanOutChangeType: ChangeType,\n mergeRelationships: (existing: Change, incoming: Change) => Change,\n addEmptyRelationships: (change: Change) => Change,\n): Stream<'yield'> {\n if (accumulatedPushes.length === 0) {\n // It is possible for no forks to pass along the push.\n // E.g., if no filters match in any fork.\n return;\n }\n\n // collapse down to a single change per type\n const candidatesToPush = new Map<ChangeType, Change>();\n for (const change of accumulatedPushes) {\n if (\n fanOutChangeType === ChangeType.CHILD &&\n change[ChangeIndex.TYPE] !== ChangeType.CHILD\n ) {\n assert(\n candidatesToPush.has(change[ChangeIndex.TYPE]) === false,\n () =>\n `Fan-in:child expected at most one ${change[ChangeIndex.TYPE]} when fan-out is of type child`,\n );\n }\n\n const existing = candidatesToPush.get(change[ChangeIndex.TYPE]);\n let mergedChange = change;\n if (existing) {\n // merge in relationships\n mergedChange = mergeRelationships(existing, change);\n }\n candidatesToPush.set(change[ChangeIndex.TYPE], mergedChange);\n }\n\n accumulatedPushes.length = 0;\n\n const types = [...candidatesToPush.keys()];\n /**\n * Based on the received `fanOutChangeType` only certain output types are valid.\n *\n * - remove must result in all removes\n * - add must result in all adds\n * - edit must result in add or removes or edits\n * - child must result in a single add or single remove or many child changes\n * - Single add or remove because the relationship will be unique to one exist check within the fan-out,fan-in sub-graph\n * - Many child changes because other operators may preserve the child change\n */\n switch (fanOutChangeType) {\n case ChangeType.REMOVE:\n assert(\n types.length === 1 && types[0] === ChangeType.REMOVE,\n 'Fan-in:remove expected all removes',\n );\n yield* output.push(\n addEmptyRelationships(must(candidatesToPush.get(ChangeType.REMOVE))),\n pusher,\n );\n return;\n case ChangeType.ADD:\n assert(\n types.length === 1 && types[0] === ChangeType.ADD,\n 'Fan-in:add expected all adds',\n );\n yield* output.push(\n addEmptyRelationships(must(candidatesToPush.get(ChangeType.ADD))),\n pusher,\n );\n return;\n case ChangeType.EDIT: {\n assert(\n types.every(\n type =>\n type === ChangeType.ADD ||\n type === ChangeType.REMOVE ||\n type === ChangeType.EDIT,\n ),\n 'Fan-in:edit expected all adds, removes, or edits',\n );\n const addChange = candidatesToPush.get(ChangeType.ADD);\n const removeChange = candidatesToPush.get(ChangeType.REMOVE);\n let editChange = candidatesToPush.get(ChangeType.EDIT);\n\n // If an `edit` is present, it supersedes `add` and `remove`\n // as it semantically represents both.\n if (editChange) {\n if (addChange) {\n editChange = mergeRelationships(editChange, addChange);\n }\n if (removeChange) {\n editChange = mergeRelationships(editChange, removeChange);\n }\n yield* output.push(addEmptyRelationships(editChange), pusher);\n return;\n }\n\n // If `edit` didn't make it through but both `add` and `remove` did,\n // convert back to an edit.\n //\n // When can this happen?\n //\n // EDIT old: a=1, new: a=2\n // |\n // FanOut\n // / \\\n // a=1 a=2\n // | |\n // remove add\n // \\ /\n // FanIn\n //\n // The left filter converts the edit into a remove.\n // The right filter converts the edit into an add.\n if (addChange && removeChange) {\n yield* output.push(\n addEmptyRelationships(\n makeEditChange(\n addChange[ChangeIndex.NODE],\n removeChange[ChangeIndex.NODE],\n ),\n ),\n pusher,\n );\n return;\n }\n\n yield* output.push(\n addEmptyRelationships(must(addChange ?? removeChange)),\n pusher,\n );\n return;\n }\n case ChangeType.CHILD: {\n assert(\n types.every(\n type =>\n type === ChangeType.ADD || // exists can change child to add or remove\n type === ChangeType.REMOVE || // exists can change child to add or remove\n type === ChangeType.CHILD, // other operators may preserve the child change\n ),\n 'Fan-in:child expected all adds, removes, or children',\n );\n assert(\n types.length <= 2,\n 'Fan-in:child expected at most 2 types on a child change from fan-out',\n );\n\n // If any branch preserved the original child change, that takes precedence over all other changes.\n const childChange = candidatesToPush.get(ChangeType.CHILD);\n if (childChange) {\n yield* output.push(childChange, pusher);\n return;\n }\n\n const addChange = candidatesToPush.get(ChangeType.ADD);\n const removeChange = candidatesToPush.get(ChangeType.REMOVE);\n\n assert(\n addChange === undefined || removeChange === undefined,\n 'Fan-in:child expected either add or remove, not both',\n );\n\n yield* output.push(\n addEmptyRelationships(must(addChange ?? removeChange)),\n pusher,\n );\n return;\n }\n default:\n fanOutChangeType satisfies never;\n }\n}\n\n/**\n * Puts relationships from `right` into `left` if they don't already exist in `left`.\n */\nexport function mergeRelationships(left: Change, right: Change): Change {\n // change types will always match\n // unless we have an edit on the left\n // then the right could be edit, add, or remove\n if (left[ChangeIndex.TYPE] === right[ChangeIndex.TYPE]) {\n switch (left[ChangeIndex.TYPE]) {\n case ChangeType.ADD: {\n return makeAddChange({\n row: left[ChangeIndex.NODE].row,\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.NODE].relationships,\n },\n });\n }\n case ChangeType.REMOVE: {\n return makeRemoveChange({\n row: left[ChangeIndex.NODE].row,\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.NODE].relationships,\n },\n });\n }\n case ChangeType.EDIT: {\n assert(\n right[ChangeIndex.TYPE] === ChangeType.EDIT,\n () =>\n `mergeRelationships: when left.type is edit and types match, right.type must be edit, got ${right[ChangeIndex.TYPE]}`,\n );\n // merge edits into a single edit\n return makeEditChange(\n {\n row: left[ChangeIndex.NODE].row,\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.NODE].relationships,\n },\n },\n {\n row: left[ChangeIndex.OLD_NODE].row,\n relationships: {\n ...right[ChangeIndex.OLD_NODE].relationships,\n ...left[ChangeIndex.OLD_NODE].relationships,\n },\n },\n );\n }\n case ChangeType.CHILD: {\n // Multiple branches may preserve the same child change, each adding\n // different relationships. Merge the relationships, keeping the child\n // (which should be identical across branches).\n assert(\n right[ChangeIndex.TYPE] === ChangeType.CHILD,\n () =>\n `mergeRelationships: when left.type is child and types match, right.type must be child, got ${right[ChangeIndex.TYPE]}`,\n );\n return makeChildChange(\n {\n row: left[ChangeIndex.NODE].row,\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.NODE].relationships,\n },\n },\n left[ChangeIndex.CHILD_DATA],\n );\n }\n }\n }\n\n // left is always an edit here\n assert(\n left[ChangeIndex.TYPE] === ChangeType.EDIT,\n () =>\n `mergeRelationships: when types differ, left.type must be edit, got left.type=${left[ChangeIndex.TYPE]}, right.type=${right[ChangeIndex.TYPE]}`,\n );\n switch (right[ChangeIndex.TYPE]) {\n case ChangeType.ADD: {\n return makeEditChange(\n {\n ...left[ChangeIndex.NODE],\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.NODE].relationships,\n },\n },\n left[ChangeIndex.OLD_NODE],\n );\n }\n case ChangeType.REMOVE: {\n return makeEditChange(left[ChangeIndex.NODE], {\n ...left[ChangeIndex.OLD_NODE],\n relationships: {\n ...right[ChangeIndex.NODE].relationships,\n ...left[ChangeIndex.OLD_NODE].relationships,\n },\n });\n }\n }\n\n unreachable();\n}\n\nexport function makeAddEmptyRelationships(\n schema: SourceSchema,\n): (change: Change) => Change {\n return (change: Change): Change => {\n if (Object.keys(schema.relationships).length === 0) {\n return change;\n }\n\n switch (change[ChangeIndex.TYPE]) {\n case ChangeType.ADD: {\n const relationships = {...change[ChangeIndex.NODE].relationships};\n mergeEmpty(relationships, Object.keys(schema.relationships));\n return makeAddChange({\n row: change[ChangeIndex.NODE].row,\n relationships,\n });\n }\n case ChangeType.REMOVE: {\n const relationships = {...change[ChangeIndex.NODE].relationships};\n mergeEmpty(relationships, Object.keys(schema.relationships));\n return makeRemoveChange({\n row: change[ChangeIndex.NODE].row,\n relationships,\n });\n }\n case ChangeType.EDIT: {\n const nodeRelationships = {...change[ChangeIndex.NODE].relationships};\n const oldNodeRelationships = {\n ...change[ChangeIndex.OLD_NODE].relationships,\n };\n mergeEmpty(nodeRelationships, Object.keys(schema.relationships));\n mergeEmpty(oldNodeRelationships, Object.keys(schema.relationships));\n return makeEditChange(\n {row: change[ChangeIndex.NODE].row, relationships: nodeRelationships},\n {\n row: change[ChangeIndex.OLD_NODE].row,\n relationships: oldNodeRelationships,\n },\n );\n }\n case ChangeType.CHILD:\n return change; // children only have relationships along the path to the change\n }\n };\n}\n\n/**\n * For each relationship in `schema` that does not exist\n * in `relationships`, add it with an empty stream.\n *\n * This modifies the `relationships` object in place.\n */\nexport function mergeEmpty(\n relationships: Record<string, () => Stream<Node | 'yield'>>,\n relationshipNames: string[],\n) {\n for (const relName of relationshipNames) {\n if (relationships[relName] === undefined) {\n relationships[relName] = () => emptyArray;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,UAAiB,uBACf,mBACA,QACA,QACA,kBACA,oBACA,uBACiB;AACjB,KAAI,kBAAkB,WAAW,EAG/B;CAIF,MAAM,mCAAmB,IAAI,KAAyB;AACtD,MAAK,MAAM,UAAU,mBAAmB;AACtC,MACE,qBAAqB,KACrB,OAAO,OAAsB,EAE7B,QACE,iBAAiB,IAAI,OAAO,GAAkB,KAAK,aAEjD,qCAAqC,OAAO,GAAkB,gCACjE;EAGH,MAAM,WAAW,iBAAiB,IAAI,OAAO,GAAkB;EAC/D,IAAI,eAAe;AACnB,MAAI,SAEF,gBAAe,mBAAmB,UAAU,OAAO;AAErD,mBAAiB,IAAI,OAAO,IAAmB,aAAa;;AAG9D,mBAAkB,SAAS;CAE3B,MAAM,QAAQ,CAAC,GAAG,iBAAiB,MAAM,CAAC;;;;;;;;;;;AAW1C,SAAQ,kBAAR;EACE,KAAK;AACH,UACE,MAAM,WAAW,KAAK,MAAM,OAAO,GACnC,qCACD;AACD,UAAO,OAAO,KACZ,sBAAsB,KAA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SAAQ,WAA2B;AACjC,MAAI,OAAO,KAAK,OAAO,cAAc,CAAC,WAAW,EAC/C,QAAO;AAGT,UAAQ,OAAO,IAAf;GACE,KAAK,GAAgB;IACnB,MAAM,gBAAgB,EAAC,GAAG,OAAO,GAAkB,eAAc;AACjE,eAAW,eAAe,OAAO,KAAK,OAAO,cAAc,CAAC;AAC5D,WAAO,cAAc;KACnB,KAAK,OAAO,GAAkB;KAC9B;KACD,CAAC;;GAEJ,KAAK,GAAmB;IACtB,MAAM,gBAAgB,EAAC,GAAG,OAAO,GAAkB,eAAc;AACjE,eAAW,eAAe,OAAO,KAAK,OAAO,cAAc,CAAC;AAC5D,WAAO,iBAAiB;KACtB,KAAK,OAAO,GAAkB;KAC9B;KACD,CAAC;;GAEJ,KAAK,GAAiB;IACpB,MAAM,oBAAoB,EAAC,GAAG,OAAO,GAAkB,eAAc;IACrE,MAAM,uBAAuB,EAC3B,GAAG,OAAO,GAAsB,eACjC;AACD,eAAW,mBAAmB,OAAO,KAAK,OAAO,cAAc,CAAC;AAChE,eAAW,sBAAsB,OAAO,KAAK,OAAO,cAAc,CAAC;AACnE,WAAO,eACL;KAAC,KAAK,OAAO,GAAkB;KAAK,eAAe;KAAkB,EACrE;KACE,KAAK,OAAO,GAAsB;KAClC,eAAe;KAChB,CACF;;GAEH,KAAK,EACH,QAAO;;;;;;;;;;AAWf,SAAgB,WACd,eACA,mBACA;AACA,MAAK,MAAM,WAAW,kBACpB,KAAI,cAAc,aAAa,KAAA,EAC7B,eAAc,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"push-accumulated.js","names":[],"sources":["../../../../../zql/src/ivm/push-accumulated.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyArray} from '../../../shared/src/sentinels.ts';\nimport type {Change} from './change.ts';\nimport type {Node} from './data.ts';\nimport type {InputBase, Output} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * # pushAccumulatedChanges\n *\n * Pushes the changes that were accumulated by\n * [fan-out, fan-in] or [ufo, ufi] sub-graphs.\n *\n * This function is called at the end of the sub-graph.\n *\n * The sub-graphs represents `OR`s.\n *\n * Changes that can enter the subgraphs:\n * 1. child (due to exist joins being above the sub-graph)\n * 2. add\n * 3. remove\n * 4. edit\n *\n * # Changes that can exit into `pushAccumulatedChanges`:\n *\n * ## Child\n * If a `child` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `child` change\n * - stop the `child` change (e.g., filter)\n * - convert it to an `add` or `remove` (e.g., exists filter)\n *\n * ## Add\n * If an `add` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `add` change\n * - hide the change (e.g., filter)\n *\n * ## Remove\n * If a `remove` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `remove` change\n * - hide the change (e.g., filter)\n *\n * ## Edit\n * If an `edit` change enters a sub-graph, it will flow to all branches.\n * Each branch will either:\n * - preserve the `edit` change\n * - convert it to an `add` (e.g., filter where old didn't match but new does)\n * - convert it to a `remove` (e.g., filter where old matched but new doesn't)\n *\n * This results in some invariants:\n * - an add coming in will only create adds coming out\n * - a remove coming in will only create removes coming out\n * - an edit coming in can create adds, removes, and edits coming out\n * - a child coming in can create adds, removes, and children coming out\n *\n * # Return of `pushAccumulatedChanges`\n *\n * This function will only push a single change.\n * Given the above invariants, how is this possible?\n *\n * An add that becomes many `adds` results in a single add\n * as the `add` is the same row across all adds. Branches do not change the row.\n *\n * A remove that becomes many `removes` results in a single remove\n * for the same reason.\n *\n * If a child enters and exits, it takes precedence over all other changes.\n * If a child enters and is converted only to add and remove it exits as an edit.\n * If a child enters and is converted to only add or only remove, it exits as that change.\n *\n * If an edit enters and is converted to add and remove it exits as an edit.\n * If an edit enters and is converted to only add or only remove, it exits as that change.\n * If an edit enters and exits as edits only, it exits as a single edit.\n */\nexport function* pushAccumulatedChanges(\n accumulatedPushes: Change[],\n output: Output,\n pusher: InputBase,\n fanOutChangeType: Change['type'],\n mergeRelationships: (existing: Change, incoming: Change) => Change,\n addEmptyRelationships: (change: Change) => Change,\n): Stream<'yield'> {\n if (accumulatedPushes.length === 0) {\n // It is possible for no forks to pass along the push.\n // E.g., if no filters match in any fork.\n return;\n }\n\n // collapse down to a single change per type\n const candidatesToPush = new Map<Change['type'], Change>();\n for (const change of accumulatedPushes) {\n if (fanOutChangeType === 'child' && change.type !== 'child') {\n assert(\n candidatesToPush.has(change.type) === false,\n () =>\n `Fan-in:child expected at most one ${change.type} when fan-out is of type child`,\n );\n }\n\n const existing = candidatesToPush.get(change.type);\n let mergedChange = change;\n if (existing) {\n // merge in relationships\n mergedChange = mergeRelationships(existing, change);\n }\n candidatesToPush.set(change.type, mergedChange);\n }\n\n accumulatedPushes.length = 0;\n\n const types = [...candidatesToPush.keys()];\n /**\n * Based on the received `fanOutChangeType` only certain output types are valid.\n *\n * - remove must result in all removes\n * - add must result in all adds\n * - edit must result in add or removes or edits\n * - child must result in a single add or single remove or many child changes\n * - Single add or remove because the relationship will be unique to one exist check within the fan-out,fan-in sub-graph\n * - Many child changes because other operators may preserve the child change\n */\n switch (fanOutChangeType) {\n case 'remove':\n assert(\n types.length === 1 && types[0] === 'remove',\n 'Fan-in:remove expected all removes',\n );\n yield* output.push(\n addEmptyRelationships(must(candidatesToPush.get('remove'))),\n pusher,\n );\n return;\n case 'add':\n assert(\n types.length === 1 && types[0] === 'add',\n 'Fan-in:add expected all adds',\n );\n yield* output.push(\n addEmptyRelationships(must(candidatesToPush.get('add'))),\n pusher,\n );\n return;\n case 'edit': {\n assert(\n types.every(\n type => type === 'add' || type === 'remove' || type === 'edit',\n ),\n 'Fan-in:edit expected all adds, removes, or edits',\n );\n const addChange = candidatesToPush.get('add');\n const removeChange = candidatesToPush.get('remove');\n let editChange = candidatesToPush.get('edit');\n\n // If an `edit` is present, it supersedes `add` and `remove`\n // as it semantically represents both.\n if (editChange) {\n if (addChange) {\n editChange = mergeRelationships(editChange, addChange);\n }\n if (removeChange) {\n editChange = mergeRelationships(editChange, removeChange);\n }\n yield* output.push(addEmptyRelationships(editChange), pusher);\n return;\n }\n\n // If `edit` didn't make it through but both `add` and `remove` did,\n // convert back to an edit.\n //\n // When can this happen?\n //\n // EDIT old: a=1, new: a=2\n // |\n // FanOut\n // / \\\n // a=1 a=2\n // | |\n // remove add\n // \\ /\n // FanIn\n //\n // The left filter converts the edit into a remove.\n // The right filter converts the edit into an add.\n if (addChange && removeChange) {\n yield* output.push(\n addEmptyRelationships({\n type: 'edit',\n node: addChange.node,\n oldNode: removeChange.node,\n } as const),\n pusher,\n );\n return;\n }\n\n yield* output.push(\n addEmptyRelationships(must(addChange ?? removeChange)),\n pusher,\n );\n return;\n }\n case 'child': {\n assert(\n types.every(\n type =>\n type === 'add' || // exists can change child to add or remove\n type === 'remove' || // exists can change child to add or remove\n type === 'child', // other operators may preserve the child change\n ),\n 'Fan-in:child expected all adds, removes, or children',\n );\n assert(\n types.length <= 2,\n 'Fan-in:child expected at most 2 types on a child change from fan-out',\n );\n\n // If any branch preserved the original child change, that takes precedence over all other changes.\n const childChange = candidatesToPush.get('child');\n if (childChange) {\n yield* output.push(childChange, pusher);\n return;\n }\n\n const addChange = candidatesToPush.get('add');\n const removeChange = candidatesToPush.get('remove');\n\n assert(\n addChange === undefined || removeChange === undefined,\n 'Fan-in:child expected either add or remove, not both',\n );\n\n yield* output.push(\n addEmptyRelationships(must(addChange ?? removeChange)),\n pusher,\n );\n return;\n }\n default:\n fanOutChangeType satisfies never;\n }\n}\n\n/**\n * Puts relationships from `right` into `left` if they don't already exist in `left`.\n */\nexport function mergeRelationships(left: Change, right: Change): Change {\n // change types will always match\n // unless we have an edit on the left\n // then the right could be edit, add, or remove\n if (left.type === right.type) {\n switch (left.type) {\n case 'add': {\n return {\n type: 'add',\n node: {\n row: left.node.row,\n relationships: {\n ...right.node.relationships,\n ...left.node.relationships,\n },\n },\n };\n }\n case 'remove': {\n return {\n type: 'remove',\n node: {\n row: left.node.row,\n relationships: {\n ...right.node.relationships,\n ...left.node.relationships,\n },\n },\n };\n }\n case 'edit': {\n assert(\n right.type === 'edit',\n () =>\n `mergeRelationships: when left.type is edit and types match, right.type must be edit, got ${right.type}`,\n );\n // merge edits into a single edit\n return {\n type: 'edit',\n node: {\n row: left.node.row,\n relationships: {\n ...right.node.relationships,\n ...left.node.relationships,\n },\n },\n oldNode: {\n row: left.oldNode.row,\n relationships: {\n ...right.oldNode.relationships,\n ...left.oldNode.relationships,\n },\n },\n };\n }\n case 'child': {\n // Multiple branches may preserve the same child change, each adding\n // different relationships. Merge the relationships, keeping the child\n // (which should be identical across branches).\n assert(\n right.type === 'child',\n () =>\n `mergeRelationships: when left.type is child and types match, right.type must be child, got ${right.type}`,\n );\n return {\n type: 'child',\n node: {\n row: left.node.row,\n relationships: {\n ...right.node.relationships,\n ...left.node.relationships,\n },\n },\n child: left.child,\n };\n }\n }\n }\n\n // left is always an edit here\n assert(\n left.type === 'edit',\n () =>\n `mergeRelationships: when types differ, left.type must be edit, got left.type=${left.type}, right.type=${right.type}`,\n );\n switch (right.type) {\n case 'add': {\n return {\n type: 'edit',\n node: {\n ...left.node,\n relationships: {\n ...right.node.relationships,\n ...left.node.relationships,\n },\n },\n oldNode: left.oldNode,\n };\n }\n case 'remove': {\n return {\n type: 'edit',\n node: left.node,\n oldNode: {\n ...left.oldNode,\n relationships: {\n ...right.node.relationships,\n ...left.oldNode.relationships,\n },\n },\n };\n }\n }\n\n unreachable();\n}\n\nexport function makeAddEmptyRelationships(\n schema: SourceSchema,\n): (change: Change) => Change {\n return (change: Change): Change => {\n if (Object.keys(schema.relationships).length === 0) {\n return change;\n }\n\n switch (change.type) {\n case 'add':\n case 'remove': {\n const ret = {\n ...change,\n node: {\n ...change.node,\n relationships: {\n ...change.node.relationships,\n },\n },\n };\n\n mergeEmpty(ret.node.relationships, Object.keys(schema.relationships));\n\n return ret;\n }\n case 'edit': {\n const ret = {\n ...change,\n node: {\n ...change.node,\n relationships: {\n ...change.node.relationships,\n },\n },\n oldNode: {\n ...change.oldNode,\n relationships: {\n ...change.oldNode.relationships,\n },\n },\n };\n\n mergeEmpty(ret.node.relationships, Object.keys(schema.relationships));\n mergeEmpty(\n ret.oldNode.relationships,\n Object.keys(schema.relationships),\n );\n\n return ret;\n }\n case 'child':\n return change; // children only have relationships along the path to the change\n }\n };\n}\n\n/**\n * For each relationship in `schema` that does not exist\n * in `relationships`, add it with an empty stream.\n *\n * This modifies the `relationships` object in place.\n */\nexport function mergeEmpty(\n relationships: Record<string, () => Stream<Node | 'yield'>>,\n relationshipNames: string[],\n) {\n for (const relName of relationshipNames) {\n if (relationships[relName] === undefined) {\n relationships[relName] = () => emptyArray;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,UAAiB,uBACf,mBACA,QACA,QACA,kBACA,oBACA,uBACiB;AACjB,KAAI,kBAAkB,WAAW,EAG/B;CAIF,MAAM,mCAAmB,IAAI,KAA6B;AAC1D,MAAK,MAAM,UAAU,mBAAmB;AACtC,MAAI,qBAAqB,WAAW,OAAO,SAAS,QAClD,QACE,iBAAiB,IAAI,OAAO,KAAK,KAAK,aAEpC,qCAAqC,OAAO,KAAK,gCACpD;EAGH,MAAM,WAAW,iBAAiB,IAAI,OAAO,KAAK;EAClD,IAAI,eAAe;AACnB,MAAI,SAEF,gBAAe,mBAAmB,UAAU,OAAO;AAErD,mBAAiB,IAAI,OAAO,MAAM,aAAa;;AAGjD,mBAAkB,SAAS;CAE3B,MAAM,QAAQ,CAAC,GAAG,iBAAiB,MAAM,CAAC;;;;;;;;;;;AAW1C,SAAQ,kBAAR;EACE,KAAK;AACH,UACE,MAAM,WAAW,KAAK,MAAM,OAAO,UACnC,qCACD;AACD,UAAO,OAAO,KACZ,sBAAsB,KAAK,iBAAiB,IAAI,SAAS,CAAC,C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L,cAAa;;AAGf,SAAgB,0BACd,QAC4B;AAC5B,SAAQ,WAA2B;AACjC,MAAI,OAAO,KAAK,OAAO,cAAc,CAAC,WAAW,EAC/C,QAAO;AAGT,UAAQ,OAAO,MAAf;GACE,KAAK;GACL,KAAK,UAAU;IACb,MAAM,MAAM;KACV,GAAG;KACH,MAAM;MACJ,GAAG,OAAO;MACV,eAAe,EACb,GAAG,OAAO,KAAK,eAChB;MACF;KACF;AAED,eAAW,IAAI,KAAK,eAAe,OAAO,KAAK,OAAO,cAAc,CAAC;AAErE,WAAO;;GAET,KAAK,QAAQ;IACX,MAAM,MAAM;KACV,GAAG;KACH,MAAM;MACJ,GAAG,OAAO;MACV,eAAe,EACb,GAAG,OAAO,KAAK,eAChB;MACF;KACD,SAAS;MACP,GAAG,OAAO;MACV,eAAe,EACb,GAAG,OAAO,QAAQ,eACnB;MACF;KACF;AAED,eAAW,IAAI,KAAK,eAAe,OAAO,KAAK,OAAO,cAAc,CAAC;AACrE,eACE,IAAI,QAAQ,eACZ,OAAO,KAAK,OAAO,cAAc,CAClC;AAED,WAAO;;GAET,KAAK,QACH,QAAO;;;;;;;;;;AAWf,SAAgB,WACd,eACA,mBACA;AACA,MAAK,MAAM,WAAW,kBACpB,KAAI,cAAc,aAAa,KAAA,EAC7B,eAAc,iBAAiB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Row } from '../../../zero-protocol/src/data.ts';
|
|
2
|
-
import {
|
|
2
|
+
import type { Change } from './change.ts';
|
|
3
3
|
import type { Node } from './data.ts';
|
|
4
4
|
import { type FetchRequest, type Input, type Operator, type Output } from './operator.ts';
|
|
5
5
|
import type { SourceSchema } from './schema.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/skip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"skip.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/skip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAY,MAAM,EAA4B,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAa,IAAI,EAAC,MAAM,WAAW,CAAC;AAEhD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,MAAM,EAEZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,qBAAa,IAAK,YAAW,QAAQ;;gBAOvB,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAStC,SAAS,IAAI,YAAY;IAIxB,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;IAsBjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,OAAO,IAAI,IAAI;IASd,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;CA+EvC"}
|
package/out/zql/src/ivm/skip.js
CHANGED
|
@@ -54,11 +54,11 @@ var Skip = class {
|
|
|
54
54
|
}
|
|
55
55
|
*push(change) {
|
|
56
56
|
const shouldBePresent = (row) => this.#shouldBePresent(row);
|
|
57
|
-
if (change
|
|
57
|
+
if (change.type === "edit") {
|
|
58
58
|
yield* maybeSplitAndPushEditChange(change, shouldBePresent, this.#output, this);
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
if (shouldBePresent(change
|
|
61
|
+
if (shouldBePresent(change.node.row)) yield* this.#output.push(change, this);
|
|
62
62
|
}
|
|
63
63
|
#getStart(req) {
|
|
64
64
|
const boundStart = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip.js","names":["#input","#bound","#comparator","#getStart","#shouldBePresent","#output"],"sources":["../../../../../zql/src/ivm/skip.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport
|
|
1
|
+
{"version":3,"file":"skip.js","names":["#input","#bound","#comparator","#getStart","#shouldBePresent","#output"],"sources":["../../../../../zql/src/ivm/skip.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {AddChange, Change, ChildChange, RemoveChange} from './change.ts';\nimport type {Comparator, Node} from './data.ts';\nimport {maybeSplitAndPushEditChange} from './maybe-split-and-push-edit-change.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Operator,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Bound = {\n row: Row;\n exclusive: boolean;\n};\n\n/**\n * Skip sets the start position for the pipeline. No rows before the bound will\n * be output.\n */\nexport class Skip implements Operator {\n readonly #input: Input;\n readonly #bound: Bound;\n readonly #comparator: Comparator;\n\n #output: Output = throwOutput;\n\n constructor(input: Input, bound: Bound) {\n const {sort} = input.getSchema();\n assert(sort !== undefined, 'Skip requires sorted input');\n this.#input = input;\n this.#bound = bound;\n this.#comparator = input.getSchema().compareRows;\n input.setOutput(this);\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n const start = this.#getStart(req);\n if (start === 'empty') {\n return;\n }\n const nodes = this.#input.fetch({...req, start});\n if (!req.reverse) {\n yield* nodes;\n return;\n }\n for (const node of nodes) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!this.#shouldBePresent(node.row)) {\n return;\n }\n yield node;\n }\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n #shouldBePresent(row: Row): boolean {\n const cmp = this.#comparator(this.#bound.row, row);\n return cmp < 0 || (cmp === 0 && !this.#bound.exclusive);\n }\n\n *push(change: Change): Stream<'yield'> {\n const shouldBePresent = (row: Row) => this.#shouldBePresent(row);\n if (change.type === 'edit') {\n yield* maybeSplitAndPushEditChange(\n change,\n shouldBePresent,\n this.#output,\n this,\n );\n return;\n }\n\n change satisfies AddChange | RemoveChange | ChildChange;\n\n if (shouldBePresent(change.node.row)) {\n yield* this.#output.push(change, this);\n }\n }\n\n #getStart(req: FetchRequest): Start | undefined | 'empty' {\n const boundStart = {\n row: this.#bound.row,\n basis: this.#bound.exclusive ? 'after' : 'at',\n } as const;\n\n if (!req.start) {\n if (req.reverse) {\n return undefined;\n }\n return boundStart;\n }\n\n const cmp = this.#comparator(this.#bound.row, req.start.row);\n\n if (!req.reverse) {\n // The skip bound is after the requested bound. The requested bound cannot\n // be relevant because even if it was basis: 'after', the skip bound is\n // itself after the requested bound. Return the skip bound.\n if (cmp > 0) {\n return boundStart;\n }\n\n // The skip bound and requested bound are equal. If either is exclusive,\n // return that bound with exclusive. Otherwise, return the skip bound.\n if (cmp === 0) {\n if (this.#bound.exclusive || req.start.basis === 'after') {\n return {\n row: this.#bound.row,\n basis: 'after',\n };\n }\n return boundStart;\n }\n\n return req.start;\n }\n\n req.reverse satisfies true;\n\n // bound is after the start, but request is for reverse so results\n // must be empty\n if (cmp > 0) {\n return 'empty';\n }\n\n if (cmp === 0) {\n // if both are inclusive, the result can be the single row at bound\n // return it as start\n if (!this.#bound.exclusive && req.start.basis === 'at') {\n return boundStart;\n }\n // otherwise the results must be empty, one or both are exclusive\n // in opposite directions\n return 'empty';\n }\n\n // bound is before the start, return start\n return req.start;\n }\n}\n"],"mappings":";;;;;;;;AAyBA,IAAa,OAAb,MAAs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AO;;EAGT,MAAM,MAAM,MAAA,WAAiB,MAAA,MAAY,KAAK,IAAI,MAAM,IAAI;AAE5D,MAAI,CAAC,IAAI,SAAS;AAIhB,OAAI,MAAM,EACR,QAAO;AAKT,OAAI,QAAQ,GAAG;AACb,QAAI,MAAA,MAAY,aAAa,IAAI,MAAM,UAAU,QAC/C,QAAO;KACL,KAAK,MAAA,MAAY;KACjB,OAAO;KACR;AAEH,WAAO;;AAGT,UAAO,IAAI;;AAGb,MAAI;AAIJ,MAAI,MAAM,EACR,QAAO;AAGT,MAAI,QAAQ,GAAG;AAGb,OAAI,CAAC,MAAA,MAAY,aAAa,IAAI,MAAM,UAAU,KAChD,QAAO;AAIT,UAAO;;AAIT,SAAO,IAAI"}
|
|
@@ -2,20 +2,22 @@ import type { Condition, Ordering } from '../../../zero-protocol/src/ast.ts';
|
|
|
2
2
|
import type { Row } from '../../../zero-protocol/src/data.ts';
|
|
3
3
|
import type { TableSchema } from '../../../zero-types/src/schema.ts';
|
|
4
4
|
import type { DebugDelegate } from '../builder/debug-delegate.ts';
|
|
5
|
-
import { ChangeType } from './change-type.ts';
|
|
6
5
|
import type { Input } from './operator.ts';
|
|
7
6
|
import type { Stream } from './stream.ts';
|
|
8
|
-
export type SourceChangeAdd =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export type SourceChangeAdd = {
|
|
8
|
+
type: 'add';
|
|
9
|
+
row: Row;
|
|
10
|
+
};
|
|
11
|
+
export type SourceChangeRemove = {
|
|
12
|
+
type: 'remove';
|
|
13
|
+
row: Row;
|
|
14
|
+
};
|
|
15
|
+
export type SourceChangeEdit = {
|
|
16
|
+
type: 'edit';
|
|
17
|
+
row: Row;
|
|
18
|
+
oldRow: Row;
|
|
19
|
+
};
|
|
15
20
|
export type SourceChange = SourceChangeAdd | SourceChangeRemove | SourceChangeEdit;
|
|
16
|
-
export declare function makeSourceChangeAdd(row: Row): SourceChangeAdd;
|
|
17
|
-
export declare function makeSourceChangeRemove(row: Row): SourceChangeRemove;
|
|
18
|
-
export declare function makeSourceChangeEdit(row: Row, oldRow: Row): SourceChangeEdit;
|
|
19
21
|
/**
|
|
20
22
|
* A source is an input that serves as the root data source of the pipeline.
|
|
21
23
|
* Sources have multiple outputs. To add an output, call `connect()`, then
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB,eAAe,GACf,kBAAkB,GAClB,gBAAgB,CAAC;AAErB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,WAAW,IAAI,WAAW,CAAC;IAC/B;;;;;;;;;;;OAWG;IACH,OAAO,CACL,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,OAAO,CAAC,EAAE,SAAS,EACnB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC3B,KAAK,CAAC,EAAE,aAAa,GACpB,WAAW,CAAC;IAEf;;;;;;;;OAQG;IACH,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;CACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/take.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/take.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;AAE1E,OAAO,EAAC,KAAK,MAAM,EAAqC,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAgB,KAAK,UAAU,EA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