@kevisual/router 0.0.52 → 0.0.54

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.
@@ -1,5 +1,3 @@
1
- import url from 'node:url';
2
-
3
1
  const urlAlphabet =
4
2
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
5
3
 
@@ -147,6 +145,13 @@ const listenProcess = async ({ app, emitter, params, timeout = 10 * 60 * 60 * 10
147
145
  };
148
146
 
149
147
  const pickValue = ['path', 'key', 'id', 'description', 'type', 'middleware', 'metadata'];
148
+ /** */
149
+ const createSkill = (skill) => {
150
+ return {
151
+ args: {},
152
+ ...skill
153
+ };
154
+ };
150
155
  class Route {
151
156
  /**
152
157
  * 一级路径
@@ -270,6 +275,7 @@ class Route {
270
275
  }
271
276
  }
272
277
  class QueryRouter {
278
+ appId = '';
273
279
  routes;
274
280
  maxNextRoute = 40;
275
281
  context = {}; // default context for call
@@ -620,6 +626,21 @@ class QueryRouter {
620
626
  hasRoute(path, key = '') {
621
627
  return this.routes.find((r) => r.path === path && r.key === key);
622
628
  }
629
+ findRoute(opts) {
630
+ const { path, key, id } = opts || {};
631
+ return this.routes.find((r) => {
632
+ if (id) {
633
+ return r.id === id;
634
+ }
635
+ if (path) {
636
+ if (key !== undefined) {
637
+ return r.path === path && r.key === key;
638
+ }
639
+ return r.path === path;
640
+ }
641
+ return false;
642
+ });
643
+ }
623
644
  createRouteList(force = false, filter) {
624
645
  const hasListRoute = this.hasRoute('router', 'list');
625
646
  if (!hasListRoute || force) {
@@ -659,6 +680,12 @@ class QueryRouterServer extends QueryRouter {
659
680
  super();
660
681
  this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
661
682
  this.setContext({ needSerialize: false, ...opts?.context });
683
+ if (opts?.appId) {
684
+ this.appId = opts.appId;
685
+ }
686
+ else {
687
+ this.appId = nanoid$1(16);
688
+ }
662
689
  }
663
690
  setHandle(wrapperFn, ctx) {
664
691
  this.handle = this.getHandle(this, wrapperFn, ctx);
@@ -969,6 +996,11 @@ const NUMBER_FORMAT_RANGES = {
969
996
  };
970
997
  function pick(schema, mask) {
971
998
  const currDef = schema._zod.def;
999
+ const checks = currDef.checks;
1000
+ const hasChecks = checks && checks.length > 0;
1001
+ if (hasChecks) {
1002
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
1003
+ }
972
1004
  const def = mergeDefs(schema._zod.def, {
973
1005
  get shape() {
974
1006
  const newShape = {};
@@ -989,6 +1021,11 @@ function pick(schema, mask) {
989
1021
  }
990
1022
  function omit(schema, mask) {
991
1023
  const currDef = schema._zod.def;
1024
+ const checks = currDef.checks;
1025
+ const hasChecks = checks && checks.length > 0;
1026
+ if (hasChecks) {
1027
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
1028
+ }
992
1029
  const def = mergeDefs(schema._zod.def, {
993
1030
  get shape() {
994
1031
  const newShape = { ...schema._zod.def.shape };
@@ -1014,7 +1051,14 @@ function extend(schema, shape) {
1014
1051
  const checks = schema._zod.def.checks;
1015
1052
  const hasChecks = checks && checks.length > 0;
1016
1053
  if (hasChecks) {
1017
- throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
1054
+ // Only throw if new shape overlaps with existing shape
1055
+ // Use getOwnPropertyDescriptor to check key existence without accessing values
1056
+ const existingShape = schema._zod.def.shape;
1057
+ for (const key in shape) {
1058
+ if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
1059
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
1060
+ }
1061
+ }
1018
1062
  }
1019
1063
  const def = mergeDefs(schema._zod.def, {
1020
1064
  get shape() {
@@ -1022,7 +1066,6 @@ function extend(schema, shape) {
1022
1066
  assignProp(this, "shape", _shape); // self-caching
1023
1067
  return _shape;
1024
1068
  },
1025
- checks: [],
1026
1069
  });
1027
1070
  return clone(schema, def);
1028
1071
  }
@@ -1030,15 +1073,13 @@ function safeExtend(schema, shape) {
1030
1073
  if (!isPlainObject(shape)) {
1031
1074
  throw new Error("Invalid input to safeExtend: expected a plain object");
1032
1075
  }
1033
- const def = {
1034
- ...schema._zod.def,
1076
+ const def = mergeDefs(schema._zod.def, {
1035
1077
  get shape() {
1036
1078
  const _shape = { ...schema._zod.def.shape, ...shape };
1037
1079
  assignProp(this, "shape", _shape); // self-caching
1038
1080
  return _shape;
1039
1081
  },
1040
- checks: schema._zod.def.checks,
1041
- };
1082
+ });
1042
1083
  return clone(schema, def);
1043
1084
  }
1044
1085
  function merge(a, b) {
@@ -1056,6 +1097,12 @@ function merge(a, b) {
1056
1097
  return clone(a, def);
1057
1098
  }
1058
1099
  function partial(Class, schema, mask) {
1100
+ const currDef = schema._zod.def;
1101
+ const checks = currDef.checks;
1102
+ const hasChecks = checks && checks.length > 0;
1103
+ if (hasChecks) {
1104
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
1105
+ }
1059
1106
  const def = mergeDefs(schema._zod.def, {
1060
1107
  get shape() {
1061
1108
  const oldShape = schema._zod.def.shape;
@@ -1125,7 +1172,6 @@ function required(Class, schema, mask) {
1125
1172
  assignProp(this, "shape", shape); // self-caching
1126
1173
  return shape;
1127
1174
  },
1128
- checks: [],
1129
1175
  });
1130
1176
  return clone(schema, def);
1131
1177
  }
@@ -1375,7 +1421,8 @@ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?:
1375
1421
  const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
1376
1422
  const base64url = /^[A-Za-z0-9_-]*$/;
1377
1423
  // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
1378
- const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
1424
+ // E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
1425
+ const e164 = /^\+[1-9]\d{6,14}$/;
1379
1426
  // 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])))`;
1380
1427
  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])))`;
1381
1428
  const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
@@ -1410,7 +1457,7 @@ const string$1 = (params) => {
1410
1457
  return new RegExp(`^${regex}$`);
1411
1458
  };
1412
1459
  const integer = /^-?\d+$/;
1413
- const number$1 = /^-?\d+(?:\.\d+)?/;
1460
+ const number$1 = /^-?\d+(?:\.\d+)?$/;
1414
1461
  const boolean$1 = /^(?:true|false)$/i;
1415
1462
  // regex for string with no uppercase letters
1416
1463
  const lowercase = /^[^A-Z]*$/;
@@ -1449,7 +1496,7 @@ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst,
1449
1496
  payload.issues.push({
1450
1497
  origin,
1451
1498
  code: "too_big",
1452
- maximum: def.value,
1499
+ maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
1453
1500
  input: payload.value,
1454
1501
  inclusive: def.inclusive,
1455
1502
  inst,
@@ -1477,7 +1524,7 @@ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan",
1477
1524
  payload.issues.push({
1478
1525
  origin,
1479
1526
  code: "too_small",
1480
- minimum: def.value,
1527
+ minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
1481
1528
  input: payload.value,
1482
1529
  inclusive: def.inclusive,
1483
1530
  inst,
@@ -1565,6 +1612,7 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
1565
1612
  note: "Integers must be within the safe integer range.",
1566
1613
  inst,
1567
1614
  origin,
1615
+ inclusive: true,
1568
1616
  continue: !def.abort,
1569
1617
  });
1570
1618
  }
@@ -1577,6 +1625,7 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
1577
1625
  note: "Integers must be within the safe integer range.",
1578
1626
  inst,
1579
1627
  origin,
1628
+ inclusive: true,
1580
1629
  continue: !def.abort,
1581
1630
  });
1582
1631
  }
@@ -1600,7 +1649,9 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
1600
1649
  input,
1601
1650
  code: "too_big",
1602
1651
  maximum,
1652
+ inclusive: true,
1603
1653
  inst,
1654
+ continue: !def.abort,
1604
1655
  });
1605
1656
  }
1606
1657
  };
@@ -1863,8 +1914,8 @@ class Doc {
1863
1914
 
1864
1915
  const version = {
1865
1916
  major: 4,
1866
- minor: 2,
1867
- patch: 1,
1917
+ minor: 3,
1918
+ patch: 5,
1868
1919
  };
1869
1920
 
1870
1921
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -1974,7 +2025,8 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1974
2025
  return runChecks(result, checks, ctx);
1975
2026
  };
1976
2027
  }
1977
- inst["~standard"] = {
2028
+ // Lazy initialize ~standard to avoid creating objects for every schema
2029
+ defineLazy(inst, "~standard", () => ({
1978
2030
  validate: (value) => {
1979
2031
  try {
1980
2032
  const r = safeParse$1(inst, value);
@@ -1986,7 +2038,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1986
2038
  },
1987
2039
  vendor: "zod",
1988
2040
  version: 1,
1989
- };
2041
+ }));
1990
2042
  });
1991
2043
  const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1992
2044
  $ZodType.init(inst, def);
@@ -2415,8 +2467,12 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
2415
2467
  return payload; //handleArrayResultsAsync(parseResults, final);
2416
2468
  };
2417
2469
  });
2418
- function handlePropertyResult(result, final, key, input) {
2470
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
2419
2471
  if (result.issues.length) {
2472
+ // For optional-out schemas, ignore errors on absent keys
2473
+ if (isOptionalOut && !(key in input)) {
2474
+ return;
2475
+ }
2420
2476
  final.issues.push(...prefixIssues(key, result.issues));
2421
2477
  }
2422
2478
  if (result.value === undefined) {
@@ -2450,6 +2506,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
2450
2506
  const keySet = def.keySet;
2451
2507
  const _catchall = def.catchall._zod;
2452
2508
  const t = _catchall.def.type;
2509
+ const isOptionalOut = _catchall.optout === "optional";
2453
2510
  for (const key in input) {
2454
2511
  if (keySet.has(key))
2455
2512
  continue;
@@ -2459,10 +2516,10 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
2459
2516
  }
2460
2517
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
2461
2518
  if (r instanceof Promise) {
2462
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
2519
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
2463
2520
  }
2464
2521
  else {
2465
- handlePropertyResult(r, payload, key, input);
2522
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
2466
2523
  }
2467
2524
  }
2468
2525
  if (unrecognized.length) {
@@ -2530,12 +2587,13 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
2530
2587
  const shape = value.shape;
2531
2588
  for (const key of value.keys) {
2532
2589
  const el = shape[key];
2590
+ const isOptionalOut = el._zod.optout === "optional";
2533
2591
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
2534
2592
  if (r instanceof Promise) {
2535
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
2593
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
2536
2594
  }
2537
2595
  else {
2538
- handlePropertyResult(r, payload, key, input);
2596
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
2539
2597
  }
2540
2598
  }
2541
2599
  if (!catchall) {
@@ -2567,8 +2625,33 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
2567
2625
  for (const key of normalized.keys) {
2568
2626
  const id = ids[key];
2569
2627
  const k = esc(key);
2628
+ const schema = shape[key];
2629
+ const isOptionalOut = schema?._zod?.optout === "optional";
2570
2630
  doc.write(`const ${id} = ${parseStr(key)};`);
2571
- doc.write(`
2631
+ if (isOptionalOut) {
2632
+ // For optional-out schemas, ignore errors on absent keys
2633
+ doc.write(`
2634
+ if (${id}.issues.length) {
2635
+ if (${k} in input) {
2636
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2637
+ ...iss,
2638
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2639
+ })));
2640
+ }
2641
+ }
2642
+
2643
+ if (${id}.value === undefined) {
2644
+ if (${k} in input) {
2645
+ newResult[${k}] = undefined;
2646
+ }
2647
+ } else {
2648
+ newResult[${k}] = ${id}.value;
2649
+ }
2650
+
2651
+ `);
2652
+ }
2653
+ else {
2654
+ doc.write(`
2572
2655
  if (${id}.issues.length) {
2573
2656
  payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2574
2657
  ...iss,
@@ -2576,7 +2659,6 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
2576
2659
  })));
2577
2660
  }
2578
2661
 
2579
-
2580
2662
  if (${id}.value === undefined) {
2581
2663
  if (${k} in input) {
2582
2664
  newResult[${k}] = undefined;
@@ -2586,6 +2668,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
2586
2668
  }
2587
2669
 
2588
2670
  `);
2671
+ }
2589
2672
  }
2590
2673
  doc.write(`payload.value = newResult;`);
2591
2674
  doc.write(`return payload;`);
@@ -2752,11 +2835,38 @@ function mergeValues(a, b) {
2752
2835
  return { valid: false, mergeErrorPath: [] };
2753
2836
  }
2754
2837
  function handleIntersectionResults(result, left, right) {
2755
- if (left.issues.length) {
2756
- result.issues.push(...left.issues);
2838
+ // Track which side(s) report each key as unrecognized
2839
+ const unrecKeys = new Map();
2840
+ let unrecIssue;
2841
+ for (const iss of left.issues) {
2842
+ if (iss.code === "unrecognized_keys") {
2843
+ unrecIssue ?? (unrecIssue = iss);
2844
+ for (const k of iss.keys) {
2845
+ if (!unrecKeys.has(k))
2846
+ unrecKeys.set(k, {});
2847
+ unrecKeys.get(k).l = true;
2848
+ }
2849
+ }
2850
+ else {
2851
+ result.issues.push(iss);
2852
+ }
2853
+ }
2854
+ for (const iss of right.issues) {
2855
+ if (iss.code === "unrecognized_keys") {
2856
+ for (const k of iss.keys) {
2857
+ if (!unrecKeys.has(k))
2858
+ unrecKeys.set(k, {});
2859
+ unrecKeys.get(k).r = true;
2860
+ }
2861
+ }
2862
+ else {
2863
+ result.issues.push(iss);
2864
+ }
2757
2865
  }
2758
- if (right.issues.length) {
2759
- result.issues.push(...right.issues);
2866
+ // Report only keys unrecognized by BOTH sides
2867
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2868
+ if (bothKeys.length && unrecIssue) {
2869
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
2760
2870
  }
2761
2871
  if (aborted(result))
2762
2872
  return result;
@@ -2841,6 +2951,17 @@ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
2841
2951
  return def.innerType._zod.run(payload, ctx);
2842
2952
  };
2843
2953
  });
2954
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
2955
+ // Call parent init - inherits optin/optout = "optional"
2956
+ $ZodOptional.init(inst, def);
2957
+ // Override values/pattern to NOT add undefined
2958
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2959
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2960
+ // Override parse to just delegate (no undefined handling)
2961
+ inst._zod.parse = (payload, ctx) => {
2962
+ return def.innerType._zod.run(payload, ctx);
2963
+ };
2964
+ });
2844
2965
  const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
2845
2966
  $ZodType.init(inst, def);
2846
2967
  defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
@@ -3063,9 +3184,6 @@ class $ZodRegistry {
3063
3184
  const meta = _meta[0];
3064
3185
  this._map.set(schema, meta);
3065
3186
  if (meta && typeof meta === "object" && "id" in meta) {
3066
- if (this._idmap.has(meta.id)) {
3067
- throw new Error(`ID ${meta.id} already exists in the registry`);
3068
- }
3069
3187
  this._idmap.set(meta.id, schema);
3070
3188
  }
3071
3189
  return this;
@@ -3106,12 +3224,14 @@ function registry() {
3106
3224
  (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
3107
3225
  const globalRegistry = globalThis.__zod_globalRegistry;
3108
3226
 
3227
+ // @__NO_SIDE_EFFECTS__
3109
3228
  function _string(Class, params) {
3110
3229
  return new Class({
3111
3230
  type: "string",
3112
3231
  ...normalizeParams(params),
3113
3232
  });
3114
3233
  }
3234
+ // @__NO_SIDE_EFFECTS__
3115
3235
  function _email(Class, params) {
3116
3236
  return new Class({
3117
3237
  type: "string",
@@ -3121,6 +3241,7 @@ function _email(Class, params) {
3121
3241
  ...normalizeParams(params),
3122
3242
  });
3123
3243
  }
3244
+ // @__NO_SIDE_EFFECTS__
3124
3245
  function _guid(Class, params) {
3125
3246
  return new Class({
3126
3247
  type: "string",
@@ -3130,6 +3251,7 @@ function _guid(Class, params) {
3130
3251
  ...normalizeParams(params),
3131
3252
  });
3132
3253
  }
3254
+ // @__NO_SIDE_EFFECTS__
3133
3255
  function _uuid(Class, params) {
3134
3256
  return new Class({
3135
3257
  type: "string",
@@ -3139,6 +3261,7 @@ function _uuid(Class, params) {
3139
3261
  ...normalizeParams(params),
3140
3262
  });
3141
3263
  }
3264
+ // @__NO_SIDE_EFFECTS__
3142
3265
  function _uuidv4(Class, params) {
3143
3266
  return new Class({
3144
3267
  type: "string",
@@ -3149,6 +3272,7 @@ function _uuidv4(Class, params) {
3149
3272
  ...normalizeParams(params),
3150
3273
  });
3151
3274
  }
3275
+ // @__NO_SIDE_EFFECTS__
3152
3276
  function _uuidv6(Class, params) {
3153
3277
  return new Class({
3154
3278
  type: "string",
@@ -3159,6 +3283,7 @@ function _uuidv6(Class, params) {
3159
3283
  ...normalizeParams(params),
3160
3284
  });
3161
3285
  }
3286
+ // @__NO_SIDE_EFFECTS__
3162
3287
  function _uuidv7(Class, params) {
3163
3288
  return new Class({
3164
3289
  type: "string",
@@ -3169,6 +3294,7 @@ function _uuidv7(Class, params) {
3169
3294
  ...normalizeParams(params),
3170
3295
  });
3171
3296
  }
3297
+ // @__NO_SIDE_EFFECTS__
3172
3298
  function _url(Class, params) {
3173
3299
  return new Class({
3174
3300
  type: "string",
@@ -3178,6 +3304,7 @@ function _url(Class, params) {
3178
3304
  ...normalizeParams(params),
3179
3305
  });
3180
3306
  }
3307
+ // @__NO_SIDE_EFFECTS__
3181
3308
  function _emoji(Class, params) {
3182
3309
  return new Class({
3183
3310
  type: "string",
@@ -3187,6 +3314,7 @@ function _emoji(Class, params) {
3187
3314
  ...normalizeParams(params),
3188
3315
  });
3189
3316
  }
3317
+ // @__NO_SIDE_EFFECTS__
3190
3318
  function _nanoid(Class, params) {
3191
3319
  return new Class({
3192
3320
  type: "string",
@@ -3196,6 +3324,7 @@ function _nanoid(Class, params) {
3196
3324
  ...normalizeParams(params),
3197
3325
  });
3198
3326
  }
3327
+ // @__NO_SIDE_EFFECTS__
3199
3328
  function _cuid(Class, params) {
3200
3329
  return new Class({
3201
3330
  type: "string",
@@ -3205,6 +3334,7 @@ function _cuid(Class, params) {
3205
3334
  ...normalizeParams(params),
3206
3335
  });
3207
3336
  }
3337
+ // @__NO_SIDE_EFFECTS__
3208
3338
  function _cuid2(Class, params) {
3209
3339
  return new Class({
3210
3340
  type: "string",
@@ -3214,6 +3344,7 @@ function _cuid2(Class, params) {
3214
3344
  ...normalizeParams(params),
3215
3345
  });
3216
3346
  }
3347
+ // @__NO_SIDE_EFFECTS__
3217
3348
  function _ulid(Class, params) {
3218
3349
  return new Class({
3219
3350
  type: "string",
@@ -3223,6 +3354,7 @@ function _ulid(Class, params) {
3223
3354
  ...normalizeParams(params),
3224
3355
  });
3225
3356
  }
3357
+ // @__NO_SIDE_EFFECTS__
3226
3358
  function _xid(Class, params) {
3227
3359
  return new Class({
3228
3360
  type: "string",
@@ -3232,6 +3364,7 @@ function _xid(Class, params) {
3232
3364
  ...normalizeParams(params),
3233
3365
  });
3234
3366
  }
3367
+ // @__NO_SIDE_EFFECTS__
3235
3368
  function _ksuid(Class, params) {
3236
3369
  return new Class({
3237
3370
  type: "string",
@@ -3241,6 +3374,7 @@ function _ksuid(Class, params) {
3241
3374
  ...normalizeParams(params),
3242
3375
  });
3243
3376
  }
3377
+ // @__NO_SIDE_EFFECTS__
3244
3378
  function _ipv4(Class, params) {
3245
3379
  return new Class({
3246
3380
  type: "string",
@@ -3250,6 +3384,7 @@ function _ipv4(Class, params) {
3250
3384
  ...normalizeParams(params),
3251
3385
  });
3252
3386
  }
3387
+ // @__NO_SIDE_EFFECTS__
3253
3388
  function _ipv6(Class, params) {
3254
3389
  return new Class({
3255
3390
  type: "string",
@@ -3259,6 +3394,7 @@ function _ipv6(Class, params) {
3259
3394
  ...normalizeParams(params),
3260
3395
  });
3261
3396
  }
3397
+ // @__NO_SIDE_EFFECTS__
3262
3398
  function _cidrv4(Class, params) {
3263
3399
  return new Class({
3264
3400
  type: "string",
@@ -3268,6 +3404,7 @@ function _cidrv4(Class, params) {
3268
3404
  ...normalizeParams(params),
3269
3405
  });
3270
3406
  }
3407
+ // @__NO_SIDE_EFFECTS__
3271
3408
  function _cidrv6(Class, params) {
3272
3409
  return new Class({
3273
3410
  type: "string",
@@ -3277,6 +3414,7 @@ function _cidrv6(Class, params) {
3277
3414
  ...normalizeParams(params),
3278
3415
  });
3279
3416
  }
3417
+ // @__NO_SIDE_EFFECTS__
3280
3418
  function _base64(Class, params) {
3281
3419
  return new Class({
3282
3420
  type: "string",
@@ -3286,6 +3424,7 @@ function _base64(Class, params) {
3286
3424
  ...normalizeParams(params),
3287
3425
  });
3288
3426
  }
3427
+ // @__NO_SIDE_EFFECTS__
3289
3428
  function _base64url(Class, params) {
3290
3429
  return new Class({
3291
3430
  type: "string",
@@ -3295,6 +3434,7 @@ function _base64url(Class, params) {
3295
3434
  ...normalizeParams(params),
3296
3435
  });
3297
3436
  }
3437
+ // @__NO_SIDE_EFFECTS__
3298
3438
  function _e164(Class, params) {
3299
3439
  return new Class({
3300
3440
  type: "string",
@@ -3304,6 +3444,7 @@ function _e164(Class, params) {
3304
3444
  ...normalizeParams(params),
3305
3445
  });
3306
3446
  }
3447
+ // @__NO_SIDE_EFFECTS__
3307
3448
  function _jwt(Class, params) {
3308
3449
  return new Class({
3309
3450
  type: "string",
@@ -3313,6 +3454,7 @@ function _jwt(Class, params) {
3313
3454
  ...normalizeParams(params),
3314
3455
  });
3315
3456
  }
3457
+ // @__NO_SIDE_EFFECTS__
3316
3458
  function _isoDateTime(Class, params) {
3317
3459
  return new Class({
3318
3460
  type: "string",
@@ -3324,6 +3466,7 @@ function _isoDateTime(Class, params) {
3324
3466
  ...normalizeParams(params),
3325
3467
  });
3326
3468
  }
3469
+ // @__NO_SIDE_EFFECTS__
3327
3470
  function _isoDate(Class, params) {
3328
3471
  return new Class({
3329
3472
  type: "string",
@@ -3332,6 +3475,7 @@ function _isoDate(Class, params) {
3332
3475
  ...normalizeParams(params),
3333
3476
  });
3334
3477
  }
3478
+ // @__NO_SIDE_EFFECTS__
3335
3479
  function _isoTime(Class, params) {
3336
3480
  return new Class({
3337
3481
  type: "string",
@@ -3341,6 +3485,7 @@ function _isoTime(Class, params) {
3341
3485
  ...normalizeParams(params),
3342
3486
  });
3343
3487
  }
3488
+ // @__NO_SIDE_EFFECTS__
3344
3489
  function _isoDuration(Class, params) {
3345
3490
  return new Class({
3346
3491
  type: "string",
@@ -3349,6 +3494,7 @@ function _isoDuration(Class, params) {
3349
3494
  ...normalizeParams(params),
3350
3495
  });
3351
3496
  }
3497
+ // @__NO_SIDE_EFFECTS__
3352
3498
  function _number(Class, params) {
3353
3499
  return new Class({
3354
3500
  type: "number",
@@ -3356,6 +3502,7 @@ function _number(Class, params) {
3356
3502
  ...normalizeParams(params),
3357
3503
  });
3358
3504
  }
3505
+ // @__NO_SIDE_EFFECTS__
3359
3506
  function _int(Class, params) {
3360
3507
  return new Class({
3361
3508
  type: "number",
@@ -3365,28 +3512,33 @@ function _int(Class, params) {
3365
3512
  ...normalizeParams(params),
3366
3513
  });
3367
3514
  }
3515
+ // @__NO_SIDE_EFFECTS__
3368
3516
  function _boolean(Class, params) {
3369
3517
  return new Class({
3370
3518
  type: "boolean",
3371
3519
  ...normalizeParams(params),
3372
3520
  });
3373
3521
  }
3522
+ // @__NO_SIDE_EFFECTS__
3374
3523
  function _any(Class) {
3375
3524
  return new Class({
3376
3525
  type: "any",
3377
3526
  });
3378
3527
  }
3528
+ // @__NO_SIDE_EFFECTS__
3379
3529
  function _unknown(Class) {
3380
3530
  return new Class({
3381
3531
  type: "unknown",
3382
3532
  });
3383
3533
  }
3534
+ // @__NO_SIDE_EFFECTS__
3384
3535
  function _never(Class, params) {
3385
3536
  return new Class({
3386
3537
  type: "never",
3387
3538
  ...normalizeParams(params),
3388
3539
  });
3389
3540
  }
3541
+ // @__NO_SIDE_EFFECTS__
3390
3542
  function _lt(value, params) {
3391
3543
  return new $ZodCheckLessThan({
3392
3544
  check: "less_than",
@@ -3395,6 +3547,7 @@ function _lt(value, params) {
3395
3547
  inclusive: false,
3396
3548
  });
3397
3549
  }
3550
+ // @__NO_SIDE_EFFECTS__
3398
3551
  function _lte(value, params) {
3399
3552
  return new $ZodCheckLessThan({
3400
3553
  check: "less_than",
@@ -3403,6 +3556,7 @@ function _lte(value, params) {
3403
3556
  inclusive: true,
3404
3557
  });
3405
3558
  }
3559
+ // @__NO_SIDE_EFFECTS__
3406
3560
  function _gt(value, params) {
3407
3561
  return new $ZodCheckGreaterThan({
3408
3562
  check: "greater_than",
@@ -3411,6 +3565,7 @@ function _gt(value, params) {
3411
3565
  inclusive: false,
3412
3566
  });
3413
3567
  }
3568
+ // @__NO_SIDE_EFFECTS__
3414
3569
  function _gte(value, params) {
3415
3570
  return new $ZodCheckGreaterThan({
3416
3571
  check: "greater_than",
@@ -3419,6 +3574,7 @@ function _gte(value, params) {
3419
3574
  inclusive: true,
3420
3575
  });
3421
3576
  }
3577
+ // @__NO_SIDE_EFFECTS__
3422
3578
  function _multipleOf(value, params) {
3423
3579
  return new $ZodCheckMultipleOf({
3424
3580
  check: "multiple_of",
@@ -3426,6 +3582,7 @@ function _multipleOf(value, params) {
3426
3582
  value,
3427
3583
  });
3428
3584
  }
3585
+ // @__NO_SIDE_EFFECTS__
3429
3586
  function _maxLength(maximum, params) {
3430
3587
  const ch = new $ZodCheckMaxLength({
3431
3588
  check: "max_length",
@@ -3434,6 +3591,7 @@ function _maxLength(maximum, params) {
3434
3591
  });
3435
3592
  return ch;
3436
3593
  }
3594
+ // @__NO_SIDE_EFFECTS__
3437
3595
  function _minLength(minimum, params) {
3438
3596
  return new $ZodCheckMinLength({
3439
3597
  check: "min_length",
@@ -3441,6 +3599,7 @@ function _minLength(minimum, params) {
3441
3599
  minimum,
3442
3600
  });
3443
3601
  }
3602
+ // @__NO_SIDE_EFFECTS__
3444
3603
  function _length(length, params) {
3445
3604
  return new $ZodCheckLengthEquals({
3446
3605
  check: "length_equals",
@@ -3448,6 +3607,7 @@ function _length(length, params) {
3448
3607
  length,
3449
3608
  });
3450
3609
  }
3610
+ // @__NO_SIDE_EFFECTS__
3451
3611
  function _regex(pattern, params) {
3452
3612
  return new $ZodCheckRegex({
3453
3613
  check: "string_format",
@@ -3456,6 +3616,7 @@ function _regex(pattern, params) {
3456
3616
  pattern,
3457
3617
  });
3458
3618
  }
3619
+ // @__NO_SIDE_EFFECTS__
3459
3620
  function _lowercase(params) {
3460
3621
  return new $ZodCheckLowerCase({
3461
3622
  check: "string_format",
@@ -3463,6 +3624,7 @@ function _lowercase(params) {
3463
3624
  ...normalizeParams(params),
3464
3625
  });
3465
3626
  }
3627
+ // @__NO_SIDE_EFFECTS__
3466
3628
  function _uppercase(params) {
3467
3629
  return new $ZodCheckUpperCase({
3468
3630
  check: "string_format",
@@ -3470,6 +3632,7 @@ function _uppercase(params) {
3470
3632
  ...normalizeParams(params),
3471
3633
  });
3472
3634
  }
3635
+ // @__NO_SIDE_EFFECTS__
3473
3636
  function _includes(includes, params) {
3474
3637
  return new $ZodCheckIncludes({
3475
3638
  check: "string_format",
@@ -3478,6 +3641,7 @@ function _includes(includes, params) {
3478
3641
  includes,
3479
3642
  });
3480
3643
  }
3644
+ // @__NO_SIDE_EFFECTS__
3481
3645
  function _startsWith(prefix, params) {
3482
3646
  return new $ZodCheckStartsWith({
3483
3647
  check: "string_format",
@@ -3486,6 +3650,7 @@ function _startsWith(prefix, params) {
3486
3650
  prefix,
3487
3651
  });
3488
3652
  }
3653
+ // @__NO_SIDE_EFFECTS__
3489
3654
  function _endsWith(suffix, params) {
3490
3655
  return new $ZodCheckEndsWith({
3491
3656
  check: "string_format",
@@ -3494,6 +3659,7 @@ function _endsWith(suffix, params) {
3494
3659
  suffix,
3495
3660
  });
3496
3661
  }
3662
+ // @__NO_SIDE_EFFECTS__
3497
3663
  function _overwrite(tx) {
3498
3664
  return new $ZodCheckOverwrite({
3499
3665
  check: "overwrite",
@@ -3501,25 +3667,31 @@ function _overwrite(tx) {
3501
3667
  });
3502
3668
  }
3503
3669
  // normalize
3670
+ // @__NO_SIDE_EFFECTS__
3504
3671
  function _normalize(form) {
3505
3672
  return _overwrite((input) => input.normalize(form));
3506
3673
  }
3507
3674
  // trim
3675
+ // @__NO_SIDE_EFFECTS__
3508
3676
  function _trim() {
3509
3677
  return _overwrite((input) => input.trim());
3510
3678
  }
3511
3679
  // toLowerCase
3680
+ // @__NO_SIDE_EFFECTS__
3512
3681
  function _toLowerCase() {
3513
3682
  return _overwrite((input) => input.toLowerCase());
3514
3683
  }
3515
3684
  // toUpperCase
3685
+ // @__NO_SIDE_EFFECTS__
3516
3686
  function _toUpperCase() {
3517
3687
  return _overwrite((input) => input.toUpperCase());
3518
3688
  }
3519
3689
  // slugify
3690
+ // @__NO_SIDE_EFFECTS__
3520
3691
  function _slugify() {
3521
3692
  return _overwrite((input) => slugify(input));
3522
3693
  }
3694
+ // @__NO_SIDE_EFFECTS__
3523
3695
  function _array(Class, element, params) {
3524
3696
  return new Class({
3525
3697
  type: "array",
@@ -3531,6 +3703,7 @@ function _array(Class, element, params) {
3531
3703
  });
3532
3704
  }
3533
3705
  // same as _custom but defaults to abort:false
3706
+ // @__NO_SIDE_EFFECTS__
3534
3707
  function _refine(Class, fn, _params) {
3535
3708
  const schema = new Class({
3536
3709
  type: "custom",
@@ -3540,6 +3713,7 @@ function _refine(Class, fn, _params) {
3540
3713
  });
3541
3714
  return schema;
3542
3715
  }
3716
+ // @__NO_SIDE_EFFECTS__
3543
3717
  function _superRefine(fn) {
3544
3718
  const ch = _check((payload) => {
3545
3719
  payload.addIssue = (issue$1) => {
@@ -3562,6 +3736,7 @@ function _superRefine(fn) {
3562
3736
  });
3563
3737
  return ch;
3564
3738
  }
3739
+ // @__NO_SIDE_EFFECTS__
3565
3740
  function _check(fn, params) {
3566
3741
  const ch = new $ZodCheck({
3567
3742
  check: "custom",
@@ -3600,7 +3775,7 @@ function initializeContext(params) {
3600
3775
  external: params?.external ?? undefined,
3601
3776
  };
3602
3777
  }
3603
- function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3778
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3604
3779
  var _a;
3605
3780
  const def = schema._zod.def;
3606
3781
  // check for schema in seens
@@ -3628,14 +3803,7 @@ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3628
3803
  schemaPath: [..._params.schemaPath, schema],
3629
3804
  path: _params.path,
3630
3805
  };
3631
- const parent = schema._zod.parent;
3632
- if (parent) {
3633
- // schema was cloned from another schema
3634
- result.ref = parent;
3635
- process$1(parent, ctx, params);
3636
- ctx.seen.get(parent).isParent = true;
3637
- }
3638
- else if (schema._zod.processJSONSchema) {
3806
+ if (schema._zod.processJSONSchema) {
3639
3807
  schema._zod.processJSONSchema(ctx, result.schema, params);
3640
3808
  }
3641
3809
  else {
@@ -3646,6 +3814,14 @@ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3646
3814
  }
3647
3815
  processor(schema, ctx, _json, params);
3648
3816
  }
3817
+ const parent = schema._zod.parent;
3818
+ if (parent) {
3819
+ // Also set ref if processor didn't (for inheritance)
3820
+ if (!result.ref)
3821
+ result.ref = parent;
3822
+ process(parent, ctx, params);
3823
+ ctx.seen.get(parent).isParent = true;
3824
+ }
3649
3825
  }
3650
3826
  // metadata
3651
3827
  const meta = ctx.metadataRegistry.get(schema);
@@ -3671,6 +3847,18 @@ function extractDefs(ctx, schema
3671
3847
  const root = ctx.seen.get(schema);
3672
3848
  if (!root)
3673
3849
  throw new Error("Unprocessed schema. This is a bug in Zod.");
3850
+ // Track ids to detect duplicates across different schemas
3851
+ const idToSchema = new Map();
3852
+ for (const entry of ctx.seen.entries()) {
3853
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3854
+ if (id) {
3855
+ const existing = idToSchema.get(id);
3856
+ if (existing && existing !== entry[0]) {
3857
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
3858
+ }
3859
+ idToSchema.set(id, entry[0]);
3860
+ }
3861
+ }
3674
3862
  // returns a ref to the schema
3675
3863
  // defId will be empty if the ref points to an external schema (or #)
3676
3864
  const makeURI = (entry) => {
@@ -3772,43 +3960,84 @@ function extractDefs(ctx, schema
3772
3960
  }
3773
3961
  }
3774
3962
  function finalize(ctx, schema) {
3775
- //
3776
- // iterate over seen map;
3777
3963
  const root = ctx.seen.get(schema);
3778
3964
  if (!root)
3779
3965
  throw new Error("Unprocessed schema. This is a bug in Zod.");
3780
- // flatten _refs
3966
+ // flatten refs - inherit properties from parent schemas
3781
3967
  const flattenRef = (zodSchema) => {
3782
3968
  const seen = ctx.seen.get(zodSchema);
3969
+ // already processed
3970
+ if (seen.ref === null)
3971
+ return;
3783
3972
  const schema = seen.def ?? seen.schema;
3784
3973
  const _cached = { ...schema };
3785
- // already seen
3786
- if (seen.ref === null) {
3787
- return;
3788
- }
3789
- // flatten ref if defined
3790
3974
  const ref = seen.ref;
3791
- seen.ref = null; // prevent recursion
3975
+ seen.ref = null; // prevent infinite recursion
3792
3976
  if (ref) {
3793
3977
  flattenRef(ref);
3978
+ const refSeen = ctx.seen.get(ref);
3979
+ const refSchema = refSeen.schema;
3794
3980
  // merge referenced schema into current
3795
- const refSchema = ctx.seen.get(ref).schema;
3796
3981
  if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
3982
+ // older drafts can't combine $ref with other properties
3797
3983
  schema.allOf = schema.allOf ?? [];
3798
3984
  schema.allOf.push(refSchema);
3799
3985
  }
3800
3986
  else {
3801
3987
  Object.assign(schema, refSchema);
3802
- Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
3988
+ }
3989
+ // restore child's own properties (child wins)
3990
+ Object.assign(schema, _cached);
3991
+ const isParentRef = zodSchema._zod.parent === ref;
3992
+ // For parent chain, child is a refinement - remove parent-only properties
3993
+ if (isParentRef) {
3994
+ for (const key in schema) {
3995
+ if (key === "$ref" || key === "allOf")
3996
+ continue;
3997
+ if (!(key in _cached)) {
3998
+ delete schema[key];
3999
+ }
4000
+ }
4001
+ }
4002
+ // When ref was extracted to $defs, remove properties that match the definition
4003
+ if (refSchema.$ref) {
4004
+ for (const key in schema) {
4005
+ if (key === "$ref" || key === "allOf")
4006
+ continue;
4007
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) {
4008
+ delete schema[key];
4009
+ }
4010
+ }
4011
+ }
4012
+ }
4013
+ // If parent was extracted (has $ref), propagate $ref to this schema
4014
+ // This handles cases like: readonly().meta({id}).describe()
4015
+ // where processor sets ref to innerType but parent should be referenced
4016
+ const parent = zodSchema._zod.parent;
4017
+ if (parent && parent !== ref) {
4018
+ // Ensure parent is processed first so its def has inherited properties
4019
+ flattenRef(parent);
4020
+ const parentSeen = ctx.seen.get(parent);
4021
+ if (parentSeen?.schema.$ref) {
4022
+ schema.$ref = parentSeen.schema.$ref;
4023
+ // De-duplicate with parent's definition
4024
+ if (parentSeen.def) {
4025
+ for (const key in schema) {
4026
+ if (key === "$ref" || key === "allOf")
4027
+ continue;
4028
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) {
4029
+ delete schema[key];
4030
+ }
4031
+ }
4032
+ }
3803
4033
  }
3804
4034
  }
3805
4035
  // execute overrides
3806
- if (!seen.isParent)
3807
- ctx.override({
3808
- zodSchema: zodSchema,
3809
- jsonSchema: schema,
3810
- path: seen.path ?? [],
3811
- });
4036
+ ctx.override({
4037
+ zodSchema: zodSchema,
4038
+ jsonSchema: schema,
4039
+ path: seen.path ?? [],
4040
+ });
3812
4041
  };
3813
4042
  for (const entry of [...ctx.seen.entries()].reverse()) {
3814
4043
  flattenRef(entry[0]);
@@ -3861,8 +4090,8 @@ function finalize(ctx, schema) {
3861
4090
  value: {
3862
4091
  ...schema["~standard"],
3863
4092
  jsonSchema: {
3864
- input: createStandardJSONSchemaMethod(schema, "input"),
3865
- output: createStandardJSONSchemaMethod(schema, "output"),
4093
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
4094
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors),
3866
4095
  },
3867
4096
  },
3868
4097
  enumerable: false,
@@ -3937,14 +4166,14 @@ function isTransforming(_schema, _ctx) {
3937
4166
  */
3938
4167
  const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3939
4168
  const ctx = initializeContext({ ...params, processors });
3940
- process$1(schema, ctx);
4169
+ process(schema, ctx);
3941
4170
  extractDefs(ctx, schema);
3942
4171
  return finalize(ctx, schema);
3943
4172
  };
3944
- const createStandardJSONSchemaMethod = (schema, io) => (params) => {
4173
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3945
4174
  const { libraryOptions, target } = params ?? {};
3946
- const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
3947
- process$1(schema, ctx);
4175
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors });
4176
+ process(schema, ctx);
3948
4177
  extractDefs(ctx, schema);
