@rpcbase/server 0.482.0 → 0.484.0

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.
@@ -233,6 +233,11 @@ const NUMBER_FORMAT_RANGES = {
233
233
  };
234
234
  function pick(schema, mask) {
235
235
  const currDef = schema._zod.def;
236
+ const checks = currDef.checks;
237
+ const hasChecks = checks && checks.length > 0;
238
+ if (hasChecks) {
239
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
240
+ }
236
241
  const def = mergeDefs(schema._zod.def, {
237
242
  get shape() {
238
243
  const newShape = {};
@@ -253,6 +258,11 @@ function pick(schema, mask) {
253
258
  }
254
259
  function omit(schema, mask) {
255
260
  const currDef = schema._zod.def;
261
+ const checks = currDef.checks;
262
+ const hasChecks = checks && checks.length > 0;
263
+ if (hasChecks) {
264
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
265
+ }
256
266
  const def = mergeDefs(schema._zod.def, {
257
267
  get shape() {
258
268
  const newShape = { ...schema._zod.def.shape };
@@ -278,15 +288,19 @@ function extend(schema, shape) {
278
288
  const checks = schema._zod.def.checks;
279
289
  const hasChecks = checks && checks.length > 0;
280
290
  if (hasChecks) {
281
- throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
291
+ const existingShape = schema._zod.def.shape;
292
+ for (const key in shape) {
293
+ if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) {
294
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
295
+ }
296
+ }
282
297
  }
283
298
  const def = mergeDefs(schema._zod.def, {
284
299
  get shape() {
285
300
  const _shape = { ...schema._zod.def.shape, ...shape };
286
301
  assignProp(this, "shape", _shape);
287
302
  return _shape;
288
- },
289
- checks: []
303
+ }
290
304
  });
291
305
  return clone(schema, def);
292
306
  }
@@ -294,15 +308,13 @@ function safeExtend(schema, shape) {
294
308
  if (!isPlainObject(shape)) {
295
309
  throw new Error("Invalid input to safeExtend: expected a plain object");
296
310
  }
297
- const def = {
298
- ...schema._zod.def,
311
+ const def = mergeDefs(schema._zod.def, {
299
312
  get shape() {
300
313
  const _shape = { ...schema._zod.def.shape, ...shape };
301
314
  assignProp(this, "shape", _shape);
302
315
  return _shape;
303
- },
304
- checks: schema._zod.def.checks
305
- };
316
+ }
317
+ });
306
318
  return clone(schema, def);
307
319
  }
308
320
  function merge(a, b) {
@@ -321,6 +333,12 @@ function merge(a, b) {
321
333
  return clone(a, def);
322
334
  }
323
335
  function partial(Class, schema, mask) {
336
+ const currDef = schema._zod.def;
337
+ const checks = currDef.checks;
338
+ const hasChecks = checks && checks.length > 0;
339
+ if (hasChecks) {
340
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
341
+ }
324
342
  const def = mergeDefs(schema._zod.def, {
325
343
  get shape() {
326
344
  const oldShape = schema._zod.def.shape;
@@ -379,8 +397,7 @@ function required(Class, schema, mask) {
379
397
  }
380
398
  assignProp(this, "shape", shape);
381
399
  return shape;
382
- },
383
- checks: []
400
+ }
384
401
  });
385
402
  return clone(schema, def);
386
403
  }
@@ -601,7 +618,7 @@ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-
601
618
  const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
602
619
  const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
603
620
  const base64url = /^[A-Za-z0-9_-]*$/;
604
- const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
621
+ const e164 = /^\+[1-9]\d{6,14}$/;
605
622
  const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
606
623
  const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
607
624
  function timeSource(args) {
@@ -627,7 +644,7 @@ const string$1 = (params) => {
627
644
  return new RegExp(`^${regex}$`);
628
645
  };
629
646
  const integer = /^-?\d+$/;
630
- const number$1 = /^-?\d+(?:\.\d+)?/;
647
+ const number$1 = /^-?\d+(?:\.\d+)?$/;
631
648
  const boolean$1 = /^(?:true|false)$/i;
632
649
  const lowercase = /^[^A-Z]*$/;
633
650
  const uppercase = /^[^a-z]*$/;
@@ -662,7 +679,7 @@ const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (ins
662
679
  payload.issues.push({
663
680
  origin,
664
681
  code: "too_big",
665
- maximum: def.value,
682
+ maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
666
683
  input: payload.value,
667
684
  inclusive: def.inclusive,
668
685
  inst,
@@ -690,7 +707,7 @@ const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan"
690
707
  payload.issues.push({
691
708
  origin,
692
709
  code: "too_small",
693
- minimum: def.value,
710
+ minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
694
711
  input: payload.value,
695
712
  inclusive: def.inclusive,
696
713
  inst,
@@ -757,6 +774,7 @@ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberForma
757
774
  note: "Integers must be within the safe integer range.",
758
775
  inst,
759
776
  origin,
777
+ inclusive: true,
760
778
  continue: !def.abort
761
779
  });
762
780
  } else {
@@ -767,6 +785,7 @@ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberForma
767
785
  note: "Integers must be within the safe integer range.",
768
786
  inst,
769
787
  origin,
788
+ inclusive: true,
770
789
  continue: !def.abort
771
790
  });
772
791
  }
@@ -790,7 +809,9 @@ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberForma
790
809
  input,
791
810
  code: "too_big",
792
811
  maximum,
793
- inst
812
+ inclusive: true,
813
+ inst,
814
+ continue: !def.abort
794
815
  });
795
816
  }
796
817
  };
@@ -1051,8 +1072,8 @@ class Doc {
1051
1072
  }
1052
1073
  const version = {
1053
1074
  major: 4,
1054
- minor: 2,
1055
- patch: 1
1075
+ minor: 3,
1076
+ patch: 5
1056
1077
  };
1057
1078
  const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1058
1079
  var _a2;
@@ -1150,7 +1171,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1150
1171
  return runChecks(result, checks, ctx);
1151
1172
  };
1152
1173
  }
1153
- inst["~standard"] = {
1174
+ defineLazy(inst, "~standard", () => ({
1154
1175
  validate: (value) => {
1155
1176
  try {
1156
1177
  const r = safeParse$1(inst, value);
@@ -1161,7 +1182,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1161
1182
  },
1162
1183
  vendor: "zod",
1163
1184
  version: 1
1164
- };
1185
+ }));
1165
1186
  });
1166
1187
  const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1167
1188
  $ZodType.init(inst, def);
@@ -1558,8 +1579,11 @@ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1558
1579
  return payload;
1559
1580
  };
1560
1581
  });
