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