@bjornpagen/bumbledb 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COOKBOOK.md +155 -136
- package/README.md +3 -7
- package/dist/capacity.d.ts +14 -1
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js.map +1 -1
- package/dist/db.d.ts +77 -109
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +121 -339
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +11 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -10
- package/dist/index.js.map +1 -1
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +8 -1
- package/dist/lower.js.map +1 -1
- package/dist/native.d.ts +69 -50
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +162 -122
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +26 -22
- package/dist/query/atom.js.map +1 -1
- package/dist/query/find.d.ts +18 -35
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +13 -32
- package/dist/query/find.js.map +1 -1
- package/dist/query/lower.d.ts +113 -122
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +336 -260
- package/dist/query/lower.js.map +1 -1
- package/dist/query/parse-ir.d.ts +12 -0
- package/dist/query/parse-ir.d.ts.map +1 -0
- package/dist/query/parse-ir.js +71 -0
- package/dist/query/parse-ir.js.map +1 -0
- package/dist/query/run.d.ts +2 -2
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +2 -13
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +4 -16
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +1 -6
- package/dist/query/scope.js.map +1 -1
- package/dist/schema.js +2 -2
- package/dist/schema.js.map +1 -1
- package/dist/statements.d.ts +15 -9
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +14 -9
- package/dist/statements.js.map +1 -1
- package/package.json +2 -2
- package/src/capacity.ts +24 -1
- package/src/db.ts +182 -443
- package/src/index.ts +9 -23
- package/src/lower.ts +8 -1
- package/src/native.ts +69 -42
- package/src/query/atom.ts +255 -165
- package/src/query/find.ts +39 -80
- package/src/query/lower.ts +578 -432
- package/src/query/parse-ir.ts +82 -0
- package/src/query/run.ts +2 -14
- package/src/query/scope.ts +3 -21
- package/src/schema.ts +2 -2
- package/src/statements.ts +33 -17
- package/dist/order.d.ts +0 -87
- package/dist/order.d.ts.map +0 -1
- package/dist/order.js +0 -153
- package/dist/order.js.map +0 -1
- package/dist/query/predicate.d.ts +0 -91
- package/dist/query/predicate.d.ts.map +0 -1
- package/dist/query/predicate.js +0 -156
- package/dist/query/predicate.js.map +0 -1
- package/src/order.ts +0 -234
- package/src/query/predicate.ts +0 -269
package/dist/query/find.d.ts
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
* vocabulary, mirroring the IR's aggregate roster exactly
|
|
4
4
|
* (`bumbledb/crates/bumbledb/src/ir.rs` `AggOp`/`FindTerm`;
|
|
5
5
|
* `docs/architecture/20-query-ir.md` § aggregation): `count` (nullary),
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `r.sum(w)` — and are typed by the variable's own descriptor.
|
|
6
|
+
* `sum`/`min`/`max` (over an orderable variable or the measure), and
|
|
7
|
+
* `pack` (the coalescing fold — RELATION-SHAPED, the result position
|
|
8
|
+
* interval-typed). Aggregates fold VARIABLES by reference — `r.sum(w)` —
|
|
9
|
+
* and are typed by the variable's own descriptor.
|
|
11
10
|
*
|
|
12
11
|
* `select(strings)` is DEAD: the head is a `find` RECORD, whose KEYS name
|
|
13
12
|
* the answer columns (`find({ total: r.count(), owner: h })`). The keys are
|
|
@@ -23,27 +22,23 @@ import type { SchemaClasses } from "#law.ts";
|
|
|
23
22
|
import type { IntervalVarOk, NumericVarOk, OrderVarOk } from "#query/atom.ts";
|
|
24
23
|
import type { AnyVar, Duration, MintSlotOf } from "#query/scope.ts";
|
|
25
24
|
/** One aggregate operator name of the find vocabulary. */
|
|
26
|
-
type AggOpName = "count" | "
|
|
25
|
+
type AggOpName = "count" | "sum" | "min" | "max" | "pack";
|
|
27
26
|
/**
|
|
28
|
-
* One aggregate find VALUE: the op
|
|
29
|
-
* REFERENCE
|
|
30
|
-
* variable's own descriptor types the result.
|
|
27
|
+
* One aggregate find VALUE: the op and the variable (or measure) it folds
|
|
28
|
+
* BY REFERENCE. The variable's own descriptor types the result.
|
|
31
29
|
*/
|
|
32
|
-
interface Agg<Op extends AggOpName, Over extends AnyVar | Duration | undefined
|
|
30
|
+
interface Agg<Op extends AggOpName, Over extends AnyVar | Duration | undefined> {
|
|
33
31
|
readonly agg: Op;
|
|
34
32
|
readonly over: Over;
|
|
35
|
-
readonly key: Key;
|
|
36
33
|
}
|
|
37
34
|
/** Any aggregate find value. */
|
|
38
|
-
type AnyAgg = Agg<AggOpName, AnyVar | Duration | undefined
|
|
35
|
+
type AnyAgg = Agg<AggOpName, AnyVar | Duration | undefined>;
|
|
39
36
|
/** One find entry: a projected variable, the measure, or an aggregate. */
|
|
40
37
|
type FindEntry = AnyVar | Duration | AnyAgg;
|
|
41
38
|
/** The `find` record: column name → find entry. Keys ARE the answer columns. */
|
|
42
39
|
type FindShape = Readonly<Record<string, FindEntry>>;
|
|
43
40
|
/** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
|
|
44
41
|
declare function count(): Agg<"count", undefined>;
|
|
45
|
-
/** |the distinct values of the variable across the group|, `bigint`; legal over every type. */
|
|
46
|
-
declare function countDistinct<const V extends AnyVar>(over: V): Agg<"countDistinct", V>;
|
|
47
42
|
/**
|
|
48
43
|
* Exact checked sum over a NUMERIC (u64/i64) variable — wide accumulator,
|
|
49
44
|
* one finalize range check; overflow is the engine's typed runtime error —
|
|
@@ -55,22 +50,12 @@ declare function sum<const O extends AnyVar | Duration>(over: O): Agg<"sum", O>;
|
|
|
55
50
|
declare function min<const O extends AnyVar | Duration>(over: O): Agg<"min", O>;
|
|
56
51
|
/** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
|
|
57
52
|
declare function max<const O extends AnyVar | Duration>(over: O): Agg<"max", O>;
|
|
58
|
-
/**
|
|
59
|
-
* Arg-restriction toward the maximum of `key` (`ir::AggOp::ArgMax`): the
|
|
60
|
-
* group's binding set is restricted to the bindings attaining the extreme
|
|
61
|
-
* of the orderable key, and `value` is the carried payload — a tie yields
|
|
62
|
-
* every attaining row. All Arg entries of one query share one key and one
|
|
63
|
-
* direction; Arg and fold aggregates never mix (both the engine's rules).
|
|
64
|
-
*/
|
|
65
|
-
declare function argMax<const V extends AnyVar, const K extends AnyVar>(value: V, key: K): Agg<"argMax", V, K>;
|
|
66
|
-
/** Arg-restriction toward the minimum of `key`; rules as {@link argMax}. */
|
|
67
|
-
declare function argMin<const V extends AnyVar, const K extends AnyVar>(value: V, key: K): Agg<"argMin", V, K>;
|
|
68
53
|
/**
|
|
69
54
|
* The coalescing fold (Snodgrass coalesce, `ir::AggOp::Pack`): per group,
|
|
70
55
|
* the maximal disjoint half-open segments of the union of the group's
|
|
71
56
|
* interval point sets — RELATION-SHAPED, one answer row per (group, maximal
|
|
72
57
|
* segment), the result position carrying one interval of the input's element
|
|
73
|
-
* type. At most one `pack` per find, never beside a fold
|
|
58
|
+
* type. At most one `pack` per find, never beside a fold entry.
|
|
74
59
|
*/
|
|
75
60
|
declare function pack<const V extends AnyVar>(over: V): Agg<"pack", V>;
|
|
76
61
|
/**
|
|
@@ -88,28 +73,26 @@ type FoldOverOk<O> = O extends AnyVar ? OrderVarOk<O> : O extends Duration<infer
|
|
|
88
73
|
/**
|
|
89
74
|
* One find entry's judgment (off the entry's own descriptor — no env, no
|
|
90
75
|
* class map needed): a projected variable is ok, the measure and `pack`
|
|
91
|
-
* demand interval-typed variables, folds
|
|
76
|
+
* demand interval-typed variables, folds demand orderable ones.
|
|
92
77
|
*/
|
|
93
|
-
type FindEntryOk<E> = E extends AnyVar ? true : E extends Duration<infer V extends AnyVar> ? IntervalVarOk<V> : E extends Agg<"count", undefined> ? true : E extends Agg<"
|
|
78
|
+
type FindEntryOk<E> = E extends AnyVar ? true : E extends Duration<infer V extends AnyVar> ? IntervalVarOk<V> : E extends Agg<"count", undefined> ? true : E extends Agg<"sum", infer O> ? SumOverOk<O> : E extends Agg<"min" | "max", infer O> ? FoldOverOk<O> : E extends Agg<"pack", infer V extends AnyVar> ? IntervalVarOk<V> : false;
|
|
94
79
|
/** The validated find record (intersect with the inferred entries — errors land on the offending key). */
|
|
95
80
|
type CheckFind<F extends FindShape> = {
|
|
96
81
|
readonly [K in keyof F]: FindEntryOk<F[K]> extends true ? F[K] : never;
|
|
97
82
|
};
|
|
98
83
|
/**
|
|
99
84
|
* The validated find record of a RECURSIVE rule: every entry must be a plain
|
|
100
|
-
* variable (aggregates and the measure are unwritable in a
|
|
101
|
-
* the strata quarantine).
|
|
85
|
+
* variable (aggregates and the measure are unwritable in a rec head).
|
|
102
86
|
*/
|
|
103
87
|
type CheckRecFind<F extends FindShape> = {
|
|
104
88
|
readonly [K in keyof F]: F[K] extends AnyVar ? F[K] : never;
|
|
105
89
|
};
|
|
106
90
|
/**
|
|
107
91
|
* One find entry's answer-column value type: a variable carries its field's
|
|
108
|
-
* type, the measure/count
|
|
109
|
-
*
|
|
110
|
-
* payload's type, `pack` its interval type.
|
|
92
|
+
* type, the measure/count are `bigint`, folds carry their input's type
|
|
93
|
+
* (a measure fold is `bigint`), `pack` its interval type.
|
|
111
94
|
*/
|
|
112
|
-
type FindValue<E> = E extends AnyVar ? Infer<E["field"]> : E extends Duration<AnyVar> ? bigint : E extends Agg<"count", undefined> ? bigint : E extends Agg<"
|
|
95
|
+
type FindValue<E> = E extends AnyVar ? Infer<E["field"]> : E extends Duration<AnyVar> ? bigint : E extends Agg<"count", undefined> ? bigint : E extends Agg<"sum" | "min" | "max", infer O> ? O extends AnyVar ? Infer<O["field"]> : bigint : E extends Agg<"pack", infer V extends AnyVar> ? Infer<V["field"]> : never;
|
|
113
96
|
/** The inferred answer-row object type of a find record — the keys ARE the columns. */
|
|
114
97
|
type RowOfFind<F extends FindShape> = {
|
|
115
98
|
readonly [K in keyof F]: FindValue<F[K]>;
|
|
@@ -117,11 +100,11 @@ type RowOfFind<F extends FindShape> = {
|
|
|
117
100
|
/**
|
|
118
101
|
* The head signature of a recursive rule's find record as classed mint
|
|
119
102
|
* slots (descriptor + law-computed class), keyed by column name — the
|
|
120
|
-
* signature an
|
|
103
|
+
* signature an interior join pairs against (`F` is variable-only there).
|
|
121
104
|
*/
|
|
122
105
|
type HeadRecordOf<Classes extends SchemaClasses, F extends FindShape> = {
|
|
123
106
|
readonly [K in keyof F]: F[K] extends AnyVar ? MintSlotOf<Classes, F[K]> : never;
|
|
124
107
|
};
|
|
125
108
|
export type { Agg, AggOpName, AnyAgg, CheckFind, CheckRecFind, FindEntry, FindEntryOk, FindShape, FindValue, HeadRecordOf, RowOfFind };
|
|
126
|
-
export {
|
|
109
|
+
export { count, max, min, pack, sum };
|
|
127
110
|
//# sourceMappingURL=find.d.ts.map
|
package/dist/query/find.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE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ACN,SAAS,EACT,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,EACZ,SAAS,EACT,CAAA;AACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/query/find.js
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
* vocabulary, mirroring the IR's aggregate roster exactly
|
|
4
4
|
* (`bumbledb/crates/bumbledb/src/ir.rs` `AggOp`/`FindTerm`;
|
|
5
5
|
* `docs/architecture/20-query-ir.md` § aggregation): `count` (nullary),
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `r.sum(w)` — and are typed by the variable's own descriptor.
|
|
6
|
+
* `sum`/`min`/`max` (over an orderable variable or the measure), and
|
|
7
|
+
* `pack` (the coalescing fold — RELATION-SHAPED, the result position
|
|
8
|
+
* interval-typed). Aggregates fold VARIABLES by reference — `r.sum(w)` —
|
|
9
|
+
* and are typed by the variable's own descriptor.
|
|
11
10
|
*
|
|
12
11
|
* `select(strings)` is DEAD: the head is a `find` RECORD, whose KEYS name
|
|
13
12
|
* the answer columns (`find({ total: r.count(), owner: h })`). The keys are
|
|
@@ -19,16 +18,12 @@
|
|
|
19
18
|
* aggregate — no minting or arithmetic term exists to spell (permanent law).
|
|
20
19
|
*/
|
|
21
20
|
/** Builds one aggregate value. */
|
|
22
|
-
function aggregate(op, over
|
|
23
|
-
return Object.freeze({ agg: op, over
|
|
21
|
+
function aggregate(op, over) {
|
|
22
|
+
return Object.freeze({ agg: op, over });
|
|
24
23
|
}
|
|
25
24
|
/** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
|
|
26
25
|
function count() {
|
|
27
|
-
return aggregate("count", undefined
|
|
28
|
-
}
|
|
29
|
-
/** |the distinct values of the variable across the group|, `bigint`; legal over every type. */
|
|
30
|
-
function countDistinct(over) {
|
|
31
|
-
return aggregate("countDistinct", over, undefined);
|
|
26
|
+
return aggregate("count", undefined);
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
* Exact checked sum over a NUMERIC (u64/i64) variable — wide accumulator,
|
|
@@ -37,39 +32,25 @@ function countDistinct(over) {
|
|
|
37
32
|
* quantifier is not an addition (R3).
|
|
38
33
|
*/
|
|
39
34
|
function sum(over) {
|
|
40
|
-
return aggregate("sum", over
|
|
35
|
+
return aggregate("sum", over);
|
|
41
36
|
}
|
|
42
37
|
/** Minimum over an orderable variable (u64/i64/bool — over bool, `Min` is the ALL quantifier; R3) or the measure. */
|
|
43
38
|
function min(over) {
|
|
44
|
-
return aggregate("min", over
|
|
39
|
+
return aggregate("min", over);
|
|
45
40
|
}
|
|
46
41
|
/** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
|
|
47
42
|
function max(over) {
|
|
48
|
-
return aggregate("max", over
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Arg-restriction toward the maximum of `key` (`ir::AggOp::ArgMax`): the
|
|
52
|
-
* group's binding set is restricted to the bindings attaining the extreme
|
|
53
|
-
* of the orderable key, and `value` is the carried payload — a tie yields
|
|
54
|
-
* every attaining row. All Arg entries of one query share one key and one
|
|
55
|
-
* direction; Arg and fold aggregates never mix (both the engine's rules).
|
|
56
|
-
*/
|
|
57
|
-
function argMax(value, key) {
|
|
58
|
-
return aggregate("argMax", value, key);
|
|
59
|
-
}
|
|
60
|
-
/** Arg-restriction toward the minimum of `key`; rules as {@link argMax}. */
|
|
61
|
-
function argMin(value, key) {
|
|
62
|
-
return aggregate("argMin", value, key);
|
|
43
|
+
return aggregate("max", over);
|
|
63
44
|
}
|
|
64
45
|
/**
|
|
65
46
|
* The coalescing fold (Snodgrass coalesce, `ir::AggOp::Pack`): per group,
|
|
66
47
|
* the maximal disjoint half-open segments of the union of the group's
|
|
67
48
|
* interval point sets — RELATION-SHAPED, one answer row per (group, maximal
|
|
68
49
|
* segment), the result position carrying one interval of the input's element
|
|
69
|
-
* type. At most one `pack` per find, never beside a fold
|
|
50
|
+
* type. At most one `pack` per find, never beside a fold entry.
|
|
70
51
|
*/
|
|
71
52
|
function pack(over) {
|
|
72
|
-
return aggregate("pack", over
|
|
53
|
+
return aggregate("pack", over);
|
|
73
54
|
}
|
|
74
|
-
export {
|
|
55
|
+
export { count, max, min, pack, sum };
|
|
75
56
|
//# sourceMappingURL=find.js.map
|
package/dist/query/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA4BH,kCAAkC;AAClC,SAAS,SAAS,CACjB,EAAM,EACN,IAAU;IAEV,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AACxC,CAAC;AAED,4EAA4E;AAC5E,SAAS,KAAK;IACb,OAAO,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,qHAAqH;AACrH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,qHAAqH;AACrH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,IAAI,CAAyB,IAAO;IAC5C,OAAO,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC/B,CAAC;AAoGD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/query/lower.d.ts
CHANGED
|
@@ -18,11 +18,8 @@
|
|
|
18
18
|
* `Params` inferred to be EXACTLY the params the rules use (params are typed
|
|
19
19
|
* BY USE; a param no rule uses never registers). Variable IDENTITY is the
|
|
20
20
|
* object reference: reusing one value across binding positions IS the join,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* equality, that alone makes every cross-binding join transitively
|
|
24
|
-
* class-equal. Lowering is a pure function of the query value down to the
|
|
25
|
-
* bridge's `ProgramIr` (`bumbledb/crates/bumbledb/src/ir.rs`): relations by
|
|
21
|
+
* lowering is a pure function of the query value down to the
|
|
22
|
+
* bridge's `QueryIr` (`bumbledb/crates/bumbledb/src/ir.rs`): relations by
|
|
26
23
|
* declaration ordinal, variables by dense per-rule first-occurrence ids
|
|
27
24
|
* (keyed on the object REFERENCE — the discipline is unchanged, only the map
|
|
28
25
|
* key moved from name to reference), params by first-use order. Lowering is
|
|
@@ -30,18 +27,18 @@
|
|
|
30
27
|
* two identically-written queries (fresh mints each) lower identically.
|
|
31
28
|
* Construction validates negation safety and boundness (typed by the var's
|
|
32
29
|
* label — object identity is invisible to the type tier, so these are
|
|
33
|
-
* construction-time walls); everything else (
|
|
30
|
+
* construction-time walls); everything else (types, aggregate
|
|
34
31
|
* rosters, rule caps) is the ENGINE's judge, surfacing at prepare.
|
|
35
32
|
*/
|
|
36
33
|
import type { AnyField } from "#fields.ts";
|
|
37
34
|
import type { ClassRecordOf, SchemaClasses } from "#law.ts";
|
|
38
|
-
import type {
|
|
39
|
-
import type { AnyCond, BindParamsShape, CheckBindings, CheckCond, CmpKind, CondParamsShape, FindColumn, MatchFields, MatchOwner, MatchShape, RecData, RuleData } from "#query/atom.ts";
|
|
35
|
+
import type { ParsedQuery, TaggedValue } from "#native.ts";
|
|
36
|
+
import type { AnyCond, BindParamsShape, CheckBindings, CheckCond, CmpKind, CondParamsShape, FindColumn, InteriorData, MatchFields, MatchOwner, MatchShape, RecData, RecHandle, RecHead, RuleData } from "#query/atom.ts";
|
|
40
37
|
import { allen, and, eq, ge, gt, le, lt, ne, not, or, pointIn } from "#query/atom.ts";
|
|
41
38
|
import type { CheckFind, CheckRecFind, FindShape, HeadRecordOf, RowOfFind } from "#query/find.ts";
|
|
42
|
-
import {
|
|
43
|
-
import type { AnyVar, ClassedField, Flatten, InferredOf,
|
|
44
|
-
import { inferred, makeDuration,
|
|
39
|
+
import { count, max, min, pack, sum } from "#query/find.ts";
|
|
40
|
+
import type { AnyVar, ClassedField, Flatten, InferredOf, ParamEntry, ParamsRecord, ShapeOf } from "#query/scope.ts";
|
|
41
|
+
import { inferred, makeDuration, makeParam, makeSetParam } from "#query/scope.ts";
|
|
45
42
|
import type { AnySchema, Schema, SchemaRelations } from "#schema.ts";
|
|
46
43
|
/**
|
|
47
44
|
* The matchable members of a schema's record — ordinary relations AND
|
|
@@ -58,15 +55,15 @@ type RowOf<T> = InferredOf<T> extends {
|
|
|
58
55
|
readonly row: infer R;
|
|
59
56
|
} ? R : never;
|
|
60
57
|
/**
|
|
61
|
-
* A
|
|
62
|
-
* name
|
|
63
|
-
* it; `undefined` on values that carry no head.
|
|
58
|
+
* A derived table's HEAD signature as classed slots, keyed by column
|
|
59
|
+
* name; `undefined` on values that carry no head.
|
|
64
60
|
*/
|
|
65
61
|
type HeadShape = Readonly<Record<string, ClassedField>> | undefined;
|
|
66
62
|
/**
|
|
67
63
|
* One finished rule as a plain value: the runtime data plus the inferred
|
|
68
|
-
* row/params carrier (and, for
|
|
69
|
-
*
|
|
64
|
+
* row/params carrier (and, for an interior or recursive rule, the head
|
|
65
|
+
* record of classed slots an `.interior(name)` join pairs against).
|
|
66
|
+
* `.rule(...)` consumes it.
|
|
70
67
|
*/
|
|
71
68
|
interface RuleValue<Row, P extends ParamsRecord, Head extends HeadShape = undefined> {
|
|
72
69
|
readonly rule: RuleData;
|
|
@@ -82,38 +79,25 @@ type AnyRuleValue = RuleValue<unknown, ParamsRecord, HeadShape>;
|
|
|
82
79
|
type HeadOf<T> = InferredOf<T> extends {
|
|
83
80
|
readonly head: infer H extends Readonly<Record<string, ClassedField>>;
|
|
84
81
|
} ? H : undefined;
|
|
82
|
+
/** One `.interior(name)` position's judgment: a variable. */
|
|
83
|
+
type InteriorBindingOk<V> = V extends AnyVar ? true : false;
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* The validated `.interior(name)` bindings record: every entry must be a
|
|
86
|
+
* variable. Arity and class against the named table's head are
|
|
87
|
+
* construction-time (the name is a string, so the head is not a type-level
|
|
88
|
+
* fact).
|
|
89
89
|
*/
|
|
90
|
-
|
|
91
|
-
readonly
|
|
92
|
-
readonly data: RecData;
|
|
93
|
-
readonly [inferred]?: {
|
|
94
|
-
readonly params: P;
|
|
95
|
-
readonly head: Head;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/** One `idb` position's judgment: a variable class-equal to the head slot when the head is carried. */
|
|
99
|
-
type IdbBindingOk<Classes extends SchemaClasses, HeadSlot, V> = V extends AnyVar ? HeadSlot extends ClassedField ? JoinOk<HeadSlot, MintSlotOf<Classes, V>> extends true ? true : false : true : false;
|
|
100
|
-
/**
|
|
101
|
-
* The validated `idb` bindings record: when the target carries its head
|
|
102
|
-
* (a threaded rec handle), the record's key set must EXACTLY equal the
|
|
103
|
-
* head's (a missing or extra key maps every property to `never`) and each
|
|
104
|
-
* variable must be class-equal to its head slot — the same wall `JoinOk`
|
|
105
|
-
* holds for EDB atoms. An unthreaded handle carries no head; every entry
|
|
106
|
-
* must still be a variable, arity/class judged at construction and prepare.
|
|
107
|
-
*/
|
|
108
|
-
type CheckIdbBindings<Classes extends SchemaClasses, Head, B> = Head extends Readonly<Record<string, ClassedField>> ? [keyof B] extends [keyof Head] ? [keyof Head] extends [keyof B] ? {
|
|
109
|
-
readonly [K in keyof B]: K extends keyof Head ? IdbBindingOk<Classes, Head[K], B[K]> extends true ? B[K] : never : never;
|
|
110
|
-
} : {
|
|
111
|
-
readonly [K in keyof B]: never;
|
|
112
|
-
} : {
|
|
113
|
-
readonly [K in keyof B]: never;
|
|
114
|
-
} : {
|
|
115
|
-
readonly [K in keyof B]: B[K] extends AnyVar ? B[K] : never;
|
|
90
|
+
type CheckInteriorBindings<B> = {
|
|
91
|
+
readonly [K in keyof B]: InteriorBindingOk<B[K]> extends true ? B[K] : never;
|
|
116
92
|
};
|
|
93
|
+
/** One interior-rule builder function. */
|
|
94
|
+
type InteriorBuild<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> = (r: InteriorRuleScope<Rels, Classes>) => AnyRuleValue;
|
|
95
|
+
/** One rec-arm builder function. */
|
|
96
|
+
type RecBuild<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> = (r: RecRuleScope<Rels, Classes>) => AnyRuleValue;
|
|
97
|
+
/** A build function's rule value. */
|
|
98
|
+
type BuiltRule<F> = F extends (r: never) => infer RV ? RV : never;
|
|
99
|
+
/** The intersected params record of a tuple of rule builds. */
|
|
100
|
+
type BuildsParams<Builds extends readonly ((r: never) => AnyRuleValue)[]> = ShapeOf<ParamsOf<BuiltRule<Builds[number]>>>;
|
|
117
101
|
/**
|
|
118
102
|
* The term/predicate/aggregate constructor vocabulary every rule builder
|
|
119
103
|
* carries — pure value builders. Variables are minted by the free {@link v},
|
|
@@ -124,8 +108,6 @@ interface TermOps {
|
|
|
124
108
|
readonly param: typeof makeParam;
|
|
125
109
|
/** Names one ∈-set parameter (the IR's `ParamSet`): bound to a readonly array at execution. */
|
|
126
110
|
readonly inSet: typeof makeSetParam;
|
|
127
|
-
/** Names one Allen-mask parameter (`MaskTerm::Param`): a bind-time 13-bit mask number. */
|
|
128
|
-
readonly maskParam: typeof makeMaskParam;
|
|
129
111
|
/** The measure of an interval-typed variable: `|[s, e)| = e − s`, u64. */
|
|
130
112
|
readonly duration: typeof makeDuration;
|
|
131
113
|
readonly eq: typeof eq;
|
|
@@ -140,18 +122,22 @@ interface TermOps {
|
|
|
140
122
|
readonly or: typeof or;
|
|
141
123
|
readonly not: typeof not;
|
|
142
124
|
readonly count: typeof count;
|
|
143
|
-
readonly countDistinct: typeof countDistinct;
|
|
144
125
|
readonly sum: typeof sum;
|
|
145
126
|
readonly min: typeof min;
|
|
146
127
|
readonly max: typeof max;
|
|
147
|
-
readonly argMax: typeof argMax;
|
|
148
|
-
readonly argMin: typeof argMin;
|
|
149
128
|
readonly pack: typeof pack;
|
|
150
129
|
}
|
|
151
130
|
/** The rule builder a `query(S).rule(...)` callback receives (`Classes` — the join judge's authority). */
|
|
152
131
|
interface QueryRuleScope<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> extends TermOps {
|
|
153
132
|
/** The first EDB atom of the rule: fields bind variables, params, ∈-sets, or bare literals; absence is the wildcard. */
|
|
154
133
|
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): QueryRuleChain<Rels, BindParamsShape<MatchFields<R>, B>, Classes>;
|
|
134
|
+
/**
|
|
135
|
+
* A rule may START with a finished table: an interior atom is a positive
|
|
136
|
+
* occurrence exactly as the engine represents it, so its variables ground
|
|
137
|
+
* — the identity projection `(c) | reach(c);` is spellable with no
|
|
138
|
+
* re-grounding join over a domain relation.
|
|
139
|
+
*/
|
|
140
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): QueryRuleChain<Rels, Record<never, never>, Classes>;
|
|
155
141
|
}
|
|
156
142
|
/** The chain of a plain query rule: more atoms, residual predicates, then the head. */
|
|
157
143
|
interface QueryRuleChain<Rels extends SchemaRelations, P extends ParamsRecord, Classes extends SchemaClasses = SchemaClasses> {
|
|
@@ -159,61 +145,51 @@ interface QueryRuleChain<Rels extends SchemaRelations, P extends ParamsRecord, C
|
|
|
159
145
|
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): QueryRuleChain<Rels, Flatten<P & BindParamsShape<MatchFields<R>, B>>, Classes>;
|
|
160
146
|
/** One residual predicate: a comparison, an `and`/`or` tree, or a negated atom (`r.not`). */
|
|
161
147
|
where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): QueryRuleChain<Rels, Flatten<P & CondParamsShape<C>>, Classes>;
|
|
148
|
+
/** One interior atom over a finished table (an earlier interior, or the rec). */
|
|
149
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): QueryRuleChain<Rels, P, Classes>;
|
|
162
150
|
/** The head projection: a `find` RECORD whose keys name the answer columns. */
|
|
163
151
|
find<const F extends FindShape>(entries: F & CheckFind<F>): RuleValue<RowOfFind<F>, P>;
|
|
164
152
|
}
|
|
165
|
-
/** The rule builder an
|
|
166
|
-
interface
|
|
167
|
-
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>):
|
|
168
|
-
|
|
169
|
-
* A rule may START with the finished stratum: an idb atom is a positive
|
|
170
|
-
* occurrence exactly as the engine represents it, so its variables ground
|
|
171
|
-
* — the identity projection `(c) | reach(c);` is spellable with no
|
|
172
|
-
* re-grounding join over a domain relation.
|
|
173
|
-
*/
|
|
174
|
-
idb<Target extends RecRef<string, ParamsRecord>, const B extends Readonly<Record<string, AnyVar>>>(target: Target, bindings: B & CheckIdbBindings<Classes, HeadOf<Target>, B>): OutputRuleChain<Rels, ParamsOf<Target>, Classes>;
|
|
153
|
+
/** The rule builder an `interior("mid", ...)` callback receives. */
|
|
154
|
+
interface InteriorRuleScope<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> extends TermOps {
|
|
155
|
+
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): InteriorRuleChain<Rels, BindParamsShape<MatchFields<R>, B>, Classes>;
|
|
156
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): InteriorRuleChain<Rels, Record<never, never>, Classes>;
|
|
175
157
|
}
|
|
176
|
-
/** The chain of an
|
|
177
|
-
interface
|
|
178
|
-
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>):
|
|
179
|
-
where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C):
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* NAMED join against the rec's head — the bindings record's keys are the
|
|
183
|
-
* head columns, each bound to a variable positively bound by a relation
|
|
184
|
-
* atom of the rule. Threading the rec value the last `.rule(...)` returned
|
|
185
|
-
* carries its params into `Params` AND its head signature, so the join is
|
|
186
|
-
* key-exact and class-checked against the head at compile time.
|
|
187
|
-
*/
|
|
188
|
-
idb<Target extends RecRef<string, ParamsRecord>, const B extends Readonly<Record<string, AnyVar>>>(target: Target, bindings: B & CheckIdbBindings<Classes, HeadOf<Target>, B>): OutputRuleChain<Rels, Flatten<P & ParamsOf<Target>>, Classes>;
|
|
189
|
-
find<const F extends FindShape>(entries: F & CheckFind<F>): RuleValue<RowOfFind<F>, P>;
|
|
158
|
+
/** The chain of an interior rule: bound-variable heads only. */
|
|
159
|
+
interface InteriorRuleChain<Rels extends SchemaRelations, P extends ParamsRecord, Classes extends SchemaClasses = SchemaClasses> {
|
|
160
|
+
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): InteriorRuleChain<Rels, Flatten<P & BindParamsShape<MatchFields<R>, B>>, Classes>;
|
|
161
|
+
where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): InteriorRuleChain<Rels, Flatten<P & CondParamsShape<C>>, Classes>;
|
|
162
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): InteriorRuleChain<Rels, P, Classes>;
|
|
163
|
+
find<const F extends FindShape>(entries: F & CheckRecFind<F>): RuleValue<RowOfFind<F>, P, HeadRecordOf<Classes, F>>;
|
|
190
164
|
}
|
|
191
|
-
/** The rule builder a
|
|
192
|
-
interface RecRuleScope<Rels extends SchemaRelations,
|
|
193
|
-
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): RecRuleChain<Rels,
|
|
165
|
+
/** The rule builder a `recursive("reach", { base, rec })` arm receives. */
|
|
166
|
+
interface RecRuleScope<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> extends TermOps {
|
|
167
|
+
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): RecRuleChain<Rels, BindParamsShape<MatchFields<R>, B>, Classes>;
|
|
168
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): RecRuleChain<Rels, Record<never, never>, Classes>;
|
|
194
169
|
}
|
|
195
170
|
/**
|
|
196
|
-
* The chain of a recursive
|
|
197
|
-
*
|
|
198
|
-
* and the measure are unrepresentable in a
|
|
171
|
+
* The chain of a recursive arm. `.interior("reach", …)` is the self-atom
|
|
172
|
+
* on rec arms (and a prior interior on either list). `find` takes bound
|
|
173
|
+
* variables only — aggregates and the measure are unrepresentable in a
|
|
174
|
+
* recursive head.
|
|
199
175
|
*/
|
|
200
|
-
interface RecRuleChain<Rels extends SchemaRelations,
|
|
201
|
-
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): RecRuleChain<Rels,
|
|
202
|
-
where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): RecRuleChain<Rels,
|
|
203
|
-
|
|
204
|
-
idb<Target extends RecRef<Self, ParamsRecord>, const B extends Readonly<Record<string, AnyVar>>>(target: Target, bindings: B & CheckIdbBindings<Classes, HeadOf<Target>, B>): RecRuleChain<Rels, Self, P, Classes>;
|
|
205
|
-
/** The recursive head: a `find` record of bound variables only; the value carries the head's classed slots for `idb` pairing. */
|
|
176
|
+
interface RecRuleChain<Rels extends SchemaRelations, P extends ParamsRecord, Classes extends SchemaClasses = SchemaClasses> {
|
|
177
|
+
match<R extends QueryRelation<Rels>, const B extends MatchShape<MatchFields<R>>>(relation: R, bindings: B & CheckBindings<Classes, MatchFields<R>, ClassRecordOf<Classes, R["name"]>, B>): RecRuleChain<Rels, Flatten<P & BindParamsShape<MatchFields<R>, B>>, Classes>;
|
|
178
|
+
where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): RecRuleChain<Rels, Flatten<P & CondParamsShape<C>>, Classes>;
|
|
179
|
+
interior<const B extends Readonly<Record<string, AnyVar>>>(name: string, bindings: B & CheckInteriorBindings<B>): RecRuleChain<Rels, P, Classes>;
|
|
206
180
|
find<const F extends FindShape>(entries: F & CheckRecFind<F>): RuleValue<RowOfFind<F>, P, HeadRecordOf<Classes, F>>;
|
|
207
181
|
}
|
|
208
182
|
/** A query's runtime description — everything lowering, the wire marshal, and answer decode read. */
|
|
209
183
|
interface QueryData {
|
|
210
|
-
/**
|
|
211
|
-
readonly
|
|
212
|
-
/** The
|
|
184
|
+
/** Named interiors in declaration order (DAG). */
|
|
185
|
+
readonly interiors: readonly InteriorData[];
|
|
186
|
+
/** The optional linear rec. */
|
|
187
|
+
readonly rec: RecData | null;
|
|
188
|
+
/** The main rules in written order (multiple rules = set union). */
|
|
213
189
|
readonly rules: readonly RuleData[];
|
|
214
190
|
/** The head columns (every rule derives the same head; written order = answer column order). */
|
|
215
191
|
readonly finds: readonly FindColumn[];
|
|
216
|
-
/** The registered params in first-use order across the
|
|
192
|
+
/** The registered params in first-use order across the query walk (= dense `ParamId`s). */
|
|
217
193
|
readonly params: readonly ParamEntry[];
|
|
218
194
|
}
|
|
219
195
|
/**
|
|
@@ -226,6 +202,10 @@ interface Query<Rels extends SchemaRelations, Row, Params extends ParamsRecord,
|
|
|
226
202
|
readonly data: QueryData;
|
|
227
203
|
/** One more rule — the query's answers are the SET UNION of its rules' answers; every rule derives the same head. */
|
|
228
204
|
rule<RV extends AnyRuleValue>(build: (r: QueryRuleScope<Rels, Classes>) => RV): Query<Rels, Row | RowOf<RV>, Flatten<Params & ParamsOf<RV>>, Classes>;
|
|
205
|
+
/** Construction error: interiors precede main rules. Uncallable after `.rule()`. */
|
|
206
|
+
interior(name: string, ...builds: never[]): never;
|
|
207
|
+
/** Construction error: recursive precedes main rules. Uncallable after `.rule()`. */
|
|
208
|
+
recursive(name: string, arms: never): never;
|
|
229
209
|
readonly [inferred]?: {
|
|
230
210
|
readonly row: Row;
|
|
231
211
|
readonly params: Params;
|
|
@@ -240,10 +220,23 @@ interface AnyQuery {
|
|
|
240
220
|
type QueryRow<Q extends AnyQuery> = RowOf<Q>;
|
|
241
221
|
/** Extracts a query value's inferred execute-params type. */
|
|
242
222
|
type QueryParams<Q extends AnyQuery> = ParamsOf<Q>;
|
|
243
|
-
/**
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
223
|
+
/**
|
|
224
|
+
* The entry value of `query(S)`: interiors, then optional recursive, then
|
|
225
|
+
* the first `.rule` mints the query. `interior` / `recursive` exist only
|
|
226
|
+
* while `Rec` is `null`; `.recursive()` moves the type parameter.
|
|
227
|
+
*/
|
|
228
|
+
type QueryStart<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses, P extends ParamsRecord = Record<never, never>, Rec extends RecData | null = null> = {
|
|
229
|
+
rule<RV extends AnyRuleValue>(build: (r: QueryRuleScope<Rels, Classes>) => RV): Query<Rels, RowOf<RV>, Flatten<P & ParamsOf<RV>>, Classes>;
|
|
230
|
+
} & (Rec extends null ? {
|
|
231
|
+
interior<const Builds extends readonly InteriorBuild<Rels, Classes>[]>(name: string, ...builds: Builds): QueryStart<Rels, Classes, Flatten<P & BuildsParams<Builds>>, null>;
|
|
232
|
+
recursive<const Base extends readonly RecBuild<Rels, Classes>[], const Step extends readonly RecBuild<Rels, Classes>[]>(name: string, arms: {
|
|
233
|
+
readonly base: Base;
|
|
234
|
+
readonly rec: Step;
|
|
235
|
+
}): QueryStart<Rels, Classes, Flatten<P & BuildsParams<Base> & BuildsParams<Step>>, RecData>;
|
|
236
|
+
} : {
|
|
237
|
+
interior: never;
|
|
238
|
+
recursive: never;
|
|
239
|
+
});
|
|
247
240
|
/**
|
|
248
241
|
* The one runtime chain every context shares — non-generic on purpose. The
|
|
249
242
|
* typed chain interfaces apply at the scope factories' boundaries.
|
|
@@ -251,45 +244,43 @@ interface QueryStart<Rels extends SchemaRelations, Classes extends SchemaClasses
|
|
|
251
244
|
interface RawChain {
|
|
252
245
|
match(relation: MatchOwner, bindings: Readonly<Record<string, unknown>>): RawChain;
|
|
253
246
|
where(cond: AnyCond): RawChain;
|
|
254
|
-
|
|
247
|
+
interior(name: string, bindings: Readonly<Record<string, unknown>>): RawChain;
|
|
255
248
|
find(entries: Readonly<Record<string, unknown>>): RuleValue<never, never>;
|
|
256
249
|
}
|
|
257
250
|
/** The runtime rule-builder shape beneath every typed scope. */
|
|
258
251
|
interface RawScope extends TermOps {
|
|
259
252
|
match(relation: MatchOwner, bindings: Readonly<Record<string, unknown>>): RawChain;
|
|
260
|
-
|
|
253
|
+
interior(name: string, bindings: Readonly<Record<string, unknown>>): RawChain;
|
|
254
|
+
}
|
|
255
|
+
/** The declared derived tables a chain may name. */
|
|
256
|
+
interface DerivedEnv {
|
|
257
|
+
readonly interiors: readonly InteriorData[];
|
|
258
|
+
readonly rec: RecHandle | RecHead | RecData | null;
|
|
261
259
|
}
|
|
262
260
|
/** Which rule family a chain builds — plus the schema's runtime class map and theory value (the join judge's authority). */
|
|
263
261
|
type ChainContext = {
|
|
264
262
|
readonly classes: SchemaClasses;
|
|
265
263
|
readonly theory: AnySchema;
|
|
266
|
-
} & ({
|
|
264
|
+
} & DerivedEnv & ({
|
|
267
265
|
readonly kind: "query";
|
|
268
266
|
} | {
|
|
269
|
-
readonly kind: "
|
|
270
|
-
readonly self:
|
|
267
|
+
readonly kind: "interior";
|
|
268
|
+
readonly self: string;
|
|
271
269
|
} | {
|
|
272
|
-
readonly kind: "
|
|
273
|
-
readonly
|
|
270
|
+
readonly kind: "rec-base";
|
|
271
|
+
readonly self: RecHandle;
|
|
272
|
+
} | {
|
|
273
|
+
readonly kind: "rec-arm";
|
|
274
|
+
readonly self: RecHead;
|
|
274
275
|
});
|
|
275
276
|
/** Builds one runtime rule-builder over a context. */
|
|
276
277
|
declare function makeRawScope(context: ChainContext): RawScope;
|
|
277
|
-
/** Builds one output-rule builder over a program's recs. */
|
|
278
|
-
declare function makeOutputRuleScope<Rels extends SchemaRelations, Classes extends SchemaClasses>(program: ProgramState): OutputRuleScope<Rels, Classes>;
|
|
279
|
-
/** One program's build-time registry: its recs in declaration order, the theory value, and its class map. */
|
|
280
|
-
interface ProgramState {
|
|
281
|
-
readonly recs: RecData[];
|
|
282
|
-
readonly classes: SchemaClasses;
|
|
283
|
-
readonly theory: AnySchema;
|
|
284
|
-
sealed: boolean;
|
|
285
|
-
}
|
|
286
|
-
/** Assembles one typed query value (rules already completed). */
|
|
287
|
-
declare function makeQuery<Rels extends SchemaRelations, Row, P extends ParamsRecord, Classes extends SchemaClasses>(theory: Schema<Rels, Classes>, recs: readonly RecData[], rules: readonly RuleData[]): Query<Rels, Row, P, Classes>;
|
|
288
278
|
/**
|
|
289
|
-
* Opens a query over a schema: `query(S).rule(r => ...)
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
279
|
+
* Opens a query over a schema: `query(S).rule(r => ...)`, optionally with
|
|
280
|
+
* `interior` / `recursive` first. Each `.rule` adds one conjunctive rule;
|
|
281
|
+
* multiple rules are the set union. The schema's law-computed class map and
|
|
282
|
+
* theory value ride into every rule builder — the join walls compare
|
|
283
|
+
* against the mint slots off it.
|
|
293
284
|
*/
|
|
294
285
|
declare function query<Rels extends SchemaRelations, Classes extends SchemaClasses>(theory: Schema<Rels, Classes>): QueryStart<Rels, Classes>;
|
|
295
286
|
/**
|
|
@@ -308,11 +299,11 @@ declare function taggedLiteral(context: string, field: AnyField, value: unknown)
|
|
|
308
299
|
*/
|
|
309
300
|
declare function taggedCmpLiteral(context: string, sibling: AnyField | "measure", value: unknown, op: CmpKind | "binding"): TaggedValue;
|
|
310
301
|
/**
|
|
311
|
-
* Lowers a query value to the bridge's `
|
|
312
|
-
*
|
|
313
|
-
*
|
|
302
|
+
* Lowers a query value to the bridge's `QueryIr` — pure and stable: interiors
|
|
303
|
+
* in declaration order, optional rec, then main. Every registered param must
|
|
304
|
+
* carry a field anchor by now.
|
|
314
305
|
*/
|
|
315
|
-
declare function lowerQuery(q: AnyQuery):
|
|
316
|
-
export type { AnyQuery, AnyRuleValue, HeadOf, HeadShape,
|
|
317
|
-
export { lowerQuery,
|
|
306
|
+
declare function lowerQuery(q: AnyQuery): ParsedQuery;
|
|
307
|
+
export type { AnyQuery, AnyRuleValue, HeadOf, HeadShape, InteriorRuleChain, InteriorRuleScope, ParamsOf, Query, QueryData, QueryParams, QueryRelation, QueryRow, QueryRuleChain, QueryRuleScope, QueryStart, RawChain, RawScope, RecRuleChain, RecRuleScope, RowOf, RuleValue, TermOps };
|
|
308
|
+
export { lowerQuery, makeRawScope, query, taggedCmpLiteral, taggedLiteral };
|
|
318
309
|
//# sourceMappingURL=lower.d.ts.map
|