@orkestrel/contract 0.0.23 → 0.0.24
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 +924 -335
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +514 -125
- package/dist/src/core/index.d.ts +514 -125
- package/dist/src/core/index.js +913 -336
- package/dist/src/core/index.js.map +1 -1
- package/package.json +6 -6
package/dist/src/core/index.cjs
CHANGED
|
@@ -45,7 +45,8 @@ var SHAPE_FIELDS = Object.freeze({
|
|
|
45
45
|
nullable: Object.freeze(["inner"]),
|
|
46
46
|
json: Object.freeze(["description"]),
|
|
47
47
|
raw: Object.freeze(["schema"]),
|
|
48
|
-
shape: Object.freeze(["description"])
|
|
48
|
+
shape: Object.freeze(["description"]),
|
|
49
|
+
function: Object.freeze(["description"])
|
|
49
50
|
});
|
|
50
51
|
/**
|
|
51
52
|
* Holds the registry-global key used to recognize {@link ContractError} values
|
|
@@ -151,6 +152,8 @@ var INTRINSICS = Object.freeze({
|
|
|
151
152
|
prototype: Object.getPrototypeOf,
|
|
152
153
|
/** Captures `Object.getOwnPropertySymbols` — the own-symbol population. */
|
|
153
154
|
symbols: Object.getOwnPropertySymbols,
|
|
155
|
+
/** Captures `Object.getOwnPropertyNames` — the own string-key population, enumerable or not. */
|
|
156
|
+
names: Object.getOwnPropertyNames,
|
|
154
157
|
/** Captures `Object.prototype` — the realm-local plain-record prototype identity. */
|
|
155
158
|
base: Object.prototype,
|
|
156
159
|
/**
|
|
@@ -238,6 +241,8 @@ var INTRINSICS = Object.freeze({
|
|
|
238
241
|
order: Array.prototype.sort,
|
|
239
242
|
/** Captures `Array.prototype.some` for short-circuit membership checks. */
|
|
240
243
|
some: Array.prototype.some,
|
|
244
|
+
/** Captures `Array.prototype.every` for short-circuit checks that every entry passes. */
|
|
245
|
+
every: Array.prototype.every,
|
|
241
246
|
/** Captures `Array.prototype.findIndex`, including reads of sparse positions. */
|
|
242
247
|
find: Array.prototype.findIndex,
|
|
243
248
|
/** Captures `Array.prototype.forEach` for indexed visits of owned arrays. */
|
|
@@ -343,34 +348,50 @@ var JSON_SCHEMA_TYPES = Object.freeze([
|
|
|
343
348
|
"string"
|
|
344
349
|
]);
|
|
345
350
|
/**
|
|
346
|
-
* Lists the JSON Schema
|
|
351
|
+
* Lists the JSON Schema annotations a strict `schemaToShape` conversion admits on any node, frozen.
|
|
347
352
|
*
|
|
348
353
|
* @remarks
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* `pattern` and `format` are absent because no compiled shape asserts them, so a
|
|
353
|
-
* schema holding one would convert to a shape wider than the schema it came from. The
|
|
354
|
-
* one exception is `format: 'date'` on a string node, which a strict conversion reads
|
|
355
|
-
* as a date string shape.
|
|
354
|
+
* Each asserts nothing about a value, so a converted shape drops it without loss, except
|
|
355
|
+
* `description`, which the shape keeps. A strict conversion admits them beside every
|
|
356
|
+
* keyword it reads, the function leaf `{ not: {}, format: 'function' }` included.
|
|
356
357
|
*
|
|
357
358
|
* @example
|
|
358
359
|
* ```ts
|
|
359
|
-
*
|
|
360
|
-
*
|
|
360
|
+
* SCHEMA_ANNOTATIONS.includes('title') // true
|
|
361
|
+
* SCHEMA_ANNOTATIONS.at(-1) // 'examples'
|
|
361
362
|
* ```
|
|
362
363
|
*/
|
|
363
|
-
var
|
|
364
|
-
"type",
|
|
364
|
+
var SCHEMA_ANNOTATIONS = Object.freeze([
|
|
365
365
|
"title",
|
|
366
366
|
"description",
|
|
367
367
|
"$schema",
|
|
368
368
|
"$id",
|
|
369
369
|
"$comment",
|
|
370
|
-
"examples",
|
|
371
370
|
"deprecated",
|
|
372
371
|
"readOnly",
|
|
373
372
|
"writeOnly",
|
|
373
|
+
"examples"
|
|
374
|
+
]);
|
|
375
|
+
/**
|
|
376
|
+
* Lists the JSON Schema keywords a strict `schemaToShape` conversion reads, frozen.
|
|
377
|
+
*
|
|
378
|
+
* @remarks
|
|
379
|
+
* The keywords a shape can honour, plus {@link SCHEMA_ANNOTATIONS}. Every other keyword
|
|
380
|
+
* refuses. `pattern`, `format`, and `not` are absent because no compiled shape asserts
|
|
381
|
+
* them, so a schema holding one would convert to a shape wider than the schema it came
|
|
382
|
+
* from. The exceptions are `format: 'date'` on a string node, which a strict conversion
|
|
383
|
+
* reads as a date string shape, and the function leaf `{ not: {}, format: 'function' }`,
|
|
384
|
+
* which it reads as a function shape.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* STRICT_SCHEMA_KEYWORDS.includes('title') // true
|
|
389
|
+
* STRICT_SCHEMA_KEYWORDS.includes('pattern') // false
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
var STRICT_SCHEMA_KEYWORDS = Object.freeze([
|
|
393
|
+
"type",
|
|
394
|
+
...SCHEMA_ANNOTATIONS,
|
|
374
395
|
"default",
|
|
375
396
|
"enum",
|
|
376
397
|
"minLength",
|
|
@@ -442,7 +463,8 @@ var FAULT_KINDS = Object.freeze([
|
|
|
442
463
|
"object",
|
|
443
464
|
"union",
|
|
444
465
|
"json",
|
|
445
|
-
"shape"
|
|
466
|
+
"shape",
|
|
467
|
+
"function"
|
|
446
468
|
]);
|
|
447
469
|
/**
|
|
448
470
|
* Lists every {@link FaultConstraint}, frozen.
|
|
@@ -477,12 +499,14 @@ var FAULT_CONSTRAINTS = Object.freeze([
|
|
|
477
499
|
*/
|
|
478
500
|
var FAULT_LIMIT = 64;
|
|
479
501
|
/**
|
|
480
|
-
* Caps at `64` the
|
|
502
|
+
* Caps at `64` the length in UTF-16 code units of every {@link preview} result, frozen.
|
|
481
503
|
*
|
|
482
504
|
* @remarks
|
|
483
|
-
*
|
|
505
|
+
* The cap covers the whole preview, its quotes, its trailing `…`, and a
|
|
506
|
+
* bigint's `n` included, for every input. A longer rendering is clipped with `…`, so a
|
|
484
507
|
* {@link Fault}'s `received` field never embeds an unbounded amount of
|
|
485
|
-
* untrusted text
|
|
508
|
+
* untrusted text, and the {@link describeFaultLine} function prints it as
|
|
509
|
+
* written.
|
|
486
510
|
*/
|
|
487
511
|
var PREVIEW_LIMIT = 64;
|
|
488
512
|
/**
|
|
@@ -577,6 +601,25 @@ var COMPILE_NODE_LIMIT = 16384;
|
|
|
577
601
|
*/
|
|
578
602
|
var PRESENCE_MASK_LIMIT = 31;
|
|
579
603
|
/**
|
|
604
|
+
* Caps at `4` the number of key plans one compiled closed-object guard keeps, frozen.
|
|
605
|
+
*
|
|
606
|
+
* @remarks
|
|
607
|
+
* A compiled closed-object guard answers a value through the full key walk and,
|
|
608
|
+
* after a walk that accepts, keeps that value's key order as a plan: one
|
|
609
|
+
* {@link KeyStep} entry per key, in order. A later value whose own enumerable keys
|
|
610
|
+
* arrive in a kept order is answered by asking each step's guard in turn, with
|
|
611
|
+
* no presence or vocabulary question. The guard learns only from an accepted
|
|
612
|
+
* walk, never evicts, and stops learning at this count, so the plans it keeps
|
|
613
|
+
* are those of the earliest accepted key orders. Every other key order takes the
|
|
614
|
+
* full walk. Both paths answer identically; only the cost differs.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* KEY_PLAN_LIMIT // 4
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
var KEY_PLAN_LIMIT = 4;
|
|
622
|
+
/**
|
|
580
623
|
* Caps at `262144` the number of nodes one JSON snapshot may produce, frozen.
|
|
581
624
|
*
|
|
582
625
|
* @remarks
|
|
@@ -1498,20 +1541,28 @@ function isFault(value) {
|
|
|
1498
1541
|
* Determines whether a value is exactly one {@link AuditFault}.
|
|
1499
1542
|
*
|
|
1500
1543
|
* @remarks
|
|
1501
|
-
* Every {@link Fault}, and the undeclared-key
|
|
1544
|
+
* Every {@link Fault}, and the undeclared-key and hidden-key faults an audit adds: `extra` with
|
|
1545
|
+
* exactly `reason` and `path`, or with a string `symbol` beside them, and `hidden` with exactly
|
|
1546
|
+
* `reason` and `path`.
|
|
1502
1547
|
*
|
|
1503
1548
|
* @param value - The value to inspect
|
|
1504
1549
|
* @returns True if the value is a well-formed audit fault; false otherwise
|
|
1505
1550
|
*
|
|
1506
1551
|
* @example
|
|
1507
1552
|
* ```ts
|
|
1508
|
-
* isAuditFault({ reason: 'extra', path: ['a'] })
|
|
1509
|
-
* isAuditFault({})
|
|
1553
|
+
* isAuditFault({ reason: 'extra', path: ['a'] }) // true
|
|
1554
|
+
* isAuditFault({ reason: 'extra', path: [], symbol: 'Symbol(tag)' }) // true
|
|
1555
|
+
* isAuditFault({ reason: 'hidden', path: ['note'] }) // true
|
|
1556
|
+
* isAuditFault({}) // false
|
|
1510
1557
|
* ```
|
|
1511
1558
|
*/
|
|
1512
1559
|
function isAuditFault(value) {
|
|
1513
1560
|
if (isFault(value)) return true;
|
|
1514
|
-
return holds(() => isRecord(value) && value.reason === "
|
|
1561
|
+
return holds(() => isRecord(value) && isFaultPath(value.path) && (value.reason === "hidden" && matchesExactKeys(value, ["reason", "path"]) || value.reason === "extra" && (matchesExactKeys(value, ["reason", "path"]) || isString(value.symbol) && matchesExactKeys(value, [
|
|
1562
|
+
"reason",
|
|
1563
|
+
"path",
|
|
1564
|
+
"symbol"
|
|
1565
|
+
]))));
|
|
1515
1566
|
}
|
|
1516
1567
|
/** Determines whether a value is a `Map`.
|
|
1517
1568
|
*
|
|
@@ -2156,24 +2207,57 @@ function isJSONPrimitive(value) {
|
|
|
2156
2207
|
}
|
|
2157
2208
|
// src/core/helpers.ts
|
|
2158
2209
|
/**
|
|
2159
|
-
* Admits a
|
|
2210
|
+
* Admits a readable value exactly where `is` holds and returns the parser's value.
|
|
2211
|
+
*
|
|
2212
|
+
* @remarks
|
|
2213
|
+
* Guard-valid input parses once. Any other input refuses with every fault `audit` reports
|
|
2214
|
+
* after {@link filterUncoveredFaults} prunes the faults a union fault covers, bounded at
|
|
2215
|
+
* {@link FAULT_LIMIT}. A parse that returns `undefined` for a value other than `undefined`
|
|
2216
|
+
* refuses with no fault, and a read failure refuses with its cause rather than throwing.
|
|
2217
|
+
* Repair a lossless leaf through {@link repairValue}.
|
|
2218
|
+
*
|
|
2219
|
+
* @example
|
|
2220
|
+
* ```ts
|
|
2221
|
+
* admitValue(createContract(numberShape()), 3) // success carrying 3
|
|
2222
|
+
* admitValue(createContract(numberShape()), '3') // refusal carrying the type fault
|
|
2223
|
+
* ```
|
|
2224
|
+
*/
|
|
2225
|
+
function admitValue(contract, value) {
|
|
2226
|
+
try {
|
|
2227
|
+
if (contract.is(value)) {
|
|
2228
|
+
const parsed = contract.parse(value);
|
|
2229
|
+
if (parsed === void 0 && value !== void 0) return failure({ faults: [] });
|
|
2230
|
+
return success(parsed === void 0 ? value : parsed);
|
|
2231
|
+
}
|
|
2232
|
+
return failure({ faults: limitEntries(filterUncoveredFaults(contract.audit(value)), 64) });
|
|
2233
|
+
} catch (cause) {
|
|
2234
|
+
return failure({
|
|
2235
|
+
faults: [],
|
|
2236
|
+
cause
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Repairs a stable readable value with only lossless repairs and returns the parser's value.
|
|
2160
2242
|
*
|
|
2161
2243
|
* @remarks
|
|
2162
2244
|
* Reads must remain stable across artifacts. Guard-valid input skips both reports and parses
|
|
2163
2245
|
* once. Repairs use audit, parse once, and explain only on parse failure. Unresolved unions,
|
|
2164
2246
|
* extras, lossy repairs, and a capped audit refuse. An own optional undefined field omitted or
|
|
2165
|
-
* filled by its declared default is not a repair. The
|
|
2247
|
+
* filled by its declared default is not a repair. The merge of explain and audit faults keys on
|
|
2248
|
+
* reason and path, and keeps every `extra` fault carrying `symbol`, so two symbol keys of
|
|
2249
|
+
* one description stay two faults. The result preserves parser ownership, including union input identity.
|
|
2166
2250
|
* A read failure returns its cause rather than throwing.
|
|
2167
|
-
* Snapshot a foreign object before
|
|
2251
|
+
* Snapshot a foreign object before repair, as Tool.execute does. A getter changing between
|
|
2168
2252
|
* is and parse can publish a value that no recorded repair describes. A shallow snapshot only
|
|
2169
2253
|
* stabilizes its own level; nested foreign values must also provide stable reads.
|
|
2170
2254
|
*
|
|
2171
2255
|
* @example
|
|
2172
2256
|
* ```ts
|
|
2173
|
-
*
|
|
2257
|
+
* repairValue(createContract(numberShape()), '3') // success carrying 3 and its type repair
|
|
2174
2258
|
* ```
|
|
2175
2259
|
*/
|
|
2176
|
-
function
|
|
2260
|
+
function repairValue(contract, value) {
|
|
2177
2261
|
try {
|
|
2178
2262
|
if (contract.is(value)) {
|
|
2179
2263
|
const parsed = contract.parse(value);
|
|
@@ -2186,16 +2270,32 @@ function admitValue(contract, value) {
|
|
|
2186
2270
|
const audited = contract.audit(value);
|
|
2187
2271
|
const parsed = contract.parse(value);
|
|
2188
2272
|
const explained = parsed === void 0 ? contract.explain(value) : [];
|
|
2189
|
-
const repairs =
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2273
|
+
const repairs = [];
|
|
2274
|
+
const merged = [];
|
|
2275
|
+
appendEntries(merged, explained);
|
|
2276
|
+
for (const index of iterateIndices(() => audited.length)) {
|
|
2277
|
+
const fault = audited[index];
|
|
2278
|
+
if (fault === void 0) continue;
|
|
2279
|
+
if (matchesLosslessRepair(fault, value, parsed)) repairs[repairs.length] = fault;
|
|
2280
|
+
else if (!matchesUndefinedField(fault, value, parsed)) merged[merged.length] = fault;
|
|
2281
|
+
}
|
|
2282
|
+
const faults = [];
|
|
2283
|
+
const seen = new INTRINSICS.map();
|
|
2284
|
+
for (const index of iterateIndices(() => merged.length)) {
|
|
2285
|
+
const fault = merged[index];
|
|
2286
|
+
if (fault === void 0) continue;
|
|
2287
|
+
if (fault.reason === "extra" && fault.symbol !== void 0) {
|
|
2288
|
+
faults[faults.length] = fault;
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2291
|
+
const key = `${INTRINSICS.stringify(fault.reason)}|${buildPathKey(extractPath(fault))}`;
|
|
2292
|
+
const slot = INTRINSICS.reflect.apply(INTRINSICS.fetch, seen, [key]);
|
|
2293
|
+
if (slot === void 0) {
|
|
2294
|
+
INTRINSICS.reflect.apply(INTRINSICS.store, seen, [key, faults.length]);
|
|
2295
|
+
faults[faults.length] = fault;
|
|
2296
|
+
} else faults[slot] = fault;
|
|
2297
|
+
}
|
|
2298
|
+
const uncovered = filterUncoveredFaults(faults);
|
|
2199
2299
|
if (uncovered.length > 0) return failure({ faults: limitEntries(uncovered, 64) });
|
|
2200
2300
|
if (audited.length >= 64) return failure({ faults: limitEntries(audited, 64) });
|
|
2201
2301
|
if (parsed === void 0) return failure({ faults: limitEntries(audited, 64) });
|
|
@@ -2211,6 +2311,68 @@ function admitValue(contract, value) {
|
|
|
2211
2311
|
}
|
|
2212
2312
|
}
|
|
2213
2313
|
/**
|
|
2314
|
+
* Builds a map key from the leading segments of a path, without dispatching through array serialization.
|
|
2315
|
+
*
|
|
2316
|
+
* @remarks
|
|
2317
|
+
* Each segment is encoded as a quoted string and the encodings are joined by a captured `join`,
|
|
2318
|
+
* so a caller-installed `Array.prototype.toJSON` cannot reach the key and two paths never share one.
|
|
2319
|
+
*
|
|
2320
|
+
* @param path - The path whose leading segments form the key
|
|
2321
|
+
* @param length - The number of leading segments to keep; default: every segment
|
|
2322
|
+
* @returns The key text, empty for no segment
|
|
2323
|
+
*
|
|
2324
|
+
* @example
|
|
2325
|
+
* ```ts
|
|
2326
|
+
* buildPathKey(['a', 'b'], 1) // '"a"'
|
|
2327
|
+
* ```
|
|
2328
|
+
*/
|
|
2329
|
+
function buildPathKey(path, length = path.length) {
|
|
2330
|
+
const parts = INTRINSICS.from(iterateIndices(() => length), (index) => INTRINSICS.stringify(path[index]));
|
|
2331
|
+
return INTRINSICS.reflect.apply(INTRINSICS.join, parts, [","]);
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* Filters out the faults a union fault covers, keeping every fault that states a fact no form shows.
|
|
2335
|
+
*
|
|
2336
|
+
* @remarks
|
|
2337
|
+
* A `variant` or `oneOf` fault covers every fault beneath its path and every non-union fault at
|
|
2338
|
+
* its path, and never itself. A `hidden` fault and an `extra` fault carrying `symbol` are kept
|
|
2339
|
+
* whatever covers them, because each reports a member outside the enumerable view that no
|
|
2340
|
+
* form summary names.
|
|
2341
|
+
*
|
|
2342
|
+
* @param faults - The faults an audit reported
|
|
2343
|
+
* @returns The faults no cover prunes, in their order
|
|
2344
|
+
*
|
|
2345
|
+
* @example
|
|
2346
|
+
* ```ts
|
|
2347
|
+
* filterUncoveredFaults([
|
|
2348
|
+
* { reason: 'variant', path: [], variants: 2 },
|
|
2349
|
+
* { reason: 'extra', path: ['typo'] },
|
|
2350
|
+
* ]) // [{ reason: 'variant', path: [], variants: 2 }]
|
|
2351
|
+
* ```
|
|
2352
|
+
*/
|
|
2353
|
+
function filterUncoveredFaults(faults) {
|
|
2354
|
+
const covers = new INTRINSICS.set();
|
|
2355
|
+
for (const index of iterateIndices(() => faults.length)) {
|
|
2356
|
+
const fault = faults[index];
|
|
2357
|
+
if (fault !== void 0 && (fault.reason === "variant" || fault.reason === "oneOf")) INTRINSICS.reflect.apply(INTRINSICS.admit, covers, [buildPathKey(extractPath(fault))]);
|
|
2358
|
+
}
|
|
2359
|
+
const kept = [];
|
|
2360
|
+
pruning: for (const index of iterateIndices(() => faults.length)) {
|
|
2361
|
+
const fault = faults[index];
|
|
2362
|
+
if (fault === void 0) continue;
|
|
2363
|
+
if (fault.reason !== "hidden" && !(fault.reason === "extra" && fault.symbol !== void 0)) {
|
|
2364
|
+
const path = extractPath(fault);
|
|
2365
|
+
const room = fault.reason === "variant" || fault.reason === "oneOf" ? 1 : 0;
|
|
2366
|
+
for (const length of iterateIndices(() => path.length - room + 1)) {
|
|
2367
|
+
const prefix = buildPathKey(path, length);
|
|
2368
|
+
if (INTRINSICS.reflect.apply(INTRINSICS.member, covers, [prefix])) continue pruning;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
kept[kept.length] = fault;
|
|
2372
|
+
}
|
|
2373
|
+
return kept;
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2214
2376
|
* Checks whether a type fault describes an own undefined field omitted or defaulted by a successful parse.
|
|
2215
2377
|
*
|
|
2216
2378
|
* @remarks
|
|
@@ -2226,9 +2388,20 @@ function admitValue(contract, value) {
|
|
|
2226
2388
|
function matchesUndefinedField(fault, value, parsed) {
|
|
2227
2389
|
if (fault.reason !== "type" || parsed === void 0) return false;
|
|
2228
2390
|
const path = extractPath(fault);
|
|
2229
|
-
const key = path.
|
|
2391
|
+
const key = path[path.length - 1];
|
|
2230
2392
|
if (key === void 0) return false;
|
|
2231
|
-
const
|
|
2393
|
+
const cursor = {
|
|
2394
|
+
raw: value,
|
|
2395
|
+
result: parsed
|
|
2396
|
+
};
|
|
2397
|
+
for (const index of iterateIndices(() => path.length - 1)) {
|
|
2398
|
+
const segment = path[index];
|
|
2399
|
+
if (segment === void 0) return false;
|
|
2400
|
+
const { raw, result } = cursor;
|
|
2401
|
+
cursor.raw = isObject(raw) && INTRINSICS.own(raw, segment) ? INTRINSICS.reflect.read(raw, segment) : void 0;
|
|
2402
|
+
cursor.result = isObject(result) && INTRINSICS.own(result, segment) ? INTRINSICS.reflect.read(result, segment) : void 0;
|
|
2403
|
+
}
|
|
2404
|
+
const { raw, result } = cursor;
|
|
2232
2405
|
return isObject(raw) && INTRINSICS.own(raw, key) && INTRINSICS.reflect.read(raw, key) === void 0 && isObject(result);
|
|
2233
2406
|
}
|
|
2234
2407
|
/**
|
|
@@ -2242,7 +2415,10 @@ function matchesUndefinedField(fault, value, parsed) {
|
|
|
2242
2415
|
function truncateFaultText(text, limit) {
|
|
2243
2416
|
if (limit <= 0) return "";
|
|
2244
2417
|
if (text.length <= limit) return text;
|
|
2245
|
-
|
|
2418
|
+
const bound = INTRINSICS.floor(limit);
|
|
2419
|
+
const last = text[bound - 2];
|
|
2420
|
+
const kept = last !== void 0 && last >= "\ud800" && last <= "\udbff" ? bound - 2 : bound - 1;
|
|
2421
|
+
return `${INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.from(iterateIndices(() => kept), (index) => text[index]), [""])}…`;
|
|
2246
2422
|
}
|
|
2247
2423
|
/**
|
|
2248
2424
|
* Describes bounded faults with encoded values and a schema-derived correction summary.
|
|
@@ -2261,19 +2437,19 @@ function truncateFaultText(text, limit) {
|
|
|
2261
2437
|
function describeFaults(faults, schema, options) {
|
|
2262
2438
|
const requested = options?.limit ?? 2048;
|
|
2263
2439
|
if (!isInteger(requested) || requested < 0) throw new ContractError("Fault text limit must be a non-negative integer", { code: "range" });
|
|
2264
|
-
const limit =
|
|
2265
|
-
const send = schema === void 0 ? "" : `send ${renderForm(schema,
|
|
2266
|
-
const lines = limitEntries(faults, 64)
|
|
2267
|
-
const room =
|
|
2268
|
-
const kept =
|
|
2440
|
+
const limit = INTRINSICS.min(requested, FAULT_TEXT_LIMIT);
|
|
2441
|
+
const send = schema === void 0 ? "" : `send ${renderForm(schema, INTRINSICS.min(160, INTRINSICS.floor(limit / 3)))}`;
|
|
2442
|
+
const lines = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(limitEntries(faults, 64)), [(fault) => describeFaultLine(fault, schema ?? {})]);
|
|
2443
|
+
const room = INTRINSICS.max(0, limit - send.length - 82);
|
|
2444
|
+
const kept = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(lines), [(_line, index) => INTRINSICS.reflect.apply(INTRINSICS.join, limitEntries(lines, index + 1), ["\n"]).length <= room]);
|
|
2269
2445
|
const hidden = faults.length - kept.length;
|
|
2270
|
-
const note = [
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2446
|
+
const note = INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([hidden > 0 ? `and ${INTRINSICS.text(hidden)} more faults` : void 0, faults.length >= 64 ? `the report stops at ${INTRINSICS.text(64)}` : void 0]), [(part) => part !== void 0]), [", "]);
|
|
2447
|
+
const extras = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([
|
|
2448
|
+
kept.length === 0 && lines.length > 0 && room > 0 ? truncateFaultText(lines[0] ?? "", room) : void 0,
|
|
2449
|
+
note.length === 0 ? void 0 : note,
|
|
2450
|
+
send.length === 0 ? void 0 : send
|
|
2451
|
+
]), [(part) => part !== void 0]);
|
|
2452
|
+
return truncateFaultText(INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.from(iterateIndices(() => kept.length + extras.length), (index) => index < kept.length ? kept[index] : extras[index - kept.length]), ["\n"]), limit);
|
|
2277
2453
|
}
|
|
2278
2454
|
/**
|
|
2279
2455
|
* Iterates indices while rereading the upper bound before every step.
|
|
@@ -2753,9 +2929,10 @@ function collectEntries(target) {
|
|
|
2753
2929
|
function readSetEntries(value) {
|
|
2754
2930
|
return attempt(() => {
|
|
2755
2931
|
const collected = [];
|
|
2756
|
-
INTRINSICS.reflect.apply(INTRINSICS.sweep, value, [
|
|
2757
|
-
|
|
2758
|
-
|
|
2932
|
+
INTRINSICS.reflect.apply(INTRINSICS.sweep, value, [(entry) => {
|
|
2933
|
+
collected[collected.length] = entry;
|
|
2934
|
+
}]);
|
|
2935
|
+
return INTRINSICS.freeze(collected);
|
|
2759
2936
|
});
|
|
2760
2937
|
}
|
|
2761
2938
|
/**
|
|
@@ -3462,80 +3639,109 @@ function matchesRecordBrand(value) {
|
|
|
3462
3639
|
return true;
|
|
3463
3640
|
}
|
|
3464
3641
|
/**
|
|
3465
|
-
*
|
|
3642
|
+
* Collects an array's entries through its reflected own-index population.
|
|
3466
3643
|
*
|
|
3467
3644
|
* @remarks
|
|
3468
3645
|
* Reads `length` once and one reflected own-key population, then corroborates
|
|
3469
3646
|
* and reads only those reflected canonical indices in ascending order. The
|
|
3470
|
-
*
|
|
3471
|
-
*
|
|
3472
|
-
*
|
|
3473
|
-
*
|
|
3474
|
-
*
|
|
3475
|
-
*
|
|
3476
|
-
*
|
|
3477
|
-
*
|
|
3478
|
-
*
|
|
3479
|
-
*
|
|
3480
|
-
*
|
|
3481
|
-
*
|
|
3647
|
+
* native entries retain actual holes: reading one yields `undefined`, while
|
|
3648
|
+
* own membership remains absent. Its work is proportional to the reflected
|
|
3649
|
+
* population, so a length-driven consumer must require `dense` or carry an
|
|
3650
|
+
* independent bound. `exact` is false when the population holds any key other
|
|
3651
|
+
* than a canonical index or `length`, a symbol key included. A population that
|
|
3652
|
+
* is exactly the canonical indices in ascending order followed by `length` is
|
|
3653
|
+
* copied straight by index under the same per-index corroboration, and answers
|
|
3654
|
+
* with the same entries, the same `dense` and `exact` facts, and the same
|
|
3655
|
+
* refusals as the walk. Caller-defined iteration is ignored. A descriptor-only
|
|
3656
|
+
* index omitted from reflection is deliberately outside this lens and remains a
|
|
3657
|
+
* hole. `4294967295` is metadata rather than an array index. Every call returns
|
|
3658
|
+
* a fresh unfrozen read; {@link readArrayEntries} freezes it.
|
|
3482
3659
|
*
|
|
3483
|
-
* @param value - The array whose reflected indexed entries to
|
|
3484
|
-
* @returns
|
|
3485
|
-
*
|
|
3660
|
+
* @param value - The array whose reflected indexed entries to collect
|
|
3661
|
+
* @returns The entries with their `dense` and `exact` facts
|
|
3662
|
+
* @throws The exact thrown value when length, reflection, membership, or
|
|
3663
|
+
* indexed value observation throws, and an `Error` on a non-native
|
|
3664
|
+
* length or a view disagreement
|
|
3486
3665
|
*
|
|
3487
3666
|
* @example
|
|
3488
3667
|
* ```ts
|
|
3489
|
-
*
|
|
3668
|
+
* collectArrayEntries([1, 2]) // { entries: [1, 2], dense: true, exact: true }
|
|
3490
3669
|
* ```
|
|
3491
3670
|
*/
|
|
3492
|
-
function
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3671
|
+
function collectArrayEntries(value) {
|
|
3672
|
+
const length = value.length;
|
|
3673
|
+
if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
|
|
3674
|
+
const members = INTRINSICS.reflect.members(value);
|
|
3675
|
+
if (members.length === length + 1 && members[length] === "length" && !INTRINSICS.reflect.apply(INTRINSICS.some, members, [(key, index) => index < length && key !== INTRINSICS.text(index)])) {
|
|
3676
|
+
const indices = {
|
|
3677
|
+
__proto__: null,
|
|
3678
|
+
length
|
|
3679
|
+
};
|
|
3680
|
+
return {
|
|
3681
|
+
entries: INTRINSICS.from(indices, (_entry, index) => {
|
|
3499
3682
|
const key = members[index];
|
|
3500
3683
|
if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
|
|
3501
3684
|
return value[index];
|
|
3502
|
-
})
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
const
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3685
|
+
}),
|
|
3686
|
+
dense: true,
|
|
3687
|
+
exact: true
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
const selected = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => {
|
|
3691
|
+
if (!isString(key)) return [];
|
|
3692
|
+
const index = INTRINSICS.numeric(key);
|
|
3693
|
+
if (!INTRINSICS.integer(index) || index < 0 || index >= 2 ** 32 - 1 || INTRINSICS.text(index) !== key) return [];
|
|
3694
|
+
if (index >= length) throw new INTRINSICS.error("Array index views disagree");
|
|
3695
|
+
return [{
|
|
3696
|
+
index,
|
|
3697
|
+
key
|
|
3698
|
+
}];
|
|
3699
|
+
}]);
|
|
3700
|
+
const collected = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.index]);
|
|
3701
|
+
const keys = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
|
|
3702
|
+
const ascending = !INTRINSICS.reflect.apply(INTRINSICS.some, collected, [(index, position) => index <= (collected[position - 1] ?? -1)]);
|
|
3703
|
+
const indices = ascending ? collected : sortValues(collected);
|
|
3704
|
+
const pairs = INTRINSICS.from(iterateIndices(() => indices.length), (position) => {
|
|
3705
|
+
const index = indices[position];
|
|
3706
|
+
const key = ascending ? keys[position] : INTRINSICS.text(index);
|
|
3707
|
+
if (index === void 0 || key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
|
|
3708
|
+
return [key, {
|
|
3709
|
+
value: value[index],
|
|
3710
|
+
enumerable: true,
|
|
3711
|
+
configurable: true,
|
|
3712
|
+
writable: true
|
|
3713
|
+
}];
|
|
3714
|
+
});
|
|
3715
|
+
const descriptors = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
|
|
3716
|
+
return {
|
|
3717
|
+
entries: INTRINSICS.definitions(new INTRINSICS.list(length), descriptors),
|
|
3718
|
+
dense: indices.length === length,
|
|
3719
|
+
exact: members.length === selected.length + 1
|
|
3720
|
+
};
|
|
3721
|
+
}
|
|
3722
|
+
/**
|
|
3723
|
+
* Snapshots an array through its reflected own-index population.
|
|
3724
|
+
*
|
|
3725
|
+
* @remarks
|
|
3726
|
+
* Answers what {@link collectArrayEntries} answers, as a frozen read whose
|
|
3727
|
+
* entries are frozen too. Failure retains the exact thrown value when length,
|
|
3728
|
+
* reflection, membership, or indexed value observation throws; a non-native
|
|
3729
|
+
* length or view disagreement is also failure.
|
|
3730
|
+
*
|
|
3731
|
+
* @param value - The array whose reflected indexed entries to read
|
|
3732
|
+
* @returns A successful frozen entry snapshot with its `dense` and `exact`
|
|
3733
|
+
* facts, or a failure carrying the exact thrown value as `unknown`
|
|
3734
|
+
*
|
|
3735
|
+
* @example
|
|
3736
|
+
* ```ts
|
|
3737
|
+
* readArrayEntries([1, 2]) // { success: true, value: { entries: [1, 2], dense: true, exact: true } }
|
|
3738
|
+
* ```
|
|
3739
|
+
*/
|
|
3740
|
+
function readArrayEntries(value) {
|
|
3741
|
+
return attempt(() => {
|
|
3742
|
+
const read = collectArrayEntries(value);
|
|
3743
|
+
INTRINSICS.freeze(read.entries);
|
|
3744
|
+
return INTRINSICS.freeze(read);
|
|
3539
3745
|
});
|
|
3540
3746
|
}
|
|
3541
3747
|
/**
|
|
@@ -3611,6 +3817,110 @@ function enumerableKeys(value) {
|
|
|
3611
3817
|
return isSuccess(outcome) ? outcome.value : void 0;
|
|
3612
3818
|
}
|
|
3613
3819
|
/**
|
|
3820
|
+
* Checks whether an object owns no key outside the enumerable string keys already read from it.
|
|
3821
|
+
*
|
|
3822
|
+
* @remarks
|
|
3823
|
+
* Counts the own string keys, enumerable or not, against the key list and requires no own
|
|
3824
|
+
* symbol key. A key a `Proxy` lists among its own keys with no descriptor counts as own.
|
|
3825
|
+
* Thrown when the object's own-key reflection throws, so call it inside a boundary.
|
|
3826
|
+
*
|
|
3827
|
+
* @param value - The object whose own keys to count
|
|
3828
|
+
* @param keys - The object's own enumerable string keys, as `Object.keys` returned them
|
|
3829
|
+
* @returns True if the object owns no other key; false otherwise
|
|
3830
|
+
*
|
|
3831
|
+
* @example
|
|
3832
|
+
* ```ts
|
|
3833
|
+
* const value = { id: 'a' }
|
|
3834
|
+
* matchesEnumerableKeys(value, Object.keys(value)) // true
|
|
3835
|
+
* matchesEnumerableKeys(Object.defineProperty(value, 'secret', { value: 1 }), ['id']) // false
|
|
3836
|
+
* ```
|
|
3837
|
+
*/
|
|
3838
|
+
function matchesEnumerableKeys(value, keys) {
|
|
3839
|
+
return INTRINSICS.names(value).length === keys.length && INTRINSICS.symbols(value).length === 0;
|
|
3840
|
+
}
|
|
3841
|
+
/**
|
|
3842
|
+
* Builds the key plan that answers one key order from the declared member guards.
|
|
3843
|
+
*
|
|
3844
|
+
* @remarks
|
|
3845
|
+
* One {@link KeyStep} per key, in the order given, each holding the key and its declared guard.
|
|
3846
|
+
* The plan and its steps are fresh and unfrozen.
|
|
3847
|
+
*
|
|
3848
|
+
* @param keys - The key order the plan answers
|
|
3849
|
+
* @param guards - The declared member guards, keyed by own string key
|
|
3850
|
+
* @returns The plan, or `undefined` when any key is undeclared
|
|
3851
|
+
*
|
|
3852
|
+
* @example
|
|
3853
|
+
* ```ts
|
|
3854
|
+
* buildKeyPlan(['id'], { id: isString }) // [{ key: 'id', guard: isString }]
|
|
3855
|
+
* buildKeyPlan(['other'], { id: isString }) // undefined
|
|
3856
|
+
* ```
|
|
3857
|
+
*/
|
|
3858
|
+
function buildKeyPlan(keys, guards) {
|
|
3859
|
+
const plan = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(keys), [(key) => {
|
|
3860
|
+
const guard = INTRINSICS.own(guards, key) ? guards[key] : void 0;
|
|
3861
|
+
return guard === void 0 ? [] : [{
|
|
3862
|
+
key,
|
|
3863
|
+
guard
|
|
3864
|
+
}];
|
|
3865
|
+
}]);
|
|
3866
|
+
return plan.length === keys.length ? plan : void 0;
|
|
3867
|
+
}
|
|
3868
|
+
/**
|
|
3869
|
+
* Checks whether a key plan answers the key list bound as `this`.
|
|
3870
|
+
*
|
|
3871
|
+
* @remarks
|
|
3872
|
+
* Passed with the key list as the `thisArg` argument to the captured `findIndex` member over a list of
|
|
3873
|
+
* plans. A plan answers a key list holding the same keys in the same order, so a prefix and a
|
|
3874
|
+
* reordering both miss.
|
|
3875
|
+
*
|
|
3876
|
+
* @param plan - The key plan to compare
|
|
3877
|
+
* @returns True if the plan's keys equal the bound list in order; false otherwise
|
|
3878
|
+
*
|
|
3879
|
+
* @example
|
|
3880
|
+
* ```ts
|
|
3881
|
+
* matchesKeyPlan.call(['id'], [{ key: 'id', guard: isString }]) // true
|
|
3882
|
+
* ```
|
|
3883
|
+
*/
|
|
3884
|
+
function matchesKeyPlan(plan) {
|
|
3885
|
+
return plan.length === this.length && INTRINSICS.reflect.apply(INTRINSICS.every, plan, [matchesStepKey, this]);
|
|
3886
|
+
}
|
|
3887
|
+
/**
|
|
3888
|
+
* Checks whether a key-plan step names the key at its index in the list bound as `this`.
|
|
3889
|
+
*
|
|
3890
|
+
* @remarks
|
|
3891
|
+
* Passed with the key list as the `thisArg` argument to the captured `every` member over a key plan.
|
|
3892
|
+
*
|
|
3893
|
+
* @param step - The step to compare
|
|
3894
|
+
* @param index - The step's position in its plan
|
|
3895
|
+
* @returns True if the step's key equals the bound list's key at that index; false otherwise
|
|
3896
|
+
*
|
|
3897
|
+
* @example
|
|
3898
|
+
* ```ts
|
|
3899
|
+
* matchesStepKey.call(['id'], { key: 'id', guard: isString }, 0) // true
|
|
3900
|
+
* ```
|
|
3901
|
+
*/
|
|
3902
|
+
function matchesStepKey(step, index) {
|
|
3903
|
+
return step.key === this[index];
|
|
3904
|
+
}
|
|
3905
|
+
/**
|
|
3906
|
+
* Checks whether the member of the record bound as `this` passes a key-plan step's guard.
|
|
3907
|
+
*
|
|
3908
|
+
* @remarks
|
|
3909
|
+
* Passed with the record as the `thisArg` argument to the captured `every` member over a key plan, so the
|
|
3910
|
+
* walk reads each member once, in the plan's order, and stops at the first refusal.
|
|
3911
|
+
*
|
|
3912
|
+
* @param step - The step whose member to read and guard
|
|
3913
|
+
* @returns True if the member under the step's key passes its guard; false otherwise
|
|
3914
|
+
*
|
|
3915
|
+
* @example
|
|
3916
|
+
* ```ts
|
|
3917
|
+
* matchesStepGuard.call({ id: 'a' }, { key: 'id', guard: isString }) // true
|
|
3918
|
+
* ```
|
|
3919
|
+
*/
|
|
3920
|
+
function matchesStepGuard(step) {
|
|
3921
|
+
return step.guard(this[step.key]);
|
|
3922
|
+
}
|
|
3923
|
+
/**
|
|
3614
3924
|
* Validates and snapshots a shape-builder options record through every reflective
|
|
3615
3925
|
* operation the builder relies on.
|
|
3616
3926
|
*
|
|
@@ -3751,8 +4061,9 @@ function drawRandom(random, shape) {
|
|
|
3751
4061
|
*/
|
|
3752
4062
|
function resolveField(record, path) {
|
|
3753
4063
|
const outcome = attempt(() => {
|
|
3754
|
-
if (!
|
|
3755
|
-
|
|
4064
|
+
if (!matchesRecordBrand(record)) return void 0;
|
|
4065
|
+
if (isString(path)) return INTRINSICS.own(record, path) ? INTRINSICS.reflect.read(record, path) : void 0;
|
|
4066
|
+
const keys = path;
|
|
3756
4067
|
const indices = iterateIndices(() => keys.length);
|
|
3757
4068
|
return INTRINSICS.reflect.apply(INTRINSICS.reduce, indices, [(current, index) => {
|
|
3758
4069
|
const key = keys[index];
|
|
@@ -3800,7 +4111,7 @@ function matchesExactKeys(value, required, optional = []) {
|
|
|
3800
4111
|
* Only a `type` fault is a repair. A number needs a string whose trim is the number's own
|
|
3801
4112
|
* text, so `'30'` and `' 30 '` pass while `'30.0'`, `'007'`, `'0x10'`, `'1e3'`, `'+5'`,
|
|
3802
4113
|
* `'.5'`, `'-0'`, and `'9007199254740993'` do not. A boolean needs `'true'` or `'false'`,
|
|
3803
|
-
* a literal its trimmed text, and a string a finite number
|
|
4114
|
+
* a literal its trimmed text, and a string a finite number other than `-0`. Anything else refuses.
|
|
3804
4115
|
*
|
|
3805
4116
|
* @param fault - A fault `audit` reported
|
|
3806
4117
|
* @param input - The value as it arrived
|
|
@@ -3825,7 +4136,7 @@ function matchesLosslessRepair(fault, input, parsed) {
|
|
|
3825
4136
|
case "integer": return isString(raw) && isNumber(value) && raw.trim() === INTRINSICS.text(value);
|
|
3826
4137
|
case "literal": return isString(raw) && (isString(value) || isNumber(value) || isBoolean(value)) && raw.trim() === INTRINSICS.text(value);
|
|
3827
4138
|
case "boolean": return raw === "true" || raw === "false";
|
|
3828
|
-
case "string": return isFiniteNumber(raw);
|
|
4139
|
+
case "string": return isFiniteNumber(raw) && !INTRINSICS.same(raw, -0);
|
|
3829
4140
|
default: return false;
|
|
3830
4141
|
}
|
|
3831
4142
|
}
|
|
@@ -4207,7 +4518,8 @@ function canonicalStringify(value) {
|
|
|
4207
4518
|
value
|
|
4208
4519
|
}];
|
|
4209
4520
|
while (stack.length > 0) {
|
|
4210
|
-
const frame = stack.
|
|
4521
|
+
const frame = stack[stack.length - 1];
|
|
4522
|
+
stack.length -= 1;
|
|
4211
4523
|
if (frame === void 0) return void 0;
|
|
4212
4524
|
if (frame.operation === "exit") {
|
|
4213
4525
|
const parts = INTRINSICS.from(encodeParts(frame.members, frame.keys, encodings));
|
|
@@ -4503,41 +4815,51 @@ function sanitizeDepth(value) {
|
|
|
4503
4815
|
return INTRINSICS.min(sanitizeBudget(value, 32), 32);
|
|
4504
4816
|
}
|
|
4505
4817
|
/**
|
|
4506
|
-
* Renders
|
|
4507
|
-
* `
|
|
4508
|
-
*
|
|
4509
|
-
* @remarks
|
|
4510
|
-
*
|
|
4511
|
-
*
|
|
4512
|
-
* and
|
|
4513
|
-
*
|
|
4514
|
-
*
|
|
4515
|
-
*
|
|
4516
|
-
*
|
|
4517
|
-
*
|
|
4518
|
-
*
|
|
4519
|
-
*
|
|
4520
|
-
*
|
|
4521
|
-
*
|
|
4522
|
-
* `
|
|
4523
|
-
*
|
|
4524
|
-
*
|
|
4525
|
-
*
|
|
4526
|
-
*
|
|
4527
|
-
*
|
|
4528
|
-
*
|
|
4529
|
-
*
|
|
4530
|
-
*
|
|
4531
|
-
*
|
|
4532
|
-
*
|
|
4533
|
-
*
|
|
4534
|
-
*
|
|
4535
|
-
*
|
|
4536
|
-
*
|
|
4537
|
-
*
|
|
4818
|
+
* Renders a value as a bounded single-line string for a {@link Fault}'s `received` field, running
|
|
4819
|
+
* a `Proxy` object's `getPrototypeOf` trap.
|
|
4820
|
+
*
|
|
4821
|
+
* @remarks
|
|
4822
|
+
* Every preview, its quotes and its `…` included, is at most
|
|
4823
|
+
* {@link PREVIEW_LIMIT} UTF-16 code units long and holds no control character
|
|
4824
|
+
* and no line terminator.
|
|
4825
|
+
*
|
|
4826
|
+
* A string renders as its quoted JSON representation, and a narrowed symbol
|
|
4827
|
+
* through intrinsic `String` with the same escaping and no outer quotes. DEL
|
|
4828
|
+
* (U+007F), the C1 controls (U+0080 to U+009F), U+2028, and U+2029, which a
|
|
4829
|
+
* `JSON.stringify` call leaves raw, render as `\u` sequences. A string of at
|
|
4830
|
+
* most {@link PREVIEW_LIMIT} UTF-16 code units that holds none of those raw
|
|
4831
|
+
* characters takes its answer from one whole-string encode when that encode
|
|
4832
|
+
* fits the same limit. Every other string and every symbol renders through one
|
|
4833
|
+
* bounded indexed encoder that appends only complete escaped code-point tokens,
|
|
4834
|
+
* at most `PREVIEW_LIMIT - 2` UTF-16 code units between a string's quotes and
|
|
4835
|
+
* `PREVIEW_LIMIT - 1` of a symbol, and then closes with the quote when every
|
|
4836
|
+
* token fit and with `…` otherwise. Clipping therefore never retrieves the
|
|
4837
|
+
* mutable string iterator or splits an escape or a surrogate pair, and
|
|
4838
|
+
* enormous primitive text is not fully traversed. The two paths agree: one
|
|
4839
|
+
* `JSON.stringify` call fits the limit exactly when the escaped inner length
|
|
4840
|
+
* is at most `PREVIEW_LIMIT - 2`, which is when the indexed encoder closes
|
|
4841
|
+
* with the quote.
|
|
4842
|
+
*
|
|
4843
|
+
* A number or a boolean renders through `String`. A bigint renders through
|
|
4844
|
+
* `String` with a trailing `n`; when its text reaches {@link PREVIEW_LIMIT}
|
|
4845
|
+
* UTF-16 code units, the preview keeps the leading `PREVIEW_LIMIT - 2`, then
|
|
4846
|
+
* `…`, then `n`. `null` and `undefined` render as their own name.
|
|
4847
|
+
*
|
|
4848
|
+
* An array renders as `'array'`, a function as `'function'`, a plain or
|
|
4849
|
+
* null-prototype record as `'object'`, and every other object, such as a class
|
|
4850
|
+
* instance, a `Map`, a `Date`, or a revoked `Proxy`, as `'instance'`. To tell a
|
|
4851
|
+
* record from an instance, the {@link isRecord} guard reads the object's
|
|
4852
|
+
* prototype, that prototype's prototype, and, when the second is `null`, the
|
|
4853
|
+
* first one's own property descriptors. A `Proxy` object's `getPrototypeOf`
|
|
4854
|
+
* trap therefore runs, and so do the `getPrototypeOf` and
|
|
4855
|
+
* `getOwnPropertyDescriptor` traps of a `Proxy` object that stands as the
|
|
4856
|
+
* prototype; a trap that throws yields `'instance'`. Every read is a prototype
|
|
4857
|
+
* or descriptor read, so no accessor on the object or its prototype runs, and
|
|
4858
|
+
* no object is stringified.
|
|
4538
4859
|
*
|
|
4539
4860
|
* @param value - The value to preview
|
|
4540
|
-
* @returns A
|
|
4861
|
+
* @returns A string of at most {@link PREVIEW_LIMIT} UTF-16 code units with no
|
|
4862
|
+
* control character and no line terminator
|
|
4541
4863
|
*
|
|
4542
4864
|
* @example
|
|
4543
4865
|
* ```ts
|
|
@@ -4545,6 +4867,7 @@ function sanitizeDepth(value) {
|
|
|
4545
4867
|
* preview(42) // '42'
|
|
4546
4868
|
* preview(null) // 'null'
|
|
4547
4869
|
* preview({ a: 1 }) // 'object'
|
|
4870
|
+
* preview(new Map()) // 'instance'
|
|
4548
4871
|
* preview([1, 2, 3]) // 'array'
|
|
4549
4872
|
* ```
|
|
4550
4873
|
*/
|
|
@@ -4554,17 +4877,23 @@ function preview(value) {
|
|
|
4554
4877
|
if (isString(value) || isSymbol(value)) {
|
|
4555
4878
|
const quoted = isString(value);
|
|
4556
4879
|
const source = INTRINSICS.text(value);
|
|
4557
|
-
if (quoted && source.length <= 64) {
|
|
4880
|
+
if (quoted && source.length <= 64 && !matchesPattern(/[\x7f-\x9f\u{2028}\u{2029}]/u, source)) {
|
|
4558
4881
|
const whole = INTRINSICS.stringify(source);
|
|
4559
4882
|
if (whole.length <= 64) return whole;
|
|
4560
4883
|
}
|
|
4561
|
-
const parts = previewParts(source, 0, 64 - (quoted ?
|
|
4884
|
+
const parts = previewParts(source, 0, 64 - (quoted ? 2 : 1), quoted);
|
|
4562
4885
|
const body = INTRINSICS.reflect.apply(INTRINSICS.join, parts, [""]);
|
|
4563
4886
|
return quoted ? `"${body}` : body;
|
|
4564
4887
|
}
|
|
4565
4888
|
if (isNumber(value) || isBoolean(value)) return INTRINSICS.text(value);
|
|
4566
|
-
if (isBigInt(value))
|
|
4889
|
+
if (isBigInt(value)) {
|
|
4890
|
+
const digits = INTRINSICS.text(value);
|
|
4891
|
+
if (digits.length < 64) return `${digits}n`;
|
|
4892
|
+
const parts = previewParts(digits, 0, 62, false);
|
|
4893
|
+
return `${INTRINSICS.reflect.apply(INTRINSICS.join, parts, [""])}n`;
|
|
4894
|
+
}
|
|
4567
4895
|
if (isArray(value)) return "array";
|
|
4896
|
+
if (isObject(value) && !isRecord(value)) return "instance";
|
|
4568
4897
|
return typeof value;
|
|
4569
4898
|
}
|
|
4570
4899
|
/**
|
|
@@ -4809,6 +5138,7 @@ function selectClosestFaults(reports) {
|
|
|
4809
5138
|
* `'date'` when `date: true`, else `'string'`); `optionalShape` /
|
|
4810
5139
|
* `nullableShape` project through to their inner shape's kind, and `rawShape`
|
|
4811
5140
|
* (an arbitrary embedded schema with no fixed kind) projects to `'json'`.
|
|
5141
|
+
* `functionShape` projects to `'function'`.
|
|
4812
5142
|
*
|
|
4813
5143
|
* A hand-authored node carrying an unrecognized discriminant is REFUSED rather
|
|
4814
5144
|
* than answered out of type, which keeps the declared non-optional
|
|
@@ -4839,6 +5169,7 @@ function shapeToKind(shape) {
|
|
|
4839
5169
|
case "union": return "union";
|
|
4840
5170
|
case "json": return "json";
|
|
4841
5171
|
case "shape": return "shape";
|
|
5172
|
+
case "function": return "function";
|
|
4842
5173
|
case "optional": return shapeToKind(shape.inner);
|
|
4843
5174
|
case "nullable": return shapeToKind(shape.inner);
|
|
4844
5175
|
case "raw": return "json";
|
|
@@ -4912,9 +5243,14 @@ function* encodeParts(members, keys, encodings) {
|
|
|
4912
5243
|
/**
|
|
4913
5244
|
* Builds bounded escaped preview parts without splitting a surrogate pair.
|
|
4914
5245
|
*
|
|
5246
|
+
* @remarks
|
|
5247
|
+
* Each token is one code point's escape: its `JSON.stringify` form, or a `\u` sequence for DEL
|
|
5248
|
+
* (U+007F), a C1 control (U+0080 to U+009F), U+2028, or U+2029. The parts end with `…` when a
|
|
5249
|
+
* token does not fit, and otherwise with the closing quote of a quoted source.
|
|
5250
|
+
*
|
|
4915
5251
|
* @param source - The source text
|
|
4916
5252
|
* @param index - The next UTF-16 offset
|
|
4917
|
-
* @param capacity - The
|
|
5253
|
+
* @param capacity - The UTF-16 code units left for tokens; the closing quote or `…` takes one more
|
|
4918
5254
|
* @param quoted - Whether the final part closes a string quote
|
|
4919
5255
|
* @returns The escaped parts with their closing quote or truncation mark
|
|
4920
5256
|
*
|
|
@@ -4926,11 +5262,13 @@ function* encodeParts(members, keys, encodings) {
|
|
|
4926
5262
|
function previewParts(source, index, capacity, quoted) {
|
|
4927
5263
|
const available = INTRINSICS.min(capacity, 64);
|
|
4928
5264
|
const first = source[index];
|
|
4929
|
-
if (index >= source.length || first === void 0) return quoted ? [
|
|
5265
|
+
if (index >= source.length || first === void 0) return quoted ? ["\""] : [];
|
|
4930
5266
|
const second = index + 1 < source.length ? source[index + 1] : void 0;
|
|
4931
5267
|
const paired = first >= "\ud800" && first <= "\udbff" && second !== void 0 && second >= "\udc00" && second <= "\udfff";
|
|
4932
5268
|
const character = paired ? `${first}${second}` : first;
|
|
4933
|
-
const
|
|
5269
|
+
const control = character >= "" && character <= "" ? INTRINSICS.reflect.apply(INTRINSICS.find, "
", [(entry) => entry === character]) : -1;
|
|
5270
|
+
const code = 127 + control;
|
|
5271
|
+
const encoded = control >= 0 ? `"\\u00${"0123456789abcdef"[INTRINSICS.floor(code / 16)] ?? ""}${"0123456789abcdef"[code % 16] ?? ""}"` : character === "\u2028" ? "\"\\u2028\"" : character === "\u2029" ? "\"\\u2029\"" : INTRINSICS.stringify(character);
|
|
4934
5272
|
const length = encoded.length - 2;
|
|
4935
5273
|
if (length > available) return ["…"];
|
|
4936
5274
|
const characters = INTRINSICS.from(iterateIndices(() => length), (offset) => encoded[offset + 1]);
|
|
@@ -4956,6 +5294,11 @@ function buildPositions(names) {
|
|
|
4956
5294
|
/**
|
|
4957
5295
|
* Derives the bit mask of names present in an indexed lookup.
|
|
4958
5296
|
*
|
|
5297
|
+
* @remarks
|
|
5298
|
+
* Takes `names` as the array it declares and reads each present index once, in order,
|
|
5299
|
+
* through the captured fold, so a hole adds no bit. An array-like that is not an array
|
|
5300
|
+
* is outside this contract.
|
|
5301
|
+
*
|
|
4959
5302
|
* @param names - Names to observe in order
|
|
4960
5303
|
* @param positions - The bit position of each declared name
|
|
4961
5304
|
* @returns The combined signed 32-bit mask
|
|
@@ -4966,8 +5309,7 @@ function buildPositions(names) {
|
|
|
4966
5309
|
* ```
|
|
4967
5310
|
*/
|
|
4968
5311
|
function readPresence(names, positions) {
|
|
4969
|
-
return INTRINSICS.reflect.apply(INTRINSICS.
|
|
4970
|
-
const name = names[index];
|
|
5312
|
+
return INTRINSICS.reflect.apply(INTRINSICS.fold, names, [(mask, name) => {
|
|
4971
5313
|
if (name === void 0 || !INTRINSICS.own(positions, name)) return mask;
|
|
4972
5314
|
const position = positions[name];
|
|
4973
5315
|
return position === void 0 ? mask : mask | 1 << position;
|
|
@@ -5018,7 +5360,10 @@ function extractForms(schema) {
|
|
|
5018
5360
|
if (schema === void 0) return [];
|
|
5019
5361
|
const anyOf = INTRINSICS.own(schema, "anyOf") ? schema.anyOf : void 0;
|
|
5020
5362
|
const oneOf = INTRINSICS.own(schema, "oneOf") ? schema.oneOf : void 0;
|
|
5021
|
-
|
|
5363
|
+
const arms = isArray(anyOf) ? anyOf : isArray(oneOf) ? oneOf : [];
|
|
5364
|
+
const members = INTRINSICS.from(iterateIndices(() => arms.length), (index) => arms[index]);
|
|
5365
|
+
const forms = INTRINSICS.from(iterateIndices(() => members.length + 1), (index) => index === 0 ? schema : members[index - 1]);
|
|
5366
|
+
return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(forms), [(form) => form !== void 0]);
|
|
5022
5367
|
}
|
|
5023
5368
|
/**
|
|
5024
5369
|
* Extracts the part of a schema a path reaches, through properties, array items, record values,
|
|
@@ -5043,15 +5388,19 @@ function extractForms(schema) {
|
|
|
5043
5388
|
* ```
|
|
5044
5389
|
*/
|
|
5045
5390
|
function extractSchema(schema, path) {
|
|
5046
|
-
const nodes =
|
|
5047
|
-
const
|
|
5048
|
-
const
|
|
5049
|
-
|
|
5050
|
-
|
|
5391
|
+
const nodes = INTRINSICS.reflect.apply(INTRINSICS.fold, path, [(parents, key) => {
|
|
5392
|
+
const forms = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(parents), [(node) => extractForms(node)]);
|
|
5393
|
+
const children = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(forms), [(form) => {
|
|
5394
|
+
const properties = INTRINSICS.own(form, "properties") ? form.properties : void 0;
|
|
5395
|
+
const additional = INTRINSICS.own(form, "additionalProperties") ? form.additionalProperties : void 0;
|
|
5396
|
+
return properties !== void 0 && INTRINSICS.own(properties, key) ? properties[key] : isRecord(additional) ? additional : INTRINSICS.own(form, "items") ? form.items : void 0;
|
|
5397
|
+
}])), [(child) => child !== void 0]);
|
|
5398
|
+
return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(children), [(child, index) => INTRINSICS.reflect.apply(INTRINSICS.find, children, [(other) => other === child]) === index]);
|
|
5399
|
+
}, [schema]]);
|
|
5051
5400
|
const first = nodes[0];
|
|
5052
5401
|
if (nodes.length < 2) return first;
|
|
5053
5402
|
const encoded = canonicalStringify(first);
|
|
5054
|
-
return encoded !== void 0 &&
|
|
5403
|
+
return encoded !== void 0 && !INTRINSICS.reflect.apply(INTRINSICS.some, nodes, [(node) => canonicalStringify(node) !== encoded]) ? first : void 0;
|
|
5055
5404
|
}
|
|
5056
5405
|
/**
|
|
5057
5406
|
* Renders a path as text, encoding what a caller could have sent and eliding the middle of a long
|
|
@@ -5073,13 +5422,15 @@ function extractSchema(schema, path) {
|
|
|
5073
5422
|
* ```
|
|
5074
5423
|
*/
|
|
5075
5424
|
function renderPath(path) {
|
|
5076
|
-
const segments =
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5425
|
+
const segments = INTRINSICS.from(iterateIndices(() => path.length), (index) => {
|
|
5426
|
+
const segment = path[index];
|
|
5427
|
+
if (segment === void 0) return "";
|
|
5428
|
+
return matchesPattern(/^[\w$-]{1,64}$/u, segment) ? segment : preview(segment);
|
|
5429
|
+
});
|
|
5430
|
+
const text = INTRINSICS.reflect.apply(INTRINSICS.join, segments, ["."]);
|
|
5431
|
+
if (segments.length <= 4 || text.length <= 120) return text;
|
|
5432
|
+
const elided = INTRINSICS.from(iterateIndices(() => 5), (index) => index === 0 ? segments[0] ?? "" : index === 1 ? "…" : segments[segments.length - 5 + index] ?? "");
|
|
5433
|
+
return INTRINSICS.reflect.apply(INTRINSICS.join, elided, ["."]);
|
|
5083
5434
|
}
|
|
5084
5435
|
/**
|
|
5085
5436
|
* Renders a list as text, naming at most `FAULT_LIST_LIMIT` of its entries and counting the rest.
|
|
@@ -5095,8 +5446,8 @@ function renderPath(path) {
|
|
|
5095
5446
|
* ```
|
|
5096
5447
|
*/
|
|
5097
5448
|
function renderList(entries) {
|
|
5098
|
-
const listed =
|
|
5099
|
-
return entries.length > 12 ? `${listed} and ${
|
|
5449
|
+
const listed = INTRINSICS.reflect.apply(INTRINSICS.join, limitEntries(entries, 12), [", "]);
|
|
5450
|
+
return entries.length > 12 ? `${listed} and ${INTRINSICS.text(entries.length - 12)} more` : listed;
|
|
5100
5451
|
}
|
|
5101
5452
|
/**
|
|
5102
5453
|
* Renders a schema as a short summary of what to send, such as `{"city": string, "note"?: string}`.
|
|
@@ -5107,6 +5458,8 @@ function renderList(entries) {
|
|
|
5107
5458
|
* and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
|
|
5108
5459
|
* below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
|
|
5109
5460
|
* `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
|
|
5461
|
+
* A schema with an own `not` reads `function` when its `format` is `'function'` and `never`
|
|
5462
|
+
* otherwise.
|
|
5110
5463
|
*
|
|
5111
5464
|
* @param schema - The schema to summarize
|
|
5112
5465
|
* @param room - The characters the summary can take. Default: `FAULT_SCHEMA_LIMIT`
|
|
@@ -5121,19 +5474,23 @@ function renderList(entries) {
|
|
|
5121
5474
|
*/
|
|
5122
5475
|
function renderForm(schema, room = 160) {
|
|
5123
5476
|
const deep = room >= 16;
|
|
5124
|
-
const inner =
|
|
5477
|
+
const inner = INTRINSICS.floor(room / 2);
|
|
5125
5478
|
const anyOf = INTRINSICS.own(schema, "anyOf") ? schema.anyOf : void 0;
|
|
5126
5479
|
const oneOf = INTRINSICS.own(schema, "oneOf") ? schema.oneOf : void 0;
|
|
5127
|
-
const forms = anyOf
|
|
5128
|
-
const required = (INTRINSICS.own(schema, "required") ? schema.required : void 0) ?? [];
|
|
5129
|
-
const
|
|
5480
|
+
const forms = isArray(anyOf) ? anyOf : isArray(oneOf) ? oneOf : void 0;
|
|
5481
|
+
const required = collectMembers((INTRINSICS.own(schema, "required") ? schema.required : void 0) ?? []);
|
|
5482
|
+
const properties = (INTRINSICS.own(schema, "properties") ? schema.properties : void 0) ?? {};
|
|
5483
|
+
const keys = INTRINSICS.keys(properties);
|
|
5130
5484
|
const type = INTRINSICS.own(schema, "type") ? schema.type : void 0;
|
|
5131
5485
|
const enumeration = INTRINSICS.own(schema, "enum") ? schema.enum : void 0;
|
|
5132
5486
|
const additional = INTRINSICS.own(schema, "additionalProperties") ? schema.additionalProperties : void 0;
|
|
5133
|
-
const
|
|
5134
|
-
const
|
|
5487
|
+
const negated = INTRINSICS.own(schema, "not");
|
|
5488
|
+
const callable = INTRINSICS.own(schema, "format") && schema.format === "function";
|
|
5489
|
+
const ordered = deep ? INTRINSICS.reflect.apply(INTRINSICS.order, INTRINSICS.from(iterateIndices(() => keys.length), (index) => keys[index] ?? ""), [(left, right) => INTRINSICS.numeric(matchesMember(required, right)) - INTRINSICS.numeric(matchesMember(required, left))]) : [];
|
|
5490
|
+
const listed = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(limitEntries(ordered, 12)), [(key) => `${preview(key)}${matchesMember(required, key) ? "" : "?"}: ${renderForm(properties[key] ?? {}, inner)}`]);
|
|
5491
|
+
const left = keys.length - listed.length;
|
|
5135
5492
|
const child = type === "array" ? INTRINSICS.own(schema, "items") ? schema.items : void 0 : isRecord(additional) ? additional : void 0;
|
|
5136
|
-
const bounds =
|
|
5493
|
+
const bounds = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.keys(schema)), [(key) => INTRINSICS.reflect.apply(INTRINSICS.some, [
|
|
5137
5494
|
"minLength",
|
|
5138
5495
|
"maxLength",
|
|
5139
5496
|
"minimum",
|
|
@@ -5142,20 +5499,19 @@ function renderForm(schema, room = 160) {
|
|
|
5142
5499
|
"maxItems",
|
|
5143
5500
|
"pattern",
|
|
5144
5501
|
"format"
|
|
5145
|
-
]
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
...deep && child !== void 0 ? [` of ${renderForm(child, inner)}`] : [],
|
|
5149
|
-
...bounds.length > 0 ? [` (${bounds.join(", ")})`] : []
|
|
5150
|
-
].join(""), room);
|
|
5502
|
+
], [(name) => name === key])])), [(key) => `${key} ${preview(INTRINSICS.reflect.read(schema, key))}`]);
|
|
5503
|
+
const word = type === void 0 ? keys.length > 0 ? "object" : "any" : INTRINSICS.reflect.apply(INTRINSICS.some, JSON_SCHEMA_TYPES, [(name) => name === type]) ? INTRINSICS.text(type) : preview(type);
|
|
5504
|
+
return truncateFaultText(negated ? callable ? "function" : "never" : forms !== void 0 ? deep ? INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(forms), [(form) => renderForm(form, inner)]), [" | "]) : "any" : enumeration !== void 0 ? INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(enumeration), [(value) => preview(value)]), [" | "]) : listed.length > 0 ? `{${INTRINSICS.reflect.apply(INTRINSICS.join, listed, [", "])}${left > 0 ? `, and ${INTRINSICS.text(left)} more` : ""}}` : `${word}${deep && child !== void 0 ? ` of ${renderForm(child, inner)}` : ""}${bounds.length > 0 ? ` (${INTRINSICS.reflect.apply(INTRINSICS.join, bounds, [", "])})` : ""}`, room);
|
|
5151
5505
|
}
|
|
5152
5506
|
/**
|
|
5153
5507
|
* Describes one fault as the line a caller corrects from, naming what to send where the schema
|
|
5154
5508
|
* says.
|
|
5155
5509
|
*
|
|
5156
5510
|
* @remarks
|
|
5157
|
-
* Each line opens with the fault's path (or `value` at the root) and reason.
|
|
5158
|
-
*
|
|
5511
|
+
* Each line opens with the fault's path (or `value` at the root) and reason. A `hidden` fault says
|
|
5512
|
+
* the member is not enumerable and to send it as a plain data member. An `extra` fault carrying
|
|
5513
|
+
* `symbol` names the symbol key and lists no declared key; another `extra` fault lists its
|
|
5514
|
+
* parent's keys only when no array form sits at the parent and the declaring arms agree. A literal names candidates only where
|
|
5159
5515
|
* the declarations agree; lists are deduplicated and bounded. A received preview stays as written
|
|
5160
5516
|
* within PREVIEW_LIMIT and without control or line-separator characters; otherwise it is encoded
|
|
5161
5517
|
* through preview. Received, constraint, and limit details read only own fields. A `variant` or
|
|
@@ -5177,39 +5533,52 @@ function renderForm(schema, room = 160) {
|
|
|
5177
5533
|
function describeFaultLine(fault, schema) {
|
|
5178
5534
|
const path = extractPath(fault);
|
|
5179
5535
|
const head = `${renderPath(path) || "value"}: ${fault.reason}`;
|
|
5536
|
+
if (fault.reason === "hidden") return `${head}; this member is not enumerable, send it as a plain data member`;
|
|
5537
|
+
const detail = "received" in fault && INTRINSICS.own(fault, "received") ? fault.received : "symbol" in fault && INTRINSICS.own(fault, "symbol") ? fault.symbol : void 0;
|
|
5538
|
+
const encoded = detail !== void 0 && detail.length <= 64 && !matchesPattern(/[\p{Cc}\p{Zl}\p{Zp}]/u, detail) ? detail : preview(detail);
|
|
5539
|
+
if (fault.reason === "extra" && detail !== void 0) return `${head}; symbol key ${encoded} is not declared, remove it`;
|
|
5180
5540
|
if (fault.reason === "extra") {
|
|
5181
|
-
const
|
|
5541
|
+
const forms = extractForms(extractSchema(schema, INTRINSICS.from(iterateIndices(() => path.length - 1), (index) => path[index] ?? "")));
|
|
5542
|
+
const declarations = INTRINSICS.reflect.apply(INTRINSICS.some, forms, [(form) => INTRINSICS.own(form, "items") || INTRINSICS.own(form, "type") && form.type === "array"]) ? [] : INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(forms), [(form) => INTRINSICS.own(form, "properties") && form.properties !== void 0])), [(form) => INTRINSICS.keys(form.properties ?? {})]);
|
|
5182
5543
|
const first = declarations[0] ?? [];
|
|
5183
|
-
const keys =
|
|
5184
|
-
return keys.length === 0 ? `${head}; this key is not declared, remove it` : `${head}; this key is not declared, remove it or use a declared key: ${renderList(
|
|
5544
|
+
const keys = INTRINSICS.reflect.apply(INTRINSICS.some, declarations, [(declared) => declared.length !== first.length || INTRINSICS.reflect.apply(INTRINSICS.some, declared, [(key) => !INTRINSICS.reflect.apply(INTRINSICS.some, first, [(name) => name === key])])]) ? [] : first;
|
|
5545
|
+
return keys.length === 0 ? `${head}; this key is not declared, remove it` : `${head}; this key is not declared, remove it or use a declared key: ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(keys), [(key) => renderPath([key])]))}`;
|
|
5185
5546
|
}
|
|
5186
5547
|
const node = extractSchema(schema, path);
|
|
5187
5548
|
const anyOf = node !== void 0 && INTRINSICS.own(node, "anyOf") ? node.anyOf : void 0;
|
|
5188
5549
|
const oneOf = node !== void 0 && INTRINSICS.own(node, "oneOf") ? node.oneOf : void 0;
|
|
5189
5550
|
if (fault.reason === "variant" || fault.reason === "oneOf") {
|
|
5190
5551
|
const count = fault.reason === "variant" ? fault.variants : oneOf?.length;
|
|
5191
|
-
const forms = count === void 0 ? "the declared forms" : `the ${
|
|
5192
|
-
const claim = fault.reason === "oneOf" && fault.matched > 0 ? `the value matches ${
|
|
5552
|
+
const forms = count === void 0 ? "the declared forms" : `the ${INTRINSICS.text(count)} declared forms`;
|
|
5553
|
+
const claim = fault.reason === "oneOf" && fault.matched > 0 ? `the value matches ${INTRINSICS.text(fault.matched)} of ${forms} and must match exactly one` : `the value matches none of ${forms}`;
|
|
5193
5554
|
const declared = anyOf ?? oneOf ?? [];
|
|
5194
|
-
const shown = declared
|
|
5195
|
-
const room =
|
|
5555
|
+
const shown = limitEntries(declared, 12);
|
|
5556
|
+
const room = INTRINSICS.min(160, INTRINSICS.floor(FAULT_TEXT_LIMIT / 2 / INTRINSICS.max(shown.length, 1)));
|
|
5196
5557
|
const more = declared.length - shown.length;
|
|
5197
|
-
const summary = shown.length === 0 ? "" : `, one of: ${
|
|
5198
|
-
return `${head}; ${claim}${fault.key === void 0 ? "" : `; discriminator ${preview(fault.key)} expects ${renderList((fault.expected ?? [])
|
|
5199
|
-
}
|
|
5200
|
-
const candidates = fault.expected === "literal" ?
|
|
5558
|
+
const summary = shown.length === 0 ? "" : `, one of: ${INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(shown), [(form) => renderForm(form, room)]), [" or "])}${more > 0 ? ` and ${INTRINSICS.text(more)} more` : ""}`;
|
|
5559
|
+
return `${head}; ${claim}${fault.key === void 0 ? "" : `; discriminator ${preview(fault.key)} expects ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(fault.expected ?? []), [(value) => preview(value)]))}`}; send it exactly as the schema declares${summary}`;
|
|
5560
|
+
}
|
|
5561
|
+
const candidates = fault.expected === "literal" ? INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(extractForms(node)), [(form) => {
|
|
5562
|
+
const values = (INTRINSICS.own(form, "enum") ? form.enum : void 0) ?? [];
|
|
5563
|
+
const nullable = INTRINSICS.own(form, "type") && form.type === "null";
|
|
5564
|
+
return INTRINSICS.from(iterateIndices(() => values.length + (nullable ? 1 : 0)), (index) => index < values.length ? values[index] : null);
|
|
5565
|
+
}]) : [];
|
|
5566
|
+
const seen = new INTRINSICS.set();
|
|
5567
|
+
const distinct = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(candidates), [(value) => {
|
|
5568
|
+
if (matchesMember(seen, value)) return false;
|
|
5569
|
+
admitMember(seen, value);
|
|
5570
|
+
return true;
|
|
5571
|
+
}]);
|
|
5201
5572
|
const description = node !== void 0 && INTRINSICS.own(node, "description") ? node.description : void 0;
|
|
5202
|
-
|
|
5203
|
-
const shown = received !== void 0 && received.length <= 64 && !/[\p{Cc}\p{Zl}\p{Zp}]/u.test(received) ? received : preview(received);
|
|
5204
|
-
return [
|
|
5573
|
+
return INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([
|
|
5205
5574
|
head,
|
|
5206
5575
|
`expected ${fault.expected}`,
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
]
|
|
5576
|
+
detail !== void 0 ? `received ${encoded}` : void 0,
|
|
5577
|
+
"constraint" in fault && INTRINSICS.own(fault, "constraint") ? `constraint ${fault.constraint}` : void 0,
|
|
5578
|
+
"limit" in fault && INTRINSICS.own(fault, "limit") && fault.limit !== void 0 ? `limit ${preview(fault.limit)}` : void 0,
|
|
5579
|
+
description === void 0 ? void 0 : `description ${preview(description)}`,
|
|
5580
|
+
distinct.length > 0 ? `send one of ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(distinct), [(value) => preview(value)]))}` : void 0
|
|
5581
|
+
]), [(part) => part !== void 0]), ["; "]);
|
|
5213
5582
|
}
|
|
5214
5583
|
// src/core/JSONCloner.ts
|
|
5215
5584
|
/**
|
|
@@ -5270,7 +5639,7 @@ var JSONCloner = class JSONCloner {
|
|
|
5270
5639
|
this.#terminal = failure(poison);
|
|
5271
5640
|
throw poison;
|
|
5272
5641
|
}
|
|
5273
|
-
this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered");
|
|
5642
|
+
this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered", { shape: "json" });
|
|
5274
5643
|
const outcome = attempt(() => this.#execute(budget));
|
|
5275
5644
|
const interruption = this.#terminal;
|
|
5276
5645
|
if (interruption !== void 0) {
|
|
@@ -5281,7 +5650,7 @@ var JSONCloner = class JSONCloner {
|
|
|
5281
5650
|
this.#terminal = outcome;
|
|
5282
5651
|
return outcome.value;
|
|
5283
5652
|
}
|
|
5284
|
-
const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneJSONValue: failed to create an owned JSON snapshot");
|
|
5653
|
+
const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneJSONValue: failed to create an owned JSON snapshot", { shape: "json" });
|
|
5285
5654
|
this.#fail(error);
|
|
5286
5655
|
}
|
|
5287
5656
|
#fail(error) {
|
|
@@ -5290,7 +5659,7 @@ var JSONCloner = class JSONCloner {
|
|
|
5290
5659
|
throw error;
|
|
5291
5660
|
}
|
|
5292
5661
|
#execute(budget) {
|
|
5293
|
-
if (!INTRINSICS.safe(budget.left)) this.#refuse("cloneJSONValue: invalid node budget");
|
|
5662
|
+
if (!INTRINSICS.safe(budget.left)) this.#refuse("cloneJSONValue: invalid node budget", { shape: "json" });
|
|
5294
5663
|
budget.left = INTRINSICS.min(budget.left, CLONE_NODE_LIMIT);
|
|
5295
5664
|
const root = this.#capture(this.#source, budget);
|
|
5296
5665
|
this.#drain(budget);
|
|
@@ -5320,22 +5689,25 @@ var JSONCloner = class JSONCloner {
|
|
|
5320
5689
|
}
|
|
5321
5690
|
#capture(value, budget) {
|
|
5322
5691
|
budget.left -= 1;
|
|
5323
|
-
if (budget.left < 0) this.#refuse(`cloneJSONValue: snapshot exceeds the node limit ${CLONE_NODE_LIMIT}`,
|
|
5692
|
+
if (budget.left < 0) this.#refuse(`cloneJSONValue: snapshot exceeds the node limit ${CLONE_NODE_LIMIT}`, {
|
|
5693
|
+
shape: "json",
|
|
5694
|
+
limit: CLONE_NODE_LIMIT
|
|
5695
|
+
});
|
|
5324
5696
|
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
5325
5697
|
if (typeof value === "number") {
|
|
5326
5698
|
if (INTRINSICS.finite(value)) return value;
|
|
5327
|
-
this.#
|
|
5699
|
+
this.#refusePath("number is not finite", preview(value));
|
|
5328
5700
|
}
|
|
5329
5701
|
if (typeof value === "object") return this.#captureObject(value);
|
|
5330
|
-
this.#
|
|
5702
|
+
this.#refusePath(this.#pending.length === 0 ? "value is not JSON data" : "property is not JSON data", preview(value));
|
|
5331
5703
|
}
|
|
5332
5704
|
#captureObject(source) {
|
|
5333
|
-
if (matchesVisited(this.#active, source)) this.#
|
|
5705
|
+
if (matchesVisited(this.#active, source)) this.#refusePath("cycle detected", preview(source));
|
|
5334
5706
|
const arrayOutcome = attempt(() => INTRINSICS.array(source));
|
|
5335
|
-
if (isFailure(arrayOutcome)) this.#
|
|
5707
|
+
if (isFailure(arrayOutcome)) this.#refusePath("value brand could not be inspected", preview(source));
|
|
5336
5708
|
if (arrayOutcome.value) return this.#schedule(source, true);
|
|
5337
5709
|
if (isRecord(source)) return this.#schedule(source, false);
|
|
5338
|
-
this.#
|
|
5710
|
+
this.#refusePath("object is not a plain record", preview(source));
|
|
5339
5711
|
}
|
|
5340
5712
|
#schedule(source, array) {
|
|
5341
5713
|
const clone = array ? [] : INTRINSICS.create(null);
|
|
@@ -5351,45 +5723,42 @@ var JSONCloner = class JSONCloner {
|
|
|
5351
5723
|
}
|
|
5352
5724
|
#captureArray(source) {
|
|
5353
5725
|
const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
|
|
5354
|
-
if (isFailure(keysOutcome)) this.#
|
|
5726
|
+
if (isFailure(keysOutcome)) this.#refusePath("own keys could not be inspected", preview(source));
|
|
5355
5727
|
const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
|
|
5356
|
-
if (isFailure(lengthOutcome)) this.#
|
|
5728
|
+
if (isFailure(lengthOutcome)) this.#refusePath("array length could not be inspected", preview(source));
|
|
5357
5729
|
const lengthDescriptor = lengthOutcome.value;
|
|
5358
|
-
if (lengthDescriptor === void 0 || !("value"
|
|
5730
|
+
if (lengthDescriptor === void 0 || !INTRINSICS.own(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refusePath("array is not intrinsic and dense", preview(source));
|
|
5359
5731
|
const owned = collectMembers(keysOutcome.value);
|
|
5360
|
-
if (!matchesMember(owned, "length")) this.#
|
|
5361
|
-
if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#
|
|
5732
|
+
if (!matchesMember(owned, "length")) this.#refusePath("array own keys are not exact", preview(source));
|
|
5733
|
+
if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refusePath("array own keys are not exact", preview(source));
|
|
5362
5734
|
return INTRINSICS.from(iterateIndices(() => lengthDescriptor.value), (index) => {
|
|
5363
5735
|
const key = INTRINSICS.text(index);
|
|
5364
|
-
if (!matchesMember(owned, key)) this.#
|
|
5736
|
+
if (!matchesMember(owned, key)) this.#refusePath("array own keys are not exact", preview(source));
|
|
5365
5737
|
const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
|
|
5366
|
-
if (isFailure(descriptorOutcome)) this.#
|
|
5738
|
+
if (isFailure(descriptorOutcome)) this.#refusePath("array index could not be inspected", "threw", key);
|
|
5367
5739
|
const descriptor = descriptorOutcome.value;
|
|
5368
|
-
if (descriptor === void 0 || !("value"
|
|
5740
|
+
if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value") || descriptor.enumerable !== true) this.#refuseMember("array index is not enumerable data", descriptor, key);
|
|
5369
5741
|
return [key, descriptor.value];
|
|
5370
5742
|
});
|
|
5371
5743
|
}
|
|
5372
5744
|
#captureRecord(source) {
|
|
5373
5745
|
const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
|
|
5374
|
-
if (isFailure(keysOutcome)) this.#
|
|
5746
|
+
if (isFailure(keysOutcome)) this.#refusePath("own keys could not be inspected", preview(source));
|
|
5375
5747
|
const names = keysOutcome.value;
|
|
5376
5748
|
return INTRINSICS.from(iterateIndices(() => names.length), (index) => {
|
|
5377
5749
|
const key = names[index];
|
|
5378
|
-
if (typeof key !== "string") this.#
|
|
5750
|
+
if (typeof key !== "string") this.#refusePath(`record has a symbol property ${preview(key)}`, preview(key));
|
|
5379
5751
|
const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
|
|
5380
|
-
if (isFailure(descriptorOutcome)) this.#
|
|
5752
|
+
if (isFailure(descriptorOutcome)) this.#refusePath("record property could not be inspected", "threw", key);
|
|
5381
5753
|
const descriptor = descriptorOutcome.value;
|
|
5382
|
-
if (descriptor === void 0 || !("value"
|
|
5754
|
+
if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value") || descriptor.enumerable !== true) this.#refuseMember("record property is not enumerable data", descriptor, key);
|
|
5383
5755
|
return [key, descriptor.value];
|
|
5384
5756
|
});
|
|
5385
5757
|
}
|
|
5386
|
-
#create(message,
|
|
5758
|
+
#create(message, context) {
|
|
5387
5759
|
const error = new ContractError(message, {
|
|
5388
5760
|
code: "clone",
|
|
5389
|
-
context
|
|
5390
|
-
shape: "json",
|
|
5391
|
-
...limit === void 0 ? {} : { limit }
|
|
5392
|
-
}
|
|
5761
|
+
context
|
|
5393
5762
|
});
|
|
5394
5763
|
admitVisited(this.#owned, error);
|
|
5395
5764
|
return error;
|
|
@@ -5397,10 +5766,30 @@ var JSONCloner = class JSONCloner {
|
|
|
5397
5766
|
#owns(error) {
|
|
5398
5767
|
return isObject(error) && matchesVisited(this.#owned, error);
|
|
5399
5768
|
}
|
|
5400
|
-
#refuse(message,
|
|
5769
|
+
#refuse(message, context) {
|
|
5401
5770
|
const terminal = this.#terminal;
|
|
5402
5771
|
if (terminal !== void 0 && isFailure(terminal)) throw terminal.error;
|
|
5403
|
-
throw this.#create(message,
|
|
5772
|
+
throw this.#create(message, context);
|
|
5773
|
+
}
|
|
5774
|
+
#refusePath(reason, received, key) {
|
|
5775
|
+
const path = this.#trace(key);
|
|
5776
|
+
this.#refuse(path.length === 0 ? `cloneJSONValue: ${reason}` : `cloneJSONValue: ${reason} at ${renderPath(path)}`, {
|
|
5777
|
+
shape: "json",
|
|
5778
|
+
path,
|
|
5779
|
+
received
|
|
5780
|
+
});
|
|
5781
|
+
}
|
|
5782
|
+
#refuseMember(reason, descriptor, key) {
|
|
5783
|
+
this.#refusePath(reason, descriptor === void 0 ? preview(void 0) : INTRINSICS.own(descriptor, "value") ? preview(descriptor.value) : "accessor", key);
|
|
5784
|
+
}
|
|
5785
|
+
#trace(key) {
|
|
5786
|
+
const pending = this.#pending;
|
|
5787
|
+
const size = pending[pending.length - 1]?.entries === void 0 && key === void 0 ? pending.length - 1 : pending.length;
|
|
5788
|
+
return INTRINSICS.from(iterateIndices(() => size), (index) => {
|
|
5789
|
+
const frame = pending[index];
|
|
5790
|
+
const entry = frame?.entries?.[frame.index - 1];
|
|
5791
|
+
return entry === void 0 ? key ?? "" : entry[0];
|
|
5792
|
+
});
|
|
5404
5793
|
}
|
|
5405
5794
|
static {
|
|
5406
5795
|
INTRINSICS.freeze(JSONCloner.#emptyPending);
|
|
@@ -6065,13 +6454,14 @@ var ShapePass = class ShapePass {
|
|
|
6065
6454
|
for (const keyIndex of iterateIndices(() => keyList.length)) {
|
|
6066
6455
|
const key = keyList[keyIndex];
|
|
6067
6456
|
if (key === void 0) continue;
|
|
6068
|
-
if (key !== "type" && key !== "description" && key !== "default" && key !== "enum" && key !== "minLength" && key !== "maxLength" && key !== "pattern" && key !== "format" && key !== "minimum" && key !== "maximum" && key !== "minItems" && key !== "maxItems" && key !== "items" && key !== "properties" && key !== "required" && key !== "additionalProperties" && key !== "anyOf" && key !== "oneOf") return this.#refuseSchema("validateShape: raw schema contains an unsupported keyword", stack, first, second, key);
|
|
6457
|
+
if (key !== "type" && key !== "description" && key !== "default" && key !== "enum" && key !== "minLength" && key !== "maxLength" && key !== "pattern" && key !== "format" && key !== "minimum" && key !== "maximum" && key !== "minItems" && key !== "maxItems" && key !== "items" && key !== "properties" && key !== "required" && key !== "additionalProperties" && key !== "anyOf" && key !== "oneOf" && key !== "not") return this.#refuseSchema("validateShape: raw schema contains an unsupported keyword", stack, first, second, key);
|
|
6069
6458
|
}
|
|
6070
6459
|
const category = INTRINSICS.own(schema, "type") ? schema.type : void 0;
|
|
6071
6460
|
if (category !== void 0 && category !== "null" && category !== "boolean" && category !== "object" && category !== "array" && category !== "number" && category !== "integer" && category !== "string") return this.#refuseSchema("validateShape: raw schema type is outside the supported vocabulary", stack, first, second, "type");
|
|
6072
6461
|
if (INTRINSICS.own(schema, "description") && schema.description !== void 0 && typeof schema.description !== "string") return this.#refuseSchema("validateShape: raw schema description must be a string", stack, first, second, "description");
|
|
6073
6462
|
if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) return this.#refuseSchema("validateShape: raw schema default must be a JSON value", stack, first, second, "default");
|
|
6074
6463
|
if (INTRINSICS.own(schema, "format") && schema.format !== void 0 && typeof schema.format !== "string") return this.#refuseSchema("validateShape: raw schema format must be a string", stack, first, second, "format");
|
|
6464
|
+
if (INTRINSICS.own(schema, "not") && (!isRecord(schema.not) || INTRINSICS.reflect.members(schema.not).length > 0)) return this.#refuseSchema("validateShape: raw schema not must be the empty schema", stack, first, second, "not");
|
|
6075
6465
|
if (INTRINSICS.own(schema, "pattern") && schema.pattern !== void 0) {
|
|
6076
6466
|
if (typeof schema.pattern !== "string") return this.#refuseSchema("validateShape: raw schema pattern must be a string", stack, first, second, "pattern");
|
|
6077
6467
|
if (isFailure(attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])))) return this.#refuseSchema("validateShape: raw schema pattern must be valid", stack, first, second, "pattern");
|
|
@@ -6799,6 +7189,7 @@ var ShapeCloner = class ShapeCloner {
|
|
|
6799
7189
|
case "nullable": return this.#captureNullable(source, path, budget);
|
|
6800
7190
|
case "json": return this.#captureSimple(source, path, "json");
|
|
6801
7191
|
case "shape": return this.#captureSimple(source, path, "shape");
|
|
7192
|
+
case "function": return this.#captureSimple(source, path, "function");
|
|
6802
7193
|
case "raw": return this.#captureRaw(source, path, budget);
|
|
6803
7194
|
default: throw this.#create("validateShape: every node must be a recognized shape", {
|
|
6804
7195
|
code: "structure",
|
|
@@ -6947,6 +7338,10 @@ var ShapeCloner = class ShapeCloner {
|
|
|
6947
7338
|
category: "shape",
|
|
6948
7339
|
...description === void 0 ? {} : { description }
|
|
6949
7340
|
};
|
|
7341
|
+
if (category === "function") return {
|
|
7342
|
+
category: "function",
|
|
7343
|
+
...description === void 0 ? {} : { description }
|
|
7344
|
+
};
|
|
6950
7345
|
return {
|
|
6951
7346
|
category: "json",
|
|
6952
7347
|
...description === void 0 ? {} : { description }
|
|
@@ -7415,7 +7810,10 @@ var ShapeCloner = class ShapeCloner {
|
|
|
7415
7810
|
*
|
|
7416
7811
|
* @param value - The unknown value to validate and snapshot
|
|
7417
7812
|
* @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
|
|
7418
|
-
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
|
|
7813
|
+
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails; a
|
|
7814
|
+
* refusal that names a member or a container carries its `path` and `received`, and its message
|
|
7815
|
+
* ends with ` at ` and the rendered path, except at the root, where the path is `[]` and the
|
|
7816
|
+
* message has no suffix
|
|
7419
7817
|
*
|
|
7420
7818
|
* @example
|
|
7421
7819
|
* ```ts
|
|
@@ -7440,7 +7838,9 @@ function cloneJSONValue(value) {
|
|
|
7440
7838
|
*
|
|
7441
7839
|
* @param value - The unknown record value to validate and snapshot
|
|
7442
7840
|
* @returns A deeply cloned and frozen JSON record
|
|
7443
|
-
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal
|
|
7841
|
+
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal
|
|
7842
|
+
* fails; a nested refusal is the one {@link cloneJSONValue} raises, `cloneJSONValue:` prefix and path
|
|
7843
|
+
* included
|
|
7444
7844
|
*
|
|
7445
7845
|
* @example
|
|
7446
7846
|
* ```ts
|
|
@@ -7451,7 +7851,11 @@ function cloneJSONRecord(value) {
|
|
|
7451
7851
|
return contain(() => {
|
|
7452
7852
|
if (!isRecord(value)) throw new ContractError("cloneJSONRecord: value is not a plain record", {
|
|
7453
7853
|
code: "clone",
|
|
7454
|
-
context: {
|
|
7854
|
+
context: {
|
|
7855
|
+
shape: "json",
|
|
7856
|
+
path: [],
|
|
7857
|
+
received: preview(value)
|
|
7858
|
+
}
|
|
7455
7859
|
});
|
|
7456
7860
|
const clone = cloneJSONValue(value);
|
|
7457
7861
|
if (!isRecord(clone)) throw new ContractError("cloneJSONRecord: cloned value is not a record", {
|
|
@@ -7554,11 +7958,10 @@ var LazyGuard = class {
|
|
|
7554
7958
|
// src/core/combinators.ts
|
|
7555
7959
|
function arrayOf(elementGuard) {
|
|
7556
7960
|
return (value) => holds(() => {
|
|
7557
|
-
if (!
|
|
7961
|
+
if (!INTRINSICS.array(value)) return false;
|
|
7558
7962
|
const entries = readArrayEntries(value);
|
|
7559
7963
|
if (isFailure(entries) || !entries.value.dense) return false;
|
|
7560
|
-
|
|
7561
|
-
return true;
|
|
7964
|
+
return !INTRINSICS.reflect.apply(INTRINSICS.some, entries.value.entries, [(entry) => !elementGuard(entry)]);
|
|
7562
7965
|
});
|
|
7563
7966
|
}
|
|
7564
7967
|
function tupleOf(...guards) {
|
|
@@ -7886,13 +8289,7 @@ function complementOf(base, excluded) {
|
|
|
7886
8289
|
});
|
|
7887
8290
|
}
|
|
7888
8291
|
function unionOf(...guards) {
|
|
7889
|
-
return (value) =>
|
|
7890
|
-
for (const index of iterateIndices(() => guards.length)) {
|
|
7891
|
-
const guard = guards[index];
|
|
7892
|
-
if (guard !== void 0 && holds(() => guard(value))) return true;
|
|
7893
|
-
}
|
|
7894
|
-
return false;
|
|
7895
|
-
};
|
|
8292
|
+
return (value) => INTRINSICS.reflect.apply(INTRINSICS.some, guards, [(guard) => guard !== void 0 && holds(() => guard(value))]);
|
|
7896
8293
|
}
|
|
7897
8294
|
function intersectionOf(...guards) {
|
|
7898
8295
|
return (value) => holds(() => {
|
|
@@ -8264,7 +8661,7 @@ function parseJSONValue(value) {
|
|
|
8264
8661
|
function parseEnum(value, allowed) {
|
|
8265
8662
|
const outcome = readArrayEntries(allowed);
|
|
8266
8663
|
if (isFailure(outcome) || !outcome.value.dense) return void 0;
|
|
8267
|
-
if (!holds(() =>
|
|
8664
|
+
if (!holds(() => INTRINSICS.reflect.apply(INTRINSICS.some, outcome.value.entries, [(entry) => entry === value || INTRINSICS.same(entry, value)]))) return void 0;
|
|
8268
8665
|
return isLiteralValue(value) ? value : void 0;
|
|
8269
8666
|
}
|
|
8270
8667
|
/**
|
|
@@ -8490,7 +8887,7 @@ var EvaluationScope = class EvaluationScope {
|
|
|
8490
8887
|
const scope = new EvaluationScope();
|
|
8491
8888
|
INTRINSICS.reflect.apply(INTRINSICS.admit, EvaluationScope.#active, [scope]);
|
|
8492
8889
|
try {
|
|
8493
|
-
return
|
|
8890
|
+
return plan(value, path);
|
|
8494
8891
|
} finally {
|
|
8495
8892
|
INTRINSICS.reflect.apply(INTRINSICS.remove, EvaluationScope.#active, [scope]);
|
|
8496
8893
|
}
|
|
@@ -8506,6 +8903,43 @@ var EvaluationScope = class EvaluationScope {
|
|
|
8506
8903
|
return answer;
|
|
8507
8904
|
}
|
|
8508
8905
|
};
|
|
8906
|
+
// src/core/KeyPlanCache.ts
|
|
8907
|
+
/**
|
|
8908
|
+
* Keeps the key plans one compiled closed-object guard learned from the key orders it accepted.
|
|
8909
|
+
*
|
|
8910
|
+
* @remarks
|
|
8911
|
+
* Its constructor takes the declared member guards of one object node. The guard calls the
|
|
8912
|
+
* {@link recall} method before its full walk and the {@link retain} method after a walk that
|
|
8913
|
+
* accepted. The cache learns only through the `retain` method, never evicts, and stops at
|
|
8914
|
+
* {@link KEY_PLAN_LIMIT} plans. Each plan is unfrozen and lives in the `#plans` field alone.
|
|
8915
|
+
* The `retain` method copies the plan list by index through the captured `Array.from`
|
|
8916
|
+
* function, so no array species is consulted.
|
|
8917
|
+
*/
|
|
8918
|
+
var KeyPlanCache = class {
|
|
8919
|
+
#guards;
|
|
8920
|
+
#plans;
|
|
8921
|
+
constructor(guards) {
|
|
8922
|
+
this.#guards = guards;
|
|
8923
|
+
this.#plans = [];
|
|
8924
|
+
}
|
|
8925
|
+
/** Returns the plan kept for a key order, or `undefined` when none answers it. */
|
|
8926
|
+
recall(keys) {
|
|
8927
|
+
const found = INTRINSICS.reflect.apply(INTRINSICS.find, this.#plans, [matchesKeyPlan, keys]);
|
|
8928
|
+
return found === -1 ? void 0 : this.#plans[found];
|
|
8929
|
+
}
|
|
8930
|
+
/** Keeps the plan for an accepted key order while room remains and every key is declared. */
|
|
8931
|
+
retain(keys) {
|
|
8932
|
+
const plans = this.#plans;
|
|
8933
|
+
if (plans.length >= 4 || this.recall(keys) !== void 0) return;
|
|
8934
|
+
const plan = buildKeyPlan(keys, this.#guards);
|
|
8935
|
+
if (plan === void 0) return;
|
|
8936
|
+
const indices = {
|
|
8937
|
+
__proto__: null,
|
|
8938
|
+
length: plans.length + 1
|
|
8939
|
+
};
|
|
8940
|
+
this.#plans = INTRINSICS.from(indices, (_entry, index) => index < plans.length ? plans[index] ?? plan : plan);
|
|
8941
|
+
}
|
|
8942
|
+
};
|
|
8509
8943
|
// src/core/RandomSource.ts
|
|
8510
8944
|
/** Owns the changing state projected by one seeded random function. */
|
|
8511
8945
|
var RandomSource = class {
|
|
@@ -8608,6 +9042,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
8608
9042
|
static #emptyAudits = [];
|
|
8609
9043
|
static #emptyReports = [];
|
|
8610
9044
|
static #emptySeeds = [];
|
|
9045
|
+
static #function = INTRINSICS.freeze(() => void 0);
|
|
8611
9046
|
static {
|
|
8612
9047
|
INTRINSICS.freeze(ContractCompiler.#emptyStack);
|
|
8613
9048
|
INTRINSICS.freeze(ContractCompiler.#emptyNodes);
|
|
@@ -9105,6 +9540,11 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9105
9540
|
...owned.description !== void 0 ? { description: owned.description } : {}
|
|
9106
9541
|
});
|
|
9107
9542
|
case "json": return INTRINSICS.freeze({ ...owned.description !== void 0 ? { description: owned.description } : {} });
|
|
9543
|
+
case "function": return INTRINSICS.freeze({
|
|
9544
|
+
not: INTRINSICS.freeze({}),
|
|
9545
|
+
format: "function",
|
|
9546
|
+
...owned.description !== void 0 ? { description: owned.description } : {}
|
|
9547
|
+
});
|
|
9108
9548
|
case "literal": {
|
|
9109
9549
|
const vocabulary = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(owned.values), [(value) => value !== void 0]);
|
|
9110
9550
|
return INTRINSICS.freeze({
|
|
@@ -9214,13 +9654,18 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9214
9654
|
case "boolean": return isBoolean;
|
|
9215
9655
|
case "null": return isNull;
|
|
9216
9656
|
case "json": return isJSONValue;
|
|
9657
|
+
case "function": return isFunction;
|
|
9217
9658
|
case "shape": return (value) => ContractCompiler.#acceptShape(value);
|
|
9218
9659
|
case "literal": return literalOf(owned.values);
|
|
9219
9660
|
case "array": {
|
|
9220
|
-
const
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9661
|
+
const element = this.#guardAt(owned.items);
|
|
9662
|
+
const withinLength = owned.min === void 0 && owned.max === void 0 ? void 0 : boundsOf(owned.min, owned.max);
|
|
9663
|
+
return (value) => holds(() => {
|
|
9664
|
+
if (!INTRINSICS.array(value)) return false;
|
|
9665
|
+
const read = collectArrayEntries(value);
|
|
9666
|
+
if (!read.dense || !read.exact) return false;
|
|
9667
|
+
return !INTRINSICS.reflect.apply(INTRINSICS.some, read.entries, [(entry) => !element(entry)]) && (withinLength === void 0 || withinLength(read.entries.length));
|
|
9668
|
+
});
|
|
9224
9669
|
}
|
|
9225
9670
|
case "object": {
|
|
9226
9671
|
const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(INTRINSICS.keys(owned.properties)), [(key) => {
|
|
@@ -9243,44 +9688,48 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9243
9688
|
const maskable = required.length <= 31;
|
|
9244
9689
|
const positions = buildPositions(maskable ? required : []);
|
|
9245
9690
|
const full = maskable ? readPresence(required, positions) : 0;
|
|
9691
|
+
const plans = closed ? new KeyPlanCache(map) : void 0;
|
|
9246
9692
|
return (value) => {
|
|
9247
9693
|
if (!isRecord(value)) return false;
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9694
|
+
return holds(() => {
|
|
9695
|
+
const keys = INTRINSICS.keys(value);
|
|
9696
|
+
if (extra !== true && !matchesEnumerableKeys(value, keys)) return false;
|
|
9697
|
+
const plan = plans?.recall(keys);
|
|
9698
|
+
if (plan !== void 0) return INTRINSICS.reflect.apply(INTRINSICS.every, plan, [matchesStepGuard, value]);
|
|
9251
9699
|
if (maskable) {
|
|
9252
9700
|
if (readPresence(keys, positions) !== full) return false;
|
|
9253
9701
|
} else {
|
|
9254
9702
|
const present = collectMembers(keys);
|
|
9255
|
-
|
|
9256
|
-
const key = required[keyIndex];
|
|
9257
|
-
if (key === void 0) continue;
|
|
9258
|
-
if (!matchesMember(present, key)) return false;
|
|
9259
|
-
}
|
|
9703
|
+
if (INTRINSICS.reflect.apply(INTRINSICS.some, required, [(key) => !matchesMember(present, key)])) return false;
|
|
9260
9704
|
}
|
|
9261
|
-
|
|
9262
|
-
const key = keys[keyIndex];
|
|
9263
|
-
if (key === void 0) continue;
|
|
9705
|
+
if (INTRINSICS.reflect.apply(INTRINSICS.some, keys, [(key) => {
|
|
9264
9706
|
const guard = INTRINSICS.own(map, key) ? map[key] : void 0;
|
|
9265
|
-
if (guard !== void 0)
|
|
9266
|
-
|
|
9267
|
-
continue;
|
|
9268
|
-
}
|
|
9269
|
-
if (closed) return false;
|
|
9707
|
+
if (guard !== void 0) return !guard(value[key]);
|
|
9708
|
+
if (closed) return true;
|
|
9270
9709
|
const observed = value[key];
|
|
9271
|
-
|
|
9272
|
-
}
|
|
9710
|
+
return additional !== void 0 && !additional(observed);
|
|
9711
|
+
}])) return false;
|
|
9712
|
+
plans?.retain(keys);
|
|
9273
9713
|
return true;
|
|
9274
9714
|
});
|
|
9275
|
-
return isSuccess(outcome) && outcome.value;
|
|
9276
9715
|
};
|
|
9277
9716
|
}
|
|
9278
9717
|
case "union": {
|
|
9279
9718
|
const guards = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#guardAt(variant)]]);
|
|
9719
|
+
const discriminated = this.#discriminate(owned);
|
|
9280
9720
|
if (owned.mode === "oneOf") return (value) => {
|
|
9721
|
+
const arm = discriminated?.select(value);
|
|
9722
|
+
const named = arm === void 0 ? void 0 : guards[arm];
|
|
9723
|
+
if (named !== void 0) return holds(() => named(value));
|
|
9281
9724
|
return INTRINSICS.reflect.apply(INTRINSICS.fold, guards, [(total, guard) => total + (guard(value) ? 1 : 0), 0]) === 1;
|
|
9282
9725
|
};
|
|
9283
|
-
|
|
9726
|
+
const union = INTRINSICS.reflect.apply(unionOf, void 0, guards);
|
|
9727
|
+
if (discriminated === void 0) return union;
|
|
9728
|
+
return (value) => {
|
|
9729
|
+
const arm = discriminated.select(value);
|
|
9730
|
+
const named = arm === void 0 ? void 0 : guards[arm];
|
|
9731
|
+
return named !== void 0 ? holds(() => named(value)) : union(value);
|
|
9732
|
+
};
|
|
9284
9733
|
}
|
|
9285
9734
|
case "optional": return orOf(isUndefined, this.#guardAt(owned.inner));
|
|
9286
9735
|
case "nullable": return nullableOf(this.#guardAt(owned.inner));
|
|
@@ -9335,6 +9784,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9335
9784
|
case "boolean": return parseBoolean;
|
|
9336
9785
|
case "null": return (value) => value === null ? null : void 0;
|
|
9337
9786
|
case "json": return parseJSONValue;
|
|
9787
|
+
case "function": return (value) => isFunction(value) ? value : void 0;
|
|
9338
9788
|
case "shape": return (value) => ContractCompiler.#acceptShape(value) ? value : void 0;
|
|
9339
9789
|
case "literal": {
|
|
9340
9790
|
const allowed = literalOf(owned.values);
|
|
@@ -9405,33 +9855,32 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9405
9855
|
const present = maskable ? void 0 : collectMembers(keys);
|
|
9406
9856
|
const seen = present === void 0 ? readPresence(keys, positions) : 0;
|
|
9407
9857
|
const selected = [];
|
|
9408
|
-
|
|
9409
|
-
const entry = entries[entryIndex];
|
|
9410
|
-
if (entry === void 0) continue;
|
|
9858
|
+
if (INTRINSICS.reflect.apply(INTRINSICS.some, entries, [(entry, entryIndex) => {
|
|
9411
9859
|
const raw = (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) ? void 0 : record[entry.key];
|
|
9412
9860
|
if (raw === void 0) {
|
|
9413
|
-
if (!entry.optional) return
|
|
9861
|
+
if (!entry.optional) return true;
|
|
9414
9862
|
if (entry.fill !== void 0) {
|
|
9415
9863
|
const fill = isObject(entry.fill) ? cloneJSONValue(entry.fill) : entry.fill;
|
|
9416
9864
|
selected[selected.length] = [entry.key, entry.parse(fill)];
|
|
9417
9865
|
}
|
|
9418
|
-
|
|
9866
|
+
return false;
|
|
9419
9867
|
}
|
|
9420
9868
|
const parsed = entry.parse(raw);
|
|
9421
|
-
if (parsed === void 0) return
|
|
9869
|
+
if (parsed === void 0) return true;
|
|
9422
9870
|
selected[selected.length] = [entry.key, parsed];
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
if (key
|
|
9427
|
-
if (
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
const parsed = additional(record[key]);
|
|
9431
|
-
if (parsed === void 0) return void 0;
|
|
9432
|
-
selected[selected.length] = [key, parsed];
|
|
9871
|
+
return false;
|
|
9872
|
+
}])) return void 0;
|
|
9873
|
+
if (open && INTRINSICS.reflect.apply(INTRINSICS.some, keys, [(key) => {
|
|
9874
|
+
if (matchesMember(known, key)) return false;
|
|
9875
|
+
if (additional === void 0) {
|
|
9876
|
+
selected[selected.length] = [key, record[key]];
|
|
9877
|
+
return false;
|
|
9433
9878
|
}
|
|
9434
|
-
|
|
9879
|
+
const parsed = additional(record[key]);
|
|
9880
|
+
if (parsed === void 0) return true;
|
|
9881
|
+
selected[selected.length] = [key, parsed];
|
|
9882
|
+
return false;
|
|
9883
|
+
}])) return void 0;
|
|
9435
9884
|
return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) }), null);
|
|
9436
9885
|
});
|
|
9437
9886
|
if (isSuccess(outcome)) return outcome.value;
|
|
@@ -9566,6 +10015,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9566
10015
|
expected: "json",
|
|
9567
10016
|
received: preview(value)
|
|
9568
10017
|
}];
|
|
10018
|
+
case "function": return (value, path) => isFunction(value) ? [] : [{
|
|
10019
|
+
reason: "type",
|
|
10020
|
+
path,
|
|
10021
|
+
expected: "function",
|
|
10022
|
+
received: preview(value)
|
|
10023
|
+
}];
|
|
9569
10024
|
case "shape": return (value, path) => ContractCompiler.#acceptShape(value) ? [] : [{
|
|
9570
10025
|
reason: "type",
|
|
9571
10026
|
path,
|
|
@@ -9614,6 +10069,29 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9614
10069
|
appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, INTRINSICS.text(entryIndex))));
|
|
9615
10070
|
}
|
|
9616
10071
|
appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
|
|
10072
|
+
if (entries.value.exact) return limitEntries(faults, 64);
|
|
10073
|
+
const snapshot = entries.value.entries;
|
|
10074
|
+
const members = readValue(() => INTRINSICS.reflect.members(value), "compileAuditor", {
|
|
10075
|
+
subject: "array",
|
|
10076
|
+
context: {
|
|
10077
|
+
path,
|
|
10078
|
+
shape: "array"
|
|
10079
|
+
}
|
|
10080
|
+
});
|
|
10081
|
+
for (const memberIndex of iterateIndices(() => members.length)) {
|
|
10082
|
+
const member = members[memberIndex];
|
|
10083
|
+
if (faults.length >= 64) break;
|
|
10084
|
+
if (isString(member)) {
|
|
10085
|
+
if (!INTRINSICS.own(snapshot, member)) faults[faults.length] = {
|
|
10086
|
+
reason: "extra",
|
|
10087
|
+
path: pathOf(path, member)
|
|
10088
|
+
};
|
|
10089
|
+
} else if (member !== void 0) faults[faults.length] = {
|
|
10090
|
+
reason: "extra",
|
|
10091
|
+
path,
|
|
10092
|
+
symbol: preview(member)
|
|
10093
|
+
};
|
|
10094
|
+
}
|
|
9617
10095
|
return limitEntries(faults, 64);
|
|
9618
10096
|
};
|
|
9619
10097
|
}
|
|
@@ -9665,12 +10143,19 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9665
10143
|
const present = maskable ? void 0 : collectMembers(keys);
|
|
9666
10144
|
const vocabulary = declared ?? collectMembers(declaredKeys);
|
|
9667
10145
|
const seen = present === void 0 ? readPresence(keys, positions) : 0;
|
|
10146
|
+
const listed = present ?? collectMembers(keys);
|
|
10147
|
+
const outside = extra === true ? [] : INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.names(record)), [(name) => !matchesMember(listed, name)]);
|
|
10148
|
+
const concealed = collectMembers(outside);
|
|
9668
10149
|
for (const entryIndex of iterateIndices(() => entries.length)) {
|
|
9669
10150
|
const entry = entries[entryIndex];
|
|
9670
10151
|
if (entry === void 0) continue;
|
|
9671
10152
|
if (faults.length >= 64) return;
|
|
9672
10153
|
if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
|
|
9673
|
-
if (
|
|
10154
|
+
if (matchesMember(concealed, entry.key)) faults[faults.length] = {
|
|
10155
|
+
reason: "hidden",
|
|
10156
|
+
path: pathOf(path, entry.key)
|
|
10157
|
+
};
|
|
10158
|
+
else if (!entry.optional) faults[faults.length] = {
|
|
9674
10159
|
reason: "missing",
|
|
9675
10160
|
path: pathOf(path, entry.key),
|
|
9676
10161
|
expected: entry.kind
|
|
@@ -9694,6 +10179,24 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9694
10179
|
const observed = record[key];
|
|
9695
10180
|
if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
|
|
9696
10181
|
}
|
|
10182
|
+
for (const nameIndex of iterateIndices(() => outside.length)) {
|
|
10183
|
+
const name = outside[nameIndex];
|
|
10184
|
+
if (name === void 0 || matchesMember(vocabulary, name)) continue;
|
|
10185
|
+
if (faults.length >= 64) return;
|
|
10186
|
+
faults[faults.length] = {
|
|
10187
|
+
reason: closed ? "extra" : "hidden",
|
|
10188
|
+
path: pathOf(path, name)
|
|
10189
|
+
};
|
|
10190
|
+
}
|
|
10191
|
+
const symbols = extra === true ? [] : INTRINSICS.symbols(record);
|
|
10192
|
+
for (const symbolIndex of iterateIndices(() => symbols.length)) {
|
|
10193
|
+
if (faults.length >= 64) return;
|
|
10194
|
+
faults[faults.length] = {
|
|
10195
|
+
reason: "extra",
|
|
10196
|
+
path,
|
|
10197
|
+
symbol: preview(symbols[symbolIndex])
|
|
10198
|
+
};
|
|
10199
|
+
}
|
|
9697
10200
|
});
|
|
9698
10201
|
if (isFailure(outcome)) {
|
|
9699
10202
|
if (isContractError(outcome.error)) throw outcome.error;
|
|
@@ -9853,6 +10356,12 @@ var ContractCompiler = class ContractCompiler {
|
|
|
9853
10356
|
expected: "json",
|
|
9854
10357
|
received: preview(value)
|
|
9855
10358
|
}];
|
|
10359
|
+
case "function": return (value, path) => isFunction(value) ? [] : [{
|
|
10360
|
+
reason: "type",
|
|
10361
|
+
path,
|
|
10362
|
+
expected: "function",
|
|
10363
|
+
received: preview(value)
|
|
10364
|
+
}];
|
|
9856
10365
|
case "literal": {
|
|
9857
10366
|
const allowed = literalOf(owned.values);
|
|
9858
10367
|
return (value, path) => allowed(value) || isString(value) && allowed(value.trim()) ? [] : [{
|
|
@@ -10123,6 +10632,7 @@ var ContractCompiler = class ContractCompiler {
|
|
|
10123
10632
|
}
|
|
10124
10633
|
case "boolean": return (random) => drawRandom(random, "boolean") >= .5;
|
|
10125
10634
|
case "null": return () => null;
|
|
10635
|
+
case "function": return () => ContractCompiler.#function;
|
|
10126
10636
|
case "shape": return () => ({
|
|
10127
10637
|
category: "object",
|
|
10128
10638
|
properties: {},
|
|
@@ -10623,7 +11133,7 @@ var ValueInferer = class ValueInferer {
|
|
|
10623
11133
|
const outcome = attempt(() => {
|
|
10624
11134
|
const snapshot = readArrayEntries(value);
|
|
10625
11135
|
if (isFailure(snapshot)) throw snapshot.error;
|
|
10626
|
-
if (!snapshot.value.dense) return void 0;
|
|
11136
|
+
if (!snapshot.value.dense || !snapshot.value.exact) return void 0;
|
|
10627
11137
|
const entries = snapshot.value.entries;
|
|
10628
11138
|
const length = INTRINSICS.ceil(INTRINSICS.min(entries.length, this.#breadth));
|
|
10629
11139
|
return INTRINSICS.from(iterateIndices(() => length), (index) => this.#infer(entries[index], depth - 1));
|
|
@@ -10666,10 +11176,11 @@ var ValueInferer = class ValueInferer {
|
|
|
10666
11176
|
const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
|
|
10667
11177
|
const required = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
|
|
10668
11178
|
const dropped = INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.key !== void 0 && entry.schema === void 0]);
|
|
11179
|
+
const hidden = !matchesEnumerableKeys(value, snapshot);
|
|
10669
11180
|
return {
|
|
10670
11181
|
properties,
|
|
10671
11182
|
required,
|
|
10672
|
-
partial: truncated || dropped
|
|
11183
|
+
partial: truncated || dropped || hidden
|
|
10673
11184
|
};
|
|
10674
11185
|
});
|
|
10675
11186
|
omitVisited(this.#visited, value);
|
|
@@ -10766,12 +11277,16 @@ var SampleInferer = class {
|
|
|
10766
11277
|
const signature = `${depth}|${this.#breadth}|${this.#closed}|${this.#format}|${this.#enumerated}`;
|
|
10767
11278
|
const cached = INTRINSICS.reflect.apply(INTRINSICS.fetch, node.schemas, [signature]);
|
|
10768
11279
|
if (cached !== void 0) return cached;
|
|
10769
|
-
const
|
|
11280
|
+
const listings = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(samples), [(sample) => {
|
|
10770
11281
|
if (sample === void 0) throw new INTRINSICS.error("samplesToSchema: every sample must be a record");
|
|
10771
11282
|
const sampleKeys = enumerableKeys(sample);
|
|
10772
11283
|
if (sampleKeys === void 0) throw new INTRINSICS.error("samplesToSchema: property enumeration failed");
|
|
10773
|
-
return
|
|
11284
|
+
return {
|
|
11285
|
+
keys: sampleKeys,
|
|
11286
|
+
hidden: !matchesEnumerableKeys(sample, sampleKeys)
|
|
11287
|
+
};
|
|
10774
11288
|
}]);
|
|
11289
|
+
const keyPairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(listings), [(listing) => INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(listing.keys), [(key) => [key, true]])]);
|
|
10775
11290
|
const keySet = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [keyPairs]) });
|
|
10776
11291
|
const allKeys = sortValues(INTRINSICS.keys(keySet));
|
|
10777
11292
|
const keys = limitEntries(allKeys, this.#breadth);
|
|
@@ -10812,7 +11327,7 @@ var SampleInferer = class {
|
|
|
10812
11327
|
const pairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.key === void 0 || column.schema === void 0 ? [] : [[column.key, column.schema]]]);
|
|
10813
11328
|
const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
|
|
10814
11329
|
const required = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.required && column.key !== void 0 ? [column.key] : []]);
|
|
10815
|
-
const partial = truncated || INTRINSICS.reflect.apply(INTRINSICS.some, columns, [(column) => column.dropped]);
|
|
11330
|
+
const partial = truncated || INTRINSICS.reflect.apply(INTRINSICS.some, columns, [(column) => column.dropped]) || INTRINSICS.reflect.apply(INTRINSICS.some, listings, [(listing) => listing.hidden]);
|
|
10816
11331
|
const schema = {
|
|
10817
11332
|
type: "object",
|
|
10818
11333
|
...INTRINSICS.keys(properties).length > 0 ? { properties } : {},
|
|
@@ -11032,7 +11547,11 @@ function inferPrimitiveEnum(values, limit) {
|
|
|
11032
11547
|
* throws a `structure`
|
|
11033
11548
|
* {@link ContractError}; it never becomes `{}` or another permissive schema. Nested
|
|
11034
11549
|
* objects close to unknown keys (`additionalProperties: false`) by default;
|
|
11035
|
-
* pass `closed: false` to open them.
|
|
11550
|
+
* pass `closed: false` to open them. A record whose sampled keys are not every
|
|
11551
|
+
* key it owns stays open whatever `closed` says: one truncated by the breadth
|
|
11552
|
+
* budget, one holding a member that is `undefined`, and one holding a
|
|
11553
|
+
* non-enumerable string key or a symbol key, because a closed schema would refuse
|
|
11554
|
+
* the record it was inferred from. `format` (default `false`) opts a
|
|
11036
11555
|
* string/`Date` leaf into the `format` keyword. Structurally-equal inputs
|
|
11037
11556
|
* infer byte-identical schemas (object keys and `anyOf` members are sorted).
|
|
11038
11557
|
*
|
|
@@ -11090,7 +11609,10 @@ function valueToSchema(value, options) {
|
|
|
11090
11609
|
* An empty `samples` array infers the empty accept-anything schema `{}`.
|
|
11091
11610
|
* When every sample is a plain record, properties/required are unified
|
|
11092
11611
|
* per-key across all samples — a key
|
|
11093
|
-
* required iff present and non-`undefined` in every sample.
|
|
11612
|
+
* required iff present and non-`undefined` in every sample. The unified object
|
|
11613
|
+
* stays open whatever `closed` says when the key union is truncated, or when any
|
|
11614
|
+
* sample holds a member that is `undefined`, a non-enumerable string key, or a
|
|
11615
|
+
* symbol key. When any sample is not a plain record, the
|
|
11094
11616
|
* slot is inferred one value at a time (independent {@link valueToSchema}
|
|
11095
11617
|
* per sample, unified with {@link unifySchemas} — the same de-duplication and
|
|
11096
11618
|
* `anyOf` ordering an array's element schemas receive). `format`
|
|
@@ -11286,6 +11808,10 @@ var SchemaShaper = class SchemaShaper {
|
|
|
11286
11808
|
});
|
|
11287
11809
|
}
|
|
11288
11810
|
#inspect(schema) {
|
|
11811
|
+
if (INTRINSICS.own(schema, "not")) {
|
|
11812
|
+
this.#inspectFunction(schema);
|
|
11813
|
+
return;
|
|
11814
|
+
}
|
|
11289
11815
|
const keys = INTRINSICS.keys(schema);
|
|
11290
11816
|
for (const index of iterateIndices(() => keys.length)) {
|
|
11291
11817
|
const key = keys[index];
|
|
@@ -11320,33 +11846,46 @@ var SchemaShaper = class SchemaShaper {
|
|
|
11320
11846
|
this.#inspectRange(schema, this.#names(effective, "integer"));
|
|
11321
11847
|
this.#inspectObject(schema);
|
|
11322
11848
|
}
|
|
11323
|
-
#
|
|
11324
|
-
const
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
for (const index of iterateIndices(() => texts.length)) {
|
|
11332
|
-
const keyword = texts[index];
|
|
11333
|
-
if (keyword === void 0) continue;
|
|
11334
|
-
const value = INTRINSICS.own(schema, keyword) ? INTRINSICS.reflect.read(schema, keyword) : void 0;
|
|
11335
|
-
if (value !== void 0 && !isString(value)) throw this.#refusal(`${keyword} must be a string`, keyword);
|
|
11849
|
+
#inspectFunction(schema) {
|
|
11850
|
+
const operand = schema.not;
|
|
11851
|
+
if (!isRecord(operand) || INTRINSICS.reflect.members(operand).length > 0 || !INTRINSICS.own(schema, "format") || schema.format !== "function") throw this.#refusal("a strict conversion reads not only as the empty schema beside format function", "not");
|
|
11852
|
+
const keys = INTRINSICS.keys(schema);
|
|
11853
|
+
for (const index of iterateIndices(() => keys.length)) {
|
|
11854
|
+
const key = keys[index];
|
|
11855
|
+
if (key === void 0) continue;
|
|
11856
|
+
if (!(key === "not" || key === "format" || key === "default" || INTRINSICS.reflect.apply(INTRINSICS.some, SCHEMA_ANNOTATIONS, [(keyword) => keyword === key]))) throw this.#refusal("a function schema reads no assertion beside not", key);
|
|
11336
11857
|
}
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
const keyword = flags[index];
|
|
11858
|
+
this.#inspectAnnotations(schema);
|
|
11859
|
+
if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) throw this.#refusal("a default must be a JSON value", "default");
|
|
11860
|
+
}
|
|
11861
|
+
#inspectAnnotations(schema) {
|
|
11862
|
+
for (const index of iterateIndices(() => SCHEMA_ANNOTATIONS.length)) {
|
|
11863
|
+
const keyword = SCHEMA_ANNOTATIONS[index];
|
|
11344
11864
|
if (keyword === void 0) continue;
|
|
11345
11865
|
const value = INTRINSICS.own(schema, keyword) ? INTRINSICS.reflect.read(schema, keyword) : void 0;
|
|
11346
|
-
if (value
|
|
11866
|
+
if (value === void 0) continue;
|
|
11867
|
+
switch (keyword) {
|
|
11868
|
+
case "title":
|
|
11869
|
+
case "description":
|
|
11870
|
+
case "$schema":
|
|
11871
|
+
case "$id":
|
|
11872
|
+
case "$comment":
|
|
11873
|
+
if (!isString(value)) throw this.#refusal(`${keyword} must be a string`, keyword);
|
|
11874
|
+
break;
|
|
11875
|
+
case "deprecated":
|
|
11876
|
+
case "readOnly":
|
|
11877
|
+
case "writeOnly":
|
|
11878
|
+
if (!isBoolean(value)) throw this.#refusal(`${keyword} must be a boolean`, keyword);
|
|
11879
|
+
break;
|
|
11880
|
+
case "examples":
|
|
11881
|
+
if (!isArray(value)) throw this.#refusal("examples must be an array", keyword);
|
|
11882
|
+
break;
|
|
11883
|
+
default: {
|
|
11884
|
+
const unchecked = keyword;
|
|
11885
|
+
throw this.#refusal("an annotation has no value check", unchecked);
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11347
11888
|
}
|
|
11348
|
-
const examples = INTRINSICS.own(schema, "examples") ? INTRINSICS.reflect.read(schema, "examples") : void 0;
|
|
11349
|
-
if (examples !== void 0 && !isArray(examples)) throw this.#refusal("examples must be an array", "examples");
|
|
11350
11889
|
}
|
|
11351
11890
|
#inspectType(schema) {
|
|
11352
11891
|
const declared = INTRINSICS.own(schema, "type") ? schema.type : void 0;
|
|
@@ -11439,6 +11978,7 @@ var SchemaShaper = class SchemaShaper {
|
|
|
11439
11978
|
this.#built += 1;
|
|
11440
11979
|
const description = INTRINSICS.own(schema, "description") && isString(schema.description) ? schema.description : void 0;
|
|
11441
11980
|
if (INTRINSICS.own(schema, "$ref")) return this.#widen("a reference is not resolved", description, "$ref");
|
|
11981
|
+
if (this.#strict && INTRINSICS.own(schema, "not")) return functionShape(description === void 0 ? void 0 : { description });
|
|
11442
11982
|
if (INTRINSICS.own(schema, "enum") && isArray(schema.enum)) {
|
|
11443
11983
|
const observed = INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"])[index]);
|
|
11444
11984
|
if (INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry !== null && (!isLiteralValue(entry) || typeof entry === "number" && !isFiniteNumber(entry))])) return this.#widen("an enum entry has no literal form", description, "enum");
|
|
@@ -11665,6 +12205,13 @@ var FaultShaper = class FaultShaper {
|
|
|
11665
12205
|
}), objectShape({
|
|
11666
12206
|
reason: literalShape(["extra"]),
|
|
11667
12207
|
path
|
|
12208
|
+
}), objectShape({
|
|
12209
|
+
reason: literalShape(["extra"]),
|
|
12210
|
+
path,
|
|
12211
|
+
symbol: stringShape()
|
|
12212
|
+
}), objectShape({
|
|
12213
|
+
reason: literalShape(["hidden"]),
|
|
12214
|
+
path
|
|
11668
12215
|
}));
|
|
11669
12216
|
}
|
|
11670
12217
|
static {
|
|
@@ -12133,9 +12680,9 @@ function recordShape(values, options) {
|
|
|
12133
12680
|
* @remarks
|
|
12134
12681
|
* When every arm is an object declaring one required literal property, and a value's
|
|
12135
12682
|
* own property exactly equals a literal only one arm holds, that arm answers: `explain`
|
|
12136
|
-
* and `audit` report its faults at their real paths,
|
|
12137
|
-
* alone. Any other value reports `variant`, with `key`
|
|
12138
|
-
* have named an arm.
|
|
12683
|
+
* and `audit` report its faults at their real paths, `parse` repairs through it
|
|
12684
|
+
* alone, and `is` answers from it alone. Any other value reports `variant`, with `key`
|
|
12685
|
+
* and `expected` saying what would have named an arm.
|
|
12139
12686
|
*
|
|
12140
12687
|
* @param variants - The candidate shapes; the first match wins at runtime
|
|
12141
12688
|
* @returns A union shape whose `Infer` is the union of the variants
|
|
@@ -12164,7 +12711,8 @@ function unionShape(...variants) {
|
|
|
12164
12711
|
* - **Guard**: accepts the value only when exactly one variant's guard
|
|
12165
12712
|
* accepts it. A value matching two-or-more variants — which would violate
|
|
12166
12713
|
* the emitted `oneOf` schema — is rejected, even though it would pass
|
|
12167
|
-
* {@link unionShape}'s guard.
|
|
12714
|
+
* {@link unionShape}'s guard. A value that names one arm through a required
|
|
12715
|
+
* literal is answered by that arm's guard alone.
|
|
12168
12716
|
* - **Parser**: judged on the RAW input's guard matches only, with NO
|
|
12169
12717
|
* coercion fallback for an ambiguous input. When exactly one variant's
|
|
12170
12718
|
* guard accepts the raw value, the input itself is returned. Zero matches or
|
|
@@ -12328,6 +12876,32 @@ function shapeShape(options) {
|
|
|
12328
12876
|
}, "shapeShape");
|
|
12329
12877
|
}
|
|
12330
12878
|
/**
|
|
12879
|
+
* Builds a {@link FunctionShape}.
|
|
12880
|
+
*
|
|
12881
|
+
* @remarks
|
|
12882
|
+
* The guard accepts every callable and checks no arity: TypeScript admits a callback that
|
|
12883
|
+
* declares fewer parameters than its type, and `Function.length` undercounts rest and
|
|
12884
|
+
* defaulted parameters.
|
|
12885
|
+
*
|
|
12886
|
+
* @param options - Optional description
|
|
12887
|
+
* @returns A function-valued declaration
|
|
12888
|
+
*
|
|
12889
|
+
* @example
|
|
12890
|
+
* ```ts
|
|
12891
|
+
* const options = objectShape({ upgrade: optionalShape(functionShape()) })
|
|
12892
|
+
* ```
|
|
12893
|
+
*/
|
|
12894
|
+
function functionShape(options) {
|
|
12895
|
+
return contain(() => {
|
|
12896
|
+
const safe = readOptions(options, ["description"], "functionShape", "function");
|
|
12897
|
+
const shape = {
|
|
12898
|
+
category: "function",
|
|
12899
|
+
...safe?.description === void 0 ? {} : { description: safe.description }
|
|
12900
|
+
};
|
|
12901
|
+
return ShapePass.seal(shape);
|
|
12902
|
+
}, "functionShape");
|
|
12903
|
+
}
|
|
12904
|
+
/**
|
|
12331
12905
|
* Builds a {@link RawShape} from a supported JSON Schema fragment.
|
|
12332
12906
|
*
|
|
12333
12907
|
* @remarks
|
|
@@ -12441,7 +13015,8 @@ function rawShape(schema) {
|
|
|
12441
13015
|
*
|
|
12442
13016
|
* STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
|
|
12443
13017
|
* code `structure`, every node the lenient walk would widen, every keyword it
|
|
12444
|
-
* would ignore (`pattern`, every `format` but `'date'` on a string node
|
|
13018
|
+
* would ignore (`pattern`, every `format` but `'date'` on a string node and `'function'` in
|
|
13019
|
+
* the function leaf, every `not` outside that leaf, `nullable`,
|
|
12445
13020
|
* `patternProperties`, `propertyNames`, `prefixItems`, and anything else outside
|
|
12446
13021
|
* {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
|
|
12447
13022
|
* that is neither a finite primitive nor `null`, a contradictory bound, a date format whose
|
|
@@ -12452,7 +13027,9 @@ function rawShape(schema) {
|
|
|
12452
13027
|
* every keyword that could keep two arms apart. Below a `oneOf` that object refuses
|
|
12453
13028
|
* instead, since closing it could change which arms match. A strict conversion is the
|
|
12454
13029
|
* one walk that asserts a `format`: it reads `format: 'date'` on a string node as a
|
|
12455
|
-
* date string shape, so a compiled {@link dateShape} round-trips
|
|
13030
|
+
* date string shape, so a compiled {@link dateShape} round-trips, and it reads the function
|
|
13031
|
+
* leaf `{ not: {}, format: 'function' }` back as {@link functionShape}, so a compiled
|
|
13032
|
+
* function shape round-trips too.
|
|
12456
13033
|
*
|
|
12457
13034
|
* @param schema - The JSON Schema value to convert
|
|
12458
13035
|
* @param options - Optional `strict`, default `false`
|
|
@@ -12521,10 +13098,12 @@ exports.INFER_ENUM_LIMIT = INFER_ENUM_LIMIT;
|
|
|
12521
13098
|
exports.INTRINSICS = INTRINSICS;
|
|
12522
13099
|
exports.JSONCloner = JSONCloner;
|
|
12523
13100
|
exports.JSON_SCHEMA_TYPES = JSON_SCHEMA_TYPES;
|
|
13101
|
+
exports.KEY_PLAN_LIMIT = KEY_PLAN_LIMIT;
|
|
12524
13102
|
exports.NAME_LIMIT = NAME_LIMIT;
|
|
12525
13103
|
exports.NODE_LIMIT = NODE_LIMIT;
|
|
12526
13104
|
exports.PRESENCE_MASK_LIMIT = PRESENCE_MASK_LIMIT;
|
|
12527
13105
|
exports.PREVIEW_LIMIT = PREVIEW_LIMIT;
|
|
13106
|
+
exports.SCHEMA_ANNOTATIONS = SCHEMA_ANNOTATIONS;
|
|
12528
13107
|
exports.SHAPE_FIELDS = SHAPE_FIELDS;
|
|
12529
13108
|
exports.STRICT_SCHEMA_KEYWORDS = STRICT_SCHEMA_KEYWORDS;
|
|
12530
13109
|
exports.STRING_LIMIT = STRING_LIMIT;
|
|
@@ -12544,7 +13123,9 @@ exports.auditFaultShape = auditFaultShape;
|
|
|
12544
13123
|
exports.booleanShape = booleanShape;
|
|
12545
13124
|
exports.boundsOf = boundsOf;
|
|
12546
13125
|
exports.buildArrayFaults = buildArrayFaults;
|
|
13126
|
+
exports.buildKeyPlan = buildKeyPlan;
|
|
12547
13127
|
exports.buildNumberFaults = buildNumberFaults;
|
|
13128
|
+
exports.buildPathKey = buildPathKey;
|
|
12548
13129
|
exports.buildPositions = buildPositions;
|
|
12549
13130
|
exports.buildSampleMemo = buildSampleMemo;
|
|
12550
13131
|
exports.buildStringFaults = buildStringFaults;
|
|
@@ -12554,6 +13135,7 @@ exports.cloneJSONRecord = cloneJSONRecord;
|
|
|
12554
13135
|
exports.cloneJSONValue = cloneJSONValue;
|
|
12555
13136
|
exports.cloneSchema = cloneSchema;
|
|
12556
13137
|
exports.cloneShape = cloneShape;
|
|
13138
|
+
exports.collectArrayEntries = collectArrayEntries;
|
|
12557
13139
|
exports.collectEntries = collectEntries;
|
|
12558
13140
|
exports.collectMembers = collectMembers;
|
|
12559
13141
|
exports.comparePrimitives = comparePrimitives;
|
|
@@ -12585,6 +13167,8 @@ exports.extractForms = extractForms;
|
|
|
12585
13167
|
exports.extractPath = extractPath;
|
|
12586
13168
|
exports.extractSchema = extractSchema;
|
|
12587
13169
|
exports.failure = failure;
|
|
13170
|
+
exports.filterUncoveredFaults = filterUncoveredFaults;
|
|
13171
|
+
exports.functionShape = functionShape;
|
|
12588
13172
|
exports.holds = holds;
|
|
12589
13173
|
exports.inferPrimitiveEnum = inferPrimitiveEnum;
|
|
12590
13174
|
exports.instanceOf = instanceOf;
|
|
@@ -12677,14 +13261,18 @@ exports.literalShape = literalShape;
|
|
|
12677
13261
|
exports.mapOf = mapOf;
|
|
12678
13262
|
exports.matchOf = matchOf;
|
|
12679
13263
|
exports.matchesCalendarDate = matchesCalendarDate;
|
|
13264
|
+
exports.matchesEnumerableKeys = matchesEnumerableKeys;
|
|
12680
13265
|
exports.matchesExactKeys = matchesExactKeys;
|
|
12681
13266
|
exports.matchesISOInstant = matchesISOInstant;
|
|
12682
13267
|
exports.matchesJSONDepth = matchesJSONDepth;
|
|
12683
13268
|
exports.matchesJSONValue = matchesJSONValue;
|
|
13269
|
+
exports.matchesKeyPlan = matchesKeyPlan;
|
|
12684
13270
|
exports.matchesLosslessRepair = matchesLosslessRepair;
|
|
12685
13271
|
exports.matchesMember = matchesMember;
|
|
12686
13272
|
exports.matchesPattern = matchesPattern;
|
|
12687
13273
|
exports.matchesRecordBrand = matchesRecordBrand;
|
|
13274
|
+
exports.matchesStepGuard = matchesStepGuard;
|
|
13275
|
+
exports.matchesStepKey = matchesStepKey;
|
|
12688
13276
|
exports.matchesStringLength = matchesStringLength;
|
|
12689
13277
|
exports.matchesUndefinedField = matchesUndefinedField;
|
|
12690
13278
|
exports.matchesVisited = matchesVisited;
|
|
@@ -12749,6 +13337,7 @@ exports.refuseOptionKeys = refuseOptionKeys;
|
|
|
12749
13337
|
exports.renderForm = renderForm;
|
|
12750
13338
|
exports.renderList = renderList;
|
|
12751
13339
|
exports.renderPath = renderPath;
|
|
13340
|
+
exports.repairValue = repairValue;
|
|
12752
13341
|
exports.resolveField = resolveField;
|
|
12753
13342
|
exports.retainDepth = retainDepth;
|
|
12754
13343
|
exports.samplesToFormat = samplesToFormat;
|