@bjornpagen/bumbledb 0.20.2 → 1.0.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 (192) hide show
  1. package/COOKBOOK.md +283 -1611
  2. package/README.md +156 -118
  3. package/dist/capacity.d.ts +16 -12
  4. package/dist/capacity.d.ts.map +1 -1
  5. package/dist/capacity.js +16 -48
  6. package/dist/capacity.js.map +1 -1
  7. package/dist/changes.d.ts +54 -0
  8. package/dist/changes.d.ts.map +1 -0
  9. package/dist/changes.js +245 -0
  10. package/dist/changes.js.map +1 -0
  11. package/dist/close.d.ts +24 -0
  12. package/dist/close.d.ts.map +1 -0
  13. package/dist/close.js +34 -0
  14. package/dist/close.js.map +1 -0
  15. package/dist/closed.d.ts +1 -3
  16. package/dist/closed.d.ts.map +1 -1
  17. package/dist/closed.js +24 -12
  18. package/dist/closed.js.map +1 -1
  19. package/dist/codec.d.ts +56 -0
  20. package/dist/codec.d.ts.map +1 -0
  21. package/dist/codec.js +289 -0
  22. package/dist/codec.js.map +1 -0
  23. package/dist/compile.d.ts +68 -0
  24. package/dist/compile.d.ts.map +1 -0
  25. package/dist/compile.js +75 -0
  26. package/dist/compile.js.map +1 -0
  27. package/dist/db-native.d.ts +170 -0
  28. package/dist/db-native.d.ts.map +1 -0
  29. package/dist/db-native.js +5 -0
  30. package/dist/db-native.js.map +1 -0
  31. package/dist/db.d.ts +101 -233
  32. package/dist/db.d.ts.map +1 -1
  33. package/dist/db.js +232 -1084
  34. package/dist/db.js.map +1 -1
  35. package/dist/errors.d.ts +57 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +32 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/face.d.ts.map +1 -1
  40. package/dist/face.js +2 -2
  41. package/dist/face.js.map +1 -1
  42. package/dist/fields.d.ts +65 -24
  43. package/dist/fields.d.ts.map +1 -1
  44. package/dist/fields.js +94 -24
  45. package/dist/fields.js.map +1 -1
  46. package/dist/index.d.ts +37 -32
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +17 -21
  49. package/dist/index.js.map +1 -1
  50. package/dist/internal/log.d.ts +24 -0
  51. package/dist/internal/log.d.ts.map +1 -0
  52. package/dist/internal/log.js +10 -0
  53. package/dist/internal/log.js.map +1 -0
  54. package/dist/law.d.ts +8 -13
  55. package/dist/law.d.ts.map +1 -1
  56. package/dist/law.js +6 -59
  57. package/dist/law.js.map +1 -1
  58. package/dist/lower.d.ts +0 -13
  59. package/dist/lower.d.ts.map +1 -1
  60. package/dist/lower.js +9 -17
  61. package/dist/lower.js.map +1 -1
  62. package/dist/migration.d.ts +33 -0
  63. package/dist/migration.d.ts.map +1 -0
  64. package/dist/migration.js +48 -0
  65. package/dist/migration.js.map +1 -0
  66. package/dist/native.d.ts +256 -301
  67. package/dist/native.d.ts.map +1 -1
  68. package/dist/native.js +65 -108
  69. package/dist/native.js.map +1 -1
  70. package/dist/query/atom.d.ts +24 -13
  71. package/dist/query/atom.d.ts.map +1 -1
  72. package/dist/query/atom.js +7 -3
  73. package/dist/query/atom.js.map +1 -1
  74. package/dist/query/compute.d.ts +68 -0
  75. package/dist/query/compute.d.ts.map +1 -0
  76. package/dist/query/compute.js +141 -0
  77. package/dist/query/compute.js.map +1 -0
  78. package/dist/query/find.d.ts +15 -8
  79. package/dist/query/find.d.ts.map +1 -1
  80. package/dist/query/find.js +6 -2
  81. package/dist/query/find.js.map +1 -1
  82. package/dist/query/lower.d.ts +23 -2
  83. package/dist/query/lower.d.ts.map +1 -1
  84. package/dist/query/lower.js +433 -80
  85. package/dist/query/lower.js.map +1 -1
  86. package/dist/query/parse-ir.d.ts.map +1 -1
  87. package/dist/query/parse-ir.js +17 -8
  88. package/dist/query/parse-ir.js.map +1 -1
  89. package/dist/query/run.d.ts +12 -2
  90. package/dist/query/run.d.ts.map +1 -1
  91. package/dist/query/run.js +26 -9
  92. package/dist/query/run.js.map +1 -1
  93. package/dist/query/scope.d.ts +47 -3
  94. package/dist/query/scope.d.ts.map +1 -1
  95. package/dist/query/scope.js +83 -19
  96. package/dist/query/scope.js.map +1 -1
  97. package/dist/relation.d.ts +3 -8
  98. package/dist/relation.d.ts.map +1 -1
  99. package/dist/relation.js +16 -10
  100. package/dist/relation.js.map +1 -1
  101. package/dist/result.d.ts +47 -0
  102. package/dist/result.d.ts.map +1 -0
  103. package/dist/result.js +50 -0
  104. package/dist/result.js.map +1 -0
  105. package/dist/rows.d.ts +69 -0
  106. package/dist/rows.d.ts.map +1 -0
  107. package/dist/rows.js +328 -0
  108. package/dist/rows.js.map +1 -0
  109. package/dist/runtime-codes.d.ts +2 -0
  110. package/dist/runtime-codes.d.ts.map +1 -0
  111. package/dist/runtime-codes.js +19 -0
  112. package/dist/runtime-codes.js.map +1 -0
  113. package/dist/runtime-errors.d.ts +106 -0
  114. package/dist/runtime-errors.d.ts.map +1 -0
  115. package/dist/runtime-errors.js +62 -0
  116. package/dist/runtime-errors.js.map +1 -0
  117. package/dist/runtime-native.d.ts +171 -0
  118. package/dist/runtime-native.d.ts.map +1 -0
  119. package/dist/runtime-native.js +5 -0
  120. package/dist/runtime-native.js.map +1 -0
  121. package/dist/runtime.d.ts +73 -0
  122. package/dist/runtime.d.ts.map +1 -0
  123. package/dist/runtime.js +293 -0
  124. package/dist/runtime.js.map +1 -0
  125. package/dist/scalar.d.ts +165 -0
  126. package/dist/scalar.d.ts.map +1 -0
  127. package/dist/scalar.js +344 -0
  128. package/dist/scalar.js.map +1 -0
  129. package/dist/schema.d.ts +1 -1
  130. package/dist/schema.d.ts.map +1 -1
  131. package/dist/schema.js +34 -37
  132. package/dist/schema.js.map +1 -1
  133. package/dist/shape.d.ts +28 -0
  134. package/dist/shape.d.ts.map +1 -0
  135. package/dist/shape.js +2 -0
  136. package/dist/shape.js.map +1 -0
  137. package/dist/spec.d.ts +27 -3
  138. package/dist/spec.d.ts.map +1 -1
  139. package/dist/spec.js +22 -1
  140. package/dist/spec.js.map +1 -1
  141. package/dist/statements.d.ts +16 -3
  142. package/dist/statements.d.ts.map +1 -1
  143. package/dist/statements.js +54 -28
  144. package/dist/statements.js.map +1 -1
  145. package/dist/uuid.d.ts +23 -0
  146. package/dist/uuid.d.ts.map +1 -0
  147. package/dist/uuid.js +54 -0
  148. package/dist/uuid.js.map +1 -0
  149. package/pack-provenance.json +7 -0
  150. package/package.json +12 -16
  151. package/src/capacity.ts +34 -54
  152. package/src/changes.ts +361 -0
  153. package/src/close.ts +53 -0
  154. package/src/closed.ts +25 -19
  155. package/src/codec.ts +379 -0
  156. package/src/compile.ts +149 -0
  157. package/src/db-native.ts +247 -0
  158. package/src/db.ts +461 -1632
  159. package/src/errors.ts +50 -0
  160. package/src/face.ts +2 -2
  161. package/src/fields.ts +182 -55
  162. package/src/index.ts +62 -126
  163. package/src/internal/log.ts +51 -0
  164. package/src/law.ts +13 -28
  165. package/src/lower.ts +9 -4
  166. package/src/migration.ts +69 -0
  167. package/src/native.ts +326 -487
  168. package/src/query/atom.ts +61 -25
  169. package/src/query/compute.ts +237 -0
  170. package/src/query/find.ts +31 -12
  171. package/src/query/lower.ts +531 -143
  172. package/src/query/parse-ir.ts +18 -13
  173. package/src/query/run.ts +32 -16
  174. package/src/query/scope.ts +140 -8
  175. package/src/relation.ts +17 -21
  176. package/src/result.ts +130 -0
  177. package/src/rows.ts +404 -0
  178. package/src/runtime-codes.ts +18 -0
  179. package/src/runtime-errors.ts +69 -0
  180. package/src/runtime-native.ts +242 -0
  181. package/src/runtime.ts +440 -0
  182. package/src/scalar.ts +560 -0
  183. package/src/schema.ts +35 -37
  184. package/src/shape.ts +31 -0
  185. package/src/spec.ts +33 -3
  186. package/src/statements.ts +75 -68
  187. package/src/uuid.ts +69 -0
  188. package/dist/marshal.d.ts +0 -44
  189. package/dist/marshal.d.ts.map +0 -1
  190. package/dist/marshal.js +0 -165
  191. package/dist/marshal.js.map +0 -1
  192. package/src/marshal.ts +0 -200
