@bjornpagen/bumbledb 0.1.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 (108) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +84 -0
  3. package/dist/brand.d.ts +59 -0
  4. package/dist/brand.d.ts.map +1 -0
  5. package/dist/brand.js +47 -0
  6. package/dist/brand.js.map +1 -0
  7. package/dist/closed.d.ts +97 -0
  8. package/dist/closed.d.ts.map +1 -0
  9. package/dist/closed.js +107 -0
  10. package/dist/closed.js.map +1 -0
  11. package/dist/count.d.ts +55 -0
  12. package/dist/count.d.ts.map +1 -0
  13. package/dist/count.js +92 -0
  14. package/dist/count.js.map +1 -0
  15. package/dist/db.d.ts +341 -0
  16. package/dist/db.d.ts.map +1 -0
  17. package/dist/db.js +1016 -0
  18. package/dist/db.js.map +1 -0
  19. package/dist/exhume.d.ts +130 -0
  20. package/dist/exhume.d.ts.map +1 -0
  21. package/dist/exhume.js +145 -0
  22. package/dist/exhume.js.map +1 -0
  23. package/dist/face.d.ts +91 -0
  24. package/dist/face.d.ts.map +1 -0
  25. package/dist/face.js +69 -0
  26. package/dist/face.js.map +1 -0
  27. package/dist/fields.d.ts +187 -0
  28. package/dist/fields.d.ts.map +1 -0
  29. package/dist/fields.js +204 -0
  30. package/dist/fields.js.map +1 -0
  31. package/dist/index.d.ts +49 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +31 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lower.d.ts +34 -0
  36. package/dist/lower.d.ts.map +1 -0
  37. package/dist/lower.js +105 -0
  38. package/dist/lower.js.map +1 -0
  39. package/dist/marshal.d.ts +79 -0
  40. package/dist/marshal.d.ts.map +1 -0
  41. package/dist/marshal.js +167 -0
  42. package/dist/marshal.js.map +1 -0
  43. package/dist/native.d.ts +532 -0
  44. package/dist/native.d.ts.map +1 -0
  45. package/dist/native.js +64 -0
  46. package/dist/native.js.map +1 -0
  47. package/dist/query/atom.d.ts +285 -0
  48. package/dist/query/atom.d.ts.map +1 -0
  49. package/dist/query/atom.js +281 -0
  50. package/dist/query/atom.js.map +1 -0
  51. package/dist/query/lower.d.ts +145 -0
  52. package/dist/query/lower.d.ts.map +1 -0
  53. package/dist/query/lower.js +604 -0
  54. package/dist/query/lower.js.map +1 -0
  55. package/dist/query/predicate.d.ts +101 -0
  56. package/dist/query/predicate.d.ts.map +1 -0
  57. package/dist/query/predicate.js +85 -0
  58. package/dist/query/predicate.js.map +1 -0
  59. package/dist/query/run.d.ts +30 -0
  60. package/dist/query/run.d.ts.map +1 -0
  61. package/dist/query/run.js +94 -0
  62. package/dist/query/run.js.map +1 -0
  63. package/dist/query/scope.d.ts +168 -0
  64. package/dist/query/scope.d.ts.map +1 -0
  65. package/dist/query/scope.js +134 -0
  66. package/dist/query/scope.js.map +1 -0
  67. package/dist/query/select.d.ts +106 -0
  68. package/dist/query/select.d.ts.map +1 -0
  69. package/dist/query/select.js +69 -0
  70. package/dist/query/select.js.map +1 -0
  71. package/dist/relation.d.ts +120 -0
  72. package/dist/relation.d.ts.map +1 -0
  73. package/dist/relation.js +108 -0
  74. package/dist/relation.js.map +1 -0
  75. package/dist/schema.d.ts +50 -0
  76. package/dist/schema.d.ts.map +1 -0
  77. package/dist/schema.js +235 -0
  78. package/dist/schema.js.map +1 -0
  79. package/dist/spec.d.ts +218 -0
  80. package/dist/spec.d.ts.map +1 -0
  81. package/dist/spec.js +154 -0
  82. package/dist/spec.js.map +1 -0
  83. package/dist/statements.d.ts +91 -0
  84. package/dist/statements.d.ts.map +1 -0
  85. package/dist/statements.js +101 -0
  86. package/dist/statements.js.map +1 -0
  87. package/package.json +66 -0
  88. package/src/brand.ts +82 -0
  89. package/src/closed.ts +228 -0
  90. package/src/count.ts +117 -0
  91. package/src/db.ts +1519 -0
  92. package/src/exhume.ts +243 -0
  93. package/src/face.ts +161 -0
  94. package/src/fields.ts +385 -0
  95. package/src/index.ts +185 -0
  96. package/src/lower.ts +118 -0
  97. package/src/marshal.ts +220 -0
  98. package/src/native.ts +576 -0
  99. package/src/query/atom.ts +556 -0
  100. package/src/query/lower.ts +855 -0
  101. package/src/query/predicate.ts +195 -0
  102. package/src/query/run.ts +106 -0
  103. package/src/query/scope.ts +301 -0
  104. package/src/query/select.ts +140 -0
  105. package/src/relation.ts +252 -0
  106. package/src/schema.ts +297 -0
  107. package/src/spec.ts +325 -0
  108. package/src/statements.ts +148 -0
