@orkestrel/contract 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@ var SHAPE_FIELDS = Object.freeze({
13
13
  "min",
14
14
  "max",
15
15
  "pattern",
16
+ "date",
16
17
  "description"
17
18
  ]),
18
19
  number: Object.freeze([
@@ -349,7 +350,9 @@ var JSON_SCHEMA_TYPES = Object.freeze([
349
350
  * lose nothing when a shape drops them: `title`, `$schema`, `$id`, `$comment`,
350
351
  * `examples`, `deprecated`, `readOnly`, and `writeOnly`. Every other keyword refuses.
351
352
  * `pattern` and `format` are absent because no compiled shape asserts them, so a
352
- * schema holding one would convert to a shape wider than the schema it came from.
353
+ * schema holding one would convert to a shape wider than the schema it came from. The
354
+ * one exception is `format: 'date'` on a string node, which a strict conversion reads
355
+ * as a date string shape.
353
356
  *
354
357
  * @example
355
358
  * ```ts
@@ -429,6 +432,7 @@ var CONTRACT_CODES = Object.freeze([
429
432
  */
430
433
  var FAULT_KINDS = Object.freeze([
431
434
  "string",
435
+ "date",
432
436
  "number",
433
437
  "integer",
434
438
  "boolean",
@@ -455,6 +459,7 @@ var FAULT_CONSTRAINTS = Object.freeze([
455
459
  "min",
456
460
  "max",
457
461
  "pattern",
462
+ "date",
458
463
  "integer"
459
464
  ]);
460
465
  /**
@@ -678,6 +683,19 @@ var FORMAT_PATTERNS = Object.freeze({
678
683
  uri: /^[a-z][a-z0-9+.-]*:\/\//i
679
684
  });
680
685
  /**
686
+ * Holds `10`, the length of every `YYYY-MM-DD` date a date string shape admits.
687
+ *
688
+ * @remarks
689
+ * A date string shape whose `min` or `max` excludes this length admits no value, so
690
+ * building one refuses with code `range`.
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * DATE_LENGTH // 10
695
+ * ```
696
+ */
697
+ var DATE_LENGTH = 10;
698
+ /**
681
699
  * Caps at `1024` the number of choices one schema field may offer, frozen.
682
700
  *
683
701
  * @remarks
@@ -4231,6 +4249,27 @@ function canonicalStringify(value) {
4231
4249
  }, "canonicalStringify");
4232
4250
  }
4233
4251
  /**
4252
+ * Computes the number of days in a month of the Gregorian calendar.
4253
+ *
4254
+ * @remarks
4255
+ * February has 29 days in a year divisible by 4, except a century year not divisible
4256
+ * by 400. The caller supplies a month from 1 to 12.
4257
+ *
4258
+ * @param year - The calendar year
4259
+ * @param month - The month, from 1 for January to 12 for December
4260
+ * @returns The days in that month, from 28 to 31
4261
+ *
4262
+ * @example
4263
+ * ```ts
4264
+ * computeMonthLength(2024, 2) // 29
4265
+ * computeMonthLength(1900, 2) // 28
4266
+ * ```
4267
+ */
4268
+ function computeMonthLength(year, month) {
4269
+ const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
4270
+ return month === 2 ? 28 + INTRINSICS.numeric(leap) : 31 - INTRINSICS.numeric(month === 4 || month === 6 || month === 9 || month === 11);
4271
+ }
4272
+ /**
4234
4273
  * Checks whether a supported ISO-8601 date or date-time names a real instant.
4235
4274
  *
4236
4275
  * @remarks
@@ -4261,9 +4300,7 @@ function matchesISOInstant(value) {
4261
4300
  const month = INTRINSICS.numeric(monthText);
4262
4301
  const day = INTRINSICS.numeric(dayText);
4263
4302
  if (month < 1 || month > 12) return false;
4264
- const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
4265
- const limit = month === 2 ? 28 + INTRINSICS.numeric(leap) : 31 - INTRINSICS.numeric(month === 4 || month === 6 || month === 9 || month === 11);
4266
- if (day < 1 || day > limit) return false;
4303
+ if (day < 1 || day > computeMonthLength(year, month)) return false;
4267
4304
  const hourText = match?.[4];
4268
4305
  const minuteText = match?.[5];
4269
4306
  const secondText = match?.[6];
@@ -4280,6 +4317,27 @@ function matchesISOInstant(value) {
4280
4317
  return isSuccess(outcome) && outcome.value;
4281
4318
  }
4282
4319
  /**
4320
+ * Checks whether a string is exactly a calendar-valid `YYYY-MM-DD` date.
4321
+ *
4322
+ * @remarks
4323
+ * Refuses a date-time, surrounding whitespace, and a date the Gregorian calendar
4324
+ * lacks, such as `2026-02-29`. Backs a date string shape and {@link classifyFormat}'s
4325
+ * `date`.
4326
+ *
4327
+ * @param value - The candidate string
4328
+ * @returns True if `value` is a calendar-valid `YYYY-MM-DD`; false otherwise
4329
+ * @throws The exact value thrown by a redirected pattern dispatch
4330
+ *
4331
+ * @example
4332
+ * ```ts
4333
+ * matchesCalendarDate('2024-02-29') // true
4334
+ * matchesCalendarDate('2026-02-29') // false
4335
+ * ```
4336
+ */
4337
+ function matchesCalendarDate(value) {
4338
+ return matchesPattern(/^\d{4}-\d{2}-\d{2}$/, value) && matchesISOInstant(value);
4339
+ }
4340
+ /**
4283
4341
  * Classifies an already-bounded string against the pattern-only and
4284
4342
  * calendar-checked {@link SchemaFormat} vocabulary.
4285
4343
  *
@@ -4301,7 +4359,7 @@ function matchesISOInstant(value) {
4301
4359
  function classifyFormat(value) {
4302
4360
  if (matchesPattern(FORMAT_PATTERNS.uuid, value)) return "uuid";
4303
4361
  if (matchesPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/, value) && matchesISOInstant(value)) return "date-time";
4304
- if (matchesPattern(/^\d{4}-\d{2}-\d{2}$/, value) && matchesISOInstant(value)) return "date";
4362
+ if (matchesCalendarDate(value)) return "date";
4305
4363
  if (matchesPattern(/^\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/, value) && matchesISOInstant(`1970-01-01T${value}`)) return "time";
4306
4364
  if (matchesPattern(FORMAT_PATTERNS.email, value)) return "email";
4307
4365
  if (matchesPattern(FORMAT_PATTERNS.uri, value)) return "uri";
@@ -4518,8 +4576,10 @@ function preview(value) {
4518
4576
  * OBTAIN the string — the reporter coerces through `parseString`, the auditor
4519
4577
  * demands a primitive string — and share every constraint afterwards through
4520
4578
  * this helper, so a constraint cannot drift between them.
4521
- * Faults come out in declaration order — `min`, then `max`, then
4579
+ * Faults come out in declaration order — `date`, then `min`, then `max`, then
4522
4580
  * `pattern` — because a report is read top to bottom and its order is public.
4581
+ * `expected` is `'date'` on a date string shape and `'string'` otherwise, as
4582
+ * {@link buildNumberFaults} names `'integer'`.
4523
4583
  *
4524
4584
  * The declaration's pattern is applied through an OWNED stateless rebuild
4525
4585
  * ({@link readPattern}) asked through {@link matchesPattern}, so the shape's own
@@ -4566,11 +4626,20 @@ function preview(value) {
4566
4626
  */
4567
4627
  function buildStringFaults(shape, value, path, pattern) {
4568
4628
  return readValue(() => {
4629
+ const dated = INTRINSICS.own(shape, "date") && shape.date === true;
4630
+ const expected = dated ? "date" : "string";
4569
4631
  const faults = [];
4632
+ if (dated && !matchesCalendarDate(value)) faults[faults.length] = {
4633
+ reason: "constraint",
4634
+ path,
4635
+ expected,
4636
+ constraint: "date",
4637
+ received: preview(value)
4638
+ };
4570
4639
  if (INTRINSICS.own(shape, "min") && shape.min !== void 0 && !matchesStringLength(value, shape.min, void 0)) faults[faults.length] = {
4571
4640
  reason: "constraint",
4572
4641
  path,
4573
- expected: "string",
4642
+ expected,
4574
4643
  constraint: "min",
4575
4644
  limit: shape.min,
4576
4645
  received: preview(value)
@@ -4578,7 +4647,7 @@ function buildStringFaults(shape, value, path, pattern) {
4578
4647
  if (INTRINSICS.own(shape, "max") && shape.max !== void 0 && !matchesStringLength(value, void 0, shape.max)) faults[faults.length] = {
4579
4648
  reason: "constraint",
4580
4649
  path,
4581
- expected: "string",
4650
+ expected,
4582
4651
  constraint: "max",
4583
4652
  limit: shape.max,
4584
4653
  received: preview(value)
@@ -4589,7 +4658,7 @@ function buildStringFaults(shape, value, path, pattern) {
4589
4658
  faults[faults.length] = {
4590
4659
  reason: "constraint",
4591
4660
  path,
4592
- expected: "string",
4661
+ expected,
4593
4662
  constraint: "pattern",
4594
4663
  ...limit === void 0 ? {} : { limit },
4595
4664
  received: preview(value)
@@ -4736,7 +4805,8 @@ function selectClosestFaults(reports) {
4736
4805
  * A structural mapping used by {@link compileReporter} to fill a `Fault`'s
4737
4806
  * `expected` field and by {@link compileAuditor} to fill an `AuditFault`'s:
4738
4807
  * most shapes map to their own `category` (`numberShape` maps to
4739
- * `'integer'` when `integer: true`, else `'number'`); `optionalShape` /
4808
+ * `'integer'` when `integer: true`, else `'number'`, and `stringShape` maps to
4809
+ * `'date'` when `date: true`, else `'string'`); `optionalShape` /
4740
4810
  * `nullableShape` project through to their inner shape's kind, and `rawShape`
4741
4811
  * (an arbitrary embedded schema with no fixed kind) projects to `'json'`.
4742
4812
  *
@@ -4759,7 +4829,7 @@ function selectClosestFaults(reports) {
4759
4829
  function shapeToKind(shape) {
4760
4830
  return readValue(() => {
4761
4831
  switch (shape.category) {
4762
- case "string": return "string";
4832
+ case "string": return INTRINSICS.own(shape, "date") && shape.date === true ? "date" : "string";
4763
4833
  case "number": return INTRINSICS.own(shape, "integer") && shape.integer === true ? "integer" : "number";
4764
4834
  case "boolean": return "boolean";
4765
4835
  case "null": return "null";
@@ -5033,7 +5103,7 @@ function renderList(entries) {
5033
5103
  *
5034
5104
  * @remarks
5035
5105
  * An object lists its required keys first and marks the rest with `?`, at most `FAULT_LIST_LIMIT`
5036
- * of them. A leaf or array keeps its numeric bounds and pattern, a union joins its forms with ` | `,
5106
+ * of them. A leaf or array keeps its numeric bounds, pattern, and format, a union joins its forms with ` | `,
5037
5107
  * and a schema that says nothing reads `any`. Each nested form takes half the room of its parent, and
5038
5108
  * below 16 characters a form stops at its type, so a schema that holds itself still ends. Text past
5039
5109
  * `room` is cut and closes with `…`. A type word outside JSON Schema's vocabulary is encoded.
@@ -5070,7 +5140,8 @@ function renderForm(schema, room = 160) {
5070
5140
  "maximum",
5071
5141
  "minItems",
5072
5142
  "maxItems",
5073
- "pattern"
5143
+ "pattern",
5144
+ "format"
5074
5145
  ].includes(key)).map(([key, value]) => `${key} ${preview(value)}`);
5075
5146
  return truncateFaultText(forms !== void 0 ? deep ? forms.map((form) => renderForm(form, inner)).join(" | ") : "any" : enumeration !== void 0 ? enumeration.map((value) => preview(value)).join(" | ") : listed.length > 0 ? `{${[...listed, ...left > 0 ? [`and ${String(left)} more`] : []].join(", ")}}` : [
5076
5147
  type === void 0 ? entries.length > 0 ? "object" : "any" : JSON_SCHEMA_TYPES.some((name) => name === type) ? type : preview(type),
@@ -5543,6 +5614,7 @@ var ShapePass = class ShapePass {
5543
5614
  "min",
5544
5615
  "max",
5545
5616
  "pattern",
5617
+ "date",
5546
5618
  "description",
5547
5619
  "integer",
5548
5620
  "additionalProperties",
@@ -5825,6 +5897,7 @@ var ShapePass = class ShapePass {
5825
5897
  if (current.category === "string") {
5826
5898
  if (current.min !== void 0 && typeof current.min !== "number") return this.#refuse("validateShape: string min must be a number", "min");
5827
5899
  if (current.max !== void 0 && typeof current.max !== "number") return this.#refuse("validateShape: string max must be a number", "max");
5900
+ if (current.date !== void 0 && typeof current.date !== "boolean") return this.#refuse("validateShape: string date must be a boolean", "date");
5828
5901
  if (current.pattern !== void 0) {
5829
5902
  const pattern = current.pattern;
5830
5903
  if (!isRegExp(pattern)) return this.#refuse("validateShape: string pattern must be a RegExp", "pattern");
@@ -5949,6 +6022,21 @@ var ShapePass = class ShapePass {
5949
6022
  shape: "string"
5950
6023
  }
5951
6024
  });
6025
+ 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", {
6026
+ code: "pattern",
6027
+ context: {
6028
+ path: pathOf(this.#path),
6029
+ shape: "string"
6030
+ }
6031
+ });
6032
+ 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`, {
6033
+ code: "range",
6034
+ context: {
6035
+ path: pathOf(this.#path),
6036
+ shape: "string",
6037
+ limit: 10
6038
+ }
6039
+ });
5952
6040
  }
5953
6041
  #inspect(source) {
5954
6042
  if (this.#structure !== void 0) return true;
@@ -6813,11 +6901,13 @@ var ShapeCloner = class ShapeCloner {
6813
6901
  const min = this.#captureField(source, "min", path);
6814
6902
  const max = this.#captureField(source, "max", path);
6815
6903
  const pattern = this.#capturePattern(source, path);
6904
+ const date = this.#captureField(source, "date", path);
6816
6905
  const description = this.#captureField(source, "description", path);
6817
6906
  const fields = {
6818
6907
  category: "string",
6819
6908
  ...min === void 0 ? {} : { min },
6820
6909
  ...max === void 0 ? {} : { max },
6910
+ ...date === void 0 ? {} : { date },
6821
6911
  ...description === void 0 ? {} : { description }
6822
6912
  };
6823
6913
  if (pattern === void 0) return fields;
@@ -8996,6 +9086,7 @@ var ContractCompiler = class ContractCompiler {
8996
9086
  ...owned.min !== void 0 ? { minLength: owned.min } : {},
8997
9087
  ...owned.max !== void 0 ? { maxLength: owned.max } : {},
8998
9088
  ...text !== void 0 ? { pattern: text } : {},
9089
+ ...owned.date === true ? { format: "date" } : {},
8999
9090
  ...owned.description !== void 0 ? { description: owned.description } : {}
9000
9091
  });
9001
9092
  }
@@ -9097,11 +9188,12 @@ var ContractCompiler = class ContractCompiler {
9097
9188
  return compiled;
9098
9189
  }
9099
9190
  #stringGuard(owned) {
9100
- return stringOf(INTRINSICS.rebase({
9191
+ const guard = stringOf(INTRINSICS.rebase({
9101
9192
  ...owned.min === void 0 ? {} : { min: owned.min },
9102
9193
  ...owned.max === void 0 ? {} : { max: owned.max },
9103
9194
  ...owned.pattern === void 0 ? {} : { pattern: owned.pattern }
9104
9195
  }, null));
9196
+ return owned.date === true ? whereOf(guard, matchesCalendarDate) : guard;
9105
9197
  }
9106
9198
  static #acceptShape(value) {
9107
9199
  return isSuccess(attempt(() => {
@@ -9224,7 +9316,7 @@ var ContractCompiler = class ContractCompiler {
9224
9316
  const owned = this.#node(index);
9225
9317
  switch (owned.category) {
9226
9318
  case "string": {
9227
- if (owned.min === void 0 && owned.max === void 0 && owned.pattern === void 0) return parseString;
9319
+ if (owned.min === void 0 && owned.max === void 0 && owned.pattern === void 0 && owned.date !== true) return parseString;
9228
9320
  const guard = this.#stringGuard(owned);
9229
9321
  return (value) => {
9230
9322
  const parsed = parseString(value);
@@ -9429,13 +9521,14 @@ var ContractCompiler = class ContractCompiler {
9429
9521
  case "string": {
9430
9522
  const node = owned;
9431
9523
  const declared = owned.pattern;
9432
- const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0;
9524
+ const kind = owned.date === true ? "date" : "string";
9525
+ const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0 || owned.date === true;
9433
9526
  const pattern = declared === void 0 ? void 0 : ownPattern(declared, "compileAuditor");
9434
9527
  return (value, path) => {
9435
9528
  if (!isString(value)) return [{
9436
9529
  reason: "type",
9437
9530
  path,
9438
- expected: "string",
9531
+ expected: kind,
9439
9532
  received: preview(value)
9440
9533
  }];
9441
9534
  return refined ? buildStringFaults(node, value, path, pattern) : [];
@@ -9713,14 +9806,15 @@ var ContractCompiler = class ContractCompiler {
9713
9806
  case "string": {
9714
9807
  const node = owned;
9715
9808
  const declared = owned.pattern;
9716
- const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0;
9809
+ const kind = owned.date === true ? "date" : "string";
9810
+ const refined = owned.min !== void 0 || owned.max !== void 0 || declared !== void 0 || owned.date === true;
9717
9811
  const pattern = declared === void 0 ? void 0 : ownPattern(declared, "compileReporter");
9718
9812
  return (value, path) => {
9719
9813
  const parsed = parseString(value);
9720
9814
  if (parsed === void 0) return [{
9721
9815
  reason: "type",
9722
9816
  path,
9723
- expected: "string",
9817
+ expected: kind,
9724
9818
  received: preview(value)
9725
9819
  }];
9726
9820
  return refined ? buildStringFaults(node, parsed, path, pattern) : [];
@@ -9983,6 +10077,13 @@ var ContractCompiler = class ContractCompiler {
9983
10077
  const owned = this.#node(index);
9984
10078
  switch (owned.category) {
9985
10079
  case "string": {
10080
+ if (owned.date === true) return (random) => {
10081
+ const year = 2e3 + INTRINSICS.floor(drawRandom(random, "string") * 100);
10082
+ const month = 1 + INTRINSICS.floor(drawRandom(random, "string") * 12);
10083
+ const length = computeMonthLength(year, month);
10084
+ const day = 1 + INTRINSICS.floor(drawRandom(random, "string") * length);
10085
+ return `${year}-${month < 10 ? "0" : ""}${month}-${day < 10 ? "0" : ""}${day}`;
10086
+ };
9986
10087
  const min = owned.min ?? 0;
9987
10088
  const max = owned.max ?? INTRINSICS.max(min, 12);
9988
10089
  const length = INTRINSICS.max(min, INTRINSICS.min(max, 8));
@@ -11189,7 +11290,7 @@ var SchemaShaper = class SchemaShaper {
11189
11290
  for (const index of iterateIndices(() => keys.length)) {
11190
11291
  const key = keys[index];
11191
11292
  if (key === void 0) continue;
11192
- if (!INTRINSICS.reflect.apply(INTRINSICS.some, STRICT_SCHEMA_KEYWORDS, [(keyword) => keyword === key])) throw this.#refusal("a strict conversion refuses a keyword it cannot honour", key);
11293
+ if (!(INTRINSICS.reflect.apply(INTRINSICS.some, STRICT_SCHEMA_KEYWORDS, [(keyword) => keyword === key]) || key === "format" && schema.format === "date")) throw this.#refusal("a strict conversion refuses a keyword it cannot honour", key);
11193
11294
  }
11194
11295
  this.#inspectAnnotations(schema);
11195
11296
  if (INTRINSICS.own(schema, "default") && !isJSONValue(schema.default)) throw this.#refusal("a default must be a JSON value", "default");
@@ -11198,7 +11299,11 @@ var SchemaShaper = class SchemaShaper {
11198
11299
  const hasForm = INTRINSICS.own(schema, "enum") || INTRINSICS.own(schema, "oneOf") || INTRINSICS.own(schema, "anyOf");
11199
11300
  const object = types.length === 0 && INTRINSICS.own(schema, "properties") ? ["object"] : types;
11200
11301
  const effective = hasForm ? [] : object;
11201
- this.#confine(schema, ["minLength", "maxLength"], this.#names(effective, "string"));
11302
+ this.#confine(schema, [
11303
+ "minLength",
11304
+ "maxLength",
11305
+ "format"
11306
+ ], this.#names(effective, "string"));
11202
11307
  this.#confine(schema, ["minimum", "maximum"], this.#names(effective, "number", "integer"));
11203
11308
  this.#confine(schema, [
11204
11309
  "items",
@@ -11384,8 +11489,12 @@ var SchemaShaper = class SchemaShaper {
11384
11489
  const type = isString(category) && INTRINSICS.own(schema, "type") ? schema.type : void 0;
11385
11490
  if (type === "string") {
11386
11491
  const bounds = deriveLengthBounds(INTRINSICS.own(schema, "minLength") ? schema.minLength : void 0, INTRINSICS.own(schema, "maxLength") ? schema.maxLength : void 0);
11492
+ const formatted = this.#strict && INTRINSICS.own(schema, "format") && schema.format === "date";
11493
+ const dated = formatted && (bounds.min ?? 0) <= 10 && (bounds.max ?? 10) >= 10;
11494
+ if (formatted && !dated) throw this.#refusal(`a date length range must admit length 10`, "format");
11387
11495
  return stringShape(INTRINSICS.rebase({
11388
11496
  ...bounds,
11497
+ ...dated ? { date: true } : {},
11389
11498
  ...description === void 0 ? {} : { description }
11390
11499
  }, null));
11391
11500
  }
@@ -11585,10 +11694,12 @@ function auditFaultShape() {
11585
11694
  * A supplied pattern is captured by source and flags. The shape exposes a fresh
11586
11695
  * frozen zero-state `RegExp` on every `pattern` read, so neither the caller's
11587
11696
  * original nor a value read from the shape can drift later compiled artifacts.
11697
+ * `date: true` restricts the string to a calendar-valid `YYYY-MM-DD`, as
11698
+ * {@link dateShape} builds it.
11588
11699
  *
11589
- * @param options - Optional length (`min` / `max`), `pattern`, and `description`
11700
+ * @param options - Optional length (`min` / `max`), `pattern`, `date`, and `description`
11590
11701
  * @returns A string shape
11591
- * @throws {ContractError} When a present bound is invalid, `pattern` is not a `RegExp`, or `pattern` has flags
11702
+ * @throws {ContractError} When a present bound is invalid, `pattern` is not a `RegExp`, `pattern` has flags, `date` is not a boolean, or `date` meets `pattern` or a bound that excludes length 10
11592
11703
  *
11593
11704
  * @example
11594
11705
  * ```ts
@@ -11601,6 +11712,7 @@ function stringShape(options) {
11601
11712
  "min",
11602
11713
  "max",
11603
11714
  "pattern",
11715
+ "date",
11604
11716
  "description"
11605
11717
  ], "stringShape", "string");
11606
11718
  const pattern = safe?.pattern;
@@ -11653,6 +11765,7 @@ function stringShape(options) {
11653
11765
  ...safe?.min === void 0 ? {} : { min: safe.min },
11654
11766
  ...safe?.max === void 0 ? {} : { max: safe.max },
11655
11767
  ...patternSnapshot === void 0 ? {} : { pattern: new INTRINSICS.pattern(patternSnapshot.source) },
11768
+ ...safe?.date === void 0 || safe.date === false ? {} : { date: safe.date },
11656
11769
  ...safe?.description === void 0 ? {} : { description: safe.description }
11657
11770
  };
11658
11771
  if (patternSnapshot === void 0 && !ShapePass.polluted()) return ShapePass.seal(shape);
@@ -11736,6 +11849,42 @@ function integerShape(options) {
11736
11849
  }, "integerShape");
11737
11850
  }
11738
11851
  /**
11852
+ * Builds a calendar-date {@link StringShape} — forces `date: true`.
11853
+ *
11854
+ * @remarks
11855
+ * The guard and the parser admit exactly a calendar-valid `YYYY-MM-DD` and coerce
11856
+ * nothing, so `2026-02-30`, `2026-1-10`, and a date-time all refuse. The emitted JSON
11857
+ * Schema carries `"format": "date"`. Options other than `min`, `max`, and `description`
11858
+ * refuse, because a dropped `pattern` would widen the shape.
11859
+ *
11860
+ * @param options - Optional length bounds and `description` (no `date` or `pattern` key)
11861
+ * @returns A date string shape
11862
+ * @throws {ContractError} When an option key is unknown, or a present bound is invalid or excludes length 10
11863
+ *
11864
+ * @example
11865
+ * ```ts
11866
+ * createContract(dateShape()).is('2024-02-29') // true
11867
+ * ```
11868
+ */
11869
+ function dateShape(options) {
11870
+ return contain(() => {
11871
+ const safe = readOptions(options, [
11872
+ "min",
11873
+ "max",
11874
+ "description"
11875
+ ], "dateShape", "string");
11876
+ refuseOptionKeys(options, [
11877
+ "min",
11878
+ "max",
11879
+ "description"
11880
+ ], "dateShape", "string");
11881
+ return stringShape({
11882
+ ...safe,
11883
+ date: true
11884
+ });
11885
+ }, "dateShape");
11886
+ }
11887
+ /**
11739
11888
  * Builds a {@link BooleanShape}.
11740
11889
  *
11741
11890
  * @param options - Optional `description`
@@ -12292,15 +12441,18 @@ function rawShape(schema) {
12292
12441
  *
12293
12442
  * STRICT: `{ strict: true }` is the door for a foreign schema. It refuses, with
12294
12443
  * code `structure`, every node the lenient walk would widen, every keyword it
12295
- * would ignore (`pattern`, `format`, `nullable`, `patternProperties`,
12296
- * `propertyNames`, `prefixItems`, and anything else outside
12444
+ * would ignore (`pattern`, every `format` but `'date'` on a string node, `nullable`,
12445
+ * `patternProperties`, `propertyNames`, `prefixItems`, and anything else outside
12297
12446
  * {@link STRICT_SCHEMA_KEYWORDS}), a malformed keyword or annotation, a boolean schema, an `enum` entry
12298
- * that is neither a finite primitive nor `null`, a contradictory bound, a `required` name not in
12447
+ * that is neither a finite primitive nor `null`, a contradictory bound, a date format whose
12448
+ * length bounds exclude length 10, a `required` name not in
12299
12449
  * `properties`, breadth past {@link INFER_BREADTH_LIMIT}, and a `default` with no
12300
12450
  * optional property to fill. An object with no `additionalProperties` closes
12301
12451
  * rather than opens, and `oneOf` keeps exactly-one, because a strict walk reads
12302
12452
  * every keyword that could keep two arms apart. Below a `oneOf` that object refuses
12303
- * instead, since closing it could change which arms match.
12453
+ * instead, since closing it could change which arms match. A strict conversion is the
12454
+ * one walk that asserts a `format`: it reads `format: 'date'` on a string node as a
12455
+ * date string shape, so a compiled {@link dateShape} round-trips.
12304
12456
  *
12305
12457
  * @param schema - The JSON Schema value to convert
12306
12458
  * @param options - Optional `strict`, default `false`
@@ -12352,6 +12504,7 @@ exports.CONTRACT_CODES = CONTRACT_CODES;
12352
12504
  exports.CONTRACT_ERROR_BRAND = CONTRACT_ERROR_BRAND;
12353
12505
  exports.ContractCompiler = ContractCompiler;
12354
12506
  exports.ContractError = ContractError;
12507
+ exports.DATE_LENGTH = DATE_LENGTH;
12355
12508
  exports.FAULT_CONSTRAINTS = FAULT_CONSTRAINTS;
12356
12509
  exports.FAULT_KINDS = FAULT_KINDS;
12357
12510
  exports.FAULT_LIMIT = FAULT_LIMIT;
@@ -12411,9 +12564,11 @@ exports.compileParser = compileParser;
12411
12564
  exports.compileReporter = compileReporter;
12412
12565
  exports.compileSchema = compileSchema;
12413
12566
  exports.complementOf = complementOf;
12567
+ exports.computeMonthLength = computeMonthLength;
12414
12568
  exports.computeSurrogatePairs = computeSurrogatePairs;
12415
12569
  exports.contain = contain;
12416
12570
  exports.createContract = createContract;
12571
+ exports.dateShape = dateShape;
12417
12572
  exports.deriveLengthBounds = deriveLengthBounds;
12418
12573
  exports.deriveRangeBounds = deriveRangeBounds;
12419
12574
  exports.describeFaultLine = describeFaultLine;
@@ -12521,6 +12676,7 @@ exports.literalOf = literalOf;
12521
12676
  exports.literalShape = literalShape;
12522
12677
  exports.mapOf = mapOf;
12523
12678
  exports.matchOf = matchOf;
12679
+ exports.matchesCalendarDate = matchesCalendarDate;
12524
12680
  exports.matchesExactKeys = matchesExactKeys;
12525
12681
  exports.matchesISOInstant = matchesISOInstant;
12526
12682
  exports.matchesJSONDepth = matchesJSONDepth;