@naylence/agent-sdk 0.4.7 → 0.4.9

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.
@@ -5,12 +5,12 @@
5
5
  })(this, (function (exports, runtime, factory, core, node) { 'use strict';
6
6
 
7
7
  // This file is auto-generated during build - do not edit manually
8
- // Generated from package.json version: 0.4.7
8
+ // Generated from package.json version: 0.4.9
9
9
  /**
10
10
  * The package version, injected at build time.
11
11
  * @internal
12
12
  */
13
- const VERSION = '0.4.7';
13
+ const VERSION = '0.4.9';
14
14
 
15
15
  /**
16
16
  * AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
@@ -395,6 +395,11 @@
395
395
  };
396
396
  function pick(schema, mask) {
397
397
  const currDef = schema._zod.def;
398
+ const checks = currDef.checks;
399
+ const hasChecks = checks && checks.length > 0;
400
+ if (hasChecks) {
401
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
402
+ }
398
403
  const def = mergeDefs(schema._zod.def, {
399
404
  get shape() {
400
405
  const newShape = {};
@@ -415,6 +420,11 @@
415
420
  }
416
421
  function omit(schema, mask) {
417
422
  const currDef = schema._zod.def;
423
+ const checks = currDef.checks;
424
+ const hasChecks = checks && checks.length > 0;
425
+ if (hasChecks) {
426
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
427
+ }
418
428
  const def = mergeDefs(schema._zod.def, {
419
429
  get shape() {
420
430
  const newShape = { ...schema._zod.def.shape };
@@ -440,7 +450,14 @@
440
450
  const checks = schema._zod.def.checks;
441
451
  const hasChecks = checks && checks.length > 0;
442
452
  if (hasChecks) {
443
- throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
453
+ // Only throw if new shape overlaps with existing shape
454
+ // Use getOwnPropertyDescriptor to check key existence without accessing values
455
+ const existingShape = schema._zod.def.shape;
456
+ for (const key in shape) {
457
+ if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
458
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
459
+ }
460
+ }
444
461
  }
445
462
  const def = mergeDefs(schema._zod.def, {
446
463
  get shape() {
@@ -448,7 +465,6 @@
448
465
  assignProp(this, "shape", _shape); // self-caching
449
466
  return _shape;
450
467
  },
451
- checks: [],
452
468
  });
453
469
  return clone(schema, def);
454
470
  }
@@ -456,15 +472,13 @@
456
472
  if (!isPlainObject(shape)) {
457
473
  throw new Error("Invalid input to safeExtend: expected a plain object");
458
474
  }
459
- const def = {
460
- ...schema._zod.def,
475
+ const def = mergeDefs(schema._zod.def, {
461
476
  get shape() {
462
477
  const _shape = { ...schema._zod.def.shape, ...shape };
463
478
  assignProp(this, "shape", _shape); // self-caching
464
479
  return _shape;
465
480
  },
466
- checks: schema._zod.def.checks,
467
- };
481
+ });
468
482
  return clone(schema, def);
469
483
  }
470
484
  function merge(a, b) {
@@ -482,6 +496,12 @@
482
496
  return clone(a, def);
483
497
  }
484
498
  function partial(Class, schema, mask) {
499
+ const currDef = schema._zod.def;
500
+ const checks = currDef.checks;
501
+ const hasChecks = checks && checks.length > 0;
502
+ if (hasChecks) {
503
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
504
+ }
485
505
  const def = mergeDefs(schema._zod.def, {
486
506
  get shape() {
487
507
  const oldShape = schema._zod.def.shape;
@@ -551,7 +571,6 @@
551
571
  assignProp(this, "shape", shape); // self-caching
552
572
  return shape;
553
573
  },
554
- checks: [],
555
574
  });
556
575
  return clone(schema, def);
557
576
  }
@@ -801,7 +820,8 @@
801
820
  const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
802
821
  const base64url = /^[A-Za-z0-9_-]*$/;
803
822
  // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
804
- const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
823
+ // E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
824
+ const e164 = /^\+[1-9]\d{6,14}$/;
805
825
  // 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])))`;
806
826
  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])))`;
807
827
  const date$2 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
@@ -836,7 +856,7 @@
836
856
  return new RegExp(`^${regex}$`);
837
857
  };
838
858
  const integer = /^-?\d+$/;
839
- const number$1 = /^-?\d+(?:\.\d+)?/;
859
+ const number$1 = /^-?\d+(?:\.\d+)?$/;
840
860
  const boolean$1 = /^(?:true|false)$/i;
841
861
  // regex for string with no uppercase letters
842
862
  const lowercase = /^[^A-Z]*$/;
@@ -875,7 +895,7 @@
875
895
  payload.issues.push({
876
896
  origin,
877
897
  code: "too_big",
878
- maximum: def.value,
898
+ maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
879
899
  input: payload.value,
880
900
  inclusive: def.inclusive,
881
901
  inst,
@@ -903,7 +923,7 @@
903
923
  payload.issues.push({
904
924
  origin,
905
925
  code: "too_small",
906
- minimum: def.value,
926
+ minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
907
927
  input: payload.value,
908
928
  inclusive: def.inclusive,
909
929
  inst,
@@ -991,6 +1011,7 @@
991
1011
  note: "Integers must be within the safe integer range.",
992
1012
  inst,
993
1013
  origin,
1014
+ inclusive: true,
994
1015
  continue: !def.abort,
995
1016
  });
996
1017
  }
@@ -1003,6 +1024,7 @@
1003
1024
  note: "Integers must be within the safe integer range.",
1004
1025
  inst,
1005
1026
  origin,
1027
+ inclusive: true,
1006
1028
  continue: !def.abort,
1007
1029
  });
1008
1030
  }
@@ -1026,7 +1048,9 @@
1026
1048
  input,
1027
1049
  code: "too_big",
1028
1050
  maximum,
1051
+ inclusive: true,
1029
1052
  inst,
1053
+ continue: !def.abort,
1030
1054
  });
1031
1055
  }
1032
1056
  };
@@ -1289,8 +1313,8 @@
1289
1313
 
1290
1314
  const version = {
1291
1315
  major: 4,
1292
- minor: 2,
1293
- patch: 1,
1316
+ minor: 3,
1317
+ patch: 6,
1294
1318
  };
1295
1319
 
1296
1320
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -1400,7 +1424,8 @@
1400
1424
  return runChecks(result, checks, ctx);
1401
1425
  };
1402
1426
  }
1403
- inst["~standard"] = {
1427
+ // Lazy initialize ~standard to avoid creating objects for every schema
1428
+ defineLazy(inst, "~standard", () => ({
1404
1429
  validate: (value) => {
1405
1430
  try {
1406
1431
  const r = safeParse$1(inst, value);
@@ -1412,7 +1437,7 @@
1412
1437
  },
1413
1438
  vendor: "zod",
1414
1439
  version: 1,
1415
- };
1440
+ }));
1416
1441
  });
1417
1442
  const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1418
1443
  $ZodType.init(inst, def);
@@ -1865,8 +1890,12 @@
1865
1890
  return payload; //handleArrayResultsAsync(parseResults, final);
1866
1891
  };
1867
1892
  });
1868
- function handlePropertyResult(result, final, key, input) {
1893
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
1869
1894
  if (result.issues.length) {
1895
+ // For optional-out schemas, ignore errors on absent keys
1896
+ if (isOptionalOut && !(key in input)) {
1897
+ return;
1898
+ }
1870
1899
  final.issues.push(...prefixIssues(key, result.issues));
1871
1900
  }
1872
1901
  if (result.value === undefined) {
@@ -1900,6 +1929,7 @@
1900
1929
  const keySet = def.keySet;
1901
1930
  const _catchall = def.catchall._zod;
1902
1931
  const t = _catchall.def.type;
1932
+ const isOptionalOut = _catchall.optout === "optional";
1903
1933
  for (const key in input) {
1904
1934
  if (keySet.has(key))
1905
1935
  continue;
@@ -1909,10 +1939,10 @@
1909
1939
  }
1910
1940
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1911
1941
  if (r instanceof Promise) {
1912
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
1942
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1913
1943
  }
1914
1944
  else {
1915
- handlePropertyResult(r, payload, key, input);
1945
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1916
1946
  }
1917
1947
  }
1918
1948
  if (unrecognized.length) {
@@ -1980,12 +2010,13 @@
1980
2010
  const shape = value.shape;
1981
2011
  for (const key of value.keys) {
1982
2012
  const el = shape[key];
2013
+ const isOptionalOut = el._zod.optout === "optional";
1983
2014
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1984
2015
  if (r instanceof Promise) {
1985
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
2016
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1986
2017
  }
1987
2018
  else {
1988
- handlePropertyResult(r, payload, key, input);
2019
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1989
2020
  }
1990
2021
  }
1991
2022
  if (!catchall) {
@@ -2017,8 +2048,33 @@
2017
2048
  for (const key of normalized.keys) {
2018
2049
  const id = ids[key];
2019
2050
  const k = esc(key);
2051
+ const schema = shape[key];
2052
+ const isOptionalOut = schema?._zod?.optout === "optional";
2020
2053
  doc.write(`const ${id} = ${parseStr(key)};`);
2021
- doc.write(`
2054
+ if (isOptionalOut) {
2055
+ // For optional-out schemas, ignore errors on absent keys
2056
+ doc.write(`
2057
+ if (${id}.issues.length) {
2058
+ if (${k} in input) {
2059
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2060
+ ...iss,
2061
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2062
+ })));
2063
+ }
2064
+ }
2065
+
2066
+ if (${id}.value === undefined) {
2067
+ if (${k} in input) {
2068
+ newResult[${k}] = undefined;
2069
+ }
2070
+ } else {
2071
+ newResult[${k}] = ${id}.value;
2072
+ }
2073
+
2074
+ `);
2075
+ }
2076
+ else {
2077
+ doc.write(`
2022
2078
  if (${id}.issues.length) {
2023
2079
  payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2024
2080
  ...iss,
@@ -2026,7 +2082,6 @@
2026
2082
  })));
2027
2083
  }
2028
2084
 
2029
-
2030
2085
  if (${id}.value === undefined) {
2031
2086
  if (${k} in input) {
2032
2087
  newResult[${k}] = undefined;
@@ -2036,6 +2091,7 @@
2036
2091
  }
2037
2092
 
2038
2093
  `);
2094
+ }
2039
2095
  }
2040
2096
  doc.write(`payload.value = newResult;`);
2041
2097
  doc.write(`return payload;`);
@@ -2271,11 +2327,38 @@
2271
2327
  return { valid: false, mergeErrorPath: [] };
2272
2328
  }
2273
2329
  function handleIntersectionResults(result, left, right) {
2274
- if (left.issues.length) {
2275
- result.issues.push(...left.issues);
2330
+ // Track which side(s) report each key as unrecognized
2331
+ const unrecKeys = new Map();
2332
+ let unrecIssue;
2333
+ for (const iss of left.issues) {
2334
+ if (iss.code === "unrecognized_keys") {
2335
+ unrecIssue ?? (unrecIssue = iss);
2336
+ for (const k of iss.keys) {
2337
+ if (!unrecKeys.has(k))
2338
+ unrecKeys.set(k, {});
2339
+ unrecKeys.get(k).l = true;
2340
+ }
2341
+ }
2342
+ else {
2343
+ result.issues.push(iss);
2344
+ }
2345
+ }
2346
+ for (const iss of right.issues) {
2347
+ if (iss.code === "unrecognized_keys") {
2348
+ for (const k of iss.keys) {
2349
+ if (!unrecKeys.has(k))
2350
+ unrecKeys.set(k, {});
2351
+ unrecKeys.get(k).r = true;
2352
+ }
2353
+ }
2354
+ else {
2355
+ result.issues.push(iss);
2356
+ }
2276
2357
  }
2277
- if (right.issues.length) {
2278
- result.issues.push(...right.issues);
2358
+ // Report only keys unrecognized by BOTH sides
2359
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2360
+ if (bothKeys.length && unrecIssue) {
2361
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
2279
2362
  }
2280
2363
  if (aborted(result))
2281
2364
  return result;
@@ -2345,10 +2428,22 @@
2345
2428
  for (const key of Reflect.ownKeys(input)) {
2346
2429
  if (key === "__proto__")
2347
2430
  continue;
2348
- const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2431
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2349
2432
  if (keyResult instanceof Promise) {
2350
2433
  throw new Error("Async schemas not supported in object keys currently");
2351
2434
  }
2435
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
2436
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
2437
+ const checkNumericKey = typeof key === "string" && number$1.test(key) && keyResult.issues.length;
2438
+ if (checkNumericKey) {
2439
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
2440
+ if (retryResult instanceof Promise) {
2441
+ throw new Error("Async schemas not supported in object keys currently");
2442
+ }
2443
+ if (retryResult.issues.length === 0) {
2444
+ keyResult = retryResult;
2445
+ }
2446
+ }
2352
2447
  if (keyResult.issues.length) {
2353
2448
  if (def.mode === "loose") {
2354
2449
  // Pass through unchanged
@@ -2488,6 +2583,17 @@
2488
2583
  return def.innerType._zod.run(payload, ctx);
2489
2584
  };
2490
2585
  });
2586
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
2587
+ // Call parent init - inherits optin/optout = "optional"
2588
+ $ZodOptional.init(inst, def);
2589
+ // Override values/pattern to NOT add undefined
2590
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2591
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2592
+ // Override parse to just delegate (no undefined handling)
2593
+ inst._zod.parse = (payload, ctx) => {
2594
+ return def.innerType._zod.run(payload, ctx);
2595
+ };
2596
+ });
2491
2597
  const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
2492
2598
  $ZodType.init(inst, def);
2493
2599
  defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
@@ -2710,9 +2816,6 @@
2710
2816
  const meta = _meta[0];
2711
2817
  this._map.set(schema, meta);
2712
2818
  if (meta && typeof meta === "object" && "id" in meta) {
2713
- if (this._idmap.has(meta.id)) {
2714
- throw new Error(`ID ${meta.id} already exists in the registry`);
2715
- }
2716
2819
  this._idmap.set(meta.id, schema);
2717
2820
  }
2718
2821
  return this;
@@ -2753,12 +2856,14 @@
2753
2856
  (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2754
2857
  const globalRegistry = globalThis.__zod_globalRegistry;
2755
2858
 
2859
+ // @__NO_SIDE_EFFECTS__
2756
2860
  function _string(Class, params) {
2757
2861
  return new Class({
2758
2862
  type: "string",
2759
2863
  ...normalizeParams(params),
2760
2864
  });
2761
2865
  }
2866
+ // @__NO_SIDE_EFFECTS__
2762
2867
  function _email(Class, params) {
2763
2868
  return new Class({
2764
2869
  type: "string",
@@ -2768,6 +2873,7 @@
2768
2873
  ...normalizeParams(params),
2769
2874
  });
2770
2875
  }
2876
+ // @__NO_SIDE_EFFECTS__
2771
2877
  function _guid(Class, params) {
2772
2878
  return new Class({
2773
2879
  type: "string",
@@ -2777,6 +2883,7 @@
2777
2883
  ...normalizeParams(params),
2778
2884
  });
2779
2885
  }
2886
+ // @__NO_SIDE_EFFECTS__
2780
2887
  function _uuid(Class, params) {
2781
2888
  return new Class({
2782
2889
  type: "string",
@@ -2786,6 +2893,7 @@
2786
2893
  ...normalizeParams(params),
2787
2894
  });
2788
2895
  }
2896
+ // @__NO_SIDE_EFFECTS__
2789
2897
  function _uuidv4(Class, params) {
2790
2898
  return new Class({
2791
2899
  type: "string",
@@ -2796,6 +2904,7 @@
2796
2904
  ...normalizeParams(params),
2797
2905
  });
2798
2906
  }
2907
+ // @__NO_SIDE_EFFECTS__
2799
2908
  function _uuidv6(Class, params) {
2800
2909
  return new Class({
2801
2910
  type: "string",
@@ -2806,6 +2915,7 @@
2806
2915
  ...normalizeParams(params),
2807
2916
  });
2808
2917
  }
2918
+ // @__NO_SIDE_EFFECTS__
2809
2919
  function _uuidv7(Class, params) {
2810
2920
  return new Class({
2811
2921
  type: "string",
@@ -2816,6 +2926,7 @@
2816
2926
  ...normalizeParams(params),
2817
2927
  });
2818
2928
  }
2929
+ // @__NO_SIDE_EFFECTS__
2819
2930
  function _url(Class, params) {
2820
2931
  return new Class({
2821
2932
  type: "string",
@@ -2825,6 +2936,7 @@
2825
2936
  ...normalizeParams(params),
2826
2937
  });
2827
2938
  }
2939
+ // @__NO_SIDE_EFFECTS__
2828
2940
  function _emoji(Class, params) {
2829
2941
  return new Class({
2830
2942
  type: "string",
@@ -2834,6 +2946,7 @@
2834
2946
  ...normalizeParams(params),
2835
2947
  });
2836
2948
  }
2949
+ // @__NO_SIDE_EFFECTS__
2837
2950
  function _nanoid(Class, params) {
2838
2951
  return new Class({
2839
2952
  type: "string",
@@ -2843,6 +2956,7 @@
2843
2956
  ...normalizeParams(params),
2844
2957
  });
2845
2958
  }
2959
+ // @__NO_SIDE_EFFECTS__
2846
2960
  function _cuid(Class, params) {
2847
2961
  return new Class({
2848
2962
  type: "string",
@@ -2852,6 +2966,7 @@
2852
2966
  ...normalizeParams(params),
2853
2967
  });
2854
2968
  }
2969
+ // @__NO_SIDE_EFFECTS__
2855
2970
  function _cuid2(Class, params) {
2856
2971
  return new Class({
2857
2972
  type: "string",
@@ -2861,6 +2976,7 @@
2861
2976
  ...normalizeParams(params),
2862
2977
  });
2863
2978
  }
2979
+ // @__NO_SIDE_EFFECTS__
2864
2980
  function _ulid(Class, params) {
2865
2981
  return new Class({
2866
2982
  type: "string",
@@ -2870,6 +2986,7 @@
2870
2986
  ...normalizeParams(params),
2871
2987
  });
2872
2988
  }
2989
+ // @__NO_SIDE_EFFECTS__
2873
2990
  function _xid(Class, params) {
2874
2991
  return new Class({
2875
2992
  type: "string",
@@ -2879,6 +2996,7 @@
2879
2996
  ...normalizeParams(params),
2880
2997
  });
2881
2998
  }
2999
+ // @__NO_SIDE_EFFECTS__
2882
3000
  function _ksuid(Class, params) {
2883
3001
  return new Class({
2884
3002
  type: "string",
@@ -2888,6 +3006,7 @@
2888
3006
  ...normalizeParams(params),
2889
3007
  });
2890
3008
  }
3009
+ // @__NO_SIDE_EFFECTS__
2891
3010
  function _ipv4(Class, params) {
2892
3011
  return new Class({
2893
3012
  type: "string",
@@ -2897,6 +3016,7 @@
2897
3016
  ...normalizeParams(params),
2898
3017
  });
2899
3018
  }
3019
+ // @__NO_SIDE_EFFECTS__
2900
3020
  function _ipv6(Class, params) {
2901
3021
  return new Class({
2902
3022
  type: "string",
@@ -2906,6 +3026,7 @@
2906
3026
  ...normalizeParams(params),
2907
3027
  });
2908
3028
  }
3029
+ // @__NO_SIDE_EFFECTS__
2909
3030
  function _cidrv4(Class, params) {
2910
3031
  return new Class({
2911
3032
  type: "string",
@@ -2915,6 +3036,7 @@
2915
3036
  ...normalizeParams(params),
2916
3037
  });
2917
3038
  }
3039
+ // @__NO_SIDE_EFFECTS__
2918
3040
  function _cidrv6(Class, params) {
2919
3041
  return new Class({
2920
3042
  type: "string",
@@ -2924,6 +3046,7 @@
2924
3046
  ...normalizeParams(params),
2925
3047
  });
2926
3048
  }
3049
+ // @__NO_SIDE_EFFECTS__
2927
3050
  function _base64(Class, params) {
2928
3051
  return new Class({
2929
3052
  type: "string",
@@ -2933,6 +3056,7 @@
2933
3056
  ...normalizeParams(params),
2934
3057
  });
2935
3058
  }
3059
+ // @__NO_SIDE_EFFECTS__
2936
3060
  function _base64url(Class, params) {
2937
3061
  return new Class({
2938
3062
  type: "string",
@@ -2942,6 +3066,7 @@
2942
3066
  ...normalizeParams(params),
2943
3067
  });
2944
3068
  }
3069
+ // @__NO_SIDE_EFFECTS__
2945
3070
  function _e164(Class, params) {
2946
3071
  return new Class({
2947
3072
  type: "string",
@@ -2951,6 +3076,7 @@
2951
3076
  ...normalizeParams(params),
2952
3077
  });
2953
3078
  }
3079
+ // @__NO_SIDE_EFFECTS__
2954
3080
  function _jwt(Class, params) {
2955
3081
  return new Class({
2956
3082
  type: "string",
@@ -2960,6 +3086,7 @@
2960
3086
  ...normalizeParams(params),
2961
3087
  });
2962
3088
  }
3089
+ // @__NO_SIDE_EFFECTS__
2963
3090
  function _isoDateTime(Class, params) {
2964
3091
  return new Class({
2965
3092
  type: "string",
@@ -2971,6 +3098,7 @@
2971
3098
  ...normalizeParams(params),
2972
3099
  });
2973
3100
  }
3101
+ // @__NO_SIDE_EFFECTS__
2974
3102
  function _isoDate(Class, params) {
2975
3103
  return new Class({
2976
3104
  type: "string",
@@ -2979,6 +3107,7 @@
2979
3107
  ...normalizeParams(params),
2980
3108
  });
2981
3109
  }
3110
+ // @__NO_SIDE_EFFECTS__
2982
3111
  function _isoTime(Class, params) {
2983
3112
  return new Class({
2984
3113
  type: "string",
@@ -2988,6 +3117,7 @@
2988
3117
  ...normalizeParams(params),
2989
3118
  });
2990
3119
  }
3120
+ // @__NO_SIDE_EFFECTS__
2991
3121
  function _isoDuration(Class, params) {
2992
3122
  return new Class({
2993
3123
  type: "string",
@@ -2996,6 +3126,7 @@
2996
3126
  ...normalizeParams(params),
2997
3127
  });
2998
3128
  }
3129
+ // @__NO_SIDE_EFFECTS__
2999
3130
  function _number(Class, params) {
3000
3131
  return new Class({
3001
3132
  type: "number",
@@ -3003,6 +3134,7 @@
3003
3134
  ...normalizeParams(params),
3004
3135
  });
3005
3136
  }
3137
+ // @__NO_SIDE_EFFECTS__
3006
3138
  function _int(Class, params) {
3007
3139
  return new Class({
3008
3140
  type: "number",
@@ -3012,34 +3144,40 @@
3012
3144
  ...normalizeParams(params),
3013
3145
  });
3014
3146
  }
3147
+ // @__NO_SIDE_EFFECTS__
3015
3148
  function _boolean(Class, params) {
3016
3149
  return new Class({
3017
3150
  type: "boolean",
3018
3151
  ...normalizeParams(params),
3019
3152
  });
3020
3153
  }
3154
+ // @__NO_SIDE_EFFECTS__
3021
3155
  function _any(Class) {
3022
3156
  return new Class({
3023
3157
  type: "any",
3024
3158
  });
3025
3159
  }
3160
+ // @__NO_SIDE_EFFECTS__
3026
3161
  function _unknown(Class) {
3027
3162
  return new Class({
3028
3163
  type: "unknown",
3029
3164
  });
3030
3165
  }
3166
+ // @__NO_SIDE_EFFECTS__
3031
3167
  function _never(Class, params) {
3032
3168
  return new Class({
3033
3169
  type: "never",
3034
3170
  ...normalizeParams(params),
3035
3171
  });
3036
3172
  }
3173
+ // @__NO_SIDE_EFFECTS__
3037
3174
  function _date(Class, params) {
3038
3175
  return new Class({
3039
3176
  type: "date",
3040
3177
  ...normalizeParams(params),
3041
3178
  });
3042
3179
  }
3180
+ // @__NO_SIDE_EFFECTS__
3043
3181
  function _lt(value, params) {
3044
3182
  return new $ZodCheckLessThan({
3045
3183
  check: "less_than",
@@ -3048,6 +3186,7 @@
3048
3186
  inclusive: false,
3049
3187
  });
3050
3188
  }
3189
+ // @__NO_SIDE_EFFECTS__
3051
3190
  function _lte(value, params) {
3052
3191
  return new $ZodCheckLessThan({
3053
3192
  check: "less_than",
@@ -3056,6 +3195,7 @@
3056
3195
  inclusive: true,
3057
3196
  });
3058
3197
  }
3198
+ // @__NO_SIDE_EFFECTS__
3059
3199
  function _gt(value, params) {
3060
3200
  return new $ZodCheckGreaterThan({
3061
3201
  check: "greater_than",
@@ -3064,6 +3204,7 @@
3064
3204
  inclusive: false,
3065
3205
  });
3066
3206
  }
3207
+ // @__NO_SIDE_EFFECTS__
3067
3208
  function _gte(value, params) {
3068
3209
  return new $ZodCheckGreaterThan({
3069
3210
  check: "greater_than",
@@ -3072,6 +3213,7 @@
3072
3213
  inclusive: true,
3073
3214
  });
3074
3215
  }
3216
+ // @__NO_SIDE_EFFECTS__
3075
3217
  function _multipleOf(value, params) {
3076
3218
  return new $ZodCheckMultipleOf({
3077
3219
  check: "multiple_of",
@@ -3079,6 +3221,7 @@
3079
3221
  value,
3080
3222
  });
3081
3223
  }
3224
+ // @__NO_SIDE_EFFECTS__
3082
3225
  function _maxLength(maximum, params) {
3083
3226
  const ch = new $ZodCheckMaxLength({
3084
3227
  check: "max_length",
@@ -3087,6 +3230,7 @@
3087
3230
  });
3088
3231
  return ch;
3089
3232
  }
3233
+ // @__NO_SIDE_EFFECTS__
3090
3234
  function _minLength(minimum, params) {
3091
3235
  return new $ZodCheckMinLength({
3092
3236
  check: "min_length",
@@ -3094,6 +3238,7 @@
3094
3238
  minimum,
3095
3239
  });
3096
3240
  }
3241
+ // @__NO_SIDE_EFFECTS__
3097
3242
  function _length(length, params) {
3098
3243
  return new $ZodCheckLengthEquals({
3099
3244
  check: "length_equals",
@@ -3101,6 +3246,7 @@
3101
3246
  length,
3102
3247
  });
3103
3248
  }
3249
+ // @__NO_SIDE_EFFECTS__
3104
3250
  function _regex(pattern, params) {
3105
3251
  return new $ZodCheckRegex({
3106
3252
  check: "string_format",
@@ -3109,6 +3255,7 @@
3109
3255
  pattern,
3110
3256
  });
3111
3257
  }
3258
+ // @__NO_SIDE_EFFECTS__
3112
3259
  function _lowercase(params) {
3113
3260
  return new $ZodCheckLowerCase({
3114
3261
  check: "string_format",
@@ -3116,6 +3263,7 @@
3116
3263
  ...normalizeParams(params),
3117
3264
  });
3118
3265
  }
3266
+ // @__NO_SIDE_EFFECTS__
3119
3267
  function _uppercase(params) {
3120
3268
  return new $ZodCheckUpperCase({
3121
3269
  check: "string_format",
@@ -3123,6 +3271,7 @@
3123
3271
  ...normalizeParams(params),
3124
3272
  });
3125
3273
  }
3274
+ // @__NO_SIDE_EFFECTS__
3126
3275
  function _includes(includes, params) {
3127
3276
  return new $ZodCheckIncludes({
3128
3277
  check: "string_format",
@@ -3131,6 +3280,7 @@
3131
3280
  includes,
3132
3281
  });
3133
3282
  }
3283
+ // @__NO_SIDE_EFFECTS__
3134
3284
  function _startsWith(prefix, params) {
3135
3285
  return new $ZodCheckStartsWith({
3136
3286
  check: "string_format",
@@ -3139,6 +3289,7 @@
3139
3289
  prefix,
3140
3290
  });
3141
3291
  }
3292
+ // @__NO_SIDE_EFFECTS__
3142
3293
  function _endsWith(suffix, params) {
3143
3294
  return new $ZodCheckEndsWith({
3144
3295
  check: "string_format",
@@ -3147,6 +3298,7 @@
3147
3298
  suffix,
3148
3299
  });
3149
3300
  }
3301
+ // @__NO_SIDE_EFFECTS__
3150
3302
  function _overwrite(tx) {
3151
3303
  return new $ZodCheckOverwrite({
3152
3304
  check: "overwrite",
@@ -3154,25 +3306,31 @@
3154
3306
  });
3155
3307
  }
3156
3308
  // normalize
3309
+ // @__NO_SIDE_EFFECTS__
3157
3310
  function _normalize(form) {
3158
3311
  return _overwrite((input) => input.normalize(form));
3159
3312
  }
3160
3313
  // trim
3314
+ // @__NO_SIDE_EFFECTS__
3161
3315
  function _trim() {
3162
3316
  return _overwrite((input) => input.trim());
3163
3317
  }
3164
3318
  // toLowerCase
3319
+ // @__NO_SIDE_EFFECTS__
3165
3320
  function _toLowerCase() {
3166
3321
  return _overwrite((input) => input.toLowerCase());
3167
3322
  }
3168
3323
  // toUpperCase
3324
+ // @__NO_SIDE_EFFECTS__
3169
3325
  function _toUpperCase() {
3170
3326
  return _overwrite((input) => input.toUpperCase());
3171
3327
  }
3172
3328
  // slugify
3329
+ // @__NO_SIDE_EFFECTS__
3173
3330
  function _slugify() {
3174
3331
  return _overwrite((input) => slugify(input));
3175
3332
  }
3333
+ // @__NO_SIDE_EFFECTS__
3176
3334
  function _array(Class, element, params) {
3177
3335
  return new Class({
3178
3336
  type: "array",
@@ -3184,6 +3342,7 @@
3184
3342
  });
3185
3343
  }
3186
3344
  // same as _custom but defaults to abort:false
3345
+ // @__NO_SIDE_EFFECTS__
3187
3346
  function _refine(Class, fn, _params) {
3188
3347
  const schema = new Class({
3189
3348
  type: "custom",
@@ -3193,6 +3352,7 @@
3193
3352
  });
3194
3353
  return schema;
3195
3354
  }
3355
+ // @__NO_SIDE_EFFECTS__
3196
3356
  function _superRefine(fn) {
3197
3357
  const ch = _check((payload) => {
3198
3358
  payload.addIssue = (issue$1) => {
@@ -3215,6 +3375,7 @@
3215
3375
  });
3216
3376
  return ch;
3217
3377
  }
3378
+ // @__NO_SIDE_EFFECTS__
3218
3379
  function _check(fn, params) {
3219
3380
  const ch = new $ZodCheck({
3220
3381
  check: "custom",
@@ -3281,14 +3442,7 @@
3281
3442
  schemaPath: [..._params.schemaPath, schema],
3282
3443
  path: _params.path,
3283
3444
  };
3284
- const parent = schema._zod.parent;
3285
- if (parent) {
3286
- // schema was cloned from another schema
3287
- result.ref = parent;
3288
- process$1(parent, ctx, params);
3289
- ctx.seen.get(parent).isParent = true;
3290
- }
3291
- else if (schema._zod.processJSONSchema) {
3445
+ if (schema._zod.processJSONSchema) {
3292
3446
  schema._zod.processJSONSchema(ctx, result.schema, params);
3293
3447
  }
3294
3448
  else {
@@ -3299,6 +3453,14 @@
3299
3453
  }
3300
3454
  processor(schema, ctx, _json, params);
3301
3455
  }
3456
+ const parent = schema._zod.parent;
3457
+ if (parent) {
3458
+ // Also set ref if processor didn't (for inheritance)
3459
+ if (!result.ref)
3460
+ result.ref = parent;
3461
+ process$1(parent, ctx, params);
3462
+ ctx.seen.get(parent).isParent = true;
3463
+ }
3302
3464
  }
3303
3465
  // metadata
3304
3466
  const meta = ctx.metadataRegistry.get(schema);
@@ -3324,6 +3486,18 @@
3324
3486
  const root = ctx.seen.get(schema);
3325
3487
  if (!root)
3326
3488
  throw new Error("Unprocessed schema. This is a bug in Zod.");
3489
+ // Track ids to detect duplicates across different schemas
3490
+ const idToSchema = new Map();
3491
+ for (const entry of ctx.seen.entries()) {
3492
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3493
+ if (id) {
3494
+ const existing = idToSchema.get(id);
3495
+ if (existing && existing !== entry[0]) {
3496
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
3497
+ }
3498
+ idToSchema.set(id, entry[0]);
3499
+ }
3500
+ }
3327
3501
  // returns a ref to the schema
3328
3502
  // defId will be empty if the ref points to an external schema (or #)
3329
3503
  const makeURI = (entry) => {
@@ -3425,43 +3599,84 @@
3425
3599
  }
3426
3600
  }
3427
3601
  function finalize(ctx, schema) {
3428
- //
3429
- // iterate over seen map;
3430
3602
  const root = ctx.seen.get(schema);
3431
3603
  if (!root)
3432
3604
  throw new Error("Unprocessed schema. This is a bug in Zod.");
3433
- // flatten _refs
3605
+ // flatten refs - inherit properties from parent schemas
3434
3606
  const flattenRef = (zodSchema) => {
3435
3607
  const seen = ctx.seen.get(zodSchema);
3608
+ // already processed
3609
+ if (seen.ref === null)
3610
+ return;
3436
3611
  const schema = seen.def ?? seen.schema;
3437
3612
  const _cached = { ...schema };
3438
- // already seen
3439
- if (seen.ref === null) {
3440
- return;
3441
- }
3442
- // flatten ref if defined
3443
3613
  const ref = seen.ref;
3444
- seen.ref = null; // prevent recursion
3614
+ seen.ref = null; // prevent infinite recursion
3445
3615
  if (ref) {
3446
3616
  flattenRef(ref);
3617
+ const refSeen = ctx.seen.get(ref);
3618
+ const refSchema = refSeen.schema;
3447
3619
  // merge referenced schema into current
3448
- const refSchema = ctx.seen.get(ref).schema;
3449
3620
  if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
3621
+ // older drafts can't combine $ref with other properties
3450
3622
  schema.allOf = schema.allOf ?? [];
3451
3623
  schema.allOf.push(refSchema);
3452
3624
  }
3453
3625
  else {
3454
3626
  Object.assign(schema, refSchema);
3455
- Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
3627
+ }
3628
+ // restore child's own properties (child wins)
3629
+ Object.assign(schema, _cached);
3630
+ const isParentRef = zodSchema._zod.parent === ref;
3631
+ // For parent chain, child is a refinement - remove parent-only properties
3632
+ if (isParentRef) {
3633
+ for (const key in schema) {
3634
+ if (key === "$ref" || key === "allOf")
3635
+ continue;
3636
+ if (!(key in _cached)) {
3637
+ delete schema[key];
3638
+ }
3639
+ }
3640
+ }
3641
+ // When ref was extracted to $defs, remove properties that match the definition
3642
+ if (refSchema.$ref && refSeen.def) {
3643
+ for (const key in schema) {
3644
+ if (key === "$ref" || key === "allOf")
3645
+ continue;
3646
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) {
3647
+ delete schema[key];
3648
+ }
3649
+ }
3650
+ }
3651
+ }
3652
+ // If parent was extracted (has $ref), propagate $ref to this schema
3653
+ // This handles cases like: readonly().meta({id}).describe()
3654
+ // where processor sets ref to innerType but parent should be referenced
3655
+ const parent = zodSchema._zod.parent;
3656
+ if (parent && parent !== ref) {
3657
+ // Ensure parent is processed first so its def has inherited properties
3658
+ flattenRef(parent);
3659
+ const parentSeen = ctx.seen.get(parent);
3660
+ if (parentSeen?.schema.$ref) {
3661
+ schema.$ref = parentSeen.schema.$ref;
3662
+ // De-duplicate with parent's definition
3663
+ if (parentSeen.def) {
3664
+ for (const key in schema) {
3665
+ if (key === "$ref" || key === "allOf")
3666
+ continue;
3667
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) {
3668
+ delete schema[key];
3669
+ }
3670
+ }
3671
+ }
3456
3672
  }
3457
3673
  }
3458
3674
  // execute overrides
3459
- if (!seen.isParent)
3460
- ctx.override({
3461
- zodSchema: zodSchema,
3462
- jsonSchema: schema,
3463
- path: seen.path ?? [],
3464
- });
3675
+ ctx.override({
3676
+ zodSchema: zodSchema,
3677
+ jsonSchema: schema,
3678
+ path: seen.path ?? [],
3679
+ });
3465
3680
  };
3466
3681
  for (const entry of [...ctx.seen.entries()].reverse()) {
3467
3682
  flattenRef(entry[0]);
@@ -3514,8 +3729,8 @@
3514
3729
  value: {
3515
3730
  ...schema["~standard"],
3516
3731
  jsonSchema: {
3517
- input: createStandardJSONSchemaMethod(schema, "input"),
3518
- output: createStandardJSONSchemaMethod(schema, "output"),
3732
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
3733
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors),
3519
3734
  },
3520
3735
  },
3521
3736
  enumerable: false,
@@ -3594,9 +3809,9 @@
3594
3809
  extractDefs(ctx, schema);
3595
3810
  return finalize(ctx, schema);
3596
3811
  };
3597
- const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3812
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3598
3813
  const { libraryOptions, target } = params ?? {};
3599
- const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
3814
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors });
3600
3815
  process$1(schema, ctx);
3601
3816
  extractDefs(ctx, schema);
3602
3817
  return finalize(ctx, schema);
@@ -3624,6 +3839,11 @@
3624
3839
  json.format = formatMap[format] ?? format;
3625
3840
  if (json.format === "")
3626
3841
  delete json.format; // empty format is not valid
3842
+ // JSON Schema format: "time" requires a full time with offset or Z
3843
+ // z.iso.time() does not include timezone information, so format: "time" should never be used
3844
+ if (format === "time") {
3845
+ delete json.format;
3846
+ }
3627
3847
  }
3628
3848
  if (contentEncoding)
3629
3849
  json.contentEncoding = contentEncoding;
@@ -3862,16 +4082,44 @@
3862
4082
  const json = _json;
3863
4083
  const def = schema._zod.def;
3864
4084
  json.type = "object";
3865
- if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
3866
- json.propertyNames = process$1(def.keyType, ctx, {
4085
+ // For looseRecord with regex patterns, use patternProperties
4086
+ // This correctly represents "only validate keys matching the pattern" semantics
4087
+ // and composes well with allOf (intersections)
4088
+ const keyType = def.keyType;
4089
+ const keyBag = keyType._zod.bag;
4090
+ const patterns = keyBag?.patterns;
4091
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
4092
+ // Use patternProperties for looseRecord with regex patterns
4093
+ const valueSchema = process$1(def.valueType, ctx, {
3867
4094
  ...params,
3868
- path: [...params.path, "propertyNames"],
4095
+ path: [...params.path, "patternProperties", "*"],
3869
4096
  });
4097
+ json.patternProperties = {};
4098
+ for (const pattern of patterns) {
4099
+ json.patternProperties[pattern.source] = valueSchema;
4100
+ }
4101
+ }
4102
+ else {
4103
+ // Default behavior: use propertyNames + additionalProperties
4104
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
4105
+ json.propertyNames = process$1(def.keyType, ctx, {
4106
+ ...params,
4107
+ path: [...params.path, "propertyNames"],
4108
+ });
4109
+ }
4110
+ json.additionalProperties = process$1(def.valueType, ctx, {
4111
+ ...params,
4112
+ path: [...params.path, "additionalProperties"],
4113
+ });
4114
+ }
4115
+ // Add required for keys with discrete values (enum, literal, etc.)
4116
+ const keyValues = keyType._zod.values;
4117
+ if (keyValues) {
4118
+ const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
4119
+ if (validKeyValues.length > 0) {
4120
+ json.required = validKeyValues;
4121
+ }
3870
4122
  }
3871
- json.additionalProperties = process$1(def.valueType, ctx, {
3872
- ...params,
3873
- path: [...params.path, "additionalProperties"],
3874
- });
3875
4123
  };
3876
4124
  const nullableProcessor = (schema, ctx, json, params) => {
3877
4125
  const def = schema._zod.def;
@@ -4049,8 +4297,11 @@
4049
4297
  ...(def.checks ?? []),
4050
4298
  ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
4051
4299
  ],
4052
- }));
4300
+ }), {
4301
+ parent: true,
4302
+ });
4053
4303
  };
4304
+ inst.with = inst.check;
4054
4305
  inst.clone = (def, params) => clone(inst, def, params);
4055
4306
  inst.brand = () => inst;
4056
4307
  inst.register = ((reg, meta) => {
@@ -4078,6 +4329,7 @@
4078
4329
  inst.overwrite = (fn) => inst.check(_overwrite(fn));
4079
4330
  // wrappers
4080
4331
  inst.optional = () => optional(inst);
4332
+ inst.exactOptional = () => exactOptional(inst);
4081
4333
  inst.nullable = () => nullable(inst);
4082
4334
  inst.nullish = () => optional(nullable(inst));
4083
4335
  inst.nonoptional = (params) => nonoptional(inst, params);
@@ -4114,6 +4366,7 @@
4114
4366
  // helpers
4115
4367
  inst.isOptional = () => inst.safeParse(undefined).success;
4116
4368
  inst.isNullable = () => inst.safeParse(null).success;
4369
+ inst.apply = (fn) => fn(inst);
4117
4370
  return inst;
4118
4371
  });
4119
4372
  /** @internal */
@@ -4595,6 +4848,18 @@
4595
4848
  innerType: innerType,
4596
4849
  });
4597
4850
  }
4851
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
4852
+ $ZodExactOptional.init(inst, def);
4853
+ ZodType.init(inst, def);
4854
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4855
+ inst.unwrap = () => inst._zod.def.innerType;
4856
+ });
4857
+ function exactOptional(innerType) {
4858
+ return new ZodExactOptional({
4859
+ type: "optional",
4860
+ innerType: innerType,
4861
+ });
4862
+ }
4598
4863
  const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4599
4864
  $ZodNullable.init(inst, def);
4600
4865
  ZodType.init(inst, def);