@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.
Files changed (108) hide show
  1. package/COOKBOOK.md +58 -62
  2. package/README.md +82 -56
  3. package/dist/capacity.d.ts +24 -136
  4. package/dist/capacity.d.ts.map +1 -1
  5. package/dist/capacity.js +18 -40
  6. package/dist/capacity.js.map +1 -1
  7. package/dist/closed.d.ts +0 -156
  8. package/dist/closed.d.ts.map +1 -1
  9. package/dist/closed.js +0 -104
  10. package/dist/closed.js.map +1 -1
  11. package/dist/db.d.ts +93 -290
  12. package/dist/db.d.ts.map +1 -1
  13. package/dist/db.js +713 -556
  14. package/dist/db.js.map +1 -1
  15. package/dist/face.d.ts +0 -133
  16. package/dist/face.d.ts.map +1 -1
  17. package/dist/face.js +0 -33
  18. package/dist/face.js.map +1 -1
  19. package/dist/fields.d.ts +1 -145
  20. package/dist/fields.d.ts.map +1 -1
  21. package/dist/fields.js +2 -91
  22. package/dist/fields.js.map +1 -1
  23. package/dist/index.d.ts +13 -23
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +11 -20
  26. package/dist/index.js.map +1 -1
  27. package/dist/law.d.ts +111 -93
  28. package/dist/law.d.ts.map +1 -1
  29. package/dist/law.js +23 -27
  30. package/dist/law.js.map +1 -1
  31. package/dist/lower.d.ts +9 -35
  32. package/dist/lower.d.ts.map +1 -1
  33. package/dist/lower.js +8 -53
  34. package/dist/lower.js.map +1 -1
  35. package/dist/marshal.d.ts +0 -65
  36. package/dist/marshal.d.ts.map +1 -1
  37. package/dist/marshal.js +0 -72
  38. package/dist/marshal.js.map +1 -1
  39. package/dist/native.d.ts +97 -390
  40. package/dist/native.d.ts.map +1 -1
  41. package/dist/native.js +39 -61
  42. package/dist/native.js.map +1 -1
  43. package/dist/query/atom.d.ts +10 -276
  44. package/dist/query/atom.d.ts.map +1 -1
  45. package/dist/query/atom.js +1 -96
  46. package/dist/query/atom.js.map +1 -1
  47. package/dist/query/find.d.ts +10 -76
  48. package/dist/query/find.d.ts.map +1 -1
  49. package/dist/query/find.js +0 -30
  50. package/dist/query/find.js.map +1 -1
  51. package/dist/query/lower.d.ts +64 -146
  52. package/dist/query/lower.d.ts.map +1 -1
  53. package/dist/query/lower.js +19 -256
  54. package/dist/query/lower.js.map +1 -1
  55. package/dist/query/parse-ir.d.ts +0 -7
  56. package/dist/query/parse-ir.d.ts.map +1 -1
  57. package/dist/query/parse-ir.js +1 -13
  58. package/dist/query/parse-ir.js.map +1 -1
  59. package/dist/query/run.d.ts +0 -36
  60. package/dist/query/run.d.ts.map +1 -1
  61. package/dist/query/run.js +0 -44
  62. package/dist/query/run.js.map +1 -1
  63. package/dist/query/scope.d.ts +24 -180
  64. package/dist/query/scope.d.ts.map +1 -1
  65. package/dist/query/scope.js +2 -66
  66. package/dist/query/scope.js.map +1 -1
  67. package/dist/relation.d.ts +2 -50
  68. package/dist/relation.d.ts.map +1 -1
  69. package/dist/relation.js +2 -37
  70. package/dist/relation.js.map +1 -1
  71. package/dist/schema.d.ts +13 -63
  72. package/dist/schema.d.ts.map +1 -1
  73. package/dist/schema.js +118 -92
  74. package/dist/schema.js.map +1 -1
  75. package/dist/spec.d.ts +1 -140
  76. package/dist/spec.d.ts.map +1 -1
  77. package/dist/spec.js +1 -68
  78. package/dist/spec.js.map +1 -1
  79. package/dist/statements.d.ts +6 -137
  80. package/dist/statements.d.ts.map +1 -1
  81. package/dist/statements.js +16 -119
  82. package/dist/statements.js.map +1 -1
  83. package/package.json +3 -3
  84. package/src/capacity.ts +26 -140
  85. package/src/closed.ts +5 -206
  86. package/src/db.ts +997 -854
  87. package/src/face.ts +0 -142
  88. package/src/fields.ts +4 -172
  89. package/src/index.ts +32 -35
  90. package/src/law.ts +201 -129
  91. package/src/lower.ts +8 -53
  92. package/src/marshal.ts +1 -85
  93. package/src/native.ts +192 -413
  94. package/src/query/atom.ts +26 -313
  95. package/src/query/find.ts +24 -110
  96. package/src/query/lower.ts +132 -377
  97. package/src/query/parse-ir.ts +1 -14
  98. package/src/query/run.ts +0 -45
  99. package/src/query/scope.ts +25 -186
  100. package/src/relation.ts +2 -66
  101. package/src/schema.ts +143 -122
  102. package/src/spec.ts +1 -160
  103. package/src/statements.ts +22 -174
  104. package/dist/exhume.d.ts +0 -143
  105. package/dist/exhume.d.ts.map +0 -1
  106. package/dist/exhume.js +0 -166
  107. package/dist/exhume.js.map +0 -1
  108. package/src/exhume.ts +0 -267
