@bjornpagen/bumbledb 0.14.0 → 0.17.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 +58 -62
- package/README.md +82 -56
- package/dist/capacity.d.ts +24 -136
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js +18 -40
- package/dist/capacity.js.map +1 -1
- package/dist/closed.d.ts +0 -156
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +0 -104
- package/dist/closed.js.map +1 -1
- package/dist/db.d.ts +93 -290
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +713 -556
- package/dist/db.js.map +1 -1
- package/dist/face.d.ts +0 -133
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +0 -33
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +1 -145
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +2 -91
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +13 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -20
- package/dist/index.js.map +1 -1
- package/dist/law.d.ts +111 -93
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +23 -27
- package/dist/law.js.map +1 -1
- package/dist/lower.d.ts +9 -35
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +8 -53
- package/dist/lower.js.map +1 -1
- package/dist/marshal.d.ts +0 -65
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +0 -72
- package/dist/marshal.js.map +1 -1
- package/dist/native.d.ts +97 -390
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +39 -61
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +10 -276
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +1 -96
- package/dist/query/atom.js.map +1 -1
- package/dist/query/find.d.ts +10 -76
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +0 -30
- package/dist/query/find.js.map +1 -1
- package/dist/query/lower.d.ts +64 -146
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +19 -256
- package/dist/query/lower.js.map +1 -1
- package/dist/query/parse-ir.d.ts +0 -7
- package/dist/query/parse-ir.d.ts.map +1 -1
- package/dist/query/parse-ir.js +1 -13
- package/dist/query/parse-ir.js.map +1 -1
- package/dist/query/run.d.ts +0 -36
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +0 -44
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +24 -180
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +2 -66
- package/dist/query/scope.js.map +1 -1
- package/dist/relation.d.ts +2 -50
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +2 -37
- package/dist/relation.js.map +1 -1
- package/dist/schema.d.ts +13 -63
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +118 -92
- package/dist/schema.js.map +1 -1
- package/dist/spec.d.ts +1 -140
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +1 -68
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +6 -137
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +16 -119
- package/dist/statements.js.map +1 -1
- package/package.json +3 -3
- package/src/capacity.ts +26 -140
- package/src/closed.ts +5 -206
- package/src/db.ts +997 -854
- package/src/face.ts +0 -142
- package/src/fields.ts +4 -172
- package/src/index.ts +32 -35
- package/src/law.ts +201 -129
- package/src/lower.ts +8 -53
- package/src/marshal.ts +1 -85
- package/src/native.ts +192 -413
- package/src/query/atom.ts +26 -313
- package/src/query/find.ts +24 -110
- package/src/query/lower.ts +132 -377
- package/src/query/parse-ir.ts +1 -14
- package/src/query/run.ts +0 -45
- package/src/query/scope.ts +25 -186
- package/src/relation.ts +2 -66
- package/src/schema.ts +143 -122
- package/src/spec.ts +1 -160
- package/src/statements.ts +22 -174
- package/dist/exhume.d.ts +0 -143
- package/dist/exhume.d.ts.map +0 -1
- package/dist/exhume.js +0 -166
- package/dist/exhume.js.map +0 -1
- package/src/exhume.ts +0 -267
package/dist/query/atom.js
CHANGED
|
@@ -1,118 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Atoms and conditions, REFERENCE-IDENTITY edition — the body vocabulary of
|
|
3
|
-
* a rule, 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). A `match` binding record
|
|
6
|
-
* binds fields to VARIABLES (minted by {@link v}), params, ∈-set params, or
|
|
7
|
-
* bare structural literals — a closed-reference field's literal is its
|
|
8
|
-
* handle NAME, and a plain ARRAY of names there is membership
|
|
9
|
-
* (unmentioned fields ARE the wildcard — no wildcard value exists);
|
|
10
|
-
* `not(Rel, {...})` is negation-as-position (anti-join); `eq`/`ne` and the
|
|
11
|
-
* order roster, `pointIn` (the one spelling of `ir::CmpOp::PointIn`,
|
|
12
|
-
* always lowered interval-left), `allen` (the 13-bit mask pair
|
|
13
|
-
* comparison), and `and`/`or` (the input condition-tree grammar) complete
|
|
14
|
-
* the roster. Nothing beyond the IR exists here — and the walls the engine
|
|
15
|
-
* enforces at prepare are TYPES first: a variable joins only class-equal
|
|
16
|
-
* fields, judged at every binding position against the var's MINT slot
|
|
17
|
-
* ({@link MintSlotOf}); because {@link JoinOk} is an equality, that ALONE
|
|
18
|
-
* makes every cross-binding join transitively class-equal (the env/sibling
|
|
19
|
-
* checks the name-keyed edition needed are gone). An interval-typed var
|
|
20
|
-
* under a non-`pointIn` comparison is unwritable. BOUNDNESS (a negated
|
|
21
|
-
* atom's variables must be positively bound) is the one check types cannot
|
|
22
|
-
* carry — object identity is invisible to TS — so it is a construction-time
|
|
23
|
-
* wall only.
|
|
24
|
-
*
|
|
25
|
-
* This module also owns the plain runtime DATA a built rule is made of
|
|
26
|
-
* (`RuleData`/`InteriorData`/`RecData` and friends): frozen values the
|
|
27
|
-
* lowering walks — pure data (variable references included), so lowering
|
|
28
|
-
* stays a pure, stable function of the query value.
|
|
29
|
-
*/
|
|
30
1
|
import * as errors from "@superbuilders/errors";
|
|
31
2
|
import { isTerm, term } from "#query/scope.ts";
|
|
32
|
-
/** Builds one comparison value. */
|
|
33
3
|
function comparison(op, lhs, rhs, mask) {
|
|
34
4
|
return Object.freeze({ cond: "cmp", op, lhs, rhs, mask });
|
|
35
5
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Whether a comparison side is a VARIABLE side in the engine's sense — a
|
|
38
|
-
* bound variable or the measure. A param is a constant at execution, so a
|
|
39
|
-
* comparison whose every side is a param or literal is constant-valued:
|
|
40
|
-
* the engine's `ConstantComparison` conviction
|
|
41
|
-
* (`bumbledb/crates/bumbledb/src/ir/validate/context.rs`,
|
|
42
|
-
* `comparison_shape`'s last arm).
|
|
43
|
-
*/
|
|
44
6
|
function isVariableSide(value) {
|
|
45
|
-
return isTerm(value) &&
|
|
7
|
+
return isTerm(value) && value[term] === "var";
|
|
46
8
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Rejects a comparison with no variable side: it is constant-valued —
|
|
49
|
-
* params included, a param is a constant the moment it binds — the
|
|
50
|
-
* engine's own validation refuses it (`ConstantComparison`), and the
|
|
51
|
-
* lowering has no anchored position to type the literals by — fail here
|
|
52
|
-
* with the same verdict.
|
|
53
|
-
*/
|
|
54
9
|
function assertTermSide(op, lhs, rhs) {
|
|
55
10
|
if (!isVariableSide(lhs) && !isVariableSide(rhs)) {
|
|
56
11
|
throw errors.new(`${op}: a comparison without a variable side is constant-valued (a parameter is a constant at execution) — write the query you mean`);
|
|
57
12
|
}
|
|
58
13
|
}
|
|
59
|
-
/**
|
|
60
|
-
* The equality comparison (`ir::CmpOp::Eq`) — a bound variable against a
|
|
61
|
-
* variable (var-to-var unification, class-equal by the join judgment), a
|
|
62
|
-
* param (typed by the variable), an ∈-set param (`Eq`-only), or a bare
|
|
63
|
-
* literal of the variable's own value type. Prefer direct placement in
|
|
64
|
-
* `match` where punning applies.
|
|
65
|
-
*/
|
|
66
14
|
function eq(left, right) {
|
|
67
15
|
return comparison("eq", left, right, undefined);
|
|
68
16
|
}
|
|
69
|
-
/** Typed disequality (`ir::CmpOp::Ne`). "Not in set" has no operator — write a negated atom. */
|
|
70
17
|
function ne(left, right) {
|
|
71
18
|
return comparison("ne", left, right, undefined);
|
|
72
19
|
}
|
|
73
|
-
/** The shared order-comparison constructor. */
|
|
74
20
|
function order(op, left, right) {
|
|
75
21
|
assertTermSide(op, left, right);
|
|
76
22
|
return comparison(op, left, right, undefined);
|
|
77
23
|
}
|
|
78
|
-
/** Strict less-than (`ir::CmpOp::Lt`) — orderable sides only (bool included: `false < true`, R3), never intervals/bytes/strings. */
|
|
79
24
|
function lt(left, right) {
|
|
80
25
|
return order("lt", left, right);
|
|
81
26
|
}
|
|
82
|
-
/** Less-or-equal (`ir::CmpOp::Le`). */
|
|
83
27
|
function le(left, right) {
|
|
84
28
|
return order("le", left, right);
|
|
85
29
|
}
|
|
86
|
-
/** Strict greater-than (`ir::CmpOp::Gt`). */
|
|
87
30
|
function gt(left, right) {
|
|
88
31
|
return order("gt", left, right);
|
|
89
32
|
}
|
|
90
|
-
/** Greater-or-equal (`ir::CmpOp::Ge`). */
|
|
91
33
|
function ge(left, right) {
|
|
92
34
|
return order("ge", left, right);
|
|
93
35
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Point membership as a predicate (`ir::CmpOp::PointIn`) — THE one
|
|
96
|
-
* spelling: `pointIn(t, w)` holds iff `w.start ≤ t < w.end`. The IR
|
|
97
|
-
* orders the operands interval-left, point-right; the value stores them
|
|
98
|
-
* that way whatever the surface argument order. Interval ⊇ interval is NOT
|
|
99
|
-
* this operator; that predicate is `allen(a, ALLEN.covers, b)`.
|
|
100
|
-
*/
|
|
101
36
|
function pointIn(point, interval) {
|
|
102
37
|
assertTermSide("pointIn", point, interval);
|
|
103
38
|
return comparison("pointIn", interval, point, undefined);
|
|
104
39
|
}
|
|
105
|
-
/**
|
|
106
|
-
* The 13-bit mask range: bits above the low 13 are unrepresentable in the
|
|
107
|
-
* engine's `AllenMask` (`bumbledb/crates/bumbledb/src/allen.rs`:
|
|
108
|
-
* `AllenMask::new` refuses them).
|
|
109
|
-
*/
|
|
110
40
|
const ALLEN_ALL_BITS = (1 << 13) - 1;
|
|
111
|
-
/**
|
|
112
|
-
* The Allen coordinate system's named constants — the 13 basics in the
|
|
113
|
-
* engine's palindromic bit order plus the workload composites, values
|
|
114
|
-
* identical to the engine's. Compose with `|`: `ALLEN.before | ALLEN.meets`.
|
|
115
|
-
*/
|
|
116
41
|
const ALLEN = Object.freeze({
|
|
117
42
|
before: 1 << 0,
|
|
118
43
|
meets: 1 << 1,
|
|
@@ -127,20 +52,11 @@ const ALLEN = Object.freeze({
|
|
|
127
52
|
overlappedBy: 1 << 10,
|
|
128
53
|
metBy: 1 << 11,
|
|
129
54
|
after: 1 << 12,
|
|
130
|
-
/** The point-sets share a point (9 bits; under half-open intervals *meets* shares none). */
|
|
131
55
|
intersects: (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10),
|
|
132
|
-
/** Point-set ⊇: equals ∪ contains ∪ started-by ∪ finished-by. */
|
|
133
56
|
covers: (1 << 6) | (1 << 8) | (1 << 9) | (1 << 7),
|
|
134
|
-
/** Point-set ⊆ — `covers`' converse: equals ∪ during ∪ starts ∪ finishes. */
|
|
135
57
|
coveredBy: (1 << 6) | (1 << 4) | (1 << 3) | (1 << 5),
|
|
136
|
-
/** The point-sets share no point: before ∪ meets ∪ met-by ∪ after. */
|
|
137
58
|
disjoint: (1 << 0) | (1 << 1) | (1 << 11) | (1 << 12)
|
|
138
59
|
});
|
|
139
|
-
/**
|
|
140
|
-
* THE interval-pair comparison (`ir::CmpOp::Allen`): two interval terms of
|
|
141
|
-
* one element type, satisfied iff the pair's classification is in the
|
|
142
|
-
* 13-bit mask — a literal built from the `ALLEN` constants.
|
|
143
|
-
*/
|
|
144
60
|
function allen(left, mask, right) {
|
|
145
61
|
assertTermSide("allen", left, right);
|
|
146
62
|
if (!Number.isInteger(mask) || mask < 0 || mask > ALLEN_ALL_BITS) {
|
|
@@ -148,20 +64,9 @@ function allen(left, mask, right) {
|
|
|
148
64
|
}
|
|
149
65
|
return comparison("allen", left, right, mask);
|
|
150
66
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Conjunction node of the input condition grammar (`ConditionTree::And`).
|
|
153
|
-
* The rule's condition list is already a conjunction — `and` exists for
|
|
154
|
-
* nesting under `or`, and the empty combination keeps the IR's algebraic
|
|
155
|
-
* reading (`And([])` is true).
|
|
156
|
-
*/
|
|
157
67
|
function and(...children) {
|
|
158
68
|
return Object.freeze({ cond: "tree", op: "and", children: Object.freeze(children) });
|
|
159
69
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Disjunction node of the input condition grammar (`ConditionTree::Or`) —
|
|
162
|
-
* the one place the surface admits a nested OR; validation distributes it
|
|
163
|
-
* to DNF rules engine-side. `Or([])` keeps its algebraic reading (false).
|
|
164
|
-
*/
|
|
165
70
|
function or(...children) {
|
|
166
71
|
return Object.freeze({ cond: "tree", op: "or", children: Object.freeze(children) });
|
|
167
72
|
}
|
package/dist/query/atom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.js","sourceRoot":"","sources":["../../src/query/atom.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"atom.js","sourceRoot":"","sources":["../../src/query/atom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAe/C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAoN9C,SAAS,UAAU,CAA8B,EAAM,EAAE,GAAM,EAAE,GAAM,EAAE,IAAO;IAC/E,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE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,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AACpF,CAAC;AAiBD,SAAS,GAAG,CACX,QAA6B,EAC7B,QAA2C;IAE3C,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,aAAsB,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;AACnE,CAAC;AA8OD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,CAAA"}
|
package/dist/query/find.d.ts
CHANGED
|
@@ -1,48 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Find entries and aggregates, REFERENCE-IDENTITY edition — the head
|
|
3
|
-
* vocabulary, mirroring the IR's aggregate roster exactly
|
|
4
|
-
* (`bumbledb/crates/bumbledb/src/ir.rs` `AggOp`/`FindTerm`;
|
|
5
|
-
* `docs/architecture/20-query-ir.md` § aggregation): `count` (nullary),
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
* `select(strings)` is DEAD: the head is a `find` RECORD, whose KEYS name
|
|
12
|
-
* the answer columns (`find({ total: r.count(), owner: h })`). The keys are
|
|
13
|
-
* unique object keys, so a duplicate answer column is unrepresentable and a
|
|
14
|
-
* rename is a real typed key. Grouping is implicit: the non-aggregate
|
|
15
|
-
* entries are the group key; over empty input an all-aggregate find yields
|
|
16
|
-
* the EMPTY SET, never a zero row. The creation quarantine is
|
|
17
|
-
* representational: a head position is a variable, the measure, or an
|
|
18
|
-
* aggregate — no minting or arithmetic term exists to spell (permanent law).
|
|
19
|
-
*/
|
|
20
1
|
import type { Infer } from "../fields.js";
|
|
21
2
|
import type { SchemaClasses } from "../law.js";
|
|
22
|
-
import type { IntervalVarOk, NumericVarOk
|
|
23
|
-
import type { AnyVar,
|
|
24
|
-
/** One aggregate operator name of the find vocabulary. */
|
|
3
|
+
import type { IntervalVarOk, NumericVarOk } from "./atom.js";
|
|
4
|
+
import type { AnyVar, MintSlotOf } from "./scope.js";
|
|
25
5
|
type FoldOpName = "sum" | "min" | "max" | "pack";
|
|
26
6
|
type AggOpName = "count" | FoldOpName;
|
|
27
|
-
/** Nullary count: no `over` exists to inhabit. */
|
|
28
7
|
interface CountAgg {
|
|
29
8
|
readonly agg: "count";
|
|
30
9
|
}
|
|
31
|
-
|
|
32
|
-
* One fold aggregate: the op and the variable (or measure) it folds
|
|
33
|
-
* BY REFERENCE. Count is [`CountAgg`], not this type with `undefined`.
|
|
34
|
-
*/
|
|
35
|
-
interface Agg<Op extends FoldOpName, Over extends AnyVar | Duration> {
|
|
10
|
+
interface Agg<Op extends FoldOpName, Over extends AnyVar> {
|
|
36
11
|
readonly agg: Op;
|
|
37
12
|
readonly over: Over;
|
|
38
13
|
}
|
|
39
|
-
|
|
40
|
-
type
|
|
41
|
-
/** One find entry: a projected variable, the measure, or an aggregate. */
|
|
42
|
-
type FindEntry = AnyVar | Duration | AnyAgg;
|
|
43
|
-
/** The `find` record: column name → find entry. Keys ARE the answer columns. */
|
|
14
|
+
type AnyAgg = CountAgg | Agg<FoldOpName, AnyVar>;
|
|
15
|
+
type FindEntry = AnyVar | AnyAgg;
|
|
44
16
|
type FindShape = Readonly<Record<string, FindEntry>>;
|
|
45
|
-
/** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
|
|
46
17
|
declare function count(): CountAgg;
|
|
47
18
|
/**
|
|
48
19
|
* Exact checked sum over a NUMERIC (u64/i64) variable — wide accumulator,
|
|
@@ -50,55 +21,18 @@ declare function count(): CountAgg;
|
|
|
50
21
|
* or over the measure (`r.sum(r.duration(w))`). Bool stays refused: a
|
|
51
22
|
* quantifier is not an addition (R3).
|
|
52
23
|
*/
|
|
53
|
-
declare function sum<const O extends AnyVar
|
|
54
|
-
|
|
55
|
-
declare function
|
|
56
|
-
/** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
|
|
57
|
-
declare function max<const O extends AnyVar | Duration>(over: O): Agg<"max", O>;
|
|
58
|
-
/**
|
|
59
|
-
* The coalescing fold (Snodgrass coalesce, `ir::AggOp::Pack`): per group,
|
|
60
|
-
* the maximal disjoint half-open segments of the union of the group's
|
|
61
|
-
* interval point sets — RELATION-SHAPED, one answer row per (group, maximal
|
|
62
|
-
* segment), the result position carrying one interval of the input's element
|
|
63
|
-
* type. At most one `pack` per find, never beside a fold entry.
|
|
64
|
-
*/
|
|
24
|
+
declare function sum<const O extends AnyVar>(over: O): Agg<"sum", O>;
|
|
25
|
+
declare function min<const O extends AnyVar>(over: O): Agg<"min", O>;
|
|
26
|
+
declare function max<const O extends AnyVar>(over: O): Agg<"max", O>;
|
|
65
27
|
declare function pack<const V extends AnyVar>(over: V): Agg<"pack", V>;
|
|
66
|
-
|
|
67
|
-
* A `sum` input's judgment: a NUMERIC variable — Sum over bool stays
|
|
68
|
-
* refused, a quantifier is not an addition (R3) — or the measure of an
|
|
69
|
-
* interval variable.
|
|
70
|
-
*/
|
|
71
|
-
type SumOverOk<O> = O extends AnyVar ? NumericVarOk<O> : O extends Duration<infer V extends AnyVar> ? IntervalVarOk<V> : false;
|
|
72
|
-
/**
|
|
73
|
-
* A `min`/`max` input's judgment: an ORDERABLE variable — bool folds:
|
|
74
|
-
* `Max` is Any and `Min` is All, the two quantifiers as the 0/1 encoding's
|
|
75
|
-
* extremes (R3) — or the measure of an interval variable.
|
|
76
|
-
*/
|
|
77
|
-
type FoldOverOk<O> = O extends AnyVar ? OrderVarOk<O> : O extends Duration<infer V extends AnyVar> ? IntervalVarOk<V> : false;
|
|
78
|
-
/**
|
|
79
|
-
* One find entry's judgment (off the entry's own descriptor — no env, no
|
|
80
|
-
* class map needed): a projected variable is ok, the measure and `pack`
|
|
81
|
-
* demand interval-typed variables, folds demand orderable ones.
|
|
82
|
-
*/
|
|
83
|
-
type FindEntryOk<E> = E extends AnyVar ? true : E extends Duration<infer V extends AnyVar> ? IntervalVarOk<V> : E extends CountAgg ? 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;
|
|
84
|
-
/** The validated find record (intersect with the inferred entries — errors land on the offending key). */
|
|
28
|
+
type FindEntryOk<E> = E extends AnyVar ? true : E extends CountAgg ? true : E extends Agg<"sum" | "min" | "max", infer O extends AnyVar> ? NumericVarOk<O> : E extends Agg<"pack", infer V extends AnyVar> ? IntervalVarOk<V> : false;
|
|
85
29
|
type CheckFind<F extends FindShape> = {
|
|
86
30
|
readonly [K in keyof F]: FindEntryOk<F[K]> extends true ? F[K] : never;
|
|
87
31
|
};
|
|
88
|
-
/**
|
|
89
|
-
* The validated find record of a RECURSIVE rule: every entry must be a plain
|
|
90
|
-
* variable (aggregates and the measure are unwritable in a rec head).
|
|
91
|
-
*/
|
|
92
32
|
type CheckRecFind<F extends FindShape> = {
|
|
93
33
|
readonly [K in keyof F]: F[K] extends AnyVar ? F[K] : never;
|
|
94
34
|
};
|
|
95
|
-
|
|
96
|
-
* One find entry's answer-column value type: a variable carries its field's
|
|
97
|
-
* type, the measure/count are `bigint`, folds carry their input's type
|
|
98
|
-
* (a measure fold is `bigint`), `pack` its interval type.
|
|
99
|
-
*/
|
|
100
|
-
type FindValue<E> = E extends AnyVar ? Infer<E["field"]> : E extends Duration<AnyVar> ? bigint : E extends CountAgg ? 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;
|
|
101
|
-
/** The inferred answer-row object type of a find record — the keys ARE the columns. */
|
|
35
|
+
type FindValue<E> = E extends AnyVar ? Infer<E["field"]> : E extends CountAgg ? bigint : E extends Agg<"sum" | "min" | "max", infer O extends AnyVar> ? Infer<O["field"]> : E extends Agg<"pack", infer V extends AnyVar> ? Infer<V["field"]> : never;
|
|
102
36
|
type RowOfFind<F extends FindShape> = {
|
|
103
37
|
readonly [K in keyof F]: FindValue<F[K]>;
|
|
104
38
|
};
|
package/dist/query/find.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAAA,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,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEzD,KAAK,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;AAChD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAErC,UAAU,QAAQ;IACjB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;CACrB;AAED,UAAU,GAAG,CAAC,EAAE,SAAS,UAAU,EAAE,IAAI,SAAS,MAAM;IACvD,QAAQ,CAAC,GAAG,EAAE,EAAE,CAA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,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,CAAA;AACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/query/find.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Find entries and aggregates, REFERENCE-IDENTITY edition — the head
|
|
3
|
-
* vocabulary, mirroring the IR's aggregate roster exactly
|
|
4
|
-
* (`bumbledb/crates/bumbledb/src/ir.rs` `AggOp`/`FindTerm`;
|
|
5
|
-
* `docs/architecture/20-query-ir.md` § aggregation): `count` (nullary),
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
* `select(strings)` is DEAD: the head is a `find` RECORD, whose KEYS name
|
|
12
|
-
* the answer columns (`find({ total: r.count(), owner: h })`). The keys are
|
|
13
|
-
* unique object keys, so a duplicate answer column is unrepresentable and a
|
|
14
|
-
* rename is a real typed key. Grouping is implicit: the non-aggregate
|
|
15
|
-
* entries are the group key; over empty input an all-aggregate find yields
|
|
16
|
-
* the EMPTY SET, never a zero row. The creation quarantine is
|
|
17
|
-
* representational: a head position is a variable, the measure, or an
|
|
18
|
-
* aggregate — no minting or arithmetic term exists to spell (permanent law).
|
|
19
|
-
*/
|
|
20
|
-
/** Builds one fold aggregate value. */
|
|
21
1
|
function aggregate(op, over) {
|
|
22
2
|
return Object.freeze({ agg: op, over });
|
|
23
3
|
}
|
|
24
|
-
/** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
|
|
25
4
|
function count() {
|
|
26
5
|
return Object.freeze({ agg: "count" });
|
|
27
6
|
}
|
|
@@ -34,21 +13,12 @@ function count() {
|
|
|
34
13
|
function sum(over) {
|
|
35
14
|
return aggregate("sum", over);
|
|
36
15
|
}
|
|
37
|
-
/** Minimum over an orderable variable (u64/i64/bool — over bool, `Min` is the ALL quantifier; R3) or the measure. */
|
|
38
16
|
function min(over) {
|
|
39
17
|
return aggregate("min", over);
|
|
40
18
|
}
|
|
41
|
-
/** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
|
|
42
19
|
function max(over) {
|
|
43
20
|
return aggregate("max", over);
|
|
44
21
|
}
|
|
45
|
-
/**
|
|
46
|
-
* The coalescing fold (Snodgrass coalesce, `ir::AggOp::Pack`): per group,
|
|
47
|
-
* the maximal disjoint half-open segments of the union of the group's
|
|
48
|
-
* interval point sets — RELATION-SHAPED, one answer row per (group, maximal
|
|
49
|
-
* segment), the result position carrying one interval of the input's element
|
|
50
|
-
* type. At most one `pack` per find, never beside a fold entry.
|
|
51
|
-
*/
|
|
52
22
|
function pack(over) {
|
|
53
23
|
return aggregate("pack", over);
|
|
54
24
|
}
|
package/dist/query/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/query/find.ts"],"names":[],"mappings":"AAuBA,SAAS,SAAS,CAA6C,EAAM,EAAE,IAAU;IAChF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,KAAK;IACb,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;AACvC,CAAC;AAED;;;;;GAKG;AACH,SAAS,GAAG,CAAyB,IAAO;IAC3C,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,GAAG,CAAyB,IAAO;IAC3C,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,GAAG,CAAyB,IAAO;IAC3C,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,IAAI,CAAyB,IAAO;IAC5C,OAAO,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC/B,CAAC;AAwDD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA"}
|