@enspirit/bmg-js 1.0.2 → 1.1.1
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/README.md +3 -2
- package/dist/AsyncRelation/Base.d.ts +47 -0
- package/dist/AsyncRelation/index.d.ts +25 -0
- package/dist/Relation/Memory.d.ts +2 -1
- package/dist/Relation/index.d.ts +1 -1
- package/dist/async/Relation/Base.d.ts +47 -0
- package/dist/async/Relation/index.d.ts +25 -0
- package/dist/async/operators/_helpers.d.ts +16 -0
- package/dist/async/operators/autowrap.d.ts +7 -0
- package/dist/async/operators/constants.d.ts +6 -0
- package/dist/async/operators/cross_product.d.ts +9 -0
- package/dist/async/operators/extend.d.ts +7 -0
- package/dist/async/operators/group.d.ts +7 -0
- package/dist/async/operators/image.d.ts +8 -0
- package/dist/async/operators/index.d.ts +28 -0
- package/dist/async/operators/intersect.d.ts +7 -0
- package/dist/async/operators/isEqual.d.ts +7 -0
- package/dist/async/operators/join.d.ts +7 -0
- package/dist/async/operators/left_join.d.ts +8 -0
- package/dist/async/operators/matching.d.ts +7 -0
- package/dist/async/operators/minus.d.ts +7 -0
- package/dist/async/operators/not_matching.d.ts +7 -0
- package/dist/async/operators/one.d.ts +6 -0
- package/dist/async/operators/prefix.d.ts +6 -0
- package/dist/async/operators/project.d.ts +10 -0
- package/dist/async/operators/rename.d.ts +6 -0
- package/dist/async/operators/restrict.d.ts +14 -0
- package/dist/async/operators/suffix.d.ts +6 -0
- package/dist/async/operators/summarize.d.ts +8 -0
- package/dist/async/operators/toArray.d.ts +5 -0
- package/dist/async/operators/transform.d.ts +9 -0
- package/dist/async/operators/ungroup.d.ts +7 -0
- package/dist/async/operators/union.d.ts +6 -0
- package/dist/async/operators/unwrap.d.ts +6 -0
- package/dist/async/operators/wrap.d.ts +6 -0
- package/dist/async/operators/yByX.d.ts +7 -0
- package/dist/async/types.d.ts +58 -0
- package/dist/async-operators/_helpers.d.ts +16 -0
- package/dist/async-operators/autowrap.d.ts +7 -0
- package/dist/async-operators/constants.d.ts +6 -0
- package/dist/async-operators/cross_product.d.ts +9 -0
- package/dist/async-operators/extend.d.ts +7 -0
- package/dist/async-operators/group.d.ts +7 -0
- package/dist/async-operators/image.d.ts +8 -0
- package/dist/async-operators/index.d.ts +28 -0
- package/dist/async-operators/intersect.d.ts +7 -0
- package/dist/async-operators/isEqual.d.ts +7 -0
- package/dist/async-operators/join.d.ts +7 -0
- package/dist/async-operators/left_join.d.ts +8 -0
- package/dist/async-operators/matching.d.ts +7 -0
- package/dist/async-operators/minus.d.ts +7 -0
- package/dist/async-operators/not_matching.d.ts +7 -0
- package/dist/async-operators/one.d.ts +6 -0
- package/dist/async-operators/prefix.d.ts +6 -0
- package/dist/async-operators/project.d.ts +10 -0
- package/dist/async-operators/rename.d.ts +6 -0
- package/dist/async-operators/restrict.d.ts +14 -0
- package/dist/async-operators/suffix.d.ts +6 -0
- package/dist/async-operators/summarize.d.ts +8 -0
- package/dist/async-operators/toArray.d.ts +5 -0
- package/dist/async-operators/transform.d.ts +9 -0
- package/dist/async-operators/ungroup.d.ts +7 -0
- package/dist/async-operators/union.d.ts +6 -0
- package/dist/async-operators/unwrap.d.ts +6 -0
- package/dist/async-operators/wrap.d.ts +6 -0
- package/dist/async-operators/yByX.d.ts +7 -0
- package/dist/async-types.d.ts +58 -0
- package/dist/async.d.ts +4 -0
- package/dist/bmg.cjs +1 -1
- package/dist/bmg.cjs.map +1 -1
- package/dist/bmg.modern.js +1 -1
- package/dist/bmg.modern.js.map +1 -1
- package/dist/bmg.module.js +1 -1
- package/dist/bmg.module.js.map +1 -1
- package/dist/bmg.umd.js +1 -1
- package/dist/bmg.umd.js.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/lib-definitions.d.ts +1 -1
- package/dist/operators/index.d.ts +1 -30
- package/dist/operators/isEqual.d.ts +1 -2
- package/dist/operators/isRelation.d.ts +2 -1
- package/dist/sync/Relation/Memory.d.ts +46 -0
- package/dist/sync/Relation/index.d.ts +1 -0
- package/dist/sync/operators/_helpers.d.ts +142 -0
- package/dist/sync/operators/allbut.d.ts +2 -0
- package/dist/sync/operators/autowrap.d.ts +2 -0
- package/dist/sync/operators/constants.d.ts +2 -0
- package/dist/sync/operators/cross_product.d.ts +3 -0
- package/dist/sync/operators/exclude.d.ts +2 -0
- package/dist/sync/operators/extend.d.ts +2 -0
- package/dist/sync/operators/group.d.ts +2 -0
- package/dist/sync/operators/image.d.ts +2 -0
- package/dist/sync/operators/index.d.ts +30 -0
- package/dist/sync/operators/intersect.d.ts +2 -0
- package/dist/sync/operators/isEqual.d.ts +1 -0
- package/dist/sync/operators/isRelation.d.ts +2 -0
- package/dist/sync/operators/join.d.ts +2 -0
- package/dist/sync/operators/left_join.d.ts +2 -0
- package/dist/sync/operators/matching.d.ts +2 -0
- package/dist/sync/operators/minus.d.ts +2 -0
- package/dist/sync/operators/not_matching.d.ts +2 -0
- package/dist/sync/operators/one.d.ts +2 -0
- package/dist/sync/operators/prefix.d.ts +2 -0
- package/dist/sync/operators/project.d.ts +2 -0
- package/dist/sync/operators/rename.d.ts +2 -0
- package/dist/sync/operators/restrict.d.ts +2 -0
- package/dist/sync/operators/suffix.d.ts +2 -0
- package/dist/sync/operators/summarize.d.ts +2 -0
- package/dist/sync/operators/transform.d.ts +2 -0
- package/dist/sync/operators/ungroup.d.ts +2 -0
- package/dist/sync/operators/union.d.ts +2 -0
- package/dist/sync/operators/unwrap.d.ts +2 -0
- package/dist/sync/operators/wrap.d.ts +2 -0
- package/dist/sync/operators/yByX.d.ts +2 -0
- package/dist/types.d.ts +7 -0
- package/dist/writer/Text.d.ts +68 -0
- package/dist/writer/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Relation/index.ts +2 -1
- package/src/async/Relation/Base.ts +245 -0
- package/src/async/Relation/index.ts +31 -0
- package/src/async/operators/_helpers.ts +60 -0
- package/src/async/operators/autowrap.ts +31 -0
- package/src/async/operators/constants.ts +26 -0
- package/src/async/operators/cross_product.ts +39 -0
- package/src/async/operators/extend.ts +36 -0
- package/src/async/operators/group.ts +61 -0
- package/src/async/operators/image.ts +42 -0
- package/src/async/operators/index.ts +28 -0
- package/src/async/operators/intersect.ts +28 -0
- package/src/async/operators/isEqual.ts +39 -0
- package/src/async/operators/join.ts +39 -0
- package/src/async/operators/left_join.ts +55 -0
- package/src/async/operators/matching.ts +39 -0
- package/src/async/operators/minus.ts +28 -0
- package/src/async/operators/not_matching.ts +39 -0
- package/src/async/operators/one.ts +25 -0
- package/src/async/operators/prefix.ts +15 -0
- package/src/async/operators/project.ts +64 -0
- package/src/async/operators/rename.ts +33 -0
- package/src/async/operators/restrict.ts +61 -0
- package/src/async/operators/suffix.ts +15 -0
- package/src/async/operators/summarize.ts +90 -0
- package/src/async/operators/toArray.ts +18 -0
- package/src/async/operators/transform.ts +43 -0
- package/src/async/operators/ungroup.ts +43 -0
- package/src/async/operators/union.ts +29 -0
- package/src/async/operators/unwrap.ts +31 -0
- package/src/async/operators/wrap.ts +32 -0
- package/src/async/operators/yByX.ts +19 -0
- package/src/async/types.ts +86 -0
- package/src/async.ts +4 -0
- package/src/index.ts +17 -3
- package/src/lib-definitions.ts +11 -0
- package/src/operators/index.ts +2 -31
- package/src/{Relation → sync/Relation}/Memory.ts +9 -1
- package/src/sync/Relation/index.ts +1 -0
- package/src/{operators → sync/operators}/_helpers.ts +1 -1
- package/src/{operators → sync/operators}/allbut.ts +1 -1
- package/src/{operators → sync/operators}/autowrap.ts +1 -1
- package/src/{operators → sync/operators}/constants.ts +1 -1
- package/src/{operators → sync/operators}/cross_product.ts +1 -1
- package/src/{operators → sync/operators}/exclude.ts +2 -2
- package/src/{operators → sync/operators}/extend.ts +1 -1
- package/src/{operators → sync/operators}/group.ts +2 -2
- package/src/{operators → sync/operators}/image.ts +2 -2
- package/src/sync/operators/index.ts +31 -0
- package/src/{operators → sync/operators}/intersect.ts +1 -1
- package/src/{operators → sync/operators}/isEqual.ts +1 -2
- package/src/sync/operators/isRelation.ts +6 -0
- package/src/{operators → sync/operators}/join.ts +1 -1
- package/src/{operators → sync/operators}/left_join.ts +1 -1
- package/src/{operators → sync/operators}/matching.ts +1 -1
- package/src/{operators → sync/operators}/minus.ts +1 -1
- package/src/{operators → sync/operators}/not_matching.ts +1 -1
- package/src/{operators → sync/operators}/one.ts +1 -1
- package/src/{operators → sync/operators}/prefix.ts +1 -1
- package/src/{operators → sync/operators}/project.ts +1 -1
- package/src/{operators → sync/operators}/rename.ts +1 -1
- package/src/{operators → sync/operators}/restrict.ts +2 -2
- package/src/{operators → sync/operators}/suffix.ts +1 -1
- package/src/{operators → sync/operators}/summarize.ts +1 -1
- package/src/{operators → sync/operators}/transform.ts +1 -1
- package/src/{operators → sync/operators}/ungroup.ts +1 -1
- package/src/{operators → sync/operators}/union.ts +1 -1
- package/src/{operators → sync/operators}/unwrap.ts +1 -1
- package/src/sync/operators/where.ts +1 -0
- package/src/{operators → sync/operators}/wrap.ts +1 -1
- package/src/{operators → sync/operators}/yByX.ts +1 -1
- package/src/types.ts +11 -0
- package/src/writer/Text.ts +415 -0
- package/src/writer/index.ts +1 -0
- package/src/operators/isRelation.ts +0 -5
- /package/{src/operators/where.ts → dist/sync/operators/where.d.ts} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AsyncRelationOperand } from '../types';
|
|
2
|
+
import type { AttrName, Tuple } from '../../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps specified attributes into a nested object.
|
|
6
|
+
*/
|
|
7
|
+
export async function* wrap<T>(
|
|
8
|
+
operand: AsyncRelationOperand<T>,
|
|
9
|
+
attrs: AttrName[],
|
|
10
|
+
as: AttrName
|
|
11
|
+
): AsyncIterable<Tuple> {
|
|
12
|
+
const wrappedSet = new Set(attrs);
|
|
13
|
+
|
|
14
|
+
for await (const tuple of operand) {
|
|
15
|
+
const t = tuple as Tuple;
|
|
16
|
+
const wrapped: Tuple = {};
|
|
17
|
+
const remaining: Tuple = {};
|
|
18
|
+
|
|
19
|
+
for (const [key, value] of Object.entries(t)) {
|
|
20
|
+
if (wrappedSet.has(key)) {
|
|
21
|
+
wrapped[key] = value;
|
|
22
|
+
} else {
|
|
23
|
+
remaining[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
yield {
|
|
28
|
+
...remaining,
|
|
29
|
+
[as]: wrapped
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AsyncRelationOperand } from '../types';
|
|
2
|
+
import type { AttrName, Tuple } from '../../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Builds a key-value map from two attributes.
|
|
6
|
+
* Terminal operation - returns a Promise.
|
|
7
|
+
*/
|
|
8
|
+
export const yByX = async <T>(
|
|
9
|
+
operand: AsyncRelationOperand<T>,
|
|
10
|
+
y: AttrName,
|
|
11
|
+
x: AttrName
|
|
12
|
+
): Promise<Tuple> => {
|
|
13
|
+
const hash: Tuple = {};
|
|
14
|
+
for await (const tuple of operand) {
|
|
15
|
+
const t = tuple as Tuple;
|
|
16
|
+
hash[`${t[x]}`] = t[y];
|
|
17
|
+
}
|
|
18
|
+
return hash;
|
|
19
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Tuple, TypedPredicate, Relation, TypedExtension, RenameMap, Renamed, Prefixed, Suffixed, Transformation, JoinKeys, AttrName, Aggregators, AutowrapOptions, TextOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Async version of the Relation interface.
|
|
5
|
+
* Operations are lazy - they build a pipeline that executes only when
|
|
6
|
+
* a terminal method (one(), toArray()) is awaited.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The tuple type for this relation.
|
|
9
|
+
*/
|
|
10
|
+
export interface AsyncRelation<T = Tuple> {
|
|
11
|
+
// === Type-preserving operators ===
|
|
12
|
+
|
|
13
|
+
restrict(p: TypedPredicate<T>): AsyncRelation<T>
|
|
14
|
+
where(p: TypedPredicate<T>): AsyncRelation<T>
|
|
15
|
+
exclude(p: TypedPredicate<T>): AsyncRelation<T>
|
|
16
|
+
|
|
17
|
+
// === Projection operators ===
|
|
18
|
+
|
|
19
|
+
project<K extends keyof T>(attrs: K[]): AsyncRelation<Pick<T, K>>
|
|
20
|
+
allbut<K extends keyof T>(attrs: K[]): AsyncRelation<Omit<T, K>>
|
|
21
|
+
|
|
22
|
+
// === Extension operators ===
|
|
23
|
+
|
|
24
|
+
extend<E extends Record<string, unknown>>(e: TypedExtension<T, E>): AsyncRelation<T & E>
|
|
25
|
+
constants<C extends Tuple>(consts: C): AsyncRelation<T & C>
|
|
26
|
+
|
|
27
|
+
// === Rename operators ===
|
|
28
|
+
|
|
29
|
+
rename<R extends RenameMap<T>>(r: R): AsyncRelation<Renamed<T, R>>
|
|
30
|
+
prefix<P extends string, Ex extends keyof T = never>(pfx: P, options?: { except?: Ex[] }): AsyncRelation<Prefixed<T, P, Ex>>
|
|
31
|
+
suffix<S extends string, Ex extends keyof T = never>(sfx: S, options?: { except?: Ex[] }): AsyncRelation<Suffixed<T, S, Ex>>
|
|
32
|
+
transform(t: Transformation): AsyncRelation<T>
|
|
33
|
+
|
|
34
|
+
// === Set operations ===
|
|
35
|
+
|
|
36
|
+
union(other: AsyncRelationOperand<T>): AsyncRelation<T>
|
|
37
|
+
minus(other: AsyncRelationOperand<T>): AsyncRelation<T>
|
|
38
|
+
intersect(other: AsyncRelationOperand<T>): AsyncRelation<T>
|
|
39
|
+
|
|
40
|
+
// === Semi-joins ===
|
|
41
|
+
|
|
42
|
+
matching<U = Tuple>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T>
|
|
43
|
+
not_matching<U = Tuple>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T>
|
|
44
|
+
|
|
45
|
+
// === Joins ===
|
|
46
|
+
|
|
47
|
+
join<U = Tuple>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T & U>
|
|
48
|
+
left_join<U = Tuple>(other: AsyncRelationOperand<U>, keys?: JoinKeys): AsyncRelation<T & Partial<U>>
|
|
49
|
+
cross_product<U = Tuple>(other: AsyncRelationOperand<U>): AsyncRelation<T & U>
|
|
50
|
+
cross_join<U = Tuple>(other: AsyncRelationOperand<U>): AsyncRelation<T & U>
|
|
51
|
+
|
|
52
|
+
// === Nesting/Grouping ===
|
|
53
|
+
|
|
54
|
+
group<K extends keyof T>(attrs: K[], as: AttrName): AsyncRelation<Omit<T, K> & Record<string, Relation<Pick<T, K>>>>
|
|
55
|
+
ungroup(attr: AttrName): AsyncRelation<Tuple>
|
|
56
|
+
wrap<K extends keyof T>(attrs: K[], as: AttrName): AsyncRelation<Omit<T, K> & Record<string, Pick<T, K>>>
|
|
57
|
+
unwrap(attr: AttrName): AsyncRelation<Tuple>
|
|
58
|
+
image<U = Tuple>(other: AsyncRelationOperand<U>, as: AttrName, keys?: JoinKeys): AsyncRelation<T & Record<string, Relation<U>>>
|
|
59
|
+
summarize<K extends keyof T>(by: K[], aggs: Aggregators): AsyncRelation<Pick<T, K> & Tuple>
|
|
60
|
+
autowrap(options?: AutowrapOptions): AsyncRelation<Tuple>
|
|
61
|
+
|
|
62
|
+
// === Terminal operations (return Promises) ===
|
|
63
|
+
|
|
64
|
+
one(): Promise<T>
|
|
65
|
+
toArray(): Promise<T[]>
|
|
66
|
+
toRelation(): Promise<Relation<T>>
|
|
67
|
+
yByX(y: AttrName, x: AttrName): Promise<Tuple>
|
|
68
|
+
toText(options?: TextOptions): Promise<string>
|
|
69
|
+
|
|
70
|
+
// === Async iteration ===
|
|
71
|
+
|
|
72
|
+
[Symbol.asyncIterator](): AsyncIterator<T>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* What can be passed as an operand to async operators.
|
|
77
|
+
*/
|
|
78
|
+
export type AsyncRelationOperand<T = Tuple> = AsyncRelation<T> | AsyncIterable<T>
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Async version of OperationalOperand for internal use by operators.
|
|
82
|
+
*/
|
|
83
|
+
export interface AsyncOperationalOperand<T = Tuple> {
|
|
84
|
+
tuples(): AsyncIterable<T>
|
|
85
|
+
output(tuples: AsyncIterable<T>): AsyncRelationOperand<T>
|
|
86
|
+
}
|
package/src/async.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export * from './operators';
|
|
1
|
+
export * from './sync/operators';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export { LIB_DEFINITIONS } from './lib-definitions';
|
|
4
|
+
export { toText } from './writer';
|
|
5
|
+
export type { TextOptions, BorderStyleName } from './writer';
|
|
4
6
|
|
|
5
|
-
import { MemoryRelation } from './Relation';
|
|
6
|
-
import { isRelation } from './operators';
|
|
7
|
+
import { MemoryRelation } from './sync/Relation';
|
|
8
|
+
import { isRelation } from './sync/operators';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Creates a new in-memory relation from an array of tuples.
|
|
@@ -29,3 +31,15 @@ export function Bmg<T>(tuples: T[]): MemoryRelation<T> {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
Bmg.isRelation = isRelation;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* DEE - The relation with no attributes and exactly one tuple.
|
|
37
|
+
* This is the identity element for natural join.
|
|
38
|
+
*/
|
|
39
|
+
export const DEE = new MemoryRelation<Record<string, never>>([{}]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* DUM - The relation with no attributes and no tuples.
|
|
43
|
+
* This is the identity element for union.
|
|
44
|
+
*/
|
|
45
|
+
export const DUM = new MemoryRelation<Record<string, never>>([]);
|
package/src/lib-definitions.ts
CHANGED
|
@@ -152,6 +152,13 @@ interface PrefixOptions {
|
|
|
152
152
|
except?: AttrName[]
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
interface TextOptions {
|
|
156
|
+
/** Precision for floating point numbers (default: 3) */
|
|
157
|
+
floatPrecision?: number;
|
|
158
|
+
/** Maximum width to trim output at */
|
|
159
|
+
trimAt?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
interface SuffixOptions {
|
|
156
163
|
except?: AttrName[]
|
|
157
164
|
}
|
|
@@ -256,6 +263,10 @@ interface Relation<T = Tuple> {
|
|
|
256
263
|
yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>
|
|
257
264
|
toArray(): T[]
|
|
258
265
|
isEqual(right: any): boolean
|
|
266
|
+
|
|
267
|
+
// === Display ===
|
|
268
|
+
|
|
269
|
+
toText(options?: TextOptions): string
|
|
259
270
|
}
|
|
260
271
|
|
|
261
272
|
// ============================================================================
|
package/src/operators/index.ts
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from '
|
|
3
|
-
export * from './exclude'
|
|
4
|
-
export * from './constants'
|
|
5
|
-
export * from './rename'
|
|
6
|
-
export * from './prefix'
|
|
7
|
-
export * from './suffix'
|
|
8
|
-
export * from './project'
|
|
9
|
-
export * from './allbut'
|
|
10
|
-
export * from './extend'
|
|
11
|
-
export * from './union'
|
|
12
|
-
export * from './minus'
|
|
13
|
-
export * from './intersect'
|
|
14
|
-
export * from './matching'
|
|
15
|
-
export * from './not_matching'
|
|
16
|
-
export * from './join'
|
|
17
|
-
export * from './left_join'
|
|
18
|
-
export * from './cross_product'
|
|
19
|
-
export * from './image'
|
|
20
|
-
export * from './summarize'
|
|
21
|
-
export * from './group'
|
|
22
|
-
export * from './ungroup'
|
|
23
|
-
export * from './wrap'
|
|
24
|
-
export * from './unwrap'
|
|
25
|
-
export * from './autowrap'
|
|
26
|
-
export * from './transform'
|
|
27
|
-
|
|
28
|
-
export * from './isRelation'
|
|
29
|
-
export * from './isEqual'
|
|
30
|
-
export * from './one'
|
|
31
|
-
export * from './yByX'
|
|
1
|
+
// Re-export sync operators for backward compatibility
|
|
2
|
+
export * from '../sync/operators';
|
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
AutowrapOptions,
|
|
35
35
|
Relation,
|
|
36
36
|
RelationOperand,
|
|
37
|
+
TextOptions,
|
|
37
38
|
Transformation,
|
|
38
39
|
Tuple,
|
|
39
40
|
TypedPredicate,
|
|
@@ -50,7 +51,8 @@ import type {
|
|
|
50
51
|
AggregatorResults,
|
|
51
52
|
TypedJoinKeysArray,
|
|
52
53
|
TypedJoinKeysObject,
|
|
53
|
-
} from "
|
|
54
|
+
} from "../../types";
|
|
55
|
+
import { toText } from "../../writer";
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* In-memory implementation of the Relation interface.
|
|
@@ -211,4 +213,10 @@ export class MemoryRelation<T = Tuple> implements Relation<T> {
|
|
|
211
213
|
return isEqual(this as any, right as any);
|
|
212
214
|
}
|
|
213
215
|
|
|
216
|
+
// === Display ===
|
|
217
|
+
|
|
218
|
+
toText(options?: TextOptions): string {
|
|
219
|
+
return toText(this as any, options);
|
|
220
|
+
}
|
|
221
|
+
|
|
214
222
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Memory';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationalOperand, Relation, RelationOperand, Renaming, RenamingFunc, Tuple, JoinKeys, AttrName } from "@/types";
|
|
2
|
-
import { MemoryRelation } from '@/Relation';
|
|
2
|
+
import { MemoryRelation } from '@/sync/Relation';
|
|
3
3
|
import { isRelation } from "./isRelation";
|
|
4
4
|
|
|
5
5
|
const valueKey = (value: unknown): unknown => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, AttrName, Tuple } from "
|
|
1
|
+
import { RelationOperand, AttrName, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, deduplicate } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const allbut = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AutowrapOptions, RelationOperand, Tuple } from "
|
|
1
|
+
import { AutowrapOptions, RelationOperand, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const autowrap = (operand: RelationOperand, options?: AutowrapOptions): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, Tuple } from "
|
|
1
|
+
import { RelationOperand, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, deduplicate } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const cross_product = (left: RelationOperand, right: RelationOperand): RelationOperand => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toPredicateFunc } from "
|
|
2
|
-
import { RelationOperand, Predicate, Tuple } from "
|
|
1
|
+
import { toPredicateFunc } from "../../support/toPredicateFunc";
|
|
2
|
+
import { RelationOperand, Predicate, Tuple } from "../../types";
|
|
3
3
|
import { toOperationalOperand } from "./_helpers";
|
|
4
4
|
|
|
5
5
|
export const exclude = (operand: RelationOperand, p: Predicate): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, Extension, Tuple } from "
|
|
1
|
+
import { RelationOperand, Extension, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const extend = (operand: RelationOperand, extension: Extension): RelationOperand => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RelationOperand, AttrName, Tuple } from "
|
|
1
|
+
import { RelationOperand, AttrName, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
|
-
import { MemoryRelation } from "@/Relation";
|
|
3
|
+
import { MemoryRelation } from "@/sync/Relation";
|
|
4
4
|
|
|
5
5
|
const groupKey = (tuple: Tuple, byAttrs: AttrName[]): string => {
|
|
6
6
|
const keyParts = byAttrs.map(attr => JSON.stringify(tuple[attr]));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RelationOperand, JoinKeys, Tuple, AttrName } from "
|
|
1
|
+
import { RelationOperand, JoinKeys, Tuple, AttrName } from "../../types";
|
|
2
2
|
import { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from "./_helpers";
|
|
3
|
-
import { MemoryRelation } from "@/Relation";
|
|
3
|
+
import { MemoryRelation } from "@/sync/Relation";
|
|
4
4
|
|
|
5
5
|
export const image = (left: RelationOperand, right: RelationOperand, as: AttrName, keys?: JoinKeys): RelationOperand => {
|
|
6
6
|
const opLeft = toOperationalOperand(left);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export * from './restrict'
|
|
2
|
+
export * from './where'
|
|
3
|
+
export * from './exclude'
|
|
4
|
+
export * from './constants'
|
|
5
|
+
export * from './rename'
|
|
6
|
+
export * from './prefix'
|
|
7
|
+
export * from './suffix'
|
|
8
|
+
export * from './project'
|
|
9
|
+
export * from './allbut'
|
|
10
|
+
export * from './extend'
|
|
11
|
+
export * from './union'
|
|
12
|
+
export * from './minus'
|
|
13
|
+
export * from './intersect'
|
|
14
|
+
export * from './matching'
|
|
15
|
+
export * from './not_matching'
|
|
16
|
+
export * from './join'
|
|
17
|
+
export * from './left_join'
|
|
18
|
+
export * from './cross_product'
|
|
19
|
+
export * from './image'
|
|
20
|
+
export * from './summarize'
|
|
21
|
+
export * from './group'
|
|
22
|
+
export * from './ungroup'
|
|
23
|
+
export * from './wrap'
|
|
24
|
+
export * from './unwrap'
|
|
25
|
+
export * from './autowrap'
|
|
26
|
+
export * from './transform'
|
|
27
|
+
|
|
28
|
+
export * from './isRelation'
|
|
29
|
+
export * from './isEqual'
|
|
30
|
+
export * from './one'
|
|
31
|
+
export * from './yByX'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { RelationOperand } from "../types";
|
|
2
1
|
import { toOperationalOperand, tupleKey } from "./_helpers";
|
|
3
2
|
|
|
4
|
-
export const isEqual = (left:
|
|
3
|
+
export const isEqual = (left: any, right: any): boolean => {
|
|
5
4
|
const opLeft = toOperationalOperand(left);
|
|
6
5
|
const opRight = toOperationalOperand(right);
|
|
7
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, JoinKeys, Tuple, AttrName } from "
|
|
1
|
+
import { RelationOperand, JoinKeys, Tuple, AttrName } from "../../types";
|
|
2
2
|
import { toOperationalOperand, normalizeKeys, tuplesMatch, projectOutKeys } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
const mergeTuples = (left: Tuple, right: Tuple, keyMap: Record<AttrName, AttrName>): Tuple => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, JoinKeys, Tuple, AttrName } from "
|
|
1
|
+
import { RelationOperand, JoinKeys, Tuple, AttrName } from "../../types";
|
|
2
2
|
import { toOperationalOperand, normalizeKeys, tuplesMatch } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
const getRightAttrs = (rightTuples: Tuple[], keyMap: Record<AttrName, AttrName>): AttrName[] => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, JoinKeys, Tuple } from "
|
|
1
|
+
import { RelationOperand, JoinKeys, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, normalizeKeys, matchKey } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, JoinKeys, Tuple } from "
|
|
1
|
+
import { RelationOperand, JoinKeys, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, normalizeKeys, matchKey } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const not_matching = (left: RelationOperand, right: RelationOperand, keys?: JoinKeys): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrefixOptions, RelationOperand } from "
|
|
1
|
+
import { PrefixOptions, RelationOperand } from "../../types";
|
|
2
2
|
import { rename } from "./rename";
|
|
3
3
|
|
|
4
4
|
export const prefix = (operand: RelationOperand, pfx: string, options?: PrefixOptions): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, AttrName, Tuple } from "
|
|
1
|
+
import { RelationOperand, AttrName, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, deduplicate } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const project = (operand: RelationOperand, attrs: AttrName[]): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, Renaming, Tuple } from "
|
|
1
|
+
import { RelationOperand, Renaming, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand, toRenamingFunc } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const rename = (operand: RelationOperand, renaming: Renaming): RelationOperand => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toPredicateFunc } from "
|
|
2
|
-
import { RelationOperand, Predicate, Tuple } from "
|
|
1
|
+
import { toPredicateFunc } from "../../support/toPredicateFunc";
|
|
2
|
+
import { RelationOperand, Predicate, Tuple } from "../../types";
|
|
3
3
|
import { toOperationalOperand } from "./_helpers";
|
|
4
4
|
|
|
5
5
|
export const restrict = (operand: RelationOperand, p: Predicate): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, SuffixOptions } from "
|
|
1
|
+
import { RelationOperand, SuffixOptions } from "../../types";
|
|
2
2
|
import { rename } from "./rename";
|
|
3
3
|
|
|
4
4
|
export const suffix = (operand: RelationOperand, sfx: string, options?: SuffixOptions): RelationOperand => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, AttrName, Tuple, Aggregator, Aggregators } from "
|
|
1
|
+
import { RelationOperand, AttrName, Tuple, Aggregator, Aggregators } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
const groupKey = (tuple: Tuple, by: AttrName[]): string => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, Transformation, Tuple } from "
|
|
1
|
+
import { RelationOperand, Transformation, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const transform = (operand: RelationOperand, transformation: Transformation): RelationOperand => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { restrict as where } from './restrict';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelationOperand, AttrName, Tuple } from "
|
|
1
|
+
import { RelationOperand, AttrName, Tuple } from "../../types";
|
|
2
2
|
import { toOperationalOperand } from "./_helpers";
|
|
3
3
|
|
|
4
4
|
export const wrap = (operand: RelationOperand, attrs: AttrName[], as: AttrName): RelationOperand => {
|
package/src/types.ts
CHANGED
|
@@ -148,6 +148,13 @@ export interface PrefixOptions {
|
|
|
148
148
|
except?: AttrName[]
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
export interface TextOptions {
|
|
152
|
+
/** Precision for floating point numbers (default: 3) */
|
|
153
|
+
floatPrecision?: number;
|
|
154
|
+
/** Maximum width to trim output at */
|
|
155
|
+
trimAt?: number;
|
|
156
|
+
}
|
|
157
|
+
|
|
151
158
|
export interface SuffixOptions {
|
|
152
159
|
except?: AttrName[]
|
|
153
160
|
}
|
|
@@ -252,6 +259,10 @@ export interface Relation<T = Tuple> {
|
|
|
252
259
|
yByX<Y extends keyof T, X extends keyof T>(y: Y, x: X): Record<T[X] & PropertyKey, T[Y]>
|
|
253
260
|
toArray(): T[]
|
|
254
261
|
isEqual(right: any): boolean
|
|
262
|
+
|
|
263
|
+
// === Display ===
|
|
264
|
+
|
|
265
|
+
toText(options?: TextOptions): string
|
|
255
266
|
}
|
|
256
267
|
|
|
257
268
|
// ============================================================================
|