@bjornpagen/bumbledb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/README.md +84 -0
- package/dist/brand.d.ts +59 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +47 -0
- package/dist/brand.js.map +1 -0
- package/dist/closed.d.ts +97 -0
- package/dist/closed.d.ts.map +1 -0
- package/dist/closed.js +107 -0
- package/dist/closed.js.map +1 -0
- package/dist/count.d.ts +55 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +92 -0
- package/dist/count.js.map +1 -0
- package/dist/db.d.ts +341 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +1016 -0
- package/dist/db.js.map +1 -0
- package/dist/exhume.d.ts +130 -0
- package/dist/exhume.d.ts.map +1 -0
- package/dist/exhume.js +145 -0
- package/dist/exhume.js.map +1 -0
- package/dist/face.d.ts +91 -0
- package/dist/face.d.ts.map +1 -0
- package/dist/face.js +69 -0
- package/dist/face.js.map +1 -0
- package/dist/fields.d.ts +187 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +204 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lower.d.ts +34 -0
- package/dist/lower.d.ts.map +1 -0
- package/dist/lower.js +105 -0
- package/dist/lower.js.map +1 -0
- package/dist/marshal.d.ts +79 -0
- package/dist/marshal.d.ts.map +1 -0
- package/dist/marshal.js +167 -0
- package/dist/marshal.js.map +1 -0
- package/dist/native.d.ts +532 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +64 -0
- package/dist/native.js.map +1 -0
- package/dist/query/atom.d.ts +285 -0
- package/dist/query/atom.d.ts.map +1 -0
- package/dist/query/atom.js +281 -0
- package/dist/query/atom.js.map +1 -0
- package/dist/query/lower.d.ts +145 -0
- package/dist/query/lower.d.ts.map +1 -0
- package/dist/query/lower.js +604 -0
- package/dist/query/lower.js.map +1 -0
- package/dist/query/predicate.d.ts +101 -0
- package/dist/query/predicate.d.ts.map +1 -0
- package/dist/query/predicate.js +85 -0
- package/dist/query/predicate.js.map +1 -0
- package/dist/query/run.d.ts +30 -0
- package/dist/query/run.d.ts.map +1 -0
- package/dist/query/run.js +94 -0
- package/dist/query/run.js.map +1 -0
- package/dist/query/scope.d.ts +168 -0
- package/dist/query/scope.d.ts.map +1 -0
- package/dist/query/scope.js +134 -0
- package/dist/query/scope.js.map +1 -0
- package/dist/query/select.d.ts +106 -0
- package/dist/query/select.d.ts.map +1 -0
- package/dist/query/select.js +69 -0
- package/dist/query/select.js.map +1 -0
- package/dist/relation.d.ts +120 -0
- package/dist/relation.d.ts.map +1 -0
- package/dist/relation.js +108 -0
- package/dist/relation.js.map +1 -0
- package/dist/schema.d.ts +50 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +235 -0
- package/dist/schema.js.map +1 -0
- package/dist/spec.d.ts +218 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +154 -0
- package/dist/spec.js.map +1 -0
- package/dist/statements.d.ts +91 -0
- package/dist/statements.d.ts.map +1 -0
- package/dist/statements.js +101 -0
- package/dist/statements.js.map +1 -0
- package/package.json +66 -0
- package/src/brand.ts +82 -0
- package/src/closed.ts +228 -0
- package/src/count.ts +117 -0
- package/src/db.ts +1519 -0
- package/src/exhume.ts +243 -0
- package/src/face.ts +161 -0
- package/src/fields.ts +385 -0
- package/src/index.ts +185 -0
- package/src/lower.ts +118 -0
- package/src/marshal.ts +220 -0
- package/src/native.ts +576 -0
- package/src/query/atom.ts +556 -0
- package/src/query/lower.ts +855 -0
- package/src/query/predicate.ts +195 -0
- package/src/query/run.ts +106 -0
- package/src/query/scope.ts +301 -0
- package/src/query/select.ts +140 -0
- package/src/relation.ts +252 -0
- package/src/schema.ts +297 -0
- package/src/spec.ts +325 -0
- package/src/statements.ts +148 -0
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field type constructors — the value half of the `schema!` field grammar
|
|
3
|
+
* (`docs/architecture/70-api.md`): `bool`, `u64`, `i64`, `str`, `bytes(n)`,
|
|
4
|
+
* `interval(u64|i64[, width])`, each a plain frozen value carrying its
|
|
5
|
+
* structural type at runtime and its host value type in a phantom generic.
|
|
6
|
+
* Newtypes are DECLARATION-FIRST, one spelling only (owner ruling
|
|
7
|
+
* 2026-07-16): `const AccountId = u64.newtype("AccountId")` declares the
|
|
8
|
+
* brand ONCE as a value that IS the field, paired with
|
|
9
|
+
* `type AccountId = Infer<typeof AccountId>` for signatures; every field
|
|
10
|
+
* position references the declared value (`holder: HolderId`). The macro's
|
|
11
|
+
* refusals are reproduced representationally: `.newtype` exists only where
|
|
12
|
+
* Rust's `as` is legal (u64, i64, bytes, intervals — never bool/str),
|
|
13
|
+
* `.fresh` exists only on declared u64 newtypes (the macro demands `as
|
|
14
|
+
* NewType` on fresh fields), and no field-level constraint vocabulary of
|
|
15
|
+
* any kind exists — `unique`/`fk` are unwritable, not rejected.
|
|
16
|
+
*/
|
|
17
|
+
import type { Brand, Interval, IntervalValue } from "#brand.ts";
|
|
18
|
+
import { phantom } from "#brand.ts";
|
|
19
|
+
import type { LiteralSpec, ValueTypeSpec } from "#spec.ts";
|
|
20
|
+
/**
|
|
21
|
+
* A closed relation's roster as seen from a referencing field: the handle
|
|
22
|
+
* namespace `where()` selections and ground axioms resolve bare handles
|
|
23
|
+
* through (the macro's own rule: a handle is legal exactly on a field whose
|
|
24
|
+
* newtype is a closed relation's handle newtype).
|
|
25
|
+
*/
|
|
26
|
+
interface ClosedRoster {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly handles: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One field's runtime description: structural type, host newtype name, the
|
|
32
|
+
* `fresh` mint mark (`minted` — the property name `fresh` is taken by the
|
|
33
|
+
* builder surface), and the closed-relation reference when the field is a
|
|
34
|
+
* closed relation's id type.
|
|
35
|
+
*/
|
|
36
|
+
interface FieldData<Minted extends boolean = boolean> {
|
|
37
|
+
readonly type: ValueTypeSpec;
|
|
38
|
+
readonly newtype: string | undefined;
|
|
39
|
+
readonly minted: Minted;
|
|
40
|
+
readonly closed: ClosedRoster | undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The base shape every field value shares: runtime data plus the phantom
|
|
44
|
+
* host value type `V` (never present at runtime).
|
|
45
|
+
*/
|
|
46
|
+
interface Field<V> {
|
|
47
|
+
readonly data: FieldData;
|
|
48
|
+
readonly [phantom]?: V;
|
|
49
|
+
}
|
|
50
|
+
/** Extracts a field value's host value type from its phantom. */
|
|
51
|
+
type FieldValue<F> = F extends Field<infer V> ? V : never;
|
|
52
|
+
/** Any field value, whatever its host value type. */
|
|
53
|
+
type AnyField = Field<unknown>;
|
|
54
|
+
/** The `bool` field: host type `boolean`. No `.newtype`, no `.fresh` (macro parity). */
|
|
55
|
+
interface BoolField extends Field<boolean> {
|
|
56
|
+
readonly data: FieldData<false>;
|
|
57
|
+
}
|
|
58
|
+
/** The `str` field: host type `string`. No `.newtype`, no `.fresh` (macro parity). */
|
|
59
|
+
interface StrField extends Field<string> {
|
|
60
|
+
readonly data: FieldData<false>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A `fresh`-marked u64 newtype field — `id: AccountId.fresh` (Rust: `id:
|
|
64
|
+
* u64 as AccountId, fresh`). Terminal: the mark implies the key
|
|
65
|
+
* `R(field) -> R`, which the ENGINE materializes
|
|
66
|
+
* (`SchemaDescriptor::materialized_statements`); `schema()` rejects an
|
|
67
|
+
* explicit duplicate of it (macro parity).
|
|
68
|
+
*/
|
|
69
|
+
interface FreshU64Newtype<Name extends string> extends Field<Brand<bigint, Name>> {
|
|
70
|
+
readonly data: FieldData<true>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A declared u64 newtype — `const AccountId = u64.newtype("AccountId")`
|
|
74
|
+
* (Rust: `u64 as AccountId`). The value IS the field: relation blocks
|
|
75
|
+
* reference it (`holder: HolderId`). `.fresh` marks it as minted; the
|
|
76
|
+
* property exists ONLY here (the macro demands `as NewType` on fresh
|
|
77
|
+
* fields, so bare-u64 fresh is unwritable).
|
|
78
|
+
*/
|
|
79
|
+
interface U64Newtype<Name extends string> extends Field<Brand<bigint, Name>> {
|
|
80
|
+
readonly data: FieldData<false>;
|
|
81
|
+
readonly fresh: FreshU64Newtype<Name>;
|
|
82
|
+
}
|
|
83
|
+
/** The bare `u64` field; `.newtype(name)` declares a branded u64 newtype. */
|
|
84
|
+
interface U64Field extends Field<bigint> {
|
|
85
|
+
readonly data: FieldData<false>;
|
|
86
|
+
newtype<const Name extends string>(name: Name): U64Newtype<Name>;
|
|
87
|
+
}
|
|
88
|
+
/** A declared i64 newtype. Terminal: `fresh` is legal on u64 only. */
|
|
89
|
+
interface I64Newtype<Name extends string> extends Field<Brand<bigint, Name>> {
|
|
90
|
+
readonly data: FieldData<false>;
|
|
91
|
+
}
|
|
92
|
+
/** The bare `i64` field; `.newtype(name)` declares a branded i64 newtype. */
|
|
93
|
+
interface I64Field extends Field<bigint> {
|
|
94
|
+
readonly data: FieldData<false>;
|
|
95
|
+
newtype<const Name extends string>(name: Name): I64Newtype<Name>;
|
|
96
|
+
}
|
|
97
|
+
/** A declared `bytes<N>` newtype (no order derived — no comparators exist). */
|
|
98
|
+
interface BytesNewtype<Name extends string> extends Field<Brand<Uint8Array, Name>> {
|
|
99
|
+
readonly data: FieldData<false>;
|
|
100
|
+
}
|
|
101
|
+
/** A `bytes<N>` field; `.newtype(name)` declares a branded bytes newtype. */
|
|
102
|
+
interface BytesField extends Field<Uint8Array> {
|
|
103
|
+
readonly data: FieldData<false>;
|
|
104
|
+
newtype<const Name extends string>(name: Name): BytesNewtype<Name>;
|
|
105
|
+
}
|
|
106
|
+
/** A declared interval newtype — Rust: `interval<i64> as ActiveDuring`. */
|
|
107
|
+
interface IntervalNewtype<Name extends string> extends Field<Interval<Name>> {
|
|
108
|
+
readonly data: FieldData<false>;
|
|
109
|
+
}
|
|
110
|
+
/** An interval field; `.newtype(name)` brands the whole `{ start, end }` object. */
|
|
111
|
+
interface IntervalField extends Field<IntervalValue> {
|
|
112
|
+
readonly data: FieldData<false>;
|
|
113
|
+
newtype<const Name extends string>(name: Name): IntervalNewtype<Name>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The branded value type of a declared newtype — the type half of the
|
|
117
|
+
* declaration-first pairing (owner ruling 2026-07-16): `const AccountId =
|
|
118
|
+
* u64.newtype("AccountId")` + `type AccountId = Infer<typeof AccountId>`.
|
|
119
|
+
* Reads the phantom, so it works on any field value (a closed relation's
|
|
120
|
+
* `id` field infers its handle brand the same way).
|
|
121
|
+
*/
|
|
122
|
+
type Infer<F extends AnyField> = F extends Field<infer V> ? V : never;
|
|
123
|
+
/**
|
|
124
|
+
* A closed relation's id field constructor (`Kind.id`) — a u64 field
|
|
125
|
+
* pre-branded with the closed relation's handle newtype, for use in other
|
|
126
|
+
* relations' field blocks (`kind: Kind.id`). Terminal: its newtype IS the
|
|
127
|
+
* closed relation, so `.newtype` and `.fresh` do not exist.
|
|
128
|
+
*/
|
|
129
|
+
interface ClosedIdField<Name extends string> extends Field<Brand<bigint, Name>> {
|
|
130
|
+
readonly data: FieldData<false>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Rejects a declaration name that JavaScript would re-order. Declaration
|
|
134
|
+
* order = ordinal ids is the law relations, columns, and schemas all lean
|
|
135
|
+
* on, and it is carried by object-literal key order — which ECMA-262's
|
|
136
|
+
* OrdinaryOwnPropertyKeys breaks for integer-index keys (they enumerate
|
|
137
|
+
* first, ascending, regardless of where they were written). An
|
|
138
|
+
* integer-index name would silently reorder its declaration, so it is a
|
|
139
|
+
* construction error, exactly as an unparseable name is a macro expansion
|
|
140
|
+
* error.
|
|
141
|
+
*/
|
|
142
|
+
declare function assertDeclarationOrderKey(where: string, name: string): void;
|
|
143
|
+
/**
|
|
144
|
+
* Builds one frozen {@link FieldData}. Internal seam shared by the field
|
|
145
|
+
* constructors here and by `closed()` (which mints {@link ClosedIdField}
|
|
146
|
+
* values against its own roster).
|
|
147
|
+
*/
|
|
148
|
+
declare function fieldData<Minted extends boolean>(type: ValueTypeSpec, newtype: string | undefined, minted: Minted, closed: ClosedRoster | undefined): FieldData<Minted>;
|
|
149
|
+
/** The one `u64` field constructor value. */
|
|
150
|
+
declare const u64: U64Field;
|
|
151
|
+
/** The one `i64` field constructor value. */
|
|
152
|
+
declare const i64: I64Field;
|
|
153
|
+
/** The one `bool` field constructor value. */
|
|
154
|
+
declare const bool: BoolField;
|
|
155
|
+
/** The one `str` field constructor value. */
|
|
156
|
+
declare const str: StrField;
|
|
157
|
+
/**
|
|
158
|
+
* The `bytes<N>` field constructor. The width is mandatory and part of the
|
|
159
|
+
* type; `len` is validated to 1..=64 here because the grammar pins that
|
|
160
|
+
* range at declaration (`docs/architecture/70-api.md` § the `schema!`
|
|
161
|
+
* grammar: N ∈ 1..=64 — bare `bytes` does not parse), the macro-expansion
|
|
162
|
+
* boundary's analog being construction.
|
|
163
|
+
*/
|
|
164
|
+
declare function bytes(len: number): BytesField;
|
|
165
|
+
/**
|
|
166
|
+
* The interval field constructor — `interval(u64)` / `interval(i64)` for
|
|
167
|
+
* the general type (rays representable), `interval(u64, w)` for the
|
|
168
|
+
* fixed-width family whose width IS the type. The element is spelled with
|
|
169
|
+
* the u64/i64 field constructor values themselves, never a string. `width
|
|
170
|
+
* >= 1` is validated here because the grammar pins it at declaration
|
|
171
|
+
* (`docs/architecture/70-api.md`: w ≥ 1; `interval<u64, 0>` is an
|
|
172
|
+
* expansion error naming the field).
|
|
173
|
+
*/
|
|
174
|
+
declare function interval(element: U64Field | I64Field, width?: bigint): IntervalField;
|
|
175
|
+
/**
|
|
176
|
+
* Lowers one host literal at its field position to the wire
|
|
177
|
+
* {@link LiteralSpec} — the selection-literal machine ground axioms and
|
|
178
|
+
* `where()` bindings both ride (one machine, same errors — the macro's own
|
|
179
|
+
* rule). A value on a closed-reference field resolves to its handle NAME
|
|
180
|
+
* (the id is re-verified against the roster: an out-of-roster id is a
|
|
181
|
+
* construction error); everything else lowers to a plain value tagged by
|
|
182
|
+
* the field's structural type.
|
|
183
|
+
*/
|
|
184
|
+
declare function literalOf(field: FieldData, value: unknown): LiteralSpec;
|
|
185
|
+
export type { AnyField, BoolField, BytesField, BytesNewtype, ClosedIdField, ClosedRoster, Field, FieldData, FieldValue, FreshU64Newtype, I64Field, I64Newtype, Infer, IntervalField, IntervalNewtype, StrField, U64Field, U64Newtype };
|
|
186
|
+
export { assertDeclarationOrderKey, bool, bytes, fieldData, i64, interval, literalOf, str, u64 };
|
|
187
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAoD1D;;;;;GAKG;AACH,UAAU,YAAY;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAED;;;;;GAKG;AACH,UAAU,SAAS,CAAC,MAAM,SAAS,OAAO,GAAG,OAAO;IACnD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CA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AAE,KAAK,CAAC,EAAE,MAAM,GAAG,aAAa,CAiB7E;AAED;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,WAAW,CAsChE;AAED,YAAY,EACX,QAAQ,EACR,SAAS,EACT,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,KAAK,EACL,SAAS,EACT,UAAU,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,CAAA;AACD,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field type constructors — the value half of the `schema!` field grammar
|
|
3
|
+
* (`docs/architecture/70-api.md`): `bool`, `u64`, `i64`, `str`, `bytes(n)`,
|
|
4
|
+
* `interval(u64|i64[, width])`, each a plain frozen value carrying its
|
|
5
|
+
* structural type at runtime and its host value type in a phantom generic.
|
|
6
|
+
* Newtypes are DECLARATION-FIRST, one spelling only (owner ruling
|
|
7
|
+
* 2026-07-16): `const AccountId = u64.newtype("AccountId")` declares the
|
|
8
|
+
* brand ONCE as a value that IS the field, paired with
|
|
9
|
+
* `type AccountId = Infer<typeof AccountId>` for signatures; every field
|
|
10
|
+
* position references the declared value (`holder: HolderId`). The macro's
|
|
11
|
+
* refusals are reproduced representationally: `.newtype` exists only where
|
|
12
|
+
* Rust's `as` is legal (u64, i64, bytes, intervals — never bool/str),
|
|
13
|
+
* `.fresh` exists only on declared u64 newtypes (the macro demands `as
|
|
14
|
+
* NewType` on fresh fields), and no field-level constraint vocabulary of
|
|
15
|
+
* any kind exists — `unique`/`fk` are unwritable, not rejected.
|
|
16
|
+
*/
|
|
17
|
+
import * as errors from "@superbuilders/errors";
|
|
18
|
+
import { phantom } from "#brand.ts";
|
|
19
|
+
/**
|
|
20
|
+
* The typed shape refusal of the selection-literal machine — reached only
|
|
21
|
+
* through ill-typed input (the well-typed surfaces make it unrepresentable).
|
|
22
|
+
*/
|
|
23
|
+
function literalShapeError(expected, value) {
|
|
24
|
+
return errors.new(`selection literal shape mismatch: expected ${expected}, got ${typeof value}`);
|
|
25
|
+
}
|
|
26
|
+
/** Narrows an interval literal: a plain object with bigint start/end. */
|
|
27
|
+
function isIntervalLiteral(value) {
|
|
28
|
+
return (typeof value === "object" &&
|
|
29
|
+
value !== null &&
|
|
30
|
+
"start" in value &&
|
|
31
|
+
"end" in value &&
|
|
32
|
+
typeof value.start === "bigint" &&
|
|
33
|
+
typeof value.end === "bigint");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolves one closed-handle literal: the branded id (a bigint at runtime)
|
|
37
|
+
* back to its handle NAME through the roster — an out-of-roster id is a
|
|
38
|
+
* construction error, the belt the type level cannot provide against
|
|
39
|
+
* forged brands.
|
|
40
|
+
*/
|
|
41
|
+
function handleLiteral(closed, value) {
|
|
42
|
+
if (typeof value !== "bigint") {
|
|
43
|
+
throw literalShapeError(`a ${closed.name} handle id (bigint)`, value);
|
|
44
|
+
}
|
|
45
|
+
const handle = closed.handles[Number(value)];
|
|
46
|
+
if (handle === undefined) {
|
|
47
|
+
throw errors.new(`closed relation ${closed.name} has no handle with id ${value} (roster holds ${closed.handles.length})`);
|
|
48
|
+
}
|
|
49
|
+
return { kind: "handle", handle };
|
|
50
|
+
}
|
|
51
|
+
/** Lowers one interval literal at its element type. */
|
|
52
|
+
function intervalLiteral(element, value) {
|
|
53
|
+
if (!isIntervalLiteral(value)) {
|
|
54
|
+
throw literalShapeError("interval ({ start, end } bigints)", value);
|
|
55
|
+
}
|
|
56
|
+
if (element === "u64") {
|
|
57
|
+
return { kind: "value", value: { kind: "intervalU64", start: value.start, end: value.end } };
|
|
58
|
+
}
|
|
59
|
+
return { kind: "value", value: { kind: "intervalI64", start: value.start, end: value.end } };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Rejects a declaration name that JavaScript would re-order. Declaration
|
|
63
|
+
* order = ordinal ids is the law relations, columns, and schemas all lean
|
|
64
|
+
* on, and it is carried by object-literal key order — which ECMA-262's
|
|
65
|
+
* OrdinaryOwnPropertyKeys breaks for integer-index keys (they enumerate
|
|
66
|
+
* first, ascending, regardless of where they were written). An
|
|
67
|
+
* integer-index name would silently reorder its declaration, so it is a
|
|
68
|
+
* construction error, exactly as an unparseable name is a macro expansion
|
|
69
|
+
* error.
|
|
70
|
+
*/
|
|
71
|
+
function assertDeclarationOrderKey(where, name) {
|
|
72
|
+
if (/^(?:0|[1-9][0-9]*)$/.test(name)) {
|
|
73
|
+
throw errors.new(`${where}: name ${name} is an integer index — JavaScript object keys re-order integer indices, breaking the declaration-order law; use a non-numeric name`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Builds one frozen {@link FieldData}. Internal seam shared by the field
|
|
78
|
+
* constructors here and by `closed()` (which mints {@link ClosedIdField}
|
|
79
|
+
* values against its own roster).
|
|
80
|
+
*/
|
|
81
|
+
function fieldData(type, newtype, minted, closed) {
|
|
82
|
+
return Object.freeze({ type: Object.freeze(type), newtype, minted, closed });
|
|
83
|
+
}
|
|
84
|
+
/** The one `u64` field constructor value. */
|
|
85
|
+
const u64 = Object.freeze({
|
|
86
|
+
data: fieldData({ kind: "u64" }, undefined, false, undefined),
|
|
87
|
+
newtype(name) {
|
|
88
|
+
const fresh = Object.freeze({
|
|
89
|
+
data: fieldData({ kind: "u64" }, name, true, undefined)
|
|
90
|
+
});
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
data: fieldData({ kind: "u64" }, name, false, undefined),
|
|
93
|
+
fresh
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
/** The one `i64` field constructor value. */
|
|
98
|
+
const i64 = Object.freeze({
|
|
99
|
+
data: fieldData({ kind: "i64" }, undefined, false, undefined),
|
|
100
|
+
newtype(name) {
|
|
101
|
+
return Object.freeze({ data: fieldData({ kind: "i64" }, name, false, undefined) });
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
/** The one `bool` field constructor value. */
|
|
105
|
+
const bool = Object.freeze({
|
|
106
|
+
data: fieldData({ kind: "bool" }, undefined, false, undefined)
|
|
107
|
+
});
|
|
108
|
+
/** The one `str` field constructor value. */
|
|
109
|
+
const str = Object.freeze({
|
|
110
|
+
data: fieldData({ kind: "string" }, undefined, false, undefined)
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* The `bytes<N>` field constructor. The width is mandatory and part of the
|
|
114
|
+
* type; `len` is validated to 1..=64 here because the grammar pins that
|
|
115
|
+
* range at declaration (`docs/architecture/70-api.md` § the `schema!`
|
|
116
|
+
* grammar: N ∈ 1..=64 — bare `bytes` does not parse), the macro-expansion
|
|
117
|
+
* boundary's analog being construction.
|
|
118
|
+
*/
|
|
119
|
+
function bytes(len) {
|
|
120
|
+
if (!Number.isInteger(len) || len < 1 || len > 64) {
|
|
121
|
+
throw errors.new(`bytes width must be an integer in 1..=64 (got ${len}) — docs/architecture/70-api.md pins the range at declaration`);
|
|
122
|
+
}
|
|
123
|
+
return Object.freeze({
|
|
124
|
+
data: fieldData({ kind: "fixedBytes", len }, undefined, false, undefined),
|
|
125
|
+
newtype(name) {
|
|
126
|
+
return Object.freeze({ data: fieldData({ kind: "fixedBytes", len }, name, false, undefined) });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The interval field constructor — `interval(u64)` / `interval(i64)` for
|
|
132
|
+
* the general type (rays representable), `interval(u64, w)` for the
|
|
133
|
+
* fixed-width family whose width IS the type. The element is spelled with
|
|
134
|
+
* the u64/i64 field constructor values themselves, never a string. `width
|
|
135
|
+
* >= 1` is validated here because the grammar pins it at declaration
|
|
136
|
+
* (`docs/architecture/70-api.md`: w ≥ 1; `interval<u64, 0>` is an
|
|
137
|
+
* expansion error naming the field).
|
|
138
|
+
*/
|
|
139
|
+
function interval(element, width) {
|
|
140
|
+
const elementKind = element.data.type.kind;
|
|
141
|
+
if (elementKind !== "u64" && elementKind !== "i64") {
|
|
142
|
+
throw errors.new(`interval element must be the u64 or i64 field constructor (got ${elementKind})`);
|
|
143
|
+
}
|
|
144
|
+
if (width !== undefined && width < 1n) {
|
|
145
|
+
throw errors.new(`interval width must be >= 1 (got ${width}) — docs/architecture/70-api.md pins w >= 1 at declaration`);
|
|
146
|
+
}
|
|
147
|
+
const type = { kind: "interval", element: elementKind, width };
|
|
148
|
+
return Object.freeze({
|
|
149
|
+
data: fieldData(type, undefined, false, undefined),
|
|
150
|
+
newtype(name) {
|
|
151
|
+
return Object.freeze({ data: fieldData(type, name, false, undefined) });
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Lowers one host literal at its field position to the wire
|
|
157
|
+
* {@link LiteralSpec} — the selection-literal machine ground axioms and
|
|
158
|
+
* `where()` bindings both ride (one machine, same errors — the macro's own
|
|
159
|
+
* rule). A value on a closed-reference field resolves to its handle NAME
|
|
160
|
+
* (the id is re-verified against the roster: an out-of-roster id is a
|
|
161
|
+
* construction error); everything else lowers to a plain value tagged by
|
|
162
|
+
* the field's structural type.
|
|
163
|
+
*/
|
|
164
|
+
function literalOf(field, value) {
|
|
165
|
+
if (field.closed !== undefined) {
|
|
166
|
+
return handleLiteral(field.closed, value);
|
|
167
|
+
}
|
|
168
|
+
switch (field.type.kind) {
|
|
169
|
+
case "bool": {
|
|
170
|
+
if (typeof value !== "boolean") {
|
|
171
|
+
throw literalShapeError("boolean", value);
|
|
172
|
+
}
|
|
173
|
+
return { kind: "value", value: { kind: "bool", value } };
|
|
174
|
+
}
|
|
175
|
+
case "u64": {
|
|
176
|
+
if (typeof value !== "bigint") {
|
|
177
|
+
throw literalShapeError("bigint", value);
|
|
178
|
+
}
|
|
179
|
+
return { kind: "value", value: { kind: "u64", value } };
|
|
180
|
+
}
|
|
181
|
+
case "i64": {
|
|
182
|
+
if (typeof value !== "bigint") {
|
|
183
|
+
throw literalShapeError("bigint", value);
|
|
184
|
+
}
|
|
185
|
+
return { kind: "value", value: { kind: "i64", value } };
|
|
186
|
+
}
|
|
187
|
+
case "string": {
|
|
188
|
+
if (typeof value !== "string") {
|
|
189
|
+
throw literalShapeError("string", value);
|
|
190
|
+
}
|
|
191
|
+
return { kind: "value", value: { kind: "string", value } };
|
|
192
|
+
}
|
|
193
|
+
case "fixedBytes": {
|
|
194
|
+
if (!(value instanceof Uint8Array)) {
|
|
195
|
+
throw literalShapeError("Uint8Array", value);
|
|
196
|
+
}
|
|
197
|
+
return { kind: "value", value: { kind: "fixedBytes", value } };
|
|
198
|
+
}
|
|
199
|
+
case "interval":
|
|
200
|
+
return intervalLiteral(field.type.element, value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export { assertDeclarationOrderKey, bool, bytes, fieldData, i64, interval, literalOf, str, u64 };
|
|
204
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC;;;GAGG;AACH,SAAS,iBAAiB,CAAC,QAAgB,EAAE,KAAc;IAC1D,OAAO,MAAM,CAAC,GAAG,CAAC,8CAA8C,QAAQ,SAAS,OAAO,KAAK,EAAE,CAAC,CAAA;AACjG,CAAC;AAED,yEAAyE;AACzE,SAAS,iBAAiB,CAAC,KAAc;IACxC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK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ACD,KAAK,UAAU;YACd,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACnD,CAAC;AACF,CAAC;AAsBD,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bjornpagen/bumbledb — the type-theoretic TypeScript SDK for the
|
|
3
|
+
* bumbledb embedded relational engine. Public surface: the type kernel
|
|
4
|
+
* (brands, fields, `relation()`, `closed()` — PRD-05), the statement
|
|
5
|
+
* algebra with `schema()` and `SchemaSpec` lowering (PRD-06), the `Db`
|
|
6
|
+
* runtime (path-cached stores, transactions, typed violations, scoped
|
|
7
|
+
* snapshot reads, the witnessed write loop with `abandon` — PRD-07, zero
|
|
8
|
+
* closables), the query surface (Datalog as values: scoped vars/params,
|
|
9
|
+
* atoms, negation, conditions, aggregates, engine recursion via predicates,
|
|
10
|
+
* `db.prepare` as a plain value — PRD-08), and the exhume surface
|
|
11
|
+
* (`Db.exhume` — the one schema-independent read path: the store's
|
|
12
|
+
* self-described shapes and raw facts by name, deliberately untyped —
|
|
13
|
+
* course-serialization PRD-02). The raw native bridge is not exported (the
|
|
14
|
+
* PRD-03 stub died here as scheduled).
|
|
15
|
+
*/
|
|
16
|
+
export type { Brand, Interval, IntervalValue } from "#brand.ts";
|
|
17
|
+
export { span } from "#brand.ts";
|
|
18
|
+
export type { AnyClosed, AxiomRow, Axioms, Closed, ClosedColumn, ClosedCore, ClosedData, ClosedRow, PayloadField } from "#closed.ts";
|
|
19
|
+
export { closed } from "#closed.ts";
|
|
20
|
+
export type { Count } from "#count.ts";
|
|
21
|
+
export { atLeast, atMost, between, exactly, none } from "#count.ts";
|
|
22
|
+
export type { Abandon, DeclaredKeyFact, DeltaBuild, MemberRelation, OffendingFact, Prepared, ReadScope, Tx, Violation, WitnessedWriteResult, WriteResult } from "#db.ts";
|
|
23
|
+
export { abandon, Db } from "#db.ts";
|
|
24
|
+
export type { Exhumed, ExhumedAxiom, ExhumedDescriptor, ExhumedFact, ExhumedField, ExhumedRelation } from "#exhume.ts";
|
|
25
|
+
export { ErrExhumeCorruption, ErrExhumeFormatMismatch, ErrExhumeNoDescriptor } from "#exhume.ts";
|
|
26
|
+
export type { AnyFace, Arity, Face, FaceArityMismatch, FaceData, FaceFields, FaceOwner, FaceSource, OneOf, SameArity } from "#face.ts";
|
|
27
|
+
export { on, oneOf } from "#face.ts";
|
|
28
|
+
export type { AnyField, BoolField, BytesField, BytesNewtype, ClosedIdField, ClosedRoster, Field, FieldData, FieldValue, FreshU64Newtype, I64Field, I64Newtype, Infer, IntervalField, IntervalNewtype, StrField, U64Field, U64Newtype } from "#fields.ts";
|
|
29
|
+
export { bool, bytes, i64, interval, str, u64 } from "#fields.ts";
|
|
30
|
+
export { lower, lowerClosed, lowerRelation } from "#lower.ts";
|
|
31
|
+
export type { KeyFact, Minted } from "#marshal.ts";
|
|
32
|
+
export type { FactValue, OccurrenceDrift, ProgramIr, Staleness, StatementKindTag } from "#native.ts";
|
|
33
|
+
export type { AnyBodyItem, AnyCondition, ComparisonItem, ConditionTreeItem, Duration, MatchAtom, MatchInput, TermInput } from "#query/atom.ts";
|
|
34
|
+
export { ALLEN, allen, and, covers, duration, ge, gt, is, le, lt, match, ne, not, or } from "#query/atom.ts";
|
|
35
|
+
export type { AnyQuery, Query, QueryBuild, QueryParams, QueryRow, Scope } from "#query/lower.ts";
|
|
36
|
+
export { lowerQuery, query } from "#query/lower.ts";
|
|
37
|
+
export type { Predicate, PredicateBindings, PredicateRuleInput, PredicateSelf } from "#query/predicate.ts";
|
|
38
|
+
export type { MaskParam, Param, ParamSet, ParamsRecord, Var } from "#query/scope.ts";
|
|
39
|
+
export type { Aggregate, RowOf, SelectShape } from "#query/select.ts";
|
|
40
|
+
export { argmax, argmin, count, countDistinct, max, min, pack, sum } from "#query/select.ts";
|
|
41
|
+
export type { AnyRelation, AnySelected, Fact, FieldRef, FieldRefs, FieldsShape, FreshKeys, InsertFact, Relation, RelationData, RelationField, RelationFields, Selected, SelectionBinding, SelectionInput } from "#relation.ts";
|
|
42
|
+
export { relation } from "#relation.ts";
|
|
43
|
+
export type { AnySchema, Schema, SchemaRelation, SchemaRelations } from "#schema.ts";
|
|
44
|
+
export { schema } from "#schema.ts";
|
|
45
|
+
export type { FieldSpec, LiteralSetSpec, LiteralSpec, RelationSpec, RowSpec, SchemaSpec, SideSpec, StatementSpec, ValueSpec, ValueTypeSpec, WindowSpec } from "#spec.ts";
|
|
46
|
+
export { renderLiteral, renderLiteralSet, renderWindow } from "#spec.ts";
|
|
47
|
+
export type { KeyStatement, Statement, StatementData } from "#statements.ts";
|
|
48
|
+
export { contained, key, mirrors, renderStatement, window } from "#statements.ts";
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,YAAY,EACX,SAAS,EACT,QAAQ,EACR,MAAM,EACN,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,YAAY,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACnE,YAAY,EACX,OAAO,EACP,e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cAAc,EACd,WAAW,EACX,YAAY,EACZ,OAAO,EACP,UAAU,EACV,QAAQ,EACR,aAAa,EACb,SAAS,EACT,aAAa,EACb,UAAU,EACV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACxE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bjornpagen/bumbledb — the type-theoretic TypeScript SDK for the
|
|
3
|
+
* bumbledb embedded relational engine. Public surface: the type kernel
|
|
4
|
+
* (brands, fields, `relation()`, `closed()` — PRD-05), the statement
|
|
5
|
+
* algebra with `schema()` and `SchemaSpec` lowering (PRD-06), the `Db`
|
|
6
|
+
* runtime (path-cached stores, transactions, typed violations, scoped
|
|
7
|
+
* snapshot reads, the witnessed write loop with `abandon` — PRD-07, zero
|
|
8
|
+
* closables), the query surface (Datalog as values: scoped vars/params,
|
|
9
|
+
* atoms, negation, conditions, aggregates, engine recursion via predicates,
|
|
10
|
+
* `db.prepare` as a plain value — PRD-08), and the exhume surface
|
|
11
|
+
* (`Db.exhume` — the one schema-independent read path: the store's
|
|
12
|
+
* self-described shapes and raw facts by name, deliberately untyped —
|
|
13
|
+
* course-serialization PRD-02). The raw native bridge is not exported (the
|
|
14
|
+
* PRD-03 stub died here as scheduled).
|
|
15
|
+
*/
|
|
16
|
+
export { span } from "#brand.ts";
|
|
17
|
+
export { closed } from "#closed.ts";
|
|
18
|
+
export { atLeast, atMost, between, exactly, none } from "#count.ts";
|
|
19
|
+
export { abandon, Db } from "#db.ts";
|
|
20
|
+
export { ErrExhumeCorruption, ErrExhumeFormatMismatch, ErrExhumeNoDescriptor } from "#exhume.ts";
|
|
21
|
+
export { on, oneOf } from "#face.ts";
|
|
22
|
+
export { bool, bytes, i64, interval, str, u64 } from "#fields.ts";
|
|
23
|
+
export { lower, lowerClosed, lowerRelation } from "#lower.ts";
|
|
24
|
+
export { ALLEN, allen, and, covers, duration, ge, gt, is, le, lt, match, ne, not, or } from "#query/atom.ts";
|
|
25
|
+
export { lowerQuery, query } from "#query/lower.ts";
|
|
26
|
+
export { argmax, argmin, count, countDistinct, max, min, pack, sum } from "#query/select.ts";
|
|
27
|
+
export { relation } from "#relation.ts";
|
|
28
|
+
export { schema } from "#schema.ts";
|
|
29
|
+
export { renderLiteral, renderLiteralSet, renderWindow } from "#spec.ts";
|
|
30
|
+
export { contained, key, mirrors, renderStatement, window } from "#statements.ts";
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAYhC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAcnE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AASpC,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,MAAM,YAAY,CAAA;AAanB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAqBpC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAqB7D,OAAO,EACN,KAAK,EACL,KAAK,EACL,GAAG,EACH,MAAM,EACN,QAAQ,EACR,EAAE,EACF,EAAE,EACF,EAAE,EACF,EAAE,EACF,EAAE,EACF,KAAK,EACL,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,gBAAgB,CAAA;AAUvB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AASnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAkB5F,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAcnC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/lower.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Descriptor lowering: SDK values down to the PRD-01 `SchemaSpec` plain
|
|
3
|
+
* data (`#spec.ts`), which the napi bridge marshals verbatim. Lowering is
|
|
4
|
+
* TOTAL on well-typed inputs — no validation lives here beyond what the
|
|
5
|
+
* types and the construction boundaries already guarantee — and it is the
|
|
6
|
+
* only place statement internals are read for the wire. Ordering is
|
|
7
|
+
* declaration order throughout, and every output object is built with one
|
|
8
|
+
* fixed key order, so serialization is deterministic (byte-stable).
|
|
9
|
+
*/
|
|
10
|
+
import type { AnyClosed } from "#closed.ts";
|
|
11
|
+
import type { AnyRelation } from "#relation.ts";
|
|
12
|
+
import type { AnySchema } from "#schema.ts";
|
|
13
|
+
import type { RelationSpec, SchemaSpec } from "#spec.ts";
|
|
14
|
+
/**
|
|
15
|
+
* Lowers one ordinary relation to its `RelationSpec` fragment: fields in
|
|
16
|
+
* declaration order, `extension: undefined` (the option is the kind).
|
|
17
|
+
*/
|
|
18
|
+
declare function lowerRelation(relation: AnyRelation): RelationSpec;
|
|
19
|
+
/**
|
|
20
|
+
* Lowers one closed relation to its `RelationSpec` fragment: declared
|
|
21
|
+
* intrinsic columns only (the engine materializes the synthetic `id`),
|
|
22
|
+
* the relation's own name as its handle newtype, and the ground axioms in
|
|
23
|
+
* declaration order (row id = index) — the literals were already lowered
|
|
24
|
+
* at `closed()` construction.
|
|
25
|
+
*/
|
|
26
|
+
declare function lowerClosed(member: AnyClosed): RelationSpec;
|
|
27
|
+
/**
|
|
28
|
+
* Lowers a whole theory to the `SchemaSpec` the bridge takes: relations in
|
|
29
|
+
* record declaration order, DECLARED statements only in written order (the
|
|
30
|
+
* engine materializes the fresh-implied and closed auto-keys itself).
|
|
31
|
+
*/
|
|
32
|
+
declare function lower(theory: AnySchema): SchemaSpec;
|
|
33
|
+
export { lower, lowerClosed, lowerRelation };
|
|
34
|
+
//# sourceMappingURL=lower.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lower.d.ts","sourceRoot":"","sources":["../src/lower.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAA;AAC3D,OAAO,KAAK,EAAa,YAAY,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAA;AAkD5F;;;GAGG;AACH,iBAAS,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,CAU1D;AAED;;;;;;GAMG;AACH,iBAAS,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,YAAY,CAapD;AAED;;;;GAIG;AACH,iBAAS,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAQ5C;AAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA"}
|
package/dist/lower.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Descriptor lowering: SDK values down to the PRD-01 `SchemaSpec` plain
|
|
3
|
+
* data (`#spec.ts`), which the napi bridge marshals verbatim. Lowering is
|
|
4
|
+
* TOTAL on well-typed inputs — no validation lives here beyond what the
|
|
5
|
+
* types and the construction boundaries already guarantee — and it is the
|
|
6
|
+
* only place statement internals are read for the wire. Ordering is
|
|
7
|
+
* declaration order throughout, and every output object is built with one
|
|
8
|
+
* fixed key order, so serialization is deterministic (byte-stable).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The relation-kind discriminant: a closed relation's runtime description
|
|
12
|
+
* carries its handle roster, an ordinary relation's never does.
|
|
13
|
+
*/
|
|
14
|
+
function isClosedMember(member) {
|
|
15
|
+
return "handles" in member.data;
|
|
16
|
+
}
|
|
17
|
+
/** Lowers one face to a `SideSpec`: names only, σ as (field, set) pairs. */
|
|
18
|
+
function lowerFace(face) {
|
|
19
|
+
return {
|
|
20
|
+
relation: face.owner.name,
|
|
21
|
+
projection: [...face.projection],
|
|
22
|
+
selection: face.selection.map(function lowerBinding(binding) {
|
|
23
|
+
return [binding.field, binding.set];
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Lowers one statement. `mirrors` stays ONE spec statement
|
|
29
|
+
* (`bidirectional: true`) — the engine performs the `==` lowering to two
|
|
30
|
+
* adjacent containments, `source <= target` first, exactly as the macro
|
|
31
|
+
* does.
|
|
32
|
+
*/
|
|
33
|
+
function lowerStatement(statement) {
|
|
34
|
+
const data = statement.data;
|
|
35
|
+
switch (data.kind) {
|
|
36
|
+
case "key":
|
|
37
|
+
return { kind: "fd", relation: data.owner.name, projection: [...data.projection] };
|
|
38
|
+
case "containment":
|
|
39
|
+
return {
|
|
40
|
+
kind: "containment",
|
|
41
|
+
source: lowerFace(data.source),
|
|
42
|
+
target: lowerFace(data.target),
|
|
43
|
+
bidirectional: data.bidirectional
|
|
44
|
+
};
|
|
45
|
+
case "window":
|
|
46
|
+
return {
|
|
47
|
+
kind: "cardinality",
|
|
48
|
+
target: lowerFace(data.target),
|
|
49
|
+
window: data.window,
|
|
50
|
+
source: lowerFace(data.source)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Lowers one ordinary relation to its `RelationSpec` fragment: fields in
|
|
56
|
+
* declaration order, `extension: undefined` (the option is the kind).
|
|
57
|
+
*/
|
|
58
|
+
function lowerRelation(relation) {
|
|
59
|
+
const fields = relation.data.fields.map(function lowerField(declared) {
|
|
60
|
+
return {
|
|
61
|
+
name: declared.name,
|
|
62
|
+
valueType: declared.field.type,
|
|
63
|
+
newtype: declared.field.newtype,
|
|
64
|
+
fresh: declared.field.minted
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return { name: relation.name, newtype: undefined, fields, extension: undefined };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Lowers one closed relation to its `RelationSpec` fragment: declared
|
|
71
|
+
* intrinsic columns only (the engine materializes the synthetic `id`),
|
|
72
|
+
* the relation's own name as its handle newtype, and the ground axioms in
|
|
73
|
+
* declaration order (row id = index) — the literals were already lowered
|
|
74
|
+
* at `closed()` construction.
|
|
75
|
+
*/
|
|
76
|
+
function lowerClosed(member) {
|
|
77
|
+
const fields = member.data.columns.map(function lowerColumn(column) {
|
|
78
|
+
return {
|
|
79
|
+
name: column.name,
|
|
80
|
+
valueType: column.field.type,
|
|
81
|
+
newtype: column.field.newtype,
|
|
82
|
+
fresh: false
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const extension = member.data.rows.map(function lowerRow(row) {
|
|
86
|
+
return { handle: row.handle, values: row.values };
|
|
87
|
+
});
|
|
88
|
+
return { name: member.name, newtype: member.name, fields, extension };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Lowers a whole theory to the `SchemaSpec` the bridge takes: relations in
|
|
92
|
+
* record declaration order, DECLARED statements only in written order (the
|
|
93
|
+
* engine materializes the fresh-implied and closed auto-keys itself).
|
|
94
|
+
*/
|
|
95
|
+
function lower(theory) {
|
|
96
|
+
const relations = Object.values(theory.relations).map(function lowerMember(member) {
|
|
97
|
+
if (isClosedMember(member)) {
|
|
98
|
+
return lowerClosed(member);
|
|
99
|
+
}
|
|
100
|
+
return lowerRelation(member);
|
|
101
|
+
});
|
|
102
|
+
return { relations, statements: theory.statements.map(lowerStatement) };
|
|
103
|
+
}
|
|
104
|
+
export { lower, lowerClosed, lowerRelation };
|
|
105
|
+
//# sourceMappingURL=lower.js.map
|