@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.
Files changed (73) hide show
  1. package/COOKBOOK.md +155 -136
  2. package/README.md +3 -7
  3. package/dist/capacity.d.ts +14 -1
  4. package/dist/capacity.d.ts.map +1 -1
  5. package/dist/capacity.js.map +1 -1
  6. package/dist/db.d.ts +77 -109
  7. package/dist/db.d.ts.map +1 -1
  8. package/dist/db.js +121 -339
  9. package/dist/db.js.map +1 -1
  10. package/dist/index.d.ts +11 -16
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/lower.d.ts.map +1 -1
  15. package/dist/lower.js +8 -1
  16. package/dist/lower.js.map +1 -1
  17. package/dist/native.d.ts +69 -50
  18. package/dist/native.d.ts.map +1 -1
  19. package/dist/native.js.map +1 -1
  20. package/dist/query/atom.d.ts +162 -122
  21. package/dist/query/atom.d.ts.map +1 -1
  22. package/dist/query/atom.js +26 -22
  23. package/dist/query/atom.js.map +1 -1
  24. package/dist/query/find.d.ts +18 -35
  25. package/dist/query/find.d.ts.map +1 -1
  26. package/dist/query/find.js +13 -32
  27. package/dist/query/find.js.map +1 -1
  28. package/dist/query/lower.d.ts +113 -122
  29. package/dist/query/lower.d.ts.map +1 -1
  30. package/dist/query/lower.js +336 -260
  31. package/dist/query/lower.js.map +1 -1
  32. package/dist/query/parse-ir.d.ts +12 -0
  33. package/dist/query/parse-ir.d.ts.map +1 -0
  34. package/dist/query/parse-ir.js +71 -0
  35. package/dist/query/parse-ir.js.map +1 -0
  36. package/dist/query/run.d.ts +2 -2
  37. package/dist/query/run.d.ts.map +1 -1
  38. package/dist/query/run.js +2 -13
  39. package/dist/query/run.js.map +1 -1
  40. package/dist/query/scope.d.ts +4 -16
  41. package/dist/query/scope.d.ts.map +1 -1
  42. package/dist/query/scope.js +1 -6
  43. package/dist/query/scope.js.map +1 -1
  44. package/dist/schema.js +2 -2
  45. package/dist/schema.js.map +1 -1
  46. package/dist/statements.d.ts +15 -9
  47. package/dist/statements.d.ts.map +1 -1
  48. package/dist/statements.js +14 -9
  49. package/dist/statements.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/capacity.ts +24 -1
  52. package/src/db.ts +182 -443
  53. package/src/index.ts +9 -23
  54. package/src/lower.ts +8 -1
  55. package/src/native.ts +69 -42
  56. package/src/query/atom.ts +255 -165
  57. package/src/query/find.ts +39 -80
  58. package/src/query/lower.ts +578 -432
  59. package/src/query/parse-ir.ts +82 -0
  60. package/src/query/run.ts +2 -14
  61. package/src/query/scope.ts +3 -21
  62. package/src/schema.ts +2 -2
  63. package/src/statements.ts +33 -17
  64. package/dist/order.d.ts +0 -87
  65. package/dist/order.d.ts.map +0 -1
  66. package/dist/order.js +0 -153
  67. package/dist/order.js.map +0 -1
  68. package/dist/query/predicate.d.ts +0 -91
  69. package/dist/query/predicate.d.ts.map +0 -1
  70. package/dist/query/predicate.js +0 -156
  71. package/dist/query/predicate.js.map +0 -1
  72. package/src/order.ts +0 -234
  73. package/src/query/predicate.ts +0 -269
