@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.js
CHANGED
|
@@ -302,6 +302,12 @@ var INTRINSICS = Object.freeze({
|
|
|
302
302
|
sweep: Set.prototype.forEach,
|
|
303
303
|
/** Captures `Set.prototype.delete` — settlement of an active operation. */
|
|
304
304
|
remove: Set.prototype.delete,
|
|
305
|
+
/** Captures the `Set.prototype.size` getter — the emptiness answer of a registry this package built, dispatched through `apply`. */
|
|
306
|
+
count: Object.getOwnPropertyDescriptor(Set.prototype, "size")?.get,
|
|
307
|
+
/** Captures `Set.prototype.values` — an ordered cursor over a registry this package built, dispatched through `apply`. */
|
|
308
|
+
cursor: Set.prototype.values,
|
|
309
|
+
/** Captures the native set iterator advance operation. */
|
|
310
|
+
step: Object.getPrototypeOf((/* @__PURE__ */ new Set()).values()).next,
|
|
305
311
|
/** Captures `WeakMap` — object-keyed working state. */
|
|
306
312
|
weakMap: WeakMap,
|
|
307
313
|
/** Captures `WeakMap.prototype.get` — an object-keyed memo read a published graph embeds, dispatched through `apply`. */
|
|
@@ -1157,6 +1163,37 @@ function pathOf(path, ...segments) {
|
|
|
1157
1163
|
return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(combined), [(segment) => segment !== void 0]);
|
|
1158
1164
|
}
|
|
1159
1165
|
/**
|
|
1166
|
+
* Builds a child's path from a dense path this package built and the child's key, without
|
|
1167
|
+
* dispatching through array iteration.
|
|
1168
|
+
*
|
|
1169
|
+
* @remarks
|
|
1170
|
+
* Reads `length` once and each segment once, in order, through a null-prototype array-like
|
|
1171
|
+
* that reaches no iterator and no caller member. A caller's path goes through {@link pathOf}
|
|
1172
|
+
* instead, which rereads its length before every segment and omits an absent one.
|
|
1173
|
+
*
|
|
1174
|
+
* @param path - A dense path this package built
|
|
1175
|
+
* @param key - The child's key
|
|
1176
|
+
* @returns A fresh path carrying every segment and then the key
|
|
1177
|
+
* @throws An `Error` when `path` holds an absent segment
|
|
1178
|
+
*
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```ts
|
|
1181
|
+
* buildChildPath(['user'], 'name') // ['user', 'name']
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
function buildChildPath(path, key) {
|
|
1185
|
+
const length = path.length;
|
|
1186
|
+
const indices = {
|
|
1187
|
+
__proto__: null,
|
|
1188
|
+
length: length + 1
|
|
1189
|
+
};
|
|
1190
|
+
return INTRINSICS.from(indices, (_entry, index) => {
|
|
1191
|
+
const segment = index < length ? path[index] : key;
|
|
1192
|
+
if (segment === void 0) throw new INTRINSICS.error("A built path holds an absent segment");
|
|
1193
|
+
return segment;
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1160
1197
|
* Appends every element of one array onto another, by index.
|
|
1161
1198
|
*
|
|
1162
1199
|
* @remarks
|
|
@@ -1890,10 +1927,15 @@ function pinMembers(prototype, owner) {
|
|
|
1890
1927
|
if (key === void 0) continue;
|
|
1891
1928
|
const declared = INTRINSICS.describe(prototype, key);
|
|
1892
1929
|
const accessor = declared !== void 0 && !INTRINSICS.own(declared, "value");
|
|
1893
|
-
|
|
1930
|
+
const pin = accessor ? {
|
|
1931
|
+
__proto__: null,
|
|
1932
|
+
configurable: false
|
|
1933
|
+
} : {
|
|
1934
|
+
__proto__: null,
|
|
1894
1935
|
writable: false,
|
|
1895
1936
|
configurable: false
|
|
1896
|
-
}
|
|
1937
|
+
};
|
|
1938
|
+
INTRINSICS.reflect.define(prototype, key, pin);
|
|
1897
1939
|
const pinned = INTRINSICS.describe(prototype, key);
|
|
1898
1940
|
if (pinned?.configurable !== false || !accessor && pinned.writable !== false) throw new ContractError(`${owner}: a prototype member could not be pinned`, {
|
|
1899
1941
|
code: "structure",
|
|
@@ -2431,7 +2473,9 @@ function collectArrayEntries(value) {
|
|
|
2431
2473
|
const length = value.length;
|
|
2432
2474
|
if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
|
|
2433
2475
|
const members = INTRINSICS.reflect.members(value);
|
|
2434
|
-
|
|
2476
|
+
let canonical = members.length === length + 1 && members[length] === "length";
|
|
2477
|
+
for (let index = 0; canonical && index < length; index++) canonical = members[index] === INTRINSICS.text(index);
|
|
2478
|
+
if (canonical) {
|
|
2435
2479
|
const indices = {
|
|
2436
2480
|
__proto__: null,
|
|
2437
2481
|
length
|
|
@@ -2641,13 +2685,16 @@ function buildKeyPlan(keys, guards) {
|
|
|
2641
2685
|
* ```
|
|
2642
2686
|
*/
|
|
2643
2687
|
function matchesKeyPlan(plan) {
|
|
2644
|
-
|
|
2688
|
+
if (plan.length !== this.length) return false;
|
|
2689
|
+
for (let index = 0, count = plan.length; index < count; index++) if (index in plan && plan[index]?.key !== this[index]) return false;
|
|
2690
|
+
return true;
|
|
2645
2691
|
}
|
|
2646
2692
|
/**
|
|
2647
2693
|
* Checks whether a key-plan step names the key at its index in the list bound as `this`.
|
|
2648
2694
|
*
|
|
2649
2695
|
* @remarks
|
|
2650
|
-
*
|
|
2696
|
+
* Answers one step of the comparison {@link matchesKeyPlan} makes, for a caller that passes it with
|
|
2697
|
+
* the key list as the `thisArg` argument to an `every` walk over a key plan.
|
|
2651
2698
|
*
|
|
2652
2699
|
* @param step - The step to compare
|
|
2653
2700
|
* @param index - The step's position in its plan
|
|
@@ -2665,8 +2712,9 @@ function matchesStepKey(step, index) {
|
|
|
2665
2712
|
* Checks whether the member of the record bound as `this` passes a key-plan step's guard.
|
|
2666
2713
|
*
|
|
2667
2714
|
* @remarks
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
2715
|
+
* Answers one step of the walk a compiled closed-object guard makes over a kept key plan, for a
|
|
2716
|
+
* caller that passes it with the record as the `thisArg` argument to an `every` walk over the plan,
|
|
2717
|
+
* which reads each member once, in the plan's order, and stops at the first refusal.
|
|
2670
2718
|
*
|
|
2671
2719
|
* @param step - The step whose member to read and guard
|
|
2672
2720
|
* @returns True if the member under the step's key passes its guard; false otherwise
|
|
@@ -2822,16 +2870,13 @@ function resolveField(record, path) {
|
|
|
2822
2870
|
const outcome = attempt(() => {
|
|
2823
2871
|
if (!matchesRecordBrand(record)) return void 0;
|
|
2824
2872
|
if (isString(path)) return INTRINSICS.own(record, path) ? INTRINSICS.reflect.read(record, path) : void 0;
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
}
|
|
2833
|
-
return INTRINSICS.reflect.read(current, key);
|
|
2834
|
-
}, record]);
|
|
2873
|
+
let current = record;
|
|
2874
|
+
for (let index = 0; index < path.length; index++) {
|
|
2875
|
+
const key = path[index];
|
|
2876
|
+
if (key === void 0 || !isObject(current) || !INTRINSICS.own(current, key)) return void 0;
|
|
2877
|
+
current = INTRINSICS.reflect.read(current, key);
|
|
2878
|
+
}
|
|
2879
|
+
return current;
|
|
2835
2880
|
});
|
|
2836
2881
|
return isSuccess(outcome) ? outcome.value : void 0;
|
|
2837
2882
|
}
|
|
@@ -2936,7 +2981,9 @@ function matchesJSONDepth(value) {
|
|
|
2936
2981
|
const active = new INTRINSICS.weakSet();
|
|
2937
2982
|
const settled = new INTRINSICS.weakMap();
|
|
2938
2983
|
while (stack.length > 0) {
|
|
2939
|
-
const
|
|
2984
|
+
const top = stack.length - 1;
|
|
2985
|
+
const frame = stack[top];
|
|
2986
|
+
stack.length = top;
|
|
2940
2987
|
if (frame === void 0) return false;
|
|
2941
2988
|
if (frame.operation === "exit") {
|
|
2942
2989
|
omitVisited(active, frame.value);
|
|
@@ -3037,7 +3084,9 @@ function matchesJSONValue(entry, ancestors, budget) {
|
|
|
3037
3084
|
}];
|
|
3038
3085
|
const proved = new INTRINSICS.weakSet();
|
|
3039
3086
|
while (stack.length > 0) {
|
|
3040
|
-
const
|
|
3087
|
+
const top = stack.length - 1;
|
|
3088
|
+
const frame = stack[top];
|
|
3089
|
+
stack.length = top;
|
|
3041
3090
|
if (frame === void 0) return false;
|
|
3042
3091
|
if (frame.operation === "exit") {
|
|
3043
3092
|
omitVisited(ancestors, frame.value);
|
|
@@ -4177,8 +4226,8 @@ function buildPositions(names) {
|
|
|
4177
4226
|
* Derives the bit mask of names present in an indexed lookup.
|
|
4178
4227
|
*
|
|
4179
4228
|
* @remarks
|
|
4180
|
-
* Takes `names` as the array it declares
|
|
4181
|
-
*
|
|
4229
|
+
* Takes `names` as the array it declares, reads its length once, and reads each present
|
|
4230
|
+
* index once, in order, so a hole adds no bit and is never read. An array-like that is not an array
|
|
4182
4231
|
* is outside this contract.
|
|
4183
4232
|
*
|
|
4184
4233
|
* @param names - Names to observe in order
|
|
@@ -4191,11 +4240,15 @@ function buildPositions(names) {
|
|
|
4191
4240
|
* ```
|
|
4192
4241
|
*/
|
|
4193
4242
|
function readPresence(names, positions) {
|
|
4194
|
-
|
|
4195
|
-
|
|
4243
|
+
let mask = 0;
|
|
4244
|
+
for (let index = 0, count = names.length; index < count; index++) {
|
|
4245
|
+
if (!(index in names)) continue;
|
|
4246
|
+
const name = names[index];
|
|
4247
|
+
if (name === void 0 || !INTRINSICS.own(positions, name)) continue;
|
|
4196
4248
|
const position = positions[name];
|
|
4197
|
-
|
|
4198
|
-
}
|
|
4249
|
+
if (position !== void 0) mask |= 1 << position;
|
|
4250
|
+
}
|
|
4251
|
+
return mask;
|
|
4199
4252
|
}
|
|
4200
4253
|
for (const generator of [iterateIndices, encodeParts]) {
|
|
4201
4254
|
for (const key of [
|
|
@@ -5846,10 +5899,12 @@ var ContractError = class ContractError extends Error {
|
|
|
5846
5899
|
*/
|
|
5847
5900
|
constructor(message, options) {
|
|
5848
5901
|
super(message, INTRINSICS.own(options, "cause") ? { cause: options.cause } : void 0);
|
|
5849
|
-
|
|
5902
|
+
const brand = {
|
|
5903
|
+
__proto__: null,
|
|
5850
5904
|
value: this,
|
|
5851
5905
|
configurable: true
|
|
5852
|
-
}
|
|
5906
|
+
};
|
|
5907
|
+
INTRINSICS.define(this, CONTRACT_ERROR_BRAND, brand);
|
|
5853
5908
|
this.code = options.code;
|
|
5854
5909
|
this.context = INTRINSICS.own(options, "context") ? options.context : void 0;
|
|
5855
5910
|
}
|
|
@@ -5859,10 +5914,15 @@ var ContractError = class ContractError extends Error {
|
|
|
5859
5914
|
if (key === void 0) continue;
|
|
5860
5915
|
const declared = INTRINSICS.describe(this.prototype, key);
|
|
5861
5916
|
const accessor = declared !== void 0 && !INTRINSICS.own(declared, "value");
|
|
5862
|
-
|
|
5917
|
+
const pin = accessor ? {
|
|
5918
|
+
__proto__: null,
|
|
5919
|
+
configurable: false
|
|
5920
|
+
} : {
|
|
5921
|
+
__proto__: null,
|
|
5863
5922
|
writable: false,
|
|
5864
5923
|
configurable: false
|
|
5865
|
-
}
|
|
5924
|
+
};
|
|
5925
|
+
INTRINSICS.reflect.define(this.prototype, key, pin);
|
|
5866
5926
|
const pinned = INTRINSICS.describe(this.prototype, key);
|
|
5867
5927
|
if (pinned?.configurable !== false || !accessor && pinned.writable !== false) throw new ContractError("ContractError: a prototype member could not be pinned", { code: "structure" });
|
|
5868
5928
|
}
|
|
@@ -5953,14 +6013,14 @@ var JSONCloner = class JSONCloner {
|
|
|
5953
6013
|
#owned;
|
|
5954
6014
|
#active;
|
|
5955
6015
|
#pending;
|
|
5956
|
-
#
|
|
6016
|
+
#entered;
|
|
5957
6017
|
#terminal;
|
|
5958
6018
|
constructor(value) {
|
|
5959
6019
|
this.#source = value;
|
|
5960
6020
|
this.#owned = new JSONCloner.#weakSet();
|
|
5961
6021
|
this.#active = new JSONCloner.#weakSet();
|
|
5962
6022
|
this.#pending = [];
|
|
5963
|
-
this.#
|
|
6023
|
+
this.#entered = false;
|
|
5964
6024
|
this.#terminal = void 0;
|
|
5965
6025
|
}
|
|
5966
6026
|
/**
|
|
@@ -5976,12 +6036,12 @@ var JSONCloner = class JSONCloner {
|
|
|
5976
6036
|
if (isSuccess(terminal)) return terminal.value;
|
|
5977
6037
|
throw terminal.error;
|
|
5978
6038
|
}
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
this.#terminal = failure(
|
|
5982
|
-
throw
|
|
6039
|
+
if (this.#entered) {
|
|
6040
|
+
const reentry = this.#create("JSONCloner.clone: JSON cloning may not be reentered", { shape: "json" });
|
|
6041
|
+
this.#terminal = failure(reentry);
|
|
6042
|
+
throw reentry;
|
|
5983
6043
|
}
|
|
5984
|
-
this.#
|
|
6044
|
+
this.#entered = true;
|
|
5985
6045
|
const outcome = attempt(() => this.#execute(budget));
|
|
5986
6046
|
const interruption = this.#terminal;
|
|
5987
6047
|
if (interruption !== void 0) {
|
|
@@ -6016,7 +6076,7 @@ var JSONCloner = class JSONCloner {
|
|
|
6016
6076
|
if (entry === void 0) {
|
|
6017
6077
|
INTRINSICS.freeze(frame.clone);
|
|
6018
6078
|
omitVisited(this.#active, frame.source);
|
|
6019
|
-
this.#pending.
|
|
6079
|
+
this.#pending.length -= 1;
|
|
6020
6080
|
continue;
|
|
6021
6081
|
}
|
|
6022
6082
|
frame.index = index + 1;
|
|
@@ -6082,7 +6142,7 @@ var JSONCloner = class JSONCloner {
|
|
|
6082
6142
|
const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
|
|
6083
6143
|
if (isFailure(lengthOutcome)) this.#refusePath("array length could not be inspected", preview(source));
|
|
6084
6144
|
const lengthDescriptor = lengthOutcome.value;
|
|
6085
|
-
if (lengthDescriptor === void 0 || !INTRINSICS.own(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value >
|
|
6145
|
+
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));
|
|
6086
6146
|
const owned = collectMembers(keysOutcome.value);
|
|
6087
6147
|
if (!matchesMember(owned, "length")) this.#refusePath("array own keys are not exact", preview(source));
|
|
6088
6148
|
if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refusePath("array own keys are not exact", preview(source));
|
|
@@ -6215,7 +6275,14 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6215
6275
|
case "settled":
|
|
6216
6276
|
if (isSuccess(state.result)) return state.result.value;
|
|
6217
6277
|
throw state.result.error;
|
|
6218
|
-
case "running":
|
|
6278
|
+
case "running": {
|
|
6279
|
+
const poison = this.#create("SchemaCloner.clone: schema cloning may not be reentered");
|
|
6280
|
+
this.#state = {
|
|
6281
|
+
phase: "interrupted",
|
|
6282
|
+
poison
|
|
6283
|
+
};
|
|
6284
|
+
throw poison;
|
|
6285
|
+
}
|
|
6219
6286
|
case "interrupted":
|
|
6220
6287
|
this.#state = {
|
|
6221
6288
|
phase: "interrupted",
|
|
@@ -6223,11 +6290,7 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6223
6290
|
};
|
|
6224
6291
|
throw state.poison;
|
|
6225
6292
|
}
|
|
6226
|
-
|
|
6227
|
-
this.#state = {
|
|
6228
|
-
phase: "running",
|
|
6229
|
-
poison
|
|
6230
|
-
};
|
|
6293
|
+
this.#state = { phase: "running" };
|
|
6231
6294
|
return this.#complete(attempt(() => this.#execute()));
|
|
6232
6295
|
}
|
|
6233
6296
|
#complete(outcome) {
|
|
@@ -6254,7 +6317,9 @@ var SchemaCloner = class SchemaCloner {
|
|
|
6254
6317
|
}
|
|
6255
6318
|
#drain() {
|
|
6256
6319
|
while (this.#pending.length > 0) {
|
|
6257
|
-
const
|
|
6320
|
+
const top = this.#pending.length - 1;
|
|
6321
|
+
const frame = this.#pending[top];
|
|
6322
|
+
this.#pending.length = top;
|
|
6258
6323
|
if (frame === void 0) continue;
|
|
6259
6324
|
if (frame.depth > 512) this.#refuse("cloneSchema: schema exceeds the compilation depth limit", "depth", frame.path);
|
|
6260
6325
|
const keys = enumerableKeys(frame.source);
|
|
@@ -6548,7 +6613,9 @@ var ShapePass = class ShapePass {
|
|
|
6548
6613
|
this.#finish();
|
|
6549
6614
|
}
|
|
6550
6615
|
#visit() {
|
|
6551
|
-
const
|
|
6616
|
+
const top = this.#stack.length - 1;
|
|
6617
|
+
const frame = this.#stack[top];
|
|
6618
|
+
this.#stack.length = top;
|
|
6552
6619
|
if (frame === void 0) return;
|
|
6553
6620
|
if (frame.operation === "exit") {
|
|
6554
6621
|
const capture = this.#captures[frame.index];
|
|
@@ -6835,7 +6902,9 @@ var ShapePass = class ShapePass {
|
|
|
6835
6902
|
schema: source
|
|
6836
6903
|
}];
|
|
6837
6904
|
while (stack.length > 0) {
|
|
6838
|
-
const
|
|
6905
|
+
const top = stack.length - 1;
|
|
6906
|
+
const frame = stack[top];
|
|
6907
|
+
stack.length = top;
|
|
6839
6908
|
if (frame === void 0) continue;
|
|
6840
6909
|
if (frame.operation === "exit") {
|
|
6841
6910
|
omitVisited(active, frame.schema);
|
|
@@ -7531,21 +7600,25 @@ var ShapeCloner = class ShapeCloner {
|
|
|
7531
7600
|
if (isSuccess(state.result)) return state.result.value;
|
|
7532
7601
|
throw state.result.error;
|
|
7533
7602
|
}
|
|
7534
|
-
if (state.phase === "
|
|
7603
|
+
if (state.phase === "interrupted") {
|
|
7535
7604
|
this.#state = {
|
|
7536
7605
|
phase: "interrupted",
|
|
7537
7606
|
poison: state.poison
|
|
7538
7607
|
};
|
|
7539
7608
|
throw state.poison;
|
|
7540
7609
|
}
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7610
|
+
if (state.phase === "running") {
|
|
7611
|
+
const poison = this.#create("ShapeCloner.clone: shape cloning may not be reentered", {
|
|
7612
|
+
code: "clone",
|
|
7613
|
+
context: { shape: "shape" }
|
|
7614
|
+
});
|
|
7615
|
+
this.#state = {
|
|
7616
|
+
phase: "interrupted",
|
|
7617
|
+
poison
|
|
7618
|
+
};
|
|
7619
|
+
throw poison;
|
|
7620
|
+
}
|
|
7621
|
+
this.#state = { phase: "running" };
|
|
7549
7622
|
return this.#complete(attempt(() => this.#execute()));
|
|
7550
7623
|
}
|
|
7551
7624
|
#complete(outcome) {
|
|
@@ -8567,11 +8640,11 @@ function recordOf(shape, optional) {
|
|
|
8567
8640
|
return (value) => holds(() => {
|
|
8568
8641
|
if (!isRecord(value)) return false;
|
|
8569
8642
|
const members = INTRINSICS.reflect.members(value);
|
|
8570
|
-
for (
|
|
8643
|
+
for (let index = 0, count = members.length; index < count; index++) {
|
|
8571
8644
|
const key = members[index];
|
|
8572
8645
|
if (isString(key) && !matchesMember(declared.vocabulary, key)) return false;
|
|
8573
8646
|
}
|
|
8574
|
-
for (
|
|
8647
|
+
for (let index = 0; index < declared.names.length; index++) {
|
|
8575
8648
|
const key = declared.names[index];
|
|
8576
8649
|
if (key === void 0) continue;
|
|
8577
8650
|
const guard = declared.guards[key];
|
|
@@ -9139,7 +9212,14 @@ function parseJSONValue(value) {
|
|
|
9139
9212
|
function parseEnum(value, allowed) {
|
|
9140
9213
|
const outcome = readArrayEntries(allowed);
|
|
9141
9214
|
if (isFailure(outcome) || !outcome.value.dense) return void 0;
|
|
9142
|
-
|
|
9215
|
+
const entries = outcome.value.entries;
|
|
9216
|
+
if (!holds(() => {
|
|
9217
|
+
for (let index = 0, count = entries.length; index < count; index++) {
|
|
9218
|
+
const entry = entries[index];
|
|
9219
|
+
if (entry === value || INTRINSICS.same(entry, value)) return true;
|
|
9220
|
+
}
|
|
9221
|
+
return false;
|
|
9222
|
+
})) return void 0;
|
|
9143
9223
|
return isLiteralValue(value) ? value : void 0;
|
|
9144
9224
|
}
|
|
9145
9225
|
/**
|
|
@@ -9353,30 +9433,41 @@ function parseJSONAs(value, guard) {
|
|
|
9353
9433
|
var EvaluationScope = class EvaluationScope {
|
|
9354
9434
|
static #active = new INTRINSICS.set();
|
|
9355
9435
|
static #path = INTRINSICS.freeze([]);
|
|
9356
|
-
#answers
|
|
9357
|
-
/**
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9436
|
+
#answers;
|
|
9437
|
+
/**
|
|
9438
|
+
* Evaluates a node within the active call, disposing a newly opened scope on settlement.
|
|
9439
|
+
*
|
|
9440
|
+
* @remarks
|
|
9441
|
+
* The plan receives `built` as its third argument: true when this package built `path`.
|
|
9442
|
+
*/
|
|
9443
|
+
static run(plan, value, path = EvaluationScope.#path, clean = false, built = false) {
|
|
9444
|
+
if (!isObject(value) && !isFunction(value)) return plan(value, path, built);
|
|
9445
|
+
const active = EvaluationScope.#read();
|
|
9446
|
+
if (active instanceof EvaluationScope) return active.#evaluate(plan, value, path, clean, built);
|
|
9364
9447
|
if (active !== void 0) throw new INTRINSICS.error("Evaluation scope is unavailable");
|
|
9365
9448
|
const scope = new EvaluationScope();
|
|
9366
9449
|
INTRINSICS.reflect.apply(INTRINSICS.admit, EvaluationScope.#active, [scope]);
|
|
9367
9450
|
try {
|
|
9368
|
-
return plan(value, path);
|
|
9451
|
+
return plan(value, path, built);
|
|
9369
9452
|
} finally {
|
|
9370
9453
|
INTRINSICS.reflect.apply(INTRINSICS.remove, EvaluationScope.#active, [scope]);
|
|
9371
9454
|
}
|
|
9372
9455
|
}
|
|
9373
|
-
#
|
|
9374
|
-
const
|
|
9456
|
+
static #read() {
|
|
9457
|
+
const count = INTRINSICS.count;
|
|
9458
|
+
if (count !== void 0 && INTRINSICS.reflect.apply(count, EvaluationScope.#active, []) === 0) return;
|
|
9459
|
+
const cursor = INTRINSICS.reflect.apply(INTRINSICS.cursor, EvaluationScope.#active, []);
|
|
9460
|
+
const step = INTRINSICS.reflect.apply(INTRINSICS.step, cursor, []);
|
|
9461
|
+
return step.done === true ? void 0 : step.value;
|
|
9462
|
+
}
|
|
9463
|
+
#evaluate(plan, value, path, clean, built) {
|
|
9464
|
+
const answers = this.#answers ??= new INTRINSICS.weakMap();
|
|
9465
|
+
const cached = INTRINSICS.reflect.apply(INTRINSICS.recall, answers, [plan]);
|
|
9375
9466
|
const memo = cached ?? new INTRINSICS.weakMap();
|
|
9376
|
-
if (cached === void 0) INTRINSICS.reflect.apply(INTRINSICS.retain,
|
|
9467
|
+
if (cached === void 0) INTRINSICS.reflect.apply(INTRINSICS.retain, answers, [plan, memo]);
|
|
9377
9468
|
const recalled = INTRINSICS.reflect.apply(INTRINSICS.recall, memo, [value]);
|
|
9378
9469
|
if (recalled !== void 0) return recalled;
|
|
9379
|
-
const answer = plan(value, path);
|
|
9470
|
+
const answer = plan(value, path, built);
|
|
9380
9471
|
if (!clean || INTRINSICS.array(answer) && answer.length === 0) INTRINSICS.reflect.apply(INTRINSICS.retain, memo, [value, answer]);
|
|
9381
9472
|
return answer;
|
|
9382
9473
|
}
|
|
@@ -9519,7 +9610,7 @@ var ValueCloner = class ValueCloner {
|
|
|
9519
9610
|
copy,
|
|
9520
9611
|
array,
|
|
9521
9612
|
plan,
|
|
9522
|
-
path: key === void 0 ? path :
|
|
9613
|
+
path: key === void 0 ? path : buildChildPath(path, key)
|
|
9523
9614
|
};
|
|
9524
9615
|
return copy;
|
|
9525
9616
|
}
|
|
@@ -9592,7 +9683,7 @@ var RandomSource = class {
|
|
|
9592
9683
|
}
|
|
9593
9684
|
/** Advances the generator and returns its next unit-interval value. */
|
|
9594
9685
|
next() {
|
|
9595
|
-
this.#state = this.#state +
|
|
9686
|
+
this.#state = this.#state + 0x6d2b79f5 >>> 0;
|
|
9596
9687
|
const mixed = INTRINSICS.imul(this.#state ^ this.#state >>> 15, this.#state | 1);
|
|
9597
9688
|
const final = mixed ^ mixed + INTRINSICS.imul(mixed ^ mixed >>> 7, mixed | 61);
|
|
9598
9689
|
return ((final ^ final >>> 14) >>> 0) / 4294967296;
|
|
@@ -9829,24 +9920,28 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9829
9920
|
#enter(build) {
|
|
9830
9921
|
const state = this.#state;
|
|
9831
9922
|
if (state.phase === "failed") throw state.error;
|
|
9832
|
-
if (state.phase === "
|
|
9923
|
+
if (state.phase === "interrupted") {
|
|
9833
9924
|
this.#state = {
|
|
9834
9925
|
phase: "interrupted",
|
|
9835
9926
|
poison: state.poison
|
|
9836
9927
|
};
|
|
9837
9928
|
throw state.poison;
|
|
9838
9929
|
}
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9930
|
+
if (state.phase === "running") {
|
|
9931
|
+
const poison = new ContractError("ContractCompiler: contract compilation may not be reentered", {
|
|
9932
|
+
code: "structure",
|
|
9933
|
+
context: {
|
|
9934
|
+
path: [],
|
|
9935
|
+
shape: "contract"
|
|
9936
|
+
}
|
|
9937
|
+
});
|
|
9938
|
+
this.#state = {
|
|
9939
|
+
phase: "interrupted",
|
|
9940
|
+
poison
|
|
9941
|
+
};
|
|
9942
|
+
throw poison;
|
|
9943
|
+
}
|
|
9944
|
+
this.#state = { phase: "running" };
|
|
9850
9945
|
return this.#leave(attempt(build));
|
|
9851
9946
|
}
|
|
9852
9947
|
#leave(outcome) {
|
|
@@ -10123,7 +10218,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10123
10218
|
return (value) => EvaluationScope.run(plan, value);
|
|
10124
10219
|
}
|
|
10125
10220
|
#trackFaults(plan) {
|
|
10126
|
-
return (value, path) => EvaluationScope.run(plan, value, path, true);
|
|
10221
|
+
return (value, path, built) => EvaluationScope.run(plan, value, path, true, built);
|
|
10127
10222
|
}
|
|
10128
10223
|
#discriminate(owned) {
|
|
10129
10224
|
const arms = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(owned.variants), [(variant) => variant?.category === "object"]);
|
|
@@ -10140,7 +10235,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10140
10235
|
}),
|
|
10141
10236
|
select: (value) => {
|
|
10142
10237
|
if (!isObject(value)) return void 0;
|
|
10143
|
-
for (
|
|
10238
|
+
for (let index = 0, count = tables.length; index < count; index++) {
|
|
10144
10239
|
const table = tables[index];
|
|
10145
10240
|
if (table === void 0) continue;
|
|
10146
10241
|
const held = attempt(() => INTRINSICS.describe(value, table.key));
|
|
@@ -10398,7 +10493,9 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10398
10493
|
if (!INTRINSICS.array(value)) return false;
|
|
10399
10494
|
const read = collectArrayEntries(value);
|
|
10400
10495
|
if (!read.dense || !read.exact) return false;
|
|
10401
|
-
|
|
10496
|
+
const entries = read.entries;
|
|
10497
|
+
for (let position = 0, count = entries.length; position < count; position++) if (!element(entries[position])) return false;
|
|
10498
|
+
return withinLength === void 0 || withinLength(entries.length);
|
|
10402
10499
|
});
|
|
10403
10500
|
}
|
|
10404
10501
|
case "object": {
|
|
@@ -10429,7 +10526,13 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10429
10526
|
const keys = INTRINSICS.keys(value);
|
|
10430
10527
|
if (extra !== true && !matchesEnumerableKeys(value, keys)) return false;
|
|
10431
10528
|
const plan = plans?.recall(keys);
|
|
10432
|
-
if (plan !== void 0)
|
|
10529
|
+
if (plan !== void 0) {
|
|
10530
|
+
for (let position = 0, count = plan.length; position < count; position++) {
|
|
10531
|
+
const step = plan[position];
|
|
10532
|
+
if (step !== void 0 && !step.guard(value[step.key])) return false;
|
|
10533
|
+
}
|
|
10534
|
+
return true;
|
|
10535
|
+
}
|
|
10433
10536
|
if (maskable) {
|
|
10434
10537
|
if (readPresence(keys, positions) !== full) return false;
|
|
10435
10538
|
} else {
|
|
@@ -10469,7 +10572,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10469
10572
|
case "nullable": return nullableOf(this.#guardAt(owned.inner));
|
|
10470
10573
|
case "interface": {
|
|
10471
10574
|
const audit = this.#auditAt(owned);
|
|
10472
|
-
return (value) => holds(() => audit(value, ContractCompiler.#root).length === 0);
|
|
10575
|
+
return (value) => holds(() => audit(value, ContractCompiler.#root, true).length === 0);
|
|
10473
10576
|
}
|
|
10474
10577
|
case "raw": return (value) => value !== void 0;
|
|
10475
10578
|
}
|
|
@@ -10639,7 +10742,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10639
10742
|
selected[selected.length] = [key, parsed];
|
|
10640
10743
|
return false;
|
|
10641
10744
|
}])) return void 0;
|
|
10642
|
-
|
|
10745
|
+
const result = { __proto__: null };
|
|
10746
|
+
for (let step = 0; step < selected.length; step++) {
|
|
10747
|
+
const pair = selected[step];
|
|
10748
|
+
if (pair !== void 0) result[pair[0]] = pair[1];
|
|
10749
|
+
}
|
|
10750
|
+
return result;
|
|
10643
10751
|
});
|
|
10644
10752
|
if (isSuccess(outcome)) return outcome.value;
|
|
10645
10753
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
@@ -10669,12 +10777,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10669
10777
|
const selected = discriminated?.select(value);
|
|
10670
10778
|
const arm = selected === void 0 ? void 0 : variants[selected];
|
|
10671
10779
|
if (arm !== void 0) return ContractCompiler.#parseArm(arm, value);
|
|
10672
|
-
for (
|
|
10780
|
+
for (let variantIndex = 0, count = variants.length; variantIndex < count; variantIndex++) {
|
|
10673
10781
|
const variant = variants[variantIndex];
|
|
10674
10782
|
if (variant === void 0) continue;
|
|
10675
10783
|
if (variant.guard(value)) return value;
|
|
10676
10784
|
}
|
|
10677
|
-
for (
|
|
10785
|
+
for (let variantIndex = 0, count = variants.length; variantIndex < count; variantIndex++) {
|
|
10678
10786
|
const variant = variants[variantIndex];
|
|
10679
10787
|
if (variant === void 0) continue;
|
|
10680
10788
|
const parsed = variant.parse(value);
|
|
@@ -10693,7 +10801,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10693
10801
|
case "interface": {
|
|
10694
10802
|
const audit = this.#auditAt(owned);
|
|
10695
10803
|
return (value) => {
|
|
10696
|
-
const outcome = attempt(() => audit(value, ContractCompiler.#root));
|
|
10804
|
+
const outcome = attempt(() => audit(value, ContractCompiler.#root, true));
|
|
10697
10805
|
if (isSuccess(outcome)) return outcome.value.length === 0 ? value : void 0;
|
|
10698
10806
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
10699
10807
|
return readValue(() => {
|
|
@@ -10742,7 +10850,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10742
10850
|
}]);
|
|
10743
10851
|
}
|
|
10744
10852
|
#exposeAudit(plan) {
|
|
10745
|
-
return (value, path
|
|
10853
|
+
return (value, path) => contain(() => path === void 0 ? plan(value, [], true) : plan(value, path, false), "compileAuditor");
|
|
10746
10854
|
}
|
|
10747
10855
|
#auditAt(shape) {
|
|
10748
10856
|
const compiled = this.#audits[this.#locate(shape)];
|
|
@@ -10838,7 +10946,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10838
10946
|
const item = this.#auditAt(owned.items);
|
|
10839
10947
|
const admitted = this.#admits(owned.items);
|
|
10840
10948
|
const kind = shapeToKind(owned.items);
|
|
10841
|
-
return (value, path) => {
|
|
10949
|
+
return (value, path, built) => {
|
|
10842
10950
|
if (isObject(value)) readValue(() => INTRINSICS.array(value), "compileAuditor", {
|
|
10843
10951
|
subject: "array",
|
|
10844
10952
|
context: {
|
|
@@ -10869,12 +10977,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10869
10977
|
if (admitted && !entries.value.dense && !INTRINSICS.own(entries.value.entries, at)) {
|
|
10870
10978
|
faults[faults.length] = {
|
|
10871
10979
|
reason: "missing",
|
|
10872
|
-
path: pathOf(path, at),
|
|
10980
|
+
path: built ? buildChildPath(path, at) : pathOf(path, at),
|
|
10873
10981
|
expected: kind
|
|
10874
10982
|
};
|
|
10875
10983
|
continue;
|
|
10876
10984
|
}
|
|
10877
|
-
appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, at)));
|
|
10985
|
+
appendEntries(faults, item(entries.value.entries[entryIndex], built ? buildChildPath(path, at) : pathOf(path, at), true));
|
|
10878
10986
|
}
|
|
10879
10987
|
appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
|
|
10880
10988
|
if (entries.value.exact) return limitEntries(faults, 64);
|
|
@@ -10892,7 +11000,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10892
11000
|
if (isString(member)) {
|
|
10893
11001
|
if (!INTRINSICS.own(snapshot, member)) faults[faults.length] = {
|
|
10894
11002
|
reason: "extra",
|
|
10895
|
-
path: pathOf(path, member)
|
|
11003
|
+
path: built ? buildChildPath(path, member) : pathOf(path, member)
|
|
10896
11004
|
};
|
|
10897
11005
|
} else if (member !== void 0) faults[faults.length] = {
|
|
10898
11006
|
reason: "extra",
|
|
@@ -10924,7 +11032,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10924
11032
|
const declared = isSuccess(planned) ? planned.value : void 0;
|
|
10925
11033
|
const maskable = entries.length <= 31;
|
|
10926
11034
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
10927
|
-
return (value, path) => {
|
|
11035
|
+
return (value, path, built) => {
|
|
10928
11036
|
if (isObject(value)) readValue(() => INTRINSICS.reflect.prototype(value), "compileAuditor", {
|
|
10929
11037
|
subject: "object",
|
|
10930
11038
|
context: {
|
|
@@ -10961,16 +11069,16 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10961
11069
|
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
10962
11070
|
if (matchesMember(concealed, entry.key)) faults[faults.length] = {
|
|
10963
11071
|
reason: "hidden",
|
|
10964
|
-
path: pathOf(path, entry.key)
|
|
11072
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key)
|
|
10965
11073
|
};
|
|
10966
11074
|
else if (!entry.optional) faults[faults.length] = {
|
|
10967
11075
|
reason: "missing",
|
|
10968
|
-
path: pathOf(path, entry.key),
|
|
11076
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
10969
11077
|
expected: entry.kind
|
|
10970
11078
|
};
|
|
10971
11079
|
continue;
|
|
10972
11080
|
}
|
|
10973
|
-
appendEntries(faults, entry.audit(record[entry.key], pathOf(path, entry.key)));
|
|
11081
|
+
appendEntries(faults, entry.audit(record[entry.key], built ? buildChildPath(path, entry.key) : pathOf(path, entry.key), true));
|
|
10974
11082
|
}
|
|
10975
11083
|
for (const keyIndex of iterateIndices(() => keys.length)) {
|
|
10976
11084
|
const key = keys[keyIndex];
|
|
@@ -10980,12 +11088,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10980
11088
|
if (closed) {
|
|
10981
11089
|
faults[faults.length] = {
|
|
10982
11090
|
reason: "extra",
|
|
10983
|
-
path: pathOf(path, key)
|
|
11091
|
+
path: built ? buildChildPath(path, key) : pathOf(path, key)
|
|
10984
11092
|
};
|
|
10985
11093
|
continue;
|
|
10986
11094
|
}
|
|
10987
11095
|
const observed = record[key];
|
|
10988
|
-
if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
|
|
11096
|
+
if (additional !== void 0) appendEntries(faults, additional(observed, built ? buildChildPath(path, key) : pathOf(path, key), true));
|
|
10989
11097
|
}
|
|
10990
11098
|
for (const nameIndex of iterateIndices(() => outside.length)) {
|
|
10991
11099
|
const name = outside[nameIndex];
|
|
@@ -10993,7 +11101,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10993
11101
|
if (faults.length >= 64) return;
|
|
10994
11102
|
faults[faults.length] = {
|
|
10995
11103
|
reason: closed ? "extra" : "hidden",
|
|
10996
|
-
path: pathOf(path, name)
|
|
11104
|
+
path: built ? buildChildPath(path, name) : pathOf(path, name)
|
|
10997
11105
|
};
|
|
10998
11106
|
}
|
|
10999
11107
|
const symbols = extra === true ? [] : INTRINSICS.symbols(record);
|
|
@@ -11026,15 +11134,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11026
11134
|
const exclusive = owned.mode === "oneOf";
|
|
11027
11135
|
const count = owned.variants.length;
|
|
11028
11136
|
const discriminated = this.#discriminate(owned);
|
|
11029
|
-
return (value, path) => {
|
|
11137
|
+
return (value, path, built) => {
|
|
11030
11138
|
const selected = discriminated?.select(value);
|
|
11031
11139
|
const arm = selected === void 0 ? void 0 : plans[selected];
|
|
11032
|
-
if (arm !== void 0) return arm(value, path);
|
|
11140
|
+
if (arm !== void 0) return arm(value, path, built);
|
|
11033
11141
|
const perVariant = [];
|
|
11034
11142
|
for (const index2 of iterateIndices(() => plans.length)) {
|
|
11035
11143
|
const plan = plans[index2];
|
|
11036
11144
|
if (plan === void 0) continue;
|
|
11037
|
-
const variantFaults = plan(value, path);
|
|
11145
|
+
const variantFaults = plan(value, path, built);
|
|
11038
11146
|
if (variantFaults.length === 0) {
|
|
11039
11147
|
if (!exclusive) return [];
|
|
11040
11148
|
}
|
|
@@ -11068,15 +11176,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11068
11176
|
}
|
|
11069
11177
|
case "optional": {
|
|
11070
11178
|
const inner = this.#auditAt(owned.inner);
|
|
11071
|
-
return (value, path) => value === void 0 ? [] : inner(value, path);
|
|
11179
|
+
return (value, path, built) => value === void 0 ? [] : inner(value, path, built);
|
|
11072
11180
|
}
|
|
11073
11181
|
case "nullable": {
|
|
11074
11182
|
const inner = this.#auditAt(owned.inner);
|
|
11075
|
-
return (value, path) => value === null ? [] : inner(value, path);
|
|
11183
|
+
return (value, path, built) => value === null ? [] : inner(value, path, built);
|
|
11076
11184
|
}
|
|
11077
11185
|
case "interface": {
|
|
11078
11186
|
const entries = this.#membersOf(owned);
|
|
11079
|
-
return (value, path) => {
|
|
11187
|
+
return (value, path, built) => {
|
|
11080
11188
|
if (isObject(value)) readValue(() => INTRINSICS.array(value), "compileAuditor", {
|
|
11081
11189
|
subject: "interface",
|
|
11082
11190
|
context: {
|
|
@@ -11095,7 +11203,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11095
11203
|
const entry = entries[entryIndex];
|
|
11096
11204
|
if (entry === void 0) continue;
|
|
11097
11205
|
if (faults.length >= 64) break;
|
|
11098
|
-
const at = pathOf(path, entry.key);
|
|
11206
|
+
const at = built ? buildChildPath(path, entry.key) : pathOf(path, entry.key);
|
|
11099
11207
|
const member = readValue(() => INTRINSICS.reflect.read(value, entry.key), "compileAuditor", {
|
|
11100
11208
|
subject: "interface member",
|
|
11101
11209
|
context: {
|
|
@@ -11111,7 +11219,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11111
11219
|
};
|
|
11112
11220
|
continue;
|
|
11113
11221
|
}
|
|
11114
|
-
appendEntries(faults, entry.audit(member, at));
|
|
11222
|
+
appendEntries(faults, entry.audit(member, at, true));
|
|
11115
11223
|
}
|
|
11116
11224
|
return limitEntries(faults, 64);
|
|
11117
11225
|
};
|
|
@@ -11141,7 +11249,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11141
11249
|
return root;
|
|
11142
11250
|
}
|
|
11143
11251
|
#exposeReport(plan) {
|
|
11144
|
-
return (value, path
|
|
11252
|
+
return (value, path) => contain(() => path === void 0 ? plan(value, [], true) : plan(value, path, false), "compileReporter");
|
|
11145
11253
|
}
|
|
11146
11254
|
#reportAt(shape) {
|
|
11147
11255
|
const compiled = this.#reports[this.#locate(shape)];
|
|
@@ -11239,7 +11347,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11239
11347
|
const item = this.#reportAt(owned.items);
|
|
11240
11348
|
const admitted = this.#admits(owned.items);
|
|
11241
11349
|
const kind = shapeToKind(owned.items);
|
|
11242
|
-
return (value, path) => {
|
|
11350
|
+
return (value, path, built) => {
|
|
11243
11351
|
if (!isArray(value)) return [{
|
|
11244
11352
|
reason: "type",
|
|
11245
11353
|
path,
|
|
@@ -11260,12 +11368,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11260
11368
|
if (admitted && !entries.value.dense && !INTRINSICS.own(entries.value.entries, at)) {
|
|
11261
11369
|
faults[faults.length] = {
|
|
11262
11370
|
reason: "missing",
|
|
11263
|
-
path: pathOf(path, at),
|
|
11371
|
+
path: built ? buildChildPath(path, at) : pathOf(path, at),
|
|
11264
11372
|
expected: kind
|
|
11265
11373
|
};
|
|
11266
11374
|
continue;
|
|
11267
11375
|
}
|
|
11268
|
-
appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, at)));
|
|
11376
|
+
appendEntries(faults, item(entries.value.entries[entryIndex], built ? buildChildPath(path, at) : pathOf(path, at), true));
|
|
11269
11377
|
}
|
|
11270
11378
|
appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
|
|
11271
11379
|
return limitEntries(faults, 64);
|
|
@@ -11294,7 +11402,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11294
11402
|
const known = isSuccess(planned) ? planned.value : void 0;
|
|
11295
11403
|
const maskable = entries.length <= 31;
|
|
11296
11404
|
const positions = buildPositions(maskable ? INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(entries), [(entry) => entry.key]) : []);
|
|
11297
|
-
return (value, path) => {
|
|
11405
|
+
return (value, path, built) => {
|
|
11298
11406
|
if (!isRecord(value)) return [{
|
|
11299
11407
|
reason: "type",
|
|
11300
11408
|
path,
|
|
@@ -11321,7 +11429,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11321
11429
|
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
11322
11430
|
if (!entry.optional) faults[faults.length] = {
|
|
11323
11431
|
reason: "missing",
|
|
11324
|
-
path: pathOf(path, entry.key),
|
|
11432
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
11325
11433
|
expected: entry.kind
|
|
11326
11434
|
};
|
|
11327
11435
|
continue;
|
|
@@ -11330,12 +11438,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11330
11438
|
if (raw === void 0 && !entry.admits) {
|
|
11331
11439
|
if (!entry.optional) faults[faults.length] = {
|
|
11332
11440
|
reason: "missing",
|
|
11333
|
-
path: pathOf(path, entry.key),
|
|
11441
|
+
path: built ? buildChildPath(path, entry.key) : pathOf(path, entry.key),
|
|
11334
11442
|
expected: entry.kind
|
|
11335
11443
|
};
|
|
11336
11444
|
continue;
|
|
11337
11445
|
}
|
|
11338
|
-
appendEntries(faults, entry.report(raw, pathOf(path, entry.key)));
|
|
11446
|
+
appendEntries(faults, entry.report(raw, built ? buildChildPath(path, entry.key) : pathOf(path, entry.key), true));
|
|
11339
11447
|
}
|
|
11340
11448
|
if (open) for (const keyIndex of iterateIndices(() => keys.length)) {
|
|
11341
11449
|
const key = keys[keyIndex];
|
|
@@ -11343,7 +11451,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11343
11451
|
if (faults.length >= 64) return;
|
|
11344
11452
|
if (matchesMember(vocabulary, key)) continue;
|
|
11345
11453
|
const observed = record[key];
|
|
11346
|
-
if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
|
|
11454
|
+
if (tail !== void 0) appendEntries(faults, tail(observed, built ? buildChildPath(path, key) : pathOf(path, key), true));
|
|
11347
11455
|
}
|
|
11348
11456
|
}))) return [{
|
|
11349
11457
|
reason: "type",
|
|
@@ -11364,15 +11472,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11364
11472
|
const exclusive = owned.mode === "oneOf";
|
|
11365
11473
|
const count = owned.variants.length;
|
|
11366
11474
|
const discriminated = this.#discriminate(owned);
|
|
11367
|
-
return (value, path) => {
|
|
11475
|
+
return (value, path, built) => {
|
|
11368
11476
|
const selected = discriminated?.select(value);
|
|
11369
11477
|
const arm = selected === void 0 ? void 0 : plans[selected];
|
|
11370
|
-
if (arm !== void 0) return arm(value, path);
|
|
11478
|
+
if (arm !== void 0) return arm(value, path, built);
|
|
11371
11479
|
const perVariant = [];
|
|
11372
11480
|
for (const index2 of iterateIndices(() => plans.length)) {
|
|
11373
11481
|
const plan = plans[index2];
|
|
11374
11482
|
if (plan === void 0) continue;
|
|
11375
|
-
const variantFaults = plan(value, path);
|
|
11483
|
+
const variantFaults = plan(value, path, built);
|
|
11376
11484
|
if (!exclusive && variantFaults.length === 0) return [];
|
|
11377
11485
|
perVariant[perVariant.length] = variantFaults;
|
|
11378
11486
|
}
|
|
@@ -11409,15 +11517,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11409
11517
|
}
|
|
11410
11518
|
case "optional": {
|
|
11411
11519
|
const inner = this.#reportAt(owned.inner);
|
|
11412
|
-
return (value, path) => value === void 0 ? [] : inner(value, path);
|
|
11520
|
+
return (value, path, built) => value === void 0 ? [] : inner(value, path, built);
|
|
11413
11521
|
}
|
|
11414
11522
|
case "nullable": {
|
|
11415
11523
|
const inner = this.#reportAt(owned.inner);
|
|
11416
|
-
return (value, path) => value === null ? [] : inner(value, path);
|
|
11524
|
+
return (value, path, built) => value === null ? [] : inner(value, path, built);
|
|
11417
11525
|
}
|
|
11418
11526
|
case "interface": {
|
|
11419
11527
|
const entries = this.#membersOf(owned);
|
|
11420
|
-
return (value, path) => {
|
|
11528
|
+
return (value, path, built) => {
|
|
11421
11529
|
if (!isObject(value) && !isFunction(value) || isArray(value)) return [{
|
|
11422
11530
|
reason: "type",
|
|
11423
11531
|
path,
|
|
@@ -11430,7 +11538,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11430
11538
|
const entry = entries[entryIndex];
|
|
11431
11539
|
if (entry === void 0) continue;
|
|
11432
11540
|
if (faults.length >= 64) return;
|
|
11433
|
-
const at = pathOf(path, entry.key);
|
|
11541
|
+
const at = built ? buildChildPath(path, entry.key) : pathOf(path, entry.key);
|
|
11434
11542
|
const member = INTRINSICS.reflect.read(value, entry.key);
|
|
11435
11543
|
if (member === void 0 && !entry.admits) {
|
|
11436
11544
|
if (!entry.optional) faults[faults.length] = {
|
|
@@ -11440,7 +11548,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
11440
11548
|
};
|
|
11441
11549
|
continue;
|
|
11442
11550
|
}
|
|
11443
|
-
const found = entry.audit(member, at);
|
|
11551
|
+
const found = entry.audit(member, at, true);
|
|
11444
11552
|
const kept = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(found), [(fault) => fault.reason !== "extra" && fault.reason !== "hidden"]);
|
|
11445
11553
|
if (kept.length < found.length) faults[faults.length] = {
|
|
11446
11554
|
reason: "type",
|
|
@@ -11947,7 +12055,7 @@ function compileGenerator(shape, random) {
|
|
|
11947
12055
|
* compileReporter(user, { name: 'Ada' }) // []
|
|
11948
12056
|
* ```
|
|
11949
12057
|
*/
|
|
11950
|
-
function compileReporter(shape, value, path
|
|
12058
|
+
function compileReporter(shape, value, path) {
|
|
11951
12059
|
return contain(() => new ContractCompiler(shape).reporter(value, path), "compileReporter");
|
|
11952
12060
|
}
|
|
11953
12061
|
/**
|
|
@@ -11985,7 +12093,7 @@ function compileReporter(shape, value, path = []) {
|
|
|
11985
12093
|
* // [{ reason: 'extra', path: ['extra'] }]
|
|
11986
12094
|
* ```
|
|
11987
12095
|
*/
|
|
11988
|
-
function compileAuditor(shape, value, path
|
|
12096
|
+
function compileAuditor(shape, value, path) {
|
|
11989
12097
|
return contain(() => new ContractCompiler(shape).auditor(value, path), "compileAuditor");
|
|
11990
12098
|
}
|
|
11991
12099
|
// src/core/LazyContract.ts
|
|
@@ -12050,10 +12158,10 @@ var LazyContract = class {
|
|
|
12050
12158
|
};
|
|
12051
12159
|
}
|
|
12052
12160
|
#audit() {
|
|
12053
|
-
return (value, path
|
|
12161
|
+
return (value, path) => (this.#settled ?? this.#settle("compileAuditor")).auditor(value, path);
|
|
12054
12162
|
}
|
|
12055
12163
|
#explain() {
|
|
12056
|
-
return (value, path
|
|
12164
|
+
return (value, path) => (this.#settled ?? this.#settle("compileReporter")).reporter(value, path);
|
|
12057
12165
|
}
|
|
12058
12166
|
#generate() {
|
|
12059
12167
|
return (random) => (this.#settled ?? this.#settle("compileGenerator")).generator(random);
|
|
@@ -14263,6 +14371,6 @@ function schemaToShape(schema, options) {
|
|
|
14263
14371
|
});
|
|
14264
14372
|
}, "schemaToShape");
|
|
14265
14373
|
}
|
|
14266
|
-
export { CHOICE_LIMIT, CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, DATE_LENGTH, FAULT_CONSTRAINTS, FAULT_KINDS, FAULT_LIMIT, FAULT_LIST_LIMIT, FAULT_SCHEMA_LIMIT, FAULT_TEXT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, KEY_PLAN_LIMIT, NAME_LIMIT, NODE_LIMIT, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SCHEMA_ANNOTATIONS, SHAPE_FIELDS, STRICT_SCHEMA_KEYWORDS, STRING_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, TEXT_LIMIT, admitMember, admitValue, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, auditFaultShape, booleanShape, boundsOf, buildArrayFaults, buildKeyPlan, buildNumberFaults, buildPathKey, buildPositions, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectArrayEntries, collectEntries, collectMembers, comparePrimitives, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, computeMonthLength, computeSurrogatePairs, contain, createContract, dateShape, deriveLengthBounds, deriveRangeBounds, describeFaultLine, describeFaults, drawRandom, encodeLeaf, encodeParts, enumOf, enumerableKeys, enumerableSymbolCount, errorToMessage, escapeControls, escapeRegExp, extractForms, extractPath, extractSchema, failure, filterUncoveredFaults, functionShape, holds, inferPrimitiveEnum, instanceOf, integerShape, interfaceShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isAuditFault, isAuditFaults, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isCodedError, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFailure, isFalse, isFault, isFaultPath, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSafeInteger, isSet, isSharedArrayBuffer, isString, isSuccess, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterateIndices, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesCalendarDate, matchesEmptyRange, matchesEnumerableKeys, matchesExactKeys, matchesISOInstant, matchesJSONDepth, matchesJSONValue, matchesKeyPlan, matchesLosslessRepair, matchesMember, matchesPattern, matchesRecordBrand, matchesStepGuard, matchesStepKey, matchesStringLength, matchesUndefinedField, matchesUndefinedNode, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownPattern, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseEnumValues, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, previewParts, previewText, rawShape, readArrayEntries, readGuardShape, readIndexView, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readPresence, readSampleMemo, readSetEntries, readShapeMap, readValue, recordOf, recordShape, refusalToError, refuseExpansion, refuseOptionKeys, refuseValue, renderForm, renderList, renderPath, repairValue, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, settle, shapeShape, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, success, transformOf, truncateFaultText, tupleOf, undefinedShape, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
|
|
14374
|
+
export { CHOICE_LIMIT, CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_CODES, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, DATE_LENGTH, FAULT_CONSTRAINTS, FAULT_KINDS, FAULT_LIMIT, FAULT_LIST_LIMIT, FAULT_SCHEMA_LIMIT, FAULT_TEXT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, KEY_PLAN_LIMIT, NAME_LIMIT, NODE_LIMIT, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SCHEMA_ANNOTATIONS, SHAPE_FIELDS, STRICT_SCHEMA_KEYWORDS, STRING_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, TEXT_LIMIT, admitMember, admitValue, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, auditFaultShape, booleanShape, boundsOf, buildArrayFaults, buildChildPath, buildKeyPlan, buildNumberFaults, buildPathKey, buildPositions, buildSampleMemo, buildStringFaults, canonicalStringify, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectArrayEntries, collectEntries, collectMembers, comparePrimitives, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, computeMonthLength, computeSurrogatePairs, contain, createContract, dateShape, deriveLengthBounds, deriveRangeBounds, describeFaultLine, describeFaults, drawRandom, encodeLeaf, encodeParts, enumOf, enumerableKeys, enumerableSymbolCount, errorToMessage, escapeControls, escapeRegExp, extractForms, extractPath, extractSchema, failure, filterUncoveredFaults, functionShape, holds, inferPrimitiveEnum, instanceOf, integerShape, interfaceShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isAuditFault, isAuditFaults, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isCodedError, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFailure, isFalse, isFault, isFaultPath, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSafeInteger, isSet, isSharedArrayBuffer, isString, isSuccess, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterateIndices, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesCalendarDate, matchesEmptyRange, matchesEnumerableKeys, matchesExactKeys, matchesISOInstant, matchesJSONDepth, matchesJSONValue, matchesKeyPlan, matchesLosslessRepair, matchesMember, matchesPattern, matchesRecordBrand, matchesStepGuard, matchesStepKey, matchesStringLength, matchesUndefinedField, matchesUndefinedNode, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownPattern, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseEnumValues, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, previewParts, previewText, rawShape, readArrayEntries, readGuardShape, readIndexView, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readPresence, readSampleMemo, readSetEntries, readShapeMap, readValue, recordOf, recordShape, refusalToError, refuseExpansion, refuseOptionKeys, refuseValue, renderForm, renderList, renderPath, repairValue, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, settle, shapeShape, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, success, transformOf, truncateFaultText, tupleOf, undefinedShape, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
|
|
14267
14375
|
|
|
14268
14376
|
//# sourceMappingURL=index.js.map
|