1561
- function handlePropertyResult(result, final, key, input) {
1582
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
1562
1583
  if (result.issues.length) {
1584
+ if (isOptionalOut && !(key in input)) {
1585
+ return;
1586
+ }
1563
1587
  final.issues.push(...prefixIssues(key, result.issues));
1564
1588
  }
1565
1589
  if (result.value === void 0) {
@@ -1591,6 +1615,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
1591
1615
  const keySet = def.keySet;
1592
1616
  const _catchall = def.catchall._zod;
1593
1617
  const t = _catchall.def.type;
1618
+ const isOptionalOut = _catchall.optout === "optional";
1594
1619
  for (const key in input) {
1595
1620
  if (keySet.has(key))
1596
1621
  continue;
@@ -1600,9 +1625,9 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
1600
1625
  }
1601
1626
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1602
1627
  if (r instanceof Promise) {
1603
- proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
1628
+ proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
1604
1629
  } else {
1605
- handlePropertyResult(r, payload, key, input);
1630
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1606
1631
  }
1607
1632
  }
1608
1633
  if (unrecognized.length) {
@@ -1668,11 +1693,12 @@ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1668
1693
  const shape = value.shape;
1669
1694
  for (const key of value.keys) {
1670
1695
  const el = shape[key];
1696
+ const isOptionalOut = el._zod.optout === "optional";
1671
1697
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1672
1698
  if (r instanceof Promise) {
1673
- proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
1699
+ proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
1674
1700
  } else {
1675
- handlePropertyResult(r, payload, key, input);
1701
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1676
1702
  }
1677
1703
  }
1678
1704
  if (!catchall) {
@@ -1702,8 +1728,31 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
1702
1728
  for (const key of normalized.keys) {
1703
1729
  const id = ids[key];
1704
1730
  const k = esc(key);
1731
+ const schema = shape[key];
1732
+ const isOptionalOut = schema?._zod?.optout === "optional";
1705
1733
  doc.write(`const ${id} = ${parseStr(key)};`);
1706
- doc.write(`
1734
+ if (isOptionalOut) {
1735
+ doc.write(`
1736
+ if (${id}.issues.length) {
1737
+ if (${k} in input) {
1738
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1739
+ ...iss,
1740
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1741
+ })));
1742
+ }
1743
+ }
1744
+
1745
+ if (${id}.value === undefined) {
1746
+ if (${k} in input) {
1747
+ newResult[${k}] = undefined;
1748
+ }
1749
+ } else {
1750
+ newResult[${k}] = ${id}.value;
1751
+ }
1752
+
1753
+ `);
1754
+ } else {
1755
+ doc.write(`
1707
1756
  if (${id}.issues.length) {
1708
1757
  payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1709
1758
  ...iss,
@@ -1711,7 +1760,6 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
1711
1760
  })));
1712
1761
  }
1713
1762
 
