agent-relay 6.0.2 → 6.0.4

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.
Files changed (173) hide show
  1. package/README.md +10 -3
  2. package/dist/index.cjs +2024 -962
  3. package/dist/src/cli/commands/cloud.d.ts.map +1 -1
  4. package/dist/src/cli/commands/cloud.js +17 -144
  5. package/dist/src/cli/commands/cloud.js.map +1 -1
  6. package/dist/src/cli/commands/setup.d.ts +2 -39
  7. package/dist/src/cli/commands/setup.d.ts.map +1 -1
  8. package/dist/src/cli/commands/setup.js +4 -333
  9. package/dist/src/cli/commands/setup.js.map +1 -1
  10. package/dist/src/cli/lib/auth-ssh.d.ts +2 -33
  11. package/dist/src/cli/lib/auth-ssh.d.ts.map +1 -1
  12. package/dist/src/cli/lib/auth-ssh.js +3 -39
  13. package/dist/src/cli/lib/auth-ssh.js.map +1 -1
  14. package/dist/src/cli/lib/ssh-interactive.d.ts +4 -66
  15. package/dist/src/cli/lib/ssh-interactive.d.ts.map +1 -1
  16. package/dist/src/cli/lib/ssh-interactive.js +4 -436
  17. package/dist/src/cli/lib/ssh-interactive.js.map +1 -1
  18. package/node_modules/@relaycast/sdk/node_modules/zod/README.md +1 -1
  19. package/node_modules/@relaycast/sdk/node_modules/zod/locales/package.json +2 -1
  20. package/node_modules/@relaycast/sdk/node_modules/zod/mini/package.json +2 -1
  21. package/node_modules/@relaycast/sdk/node_modules/zod/package.json +1 -1
  22. package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/all-errors.test.ts +3 -3
  23. package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/object.test.ts +5 -5
  24. package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/partials.test.ts +3 -3
  25. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/errors.ts +2 -2
  26. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/external.ts +1 -0
  27. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/from-json-schema.ts +39 -23
  28. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/parse.ts +6 -6
  29. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/schemas.ts +389 -148
  30. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/catch.test.ts +4 -2
  31. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/codec.test.ts +142 -1
  32. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/continuability.test.ts +1 -1
  33. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/datetime.test.ts +1 -1
  34. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/default.test.ts +44 -0
  35. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +197 -0
  36. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +31 -1
  37. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +214 -2
  38. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +161 -0
  39. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/function.test.ts +6 -6
  40. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/global-config.test.ts +39 -0
  41. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/index.test.ts +2 -2
  42. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +46 -0
  43. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  44. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  45. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/number.test.ts +55 -0
  46. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/object.test.ts +83 -6
  47. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/optional.test.ts +114 -4
  48. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/partial.test.ts +28 -2
  49. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/prefault.test.ts +1 -1
  50. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/record.test.ts +85 -0
  51. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +49 -0
  52. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/refine.test.ts +63 -0
  53. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/string.test.ts +50 -1
  54. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +4 -4
  55. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +128 -14
  56. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/transform.test.ts +17 -0
  57. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/tuple.test.ts +315 -2
  58. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/union.test.ts +54 -0
  59. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/api.ts +25 -2
  60. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/checks.ts +1 -1
  61. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/core.ts +17 -2
  62. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/errors.ts +31 -24
  63. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/json-schema-processors.ts +15 -17
  64. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/parse.ts +7 -7
  65. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/regexes.ts +8 -1
  66. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/schemas.ts +218 -66
  67. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/el.test.ts +215 -0
  68. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  69. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  70. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +22 -0
  71. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +58 -0
  72. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/to-json-schema.ts +9 -1
  73. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/util.ts +52 -35
  74. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/versions.ts +2 -2
  75. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/el.ts +121 -0
  76. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/en.ts +4 -0
  77. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/fr.ts +24 -8
  78. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/hr.ts +131 -0
  79. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/index.ts +3 -0
  80. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/it.ts +1 -1
  81. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/ka.ts +8 -8
  82. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/ro.ts +129 -0
  83. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/uz.ts +1 -0
  84. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/external.ts +1 -0
  85. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/schemas.ts +55 -24
  86. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/codec.test.ts +19 -0
  87. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/index.test.ts +27 -2
  88. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/object.test.ts +9 -9
  89. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +51 -1
  90. package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/string.test.ts +5 -0
  91. package/node_modules/@relaycast/sdk/node_modules/zod/v3/package.json +2 -1
  92. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/errors.js +2 -2
  93. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/external.d.cts +1 -0
  94. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/external.d.ts +1 -0
  95. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/from-json-schema.cjs +31 -16
  96. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/from-json-schema.js +31 -16
  97. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/package.json +2 -1
  98. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.cjs +346 -117
  99. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.cts +34 -12
  100. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.ts +34 -12
  101. package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.js +345 -117
  102. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.cjs +7 -2
  103. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.cts +20 -1
  104. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.ts +20 -1
  105. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.js +7 -2
  106. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/checks.d.cts +1 -1
  107. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/checks.d.ts +1 -1
  108. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/core.cjs +3 -1
  109. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/core.js +4 -2
  110. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.cjs +26 -23
  111. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.d.cts +1 -0
  112. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.d.ts +1 -0
  113. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.js +26 -23
  114. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.cjs +14 -19
  115. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.js +14 -19
  116. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/package.json +2 -1
  117. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/parse.cjs +7 -7
  118. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/parse.js +7 -7
  119. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.cjs +9 -3
  120. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.d.cts +6 -0
  121. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.d.ts +6 -0
  122. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.js +7 -1
  123. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.cjs +196 -59
  124. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.cts +21 -1
  125. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.ts +21 -1
  126. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.js +196 -59
  127. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.cjs +10 -1
  128. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.js +10 -1
  129. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.cjs +54 -30
  130. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.d.cts +1 -0
  131. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.d.ts +1 -0
  132. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.js +55 -32
  133. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.cjs +2 -2
  134. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.d.cts +1 -1
  135. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.d.ts +1 -1
  136. package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.js +2 -2
  137. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.cjs +136 -0
  138. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.d.cts +5 -0
  139. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.d.ts +4 -0
  140. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.js +109 -0
  141. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/en.cjs +4 -0
  142. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/en.js +4 -0
  143. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/fr.cjs +24 -7
  144. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/fr.js +24 -7
  145. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.cjs +149 -0
  146. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.d.cts +5 -0
  147. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.d.ts +4 -0
  148. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.js +122 -0
  149. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.cjs +8 -1
  150. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.d.cts +3 -0
  151. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.d.ts +3 -0
  152. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.js +3 -0
  153. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/it.cjs +1 -1
  154. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/it.js +1 -1
  155. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ka.cjs +8 -8
  156. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ka.js +8 -8
  157. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/package.json +2 -1
  158. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.cjs +146 -0
  159. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.d.cts +5 -0
  160. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.d.ts +4 -0
  161. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.js +119 -0
  162. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/uz.cjs +1 -0
  163. package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/uz.js +1 -0
  164. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/external.d.cts +1 -0
  165. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/external.d.ts +1 -0
  166. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/package.json +2 -1
  167. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.cjs +41 -4
  168. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.cts +27 -9
  169. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.ts +27 -9
  170. package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.js +40 -4
  171. package/node_modules/@relaycast/sdk/node_modules/zod/v4/package.json +2 -1
  172. package/node_modules/@relaycast/sdk/node_modules/zod/v4-mini/package.json +2 -1
  173. package/package.json +10 -10
