@bjornpagen/bumbledb 0.7.0 → 0.9.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 (68) hide show
  1. package/COOKBOOK.md +105 -3
  2. package/README.md +3 -3
  3. package/dist/capacity.d.ts +310 -0
  4. package/dist/capacity.d.ts.map +1 -0
  5. package/dist/capacity.js +138 -0
  6. package/dist/capacity.js.map +1 -0
  7. package/dist/db.d.ts +5 -3
  8. package/dist/db.d.ts.map +1 -1
  9. package/dist/db.js +8 -8
  10. package/dist/db.js.map +1 -1
  11. package/dist/face.d.ts +1 -1
  12. package/dist/face.d.ts.map +1 -1
  13. package/dist/face.js.map +1 -1
  14. package/dist/index.d.ts +8 -8
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -3
  17. package/dist/index.js.map +1 -1
  18. package/dist/law.d.ts +3 -2
  19. package/dist/law.d.ts.map +1 -1
  20. package/dist/law.js +1 -1
  21. package/dist/law.js.map +1 -1
  22. package/dist/lower.d.ts.map +1 -1
  23. package/dist/lower.js +3 -2
  24. package/dist/lower.js.map +1 -1
  25. package/dist/native.d.ts +6 -3
  26. package/dist/native.d.ts.map +1 -1
  27. package/dist/native.js.map +1 -1
  28. package/dist/order.d.ts +53 -2
  29. package/dist/order.d.ts.map +1 -1
  30. package/dist/order.js +30 -12
  31. package/dist/order.js.map +1 -1
  32. package/dist/query/atom.d.ts +33 -13
  33. package/dist/query/atom.d.ts.map +1 -1
  34. package/dist/query/atom.js +1 -1
  35. package/dist/query/atom.js.map +1 -1
  36. package/dist/query/find.d.ts +19 -8
  37. package/dist/query/find.d.ts.map +1 -1
  38. package/dist/query/find.js +6 -5
  39. package/dist/query/find.js.map +1 -1
  40. package/dist/schema.js +1 -1
  41. package/dist/schema.js.map +1 -1
  42. package/dist/spec.d.ts +76 -23
  43. package/dist/spec.d.ts.map +1 -1
  44. package/dist/spec.js +39 -7
  45. package/dist/spec.js.map +1 -1
  46. package/dist/statements.d.ts +42 -25
  47. package/dist/statements.d.ts.map +1 -1
  48. package/dist/statements.js +81 -19
  49. package/dist/statements.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/capacity.ts +454 -0
  52. package/src/db.ts +13 -11
  53. package/src/face.ts +1 -0
  54. package/src/index.ts +20 -9
  55. package/src/law.ts +3 -2
  56. package/src/lower.ts +3 -2
  57. package/src/native.ts +6 -3
  58. package/src/order.ts +83 -5
  59. package/src/query/atom.ts +37 -13
  60. package/src/query/find.ts +34 -16
  61. package/src/schema.ts +1 -1
  62. package/src/spec.ts +91 -25
  63. package/src/statements.ts +160 -34
  64. package/dist/count.d.ts +0 -102
  65. package/dist/count.d.ts.map +0 -1
  66. package/dist/count.js +0 -115
  67. package/dist/count.js.map +0 -1
  68. package/src/count.ts +0 -211