package/src/query/find.ts CHANGED
@@ -1,61 +1,30 @@
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
-
21
1
  import type { Infer } from "#fields.ts"
22
2
  import type { SchemaClasses } from "#law.ts"
23
- import type { IntervalVarOk, NumericVarOk, OrderVarOk } from "#query/atom.ts"
24
- import type { AnyVar, Duration, MintSlotOf } from "#query/scope.ts"
3
+ import type { IntervalVarOk, NumericVarOk } from "#query/atom.ts"
4
+ import type { AnyVar, MintSlotOf } from "#query/scope.ts"
25
5
 
26
- /** One aggregate operator name of the find vocabulary. */
27
6
  type FoldOpName = "sum" | "min" | "max" | "pack"
28
7
  type AggOpName = "count" | FoldOpName
29
8
 
30
- /** Nullary count: no `over` exists to inhabit. */
31
9
  interface CountAgg {
32
10
  readonly agg: "count"
33
11
  }
34
12
 
35
- /**
36
- * One fold aggregate: the op and the variable (or measure) it folds
37
- * BY REFERENCE. Count is [`CountAgg`], not this type with `undefined`.
38
- */
39
- interface Agg<Op extends FoldOpName, Over extends AnyVar | Duration> {
13
+ interface Agg<Op extends FoldOpName, Over extends AnyVar> {
40
14
  readonly agg: Op
41
15
  readonly over: Over
42
16
  }
43
17
 
44
- /** Any aggregate find value. */
45
- type AnyAgg = CountAgg | Agg<FoldOpName, AnyVar | Duration>
18
+ type AnyAgg = CountAgg | Agg<FoldOpName, AnyVar>
46
19
 
47
- /** One find entry: a projected variable, the measure, or an aggregate. */
48
- type FindEntry = AnyVar | Duration | AnyAgg
20
+ type FindEntry = AnyVar | AnyAgg
49
21
 
50
- /** The `find` record: column name → find entry. Keys ARE the answer columns. */
51
22
  type FindShape = Readonly<Record<string, FindEntry>>
52
23
 
53
- /** Builds one fold aggregate value. */
54
- function aggregate<Op extends FoldOpName, Over extends AnyVar | Duration>(op: Op, over: Over): Agg<Op, Over> {
24
+ function aggregate<Op extends FoldOpName, Over extends AnyVar>(op: Op, over: Over): Agg<Op, Over> {
55
25
  return Object.freeze({ agg: op, over })
56
26
  }
57
27
 
58
- /** Nullary count: |the group's set of distinct full bindings|, `bigint`. */
59
28
  function count(): CountAgg {
60
29
  return Object.freeze({ agg: "count" })
61
30
  }
@@ -66,105 +35,50 @@ function count(): CountAgg {
66
35
  * or over the measure (`r.sum(r.duration(w))`). Bool stays refused: a
67
36
  * quantifier is not an addition (R3).
68
37
  */
69
- function sum<const O extends AnyVar | Duration>(over: O): Agg<"sum", O> {
38
+ function sum<const O extends AnyVar>(over: O): Agg<"sum", O> {
70
39
  return aggregate("sum", over)
71
40
  }
72
41
 
73
- /** Minimum over an orderable variable (u64/i64/bool — over bool, `Min` is the ALL quantifier; R3) or the measure. */
74
- function min<const O extends AnyVar | Duration>(over: O): Agg<"min", O> {
42
+ function min<const O extends AnyVar>(over: O): Agg<"min", O> {
75
43
  return aggregate("min", over)
76
44
  }
77
45
 
78
- /** Maximum over an orderable variable (u64/i64/bool — over bool, `Max` is the ANY quantifier; R3) or the measure. */
79
- function max<const O extends AnyVar | Duration>(over: O): Agg<"max", O> {
46
+ function max<const O extends AnyVar>(over: O): Agg<"max", O> {
80
47
  return aggregate("max", over)
81
48
  }
82
49
 
83
- /**
84
- * The coalescing fold (Snodgrass coalesce, `ir::AggOp::Pack`): per group,
85
- * the maximal disjoint half-open segments of the union of the group's
86
- * interval point sets — RELATION-SHAPED, one answer row per (group, maximal
87
- * segment), the result position carrying one interval of the input's element
88
- * type. At most one `pack` per find, never beside a fold entry.
89
- */
90
50
  function pack<const V extends AnyVar>(over: V): Agg<"pack", V> {
91
51
  return aggregate("pack", over)
92
52
  }
93
53
 
94
- /**
95
- * A `sum` input's judgment: a NUMERIC variable — Sum over bool stays
96
- * refused, a quantifier is not an addition (R3) — or the measure of an
97
- * interval variable.
98
- */
99
- type SumOverOk<O> = O extends AnyVar
100
- ? NumericVarOk<O>
101
- : O extends Duration<infer V extends AnyVar>
102
- ? IntervalVarOk<V>
103
- : false
104
-
105
- /**
106
- * A `min`/`max` input's judgment: an ORDERABLE variable — bool folds:
107
- * `Max` is Any and `Min` is All, the two quantifiers as the 0/1 encoding's
108
- * extremes (R3) — or the measure of an interval variable.
109
- */
110
- type FoldOverOk<O> = O extends AnyVar
111
- ? OrderVarOk<O>
112
- : O extends Duration<infer V extends AnyVar>
113
- ? IntervalVarOk<V>
114
- : false
115
-
116
- /**
117
- * One find entry's judgment (off the entry's own descriptor — no env, no
118
- * class map needed): a projected variable is ok, the measure and `pack`
119
- * demand interval-typed variables, folds demand orderable ones.
120
- */
121
54
  type FindEntryOk<E> = E extends AnyVar
122
55
  ? true
123
- : E extends Duration<infer V extends AnyVar>
124
- ? IntervalVarOk<V>
125
- : E extends CountAgg
126
- ? true
127
- : E extends Agg<"sum", infer O>
128
- ? SumOverOk<O>
129
- : E extends Agg<"min" | "max", infer O>
130
- ? FoldOverOk<O>
131
- : E extends Agg<"pack", infer V extends AnyVar>
132
- ? IntervalVarOk<V>
133
- : false
134
-
135
- /** The validated find record (intersect with the inferred entries — errors land on the offending key). */
56
+ : E extends CountAgg
57
+ ? true
58
+ : E extends Agg<"sum" | "min" | "max", infer O extends AnyVar>
59
+ ? NumericVarOk<O>
60
+ : E extends Agg<"pack", infer V extends AnyVar>
61
+ ? IntervalVarOk<V>
62
+ : false
63
+
136
64
  type CheckFind<F extends FindShape> = {
137
65
  readonly [K in keyof F]: FindEntryOk<F[K]> extends true ? F[K] : never
138
66
  }
139
67
 
140
- /**
141
- * The validated find record of a RECURSIVE rule: every entry must be a plain
142
- * variable (aggregates and the measure are unwritable in a rec head).
143
- */
144
68
  type CheckRecFind<F extends FindShape> = {
145
69
  readonly [K in keyof F]: F[K] extends AnyVar ? F[K] : never
146
70
  }
147
71
 
148
- /**
149
- * One find entry's answer-column value type: a variable carries its field's
150
- * type, the measure/count are `bigint`, folds carry their input's type
151
- * (a measure fold is `bigint`), `pack` its interval type.
152
- */
153
72
  type FindValue<E> = E extends AnyVar
154
73
  ? Infer<E["field"]>
155
- : E extends Duration<AnyVar>
74
+ : E extends CountAgg
156
75
  ? bigint
157
- : E extends CountAgg
158
- ? bigint
159
- : E extends Agg<"sum" | "min" | "max", infer O>
160
- ? O extends AnyVar
161
- ? Infer<O["field"]>
162
- : bigint
163
- : E extends Agg<"pack", infer V extends AnyVar>
164
- ? Infer<V["field"]>
165
- : never
166
-
167
- /** The inferred answer-row object type of a find record — the keys ARE the columns. */
76
+ : E extends Agg<"sum" | "min" | "max", infer O extends AnyVar>
77
+ ? Infer<O["field"]>
78
+ : E extends Agg<"pack", infer V extends AnyVar>
79
+ ? Infer<V["field"]>
80
+ : never
81
+
168
82
  type RowOfFind<F extends FindShape> = { readonly [K in keyof F]: FindValue<F[K]> }
169
83
 
170
84
  /**