package/src/index.ts CHANGED
@@ -1,20 +1,9 @@
1
1
  /**
2
- * @bjornpagen/bumbledb — the type-theoretic TypeScript SDK for the
3
- * bumbledb embedded relational engine. Public surface: the structural type
4
- * kernel (fields as pure structure, `relation`, `closed` — domains are
5
- * never declared: THE LAWS TYPE THE COLUMNS, `schema` computing every
6
- * field's equivalence class FROM the statement list at both tiers), the
7
- * statement algebra with `schema` and `SchemaSpec` lowering (PRD-06), the `Db`
8
- * runtime (exclusive-lock stores, transactions, typed violations, callback
9
- * instance reads, one-shot `write`/`writeFrom` with `abandon` — PRD-07), the query surface (kysely-shaped:
10
- * `query(S).rule(r => { const { id, name } = v(Holder); return r.match(Holder, { id, name }).find({ name }) })` —
11
- * variables minted by `v` and joined by OBJECT REFERENCE (reuse is the
12
- * join), the head a `find` RECORD whose keys name the answer columns
13
- * (renames are real), params still STRING-named, plus negation,
14
- * conditions, aggregates, and interiors / one linear rec via
15
- * `q.interior` / `q.reach` —
16
- * `db.prepare` as a plain value; comparisons and connectives live on
17
- * the rule scope). The raw native bridge is not exported.
2
+ * @bjornpagen/bumbledb — the Effect-native TypeScript SDK for the
3
+ * bumbledb embedded relational engine (chapter 35 surface). Pure
4
+ * schema/query/scalar construction is synchronous metadata; all work is
5
+ * lazy, scoped and bounded on the one native runtime. No Promise, sync,
6
+ * or disposal twin. The raw native bridge is not exported from this barrel.
18
7
  */
