@tanstack/db-ivm 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/d2.cjs +111 -0
- package/dist/cjs/d2.cjs.map +1 -0
- package/dist/cjs/d2.d.cts +45 -0
- package/dist/cjs/graph.cjs +90 -0
- package/dist/cjs/graph.cjs.map +1 -0
- package/dist/cjs/graph.d.cts +57 -0
- package/dist/cjs/index.cjs +72 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/indexes.cjs +104 -0
- package/dist/cjs/indexes.cjs.map +1 -0
- package/dist/cjs/indexes.d.cts +20 -0
- package/dist/cjs/multiset.cjs +173 -0
- package/dist/cjs/multiset.cjs.map +1 -0
- package/dist/cjs/multiset.d.cts +36 -0
- package/dist/cjs/operators/concat.cjs +37 -0
- package/dist/cjs/operators/concat.cjs.map +1 -0
- package/dist/cjs/operators/concat.d.cts +13 -0
- package/dist/cjs/operators/consolidate.cjs +40 -0
- package/dist/cjs/operators/consolidate.cjs.map +1 -0
- package/dist/cjs/operators/consolidate.d.cts +12 -0
- package/dist/cjs/operators/count.cjs +36 -0
- package/dist/cjs/operators/count.cjs.map +1 -0
- package/dist/cjs/operators/count.d.cts +13 -0
- package/dist/cjs/operators/debug.cjs +50 -0
- package/dist/cjs/operators/debug.cjs.map +1 -0
- package/dist/cjs/operators/debug.d.cts +16 -0
- package/dist/cjs/operators/distinct.cjs +78 -0
- package/dist/cjs/operators/distinct.cjs.map +1 -0
- package/dist/cjs/operators/distinct.d.cts +14 -0
- package/dist/cjs/operators/filter.cjs +43 -0
- package/dist/cjs/operators/filter.cjs.map +1 -0
- package/dist/cjs/operators/filter.d.cts +16 -0
- package/dist/cjs/operators/filterBy.cjs +19 -0
- package/dist/cjs/operators/filterBy.cjs.map +1 -0
- package/dist/cjs/operators/filterBy.d.cts +10 -0
- package/dist/cjs/operators/groupBy.cjs +225 -0
- package/dist/cjs/operators/groupBy.cjs.map +1 -0
- package/dist/cjs/operators/groupBy.d.cts +68 -0
- package/dist/cjs/operators/index.d.cts +18 -0
- package/dist/cjs/operators/join.cjs +145 -0
- package/dist/cjs/operators/join.cjs.map +1 -0
- package/dist/cjs/operators/join.d.cts +48 -0
- package/dist/cjs/operators/keying.cjs +16 -0
- package/dist/cjs/operators/keying.cjs.map +1 -0
- package/dist/cjs/operators/keying.d.cts +19 -0
- package/dist/cjs/operators/map.cjs +43 -0
- package/dist/cjs/operators/map.cjs.map +1 -0
- package/dist/cjs/operators/map.d.cts +16 -0
- package/dist/cjs/operators/negate.cjs +28 -0
- package/dist/cjs/operators/negate.cjs.map +1 -0
- package/dist/cjs/operators/negate.d.cts +13 -0
- package/dist/cjs/operators/orderBy.cjs +102 -0
- package/dist/cjs/operators/orderBy.cjs.map +1 -0
- package/dist/cjs/operators/orderBy.d.cts +38 -0
- package/dist/cjs/operators/orderByBTree.d.cts +3 -0
- package/dist/cjs/operators/output.cjs +46 -0
- package/dist/cjs/operators/output.cjs.map +1 -0
- package/dist/cjs/operators/output.d.cts +16 -0
- package/dist/cjs/operators/pipe.cjs +9 -0
- package/dist/cjs/operators/pipe.cjs.map +1 -0
- package/dist/cjs/operators/pipe.d.cts +21 -0
- package/dist/cjs/operators/reduce.cjs +99 -0
- package/dist/cjs/operators/reduce.cjs.map +1 -0
- package/dist/cjs/operators/reduce.d.cts +14 -0
- package/dist/cjs/operators/topK.cjs +39 -0
- package/dist/cjs/operators/topK.cjs.map +1 -0
- package/dist/cjs/operators/topK.d.cts +32 -0
- package/dist/cjs/operators/topKWithFractionalIndex.cjs +218 -0
- package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -0
- package/dist/cjs/operators/topKWithFractionalIndex.d.cts +58 -0
- package/dist/cjs/operators/topKWithFractionalIndexBTree.d.cts +27 -0
- package/dist/cjs/types.d.cts +30 -0
- package/dist/cjs/utils.cjs +125 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +40 -0
- package/dist/esm/d2.d.ts +45 -0
- package/dist/esm/d2.js +111 -0
- package/dist/esm/d2.js.map +1 -0
- package/dist/esm/graph.d.ts +57 -0
- package/dist/esm/graph.js +90 -0
- package/dist/esm/graph.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexes.d.ts +20 -0
- package/dist/esm/indexes.js +104 -0
- package/dist/esm/indexes.js.map +1 -0
- package/dist/esm/multiset.d.ts +36 -0
- package/dist/esm/multiset.js +173 -0
- package/dist/esm/multiset.js.map +1 -0
- package/dist/esm/operators/concat.d.ts +13 -0
- package/dist/esm/operators/concat.js +37 -0
- package/dist/esm/operators/concat.js.map +1 -0
- package/dist/esm/operators/consolidate.d.ts +12 -0
- package/dist/esm/operators/consolidate.js +40 -0
- package/dist/esm/operators/consolidate.js.map +1 -0
- package/dist/esm/operators/count.d.ts +13 -0
- package/dist/esm/operators/count.js +36 -0
- package/dist/esm/operators/count.js.map +1 -0
- package/dist/esm/operators/debug.d.ts +16 -0
- package/dist/esm/operators/debug.js +50 -0
- package/dist/esm/operators/debug.js.map +1 -0
- package/dist/esm/operators/distinct.d.ts +14 -0
- package/dist/esm/operators/distinct.js +78 -0
- package/dist/esm/operators/distinct.js.map +1 -0
- package/dist/esm/operators/filter.d.ts +16 -0
- package/dist/esm/operators/filter.js +43 -0
- package/dist/esm/operators/filter.js.map +1 -0
- package/dist/esm/operators/filterBy.d.ts +10 -0
- package/dist/esm/operators/filterBy.js +19 -0
- package/dist/esm/operators/filterBy.js.map +1 -0
- package/dist/esm/operators/groupBy.d.ts +68 -0
- package/dist/esm/operators/groupBy.js +225 -0
- package/dist/esm/operators/groupBy.js.map +1 -0
- package/dist/esm/operators/index.d.ts +18 -0
- package/dist/esm/operators/join.d.ts +48 -0
- package/dist/esm/operators/join.js +145 -0
- package/dist/esm/operators/join.js.map +1 -0
- package/dist/esm/operators/keying.d.ts +19 -0
- package/dist/esm/operators/keying.js +16 -0
- package/dist/esm/operators/keying.js.map +1 -0
- package/dist/esm/operators/map.d.ts +16 -0
- package/dist/esm/operators/map.js +43 -0
- package/dist/esm/operators/map.js.map +1 -0
- package/dist/esm/operators/negate.d.ts +13 -0
- package/dist/esm/operators/negate.js +28 -0
- package/dist/esm/operators/negate.js.map +1 -0
- package/dist/esm/operators/orderBy.d.ts +38 -0
- package/dist/esm/operators/orderBy.js +102 -0
- package/dist/esm/operators/orderBy.js.map +1 -0
- package/dist/esm/operators/orderByBTree.d.ts +3 -0
- package/dist/esm/operators/output.d.ts +16 -0
- package/dist/esm/operators/output.js +46 -0
- package/dist/esm/operators/output.js.map +1 -0
- package/dist/esm/operators/pipe.d.ts +21 -0
- package/dist/esm/operators/pipe.js +9 -0
- package/dist/esm/operators/pipe.js.map +1 -0
- package/dist/esm/operators/reduce.d.ts +14 -0
- package/dist/esm/operators/reduce.js +99 -0
- package/dist/esm/operators/reduce.js.map +1 -0
- package/dist/esm/operators/topK.d.ts +32 -0
- package/dist/esm/operators/topK.js +39 -0
- package/dist/esm/operators/topK.js.map +1 -0
- package/dist/esm/operators/topKWithFractionalIndex.d.ts +58 -0
- package/dist/esm/operators/topKWithFractionalIndex.js +218 -0
- package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -0
- package/dist/esm/operators/topKWithFractionalIndexBTree.d.ts +27 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/utils.d.ts +40 -0
- package/dist/esm/utils.js +125 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +6 -7
- package/src/operators/orderBy.ts +11 -29
- package/src/operators/topKWithFractionalIndex.ts +69 -57
- package/src/operators/topKWithFractionalIndexBTree.ts +14 -19
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _f;
|
|
9
|
+
import { LinearUnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
10
|
+
import { StreamBuilder } from "../d2.js";
|
|
11
|
+
class MapOperator extends LinearUnaryOperator {
|
|
12
|
+
constructor(id, inputA, output, f) {
|
|
13
|
+
super(id, inputA, output);
|
|
14
|
+
__privateAdd(this, _f);
|
|
15
|
+
__privateSet(this, _f, f);
|
|
16
|
+
}
|
|
17
|
+
inner(collection) {
|
|
18
|
+
return collection.map(__privateGet(this, _f));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
_f = new WeakMap();
|
|
22
|
+
function map(f) {
|
|
23
|
+
return (stream) => {
|
|
24
|
+
const output = new StreamBuilder(
|
|
25
|
+
stream.graph,
|
|
26
|
+
new DifferenceStreamWriter()
|
|
27
|
+
);
|
|
28
|
+
const operator = new MapOperator(
|
|
29
|
+
stream.graph.getNextOperatorId(),
|
|
30
|
+
stream.connectReader(),
|
|
31
|
+
output.writer,
|
|
32
|
+
f
|
|
33
|
+
);
|
|
34
|
+
stream.graph.addOperator(operator);
|
|
35
|
+
stream.graph.addStream(output.connectReader());
|
|
36
|
+
return output;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
MapOperator,
|
|
41
|
+
map
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","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 stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AASO,MAAM,oBAA0B,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,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,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,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LinearUnaryOperator } from '../graph.js';
|
|
2
|
+
import { PipedOperator } from '../types.js';
|
|
3
|
+
import { MultiSet } from '../multiset.js';
|
|
4
|
+
/**
|
|
5
|
+
* Operator that negates the multiplicities in the input stream
|
|
6
|
+
*/
|
|
7
|
+
export declare class NegateOperator<T> extends LinearUnaryOperator<T, T> {
|
|
8
|
+
inner(collection: MultiSet<T>): MultiSet<T>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Negates the multiplicities in the input stream
|
|
12
|
+
*/
|
|
13
|
+
export declare function negate<T>(): PipedOperator<T, T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LinearUnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
2
|
+
import { StreamBuilder } from "../d2.js";
|
|
3
|
+
class NegateOperator extends LinearUnaryOperator {
|
|
4
|
+
inner(collection) {
|
|
5
|
+
return collection.negate();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function negate() {
|
|
9
|
+
return (stream) => {
|
|
10
|
+
const output = new StreamBuilder(
|
|
11
|
+
stream.graph,
|
|
12
|
+
new DifferenceStreamWriter()
|
|
13
|
+
);
|
|
14
|
+
const operator = new NegateOperator(
|
|
15
|
+
stream.graph.getNextOperatorId(),
|
|
16
|
+
stream.connectReader(),
|
|
17
|
+
output.writer
|
|
18
|
+
);
|
|
19
|
+
stream.graph.addOperator(operator);
|
|
20
|
+
stream.graph.addStream(output.connectReader());
|
|
21
|
+
return output;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
NegateOperator,
|
|
26
|
+
negate
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=negate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"negate.js","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 stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":[],"mappings":";;AAQO,MAAM,uBAA0B,oBAA0B;AAAA,EAC/D,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAA;AAAA,EACpB;AACF;AAKO,SAAS,SAAiC;AAC/C,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,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,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { topKWithFractionalIndex } from './topKWithFractionalIndex.js';
|
|
2
|
+
import { KeyValue } from '../types.js';
|
|
3
|
+
import { IStreamBuilder } from '../types.js';
|
|
4
|
+
export interface OrderByOptions<Ve> {
|
|
5
|
+
comparator?: (a: Ve, b: Ve) => number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Orders the elements and limits the number of results, with optional offset
|
|
11
|
+
* This requires a keyed stream, and uses the `topK` operator to order all the elements.
|
|
12
|
+
*
|
|
13
|
+
* @param valueExtractor - A function that extracts the value to order by from the element
|
|
14
|
+
* @param options - An optional object containing comparator, limit and offset properties
|
|
15
|
+
* @returns A piped operator that orders the elements and limits the number of results
|
|
16
|
+
*/
|
|
17
|
+
export declare function orderBy<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Orders the elements and limits the number of results, with optional offset and
|
|
20
|
+
* annotates the value with the index.
|
|
21
|
+
* This requires a keyed stream, and uses the `topKWithIndex` operator to order all the elements.
|
|
22
|
+
*
|
|
23
|
+
* @param valueExtractor - A function that extracts the value to order by from the element
|
|
24
|
+
* @param options - An optional object containing comparator, limit and offset properties
|
|
25
|
+
* @returns A piped operator that orders the elements and limits the number of results
|
|
26
|
+
*/
|
|
27
|
+
export declare function orderByWithIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, number]>>;
|
|
28
|
+
export declare function orderByWithFractionalIndexBase<T extends KeyValue<unknown, unknown>, Ve = unknown>(topKFunction: typeof topKWithFractionalIndex, valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<[T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]]>;
|
|
29
|
+
/**
|
|
30
|
+
* Orders the elements and limits the number of results, with optional offset and
|
|
31
|
+
* annotates the value with a fractional index.
|
|
32
|
+
* This requires a keyed stream, and uses the `topKWithFractionalIndex` operator to order all the elements.
|
|
33
|
+
*
|
|
34
|
+
* @param valueExtractor - A function that extracts the value to order by from the element
|
|
35
|
+
* @param options - An optional object containing comparator, limit and offset properties
|
|
36
|
+
* @returns A piped operator that orders the elements and limits the number of results
|
|
37
|
+
*/
|
|
38
|
+
export declare function orderByWithFractionalIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<[T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]]>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { topK, topKWithIndex } from "./topK.js";
|
|
2
|
+
import { topKWithFractionalIndex } from "./topKWithFractionalIndex.js";
|
|
3
|
+
import { map } from "./map.js";
|
|
4
|
+
import { innerJoin } from "./join.js";
|
|
5
|
+
import { consolidate } from "./consolidate.js";
|
|
6
|
+
function orderBy(valueExtractor, options) {
|
|
7
|
+
const limit = (options == null ? void 0 : options.limit) ?? Infinity;
|
|
8
|
+
const offset = (options == null ? void 0 : options.offset) ?? 0;
|
|
9
|
+
const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
|
|
10
|
+
if (a === b) return 0;
|
|
11
|
+
if (a < b) return -1;
|
|
12
|
+
return 1;
|
|
13
|
+
});
|
|
14
|
+
return (stream) => {
|
|
15
|
+
return stream.pipe(
|
|
16
|
+
map(
|
|
17
|
+
([key, value]) => [
|
|
18
|
+
null,
|
|
19
|
+
[
|
|
20
|
+
key,
|
|
21
|
+
valueExtractor(
|
|
22
|
+
value
|
|
23
|
+
)
|
|
24
|
+
]
|
|
25
|
+
]
|
|
26
|
+
),
|
|
27
|
+
topK((a, b) => comparator(a[1], b[1]), { limit, offset }),
|
|
28
|
+
map(([_, [key]]) => [key, null]),
|
|
29
|
+
innerJoin(stream),
|
|
30
|
+
map(([key, value]) => {
|
|
31
|
+
return [key, value[1]];
|
|
32
|
+
}),
|
|
33
|
+
consolidate()
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function orderByWithIndex(valueExtractor, options) {
|
|
38
|
+
const limit = (options == null ? void 0 : options.limit) ?? Infinity;
|
|
39
|
+
const offset = (options == null ? void 0 : options.offset) ?? 0;
|
|
40
|
+
const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
|
|
41
|
+
if (a === b) return 0;
|
|
42
|
+
if (a < b) return -1;
|
|
43
|
+
return 1;
|
|
44
|
+
});
|
|
45
|
+
return (stream) => {
|
|
46
|
+
return stream.pipe(
|
|
47
|
+
map(
|
|
48
|
+
([key, value]) => [
|
|
49
|
+
null,
|
|
50
|
+
[
|
|
51
|
+
key,
|
|
52
|
+
valueExtractor(
|
|
53
|
+
value
|
|
54
|
+
)
|
|
55
|
+
]
|
|
56
|
+
]
|
|
57
|
+
),
|
|
58
|
+
topKWithIndex((a, b) => comparator(a[1], b[1]), { limit, offset }),
|
|
59
|
+
map(([_, [[key], index]]) => [key, index]),
|
|
60
|
+
innerJoin(stream),
|
|
61
|
+
map(([key, [index, value]]) => {
|
|
62
|
+
return [key, [value, index]];
|
|
63
|
+
}),
|
|
64
|
+
consolidate()
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function orderByWithFractionalIndexBase(topKFunction, valueExtractor, options) {
|
|
69
|
+
const limit = (options == null ? void 0 : options.limit) ?? Infinity;
|
|
70
|
+
const offset = (options == null ? void 0 : options.offset) ?? 0;
|
|
71
|
+
const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
|
|
72
|
+
if (a === b) return 0;
|
|
73
|
+
if (a < b) return -1;
|
|
74
|
+
return 1;
|
|
75
|
+
});
|
|
76
|
+
return (stream) => {
|
|
77
|
+
return stream.pipe(
|
|
78
|
+
topKFunction(
|
|
79
|
+
(a, b) => comparator(valueExtractor(a), valueExtractor(b)),
|
|
80
|
+
{
|
|
81
|
+
limit,
|
|
82
|
+
offset
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
consolidate()
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function orderByWithFractionalIndex(valueExtractor, options) {
|
|
90
|
+
return orderByWithFractionalIndexBase(
|
|
91
|
+
topKWithFractionalIndex,
|
|
92
|
+
valueExtractor,
|
|
93
|
+
options
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
orderBy,
|
|
98
|
+
orderByWithFractionalIndex,
|
|
99
|
+
orderByWithFractionalIndexBase,
|
|
100
|
+
orderByWithIndex
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=orderBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderBy.js","sources":["../../../src/operators/orderBy.ts"],"sourcesContent":["import { topK, topKWithIndex } from \"./topK.js\"\nimport { topKWithFractionalIndex } from \"./topKWithFractionalIndex.js\"\nimport { map } from \"./map.js\"\nimport { innerJoin } from \"./join.js\"\nimport { consolidate } from \"./consolidate.js\"\nimport type { KeyValue } from \"../types.js\"\nimport type { IStreamBuilder } from \"../types\"\n\nexport interface OrderByOptions<Ve> {\n comparator?: (a: Ve, b: Ve) => number\n limit?: number\n offset?: number\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset\n * This requires a keyed stream, and uses the `topK` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderBy<T extends KeyValue<unknown, unknown>, Ve = unknown>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n\n return stream.pipe(\n map(\n ([key, value]) =>\n [\n null,\n [\n key,\n valueExtractor(\n value as T extends KeyValue<unknown, infer V> ? V : never\n ),\n ],\n ] as KeyValue<null, [KeyType, Ve]>\n ),\n topK((a, b) => comparator(a[1], b[1]), { limit, offset }),\n map(([_, [key]]) => [key, null] as KeyValue<KeyType, null>),\n innerJoin(stream),\n map(([key, value]) => {\n return [key, value[1]] as T\n }),\n consolidate()\n )\n }\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset and\n * annotates the value with the index.\n * This requires a keyed stream, and uses the `topKWithIndex` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderByWithIndex<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<\n KeyValue<\n T extends KeyValue<infer K, unknown> ? K : never,\n [T extends KeyValue<unknown, infer V> ? V : never, number]\n >\n > => {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n type ValueType = T extends KeyValue<unknown, infer V> ? V : never\n\n return stream.pipe(\n map(\n ([key, value]) =>\n [\n null,\n [\n key,\n valueExtractor(\n value as T extends KeyValue<unknown, infer V> ? V : never\n ),\n ],\n ] as KeyValue<null, [KeyType, Ve]>\n ),\n topKWithIndex((a, b) => comparator(a[1], b[1]), { limit, offset }),\n map(([_, [[key], index]]) => [key, index] as KeyValue<KeyType, number>),\n innerJoin(stream),\n map(([key, [index, value]]) => {\n return [key, [value, index]] as KeyValue<KeyType, [ValueType, number]>\n }),\n consolidate()\n )\n }\n}\n\nexport function orderByWithFractionalIndexBase<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n topKFunction: typeof topKWithFractionalIndex,\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n type ValueType = T extends KeyValue<unknown, infer V> ? V : never\n\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<[KeyType, [ValueType, string]]> => {\n return stream.pipe(\n topKFunction(\n (a: ValueType, b: ValueType) =>\n comparator(valueExtractor(a), valueExtractor(b)),\n {\n limit,\n offset,\n }\n ),\n consolidate()\n )\n }\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset and\n * annotates the value with a fractional index.\n * This requires a keyed stream, and uses the `topKWithFractionalIndex` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderByWithFractionalIndex<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n return orderByWithFractionalIndexBase(\n topKWithFractionalIndex,\n valueExtractor,\n options\n )\n}\n"],"names":[],"mappings":";;;;;AAsBO,SAAS,QACd,gBAGA,SACA;AACA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CAAC,WAAiD;AAGvD,WAAO,OAAO;AAAA,MACZ;AAAA,QACE,CAAC,CAAC,KAAK,KAAK,MACV;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,cACE;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEJ,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,QAAQ;AAAA,MACxD,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAA4B;AAAA,MAC1D,UAAU,MAAM;AAAA,MAChB,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACpB,eAAO,CAAC,KAAK,MAAM,CAAC,CAAC;AAAA,MACvB,CAAC;AAAA,MACD,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAWO,SAAS,iBAId,gBAGA,SACA;AACA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CACL,WAMG;AAIH,WAAO,OAAO;AAAA,MACZ;AAAA,QACE,CAAC,CAAC,KAAK,KAAK,MACV;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,cACE;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEJ,cAAc,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,QAAQ;AAAA,MACjE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,CAA8B;AAAA,MACtE,UAAU,MAAM;AAAA,MAChB,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,MAAM;AAC7B,eAAO,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC;AAAA,MAC7B,CAAC;AAAA,MACD,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAEO,SAAS,+BAId,cACA,gBAGA,SACA;AAIA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CACL,WACmD;AACnD,WAAO,OAAO;AAAA,MACZ;AAAA,QACE,CAAC,GAAc,MACb,WAAW,eAAe,CAAC,GAAG,eAAe,CAAC,CAAC;AAAA,QACjD;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAAA,MAEF,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAWO,SAAS,2BAId,gBAGA,SACA;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { KeyValue } from '../types.js';
|
|
2
|
+
import { OrderByOptions } from './orderBy.js';
|
|
3
|
+
export declare function orderByWithFractionalIndexBTree<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: import('../types.js').IStreamBuilder<T>) => import('../types.js').IStreamBuilder<[T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]]>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
|
|
2
|
+
import { PipedOperator } from '../types.js';
|
|
3
|
+
import { MultiSet } from '../multiset.js';
|
|
4
|
+
/**
|
|
5
|
+
* Operator that outputs the messages in the stream
|
|
6
|
+
*/
|
|
7
|
+
export declare class OutputOperator<T> extends UnaryOperator<T> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(id: number, inputA: DifferenceStreamReader<T>, outputWriter: DifferenceStreamWriter<T>, fn: (data: MultiSet<T>) => void);
|
|
10
|
+
run(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Outputs the messages in the stream
|
|
14
|
+
* @param fn - The function to call with each message
|
|
15
|
+
*/
|
|
16
|
+
export declare function output<T>(fn: (data: MultiSet<T>) => void): PipedOperator<T, T>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _fn;
|
|
9
|
+
import { UnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
10
|
+
import { StreamBuilder } from "../d2.js";
|
|
11
|
+
class OutputOperator extends UnaryOperator {
|
|
12
|
+
constructor(id, inputA, outputWriter, fn) {
|
|
13
|
+
super(id, inputA, outputWriter);
|
|
14
|
+
__privateAdd(this, _fn);
|
|
15
|
+
__privateSet(this, _fn, fn);
|
|
16
|
+
}
|
|
17
|
+
run() {
|
|
18
|
+
for (const message of this.inputMessages()) {
|
|
19
|
+
__privateGet(this, _fn).call(this, message);
|
|
20
|
+
this.output.sendData(message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
_fn = new WeakMap();
|
|
25
|
+
function output(fn) {
|
|
26
|
+
return (stream) => {
|
|
27
|
+
const outputStream = new StreamBuilder(
|
|
28
|
+
stream.graph,
|
|
29
|
+
new DifferenceStreamWriter()
|
|
30
|
+
);
|
|
31
|
+
const operator = new OutputOperator(
|
|
32
|
+
stream.graph.getNextOperatorId(),
|
|
33
|
+
stream.connectReader(),
|
|
34
|
+
outputStream.writer,
|
|
35
|
+
fn
|
|
36
|
+
);
|
|
37
|
+
stream.graph.addOperator(operator);
|
|
38
|
+
stream.graph.addStream(outputStream.connectReader());
|
|
39
|
+
return outputStream;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
OutputOperator,
|
|
44
|
+
output
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","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 stream.graph.addStream(outputStream.connectReader())\n return outputStream\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AASO,MAAM,uBAA0B,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,IAAI;AAAA,MACvB,OAAO;AAAA,MACP,IAAI,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,MAAM,UAAU,aAAa,cAAA,CAAe;AACnD,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PipedOperator } from '../types.js';
|
|
2
|
+
export declare function pipe<T, O>(o1: PipedOperator<T, O>): PipedOperator<T, O>;
|
|
3
|
+
export declare function pipe<T, T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): PipedOperator<T, O>;
|
|
4
|
+
export declare function pipe<T, T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): PipedOperator<T, O>;
|
|
5
|
+
export declare function pipe<T, T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): PipedOperator<T, O>;
|
|
6
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
7
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
8
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
9
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
10
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
11
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
12
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
13
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
14
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
15
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
16
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
17
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
18
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
19
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
20
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
21
|
+
export declare function pipe<T, 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>): PipedOperator<T, O>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.js","sources":["../../../src/operators/pipe.ts"],"sourcesContent":["import type { IStreamBuilder, PipedOperator } from \"../types.js\"\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 surely that's enough for anyone...\n// A user can always split the pipe into multiple pipes to get around this.\nexport function pipe<T, O>(o1: PipedOperator<T, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n\n/**\n * Creates a new stream by piping the input stream through a series of operators\n */\nexport function pipe<T>(...operators: Array<PipedOperator<any, any>>) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n return stream.pipe(...operators)\n }\n}\n"],"names":[],"mappings":"AAkDO,SAAS,QAAW,WAA2C;AACpE,SAAO,CAAC,WAAiD;AACvD,WAAO,OAAO,KAAK,GAAG,SAAS;AAAA,EACjC;AACF;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
|
|
2
|
+
import { IStreamBuilder, KeyValue } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base operator for reduction operations (version-free)
|
|
5
|
+
*/
|
|
6
|
+
export declare class ReduceOperator<K, V1, V2> extends UnaryOperator<[K, V1], [K, V2]> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(id: number, inputA: DifferenceStreamReader<[K, V1]>, output: DifferenceStreamWriter<[K, V2]>, f: (values: Array<[V1, number]>) => Array<[V2, number]>);
|
|
9
|
+
run(): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Reduces the elements in the stream by key (version-free)
|
|
13
|
+
*/
|
|
14
|
+
export declare function reduce<KType extends T extends KeyValue<infer K, infer _V> ? K : never, V1Type extends T extends KeyValue<KType, infer V> ? V : never, R, T>(f: (values: Array<[V1Type, number]>) => Array<[R, number]>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<KType, R>>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _index, _indexOut, _f;
|
|
9
|
+
import { UnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
10
|
+
import { StreamBuilder } from "../d2.js";
|
|
11
|
+
import { MultiSet } from "../multiset.js";
|
|
12
|
+
import { Index } from "../indexes.js";
|
|
13
|
+
class ReduceOperator extends UnaryOperator {
|
|
14
|
+
constructor(id, inputA, output, f) {
|
|
15
|
+
super(id, inputA, output);
|
|
16
|
+
__privateAdd(this, _index, new Index());
|
|
17
|
+
__privateAdd(this, _indexOut, new Index());
|
|
18
|
+
__privateAdd(this, _f);
|
|
19
|
+
__privateSet(this, _f, f);
|
|
20
|
+
}
|
|
21
|
+
run() {
|
|
22
|
+
const keysTodo = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const message of this.inputMessages()) {
|
|
24
|
+
for (const [item, multiplicity] of message.getInner()) {
|
|
25
|
+
const [key, value] = item;
|
|
26
|
+
__privateGet(this, _index).addValue(key, [value, multiplicity]);
|
|
27
|
+
keysTodo.add(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const result = [];
|
|
31
|
+
for (const key of keysTodo) {
|
|
32
|
+
const curr = __privateGet(this, _index).get(key);
|
|
33
|
+
const currOut = __privateGet(this, _indexOut).get(key);
|
|
34
|
+
const out = __privateGet(this, _f).call(this, curr);
|
|
35
|
+
const newOutputMap = /* @__PURE__ */ new Map();
|
|
36
|
+
const oldOutputMap = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const [value, multiplicity] of out) {
|
|
38
|
+
const existing = newOutputMap.get(value) ?? 0;
|
|
39
|
+
newOutputMap.set(value, existing + multiplicity);
|
|
40
|
+
}
|
|
41
|
+
for (const [value, multiplicity] of currOut) {
|
|
42
|
+
const existing = oldOutputMap.get(value) ?? 0;
|
|
43
|
+
oldOutputMap.set(value, existing + multiplicity);
|
|
44
|
+
}
|
|
45
|
+
for (const [value, multiplicity] of oldOutputMap) {
|
|
46
|
+
if (!newOutputMap.has(value)) {
|
|
47
|
+
result.push([[key, value], -multiplicity]);
|
|
48
|
+
__privateGet(this, _indexOut).addValue(key, [value, -multiplicity]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const [value, multiplicity] of newOutputMap) {
|
|
52
|
+
if (!oldOutputMap.has(value)) {
|
|
53
|
+
if (multiplicity !== 0) {
|
|
54
|
+
result.push([[key, value], multiplicity]);
|
|
55
|
+
__privateGet(this, _indexOut).addValue(key, [value, multiplicity]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const [value, newMultiplicity] of newOutputMap) {
|
|
60
|
+
const oldMultiplicity = oldOutputMap.get(value);
|
|
61
|
+
if (oldMultiplicity !== void 0) {
|
|
62
|
+
const delta = newMultiplicity - oldMultiplicity;
|
|
63
|
+
if (delta !== 0) {
|
|
64
|
+
result.push([[key, value], delta]);
|
|
65
|
+
__privateGet(this, _indexOut).addValue(key, [value, delta]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (result.length > 0) {
|
|
71
|
+
this.output.sendData(new MultiSet(result));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
_index = new WeakMap();
|
|
76
|
+
_indexOut = new WeakMap();
|
|
77
|
+
_f = new WeakMap();
|
|
78
|
+
function reduce(f) {
|
|
79
|
+
return (stream) => {
|
|
80
|
+
const output = new StreamBuilder(
|
|
81
|
+
stream.graph,
|
|
82
|
+
new DifferenceStreamWriter()
|
|
83
|
+
);
|
|
84
|
+
const operator = new ReduceOperator(
|
|
85
|
+
stream.graph.getNextOperatorId(),
|
|
86
|
+
stream.connectReader(),
|
|
87
|
+
output.writer,
|
|
88
|
+
f
|
|
89
|
+
);
|
|
90
|
+
stream.graph.addOperator(operator);
|
|
91
|
+
stream.graph.addStream(output.connectReader());
|
|
92
|
+
return output;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
ReduceOperator,
|
|
97
|
+
reduce
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=reduce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.js","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 stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAUO,MAAM,uBAAkC,cAAgC;AAAA,EAK7E,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAV1B,+BAAS,IAAI,MAAA;AACb,kCAAY,IAAI,MAAA;AAChB;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAY;AAEV,UAAM,+BAAe,IAAA;AACrB,eAAW,WAAW,KAAK,iBAAiB;AAC1C,iBAAW,CAAC,MAAM,YAAY,KAAK,QAAQ,YAAY;AACrD,cAAM,CAAC,KAAK,KAAK,IAAI;AACrB,2BAAK,QAAO,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAC/C,iBAAS,IAAI,GAAG;AAAA,MAClB;AAAA,IACF;AAGA,UAAM,SAAmC,CAAA;AACzC,eAAW,OAAO,UAAU;AAC1B,YAAM,OAAO,mBAAK,QAAO,IAAI,GAAG;AAChC,YAAM,UAAU,mBAAK,WAAU,IAAI,GAAG;AACtC,YAAM,MAAM,mBAAK,IAAL,WAAQ;AAGpB,YAAM,mCAAmB,IAAA;AACzB,YAAM,mCAAmB,IAAA;AAGzB,iBAAW,CAAC,OAAO,YAAY,KAAK,KAAK;AACvC,cAAM,WAAW,aAAa,IAAI,KAAK,KAAK;AAC5C,qBAAa,IAAI,OAAO,WAAW,YAAY;AAAA,MACjD;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,SAAS;AAC3C,cAAM,WAAW,aAAa,IAAI,KAAK,KAAK;AAC5C,qBAAa,IAAI,OAAO,WAAW,YAAY;AAAA,MACjD;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,cAAc;AAChD,YAAI,CAAC,aAAa,IAAI,KAAK,GAAG;AAE5B,iBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,YAAY,CAAC;AACzC,6BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;AAAA,QACrD;AAAA,MACF;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,cAAc;AAChD,YAAI,CAAC,aAAa,IAAI,KAAK,GAAG;AAE5B,cAAI,iBAAiB,GAAG;AACtB,mBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,YAAY,CAAC;AACxC,+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,IAAI,SAAS,MAAM,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;AAtFE;AACA;AACA;AAyFK,SAAS,OAKd,GAA4D;AAC5D,SAAO,CAAC,WAAkE;AACxE,UAAM,SAAS,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,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,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PipedOperator } from '../types.js';
|
|
2
|
+
import { KeyValue } from '../types.js';
|
|
3
|
+
interface TopKOptions {
|
|
4
|
+
limit?: number;
|
|
5
|
+
offset?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Limits the number of results based on a comparator, with optional offset.
|
|
9
|
+
* This works on a keyed stream, where the key is the first element of the tuple
|
|
10
|
+
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
11
|
+
* and the limit + offset is applied to that sorted group.
|
|
12
|
+
* To order the entire stream, key by the same value for all elements such as null.
|
|
13
|
+
*
|
|
14
|
+
* @param comparator - A function that compares two elements
|
|
15
|
+
* @param options - An optional object containing limit and offset properties
|
|
16
|
+
* @returns A piped operator that limits the number of results
|
|
17
|
+
*/
|
|
18
|
+
export declare function topK<KType extends T extends KeyValue<infer K, infer _V> ? K : never, V1Type extends T extends KeyValue<KType, infer V> ? V : never, T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, T>;
|
|
19
|
+
/**
|
|
20
|
+
* Limits the number of results based on a comparator, with optional offset.
|
|
21
|
+
* This works on a keyed stream, where the key is the first element of the tuple
|
|
22
|
+
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
23
|
+
* and the limit + offset is applied to that sorted group.
|
|
24
|
+
* To order the entire stream, key by the same value for all elements such as null.
|
|
25
|
+
* Adds the index of the element to the result as [key, [value, index]]
|
|
26
|
+
*
|
|
27
|
+
* @param comparator - A function that compares two elements
|
|
28
|
+
* @param options - An optional object containing limit and offset properties
|
|
29
|
+
* @returns A piped operator that orders the elements and limits the number of results
|
|
30
|
+
*/
|
|
31
|
+
export declare function topKWithIndex<KType extends T extends KeyValue<infer K, infer _V> ? K : never, V1Type extends T extends KeyValue<KType, infer V> ? V : never, T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, KeyValue<KType, [V1Type, number]>>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MultiSet } from "../multiset.js";
|
|
2
|
+
import { reduce } from "./reduce.js";
|
|
3
|
+
function topK(comparator, options) {
|
|
4
|
+
const limit = (options == null ? void 0 : options.limit) ?? Infinity;
|
|
5
|
+
const offset = (options == null ? void 0 : options.offset) ?? 0;
|
|
6
|
+
return (stream) => {
|
|
7
|
+
const reduced = stream.pipe(
|
|
8
|
+
reduce((values) => {
|
|
9
|
+
const consolidated = new MultiSet(values).consolidate();
|
|
10
|
+
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0]));
|
|
11
|
+
return sortedValues.slice(offset, offset + limit);
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
return reduced;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function topKWithIndex(comparator, options) {
|
|
18
|
+
const limit = (options == null ? void 0 : options.limit) ?? Infinity;
|
|
19
|
+
const offset = (options == null ? void 0 : options.offset) ?? 0;
|
|
20
|
+
return (stream) => {
|
|
21
|
+
const reduced = stream.pipe(
|
|
22
|
+
reduce((values) => {
|
|
23
|
+
const consolidated = new MultiSet(values).consolidate();
|
|
24
|
+
let i = offset;
|
|
25
|
+
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0])).slice(offset, offset + limit).map(([value, multiplicity]) => [
|
|
26
|
+
[value, i++],
|
|
27
|
+
multiplicity
|
|
28
|
+
]);
|
|
29
|
+
return sortedValues;
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
return reduced;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
topK,
|
|
37
|
+
topKWithIndex
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=topK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topK.js","sources":["../../../src/operators/topK.ts"],"sourcesContent":["import { MultiSet } from \"../multiset.js\"\nimport { reduce } from \"./reduce.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types\"\nimport type { KeyValue } from \"../types.js\"\n\ninterface TopKOptions {\n limit?: number\n offset?: number\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that limits the number of results\n */\nexport function topK<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions\n): PipedOperator<T, T> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const reduced = stream.pipe(\n reduce((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0] as V1Type, b[0] as V1Type))\n return sortedValues.slice(offset, offset + limit)\n })\n )\n return reduced as IStreamBuilder<T>\n }\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n * Adds the index of the element to the result as [key, [value, index]]\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function topKWithIndex<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions\n): PipedOperator<T, KeyValue<KType, [V1Type, number]>> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<KType, [V1Type, number]>> => {\n const reduced = stream.pipe(\n reduce<KType, V1Type, [V1Type, number], T>((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n let i = offset\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0], b[0]))\n .slice(offset, offset + limit)\n .map(([value, multiplicity]): [[V1Type, number], number] => [\n [value, i++],\n multiplicity,\n ])\n return sortedValues\n })\n )\n return reduced\n }\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,KAKd,YACA,SACqB;AACrB,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAElC,SAAO,CAAC,WAAiD;AACvD,UAAM,UAAU,OAAO;AAAA,MACrB,OAAO,CAAC,WAAW;AAEjB,cAAM,eAAe,IAAI,SAAS,MAAM,EAAE,YAAA;AAC1C,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAa,EAAE,CAAC,CAAW,CAAC;AAC5D,eAAO,aAAa,MAAM,QAAQ,SAAS,KAAK;AAAA,MAClD,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;AAcO,SAAS,cAKd,YACA,SACqD;AACrD,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAElC,SAAO,CACL,WACsD;AACtD,UAAM,UAAU,OAAO;AAAA,MACrB,OAA2C,CAAC,WAAW;AAErD,cAAM,eAAe,IAAI,SAAS,MAAM,EAAE,YAAA;AAC1C,YAAI,IAAI;AACR,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EACrC,MAAM,QAAQ,SAAS,KAAK,EAC5B,IAAI,CAAC,CAAC,OAAO,YAAY,MAAkC;AAAA,UAC1D,CAAC,OAAO,GAAG;AAAA,UACX;AAAA,QAAA,CACD;AACH,eAAO;AAAA,MACT,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;"}
|