@tanstack/db-ivm 0.1.25 → 0.1.26

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.
Files changed (60) hide show
  1. package/dist/cjs/d2.d.cts +3 -3
  2. package/dist/cjs/graph.d.cts +2 -2
  3. package/dist/cjs/hashing/index.d.cts +2 -2
  4. package/dist/cjs/index.cjs +42 -42
  5. package/dist/cjs/index.d.cts +6 -6
  6. package/dist/cjs/indexes.d.cts +38 -8
  7. package/dist/cjs/multiset.d.cts +8 -2
  8. package/dist/cjs/operators/concat.d.cts +2 -2
  9. package/dist/cjs/operators/consolidate.d.cts +2 -2
  10. package/dist/cjs/operators/count.cjs.map +1 -1
  11. package/dist/cjs/operators/count.d.cts +11 -5
  12. package/dist/cjs/operators/debug.d.cts +2 -2
  13. package/dist/cjs/operators/distinct.d.cts +2 -2
  14. package/dist/cjs/operators/filter.d.cts +3 -3
  15. package/dist/cjs/operators/filterBy.cjs.map +1 -1
  16. package/dist/cjs/operators/filterBy.d.cts +2 -2
  17. package/dist/cjs/operators/groupBy.cjs.map +1 -1
  18. package/dist/cjs/operators/groupBy.d.cts +5 -2
  19. package/dist/cjs/operators/groupedOrderBy.d.cts +8 -2
  20. package/dist/cjs/operators/groupedTopKWithFractionalIndex.d.cts +34 -7
  21. package/dist/cjs/operators/index.d.cts +21 -21
  22. package/dist/cjs/operators/join.cjs.map +1 -1
  23. package/dist/cjs/operators/join.d.cts +49 -10
  24. package/dist/cjs/operators/keying.d.cts +5 -2
  25. package/dist/cjs/operators/map.d.cts +3 -3
  26. package/dist/cjs/operators/negate.d.cts +3 -3
  27. package/dist/cjs/operators/orderBy.d.cts +20 -5
  28. package/dist/cjs/operators/output.d.cts +3 -3
  29. package/dist/cjs/operators/pipe.d.cts +1 -1
  30. package/dist/cjs/operators/reduce.cjs.map +1 -1
  31. package/dist/cjs/operators/reduce.d.cts +29 -5
  32. package/dist/cjs/operators/tap.d.cts +3 -3
  33. package/dist/cjs/operators/topK.cjs.map +1 -1
  34. package/dist/cjs/operators/topK.d.cts +5 -2
  35. package/dist/cjs/operators/topKArray.d.cts +11 -2
  36. package/dist/cjs/operators/topKState.d.cts +44 -8
  37. package/dist/cjs/operators/topKWithFractionalIndex.d.cts +41 -8
  38. package/dist/cjs/operators/topKWithFractionalIndexBTree.d.cts +20 -5
  39. package/dist/cjs/types.d.cts +6 -3
  40. package/dist/cjs/utils.d.cts +4 -1
  41. package/dist/esm/index.js +15 -15
  42. package/dist/esm/operators/count.d.ts +1 -1
  43. package/dist/esm/operators/count.js.map +1 -1
  44. package/dist/esm/operators/filterBy.d.ts +1 -1
  45. package/dist/esm/operators/filterBy.js.map +1 -1
  46. package/dist/esm/operators/groupBy.js.map +1 -1
  47. package/dist/esm/operators/join.d.ts +6 -6
  48. package/dist/esm/operators/join.js.map +1 -1
  49. package/dist/esm/operators/reduce.d.ts +1 -1
  50. package/dist/esm/operators/reduce.js.map +1 -1
  51. package/dist/esm/operators/topK.d.ts +2 -2
  52. package/dist/esm/operators/topK.js.map +1 -1
  53. package/dist/esm/operators/topKArray.js +1 -1
  54. package/package.json +2 -2
  55. package/src/operators/count.ts +2 -2
  56. package/src/operators/filterBy.ts +1 -1
  57. package/src/operators/groupBy.ts +1 -2
  58. package/src/operators/join.ts +6 -6
  59. package/src/operators/reduce.ts +2 -2
  60. package/src/operators/topK.ts +4 -4
