@orkestrel/contract 0.0.22 → 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.
@@ -13,6 +13,7 @@ var SHAPE_FIELDS = Object.freeze({
13
13
  "min",
14
14
  "max",
15
15
  "pattern",
16
+ "date",
16
17
  "description"
17
18
  ]),
18
19
  number: Object.freeze([
@@ -44,7 +45,8 @@ var SHAPE_FIELDS = Object.freeze({
44
45
  nullable: Object.freeze(["inner"]),
45
46
  json: Object.freeze(["description"]),
46
47
  raw: Object.freeze(["schema"]),
47
- shape: Object.freeze(["description"])
48
+ shape: Object.freeze(["description"]),
49
+ function: Object.freeze(["description"])
48
50
  });
49
51
  /**
50
52
  * Holds the registry-global key used to recognize {@link ContractError} values
@@ -150,6 +152,8 @@ var INTRINSICS = Object.freeze({
150
152
  prototype: Object.getPrototypeOf,
151
153
  /** Captures `Object.getOwnPropertySymbols` — the own-symbol population. */
152
154
  symbols: Object.getOwnPropertySymbols,
155
+ /** Captures `Object.getOwnPropertyNames` — the own string-key population, enumerable or not. */
156
+ names: Object.getOwnPropertyNames,
153
157
  /** Captures `Object.prototype` — the realm-local plain-record prototype identity. */
154
158
  base: Object.prototype,
155
159
  /**
@@ -237,6 +241,8 @@ var INTRINSICS = Object.freeze({
237
241
  order: Array.prototype.sort,
238
242
  /** Captures `Array.prototype.some` for short-circuit membership checks. */
239
243
  some: Array.prototype.some,
244
+ /** Captures `Array.prototype.every` for short-circuit checks that every entry passes. */
245
+ every: Array.prototype.every,
240
246
  /** Captures `Array.prototype.findIndex`, including reads of sparse positions. */
241
247
  find: Array.prototype.findIndex,
242
248
  /** Captures `Array.prototype.forEach` for indexed visits of owned arrays. */
@@ -342,32 +348,50 @@ var JSON_SCHEMA_TYPES = Object.freeze([
342
348
  "string"
343
349
  ]);
344
350
  /**
345
- * Lists the JSON Schema keywords a strict `schemaToShape` conversion reads, frozen.
351
+ * Lists the JSON Schema annotations a strict `schemaToShape` conversion admits on any node, frozen.
346
352
  *
347
353
  * @remarks
348
- * The keywords a shape can honour, plus the annotations that assert nothing and so
349
- * lose nothing when a shape drops them: `title`, `$schema`, `$id`, `$comment`,
350
- * `examples`, `deprecated`, `readOnly`, and `writeOnly`. Every other keyword refuses.
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.
354
+ * Each asserts nothing about a value, so a converted shape drops it without loss, except
355
+ * `description`, which the shape keeps. A strict conversion admits them beside every
356
+ * keyword it reads, the function leaf `{ not: {}, format: 'function' }` included.
353
357
  *
354
358
  * @example
355
359
  * ```ts
356
- * STRICT_SCHEMA_KEYWORDS.includes('title') // true
357
- * STRICT_SCHEMA_KEYWORDS.includes('pattern') // false
360
+ * SCHEMA_ANNOTATIONS.includes('title') // true
361
+ * SCHEMA_ANNOTATIONS.at(-1) // 'examples'
358
362
  * ```
359
363
  */
360
- var STRICT_SCHEMA_KEYWORDS = Object.freeze([
361
- "type",
364
+ var SCHEMA_ANNOTATIONS = Object.freeze([
362
365
  "title",
363
366
  "description",
364
367
  "$schema",
365
368
  "$id",
366
369
  "$comment",
367
- "examples",
368
370
  "deprecated",
369
371
  "readOnly",
370
372
  "writeOnly",
373
+ "examples"
374
+ ]);
375
+ /**
376
+ * Lists the JSON Schema keywords a strict `schemaToShape` conversion reads, frozen.
377
+ *
378
+ * @remarks
379
+ * The keywords a shape can honour, plus {@link SCHEMA_ANNOTATIONS}. Every other keyword
380
+ * refuses. `pattern`, `format`, and `not` are absent because no compiled shape asserts
381
+ * them, so a schema holding one would convert to a shape wider than the schema it came
382
+ * from. The exceptions are `format: 'date'` on a string node, which a strict conversion
383
+ * reads as a date string shape, and the function leaf `{ not: {}, format: 'function' }`,
384
+ * which it reads as a function shape.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * STRICT_SCHEMA_KEYWORDS.includes('title') // true
389
+ * STRICT_SCHEMA_KEYWORDS.includes('pattern') // false
390
+ * ```
391
+ */
392
+ var STRICT_SCHEMA_KEYWORDS = Object.freeze([
393
+ "type",
394
+ ...SCHEMA_ANNOTATIONS,
371
395
  "default",
372
396
  "enum",
373
397
  "minLength",
@@ -429,6 +453,7 @@ var CONTRACT_CODES = Object.freeze([
429
453
  */
430
454
  var FAULT_KINDS = Object.freeze([
431
455
  "string",
456
+ "date",
432
457
  "number",
433
458
  "integer",
434
459
  "boolean",
@@ -438,7 +463,8 @@ var FAULT_KINDS = Object.freeze([
438
463
  "object",
439
464
  "union",
440
465
  "json",
441
- "shape"
466
+ "shape",
467
+ "function"
442
468
  ]);
443
469
  /**
444
470
  * Lists every {@link FaultConstraint}, frozen.
@@ -455,6 +481,7 @@ var FAULT_CONSTRAINTS = Object.freeze([
455
481
  "min",
456
482
  "max",
457
483
  "pattern",
484
+ "date",
458
485
  "integer"
459
486
  ]);
460
487
  /**
@@ -472,12 +499,14 @@ var FAULT_CONSTRAINTS = Object.freeze([
472
499
  */
473
500
  var FAULT_LIMIT = 64;
474
501
  /**
475
- * Caps at `64` the character length of a {@link preview}-rendered string, frozen.
502
+ * Caps at `64` the length in UTF-16 code units of every {@link preview} result, frozen.
476
503
  *
477
504
  * @remarks
478
- * A previewed string longer than this is clipped with a trailing `…` so a
505
+ * The cap covers the whole preview, its quotes, its trailing `…`, and a
506
+ * bigint's `n` included, for every input. A longer rendering is clipped with `…`, so a
479
507
  * {@link Fault}'s `received` field never embeds an unbounded amount of
480
- * untrusted text.
508
+ * untrusted text, and the {@link describeFaultLine} function prints it as
509
+ * written.
481
510
  */
482
511
  var PREVIEW_LIMIT = 64;
483
512
  /**
@@ -572,6 +601,25 @@ var COMPILE_NODE_LIMIT = 16384;
572
601
  */
573
602
  var PRESENCE_MASK_LIMIT = 31;
574
603
  /**
604
+ * Caps at `4` the number of key plans one compiled closed-object guard keeps, frozen.
605
+ *
606
+ * @remarks
607
+ * A compiled closed-object guard answers a value through the full key walk and,
608
+ * after a walk that accepts, keeps that value's key order as a plan: one
609
+ * {@link KeyStep} entry per key, in order. A later value whose own enumerable keys
610
+ * arrive in a kept order is answered by asking each step's guard in turn, with
611
+ * no presence or vocabulary question. The guard learns only from an accepted
612
+ * walk, never evicts, and stops learning at this count, so the plans it keeps
613
+ * are those of the earliest accepted key orders. Every other key order takes the
614
+ * full walk. Both paths answer identically; only the cost differs.
615
+ *
616
+ * @example
617
+ * ```ts
618
+ * KEY_PLAN_LIMIT // 4
619
+ * ```
620
+ */
621
+ var KEY_PLAN_LIMIT = 4;
622
+ /**
575
623
  * Caps at `262144` the number of nodes one JSON snapshot may produce, frozen.
576
624
  *
577
625
  * @remarks
@@ -678,6 +726,19 @@ var FORMAT_PATTERNS = Object.freeze({
678
726
  uri: /^[a-z][a-z0-9+.-]*:\/\//i
679
727
  });
680
728
  /**
729
+ * Holds `10`, the length of every `YYYY-MM-DD` date a date string shape admits.
730
+ *
731
+ * @remarks
732
+ * A date string shape whose `min` or `max` excludes this length admits no value, so
733
+ * building one refuses with code `range`.
734
+ *
735
+ * @example
736
+ * ```ts
737
+ * DATE_LENGTH // 10
738
+ * ```
739
+ */
740
+ var DATE_LENGTH = 10;
741
+ /**
681
742
  * Caps at `1024` the number of choices one schema field may offer, frozen.
682
743
  *
683
744
  * @remarks
@@ -1480,20 +1541,28 @@ function isFault(value) {
1480
1541
  * Determines whether a value is exactly one {@link AuditFault}.
1481
1542
  *
1482
1543
  * @remarks
1483
- * Every {@link Fault}, and the undeclared-key fault an audit adds.
1544
+ * Every {@link Fault}, and the undeclared-key and hidden-key faults an audit adds: `extra` with
1545
+ * exactly `reason` and `path`, or with a string `symbol` beside them, and `hidden` with exactly
1546
+ * `reason` and `path`.
1484
1547
  *
1485
1548
  * @param value - The value to inspect
1486
1549
  * @returns True if the value is a well-formed audit fault; false otherwise
1487
1550
  *
1488
1551
  * @example
1489
1552
  * ```ts
1490
- * isAuditFault({ reason: 'extra', path: ['a'] }) // true
1491
- * isAuditFault({}) // false
1553
+ * isAuditFault({ reason: 'extra', path: ['a'] }) // true
1554
+ * isAuditFault({ reason: 'extra', path: [], symbol: 'Symbol(tag)' }) // true
1555
+ * isAuditFault({ reason: 'hidden', path: ['note'] }) // true
1556
+ * isAuditFault({}) // false
1492
1557
  * ```
1493
1558
  */
1494
1559
  function isAuditFault(value) {
1495
1560
  if (isFault(value)) return true;
1496
- return holds(() => isRecord(value) && value.reason === "extra" && isFaultPath(value.path) && matchesExactKeys(value, ["reason", "path"]));
1561
+ return holds(() => isRecord(value) && isFaultPath(value.path) && (value.reason === "hidden" && matchesExactKeys(value, ["reason", "path"]) || value.reason === "extra" && (matchesExactKeys(value, ["reason", "path"]) || isString(value.symbol) && matchesExactKeys(value, [
1562
+ "reason",
1563
+ "path",
1564
+ "symbol"
1565
+ ]))));
1497
1566
  }
1498
1567
  /** Determines whether a value is a `Map`.
1499
1568
  *
@@ -2138,24 +2207,57 @@ function isJSONPrimitive(value) {
2138
2207
  }
2139
2208
  // src/core/helpers.ts
2140
2209
  /**
2141
- * Admits a stable readable value with only lossless repairs and returns the parser's value.
2210
+ * Admits a readable value exactly where `is` holds and returns the parser's value.
2211
+ *
2212
+ * @remarks
2213
+ * Guard-valid input parses once. Any other input refuses with every fault `audit` reports
2214
+ * after {@link filterUncoveredFaults} prunes the faults a union fault covers, bounded at
2215
+ * {@link FAULT_LIMIT}. A parse that returns `undefined` for a value other than `undefined`
2216
+ * refuses with no fault, and a read failure refuses with its cause rather than throwing.
2217
+ * Repair a lossless leaf through {@link repairValue}.
2218
+ *
2219
+ * @example
2220
+ * ```ts
2221
+ * admitValue(createContract(numberShape()), 3) // success carrying 3
2222
+ * admitValue(createContract(numberShape()), '3') // refusal carrying the type fault
2223
+ * ```
2224
+ */
2225
+ function admitValue(contract, value) {
2226
+ try {
2227
+ if (contract.is(value)) {
2228
+ const parsed = contract.parse(value);
2229
+ if (parsed === void 0 && value !== void 0) return failure({ faults: [] });
2230
+ return success(parsed === void 0 ? value : parsed);
2231
+ }
2232
+ return failure({ faults: limitEntries(filterUncoveredFaults(contract.audit(value)), 64) });
2233
+ } catch (cause) {
2234
+ return failure({
2235
+ faults: [],
2236
+ cause
2237
+ });
2238
+ }
2239
+ }
2240
+ /**
2241
+ * Repairs a stable readable value with only lossless repairs and returns the parser's value.
2142
2242
  *
2143
2243
  * @remarks
2144
2244
  * Reads must remain stable across artifacts. Guard-valid input skips both reports and parses
2145
2245
  * once. Repairs use audit, parse once, and explain only on parse failure. Unresolved unions,
2146
2246
  * extras, lossy repairs, and a capped audit refuse. An own optional undefined field omitted or
2147
- * filled by its declared default is not a repair. The result preserves parser ownership, including union input identity.
2247
+ * filled by its declared default is not a repair. The merge of explain and audit faults keys on
2248
+ * reason and path, and keeps every `extra` fault carrying `symbol`, so two symbol keys of
2249
+ * one description stay two faults. The result preserves parser ownership, including union input identity.
2148
2250
  * A read failure returns its cause rather than throwing.
2149
- * Snapshot a foreign object before admission, as Tool.execute does. A getter changing between
2251
+ * Snapshot a foreign object before repair, as Tool.execute does. A getter changing between
2150
2252
  * is and parse can publish a value that no recorded repair describes. A shallow snapshot only
2151
2253
  * stabilizes its own level; nested foreign values must also provide stable reads.
2152
2254
  *
2153
2255
  * @example
2154
2256
  * ```ts
2155
- * admitValue(createContract(numberShape()), '3') // success carrying 3 and its type repair
2257
+ * repairValue(createContract(numberShape()), '3') // success carrying 3 and its type repair
2156
2258
  * ```
2157
2259
  */
2158
- function admitValue(contract, value) {
2260
+ function repairValue(contract, value) {
2159
2261
  try {
2160
2262
  if (contract.is(value)) {
2161
2263
  const parsed = contract.parse(value);
@@ -2168,16 +2270,32 @@ function admitValue(contract, value) {
2168
2270
  const audited = contract.audit(value);
2169
2271
  const parsed = contract.parse(value);
2170
2272
  const explained = parsed === void 0 ? contract.explain(value) : [];
2171
- const repairs = audited.filter((fault) => matchesLosslessRepair(fault, value, parsed));
2172
- const refused = audited.filter((fault) => !repairs.includes(fault) && !matchesUndefinedField(fault, value, parsed));
2173
- const merged = [...explained, ...refused];
2174
- const faults = [...new Map(merged.map((fault) => [JSON.stringify([fault.reason, extractPath(fault)]), fault])).values()];
2175
- const covers = faults.filter((fault) => fault.reason === "variant" || fault.reason === "oneOf").map((fault) => extractPath(fault));
2176
- const uncovered = faults.filter((fault) => {
2177
- const path = extractPath(fault);
2178
- const room = fault.reason === "variant" || fault.reason === "oneOf" ? 1 : 0;
2179
- return !covers.some((cover) => cover.length + room <= path.length && cover.every((segment, index) => segment === path[index]));
2180
- });
2273
+ const repairs = [];
2274
+ const merged = [];
2275
+ appendEntries(merged, explained);
2276
+ for (const index of iterateIndices(() => audited.length)) {
2277
+ const fault = audited[index];
2278
+ if (fault === void 0) continue;
2279
+ if (matchesLosslessRepair(fault, value, parsed)) repairs[repairs.length] = fault;
2280
+ else if (!matchesUndefinedField(fault, value, parsed)) merged[merged.length] = fault;
2281
+ }
2282
+ const faults = [];
2283
+ const seen = new INTRINSICS.map();
2284
+ for (const index of iterateIndices(() => merged.length)) {
2285
+ const fault = merged[index];
2286
+ if (fault === void 0) continue;
2287
+ if (fault.reason === "extra" && fault.symbol !== void 0) {
2288
+ faults[faults.length] = fault;
2289
+ continue;
2290
+ }
2291
+ const key = `${INTRINSICS.stringify(fault.reason)}|${buildPathKey(extractPath(fault))}`;
2292
+ const slot = INTRINSICS.reflect.apply(INTRINSICS.fetch, seen, [key]);
2293
+ if (slot === void 0) {
2294
+ INTRINSICS.reflect.apply(INTRINSICS.store, seen, [key, faults.length]);
2295
+ faults[faults.length] = fault;
2296
+ } else faults[slot] = fault;
2297
+ }
2298
+ const uncovered = filterUncoveredFaults(faults);
2181
2299
  if (uncovered.length > 0) return failure({ faults: limitEntries(uncovered, 64) });
2182
2300
  if (audited.length >= 64) return failure({ faults: limitEntries(audited, 64) });
2183
2301
  if (parsed === void 0) return failure({ faults: limitEntries(audited, 64) });
@@ -2193,6 +2311,68 @@ function admitValue(contract, value) {
2193
2311
  }
2194
2312
  }
2195
2313
  /**
2314
+ * Builds a map key from the leading segments of a path, without dispatching through array serialization.
2315
+ *
2316
+ * @remarks
2317
+ * Each segment is encoded as a quoted string and the encodings are joined by a captured `join`,
2318
+ * so a caller-installed `Array.prototype.toJSON` cannot reach the key and two paths never share one.
2319
+ *
2320
+ * @param path - The path whose leading segments form the key
2321
+ * @param length - The number of leading segments to keep; default: every segment
2322
+ * @returns The key text, empty for no segment
2323
+ *
2324
+ * @example
2325
+ * ```ts
2326
+ * buildPathKey(['a', 'b'], 1) // '"a"'
2327
+ * ```
2328
+ */
2329
+ function buildPathKey(path, length = path.length) {
2330
+ const parts = INTRINSICS.from(iterateIndices(() => length), (index) => INTRINSICS.stringify(path[index]));
2331
+ return INTRINSICS.reflect.apply(INTRINSICS.join, parts, [","]);
2332
+ }
2333
+ /**
2334
+ * Filters out the faults a union fault covers, keeping every fault that states a fact no form shows.
2335
+ *
2336
+ * @remarks
2337
+ * A `variant` or `oneOf` fault covers every fault beneath its path and every non-union fault at
2338
+ * its path, and never itself. A `hidden` fault and an `extra` fault carrying `symbol` are kept
2339
+ * whatever covers them, because each reports a member outside the enumerable view that no
2340
+ * form summary names.
2341
+ *
2342
+ * @param faults - The faults an audit reported
2343
+ * @returns The faults no cover prunes, in their order
2344
+ *
2345
+ * @example
2346
+ * ```ts
2347
+ * filterUncoveredFaults([
2348
+ * { reason: 'variant', path: [], variants: 2 },
2349
+ * { reason: 'extra', path: ['typo'] },
2350
+ * ]) // [{ reason: 'variant', path: [], variants: 2 }]
2351
+ * ```
2352
+ */
2353
+ function filterUncoveredFaults(faults) {
2354
+ const covers = new INTRINSICS.set();
2355
+ for (const index of iterateIndices(() => faults.length)) {
2356
+ const fault = faults[index];
2357
+ if (fault !== void 0 && (fault.reason === "variant" || fault.reason === "oneOf")) INTRINSICS.reflect.apply(INTRINSICS.admit, covers, [buildPathKey(extractPath(fault))]);
2358
+ }
2359
+ const kept = [];
2360
+ pruning: for (const index of iterateIndices(() => faults.length)) {
2361
+ const fault = faults[index];
2362
+ if (fault === void 0) continue;
2363
+ if (fault.reason !== "hidden" && !(fault.reason === "extra" && fault.symbol !== void 0)) {
2364
+ const path = extractPath(fault);
2365
+ const room = fault.reason === "variant" || fault.reason === "oneOf" ? 1 : 0;
2366
+ for (const length of iterateIndices(() => path.length - room + 1)) {
2367
+ const prefix = buildPathKey(path, length);
2368
+ if (INTRINSICS.reflect.apply(INTRINSICS.member, covers, [prefix])) continue pruning;
2369
+ }
2370
+ }
2371
+ kept[kept.length] = fault;
2372
+ }
2373
+ return kept;
2374
+ }
2375
+ /**
2196
2376
  * Checks whether a type fault describes an own undefined field omitted or defaulted by a successful parse.
2197
2377
  *
2198
2378
  * @remarks
@@ -2208,9 +2388,20 @@ function admitValue(contract, value) {
2208
2388
  function matchesUndefinedField(fault, value, parsed) {
2209
2389
  if (fault.reason !== "type" || parsed === void 0) return false;
2210
2390
  const path = extractPath(fault);
2211
- const key = path.at(-1);
2391
+ const key = path[path.length - 1];
2212
2392
  if (key === void 0) return false;
2213
- const [raw, result] = path.slice(0, -1).reduce(([raw, result], segment) => [isObject(raw) && INTRINSICS.own(raw, segment) ? INTRINSICS.reflect.read(raw, segment) : void 0, isObject(result) && INTRINSICS.own(result, segment) ? INTRINSICS.reflect.read(result, segment) : void 0], [value, parsed]);
2393
+ const cursor = {
2394
+ raw: value,
2395
+ result: parsed
2396
+ };
2397
+ for (const index of iterateIndices(() => path.length - 1)) {
2398
+ const segment = path[index];
2399
+ if (segment === void 0) return false;
2400
+ const { raw, result } = cursor;
2401
+ cursor.raw = isObject(raw) && INTRINSICS.own(raw, segment) ? INTRINSICS.reflect.read(raw, segment) : void 0;
2402
+ cursor.result = isObject(result) && INTRINSICS.own(result, segment) ? INTRINSICS.reflect.read(result, segment) : void 0;
2403
+ }
2404
+ const { raw, result } = cursor;
2214
2405
  return isObject(raw) && INTRINSICS.own(raw, key) && INTRINSICS.reflect.read(raw, key) === void 0 && isObject(result);
2215
2406
  }
2216
2407
  /**
@@ -2224,7 +2415,10 @@ function matchesUndefinedField(fault, value, parsed) {
2224
2415
  function truncateFaultText(text, limit) {
2225
2416
  if (limit <= 0) return "";
2226
2417
  if (text.length <= limit) return text;
2227
- return `${text.slice(0, limit - 1).replace(/[\uD800-\uDBFF]$/u, "")}…`;
2418
+ const bound = INTRINSICS.floor(limit);
2419
+ const last = text[bound - 2];
2420
+ const kept = last !== void 0 && last >= "\ud800" && last <= "\udbff" ? bound - 2 : bound - 1;
2421
+ return `${INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.from(iterateIndices(() => kept), (index) => text[index]), [""])}…`;
2228
2422
  }
2229
2423
  /**
2230
2424
  * Describes bounded faults with encoded values and a schema-derived correction summary.
@@ -2243,19 +2437,19 @@ function truncateFaultText(text, limit) {
2243
2437
  function describeFaults(faults, schema, options) {
2244
2438
  const requested = options?.limit ?? 2048;
2245
2439
  if (!isInteger(requested) || requested < 0) throw new ContractError("Fault text limit must be a non-negative integer", { code: "range" });
2246
- const limit = Math.min(requested, FAULT_TEXT_LIMIT);
2247
- const send = schema === void 0 ? "" : `send ${renderForm(schema, Math.min(160, Math.floor(limit / 3)))}`;
2248
- const lines = limitEntries(faults, 64).map((fault) => describeFaultLine(fault, schema ?? {}));
2249
- const room = Math.max(0, limit - send.length - 82);
2250
- const kept = lines.filter((_, index) => lines.slice(0, index + 1).join("\n").length <= room);
2440
+ const limit = INTRINSICS.min(requested, FAULT_TEXT_LIMIT);
2441
+ const send = schema === void 0 ? "" : `send ${renderForm(schema, INTRINSICS.min(160, INTRINSICS.floor(limit / 3)))}`;
2442
+ const lines = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(limitEntries(faults, 64)), [(fault) => describeFaultLine(fault, schema ?? {})]);
2443
+ const room = INTRINSICS.max(0, limit - send.length - 82);
2444
+ const kept = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(lines), [(_line, index) => INTRINSICS.reflect.apply(INTRINSICS.join, limitEntries(lines, index + 1), ["\n"]).length <= room]);
2251
2445
  const hidden = faults.length - kept.length;
2252
- const note = [...hidden > 0 ? [`and ${String(hidden)} more faults`] : [], ...faults.length >= 64 ? [`the report stops at ${String(64)}`] : []].join(", ");
2253
- return truncateFaultText([
2254
- ...kept,
2255
- ...kept.length === 0 && lines.length > 0 && room > 0 ? [truncateFaultText(lines[0] ?? "", room)] : [],
2256
- ...note.length === 0 ? [] : [note],
2257
- ...send.length === 0 ? [] : [send]
2258
- ].join("\n"), limit);
2446
+ const note = INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([hidden > 0 ? `and ${INTRINSICS.text(hidden)} more faults` : void 0, faults.length >= 64 ? `the report stops at ${INTRINSICS.text(64)}` : void 0]), [(part) => part !== void 0]), [", "]);
2447
+ const extras = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([
2448
+ kept.length === 0 && lines.length > 0 && room > 0 ? truncateFaultText(lines[0] ?? "", room) : void 0,
2449
+ note.length === 0 ? void 0 : note,
2450
+ send.length === 0 ? void 0 : send
2451
+ ]), [(part) => part !== void 0]);
2452
+ return truncateFaultText(INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.from(iterateIndices(() => kept.length + extras.length), (index) => index < kept.length ? kept[index] : extras[index - kept.length]), ["\n"]), limit);
2259
2453
  }
2260
2454
  /**
2261
2455
  * Iterates indices while rereading the upper bound before every step.
@@ -2735,9 +2929,10 @@ function collectEntries(target) {
2735
2929
  function readSetEntries(value) {
2736
2930
  return attempt(() => {
2737
2931
  const collected = [];
2738
- INTRINSICS.reflect.apply(INTRINSICS.sweep, value, [collectEntries(collected)]);
2739
- const entries = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(collected), [(pair) => pair[1]]);
2740
- return INTRINSICS.freeze(entries);
2932
+ INTRINSICS.reflect.apply(INTRINSICS.sweep, value, [(entry) => {
2933
+ collected[collected.length] = entry;
2934
+ }]);
2935
+ return INTRINSICS.freeze(collected);
2741
2936
  });
2742
2937
  }
2743
2938
  /**
@@ -3444,80 +3639,109 @@ function matchesRecordBrand(value) {
3444
3639
  return true;
3445
3640
  }
3446
3641
  /**
3447
- * Snapshots an array through its reflected own-index population.
3642
+ * Collects an array's entries through its reflected own-index population.
3448
3643
  *
3449
3644
  * @remarks
3450
3645
  * Reads `length` once and one reflected own-key population, then corroborates
3451
3646
  * and reads only those reflected canonical indices in ascending order. The
3452
- * frozen native snapshot retains actual holes: reading one yields `undefined`,
3453
- * while own membership remains absent. Its work is proportional to the
3454
- * reflected population, so a length-driven consumer must require `dense` or
3455
- * carry an independent bound. A population that is exactly the canonical
3456
- * indices in ascending order followed by `length` is copied straight by index
3457
- * under the same per-index corroboration, and answers with the same entries,
3458
- * the same `dense` fact, and the same refusals as the walk. Caller-defined
3459
- * iteration is ignored. A descriptor-only index omitted from reflection is
3460
- * deliberately outside this lens and remains a hole. Failure retains the exact
3461
- * thrown value when length, reflection, membership, or indexed value
3462
- * observation throws; a non-native length or view disagreement is also
3463
- * failure. `4294967295` is metadata rather than an array index.
3647
+ * native entries retain actual holes: reading one yields `undefined`, while
3648
+ * own membership remains absent. Its work is proportional to the reflected
3649
+ * population, so a length-driven consumer must require `dense` or carry an
3650
+ * independent bound. `exact` is false when the population holds any key other
3651
+ * than a canonical index or `length`, a symbol key included. A population that
3652
+ * is exactly the canonical indices in ascending order followed by `length` is
3653
+ * copied straight by index under the same per-index corroboration, and answers
3654
+ * with the same entries, the same `dense` and `exact` facts, and the same
3655
+ * refusals as the walk. Caller-defined iteration is ignored. A descriptor-only
3656
+ * index omitted from reflection is deliberately outside this lens and remains a
3657
+ * hole. `4294967295` is metadata rather than an array index. Every call returns
3658
+ * a fresh unfrozen read; {@link readArrayEntries} freezes it.
3464
3659
  *
3465
- * @param value - The array whose reflected indexed entries to read
3466
- * @returns A successful frozen entry snapshot with its dense fact, or a
3467
- * failure carrying the exact thrown value as `unknown`
3660
+ * @param value - The array whose reflected indexed entries to collect
3661
+ * @returns The entries with their `dense` and `exact` facts
3662
+ * @throws The exact thrown value when length, reflection, membership, or
3663
+ * indexed value observation throws, and an `Error` on a non-native
3664
+ * length or a view disagreement
3468
3665
  *
3469
3666
  * @example
3470
3667
  * ```ts
3471
- * readArrayEntries([1, 2]) // { success: true, value: { entries: [1, 2], dense: true } }
3668
+ * collectArrayEntries([1, 2]) // { entries: [1, 2], dense: true, exact: true }
3472
3669
  * ```
3473
3670
  */
3474
- function readArrayEntries(value) {
3475
- return attempt(() => {
3476
- const length = value.length;
3477
- if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
3478
- const members = INTRINSICS.reflect.members(value);
3479
- if (members.length === length + 1 && members[length] === "length" && !INTRINSICS.reflect.apply(INTRINSICS.some, members, [(key, index) => index < length && key !== INTRINSICS.text(index)])) {
3480
- const packed = INTRINSICS.from(iterateIndices(() => length), (index) => {
3671
+ function collectArrayEntries(value) {
3672
+ const length = value.length;
3673
+ if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
3674
+ const members = INTRINSICS.reflect.members(value);
3675
+ if (members.length === length + 1 && members[length] === "length" && !INTRINSICS.reflect.apply(INTRINSICS.some, members, [(key, index) => index < length && key !== INTRINSICS.text(index)])) {
3676
+ const indices = {
3677
+ __proto__: null,
3678
+ length
3679
+ };
3680
+ return {
3681
+ entries: INTRINSICS.from(indices, (_entry, index) => {
3481
3682
  const key = members[index];
3482
3683
  if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
3483
3684
  return value[index];
3484
- });
3485
- return INTRINSICS.freeze({
3486
- entries: INTRINSICS.freeze(packed),
3487
- dense: true
3488
- });
3489
- }
3490
- const selected = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => {
3491
- if (!isString(key)) return [];
3492
- const index = INTRINSICS.numeric(key);
3493
- if (!INTRINSICS.integer(index) || index < 0 || index >= 2 ** 32 - 1 || INTRINSICS.text(index) !== key) return [];
3494
- if (index >= length) throw new INTRINSICS.error("Array index views disagree");
3495
- return [{
3496
- index,
3497
- key
3498
- }];
3499
- }]);
3500
- const collected = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.index]);
3501
- const keys = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
3502
- const ascending = !INTRINSICS.reflect.apply(INTRINSICS.some, collected, [(index, position) => index <= (collected[position - 1] ?? -1)]);
3503
- const indices = ascending ? collected : sortValues(collected);
3504
- const pairs = INTRINSICS.from(iterateIndices(() => indices.length), (position) => {
3505
- const index = indices[position];
3506
- const key = ascending ? keys[position] : INTRINSICS.text(index);
3507
- if (index === void 0 || key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
3508
- return [key, {
3509
- value: value[index],
3510
- enumerable: true,
3511
- configurable: true,
3512
- writable: true
3513
- }];
3514
- });
3515
- const descriptors = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
3516
- const entries = INTRINSICS.definitions(new INTRINSICS.list(length), descriptors);
3517
- return INTRINSICS.freeze({
3518
- entries: INTRINSICS.freeze(entries),
3519
- dense: indices.length === length
3520
- });
3685
+ }),
3686
+ dense: true,
3687
+ exact: true
3688
+ };
3689
+ }
3690
+ const selected = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(members), [(key) => {
3691
+ if (!isString(key)) return [];
3692
+ const index = INTRINSICS.numeric(key);
3693
+ if (!INTRINSICS.integer(index) || index < 0 || index >= 2 ** 32 - 1 || INTRINSICS.text(index) !== key) return [];
3694
+ if (index >= length) throw new INTRINSICS.error("Array index views disagree");
3695
+ return [{
3696
+ index,
3697
+ key
3698
+ }];
3699
+ }]);
3700
+ const collected = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.index]);
3701
+ const keys = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
3702
+ const ascending = !INTRINSICS.reflect.apply(INTRINSICS.some, collected, [(index, position) => index <= (collected[position - 1] ?? -1)]);
3703
+ const indices = ascending ? collected : sortValues(collected);
3704
+ const pairs = INTRINSICS.from(iterateIndices(() => indices.length), (position) => {
3705
+ const index = indices[position];
3706
+ const key = ascending ? keys[position] : INTRINSICS.text(index);
3707
+ if (index === void 0 || key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
3708
+ return [key, {
3709
+ value: value[index],
3710
+ enumerable: true,
3711
+ configurable: true,
3712
+ writable: true
3713
+ }];
3714
+ });
3715
+ const descriptors = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) });
3716
+ return {
3717
+ entries: INTRINSICS.definitions(new INTRINSICS.list(length), descriptors),
3718
+ dense: indices.length === length,
3719
+ exact: members.length === selected.length + 1
3720
+ };
3721
+ }
3722
+ /**
3723
+ * Snapshots an array through its reflected own-index population.
3724
+ *
3725
+ * @remarks
3726
+ * Answers what {@link collectArrayEntries} answers, as a frozen read whose
3727
+ * entries are frozen too. Failure retains the exact thrown value when length,
3728
+ * reflection, membership, or indexed value observation throws; a non-native
3729
+ * length or view disagreement is also failure.
3730
+ *
3731
+ * @param value - The array whose reflected indexed entries to read
3732
+ * @returns A successful frozen entry snapshot with its `dense` and `exact`
3733
+ * facts, or a failure carrying the exact thrown value as `unknown`
3734
+ *
3735
+ * @example
3736
+ * ```ts
3737
+ * readArrayEntries([1, 2]) // { success: true, value: { entries: [1, 2], dense: true, exact: true } }
3738
+ * ```
3739
+ */
3740
+ function readArrayEntries(value) {
3741
+ return attempt(() => {
3742
+ const read = collectArrayEntries(value);
3743
+ INTRINSICS.freeze(read.entries);
3744
+ return INTRINSICS.freeze(read);
3521
3745
  });
3522
3746
  }
3523
3747
  /**
@@ -3593,6 +3817,110 @@ function enumerableKeys(value) {
3593
3817
  return isSuccess(outcome) ? outcome.value : void 0;
3594
3818
  }
3595
3819
  /**
3820
+ * Checks whether an object owns no key outside the enumerable string keys already read from it.
3821
+ *
3822
+ * @remarks
3823
+ * Counts the own string keys, enumerable or not, against the key list and requires no own
3824
+ * symbol key. A key a `Proxy` lists among its own keys with no descriptor counts as own.
3825
+ * Thrown when the object's own-key reflection throws, so call it inside a boundary.
3826
+ *
3827
+ * @param value - The object whose own keys to count
3828
+ * @param keys - The object's own enumerable string keys, as `Object.keys` returned them
3829
+ * @returns True if the object owns no other key; false otherwise
3830
+ *
3831
+ * @example
3832
+ * ```ts
3833
+ * const value = { id: 'a' }
3834
+ * matchesEnumerableKeys(value, Object.keys(value)) // true
3835
+ * matchesEnumerableKeys(Object.defineProperty(value, 'secret', { value: 1 }), ['id']) // false
3836
+ * ```
3837
+ */
3838
+ function matchesEnumerableKeys(value, keys) {
3839
+ return INTRINSICS.names(value).length === keys.length && INTRINSICS.symbols(value).length === 0;
3840
+ }
3841
+ /**
3842
+ * Builds the key plan that answers one key order from the declared member guards.
3843
+ *
3844
+ * @remarks
3845
+ * One {@link KeyStep} per key, in the order given, each holding the key and its declared guard.
3846
+ * The plan and its steps are fresh and unfrozen.
3847
+ *
3848
+ * @param keys - The key order the plan answers
3849
+ * @param guards - The declared member guards, keyed by own string key
3850
+ * @returns The plan, or `undefined` when any key is undeclared
3851
+ *
3852
+ * @example
3853
+ * ```ts
3854
+ * buildKeyPlan(['id'], { id: isString }) // [{ key: 'id', guard: isString }]
3855
+ * buildKeyPlan(['other'], { id: isString }) // undefined
3856
+ * ```
3857
+ */
3858
+ function buildKeyPlan(keys, guards) {
3859
+ const plan = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(keys), [(key) => {
3860
+ const guard = INTRINSICS.own(guards, key) ? guards[key] : void 0;
3861
+ return guard === void 0 ? [] : [{
3862
+ key,
3863
+ guard
3864
+ }];
3865
+ }]);
3866
+ return plan.length === keys.length ? plan : void 0;
3867
+ }
3868
+ /**
3869
+ * Checks whether a key plan answers the key list bound as `this`.
3870
+ *
3871
+ * @remarks
3872
+ * Passed with the key list as the `thisArg` argument to the captured `findIndex` member over a list of
3873
+ * plans. A plan answers a key list holding the same keys in the same order, so a prefix and a
3874
+ * reordering both miss.
3875
+ *
3876
+ * @param plan - The key plan to compare
3877
+ * @returns True if the plan's keys equal the bound list in order; false otherwise
3878
+ *
3879
+ * @example
3880
+ * ```ts
3881
+ * matchesKeyPlan.call(['id'], [{ key: 'id', guard: isString }]) // true
3882
+ * ```
3883
+ */
3884
+ function matchesKeyPlan(plan) {
3885
+ return plan.length === this.length && INTRINSICS.reflect.apply(INTRINSICS.every, plan, [matchesStepKey, this]);
3886
+ }
3887
+ /**
3888
+ * Checks whether a key-plan step names the key at its index in the list bound as `this`.
3889
+ *
3890
+ * @remarks
3891
+ * Passed with the key list as the `thisArg` argument to the captured `every` member over a key plan.
3892
+ *
3893
+ * @param step - The step to compare
3894
+ * @param index - The step's position in its plan
3895
+ * @returns True if the step's key equals the bound list's key at that index; false otherwise
3896
+ *
3897
+ * @example
3898
+ * ```ts
3899
+ * matchesStepKey.call(['id'], { key: 'id', guard: isString }, 0) // true
3900
+ * ```
3901
+ */
3902
+ function matchesStepKey(step, index) {
3903
+ return step.key === this[index];
3904
+ }
3905
+ /**
3906
+ * Checks whether the member of the record bound as `this` passes a key-plan step's guard.
3907
+ *
3908
+ * @remarks
3909
+ * Passed with the record as the `thisArg` argument to the captured `every` member over a key plan, so the
3910
+ * walk reads each member once, in the plan's order, and stops at the first refusal.
3911
+ *
3912
+ * @param step - The step whose member to read and guard
3913
+ * @returns True if the member under the step's key passes its guard; false otherwise
3914
+ *
3915
+ * @example
3916
+ * ```ts
3917
+ * matchesStepGuard.call({ id: 'a' }, { key: 'id', guard: isString }) // true
3918
+ * ```
3919
+ */
3920
+ function matchesStepGuard(step) {
3921
+ return step.guard(this[step.key]);
3922
+ }
3923
+ /**
3596
3924
  * Validates and snapshots a shape-builder options record through every reflective
3597
3925
  * operation the builder relies on.
3598
3926
  *
@@ -3733,8 +4061,9 @@ function drawRandom(random, shape) {
3733
4061
  */
3734
4062
  function resolveField(record, path) {
3735
4063
  const outcome = attempt(() => {
3736
- if (!isRecord(record)) return void 0;
3737
- const keys = isString(path) ? [path] : path;
4064
+ if (!matchesRecordBrand(record)) return void 0;
4065
+ if (isString(path)) return INTRINSICS.own(record, path) ? INTRINSICS.reflect.read(record, path) : void 0;
4066
+ const keys = path;
3738
4067
  const indices = iterateIndices(() => keys.length);
3739
4068
  return INTRINSICS.reflect.apply(INTRINSICS.reduce, indices, [(current, index) => {
3740
4069
  const key = keys[index];
@@ -3782,7 +4111,7 @@ function matchesExactKeys(value, required, optional = []) {
3782
4111
  * Only a `type` fault is a repair. A number needs a string whose trim is the number's own
3783
4112
  * text, so `'30'` and `' 30 '` pass while `'30.0'`, `'007'`, `'0x10'`, `'1e3'`, `'+5'`,
3784
4113
  * `'.5'`, `'-0'`, and `'9007199254740993'` do not. A boolean needs `'true'` or `'false'`,
3785
- * a literal its trimmed text, and a string a finite number. Anything else refuses.
4114
+ * a literal its trimmed text, and a string a finite number other than `-0`. Anything else refuses.
3786
4115
  *
3787
4116
  * @param fault - A fault `audit` reported
3788
4117
  * @param input - The value as it arrived
@@ -3807,7 +4136,7 @@ function matchesLosslessRepair(fault, input, parsed) {
3807
4136
  case "integer": return isString(raw) && isNumber(value) && raw.trim() === INTRINSICS.text(value);
3808
4137
  case "literal": return isString(raw) && (isString(value) || isNumber(value) || isBoolean(value)) && raw.trim() === INTRINSICS.text(value);
3809
4138
  case "boolean": return raw === "true" || raw === "false";
3810
- case "string": return isFiniteNumber(raw);
4139
+ case "string": return isFiniteNumber(raw) && !INTRINSICS.same(raw, -0);
3811
4140
  default: return false;
3812
4141
  }
3813
4142
  }
@@ -4189,7 +4518,8 @@ function canonicalStringify(value) {
4189
4518
  value
4190
4519
  }];
4191
4520
  while (stack.length > 0) {
4192
- const frame = stack.pop();
4521
+ const frame = stack[stack.length - 1];
4522
+ stack.length -= 1;
4193
4523
  if (frame === void 0) return void 0;
4194
4524
  if (frame.operation === "exit") {
4195
4525
  const parts = INTRINSICS.from(encodeParts(frame.members, frame.keys, encodings));
@@ -4231,6 +4561,27 @@ function canonicalStringify(value) {
4231
4561
  }, "canonicalStringify");
4232
4562
  }
4233
4563
  /**
4564
+ * Computes the number of days in a month of the Gregorian calendar.
4565
+ *
4566
+ * @remarks
4567
+ * February has 29 days in a year divisible by 4, except a century year not divisible
4568
+ * by 400. The caller supplies a month from 1 to 12.
4569
+ *
4570
+ * @param year - The calendar year
4571
+ * @param month - The month, from 1 for January to 12 for December
4572
+ * @returns The days in that month, from 28 to 31
4573
+ *
4574
+ * @example
4575
+ * ```ts
4576
+ * computeMonthLength(2024, 2) // 29
4577
+ * computeMonthLength(1900, 2) // 28
4578
+ * ```
4579
+ */
4580
+ function computeMonthLength(year, month) {
4581
+ const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
4582
+ return month === 2 ? 28 + INTRINSICS.numeric(leap) : 31 - INTRINSICS.numeric(month === 4 || month === 6 || month === 9 || month === 11);
4583
+ }
4584
+ /**
4234
4585
  * Checks whether a supported ISO-8601 date or date-time names a real instant.
4235
4586
  *
4236
4587
  * @remarks
@@ -4261,9 +4612,7 @@ function matchesISOInstant(value) {
4261
4612
  const month = INTRINSICS.numeric(monthText);
4262
4613
  const day = INTRINSICS.numeric(dayText);
4263
4614
  if (month < 1 || month > 12) return false;
4264
- const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
4265
- const limit = month === 2 ? 28 + INTRINSICS.numeric(leap) : 31 - INTRINSICS.numeric(month === 4 || month === 6 || month === 9 || month === 11);
4266
- if (day < 1 || day > limit) return false;
4615
+ if (day < 1 || day > computeMonthLength(year, month)) return false;
4267
4616
  const hourText = match?.[4];
4268
4617
  const minuteText = match?.[5];
4269
4618
  const secondText = match?.[6];
@@ -4280,6 +4629,27 @@ function matchesISOInstant(value) {
4280
4629
  return isSuccess(outcome) && outcome.value;
4281
4630
  }
4282
4631
  /**
4632
+ * Checks whether a string is exactly a calendar-valid `YYYY-MM-DD` date.
4633
+ *
4634
+ * @remarks
4635
+ * Refuses a date-time, surrounding whitespace, and a date the Gregorian calendar
4636
+ * lacks, such as `2026-02-29`. Backs a date string shape and {@link classifyFormat}'s
4637
+ * `date`.
4638
+ *
4639
+ * @param value - The candidate string
4640
+ * @returns True if `value` is a calendar-valid `YYYY-MM-DD`; false otherwise
4641
+ * @throws The exact value thrown by a redirected pattern dispatch
4642
+ *
4643
+ * @example
4644
+ * ```ts
4645
+ * matchesCalendarDate('2024-02-29') // true
4646
+ * matchesCalendarDate('2026-02-29') // false
4647
+ * ```
4648
+ */
4649
+ function matchesCalendarDate(value) {
4650
+ return matchesPattern(/^\d{4}-\d{2}-\d{2}$/, value) && matchesISOInstant(value);
4651
+ }
4652
+ /**
4283
4653
  * Classifies an already-bounded string against the pattern-only and
4284
4654
  * calendar-checked {@link SchemaFormat} vocabulary.
4285
4655
  *
@@ -4301,7 +4671,7 @@ function matchesISOInstant(value) {
4301
4671
  function classifyFormat(value) {
4302
4672
  if (matchesPattern(FORMAT_PATTERNS.uuid, value)) return "uuid";
4303
4673
  if (matchesPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/, value) && matchesISOInstant(value)) return "date-time";
4304
- if (matchesPattern(/^\d{4}-\d{2}-\d{2}$/, value) && matchesISOInstant(value)) return "date";
4674
+ if (matchesCalendarDate(value)) return "date";
4305
4675
  if (matchesPattern(/^\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/, value) && matchesISOInstant(`1970-01-01T${value}`)) return "time";
4306
4676
  if (matchesPattern(FORMAT_PATTERNS.email, value)) return "email";
4307
4677
  if (matchesPattern(FORMAT_PATTERNS.uri, value)) return "uri";
@@ -4445,41 +4815,51 @@ function sanitizeDepth(value) {
4445
4815
  return INTRINSICS.min(sanitizeBudget(value, 32), 32);
4446
4816
  }
4447
4817
  /**
4448
- * Renders an unknown value as a short, safe, TOTAL string for a {@link Fault}'s
4449
- * `received` field.
4450
- *
4451
- * @remarks
4452
- * A primitive renders as printable text: a string retains its quoted JSON
4453
- * representation, while a narrowed symbol renders through intrinsic `String`
4454
- * and receives the same escaping without outer quotes. A string of at most
4455
- * {@link PREVIEW_LIMIT} code units takes its answer from one whole-string
4456
- * encode when that encode fits the same limit, and the length predicate
4457
- * deciding it is exact rather than approximate. Every other string and every
4458
- * symbol renders through one bounded indexed encoder that appends only
4459
- * complete escaped code-point tokens within {@link PREVIEW_LIMIT}; clipping
4460
- * therefore never retrieves the mutable string iterator or splits an
4461
- * escape/surrogate pair before its trailing `…`, and enormous primitive text
4462
- * is not fully traversed. A number / boolean / bigint renders through `String`;
4463
- * `null` and `undefined` render as their own name. An array renders as
4464
- * `'array'`. Every other host — a plain object, a function, a class instance,
4465
- * a `Map` — is NEVER traversed or stringified; it renders as its bare
4466
- * `typeof` tag (`'object'` / `'function'`).
4467
- *
4468
- * The indexed encoder appends every token and closes with the quote exactly
4469
- * when the escaped inner length is at most `PREVIEW_LIMIT - 2`, which is
4470
- * character for character what one `JSON.stringify` call returns. At an inner
4471
- * length of `PREVIEW_LIMIT - 1` the indexed encoder appends every token and
4472
- * closes with `…` instead, while one `JSON.stringify` call over that same
4473
- * string measures `PREVIEW_LIMIT + 1` — so the predicate refuses that string
4474
- * and every longer one, and each of them renders through the indexed encoder.
4475
- * Escaping never shrinks text, so the leading `source.length` gate admits
4476
- * every string the predicate could accept while keeping enormous primitive
4477
- * text out of the whole-string encode. A symbol renders through the indexed
4478
- * encoder because its unquoted text is not what a `JSON.stringify` call
4479
- * returns.
4818
+ * Renders a value as a bounded single-line string for a {@link Fault}'s `received` field, running
4819
+ * a `Proxy` object's `getPrototypeOf` trap.
4820
+ *
4821
+ * @remarks
4822
+ * Every preview, its quotes and its `…` included, is at most
4823
+ * {@link PREVIEW_LIMIT} UTF-16 code units long and holds no control character
4824
+ * and no line terminator.
4825
+ *
4826
+ * A string renders as its quoted JSON representation, and a narrowed symbol
4827
+ * through intrinsic `String` with the same escaping and no outer quotes. DEL
4828
+ * (U+007F), the C1 controls (U+0080 to U+009F), U+2028, and U+2029, which a
4829
+ * `JSON.stringify` call leaves raw, render as `\u` sequences. A string of at
4830
+ * most {@link PREVIEW_LIMIT} UTF-16 code units that holds none of those raw
4831
+ * characters takes its answer from one whole-string encode when that encode
4832
+ * fits the same limit. Every other string and every symbol renders through one
4833
+ * bounded indexed encoder that appends only complete escaped code-point tokens,
4834
+ * at most `PREVIEW_LIMIT - 2` UTF-16 code units between a string's quotes and
4835
+ * `PREVIEW_LIMIT - 1` of a symbol, and then closes with the quote when every
4836
+ * token fit and with `…` otherwise. Clipping therefore never retrieves the
4837
+ * mutable string iterator or splits an escape or a surrogate pair, and
4838
+ * enormous primitive text is not fully traversed. The two paths agree: one
4839
+ * `JSON.stringify` call fits the limit exactly when the escaped inner length
4840
+ * is at most `PREVIEW_LIMIT - 2`, which is when the indexed encoder closes
4841
+ * with the quote.
4842
+ *
4843
+ * A number or a boolean renders through `String`. A bigint renders through
4844
+ * `String` with a trailing `n`; when its text reaches {@link PREVIEW_LIMIT}
4845
+ * UTF-16 code units, the preview keeps the leading `PREVIEW_LIMIT - 2`, then
4846
+ * `…`, then `n`. `null` and `undefined` render as their own name.
4847
+ *
4848
+ * An array renders as `'array'`, a function as `'function'`, a plain or
4849
+ * null-prototype record as `'object'`, and every other object, such as a class
4850
+ * instance, a `Map`, a `Date`, or a revoked `Proxy`, as `'instance'`. To tell a
4851
+ * record from an instance, the {@link isRecord} guard reads the object's
4852
+ * prototype, that prototype's prototype, and, when the second is `null`, the
4853
+ * first one's own property descriptors. A `Proxy` object's `getPrototypeOf`
4854
+ * trap therefore runs, and so do the `getPrototypeOf` and
4855
+ * `getOwnPropertyDescriptor` traps of a `Proxy` object that stands as the
4856
+ * prototype; a trap that throws yields `'instance'`. Every read is a prototype
4857
+ * or descriptor read, so no accessor on the object or its prototype runs, and
4858
+ * no object is stringified.
4480
4859
  *
4481
4860
  * @param value - The value to preview
4482
- * @returns A short descriptive string, always safe to embed in a diagnostic
4861
+ * @returns A string of at most {@link PREVIEW_LIMIT} UTF-16 code units with no
4862
+ * control character and no line terminator
4483
4863
  *
4484
4864
  * @example
4485
4865
  * ```ts
@@ -4487,6 +4867,7 @@ function sanitizeDepth(value) {
4487
4867
  * preview(42) // '42'
4488
4868
  * preview(null) // 'null'
4489
4869
  * preview({ a: 1 }) // 'object'
4870
+ * preview(new Map()) // 'instance'
4490
4871
  * preview([1, 2, 3]) // 'array'
4491
4872
  * ```
4492
4873
  */
@@ -4496,17 +4877,23 @@ function preview(value) {
4496
4877
  if (isString(value) || isSymbol(value)) {
4497
4878
  const quoted = isString(value);
4498
4879
  const source = INTRINSICS.text(value);
4499
- if (quoted && source.length <= 64) {
4880
+ if (quoted && source.length <= 64 && !matchesPattern(/[\x7f-\x9f\u{2028}\u{2029}]/u, source)) {
4500
4881
  const whole = INTRINSICS.stringify(source);
4501
4882
  if (whole.length <= 64) return whole;
4502
4883
  }
4503
- const parts = previewParts(source, 0, 64 - (quoted ? 1 : 0), quoted);
4884
+ const parts = previewParts(source, 0, 64 - (quoted ? 2 : 1), quoted);
4504
4885
  const body = INTRINSICS.reflect.apply(INTRINSICS.join, parts, [""]);
4505
4886
  return quoted ? `"${body}` : body;
4506
4887
  }
4507
4888
  if (isNumber(value) || isBoolean(value)) return INTRINSICS.text(value);
4508
- if (isBigInt(value)) return `${value}n`;
4889
+ if (isBigInt(value)) {
4890
+ const digits = INTRINSICS.text(value);
4891
+ if (digits.length < 64) return `${digits}n`;
4892
+ const parts = previewParts(digits, 0, 62, false);
4893
+ return `${INTRINSICS.reflect.apply(INTRINSICS.join, parts, [""])}n`;
4894
+ }
4509
4895
  if (isArray(value)) return "array";
4896
+ if (isObject(value) && !isRecord(value)) return "instance";
4510
4897
  return typeof value;
4511
4898
  }
4512
4899
  /**
@@ -4518,8 +4905,10 @@ function preview(value) {
4518
4905
  * OBTAIN the string — the reporter coerces through `parseString`, the auditor
4519
4906
  * demands a primitive string — and share every constraint afterwards through
4520
4907
  * this helper, so a constraint cannot drift between them.
4521
- * Faults come out in declaration order — `min`, then `max`, then
4908
+ * Faults come out in declaration order — `date`, then `min`, then `max`, then
4522
4909
  * `pattern` — because a report is read top to bottom and its order is public.
4910
+ * `expected` is `'date'` on a date string shape and `'string'` otherwise, as
4911
+ * {@link buildNumberFaults} names `'integer'`.
4523
4912
  *
4524
4913
  * The declaration's pattern is applied through an OWNED stateless rebuild
4525
4914
  * ({@link readPattern}) asked through {@link matchesPattern}, so the shape's own
@@ -4566,11 +4955,20 @@ function preview(value) {
4566
4955
  */
4567
4956
  function buildStringFaults(shape, value, path, pattern) {
4568
4957
  return readValue(() => {
4958
+ const dated = INTRINSICS.own(shape, "date") && shape.date === true;
4959
+ const expected = dated ? "date" : "string";
4569
4960
  const faults = [];
4961
+ if (dated && !matchesCalendarDate(value)) faults[faults.length] = {
4962
+ reason: "constraint",
4963
+ path,
4964
+ expected,
4965
+ constraint: "date",
4966
+ received: preview(value)
4967
+ };
4570
4968
  if (INTRINSICS.own(shape, "min") && shape.min !== void 0 && !matchesStringLength(value, shape.min, void 0)) faults[faults.length] = {
4571
4969
  reason: "constraint",
4572
4970
  path,
4573
- expected: "string",
4971
+ expected,
4574
4972
  constraint: "min",
4575
4973
  limit: shape.min,
4576
4974
  received: preview(value)
@@ -4578,7 +4976,7 @@ function buildStringFaults(shape, value, path, pattern) {
4578
4976
  if (INTRINSICS.own(shape, "max") && shape.max !== void 0 && !matchesStringLength(value, void 0, shape.max)) faults[faults.length] = {
4579
4977
  reason: "constraint",
4580
4978
  path,
4581
- expected: "string",
4979
+ expected,
4582
4980
  constraint: "max",
4583
4981
  limit: shape.max,
4584
4982
  received: preview(value)
@@ -4589,7 +4987,7 @@ function buildStringFaults(shape, value, path, pattern) {
4589
4987
  faults[faults.length] = {
4590
4988
  reason: "constraint",
4591
4989
  path,
4592
- expected: "string",
4990
+ expected,
4593
4991
  constraint: "pattern",
4594
4992
  ...limit === void 0 ? {} : { limit },
4595
4993
  received: preview(value)
@@ -4736,9 +5134,11 @@ function selectClosestFaults(reports) {
4736
5134
  * A structural mapping used by {@link compileReporter} to fill a `Fault`'s
4737
5135
  * `expected` field and by {@link compileAuditor} to fill an `AuditFault`'s:
4738
5136
  * most shapes map to their own `category` (`numberShape` maps to
4739
- * `'integer'` when `integer: true`, else `'number'`); `optionalShape` /
5137
+ * `'integer'` when `integer: true`, else `'number'`, and `stringShape` maps to
5138
+ * `'date'` when `date: true`, else `'string'`); `optionalShape` /
4740
5139
  * `nullableShape` project through to their inner shape's kind, and `rawShape`
4741
5140
  * (an arbitrary embedded schema with no fixed kind) projects to `'json'`.
5141
+ * `functionShape` projects to `'function'`.
4742
5142
  *
4743
5143
  * A hand-authored node carrying an unrecognized discriminant is REFUSED rather
4744
5144
  * than answered out of type, which keeps the declared non-optional
@@ -4759,7 +5159,7 @@ function selectClosestFaults(reports) {
4759
5159
  function shapeToKind(shape) {
4760
5160
  return readValue(() => {
4761
5161
  switch (shape.category) {
4762
- case "string": return "string";
5162
+ case "string": return INTRINSICS.own(shape, "date") && shape.date === true ? "date" : "string";
4763
5163
  case "number": return INTRINSICS.own(shape, "integer") && shape.integer === true ? "integer" : "number";
4764
5164
  case "boolean": return "boolean";
4765
5165
  case "null": return "null";
@@ -4769,6 +5169,7 @@ function shapeToKind(shape) {
4769
5169
  case "union": return "union";
4770
5170
  case "json": return "json";
4771
5171
  case "shape": return "shape";
5172
+ case "function": return "function";
4772
5173
  case "optional": return shapeToKind(shape.inner);
4773
5174
  case "nullable": return shapeToKind(shape.inner);
4774
5175
  case "raw": return "json";
@@ -4842,9 +5243,14 @@ function* encodeParts(members, keys, encodings) {
4842
5243
  /**
4843
5244
  * Builds bounded escaped preview parts without splitting a surrogate pair.
4844
5245
  *
5246
+ * @remarks
5247
+ * Each token is one code point's escape: its `JSON.stringify` form, or a `\u` sequence for DEL
5248
+ * (U+007F), a C1 control (U+0080 to U+009F), U+2028, or U+2029. The parts end with `…` when a
5249
+ * token does not fit, and otherwise with the closing quote of a quoted source.
5250
+ *
4845
5251
  * @param source - The source text
4846
5252
  * @param index - The next UTF-16 offset
4847
- * @param capacity - The unused preview width
5253
+ * @param capacity - The UTF-16 code units left for tokens; the closing quote or `…` takes one more
4848
5254
  * @param quoted - Whether the final part closes a string quote
4849
5255
  * @returns The escaped parts with their closing quote or truncation mark
4850
5256
  *
@@ -4856,11 +5262,13 @@ function* encodeParts(members, keys, encodings) {
4856
5262
  function previewParts(source, index, capacity, quoted) {
4857
5263
  const available = INTRINSICS.min(capacity, 64);
4858
5264
  const first = source[index];
4859
- if (index >= source.length || first === void 0) return quoted ? [available > 0 ? "\"" : "…"] : [];
5265
+ if (index >= source.length || first === void 0) return quoted ? ["\""] : [];
4860
5266
  const second = index + 1 < source.length ? source[index + 1] : void 0;
4861
5267
  const paired = first >= "\ud800" && first <= "\udbff" && second !== void 0 && second >= "\udc00" && second <= "\udfff";
4862
5268
  const character = paired ? `${first}${second}` : first;
4863
- const encoded = INTRINSICS.stringify(character);
5269
+ const control = character >= "" && character <= "Ÿ" ? INTRINSICS.reflect.apply(INTRINSICS.find, "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ", [(entry) => entry === character]) : -1;
5270
+ const code = 127 + control;
5271
+ const encoded = control >= 0 ? `"\\u00${"0123456789abcdef"[INTRINSICS.floor(code / 16)] ?? ""}${"0123456789abcdef"[code % 16] ?? ""}"` : character === "\u2028" ? "\"\\u2028\"" : character === "\u2029" ? "\"\\u2029\"" : INTRINSICS.stringify(character);
4864
5272
  const length = encoded.length - 2;
4865
5273
  if (length > available) return ["…"];
4866
5274
  const characters = INTRINSICS.from(iterateIndices(() => length), (offset) => encoded[offset + 1]);
@@ -4886,6 +5294,11 @@ function buildPositions(names) {
4886
5294
  /**
4887
5295
  * Derives the bit mask of names present in an indexed lookup.
4888
5296
  *
5297
+ * @remarks
5298
+ * Takes `names` as the array it declares and reads each present index once, in order,
5299
+ * through the captured fold, so a hole adds no bit. An array-like that is not an array
5300
+ * is outside this contract.
5301
+ *
4889
5302
  * @param names - Names to observe in order
4890
5303
  * @param positions - The bit position of each declared name
4891
5304
  * @returns The combined signed 32-bit mask
@@ -4896,8 +5309,7 @@ function buildPositions(names) {
4896
5309
  * ```
4897
5310
  */
4898
5311
  function readPresence(names, positions) {
4899
- return INTRINSICS.reflect.apply(INTRINSICS.reduce, iterateIndices(() => names.length), [(mask, index) => {
4900
- const name = names[index];
5312
+ return INTRINSICS.reflect.apply(INTRINSICS.fold, names, [(mask, name) => {
4901
5313
  if (name === void 0 || !INTRINSICS.own(positions, name)) return mask;
4902
5314
  const position = positions[name];
4903
5315
  return position === void 0 ? mask : mask | 1 << position;
@@ -4948,7 +5360,10 @@ function extractForms(schema) {
4948
5360
  if (schema === void 0) return [];
4949
5361
  const anyOf = INTRINSICS.own(schema, "anyOf") ? schema.anyOf : void 0;
4950
5362
  const oneOf = INTRINSICS.own(schema, "oneOf") ? schema.oneOf : void 0;
4951
- return [schema, ...anyOf ?? oneOf ?? []];
5363
+ const arms = isArray(anyOf) ? anyOf : isArray(oneOf) ? oneOf : [];
5364
+ const members = INTRINSICS.from(iterateIndices(() => arms.length), (index) => arms[index]);
5365
+ const forms = INTRINSICS.from(iterateIndices(() => members.length + 1), (index) => index === 0 ? schema : members[index - 1]);
5366
+ return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(forms), [(form) => form !== void 0]);
4952
5367
  }
4953
5368
  /**
4954
5369
  * Extracts the part of a schema a path reaches, through properties, array items, record values,
@@ -4973,15 +5388,19 @@ function extractForms(schema) {
4973
5388
  * ```
4974
5389
  */
4975
5390
  function extractSchema(schema, path) {
4976
- const nodes = path.reduce((parents, key) => Array.from(new Set(parents.flatMap((node) => extractForms(node)).map((form) => {
4977
- const properties = INTRINSICS.own(form, "properties") ? form.properties : void 0;
4978
- const additional = INTRINSICS.own(form, "additionalProperties") ? form.additionalProperties : void 0;
4979
- return properties !== void 0 && INTRINSICS.own(properties, key) ? properties[key] : isRecord(additional) ? additional : INTRINSICS.own(form, "items") ? form.items : void 0;
4980
- }).filter((child) => child !== void 0))), [schema]);
5391
+ const nodes = INTRINSICS.reflect.apply(INTRINSICS.fold, path, [(parents, key) => {
5392
+ const forms = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(parents), [(node) => extractForms(node)]);
5393
+ const children = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(forms), [(form) => {
5394
+ const properties = INTRINSICS.own(form, "properties") ? form.properties : void 0;
5395
+ const additional = INTRINSICS.own(form, "additionalProperties") ? form.additionalProperties : void 0;
5396
+ return properties !== void 0 && INTRINSICS.own(properties, key) ? properties[key] : isRecord(additional) ? additional : INTRINSICS.own(form, "items") ? form.items : void 0;
5397
+ }])), [(child) => child !== void 0]);
5398
+ return INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(children), [(child, index) => INTRINSICS.reflect.apply(INTRINSICS.find, children, [(other) => other === child]) === index]);
5399
+ }, [schema]]);
4981
5400
  const first = nodes[0];
4982
5401
  if (nodes.length < 2) return first;
4983
5402
  const encoded = canonicalStringify(first);
4984
- return encoded !== void 0 && nodes.every((node) => canonicalStringify(node) === encoded) ? first : void 0;
5403
+ return encoded !== void 0 && !INTRINSICS.reflect.apply(INTRINSICS.some, nodes, [(node) => canonicalStringify(node) !== encoded]) ? first : void 0;
4985
5404
  }
4986
5405
  /**
4987
5406
  * Renders a path as text, encoding what a caller could have sent and eliding the middle of a long
@@ -5003,13 +5422,15 @@ function extractSchema(schema, path) {
5003
5422
  * ```
5004
5423
  */
5005
5424
  function renderPath(path) {
5006
- const segments = path.map((segment) => /^[\w$-]{1,64}$/u.test(segment) ? segment : preview(segment));
5007
- const text = segments.join(".");
5008
- return segments.length <= 4 || text.length <= 120 ? text : [
5009
- ...segments.slice(0, 1),
5010
- "…",
5011
- ...segments.slice(-3)
5012
- ].join(".");
5425
+ const segments = INTRINSICS.from(iterateIndices(() => path.length), (index) => {
5426
+ const segment = path[index];
5427
+ if (segment === void 0) return "";
5428
+ return matchesPattern(/^[\w$-]{1,64}$/u, segment) ? segment : preview(segment);
5429
+ });
5430
+ const text = INTRINSICS.reflect.apply(INTRINSICS.join, segments, ["."]);
5431
+ if (segments.length <= 4 || text.length <= 120) return text;
5432
+ const elided = INTRINSICS.from(iterateIndices(() => 5), (index) => index === 0 ? segments[0] ?? "" : index === 1 ? "…" : segments[segments.length - 5 + index] ?? "");
5433
+ return INTRINSICS.reflect.apply(INTRINSICS.join, elided, ["."]);
5013
5434
  }
5014
5435
  /**
5015
5436
  * Renders a list as text, naming at most `FAULT_LIST_LIMIT` of its entries and counting the rest.
@@ -5025,18 +5446,20 @@ function renderPath(path) {
5025
5446
  * ```
5026
5447
  */
5027
5448
  function renderList(entries) {
5028
- const listed = entries.slice(0, 12).join(", ");
5029
- return entries.length > 12 ? `${listed} and ${String(entries.length - 12)} more` : listed;
5449
+ const listed = INTRINSICS.reflect.apply(INTRINSICS.join, limitEntries(entries, 12), [", "]);
5450
+ return entries.length > 12 ? `${listed} and ${INTRINSICS.text(entries.length - 12)} more` : listed;
5030
5451
  }
5031
5452
  /**
5032
5453
  * Renders a schema as a short summary of what to send, such as `{"city": string, "note"?: string}`.
5033
5454
  *
5034
5455
  * @remarks
5035
5456
  * An object lists its required keys first and marks the rest with `?`, at most `FAULT_LIST_LIMIT`
5036
- * of them. A leaf or array keeps its numeric bounds and pattern, a union joins its forms with ` | `,
5457
+ * of them. A leaf or array keeps its numeric bounds, pattern, and format, a union joins its forms with ` | `,
5037
5458
  * and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
5038
5459
  * below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
5039
5460
  * `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
5461
+ * A schema with an own `not` reads `function` when its `format` is `'function'` and `never`
5462
+ * otherwise.
5040
5463
  *
5041
5464
  * @param schema - The schema to summarize
5042
5465
  * @param room - The characters the summary can take. Default: `FAULT_SCHEMA_LIMIT`
@@ -5051,40 +5474,44 @@ function renderList(entries) {
5051
5474
  */
5052
5475
  function renderForm(schema, room = 160) {
5053
5476
  const deep = room >= 16;
5054
- const inner = Math.floor(room / 2);
5477
+ const inner = INTRINSICS.floor(room / 2);
5055
5478
  const anyOf = INTRINSICS.own(schema, "anyOf") ? schema.anyOf : void 0;
5056
5479
  const oneOf = INTRINSICS.own(schema, "oneOf") ? schema.oneOf : void 0;
5057
- const forms = anyOf ?? oneOf;
5058
- const required = (INTRINSICS.own(schema, "required") ? schema.required : void 0) ?? [];
5059
- const entries = Object.entries((INTRINSICS.own(schema, "properties") ? schema.properties : void 0) ?? {});
5480
+ const forms = isArray(anyOf) ? anyOf : isArray(oneOf) ? oneOf : void 0;
5481
+ const required = collectMembers((INTRINSICS.own(schema, "required") ? schema.required : void 0) ?? []);
5482
+ const properties = (INTRINSICS.own(schema, "properties") ? schema.properties : void 0) ?? {};
5483
+ const keys = INTRINSICS.keys(properties);
5060
5484
  const type = INTRINSICS.own(schema, "type") ? schema.type : void 0;
5061
5485
  const enumeration = INTRINSICS.own(schema, "enum") ? schema.enum : void 0;
5062
5486
  const additional = INTRINSICS.own(schema, "additionalProperties") ? schema.additionalProperties : void 0;
5063
- const listed = (deep ? entries : []).toSorted(([left], [right]) => Number(required.includes(right)) - Number(required.includes(left))).slice(0, 12).map(([key, child]) => `${preview(key)}${required.includes(key) ? "" : "?"}: ${renderForm(child, inner)}`);
5064
- const left = entries.length - listed.length;
5487
+ const negated = INTRINSICS.own(schema, "not");
5488
+ const callable = INTRINSICS.own(schema, "format") && schema.format === "function";
5489
+ const ordered = deep ? INTRINSICS.reflect.apply(INTRINSICS.order, INTRINSICS.from(iterateIndices(() => keys.length), (index) => keys[index] ?? ""), [(left, right) => INTRINSICS.numeric(matchesMember(required, right)) - INTRINSICS.numeric(matchesMember(required, left))]) : [];
5490
+ const listed = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(limitEntries(ordered, 12)), [(key) => `${preview(key)}${matchesMember(required, key) ? "" : "?"}: ${renderForm(properties[key] ?? {}, inner)}`]);
5491
+ const left = keys.length - listed.length;
5065
5492
  const child = type === "array" ? INTRINSICS.own(schema, "items") ? schema.items : void 0 : isRecord(additional) ? additional : void 0;
5066
- const bounds = Object.entries(schema).filter(([key]) => [
5493
+ const bounds = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.keys(schema)), [(key) => INTRINSICS.reflect.apply(INTRINSICS.some, [
5067
5494
  "minLength",
5068
5495
  "maxLength",
5069
5496
  "minimum",
5070
5497
  "maximum",
5071
5498
  "minItems",
5072
5499
  "maxItems",
5073
- "pattern"
5074
- ].includes(key)).map(([key, value]) => `${key} ${preview(value)}`);
5075
- return truncateFaultText(forms !== void 0 ? deep ? forms.map((form) => renderForm(form, inner)).join(" | ") : "any" : enumeration !== void 0 ? enumeration.map((value) => preview(value)).join(" | ") : listed.length > 0 ? `{${[...listed, ...left > 0 ? [`and ${String(left)} more`] : []].join(", ")}}` : [
5076
- type === void 0 ? entries.length > 0 ? "object" : "any" : JSON_SCHEMA_TYPES.some((name) => name === type) ? type : preview(type),
5077
- ...deep && child !== void 0 ? [` of ${renderForm(child, inner)}`] : [],
5078
- ...bounds.length > 0 ? [` (${bounds.join(", ")})`] : []
5079
- ].join(""), room);
5500
+ "pattern",
5501
+ "format"
5502
+ ], [(name) => name === key])])), [(key) => `${key} ${preview(INTRINSICS.reflect.read(schema, key))}`]);
5503
+ const word = type === void 0 ? keys.length > 0 ? "object" : "any" : INTRINSICS.reflect.apply(INTRINSICS.some, JSON_SCHEMA_TYPES, [(name) => name === type]) ? INTRINSICS.text(type) : preview(type);
5504
+ return truncateFaultText(negated ? callable ? "function" : "never" : forms !== void 0 ? deep ? INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(forms), [(form) => renderForm(form, inner)]), [" | "]) : "any" : enumeration !== void 0 ? INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(enumeration), [(value) => preview(value)]), [" | "]) : listed.length > 0 ? `{${INTRINSICS.reflect.apply(INTRINSICS.join, listed, [", "])}${left > 0 ? `, and ${INTRINSICS.text(left)} more` : ""}}` : `${word}${deep && child !== void 0 ? ` of ${renderForm(child, inner)}` : ""}${bounds.length > 0 ? ` (${INTRINSICS.reflect.apply(INTRINSICS.join, bounds, [", "])})` : ""}`, room);
5080
5505
  }
5081
5506
  /**
5082
5507
  * Describes one fault as the line a caller corrects from, naming what to send where the schema
5083
5508
  * says.
5084
5509
  *
5085
5510
  * @remarks
5086
- * Each line opens with the fault's path (or `value` at the root) and reason. An `extra` fault lists
5087
- * its parent's keys only when the declaring arms agree. A literal names candidates only where
5511
+ * Each line opens with the fault's path (or `value` at the root) and reason. A `hidden` fault says
5512
+ * the member is not enumerable and to send it as a plain data member. An `extra` fault carrying
5513
+ * `symbol` names the symbol key and lists no declared key; another `extra` fault lists its
5514
+ * parent's keys only when no array form sits at the parent and the declaring arms agree. A literal names candidates only where
5088
5515
  * the declarations agree; lists are deduplicated and bounded. A received preview stays as written
5089
5516
  * within PREVIEW_LIMIT and without control or line-separator characters; otherwise it is encoded
5090
5517
  * through preview. Received, constraint, and limit details read only own fields. A `variant` or
@@ -5106,39 +5533,52 @@ function renderForm(schema, room = 160) {
5106
5533
  function describeFaultLine(fault, schema) {
5107
5534
  const path = extractPath(fault);
5108
5535
  const head = `${renderPath(path) || "value"}: ${fault.reason}`;
5536
+ if (fault.reason === "hidden") return `${head}; this member is not enumerable, send it as a plain data member`;
5537
+ const detail = "received" in fault && INTRINSICS.own(fault, "received") ? fault.received : "symbol" in fault && INTRINSICS.own(fault, "symbol") ? fault.symbol : void 0;
5538
+ const encoded = detail !== void 0 && detail.length <= 64 && !matchesPattern(/[\p{Cc}\p{Zl}\p{Zp}]/u, detail) ? detail : preview(detail);
5539
+ if (fault.reason === "extra" && detail !== void 0) return `${head}; symbol key ${encoded} is not declared, remove it`;
5109
5540
  if (fault.reason === "extra") {
5110
- const declarations = extractForms(extractSchema(schema, path.slice(0, -1))).filter((form) => INTRINSICS.own(form, "properties") && form.properties !== void 0).map((form) => Object.keys(form.properties ?? {}));
5541
+ const forms = extractForms(extractSchema(schema, INTRINSICS.from(iterateIndices(() => path.length - 1), (index) => path[index] ?? "")));
5542
+ const declarations = INTRINSICS.reflect.apply(INTRINSICS.some, forms, [(form) => INTRINSICS.own(form, "items") || INTRINSICS.own(form, "type") && form.type === "array"]) ? [] : INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(forms), [(form) => INTRINSICS.own(form, "properties") && form.properties !== void 0])), [(form) => INTRINSICS.keys(form.properties ?? {})]);
5111
5543
  const first = declarations[0] ?? [];
5112
- const keys = declarations.every((declared) => declared.length === first.length && declared.every((key) => first.includes(key))) ? first : [];
5113
- 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(keys.map((key) => renderPath([key])))}`;
5544
+ const keys = INTRINSICS.reflect.apply(INTRINSICS.some, declarations, [(declared) => declared.length !== first.length || INTRINSICS.reflect.apply(INTRINSICS.some, declared, [(key) => !INTRINSICS.reflect.apply(INTRINSICS.some, first, [(name) => name === key])])]) ? [] : first;
5545
+ return keys.length === 0 ? `${head}; this key is not declared, remove it` : `${head}; this key is not declared, remove it or use a declared key: ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(keys), [(key) => renderPath([key])]))}`;
5114
5546
  }
5115
5547
  const node = extractSchema(schema, path);
5116
5548
  const anyOf = node !== void 0 && INTRINSICS.own(node, "anyOf") ? node.anyOf : void 0;
5117
5549
  const oneOf = node !== void 0 && INTRINSICS.own(node, "oneOf") ? node.oneOf : void 0;
5118
5550
  if (fault.reason === "variant" || fault.reason === "oneOf") {
5119
5551
  const count = fault.reason === "variant" ? fault.variants : oneOf?.length;
5120
- const forms = count === void 0 ? "the declared forms" : `the ${String(count)} declared forms`;
5121
- const claim = fault.reason === "oneOf" && fault.matched > 0 ? `the value matches ${String(fault.matched)} of ${forms} and must match exactly one` : `the value matches none of ${forms}`;
5552
+ const forms = count === void 0 ? "the declared forms" : `the ${INTRINSICS.text(count)} declared forms`;
5553
+ const claim = fault.reason === "oneOf" && fault.matched > 0 ? `the value matches ${INTRINSICS.text(fault.matched)} of ${forms} and must match exactly one` : `the value matches none of ${forms}`;
5122
5554
  const declared = anyOf ?? oneOf ?? [];
5123
- const shown = declared.slice(0, 12);
5124
- const room = Math.min(160, Math.floor(FAULT_TEXT_LIMIT / 2 / Math.max(shown.length, 1)));
5555
+ const shown = limitEntries(declared, 12);
5556
+ const room = INTRINSICS.min(160, INTRINSICS.floor(FAULT_TEXT_LIMIT / 2 / INTRINSICS.max(shown.length, 1)));
5125
5557
  const more = declared.length - shown.length;
5126
- const summary = shown.length === 0 ? "" : `, one of: ${shown.map((form) => renderForm(form, room)).join(" or ")}${more > 0 ? ` and ${String(more)} more` : ""}`;
5127
- return `${head}; ${claim}${fault.key === void 0 ? "" : `; discriminator ${preview(fault.key)} expects ${renderList((fault.expected ?? []).map((value) => preview(value)))}`}; send it exactly as the schema declares${summary}`;
5128
- }
5129
- const candidates = fault.expected === "literal" ? extractForms(node).flatMap((form) => [...(INTRINSICS.own(form, "enum") ? form.enum : void 0) ?? [], ...INTRINSICS.own(form, "type") && form.type === "null" ? [null] : []]) : [];
5558
+ const summary = shown.length === 0 ? "" : `, one of: ${INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(shown), [(form) => renderForm(form, room)]), [" or "])}${more > 0 ? ` and ${INTRINSICS.text(more)} more` : ""}`;
5559
+ return `${head}; ${claim}${fault.key === void 0 ? "" : `; discriminator ${preview(fault.key)} expects ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(fault.expected ?? []), [(value) => preview(value)]))}`}; send it exactly as the schema declares${summary}`;
5560
+ }
5561
+ const candidates = fault.expected === "literal" ? INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(extractForms(node)), [(form) => {
5562
+ const values = (INTRINSICS.own(form, "enum") ? form.enum : void 0) ?? [];
5563
+ const nullable = INTRINSICS.own(form, "type") && form.type === "null";
5564
+ return INTRINSICS.from(iterateIndices(() => values.length + (nullable ? 1 : 0)), (index) => index < values.length ? values[index] : null);
5565
+ }]) : [];
5566
+ const seen = new INTRINSICS.set();
5567
+ const distinct = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(candidates), [(value) => {
5568
+ if (matchesMember(seen, value)) return false;
5569
+ admitMember(seen, value);
5570
+ return true;
5571
+ }]);
5130
5572
  const description = node !== void 0 && INTRINSICS.own(node, "description") ? node.description : void 0;
5131
- const received = "received" in fault && INTRINSICS.own(fault, "received") ? fault.received : void 0;
5132
- const shown = received !== void 0 && received.length <= 64 && !/[\p{Cc}\p{Zl}\p{Zp}]/u.test(received) ? received : preview(received);
5133
- return [
5573
+ return INTRINSICS.reflect.apply(INTRINSICS.join, INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView([
5134
5574
  head,
5135
5575
  `expected ${fault.expected}`,
5136
- ...received !== void 0 ? [`received ${shown}`] : [],
5137
- ..."constraint" in fault && INTRINSICS.own(fault, "constraint") ? [`constraint ${fault.constraint}`] : [],
5138
- ..."limit" in fault && INTRINSICS.own(fault, "limit") && fault.limit !== void 0 ? [`limit ${preview(fault.limit)}`] : [],
5139
- ...description === void 0 ? [] : [`description ${preview(description)}`],
5140
- ...candidates.length > 0 ? [`send one of ${renderList(Array.from(new Set(candidates), (value) => preview(value)))}`] : []
5141
- ].join("; ");
5576
+ detail !== void 0 ? `received ${encoded}` : void 0,
5577
+ "constraint" in fault && INTRINSICS.own(fault, "constraint") ? `constraint ${fault.constraint}` : void 0,
5578
+ "limit" in fault && INTRINSICS.own(fault, "limit") && fault.limit !== void 0 ? `limit ${preview(fault.limit)}` : void 0,
5579
+ description === void 0 ? void 0 : `description ${preview(description)}`,
5580
+ distinct.length > 0 ? `send one of ${renderList(INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(distinct), [(value) => preview(value)]))}` : void 0
5581
+ ]), [(part) => part !== void 0]), ["; "]);
5142
5582
  }
5143
5583
  // src/core/JSONCloner.ts
5144
5584
  /**
@@ -5199,7 +5639,7 @@ var JSONCloner = class JSONCloner {
5199
5639
  this.#terminal = failure(poison);
5200
5640
  throw poison;
5201
5641
  }
5202
- this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered");
5642
+ this.#poison = this.#create("JSONCloner.clone: JSON cloning may not be reentered", { shape: "json" });
5203
5643
  const outcome = attempt(() => this.#execute(budget));
5204
5644
  const interruption = this.#terminal;
5205
5645
  if (interruption !== void 0) {
@@ -5210,7 +5650,7 @@ var JSONCloner = class JSONCloner {
5210
5650
  this.#terminal = outcome;
5211
5651
  return outcome.value;
5212
5652
  }
5213
- const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneJSONValue: failed to create an owned JSON snapshot");
5653
+ const error = this.#owns(outcome.error) ? outcome.error : this.#create("cloneJSONValue: failed to create an owned JSON snapshot", { shape: "json" });
5214
5654
  this.#fail(error);
5215
5655
  }
5216
5656
  #fail(error) {
@@ -5219,7 +5659,7 @@ var JSONCloner = class JSONCloner {
5219
5659
  throw error;
5220
5660
  }
5221
5661
  #execute(budget) {
5222
- if (!INTRINSICS.safe(budget.left)) this.#refuse("cloneJSONValue: invalid node budget");
5662
+ if (!INTRINSICS.safe(budget.left)) this.#refuse("cloneJSONValue: invalid node budget", { shape: "json" });
5223
5663
  budget.left = INTRINSICS.min(budget.left, CLONE_NODE_LIMIT);
5224
5664
  const root = this.#capture(this.#source, budget);
5225
5665
  this.#drain(budget);
@@ -5249,22 +5689,25 @@ var JSONCloner = class JSONCloner {
5249
5689
  }
5250
5690
  #capture(value, budget) {
5251
5691
  budget.left -= 1;
5252
- if (budget.left < 0) this.#refuse(`cloneJSONValue: snapshot exceeds the node limit ${CLONE_NODE_LIMIT}`, CLONE_NODE_LIMIT);
5692
+ if (budget.left < 0) this.#refuse(`cloneJSONValue: snapshot exceeds the node limit ${CLONE_NODE_LIMIT}`, {
5693
+ shape: "json",
5694
+ limit: CLONE_NODE_LIMIT
5695
+ });
5253
5696
  if (value === null || typeof value === "string" || typeof value === "boolean") return value;
5254
5697
  if (typeof value === "number") {
5255
5698
  if (INTRINSICS.finite(value)) return value;
5256
- this.#refuse("cloneJSONValue: number is not finite");
5699
+ this.#refusePath("number is not finite", preview(value));
5257
5700
  }
5258
5701
  if (typeof value === "object") return this.#captureObject(value);
5259
- this.#refuse(this.#pending.length === 0 ? "cloneJSONValue: value is not JSON data" : "cloneJSONValue: property is not JSON data");
5702
+ this.#refusePath(this.#pending.length === 0 ? "value is not JSON data" : "property is not JSON data", preview(value));
5260
5703
  }
5261
5704
  #captureObject(source) {
5262
- if (matchesVisited(this.#active, source)) this.#refuse("cloneJSONValue: cycle detected");
5705
+ if (matchesVisited(this.#active, source)) this.#refusePath("cycle detected", preview(source));
5263
5706
  const arrayOutcome = attempt(() => INTRINSICS.array(source));
5264
- if (isFailure(arrayOutcome)) this.#refuse("cloneJSONValue: value brand could not be inspected");
5707
+ if (isFailure(arrayOutcome)) this.#refusePath("value brand could not be inspected", preview(source));
5265
5708
  if (arrayOutcome.value) return this.#schedule(source, true);
5266
5709
  if (isRecord(source)) return this.#schedule(source, false);
5267
- this.#refuse("cloneJSONValue: object is not a plain record");
5710
+ this.#refusePath("object is not a plain record", preview(source));
5268
5711
  }
5269
5712
  #schedule(source, array) {
5270
5713
  const clone = array ? [] : INTRINSICS.create(null);
@@ -5280,45 +5723,42 @@ var JSONCloner = class JSONCloner {
5280
5723
  }
5281
5724
  #captureArray(source) {
5282
5725
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
5283
- if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
5726
+ if (isFailure(keysOutcome)) this.#refusePath("own keys could not be inspected", preview(source));
5284
5727
  const lengthOutcome = attempt(() => INTRINSICS.reflect.describe(source, "length"));
5285
- if (isFailure(lengthOutcome)) this.#refuse("cloneJSONValue: array length could not be inspected");
5728
+ if (isFailure(lengthOutcome)) this.#refusePath("array length could not be inspected", preview(source));
5286
5729
  const lengthDescriptor = lengthOutcome.value;
5287
- if (lengthDescriptor === void 0 || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refuse("cloneJSONValue: array is not intrinsic and dense");
5730
+ if (lengthDescriptor === void 0 || !INTRINSICS.own(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !INTRINSICS.integer(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) this.#refusePath("array is not intrinsic and dense", preview(source));
5288
5731
  const owned = collectMembers(keysOutcome.value);
5289
- if (!matchesMember(owned, "length")) this.#refuse("cloneJSONValue: array own keys are not exact");
5290
- if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refuse("cloneJSONValue: array own keys are not exact");
5732
+ if (!matchesMember(owned, "length")) this.#refusePath("array own keys are not exact", preview(source));
5733
+ if (keysOutcome.value.length !== lengthDescriptor.value + 1) this.#refusePath("array own keys are not exact", preview(source));
5291
5734
  return INTRINSICS.from(iterateIndices(() => lengthDescriptor.value), (index) => {
5292
5735
  const key = INTRINSICS.text(index);
5293
- if (!matchesMember(owned, key)) this.#refuse("cloneJSONValue: array own keys are not exact");
5736
+ if (!matchesMember(owned, key)) this.#refusePath("array own keys are not exact", preview(source));
5294
5737
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
5295
- if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: array index could not be inspected");
5738
+ if (isFailure(descriptorOutcome)) this.#refusePath("array index could not be inspected", "threw", key);
5296
5739
  const descriptor = descriptorOutcome.value;
5297
- if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: array index is not enumerable data");
5740
+ if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value") || descriptor.enumerable !== true) this.#refuseMember("array index is not enumerable data", descriptor, key);
5298
5741
  return [key, descriptor.value];
5299
5742
  });
5300
5743
  }
5301
5744
  #captureRecord(source) {
5302
5745
  const keysOutcome = attempt(() => INTRINSICS.reflect.members(source));
5303
- if (isFailure(keysOutcome)) this.#refuse("cloneJSONValue: own keys could not be inspected");
5746
+ if (isFailure(keysOutcome)) this.#refusePath("own keys could not be inspected", preview(source));
5304
5747
  const names = keysOutcome.value;
5305
5748
  return INTRINSICS.from(iterateIndices(() => names.length), (index) => {
5306
5749
  const key = names[index];
5307
- if (typeof key !== "string") this.#refuse("cloneJSONValue: record has a symbol property");
5750
+ if (typeof key !== "string") this.#refusePath(`record has a symbol property ${preview(key)}`, preview(key));
5308
5751
  const descriptorOutcome = attempt(() => INTRINSICS.reflect.describe(source, key));
5309
- if (isFailure(descriptorOutcome)) this.#refuse("cloneJSONValue: record property could not be inspected");
5752
+ if (isFailure(descriptorOutcome)) this.#refusePath("record property could not be inspected", "threw", key);
5310
5753
  const descriptor = descriptorOutcome.value;
5311
- if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) this.#refuse("cloneJSONValue: record property is not enumerable data");
5754
+ if (descriptor === void 0 || !INTRINSICS.own(descriptor, "value") || descriptor.enumerable !== true) this.#refuseMember("record property is not enumerable data", descriptor, key);
5312
5755
  return [key, descriptor.value];
5313
5756
  });
5314
5757
  }
5315
- #create(message, limit) {
5758
+ #create(message, context) {
5316
5759
  const error = new ContractError(message, {
5317
5760
  code: "clone",
5318
- context: {
5319
- shape: "json",
5320
- ...limit === void 0 ? {} : { limit }
5321
- }
5761
+ context
5322
5762
  });
5323
5763
  admitVisited(this.#owned, error);
5324
5764
  return error;
@@ -5326,10 +5766,30 @@ var JSONCloner = class JSONCloner {
5326
5766
  #owns(error) {
5327
5767
  return isObject(error) && matchesVisited(this.#owned, error);
5328
5768
  }
5329
- #refuse(message, limit) {
5769
+ #refuse(message, context) {
5330
5770
  const terminal = this.#terminal;
5331
5771
  if (terminal !== void 0 && isFailure(terminal)) throw terminal.error;
5332
- throw this.#create(message, limit);
5772
+ throw this.#create(message, context);
5773
+ }
5774
+ #refusePath(reason, received, key) {
5775
+ const path = this.#trace(key);
5776
+ this.#refuse(path.length === 0 ? `cloneJSONValue: ${reason}` : `cloneJSONValue: ${reason} at ${renderPath(path)}`, {
5777
+ shape: "json",
5778
+ path,
5779
+ received
5780
+ });
5781
+ }
5782
+ #refuseMember(reason, descriptor, key) {
5783
+ this.#refusePath(reason, descriptor === void 0 ? preview(void 0) : INTRINSICS.own(descriptor, "value") ? preview(descriptor.value) : "accessor", key);
5784
+ }
5785
+ #trace(key) {
5786
+ const pending = this.#pending;
5787
+ const size = pending[pending.length - 1]?.entries === void 0 && key === void 0 ? pending.length - 1 : pending.length;
5788
+ return INTRINSICS.from(iterateIndices(() => size), (index) => {
5789
+ const frame = pending[index];
5790
+ const entry = frame?.entries?.[frame.index - 1];
5791
+ return entry === void 0 ? key ?? "" : entry[0];
5792
+ });
5333
5793
  }
5334
5794
  static {
5335
5795
  INTRINSICS.freeze(JSONCloner.#emptyPending);
@@ -5543,6 +6003,7 @@ var ShapePass = class ShapePass {
5543
6003
  "min",
5544
6004
  "max",
5545
6005
  "pattern",
6006
+ "date",
5546
6007
  "description",
5547
6008
  "integer",
5548
6009
  "additionalProperties",
@@ -5825,6 +6286,7 @@ var ShapePass = class ShapePass {
5825
6286
  if (current.category === "string") {
5826
6287
  if (current.min !== void 0 && typeof current.min !== "number") return this.#refuse("validateShape: string min must be a number", "min");
5827
6288
  if (current.max !== void 0 && typeof current.max !== "number") return this.#refuse("validateShape: string max must be a number", "max");
6289
+ if (current.date !== void 0 && typeof current.date !== "boolean") return this.#refuse("validateShape: string date must be a boolean", "date");
5828
6290
  if (current.pattern !== void 0) {
5829
6291
  const pattern = current.pattern;
5830
6292
  if (!isRegExp(pattern)) return this.#refuse("validateShape: string pattern must be a RegExp", "pattern");
@@ -5949,6 +6411,21 @@ var ShapePass = class ShapePass {
5949
6411
  shape: "string"
5950
6412
  }
5951
6413
  });
6414
+ if (this.#domain === void 0 && current.date === true && current.pattern !== void 0) this.#domain = new ContractError("validateShape: a string shape declares date or pattern, never both", {
6415
+ code: "pattern",
6416
+ context: {
6417
+ path: pathOf(this.#path),
6418
+ shape: "string"
6419
+ }
6420
+ });
6421
+ if (this.#domain === void 0 && current.date === true && (typeof current.min === "number" && current.min > 10 || typeof current.max === "number" && current.max < 10)) this.#domain = new ContractError(`validateShape: a date string shape needs min and max to admit length 10`, {
6422
+ code: "range",
6423
+ context: {
6424
+ path: pathOf(this.#path),
6425
+ shape: "string",
6426
+ limit: 10
6427
+ }
6428
+ });
5952
6429
  }
5953
6430
  #inspect(source) {
5954
6431
  if (this.#structure !== void 0) return true;
@@ -5977,13 +6454,14 @@ var ShapePass = class ShapePass {
5977
6454
  for (const keyIndex of iterateIndices(() => keyList.length)) {
5978
6455
  const key = keyList[keyIndex];
5979
6456
  if (key === void 0) continue;
5980
- if (key !== "type" && key !== "description" && key !== "default" && key !== "enum" && key !== "minLength" && key !== "maxLength" && key !== "pattern" && key !== "format" && key !== "minimum" && key !== "maximum" && key !== "minItems" && key !== "maxItems" && key !== "items" && key !== "properties" && key !== "required" && key !== "additionalProperties" && key !== "anyOf" && key !== "oneOf") return this.#refuseSchema("validateShape: raw schema contains an unsupported keyword", stack, first, second, key);
6457
+ if (key !== "type" && key !== "description" && key !== "default" && key !== "enum" && key !== "minLength" && key !== "maxLength" && key !== "pattern" && key !== "format" && key !== "minimum" && key !== "maximum" && key !== "minItems" && key !== "maxItems" && key !== "items" && key !== "properties" && key !== "required" && key !== "additionalProperties" && key !== "anyOf" && key !== "oneOf" && key !== "not") return this.#refuseSchema("validateShape: raw schema contains an unsupported keyword", stack, first, second, key);
5981
6458
  }
5982
6459
  const category = INTRINSICS.own(schema, "type") ? schema.type : void 0;
5983
6460
  if (category !== void 0 && category !== "null" && category !== "boolean" && category !== "object" && category !== "array" && category !== "number" && category !== "integer" && category !== "string") return this.#refuseSchema("validateShape: raw schema type is outside the supported vocabulary", stack, first, second, "type");
5984
6461
  if (INTRINSICS.own(schema, "description") && schema.description !== void 0 && typeof schema.description !== "string") return this.#refuseSchema("validateShape: raw schema description must be a string", stack, first, second, "description");
5985
6462
  if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) return this.#refuseSchema("validateShape: raw schema default must be a JSON value", stack, first, second, "default");
5986
6463
  if (INTRINSICS.own(schema, "format") && schema.format !== void 0 && typeof schema.format !== "string") return this.#refuseSchema("validateShape: raw schema format must be a string", stack, first, second, "format");
6464
+ if (INTRINSICS.own(schema, "not") && (!isRecord(schema.not) || INTRINSICS.reflect.members(schema.not).length > 0)) return this.#refuseSchema("validateShape: raw schema not must be the empty schema", stack, first, second, "not");
5987
6465
  if (INTRINSICS.own(schema, "pattern") && schema.pattern !== void 0) {
5988
6466
  if (typeof schema.pattern !== "string") return this.#refuseSchema("validateShape: raw schema pattern must be a string", stack, first, second, "pattern");
5989
6467
  if (isFailure(attempt(() => INTRINSICS.reflect.apply(INTRINSICS.pattern, void 0, [schema.pattern])))) return this.#refuseSchema("validateShape: raw schema pattern must be valid", stack, first, second, "pattern");
@@ -6711,6 +7189,7 @@ var ShapeCloner = class ShapeCloner {
6711
7189
  case "nullable": return this.#captureNullable(source, path, budget);
6712
7190
  case "json": return this.#captureSimple(source, path, "json");
6713
7191
  case "shape": return this.#captureSimple(source, path, "shape");
7192
+ case "function": return this.#captureSimple(source, path, "function");
6714
7193
  case "raw": return this.#captureRaw(source, path, budget);
6715
7194
  default: throw this.#create("validateShape: every node must be a recognized shape", {
6716
7195
  code: "structure",
@@ -6813,11 +7292,13 @@ var ShapeCloner = class ShapeCloner {
6813
7292
  const min = this.#captureField(source, "min", path);
6814
7293
  const max = this.#captureField(source, "max", path);
6815
7294
  const pattern = this.#capturePattern(source, path);
7295
+ const date = this.#captureField(source, "date", path);
6816
7296
  const description = this.#captureField(source, "description", path);
6817
7297
  const fields = {
6818
7298
  category: "string",
6819
7299
  ...min === void 0 ? {} : { min },
6820
7300
  ...max === void 0 ? {} : { max },
7301
+ ...date === void 0 ? {} : { date },
6821
7302
  ...description === void 0 ? {} : { description }
6822
7303
  };
6823
7304
  if (pattern === void 0) return fields;
@@ -6857,6 +7338,10 @@ var ShapeCloner = class ShapeCloner {
6857
7338
  category: "shape",
6858
7339
  ...description === void 0 ? {} : { description }
6859
7340
  };
7341
+ if (category === "function") return {
7342
+ category: "function",
7343
+ ...description === void 0 ? {} : { description }
7344
+ };
6860
7345
  return {
6861
7346
  category: "json",
6862
7347
  ...description === void 0 ? {} : { description }
@@ -7325,7 +7810,10 @@ var ShapeCloner = class ShapeCloner {
7325
7810
  *
7326
7811
  * @param value - The unknown value to validate and snapshot
7327
7812
  * @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
7328
- * @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
7813
+ * @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails; a
7814
+ * refusal that names a member or a container carries its `path` and `received`, and its message
7815
+ * ends with ` at ` and the rendered path, except at the root, where the path is `[]` and the
7816
+ * message has no suffix
7329
7817
  *
7330
7818
  * @example
7331
7819
  * ```ts
@@ -7350,7 +7838,9 @@ function cloneJSONValue(value) {
7350
7838
  *
7351
7839
  * @param value - The unknown record value to validate and snapshot
7352
7840
  * @returns A deeply cloned and frozen JSON record
7353
- * @throws {ContractError} When the root is not a record, nested data is inexact, or traversal fails
7841
+ * @throws {ContractError} When the root is not a record, nested data is inexact, or traversal
7842
+ * fails; a nested refusal is the one {@link cloneJSONValue} raises, `cloneJSONValue:` prefix and path
7843
+ * included
7354
7844
  *
7355
7845
  * @example
7356
7846
  * ```ts
@@ -7361,7 +7851,11 @@ function cloneJSONRecord(value) {
7361
7851
  return contain(() => {
7362
7852
  if (!isRecord(value)) throw new ContractError("cloneJSONRecord: value is not a plain record", {
7363
7853
  code: "clone",
7364
- context: { shape: "json" }
7854
+ context: {
7855
+ shape: "json",
7856
+ path: [],
7857
+ received: preview(value)
7858
+ }
7365
7859
  });
7366
7860
  const clone = cloneJSONValue(value);
7367
7861
  if (!isRecord(clone)) throw new ContractError("cloneJSONRecord: cloned value is not a record", {
@@ -7464,11 +7958,10 @@ var LazyGuard = class {
7464
7958
  // src/core/combinators.ts
7465
7959
  function arrayOf(elementGuard) {
7466
7960
  return (value) => holds(() => {
7467
- if (!isArray(value)) return false;
7961
+ if (!INTRINSICS.array(value)) return false;
7468
7962
  const entries = readArrayEntries(value);
7469
7963
  if (isFailure(entries) || !entries.value.dense) return false;
7470
- for (const index of iterateIndices(() => entries.value.entries.length)) if (!elementGuard(entries.value.entries[index])) return false;
7471
- return true;
7964
+ return !INTRINSICS.reflect.apply(INTRINSICS.some, entries.value.entries, [(entry) => !elementGuard(entry)]);
7472
7965
  });
7473
7966
  }
7474
7967
  function tupleOf(...guards) {
@@ -7796,13 +8289,7 @@ function complementOf(base, excluded) {
7796
8289
  });
7797
8290
  }
7798
8291
  function unionOf(...guards) {
7799
- return (value) => {
7800
- for (const index of iterateIndices(() => guards.length)) {
7801
- const guard = guards[index];
7802
- if (guard !== void 0 && holds(() => guard(value))) return true;
7803
- }
7804
- return false;
7805
- };
8292
+ return (value) => INTRINSICS.reflect.apply(INTRINSICS.some, guards, [(guard) => guard !== void 0 && holds(() => guard(value))]);
7806
8293
  }
7807
8294
  function intersectionOf(...guards) {
7808
8295
  return (value) => holds(() => {
@@ -8174,7 +8661,7 @@ function parseJSONValue(value) {
8174
8661
  function parseEnum(value, allowed) {
8175
8662
  const outcome = readArrayEntries(allowed);
8176
8663
  if (isFailure(outcome) || !outcome.value.dense) return void 0;
8177
- if (!holds(() => matchesMember(collectMembers(outcome.value.entries), value))) return void 0;
8664
+ if (!holds(() => INTRINSICS.reflect.apply(INTRINSICS.some, outcome.value.entries, [(entry) => entry === value || INTRINSICS.same(entry, value)]))) return void 0;
8178
8665
  return isLiteralValue(value) ? value : void 0;
8179
8666
  }
8180
8667
  /**
@@ -8400,7 +8887,7 @@ var EvaluationScope = class EvaluationScope {
8400
8887
  const scope = new EvaluationScope();
8401
8888
  INTRINSICS.reflect.apply(INTRINSICS.admit, EvaluationScope.#active, [scope]);
8402
8889
  try {
8403
- return scope.#evaluate(plan, value, path, clean);
8890
+ return plan(value, path);
8404
8891
  } finally {
8405
8892
  INTRINSICS.reflect.apply(INTRINSICS.remove, EvaluationScope.#active, [scope]);
8406
8893
  }
@@ -8416,6 +8903,43 @@ var EvaluationScope = class EvaluationScope {
8416
8903
  return answer;
8417
8904
  }
8418
8905
  };
8906
+ // src/core/KeyPlanCache.ts
8907
+ /**
8908
+ * Keeps the key plans one compiled closed-object guard learned from the key orders it accepted.
8909
+ *
8910
+ * @remarks
8911
+ * Its constructor takes the declared member guards of one object node. The guard calls the
8912
+ * {@link recall} method before its full walk and the {@link retain} method after a walk that
8913
+ * accepted. The cache learns only through the `retain` method, never evicts, and stops at
8914
+ * {@link KEY_PLAN_LIMIT} plans. Each plan is unfrozen and lives in the `#plans` field alone.
8915
+ * The `retain` method copies the plan list by index through the captured `Array.from`
8916
+ * function, so no array species is consulted.
8917
+ */
8918
+ var KeyPlanCache = class {
8919
+ #guards;
8920
+ #plans;
8921
+ constructor(guards) {
8922
+ this.#guards = guards;
8923
+ this.#plans = [];
8924
+ }
8925
+ /** Returns the plan kept for a key order, or `undefined` when none answers it. */
8926
+ recall(keys) {
8927
+ const found = INTRINSICS.reflect.apply(INTRINSICS.find, this.#plans, [matchesKeyPlan, keys]);
8928
+ return found === -1 ? void 0 : this.#plans[found];
8929
+ }
8930
+ /** Keeps the plan for an accepted key order while room remains and every key is declared. */
8931
+ retain(keys) {
8932
+ const plans = this.#plans;
8933
+ if (plans.length >= 4 || this.recall(keys) !== void 0) return;
8934
+ const plan = buildKeyPlan(keys, this.#guards);
8935
+ if (plan === void 0) return;
8936
+ const indices = {
8937
+ __proto__: null,
8938
+ length: plans.length + 1
8939
+ };
8940
+ this.#plans = INTRINSICS.from(indices, (_entry, index) => index < plans.length ? plans[index] ?? plan : plan);
8941
+ }
8942
+ };
8419
8943
  // src/core/RandomSource.ts
8420
8944
  /** Owns the changing state projected by one seeded random function. */
8421
8945
  var RandomSource = class {
@@ -8518,6 +9042,7 @@ var ContractCompiler = class ContractCompiler {
8518
9042
  static #emptyAudits = [];
8519
9043
  static #emptyReports = [];
8520
9044
  static #emptySeeds = [];
9045
+ static #function = INTRINSICS.freeze(() => void 0);
8521
9046
  static {
8522
9047
  INTRINSICS.freeze(ContractCompiler.#emptyStack);
8523
9048
  INTRINSICS.freeze(ContractCompiler.#emptyNodes);
@@ -8996,6 +9521,7 @@ var ContractCompiler = class ContractCompiler {
8996
9521
  ...owned.min !== void 0 ? { minLength: owned.min } : {},
8997
9522
  ...owned.max !== void 0 ? { maxLength: owned.max } : {},
8998
9523
  ...text !== void 0 ? { pattern: text } : {},
9524
+ ...owned.date === true ? { format: "date" } : {},
8999
9525
  ...owned.description !== void 0 ? { description: owned.description } : {}
9000
9526
  });
9001
9527
  }
@@ -9014,6 +9540,11 @@ var ContractCompiler = class ContractCompiler {
9014
9540
  ...owned.description !== void 0 ? { description: owned.description } : {}
9015
9541
  });
9016
9542
  case "json": return INTRINSICS.freeze({ ...owned.description !== void 0 ? { description: owned.description } : {} });
9543
+ case "function": return INTRINSICS.freeze({
9544
+ not: INTRINSICS.freeze({}),
9545
+ format: "function",
9546
+ ...owned.description !== void 0 ? { description: owned.description } : {}
9547
+ });
9017
9548
  case "literal": {
9018
9549
  const vocabulary = INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(owned.values), [(value) => value !== void 0]);
9019
9550
  return INTRINSICS.freeze({
@@ -9097,11 +9628,12 @@ var ContractCompiler = class ContractCompiler {
9097
9628
  return compiled;
9098
9629
  }
9099
9630
  #stringGuard(owned) {
9100
- return stringOf(INTRINSICS.rebase({
9631
+ const guard = stringOf(INTRINSICS.rebase({
9101
9632
  ...owned.min === void 0 ? {} : { min: owned.min },
9102
9633
  ...owned.max === void 0 ? {} : { max: owned.max },
9103
9634
  ...owned.pattern === void 0 ? {} : { pattern: owned.pattern }
9104
9635
  }, null));
9636
+ return owned.date === true ? whereOf(guard, matchesCalendarDate) : guard;
9105
9637
  }
9106
9638
  static #acceptShape(value) {
9107
9639
  return isSuccess(attempt(() => {
@@ -9122,13 +9654,18 @@ var ContractCompiler = class ContractCompiler {
9122
9654
  case "boolean": return isBoolean;
9123
9655
  case "null": return isNull;
9124
9656
  case "json": return isJSONValue;
9657
+ case "function": return isFunction;
9125
9658
  case "shape": return (value) => ContractCompiler.#acceptShape(value);
9126
9659
  case "literal": return literalOf(owned.values);
9127
9660
  case "array": {
9128
- const base = arrayOf(this.#guardAt(owned.items));
9129
- if (owned.min === void 0 && owned.max === void 0) return base;
9130
- const withinLength = boundsOf(owned.min, owned.max);
9131
- return whereOf(base, (value) => withinLength(value.length));
9661
+ const element = this.#guardAt(owned.items);
9662
+ const withinLength = owned.min === void 0 && owned.max === void 0 ? void 0 : boundsOf(owned.min, owned.max);
9663
+ return (value) => holds(() => {
9664
+ if (!INTRINSICS.array(value)) return false;
9665
+ const read = collectArrayEntries(value);
9666
+ if (!read.dense || !read.exact) return false;
9667
+ return !INTRINSICS.reflect.apply(INTRINSICS.some, read.entries, [(entry) => !element(entry)]) && (withinLength === void 0 || withinLength(read.entries.length));
9668
+ });
9132
9669
  }
9133
9670
  case "object": {
9134
9671
  const entries = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(INTRINSICS.keys(owned.properties)), [(key) => {
@@ -9151,44 +9688,48 @@ var ContractCompiler = class ContractCompiler {
9151
9688
  const maskable = required.length <= 31;
9152
9689
  const positions = buildPositions(maskable ? required : []);
9153
9690
  const full = maskable ? readPresence(required, positions) : 0;
9691
+ const plans = closed ? new KeyPlanCache(map) : void 0;
9154
9692
  return (value) => {
9155
9693
  if (!isRecord(value)) return false;
9156
- const keys = enumerableKeys(value);
9157
- if (keys === void 0) return false;
9158
- const outcome = attempt(() => {
9694
+ return holds(() => {
9695
+ const keys = INTRINSICS.keys(value);
9696
+ if (extra !== true && !matchesEnumerableKeys(value, keys)) return false;
9697
+ const plan = plans?.recall(keys);
9698
+ if (plan !== void 0) return INTRINSICS.reflect.apply(INTRINSICS.every, plan, [matchesStepGuard, value]);
9159
9699
  if (maskable) {
9160
9700
  if (readPresence(keys, positions) !== full) return false;
9161
9701
  } else {
9162
9702
  const present = collectMembers(keys);
9163
- for (const keyIndex of iterateIndices(() => required.length)) {
9164
- const key = required[keyIndex];
9165
- if (key === void 0) continue;
9166
- if (!matchesMember(present, key)) return false;
9167
- }
9703
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, required, [(key) => !matchesMember(present, key)])) return false;
9168
9704
  }
9169
- for (const keyIndex of iterateIndices(() => keys.length)) {
9170
- const key = keys[keyIndex];
9171
- if (key === void 0) continue;
9705
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, keys, [(key) => {
9172
9706
  const guard = INTRINSICS.own(map, key) ? map[key] : void 0;
9173
- if (guard !== void 0) {
9174
- if (!guard(value[key])) return false;
9175
- continue;
9176
- }
9177
- if (closed) return false;
9707
+ if (guard !== void 0) return !guard(value[key]);
9708
+ if (closed) return true;
9178
9709
  const observed = value[key];
9179
- if (additional !== void 0 && !additional(observed)) return false;
9180
- }
9710
+ return additional !== void 0 && !additional(observed);
9711
+ }])) return false;
9712
+ plans?.retain(keys);
9181
9713
  return true;
9182
9714
  });
9183
- return isSuccess(outcome) && outcome.value;
9184
9715
  };
9185
9716
  }
9186
9717
  case "union": {
9187
9718
  const guards = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(owned.variants), [(variant) => variant === void 0 ? [] : [this.#guardAt(variant)]]);
9719
+ const discriminated = this.#discriminate(owned);
9188
9720
  if (owned.mode === "oneOf") return (value) => {
9721
+ const arm = discriminated?.select(value);
9722
+ const named = arm === void 0 ? void 0 : guards[arm];
9723
+ if (named !== void 0) return holds(() => named(value));
9189
9724
  return INTRINSICS.reflect.apply(INTRINSICS.fold, guards, [(total, guard) => total + (guard(value) ? 1 : 0), 0]) === 1;
9190
9725
  };
9191
- return INTRINSICS.reflect.apply(unionOf, void 0, guards);
9726
+ const union = INTRINSICS.reflect.apply(unionOf, void 0, guards);
9727
+ if (discriminated === void 0) return union;
9728
+ return (value) => {
9729
+ const arm = discriminated.select(value);
9730
+ const named = arm === void 0 ? void 0 : guards[arm];
9731
+ return named !== void 0 ? holds(() => named(value)) : union(value);
9732
+ };
9192
9733
  }
9193
9734
  case "optional": return orOf(isUndefined, this.#guardAt(owned.inner));
9194
9735
  case "nullable": return nullableOf(this.#guardAt(owned.inner));
@@ -9224,7 +9765,7 @@ var ContractCompiler = class ContractCompiler {
9224
9765
  const owned = this.#node(index);
9225
9766
  switch (owned.category) {
9226
9767
  case "string": {
9227
- if (owned.min === void 0 && owned.max === void 0 && owned.pattern === void 0) return parseString;
9768
+ if (owned.min === void 0 && owned.max === void 0 && owned.pattern === void 0 && owned.date !== true) return parseString;
9228
9769
  const guard = this.#stringGuard(owned);
9229
9770
  return (value) => {
9230
9771
  const parsed = parseString(value);
@@ -9243,6 +9784,7 @@ var ContractCompiler = class ContractCompiler {
9243
9784
  case "boolean": return parseBoolean;
9244
9785
  case "null": return (value) => value === null ? null : void 0;
9245
9786
  case "json": return parseJSONValue;
9787
+ case "function": return (value) => isFunction(value) ? value : void 0;
9246
9788
  case "shape": return (value) => ContractCompiler.#acceptShape(value) ? value : void 0;
9247
9789
  case "literal": {
9248
9790
  const allowed = literalOf(owned.values);
@@ -9313,33 +9855,32 @@ var ContractCompiler = class ContractCompiler {
9313
9855
  const present = maskable ? void 0 : collectMembers(keys);
9314
9856
  const seen = present === void 0 ? readPresence(keys, positions) : 0;
9315
9857
  const selected = [];
9316
- for (const entryIndex of iterateIndices(() => entries.length)) {
9317
- const entry = entries[entryIndex];
9318
- if (entry === void 0) continue;
9858
+ if (INTRINSICS.reflect.apply(INTRINSICS.some, entries, [(entry, entryIndex) => {
9319
9859
  const raw = (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) ? void 0 : record[entry.key];
9320
9860
  if (raw === void 0) {
9321
- if (!entry.optional) return void 0;
9861
+ if (!entry.optional) return true;
9322
9862
  if (entry.fill !== void 0) {
9323
9863
  const fill = isObject(entry.fill) ? cloneJSONValue(entry.fill) : entry.fill;
9324
9864
  selected[selected.length] = [entry.key, entry.parse(fill)];
9325
9865
  }
9326
- continue;
9866
+ return false;
9327
9867
  }
9328
9868
  const parsed = entry.parse(raw);
9329
- if (parsed === void 0) return void 0;
9869
+ if (parsed === void 0) return true;
9330
9870
  selected[selected.length] = [entry.key, parsed];
9331
- }
9332
- if (open) for (const keyIndex of iterateIndices(() => keys.length)) {
9333
- const key = keys[keyIndex];
9334
- if (key === void 0) continue;
9335
- if (matchesMember(known, key)) continue;
9336
- if (additional === void 0) selected[selected.length] = [key, record[key]];
9337
- else {
9338
- const parsed = additional(record[key]);
9339
- if (parsed === void 0) return void 0;
9340
- selected[selected.length] = [key, parsed];
9871
+ return false;
9872
+ }])) return void 0;
9873
+ if (open && INTRINSICS.reflect.apply(INTRINSICS.some, keys, [(key) => {
9874
+ if (matchesMember(known, key)) return false;
9875
+ if (additional === void 0) {
9876
+ selected[selected.length] = [key, record[key]];
9877
+ return false;
9341
9878
  }
9342
- }
9879
+ const parsed = additional(record[key]);
9880
+ if (parsed === void 0) return true;
9881
+ selected[selected.length] = [key, parsed];
9882
+ return false;
9883
+ }])) return void 0;
9343
9884
  return INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [selected]) }), null);
9344
9885
  });
9345
9886
  if (isSuccess(outcome)) return outcome.value;
@@ -9429,13 +9970,14 @@ var ContractCompiler = class ContractCompiler {
9429
9970
  case "string": {
9430
9971
  const node = owned;
9431
9972
  const declared = owned.pattern;
9432
- const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0;
9973
+ const kind = owned.date === true ? "date" : "string";
9974
+ const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0 || owned.date === true;
9433
9975
  const pattern = declared === void 0 ? void 0 : ownPattern(declared, "compileAuditor");
9434
9976
  return (value, path) => {
9435
9977
  if (!isString(value)) return [{
9436
9978
  reason: "type",
9437
9979
  path,
9438
- expected: "string",
9980
+ expected: kind,
9439
9981
  received: preview(value)
9440
9982
  }];
9441
9983
  return refined ? buildStringFaults(node, value, path, pattern) : [];
@@ -9473,6 +10015,12 @@ var ContractCompiler = class ContractCompiler {
9473
10015
  expected: "json",
9474
10016
  received: preview(value)
9475
10017
  }];
10018
+ case "function": return (value, path) => isFunction(value) ? [] : [{
10019
+ reason: "type",
10020
+ path,
10021
+ expected: "function",
10022
+ received: preview(value)
10023
+ }];
9476
10024
  case "shape": return (value, path) => ContractCompiler.#acceptShape(value) ? [] : [{
9477
10025
  reason: "type",
9478
10026
  path,
@@ -9521,6 +10069,29 @@ var ContractCompiler = class ContractCompiler {
9521
10069
  appendEntries(faults, item(entries.value.entries[entryIndex], pathOf(path, INTRINSICS.text(entryIndex))));
9522
10070
  }
9523
10071
  appendEntries(faults, buildArrayFaults(node, entries.value.entries.length, path));
10072
+ if (entries.value.exact) return limitEntries(faults, 64);
10073
+ const snapshot = entries.value.entries;
10074
+ const members = readValue(() => INTRINSICS.reflect.members(value), "compileAuditor", {
10075
+ subject: "array",
10076
+ context: {
10077
+ path,
10078
+ shape: "array"
10079
+ }
10080
+ });
10081
+ for (const memberIndex of iterateIndices(() => members.length)) {
10082
+ const member = members[memberIndex];
10083
+ if (faults.length >= 64) break;
10084
+ if (isString(member)) {
10085
+ if (!INTRINSICS.own(snapshot, member)) faults[faults.length] = {
10086
+ reason: "extra",
10087
+ path: pathOf(path, member)
10088
+ };
10089
+ } else if (member !== void 0) faults[faults.length] = {
10090
+ reason: "extra",
10091
+ path,
10092
+ symbol: preview(member)
10093
+ };
10094
+ }
9524
10095
  return limitEntries(faults, 64);
9525
10096
  };
9526
10097
  }
@@ -9572,12 +10143,19 @@ var ContractCompiler = class ContractCompiler {
9572
10143
  const present = maskable ? void 0 : collectMembers(keys);
9573
10144
  const vocabulary = declared ?? collectMembers(declaredKeys);
9574
10145
  const seen = present === void 0 ? readPresence(keys, positions) : 0;
10146
+ const listed = present ?? collectMembers(keys);
10147
+ const outside = extra === true ? [] : INTRINSICS.reflect.apply(INTRINSICS.select, readIndexView(INTRINSICS.names(record)), [(name) => !matchesMember(listed, name)]);
10148
+ const concealed = collectMembers(outside);
9575
10149
  for (const entryIndex of iterateIndices(() => entries.length)) {
9576
10150
  const entry = entries[entryIndex];
9577
10151
  if (entry === void 0) continue;
9578
10152
  if (faults.length >= 64) return;
9579
10153
  if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
9580
- if (!entry.optional) faults[faults.length] = {
10154
+ if (matchesMember(concealed, entry.key)) faults[faults.length] = {
10155
+ reason: "hidden",
10156
+ path: pathOf(path, entry.key)
10157
+ };
10158
+ else if (!entry.optional) faults[faults.length] = {
9581
10159
  reason: "missing",
9582
10160
  path: pathOf(path, entry.key),
9583
10161
  expected: entry.kind
@@ -9601,6 +10179,24 @@ var ContractCompiler = class ContractCompiler {
9601
10179
  const observed = record[key];
9602
10180
  if (additional !== void 0) appendEntries(faults, additional(observed, pathOf(path, key)));
9603
10181
  }
10182
+ for (const nameIndex of iterateIndices(() => outside.length)) {
10183
+ const name = outside[nameIndex];
10184
+ if (name === void 0 || matchesMember(vocabulary, name)) continue;
10185
+ if (faults.length >= 64) return;
10186
+ faults[faults.length] = {
10187
+ reason: closed ? "extra" : "hidden",
10188
+ path: pathOf(path, name)
10189
+ };
10190
+ }
10191
+ const symbols = extra === true ? [] : INTRINSICS.symbols(record);
10192
+ for (const symbolIndex of iterateIndices(() => symbols.length)) {
10193
+ if (faults.length >= 64) return;
10194
+ faults[faults.length] = {
10195
+ reason: "extra",
10196
+ path,
10197
+ symbol: preview(symbols[symbolIndex])
10198
+ };
10199
+ }
9604
10200
  });
9605
10201
  if (isFailure(outcome)) {
9606
10202
  if (isContractError(outcome.error)) throw outcome.error;
@@ -9713,14 +10309,15 @@ var ContractCompiler = class ContractCompiler {
9713
10309
  case "string": {
9714
10310
  const node = owned;
9715
10311
  const declared = owned.pattern;
9716
- const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0;
10312
+ const kind = owned.date === true ? "date" : "string";
10313
+ const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0 || owned.date === true;
9717
10314
  const pattern = declared === void 0 ? void 0 : ownPattern(declared, "compileReporter");
9718
10315
  return (value, path) => {
9719
10316
  const parsed = parseString(value);
9720
10317
  if (parsed === void 0) return [{
9721
10318
  reason: "type",
9722
10319
  path,
9723
- expected: "string",
10320
+ expected: kind,
9724
10321
  received: preview(value)
9725
10322
  }];
9726
10323
  return refined ? buildStringFaults(node, parsed, path, pattern) : [];
@@ -9759,6 +10356,12 @@ var ContractCompiler = class ContractCompiler {
9759
10356
  expected: "json",
9760
10357
  received: preview(value)
9761
10358
  }];
10359
+ case "function": return (value, path) => isFunction(value) ? [] : [{
10360
+ reason: "type",
10361
+ path,
10362
+ expected: "function",
10363
+ received: preview(value)
10364
+ }];
9762
10365
  case "literal": {
9763
10366
  const allowed = literalOf(owned.values);
9764
10367
  return (value, path) => allowed(value) || isString(value) && allowed(value.trim()) ? [] : [{
@@ -9983,6 +10586,13 @@ var ContractCompiler = class ContractCompiler {
9983
10586
  const owned = this.#node(index);
9984
10587
  switch (owned.category) {
9985
10588
  case "string": {
10589
+ if (owned.date === true) return (random) => {
10590
+ const year = 2e3 + INTRINSICS.floor(drawRandom(random, "string") * 100);
10591
+ const month = 1 + INTRINSICS.floor(drawRandom(random, "string") * 12);
10592
+ const length = computeMonthLength(year, month);
10593
+ const day = 1 + INTRINSICS.floor(drawRandom(random, "string") * length);
10594
+ return `${year}-${month < 10 ? "0" : ""}${month}-${day < 10 ? "0" : ""}${day}`;
10595
+ };
9986
10596
  const min = owned.min ?? 0;
9987
10597
  const max = owned.max ?? INTRINSICS.max(min, 12);
9988
10598
  const length = INTRINSICS.max(min, INTRINSICS.min(max, 8));
@@ -10022,6 +10632,7 @@ var ContractCompiler = class ContractCompiler {
10022
10632
  }
10023
10633
  case "boolean": return (random) => drawRandom(random, "boolean") >= .5;
10024
10634
  case "null": return () => null;
10635
+ case "function": return () => ContractCompiler.#function;
10025
10636
  case "shape": return () => ({
10026
10637
  category: "object",
10027
10638
  properties: {},
@@ -10522,7 +11133,7 @@ var ValueInferer = class ValueInferer {
10522
11133
  const outcome = attempt(() => {
10523
11134
  const snapshot = readArrayEntries(value);
10524
11135
  if (isFailure(snapshot)) throw snapshot.error;
10525
- if (!snapshot.value.dense) return void 0;
11136
+ if (!snapshot.value.dense || !snapshot.value.exact) return void 0;
10526
11137
  const entries = snapshot.value.entries;
10527
11138
  const length = INTRINSICS.ceil(INTRINSICS.min(entries.length, this.#breadth));
10528
11139
  return INTRINSICS.from(iterateIndices(() => length), (index) => this.#infer(entries[index], depth - 1));
@@ -10565,10 +11176,11 @@ var ValueInferer = class ValueInferer {
10565
11176
  const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
10566
11177
  const required = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(selected), [(entry) => entry.key]);
10567
11178
  const dropped = INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry.key !== void 0 && entry.schema === void 0]);
11179
+ const hidden = !matchesEnumerableKeys(value, snapshot);
10568
11180
  return {
10569
11181
  properties,
10570
11182
  required,
10571
- partial: truncated || dropped
11183
+ partial: truncated || dropped || hidden
10572
11184
  };
10573
11185
  });
10574
11186
  omitVisited(this.#visited, value);
@@ -10665,12 +11277,16 @@ var SampleInferer = class {
10665
11277
  const signature = `${depth}|${this.#breadth}|${this.#closed}|${this.#format}|${this.#enumerated}`;
10666
11278
  const cached = INTRINSICS.reflect.apply(INTRINSICS.fetch, node.schemas, [signature]);
10667
11279
  if (cached !== void 0) return cached;
10668
- const keyPairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(samples), [(sample) => {
11280
+ const listings = INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(samples), [(sample) => {
10669
11281
  if (sample === void 0) throw new INTRINSICS.error("samplesToSchema: every sample must be a record");
10670
11282
  const sampleKeys = enumerableKeys(sample);
10671
11283
  if (sampleKeys === void 0) throw new INTRINSICS.error("samplesToSchema: property enumeration failed");
10672
- return INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(sampleKeys), [(key) => [key, true]]);
11284
+ return {
11285
+ keys: sampleKeys,
11286
+ hidden: !matchesEnumerableKeys(sample, sampleKeys)
11287
+ };
10673
11288
  }]);
11289
+ const keyPairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(listings), [(listing) => INTRINSICS.reflect.apply(INTRINSICS.project, readIndexView(listing.keys), [(key) => [key, true]])]);
10674
11290
  const keySet = INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [keyPairs]) });
10675
11291
  const allKeys = sortValues(INTRINSICS.keys(keySet));
10676
11292
  const keys = limitEntries(allKeys, this.#breadth);
@@ -10711,7 +11327,7 @@ var SampleInferer = class {
10711
11327
  const pairs = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.key === void 0 || column.schema === void 0 ? [] : [[column.key, column.schema]]]);
10712
11328
  const properties = INTRINSICS.rebase(INTRINSICS.record({ [Symbol.iterator]: INTRINSICS.reflect.apply(INTRINSICS.bind, INTRINSICS.iterator, [pairs]) }), null);
10713
11329
  const required = INTRINSICS.reflect.apply(INTRINSICS.expand, readIndexView(columns), [(column) => column.required && column.key !== void 0 ? [column.key] : []]);
10714
- const partial = truncated || INTRINSICS.reflect.apply(INTRINSICS.some, columns, [(column) => column.dropped]);
11330
+ const partial = truncated || INTRINSICS.reflect.apply(INTRINSICS.some, columns, [(column) => column.dropped]) || INTRINSICS.reflect.apply(INTRINSICS.some, listings, [(listing) => listing.hidden]);
10715
11331
  const schema = {
10716
11332
  type: "object",
10717
11333
  ...INTRINSICS.keys(properties).length > 0 ? { properties } : {},
@@ -10931,7 +11547,11 @@ function inferPrimitiveEnum(values, limit) {
10931
11547
  * throws a `structure`
10932
11548
  * {@link ContractError}; it never becomes `{}` or another permissive schema. Nested
10933
11549
  * objects close to unknown keys (`additionalProperties: false`) by default;
10934
- * pass `closed: false` to open them. `format` (default `false`) opts a
11550
+ * pass `closed: false` to open them. A record whose sampled keys are not every
11551
+ * key it owns stays open whatever `closed` says: one truncated by the breadth
11552
+ * budget, one holding a member that is `undefined`, and one holding a
11553
+ * non-enumerable string key or a symbol key, because a closed schema would refuse
11554
+ * the record it was inferred from. `format` (default `false`) opts a
10935
11555
  * string/`Date` leaf into the `format` keyword. Structurally-equal inputs
10936
11556
  * infer byte-identical schemas (object keys and `anyOf` members are sorted).
10937
11557
  *
@@ -10989,7 +11609,10 @@ function valueToSchema(value, options) {
10989
11609
  * An empty `samples` array infers the empty accept-anything schema `{}`.
10990
11610
  * When every sample is a plain record, properties/required are unified
10991
11611
  * per-key across all samples — a key
10992
- * required iff present and non-`undefined` in every sample. Otherwise the
11612
+ * required iff present and non-`undefined` in every sample. The unified object
11613
+ * stays open whatever `closed` says when the key union is truncated, or when any
11614
+ * sample holds a member that is `undefined`, a non-enumerable string key, or a
11615
+ * symbol key. When any sample is not a plain record, the
10993
11616
  * slot is inferred one value at a time (independent {@link valueToSchema}
10994
11617
  * per sample, unified with {@link unifySchemas} — the same de-duplication and
10995
11618
  * `anyOf` ordering an array's element schemas receive). `format`
@@ -11185,11 +11808,15 @@ var SchemaShaper = class SchemaShaper {
11185
11808
  });
11186
11809
  }
11187
11810
  #inspect(schema) {
11811
+ if (INTRINSICS.own(schema, "not")) {
11812
+ this.#inspectFunction(schema);
11813
+ return;
11814
+ }
11188
11815
  const keys = INTRINSICS.keys(schema);
11189
11816
  for (const index of iterateIndices(() => keys.length)) {
11190
11817
  const key = keys[index];
11191
11818
  if (key === void 0) continue;
11192
- if (!INTRINSICS.reflect.apply(INTRINSICS.some, STRICT_SCHEMA_KEYWORDS, [(keyword) => keyword === key])) throw this.#refusal("a strict conversion refuses a keyword it cannot honour", key);
11819
+ if (!(INTRINSICS.reflect.apply(INTRINSICS.some, STRICT_SCHEMA_KEYWORDS, [(keyword) => keyword === key]) || key === "format" && schema.format === "date")) throw this.#refusal("a strict conversion refuses a keyword it cannot honour", key);
11193
11820
  }
11194
11821
  this.#inspectAnnotations(schema);
11195
11822
  if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) throw this.#refusal("a default must be a JSON value", "default");
@@ -11198,7 +11825,11 @@ var SchemaShaper = class SchemaShaper {
11198
11825
  const hasForm = INTRINSICS.own(schema, "enum") || INTRINSICS.own(schema, "oneOf") || INTRINSICS.own(schema, "anyOf");
11199
11826
  const object = types.length === 0 && INTRINSICS.own(schema, "properties") ? ["object"] : types;
11200
11827
  const effective = hasForm ? [] : object;
11201
- this.#confine(schema, ["minLength", "maxLength"], this.#names(effective, "string"));
11828
+ this.#confine(schema, [
11829
+ "minLength",
11830
+ "maxLength",
11831
+ "format"
11832
+ ], this.#names(effective, "string"));
11202
11833
  this.#confine(schema, ["minimum", "maximum"], this.#names(effective, "number", "integer"));
11203
11834
  this.#confine(schema, [
11204
11835
  "items",
@@ -11215,33 +11846,46 @@ var SchemaShaper = class SchemaShaper {
11215
11846
  this.#inspectRange(schema, this.#names(effective, "integer"));
11216
11847
  this.#inspectObject(schema);
11217
11848
  }
11218
- #inspectAnnotations(schema) {
11219
- const texts = [
11220
- "title",
11221
- "description",
11222
- "$schema",
11223
- "$id",
11224
- "$comment"
11225
- ];
11226
- for (const index of iterateIndices(() => texts.length)) {
11227
- const keyword = texts[index];
11228
- if (keyword === void 0) continue;
11229
- const value = INTRINSICS.own(schema, keyword) ? INTRINSICS.reflect.read(schema, keyword) : void 0;
11230
- if (value !== void 0 && !isString(value)) throw this.#refusal(`${keyword} must be a string`, keyword);
11849
+ #inspectFunction(schema) {
11850
+ const operand = schema.not;
11851
+ if (!isRecord(operand) || INTRINSICS.reflect.members(operand).length > 0 || !INTRINSICS.own(schema, "format") || schema.format !== "function") throw this.#refusal("a strict conversion reads not only as the empty schema beside format function", "not");
11852
+ const keys = INTRINSICS.keys(schema);
11853
+ for (const index of iterateIndices(() => keys.length)) {
11854
+ const key = keys[index];
11855
+ if (key === void 0) continue;
11856
+ if (!(key === "not" || key === "format" || key === "default" || INTRINSICS.reflect.apply(INTRINSICS.some, SCHEMA_ANNOTATIONS, [(keyword) => keyword === key]))) throw this.#refusal("a function schema reads no assertion beside not", key);
11231
11857
  }
11232
- const flags = [
11233
- "deprecated",
11234
- "readOnly",
11235
- "writeOnly"
11236
- ];
11237
- for (const index of iterateIndices(() => flags.length)) {
11238
- const keyword = flags[index];
11858
+ this.#inspectAnnotations(schema);
11859
+ if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) throw this.#refusal("a default must be a JSON value", "default");
11860
+ }
11861
+ #inspectAnnotations(schema) {
11862
+ for (const index of iterateIndices(() => SCHEMA_ANNOTATIONS.length)) {
11863
+ const keyword = SCHEMA_ANNOTATIONS[index];
11239
11864
  if (keyword === void 0) continue;
11240
11865
  const value = INTRINSICS.own(schema, keyword) ? INTRINSICS.reflect.read(schema, keyword) : void 0;
11241
- if (value !== void 0 && !isBoolean(value)) throw this.#refusal(`${keyword} must be a boolean`, keyword);
11866
+ if (value === void 0) continue;
11867
+ switch (keyword) {
11868
+ case "title":
11869
+ case "description":
11870
+ case "$schema":
11871
+ case "$id":
11872
+ case "$comment":
11873
+ if (!isString(value)) throw this.#refusal(`${keyword} must be a string`, keyword);
11874
+ break;
11875
+ case "deprecated":
11876
+ case "readOnly":
11877
+ case "writeOnly":
11878
+ if (!isBoolean(value)) throw this.#refusal(`${keyword} must be a boolean`, keyword);
11879
+ break;
11880
+ case "examples":
11881
+ if (!isArray(value)) throw this.#refusal("examples must be an array", keyword);
11882
+ break;
11883
+ default: {
11884
+ const unchecked = keyword;
11885
+ throw this.#refusal("an annotation has no value check", unchecked);
11886
+ }
11887
+ }
11242
11888
  }
11243
- const examples = INTRINSICS.own(schema, "examples") ? INTRINSICS.reflect.read(schema, "examples") : void 0;
11244
- if (examples !== void 0 && !isArray(examples)) throw this.#refusal("examples must be an array", "examples");
11245
11889
  }
11246
11890
  #inspectType(schema) {
11247
11891
  const declared = INTRINSICS.own(schema, "type") ? schema.type : void 0;
@@ -11334,6 +11978,7 @@ var SchemaShaper = class SchemaShaper {
11334
11978
  this.#built += 1;
11335
11979
  const description = INTRINSICS.own(schema, "description") && isString(schema.description) ? schema.description : void 0;
11336
11980
  if (INTRINSICS.own(schema, "$ref")) return this.#widen("a reference is not resolved", description, "$ref");
11981
+ if (this.#strict && INTRINSICS.own(schema, "not")) return functionShape(description === void 0 ? void 0 : { description });
11337
11982
  if (INTRINSICS.own(schema, "enum") && isArray(schema.enum)) {
11338
11983
  const observed = INTRINSICS.from(iterateIndices(() => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"]).length), (index) => INTRINSICS.reflect.apply(INTRINSICS.reflect.read, void 0, [schema, "enum"])[index]);
11339
11984
  if (INTRINSICS.reflect.apply(INTRINSICS.some, observed, [(entry) => entry !== null && (!isLiteralValue(entry) || typeof entry === "number" && !isFiniteNumber(entry))])) return this.#widen("an enum entry has no literal form", description, "enum");
@@ -11384,8 +12029,12 @@ var SchemaShaper = class SchemaShaper {
11384
12029
  const type = isString(category) && INTRINSICS.own(schema, "type") ? schema.type : void 0;
11385
12030
  if (type === "string") {
11386
12031
  const bounds = deriveLengthBounds(INTRINSICS.own(schema, "minLength") ? schema.minLength : void 0, INTRINSICS.own(schema, "maxLength") ? schema.maxLength : void 0);
12032
+ const formatted = this.#strict && INTRINSICS.own(schema, "format") && schema.format === "date";
12033
+ const dated = formatted && (bounds.min ?? 0) <= 10 && (bounds.max ?? 10) >= 10;
12034
+ if (formatted && !dated) throw this.#refusal(`a date length range must admit length 10`, "format");
11387
12035
  return stringShape(INTRINSICS.rebase({
11388
12036
  ...bounds,
12037
+ ...dated ? { date: true } : {},
11389
12038
  ...description === void 0 ? {} : { description }
11390
12039
  }, null));
11391
12040
  }
@@ -11556,6 +12205,13 @@ var FaultShaper = class FaultShaper {
11556
12205
  }), objectShape({
11557
12206
  reason: literalShape(["extra"]),
11558
12207
  path
12208
+ }), objectShape({
12209
+ reason: literalShape(["extra"]),
12210
+ path,
12211
+ symbol: stringShape()
12212
+ }), objectShape({
12213
+ reason: literalShape(["hidden"]),
12214
+ path
11559
12215
  }));
11560
12216
  }
11561
12217
  static {
@@ -11585,10 +12241,12 @@ function auditFaultShape() {
11585
12241
  * A supplied pattern is captured by source and flags. The shape exposes a fresh
11586
12242
  * frozen zero-state `RegExp` on every `pattern` read, so neither the caller's
11587
12243
  * original nor a value read from the shape can drift later compiled artifacts.
12244
+ * `date: true` restricts the string to a calendar-valid `YYYY-MM-DD`, as
12245
+ * {@link dateShape} builds it.
11588
12246
  *
11589
- * @param options - Optional length (`min` / `max`), `pattern`, and `description`
12247
+ * @param options - Optional length (`min` / `max`), `pattern`, `date`, and `description`
11590
12248
  * @returns A string shape
11591
- * @throws {ContractError} When a present bound is invalid, `pattern` is not a `RegExp`, or `pattern` has flags
12249
+ * @throws {ContractError} When a present bound is invalid, `pattern` is not a `RegExp`, `pattern` has flags, `date` is not a boolean, or `date` meets `pattern` or a bound that excludes length 10
11592
12250
  *
11593
12251
  * @example
11594
12252
  * ```ts
@@ -11601,6 +12259,7 @@ function stringShape(options) {
11601
12259
  "min",
11602
12260
  "max",
11603
12261
  "pattern",
12262
+ "date",
11604
12263
  "description"
11605
12264
  ], "stringShape", "string");
11606
12265
  const pattern = safe?.pattern;
@@ -11653,6 +12312,7 @@ function stringShape(options) {
11653
12312
  ...safe?.min === void 0 ? {} : { min: safe.min },
11654
12313
  ...safe?.max === void 0 ? {} : { max: safe.max },
11655
12314
  ...patternSnapshot === void 0 ? {} : { pattern: new INTRINSICS.pattern(patternSnapshot.source) },
12315
+ ...safe?.date === void 0 || safe.date === false ? {} : { date: safe.date },
11656
12316
  ...safe?.description === void 0 ? {} : { description: safe.description }
11657
12317
  };
11658
12318
  if (patternSnapshot === void 0 && !ShapePass.polluted()) return ShapePass.seal(shape);
@@ -11736,6 +12396,42 @@ function integerShape(options) {
11736
12396
  }, "integerShape");
11737
12397
  }
11738
12398
  /**
12399
+ * Builds a calendar-date {@link StringShape} — forces `date: true`.
12400
+ *
12401
+ * @remarks
12402
+ * The guard and the parser admit exactly a calendar-valid `YYYY-MM-DD` and coerce
12403
+ * nothing, so `2026-02-30`, `2026-1-10`, and a date-time all refuse. The emitted JSON
12404
+ * Schema carries `"format": "date"`. Options other than `min`, `max`, and `description`
12405
+ * refuse, because a dropped `pattern` would widen the shape.
12406
+ *
12407
+ * @param options - Optional length bounds and `description` (no `date` or `pattern` key)
12408
+ * @returns A date string shape
12409
+ * @throws {ContractError} When an option key is unknown, or a present bound is invalid or excludes length 10
12410
+ *
12411
+ * @example
12412
+ * ```ts
12413
+ * createContract(dateShape()).is('2024-02-29') // true
12414
+ * ```
12415
+ */
12416
+ function dateShape(options) {
12417
+ return contain(() => {
12418
+ const safe = readOptions(options, [
12419
+ "min",
12420
+ "max",
12421
+ "description"
12422
+ ], "dateShape", "string");
12423
+ refuseOptionKeys(options, [
12424
+ "min",
12425
+ "max",
12426
+ "description"
12427
+ ], "dateShape", "string");
12428
+ return stringShape({
12429
+ ...safe,
12430
+ date: true
12431
+ });
12432
+ }, "dateShape");
12433
+ }
12434
+ /**
11739
12435
  * Builds a {@link BooleanShape}.
11740
12436
  *
11741
12437
  * @param options - Optional `description`
@@ -11984,9 +12680,9 @@ function recordShape(values, options) {
11984
12680
  * @remarks
11985
12681
  * When every arm is an object declaring one required literal property, and a value's
11986
12682
  * own property exactly equals a literal only one arm holds, that arm answers: `explain`
11987
- * and `audit` report its faults at their real paths, and `parse` repairs through it
11988
- * alone. Any other value reports `variant`, with `key` and `expected` saying what would
11989
- * have named an arm. `is` does not change.
12683
+ * and `audit` report its faults at their real paths, `parse` repairs through it
12684
+ * alone, and `is` answers from it alone. Any other value reports `variant`, with `key`
12685
+ * and `expected` saying what would have named an arm.
11990
12686
  *
11991
12687
  * @param variants - The candidate shapes; the first match wins at runtime
11992
12688
  * @returns A union shape whose `Infer` is the union of the variants
@@ -12015,7 +12711,8 @@ function unionShape(...variants) {
12015
12711
  * - **Guard**: accepts the value only when exactly one variant's guard
12016
12712
  * accepts it. A value matching two-or-more variants — which would violate
12017
12713
  * the emitted `oneOf` schema — is rejected, even though it would pass
12018
- * {@link unionShape}'s guard.
12714
+ * {@link unionShape}'s guard. A value that names one arm through a required
12715
+ * literal is answered by that arm's guard alone.
12019
12716
  * - **Parser**: judged on the RAW input's guard matches only, with NO
12020
12717
  * coercion fallback for an ambiguous input. When exactly one variant's
12021
12718
  * guard accepts the raw value, the input itself is returned. Zero matches or
@@ -12179,6 +12876,32 @@ function shapeShape(options) {
12179
12876
  }, "shapeShape");
12180
12877
  }
12181
12878
  /**
12879
+ * Builds a {@link FunctionShape}.
12880
+ *
12881
+ * @remarks
12882
+ * The guard accepts every callable and checks no arity: TypeScript admits a callback that
12883
+ * declares fewer parameters than its type, and `Function.length` undercounts rest and
12884
+ * defaulted parameters.
12885
+ *
12886
+ * @param options - Optional description
12887
+ * @returns A function-valued declaration
12888
+ *
12889
+ * @example
12890
+ * ```ts
12891
+ * const options = objectShape({ upgrade: optionalShape(functionShape()) })
12892
+ * ```
12893
+ */
12894
+ function functionShape(options) {
12895
+ return contain(() => {
12896
+ const safe = readOptions(options, ["description"], "functionShape", "function");
12897
+ const shape = {
12898
+ category: "function",
12899
+ ...safe?.description === void 0 ? {} : { description: safe.description }
12900
+ };
12901
+ return ShapePass.seal(shape);
12902
+ }, "functionShape");
12903
+ }
12904
+ /**
12182
12905
  * Builds a {@link RawShape} from a supported JSON Schema fragment.
12183
12906
  *
12184
12907
  * @remarks
@@ -12292,15 +13015,21 @@ function rawShape(schema) {
12292
13015
  *
12293
13016
  * STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
12294
13017
  * code `structure`, every node the lenient walk would widen, every keyword it
12295
- * would ignore (`pattern`, `format`, `nullable`, `patternProperties`,
12296
- * `propertyNames`, `prefixItems`, and anything else outside
13018
+ * would ignore (`pattern`, every `format` but `'date'` on a string node and `'function'` in
13019
+ * the function leaf, every `not` outside that leaf, `nullable`,
13020
+ * `patternProperties`, `propertyNames`, `prefixItems`, and anything else outside
12297
13021
  * {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
12298
- * that is neither a finite primitive nor `null`, a contradictory bound, a `required` name not in
13022
+ * that is neither a finite primitive nor `null`, a contradictory bound, a date format whose
13023
+ * length bounds exclude length 10, a `required` name not in
12299
13024
  * `properties`, breadth past {@link INFER_BREADTH_LIMIT}, and a `default` with no
12300
13025
  * optional property to fill. An object with no `additionalProperties` closes
12301
13026
  * rather than opens, and `oneOf` keeps exactly-one, because a strict walk reads
12302
13027
  * every keyword that could keep two arms apart. Below a `oneOf` that object refuses
12303
- * instead, since closing it could change which arms match.
13028
+ * instead, since closing it could change which arms match. A strict conversion is the
13029
+ * one walk that asserts a `format`: it reads `format: 'date'` on a string node as a
13030
+ * date string shape, so a compiled {@link dateShape} round-trips, and it reads the function
13031
+ * leaf `{ not: {}, format: 'function' }` back as {@link functionShape}, so a compiled
13032
+ * function shape round-trips too.
12304
13033
  *
12305
13034
  * @param schema - The JSON Schema value to convert
12306
13035
  * @param options - Optional `strict`, default `false`
@@ -12352,6 +13081,7 @@ exports.CONTRACT_CODES = CONTRACT_CODES;
12352
13081
  exports.CONTRACT_ERROR_BRAND = CONTRACT_ERROR_BRAND;
12353
13082
  exports.ContractCompiler = ContractCompiler;
12354
13083
  exports.ContractError = ContractError;
13084
+ exports.DATE_LENGTH = DATE_LENGTH;
12355
13085
  exports.FAULT_CONSTRAINTS = FAULT_CONSTRAINTS;
12356
13086
  exports.FAULT_KINDS = FAULT_KINDS;
12357
13087
  exports.FAULT_LIMIT = FAULT_LIMIT;
@@ -12368,10 +13098,12 @@ exports.INFER_ENUM_LIMIT = INFER_ENUM_LIMIT;
12368
13098
  exports.INTRINSICS = INTRINSICS;
12369
13099
  exports.JSONCloner = JSONCloner;
12370
13100
  exports.JSON_SCHEMA_TYPES = JSON_SCHEMA_TYPES;
13101
+ exports.KEY_PLAN_LIMIT = KEY_PLAN_LIMIT;
12371
13102
  exports.NAME_LIMIT = NAME_LIMIT;
12372
13103
  exports.NODE_LIMIT = NODE_LIMIT;
12373
13104
  exports.PRESENCE_MASK_LIMIT = PRESENCE_MASK_LIMIT;
12374
13105
  exports.PREVIEW_LIMIT = PREVIEW_LIMIT;
13106
+ exports.SCHEMA_ANNOTATIONS = SCHEMA_ANNOTATIONS;
12375
13107
  exports.SHAPE_FIELDS = SHAPE_FIELDS;
12376
13108
  exports.STRICT_SCHEMA_KEYWORDS = STRICT_SCHEMA_KEYWORDS;
12377
13109
  exports.STRING_LIMIT = STRING_LIMIT;
@@ -12391,7 +13123,9 @@ exports.auditFaultShape = auditFaultShape;
12391
13123
  exports.booleanShape = booleanShape;
12392
13124
  exports.boundsOf = boundsOf;
12393
13125
  exports.buildArrayFaults = buildArrayFaults;
13126
+ exports.buildKeyPlan = buildKeyPlan;
12394
13127
  exports.buildNumberFaults = buildNumberFaults;
13128
+ exports.buildPathKey = buildPathKey;
12395
13129
  exports.buildPositions = buildPositions;
12396
13130
  exports.buildSampleMemo = buildSampleMemo;
12397
13131
  exports.buildStringFaults = buildStringFaults;
@@ -12401,6 +13135,7 @@ exports.cloneJSONRecord = cloneJSONRecord;
12401
13135
  exports.cloneJSONValue = cloneJSONValue;
12402
13136
  exports.cloneSchema = cloneSchema;
12403
13137
  exports.cloneShape = cloneShape;
13138
+ exports.collectArrayEntries = collectArrayEntries;
12404
13139
  exports.collectEntries = collectEntries;
12405
13140
  exports.collectMembers = collectMembers;
12406
13141
  exports.comparePrimitives = comparePrimitives;
@@ -12411,9 +13146,11 @@ exports.compileParser = compileParser;
12411
13146
  exports.compileReporter = compileReporter;
12412
13147
  exports.compileSchema = compileSchema;
12413
13148
  exports.complementOf = complementOf;
13149
+ exports.computeMonthLength = computeMonthLength;
12414
13150
  exports.computeSurrogatePairs = computeSurrogatePairs;
12415
13151
  exports.contain = contain;
12416
13152
  exports.createContract = createContract;
13153
+ exports.dateShape = dateShape;
12417
13154
  exports.deriveLengthBounds = deriveLengthBounds;
12418
13155
  exports.deriveRangeBounds = deriveRangeBounds;
12419
13156
  exports.describeFaultLine = describeFaultLine;
@@ -12430,6 +13167,8 @@ exports.extractForms = extractForms;
12430
13167
  exports.extractPath = extractPath;
12431
13168
  exports.extractSchema = extractSchema;
12432
13169
  exports.failure = failure;
13170
+ exports.filterUncoveredFaults = filterUncoveredFaults;
13171
+ exports.functionShape = functionShape;
12433
13172
  exports.holds = holds;
12434
13173
  exports.inferPrimitiveEnum = inferPrimitiveEnum;
12435
13174
  exports.instanceOf = instanceOf;
@@ -12521,14 +13260,19 @@ exports.literalOf = literalOf;
12521
13260
  exports.literalShape = literalShape;
12522
13261
  exports.mapOf = mapOf;
12523
13262
  exports.matchOf = matchOf;
13263
+ exports.matchesCalendarDate = matchesCalendarDate;
13264
+ exports.matchesEnumerableKeys = matchesEnumerableKeys;
12524
13265
  exports.matchesExactKeys = matchesExactKeys;
12525
13266
  exports.matchesISOInstant = matchesISOInstant;
12526
13267
  exports.matchesJSONDepth = matchesJSONDepth;
12527
13268
  exports.matchesJSONValue = matchesJSONValue;
13269
+ exports.matchesKeyPlan = matchesKeyPlan;
12528
13270
  exports.matchesLosslessRepair = matchesLosslessRepair;
12529
13271
  exports.matchesMember = matchesMember;
12530
13272
  exports.matchesPattern = matchesPattern;
12531
13273
  exports.matchesRecordBrand = matchesRecordBrand;
13274
+ exports.matchesStepGuard = matchesStepGuard;
13275
+ exports.matchesStepKey = matchesStepKey;
12532
13276
  exports.matchesStringLength = matchesStringLength;
12533
13277
  exports.matchesUndefinedField = matchesUndefinedField;
12534
13278
  exports.matchesVisited = matchesVisited;
@@ -12593,6 +13337,7 @@ exports.refuseOptionKeys = refuseOptionKeys;
12593
13337
  exports.renderForm = renderForm;
12594
13338
  exports.renderList = renderList;
12595
13339
  exports.renderPath = renderPath;
13340
+ exports.repairValue = repairValue;
12596
13341
  exports.resolveField = resolveField;
12597
13342
  exports.retainDepth = retainDepth;
12598
13343
  exports.samplesToFormat = samplesToFormat;