@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.
Files changed (158) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/{src/Relation → Relation}/Memory.d.ts +45 -46
  3. package/dist/{src/src/Relation → Relation}/index.d.ts +1 -1
  4. package/dist/bmg.cjs +1 -1
  5. package/dist/bmg.cjs.map +1 -1
  6. package/dist/bmg.modern.js +1 -1
  7. package/dist/bmg.modern.js.map +1 -1
  8. package/dist/bmg.module.js +1 -1
  9. package/dist/bmg.module.js.map +1 -1
  10. package/dist/bmg.umd.js +1 -1
  11. package/dist/bmg.umd.js.map +1 -1
  12. package/dist/index.d.ts +27 -1
  13. package/dist/lib-definitions.d.ts +1 -0
  14. package/dist/{src/operators → operators}/_helpers.d.ts +142 -142
  15. package/dist/{src/operators → operators}/allbut.d.ts +2 -2
  16. package/dist/{src/operators → operators}/autowrap.d.ts +2 -2
  17. package/dist/{src/operators → operators}/constants.d.ts +2 -2
  18. package/dist/{src/operators → operators}/cross_product.d.ts +3 -3
  19. package/dist/{src/operators → operators}/exclude.d.ts +2 -2
  20. package/dist/{src/operators → operators}/extend.d.ts +2 -2
  21. package/dist/{src/src/operators → operators}/group.d.ts +2 -2
  22. package/dist/{src/operators → operators}/image.d.ts +2 -2
  23. package/dist/{src/operators → operators}/index.d.ts +30 -30
  24. package/dist/{src/src/operators → operators}/intersect.d.ts +2 -2
  25. package/dist/{src/src/operators → operators}/isEqual.d.ts +2 -2
  26. package/dist/{src/operators → operators}/isRelation.d.ts +1 -1
  27. package/dist/{src/operators → operators}/join.d.ts +2 -2
  28. package/dist/{src/operators → operators}/left_join.d.ts +2 -2
  29. package/dist/{src/src/operators → operators}/matching.d.ts +2 -2
  30. package/dist/{src/src/operators → operators}/minus.d.ts +2 -2
  31. package/dist/{src/src/operators → operators}/not_matching.d.ts +2 -2
  32. package/dist/{src/operators → operators}/one.d.ts +2 -2
  33. package/dist/{src/operators → operators}/prefix.d.ts +2 -2
  34. package/dist/{src/src/operators → operators}/project.d.ts +2 -2
  35. package/dist/{src/operators → operators}/rename.d.ts +2 -2
  36. package/dist/{src/operators → operators}/restrict.d.ts +2 -2
  37. package/dist/{src/operators → operators}/suffix.d.ts +2 -2
  38. package/dist/{src/operators → operators}/summarize.d.ts +2 -2
  39. package/dist/{src/operators → operators}/transform.d.ts +2 -2
  40. package/dist/{src/src/operators → operators}/ungroup.d.ts +2 -2
  41. package/dist/{src/operators → operators}/union.d.ts +2 -2
  42. package/dist/{src/operators → operators}/unwrap.d.ts +2 -2
  43. package/dist/{src/operators → operators}/where.d.ts +1 -1
  44. package/dist/{src/operators → operators}/wrap.d.ts +2 -2
  45. package/dist/{src/operators → operators}/yByX.d.ts +2 -2
  46. package/dist/{src/src/support → support}/toPredicateFunc.d.ts +2 -2
  47. package/dist/{src/src/types.d.ts → types.d.ts} +162 -101
  48. package/package.json +6 -4
  49. package/src/Relation/Memory.ts +13 -12
  50. package/src/index.ts +1 -1
  51. package/src/lib-definitions.ts +281 -0
  52. package/src/types.ts +142 -54
  53. package/dist/src/Relation/index.d.ts +0 -1
  54. package/dist/src/Relation.d.ts +0 -8
  55. package/dist/src/index.d.ts +0 -27
  56. package/dist/src/operators/group.d.ts +0 -2
  57. package/dist/src/operators/intersect.d.ts +0 -2
  58. package/dist/src/operators/isEqual.d.ts +0 -2
  59. package/dist/src/operators/matching.d.ts +0 -2
  60. package/dist/src/operators/minus.d.ts +0 -2
  61. package/dist/src/operators/not_matching.d.ts +0 -2
  62. package/dist/src/operators/project.d.ts +0 -2
  63. package/dist/src/operators/ungroup.d.ts +0 -2
  64. package/dist/src/src/Relation/Memory.d.ts +0 -46
  65. package/dist/src/src/index.d.ts +0 -27
  66. package/dist/src/src/operators/_helpers.d.ts +0 -142
  67. package/dist/src/src/operators/allbut.d.ts +0 -2
  68. package/dist/src/src/operators/autowrap.d.ts +0 -2
  69. package/dist/src/src/operators/constants.d.ts +0 -2
  70. package/dist/src/src/operators/cross_product.d.ts +0 -3
  71. package/dist/src/src/operators/exclude.d.ts +0 -2
  72. package/dist/src/src/operators/extend.d.ts +0 -2
  73. package/dist/src/src/operators/image.d.ts +0 -2
  74. package/dist/src/src/operators/index.d.ts +0 -30
  75. package/dist/src/src/operators/isRelation.d.ts +0 -1
  76. package/dist/src/src/operators/join.d.ts +0 -2
  77. package/dist/src/src/operators/left_join.d.ts +0 -2
  78. package/dist/src/src/operators/one.d.ts +0 -2
  79. package/dist/src/src/operators/prefix.d.ts +0 -2
  80. package/dist/src/src/operators/rename.d.ts +0 -2
  81. package/dist/src/src/operators/restrict.d.ts +0 -2
  82. package/dist/src/src/operators/suffix.d.ts +0 -2
  83. package/dist/src/src/operators/summarize.d.ts +0 -2
  84. package/dist/src/src/operators/transform.d.ts +0 -2
  85. package/dist/src/src/operators/union.d.ts +0 -2
  86. package/dist/src/src/operators/unwrap.d.ts +0 -2
  87. package/dist/src/src/operators/where.d.ts +0 -1
  88. package/dist/src/src/operators/wrap.d.ts +0 -2
  89. package/dist/src/src/operators/yByX.d.ts +0 -2
  90. package/dist/src/src/utility-types.d.ts +0 -43
  91. package/dist/src/support/toPredicateFunc.d.ts +0 -2
  92. package/dist/src/tests/bmg.test.d.ts +0 -1
  93. package/dist/src/tests/fixtures.d.ts +0 -6
  94. package/dist/src/tests/operators/allbut.test.d.ts +0 -1
  95. package/dist/src/tests/operators/autowrap.test.d.ts +0 -1
  96. package/dist/src/tests/operators/constants.test.d.ts +0 -1
  97. package/dist/src/tests/operators/cross_product.test.d.ts +0 -1
  98. package/dist/src/tests/operators/exclude.test.d.ts +0 -1
  99. package/dist/src/tests/operators/extend.test.d.ts +0 -1
  100. package/dist/src/tests/operators/group.test.d.ts +0 -1
  101. package/dist/src/tests/operators/image.test.d.ts +0 -1
  102. package/dist/src/tests/operators/intersect.test.d.ts +0 -1
  103. package/dist/src/tests/operators/isEqual.test.d.ts +0 -1
  104. package/dist/src/tests/operators/join.test.d.ts +0 -1
  105. package/dist/src/tests/operators/left_join.test.d.ts +0 -1
  106. package/dist/src/tests/operators/matching.test.d.ts +0 -1
  107. package/dist/src/tests/operators/minus.test.d.ts +0 -1
  108. package/dist/src/tests/operators/not_matching.test.d.ts +0 -1
  109. package/dist/src/tests/operators/one.test.d.ts +0 -1
  110. package/dist/src/tests/operators/prefix.test.d.ts +0 -1
  111. package/dist/src/tests/operators/project.test.d.ts +0 -1
  112. package/dist/src/tests/operators/rename.test.d.ts +0 -1
  113. package/dist/src/tests/operators/restrict.test.d.ts +0 -1
  114. package/dist/src/tests/operators/suffix.test.d.ts +0 -1
  115. package/dist/src/tests/operators/summarize.test.d.ts +0 -1
  116. package/dist/src/tests/operators/transform.test.d.ts +0 -1
  117. package/dist/src/tests/operators/ungroup.test.d.ts +0 -1
  118. package/dist/src/tests/operators/union.test.d.ts +0 -1
  119. package/dist/src/tests/operators/unwrap.test.d.ts +0 -1
  120. package/dist/src/tests/operators/where.test.d.ts +0 -1
  121. package/dist/src/tests/operators/wrap.test.d.ts +0 -1
  122. package/dist/src/tests/operators/yByX.test.d.ts +0 -1
  123. package/dist/src/tests/types/relation.test.d.ts +0 -1
  124. package/dist/src/types.d.ts +0 -101
  125. package/dist/src/utility-types.d.ts +0 -43
  126. package/dist/tests/bmg.test.d.ts +0 -1
  127. package/dist/tests/fixtures.d.ts +0 -6
  128. package/dist/tests/operators/allbut.test.d.ts +0 -1
  129. package/dist/tests/operators/autowrap.test.d.ts +0 -1
  130. package/dist/tests/operators/constants.test.d.ts +0 -1
  131. package/dist/tests/operators/cross_product.test.d.ts +0 -1
  132. package/dist/tests/operators/exclude.test.d.ts +0 -1
  133. package/dist/tests/operators/extend.test.d.ts +0 -1
  134. package/dist/tests/operators/group.test.d.ts +0 -1
  135. package/dist/tests/operators/image.test.d.ts +0 -1
  136. package/dist/tests/operators/intersect.test.d.ts +0 -1
  137. package/dist/tests/operators/isEqual.test.d.ts +0 -1
  138. package/dist/tests/operators/join.test.d.ts +0 -1
  139. package/dist/tests/operators/left_join.test.d.ts +0 -1
  140. package/dist/tests/operators/matching.test.d.ts +0 -1
  141. package/dist/tests/operators/minus.test.d.ts +0 -1
  142. package/dist/tests/operators/not_matching.test.d.ts +0 -1
  143. package/dist/tests/operators/one.test.d.ts +0 -1
  144. package/dist/tests/operators/prefix.test.d.ts +0 -1
  145. package/dist/tests/operators/project.test.d.ts +0 -1
  146. package/dist/tests/operators/rename.test.d.ts +0 -1
  147. package/dist/tests/operators/restrict.test.d.ts +0 -1
  148. package/dist/tests/operators/suffix.test.d.ts +0 -1
  149. package/dist/tests/operators/summarize.test.d.ts +0 -1
  150. package/dist/tests/operators/transform.test.d.ts +0 -1
  151. package/dist/tests/operators/ungroup.test.d.ts +0 -1
  152. package/dist/tests/operators/union.test.d.ts +0 -1
  153. package/dist/tests/operators/unwrap.test.d.ts +0 -1
  154. package/dist/tests/operators/where.test.d.ts +0 -1
  155. package/dist/tests/operators/wrap.test.d.ts +0 -1
  156. package/dist/tests/operators/yByX.test.d.ts +0 -1
  157. package/dist/tests/types/relation.test.d.ts +0 -1
  158. package/src/utility-types.ts +0 -77
