@bjornpagen/bumbledb 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/COOKBOOK.md +155 -136
  2. package/README.md +3 -7
  3. package/dist/capacity.d.ts +14 -1
  4. package/dist/capacity.d.ts.map +1 -1
  5. package/dist/capacity.js.map +1 -1
  6. package/dist/db.d.ts +77 -109
  7. package/dist/db.d.ts.map +1 -1
  8. package/dist/db.js +121 -339
  9. package/dist/db.js.map +1 -1
  10. package/dist/index.d.ts +11 -16
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/lower.d.ts.map +1 -1
  15. package/dist/lower.js +8 -1
  16. package/dist/lower.js.map +1 -1
  17. package/dist/native.d.ts +69 -50
  18. package/dist/native.d.ts.map +1 -1
  19. package/dist/native.js.map +1 -1
  20. package/dist/query/atom.d.ts +162 -122
  21. package/dist/query/atom.d.ts.map +1 -1
  22. package/dist/query/atom.js +26 -22
  23. package/dist/query/atom.js.map +1 -1
  24. package/dist/query/find.d.ts +18 -35
  25. package/dist/query/find.d.ts.map +1 -1
  26. package/dist/query/find.js +13 -32
  27. package/dist/query/find.js.map +1 -1
  28. package/dist/query/lower.d.ts +113 -122
  29. package/dist/query/lower.d.ts.map +1 -1
  30. package/dist/query/lower.js +336 -260
  31. package/dist/query/lower.js.map +1 -1
  32. package/dist/query/parse-ir.d.ts +12 -0
  33. package/dist/query/parse-ir.d.ts.map +1 -0
  34. package/dist/query/parse-ir.js +71 -0
  35. package/dist/query/parse-ir.js.map +1 -0
  36. package/dist/query/run.d.ts +2 -2
  37. package/dist/query/run.d.ts.map +1 -1
  38. package/dist/query/run.js +2 -13
  39. package/dist/query/run.js.map +1 -1
  40. package/dist/query/scope.d.ts +4 -16
  41. package/dist/query/scope.d.ts.map +1 -1
  42. package/dist/query/scope.js +1 -6
  43. package/dist/query/scope.js.map +1 -1
  44. package/dist/schema.js +2 -2
  45. package/dist/schema.js.map +1 -1
  46. package/dist/statements.d.ts +15 -9
  47. package/dist/statements.d.ts.map +1 -1
  48. package/dist/statements.js +14 -9
  49. package/dist/statements.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/capacity.ts +24 -1
  52. package/src/db.ts +182 -443
  53. package/src/index.ts +9 -23
  54. package/src/lower.ts +8 -1
  55. package/src/native.ts +69 -42
  56. package/src/query/atom.ts +255 -165
  57. package/src/query/find.ts +39 -80
  58. package/src/query/lower.ts +578 -432
  59. package/src/query/parse-ir.ts +82 -0
  60. package/src/query/run.ts +2 -14
  61. package/src/query/scope.ts +3 -21
  62. package/src/schema.ts +2 -2
  63. package/src/statements.ts +33 -17
  64. package/dist/order.d.ts +0 -87
  65. package/dist/order.d.ts.map +0 -1
  66. package/dist/order.js +0 -153
  67. package/dist/order.js.map +0 -1
  68. package/dist/query/predicate.d.ts +0 -91
  69. package/dist/query/predicate.d.ts.map +0 -1
  70. package/dist/query/predicate.js +0 -156
  71. package/dist/query/predicate.js.map +0 -1
  72. package/src/order.ts +0 -234
  73. package/src/query/predicate.ts +0 -269
package/src/query/find.ts CHANGED
@@ -3,11 +3,10 @@
3
3
  * vocabulary, mirroring the IR's aggregate roster exactly
4
4
  * (`bumbledb/crates/bumbledb/src/ir.rs` `AggOp`/`FindTerm`;
5
5
  * `docs/architecture/20-query-ir.md` § aggregation): `count` (nullary),
