@bjornpagen/bumbledb 1.3.1 → 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.
- package/COOKBOOK.md +153 -77
- package/README.md +107 -41
- package/dist/alternatives.d.ts +5 -6
- package/dist/alternatives.d.ts.map +1 -1
- package/dist/alternatives.js +5 -6
- package/dist/alternatives.js.map +1 -1
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +85 -0
- package/dist/bin.js.map +1 -0
- package/dist/capacity.d.ts +14 -17
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js +7 -7
- package/dist/capacity.js.map +1 -1
- package/dist/changes.d.ts +32 -40
- package/dist/changes.d.ts.map +1 -1
- package/dist/changes.js +86 -104
- package/dist/changes.js.map +1 -1
- package/dist/closed.d.ts +2 -2
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +5 -5
- package/dist/closed.js.map +1 -1
- package/dist/codec.d.ts +13 -27
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +20 -21
- package/dist/codec.js.map +1 -1
- package/dist/compile.d.ts +26 -50
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +75 -64
- package/dist/compile.js.map +1 -1
- package/dist/database/database.d.ts +98 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/database.js +249 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/driver.d.ts +40 -0
- package/dist/database/driver.d.ts.map +1 -0
- package/dist/database/driver.js +68 -0
- package/dist/database/driver.js.map +1 -0
- package/dist/database/fs.d.ts +12 -0
- package/dist/database/fs.d.ts.map +1 -0
- package/dist/database/fs.js +120 -0
- package/dist/database/fs.js.map +1 -0
- package/dist/database/generate.d.ts +26 -0
- package/dist/database/generate.d.ts.map +1 -0
- package/dist/database/generate.js +102 -0
- package/dist/database/generate.js.map +1 -0
- package/dist/database/hosted.d.ts +32 -0
- package/dist/database/hosted.d.ts.map +1 -0
- package/dist/database/hosted.js +44 -0
- package/dist/database/hosted.js.map +1 -0
- package/dist/database/io.d.ts +94 -0
- package/dist/database/io.d.ts.map +1 -0
- package/dist/database/io.js +35 -0
- package/dist/database/io.js.map +1 -0
- package/dist/database/mem.d.ts +26 -0
- package/dist/database/mem.d.ts.map +1 -0
- package/dist/database/mem.js +67 -0
- package/dist/database/mem.js.map +1 -0
- package/dist/database/migration.d.ts +55 -0
- package/dist/database/migration.d.ts.map +1 -0
- package/dist/database/migration.js +46 -0
- package/dist/database/migration.js.map +1 -0
- package/dist/database/s3.d.ts +36 -0
- package/dist/database/s3.d.ts.map +1 -0
- package/dist/database/s3.js +141 -0
- package/dist/database/s3.js.map +1 -0
- package/dist/db.d.ts +44 -128
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +163 -287
- package/dist/db.js.map +1 -1
- package/dist/engine.d.ts +7 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.d.ts +152 -46
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +107 -19
- package/dist/errors.js.map +1 -1
- package/dist/face.d.ts +5 -5
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +6 -6
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +4 -5
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +3 -3
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +60 -57
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -28
- package/dist/index.js.map +1 -1
- package/dist/judgment.d.ts +1 -1
- package/dist/judgment.js +1 -1
- package/dist/law.d.ts +16 -68
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +3 -3
- package/dist/law.js.map +1 -1
- package/dist/lower.d.ts +3 -3
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +35 -39
- package/dist/lower.js.map +1 -1
- package/dist/native/addon.d.ts +23 -0
- package/dist/native/addon.d.ts.map +1 -0
- package/dist/native/addon.js +15 -0
- package/dist/native/addon.js.map +1 -0
- package/dist/native/binding.d.ts +996 -0
- package/dist/native/json.d.ts +14 -0
- package/dist/native/json.d.ts.map +1 -0
- package/dist/native/json.js +73 -0
- package/dist/native/json.js.map +1 -0
- package/dist/native/load.d.ts +9 -0
- package/dist/native/load.d.ts.map +1 -0
- package/dist/native/load.js +30 -0
- package/dist/native/load.js.map +1 -0
- package/dist/native/op.d.ts +29 -0
- package/dist/native/op.d.ts.map +1 -0
- package/dist/native/op.js +50 -0
- package/dist/native/op.js.map +1 -0
- package/dist/query/atom.d.ts +13 -14
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +2 -2
- package/dist/query/atom.js.map +1 -1
- package/dist/query/compute.d.ts +4 -4
- package/dist/query/compute.d.ts.map +1 -1
- package/dist/query/compute.js +4 -4
- package/dist/query/compute.js.map +1 -1
- package/dist/query/find.d.ts +8 -8
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +1 -1
- package/dist/query/lower.d.ts +22 -17
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +230 -343
- package/dist/query/lower.js.map +1 -1
- package/dist/query/run.d.ts +5 -5
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +32 -15
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +20 -28
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +7 -7
- package/dist/query/scope.js.map +1 -1
- package/dist/query/segments.d.ts +2 -2
- package/dist/query/segments.d.ts.map +1 -1
- package/dist/query/segments.js +3 -3
- package/dist/query/segments.js.map +1 -1
- package/dist/relation.d.ts +1 -1
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +4 -4
- package/dist/relation.js.map +1 -1
- package/dist/result.d.ts +15 -22
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +30 -39
- package/dist/result.js.map +1 -1
- package/dist/rows.d.ts +9 -33
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +8 -12
- package/dist/rows.js.map +1 -1
- package/dist/runtime.d.ts +17 -20
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +41 -205
- package/dist/runtime.js.map +1 -1
- package/dist/scalar.d.ts +4 -4
- package/dist/scalar.d.ts.map +1 -1
- package/dist/scalar.js +24 -8
- package/dist/scalar.js.map +1 -1
- package/dist/schema.d.ts +7 -18
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +18 -228
- package/dist/schema.js.map +1 -1
- package/dist/selection.d.ts +4 -4
- package/dist/selection.d.ts.map +1 -1
- package/dist/selection.js +5 -5
- package/dist/selection.js.map +1 -1
- package/dist/shape.d.ts +5 -5
- package/dist/shape.d.ts.map +1 -1
- package/dist/spec.d.ts +7 -79
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +3 -3
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +10 -10
- package/dist/statements.js.map +1 -1
- package/dist/uuid.d.ts +1 -1
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +1 -1
- package/dist/uuid.js.map +1 -1
- package/dist/values.d.ts +2 -2
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +2 -2
- package/dist/values.js.map +1 -1
- package/package.json +18 -18
- package/src/alternatives.ts +7 -8
- package/src/bin.ts +82 -0
- package/src/capacity.ts +20 -23
- package/src/changes.ts +134 -191
- package/src/closed.ts +5 -5
- package/src/codec.ts +35 -49
- package/src/compile.ts +91 -113
- package/src/database/database.ts +413 -0
- package/src/database/driver.ts +134 -0
- package/src/database/fs.ts +119 -0
- package/src/database/generate.ts +116 -0
- package/src/database/hosted.ts +102 -0
- package/src/database/io.ts +134 -0
- package/src/database/mem.ts +113 -0
- package/src/database/migration.ts +107 -0
- package/src/database/s3.ts +231 -0
- package/src/db.ts +290 -547
- package/src/engine.ts +14 -0
- package/src/errors.ts +118 -39
- package/src/face.ts +9 -9
- package/src/fields.ts +6 -7
- package/src/index.ts +92 -105
- package/src/judgment.ts +1 -1
- package/src/law.ts +18 -70
- package/src/lower.ts +61 -72
- package/src/native/addon.ts +54 -0
- package/src/native/binding.d.ts +996 -0
- package/src/native/json.ts +100 -0
- package/src/native/load.ts +31 -0
- package/src/native/op.ts +73 -0
- package/src/query/atom.ts +15 -16
- package/src/query/compute.ts +7 -7
- package/src/query/find.ts +8 -8
- package/src/query/lower.ts +270 -392
- package/src/query/run.ts +42 -21
- package/src/query/scope.ts +29 -37
- package/src/query/segments.ts +4 -4
- package/src/relation.ts +4 -4
- package/src/result.ts +53 -80
- package/src/rows.ts +18 -46
- package/src/runtime.ts +50 -277
- package/src/scalar.ts +32 -12
- package/src/schema.ts +23 -284
- package/src/selection.ts +6 -6
- package/src/shape.ts +5 -5
- package/src/spec.ts +7 -85
- package/src/statements.ts +11 -11
- package/src/uuid.ts +1 -1
- package/src/values.ts +4 -4
- package/dist/close.d.ts +0 -24
- package/dist/close.d.ts.map +0 -1
- package/dist/close.js +0 -34
- package/dist/close.js.map +0 -1
- package/dist/db-native.d.ts +0 -189
- package/dist/db-native.d.ts.map +0 -1
- package/dist/db-native.js +0 -13
- package/dist/db-native.js.map +0 -1
- package/dist/internal/log.d.ts +0 -26
- package/dist/internal/log.d.ts.map +0 -1
- package/dist/internal/log.js +0 -12
- package/dist/internal/log.js.map +0 -1
- package/dist/native.d.ts +0 -562
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js +0 -123
- package/dist/native.js.map +0 -1
- package/dist/query/description.d.ts +0 -41
- package/dist/query/description.d.ts.map +0 -1
- package/dist/query/description.js +0 -311
- package/dist/query/description.js.map +0 -1
- package/dist/query/parse-ir.d.ts +0 -10
- package/dist/query/parse-ir.d.ts.map +0 -1
- package/dist/query/parse-ir.js +0 -280
- package/dist/query/parse-ir.js.map +0 -1
- package/dist/runtime-codes.d.ts +0 -2
- package/dist/runtime-codes.d.ts.map +0 -1
- package/dist/runtime-codes.js +0 -19
- package/dist/runtime-codes.js.map +0 -1
- package/dist/runtime-errors.d.ts +0 -138
- package/dist/runtime-errors.d.ts.map +0 -1
- package/dist/runtime-errors.js +0 -111
- package/dist/runtime-errors.js.map +0 -1
- package/dist/runtime-native.d.ts +0 -136
- package/dist/runtime-native.d.ts.map +0 -1
- package/dist/runtime-native.js +0 -5
- package/dist/runtime-native.js.map +0 -1
- package/dist/schema-file.d.ts +0 -7
- package/dist/schema-file.d.ts.map +0 -1
- package/dist/schema-file.js +0 -24
- package/dist/schema-file.js.map +0 -1
- package/pack-provenance.json +0 -7
- package/src/close.ts +0 -53
- package/src/db-native.ts +0 -235
- package/src/internal/log.ts +0 -46
- package/src/native.ts +0 -736
- package/src/query/description.ts +0 -424
- package/src/query/parse-ir.ts +0 -293
- package/src/runtime-codes.ts +0 -18
- package/src/runtime-errors.ts +0 -122
- package/src/runtime-native.ts +0 -181
- package/src/schema-file.ts +0 -38
package/src/query/parse-ir.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { AuthoringError } from "#errors.ts"
|
|
2
|
-
import type {
|
|
3
|
-
AtomIr,
|
|
4
|
-
CmpOpIr,
|
|
5
|
-
ConditionTreeIr,
|
|
6
|
-
FindTermIr,
|
|
7
|
-
HeadTermIr,
|
|
8
|
-
ParsedQuery,
|
|
9
|
-
QueryIr,
|
|
10
|
-
RuleIr,
|
|
11
|
-
ScalarExprIr,
|
|
12
|
-
TermIr
|
|
13
|
-
} from "#native.ts"
|
|
14
|
-
import { roundingMode } from "#scalar.ts"
|
|
15
|
-
import { arrayValue as array, recordValue, valueDescriptor } from "#values.ts"
|
|
16
|
-
|
|
17
|
-
function fail(context: string, expected: string): never {
|
|
18
|
-
throw new AuthoringError({
|
|
19
|
-
message: `${context}: ${expected}`,
|
|
20
|
-
diagnostic: { code: "InvalidQuery", context, expected }
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function tagged(context: string, input: unknown): Readonly<Record<string, unknown>> {
|
|
25
|
-
if (typeof input !== "object" || input === null) return fail(context, "expected a descriptor record")
|
|
26
|
-
return recordValue(context, input, Object.keys(input))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function ordinal(context: string, input: unknown, maximum = 0xffff): number {
|
|
30
|
-
if (typeof input !== "number" || !Number.isInteger(input) || input < 0 || input > maximum)
|
|
31
|
-
return fail(context, `expected an ordinal from 0 through ${maximum}`)
|
|
32
|
-
return input
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function term(context: string, input: unknown): TermIr {
|
|
36
|
-
const raw = tagged(context, input)
|
|
37
|
-
switch (raw.kind) {
|
|
38
|
-
case "var":
|
|
39
|
-
recordValue(context, raw, ["kind", "var"])
|
|
40
|
-
return Object.freeze({ kind: raw.kind, var: ordinal(context, raw.var) })
|
|
41
|
-
case "param":
|
|
42
|
-
case "paramSet":
|
|
43
|
-
recordValue(context, raw, ["kind", "param"])
|
|
44
|
-
return Object.freeze({ kind: raw.kind, param: ordinal(context, raw.param) })
|
|
45
|
-
case "literal":
|
|
46
|
-
recordValue(context, raw, ["kind", "value"])
|
|
47
|
-
return Object.freeze({ kind: raw.kind, value: valueDescriptor(`${context}.value`, raw.value) })
|
|
48
|
-
default:
|
|
49
|
-
return fail(context, "unknown term kind")
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function scalar(context: string, input: unknown, depth = 1): ScalarExprIr {
|
|
54
|
-
if (depth > 128) return fail(context, "scalar expression deeper than 128")
|
|
55
|
-
const raw = tagged(context, input)
|
|
56
|
-
switch (raw.kind) {
|
|
57
|
-
case "var":
|
|
58
|
-
recordValue(context, raw, ["kind", "var"])
|
|
59
|
-
return Object.freeze({ kind: raw.kind, var: ordinal(context, raw.var) })
|
|
60
|
-
case "literal":
|
|
61
|
-
recordValue(context, raw, ["kind", "value"])
|
|
62
|
-
return Object.freeze({ kind: raw.kind, value: valueDescriptor(`${context}.value`, raw.value) })
|
|
63
|
-
case "measure":
|
|
64
|
-
case "negate":
|
|
65
|
-
case "isNaN":
|
|
66
|
-
case "isFinite":
|
|
67
|
-
recordValue(context, raw, ["kind", "expr"])
|
|
68
|
-
return Object.freeze({ kind: raw.kind, expr: scalar(`${context}.expr`, raw.expr, depth + 1) })
|
|
69
|
-
case "add":
|
|
70
|
-
case "subtract":
|
|
71
|
-
case "multiply":
|
|
72
|
-
case "divide":
|
|
73
|
-
recordValue(context, raw, ["kind", "left", "right"])
|
|
74
|
-
return Object.freeze({
|
|
75
|
-
kind: raw.kind,
|
|
76
|
-
left: scalar(`${context}.left`, raw.left, depth + 1),
|
|
77
|
-
right: scalar(`${context}.right`, raw.right, depth + 1)
|
|
78
|
-
})
|
|
79
|
-
case "mulDiv":
|
|
80
|
-
recordValue(context, raw, ["kind", "a", "b", "divisor", "rounding"])
|
|
81
|
-
return Object.freeze({
|
|
82
|
-
kind: raw.kind,
|
|
83
|
-
a: scalar(`${context}.a`, raw.a, depth + 1),
|
|
84
|
-
b: scalar(`${context}.b`, raw.b, depth + 1),
|
|
85
|
-
divisor: scalar(`${context}.divisor`, raw.divisor, depth + 1),
|
|
86
|
-
rounding: roundingMode(raw.rounding)
|
|
87
|
-
})
|
|
88
|
-
case "cast": {
|
|
89
|
-
recordValue(context, raw, ["kind", "cast", "expr"])
|
|
90
|
-
const cast = raw.cast
|
|
91
|
-
if (cast !== "toF64" && cast !== "toF64Exact" && cast !== "toI64Exact" && cast !== "toU64Exact")
|
|
92
|
-
return fail(context, "unknown numeric cast")
|
|
93
|
-
return Object.freeze({ kind: raw.kind, cast, expr: scalar(`${context}.expr`, raw.expr, depth + 1) })
|
|
94
|
-
}
|
|
95
|
-
default:
|
|
96
|
-
return fail(context, "unknown scalar expression kind")
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function headTerm(context: string, input: unknown): HeadTermIr {
|
|
101
|
-
const raw = tagged(context, input)
|
|
102
|
-
if (raw.kind === "var" || raw.kind === "compute") {
|
|
103
|
-
recordValue(context, raw, ["kind"])
|
|
104
|
-
return Object.freeze({ kind: raw.kind })
|
|
105
|
-
}
|
|
106
|
-
recordValue(context, raw, ["kind", "op"])
|
|
107
|
-
if (raw.kind !== "aggregate") return fail(context, "unknown head kind")
|
|
108
|
-
const op = raw.op
|
|
109
|
-
if (op !== "sum" && op !== "mean" && op !== "min" && op !== "max" && op !== "count" && op !== "pack")
|
|
110
|
-
return fail(context, "unknown head aggregate")
|
|
111
|
-
return Object.freeze({ kind: raw.kind, op })
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function find(context: string, input: unknown): FindTermIr {
|
|
115
|
-
const raw = tagged(context, input)
|
|
116
|
-
if (raw.kind === "segments") {
|
|
117
|
-
recordValue(context, raw, ["kind", "op", "left", "right"])
|
|
118
|
-
if (raw.op !== "intersection" && raw.op !== "difference") return fail(context, "unknown segment operator")
|
|
119
|
-
return Object.freeze({
|
|
120
|
-
kind: raw.kind,
|
|
121
|
-
op: raw.op,
|
|
122
|
-
left: ordinal(context, raw.left),
|
|
123
|
-
right: ordinal(context, raw.right)
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
switch (raw.kind) {
|
|
127
|
-
case "var":
|
|
128
|
-
recordValue(context, raw, ["kind", "var"])
|
|
129
|
-
return Object.freeze({ kind: raw.kind, var: ordinal(context, raw.var) })
|
|
130
|
-
case "count":
|
|
131
|
-
if (Object.hasOwn(raw, "over")) return fail(context, "Count carries no over")
|
|
132
|
-
recordValue(context, raw, ["kind"])
|
|
133
|
-
return Object.freeze({ kind: raw.kind })
|
|
134
|
-
case "compute":
|
|
135
|
-
if (!Object.hasOwn(raw, "expr")) return fail(context, "compute requires expr")
|
|
136
|
-
recordValue(context, raw, ["kind", "expr"])
|
|
137
|
-
return Object.freeze({ kind: raw.kind, expr: scalar(`${context}.expr`, raw.expr) })
|
|
138
|
-
case "pack":
|
|
139
|
-
recordValue(context, raw, ["kind", "over"])
|
|
140
|
-
return Object.freeze({ kind: raw.kind, over: ordinal(context, raw.over) })
|
|
141
|
-
case "aggregate": {
|
|
142
|
-
recordValue(context, raw, ["kind", "op", "over"])
|
|
143
|
-
const op = recordValue(`${context}.op`, raw.op, ["kind"]).kind
|
|
144
|
-
if (op !== "sum" && op !== "mean" && op !== "min" && op !== "max") return fail(context, "unknown fold operator")
|
|
145
|
-
return Object.freeze({ kind: raw.kind, op: Object.freeze({ kind: op }), over: ordinal(context, raw.over) })
|
|
146
|
-
}
|
|
147
|
-
default:
|
|
148
|
-
return fail(context, "unknown find kind")
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function atom(context: string, input: unknown): AtomIr {
|
|
153
|
-
const raw = recordValue(context, input, ["source", "bindings"])
|
|
154
|
-
const source = tagged(`${context}.source`, raw.source)
|
|
155
|
-
let owned: AtomIr["source"]
|
|
156
|
-
if (source.kind === "edb") {
|
|
157
|
-
recordValue(context, source, ["kind", "relation"])
|
|
158
|
-
owned = { kind: source.kind, relation: ordinal(`${context}.source.relation`, source.relation, 0xffffffff) }
|
|
159
|
-
} else if (source.kind === "interior") {
|
|
160
|
-
recordValue(context, source, ["kind", "interior"])
|
|
161
|
-
owned = { kind: source.kind, interior: ordinal(`${context}.source.interior`, source.interior, 0xffffffff) }
|
|
162
|
-
} else return fail(context, "unknown atom source")
|
|
163
|
-
const seen = new Set<number>()
|
|
164
|
-
const bindings = array(`${context}.bindings`, raw.bindings, (path, pair): readonly [number, TermIr] => {
|
|
165
|
-
const cells = array(path, pair, (_, value) => value)
|
|
166
|
-
if (cells.length !== 2) return fail(path, "a binding has exactly two elements")
|
|
167
|
-
const field = ordinal(`${path}[0]`, cells[0])
|
|
168
|
-
if (seen.has(field)) return fail(path, "duplicate field binding")
|
|
169
|
-
seen.add(field)
|
|
170
|
-
return Object.freeze([field, term(`${path}[1]`, cells[1])])
|
|
171
|
-
})
|
|
172
|
-
return Object.freeze({ source: Object.freeze(owned), bindings })
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function comparisonOp(context: string, input: unknown): CmpOpIr {
|
|
176
|
-
const raw = tagged(context, input)
|
|
177
|
-
if (raw.kind === "allen") {
|
|
178
|
-
recordValue(context, raw, ["kind", "mask"])
|
|
179
|
-
return Object.freeze({ kind: raw.kind, mask: ordinal(`${context}.mask`, raw.mask, 0x1fff) })
|
|
180
|
-
}
|
|
181
|
-
recordValue(context, raw, ["kind"])
|
|
182
|
-
const kind = raw.kind
|
|
183
|
-
if (
|
|
184
|
-
kind !== "eq" &&
|
|
185
|
-
kind !== "ne" &&
|
|
186
|
-
kind !== "lt" &&
|
|
187
|
-
kind !== "le" &&
|
|
188
|
-
kind !== "gt" &&
|
|
189
|
-
kind !== "ge" &&
|
|
190
|
-
kind !== "pointIn"
|
|
191
|
-
)
|
|
192
|
-
return fail(context, "unknown comparison operator")
|
|
193
|
-
return Object.freeze({ kind })
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function condition(context: string, input: unknown, depth = 1): ConditionTreeIr {
|
|
197
|
-
if (depth > 64) return fail(context, "condition tree deeper than 64")
|
|
198
|
-
const raw = tagged(context, input)
|
|
199
|
-
if (raw.kind === "leaf") {
|
|
200
|
-
recordValue(context, raw, ["kind", "cmp"])
|
|
201
|
-
const cmp = recordValue(`${context}.cmp`, raw.cmp, ["op", "lhs", "rhs"])
|
|
202
|
-
return Object.freeze({
|
|
203
|
-
kind: raw.kind,
|
|
204
|
-
cmp: Object.freeze({
|
|
205
|
-
op: comparisonOp(`${context}.cmp.op`, cmp.op),
|
|
206
|
-
lhs: term(`${context}.cmp.lhs`, cmp.lhs),
|
|
207
|
-
rhs: term(`${context}.cmp.rhs`, cmp.rhs)
|
|
208
|
-
})
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
|
-
if (raw.kind !== "and" && raw.kind !== "or") return fail(context, "unknown condition kind")
|
|
212
|
-
recordValue(context, raw, ["kind", "children"])
|
|
213
|
-
return Object.freeze({
|
|
214
|
-
kind: raw.kind,
|
|
215
|
-
children: array(`${context}.children`, raw.children, (path, value) => condition(path, value, depth + 1))
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function rule(context: string, input: unknown): RuleIr {
|
|
220
|
-
const raw = recordValue(context, input, ["finds", "atoms", "negated", "conditions"])
|
|
221
|
-
return Object.freeze({
|
|
222
|
-
finds: array(`${context}.finds`, raw.finds, find),
|
|
223
|
-
atoms: array(`${context}.atoms`, raw.atoms, atom),
|
|
224
|
-
negated: array(`${context}.negated`, raw.negated, atom),
|
|
225
|
-
conditions: array(`${context}.conditions`, raw.conditions, condition)
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function align(context: string, head: readonly HeadTermIr[], rules: readonly RuleIr[]): void {
|
|
230
|
-
for (const [index, rule] of rules.entries()) {
|
|
231
|
-
if (rule.finds.length !== head.length) fail(`${context}.rules[${index}]`, "finds width does not match head width")
|
|
232
|
-
for (const [position, find] of rule.finds.entries()) {
|
|
233
|
-
const term = head[position]
|
|
234
|
-
const projects = find.kind === "var" || find.kind === "compute" || find.kind === "segments"
|
|
235
|
-
if (term === undefined || (term.kind === "aggregate") === projects)
|
|
236
|
-
fail(`${context}.rules[${index}].finds[${position}]`, "find family does not match head")
|
|
237
|
-
if (term.kind === "aggregate") {
|
|
238
|
-
const op = find.kind === "aggregate" ? find.op.kind : find.kind
|
|
239
|
-
if (op !== term.op)
|
|
240
|
-
fail(`${context}.rules[${index}].finds[${position}]`, "aggregate operator does not match head")
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Own and validate the complete wire grammar. The native compiler then
|
|
248
|
-
* checks schema membership, binding types, safety and recursion semantics;
|
|
249
|
-
* parsing alone does not assert that a query is admitted by a schema.
|
|
250
|
-
*/
|
|
251
|
-
function parseQueryIr(input: unknown): ParsedQuery {
|
|
252
|
-
const raw = tagged("query", input)
|
|
253
|
-
if (raw.kind !== "cq" && raw.kind !== "reach") return fail("query", "unknown query kind")
|
|
254
|
-
recordValue(
|
|
255
|
-
"query",
|
|
256
|
-
raw,
|
|
257
|
-
raw.kind === "cq" ? ["kind", "interiors", "head", "rules"] : ["kind", "interiors", "rec", "head", "rules"]
|
|
258
|
-
)
|
|
259
|
-
const rules = array("query.rules", raw.rules, rule)
|
|
260
|
-
if (rules.length === 0) return fail("parseQueryIr", "main rules are empty")
|
|
261
|
-
const head = array("query.head", raw.head, headTerm)
|
|
262
|
-
align("query", head, rules)
|
|
263
|
-
const interiors = array("query.interiors", raw.interiors, (path, input) => {
|
|
264
|
-
const raw = recordValue(path, input, ["head", "rules"])
|
|
265
|
-
const head = array(`${path}.head`, raw.head, headTerm)
|
|
266
|
-
const rules = array(`${path}.rules`, raw.rules, rule)
|
|
267
|
-
if (rules.length === 0) return fail(path, "interior rules are empty")
|
|
268
|
-
align(path, head, rules)
|
|
269
|
-
return Object.freeze({ head, rules })
|
|
270
|
-
})
|
|
271
|
-
let owned: QueryIr
|
|
272
|
-
if (raw.kind === "cq") owned = { kind: raw.kind, interiors, head, rules }
|
|
273
|
-
else {
|
|
274
|
-
const rawRec = recordValue("query.rec", raw.rec, ["head", "base", "rec"])
|
|
275
|
-
const headRec = array("query.rec.head", rawRec.head, headTerm)
|
|
276
|
-
const base = array("query.rec.base", rawRec.base, rule)
|
|
277
|
-
if (base.length === 0) return fail("parseQueryIr", "rec base is empty")
|
|
278
|
-
const rec = array("query.rec.rec", rawRec.rec, rule)
|
|
279
|
-
if (rec.length === 0) return fail("parseQueryIr", "rec step is empty")
|
|
280
|
-
align("rec base", headRec, base)
|
|
281
|
-
align("rec step", headRec, rec)
|
|
282
|
-
if (
|
|
283
|
-
headRec.some((term) => term.kind !== "var") ||
|
|
284
|
-
[...base, ...rec].some((rule) => rule.negated.length !== 0 || rule.finds.some((find) => find.kind !== "var"))
|
|
285
|
-
)
|
|
286
|
-
return fail("query.rec", "recursion requires projection-only heads and no negation")
|
|
287
|
-
owned = { kind: raw.kind, interiors, head, rules, rec: Object.freeze({ head: headRec, base, rec }) }
|
|
288
|
-
}
|
|
289
|
-
return Object.freeze(owned) as ParsedQuery
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export type { ParsedQuery }
|
|
293
|
-
export { parseQueryIr }
|
package/src/runtime-codes.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Generated from the exact native runtimeErrorCodes export; do not edit.
|
|
2
|
-
export const runtimeErrorCodes = [
|
|
3
|
-
"RuntimeAlreadyLive",
|
|
4
|
-
"ForeignRuntime",
|
|
5
|
-
"ClosedHandle",
|
|
6
|
-
"HandleBusy",
|
|
7
|
-
"SpentHandle",
|
|
8
|
-
"QueueFull",
|
|
9
|
-
"InvalidArgument",
|
|
10
|
-
"Internal",
|
|
11
|
-
"DirectoryBusy",
|
|
12
|
-
"WriterBusy",
|
|
13
|
-
"InvalidPath",
|
|
14
|
-
"Io",
|
|
15
|
-
"ResourceLimit",
|
|
16
|
-
"Engine",
|
|
17
|
-
"Cancelled"
|
|
18
|
-
] as const
|
package/src/runtime-errors.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect"
|
|
2
|
-
import { AuthoringDiagnostic, AuthoringError } from "#errors.ts"
|
|
3
|
-
import { runtimeErrorCodes } from "#runtime-codes.ts"
|
|
4
|
-
|
|
5
|
-
export { runtimeErrorCodes } from "#runtime-codes.ts"
|
|
6
|
-
|
|
7
|
-
const ResourceLimit = Schema.Struct({
|
|
8
|
-
_tag: Schema.Literal("ResourceLimit"),
|
|
9
|
-
dimension: Schema.String,
|
|
10
|
-
used: Schema.BigInt,
|
|
11
|
-
requested: Schema.BigInt,
|
|
12
|
-
limit: Schema.BigInt
|
|
13
|
-
})
|
|
14
|
-
const PlainReason = Schema.Struct({
|
|
15
|
-
_tag: Schema.Literals(
|
|
16
|
-
runtimeErrorCodes.filter(
|
|
17
|
-
(code) => code !== "ResourceLimit" && code !== "Io" && code !== "Engine" && code !== "InvalidArgument"
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
})
|
|
21
|
-
const InvalidArgument = Schema.Struct({
|
|
22
|
-
_tag: Schema.Literal("InvalidArgument"),
|
|
23
|
-
detail: Schema.optional(
|
|
24
|
-
Schema.Struct({
|
|
25
|
-
message: Schema.String,
|
|
26
|
-
diagnostic: Schema.optional(AuthoringDiagnostic)
|
|
27
|
-
})
|
|
28
|
-
)
|
|
29
|
-
})
|
|
30
|
-
const Io = Schema.Struct({
|
|
31
|
-
_tag: Schema.Literal("Io"),
|
|
32
|
-
kind: Schema.String,
|
|
33
|
-
osCode: Schema.optional(Schema.Number)
|
|
34
|
-
})
|
|
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. */
|
|
42
|
-
const Engine = Schema.Struct({
|
|
43
|
-
_tag: Schema.Literal("Engine"),
|
|
44
|
-
kind: Schema.String,
|
|
45
|
-
message: Schema.String,
|
|
46
|
-
diagnostic: Schema.optional(SchemaDiagnostic)
|
|
47
|
-
})
|
|
48
|
-
export const DbReason = Schema.Union([ResourceLimit, Io, Engine, InvalidArgument, PlainReason])
|
|
49
|
-
export class DbError extends Schema.TaggedError<DbError>()("DbError", {
|
|
50
|
-
operation: Schema.String,
|
|
51
|
-
reason: DbReason
|
|
52
|
-
}) {
|
|
53
|
-
get code() {
|
|
54
|
-
return this.reason._tag
|
|
55
|
-
}
|
|
56
|
-
/** Safe default display; callers explicitly inspect structured detail. */
|
|
57
|
-
override get message(): string {
|
|
58
|
-
return `${this.operation}: ${this.code}`
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const decodeReason = Schema.decodeUnknownOption(DbReason)
|
|
63
|
-
export function dbError(operation: string, cause: unknown): DbError {
|
|
64
|
-
if (cause instanceof DbError) return cause
|
|
65
|
-
if (cause instanceof AuthoringError) return argumentError(operation, cause)
|
|
66
|
-
const decoded = decodeReason(cause)
|
|
67
|
-
if (decoded._tag === "Some") return new DbError({ operation, reason: decoded.value })
|
|
68
|
-
// Synchronous native schema/marshalling refusals precede the executor's
|
|
69
|
-
// tagged error wire. Preserve their engine family instead of losing it.
|
|
70
|
-
if (
|
|
71
|
-
typeof cause === "object" &&
|
|
72
|
-
cause !== null &&
|
|
73
|
-
"kind" in cause &&
|
|
74
|
-
typeof cause.kind === "string" &&
|
|
75
|
-
"message" in cause &&
|
|
76
|
-
typeof cause.message === "string"
|
|
77
|
-
) {
|
|
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 })
|
|
85
|
-
}
|
|
86
|
-
return new DbError({ operation, reason: { _tag: "Internal" } })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Host input failures retain authoring details without displaying values. */
|
|
90
|
-
export function argumentError(operation: string, cause: unknown): DbError {
|
|
91
|
-
if (cause instanceof DbError) return cause
|
|
92
|
-
if (cause instanceof AuthoringError) {
|
|
93
|
-
const detail =
|
|
94
|
-
cause.diagnostic === undefined
|
|
95
|
-
? { message: cause.message }
|
|
96
|
-
: { message: cause.message, diagnostic: cause.diagnostic }
|
|
97
|
-
return new DbError({ operation, reason: { _tag: "InvalidArgument", detail } })
|
|
98
|
-
}
|
|
99
|
-
return new DbError({ operation, reason: { _tag: "InvalidArgument" } })
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const Outstanding = Schema.Struct({
|
|
103
|
-
phase: Schema.Literals(["open", "closing", "closed"]),
|
|
104
|
-
queued: Schema.BigInt,
|
|
105
|
-
active: Schema.BigInt,
|
|
106
|
-
retained: Schema.BigInt,
|
|
107
|
-
owners: Schema.BigInt,
|
|
108
|
-
databases: Schema.BigInt,
|
|
109
|
-
natives: Schema.BigInt
|
|
110
|
-
})
|
|
111
|
-
export type OutstandingWork = typeof Outstanding.Type
|
|
112
|
-
const Close = Schema.Union([
|
|
113
|
-
Schema.Struct({ kind: Schema.Literal("closed") }),
|
|
114
|
-
Schema.Struct({ kind: Schema.Literal("incomplete"), outstanding: Outstanding }),
|
|
115
|
-
Schema.Struct({ kind: Schema.Literal("failed"), error: DbError })
|
|
116
|
-
])
|
|
117
|
-
export type CloseReport = typeof Close.Type
|
|
118
|
-
|
|
119
|
-
export class CloseFailure extends Schema.TaggedError<CloseFailure>()("CloseFailure", {
|
|
120
|
-
operation: Schema.String,
|
|
121
|
-
report: Close
|
|
122
|
-
}) {}
|
package/src/runtime-native.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/** Exact-version internal bridge, shared by core and log. Not a public API. */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
DbHandle,
|
|
5
|
-
LogChainKind,
|
|
6
|
-
LogCommandKind,
|
|
7
|
-
LogCommandMetadata,
|
|
8
|
-
LogCommandRef,
|
|
9
|
-
LogCondition,
|
|
10
|
-
LogDecisionStamp,
|
|
11
|
-
LogIdentity,
|
|
12
|
-
LogLimits,
|
|
13
|
-
LogOutcomeWire,
|
|
14
|
-
LogSchemaHandle,
|
|
15
|
-
LogStateStamp,
|
|
16
|
-
Violation
|
|
17
|
-
} from "#native.ts"
|
|
18
|
-
import { native } from "#native.ts"
|
|
19
|
-
import type { SchemaSpec } from "#spec.ts"
|
|
20
|
-
|
|
21
|
-
export interface RuntimeHandle {
|
|
22
|
-
readonly __runtime: unique symbol
|
|
23
|
-
}
|
|
24
|
-
export interface OperationHandle {
|
|
25
|
-
readonly __operation: unique symbol
|
|
26
|
-
}
|
|
27
|
-
export interface DirectoryHandle {
|
|
28
|
-
readonly __directory: unique symbol
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Resource kinds installed in native worker tables. */
|
|
32
|
-
export type NativeKind = "snapshot" | "prepared" | "result" | "cursor" | "draft" | "changes" | "repository-lock"
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Checked capability into the native registry. JS tokens validate
|
|
36
|
-
* these five fields; native re-judges kind/generation/owner on every verb.
|
|
37
|
-
*/
|
|
38
|
-
export interface Capability {
|
|
39
|
-
readonly runtime: bigint
|
|
40
|
-
readonly worker: number
|
|
41
|
-
readonly kind: NativeKind
|
|
42
|
-
readonly id: bigint
|
|
43
|
-
readonly generation: bigint
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type ManagedDbOutcome =
|
|
47
|
-
| { readonly tag: "accepted"; readonly db: DbHandle }
|
|
48
|
-
| { readonly tag: "rejected"; readonly violations: readonly Violation[] }
|
|
49
|
-
| {
|
|
50
|
-
readonly tag: "refused"
|
|
51
|
-
readonly kind: "schemaError" | "newtypeMismatch" | "fingerprintMismatch" | "destinationExists"
|
|
52
|
-
readonly message: string
|
|
53
|
-
readonly diagnostic?: Extract<import("#runtime-errors.ts").DbError["reason"], { _tag: "Engine" }>["diagnostic"]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type LogTakeWire =
|
|
57
|
-
| { readonly ok: false; readonly kind: LogCommandKind | LogChainKind; readonly message: string }
|
|
58
|
-
| {
|
|
59
|
-
/** Command sealed: envelope bytes + reference. */
|
|
60
|
-
readonly ok: true
|
|
61
|
-
readonly bytes: Uint8Array
|
|
62
|
-
readonly ref: LogCommandRef
|
|
63
|
-
}
|
|
64
|
-
| {
|
|
65
|
-
/** Command parsed. */
|
|
66
|
-
readonly ok: true
|
|
67
|
-
readonly identity: LogIdentity
|
|
68
|
-
readonly receiptEpoch: bigint
|
|
69
|
-
readonly requestId: string
|
|
70
|
-
readonly condition: LogCondition
|
|
71
|
-
readonly changes: Uint8Array
|
|
72
|
-
readonly result: Uint8Array
|
|
73
|
-
readonly ref: LogCommandRef
|
|
74
|
-
}
|
|
75
|
-
| {
|
|
76
|
-
/** Decision framed. */
|
|
77
|
-
readonly ok: true
|
|
78
|
-
readonly bytes: Uint8Array
|
|
79
|
-
readonly digest: Uint8Array
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
/** Decision decoded (and chain-verified when a parent was given). */
|
|
83
|
-
readonly ok: true
|
|
84
|
-
readonly identity: LogIdentity
|
|
85
|
-
readonly seq: bigint
|
|
86
|
-
readonly parent: LogDecisionStamp
|
|
87
|
-
readonly beforeState: LogStateStamp
|
|
88
|
-
readonly afterState: LogStateStamp
|
|
89
|
-
readonly commandBytes: Uint8Array
|
|
90
|
-
readonly command: LogCommandRef
|
|
91
|
-
readonly outcome: LogOutcomeWire
|
|
92
|
-
readonly digest: Uint8Array
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface OptionsWire {
|
|
96
|
-
readonly workers?: number | undefined
|
|
97
|
-
readonly queueCapacity?: number | undefined
|
|
98
|
-
readonly cleanupCapacity?: number | undefined
|
|
99
|
-
readonly ownerCapacity?: number | undefined
|
|
100
|
-
readonly nativeHandleCapacity?: number | undefined
|
|
101
|
-
readonly cleanupTimeoutMs?: number | undefined
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface InspectionWire {
|
|
105
|
-
readonly phase: "open" | "closing" | "closed"
|
|
106
|
-
readonly queued: bigint
|
|
107
|
-
readonly active: bigint
|
|
108
|
-
readonly retained: bigint
|
|
109
|
-
readonly owners: bigint
|
|
110
|
-
readonly databases: bigint
|
|
111
|
-
readonly natives: bigint
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export type CloseWire =
|
|
115
|
-
| { readonly kind: "closed" }
|
|
116
|
-
| { readonly kind: "incomplete"; readonly outstanding: InspectionWire }
|
|
117
|
-
| { readonly kind: "failed" }
|
|
118
|
-
|
|
119
|
-
interface RuntimeNative {
|
|
120
|
-
runtimeErrorCodes(): readonly string[]
|
|
121
|
-
runtimeOpen(options: OptionsWire): RuntimeHandle
|
|
122
|
-
runtimeReady(runtime: RuntimeHandle, callback: () => void): OperationHandle
|
|
123
|
-
runtimeHash(runtime: RuntimeHandle, bytes: Uint8Array, callback: () => void): OperationHandle
|
|
124
|
-
runtimeTake(operation: OperationHandle): Uint8Array | null
|
|
125
|
-
runtimeCancel(operation: OperationHandle, callback: (report: CloseWire) => void): void
|
|
126
|
-
runtimeClose(runtime: RuntimeHandle, callback: (report: CloseWire) => void): void
|
|
127
|
-
runtimeInspect(runtime: RuntimeHandle): InspectionWire
|
|
128
|
-
/**
|
|
129
|
-
* L12 request (D12/D25): one-shot arm. Next `dispatch_payload_message`
|
|
130
|
-
* must cancel after `work()` returns and the post-work `checkpoint()`
|
|
131
|
-
* (`runtime.rs` ~860–862), before `complete_operation` writes
|
|
132
|
-
* `operation.output`. A local `QueuedOutput` is not registration.
|
|
133
|
-
* Predelivery: no JS take; cursor stays on row1 so retry does not skip.
|
|
134
|
-
*/
|
|
135
|
-
runtimeArmPublicationCancel(runtime: RuntimeHandle): void
|
|
136
|
-
runtimeDirectoryAcquire(runtime: RuntimeHandle, path: string, callback: () => void): OperationHandle
|
|
137
|
-
runtimeDirectoryTake(operation: OperationHandle): DirectoryHandle
|
|
138
|
-
runtimeDirectoryBegin(owner: DirectoryHandle): OperationHandle
|
|
139
|
-
runtimeDirectoryCheck(operation: OperationHandle): void
|
|
140
|
-
runtimeDirectoryEnd(operation: OperationHandle): void
|
|
141
|
-
runtimeDirectoryClose(owner: DirectoryHandle, remove: boolean, callback: (report: CloseWire) => void): void
|
|
142
|
-
runtimeDirectoryDbOpen(
|
|
143
|
-
owner: DirectoryHandle,
|
|
144
|
-
childName: string,
|
|
145
|
-
spec: SchemaSpec,
|
|
146
|
-
create: boolean,
|
|
147
|
-
callback: () => void
|
|
148
|
-
): OperationHandle
|
|
149
|
-
runtimeDbTake(operation: OperationHandle): ManagedDbOutcome
|
|
150
|
-
runtimeManagedDbClose(db: DbHandle, callback: (report: CloseWire) => void): void
|
|
151
|
-
|
|
152
|
-
// --- successor log grammar on the executor (hashing over
|
|
153
|
-
// whole canonical change payloads; C06 through C09) ---
|
|
154
|
-
runtimeLogCommandSeal(
|
|
155
|
-
runtime: RuntimeHandle,
|
|
156
|
-
schema: LogSchemaHandle,
|
|
157
|
-
metadata: LogCommandMetadata,
|
|
158
|
-
changes: Uint8Array,
|
|
159
|
-
result: Uint8Array | null,
|
|
160
|
-
limits: LogLimits,
|
|
161
|
-
callback: () => void
|
|
162
|
-
): OperationHandle
|
|
163
|
-
runtimeLogCommandParse(
|
|
164
|
-
runtime: RuntimeHandle,
|
|
165
|
-
schema: LogSchemaHandle,
|
|
166
|
-
bytes: Uint8Array,
|
|
167
|
-
limits: LogLimits,
|
|
168
|
-
callback: () => void
|
|
169
|
-
): OperationHandle
|
|
170
|
-
runtimeLogDecisionDecode(
|
|
171
|
-
runtime: RuntimeHandle,
|
|
172
|
-
bytes: Uint8Array,
|
|
173
|
-
parent: LogDecisionStamp | null,
|
|
174
|
-
limits: LogLimits,
|
|
175
|
-
callback: () => void
|
|
176
|
-
): OperationHandle
|
|
177
|
-
runtimeLogTake(operation: OperationHandle): LogTakeWire
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// The checked source/fresh-addon roster test pins this private declaration.
|
|
181
|
-
export const runtimeNative = native as typeof native & RuntimeNative
|
package/src/schema-file.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect"
|
|
2
|
-
import { dbNative } from "#db-native.ts"
|
|
3
|
-
import { nativeOperationWith, runtimeHandle } from "#runtime.ts"
|
|
4
|
-
import { DbError, dbError } from "#runtime-errors.ts"
|
|
5
|
-
import type { SchemaSpec } from "#spec.ts"
|
|
6
|
-
|
|
7
|
-
const decoder = new TextDecoder("utf-8", { fatal: true })
|
|
8
|
-
|
|
9
|
-
function text(operation: string, bytes: Uint8Array | null): string {
|
|
10
|
-
if (bytes === null) throw dbError(operation, { _tag: "Internal" })
|
|
11
|
-
return decoder.decode(bytes)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const internalSchemaSnapshot = Effect.fn("internalSchemaSnapshot")(function* (spec: SchemaSpec) {
|
|
15
|
-
const runtime = yield* runtimeHandle()
|
|
16
|
-
return yield* nativeOperationWith(
|
|
17
|
-
"internalSchemaSnapshot",
|
|
18
|
-
(callback) => dbNative.runtimeSchemaSnapshot(runtime, spec, callback),
|
|
19
|
-
dbNative.runtimeBytesTake,
|
|
20
|
-
(bytes) => text("internalSchemaSnapshot", bytes)
|
|
21
|
-
)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const internalSchemaBindings = Effect.fn("internalSchemaBindings")(function* (snapshot: string) {
|
|
25
|
-
if (typeof snapshot !== "string" || !snapshot.isWellFormed()) {
|
|
26
|
-
return yield* Effect.fail(new DbError({ operation: "internalSchemaBindings", reason: { _tag: "InvalidArgument" } }))
|
|
27
|
-
}
|
|
28
|
-
const runtime = yield* runtimeHandle()
|
|
29
|
-
const bytes = new TextEncoder().encode(snapshot)
|
|
30
|
-
return yield* nativeOperationWith(
|
|
31
|
-
"internalSchemaBindings",
|
|
32
|
-
(callback) => dbNative.runtimeSchemaBindings(runtime, bytes, callback),
|
|
33
|
-
dbNative.runtimeBytesTake,
|
|
34
|
-
(bytes) => text("internalSchemaBindings", bytes)
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
export { internalSchemaBindings, internalSchemaSnapshot }
|