@@ -65,6 +65,8 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
65
65
  let asyncResult;
66
66
  for (const ch of checks) {
67
67
  if (ch._zod.def.when) {
68
+ if (util.explicitlyAborted(payload))
69
+ continue;
68
70
  const shouldRun = ch._zod.def.when(payload);
69
71
  if (!shouldRun)
70
72
  continue;
@@ -219,6 +221,21 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
219
221
  try {
220
222
  // Trim whitespace from input
221
223
  const trimmed = payload.value.trim();
224
+ // When normalize is off, require :// for http/https URLs
225
+ // This prevents strings like "http:example.com" or "https:/path" from being silently accepted
226
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source) {
227
+ if (!/^https?:\/\//i.test(trimmed)) {
228
+ payload.issues.push({
229
+ code: "invalid_format",
230
+ format: "url",
231
+ note: "Invalid URL format",
232
+ input: payload.value,
233
+ inst,
234
+ continue: !def.abort,
235
+ });
236
+ return;
237
+ }
238
+ }
222
239
  // @ts-ignore
223
240
  const url = new URL(trimmed);
224
241
  if (def.hostname) {
@@ -279,6 +296,11 @@ exports.$ZodNanoID = core.$constructor("$ZodNanoID", (inst, def) => {
279
296
  def.pattern ?? (def.pattern = regexes.nanoid);
280
297
  exports.$ZodStringFormat.init(inst, def);
281
298
  });
299
+ /**
300
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
301
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
302
+ * See https://github.com/paralleldrive/cuid.
303
+ */
282
304
  exports.$ZodCUID = core.$constructor("$ZodCUID", (inst, def) => {
283
305
  def.pattern ?? (def.pattern = regexes.cuid);
284
306
  exports.$ZodStringFormat.init(inst, def);
@@ -384,6 +406,9 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
384
406
  function isValidBase64(data) {
385
407
  if (data === "")
386
408
  return true;
409
+ // atob ignores whitespace, so reject it up front.
410
+ if (/\s/.test(data))
411
+ return false;
387
412
  if (data.length % 4 !== 0)
388
413
  return false;
389
414
  try {
@@ -588,8 +613,6 @@ exports.$ZodUndefined = core.$constructor("$ZodUndefined", (inst, def) => {
588
613
  exports.$ZodType.init(inst, def);
589
614
  inst._zod.pattern = regexes.undefined;
590
615
  inst._zod.values = new Set([undefined]);
591
- inst._zod.optin = "optional";
592
- inst._zod.optout = "optional";
593
616
  inst._zod.parse = (payload, _ctx) => {
594
617
  const input = payload.value;
595
618
  if (typeof input === "undefined")
@@ -719,16 +742,28 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
719
742
  return payload; //handleArrayResultsAsync(parseResults, final);
720
743
  };
721
744
  });
722
- function handlePropertyResult(result, final, key, input, isOptionalOut) {
745
+ function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
746
+ const isPresent = key in input;
723
747
  if (result.issues.length) {
724
- // For optional-out schemas, ignore errors on absent keys
725
- if (isOptionalOut && !(key in input)) {
748
+ // For optional-in/out schemas, ignore errors on absent keys.
749
+ if (isOptionalIn && isOptionalOut && !isPresent) {
726
750
  return;
727
751
  }
728
752
  final.issues.push(...util.prefixIssues(key, result.issues));
729
753
  }
754
+ if (!isPresent && !isOptionalIn) {
755
+ if (!result.issues.length) {
756
+ final.issues.push({
757
+ code: "invalid_type",
758
+ expected: "nonoptional",
759
+ input: undefined,
760
+ path: [key],
761
+ });
762
+ }
763
+ return;
764
+ }
730
765
  if (result.value === undefined) {
731
- if (key in input) {
766
+ if (isPresent) {
732
767
  final.value[key] = undefined;
733
768
  }
734
769
  }
@@ -754,12 +789,16 @@ function normalizeDef(def) {
754
789
  }
755
790
  function handleCatchall(proms, input, payload, ctx, def, inst) {
756
791
  const unrecognized = [];
757
- // iterate over input keys
758
792
  const keySet = def.keySet;
759
793
  const _catchall = def.catchall._zod;
760
794
  const t = _catchall.def.type;
795
+ const isOptionalIn = _catchall.optin === "optional";
761
796
  const isOptionalOut = _catchall.optout === "optional";
762
797
  for (const key in input) {
798
+ // skip __proto__ so it can't replace the result prototype via the
799
+ // assignment setter on the plain {} we build into
800
+ if (key === "__proto__")
801
+ continue;
763
802
  if (keySet.has(key))
764
803
  continue;
765
804
  if (t === "never") {
@@ -768,10 +807,10 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
768
807
  }
769
808
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
770
809
  if (r instanceof Promise) {
771
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
810
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
772
811
  }
773
812
  else {
774
- handlePropertyResult(r, payload, key, input, isOptionalOut);
813
+ handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
775
814
  }
776
815
  }
777
816
  if (unrecognized.length) {
@@ -839,13 +878,14 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
839
878
  const shape = value.shape;
840
879
  for (const key of value.keys) {
841
880
  const el = shape[key];
881
+ const isOptionalIn = el._zod.optin === "optional";
842
882
  const isOptionalOut = el._zod.optout === "optional";
843
883
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
844
884
  if (r instanceof Promise) {
845
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
885
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
846
886
  }
847
887
  else {
848
- handlePropertyResult(r, payload, key, input, isOptionalOut);
888
+ handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
849
889
  }
850
890
  }
851
891
  if (!catchall) {
@@ -878,10 +918,11 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
878
918
  const id = ids[key];
879
919
  const k = util.esc(key);
880
920
  const schema = shape[key];
921
+ const isOptionalIn = schema?._zod?.optin === "optional";
881
922
  const isOptionalOut = schema?._zod?.optout === "optional";
882
923
  doc.write(`const ${id} = ${parseStr(key)};`);
883
- if (isOptionalOut) {
884
- // For optional-out schemas, ignore errors on absent keys
924
+ if (isOptionalIn && isOptionalOut) {
925
+ // For optional-in/out schemas, ignore errors on absent keys
885
926
  doc.write(`
886
927
  if (${id}.issues.length) {
887
928
  if (${k} in input) {
@@ -900,6 +941,34 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
900
941
  newResult[${k}] = ${id}.value;
901
942
  }
902
943
 
944
+ `);
945
+ }
946
+ else if (!isOptionalIn) {
947
+ doc.write(`
948
+ const ${id}_present = ${k} in input;
949
+ if (${id}.issues.length) {
950
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
951
+ ...iss,
952
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
953
+ })));
954
+ }
955
+ if (!${id}_present && !${id}.issues.length) {
956
+ payload.issues.push({
957
+ code: "invalid_type",
958
+ expected: "nonoptional",
959
+ input: undefined,
960
+ path: [${k}]
961
+ });
962
+ }
963
+
964
+ if (${id}_present) {
965
+ if (${id}.value === undefined) {
966
+ newResult[${k}] = undefined;
967
+ } else {
968
+ newResult[${k}] = ${id}.value;
969
+ }
970
+ }
971
+
903
972
  `);
904
973
  }
905
974
  else {
@@ -995,10 +1064,9 @@ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
995
1064
  }
996
1065
  return undefined;
997
1066
  });
998
- const single = def.options.length === 1;
999
- const first = def.options[0]._zod.run;
1067
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1000
1068
  inst._zod.parse = (payload, ctx) => {
1001
- if (single) {
1069
+ if (first) {
1002
1070
  return first(payload, ctx);
1003
1071
  }
1004
1072
  let async = false;
@@ -1055,10 +1123,9 @@ function handleExclusiveUnionResults(results, final, inst, ctx) {
1055
1123
  exports.$ZodXor = core.$constructor("$ZodXor", (inst, def) => {
1056
1124
  exports.$ZodUnion.init(inst, def);
1057
1125
  def.inclusive = false;
1058
- const single = def.options.length === 1;
1059
- const first = def.options[0]._zod.run;
1126
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1060
1127
  inst._zod.parse = (payload, ctx) => {
1061
- if (single) {
1128
+ if (first) {
1062
1129
  return first(payload, ctx);
1063
1130
  }
1064
1131
  let async = false;
@@ -1136,7 +1203,11 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1136
1203
  if (opt) {
1137
1204
  return opt._zod.run(payload, ctx);
1138
1205
  }
1139
- if (def.unionFallback) {
1206
+ // Fall back to union matching when the fast discriminator path fails:
1207
+ // - explicitly enabled via unionFallback, or
1208
+ // - during backward direction (encode), since codec-based discriminators
1209
+ // have different values in forward vs backward directions
1210
+ if (def.unionFallback || ctx.direction === "backward") {
1140
1211
  return _super(payload, ctx);
1141
1212
  }
1142
1213
  // no matching discriminator
@@ -1145,6 +1216,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1145
1216
  errors: [],
1146
1217
  note: "No matching discriminator",
1147
1218
  discriminator: def.discriminator,
1219
+ options: Array.from(disc.value.keys()),
1148
1220
  input,
1149
1221
  path: [def.discriminator],
1150
1222
  inst,
@@ -1272,67 +1344,112 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1272
1344
  }
1273
1345
  payload.value = [];
1274
1346
  const proms = [];
1275
- const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
1276
- const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
1347
+ const optinStart = getTupleOptStart(items, "optin");
1348
+ const optoutStart = getTupleOptStart(items, "optout");
1277
1349
  if (!def.rest) {
1278
- const tooBig = input.length > items.length;
1279
- const tooSmall = input.length < optStart - 1;
1280
- if (tooBig || tooSmall) {
1350
+ if (input.length < optinStart) {
1281
1351
  payload.issues.push({
1282
- ...(tooBig
1283
- ? { code: "too_big", maximum: items.length, inclusive: true }
1284
- : { code: "too_small", minimum: items.length }),
1352
+ code: "too_small",
1353
+ minimum: optinStart,
1354
+ inclusive: true,
1285
1355
  input,
1286
1356
  inst,
1287
1357
  origin: "array",
1288
1358
  });
1289
1359
  return payload;
1290
1360
  }
1361
+ if (input.length > items.length) {
1362
+ payload.issues.push({
1363
+ code: "too_big",
1364
+ maximum: items.length,
1365
+ inclusive: true,
1366
+ input,
1367
+ inst,
1368
+ origin: "array",
1369
+ });
1370
+ }
1291
1371
  }
1292
- let i = -1;
1293
- for (const item of items) {
1294
- i++;
1295
- if (i >= input.length)
1296
- if (i >= optStart)
1297
- continue;
1298
- const result = item._zod.run({
1299
- value: input[i],
1300
- issues: [],
1301
- }, ctx);
1302
- if (result instanceof Promise) {
1303
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1372
+ // Run every item in parallel, collecting results into an indexed
1373
+ // array. The post-processing in `handleTupleResults` walks them in
1374
+ // order so it can decide whether an absent optional-output error can
1375
+ // truncate the tail or must be reported to preserve required output.
1376
+ const itemResults = new Array(items.length);
1377
+ for (let i = 0; i < items.length; i++) {
1378
+ const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
1379
+ if (r instanceof Promise) {
1380
+ proms.push(r.then((rr) => {
1381
+ itemResults[i] = rr;
1382
+ }));
1304
1383
  }
1305
1384
  else {
1306
- handleTupleResult(result, payload, i);
1385
+ itemResults[i] = r;
1307
1386
  }
1308
1387
  }
1309
1388
  if (def.rest) {
1389
+ let i = items.length - 1;
1310
1390
  const rest = input.slice(items.length);
1311
1391
  for (const el of rest) {
1312
1392
  i++;
1313
- const result = def.rest._zod.run({
1314
- value: el,
1315
- issues: [],
1316
- }, ctx);
1393
+ const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
1317
1394
  if (result instanceof Promise) {
1318
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1395
+ proms.push(result.then((r) => handleTupleResult(r, payload, i)));
1319
1396
  }
1320
1397
  else {
1321
1398
  handleTupleResult(result, payload, i);
1322
1399
  }
1323
1400
  }
1324
1401
  }
1325
- if (proms.length)
1326
- return Promise.all(proms).then(() => payload);
1327
- return payload;
1402
+ if (proms.length) {
1403
+ return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
1404
+ }
1405
+ return handleTupleResults(itemResults, payload, items, input, optoutStart);
1328
1406
  };
1329
1407
  });
1408
+ function getTupleOptStart(items, key) {
1409
+ for (let i = items.length - 1; i >= 0; i--) {
1410
+ if (items[i]._zod[key] !== "optional")
1411
+ return i + 1;
1412
+ }
1413
+ return 0;
1414
+ }
1330
1415
  function handleTupleResult(result, final, index) {
1331
1416
  if (result.issues.length) {
1332
1417
  final.issues.push(...util.prefixIssues(index, result.issues));
1333
1418
  }
1334
1419
  final.value[index] = result.value;
1335
1420
  }
1421
+ function handleTupleResults(itemResults, final, items, input, optoutStart) {
1422
+ // Walk results in order. Mirror $ZodObject's swallow-on-absent-optional
1423
+ // rule, but only after `optoutStart`: the first index where the output
1424
+ // tuple tail can be absent.
1425
+ for (let i = 0; i < items.length; i++) {
1426
+ const r = itemResults[i];
1427
+ const isPresent = i < input.length;
1428
+ if (r.issues.length) {
1429
+ if (!isPresent && i >= optoutStart) {
1430
+ final.value.length = i;
1431
+ break;
1432
+ }
1433
+ final.issues.push(...util.prefixIssues(i, r.issues));
1434
+ }
1435
+ final.value[i] = r.value;
1436
+ }
1437
+ // Drop trailing slots that produced `undefined` for absent input
1438
+ // (the array analog of an absent optional key on an object). The
1439
+ // `i >= input.length` floor is critical: an explicit `undefined`
1440
+ // *inside* the input must be preserved even when the schema is
1441
+ // optional-out (e.g. `z.string().or(z.undefined())` accepting an
1442
+ // explicit undefined value).
1443
+ for (let i = final.value.length - 1; i >= input.length; i--) {
1444
+ if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
1445
+ final.value.length = i;
1446
+ }
1447
+ else {
1448
+ break;
1449
+ }
1450
+ }
1451
+ return final;
1452
+ }
1336
1453
  exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1337
1454
  exports.$ZodType.init(inst, def);
1338
1455
  inst._zod.parse = (payload, ctx) => {
@@ -1354,20 +1471,36 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1354
1471
  for (const key of values) {
1355
1472
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1356
1473
  recordKeys.add(typeof key === "number" ? key.toString() : key);
1474
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1475
+ if (keyResult instanceof Promise) {
1476
+ throw new Error("Async schemas not supported in object keys currently");
1477
+ }
1478
+ if (keyResult.issues.length) {
1479
+ payload.issues.push({
1480
+ code: "invalid_key",
1481
+ origin: "record",
1482
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1483
+ input: key,
1484
+ path: [key],
1485
+ inst,
1486
+ });
1487
+ continue;
1488
+ }
1489
+ const outKey = keyResult.value;
1357
1490
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1358
1491
  if (result instanceof Promise) {
1359
1492
  proms.push(result.then((result) => {
1360
1493
  if (result.issues.length) {
1361
1494
  payload.issues.push(...util.prefixIssues(key, result.issues));
1362
1495
  }
1363
- payload.value[key] = result.value;
1496
+ payload.value[outKey] = result.value;
1364
1497
  }));
1365
1498
  }
1366
1499
  else {
1367
1500
  if (result.issues.length) {
1368
1501
  payload.issues.push(...util.prefixIssues(key, result.issues));
1369
1502
  }
1370
- payload.value[key] = result.value;
1503
+ payload.value[outKey] = result.value;
1371
1504
  }
1372
1505
  }
1373
1506
  }
@@ -1389,9 +1522,12 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1389
1522
  }
1390
1523
  else {
1391
1524
  payload.value = {};
1525
+ // Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
1392
1526
  for (const key of Reflect.ownKeys(input)) {
1393
1527
  if (key === "__proto__")
1394
1528
  continue;
1529
+ if (!Object.prototype.propertyIsEnumerable.call(input, key))
1530
+ continue;
1395
1531
  let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1396
1532
  if (keyResult instanceof Promise) {
1397
1533
  throw new Error("Async schemas not supported in object keys currently");
@@ -2074,14 +2210,15 @@ exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
2074
2210
  });
2075
2211
  exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
2076
2212
  exports.$ZodType.init(inst, def);
2077
- // let _innerType!: any;
2078
- // util.defineLazy(def, "getter", () => {
2079
- // if (!_innerType) {
2080
- // _innerType = def.getter();
2081
- // }
2082
- // return () => _innerType;
2083
- // });
2084
- util.defineLazy(inst._zod, "innerType", () => def.getter());
2213
+ // Cache the resolved inner type on the shared `def` so all clones of this
2214
+ // lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance,
2215
+ // preserving identity for cycle detection on recursive schemas.
2216
+ util.defineLazy(inst._zod, "innerType", () => {
2217
+ const d = def;
2218
+ if (!d._cachedInner)
2219
+ d._cachedInner = def.getter();
2220
+ return d._cachedInner;
2221
+ });
2085
2222
  util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
2086
2223
  util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
2087
2224
  util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
@@ -23,7 +23,7 @@ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> ex
23
23
  export interface ParsePayload<T = unknown> {
24
24
  value: T;
25
25
  issues: errors.$ZodRawIssue[];
26
- /** A may to mark a whole payload as aborted. Used in codecs/pipes. */
26
+ /** A way to mark a whole payload as aborted. Used in codecs/pipes. */
27
27
  aborted?: boolean;
28
28
  }
29
29
  export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
@@ -182,13 +182,33 @@ export interface $ZodNanoID extends $ZodType {
182
182
  _zod: $ZodNanoIDInternals;
183
183
  }
184
184
  export declare const $ZodNanoID: core.$constructor<$ZodNanoID>;
185
+ /**
186
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
187
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
188
+ * See https://github.com/paralleldrive/cuid.
189
+ */
185
190
  export interface $ZodCUIDDef extends $ZodStringFormatDef<"cuid"> {
186
191
  }
192
+ /**
193
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
194
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
195
+ * See https://github.com/paralleldrive/cuid.
196
+ */
187
197
  export interface $ZodCUIDInternals extends $ZodStringFormatInternals<"cuid"> {
188
198
  }
199
+ /**
200
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
201
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
202
+ * See https://github.com/paralleldrive/cuid.
203
+ */
189
204
  export interface $ZodCUID extends $ZodType {
190
205
  _zod: $ZodCUIDInternals;
191
206
  }
207
+ /**
208
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
209
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
210
+ * See https://github.com/paralleldrive/cuid.
211
+ */
192
212
  export declare const $ZodCUID: core.$constructor<$ZodCUID>;
193
213
  export interface $ZodCUID2Def extends $ZodStringFormatDef<"cuid2"> {
194
214
  }
@@ -23,7 +23,7 @@ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> ex
23
23
  export interface ParsePayload<T = unknown> {
24
24
  value: T;
25
25
  issues: errors.$ZodRawIssue[];
26
- /** A may to mark a whole payload as aborted. Used in codecs/pipes. */
26
+ /** A way to mark a whole payload as aborted. Used in codecs/pipes. */
27
27
  aborted?: boolean;
28
28
  }
29
29
  export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
@@ -182,13 +182,33 @@ export interface $ZodNanoID extends $ZodType {
182
182
  _zod: $ZodNanoIDInternals;
183
183
  }
184
184
  export declare const $ZodNanoID: core.$constructor<$ZodNanoID>;
185
+ /**
186
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
187
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
188
+ * See https://github.com/paralleldrive/cuid.
189
+ */
185
190
  export interface $ZodCUIDDef extends $ZodStringFormatDef<"cuid"> {
186
191
  }
192
+ /**
193
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
194
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
195
+ * See https://github.com/paralleldrive/cuid.
196
+ */
187
197
  export interface $ZodCUIDInternals extends $ZodStringFormatInternals<"cuid"> {
188
198
  }
199
+ /**
200
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
201
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
202
+ * See https://github.com/paralleldrive/cuid.
203
+ */
189
204
  export interface $ZodCUID extends $ZodType {
190
205
  _zod: $ZodCUIDInternals;
191
206
  }
207
+ /**
208
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
209
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
210
+ * See https://github.com/paralleldrive/cuid.
211
+ */
192
212
  export declare const $ZodCUID: core.$constructor<$ZodCUID>;
193
213
  export interface $ZodCUID2Def extends $ZodStringFormatDef<"cuid2"> {
194
214
  }