6
- * `countDistinct`, `sum`/`min`/`max` (over an orderable variable or the
7
- * measure), `argMax`/`argMin` (arg-restriction: carried value + orderable
8
- * key), and `pack` (the coalescing fold — RELATION-SHAPED, the result
9
- * position interval-typed). Aggregates fold VARIABLES by reference —
10
- * `r.sum(w)` — and are typed by the variable's own descriptor.
6
+ * `sum`/`min`/`max` (over an orderable variable or the measure), and
7
+ * `pack` (the coalescing fold — RELATION-SHAPED, the result position
8
+ * interval-typed). Aggregates fold VARIABLES by reference — `r.sum(w)` —
9
+ * and are typed by the variable's own descriptor.
11
10
  *
12
11
  * `select(strings)` is DEAD: the head is a `find` RECORD, whose KEYS name
13
12
  * the answer columns (`find({ total: r.count(), owner: h })`). The keys are
@@ -25,25 +24,19 @@ import type { IntervalVarOk, NumericVarOk, OrderVarOk } from "#query/atom.ts"
25
24
  import type { AnyVar, Duration, MintSlotOf } from "#query/scope.ts"
26
25
 
27
26
  /** One aggregate operator name of the find vocabulary. */
28
- type AggOpName = "count" | "countDistinct" | "sum" | "min" | "max" | "argMax" | "argMin" | "pack"
27
+ type AggOpName = "count" | "sum" | "min" | "max" | "pack"
29
28
 
30
29
  /**
31
- * One aggregate find VALUE: the op, the variable (or measure) it folds BY
32
- * REFERENCE, and — for the Arg forms — the orderable key variable. The
33
- * variable's own descriptor types the result.
30
+ * One aggregate find VALUE: the op and the variable (or measure) it folds
31
+ * BY REFERENCE. The variable's own descriptor types the result.
34
32
  */