1714
-
1715
1763
  if (${id}.value === undefined) {
1716
1764
  if (${k} in input) {
1717
1765
  newResult[${k}] = undefined;
@@ -1721,6 +1769,7 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
1721
1769
  }
1722
1770
 
1723
1771
  `);
1772
+ }
1724
1773
  }
1725
1774
  doc.write(`payload.value = newResult;`);
1726
1775
  doc.write(`return payload;`);
@@ -1883,11 +1932,34 @@ function mergeValues(a, b) {
1883
1932
  return { valid: false, mergeErrorPath: [] };
1884
1933
  }
1885
1934
  function handleIntersectionResults(result, left, right) {
1886
- if (left.issues.length) {
1887
- result.issues.push(...left.issues);
1935
+ const unrecKeys = /* @__PURE__ */ new Map();
1936
+ let unrecIssue;
1937
+ for (const iss of left.issues) {
1938
+ if (iss.code === "unrecognized_keys") {
1939
+ unrecIssue ?? (unrecIssue = iss);
1940
+ for (const k of iss.keys) {
1941
+ if (!unrecKeys.has(k))
1942
+ unrecKeys.set(k, {});
1943
+ unrecKeys.get(k).l = true;
1944
+ }
1945
+ } else {
1946
+ result.issues.push(iss);
1947
+ }
1888
1948
  }
1889
- if (right.issues.length) {
1890
- result.issues.push(...right.issues);
1949
+ for (const iss of right.issues) {
1950
+ if (iss.code === "unrecognized_keys") {
1951
+ for (const k of iss.keys) {
1952
+ if (!unrecKeys.has(k))
1953
+ unrecKeys.set(k, {});
1954
+ unrecKeys.get(k).r = true;
1955
+ }
1956
+ } else {
1957
+ result.issues.push(iss);
1958
+ }
1959
+ }
1960
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1961
+ if (bothKeys.length && unrecIssue) {
1962
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
1891
1963
  }
1892
1964
  if (aborted(result))
1893
1965
  return result;
@@ -1955,10 +2027,20 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1955
2027
  for (const key of Reflect.ownKeys(input)) {
1956
2028
  if (key === "__proto__")
1957
2029
  continue;
1958
- const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2030
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1959
2031
  if (keyResult instanceof Promise) {
1960
2032
  throw new Error("Async schemas not supported in object keys currently");
1961
2033
  }
2034
+ const checkNumericKey = typeof key === "string" && number$1.test(key) && keyResult.issues.length && keyResult.issues.some((iss) => iss.code === "invalid_type" && iss.expected === "number");
2035
+ if (checkNumericKey) {
2036
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
2037
+ if (retryResult instanceof Promise) {
2038
+ throw new Error("Async schemas not supported in object keys currently");
2039
+ }
2040
+ if (retryResult.issues.length === 0) {
2041
+ keyResult = retryResult;
2042
+ }
2043
+ }
1962
2044
  if (keyResult.issues.length) {
1963
2045
  if (def.mode === "loose") {
1964
2046
  payload.value[key] = input[key];
@@ -2067,6 +2149,14 @@ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) =>
2067
2149
  return def.innerType._zod.run(payload, ctx);
2068
2150
  };
2069
2151
  });
2152
+ const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
2153
+ $ZodOptional.init(inst, def);
2154
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2155
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2156
+ inst._zod.parse = (payload, ctx) => {
2157
+ return def.innerType._zod.run(payload, ctx);
2158
+ };
2159
+ });
2070
2160
  const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
2071
2161
  $ZodType.init(inst, def);
2072
2162
  defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
@@ -2280,9 +2370,6 @@ class $ZodRegistry {
2280
2370
  const meta = _meta[0];
2281
2371
  this._map.set(schema, meta);
2282
2372
  if (meta && typeof meta === "object" && "id" in meta) {
2283
- if (this._idmap.has(meta.id)) {
2284
- throw new Error(`ID ${meta.id} already exists in the registry`);
2285
- }
2286
2373
  this._idmap.set(meta.id, schema);
2287
2374
  }
2288
2375
  return this;
@@ -2319,12 +2406,14 @@ function registry() {
2319
2406
  }
2320
2407
  (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2321
2408
  const globalRegistry = globalThis.__zod_globalRegistry;
2409
+ // @__NO_SIDE_EFFECTS__
2322
2410
  function _string(Class, params) {
2323
2411
  return new Class({
2324
2412
  type: "string",
2325
2413
  ...normalizeParams(params)
2326
2414
  });
2327
2415
  }
2416
+ // @__NO_SIDE_EFFECTS__
2328
2417
  function _email(Class, params) {
2329
2418
  return new Class({
2330
2419
  type: "string",
@@ -2334,6 +2423,7 @@ function _email(Class, params) {
2334
2423
  ...normalizeParams(params)
2335
2424
  });
2336
2425
  }
2426
+ // @__NO_SIDE_EFFECTS__
2337
2427
  function _guid(Class, params) {
2338
2428
  return new Class({
2339
2429
  type: "string",
@@ -2343,6 +2433,7 @@ function _guid(Class, params) {
2343
2433
  ...normalizeParams(params)
2344
2434
  });
2345
2435
  }
2436
+ // @__NO_SIDE_EFFECTS__
2346
2437
  function _uuid(Class, params) {
2347
2438
  return new Class({
2348
2439
  type: "string",
@@ -2352,6 +2443,7 @@ function _uuid(Class, params) {
2352
2443
  ...normalizeParams(params)
2353
2444
  });
2354
2445
  }
2446
+ // @__NO_SIDE_EFFECTS__
2355
2447
  function _uuidv4(Class, params) {
2356
2448
  return new Class({
2357
2449
  type: "string",
@@ -2362,6 +2454,7 @@ function _uuidv4(Class, params) {
2362
2454
  ...normalizeParams(params)
2363
2455
  });
2364
2456
  }
2457
+ // @__NO_SIDE_EFFECTS__
2365
2458
  function _uuidv6(Class, params) {
2366
2459
  return new Class({
2367
2460
  type: "string",
@@ -2372,6 +2465,7 @@ function _uuidv6(Class, params) {
2372
2465
  ...normalizeParams(params)
2373
2466
  });
2374
2467
  }
2468
+ // @__NO_SIDE_EFFECTS__
2375
2469
  function _uuidv7(Class, params) {
2376
2470
  return new Class({
2377
2471
  type: "string",
@@ -2382,6 +2476,7 @@ function _uuidv7(Class, params) {
2382
2476
  ...normalizeParams(params)
2383
2477
  });
2384
2478
  }
2479
+ // @__NO_SIDE_EFFECTS__
2385
2480
  function _url(Class, params) {
2386
2481
  return new Class({
2387
2482
  type: "string",
@@ -2391,6 +2486,7 @@ function _url(Class, params) {
2391
2486
  ...normalizeParams(params)
2392
2487
  });
2393
2488
  }
2489
+ // @__NO_SIDE_EFFECTS__
2394
2490
  function _emoji(Class, params) {
2395
2491
  return new Class({
2396
2492
  type: "string",
@@ -2400,6 +2496,7 @@ function _emoji(Class, params) {
2400
2496
  ...normalizeParams(params)
2401
2497
  });
2402
2498
  }
2499
+ // @__NO_SIDE_EFFECTS__
2403
2500
  function _nanoid(Class, params) {
2404
2501
  return new Class({
2405
2502
  type: "string",
@@ -2409,6 +2506,7 @@ function _nanoid(Class, params) {
2409
2506
  ...normalizeParams(params)
2410
2507
  });
2411
2508
  }
2509
+ // @__NO_SIDE_EFFECTS__
2412
2510
  function _cuid(Class, params) {
2413
2511
  return new Class({
2414
2512
  type: "string",
@@ -2418,6 +2516,7 @@ function _cuid(Class, params) {
2418
2516
  ...normalizeParams(params)
2419
2517
  });
2420
2518
  }
2519
+ // @__NO_SIDE_EFFECTS__
2421
2520
  function _cuid2(Class, params) {
2422
2521
  return new Class({
2423
2522
  type: "string",
@@ -2427,6 +2526,7 @@ function _cuid2(Class, params) {
2427
2526
  ...normalizeParams(params)
2428
2527
  });
2429
2528
  }
2529
+ // @__NO_SIDE_EFFECTS__
2430
2530
  function _ulid(Class, params) {
2431
2531
  return new Class({
2432
2532
  type: "string",
@@ -2436,6 +2536,7 @@ function _ulid(Class, params) {
2436
2536
  ...normalizeParams(params)
2437
2537
  });
2438
2538
  }
2539
+ // @__NO_SIDE_EFFECTS__
2439
2540
  function _xid(Class, params) {
2440
2541
  return new Class({
2441
2542
  type: "string",
@@ -2445,6 +2546,7 @@ function _xid(Class, params) {
2445
2546
  ...normalizeParams(params)
2446
2547
  });
2447
2548
  }
2549
+ // @__NO_SIDE_EFFECTS__
2448
2550
  function _ksuid(Class, params) {
2449
2551
  return new Class({
2450
2552
  type: "string",
@@ -2454,6 +2556,7 @@ function _ksuid(Class, params) {
2454
2556
  ...normalizeParams(params)
2455
2557
  });
2456
2558
  }
2559
+ // @__NO_SIDE_EFFECTS__
2457
2560
  function _ipv4(Class, params) {
2458
2561
  return new Class({
2459
2562
  type: "string",
@@ -2463,6 +2566,7 @@ function _ipv4(Class, params) {
2463
2566
  ...normalizeParams(params)
2464
2567
  });
2465
2568
  }
2569
+ // @__NO_SIDE_EFFECTS__
2466
2570
  function _ipv6(Class, params) {
2467
2571
  return new Class({
2468
2572
  type: "string",
@@ -2472,6 +2576,7 @@ function _ipv6(Class, params) {
2472
2576
  ...normalizeParams(params)
2473
2577
  });
2474
2578
  }
2579
+ // @__NO_SIDE_EFFECTS__
2475
2580
  function _cidrv4(Class, params) {
2476
2581
  return new Class({
2477
2582
  type: "string",
@@ -2481,6 +2586,7 @@ function _cidrv4(Class, params) {
2481
2586
  ...normalizeParams(params)
2482
2587
  });
2483
2588
  }
2589
+ // @__NO_SIDE_EFFECTS__
2484
2590
  function _cidrv6(Class, params) {
2485
2591
  return new Class({
2486
2592
  type: "string",
@@ -2490,6 +2596,7 @@ function _cidrv6(Class, params) {
2490
2596
  ...normalizeParams(params)
2491
2597
  });
2492
2598
  }
2599
+ // @__NO_SIDE_EFFECTS__
2493
2600
  function _base64(Class, params) {
2494
2601
  return new Class({
2495
2602
  type: "string",
@@ -2499,6 +2606,7 @@ function _base64(Class, params) {
2499
2606
  ...normalizeParams(params)
2500
2607
  });
2501
2608
  }
2609
+ // @__NO_SIDE_EFFECTS__
2502
2610
  function _base64url(Class, params) {
2503
2611
  return new Class({
2504
2612
  type: "string",
@@ -2508,6 +2616,7 @@ function _base64url(Class, params) {
2508
2616
  ...normalizeParams(params)
2509
2617
  });
2510
2618
  }
2619
+ // @__NO_SIDE_EFFECTS__
2511
2620
  function _e164(Class, params) {
2512
2621
  return new Class({
2513
2622
  type: "string",
@@ -2517,6 +2626,7 @@ function _e164(Class, params) {
2517
2626
  ...normalizeParams(params)
2518
2627
  });
2519
2628
  }
2629
+ // @__NO_SIDE_EFFECTS__
2520
2630
  function _jwt(Class, params) {
2521
2631
  return new Class({
2522
2632
  type: "string",
@@ -2526,6 +2636,7 @@ function _jwt(Class, params) {
2526
2636
  ...normalizeParams(params)
2527
2637
  });
2528
2638
  }
2639
+ // @__NO_SIDE_EFFECTS__
2529
2640
  function _isoDateTime(Class, params) {
2530
2641
  return new Class({
2531
2642
  type: "string",
@@ -2537,6 +2648,7 @@ function _isoDateTime(Class, params) {
2537
2648
  ...normalizeParams(params)
2538
2649
  });
2539
2650
  }
2651
+ // @__NO_SIDE_EFFECTS__
2540
2652
  function _isoDate(Class, params) {
2541
2653
  return new Class({
2542
2654
  type: "string",
@@ -2545,6 +2657,7 @@ function _isoDate(Class, params) {
2545
2657
  ...normalizeParams(params)
2546
2658
  });
2547
2659
  }
2660
+ // @__NO_SIDE_EFFECTS__
2548
2661
  function _isoTime(Class, params) {
2549
2662
  return new Class({
2550
2663
  type: "string",
@@ -2554,6 +2667,7 @@ function _isoTime(Class, params) {
2554
2667
  ...normalizeParams(params)
2555
2668
  });
2556
2669
  }
2670
+ // @__NO_SIDE_EFFECTS__
2557
2671
  function _isoDuration(Class, params) {
2558
2672
  return new Class({
2559
2673
  type: "string",
@@ -2562,6 +2676,7 @@ function _isoDuration(Class, params) {
2562
2676
  ...normalizeParams(params)
2563
2677
  });
2564
2678
  }
2679
+ // @__NO_SIDE_EFFECTS__
2565
2680
  function _number(Class, params) {
2566
2681
  return new Class({
2567
2682
  type: "number",
@@ -2569,6 +2684,7 @@ function _number(Class, params) {
2569
2684
  ...normalizeParams(params)
2570
2685
  });
2571
2686
  }
2687
+ // @__NO_SIDE_EFFECTS__
2572
2688
  function _int(Class, params) {
2573
2689
  return new Class({
2574
2690
  type: "number",
@@ -2578,23 +2694,27 @@ function _int(Class, params) {
2578
2694
  ...normalizeParams(params)
2579
2695
  });
2580
2696
  }
2697
+ // @__NO_SIDE_EFFECTS__
2581
2698
  function _boolean(Class, params) {
2582
2699
  return new Class({
2583
2700
  type: "boolean",
2584
2701
  ...normalizeParams(params)
2585
2702
  });
2586
2703
  }
2704
+ // @__NO_SIDE_EFFECTS__
2587
2705
  function _unknown(Class) {
2588
2706
  return new Class({
2589
2707
  type: "unknown"
2590
2708
  });
2591
2709
  }
2710
+ // @__NO_SIDE_EFFECTS__
2592
2711
  function _never(Class, params) {
2593
2712
  return new Class({
2594
2713
  type: "never",
2595
2714
  ...normalizeParams(params)
2596
2715
  });
2597
2716
  }
2717
+ // @__NO_SIDE_EFFECTS__
2598
2718
  function _lt(value, params) {
2599
2719
  return new $ZodCheckLessThan({
2600
2720
  check: "less_than",
@@ -2603,6 +2723,7 @@ function _lt(value, params) {
2603
2723
  inclusive: false
2604
2724
  });
2605
2725
  }
2726
+ // @__NO_SIDE_EFFECTS__
2606
2727
  function _lte(value, params) {
2607
2728
  return new $ZodCheckLessThan({
2608
2729
  check: "less_than",
@@ -2611,6 +2732,7 @@ function _lte(value, params) {
2611
2732
  inclusive: true
2612
2733
  });
2613
2734
  }
2735
+ // @__NO_SIDE_EFFECTS__
2614
2736
  function _gt(value, params) {
2615
2737
  return new $ZodCheckGreaterThan({
2616
2738
  check: "greater_than",
@@ -2619,6 +2741,7 @@ function _gt(value, params) {
2619
2741
  inclusive: false
2620
2742
  });
2621
2743
  }
2744
+ // @__NO_SIDE_EFFECTS__
2622
2745
  function _gte(value, params) {
2623
2746
  return new $ZodCheckGreaterThan({
2624
2747
  check: "greater_than",
@@ -2627,6 +2750,7 @@ function _gte(value, params) {
2627
2750
  inclusive: true
2628
2751
  });
2629
2752
  }
2753
+ // @__NO_SIDE_EFFECTS__
2630
2754
  function _multipleOf(value, params) {
2631
2755
  return new $ZodCheckMultipleOf({
2632
2756
  check: "multiple_of",
@@ -2634,6 +2758,7 @@ function _multipleOf(value, params) {
2634
2758
  value
2635
2759
  });
2636
2760
  }
2761
+ // @__NO_SIDE_EFFECTS__
2637
2762
  function _maxLength(maximum, params) {
2638
2763
  const ch = new $ZodCheckMaxLength({
2639
2764
  check: "max_length",
@@ -2642,6 +2767,7 @@ function _maxLength(maximum, params) {
2642
2767
  });
2643
2768
  return ch;
2644
2769
  }
2770
+ // @__NO_SIDE_EFFECTS__
2645
2771
  function _minLength(minimum, params) {
2646
2772
  return new $ZodCheckMinLength({
2647
2773
  check: "min_length",
@@ -2649,6 +2775,7 @@ function _minLength(minimum, params) {
2649
2775
  minimum
2650
2776
  });
2651
2777
  }
2778
+ // @__NO_SIDE_EFFECTS__
2652
2779
  function _length(length, params) {
2653
2780
  return new $ZodCheckLengthEquals({
2654
2781
  check: "length_equals",
@@ -2656,6 +2783,7 @@ function _length(length, params) {
2656
2783
  length
2657
2784
  });
2658
2785
  }
2786
+ // @__NO_SIDE_EFFECTS__
2659
2787
  function _regex(pattern, params) {
2660
2788
  return new $ZodCheckRegex({
2661
2789
  check: "string_format",
@@ -2664,6 +2792,7 @@ function _regex(pattern, params) {
2664
2792
  pattern
2665
2793
  });
2666
2794
  }
2795
+ // @__NO_SIDE_EFFECTS__
2667
2796
  function _lowercase(params) {
2668
2797
  return new $ZodCheckLowerCase({
2669
2798
  check: "string_format",
@@ -2671,6 +2800,7 @@ function _lowercase(params) {
2671
2800
  ...normalizeParams(params)
2672
2801
  });
2673
2802
  }
2803
+ // @__NO_SIDE_EFFECTS__
2674
2804
  function _uppercase(params) {
2675
2805
  return new $ZodCheckUpperCase({
2676
2806
  check: "string_format",
@@ -2678,6 +2808,7 @@ function _uppercase(params) {
2678
2808
  ...normalizeParams(params)
2679
2809
  });
2680
2810
  }
2811
+ // @__NO_SIDE_EFFECTS__
2681
2812
  function _includes(includes, params) {
2682
2813
  return new $ZodCheckIncludes({
2683
2814
  check: "string_format",
@@ -2686,6 +2817,7 @@ function _includes(includes, params) {
2686
2817
  includes
2687
2818
  });
2688
2819
  }
2820
+ // @__NO_SIDE_EFFECTS__
2689
2821
  function _startsWith(prefix, params) {
2690
2822
  return new $ZodCheckStartsWith({
2691
2823
  check: "string_format",
@@ -2694,6 +2826,7 @@ function _startsWith(prefix, params) {
2694
2826
  prefix
2695
2827
  });
2696
2828
  }
2829
+ // @__NO_SIDE_EFFECTS__
2697
2830
  function _endsWith(suffix, params) {
2698
2831
  return new $ZodCheckEndsWith({
2699
2832
  check: "string_format",
@@ -2702,27 +2835,34 @@ function _endsWith(suffix, params) {
2702
2835
  suffix
2703
2836
  });
2704
2837
  }
2838
+ // @__NO_SIDE_EFFECTS__
2705
2839
  function _overwrite(tx) {
2706
2840
  return new $ZodCheckOverwrite({
2707
2841
  check: "overwrite",
2708
2842
  tx
2709
2843
  });
2710
2844
  }
2845
+ // @__NO_SIDE_EFFECTS__
2711
2846
  function _normalize(form) {
2712
- return _overwrite((input) => input.normalize(form));
2847
+ return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
2713
2848
  }
2849
+ // @__NO_SIDE_EFFECTS__
2714
2850
  function _trim() {
2715
- return _overwrite((input) => input.trim());
2851
+ return /* @__PURE__ */ _overwrite((input) => input.trim());
2716
2852
  }
2853
+ // @__NO_SIDE_EFFECTS__
2717
2854
  function _toLowerCase() {
2718
- return _overwrite((input) => input.toLowerCase());
2855
+ return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
2719
2856
  }
2857
+ // @__NO_SIDE_EFFECTS__
2720
2858
  function _toUpperCase() {
2721
- return _overwrite((input) => input.toUpperCase());
2859
+ return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
2722
2860
  }
2861
+ // @__NO_SIDE_EFFECTS__
2723
2862
  function _slugify() {
2724
- return _overwrite((input) => slugify(input));
2863
+ return /* @__PURE__ */ _overwrite((input) => slugify(input));
2725
2864
  }
2865
+ // @__NO_SIDE_EFFECTS__
2726
2866
  function _array(Class, element, params) {
2727
2867
  return new Class({
2728
2868
  type: "array",
@@ -2733,6 +2873,7 @@ function _array(Class, element, params) {
2733
2873
  ...normalizeParams(params)
2734
2874
  });
2735
2875
  }
2876
+ // @__NO_SIDE_EFFECTS__
2736
2877
  function _refine(Class, fn, _params) {
2737
2878
  const schema = new Class({
2738
2879
  type: "custom",
@@ -2742,8 +2883,9 @@ function _refine(Class, fn, _params) {
2742
2883
  });
2743
2884
  return schema;
2744
2885
  }
2886
+ // @__NO_SIDE_EFFECTS__
2745
2887
  function _superRefine(fn) {
2746
- const ch = _check((payload) => {
2888
+ const ch = /* @__PURE__ */ _check((payload) => {
2747
2889
  payload.addIssue = (issue$1) => {
2748
2890
  if (typeof issue$1 === "string") {
2749
2891
  payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
@@ -2762,6 +2904,7 @@ function _superRefine(fn) {
2762
2904
  });
2763
2905
  return ch;
2764
2906
  }
2907
+ // @__NO_SIDE_EFFECTS__
2765
2908
  function _check(fn, params) {
2766
2909
  const ch = new $ZodCheck({
2767
2910
  check: "custom",
@@ -2814,12 +2957,7 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
2814
2957
  schemaPath: [..._params.schemaPath, schema],
2815
2958
  path: _params.path
2816
2959
  };
2817
- const parent = schema._zod.parent;
2818
- if (parent) {
2819
- result.ref = parent;
2820
- process(parent, ctx, params);
2821
- ctx.seen.get(parent).isParent = true;
2822
- } else if (schema._zod.processJSONSchema) {
2960
+ if (schema._zod.processJSONSchema) {
2823
2961
  schema._zod.processJSONSchema(ctx, result.schema, params);
2824
2962
  } else {
2825
2963
  const _json = result.schema;
@@ -2829,6 +2967,13 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
2829
2967
  }
2830
2968
  processor(schema, ctx, _json, params);
2831
2969
  }
2970
+ const parent = schema._zod.parent;
2971
+ if (parent) {
2972
+ if (!result.ref)
2973
+ result.ref = parent;
2974
+ process(parent, ctx, params);
2975
+ ctx.seen.get(parent).isParent = true;
2976
+ }
2832
2977
  }
2833
2978
  const meta = ctx.metadataRegistry.get(schema);
2834
2979
  if (meta)
@@ -2847,6 +2992,17 @@ function extractDefs(ctx, schema) {
2847
2992
  const root = ctx.seen.get(schema);
2848
2993
  if (!root)
2849
2994
  throw new Error("Unprocessed schema. This is a bug in Zod.");
2995
+ const idToSchema = /* @__PURE__ */ new Map();
2996
+ for (const entry of ctx.seen.entries()) {
2997
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2998
+ if (id) {
2999
+ const existing = idToSchema.get(id);
3000
+ if (existing && existing !== entry[0]) {
3001
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
3002
+ }
3003
+ idToSchema.set(id, entry[0]);
3004
+ }
3005
+ }
2850
3006
  const makeURI = (entry) => {
2851
3007
  const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2852
3008
  if (ctx.external) {
@@ -2928,30 +3084,65 @@ function finalize(ctx, schema) {
2928
3084
  throw new Error("Unprocessed schema. This is a bug in Zod.");
2929
3085
  const flattenRef = (zodSchema) => {
2930
3086
  const seen = ctx.seen.get(zodSchema);
3087
+ if (seen.ref === null)
3088
+ return;
2931
3089
  const schema2 = seen.def ?? seen.schema;
2932
3090
  const _cached = { ...schema2 };
2933
- if (seen.ref === null) {
2934
- return;
2935
- }
2936
3091
  const ref = seen.ref;
2937
3092
  seen.ref = null;
2938
3093
  if (ref) {
2939
3094
  flattenRef(ref);
2940
- const refSchema = ctx.seen.get(ref).schema;
3095
+ const refSeen = ctx.seen.get(ref);
3096
+ const refSchema = refSeen.schema;
2941
3097
  if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2942
3098
  schema2.allOf = schema2.allOf ?? [];
2943
3099
  schema2.allOf.push(refSchema);
2944
3100
  } else {
2945
3101
  Object.assign(schema2, refSchema);
2946
- Object.assign(schema2, _cached);
3102
+ }
3103
+ Object.assign(schema2, _cached);
3104
+ const isParentRef = zodSchema._zod.parent === ref;
3105
+ if (isParentRef) {
3106
+ for (const key in schema2) {
3107
+ if (key === "$ref" || key === "allOf")
3108
+ continue;
3109
+ if (!(key in _cached)) {
3110
+ delete schema2[key];
3111
+ }
3112
+ }
3113
+ }
3114
+ if (refSchema.$ref) {
3115
+ for (const key in schema2) {
3116
+ if (key === "$ref" || key === "allOf")
3117
+ continue;
3118
+ if (key in refSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(refSeen.def[key])) {
3119
+ delete schema2[key];
3120
+ }
3121
+ }
2947
3122
  }
2948
3123
  }
2949
- if (!seen.isParent)
2950
- ctx.override({
2951
- zodSchema,
2952
- jsonSchema: schema2,
2953
- path: seen.path ?? []
2954
- });
3124
+ const parent = zodSchema._zod.parent;
3125
+ if (parent && parent !== ref) {
3126
+ flattenRef(parent);
3127
+ const parentSeen = ctx.seen.get(parent);
3128
+ if (parentSeen?.schema.$ref) {
3129
+ schema2.$ref = parentSeen.schema.$ref;
3130
+ if (parentSeen.def) {
3131
+ for (const key in schema2) {
3132
+ if (key === "$ref" || key === "allOf")
3133
+ continue;
3134
+ if (key in parentSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(parentSeen.def[key])) {
3135
+ delete schema2[key];
3136
+ }
3137
+ }
3138
+ }
3139
+ }
3140
+ }
3141
+ ctx.override({
3142
+ zodSchema,
3143
+ jsonSchema: schema2,
3144
+ path: seen.path ?? []
3145
+ });
2955
3146
  };
2956
3147
  for (const entry of [...ctx.seen.entries()].reverse()) {
2957
3148
  flattenRef(entry[0]);
@@ -2995,8 +3186,8 @@ function finalize(ctx, schema) {
2995
3186
  value: {
2996
3187
  ...schema["~standard"],
2997
3188
  jsonSchema: {
2998
- input: createStandardJSONSchemaMethod(schema, "input"),
2999
- output: createStandardJSONSchemaMethod(schema, "output")
3189
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
3190
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
3000
3191
  }
3001
3192
  },
3002
3193
  enumerable: false,
@@ -3064,9 +3255,9 @@ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3064
3255
  extractDefs(ctx, schema);
3065
3256
  return finalize(ctx, schema);
3066
3257
  };
3067
- const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3258
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3068
3259
  const { libraryOptions, target } = params ?? {};
3069
- const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors: {} });
3260
+ const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
3070
3261
  process(schema, ctx);
3071
3262
  extractDefs(ctx, schema);
3072
3263
  return finalize(ctx, schema);
@@ -3091,6 +3282,9 @@ const stringProcessor = (schema, ctx, _json, _params) => {
3091
3282
  json.format = formatMap[format] ?? format;
3092
3283
  if (json.format === "")
3093
3284
  delete json.format;
3285
+ if (format === "time") {
3286
+ delete json.format;
3287
+ }
3094
3288
  }
3095
3289
  if (contentEncoding)
3096
3290
  json.contentEncoding = contentEncoding;
@@ -3260,16 +3454,37 @@ const recordProcessor = (schema, ctx, _json, params) => {
3260
3454
  const json = _json;
3261
3455
  const def = schema._zod.def;
3262
3456
  json.type = "object";
3263
- if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
3264
- json.propertyNames = process(def.keyType, ctx, {
3457
+ const keyType = def.keyType;
3458
+ const keyBag = keyType._zod.bag;
3459
+ const patterns = keyBag?.patterns;
3460
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
3461
+ const valueSchema = process(def.valueType, ctx, {
3462
+ ...params,
3463
+ path: [...params.path, "patternProperties", "*"]
3464
+ });
3465
+ json.patternProperties = {};
3466
+ for (const pattern of patterns) {
3467
+ json.patternProperties[pattern.source] = valueSchema;
3468
+ }
3469
+ } else {
3470
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
3471
+ json.propertyNames = process(def.keyType, ctx, {
3472
+ ...params,
3473
+ path: [...params.path, "propertyNames"]
3474
+ });
3475
+ }
3476
+ json.additionalProperties = process(def.valueType, ctx, {
3265
3477
  ...params,
3266
- path: [...params.path, "propertyNames"]
3478
+ path: [...params.path, "additionalProperties"]
3267
3479
  });
3268
3480
  }
3269
- json.additionalProperties = process(def.valueType, ctx, {
3270
- ...params,
3271
- path: [...params.path, "additionalProperties"]
3272
- });
3481
+ const keyValues = keyType._zod.values;
3482
+ if (keyValues) {
3483
+ const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
3484
+ if (validKeyValues.length > 0) {
3485
+ json.required = validKeyValues;
3486
+ }
3487
+ }
3273
3488
  };
3274
3489
  const nullableProcessor = (schema, ctx, json, params) => {
3275
3490
  const def = schema._zod.def;
@@ -3341,28 +3556,28 @@ const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def
3341
3556
  ZodStringFormat.init(inst, def);
3342
3557
  });
3343
3558
  function datetime(params) {
3344
- return _isoDateTime(ZodISODateTime, params);
3559
+ return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
3345
3560
  }
3346
3561
  const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
3347
3562
  $ZodISODate.init(inst, def);
3348
3563
  ZodStringFormat.init(inst, def);
3349
3564
  });
3350
3565
  function date(params) {
3351
- return _isoDate(ZodISODate, params);
3566
+ return /* @__PURE__ */ _isoDate(ZodISODate, params);
3352
3567
  }
3353
3568
  const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
3354
3569
  $ZodISOTime.init(inst, def);
3355
3570
  ZodStringFormat.init(inst, def);
3356
3571
  });
3357
3572
  function time(params) {
3358
- return _isoTime(ZodISOTime, params);
3573
+ return /* @__PURE__ */ _isoTime(ZodISOTime, params);
3359
3574
  }
3360
3575
  const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
3361
3576
  $ZodISODuration.init(inst, def);
3362
3577
  ZodStringFormat.init(inst, def);
3363
3578
  });
3364
3579
  function duration(params) {
3365
- return _isoDuration(ZodISODuration, params);
3580
+ return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
3366
3581
  }
3367
3582
  const initializer = (inst, issues) => {
3368
3583
  $ZodError.init(inst, issues);
@@ -3431,8 +3646,11 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
3431
3646
  ...def.checks ?? [],
3432
3647
  ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
3433
3648
  ]
3434
- }));
3649
+ }), {
3650
+ parent: true
3651
+ });
3435
3652
  };
3653
+ inst.with = inst.check;
3436
3654
  inst.clone = (def2, params) => clone(inst, def2, params);
3437
3655
  inst.brand = () => inst;
3438
3656
  inst.register = ((reg, meta) => {
@@ -3454,8 +3672,9 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
3454
3672
  inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3455
3673
  inst.refine = (check, params) => inst.check(refine(check, params));
3456
3674
  inst.superRefine = (refinement) => inst.check(superRefine(refinement));
3457
- inst.overwrite = (fn) => inst.check(_overwrite(fn));
3675
+ inst.overwrite = (fn) => inst.check(/* @__PURE__ */ _overwrite(fn));
3458
3676
  inst.optional = () => optional(inst);
3677
+ inst.exactOptional = () => exactOptional(inst);
3459
3678
  inst.nullable = () => nullable(inst);
3460
3679
  inst.nullish = () => optional(nullable(inst));
3461
3680
  inst.nonoptional = (params) => nonoptional(inst, params);
@@ -3489,6 +3708,7 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
3489
3708
  };
3490
3709
  inst.isOptional = () => inst.safeParse(void 0).success;
3491
3710
  inst.isNullable = () => inst.safeParse(null).success;
3711
+ inst.apply = (fn) => fn(inst);
3492
3712
  return inst;
3493
3713
  });
3494
3714
  const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
@@ -3499,55 +3719,55 @@ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
3499
3719
  inst.format = bag.format ?? null;
3500
3720
  inst.minLength = bag.minimum ?? null;
3501
3721
  inst.maxLength = bag.maximum ?? null;
3502
- inst.regex = (...args) => inst.check(_regex(...args));
3503
- inst.includes = (...args) => inst.check(_includes(...args));
3504
- inst.startsWith = (...args) => inst.check(_startsWith(...args));
3505
- inst.endsWith = (...args) => inst.check(_endsWith(...args));
3506
- inst.min = (...args) => inst.check(_minLength(...args));
3507
- inst.max = (...args) => inst.check(_maxLength(...args));
3508
- inst.length = (...args) => inst.check(_length(...args));
3509
- inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
3510
- inst.lowercase = (params) => inst.check(_lowercase(params));
3511
- inst.uppercase = (params) => inst.check(_uppercase(params));
3512
- inst.trim = () => inst.check(_trim());
3513
- inst.normalize = (...args) => inst.check(_normalize(...args));
3514
- inst.toLowerCase = () => inst.check(_toLowerCase());
3515
- inst.toUpperCase = () => inst.check(_toUpperCase());
3516
- inst.slugify = () => inst.check(_slugify());
3722
+ inst.regex = (...args) => inst.check(/* @__PURE__ */ _regex(...args));
3723
+ inst.includes = (...args) => inst.check(/* @__PURE__ */ _includes(...args));
3724
+ inst.startsWith = (...args) => inst.check(/* @__PURE__ */ _startsWith(...args));
3725
+ inst.endsWith = (...args) => inst.check(/* @__PURE__ */ _endsWith(...args));
3726
+ inst.min = (...args) => inst.check(/* @__PURE__ */ _minLength(...args));
3727
+ inst.max = (...args) => inst.check(/* @__PURE__ */ _maxLength(...args));
3728
+ inst.length = (...args) => inst.check(/* @__PURE__ */ _length(...args));
3729
+ inst.nonempty = (...args) => inst.check(/* @__PURE__ */ _minLength(1, ...args));
3730
+ inst.lowercase = (params) => inst.check(/* @__PURE__ */ _lowercase(params));
3731
+ inst.uppercase = (params) => inst.check(/* @__PURE__ */ _uppercase(params));
3732
+ inst.trim = () => inst.check(/* @__PURE__ */ _trim());
3733
+ inst.normalize = (...args) => inst.check(/* @__PURE__ */ _normalize(...args));
3734
+ inst.toLowerCase = () => inst.check(/* @__PURE__ */ _toLowerCase());
3735
+ inst.toUpperCase = () => inst.check(/* @__PURE__ */ _toUpperCase());
3736
+ inst.slugify = () => inst.check(/* @__PURE__ */ _slugify());
3517
3737
  });
3518
3738
  const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
3519
3739
  $ZodString.init(inst, def);
3520
3740
  _ZodString.init(inst, def);
3521
- inst.email = (params) => inst.check(_email(ZodEmail, params));
3522
- inst.url = (params) => inst.check(_url(ZodURL, params));
3523
- inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
3524
- inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
3525
- inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3526
- inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
3527
- inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
3528
- inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
3529
- inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
3530
- inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
3531
- inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3532
- inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
3533
- inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
3534
- inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
3535
- inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
3536
- inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
3537
- inst.xid = (params) => inst.check(_xid(ZodXID, params));
3538
- inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
3539
- inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
3540
- inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
3541
- inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
3542
- inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
3543
- inst.e164 = (params) => inst.check(_e164(ZodE164, params));
3741
+ inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
3742
+ inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
3743
+ inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
3744
+ inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
3745
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3746
+ inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
3747
+ inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
3748
+ inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
3749
+ inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
3750
+ inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
3751
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3752
+ inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
3753
+ inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
3754
+ inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
3755
+ inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
3756
+ inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
3757
+ inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
3758
+ inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
3759
+ inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
3760
+ inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
3761
+ inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
3762
+ inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
3763
+ inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
3544
3764
  inst.datetime = (params) => inst.check(datetime(params));
3545
3765
  inst.date = (params) => inst.check(date(params));
3546
3766
  inst.time = (params) => inst.check(time(params));
3547
3767
  inst.duration = (params) => inst.check(duration(params));
3548
3768
  });
3549
3769
  function string(params) {
3550
- return _string(ZodString, params);
3770
+ return /* @__PURE__ */ _string(ZodString, params);
3551
3771
  }
3552
3772
  const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
3553
3773
  $ZodStringFormat.init(inst, def);
@@ -3633,20 +3853,20 @@ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
3633
3853
  $ZodNumber.init(inst, def);
3634
3854
  ZodType.init(inst, def);
3635
3855
  inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
3636
- inst.gt = (value, params) => inst.check(_gt(value, params));
3637
- inst.gte = (value, params) => inst.check(_gte(value, params));
3638
- inst.min = (value, params) => inst.check(_gte(value, params));
3639
- inst.lt = (value, params) => inst.check(_lt(value, params));
3640
- inst.lte = (value, params) => inst.check(_lte(value, params));
3641
- inst.max = (value, params) => inst.check(_lte(value, params));
3856
+ inst.gt = (value, params) => inst.check(/* @__PURE__ */ _gt(value, params));
3857
+ inst.gte = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
3858
+ inst.min = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
3859
+ inst.lt = (value, params) => inst.check(/* @__PURE__ */ _lt(value, params));
3860
+ inst.lte = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
3861
+ inst.max = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
3642
3862
  inst.int = (params) => inst.check(int(params));
3643
3863
  inst.safe = (params) => inst.check(int(params));
3644
- inst.positive = (params) => inst.check(_gt(0, params));
3645
- inst.nonnegative = (params) => inst.check(_gte(0, params));
3646
- inst.negative = (params) => inst.check(_lt(0, params));
3647
- inst.nonpositive = (params) => inst.check(_lte(0, params));
3648
- inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
3649
- inst.step = (value, params) => inst.check(_multipleOf(value, params));
3864
+ inst.positive = (params) => inst.check(/* @__PURE__ */ _gt(0, params));
3865
+ inst.nonnegative = (params) => inst.check(/* @__PURE__ */ _gte(0, params));
3866
+ inst.negative = (params) => inst.check(/* @__PURE__ */ _lt(0, params));
3867
+ inst.nonpositive = (params) => inst.check(/* @__PURE__ */ _lte(0, params));
3868
+ inst.multipleOf = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
3869
+ inst.step = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
3650
3870
  inst.finite = () => inst;
3651
3871
  const bag = inst._zod.bag;
3652
3872
  inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
@@ -3656,14 +3876,14 @@ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
3656
3876
  inst.format = bag.format ?? null;
3657
3877
  });
3658
3878
  function number(params) {
3659
- return _number(ZodNumber, params);
3879
+ return /* @__PURE__ */ _number(ZodNumber, params);
3660
3880
  }
3661
3881
  const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
3662
3882
  $ZodNumberFormat.init(inst, def);
3663
3883
  ZodNumber.init(inst, def);
3664
3884
  });
3665
3885
  function int(params) {
3666
- return _int(ZodNumberFormat, params);
3886
+ return /* @__PURE__ */ _int(ZodNumberFormat, params);
3667
3887
  }
3668
3888
  const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
3669
3889
  $ZodBoolean.init(inst, def);
@@ -3671,7 +3891,7 @@ const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
3671
3891
  inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
3672
3892
  });
3673
3893
  function boolean(params) {
3674
- return _boolean(ZodBoolean, params);
3894
+ return /* @__PURE__ */ _boolean(ZodBoolean, params);
3675
3895
  }
3676
3896
  const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3677
3897
  $ZodUnknown.init(inst, def);
@@ -3679,7 +3899,7 @@ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3679
3899
  inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
3680
3900
  });
3681
3901
  function unknown() {
3682
- return _unknown(ZodUnknown);
3902
+ return /* @__PURE__ */ _unknown(ZodUnknown);
3683
3903
  }
3684
3904
  const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3685
3905
  $ZodNever.init(inst, def);
@@ -3687,21 +3907,21 @@ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3687
3907
  inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
3688
3908
  });
3689
3909
  function never(params) {
3690
- return _never(ZodNever, params);
3910
+ return /* @__PURE__ */ _never(ZodNever, params);
3691
3911
  }
3692
3912
  const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3693
3913
  $ZodArray.init(inst, def);
3694
3914
  ZodType.init(inst, def);
3695
3915
  inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3696
3916
  inst.element = def.element;
3697
- inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3698
- inst.nonempty = (params) => inst.check(_minLength(1, params));
3699
- inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
3700
- inst.length = (len, params) => inst.check(_length(len, params));
3917
+ inst.min = (minLength, params) => inst.check(/* @__PURE__ */ _minLength(minLength, params));
3918
+ inst.nonempty = (params) => inst.check(/* @__PURE__ */ _minLength(1, params));
3919
+ inst.max = (maxLength, params) => inst.check(/* @__PURE__ */ _maxLength(maxLength, params));
3920
+ inst.length = (len, params) => inst.check(/* @__PURE__ */ _length(len, params));
3701
3921
  inst.unwrap = () => inst.element;
3702
3922
  });
3703
3923
  function array(element, params) {
3704
- return _array(ZodArray, element, params);
3924
+ return /* @__PURE__ */ _array(ZodArray, element, params);
3705
3925
  }
3706
3926
  const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3707
3927
  $ZodObjectJIT.init(inst, def);
@@ -3872,6 +4092,18 @@ function optional(innerType) {
3872
4092
  innerType
3873
4093
  });
3874
4094
  }
4095
+ const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
4096
+ $ZodExactOptional.init(inst, def);
4097
+ ZodType.init(inst, def);
4098
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4099
+ inst.unwrap = () => inst._zod.def.innerType;
4100
+ });
4101
+ function exactOptional(innerType) {
4102
+ return new ZodExactOptional({
4103
+ type: "optional",
4104
+ innerType
4105
+ });
4106
+ }
3875
4107
  const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3876
4108
  $ZodNullable.init(inst, def);
3877
4109
  ZodType.init(inst, def);
@@ -3975,10 +4207,10 @@ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3975
4207
  inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
3976
4208
  });
3977
4209
  function refine(fn, _params = {}) {
3978
- return _refine(ZodCustom, fn, _params);
4210
+ return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
3979
4211
  }
3980
4212
  function superRefine(fn) {
3981
- return _superRefine(fn);
4213
+ return /* @__PURE__ */ _superRefine(fn);
3982
4214
  }
3983
4215
  export {
3984
4216
  _enum as _,