@@ -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
- * `countDistinct`, `sum`/`min`/`max` (over an orderable variable or the
7
- * measure), `argMax`/`argMin` (arg-restriction: carried value + orderable
8
- * key), and `pack` (the coalescing fold — RELATION-SHAPED, the result
9
- * position interval-typed). Aggregates fold VARIABLES by reference —
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" | "countDistinct" | "sum" | "min" | "max" | "argMax" | "argMin" | "pack";
25
+ type AggOpName = "count" | "sum" | "min" | "max" | "pack";
27
26
  /**
28
- * One aggregate find VALUE: the op, the variable (or measure) it folds BY
29
- * REFERENCE, and — for the Arg forms — the orderable key variable. The
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, Key extends AnyVar | undefined = 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, AnyVar | 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 or an Arg entry.
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 and Arg keys demand orderable ones.
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<"countDistinct", AnyVar> ? true : E extends Agg<"sum", infer O> ? SumOverOk<O> : E extends Agg<"min" | "max", infer O> ? FoldOverOk<O> : E extends Agg<"argMax" | "argMin", AnyVar, infer K extends AnyVar> ? OrderVarOk<K> extends true ? true : false : E extends Agg<"pack", infer V extends AnyVar> ? IntervalVarOk<V> : false;
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 recursive head —
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/countDistinct are `bigint`, folds carry their
109
- * input's type (a measure fold is `bigint`), the Arg forms carry the
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<"countDistinct", AnyVar> ? bigint : E extends Agg<"sum" | "min" | "max", infer O> ? O extends AnyVar ? Infer<O["field"]> : bigint : E extends Agg<"argMax" | "argMin", infer V extends AnyVar, AnyVar> ? Infer<V["field"]> : E extends Agg<"pack", infer V extends AnyVar> ? Infer<V["field"]> : never;
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 `idb` join pairs against (`F` is variable-only there).
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 { argMax, argMin, count, countDistinct, max, min, pack, sum };
109
+ export { count, max, min, pack, sum };
127
110
  //# sourceMappingURL=find.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;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,MAAM,iBAAiB,CAAA;AAEnE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C,GACjB,KAAK,CAAA;AAEZ,uFAAuF;AACvF,KAAK,SAAS,CAAC,CAAC,SAAS,SAAS,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAElF;;;;GAIG;AACH,KAAK,YAAY,CAAC,OAAO,SAAS,aAAa,EAAE,CAAC,SAAS,SAAS,IAAI;IACvE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CAChF,CAAA;AAED,YAAY,EACX,GAAG,EACH,SAAS,EACT,MAAM,EACN,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"}
@@ -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
- * `countDistinct`, `sum`/`min`/`max` (over an orderable variable or the
7
- * measure), `argMax`/`argMin` (arg-restriction: carried value + orderable
8
- * key), and `pack` (the coalescing fold — RELATION-SHAPED, the result
9
- * position interval-typed). Aggregates fold VARIABLES by reference —
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, key) {
23
- return Object.freeze({ agg: op, over, key });
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, 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, undefined);
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, undefined);
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, undefined);
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 or an Arg entry.
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, undefined);
53
+ return aggregate("pack", over);
73
54
  }
74
- export { argMax, argMin, count, countDistinct, max, min, pack, sum };
55
+ export { count, max, min, pack, sum };
75
56
  //# sourceMappingURL=find.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkCH,kCAAkC;AAClC,SAAS,SAAS,CACjB,EAAM,EACN,IAAU,EACV,GAAQ;IAER,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;AAC7C,CAAC;AAED,4EAA4E;AAC5E,SAAS,KAAK;IACb,OAAO,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AAChD,CAAC;AAED,+FAA+F;AAC/F,SAAS,aAAa,CAAyB,IAAO;IACrD,OAAO,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AACnD,CAAC;AAED;;;;;GAKG;AACH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AACzC,CAAC;AAED,qHAAqH;AACrH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AACzC,CAAC;AAED,qHAAqH;AACrH,SAAS,GAAG,CAAoC,IAAO;IACtD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,EA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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"}
@@ -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
- * and a name-collision join is unrepresentable. Each binding position is
22
- * judged against the variable's MINT slot — and because {@link JoinOk} is an
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 (strata, types, aggregate
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 { ProgramIr, TaggedValue } from "#native.ts";
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 { argMax, argMin, count, countDistinct, max, min, pack, sum } from "#query/find.ts";
43
- import type { AnyVar, ClassedField, Flatten, InferredOf, JoinOk, MintSlotOf, ParamEntry, ParamsRecord } from "#query/scope.ts";
44
- import { inferred, makeDuration, makeMaskParam, makeParam, makeSetParam } from "#query/scope.ts";
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 recursive predicate's HEAD signature as classed slots, keyed by column
62
- * name — carried on the rec reference so an `idb` join can be judged against
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 a RECURSIVE rule, the head record of classed
69
- * slots `idb` pairs against). `.rule(...)` consumes it.
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
- * A recursive predicate REFERENCE — the shape `idb()` targets carry: the
87
- * name (type-level identity), the runtime data (value identity), the params
88
- * its rules have used, and the head signature its FIRST rule sealed.
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
- interface RecRef<Name extends string, P extends ParamsRecord, Head extends HeadShape = HeadShape> {
91
- readonly name: Name;
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 OUTPUT rule of a `program()` receives: a query rule plus finished-stratum `idb` atoms. */
166
- interface OutputRuleScope<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>): OutputRuleChain<Rels, BindParamsShape<MatchFields<R>, B>, Classes>;
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 output rule: atoms, predicates, `idb` joins over the program's recs, then the head. */
177
- interface OutputRuleChain<Rels extends SchemaRelations, P extends ParamsRecord, Classes extends SchemaClasses = SchemaClasses> {
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>): OutputRuleChain<Rels, Flatten<P & BindParamsShape<MatchFields<R>, B>>, Classes>;
179
- where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): OutputRuleChain<Rels, Flatten<P & CondParamsShape<C>>, Classes>;
180
- /**
181
- * One `idb` atom over a FINISHED stratum (any rec of this program): a
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 RECURSIVE rule (`rec.rule(...)`) receives. */
192
- interface RecRuleScope<Rels extends SchemaRelations, Self extends string, Classes extends SchemaClasses = SchemaClasses> extends TermOps {
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, Self, BindParamsShape<MatchFields<R>, B>, Classes>;
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 rule. Its `idb` accepts ONLY the rec itself (the
197
- * self-recursion cut) and its `find` takes bound variables only — aggregates
198
- * and the measure are unrepresentable in a recursive head.
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, Self extends string, P extends ParamsRecord, Classes extends SchemaClasses = SchemaClasses> {
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, Self, Flatten<P & BindParamsShape<MatchFields<R>, B>>, Classes>;
202
- where<const C extends AnyCond>(cond: CheckCond<Classes, C> & C): RecRuleChain<Rels, Self, Flatten<P & CondParamsShape<C>>, Classes>;
203
- /** The self-recursive atom: `idb(self, { headKey: boundVar })` — only this rec's own reference is accepted. */
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
- /** The program's recursive predicates in declaration order (empty for a plain query); `PredId` = index. */
211
- readonly recs: readonly RecData[];
212
- /** The output rules in written order (multiple rules = set union). */
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 program walk (= dense `ParamId`s). */
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
- /** The entry value of `query(S)`: the first `.rule` mints the query. */
244
- interface QueryStart<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> {
245
- rule<RV extends AnyRuleValue>(build: (r: QueryRuleScope<Rels, Classes>) => RV): Query<Rels, RowOf<RV>, ParamsOf<RV>, Classes>;
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
- idb(target: RecRef<string, ParamsRecord>, bindings: Readonly<Record<string, unknown>>): RawChain;
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
- idb(target: RecRef<string, ParamsRecord>, bindings: Readonly<Record<string, unknown>>): RawChain;
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: "rec";
270
- readonly self: RecData;
267
+ readonly kind: "interior";
268
+ readonly self: string;
271
269
  } | {
272
- readonly kind: "output";
273
- readonly program: ProgramState;
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 => ...)`. Each `.rule` adds
290
- * one conjunctive rule; multiple rules are the set union. The schema's
291
- * law-computed class map and theory value ride into every rule builder — the
292
- * join walls compare against the mint slots off it.
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 `ProgramIr` — pure and stable: the
312
- * recs in declaration order (`PredId` = index), the output predicate
313
- * appended last. Every registered param must carry a field anchor by now.
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): ProgramIr;
316
- export type { AnyQuery, AnyRuleValue, HeadOf, HeadShape, OutputRuleChain, OutputRuleScope, ParamsOf, ProgramState, Query, QueryData, QueryParams, QueryRelation, QueryRow, QueryRuleChain, QueryRuleScope, QueryStart, RawChain, RawScope, RecRef, RecRuleChain, RecRuleScope, RowOf, RuleValue, TermOps };
317
- export { lowerQuery, makeOutputRuleScope, makeQuery, makeRawScope, query, taggedCmpLiteral, taggedLiteral };
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