3949
4178
  return finalize(ctx, schema);
3950
4179
  };
@@ -3971,6 +4200,11 @@ const stringProcessor = (schema, ctx, _json, _params) => {
3971
4200
  json.format = formatMap[format] ?? format;
3972
4201
  if (json.format === "")
3973
4202
  delete json.format; // empty format is not valid
4203
+ // JSON Schema format: "time" requires a full time with offset or Z
4204
+ // z.iso.time() does not include timezone information, so format: "time" should never be used
4205
+ if (format === "time") {
4206
+ delete json.format;
4207
+ }
3974
4208
  }
3975
4209
  if (contentEncoding)
3976
4210
  json.contentEncoding = contentEncoding;
@@ -4078,7 +4312,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
4078
4312
  if (typeof maximum === "number")
4079
4313
  json.maxItems = maximum;
4080
4314
  json.type = "array";
4081
- json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
4315
+ json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
4082
4316
  };
4083
4317
  const objectProcessor = (schema, ctx, _json, params) => {
4084
4318
  const json = _json;
@@ -4087,7 +4321,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4087
4321
  json.properties = {};
4088
4322
  const shape = def.shape;
4089
4323
  for (const key in shape) {
4090
- json.properties[key] = process$1(shape[key], ctx, {
4324
+ json.properties[key] = process(shape[key], ctx, {
4091
4325
  ...params,
4092
4326
  path: [...params.path, "properties", key],
4093
4327
  });
@@ -4117,7 +4351,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
4117
4351
  json.additionalProperties = false;
4118
4352
  }
4119
4353
  else if (def.catchall) {
4120
- json.additionalProperties = process$1(def.catchall, ctx, {
4354
+ json.additionalProperties = process(def.catchall, ctx, {
4121
4355
  ...params,
4122
4356
  path: [...params.path, "additionalProperties"],
4123
4357
  });
@@ -4128,7 +4362,7 @@ const unionProcessor = (schema, ctx, json, params) => {
4128
4362
  // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
4129
4363
  // This includes both z.xor() and discriminated unions
4130
4364
  const isExclusive = def.inclusive === false;
4131
- const options = def.options.map((x, i) => process$1(x, ctx, {
4365
+ const options = def.options.map((x, i) => process(x, ctx, {
4132
4366
  ...params,
4133
4367
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
4134
4368
  }));
@@ -4141,11 +4375,11 @@ const unionProcessor = (schema, ctx, json, params) => {
4141
4375
  };
4142
4376
  const intersectionProcessor = (schema, ctx, json, params) => {
4143
4377
  const def = schema._zod.def;
4144
- const a = process$1(def.left, ctx, {
4378
+ const a = process(def.left, ctx, {
4145
4379
  ...params,
4146
4380
  path: [...params.path, "allOf", 0],
4147
4381
  });
4148
- const b = process$1(def.right, ctx, {
4382
+ const b = process(def.right, ctx, {
4149
4383
  ...params,
4150
4384
  path: [...params.path, "allOf", 1],
4151
4385
  });
@@ -4158,7 +4392,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
4158
4392
  };
4159
4393
  const nullableProcessor = (schema, ctx, json, params) => {
4160
4394
  const def = schema._zod.def;
4161
- const inner = process$1(def.innerType, ctx, params);
4395
+ const inner = process(def.innerType, ctx, params);
4162
4396
  const seen = ctx.seen.get(schema);
4163
4397
  if (ctx.target === "openapi-3.0") {
4164
4398
  seen.ref = def.innerType;
@@ -4170,20 +4404,20 @@ const nullableProcessor = (schema, ctx, json, params) => {
4170
4404
  };
4171
4405
  const nonoptionalProcessor = (schema, ctx, _json, params) => {
4172
4406
  const def = schema._zod.def;
4173
- process$1(def.innerType, ctx, params);
4407
+ process(def.innerType, ctx, params);
4174
4408
  const seen = ctx.seen.get(schema);
4175
4409
  seen.ref = def.innerType;
4176
4410
  };
4177
4411
  const defaultProcessor = (schema, ctx, json, params) => {
4178
4412
  const def = schema._zod.def;
4179
- process$1(def.innerType, ctx, params);
4413
+ process(def.innerType, ctx, params);
4180
4414
  const seen = ctx.seen.get(schema);
4181
4415
  seen.ref = def.innerType;
4182
4416
  json.default = JSON.parse(JSON.stringify(def.defaultValue));
4183
4417
  };
4184
4418
  const prefaultProcessor = (schema, ctx, json, params) => {
4185
4419
  const def = schema._zod.def;
4186
- process$1(def.innerType, ctx, params);
4420
+ process(def.innerType, ctx, params);
4187
4421
  const seen = ctx.seen.get(schema);
4188
4422
  seen.ref = def.innerType;
4189
4423
  if (ctx.io === "input")
@@ -4191,7 +4425,7 @@ const prefaultProcessor = (schema, ctx, json, params) => {
4191
4425
  };
4192
4426
  const catchProcessor = (schema, ctx, json, params) => {
4193
4427
  const def = schema._zod.def;
4194
- process$1(def.innerType, ctx, params);
4428
+ process(def.innerType, ctx, params);
4195
4429
  const seen = ctx.seen.get(schema);
4196
4430
  seen.ref = def.innerType;
4197
4431
  let catchValue;
@@ -4206,20 +4440,20 @@ const catchProcessor = (schema, ctx, json, params) => {
4206
4440
  const pipeProcessor = (schema, ctx, _json, params) => {
4207
4441
  const def = schema._zod.def;
4208
4442
  const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
4209
- process$1(innerType, ctx, params);
4443
+ process(innerType, ctx, params);
4210
4444
  const seen = ctx.seen.get(schema);
4211
4445
  seen.ref = innerType;
4212
4446
  };
4213
4447
  const readonlyProcessor = (schema, ctx, json, params) => {
4214
4448
  const def = schema._zod.def;
4215
- process$1(def.innerType, ctx, params);
4449
+ process(def.innerType, ctx, params);
4216
4450
  const seen = ctx.seen.get(schema);
4217
4451
  seen.ref = def.innerType;
4218
4452
  json.readOnly = true;
4219
4453
  };
4220
4454
  const optionalProcessor = (schema, ctx, _json, params) => {
4221
4455
  const def = schema._zod.def;
4222
- process$1(def.innerType, ctx, params);
4456
+ process(def.innerType, ctx, params);
4223
4457
  const seen = ctx.seen.get(schema);
4224
4458
  seen.ref = def.innerType;
4225
4459
  };
@@ -4332,8 +4566,11 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4332
4566
  ...(def.checks ?? []),
4333
4567
  ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
4334
4568
  ],
4335
- }));
4569
+ }), {
4570
+ parent: true,
4571
+ });
4336
4572
  };
4573
+ inst.with = inst.check;
4337
4574
  inst.clone = (def, params) => clone(inst, def, params);
4338
4575
  inst.brand = () => inst;
4339
4576
  inst.register = ((reg, meta) => {
@@ -4361,6 +4598,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4361
4598
  inst.overwrite = (fn) => inst.check(_overwrite(fn));
4362
4599
  // wrappers
4363
4600
  inst.optional = () => optional(inst);
4601
+ inst.exactOptional = () => exactOptional(inst);
4364
4602
  inst.nullable = () => nullable(inst);
4365
4603
  inst.nullish = () => optional(nullable(inst));
4366
4604
  inst.nonoptional = (params) => nonoptional(inst, params);
@@ -4397,6 +4635,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4397
4635
  // helpers
4398
4636
  inst.isOptional = () => inst.safeParse(undefined).success;
4399
4637
  inst.isNullable = () => inst.safeParse(null).success;
4638
+ inst.apply = (fn) => fn(inst);
4400
4639
  return inst;
4401
4640
  });
4402
4641
  /** @internal */
@@ -4802,6 +5041,18 @@ function optional(innerType) {
4802
5041
  innerType: innerType,
4803
5042
  });
4804
5043
  }
5044
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
5045
+ $ZodExactOptional.init(inst, def);
5046
+ ZodType.init(inst, def);
5047
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
5048
+ inst.unwrap = () => inst._zod.def.innerType;
5049
+ });
5050
+ function exactOptional(innerType) {
5051
+ return new ZodExactOptional({
5052
+ type: "optional",
5053
+ innerType: innerType,
5054
+ });
5055
+ }
4805
5056
  const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4806
5057
  $ZodNullable.init(inst, def);
4807
5058
  ZodType.init(inst, def);
@@ -4961,93 +5212,6 @@ const createSchema = (rule) => {
4961
5212
  }
4962
5213
  };
4963
5214
 
4964
- typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
4965
- // @ts-ignore
4966
- typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
4967
- // @ts-ignore
4968
- const isBun = typeof Bun !== 'undefined' && typeof Bun.version === 'string';
4969
-
4970
- const parseBody = async (req) => {
4971
- const resolveBody = (body) => {
4972
- // 获取 Content-Type 头信息
4973
- const contentType = req.headers['content-type'] || '';
4974
- const resolve = (data) => {
4975
- return data;
4976
- };
4977
- // 处理 application/json
4978
- if (contentType.includes('application/json')) {
4979
- return resolve(JSON.parse(body));
4980
- }
4981
- // 处理 application/x-www-form-urlencoded
4982
- if (contentType.includes('application/x-www-form-urlencoded')) {
4983
- const formData = new URLSearchParams(body);
4984
- const result = {};
4985
- formData.forEach((value, key) => {
4986
- // 尝试将值解析为 JSON,如果失败则保留原始字符串
4987
- try {
4988
- result[key] = JSON.parse(value);
4989
- }
4990
- catch {
4991
- result[key] = value;
4992
- }
4993
- });
4994
- return resolve(result);
4995
- }
4996
- // 默认尝试 JSON 解析
4997
- try {
4998
- return resolve(JSON.parse(body));
4999
- }
5000
- catch {
5001
- return resolve({});
5002
- }
5003
- };
5004
- if (isBun) {
5005
- // @ts-ignore
5006
- const body = req.body;
5007
- if (body) {
5008
- return resolveBody(body);
5009
- }
5010
- return {};
5011
- }
5012
- return new Promise((resolve, reject) => {
5013
- const arr = [];
5014
- req.on('data', (chunk) => {
5015
- arr.push(chunk);
5016
- });
5017
- req.on('end', () => {
5018
- try {
5019
- const body = Buffer.concat(arr).toString();
5020
- resolve(resolveBody(body));
5021
- }
5022
- catch (e) {
5023
- resolve({});
5024
- }
5025
- });
5026
- });
5027
- };
5028
- const parseSearch = (req) => {
5029
- const parsedUrl = url.parse(req.url, true);
5030
- return parsedUrl.query;
5031
- };
5032
- /**
5033
- * 把url当个key 的 value 的字符串转成json
5034
- * @param value
5035
- */
5036
- const parseSearchValue = (value, opts) => {
5037
- if (!value)
5038
- return {};
5039
- const decode = opts?.decode ?? false;
5040
- if (decode) {
5041
- value = decodeURIComponent(value);
5042
- }
5043
- try {
5044
- return JSON.parse(value);
5045
- }
5046
- catch (e) {
5047
- return {};
5048
- }
5049
- };
5050
-
5051
5215
  function define(value) {
5052
5216
  return value;
5053
5217
  }
@@ -5182,4 +5346,4 @@ class QueryUtil {
5182
5346
 
5183
5347
  const App = QueryRouterServer;
5184
5348
 
5185
- export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, define, parseBody, parseSearch, parseSearchValue, util };
5349
+ export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, util };