@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.
- package/COOKBOOK.md +224 -95
- package/README.md +114 -45
- 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 -41
- package/dist/changes.d.ts.map +1 -1
- package/dist/changes.js +86 -110
- 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 +20 -27
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +48 -22
- 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 -58
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -29
- 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 +7 -7
- package/dist/query/compute.d.ts.map +1 -1
- package/dist/query/compute.js +7 -16
- 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 +31 -17
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +260 -368
- 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 +13 -8
- 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 -43
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +41 -241
- package/dist/runtime.js.map +1 -1
- package/dist/scalar.d.ts +36 -106
- package/dist/scalar.d.ts.map +1 -1
- package/dist/scalar.js +36 -185
- 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 -197
- package/src/closed.ts +5 -5
- package/src/codec.ts +77 -51
- 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 +102 -109
- 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 +13 -22
- package/src/query/find.ts +8 -8
- package/src/query/lower.ts +323 -414
- package/src/query/run.ts +42 -21
- package/src/query/scope.ts +37 -38
- 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 -346
- package/src/scalar.ts +76 -336
- 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 -196
- 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/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/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 -18
- package/dist/runtime-codes.js.map +0 -1
- package/dist/runtime-errors.d.ts +0 -118
- package/dist/runtime-errors.d.ts.map +0 -1
- package/dist/runtime-errors.js +0 -98
- package/dist/runtime-errors.js.map +0 -1
- package/dist/runtime-native.d.ts +0 -141
- 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/pack-provenance.json +0 -7
- package/src/close.ts +0 -53
- package/src/db-native.ts +0 -243
- package/src/internal/log.ts +0 -48
- package/src/migration.ts +0 -61
- package/src/native.ts +0 -736
- package/src/query/description.ts +0 -424
- package/src/query/parse-ir.ts +0 -291
- package/src/runtime-codes.ts +0 -17
- package/src/runtime-errors.ts +0 -109
- package/src/runtime-native.ts +0 -189
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spellings for the addon's JSON inputs. 64-bit integers cross as decimal strings, `f64` as its
|
|
3
|
+
* 16-hex-digit IEEE bit pattern (so -0, NaN and the infinities stay exact) and bytes as lowercase
|
|
4
|
+
* hex; JSON numbers only ever carry ordinals.
|
|
5
|
+
*/
|
|
6
|
+
import type {
|
|
7
|
+
CapacityBoundSpec,
|
|
8
|
+
CapacityWindowSpec,
|
|
9
|
+
LiteralSetSpec,
|
|
10
|
+
LiteralSpec,
|
|
11
|
+
ValueSpec,
|
|
12
|
+
WeightSpec
|
|
13
|
+
} from "../spec.ts"
|
|
14
|
+
import { f64BitsHex } from "../spec.ts"
|
|
15
|
+
import type {
|
|
16
|
+
BoundSpecIn,
|
|
17
|
+
CapacityWindowSpecIn,
|
|
18
|
+
LiteralSetSpecIn,
|
|
19
|
+
LiteralSpecIn,
|
|
20
|
+
ValueIn,
|
|
21
|
+
WeightSpecIn
|
|
22
|
+
} from "./binding.d.ts"
|
|
23
|
+
|
|
24
|
+
function hex(bytes: Uint8Array): string {
|
|
25
|
+
let out = ""
|
|
26
|
+
for (const byte of bytes) out += byte.toString(16).padStart(2, "0")
|
|
27
|
+
return out
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function valueIn(value: ValueSpec): ValueIn {
|
|
31
|
+
switch (value.kind) {
|
|
32
|
+
case "bool":
|
|
33
|
+
return { kind: "Bool", value: value.value }
|
|
34
|
+
case "u64":
|
|
35
|
+
return { kind: "U64", value: value.value.toString() }
|
|
36
|
+
case "i64":
|
|
37
|
+
return { kind: "I64", value: value.value.toString() }
|
|
38
|
+
case "f64":
|
|
39
|
+
return { kind: "F64", value: f64BitsHex(value.value) }
|
|
40
|
+
case "string":
|
|
41
|
+
return { kind: "String", value: value.value }
|
|
42
|
+
case "uuid":
|
|
43
|
+
return { kind: "Uuid", value: value.value }
|
|
44
|
+
case "fixedBytes":
|
|
45
|
+
return { kind: "FixedBytes", value: hex(value.value) }
|
|
46
|
+
case "intervalU64":
|
|
47
|
+
return { kind: "IntervalU64", start: value.start.toString(), end: value.end.toString() }
|
|
48
|
+
case "intervalI64":
|
|
49
|
+
return { kind: "IntervalI64", start: value.start.toString(), end: value.end.toString() }
|
|
50
|
+
case "intervalF64":
|
|
51
|
+
return { kind: "IntervalF64", start: f64BitsHex(value.start), end: f64BitsHex(value.end) }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function literalIn(literal: LiteralSpec): LiteralSpecIn {
|
|
56
|
+
return literal.kind === "handle"
|
|
57
|
+
? { kind: "Handle", handle: literal.handle }
|
|
58
|
+
: { kind: "Value", value: valueIn(literal.value) }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function literalSetIn(set: LiteralSetSpec): LiteralSetSpecIn {
|
|
62
|
+
return set.kind === "one"
|
|
63
|
+
? { kind: "One", literal: literalIn(set.literal) }
|
|
64
|
+
: { kind: "Many", literals: set.literals.map(literalIn) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function boundIn(bound: CapacityBoundSpec): BoundSpecIn {
|
|
68
|
+
switch (bound.kind) {
|
|
69
|
+
case "lit":
|
|
70
|
+
return { kind: "Lit", value: bound.value.toString() }
|
|
71
|
+
case "field":
|
|
72
|
+
return { kind: "Field", field: bound.field }
|
|
73
|
+
case "durationField":
|
|
74
|
+
return { kind: "Duration", field: bound.field }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function windowIn(window: CapacityWindowSpec): CapacityWindowSpecIn {
|
|
79
|
+
switch (window.kind) {
|
|
80
|
+
case "exact":
|
|
81
|
+
return { kind: "Exact", n: boundIn(window.n) }
|
|
82
|
+
case "range":
|
|
83
|
+
return { kind: "Range", lo: boundIn(window.lo), hi: boundIn(window.hi) }
|
|
84
|
+
case "floor":
|
|
85
|
+
return { kind: "Floor", lo: boundIn(window.lo) }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function weightIn(weight: WeightSpec): WeightSpecIn {
|
|
90
|
+
switch (weight.kind) {
|
|
91
|
+
case "unit":
|
|
92
|
+
return { kind: "Unit" }
|
|
93
|
+
case "field":
|
|
94
|
+
return { kind: "Field", field: weight.field }
|
|
95
|
+
case "durationField":
|
|
96
|
+
return { kind: "Duration", field: weight.field }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { literalIn, literalSetIn, valueIn, weightIn, windowIn }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import { createRequire } from "node:module"
|
|
3
|
+
import { fileURLToPath } from "node:url"
|
|
4
|
+
import { NativeLoadError } from "../errors.ts"
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
|
+
|
|
8
|
+
/** The platforms that ship a prebuilt addon package. */
|
|
9
|
+
export const SHIPPED_PLATFORMS = ["darwin-arm64", "linux-arm64", "linux-x64"] as const
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loads the addon for `platform-arch`: a development build at the package root
|
|
13
|
+
* (`bdb.<platform>-<arch>.node`, written by `scripts/build.ts dev`) wins over the
|
|
14
|
+
* installed `@bjornpagen/bumbledb-<platform>-<arch>` package.
|
|
15
|
+
*/
|
|
16
|
+
export function loadAddon<T>(platform: string, arch: string): T {
|
|
17
|
+
const target = `${platform}-${arch}`
|
|
18
|
+
const dev = fileURLToPath(new URL(`../../bdb.${target}.node`, import.meta.url))
|
|
19
|
+
const source = existsSync(dev) ? dev : `@bjornpagen/bumbledb-${target}`
|
|
20
|
+
try {
|
|
21
|
+
return require(source) as T
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
throw new NativeLoadError({
|
|
24
|
+
target,
|
|
25
|
+
message: SHIPPED_PLATFORMS.some((shipped) => shipped === target)
|
|
26
|
+
? `load the bumbledb addon from ${source}`
|
|
27
|
+
: `no bumbledb addon for ${target}; prebuilt addons ship for ${SHIPPED_PLATFORMS.join(", ")}`,
|
|
28
|
+
cause
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/native/op.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect over the addon's callback protocol. A native verb registers work and returns its lease
|
|
3
|
+
* before any completion can reach JS; the addon then calls back exactly once. Interruption cancels
|
|
4
|
+
* the lease and joins its drain, and a drain that does not close cleanly is a `CloseFailure`
|
|
5
|
+
* defect beside the interrupt.
|
|
6
|
+
*/
|
|
7
|
+
import type { Scope } from "effect"
|
|
8
|
+
import { Effect } from "effect"
|
|
9
|
+
import type { DbError } from "../errors.ts"
|
|
10
|
+
import { CloseFailure, dbError } from "../errors.ts"
|
|
11
|
+
import type { OperationRef } from "./addon.ts"
|
|
12
|
+
import { addon } from "./addon.ts"
|
|
13
|
+
import type { CloseOut } from "./binding.d.ts"
|
|
14
|
+
|
|
15
|
+
/** Registers one native operation; the addon calls `done` once its result can be taken. */
|
|
16
|
+
type Start = (done: () => void) => OperationRef
|
|
17
|
+
|
|
18
|
+
/** Starts one native close or cancel transition; the addon reports how it drained. */
|
|
19
|
+
type Drain = (done: (report: CloseOut) => void) => void
|
|
20
|
+
|
|
21
|
+
/** Runs a native close or cancel transition to completion. It cannot be interrupted and never fails. */
|
|
22
|
+
function drain(start: Drain): Effect.Effect<CloseOut> {
|
|
23
|
+
return Effect.callback<CloseOut>((resume) => {
|
|
24
|
+
try {
|
|
25
|
+
start((report) => resume(Effect.succeed(report)))
|
|
26
|
+
} catch {
|
|
27
|
+
resume(Effect.succeed({ _tag: "Failed" }))
|
|
28
|
+
}
|
|
29
|
+
}).pipe(Effect.uninterruptible)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Drains, then dies with `CloseFailure` unless the transition closed cleanly. */
|
|
33
|
+
function release(operation: string, start: Drain): Effect.Effect<void> {
|
|
34
|
+
return Effect.flatMap(drain(start), (report) =>
|
|
35
|
+
report._tag === "Closed" ? Effect.void : Effect.die(new CloseFailure({ operation, report }))
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One native operation. A completion that arrives after interruption is left to the cancel drain
|
|
41
|
+
* the interruption already started.
|
|
42
|
+
*/
|
|
43
|
+
function call<A>(operation: string, start: Start, take: (lease: OperationRef) => A): Effect.Effect<A, DbError> {
|
|
44
|
+
return Effect.callback<A, DbError>((resume, signal) => {
|
|
45
|
+
let lease: OperationRef
|
|
46
|
+
try {
|
|
47
|
+
lease = start(() => {
|
|
48
|
+
if (signal.aborted) return
|
|
49
|
+
try {
|
|
50
|
+
resume(Effect.succeed(take(lease)))
|
|
51
|
+
} catch (cause) {
|
|
52
|
+
resume(Effect.fail(dbError(operation, cause)))
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
resume(Effect.fail(dbError(operation, cause)))
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
return release(`${operation}.cancel`, (done) => addon.runtimeCancel(lease, done))
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A native resource owned by the current scope, released by its native close transition. */
|
|
64
|
+
function scoped<A, E, R>(
|
|
65
|
+
operation: string,
|
|
66
|
+
acquire: Effect.Effect<A, E, R>,
|
|
67
|
+
close: (resource: A) => Drain
|
|
68
|
+
): Effect.Effect<A, E, R | Scope.Scope> {
|
|
69
|
+
return Effect.acquireRelease(acquire, (resource) => release(operation, close(resource)), { interruptible: true })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type { Drain, Start }
|
|
73
|
+
export { call, drain, release, scoped }
|
package/src/query/atom.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { AuthoringError } from "
|
|
2
|
-
import type { AnyClosedRoster, AnyField, FloatIntervalValue, Infer, IntervalValue } from "
|
|
3
|
-
import type { ClassLookup, ClassRecordOf, SchemaClasses } from "
|
|
4
|
-
import type {
|
|
1
|
+
import { AuthoringError } from "../errors.ts"
|
|
2
|
+
import type { AnyClosedRoster, AnyField, FloatIntervalValue, Infer, IntervalValue } from "../fields.ts"
|
|
3
|
+
import type { ClassLookup, ClassRecordOf, SchemaClasses } from "../law.ts"
|
|
4
|
+
import type { FieldsShape } from "../relation.ts"
|
|
5
|
+
import type { ScalarKind } from "../scalar.ts"
|
|
6
|
+
import type { Uuid } from "../uuid.ts"
|
|
7
|
+
import type { QueryNode } from "./compute.ts"
|
|
5
8
|
import type {
|
|
6
9
|
AntiJoinOk,
|
|
7
10
|
AnyVar,
|
|
@@ -14,12 +17,9 @@ import type {
|
|
|
14
17
|
ParamValueAt,
|
|
15
18
|
SetParam,
|
|
16
19
|
ShapeOf
|
|
17
|
-
} from "
|
|
18
|
-
import { isTerm, term } from "
|
|
19
|
-
import type { Segments } from "
|
|
20
|
-
import type { FieldsShape } from "#relation.ts"
|
|
21
|
-
import type { ScalarKind } from "#scalar.ts"
|
|
22
|
-
import type { Uuid } from "#uuid.ts"
|
|
20
|
+
} from "./scope.ts"
|
|
21
|
+
import { isTerm, term } from "./scope.ts"
|
|
22
|
+
import type { Segments } from "./segments.ts"
|
|
23
23
|
|
|
24
24
|
type BindingTermData =
|
|
25
25
|
| { readonly kind: "var"; readonly ref: AnyVar }
|
|
@@ -387,12 +387,11 @@ function not(
|
|
|
387
387
|
* Whether a variable's OWN field is NUMERIC (u64/i64/f64) — the judgment the
|
|
388
388
|
* point side of `pointIn` and the `sum` input read: a point lives in the
|
|
389
389
|
* interval's element domain, and a quantifier is not an addition, so bool
|
|
390
|
-
* (orderable, never numeric) is
|
|
391
|
-
*
|
|
392
|
-
* order
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* `#query/lower.ts` are that ban's runtime twin.
|
|
390
|
+
* (orderable, never numeric) is refused here. A CLOSED reference is
|
|
391
|
+
* excluded even though its kind is `u64`: a vocabulary's declaration-id
|
|
392
|
+
* order carries no meaning, so every order-comparison and fold position
|
|
393
|
+
* refuses closed-bound terms; `query/lower.ts` checks the same at
|
|
394
|
+
* construction.
|
|
396
395
|
*/
|
|
397
396
|
type NumericVarOk<V extends AnyVar> = V["field"] extends { readonly closed: AnyClosedRoster }
|
|
398
397
|
? false
|
package/src/query/compute.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* `ComputeExpr<K>` is a `ScalarNode<"query-var", K>`. Distinct I64 and U64
|
|
9
|
-
* survive host inference; they do not collapse to plain `bigint`.
|
|
10
|
-
*/
|
|
11
|
-
import { AuthoringError } from "#errors.ts"
|
|
12
|
-
import type { AnyField } from "#fields.ts"
|
|
13
|
-
import { bool as boolField, f64 as f64Field, i64 as i64Field, rosterOf, u64 as u64Field } from "#fields.ts"
|
|
14
|
-
import type { AnyVar } from "#query/scope.ts"
|
|
15
|
-
import { isTerm, term } from "#query/scope.ts"
|
|
16
|
-
import type { Rounding, ScalarKind, ScalarLiteral, ScalarNode } from "#scalar.ts"
|
|
1
|
+
/** Query scalar expressions use the same nodes that native preparation reads.
|
|
2
|
+
* Distinct i64 and u64 kinds survive TypeScript's shared bigint carrier. */
|
|
3
|
+
import { AuthoringError } from "../errors.ts"
|
|
4
|
+
import type { AnyField } from "../fields.ts"
|
|
5
|
+
import { bool as boolField, f64 as f64Field, i64 as i64Field, rosterOf, u64 as u64Field } from "../fields.ts"
|
|
6
|
+
import type { Rounding, ScalarKind, ScalarLiteral, ScalarNode } from "../scalar.ts"
|
|
17
7
|
import {
|
|
18
8
|
checkBool,
|
|
19
9
|
checkF64,
|
|
@@ -30,15 +20,17 @@ import {
|
|
|
30
20
|
scalarMeasure,
|
|
31
21
|
scalarMulDiv,
|
|
32
22
|
scalarNegate
|
|
33
|
-
} from "
|
|
23
|
+
} from "../scalar.ts"
|
|
24
|
+
import type { AnyVar } from "./scope.ts"
|
|
25
|
+
import { isTerm, term } from "./scope.ts"
|
|
34
26
|
|
|
35
|
-
/** Query
|
|
36
|
-
type QueryNode = ScalarNode
|
|
27
|
+
/** Query expression, including interval leaves consumed by measure. */
|
|
28
|
+
type QueryNode = ScalarNode
|
|
37
29
|
|
|
38
30
|
/** Host value for a derived query compute kind. */
|
|
39
31
|
type ComputeValue<K extends ScalarKind> = K extends "f64" ? number : K extends "bool" ? boolean : bigint
|
|
40
32
|
|
|
41
|
-
type ComputeExpr<K extends ScalarKind> = ScalarNode<
|
|
33
|
+
type ComputeExpr<K extends ScalarKind> = ScalarNode<K>
|
|
42
34
|
|
|
43
35
|
type AnyComputeExpr = ComputeExpr<"u64"> | ComputeExpr<"i64"> | ComputeExpr<"f64"> | ComputeExpr<"bool">
|
|
44
36
|
|
|
@@ -65,7 +57,6 @@ type OperandKind<O> =
|
|
|
65
57
|
function isComputeExpr(value: unknown): value is AnyComputeExpr {
|
|
66
58
|
return (
|
|
67
59
|
isScalarNode(value) &&
|
|
68
|
-
value.scope === "query-var" &&
|
|
69
60
|
(value.result === "u64" || value.result === "i64" || value.result === "f64" || value.result === "bool")
|
|
70
61
|
)
|
|
71
62
|
}
|
|
@@ -99,7 +90,7 @@ function asQueryNode(where: string, operand: Operand): QueryNode {
|
|
|
99
90
|
}
|
|
100
91
|
|
|
101
92
|
function literal<K extends ScalarKind>(value: ScalarLiteral): ComputeExpr<K> {
|
|
102
|
-
return scalarLiteral(
|
|
93
|
+
return scalarLiteral(value) as ComputeExpr<K>
|
|
103
94
|
}
|
|
104
95
|
|
|
105
96
|
function u64(value: bigint): ComputeExpr<"u64"> {
|
package/src/query/find.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { BoolField, F64Field, I64Field, Infer, IntervalField, U64Field } from "
|
|
2
|
-
import type { SchemaClasses } from "
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
1
|
+
import type { BoolField, F64Field, I64Field, Infer, IntervalField, U64Field } from "../fields.ts"
|
|
2
|
+
import type { SchemaClasses } from "../law.ts"
|
|
3
|
+
import type { ScalarKind } from "../scalar.ts"
|
|
4
|
+
import type { IntervalVarOk, NumericVarOk } from "./atom.ts"
|
|
5
|
+
import type { AnyComputeExpr, ComputeExpr, ComputeValue } from "./compute.ts"
|
|
6
|
+
import type { AnyVar, MintSlotOf } from "./scope.ts"
|
|
7
|
+
import type { Segments } from "./segments.ts"
|
|
8
8
|
|
|
9
9
|
type FoldOpName = "sum" | "mean" | "min" | "max" | "pack"
|
|
10
10
|
|
|
@@ -35,7 +35,7 @@ function count(): CountAgg {
|
|
|
35
35
|
* Exact checked sum over a NUMERIC (u64/i64/f64) variable — wide accumulator,
|
|
36
36
|
* one finalize range check; overflow is the engine's typed runtime error —
|
|
37
37
|
* of a measured interval in a following stage. Bool stays refused: a
|
|
38
|
-
* quantifier is not an addition
|
|
38
|
+
* quantifier is not an addition.
|
|
39
39
|
*/
|
|
40
40
|
function sum<const O extends AnyVar>(over: O): Agg<"sum", O> {
|
|
41
41
|
return aggregate("sum", over)
|