@orkestrel/contract 0.0.26 → 0.0.28
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 +245 -136
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +41 -7
- package/dist/src/core/index.d.ts +41 -7
- package/dist/src/core/index.js +245 -137
- package/dist/src/core/index.js.map +1 -1
- package/package.json +11 -11
package/dist/src/core/index.cjs
CHANGED
|
@@ -303,6 +303,12 @@ var INTRINSICS = Object.freeze({
|
|
|
303
303
|
sweep: Set.prototype.forEach,
|
|
304
304
|
/** Captures `Set.prototype.delete` — settlement of an active operation. */
|
|
305
305
|
remove: Set.prototype.delete,
|
|
306
|
+
/** Captures the `Set.prototype.size` getter — the emptiness answer of a registry this package built, dispatched through `apply`. */
|
|
307
|
+
count: Object.getOwnPropertyDescriptor(Set.prototype, "size")?.get,
|
|
308
|
+
/** Captures `Set.prototype.values` — an ordered cursor over a registry this package built, dispatched through `apply`. */
|
|
309
|
+
cursor: Set.prototype.values,
|
|
310
|
+
/** Captures the native set iterator advance operation. */
|
|
311
|
+
step: Object.getPrototypeOf((/* @__PURE__ */ new Set()).values()).next,
|
|
306
312
|
/** Captures `WeakMap` — object-keyed working state. */
|
|
307
313
|
weakMap: WeakMap,
|
|
308
314
|
/** Captures `WeakMap.prototype.get` — an object-keyed memo read a published graph embeds, dispatched through `apply`. */
|
|
@@ -1158,6 +1164,37 @@ function pathOf(path, ...segments) {
|
|
|
1158
1164
|
return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(combined), [(segment) => segment !== void 0]);
|
|
1159
1165
|
}
|
|
1160
1166
|
/**
|
|
1167
|
+
* Builds a child's path from a dense path this package built and the child's key, without
|
|
1168
|
+
* dispatching through array iteration.
|
|
1169
|
+
*
|
|
1170
|
+
* @remarks
|
|
1171
|
+
* Reads `length` once and each segment once, in order, through a null-prototype array-like
|
|
1172
|
+
* that reaches no iterator and no caller member. A caller's path goes through {@link pathOf}
|
|
1173
|
+
* instead, which rereads its length before every segment and omits an absent one.
|
|
1174
|
+
*
|
|
1175
|
+
* @param path - A dense path this package built
|
|
1176
|
+
* @param key - The child's key
|
|
1177
|
+
* @returns A fresh path carrying every segment and then the key
|
|
1178
|
+
* @throws An `Error` when `path` holds an absent segment
|
|
1179
|
+
*
|
|
1180
|
+
* @example
|
|
1181
|
+
* ```ts
|
|
1182
|
+
* buildChildPath(['user'], 'name') // ['user', 'name']
|
|
1183
|
+
* ```
|
|
1184
|
+
*/
|
|
1185
|
+
function buildChildPath(path, key) {
|
|
1186
|
+
const length = path.length;
|
|
1187
|
+
const indices = {
|
|
1188
|
+
__proto__: null,
|
|
1189
|
+
length: length + 1
|
|
1190
|
+
};
|
|
1191
|
+
return INTRINSICS.from(indices, (_entry, index) => {
|
|
1192
|
+
const segment = index < length ? path[index] : key;
|
|
1193
|
+
if (segment === void 0) throw new INTRINSICS.error("A built path holds an absent segment");
|
|
1194
|
+
return segment;
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1161
1198
|
* Appends every element of one array onto another, by index.
|
|
1162
1199
|
*
|
|
1163
1200
|
* @remarks
|
|
@@ -1891,10 +1928,15 @@ function pinMembers(prototype, owner) {
|
|
|
1891
1928
|
if (key === void 0) continue;
|
|
1892
1929
|
const declared = INTRINSICS.describe(prototype, key);
|
|
1893
1930
|
const accessor = declared !== void 0 && !INTRINSICS.own(declared, "value");
|
|
1894
|
-
|
|
1931
|
+
const pin = accessor ? {
|
|
1932
|
+
__proto__: null,
|
|
1933
|
+
configurable: false
|
|
1934
|
+
} : {
|
|
1935
|
+
__proto__: null,
|
|
1895
1936
|
writable: false,
|
|
1896
1937
|
configurable: false
|
|
1897
|
-
}
|
|
1938
|
+
};
|
|
1939
|
+
INTRINSICS.reflect.define(prototype, key, pin);
|
|
1898
1940
|
const pinned = INTRINSICS.describe(prototype, key);
|
|
1899
1941
|
if (pinned?.configurable !== false || !accessor && pinned.writable !== false) throw new ContractError(`${owner}: a prototype member could not be pinned`, {
|
|
1900
1942
|
code: "structure",
|
|
@@ -2432,7 +2474,9 @@ function collectArrayEntries(value) {
|
|
|
2432
2474
|
const length = value.length;
|
|
2433
2475
|
if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
|
|
2434
2476
|
const members = INTRINSICS.reflect.members(value);
|
|
2435
|
-
|
|
2477
|
+
let canonical = members.length === length + 1 && members[length] === "length";
|
|
2478
|
+
for (let index = 0; canonical && index < length; index++) canonical = members[index] === INTRINSICS.text(index);
|
|
2479
|
+
if (canonical) {
|
|
2436
2480
|
const indices = {
|
|
2437
2481
|
__proto__: null,
|
|
2438
2482
|
length
|
|
@@ -2642,13 +2686,16 @@ function buildKeyPlan(keys, guards) {
|
|
|
2642
2686
|
* ```
|
|
2643
2687
|
*/
|
|
2644
2688
|
function matchesKeyPlan(plan) {
|
|
2645
|
-
|
|
2689
|
+
if (plan.length !== this.length) return false;
|
|
2690
|
+
for (let index = 0, count = plan.length; index < count; index++) if (index in plan && plan[index]?.key !== this[index]) return false;
|
|
2691
|
+
return true;
|
|
2646
2692
|
}
|
|
2647
2693
|
/**
|
|
2648
2694
|
* Checks whether a key-plan step names the key at its index in the list bound as `this`.
|
|
2649
2695
|
*
|
|
2650
2696
|
* @remarks
|
|
2651
|
-
*
|
|
2697
|
+
* Answers one step of the comparison {@link matchesKeyPlan} makes, for a caller that passes it with
|
|
2698
|
+
* the key list as the `thisArg` argument to an `every` walk over a key plan.
|
|
2652
2699
|
*
|
|
2653
2700
|
* @param step - The step to compare
|
|
2654
2701
|
* @param index - The step's position in its plan
|
|
@@ -2666,8 +2713,9 @@ function matchesStepKey(step, index) {
|
|
|
2666
2713
|
* Checks whether the member of the record bound as `this` passes a key-plan step's guard.
|
|
2667
2714
|
*
|
|
2668
2715
|
* @remarks
|
|
2669
|
-
*
|
|
2670
|
-
*
|
|
2716
|
+
* Answers one step of the walk a compiled closed-object guard makes over a kept key plan, for a
|
|
2717
|
+
* caller that passes it with the record as the `thisArg` argument to an `every` walk over the plan,
|
|
2718
|
+
* which reads each member once, in the plan's order, and stops at the first refusal.
|
|
2671
2719
|
*
|
|
2672
2720
|
* @param step - The step whose member to read and guard
|
|
2673
2721
|
* @returns True if the member under the step's key passes its guard; false otherwise
|
|
@@ -2823,16 +2871,13 @@ function resolveField(record, path) {
|
|
|
2823
2871
|
const outcome = attempt(() => {
|
|
2824
2872
|
if (!matchesRecordBrand(record)) return void 0;
|
|
2825
2873
|
if (isString(path)) return INTRINSICS.own(record, path) ? INTRINSICS.reflect.read(record, path) : void 0;
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
}
|
|
2834
|
-
return INTRINSICS.reflect.read(current, key);
|
|
2835
|
-
}, record]);
|
|
2874
|
+
let current = record;
|
|
2875
|
+
for (let index = 0; index < path.length; index++) {
|
|
2876
|
+
const key = path[index];
|
|
2877
|
+
if (key === void 0 || !isObject(current) || !INTRINSICS.own(current, key)) return void 0;
|
|
2878
|
+
current = INTRINSICS.reflect.read(current, key);
|
|
2879
|
+
}
|
|
2880
|
+
return current;
|
|
2836
2881
|
});
|
|
2837
2882
|
return isSuccess(outcome) ? outcome.value : void 0;
|
|
2838
2883
|
}
|
|
@@ -2937,7 +2982,9 @@ function matchesJSONDepth(value) {
|
|
|
2937
2982
|
const active = new INTRINSICS.weakSet();
|
|
2938
2983
|
const settled = new INTRINSICS.weakMap();
|
|
2939
2984
|
while (stack.length > 0) {
|
|
2940
|
-
const
|
|
2985
|
+
const top = stack.length - 1;
|
|
2986
|
+
const frame = stack[top];
|
|
2987
|
+
stack.length = top;
|
|
2941
2988
|
if (frame === void 0) return false;
|
|
2942
2989
|
if (frame.operation === "exit") {
|
|
2943
2990
|
omitVisited(active, frame.value);
|
|
@@ -3038,7 +3085,9 @@ function matchesJSONValue(entry, ancestors, budget) {
|
|
|
3038
3085
|
}];
|
|
3039
3086
|
const proved = new INTRINSICS.weakSet();
|
|
3040
3087
|
while (stack.length > 0) {
|
|
3041
|
-
const
|
|
3088
|
+
const top = stack.length - 1;
|
|
3089
|
+
const frame = stack[top];
|
|
3090
|
+
stack.length = top;
|
|
3042
3091
|
if (frame === void 0) return false;
|
|
3043
3092
|
if (frame.operation === "exit") {
|
|
3044
3093
|
omitVisited(ancestors, frame.value);
|
|
@@ -4178,8 +4227,8 @@ function buildPositions(names) {
|
|
|
4178
4227
|
* Derives the bit mask of names present in an indexed lookup.
|
|
4179
4228
|
*
|
|
4180
4229
|
* @remarks
|
|
4181
|
-
* Takes `names` as the array it declares
|
|
4182
|
-
*
|
|
4230
|
+
* Takes `names` as the array it declares, reads its length once, and reads each present
|
|
4231
|
+
* index once, in order, so a hole adds no bit and is never read. An array-like that is not an array
|
|
4183
4232
|
* is outside this contract.
|
|
4184
4233
|
*
|
|
4185
4234
|
* @param names - Names to observe in order
|
|
@@ -4192,11 +4241,15 @@ function buildPositions(names) {
|
|
|
4192
4241
|
* ```
|
|
4193
4242
|
*/
|
|
4194
4243
|
function readPresence(names, positions) {
|
|
4195
|
-
|
|
4196
|
-
|
|
4244
|
+
let mask = 0;
|
|
4245
|
+
for (let index = 0, count = names.length; index < count; index++) {
|
|
4246
|
+
if (!(index in names)) continue;
|
|
4247
|
+
const name = names[index];
|
|
4248
|
+
if (name === void 0 || !INTRINSICS.own(positions, name)) continue;
|
|
4197
4249
|
const position = positions[name];
|
|
4198
|
-
|
|
4199
|
-
}
|
|
4250
|
+
if (position !== void 0) mask |= 1 << position;
|
|
4251
|
+
}
|
|
4252
|
+
return mask;
|
|
4200
4253
|
}
|
|
4201
4254
|
for (const generator of [iterateIndices, encodeParts]) {
|
|
4202
4255
|
for (const key of [
|
|
@@ -5847,10 +5900,12 @@ var ContractError = class ContractError extends Error {
|
|
|
5847
5900
|
*/
|
|
5848
5901
|
constructor(message, options) {
|
|
5849
5902
|
super(message, INTRINSICS.own(options, "cause") ? { cause: options.cause } : void 0);
|
|
5850
|
-
|
|
5903
|
+
const brand = {
|
|
5904
|
+
__proto__: null,
|
|
5851
5905
|
value: this,
|
|
5852
5906
|
configurable: true
|
|
5853
|
-
}
|
|
5907
|
+
};
|
|
5908
|
+
INTRINSICS.define(this, CONTRACT_ERROR_BRAND, brand);
|
|
5854
5909
|
this.code = options.code;
|
|
5855
5910
|
this.context = INTRINSICS.own(options, "context") ? options.context : void 0;
|
|
5856
5911
|
}
|
|
@@ -5860,10 +5915,15 @@ var ContractError = class ContractError extends Error {
|
|
|
5860
5915
|
if (key === void 0) continue;
|
|
5861
5916
|
const declared = INTRINSICS.describe(this.prototype, key);
|
|
5862
5917
|
const accessor = declared !== void 0 && !INTRINSICS.own(declared, "value");
|
|
5863
|
-
|
|
5918
|
+
const pin = accessor ? {
|
|
5919
|
+
__proto__: null,
|
|
5920
|
+
configurable: false
|
|
5921
|
+
} : {
|
|
5922
|
+
__proto__: null,
|
|
5864
5923
|
writable: false,
|
|
5865
5924
|
configurable: false
|
|
5866
|
-
}
|
|
5925
|
+
};
|
|
5926
|
+
INTRINSICS.reflect.define(this.prototype, key, pin);
|
|
5867
5927
|
const pinned = INTRINSICS.describe(this.prototype, key);
|
|
5868
5928
|
if (pinned?.configurable !== false || !accessor && pinned.writable !== false) throw new ContractError("ContractError: a prototype member could not be pinned", { code: "structure" });
|
|
5869
5929
|
}
|
|
@@ -5954,14 +6014,14 @@ var JSONCloner = class JSONCloner {
|
|
|
5954
6014
|
#owned;
|
|
5955
6015
|
#active;
|
|
5956
6016
|
#pending;
|
|
5957
|
-
#
|
|
6017
|
+
#entered;
|
|
5958
6018
|
#terminal;
|
|
5959
6019
|
constructor(value) {
|
|
5960
6020
|
this.#source = value;
|
|
5961
6021
|
this.#owned = new JSONCloner.#weakSet();
|
|
5962
6022
|
this.#active = new JSONCloner.#weakSet();
|
|
5963
6023
|
this.#pending = [];
|
|
5964
|
-
this.#
|
|
6024
|
+
this.#entered = false;
|
|
5965
6025
|
this.#terminal = void 0;
|
|
5966
6026
|
}
|
|
5967
6027
|
/**
|
|
@@ -5977,12 +6037,12 @@ var JSONCloner = class JSONCloner {
|
|
|
5977
6037
|
if (isSuccess(terminal)) return terminal.value;
|
|
5978
6038
|
throw terminal.error;
|
|
5979
6039
|
}
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
this.#terminal = failure(
|
|
5983
|
-
throw
|
|
6040
|
+
if (this.#entered) {
|
|
6041
|
+
const reentry = this.#create("JSONCloner.clone: JSON cloning may not be reentered", { shape: "json" });
|
|
6042
|
+
this.#terminal = failure(reentry);
|
|
6043
|
+
throw reentry;
|
|
5984
6044
|
}
|
|
5985
|
-
this.#
|
|
6045
|
+
this.#entered = true;
|
|
5986
6046
|
const outcome = attempt(() => this.#execute(budget));
|
|
5987
6047
|
const interruption = this.#terminal;
|
|
5988
6048
|
if (interruption !== void 0) {
|
|
@@ -6017,7 +6077,7 @@ var JSONCloner = class JSONCloner {
|
|
|
6017
6077
|
if (entry === void 0) {
|
|
6018
6078
|
INTRINSICS.freeze(frame.clone);
|
|
6019
6079
|
omitVisited(this.#active, frame.source);
|
|
6020
|
-
this.#pending.
|
|
6080
|
+
this.#pending.length -= 1;
|
|
6021
6081
|
continue;
|
|
6022
6082
|
}
|
|
6023
6083
|
frame.index = index + 1;
|
|
@@ -6083,7 +6143,7 @@ var JSONCloner = class JSONCloner {
|
|
|
6083
6143
|
const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
|
|
6084
6144
|
if (isFailure(lengthOutcome)) this.#refusePath("array length could not be inspected", preview(source));
|
|
6085
6145
|
const lengthDescriptor = lengthOutcome.value;
|
|
6086
|
-
if (lengthDescriptor === void 0 || !INTRINSICS.own(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value >
|
|
6146
|
+
if (lengthDescriptor === void 0 || !INTRINSICS.own(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 0xffffffff || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refusePath("array is not intrinsic and dense", preview(source));
|
|
6087
6147
|
const owned = collectMembers(keysOutcome.value);
|
|
6088
6148
|
if (!matchesMember(owned, "length")) this.#refusePath("array own keys are not exact", preview(source));
|
|
6089
6149
|
if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refusePath("array own keys are not exact", preview(source));
|
|
@@ -6216,7 +6276,14 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6216
6276
|
case "settled":
|
|
6217
6277
|
if (isSuccess(state.result)) return state.result.value;
|
|
6218
6278
|
throw state.result.error;
|
|
6219
|
-
case "running":
|
|
6279
|
+
case "running": {
|
|
6280
|
+
const poison = this.#create("SchemaCloner.clone: schema cloning may not be reentered");
|
|
6281
|
+
this.#state = {
|
|
6282
|
+
phase: "interrupted",
|
|
6283
|
+
poison
|
|
6284
|
+
};
|
|
6285
|
+
throw poison;
|
|
6286
|
+
}
|
|
6220
6287
|
case "interrupted":
|
|
6221
6288
|
this.#state = {
|
|
6222
6289
|
phase: "interrupted",
|
|
@@ -6224,11 +6291,7 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6224
6291
|
};
|
|
6225
6292
|
throw state.poison;
|
|
6226
6293
|
}
|
|
6227
|
-
|
|
6228
|
-
this.#state = {
|
|
6229
|
-
phase: "running",
|
|
6230
|
-
poison
|
|
6231
|
-
};
|
|
6294
|
+
this.#state = { phase: "running" };
|
|
6232
6295
|
return this.#complete(attempt(() => this.#execute()));
|
|
6233
6296
|
}
|
|
6234
6297
|
#complete(outcome) {
|
|
@@ -6255,7 +6318,9 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6255
6318
|
}
|
|
6256
6319
|
#drain() {
|
|
6257
6320
|
while (this.#pending.length > 0) {
|
|
6258
|
-
const
|
|
6321
|
+
const top = this.#pending.length - 1;
|
|
6322
|
+
const frame = this.#pending[top];
|
|
6323
|
+
this.#pending.length = top;
|
|
6259
6324
|
if (frame === void 0) continue;
|
|
6260
6325
|
if (frame.depth > 512) this.#refuse("cloneSchema: schema exceeds the compilation depth limit", "depth", frame.path);
|
|
6261
6326
|
const keys = enumerableKeys(frame.source);
|
|
@@ -6549,7 +6614,9 @@ var ShapePass = class ShapePass {
|
|
|
6549
6614
|
this.#finish();
|
|
6550
6615
|
}
|
|
6551
6616
|
#visit() {
|
|
6552
|
-
const
|
|
6617
|
+
const top = this.#stack.length - 1;
|
|
6618
|
+
const frame = this.#stack[top];
|
|
6619
|
+
this.#stack.length = top;
|
|
6553
6620
|
if (frame === void 0) return;
|
|
6554
6621
|
if (frame.operation === "exit") {
|
|
6555
6622
|
const capture = this.#captures[frame.index];
|
|
@@ -6836,7 +6903,9 @@ var ShapePass = class ShapePass {
|
|
|
6836
6903
|
schema: source
|
|
6837
6904
|
}];
|
|
6838
6905
|
while (stack.length > 0) {
|
|
6839
|
-
const
|
|
6906
|
+
const top = stack.length - 1;
|
|
6907
|
+
const frame = stack[top];
|
|
6908
|
+
stack.length = top;
|
|
6840
6909
|
if (frame === void 0) continue;
|
|
6841
6910
|
if (frame.operation === "exit") {
|
|
6842
6911
|
omitVisited(active, frame.schema);
|
|
@@ -7532,21 +7601,25 @@ var ShapeCloner = class ShapeCloner {
|
|
|
7532
7601
|
if (isSuccess(state.result)) return state.result.value;
|
|
7533
7602
|
throw state.result.error;
|
|
7534
7603
|
}
|
|
7535
|
-
if (state.phase === "
|
|
7604
|
+
if (state.phase === "interrupted") {
|
|
7536
7605
|
this.#state = {
|
|
7537
7606
|
phase: "interrupted",
|
|
7538
7607
|
poison: state.poison
|
|
7539
7608
|
};
|
|
7540
7609
|
throw state.poison;
|
|
7541
7610
|
}
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7611
|
+
if (state.phase === "running") {
|
|
7612
|
+
const poison = this.#create("ShapeCloner.clone: shape cloning may not be reentered", {
|
|
7613
|
+
code: "clone",
|
|
7614
|
+
context: { shape: "shape" }
|
|
7615
|
+
});
|
|
7616
|
+
this.#state = {
|
|
7617
|
+
phase: "interrupted",
|
|
7618
|
+
poison
|
|
7619
|
+
};
|
|
7620
|
+
throw poison;
|
|
7621
|
+
}
|
|
7622
|
+
this.#state = { phase: "running" };
|
|
7550
7623
|
return this.#complete(attempt(() => this.#execute()));
|
|
7551
7624
|
}
|
|
7552
7625
|
#complete(outcome) {
|
|
@@ -8568,11 +8641,11 @@ function recordOf(shape, optional) {
|
|
|
8568
8641
|
return (value) => holds(() => {
|
|
8569
8642
|
if (!isRecord(value)) return false;
|
|
8570
8643
|
const members = INTRINSICS.reflect.members(value);
|
|
8571
|
-
for (
|
|
8644
|
+
for (let index = 0, count = members.length; index < count; index++) {
|
|
8572
8645
|
const key = members[index];
|
|
8573
8646
|
if (isString(key) && !matchesMember(declared.vocabulary, key)) return false;
|
|
8574
8647
|
}
|
|
8575
|
-
for (
|
|
8648
|
+
for (let index = 0; index < declared.names.length; index++) {
|
|
8576
8649
|
const key = declared.names[index];
|
|
8577
8650
|
if (key === void 0) continue;
|
|
8578
8651
|
const guard = declared.guards[key];
|
|
@@ -9140,7 +9213,14 @@ function parseJSONValue(value) {
|
|
|
9140
9213
|
function parseEnum(value, allowed) {
|
|
9141
9214
|
const outcome = readArrayEntries(allowed);
|
|
9142
9215
|
if (isFailure(outcome) || !outcome.value.dense) return void 0;
|
|
9143
|
-
|
|
9216
|
+
const entries = outcome.value.entries;
|
|
9217
|
+
if (!holds(() => {
|
|
9218
|
+
for (let index = 0, count = entries.length; index < count; index++) {
|
|
9219
|
+
const entry = entries[index];
|
|
9220
|
+
if (entry === value || INTRINSICS.same(entry, value)) return true;
|
|
9221
|
+
}
|
|
9222
|
+
return false;
|
|
9223
|
+
})) return void 0;
|
|
9144
9224
|
return isLiteralValue(value) ? value : void 0;
|
|
9145
9225
|
}
|
|
9146
9226
|
/**
|
|
@@ -9354,30 +9434,41 @@ function parseJSONAs(value, guard) {
|
|
|
9354
9434
|
var EvaluationScope = class EvaluationScope {
|
|
9355
9435
|
static #active = new INTRINSICS.set();
|
|
9356
9436
|
static #path = INTRINSICS.freeze([]);
|
|
9357
|
-
#answers
|
|
9358
|
-
/**
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9437
|
+
#answers;
|
|
9438
|
+
/**
|
|
9439
|
+
* Evaluates a node within the active call, disposing a newly opened scope on settlement.
|
|
9440
|
+
*
|
|
9441
|
+
* @remarks
|
|
9442
|
+
* The plan receives `built` as its third argument: true when this package built `path`.
|
|
9443
|
+
*/
|
|
9444
|
+
static run(plan, value, path = EvaluationScope.#path, clean = false, built = false) {
|
|
9445
|
+
if (!isObject(value) && !isFunction(value)) return plan(value, path, built);
|
|
9446
|
+
const active = EvaluationScope.#read();
|
|
9447
|
+
if (active instanceof EvaluationScope) return active.#evaluate(plan, value, path, clean, built);
|
|
9365
9448
|
if (active !== void 0) throw new INTRINSICS.error("Evaluation scope is unavailable");
|
|
9366
9449
|
const scope = new EvaluationScope();
|
|
9367
9450
|
INTRINSICS.reflect.apply(INTRINSICS.admit, EvaluationScope.#active, [scope]);
|
|
9368
9451
|
try {
|
|
9369
|
-
return plan(value, path);
|
|
9452
|
+
return plan(value, path, built);
|
|
9370
9453
|
} finally {
|
|
9371
9454
|
INTRINSICS.reflect.apply(INTRINSICS.remove, EvaluationScope.#active, [scope]);
|
|
9372
9455
|
}
|
|
9373
9456
|
}
|
|
9374
|
-
#
|
|
9375
|
-
const
|
|
9457
|
+
static #read() {
|
|
9458
|
+
const count = INTRINSICS.count;
|
|
9459
|
+
if (count !== void 0 && INTRINSICS.reflect.apply(count, EvaluationScope.#active, []) === 0) return;
|
|
9460
|
+
const cursor = INTRINSICS.reflect.apply(INTRINSICS.cursor, EvaluationScope.#active, []);
|
|
9461
|
+
const step = INTRINSICS.reflect.apply(INTRINSICS.step, cursor, []);
|
|
9462
|
+
return step.done === true ? void 0 : step.value;
|
|
9463
|
+
}
|
|
9464
|
+
#evaluate(plan, value, path, clean, built) {
|
|
9465
|
+
const answers = this.#answers ??= new INTRINSICS.weakMap();
|
|
9466
|
+
const cached = INTRINSICS.reflect.apply(INTRINSICS.recall, answers, [plan]);
|
|
9376
9467
|
const memo = cached ?? new INTRINSICS.weakMap();
|
|
9377
|
-
if (cached === void 0) INTRINSICS.reflect.apply(INTRINSICS.retain,
|
|
9468
|
+
if (cached === void 0) INTRINSICS.reflect.apply(INTRINSICS.retain, answers, [plan, memo]);
|
|
9378
9469
|
const recalled = INTRINSICS.reflect.apply(INTRINSICS.recall, memo, [value]);
|
|
9379
9470
|
if (recalled !== void 0) return recalled;
|
|
9380
|
-
const answer = plan(value, path);
|
|
9471
|
+
const answer = plan(value, path, built);
|
|
9381
9472
|
if (!clean || INTRINSICS.array(answer) && answer.length === 0) INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [value, answer]);
|
|
9382
9473
|
return answer;
|
|
9383
9474
|
}
|
|
@@ -9520,7 +9611,7 @@ var ValueCloner = class ValueCloner {
|
|
|
9520
9611
|
copy,
|
|
9521
9612
|
array,
|
|
9522
9613
|
plan,
|
|
9523
|
-
path: key === void 0 ? path :
|
|
9614
|
+
path: key === void 0 ? path : buildChildPath(path, key)
|
|
9524
9615
|
};
|
|
9525
9616
|
return copy;
|
|
9526
9617
|
}
|
|
@@ -9593,7 +9684,7 @@ var RandomSource = class {
|
|
|
9593
9684
|
}
|
|
9594
9685
|
/** Advances the generator and returns its next unit-interval value. */
|
|
9595
9686
|
next() {
|
|
9596
|
-
this.#state = this.#state +
|
|
9687
|
+
this.#state = this.#state + 0x6d2b79f5 >>> 0;
|
|
9597
9688
|
const mixed = INTRINSICS.imul(this.#state ^ this.#state >>> 15, this.#state | 1);
|
|
9598
9689
|
const final = mixed ^ mixed + INTRINSICS.imul(mixed ^ mixed >>> 7, mixed | 61);
|
|
9599
9690
|
return ((final ^ final >>> 14) >>> 0) / 4294967296;
|
|
@@ -9830,24 +9921,28 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9830
9921
|
#enter(build) {
|
|
9831
9922
|
const state = this.#state;
|
|
9832
9923
|
if (state.phase === "failed") throw state.error;
|
|
9833
|
-
if (state.phase === "
|
|
9924
|
+
if (state.phase === "interrupted") {
|
|
9834
9925
|
this.#state = {
|
|
9835
9926
|
phase: "interrupted",
|
|
9836
9927
|
poison: state.poison
|
|
9837
9928
|
};
|
|
9838
9929
|
throw state.poison;
|
|
9839
9930
|
}
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9931
|
+
if (state.phase === "running") {
|
|
9932
|
+
const poison = new ContractError("ContractCompiler: contract compilation may not be reentered", {
|
|
9933
|
+
code: "structure",
|
|
9934
|
+
context: {
|
|
9935
|
+
path: [],
|
|
9936
|
+
shape: "contract"
|
|
9937
|
+
}
|
|
9938
|
+
});
|
|
9939
|
+
this.#state = {
|
|
9940
|
+
phase: "interrupted",
|
|
9941
|
+
poison
|
|
9942
|
+
};
|
|
9943
|
+
throw poison;
|
|
9944
|
+
}
|
|
9945
|
+
this.#state = { phase: "running" };
|
|
9851
9946
|
return this.#leave(attempt(build));
|
|
9852
9947
|
}
|
|
9853
9948
|
#leave(outcome) {
|
|
@@ -10124,7 +10219,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10124
10219
|
return (value) => EvaluationScope.run(plan, value);
|
|
10125
10220
|
}
|
|
10126
10221
|
#trackFaults(plan) {
|
|
10127
|
-
return (value, path) => EvaluationScope.run(plan, value, path, true);
|
|
10222
|
+
return (value, path, built) => EvaluationScope.run(plan, value, path, true, built);
|
|
10128
10223
|
}
|
|
10129
10224
|
#discriminate(owned) {
|
|
10130
10225
|
const arms = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(owned.variants), [(variant) => variant?.category === "object"]);
|
|
@@ -10141,7 +10236,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10141
10236
|
}),
|
|
10142
10237
|
select: (value) => {
|
|
10143
10238
|
if (!isObject(value)) return void 0;
|
|
10144
|
-
for (
|
|
10239
|
+
for (let index = 0, count = tables.length; index < count; index++) {
|
|
10145
10240
|
const table = tables[index];
|
|
10146
10241
|
if (table === void 0) continue;
|
|
10147
10242
|
const held = attempt(() => INTRINSICS.describe(value, table.key));
|
|
@@ -10399,7 +10494,9 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10399
10494
|
if (!INTRINSICS.array(value)) return false;
|
|
10400
10495
|
const read = collectArrayEntries(value);
|
|
10401
10496
|
if (!read.dense || !read.exact) return false;
|
|
10402
|
-
|
|
10497
|
+
const entries = read.entries;
|
|
10498
|
+
for (let position = 0, count = entries.length; position < count; position++) if (!element(entries[position])) return false;
|
|
10499
|
+
return withinLength === void 0 || withinLength(entries.length);
|
|
10403
10500
|
});
|
|
10404
10501
|
}
|
|
10405
10502
|
case "object": {
|
|
@@ -10430,7 +10527,13 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10430
10527
|
const keys = INTRINSICS.keys(value);
|
|
10431
10528
|
if (extra !== true && !matchesEnumerableKeys(value, keys)) return false;
|
|
10432
10529
|
const plan = plans?.recall(keys);
|
|
10433
|
-
if (plan !== void 0)
|
|
10530
|
+
if (plan !== void 0) {
|
|
10531
|
+
for (let position = 0, count = plan.length; position < count; position++) {
|
|
10532
|
+
const step = plan[position];
|
|
10533
|
+
if (step !== void 0 && !step.guard(value[step.key])) return false;
|
|
10534
|
+
}
|
|
10535
|
+
return true;
|
|
10536
|
+
}
|
|
10434
10537
|
if (maskable) {
|
|
10435
10538
|
if (readPresence(keys, positions) !== full) return false;
|
|
10436
10539
|
} else {
|
|
@@ -10470,7 +10573,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10470
10573
|
case "nullable": return nullableOf(this.#guardAt(owned.inner));
|
|
10471
10574
|
case "interface": {
|
|
10472
10575
|
const audit = this.#auditAt(owned);
|
|
10473
|
-
return (value) => holds(() => audit(value, ContractCompiler.#root).length === 0);
|
|
10576
|
+
return (value) => holds(() => audit(value, ContractCompiler.#root, true).length === 0);
|
|
10474
10577
|
}
|
|
10475
10578
|
case "raw": return (value) => value !== void 0;
|
|
10476
10579
|
}
|
|
@@ -10640,7 +10743,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10640
10743
|
selected[selected.length] = [key, parsed];
|
|
10641
10744
|
return false;
|
|
10642
10745
|
}])) return void 0;
|
|
10643
|
-
|
|
10746
|
+
const result = { __proto__: null };
|
|
10747
|
+
for (let step = 0; step < selected.length; step++) {
|
|
10748
|
+
const pair = selected[step];
|
|
10749
|
+
if (pair !== void 0) result[pair[0]] = pair[1];
|
|
10750
|
+
}
|
|
10751
|
+
return result;
|
|
10644
10752
|
});
|
|
10645
10753
|
if (isSuccess(outcome)) return outcome.value;
|
|
10646
10754
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
@@ -10670,12 +10778,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10670
10778
|
const selected = discriminated?.select(value);
|
|
10671
10779
|
const arm = selected === void 0 ? void 0 : variants[selected];
|
|
10672
10780
|
if (arm !== void 0) return ContractCompiler.#parseArm(arm, value);
|
|
10673
|
-
for (
|
|
10781
|
+
for (let variantIndex = 0, count = variants.length; variantIndex < count; variantIndex++) {
|
|
10674
10782
|
const variant = variants[variantIndex];
|
|
10675
10783
|
if (variant === void 0) continue;
|
|
10676
10784
|
if (variant.guard(value)) return value;
|
|
10677
10785
|
}
|
|
10678
|
-
for (
|
|
10786
|
+
for (let variantIndex = 0, count = variants.length; variantIndex < count; variantIndex++) {
|
|
10679
10787
|
const variant = variants[variantIndex];
|
|
10680
10788
|
if (variant === void 0) continue;
|
|
10681
10789
|
const parsed = variant.parse(value);
|
|
@@ -10694,7 +10802,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10694
10802
|
case "interface": {
|
|
10695
10803
|
const audit = this.#auditAt(owned);
|
|
10696
10804
|
return (value) => {
|
|
10697
|
-
const outcome = attempt(() => audit(value, ContractCompiler.#root));
|
|
10805
|
+
const outcome = attempt(() => audit(value, ContractCompiler.#root, true));
|
|
10698
10806
|
if (isSuccess(outcome)) return outcome.value.length === 0 ? value : void 0;
|
|
10699
10807
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
10700
10808
|
return readValue(() => {
|
|
@@ -10743,7 +10851,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10743
10851
|
}]);
|
|
10744
10852
|
}
|
|
10745
10853
|
#exposeAudit(plan) {
|
|
10746
|
-
return (value, path
|
|
10854
|
+
return (value, path) => contain(() => path === void 0 ? plan(value, [], true) : plan(value, path, false), "compileAuditor");
|
|
10747
10855
|
}
|
|
10748
10856
|
#auditAt(shape) {
|
|
10749
10857
|
const compiled = this.#audits[this.#locate(shape)];
|
|
@@ -10839,7 +10947,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10839
10947
|
const item = this.#auditAt(owned.items);
|
|
10840
10948
|
const admitted = this.#admits(owned.items);
|
|
10841
10949
|
const kind = shapeToKind(owned.items);
|
|
10842
|
-
return (value, path) => {
|
|
10950
|
+
return (value, path, built) => {
|
|
10843
10951
|
if (isObject(value)) readValue(() => INTRINSICS.array(value), "compileAuditor", {
|
|
10844
10952
|
subject: "array",
|
|
10845
10953
|
context: {
|
|
@@ -10870,12 +10978,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10870
10978
|
if (admitted && !entries.value.dense && !INTRINSICS.own(entries.value.entries, at)) {
|
|
10871
10979
|
faults[faults.length] = {
|
|
10872
10980
|
reason: "missing",
|
|
10873
|
-
path: pathOf(path, at),
|
|
10981
|
+
path: built ? buildChildPath(path, at) : pathOf(path, at),
|
|
10874
10982
|
expected: kind
|
|
10875
10983
|
};
|
|
10876
10984
|
continue;
|
|
10877
10985
|
}
|
|
10878
|
-
appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, at)));
|
|
10986
|
+
appendEntries(faults, item(entries.value.entries[entryIndex], built ? buildChildPath(path, at) : pathOf(path, at), true));
|
|
10879
10987
|
}
|
|
10880
10988
|
appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
|
|
10881
10989
|
if (entries.value.exact) return limitEntries(faults, 64);
|
|
@@ -10893,7 +11001,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10893
11001
|
if (isString(member)) {
|
|
10894
11002
|
if (!INTRINSICS.own(snapshot, member)) faults[faults.length] = {
|
|
10895
11003
|
reason: "extra",
|
|
10896
|
-
path: pathOf(path, member)
|
|
11004
|
+
path: built ? buildChildPath(path, member) : pathOf(path, member)
|
|
10897
11005
|
};
|
|
10898
11006
|
} else if (member !== void 0) faults[faults.length] = {
|
|
10899
11007
|
reason: "extra",
|
|
@@ -10925,7 +11033,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10925
11033
|
const declared = isSuccess(planned) ? planned.value : void 0;
|
|
10926
11034
|
const maskable = entries.length <= 31;
|
|
10927
11035
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
10928
|
-
return (value, path) => {
|
|
11036
|
+
return (value, path, built) => {
|
|
10929
11037
|
if (isObject(value)) readValue(() => INTRINSICS.reflect.prototype(value), "compileAuditor", {
|
|
10930
11038
|
subject: "object",
|
|
10931
11039
|
context: {
|
|
@@ -10962,16 +11070,16 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10962
11070
|
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
10963
11071
|
if (matchesMember(concealed, entry.key)) faults[faults.length] = {
|
|
10964
11072
|
reason: "hidden",
|
|
10965
|
-
path: pathOf(path, entry.key)
|
|
11073
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key)
|
|
10966
11074
|
};
|
|
10967
11075
|
else if (!entry.optional) faults[faults.length] = {
|
|
10968
11076
|
reason: "missing",
|
|
10969
|
-
path: pathOf(path, entry.key),
|
|
11077
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
10970
11078
|
expected: entry.kind
|
|
10971
11079
|
};
|
|
10972
11080
|
continue;
|
|
10973
11081
|
}
|
|
10974
|
-
appendEntries(faults, entry.audit(record[entry.key], pathOf(path, entry.key)));
|
|
11082
|
+
appendEntries(faults, entry.audit(record[entry.key], built ? buildChildPath(path, entry.key) : pathOf(path, entry.key), true));
|
|
10975
11083
|
}
|
|
10976
11084
|
for (const keyIndex of iterateIndices(() => keys.length)) {
|
|
10977
11085
|
const key = keys[keyIndex];
|
|
@@ -10981,12 +11089,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10981
11089
|
if (closed) {
|
|
10982
11090
|
faults[faults.length] = {
|
|
10983
11091
|
reason: "extra",
|
|
10984
|
-
path: pathOf(path, key)
|
|
11092
|
+
path: built ? buildChildPath(path, key) : pathOf(path, key)
|
|
10985
11093
|
};
|
|
10986
11094
|
continue;
|
|
10987
11095
|
}
|
|
10988
11096
|
const observed = record[key];
|
|
10989
|
-
if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
|
|
11097
|
+
if (additional !== void 0) appendEntries(faults, additional(observed, built ? buildChildPath(path, key) : pathOf(path, key), true));
|
|
10990
11098
|
}
|
|
10991
11099
|
for (const nameIndex of iterateIndices(() => outside.length)) {
|
|
10992
11100
|
const name = outside[nameIndex];
|
|
@@ -10994,7 +11102,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10994
11102
|
if (faults.length >= 64) return;
|
|
10995
11103
|
faults[faults.length] = {
|
|
10996
11104
|
reason: closed ? "extra" : "hidden",
|
|
10997
|
-
path: pathOf(path, name)
|
|
11105
|
+
path: built ? buildChildPath(path, name) : pathOf(path, name)
|
|
10998
11106
|
};
|
|
10999
11107
|
}
|
|
11000
11108
|
const symbols = extra === true ? [] : INTRINSICS.symbols(record);
|
|
@@ -11027,15 +11135,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11027
11135
|
const exclusive = owned.mode === "oneOf";
|
|
11028
11136
|
const count = owned.variants.length;
|
|
11029
11137
|
const discriminated = this.#discriminate(owned);
|
|
11030
|
-
return (value, path) => {
|
|
11138
|
+
return (value, path, built) => {
|
|
11031
11139
|
const selected = discriminated?.select(value);
|
|
11032
11140
|
const arm = selected === void 0 ? void 0 : plans[selected];
|
|
11033
|
-
if (arm !== void 0) return arm(value, path);
|
|
11141
|
+
if (arm !== void 0) return arm(value, path, built);
|
|
11034
11142
|
const perVariant = [];
|
|
11035
11143
|
for (const index2 of iterateIndices(() => plans.length)) {
|
|
11036
11144
|
const plan = plans[index2];
|
|
11037
11145
|
if (plan === void 0) continue;
|
|
11038
|
-
const variantFaults = plan(value, path);
|
|
11146
|
+
const variantFaults = plan(value, path, built);
|
|
11039
11147
|
if (variantFaults.length === 0) {
|
|
11040
11148
|
if (!exclusive) return [];
|
|
11041
11149
|
}
|
|
@@ -11069,15 +11177,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11069
11177
|
}
|
|
11070
11178
|
case "optional": {
|
|
11071
11179
|
const inner = this.#auditAt(owned.inner);
|
|
11072
|
-
return (value, path) => value === void 0 ? [] : inner(value, path);
|
|
11180
|
+
return (value, path, built) => value === void 0 ? [] : inner(value, path, built);
|
|
11073
11181
|
}
|
|
11074
11182
|
case "nullable": {
|
|
11075
11183
|
const inner = this.#auditAt(owned.inner);
|
|
11076
|
-
return (value, path) => value === null ? [] : inner(value, path);
|
|
11184
|
+
return (value, path, built) => value === null ? [] : inner(value, path, built);
|
|
11077
11185
|
}
|
|
11078
11186
|
case "interface": {
|
|
11079
11187
|
const entries = this.#membersOf(owned);
|
|
11080
|
-
return (value, path) => {
|
|
11188
|
+
return (value, path, built) => {
|
|
11081
11189
|
if (isObject(value)) readValue(() => INTRINSICS.array(value), "compileAuditor", {
|
|
11082
11190
|
subject: "interface",
|
|
11083
11191
|
context: {
|
|
@@ -11096,7 +11204,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11096
11204
|
const entry = entries[entryIndex];
|
|
11097
11205
|
if (entry === void 0) continue;
|
|
11098
11206
|
if (faults.length >= 64) break;
|
|
11099
|
-
const at = pathOf(path, entry.key);
|
|
11207
|
+
const at = built ? buildChildPath(path, entry.key) : pathOf(path, entry.key);
|
|
11100
11208
|
const member = readValue(() => INTRINSICS.reflect.read(value, entry.key), "compileAuditor", {
|
|
11101
11209
|
subject: "interface member",
|
|
11102
11210
|
context: {
|
|
@@ -11112,7 +11220,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11112
11220
|
};
|
|
11113
11221
|
continue;
|
|
11114
11222
|
}
|
|
11115
|
-
appendEntries(faults, entry.audit(member, at));
|
|
11223
|
+
appendEntries(faults, entry.audit(member, at, true));
|
|
11116
11224
|
}
|
|
11117
11225
|
return limitEntries(faults, 64);
|
|
11118
11226
|
};
|
|
@@ -11142,7 +11250,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11142
11250
|
return root;
|
|
11143
11251
|
}
|
|
11144
11252
|
#exposeReport(plan) {
|
|
11145
|
-
return (value, path
|
|
11253
|
+
return (value, path) => contain(() => path === void 0 ? plan(value, [], true) : plan(value, path, false), "compileReporter");
|
|
11146
11254
|
}
|
|
11147
11255
|
#reportAt(shape) {
|
|
11148
11256
|
const compiled = this.#reports[this.#locate(shape)];
|
|
@@ -11240,7 +11348,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11240
11348
|
const item = this.#reportAt(owned.items);
|
|
11241
11349
|
const admitted = this.#admits(owned.items);
|
|
11242
11350
|
const kind = shapeToKind(owned.items);
|
|
11243
|
-
return (value, path) => {
|
|
11351
|
+
return (value, path, built) => {
|
|
11244
11352
|
if (!isArray(value)) return [{
|
|
11245
11353
|
reason: "type",
|
|
11246
11354
|
path,
|
|
@@ -11261,12 +11369,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11261
11369
|
if (admitted && !entries.value.dense && !INTRINSICS.own(entries.value.entries, at)) {
|
|
11262
11370
|
faults[faults.length] = {
|
|
11263
11371
|
reason: "missing",
|
|
11264
|
-
path: pathOf(path, at),
|
|
11372
|
+
path: built ? buildChildPath(path, at) : pathOf(path, at),
|
|
11265
11373
|
expected: kind
|
|
11266
11374
|
};
|
|
11267
11375
|
continue;
|
|
11268
11376
|
}
|
|
11269
|
-
appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, at)));
|
|
11377
|
+
appendEntries(faults, item(entries.value.entries[entryIndex], built ? buildChildPath(path, at) : pathOf(path, at), true));
|
|
11270
11378
|
}
|
|
11271
11379
|
appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
|
|
11272
11380
|
return limitEntries(faults, 64);
|
|
@@ -11295,7 +11403,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11295
11403
|
const known = isSuccess(planned) ? planned.value : void 0;
|
|
11296
11404
|
const maskable = entries.length <= 31;
|
|
11297
11405
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
11298
|
-
return (value, path) => {
|
|
11406
|
+
return (value, path, built) => {
|
|
11299
11407
|
if (!isRecord(value)) return [{
|
|
11300
11408
|
reason: "type",
|
|
11301
11409
|
path,
|
|
@@ -11322,7 +11430,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11322
11430
|
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
11323
11431
|
if (!entry.optional) faults[faults.length] = {
|
|
11324
11432
|
reason: "missing",
|
|
11325
|
-
path: pathOf(path, entry.key),
|
|
11433
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
11326
11434
|
expected: entry.kind
|
|
11327
11435
|
};
|
|
11328
11436
|
continue;
|
|
@@ -11331,12 +11439,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11331
11439
|
if (raw === void 0 && !entry.admits) {
|
|
11332
11440
|
if (!entry.optional) faults[faults.length] = {
|
|
11333
11441
|
reason: "missing",
|
|
11334
|
-
path: pathOf(path, entry.key),
|
|
11442
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
11335
11443
|
expected: entry.kind
|
|
11336
11444
|
};
|
|
11337
11445
|
continue;
|
|
11338
11446
|
}
|
|
11339
|
-
appendEntries(faults, entry.report(raw, pathOf(path, entry.key)));
|
|
11447
|
+
appendEntries(faults, entry.report(raw, built ? buildChildPath(path, entry.key) : pathOf(path, entry.key), true));
|
|
11340
11448
|
}
|
|
11341
11449
|
if (open) for (const keyIndex of iterateIndices(() => keys.length)) {
|
|
11342
11450
|
const key = keys[keyIndex];
|
|
@@ -11344,7 +11452,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11344
11452
|
if (faults.length >= 64) return;
|
|
11345
11453
|
if (matchesMember(vocabulary, key)) continue;
|
|
11346
11454
|
const observed = record[key];
|
|
11347
|
-
if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
|
|
11455
|
+
if (tail !== void 0) appendEntries(faults, tail(observed, built ? buildChildPath(path, key) : pathOf(path, key), true));
|
|
11348
11456
|
}
|
|
11349
11457
|
}))) return [{
|
|
11350
11458
|
reason: "type",
|
|
@@ -11365,15 +11473,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11365
11473
|
const exclusive = owned.mode === "oneOf";
|
|
11366
11474
|
const count = owned.variants.length;
|
|
11367
11475
|
const discriminated = this.#discriminate(owned);
|
|
11368
|
-
return (value, path) => {
|
|
11476
|
+
return (value, path, built) => {
|
|
11369
11477
|
const selected = discriminated?.select(value);
|
|
11370
11478
|
const arm = selected === void 0 ? void 0 : plans[selected];
|
|
11371
|
-
if (arm !== void 0) return arm(value, path);
|
|
11479
|
+
if (arm !== void 0) return arm(value, path, built);
|
|
11372
11480
|
const perVariant = [];
|
|
11373
11481
|
for (const index2 of iterateIndices(() => plans.length)) {
|
|
11374
11482
|
const plan = plans[index2];
|
|
11375
11483
|
if (plan === void 0) continue;
|
|
11376
|
-
const variantFaults = plan(value, path);
|
|
11484
|
+
const variantFaults = plan(value, path, built);
|
|
11377
11485
|
if (!exclusive && variantFaults.length === 0) return [];
|
|
11378
11486
|
perVariant[perVariant.length] = variantFaults;
|
|
11379
11487
|
}
|
|
@@ -11410,15 +11518,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11410
11518
|
}
|
|
11411
11519
|
case "optional": {
|
|
11412
11520
|
const inner = this.#reportAt(owned.inner);
|
|
11413
|
-
return (value, path) => value === void 0 ? [] : inner(value, path);
|
|
11521
|
+
return (value, path, built) => value === void 0 ? [] : inner(value, path, built);
|
|
11414
11522
|
}
|
|
11415
11523
|
case "nullable": {
|
|
11416
11524
|
const inner = this.#reportAt(owned.inner);
|
|
11417
|
-
return (value, path) => value === null ? [] : inner(value, path);
|
|
11525
|
+
return (value, path, built) => value === null ? [] : inner(value, path, built);
|
|
11418
11526
|
}
|
|
11419
11527
|
case "interface": {
|
|
11420
11528
|
const entries = this.#membersOf(owned);
|
|
11421
|
-
return (value, path) => {
|
|
11529
|
+
return (value, path, built) => {
|
|
11422
11530
|
if (!isObject(value) && !isFunction(value) || isArray(value)) return [{
|
|
11423
11531
|
reason: "type",
|
|
11424
11532
|
path,
|
|
@@ -11431,7 +11539,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11431
11539
|
const entry = entries[entryIndex];
|
|
11432
11540
|
if (entry === void 0) continue;
|
|
11433
11541
|
if (faults.length >= 64) return;
|
|
11434
|
-
const at = pathOf(path, entry.key);
|
|
11542
|
+
const at = built ? buildChildPath(path, entry.key) : pathOf(path, entry.key);
|
|
11435
11543
|
const member = INTRINSICS.reflect.read(value, entry.key);
|
|
11436
11544
|
if (member === void 0 && !entry.admits) {
|
|
11437
11545
|
if (!entry.optional) faults[faults.length] = {
|
|
@@ -11441,7 +11549,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11441
11549
|
};
|
|
11442
11550
|
continue;
|
|
11443
11551
|
}
|
|
11444
|
-
const found = entry.audit(member, at);
|
|
11552
|
+
const found = entry.audit(member, at, true);
|
|
11445
11553
|
const kept = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(found), [(fault) => fault.reason !== "extra" && fault.reason !== "hidden"]);
|
|
11446
11554
|
if (kept.length < found.length) faults[faults.length] = {
|
|
11447
11555
|
reason: "type",
|
|
@@ -11948,7 +12056,7 @@ function compileGenerator(shape, random) {
|
|
|
11948
12056
|
* compileReporter(user, { name: 'Ada' }) // []
|
|
11949
12057
|
* ```
|
|
11950
12058
|
*/
|
|
11951
|
-
function compileReporter(shape, value, path
|
|
12059
|
+
function compileReporter(shape, value, path) {
|
|
11952
12060
|
return contain(() => new ContractCompiler(shape).reporter(value, path), "compileReporter");
|
|
11953
12061
|
}
|
|
11954
12062
|
/**
|
|
@@ -11986,7 +12094,7 @@ function compileReporter(shape, value, path = []) {
|
|
|
11986
12094
|
* // [{ reason: 'extra', path: ['extra'] }]
|
|
11987
12095
|
* ```
|
|
11988
12096
|
*/
|
|
11989
|
-
function compileAuditor(shape, value, path
|
|
12097
|
+
function compileAuditor(shape, value, path) {
|
|
11990
12098
|
return contain(() => new ContractCompiler(shape).auditor(value, path), "compileAuditor");
|
|
11991
12099
|
}
|
|
11992
12100
|
// src/core/LazyContract.ts
|
|
@@ -12051,10 +12159,10 @@ var LazyContract = class {
|
|
|
12051
12159
|
};
|
|
12052
12160
|
}
|
|
12053
12161
|
#audit() {
|
|
12054
|
-
return (value, path
|
|
12162
|
+
return (value, path) => (this.#settled ?? this.#settle("compileAuditor")).auditor(value, path);
|
|
12055
12163
|
}
|
|
12056
12164
|
#explain() {
|
|
12057
|
-
return (value, path
|
|
12165
|
+
return (value, path) => (this.#settled ?? this.#settle("compileReporter")).reporter(value, path);
|
|
12058
12166
|
}
|
|
12059
12167
|
#generate() {
|
|
12060
12168
|
return (random) => (this.#settled ?? this.#settle("compileGenerator")).generator(random);
|
|
@@ -14314,6 +14422,7 @@ exports.auditFaultShape = auditFaultShape;
|
|
|
14314
14422
|
exports.booleanShape = booleanShape;
|
|
14315
14423
|
exports.boundsOf = boundsOf;
|
|
14316
14424
|
exports.buildArrayFaults = buildArrayFaults;
|
|
14425
|
+
exports.buildChildPath = buildChildPath;
|
|
14317
14426
|
exports.buildKeyPlan = buildKeyPlan;
|
|
14318
14427
|
exports.buildNumberFaults = buildNumberFaults;
|
|
14319
14428
|
exports.buildPathKey = buildPathKey;
|