@@ -0,0 +1,285 @@
1
+ /**
2
+ * Query atoms and conditions (PRD-08) — the body vocabulary of a rule,
3
+ * mirroring the engine IR variant for variant
4
+ * (`bumbledb/crates/bumbledb/src/ir.rs`, the bijection target;
5
+ * `docs/architecture/20-query-ir.md` normative): `match` is the named-field
6
+ * atom (unmentioned fields ARE the wildcard — no wildcard value exists),
7
+ * `not` is negation-as-position (anti-join), `is`/`ne`/`lt`/`le`/`gt`/`ge`
8
+ * are the comparison roster, `covers` is the IR's `PointIn` predicate,
9
+ * `allen` the 13-bit-mask interval-pair comparison, `and`/`or` the input
10
+ * condition-tree grammar (distributed to DNF by the engine's validation),
11
+ * and `duration` the measure term. Nothing beyond the IR exists here: no
12
+ * convenience operator fakes an unsupported comparison.
13
+ */
14
+ import type { IntervalValue } from "#brand.ts";
15
+ import { phantom } from "#brand.ts";
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";
20
+ import type { AnyRelation, FieldsShape, Relation } from "#relation.ts";
21
+ /**
22
+ * One atom-binding position as runtime data: a scope term, a host literal
23
+ * (tagged at lowering by the FIELD's structural type — a point-typed
24
+ * literal at an interval field is the IR's membership typing rule), or an
25
+ * `oneOf` literal set (lowered to a fresh variable plus a disjunctive
26
+ * equality condition — the three-confinement law's rule-level OR, spelled
27
+ * for the caller as one binding).
28
+ */
29
+ type BindingTerm = {
30
+ readonly kind: "term";
31
+ readonly value: AnyTerm;
32
+ } | {
33
+ readonly kind: "literal";
34
+ readonly value: unknown;
35
+ } | {
36
+ readonly kind: "oneOf";
37
+ readonly values: readonly unknown[];
38
+ };
39
+ /** One resolved binding: the field's name, its description, and the term. */
40
+ interface BindingEntry {
41
+ readonly field: string;
42
+ readonly data: FieldData;
43
+ readonly term: BindingTerm;
44
+ }
45
+ /** Where an atom draws its facts: a stored relation or a scope predicate. */
46
+ type AtomSourceData = {
47
+ readonly kind: "relation";
48
+ 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
+ readonly bindings: readonly BindingEntry[];
63
+ readonly [phantom]?: P;
64
+ }
65
+ /** One comparison side as runtime data. */
66
+ type CmpTerm = {
67
+ readonly kind: "term";
68
+ readonly value: AnyTerm;
69
+ } | {
70
+ readonly kind: "literal";
71
+ readonly value: unknown;
72
+ } | {
73
+ readonly kind: "measure";
74
+ readonly over: AnyVar;
75
+ };
76
+ /** The `allen` mask position: a literal 13-bit mask or a mask parameter. */
77
+ type MaskData = {
78
+ readonly kind: "literal";
79
+ readonly mask: number;
80
+ } | {
81
+ readonly kind: "param";
82
+ readonly param: MaskParam<string>;
83
+ };
84
+ /** One comparison operator as runtime data (mirrors `ir::CmpOp`). */
85
+ type CmpOpData = {
86
+ readonly kind: "eq";
87
+ } | {
88
+ readonly kind: "ne";
89
+ } | {
90
+ readonly kind: "lt";
91
+ } | {
92
+ readonly kind: "le";
93
+ } | {
94
+ readonly kind: "gt";
95
+ } | {
96
+ readonly kind: "ge";
97
+ } | {
98
+ readonly kind: "allen";
99
+ readonly mask: MaskData;
100
+ } | {
101
+ readonly kind: "pointIn";
102
+ };
103
+ /** One comparison condition value. */
104
+ interface ComparisonItem<P extends ParamsRecord> {
105
+ readonly item: "cmp";
106
+ readonly op: CmpOpData;
107
+ readonly lhs: CmpTerm;
108
+ readonly rhs: CmpTerm;
109
+ readonly [phantom]?: P;
110
+ }
111
+ /**
112
+ * One condition-tree node (`ir::ConditionTree`): any boolean combination
113
+ * of comparisons — the engine's validation distributes nested OR to DNF
114
+ * rules; the surface admits exactly what the IR admits.
115
+ */
116
+ interface ConditionTreeItem<P extends ParamsRecord> {
117
+ readonly item: "tree";
118
+ readonly op: "and" | "or";
119
+ readonly children: readonly AnyCondition[];
120
+ readonly [phantom]?: P;
121
+ }
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
+ /**
127
+ * The measure of an interval-typed variable (`ir::Term::Measure`, surface
128
+ * `Duration`): `|[s, e)| = e − s`, u64 — legal as one side of an order
129
+ * comparison, as a projected select entry, and as the input of
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).
134
+ */
135
+ interface Duration {
136
+ readonly measure: AnyVar;
137
+ readonly [phantom]?: bigint;
138
+ }
139
+ /**
140
+ * What a binding position of value type `V` accepts: a branded literal, a
141
+ * disjunctive `oneOf` literal set, a `Var`/`Param`/`ParamSet` of the same
142
+ * brand — and, when the field is interval-typed, a point-typed term (the
143
+ * IR's membership typing rule: an element-typed term at an interval field
144
+ * is point membership; an interval-typed term is value equality).
145
+ */
146
+ type TermInput<V> = V | OneOf<V> | Var<V> | Param<string, V> | ParamSet<string, V> | (V extends IntervalValue ? PointTermInput : never);
147
+ /** The point-typed terms an interval field position additionally accepts. */
148
+ type PointTermInput = bigint | Var<bigint> | Param<string, bigint> | ParamSet<string, bigint>;
149
+ /**
150
+ * The `match` bindings record: per field, a term of that field's brand;
151
+ * unmentioned fields are wildcards (absence IS the wildcard — the IR has
152
+ * no wildcard variant to spell).
153
+ */
154
+ type MatchInput<Fields extends FieldsShape> = {
155
+ readonly [K in keyof Fields]?: TermInput<FieldValue<Fields[K]>>;
156
+ };
157
+ /** The params object a bindings record contributes (used by `match`). */
158
+ type BindingsParams<B> = ParamsShape<TermContribution<B[keyof B]>>;
159
+ /**
160
+ * Resolves a bindings record against an ordered field roster (shared by
161
+ * relation atoms here and predicate atoms in `#query/predicate.ts`), in
162
+ * the record's written order.
163
+ */
164
+ declare function resolveBindings(context: string, fields: ReadonlyArray<{
165
+ readonly name: string;
166
+ readonly field: FieldData;
167
+ }>, bindings: Readonly<Record<string, unknown>>): readonly BindingEntry[];
168
+ /**
169
+ * The named-field atom — the semantic twin of `query!`'s `Node(id: c)`:
170
+ * fields bind vars, params, branded literals, `oneOf` sets, or (interval
171
+ * fields) point terms; unmentioned fields are wildcards; a zero-binding
172
+ * atom is a nonemptiness gate on the relation (IR-legal, so writable).
173
+ */
174
+ declare function match<Name extends string, Fields extends FieldsShape, const B extends MatchInput<Fields>>(relation: Relation<Name, Fields>, bindings: B): MatchAtom<BindingsParams<B>>;
175
+ /**
176
+ * Negation — anti-join over sets, no null trick: a binding satisfies the
177
+ * negated atom iff NO fact matches it. Safety (every negated var bound
178
+ * positively) is validated at `query()` construction with an error naming
179
+ * the variable; the negated atom binds nothing, only rejects. An `oneOf`
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).
185
+ */
186
+ declare function not<P extends ParamsRecord>(atom: MatchAtom<P>): MatchAtom<P>;
187
+ /**
188
+ * The equality atom (`ir::CmpOp::Eq`) — for binding a var to a param or
189
+ * literal where punning inside `match` doesn't apply, and for var-to-var
190
+ * unification. Prefer direct placement (`match(Account, { kind:
191
+ * Kind.Savings })`); `is` exists for the var-to-param case. `ParamSet` is
192
+ * legal here and under no other operator (the IR's `Eq`-only set rule).
193
+ */
194
+ declare function is<V, const R extends Var<V> | Param<string, V> | ParamSet<string, V> | V>(left: Var<V>, right: R): ComparisonItem<ParamsShape<TermContribution<R>>>;
195
+ /** Typed disequality (`ir::CmpOp::Ne`). "Not in set" has no operator — write a negated atom. */
196
+ declare function ne<V, const R extends Var<V> | Param<string, V> | V>(left: Var<V>, right: R): ComparisonItem<ParamsShape<TermContribution<R>>>;
197
+ /**
198
+ * One side of an order comparison: a u64/i64-typed var or param, a bigint
199
+ * literal, or the measure (`duration(v)`) — order operators are legal for
200
+ * the orderable types only, never intervals/bytes/strings/bools (the IR's
201
+ * comparison rules; each refusal is the engine's own typed diagnostic).
202
+ */
203
+ type OrderInput = Var<bigint> | Param<string, bigint> | bigint | Duration;
204
+ /** Strict less-than (`ir::CmpOp::Lt`). */
205
+ declare function lt<const L extends OrderInput, const R extends OrderInput>(left: L, right: R): ComparisonItem<ParamsShape<TermContribution<L> | TermContribution<R>>>;
206
+ /** Less-or-equal (`ir::CmpOp::Le`). */
207
+ declare function le<const L extends OrderInput, const R extends OrderInput>(left: L, right: R): ComparisonItem<ParamsShape<TermContribution<L> | TermContribution<R>>>;
208
+ /** Strict greater-than (`ir::CmpOp::Gt`). */
209
+ declare function gt<const L extends OrderInput, const R extends OrderInput>(left: L, right: R): ComparisonItem<ParamsShape<TermContribution<L> | TermContribution<R>>>;
210
+ /** Greater-or-equal (`ir::CmpOp::Ge`). */
211
+ declare function ge<const L extends OrderInput, const R extends OrderInput>(left: L, right: R): ComparisonItem<ParamsShape<TermContribution<L> | TermContribution<R>>>;
212
+ /** An interval-typed comparison side: a var, a param, or a `span` literal. */
213
+ type IntervalInput = Var<IntervalValue> | Param<string, IntervalValue> | IntervalValue;
214
+ /** A point-typed comparison side. */
215
+ type PointInput = Var<bigint> | Param<string, bigint> | bigint;
216
+ /**
217
+ * Point membership as a predicate (`ir::CmpOp::PointIn`): `covers(iv, t)`
218
+ * holds iff `iv.start ≤ t < iv.end` — the predicate form of the membership
219
+ * typing rule, for terms already bound elsewhere. Interval ⊇ interval is
220
+ * NOT this operator; that predicate is `allen(a, ALLEN.covers, b)`. The IR
221
+ * orders the operands interval-left, point-right; so does this surface.
222
+ */
223
+ declare function covers<const I extends IntervalInput, const T extends PointInput>(interval: I, point: T): ComparisonItem<ParamsShape<TermContribution<I> | TermContribution<T>>>;
224
+ /**
225
+ * The Allen coordinate system's named constants — the 13 basics in the
226
+ * engine's palindromic bit order (bit i = basic i:
227
+ * `bumbledb/crates/bumbledb/src/allen.rs`, a specified representation)
228
+ * plus the workload composites, values identical to the engine's. Compose
229
+ * with `|`: `ALLEN.before | ALLEN.meets`.
230
+ */
231
+ declare const ALLEN: Readonly<{
232
+ before: number;
233
+ meets: number;
234
+ overlaps: number;
235
+ starts: number;
236
+ during: number;
237
+ finishes: number;
238
+ equals: number;
239
+ finishedBy: number;
240
+ contains: number;
241
+ startedBy: number;
242
+ overlappedBy: number;
243
+ metBy: number;
244
+ after: number;
245
+ /** The point-sets share a point (9 bits; under half-open intervals *meets* shares none). */
246
+ intersects: number;
247
+ /** Point-set ⊇: equals ∪ contains ∪ started-by ∪ finished-by. */
248
+ covers: number;
249
+ /** Point-set ⊆ — `covers`' converse: equals ∪ during ∪ starts ∪ finishes. */
250
+ coveredBy: number;
251
+ /** The point-sets share no point: before ∪ meets ∪ met-by ∪ after. */
252
+ disjoint: number;
253
+ }>;
254
+ /**
255
+ * THE interval-pair comparison (`ir::CmpOp::Allen`): two interval terms of
256
+ * one element type, satisfied iff the pair's classification is in the
257
+ * 13-bit mask — a literal built from the `ALLEN` constants, or a mask
258
+ * parameter (`$.allenParam`). Vacuous masks (empty/full) are the engine's
259
+ * two distinct typed rejections; nothing is pre-judged here beyond the
260
+ * representable bit range.
261
+ */
262
+ declare function allen<const A extends IntervalInput, const M extends number | MaskParam<string>, const B extends IntervalInput>(left: A, mask: M, right: B): ComparisonItem<ParamsShape<TermContribution<A> | TermContribution<M> | TermContribution<B>>>;
263
+ /**
264
+ * Conjunction node of the input condition grammar (`ConditionTree::And`).
265
+ * The rule's condition list is already a conjunction — `and` exists for
266
+ * nesting under `or`, and the empty combination keeps the IR's algebraic
267
+ * reading (`And([])` is true).
268
+ */
269
+ declare function and<const C extends readonly AnyCondition[]>(...children: C): ConditionTreeItem<ParamsShape<ItemParams<C[number]>>>;
270
+ /**
271
+ * Disjunction node of the input condition grammar (`ConditionTree::Or`) —
272
+ * the one place the surface admits a nested OR; validation distributes it
273
+ * to DNF rules engine-side (OR is data or it is nothing). `Or([])` keeps
274
+ * its algebraic reading (false: the rule denotes nothing).
275
+ */
276
+ declare function or<const C extends readonly AnyCondition[]>(...children: C): ConditionTreeItem<ParamsShape<ItemParams<C[number]>>>;
277
+ /**
278
+ * The measure term — surface `Duration`, IR `Measure`: the point-set
279
+ * cardinality `end − start` of an interval-typed variable, u64. See
280
+ * {@link Duration} for the legal positions.
281
+ */
282
+ declare function duration<IV extends IntervalValue>(over: Var<IV>): Duration;
283
+ export type { AnyBodyItem, AnyCondition, AtomSourceData, BindingEntry, BindingsParams, BindingTerm, CmpOpData, CmpTerm, ComparisonItem, ConditionTreeItem, Duration, IntervalInput, MaskData, MatchAtom, MatchInput, OrderInput, PointInput, PointTermInput, TermInput };
284
+ export { ALLEN, allen, and, covers, duration, ge, gt, is, le, lt, match, ne, not, or, resolveBindings };
285
+ //# sourceMappingURL=atom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/query/atom.ts"],"names":[],"mappings":"AAAA;;;;;;;;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QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,CAAA;AACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Query atoms and conditions (PRD-08) — the body vocabulary of a rule,
3
+ * mirroring the engine IR variant for variant
4
+ * (`bumbledb/crates/bumbledb/src/ir.rs`, the bijection target;
5
+ * `docs/architecture/20-query-ir.md` normative): `match` is the named-field
6
+ * atom (unmentioned fields ARE the wildcard — no wildcard value exists),
7
+ * `not` is negation-as-position (anti-join), `is`/`ne`/`lt`/`le`/`gt`/`ge`
8
+ * are the comparison roster, `covers` is the IR's `PointIn` predicate,
9
+ * `allen` the 13-bit-mask interval-pair comparison, `and`/`or` the input
10
+ * condition-tree grammar (distributed to DNF by the engine's validation),
11
+ * and `duration` the measure term. Nothing beyond the IR exists here: no
12
+ * convenience operator fakes an unsupported comparison.
13
+ */
14
+ import * as errors from "@superbuilders/errors";
15
+ import { phantom } from "#brand.ts";
16
+ import { isTerm, term } from "#query/scope.ts";
17
+ /** Narrows an `oneOf` literal set (the detection rule `where()` uses). */
18
+ function isOneOf(value) {
19
+ return typeof value === "object" && value !== null && "literals" in value && Array.isArray(value.literals);
20
+ }
21
+ /** Resolves one binding value to its runtime term. */
22
+ function bindingTermOf(context, value) {
23
+ if (isTerm(value)) {
24
+ if (value[term] === "maskParam") {
25
+ throw errors.new(`${context}: an Allen-mask param is not a field-typed value — masks live in allen() conditions only`);
26
+ }
27
+ return Object.freeze({ kind: "term", value });
28
+ }
29
+ if (isOneOf(value)) {
30
+ return Object.freeze({ kind: "oneOf", values: Object.freeze([...value.literals]) });
31
+ }
32
+ return Object.freeze({ kind: "literal", value });
33
+ }
34
+ /**
35
+ * Resolves a bindings record against an ordered field roster (shared by
36
+ * relation atoms here and predicate atoms in `#query/predicate.ts`), in
37
+ * the record's written order.
38
+ */
39
+ function resolveBindings(context, fields, bindings) {
40
+ const entries = [];
41
+ for (const [fieldName, value] of Object.entries(bindings)) {
42
+ if (value === undefined) {
43
+ continue;
44
+ }
45
+ const declared = fields.find(function byName(candidate) {
46
+ return candidate.name === fieldName;
47
+ });
48
+ if (declared === undefined) {
49
+ throw errors.new(`${context} has no field ${fieldName}`);
50
+ }
51
+ entries.push(Object.freeze({
52
+ field: fieldName,
53
+ data: declared.field,
54
+ term: bindingTermOf(`${context}.${fieldName}`, value)
55
+ }));
56
+ }
57
+ return Object.freeze(entries);
58
+ }
59
+ /**
60
+ * The named-field atom — the semantic twin of `query!`'s `Node(id: c)`:
61
+ * fields bind vars, params, branded literals, `oneOf` sets, or (interval
62
+ * fields) point terms; unmentioned fields are wildcards; a zero-binding
63
+ * atom is a nonemptiness gate on the relation (IR-legal, so writable).
64
+ */
65
+ function match(relation, bindings) {
66
+ return Object.freeze({
67
+ item: "atom",
68
+ negated: false,
69
+ source: Object.freeze({ kind: "relation", relation }),
70
+ bindings: resolveBindings(`relation ${relation.name}`, relation.data.fields, Object.fromEntries(Object.entries(bindings)))
71
+ });
72
+ }
73
+ /**
74
+ * Negation — anti-join over sets, no null trick: a binding satisfies the
75
+ * negated atom iff NO fact matches it. Safety (every negated var bound
76
+ * positively) is validated at `query()` construction with an error naming
77
+ * the variable; the negated atom binds nothing, only rejects. An `oneOf`
78
+ * binding is refused HERE, at construction: it lowers to a synthetic
79
+ * variable bound only inside the atom plus a rule-level OR — which is
80
+ * exactly the shape the safety rule rejects, and semantically wrong for
81
+ * negation anyway (¬∃(f = a ∨ f = b) is a CONJUNCTION of negated atoms,
82
+ * ¬∃(f = a) ∧ ¬∃(f = b), never one negated atom's OR).
83
+ */
84
+ function not(atom) {
85
+ if (atom.item !== "atom" || atom.negated) {
86
+ throw errors.new("negation is a position in the rule, not an operator — not() takes one positive atom");
87
+ }
88
+ for (const binding of atom.bindings) {
89
+ if (binding.term.kind === "oneOf") {
90
+ const source = atom.source.kind === "relation" ? atom.source.relation.name : `predicate ${atom.source.pred.name}`;
91
+ throw errors.new(`negated ${source} atom binds ${binding.field} with oneOf(...) — ¬∃(${binding.field} = a ∨ ${binding.field} = b) means ¬∃(${binding.field} = a) ∧ ¬∃(${binding.field} = b): write one not(match(...)) per literal, or bind a paramSet`);
92
+ }
93
+ }
94
+ return Object.freeze({
95
+ item: "atom",
96
+ negated: true,
97
+ source: atom.source,
98
+ bindings: atom.bindings
99
+ });
100
+ }
101
+ /** Builds one comparison value. */
102
+ function comparison(op, lhs, rhs) {
103
+ return Object.freeze({ item: "cmp", op: Object.freeze(op), lhs, rhs });
104
+ }
105
+ /** Narrows a `duration()` value. */
106
+ function isDuration(value) {
107
+ return typeof value === "object" && value !== null && "measure" in value && !isTerm(value);
108
+ }
109
+ /** Resolves one comparison side to its runtime term. */
110
+ function cmpTermOf(value) {
111
+ if (isTerm(value)) {
112
+ return Object.freeze({ kind: "term", value });
113
+ }
114
+ if (isDuration(value)) {
115
+ return Object.freeze({ kind: "measure", over: value.measure });
116
+ }
117
+ return Object.freeze({ kind: "literal", value });
118
+ }
119
+ /**
120
+ * Rejects a comparison with no term side: it is constant-valued, the
121
+ * engine's own validation refuses it, and the lowering has no field
122
+ * position to type the literals by — fail here with the same verdict.
123
+ */
124
+ function assertTermSide(op, lhs, rhs) {
125
+ if (lhs.kind === "literal" && rhs.kind === "literal") {
126
+ throw errors.new(`${op}: a comparison without a variable or parameter side is constant-valued — write the query you mean`);
127
+ }
128
+ }
129
+ /**
130
+ * The equality atom (`ir::CmpOp::Eq`) — for binding a var to a param or
131
+ * literal where punning inside `match` doesn't apply, and for var-to-var
132
+ * unification. Prefer direct placement (`match(Account, { kind:
133
+ * Kind.Savings })`); `is` exists for the var-to-param case. `ParamSet` is
134
+ * legal here and under no other operator (the IR's `Eq`-only set rule).
135
+ */
136
+ function is(left, right) {
137
+ return comparison(Object.freeze({ kind: "eq" }), cmpTermOf(left), cmpTermOf(right));
138
+ }
139
+ /** Typed disequality (`ir::CmpOp::Ne`). "Not in set" has no operator — write a negated atom. */
140
+ function ne(left, right) {
141
+ return comparison(Object.freeze({ kind: "ne" }), cmpTermOf(left), cmpTermOf(right));
142
+ }
143
+ /** The shared order-comparison constructor. */
144
+ function order(op, left, right) {
145
+ const lhs = cmpTermOf(left);
146
+ const rhs = cmpTermOf(right);
147
+ assertTermSide(op, lhs, rhs);
148
+ return comparison(Object.freeze({ kind: op }), lhs, rhs);
149
+ }
150
+ /** Strict less-than (`ir::CmpOp::Lt`). */
151
+ function lt(left, right) {
152
+ return order("lt", left, right);
153
+ }
154
+ /** Less-or-equal (`ir::CmpOp::Le`). */
155
+ function le(left, right) {
156
+ return order("le", left, right);
157
+ }
158
+ /** Strict greater-than (`ir::CmpOp::Gt`). */
159
+ function gt(left, right) {
160
+ return order("gt", left, right);
161
+ }
162
+ /** Greater-or-equal (`ir::CmpOp::Ge`). */
163
+ function ge(left, right) {
164
+ return order("ge", left, right);
165
+ }
166
+ /**
167
+ * Point membership as a predicate (`ir::CmpOp::PointIn`): `covers(iv, t)`
168
+ * holds iff `iv.start ≤ t < iv.end` — the predicate form of the membership
169
+ * typing rule, for terms already bound elsewhere. Interval ⊇ interval is
170
+ * NOT this operator; that predicate is `allen(a, ALLEN.covers, b)`. The IR
171
+ * orders the operands interval-left, point-right; so does this surface.
172
+ */
173
+ function covers(interval, point) {
174
+ const lhs = cmpTermOf(interval);
175
+ const rhs = cmpTermOf(point);
176
+ assertTermSide("covers", lhs, rhs);
177
+ return comparison(Object.freeze({ kind: "pointIn" }), lhs, rhs);
178
+ }
179
+ /**
180
+ * The 13-bit mask range: bits above the low 13 are unrepresentable in the
181
+ * engine's `AllenMask` (`bumbledb/crates/bumbledb/src/allen.rs`:
182
+ * `AllenMask::new` refuses them) — the check here is the same boundary,
183
+ * moved to construction where the message can name the constants.
184
+ */
185
+ const ALLEN_ALL_BITS = (1 << 13) - 1;
186
+ /**
187
+ * The Allen coordinate system's named constants — the 13 basics in the
188
+ * engine's palindromic bit order (bit i = basic i:
189
+ * `bumbledb/crates/bumbledb/src/allen.rs`, a specified representation)
190
+ * plus the workload composites, values identical to the engine's. Compose
191
+ * with `|`: `ALLEN.before | ALLEN.meets`.
192
+ */
193
+ const ALLEN = Object.freeze({
194
+ before: 1 << 0,
195
+ meets: 1 << 1,
196
+ overlaps: 1 << 2,
197
+ starts: 1 << 3,
198
+ during: 1 << 4,
199
+ finishes: 1 << 5,
200
+ equals: 1 << 6,
201
+ finishedBy: 1 << 7,
202
+ contains: 1 << 8,
203
+ startedBy: 1 << 9,
204
+ overlappedBy: 1 << 10,
205
+ metBy: 1 << 11,
206
+ after: 1 << 12,
207
+ /** The point-sets share a point (9 bits; under half-open intervals *meets* shares none). */
208
+ intersects: (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10),
209
+ /** Point-set ⊇: equals ∪ contains ∪ started-by ∪ finished-by. */
210
+ covers: (1 << 6) | (1 << 8) | (1 << 9) | (1 << 7),
211
+ /** Point-set ⊆ — `covers`' converse: equals ∪ during ∪ starts ∪ finishes. */
212
+ coveredBy: (1 << 6) | (1 << 4) | (1 << 3) | (1 << 5),
213
+ /** The point-sets share no point: before ∪ meets ∪ met-by ∪ after. */
214
+ disjoint: (1 << 0) | (1 << 1) | (1 << 11) | (1 << 12)
215
+ });
216
+ /**
217
+ * THE interval-pair comparison (`ir::CmpOp::Allen`): two interval terms of
218
+ * one element type, satisfied iff the pair's classification is in the
219
+ * 13-bit mask — a literal built from the `ALLEN` constants, or a mask
220
+ * parameter (`$.allenParam`). Vacuous masks (empty/full) are the engine's
221
+ * two distinct typed rejections; nothing is pre-judged here beyond the
222
+ * representable bit range.
223
+ */
224
+ function allen(left, mask, right) {
225
+ const lhs = cmpTermOf(left);
226
+ const rhs = cmpTermOf(right);
227
+ assertTermSide("allen", lhs, rhs);
228
+ const maskValue = mask;
229
+ if (typeof maskValue === "number") {
230
+ if (!Number.isInteger(maskValue) || maskValue < 0 || maskValue > ALLEN_ALL_BITS) {
231
+ throw errors.new(`allen mask ${maskValue} is not a 13-bit mask — build masks from the ALLEN constants (bumbledb allen.rs: bits above the low 13 are unrepresentable)`);
232
+ }
233
+ return comparison(Object.freeze({
234
+ kind: "allen",
235
+ mask: Object.freeze({ kind: "literal", mask: maskValue })
236
+ }), lhs, rhs);
237
+ }
238
+ return comparison(Object.freeze({
239
+ kind: "allen",
240
+ mask: Object.freeze({ kind: "param", param: maskValue })
241
+ }), lhs, rhs);
242
+ }
243
+ /**
244
+ * Conjunction node of the input condition grammar (`ConditionTree::And`).
245
+ * The rule's condition list is already a conjunction — `and` exists for
246
+ * nesting under `or`, and the empty combination keeps the IR's algebraic
247
+ * reading (`And([])` is true).
248
+ */
249
+ function and(...children) {
250
+ return Object.freeze({
251
+ item: "tree",
252
+ op: "and",
253
+ children: Object.freeze([...children])
254
+ });
255
+ }
256
+ /**
257
+ * Disjunction node of the input condition grammar (`ConditionTree::Or`) —
258
+ * the one place the surface admits a nested OR; validation distributes it
259
+ * to DNF rules engine-side (OR is data or it is nothing). `Or([])` keeps
260
+ * its algebraic reading (false: the rule denotes nothing).
261
+ */
262
+ function or(...children) {
263
+ return Object.freeze({
264
+ item: "tree",
265
+ op: "or",
266
+ children: Object.freeze([...children])
267
+ });
268
+ }
269
+ /**
270
+ * The measure term — surface `Duration`, IR `Measure`: the point-set
271
+ * cardinality `end − start` of an interval-typed variable, u64. See
272
+ * {@link Duration} for the legal positions.
273
+ */
274
+ function duration(over) {
275
+ if (over.data.type.kind !== "interval") {
276
+ throw errors.new(`duration(${over.relation}.${over.field}): the measure is defined over interval-typed variables only`);
277
+ }
278
+ return Object.freeze({ measure: over });
279
+ }
280
+ export { ALLEN, allen, and, covers, duration, ge, gt, is, le, lt, match, ne, not, or, resolveBindings };
281
+ //# sourceMappingURL=atom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.js","sourceRoot":"","sources":["../../src/query/atom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAgBnC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAsI9C,0EAA0E;AAC1E,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAC3G,CAAC;AAED,sDAAsD;AACtD,SAAS,aAAa,CAAC,OAAe,EAAE,KAAc;IACrD,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,WAAW,EAAE,CAAC;YACjC,MAAM,MAAM,CAAC,GAAG,CACf,GAAG,OAAO,0FAA0F,CACpG,CAAA;QACF,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,CAAC,CAAA;IACvD,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAA;IAC7F,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAkB,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAS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