@orkestrel/contract 0.0.13 → 0.0.14
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/dist/src/core/index.cjs +53 -37
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +22 -0
- package/dist/src/core/index.d.ts +22 -0
- package/dist/src/core/index.js +53 -37
- package/dist/src/core/index.js.map +1 -1
- package/package.json +16 -12
|
@@ -1214,6 +1214,14 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1214
1214
|
* interrupted outer read, and every later read with one shared cause-free
|
|
1215
1215
|
* error.
|
|
1216
1216
|
*
|
|
1217
|
+
* After every family exists, the compiler releases its working set — the owned
|
|
1218
|
+
* graph, the node index, the order, and every family plan. A compiler read for
|
|
1219
|
+
* one artifact and then kept holds that whole set for as long as you keep the
|
|
1220
|
+
* compiler. A compiled artifact is the opposite: each one closes over the child
|
|
1221
|
+
* entries its family needed while that family was built, so it answers on its
|
|
1222
|
+
* own and outlives the compiler that produced it. When one artifact is what you
|
|
1223
|
+
* want, keep the artifact and let the compiler go.
|
|
1224
|
+
*
|
|
1217
1225
|
* @example
|
|
1218
1226
|
* ```ts
|
|
1219
1227
|
* const compiler = new ContractCompiler(stringShape({ min: 1 }))
|
|
@@ -1410,6 +1418,20 @@ export declare function createArrayFaults(shape: ArrayShape, length: number, pat
|
|
|
1410
1418
|
* longer re-walk and re-gate the declaration on every call the way they used
|
|
1411
1419
|
* to; `contract.audit` and `compileAuditor` are the same compiled function
|
|
1412
1420
|
* reached two ways.
|
|
1421
|
+
* The bundle is eager by intent. Its members are plain data properties holding
|
|
1422
|
+
* the compiled artifacts, so `const { is, parse } = createContract(shape)`
|
|
1423
|
+
* destructures those exact values and a spread of the result copies them; a
|
|
1424
|
+
* lazily compiled member would compile on either, which spends the laziness
|
|
1425
|
+
* rather than saving it. A malformed declaration refuses at this call rather
|
|
1426
|
+
* than at the first read of whichever member a caller happens to touch, so the
|
|
1427
|
+
* failure arrives at the call the caller made — carrying the authoring door's
|
|
1428
|
+
* own diagnosis, which this door adopts rather than rewraps. Every member is
|
|
1429
|
+
* self-contained, and the compiler this call builds releases its working set
|
|
1430
|
+
* before the call returns. The contract keeps part of the declaration even so:
|
|
1431
|
+
* the auditor and reporter plans close over the owned leaf and array nodes they
|
|
1432
|
+
* read their bounds from, so a kept contract retains those nodes and, through
|
|
1433
|
+
* an array node's `items` field, the subgraph beneath them. Nothing the caller
|
|
1434
|
+
* keeps reaches back into the compiler.
|
|
1413
1435
|
*
|
|
1414
1436
|
* @param shape - The shape to compile
|
|
1415
1437
|
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1214,6 +1214,14 @@ export declare class ContractCompiler<S extends ContractShape = ContractShape> i
|
|
|
1214
1214
|
* interrupted outer read, and every later read with one shared cause-free
|
|
1215
1215
|
* error.
|
|
1216
1216
|
*
|
|
1217
|
+
* After every family exists, the compiler releases its working set — the owned
|
|
1218
|
+
* graph, the node index, the order, and every family plan. A compiler read for
|
|
1219
|
+
* one artifact and then kept holds that whole set for as long as you keep the
|
|
1220
|
+
* compiler. A compiled artifact is the opposite: each one closes over the child
|
|
1221
|
+
* entries its family needed while that family was built, so it answers on its
|
|
1222
|
+
* own and outlives the compiler that produced it. When one artifact is what you
|
|
1223
|
+
* want, keep the artifact and let the compiler go.
|
|
1224
|
+
*
|
|
1217
1225
|
* @example
|
|
1218
1226
|
* ```ts
|
|
1219
1227
|
* const compiler = new ContractCompiler(stringShape({ min: 1 }))
|
|
@@ -1410,6 +1418,20 @@ export declare function createArrayFaults(shape: ArrayShape, length: number, pat
|
|
|
1410
1418
|
* longer re-walk and re-gate the declaration on every call the way they used
|
|
1411
1419
|
* to; `contract.audit` and `compileAuditor` are the same compiled function
|
|
1412
1420
|
* reached two ways.
|
|
1421
|
+
* The bundle is eager by intent. Its members are plain data properties holding
|
|
1422
|
+
* the compiled artifacts, so `const { is, parse } = createContract(shape)`
|
|
1423
|
+
* destructures those exact values and a spread of the result copies them; a
|
|
1424
|
+
* lazily compiled member would compile on either, which spends the laziness
|
|
1425
|
+
* rather than saving it. A malformed declaration refuses at this call rather
|
|
1426
|
+
* than at the first read of whichever member a caller happens to touch, so the
|
|
1427
|
+
* failure arrives at the call the caller made — carrying the authoring door's
|
|
1428
|
+
* own diagnosis, which this door adopts rather than rewraps. Every member is
|
|
1429
|
+
* self-contained, and the compiler this call builds releases its working set
|
|
1430
|
+
* before the call returns. The contract keeps part of the declaration even so:
|
|
1431
|
+
* the auditor and reporter plans close over the owned leaf and array nodes they
|
|
1432
|
+
* read their bounds from, so a kept contract retains those nodes and, through
|
|
1433
|
+
* an array node's `items` field, the subgraph beneath them. Nothing the caller
|
|
1434
|
+
* keeps reaches back into the compiler.
|
|
1413
1435
|
*
|
|
1414
1436
|
* @param shape - The shape to compile
|
|
1415
1437
|
* @returns A contract bundling `schema` / `is` / `parse` / `audit` / `explain` / `generate`
|
package/dist/src/core/index.js
CHANGED
|
@@ -6502,28 +6502,38 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6502
6502
|
static #weakMap = WeakMap;
|
|
6503
6503
|
static #visits = 0;
|
|
6504
6504
|
static #scope = 0;
|
|
6505
|
+
static #emptyStack = [];
|
|
6506
|
+
static #emptyNodes = [];
|
|
6507
|
+
static #emptyOrder = [];
|
|
6508
|
+
static #emptySchemas = [];
|
|
6509
|
+
static #emptyGuards = [];
|
|
6510
|
+
static #emptyParsers = [];
|
|
6511
|
+
static #emptyAudits = [];
|
|
6512
|
+
static #emptyReports = [];
|
|
6513
|
+
static #emptySeeds = [];
|
|
6514
|
+
static {
|
|
6515
|
+
INTRINSICS.freeze(ContractCompiler.#emptyStack);
|
|
6516
|
+
INTRINSICS.freeze(ContractCompiler.#emptyNodes);
|
|
6517
|
+
INTRINSICS.freeze(ContractCompiler.#emptyOrder);
|
|
6518
|
+
INTRINSICS.freeze(ContractCompiler.#emptySchemas);
|
|
6519
|
+
INTRINSICS.freeze(ContractCompiler.#emptyGuards);
|
|
6520
|
+
INTRINSICS.freeze(ContractCompiler.#emptyParsers);
|
|
6521
|
+
INTRINSICS.freeze(ContractCompiler.#emptyAudits);
|
|
6522
|
+
INTRINSICS.freeze(ContractCompiler.#emptyReports);
|
|
6523
|
+
INTRINSICS.freeze(ContractCompiler.#emptySeeds);
|
|
6524
|
+
}
|
|
6505
6525
|
#source;
|
|
6506
6526
|
#state;
|
|
6507
6527
|
#stack;
|
|
6508
|
-
#emptyStack;
|
|
6509
6528
|
#nodes;
|
|
6510
|
-
#emptyNodes;
|
|
6511
6529
|
#index;
|
|
6512
|
-
#emptyIndex;
|
|
6513
6530
|
#order;
|
|
6514
|
-
#emptyOrder;
|
|
6515
6531
|
#schemas;
|
|
6516
|
-
#emptySchemas;
|
|
6517
6532
|
#guards;
|
|
6518
|
-
#emptyGuards;
|
|
6519
6533
|
#parsers;
|
|
6520
|
-
#emptyParsers;
|
|
6521
6534
|
#audits;
|
|
6522
|
-
#emptyAudits;
|
|
6523
6535
|
#reports;
|
|
6524
|
-
#emptyReports;
|
|
6525
6536
|
#seeds;
|
|
6526
|
-
#emptySeeds;
|
|
6527
6537
|
#schema;
|
|
6528
6538
|
#guard;
|
|
6529
6539
|
#parser;
|
|
@@ -6540,25 +6550,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6540
6550
|
this.#source = shape;
|
|
6541
6551
|
this.#state = { phase: "ready" };
|
|
6542
6552
|
this.#stack = [];
|
|
6543
|
-
this.#emptyStack = [];
|
|
6544
6553
|
this.#nodes = [];
|
|
6545
|
-
this.#emptyNodes = [];
|
|
6546
6554
|
this.#index = new ContractCompiler.#weakMap();
|
|
6547
|
-
this.#emptyIndex = new ContractCompiler.#weakMap();
|
|
6548
6555
|
this.#order = [];
|
|
6549
|
-
this.#emptyOrder = [];
|
|
6550
6556
|
this.#schemas = [];
|
|
6551
|
-
this.#emptySchemas = [];
|
|
6552
6557
|
this.#guards = [];
|
|
6553
|
-
this.#emptyGuards = [];
|
|
6554
6558
|
this.#parsers = [];
|
|
6555
|
-
this.#emptyParsers = [];
|
|
6556
6559
|
this.#audits = [];
|
|
6557
|
-
this.#emptyAudits = [];
|
|
6558
6560
|
this.#reports = [];
|
|
6559
|
-
this.#emptyReports = [];
|
|
6560
6561
|
this.#seeds = [];
|
|
6561
|
-
this.#emptySeeds = [];
|
|
6562
6562
|
this.#schema = void 0;
|
|
6563
6563
|
this.#guard = void 0;
|
|
6564
6564
|
this.#parser = void 0;
|
|
@@ -6680,16 +6680,16 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6680
6680
|
}
|
|
6681
6681
|
#release() {
|
|
6682
6682
|
this.#source = void 0;
|
|
6683
|
-
this.#stack =
|
|
6684
|
-
this.#nodes =
|
|
6685
|
-
this.#index =
|
|
6686
|
-
this.#order =
|
|
6687
|
-
this.#schemas =
|
|
6688
|
-
this.#guards =
|
|
6689
|
-
this.#parsers =
|
|
6690
|
-
this.#audits =
|
|
6691
|
-
this.#reports =
|
|
6692
|
-
this.#seeds =
|
|
6683
|
+
this.#stack = ContractCompiler.#emptyStack;
|
|
6684
|
+
this.#nodes = ContractCompiler.#emptyNodes;
|
|
6685
|
+
this.#index = void 0;
|
|
6686
|
+
this.#order = ContractCompiler.#emptyOrder;
|
|
6687
|
+
this.#schemas = ContractCompiler.#emptySchemas;
|
|
6688
|
+
this.#guards = ContractCompiler.#emptyGuards;
|
|
6689
|
+
this.#parsers = ContractCompiler.#emptyParsers;
|
|
6690
|
+
this.#audits = ContractCompiler.#emptyAudits;
|
|
6691
|
+
this.#reports = ContractCompiler.#emptyReports;
|
|
6692
|
+
this.#seeds = ContractCompiler.#emptySeeds;
|
|
6693
6693
|
}
|
|
6694
6694
|
#prepare() {
|
|
6695
6695
|
if (this.#nodes.length > 0) return;
|
|
@@ -6709,6 +6709,14 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6709
6709
|
this.#source = void 0;
|
|
6710
6710
|
}
|
|
6711
6711
|
#discover(root) {
|
|
6712
|
+
const known = this.#index;
|
|
6713
|
+
if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
|
|
6714
|
+
code: "structure",
|
|
6715
|
+
context: {
|
|
6716
|
+
path: [],
|
|
6717
|
+
shape: "contract"
|
|
6718
|
+
}
|
|
6719
|
+
});
|
|
6712
6720
|
this.#stack[this.#stack.length] = {
|
|
6713
6721
|
operation: "enter",
|
|
6714
6722
|
shape: root
|
|
@@ -6723,10 +6731,10 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6723
6731
|
continue;
|
|
6724
6732
|
}
|
|
6725
6733
|
const shape = frame.shape;
|
|
6726
|
-
if (INTRINSICS.apply(INTRINSICS.recall,
|
|
6734
|
+
if (INTRINSICS.apply(INTRINSICS.recall, known, [shape]) !== void 0) continue;
|
|
6727
6735
|
const index = this.#nodes.length;
|
|
6728
6736
|
this.#nodes[index] = shape;
|
|
6729
|
-
INTRINSICS.apply(INTRINSICS.retain,
|
|
6737
|
+
INTRINSICS.apply(INTRINSICS.retain, known, [shape, index]);
|
|
6730
6738
|
this.#stack[this.#stack.length] = {
|
|
6731
6739
|
operation: "exit",
|
|
6732
6740
|
index
|
|
@@ -6782,7 +6790,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6782
6790
|
}
|
|
6783
6791
|
}
|
|
6784
6792
|
#locate(shape) {
|
|
6785
|
-
const
|
|
6793
|
+
const known = this.#index;
|
|
6794
|
+
if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
|
|
6795
|
+
code: "structure",
|
|
6796
|
+
context: {
|
|
6797
|
+
path: [],
|
|
6798
|
+
shape: "contract"
|
|
6799
|
+
}
|
|
6800
|
+
});
|
|
6801
|
+
const index = INTRINSICS.apply(INTRINSICS.recall, known, [shape]);
|
|
6786
6802
|
if (index === void 0) throw new ContractError("ContractCompiler: a structural child is not in the prepared index", {
|
|
6787
6803
|
code: "structure",
|
|
6788
6804
|
context: {
|
|
@@ -6814,7 +6830,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6814
6830
|
}
|
|
6815
6831
|
#trackGuard(plan) {
|
|
6816
6832
|
let filled = 0;
|
|
6817
|
-
let memo
|
|
6833
|
+
let memo;
|
|
6818
6834
|
return (value) => {
|
|
6819
6835
|
if (!isObject(value)) return plan(value);
|
|
6820
6836
|
const opened = ContractCompiler.#scope === 0;
|
|
@@ -6824,7 +6840,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6824
6840
|
}
|
|
6825
6841
|
try {
|
|
6826
6842
|
const scope = ContractCompiler.#scope;
|
|
6827
|
-
if (filled !== scope) {
|
|
6843
|
+
if (memo === void 0 || filled !== scope) {
|
|
6828
6844
|
memo = new ContractCompiler.#weakMap();
|
|
6829
6845
|
filled = scope;
|
|
6830
6846
|
}
|
|
@@ -6840,7 +6856,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6840
6856
|
}
|
|
6841
6857
|
#trackFaults(plan) {
|
|
6842
6858
|
let filled = 0;
|
|
6843
|
-
let memo
|
|
6859
|
+
let memo;
|
|
6844
6860
|
return (value, path) => {
|
|
6845
6861
|
if (!isObject(value)) return plan(value, path);
|
|
6846
6862
|
const opened = ContractCompiler.#scope === 0;
|
|
@@ -6850,7 +6866,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6850
6866
|
}
|
|
6851
6867
|
try {
|
|
6852
6868
|
const scope = ContractCompiler.#scope;
|
|
6853
|
-
if (filled !== scope) {
|
|
6869
|
+
if (memo === void 0 || filled !== scope) {
|
|
6854
6870
|
memo = new ContractCompiler.#weakMap();
|
|
6855
6871
|
filled = scope;
|
|
6856
6872
|
}
|