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
@@ -8,6 +8,65 @@ import * as checks from "./checks.js";
8
8
  import * as iso from "./iso.js";
9
9
  import * as parse from "./parse.js";
10
10
 
11
+ // Lazy-bind builder methods.
12
+ //
13
+ // Builder methods (`.optional`, `.array`, `.refine`, ...) live as
14
+ // non-enumerable getters on each concrete schema constructor's
15
+ // prototype. On first access from an instance the getter allocates
16
+ // `fn.bind(this)` and caches it as an own property on that instance,
17
+ // so detached usage (`const m = schema.optional; m()`) still works
18
+ // and the per-instance allocation only happens for methods actually
19
+ // touched.
20
+ //
21
+ // One install per (prototype, group), memoized by `_installedGroups`.
22
+ const _installedGroups = /* @__PURE__ */ new WeakMap<object, Set<string>>();
23
+
24
+ /**
25
+ * Methods of `T` reshaped so each body has `this: T` and matches the
26
+ * declared (args, return) of the corresponding interface method. Allows
27
+ * us to type-check inline method-shorthand bodies against the
28
+ * `ZodType` / `_ZodString` / etc. interface declarations.
29
+ */
30
+ type _LazyMethodsOf<T> = Partial<{
31
+ [K in keyof T]: T[K] extends (...args: infer A) => infer R ? (this: T, ...args: A) => R : never;
32
+ }>;
33
+
34
+ function _installLazyMethods<T extends object>(inst: T, group: string, methods: _LazyMethodsOf<T>): void {
35
+ const proto = Object.getPrototypeOf(inst);
36
+ let installed = _installedGroups.get(proto);
37
+ if (!installed) {
38
+ installed = new Set();
39
+ _installedGroups.set(proto, installed);
40
+ }
41
+ if (installed.has(group)) return;
42
+ installed.add(group);
43
+ for (const key in methods) {
44
+ const fn = methods[key]!;
45
+ Object.defineProperty(proto, key, {
46
+ configurable: true,
47
+ enumerable: false,
48
+ get(this: any) {
49
+ const bound = fn.bind(this);
50
+ Object.defineProperty(this, key, {
51
+ configurable: true,
52
+ writable: true,
53
+ enumerable: true,
54
+ value: bound,
55
+ });
56
+ return bound;
57
+ },
58
+ set(this: any, v: unknown) {
59
+ Object.defineProperty(this, key, {
60
+ configurable: true,
61
+ writable: true,
62
+ enumerable: true,
63
+ value: v,
64
+ });
65
+ },
66
+ });
67
+ }
68
+ }
69
+
11
70
  ///////////////////////////////////////////
12
71
  ///////////////////////////////////////////
13
72
  //////////// ////////////
@@ -94,7 +153,8 @@ export interface ZodType<
94
153
  params?: string | core.$ZodCustomParams
95
154
  ): Ch extends (arg: any) => arg is infer R ? this & ZodType<R, core.input<this>> : this;
96
155
  superRefine(
97
- refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>
156
+ refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>,
157
+ params?: core.$ZodSuperRefineParams
98
158
  ): this;
99
159
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
100
160
 
@@ -167,38 +227,16 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
167
227
  inst.type = def.type;
168
228
  Object.defineProperty(inst, "_def", { value: def });
169
229
 
170
- // base methods
171
- inst.check = (...checks) => {
172
- return inst.clone(
173
- util.mergeDefs(def, {
174
- checks: [
175
- ...(def.checks ?? []),
176
- ...checks.map((ch) =>
177
- typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
178
- ),
179
- ],
180
- }),
181
- {
182
- parent: true,
183
- }
184
- );
185
- };
186
- inst.with = inst.check;
187
- inst.clone = (def, params) => core.clone(inst, def, params);
188
- inst.brand = () => inst as any;
189
- inst.register = ((reg: any, meta: any) => {
190
- reg.add(inst, meta);
191
- return inst;
192
- }) as any;
193
-
194
- // parsing
230
+ // Parse-family is intentionally kept as per-instance closures: these are
231
+ // the hot path AND the most-detached methods (`arr.map(schema.parse)`,
232
+ // `const { parse } = schema`, etc.). Eager closures here mean callers pay
233
+ // ~12 closure allocations per schema but get monomorphic call sites and
234
+ // detached usage that "just works".
195
235
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
196
236
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
197
237
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
198
238
  inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