package/dist/cjs/d2.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { DifferenceStreamWriter, BinaryOperator, DifferenceStreamReader, UnaryOperator } from './graph.js';
2
- import { MultiSet, MultiSetArray } from './multiset.js';
3
- import { ID2, IStreamBuilder, PipedOperator } from './types.js';
1
+ import { DifferenceStreamWriter, BinaryOperator, DifferenceStreamReader, UnaryOperator } from "./graph.cjs";
2
+ import { MultiSet, MultiSetArray } from "./multiset.cjs";
3
+ import { ID2, IStreamBuilder, PipedOperator } from "./types.cjs";
4
4
  export declare class D2 implements ID2 {
5
5
  #private;
6
6
  constructor();
@@ -1,5 +1,5 @@
1
- import { MultiSet, MultiSetArray } from './multiset.js';
2
- import { IDifferenceStreamReader, IDifferenceStreamWriter, IOperator } from './types.js';
1
+ import { MultiSet, MultiSetArray } from "./multiset.cjs";
2
+ import { IDifferenceStreamReader, IDifferenceStreamWriter, IOperator } from "./types.cjs";
3
3
  /**
4
4
  * A read handle to a dataflow edge that receives data from a writer.
5
5
  */
@@ -1,2 +1,2 @@
1
- export { hash } from './hash.js';
2
- export type { Hash, Hasher } from './murmur.js';
1
+ export { hash } from "./hash.cjs";
2
+ export type { Hash, Hasher } from "./murmur.cjs";
@@ -4,27 +4,27 @@ const d2 = require("./d2.cjs");
4
4
  const multiset = require("./multiset.cjs");
5
5
  const utils = require("./utils.cjs");
6
6
  const hash = require("./hashing/hash.cjs");
7
- const groupBy = require("./operators/groupBy.cjs");
8
- const pipe = require("./operators/pipe.cjs");
9
- const map = require("./operators/map.cjs");
10
- const tap = require("./operators/tap.cjs");
11
- const filter = require("./operators/filter.cjs");
12
- const negate = require("./operators/negate.cjs");
13
7
  const concat = require("./operators/concat.cjs");
14
- const debug = require("./operators/debug.cjs");
15
- const output = require("./operators/output.cjs");
16
8
  const consolidate = require("./operators/consolidate.cjs");
17
- const join = require("./operators/join.cjs");
18
- const reduce = require("./operators/reduce.cjs");
19
9
  const count = require("./operators/count.cjs");
10
+ const debug = require("./operators/debug.cjs");
20
11
  const distinct = require("./operators/distinct.cjs");
21
- const keying = require("./operators/keying.cjs");
22
- const topK = require("./operators/topK.cjs");
23
- const topKWithFractionalIndex = require("./operators/topKWithFractionalIndex.cjs");
12
+ const filter = require("./operators/filter.cjs");
24
13
  const groupedTopKWithFractionalIndex = require("./operators/groupedTopKWithFractionalIndex.cjs");
25
- const orderBy = require("./operators/orderBy.cjs");
26
- const groupedOrderBy = require("./operators/groupedOrderBy.cjs");
14
+ const join = require("./operators/join.cjs");
15
+ const map = require("./operators/map.cjs");
16
+ const negate = require("./operators/negate.cjs");
17
+ const output = require("./operators/output.cjs");
18
+ const reduce = require("./operators/reduce.cjs");
19
+ const tap = require("./operators/tap.cjs");
20
+ const topKWithFractionalIndex = require("./operators/topKWithFractionalIndex.cjs");
27
21
  const filterBy = require("./operators/filterBy.cjs");
22
+ const groupBy = require("./operators/groupBy.cjs");
23
+ const groupedOrderBy = require("./operators/groupedOrderBy.cjs");
24
+ const keying = require("./operators/keying.cjs");
25
+ const orderBy = require("./operators/orderBy.cjs");
26
+ const pipe = require("./operators/pipe.cjs");
27
+ const topK = require("./operators/topK.cjs");
28
28
  exports.D2 = d2.D2;
29
29
  exports.RootStreamBuilder = d2.RootStreamBuilder;
30
30
  exports.StreamBuilder = d2.StreamBuilder;
@@ -32,25 +32,20 @@ exports.MultiSet = multiset.MultiSet;
32
32
  exports.compareKeys = utils.compareKeys;
33
33
  exports.serializeValue = utils.serializeValue;
34
34
  exports.registerOpaqueHash = hash.registerOpaqueHash;
35
- exports.groupBy = groupBy.groupBy;
36
- exports.groupByOperators = groupBy.groupByOperators;
37
- exports.pipe = pipe.pipe;
38
- exports.MapOperator = map.MapOperator;
39
- exports.map = map.map;
40
- exports.TapOperator = tap.TapOperator;
41
- exports.tap = tap.tap;
42
- exports.FilterOperator = filter.FilterOperator;
43
- exports.filter = filter.filter;
44
- exports.NegateOperator = negate.NegateOperator;
45
- exports.negate = negate.negate;
46
35
  exports.ConcatOperator = concat.ConcatOperator;
47
36
  exports.concat = concat.concat;
48
- exports.DebugOperator = debug.DebugOperator;
49
- exports.debug = debug.debug;
50
- exports.OutputOperator = output.OutputOperator;
51
- exports.output = output.output;
52
37
  exports.ConsolidateOperator = consolidate.ConsolidateOperator;
53
38
  exports.consolidate = consolidate.consolidate;
39
+ exports.CountOperator = count.CountOperator;
40
+ exports.count = count.count;
41
+ exports.DebugOperator = debug.DebugOperator;
42
+ exports.debug = debug.debug;
43
+ exports.DistinctOperator = distinct.DistinctOperator;
44
+ exports.distinct = distinct.distinct;
45
+ exports.FilterOperator = filter.FilterOperator;
46
+ exports.filter = filter.filter;
47
+ exports.GroupedTopKWithFractionalIndexOperator = groupedTopKWithFractionalIndex.GroupedTopKWithFractionalIndexOperator;
48
+ exports.groupedTopKWithFractionalIndex = groupedTopKWithFractionalIndex.groupedTopKWithFractionalIndex;
54
49
  exports.JoinOperator = join.JoinOperator;
55
50
  exports.antiJoin = join.antiJoin;
56
51
  exports.fullJoin = join.fullJoin;
@@ -58,25 +53,30 @@ exports.innerJoin = join.innerJoin;
58
53
  exports.join = join.join;
59
54
  exports.leftJoin = join.leftJoin;
60
55
  exports.rightJoin = join.rightJoin;
56
+ exports.MapOperator = map.MapOperator;
57
+ exports.map = map.map;
58
+ exports.NegateOperator = negate.NegateOperator;
59
+ exports.negate = negate.negate;
60
+ exports.OutputOperator = output.OutputOperator;
61
+ exports.output = output.output;
61
62
  exports.ReduceOperator = reduce.ReduceOperator;
62
63
  exports.reduce = reduce.reduce;
63
- exports.CountOperator = count.CountOperator;
64
- exports.count = count.count;
65
- exports.DistinctOperator = distinct.DistinctOperator;
66
- exports.distinct = distinct.distinct;
64
+ exports.TapOperator = tap.TapOperator;
65
+ exports.tap = tap.tap;
66
+ exports.TopKWithFractionalIndexOperator = topKWithFractionalIndex.TopKWithFractionalIndexOperator;
67
+ exports.topKWithFractionalIndex = topKWithFractionalIndex.topKWithFractionalIndex;
68
+ exports.filterBy = filterBy.filterBy;
69
+ exports.groupBy = groupBy.groupBy;
70
+ exports.groupByOperators = groupBy.groupByOperators;
71
+ exports.groupedOrderByWithFractionalIndex = groupedOrderBy.groupedOrderByWithFractionalIndex;
67
72
  exports.keyBy = keying.keyBy;
68
73
  exports.rekey = keying.rekey;
69
74
  exports.unkey = keying.unkey;
70
- exports.topK = topK.topK;
71
- exports.topKWithIndex = topK.topKWithIndex;
72
- exports.TopKWithFractionalIndexOperator = topKWithFractionalIndex.TopKWithFractionalIndexOperator;
73
- exports.topKWithFractionalIndex = topKWithFractionalIndex.topKWithFractionalIndex;
74
- exports.GroupedTopKWithFractionalIndexOperator = groupedTopKWithFractionalIndex.GroupedTopKWithFractionalIndexOperator;
75
- exports.groupedTopKWithFractionalIndex = groupedTopKWithFractionalIndex.groupedTopKWithFractionalIndex;
76
75
  exports.orderBy = orderBy.orderBy;
77
76
  exports.orderByWithFractionalIndex = orderBy.orderByWithFractionalIndex;
78
77
  exports.orderByWithFractionalIndexBase = orderBy.orderByWithFractionalIndexBase;
79
78
  exports.orderByWithIndex = orderBy.orderByWithIndex;
80
- exports.groupedOrderByWithFractionalIndex = groupedOrderBy.groupedOrderByWithFractionalIndex;
81
- exports.filterBy = filterBy.filterBy;
79
+ exports.pipe = pipe.pipe;
80
+ exports.topK = topK.topK;
81
+ exports.topKWithIndex = topK.topKWithIndex;
82
82
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,6 @@
1
- export * from './d2.js';
2
- export * from './multiset.js';
3
- export * from './operators/index.js';
4
- export * from './types.js';
5
- export { compareKeys, serializeValue } from './utils.js';
6
- export { registerOpaqueHash } from './hashing/hash.js';
1
+ export * from "./d2.cjs";
2
+ export * from "./multiset.cjs";
3
+ export * from "./operators/index.cjs";
4
+ export * from "./types.cjs";
5
+ export { compareKeys, serializeValue } from "./utils.cjs";
6
+ export { registerOpaqueHash } from "./hashing/hash.cjs";
@@ -1,5 +1,8 @@
1
- import { MultiSet } from './multiset.js';
2
- type SingleValue<TValue> = [TValue, number];
1
+ import { MultiSet } from "./multiset.cjs";
2
+ type SingleValue<TValue> = [
3
+ TValue,
4
+ number
5
+ ];
3
6
  /**
4
7
  * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
5
8
  * Used in operations like join and reduce where the operation needs to
@@ -13,7 +16,10 @@ export declare class Index<TKey, TValue, TPrefix = any> {
13
16
  * @param messages - Array of MultiSet messages to build the index from.
14
17
  * @returns A new Index containing all the data from the messages.
15
18
  */
16
- static fromMultiSets<K, V>(messages: Array<MultiSet<[K, V]>>): Index<K, V>;
19
+ static fromMultiSets<K, V>(messages: Array<MultiSet<[
20
+ K,
21
+ V
22
+ ]>>): Index<K, V>;
17
23
  /**
18
24
  * This method returns a string representation of the index.
19
25
  * @param indent - Whether to indent the string representation.
@@ -52,25 +58,43 @@ export declare class Index<TKey, TValue, TPrefix = any> {
52
58
  * @param key - The key to get the values for.
53
59
  * @returns An array of value tuples [value, multiplicity].
54
60
  */
55
- get(key: TKey): Array<[TValue, number]>;
61
+ get(key: TKey): Array<[
62
+ TValue,
63
+ number
64
+ ]>;
56
65
  /**
57
66
  * This method returns an iterator over all values for a given key.
58
67
  * @param key - The key to get the values for.
59
68
  * @returns An iterator of value tuples [value, multiplicity].
60
69
  */
61
- getIterator(key: TKey): Iterable<[TValue, number]>;
70
+ getIterator(key: TKey): Iterable<[
71
+ TValue,
72
+ number
73
+ ]>;
62
74
  /**
63
75
  * This returns an iterator that iterates over all key-value pairs.
64
76
  * @returns An iterable of all key-value pairs (and their multiplicities) in the index.
65
77
  */
66
- entries(): Iterable<[TKey, [TValue, number]]>;
78
+ entries(): Iterable<[
79
+ TKey,
80
+ [
81
+ TValue,
82
+ number
83
+ ]
84
+ ]>;
67
85
  /**
68
86
  * This method only iterates over the keys and not over the values.
69
87
  * Hence, it is more efficient than the `#entries` method.
70
88
  * It returns an iterator that you can use if you need to iterate over the values for a given key.
71
89
  * @returns An iterator of all *keys* in the index and their corresponding value iterator.
72
90
  */
73
- entriesIterators(): Iterable<[TKey, Iterable<[TValue, number]>]>;
91
+ entriesIterators(): Iterable<[
92
+ TKey,
93
+ Iterable<[
94
+ TValue,
95
+ number
96
+ ]>
97
+ ]>;
74
98
  /**
75
99
  * This method adds a value to the index.
76
100
  * @param key - The key to add the value to.
@@ -87,6 +111,12 @@ export declare class Index<TKey, TValue, TPrefix = any> {
87
111
  * @param other - The index to join with the current index.
88
112
  * @returns A multiset of the joined values.
89
113
  */
90
- join<TValue2>(other: Index<TKey, TValue2>): MultiSet<[TKey, [TValue, TValue2]]>;
114
+ join<TValue2>(other: Index<TKey, TValue2>): MultiSet<[
115
+ TKey,
116
+ [
117
+ TValue,
118
+ TValue2
119
+ ]
120
+ ]>;
91
121
  }
