@tanstack/db-ivm 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/d2.cjs +1 -8
- package/dist/cjs/d2.cjs.map +1 -1
- package/dist/cjs/d2.d.cts +0 -1
- package/dist/cjs/operators/concat.cjs +0 -1
- package/dist/cjs/operators/concat.cjs.map +1 -1
- package/dist/cjs/operators/consolidate.cjs +0 -1
- package/dist/cjs/operators/consolidate.cjs.map +1 -1
- package/dist/cjs/operators/count.cjs +0 -1
- package/dist/cjs/operators/count.cjs.map +1 -1
- package/dist/cjs/operators/debug.cjs +0 -1
- package/dist/cjs/operators/debug.cjs.map +1 -1
- package/dist/cjs/operators/distinct.cjs +0 -1
- package/dist/cjs/operators/distinct.cjs.map +1 -1
- package/dist/cjs/operators/filter.cjs +0 -1
- package/dist/cjs/operators/filter.cjs.map +1 -1
- package/dist/cjs/operators/join.cjs +0 -1
- package/dist/cjs/operators/join.cjs.map +1 -1
- package/dist/cjs/operators/map.cjs +0 -1
- package/dist/cjs/operators/map.cjs.map +1 -1
- package/dist/cjs/operators/negate.cjs +0 -1
- package/dist/cjs/operators/negate.cjs.map +1 -1
- package/dist/cjs/operators/output.cjs +0 -1
- package/dist/cjs/operators/output.cjs.map +1 -1
- package/dist/cjs/operators/reduce.cjs +0 -1
- package/dist/cjs/operators/reduce.cjs.map +1 -1
- package/dist/cjs/operators/tap.cjs +2 -5
- package/dist/cjs/operators/tap.cjs.map +1 -1
- package/dist/cjs/operators/tap.d.cts +5 -5
- package/dist/cjs/operators/topKWithFractionalIndex.cjs +0 -1
- package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -1
- package/dist/cjs/types.d.cts +0 -1
- package/dist/esm/d2.d.ts +0 -1
- package/dist/esm/d2.js +1 -8
- package/dist/esm/d2.js.map +1 -1
- package/dist/esm/operators/concat.js +0 -1
- package/dist/esm/operators/concat.js.map +1 -1
- package/dist/esm/operators/consolidate.js +0 -1
- package/dist/esm/operators/consolidate.js.map +1 -1
- package/dist/esm/operators/count.js +0 -1
- package/dist/esm/operators/count.js.map +1 -1
- package/dist/esm/operators/debug.js +0 -1
- package/dist/esm/operators/debug.js.map +1 -1
- package/dist/esm/operators/distinct.js +0 -1
- package/dist/esm/operators/distinct.js.map +1 -1
- package/dist/esm/operators/filter.js +0 -1
- package/dist/esm/operators/filter.js.map +1 -1
- package/dist/esm/operators/join.js +0 -1
- package/dist/esm/operators/join.js.map +1 -1
- package/dist/esm/operators/map.js +0 -1
- package/dist/esm/operators/map.js.map +1 -1
- package/dist/esm/operators/negate.js +0 -1
- package/dist/esm/operators/negate.js.map +1 -1
- package/dist/esm/operators/output.js +0 -1
- package/dist/esm/operators/output.js.map +1 -1
- package/dist/esm/operators/reduce.js +0 -1
- package/dist/esm/operators/reduce.js.map +1 -1
- package/dist/esm/operators/tap.d.ts +5 -5
- package/dist/esm/operators/tap.js +2 -5
- package/dist/esm/operators/tap.js.map +1 -1
- package/dist/esm/operators/topKWithFractionalIndex.js +0 -1
- package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -1
- package/dist/esm/types.d.ts +0 -1
- package/package.json +1 -1
- package/src/d2.ts +0 -7
- package/src/operators/concat.ts +0 -1
- package/src/operators/consolidate.ts +0 -1
- package/src/operators/count.ts +0 -1
- package/src/operators/debug.ts +0 -1
- package/src/operators/distinct.ts +0 -1
- package/src/operators/filter.ts +0 -1
- package/src/operators/join.ts +0 -1
- package/src/operators/map.ts +0 -1
- package/src/operators/negate.ts +0 -1
- package/src/operators/output.ts +0 -1
- package/src/operators/reduce.ts +0 -1
- package/src/operators/tap.ts +8 -11
- package/src/operators/topKWithFractionalIndex.ts +0 -1
- package/src/operators/topKWithFractionalIndexBTree.ts +0 -1
- package/src/types.ts +0 -1
package/dist/cjs/d2.cjs
CHANGED
|
@@ -15,13 +15,12 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
15
15
|
return __privateGet(obj, member, getter);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
var
|
|
18
|
+
var _operators, _nextOperatorId, _finalized, _D2_instances, checkNotFinalized_fn, _graph, _writer;
|
|
19
19
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
20
20
|
const graph = require("./graph.cjs");
|
|
21
21
|
class D2 {
|
|
22
22
|
constructor() {
|
|
23
23
|
__privateAdd(this, _D2_instances);
|
|
24
|
-
__privateAdd(this, _streams, []);
|
|
25
24
|
__privateAdd(this, _operators, []);
|
|
26
25
|
__privateAdd(this, _nextOperatorId, 0);
|
|
27
26
|
__privateAdd(this, _finalized, false);
|
|
@@ -34,17 +33,12 @@ class D2 {
|
|
|
34
33
|
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
35
34
|
const writer = new graph.DifferenceStreamWriter();
|
|
36
35
|
const streamBuilder = new RootStreamBuilder(this, writer);
|
|
37
|
-
__privateGet(this, _streams).push(streamBuilder.connectReader());
|
|
38
36
|
return streamBuilder;
|
|
39
37
|
}
|
|
40
38
|
addOperator(operator) {
|
|
41
39
|
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
42
40
|
__privateGet(this, _operators).push(operator);
|
|
43
41
|
}
|
|
44
|
-
addStream(stream) {
|
|
45
|
-
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
46
|
-
__privateGet(this, _streams).push(stream);
|
|
47
|
-
}
|
|
48
42
|
finalize() {
|
|
49
43
|
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
50
44
|
__privateSet(this, _finalized, true);
|
|
@@ -66,7 +60,6 @@ class D2 {
|
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
|
-
_streams = new WeakMap();
|
|
70
63
|
_operators = new WeakMap();
|
|
71
64
|
_nextOperatorId = new WeakMap();
|
|
72
65
|
_finalized = new WeakMap();
|
package/dist/cjs/d2.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d2.cjs","sources":["../../src/d2.ts"],"sourcesContent":["import { DifferenceStreamWriter } from \"./graph.js\"\nimport type {\n BinaryOperator,\n DifferenceStreamReader,\n UnaryOperator,\n} from \"./graph.js\"\nimport type { MultiSet, MultiSetArray } from \"./multiset.js\"\nimport type { ID2, IStreamBuilder, PipedOperator } from \"./types.js\"\n\nexport class D2 implements ID2 {\n #streams: Array<DifferenceStreamReader<any>> = []\n #operators: Array<UnaryOperator<any> | BinaryOperator<any>> = []\n #nextOperatorId = 0\n #finalized = false\n\n constructor() {}\n\n #checkNotFinalized(): void {\n if (this.#finalized) {\n throw new Error(`Graph already finalized`)\n }\n }\n\n getNextOperatorId(): number {\n this.#checkNotFinalized()\n return this.#nextOperatorId++\n }\n\n newInput<T>(): RootStreamBuilder<T> {\n this.#checkNotFinalized()\n const writer = new DifferenceStreamWriter<T>()\n // Use the root stream builder that exposes the sendData and sendFrontier methods\n const streamBuilder = new RootStreamBuilder<T>(this, writer)\n this.#streams.push(streamBuilder.connectReader())\n return streamBuilder\n }\n\n addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void {\n this.#checkNotFinalized()\n this.#operators.push(operator)\n }\n\n addStream(stream: DifferenceStreamReader<any>): void {\n this.#checkNotFinalized()\n this.#streams.push(stream)\n }\n\n finalize() {\n this.#checkNotFinalized()\n this.#finalized = true\n }\n\n step(): void {\n if (!this.#finalized) {\n throw new Error(`Graph not finalized`)\n }\n for (const op of this.#operators) {\n op.run()\n }\n }\n\n pendingWork(): boolean {\n return this.#operators.some((op) => op.hasPendingWork())\n }\n\n run(): void {\n while (this.pendingWork()) {\n this.step()\n }\n }\n}\n\nexport class StreamBuilder<T> implements IStreamBuilder<T> {\n #graph: ID2\n #writer: DifferenceStreamWriter<T>\n\n constructor(graph: ID2, writer: DifferenceStreamWriter<T>) {\n this.#graph = graph\n this.#writer = writer\n }\n\n connectReader(): DifferenceStreamReader<T> {\n return this.#writer.newReader()\n }\n\n get writer(): DifferenceStreamWriter<T> {\n return this.#writer\n }\n\n get graph(): ID2 {\n return this.#graph\n }\n\n // Don't judge, this is the only way to type this function.\n // rxjs has very similar code to type its pipe function\n // https://github.com/ReactiveX/rxjs/blob/master/packages/rxjs/src/internal/util/pipe.ts\n // We go to 20 operators deep, because surly that's enough for anyone...\n // A user can always split the pipe into multiple pipes to get around this.\n pipe<O>(o1: PipedOperator<T, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, T20>, o20: PipedOperator<T20, O>): IStreamBuilder<O>\n\n pipe(...operators: Array<PipedOperator<any, any>>): IStreamBuilder<any> {\n return operators.reduce((stream, operator) => {\n return operator(stream)\n }, this as IStreamBuilder<any>)\n }\n}\n\nexport class RootStreamBuilder<T> extends StreamBuilder<T> {\n sendData(collection: MultiSet<T> | MultiSetArray<T>): void {\n this.writer.sendData(collection)\n }\n}\n"],"names":["DifferenceStreamWriter","graph"],"mappings":";;;;;;;;;;;;;;;;;;;;AASO,MAAM,GAA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AAK,SAAQ,UAAA;AAAA,EACtB;AAAA,EAEA,IAAI,SAAoC;AACtC,WAAO,mBAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAa;AACf,WAAO,mBAAK;AAAA,EACd;AAAA,EA+CA,QAAQ,WAAgE;AACtE,WAAO,UAAU,OAAO,CAAC,QAAQ,aAAa;AAC5C,aAAO,SAAS,MAAM;AAAA,IACxB,GAAG,IAA2B;AAAA,EAChC;AACF;AAtEE;AACA;AAuEK,MAAM,0BAA6B,cAAiB;AAAA,EACzD,SAAS,YAAkD;AACzD,SAAK,OAAO,SAAS,UAAU;AAAA,EACjC;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"d2.cjs","sources":["../../src/d2.ts"],"sourcesContent":["import { DifferenceStreamWriter } from \"./graph.js\"\nimport type {\n BinaryOperator,\n DifferenceStreamReader,\n UnaryOperator,\n} from \"./graph.js\"\nimport type { MultiSet, MultiSetArray } from \"./multiset.js\"\nimport type { ID2, IStreamBuilder, PipedOperator } from \"./types.js\"\n\nexport class D2 implements ID2 {\n #operators: Array<UnaryOperator<any> | BinaryOperator<any>> = []\n #nextOperatorId = 0\n #finalized = false\n\n constructor() {}\n\n #checkNotFinalized(): void {\n if (this.#finalized) {\n throw new Error(`Graph already finalized`)\n }\n }\n\n getNextOperatorId(): number {\n this.#checkNotFinalized()\n return this.#nextOperatorId++\n }\n\n newInput<T>(): RootStreamBuilder<T> {\n this.#checkNotFinalized()\n const writer = new DifferenceStreamWriter<T>()\n // Use the root stream builder that exposes the sendData and sendFrontier methods\n const streamBuilder = new RootStreamBuilder<T>(this, writer)\n return streamBuilder\n }\n\n addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void {\n this.#checkNotFinalized()\n this.#operators.push(operator)\n }\n\n finalize() {\n this.#checkNotFinalized()\n this.#finalized = true\n }\n\n step(): void {\n if (!this.#finalized) {\n throw new Error(`Graph not finalized`)\n }\n for (const op of this.#operators) {\n op.run()\n }\n }\n\n pendingWork(): boolean {\n return this.#operators.some((op) => op.hasPendingWork())\n }\n\n run(): void {\n while (this.pendingWork()) {\n this.step()\n }\n }\n}\n\nexport class StreamBuilder<T> implements IStreamBuilder<T> {\n #graph: ID2\n #writer: DifferenceStreamWriter<T>\n\n constructor(graph: ID2, writer: DifferenceStreamWriter<T>) {\n this.#graph = graph\n this.#writer = writer\n }\n\n connectReader(): DifferenceStreamReader<T> {\n return this.#writer.newReader()\n }\n\n get writer(): DifferenceStreamWriter<T> {\n return this.#writer\n }\n\n get graph(): ID2 {\n return this.#graph\n }\n\n // Don't judge, this is the only way to type this function.\n // rxjs has very similar code to type its pipe function\n // https://github.com/ReactiveX/rxjs/blob/master/packages/rxjs/src/internal/util/pipe.ts\n // We go to 20 operators deep, because surly that's enough for anyone...\n // A user can always split the pipe into multiple pipes to get around this.\n pipe<O>(o1: PipedOperator<T, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, T20>, o20: PipedOperator<T20, O>): IStreamBuilder<O>\n\n pipe(...operators: Array<PipedOperator<any, any>>): IStreamBuilder<any> {\n return operators.reduce((stream, operator) => {\n return operator(stream)\n }, this as IStreamBuilder<any>)\n }\n}\n\nexport class RootStreamBuilder<T> extends StreamBuilder<T> {\n sendData(collection: MultiSet<T> | MultiSetArray<T>): void {\n this.writer.sendData(collection)\n }\n}\n"],"names":["DifferenceStreamWriter","graph"],"mappings":";;;;;;;;;;;;;;;;;;;;AASO,MAAM,GAAkB;AAAA,EAK7B,cAAc;AALT;AACL,mCAA8D,CAAA;AAC9D,wCAAkB;AAClB,mCAAa;AAAA,EAEE;AAAA,EAQf,oBAA4B;AAC1B,0BAAK,qCAAL;AACA,WAAO,uBAAK,iBAAL;AAAA,EACT;AAAA,EAEA,WAAoC;AAClC,0BAAK,qCAAL;AACA,UAAM,SAAS,IAAIA,6BAAA;AAEnB,UAAM,gBAAgB,IAAI,kBAAqB,MAAM,MAAM;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,UAA0D;AACpE,0BAAK,qCAAL;AACA,uBAAK,YAAW,KAAK,QAAQ;AAAA,EAC/B;AAAA,EAEA,WAAW;AACT,0BAAK,qCAAL;AACA,uBAAK,YAAa;AAAA,EACpB;AAAA,EAEA,OAAa;AACX,QAAI,CAAC,mBAAK,aAAY;AACpB,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AACA,eAAW,MAAM,mBAAK,aAAY;AAChC,SAAG,IAAA;AAAA,IACL;AAAA,EACF;AAAA,EAEA,cAAuB;AACrB,WAAO,mBAAK,YAAW,KAAK,CAAC,OAAO,GAAG,gBAAgB;AAAA,EACzD;AAAA,EAEA,MAAY;AACV,WAAO,KAAK,eAAe;AACzB,WAAK,KAAA;AAAA,IACP;AAAA,EACF;AACF;AArDE;AACA;AACA;AAHK;AAOL,uBAAA,WAA2B;AACzB,MAAI,mBAAK,aAAY;AACnB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACF;AA6CK,MAAM,cAA8C;AAAA,EAIzD,YAAYC,QAAY,QAAmC;AAH3D;AACA;AAGE,uBAAK,QAASA;AACd,uBAAK,SAAU;AAAA,EACjB;AAAA,EAEA,gBAA2C;AACzC,WAAO,mBAAK,SAAQ,UAAA;AAAA,EACtB;AAAA,EAEA,IAAI,SAAoC;AACtC,WAAO,mBAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAa;AACf,WAAO,mBAAK;AAAA,EACd;AAAA,EA+CA,QAAQ,WAAgE;AACtE,WAAO,UAAU,OAAO,CAAC,QAAQ,aAAa;AAC5C,aAAO,SAAS,MAAM;AAAA,IACxB,GAAG,IAA2B;AAAA,EAChC;AACF;AAtEE;AACA;AAuEK,MAAM,0BAA6B,cAAiB;AAAA,EACzD,SAAS,YAAkD;AACzD,SAAK,OAAO,SAAS,UAAU;AAAA,EACjC;AACF;;;;"}
|
package/dist/cjs/d2.d.cts
CHANGED
|
@@ -7,7 +7,6 @@ export declare class D2 implements ID2 {
|
|
|
7
7
|
getNextOperatorId(): number;
|
|
8
8
|
newInput<T>(): RootStreamBuilder<T>;
|
|
9
9
|
addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void;
|
|
10
|
-
addStream(stream: DifferenceStreamReader<any>): void;
|
|
11
10
|
finalize(): void;
|
|
12
11
|
step(): void;
|
|
13
12
|
pendingWork(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat.cjs","sources":["../../../src/operators/concat.ts"],"sourcesContent":["import { BinaryOperator, DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\n\n/**\n * Operator that concatenates two input streams\n */\nexport class ConcatOperator<T, T2> extends BinaryOperator<T | T2> {\n run(): void {\n for (const message of this.inputAMessages()) {\n this.output.sendData(message)\n }\n\n for (const message of this.inputBMessages()) {\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Concatenates two input streams\n * @param other - The other stream to concatenate\n */\nexport function concat<T, T2>(\n other: IStreamBuilder<T2>\n): PipedOperator<T, T | T2> {\n return (stream: IStreamBuilder<T | T2>): IStreamBuilder<T | T2> => {\n if (stream.graph !== other.graph) {\n throw new Error(`Cannot concat streams from different graphs`)\n }\n const output = new StreamBuilder<T | T2>(\n stream.graph,\n new DifferenceStreamWriter<T | T2>()\n )\n const operator = new ConcatOperator<T, T2>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n other.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"concat.cjs","sources":["../../../src/operators/concat.ts"],"sourcesContent":["import { BinaryOperator, DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\n\n/**\n * Operator that concatenates two input streams\n */\nexport class ConcatOperator<T, T2> extends BinaryOperator<T | T2> {\n run(): void {\n for (const message of this.inputAMessages()) {\n this.output.sendData(message)\n }\n\n for (const message of this.inputBMessages()) {\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Concatenates two input streams\n * @param other - The other stream to concatenate\n */\nexport function concat<T, T2>(\n other: IStreamBuilder<T2>\n): PipedOperator<T, T | T2> {\n return (stream: IStreamBuilder<T | T2>): IStreamBuilder<T | T2> => {\n if (stream.graph !== other.graph) {\n throw new Error(`Cannot concat streams from different graphs`)\n }\n const output = new StreamBuilder<T | T2>(\n stream.graph,\n new DifferenceStreamWriter<T | T2>()\n )\n const operator = new ConcatOperator<T, T2>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n other.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["BinaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;AAOO,MAAM,uBAA8BA,MAAAA,eAAuB;AAAA,EAChE,MAAY;AACV,eAAW,WAAW,KAAK,kBAAkB;AAC3C,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAEA,eAAW,WAAW,KAAK,kBAAkB;AAC3C,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AAMO,SAAS,OACd,OAC0B;AAC1B,SAAO,CAAC,WAA2D;AACjE,QAAI,OAAO,UAAU,MAAM,OAAO;AAChC,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA+B;AAErC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,MAAM,cAAA;AAAA,MACN,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consolidate.cjs","sources":["../../../src/operators/consolidate.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\n\n/**\n * Operator that consolidates collections\n */\nexport class ConsolidateOperator<T> extends UnaryOperator<T> {\n run(): void {\n const messages = this.inputMessages()\n if (messages.length === 0) {\n return\n }\n\n // Combine all messages into a single MultiSet\n const combined = new MultiSet<T>()\n for (const message of messages) {\n combined.extend(message)\n }\n\n // Consolidate the combined MultiSet\n const consolidated = combined.consolidate()\n\n // Only send if there are results\n if (consolidated.getInner().length > 0) {\n this.output.sendData(consolidated)\n }\n }\n}\n\n/**\n * Consolidates the elements in the stream\n */\nexport function consolidate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new ConsolidateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"consolidate.cjs","sources":["../../../src/operators/consolidate.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\n\n/**\n * Operator that consolidates collections\n */\nexport class ConsolidateOperator<T> extends UnaryOperator<T> {\n run(): void {\n const messages = this.inputMessages()\n if (messages.length === 0) {\n return\n }\n\n // Combine all messages into a single MultiSet\n const combined = new MultiSet<T>()\n for (const message of messages) {\n combined.extend(message)\n }\n\n // Consolidate the combined MultiSet\n const consolidated = combined.consolidate()\n\n // Only send if there are results\n if (consolidated.getInner().length > 0) {\n this.output.sendData(consolidated)\n }\n }\n}\n\n/**\n * Consolidates the elements in the stream\n */\nexport function consolidate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new ConsolidateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["UnaryOperator","MultiSet","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;AAQO,MAAM,4BAA+BA,MAAAA,cAAiB;AAAA,EAC3D,MAAY;AACV,UAAM,WAAW,KAAK,cAAA;AACtB,QAAI,SAAS,WAAW,GAAG;AACzB;AAAA,IACF;AAGA,UAAM,WAAW,IAAIC,kBAAA;AACrB,eAAW,WAAW,UAAU;AAC9B,eAAS,OAAO,OAAO;AAAA,IACzB;AAGA,UAAM,eAAe,SAAS,YAAA;AAG9B,QAAI,aAAa,WAAW,SAAS,GAAG;AACtC,WAAK,OAAO,SAAS,YAAY;AAAA,IACnC;AAAA,EACF;AACF;AAKO,SAAS,cAAsC;AACpD,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.cjs","sources":["../../../src/operators/count.ts"],"sourcesContent":["import { DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { ReduceOperator } from \"./reduce.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue } from \"../types.js\"\n\n/**\n * Operator that counts elements by key (version-free)\n */\nexport class CountOperator<K, V> extends ReduceOperator<K, V, number> {\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V]>,\n output: DifferenceStreamWriter<[K, number]>\n ) {\n const countInner = (vals: Array<[V, number]>): Array<[number, number]> => {\n let totalCount = 0\n for (const [_, diff] of vals) {\n totalCount += diff\n }\n return [[totalCount, 1]]\n }\n\n super(id, inputA, output, countInner)\n }\n}\n\n/**\n * Counts the number of elements by key (version-free)\n */\nexport function count<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n VType extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>() {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<KType, number>> => {\n const output = new StreamBuilder<KeyValue<KType, number>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, number>>()\n )\n const operator = new CountOperator<KType, VType>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, VType>>,\n output.writer\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"count.cjs","sources":["../../../src/operators/count.ts"],"sourcesContent":["import { DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { ReduceOperator } from \"./reduce.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue } from \"../types.js\"\n\n/**\n * Operator that counts elements by key (version-free)\n */\nexport class CountOperator<K, V> extends ReduceOperator<K, V, number> {\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V]>,\n output: DifferenceStreamWriter<[K, number]>\n ) {\n const countInner = (vals: Array<[V, number]>): Array<[number, number]> => {\n let totalCount = 0\n for (const [_, diff] of vals) {\n totalCount += diff\n }\n return [[totalCount, 1]]\n }\n\n super(id, inputA, output, countInner)\n }\n}\n\n/**\n * Counts the number of elements by key (version-free)\n */\nexport function count<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n VType extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>() {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<KType, number>> => {\n const output = new StreamBuilder<KeyValue<KType, number>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, number>>()\n )\n const operator = new CountOperator<KType, VType>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, VType>>,\n output.writer\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["ReduceOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;AASO,MAAM,sBAA4BA,OAAAA,eAA6B;AAAA,EACpE,YACE,IACA,QACA,QACA;AACA,UAAM,aAAa,CAAC,SAAsD;AACxE,UAAI,aAAa;AACjB,iBAAW,CAAC,GAAG,IAAI,KAAK,MAAM;AAC5B,sBAAc;AAAA,MAChB;AACA,aAAO,CAAC,CAAC,YAAY,CAAC,CAAC;AAAA,IACzB;AAEA,UAAM,IAAI,QAAQ,QAAQ,UAAU;AAAA,EACtC;AACF;AAKO,SAAS,QAIZ;AACF,SAAO,CACL,WAC4C;AAC5C,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAAgD;AAEtD,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.cjs","sources":["../../../src/operators/debug.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\n\n/**\n * Operator that logs debug information about the stream\n */\nexport class DebugOperator<T> extends UnaryOperator<T> {\n #name: string\n #indent: boolean\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n name: string,\n indent: boolean = false\n ) {\n super(id, inputA, output)\n this.#name = name\n this.#indent = indent\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n console.log(`debug ${this.#name} data: ${message.toString(this.#indent)}`)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Logs debug information about the stream using console.log\n * @param name - The name to prefix debug messages with\n * @param indent - Whether to indent the debug output\n */\nexport function debug<T>(\n name: string,\n indent: boolean = false\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new DebugOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n name,\n indent\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"debug.cjs","sources":["../../../src/operators/debug.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\n\n/**\n * Operator that logs debug information about the stream\n */\nexport class DebugOperator<T> extends UnaryOperator<T> {\n #name: string\n #indent: boolean\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n name: string,\n indent: boolean = false\n ) {\n super(id, inputA, output)\n this.#name = name\n this.#indent = indent\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n console.log(`debug ${this.#name} data: ${message.toString(this.#indent)}`)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Logs debug information about the stream using console.log\n * @param name - The name to prefix debug messages with\n * @param indent - Whether to indent the debug output\n */\nexport function debug<T>(\n name: string,\n indent: boolean = false\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new DebugOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n name,\n indent\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["UnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AAQO,MAAM,sBAAyBA,MAAAA,cAAiB;AAAA,EAIrD,YACE,IACA,QACA,QACA,MACA,SAAkB,OAClB;AACA,UAAM,IAAI,QAAQ,MAAM;AAV1B;AACA;AAUE,uBAAK,OAAQ;AACb,uBAAK,SAAU;AAAA,EACjB;AAAA,EAEA,MAAY;AACV,eAAW,WAAW,KAAK,iBAAiB;AAC1C,cAAQ,IAAI,SAAS,mBAAK,MAAK,UAAU,QAAQ,SAAS,mBAAK,QAAO,CAAC,EAAE;AACzE,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AArBE;AACA;AA2BK,SAAS,MACd,MACA,SAAkB,OACG;AACrB,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distinct.cjs","sources":["../../../src/operators/distinct.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { hash } from \"../hashing/index.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport type { Hash } from \"../hashing/index.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder } from \"../types.js\"\n\ntype Multiplicity = number\n\n/**\n * Operator that removes duplicates\n */\nexport class DistinctOperator<T> extends UnaryOperator<T> {\n #by: (value: T) => any\n #values: Map<Hash, Multiplicity> // keeps track of the number of times each value has been seen\n\n constructor(\n id: number,\n input: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n by: (value: T) => any = (value: T) => value\n ) {\n super(id, input, output)\n this.#by = by\n this.#values = new Map()\n }\n\n run(): void {\n const updatedValues = new Map<Hash, [Multiplicity, T]>()\n\n // Compute the new multiplicity for each value\n for (const message of this.inputMessages()) {\n for (const [value, diff] of message.getInner()) {\n const hashedValue = hash(this.#by(value))\n\n const oldMultiplicity =\n updatedValues.get(hashedValue)?.[0] ??\n this.#values.get(hashedValue) ??\n 0\n const newMultiplicity = oldMultiplicity + diff\n\n updatedValues.set(hashedValue, [newMultiplicity, value])\n }\n }\n\n const result: Array<[T, number]> = []\n\n // Check which values became visible or disappeared\n for (const [\n hashedValue,\n [newMultiplicity, value],\n ] of updatedValues.entries()) {\n const oldMultiplicity = this.#values.get(hashedValue) ?? 0\n\n if (newMultiplicity === 0) {\n this.#values.delete(hashedValue)\n } else {\n this.#values.set(hashedValue, newMultiplicity)\n }\n\n if (oldMultiplicity <= 0 && newMultiplicity > 0) {\n // The value wasn't present in the stream\n // but with this change it is now present in the stream\n result.push([value, 1])\n } else if (oldMultiplicity > 0 && newMultiplicity <= 0) {\n // The value was present in the stream\n // but with this change it is no longer present in the stream\n result.push([value, -1])\n }\n }\n\n if (result.length > 0) {\n this.output.sendData(new MultiSet(result))\n }\n }\n}\n\n/**\n * Removes duplicate values\n */\nexport function distinct<T>(by: (value: T) => any = (value: T) => value) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new DistinctOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n by\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"distinct.cjs","sources":["../../../src/operators/distinct.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { hash } from \"../hashing/index.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport type { Hash } from \"../hashing/index.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder } from \"../types.js\"\n\ntype Multiplicity = number\n\n/**\n * Operator that removes duplicates\n */\nexport class DistinctOperator<T> extends UnaryOperator<T> {\n #by: (value: T) => any\n #values: Map<Hash, Multiplicity> // keeps track of the number of times each value has been seen\n\n constructor(\n id: number,\n input: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n by: (value: T) => any = (value: T) => value\n ) {\n super(id, input, output)\n this.#by = by\n this.#values = new Map()\n }\n\n run(): void {\n const updatedValues = new Map<Hash, [Multiplicity, T]>()\n\n // Compute the new multiplicity for each value\n for (const message of this.inputMessages()) {\n for (const [value, diff] of message.getInner()) {\n const hashedValue = hash(this.#by(value))\n\n const oldMultiplicity =\n updatedValues.get(hashedValue)?.[0] ??\n this.#values.get(hashedValue) ??\n 0\n const newMultiplicity = oldMultiplicity + diff\n\n updatedValues.set(hashedValue, [newMultiplicity, value])\n }\n }\n\n const result: Array<[T, number]> = []\n\n // Check which values became visible or disappeared\n for (const [\n hashedValue,\n [newMultiplicity, value],\n ] of updatedValues.entries()) {\n const oldMultiplicity = this.#values.get(hashedValue) ?? 0\n\n if (newMultiplicity === 0) {\n this.#values.delete(hashedValue)\n } else {\n this.#values.set(hashedValue, newMultiplicity)\n }\n\n if (oldMultiplicity <= 0 && newMultiplicity > 0) {\n // The value wasn't present in the stream\n // but with this change it is now present in the stream\n result.push([value, 1])\n } else if (oldMultiplicity > 0 && newMultiplicity <= 0) {\n // The value was present in the stream\n // but with this change it is no longer present in the stream\n result.push([value, -1])\n }\n }\n\n if (result.length > 0) {\n this.output.sendData(new MultiSet(result))\n }\n }\n}\n\n/**\n * Removes duplicate values\n */\nexport function distinct<T>(by: (value: T) => any = (value: T) => value) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new DistinctOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n by\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["UnaryOperator","hash","MultiSet","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;;;AAaO,MAAM,yBAA4BA,MAAAA,cAAiB;AAAA;AAAA,EAIxD,YACE,IACA,OACA,QACA,KAAwB,CAAC,UAAa,OACtC;AACA,UAAM,IAAI,OAAO,MAAM;AATzB;AACA;AASE,uBAAK,KAAM;AACX,uBAAK,6BAAc,IAAA;AAAA,EACrB;AAAA,EAEA,MAAY;;AACV,UAAM,oCAAoB,IAAA;AAG1B,eAAW,WAAW,KAAK,iBAAiB;AAC1C,iBAAW,CAAC,OAAO,IAAI,KAAK,QAAQ,YAAY;AAC9C,cAAM,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|
|
|
1
|
-
{"version":3,"file":"filter.cjs","sources":["../../../src/operators/filter.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that filters elements from the input stream\n */\nexport class FilterOperator<T> extends LinearUnaryOperator<T, T> {\n #f: (data: T) => boolean\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n f: (data: T) => boolean\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.filter(this.#f)\n }\n}\n\n/**\n * Filters elements from the input stream\n * @param f - The predicate to filter elements\n */\nexport function filter<T>(f: (data: T) => boolean): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new FilterOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"filter.cjs","sources":["../../../src/operators/filter.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that filters elements from the input stream\n */\nexport class FilterOperator<T> extends LinearUnaryOperator<T, T> {\n #f: (data: T) => boolean\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n f: (data: T) => boolean\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.filter(this.#f)\n }\n}\n\n/**\n * Filters elements from the input stream\n * @param f - The predicate to filter elements\n */\nexport function filter<T>(f: (data: T) => boolean): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new FilterOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,uBAA0BA,MAAAA,oBAA0B;AAAA,EAG/D,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAR1B;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAO,mBAAK,GAAE;AAAA,EAClC;AACF;AAfE;AAqBK,SAAS,OAAU,GAA8C;AACtE,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"join.cjs","sources":["../../../src/operators/join.ts"],"sourcesContent":["import { BinaryOperator, DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport { Index } from \"../indexes.js\"\nimport { negate } from \"./negate.js\"\nimport { map } from \"./map.js\"\nimport { concat } from \"./concat.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue, PipedOperator } from \"../types.js\"\n\n/**\n * Type of join to perform\n */\nexport type JoinType = `inner` | `left` | `right` | `full` | `anti`\n\n/**\n * Operator that joins two input streams\n */\nexport class JoinOperator<K, V1, V2> extends BinaryOperator<\n [K, V1] | [K, V2] | [K, [V1, V2]]\n> {\n #indexA = new Index<K, V1>()\n #indexB = new Index<K, V2>()\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V1]>,\n inputB: DifferenceStreamReader<[K, V2]>,\n output: DifferenceStreamWriter<[K, [V1, V2]]>\n ) {\n super(id, inputA, inputB, output)\n }\n\n run(): void {\n const deltaA = new Index<K, V1>()\n const deltaB = new Index<K, V2>()\n\n // Process input A - process ALL messages, not just the first one\n const messagesA = this.inputAMessages()\n for (const message of messagesA) {\n const multiSetMessage = message as unknown as MultiSet<[K, V1]>\n for (const [item, multiplicity] of multiSetMessage.getInner()) {\n const [key, value] = item\n deltaA.addValue(key, [value, multiplicity])\n }\n }\n\n // Process input B - process ALL messages, not just the first one\n const messagesB = this.inputBMessages()\n for (const message of messagesB) {\n const multiSetMessage = message as unknown as MultiSet<[K, V2]>\n for (const [item, multiplicity] of multiSetMessage.getInner()) {\n const [key, value] = item\n deltaB.addValue(key, [value, multiplicity])\n }\n }\n\n // Process results\n const results = new MultiSet<[K, [V1, V2]]>()\n\n // Join deltaA with existing indexB\n results.extend(deltaA.join(this.#indexB))\n\n // Append deltaA to indexA\n this.#indexA.append(deltaA)\n\n // Join existing indexA with deltaB\n results.extend(this.#indexA.join(deltaB))\n\n // Send results\n if (results.getInner().length > 0) {\n this.output.sendData(results)\n }\n\n // Append deltaB to indexB\n this.#indexB.append(deltaB)\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n * @param type - The type of join to perform\n */\nexport function join<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>,\n type: JoinType = `inner`\n): PipedOperator<T, KeyValue<K, [V1 | null, V2 | null]>> {\n switch (type) {\n case `inner`:\n return innerJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, V2]>\n >\n case `anti`:\n return antiJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, null]>\n >\n case `left`:\n return leftJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, V2 | null]>\n >\n case `right`:\n return rightJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1 | null, V2]>\n >\n case `full`:\n return fullJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1 | null, V2 | null]>\n >\n default:\n throw new Error(`Join type ${type} is invalid`)\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function innerJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, V2]>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, [V1, V2]>> => {\n if (stream.graph !== other.graph) {\n throw new Error(`Cannot join streams from different graphs`)\n }\n const output = new StreamBuilder<KeyValue<K, [V1, V2]>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<K, [V1, V2]>>()\n )\n const operator = new JoinOperator<K, V1, V2>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<K, V1>>,\n other.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(output.connectReader())\n return output\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function antiJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1, null]>> => {\n const matchedLeft = stream.pipe(\n innerJoin(other),\n map(([key, [valueLeft, _valueRight]]) => [key, valueLeft])\n )\n const anti = stream.pipe(\n concat(matchedLeft.pipe(negate())),\n // @ts-ignore TODO: fix this\n map(([key, value]) => [key, [value, null]])\n )\n return anti as IStreamBuilder<KeyValue<K, [V1, null]>>\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function leftJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, V2 | null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1, V2 | null]>> => {\n const left = stream\n const right = other\n const inner = left.pipe(innerJoin(right))\n const anti = left.pipe(antiJoin(right))\n return inner.pipe(concat(anti)) as IStreamBuilder<\n KeyValue<K, [V1, V2 | null]>\n >\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function rightJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1 | null, V2]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1 | null, V2]>> => {\n const left = stream as IStreamBuilder<KeyValue<K, V1>>\n const right = other\n const inner = left.pipe(innerJoin(right))\n const anti = right.pipe(\n antiJoin(left),\n map(([key, [a, b]]) => [key, [b, a]])\n )\n return inner.pipe(concat(anti)) as IStreamBuilder<\n KeyValue<K, [V1 | null, V2]>\n >\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function fullJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1 | null, V2 | null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1 | null, V2 | null]>> => {\n const left = stream as IStreamBuilder<KeyValue<K, V1>>\n const right = other\n const inner = left.pipe(innerJoin(right))\n const antiLeft = left.pipe(antiJoin(right))\n const antiRight = right.pipe(\n antiJoin(left),\n map(([key, [a, b]]) => [key, [b, a]])\n )\n return inner.pipe(concat(antiLeft), concat(antiRight)) as IStreamBuilder<\n KeyValue<K, [V1 | null, V2 | null]>\n >\n }\n}\n"],"names":["BinaryOperator","Index","MultiSet","StreamBuilder","DifferenceStreamWriter","map","concat","negate"],"mappings":";;;;;;;;;;;;;;;;AAkBO,MAAM,qBAAgCA,MAAAA,eAE3C;AAAA,EAIA,YACE,IACA,QACA,QACA,QACA;AACA,UAAM,IAAI,QAAQ,QAAQ,MAAM;AATlC,gCAAU,IAAIC,QAAAA,MAAA;AACd,gCAAU,IAAIA,QAAAA,MAAA;AAAA,EASd;AAAA,EAEA,MAAY;AACV,UAAM,SAAS,IAAIA,cAAA;AACnB,UAAM,SAAS,IAAIA,cAAA;AAGnB,UAAM,YAAY,KAAK,eAAA;AACvB,eAAW,WAAW,WAAW;AAC/B,YAAM,kBAAkB;AACxB,iBAAW,CAAC,MAAM,YAAY,KAAK,gBAAgB,YAAY;AAC7D,cAAM,CAAC,KAAK,KAAK,IAAI;AACrB,eAAO,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,MAC5C;AAAA,IACF;AAGA,UAAM,YAAY,KAAK,eAAA;AACvB,eAAW,WAAW,WAAW;AAC/B,YAAM,kBAAkB;AACxB,iBAAW,CAAC,MAAM,YAAY,KAAK,gBAAgB,YAAY;AAC7D,cAAM,CAAC,KAAK,KAAK,IAAI;AACrB,eAAO,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,MAC5C;AAAA,IACF;AAGA,UAAM,UAAU,IAAIC,kBAAA;AAGpB,YAAQ,OAAO,OAAO,KAAK,mBAAK,QAAO,CAAC;AAGxC,uBAAK,SAAQ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QAAQ,GAAGA,OAAAA,OAAO,SAAS,CAAC;AAAA,EAGvD;AACF;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"join.cjs","sources":["../../../src/operators/join.ts"],"sourcesContent":["import { BinaryOperator, DifferenceStreamWriter } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport { Index } from \"../indexes.js\"\nimport { negate } from \"./negate.js\"\nimport { map } from \"./map.js\"\nimport { concat } from \"./concat.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue, PipedOperator } from \"../types.js\"\n\n/**\n * Type of join to perform\n */\nexport type JoinType = `inner` | `left` | `right` | `full` | `anti`\n\n/**\n * Operator that joins two input streams\n */\nexport class JoinOperator<K, V1, V2> extends BinaryOperator<\n [K, V1] | [K, V2] | [K, [V1, V2]]\n> {\n #indexA = new Index<K, V1>()\n #indexB = new Index<K, V2>()\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V1]>,\n inputB: DifferenceStreamReader<[K, V2]>,\n output: DifferenceStreamWriter<[K, [V1, V2]]>\n ) {\n super(id, inputA, inputB, output)\n }\n\n run(): void {\n const deltaA = new Index<K, V1>()\n const deltaB = new Index<K, V2>()\n\n // Process input A - process ALL messages, not just the first one\n const messagesA = this.inputAMessages()\n for (const message of messagesA) {\n const multiSetMessage = message as unknown as MultiSet<[K, V1]>\n for (const [item, multiplicity] of multiSetMessage.getInner()) {\n const [key, value] = item\n deltaA.addValue(key, [value, multiplicity])\n }\n }\n\n // Process input B - process ALL messages, not just the first one\n const messagesB = this.inputBMessages()\n for (const message of messagesB) {\n const multiSetMessage = message as unknown as MultiSet<[K, V2]>\n for (const [item, multiplicity] of multiSetMessage.getInner()) {\n const [key, value] = item\n deltaB.addValue(key, [value, multiplicity])\n }\n }\n\n // Process results\n const results = new MultiSet<[K, [V1, V2]]>()\n\n // Join deltaA with existing indexB\n results.extend(deltaA.join(this.#indexB))\n\n // Append deltaA to indexA\n this.#indexA.append(deltaA)\n\n // Join existing indexA with deltaB\n results.extend(this.#indexA.join(deltaB))\n\n // Send results\n if (results.getInner().length > 0) {\n this.output.sendData(results)\n }\n\n // Append deltaB to indexB\n this.#indexB.append(deltaB)\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n * @param type - The type of join to perform\n */\nexport function join<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>,\n type: JoinType = `inner`\n): PipedOperator<T, KeyValue<K, [V1 | null, V2 | null]>> {\n switch (type) {\n case `inner`:\n return innerJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, V2]>\n >\n case `anti`:\n return antiJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, null]>\n >\n case `left`:\n return leftJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1, V2 | null]>\n >\n case `right`:\n return rightJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1 | null, V2]>\n >\n case `full`:\n return fullJoin(other) as unknown as PipedOperator<\n T,\n KeyValue<K, [V1 | null, V2 | null]>\n >\n default:\n throw new Error(`Join type ${type} is invalid`)\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function innerJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, V2]>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, [V1, V2]>> => {\n if (stream.graph !== other.graph) {\n throw new Error(`Cannot join streams from different graphs`)\n }\n const output = new StreamBuilder<KeyValue<K, [V1, V2]>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<K, [V1, V2]>>()\n )\n const operator = new JoinOperator<K, V1, V2>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<K, V1>>,\n other.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function antiJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1, null]>> => {\n const matchedLeft = stream.pipe(\n innerJoin(other),\n map(([key, [valueLeft, _valueRight]]) => [key, valueLeft])\n )\n const anti = stream.pipe(\n concat(matchedLeft.pipe(negate())),\n // @ts-ignore TODO: fix this\n map(([key, value]) => [key, [value, null]])\n )\n return anti as IStreamBuilder<KeyValue<K, [V1, null]>>\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function leftJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1, V2 | null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1, V2 | null]>> => {\n const left = stream\n const right = other\n const inner = left.pipe(innerJoin(right))\n const anti = left.pipe(antiJoin(right))\n return inner.pipe(concat(anti)) as IStreamBuilder<\n KeyValue<K, [V1, V2 | null]>\n >\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function rightJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1 | null, V2]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1 | null, V2]>> => {\n const left = stream as IStreamBuilder<KeyValue<K, V1>>\n const right = other\n const inner = left.pipe(innerJoin(right))\n const anti = right.pipe(\n antiJoin(left),\n map(([key, [a, b]]) => [key, [b, a]])\n )\n return inner.pipe(concat(anti)) as IStreamBuilder<\n KeyValue<K, [V1 | null, V2]>\n >\n }\n}\n\n/**\n * Joins two input streams\n * @param other - The other stream to join with\n */\nexport function fullJoin<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n V2,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, V2>>\n): PipedOperator<T, KeyValue<K, [V1 | null, V2 | null]>> {\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<K, [V1 | null, V2 | null]>> => {\n const left = stream as IStreamBuilder<KeyValue<K, V1>>\n const right = other\n const inner = left.pipe(innerJoin(right))\n const antiLeft = left.pipe(antiJoin(right))\n const antiRight = right.pipe(\n antiJoin(left),\n map(([key, [a, b]]) => [key, [b, a]])\n )\n return inner.pipe(concat(antiLeft), concat(antiRight)) as IStreamBuilder<\n KeyValue<K, [V1 | null, V2 | null]>\n >\n }\n}\n"],"names":["BinaryOperator","Index","MultiSet","StreamBuilder","DifferenceStreamWriter","map","concat","negate"],"mappings":";;;;;;;;;;;;;;;;AAkBO,MAAM,qBAAgCA,MAAAA,eAE3C;AAAA,EAIA,YACE,IACA,QACA,QACA,QACA;AACA,UAAM,IAAI,QAAQ,QAAQ,MAAM;AATlC,gCAAU,IAAIC,QAAAA,MAAA;AACd,gCAAU,IAAIA,QAAAA,MAAA;AAAA,EASd;AAAA,EAEA,MAAY;AACV,UAAM,SAAS,IAAIA,cAAA;AACnB,UAAM,SAAS,IAAIA,cAAA;AAGnB,UAAM,YAAY,KAAK,eAAA;AACvB,eAAW,WAAW,WAAW;AAC/B,YAAM,kBAAkB;AACxB,iBAAW,CAAC,MAAM,YAAY,KAAK,gBAAgB,YAAY;AAC7D,cAAM,CAAC,KAAK,KAAK,IAAI;AACrB,eAAO,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,MAC5C;AAAA,IACF;AAGA,UAAM,YAAY,KAA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AAK,CAAC;AACxC,UAAM,WAAW,KAAK,KAAK,SAAS,KAAK,CAAC;AAC1C,UAAM,YAAY,MAAM;AAAA,MACtB,SAAS,IAAI;AAAA,MACbD,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAAA,IAAA;AAEtC,WAAO,MAAM,KAAKC,OAAAA,OAAO,QAAQ,GAAGA,OAAAA,OAAO,SAAS,CAAC;AAAA,EAGvD;AACF;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.cjs","sources":["../../../src/operators/map.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each element in the input stream\n */\nexport class MapOperator<T, U> extends LinearUnaryOperator<T, U> {\n #f: (data: T) => U\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<U>,\n f: (data: T) => U\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<U> {\n return collection.map(this.#f)\n }\n}\n\n/**\n * Applies a function to each element in the input stream\n * @param f - The function to apply to each element\n */\nexport function map<T, O>(f: (data: T) => O): PipedOperator<T, O> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<O> => {\n const output = new StreamBuilder<O>(\n stream.graph,\n new DifferenceStreamWriter<O>()\n )\n const operator = new MapOperator<T, O>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"map.cjs","sources":["../../../src/operators/map.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each element in the input stream\n */\nexport class MapOperator<T, U> extends LinearUnaryOperator<T, U> {\n #f: (data: T) => U\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<U>,\n f: (data: T) => U\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<U> {\n return collection.map(this.#f)\n }\n}\n\n/**\n * Applies a function to each element in the input stream\n * @param f - The function to apply to each element\n */\nexport function map<T, O>(f: (data: T) => O): PipedOperator<T, O> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<O> => {\n const output = new StreamBuilder<O>(\n stream.graph,\n new DifferenceStreamWriter<O>()\n )\n const operator = new MapOperator<T, O>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,oBAA0BA,MAAAA,oBAA0B;AAAA,EAG/D,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAR1B;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAsC;AAC1C,WAAO,WAAW,IAAI,mBAAK,GAAE;AAAA,EAC/B;AACF;AAfE;AAqBK,SAAS,IAAU,GAAwC;AAChE,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negate.cjs","sources":["../../../src/operators/negate.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that negates the multiplicities in the input stream\n */\nexport class NegateOperator<T> extends LinearUnaryOperator<T, T> {\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.negate()\n }\n}\n\n/**\n * Negates the multiplicities in the input stream\n */\nexport function negate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new NegateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"negate.cjs","sources":["../../../src/operators/negate.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that negates the multiplicities in the input stream\n */\nexport class NegateOperator<T> extends LinearUnaryOperator<T, T> {\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.negate()\n }\n}\n\n/**\n * Negates the multiplicities in the input stream\n */\nexport function negate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new NegateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;AAQO,MAAM,uBAA0BA,MAAAA,oBAA0B;AAAA,EAC/D,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAA;AAAA,EACpB;AACF;AAKO,SAAS,SAAiC;AAC/C,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.cjs","sources":["../../../src/operators/output.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that outputs the messages in the stream\n */\nexport class OutputOperator<T> extends UnaryOperator<T> {\n #fn: (data: MultiSet<T>) => void\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n outputWriter: DifferenceStreamWriter<T>,\n fn: (data: MultiSet<T>) => void\n ) {\n super(id, inputA, outputWriter)\n this.#fn = fn\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n this.#fn(message)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Outputs the messages in the stream\n * @param fn - The function to call with each message\n */\nexport function output<T>(\n fn: (data: MultiSet<T>) => void\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const outputStream = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new OutputOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n outputStream.writer,\n fn\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"output.cjs","sources":["../../../src/operators/output.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that outputs the messages in the stream\n */\nexport class OutputOperator<T> extends UnaryOperator<T> {\n #fn: (data: MultiSet<T>) => void\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n outputWriter: DifferenceStreamWriter<T>,\n fn: (data: MultiSet<T>) => void\n ) {\n super(id, inputA, outputWriter)\n this.#fn = fn\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n this.#fn(message)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Outputs the messages in the stream\n * @param fn - The function to call with each message\n */\nexport function output<T>(\n fn: (data: MultiSet<T>) => void\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const outputStream = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new OutputOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n outputStream.writer,\n fn\n )\n stream.graph.addOperator(operator)\n return outputStream\n }\n}\n"],"names":["UnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,uBAA0BA,MAAAA,cAAiB;AAAA,EAGtD,YACE,IACA,QACA,cACA,IACA;AACA,UAAM,IAAI,QAAQ,YAAY;AARhC;AASE,uBAAK,KAAM;AAAA,EACb;AAAA,EAEA,MAAY;AACV,eAAW,WAAW,KAAK,iBAAiB;AAC1C,yBAAK,KAAL,WAAS;AACT,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AAlBE;AAwBK,SAAS,OACd,IACqB;AACrB,SAAO,CAAC,WAAiD;AACvD,UAAM,eAAe,IAAIC,GAAAA;AAAAA,MACvB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,aAAa;AAAA,MACb;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduce.cjs","sources":["../../../src/operators/reduce.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport { Index } from \"../indexes.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue } from \"../types.js\"\n\n/**\n * Base operator for reduction operations (version-free)\n */\nexport class ReduceOperator<K, V1, V2> extends UnaryOperator<[K, V1], [K, V2]> {\n #index = new Index<K, V1>()\n #indexOut = new Index<K, V2>()\n #f: (values: Array<[V1, number]>) => Array<[V2, number]>\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V1]>,\n output: DifferenceStreamWriter<[K, V2]>,\n f: (values: Array<[V1, number]>) => Array<[V2, number]>\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n run(): void {\n // Collect all input messages and update the index\n const keysTodo = new Set<K>()\n for (const message of this.inputMessages()) {\n for (const [item, multiplicity] of message.getInner()) {\n const [key, value] = item\n this.#index.addValue(key, [value, multiplicity])\n keysTodo.add(key)\n }\n }\n\n // For each key, compute the reduction and delta\n const result: Array<[[K, V2], number]> = []\n for (const key of keysTodo) {\n const curr = this.#index.get(key)\n const currOut = this.#indexOut.get(key)\n const out = this.#f(curr)\n\n // Create maps for current and previous outputs using values directly as keys\n const newOutputMap = new Map<V2, number>()\n const oldOutputMap = new Map<V2, number>()\n\n // Process new output\n for (const [value, multiplicity] of out) {\n const existing = newOutputMap.get(value) ?? 0\n newOutputMap.set(value, existing + multiplicity)\n }\n\n // Process previous output\n for (const [value, multiplicity] of currOut) {\n const existing = oldOutputMap.get(value) ?? 0\n oldOutputMap.set(value, existing + multiplicity)\n }\n\n // First, emit removals for old values that are no longer present\n for (const [value, multiplicity] of oldOutputMap) {\n if (!newOutputMap.has(value)) {\n // Remove the old value entirely\n result.push([[key, value], -multiplicity])\n this.#indexOut.addValue(key, [value, -multiplicity])\n }\n }\n\n // Then, emit additions for new values that are not present in old\n for (const [value, multiplicity] of newOutputMap) {\n if (!oldOutputMap.has(value)) {\n // Add the new value only if it has non-zero multiplicity\n if (multiplicity !== 0) {\n result.push([[key, value], multiplicity])\n this.#indexOut.addValue(key, [value, multiplicity])\n }\n }\n }\n\n // Finally, emit multiplicity changes for values that were present and are still present\n for (const [value, newMultiplicity] of newOutputMap) {\n const oldMultiplicity = oldOutputMap.get(value)\n if (oldMultiplicity !== undefined) {\n const delta = newMultiplicity - oldMultiplicity\n // Only emit actual changes, i.e. non-zero deltas\n if (delta !== 0) {\n result.push([[key, value], delta])\n this.#indexOut.addValue(key, [value, delta])\n }\n }\n }\n }\n\n if (result.length > 0) {\n this.output.sendData(new MultiSet(result))\n }\n }\n}\n\n/**\n * Reduces the elements in the stream by key (version-free)\n */\nexport function reduce<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n R,\n T,\n>(f: (values: Array<[V1Type, number]>) => Array<[R, number]>) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<KType, R>> => {\n const output = new StreamBuilder<KeyValue<KType, R>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, R>>()\n )\n const operator = new ReduceOperator<KType, V1Type, R>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, V1Type>>,\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n
|
|
1
|
+
{"version":3,"file":"reduce.cjs","sources":["../../../src/operators/reduce.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport { Index } from \"../indexes.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue } from \"../types.js\"\n\n/**\n * Base operator for reduction operations (version-free)\n */\nexport class ReduceOperator<K, V1, V2> extends UnaryOperator<[K, V1], [K, V2]> {\n #index = new Index<K, V1>()\n #indexOut = new Index<K, V2>()\n #f: (values: Array<[V1, number]>) => Array<[V2, number]>\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V1]>,\n output: DifferenceStreamWriter<[K, V2]>,\n f: (values: Array<[V1, number]>) => Array<[V2, number]>\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n run(): void {\n // Collect all input messages and update the index\n const keysTodo = new Set<K>()\n for (const message of this.inputMessages()) {\n for (const [item, multiplicity] of message.getInner()) {\n const [key, value] = item\n this.#index.addValue(key, [value, multiplicity])\n keysTodo.add(key)\n }\n }\n\n // For each key, compute the reduction and delta\n const result: Array<[[K, V2], number]> = []\n for (const key of keysTodo) {\n const curr = this.#index.get(key)\n const currOut = this.#indexOut.get(key)\n const out = this.#f(curr)\n\n // Create maps for current and previous outputs using values directly as keys\n const newOutputMap = new Map<V2, number>()\n const oldOutputMap = new Map<V2, number>()\n\n // Process new output\n for (const [value, multiplicity] of out) {\n const existing = newOutputMap.get(value) ?? 0\n newOutputMap.set(value, existing + multiplicity)\n }\n\n // Process previous output\n for (const [value, multiplicity] of currOut) {\n const existing = oldOutputMap.get(value) ?? 0\n oldOutputMap.set(value, existing + multiplicity)\n }\n\n // First, emit removals for old values that are no longer present\n for (const [value, multiplicity] of oldOutputMap) {\n if (!newOutputMap.has(value)) {\n // Remove the old value entirely\n result.push([[key, value], -multiplicity])\n this.#indexOut.addValue(key, [value, -multiplicity])\n }\n }\n\n // Then, emit additions for new values that are not present in old\n for (const [value, multiplicity] of newOutputMap) {\n if (!oldOutputMap.has(value)) {\n // Add the new value only if it has non-zero multiplicity\n if (multiplicity !== 0) {\n result.push([[key, value], multiplicity])\n this.#indexOut.addValue(key, [value, multiplicity])\n }\n }\n }\n\n // Finally, emit multiplicity changes for values that were present and are still present\n for (const [value, newMultiplicity] of newOutputMap) {\n const oldMultiplicity = oldOutputMap.get(value)\n if (oldMultiplicity !== undefined) {\n const delta = newMultiplicity - oldMultiplicity\n // Only emit actual changes, i.e. non-zero deltas\n if (delta !== 0) {\n result.push([[key, value], delta])\n this.#indexOut.addValue(key, [value, delta])\n }\n }\n }\n }\n\n if (result.length > 0) {\n this.output.sendData(new MultiSet(result))\n }\n }\n}\n\n/**\n * Reduces the elements in the stream by key (version-free)\n */\nexport function reduce<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n R,\n T,\n>(f: (values: Array<[V1Type, number]>) => Array<[R, number]>) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<KType, R>> => {\n const output = new StreamBuilder<KeyValue<KType, R>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, R>>()\n )\n const operator = new ReduceOperator<KType, V1Type, R>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, V1Type>>,\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["UnaryOperator","Index","MultiSet","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;;;AAUO,MAAM,uBAAkCA,MAAAA,cAAgC;AAAA,EAK7E,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAV1B,+BAAS,IAAIC,QAAAA,MAAA;AACb,kCAAY,IAAIA,QAAAA,M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+BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAGA,iBAAW,CAAC,OAAO,eAAe,KAAK,cAAc;AACnD,cAAM,kBAAkB,aAAa,IAAI,KAAK;AAC9C,YAAI,oBAAoB,QAAW;AACjC,gBAAM,QAAQ,kBAAkB;AAEhC,cAAI,UAAU,GAAG;AACf,mBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,KAAK,CAAC;AACjC,+BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,KAAK,CAAC;AAAA,UAC7C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,OAAO,SAAS,GAAG;AACrB,WAAK,OAAO,SAAS,IAAIC,SAAAA,SAAS,MAAM,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;AAtFE;AACA;AACA;AAyFK,SAAS,OAKd,GAA4D;AAC5D,SAAO,CAAC,WAAkE;AACxE,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA2C;AAEjD,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -17,10 +17,8 @@ class TapOperator extends graph.LinearUnaryOperator {
|
|
|
17
17
|
__privateSet(this, _f, f);
|
|
18
18
|
}
|
|
19
19
|
inner(collection) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return data;
|
|
23
|
-
});
|
|
20
|
+
__privateGet(this, _f).call(this, collection);
|
|
21
|
+
return collection;
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
_f = new WeakMap();
|
|
@@ -37,7 +35,6 @@ function tap(f) {
|
|
|
37
35
|
f
|
|
38
36
|
);
|
|
39
37
|
stream.graph.addOperator(operator);
|
|
40
|
-
stream.graph.addStream(output.connectReader());
|
|
41
38
|
return output;
|
|
42
39
|
};
|
|
43
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap.cjs","sources":["../../../src/operators/tap.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each
|
|
1
|
+
{"version":3,"file":"tap.cjs","sources":["../../../src/operators/tap.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each multi-set in the input stream\n */\nexport class TapOperator<T> extends LinearUnaryOperator<T, T> {\n #f: (data: MultiSet<T>) => void\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n f: (data: MultiSet<T>) => void\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<T> {\n this.#f(collection)\n return collection\n }\n}\n\n/**\n * Invokes a function for each multi-set in the input stream.\n * This operator doesn't modify the stream and is used to perform side effects.\n * @param f - The function to invoke on each multi-set\n * @returns The input stream\n */\nexport function tap<T>(f: (data: MultiSet<T>) => void): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new TapOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,oBAAuBA,MAAAA,oBAA0B;AAAA,EAG5D,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAR1B;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAsC;AAC1C,uBAAK,IAAL,WAAQ;AACR,WAAO;AAAA,EACT;AACF;AAhBE;AAwBK,SAAS,IAAO,GAAqD;AAC1E,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -2,17 +2,17 @@ import { DifferenceStreamWriter, LinearUnaryOperator, DifferenceStreamReader } f
|
|
|
2
2
|
import { PipedOperator } from '../types.js';
|
|
3
3
|
import { MultiSet } from '../multiset.js';
|
|
4
4
|
/**
|
|
5
|
-
* Operator that applies a function to each
|
|
5
|
+
* Operator that applies a function to each multi-set in the input stream
|
|
6
6
|
*/
|
|
7
7
|
export declare class TapOperator<T> extends LinearUnaryOperator<T, T> {
|
|
8
8
|
#private;
|
|
9
|
-
constructor(id: number, inputA: DifferenceStreamReader<T>, output: DifferenceStreamWriter<T>, f: (data: T) => void);
|
|
9
|
+
constructor(id: number, inputA: DifferenceStreamReader<T>, output: DifferenceStreamWriter<T>, f: (data: MultiSet<T>) => void);
|
|
10
10
|
inner(collection: MultiSet<T>): MultiSet<T>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Invokes a function for each
|
|
13
|
+
* Invokes a function for each multi-set in the input stream.
|
|
14
14
|
* This operator doesn't modify the stream and is used to perform side effects.
|
|
15
|
-
* @param f - The function to invoke on each
|
|
15
|
+
* @param f - The function to invoke on each multi-set
|
|
16
16
|
* @returns The input stream
|
|
17
17
|
*/
|
|
18
|
-
export declare function tap<T>(f: (data: T) => void): PipedOperator<T, T>;
|
|
18
|
+
export declare function tap<T>(f: (data: MultiSet<T>) => void): PipedOperator<T, T>;
|