199
239
  inst.spa = inst.safeParseAsync;
200
-
201
- // encoding/decoding
202
240
  inst.encode = (data, params) => parse.encode(inst, data, params);
203
241
  inst.decode = (data, params) => parse.decode(inst, data, params);
204
242
  inst.encodeAsync = async (data, params) => parse.encodeAsync(inst, data, params);
@@ -208,53 +246,122 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
208
246
  inst.safeEncodeAsync = async (data, params) => parse.safeEncodeAsync(inst, data, params);
209
247
  inst.safeDecodeAsync = async (data, params) => parse.safeDecodeAsync(inst, data, params);
210
248
 
211
- // refinements
212
- inst.refine = (check, params) => inst.check(refine(check, params)) as never;
213
- inst.superRefine = (refinement) => inst.check(superRefine(refinement));
214
- inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
215
-
216
- // wrappers
217
- inst.optional = () => optional(inst);
218
- inst.exactOptional = () => exactOptional(inst);
219
- inst.nullable = () => nullable(inst);
220
- inst.nullish = () => optional(nullable(inst));
221
- inst.nonoptional = (params) => nonoptional(inst, params);
222
- inst.array = () => array(inst);
223
- inst.or = (arg) => union([inst, arg]);
224
- inst.and = (arg) => intersection(inst, arg);
225
- inst.transform = (tx) => pipe(inst, transform(tx as any)) as never;
226
- inst.default = (def) => _default(inst, def);
227
- inst.prefault = (def) => prefault(inst, def);
228
- // inst.coalesce = (def, params) => coalesce(inst, def, params);
229
- inst.catch = (params) => _catch(inst, params);
230
- inst.pipe = (target) => pipe(inst, target);
231
- inst.readonly = () => readonly(inst);
232
-
233
- // meta
234
- inst.describe = (description) => {
235
- const cl = inst.clone();
236
- core.globalRegistry.add(cl, { description });
237
- return cl;
238
- };
249
+ // All builder methods are placed on the internal prototype as lazy-bind
250
+ // getters. On first access per-instance, a bound thunk is allocated and
251
+ // cached as an own property; subsequent accesses skip the getter. This
252
+ // means: no per-instance allocation for unused methods, full
253
+ // detachability preserved (`const m = schema.optional; m()` works), and
254
+ // shared underlying function references across all instances.
255
+ _installLazyMethods(inst, "ZodType", {
256
+ check(...chks) {
257
+ const def = this.def;
258
+ return this.clone(
259
+ util.mergeDefs(def, {
260
+ checks: [
261
+ ...(def.checks ?? []),
262
+ ...chks.map((ch) =>
263
+ typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
264
+ ),
265
+ ],
266
+ }),
267
+ { parent: true }
268
+ );
269
+ },
270
+ with(...chks) {
271
+ return this.check(...chks);
272
+ },
273
+ clone(def, params) {
274
+ return core.clone(this, def, params);
275
+ },
276
+ brand() {
277
+ return this;
278
+ },
279
+ register(reg, meta) {
280
+ reg.add(this, meta);
281
+ return this;
282
+ },
283
+ refine(check, params) {
284
+ return this.check(refine(check, params));
285
+ },
286
+ superRefine(refinement, params) {
287
+ return this.check(superRefine(refinement, params));
288
+ },
289
+ overwrite(fn) {
290
+ return this.check(checks.overwrite(fn));
291
+ },
292
+ optional() {
293
+ return optional(this);
294
+ },
295
+ exactOptional() {
296
+ return exactOptional(this);
297
+ },
298
+ nullable() {
299
+ return nullable(this);
300
+ },
301
+ nullish() {
302
+ return optional(nullable(this));
303
+ },
304
+ nonoptional(params) {
305
+ return nonoptional(this, params);
306
+ },
307
+ array() {
308
+ return array(this);
309
+ },
310
+ or(arg) {
311
+ return union([this, arg]);
312
+ },
313
+ and(arg) {
314
+ return intersection(this, arg);
315
+ },
316
+ transform(tx) {
317
+ return pipe(this, transform(tx));
318
+ },
319
+ default(d) {
320
+ return _default(this, d);
321
+ },
322
+ prefault(d) {
323
+ return prefault(this, d);
324
+ },
325
+ catch(params) {
326
+ return _catch(this, params);
327
+ },
328
+ pipe(target) {
329
+ return pipe(this, target);
330
+ },
331
+ readonly() {
332
+ return readonly(this);
333
+ },
334
+ describe(description) {
335
+ const cl = this.clone();
336
+ core.globalRegistry.add(cl, { description });
337
+ return cl;
338
+ },
339
+ meta(...args: any[]): any {
340
+ // overloaded: meta() returns the registered metadata, meta(data)
341
+ // returns a clone with `data` registered. The mapped type picks
342
+ // up the second overload, so we accept variadic any-args and
343
+ // return `any` to satisfy both at runtime.
344
+ if (args.length === 0) return core.globalRegistry.get(this);
345
+ const cl = this.clone();
346
+ core.globalRegistry.add(cl, args[0]);
347
+ return cl;
348
+ },
349
+ isOptional() {
350
+ return this.safeParse(undefined).success;
351
+ },
352
+ isNullable() {
353
+ return this.safeParse(null).success;
354
+ },
355
+ apply(fn) {
356
+ return fn(this);
357
+ },
358
+ });
239
359
  Object.defineProperty(inst, "description", {
240
360
  get() {
241
361
  return core.globalRegistry.get(inst)?.description;
242
362
  },
243
363
  configurable: true,
244
364
  });