92
122
  export {};
@@ -1,5 +1,11 @@
1
- export type MultiSetArray<T> = Array<[T, number]>;
2
- export type KeyedData<T> = [key: string, value: T];
1
+ export type MultiSetArray<T> = Array<[
2
+ T,
3
+ number
4
+ ]>;
5
+ export type KeyedData<T> = [
6
+ key: string,
7
+ value: T
8
+ ];
3
9
  /**
4
10
  * A multiset of data.
5
11
  */
@@ -1,5 +1,5 @@
1
- import { BinaryOperator } from '../graph.js';
2
- import { IStreamBuilder, PipedOperator } from '../types.js';
1
+ import { BinaryOperator } from "../graph.cjs";
2
+ import { IStreamBuilder, PipedOperator } from "../types.cjs";
3
3
  /**
4
4
  * Operator that concatenates two input streams
5
5
  */
@@ -1,5 +1,5 @@
1
- import { UnaryOperator } from '../graph.js';
2
- import { PipedOperator } from '../types.js';
1
+ import { UnaryOperator } from "../graph.cjs";
2
+ import { PipedOperator } from "../types.cjs";
3
3
  /**
4
4
  * Operator that consolidates collections
5
5
  */
@@ -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 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
+ {"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,13 +1,19 @@
1
- import { DifferenceStreamWriter, DifferenceStreamReader } from '../graph.js';
2
- import { ReduceOperator } from './reduce.js';
3
- import { IStreamBuilder, KeyValue } from '../types.js';
1
+ import { DifferenceStreamWriter, DifferenceStreamReader } from "../graph.cjs";
2
+ import { ReduceOperator } from "./reduce.cjs";
3
+ import { IStreamBuilder, KeyValue } from "../types.cjs";
4
4
  /**
5
5
  * Operator that counts elements by key (version-free)
6
6
  */
7
7
  export declare class CountOperator<K, V> extends ReduceOperator<K, V, number> {
8
- constructor(id: number, inputA: DifferenceStreamReader<[K, V]>, output: DifferenceStreamWriter<[K, number]>);
8
+ constructor(id: number, inputA: DifferenceStreamReader<[
9
+ K,
10
+ V
11
+ ]>, output: DifferenceStreamWriter<[
12
+ K,
13
+ number
14
+ ]>);
9
15
  }
10
16
  /**
11
17
  * Counts the number of elements by key (version-free)
12
18
  */
13
- export declare function count<KType extends T extends KeyValue<infer K, infer _V> ? K : never, VType extends T extends KeyValue<KType, infer V> ? V : never, T>(): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<KType, number>>;
19
+ export declare function count<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), VType extends (T extends KeyValue<KType, infer V> ? V : never), T>(): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<KType, number>>;
@@ -1,5 +1,5 @@
1
- import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
2
- import { PipedOperator } from '../types.js';
1
+ import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from "../graph.cjs";
2
+ import { PipedOperator } from "../types.cjs";
3
3
  /**
4
4
  * Operator that logs debug information about the stream
5
5
  */