package/src/count.ts DELETED
@@ -1,211 +0,0 @@
1
- /**
2
- * Cardinality-window counts — exactly five constructors, and nothing else
3
- * (`docs/architecture/70-api.md` § the canonical-utterance law). The five
4
- * constructors PARTITION the legal windows, and the ban table is enforced
5
- * REPRESENTATIONALLY, stronger than Rust's expansion errors, in two tiers:
6
- *
7
- * - **The type tier**: a banned spelling written as a LITERAL does not
8
- * compile — `exactly(0n)`, `between(n, n)`, `between(0n, hi)`,
9
- * `atLeast(0n)`, `atLeast(1n)`, `atMost(0n)`, and every negative bound
10
- * are type errors naming the canonical form (`{n..n}`, `{0..0}`,
11
- * `{0..hi}`-via-between, `{0..*}`, `{1..*}` have NO argument shape that
12
- * produces them), and no sixth constructor exists at all.
13
- * - **The construction tier**: a bound the type level cannot judge — a
14
- * COMPUTED `bigint`, whose literal identity is erased, or an inverted
15
- * `between(lo, hi)` order, which type-level bigints cannot compare — is
16
- * judged here at construction with the same canonical-naming errors; and
17
- * past both tiers the engine's own spec validation remains the law for a
18
- * hostile FFI caller (the standing two-tier ban enforcement).
19
- *
20
- * Bounds are `bigint` (u64 crosses as bigint always, PRD-04's law).
21
- */
22
-
23
- import * as errors from "@superbuilders/errors"
24
- import type { WindowSpec } from "#spec.ts"
25
-
26
- /** The exclusion's one spelling, shared by `none`. */
27
- const exclusion: WindowSpec = Object.freeze({ kind: "exact", n: 0n })
28
-
29
- /**
30
- * The admission brand — a module-private symbol, deliberately unexported:
31
- * `WindowSpec` is a public wire type, so without this brand every banned
32
- * spelling in the ban table would be writable as a plain object literal
33
- * (`{ window: { kind: "floor", lo: 1n } }` typechecks structurally). The
34
- * symbol makes the five constructors the ONLY producers of a `Count`
35
- * value, which is what "the ban table is unwritable" means.
36
- */
37
- const admitted: unique symbol = Symbol("bumbledb.count.admitted")
38
-
39
- /**
40
- * An admitted window count — opaque and inert: a fact about the theory,
41
- * not a builder. Only the five constructors below produce one (the
42
- * module-private {@link admitted} brand forecloses structural literals).
43
- */
44
- interface Count {
45
- readonly window: WindowSpec
46
- readonly [admitted]: true
47
- }
48
-
49
- /** Stamps one admitted window as a frozen `Count` value. */
50
- function admit(window: WindowSpec): Count {
51
- const count: Count = { window, [admitted]: true }
52
- return Object.freeze(count)
53
- }
54
-
55
- /**
56
- * The legible banned-spelling verdict: intersected into a count
57
- * constructor's parameter when the LITERAL argument spells a banned window,
58
- * naming the canonical form — the compile-time face of the ban table.
59
- */
60
- interface BannedWindow<Canonical extends string> {
61
- readonly "banned window spelling — the canonical-utterance law names the one legal form": Canonical
62
- }
63
-
64
- /** `true` exactly when the literal bigint `N` is negative (out of the u64 count domain). */
65
- type IsNegative<N extends bigint> = `${N}` extends `-${string}` ? true : false
66
-
67
- /** The ban verdict on `exactly(n)`: negatives are out of domain; `{0}` is the exclusion, written `none`. */
68
- type ExactlyBan<N extends bigint> = bigint extends N
69
- ? unknown
70
- : IsNegative<N> extends true
71
- ? BannedWindow<"window counts are u64 — a negative count is out of domain">
72
- : N extends 0n
73
- ? BannedWindow<"`{0}` is the exclusion — write none">
74
- : unknown
75
-
76
- /** The ban verdict on `atLeast(lo)`: `{0..*}` is vacuous; `{1..*}` is the bare containment respelled. */
77
- type AtLeastBan<N extends bigint> = bigint extends N
78
- ? unknown
79
- : IsNegative<N> extends true
80
- ? BannedWindow<"window counts are u64 — a negative count is out of domain">
81
- : N extends 0n
82
- ? BannedWindow<"`{0..*}` is vacuous — it provably says nothing; delete the statement">
83
- : N extends 1n
84
- ? BannedWindow<"`{1..*}` says only what the bare containment says — write contained(source, target)">
85
- : unknown
86
-
87
- /** The ban verdict on `atMost(hi)`: `{0..0}` is the exclusion, written `none`. */
88
- type AtMostBan<N extends bigint> = bigint extends N
89
- ? unknown
90
- : IsNegative<N> extends true
91
- ? BannedWindow<"window counts are u64 — a negative count is out of domain">
92
- : N extends 0n
93
- ? BannedWindow<"`{0..0}` — the exclusion is written `{0}`: use none">
94
- : unknown
95
-
96
- /** The ban verdict on a `between` floor of zero: `{0..hi}` is the ceiling respelled (`atMost(hi)`). */
97
- type BetweenFloorBan<Lo extends bigint> = Lo extends 0n
98
- ? BannedWindow<"`{0..hi}` — a ceiling is written atMost(hi)">
99
- : unknown
100
-
101
- /**
102
- * The ban verdict on `between(lo, hi)`, judged on the second bound once
103
- * both literals are known: `{n..n}` is the exact count respelled
104
- * (`exactly(n)`, or `none` at 0), and `{0..hi}` is the ceiling respelled
105
- * (`atMost(hi)` — the five constructors PARTITION the legal windows, so
106
- * the one ceiling window keeps its one spelling). Bound ORDER (`{hi..lo}`
107
- * inverted) is not type-expressible — bigint literals have no type-level
108
- * comparison — so inversion stays a construction error below.
109
- */
110
- type BetweenBan<Lo extends bigint, Hi extends bigint> = bigint extends Lo
111
- ? unknown
112
- : bigint extends Hi
113
- ? unknown
114
- : IsNegative<Lo> extends true
115
- ? BannedWindow<"window counts are u64 — a negative bound is out of domain">
116
- : IsNegative<Hi> extends true
117
- ? BannedWindow<"window counts are u64 — a negative bound is out of domain">
118
- : Lo extends Hi
119
- ? Hi extends Lo
120
- ? Lo extends 0n
121
- ? BannedWindow<"`{0..0}` — the exclusion is written `{0}`: use none">
122
- : BannedWindow<"`{n..n}` — an exact count is written `{n}`: use exactly(n)">
123
- : BetweenFloorBan<Lo>
124
- : BetweenFloorBan<Lo>
125
-
126
- /**
127
- * `{n}` — THE exact-count spelling, n ≥ 1. `exactly(0)` is the exclusion
128
- * respelled: unwritable as a literal ({@link ExactlyBan} names `none`),
129
- * rejected at construction when computed.
130
- */
131
- function exactly<const N extends bigint>(n: N & ExactlyBan<N>): Count {
132
- if (n < 0n) {
133
- throw errors.new(`window counts are u64: exactly(${n}) is out of domain`)
134
- }
135
- if (n === 0n) {
136
- throw errors.new("`{0}` is the exclusion — write none")
137
- }
138
- return admit(Object.freeze({ kind: "exact", n }))
139
- }
140
-
141
- /** `{0}` — the exclusion: no source fact may pair with the target group. */
142
- const none: Count = admit(exclusion)
143
-
144
- /**
145
- * `{lo..hi}` — both bounds explicit, 1 ≤ lo < hi. `lo === hi` is the exact
146
- * count respelled and `lo === 0` is the ceiling respelled: unwritable as
147
- * literals ({@link BetweenBan} names `exactly(n)`, `none` at `{0..0}`, or
148
- * `atMost(hi)` at a zero floor — the five constructors PARTITION the legal
149
- * windows), rejected at construction when computed; an inverted window is
150
- * unsatisfiable and rejected at construction (bigint literals carry no
151
- * type-level order).
152
- */
153
- function between<const Lo extends bigint, const Hi extends bigint>(lo: Lo, hi: Hi & BetweenBan<Lo, Hi>): Count {
154
- if (lo < 0n || hi < 0n) {
155
- throw errors.new(`window counts are u64: between(${lo}, ${hi}) is out of domain`)
156
- }
157
- if (hi < lo) {
158
- throw errors.new(
159
- `the window \`{${lo}..${hi}}\` is inverted — no count satisfies it; bounds are \`{lo..hi}\` with lo < hi (an exact count is \`{n}\`: exactly(n))`
160
- )
161
- }
162
- if (lo === hi) {
163
- if (lo === 0n) {
164
- throw errors.new("`{0..0}` — the exclusion is written `{0}`: use none")
165
- }
166
- throw errors.new(`\`{${lo}..${lo}}\` — an exact count is written \`{${lo}}\`: use exactly(${lo})`)
167
- }
168
- if (lo === 0n) {
169
- throw errors.new(`\`{0..${hi}}\` — a ceiling is written atMost: use atMost(${hi})`)
170
- }
171
- return admit(Object.freeze({ kind: "range", lo, hi }))
172
- }
173
-
174
- /**
175
- * `{lo..*}` — a floor with no ceiling, lo ≥ 2: `atLeast(1)` says only what
176
- * the bare containment says and `atLeast(0)` is vacuous — both unwritable
177
- * as literals ({@link AtLeastBan} names the canonical form), rejected at
178
- * construction when computed.
179
- */
180
- function atLeast<const N extends bigint>(lo: N & AtLeastBan<N>): Count {
181
- if (lo < 0n) {
182
- throw errors.new(`window counts are u64: atLeast(${lo}) is out of domain`)
183
- }
184
- if (lo === 0n) {
185
- throw errors.new("the `{0..*}` window is vacuous — it provably says nothing; delete the statement")
186
- }
187
- if (lo === 1n) {
188
- throw errors.new(
189
- "`{1..*}` says only what the bare containment says — drop the annotation and write the containment: contained(source, target)"
190
- )
191
- }
192
- return admit(Object.freeze({ kind: "floor", lo }))
193
- }
194
-
195
- /**
196
- * `{0..hi}` — a ceiling, hi ≥ 1: `atMost(0)` is the exclusion respelled —
197
- * unwritable as a literal ({@link AtMostBan} names `none`), rejected at
198
- * construction when computed.
199
- */
200
- function atMost<const N extends bigint>(hi: N & AtMostBan<N>): Count {
201
- if (hi < 0n) {
202
- throw errors.new(`window counts are u64: atMost(${hi}) is out of domain`)
203
- }
204
- if (hi === 0n) {
205
- throw errors.new("`{0..0}` — the exclusion is written `{0}`: use none")
206
- }
207
- return admit(Object.freeze({ kind: "range", lo: 0n, hi }))
208
- }
209
-
210
- export type { Count }
211
- export { atLeast, atMost, between, exactly, none }