245
- inst.meta = (...args: any) => {
246
- if (args.length === 0) {
247
- return core.globalRegistry.get(inst);
248
- }
249
- const cl = inst.clone();
250
- core.globalRegistry.add(cl, args[0]);
251
- return cl as any;
252
- };
253
-
254
- // helpers
255
- inst.isOptional = () => inst.safeParse(undefined).success;
256
- inst.isNullable = () => inst.safeParse(null).success;
257
- inst.apply = (fn) => fn(inst);
258
365
  return inst;
259
366
  });
260
367
 
@@ -297,24 +404,53 @@ export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$con
297
404
  inst.minLength = bag.minimum ?? null;
298
405
  inst.maxLength = bag.maximum ?? null;
299
406
 
300
- // validations
301
- inst.regex = (...args) => inst.check(checks.regex(...args));
302
- inst.includes = (...args) => inst.check(checks.includes(...args));
303
- inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
304
- inst.endsWith = (...args) => inst.check(checks.endsWith(...args));
305
- inst.min = (...args) => inst.check(checks.minLength(...args));
306
- inst.max = (...args) => inst.check(checks.maxLength(...args));
307
- inst.length = (...args) => inst.check(checks.length(...args));
308
- inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args));
309
- inst.lowercase = (params) => inst.check(checks.lowercase(params));
310
- inst.uppercase = (params) => inst.check(checks.uppercase(params));
311
-
312
- // transforms
313
- inst.trim = () => inst.check(checks.trim());
314
- inst.normalize = (...args) => inst.check(checks.normalize(...args));
315
- inst.toLowerCase = () => inst.check(checks.toLowerCase());
316
- inst.toUpperCase = () => inst.check(checks.toUpperCase());
317
- inst.slugify = () => inst.check(checks.slugify());
407
+ _installLazyMethods(inst, "_ZodString", {
408
+ regex(...args) {
409
+ return this.check((checks.regex as any)(...args));
410
+ },
411
+ includes(...args) {
412
+ return this.check((checks.includes as any)(...args));
413
+ },
414
+ startsWith(...args) {
415
+ return this.check((checks.startsWith as any)(...args));
416
+ },
417
+ endsWith(...args) {
418
+ return this.check((checks.endsWith as any)(...args));
419
+ },
420
+ min(...args) {
421
+ return this.check((checks.minLength as any)(...args));
422
+ },
423
+ max(...args) {
424
+ return this.check((checks.maxLength as any)(...args));
425
+ },
426
+ length(...args) {
427
+ return this.check((checks.length as any)(...args));
428
+ },
429
+ nonempty(...args) {
430
+ return this.check((checks.minLength as any)(1, ...args));
431
+ },
432
+ lowercase(params) {
433
+ return this.check(checks.lowercase(params));
434
+ },
435
+ uppercase(params) {
436
+ return this.check(checks.uppercase(params));
437
+ },
438
+ trim() {
439
+ return this.check(checks.trim());
440
+ },
441
+ normalize(...args) {
442
+ return this.check(checks.normalize(...args));
443
+ },
444
+ toLowerCase() {
445
+ return this.check(checks.toLowerCase());
446
+ },
447
+ toUpperCase() {
448
+ return this.check(checks.toUpperCase());
449
+ },
450
+ slugify() {
451
+ return this.check(checks.slugify());
452
+ },
453
+ });
318
454
  });