19
8
 
20
9
  export type {
@@ -23,10 +12,12 @@ export type {
23
12
  CapacityWindow,
24
13
  DurationRef,
25
14
  FieldRef,
26
- UnitWindowBan,
15
+ UnitDimensionBan,
27
16
  WeightOnSource
28
17
  } from "#capacity.ts"
29
18
  export { duration, ref, weigh, within } from "#capacity.ts"
19
+ export type { ChangeDraft } from "#changes.ts"
20
+ export { ChangeSet } from "#changes.ts"
30
21
  export type {
31
22
  AnyClosed,
32
23
  AnySelectedClosed,
@@ -42,47 +33,28 @@ export type {
42
33
  SelectedClosed
43
34
  } from "#closed.ts"
44
35
  export { closed } from "#closed.ts"
36
+ export type { RowShape } from "#codec.ts"
37
+ export { decodeBoundaryRows, decodeRows, encodeBoundaryRows, encodeRows, rowSchema, rowShape } from "#codec.ts"
38
+ export type { CompiledSchema, SchemaId } from "#compile.ts"
39
+ export { Schema } from "#compile.ts"
45
40
  export type {
46
- Abandon,
47
- AbandonedArm,
48
- Admission,
49
- CapacityViolation,
50
- CollectionWrite,
51
- Committed,
52
- ContainmentViolation,
53
- DeclaredKeyFact,
54
- DeclaredKeyViolation,
55
- DeltaBuild,
56
- FreshRange,
57
- ImpliedKeyViolation,
58
- MemberRelation,
59
- MirrorViolation,
60
- MutationReport,
61
- OffendingFact,
62
- OwnedInstance,
63
- Prepared,
64
- ReadInstance,
65
- SyncResult,
66
- Violation,
67
- Witness,
68
- WriteFromOutcome,
69
- WriteOutcome,
70
- WriteTx
41
+ ApplyExpected,
42
+ ApplyOptions,
43
+ ApplyOutcome,
44
+ CoreWitness,
45
+ DbInspection,
46
+ ExecutionSession,
47
+ QueryReader,
48
+ Snapshot
71
49
  } from "#db.ts"
50
+ export { Db } from "#db.ts"
72
51
  export {
73
- abandon,
74
- Db,
75
- ErrAsyncCallback,
76
- ErrFingerprintMismatch,
77
- ErrForeignPrepared,
78
- ErrForeignWitness,
79
- ErrIrError,
80
- ErrNewtypeMismatch,
81
- ErrSchemaError,
82
- ErrSpentHandle,
83
- ErrUseAfterScope,
84
- InstanceBuilder
85
- } from "#db.ts"
52
+ AuthoringError,
53
+ NativeLoadError,
54
+ NativeOperationError,
55
+ NativeReportedError,
56
+ SdkInvariantError
57
+ } from "#errors.ts"
86
58
  export type {
87
59
  AnyFace,
88
60
  Arity,
@@ -109,83 +81,27 @@ export type {
109
81
  ClosedHandleTuple,
110
82
  ClosedIdField,
111
83
  ClosedRoster,
112
- FreshU64Field,
84
+ F64Field,
85
+ FloatIntervalValue,
113
86
  I64Field,
114
87
  Infer,
88
+ IntervalElementKind,
115
89
  IntervalField,
116
90
  IntervalValue,
117
91
  SignatureOf,
118
92
  StrField,
119
- U64Field
93
+ U64Field,
94
+ UuidField
120
95
  } from "#fields.ts"
121
- export { bool, bytes, i64, interval, span, str, u64 } from "#fields.ts"
96
+ export { bool, bytes, f64, i64, interval, span, str, u64, uuid } from "#fields.ts"
122
97
  export type { Same, SameLen } from "#judgment.ts"
123
98
  export type { ClassesOf, ClassWall, LawfulStatements, RelationClasses, SchemaClasses } from "#law.ts"
124
- export { lower } from "#lower.ts"
125
- export type { KeyFact } from "#marshal.ts"
126
- export { factOf, rowOf } from "#marshal.ts"
127
- export type {
128
- FactValue,
129
- LogBatch,
130
- LogBatchDecodeKind,
131
- LogBatchEncodeKind,
132
- LogBatchHeader,
133
- LogBraidComponent,
134
- LogBraids,
135
- LogChain,
136
- LogChainEntry,
137
- LogCheckpointDoc,
138
- LogCheckpointHead,
139
- LogCheckpointKind,
140
- LogCodecHandle,
141
- LogManifestDoc,
142
- LogManifestKind,
143
- LogOpIn,
144
- LogOpKind,
145
- LogOpOut,
146
- LogPendingBatch,
147
- LogResult,
148
- LogSidecarKind,
149
- ParsedQuery,
150
- QueryIr,
151
- SealedDescriptor,
152
- SealedHi,
153
- SealedSide,
154
- SealedStatement,
155
- SealedWeight,
156
- StatementKindTag
157
- } from "#native.ts"
158
- export {
159
- internalBlake3,
160
- internalDescriptor,
161
- internalLogBraidsOf,
162
- internalLogCodec,
163
- internalLogDecodeBatch,
164
- internalLogEncodeBatch,
165
- internalLogParseCheckpoint,
166
- internalLogParseCkptScratch,
167
- internalLogParseManifest,
168
- internalLogParseSidecar,
169
- internalLogRenderCheckpoint,
170
- internalLogRenderCkptScratch,
171
- internalLogRenderManifest,
172
- internalLogRenderSidecar
173
- } from "#native.ts"
174
-
175
- export type {
176
- AnyCond,
177
- BindingInput,
178
- Cmp,
179
- FindColumn,
180
- InteriorData,
181
- MatchShape,
182
- NotAtom,
183
- RecData,
184
- RuleData,
185
- Tree
186
- } from "#query/atom.ts"
99
+ export type { Violation, ViolationFact } from "#native.ts"
100
+ export type { FindColumn } from "#query/atom.ts"
187
101
  export { ALLEN } from "#query/atom.ts"
188
- export type { Agg, FindEntry } from "#query/find.ts"
102
+ export type { AnyComputeExpr, ComputeExpr, ComputeValue, QueryNode } from "#query/compute.ts"
103
+ export { Compute } from "#query/compute.ts"
104
+ export type { Agg, RowOfFind } from "#query/find.ts"
189
105
  export type {
190
106
  AnyQuery,
191
107
  AnyRuleValue,
@@ -206,6 +122,7 @@ export type {
206
122
  export { lowerQuery, query } from "#query/lower.ts"
207
123
  export type {
208
124
  ClassedField,
125
+ Flatten,
209
126
  MatchFields,
210
127
  MatchOwner,
211
128
  Param,
@@ -221,7 +138,6 @@ export type {
221
138
  AnySelected,
222
139
  Fact,
223
140
  FieldsShape,
224
- FreshKeys,
225
141
  Relation,
226
142
  RelationData,
227
143
  RelationField,
@@ -231,8 +147,28 @@ export type {
231
147
  SelectionInput
232
148
  } from "#relation.ts"
233
149
  export { relation } from "#relation.ts"
234
- export type { AnySchema, Schema, SchemaRelation, SchemaRelations } from "#schema.ts"
150
+ export type { CompleteResult } from "#result.ts"
151
+ export type { CellValue } from "#rows.ts"
152
+ export { cellBytes, cellOf, factOfCells, flatRowsOf, keyCellsOf } from "#rows.ts"
153
+ export type { ExecutionPolicy, NativeRuntimeOptions } from "#runtime.ts"
154
+ export { NativeRuntime } from "#runtime.ts"
155
+ export type { CloseReport, OutstandingWork } from "#runtime-errors.ts"
156
+ export { CloseFailure, DbError, dbError, runtimeErrorCodes } from "#runtime-errors.ts"
157
+ export type {
158
+ NumericCast,
159
+ ScalarExpr,
160
+ ScalarFieldRef,
161
+ ScalarKind,
162
+ ScalarLeafScope,
163
+ ScalarLiteral,
164
+ ScalarNode,
165
+ ScalarResultKind,
166
+ ScalarValue
167
+ } from "#scalar.ts"
168
+ export { Scalar } from "#scalar.ts"
169
+ export type { AnySchema, Schema as SchemaDeclaration, SchemaRelation, SchemaRelations } from "#schema.ts"
235
170
  export { schema } from "#schema.ts"
171
+ export type { Key, QueryTemplate, Rel } from "#shape.ts"
236
172
  export type {
237
173
  CapacityBoundSpec,
238
174
  CapacityWindowSpec,
@@ -245,8 +181,7 @@ export type {
245
181
  SideSpec,
246
182
  StatementSpec,
247
183
  ValueSpec,
248
- ValueTypeSpec,
249
- WeightSpec
184
+ ValueTypeSpec
250
185
  } from "#spec.ts"
251
186
  export type {
252
187
  CapacityData,
@@ -259,3 +194,4 @@ export type {
259
194
  StatementData
260
195
  } from "#statements.ts"
261
196
  export { capacity, contained, key, mirrors, renderStatement } from "#statements.ts"
197
+ export { Uuid } from "#uuid.ts"
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @bjornpagen/bumbledb/internal/log — the exact-version cross-package seam
3
+ * consumed by `@bjornpagen/bumbledb-log`. Unsupported application surface;
4
+ * not a security boundary. Native kind/runtime/owner/state validation remains
5
+ * mandatory on every verb. Real types are shipped; this is not stripInternal.
6
+ */
7
+ export type { ChangeDraft } from "#changes.ts"
8
+ export { ChangeSet, internalChanges } from "#changes.ts"
9
+ export type { CompiledSchema, SchemaId } from "#compile.ts"
10
+ export { Schema } from "#compile.ts"
11
+ export type { ExecutionSession, QueryReader } from "#db.ts"
12
+ export { Db, internalPublishedReader } from "#db.ts"
13
+ export type { SnapshotHandle } from "#db-native.ts"
14
+ export { lower } from "#lower.ts"
15
+ export { internalMigrationRead, internalMigrationSchema } from "#migration.ts"
16
+ export {
17
+ internalBlake3,
18
+ internalDescriptor,
19
+ internalLogIdentities,
20
+ internalLogSchema,
21
+ nativeBindingIsLoaded
22
+ } from "#native.ts"
23
+ export type { CompleteResult } from "#result.ts"
24
+ export type { ExecutionPolicy, NativeRuntimeOptions, RepositoryLock } from "#runtime.ts"
25
+ export {
26
+ deliveryResultBytes,
27
+ finalizeClose,
28
+ hashChunk,
29
+ internalAcquireRepositoryLock,
30
+ NativeRuntime,
31
+ nativeOperation,
32
+ nativeOperationWith,
33
+ policyWire,
34
+ runtimeHandle
35
+ } from "#runtime.ts"
36
+ export type { CloseReport, OutstandingWork } from "#runtime-errors.ts"
37
+ export { CloseFailure, DbError, dbError, runtimeErrorCodes } from "#runtime-errors.ts"
38
+ export type {
39
+ Capability,
40
+ CloseDrain,
41
+ CloseWire,
42
+ DirectoryHandle,
43
+ InspectionWire,
44
+ NativeKind,
45
+ OperationHandle,
46
+ PolicyWire,
47
+ RepositoryLockHandle,
48
+ ResourceHeader,
49
+ RuntimeHandle
50
+ } from "#runtime-native.ts"
51
+ export { runtimeNative } from "#runtime-native.ts"
package/src/law.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AuthoringError } from "#errors.ts"
1
2
  /**
2
3
  * The law-typing engine (owner ruling 2026-07-18, "option 2, zero debate"):
3
4
  * THE LAWS TYPE THE COLUMNS. Domains are declared nowhere — `schema`
@@ -8,9 +9,10 @@
8
9
  *
9
10
  * The three class laws (ratified; implemented exactly):
10
11
  *
11
- * 1. GENERATORS — a `fresh` field is a generator and names its class by
12
- * its declaration coordinate (`"Account.id"`); a closed relation's
13
- * synthetic id is a generator named `"Kind.id"`.
12
+ * 1. GENERATORS — a closed relation's synthetic id is a generator named
13
+ * `"Kind.id"` (the vocabulary mints its own row ids). Ordinary relations
14
+ * have no generator: the database issues no identity (`fresh` is deleted),
15
+ * and identity fields are ordinary application-owned values.
14
16
  * 2. GENERATOR-LESS classes are named by their least member coordinate
15
17
  * in relation-declaration × field-declaration order (readable off the
16
18
  * relation record and each member's frozen field list at the VALUE
@@ -54,7 +56,6 @@
54
56
  * silently widened.
55
57
  */
56
58
 
57
- import * as errors from "@superbuilders/errors"
58
59
  import type { AnyClosed } from "#closed.ts"
59
60
  import { isClosedMember, sealedFieldsOf } from "#closed.ts"
60
61
  import type { FaceData } from "#face.ts"
@@ -81,15 +82,7 @@ type MemberFieldNames<M extends SchemaRelation> = M extends AnyClosed
81
82
  ? keyof RelationFields<M> & string
82
83
  : never
83
84
 
84
- type FreshFieldNames<Fields> = {
85
- [F in keyof Fields & string]: Fields[F] extends { readonly fresh: true } ? F : never
86
- }[keyof Fields & string]
87
-
88
- type MemberGenerators<N extends string, M extends SchemaRelation> = M extends AnyClosed
89
- ? `${N}.id`
90
- : M extends AnyRelation
91
- ? `${N}.${FreshFieldNames<RelationFields<M>>}`
92
- : never
85
+ type MemberGenerators<N extends string, M extends SchemaRelation> = M extends AnyClosed ? `${N}.id` : never
93
86
 
94
87
  type GeneratorsOf<Rels extends SchemaRelations> = {
95
88
  [N in keyof Rels & string]: MemberGenerators<N, Rels[N]>
@@ -204,7 +197,7 @@ type KeyEntry = readonly [string, string]
204
197
  /**
205
198
  * Every declared `key` of a statements tuple as {@link KeyEntry} rows —
206
199
  * the declared half of the target-key roster (the implied half is read off
207
- * each target face's own relation value: fresh marks, closed ids). A
200
+ * each target face's own relation value: closed ids). A
208
201
  * statement-tuple union or any undecidable key element degrades the WHOLE
209
202
  * wall to silent before this roster is ever consulted
210
203
  * ({@link DecidableRoster}) — the skip arm here is the same judgment
@@ -329,12 +322,6 @@ type DeclaredKeyMatch<N extends string, PU extends string, Keys extends readonly
329
322
  : DeclaredKeyMatch<N, PU, T>
330
323
  : TargetKeyWall<N, PU>
331
324
 
332
- type FreshKeyMatch<PU extends string, O extends AnyRelation> = [PU] extends [FreshFieldNames<RelationFields<O>>]
333
- ? true extends IsMulti<PU>
334
- ? false
335
- : true
336
- : false
337
-
338
325
  type JudgeTargetFace<F extends FaceData, Keys extends readonly KeyEntry[]> = string extends F["owner"]["name"]
339
326
  ? true
340
327
  : string extends F["projection"][number]
@@ -344,9 +331,7 @@ type JudgeTargetFace<F extends FaceData, Keys extends readonly KeyEntry[]> = str
344
331
  ? true
345
332
  : TargetKeyWall<F["owner"]["name"], F["projection"][number]>
346
333
  : F["owner"] extends AnyRelation
347
- ? FreshKeyMatch<F["projection"][number], F["owner"]> extends true
348
- ? true
349
- : DeclaredKeyMatch<F["owner"]["name"], F["projection"][number], Keys>
334
+ ? DeclaredKeyMatch<F["owner"]["name"], F["projection"][number], Keys>
350
335
  : true
351
336
 
352
337
  type JudgeStatement<St extends Statement, Keys extends readonly KeyEntry[]> = St["data"] extends {
@@ -410,7 +395,7 @@ function memberCoords(relations: SchemaRelations): MemberCoords[] {
410
395
  const fields = sealedFieldsOf(member).map(function fieldCoord(declared) {
411
396
  return {
412
397
  name: declared.name,
413
- generator: closed ? declared.name === "id" : "fresh" in declared.field && declared.field.fresh === true
398
+ generator: closed && declared.name === "id"
414
399
  }
415
400
  })
416
401
  out.push({ relation: relationName, fields })
@@ -478,7 +463,7 @@ function statementFaces(statement: Statement): readonly [FaceData, FaceData] | u
478
463
  /**
479
464
  * Computes the class map — the runtime twin of {@link ClassesOf}, the SAME
480
465
  * computation as a plain union-find: every paired face's positionwise slot
481
- * pairs union their coordinates; a fresh field or closed id is a generator
466
+ * pairs union their coordinates; a closed id is a generator
482
467
  * naming its class; a generator-less class is named by its least member in
483
468
  * relation-declaration × field-declaration order; a slot in no law is bare
484
469
  * (`undefined`). The one-generator wall throws HERE, naming the two
@@ -520,9 +505,9 @@ function computeClasses(name: string, relations: SchemaRelations, statements: re
520
505
  const root = uf.union(coordA, coordB)
521
506
  const gens = uf.generatorsOf(root)
522
507
  if (gens.length > 1) {
523
- throw errors.new(
524
- `schema ${name}: the statements unify two generators into one class — ${gens.join(" and ")} (two mints cannot share a carrier) — ${renderStatement(statement)}`
525
- )
508
+ throw new AuthoringError({
509
+ message: `schema ${name}: the statements unify two generators into one class — ${gens.join(" and ")} (two mints cannot share a carrier) — ${renderStatement(statement)}`
510
+ })
526
511
  }
527
512
  })
528
513
  }
package/src/lower.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AuthoringError } from "#errors.ts"
1
2
  /**
2
3
  * Descriptor lowering: SDK values down to the PRD-01 `SchemaSpec` plain
3
4
  * data (`#spec.ts`), which the napi bridge marshals verbatim. Lowering is
@@ -12,7 +13,6 @@
12
13
  * so serialization is deterministic (byte-stable).
13
14
  */
14
15
 
15
- import * as errors from "@superbuilders/errors"
16
16
  import type { AnyClosed } from "#closed.ts"
17
17
  import { isClosedMember } from "#closed.ts"
18
18
  import type { FaceData } from "#face.ts"
@@ -39,6 +39,10 @@ function valueTypeOf(field: AnyField): ValueTypeSpec {
39
39
  return { kind: "u64" }
40
40
  case "i64":
41
41
  return { kind: "i64" }
42
+ case "f64":
43
+ return { kind: "f64" }
44
+ case "uuid":
45
+ return { kind: "uuid" }
42
46
  case "str":
43
47
  return { kind: "string" }
44
48
  case "bytes":
@@ -52,8 +56,7 @@ function lowerField(name: string, field: AnyField, newtype: string | undefined):
52
56
  return {
53
57
  name,
54
58
  valueType: valueTypeOf(field),
55
- newtype,
56
- fresh: "fresh" in field && field.fresh === true
59
+ newtype
57
60
  }
58
61
  }
59
62
 
@@ -113,7 +116,9 @@ function lowerClosed(member: AnyClosed, classes: RelationClasses): RelationSpec
113
116
  })
114
117
  const newtype = classes.id
115
118
  if (newtype === undefined) {
116
- throw errors.new(`closed relation ${member.name}: the id's generator class is missing from the class map`)
119
+ throw new AuthoringError({
120
+ message: `closed relation ${member.name}: the id's generator class is missing from the class map`
121
+ })
117
122
  }
118
123
  return { name: member.name, fields, closed: { newtype, rows } }
119
124
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Private log-migration integration entrypoints (C11): the two read-only
3
+ * native migration-codec verbs the `@bjornpagen/bumbledb-log/migrations`
4
+ * generator consumes literally (recorded contract in
5
+ * implementation/packets/P10.md), wired over the P06 executor onto P09's
6
+ * native `schema_file`/`migration::plan`/`migration::manifest` lanes.
7
+ *
8
+ * Both follow `hashChunk`'s shape: bounded owned input, bounded owned JSON
9
+ * response bytes, ONE registered cancellable operation under the acquired
10
+ * `NativeRuntime`. The schema verb takes the SDK `SchemaSpec` object — the
11
+ * same wire that already crosses the bridge for open/create — never a
12
+ * respelled text form. Neither verb opens, initializes, freezes or migrates
13
+ * a database; the durable migrate/activate/abort workflow is the log's
14
+ * admin surface, not this seam.
15
+ */
16
+ import { Effect } from "effect"
17
+ import { dbNative } from "#db-native.ts"
18
+ import type { ExecutionPolicy } from "#runtime.ts"
19
+ import { nativeOperationWith, policyWire, runtimeHandle } from "#runtime.ts"
20
+ import { DbError, dbError } from "#runtime-errors.ts"
21
+ import type { SchemaSpec } from "#spec.ts"
22
+
23
+ function owned(operation: string, value: Uint8Array | null): Uint8Array {
24
+ if (value === null) {
25
+ throw dbError(operation, { _tag: "Internal" })
26
+ }
27
+ return value
28
+ }
29
+
30
+ /**
31
+ * Canonical schema admission for the migration generator: validates the
32
+ * spec natively and yields bounded JSON bytes carrying the canonical
33
+ * `schemaId` and the rendered schema snapshot.
34
+ */
35
+ const internalMigrationSchema = Effect.fn("internalMigrationSchema")(function* (
36
+ spec: SchemaSpec,
37
+ work: ExecutionPolicy
38
+ ) {
39
+ const runtime = yield* runtimeHandle()
40
+ return yield* nativeOperationWith(
41
+ "internalMigrationSchema",
42
+ (callback) => dbNative.runtimeMigrationSchema(runtime, policyWire(work, "internalMigrationSchema"), spec, callback),
43
+ dbNative.runtimeBytesTake,
44
+ (bytes) => owned("internalMigrationSchema", bytes)
45
+ )
46
+ })
47
+
48
+ /**
49
+ * One bounded read-only migration-codec request (plan parse/validate/
50
+ * render/digest, manifest verify/append preview, plan-set digests): owned
51
+ * JSON request bytes in, owned JSON response bytes out.
52
+ */
53
+ const internalMigrationRead = Effect.fn("internalMigrationRead")(function* (
54
+ request: Uint8Array,
55
+ work: ExecutionPolicy
56
+ ) {
57
+ if (!(request instanceof Uint8Array) || !(request.buffer instanceof ArrayBuffer)) {
58
+ return yield* Effect.fail(new DbError({ operation: "internalMigrationRead", reason: { _tag: "InvalidArgument" } }))
59
+ }
60
+ const runtime = yield* runtimeHandle()
61
+ return yield* nativeOperationWith(
62
+ "internalMigrationRead",
63
+ (callback) => dbNative.runtimeMigrationRead(runtime, policyWire(work, "internalMigrationRead"), request, callback),
64
+ dbNative.runtimeBytesTake,
65
+ (bytes) => owned("internalMigrationRead", bytes)
66
+ )
67
+ })
68
+
69
+ export { internalMigrationRead, internalMigrationSchema }