@bjornpagen/bumbledb 1.3.0 → 2.0.0-rc.1

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 (290) hide show
  1. package/COOKBOOK.md +224 -95
  2. package/README.md +114 -45
  3. package/dist/alternatives.d.ts +5 -6
  4. package/dist/alternatives.d.ts.map +1 -1
  5. package/dist/alternatives.js +5 -6
  6. package/dist/alternatives.js.map +1 -1
  7. package/dist/bin.d.ts +3 -0
  8. package/dist/bin.d.ts.map +1 -0
  9. package/dist/bin.js +85 -0
  10. package/dist/bin.js.map +1 -0
  11. package/dist/capacity.d.ts +14 -17
  12. package/dist/capacity.d.ts.map +1 -1
  13. package/dist/capacity.js +7 -7
  14. package/dist/capacity.js.map +1 -1
  15. package/dist/changes.d.ts +32 -41
  16. package/dist/changes.d.ts.map +1 -1
  17. package/dist/changes.js +86 -110
  18. package/dist/changes.js.map +1 -1
  19. package/dist/closed.d.ts +2 -2
  20. package/dist/closed.d.ts.map +1 -1
  21. package/dist/closed.js +5 -5
  22. package/dist/closed.js.map +1 -1
  23. package/dist/codec.d.ts +20 -27
  24. package/dist/codec.d.ts.map +1 -1
  25. package/dist/codec.js +48 -22
  26. package/dist/codec.js.map +1 -1
  27. package/dist/compile.d.ts +26 -50
  28. package/dist/compile.d.ts.map +1 -1
  29. package/dist/compile.js +75 -64
  30. package/dist/compile.js.map +1 -1
  31. package/dist/database/database.d.ts +98 -0
  32. package/dist/database/database.d.ts.map +1 -0
  33. package/dist/database/database.js +249 -0
  34. package/dist/database/database.js.map +1 -0
  35. package/dist/database/driver.d.ts +40 -0
  36. package/dist/database/driver.d.ts.map +1 -0
  37. package/dist/database/driver.js +68 -0
  38. package/dist/database/driver.js.map +1 -0
  39. package/dist/database/fs.d.ts +12 -0
  40. package/dist/database/fs.d.ts.map +1 -0
  41. package/dist/database/fs.js +120 -0
  42. package/dist/database/fs.js.map +1 -0
  43. package/dist/database/generate.d.ts +26 -0
  44. package/dist/database/generate.d.ts.map +1 -0
  45. package/dist/database/generate.js +102 -0
  46. package/dist/database/generate.js.map +1 -0
  47. package/dist/database/hosted.d.ts +32 -0
  48. package/dist/database/hosted.d.ts.map +1 -0
  49. package/dist/database/hosted.js +44 -0
  50. package/dist/database/hosted.js.map +1 -0
  51. package/dist/database/io.d.ts +94 -0
  52. package/dist/database/io.d.ts.map +1 -0
  53. package/dist/database/io.js +35 -0
  54. package/dist/database/io.js.map +1 -0
  55. package/dist/database/mem.d.ts +26 -0
  56. package/dist/database/mem.d.ts.map +1 -0
  57. package/dist/database/mem.js +67 -0
  58. package/dist/database/mem.js.map +1 -0
  59. package/dist/database/migration.d.ts +55 -0
  60. package/dist/database/migration.d.ts.map +1 -0
  61. package/dist/database/migration.js +46 -0
  62. package/dist/database/migration.js.map +1 -0
  63. package/dist/database/s3.d.ts +36 -0
  64. package/dist/database/s3.d.ts.map +1 -0
  65. package/dist/database/s3.js +141 -0
  66. package/dist/database/s3.js.map +1 -0
  67. package/dist/db.d.ts +44 -128
  68. package/dist/db.d.ts.map +1 -1
  69. package/dist/db.js +163 -287
  70. package/dist/db.js.map +1 -1
  71. package/dist/engine.d.ts +7 -0
  72. package/dist/engine.d.ts.map +1 -0
  73. package/dist/engine.js +2 -0
  74. package/dist/engine.js.map +1 -0
  75. package/dist/errors.d.ts +152 -46
  76. package/dist/errors.d.ts.map +1 -1
  77. package/dist/errors.js +107 -19
  78. package/dist/errors.js.map +1 -1
  79. package/dist/face.d.ts +5 -5
  80. package/dist/face.d.ts.map +1 -1
  81. package/dist/face.js +6 -6
  82. package/dist/face.js.map +1 -1
  83. package/dist/fields.d.ts +4 -5
  84. package/dist/fields.d.ts.map +1 -1
  85. package/dist/fields.js +3 -3
  86. package/dist/fields.js.map +1 -1
  87. package/dist/index.d.ts +60 -58
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +27 -29
  90. package/dist/index.js.map +1 -1
  91. package/dist/judgment.d.ts +1 -1
  92. package/dist/judgment.js +1 -1
  93. package/dist/law.d.ts +16 -68
  94. package/dist/law.d.ts.map +1 -1
  95. package/dist/law.js +3 -3
  96. package/dist/law.js.map +1 -1
  97. package/dist/lower.d.ts +3 -3
  98. package/dist/lower.d.ts.map +1 -1
  99. package/dist/lower.js +35 -39
  100. package/dist/lower.js.map +1 -1
  101. package/dist/native/addon.d.ts +23 -0
  102. package/dist/native/addon.d.ts.map +1 -0
  103. package/dist/native/addon.js +15 -0
  104. package/dist/native/addon.js.map +1 -0
  105. package/dist/native/binding.d.ts +996 -0
  106. package/dist/native/json.d.ts +14 -0
  107. package/dist/native/json.d.ts.map +1 -0
  108. package/dist/native/json.js +73 -0
  109. package/dist/native/json.js.map +1 -0
  110. package/dist/native/load.d.ts +9 -0
  111. package/dist/native/load.d.ts.map +1 -0
  112. package/dist/native/load.js +30 -0
  113. package/dist/native/load.js.map +1 -0
  114. package/dist/native/op.d.ts +29 -0
  115. package/dist/native/op.d.ts.map +1 -0
  116. package/dist/native/op.js +50 -0
  117. package/dist/native/op.js.map +1 -0
  118. package/dist/query/atom.d.ts +13 -14
  119. package/dist/query/atom.d.ts.map +1 -1
  120. package/dist/query/atom.js +2 -2
  121. package/dist/query/atom.js.map +1 -1
  122. package/dist/query/compute.d.ts +7 -7
  123. package/dist/query/compute.d.ts.map +1 -1
  124. package/dist/query/compute.js +7 -16
  125. package/dist/query/compute.js.map +1 -1
  126. package/dist/query/find.d.ts +8 -8
  127. package/dist/query/find.d.ts.map +1 -1
  128. package/dist/query/find.js +1 -1
  129. package/dist/query/lower.d.ts +31 -17
  130. package/dist/query/lower.d.ts.map +1 -1
  131. package/dist/query/lower.js +260 -368
  132. package/dist/query/lower.js.map +1 -1
  133. package/dist/query/run.d.ts +5 -5
  134. package/dist/query/run.d.ts.map +1 -1
  135. package/dist/query/run.js +32 -15
  136. package/dist/query/run.js.map +1 -1
  137. package/dist/query/scope.d.ts +20 -28
  138. package/dist/query/scope.d.ts.map +1 -1
  139. package/dist/query/scope.js +13 -8
  140. package/dist/query/scope.js.map +1 -1
  141. package/dist/query/segments.d.ts +2 -2
  142. package/dist/query/segments.d.ts.map +1 -1
  143. package/dist/query/segments.js +3 -3
  144. package/dist/query/segments.js.map +1 -1
  145. package/dist/relation.d.ts +1 -1
  146. package/dist/relation.d.ts.map +1 -1
  147. package/dist/relation.js +4 -4
  148. package/dist/relation.js.map +1 -1
  149. package/dist/result.d.ts +15 -22
  150. package/dist/result.d.ts.map +1 -1
  151. package/dist/result.js +30 -39
  152. package/dist/result.js.map +1 -1
  153. package/dist/rows.d.ts +9 -33
  154. package/dist/rows.d.ts.map +1 -1
  155. package/dist/rows.js +8 -12
  156. package/dist/rows.js.map +1 -1
  157. package/dist/runtime.d.ts +17 -43
  158. package/dist/runtime.d.ts.map +1 -1
  159. package/dist/runtime.js +41 -241
  160. package/dist/runtime.js.map +1 -1
  161. package/dist/scalar.d.ts +36 -106
  162. package/dist/scalar.d.ts.map +1 -1
  163. package/dist/scalar.js +36 -185
  164. package/dist/scalar.js.map +1 -1
  165. package/dist/schema.d.ts +7 -18
  166. package/dist/schema.d.ts.map +1 -1
  167. package/dist/schema.js +18 -228
  168. package/dist/schema.js.map +1 -1
  169. package/dist/selection.d.ts +4 -4
  170. package/dist/selection.d.ts.map +1 -1
  171. package/dist/selection.js +5 -5
  172. package/dist/selection.js.map +1 -1
  173. package/dist/shape.d.ts +5 -5
  174. package/dist/shape.d.ts.map +1 -1
  175. package/dist/spec.d.ts +7 -79
  176. package/dist/spec.d.ts.map +1 -1
  177. package/dist/spec.js.map +1 -1
  178. package/dist/statements.d.ts +3 -3
  179. package/dist/statements.d.ts.map +1 -1
  180. package/dist/statements.js +10 -10
  181. package/dist/statements.js.map +1 -1
  182. package/dist/uuid.d.ts +1 -1
  183. package/dist/uuid.d.ts.map +1 -1
  184. package/dist/uuid.js +1 -1
  185. package/dist/uuid.js.map +1 -1
  186. package/dist/values.d.ts +2 -2
  187. package/dist/values.d.ts.map +1 -1
  188. package/dist/values.js +2 -2
  189. package/dist/values.js.map +1 -1
  190. package/package.json +18 -18
  191. package/src/alternatives.ts +7 -8
  192. package/src/bin.ts +82 -0
  193. package/src/capacity.ts +20 -23
  194. package/src/changes.ts +134 -197
  195. package/src/closed.ts +5 -5
  196. package/src/codec.ts +77 -51
  197. package/src/compile.ts +91 -113
  198. package/src/database/database.ts +413 -0
  199. package/src/database/driver.ts +134 -0
  200. package/src/database/fs.ts +119 -0
  201. package/src/database/generate.ts +116 -0
  202. package/src/database/hosted.ts +102 -0
  203. package/src/database/io.ts +134 -0
  204. package/src/database/mem.ts +113 -0
  205. package/src/database/migration.ts +107 -0
  206. package/src/database/s3.ts +231 -0
  207. package/src/db.ts +290 -547
  208. package/src/engine.ts +14 -0
  209. package/src/errors.ts +118 -39
  210. package/src/face.ts +9 -9
  211. package/src/fields.ts +6 -7
  212. package/src/index.ts +102 -109
  213. package/src/judgment.ts +1 -1
  214. package/src/law.ts +18 -70
  215. package/src/lower.ts +61 -72
  216. package/src/native/addon.ts +54 -0
  217. package/src/native/binding.d.ts +996 -0
  218. package/src/native/json.ts +100 -0
  219. package/src/native/load.ts +31 -0
  220. package/src/native/op.ts +73 -0
  221. package/src/query/atom.ts +15 -16
  222. package/src/query/compute.ts +13 -22
  223. package/src/query/find.ts +8 -8
  224. package/src/query/lower.ts +323 -414
  225. package/src/query/run.ts +42 -21
  226. package/src/query/scope.ts +37 -38
  227. package/src/query/segments.ts +4 -4
  228. package/src/relation.ts +4 -4
  229. package/src/result.ts +53 -80
  230. package/src/rows.ts +18 -46
  231. package/src/runtime.ts +50 -346
  232. package/src/scalar.ts +76 -336
  233. package/src/schema.ts +23 -284
  234. package/src/selection.ts +6 -6
  235. package/src/shape.ts +5 -5
  236. package/src/spec.ts +7 -85
  237. package/src/statements.ts +11 -11
  238. package/src/uuid.ts +1 -1
  239. package/src/values.ts +4 -4
  240. package/dist/close.d.ts +0 -24
  241. package/dist/close.d.ts.map +0 -1
  242. package/dist/close.js +0 -34
  243. package/dist/close.js.map +0 -1
  244. package/dist/db-native.d.ts +0 -196
  245. package/dist/db-native.d.ts.map +0 -1
  246. package/dist/db-native.js +0 -13
  247. package/dist/db-native.js.map +0 -1
  248. package/dist/internal/log.d.ts +0 -26
  249. package/dist/internal/log.d.ts.map +0 -1
  250. package/dist/internal/log.js +0 -12
  251. package/dist/internal/log.js.map +0 -1
  252. package/dist/migration.d.ts +0 -31
  253. package/dist/migration.d.ts.map +0 -1
  254. package/dist/migration.js +0 -47
  255. package/dist/migration.js.map +0 -1
  256. package/dist/native.d.ts +0 -562
  257. package/dist/native.d.ts.map +0 -1
  258. package/dist/native.js +0 -123
  259. package/dist/native.js.map +0 -1
  260. package/dist/query/description.d.ts +0 -41
  261. package/dist/query/description.d.ts.map +0 -1
  262. package/dist/query/description.js +0 -311
  263. package/dist/query/description.js.map +0 -1
  264. package/dist/query/parse-ir.d.ts +0 -10
  265. package/dist/query/parse-ir.d.ts.map +0 -1
  266. package/dist/query/parse-ir.js +0 -280
  267. package/dist/query/parse-ir.js.map +0 -1
  268. package/dist/runtime-codes.d.ts +0 -2
  269. package/dist/runtime-codes.d.ts.map +0 -1
  270. package/dist/runtime-codes.js +0 -18
  271. package/dist/runtime-codes.js.map +0 -1
  272. package/dist/runtime-errors.d.ts +0 -118
  273. package/dist/runtime-errors.d.ts.map +0 -1
  274. package/dist/runtime-errors.js +0 -98
  275. package/dist/runtime-errors.js.map +0 -1
  276. package/dist/runtime-native.d.ts +0 -141
  277. package/dist/runtime-native.d.ts.map +0 -1
  278. package/dist/runtime-native.js +0 -5
  279. package/dist/runtime-native.js.map +0 -1
  280. package/pack-provenance.json +0 -7
  281. package/src/close.ts +0 -53
  282. package/src/db-native.ts +0 -243
  283. package/src/internal/log.ts +0 -48
  284. package/src/migration.ts +0 -61
  285. package/src/native.ts +0 -736
  286. package/src/query/description.ts +0 -424
  287. package/src/query/parse-ir.ts +0 -291
  288. package/src/runtime-codes.ts +0 -17
  289. package/src/runtime-errors.ts +0 -109
  290. package/src/runtime-native.ts +0 -189