319
455
 
320
456
  export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
@@ -342,7 +478,11 @@ export interface ZodString extends _ZodString<core.$ZodStringInternals<string>>
342
478
  nanoid(params?: string | core.$ZodCheckNanoIDParams): this;
343
479
  /** @deprecated Use `z.guid()` instead. */
344
480
  guid(params?: string | core.$ZodCheckGUIDParams): this;
345
- /** @deprecated Use `z.cuid()` instead. */
481
+ /**
482
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
483
+ * (timestamps embedded in the id). Use `z.cuid2()` instead.
484
+ * See https://github.com/paralleldrive/cuid.
485
+ */
346
486
  cuid(params?: string | core.$ZodCheckCUIDParams): this;
347
487
  /** @deprecated Use `z.cuid2()` instead. */
348
488
  cuid2(params?: string | core.$ZodCheckCUID2Params): this;
@@ -428,7 +568,7 @@ export const ZodString: core.$constructor<ZodString> = /*@__PURE__*/ core.$const
428
568
  export function string(params?: string | core.$ZodStringParams): ZodString;
429
569
  export function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
430
570
  export function string(params?: string | core.$ZodStringParams): ZodString {
431
- return core._string(ZodString, params) as any;
571
+ return core._string(ZodString, params);
432
572
  }
433
573
 
434
574
  // ZodStringFormat
