@rocicorp/zero 0.25.0-canary.12 → 0.25.0-canary.14
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/zero/package.json.js +1 -1
- package/out/zero/src/pg.js +4 -2
- package/out/zero/src/server.js +4 -2
- package/out/zero-cache/src/config/zero-config.d.ts +0 -4
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +5 -15
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +2 -8
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/otel-diag-logger.js +1 -0
- package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +62 -42
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/control.js +5 -1
- package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +2 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts +8 -0
- package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/json.js +19 -0
- package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current.js +3 -0
- package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +0 -2
- 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 +0 -5
- 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.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +8 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +2 -3
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/http-service.d.ts +0 -1
- package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/http-service.js +0 -4
- package/out/zero-cache/src/services/http-service.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replication-status.d.ts +2 -0
- package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/replication-status.js +14 -1
- package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
- package/out/zero-client/src/client/connection-manager.d.ts +3 -3
- package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/connection-manager.js.map +1 -1
- package/out/zero-client/src/client/connection.d.ts.map +1 -1
- package/out/zero-client/src/client/connection.js +8 -1
- package/out/zero-client/src/client/connection.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.js +4 -3
- package/out/zero-client/src/client/custom.js.map +1 -1
- package/out/zero-client/src/client/error.d.ts +6 -1
- package/out/zero-client/src/client/error.d.ts.map +1 -1
- package/out/zero-client/src/client/error.js +2 -2
- package/out/zero-client/src/client/error.js.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.d.ts +6 -9
- package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.js +3 -8
- package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.d.ts +3 -2
- package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.js +15 -3
- package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +8 -8
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-events/src/status.d.ts +1 -1
- package/out/zero-events/src/status.d.ts.map +1 -1
- package/out/zero-schema/src/permissions.d.ts +3 -0
- package/out/zero-schema/src/permissions.d.ts.map +1 -1
- package/out/zero-schema/src/permissions.js.map +1 -1
- package/out/zero-server/src/custom.d.ts +2 -2
- package/out/zero-server/src/custom.d.ts.map +1 -1
- package/out/zero-server/src/custom.js +40 -4
- package/out/zero-server/src/custom.js.map +1 -1
- package/out/zero-server/src/mod.d.ts +1 -1
- package/out/zero-server/src/mod.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.d.ts +10 -6
- package/out/zero-server/src/process-mutations.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.js +9 -18
- package/out/zero-server/src/process-mutations.js.map +1 -1
- package/out/zero-server/src/push-processor.d.ts.map +1 -1
- package/out/zero-server/src/push-processor.js +10 -8
- package/out/zero-server/src/push-processor.js.map +1 -1
- package/out/zero-server/src/queries/process-queries.d.ts +14 -2
- package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
- package/out/zero-server/src/queries/process-queries.js +18 -15
- package/out/zero-server/src/queries/process-queries.js.map +1 -1
- package/out/zero-server/src/zql-database.d.ts.map +1 -1
- package/out/zero-server/src/zql-database.js +1 -5
- package/out/zero-server/src/zql-database.js.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +0 -1
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/ivm/data.js +0 -11
- package/out/zql/src/ivm/data.js.map +1 -1
- package/out/zql/src/ivm/exists.d.ts +2 -2
- package/out/zql/src/ivm/exists.d.ts.map +1 -1
- package/out/zql/src/ivm/exists.js +34 -20
- package/out/zql/src/ivm/exists.js.map +1 -1
- package/out/zql/src/ivm/fan-in.d.ts +1 -1
- package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/fan-in.js +4 -2
- 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 +9 -3
- package/out/zql/src/ivm/fan-out.js.map +1 -1
- package/out/zql/src/ivm/filter-operators.d.ts +4 -6
- package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
- package/out/zql/src/ivm/filter-operators.js +14 -27
- package/out/zql/src/ivm/filter-operators.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 +4 -2
- package/out/zql/src/ivm/filter.js.map +1 -1
- package/out/zql/src/ivm/flipped-join.d.ts +0 -1
- package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
- package/out/zql/src/ivm/flipped-join.js +0 -2
- package/out/zql/src/ivm/flipped-join.js.map +1 -1
- package/out/zql/src/ivm/join.d.ts +2 -15
- package/out/zql/src/ivm/join.d.ts.map +1 -1
- package/out/zql/src/ivm/join.js +33 -96
- package/out/zql/src/ivm/join.js.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts +4 -3
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +24 -23
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/operator.d.ts +0 -12
- package/out/zql/src/ivm/operator.d.ts.map +1 -1
- package/out/zql/src/ivm/operator.js.map +1 -1
- package/out/zql/src/ivm/skip.d.ts +0 -1
- package/out/zql/src/ivm/skip.d.ts.map +1 -1
- package/out/zql/src/ivm/skip.js +3 -11
- package/out/zql/src/ivm/skip.js.map +1 -1
- package/out/zql/src/ivm/take.d.ts +0 -1
- package/out/zql/src/ivm/take.d.ts.map +1 -1
- package/out/zql/src/ivm/take.js +0 -17
- package/out/zql/src/ivm/take.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts +0 -1
- package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +0 -3
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/ivm/union-fan-out.d.ts +0 -1
- package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-out.js +0 -3
- package/out/zql/src/ivm/union-fan-out.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +1 -2
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/mutator.d.ts +2 -2
- package/out/zql/src/mutate/mutator.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator.js.map +1 -1
- package/out/zql/src/query/create-builder.d.ts +2 -2
- package/out/zql/src/query/create-builder.d.ts.map +1 -1
- package/out/zql/src/query/create-builder.js +12 -3
- package/out/zql/src/query/create-builder.js.map +1 -1
- package/out/zql/src/query/measure-push-operator.d.ts +0 -1
- package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
- package/out/zql/src/query/measure-push-operator.js +0 -3
- package/out/zql/src/query/measure-push-operator.js.map +1 -1
- package/out/zql/src/query/query.d.ts +18 -5
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +6 -10
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ class Exists {
|
|
|
9
9
|
#parentJoinKey;
|
|
10
10
|
#noSizeReuse;
|
|
11
11
|
#cache;
|
|
12
|
+
#cacheHitCountsForTesting;
|
|
12
13
|
#output = throwFilterOutput;
|
|
13
14
|
/**
|
|
14
15
|
* This instance variable is `true` when this operator is processing a `push`,
|
|
@@ -19,11 +20,12 @@ class Exists {
|
|
|
19
20
|
* Node at a time.
|
|
20
21
|
*/
|
|
21
22
|
#inPush = false;
|
|
22
|
-
constructor(input, relationshipName, parentJoinKey, type) {
|
|
23
|
+
constructor(input, relationshipName, parentJoinKey, type, cacheHitCountsForTesting) {
|
|
23
24
|
this.#input = input;
|
|
24
25
|
this.#relationshipName = relationshipName;
|
|
25
26
|
this.#input.setFilterOutput(this);
|
|
26
27
|
this.#cache = /* @__PURE__ */ new Map();
|
|
28
|
+
this.#cacheHitCountsForTesting = cacheHitCountsForTesting;
|
|
27
29
|
assert(
|
|
28
30
|
this.#input.getSchema().relationships[relationshipName],
|
|
29
31
|
`Input schema missing ${relationshipName}`
|
|
@@ -39,21 +41,28 @@ class Exists {
|
|
|
39
41
|
this.#output = output;
|
|
40
42
|
}
|
|
41
43
|
beginFilter() {
|
|
44
|
+
this.#output.beginFilter();
|
|
42
45
|
}
|
|
43
46
|
endFilter() {
|
|
44
47
|
this.#cache = /* @__PURE__ */ new Map();
|
|
48
|
+
this.#output.endFilter();
|
|
45
49
|
}
|
|
46
|
-
filter(node
|
|
47
|
-
let
|
|
48
|
-
if (!this.#noSizeReuse) {
|
|
49
|
-
const key = this.#
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
this.#cache.set(key,
|
|
50
|
+
filter(node) {
|
|
51
|
+
let exists;
|
|
52
|
+
if (!this.#noSizeReuse && !this.#inPush) {
|
|
53
|
+
const key = this.#getCacheKey(node, this.#parentJoinKey);
|
|
54
|
+
exists = this.#cache.get(key);
|
|
55
|
+
if (exists === void 0) {
|
|
56
|
+
exists = this.#fetchExists(node);
|
|
57
|
+
this.#cache.set(key, exists);
|
|
58
|
+
} else if (this.#cacheHitCountsForTesting) {
|
|
59
|
+
this.#cacheHitCountsForTesting.set(
|
|
60
|
+
key,
|
|
61
|
+
(this.#cacheHitCountsForTesting.get(key) ?? 0) + 1
|
|
62
|
+
);
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
|
-
const result = this.#filter(node,
|
|
65
|
+
const result = this.#filter(node, exists) && this.#output.filter(node);
|
|
57
66
|
return result;
|
|
58
67
|
}
|
|
59
68
|
destroy() {
|
|
@@ -108,7 +117,7 @@ class Exists {
|
|
|
108
117
|
);
|
|
109
118
|
}
|
|
110
119
|
} else {
|
|
111
|
-
this.#pushWithFilter(change, size);
|
|
120
|
+
this.#pushWithFilter(change, size > 0);
|
|
112
121
|
}
|
|
113
122
|
return;
|
|
114
123
|
}
|
|
@@ -141,7 +150,7 @@ class Exists {
|
|
|
141
150
|
);
|
|
142
151
|
}
|
|
143
152
|
} else {
|
|
144
|
-
this.#pushWithFilter(change, size);
|
|
153
|
+
this.#pushWithFilter(change, size > 0);
|
|
145
154
|
}
|
|
146
155
|
return;
|
|
147
156
|
}
|
|
@@ -163,31 +172,36 @@ class Exists {
|
|
|
163
172
|
* relationship with this.#relationshipName (this computed size is also
|
|
164
173
|
* stored).
|
|
165
174
|
*/
|
|
166
|
-
#filter(node,
|
|
167
|
-
|
|
175
|
+
#filter(node, exists) {
|
|
176
|
+
exists = exists ?? this.#fetchExists(node);
|
|
168
177
|
return this.#not ? !exists : exists;
|
|
169
178
|
}
|
|
170
|
-
#
|
|
179
|
+
#getCacheKey(node, def) {
|
|
171
180
|
const values = [];
|
|
172
181
|
for (const key of def) {
|
|
173
182
|
values.push(normalizeUndefined(node.row[key]));
|
|
174
183
|
}
|
|
175
|
-
return values;
|
|
184
|
+
return JSON.stringify(values);
|
|
176
185
|
}
|
|
177
186
|
/**
|
|
178
187
|
* Pushes a change if this.#filter is true for its row.
|
|
179
188
|
*/
|
|
180
|
-
#pushWithFilter(change,
|
|
181
|
-
if (this.#filter(change.node,
|
|
189
|
+
#pushWithFilter(change, exists) {
|
|
190
|
+
if (this.#filter(change.node, exists)) {
|
|
182
191
|
this.#output.push(change, this);
|
|
183
192
|
}
|
|
184
193
|
}
|
|
194
|
+
#fetchExists(node) {
|
|
195
|
+
return this.#fetchSize(node) > 0;
|
|
196
|
+
}
|
|
185
197
|
#fetchSize(node) {
|
|
186
198
|
const relationship = node.relationships[this.#relationshipName];
|
|
187
199
|
assert(relationship);
|
|
188
200
|
let size = 0;
|
|
189
|
-
for (const
|
|
190
|
-
|
|
201
|
+
for (const n of relationship()) {
|
|
202
|
+
if (n !== "yield") {
|
|
203
|
+
size++;
|
|
204
|
+
}
|
|
191
205
|
}
|
|
192
206
|
return size;
|
|
193
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exists.js","sources":["../../../../../zql/src/ivm/exists.ts"],"sourcesContent":["import {areEqual} from '../../../shared/src/arrays.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport {type Change} from './change.ts';\nimport {normalizeUndefined, type Node, type NormalizedValue} from './data.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The Exists operator filters data based on whether or not a relationship is\n * non-empty.\n */\nexport class Exists implements FilterOperator {\n readonly #input: FilterInput;\n readonly #relationshipName: string;\n readonly #not: boolean;\n readonly #parentJoinKey: CompoundKey;\n readonly #noSizeReuse: boolean;\n #cache: Map<string, number>;\n\n #output: FilterOutput = throwFilterOutput;\n\n /**\n * This instance variable is `true` when this operator is processing a `push`,\n * and is used to disable reuse of cached sizes across rows with the\n * same parent join key value.\n * This is necessary because during a push relationships can be inconsistent\n * due to push communicating changes (which may change multiple Nodes) one\n * Node at a time.\n */\n #inPush = false;\n\n constructor(\n input: FilterInput,\n relationshipName: string,\n parentJoinKey: CompoundKey,\n type: 'EXISTS' | 'NOT EXISTS',\n ) {\n this.#input = input;\n this.#relationshipName = relationshipName;\n this.#input.setFilterOutput(this);\n this.#cache = new Map();\n assert(\n this.#input.getSchema().relationships[relationshipName],\n `Input schema missing ${relationshipName}`,\n );\n this.#not = type === 'NOT EXISTS';\n this.#parentJoinKey = parentJoinKey;\n\n // If the parentJoinKey is the primary key, no sense in trying to reuse.\n this.#noSizeReuse = areEqual(\n parentJoinKey,\n this.#input.getSchema().primaryKey,\n );\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#output = output;\n }\n\n beginFilter() {}\n\n endFilter() {\n this.#cache = new Map();\n }\n\n filter(node: Node, cleanup: boolean): boolean {\n let size: number | undefined;\n if (!this.#noSizeReuse) {\n const key = this.#getKeyValues(node, this.#parentJoinKey).toString();\n size = this.#cache.get(key);\n if (size === undefined) {\n size = this.#fetchSize(node);\n this.#cache.set(key, size);\n }\n }\n\n const result =\n this.#filter(node, size) && this.#output.filter(node, cleanup);\n return result;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n push(change: Change) {\n assert(!this.#inPush, 'Unexpected re-entrancy');\n this.#inPush = true;\n try {\n switch (change.type) {\n // add, remove and edit cannot change the size of the\n // this.#relationshipName relationship, so simply #pushWithFilter\n case 'add':\n case 'edit':\n case 'remove': {\n this.#pushWithFilter(change);\n return;\n }\n case 'child':\n // Only add and remove child changes for the\n // this.#relationshipName relationship, can change the size\n // of the this.#relationshipName relationship, for other\n // child changes simply #pushWithFilter\n if (\n change.child.relationshipName !== this.#relationshipName ||\n change.child.change.type === 'edit' ||\n change.child.change.type === 'child'\n ) {\n this.#pushWithFilter(change);\n return;\n }\n switch (change.child.change.type) {\n case 'add': {\n const size = this.#fetchSize(change.node);\n if (size === 1) {\n if (this.#not) {\n // Since the add child change currently being processed is not\n // pushed to output, the added child needs to be excluded from\n // the remove being pushed to output (since the child has\n // never been added to the output).\n this.#output.push(\n {\n type: 'remove',\n node: {\n row: change.node.row,\n relationships: {\n ...change.node.relationships,\n [this.#relationshipName]: () => [],\n },\n },\n },\n this,\n );\n } else {\n this.#output.push(\n {\n type: 'add',\n node: change.node,\n },\n this,\n );\n }\n } else {\n this.#pushWithFilter(change, size);\n }\n return;\n }\n case 'remove': {\n const size = this.#fetchSize(change.node);\n if (size === 0) {\n if (this.#not) {\n this.#output.push(\n {\n type: 'add',\n node: change.node,\n },\n this,\n );\n } else {\n // Since the remove child change currently being processed is\n // not pushed to output, the removed child needs to be added to\n // the remove being pushed to output.\n this.#output.push(\n {\n type: 'remove',\n node: {\n row: change.node.row,\n relationships: {\n ...change.node.relationships,\n [this.#relationshipName]: () => [\n change.child.change.node,\n ],\n },\n },\n },\n this,\n );\n }\n } else {\n this.#pushWithFilter(change, size);\n }\n return;\n }\n }\n return;\n default:\n unreachable(change);\n }\n } finally {\n this.#inPush = false;\n }\n }\n\n /**\n * Returns whether or not the node's this.#relationshipName\n * relationship passes the exist/not exists filter condition.\n * If the optional `size` is passed it is used.\n * Otherwise, if there is a stored size for the row it is used.\n * Otherwise the size is computed by streaming the node's\n * relationship with this.#relationshipName (this computed size is also\n * stored).\n */\n #filter(node: Node, size?: number): boolean {\n const exists = (size ?? this.#fetchSize(node)) > 0;\n return this.#not ? !exists : exists;\n }\n\n #getKeyValues(node: Node, def: CompoundKey): NormalizedValue[] {\n const values: NormalizedValue[] = [];\n for (const key of def) {\n values.push(normalizeUndefined(node.row[key]));\n }\n return values;\n }\n\n /**\n * Pushes a change if this.#filter is true for its row.\n */\n #pushWithFilter(change: Change, size?: number): void {\n if (this.#filter(change.node, size)) {\n this.#output.push(change, this);\n }\n }\n\n #fetchSize(node: Node): number {\n const relationship = node.relationships[this.#relationshipName];\n assert(relationship);\n let size = 0;\n for (const _relatedNode of relationship()) {\n size++;\n }\n return size;\n }\n}\n"],"names":[],"mappings":";;;;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
+
{"version":3,"file":"exists.js","sources":["../../../../../zql/src/ivm/exists.ts"],"sourcesContent":["import {areEqual} from '../../../shared/src/arrays.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport {type Change} from './change.ts';\nimport {normalizeUndefined, type Node, type NormalizedValue} from './data.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The Exists operator filters data based on whether or not a relationship is\n * non-empty.\n */\nexport class Exists implements FilterOperator {\n readonly #input: FilterInput;\n readonly #relationshipName: string;\n readonly #not: boolean;\n readonly #parentJoinKey: CompoundKey;\n readonly #noSizeReuse: boolean;\n #cache: Map<string, boolean>;\n #cacheHitCountsForTesting: Map<string, number> | undefined;\n #output: FilterOutput = throwFilterOutput;\n\n /**\n * This instance variable is `true` when this operator is processing a `push`,\n * and is used to disable reuse of cached sizes across rows with the\n * same parent join key value.\n * This is necessary because during a push relationships can be inconsistent\n * due to push communicating changes (which may change multiple Nodes) one\n * Node at a time.\n */\n #inPush = false;\n\n constructor(\n input: FilterInput,\n relationshipName: string,\n parentJoinKey: CompoundKey,\n type: 'EXISTS' | 'NOT EXISTS',\n cacheHitCountsForTesting?: Map<string, number>,\n ) {\n this.#input = input;\n this.#relationshipName = relationshipName;\n this.#input.setFilterOutput(this);\n this.#cache = new Map();\n this.#cacheHitCountsForTesting = cacheHitCountsForTesting;\n assert(\n this.#input.getSchema().relationships[relationshipName],\n `Input schema missing ${relationshipName}`,\n );\n this.#not = type === 'NOT EXISTS';\n this.#parentJoinKey = parentJoinKey;\n\n // If the parentJoinKey is the primary key, no sense in trying to reuse.\n this.#noSizeReuse = areEqual(\n parentJoinKey,\n this.#input.getSchema().primaryKey,\n );\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#output = output;\n }\n\n beginFilter() {\n this.#output.beginFilter();\n }\n\n endFilter() {\n this.#cache = new Map();\n this.#output.endFilter();\n }\n\n filter(node: Node): boolean {\n let exists: boolean | undefined;\n if (!this.#noSizeReuse && !this.#inPush) {\n const key = this.#getCacheKey(node, this.#parentJoinKey);\n exists = this.#cache.get(key);\n if (exists === undefined) {\n exists = this.#fetchExists(node);\n this.#cache.set(key, exists);\n } else if (this.#cacheHitCountsForTesting) {\n this.#cacheHitCountsForTesting.set(\n key,\n (this.#cacheHitCountsForTesting.get(key) ?? 0) + 1,\n );\n }\n }\n\n const result = this.#filter(node, exists) && this.#output.filter(node);\n return result;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n push(change: Change) {\n assert(!this.#inPush, 'Unexpected re-entrancy');\n this.#inPush = true;\n try {\n switch (change.type) {\n // add, remove and edit cannot change the size of the\n // this.#relationshipName relationship, so simply #pushWithFilter\n case 'add':\n case 'edit':\n case 'remove': {\n this.#pushWithFilter(change);\n return;\n }\n case 'child':\n // Only add and remove child changes for the\n // this.#relationshipName relationship, can change the size\n // of the this.#relationshipName relationship, for other\n // child changes simply #pushWithFilter\n if (\n change.child.relationshipName !== this.#relationshipName ||\n change.child.change.type === 'edit' ||\n change.child.change.type === 'child'\n ) {\n this.#pushWithFilter(change);\n return;\n }\n switch (change.child.change.type) {\n case 'add': {\n const size = this.#fetchSize(change.node);\n if (size === 1) {\n if (this.#not) {\n // Since the add child change currently being processed is not\n // pushed to output, the added child needs to be excluded from\n // the remove being pushed to output (since the child has\n // never been added to the output).\n this.#output.push(\n {\n type: 'remove',\n node: {\n row: change.node.row,\n relationships: {\n ...change.node.relationships,\n [this.#relationshipName]: () => [],\n },\n },\n },\n this,\n );\n } else {\n this.#output.push(\n {\n type: 'add',\n node: change.node,\n },\n this,\n );\n }\n } else {\n this.#pushWithFilter(change, size > 0);\n }\n return;\n }\n case 'remove': {\n const size = this.#fetchSize(change.node);\n if (size === 0) {\n if (this.#not) {\n this.#output.push(\n {\n type: 'add',\n node: change.node,\n },\n this,\n );\n } else {\n // Since the remove child change currently being processed is\n // not pushed to output, the removed child needs to be added to\n // the remove being pushed to output.\n this.#output.push(\n {\n type: 'remove',\n node: {\n row: change.node.row,\n relationships: {\n ...change.node.relationships,\n [this.#relationshipName]: () => [\n change.child.change.node,\n ],\n },\n },\n },\n this,\n );\n }\n } else {\n this.#pushWithFilter(change, size > 0);\n }\n return;\n }\n }\n return;\n default:\n unreachable(change);\n }\n } finally {\n this.#inPush = false;\n }\n }\n\n /**\n * Returns whether or not the node's this.#relationshipName\n * relationship passes the exist/not exists filter condition.\n * If the optional `size` is passed it is used.\n * Otherwise, if there is a stored size for the row it is used.\n * Otherwise the size is computed by streaming the node's\n * relationship with this.#relationshipName (this computed size is also\n * stored).\n */\n #filter(node: Node, exists?: boolean): boolean {\n exists = exists ?? this.#fetchExists(node);\n return this.#not ? !exists : exists;\n }\n\n #getCacheKey(node: Node, def: CompoundKey): string {\n const values: NormalizedValue[] = [];\n for (const key of def) {\n values.push(normalizeUndefined(node.row[key]));\n }\n return JSON.stringify(values);\n }\n\n /**\n * Pushes a change if this.#filter is true for its row.\n */\n #pushWithFilter(change: Change, exists?: boolean): void {\n if (this.#filter(change.node, exists)) {\n this.#output.push(change, this);\n }\n }\n\n #fetchExists(node: Node): boolean {\n // While it seems like this should be able to fetch just 1 node\n // to check for exists, we can't because Take does not support\n // early return during initial fetch.\n return this.#fetchSize(node) > 0;\n }\n\n #fetchSize(node: Node): number {\n const relationship = node.relationships[this.#relationshipName];\n assert(relationship);\n let size = 0;\n for (const n of relationship()) {\n if (n !== 'yield') {\n size++;\n }\n }\n return size;\n }\n}\n"],"names":[],"mappings":";;;;AAiBO,MAAM,OAAiC;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EACA;AAAA,EACA,UAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUxB,UAAU;AAA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WAAO,YAAY;AACnB,QAAI,OAAO;AACX,eAAW,KAAK,gBAAgB;AAC9B,UAAI,MAAM,SAAS;AACjB;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -25,7 +25,7 @@ export declare class FanIn implements FilterOperator {
|
|
|
25
25
|
getSchema(): SourceSchema;
|
|
26
26
|
beginFilter(): void;
|
|
27
27
|
endFilter(): void;
|
|
28
|
-
filter(node: Node
|
|
28
|
+
filter(node: Node): boolean;
|
|
29
29
|
push(change: Change): void;
|
|
30
30
|
fanOutDonePushingToAllBranches(fanOutChangeType: Change['type']): void;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fan-in.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/fan-in.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACzC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAM,YAAW,cAAc;;gBAM9B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE;IASjD,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAI3C,OAAO,IAAI,IAAI;IAMf,SAAS;IAIT,WAAW,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"fan-in.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/fan-in.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACzC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAM,YAAW,cAAc;;gBAM9B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE;IASjD,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAI3C,OAAO,IAAI,IAAI;IAMf,SAAS;IAIT,WAAW,IAAI,IAAI;IAInB,SAAS,IAAI,IAAI;IAIjB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI3B,IAAI,CAAC,MAAM,EAAE,MAAM;IAInB,8BAA8B,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC;CAkBhE"}
|
|
@@ -28,11 +28,13 @@ class FanIn {
|
|
|
28
28
|
return this.#schema;
|
|
29
29
|
}
|
|
30
30
|
beginFilter() {
|
|
31
|
+
this.#output.beginFilter();
|
|
31
32
|
}
|
|
32
33
|
endFilter() {
|
|
34
|
+
this.#output.endFilter();
|
|
33
35
|
}
|
|
34
|
-
filter(node
|
|
35
|
-
return this.#output.filter(node
|
|
36
|
+
filter(node) {
|
|
37
|
+
return this.#output.filter(node);
|
|
36
38
|
}
|
|
37
39
|
push(change) {
|
|
38
40
|
this.#accumulatedPushes.push(change);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fan-in.js","sources":["../../../../../zql/src/ivm/fan-in.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport {identity} from '../../../shared/src/sentinels.ts';\nimport type {Change} from './change.ts';\nimport {type Node} from './data.ts';\nimport type {FanOut} from './fan-out.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport {pushAccumulatedChanges} from './push-accumulated.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The FanIn operator merges multiple streams into one.\n * It eliminates duplicates and must be paired with a fan-out operator\n * somewhere upstream of the fan-in.\n *\n * issue\n * |\n * fan-out\n * / \\\n * a b\n * \\ /\n * fan-in\n * |\n */\nexport class FanIn implements FilterOperator {\n readonly #inputs: readonly FilterInput[];\n readonly #schema: SourceSchema;\n #output: FilterOutput = throwFilterOutput;\n #accumulatedPushes: Change[] = [];\n\n constructor(fanOut: FanOut, inputs: FilterInput[]) {\n this.#inputs = inputs;\n this.#schema = fanOut.getSchema();\n for (const input of inputs) {\n input.setFilterOutput(this);\n assert(this.#schema === input.getSchema(), `Schema mismatch in fan-in`);\n }\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#output = output;\n }\n\n destroy(): void {\n for (const input of this.#inputs) {\n input.destroy();\n }\n }\n\n getSchema() {\n return this.#schema;\n }\n\n beginFilter(): void {}\n\n endFilter(): void {}\n\n filter(node: Node
|
|
1
|
+
{"version":3,"file":"fan-in.js","sources":["../../../../../zql/src/ivm/fan-in.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport {identity} from '../../../shared/src/sentinels.ts';\nimport type {Change} from './change.ts';\nimport {type Node} from './data.ts';\nimport type {FanOut} from './fan-out.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport {pushAccumulatedChanges} from './push-accumulated.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The FanIn operator merges multiple streams into one.\n * It eliminates duplicates and must be paired with a fan-out operator\n * somewhere upstream of the fan-in.\n *\n * issue\n * |\n * fan-out\n * / \\\n * a b\n * \\ /\n * fan-in\n * |\n */\nexport class FanIn implements FilterOperator {\n readonly #inputs: readonly FilterInput[];\n readonly #schema: SourceSchema;\n #output: FilterOutput = throwFilterOutput;\n #accumulatedPushes: Change[] = [];\n\n constructor(fanOut: FanOut, inputs: FilterInput[]) {\n this.#inputs = inputs;\n this.#schema = fanOut.getSchema();\n for (const input of inputs) {\n input.setFilterOutput(this);\n assert(this.#schema === input.getSchema(), `Schema mismatch in fan-in`);\n }\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#output = output;\n }\n\n destroy(): void {\n for (const input of this.#inputs) {\n input.destroy();\n }\n }\n\n getSchema() {\n return this.#schema;\n }\n\n beginFilter(): void {\n this.#output.beginFilter();\n }\n\n endFilter(): void {\n this.#output.endFilter();\n }\n\n filter(node: Node): boolean {\n return this.#output.filter(node);\n }\n\n push(change: Change) {\n this.#accumulatedPushes.push(change);\n }\n\n fanOutDonePushingToAllBranches(fanOutChangeType: Change['type']) {\n if (this.#inputs.length === 0) {\n assert(\n this.#accumulatedPushes.length === 0,\n 'If there are no inputs then fan-in should not receive any pushes.',\n );\n return;\n }\n\n pushAccumulatedChanges(\n this.#accumulatedPushes,\n this.#output,\n this,\n fanOutChangeType,\n identity,\n identity,\n );\n }\n}\n"],"names":[],"mappings":";;;;;AA4BO,MAAM,MAAgC;AAAA,EAClC;AAAA,EACA;AAAA,EACT,UAAwB;AAAA,EACxB,qBAA+B,CAAA;AAAA,EAE/B,YAAY,QAAgB,QAAuB;AACjD,SAAK,UAAU;AACf,SAAK,UAAU,OAAO,UAAA;AACtB,eAAW,SAAS,QAAQ;AAC1B,YAAM,gBAAgB,IAAI;AAC1B,aAAO,KAAK,YAAY,MAAM,UAAA,GAAa,2BAA2B;AAAA,IACxE;AAAA,EACF;AAAA,EAEA,gBAAgB,QAA4B;AAC1C,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,UAAgB;AACd,eAAW,SAAS,KAAK,SAAS;AAChC,YAAM,QAAA;AAAA,IACR;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,cAAoB;AAClB,SAAK,QAAQ,YAAA;AAAA,EACf;AAAA,EAEA,YAAkB;AAChB,SAAK,QAAQ,UAAA;AAAA,EACf;AAAA,EAEA,OAAO,MAAqB;AAC1B,WAAO,KAAK,QAAQ,OAAO,IAAI;AAAA,EACjC;AAAA,EAEA,KAAK,QAAgB;AACnB,SAAK,mBAAmB,KAAK,MAAM;AAAA,EACrC;AAAA,EAEA,+BAA+B,kBAAkC;AAC/D,QAAI,KAAK,QAAQ,WAAW,GAAG;AAC7B;AAAA,QACE,KAAK,mBAAmB,WAAW;AAAA,QACnC;AAAA,MAAA;AAEF;AAAA,IACF;AAEA;AAAA,MACE,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AACF;"}
|
|
@@ -16,7 +16,7 @@ export declare class FanOut implements FilterOperator {
|
|
|
16
16
|
getSchema(): import("./schema.ts").SourceSchema;
|
|
17
17
|
beginFilter(): void;
|
|
18
18
|
endFilter(): void;
|
|
19
|
-
filter(node: Node
|
|
19
|
+
filter(node: Node): boolean;
|
|
20
20
|
push(change: Change): void;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=fan-out.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fan-out.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/fan-out.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACb,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,MAAO,YAAW,cAAc;;gBAM/B,KAAK,EAAE,WAAW;IAK9B,QAAQ,CAAC,KAAK,EAAE,KAAK;IAIrB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAI3C,OAAO,IAAI,IAAI;IAWf,SAAS;IAIT,WAAW,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"fan-out.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/fan-out.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACb,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,MAAO,YAAW,cAAc;;gBAM/B,KAAK,EAAE,WAAW;IAK9B,QAAQ,CAAC,KAAK,EAAE,KAAK;IAIrB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAI3C,OAAO,IAAI,IAAI;IAWf,SAAS;IAIT,WAAW,IAAI,IAAI;IAMnB,SAAS,IAAI,IAAI;IAMjB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAW3B,IAAI,CAAC,MAAM,EAAE,MAAM;CASpB"}
|
|
@@ -28,14 +28,20 @@ class FanOut {
|
|
|
28
28
|
return this.#input.getSchema();
|
|
29
29
|
}
|
|
30
30
|
beginFilter() {
|
|
31
|
+
for (const output of this.#outputs) {
|
|
32
|
+
output.beginFilter();
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
endFilter() {
|
|
36
|
+
for (const output of this.#outputs) {
|
|
37
|
+
output.endFilter();
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
|
-
filter(node
|
|
40
|
+
filter(node) {
|
|
35
41
|
let result = false;
|
|
36
42
|
for (const output of this.#outputs) {
|
|
37
|
-
result = output.filter(node
|
|
38
|
-
if (
|
|
43
|
+
result = output.filter(node) || result;
|
|
44
|
+
if (result) {
|
|
39
45
|
return true;
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fan-out.js","sources":["../../../../../zql/src/ivm/fan-out.ts"],"sourcesContent":["import {must} from '../../../shared/src/must.ts';\nimport type {Change} from './change.ts';\nimport type {FanIn} from './fan-in.ts';\nimport type {Node} from './data.ts';\nimport type {\n FilterInput,\n FilterOperator,\n FilterOutput,\n} from './filter-operators.ts';\n\n/**\n * Forks a stream into multiple streams.\n * Is meant to be paired with a `FanIn` operator which will\n * later merge the forks back together.\n */\nexport class FanOut implements FilterOperator {\n readonly #input: FilterInput;\n readonly #outputs: FilterOutput[] = [];\n #fanIn: FanIn | undefined;\n #destroyCount: number = 0;\n\n constructor(input: FilterInput) {\n this.#input = input;\n input.setFilterOutput(this);\n }\n\n setFanIn(fanIn: FanIn) {\n this.#fanIn = fanIn;\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#outputs.push(output);\n }\n\n destroy(): void {\n if (this.#destroyCount < this.#outputs.length) {\n ++this.#destroyCount;\n if (this.#destroyCount === this.#outputs.length) {\n this.#input.destroy();\n }\n } else {\n throw new Error('FanOut already destroyed once for each output');\n }\n }\n\n getSchema() {\n return this.#input.getSchema();\n }\n\n beginFilter(): void {}\n\n endFilter(): void {}\n\n filter(node: Node
|
|
1
|
+
{"version":3,"file":"fan-out.js","sources":["../../../../../zql/src/ivm/fan-out.ts"],"sourcesContent":["import {must} from '../../../shared/src/must.ts';\nimport type {Change} from './change.ts';\nimport type {FanIn} from './fan-in.ts';\nimport type {Node} from './data.ts';\nimport type {\n FilterInput,\n FilterOperator,\n FilterOutput,\n} from './filter-operators.ts';\n\n/**\n * Forks a stream into multiple streams.\n * Is meant to be paired with a `FanIn` operator which will\n * later merge the forks back together.\n */\nexport class FanOut implements FilterOperator {\n readonly #input: FilterInput;\n readonly #outputs: FilterOutput[] = [];\n #fanIn: FanIn | undefined;\n #destroyCount: number = 0;\n\n constructor(input: FilterInput) {\n this.#input = input;\n input.setFilterOutput(this);\n }\n\n setFanIn(fanIn: FanIn) {\n this.#fanIn = fanIn;\n }\n\n setFilterOutput(output: FilterOutput): void {\n this.#outputs.push(output);\n }\n\n destroy(): void {\n if (this.#destroyCount < this.#outputs.length) {\n ++this.#destroyCount;\n if (this.#destroyCount === this.#outputs.length) {\n this.#input.destroy();\n }\n } else {\n throw new Error('FanOut already destroyed once for each output');\n }\n }\n\n getSchema() {\n return this.#input.getSchema();\n }\n\n beginFilter(): void {\n for (const output of this.#outputs) {\n output.beginFilter();\n }\n }\n\n endFilter(): void {\n for (const output of this.#outputs) {\n output.endFilter();\n }\n }\n\n filter(node: Node): boolean {\n let result = false;\n for (const output of this.#outputs) {\n result = output.filter(node) || result;\n if (result) {\n return true;\n }\n }\n return result;\n }\n\n push(change: Change) {\n for (const out of this.#outputs) {\n out.push(change, this);\n }\n must(\n this.#fanIn,\n 'fan-out must have a corresponding fan-in set!',\n ).fanOutDonePushingToAllBranches(change.type);\n }\n}\n"],"names":[],"mappings":";AAeO,MAAM,OAAiC;AAAA,EACnC;AAAA,EACA,WAA2B,CAAA;AAAA,EACpC;AAAA,EACA,gBAAwB;AAAA,EAExB,YAAY,OAAoB;AAC9B,SAAK,SAAS;AACd,UAAM,gBAAgB,IAAI;AAAA,EAC5B;AAAA,EAEA,SAAS,OAAc;AACrB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,gBAAgB,QAA4B;AAC1C,SAAK,SAAS,KAAK,MAAM;AAAA,EAC3B;AAAA,EAEA,UAAgB;AACd,QAAI,KAAK,gBAAgB,KAAK,SAAS,QAAQ;AAC7C,QAAE,KAAK;AACP,UAAI,KAAK,kBAAkB,KAAK,SAAS,QAAQ;AAC/C,aAAK,OAAO,QAAA;AAAA,MACd;AAAA,IACF,OAAO;AACL,YAAM,IAAI,MAAM,+CAA+C;AAAA,IACjE;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,cAAoB;AAClB,eAAW,UAAU,KAAK,UAAU;AAClC,aAAO,YAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,YAAkB;AAChB,eAAW,UAAU,KAAK,UAAU;AAClC,aAAO,UAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,OAAO,MAAqB;AAC1B,QAAI,SAAS;AACb,eAAW,UAAU,KAAK,UAAU;AAClC,eAAS,OAAO,OAAO,IAAI,KAAK;AAChC,UAAI,QAAQ;AACV,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAAgB;AACnB,eAAW,OAAO,KAAK,UAAU;AAC/B,UAAI,KAAK,QAAQ,IAAI;AAAA,IACvB;AACA;AAAA,MACE,KAAK;AAAA,MACL;AAAA,IAAA,EACA,+BAA+B,OAAO,IAAI;AAAA,EAC9C;AACF;"}
|
|
@@ -10,8 +10,8 @@ import type { BuilderDelegate } from '../builder/builder.ts';
|
|
|
10
10
|
* that adapts from the normal `Operator` `Output`, to the
|
|
11
11
|
* `FilterOperator` `FilterInput`, and ends with a `FilterEnd` operator that
|
|
12
12
|
* adapts from a `FilterOperator` `FilterOutput` to a normal `Operator` `Input`.
|
|
13
|
-
* `FilterOperator'
|
|
14
|
-
* `filter(node: Node
|
|
13
|
+
* `FilterOperator`'s do not have `fetch` instead they have a
|
|
14
|
+
* `filter(node: Node): boolean` method.
|
|
15
15
|
* They also have `push` which is just like normal `Operator` push.
|
|
16
16
|
* Not having a `fetch` means these `FilterOperator`'s cannot modify
|
|
17
17
|
* `Node` `row`s or `relationship`s, but they shouldn't, they should just
|
|
@@ -28,7 +28,7 @@ export interface FilterInput extends InputBase {
|
|
|
28
28
|
}
|
|
29
29
|
export interface FilterOutput extends Output {
|
|
30
30
|
beginFilter(): void;
|
|
31
|
-
filter(node: Node
|
|
31
|
+
filter(node: Node): boolean;
|
|
32
32
|
endFilter(): void;
|
|
33
33
|
}
|
|
34
34
|
export interface FilterOperator extends FilterInput, FilterOutput {
|
|
@@ -47,7 +47,6 @@ export declare class FilterStart implements FilterInput, Output {
|
|
|
47
47
|
getSchema(): SourceSchema;
|
|
48
48
|
push(change: Change): void;
|
|
49
49
|
fetch(req: FetchRequest): Stream<Node | 'yield'>;
|
|
50
|
-
cleanup(req: FetchRequest): Stream<Node>;
|
|
51
50
|
}
|
|
52
51
|
export declare class FilterEnd implements Input, FilterOutput {
|
|
53
52
|
#private;
|
|
@@ -55,8 +54,7 @@ export declare class FilterEnd implements Input, FilterOutput {
|
|
|
55
54
|
fetch(req: FetchRequest): Stream<Node | 'yield'>;
|
|
56
55
|
beginFilter(): void;
|
|
57
56
|
endFilter(): void;
|
|
58
|
-
|
|
59
|
-
filter(_node: Node, _cleanup: boolean): boolean;
|
|
57
|
+
filter(_node: Node): boolean;
|
|
60
58
|
setOutput(output: Output): void;
|
|
61
59
|
destroy(): void;
|
|
62
60
|
getSchema(): SourceSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-operators.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/filter-operators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,
|
|
1
|
+
{"version":3,"file":"filter-operators.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/filter-operators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;A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,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "compare-utf8";
|
|
2
2
|
const throwFilterOutput = {
|
|
3
3
|
push(_change) {
|
|
4
4
|
throw new Error("Output not set");
|
|
5
5
|
},
|
|
6
|
-
filter(_node
|
|
6
|
+
filter(_node) {
|
|
7
7
|
throw new Error("Output not set");
|
|
8
8
|
},
|
|
9
9
|
beginFilter() {
|
|
@@ -32,27 +32,19 @@ class FilterStart {
|
|
|
32
32
|
}
|
|
33
33
|
*fetch(req) {
|
|
34
34
|
this.#output.beginFilter();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
yield
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.#output.endFilter();
|
|
45
|
-
}
|
|
46
|
-
*cleanup(req) {
|
|
47
|
-
this.#output.beginFilter();
|
|
48
|
-
for (const node of this.#input.cleanup(req)) {
|
|
49
|
-
if (this.#output.filter(node, true)) {
|
|
50
|
-
yield node;
|
|
51
|
-
} else {
|
|
52
|
-
drainStreams(node);
|
|
35
|
+
try {
|
|
36
|
+
for (const node of this.#input.fetch(req)) {
|
|
37
|
+
if (node === "yield") {
|
|
38
|
+
yield node;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (this.#output.filter(node)) {
|
|
42
|
+
yield node;
|
|
43
|
+
}
|
|
53
44
|
}
|
|
45
|
+
} finally {
|
|
46
|
+
this.#output.endFilter();
|
|
54
47
|
}
|
|
55
|
-
this.#output.endFilter();
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
class FilterEnd {
|
|
@@ -73,12 +65,7 @@ class FilterEnd {
|
|
|
73
65
|
}
|
|
74
66
|
endFilter() {
|
|
75
67
|
}
|
|
76
|
-
|
|
77
|
-
for (const node of this.#start.cleanup(req)) {
|
|
78
|
-
yield node;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
filter(_node, _cleanup) {
|
|
68
|
+
filter(_node) {
|
|
82
69
|
return true;
|
|
83
70
|
}
|
|
84
71
|
setOutput(output) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-operators.js","sources":["../../../../../zql/src/ivm/filter-operators.ts"],"sourcesContent":["import type {FetchRequest, Input, InputBase, Output} from './operator.ts';\nimport {
|
|
1
|
+
{"version":3,"file":"filter-operators.js","sources":["../../../../../zql/src/ivm/filter-operators.ts"],"sourcesContent":["import type {FetchRequest, Input, InputBase, Output} from './operator.ts';\nimport {type Node} from './data.ts';\nimport type {Change} from './change.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\nimport type {BuilderDelegate} from '../builder/builder.ts';\n\n/**\n * The `where` clause of a ZQL query is implemented using a sub-graph of\n * `FilterOperators`. This sub-graph starts with a `FilterStart` operator,\n * that adapts from the normal `Operator` `Output`, to the\n * `FilterOperator` `FilterInput`, and ends with a `FilterEnd` operator that\n * adapts from a `FilterOperator` `FilterOutput` to a normal `Operator` `Input`.\n * `FilterOperator`'s do not have `fetch` instead they have a\n * `filter(node: Node): boolean` method.\n * They also have `push` which is just like normal `Operator` push.\n * Not having a `fetch` means these `FilterOperator`'s cannot modify\n * `Node` `row`s or `relationship`s, but they shouldn't, they should just\n * filter.\n *\n * This `FilterOperator` abstraction enables much more efficient processing of\n * `fetch` for `where` clauses containing OR conditions.\n *\n * See https://github.com/rocicorp/mono/pull/4339\n */\n\nexport interface FilterInput extends InputBase {\n /** Tell the input where to send its output. */\n setFilterOutput(output: FilterOutput): void;\n}\n\nexport interface FilterOutput extends Output {\n // Lets the operator know that we're in a loop of filtering\n // nodes. E.g., so the operator can cache results for the\n // duration of the loop.\n beginFilter(): void;\n filter(node: Node): boolean;\n endFilter(): void;\n}\n\nexport interface FilterOperator extends FilterInput, FilterOutput {}\n\n/**\n * An implementation of FilterOutput that throws if push or filter is called.\n * It is used as the initial value for for an operator's output before it is\n * set.\n */\nexport const throwFilterOutput: FilterOutput = {\n push(_change: Change): void {\n throw new Error('Output not set');\n },\n\n filter(_node: Node): boolean {\n throw new Error('Output not set');\n },\n\n beginFilter() {},\n endFilter() {},\n};\n\nexport class FilterStart implements FilterInput, Output {\n readonly #input: Input;\n #output: FilterOutput = throwFilterOutput;\n\n constructor(input: Input) {\n this.#input = input;\n input.setOutput(this);\n }\n\n setFilterOutput(output: FilterOutput) {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n push(change: Change) {\n this.#output.push(change, this);\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n this.#output.beginFilter();\n try {\n for (const node of this.#input.fetch(req)) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (this.#output.filter(node)) {\n yield node;\n }\n }\n } finally {\n // finally is important if an exception is thrown or\n // if the stream is not fully consumed.\n this.#output.endFilter();\n }\n }\n}\n\nexport class FilterEnd implements Input, FilterOutput {\n readonly #start: FilterStart;\n readonly #input: FilterInput;\n\n #output: Output = throwFilterOutput;\n\n constructor(start: FilterStart, input: FilterInput) {\n this.#start = start;\n this.#input = input;\n input.setFilterOutput(this);\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n for (const node of this.#start.fetch(req)) {\n yield node;\n }\n }\n\n beginFilter() {}\n endFilter() {}\n\n filter(_node: Node) {\n return true;\n }\n\n setOutput(output: Output) {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n push(change: Change) {\n this.#output.push(change, this);\n }\n}\n\nexport function buildFilterPipeline(\n input: Input,\n delegate: BuilderDelegate,\n pipeline: (filterInput: FilterInput) => FilterInput,\n): Input {\n const filterStart = new FilterStart(input);\n delegate.addEdge(input, filterStart);\n const middle = pipeline(filterStart);\n delegate.addEdge(filterStart, middle);\n const filterEnd = new FilterEnd(filterStart, middle);\n delegate.addEdge(middle, filterEnd);\n return filterEnd;\n}\n"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c;AAAA,EAAC;AAAA,EACf,YAAY;AAAA,EAAC;AAAA,EAEb,OAAO,OAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAgB;AACxB,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,UAAgB;AACd,SAAK,OAAO,QAAA;AAAA,EACd;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,KAAK,QAAgB;AACnB,SAAK,QAAQ,KAAK,QAAQ,IAAI;AAAA,EAChC;AACF;AAEO,SAAS,oBACd,OACA,UACA,UACO;AACP,QAAM,cAAc,IAAI,YAAY,KAAK;AACzC,WAAS,QAAQ,OAAO,WAAW;AACnC,QAAM,SAAS,SAAS,WAAW;AACnC,WAAS,QAAQ,aAAa,MAAM;AACpC,QAAM,YAAY,IAAI,UAAU,aAAa,MAAM;AACnD,WAAS,QAAQ,QAAQ,SAAS;AAClC,SAAO;AACT;"}
|
|
@@ -13,7 +13,7 @@ export declare class Filter implements FilterOperator {
|
|
|
13
13
|
constructor(input: FilterInput, predicate: (row: Row) => boolean);
|
|
14
14
|
beginFilter(): void;
|
|
15
15
|
endFilter(): void;
|
|
16
|
-
filter(node: Node
|
|
16
|
+
filter(node: Node): boolean;
|
|
17
17
|
setFilterOutput(output: FilterOutput): void;
|
|
18
18
|
destroy(): void;
|
|
19
19
|
getSchema(): SourceSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAE9C;;;;GAIG;AACH,qBAAa,MAAO,YAAW,cAAc;;gBAM/B,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO;IAMhE,WAAW,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAE9C;;;;GAIG;AACH,qBAAa,MAAO,YAAW,cAAc;;gBAM/B,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO;IAMhE,WAAW,IAAI,IAAI;IAInB,SAAS,IAAI,IAAI;IAIjB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI3B,eAAe,CAAC,MAAM,EAAE,YAAY;IAIpC,OAAO,IAAI,IAAI;IAIf,SAAS,IAAI,YAAY;IAIzB,IAAI,CAAC,MAAM,EAAE,MAAM;CAGpB"}
|
|
@@ -11,11 +11,13 @@ class Filter {
|
|
|
11
11
|
input.setFilterOutput(this);
|
|
12
12
|
}
|
|
13
13
|
beginFilter() {
|
|
14
|
+
this.#output.beginFilter();
|
|
14
15
|
}
|
|
15
16
|
endFilter() {
|
|
17
|
+
this.#output.endFilter();
|
|
16
18
|
}
|
|
17
|
-
filter(node
|
|
18
|
-
return this.#predicate(node.row) && this.#output.filter(node
|
|
19
|
+
filter(node) {
|
|
20
|
+
return this.#predicate(node.row) && this.#output.filter(node);
|
|
19
21
|
}
|
|
20
22
|
setFilterOutput(output) {
|
|
21
23
|
this.#output = output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sources":["../../../../../zql/src/ivm/filter.ts"],"sourcesContent":["import type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport {filterPush} from './filter-push.ts';\nimport {type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The Filter operator filters data through a predicate. It is stateless.\n *\n * The predicate must be pure.\n */\nexport class Filter implements FilterOperator {\n readonly #input: FilterInput;\n readonly #predicate: (row: Row) => boolean;\n\n #output: FilterOutput = throwFilterOutput;\n\n constructor(input: FilterInput, predicate: (row: Row) => boolean) {\n this.#input = input;\n this.#predicate = predicate;\n input.setFilterOutput(this);\n }\n\n beginFilter(): void {}\n\n endFilter(): void {}\n\n filter(node: Node
|
|
1
|
+
{"version":3,"file":"filter.js","sources":["../../../../../zql/src/ivm/filter.ts"],"sourcesContent":["import type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport {\n throwFilterOutput,\n type FilterInput,\n type FilterOperator,\n type FilterOutput,\n} from './filter-operators.ts';\nimport {filterPush} from './filter-push.ts';\nimport {type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\n\n/**\n * The Filter operator filters data through a predicate. It is stateless.\n *\n * The predicate must be pure.\n */\nexport class Filter implements FilterOperator {\n readonly #input: FilterInput;\n readonly #predicate: (row: Row) => boolean;\n\n #output: FilterOutput = throwFilterOutput;\n\n constructor(input: FilterInput, predicate: (row: Row) => boolean) {\n this.#input = input;\n this.#predicate = predicate;\n input.setFilterOutput(this);\n }\n\n beginFilter(): void {\n this.#output.beginFilter();\n }\n\n endFilter(): void {\n this.#output.endFilter();\n }\n\n filter(node: Node): boolean {\n return this.#predicate(node.row) && this.#output.filter(node);\n }\n\n setFilterOutput(output: FilterOutput) {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n push(change: Change) {\n filterPush(change, this.#output, this, this.#predicate);\n }\n}\n"],"names":[],"mappings":";;;AAiBO,MAAM,OAAiC;AAAA,EACnC;AAAA,EACA;AAAA,EAET,UAAwB;AAAA,EAExB,YAAY,OAAoB,WAAkC;AAChE,SAAK,SAAS;AACd,SAAK,aAAa;AAClB,UAAM,gBAAgB,IAAI;AAAA,EAC5B;AAAA,EAEA,cAAoB;AAClB,SAAK,QAAQ,YAAA;AAAA,EACf;AAAA,EAEA,YAAkB;AAChB,SAAK,QAAQ,UAAA;AAAA,EACf;AAAA,EAEA,OAAO,MAAqB;AAC1B,WAAO,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,OAAO,IAAI;AAAA,EAC9D;AAAA,EAEA,gBAAgB,QAAsB;AACpC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,UAAgB;AACd,SAAK,OAAO,QAAA;AAAA,EACd;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,KAAK,QAAgB;AACnB,eAAW,QAAQ,KAAK,SAAS,MAAM,KAAK,UAAU;AAAA,EACxD;AACF;"}
|
|
@@ -27,7 +27,6 @@ export declare class FlippedJoin implements Input {
|
|
|
27
27
|
setOutput(output: Output): void;
|
|
28
28
|
getSchema(): SourceSchema;
|
|
29
29
|
fetch(req: FetchRequest): Stream<Node | 'yield'>;
|
|
30
|
-
cleanup(_req: FetchRequest): Stream<Node>;
|
|
31
30
|
}
|
|
32
31
|
export {};
|
|
33
32
|
//# sourceMappingURL=flipped-join.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flipped-join.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/flipped-join.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAI3E,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAOpC,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAQ,KAAK,MAAM,EAAC,MAAM,aAAa,CAAC;AAE/C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;IAEb,SAAS,EAAE,WAAW,CAAC;IACvB,QAAQ,EAAE,WAAW,CAAC;IAEtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,KAAK;;gBAY3B,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,MAAM,GACP,EAAE,IAAI;IAkCP,OAAO,IAAI,IAAI;IAKf,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,SAAS,IAAI,YAAY;IAQxB,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"flipped-join.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/flipped-join.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAI3E,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAOpC,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,KAAK,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