@orkestrel/contract 0.0.14 → 0.0.15
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 +179 -37
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +25 -0
- package/dist/src/core/index.d.ts +25 -0
- package/dist/src/core/index.js +179 -38
- package/dist/src/core/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -4774,6 +4774,31 @@ export declare function pickOf<S extends GuardsShape, K extends ReadonlyArray<ke
|
|
|
4774
4774
|
*/
|
|
4775
4775
|
export declare function pinMembers(prototype: object, owner: string): void;
|
|
4776
4776
|
|
|
4777
|
+
/**
|
|
4778
|
+
* The maximum number of object keys one compiled presence mask carries, frozen.
|
|
4779
|
+
*
|
|
4780
|
+
* @remarks
|
|
4781
|
+
* A compiled object plan decides which declared keys a value carries. The keys
|
|
4782
|
+
* it asks about are fixed when the plan is built, so the plan assigns each one a
|
|
4783
|
+
* bit position once and a call ORs one bit per own key it finds and compares the
|
|
4784
|
+
* result against the full mask — no per-call collection, and one integer compare
|
|
4785
|
+
* instead of one membership dispatch per declared key.
|
|
4786
|
+
*
|
|
4787
|
+
* The bound is the width a JavaScript bitwise operand has: `1 << position`
|
|
4788
|
+
* evaluates on a 32-bit signed integer, so positions run `0` through `30` and a
|
|
4789
|
+
* mask stays positive. A declaration with more keys than this is ordinary
|
|
4790
|
+
* authoring rather than an attack, so it is answered rather than refused:
|
|
4791
|
+
* {@link ContractCompiler} builds no position record for it and its compiled
|
|
4792
|
+
* guard, parser, auditor, and reporter decide presence from a collected key
|
|
4793
|
+
* vocabulary instead. Both branches answer identically; only the cost differs.
|
|
4794
|
+
*
|
|
4795
|
+
* @example
|
|
4796
|
+
* ```ts
|
|
4797
|
+
* PRESENCE_MASK_LIMIT // 31
|
|
4798
|
+
* ```
|
|
4799
|
+
*/
|
|
4800
|
+
export declare const PRESENCE_MASK_LIMIT = 31;
|
|
4801
|
+
|
|
4777
4802
|
/**
|
|
4778
4803
|
* Render a short, safe, TOTAL preview of an unknown value for a {@link Fault}'s
|
|
4779
4804
|
* `received` field.
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -4774,6 +4774,31 @@ export declare function pickOf<S extends GuardsShape, K extends ReadonlyArray<ke
|
|
|
4774
4774
|
*/
|
|
4775
4775
|
export declare function pinMembers(prototype: object, owner: string): void;
|
|
4776
4776
|
|
|
4777
|
+
/**
|
|
4778
|
+
* The maximum number of object keys one compiled presence mask carries, frozen.
|
|
4779
|
+
*
|
|
4780
|
+
* @remarks
|
|
4781
|
+
* A compiled object plan decides which declared keys a value carries. The keys
|
|
4782
|
+
* it asks about are fixed when the plan is built, so the plan assigns each one a
|
|
4783
|
+
* bit position once and a call ORs one bit per own key it finds and compares the
|
|
4784
|
+
* result against the full mask — no per-call collection, and one integer compare
|
|
4785
|
+
* instead of one membership dispatch per declared key.
|
|
4786
|
+
*
|
|
4787
|
+
* The bound is the width a JavaScript bitwise operand has: `1 << position`
|
|
4788
|
+
* evaluates on a 32-bit signed integer, so positions run `0` through `30` and a
|
|
4789
|
+
* mask stays positive. A declaration with more keys than this is ordinary
|
|
4790
|
+
* authoring rather than an attack, so it is answered rather than refused:
|
|
4791
|
+
* {@link ContractCompiler} builds no position record for it and its compiled
|
|
4792
|
+
* guard, parser, auditor, and reporter decide presence from a collected key
|
|
4793
|
+
* vocabulary instead. Both branches answer identically; only the cost differs.
|
|
4794
|
+
*
|
|
4795
|
+
* @example
|
|
4796
|
+
* ```ts
|
|
4797
|
+
* PRESENCE_MASK_LIMIT // 31
|
|
4798
|
+
* ```
|
|
4799
|
+
*/
|
|
4800
|
+
export declare const PRESENCE_MASK_LIMIT = 31;
|
|
4801
|
+
|
|
4777
4802
|
/**
|
|
4778
4803
|
* Render a short, safe, TOTAL preview of an unknown value for a {@link Fault}'s
|
|
4779
4804
|
* `received` field.
|
package/dist/src/core/index.js
CHANGED
|
@@ -332,6 +332,30 @@ var COMPILE_DEPTH_LIMIT = 512;
|
|
|
332
332
|
*/
|
|
333
333
|
var COMPILE_NODE_LIMIT = 16384;
|
|
334
334
|
/**
|
|
335
|
+
* The maximum number of object keys one compiled presence mask carries, frozen.
|
|
336
|
+
*
|
|
337
|
+
* @remarks
|
|
338
|
+
* A compiled object plan decides which declared keys a value carries. The keys
|
|
339
|
+
* it asks about are fixed when the plan is built, so the plan assigns each one a
|
|
340
|
+
* bit position once and a call ORs one bit per own key it finds and compares the
|
|
341
|
+
* result against the full mask — no per-call collection, and one integer compare
|
|
342
|
+
* instead of one membership dispatch per declared key.
|
|
343
|
+
*
|
|
344
|
+
* The bound is the width a JavaScript bitwise operand has: `1 << position`
|
|
345
|
+
* evaluates on a 32-bit signed integer, so positions run `0` through `30` and a
|
|
346
|
+
* mask stays positive. A declaration with more keys than this is ordinary
|
|
347
|
+
* authoring rather than an attack, so it is answered rather than refused:
|
|
348
|
+
* {@link ContractCompiler} builds no position record for it and its compiled
|
|
349
|
+
* guard, parser, auditor, and reporter decide presence from a collected key
|
|
350
|
+
* vocabulary instead. Both branches answer identically; only the cost differs.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```ts
|
|
354
|
+
* PRESENCE_MASK_LIMIT // 31
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
var PRESENCE_MASK_LIMIT = 31;
|
|
358
|
+
/**
|
|
335
359
|
* The maximum number of nodes one JSON snapshot may produce, frozen.
|
|
336
360
|
*
|
|
337
361
|
* @remarks
|
|
@@ -2396,6 +2420,9 @@ function readArrayEntries(value) {
|
|
|
2396
2420
|
const length = value.length;
|
|
2397
2421
|
if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
|
|
2398
2422
|
const collected = [];
|
|
2423
|
+
const keys = [];
|
|
2424
|
+
let ascending = true;
|
|
2425
|
+
let previous = -1;
|
|
2399
2426
|
const members = INTRINSICS.members(value);
|
|
2400
2427
|
for (let position = 0; position < members.length; position += 1) {
|
|
2401
2428
|
const key = members[position];
|
|
@@ -2403,16 +2430,19 @@ function readArrayEntries(value) {
|
|
|
2403
2430
|
const index = INTRINSICS.numeric(key);
|
|
2404
2431
|
if (INTRINSICS.integer(index) && index >= 0 && index < 2 ** 32 - 1 && INTRINSICS.text(index) === key) {
|
|
2405
2432
|
if (index >= length) throw new INTRINSICS.error("Array index views disagree");
|
|
2433
|
+
if (index <= previous) ascending = false;
|
|
2434
|
+
previous = index;
|
|
2406
2435
|
collected[collected.length] = index;
|
|
2436
|
+
keys[keys.length] = key;
|
|
2407
2437
|
}
|
|
2408
2438
|
}
|
|
2409
|
-
const indices = sortValues(collected);
|
|
2439
|
+
const indices = ascending ? collected : sortValues(collected);
|
|
2410
2440
|
const entries = new INTRINSICS.list(length);
|
|
2411
2441
|
for (let position = 0; position < indices.length; position += 1) {
|
|
2412
2442
|
const index = indices[position];
|
|
2413
2443
|
if (index === void 0) continue;
|
|
2414
|
-
const key = INTRINSICS.text(index);
|
|
2415
|
-
if (!INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
|
|
2444
|
+
const key = ascending ? keys[position] : INTRINSICS.text(index);
|
|
2445
|
+
if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
|
|
2416
2446
|
entries[index] = value[index];
|
|
2417
2447
|
}
|
|
2418
2448
|
return INTRINSICS.freeze({
|
|
@@ -6831,6 +6861,8 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6831
6861
|
#trackGuard(plan) {
|
|
6832
6862
|
let filled = 0;
|
|
6833
6863
|
let memo;
|
|
6864
|
+
let slot;
|
|
6865
|
+
let kept = false;
|
|
6834
6866
|
return (value) => {
|
|
6835
6867
|
if (!isObject(value)) return plan(value);
|
|
6836
6868
|
const opened = ContractCompiler.#scope === 0;
|
|
@@ -6840,14 +6872,28 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6840
6872
|
}
|
|
6841
6873
|
try {
|
|
6842
6874
|
const scope = ContractCompiler.#scope;
|
|
6843
|
-
if (
|
|
6844
|
-
memo =
|
|
6875
|
+
if (filled !== scope) {
|
|
6876
|
+
memo = void 0;
|
|
6877
|
+
slot = void 0;
|
|
6878
|
+
kept = false;
|
|
6845
6879
|
filled = scope;
|
|
6846
6880
|
}
|
|
6847
|
-
|
|
6848
|
-
if (
|
|
6881
|
+
if (slot === value) return kept;
|
|
6882
|
+
if (memo !== void 0) {
|
|
6883
|
+
const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
|
|
6884
|
+
if (recalled !== void 0) return recalled;
|
|
6885
|
+
}
|
|
6849
6886
|
const answer = plan(value);
|
|
6850
|
-
|
|
6887
|
+
if (slot === void 0) {
|
|
6888
|
+
slot = value;
|
|
6889
|
+
kept = answer;
|
|
6890
|
+
} else {
|
|
6891
|
+
if (memo === void 0) {
|
|
6892
|
+
memo = new ContractCompiler.#weakMap();
|
|
6893
|
+
INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
|
|
6894
|
+
}
|
|
6895
|
+
INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
|
|
6896
|
+
}
|
|
6851
6897
|
return answer;
|
|
6852
6898
|
} finally {
|
|
6853
6899
|
if (opened) ContractCompiler.#scope = 0;
|
|
@@ -6857,6 +6903,8 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6857
6903
|
#trackFaults(plan) {
|
|
6858
6904
|
let filled = 0;
|
|
6859
6905
|
let memo;
|
|
6906
|
+
let slot;
|
|
6907
|
+
let kept;
|
|
6860
6908
|
return (value, path) => {
|
|
6861
6909
|
if (!isObject(value)) return plan(value, path);
|
|
6862
6910
|
const opened = ContractCompiler.#scope === 0;
|
|
@@ -6866,14 +6914,28 @@ var ContractCompiler = class ContractCompiler {
|
|
|
6866
6914
|
}
|
|
6867
6915
|
try {
|
|
6868
6916
|
const scope = ContractCompiler.#scope;
|
|
6869
|
-
if (
|
|
6870
|
-
memo =
|
|
6917
|
+
if (filled !== scope) {
|
|
6918
|
+
memo = void 0;
|
|
6919
|
+
slot = void 0;
|
|
6920
|
+
kept = void 0;
|
|
6871
6921
|
filled = scope;
|
|
6872
6922
|
}
|
|
6873
|
-
|
|
6874
|
-
if (
|
|
6923
|
+
if (slot === value && kept !== void 0) return kept;
|
|
6924
|
+
if (memo !== void 0) {
|
|
6925
|
+
const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
|
|
6926
|
+
if (recalled !== void 0) return recalled;
|
|
6927
|
+
}
|
|
6875
6928
|
const answer = plan(value, path);
|
|
6876
|
-
if (
|
|
6929
|
+
if (slot === void 0) {
|
|
6930
|
+
slot = value;
|
|
6931
|
+
kept = answer.length === 0 ? answer : void 0;
|
|
6932
|
+
} else if (answer.length === 0) {
|
|
6933
|
+
if (memo === void 0) {
|
|
6934
|
+
memo = new ContractCompiler.#weakMap();
|
|
6935
|
+
if (kept !== void 0) INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
|
|
6936
|
+
}
|
|
6937
|
+
INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
|
|
6938
|
+
}
|
|
6877
6939
|
return answer;
|
|
6878
6940
|
} finally {
|
|
6879
6941
|
if (opened) ContractCompiler.#scope = 0;
|
|
@@ -7068,16 +7130,37 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7068
7130
|
for (let optionalIndex = 0; optionalIndex < optionalKeys.length; optionalIndex += 1) if (optionalKeys[optionalIndex] === key) optional = true;
|
|
7069
7131
|
if (!optional) required[required.length] = key;
|
|
7070
7132
|
}
|
|
7133
|
+
const maskable = required.length <= 31;
|
|
7134
|
+
const positions = INTRINSICS.create(null);
|
|
7135
|
+
let full = 0;
|
|
7136
|
+
if (maskable) for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
|
|
7137
|
+
const key = required[keyIndex];
|
|
7138
|
+
if (key === void 0) continue;
|
|
7139
|
+
positions[key] = keyIndex;
|
|
7140
|
+
full |= 1 << keyIndex;
|
|
7141
|
+
}
|
|
7071
7142
|
return (value) => {
|
|
7072
7143
|
if (!isRecord(value)) return false;
|
|
7073
7144
|
const keys = enumerableKeys(value);
|
|
7074
7145
|
if (keys === void 0) return false;
|
|
7075
7146
|
const outcome = attempt(() => {
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7147
|
+
if (maskable) {
|
|
7148
|
+
let seen = 0;
|
|
7149
|
+
for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
7150
|
+
const key = keys[keyIndex];
|
|
7151
|
+
if (key === void 0) continue;
|
|
7152
|
+
if (!INTRINSICS.own(positions, key)) continue;
|
|
7153
|
+
const position = positions[key];
|
|
7154
|
+
if (position !== void 0) seen |= 1 << position;
|
|
7155
|
+
}
|
|
7156
|
+
if (seen !== full) return false;
|
|
7157
|
+
} else {
|
|
7158
|
+
const present = collectMembers(keys);
|
|
7159
|
+
for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
|
|
7160
|
+
const key = required[keyIndex];
|
|
7161
|
+
if (key === void 0) continue;
|
|
7162
|
+
if (!matchesMember(present, key)) return false;
|
|
7163
|
+
}
|
|
7081
7164
|
}
|
|
7082
7165
|
for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
7083
7166
|
const key = keys[keyIndex];
|
|
@@ -7234,6 +7317,13 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7234
7317
|
subject: "object",
|
|
7235
7318
|
context: { shape: "object" }
|
|
7236
7319
|
});
|
|
7320
|
+
const maskable = entries.length <= 31;
|
|
7321
|
+
const positions = INTRINSICS.create(null);
|
|
7322
|
+
if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7323
|
+
const entry = entries[entryIndex];
|
|
7324
|
+
if (entry === void 0) continue;
|
|
7325
|
+
positions[entry.key] = entryIndex;
|
|
7326
|
+
}
|
|
7237
7327
|
const extra = owned.additionalProperties;
|
|
7238
7328
|
const additional = extra === void 0 || extra === false || extra === true ? void 0 : this.#parserAt(extra);
|
|
7239
7329
|
const open = extra === true || additional !== void 0;
|
|
@@ -7243,12 +7333,20 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7243
7333
|
const keys = enumerableKeys(record);
|
|
7244
7334
|
if (keys === void 0) return void 0;
|
|
7245
7335
|
const outcome = attempt(() => {
|
|
7246
|
-
const present = collectMembers(keys);
|
|
7336
|
+
const present = maskable ? void 0 : collectMembers(keys);
|
|
7337
|
+
let seen = 0;
|
|
7338
|
+
if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
7339
|
+
const key = keys[keyIndex];
|
|
7340
|
+
if (key === void 0) continue;
|
|
7341
|
+
if (!INTRINSICS.own(positions, key)) continue;
|
|
7342
|
+
const position = positions[key];
|
|
7343
|
+
if (position !== void 0) seen |= 1 << position;
|
|
7344
|
+
}
|
|
7247
7345
|
const result = INTRINSICS.create(null);
|
|
7248
7346
|
for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7249
7347
|
const entry = entries[entryIndex];
|
|
7250
7348
|
if (entry === void 0) continue;
|
|
7251
|
-
if (!matchesMember(present, entry.key)) {
|
|
7349
|
+
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
7252
7350
|
if (entry.optional) continue;
|
|
7253
7351
|
return;
|
|
7254
7352
|
}
|
|
@@ -7363,6 +7461,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7363
7461
|
switch (owned.type) {
|
|
7364
7462
|
case "string": {
|
|
7365
7463
|
const node = owned;
|
|
7464
|
+
const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
|
|
7366
7465
|
return (value, path) => {
|
|
7367
7466
|
if (!isString(value)) return [{
|
|
7368
7467
|
reason: "type",
|
|
@@ -7370,12 +7469,13 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7370
7469
|
expected: "string",
|
|
7371
7470
|
received: preview(value)
|
|
7372
7471
|
}];
|
|
7373
|
-
return createStringFaults(node, value, path);
|
|
7472
|
+
return refined ? createStringFaults(node, value, path) : [];
|
|
7374
7473
|
};
|
|
7375
7474
|
}
|
|
7376
7475
|
case "number": {
|
|
7377
7476
|
const node = owned;
|
|
7378
7477
|
const kind = owned.integer === true ? "integer" : "number";
|
|
7478
|
+
const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
|
|
7379
7479
|
return (value, path) => {
|
|
7380
7480
|
if (!isFiniteNumber(value)) return [{
|
|
7381
7481
|
reason: "type",
|
|
@@ -7383,7 +7483,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7383
7483
|
expected: kind,
|
|
7384
7484
|
received: preview(value)
|
|
7385
7485
|
}];
|
|
7386
|
-
return createNumberFaults(node, value, path);
|
|
7486
|
+
return refined ? createNumberFaults(node, value, path) : [];
|
|
7387
7487
|
};
|
|
7388
7488
|
}
|
|
7389
7489
|
case "boolean": return (value, path) => isBoolean(value) ? [] : [{
|
|
@@ -7469,6 +7569,15 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7469
7569
|
const extra = owned.additionalProperties;
|
|
7470
7570
|
const closed = extra === void 0 || extra === false;
|
|
7471
7571
|
const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
|
|
7572
|
+
const planned = attempt(() => collectMembers(declaredKeys));
|
|
7573
|
+
const declared = planned.success ? planned.value : void 0;
|
|
7574
|
+
const maskable = entries.length <= 31;
|
|
7575
|
+
const positions = INTRINSICS.create(null);
|
|
7576
|
+
if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7577
|
+
const entry = entries[entryIndex];
|
|
7578
|
+
if (entry === void 0) continue;
|
|
7579
|
+
positions[entry.key] = entryIndex;
|
|
7580
|
+
}
|
|
7472
7581
|
return (value, path) => {
|
|
7473
7582
|
if (isObject(value)) readValue(() => INTRINSICS.parent(value), "compileAuditor", {
|
|
7474
7583
|
subject: "object",
|
|
@@ -7493,13 +7602,21 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7493
7602
|
});
|
|
7494
7603
|
const faults = [];
|
|
7495
7604
|
const outcome = attempt(() => {
|
|
7496
|
-
const present = collectMembers(keys);
|
|
7497
|
-
const
|
|
7605
|
+
const present = maskable ? void 0 : collectMembers(keys);
|
|
7606
|
+
const vocabulary = declared ?? collectMembers(declaredKeys);
|
|
7607
|
+
let seen = 0;
|
|
7608
|
+
if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
7609
|
+
const key = keys[keyIndex];
|
|
7610
|
+
if (key === void 0) continue;
|
|
7611
|
+
if (!INTRINSICS.own(positions, key)) continue;
|
|
7612
|
+
const position = positions[key];
|
|
7613
|
+
if (position !== void 0) seen |= 1 << position;
|
|
7614
|
+
}
|
|
7498
7615
|
for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7499
7616
|
const entry = entries[entryIndex];
|
|
7500
7617
|
if (entry === void 0) continue;
|
|
7501
7618
|
if (faults.length >= 64) return;
|
|
7502
|
-
if (!matchesMember(present, entry.key)) {
|
|
7619
|
+
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
7503
7620
|
if (!entry.optional) faults[faults.length] = {
|
|
7504
7621
|
reason: "missing",
|
|
7505
7622
|
path: pathOf(path, entry.key),
|
|
@@ -7513,7 +7630,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7513
7630
|
const key = keys[keyIndex];
|
|
7514
7631
|
if (key === void 0) continue;
|
|
7515
7632
|
if (faults.length >= 64) return;
|
|
7516
|
-
if (matchesMember(
|
|
7633
|
+
if (matchesMember(vocabulary, key)) continue;
|
|
7517
7634
|
if (closed) {
|
|
7518
7635
|
faults[faults.length] = {
|
|
7519
7636
|
reason: "extra",
|
|
@@ -7556,8 +7673,11 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7556
7673
|
const plan = plans[index2];
|
|
7557
7674
|
if (plan === void 0) continue;
|
|
7558
7675
|
const variantFaults = plan(value, path);
|
|
7676
|
+
if (variantFaults.length === 0) {
|
|
7677
|
+
if (!exclusive) return [];
|
|
7678
|
+
matched += 1;
|
|
7679
|
+
}
|
|
7559
7680
|
perVariant[perVariant.length] = variantFaults;
|
|
7560
|
-
if (variantFaults.length === 0) matched += 1;
|
|
7561
7681
|
}
|
|
7562
7682
|
if (exclusive) {
|
|
7563
7683
|
if (matched === 1) return [];
|
|
@@ -7566,7 +7686,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7566
7686
|
path,
|
|
7567
7687
|
matched
|
|
7568
7688
|
}];
|
|
7569
|
-
}
|
|
7689
|
+
}
|
|
7570
7690
|
const closest = selectClosestFaults(perVariant);
|
|
7571
7691
|
const report = [exclusive ? {
|
|
7572
7692
|
reason: "oneOf",
|
|
@@ -7631,6 +7751,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7631
7751
|
switch (owned.type) {
|
|
7632
7752
|
case "string": {
|
|
7633
7753
|
const node = owned;
|
|
7754
|
+
const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
|
|
7634
7755
|
return (value, path) => {
|
|
7635
7756
|
const parsed = parseString(value);
|
|
7636
7757
|
if (parsed === void 0) return [{
|
|
@@ -7639,12 +7760,13 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7639
7760
|
expected: "string",
|
|
7640
7761
|
received: preview(value)
|
|
7641
7762
|
}];
|
|
7642
|
-
return createStringFaults(node, parsed, path);
|
|
7763
|
+
return refined ? createStringFaults(node, parsed, path) : [];
|
|
7643
7764
|
};
|
|
7644
7765
|
}
|
|
7645
7766
|
case "number": {
|
|
7646
7767
|
const node = owned;
|
|
7647
7768
|
const kind = owned.integer === true ? "integer" : "number";
|
|
7769
|
+
const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
|
|
7648
7770
|
return (value, path) => {
|
|
7649
7771
|
const parsed = parseNumber(value);
|
|
7650
7772
|
if (parsed === void 0) return [{
|
|
@@ -7653,7 +7775,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7653
7775
|
expected: kind,
|
|
7654
7776
|
received: preview(value)
|
|
7655
7777
|
}];
|
|
7656
|
-
return createNumberFaults(node, parsed, path);
|
|
7778
|
+
return refined ? createNumberFaults(node, parsed, path) : [];
|
|
7657
7779
|
};
|
|
7658
7780
|
}
|
|
7659
7781
|
case "boolean": return (value, path) => parseBoolean(value) === void 0 ? [{
|
|
@@ -7711,6 +7833,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7711
7833
|
}
|
|
7712
7834
|
case "object": {
|
|
7713
7835
|
const entries = [];
|
|
7836
|
+
const names = [];
|
|
7714
7837
|
const keyList = INTRINSICS.keys(owned.properties);
|
|
7715
7838
|
for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
|
|
7716
7839
|
const key = keyList[keyIndex];
|
|
@@ -7725,10 +7848,20 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7725
7848
|
optional,
|
|
7726
7849
|
kind: shapeToKind(inner)
|
|
7727
7850
|
};
|
|
7851
|
+
names[names.length] = key;
|
|
7728
7852
|
}
|
|
7729
7853
|
const extra = owned.additionalProperties;
|
|
7730
7854
|
const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
|
|
7731
7855
|
const open = extra === true || tail !== void 0;
|
|
7856
|
+
const planned = attempt(() => collectMembers(names));
|
|
7857
|
+
const known = planned.success ? planned.value : void 0;
|
|
7858
|
+
const maskable = entries.length <= 31;
|
|
7859
|
+
const positions = INTRINSICS.create(null);
|
|
7860
|
+
if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7861
|
+
const entry = entries[entryIndex];
|
|
7862
|
+
if (entry === void 0) continue;
|
|
7863
|
+
positions[entry.key] = entryIndex;
|
|
7864
|
+
}
|
|
7732
7865
|
return (value, path) => {
|
|
7733
7866
|
if (!isRecord(value)) return [{
|
|
7734
7867
|
reason: "type",
|
|
@@ -7746,14 +7879,21 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7746
7879
|
}];
|
|
7747
7880
|
const faults = [];
|
|
7748
7881
|
if (!attempt(() => {
|
|
7749
|
-
const present = collectMembers(keys);
|
|
7750
|
-
const
|
|
7882
|
+
const present = maskable ? void 0 : collectMembers(keys);
|
|
7883
|
+
const vocabulary = known ?? collectMembers(names);
|
|
7884
|
+
let seen = 0;
|
|
7885
|
+
if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
7886
|
+
const key = keys[keyIndex];
|
|
7887
|
+
if (key === void 0) continue;
|
|
7888
|
+
if (!INTRINSICS.own(positions, key)) continue;
|
|
7889
|
+
const position = positions[key];
|
|
7890
|
+
if (position !== void 0) seen |= 1 << position;
|
|
7891
|
+
}
|
|
7751
7892
|
for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
7752
7893
|
const entry = entries[entryIndex];
|
|
7753
7894
|
if (entry === void 0) continue;
|
|
7754
7895
|
if (faults.length >= 64) return;
|
|
7755
|
-
|
|
7756
|
-
if (!matchesMember(present, entry.key)) {
|
|
7896
|
+
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
7757
7897
|
if (!entry.optional) faults[faults.length] = {
|
|
7758
7898
|
reason: "missing",
|
|
7759
7899
|
path: pathOf(path, entry.key),
|
|
@@ -7776,7 +7916,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7776
7916
|
const key = keys[keyIndex];
|
|
7777
7917
|
if (key === void 0) continue;
|
|
7778
7918
|
if (faults.length >= 64) return;
|
|
7779
|
-
if (matchesMember(
|
|
7919
|
+
if (matchesMember(vocabulary, key)) continue;
|
|
7780
7920
|
const observed = record[key];
|
|
7781
7921
|
if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
|
|
7782
7922
|
}
|
|
@@ -7805,7 +7945,9 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7805
7945
|
for (let index2 = 0; index2 < plans.length; index2 += 1) {
|
|
7806
7946
|
const plan = plans[index2];
|
|
7807
7947
|
if (plan === void 0) continue;
|
|
7808
|
-
|
|
7948
|
+
const variantFaults = plan(value, path);
|
|
7949
|
+
if (!exclusive && variantFaults.length === 0) return [];
|
|
7950
|
+
perVariant[perVariant.length] = variantFaults;
|
|
7809
7951
|
}
|
|
7810
7952
|
const closest = selectClosestFaults(perVariant);
|
|
7811
7953
|
if (exclusive) {
|
|
@@ -7830,7 +7972,6 @@ var ContractCompiler = class ContractCompiler {
|
|
|
7830
7972
|
matched
|
|
7831
7973
|
}];
|
|
7832
7974
|
}
|
|
7833
|
-
for (let index2 = 0; index2 < perVariant.length; index2 += 1) if (perVariant[index2]?.length === 0) return [];
|
|
7834
7975
|
const report = [{
|
|
7835
7976
|
reason: "variant",
|
|
7836
7977
|
path,
|
|
@@ -10373,6 +10514,6 @@ function schemaToShape(schema) {
|
|
|
10373
10514
|
}, "schemaToShape");
|
|
10374
10515
|
}
|
|
10375
10516
|
//#endregion
|
|
10376
|
-
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_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, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, 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, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10517
|
+
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_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, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, 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, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10377
10518
|
|
|
10378
10519
|
//# sourceMappingURL=index.js.map
|