@@ -516,7 +656,7 @@ export function url(params?: string | core.$ZodURLParams): ZodURL {
516
656
 
517
657
  export function httpUrl(params?: string | Omit<core.$ZodURLParams, "protocol" | "hostname">): ZodURL {
518
658
  return core._url(ZodURL, {
519
- protocol: /^https?$/,
659
+ protocol: core.regexes.httpProtocol,
520
660
  hostname: core.regexes.domain,
521
661
  ...util.normalizeParams(params),
522
662
  });
@@ -551,15 +691,32 @@ export function nanoid(params?: string | core.$ZodNanoIDParams): ZodNanoID {
551
691
  }
552
692
 
553
693
  // ZodCUID
694
+ /**
695
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
696
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
697
+ * See https://github.com/paralleldrive/cuid.
698
+ */
554
699
  export interface ZodCUID extends ZodStringFormat<"cuid"> {
555
700
  _zod: core.$ZodCUIDInternals;
556
701
  }
702
+ /**
703
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
704
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
705
+ * See https://github.com/paralleldrive/cuid.
706
+ */
557
707
  export const ZodCUID: core.$constructor<ZodCUID> = /*@__PURE__*/ core.$constructor("ZodCUID", (inst, def) => {
558
708
  // ZodStringFormat.init(inst, def);
559
709
  core.$ZodCUID.init(inst, def);
560
710
  ZodStringFormat.init(inst, def);
561
711
  });
562
712
 
713
+ /**
714
+ * Validates a CUID v1 string.
715
+ *
716
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
717
+ * (timestamps embedded in the id). Use {@link cuid2 | `z.cuid2()`} instead.
718
+ * See https://github.com/paralleldrive/cuid.
719
+ */
563
720
  export function cuid(params?: string | core.$ZodCUIDParams): ZodCUID {
564
721
  return core._cuid(ZodCUID, params);
565
722
  }
@@ -845,23 +1002,53 @@ export const ZodNumber: core.$constructor<ZodNumber> = /*@__PURE__*/ core.$const
845
1002
 
846
1003
  inst._zod.processJSONSchema = (ctx, json, params) => processors.numberProcessor(inst, ctx, json, params);
847
1004
 
848
- inst.gt = (value, params) => inst.check(checks.gt(value, params));
849
- inst.gte = (value, params) => inst.check(checks.gte(value, params));
850
- inst.min = (value, params) => inst.check(checks.gte(value, params));
851
- inst.lt = (value, params) => inst.check(checks.lt(value, params));
852
- inst.lte = (value, params) => inst.check(checks.lte(value, params));
853
- inst.max = (value, params) => inst.check(checks.lte(value, params));
854
- inst.int = (params) => inst.check(int(params));
855
- inst.safe = (params) => inst.check(int(params));
856
- inst.positive = (params) => inst.check(checks.gt(0, params));
857
- inst.nonnegative = (params) => inst.check(checks.gte(0, params));
858
- inst.negative = (params) => inst.check(checks.lt(0, params));
859
- inst.nonpositive = (params) => inst.check(checks.lte(0, params));
860
- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
861
- inst.step = (value, params) => inst.check(checks.multipleOf(value, params));
862
-
863
- // inst.finite = (params) => inst.check(core.finite(params));
864
- inst.finite = () => inst;
1005
+ _installLazyMethods(inst, "ZodNumber", {
1006
+ gt(value, params) {
1007
+ return this.check(checks.gt(value, params));
1008
+ },
1009
+ gte(value, params) {
1010
+ return this.check(checks.gte(value, params));
1011
+ },
1012
+ min(value, params) {
1013
+ return this.check(checks.gte(value, params));
1014
+ },
1015
+ lt(value, params) {
1016
+ return this.check(checks.lt(value, params));
1017
+ },
1018
+ lte(value, params) {
1019
+ return this.check(checks.lte(value, params));
1020
+ },
1021
+ max(value, params) {
1022
+ return this.check(checks.lte(value, params));
1023
+ },
1024
+ int(params) {
1025
+ return this.check(int(params));
1026
+ },
1027
+ safe(params) {
1028
+ return this.check(int(params));
1029
+ },
1030
+ positive(params) {
1031
+ return this.check(checks.gt(0, params));
1032
+ },
1033
+ nonnegative(params) {
1034
+ return this.check(checks.gte(0, params));
1035
+ },
1036
+ negative(params) {
1037
+ return this.check(checks.lt(0, params));
1038
+ },
1039
+ nonpositive(params) {
1040
+ return this.check(checks.lte(0, params));
1041
+ },
1042
+ multipleOf(value, params) {
1043
+ return this.check(checks.multipleOf(value, params));
1044
+ },
1045
+ step(value, params) {
1046
+ return this.check(checks.multipleOf(value, params));
1047
+ },
1048
+ finite() {
1049
+ return this;
1050
+ },
1051
+ });
865
1052
 
866
1053
  const bag = inst._zod.bag;
867
1054
  inst.minValue =
@@ -874,7 +1061,7 @@ export const ZodNumber: core.$constructor<ZodNumber> = /*@__PURE__*/ core.$const
874
1061
  });
875
1062
 
876
1063
  export function number(params?: string | core.$ZodNumberParams): ZodNumber {
877
- return core._number(ZodNumber, params) as any;
1064
+ return core._number(ZodNumber, params);
878
1065
  }