35
- interface Agg<
36
- Op extends AggOpName,
37
- Over extends AnyVar | Duration | undefined,
38
- Key extends AnyVar | undefined = undefined
39
- > {
33
+ interface Agg<Op extends AggOpName, Over extends AnyVar | Duration | undefined> {
40
34
  readonly agg: Op
41
35
  readonly over: Over
42
- readonly key: Key
43
36
  }
44
37
 
45
38
  /** Any aggregate find value. */
46
- type AnyAgg = Agg<AggOpName, AnyVar | Duration | undefined, AnyVar | undefined>
39
+ type AnyAgg = Agg<AggOpName, AnyVar | Duration | undefined>
47
40
 
48
41
  /** One find entry: a projected variable, the measure, or an aggregate. */
49
42
  type FindEntry = AnyVar | Duration | AnyAgg
@@ -52,22 +45,16 @@ type FindEntry = AnyVar | Duration | AnyAgg
52
45
  type FindShape = Readonly<Record<string, FindEntry>>
53
46
 
54
47
  /** Builds one aggregate value. */
55
- function aggregate<Op extends AggOpName, Over extends AnyVar | Duration | undefined, Key extends AnyVar | undefined>(
48
+ function aggregate<Op extends AggOpName, Over extends AnyVar | Duration | undefined>(
56
49
  op: Op,
57
- over: Over,
58
- key: Key
59
- ): Agg<Op, Over, Key> {
60
- return Object.freeze({ agg: op, over, key })
50
+ over: Over
51
+ ): Agg<Op, Over> {
52
+ return Object.freeze({ agg: op, over })
61
53
  }
62
54
 
63
55
  /** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
64
56
  function count(): Agg<"count", undefined> {
65
- return aggregate("count", undefined, undefined)
66
- }
67
-
68
- /** |the distinct values of the variable across the group|, `bigint`; legal over every type. */
69
- function countDistinct<const V extends AnyVar>(over: V): Agg<"countDistinct", V> {
70
- return aggregate("countDistinct", over, undefined)
57
+ return aggregate("count", undefined)
71
58
  }
72
59
 
73
60
  /**
@@ -77,33 +64,17 @@ function countDistinct<const V extends AnyVar>(over: V): Agg<"countDistinct", V>
77
64
  * quantifier is not an addition (R3).
78
65
  */
79
66
  function sum<const O extends AnyVar | Duration>(over: O): Agg<"sum", O> {
80
- return aggregate("sum", over, undefined)
67
+ return aggregate("sum", over)
81
68
  }
82
69
 
83
70
  /** Minimum over an orderable variable (u64/i64/bool — over bool, `Min` is the ALL quantifier; R3) or the measure. */
84
71
  function min<const O extends AnyVar | Duration>(over: O): Agg<"min", O> {
85
- return aggregate("min", over, undefined)
72
+ return aggregate("min", over)
86
73
  }
87
74
 
88
75
  /** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
89
76
  function max<const O extends AnyVar | Duration>(over: O): Agg<"max", O> {
90
- return aggregate("max", over, undefined)
91
- }
92
-
93
- /**
94
- * Arg-restriction toward the maximum of `key` (`ir::AggOp::ArgMax`): the
95
- * group's binding set is restricted to the bindings attaining the extreme
96
- * of the orderable key, and `value` is the carried payload — a tie yields
97
- * every attaining row. All Arg entries of one query share one key and one
98
- * direction; Arg and fold aggregates never mix (both the engine's rules).
99
- */
100
- function argMax<const V extends AnyVar, const K extends AnyVar>(value: V, key: K): Agg<"argMax", V, K> {
101
- return aggregate("argMax", value, key)
102
- }
103
-
104
- /** Arg-restriction toward the minimum of `key`; rules as {@link argMax}. */
105
- function argMin<const V extends AnyVar, const K extends AnyVar>(value: V, key: K): Agg<"argMin", V, K> {
106
- return aggregate("argMin", value, key)
77
+ return aggregate("max", over)
107
78
  }
108
79
 
109
80
  /**
@@ -111,10 +82,10 @@ function argMin<const V extends AnyVar, const K extends AnyVar>(value: V, key: K
111
82
  * the maximal disjoint half-open segments of the union of the group's
112
83
  * interval point sets — RELATION-SHAPED, one answer row per (group, maximal
113
84
  * segment), the result position carrying one interval of the input's element
114
- * type. At most one `pack` per find, never beside a fold or an Arg entry.
85
+ * type. At most one `pack` per find, never beside a fold entry.
115
86
  */
116
87
  function pack<const V extends AnyVar>(over: V): Agg<"pack", V> {
117
- return aggregate("pack", over, undefined)
88
+ return aggregate("pack", over)
118
89
  }
119
90
 
120
91
  /**
@@ -142,7 +113,7 @@ type FoldOverOk<O> = O extends AnyVar
142
113
  /**
143
114
  * One find entry's judgment (off the entry's own descriptor — no env, no
144
115
  * class map needed): a projected variable is ok, the measure and `pack`
145
- * demand interval-typed variables, folds and Arg keys demand orderable ones.
116
+ * demand interval-typed variables, folds demand orderable ones.
146
117
  */
147
118
  type FindEntryOk<E> = E extends AnyVar
148
119
  ? true
@@ -150,19 +121,13 @@ type FindEntryOk<E> = E extends AnyVar
150
121
  ? IntervalVarOk<V>
151
122
  : E extends Agg<"count", undefined>
152
123
  ? true
153
- : E extends Agg<"countDistinct", AnyVar>
154
- ? true
155
- : E extends Agg<"sum", infer O>
156
- ? SumOverOk<O>
157
- : E extends Agg<"min" | "max", infer O>
158
- ? FoldOverOk<O>
159
- : E extends Agg<"argMax" | "argMin", AnyVar, infer K extends AnyVar>
160
- ? OrderVarOk<K> extends true
161
- ? true
162
- : false
163
- : E extends Agg<"pack", infer V extends AnyVar>
164
- ? IntervalVarOk<V>
165
- : false
124
+ : E extends Agg<"sum", infer O>
125
+ ? SumOverOk<O>
126
+ : E extends Agg<"min" | "max", infer O>
127
+ ? FoldOverOk<O>
128
+ : E extends Agg<"pack", infer V extends AnyVar>
129
+ ? IntervalVarOk<V>
130
+ : false
166
131
 
167
132
  /** The validated find record (intersect with the inferred entries — errors land on the offending key). */
168
133
  type CheckFind<F extends FindShape> = {
@@ -171,8 +136,7 @@ type CheckFind<F extends FindShape> = {
171
136
 
172
137
  /**
173
138
  * The validated find record of a RECURSIVE rule: every entry must be a plain
174
- * variable (aggregates and the measure are unwritable in a recursive head —
175
- * the strata quarantine).
139
+ * variable (aggregates and the measure are unwritable in a rec head).
176
140
  */
177
141
  type CheckRecFind<F extends FindShape> = {
178
142
  readonly [K in keyof F]: F[K] extends AnyVar ? F[K] : never
@@ -180,9 +144,8 @@ type CheckRecFind<F extends FindShape> = {
180
144
 
181
145
  /**
182
146
  * One find entry's answer-column value type: a variable carries its field's
183
- * type, the measure/count/countDistinct are `bigint`, folds carry their
184
- * input's type (a measure fold is `bigint`), the Arg forms carry the
185
- * payload's type, `pack` its interval type.
147
+ * type, the measure/count are `bigint`, folds carry their input's type
148
+ * (a measure fold is `bigint`), `pack` its interval type.
186
149
  */
187
150
  type FindValue<E> = E extends AnyVar
188
151
  ? Infer<E["field"]>
@@ -190,17 +153,13 @@ type FindValue<E> = E extends AnyVar
190
153
  ? bigint
191
154
  : E extends Agg<"count", undefined>
192
155
  ? bigint
193
- : E extends Agg<"countDistinct", AnyVar>
194
- ? bigint
195
- : E extends Agg<"sum" | "min" | "max", infer O>
196
- ? O extends AnyVar
197
- ? Infer<O["field"]>
198
- : bigint
199
- : E extends Agg<"argMax" | "argMin", infer V extends AnyVar, AnyVar>
200
- ? Infer<V["field"]>
201
- : E extends Agg<"pack", infer V extends AnyVar>
202
- ? Infer<V["field"]>
203
- : never
156
+ : E extends Agg<"sum" | "min" | "max", infer O>
157
+ ? O extends AnyVar
158
+ ? Infer<O["field"]>
159
+ : bigint
160
+ : E extends Agg<"pack", infer V extends AnyVar>
161
+ ? Infer<V["field"]>
162
+ : never
204
163
 
205
164
  /** The inferred answer-row object type of a find record — the keys ARE the columns. */
206
165
  type RowOfFind<F extends FindShape> = { readonly [K in keyof F]: FindValue<F[K]> }
@@ -208,7 +167,7 @@ type RowOfFind<F extends FindShape> = { readonly [K in keyof F]: FindValue<F[K]>
208
167
  /**
209
168
  * The head signature of a recursive rule's find record as classed mint
210
169
  * slots (descriptor + law-computed class), keyed by column name — the
211
- * signature an `idb` join pairs against (`F` is variable-only there).
170
+ * signature an interior join pairs against (`F` is variable-only there).
212
171
  */
213
172
  type HeadRecordOf<Classes extends SchemaClasses, F extends FindShape> = {
214
173
  readonly [K in keyof F]: F[K] extends AnyVar ? MintSlotOf<Classes, F[K]> : never
@@ -227,4 +186,4 @@ export type {
227
186
  HeadRecordOf,
228
187
  RowOfFind
229
188
  }
230
- export { argMax, argMin, count, countDistinct, max, min, pack, sum }
189
+ export { count, max, min, pack, sum }