@@ -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,2 +0,0 @@
1
- import { RelationOperand, AttrName } from "../types";
2
- export declare const allbut: (operand: RelationOperand, attrs: AttrName[]) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { AutowrapOptions, RelationOperand } from "../types";
2
- export declare const autowrap: (operand: RelationOperand, options?: AutowrapOptions) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Tuple } from "../types";
2
- export declare const constants: (operand: RelationOperand, consts: Tuple) => RelationOperand;
@@ -1,3 +0,0 @@
1
- import { RelationOperand } from "../types";
2
- export declare const cross_product: (left: RelationOperand, right: RelationOperand) => RelationOperand;
3
- export { cross_product as cross_join };
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Predicate } from "../types";
2
- export declare const exclude: (operand: RelationOperand, p: Predicate) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Extension } from "../types";
2
- export declare const extend: (operand: RelationOperand, extension: Extension) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, JoinKeys, AttrName } from "../types";
2
- export declare const image: (left: RelationOperand, right: RelationOperand, as: AttrName, keys?: JoinKeys) => RelationOperand;
@@ -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,2 +0,0 @@
1
- import { RelationOperand, JoinKeys } from "../types";
2
- export declare const join: (left: RelationOperand, right: RelationOperand, keys?: JoinKeys) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, JoinKeys } from "../types";
2
- export declare const left_join: (left: RelationOperand, right: RelationOperand, keys?: JoinKeys) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Tuple } from "../types";
2
- export declare const one: (operand: RelationOperand) => Tuple;
@@ -1,2 +0,0 @@
1
- import { PrefixOptions, RelationOperand } from "../types";
2
- export declare const prefix: (operand: RelationOperand, pfx: string, options?: PrefixOptions) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Renaming } from "../types";
2
- export declare const rename: (operand: RelationOperand, renaming: Renaming) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Predicate } from "../types";
2
- export declare const restrict: (operand: RelationOperand, p: Predicate) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, SuffixOptions } from "../types";
2
- export declare const suffix: (operand: RelationOperand, sfx: string, options?: SuffixOptions) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, AttrName, Aggregators } from "../types";
2
- export declare const summarize: (operand: RelationOperand, by: AttrName[], aggs: Aggregators) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, Transformation } from "../types";
2
- export declare const transform: (operand: RelationOperand, transformation: Transformation) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand } from "../types";
2
- export declare const union: (left: RelationOperand, right: RelationOperand) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { RelationOperand, AttrName } from "../types";
2
- export declare const unwrap: (operand: RelationOperand, attr: AttrName) => RelationOperand;
@@ -1 +0,0 @@
1
- export { restrict as where } from './restrict';
@@ -1,2 +0,0 @@
1
- import { RelationOperand, AttrName } from "../types";
2
- export declare const wrap: (operand: RelationOperand, attrs: AttrName[], as: AttrName) => RelationOperand;
@@ -1,2 +0,0 @@
1
- import { AttrName, RelationOperand, Tuple } from "../types";
2
- export declare const yByX: (operand: RelationOperand, y: AttrName, x: AttrName) => Tuple;
@@ -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,2 +0,0 @@
1
- import { Predicate, PredicateFunc } from '../types';
2
- export declare const toPredicateFunc: (p: Predicate) => PredicateFunc;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export declare const SUPPLIERS: import("../src/Relation").MemoryRelation<{
2
- sid: string;
3
- name: string;
4
- status: number;
5
- city: string;
6
- }>;
@@ -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,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
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export declare const SUPPLIERS: import("../src/Relation").MemoryRelation<{
2
- sid: string;
3
- name: string;
4
- status: number;
5
- city: string;
6
- }>;
@@ -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 {};