@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/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enspirit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
import type { AutowrapOptions,
|
|
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
|
-
}
|
|
1
|
+
import type { AutowrapOptions, Relation, RelationOperand, Transformation, Tuple, TypedPredicate, TypedExtension, RenameMap, Renamed, Prefixed, Suffixed, Joined, LeftJoined, Wrapped, Unwrapped, Ungrouped, AggregatorResults, TypedJoinKeysArray, TypedJoinKeysObject } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory implementation of the Relation interface.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).
|
|
6
|
+
*/
|
|
7
|
+
export declare class MemoryRelation<T = Tuple> implements Relation<T> {
|
|
8
|
+
private tuples;
|
|
9
|
+
constructor(tuples: T[]);
|
|
10
|
+
restrict(p: TypedPredicate<T>): Relation<T>;
|
|
11
|
+
where(p: TypedPredicate<T>): Relation<T>;
|
|
12
|
+
exclude(p: TypedPredicate<T>): Relation<T>;
|
|
13
|
+
project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>>;
|
|
14
|
+
allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>>;
|
|
15
|
+
extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E>;
|
|
16
|
+
constants<C extends Tuple>(consts: C): Relation<T & C>;
|
|
17
|
+
rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>>;
|
|
18
|
+
prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: {
|
|
19
|
+
except?: Ex[];
|
|
20
|
+
}): Relation<Prefixed<T, P, Ex>>;
|
|
21
|
+
suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: {
|
|
22
|
+
except?: Ex[];
|
|
23
|
+
}): Relation<Suffixed<T, S, Ex>>;
|
|
24
|
+
union(right: RelationOperand<T>): Relation<T>;
|
|
25
|
+
minus(right: RelationOperand<T>): Relation<T>;
|
|
26
|
+
intersect(right: RelationOperand<T>): Relation<T>;
|
|
27
|
+
matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>;
|
|
28
|
+
not_matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>;
|
|
29
|
+
join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<Joined<T, R>>;
|
|
30
|
+
left_join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<LeftJoined<T, R>>;
|
|
31
|
+
cross_product<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
32
|
+
cross_join<R>(right: RelationOperand<R>): Relation<T & R>;
|
|
33
|
+
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>>>>;
|
|
34
|
+
group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>;
|
|
35
|
+
ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>>;
|
|
36
|
+
wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>>;
|
|
37
|
+
unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>>;
|
|
38
|
+
summarize<By extends keyof T, Aggs extends Record<string, unknown>>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>>;
|
|
39
|
+
transform(t: Transformation): Relation<T>;
|
|
40
|
+
autowrap(options?: AutowrapOptions): Relation<Tuple>;
|
|
41
|
+
one(): T;
|
|
42
|
+
toArray(): T[];
|
|
43
|
+
yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>;
|
|
44
|
+
isEqual(right: any): boolean;
|
|
45
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Memory';
|
|
1
|
+
export * from './Memory';
|
package/dist/bmg.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,r){(null==r||r>t.length)&&(r=t.length);for(var n=0,e=Array(r);n<r;n++)e[n]=t[n];return e}function r(r,n){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,n){if(r){if("string"==typeof r)return t(r,n);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?t(r,n):void 0}}(r))||n&&r&&"number"==typeof r.length){e&&(r=e);var u=0;return function(){return u>=r.length?{done:!0}:{done:!1,value:r[u++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)({}).hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},n.apply(null,arguments)}var e=function(t){if("function"==typeof t)return t;var r=t;return function(t){return Object.keys(r).every(function(n){return t[n]===r[n]})}},u=/*#__PURE__*/function(){function t(t){this.tuples=void 0,this.tuples=t,this.tuples=t}var r=t.prototype;return r.restrict=function(t){return h(this,t)},r.where=function(t){return h(this,t)},r.exclude=function(t){return d(this,t)},r.project=function(t){return w(this,t)},r.allbut=function(t){return x(this,t)},r.extend=function(t){return j(this,t)},r.constants=function(t){return y(this,t)},r.rename=function(t){return g(this,t)},r.prefix=function(t,r){return m(this,t,r)},r.suffix=function(t,r){return b(this,t,r)},r.union=function(t){return O(this,t)},r.minus=function(t){return S(this,t)},r.intersect=function(t){return A(this,t)},r.matching=function(t,r){return N(this,t,r)},r.not_matching=function(t,r){return k(this,t,r)},r.join=function(t,r){return M(this,t,r)},r.left_join=function(t,r){return z(this,t,r)},r.cross_product=function(t){return J(this,t)},r.cross_join=function(t){return J(this,t)},r.image=function(t,r,n){return B(this,t,r,n)},r.group=function(t,r){return P(this,t,r)},r.ungroup=function(t){return V(this,t)},r.wrap=function(t,r){return $(this,t,r)},r.unwrap=function(t){return D(this,t)},r.summarize=function(t,r){return q(this,t,r)},r.transform=function(t){return G(this,t)},r.autowrap=function(t){return F(this,t)},r.one=function(){return L(this)},r.toArray=function(){return this.tuples},r.yByX=function(t,r){return Q(this,t,r)},r.isEqual=function(t){return K(this,t)},t}(),o=function(t){return null!=t&&t.constructor===u},a=function(t){var r=Object.entries(t).map(function(t){return[t[0],(r=t[1],o(r)?r.toArray().map(function(t){return a(t)}).sort():r)];var r});return JSON.stringify(r.sort(function(t,r){return t[0].localeCompare(r[0])}))},i=function(t){for(var n,e=new Set,u=[],o=r(t);!(n=o()).done;){var i=n.value,s=a(i);e.has(s)||(e.add(s),u.push(i))}return u},s=function(t){if(Array.isArray(t))return{tuples:function(){return t},output:function(t){return t}};if(o(t))return{tuples:function(){return t.toArray()},output:function(t){return new u(t)}};throw"Unable to iterate "+t},c=function(t){throw t},f=function(t,r,n){return t?Array.isArray(t)?t.reduce(function(t,r){return t[r]=r,t},{}):t:function(t,r){if(0===t.length||0===r.length)return[];var n=new Set(Object.keys(t[0]));return Object.keys(r[0]).filter(function(t){return n.has(t)})}(r,n).reduce(function(t,r){return t[r]=r,t},{})},l=function(t,r,n){for(var e=0,u=Object.entries(n);e<u.length;e++){var o=u[e];if(t[o[0]]!==r[o[1]])return!1}return!0},p=function(t,r,n){return("left"===n?Object.keys(r):Object.values(r)).map(function(r){return JSON.stringify(t[r])}).join("|")},v=function(t,r){for(var n=new Set(Object.values(r)),e={},u=0,o=Object.entries(t);u<o.length;u++){var a=o[u],i=a[0],s=a[1];n.has(i)||(e[i]=s)}return e},h=function(t,n){for(var u,o=s(t),a=o.tuples(),i=e(n),c=[],f=r(a);!(u=f()).done;){var l=u.value;i(l)&&c.push(l)}return o.output(c)},d=function(t,n){for(var u,o=s(t),a=o.tuples(),i=e(n),c=[],f=r(a);!(u=f()).done;){var l=u.value;i(l)||c.push(l)}return o.output(c)},y=function(t,e){for(var u,o=s(t),a=[],i=r(o.tuples());!(u=i()).done;)a.push(n({},u.value,e));return o.output(a)},g=function(t,n){for(var e,u=s(t),o=u.tuples(),a=function(t){return"function"==typeof t?t:function(r){return t[r]||r}}(n),i=[],c=function(){var t=e.value,r=Object.keys(t).reduce(function(r,n){return r[a(n)]=t[n],r},{});i.push(r)},f=r(o);!(e=f()).done;)c();return u.output(i)},m=function(t,r,n){var e,u=new Set(null!=(e=null==n?void 0:n.except)?e:[]);return g(t,function(t){return u.has(t)?t:""+r+t})},b=function(t,r,n){var e,u=new Set(null!=(e=null==n?void 0:n.except)?e:[]);return g(t,function(t){return u.has(t)?t:""+t+r})},w=function(t,n){for(var e,u=s(t),o=u.tuples(),a=[],c=function(){var t=e.value,r=n.reduce(function(r,n){return n in t&&(r[n]=t[n]),r},{});a.push(r)},f=r(o);!(e=f()).done;)c();return u.output(i(a))},x=function(t,n){for(var e,u=s(t),o=u.tuples(),a=new Set(n),c=[],f=function(){var t=e.value,r=Object.keys(t).reduce(function(r,n){return a.has(n)||(r[n]=t[n]),r},{});c.push(r)},l=r(o);!(e=l()).done;)f();return u.output(i(c))},j=function(t,e){for(var u,o=s(t),a=[],i=r(o.tuples());!(u=i()).done;){for(var c=u.value,f=n({},c),l=0,p=Object.entries(e);l<p.length;l++){var v=p[l],h=v[1];f[v[0]]="function"==typeof h?h(c):c[h]}a.push(f)}return o.output(a)},O=function(t,n){for(var e,u=s(t),o=s(n),i=new Set,c=[],f=r(u.tuples());!(e=f()).done;){var l=e.value,p=a(l);i.has(p)||(i.add(p),c.push(l))}for(var v,h=r(o.tuples());!(v=h()).done;){var d=v.value,y=a(d);i.has(y)||(i.add(y),c.push(d))}return u.output(c)},S=function(t,n){for(var e,u=s(t),o=s(n),i=new Set,c=r(o.tuples());!(e=c()).done;)i.add(a(e.value));for(var f,l=new Set,p=[],v=r(u.tuples());!(f=v()).done;){var h=f.value,d=a(h);i.has(d)||l.has(d)||(l.add(d),p.push(h))}return u.output(p)},A=function(t,n){for(var e,u=s(t),o=s(n),i=new Set,c=r(o.tuples());!(e=c()).done;)i.add(a(e.value));for(var f,l=new Set,p=[],v=r(u.tuples());!(f=v()).done;){var h=f.value,d=a(h);i.has(d)&&!l.has(d)&&(l.add(d),p.push(h))}return u.output(p)},N=function(t,n,e){for(var u,o=s(t),a=s(n),i=[].concat(o.tuples()),c=[].concat(a.tuples()),l=f(e,i,c),v=new Set,h=r(c);!(u=h()).done;)v.add(p(u.value,l,"right"));for(var d,y=[],g=r(i);!(d=g()).done;){var m=d.value;v.has(p(m,l,"left"))&&y.push(m)}return o.output(y)},k=function(t,n,e){for(var u,o=s(t),a=s(n),i=[].concat(o.tuples()),c=[].concat(a.tuples()),l=f(e,i,c),v=new Set,h=r(c);!(u=h()).done;)v.add(p(u.value,l,"right"));for(var d,y=[],g=r(i);!(d=g()).done;){var m=d.value;v.has(p(m,l,"left"))||y.push(m)}return o.output(y)},_=function(t,r,e){return n({},t,v(r,e))},M=function(t,n,e){for(var u,o=s(t),a=s(n),i=[].concat(o.tuples()),c=[].concat(a.tuples()),p=f(e,i,c),v=[],h=r(i);!(u=h()).done;)for(var d,y=u.value,g=r(c);!(d=g()).done;){var m=d.value;l(y,m,p)&&v.push(_(y,m,p))}return o.output(v)},E=function(t,e,u){for(var o,a=n({},t),i=r(u);!(o=i()).done;){var s=o.value;a[s]=e?e[s]:null}return a},z=function(t,n,e){for(var u,o=s(t),a=s(n),i=[].concat(o.tuples()),c=[].concat(a.tuples()),p=f(e,i,c),v=function(t,r){if(0===t.length)return[];var n=new Set(Object.values(r));return Object.keys(t[0]).filter(function(t){return!n.has(t)})}(c,p),h=[],d=r(i);!(u=d()).done;){for(var y,g=u.value,m=!1,b=r(c);!(y=b()).done;){var w=y.value;l(g,w,p)&&(h.push(E(g,w,v)),m=!0)}m||h.push(E(g,null,v))}return o.output(h)},J=function(t,e){for(var u,o=s(t),a=s(e),c=[].concat(o.tuples()),f=[].concat(a.tuples()),l=[],p=r(c);!(u=p()).done;)for(var v,h=u.value,d=r(f);!(v=d()).done;)l.push(n({},v.value,h));return o.output(i(l))},B=function(t,e,o,a){for(var i,c=s(t),p=s(e),h=[].concat(c.tuples()),d=[].concat(p.tuples()),y=f(a,h,d),g=[],m=r(h);!(i=m()).done;){for(var b,w,x=i.value,j=[],O=r(d);!(w=O()).done;){var S=w.value;l(x,S,y)&&j.push(v(S,y))}g.push(n({},x,((b={})[o]=new u(j),b)))}return c.output(g)},I=function(t,r){return r.map(function(r){return JSON.stringify(t[r])}).join("|")},R=function(t,r){return r.reduce(function(r,n){return r[n]=t[n],r},{})},U=function(t,r){if("function"==typeof r)return r(t);var n="string"==typeof r?{op:r,attr:""}:r,e=n.op,u=n.attr;switch(e){case"count":return t.length;case"sum":return t.reduce(function(t,r){return t+(Number(r[u])||0)},0);case"min":var o=t.map(function(t){return t[u]}).filter(function(t){return null!=t});return o.length>0?Math.min.apply(Math,o.map(Number)):null;case"max":var a=t.map(function(t){return t[u]}).filter(function(t){return null!=t});return a.length>0?Math.max.apply(Math,a.map(Number)):null;case"avg":var i=t.map(function(t){return Number(t[u])}).filter(function(t){return!isNaN(t)});return i.length>0?i.reduce(function(t,r){return t+r},0)/i.length:null;case"collect":return t.map(function(t){return t[u]});default:throw new Error("Unknown aggregator: "+e)}},q=function(t,n,e){for(var u,o=s(t),a=[].concat(o.tuples()),i=new Map,c=r(a);!(u=c()).done;){var f=u.value,l=I(f,n);i.has(l)||i.set(l,[]),i.get(l).push(f)}for(var p,v=[],h=r(i.values());!(p=h()).done;){for(var d=p.value,y=R(d[0],n),g=0,m=Object.entries(e);g<m.length;g++){var b=m[g];y[b[0]]=U(d,b[1])}v.push(y)}return o.output(v)},C=function(t,r){return r.map(function(r){return JSON.stringify(t[r])}).join("|")},X=function(t,r){return r.reduce(function(r,n){return r[n]=t[n],r},{})},P=function(t,e,o){var a=s(t),i=[].concat(a.tuples());if(0===i.length)return a.output([]);for(var c,f=Object.keys(i[0]),l=new Set(e),p=f.filter(function(t){return!l.has(t)}),v=new Map,h=r(i);!(c=h()).done;){var d=c.value,y=C(d,p);v.has(y)||v.set(y,{base:X(d,p),nested:[]}),v.get(y).nested.push(X(d,e))}for(var g,m=[],b=r(v.values());!(g=b()).done;){var w,x=g.value;m.push(n({},x.base,((w={})[o]=new u(x.nested),w)))}return a.output(m)},T=function(t){if(o(t))return t.toArray();if(Array.isArray(t))return t;throw new Error("Value is not a relation or array")},V=function(t,e){for(var u,o=s(t),a=[],i=r([].concat(o.tuples()));!(u=i()).done;){for(var c=u.value,f=T(c[e]),l={},p=0,v=Object.entries(c);p<v.length;p++){var h=v[p],d=h[0];d!==e&&(l[d]=h[1])}for(var y,g=r(f);!(y=g()).done;)a.push(n({},l,y.value))}return o.output(a)},$=function(t,e,u){for(var o,a=s(t),i=a.tuples(),c=new Set(e),f=[],l=r(i);!(o=l()).done;){for(var p,v={},h={},d=0,y=Object.entries(o.value);d<y.length;d++){var g=y[d],m=g[0],b=g[1];c.has(m)?v[m]=b:h[m]=b}f.push(n({},h,((p={})[u]=v,p)))}return a.output(f)},D=function(t,e){for(var u,o=s(t),a=[],i=r(o.tuples());!(u=i()).done;){var c=u.value,f=c[e];if("object"!=typeof f||null===f||Array.isArray(f))throw new Error("Attribute '"+e+"' is not a tuple (object)");for(var l={},p=0,v=Object.entries(c);p<v.length;p++){var h=v[p],d=h[0];d!==e&&(l[d]=h[1])}a.push(n({},l,f))}return o.output(a)},F=function(n,e){for(var u,o,a=null!=(u=null==e?void 0:e.separator)?u:"_",i=s(n),c=[],f=r(i.tuples());!(o=f()).done;){for(var l={},p=0,v=Object.entries(o.value);p<v.length;p++){var h=v[p],d=h[0],y=h[1],g=d.split(a);if(1===g.length)l[d]=y;else{var m,b=g[0],w=t(g).slice(1);l[b]=null!=(m=l[b])?m:{},l[b][w.join(a)]=y}}c.push(l)}return i.output(c)},G=function(t,n){for(var e,u=s(t),o=[],a=r(u.tuples());!(e=a()).done;){for(var i={},c=0,f=Object.entries(e.value);c<f.length;c++){var l=f[c],p=l[0];i[p]=H(l[1],p,n)}o.push(i)}return u.output(o)},H=function(t,r,n){if("function"==typeof n)return n(t);if(Array.isArray(n))return n.reduce(function(t,r){return r(t)},t);var e=n[r];return e?Array.isArray(e)?e.reduce(function(t,r){return r(t)},t):e(t):t},K=function(t,n){for(var e,u=s(t),o=s(n),i=new Set,c=r(u.tuples());!(e=c()).done;)i.add(a(e.value));for(var f,l=new Set,p=r(o.tuples());!(f=p()).done;)l.add(a(f.value));if(i.size!==l.size)return!1;for(var v,h=r(i);!(v=h()).done;)if(!l.has(v.value))return!1;return!0},L=function(t){for(var n,e,u=r(s(t).tuples());!(e=u()).done;){var o=e.value;if(n)return c("More than one tuple found");n=o}return n||c("Relation is empty")},Q=function(t,n,e){for(var u,o={},a=r(s(t).tuples());!(u=a()).done;){var i=u.value;o[""+i[e]]=i[n]}return o};function W(t){return new u(t)}W.isRelation=o,exports.Bmg=W,exports.allbut=x,exports.autowrap=F,exports.constants=y,exports.cross_join=J,exports.cross_product=J,exports.exclude=d,exports.extend=j,exports.group=P,exports.image=B,exports.intersect=A,exports.isEqual=K,exports.isRelation=o,exports.join=M,exports.left_join=z,exports.matching=N,exports.minus=S,exports.not_matching=k,exports.one=L,exports.prefix=m,exports.project=w,exports.rename=g,exports.restrict=h,exports.suffix=b,exports.summarize=q,exports.transform=G,exports.ungroup=V,exports.union=O,exports.unwrap=D,exports.where=h,exports.wrap=$,exports.yByX=Q;
|
|
1
|
+
function n(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=Array(e);t<e;t++)r[t]=n[t];return r}function e(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(){return t=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},t.apply(null,arguments)}var r=function(n){if("function"==typeof n)return n;var e=n;return function(n){return Object.keys(e).every(function(t){return n[t]===e[t]})}},o=/*#__PURE__*/function(){function n(n){this.tuples=void 0,this.tuples=n,this.tuples=n}var e=n.prototype;return e.restrict=function(n){return y(this,n)},e.where=function(n){return y(this,n)},e.exclude=function(n){return g(this,n)},e.project=function(n){return R(this,n)},e.allbut=function(n){return x(this,n)},e.extend=function(n){return A(this,n)},e.constants=function(n){return m(this,n)},e.rename=function(n){return v(this,n)},e.prefix=function(n,e){return T(this,n,e)},e.suffix=function(n,e){return h(this,n,e)},e.union=function(n){return b(this,n)},e.minus=function(n){return w(this,n)},e.intersect=function(n){return k(this,n)},e.matching=function(n,e){return K(this,n,e)},e.not_matching=function(n,e){return O(this,n,e)},e.join=function(n,e){return S(this,n,e)},e.left_join=function(n,e){return N(this,n,e)},e.cross_product=function(n){return P(this,n)},e.cross_join=function(n){return P(this,n)},e.image=function(n,e,t){return J(this,n,e,t)},e.group=function(n,e){return U(this,n,e)},e.ungroup=function(n){return X(this,n)},e.wrap=function(n,e){return q(this,n,e)},e.unwrap=function(n){return z(this,n)},e.summarize=function(n,e){return _(this,n,e)},e.transform=function(n){return $(this,n)},e.autowrap=function(n){return D(this,n)},e.one=function(){return Y(this)},e.toArray=function(){return this.tuples},e.yByX=function(n,e){return V(this,n,e)},e.isEqual=function(n){return W(this,n)},n}(),u=function(n){return null!=n&&n.constructor===o},a=function(n){var e=Object.entries(n).map(function(n){return[n[0],(e=n[1],u(e)?e.toArray().map(function(n){return a(n)}).sort():e)];var e});return JSON.stringify(e.sort(function(n,e){return n[0].localeCompare(e[0])}))},i=function(n){for(var t,r=new Set,o=[],u=e(n);!(t=u()).done;){var i=t.value,s=a(i);r.has(s)||(r.add(s),o.push(i))}return o},s=function(n){if(Array.isArray(n))return{tuples:function(){return n},output:function(n){return n}};if(u(n))return{tuples:function(){return n.toArray()},output:function(n){return new o(n)}};throw"Unable to iterate "+n},p=function(n){throw n},c=function(n,e,t){return n?Array.isArray(n)?n.reduce(function(n,e){return n[e]=e,n},{}):n:function(n,e){if(0===n.length||0===e.length)return[];var t=new Set(Object.keys(n[0]));return Object.keys(e[0]).filter(function(n){return t.has(n)})}(e,t).reduce(function(n,e){return n[e]=e,n},{})},l=function(n,e,t){for(var r=0,o=Object.entries(t);r<o.length;r++){var u=o[r];if(n[u[0]]!==e[u[1]])return!1}return!0},f=function(n,e,t){return("left"===t?Object.keys(e):Object.values(e)).map(function(e){return JSON.stringify(n[e])}).join("|")},d=function(n,e){for(var t=new Set(Object.values(e)),r={},o=0,u=Object.entries(n);o<u.length;o++){var a=u[o],i=a[0],s=a[1];t.has(i)||(r[i]=s)}return r},y=function(n,t){for(var o,u=s(n),a=u.tuples(),i=r(t),p=[],c=e(a);!(o=c()).done;){var l=o.value;i(l)&&p.push(l)}return u.output(p)},g=function(n,t){for(var o,u=s(n),a=u.tuples(),i=r(t),p=[],c=e(a);!(o=c()).done;){var l=o.value;i(l)||p.push(l)}return u.output(p)},m=function(n,r){for(var o,u=s(n),a=[],i=e(u.tuples());!(o=i()).done;)a.push(t({},o.value,r));return u.output(a)},v=function(n,t){for(var r,o=s(n),u=o.tuples(),a=function(n){return"function"==typeof n?n:function(e){return n[e]||e}}(t),i=[],p=function(){var n=r.value,e=Object.keys(n).reduce(function(e,t){return e[a(t)]=n[t],e},{});i.push(e)},c=e(u);!(r=c()).done;)p();return o.output(i)},T=function(n,e,t){var r,o=new Set(null!=(r=null==t?void 0:t.except)?r:[]);return v(n,function(n){return o.has(n)?n:""+e+n})},h=function(n,e,t){var r,o=new Set(null!=(r=null==t?void 0:t.except)?r:[]);return v(n,function(n){return o.has(n)?n:""+n+e})},R=function(n,t){for(var r,o=s(n),u=o.tuples(),a=[],p=function(){var n=r.value,e=t.reduce(function(e,t){return t in n&&(e[t]=n[t]),e},{});a.push(e)},c=e(u);!(r=c()).done;)p();return o.output(i(a))},x=function(n,t){for(var r,o=s(n),u=o.tuples(),a=new Set(t),p=[],c=function(){var n=r.value,e=Object.keys(n).reduce(function(e,t){return a.has(t)||(e[t]=n[t]),e},{});p.push(e)},l=e(u);!(r=l()).done;)c();return o.output(i(p))},A=function(n,r){for(var o,u=s(n),a=[],i=e(u.tuples());!(o=i()).done;){for(var p=o.value,c=t({},p),l=0,f=Object.entries(r);l<f.length;l++){var d=f[l],y=d[1];c[d[0]]="function"==typeof y?y(p):p[y]}a.push(c)}return u.output(a)},b=function(n,t){for(var r,o=s(n),u=s(t),i=new Set,p=[],c=e(o.tuples());!(r=c()).done;){var l=r.value,f=a(l);i.has(f)||(i.add(f),p.push(l))}for(var d,y=e(u.tuples());!(d=y()).done;){var g=d.value,m=a(g);i.has(m)||(i.add(m),p.push(g))}return o.output(p)},w=function(n,t){for(var r,o=s(n),u=s(t),i=new Set,p=e(u.tuples());!(r=p()).done;)i.add(a(r.value));for(var c,l=new Set,f=[],d=e(o.tuples());!(c=d()).done;){var y=c.value,g=a(y);i.has(g)||l.has(g)||(l.add(g),f.push(y))}return o.output(f)},k=function(n,t){for(var r,o=s(n),u=s(t),i=new Set,p=e(u.tuples());!(r=p()).done;)i.add(a(r.value));for(var c,l=new Set,f=[],d=e(o.tuples());!(c=d()).done;){var y=c.value,g=a(y);i.has(g)&&!l.has(g)&&(l.add(g),f.push(y))}return o.output(f)},K=function(n,t,r){for(var o,u=s(n),a=s(t),i=[].concat(u.tuples()),p=[].concat(a.tuples()),l=c(r,i,p),d=new Set,y=e(p);!(o=y()).done;)d.add(f(o.value,l,"right"));for(var g,m=[],v=e(i);!(g=v()).done;){var T=g.value;d.has(f(T,l,"left"))&&m.push(T)}return u.output(m)},O=function(n,t,r){for(var o,u=s(n),a=s(t),i=[].concat(u.tuples()),p=[].concat(a.tuples()),l=c(r,i,p),d=new Set,y=e(p);!(o=y()).done;)d.add(f(o.value,l,"right"));for(var g,m=[],v=e(i);!(g=v()).done;){var T=g.value;d.has(f(T,l,"left"))||m.push(T)}return u.output(m)},j=function(n,e,r){return t({},n,d(e,r))},S=function(n,t,r){for(var o,u=s(n),a=s(t),i=[].concat(u.tuples()),p=[].concat(a.tuples()),f=c(r,i,p),d=[],y=e(i);!(o=y()).done;)for(var g,m=o.value,v=e(p);!(g=v()).done;){var T=g.value;l(m,T,f)&&d.push(j(m,T,f))}return u.output(d)},E=function(n,r,o){for(var u,a=t({},n),i=e(o);!(u=i()).done;){var s=u.value;a[s]=r?r[s]:null}return a},N=function(n,t,r){for(var o,u=s(n),a=s(t),i=[].concat(u.tuples()),p=[].concat(a.tuples()),f=c(r,i,p),d=function(n,e){if(0===n.length)return[];var t=new Set(Object.values(e));return Object.keys(n[0]).filter(function(n){return!t.has(n)})}(p,f),y=[],g=e(i);!(o=g()).done;){for(var m,v=o.value,T=!1,h=e(p);!(m=h()).done;){var R=m.value;l(v,R,f)&&(y.push(E(v,R,d)),T=!0)}T||y.push(E(v,null,d))}return u.output(y)},P=function(n,r){for(var o,u=s(n),a=s(r),p=[].concat(u.tuples()),c=[].concat(a.tuples()),l=[],f=e(p);!(o=f()).done;)for(var d,y=o.value,g=e(c);!(d=g()).done;)l.push(t({},d.value,y));return u.output(i(l))},J=function(n,r,u,a){for(var i,p=s(n),f=s(r),y=[].concat(p.tuples()),g=[].concat(f.tuples()),m=c(a,y,g),v=[],T=e(y);!(i=T()).done;){for(var h,R,x=i.value,A=[],b=e(g);!(R=b()).done;){var w=R.value;l(x,w,m)&&A.push(d(w,m))}v.push(t({},x,((h={})[u]=new o(A),h)))}return p.output(v)},L=function(n,e){return e.map(function(e){return JSON.stringify(n[e])}).join("|")},F=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},B=function(n,e){if("function"==typeof e)return e(n);var t="string"==typeof e?{op:e,attr:""}:e,r=t.op,o=t.attr;switch(r){case"count":return n.length;case"sum":return n.reduce(function(n,e){return n+(Number(e[o])||0)},0);case"min":var u=n.map(function(n){return n[o]}).filter(function(n){return null!=n});return u.length>0?Math.min.apply(Math,u.map(Number)):null;case"max":var a=n.map(function(n){return n[o]}).filter(function(n){return null!=n});return a.length>0?Math.max.apply(Math,a.map(Number)):null;case"avg":var i=n.map(function(n){return Number(n[o])}).filter(function(n){return!isNaN(n)});return i.length>0?i.reduce(function(n,e){return n+e},0)/i.length:null;case"collect":return n.map(function(n){return n[o]});default:throw new Error("Unknown aggregator: "+r)}},_=function(n,t,r){for(var o,u=s(n),a=[].concat(u.tuples()),i=new Map,p=e(a);!(o=p()).done;){var c=o.value,l=L(c,t);i.has(l)||i.set(l,[]),i.get(l).push(c)}for(var f,d=[],y=e(i.values());!(f=y()).done;){for(var g=f.value,m=F(g[0],t),v=0,T=Object.entries(r);v<T.length;v++){var h=T[v];m[h[0]]=B(g,h[1])}d.push(m)}return u.output(d)},M=function(n,e){return e.map(function(e){return JSON.stringify(n[e])}).join("|")},I=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},U=function(n,r,u){var a=s(n),i=[].concat(a.tuples());if(0===i.length)return a.output([]);for(var p,c=Object.keys(i[0]),l=new Set(r),f=c.filter(function(n){return!l.has(n)}),d=new Map,y=e(i);!(p=y()).done;){var g=p.value,m=M(g,f);d.has(m)||d.set(m,{base:I(g,f),nested:[]}),d.get(m).nested.push(I(g,r))}for(var v,T=[],h=e(d.values());!(v=h()).done;){var R,x=v.value;T.push(t({},x.base,((R={})[u]=new o(x.nested),R)))}return a.output(T)},C=function(n){if(u(n))return n.toArray();if(Array.isArray(n))return n;throw new Error("Value is not a relation or array")},X=function(n,r){for(var o,u=s(n),a=[],i=e([].concat(u.tuples()));!(o=i()).done;){for(var p=o.value,c=C(p[r]),l={},f=0,d=Object.entries(p);f<d.length;f++){var y=d[f],g=y[0];g!==r&&(l[g]=y[1])}for(var m,v=e(c);!(m=v()).done;)a.push(t({},l,m.value))}return u.output(a)},q=function(n,r,o){for(var u,a=s(n),i=a.tuples(),p=new Set(r),c=[],l=e(i);!(u=l()).done;){for(var f,d={},y={},g=0,m=Object.entries(u.value);g<m.length;g++){var v=m[g],T=v[0],h=v[1];p.has(T)?d[T]=h:y[T]=h}c.push(t({},y,((f={})[o]=d,f)))}return a.output(c)},z=function(n,r){for(var o,u=s(n),a=[],i=e(u.tuples());!(o=i()).done;){var p=o.value,c=p[r];if("object"!=typeof c||null===c||Array.isArray(c))throw new Error("Attribute '"+r+"' is not a tuple (object)");for(var l={},f=0,d=Object.entries(p);f<d.length;f++){var y=d[f],g=y[0];g!==r&&(l[g]=y[1])}a.push(t({},l,c))}return u.output(a)},D=function(t,r){for(var o,u,a=null!=(o=null==r?void 0:r.separator)?o:"_",i=s(t),p=[],c=e(i.tuples());!(u=c()).done;){for(var l={},f=0,d=Object.entries(u.value);f<d.length;f++){var y=d[f],g=y[0],m=y[1],v=g.split(a);if(1===v.length)l[g]=m;else{var T,h=v[0],R=n(v).slice(1);l[h]=null!=(T=l[h])?T:{},l[h][R.join(a)]=m}}p.push(l)}return i.output(p)},$=function(n,t){for(var r,o=s(n),u=[],a=e(o.tuples());!(r=a()).done;){for(var i={},p=0,c=Object.entries(r.value);p<c.length;p++){var l=c[p],f=l[0];i[f]=H(l[1],f,t)}u.push(i)}return o.output(u)},H=function(n,e,t){if("function"==typeof t)return t(n);if(Array.isArray(t))return t.reduce(function(n,e){return e(n)},n);var r=t[e];return r?Array.isArray(r)?r.reduce(function(n,e){return e(n)},n):r(n):n},W=function(n,t){for(var r,o=s(n),u=s(t),i=new Set,p=e(o.tuples());!(r=p()).done;)i.add(a(r.value));for(var c,l=new Set,f=e(u.tuples());!(c=f()).done;)l.add(a(c.value));if(i.size!==l.size)return!1;for(var d,y=e(i);!(d=y()).done;)if(!l.has(d.value))return!1;return!0},Y=function(n){for(var t,r,o=e(s(n).tuples());!(r=o()).done;){var u=r.value;if(t)return p("More than one tuple found");t=u}return t||p("Relation is empty")},V=function(n,t,r){for(var o,u={},a=e(s(n).tuples());!(o=a()).done;){var i=o.value;u[""+i[r]]=i[t]}return u};function G(n){return new o(n)}G.isRelation=u,exports.Bmg=G,exports.LIB_DEFINITIONS="\n/**\n * Type definitions for Bmg.js relational algebra library.\n *\n * This file defines all types needed for type-safe relational operations:\n * - Base types (AttrName, Tuple)\n * - Utility types for transformations (Renamed, Prefixed, Joined, etc.)\n * - The Relation interface with all operators\n * - Helper types for predicates, extensions, aggregators, etc.\n */\n\n// ============================================================================\n// Base Types\n// ============================================================================\n\n/** Attribute name in a tuple */\ntype AttrName = string\n\n/** A tuple is a record mapping attribute names to values */\ntype Tuple = Record<AttrName, unknown>\n\n// ============================================================================\n// Rename Types\n// ============================================================================\n\n/** Map from old attribute names to new attribute names */\ntype RenameMap<T> = { [K in keyof T]?: string };\n\n/** Transform tuple type by renaming keys according to RenameMap */\ntype Renamed<T, R extends RenameMap<T>> = {\n [K in keyof T as K extends keyof R ? (R[K] extends string ? R[K] : K) : K]: T[K];\n};\n\n// ============================================================================\n// Prefix/Suffix Types\n// ============================================================================\n\n/** Prefix all keys except those in Except */\ntype Prefixed<T, P extends string, Except extends keyof T = never> = {\n [K in keyof T as K extends Except ? K : `${P}${K & string}`]: T[K];\n};\n\n/** Suffix all keys except those in Except */\ntype Suffixed<T, S extends string, Except extends keyof T = never> = {\n [K in keyof T as K extends Except ? K : `${K & string}${S}`]: T[K];\n};\n\n// ============================================================================\n// Join Types\n// ============================================================================\n\n/** Extract common keys between two tuple types */\ntype CommonKeys<L, R> = Extract<keyof L, keyof R>;\n\n/** Result of inner join: L & R with R's common keys removed */\ntype Joined<L, R> = L & Omit<R, CommonKeys<L, R>>;\n\n/** Result of left join: L & optional R attributes (common keys removed) */\ntype LeftJoined<L, R> = L & Partial<Omit<R, CommonKeys<L, R>>>;\n\n/**\n * Typed join keys for array form: keys must exist on BOTH operands.\n * Example: suppliers.join(parts, ['city']) - 'city' must be a key of both.\n */\ntype TypedJoinKeysArray<L, R> = (keyof L & keyof R & string)[];\n\n/**\n * Typed join keys for object form: maps left keys to right keys.\n * Example: suppliers.join(parts, { sid: 'supplier_id' })\n * - Left key (sid) must exist on L\n * - Right key (supplier_id) must exist on R\n */\ntype TypedJoinKeysObject<L, R> = { [K in keyof L & string]?: keyof R & string };\n\n// ============================================================================\n// Wrap/Unwrap Types\n// ============================================================================\n\n/** Result of wrap: remove wrapped attrs, add nested object */\ntype Wrapped<T, K extends keyof T, As extends string> =\n Omit<T, K> & Record<As, Pick<T, K>>;\n\n/** Result of unwrap: remove object attr, spread its properties */\ntype Unwrapped<T, K extends keyof T> =\n T[K] extends Record<string, unknown> ? Omit<T, K> & T[K] : Omit<T, K>;\n\n/** Result of ungroup: remove relation attr, flatten its tuple type */\ntype Ungrouped<T, K extends keyof T> =\n T[K] extends Relation<infer N> ? Omit<T, K> & N : Omit<T, K>;\n\n// ============================================================================\n// Aggregator Types\n// ============================================================================\n\ntype AggregatorName = 'count' | 'sum' | 'min' | 'max' | 'avg' | 'collect'\ntype AggregatorSpec = { op: AggregatorName, attr: AttrName }\ntype AggregatorFunc = (tuples: Tuple[]) => unknown\ntype Aggregator = AggregatorName | AggregatorSpec | AggregatorFunc\ntype Aggregators = Record<AttrName, Aggregator>\n\n/** Infer result type from aggregator specification */\ntype AggregatorResult<A> =\n A extends 'count' ? number :\n A extends { op: 'count' } ? number :\n A extends { op: 'sum' | 'avg' | 'min' | 'max' } ? number | null :\n A extends { op: 'collect' } ? unknown[] :\n A extends (tuples: Tuple[]) => infer R ? R :\n unknown;\n\n/** Map aggregator definitions to their result types */\ntype AggregatorResults<Aggs extends Record<string, unknown>> = {\n [K in keyof Aggs]: AggregatorResult<Aggs[K]>;\n};\n\n// ============================================================================\n// Predicate Types\n// ============================================================================\n\n/** Predicate function that receives a typed tuple */\ntype TypedPredicateFunc<T> = (t: T) => boolean\n\n/** Predicate: either a partial tuple for equality matching, or a function */\ntype TypedPredicate<T> = Partial<T> | TypedPredicateFunc<T>\n\n// Legacy predicate types (for backwards compatibility with standalone operators)\ntype PredicateFunc = ((t: Tuple) => any)\ntype Predicate = Tuple | PredicateFunc\n\n// ============================================================================\n// Extension Types\n// ============================================================================\n\n/** Extension function that receives a typed tuple */\ntype TypedExtensionFunc<T, R> = (tuple: T) => R\n\n/** Extension definition: function returning value, or attribute name to copy */\ntype TypedExtension<T, E extends Record<string, unknown>> = {\n [K in keyof E]: TypedExtensionFunc<T, E[K]> | keyof T;\n}\n\ntype ExtensionFunc = (tuple: Tuple) => unknown\ntype Extension = Record<AttrName, ExtensionFunc | AttrName>\n\n// ============================================================================\n// Other Helper Types\n// ============================================================================\n\ninterface PrefixOptions {\n except?: AttrName[]\n}\n\ninterface SuffixOptions {\n except?: AttrName[]\n}\n\ninterface AutowrapOptions {\n separator?: string\n}\n\ntype Renaming = RenamingObj | RenamingFunc\ntype RenamingFunc = (attr: AttrName) => AttrName\ntype RenamingObj = Record<AttrName, AttrName>\n\ntype JoinKeys = AttrName[] | Record<AttrName, AttrName>\n\ntype TransformFunc = (value: unknown) => unknown\ntype Transformation = TransformFunc | TransformFunc[] | Record<AttrName, TransformFunc | TransformFunc[]>\n\n// ============================================================================\n// Relation Interface\n// ============================================================================\n\n/**\n * Relation interface with generic type parameter for tuple type.\n * Default parameter `Tuple` ensures backwards compatibility.\n *\n * @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).\n *\n * @example\n * // Untyped usage (backwards compatible)\n * const r = Bmg([{ id: 1 }]); // Relation<Tuple>\n *\n * @example\n * // Typed usage with full type safety\n * interface Person { id: number; name: string }\n * const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);\n * r.project(['id']); // Relation<{ id: number }>\n */\ninterface Relation<T = Tuple> {\n // === Type-preserving operators ===\n\n restrict(p: TypedPredicate<T>): Relation<T>\n where(p: TypedPredicate<T>): Relation<T>\n exclude(p: TypedPredicate<T>): Relation<T>\n\n // === Projection operators ===\n\n project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>>\n allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>>\n\n // === Extension operators ===\n\n extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E>\n constants<C extends Tuple>(consts: C): Relation<T & C>\n\n // === Rename operators ===\n\n rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>>\n prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): Relation<Prefixed<T, P, Ex>>\n suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): Relation<Suffixed<T, S, Ex>>\n\n // === Set operators (require same type) ===\n\n union(right: RelationOperand<T>): Relation<T>\n minus(right: RelationOperand<T>): Relation<T>\n intersect(right: RelationOperand<T>): Relation<T>\n\n // === Semi-join operators (preserve left type) ===\n\n matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>\n not_matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>\n\n // === Join operators ===\n\n join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<Joined<T, R>>\n left_join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<LeftJoined<T, R>>\n cross_product<R>(right: RelationOperand<R>): Relation<T & R>\n cross_join<R>(right: RelationOperand<R>): Relation<T & R>\n\n // === Nesting operators ===\n\n 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>>>>\n group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>\n ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>>\n wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>>\n unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>>\n\n // === Aggregation ===\n\n summarize<By extends keyof T, Aggs extends Aggregators>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>>\n\n // === Transform ===\n\n transform(t: Transformation): Relation<T>\n\n // === Dynamic (loses type precision) ===\n\n autowrap(options?: AutowrapOptions): Relation<Tuple>\n\n // === Non-relational ===\n\n one(): T\n yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>\n toArray(): T[]\n isEqual(right: any): boolean\n}\n\n// ============================================================================\n// Operands\n// ============================================================================\n\ntype RelationOperand<T = Tuple> = Relation<T> | T[]\n\ninterface OperationalOperand<T = Tuple> {\n tuples(): Iterable<T>\n output(tuples: T[]): RelationOperand<T>\n}\n\n// ============================================================================\n// Bmg Function Declaration\n// ============================================================================\n\n/** Create a relation from an array of tuples */\ndeclare function Bmg<T>(tuples: T[]): Relation<T>\ndeclare namespace Bmg {\n function isRelation(op: unknown): boolean\n}\n",exports.allbut=x,exports.autowrap=D,exports.constants=m,exports.cross_join=P,exports.cross_product=P,exports.exclude=g,exports.extend=A,exports.group=U,exports.image=J,exports.intersect=k,exports.isEqual=W,exports.isRelation=u,exports.join=S,exports.left_join=N,exports.matching=K,exports.minus=w,exports.not_matching=O,exports.one=Y,exports.prefix=T,exports.project=R,exports.rename=v,exports.restrict=y,exports.suffix=h,exports.summarize=_,exports.transform=$,exports.ungroup=X,exports.union=b,exports.unwrap=z,exports.where=y,exports.wrap=q,exports.yByX=V;
|
|
2
2
|
//# sourceMappingURL=bmg.cjs.map
|
package/dist/bmg.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bmg.cjs","sources":["../src/support/toPredicateFunc.ts","../src/Relation/Memory.ts","../src/operators/isRelation.ts","../src/operators/_helpers.ts","../src/operators/restrict.ts","../src/operators/exclude.ts","../src/operators/constants.ts","../src/operators/rename.ts","../src/operators/prefix.ts","../src/operators/suffix.ts","../src/operators/project.ts","../src/operators/allbut.ts","../src/operators/extend.ts","../src/operators/union.ts","../src/operators/minus.ts","../src/operators/intersect.ts","../src/operators/matching.ts","../src/operators/not_matching.ts","../src/operators/join.ts","../src/operators/left_join.ts","../src/operators/cross_product.ts","../src/operators/image.ts","../src/operators/summarize.ts","../src/operators/group.ts","../src/operators/ungroup.ts","../src/operators/wrap.ts","../src/operators/unwrap.ts","../src/operators/autowrap.ts","../src/operators/transform.ts","../src/operators/isEqual.ts","../src/operators/one.ts","../src/operators/yByX.ts","../src/index.ts"],"sourcesContent":["import { Predicate, PredicateFunc, Tuple } from '../types';\n\nexport const toPredicateFunc = (p: Predicate): PredicateFunc => {\n if (typeof(p) === 'function') {\n return p as PredicateFunc;\n } else {\n const expected = p as Tuple;\n return (t: Tuple) => {\n return Object.keys(expected).every(k => t[k] === expected[k])\n }\n }\n}\n","import {\n allbut,\n autowrap,\n constants,\n cross_product,\n exclude,\n extend,\n group,\n image,\n intersect,\n isEqual,\n join,\n left_join,\n matching,\n minus,\n not_matching,\n one,\n prefix,\n project,\n rename,\n restrict,\n suffix,\n summarize,\n where,\n transform,\n ungroup,\n union,\n unwrap,\n wrap,\n yByX,\n} from \"../operators\";\nimport type {\n AttrName,\n AutowrapOptions,\n JoinKeys,\n Relation,\n RelationOperand,\n Transformation,\n Tuple,\n TypedPredicate,\n TypedExtension,\n RenameMap,\n Renamed,\n Prefixed,\n Suffixed,\n Joined,\n LeftJoined,\n Wrapped,\n Unwrapped,\n Ungrouped,\n} from \"../types\";\nimport type { AggregatorResults } from \"../utility-types\";\n\n/**\n * In-memory implementation of the Relation interface.\n *\n * @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).\n */\nexport class MemoryRelation<T = Tuple> implements Relation<T> {\n\n constructor(private tuples: T[]) {\n this.tuples = tuples;\n }\n\n // === Type-preserving operators ===\n\n restrict(p: TypedPredicate<T>): Relation<T> {\n return restrict(this as any, p as any) as unknown as Relation<T>;\n }\n\n where(p: TypedPredicate<T>): Relation<T> {\n return where(this as any, p as any) as unknown as Relation<T>;\n }\n\n exclude(p: TypedPredicate<T>): Relation<T> {\n return exclude(this as any, p as any) as unknown as Relation<T>;\n }\n\n // === Projection operators ===\n\n project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>> {\n return project(this as any, attrs as AttrName[]) as unknown as Relation<Pick<T, K>>;\n }\n\n allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>> {\n return allbut(this as any, attrs as AttrName[]) as unknown as Relation<Omit<T, K>>;\n }\n\n // === Extension operators ===\n\n extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E> {\n return extend(this as any, e as any) as unknown as Relation<T & E>;\n }\n\n constants<C extends Tuple>(consts: C): Relation<T & C> {\n return constants(this as any, consts) as unknown as Relation<T & C>;\n }\n\n // === Rename operators ===\n\n rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>> {\n return rename(this as any, r as any) as unknown as Relation<Renamed<T, R>>;\n }\n\n prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): Relation<Prefixed<T, P, Ex>> {\n return prefix(this as any, pfx, options as any) as unknown as Relation<Prefixed<T, P, Ex>>;\n }\n\n suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): Relation<Suffixed<T, S, Ex>> {\n return suffix(this as any, sfx, options as any) as unknown as Relation<Suffixed<T, S, Ex>>;\n }\n\n // === Set operators ===\n\n union(right: RelationOperand<T>): Relation<T> {\n return union(this as any, right as any) as unknown as Relation<T>;\n }\n\n minus(right: RelationOperand<T>): Relation<T> {\n return minus(this as any, right as any) as unknown as Relation<T>;\n }\n\n intersect(right: RelationOperand<T>): Relation<T> {\n return intersect(this as any, right as any) as unknown as Relation<T>;\n }\n\n // === Semi-join operators ===\n\n matching<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<T> {\n return matching(this as any, right as any, keys) as unknown as Relation<T>;\n }\n\n not_matching<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<T> {\n return not_matching(this as any, right as any, keys) as unknown as Relation<T>;\n }\n\n // === Join operators ===\n\n join<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<Joined<T, R>> {\n return join(this as any, right as any, keys) as unknown as Relation<Joined<T, R>>;\n }\n\n left_join<R>(right: RelationOperand<R>, keys?: JoinKeys): Relation<LeftJoined<T, R>> {\n return left_join(this as any, right as any, keys) as unknown as Relation<LeftJoined<T, R>>;\n }\n\n cross_product<R>(right: RelationOperand<R>): Relation<T & R> {\n return cross_product(this as any, right as any) as unknown as Relation<T & R>;\n }\n\n cross_join<R>(right: RelationOperand<R>): Relation<T & R> {\n return cross_product(this as any, right as any) as unknown as Relation<T & R>;\n }\n\n // === Nesting operators ===\n\n image<R, As extends string>(right: RelationOperand<R>, as: As, keys?: JoinKeys): Relation<T & Record<As, Relation<Omit<R, keyof T & keyof R>>>> {\n return image(this as any, right as any, as, keys) as unknown as Relation<T & Record<As, Relation<Omit<R, keyof T & keyof R>>>>;\n }\n\n group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>> {\n return group(this as any, attrs as AttrName[], as) as unknown as Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>;\n }\n\n ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>> {\n return ungroup(this as any, attr as AttrName) as unknown as Relation<Ungrouped<T, K>>;\n }\n\n wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>> {\n return wrap(this as any, attrs as AttrName[], as) as unknown as Relation<Wrapped<T, K, As>>;\n }\n\n unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>> {\n return unwrap(this as any, attr as AttrName) as unknown as Relation<Unwrapped<T, K>>;\n }\n\n // === Aggregation ===\n\n summarize<By extends keyof T, Aggs extends Record<string, unknown>>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>> {\n return summarize(this as any, by as AttrName[], aggs as any) as unknown as Relation<Pick<T, By> & AggregatorResults<Aggs>>;\n }\n\n // === Transform ===\n\n transform(t: Transformation): Relation<T> {\n return transform(this as any, t) as unknown as Relation<T>;\n }\n\n // === Dynamic ===\n\n autowrap(options?: AutowrapOptions): Relation<Tuple> {\n return autowrap(this as any, options) as Relation<Tuple>;\n }\n\n // === Non-relational ===\n\n one(): T {\n return one(this as any) as T;\n }\n\n toArray(): T[] {\n return this.tuples;\n }\n\n yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]> {\n return yByX(this as any, y as AttrName, x as AttrName) as Record<T[X] & PropertyKey, T[Y]>;\n }\n\n isEqual(right: any): boolean {\n return isEqual(this as any, right as any);\n }\n\n}\n","import { MemoryRelation } from \"@/Relation\";\n\nexport const isRelation = (op) => {\n return op != null && op.constructor === MemoryRelation;\n}\n","import { OperationalOperand, Relation, RelationOperand, Renaming, RenamingFunc, Tuple, JoinKeys, AttrName } from \"@/types\";\nimport { MemoryRelation } from '@/Relation';\nimport { isRelation } from \"./isRelation\";\n\nconst valueKey = (value: unknown): unknown => {\n if (isRelation(value)) {\n // For nested relations, convert to sorted array of tuple keys for comparison\n const tuples = (value as Relation).toArray();\n const keys = tuples.map(t => tupleKey(t)).sort();\n return keys;\n }\n return value;\n}\n\n/**\n * Generates a unique string key for a tuple, used for equality comparison and deduplication.\n * Handles nested relations by converting them to sorted tuple keys.\n *\n * @example\n * tupleKey({ name: 'Alice', age: 30 })\n * // => '[[\"age\",30],[\"name\",\"Alice\"]]'\n *\n * @example\n * tupleKey({ id: 1, items: Bmg([{ x: 1 }, { x: 2 }]) })\n * // => '[[\"id\",1],[\"items\",[...]]]' (nested relation converted to sorted keys)\n */\nexport const tupleKey = (tuple: Tuple): string => {\n const entries = Object.entries(tuple).map(([k, v]) => [k, valueKey(v)]);\n return JSON.stringify(entries.sort(([a], [b]) => (a as string).localeCompare(b as string)));\n}\n\n/**\n * Removes duplicate tuples from an array, preserving order of first occurrence.\n * Uses tupleKey() for equality comparison.\n *\n * @example\n * deduplicate([\n * { id: 1, name: 'Alice' },\n * { id: 2, name: 'Bob' },\n * { id: 1, name: 'Alice' }, // duplicate\n * ])\n * // => [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]\n */\nexport const deduplicate = (tuples: Tuple[]): Tuple[] => {\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of tuples) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n return result;\n}\n\n/**\n * Converts a RelationOperand (Relation or Tuple[]) to an OperationalOperand\n * that provides a uniform interface for iteration and output.\n *\n * @example\n * // With array input, output remains array\n * const op = toOperationalOperand([{ id: 1 }]);\n * [...op.tuples()]; // => [{ id: 1 }]\n * op.output([{ id: 2 }]); // => [{ id: 2 }]\n *\n * @example\n * // With Relation input, output is a new Relation\n * const op = toOperationalOperand(Bmg([{ id: 1 }]));\n * [...op.tuples()]; // => [{ id: 1 }]\n * op.output([{ id: 2 }]); // => Bmg([{ id: 2 }])\n */\nexport const toOperationalOperand = (operand: RelationOperand): OperationalOperand => {\n if (Array.isArray(operand)) {\n return {\n tuples: () => operand,\n output: (tuples) => tuples,\n };\n } else if (isRelation(operand)) {\n return {\n tuples: () => (operand as Relation).toArray(),\n output: (tuples) => new MemoryRelation(tuples),\n };\n } else {\n throw `Unable to iterate ${operand}`\n }\n}\n\n/**\n * Converts a Renaming (object or function) to a RenamingFunc.\n *\n * @example\n * // Object renaming\n * const fn = toRenamingFunc({ name: 'fullName', age: 'years' });\n * fn('name'); // => 'fullName'\n * fn('age'); // => 'years'\n * fn('other'); // => 'other' (unchanged)\n *\n * @example\n * // Function renaming (passed through)\n * const fn = toRenamingFunc(attr => attr.toUpperCase());\n * fn('name'); // => 'NAME'\n */\nexport const toRenamingFunc = (renaming: Renaming): RenamingFunc => {\n if (typeof(renaming) === 'function') {\n return renaming;\n } else {\n return (attr) => renaming[attr] || attr;\n }\n}\n\nexport const error = (msg: string) => {\n throw(msg);\n}\n\n// Join helpers\n\n/**\n * Finds attribute names that exist in both left and right tuple arrays.\n * Used for natural joins when no explicit keys are provided.\n *\n * @example\n * const left = [{ id: 1, name: 'Alice', city: 'NYC' }];\n * const right = [{ city: 'NYC', country: 'USA' }];\n * getCommonAttrs(left, right);\n * // => ['city']\n *\n * @example\n * const left = [{ a: 1, b: 2 }];\n * const right = [{ b: 2, c: 3 }];\n * getCommonAttrs(left, right);\n * // => ['b']\n */\nexport const getCommonAttrs = (left: Tuple[], right: Tuple[]): AttrName[] => {\n if (left.length === 0 || right.length === 0) return [];\n const leftAttrs = new Set(Object.keys(left[0]));\n const rightAttrs = Object.keys(right[0]);\n return rightAttrs.filter(attr => leftAttrs.has(attr));\n}\n\n/**\n * Normalizes JoinKeys to a Record<AttrName, AttrName> mapping left attrs to right attrs.\n *\n * @example\n * // undefined => use common attributes\n * normalizeKeys(undefined, [{ id: 1, city: 'NYC' }], [{ city: 'NYC' }]);\n * // => { city: 'city' }\n *\n * @example\n * // Array of common attribute names\n * normalizeKeys(['city', 'country'], leftTuples, rightTuples);\n * // => { city: 'city', country: 'country' }\n *\n * @example\n * // Object mapping left attr to right attr\n * normalizeKeys({ city: 'location' }, leftTuples, rightTuples);\n * // => { city: 'location' }\n */\nexport const normalizeKeys = (keys: JoinKeys | undefined, leftTuples: Tuple[], rightTuples: Tuple[]): Record<AttrName, AttrName> => {\n if (!keys) {\n const common = getCommonAttrs(leftTuples, rightTuples);\n return common.reduce((acc, attr) => {\n acc[attr] = attr;\n return acc;\n }, {} as Record<AttrName, AttrName>);\n }\n if (Array.isArray(keys)) {\n return keys.reduce((acc, attr) => {\n acc[attr] = attr;\n return acc;\n }, {} as Record<AttrName, AttrName>);\n }\n return keys;\n}\n\n/**\n * Checks if two tuples match on the specified key mapping.\n *\n * @example\n * const keyMap = { city: 'location' };\n * tuplesMatch({ id: 1, city: 'NYC' }, { location: 'NYC', pop: 8 }, keyMap);\n * // => true (left.city === right.location)\n *\n * @example\n * const keyMap = { city: 'city' };\n * tuplesMatch({ city: 'NYC' }, { city: 'LA' }, keyMap);\n * // => false\n */\nexport const tuplesMatch = (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>): boolean => {\n for (const [leftAttr, rightAttr] of Object.entries(keyMap)) {\n if (left[leftAttr] !== right[rightAttr]) return false;\n }\n return true;\n}\n\n/**\n * Creates a string key from a tuple's join attributes for fast Set-based lookups.\n * Used by matching/not_matching for efficient semi-join operations.\n *\n * @example\n * const keyMap = { first: 'fname', last: 'lname' };\n *\n * // Left side uses left attr names (keys of keyMap)\n * matchKey({ id: 1, first: 'John', last: 'Doe' }, keyMap, 'left');\n * // => '\"John\"|\"Doe\"'\n *\n * // Right side uses right attr names (values of keyMap)\n * matchKey({ fname: 'John', lname: 'Doe', age: 30 }, keyMap, 'right');\n * // => '\"John\"|\"Doe\"'\n */\nexport const matchKey = (tuple: Tuple, keyMap: Record<AttrName, AttrName>, side: 'left' | 'right'): string => {\n const attrs = side === 'left' ? Object.keys(keyMap) : Object.values(keyMap);\n const values = attrs.map(attr => JSON.stringify(tuple[attr]));\n return values.join('|');\n}\n\n/**\n * Removes join key attributes from a right tuple when merging.\n * Used to avoid duplicate columns in join results.\n *\n * @example\n * const keyMap = { city: 'location' };\n * projectOutKeys({ location: 'NYC', country: 'USA', pop: 8 }, keyMap);\n * // => { country: 'USA', pop: 8 } (location removed)\n *\n * @example\n * const keyMap = { a: 'a', b: 'b' };\n * projectOutKeys({ a: 1, b: 2, c: 3 }, keyMap);\n * // => { c: 3 } (a and b removed)\n */\nexport const projectOutKeys = (tuple: Tuple, keyMap: Record<AttrName, AttrName>): Tuple => {\n const rightKeys = new Set(Object.values(keyMap));\n const result: Tuple = {};\n for (const [attr, value] of Object.entries(tuple)) {\n if (!rightKeys.has(attr)) {\n result[attr] = value;\n }\n }\n return result;\n}\n","import { toPredicateFunc } from \"../support/toPredicateFunc\";\nimport { RelationOperand, Predicate, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const restrict = (operand: RelationOperand, p: Predicate): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const f = toPredicateFunc(p)\n const kept: Tuple[] = [];\n for (const tuple of iterable) {\n if (f(tuple)) kept.push(tuple);\n }\n return op.output(kept)\n}\n","import { toPredicateFunc } from \"../support/toPredicateFunc\";\nimport { RelationOperand, Predicate, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const exclude = (operand: RelationOperand, p: Predicate): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const f = toPredicateFunc(p)\n const kept: Tuple[] = [];\n for (const tuple of iterable) {\n if (!f(tuple)) kept.push(tuple);\n }\n return op.output(kept)\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const constants = (operand: RelationOperand, consts: Tuple): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n result.push({ ...tuple, ...consts });\n }\n return op.output(result)\n}\n","import { RelationOperand, Renaming, Tuple } from \"../types\";\nimport { toOperationalOperand, toRenamingFunc } from \"./_helpers\";\n\nexport const rename = (operand: RelationOperand, renaming: Renaming): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const renamingFunc = toRenamingFunc(renaming)\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const renamed = Object.keys(tuple).reduce((memo, attr) => {\n memo[renamingFunc(attr)] = tuple[attr];\n return memo;\n }, {})\n result.push(renamed);\n }\n return op.output(result)\n}\n","import { PrefixOptions, RelationOperand } from \"../types\";\nimport { rename } from \"./rename\";\n\nexport const prefix = (operand: RelationOperand, pfx: string, options?: PrefixOptions): RelationOperand => {\n const except = new Set(options?.except ?? []);\n return rename(operand, (attr) => except.has(attr) ? attr : `${pfx}${attr}`);\n}\n","import { RelationOperand, SuffixOptions } from \"../types\";\nimport { rename } from \"./rename\";\n\nexport const suffix = (operand: RelationOperand, sfx: string, options?: SuffixOptions): RelationOperand => {\n const except = new Set(options?.except ?? []);\n return rename(operand, (attr) => except.has(attr) ? attr : `${attr}${sfx}`);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const project = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const projected = attrs.reduce((memo, attr) => {\n if (attr in tuple) {\n memo[attr] = tuple[attr];\n }\n return memo;\n }, {} as Tuple);\n result.push(projected);\n }\n return op.output(deduplicate(result));\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const allbut = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const excluded = new Set(attrs);\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const projected = Object.keys(tuple).reduce((memo, attr) => {\n if (!excluded.has(attr)) {\n memo[attr] = tuple[attr];\n }\n return memo;\n }, {} as Tuple);\n result.push(projected);\n }\n return op.output(deduplicate(result));\n}\n","import { RelationOperand, Extension, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const extend = (operand: RelationOperand, extension: Extension): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const extended = { ...tuple };\n for (const [attr, spec] of Object.entries(extension)) {\n if (typeof spec === 'function') {\n extended[attr] = spec(tuple);\n } else {\n extended[attr] = tuple[spec];\n }\n }\n result.push(extended);\n }\n return op.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const union = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const seen = new Set<string>();\n const result: Tuple[] = [];\n\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n for (const tuple of opRight.tuples()) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const minus = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (!rightKeys.has(key) && !seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const intersect = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (rightKeys.has(key) && !seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, matchKey } from \"./_helpers\";\n\nexport const matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n\n const rightKeys = new Set<string>();\n for (const tuple of rightTuples) {\n rightKeys.add(matchKey(tuple, keyMap, 'right'));\n }\n\n const result: Tuple[] = [];\n for (const tuple of leftTuples) {\n if (rightKeys.has(matchKey(tuple, keyMap, 'left'))) {\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, matchKey } from \"./_helpers\";\n\nexport const not_matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n\n const rightKeys = new Set<string>();\n for (const tuple of rightTuples) {\n rightKeys.add(matchKey(tuple, keyMap, 'right'));\n }\n\n const result: Tuple[] = [];\n for (const tuple of leftTuples) {\n if (!rightKeys.has(matchKey(tuple, keyMap, 'left'))) {\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from \"./_helpers\";\n\nconst mergeTuples = (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>): Tuple => {\n return { ...left, ...projectOutKeys(right, keyMap) };\n}\n\nexport const join = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n result.push(mergeTuples(leftTuple, rightTuple, keyMap));\n }\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch } from \"./_helpers\";\n\nconst getRightAttrs = (rightTuples: Tuple[], keyMap: Record<AttrName, AttrName>): AttrName[] => {\n if (rightTuples.length === 0) return [];\n const rightKeys = new Set(Object.values(keyMap));\n return Object.keys(rightTuples[0]).filter(attr => !rightKeys.has(attr));\n}\n\nconst mergeTuples = (left: Tuple, right: Tuple | null, rightAttrs: AttrName[]): Tuple => {\n const result = { ...left };\n for (const attr of rightAttrs) {\n result[attr] = right ? right[attr] : null;\n }\n return result;\n}\n\nexport const left_join = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const rightAttrs = getRightAttrs(rightTuples, keyMap);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n let matched = false;\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n result.push(mergeTuples(leftTuple, rightTuple, rightAttrs));\n matched = true;\n }\n }\n if (!matched) {\n result.push(mergeTuples(leftTuple, null, rightAttrs));\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const cross_product = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const result: Tuple[] = [];\n\n for (const l of leftTuples) {\n for (const r of rightTuples) {\n result.push({ ...r, ...l });\n }\n }\n\n return opLeft.output(deduplicate(result));\n}\n\nexport { cross_product as cross_join };\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from \"./_helpers\";\nimport { MemoryRelation } from \"@/Relation\";\n\nexport const image = (left: RelationOperand, right: RelationOperand, as: AttrName, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n const matches: Tuple[] = [];\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n matches.push(projectOutKeys(rightTuple, keyMap));\n }\n }\n result.push({\n ...leftTuple,\n [as]: new MemoryRelation(matches)\n });\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, AttrName, Tuple, Aggregator, Aggregators } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nconst groupKey = (tuple: Tuple, by: AttrName[]): string => {\n const keyParts = by.map(attr => JSON.stringify(tuple[attr]));\n return keyParts.join('|');\n}\n\nconst pickAttrs = (tuple: Tuple, attrs: AttrName[]): Tuple => {\n return attrs.reduce((acc, attr) => {\n acc[attr] = tuple[attr];\n return acc;\n }, {} as Tuple);\n}\n\nconst applyAggregator = (tuples: Tuple[], agg: Aggregator): unknown => {\n if (typeof agg === 'function') {\n return agg(tuples);\n }\n\n const spec = typeof agg === 'string' ? { op: agg, attr: '' } : agg;\n const { op, attr } = spec;\n\n switch (op) {\n case 'count':\n return tuples.length;\n\n case 'sum': {\n return tuples.reduce((sum, t) => sum + (Number(t[attr]) || 0), 0);\n }\n\n case 'min': {\n const values = tuples.map(t => t[attr]).filter(v => v !== undefined && v !== null);\n return values.length > 0 ? Math.min(...values.map(Number)) : null;\n }\n\n case 'max': {\n const values = tuples.map(t => t[attr]).filter(v => v !== undefined && v !== null);\n return values.length > 0 ? Math.max(...values.map(Number)) : null;\n }\n\n case 'avg': {\n const values = tuples.map(t => Number(t[attr])).filter(v => !isNaN(v));\n return values.length > 0 ? values.reduce((a, b) => a + b, 0) / values.length : null;\n }\n\n case 'collect': {\n return tuples.map(t => t[attr]);\n }\n\n default:\n throw new Error(`Unknown aggregator: ${op}`);\n }\n}\n\nexport const summarize = (\n operand: RelationOperand,\n by: AttrName[],\n aggs: Aggregators\n): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n\n // Group tuples\n const groups = new Map<string, Tuple[]>();\n for (const tuple of tuples) {\n const key = groupKey(tuple, by);\n if (!groups.has(key)) {\n groups.set(key, []);\n }\n groups.get(key)!.push(tuple);\n }\n\n // Apply aggregators to each group\n const result: Tuple[] = [];\n for (const groupTuples of groups.values()) {\n const row: Tuple = pickAttrs(groupTuples[0], by);\n for (const [resultAttr, agg] of Object.entries(aggs)) {\n row[resultAttr] = applyAggregator(groupTuples, agg);\n }\n result.push(row);\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\nimport { MemoryRelation } from \"@/Relation\";\n\nconst groupKey = (tuple: Tuple, byAttrs: AttrName[]): string => {\n const keyParts = byAttrs.map(attr => JSON.stringify(tuple[attr]));\n return keyParts.join('|');\n}\n\nconst pickAttrs = (tuple: Tuple, attrs: AttrName[]): Tuple => {\n return attrs.reduce((acc, attr) => {\n acc[attr] = tuple[attr];\n return acc;\n }, {} as Tuple);\n}\n\nexport const group = (operand: RelationOperand, attrs: AttrName[], as: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n\n if (tuples.length === 0) {\n return op.output([]);\n }\n\n // Determine which attributes to keep at the top level (all except grouped ones)\n const allAttrs = Object.keys(tuples[0]);\n const groupedSet = new Set(attrs);\n const byAttrs = allAttrs.filter(a => !groupedSet.has(a));\n\n // Group tuples\n const groups = new Map<string, { base: Tuple, nested: Tuple[] }>();\n for (const tuple of tuples) {\n const key = groupKey(tuple, byAttrs);\n if (!groups.has(key)) {\n groups.set(key, {\n base: pickAttrs(tuple, byAttrs),\n nested: []\n });\n }\n groups.get(key)!.nested.push(pickAttrs(tuple, attrs));\n }\n\n // Build result with nested relations\n const result: Tuple[] = [];\n for (const { base, nested } of groups.values()) {\n result.push({\n ...base,\n [as]: new MemoryRelation(nested)\n });\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple, Relation } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\nimport { isRelation } from \"./isRelation\";\n\nconst toTupleArray = (value: unknown): Tuple[] => {\n if (isRelation(value)) {\n return (value as Relation).toArray();\n }\n if (Array.isArray(value)) {\n return value;\n }\n throw new Error(`Value is not a relation or array`);\n}\n\nexport const ungroup = (operand: RelationOperand, attr: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n const result: Tuple[] = [];\n\n for (const tuple of tuples) {\n const nested = toTupleArray(tuple[attr]);\n\n // Get base attributes (all except the grouped one)\n const base: Tuple = {};\n for (const [key, value] of Object.entries(tuple)) {\n if (key !== attr) {\n base[key] = value;\n }\n }\n\n // Flatten each nested tuple\n for (const nestedTuple of nested) {\n result.push({\n ...base,\n ...nestedTuple\n });\n }\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const wrap = (operand: RelationOperand, attrs: AttrName[], as: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const wrappedSet = new Set(attrs);\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped: Tuple = {};\n const remaining: Tuple = {};\n\n for (const [key, value] of Object.entries(tuple)) {\n if (wrappedSet.has(key)) {\n wrapped[key] = value;\n } else {\n remaining[key] = value;\n }\n }\n\n result.push({\n ...remaining,\n [as]: wrapped\n });\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const unwrap = (operand: RelationOperand, attr: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped = tuple[attr] as Tuple;\n if (typeof wrapped !== 'object' || wrapped === null || Array.isArray(wrapped)) {\n throw new Error(`Attribute '${attr}' is not a tuple (object)`);\n }\n\n const unwrapped: Tuple = {};\n for (const [key, value] of Object.entries(tuple)) {\n if (key !== attr) {\n unwrapped[key] = value;\n }\n }\n\n result.push({\n ...unwrapped,\n ...wrapped\n });\n }\n\n return op.output(result);\n}\n","import { AutowrapOptions, RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const autowrap = (operand: RelationOperand, options?: AutowrapOptions): RelationOperand => {\n const sep = options?.separator ?? '_';\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped: Tuple = {};\n for (const [attr, value] of Object.entries(tuple)) {\n const parts = attr.split(sep);\n if (parts.length === 1) {\n wrapped[attr] = value;\n } else {\n const [prefix, ...rest] = parts;\n wrapped[prefix] = wrapped[prefix] ?? {};\n (wrapped[prefix] as Tuple)[rest.join(sep)] = value;\n }\n }\n result.push(wrapped);\n }\n\n return op.output(result);\n}\n","import { RelationOperand, Transformation, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const transform = (operand: RelationOperand, transformation: Transformation): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const transformed: Tuple = {};\n\n for (const [attr, value] of Object.entries(tuple)) {\n transformed[attr] = applyTransformation(value, attr, transformation);\n }\n\n result.push(transformed);\n }\n\n return op.output(result);\n}\n\nconst applyTransformation = (value: unknown, attr: string, transformation: Transformation): unknown => {\n if (typeof transformation === 'function') {\n // Single function - apply to all values\n return transformation(value);\n } else if (Array.isArray(transformation)) {\n // Array of functions - chain them\n return transformation.reduce((v, fn) => fn(v), value);\n } else {\n // Object with attr-specific transformers\n const fn = transformation[attr];\n if (fn) {\n if (Array.isArray(fn)) {\n return fn.reduce((v, f) => f(v), value);\n }\n return fn(value);\n }\n return value;\n }\n}\n","import { RelationOperand } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const isEqual = (left: RelationOperand, right: RelationOperand): boolean => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const leftKeys = new Set<string>();\n for (const tuple of opLeft.tuples()) {\n leftKeys.add(tupleKey(tuple));\n }\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n if (leftKeys.size !== rightKeys.size) {\n return false;\n }\n\n for (const key of leftKeys) {\n if (!rightKeys.has(key)) {\n return false;\n }\n }\n\n return true;\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, error } from \"./_helpers\";\n\nexport const one = (operand: RelationOperand): Tuple => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n let tuple;\n for (const t of iterable) {\n if (tuple) {\n return error('More than one tuple found');\n } else {\n tuple = t;\n }\n }\n if (tuple) return tuple;\n return error('Relation is empty');\n}\n","import { AttrName, RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const yByX = (operand: RelationOperand, y: AttrName, x: AttrName): Tuple => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const hash = {};\n for (const tuple of iterable) {\n hash[`${tuple[x]}`] = tuple[y];\n }\n return hash;\n}\n","export * from './operators';\nexport * from './types';\nexport * from './utility-types';\n\nimport { MemoryRelation } from './Relation';\nimport { isRelation } from './operators';\n\n/**\n * Creates a new in-memory relation from an array of tuples.\n *\n * @typeParam T - The tuple type. Inferred from input or explicitly provided.\n *\n * @example\n * // Untyped usage (backwards compatible)\n * const r = Bmg([{ id: 1, name: 'Alice' }]);\n *\n * @example\n * // Typed usage with explicit type parameter\n * interface Person { id: number; name: string }\n * const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);\n * r.project(['id']); // Autocomplete suggests 'id' | 'name'\n *\n * @example\n * // Type is inferred from input\n * const r = Bmg([{ id: 1, name: 'Alice' }] as const);\n */\nexport function Bmg<T>(tuples: T[]): MemoryRelation<T> {\n return new MemoryRelation<T>(tuples);\n}\n\nBmg.isRelation = isRelation;\n"],"names":["toPredicateFunc","p","expected","t","Object","keys","every","k","MemoryRelation","tuples","this","_proto","prototype","restrict","where","exclude","project","attrs","allbut","extend","e","constants","consts","rename","r","prefix","pfx","options","suffix","sfx","union","right","minus","intersect","matching","not_matching","join","left_join","cross_product","cross_join","image","as","group","ungroup","attr","wrap","unwrap","summarize","by","aggs","transform","autowrap","one","toArray","yByX","y","x","isEqual","isRelation","op","constructor","tupleKey","tuple","entries","map","_ref","v","value","sort","JSON","stringify","_ref2","_ref3","localeCompare","deduplicate","_step","seen","Set","result","_iterator","_createForOfIteratorHelperLoose","done","key","has","add","push","toOperationalOperand","operand","Array","isArray","output","error","msg","normalizeKeys","leftTuples","rightTuples","reduce","acc","left","length","leftAttrs","filter","getCommonAttrs","tuplesMatch","keyMap","_i","_Object$entries","_Object$entries$_i","matchKey","side","values","projectOutKeys","rightKeys","_i2","_Object$entries2","_Object$entries2$_i","iterable","f","kept","_extends","renaming","renamingFunc","toRenamingFunc","_loop","renamed","memo","_options$except","except","projected","excluded","extension","extended","spec","opLeft","opRight","_step2","_iterator2","concat","mergeTuples","leftTuple","rightTuple","rightAttrs","getRightAttrs","_step3","matched","_iterator3","l","_extends2","matches","groupKey","pickAttrs","applyAggregator","agg","sum","Number","Math","min","apply","max","isNaN","a","b","Error","groups","Map","set","get","groupTuples","row","byAttrs","allAttrs","groupedSet","base","nested","_step2$value","toTupleArray","wrappedSet","wrapped","remaining","unwrapped","_options$separator","sep","separator","parts","split","_wrapped$prefix","rest","_arrayLikeToArray","slice","transformation","transformed","applyTransformation","fn","leftKeys","size","hash","Bmg"],"mappings":"4/BAEa,IAAAA,EAAkB,SAACC,GAC9B,GAAkB,mBAAPA,EACT,OAAOA,EAEP,IAAMC,EAAWD,EACjB,OAAO,SAACE,GACN,OAAOC,OAAOC,KAAKH,GAAUI,MAAM,SAAAC,GAAC,OAAIJ,EAAEI,KAAOL,EAASK,EAAE,EAC9D,CAEJ,EC+CaC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,EAD9BvB,EAAY,IAAInC,IACtB2D,EAAAxD,EAAoBsD,EAAQ7H,YAAQ8H,EAAAC,KAAAvD,MAClC+B,EAAU5B,IAAIvB,EADA0E,EAAApE,QAIhB,GAAI8H,EAASC,OAASlF,EAAUkF,KAC9B,OACD,EAED,QAA0BnD,EAA1BE,EAAAjE,EAAkBiH,KAAQlD,EAAAE,KAAAhE,MACxB,IAAK+B,EAAU7B,IADH4D,EAAA5E,OAEV,OAAO,EAIX,QACF,ECzBaf,EAAM,SAACmC,GAIlB,IAHA,IAEIzB,EACoBa,EAAxBI,EAAAC,EAHWM,EAAqBC,GACZ9E,YAEIkE,EAAAI,KAAAE,MAAE,KAAf9E,EAACwE,EAAAR,MACV,GAAIL,EACF,OAAO6B,EAAM,6BAEb7B,EAAQ3D,CAEX,CACD,OAAI2D,GACG6B,EAAM,oBACf,ECbarC,EAAO,SAACiC,EAA0BhC,EAAaC,GAI1D,IAHA,IAG4BmB,EADtBwH,EAAO,CAAE,EACfpH,EAAAC,EAHWM,EAAqBC,GACZ9E,YAEQkE,EAAAI,KAAAE,MAAE,KAAnBnB,EAAKa,EAAAR,MACdgI,EAAQrI,GAAAA,EAAMN,IAAQM,EAAMP,EAC7B,CACD,OAAO4I,CACT,ECegB,SAAAC,EAAO3L,GACrB,OAAW,IAAAD,EAAkBC,EAC/B,CAEA2L,EAAI1I,WAAaA"}
|
|
1
|
+
{"version":3,"file":"bmg.cjs","sources":["../src/support/toPredicateFunc.ts","../src/Relation/Memory.ts","../src/operators/isRelation.ts","../src/operators/_helpers.ts","../src/operators/restrict.ts","../src/operators/exclude.ts","../src/operators/constants.ts","../src/operators/rename.ts","../src/operators/prefix.ts","../src/operators/suffix.ts","../src/operators/project.ts","../src/operators/allbut.ts","../src/operators/extend.ts","../src/operators/union.ts","../src/operators/minus.ts","../src/operators/intersect.ts","../src/operators/matching.ts","../src/operators/not_matching.ts","../src/operators/join.ts","../src/operators/left_join.ts","../src/operators/cross_product.ts","../src/operators/image.ts","../src/operators/summarize.ts","../src/operators/group.ts","../src/operators/ungroup.ts","../src/operators/wrap.ts","../src/operators/unwrap.ts","../src/operators/autowrap.ts","../src/operators/transform.ts","../src/operators/isEqual.ts","../src/operators/one.ts","../src/operators/yByX.ts","../src/index.ts","../src/lib-definitions.ts"],"sourcesContent":["import { Predicate, PredicateFunc, Tuple } from '../types';\n\nexport const toPredicateFunc = (p: Predicate): PredicateFunc => {\n if (typeof(p) === 'function') {\n return p as PredicateFunc;\n } else {\n const expected = p as Tuple;\n return (t: Tuple) => {\n return Object.keys(expected).every(k => t[k] === expected[k])\n }\n }\n}\n","import {\n allbut,\n autowrap,\n constants,\n cross_product,\n exclude,\n extend,\n group,\n image,\n intersect,\n isEqual,\n join,\n left_join,\n matching,\n minus,\n not_matching,\n one,\n prefix,\n project,\n rename,\n restrict,\n suffix,\n summarize,\n where,\n transform,\n ungroup,\n union,\n unwrap,\n wrap,\n yByX,\n} from \"../operators\";\nimport type {\n AttrName,\n AutowrapOptions,\n Relation,\n RelationOperand,\n Transformation,\n Tuple,\n TypedPredicate,\n TypedExtension,\n RenameMap,\n Renamed,\n Prefixed,\n Suffixed,\n Joined,\n LeftJoined,\n Wrapped,\n Unwrapped,\n Ungrouped,\n AggregatorResults,\n TypedJoinKeysArray,\n TypedJoinKeysObject,\n} from \"../types\";\n\n/**\n * In-memory implementation of the Relation interface.\n *\n * @typeParam T - The tuple type for this relation. Defaults to `Tuple` (Record<string, unknown>).\n */\nexport class MemoryRelation<T = Tuple> implements Relation<T> {\n\n constructor(private tuples: T[]) {\n this.tuples = tuples;\n }\n\n // === Type-preserving operators ===\n\n restrict(p: TypedPredicate<T>): Relation<T> {\n return restrict(this as any, p as any) as unknown as Relation<T>;\n }\n\n where(p: TypedPredicate<T>): Relation<T> {\n return where(this as any, p as any) as unknown as Relation<T>;\n }\n\n exclude(p: TypedPredicate<T>): Relation<T> {\n return exclude(this as any, p as any) as unknown as Relation<T>;\n }\n\n // === Projection operators ===\n\n project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>> {\n return project(this as any, attrs as AttrName[]) as unknown as Relation<Pick<T, K>>;\n }\n\n allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>> {\n return allbut(this as any, attrs as AttrName[]) as unknown as Relation<Omit<T, K>>;\n }\n\n // === Extension operators ===\n\n extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E> {\n return extend(this as any, e as any) as unknown as Relation<T & E>;\n }\n\n constants<C extends Tuple>(consts: C): Relation<T & C> {\n return constants(this as any, consts) as unknown as Relation<T & C>;\n }\n\n // === Rename operators ===\n\n rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>> {\n return rename(this as any, r as any) as unknown as Relation<Renamed<T, R>>;\n }\n\n prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): Relation<Prefixed<T, P, Ex>> {\n return prefix(this as any, pfx, options as any) as unknown as Relation<Prefixed<T, P, Ex>>;\n }\n\n suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): Relation<Suffixed<T, S, Ex>> {\n return suffix(this as any, sfx, options as any) as unknown as Relation<Suffixed<T, S, Ex>>;\n }\n\n // === Set operators ===\n\n union(right: RelationOperand<T>): Relation<T> {\n return union(this as any, right as any) as unknown as Relation<T>;\n }\n\n minus(right: RelationOperand<T>): Relation<T> {\n return minus(this as any, right as any) as unknown as Relation<T>;\n }\n\n intersect(right: RelationOperand<T>): Relation<T> {\n return intersect(this as any, right as any) as unknown as Relation<T>;\n }\n\n // === Semi-join operators ===\n\n matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T> {\n return matching(this as any, right as any, keys as any) as unknown as Relation<T>;\n }\n\n not_matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T> {\n return not_matching(this as any, right as any, keys as any) as unknown as Relation<T>;\n }\n\n // === Join operators ===\n\n join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<Joined<T, R>> {\n return join(this as any, right as any, keys as any) as unknown as Relation<Joined<T, R>>;\n }\n\n left_join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<LeftJoined<T, R>> {\n return left_join(this as any, right as any, keys as any) as unknown as Relation<LeftJoined<T, R>>;\n }\n\n cross_product<R>(right: RelationOperand<R>): Relation<T & R> {\n return cross_product(this as any, right as any) as unknown as Relation<T & R>;\n }\n\n cross_join<R>(right: RelationOperand<R>): Relation<T & R> {\n return cross_product(this as any, right as any) as unknown as Relation<T & R>;\n }\n\n // === Nesting operators ===\n\n 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>>>> {\n return image(this as any, right as any, as, keys as any) as unknown as Relation<T & Record<As, Relation<Omit<R, keyof T & keyof R>>>>;\n }\n\n group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>> {\n return group(this as any, attrs as AttrName[], as) as unknown as Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>;\n }\n\n ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>> {\n return ungroup(this as any, attr as AttrName) as unknown as Relation<Ungrouped<T, K>>;\n }\n\n wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>> {\n return wrap(this as any, attrs as AttrName[], as) as unknown as Relation<Wrapped<T, K, As>>;\n }\n\n unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>> {\n return unwrap(this as any, attr as AttrName) as unknown as Relation<Unwrapped<T, K>>;\n }\n\n // === Aggregation ===\n\n summarize<By extends keyof T, Aggs extends Record<string, unknown>>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>> {\n return summarize(this as any, by as AttrName[], aggs as any) as unknown as Relation<Pick<T, By> & AggregatorResults<Aggs>>;\n }\n\n // === Transform ===\n\n transform(t: Transformation): Relation<T> {\n return transform(this as any, t) as unknown as Relation<T>;\n }\n\n // === Dynamic ===\n\n autowrap(options?: AutowrapOptions): Relation<Tuple> {\n return autowrap(this as any, options) as Relation<Tuple>;\n }\n\n // === Non-relational ===\n\n one(): T {\n return one(this as any) as T;\n }\n\n toArray(): T[] {\n return this.tuples;\n }\n\n yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]> {\n return yByX(this as any, y as AttrName, x as AttrName) as Record<T[X] & PropertyKey, T[Y]>;\n }\n\n isEqual(right: any): boolean {\n return isEqual(this as any, right as any);\n }\n\n}\n","import { MemoryRelation } from \"@/Relation\";\n\nexport const isRelation = (op) => {\n return op != null && op.constructor === MemoryRelation;\n}\n","import { OperationalOperand, Relation, RelationOperand, Renaming, RenamingFunc, Tuple, JoinKeys, AttrName } from \"@/types\";\nimport { MemoryRelation } from '@/Relation';\nimport { isRelation } from \"./isRelation\";\n\nconst valueKey = (value: unknown): unknown => {\n if (isRelation(value)) {\n // For nested relations, convert to sorted array of tuple keys for comparison\n const tuples = (value as Relation).toArray();\n const keys = tuples.map(t => tupleKey(t)).sort();\n return keys;\n }\n return value;\n}\n\n/**\n * Generates a unique string key for a tuple, used for equality comparison and deduplication.\n * Handles nested relations by converting them to sorted tuple keys.\n *\n * @example\n * tupleKey({ name: 'Alice', age: 30 })\n * // => '[[\"age\",30],[\"name\",\"Alice\"]]'\n *\n * @example\n * tupleKey({ id: 1, items: Bmg([{ x: 1 }, { x: 2 }]) })\n * // => '[[\"id\",1],[\"items\",[...]]]' (nested relation converted to sorted keys)\n */\nexport const tupleKey = (tuple: Tuple): string => {\n const entries = Object.entries(tuple).map(([k, v]) => [k, valueKey(v)]);\n return JSON.stringify(entries.sort(([a], [b]) => (a as string).localeCompare(b as string)));\n}\n\n/**\n * Removes duplicate tuples from an array, preserving order of first occurrence.\n * Uses tupleKey() for equality comparison.\n *\n * @example\n * deduplicate([\n * { id: 1, name: 'Alice' },\n * { id: 2, name: 'Bob' },\n * { id: 1, name: 'Alice' }, // duplicate\n * ])\n * // => [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]\n */\nexport const deduplicate = (tuples: Tuple[]): Tuple[] => {\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of tuples) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n return result;\n}\n\n/**\n * Converts a RelationOperand (Relation or Tuple[]) to an OperationalOperand\n * that provides a uniform interface for iteration and output.\n *\n * @example\n * // With array input, output remains array\n * const op = toOperationalOperand([{ id: 1 }]);\n * [...op.tuples()]; // => [{ id: 1 }]\n * op.output([{ id: 2 }]); // => [{ id: 2 }]\n *\n * @example\n * // With Relation input, output is a new Relation\n * const op = toOperationalOperand(Bmg([{ id: 1 }]));\n * [...op.tuples()]; // => [{ id: 1 }]\n * op.output([{ id: 2 }]); // => Bmg([{ id: 2 }])\n */\nexport const toOperationalOperand = (operand: RelationOperand): OperationalOperand => {\n if (Array.isArray(operand)) {\n return {\n tuples: () => operand,\n output: (tuples) => tuples,\n };\n } else if (isRelation(operand)) {\n return {\n tuples: () => (operand as Relation).toArray(),\n output: (tuples) => new MemoryRelation(tuples),\n };\n } else {\n throw `Unable to iterate ${operand}`\n }\n}\n\n/**\n * Converts a Renaming (object or function) to a RenamingFunc.\n *\n * @example\n * // Object renaming\n * const fn = toRenamingFunc({ name: 'fullName', age: 'years' });\n * fn('name'); // => 'fullName'\n * fn('age'); // => 'years'\n * fn('other'); // => 'other' (unchanged)\n *\n * @example\n * // Function renaming (passed through)\n * const fn = toRenamingFunc(attr => attr.toUpperCase());\n * fn('name'); // => 'NAME'\n */\nexport const toRenamingFunc = (renaming: Renaming): RenamingFunc => {\n if (typeof(renaming) === 'function') {\n return renaming;\n } else {\n return (attr) => renaming[attr] || attr;\n }\n}\n\nexport const error = (msg: string) => {\n throw(msg);\n}\n\n// Join helpers\n\n/**\n * Finds attribute names that exist in both left and right tuple arrays.\n * Used for natural joins when no explicit keys are provided.\n *\n * @example\n * const left = [{ id: 1, name: 'Alice', city: 'NYC' }];\n * const right = [{ city: 'NYC', country: 'USA' }];\n * getCommonAttrs(left, right);\n * // => ['city']\n *\n * @example\n * const left = [{ a: 1, b: 2 }];\n * const right = [{ b: 2, c: 3 }];\n * getCommonAttrs(left, right);\n * // => ['b']\n */\nexport const getCommonAttrs = (left: Tuple[], right: Tuple[]): AttrName[] => {\n if (left.length === 0 || right.length === 0) return [];\n const leftAttrs = new Set(Object.keys(left[0]));\n const rightAttrs = Object.keys(right[0]);\n return rightAttrs.filter(attr => leftAttrs.has(attr));\n}\n\n/**\n * Normalizes JoinKeys to a Record<AttrName, AttrName> mapping left attrs to right attrs.\n *\n * @example\n * // undefined => use common attributes\n * normalizeKeys(undefined, [{ id: 1, city: 'NYC' }], [{ city: 'NYC' }]);\n * // => { city: 'city' }\n *\n * @example\n * // Array of common attribute names\n * normalizeKeys(['city', 'country'], leftTuples, rightTuples);\n * // => { city: 'city', country: 'country' }\n *\n * @example\n * // Object mapping left attr to right attr\n * normalizeKeys({ city: 'location' }, leftTuples, rightTuples);\n * // => { city: 'location' }\n */\nexport const normalizeKeys = (keys: JoinKeys | undefined, leftTuples: Tuple[], rightTuples: Tuple[]): Record<AttrName, AttrName> => {\n if (!keys) {\n const common = getCommonAttrs(leftTuples, rightTuples);\n return common.reduce((acc, attr) => {\n acc[attr] = attr;\n return acc;\n }, {} as Record<AttrName, AttrName>);\n }\n if (Array.isArray(keys)) {\n return keys.reduce((acc, attr) => {\n acc[attr] = attr;\n return acc;\n }, {} as Record<AttrName, AttrName>);\n }\n return keys;\n}\n\n/**\n * Checks if two tuples match on the specified key mapping.\n *\n * @example\n * const keyMap = { city: 'location' };\n * tuplesMatch({ id: 1, city: 'NYC' }, { location: 'NYC', pop: 8 }, keyMap);\n * // => true (left.city === right.location)\n *\n * @example\n * const keyMap = { city: 'city' };\n * tuplesMatch({ city: 'NYC' }, { city: 'LA' }, keyMap);\n * // => false\n */\nexport const tuplesMatch = (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>): boolean => {\n for (const [leftAttr, rightAttr] of Object.entries(keyMap)) {\n if (left[leftAttr] !== right[rightAttr]) return false;\n }\n return true;\n}\n\n/**\n * Creates a string key from a tuple's join attributes for fast Set-based lookups.\n * Used by matching/not_matching for efficient semi-join operations.\n *\n * @example\n * const keyMap = { first: 'fname', last: 'lname' };\n *\n * // Left side uses left attr names (keys of keyMap)\n * matchKey({ id: 1, first: 'John', last: 'Doe' }, keyMap, 'left');\n * // => '\"John\"|\"Doe\"'\n *\n * // Right side uses right attr names (values of keyMap)\n * matchKey({ fname: 'John', lname: 'Doe', age: 30 }, keyMap, 'right');\n * // => '\"John\"|\"Doe\"'\n */\nexport const matchKey = (tuple: Tuple, keyMap: Record<AttrName, AttrName>, side: 'left' | 'right'): string => {\n const attrs = side === 'left' ? Object.keys(keyMap) : Object.values(keyMap);\n const values = attrs.map(attr => JSON.stringify(tuple[attr]));\n return values.join('|');\n}\n\n/**\n * Removes join key attributes from a right tuple when merging.\n * Used to avoid duplicate columns in join results.\n *\n * @example\n * const keyMap = { city: 'location' };\n * projectOutKeys({ location: 'NYC', country: 'USA', pop: 8 }, keyMap);\n * // => { country: 'USA', pop: 8 } (location removed)\n *\n * @example\n * const keyMap = { a: 'a', b: 'b' };\n * projectOutKeys({ a: 1, b: 2, c: 3 }, keyMap);\n * // => { c: 3 } (a and b removed)\n */\nexport const projectOutKeys = (tuple: Tuple, keyMap: Record<AttrName, AttrName>): Tuple => {\n const rightKeys = new Set(Object.values(keyMap));\n const result: Tuple = {};\n for (const [attr, value] of Object.entries(tuple)) {\n if (!rightKeys.has(attr)) {\n result[attr] = value;\n }\n }\n return result;\n}\n","import { toPredicateFunc } from \"../support/toPredicateFunc\";\nimport { RelationOperand, Predicate, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const restrict = (operand: RelationOperand, p: Predicate): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const f = toPredicateFunc(p)\n const kept: Tuple[] = [];\n for (const tuple of iterable) {\n if (f(tuple)) kept.push(tuple);\n }\n return op.output(kept)\n}\n","import { toPredicateFunc } from \"../support/toPredicateFunc\";\nimport { RelationOperand, Predicate, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const exclude = (operand: RelationOperand, p: Predicate): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const f = toPredicateFunc(p)\n const kept: Tuple[] = [];\n for (const tuple of iterable) {\n if (!f(tuple)) kept.push(tuple);\n }\n return op.output(kept)\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const constants = (operand: RelationOperand, consts: Tuple): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n result.push({ ...tuple, ...consts });\n }\n return op.output(result)\n}\n","import { RelationOperand, Renaming, Tuple } from \"../types\";\nimport { toOperationalOperand, toRenamingFunc } from \"./_helpers\";\n\nexport const rename = (operand: RelationOperand, renaming: Renaming): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const renamingFunc = toRenamingFunc(renaming)\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const renamed = Object.keys(tuple).reduce((memo, attr) => {\n memo[renamingFunc(attr)] = tuple[attr];\n return memo;\n }, {})\n result.push(renamed);\n }\n return op.output(result)\n}\n","import { PrefixOptions, RelationOperand } from \"../types\";\nimport { rename } from \"./rename\";\n\nexport const prefix = (operand: RelationOperand, pfx: string, options?: PrefixOptions): RelationOperand => {\n const except = new Set(options?.except ?? []);\n return rename(operand, (attr) => except.has(attr) ? attr : `${pfx}${attr}`);\n}\n","import { RelationOperand, SuffixOptions } from \"../types\";\nimport { rename } from \"./rename\";\n\nexport const suffix = (operand: RelationOperand, sfx: string, options?: SuffixOptions): RelationOperand => {\n const except = new Set(options?.except ?? []);\n return rename(operand, (attr) => except.has(attr) ? attr : `${attr}${sfx}`);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const project = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const projected = attrs.reduce((memo, attr) => {\n if (attr in tuple) {\n memo[attr] = tuple[attr];\n }\n return memo;\n }, {} as Tuple);\n result.push(projected);\n }\n return op.output(deduplicate(result));\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const allbut = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const excluded = new Set(attrs);\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const projected = Object.keys(tuple).reduce((memo, attr) => {\n if (!excluded.has(attr)) {\n memo[attr] = tuple[attr];\n }\n return memo;\n }, {} as Tuple);\n result.push(projected);\n }\n return op.output(deduplicate(result));\n}\n","import { RelationOperand, Extension, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const extend = (operand: RelationOperand, extension: Extension): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n for (const tuple of iterable) {\n const extended = { ...tuple };\n for (const [attr, spec] of Object.entries(extension)) {\n if (typeof spec === 'function') {\n extended[attr] = spec(tuple);\n } else {\n extended[attr] = tuple[spec];\n }\n }\n result.push(extended);\n }\n return op.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const union = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const seen = new Set<string>();\n const result: Tuple[] = [];\n\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n for (const tuple of opRight.tuples()) {\n const key = tupleKey(tuple);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const minus = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (!rightKeys.has(key) && !seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const intersect = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n const seen = new Set<string>();\n const result: Tuple[] = [];\n for (const tuple of opLeft.tuples()) {\n const key = tupleKey(tuple);\n if (rightKeys.has(key) && !seen.has(key)) {\n seen.add(key);\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, matchKey } from \"./_helpers\";\n\nexport const matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n\n const rightKeys = new Set<string>();\n for (const tuple of rightTuples) {\n rightKeys.add(matchKey(tuple, keyMap, 'right'));\n }\n\n const result: Tuple[] = [];\n for (const tuple of leftTuples) {\n if (rightKeys.has(matchKey(tuple, keyMap, 'left'))) {\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, matchKey } from \"./_helpers\";\n\nexport const not_matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n\n const rightKeys = new Set<string>();\n for (const tuple of rightTuples) {\n rightKeys.add(matchKey(tuple, keyMap, 'right'));\n }\n\n const result: Tuple[] = [];\n for (const tuple of leftTuples) {\n if (!rightKeys.has(matchKey(tuple, keyMap, 'left'))) {\n result.push(tuple);\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from \"./_helpers\";\n\nconst mergeTuples = (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>): Tuple => {\n return { ...left, ...projectOutKeys(right, keyMap) };\n}\n\nexport const join = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n result.push(mergeTuples(leftTuple, rightTuple, keyMap));\n }\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch } from \"./_helpers\";\n\nconst getRightAttrs = (rightTuples: Tuple[], keyMap: Record<AttrName, AttrName>): AttrName[] => {\n if (rightTuples.length === 0) return [];\n const rightKeys = new Set(Object.values(keyMap));\n return Object.keys(rightTuples[0]).filter(attr => !rightKeys.has(attr));\n}\n\nconst mergeTuples = (left: Tuple, right: Tuple | null, rightAttrs: AttrName[]): Tuple => {\n const result = { ...left };\n for (const attr of rightAttrs) {\n result[attr] = right ? right[attr] : null;\n }\n return result;\n}\n\nexport const left_join = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const rightAttrs = getRightAttrs(rightTuples, keyMap);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n let matched = false;\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n result.push(mergeTuples(leftTuple, rightTuple, rightAttrs));\n matched = true;\n }\n }\n if (!matched) {\n result.push(mergeTuples(leftTuple, null, rightAttrs));\n }\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, deduplicate } from \"./_helpers\";\n\nexport const cross_product = (left: RelationOperand, right: RelationOperand): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const result: Tuple[] = [];\n\n for (const l of leftTuples) {\n for (const r of rightTuples) {\n result.push({ ...r, ...l });\n }\n }\n\n return opLeft.output(deduplicate(result));\n}\n\nexport { cross_product as cross_join };\n","import { RelationOperand, JoinKeys, Tuple, AttrName } from \"../types\";\nimport { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from \"./_helpers\";\nimport { MemoryRelation } from \"@/Relation\";\n\nexport const image = (left: RelationOperand, right: RelationOperand, as: AttrName, keys?: JoinKeys): RelationOperand => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n const leftTuples = [...opLeft.tuples()];\n const rightTuples = [...opRight.tuples()];\n const keyMap = normalizeKeys(keys, leftTuples, rightTuples);\n const result: Tuple[] = [];\n\n for (const leftTuple of leftTuples) {\n const matches: Tuple[] = [];\n for (const rightTuple of rightTuples) {\n if (tuplesMatch(leftTuple, rightTuple, keyMap)) {\n matches.push(projectOutKeys(rightTuple, keyMap));\n }\n }\n result.push({\n ...leftTuple,\n [as]: new MemoryRelation(matches)\n });\n }\n\n return opLeft.output(result);\n}\n","import { RelationOperand, AttrName, Tuple, Aggregator, Aggregators } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nconst groupKey = (tuple: Tuple, by: AttrName[]): string => {\n const keyParts = by.map(attr => JSON.stringify(tuple[attr]));\n return keyParts.join('|');\n}\n\nconst pickAttrs = (tuple: Tuple, attrs: AttrName[]): Tuple => {\n return attrs.reduce((acc, attr) => {\n acc[attr] = tuple[attr];\n return acc;\n }, {} as Tuple);\n}\n\nconst applyAggregator = (tuples: Tuple[], agg: Aggregator): unknown => {\n if (typeof agg === 'function') {\n return agg(tuples);\n }\n\n const spec = typeof agg === 'string' ? { op: agg, attr: '' } : agg;\n const { op, attr } = spec;\n\n switch (op) {\n case 'count':\n return tuples.length;\n\n case 'sum': {\n return tuples.reduce((sum, t) => sum + (Number(t[attr]) || 0), 0);\n }\n\n case 'min': {\n const values = tuples.map(t => t[attr]).filter(v => v !== undefined && v !== null);\n return values.length > 0 ? Math.min(...values.map(Number)) : null;\n }\n\n case 'max': {\n const values = tuples.map(t => t[attr]).filter(v => v !== undefined && v !== null);\n return values.length > 0 ? Math.max(...values.map(Number)) : null;\n }\n\n case 'avg': {\n const values = tuples.map(t => Number(t[attr])).filter(v => !isNaN(v));\n return values.length > 0 ? values.reduce((a, b) => a + b, 0) / values.length : null;\n }\n\n case 'collect': {\n return tuples.map(t => t[attr]);\n }\n\n default:\n throw new Error(`Unknown aggregator: ${op}`);\n }\n}\n\nexport const summarize = (\n operand: RelationOperand,\n by: AttrName[],\n aggs: Aggregators\n): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n\n // Group tuples\n const groups = new Map<string, Tuple[]>();\n for (const tuple of tuples) {\n const key = groupKey(tuple, by);\n if (!groups.has(key)) {\n groups.set(key, []);\n }\n groups.get(key)!.push(tuple);\n }\n\n // Apply aggregators to each group\n const result: Tuple[] = [];\n for (const groupTuples of groups.values()) {\n const row: Tuple = pickAttrs(groupTuples[0], by);\n for (const [resultAttr, agg] of Object.entries(aggs)) {\n row[resultAttr] = applyAggregator(groupTuples, agg);\n }\n result.push(row);\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\nimport { MemoryRelation } from \"@/Relation\";\n\nconst groupKey = (tuple: Tuple, byAttrs: AttrName[]): string => {\n const keyParts = byAttrs.map(attr => JSON.stringify(tuple[attr]));\n return keyParts.join('|');\n}\n\nconst pickAttrs = (tuple: Tuple, attrs: AttrName[]): Tuple => {\n return attrs.reduce((acc, attr) => {\n acc[attr] = tuple[attr];\n return acc;\n }, {} as Tuple);\n}\n\nexport const group = (operand: RelationOperand, attrs: AttrName[], as: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n\n if (tuples.length === 0) {\n return op.output([]);\n }\n\n // Determine which attributes to keep at the top level (all except grouped ones)\n const allAttrs = Object.keys(tuples[0]);\n const groupedSet = new Set(attrs);\n const byAttrs = allAttrs.filter(a => !groupedSet.has(a));\n\n // Group tuples\n const groups = new Map<string, { base: Tuple, nested: Tuple[] }>();\n for (const tuple of tuples) {\n const key = groupKey(tuple, byAttrs);\n if (!groups.has(key)) {\n groups.set(key, {\n base: pickAttrs(tuple, byAttrs),\n nested: []\n });\n }\n groups.get(key)!.nested.push(pickAttrs(tuple, attrs));\n }\n\n // Build result with nested relations\n const result: Tuple[] = [];\n for (const { base, nested } of groups.values()) {\n result.push({\n ...base,\n [as]: new MemoryRelation(nested)\n });\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple, Relation } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\nimport { isRelation } from \"./isRelation\";\n\nconst toTupleArray = (value: unknown): Tuple[] => {\n if (isRelation(value)) {\n return (value as Relation).toArray();\n }\n if (Array.isArray(value)) {\n return value;\n }\n throw new Error(`Value is not a relation or array`);\n}\n\nexport const ungroup = (operand: RelationOperand, attr: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const tuples = [...op.tuples()];\n const result: Tuple[] = [];\n\n for (const tuple of tuples) {\n const nested = toTupleArray(tuple[attr]);\n\n // Get base attributes (all except the grouped one)\n const base: Tuple = {};\n for (const [key, value] of Object.entries(tuple)) {\n if (key !== attr) {\n base[key] = value;\n }\n }\n\n // Flatten each nested tuple\n for (const nestedTuple of nested) {\n result.push({\n ...base,\n ...nestedTuple\n });\n }\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const wrap = (operand: RelationOperand, attrs: AttrName[], as: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const wrappedSet = new Set(attrs);\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped: Tuple = {};\n const remaining: Tuple = {};\n\n for (const [key, value] of Object.entries(tuple)) {\n if (wrappedSet.has(key)) {\n wrapped[key] = value;\n } else {\n remaining[key] = value;\n }\n }\n\n result.push({\n ...remaining,\n [as]: wrapped\n });\n }\n\n return op.output(result);\n}\n","import { RelationOperand, AttrName, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const unwrap = (operand: RelationOperand, attr: AttrName): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped = tuple[attr] as Tuple;\n if (typeof wrapped !== 'object' || wrapped === null || Array.isArray(wrapped)) {\n throw new Error(`Attribute '${attr}' is not a tuple (object)`);\n }\n\n const unwrapped: Tuple = {};\n for (const [key, value] of Object.entries(tuple)) {\n if (key !== attr) {\n unwrapped[key] = value;\n }\n }\n\n result.push({\n ...unwrapped,\n ...wrapped\n });\n }\n\n return op.output(result);\n}\n","import { AutowrapOptions, RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const autowrap = (operand: RelationOperand, options?: AutowrapOptions): RelationOperand => {\n const sep = options?.separator ?? '_';\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const wrapped: Tuple = {};\n for (const [attr, value] of Object.entries(tuple)) {\n const parts = attr.split(sep);\n if (parts.length === 1) {\n wrapped[attr] = value;\n } else {\n const [prefix, ...rest] = parts;\n wrapped[prefix] = wrapped[prefix] ?? {};\n (wrapped[prefix] as Tuple)[rest.join(sep)] = value;\n }\n }\n result.push(wrapped);\n }\n\n return op.output(result);\n}\n","import { RelationOperand, Transformation, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const transform = (operand: RelationOperand, transformation: Transformation): RelationOperand => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const result: Tuple[] = [];\n\n for (const tuple of iterable) {\n const transformed: Tuple = {};\n\n for (const [attr, value] of Object.entries(tuple)) {\n transformed[attr] = applyTransformation(value, attr, transformation);\n }\n\n result.push(transformed);\n }\n\n return op.output(result);\n}\n\nconst applyTransformation = (value: unknown, attr: string, transformation: Transformation): unknown => {\n if (typeof transformation === 'function') {\n // Single function - apply to all values\n return transformation(value);\n } else if (Array.isArray(transformation)) {\n // Array of functions - chain them\n return transformation.reduce((v, fn) => fn(v), value);\n } else {\n // Object with attr-specific transformers\n const fn = transformation[attr];\n if (fn) {\n if (Array.isArray(fn)) {\n return fn.reduce((v, f) => f(v), value);\n }\n return fn(value);\n }\n return value;\n }\n}\n","import { RelationOperand } from \"../types\";\nimport { toOperationalOperand, tupleKey } from \"./_helpers\";\n\nexport const isEqual = (left: RelationOperand, right: RelationOperand): boolean => {\n const opLeft = toOperationalOperand(left);\n const opRight = toOperationalOperand(right);\n\n const leftKeys = new Set<string>();\n for (const tuple of opLeft.tuples()) {\n leftKeys.add(tupleKey(tuple));\n }\n\n const rightKeys = new Set<string>();\n for (const tuple of opRight.tuples()) {\n rightKeys.add(tupleKey(tuple));\n }\n\n if (leftKeys.size !== rightKeys.size) {\n return false;\n }\n\n for (const key of leftKeys) {\n if (!rightKeys.has(key)) {\n return false;\n }\n }\n\n return true;\n}\n","import { RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand, error } from \"./_helpers\";\n\nexport const one = (operand: RelationOperand): Tuple => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n let tuple;\n for (const t of iterable) {\n if (tuple) {\n return error('More than one tuple found');\n } else {\n tuple = t;\n }\n }\n if (tuple) return tuple;\n return error('Relation is empty');\n}\n","import { AttrName, RelationOperand, Tuple } from \"../types\";\nimport { toOperationalOperand } from \"./_helpers\";\n\nexport const yByX = (operand: RelationOperand, y: AttrName, x: AttrName): Tuple => {\n const op = toOperationalOperand(operand);\n const iterable = op.tuples();\n const hash = {};\n for (const tuple of iterable) {\n hash[`${tuple[x]}`] = tuple[y];\n }\n return hash;\n}\n","export * from './operators';\nexport * from './types';\nexport { LIB_DEFINITIONS } from './lib-definitions';\n\nimport { MemoryRelation } from './Relation';\nimport { isRelation } from './operators';\n\n/**\n * Creates a new in-memory relation from an array of tuples.\n *\n * @typeParam T - The tuple type. Inferred from input or explicitly provided.\n *\n * @example\n * // Untyped usage (backwards compatible)\n * const r = Bmg([{ id: 1, name: 'Alice' }]);\n *\n * @example\n * // Typed usage with explicit type parameter\n * interface Person { id: number; name: string }\n * const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);\n * r.project(['id']); // Autocomplete suggests 'id' | 'name'\n *\n * @example\n * // Type is inferred from input\n * const r = Bmg([{ id: 1, name: 'Alice' }] as const);\n */\nexport function Bmg<T>(tuples: T[]): MemoryRelation<T> {\n return new MemoryRelation<T>(tuples);\n}\n\nBmg.isRelation = isRelation;\n","// Auto-generated from types.ts\n// Run 'npm run generate:lib-definitions' to regenerate\n\nexport const LIB_DEFINITIONS = `\n/**\n * Type definitions for Bmg.js relational algebra library.\n *\n * This file defines all types needed for type-safe relational operations:\n * - Base types (AttrName, Tuple)\n * - Utility types for transformations (Renamed, Prefixed, Joined, etc.)\n * - The Relation interface with all operators\n * - Helper types for predicates, extensions, aggregators, etc.\n */\n\n// ============================================================================\n// Base Types\n// ============================================================================\n\n/** Attribute name in a tuple */\ntype AttrName = string\n\n/** A tuple is a record mapping attribute names to values */\ntype Tuple = Record<AttrName, unknown>\n\n// ============================================================================\n// Rename Types\n// ============================================================================\n\n/** Map from old attribute names to new attribute names */\ntype RenameMap<T> = { [K in keyof T]?: string };\n\n/** Transform tuple type by renaming keys according to RenameMap */\ntype Renamed<T, R extends RenameMap<T>> = {\n [K in keyof T as K extends keyof R ? (R[K] extends string ? R[K] : K) : K]: T[K];\n};\n\n// ============================================================================\n// Prefix/Suffix Types\n// ============================================================================\n\n/** Prefix all keys except those in Except */\ntype Prefixed<T, P extends string, Except extends keyof T = never> = {\n [K in keyof T as K extends Except ? K : \\`\\${P}\\${K & string}\\`]: T[K];\n};\n\n/** Suffix all keys except those in Except */\ntype Suffixed<T, S extends string, Except extends keyof T = never> = {\n [K in keyof T as K extends Except ? K : \\`\\${K & string}\\${S}\\`]: T[K];\n};\n\n// ============================================================================\n// Join Types\n// ============================================================================\n\n/** Extract common keys between two tuple types */\ntype CommonKeys<L, R> = Extract<keyof L, keyof R>;\n\n/** Result of inner join: L & R with R's common keys removed */\ntype Joined<L, R> = L & Omit<R, CommonKeys<L, R>>;\n\n/** Result of left join: L & optional R attributes (common keys removed) */\ntype LeftJoined<L, R> = L & Partial<Omit<R, CommonKeys<L, R>>>;\n\n/**\n * Typed join keys for array form: keys must exist on BOTH operands.\n * Example: suppliers.join(parts, ['city']) - 'city' must be a key of both.\n */\ntype TypedJoinKeysArray<L, R> = (keyof L & keyof R & string)[];\n\n/**\n * Typed join keys for object form: maps left keys to right keys.\n * Example: suppliers.join(parts, { sid: 'supplier_id' })\n * - Left key (sid) must exist on L\n * - Right key (supplier_id) must exist on R\n */\ntype TypedJoinKeysObject<L, R> = { [K in keyof L & string]?: keyof R & string };\n\n// ============================================================================\n// Wrap/Unwrap Types\n// ============================================================================\n\n/** Result of wrap: remove wrapped attrs, add nested object */\ntype Wrapped<T, K extends keyof T, As extends string> =\n Omit<T, K> & Record<As, Pick<T, K>>;\n\n/** Result of unwrap: remove object attr, spread its properties */\ntype Unwrapped<T, K extends keyof T> =\n T[K] extends Record<string, unknown> ? Omit<T, K> & T[K] : Omit<T, K>;\n\n/** Result of ungroup: remove relation attr, flatten its tuple type */\ntype Ungrouped<T, K extends keyof T> =\n T[K] extends Relation<infer N> ? Omit<T, K> & N : Omit<T, K>;\n\n// ============================================================================\n// Aggregator Types\n// ============================================================================\n\ntype AggregatorName = 'count' | 'sum' | 'min' | 'max' | 'avg' | 'collect'\ntype AggregatorSpec = { op: AggregatorName, attr: AttrName }\ntype AggregatorFunc = (tuples: Tuple[]) => unknown\ntype Aggregator = AggregatorName | AggregatorSpec | AggregatorFunc\ntype Aggregators = Record<AttrName, Aggregator>\n\n/** Infer result type from aggregator specification */\ntype AggregatorResult<A> =\n A extends 'count' ? number :\n A extends { op: 'count' } ? number :\n A extends { op: 'sum' | 'avg' | 'min' | 'max' } ? number | null :\n A extends { op: 'collect' } ? unknown[] :\n A extends (tuples: Tuple[]) => infer R ? R :\n unknown;\n\n/** Map aggregator definitions to their result types */\ntype AggregatorResults<Aggs extends Record<string, unknown>> = {\n [K in keyof Aggs]: AggregatorResult<Aggs[K]>;\n};\n\n// ============================================================================\n// Predicate Types\n// ============================================================================\n\n/** Predicate function that receives a typed tuple */\ntype TypedPredicateFunc<T> = (t: T) => boolean\n\n/** Predicate: either a partial tuple for equality matching, or a function */\ntype TypedPredicate<T> = Partial<T> | TypedPredicateFunc<T>\n\n// Legacy predicate types (for backwards compatibility with standalone operators)\ntype PredicateFunc = ((t: Tuple) => any)\ntype Predicate = Tuple | PredicateFunc\n\n// ============================================================================\n// Extension Types\n// ============================================================================\n\n/** Extension function that receives a typed tuple */\ntype TypedExtensionFunc<T, R> = (tuple: T) => R\n\n/** Extension definition: function returning value, or attribute name to copy */\ntype TypedExtension<T, E extends Record<string, unknown>> = {\n [K in keyof E]: TypedExtensionFunc<T, E[K]> | keyof T;\n}\n\ntype ExtensionFunc = (tuple: Tuple) => unknown\ntype Extension = Record<AttrName, ExtensionFunc | AttrName>\n\n// ============================================================================\n// Other Helper Types\n// ============================================================================\n\ninterface PrefixOptions {\n except?: AttrName[]\n}\n\ninterface SuffixOptions {\n except?: AttrName[]\n}\n\ninterface AutowrapOptions {\n separator?: string\n}\n\ntype Renaming = RenamingObj | RenamingFunc\ntype RenamingFunc = (attr: AttrName) => AttrName\ntype RenamingObj = Record<AttrName, AttrName>\n\ntype JoinKeys = AttrName[] | Record<AttrName, AttrName>\n\ntype TransformFunc = (value: unknown) => unknown\ntype Transformation = TransformFunc | TransformFunc[] | Record<AttrName, TransformFunc | TransformFunc[]>\n\n// ============================================================================\n// Relation Interface\n// ============================================================================\n\n/**\n * Relation interface with generic type parameter for tuple type.\n * Default parameter \\`Tuple\\` ensures backwards compatibility.\n *\n * @typeParam T - The tuple type for this relation. Defaults to \\`Tuple\\` (Record<string, unknown>).\n *\n * @example\n * // Untyped usage (backwards compatible)\n * const r = Bmg([{ id: 1 }]); // Relation<Tuple>\n *\n * @example\n * // Typed usage with full type safety\n * interface Person { id: number; name: string }\n * const r = Bmg<Person>([{ id: 1, name: 'Alice' }]);\n * r.project(['id']); // Relation<{ id: number }>\n */\ninterface Relation<T = Tuple> {\n // === Type-preserving operators ===\n\n restrict(p: TypedPredicate<T>): Relation<T>\n where(p: TypedPredicate<T>): Relation<T>\n exclude(p: TypedPredicate<T>): Relation<T>\n\n // === Projection operators ===\n\n project<K extends keyof T>(attrs: K[]): Relation<Pick<T, K>>\n allbut<K extends keyof T>(attrs: K[]): Relation<Omit<T, K>>\n\n // === Extension operators ===\n\n extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): Relation<T & E>\n constants<C extends Tuple>(consts: C): Relation<T & C>\n\n // === Rename operators ===\n\n rename<R extends RenameMap<T>>(r: R): Relation<Renamed<T, R>>\n prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): Relation<Prefixed<T, P, Ex>>\n suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): Relation<Suffixed<T, S, Ex>>\n\n // === Set operators (require same type) ===\n\n union(right: RelationOperand<T>): Relation<T>\n minus(right: RelationOperand<T>): Relation<T>\n intersect(right: RelationOperand<T>): Relation<T>\n\n // === Semi-join operators (preserve left type) ===\n\n matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>\n not_matching<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<T>\n\n // === Join operators ===\n\n join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<Joined<T, R>>\n left_join<R>(right: RelationOperand<R>, keys?: TypedJoinKeysArray<T, R> | TypedJoinKeysObject<T, R>): Relation<LeftJoined<T, R>>\n cross_product<R>(right: RelationOperand<R>): Relation<T & R>\n cross_join<R>(right: RelationOperand<R>): Relation<T & R>\n\n // === Nesting operators ===\n\n 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>>>>\n group<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Omit<T, K> & Record<As, Relation<Pick<T, K>>>>\n ungroup<K extends keyof T>(attr: K): Relation<Ungrouped<T, K>>\n wrap<K extends keyof T, As extends string>(attrs: K[], as: As): Relation<Wrapped<T, K, As>>\n unwrap<K extends keyof T>(attr: K): Relation<Unwrapped<T, K>>\n\n // === Aggregation ===\n\n summarize<By extends keyof T, Aggs extends Aggregators>(by: By[], aggs: Aggs): Relation<Pick<T, By> & AggregatorResults<Aggs>>\n\n // === Transform ===\n\n transform(t: Transformation): Relation<T>\n\n // === Dynamic (loses type precision) ===\n\n autowrap(options?: AutowrapOptions): Relation<Tuple>\n\n // === Non-relational ===\n\n one(): T\n yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>\n toArray(): T[]\n isEqual(right: any): boolean\n}\n\n// ============================================================================\n// Operands\n// ============================================================================\n\ntype RelationOperand<T = Tuple> = Relation<T> | T[]\n\ninterface OperationalOperand<T = Tuple> {\n tuples(): Iterable<T>\n output(tuples: T[]): RelationOperand<T>\n}\n\n// ============================================================================\n// Bmg Function Declaration\n// ============================================================================\n\n/** Create a relation from an array of tuples */\ndeclare function Bmg<T>(tuples: T[]): Relation<T>\ndeclare namespace Bmg {\n function isRelation(op: unknown): boolean\n}\n`\n"],"names":["toPredicateFunc","p","expected","t","Object","keys","every","k","MemoryRelation","tuples","this","_proto","prototype","restrict","where","exclude","project","attrs","allbut","extend","e","constants","consts","rename","r","prefix","pfx","options","suffix","sfx","union","right","minus","intersect","matching","not_matching","join","left_join","cross_product","cross_join","image","as","group","ungroup","attr","wrap","unwrap","summarize","by","aggs","transform","autowrap","one","toArray","yByX","y","x","isEqual","isRelation","op","constructor","tupleKey","tuple","entries","map","_ref","v","value","sort","JSON","stringify","_ref2","_ref3","localeCompare","deduplicate","_step","seen","Set","result","_iterator","_createForOfIteratorHelperLoose","done","key","has","add","push","toOperationalOperand","operand","Array","isArray","output","error","msg","normalizeKeys","leftTuples","rightTuples","reduce","acc","left","length","leftAttrs","filter","getCommonAttrs","tuplesMatch","keyMap","_i","_Object$entries","_Object$entries$_i","matchKey","side","values","projectOutKeys","rightKeys","_i2","_Object$entries2","_Object$entries2$_i","iterable","f","kept","_extends","renaming","renamingFunc","toRenamingFunc","_loop","renamed","memo","_options$except","except","projected","excluded","extension","extended","spec","opLeft","opRight","_step2","_iterator2","concat","mergeTuples","leftTuple","rightTuple","rightAttrs","getRightAttrs","_step3","matched","_iterator3","l","_extends2","matches","groupKey","pickAttrs","applyAggregator","agg","sum","Number","Math","min","apply","max","isNaN","a","b","Error","groups","Map","set","get","groupTuples","row","byAttrs","allAttrs","groupedSet","base","nested","_step2$value","toTupleArray","wrappedSet","wrapped","remaining","unwrapped","_options$separator","sep","separator","parts","split","_wrapped$prefix","rest","_arrayLikeToArray","slice","transformation","transformed","applyTransformation","fn","leftKeys","size","hash","Bmg"],"mappings":"4/BAEa,IAAAA,EAAkB,SAACC,GAC9B,GAAkB,mBAAPA,EACT,OAAOA,EAEP,IAAMC,EAAWD,EACjB,OAAO,SAACE,GACN,OAAOC,OAAOC,KAAKH,GAAUI,MAAM,SAAAC,GAAC,OAAIJ,EAAEI,KAAOL,EAASK,EAAE,EAC9D,CAEJ,ECgDaC,eAAc,WAEzB,SAAAA,EAAoBC,QAAAA,YAAA,EAAAC,KAAMD,OAANA,EAClBC,KAAKD,OAASA,CAChB,CAAC,IAAAE,EAAAH,EAAAI,UAoJA,OApJAD,EAIDE,SAAA,SAASZ,GACP,OAAOY,EAASH,KAAaT,EAC/B,EAACU,EAEDG,MAAA,SAAMb,GACJ,OAA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