879
1066
 
880
1067
  // ZodNumberFormat
@@ -929,7 +1116,7 @@ export const ZodBoolean: core.$constructor<ZodBoolean> = /*@__PURE__*/ core.$con
929
1116
  });
930
1117
 
931
1118
  export function boolean(params?: string | core.$ZodBooleanParams): ZodBoolean {
932
- return core._boolean(ZodBoolean, params) as any;
1119
+ return core._boolean(ZodBoolean, params);
933
1120
  }
934
1121
 
935
1122
  // bigint
@@ -980,7 +1167,7 @@ export const ZodBigInt: core.$constructor<ZodBigInt> = /*@__PURE__*/ core.$const
980
1167
  });
981
1168
 
982
1169
  export function bigint(params?: string | core.$ZodBigIntParams): ZodBigInt {
983
- return core._bigint(ZodBigInt, params) as any;
1170
+ return core._bigint(ZodBigInt, params);
984
1171
  }
985
1172
  // bigint formats
986
1173
 
@@ -1143,13 +1330,24 @@ export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constru
1143
1330
  ZodType.init(inst, def);
1144
1331
  inst._zod.processJSONSchema = (ctx, json, params) => processors.arrayProcessor(inst, ctx, json, params);
1145
1332
 
1146
- inst.element = def.element as any;
1147
- inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
1148
- inst.nonempty = (params) => inst.check(checks.minLength(1, params));
1149
- inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
1150
- inst.length = (len, params) => inst.check(checks.length(len, params));
1151
-
1152
- inst.unwrap = () => inst.element;
1333
+ inst.element = def.element;
1334
+ _installLazyMethods(inst, "ZodArray", {
1335
+ min(n, params) {
1336
+ return this.check(checks.minLength(n, params));
1337
+ },
1338
+ nonempty(params) {
1339
+ return this.check(checks.minLength(1, params));
1340
+ },
1341
+ max(n, params) {
1342
+ return this.check(checks.maxLength(n, params));
1343
+ },
1344
+ length(n, params) {
1345
+ return this.check(checks.length(n, params));
1346
+ },
1347
+ unwrap() {
1348
+ return this.element;
1349
+ },
1350
+ });
1153
1351
  });
1154
1352
 
1155
1353
  export function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T> {
@@ -1198,11 +1396,11 @@ export interface ZodObject<
1198
1396
  /** This is the default behavior. This method call is likely unnecessary. */
1199
1397
  strip(): ZodObject<Shape, core.$strip>;
1200
1398
 
1201
- extend<U extends core.$ZodLooseShape>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
1399
+ extend<U extends core.$ZodLooseShape>(shape: U): ZodObject<util.Extend<Shape, util.Writeable<U>>, Config>;
1202
1400
 
1203
1401
  safeExtend<U extends core.$ZodLooseShape>(
1204
1402
  shape: SafeExtendShape<Shape, U> & Partial<Record<keyof Shape, core.SomeType>>
1205
- ): ZodObject<util.Extend<Shape, U>, Config>;
1403
+ ): ZodObject<util.Extend<Shape, util.Writeable<U>>, Config>;
1206
1404
 
