@bjornpagen/bumbledb 0.1.0 → 0.2.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 +1394 -0
- package/README.md +4 -0
- package/dist/closed.d.ts +60 -37
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +159 -40
- package/dist/closed.js.map +1 -1
- package/dist/count.d.ts +64 -17
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +37 -14
- package/dist/count.js.map +1 -1
- package/dist/db.d.ts +15 -7
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +13 -5
- package/dist/db.js.map +1 -1
- package/dist/exhume.d.ts +12 -11
- package/dist/exhume.d.ts.map +1 -1
- package/dist/exhume.js +7 -6
- package/dist/exhume.js.map +1 -1
- package/dist/face.d.ts +79 -19
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +14 -15
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +158 -129
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +80 -81
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -12
- package/dist/index.js.map +1 -1
- package/dist/lower.d.ts +6 -3
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +48 -17
- package/dist/lower.js.map +1 -1
- package/dist/marshal.d.ts +36 -21
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +41 -25
- package/dist/marshal.js.map +1 -1
- package/dist/native.js +2 -2
- package/dist/query/atom.d.ts +332 -174
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +72 -172
- package/dist/query/atom.js.map +1 -1
- package/dist/query/lower.d.ts +295 -107
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +860 -388
- package/dist/query/lower.js.map +1 -1
- package/dist/query/predicate.d.ts +69 -88
- package/dist/query/predicate.d.ts.map +1 -1
- package/dist/query/predicate.js +118 -72
- package/dist/query/predicate.js.map +1 -1
- package/dist/query/run.d.ts +19 -16
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +31 -24
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +139 -123
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +71 -115
- package/dist/query/scope.js.map +1 -1
- package/dist/query/select.d.ts +102 -80
- package/dist/query/select.d.ts.map +1 -1
- package/dist/query/select.js +39 -34
- package/dist/query/select.js.map +1 -1
- package/dist/relation.d.ts +33 -36
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +15 -16
- package/dist/relation.js.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +19 -8
- package/dist/schema.js.map +1 -1
- package/dist/spec.d.ts +6 -5
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +56 -31
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +38 -13
- package/dist/statements.js.map +1 -1
- package/package.json +4 -3
- package/src/closed.ts +271 -93
- package/src/count.ts +112 -18
- package/src/db.ts +22 -12
- package/src/exhume.ts +12 -11
- package/src/face.ts +114 -22
- package/src/fields.ts +261 -217
- package/src/index.ts +50 -59
- package/src/lower.ts +62 -20
- package/src/marshal.ts +48 -30
- package/src/native.ts +2 -2
- package/src/query/atom.ts +480 -376
- package/src/query/lower.ts +1341 -542
- package/src/query/predicate.ts +198 -161
- package/src/query/run.ts +35 -25
- package/src/query/scope.ts +188 -218
- package/src/query/select.ts +168 -93
- package/src/relation.ts +38 -44
- package/src/schema.ts +22 -12
- package/src/spec.ts +6 -5
- package/src/statements.ts +69 -26
- package/dist/brand.d.ts +0 -59
- package/dist/brand.d.ts.map +0 -1
- package/dist/brand.js +0 -47
- package/dist/brand.js.map +0 -1
- package/src/brand.ts +0 -82
package/dist/query/atom.d.ts
CHANGED
|
@@ -1,226 +1,322 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* mirroring the engine IR variant for variant
|
|
2
|
+
* Atoms and conditions, STRUCTURAL edition — the body vocabulary of a
|
|
3
|
+
* rule, mirroring the engine IR variant for variant
|
|
4
4
|
* (`bumbledb/crates/bumbledb/src/ir.rs`, the bijection target;
|
|
5
|
-
* `docs/architecture/20-query-ir.md` normative)
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and `
|
|
12
|
-
*
|
|
5
|
+
* `docs/architecture/20-query-ir.md` normative). A `match` binding record
|
|
6
|
+
* binds fields to vars, params, ∈-set params, or bare structural literals
|
|
7
|
+
* (unmentioned fields ARE the wildcard — no wildcard value exists);
|
|
8
|
+
* `not(Rel, {...})` is negation-as-position (anti-join); `eq`/`ne` and the
|
|
9
|
+
* order roster, `pointIn`/`covers` (both spellings of `ir::CmpOp::PointIn`,
|
|
10
|
+
* always lowered interval-left), `allen` (the 13-bit mask pair
|
|
11
|
+
* comparison), and `and`/`or` (the input condition-tree grammar) complete
|
|
12
|
+
* the roster. Nothing beyond the IR exists here — and the walls the engine
|
|
13
|
+
* enforces at prepare are TYPES first: a var joins only domain-equal
|
|
14
|
+
* fields (`JoinOk`, checked against the rule environment AND against the
|
|
15
|
+
* binding record's own same-named siblings — two first occurrences of one
|
|
16
|
+
* name inside one record are a join too), an
|
|
17
|
+
* interval-typed var under a non-`pointIn` comparison is unwritable, and a
|
|
18
|
+
* negated atom's variables must be positively bound (env membership IS the
|
|
19
|
+
* safety rule). Every condition value carries its operands raw — the
|
|
20
|
+
* runtime representation is the type-inference carrier, no phantoms.
|
|
21
|
+
*
|
|
22
|
+
* This module also owns the plain runtime DATA a built rule is made of
|
|
23
|
+
* (`RuleData`/`RecData` and friends): frozen values the lowering walks —
|
|
24
|
+
* pure data, so lowering stays a pure, stable function of the query value.
|
|
13
25
|
*/
|
|
14
|
-
import type { IntervalValue } from "#
|
|
15
|
-
import {
|
|
16
|
-
import type { OneOf } from "#face.ts";
|
|
17
|
-
import type { FieldData, FieldValue } from "#fields.ts";
|
|
18
|
-
import type { PredicateData } from "#query/predicate.ts";
|
|
19
|
-
import type { AnyTerm, AnyVar, ItemParams, MaskParam, Param, ParamSet, ParamsRecord, ParamsShape, TermContribution, Var } from "#query/scope.ts";
|
|
26
|
+
import type { AnyField, Infer, IntervalValue } from "#fields.ts";
|
|
27
|
+
import type { Duration, EnvShape, JoinOk, MaskParam, Param, ParamValueAt, SetParam, ShapeOf, Var } from "#query/scope.ts";
|
|
20
28
|
import type { AnyRelation, FieldsShape, Relation } from "#relation.ts";
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
31
|
-
readonly value: AnyTerm;
|
|
29
|
+
/** One atom-binding position as runtime data. */
|
|
30
|
+
type BindingTermData = {
|
|
31
|
+
readonly kind: "var";
|
|
32
|
+
readonly name: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "param";
|
|
35
|
+
readonly name: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: "setParam";
|
|
38
|
+
readonly name: string;
|
|
32
39
|
} | {
|
|
33
40
|
readonly kind: "literal";
|
|
34
41
|
readonly value: unknown;
|
|
35
|
-
} | {
|
|
36
|
-
readonly kind: "oneOf";
|
|
37
|
-
readonly values: readonly unknown[];
|
|
38
42
|
};
|
|
39
|
-
/** One resolved binding: the field's name, its
|
|
43
|
+
/** One resolved binding: the field's name, its descriptor, and the term. */
|
|
40
44
|
interface BindingEntry {
|
|
41
45
|
readonly field: string;
|
|
42
|
-
readonly data:
|
|
43
|
-
readonly term:
|
|
46
|
+
readonly data: AnyField;
|
|
47
|
+
readonly term: BindingTermData;
|
|
44
48
|
}
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
readonly kind: "relation";
|
|
49
|
+
/** One EDB atom as runtime data (either polarity — polarity is the rule item's). */
|
|
50
|
+
interface AtomData {
|
|
48
51
|
readonly relation: AnyRelation;
|
|
49
|
-
} | {
|
|
50
|
-
readonly kind: "predicate";
|
|
51
|
-
readonly pred: PredicateData;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* One atom value (positive or negated — negation is a position in the
|
|
55
|
-
* rule, not a kind of atom, exactly as the IR reuses `Atom` unchanged).
|
|
56
|
-
* The phantom carries the params object the atom's bindings contribute.
|
|
57
|
-
*/
|
|
58
|
-
interface MatchAtom<P extends ParamsRecord> {
|
|
59
|
-
readonly item: "atom";
|
|
60
|
-
readonly negated: boolean;
|
|
61
|
-
readonly source: AtomSourceData;
|
|
62
52
|
readonly bindings: readonly BindingEntry[];
|
|
63
|
-
readonly [phantom]?: P;
|
|
64
53
|
}
|
|
54
|
+
/** One comparison operator name (mirrors `ir::CmpOp`). */
|
|
55
|
+
type CmpKind = "eq" | "ne" | "lt" | "le" | "gt" | "ge" | "pointIn" | "allen";
|
|
65
56
|
/** One comparison side as runtime data. */
|
|
66
|
-
type
|
|
67
|
-
readonly kind: "
|
|
68
|
-
readonly
|
|
57
|
+
type CmpTermData = {
|
|
58
|
+
readonly kind: "var";
|
|
59
|
+
readonly name: string;
|
|
69
60
|
} | {
|
|
70
|
-
readonly kind: "
|
|
71
|
-
readonly
|
|
61
|
+
readonly kind: "param";
|
|
62
|
+
readonly name: string;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "setParam";
|
|
65
|
+
readonly name: string;
|
|
72
66
|
} | {
|
|
73
67
|
readonly kind: "measure";
|
|
74
|
-
readonly
|
|
68
|
+
readonly name: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "literal";
|
|
71
|
+
readonly value: unknown;
|
|
75
72
|
};
|
|
76
|
-
/** The `allen` mask position
|
|
73
|
+
/** The `allen` mask position as runtime data. */
|
|
77
74
|
type MaskData = {
|
|
78
75
|
readonly kind: "literal";
|
|
79
76
|
readonly mask: number;
|
|
80
77
|
} | {
|
|
81
78
|
readonly kind: "param";
|
|
82
|
-
readonly
|
|
79
|
+
readonly name: string;
|
|
83
80
|
};
|
|
84
|
-
/** One comparison
|
|
85
|
-
|
|
86
|
-
readonly kind: "
|
|
87
|
-
|
|
88
|
-
readonly
|
|
81
|
+
/** One comparison condition as runtime data (`mask` present exactly for `allen`). */
|
|
82
|
+
interface CmpData {
|
|
83
|
+
readonly kind: "cmp";
|
|
84
|
+
readonly op: CmpKind;
|
|
85
|
+
readonly mask: MaskData | undefined;
|
|
86
|
+
readonly lhs: CmpTermData;
|
|
87
|
+
readonly rhs: CmpTermData;
|
|
88
|
+
}
|
|
89
|
+
/** One condition-tree node as runtime data (`ir::ConditionTree`). */
|
|
90
|
+
interface TreeData {
|
|
91
|
+
readonly kind: "tree";
|
|
92
|
+
readonly op: "and" | "or";
|
|
93
|
+
readonly children: readonly CondData[];
|
|
94
|
+
}
|
|
95
|
+
/** Any condition node as runtime data. */
|
|
96
|
+
type CondData = CmpData | TreeData;
|
|
97
|
+
/** One aggregate's runtime description (select vocabulary, over var NAMES). */
|
|
98
|
+
type AggData = {
|
|
99
|
+
readonly op: "count";
|
|
89
100
|
} | {
|
|
90
|
-
readonly
|
|
101
|
+
readonly op: "countDistinct";
|
|
102
|
+
readonly over: string;
|
|
91
103
|
} | {
|
|
92
|
-
readonly
|
|
104
|
+
readonly op: "fold";
|
|
105
|
+
readonly fold: "sum" | "min" | "max";
|
|
106
|
+
readonly over: string | {
|
|
107
|
+
readonly duration: string;
|
|
108
|
+
};
|
|
93
109
|
} | {
|
|
94
|
-
readonly
|
|
110
|
+
readonly op: "arg";
|
|
111
|
+
readonly direction: "argMax" | "argMin";
|
|
112
|
+
readonly over: string;
|
|
113
|
+
readonly key: string;
|
|
95
114
|
} | {
|
|
96
|
-
readonly
|
|
115
|
+
readonly op: "pack";
|
|
116
|
+
readonly over: string;
|
|
117
|
+
};
|
|
118
|
+
/** One classified select entry as runtime data. */
|
|
119
|
+
type SelectEntryData = {
|
|
120
|
+
readonly kind: "var";
|
|
121
|
+
readonly over: string;
|
|
97
122
|
} | {
|
|
98
|
-
readonly kind: "
|
|
99
|
-
readonly
|
|
123
|
+
readonly kind: "measure";
|
|
124
|
+
readonly over: string;
|
|
100
125
|
} | {
|
|
101
|
-
readonly kind: "
|
|
126
|
+
readonly kind: "aggregate";
|
|
127
|
+
readonly agg: AggData;
|
|
102
128
|
};
|
|
103
|
-
/** One
|
|
104
|
-
interface
|
|
105
|
-
readonly
|
|
106
|
-
readonly
|
|
107
|
-
readonly lhs: CmpTerm;
|
|
108
|
-
readonly rhs: CmpTerm;
|
|
109
|
-
readonly [phantom]?: P;
|
|
129
|
+
/** One answer column: its name (the row object key) and its entry. */
|
|
130
|
+
interface SelectColumn {
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly entry: SelectEntryData;
|
|
110
133
|
}
|
|
134
|
+
/** One body item of a rule, in written order. */
|
|
135
|
+
type RuleItem = {
|
|
136
|
+
readonly kind: "atom";
|
|
137
|
+
readonly atom: AtomData;
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "negated";
|
|
140
|
+
readonly atom: AtomData;
|
|
141
|
+
} | {
|
|
142
|
+
readonly kind: "idb";
|
|
143
|
+
readonly rec: RecData;
|
|
144
|
+
readonly vars: readonly string[];
|
|
145
|
+
} | {
|
|
146
|
+
readonly kind: "cond";
|
|
147
|
+
readonly cond: CondData;
|
|
148
|
+
};
|
|
111
149
|
/**
|
|
112
|
-
* One
|
|
113
|
-
*
|
|
114
|
-
*
|
|
150
|
+
* One use of a parameter inside a rule, in written order: the census the
|
|
151
|
+
* query-level registry folds (first use mints the dense `ParamId`, first
|
|
152
|
+
* FIELD-ANCHORED use types the wire).
|
|
115
153
|
*/
|
|
116
|
-
interface
|
|
117
|
-
readonly
|
|
118
|
-
readonly
|
|
119
|
-
readonly
|
|
120
|
-
readonly
|
|
154
|
+
interface ParamUse {
|
|
155
|
+
readonly name: string;
|
|
156
|
+
readonly shape: "value" | "set" | "mask";
|
|
157
|
+
readonly anchor: AnyField | "measure" | undefined;
|
|
158
|
+
readonly op: "binding" | CmpKind;
|
|
159
|
+
}
|
|
160
|
+
/** One complete rule as runtime data. */
|
|
161
|
+
interface RuleData {
|
|
162
|
+
readonly items: readonly RuleItem[];
|
|
163
|
+
readonly select: readonly SelectColumn[];
|
|
164
|
+
/** Variable name → the field descriptor its FIRST positive binding carries (the runtime env). */
|
|
165
|
+
readonly varFields: Readonly<Record<string, AnyField>>;
|
|
166
|
+
readonly paramUses: readonly ParamUse[];
|
|
121
167
|
}
|
|
122
|
-
/** Any condition value, whatever its params. */
|
|
123
|
-
type AnyCondition = ComparisonItem<ParamsRecord> | ConditionTreeItem<ParamsRecord>;
|
|
124
|
-
/** Any rule body item: an atom (either polarity) or a condition. */
|
|
125
|
-
type AnyBodyItem = MatchAtom<ParamsRecord> | AnyCondition;
|
|
126
168
|
/**
|
|
127
|
-
*
|
|
128
|
-
* `
|
|
129
|
-
*
|
|
130
|
-
* `sum`/`min`/`max`; every other position is unwritable here exactly as
|
|
131
|
-
* the IR rejects it typed. A ray has no finite measure — the engine's
|
|
132
|
-
* `MeasureOfRay` execution error; exclude rays first (`allen` against a
|
|
133
|
-
* bounded window).
|
|
169
|
+
* One recursive predicate's runtime description — identity keys the dense
|
|
170
|
+
* `PredId` at lowering. `rules` is appended by `rec.rule(...)` and sealed
|
|
171
|
+
* (frozen) when the program's output is declared.
|
|
134
172
|
*/
|
|
135
|
-
interface
|
|
136
|
-
readonly
|
|
137
|
-
readonly [
|
|
173
|
+
interface RecData {
|
|
174
|
+
readonly name: string;
|
|
175
|
+
readonly rules: RuleData[];
|
|
138
176
|
}
|
|
139
177
|
/**
|
|
140
|
-
* What a binding position of
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
178
|
+
* What a binding position of field `F` accepts: a bare structural literal
|
|
179
|
+
* of the field's value type, a var/param/∈-set-param term — and, when the
|
|
180
|
+
* field is interval-typed, a bare point literal (the IR's membership
|
|
181
|
+
* typing rule: an element-typed term at an interval field is point
|
|
182
|
+
* membership; an interval-typed term is value equality).
|
|
145
183
|
*/
|
|
146
|
-
type
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
type BindingInput<F extends AnyField> = Infer<F> | (F extends {
|
|
185
|
+
readonly kind: "interval";
|
|
186
|
+
} ? bigint : never) | Var<string> | Param<string> | SetParam<string>;
|
|
149
187
|
/**
|
|
150
|
-
* The `match` bindings record: per field, a term of that
|
|
151
|
-
* unmentioned fields are wildcards (absence IS
|
|
152
|
-
* no wildcard variant to spell).
|
|
188
|
+
* The `match`/`not` bindings record: per field, a term or literal of that
|
|
189
|
+
* field's structural type; unmentioned fields are wildcards (absence IS
|
|
190
|
+
* the wildcard — the IR has no wildcard variant to spell).
|
|
153
191
|
*/
|
|
154
|
-
type
|
|
155
|
-
readonly [K in keyof
|
|
192
|
+
type MatchShape<F extends FieldsShape> = {
|
|
193
|
+
readonly [K in keyof F]?: BindingInput<F[K]>;
|
|
156
194
|
};
|
|
157
|
-
/** The params object a bindings record contributes (used by `match`). */
|
|
158
|
-
type BindingsParams<B> = ParamsShape<TermContribution<B[keyof B]>>;
|
|
159
195
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* the record's written order.
|
|
196
|
+
* The var binding's judgment against the incoming rule environment: a name
|
|
197
|
+
* already bound must land on a domain-equal field.
|
|
163
198
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
199
|
+
type EnvJoinOk<Env extends EnvShape, F extends FieldsShape, K, N extends string> = N extends keyof Env ? JoinOk<Env[N], F[K & keyof F]> : true;
|
|
200
|
+
/**
|
|
201
|
+
* The var binding's judgment against its OWN record's siblings: two
|
|
202
|
+
* bindings of one var name inside a single bindings record are the same
|
|
203
|
+
* join the environment check judges across atoms, so every same-named
|
|
204
|
+
* sibling must be domain-equal too. Without this arm two FIRST occurrences
|
|
205
|
+
* of one name (a record the environment has not seen yet) would meet no
|
|
206
|
+
* check at all — the intra-atom join would silently cross domains.
|
|
207
|
+
*/
|
|
208
|
+
type SiblingJoinOk<F extends FieldsShape, B, K extends keyof B, N extends string> = false extends {
|
|
209
|
+
[K2 in Exclude<keyof B & keyof F, K>]: B[K2] extends Var<N> ? JoinOk<F[K2], F[K & keyof F]> : true;
|
|
210
|
+
}[Exclude<keyof B & keyof F, K>] ? false : true;
|
|
168
211
|
/**
|
|
169
|
-
* The
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
212
|
+
* The per-property join judgment of a bindings record: a var binding must
|
|
213
|
+
* be domain-equal to the rule environment's binding of the name AND to
|
|
214
|
+
* every same-named sibling of its own record (a cross-domain reuse maps
|
|
215
|
+
* the property to `never` — the compile error the old value brand carried,
|
|
216
|
+
* now structural).
|
|
173
217
|
*/
|
|
174
|
-
|
|
218
|
+
type BindingOk<Env extends EnvShape, F extends FieldsShape, B, K extends keyof B> = B[K] extends Var<infer N extends string> ? [EnvJoinOk<Env, F, K, N>, SiblingJoinOk<F, B, K, N>] extends [true, true] ? true : false : true;
|
|
219
|
+
/** The validated bindings record (intersect with the inferred `B` — errors land on the offending property). */
|
|
220
|
+
type CheckBindings<Env extends EnvShape, F extends FieldsShape, B> = {
|
|
221
|
+
readonly [K in keyof B]: K extends keyof F ? (BindingOk<Env, F, B, K> extends true ? B[K] : never) : never;
|
|
222
|
+
};
|
|
223
|
+
/** The environment a bindings record contributes: var name → the bound field's descriptor. */
|
|
224
|
+
type BindEnv<F extends FieldsShape, B> = {
|
|
225
|
+
readonly [K in keyof B & keyof F as B[K] extends Var<infer N extends string> ? N : never]: F[K];
|
|
226
|
+
};
|
|
227
|
+
/** The params-object fragments a bindings record contributes (one union member per param use). */
|
|
228
|
+
type BindParams<F extends FieldsShape, B> = {
|
|
229
|
+
[K in keyof B & keyof F]: B[K] extends Param<infer P extends string> ? {
|
|
230
|
+
readonly [Q in P]: ParamValueAt<F[K]>;
|
|
231
|
+
} : B[K] extends SetParam<infer P extends string> ? {
|
|
232
|
+
readonly [Q in P]: readonly ParamValueAt<F[K]>[];
|
|
233
|
+
} : never;
|
|
234
|
+
}[keyof B & keyof F];
|
|
175
235
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* binding is refused HERE, at construction: it lowers to a synthetic
|
|
181
|
-
* variable bound only inside the atom plus a rule-level OR — which is
|
|
182
|
-
* exactly the shape the safety rule rejects, and semantically wrong for
|
|
183
|
-
* negation anyway (¬∃(f = a ∨ f = b) is a CONJUNCTION of negated atoms,
|
|
184
|
-
* ¬∃(f = a) ∧ ¬∃(f = b), never one negated atom's OR).
|
|
236
|
+
* One comparison VALUE: op plus its operands, raw — the runtime
|
|
237
|
+
* representation carries the operand types, so `.where`'s environment
|
|
238
|
+
* check and the params inference both read the value itself (no phantom).
|
|
239
|
+
* `mask` is populated exactly for `allen`.
|
|
185
240
|
*/
|
|
186
|
-
|
|
241
|
+
interface Cmp<Op extends CmpKind, L, R, M = undefined> {
|
|
242
|
+
readonly cond: "cmp";
|
|
243
|
+
readonly op: Op;
|
|
244
|
+
readonly lhs: L;
|
|
245
|
+
readonly rhs: R;
|
|
246
|
+
readonly mask: M;
|
|
247
|
+
}
|
|
248
|
+
/** One condition-tree VALUE (`and`/`or` over comparisons and nested trees). */
|
|
249
|
+
interface Tree<Ch extends readonly AnyTreeChild[]> {
|
|
250
|
+
readonly cond: "tree";
|
|
251
|
+
readonly op: "and" | "or";
|
|
252
|
+
readonly children: Ch;
|
|
253
|
+
}
|
|
187
254
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
255
|
+
* One negated-atom VALUE — negation is a position in the rule (anti-join
|
|
256
|
+
* over sets, no null trick): a binding satisfies it iff NO fact matches.
|
|
257
|
+
* Its variables must be positively bound in the rule — environment
|
|
258
|
+
* membership at `.where` IS the safety rule, a compile error before it is
|
|
259
|
+
* the engine's refusal.
|
|
193
260
|
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
261
|
+
interface NotAtom<F extends FieldsShape, B> {
|
|
262
|
+
readonly cond: "not";
|
|
263
|
+
readonly relation: Relation<string, F>;
|
|
264
|
+
readonly bindings: B;
|
|
265
|
+
}
|
|
266
|
+
/** Any comparison value. */
|
|
267
|
+
type AnyCmp = Cmp<CmpKind, unknown, unknown, unknown>;
|
|
268
|
+
/** Any condition-tree child (trees hold comparisons and trees — never atoms). */
|
|
269
|
+
type AnyTreeChild = AnyCmp | Tree<readonly AnyTreeChild[]>;
|
|
270
|
+
/** Any negated-atom value. */
|
|
271
|
+
type AnyNotAtom = NotAtom<FieldsShape, unknown>;
|
|
272
|
+
/** Any `.where` input: a comparison, a condition tree, or a negated atom. */
|
|
273
|
+
type AnyCond = AnyCmp | Tree<readonly AnyTreeChild[]> | AnyNotAtom;
|
|
274
|
+
/** What `eq`'s right side accepts (`ParamSet` is `Eq`-only — the IR's rule). */
|
|
275
|
+
type EqRight = Var<string> | Param<string> | SetParam<string> | bigint | string | boolean | Uint8Array | IntervalValue;
|
|
276
|
+
/** What `ne`'s right side accepts. */
|
|
277
|
+
type NeRight = Var<string> | Param<string> | bigint | string | boolean | Uint8Array | IntervalValue;
|
|
278
|
+
/** One side of an order comparison: orderable terms only (the IR's comparison rules). */
|
|
279
|
+
type OrderSide = Var<string> | Param<string> | Duration<string> | bigint;
|
|
280
|
+
/** The point side of `pointIn`/`covers`. */
|
|
281
|
+
type PointSide = Var<string> | Param<string> | bigint;
|
|
282
|
+
/** The interval side of `pointIn`/`covers`/`allen`. */
|
|
283
|
+
type IntervalSide = Var<string> | Param<string> | IntervalValue;
|
|
284
|
+
/** Builds one comparison value. */
|
|
285
|
+
declare function comparison<Op extends CmpKind, L, R, M>(op: Op, lhs: L, rhs: R, mask: M): Cmp<Op, L, R, M>;
|
|
197
286
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
287
|
+
* The equality comparison (`ir::CmpOp::Eq`) — a bound variable against a
|
|
288
|
+
* variable (var-to-var unification, domain-equal by the environment
|
|
289
|
+
* check), a param (typed by the variable), an ∈-set param (`Eq`-only, the
|
|
290
|
+
* IR's set rule), or a bare literal of the variable's own value type.
|
|
291
|
+
* Prefer direct placement in `match` where punning applies.
|
|
202
292
|
*/
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
declare function
|
|
293
|
+
declare function eq<L extends Var<string>, const R extends EqRight>(left: L, right: R): Cmp<"eq", L, R>;
|
|
294
|
+
/** Typed disequality (`ir::CmpOp::Ne`). "Not in set" has no operator — write a negated atom. */
|
|
295
|
+
declare function ne<L extends Var<string>, const R extends NeRight>(left: L, right: R): Cmp<"ne", L, R>;
|
|
296
|
+
/** Strict less-than (`ir::CmpOp::Lt`) — orderable sides only, never intervals/bytes/strings/bools. */
|
|
297
|
+
declare function lt<const L extends OrderSide, const R extends OrderSide>(left: L, right: R): Cmp<"lt", L, R>;
|
|
206
298
|
/** Less-or-equal (`ir::CmpOp::Le`). */
|
|
207
|
-
declare function le<const L extends
|
|
299
|
+
declare function le<const L extends OrderSide, const R extends OrderSide>(left: L, right: R): Cmp<"le", L, R>;
|
|
208
300
|
/** Strict greater-than (`ir::CmpOp::Gt`). */
|
|
209
|
-
declare function gt<const L extends
|
|
301
|
+
declare function gt<const L extends OrderSide, const R extends OrderSide>(left: L, right: R): Cmp<"gt", L, R>;
|
|
210
302
|
/** Greater-or-equal (`ir::CmpOp::Ge`). */
|
|
211
|
-
declare function ge<const L extends
|
|
212
|
-
/**
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
303
|
+
declare function ge<const L extends OrderSide, const R extends OrderSide>(left: L, right: R): Cmp<"ge", L, R>;
|
|
304
|
+
/**
|
|
305
|
+
* Point membership as a predicate (`ir::CmpOp::PointIn`), membership
|
|
306
|
+
* spelling: `pointIn(t, w)` holds iff `w.start ≤ t < w.end`. The IR
|
|
307
|
+
* orders the operands interval-left, point-right; the value stores them
|
|
308
|
+
* that way whatever the surface spelling.
|
|
309
|
+
*/
|
|
310
|
+
declare function pointIn<const P extends PointSide, const I extends IntervalSide>(point: P, interval: I): Cmp<"pointIn", I, P>;
|
|
216
311
|
/**
|
|
217
|
-
* Point membership
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
312
|
+
* Point membership, coverage spelling — `covers(w, t)` is `pointIn(t, w)`
|
|
313
|
+
* with the interval written first (the IR's own operand order; a literal
|
|
314
|
+
* `span(...)` left operand is legal and tags by the point sibling's
|
|
315
|
+
* element domain — the bug-hunt fix, now also a type-level guarantee).
|
|
316
|
+
* Interval ⊇ interval is NOT this operator; that predicate is
|
|
317
|
+
* `allen(a, ALLEN.covers, b)`.
|
|
222
318
|
*/
|
|
223
|
-
declare function covers<const I extends
|
|
319
|
+
declare function covers<const I extends IntervalSide, const P extends PointSide>(interval: I, point: P): Cmp<"pointIn", I, P>;
|
|
224
320
|
/**
|
|
225
321
|
* The Allen coordinate system's named constants — the 13 basics in the
|
|
226
322
|
* engine's palindromic bit order (bit i = basic i:
|
|
@@ -255,31 +351,93 @@ declare const ALLEN: Readonly<{
|
|
|
255
351
|
* THE interval-pair comparison (`ir::CmpOp::Allen`): two interval terms of
|
|
256
352
|
* one element type, satisfied iff the pair's classification is in the
|
|
257
353
|
* 13-bit mask — a literal built from the `ALLEN` constants, or a mask
|
|
258
|
-
* parameter (
|
|
354
|
+
* parameter (`r.maskParam`). Vacuous masks (empty/full) are the engine's
|
|
259
355
|
* two distinct typed rejections; nothing is pre-judged here beyond the
|
|
260
356
|
* representable bit range.
|
|
261
357
|
*/
|
|
262
|
-
declare function allen<const A extends
|
|
358
|
+
declare function allen<const A extends IntervalSide, const M extends number | MaskParam<string>, const B extends IntervalSide>(left: A, mask: M, right: B): Cmp<"allen", A, B, M>;
|
|
263
359
|
/**
|
|
264
360
|
* Conjunction node of the input condition grammar (`ConditionTree::And`).
|
|
265
361
|
* The rule's condition list is already a conjunction — `and` exists for
|
|
266
362
|
* nesting under `or`, and the empty combination keeps the IR's algebraic
|
|
267
363
|
* reading (`And([])` is true).
|
|
268
364
|
*/
|
|
269
|
-
declare function and<const C extends readonly
|
|
365
|
+
declare function and<const C extends readonly AnyTreeChild[]>(...children: C): Tree<C>;
|
|
270
366
|
/**
|
|
271
367
|
* Disjunction node of the input condition grammar (`ConditionTree::Or`) —
|
|
272
368
|
* the one place the surface admits a nested OR; validation distributes it
|
|
273
369
|
* to DNF rules engine-side (OR is data or it is nothing). `Or([])` keeps
|
|
274
370
|
* its algebraic reading (false: the rule denotes nothing).
|
|
275
371
|
*/
|
|
276
|
-
declare function or<const C extends readonly
|
|
372
|
+
declare function or<const C extends readonly AnyTreeChild[]>(...children: C): Tree<C>;
|
|
373
|
+
/**
|
|
374
|
+
* Negation — anti-join over sets: `not(Rel, { field: r.var("x"), ... })`
|
|
375
|
+
* rejects every binding some matching fact extends. A negated atom binds
|
|
376
|
+
* nothing, only rejects: every variable it names must be positively bound
|
|
377
|
+
* in the rule, which `.where`'s environment check makes a COMPILE error
|
|
378
|
+
* (the engine's safety refusal stands behind it).
|
|
379
|
+
*/
|
|
380
|
+
declare function not<Name extends string, F extends FieldsShape, const B extends MatchShape<F>>(relation: Relation<Name, F>, bindings: B): NotAtom<F, B>;
|
|
381
|
+
/** Whether a var name is bound in the environment at an orderable (u64/i64) field. */
|
|
382
|
+
type OrderVarOk<Env extends EnvShape, N extends string> = N extends keyof Env ? Env[N]["kind"] extends "u64" | "i64" ? true : false : false;
|
|
383
|
+
/** Whether a var name is bound at an interval field. */
|
|
384
|
+
type IntervalVarOk<Env extends EnvShape, N extends string> = N extends keyof Env ? Env[N]["kind"] extends "interval" ? true : false : false;
|
|
385
|
+
/** One order-comparison side's judgment against the environment. */
|
|
386
|
+
type OrderSideOk<Env extends EnvShape, T> = T extends Var<infer N extends string> ? OrderVarOk<Env, N> : T extends Duration<infer N extends string> ? IntervalVarOk<Env, N> : true;
|
|
387
|
+
/** One point side's judgment. */
|
|
388
|
+
type PointSideOk<Env extends EnvShape, T> = T extends Var<infer N extends string> ? OrderVarOk<Env, N> : true;
|
|
389
|
+
/** One interval side's judgment. */
|
|
390
|
+
type IntervalSideOk<Env extends EnvShape, T> = T extends Var<infer N extends string> ? IntervalVarOk<Env, N> : true;
|
|
391
|
+
/** The `eq`/`ne` judgment: left var bound; right joins it (domain-equal var, param, or an exact-type literal). */
|
|
392
|
+
type EqOk<Env extends EnvShape, L, R> = L extends Var<infer N extends string> ? N extends keyof Env ? R extends Var<infer M extends string> ? M extends keyof Env ? JoinOk<Env[N], Env[M]> : false : R extends Param<string> | SetParam<string> ? true : [R] extends [Infer<Env[N]>] ? true : false : false : false;
|
|
393
|
+
/** One negated-atom binding's judgment: a var must be positively bound (safety) AND domain-equal. */
|
|
394
|
+
type NotBindingOk<Env extends EnvShape, F extends AnyField, T> = T extends Var<infer N extends string> ? (N extends keyof Env ? JoinOk<Env[N], F> : false) : true;
|
|
395
|
+
/** The whole negated atom's judgment. */
|
|
396
|
+
type NotOk<Env extends EnvShape, F extends FieldsShape, B> = false extends {
|
|
397
|
+
[K in keyof B]: NotBindingOk<Env, K extends keyof F ? F[K] : never, B[K]>;
|
|
398
|
+
}[keyof B] ? false : true;
|
|
399
|
+
/**
|
|
400
|
+
* One condition's judgment against the rule environment — the type-level
|
|
401
|
+
* twin of the engine's comparison roster: domain-equal joins, orderable
|
|
402
|
+
* order sides (an interval var under a non-`pointIn` op is exactly here
|
|
403
|
+
* refused), kind-correct `pointIn`/`covers`/`allen` sides, and negated-atom
|
|
404
|
+
* safety. The leading `[AnyTreeChild] extends [C]` arm is the recursion's
|
|
405
|
+
* base case: at an UNRESOLVED constraint (the whole condition union — or a
|
|
406
|
+
* tree's child union, which is the union itself) the judgment is vacuously
|
|
407
|
+
* true — without it the constraint instantiation recurses into itself.
|
|
408
|
+
*/
|
|
409
|
+
type CondOkBool<Env extends EnvShape, C> = [AnyTreeChild] extends [C] ? true : C extends Cmp<infer Op, infer L, infer R, unknown> ? Op extends "eq" | "ne" ? EqOk<Env, L, R> : Op extends "lt" | "le" | "gt" | "ge" ? [OrderSideOk<Env, L>, OrderSideOk<Env, R>] extends [true, true] ? true : false : Op extends "pointIn" ? [IntervalSideOk<Env, L>, PointSideOk<Env, R>] extends [true, true] ? true : false : Op extends "allen" ? [IntervalSideOk<Env, L>, IntervalSideOk<Env, R>] extends [true, true] ? true : false : false : C extends Tree<infer Ch extends readonly AnyTreeChild[]> ? false extends CondOkBool<Env, Ch[number]> ? false : true : C extends NotAtom<infer F extends FieldsShape, infer B> ? NotOk<Env, F, B> : false;
|
|
410
|
+
/** The validated `.where` argument (intersect with the inferred condition type). */
|
|
411
|
+
type CheckCond<Env extends EnvShape, C> = CondOkBool<Env, C> extends true ? C : never;
|
|
412
|
+
/** The `eq`/`ne` params contribution: the param typed by the left variable's field. */
|
|
413
|
+
type EqParams<Env extends EnvShape, L, R> = L extends Var<infer N extends string> ? R extends Param<infer P extends string> ? {
|
|
414
|
+
readonly [Q in P]: Infer<Env[N & keyof Env]>;
|
|
415
|
+
} : R extends SetParam<infer P extends string> ? {
|
|
416
|
+
readonly [Q in P]: readonly Infer<Env[N & keyof Env]>[];
|
|
417
|
+
} : never : never;
|
|
418
|
+
/** An order side's params contribution (order params are always `bigint`). */
|
|
419
|
+
type OrderSideParams<T> = T extends Param<infer P extends string> ? {
|
|
420
|
+
readonly [Q in P]: bigint;
|
|
421
|
+
} : never;
|
|
422
|
+
/** An interval side's params contribution. */
|
|
423
|
+
type IntervalSideParams<T> = T extends Param<infer P extends string> ? {
|
|
424
|
+
readonly [Q in P]: IntervalValue;
|
|
425
|
+
} : never;
|
|
426
|
+
/** The mask position's params contribution. */
|
|
427
|
+
type MaskParams<M> = M extends MaskParam<infer P extends string> ? {
|
|
428
|
+
readonly [Q in P]: number;
|
|
429
|
+
} : never;
|
|
277
430
|
/**
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* {@link
|
|
431
|
+
* One condition's params-object fragments (a union; the rule builder folds
|
|
432
|
+
* them into the inferred `Params` record) — every param typed by its use.
|
|
433
|
+
* The leading arm is the same base case as {@link CondOkBool}'s: the
|
|
434
|
+
* unresolved constraint contributes nothing.
|
|
281
435
|
*/
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
436
|
+
type CondParams<Env extends EnvShape, C> = [AnyTreeChild] extends [C] ? never : C extends Cmp<infer Op, infer L, infer R, infer M> ? Op extends "eq" | "ne" ? EqParams<Env, L, R> : Op extends "lt" | "le" | "gt" | "ge" ? OrderSideParams<L> | OrderSideParams<R> : Op extends "pointIn" ? IntervalSideParams<L> | OrderSideParams<R> : Op extends "allen" ? IntervalSideParams<L> | IntervalSideParams<R> | MaskParams<M> : never : C extends Tree<infer Ch extends readonly AnyTreeChild[]> ? CondParams<Env, Ch[number]> : C extends NotAtom<infer F extends FieldsShape, infer B> ? BindParams<F, B> : never;
|
|
437
|
+
/** The flattened params record one bindings record contributes. */
|
|
438
|
+
type BindParamsShape<F extends FieldsShape, B> = ShapeOf<BindParams<F, B>>;
|
|
439
|
+
/** The flattened params record one condition contributes. */
|
|
440
|
+
type CondParamsShape<Env extends EnvShape, C> = ShapeOf<CondParams<Env, C>>;
|
|
441
|
+
export type { AggData, AnyCmp, AnyCond, AnyNotAtom, AnyTreeChild, AtomData, BindEnv, BindingEntry, BindingInput, BindingTermData, BindParams, BindParamsShape, CheckBindings, CheckCond, Cmp, CmpData, CmpKind, CmpTermData, CondData, CondOkBool, CondParams, CondParamsShape, IntervalSide, IntervalVarOk, MaskData, MatchShape, NotAtom, OrderSide, OrderVarOk, ParamUse, PointSide, RecData, RuleData, RuleItem, SelectColumn, SelectEntryData, Tree, TreeData };
|
|
442
|
+
export { ALLEN, allen, and, comparison, covers, eq, ge, gt, le, lt, ne, not, or, pointIn };
|
|
285
443
|
//# sourceMappingURL=atom.d.ts.map
|