@bjornpagen/bumbledb 1.2.1 → 1.3.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.
- package/COOKBOOK.md +240 -9
- package/README.md +9 -6
- package/dist/alternatives.d.ts +25 -0
- package/dist/alternatives.d.ts.map +1 -0
- package/dist/alternatives.js +59 -0
- package/dist/alternatives.js.map +1 -0
- package/dist/changes.d.ts +0 -1
- package/dist/changes.d.ts.map +1 -1
- package/dist/changes.js +2 -8
- package/dist/changes.js.map +1 -1
- package/dist/codec.d.ts +8 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +29 -2
- package/dist/codec.js.map +1 -1
- package/dist/db-native.d.ts +2 -9
- package/dist/db-native.d.ts.map +1 -1
- package/dist/db-native.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/log.d.ts +4 -4
- package/dist/internal/log.d.ts.map +1 -1
- package/dist/internal/log.js +2 -2
- package/dist/internal/log.js.map +1 -1
- package/dist/native.d.ts +23 -9
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +2 -1
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js.map +1 -1
- package/dist/query/compute.d.ts +19 -4
- package/dist/query/compute.d.ts.map +1 -1
- package/dist/query/compute.js +17 -13
- package/dist/query/compute.js.map +1 -1
- package/dist/query/description.d.ts +10 -2
- package/dist/query/description.d.ts.map +1 -1
- package/dist/query/description.js +14 -5
- package/dist/query/description.js.map +1 -1
- package/dist/query/find.d.ts +13 -6
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +1 -1
- package/dist/query/find.js.map +1 -1
- package/dist/query/lower.d.ts +14 -2
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +64 -50
- package/dist/query/lower.js.map +1 -1
- package/dist/query/parse-ir.d.ts.map +1 -1
- package/dist/query/parse-ir.js +26 -3
- package/dist/query/parse-ir.js.map +1 -1
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +6 -1
- package/dist/query/scope.js.map +1 -1
- package/dist/query/segments.d.ts +20 -0
- package/dist/query/segments.d.ts.map +1 -0
- package/dist/query/segments.js +35 -0
- package/dist/query/segments.js.map +1 -0
- package/dist/runtime-codes.d.ts +1 -1
- package/dist/runtime-codes.d.ts.map +1 -1
- package/dist/runtime-codes.js +1 -0
- package/dist/runtime-codes.js.map +1 -1
- package/dist/runtime-errors.d.ts +23 -3
- package/dist/runtime-errors.d.ts.map +1 -1
- package/dist/runtime-errors.js +16 -3
- package/dist/runtime-errors.js.map +1 -1
- package/dist/runtime-native.d.ts +3 -8
- package/dist/runtime-native.d.ts.map +1 -1
- package/dist/runtime-native.js.map +1 -1
- package/dist/runtime.d.ts +0 -23
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +0 -36
- package/dist/runtime.js.map +1 -1
- package/dist/scalar.d.ts +46 -94
- package/dist/scalar.d.ts.map +1 -1
- package/dist/scalar.js +69 -156
- package/dist/scalar.js.map +1 -1
- package/dist/schema-file.d.ts +7 -0
- package/dist/schema-file.d.ts.map +1 -0
- package/dist/schema-file.js +24 -0
- package/dist/schema-file.js.map +1 -0
- package/pack-provenance.json +4 -4
- package/package.json +4 -4
- package/src/alternatives.ts +95 -0
- package/src/changes.ts +2 -8
- package/src/codec.ts +43 -3
- package/src/db-native.ts +2 -10
- package/src/index.ts +23 -6
- package/src/internal/log.ts +2 -4
- package/src/native.ts +21 -7
- package/src/query/atom.ts +2 -0
- package/src/query/compute.ts +46 -16
- package/src/query/description.ts +38 -8
- package/src/query/find.ts +37 -26
- package/src/query/lower.ts +89 -52
- package/src/query/parse-ir.ts +27 -3
- package/src/query/scope.ts +8 -1
- package/src/query/segments.ts +61 -0
- package/src/runtime-codes.ts +1 -0
- package/src/runtime-errors.ts +16 -3
- package/src/runtime-native.ts +1 -9
- package/src/runtime.ts +1 -70
- package/src/scalar.ts +138 -285
- package/src/schema-file.ts +38 -0
- package/dist/migration.d.ts +0 -31
- package/dist/migration.d.ts.map +0 -1
- package/dist/migration.js +0 -47
- package/dist/migration.js.map +0 -1
- package/src/migration.ts +0 -61
package/src/runtime-errors.ts
CHANGED
|
@@ -32,11 +32,18 @@ const Io = Schema.Struct({
|
|
|
32
32
|
kind: Schema.String,
|
|
33
33
|
osCode: Schema.optional(Schema.Number)
|
|
34
34
|
})
|
|
35
|
-
|
|
35
|
+
const StatementDiagnostic = Schema.Struct({ id: Schema.Number, descriptor: Schema.String })
|
|
36
|
+
const SchemaDiagnostic = Schema.Struct({
|
|
37
|
+
statement: StatementDiagnostic,
|
|
38
|
+
conflict: Schema.optional(StatementDiagnostic)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
/** A typed engine refusal, including native statement coordinates when known. */
|
|
36
42
|
const Engine = Schema.Struct({
|
|
37
43
|
_tag: Schema.Literal("Engine"),
|
|
38
44
|
kind: Schema.String,
|
|
39
|
-
message: Schema.String
|
|
45
|
+
message: Schema.String,
|
|
46
|
+
diagnostic: Schema.optional(SchemaDiagnostic)
|
|
40
47
|
})
|
|
41
48
|
export const DbReason = Schema.Union([ResourceLimit, Io, Engine, InvalidArgument, PlainReason])
|
|
42
49
|
export class DbError extends Schema.TaggedError<DbError>()("DbError", {
|
|
@@ -68,7 +75,13 @@ export function dbError(operation: string, cause: unknown): DbError {
|
|
|
68
75
|
"message" in cause &&
|
|
69
76
|
typeof cause.message === "string"
|
|
70
77
|
) {
|
|
71
|
-
|
|
78
|
+
const reason = decodeReason({
|
|
79
|
+
_tag: "Engine",
|
|
80
|
+
kind: cause.kind,
|
|
81
|
+
message: cause.message,
|
|
82
|
+
diagnostic: "diagnostic" in cause ? cause.diagnostic : undefined
|
|
83
|
+
})
|
|
84
|
+
if (reason._tag === "Some") return new DbError({ operation, reason: reason.value })
|
|
72
85
|
}
|
|
73
86
|
return new DbError({ operation, reason: { _tag: "Internal" } })
|
|
74
87
|
}
|
package/src/runtime-native.ts
CHANGED
|
@@ -28,11 +28,6 @@ export interface DirectoryHandle {
|
|
|
28
28
|
readonly __directory: unique symbol
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/** Stamped `NativeKind::RepositoryLock` mint — not a directory-owner twin. */
|
|
32
|
-
export interface RepositoryLockHandle {
|
|
33
|
-
readonly __repositoryLock: unique symbol
|
|
34
|
-
}
|
|
35
|
-
|
|
36
31
|
/** Resource kinds installed in native worker tables. */
|
|
37
32
|
export type NativeKind = "snapshot" | "prepared" | "result" | "cursor" | "draft" | "changes" | "repository-lock"
|
|
38
33
|
|
|
@@ -55,6 +50,7 @@ export type ManagedDbOutcome =
|
|
|
55
50
|
readonly tag: "refused"
|
|
56
51
|
readonly kind: "schemaError" | "newtypeMismatch" | "fingerprintMismatch" | "destinationExists"
|
|
57
52
|
readonly message: string
|
|
53
|
+
readonly diagnostic?: Extract<import("#runtime-errors.ts").DbError["reason"], { _tag: "Engine" }>["diagnostic"]
|
|
58
54
|
}
|
|
59
55
|
|
|
60
56
|
export type LogTakeWire =
|
|
@@ -179,10 +175,6 @@ interface RuntimeNative {
|
|
|
179
175
|
callback: () => void
|
|
180
176
|
): OperationHandle
|
|
181
177
|
runtimeLogTake(operation: OperationHandle): LogTakeWire
|
|
182
|
-
/** L14 mint: `Runtime::mint_repository_lock` stamps `NativeKind::RepositoryLock` at take. */
|
|
183
|
-
logRepositoryLockAcquire(runtime: RuntimeHandle, directory: string, callback: () => void): OperationHandle
|
|
184
|
-
logRepositoryLockTake(operation: OperationHandle): RepositoryLockHandle
|
|
185
|
-
logRepositoryLockRelease(owner: RepositoryLockHandle, callback: (report: CloseWire) => void): void
|
|
186
178
|
}
|
|
187
179
|
|
|
188
180
|
// The checked source/fresh-addon roster test pins this private declaration.
|
package/src/runtime.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Duration, Effect, Exit, Layer } from "effect"
|
|
2
2
|
import type { CloseReport, OutstandingWork } from "#runtime-errors.ts"
|
|
3
3
|
import { CloseFailure, DbError, dbError } from "#runtime-errors.ts"
|
|
4
|
-
import type { CloseWire, OperationHandle, OptionsWire,
|
|
4
|
+
import type { CloseWire, OperationHandle, OptionsWire, RuntimeHandle } from "#runtime-native.ts"
|
|
5
5
|
import { runtimeNative } from "#runtime-native.ts"
|
|
6
6
|
|
|
7
7
|
export interface NativeRuntimeOptions {
|
|
@@ -283,75 +283,6 @@ export const runtimeHandle = Effect.fn("NativeRuntime.handle")(function* () {
|
|
|
283
283
|
return handle
|
|
284
284
|
})
|
|
285
285
|
|
|
286
|
-
/**
|
|
287
|
-
* Opaque kernel fence (C8). Backed by L14 `log_repository_lock_*` and
|
|
288
|
-
* L12 `mint_repository_lock` (`NativeKind::RepositoryLock`). Native
|
|
289
|
-
* exclusion is the owner — there is no JS occupancy table. `release`
|
|
290
|
-
* is the one close: it joins `logRepositoryLockRelease` then clears
|
|
291
|
-
* `slot.owner` so the Scope finalizer is a no-op. Callers join host
|
|
292
|
-
* I/O first (`joinPendingIo.pipe(Effect.andThen(lock.release))`).
|
|
293
|
-
*/
|
|
294
|
-
export interface RepositoryLock {
|
|
295
|
-
readonly directory: string
|
|
296
|
-
readonly release: Effect.Effect<void>
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function joinLockRelease(operation: string, owner: RepositoryLockHandle): Effect.Effect<void> {
|
|
300
|
-
return drain(operation, (callback) => runtimeNative.logRepositoryLockRelease(owner, callback)).pipe(
|
|
301
|
-
Effect.flatMap((report) => finalizeClose(operation, report))
|
|
302
|
-
)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Internal log seam: stamped mint only. Cleanup is registered before
|
|
307
|
-
* the interruptible acquire: `acquireRelease({ interruptible })`
|
|
308
|
-
* installs the finalizer only after acquire succeeds. Interrupt, defect,
|
|
309
|
-
* and acquire failure all run the same slot finalizer — empty slot is
|
|
310
|
-
* a no-op. No `runtimeDirectoryAcquire`, no core `Db`, no JS bookkeeping.
|
|
311
|
-
*/
|
|
312
|
-
export const internalAcquireRepositoryLock = Effect.fn("internalAcquireRepositoryLock")(function* (
|
|
313
|
-
operation: string,
|
|
314
|
-
directory: string
|
|
315
|
-
) {
|
|
316
|
-
if (directory.length === 0) {
|
|
317
|
-
return yield* Effect.fail(invalid(operation))
|
|
318
|
-
}
|
|
319
|
-
const runtime = yield* runtimeHandle()
|
|
320
|
-
const closeOp = `${operation}.repositoryLock`
|
|
321
|
-
return yield* Effect.uninterruptibleMask((restore) =>
|
|
322
|
-
Effect.gen(function* () {
|
|
323
|
-
const slot: { owner: RepositoryLockHandle | undefined } = { owner: undefined }
|
|
324
|
-
const release = Effect.suspend(() => {
|
|
325
|
-
const held = slot.owner
|
|
326
|
-
if (held === undefined) {
|
|
327
|
-
return Effect.void
|
|
328
|
-
}
|
|
329
|
-
return joinLockRelease(closeOp, held).pipe(
|
|
330
|
-
Effect.ensuring(
|
|
331
|
-
Effect.sync(() => {
|
|
332
|
-
slot.owner = undefined
|
|
333
|
-
})
|
|
334
|
-
)
|
|
335
|
-
)
|
|
336
|
-
})
|
|
337
|
-
yield* Effect.addFinalizer(() => release)
|
|
338
|
-
const owner = yield* restore(
|
|
339
|
-
nativeOperationWith(
|
|
340
|
-
operation,
|
|
341
|
-
(callback) => runtimeNative.logRepositoryLockAcquire(runtime, directory, callback),
|
|
342
|
-
runtimeNative.logRepositoryLockTake,
|
|
343
|
-
(value) => value
|
|
344
|
-
)
|
|
345
|
-
)
|
|
346
|
-
slot.owner = owner
|
|
347
|
-
return Object.freeze({
|
|
348
|
-
directory,
|
|
349
|
-
release
|
|
350
|
-
})
|
|
351
|
-
})
|
|
352
|
-
)
|
|
353
|
-
})
|
|
354
|
-
|
|
355
286
|
/** Internal first executor consumer; not a replacement row codec or public hash API. */
|
|
356
287
|
export const hashChunk = Effect.fn("bumbledb.hashChunk")(function* (input: Uint8Array) {
|
|
357
288
|
const runtime = yield* NativeRuntime
|