@enspirit/bmg-js 1.0.1 → 1.1.0
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.md +21 -0
- package/README.md +3 -2
- package/dist/AsyncRelation/Base.d.ts +47 -0
- package/dist/AsyncRelation/index.d.ts +25 -0
- package/dist/{src/Relation → Relation}/Memory.d.ts +46 -46
- package/dist/Relation/index.d.ts +1 -0
- package/dist/async/Relation/Base.d.ts +47 -0
- package/dist/async/Relation/index.d.ts +25 -0
- package/dist/async/operators/_helpers.d.ts +16 -0
- package/dist/async/operators/autowrap.d.ts +7 -0
- package/dist/async/operators/constants.d.ts +6 -0
- package/dist/async/operators/cross_product.d.ts +9 -0
- package/dist/async/operators/extend.d.ts +7 -0
- package/dist/async/operators/group.d.ts +7 -0
- package/dist/async/operators/image.d.ts +8 -0
- package/dist/async/operators/index.d.ts +28 -0
- package/dist/async/operators/intersect.d.ts +7 -0
- package/dist/async/operators/isEqual.d.ts +7 -0
- package/dist/async/operators/join.d.ts +7 -0
- package/dist/async/operators/left_join.d.ts +8 -0
- package/dist/async/operators/matching.d.ts +7 -0
- package/dist/async/operators/minus.d.ts +7 -0
- package/dist/async/operators/not_matching.d.ts +7 -0
- package/dist/async/operators/one.d.ts +6 -0
- package/dist/async/operators/prefix.d.ts +6 -0
- package/dist/async/operators/project.d.ts +10 -0
- package/dist/async/operators/rename.d.ts +6 -0
- package/dist/async/operators/restrict.d.ts +14 -0
- package/dist/async/operators/suffix.d.ts +6 -0
- package/dist/async/operators/summarize.d.ts +8 -0
- package/dist/async/operators/toArray.d.ts +5 -0
- package/dist/async/operators/transform.d.ts +9 -0
- package/dist/async/operators/ungroup.d.ts +7 -0
- package/dist/async/operators/union.d.ts +6 -0
- package/dist/async/operators/unwrap.d.ts +6 -0
- package/dist/async/operators/wrap.d.ts +6 -0
- package/dist/async/operators/yByX.d.ts +7 -0
- package/dist/async/types.d.ts +58 -0
- package/dist/async-operators/_helpers.d.ts +16 -0
- package/dist/async-operators/autowrap.d.ts +7 -0
- package/dist/async-operators/constants.d.ts +6 -0
- package/dist/async-operators/cross_product.d.ts +9 -0
- package/dist/async-operators/extend.d.ts +7 -0
- package/dist/async-operators/group.d.ts +7 -0
- package/dist/async-operators/image.d.ts +8 -0
- package/dist/async-operators/index.d.ts +28 -0
- package/dist/async-operators/intersect.d.ts +7 -0
- package/dist/async-operators/isEqual.d.ts +7 -0
- package/dist/async-operators/join.d.ts +7 -0
- package/dist/async-operators/left_join.d.ts +8 -0
- package/dist/async-operators/matching.d.ts +7 -0
- package/dist/async-operators/minus.d.ts +7 -0
- package/dist/async-operators/not_matching.d.ts +7 -0
- package/dist/async-operators/one.d.ts +6 -0
- package/dist/async-operators/prefix.d.ts +6 -0
- package/dist/async-operators/project.d.ts +10 -0
- package/dist/async-operators/rename.d.ts +6 -0
- package/dist/async-operators/restrict.d.ts +14 -0
- package/dist/async-operators/suffix.d.ts +6 -0
- package/dist/async-operators/summarize.d.ts +8 -0
- package/dist/async-operators/toArray.d.ts +5 -0
- package/dist/async-operators/transform.d.ts +9 -0
- package/dist/async-operators/ungroup.d.ts +7 -0
- package/dist/async-operators/union.d.ts +6 -0
- package/dist/async-operators/unwrap.d.ts +6 -0
- package/dist/async-operators/wrap.d.ts +6 -0
- package/dist/async-operators/yByX.d.ts +7 -0
- package/dist/async-types.d.ts +58 -0
- package/dist/async.d.ts +4 -0
- package/dist/bmg.cjs +1 -1
- package/dist/bmg.cjs.map +1 -1
- package/dist/bmg.modern.js +1 -1
- package/dist/bmg.modern.js.map +1 -1
- package/dist/bmg.module.js +1 -1
- package/dist/bmg.module.js.map +1 -1
- package/dist/bmg.umd.js +1 -1
- package/dist/bmg.umd.js.map +1 -1
- package/dist/index.d.ts +38 -1
- package/dist/lib-definitions.d.ts +1 -0
- package/dist/{src/operators → operators}/_helpers.d.ts +142 -142
- package/dist/{src/operators → operators}/allbut.d.ts +2 -2
- package/dist/{src/operators → operators}/autowrap.d.ts +2 -2
- package/dist/{src/operators → operators}/constants.d.ts +2 -2
- package/dist/{src/operators → operators}/cross_product.d.ts +3 -3
- package/dist/{src/operators → operators}/exclude.d.ts +2 -2
- package/dist/{src/operators → operators}/extend.d.ts +2 -2
- package/dist/{src/src/operators → operators}/group.d.ts +2 -2
- package/dist/{src/operators → operators}/image.d.ts +2 -2
- package/dist/operators/index.d.ts +1 -0
- package/dist/{src/src/operators → operators}/intersect.d.ts +2 -2
- package/dist/operators/isEqual.d.ts +1 -0
- package/dist/operators/isRelation.d.ts +2 -0
- package/dist/{src/operators → operators}/join.d.ts +2 -2
- package/dist/{src/operators → operators}/left_join.d.ts +2 -2
- package/dist/{src/src/operators → operators}/matching.d.ts +2 -2
- package/dist/{src/src/operators → operators}/minus.d.ts +2 -2
- package/dist/{src/src/operators → operators}/not_matching.d.ts +2 -2
- package/dist/{src/operators → operators}/one.d.ts +2 -2
- package/dist/{src/operators → operators}/prefix.d.ts +2 -2
- package/dist/{src/src/operators → operators}/project.d.ts +2 -2
- package/dist/{src/operators → operators}/rename.d.ts +2 -2
- package/dist/{src/operators → operators}/restrict.d.ts +2 -2
- package/dist/{src/operators → operators}/suffix.d.ts +2 -2
- package/dist/{src/operators → operators}/summarize.d.ts +2 -2
- package/dist/{src/operators → operators}/transform.d.ts +2 -2
- package/dist/{src/src/operators → operators}/ungroup.d.ts +2 -2
- package/dist/{src/operators → operators}/union.d.ts +2 -2
- package/dist/{src/operators → operators}/unwrap.d.ts +2 -2
- package/dist/{src/operators → operators}/wrap.d.ts +2 -2
- package/dist/{src/operators → operators}/yByX.d.ts +2 -2
- package/dist/{src/src/support → support}/toPredicateFunc.d.ts +2 -2
- package/dist/{src/src → sync}/Relation/Memory.d.ts +46 -46
- package/dist/{src/src → sync}/Relation/index.d.ts +1 -1
- package/dist/{src/src → sync}/operators/_helpers.d.ts +142 -142
- package/dist/{src/src → sync}/operators/allbut.d.ts +2 -2
- package/dist/{src/src → sync}/operators/autowrap.d.ts +2 -2
- package/dist/{src/src → sync}/operators/constants.d.ts +2 -2
- package/dist/{src/src → sync}/operators/cross_product.d.ts +3 -3
- package/dist/{src/src → sync}/operators/exclude.d.ts +2 -2
- package/dist/{src/src → sync}/operators/extend.d.ts +2 -2
- package/dist/{src → sync}/operators/group.d.ts +2 -2
- package/dist/{src/src → sync}/operators/image.d.ts +2 -2
- package/dist/{src → sync}/operators/index.d.ts +30 -30
- package/dist/{src → sync}/operators/intersect.d.ts +2 -2
- package/dist/sync/operators/isEqual.d.ts +1 -0
- package/dist/sync/operators/isRelation.d.ts +2 -0
- package/dist/{src/src → sync}/operators/join.d.ts +2 -2
- package/dist/{src/src → sync}/operators/left_join.d.ts +2 -2
- package/dist/{src → sync}/operators/matching.d.ts +2 -2
- package/dist/{src → sync}/operators/minus.d.ts +2 -2
- package/dist/{src → sync}/operators/not_matching.d.ts +2 -2
- package/dist/{src/src → sync}/operators/one.d.ts +2 -2
- package/dist/{src/src → sync}/operators/prefix.d.ts +2 -2
- package/dist/{src → sync}/operators/project.d.ts +2 -2
- package/dist/{src/src → sync}/operators/rename.d.ts +2 -2
- package/dist/{src/src → sync}/operators/restrict.d.ts +2 -2
- package/dist/{src/src → sync}/operators/suffix.d.ts +2 -2
- package/dist/{src/src → sync}/operators/summarize.d.ts +2 -2
- package/dist/{src/src → sync}/operators/transform.d.ts +2 -2
- package/dist/{src → sync}/operators/ungroup.d.ts +2 -2
- package/dist/{src/src → sync}/operators/union.d.ts +2 -2
- package/dist/{src/src → sync}/operators/unwrap.d.ts +2 -2
- package/dist/{src → sync}/operators/where.d.ts +1 -1
- package/dist/{src/src → sync}/operators/wrap.d.ts +2 -2
- package/dist/{src/src → sync}/operators/yByX.d.ts +2 -2
- package/dist/{src/src/types.d.ts → types.d.ts} +169 -101
- package/dist/writer/Text.d.ts +40 -0
- package/dist/writer/index.d.ts +1 -0
- package/package.json +6 -4
- package/src/Relation/index.ts +2 -1
- package/src/async/Relation/Base.ts +245 -0
- package/src/async/Relation/index.ts +31 -0
- package/src/async/operators/_helpers.ts +60 -0
- package/src/async/operators/autowrap.ts +31 -0
- package/src/async/operators/constants.ts +26 -0
- package/src/async/operators/cross_product.ts +39 -0
- package/src/async/operators/extend.ts +36 -0
- package/src/async/operators/group.ts +61 -0
- package/src/async/operators/image.ts +42 -0
- package/src/async/operators/index.ts +28 -0
- package/src/async/operators/intersect.ts +28 -0
- package/src/async/operators/isEqual.ts +39 -0
- package/src/async/operators/join.ts +39 -0
- package/src/async/operators/left_join.ts +55 -0
- package/src/async/operators/matching.ts +39 -0
- package/src/async/operators/minus.ts +28 -0
- package/src/async/operators/not_matching.ts +39 -0
- package/src/async/operators/one.ts +25 -0
- package/src/async/operators/prefix.ts +15 -0
- package/src/async/operators/project.ts +64 -0
- package/src/async/operators/rename.ts +33 -0
- package/src/async/operators/restrict.ts +61 -0
- package/src/async/operators/suffix.ts +15 -0
- package/src/async/operators/summarize.ts +90 -0
- package/src/async/operators/toArray.ts +18 -0
- package/src/async/operators/transform.ts +43 -0
- package/src/async/operators/ungroup.ts +43 -0
- package/src/async/operators/union.ts +29 -0
- package/src/async/operators/unwrap.ts +31 -0
- package/src/async/operators/wrap.ts +32 -0
- package/src/async/operators/yByX.ts +19 -0
- package/src/async/types.ts +86 -0
- package/src/async.ts +4 -0
- package/src/index.ts +17 -4
- package/src/lib-definitions.ts +292 -0
- package/src/operators/index.ts +2 -31
- package/src/{Relation → sync/Relation}/Memory.ts +22 -13
- package/{dist/src/Relation/index.d.ts → src/sync/Relation/index.ts} +1 -1
- package/src/{operators → sync/operators}/_helpers.ts +1 -1
- package/src/{operators → sync/operators}/allbut.ts +1 -1
- package/src/{operators → sync/operators}/autowrap.ts +1 -1
- package/src/{operators → sync/operators}/constants.ts +1 -1
- package/src/{operators → sync/operators}/cross_product.ts +1 -1
- package/src/{operators → sync/operators}/exclude.ts +2 -2
- package/src/{operators → sync/operators}/extend.ts +1 -1
- package/src/{operators → sync/operators}/group.ts +2 -2
- package/src/{operators → sync/operators}/image.ts +2 -2
- package/src/sync/operators/index.ts +31 -0
- package/src/{operators → sync/operators}/intersect.ts +1 -1
- package/src/{operators → sync/operators}/isEqual.ts +1 -2
- package/src/sync/operators/isRelation.ts +6 -0
- package/src/{operators → sync/operators}/join.ts +1 -1
- package/src/{operators → sync/operators}/left_join.ts +1 -1
- package/src/{operators → sync/operators}/matching.ts +1 -1
- package/src/{operators → sync/operators}/minus.ts +1 -1
- package/src/{operators → sync/operators}/not_matching.ts +1 -1
- package/src/{operators → sync/operators}/one.ts +1 -1
- package/src/{operators → sync/operators}/prefix.ts +1 -1
- package/src/{operators → sync/operators}/project.ts +1 -1
- package/src/{operators → sync/operators}/rename.ts +1 -1
- package/src/{operators → sync/operators}/restrict.ts +2 -2
- package/src/{operators → sync/operators}/suffix.ts +1 -1
- package/src/{operators → sync/operators}/summarize.ts +1 -1
- package/src/{operators → sync/operators}/transform.ts +1 -1
- package/src/{operators → sync/operators}/ungroup.ts +1 -1
- package/src/{operators → sync/operators}/union.ts +1 -1
- package/src/{operators → sync/operators}/unwrap.ts +1 -1
- package/{dist/src/src/operators/where.d.ts → src/sync/operators/where.ts} +1 -1
- package/src/{operators → sync/operators}/wrap.ts +1 -1
- package/src/{operators → sync/operators}/yByX.ts +1 -1
- package/src/types.ts +153 -54
- package/src/writer/Text.ts +305 -0
- package/src/writer/index.ts +1 -0
- package/dist/src/Relation.d.ts +0 -8
- package/dist/src/index.d.ts +0 -27
- package/dist/src/operators/isEqual.d.ts +0 -2
- package/dist/src/operators/isRelation.d.ts +0 -1
- package/dist/src/src/index.d.ts +0 -27
- package/dist/src/src/operators/index.d.ts +0 -30
- package/dist/src/src/operators/isEqual.d.ts +0 -2
- package/dist/src/src/operators/isRelation.d.ts +0 -1
- package/dist/src/src/utility-types.d.ts +0 -43
- package/dist/src/support/toPredicateFunc.d.ts +0 -2
- package/dist/src/tests/bmg.test.d.ts +0 -1
- package/dist/src/tests/fixtures.d.ts +0 -6
- package/dist/src/tests/operators/allbut.test.d.ts +0 -1
- package/dist/src/tests/operators/autowrap.test.d.ts +0 -1
- package/dist/src/tests/operators/constants.test.d.ts +0 -1
- package/dist/src/tests/operators/cross_product.test.d.ts +0 -1
- package/dist/src/tests/operators/exclude.test.d.ts +0 -1
- package/dist/src/tests/operators/extend.test.d.ts +0 -1
- package/dist/src/tests/operators/group.test.d.ts +0 -1
- package/dist/src/tests/operators/image.test.d.ts +0 -1
- package/dist/src/tests/operators/intersect.test.d.ts +0 -1
- package/dist/src/tests/operators/isEqual.test.d.ts +0 -1
- package/dist/src/tests/operators/join.test.d.ts +0 -1
- package/dist/src/tests/operators/left_join.test.d.ts +0 -1
- package/dist/src/tests/operators/matching.test.d.ts +0 -1
- package/dist/src/tests/operators/minus.test.d.ts +0 -1
- package/dist/src/tests/operators/not_matching.test.d.ts +0 -1
- package/dist/src/tests/operators/one.test.d.ts +0 -1
- package/dist/src/tests/operators/prefix.test.d.ts +0 -1
- package/dist/src/tests/operators/project.test.d.ts +0 -1
- package/dist/src/tests/operators/rename.test.d.ts +0 -1
- package/dist/src/tests/operators/restrict.test.d.ts +0 -1
- package/dist/src/tests/operators/suffix.test.d.ts +0 -1
- package/dist/src/tests/operators/summarize.test.d.ts +0 -1
- package/dist/src/tests/operators/transform.test.d.ts +0 -1
- package/dist/src/tests/operators/ungroup.test.d.ts +0 -1
- package/dist/src/tests/operators/union.test.d.ts +0 -1
- package/dist/src/tests/operators/unwrap.test.d.ts +0 -1
- package/dist/src/tests/operators/where.test.d.ts +0 -1
- package/dist/src/tests/operators/wrap.test.d.ts +0 -1
- package/dist/src/tests/operators/yByX.test.d.ts +0 -1
- package/dist/src/tests/types/relation.test.d.ts +0 -1
- package/dist/src/types.d.ts +0 -101
- package/dist/src/utility-types.d.ts +0 -43
- package/dist/tests/bmg.test.d.ts +0 -1
- package/dist/tests/fixtures.d.ts +0 -6
- package/dist/tests/operators/allbut.test.d.ts +0 -1
- package/dist/tests/operators/autowrap.test.d.ts +0 -1
- package/dist/tests/operators/constants.test.d.ts +0 -1
- package/dist/tests/operators/cross_product.test.d.ts +0 -1
- package/dist/tests/operators/exclude.test.d.ts +0 -1
- package/dist/tests/operators/extend.test.d.ts +0 -1
- package/dist/tests/operators/group.test.d.ts +0 -1
- package/dist/tests/operators/image.test.d.ts +0 -1
- package/dist/tests/operators/intersect.test.d.ts +0 -1
- package/dist/tests/operators/isEqual.test.d.ts +0 -1
- package/dist/tests/operators/join.test.d.ts +0 -1
- package/dist/tests/operators/left_join.test.d.ts +0 -1
- package/dist/tests/operators/matching.test.d.ts +0 -1
- package/dist/tests/operators/minus.test.d.ts +0 -1
- package/dist/tests/operators/not_matching.test.d.ts +0 -1
- package/dist/tests/operators/one.test.d.ts +0 -1
- package/dist/tests/operators/prefix.test.d.ts +0 -1
- package/dist/tests/operators/project.test.d.ts +0 -1
- package/dist/tests/operators/rename.test.d.ts +0 -1
- package/dist/tests/operators/restrict.test.d.ts +0 -1
- package/dist/tests/operators/suffix.test.d.ts +0 -1
- package/dist/tests/operators/summarize.test.d.ts +0 -1
- package/dist/tests/operators/transform.test.d.ts +0 -1
- package/dist/tests/operators/ungroup.test.d.ts +0 -1
- package/dist/tests/operators/union.test.d.ts +0 -1
- package/dist/tests/operators/unwrap.test.d.ts +0 -1
- package/dist/tests/operators/where.test.d.ts +0 -1
- package/dist/tests/operators/wrap.test.d.ts +0 -1
- package/dist/tests/operators/yByX.test.d.ts +0 -1
- package/dist/tests/types/relation.test.d.ts +0 -1
- package/src/operators/isRelation.ts +0 -5
- package/src/utility-types.ts +0 -77
- /package/{src/operators/where.ts → dist/operators/where.d.ts} +0 -0
|
@@ -1,101 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export type
|
|
84
|
-
|
|
85
|
-
export type
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export type ExtensionFunc = (tuple: Tuple) => unknown;
|
|
89
|
-
export type Extension = Record<AttrName, ExtensionFunc | AttrName>;
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
export
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Bmg.js relational algebra library.
|
|
3
|
+
*
|
|
4
|
+
* This file defines all types needed for type-safe relational operations:
|
|
5
|
+
* - Base types (AttrName, Tuple)
|
|
6
|
+
* - Utility types for transformations (Renamed, Prefixed, Joined, etc.)
|
|
7
|
+
* - The Relation interface with all operators
|
|
8
|
+
* - Helper types for predicates, extensions, aggregators, etc.
|
|
9
|
+
*/
|
|
10
|
+
/** Attribute name in a tuple */
|
|
11
|
+
export type AttrName = string;
|
|
12
|
+
/** A tuple is a record mapping attribute names to values */
|
|
13
|
+
export type Tuple = Record<AttrName, unknown>;
|
|
14
|
+
/** Map from old attribute names to new attribute names */
|
|
15
|
+
export type RenameMap<T> = {
|
|
16
|
+
[K in keyof T]?: string;
|
|
17
|
+
};
|
|
18
|
+
/** Transform tuple type by renaming keys according to RenameMap */
|
|
19
|
+
export type Renamed<T, R extends RenameMap<T>> = {
|
|
20
|
+
[K in keyof T as K extends keyof R ? (R[K] extends string ? R[K] : K) : K]: T[K];
|
|
21
|
+
};
|
|
22
|
+
/** Prefix all keys except those in Except */
|
|
23
|
+
export type Prefixed<T, P extends string, Except extends keyof T = never> = {
|
|
24
|
+
[K in keyof T as K extends Except ? K : `${P}${K & string}`]: T[K];
|
|
25
|
+
};
|
|
26
|
+
/** Suffix all keys except those in Except */
|
|
27
|
+
export type Suffixed<T, S extends string, Except extends keyof T = never> = {
|
|
28
|
+
[K in keyof T as K extends Except ? K : `${K & string}${S}`]: T[K];
|
|
29
|
+
};
|
|
30
|
+
/** Extract common keys between two tuple types */
|
|
31
|
+
export type CommonKeys<L, R> = Extract<keyof L, keyof R>;
|
|
32
|
+
/** Result of inner join: L & R with R's common keys removed */
|
|
33
|
+
export type Joined<L, R> = L & Omit<R, CommonKeys<L, R>>;
|
|
34
|
+
/** Result of left join: L & optional R attributes (common keys removed) */
|
|
35
|
+
export type LeftJoined<L, R> = L & Partial<Omit<R, CommonKeys<L, R>>>;
|
|
36
|
+
/**
|
|
37
|
+
* Typed join keys for array form: keys must exist on BOTH operands.
|
|
38
|
+
* Example: suppliers.join(parts, ['city']) - 'city' must be a key of both.
|
|
39
|
+
*/
|
|
40
|
+
export type TypedJoinKeysArray<L, R> = (keyof L & keyof R & string)[];
|
|
41
|
+
/**
|
|
42
|
+
* Typed join keys for object form: maps left keys to right keys.
|
|
43
|
+
* Example: suppliers.join(parts, { sid: 'supplier_id' })
|
|
44
|
+
* - Left key (sid) must exist on L
|
|
45
|
+
* - Right key (supplier_id) must exist on R
|
|
46
|
+
*/
|
|
47
|
+
export type TypedJoinKeysObject<L, R> = {
|
|
48
|
+
[K in keyof L & string]?: keyof R & string;
|
|
49
|
+
};
|
|
50
|
+
/** Result of wrap: remove wrapped attrs, add nested object */
|
|
51
|
+
export type Wrapped<T, K extends keyof T, As extends string> = Omit<T, K> & Record<As, Pick<T, K>>;
|
|
52
|
+
/** Result of unwrap: remove object attr, spread its properties */
|
|
53
|
+
export type Unwrapped<T, K extends keyof T> = T[K] extends Record<string, unknown> ? Omit<T, K> & T[K] : Omit<T, K>;
|
|
54
|
+
/** Result of ungroup: remove relation attr, flatten its tuple type */
|
|
55
|
+
export type Ungrouped<T, K extends keyof T> = T[K] extends Relation<infer N> ? Omit<T, K> & N : Omit<T, K>;
|
|
56
|
+
export type AggregatorName = 'count' | 'sum' | 'min' | 'max' | 'avg' | 'collect';
|
|
57
|
+
export type AggregatorSpec = {
|
|
58
|
+
op: AggregatorName;
|
|
59
|
+
attr: AttrName;
|
|
60
|
+
};
|
|
61
|
+
export type AggregatorFunc = (tuples: Tuple[]) => unknown;
|
|
62
|
+
export type Aggregator = AggregatorName | AggregatorSpec | AggregatorFunc;
|
|
63
|
+
export type Aggregators = Record<AttrName, Aggregator>;
|
|
64
|
+
/** Infer result type from aggregator specification */
|
|
65
|
+
export type AggregatorResult<A> = A extends 'count' ? number : A extends {
|
|
66
|
+
op: 'count';
|
|
67
|
+
} ? number : A extends {
|
|
68
|
+
op: 'sum' | 'avg' | 'min' | 'max';
|
|
69
|
+
} ? number | null : A extends {
|
|
70
|
+
op: 'collect';
|
|
71
|
+
} ? unknown[] : A extends (tuples: Tuple[]) => infer R ? R : unknown;
|
|
72
|
+
/** Map aggregator definitions to their result types */
|
|
73
|
+
export type AggregatorResults<Aggs extends Record<string, unknown>> = {
|
|
74
|
+
[K in keyof Aggs]: AggregatorResult<Aggs[K]>;
|
|
75
|
+
};
|
|
76
|
+
/** Predicate function that receives a typed tuple */
|
|
77
|
+
export type TypedPredicateFunc<T> = (t: T) => boolean;
|
|
78
|
+
/** Predicate: either a partial tuple for equality matching, or a function */
|
|
79
|
+
export type TypedPredicate<T> = Partial<T> | TypedPredicateFunc<T>;
|
|
80
|
+
export type PredicateFunc = ((t: Tuple) => any);
|
|
81
|
+
export type Predicate = Tuple | PredicateFunc;
|
|
82
|
+
/** Extension function that receives a typed tuple */
|
|
83
|
+
export type TypedExtensionFunc<T, R> = (tuple: T) => R;
|
|
84
|
+
/** Extension definition: function returning value, or attribute name to copy */
|
|
85
|
+
export type TypedExtension<T, E extends Record<string, unknown>> = {
|
|
86
|
+
[K in keyof E]: TypedExtensionFunc<T, E[K]> | keyof T;
|
|
87
|
+
};
|
|
88
|
+
export type ExtensionFunc = (tuple: Tuple) => unknown;
|
|
89
|
+
export type Extension = Record<AttrName, ExtensionFunc | AttrName>;
|
|
90
|
+
export interface PrefixOptions {
|
|
91
|
+
except?: AttrName[];
|
|
92
|
+
}
|
|
93
|
+
export interface TextOptions {
|
|
94
|
+
/** Precision for floating point numbers (default: 3) */
|
|
95
|
+
floatPrecision?: number;
|
|
96
|
+
/** Maximum width to trim output at */
|
|
97
|
+
trimAt?: number;
|
|
98
|
+
}
|
|
99
|
+
export interface SuffixOptions {
|
|
100
|
+
except?: AttrName[];
|
|
101
|
+
}
|
|
102
|
+
export interface AutowrapOptions {
|
|
103
|
+
separator?: string;
|
|
104
|
+
}
|
|
105
|
+
export type Renaming = RenamingObj | RenamingFunc;
|
|
106
|
+
export type RenamingFunc = (attr: AttrName) => AttrName;
|
|
107
|
+
export type RenamingObj = Record<AttrName, AttrName>;
|
|
108
|
+
export type JoinKeys = AttrName[] | Record<AttrName, AttrName>;
|
|
109
|
+
export type TransformFunc = (value: unknown) => unknown;
|
|
110
|
+
export type Transformation = TransformFunc | TransformFunc[] | Record<AttrName, TransformFunc | TransformFunc[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Relation interface with generic type parameter for tuple type.
|
|
113
|
+
* Default parameter `Tuple` ensures backwards compatibility.
|
|
114
|
+
*
|
|
115
|
+
* @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // Untyped usage (backwards compatible)
|
|
119
|
+
* const r = Bmg([{ id: 1 }]); // Relation<Tuple>
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // Typed usage with full type safety
|
|
123
|
+
* interface Person { id: number; name: string }
|
|
124
|
+
* const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);
|
|
125
|
+
* r.project(['id']); // Relation<{ id: number }>
|
|
126
|
+
*/
|
|
127
|
+
export interface Relation<T = Tuple> {
|
|
128
|
+
restrict(p: TypedPredicate<T>): Relation<T>;
|
|
129
|
+
where(p: TypedPredicate<T>): Relation<T>;
|
|
130
|
+
exclude(p: TypedPredicate<T>): Relation<T>;
|
|
131
|
+
project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>>;
|
|
132
|
+
allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>>;
|
|
133
|
+
extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E>;
|
|
134
|
+
constants<C extends Tuple>(consts: C): Relation<T & C>;
|
|
135
|
+
rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>>;
|
|
136
|
+
prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: {
|
|
137
|
+
except?: Ex[];
|
|
138
|
+
}): Relation<Prefixed<T, P, Ex>>;
|
|
139
|
+
suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: {
|
|
140
|
+
except?: Ex[];
|
|
141
|
+
}): Relation<Suffixed<T, S, Ex>>;
|
|
142
|
+
union(right: RelationOperand<T>): Relation<T>;
|
|
143
|
+
minus(right: RelationOperand<T>): Relation<T>;
|
|
144
|
+
intersect(right: RelationOperand<T>): Relation<T>;
|
|
145
|
+
matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>;
|
|
146
|
+
not_matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>;
|
|
147
|
+
join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<Joined<T, R>>;
|
|
148
|
+
left_join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<LeftJoined<T, R>>;
|
|
149
|
+
cross_product<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
150
|
+
cross_join<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
151
|
+
image<R, As extends string>(right: RelationOperand<R>, as: As, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T & Record<As, Relation<Omit<R, keyof T & keyof R>>>>;
|
|
152
|
+
group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>;
|
|
153
|
+
ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>>;
|
|
154
|
+
wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>>;
|
|
155
|
+
unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>>;
|
|
156
|
+
summarize<By extends keyof T, Aggs extends Aggregators>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>>;
|
|
157
|
+
transform(t: Transformation): Relation<T>;
|
|
158
|
+
autowrap(options?: AutowrapOptions): Relation<Tuple>;
|
|
159
|
+
one(): T;
|
|
160
|
+
yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>;
|
|
161
|
+
toArray(): T[];
|
|
162
|
+
isEqual(right: any): boolean;
|
|
163
|
+
toText(options?: TextOptions): string;
|
|
164
|
+
}
|
|
165
|
+
export type RelationOperand<T = Tuple> = Relation<T> | T[];
|
|
166
|
+
export interface OperationalOperand<T = Tuple> {
|
|
167
|
+
tuples(): Iterable<T>;
|
|
168
|
+
output(tuples: T[]): RelationOperand<T>;
|
|
169
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Relation, Tuple } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for text rendering
|
|
4
|
+
*/
|
|
5
|
+
export interface TextOptions {
|
|
6
|
+
/** Format string for floating point numbers (default: '%.3f' style) */
|
|
7
|
+
floatPrecision?: number;
|
|
8
|
+
/** Maximum width to trim output at */
|
|
9
|
+
trimAt?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Text writer for rendering relations as ASCII tables
|
|
13
|
+
*/
|
|
14
|
+
export declare class TextWriter {
|
|
15
|
+
readonly options: TextOptions;
|
|
16
|
+
constructor(options?: TextOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Renders a relation or tuple array to an ASCII table string
|
|
19
|
+
*/
|
|
20
|
+
render(input: Relation | Tuple[] | Tuple, output?: string): string;
|
|
21
|
+
eachLine(input: Relation | Tuple[] | Tuple): Generator<string>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Renders a relation as an ASCII table string
|
|
25
|
+
*
|
|
26
|
+
* @param operand - The relation or tuple array to render
|
|
27
|
+
* @param options - Text rendering options
|
|
28
|
+
* @returns ASCII table string representation
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const r = Bmg([{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]);
|
|
32
|
+
* console.log(toText(r));
|
|
33
|
+
* // +----+-------+
|
|
34
|
+
* // | id | name |
|
|
35
|
+
* // +----+-------+
|
|
36
|
+
* // | 1 | Alice |
|
|
37
|
+
* // | 2 | Bob |
|
|
38
|
+
* // +----+-------+
|
|
39
|
+
*/
|
|
40
|
+
export declare const toText: (operand: Relation | Tuple[] | Tuple, options?: TextOptions) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Text';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enspirit/bmg-js",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Relational algebra for JavaScript/TypeScript - work with arrays of objects using powerful set operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"relational",
|
|
@@ -23,22 +23,24 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"source": "src/index.ts",
|
|
25
25
|
"exports": {
|
|
26
|
-
"types": "./dist/
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
27
|
"require": "./dist/bmg.cjs",
|
|
28
28
|
"default": "./dist/bmg.modern.js"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/bmg.cjs",
|
|
31
31
|
"module": "./dist/bmg.module.js",
|
|
32
|
-
"types": "./dist/
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
33
|
"unpkg": "./dist/bmg.umd.js",
|
|
34
34
|
"scripts": {
|
|
35
|
-
"
|
|
35
|
+
"generate:lib-definitions": "npx tsx scripts/generate-lib-definitions.ts",
|
|
36
|
+
"build": "npm run generate:lib-definitions && microbundle --no-generateTypes && tsc -p tsconfig.build.json",
|
|
36
37
|
"dev": "microbundle watch",
|
|
37
38
|
"test": "vitest run",
|
|
38
39
|
"test:watch": "vitest"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"microbundle": "^0.15.1",
|
|
43
|
+
"tsx": "^4.19.0",
|
|
42
44
|
"vite-tsconfig-paths": "^5.1.4",
|
|
43
45
|
"vitest": "^4.0.16"
|
|
44
46
|
},
|
package/src/Relation/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
// Re-export sync Relation for backward compatibility
|
|
2
|
+
export * from '../sync/Relation';
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { AsyncRelation, AsyncRelationOperand } from '../types';
|
|
2
|
+
import type { Tuple, TypedPredicate, TypedExtension, AttrName, Relation, RenameMap, Renamed, Prefixed, Suffixed, Transformation, JoinKeys, Aggregators, AutowrapOptions, TextOptions } from '../../types';
|
|
3
|
+
import { MemoryRelation } from '../../sync/Relation';
|
|
4
|
+
import {
|
|
5
|
+
restrict as restrictOp,
|
|
6
|
+
where as whereOp,
|
|
7
|
+
exclude as excludeOp,
|
|
8
|
+
} from '../operators/restrict';
|
|
9
|
+
import {
|
|
10
|
+
project as projectOp,
|
|
11
|
+
allbut as allbutOp,
|
|
12
|
+
} from '../operators/project';
|
|
13
|
+
import { extend as extendOp } from '../operators/extend';
|
|
14
|
+
import { constants as constantsOp } from '../operators/constants';
|
|
15
|
+
import { rename as renameOp } from '../operators/rename';
|
|
16
|
+
import { prefix as prefixOp } from '../operators/prefix';
|
|
17
|
+
import { suffix as suffixOp } from '../operators/suffix';
|
|
18
|
+
import { transform as transformOp } from '../operators/transform';
|
|
19
|
+
import { union as unionOp } from '../operators/union';
|
|
20
|
+
import { minus as minusOp } from '../operators/minus';
|
|
21
|
+
import { intersect as intersectOp } from '../operators/intersect';
|
|
22
|
+
import { matching as matchingOp } from '../operators/matching';
|
|
23
|
+
import { not_matching as notMatchingOp } from '../operators/not_matching';
|
|
24
|
+
import { join as joinOp } from '../operators/join';
|
|
25
|
+
import { left_join as leftJoinOp } from '../operators/left_join';
|
|
26
|
+
import { cross_product as crossProductOp } from '../operators/cross_product';
|
|
27
|
+
import { group as groupOp } from '../operators/group';
|
|
28
|
+
import { ungroup as ungroupOp } from '../operators/ungroup';
|
|
29
|
+
import { wrap as wrapOp } from '../operators/wrap';
|
|
30
|
+
import { unwrap as unwrapOp } from '../operators/unwrap';
|
|
31
|
+
import { image as imageOp } from '../operators/image';
|
|
32
|
+
import { summarize as summarizeOp } from '../operators/summarize';
|
|
33
|
+
import { autowrap as autowrapOp } from '../operators/autowrap';
|
|
34
|
+
import { yByX as yByXOp } from '../operators/yByX';
|
|
35
|
+
import { one as oneOp } from '../operators/one';
|
|
36
|
+
import { toArray as toArrayOp } from '../operators/toArray';
|
|
37
|
+
import { toText as toTextSync } from '../../writer';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Base implementation of AsyncRelation using lazy evaluation.
|
|
41
|
+
* Each operator returns a new BaseAsyncRelation wrapping the transformed iterable.
|
|
42
|
+
*/
|
|
43
|
+
export class BaseAsyncRelation<T = Tuple> implements AsyncRelation<T> {
|
|
44
|
+
constructor(private source: AsyncIterable<T>) {}
|
|
45
|
+
|
|
46
|
+
// === Type-preserving operators ===
|
|
47
|
+
|
|
48
|
+
restrict(p: TypedPredicate<T>): AsyncRelation<T> {
|
|
49
|
+
return new BaseAsyncRelation(restrictOp(this.source, p as any));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
where(p: TypedPredicate<T>): AsyncRelation<T> {
|
|
53
|
+
return new BaseAsyncRelation(whereOp(this.source, p as any));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exclude(p: TypedPredicate<T>): AsyncRelation<T> {
|
|
57
|
+
return new BaseAsyncRelation(excludeOp(this.source, p as any));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// === Projection operators ===
|
|
61
|
+
|
|
62
|
+
project<K extends keyof T>(attrs: K[]): AsyncRelation<Pick<T, K>> {
|
|
63
|
+
return new BaseAsyncRelation(
|
|
64
|
+
projectOp(this.source, attrs as AttrName[])
|
|
65
|
+
) as unknown as AsyncRelation<Pick<T, K>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
allbut<K extends keyof T>(attrs: K[]): AsyncRelation<Omit<T, K>> {
|
|
69
|
+
return new BaseAsyncRelation(
|
|
70
|
+
allbutOp(this.source, attrs as AttrName[])
|
|
71
|
+
) as unknown as AsyncRelation<Omit<T, K>>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// === Extension operators ===
|
|
75
|
+
|
|
76
|
+
extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): AsyncRelation<T & E> {
|
|
77
|
+
return new BaseAsyncRelation(
|
|
78
|
+
extendOp(this.source, e as any)
|
|
79
|
+
) as unknown as AsyncRelation<T & E>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
constants<C extends Tuple>(consts: C): AsyncRelation<T & C> {
|
|
83
|
+
return new BaseAsyncRelation(
|
|
84
|
+
constantsOp(this.source, consts)
|
|
85
|
+
) as unknown as AsyncRelation<T & C>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// === Rename operators ===
|
|
89
|
+
|
|
90
|
+
rename<R extends RenameMap<T>>(r: R): AsyncRelation<Renamed<T, R>> {
|
|
91
|
+
return new BaseAsyncRelation(
|
|
92
|
+
renameOp(this.source, r as any)
|
|
93
|
+
) as unknown as AsyncRelation<Renamed<T, R>>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): AsyncRelation<Prefixed<T, P, Ex>> {
|
|
97
|
+
return new BaseAsyncRelation(
|
|
98
|
+
prefixOp(this.source, pfx, options as any)
|
|
99
|
+
) as unknown as AsyncRelation<Prefixed<T, P, Ex>>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): AsyncRelation<Suffixed<T, S, Ex>> {
|
|
103
|
+
return new BaseAsyncRelation(
|
|
104
|
+
suffixOp(this.source, sfx, options as any)
|
|
105
|
+
) as unknown as AsyncRelation<Suffixed<T, S, Ex>>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
transform(t: Transformation): AsyncRelation<T> {
|
|
109
|
+
return new BaseAsyncRelation(
|
|
110
|
+
transformOp(this.source, t)
|
|
111
|
+
) as unknown as AsyncRelation<T>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// === Set operations ===
|
|
115
|
+
|
|
116
|
+
union(other: AsyncRelationOperand<T>): AsyncRelation<T> {
|
|
117
|
+
return new BaseAsyncRelation(
|
|
118
|
+
unionOp(this.source, other)
|
|
119
|
+
) as unknown as AsyncRelation<T>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
minus(other: AsyncRelationOperand<T>): AsyncRelation<T> {
|
|
123
|
+
return new BaseAsyncRelation(
|
|
124
|
+
minusOp(this.source, other)
|
|
125
|
+
) as unknown as AsyncRelation<T>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
intersect(other: AsyncRelationOperand<T>): AsyncRelation<T> {
|
|
129
|
+
return new BaseAsyncRelation(
|
|
130
|
+
intersectOp(this.source, other)
|
|
131
|
+
) as unknown as AsyncRelation<T>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// === Semi-joins ===
|
|
135
|
+
|
|
136
|
+
matching<U>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T> {
|
|
137
|
+
return new BaseAsyncRelation(
|
|
138
|
+
matchingOp(this.source, other, keys)
|
|
139
|
+
) as unknown as AsyncRelation<T>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
not_matching<U>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T> {
|
|
143
|
+
return new BaseAsyncRelation(
|
|
144
|
+
notMatchingOp(this.source, other, keys)
|
|
145
|
+
) as unknown as AsyncRelation<T>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// === Joins ===
|
|
149
|
+
|
|
150
|
+
join<U>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T & U> {
|
|
151
|
+
return new BaseAsyncRelation(
|
|
152
|
+
joinOp(this.source, other, keys)
|
|
153
|
+
) as unknown as AsyncRelation<T & U>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
left_join<U>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T & Partial<U>> {
|
|
157
|
+
return new BaseAsyncRelation(
|
|
158
|
+
leftJoinOp(this.source, other, keys)
|
|
159
|
+
) as unknown as AsyncRelation<T & Partial<U>>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
cross_product<U>(other: AsyncRelationOperand<U>): AsyncRelation<T & U> {
|
|
163
|
+
return new BaseAsyncRelation(
|
|
164
|
+
crossProductOp(this.source, other)
|
|
165
|
+
) as unknown as AsyncRelation<T & U>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
cross_join<U>(other: AsyncRelationOperand<U>): AsyncRelation<T & U> {
|
|
169
|
+
return this.cross_product(other);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// === Nesting/Grouping ===
|
|
173
|
+
|
|
174
|
+
group<K extends keyof T>(attrs: K[], as: string): AsyncRelation<Omit<T, K> & Record<string, Relation<Pick<T, K>>>> {
|
|
175
|
+
return new BaseAsyncRelation(
|
|
176
|
+
groupOp(this.source, attrs as string[], as)
|
|
177
|
+
) as unknown as AsyncRelation<Omit<T, K> & Record<string, Relation<Pick<T, K>>>>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
ungroup(attr: string): AsyncRelation<Tuple> {
|
|
181
|
+
return new BaseAsyncRelation(
|
|
182
|
+
ungroupOp(this.source, attr)
|
|
183
|
+
) as unknown as AsyncRelation<Tuple>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
wrap<K extends keyof T>(attrs: K[], as: string): AsyncRelation<Omit<T, K> & Record<string, Pick<T, K>>> {
|
|
187
|
+
return new BaseAsyncRelation(
|
|
188
|
+
wrapOp(this.source, attrs as string[], as)
|
|
189
|
+
) as unknown as AsyncRelation<Omit<T, K> & Record<string, Pick<T, K>>>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
unwrap(attr: string): AsyncRelation<Tuple> {
|
|
193
|
+
return new BaseAsyncRelation(
|
|
194
|
+
unwrapOp(this.source, attr)
|
|
195
|
+
) as unknown as AsyncRelation<Tuple>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
image<U>(other: AsyncRelationOperand<U>, as: string, keys?: JoinKeys): AsyncRelation<T & Record<string, Relation<U>>> {
|
|
199
|
+
return new BaseAsyncRelation(
|
|
200
|
+
imageOp(this.source, other, as, keys)
|
|
201
|
+
) as unknown as AsyncRelation<T & Record<string, Relation<U>>>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
summarize<K extends keyof T>(by: K[], aggs: Aggregators): AsyncRelation<Pick<T, K> & Tuple> {
|
|
205
|
+
return new BaseAsyncRelation(
|
|
206
|
+
summarizeOp(this.source, by as string[], aggs)
|
|
207
|
+
) as unknown as AsyncRelation<Pick<T, K> & Tuple>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
autowrap(options?: AutowrapOptions): AsyncRelation<Tuple> {
|
|
211
|
+
return new BaseAsyncRelation(
|
|
212
|
+
autowrapOp(this.source, options)
|
|
213
|
+
) as unknown as AsyncRelation<Tuple>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// === Terminal operations ===
|
|
217
|
+
|
|
218
|
+
one(): Promise<T> {
|
|
219
|
+
return oneOp(this.source);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
toArray(): Promise<T[]> {
|
|
223
|
+
return toArrayOp(this.source);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async toRelation(): Promise<Relation<T>> {
|
|
227
|
+
const tuples = await toArrayOp(this.source);
|
|
228
|
+
return new MemoryRelation<T>(tuples);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
yByX(y: string, x: string): Promise<Tuple> {
|
|
232
|
+
return yByXOp(this.source, y, x);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async toText(options?: TextOptions): Promise<string> {
|
|
236
|
+
const tuples = await toArrayOp(this.source);
|
|
237
|
+
return toTextSync(tuples as Tuple[], options);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// === Async iteration ===
|
|
241
|
+
|
|
242
|
+
[Symbol.asyncIterator](): AsyncIterator<T> {
|
|
243
|
+
return this.source[Symbol.asyncIterator]();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseAsyncRelation } from './Base';
|
|
2
|
+
import type { AsyncRelation, AsyncRelationOperand } from '../types';
|
|
3
|
+
import { isEqual as isEqualOp } from '../operators/isEqual';
|
|
4
|
+
|
|
5
|
+
export { BaseAsyncRelation };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new async relation from an AsyncIterable source.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The tuple type. Inferred from input or explicitly provided.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // From an async iterable
|
|
14
|
+
* const suppliers = AsyncBmg(fetchSuppliersFromDB());
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Chained operations (lazy - no execution yet)
|
|
18
|
+
* const query = AsyncBmg(source)
|
|
19
|
+
* .restrict({ city: 'London' })
|
|
20
|
+
* .project(['sid', 'name']);
|
|
21
|
+
*
|
|
22
|
+
* // Terminal operation triggers execution
|
|
23
|
+
* const results = await query.toArray();
|
|
24
|
+
*/
|
|
25
|
+
export function AsyncBmg<T>(source: AsyncIterable<T>): AsyncRelation<T> {
|
|
26
|
+
return new BaseAsyncRelation<T>(source);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
AsyncBmg.isEqual = <T, U>(left: AsyncRelationOperand<T>, right: AsyncRelationOperand<U>): Promise<boolean> => {
|
|
30
|
+
return isEqualOp(left, right);
|
|
31
|
+
};
|