@@ -1,5 +1,5 @@
1
- import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
2
- import { IStreamBuilder, KeyValue } from '../types.js';
1
+ import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from "../graph.cjs";
2
+ import { IStreamBuilder, KeyValue } from "../types.cjs";
3
3
  type GetValue<T> = T extends KeyValue<any, infer V> ? V : never;
4
4
  /**
5
5
  * Operator that removes duplicates
@@ -1,6 +1,6 @@
1
- import { DifferenceStreamWriter, LinearUnaryOperator, DifferenceStreamReader } from '../graph.js';
2
- import { PipedOperator } from '../types.js';
3
- import { MultiSet } from '../multiset.js';
1
+ import { DifferenceStreamWriter, LinearUnaryOperator, DifferenceStreamReader } from "../graph.cjs";
2
+ import { PipedOperator } from "../types.cjs";
3
+ import { MultiSet } from "../multiset.cjs";
4
4
  /**
5
5
  * Operator that filters elements from the input stream
6
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"filterBy.cjs","sources":["../../../src/operators/filterBy.ts"],"sourcesContent":["import { map } from './map.js'\nimport { innerJoin } from './join.js'\nimport { consolidate } from './consolidate.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types.js'\n\n/**\n * Filters the elements of a keyed stream, by keys of another stream.\n * This allows you to build pipelies where you have multiple outputs that are related,\n * such as a streams of issues and comments for a project.\n *\n * @param other - The other stream to filter by, which must have the same key type as the input stream\n */\nexport function filterBy<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, unknown>>,\n): PipedOperator<T, KeyValue<K, V1>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, V1>> => {\n const otherKeys = other.pipe(\n map(([key, _]) => [key, null] as KeyValue<K, null>),\n )\n return stream.pipe(\n innerJoin(otherKeys),\n map(([key, [value, _]]) => [key, value] as KeyValue<K, V1>),\n consolidate(),\n )\n }\n}\n"],"names":["map","innerJoin","consolidate"],"mappings":";;;;;AAYO,SAAS,SAKd,OACmC;AACnC,SAAO,CAAC,WAA+D;AACrE,UAAM,YAAY,MAAM;AAAA,MACtBA,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAsB;AAAA,IAAA;AAEpD,WAAO,OAAO;AAAA,MACZC,KAAAA,UAAU,SAAS;AAAA,MACnBD,QAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAoB;AAAA,MAC1DE,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;;"}
1
+ {"version":3,"file":"filterBy.cjs","sources":["../../../src/operators/filterBy.ts"],"sourcesContent":["import { map } from './map.js'\nimport { innerJoin } from './join.js'\nimport { consolidate } from './consolidate.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types.js'\n\n/**\n * Filters the elements of a keyed stream, by keys of another stream.\n * This allows you to build pipelies where you have multiple outputs that are related,\n * such as a streams of issues and comments for a project.\n *\n * @param other - The other stream to filter by, which must have the same key type as the input stream\n */\nexport function filterBy<\n K,\n V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never),\n T,\n>(\n other: IStreamBuilder<KeyValue<K, unknown>>,\n): PipedOperator<T, KeyValue<K, V1>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, V1>> => {\n const otherKeys = other.pipe(\n map(([key, _]) => [key, null] as KeyValue<K, null>),\n )\n return stream.pipe(\n innerJoin(otherKeys),\n map(([key, [value, _]]) => [key, value] as KeyValue<K, V1>),\n consolidate(),\n )\n }\n}\n"],"names":["map","innerJoin","consolidate"],"mappings":";;;;;AAYO,SAAS,SAKd,OACmC;AACnC,SAAO,CAAC,WAA+D;AACrE,UAAM,YAAY,MAAM;AAAA,MACtBA,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAsB;AAAA,IAAA;AAEpD,WAAO,OAAO;AAAA,MACZC,KAAAA,UAAU,SAAS;AAAA,MACnBD,QAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAoB;AAAA,MAC1DE,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;;"}
@@ -1,4 +1,4 @@
1
- import { IStreamBuilder, KeyValue, PipedOperator } from '../types.js';
1
+ import { IStreamBuilder, KeyValue, PipedOperator } from "../types.cjs";
2
2
  /**
3
3
  * Filters the elements of a keyed stream, by keys of another stream.
4
4
  * This allows you to build pipelies where you have multiple outputs that are related,
@@ -6,4 +6,4 @@ import { IStreamBuilder, KeyValue, PipedOperator } from '../types.js';
6
6
  *
7
7
  * @param other - The other stream to filter by, which must have the same key type as the input stream
8
8
  */
