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