1207
1405
  /**
1208
1406
  * @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
@@ -1219,7 +1417,7 @@ export interface ZodObject<
1219
1417
 
1220
1418
  partial(): ZodObject<
1221
1419
  {
1222
- [k in keyof Shape]: ZodOptional<Shape[k]>;
1420
+ -readonly [k in keyof Shape]: ZodOptional<Shape[k]>;
1223
1421
  },
1224
1422
  Config
1225
1423
  >;
@@ -1227,7 +1425,7 @@ export interface ZodObject<
1227
1425
  mask: M & Record<Exclude<keyof M, keyof Shape>, never>
1228
1426
  ): ZodObject<
1229
1427
  {
1230
- [k in keyof Shape]: k extends keyof M
1428
+ -readonly [k in keyof Shape]: k extends keyof M
1231
1429
  ? // Shape[k] extends OptionalInSchema
1232
1430
  // ? Shape[k]
1233
1431
  // :
@@ -1240,7 +1438,7 @@ export interface ZodObject<
1240
1438
  // required
1241
1439
  required(): ZodObject<
1242
1440
  {
1243
- [k in keyof Shape]: ZodNonOptional<Shape[k]>;
1441
+ -readonly [k in keyof Shape]: ZodNonOptional<Shape[k]>;
1244
1442
  },
1245
1443
  Config
1246
1444
  >;
@@ -1248,7 +1446,7 @@ export interface ZodObject<
1248
1446
  mask: M & Record<Exclude<keyof M, keyof Shape>, never>
1249
1447
  ): ZodObject<
1250
1448
  {
1251
- [k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
1449
+ -readonly [k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
1252
1450
  },
1253
1451
  Config
1254
1452
  >;
@@ -1263,24 +1461,47 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
1263
1461
  return def.shape;
1264
1462
  });
1265
1463
 
1266
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
1267
- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall as any as core.$ZodType }) as any;
1268
- inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
1269
- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
1270
- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
1271
- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
1272
-
1273
- inst.extend = (incoming: any) => {
1274
- return util.extend(inst, incoming);
1275
- };
1276
- inst.safeExtend = (incoming: any) => {
1277
- return util.safeExtend(inst, incoming);
1278
- };
1279
- inst.merge = (other) => util.merge(inst, other);
1280
- inst.pick = (mask) => util.pick(inst, mask);
1281
- inst.omit = (mask) => util.omit(inst, mask);
1282
- inst.partial = (...args: any[]) => util.partial(ZodOptional, inst, args[0] as object);
1283
- inst.required = (...args: any[]) => util.required(ZodNonOptional, inst, args[0] as object);
1464
+ _installLazyMethods(inst, "ZodObject", {
1465
+ keyof() {
1466
+ return _enum(Object.keys(this._zod.def.shape));
1467
+ },
1468
+ catchall(catchall) {
1469
+ return this.clone({ ...this._zod.def, catchall: catchall as any });
1470
+ },
1471
+ passthrough() {
1472
+ return this.clone({ ...this._zod.def, catchall: unknown() });
1473
+ },
1474
+ loose() {
1475
+ return this.clone({ ...this._zod.def, catchall: unknown() });
1476
+ },
1477
+ strict() {
1478
+ return this.clone({ ...this._zod.def, catchall: never() });
1479
+ },
1480
+ strip() {
1481
+ return this.clone({ ...this._zod.def, catchall: undefined });
1482
+ },
1483
+ extend(incoming) {
1484
+ return util.extend(this, incoming);
1485
+ },
1486
+ safeExtend(incoming) {
1487
+ return util.safeExtend(this, incoming);
1488
+ },
1489
+ merge(other) {
1490
+ return util.merge(this, other);
1491
+ },
1492
+ pick(mask) {
1493
+ return util.pick(this, mask);
1494
+ },
1495
+ omit(mask) {
1496
+ return util.omit(this, mask);
1497
+ },
1498
+ partial(...args) {
1499
+ return util.partial(ZodOptional, this, args[0]);
1500
+ },
1501
+ required(...args) {
1502
+ return util.required(ZodNonOptional, this, args[0]);
1503
+ },
1504
+ });
1284
1505
  });
1285
1506
 
1286
1507
  export function object<T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>>(
@@ -1300,7 +1521,7 @@ export function object<T extends core.$ZodLooseShape = Partial<Record<never, cor
1300
1521
  export function strictObject<T extends core.$ZodLooseShape>(
1301
1522
  shape: T,
1302
1523
  params?: string | core.$ZodObjectParams
1303
- ): ZodObject<T, core.$strict> {
1524
+ ): ZodObject<util.Writeable<T>, core.$strict> {
1304
1525
  return new ZodObject({
1305
1526
  type: "object",
1306
1527
  shape,
@@ -1314,7 +1535,7 @@ export function strictObject<T extends core.$ZodLooseShape>(
1314
1535
  export function looseObject<T extends core.$ZodLooseShape>(
1315
1536
  shape: T,
1316
1537
  params?: string | core.$ZodObjectParams
1317
- ): ZodObject<T, core.$loose> {
1538
+ ): ZodObject<util.Writeable<T>, core.$loose> {
1318
1539
  return new ZodObject({
1319
1540
  type: "object",
1320
1541
  shape,
@@ -1508,6 +1729,15 @@ export function record<Key extends core.$ZodRecordKey, Value extends core.SomeTy
1508
1729
  valueType: Value,
1509
1730
  params?: string | core.$ZodRecordParams
1510
1731
  ): ZodRecord<Key, Value> {
1732
+ // v3-compat: z.record(valueType, params?) — defaults keyType to z.string()
1733
+ if (!valueType || !(valueType as any)._zod) {
1734
+ return new ZodRecord({
1735
+ type: "record",
1736
+ keyType: string() as any,
1737
+ valueType: keyType as any as core.$ZodType,
1738
+ ...util.normalizeParams(valueType as string | core.$ZodRecordParams | undefined),
1739
+ }) as any;
1740
+ }
1511
1741
  return new ZodRecord({
1512
1742
  type: "record",
1513
1743
  keyType,
@@ -1702,7 +1932,7 @@ export function nativeEnum<T extends util.EnumLike>(entries: T, params?: string
1702
1932
  type: "enum",
1703
1933
  entries,
1704
1934
  ...util.normalizeParams(params),
1705
- }) as any as ZodEnum<T>;
1935
+ }) as ZodEnum<T>;
1706
1936
  }
1707
1937
 
1708
1938
  // ZodLiteral
@@ -1814,7 +2044,7 @@ export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.
1814
2044
  );
1815
2045
 
1816
2046
  export function transform<I = unknown, O = I>(
1817
- fn: (input: I, ctx: core.ParsePayload) => O
2047
+ fn: (input: I, ctx: core.$RefinementCtx) => O
1818
2048
  ): ZodTransform<Awaited<O>, I> {
1819
2049
  return new ZodTransform({
1820
2050
  type: "transform",
@@ -2120,6 +2350,17 @@ export function codec<const A extends core.SomeType, B extends core.SomeType = c
2120
2350
  }) as any;
2121
2351
  }
2122
2352
 
2353
+ export function invertCodec<A extends core.SomeType, B extends core.SomeType>(codec: ZodCodec<A, B>): ZodCodec<B, A> {
2354
+ const def = codec._zod.def;
2355
+ return new ZodCodec({
2356
+ type: "pipe",
2357
+ in: def.out as any,
2358
+ out: def.in as any,
2359
+ transform: def.reverseTransform as any,
2360
+ reverseTransform: def.transform as any,
2361
+ }) as any;
2362
+ }
2363
+
2123
2364
  // ZodReadonly
2124
2365
  export interface ZodReadonly<T extends core.SomeType = core.$ZodType>
2125
2366
  extends _ZodType<core.$ZodReadonlyInternals<T>>,
@@ -2321,9 +2562,10 @@ export function refine<T>(
2321
2562
 
2322
2563
  // superRefine
2323
2564
  export function superRefine<T>(
2324
- fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>
2565
+ fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>,
2566
+ params?: core.$ZodSuperRefineParams
2325
2567
  ): core.$ZodCheck<T> {
2326
- return core._superRefine(fn);
2568
+ return core._superRefine(fn, params);
2327
2569
  }
2328
2570
 
2329
2571
  // Re-export describe and meta from core
@@ -2400,7 +2642,6 @@ export function json(params?: string | core.$ZodCustomParams): ZodJSONSchema {
2400
2642
 
2401
2643
  // preprocess
2402
2644
 
2403
- // /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
2404
2645
  export function preprocess<A, U extends core.SomeType, B = unknown>(
2405
2646
  fn: (arg: B, ctx: core.$RefinementCtx) => A,
2406
2647
  schema: U