@enspirit/bmg-js 1.0.1 → 1.0.2
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/dist/{src/Relation → Relation}/Memory.d.ts +45 -46
- package/dist/{src/src/Relation → Relation}/index.d.ts +1 -1
- 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 +27 -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/{src/operators → operators}/index.d.ts +30 -30
- package/dist/{src/src/operators → operators}/intersect.d.ts +2 -2
- package/dist/{src/src/operators → operators}/isEqual.d.ts +2 -2
- package/dist/{src/operators → operators}/isRelation.d.ts +1 -1
- 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}/where.d.ts +1 -1
- 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/types.d.ts → types.d.ts} +162 -101
- package/package.json +6 -4
- package/src/Relation/Memory.ts +13 -12
- package/src/index.ts +1 -1
- package/src/lib-definitions.ts +281 -0
- package/src/types.ts +142 -54
- package/dist/src/Relation/index.d.ts +0 -1
- package/dist/src/Relation.d.ts +0 -8
- package/dist/src/index.d.ts +0 -27
- package/dist/src/operators/group.d.ts +0 -2
- package/dist/src/operators/intersect.d.ts +0 -2
- package/dist/src/operators/isEqual.d.ts +0 -2
- package/dist/src/operators/matching.d.ts +0 -2
- package/dist/src/operators/minus.d.ts +0 -2
- package/dist/src/operators/not_matching.d.ts +0 -2
- package/dist/src/operators/project.d.ts +0 -2
- package/dist/src/operators/ungroup.d.ts +0 -2
- package/dist/src/src/Relation/Memory.d.ts +0 -46
- package/dist/src/src/index.d.ts +0 -27
- package/dist/src/src/operators/_helpers.d.ts +0 -142
- package/dist/src/src/operators/allbut.d.ts +0 -2
- package/dist/src/src/operators/autowrap.d.ts +0 -2
- package/dist/src/src/operators/constants.d.ts +0 -2
- package/dist/src/src/operators/cross_product.d.ts +0 -3
- package/dist/src/src/operators/exclude.d.ts +0 -2
- package/dist/src/src/operators/extend.d.ts +0 -2
- package/dist/src/src/operators/image.d.ts +0 -2
- package/dist/src/src/operators/index.d.ts +0 -30
- package/dist/src/src/operators/isRelation.d.ts +0 -1
- package/dist/src/src/operators/join.d.ts +0 -2
- package/dist/src/src/operators/left_join.d.ts +0 -2
- package/dist/src/src/operators/one.d.ts +0 -2
- package/dist/src/src/operators/prefix.d.ts +0 -2
- package/dist/src/src/operators/rename.d.ts +0 -2
- package/dist/src/src/operators/restrict.d.ts +0 -2
- package/dist/src/src/operators/suffix.d.ts +0 -2
- package/dist/src/src/operators/summarize.d.ts +0 -2
- package/dist/src/src/operators/transform.d.ts +0 -2
- package/dist/src/src/operators/union.d.ts +0 -2
- package/dist/src/src/operators/unwrap.d.ts +0 -2
- package/dist/src/src/operators/where.d.ts +0 -1
- package/dist/src/src/operators/wrap.d.ts +0 -2
- package/dist/src/src/operators/yByX.d.ts +0 -2
- 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/utility-types.ts +0 -77
package/dist/src/src/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export * from './operators';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export * from './utility-types';
|
|
4
|
-
import { MemoryRelation } from './Relation';
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new in-memory relation from an array of tuples.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - The tuple type. Inferred from input or explicitly provided.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* // Untyped usage (backwards compatible)
|
|
12
|
-
* const r = Bmg([{ id: 1, name: 'Alice' }]);
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Typed usage with explicit type parameter
|
|
16
|
-
* interface Person { id: number; name: string }
|
|
17
|
-
* const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);
|
|
18
|
-
* r.project(['id']); // Autocomplete suggests 'id' | 'name'
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Type is inferred from input
|
|
22
|
-
* const r = Bmg([{ id: 1, name: 'Alice' }] as const);
|
|
23
|
-
*/
|
|
24
|
-
export declare function Bmg<T>(tuples: T[]): MemoryRelation<T>;
|
|
25
|
-
export declare namespace Bmg {
|
|
26
|
-
var isRelation: (op: any) => boolean;
|
|
27
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { OperationalOperand, RelationOperand, Renaming, RenamingFunc, Tuple, JoinKeys, AttrName } from "@/types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates a unique string key for a tuple, used for equality comparison and deduplication.
|
|
4
|
-
* Handles nested relations by converting them to sorted tuple keys.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* tupleKey({ name: 'Alice', age: 30 })
|
|
8
|
-
* // => '[["age",30],["name","Alice"]]'
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* tupleKey({ id: 1, items: Bmg([{ x: 1 }, { x: 2 }]) })
|
|
12
|
-
* // => '[["id",1],["items",[...]]]' (nested relation converted to sorted keys)
|
|
13
|
-
*/
|
|
14
|
-
export declare const tupleKey: (tuple: Tuple) => string;
|
|
15
|
-
/**
|
|
16
|
-
* Removes duplicate tuples from an array, preserving order of first occurrence.
|
|
17
|
-
* Uses tupleKey() for equality comparison.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* deduplicate([
|
|
21
|
-
* { id: 1, name: 'Alice' },
|
|
22
|
-
* { id: 2, name: 'Bob' },
|
|
23
|
-
* { id: 1, name: 'Alice' }, // duplicate
|
|
24
|
-
* ])
|
|
25
|
-
* // => [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
|
|
26
|
-
*/
|
|
27
|
-
export declare const deduplicate: (tuples: Tuple[]) => Tuple[];
|
|
28
|
-
/**
|
|
29
|
-
* Converts a RelationOperand (Relation or Tuple[]) to an OperationalOperand
|
|
30
|
-
* that provides a uniform interface for iteration and output.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* // With array input, output remains array
|
|
34
|
-
* const op = toOperationalOperand([{ id: 1 }]);
|
|
35
|
-
* [...op.tuples()]; // => [{ id: 1 }]
|
|
36
|
-
* op.output([{ id: 2 }]); // => [{ id: 2 }]
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* // With Relation input, output is a new Relation
|
|
40
|
-
* const op = toOperationalOperand(Bmg([{ id: 1 }]));
|
|
41
|
-
* [...op.tuples()]; // => [{ id: 1 }]
|
|
42
|
-
* op.output([{ id: 2 }]); // => Bmg([{ id: 2 }])
|
|
43
|
-
*/
|
|
44
|
-
export declare const toOperationalOperand: (operand: RelationOperand) => OperationalOperand;
|
|
45
|
-
/**
|
|
46
|
-
* Converts a Renaming (object or function) to a RenamingFunc.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* // Object renaming
|
|
50
|
-
* const fn = toRenamingFunc({ name: 'fullName', age: 'years' });
|
|
51
|
-
* fn('name'); // => 'fullName'
|
|
52
|
-
* fn('age'); // => 'years'
|
|
53
|
-
* fn('other'); // => 'other' (unchanged)
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* // Function renaming (passed through)
|
|
57
|
-
* const fn = toRenamingFunc(attr => attr.toUpperCase());
|
|
58
|
-
* fn('name'); // => 'NAME'
|
|
59
|
-
*/
|
|
60
|
-
export declare const toRenamingFunc: (renaming: Renaming) => RenamingFunc;
|
|
61
|
-
export declare const error: (msg: string) => never;
|
|
62
|
-
/**
|
|
63
|
-
* Finds attribute names that exist in both left and right tuple arrays.
|
|
64
|
-
* Used for natural joins when no explicit keys are provided.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* const left = [{ id: 1, name: 'Alice', city: 'NYC' }];
|
|
68
|
-
* const right = [{ city: 'NYC', country: 'USA' }];
|
|
69
|
-
* getCommonAttrs(left, right);
|
|
70
|
-
* // => ['city']
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* const left = [{ a: 1, b: 2 }];
|
|
74
|
-
* const right = [{ b: 2, c: 3 }];
|
|
75
|
-
* getCommonAttrs(left, right);
|
|
76
|
-
* // => ['b']
|
|
77
|
-
*/
|
|
78
|
-
export declare const getCommonAttrs: (left: Tuple[], right: Tuple[]) => AttrName[];
|
|
79
|
-
/**
|
|
80
|
-
* Normalizes JoinKeys to a Record<AttrName, AttrName> mapping left attrs to right attrs.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* // undefined => use common attributes
|
|
84
|
-
* normalizeKeys(undefined, [{ id: 1, city: 'NYC' }], [{ city: 'NYC' }]);
|
|
85
|
-
* // => { city: 'city' }
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* // Array of common attribute names
|
|
89
|
-
* normalizeKeys(['city', 'country'], leftTuples, rightTuples);
|
|
90
|
-
* // => { city: 'city', country: 'country' }
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* // Object mapping left attr to right attr
|
|
94
|
-
* normalizeKeys({ city: 'location' }, leftTuples, rightTuples);
|
|
95
|
-
* // => { city: 'location' }
|
|
96
|
-
*/
|
|
97
|
-
export declare const normalizeKeys: (keys: JoinKeys | undefined, leftTuples: Tuple[], rightTuples: Tuple[]) => Record<AttrName, AttrName>;
|
|
98
|
-
/**
|
|
99
|
-
* Checks if two tuples match on the specified key mapping.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* const keyMap = { city: 'location' };
|
|
103
|
-
* tuplesMatch({ id: 1, city: 'NYC' }, { location: 'NYC', pop: 8 }, keyMap);
|
|
104
|
-
* // => true (left.city === right.location)
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* const keyMap = { city: 'city' };
|
|
108
|
-
* tuplesMatch({ city: 'NYC' }, { city: 'LA' }, keyMap);
|
|
109
|
-
* // => false
|
|
110
|
-
*/
|
|
111
|
-
export declare const tuplesMatch: (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>) => boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Creates a string key from a tuple's join attributes for fast Set-based lookups.
|
|
114
|
-
* Used by matching/not_matching for efficient semi-join operations.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* const keyMap = { first: 'fname', last: 'lname' };
|
|
118
|
-
*
|
|
119
|
-
* // Left side uses left attr names (keys of keyMap)
|
|
120
|
-
* matchKey({ id: 1, first: 'John', last: 'Doe' }, keyMap, 'left');
|
|
121
|
-
* // => '"John"|"Doe"'
|
|
122
|
-
*
|
|
123
|
-
* // Right side uses right attr names (values of keyMap)
|
|
124
|
-
* matchKey({ fname: 'John', lname: 'Doe', age: 30 }, keyMap, 'right');
|
|
125
|
-
* // => '"John"|"Doe"'
|
|
126
|
-
*/
|
|
127
|
-
export declare const matchKey: (tuple: Tuple, keyMap: Record<AttrName, AttrName>, side: 'left' | 'right') => string;
|
|
128
|
-
/**
|
|
129
|
-
* Removes join key attributes from a right tuple when merging.
|
|
130
|
-
* Used to avoid duplicate columns in join results.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* const keyMap = { city: 'location' };
|
|
134
|
-
* projectOutKeys({ location: 'NYC', country: 'USA', pop: 8 }, keyMap);
|
|
135
|
-
* // => { country: 'USA', pop: 8 } (location removed)
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* const keyMap = { a: 'a', b: 'b' };
|
|
139
|
-
* projectOutKeys({ a: 1, b: 2, c: 3 }, keyMap);
|
|
140
|
-
* // => { c: 3 } (a and b removed)
|
|
141
|
-
*/
|
|
142
|
-
export declare const projectOutKeys: (tuple: Tuple, keyMap: Record<AttrName, AttrName>) => Tuple;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export * from './restrict';
|
|
2
|
-
export * from './where';
|
|
3
|
-
export * from './exclude';
|
|
4
|
-
export * from './constants';
|
|
5
|
-
export * from './rename';
|
|
6
|
-
export * from './prefix';
|
|
7
|
-
export * from './suffix';
|
|
8
|
-
export * from './project';
|
|
9
|
-
export * from './allbut';
|
|
10
|
-
export * from './extend';
|
|
11
|
-
export * from './union';
|
|
12
|
-
export * from './minus';
|
|
13
|
-
export * from './intersect';
|
|
14
|
-
export * from './matching';
|
|
15
|
-
export * from './not_matching';
|
|
16
|
-
export * from './join';
|
|
17
|
-
export * from './left_join';
|
|
18
|
-
export * from './cross_product';
|
|
19
|
-
export * from './image';
|
|
20
|
-
export * from './summarize';
|
|
21
|
-
export * from './group';
|
|
22
|
-
export * from './ungroup';
|
|
23
|
-
export * from './wrap';
|
|
24
|
-
export * from './unwrap';
|
|
25
|
-
export * from './autowrap';
|
|
26
|
-
export * from './transform';
|
|
27
|
-
export * from './isRelation';
|
|
28
|
-
export * from './isEqual';
|
|
29
|
-
export * from './one';
|
|
30
|
-
export * from './yByX';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isRelation: (op: any) => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { restrict as where } from './restrict';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility types for type transformations in relational operators.
|
|
3
|
-
* These enable compile-time tracking of how operators transform tuple types.
|
|
4
|
-
*/
|
|
5
|
-
import type { Tuple } from './types';
|
|
6
|
-
/** Map from old attribute names to new attribute names */
|
|
7
|
-
export type RenameMap<T> = {
|
|
8
|
-
[K in keyof T]?: string;
|
|
9
|
-
};
|
|
10
|
-
/** Transform tuple type by renaming keys according to RenameMap */
|
|
11
|
-
export type Renamed<T, R extends RenameMap<T>> = {
|
|
12
|
-
[K in keyof T as K extends keyof R ? (R[K] extends string ? R[K] : K) : K]: T[K];
|
|
13
|
-
};
|
|
14
|
-
/** Prefix all keys except those in Except */
|
|
15
|
-
export type Prefixed<T, P extends string, Except extends keyof T = never> = {
|
|
16
|
-
[K in keyof T as K extends Except ? K : `${P}${K & string}`]: T[K];
|
|
17
|
-
};
|
|
18
|
-
/** Suffix all keys except those in Except */
|
|
19
|
-
export type Suffixed<T, S extends string, Except extends keyof T = never> = {
|
|
20
|
-
[K in keyof T as K extends Except ? K : `${K & string}${S}`]: T[K];
|
|
21
|
-
};
|
|
22
|
-
/** Extract common keys between two tuple types */
|
|
23
|
-
export type CommonKeys<L, R> = Extract<keyof L, keyof R>;
|
|
24
|
-
/** Result of inner join: L & R with R's common keys removed */
|
|
25
|
-
export type Joined<L, R> = L & Omit<R, CommonKeys<L, R>>;
|
|
26
|
-
/** Result of left join: L & optional R attributes (common keys removed) */
|
|
27
|
-
export type LeftJoined<L, R> = L & Partial<Omit<R, CommonKeys<L, R>>>;
|
|
28
|
-
/** Result of wrap: remove wrapped attrs, add nested object */
|
|
29
|
-
export type Wrapped<T, K extends keyof T, As extends string> = Omit<T, K> & Record<As, Pick<T, K>>;
|
|
30
|
-
/** Result of unwrap: remove object attr, spread its properties */
|
|
31
|
-
export type Unwrapped<T, K extends keyof T> = T[K] extends Record<string, unknown> ? Omit<T, K> & T[K] : Omit<T, K>;
|
|
32
|
-
/** Infer result type from aggregator specification */
|
|
33
|
-
export type AggregatorResult<A> = A extends 'count' ? number : A extends {
|
|
34
|
-
op: 'count';
|
|
35
|
-
} ? number : A extends {
|
|
36
|
-
op: 'sum' | 'avg' | 'min' | 'max';
|
|
37
|
-
} ? number | null : A extends {
|
|
38
|
-
op: 'collect';
|
|
39
|
-
} ? unknown[] : A extends (tuples: Tuple[]) => infer R ? R : unknown;
|
|
40
|
-
/** Map aggregator definitions to their result types */
|
|
41
|
-
export type AggregatorResults<Aggs extends Record<string, unknown>> = {
|
|
42
|
-
[K in keyof Aggs]: AggregatorResult<Aggs[K]>;
|
|
43
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { RenameMap, Renamed, Prefixed, Suffixed, Joined, LeftJoined, Wrapped, Unwrapped, AggregatorResults } from './utility-types';
|
|
2
|
-
/** Result of ungroup: remove relation attr, flatten its tuple type */
|
|
3
|
-
export type Ungrouped<T, K extends keyof T> = T[K] extends Relation<infer N> ? Omit<T, K> & N : Omit<T, K>;
|
|
4
|
-
export type AttrName = string;
|
|
5
|
-
export type Tuple = Record<AttrName, unknown>;
|
|
6
|
-
export interface PrefixOptions {
|
|
7
|
-
except?: AttrName[];
|
|
8
|
-
}
|
|
9
|
-
export interface SuffixOptions {
|
|
10
|
-
except?: AttrName[];
|
|
11
|
-
}
|
|
12
|
-
export interface AutowrapOptions {
|
|
13
|
-
separator?: string;
|
|
14
|
-
}
|
|
15
|
-
/** Predicate function that receives a typed tuple */
|
|
16
|
-
export type TypedPredicateFunc<T> = (t: T) => boolean;
|
|
17
|
-
/** Predicate: either a partial tuple for equality matching, or a function */
|
|
18
|
-
export type TypedPredicate<T> = Partial<T> | TypedPredicateFunc<T>;
|
|
19
|
-
/** Extension function that receives a typed tuple */
|
|
20
|
-
export type TypedExtensionFunc<T, R> = (tuple: T) => R;
|
|
21
|
-
/** Extension definition: function returning value, or attribute name to copy */
|
|
22
|
-
export type TypedExtension<T, E extends Record<string, unknown>> = {
|
|
23
|
-
[K in keyof E]: TypedExtensionFunc<T, E[K]> | keyof T;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Relation interface with generic type parameter for tuple type.
|
|
27
|
-
* Default parameter `Tuple` ensures backwards compatibility.
|
|
28
|
-
*
|
|
29
|
-
* @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* // Untyped usage (backwards compatible)
|
|
33
|
-
* const r = Bmg([{ id: 1 }]); // Relation<Tuple>
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* // Typed usage with full type safety
|
|
37
|
-
* interface Person { id: number; name: string }
|
|
38
|
-
* const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);
|
|
39
|
-
* r.project(['id']); // Relation<{ id: number }>
|
|
40
|
-
*/
|
|
41
|
-
export interface Relation<T = Tuple> {
|
|
42
|
-
restrict(p: TypedPredicate<T>): Relation<T>;
|
|
43
|
-
where(p: TypedPredicate<T>): Relation<T>;
|
|
44
|
-
exclude(p: TypedPredicate<T>): Relation<T>;
|
|
45
|
-
project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>>;
|
|
46
|
-
allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>>;
|
|
47
|
-
extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E>;
|
|
48
|
-
constants<C extends Tuple>(consts: C): Relation<T & C>;
|
|
49
|
-
rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>>;
|
|
50
|
-
prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: {
|
|
51
|
-
except?: Ex[];
|
|
52
|
-
}): Relation<Prefixed<T, P, Ex>>;
|
|
53
|
-
suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: {
|
|
54
|
-
except?: Ex[];
|
|
55
|
-
}): Relation<Suffixed<T, S, Ex>>;
|
|
56
|
-
union(right: RelationOperand<T>): Relation<T>;
|
|
57
|
-
minus(right: RelationOperand<T>): Relation<T>;
|
|
58
|
-
intersect(right: RelationOperand<T>): Relation<T>;
|
|
59
|
-
matching<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<T>;
|
|
60
|
-
not_matching<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<T>;
|
|
61
|
-
join<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<Joined<T, R>>;
|
|
62
|
-
left_join<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<LeftJoined<T, R>>;
|
|
63
|
-
cross_product<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
64
|
-
cross_join<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
65
|
-
image<R, As extends string>(right: RelationOperand<R>, as: As, keys?: JoinKeys): Relation<T & Record<As, Relation<Omit<R, keyof T & keyof R>>>>;
|
|
66
|
-
group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>;
|
|
67
|
-
ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>>;
|
|
68
|
-
wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>>;
|
|
69
|
-
unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>>;
|
|
70
|
-
summarize<By extends keyof T, Aggs extends Aggregators>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>>;
|
|
71
|
-
transform(t: Transformation): Relation<T>;
|
|
72
|
-
autowrap(options?: AutowrapOptions): Relation<Tuple>;
|
|
73
|
-
one(): T;
|
|
74
|
-
yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>;
|
|
75
|
-
toArray(): T[];
|
|
76
|
-
isEqual(right: any): boolean;
|
|
77
|
-
}
|
|
78
|
-
export type RelationOperand<T = Tuple> = Relation<T> | T[];
|
|
79
|
-
export interface OperationalOperand<T = Tuple> {
|
|
80
|
-
tuples(): Iterable<T>;
|
|
81
|
-
output(tuples: T[]): RelationOperand<T>;
|
|
82
|
-
}
|
|
83
|
-
export type PredicateFunc = ((t: Tuple) => any);
|
|
84
|
-
export type Predicate = Tuple | PredicateFunc;
|
|
85
|
-
export type Renaming = RenamingObj | RenamingFunc;
|
|
86
|
-
export type RenamingFunc = (attr: AttrName) => AttrName;
|
|
87
|
-
export type RenamingObj = Record<AttrName, AttrName>;
|
|
88
|
-
export type ExtensionFunc = (tuple: Tuple) => unknown;
|
|
89
|
-
export type Extension = Record<AttrName, ExtensionFunc | AttrName>;
|
|
90
|
-
export type JoinKeys = AttrName[] | Record<AttrName, AttrName>;
|
|
91
|
-
export type AggregatorName = 'count' | 'sum' | 'min' | 'max' | 'avg' | 'collect';
|
|
92
|
-
export type AggregatorSpec = {
|
|
93
|
-
op: AggregatorName;
|
|
94
|
-
attr: AttrName;
|
|
95
|
-
};
|
|
96
|
-
export type AggregatorFunc = (tuples: Tuple[]) => unknown;
|
|
97
|
-
export type Aggregator = AggregatorName | AggregatorSpec | AggregatorFunc;
|
|
98
|
-
export type Aggregators = Record<AttrName, Aggregator>;
|
|
99
|
-
export type TransformFunc = (value: unknown) => unknown;
|
|
100
|
-
export type Transformation = TransformFunc | TransformFunc[] | Record<AttrName, TransformFunc | TransformFunc[]>;
|
|
101
|
-
export type { RenameMap, Renamed, Prefixed, Suffixed, Joined, LeftJoined, Wrapped, Unwrapped } from './utility-types';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility types for type transformations in relational operators.
|
|
3
|
-
* These enable compile-time tracking of how operators transform tuple types.
|
|
4
|
-
*/
|
|
5
|
-
import type { Tuple } from './types';
|
|
6
|
-
/** Map from old attribute names to new attribute names */
|
|
7
|
-
export type RenameMap<T> = {
|
|
8
|
-
[K in keyof T]?: string;
|
|
9
|
-
};
|
|
10
|
-
/** Transform tuple type by renaming keys according to RenameMap */
|
|
11
|
-
export type Renamed<T, R extends RenameMap<T>> = {
|
|
12
|
-
[K in keyof T as K extends keyof R ? (R[K] extends string ? R[K] : K) : K]: T[K];
|
|
13
|
-
};
|
|
14
|
-
/** Prefix all keys except those in Except */
|
|
15
|
-
export type Prefixed<T, P extends string, Except extends keyof T = never> = {
|
|
16
|
-
[K in keyof T as K extends Except ? K : `${P}${K & string}`]: T[K];
|
|
17
|
-
};
|
|
18
|
-
/** Suffix all keys except those in Except */
|
|
19
|
-
export type Suffixed<T, S extends string, Except extends keyof T = never> = {
|
|
20
|
-
[K in keyof T as K extends Except ? K : `${K & string}${S}`]: T[K];
|
|
21
|
-
};
|
|
22
|
-
/** Extract common keys between two tuple types */
|
|
23
|
-
export type CommonKeys<L, R> = Extract<keyof L, keyof R>;
|
|
24
|
-
/** Result of inner join: L & R with R's common keys removed */
|
|
25
|
-
export type Joined<L, R> = L & Omit<R, CommonKeys<L, R>>;
|
|
26
|
-
/** Result of left join: L & optional R attributes (common keys removed) */
|
|
27
|
-
export type LeftJoined<L, R> = L & Partial<Omit<R, CommonKeys<L, R>>>;
|
|
28
|
-
/** Result of wrap: remove wrapped attrs, add nested object */
|
|
29
|
-
export type Wrapped<T, K extends keyof T, As extends string> = Omit<T, K> & Record<As, Pick<T, K>>;
|
|
30
|
-
/** Result of unwrap: remove object attr, spread its properties */
|
|
31
|
-
export type Unwrapped<T, K extends keyof T> = T[K] extends Record<string, unknown> ? Omit<T, K> & T[K] : Omit<T, K>;
|
|
32
|
-
/** Infer result type from aggregator specification */
|
|
33
|
-
export type AggregatorResult<A> = A extends 'count' ? number : A extends {
|
|
34
|
-
op: 'count';
|
|
35
|
-
} ? number : A extends {
|
|
36
|
-
op: 'sum' | 'avg' | 'min' | 'max';
|
|
37
|
-
} ? number | null : A extends {
|
|
38
|
-
op: 'collect';
|
|
39
|
-
} ? unknown[] : A extends (tuples: Tuple[]) => infer R ? R : unknown;
|
|
40
|
-
/** Map aggregator definitions to their result types */
|
|
41
|
-
export type AggregatorResults<Aggs extends Record<string, unknown>> = {
|
|
42
|
-
[K in keyof Aggs]: AggregatorResult<Aggs[K]>;
|
|
43
|
-
};
|
package/dist/tests/bmg.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/tests/fixtures.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|