package/src/engine.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The embedded engine: one `Db` over a local LMDB directory, for single-process use, tests and
3
+ * benches. Applications that want the durable log use `Database` from the package root.
4
+ */
5
+ export type {
6
+ ApplyOutcome,
7
+ DbInspection,
8
+ JudgeOutcome,
9
+ PreparedQuery,
10
+ QueryReader,
11
+ Snapshot,
12
+ Witness
13
+ } from "./db.ts"
14
+ export { Db } from "./db.ts"
package/src/errors.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { Data, Schema } from "effect"
2
-
3
1
  /**
4
- * Pure authoring failures, SDK-invariant defects and internal native-boundary
5
- * diagnostics. AST misuse can throw synchronously without I/O. Runtime
6
- * adapters translate operational failures into the public `DbError` class
7
- * in `#runtime-errors.ts`; contradictions in SDK/native state remain defects.
2
+ * The SDK's errors. Authoring refusals throw synchronously while a schema, query or value is
3
+ * built; everything that runs as an Effect fails with `DbError { operation, reason }`; a native
4
+ * close that does not drain cleanly is a `CloseFailure` defect.
8
5
  */
6
+ import { Schema } from "effect"
9
7
 
10
- /** A pure schema, query, parameter, or value-authoring refusal. */
8
+ /** Where an authoring refusal points and what was expected there. */
11
9
  export const AuthoringDiagnostic = Schema.Struct({
12
10
  code: Schema.Literals([
13
11
  "InvalidValue",
@@ -22,40 +20,121 @@ export const AuthoringDiagnostic = Schema.Struct({
22
20
  })
23
21
  export type AuthoringDiagnostic = typeof AuthoringDiagnostic.Type
24
22
 
25
- export class AuthoringError extends Data.TaggedError("AuthoringError")<{
26
- readonly message: string
27
- readonly diagnostic?: AuthoringDiagnostic
28
- }> {}
29
-
30
- /** A contradiction in an SDK/native result, not an application refusal. */
31
- export class SdkInvariantError extends Data.TaggedError("SdkInvariantError")<{
32
- readonly message: string
33
- }> {}
34
-
35
- export class NativeLoadError extends Data.TaggedError("NativeLoadError")<{
36
- readonly package: string
37
- readonly operation: "resolve" | "load"
38
- readonly message: string
39
- readonly cause: unknown
40
- }> {}
41
-
42
- /** A native bridge call's contextual failure; the exact thrown value is retained. */
43
- export class NativeOperationError extends Data.TaggedError("NativeOperationError")<{
44
- readonly operation: string
45
- readonly cause: unknown
46
- }> {
23
+ /** A schema, query, parameter or value refused while it is being authored. */
24
+ export class AuthoringError extends Schema.TaggedError<AuthoringError>()("AuthoringError", {
25
+ message: Schema.String,
26
+ diagnostic: Schema.optional(AuthoringDiagnostic)
27
+ }) {}
28
+
29
+ /** The native addon for this host could not be loaded. */
30
+ export class NativeLoadError extends Schema.TaggedError<NativeLoadError>()("NativeLoadError", {
31
+ target: Schema.String,
32
+ message: Schema.String,
33
+ cause: Schema.Unknown
34
+ }) {}
35
+
36
+ const PlainReason = Schema.Struct({
37
+ _tag: Schema.Literals([
38
+ "RuntimeAlreadyLive",
39
+ "ForeignRuntime",
40
+ "ClosedHandle",
41
+ "HandleBusy",
42
+ "SpentHandle",
43
+ "QueueFull",
44
+ "Internal",
45
+ "DirectoryBusy",
46
+ "WriterBusy",
47
+ "InvalidPath",
48
+ "Cancelled",
49
+ "OutOfMemory"
50
+ ])
51
+ })
52
+ const InvalidArgument = Schema.Struct({
53
+ _tag: Schema.Literal("InvalidArgument"),
54
+ detail: Schema.optional(
55
+ Schema.Struct({
56
+ message: Schema.String,
57
+ diagnostic: Schema.optional(AuthoringDiagnostic)
58
+ })
59
+ )
60
+ })
61
+ const InvalidValue = Schema.Struct({ _tag: Schema.Literal("InvalidValue"), message: Schema.String })
62
+ const Io = Schema.Struct({ _tag: Schema.Literal("Io"), kind: Schema.String, osCode: Schema.optional(Schema.Number) })
63
+ const ResourceLimit = Schema.Struct({
64
+ _tag: Schema.Literal("ResourceLimit"),
65
+ dimension: Schema.String,
66
+ used: Schema.BigInt,
67
+ requested: Schema.BigInt,
68
+ limit: Schema.BigInt
69
+ })
70
+ /** An engine refusal: the engine error's kind and message. */
71
+ const Engine = Schema.Struct({ _tag: Schema.Literal("Engine"), kind: Schema.String, message: Schema.String })
72
+ const Malformed = Schema.Struct({ _tag: Schema.Literal("Malformed"), path: Schema.String, message: Schema.String })
73
+
74
+ /** Why an operation failed: the addon's `RuntimeError`, plus authoring detail on `InvalidArgument`. */
75
+ export const DbReason = Schema.Union([PlainReason, InvalidArgument, InvalidValue, Io, ResourceLimit, Engine, Malformed])
76
+ export type DbReason = typeof DbReason.Type
77
+
78
+ /** The one runtime error: which operation failed, and why. */
79
+ export class DbError extends Schema.TaggedError<DbError>()("DbError", {
80
+ operation: Schema.String,
81
+ reason: DbReason
82
+ }) {
83
+ get code() {
84
+ return this.reason._tag
85
+ }
47
86
  override get message(): string {
48
- const cause = this.cause
87
+ return `${this.operation}: ${this.code}`
88
+ }
89
+ }
90
+
91
+ const decodeReason = Schema.decodeUnknownOption(DbReason)
92
+
93
+ /** Reads a native refusal (or any thrown value) as a `DbError` for `operation`. */
94
+ export function dbError(operation: string, cause: unknown): DbError {
95
+ if (cause instanceof DbError) return cause
96
+ if (cause instanceof AuthoringError) return argumentError(operation, cause)
97
+ const decoded = decodeReason(cause)
98
+ return new DbError({ operation, reason: decoded._tag === "Some" ? decoded.value : { _tag: "Internal" } })
99
+ }
100
+
101
+ /** An input refusal, keeping an authoring error's message and diagnostic. */
102
+ export function argumentError(operation: string, cause: unknown): DbError {
103
+ if (cause instanceof DbError) return cause
104
+ if (cause instanceof AuthoringError) {
49
105
  const detail =
50
- typeof cause === "object" && cause !== null && "message" in cause && typeof cause.message === "string"
51
- ? cause.message
52
- : String(cause)
53
- return `${this.operation}: ${detail}`
106
+ cause.diagnostic === undefined
107
+ ? { message: cause.message }
108
+ : { message: cause.message, diagnostic: cause.diagnostic }
109
+ return new DbError({ operation, reason: { _tag: "InvalidArgument", detail } })
54
110
  }
111
+ return new DbError({ operation, reason: { _tag: "InvalidArgument" } })
55
112
  }
56
113
 
57
- export class NativeReportedError extends Data.TaggedError("NativeReportedError")<{
58
- readonly kind: string
59
- readonly message: string
60
- readonly cause: unknown
61
- }> {}
114
+ /** A contradiction between the SDK and the addon: a bug, reported as `Internal`. */
115
+ export function internalError(operation: string): DbError {
116
+ return new DbError({ operation, reason: { _tag: "Internal" } })
117
+ }
118
+
119
+ const Outstanding = Schema.Struct({
120
+ phase: Schema.Literals(["Open", "Closing", "Closed"]),
121
+ queued: Schema.BigInt,
122
+ active: Schema.BigInt,
123
+ retained: Schema.BigInt,
124
+ owners: Schema.BigInt,
125
+ databases: Schema.BigInt,
126
+ natives: Schema.BigInt
127
+ })
128
+ export type OutstandingWork = typeof Outstanding.Type
129
+ const Close = Schema.Union([
130
+ Schema.Struct({ _tag: Schema.Literal("Closed") }),
131
+ Schema.Struct({ _tag: Schema.Literal("Incomplete"), outstanding: Outstanding }),
132
+ Schema.Struct({ _tag: Schema.Literal("Failed") })
133
+ ])
134
+ export type CloseReport = typeof Close.Type
135
+
136
+ /** A native resource that did not drain cleanly when its scope closed. */
137
+ export class CloseFailure extends Schema.TaggedError<CloseFailure>()("CloseFailure", {
138
+ operation: Schema.String,
139
+ report: Close
140
+ }) {}
package/src/face.ts CHANGED
@@ -1,12 +1,12 @@
1
- import type { AnyClosed } from "#closed.ts"
2
- import { memberDescriptor, sealedFieldOf } from "#closed.ts"
3
- import { AuthoringError } from "#errors.ts"
4
- import { type AnyField, assertDeclarationRecord, type SignatureOf } from "#fields.ts"
5
- import type { Same } from "#judgment.ts"
6
- import type { AnyRelation, FieldsShape } from "#relation.ts"
7
- import { type AnySelected, type FieldsOf, type SelectionBinding, selectionBindings } from "#selection.ts"
8
- import { renderLiteralSet } from "#spec.ts"
9
- import { arrayValue, recordValue } from "#values.ts"
1
+ import type { AnyClosed } from "./closed.ts"
2
+ import { memberDescriptor, sealedFieldOf } from "./closed.ts"
3
+ import { AuthoringError } from "./errors.ts"
4
+ import { type AnyField, assertDeclarationRecord, type SignatureOf } from "./fields.ts"
5
+ import type { Same } from "./judgment.ts"
6
+ import type { AnyRelation, FieldsShape } from "./relation.ts"
7
+ import { type AnySelected, type FieldsOf, type SelectionBinding, selectionBindings } from "./selection.ts"
8
+ import { renderLiteralSet } from "./spec.ts"
9
+ import { arrayValue, recordValue } from "./values.ts"
10
10
 
11
11
  const emptySelection: readonly SelectionBinding[] = Object.freeze([])
12
12
 
package/src/fields.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { regex } from "arkregex"
2
- import { AuthoringError } from "#errors.ts"
3
- import type { LiteralSpec } from "#spec.ts"
4
- import type { Uuid } from "#uuid.ts"
5
- import { arrayValue, fieldValue, recordValue, taggedValueOf, U64_MAX } from "#values.ts"
2
+ import { AuthoringError } from "./errors.ts"
3
+ import type { LiteralSpec } from "./spec.ts"
4
+ import type { Uuid } from "./uuid.ts"
5
+ import { arrayValue, fieldValue, recordValue, taggedValueOf, U64_MAX } from "./values.ts"
6
6
 
7
7
  const INTEGER_INDEX_NAME = regex("^(?:0|[1-9][0-9]*)$")
8
8
 
@@ -70,8 +70,7 @@ interface F64Field {
70
70
  /**
71
71
  * The application-owned 128-bit identity scalar: sixteen
72
72
  * exact bytes, spelled as the canonical hyphenated UUID {@link Uuid}
73
- * host value. There is no `fresh` mark anywhere: the database issues no
74
- * identity, and key laws are declared statements.
73
+ * host value. Key laws are declared statements.
75
74
  */
76
75
  interface UuidField {
77
76
  readonly kind: "uuid"
@@ -335,7 +334,7 @@ const i64: I64Field = Object.freeze({ kind: "i64" })
335
334
  /** Binary64. The native value boundary canonicalizes NaN and signed zero. */
336
335
  const f64: F64Field = Object.freeze({ kind: "f64" })
337
336
 
338
- /** The application-owned 128-bit identity scalar; no fresh mark exists. */
337
+ /** The application-owned 128-bit identity scalar. */
339
338
  const uuid: UuidField = Object.freeze({ kind: "uuid" })
340
339
 
341
340
  const bool: BoolField = Object.freeze({ kind: "bool" })
package/src/index.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
- * @bjornpagen/bumbledb — the Effect-native TypeScript SDK for the
3
- * bumbledb embedded relational engine. 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.
2
+ * Typed schemas and queries, validated by the engine as they are defined, and the durable
3
+ * `Database` over an object store. Every database operation is a lazy, scoped Effect on the one
4
+ * native runtime; the embedded `Db` lives in `./engine`.
7
5
  */
8
6
 
9
- export { alternatives } from "#alternatives.ts"
7
+ export { alternatives } from "./alternatives.ts"
10
8
  export type {
11
9
  BoundsOnTarget,
12
10
  CapacityWeight,
@@ -15,43 +13,71 @@ export type {
15
13
  FieldRef,
16
14
  UnitDimensionBan,
17
15
  WeightOnSource
18
- } from "#capacity.ts"
19
- export { duration, ref, weigh, within } from "#capacity.ts"
20
- export type { ChangeCounts, ChangeDraft, ChangeRecord } from "#changes.ts"
21
- export { ChangeSet } from "#changes.ts"
16
+ } from "./capacity.ts"
17
+ export { duration, ref, weigh, within } from "./capacity.ts"
18
+ export type { ChangeCounts, ChangeDraft, ChangeRecord } from "./changes.ts"
19
+ export { ChangeSet } from "./changes.ts"
22
20
  export type {
23
21
  AnyClosed,
24
22
  AxiomRow,
25
23
  Axioms,
26
24
  Closed,
27
25
  PayloadField
28
- } from "#closed.ts"
29
- export { closed, closedId } from "#closed.ts"
30
- export type { RowShape } from "#codec.ts"
31
- export { decodeBoundaryRows, decodeRows, encodeBoundaryRows, encodeRows, rowSchema, rowShape } from "#codec.ts"
32
- export type { CompiledSchema, SchemaId } from "#compile.ts"
33
- export { Schema } from "#compile.ts"
26
+ } from "./closed.ts"
27
+ export { closed, closedId } from "./closed.ts"
28
+ export type { RowShape } from "./codec.ts"
29
+ export {
30
+ decodeBoundaryField,
31
+ decodeBoundaryRows,
32
+ decodeRows,
33
+ encodeBoundaryField,
34
+ encodeBoundaryRows,
35
+ encodeRows,
36
+ fieldSchema,
37
+ rowSchema,
38
+ rowShape
39
+ } from "./codec.ts"
40
+ export type { SchemaId } from "./compile.ts"
41
+ export type {
42
+ Consistency,
43
+ DatabaseOptions,
44
+ DatabasePool,
45
+ DatabaseReader,
46
+ PoolOptions,
47
+ SubmitOptions,
48
+ SubmitOutcome,
49
+ Tuning
50
+ } from "./database/database.ts"
51
+ export { Database, RequestId } from "./database/database.ts"
52
+ export { FsStore } from "./database/fs.ts"
34
53
  export type {
35
- ApplyOutcome,
36
- CoreWitness,
37
- DbInspection,
38
- JudgeOutcome,
39
- PreparedQuery,
40
- QueryReader,
41
- Snapshot,
42
- StorageInspection,
43
- WriteExpected,
44
- WriteOptions
45
- } from "#db.ts"
46
- export { Db } from "#db.ts"
54
+ Body,
55
+ Bucket,
56
+ ExecutorOptions,
57
+ IoRequest,
58
+ IoResponse,
59
+ IoResult,
60
+ Millis,
61
+ ObjectStore,
62
+ Reply,
63
+ Target
64
+ } from "./database/io.ts"
65
+ export type { Fault, MemStoreOptions } from "./database/mem.ts"
66
+ export { MemStore } from "./database/mem.ts"
67
+ export type { AnyMigration, Migrations, Populate } from "./database/migration.ts"
68
+ export { Migration } from "./database/migration.ts"
69
+ export type { S3Sender, S3StoreOptions } from "./database/s3.ts"
70
+ export { S3Store } from "./database/s3.ts"
71
+ export type { PreparedQuery, QueryReader } from "./db.ts"
72
+ export type { CloseReport, OutstandingWork } from "./errors.ts"
47
73
  export {
48
74
  AuthoringDiagnostic,
49
75
  AuthoringError,
50
- NativeLoadError,
51
- NativeOperationError,
52
- NativeReportedError,
53
- SdkInvariantError
54
- } from "#errors.ts"
76
+ CloseFailure,
77
+ DbError,
78
+ dbError,
79
+ NativeLoadError
80
+ } from "./errors.ts"
55
81
  export type {
56
82
  AnyFace,
57
83
  Arity,
@@ -66,8 +92,8 @@ export type {
66
92
  ProjectedShape,
67
93
  SameArity,
68
94
  SameShapes
69
- } from "#face.ts"
70
- export { on } from "#face.ts"
95
+ } from "./face.ts"
96
+ export { on } from "./face.ts"
71
97
  export type {
72
98
  AnyClosedIdField,
73
99
  AnyClosedRoster,
@@ -88,40 +114,26 @@ export type {
88
114
  StrField,
89
115
  U64Field,
90
116
  UuidField
91
- } from "#fields.ts"
92
- export { bool, bytes, f64, i64, interval, str, u64, uuid } from "#fields.ts"
93
- export type { Same, SameLen } from "#judgment.ts"
94
- export type { ClassesOf, ClassWall, LawfulStatements, RelationClasses, SchemaClasses } from "#law.ts"
117
+ } from "./fields.ts"
118
+ export { bool, bytes, f64, i64, interval, str, u64, uuid } from "./fields.ts"
119
+ export type { Same, SameLen } from "./judgment.ts"
120
+ export type { ClassesOf, ClassWall, LawfulStatements, RelationClasses, SchemaClasses } from "./law.ts"
95
121
  export type {
96
- AtomIr,
97
- AtomSourceIr,
98
- CmpOpIr,
99
- ComparisonIr,
100
- ConditionTreeIr,
101
- FindTermIr,
102
- HeadTermIr,
103
- InteriorIr,
104
- QueryIr,
105
- RecIr,
106
- RuleIr,
107
- ScalarExprIr,
108
- TermIr,
109
- Violation,
110
- ViolationFact
111
- } from "#native.ts"
112
- export type { FindColumn } from "#query/atom.ts"
113
- export { ALLEN } from "#query/atom.ts"
114
- export type { AnyComputeExpr, ComputeExpr, ComputeValue, QueryNode } from "#query/compute.ts"
115
- export { Compute } from "#query/compute.ts"
116
- export type {
117
- DescriptionHead,
118
- DescriptionParameter,
119
- DescriptionRow,
120
- DescriptionTable,
121
- QueryDescription
122
- } from "#query/description.ts"
123
- export { describeQuery, queryFromDescription } from "#query/description.ts"
124
- export type { Agg, HeadRecordOf, RowOfFind } from "#query/find.ts"
122
+ EvidenceOut,
123
+ FactOut,
124
+ HeadOut,
125
+ MigrationOut,
126
+ OutcomeOut,
127
+ ReceiptOut,
128
+ RefusalOut,
129
+ SettledOut,
130
+ ViolationOut as Violation
131
+ } from "./native/binding.d.ts"
132
+ export type { FindColumn } from "./query/atom.ts"
133
+ export { ALLEN } from "./query/atom.ts"
134
+ export type { AnyComputeExpr, ComputeExpr, ComputeValue, QueryNode } from "./query/compute.ts"
135
+ export { Compute } from "./query/compute.ts"
136
+ export type { Agg, HeadRecordOf, RowOfFind } from "./query/find.ts"
125
137
  export type {
126
138
  AnyQuery,
127
139
  AnyRuleValue,
@@ -138,8 +150,8 @@ export type {
138
150
  RecRuleScope,
139
151
  RuleValue,
140
152
  TermOps
141
- } from "#query/lower.ts"
142
- export { lowerQuery, query } from "#query/lower.ts"
153
+ } from "./query/lower.ts"
154
+ export { lowerQuery, query } from "./query/lower.ts"
143
155
  export type {
144
156
  ClassedField,
145
157
  Flatten,
@@ -152,9 +164,9 @@ export type {
152
164
  SetParam,
153
165
  Var,
154
166
  VarsOf
155
- } from "#query/scope.ts"
156
- export { v } from "#query/scope.ts"
157
- export type { IntervalVar, SegmentOp, Segments } from "#query/segments.ts"
167
+ } from "./query/scope.ts"
168
+ export { v } from "./query/scope.ts"
169
+ export type { IntervalVar, SegmentOp, Segments } from "./query/segments.ts"
158
170
  export type {
159
171
  AnyRelation,
160
172
  Fact,
@@ -162,55 +174,36 @@ export type {
162
174
  Relation,
163
175
  RelationField,
164
176
  RelationFields
165
- } from "#relation.ts"
166
- export { relation } from "#relation.ts"
167
- export type { CompleteResult } from "#result.ts"
168
- export type { CellValue } from "#rows.ts"
169
- export { cellOf, factOfCells, flatRowsOf, keyCellsOf } from "#rows.ts"
170
- export type { NativeRuntimeOptions } from "#runtime.ts"
171
- export { NativeRuntime } from "#runtime.ts"
172
- export type { CloseReport, OutstandingWork } from "#runtime-errors.ts"
173
- export { CloseFailure, DbError, dbError, runtimeErrorCodes } from "#runtime-errors.ts"
177
+ } from "./relation.ts"
178
+ export { relation } from "./relation.ts"
179
+ export type { CompleteResult } from "./result.ts"
180
+ export type { CellValue } from "./rows.ts"
181
+ export { cellOf, factOfCells, flatRowsOf, keyCellsOf } from "./rows.ts"
182
+ export type { BumbleOptions } from "./runtime.ts"
183
+ export { Bumble } from "./runtime.ts"
174
184
  export type {
175
185
  IntervalKind,
176
186
  NumericCast,
177
187
  Rounding,
178
- ScalarExpr,
179
- ScalarFieldRef,
180
188
  ScalarInputKind,
181
189
  ScalarKind,
182
- ScalarLeafScope,
183
190
  ScalarLiteral,
184
191
  ScalarNode,
185
192
  ScalarResultKind,
186
193
  ScalarValue
187
- } from "#scalar.ts"
188
- export { Scalar } from "#scalar.ts"
189
- export type { AnySchema, Schema as SchemaDeclaration, SchemaRelation, SchemaRelations } from "#schema.ts"
190
- export { schema } from "#schema.ts"
191
- export type { AnySelected, FieldsOf, Selected, SelectionBinding, SelectionInput } from "#selection.ts"
192
- export { select } from "#selection.ts"
193
- export type { Key, QueryTemplate, Rel } from "#shape.ts"
194
- export type {
195
- CapacityBoundSpec,
196
- CapacityWindowSpec,
197
- FieldSpec,
198
- LiteralSetSpec,
199
- LiteralSpec,
200
- RelationSpec,
201
- RowSpec,
202
- SchemaSpec,
203
- SideSpec,
204
- StatementSpec,
205
- ValueSpec,
206
- ValueTypeSpec
207
- } from "#spec.ts"
194
+ } from "./scalar.ts"
195
+ export type { AnySchema, Schema, SchemaRelation, SchemaRelations } from "./schema.ts"
196
+ export { schema } from "./schema.ts"
197
+ export type { AnySelected, FieldsOf, Selected, SelectionBinding, SelectionInput } from "./selection.ts"
198
+ export { select } from "./selection.ts"
199
+ export type { Key, QueryTemplate, Rel } from "./shape.ts"
200
+ export type { CapacityBoundSpec, CapacityWindowSpec, LiteralSetSpec, LiteralSpec, ValueSpec } from "./spec.ts"
208
201
  export type {
209
202
  CapacityStatement,
210
203
  ContainmentStatement,
211
204
  KeyStatement,
212
205
  MirrorsStatement,
213
206
  Statement
214
- } from "#statements.ts"
215
- export { capacity, contained, key, mirrors, renderStatement } from "#statements.ts"
216
- export { Uuid } from "#uuid.ts"
207
+ } from "./statements.ts"
208
+ export { capacity, contained, key, mirrors, renderStatement } from "./statements.ts"
209
+ export { Uuid } from "./uuid.ts"
package/src/judgment.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * {@link Same} is definitional equality by mutual extension — the ONE
5
5
  * spelling of `A = B` at the type tier. {@link SameLen} is Peano equality
6
- * on tuple lengths — zero equals zero, successor recurses on successor,
6
+ * on tuple lengths — zero equals zero, n + 1 recurses on n,
7
7
  * everything else is refused. An open array carries no Nat (its length is
8
8
  * `number`), so it proves nothing.
9
9
  */
package/src/law.ts CHANGED
@@ -1,68 +1,19 @@
1
- import { AuthoringError } from "#errors.ts"
1
+ import { AuthoringError } from "./errors.ts"
2
2
  /**
3
- * The law-typing engine (owner ruling 2026-07-18, "option 2, zero debate"):
4
- * THE LAWS TYPE THE COLUMNS. Domains are declared nowhere — `schema`
5
- * computes every field's domain FROM the statement list, at BOTH the type
6
- * level (this module's type machinery, reading the statements tuple type)
7
- * and at runtime (a plain union-find over the same pairs), and the two
8
- * tiers are the same computation by construction.
9
- *
10
- * The three class laws (ratified; implemented exactly):
11
- *
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.
16
- * 2. GENERATOR-LESS classes are named by their least member coordinate
17
- * in relation-declaration × field-declaration order (readable off the
18
- * relation record and each member's frozen field list at the VALUE
19
- * tier — deterministic, pinned forever; the wire reads only this
20
- * tier). At the TYPE tier the same class is carried as its
21
- * member-coordinate SET (see {@link ClassOfCoord}): TypeScript's
22
- * union member order is not observably deterministic, so a type-level
23
- * least-member pick would drift between compilations — the set is the
24
- * canonical deterministic spelling, the runtime name is always a
25
- * member of it, and the join judgment is identical at both tiers.
26
- * 3. BARE — a field in no law has NO class and pairs only with bare in
27
- * queries (the deliberate sum-domain pointer stays legal).
28
- *
29
- * THE WALL: a class containing more than one generator is a contradiction
30
- * (two mints cannot share a carrier) — a schema-level COMPILE error (the
31
- * named, self-locating {@link ClassWall}: which generator coordinates
32
- * collided, through which paired slots) with a construction-time runtime
33
- * twin (`computeClasses` throws with the same content, naming the exact
34
- * statement). The TARGET-KEY WALL ({@link TargetKeyWall},
35
- * 60-containment-parity) rides the same constraint seam: a containment/
36
- * mirrors/capacity target projection that resolves no key of its relation
37
- * is the same kind of schema-level compile error, with `schema`'s
38
- * `verifyTargetKeys` as its authoritative runtime twin.
39
- *
40
- * Every paired face of the statement tuple unions its positionwise field
41
- * slots: containment (ψ-selected targets included — a selection changes
42
- * pairing not at all), the `==` bijection, and capacity source/target pairs.
43
- * `key` statements pair nothing (an FD constrains one relation's own
44
- * rows; it identifies no carriers).
45
- *
46
- * The type tier reads pairs off the statement types' exact face data, so
47
- * spell the statement list INLINE in `schema` (the `const` type
48
- * parameter keeps the tuple precise). A widened `Statement[]` list
49
- * degrades the TYPE tier to generators-only (no pair is readable off a
50
- * widened type) — the runtime map stays complete and authoritative, and
51
- * the wire lowering reads only the runtime map. Every loop below is
52
- * tail-recursive with an accumulator, so the machinery rides TypeScript's
53
- * tail-recursion elimination for large schemas (~40 relations, ~200 slots,
54
- * ~123 statements); should a schema ever exceed the compiler's limits, tsc
55
- * fails LOUDLY with its own instantiation-depth error — the map is never
56
- * silently widened.
3
+ * The laws type the columns: `schema` computes each field's class from its statements at the type
4
+ * level and at runtime (a union-find over the same pairs). A closed id is a generator naming its
5
+ * class, a generator-less class is named by its least member coordinate, and a field in no law is
6
+ * bare. Two generators in one class, or a target projection that resolves no key, is a compile
7
+ * error with a runtime twin. Spell statements inline: a widened list degrades the type tier.
57
8
  */
58
9
 
59
- import type { AnyClosed } from "#closed.ts"
60
- import { isClosedMember, sealedFieldsOf } from "#closed.ts"
61
- import type { AnyFace } from "#face.ts"
62
- import type { Same } from "#judgment.ts"
63
- import type { AnyRelation, RelationFields } from "#relation.ts"
64
- import type { SchemaRelation, SchemaRelations } from "#schema.ts"
65
- import { renderStatement, type Statement } from "#statements.ts"
10
+ import type { AnyClosed } from "./closed.ts"
11
+ import { isClosedMember, sealedFieldsOf } from "./closed.ts"
12
+ import type { AnyFace } from "./face.ts"
13
+ import type { Same } from "./judgment.ts"
14
+ import type { AnyRelation, RelationFields } from "./relation.ts"
15
+ import type { SchemaRelation, SchemaRelations } from "./schema.ts"
16
+ import { renderStatement, type Statement } from "./statements.ts"
66
17
 
67
18
  type RelationClasses = { readonly [field: string]: string | undefined }
68
19
 
@@ -277,16 +228,13 @@ type DecidableKeyData<D> = [D] extends [
277
228
  * widened owner, a widened or union projection each make the roster
278
229
  * UNKNOWABLE.
279
230
  *
280
- * Any failure is the tier's one forbidden verdict in waiting — a false
281
- * wall — so anything outside the whitelist degrades the WHOLE
282
- * {@link TargetKeyWall} to silent (the degradation law: best effort
231
+ * A wrong answer here would be a false wall, so anything outside the
232
+ * whitelist degrades the WHOLE {@link TargetKeyWall} to silent (best effort
283
233
  * degrades to silent, never to a wrong judgment), exactly as a widened
284
234
  * FACE already silences its own judgment; the value tier stays
285
- * authoritative. ONE recorded limit, pre-existing and outside this
286
- * detector's reach: a generic type parameter CONSTRAINED to a union of
287
- * tuples hangs tsc in the deferred-scan machinery before any verdict is
288
- * reached — a degenerate spelling no shipped surface writes, recorded
289
- * here as the tier's known boundary, not fixed.
235
+ * authoritative. Known limit: a generic type parameter CONSTRAINED to a
236
+ * union of tuples hangs tsc in the deferred-scan machinery; no shipped
237
+ * surface writes that spelling.
290
238
  */
291
239
  type DecidableRoster<Stmts extends readonly Statement[]> = [true] extends [IsMulti<Stmts>]
292
240
  ? false