@bjornpagen/bumbledb 0.1.0 → 0.3.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/COOKBOOK.md +1450 -0
- package/README.md +69 -30
- package/dist/closed.d.ts +157 -38
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +232 -47
- package/dist/closed.js.map +1 -1
- package/dist/count.d.ts +64 -17
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +37 -14
- package/dist/count.js.map +1 -1
- package/dist/db.d.ts +27 -8
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +33 -10
- package/dist/db.js.map +1 -1
- package/dist/exhume.d.ts +12 -11
- package/dist/exhume.d.ts.map +1 -1
- package/dist/exhume.js +7 -6
- package/dist/exhume.js.map +1 -1
- package/dist/face.d.ts +135 -30
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +44 -19
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +130 -130
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +60 -94
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +29 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -14
- package/dist/index.js.map +1 -1
- package/dist/law.d.ts +224 -0
- package/dist/law.d.ts.map +1 -0
- package/dist/law.js +224 -0
- package/dist/law.js.map +1 -0
- package/dist/lower.d.ts +17 -7
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +66 -24
- package/dist/lower.js.map +1 -1
- package/dist/marshal.d.ts +36 -21
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +41 -25
- package/dist/marshal.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +2 -2
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +370 -174
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +75 -172
- package/dist/query/atom.js.map +1 -1
- package/dist/query/lower.d.ts +312 -109
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +906 -387
- package/dist/query/lower.js.map +1 -1
- package/dist/query/predicate.d.ts +70 -88
- package/dist/query/predicate.d.ts.map +1 -1
- package/dist/query/predicate.js +118 -72
- package/dist/query/predicate.js.map +1 -1
- package/dist/query/run.d.ts +19 -16
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +31 -24
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +178 -127
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +111 -108
- package/dist/query/scope.js.map +1 -1
- package/dist/query/select.d.ts +102 -80
- package/dist/query/select.d.ts.map +1 -1
- package/dist/query/select.js +39 -34
- package/dist/query/select.js.map +1 -1
- package/dist/relation.d.ts +48 -38
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +24 -19
- package/dist/relation.js.map +1 -1
- package/dist/schema.d.ts +41 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +34 -9
- package/dist/schema.js.map +1 -1
- package/dist/spec.d.ts +7 -5
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +91 -36
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +42 -12
- package/dist/statements.js.map +1 -1
- package/package.json +4 -3
- package/src/closed.ts +448 -95
- package/src/count.ts +112 -18
- package/src/db.ts +45 -17
- package/src/exhume.ts +12 -11
- package/src/face.ts +211 -41
- package/src/fields.ts +199 -234
- package/src/index.ts +78 -61
- package/src/law.ts +519 -0
- package/src/lower.ts +82 -27
- package/src/marshal.ts +48 -30
- package/src/native.ts +8 -4
- package/src/query/atom.ts +525 -374
- package/src/query/lower.ts +1469 -538
- package/src/query/predicate.ts +208 -161
- package/src/query/run.ts +35 -25
- package/src/query/scope.ts +264 -218
- package/src/query/select.ts +168 -93
- package/src/relation.ts +47 -47
- package/src/schema.ts +69 -18
- package/src/spec.ts +7 -5
- package/src/statements.ts +124 -41
- package/dist/brand.d.ts +0 -59
- package/dist/brand.d.ts.map +0 -1
- package/dist/brand.js +0 -47
- package/dist/brand.js.map +0 -1
- package/src/brand.ts +0 -82
package/dist/closed.js
CHANGED
|
@@ -1,47 +1,197 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Closed relations (`docs/architecture/10-data-model.md` § closed
|
|
3
3
|
* relations): a vocabulary whose extension is declared in the schema — two
|
|
4
|
-
* tiers, one function. The emission per closed relation mirrors the
|
|
5
|
-
* (host-enum analog): handle CONSTANTS on the value
|
|
6
|
-
* declaration order
|
|
7
|
-
*
|
|
8
|
-
* (
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* tiers, one function. The emission per closed relation mirrors the
|
|
5
|
+
* macro's (host-enum analog): handle CONSTANTS on the value
|
|
6
|
+
* (`Kind.Checking`, ids = declaration order, each a BARE `bigint` — no
|
|
7
|
+
* brand), the `fromId` weld, an `id` field descriptor carrying the CLOSED
|
|
8
|
+
* LINKAGE (the roster — pure structure, no declared domain: the laws type
|
|
9
|
+
* the columns, and `schema()` names the id's generator class `"Kind.id"`)
|
|
10
|
+
* for other relations' field blocks (`kind: Kind.id`), payload readback
|
|
11
|
+
* (`Kind.axioms`), and the declared payload column descriptors
|
|
12
|
+
* (`Kind.columns` — the runtime twin of the `Cols` type parameter, which
|
|
13
|
+
* the face layer's structural wall reads). Bare tier: `closed("Kind", ["Checking",
|
|
14
|
+
* "Savings"])`. Payload tier: `closed("Sev", { pages: bool }, { Critical:
|
|
15
|
+
* { pages: true }, ... })` — one call, three arguments (the curried tier-2
|
|
16
|
+
* spelling is DELETED — canonical utterance): the axioms record IS the
|
|
17
|
+
* handle declaration, every handle carrying every column exactly once
|
|
18
|
+
* (type-enforced). No fact type and no insert surface exist — closed
|
|
19
|
+
* relations are unwritable by construction: the value simply lacks the
|
|
20
|
+
* writable relation shape. Both tiers mint `match()` — exhaustive dispatch
|
|
21
|
+
* over the handle union (arms typed by the mapped type, so a missing or
|
|
22
|
+
* extra arm is a compile error; the payload tier's arm receives the typed
|
|
23
|
+
* axiom row). The payload tier additionally mints `where()` — the
|
|
24
|
+
* ψ-selection surface (`Kind.where({ mastered: true })` as a face source),
|
|
25
|
+
* resolved through the ONE selection machine
|
|
26
|
+
* (`relation.ts::resolveSelection`); the bare tier has no payload columns to
|
|
27
|
+
* select on, so `.where` is absent there, at the type AND on the value.
|
|
11
28
|
*/
|
|
12
29
|
import * as errors from "@superbuilders/errors";
|
|
13
|
-
import { assertDeclarationOrderKey,
|
|
30
|
+
import { assertDeclarationOrderKey, literalOf } from "#fields.ts";
|
|
31
|
+
import { resolveSelection } from "#relation.ts";
|
|
14
32
|
/**
|
|
15
33
|
* The value-surface property names a handle may not shadow — the macro's
|
|
16
34
|
* name-collision diagnostic, here over the closed value's own properties
|
|
17
35
|
* (`relation`/`selection` are reserved so a closed value can never be
|
|
18
|
-
* mistaken for a selected relation by `on()`'s discriminant
|
|
36
|
+
* mistaken for a selected relation by `on()`'s discriminant; `where` is
|
|
37
|
+
* reserved because the payload tier mints the ψ-selection method under
|
|
38
|
+
* exactly that name; `match` because BOTH tiers mint the exhaustive
|
|
39
|
+
* dispatch under exactly that name).
|
|
19
40
|
*/
|
|
20
41
|
const reservedHandleNames = Object.freeze([
|
|
21
42
|
"name",
|
|
22
43
|
"id",
|
|
23
44
|
"data",
|
|
24
45
|
"axioms",
|
|
46
|
+
"columns",
|
|
25
47
|
"fromId",
|
|
48
|
+
"where",
|
|
49
|
+
"match",
|
|
26
50
|
"relation",
|
|
27
51
|
"selection"
|
|
28
52
|
]);
|
|
53
|
+
/** Narrows the two-tier second argument: a handle tuple (bare tier) or a column block (payload tier). */
|
|
54
|
+
function isHandleTuple(shape) {
|
|
55
|
+
return Array.isArray(shape);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The trusted seam of the payload tier's handle enumeration: the axioms
|
|
59
|
+
* record's own enumerable keys ARE its handle set (the type says so —
|
|
60
|
+
* {@link Axioms} is keyed by the handles), and this guard verifies exactly
|
|
61
|
+
* that checkable fact before the key list is admitted at the handle type.
|
|
62
|
+
*/
|
|
63
|
+
function handleKeysOwn(axioms, names) {
|
|
64
|
+
return names.every(function ownHandle(name) {
|
|
65
|
+
return Object.hasOwn(axioms, name);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The trusted seam of the axiom-readback mint: every handle carries an own
|
|
70
|
+
* frozen row and every row carries every declared column as an own
|
|
71
|
+
* property — verified before the record is admitted as the typed
|
|
72
|
+
* {@link Axioms} (the `refsComplete` analog of `relation()`).
|
|
73
|
+
*/
|
|
74
|
+
function axiomsMinted(record, handles, cols) {
|
|
75
|
+
return handles.every(function rowMinted(handle) {
|
|
76
|
+
const row = record[handle];
|
|
77
|
+
return (row !== undefined &&
|
|
78
|
+
cols.every(function columnMinted(column) {
|
|
79
|
+
return Object.hasOwn(row, column.name);
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
29
83
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
84
|
+
* The trusted seam of the handle-constant mint: every handle reads back as
|
|
85
|
+
* an own bigint — verified before the record is admitted at the constants
|
|
86
|
+
* type (a "__proto__"-named handle riding the object-protocol accessor
|
|
87
|
+
* would fail exactly this check).
|
|
33
88
|
*/
|
|
34
|
-
function
|
|
89
|
+
function constantsMinted(record, handles) {
|
|
90
|
+
return handles.every(function constantMinted(handle) {
|
|
91
|
+
return typeof record[handle] === "bigint";
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Reads one handle's ground axiom row for lowering. The typed payload
|
|
96
|
+
* surface makes absence unrepresentable ({@link Axioms} carries every
|
|
97
|
+
* handle's row); the refusal below guards the one ill-typed path — payload
|
|
98
|
+
* columns with the bare tier's absent axioms — which no public spelling
|
|
99
|
+
* reaches.
|
|
100
|
+
*/
|
|
101
|
+
function groundRow(name, axioms, handle) {
|
|
35
102
|
if (axioms === undefined) {
|
|
36
103
|
throw errors.new(`closed relation ${name}: payload columns declared without ground axioms`);
|
|
37
104
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
105
|
+
return axioms[handle];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Mints the axiom-readback record: one own frozen row per handle (the bare
|
|
109
|
+
* tier's rows are empty — it declares no columns), each row a fresh copy of
|
|
110
|
+
* its ground axiom.
|
|
111
|
+
*/
|
|
112
|
+
function mintAxioms(name, handles, cols, axioms) {
|
|
113
|
+
const out = {};
|
|
114
|
+
for (const handle of handles) {
|
|
115
|
+
const row = axioms === undefined ? Object.freeze({}) : Object.freeze({ ...groundRow(name, axioms, handle) });
|
|
116
|
+
Object.defineProperty(out, handle, { value: row, enumerable: true });
|
|
117
|
+
}
|
|
118
|
+
Object.freeze(out);
|
|
119
|
+
if (!axiomsMinted(out, handles, cols)) {
|
|
120
|
+
throw errors.new(`closed relation ${name}: axiom-row minting incomplete`);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** Mints the handle constants: one own bigint per handle, ids = declaration order. */
|
|
125
|
+
function mintHandleConstants(name, handles) {
|
|
126
|
+
const out = {};
|
|
127
|
+
handles.forEach(function mintHandleConstant(handle, index) {
|
|
128
|
+
Object.defineProperty(out, handle, { value: BigInt(index), enumerable: true });
|
|
129
|
+
});
|
|
130
|
+
Object.freeze(out);
|
|
131
|
+
if (!constantsMinted(out, handles)) {
|
|
132
|
+
throw errors.new(`closed relation ${name}: handle-constant minting incomplete`);
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
function closed(name, shape, axioms) {
|
|
137
|
+
if (isHandleTuple(shape)) {
|
|
138
|
+
if (axioms !== undefined) {
|
|
139
|
+
throw errors.new(`closed relation ${name}: the bare tier declares no columns, so ground axioms are inadmissible`);
|
|
140
|
+
}
|
|
141
|
+
return closedBare(name, shape);
|
|
41
142
|
}
|
|
42
|
-
|
|
143
|
+
if (axioms === undefined) {
|
|
144
|
+
throw errors.new(`closed relation ${name}: payload columns declared without ground axioms — the payload tier is spelled closed(name, columns, axioms) (the curried spelling is deleted)`);
|
|
145
|
+
}
|
|
146
|
+
return closedPayload(name, shape, axioms);
|
|
147
|
+
}
|
|
148
|
+
/** The bare tier's precisely-typed builder: no columns, no axioms. */
|
|
149
|
+
function closedBare(name, handles) {
|
|
150
|
+
return mintClosed(name, handles, {}, undefined);
|
|
43
151
|
}
|
|
44
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The payload tier's precisely-typed builder: column names are judged
|
|
154
|
+
* first (the macro-expansion analog), then the handle set is read off the
|
|
155
|
+
* axioms record's own keys.
|
|
156
|
+
*/
|
|
157
|
+
function closedPayload(name, columns, axioms) {
|
|
158
|
+
for (const columnName of Object.keys(columns)) {
|
|
159
|
+
assertDeclarationOrderKey(`closed relation ${name} column`, columnName);
|
|
160
|
+
}
|
|
161
|
+
const handles = Object.keys(axioms);
|
|
162
|
+
for (const handle of handles) {
|
|
163
|
+
assertDeclarationOrderKey(`closed relation ${name} handle`, handle);
|
|
164
|
+
}
|
|
165
|
+
if (!handleKeysOwn(axioms, handles)) {
|
|
166
|
+
throw errors.new(`closed relation ${name}: handle enumeration incomplete`);
|
|
167
|
+
}
|
|
168
|
+
return mintClosed(name, handles, columns, axioms);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The trusted seam of the ergonomic-surface mint: `match` reads back as an
|
|
172
|
+
* own function on BOTH tiers, and `where` exactly when payload columns
|
|
173
|
+
* exist — the runtime twin of the {@link Closed} type's conditional arm
|
|
174
|
+
* (`ClosedMatchBare` vs `ClosedSelectable & ClosedMatchPayload`), verified
|
|
175
|
+
* before the minted value is admitted at the conditional type.
|
|
176
|
+
*/
|
|
177
|
+
function surfaceMinted(value, cols) {
|
|
178
|
+
const matchable = "match" in value && typeof value.match === "function";
|
|
179
|
+
const selectable = "where" in value && typeof value.where === "function";
|
|
180
|
+
return matchable && (cols.length > 0 ? selectable : !selectable);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Mints one closed relation value — the shared seam of both tiers, HONESTLY
|
|
184
|
+
* typed end to end (a wrong-shaped mint is a compile error here, not a
|
|
185
|
+
* laundered `unknown`): roster checks, eager axiom lowering, the
|
|
186
|
+
* roster-carrying `id` descriptor, the frozen `columns` carrier (the runtime
|
|
187
|
+
* twin of the `Cols` type parameter), the handle constants, the exhaustive
|
|
188
|
+
* `match()` on both tiers, and — on the payload tier only — the
|
|
189
|
+
* ψ-selection `where()`.
|
|
190
|
+
*/
|
|
191
|
+
function mintClosed(name, handles, columns, axioms) {
|
|
192
|
+
if (handles.length === 0) {
|
|
193
|
+
throw errors.new(`closed relation ${name}: at least one handle is required (an empty vocabulary declares nothing)`);
|
|
194
|
+
}
|
|
45
195
|
const seen = new Set();
|
|
46
196
|
for (const handle of handles) {
|
|
47
197
|
if (seen.has(handle)) {
|
|
@@ -52,17 +202,20 @@ function closed(name, handles, columns, axioms) {
|
|
|
52
202
|
throw errors.new(`closed relation ${name}: handle ${handle} collides with the closed value's own surface (${reservedHandleNames.join(", ")})`);
|
|
53
203
|
}
|
|
54
204
|
}
|
|
55
|
-
const
|
|
205
|
+
const handleList = Object.freeze([...handles]);
|
|
206
|
+
const roster = Object.freeze({ name, handles: handleList });
|
|
56
207
|
const cols = [];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
208
|
+
for (const [columnName, field] of Object.entries(columns)) {
|
|
209
|
+
assertDeclarationOrderKey(`closed relation ${name} column`, columnName);
|
|
210
|
+
if (columnName === "id") {
|
|
211
|
+
throw errors.new(`closed relation ${name}: the payload column id collides with the sealed shape's synthetic id (the relation mints its own id at ordinal 0; name the column something else)`);
|
|
61
212
|
}
|
|
213
|
+
cols.push(Object.freeze({ name: columnName, field }));
|
|
62
214
|
}
|
|
63
|
-
|
|
215
|
+
Object.freeze(cols);
|
|
216
|
+
const rows = handleList.map(function lowerRow(handle) {
|
|
64
217
|
const values = cols.map(function lowerAxiomLiteral(column) {
|
|
65
|
-
const row =
|
|
218
|
+
const row = groundRow(name, axioms, handle);
|
|
66
219
|
return Object.freeze(literalOf(column.field, row[column.name]));
|
|
67
220
|
});
|
|
68
221
|
return Object.freeze({ handle, values: Object.freeze(values) });
|
|
@@ -70,38 +223,70 @@ function closed(name, handles, columns, axioms) {
|
|
|
70
223
|
const data = Object.freeze({
|
|
71
224
|
name,
|
|
72
225
|
handles: roster.handles,
|
|
73
|
-
columns:
|
|
226
|
+
columns: cols,
|
|
74
227
|
rows: Object.freeze(rows)
|
|
75
228
|
});
|
|
76
|
-
const id = Object.freeze({
|
|
77
|
-
data: fieldData({ kind: "u64" }, name, false, roster)
|
|
78
|
-
});
|
|
229
|
+
const id = Object.freeze({ kind: "u64", closed: roster });
|
|
79
230
|
/**
|
|
80
231
|
* Handle names are arbitrary identifiers, so rows and constants are
|
|
81
|
-
* minted with OWN-property definition
|
|
232
|
+
* minted with OWN-property definition (inside {@link mintAxioms} and
|
|
233
|
+
* {@link mintHandleConstants}), never assignment: a handle named
|
|
82
234
|
* "__proto__" would otherwise ride the Object.prototype accessor —
|
|
83
235
|
* silently swapping the record's prototype instead of creating the row,
|
|
84
236
|
* and no-oping the constant (a primitive through the setter) — minting a
|
|
85
|
-
* value whose type claims
|
|
237
|
+
* value whose type claims a bigint constant but reads back an object.
|
|
238
|
+
* (Object SPREAD is CreateDataProperty by spec, so the copies below are
|
|
239
|
+
* own-property safe for column names too.)
|
|
86
240
|
*/
|
|
87
|
-
const axiomsOut =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
241
|
+
const axiomsOut = mintAxioms(name, handleList, cols, axioms);
|
|
242
|
+
const constants = mintHandleConstants(name, handleList);
|
|
243
|
+
const columnsOut = { ...columns };
|
|
244
|
+
Object.freeze(columnsOut);
|
|
245
|
+
function fromId(idValue) {
|
|
246
|
+
return handleList[Number(idValue)];
|
|
91
247
|
}
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
248
|
+
const holder = { value: undefined };
|
|
249
|
+
/**
|
|
250
|
+
* The ψ selection: resolved against the declared payload columns through
|
|
251
|
+
* the ONE selection machine (`relation.ts::resolveSelection` — a
|
|
252
|
+
* `ClosedColumn` is structurally a `RelationField`), never pre-folded
|
|
253
|
+
* into an id set (the engine folds at validate).
|
|
254
|
+
*/
|
|
255
|
+
function where(selection) {
|
|
256
|
+
const owner = holder.value;
|
|
257
|
+
if (owner === undefined) {
|
|
258
|
+
throw errors.new(`closed relation ${name}: self-reference read before construction completed`);
|
|
99
259
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
260
|
+
return Object.freeze({
|
|
261
|
+
relation: owner,
|
|
262
|
+
selection: resolveSelection(name, cols, Object.entries(selection))
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The exhaustive dispatch: the ROSTER judges the id (the structural type
|
|
267
|
+
* admits any bigint — a dishonest id is a THROW, never a misdispatch),
|
|
268
|
+
* and the chosen arm receives the handle's frozen axiom row (the bare
|
|
269
|
+
* tier's arms are typed to take nothing; the empty row rides along
|
|
270
|
+
* unread). One implementation serves both tiers — the conditional
|
|
271
|
+
* {@link Closed} arm claims the tier-exact arm signature and
|
|
272
|
+
* {@link surfaceMinted} is the trusted seam that admits it.
|
|
273
|
+
*/
|
|
274
|
+
function match(idValue, arms) {
|
|
275
|
+
const handle = fromId(idValue);
|
|
276
|
+
if (handle === undefined) {
|
|
277
|
+
throw errors.new(`closed relation ${name}: match on id ${idValue} misses the roster (${handleList.join(", ")})`);
|
|
278
|
+
}
|
|
279
|
+
return arms[handle](axiomsOut[handle]);
|
|
280
|
+
}
|
|
281
|
+
const core = { name, id, data, axioms: axiomsOut, columns: columnsOut, fromId };
|
|
282
|
+
const value = cols.length > 0
|
|
283
|
+
? Object.freeze({ ...constants, ...core, where, match })
|
|
284
|
+
: Object.freeze({ ...constants, ...core, match });
|
|
285
|
+
if (!surfaceMinted(value, cols)) {
|
|
286
|
+
throw errors.new(`closed relation ${name}: ergonomic-surface minting incomplete`);
|
|
287
|
+
}
|
|
288
|
+
holder.value = value;
|
|
289
|
+
return value;
|
|
105
290
|
}
|
|
106
291
|
export { closed };
|
|
107
292
|
//# sourceMappingURL=closed.js.map
|
package/dist/closed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closed.js","sourceRoot":"","sources":["../src/closed.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"closed.js","sourceRoot":"","sources":["../src/closed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAEN,yBAAyB,EAIzB,SAAS,EACT,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,gBAAgB,EAAyB,MAAM,cAAc,CAAA;AAGtE;;;;;;;;GAQG;AACH,MAAM,mBAAmB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC5D,MAAM;IACN,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,OAAO;IACP,OAAO;IACP,UAAU;IACV,WAAW;CACX,CAAC,CAAA;AAkLF,yGAAyG;AACzG,SAAS,aAAa,CACrB,KAAoE;IAEpE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CACrB,MAA2C,EAC3C,KAAwB;IAExB,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,SAAS,CAAC,IAAI;QACzC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACH,CAAC;AAED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A;IACvC,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;IAC/E,MAAM,KAAK,GACV,IAAI,CAAC,MAAM,GAAG,CAAC;QACd,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACxD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACnD,IAAI,CAAC,aAAa,CAAsB,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,MAAM,CAAC,GAAG,CAAC,mBAAmB,IAAI,wCAAwC,CAAC,CAAA;IAClF,CAAC;IACD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,OAAO,KAAK,CAAA;AACb,CAAC;AAgBD,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
package/dist/count.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cardinality-window counts — exactly five constructors, and nothing else
|
|
3
|
-
* (`docs/architecture/70-api.md` § the canonical-utterance law). The
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* (`docs/architecture/70-api.md` § the canonical-utterance law). The five
|
|
4
|
+
* constructors PARTITION the legal windows, and the ban table is enforced
|
|
5
|
+
* REPRESENTATIONALLY, stronger than Rust's expansion errors, in two tiers:
|
|
6
|
+
*
|
|
7
|
+
* - **The type tier**: a banned spelling written as a LITERAL does not
|
|
8
|
+
* compile — `exactly(0n)`, `between(n, n)`, `between(0n, hi)`,
|
|
9
|
+
* `atLeast(0n)`, `atLeast(1n)`, `atMost(0n)`, and every negative bound
|
|
10
|
+
* are type errors naming the canonical form (`{n..n}`, `{0..0}`,
|
|
11
|
+
* `{0..hi}`-via-between, `{0..*}`, `{1..*}` have NO argument shape that
|
|
12
|
+
* produces them), and no sixth constructor exists at all.
|
|
13
|
+
* - **The construction tier**: a bound the type level cannot judge — a
|
|
14
|
+
* COMPUTED `bigint`, whose literal identity is erased, or an inverted
|
|
15
|
+
* `between(lo, hi)` order, which type-level bigints cannot compare — is
|
|
16
|
+
* judged here at construction with the same canonical-naming errors; and
|
|
17
|
+
* past both tiers the engine's own spec validation remains the law for a
|
|
18
|
+
* hostile FFI caller (the standing two-tier ban enforcement).
|
|
19
|
+
*
|
|
8
20
|
* Bounds are `bigint` (u64 crosses as bigint always, PRD-04's law).
|
|
9
21
|
*/
|
|
10
22
|
import type { WindowSpec } from "#spec.ts";
|
|
@@ -26,30 +38,65 @@ interface Count {
|
|
|
26
38
|
readonly window: WindowSpec;
|
|
27
39
|
readonly [admitted]: true;
|
|
28
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The legible banned-spelling verdict: intersected into a count
|
|
43
|
+
* constructor's parameter when the LITERAL argument spells a banned window,
|
|
44
|
+
* naming the canonical form — the compile-time face of the ban table.
|
|
45
|
+
*/
|
|
46
|
+
interface BannedWindow<Canonical extends string> {
|
|
47
|
+
readonly "banned window spelling — the canonical-utterance law names the one legal form": Canonical;
|
|
48
|
+
}
|
|
49
|
+
/** `true` exactly when the literal bigint `N` is negative (out of the u64 count domain). */
|
|
50
|
+
type IsNegative<N extends bigint> = `${N}` extends `-${string}` ? true : false;
|
|
51
|
+
/** The ban verdict on `exactly(n)`: negatives are out of domain; `{0}` is the exclusion, written `none`. */
|
|
52
|
+
type ExactlyBan<N extends bigint> = bigint extends N ? unknown : IsNegative<N> extends true ? BannedWindow<"window counts are u64 — a negative count is out of domain"> : N extends 0n ? BannedWindow<"`{0}` is the exclusion — write none"> : unknown;
|
|
53
|
+
/** The ban verdict on `atLeast(lo)`: `{0..*}` is vacuous; `{1..*}` is the bare containment respelled. */
|
|
54
|
+
type AtLeastBan<N extends bigint> = bigint extends N ? unknown : IsNegative<N> extends true ? BannedWindow<"window counts are u64 — a negative count is out of domain"> : N extends 0n ? BannedWindow<"`{0..*}` is vacuous — it provably says nothing; delete the statement"> : N extends 1n ? BannedWindow<"`{1..*}` says only what the bare containment says — write contained(source, target)"> : unknown;
|
|
55
|
+
/** The ban verdict on `atMost(hi)`: `{0..0}` is the exclusion, written `none`. */
|
|
56
|
+
type AtMostBan<N extends bigint> = bigint extends N ? unknown : IsNegative<N> extends true ? BannedWindow<"window counts are u64 — a negative count is out of domain"> : N extends 0n ? BannedWindow<"`{0..0}` — the exclusion is written `{0}`: use none"> : unknown;
|
|
57
|
+
/** The ban verdict on a `between` floor of zero: `{0..hi}` is the ceiling respelled (`atMost(hi)`). */
|
|
58
|
+
type BetweenFloorBan<Lo extends bigint> = Lo extends 0n ? BannedWindow<"`{0..hi}` — a ceiling is written atMost(hi)"> : unknown;
|
|
59
|
+
/**
|
|
60
|
+
* The ban verdict on `between(lo, hi)`, judged on the second bound once
|
|
61
|
+
* both literals are known: `{n..n}` is the exact count respelled
|
|
62
|
+
* (`exactly(n)`, or `none` at 0), and `{0..hi}` is the ceiling respelled
|
|
63
|
+
* (`atMost(hi)` — the five constructors PARTITION the legal windows, so
|
|
64
|
+
* the one ceiling window keeps its one spelling). Bound ORDER (`{hi..lo}`
|
|
65
|
+
* inverted) is not type-expressible — bigint literals have no type-level
|
|
66
|
+
* comparison — so inversion stays a construction error below.
|
|
67
|
+
*/
|
|
68
|
+
type BetweenBan<Lo extends bigint, Hi extends bigint> = bigint extends Lo ? unknown : bigint extends Hi ? unknown : IsNegative<Lo> extends true ? BannedWindow<"window counts are u64 — a negative bound is out of domain"> : IsNegative<Hi> extends true ? BannedWindow<"window counts are u64 — a negative bound is out of domain"> : Lo extends Hi ? Hi extends Lo ? Lo extends 0n ? BannedWindow<"`{0..0}` — the exclusion is written `{0}`: use none"> : BannedWindow<"`{n..n}` — an exact count is written `{n}`: use exactly(n)"> : BetweenFloorBan<Lo> : BetweenFloorBan<Lo>;
|
|
29
69
|
/**
|
|
30
70
|
* `{n}` — THE exact-count spelling, n ≥ 1. `exactly(0)` is the exclusion
|
|
31
|
-
* respelled
|
|
71
|
+
* respelled: unwritable as a literal ({@link ExactlyBan} names `none`),
|
|
72
|
+
* rejected at construction when computed.
|
|
32
73
|
*/
|
|
33
|
-
declare function exactly(n:
|
|
74
|
+
declare function exactly<const N extends bigint>(n: N & ExactlyBan<N>): Count;
|
|
34
75
|
/** `{0}` — the exclusion: no source fact may pair with the target group. */
|
|
35
76
|
declare const none: Count;
|
|
36
77
|
/**
|
|
37
|
-
* `{lo..hi}` — both bounds explicit,
|
|
38
|
-
* count respelled
|
|
39
|
-
*
|
|
78
|
+
* `{lo..hi}` — both bounds explicit, 1 ≤ lo < hi. `lo === hi` is the exact
|
|
79
|
+
* count respelled and `lo === 0` is the ceiling respelled: unwritable as
|
|
80
|
+
* literals ({@link BetweenBan} names `exactly(n)`, `none` at `{0..0}`, or
|
|
81
|
+
* `atMost(hi)` at a zero floor — the five constructors PARTITION the legal
|
|
82
|
+
* windows), rejected at construction when computed; an inverted window is
|
|
83
|
+
* unsatisfiable and rejected at construction (bigint literals carry no
|
|
84
|
+
* type-level order).
|
|
40
85
|
*/
|
|
41
|
-
declare function between(lo:
|
|
86
|
+
declare function between<const Lo extends bigint, const Hi extends bigint>(lo: Lo, hi: Hi & BetweenBan<Lo, Hi>): Count;
|
|
42
87
|
/**
|
|
43
88
|
* `{lo..*}` — a floor with no ceiling, lo ≥ 2: `atLeast(1)` says only what
|
|
44
|
-
* the bare containment says
|
|
45
|
-
*
|
|
89
|
+
* the bare containment says and `atLeast(0)` is vacuous — both unwritable
|
|
90
|
+
* as literals ({@link AtLeastBan} names the canonical form), rejected at
|
|
91
|
+
* construction when computed.
|
|
46
92
|
*/
|
|
47
|
-
declare function atLeast(lo:
|
|
93
|
+
declare function atLeast<const N extends bigint>(lo: N & AtLeastBan<N>): Count;
|
|
48
94
|
/**
|
|
49
|
-
* `{0..hi}` — a ceiling, hi ≥ 1: `atMost(0)` is the exclusion respelled
|
|
50
|
-
*
|
|
95
|
+
* `{0..hi}` — a ceiling, hi ≥ 1: `atMost(0)` is the exclusion respelled —
|
|
96
|
+
* unwritable as a literal ({@link AtMostBan} names `none`), rejected at
|
|
97
|
+
* construction when computed.
|
|
51
98
|
*/
|
|
52
|
-
declare function atMost(hi:
|
|
99
|
+
declare function atMost<const N extends bigint>(hi: N & AtMostBan<N>): Count;
|
|
53
100
|
export type { Count };
|
|
54
101
|
export { atLeast, atMost, between, exactly, none };
|
|
55
102
|
//# sourceMappingURL=count.d.ts.map
|
package/dist/count.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAK1C;;;;;;;GAOG;AACH,QAAA,MAAM,QAAQ,EAAE,OAAO,MAA0C,CAAA;AAEjE;;;;GAIG;AACH,UAAU,KAAK;IACd,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CACzB;AAQD;;;;GAIG;AACH,UAAU,YAAY,CAAC,SAAS,SAAS,MAAM;IAC9C,QAAQ,CAAC,+EAA+E,EAAE,SAAS,CAAA;CACnG;AAED,4FAA4F;AAC5F,KAAK,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,EAAE,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,GAAG,KAAK,CAAA;AAE9E,4GAA4G;AAC5G,KAAK,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI,M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AY,CAAC,qDAAqD,CAAC,GACnE,YAAY,CAAC,4DAA4D,CAAC,GAC3E,eAAe,CAAC,EAAE,CAAC,GACpB,eAAe,CAAC,EAAE,CAAC,CAAA;AAE1B;;;;GAIG;AACH,iBAAS,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAQpE;AAED,4EAA4E;AAC5E,QAAA,MAAM,IAAI,EAAE,KAAwB,CAAA;AAEpC;;;;;;;;GAQG;AACH,iBAAS,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAmB7G;AAED;;;;;GAKG;AACH,iBAAS,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAarE;AAED;;;;GAIG;AACH,iBAAS,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAQnE;AAED,YAAY,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
package/dist/count.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cardinality-window counts — exactly five constructors, and nothing else
|
|
3
|
-
* (`docs/architecture/70-api.md` § the canonical-utterance law). The
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* (`docs/architecture/70-api.md` § the canonical-utterance law). The five
|
|
4
|
+
* constructors PARTITION the legal windows, and the ban table is enforced
|
|
5
|
+
* REPRESENTATIONALLY, stronger than Rust's expansion errors, in two tiers:
|
|
6
|
+
*
|
|
7
|
+
* - **The type tier**: a banned spelling written as a LITERAL does not
|
|
8
|
+
* compile — `exactly(0n)`, `between(n, n)`, `between(0n, hi)`,
|
|
9
|
+
* `atLeast(0n)`, `atLeast(1n)`, `atMost(0n)`, and every negative bound
|
|
10
|
+
* are type errors naming the canonical form (`{n..n}`, `{0..0}`,
|
|
11
|
+
* `{0..hi}`-via-between, `{0..*}`, `{1..*}` have NO argument shape that
|
|
12
|
+
* produces them), and no sixth constructor exists at all.
|
|
13
|
+
* - **The construction tier**: a bound the type level cannot judge — a
|
|
14
|
+
* COMPUTED `bigint`, whose literal identity is erased, or an inverted
|
|
15
|
+
* `between(lo, hi)` order, which type-level bigints cannot compare — is
|
|
16
|
+
* judged here at construction with the same canonical-naming errors; and
|
|
17
|
+
* past both tiers the engine's own spec validation remains the law for a
|
|
18
|
+
* hostile FFI caller (the standing two-tier ban enforcement).
|
|
19
|
+
*
|
|
8
20
|
* Bounds are `bigint` (u64 crosses as bigint always, PRD-04's law).
|
|
9
21
|
*/
|
|
10
22
|
import * as errors from "@superbuilders/errors";
|
|
@@ -21,11 +33,13 @@ const exclusion = Object.freeze({ kind: "exact", n: 0n });
|
|
|
21
33
|
const admitted = Symbol("bumbledb.count.admitted");
|
|
22
34
|
/** Stamps one admitted window as a frozen `Count` value. */
|
|
23
35
|
function admit(window) {
|
|
24
|
-
|
|
36
|
+
const count = { window, [admitted]: true };
|
|
37
|
+
return Object.freeze(count);
|
|
25
38
|
}
|
|
26
39
|
/**
|
|
27
40
|
* `{n}` — THE exact-count spelling, n ≥ 1. `exactly(0)` is the exclusion
|
|
28
|
-
* respelled
|
|
41
|
+
* respelled: unwritable as a literal ({@link ExactlyBan} names `none`),
|
|
42
|
+
* rejected at construction when computed.
|
|
29
43
|
*/
|
|
30
44
|
function exactly(n) {
|
|
31
45
|
if (n < 0n) {
|
|
@@ -39,9 +53,13 @@ function exactly(n) {
|
|
|
39
53
|
/** `{0}` — the exclusion: no source fact may pair with the target group. */
|
|
40
54
|
const none = admit(exclusion);
|
|
41
55
|
/**
|
|
42
|
-
* `{lo..hi}` — both bounds explicit,
|
|
43
|
-
* count respelled
|
|
44
|
-
*
|
|
56
|
+
* `{lo..hi}` — both bounds explicit, 1 ≤ lo < hi. `lo === hi` is the exact
|
|
57
|
+
* count respelled and `lo === 0` is the ceiling respelled: unwritable as
|
|
58
|
+
* literals ({@link BetweenBan} names `exactly(n)`, `none` at `{0..0}`, or
|
|
59
|
+
* `atMost(hi)` at a zero floor — the five constructors PARTITION the legal
|
|
60
|
+
* windows), rejected at construction when computed; an inverted window is
|
|
61
|
+
* unsatisfiable and rejected at construction (bigint literals carry no
|
|
62
|
+
* type-level order).
|
|
45
63
|
*/
|
|
46
64
|
function between(lo, hi) {
|
|
47
65
|
if (lo < 0n || hi < 0n) {
|
|
@@ -56,12 +74,16 @@ function between(lo, hi) {
|
|
|
56
74
|
}
|
|
57
75
|
throw errors.new(`\`{${lo}..${lo}}\` — an exact count is written \`{${lo}}\`: use exactly(${lo})`);
|
|
58
76
|
}
|
|
77
|
+
if (lo === 0n) {
|
|
78
|
+
throw errors.new(`\`{0..${hi}}\` — a ceiling is written atMost: use atMost(${hi})`);
|
|
79
|
+
}
|
|
59
80
|
return admit(Object.freeze({ kind: "range", lo, hi }));
|
|
60
81
|
}
|
|
61
82
|
/**
|
|
62
83
|
* `{lo..*}` — a floor with no ceiling, lo ≥ 2: `atLeast(1)` says only what
|
|
63
|
-
* the bare containment says
|
|
64
|
-
*
|
|
84
|
+
* the bare containment says and `atLeast(0)` is vacuous — both unwritable
|
|
85
|
+
* as literals ({@link AtLeastBan} names the canonical form), rejected at
|
|
86
|
+
* construction when computed.
|
|
65
87
|
*/
|
|
66
88
|
function atLeast(lo) {
|
|
67
89
|
if (lo < 0n) {
|
|
@@ -76,8 +98,9 @@ function atLeast(lo) {
|
|
|
76
98
|
return admit(Object.freeze({ kind: "floor", lo }));
|
|
77
99
|
}
|
|
78
100
|
/**
|
|
79
|
-
* `{0..hi}` — a ceiling, hi ≥ 1: `atMost(0)` is the exclusion respelled
|
|
80
|
-
*
|
|
101
|
+
* `{0..hi}` — a ceiling, hi ≥ 1: `atMost(0)` is the exclusion respelled —
|
|
102
|
+
* unwritable as a literal ({@link AtMostBan} names `none`), rejected at
|
|
103
|
+
* construction when computed.
|
|
81
104
|
*/
|
|
82
105
|
function atMost(hi) {
|
|
83
106
|
if (hi < 0n) {
|
package/dist/count.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.js","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"count.js","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAG/C,sDAAsD;AACtD,MAAM,SAAS,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AAErE;;;;;;;GAOG;AACH,MAAM,QAAQ,GAAkB,MAAM,CAAC,yBAAyB,CAAC,CAAA;AAYjE,4DAA4D;AAC5D,SAAS,KAAK,CAAC,MAAkB;IAChC,MAAM,KAAK,GAAU,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAA;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAyED;;;;GAIG;AACH,SAAS,OAAO,CAAyB,CAAoB;IAC5D,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACZ,MAAM,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,oBAAoB,CAAC,CAAA;IAC1E,CAAC;IACD,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC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