9
- export declare function filterBy<K, V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never, T>(other: IStreamBuilder<KeyValue<K, unknown>>): PipedOperator<T, KeyValue<K, V1>>;
9
+ export declare function filterBy<K, V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never), T>(other: IStreamBuilder<KeyValue<K, unknown>>): PipedOperator<T, KeyValue<K, V1>>;
@@ -1 +1 @@
1
- {"version":3,"file":"groupBy.cjs","sources":["../../../src/operators/groupBy.ts"],"sourcesContent":["import { serializeValue } from '../utils.js'\nimport { map } from './map.js'\nimport { reduce } from './reduce.js'\nimport type { IStreamBuilder, KeyValue } from '../types.js'\n\ntype GroupKey = Record<string, unknown>\n\ntype BasicAggregateFunction<T, R, V = unknown> = {\n preMap: (data: T) => V\n reduce: (values: Array<[V, number]>) => V\n postMap?: (result: V) => R\n}\n\ntype PipedAggregateFunction<T, R> = {\n pipe: (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<string, R>>\n}\n\ntype AggregateFunction<T, R, V = unknown> =\n | BasicAggregateFunction<T, R, V>\n | PipedAggregateFunction<T, R>\n\ntype ExtractAggregateReturnType<T, A> =\n A extends AggregateFunction<T, infer R, any> ? R : never\n\ntype AggregatesReturnType<T, A> = {\n [K in keyof A]: ExtractAggregateReturnType<T, A[K]>\n}\n\nfunction isPipedAggregateFunction<T, R>(\n aggregate: AggregateFunction<T, R>,\n): aggregate is PipedAggregateFunction<T, R> {\n return `pipe` in aggregate\n}\n\n/**\n * Groups data by key and applies multiple aggregate operations\n * @param keyExtractor Function to extract grouping key from data\n * @param aggregates Object mapping aggregate names to aggregate functions\n */\nexport function groupBy<\n T,\n K extends GroupKey,\n A extends Record<string, AggregateFunction<T, any, any>>,\n>(keyExtractor: (data: T) => K, aggregates: A = {} as A) {\n type ResultType = K & AggregatesReturnType<T, A>\n\n const basicAggregates = Object.fromEntries(\n Object.entries(aggregates).filter(\n ([_, aggregate]) => !isPipedAggregateFunction(aggregate),\n ),\n ) as Record<string, BasicAggregateFunction<T, any, any>>\n\n // @ts-expect-error - TODO: we don't use this yet, but we will\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const pipedAggregates = Object.fromEntries(\n Object.entries(aggregates).filter(([_, aggregate]) =>\n isPipedAggregateFunction(aggregate),\n ),\n ) as Record<string, PipedAggregateFunction<T, any>>\n\n return (\n stream: IStreamBuilder<T>,\n ): IStreamBuilder<KeyValue<string, ResultType>> => {\n // Special key to store the original key object\n const KEY_SENTINEL = Symbol(`original_group_key`)\n\n // First map to extract keys and pre-aggregate values\n const withKeysAndValues = stream.pipe(\n map((data) => {\n const key = keyExtractor(data)\n const keyString = serializeValue(key)\n\n // Create values object with pre-aggregated values\n const values: Record<string | symbol, unknown> = {}\n\n // Store the original key object\n values[KEY_SENTINEL] = key\n\n // Add pre-aggregated values\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n values[name] = aggregate.preMap(data)\n }\n\n return [keyString, values] as KeyValue<\n string,\n Record<string | symbol, unknown>\n >\n }),\n )\n\n // Then reduce to compute aggregates\n const reduced = withKeysAndValues.pipe(\n reduce((values) => {\n // Calculate total multiplicity to check if the group should exist\n let totalMultiplicity = 0\n for (const [_, multiplicity] of values) {\n totalMultiplicity += multiplicity\n }\n\n // If total multiplicity is 0 or negative, the group should be removed completely\n if (totalMultiplicity <= 0) {\n return []\n }\n\n const result: Record<PropertyKey, unknown> = {}\n\n // Get the original key from first value in group\n const originalKey = values[0]?.[0]?.[KEY_SENTINEL]\n result[KEY_SENTINEL] = originalKey\n\n // Apply each aggregate function\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n const preValues = values.map(\n ([v, m]) => [v[name], m] as [any, number],\n )\n result[name] = aggregate.reduce(preValues)\n }\n\n return [[result, 1]]\n }),\n )\n\n // Finally map to extract the key and include all values\n return reduced.pipe(\n map(([keyString, values]) => {\n // Extract the original key\n const key = values[KEY_SENTINEL] as K\n\n // Create intermediate result with key values and aggregate results\n const result: Record<string, unknown> = {}\n\n // Add key properties to result\n Object.assign(result, key)\n\n // Apply postMap if provided\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n if (aggregate.postMap) {\n result[name] = aggregate.postMap(values[name])\n } else {\n result[name] = values[name]\n }\n }\n\n // Return with the string key instead of the object\n return [keyString, result] as KeyValue<string, ResultType>\n }),\n )\n }\n}\n\n/**\n * Creates a sum aggregate function\n */\nexport function sum<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, number> {\n return {\n preMap: (data: T) => valueExtractor(data),\n reduce: (values: Array<[number, number]>) => {\n let total = 0\n for (const [value, multiplicity] of values) {\n total += value * multiplicity\n }\n return total\n },\n }\n}\n\n/**\n * Creates a count aggregate function\n */\nexport function count<T>(\n valueExtractor: (value: T) => any = (v) => v,\n): AggregateFunction<T, number, number> {\n return {\n // Count only not-null values (the `== null` comparison gives true for both null and undefined)\n preMap: (data: T) => (valueExtractor(data) == null ? 0 : 1),\n reduce: (values: Array<[number, number]>) => {\n let totalCount = 0\n for (const [nullMultiplier, multiplicity] of values) {\n totalCount += nullMultiplier * multiplicity\n }\n return totalCount\n },\n }\n}\n\n/**\n * Creates an average aggregate function\n */\nexport function avg<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, { sum: number; count: number }> {\n return {\n preMap: (data: T) => ({\n sum: valueExtractor(data),\n count: 0,\n }),\n reduce: (values: Array<[{ sum: number; count: number }, number]>) => {\n let totalSum = 0\n let totalCount = 0\n for (const [value, multiplicity] of values) {\n totalSum += value.sum * multiplicity\n totalCount += multiplicity\n }\n return {\n sum: totalSum,\n count: totalCount,\n }\n },\n postMap: (result: { sum: number; count: number }) => {\n return result.sum / result.count\n },\n }\n}\n\ntype CanMinMax = number | Date | bigint | string\n\n/**\n * Creates a min aggregate function that computes the minimum value in a group\n * @param valueExtractor Function to extract a comparable value from each data entry\n */\nexport function min<T extends CanMinMax>(): AggregateFunction<\n T,\n T | undefined,\n T | undefined\n>\nexport function min<T, V extends CanMinMax>(\n valueExtractor: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined>\nexport function min<T, V extends CanMinMax>(\n valueExtractor?: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined> {\n const extractor = valueExtractor ?? ((v: T) => v as unknown as V)\n return {\n preMap: (data: T) => extractor(data),\n reduce: (values) => {\n let minValue: V | undefined\n for (const [value, _multiplicity] of values) {\n if (\n value !== undefined &&\n (minValue === undefined || value < minValue)\n ) {\n minValue = value\n }\n }\n return minValue\n },\n }\n}\n\n/**\n * Creates a max aggregate function that computes the maximum value in a group\n * @param valueExtractor Function to extract a comparable value from each data entry\n */\nexport function max<T extends CanMinMax>(): AggregateFunction<\n T,\n T | undefined,\n T | undefined\n>\nexport function max<T, V extends CanMinMax>(\n valueExtractor: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined>\nexport function max<T, V extends CanMinMax>(\n valueExtractor?: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined> {\n const extractor = valueExtractor ?? ((v: T) => v as unknown as V)\n return {\n preMap: (data: T) => extractor(data),\n reduce: (values) => {\n let maxValue: V | undefined\n for (const [value, _multiplicity] of values) {\n if (\n value !== undefined &&\n (maxValue === undefined || value > maxValue)\n ) {\n maxValue = value\n }\n }\n return maxValue\n },\n }\n}\n\n/**\n * Creates a median aggregate function that computes the middle value in a sorted group\n * If there's an even number of values, returns the average of the two middle values\n * @param valueExtractor Function to extract a numeric value from each data entry\n */\nexport function median<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, Array<number>> {\n return {\n preMap: (data: T) => [valueExtractor(data)],\n reduce: (values: Array<[Array<number>, number]>) => {\n // Flatten all values, taking multiplicity into account\n const allValues: Array<number> = []\n for (const [valueArray, multiplicity] of values) {\n for (const value of valueArray) {\n // Add each value multiple times based on multiplicity\n for (let i = 0; i < multiplicity; i++) {\n allValues.push(value)\n }\n }\n }\n\n // Return empty array if no values\n if (allValues.length === 0) {\n return []\n }\n\n // Sort values\n allValues.sort((a, b) => a - b)\n\n return allValues\n },\n postMap: (result: Array<number>) => {\n if (result.length === 0) return 0\n\n const mid = Math.floor(result.length / 2)\n\n // If even number of values, average the two middle values\n if (result.length % 2 === 0) {\n return (result[mid - 1]! + result[mid]!) / 2\n }\n\n // If odd number of values, return the middle value\n return result[mid]!\n },\n }\n}\n\n/**\n * Creates a mode aggregate function that computes the most frequent value in a group\n * If multiple values have the same highest frequency, returns the first one encountered\n * @param valueExtractor Function to extract a value from each data entry\n */\nexport function mode<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, Map<number, number>> {\n return {\n preMap: (data: T) => {\n const value = valueExtractor(data)\n const frequencyMap = new Map<number, number>()\n frequencyMap.set(value, 1)\n return frequencyMap\n },\n reduce: (values: Array<[Map<number, number>, number]>) => {\n // Combine all frequency maps\n const combinedMap = new Map<number, number>()\n\n for (const [frequencyMap, multiplicity] of values) {\n for (const [value, frequencyCount] of frequencyMap.entries()) {\n const currentCount = combinedMap.get(value) || 0\n combinedMap.set(value, currentCount + frequencyCount * multiplicity)\n }\n }\n\n return combinedMap\n },\n postMap: (result: Map<number, number>) => {\n if (result.size === 0) return 0\n\n let modeValue = 0\n let maxFrequency = 0\n\n for (const [value, frequency] of result.entries()) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency\n modeValue = value\n }\n }\n\n return modeValue\n },\n }\n}\n\nexport const groupByOperators = {\n sum,\n count,\n av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I,OAAO,SAAS,EAAG,QAAO;AAE9B,UAAI,YAAY;AAChB,UAAI,eAAe;AAEnB,iBAAW,CAAC,OAAO,SAAS,KAAK,OAAO,WAAW;AACjD,YAAI,YAAY,cAAc;AAC5B,yBAAe;AACf,sBAAY;AAAA,QACd;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAEO,MAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;;;;;;;;"}
1
+ {"version":3,"file":"groupBy.cjs","sources":["../../../src/operators/groupBy.ts"],"sourcesContent":["import { serializeValue } from '../utils.js'\nimport { map } from './map.js'\nimport { reduce } from './reduce.js'\nimport type { IStreamBuilder, KeyValue } from '../types.js'\n\ntype GroupKey = Record<string, unknown>\n\ntype BasicAggregateFunction<T, R, V = unknown> = {\n preMap: (data: T) => V\n reduce: (values: Array<[V, number]>) => V\n postMap?: (result: V) => R\n}\n\ntype PipedAggregateFunction<T, R> = {\n pipe: (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<string, R>>\n}\n\ntype AggregateFunction<T, R, V = unknown> =\n BasicAggregateFunction<T, R, V> | PipedAggregateFunction<T, R>\n\ntype ExtractAggregateReturnType<T, A> =\n A extends AggregateFunction<T, infer R, any> ? R : never\n\ntype AggregatesReturnType<T, A> = {\n [K in keyof A]: ExtractAggregateReturnType<T, A[K]>\n}\n\nfunction isPipedAggregateFunction<T, R>(\n aggregate: AggregateFunction<T, R>,\n): aggregate is PipedAggregateFunction<T, R> {\n return `pipe` in aggregate\n}\n\n/**\n * Groups data by key and applies multiple aggregate operations\n * @param keyExtractor Function to extract grouping key from data\n * @param aggregates Object mapping aggregate names to aggregate functions\n */\nexport function groupBy<\n T,\n K extends GroupKey,\n A extends Record<string, AggregateFunction<T, any, any>>,\n>(keyExtractor: (data: T) => K, aggregates: A = {} as A) {\n type ResultType = K & AggregatesReturnType<T, A>\n\n const basicAggregates = Object.fromEntries(\n Object.entries(aggregates).filter(\n ([_, aggregate]) => !isPipedAggregateFunction(aggregate),\n ),\n ) as Record<string, BasicAggregateFunction<T, any, any>>\n\n // @ts-expect-error - TODO: we don't use this yet, but we will\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const pipedAggregates = Object.fromEntries(\n Object.entries(aggregates).filter(([_, aggregate]) =>\n isPipedAggregateFunction(aggregate),\n ),\n ) as Record<string, PipedAggregateFunction<T, any>>\n\n return (\n stream: IStreamBuilder<T>,\n ): IStreamBuilder<KeyValue<string, ResultType>> => {\n // Special key to store the original key object\n const KEY_SENTINEL = Symbol(`original_group_key`)\n\n // First map to extract keys and pre-aggregate values\n const withKeysAndValues = stream.pipe(\n map((data) => {\n const key = keyExtractor(data)\n const keyString = serializeValue(key)\n\n // Create values object with pre-aggregated values\n const values: Record<string | symbol, unknown> = {}\n\n // Store the original key object\n values[KEY_SENTINEL] = key\n\n // Add pre-aggregated values\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n values[name] = aggregate.preMap(data)\n }\n\n return [keyString, values] as KeyValue<\n string,\n Record<string | symbol, unknown>\n >\n }),\n )\n\n // Then reduce to compute aggregates\n const reduced = withKeysAndValues.pipe(\n reduce((values) => {\n // Calculate total multiplicity to check if the group should exist\n let totalMultiplicity = 0\n for (const [_, multiplicity] of values) {\n totalMultiplicity += multiplicity\n }\n\n // If total multiplicity is 0 or negative, the group should be removed completely\n if (totalMultiplicity <= 0) {\n return []\n }\n\n const result: Record<PropertyKey, unknown> = {}\n\n // Get the original key from first value in group\n const originalKey = values[0]?.[0]?.[KEY_SENTINEL]\n result[KEY_SENTINEL] = originalKey\n\n // Apply each aggregate function\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n const preValues = values.map(\n ([v, m]) => [v[name], m] as [any, number],\n )\n result[name] = aggregate.reduce(preValues)\n }\n\n return [[result, 1]]\n }),\n )\n\n // Finally map to extract the key and include all values\n return reduced.pipe(\n map(([keyString, values]) => {\n // Extract the original key\n const key = values[KEY_SENTINEL] as K\n\n // Create intermediate result with key values and aggregate results\n const result: Record<string, unknown> = {}\n\n // Add key properties to result\n Object.assign(result, key)\n\n // Apply postMap if provided\n for (const [name, aggregate] of Object.entries(basicAggregates)) {\n if (aggregate.postMap) {\n result[name] = aggregate.postMap(values[name])\n } else {\n result[name] = values[name]\n }\n }\n\n // Return with the string key instead of the object\n return [keyString, result] as KeyValue<string, ResultType>\n }),\n )\n }\n}\n\n/**\n * Creates a sum aggregate function\n */\nexport function sum<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, number> {\n return {\n preMap: (data: T) => valueExtractor(data),\n reduce: (values: Array<[number, number]>) => {\n let total = 0\n for (const [value, multiplicity] of values) {\n total += value * multiplicity\n }\n return total\n },\n }\n}\n\n/**\n * Creates a count aggregate function\n */\nexport function count<T>(\n valueExtractor: (value: T) => any = (v) => v,\n): AggregateFunction<T, number, number> {\n return {\n // Count only not-null values (the `== null` comparison gives true for both null and undefined)\n preMap: (data: T) => (valueExtractor(data) == null ? 0 : 1),\n reduce: (values: Array<[number, number]>) => {\n let totalCount = 0\n for (const [nullMultiplier, multiplicity] of values) {\n totalCount += nullMultiplier * multiplicity\n }\n return totalCount\n },\n }\n}\n\n/**\n * Creates an average aggregate function\n */\nexport function avg<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, { sum: number; count: number }> {\n return {\n preMap: (data: T) => ({\n sum: valueExtractor(data),\n count: 0,\n }),\n reduce: (values: Array<[{ sum: number; count: number }, number]>) => {\n let totalSum = 0\n let totalCount = 0\n for (const [value, multiplicity] of values) {\n totalSum += value.sum * multiplicity\n totalCount += multiplicity\n }\n return {\n sum: totalSum,\n count: totalCount,\n }\n },\n postMap: (result: { sum: number; count: number }) => {\n return result.sum / result.count\n },\n }\n}\n\ntype CanMinMax = number | Date | bigint | string\n\n/**\n * Creates a min aggregate function that computes the minimum value in a group\n * @param valueExtractor Function to extract a comparable value from each data entry\n */\nexport function min<T extends CanMinMax>(): AggregateFunction<\n T,\n T | undefined,\n T | undefined\n>\nexport function min<T, V extends CanMinMax>(\n valueExtractor: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined>\nexport function min<T, V extends CanMinMax>(\n valueExtractor?: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined> {\n const extractor = valueExtractor ?? ((v: T) => v as unknown as V)\n return {\n preMap: (data: T) => extractor(data),\n reduce: (values) => {\n let minValue: V | undefined\n for (const [value, _multiplicity] of values) {\n if (\n value !== undefined &&\n (minValue === undefined || value < minValue)\n ) {\n minValue = value\n }\n }\n return minValue\n },\n }\n}\n\n/**\n * Creates a max aggregate function that computes the maximum value in a group\n * @param valueExtractor Function to extract a comparable value from each data entry\n */\nexport function max<T extends CanMinMax>(): AggregateFunction<\n T,\n T | undefined,\n T | undefined\n>\nexport function max<T, V extends CanMinMax>(\n valueExtractor: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined>\nexport function max<T, V extends CanMinMax>(\n valueExtractor?: (value: T) => V,\n): AggregateFunction<T, V | undefined, V | undefined> {\n const extractor = valueExtractor ?? ((v: T) => v as unknown as V)\n return {\n preMap: (data: T) => extractor(data),\n reduce: (values) => {\n let maxValue: V | undefined\n for (const [value, _multiplicity] of values) {\n if (\n value !== undefined &&\n (maxValue === undefined || value > maxValue)\n ) {\n maxValue = value\n }\n }\n return maxValue\n },\n }\n}\n\n/**\n * Creates a median aggregate function that computes the middle value in a sorted group\n * If there's an even number of values, returns the average of the two middle values\n * @param valueExtractor Function to extract a numeric value from each data entry\n */\nexport function median<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, Array<number>> {\n return {\n preMap: (data: T) => [valueExtractor(data)],\n reduce: (values: Array<[Array<number>, number]>) => {\n // Flatten all values, taking multiplicity into account\n const allValues: Array<number> = []\n for (const [valueArray, multiplicity] of values) {\n for (const value of valueArray) {\n // Add each value multiple times based on multiplicity\n for (let i = 0; i < multiplicity; i++) {\n allValues.push(value)\n }\n }\n }\n\n // Return empty array if no values\n if (allValues.length === 0) {\n return []\n }\n\n // Sort values\n allValues.sort((a, b) => a - b)\n\n return allValues\n },\n postMap: (result: Array<number>) => {\n if (result.length === 0) return 0\n\n const mid = Math.floor(result.length / 2)\n\n // If even number of values, average the two middle values\n if (result.length % 2 === 0) {\n return (result[mid - 1]! + result[mid]!) / 2\n }\n\n // If odd number of values, return the middle value\n return result[mid]!\n },\n }\n}\n\n/**\n * Creates a mode aggregate function that computes the most frequent value in a group\n * If multiple values have the same highest frequency, returns the first one encountered\n * @param valueExtractor Function to extract a value from each data entry\n */\nexport function mode<T>(\n valueExtractor: (value: T) => number = (v) => v as unknown as number,\n): AggregateFunction<T, number, Map<number, number>> {\n return {\n preMap: (data: T) => {\n const value = valueExtractor(data)\n const frequencyMap = new Map<number, number>()\n frequencyMap.set(value, 1)\n return frequencyMap\n },\n reduce: (values: Array<[Map<number, number>, number]>) => {\n // Combine all frequency maps\n const combinedMap = new Map<number, number>()\n\n for (const [frequencyMap, multiplicity] of values) {\n for (const [value, frequencyCount] of frequencyMap.entries()) {\n const currentCount = combinedMap.get(value) || 0\n combinedMap.set(value, currentCount + frequencyCount * multiplicity)\n }\n }\n\n return combinedMap\n },\n postMap: (result: Map<number, number>) => {\n if (result.size === 0) return 0\n\n let modeValue = 0\n let maxFrequency = 0\n\n for (const [value, frequency] of result.entries()) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency\n modeValue = value\n }\n }\n\n return modeValue\n },\n }\n}\n\nexport const groupByOperators = {\n sum,\n count,\n avg,\n min,\n max,\n median,\n mode,\n}\n"],"names":["map","serializeValue","reduce"],"mappings":";;;;;AA2BA,SAAS,yBACP,WAC2C;AAC3C,SAAO,UAAU;AACnB;AAOO,SAAS,QAId,cAA8B,aAAgB,IAAS;AAGvD,QAAM,kBAAkB,OAAO;AAAA,IAC7B,OAAO,QAAQ,UAAU,EAAE;AA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AAEJ;AAEO,MAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;;;;;;;;"}
@@ -1,8 +1,11 @@
1
- import { IStreamBuilder, KeyValue } from '../types.js';
1
+ import { IStreamBuilder, KeyValue } from "../types.cjs";
2
2
  type GroupKey = Record<string, unknown>;
3
3
  type BasicAggregateFunction<T, R, V = unknown> = {
4
4
  preMap: (data: T) => V;
5
- reduce: (values: Array<[V, number]>) => V;
5
+ reduce: (values: Array<[
6
+ V,
7
+ number
8
+ ]>) => V;
6
9
  postMap?: (result: V) => R;
7
10
  };
8
11
  type PipedAggregateFunction<T, R> = {
@@ -1,4 +1,4 @@
1
- import { IStreamBuilder, KeyValue } from '../types.js';
1
+ import { IStreamBuilder, KeyValue } from "../types.cjs";
2
2
  export interface GroupedOrderByOptions<Ve> {
3
3
  comparator?: (a: Ve, b: Ve) => number;
4
4
  limit?: number;
@@ -28,4 +28,10 @@ export interface GroupedOrderByWithFractionalIndexOptions<Ve, KeyType = unknown,
28
28
  * @param options - Configuration including groupKeyFn, comparator, limit, and offset
29
29
  * @returns A piped operator that orders the elements per group and limits the number of results per group
30
30
  */
31
- export declare function groupedOrderByWithFractionalIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options: GroupedOrderByWithFractionalIndexOptions<Ve, T extends KeyValue<infer K, unknown> ? K : never, T extends KeyValue<unknown, infer V> ? V : never>): (stream: IStreamBuilder<T>) => IStreamBuilder<[T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]]>;
31
+ export declare function groupedOrderByWithFractionalIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options: GroupedOrderByWithFractionalIndexOptions<Ve, T extends KeyValue<infer K, unknown> ? K : never, T extends KeyValue<unknown, infer V> ? V : never>): (stream: IStreamBuilder<T>) => IStreamBuilder<[
32
+ T extends KeyValue<infer K, unknown> ? K : never,
33
+ [
34
+ T extends KeyValue<unknown, infer V> ? V : never,
35
+ string
36
+ ]
37
+ ]>;
@@ -1,6 +1,6 @@
1
- import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
2
- import { IndexedValue, TopK } from './topKArray.js';
3
- import { PipedOperator } from '../types.js';
1
+ import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from "../graph.cjs";
2
+ import { IndexedValue, TopK } from "./topKArray.cjs";
3
+ import { PipedOperator } from "../types.cjs";
4
4
  export interface GroupedTopKWithFractionalIndexOptions<K, T> {
5
5
  limit?: number;
6
6
  offset?: number;
@@ -24,14 +24,35 @@ export interface GroupedTopKWithFractionalIndexOptions<K, T> {
24
24
  * Elements are grouped by the groupKeyFn, and each group maintains
25
25
  * its own sorted collection with independent limit/offset.
26
26
  */
27
- export declare class GroupedTopKWithFractionalIndexOperator<K extends string | number, T> extends UnaryOperator<[K, T], [K, IndexedValue<T>]> {
27
+ export declare class GroupedTopKWithFractionalIndexOperator<K extends string | number, T> extends UnaryOperator<[
28
+ K,
29
+ T
30
+ ], [
31
+ K,
32
+ IndexedValue<T>
33
+ ]> {
28
34
  #private;
29
- constructor(id: number, inputA: DifferenceStreamReader<[K, T]>, output: DifferenceStreamWriter<[K, IndexedValue<T>]>, comparator: (a: T, b: T) => number, options: GroupedTopKWithFractionalIndexOptions<K, T>);
35
+ constructor(id: number, inputA: DifferenceStreamReader<[
36
+ K,
37
+ T
38
+ ]>, output: DifferenceStreamWriter<[
39
+ K,
40
+ IndexedValue<T>
41
+ ]>, comparator: (a: T, b: T) => number, options: GroupedTopKWithFractionalIndexOptions<K, T>);
30
42
  /**
31
43
  * Creates a new TopK data structure for a group.
32
44
  * Can be overridden in subclasses to use different implementations (e.g., B+ tree).
33
45
  */
34
- protected createTopK(offset: number, limit: number, comparator: (a: [K, T], b: [K, T]) => number): TopK<[K, T]>;
46
+ protected createTopK(offset: number, limit: number, comparator: (a: [
47
+ K,
48
+ T
49
+ ], b: [
50
+ K,
51
+ T
52
+ ]) => number): TopK<[
53
+ K,
54
+ T
55
+ ]>;
35
56
  run(): void;
36
57
  }
37
58
  /**
@@ -47,4 +68,10 @@ export declare class GroupedTopKWithFractionalIndexOperator<K extends string | n
47
68
  * @param options - Configuration including groupKeyFn, limit, and offset
48
69
  * @returns A piped operator that orders elements per group and limits results per group
49
70
  */
50
- export declare function groupedTopKWithFractionalIndex<K extends string | number, T>(comparator: (a: T, b: T) => number, options: GroupedTopKWithFractionalIndexOptions<K, T>): PipedOperator<[K, T], [K, IndexedValue<T>]>;
71
+ export declare function groupedTopKWithFractionalIndex<K extends string | number, T>(comparator: (a: T, b: T) => number, options: GroupedTopKWithFractionalIndexOptions<K, T>): PipedOperator<[
72
+ K,
73
+ T
74
+ ], [
75
+ K,
76
+ IndexedValue<T>
77
+ ]>;
@@ -1,21 +1,21 @@
1
- export * from './pipe.js';
2
- export * from './map.js';
3
- export * from './tap.js';
4
- export * from './filter.js';
5
- export * from './negate.js';
6
- export * from './concat.js';
7
- export * from './debug.js';
8
- export * from './output.js';
9
- export * from './consolidate.js';
10
- export * from './join.js';
11
- export * from './reduce.js';
12
- export * from './count.js';
13
- export * from './distinct.js';
14
- export * from './keying.js';
15
- export * from './topK.js';
16
- export * from './topKWithFractionalIndex.js';
17
- export * from './groupedTopKWithFractionalIndex.js';
18
- export * from './orderBy.js';
19
- export * from './groupedOrderBy.js';
20
- export * from './filterBy.js';
21
- export { groupBy, groupByOperators } from './groupBy.js';
1
+ export * from "./pipe.cjs";
2
+ export * from "./map.cjs";
3
+ export * from "./tap.cjs";
4
+ export * from "./filter.cjs";
5
+ export * from "./negate.cjs";
6
+ export * from "./concat.cjs";
7
+ export * from "./debug.cjs";
8
+ export * from "./output.cjs";
9
+ export * from "./consolidate.cjs";
10
+ export * from "./join.cjs";
11
+ export * from "./reduce.cjs";
12
+ export * from "./count.cjs";
13
+ export * from "./distinct.cjs";
14
+ export * from "./keying.cjs";
15
+ export * from "./topK.cjs";
16
+ export * from "./topKWithFractionalIndex.cjs";
17
+ export * from "./groupedTopKWithFractionalIndex.cjs";
18
+ export * from "./orderBy.cjs";
19
+ export * from "./groupedOrderBy.cjs";
20
+ export * from "./filterBy.cjs";
21
+ export { groupBy, groupByOperators } from "./groupBy.cjs";