@openclaw/feishu 2026.9.3 → 2026.9.5

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 (743) hide show
  1. package/assets/activity.svg +3 -0
  2. package/assets/icon.png +0 -0
  3. package/dist/{accounts-cCMNFBKg.js → .setup/accounts-DmU0xYPx.mjs} +1 -1
  4. package/dist/{app-registration-BI99e_JI.js → .setup/app-registration-Bv4mvauR.mjs} +1 -1
  5. package/dist/{channel-DrAqd5ED.js → .setup/channel-C1KrXXJa.mjs} +100 -99
  6. package/dist/{channel.runtime-BZzuDlOS.js → .setup/channel.runtime-Bizuv7WZ.mjs} +32 -18
  7. package/dist/{chat-BZSnEtgb.js → .setup/chat-dWJYS63b.mjs} +89 -88
  8. package/dist/{client-DMbIL3UH.js → .setup/client-DCwNVFZg.mjs} +128 -11
  9. package/dist/{conversation-id-VYgGQ-GX.js → .setup/conversation-id-H-lUayji.mjs} +49 -14
  10. package/dist/{monitor-DSGtOPio.js → .setup/monitor-C69OLzgO.mjs} +4 -4
  11. package/dist/{monitor.account-BRDUsS_q.js → .setup/monitor.account-zwHb3HKM.mjs} +76 -52
  12. package/dist/{probe-D_SatdZl.js → .setup/probe-bdidyhAn.mjs} +2 -2
  13. package/dist/{reply-delivery-result-BXEmtKpf.js → .setup/reply-delivery-result-DFjxGLgX.mjs} +162 -163
  14. package/dist/.setup/runtime-setter-api-CG-RC4_r.mjs +3 -0
  15. package/dist/.setup/secret-contract-api-jmCkqVLc.mjs +3 -0
  16. package/dist/{security-audit-DKfR4Cv3.js → .setup/security-audit-CmiKKfU-.mjs} +1 -1
  17. package/dist/{session-conversation-DFCIvQK-.js → .setup/session-conversation-ZC6TC1zk.mjs} +1 -1
  18. package/dist/.setup/setup-api-CTRwX09n.mjs +3 -0
  19. package/dist/{subagent-hooks-Buadpie_.js → .setup/subagent-hooks-BBfF1hZk.mjs} +3 -19
  20. package/dist/api.js +125 -121
  21. package/dist/channel-plugin-api.js +1 -1
  22. package/dist/contract-api.js +3 -3
  23. package/dist/doctor-contract-api.js +1 -1
  24. package/dist/runtime-api.js +1 -1
  25. package/dist/runtime-setter-api.js +1 -1
  26. package/dist/secret-contract-api.js +1 -1
  27. package/dist/security-contract-api.js +1 -1
  28. package/dist/session-binding-contract-api.js +1 -1
  29. package/dist/session-key-api.js +1 -1
  30. package/dist/setup-api.js +1 -1
  31. package/dist/setup-entry.js +4 -3
  32. package/dist/subagent-hooks-api.js +1 -1
  33. package/node_modules/@larksuiteoapi/node-sdk/es/index.js +199 -35
  34. package/node_modules/@larksuiteoapi/node-sdk/lib/index.js +199 -35
  35. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/CHANGELOG.md +62 -0
  36. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/README.md +233 -5
  37. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.js +387 -89
  38. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js +3 -3
  39. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js.map +1 -1
  40. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/browser/axios.cjs +458 -98
  41. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.js +458 -98
  42. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js +2 -2
  43. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  44. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/node/axios.cjs +568 -116
  45. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.cts +4 -0
  46. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.ts +4 -0
  47. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/fetch.js +64 -11
  48. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/http.js +134 -50
  49. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/xhr.js +52 -3
  50. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/Axios.js +19 -14
  51. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/InterceptorManager.js +107 -8
  52. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/buildFullPath.js +1 -13
  53. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/dispatchRequest.js +8 -2
  54. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/mergeConfig.js +1 -1
  55. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/methodList.js +17 -0
  56. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/defaults/index.js +2 -1
  57. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/env/data.js +1 -1
  58. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/Http2Sessions.js +2 -0
  59. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/HttpStatusCode.js +11 -1
  60. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/fromDataURI.js +5 -4
  61. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
  62. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/progressEventReducer.js +1 -1
  63. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/resolveConfig.js +4 -2
  64. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/shouldBypassProxy.js +182 -6
  65. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/throttle.js +3 -2
  66. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/toFormData.js +14 -21
  67. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/utils.js +134 -13
  68. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/package.json +1 -1
  69. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/README.md +24 -17
  70. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/light/protobuf.js +124 -14
  71. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
  72. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
  73. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
  74. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/minimal/protobuf.js +63 -9
  75. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
  76. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
  77. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
  78. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/protobuf.js +133 -18
  79. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/protobuf.js.map +1 -1
  80. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/protobuf.min.js +3 -3
  81. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
  82. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/ext/descriptor.generated.d.ts +7 -0
  83. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/ext/descriptor.js +24 -0
  84. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/ext/protojson.js +14 -4
  85. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/ext/textformat.js +8 -4
  86. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/google/protobuf/descriptor.json +20 -1
  87. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/google/protobuf/descriptor.proto +14 -1
  88. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/index.d.ts +12 -0
  89. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/package.json +1 -1
  90. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/decoder.js +31 -2
  91. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/enum.js +10 -0
  92. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/object.js +5 -2
  93. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/parse.js +9 -4
  94. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/reader.js +61 -7
  95. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/type.js +10 -0
  96. package/node_modules/@larksuiteoapi/node-sdk/node_modules/protobufjs/src/wrappers.js +5 -1
  97. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  98. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/CHANGELOG.md +15 -0
  99. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/README.md +19 -1
  100. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/dist/qs.js +21 -21
  101. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/eslint.config.mjs +1 -1
  102. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/parse.js +3 -4
  103. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/stringify.js +23 -8
  104. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/utils.js +10 -3
  105. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/package.json +4 -4
  106. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/parse.js +192 -3
  107. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/stringify.js +317 -0
  108. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/utils.js +12 -0
  109. package/node_modules/@larksuiteoapi/node-sdk/package.json +1 -1
  110. package/node_modules/@larksuiteoapi/node-sdk/types/index.d.ts +35 -0
  111. package/node_modules/typebox/build/compile/validator.d.mts +1 -1
  112. package/node_modules/typebox/build/compile/validator.mjs +1 -1
  113. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +7 -5
  114. package/node_modules/typebox/build/format/iri.mjs +5 -1
  115. package/node_modules/typebox/build/guard/emit.mjs +2 -4
  116. package/node_modules/typebox/build/guard/guard.mjs +6 -18
  117. package/node_modules/typebox/build/guard/string.mjs +16 -24
  118. package/node_modules/typebox/build/schema/build.mjs +2 -2
  119. package/node_modules/typebox/build/schema/check.mjs +1 -1
  120. package/node_modules/typebox/build/schema/compile.d.mts +3 -2
  121. package/node_modules/typebox/build/schema/compile.mjs +8 -8
  122. package/node_modules/typebox/build/schema/engine/_context.d.mts +6 -7
  123. package/node_modules/typebox/build/schema/engine/_context.mjs +23 -15
  124. package/node_modules/typebox/build/schema/engine/_functions.d.mts +2 -2
  125. package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -1
  126. package/node_modules/typebox/build/schema/engine/_reducer.d.mts +3 -3
  127. package/node_modules/typebox/build/schema/engine/_refine.d.mts +5 -5
  128. package/node_modules/typebox/build/schema/engine/_refine.mjs +4 -7
  129. package/node_modules/typebox/build/schema/engine/_stack.d.mts +34 -16
  130. package/node_modules/typebox/build/schema/engine/_stack.mjs +148 -104
  131. package/node_modules/typebox/build/schema/engine/additionalItems.d.mts +4 -4
  132. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +8 -8
  133. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +26 -18
  134. package/node_modules/typebox/build/schema/engine/allOf.d.mts +4 -4
  135. package/node_modules/typebox/build/schema/engine/allOf.mjs +3 -3
  136. package/node_modules/typebox/build/schema/engine/anyOf.d.mts +4 -4
  137. package/node_modules/typebox/build/schema/engine/anyOf.mjs +5 -10
  138. package/node_modules/typebox/build/schema/engine/boolean.d.mts +4 -4
  139. package/node_modules/typebox/build/schema/engine/boolean.mjs +2 -6
  140. package/node_modules/typebox/build/schema/engine/const.d.mts +4 -4
  141. package/node_modules/typebox/build/schema/engine/const.mjs +2 -6
  142. package/node_modules/typebox/build/schema/engine/contains.d.mts +4 -4
  143. package/node_modules/typebox/build/schema/engine/contains.mjs +2 -6
  144. package/node_modules/typebox/build/schema/engine/dependencies.d.mts +4 -4
  145. package/node_modules/typebox/build/schema/engine/dependencies.mjs +3 -6
  146. package/node_modules/typebox/build/schema/engine/dependentRequired.d.mts +4 -4
  147. package/node_modules/typebox/build/schema/engine/dependentRequired.mjs +2 -6
  148. package/node_modules/typebox/build/schema/engine/dependentSchemas.d.mts +4 -4
  149. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +4 -4
  150. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +11 -7
  151. package/node_modules/typebox/build/schema/engine/enum.d.mts +4 -4
  152. package/node_modules/typebox/build/schema/engine/enum.mjs +2 -6
  153. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.d.mts +4 -4
  154. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.mjs +2 -6
  155. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.d.mts +4 -4
  156. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.mjs +2 -6
  157. package/node_modules/typebox/build/schema/engine/format.d.mts +4 -4
  158. package/node_modules/typebox/build/schema/engine/format.mjs +2 -6
  159. package/node_modules/typebox/build/schema/engine/if.d.mts +4 -4
  160. package/node_modules/typebox/build/schema/engine/if.mjs +7 -15
  161. package/node_modules/typebox/build/schema/engine/items.d.mts +4 -4
  162. package/node_modules/typebox/build/schema/engine/items.mjs +1 -1
  163. package/node_modules/typebox/build/schema/engine/maxContains.d.mts +4 -4
  164. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -6
  165. package/node_modules/typebox/build/schema/engine/maxItems.d.mts +4 -4
  166. package/node_modules/typebox/build/schema/engine/maxItems.mjs +2 -6
  167. package/node_modules/typebox/build/schema/engine/maxLength.d.mts +4 -4
  168. package/node_modules/typebox/build/schema/engine/maxLength.mjs +2 -6
  169. package/node_modules/typebox/build/schema/engine/maxProperties.d.mts +4 -4
  170. package/node_modules/typebox/build/schema/engine/maxProperties.mjs +2 -6
  171. package/node_modules/typebox/build/schema/engine/maximum.d.mts +4 -4
  172. package/node_modules/typebox/build/schema/engine/maximum.mjs +2 -6
  173. package/node_modules/typebox/build/schema/engine/minContains.d.mts +4 -4
  174. package/node_modules/typebox/build/schema/engine/minContains.mjs +2 -6
  175. package/node_modules/typebox/build/schema/engine/minItems.d.mts +5 -5
  176. package/node_modules/typebox/build/schema/engine/minItems.mjs +2 -6
  177. package/node_modules/typebox/build/schema/engine/minLength.d.mts +4 -4
  178. package/node_modules/typebox/build/schema/engine/minLength.mjs +2 -6
  179. package/node_modules/typebox/build/schema/engine/minProperties.d.mts +4 -4
  180. package/node_modules/typebox/build/schema/engine/minProperties.mjs +2 -6
  181. package/node_modules/typebox/build/schema/engine/minimum.d.mts +4 -4
  182. package/node_modules/typebox/build/schema/engine/minimum.mjs +2 -6
  183. package/node_modules/typebox/build/schema/engine/multipleOf.d.mts +4 -4
  184. package/node_modules/typebox/build/schema/engine/multipleOf.mjs +2 -6
  185. package/node_modules/typebox/build/schema/engine/not.d.mts +4 -4
  186. package/node_modules/typebox/build/schema/engine/not.mjs +4 -8
  187. package/node_modules/typebox/build/schema/engine/oneOf.d.mts +4 -4
  188. package/node_modules/typebox/build/schema/engine/oneOf.mjs +6 -11
  189. package/node_modules/typebox/build/schema/engine/pattern.d.mts +4 -4
  190. package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -7
  191. package/node_modules/typebox/build/schema/engine/patternProperties.d.mts +4 -4
  192. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +1 -1
  193. package/node_modules/typebox/build/schema/engine/prefixItems.d.mts +4 -4
  194. package/node_modules/typebox/build/schema/engine/prefixItems.mjs +1 -1
  195. package/node_modules/typebox/build/schema/engine/properties.d.mts +4 -4
  196. package/node_modules/typebox/build/schema/engine/properties.mjs +1 -1
  197. package/node_modules/typebox/build/schema/engine/propertyNames.d.mts +4 -4
  198. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +4 -10
  199. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +4 -4
  200. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +11 -7
  201. package/node_modules/typebox/build/schema/engine/ref.d.mts +4 -4
  202. package/node_modules/typebox/build/schema/engine/ref.mjs +19 -15
  203. package/node_modules/typebox/build/schema/engine/required.d.mts +4 -4
  204. package/node_modules/typebox/build/schema/engine/required.mjs +2 -6
  205. package/node_modules/typebox/build/schema/engine/schema.d.mts +7 -7
  206. package/node_modules/typebox/build/schema/engine/schema.mjs +137 -133
  207. package/node_modules/typebox/build/schema/engine/type.d.mts +4 -4
  208. package/node_modules/typebox/build/schema/engine/type.mjs +2 -6
  209. package/node_modules/typebox/build/schema/engine/unevaluatedItems.d.mts +4 -4
  210. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +5 -9
  211. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.d.mts +4 -4
  212. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +5 -9
  213. package/node_modules/typebox/build/schema/engine/uniqueItems.d.mts +4 -4
  214. package/node_modules/typebox/build/schema/engine/uniqueItems.mjs +2 -6
  215. package/node_modules/typebox/build/schema/errors.d.mts +2 -2
  216. package/node_modules/typebox/build/schema/errors.mjs +8 -14
  217. package/node_modules/typebox/build/schema/intern/index.d.mts +1 -0
  218. package/node_modules/typebox/build/schema/intern/index.mjs +1 -0
  219. package/node_modules/typebox/build/schema/intern/intern.d.mts +11 -0
  220. package/node_modules/typebox/build/schema/intern/intern.mjs +293 -0
  221. package/node_modules/typebox/build/schema/meta/draft_2019_09.d.mts +2 -0
  222. package/node_modules/typebox/build/schema/meta/draft_2019_09.mjs +288 -0
  223. package/node_modules/typebox/build/schema/meta/draft_2020_12.d.mts +2 -0
  224. package/node_modules/typebox/build/schema/meta/draft_2020_12.mjs +300 -0
  225. package/node_modules/typebox/build/schema/meta/draft_3.d.mts +2 -0
  226. package/node_modules/typebox/build/schema/meta/draft_3.mjs +143 -0
  227. package/node_modules/typebox/build/schema/meta/draft_4.d.mts +2 -0
  228. package/node_modules/typebox/build/schema/meta/draft_4.mjs +149 -0
  229. package/node_modules/typebox/build/schema/meta/draft_6.d.mts +2 -0
  230. package/node_modules/typebox/build/schema/meta/draft_6.mjs +155 -0
  231. package/node_modules/typebox/build/schema/meta/draft_7.d.mts +2 -0
  232. package/node_modules/typebox/build/schema/meta/draft_7.mjs +172 -0
  233. package/node_modules/typebox/build/schema/meta/index.d.mts +2 -0
  234. package/node_modules/typebox/build/schema/meta/index.mjs +2 -0
  235. package/node_modules/typebox/build/schema/meta/meta.d.mts +9 -0
  236. package/node_modules/typebox/build/schema/meta/meta.mjs +15 -0
  237. package/node_modules/typebox/build/schema/meta/schema.d.mts +6 -0
  238. package/node_modules/typebox/build/schema/meta/schema.mjs +1 -0
  239. package/node_modules/typebox/build/schema/parse.d.mts +1 -0
  240. package/node_modules/typebox/build/schema/parse.mjs +10 -5
  241. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +8 -3
  242. package/node_modules/typebox/build/schema/resolve/resolve.mjs +268 -139
  243. package/node_modules/typebox/build/schema/schema.d.mts +2 -0
  244. package/node_modules/typebox/build/schema/schema.mjs +2 -0
  245. package/node_modules/typebox/build/value/errors/errors.d.mts +2 -12
  246. package/node_modules/typebox/build/value/errors/errors.mjs +2 -7
  247. package/node_modules/typebox/package.json +1 -1
  248. package/node_modules/typebox/readme.md +59 -89
  249. package/node_modules/zod/README.md +27 -0
  250. package/node_modules/zod/compile.cjs +77 -0
  251. package/node_modules/zod/compile.d.cts +1 -0
  252. package/node_modules/zod/compile.d.ts +1 -0
  253. package/node_modules/zod/compile.js +52 -0
  254. package/node_modules/zod/index.cjs +2 -2
  255. package/node_modules/zod/index.d.cts +1 -2
  256. package/node_modules/zod/index.d.ts +1 -2
  257. package/node_modules/zod/index.js +5 -2
  258. package/node_modules/zod/package.json +13 -2
  259. package/node_modules/zod/src/compile.ts +56 -0
  260. package/node_modules/zod/src/index.ts +5 -2
  261. package/node_modules/zod/src/v3/ZodError.ts +22 -12
  262. package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
  263. package/node_modules/zod/src/v3/tests/intersection.test.ts +18 -0
  264. package/node_modules/zod/src/v3/tests/language-server.test.ts +1 -2
  265. package/node_modules/zod/src/v3/tests/object.test.ts +3 -6
  266. package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
  267. package/node_modules/zod/src/v3/tests/string.test.ts +6 -0
  268. package/node_modules/zod/src/v3/types.ts +5 -5
  269. package/node_modules/zod/src/v4/classic/checks.ts +1 -0
  270. package/node_modules/zod/src/v4/classic/compat.ts +26 -18
  271. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  272. package/node_modules/zod/src/v4/classic/errors.ts +59 -44
  273. package/node_modules/zod/src/v4/classic/external.ts +12 -9
  274. package/node_modules/zod/src/v4/classic/from-json-schema.ts +140 -78
  275. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  276. package/node_modules/zod/src/v4/classic/index.ts +2 -2
  277. package/node_modules/zod/src/v4/classic/iso.ts +2 -72
  278. package/node_modules/zod/src/v4/classic/parse.ts +10 -4
  279. package/node_modules/zod/src/v4/classic/schemas.ts +452 -262
  280. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +27 -0
  281. package/node_modules/zod/src/v4/classic/tests/array.test.ts +2 -2
  282. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +135 -0
  283. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +30 -1
  284. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +278 -0
  285. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +1 -2
  286. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +2 -1
  287. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +2 -2
  288. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  289. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +720 -0
  290. package/node_modules/zod/src/v4/classic/tests/date.test.ts +30 -0
  291. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +32 -18
  292. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  293. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  294. package/node_modules/zod/src/v4/classic/tests/default.test.ts +46 -0
  295. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +31 -7
  296. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +155 -13
  297. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +11 -0
  298. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +112 -2
  299. package/node_modules/zod/src/v4/classic/tests/error.test.ts +274 -6
  300. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +425 -10
  301. package/node_modules/zod/src/v4/classic/tests/function.test.ts +31 -0
  302. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +2 -9
  303. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +1 -2
  304. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  305. package/node_modules/zod/src/v4/classic/tests/index.test.ts +21 -2
  306. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +281 -0
  307. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +47 -0
  308. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +136 -0
  309. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +183 -0
  310. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +3 -10
  311. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
  312. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +12 -1
  313. package/node_modules/zod/src/v4/classic/tests/map.test.ts +12 -0
  314. package/node_modules/zod/src/v4/classic/tests/number.test.ts +46 -9
  315. package/node_modules/zod/src/v4/classic/tests/object.test.ts +245 -12
  316. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +234 -0
  317. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +49 -16
  318. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +51 -4
  319. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +20 -2
  320. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -68
  321. package/node_modules/zod/src/v4/classic/tests/record.test.ts +186 -18
  322. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +33 -2
  323. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  324. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +60 -0
  325. package/node_modules/zod/src/v4/classic/tests/set.test.ts +9 -0
  326. package/node_modules/zod/src/v4/classic/tests/string.test.ts +127 -5
  327. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +18 -0
  328. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +11 -2
  329. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +1585 -173
  330. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +45 -30
  331. package/node_modules/zod/src/v4/classic/tests/union.test.ts +39 -2
  332. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +76 -0
  333. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +2 -2
  334. package/node_modules/zod/src/v4/core/api.ts +48 -12
  335. package/node_modules/zod/src/v4/core/checks.ts +57 -44
  336. package/node_modules/zod/src/v4/core/compile.ts +2188 -0
  337. package/node_modules/zod/src/v4/core/core.ts +98 -19
  338. package/node_modules/zod/src/v4/core/doc.ts +11 -7
  339. package/node_modules/zod/src/v4/core/errors.ts +115 -24
  340. package/node_modules/zod/src/v4/core/index.ts +3 -0
  341. package/node_modules/zod/src/v4/core/json-schema-generator.ts +6 -1
  342. package/node_modules/zod/src/v4/core/json-schema-processors.ts +257 -93
  343. package/node_modules/zod/src/v4/core/json-schema.ts +2 -1
  344. package/node_modules/zod/src/v4/core/memoizer.ts +284 -0
  345. package/node_modules/zod/src/v4/core/parse.ts +131 -38
  346. package/node_modules/zod/src/v4/core/regexes.ts +30 -13
  347. package/node_modules/zod/src/v4/core/registries.ts +2 -2
  348. package/node_modules/zod/src/v4/core/schemas.ts +759 -461
  349. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +969 -0
  350. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  351. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  352. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  353. package/node_modules/zod/src/v4/core/tests/compile.test.ts +1639 -0
  354. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +1 -2
  355. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +1 -2
  356. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +3 -3
  357. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  358. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  359. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  360. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +31 -0
  361. package/node_modules/zod/src/v4/core/to-json-schema.ts +275 -42
  362. package/node_modules/zod/src/v4/core/util.ts +268 -42
  363. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  364. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  365. package/node_modules/zod/src/v4/index.ts +3 -3
  366. package/node_modules/zod/src/v4/locales/ar.ts +3 -0
  367. package/node_modules/zod/src/v4/locales/az.ts +3 -0
  368. package/node_modules/zod/src/v4/locales/be.ts +10 -0
  369. package/node_modules/zod/src/v4/locales/bg.ts +3 -0
  370. package/node_modules/zod/src/v4/locales/bn.ts +121 -0
  371. package/node_modules/zod/src/v4/locales/ca.ts +3 -0
  372. package/node_modules/zod/src/v4/locales/ckb.ts +138 -0
  373. package/node_modules/zod/src/v4/locales/cs.ts +3 -0
  374. package/node_modules/zod/src/v4/locales/da.ts +5 -2
  375. package/node_modules/zod/src/v4/locales/de.ts +3 -0
  376. package/node_modules/zod/src/v4/locales/el.ts +1 -0
  377. package/node_modules/zod/src/v4/locales/en.ts +15 -4
  378. package/node_modules/zod/src/v4/locales/eo.ts +3 -0
  379. package/node_modules/zod/src/v4/locales/es.ts +2 -0
  380. package/node_modules/zod/src/v4/locales/fa.ts +3 -0
  381. package/node_modules/zod/src/v4/locales/fi.ts +3 -0
  382. package/node_modules/zod/src/v4/locales/fr-CA.ts +3 -0
  383. package/node_modules/zod/src/v4/locales/fr.ts +19 -14
  384. package/node_modules/zod/src/v4/locales/gu.ts +121 -0
  385. package/node_modules/zod/src/v4/locales/he.ts +6 -1
  386. package/node_modules/zod/src/v4/locales/hi.ts +124 -0
  387. package/node_modules/zod/src/v4/locales/hr.ts +2 -0
  388. package/node_modules/zod/src/v4/locales/hu.ts +3 -0
  389. package/node_modules/zod/src/v4/locales/hy.ts +9 -0
  390. package/node_modules/zod/src/v4/locales/id.ts +3 -0
  391. package/node_modules/zod/src/v4/locales/index.ts +10 -0
  392. package/node_modules/zod/src/v4/locales/is.ts +3 -0
  393. package/node_modules/zod/src/v4/locales/it.ts +3 -0
  394. package/node_modules/zod/src/v4/locales/ja.ts +3 -0
  395. package/node_modules/zod/src/v4/locales/ka.ts +3 -0
  396. package/node_modules/zod/src/v4/locales/km.ts +3 -0
  397. package/node_modules/zod/src/v4/locales/kn.ts +124 -0
  398. package/node_modules/zod/src/v4/locales/ko.ts +3 -0
  399. package/node_modules/zod/src/v4/locales/lt.ts +2 -0
  400. package/node_modules/zod/src/v4/locales/mk.ts +3 -0
  401. package/node_modules/zod/src/v4/locales/ms.ts +3 -0
  402. package/node_modules/zod/src/v4/locales/ne.ts +126 -0
  403. package/node_modules/zod/src/v4/locales/nl.ts +3 -0
  404. package/node_modules/zod/src/v4/locales/nn.ts +119 -0
  405. package/node_modules/zod/src/v4/locales/no.ts +5 -2
  406. package/node_modules/zod/src/v4/locales/ota.ts +3 -0
  407. package/node_modules/zod/src/v4/locales/pl.ts +3 -0
  408. package/node_modules/zod/src/v4/locales/ps.ts +3 -0
  409. package/node_modules/zod/src/v4/locales/pt-BR.ts +159 -0
  410. package/node_modules/zod/src/v4/locales/pt.ts +99 -58
  411. package/node_modules/zod/src/v4/locales/ro.ts +1 -0
  412. package/node_modules/zod/src/v4/locales/ru.ts +10 -0
  413. package/node_modules/zod/src/v4/locales/sk.ts +121 -0
  414. package/node_modules/zod/src/v4/locales/sl.ts +3 -0
  415. package/node_modules/zod/src/v4/locales/sv.ts +5 -2
  416. package/node_modules/zod/src/v4/locales/ta.ts +3 -0
  417. package/node_modules/zod/src/v4/locales/th.ts +3 -0
  418. package/node_modules/zod/src/v4/locales/tk.ts +111 -0
  419. package/node_modules/zod/src/v4/locales/tr.ts +3 -0
  420. package/node_modules/zod/src/v4/locales/uk.ts +3 -0
  421. package/node_modules/zod/src/v4/locales/ur.ts +3 -0
  422. package/node_modules/zod/src/v4/locales/uz.ts +1 -0
  423. package/node_modules/zod/src/v4/locales/vi.ts +3 -0
  424. package/node_modules/zod/src/v4/locales/yo.ts +3 -0
  425. package/node_modules/zod/src/v4/locales/zh-CN.ts +3 -0
  426. package/node_modules/zod/src/v4/locales/zh-TW.ts +3 -0
  427. package/node_modules/zod/src/v4/mini/checks.ts +1 -0
  428. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  429. package/node_modules/zod/src/v4/mini/external.ts +10 -1
  430. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  431. package/node_modules/zod/src/v4/mini/parse.ts +2 -0
  432. package/node_modules/zod/src/v4/mini/schemas.ts +135 -56
  433. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +33 -0
  434. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +62 -1
  435. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
  436. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +35 -1
  437. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  438. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  439. package/node_modules/zod/src/v4/mini/tests/error.test.ts +23 -4
  440. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +9 -0
  441. package/node_modules/zod/src/v4/mini/tests/index.test.ts +72 -5
  442. package/node_modules/zod/src/v4/mini/tests/number.test.ts +14 -0
  443. package/node_modules/zod/src/v4/mini/tests/object.test.ts +65 -0
  444. package/node_modules/zod/src/v4/mini/tests/string.test.ts +21 -0
  445. package/node_modules/zod/v3/ZodError.cjs +22 -12
  446. package/node_modules/zod/v3/ZodError.d.cts +1 -1
  447. package/node_modules/zod/v3/ZodError.d.ts +1 -1
  448. package/node_modules/zod/v3/ZodError.js +22 -12
  449. package/node_modules/zod/v3/types.cjs +7 -5
  450. package/node_modules/zod/v3/types.js +7 -5
  451. package/node_modules/zod/v4/classic/checks.cjs +2 -1
  452. package/node_modules/zod/v4/classic/checks.d.cts +1 -1
  453. package/node_modules/zod/v4/classic/checks.d.ts +1 -1
  454. package/node_modules/zod/v4/classic/checks.js +1 -1
  455. package/node_modules/zod/v4/classic/compat.d.cts +9 -11
  456. package/node_modules/zod/v4/classic/compat.d.ts +9 -11
  457. package/node_modules/zod/v4/classic/deep-partial.cjs +39 -0
  458. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  459. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  460. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  461. package/node_modules/zod/v4/classic/errors.cjs +43 -34
  462. package/node_modules/zod/v4/classic/errors.d.cts +3 -4
  463. package/node_modules/zod/v4/classic/errors.d.ts +3 -4
  464. package/node_modules/zod/v4/classic/errors.js +43 -34
  465. package/node_modules/zod/v4/classic/external.cjs +30 -27
  466. package/node_modules/zod/v4/classic/external.d.cts +5 -2
  467. package/node_modules/zod/v4/classic/external.d.ts +5 -2
  468. package/node_modules/zod/v4/classic/external.js +5 -8
  469. package/node_modules/zod/v4/classic/from-json-schema.cjs +136 -75
  470. package/node_modules/zod/v4/classic/from-json-schema.js +136 -75
  471. package/node_modules/zod/v4/classic/in-out.cjs +63 -0
  472. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  473. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  474. package/node_modules/zod/v4/classic/in-out.js +36 -0
  475. package/node_modules/zod/v4/classic/index.cjs +2 -2
  476. package/node_modules/zod/v4/classic/index.d.cts +1 -2
  477. package/node_modules/zod/v4/classic/index.d.ts +1 -2
  478. package/node_modules/zod/v4/classic/index.js +2 -2
  479. package/node_modules/zod/v4/classic/iso.cjs +11 -22
  480. package/node_modules/zod/v4/classic/iso.d.cts +2 -17
  481. package/node_modules/zod/v4/classic/iso.d.ts +2 -17
  482. package/node_modules/zod/v4/classic/iso.js +2 -17
  483. package/node_modules/zod/v4/classic/parse.cjs +4 -1
  484. package/node_modules/zod/v4/classic/parse.d.cts +17 -4
  485. package/node_modules/zod/v4/classic/parse.d.ts +17 -4
  486. package/node_modules/zod/v4/classic/parse.js +1 -0
  487. package/node_modules/zod/v4/classic/schemas.cjs +498 -398
  488. package/node_modules/zod/v4/classic/schemas.d.cts +53 -18
  489. package/node_modules/zod/v4/classic/schemas.d.ts +53 -18
  490. package/node_modules/zod/v4/classic/schemas.js +492 -396
  491. package/node_modules/zod/v4/core/api.cjs +23 -4
  492. package/node_modules/zod/v4/core/api.d.cts +13 -9
  493. package/node_modules/zod/v4/core/api.d.ts +13 -9
  494. package/node_modules/zod/v4/core/api.js +21 -4
  495. package/node_modules/zod/v4/core/checks.cjs +37 -31
  496. package/node_modules/zod/v4/core/checks.d.cts +13 -13
  497. package/node_modules/zod/v4/core/checks.d.ts +13 -13
  498. package/node_modules/zod/v4/core/checks.js +37 -31
  499. package/node_modules/zod/v4/core/compile.cjs +1813 -0
  500. package/node_modules/zod/v4/core/compile.d.cts +51 -0
  501. package/node_modules/zod/v4/core/compile.d.ts +51 -0
  502. package/node_modules/zod/v4/core/compile.js +1783 -0
  503. package/node_modules/zod/v4/core/core.cjs +81 -18
  504. package/node_modules/zod/v4/core/core.d.cts +16 -4
  505. package/node_modules/zod/v4/core/core.d.ts +16 -4
  506. package/node_modules/zod/v4/core/core.js +82 -19
  507. package/node_modules/zod/v4/core/doc.cjs +5 -7
  508. package/node_modules/zod/v4/core/doc.d.cts +3 -1
  509. package/node_modules/zod/v4/core/doc.d.ts +3 -1
  510. package/node_modules/zod/v4/core/doc.js +5 -7
  511. package/node_modules/zod/v4/core/errors.cjs +110 -25
  512. package/node_modules/zod/v4/core/errors.d.cts +4 -0
  513. package/node_modules/zod/v4/core/errors.d.ts +4 -0
  514. package/node_modules/zod/v4/core/errors.js +110 -25
  515. package/node_modules/zod/v4/core/index.cjs +5 -1
  516. package/node_modules/zod/v4/core/index.d.cts +3 -0
  517. package/node_modules/zod/v4/core/index.d.ts +3 -0
  518. package/node_modules/zod/v4/core/index.js +3 -0
  519. package/node_modules/zod/v4/core/json-schema-generator.cjs +4 -0
  520. package/node_modules/zod/v4/core/json-schema-generator.d.cts +2 -2
  521. package/node_modules/zod/v4/core/json-schema-generator.d.ts +2 -2
  522. package/node_modules/zod/v4/core/json-schema-generator.js +4 -0
  523. package/node_modules/zod/v4/core/json-schema-processors.cjs +264 -95
  524. package/node_modules/zod/v4/core/json-schema-processors.js +243 -97
  525. package/node_modules/zod/v4/core/json-schema.d.cts +2 -1
  526. package/node_modules/zod/v4/core/json-schema.d.ts +2 -1
  527. package/node_modules/zod/v4/core/memoizer.cjs +272 -0
  528. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  529. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  530. package/node_modules/zod/v4/core/memoizer.js +265 -0
  531. package/node_modules/zod/v4/core/parse.cjs +96 -34
  532. package/node_modules/zod/v4/core/parse.d.cts +14 -11
  533. package/node_modules/zod/v4/core/parse.d.ts +14 -11
  534. package/node_modules/zod/v4/core/parse.js +94 -33
  535. package/node_modules/zod/v4/core/regexes.cjs +27 -15
  536. package/node_modules/zod/v4/core/regexes.d.cts +2 -0
  537. package/node_modules/zod/v4/core/regexes.d.ts +2 -0
  538. package/node_modules/zod/v4/core/regexes.js +24 -13
  539. package/node_modules/zod/v4/core/registries.js +2 -2
  540. package/node_modules/zod/v4/core/schemas.cjs +537 -326
  541. package/node_modules/zod/v4/core/schemas.d.cts +100 -31
  542. package/node_modules/zod/v4/core/schemas.d.ts +100 -31
  543. package/node_modules/zod/v4/core/schemas.js +526 -325
  544. package/node_modules/zod/v4/core/to-json-schema.cjs +242 -39
  545. package/node_modules/zod/v4/core/to-json-schema.d.cts +42 -3
  546. package/node_modules/zod/v4/core/to-json-schema.d.ts +42 -3
  547. package/node_modules/zod/v4/core/to-json-schema.js +241 -39
  548. package/node_modules/zod/v4/core/util.cjs +212 -31
  549. package/node_modules/zod/v4/core/util.d.cts +58 -1
  550. package/node_modules/zod/v4/core/util.d.ts +58 -1
  551. package/node_modules/zod/v4/core/util.js +202 -30
  552. package/node_modules/zod/v4/core/versions.cjs +2 -2
  553. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  554. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  555. package/node_modules/zod/v4/core/versions.js +2 -2
  556. package/node_modules/zod/v4/core/visit.cjs +195 -0
  557. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  558. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  559. package/node_modules/zod/v4/core/visit.js +169 -0
  560. package/node_modules/zod/v4/index.cjs +15 -5
  561. package/node_modules/zod/v4/index.d.cts +2 -2
  562. package/node_modules/zod/v4/index.d.ts +2 -2
  563. package/node_modules/zod/v4/index.js +3 -2
  564. package/node_modules/zod/v4/locales/ar.cjs +3 -0
  565. package/node_modules/zod/v4/locales/ar.js +3 -0
  566. package/node_modules/zod/v4/locales/az.cjs +3 -0
  567. package/node_modules/zod/v4/locales/az.js +3 -0
  568. package/node_modules/zod/v4/locales/be.cjs +10 -0
  569. package/node_modules/zod/v4/locales/be.js +10 -0
  570. package/node_modules/zod/v4/locales/bg.cjs +3 -0
  571. package/node_modules/zod/v4/locales/bg.js +3 -0
  572. package/node_modules/zod/v4/locales/bn.cjs +138 -0
  573. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  574. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  575. package/node_modules/zod/v4/locales/bn.js +111 -0
  576. package/node_modules/zod/v4/locales/ca.cjs +3 -0
  577. package/node_modules/zod/v4/locales/ca.js +3 -0
  578. package/node_modules/zod/v4/locales/ckb.cjs +158 -0
  579. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  580. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  581. package/node_modules/zod/v4/locales/ckb.js +131 -0
  582. package/node_modules/zod/v4/locales/cs.cjs +3 -0
  583. package/node_modules/zod/v4/locales/cs.js +3 -0
  584. package/node_modules/zod/v4/locales/da.cjs +5 -2
  585. package/node_modules/zod/v4/locales/da.js +5 -2
  586. package/node_modules/zod/v4/locales/de.cjs +3 -0
  587. package/node_modules/zod/v4/locales/de.js +3 -0
  588. package/node_modules/zod/v4/locales/el.cjs +1 -0
  589. package/node_modules/zod/v4/locales/el.js +1 -0
  590. package/node_modules/zod/v4/locales/en.cjs +14 -4
  591. package/node_modules/zod/v4/locales/en.js +14 -4
  592. package/node_modules/zod/v4/locales/eo.cjs +3 -0
  593. package/node_modules/zod/v4/locales/eo.js +3 -0
  594. package/node_modules/zod/v4/locales/es.cjs +2 -0
  595. package/node_modules/zod/v4/locales/es.js +2 -0
  596. package/node_modules/zod/v4/locales/fa.cjs +3 -0
  597. package/node_modules/zod/v4/locales/fa.js +3 -0
  598. package/node_modules/zod/v4/locales/fi.cjs +3 -0
  599. package/node_modules/zod/v4/locales/fi.js +3 -0
  600. package/node_modules/zod/v4/locales/fr-CA.cjs +3 -0
  601. package/node_modules/zod/v4/locales/fr-CA.js +3 -0
  602. package/node_modules/zod/v4/locales/fr.cjs +16 -14
  603. package/node_modules/zod/v4/locales/fr.js +16 -14
  604. package/node_modules/zod/v4/locales/gu.cjs +138 -0
  605. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  606. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  607. package/node_modules/zod/v4/locales/gu.js +111 -0
  608. package/node_modules/zod/v4/locales/he.cjs +5 -0
  609. package/node_modules/zod/v4/locales/he.js +5 -0
  610. package/node_modules/zod/v4/locales/hi.cjs +136 -0
  611. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  612. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  613. package/node_modules/zod/v4/locales/hi.js +109 -0
  614. package/node_modules/zod/v4/locales/hr.cjs +2 -0
  615. package/node_modules/zod/v4/locales/hr.js +2 -0
  616. package/node_modules/zod/v4/locales/hu.cjs +3 -0
  617. package/node_modules/zod/v4/locales/hu.js +3 -0
  618. package/node_modules/zod/v4/locales/hy.cjs +9 -0
  619. package/node_modules/zod/v4/locales/hy.js +9 -0
  620. package/node_modules/zod/v4/locales/id.cjs +3 -0
  621. package/node_modules/zod/v4/locales/id.js +3 -0
  622. package/node_modules/zod/v4/locales/index.cjs +22 -2
  623. package/node_modules/zod/v4/locales/index.d.cts +10 -0
  624. package/node_modules/zod/v4/locales/index.d.ts +10 -0
  625. package/node_modules/zod/v4/locales/index.js +10 -0
  626. package/node_modules/zod/v4/locales/is.cjs +3 -0
  627. package/node_modules/zod/v4/locales/is.js +3 -0
  628. package/node_modules/zod/v4/locales/it.cjs +3 -0
  629. package/node_modules/zod/v4/locales/it.js +3 -0
  630. package/node_modules/zod/v4/locales/ja.cjs +3 -0
  631. package/node_modules/zod/v4/locales/ja.js +3 -0
  632. package/node_modules/zod/v4/locales/ka.cjs +3 -0
  633. package/node_modules/zod/v4/locales/ka.js +3 -0
  634. package/node_modules/zod/v4/locales/km.cjs +3 -0
  635. package/node_modules/zod/v4/locales/km.js +3 -0
  636. package/node_modules/zod/v4/locales/kn.cjs +141 -0
  637. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  638. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  639. package/node_modules/zod/v4/locales/kn.js +114 -0
  640. package/node_modules/zod/v4/locales/ko.cjs +3 -0
  641. package/node_modules/zod/v4/locales/ko.js +3 -0
  642. package/node_modules/zod/v4/locales/lt.cjs +2 -0
  643. package/node_modules/zod/v4/locales/lt.js +2 -0
  644. package/node_modules/zod/v4/locales/mk.cjs +3 -0
  645. package/node_modules/zod/v4/locales/mk.js +3 -0
  646. package/node_modules/zod/v4/locales/ms.cjs +3 -0
  647. package/node_modules/zod/v4/locales/ms.js +3 -0
  648. package/node_modules/zod/v4/locales/ne.cjs +136 -0
  649. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  650. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  651. package/node_modules/zod/v4/locales/ne.js +109 -0
  652. package/node_modules/zod/v4/locales/nl.cjs +3 -0
  653. package/node_modules/zod/v4/locales/nl.js +3 -0
  654. package/node_modules/zod/v4/locales/nn.cjs +138 -0
  655. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  656. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  657. package/node_modules/zod/v4/locales/nn.js +111 -0
  658. package/node_modules/zod/v4/locales/no.cjs +5 -2
  659. package/node_modules/zod/v4/locales/no.js +5 -2
  660. package/node_modules/zod/v4/locales/ota.cjs +3 -0
  661. package/node_modules/zod/v4/locales/ota.js +3 -0
  662. package/node_modules/zod/v4/locales/pl.cjs +3 -0
  663. package/node_modules/zod/v4/locales/pl.js +3 -0
  664. package/node_modules/zod/v4/locales/ps.cjs +3 -0
  665. package/node_modules/zod/v4/locales/ps.js +3 -0
  666. package/node_modules/zod/v4/locales/pt-BR.cjs +168 -0
  667. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  668. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  669. package/node_modules/zod/v4/locales/pt-BR.js +141 -0
  670. package/node_modules/zod/v4/locales/pt.cjs +87 -55
  671. package/node_modules/zod/v4/locales/pt.js +87 -55
  672. package/node_modules/zod/v4/locales/ro.cjs +1 -0
  673. package/node_modules/zod/v4/locales/ro.js +1 -0
  674. package/node_modules/zod/v4/locales/ru.cjs +10 -0
  675. package/node_modules/zod/v4/locales/ru.js +10 -0
  676. package/node_modules/zod/v4/locales/sk.cjs +141 -0
  677. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  678. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  679. package/node_modules/zod/v4/locales/sk.js +114 -0
  680. package/node_modules/zod/v4/locales/sl.cjs +3 -0
  681. package/node_modules/zod/v4/locales/sl.js +3 -0
  682. package/node_modules/zod/v4/locales/sv.cjs +5 -2
  683. package/node_modules/zod/v4/locales/sv.js +5 -2
  684. package/node_modules/zod/v4/locales/ta.cjs +3 -0
  685. package/node_modules/zod/v4/locales/ta.js +3 -0
  686. package/node_modules/zod/v4/locales/th.cjs +3 -0
  687. package/node_modules/zod/v4/locales/th.js +3 -0
  688. package/node_modules/zod/v4/locales/tk.cjs +132 -0
  689. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  690. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  691. package/node_modules/zod/v4/locales/tk.js +105 -0
  692. package/node_modules/zod/v4/locales/tr.cjs +3 -0
  693. package/node_modules/zod/v4/locales/tr.js +3 -0
  694. package/node_modules/zod/v4/locales/uk.cjs +3 -0
  695. package/node_modules/zod/v4/locales/uk.js +3 -0
  696. package/node_modules/zod/v4/locales/ur.cjs +3 -0
  697. package/node_modules/zod/v4/locales/ur.js +3 -0
  698. package/node_modules/zod/v4/locales/uz.cjs +1 -0
  699. package/node_modules/zod/v4/locales/uz.js +1 -0
  700. package/node_modules/zod/v4/locales/vi.cjs +3 -0
  701. package/node_modules/zod/v4/locales/vi.js +3 -0
  702. package/node_modules/zod/v4/locales/yo.cjs +3 -0
  703. package/node_modules/zod/v4/locales/yo.js +3 -0
  704. package/node_modules/zod/v4/locales/zh-CN.cjs +3 -0
  705. package/node_modules/zod/v4/locales/zh-CN.js +3 -0
  706. package/node_modules/zod/v4/locales/zh-TW.cjs +3 -0
  707. package/node_modules/zod/v4/locales/zh-TW.js +3 -0
  708. package/node_modules/zod/v4/mini/checks.cjs +2 -1
  709. package/node_modules/zod/v4/mini/checks.d.cts +1 -1
  710. package/node_modules/zod/v4/mini/checks.d.ts +1 -1
  711. package/node_modules/zod/v4/mini/checks.js +1 -1
  712. package/node_modules/zod/v4/mini/deep-partial.cjs +39 -0
  713. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  714. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  715. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  716. package/node_modules/zod/v4/mini/external.cjs +12 -1
  717. package/node_modules/zod/v4/mini/external.d.cts +5 -2
  718. package/node_modules/zod/v4/mini/external.d.ts +5 -2
  719. package/node_modules/zod/v4/mini/external.js +3 -1
  720. package/node_modules/zod/v4/mini/in-out.cjs +63 -0
  721. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  722. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  723. package/node_modules/zod/v4/mini/in-out.js +36 -0
  724. package/node_modules/zod/v4/mini/parse.cjs +3 -1
  725. package/node_modules/zod/v4/mini/parse.d.cts +1 -1
  726. package/node_modules/zod/v4/mini/parse.d.ts +1 -1
  727. package/node_modules/zod/v4/mini/parse.js +1 -1
  728. package/node_modules/zod/v4/mini/schemas.cjs +75 -47
  729. package/node_modules/zod/v4/mini/schemas.d.cts +43 -13
  730. package/node_modules/zod/v4/mini/schemas.d.ts +43 -13
  731. package/node_modules/zod/v4/mini/schemas.js +71 -45
  732. package/openclaw.plugin.json +27 -56
  733. package/package.json +10 -7
  734. package/dist/targets-BTQCYRZQ.js +0 -48
  735. package/node_modules/zod/src/v4/core/config.ts +0 -15
  736. /package/dist/{audio-preflight.runtime-BBfC9elv.js → .setup/audio-preflight.runtime-BBfC9elv.mjs} +0 -0
  737. /package/dist/{doctor-contract-w6FpMypv.js → .setup/doctor-contract-w6FpMypv.mjs} +0 -0
  738. /package/dist/{json-response-DXajw_FU.js → .setup/json-response-DXajw_FU.mjs} +0 -0
  739. /package/dist/{rolldown-runtime-8H4AJuhK.js → .setup/rolldown-runtime-8H4AJuhK.mjs} +0 -0
  740. /package/dist/{runtime-C5JxBWZp.js → .setup/runtime-C5JxBWZp.mjs} +0 -0
  741. /package/dist/{secret-contract-BCpDLdg9.js → .setup/secret-contract-BCpDLdg9.mjs} +0 -0
  742. /package/dist/{security-audit-shared-CK5rVR-1.js → .setup/security-audit-shared-CK5rVR-1.mjs} +0 -0
  743. /package/dist/{thread-bindings-BiL1wGqK.js → .setup/thread-bindings-BiL1wGqK.mjs} +0 -0
@@ -18,8 +18,7 @@ const validateOpenAPI30Schema = async (zodJSONSchema: Record<string, unknown>):
18
18
  });
19
19
 
20
20
  if (!res.valid) {
21
- // `console.error` should make `vitest` trow an unhandled error
22
- // printing the validation messages in consoles
21
+ // `console.error` should make `vitest` trow an unhandled error printing the validation messages in consoles
23
22
  console.error(
24
23
  `OpenAPI schema is not valid against ${openAPI30Validator.version}`,
25
24
  JSON.stringify(res.errors, null, 2)
@@ -88,7 +87,7 @@ describe("toJSONSchema", () => {
88
87
  {
89
88
  "$schema": "https://json-schema.org/draft/2020-12/schema",
90
89
  "format": "date-time",
91
- "pattern": "^(?:(?:\\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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
90
+ "pattern": "^(?:(?:\\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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
92
91
  "type": "string",
93
92
  }
94
93
  `);
@@ -100,6 +99,17 @@ describe("toJSONSchema", () => {
100
99
  "type": "string",
101
100
  }
102
101
  `);
102
+ // only shapes keeping both an offset and seconds may advertise `date-time`, composed onto a string as well as constructed
103
+ expect(z.toJSONSchema(z.iso.datetime()).format).toEqual("date-time");
104
+ expect(z.toJSONSchema(z.iso.datetime({ offset: true })).format).toEqual("date-time");
105
+ expect(z.toJSONSchema(z.iso.datetime({ precision: 0 })).format).toEqual("date-time");
106
+ expect(z.toJSONSchema(z.iso.datetime({ local: true })).format).toEqual(undefined);
107
+ expect(z.toJSONSchema(z.iso.datetime({ precision: -1 })).format).toEqual(undefined);
108
+ expect(z.toJSONSchema(z.string().check(z.iso.datetime({ local: true }))).format).toEqual(undefined);
109
+ expect(z.toJSONSchema(z.string().check(z.iso.datetime())).format).toEqual("date-time");
110
+ // the pattern still describes what the schema accepts
111
+ expect(z.toJSONSchema(z.iso.datetime({ local: true })).pattern).toBeDefined();
112
+
103
113
  expect(z.toJSONSchema(z.iso.time())).toMatchInlineSnapshot(`
104
114
  {
105
115
  "$schema": "https://json-schema.org/draft/2020-12/schema",
@@ -221,7 +231,7 @@ describe("toJSONSchema", () => {
221
231
  {
222
232
  "$schema": "https://json-schema.org/draft/2020-12/schema",
223
233
  "format": "emoji",
224
- "pattern": "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
234
+ "pattern": "^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$",
225
235
  "type": "string",
226
236
  }
227
237
  `);
@@ -233,6 +243,14 @@ describe("toJSONSchema", () => {
233
243
  "type": "string",
234
244
  }
235
245
  `);
246
+ expect(z.toJSONSchema(z.nanoid({ length: 64 }))).toMatchInlineSnapshot(`
247
+ {
248
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
249
+ "format": "nanoid",
250
+ "pattern": "^[a-zA-Z0-9_-]{64}$",
251
+ "type": "string",
252
+ }
253
+ `);
236
254
  expect(z.toJSONSchema(z.cuid2())).toMatchInlineSnapshot(`
237
255
  {
238
256
  "$schema": "https://json-schema.org/draft/2020-12/schema",
@@ -245,7 +263,7 @@ describe("toJSONSchema", () => {
245
263
  {
246
264
  "$schema": "https://json-schema.org/draft/2020-12/schema",
247
265
  "format": "ulid",
248
- "pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$",
266
+ "pattern": "^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$",
249
267
  "type": "string",
250
268
  }
251
269
  `);
@@ -325,6 +343,12 @@ describe("toJSONSchema", () => {
325
343
  // Dynamic catch values
326
344
  const dynamicCatchSchema = z.string().catch((ctx) => `${ctx.issues.length}`);
327
345
  expect(() => z.toJSONSchema(dynamicCatchSchema)).toThrow("Dynamic catch values are not supported in JSON Schema");
346
+ expect(z.toJSONSchema(dynamicCatchSchema, { unrepresentable: "any" })).toMatchInlineSnapshot(`
347
+ {
348
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
349
+ "type": "string",
350
+ }
351
+ `);
328
352
  });
329
353
 
330
354
  test("string formats", () => {
@@ -348,7 +372,7 @@ describe("toJSONSchema", () => {
348
372
  {
349
373
  "$schema": "https://json-schema.org/draft/2020-12/schema",
350
374
  "format": "date-time",
351
- "pattern": "^(?:(?:\\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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
375
+ "pattern": "^(?:(?:\\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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
352
376
  "type": "string",
353
377
  }
354
378
  `);
@@ -480,7 +504,7 @@ describe("toJSONSchema", () => {
480
504
  "pattern": "cruel",
481
505
  },
482
506
  {
483
- "pattern": "^.{10}dark",
507
+ "pattern": "^.{10,}dark",
484
508
  },
485
509
  {
486
510
  "pattern": ".*world$",
@@ -519,7 +543,7 @@ describe("toJSONSchema", () => {
519
543
  "type": "string",
520
544
  },
521
545
  {
522
- "pattern": "^.{10}dark",
546
+ "pattern": "^.{10,}dark",
523
547
  "type": "string",
524
548
  },
525
549
  {
@@ -536,6 +560,19 @@ describe("toJSONSchema", () => {
536
560
  `);
537
561
  });
538
562
 
563
+ test("includes with position emits a pattern matching runtime semantics", () => {
564
+ // String.prototype.includes(sub, position) matches `sub` at `position` OR
565
+ // LATER, so the JSON Schema pattern must allow >= position leading chars.
566
+ const schema = z.string().includes("foo", { position: 2 });
567
+ const json = z.toJSONSchema(schema) as { pattern?: string };
568
+ expect(json.pattern).toBe("^.{2,}foo");
569
+
570
+ const re = new RegExp(json.pattern!);
571
+ for (const input of ["xxfoo", "xxxfoo", "xfoo", "ab"]) {
572
+ expect(re.test(input)).toBe(schema.safeParse(input).success);
573
+ }
574
+ });
575
+
539
576
  test("number constraints", () => {
540
577
  expect(z.toJSONSchema(z.number().min(5).max(10))).toMatchInlineSnapshot(
541
578
  `
@@ -648,8 +685,7 @@ describe("toJSONSchema", () => {
648
685
  });
649
686
 
650
687
  test("number constraints intersection draft-04", () => {
651
- // When both minimum (from .int()) and exclusiveMinimum (from .positive()) exist,
652
- // the more restrictive constraint should be used
688
+ // When both minimum (from .int()) and exclusiveMinimum (from .positive()) exist, the more restrictive constraint should be used
653
689
  expect(z.toJSONSchema(z.number().int().positive().lte(65535), { target: "draft-04" })).toMatchInlineSnapshot(`
654
690
  {
655
691
  "$schema": "http://json-schema.org/draft-04/schema#",
@@ -690,6 +726,7 @@ describe("toJSONSchema", () => {
690
726
 
691
727
  test("target normalization draft-04 and draft-07", () => {
692
728
  // Test that both old (draft-4, draft-7) and new (draft-04, draft-07) target formats work
729
+
693
730
  // Test draft-04 / draft-4
694
731
  expect(z.toJSONSchema(z.number().gt(5), { target: "draft-04" })).toMatchInlineSnapshot(`
695
732
  {
@@ -787,11 +824,159 @@ describe("toJSONSchema", () => {
787
824
 
788
825
  test("unions", () => {
789
826
  const schema = z.union([z.string(), z.number()]);
827
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
828
+ {
829
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
830
+ "type": [
831
+ "string",
832
+ "number",
833
+ ],
834
+ }
835
+ `);
836
+ });
837
+
838
+ test("nullable compacts to a type array", () => {
839
+ expect(z.toJSONSchema(z.string().nullable())).toMatchInlineSnapshot(`
840
+ {
841
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
842
+ "type": [
843
+ "string",
844
+ "null",
845
+ ],
846
+ }
847
+ `);
848
+
849
+ // a nested union folds into the outer type array rather than leaving a mixed shape
850
+ expect(z.toJSONSchema(z.union([z.string(), z.number()]).nullable())).toMatchInlineSnapshot(`
851
+ {
852
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
853
+ "type": [
854
+ "string",
855
+ "number",
856
+ "null",
857
+ ],
858
+ }
859
+ `);
860
+
861
+ // the null branch is bare but the object branch is not, so this stays an anyOf
862
+ expect(z.toJSONSchema(z.object({ a: z.string() }).nullable())).toMatchInlineSnapshot(`
863
+ {
864
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
865
+ "anyOf": [
866
+ {
867
+ "additionalProperties": false,
868
+ "properties": {
869
+ "a": {
870
+ "type": "string",
871
+ },
872
+ },
873
+ "required": [
874
+ "a",
875
+ ],
876
+ "type": "object",
877
+ },
878
+ {
879
+ "type": "null",
880
+ },
881
+ ],
882
+ }
883
+ `);
884
+ });
885
+
886
+ test("duplicate branches dedupe, single branch stays a bare type", () => {
887
+ // a `type` array must have unique members, so two branches that erase to the same bare type collapse
888
+ const refined = z.union([z.string().refine((s) => s.length > 2), z.string().refine((s) => s.length < 9)]);
889
+ expect(z.toJSONSchema(refined)).toMatchInlineSnapshot(`
890
+ {
891
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
892
+ "type": "string",
893
+ }
894
+ `);
895
+ expect(z.toJSONSchema(z.union([z.string()]))).toMatchInlineSnapshot(`
896
+ {
897
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
898
+ "type": "string",
899
+ }
900
+ `);
901
+ });
902
+
903
+ test("compaction runs after overrides and ref extraction", () => {
904
+ // an override decorates the string branch, so it is no longer a bare type and must survive in anyOf
905
+ const decorated = z.toJSONSchema(z.union([z.string(), z.number()]), {
906
+ override(ctx) {
907
+ if (ctx.zodSchema._zod.def.type === "string") ctx.jsonSchema.whatever = "sup";
908
+ },
909
+ });
910
+ expect(decorated).toMatchInlineSnapshot(`
911
+ {
912
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
913
+ "anyOf": [
914
+ {
915
+ "type": "string",
916
+ "whatever": "sup",
917
+ },
918
+ {
919
+ "type": "number",
920
+ },
921
+ ],
922
+ }
923
+ `);
924
+
925
+ // a branch extracted into $defs is a $ref, not a bare type, so `reused` is not silently bypassed
926
+ const shared = z.string();
927
+ expect(
928
+ z.toJSONSchema(z.object({ a: shared, b: z.union([shared, z.null()]) }), { reused: "ref" })
929
+ ).toMatchInlineSnapshot(`
930
+ {
931
+ "$defs": {
932
+ "__schema0": {
933
+ "type": "string",
934
+ },
935
+ },
936
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
937
+ "additionalProperties": false,
938
+ "properties": {
939
+ "a": {
940
+ "$ref": "#/$defs/__schema0",
941
+ },
942
+ "b": {
943
+ "anyOf": [
944
+ {
945
+ "$ref": "#/$defs/__schema0",
946
+ },
947
+ {
948
+ "type": "null",
949
+ },
950
+ ],
951
+ },
952
+ },
953
+ "required": [
954
+ "a",
955
+ "b",
956
+ ],
957
+ "type": "object",
958
+ }
959
+ `);
960
+ });
961
+
962
+ test("openapi-3.0 keeps a single-string type", () => {
963
+ // OpenAPI 3.0 has no type arrays; nullability is spelled with `nullable`
964
+ expect(z.toJSONSchema(z.string().nullable(), { target: "openapi-3.0" })).toMatchInlineSnapshot(`
965
+ {
966
+ "nullable": true,
967
+ "type": "string",
968
+ }
969
+ `);
970
+ });
971
+
972
+ test("union with constrained branch is not compacted", () => {
973
+ const schema = z.union([z.string().min(1), z.number()]);
790
974
  expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
791
975
  {
792
976
  "$schema": "https://json-schema.org/draft/2020-12/schema",
793
977
  "anyOf": [
794
978
  {
979
+ "minLength": 1,
795
980
  "type": "string",
796
981
  },
797
982
  {
@@ -802,6 +987,25 @@ describe("toJSONSchema", () => {
802
987
  `);
803
988
  });
804
989
 
990
+ test("union of literals is not compacted", () => {
991
+ const schema = z.union([z.literal("a"), z.literal("b")]);
992
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
993
+ {
994
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
995
+ "anyOf": [
996
+ {
997
+ "const": "a",
998
+ "type": "string",
999
+ },
1000
+ {
1001
+ "const": "b",
1002
+ "type": "string",
1003
+ },
1004
+ ],
1005
+ }
1006
+ `);
1007
+ });
1008
+
805
1009
  test("discriminated unions", () => {
806
1010
  const schema = z.discriminatedUnion("type", [
807
1011
  z.object({ type: z.literal("success"), data: z.string() }),
@@ -856,32 +1060,20 @@ describe("toJSONSchema", () => {
856
1060
  expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
857
1061
  {
858
1062
  "$schema": "https://json-schema.org/draft/2020-12/schema",
859
- "allOf": [
860
- {
861
- "additionalProperties": false,
862
- "properties": {
863
- "name": {
864
- "type": "string",
865
- },
866
- },
867
- "required": [
868
- "name",
869
- ],
870
- "type": "object",
1063
+ "additionalProperties": false,
1064
+ "properties": {
1065
+ "age": {
1066
+ "type": "number",
871
1067
  },
872
- {
873
- "additionalProperties": false,
874
- "properties": {
875
- "age": {
876
- "type": "number",
877
- },
878
- },
879
- "required": [
880
- "age",
881
- ],
882
- "type": "object",
1068
+ "name": {
1069
+ "type": "string",
883
1070
  },
1071
+ },
1072
+ "required": [
1073
+ "name",
1074
+ "age",
884
1075
  ],
1076
+ "type": "object",
885
1077
  }
886
1078
  `);
887
1079
  });
@@ -941,7 +1133,23 @@ describe("toJSONSchema", () => {
941
1133
  `);
942
1134
  });
943
1135
 
944
- test("record filters enum values to strings and numbers for required", () => {
1136
+ test("record with enum keys drops required for an optional-in value under io: input", () => {
1137
+ const schema = z.record(z.enum(["key1", "key2"]), z.number().default(0));
1138
+
1139
+ expect(z.toJSONSchema(schema, { io: "input" }).required).toBeUndefined();
1140
+ expect(z.toJSONSchema(schema).required).toEqual(["key1", "key2"]);
1141
+ expect(z.toJSONSchema(z.record(z.enum(["key1", "key2"]), z.number()), { io: "input" }).required).toEqual([
1142
+ "key1",
1143
+ "key2",
1144
+ ]);
1145
+ // A caught value keeps required, matching the input type and z.object().
1146
+ expect(z.toJSONSchema(z.record(z.enum(["key1", "key2"]), z.number().catch(0)), { io: "input" }).required).toEqual([
1147
+ "key1",
1148
+ "key2",
1149
+ ]);
1150
+ });
1151
+
1152
+ test("record stringifies numeric enum keys for propertyNames and required", () => {
945
1153
  enum NumberEnum {
946
1154
  Zero = 0,
947
1155
  One = 1,
@@ -956,20 +1164,124 @@ describe("toJSONSchema", () => {
956
1164
  },
957
1165
  "propertyNames": {
958
1166
  "enum": [
959
- 0,
960
- 1,
1167
+ "0",
1168
+ "1",
961
1169
  ],
962
- "type": "number",
1170
+ "type": "string",
963
1171
  },
964
1172
  "required": [
965
- 0,
966
- 1,
1173
+ "0",
1174
+ "1",
967
1175
  ],
968
1176
  "type": "object",
969
1177
  }
970
1178
  `);
971
1179
  });
972
1180
 
1181
+ test("record with a numeric key emits propertyNames over the numeric-string form", () => {
1182
+ expect(z.toJSONSchema(z.record(z.number(), z.boolean())).propertyNames).toEqual({
1183
+ type: "string",
1184
+ pattern: "^-?\\d+(?:\\.\\d+)?$",
1185
+ });
1186
+ // range checks can't apply to a key, so only the integer shape survives
1187
+ expect(z.toJSONSchema(z.record(z.int32(), z.boolean())).propertyNames).toEqual({
1188
+ type: "string",
1189
+ pattern: "^-?\\d+$",
1190
+ });
1191
+ expect(z.toJSONSchema(z.record(z.literal([1, 2]), z.boolean()))).toMatchObject({
1192
+ propertyNames: { type: "string", enum: ["1", "2"] },
1193
+ required: ["1", "2"],
1194
+ });
1195
+ expect(z.toJSONSchema(z.record(z.literal(1), z.boolean())).propertyNames).toEqual({
1196
+ type: "string",
1197
+ const: "1",
1198
+ });
1199
+ });
1200
+
1201
+ test("record key rewrite reaches through wrappers and union branches", () => {
1202
+ const numericString = { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" };
1203
+ // a wrapper only carries its inner type once the refs are flattened, so this is decided after the record itself is emitted
1204
+ expect(
1205
+ z.toJSONSchema(
1206
+ z.record(
1207
+ z.lazy(() => z.number()),
1208
+ z.boolean()
1209
+ )
1210
+ ).propertyNames
1211
+ ).toEqual(numericString);
1212
+ expect(z.toJSONSchema(z.record(z.number().pipe(z.number()), z.boolean())).propertyNames).toEqual(numericString);
1213
+ expect(z.toJSONSchema(z.record(z.number().readonly(), z.boolean())).propertyNames).toMatchObject(numericString);
1214
+ expect(z.toJSONSchema(z.record(z.union([z.literal("Tuna"), z.literal(21)]), z.string()))).toMatchObject({
1215
+ propertyNames: {
1216
+ anyOf: [
1217
+ { type: "string", const: "Tuna" },
1218
+ { type: "string", const: "21" },
1219
+ ],
1220
+ },
1221
+ required: ["Tuna", "21"],
1222
+ });
1223
+ });
1224
+
1225
+ test("record with a numeric key inlines an extracted key, and leaves a string one referenced", () => {
1226
+ expect(z.toJSONSchema(z.record(z.number().meta({ id: "Num" }), z.boolean())).propertyNames).toEqual({
1227
+ type: "string",
1228
+ pattern: "^-?\\d+(?:\\.\\d+)?$",
1229
+ });
1230
+ expect(z.toJSONSchema(z.record(z.string().meta({ id: "Str" }), z.boolean())).propertyNames).toEqual({
1231
+ $ref: "#/$defs/Str",
1232
+ });
1233
+ // the value position still wants the number form, so the two cannot share one def
1234
+ const key = z.number().meta({ id: "Shared" });
1235
+ expect(z.toJSONSchema(z.object({ a: key, b: z.record(key, z.string()) }))).toMatchObject({
1236
+ properties: { a: { $ref: "#/$defs/Shared" }, b: { propertyNames: { type: "string" } } },
1237
+ $defs: { Shared: { type: "number" } },
1238
+ });
1239
+ });
1240
+
1241
+ test("record key rewrite reaches a wrapped record", () => {
1242
+ // the flatten copies a record's properties onto its wrapper by reference, so the rewrite has to find every copy
1243
+ expect(z.toJSONSchema(z.record(z.number(), z.boolean()).optional()).propertyNames).toEqual({
1244
+ type: "string",
1245
+ pattern: "^-?\\d+(?:\\.\\d+)?$",
1246
+ });
1247
+ expect(z.toJSONSchema(z.object({ a: z.record(z.literal([1, 2]), z.boolean()).optional() }))).toMatchObject({
1248
+ properties: { a: { propertyNames: { type: "string", enum: ["1", "2"] }, required: ["1", "2"] } },
1249
+ });
1250
+ });
1251
+
1252
+ test("record with a recursive key converts without looping", () => {
1253
+ const numeric: any = z.lazy(() => z.union([z.number(), numeric]));
1254
+ expect(z.toJSONSchema(z.record(numeric, z.boolean())).propertyNames).toMatchObject({
1255
+ anyOf: [{ type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" }, { $ref: "#/$defs/__schema0" }],
1256
+ });
1257
+ // a key with nothing to re-express keeps the reference it had
1258
+ const stringy: any = z.lazy(() => z.union([z.string(), stringy]));
1259
+ expect(z.toJSONSchema(z.record(stringy, z.boolean())).propertyNames).toEqual({ $ref: "#/$defs/__schema0" });
1260
+ expect(
1261
+ z.toJSONSchema(z.record(z.union([z.literal("a"), z.literal("b")]).meta({ id: "Keys" }), z.boolean()))
1262
+ .propertyNames
1263
+ ).toEqual({ $ref: "#/$defs/Keys" });
1264
+ });
1265
+
1266
+ test("record with a heterogeneous key stringifies only its numeric members", () => {
1267
+ // a mixed key carries no `type`, so the numeric members are caught by value rather than by type
1268
+ expect(z.toJSONSchema(z.record(z.literal(["a", 1]), z.boolean()))).toMatchObject({
1269
+ propertyNames: { enum: ["a", "1"] },
1270
+ required: ["a", "1"],
1271
+ });
1272
+ // a member no key can spell is left as it was, since the parser only ever retries a key as a number
1273
+ expect(z.toJSONSchema(z.record(z.literal(["a", true]) as any, z.boolean())).propertyNames).toEqual({
1274
+ enum: ["a", true],
1275
+ });
1276
+ });
1277
+
1278
+ test("record stringifies required for every target", () => {
1279
+ const schema = z.record(z.literal([1, 2]), z.boolean());
1280
+ for (const target of ["draft-2020-12", "draft-7", "draft-4", "openapi-3.0"] as const) {
1281
+ expect(z.toJSONSchema(schema, { target }).required).toEqual(["1", "2"]);
1282
+ }
1283
+ });
1284
+
973
1285
  test("strict record with regex key uses propertyNames", () => {
974
1286
  const schema = z.record(z.string().regex(/^label:[a-z]{2}$/), z.string());
975
1287
 
@@ -1086,6 +1398,9 @@ describe("toJSONSchema", () => {
1086
1398
  expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
1087
1399
  {
1088
1400
  "$schema": "https://json-schema.org/draft/2020-12/schema",
1401
+ "items": false,
1402
+ "maxItems": 2,
1403
+ "minItems": 2,
1089
1404
  "prefixItems": [
1090
1405
  {
1091
1406
  "type": "string",
@@ -1107,6 +1422,7 @@ describe("toJSONSchema", () => {
1107
1422
  "items": {
1108
1423
  "type": "boolean",
1109
1424
  },
1425
+ "minItems": 2,
1110
1426
  "prefixItems": [
1111
1427
  {
1112
1428
  "type": "string",
@@ -1162,7 +1478,7 @@ describe("toJSONSchema", () => {
1162
1478
  },
1163
1479
  ],
1164
1480
  },
1165
- "minItems": 3,
1481
+ "minItems": 2,
1166
1482
  "type": "array",
1167
1483
  }
1168
1484
  `);
@@ -1203,6 +1519,7 @@ describe("toJSONSchema", () => {
1203
1519
  expect(z.toJSONSchema(schema, { target: "draft-7", io: "input" })).toMatchInlineSnapshot(`
1204
1520
  {
1205
1521
  "$schema": "http://json-schema.org/draft-07/schema#",
1522
+ "additionalItems": false,
1206
1523
  "items": [
1207
1524
  {
1208
1525
  "type": "string",
@@ -1211,6 +1528,8 @@ describe("toJSONSchema", () => {
1211
1528
  "type": "number",
1212
1529
  },
1213
1530
  ],
1531
+ "maxItems": 2,
1532
+ "minItems": 2,
1214
1533
  "type": "array",
1215
1534
  }
1216
1535
  `);
@@ -1232,14 +1551,14 @@ describe("toJSONSchema", () => {
1232
1551
  "type": "number",
1233
1552
  },
1234
1553
  ],
1554
+ "minItems": 2,
1235
1555
  "type": "array",
1236
1556
  }
1237
1557
  `);
1238
1558
  });
1239
1559
 
1240
1560
  test("tuple with rest draft-7 - issue #5151 regression test", () => {
1241
- // This test addresses issue #5151: tuple with rest elements and ids
1242
- // in draft-7 had incorrect internal path handling affecting complex scenarios
1561
+ // This test addresses issue #5151: tuple with rest elements and ids in draft-7 had incorrect internal path handling affecting complex scenarios
1243
1562
  const primarySchema = z.string().meta({ id: "primary" });
1244
1563
  const restSchema = z.number().meta({ id: "rest" });
1245
1564
  const testSchema = z.tuple([primarySchema], restSchema);
@@ -1271,6 +1590,7 @@ describe("toJSONSchema", () => {
1271
1590
  "$ref": "#/definitions/primary",
1272
1591
  },
1273
1592
  ],
1593
+ "minItems": 1,
1274
1594
  "type": "array",
1275
1595
  }
1276
1596
  `);
@@ -1285,6 +1605,88 @@ describe("toJSONSchema", () => {
1285
1605
  expect(result.additionalItems).toBeDefined();
1286
1606
  });
1287
1607
 
1608
+ test("closed tuple length constraints - issue #6193", () => {
1609
+ const schema = z.tuple([z.string(), z.string(), z.object({ lang: z.string() })]);
1610
+
1611
+ expect(schema.safeParse(["a", "b", { lang: "en" }, "extra"]).success).toBe(false);
1612
+
1613
+ const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
1614
+ expect(draft2020.items).toBe(false);
1615
+ expect(draft2020.minItems).toBe(3);
1616
+ expect(draft2020.maxItems).toBe(3);
1617
+
1618
+ const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
1619
+ expect(draft7.additionalItems).toBe(false);
1620
+ expect(draft7.minItems).toBe(3);
1621
+ expect(draft7.maxItems).toBe(3);
1622
+
1623
+ const openapi = z.toJSONSchema(schema, { target: "openapi-3.0" });
1624
+ validateOpenAPI30Schema(openapi);
1625
+ expect(openapi.minItems).toBe(3);
1626
+ expect(openapi.maxItems).toBe(3);
1627
+ });
1628
+
1629
+ test("closed tuple with optional trailing items", () => {
1630
+ const schema = z.tuple([z.string(), z.number().optional()]);
1631
+
1632
+ const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
1633
+ expect(draft2020.items).toBe(false);
1634
+ expect(draft2020.minItems).toBe(1);
1635
+ expect(draft2020.maxItems).toBe(2);
1636
+
1637
+ const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
1638
+ expect(draft7.additionalItems).toBe(false);
1639
+ expect(draft7.minItems).toBe(1);
1640
+ expect(draft7.maxItems).toBe(2);
1641
+ });
1642
+
1643
+ test("empty closed tuple rejects extra elements", () => {
1644
+ const schema = z.tuple([]);
1645
+
1646
+ const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
1647
+ expect(draft2020.items).toBe(false);
1648
+ expect(draft2020.maxItems).toBe(0);
1649
+
1650
+ const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
1651
+ expect(draft7.additionalItems).toBe(false);
1652
+ expect(draft7.maxItems).toBe(0);
1653
+
1654
+ const openapi = z.toJSONSchema(schema, { target: "openapi-3.0" });
1655
+ validateOpenAPI30Schema(openapi);
1656
+ expect(openapi.maxItems).toBe(0);
1657
+ });
1658
+
1659
+ test("closed tuple length respects io direction with defaults", () => {
1660
+ const schema = z.tuple([z.string(), z.string().default("x")]);
1661
+
1662
+ const input = z.toJSONSchema(schema, { target: "draft-2020-12", io: "input" });
1663
+ expect(input.items).toBe(false);
1664
+ expect(input.minItems).toBe(1);
1665
+ expect(input.maxItems).toBe(2);
1666
+
1667
+ const output = z.toJSONSchema(schema, { target: "draft-2020-12", io: "output" });
1668
+ expect(output.items).toBe(false);
1669
+ expect(output.minItems).toBe(2);
1670
+ expect(output.maxItems).toBe(2);
1671
+ });
1672
+
1673
+ test("closed tuple length resolves input optionality past transform and catch", () => {
1674
+ const minItems = (schema: z.core.$ZodType, io: "input" | "output") =>
1675
+ z.toJSONSchema(schema, { target: "draft-2020-12", io }).minItems;
1676
+
1677
+ // Both let the parser observe an absent slot, but declare a required input.
1678
+ const pre = z.tuple([z.string(), z.preprocess((v) => v, z.string())]);
1679
+ expect(minItems(pre, "input")).toBe(2);
1680
+ expect(minItems(pre, "output")).toBe(2);
1681
+
1682
+ const caught = z.tuple([z.string(), z.string().catch("x")]);
1683
+ expect(minItems(caught, "input")).toBe(2);
1684
+ expect(minItems(caught, "output")).toBe(2);
1685
+
1686
+ // Resolution passes through the wrapper rather than stopping at it.
1687
+ expect(minItems(z.tuple([z.string(), z.string().optional().catch("x")]), "input")).toBe(1);
1688
+ });
1689
+
1288
1690
  test("promise", () => {
1289
1691
  const schema = z.promise(z.string());
1290
1692
  expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
@@ -1904,13 +2306,9 @@ test("override execution order", () => {
1904
2306
 
1905
2307
  expect(unionSchema).toMatchInlineSnapshot(`
1906
2308
  {
1907
- "anyOf": [
1908
- {
1909
- "type": "string",
1910
- },
1911
- {
1912
- "type": "number",
1913
- },
2309
+ "type": [
2310
+ "string",
2311
+ "number",
1914
2312
  ],
1915
2313
  }
1916
2314
  `);
@@ -2092,15 +2490,143 @@ test("extract schemas with id", () => {
2092
2490
  `);
2093
2491
  });
2094
2492
 
2095
- test("unrepresentable literal values are ignored", () => {
2096
- const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
2097
- expect(a).toMatchInlineSnapshot(`
2493
+ test("escapes JSON Pointer reserved characters in $ref but not in $defs key", () => {
2494
+ const User = z.object({ name: z.string() }).meta({ id: "Shared/User~" });
2495
+ const result = z.toJSONSchema(z.object({ User }));
2496
+ // the $ref pointer escapes `/` -> `~1` and `~` -> `~0` (RFC 6901),
2497
+ // while the $defs key keeps the original id
2498
+ expect((result.properties!.User as any).$ref).toBe("#/$defs/Shared~1User~0");
2499
+ expect(Object.keys(result.$defs!)).toEqual(["Shared/User~"]);
2500
+ });
2501
+
2502
+ test("escapes JSON Pointer reserved characters in the root $ref", () => {
2503
+ const User = z.object({ name: z.string() }).meta({ id: "Shared/User~" });
2504
+ const result = z.toJSONSchema(User);
2505
+ expect(result.$ref).toBe("#/$defs/Shared~1User~0");
2506
+ expect(Object.keys(result.$defs!)).toEqual(["Shared/User~"]);
2507
+ });
2508
+
2509
+ test("a multipleOf divisor JSON Schema cannot express goes through `unrepresentable`", () => {
2510
+ // the keyword must be strictly greater than zero, and NaN/Infinity do not survive JSON at all
2511
+ for (const divisor of [0, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]) {
2512
+ expect(() => z.toJSONSchema(z.number().multipleOf(divisor))).toThrow(/cannot be represented in JSON Schema/);
2513
+ expect(z.toJSONSchema(z.number().multipleOf(divisor), { unrepresentable: "any" })).toMatchObject({
2514
+ type: "number",
2515
+ });
2516
+ expect(z.toJSONSchema(z.number().multipleOf(divisor), { unrepresentable: "any" })).not.toHaveProperty("multipleOf");
2517
+ }
2518
+
2519
+ // a negative divisor accepts exactly what its absolute value accepts, so it still maps
2520
+ expect(z.number().multipleOf(-5).safeParse(10).success).toEqual(true);
2521
+ expect(z.number().multipleOf(-5).safeParse(13).success).toEqual(false);
2522
+ expect(z.toJSONSchema(z.number().multipleOf(-5))).toMatchObject({ multipleOf: 5 });
2523
+ expect(z.toJSONSchema(z.number().multipleOf(0.1))).toMatchObject({ multipleOf: 0.1 });
2524
+ });
2525
+
2526
+ test("unrepresentable default values go through `unrepresentable`", () => {
2527
+ // a bigint default has no reliable JSON encoding, so it is dropped rather than approximated
2528
+ expect(z.toJSONSchema(z.bigint().default(0n), { unrepresentable: "any" })).toMatchInlineSnapshot(`
2098
2529
  {
2099
2530
  "$schema": "https://json-schema.org/draft/2020-12/schema",
2100
- "enum": [
2101
- "hello",
2102
- null,
2103
- 5,
2531
+ }
2532
+ `);
2533
+ expect(z.toJSONSchema(z.bigint().prefault(2n), { io: "input", unrepresentable: "any" })).toMatchInlineSnapshot(`
2534
+ {
2535
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2536
+ }
2537
+ `);
2538
+ // including when nested inside an otherwise representable default
2539
+ expect(
2540
+ z.toJSONSchema(z.object({ a: z.bigint() }).default({ a: 1n }), { unrepresentable: "any" })
2541
+ ).toMatchInlineSnapshot(`
2542
+ {
2543
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2544
+ "additionalProperties": false,
2545
+ "properties": {
2546
+ "a": {},
2547
+ },
2548
+ "required": [
2549
+ "a",
2550
+ ],
2551
+ "type": "object",
2552
+ }
2553
+ `);
2554
+
2555
+ // under the default strict mode the inner type throws first; a representable inner type surfaces the default's own error rather than a raw `JSON.stringify` TypeError
2556
+ expect(() => z.toJSONSchema(z.bigint().default(0n))).toThrow("BigInt cannot be represented in JSON Schema");
2557
+ expect(() => z.toJSONSchema(z.unknown().default(1n))).toThrow("BigInt defaults cannot be represented in JSON Schema");
2558
+
2559
+ // representable defaults are untouched
2560
+ expect(z.toJSONSchema(z.object({ a: z.number() }).default({ a: 2 }))).toMatchInlineSnapshot(`
2561
+ {
2562
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2563
+ "additionalProperties": false,
2564
+ "default": {
2565
+ "a": 2,
2566
+ },
2567
+ "properties": {
2568
+ "a": {
2569
+ "type": "number",
2570
+ },
2571
+ },
2572
+ "required": [
2573
+ "a",
2574
+ ],
2575
+ "type": "object",
2576
+ }
2577
+ `);
2578
+ });
2579
+
2580
+ test("an `unrepresentable` handler can represent a bigint default", () => {
2581
+ // one handler covers both the type and its default, so no `unrepresentable: "any"` is needed and every other unrepresentable type still throws
2582
+ expect(
2583
+ z.toJSONSchema(z.object({ startAt: z.coerce.bigint().optional().default(0n) }), {
2584
+ io: "input",
2585
+ unrepresentable: ({ zodSchema }) => {
2586
+ const def = zodSchema._zod.def;
2587
+ if (def.type === "bigint") return { type: "integer", format: "int64" };
2588
+ if (def.type === "default") return { default: String(def.defaultValue) };
2589
+ return "throw";
2590
+ },
2591
+ })
2592
+ ).toMatchInlineSnapshot(`
2593
+ {
2594
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2595
+ "properties": {
2596
+ "startAt": {
2597
+ "default": "0",
2598
+ "format": "int64",
2599
+ "type": "integer",
2600
+ },
2601
+ },
2602
+ "type": "object",
2603
+ }
2604
+ `);
2605
+
2606
+ // a handler may also drop just the default while still representing the type
2607
+ expect(
2608
+ z.toJSONSchema(z.bigint().default(0n), {
2609
+ unrepresentable: ({ zodSchema }) =>
2610
+ zodSchema._zod.def.type === "bigint" ? { type: "integer", format: "int64" } : "any",
2611
+ })
2612
+ ).toMatchInlineSnapshot(`
2613
+ {
2614
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2615
+ "format": "int64",
2616
+ "type": "integer",
2617
+ }
2618
+ `);
2619
+ });
2620
+
2621
+ test("unrepresentable literal values are ignored", () => {
2622
+ const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
2623
+ expect(a).toMatchInlineSnapshot(`
2624
+ {
2625
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2626
+ "enum": [
2627
+ "hello",
2628
+ null,
2629
+ 5,
2104
2630
  1324,
2105
2631
  ],
2106
2632
  }
@@ -2168,8 +2694,7 @@ test("describe with id", () => {
2168
2694
  });
2169
2695
 
2170
2696
  test("id is stripped from $defs entries (draft-2020-12)", () => {
2171
- // The `id` in `.meta()` is a registration tag — it determines the $defs key
2172
- // but should not leak into the definition body, where it is redundant.
2697
+ // The `id` in `.meta()` is a registration tag — it determines the $defs key but should not leak into the definition body, where it is redundant.
2173
2698
  const inner = z.string().meta({ id: "Inner" });
2174
2699
  const result = z.toJSONSchema(z.object({ a: inner, b: inner }));
2175
2700
  expect(result.$defs?.Inner).toEqual({ type: "string" });
@@ -2177,9 +2702,7 @@ test("id is stripped from $defs entries (draft-2020-12)", () => {
2177
2702
  });
2178
2703
 
2179
2704
  test("id is stripped from definitions entries (draft-04)", () => {
2180
- // In draft-04, `id` is a reserved keyword that sets a base URI for the
2181
- // subschema. Leaking Zod's registration tag here is semantically wrong, so
2182
- // ensure it is stripped.
2705
+ // In draft-04, `id` is a reserved keyword that sets a base URI for the subschema. Leaking Zod's registration tag here is semantically wrong, so ensure it is stripped.
2183
2706
  const inner = z.string().meta({ id: "Inner" });
2184
2707
  const result = z.toJSONSchema(z.object({ a: inner, b: inner }), { target: "draft-04" }) as any;
2185
2708
  expect(result.definitions?.Inner).toEqual({ type: "string" });
@@ -2193,9 +2716,52 @@ test("id is stripped from root schema", () => {
2193
2716
  expect((result as any).id).toBeUndefined();
2194
2717
  });
2195
2718
 
2719
+ test("root schema with id is hoisted into $defs", () => {
2720
+ const A = z.object({ name: z.string() }).meta({ id: "A" });
2721
+ const result = z.toJSONSchema(A);
2722
+
2723
+ expect(result).toEqual({
2724
+ $schema: "https://json-schema.org/draft/2020-12/schema",
2725
+ $ref: "#/$defs/A",
2726
+ $defs: {
2727
+ A: {
2728
+ type: "object",
2729
+ properties: {
2730
+ name: {
2731
+ type: "string",
2732
+ },
2733
+ },
2734
+ required: ["name"],
2735
+ additionalProperties: false,
2736
+ },
2737
+ },
2738
+ });
2739
+ });
2740
+
2741
+ test("root schema with id uses definitions on legacy targets", () => {
2742
+ const A = z.object({ name: z.string() }).meta({ id: "A" });
2743
+ const result = z.toJSONSchema(A, { target: "draft-07" });
2744
+
2745
+ expect(result).toEqual({
2746
+ $schema: "http://json-schema.org/draft-07/schema#",
2747
+ $ref: "#/definitions/A",
2748
+ definitions: {
2749
+ A: {
2750
+ type: "object",
2751
+ properties: {
2752
+ name: {
2753
+ type: "string",
2754
+ },
2755
+ },
2756
+ required: ["name"],
2757
+ additionalProperties: false,
2758
+ },
2759
+ },
2760
+ });
2761
+ });
2762
+
2196
2763
  test("id is observable in override callback", () => {
2197
- // The strip happens after override callbacks run, so userland override code
2198
- // can still read `jsonSchema.id` if it wants to.
2764
+ // The strip happens after override callbacks run, so userland override code can still read `jsonSchema.id` if it wants to.
2199
2765
  const inner = z.string().meta({ id: "Inner" });
2200
2766
  const seenIds: Array<string | undefined> = [];
2201
2767
  z.toJSONSchema(z.object({ a: inner }), {
@@ -2207,8 +2773,7 @@ test("id is observable in override callback", () => {
2207
2773
  });
2208
2774
 
2209
2775
  test("describe with id on wrapper", () => {
2210
- // Test that $ref propagation works when processor sets a different ref (readonly -> innerType)
2211
- // but parent was extracted due to having an id
2776
+ // Test that $ref propagation works when processor sets a different ref (readonly -> innerType) but parent was extracted due to having an id
2212
2777
  const roJobId = z.string().readonly().meta({ id: "roJobId" });
2213
2778
 
2214
2779
  const a = z.toJSONSchema(
@@ -2416,45 +2981,40 @@ test("top-level readonly", () => {
2416
2981
  // .meta({ id: "B" });
2417
2982
 
2418
2983
  const result = z.toJSONSchema(A);
2419
- expect(result).toMatchInlineSnapshot(`
2420
- {
2421
- "$defs": {
2422
- "B": {
2423
- "additionalProperties": false,
2424
- "properties": {
2425
- "a": {
2426
- "$ref": "#",
2427
- },
2428
- "name": {
2429
- "type": "string",
2430
- },
2984
+ expect(result).toEqual({
2985
+ $schema: "https://json-schema.org/draft/2020-12/schema",
2986
+ $ref: "#/$defs/A",
2987
+ $defs: {
2988
+ A: {
2989
+ additionalProperties: false,
2990
+ properties: {
2991
+ b: {
2992
+ $ref: "#/$defs/B",
2993
+ },
2994
+ name: {
2995
+ type: "string",
2431
2996
  },
2432
- "readOnly": true,
2433
- "required": [
2434
- "name",
2435
- "a",
2436
- ],
2437
- "type": "object",
2438
2997
  },
2998
+ readOnly: true,
2999
+ required: ["name", "b"],
3000
+ type: "object",
2439
3001
  },
2440
- "$schema": "https://json-schema.org/draft/2020-12/schema",
2441
- "additionalProperties": false,
2442
- "properties": {
2443
- "b": {
2444
- "$ref": "#/$defs/B",
2445
- },
2446
- "name": {
2447
- "type": "string",
3002
+ B: {
3003
+ additionalProperties: false,
3004
+ properties: {
3005
+ a: {
3006
+ $ref: "#/$defs/A",
3007
+ },
3008
+ name: {
3009
+ type: "string",
3010
+ },
2448
3011
  },
3012
+ readOnly: true,
3013
+ required: ["name", "a"],
3014
+ type: "object",
2449
3015
  },
2450
- "readOnly": true,
2451
- "required": [
2452
- "name",
2453
- "b",
2454
- ],
2455
- "type": "object",
2456
- }
2457
- `);
3016
+ },
3017
+ });
2458
3018
  });
2459
3019
 
2460
3020
  test("basic registry", () => {
@@ -2531,6 +3091,192 @@ test("basic registry", () => {
2531
3091
  `);
2532
3092
  });
2533
3093
 
3094
+ test("large registry converts in linear time", () => {
3095
+ const count = 2000;
3096
+ const convert = (withIntersection: boolean) => {
3097
+ const registry = z.registry<{ id: string }>();
3098
+ for (let i = 0; i < count; i++) {
3099
+ registry.add(
3100
+ z.object({ id: z.string(), name: z.string(), count: z.number(), nested: z.object({ a: z.boolean() }) }),
3101
+ { id: `Type${i}` }
3102
+ );
3103
+ }
3104
+ if (withIntersection) registry.add(z.object({ a: z.string() }).and(z.object({ b: z.string() })), { id: "Inter" });
3105
+
3106
+ const start = performance.now();
3107
+ const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
3108
+ return { schemas, elapsed: performance.now() - start };
3109
+ };
3110
+
3111
+ const plain = convert(false);
3112
+ expect(Object.keys(plain.schemas)).toHaveLength(count);
3113
+ expect(plain.schemas.Type0).toMatchObject({
3114
+ $id: "https://example.com/Type0.json",
3115
+ type: "object",
3116
+ properties: { nested: { type: "object" } },
3117
+ });
3118
+ expect(plain.schemas[`Type${count - 1}`]!.$id).toBe(`https://example.com/Type${count - 1}.json`);
3119
+
3120
+ // The whole-map passes in extractDefs/finalize used to re-run once per registered schema, which made this quadratic: ~9s of CPU at this size before the passes were hoisted, ~50ms after.
3121
+ expect(plain.elapsed).toBeLessThan(5000);
3122
+
3123
+ // The intersection fold walks the whole map as well, so it has to run inside the same guard. Hoisting it back out costs ~10x at this size. Comparing the two conversions rather than asserting a fixed budget keeps this independent of how fast the machine is.
3124
+ const folded = convert(true);
3125
+ expect(folded.schemas.Inter).toMatchObject({ type: "object", properties: { a: {}, b: {} } });
3126
+ expect(folded.elapsed).toBeLessThan(plain.elapsed * 4 + 100);
3127
+ });
3128
+
3129
+ test("a registry of records with numeric keys converts in linear time", () => {
3130
+ const count = 2000;
3131
+ const convert = (key: (i: number) => z.core.$ZodType) => {
3132
+ const registry = z.registry<{ id: string }>();
3133
+ for (let i = 0; i < count; i++) {
3134
+ registry.add(z.object({ m: z.record(key(i) as z.core.$ZodRecordKey, z.boolean()) }), { id: `Type${i}` });
3135
+ }
3136
+ const start = performance.now();
3137
+ const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
3138
+ return { schemas, elapsed: performance.now() - start };
3139
+ };
3140
+
3141
+ const string = convert(() => z.string());
3142
+ const numeric = convert(() => z.number());
3143
+ expect(numeric.schemas.Type0).toMatchObject({
3144
+ properties: { m: { propertyNames: { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" } } },
3145
+ });
3146
+
3147
+ // The rewrite has to find every carrier the flatten copied `propertyNames` onto, which means a pass over the whole seen map. Running that once per record rather than once per conversion cost ~10x at this size. A string key needs no rewrite at all, so comparing against it keeps this independent of how fast the machine is.
3148
+ expect(numeric.elapsed).toBeLessThan(string.elapsed * 2 + 50);
3149
+
3150
+ // An extracted key resolves through a map built once per conversion rather than a search per reference. There is no stable timing control for that — extraction has its own $defs cost, which swamps the difference — so this only pins the shape.
3151
+ const extracted = convert((i) => z.number().meta({ id: `Key${i}` }));
3152
+ expect(extracted.schemas.Type0).toMatchObject({
3153
+ properties: { m: { propertyNames: { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" } } },
3154
+ });
3155
+ });
3156
+
3157
+ test("registry extracts unregistered subschemas into __shared", () => {
3158
+ const registry = z.registry<{ id: string }>();
3159
+ const address = z.object({ street: z.string() }).meta({ id: "Address" });
3160
+ registry.add(z.object({ home: address, work: address }), { id: "Person" });
3161
+ registry.add(z.object({ hq: address }), { id: "Company" });
3162
+
3163
+ const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
3164
+
3165
+ expect(schemas.__shared).toMatchInlineSnapshot(`
3166
+ {
3167
+ "$defs": {
3168
+ "Address": {
3169
+ "additionalProperties": false,
3170
+ "properties": {
3171
+ "street": {
3172
+ "type": "string",
3173
+ },
3174
+ },
3175
+ "required": [
3176
+ "street",
3177
+ ],
3178
+ "type": "object",
3179
+ },
3180
+ },
3181
+ }
3182
+ `);
3183
+ expect(schemas.Person).toMatchInlineSnapshot(`
3184
+ {
3185
+ "$id": "https://example.com/Person.json",
3186
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3187
+ "additionalProperties": false,
3188
+ "properties": {
3189
+ "home": {
3190
+ "$ref": "https://example.com/__shared.json#/$defs/Address",
3191
+ },
3192
+ "work": {
3193
+ "$ref": "https://example.com/__shared.json#/$defs/Address",
3194
+ },
3195
+ },
3196
+ "required": [
3197
+ "home",
3198
+ "work",
3199
+ ],
3200
+ "type": "object",
3201
+ }
3202
+ `);
3203
+ // Company is emitted after Person, so it only resolves if the shared $defs built on the first finalize are still reachable — the pass that writes them no longer runs per schema.
3204
+ expect(schemas.Company!.properties!.hq).toEqual({
3205
+ $ref: "https://example.com/__shared.json#/$defs/Address",
3206
+ });
3207
+ });
3208
+
3209
+ test("registry extracts reused subschemas into __shared without an id", () => {
3210
+ const registry = z.registry<{ id: string }>();
3211
+ const shared = z.object({ q: z.string() });
3212
+ registry.add(z.object({ a: shared, b: shared }), { id: "First" });
3213
+ registry.add(z.object({ c: shared }), { id: "Second" });
3214
+
3215
+ const { schemas } = z.toJSONSchema(registry, { uri: (id) => `${id}.json`, reused: "ref" });
3216
+
3217
+ // The id is counter-generated, so this pins that ctx.counter is consumed exactly once.
3218
+ expect(Object.keys(schemas.__shared!.$defs!)).toEqual(["schema0"]);
3219
+ expect(schemas.First!.properties!.a).toEqual({ $ref: "__shared.json#/$defs/schema0" });
3220
+ expect(schemas.Second!.properties!.c).toEqual({ $ref: "__shared.json#/$defs/schema0" });
3221
+ });
3222
+
3223
+ test("JSONSchemaGenerator re-runs shared passes when emit params change", () => {
3224
+ const shared = z.object({ s: z.string() });
3225
+ const a = z.object({ x: shared, y: shared });
3226
+ const registry = z.registry<{ id: string }>();
3227
+ registry.add(a, { id: "A" });
3228
+
3229
+ const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
3230
+ gen.process(a);
3231
+ const defs: Record<string, any> = {};
3232
+ const external = { registry, uri: (id: string) => `${id}.json`, defs };
3233
+
3234
+ gen.emit(a, { external, reused: "inline" });
3235
+ // Same `external`, different `reused` — the second emit must still extract `shared`.
3236
+ const second: any = gen.emit(a, { external, reused: "ref" });
3237
+
3238
+ expect(Object.keys(defs)).toEqual(["schema0"]);
3239
+ expect(second.properties.x).toEqual({ $ref: "__shared.json#/$defs/schema0" });
3240
+ expect(second.properties.y).toEqual({ $ref: "__shared.json#/$defs/schema0" });
3241
+ });
3242
+
3243
+ test("JSONSchemaGenerator still throws on cycles when a later emit asks for it", () => {
3244
+ const Node: any = z.object({
3245
+ v: z.string(),
3246
+ get next() {
3247
+ return Node;
3248
+ },
3249
+ });
3250
+ const registry = z.registry<{ id: string }>();
3251
+ registry.add(Node, { id: "Node" });
3252
+
3253
+ const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
3254
+ gen.process(Node);
3255
+ const external = { registry, uri: (id: string) => `${id}.json`, defs: {} };
3256
+
3257
+ gen.emit(Node, { external, cycles: "ref" });
3258
+ expect(() => gen.emit(Node, { external, cycles: "throw" })).toThrow(/Cycle detected/);
3259
+ });
3260
+
3261
+ test("JSONSchemaGenerator re-runs shared passes on a no-params emit", () => {
3262
+ const shared = z.object({ s: z.string() });
3263
+ const a = z.object({ x: shared });
3264
+ const registry = z.registry<{ id: string }>();
3265
+ registry.add(a, { id: "A" });
3266
+
3267
+ const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
3268
+ gen.process(a);
3269
+ const defs: Record<string, any> = {};
3270
+ gen.emit(a, { external: { registry, uri: (id: string) => `${id}.json`, defs }, reused: "ref" });
3271
+
3272
+ // Re-processing an already-seen schema bumps `seen.count`, which `extractDefs` branches on under `reused: "ref"` — and it returns early, so it cannot clear the guards itself.
3273
+ gen.process(shared);
3274
+ const second: any = gen.emit(a);
3275
+
3276
+ expect(Object.keys(defs)).toEqual(["schema0"]);
3277
+ expect(second.properties.x).toEqual({ $ref: "__shared.json#/$defs/schema0" });
3278
+ });
3279
+
2534
3280
  test("_ref", () => {
2535
3281
  // const a = z.promise(z.string().describe("a"));
2536
3282
  const a = z.toJSONSchema(z.promise(z.string().describe("a")));
@@ -2627,6 +3373,45 @@ test("defaults/prefaults", () => {
2627
3373
  `);
2628
3374
  });
2629
3375
 
3376
+ test("catch on a transforming schema", () => {
3377
+ const a = z
3378
+ .string()
3379
+ .transform((val) => val.length)
3380
+ .pipe(z.number())
3381
+ .catch(0);
3382
+
3383
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
3384
+ {
3385
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3386
+ "default": 0,
3387
+ "type": "number",
3388
+ }
3389
+ `);
3390
+ // catch values are output-typed, so they are not valid input
3391
+ expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
3392
+ {
3393
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3394
+ "type": "string",
3395
+ }
3396
+ `);
3397
+
3398
+ // the catch no longer hides the inner transform from ancestors, so their output-typed metadata is stripped too — matching a bare nested transform
3399
+ expect(z.toJSONSchema(z.object({ a }).meta({ examples: [{ a: 1 }] }), { io: "input" })).toMatchInlineSnapshot(`
3400
+ {
3401
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3402
+ "properties": {
3403
+ "a": {
3404
+ "type": "string",
3405
+ },
3406
+ },
3407
+ "required": [
3408
+ "a",
3409
+ ],
3410
+ "type": "object",
3411
+ }
3412
+ `);
3413
+ });
3414
+
2630
3415
  test("falsy prefaults (false, 0, empty string)", () => {
2631
3416
  // boolean prefault false
2632
3417
  const a = z.boolean().prefault(false);
@@ -2686,13 +3471,9 @@ test("input type", () => {
2686
3471
  "type": "string",
2687
3472
  },
2688
3473
  "d": {
2689
- "anyOf": [
2690
- {
2691
- "type": "string",
2692
- },
2693
- {
2694
- "type": "null",
2695
- },
3474
+ "type": [
3475
+ "string",
3476
+ "null",
2696
3477
  ],
2697
3478
  },
2698
3479
  "e": {
@@ -2718,19 +3499,13 @@ test("input type", () => {
2718
3499
  ],
2719
3500
  },
2720
3501
  "i": {
2721
- "anyOf": [
2722
- {
2723
- "type": "string",
2724
- },
2725
- {
2726
- "type": "string",
2727
- },
2728
- ],
3502
+ "type": "string",
2729
3503
  },
2730
3504
  },
2731
3505
  "required": [
2732
3506
  "a",
2733
3507
  "d",
3508
+ "f",
2734
3509
  "g",
2735
3510
  ],
2736
3511
  "type": "object",
@@ -2752,13 +3527,9 @@ test("input type", () => {
2752
3527
  "type": "string",
2753
3528
  },
2754
3529
  "d": {
2755
- "anyOf": [
2756
- {
2757
- "type": "string",
2758
- },
2759
- {
2760
- "type": "null",
2761
- },
3530
+ "type": [
3531
+ "string",
3532
+ "null",
2762
3533
  ],
2763
3534
  },
2764
3535
  "e": {
@@ -2783,14 +3554,7 @@ test("input type", () => {
2783
3554
  ],
2784
3555
  },
2785
3556
  "i": {
2786
- "anyOf": [
2787
- {
2788
- "type": "string",
2789
- },
2790
- {
2791
- "type": "string",
2792
- },
2793
- ],
3557
+ "type": "string",
2794
3558
  },
2795
3559
  },
2796
3560
  "required": [
@@ -2895,18 +3659,64 @@ test("use output type for preprocess", () => {
2895
3659
  `);
2896
3660
  });
2897
3661
 
2898
- test("strip output-side examples from input JSON schema for codec", () => {
2899
- const codec = z
2900
- .codec(z.string(), z.number(), { decode: (s) => Number(s), encode: (n) => String(n) })
2901
- .meta({ examples: [42] });
3662
+ test("object property with preprocess stays required in input JSON schema", () => {
3663
+ const schema = z.object({
3664
+ noPreprocess: z.string(),
3665
+ withPreprocess: z.preprocess((v) => v, z.string()),
3666
+ optionalPreprocess: z.preprocess((v) => v, z.string().optional()),
3667
+ });
2902
3668
 
2903
- expect(z.toJSONSchema(codec, { io: "input" })).toMatchInlineSnapshot(`
3669
+ // A preprocessed property is only optional when its inner schema is — the
3670
+ // transform wrapper must not make a required property optional in the input
3671
+ // JSON schema (matches runtime: `schema.parse({})` rejects `withPreprocess`).
3672
+ expect(z.toJSONSchema(schema, { io: "input" })).toMatchInlineSnapshot(`
2904
3673
  {
2905
3674
  "$schema": "https://json-schema.org/draft/2020-12/schema",
2906
- "type": "string",
2907
- }
2908
- `);
2909
- expect(z.toJSONSchema(codec, { io: "output" })).toMatchInlineSnapshot(`
3675
+ "properties": {
3676
+ "noPreprocess": {
3677
+ "type": "string",
3678
+ },
3679
+ "optionalPreprocess": {
3680
+ "type": "string",
3681
+ },
3682
+ "withPreprocess": {
3683
+ "type": "string",
3684
+ },
3685
+ },
3686
+ "required": [
3687
+ "noPreprocess",
3688
+ "withPreprocess",
3689
+ ],
3690
+ "type": "object",
3691
+ }
3692
+ `);
3693
+ });
3694
+
3695
+ test("input JSON schema resolves requiredness past transform and catch wrappers", () => {
3696
+ const required = (schema: z.ZodObject) =>
3697
+ (z.toJSONSchema(schema, { io: "input" }) as z.core.JSONSchema.ObjectSchema).required;
3698
+ const id = (v: unknown) => v;
3699
+
3700
+ // catch observes an absent key at runtime, but its declared input type stays required (#5003)
3701
+ expect(required(z.object({ a: z.string().catch("x") }))).toEqual(["a"]);
3702
+ expect(required(z.object({ a: z.string().optional().catch("x") }))).toBeUndefined();
3703
+ // nested preprocess and the legacy transform-pipe form both resolve through to the inner schema
3704
+ expect(required(z.object({ a: z.preprocess(id, z.preprocess(id, z.string())) }))).toEqual(["a"]);
3705
+ expect(required(z.object({ a: z.transform((v: unknown) => String(v)).pipe(z.string()) }))).toEqual(["a"]);
3706
+ });
3707
+
3708
+ test("strip output-side examples from input JSON schema for codec", () => {
3709
+ const codec = z
3710
+ .codec(z.string(), z.number(), { decode: (s) => Number(s), encode: (n) => String(n) })
3711
+ .meta({ examples: [42] });
3712
+
3713
+ expect(z.toJSONSchema(codec, { io: "input" })).toMatchInlineSnapshot(`
3714
+ {
3715
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3716
+ "type": "string",
3717
+ }
3718
+ `);
3719
+ expect(z.toJSONSchema(codec, { io: "output" })).toMatchInlineSnapshot(`
2910
3720
  {
2911
3721
  "$schema": "https://json-schema.org/draft/2020-12/schema",
2912
3722
  "examples": [
@@ -2968,45 +3778,25 @@ test("flatten simple intersections", () => {
2968
3778
  expect(result).toMatchInlineSnapshot(`
2969
3779
  {
2970
3780
  "$schema": "http://json-schema.org/draft-07/schema#",
2971
- "allOf": [
2972
- {
2973
- "additionalProperties": false,
2974
- "properties": {
2975
- "testNum": {
2976
- "type": "number",
2977
- },
2978
- },
2979
- "required": [
2980
- "testNum",
2981
- ],
2982
- "type": "object",
3781
+ "additionalProperties": false,
3782
+ "description": "123",
3783
+ "properties": {
3784
+ "testBool": {
3785
+ "type": "boolean",
2983
3786
  },
2984
- {
2985
- "additionalProperties": false,
2986
- "properties": {
2987
- "testStr": {
2988
- "type": "string",
2989
- },
2990
- },
2991
- "required": [
2992
- "testStr",
2993
- ],
2994
- "type": "object",
3787
+ "testNum": {
3788
+ "type": "number",
2995
3789
  },
2996
- {
2997
- "additionalProperties": false,
2998
- "properties": {
2999
- "testBool": {
3000
- "type": "boolean",
3001
- },
3002
- },
3003
- "required": [
3004
- "testBool",
3005
- ],
3006
- "type": "object",
3790
+ "testStr": {
3791
+ "type": "string",
3007
3792
  },
3793
+ },
3794
+ "required": [
3795
+ "testNum",
3796
+ "testStr",
3797
+ "testBool",
3008
3798
  ],
3009
- "description": "123",
3799
+ "type": "object",
3010
3800
  }
3011
3801
  `);
3012
3802
  });
@@ -3123,3 +3913,625 @@ test("recursive lazy with describe does not stack overflow", () => {
3123
3913
  expect(result).toBeDefined();
3124
3914
  expect(result.$defs).toBeDefined();
3125
3915
  });
3916
+
3917
+ test("__proto__ shape key is emitted as an own property", () => {
3918
+ const schema = z.object({ ["__proto__"]: z.literal("admin"), role: z.string() });
3919
+ const result = z.toJSONSchema(schema, { io: "input" });
3920
+
3921
+ expect(result.required).toEqual(["__proto__", "role"]);
3922
+ // every required key needs a matching entry in properties
3923
+ for (const key of result.required!) {
3924
+ expect(Object.prototype.hasOwnProperty.call(result.properties, key)).toBe(true);
3925
+ }
3926
+ expect(JSON.parse(JSON.stringify(result)).properties.__proto__).toEqual({ type: "string", const: "admin" });
3927
+ });
3928
+
3929
+ test("__proto__ registry id is emitted as an own entry", () => {
3930
+ const myRegistry = z.registry<{ id: string }>();
3931
+ myRegistry.add(z.object({ a: z.string() }), { id: "__proto__" });
3932
+ myRegistry.add(z.object({ b: z.string() }), { id: "normal" });
3933
+
3934
+ expect(Object.keys(z.toJSONSchema(myRegistry).schemas)).toEqual(["__proto__", "normal"]);
3935
+ });
3936
+
3937
+ test("__proto__ def id emits a resolvable $ref", () => {
3938
+ const myRegistry = z.registry<{ id: string }>();
3939
+ const Inner = z.object({ x: z.string() });
3940
+ myRegistry.add(Inner, { id: "__proto__" });
3941
+
3942
+ const json = JSON.parse(JSON.stringify(z.toJSONSchema(z.object({ a: Inner, b: Inner }), { metadata: myRegistry })));
3943
+ expect(json.properties.a.$ref).toBe("#/$defs/__proto__");
3944
+ expect(json.$defs.__proto__).toBeDefined();
3945
+ });
3946
+
3947
+ test("__proto__ patternProperties key is emitted as an own property", () => {
3948
+ const result = z.toJSONSchema(z.looseRecord(z.string().regex(/__proto__/), z.string()));
3949
+
3950
+ expect(Object.getPrototypeOf(result.patternProperties)).toBe(Object.prototype);
3951
+ expect(Object.prototype.hasOwnProperty.call(result.patternProperties, "__proto__")).toBe(true);
3952
+ expect(result.patternProperties?.__proto__).toEqual({ type: "string" });
3953
+ });
3954
+
3955
+ test("__proto__ metadata survives direct and wrapper metadata merges", () => {
3956
+ for (const schema of [z.string(), z.readonly(z.string())]) {
3957
+ const registry = z.registry<Record<string, unknown>>();
3958
+ registry.add(schema, Object.fromEntries([["__proto__", { marker: true }]]));
3959
+
3960
+ const result: any = z.toJSONSchema(schema, { metadata: registry });
3961
+ expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
3962
+ expect(Object.prototype.hasOwnProperty.call(result, "__proto__")).toBe(true);
3963
+ expect(result.__proto__).toEqual({ marker: true });
3964
+ expect(JSON.parse(JSON.stringify(result)).__proto__).toEqual({ marker: true });
3965
+ }
3966
+ });
3967
+
3968
+ test("partialRecord does not require finite keys", () => {
3969
+ const result = z.toJSONSchema(z.partialRecord(z.enum(["__proto__", "b"]), z.string()));
3970
+
3971
+ expect(result.required).toBeUndefined();
3972
+ expect(result.propertyNames).toEqual({ type: "string", enum: ["__proto__", "b"] });
3973
+ expect(result.additionalProperties).toEqual({ type: "string" });
3974
+ });
3975
+
3976
+ describe("unrepresentable callback", () => {
3977
+ test("is consulted for every unrepresentable type", () => {
3978
+ const seen: string[] = [];
3979
+ const collect: z.core.UnrepresentableHandler<z.core.$ZodTypes> = ({ zodSchema }) => {
3980
+ seen.push(zodSchema._zod.def.type);
3981
+ return "any";
3982
+ };
3983
+
3984
+ const schemas = [
3985
+ z.bigint(),
3986
+ z.symbol(),
3987
+ z.undefined(),
3988
+ z.void(),
3989
+ z.date(),
3990
+ z.nan(),
3991
+ z.custom<string>(),
3992
+ z.map(z.string(), z.string()),
3993
+ z.set(z.string()),
3994
+ z.transform((x: unknown) => x),
3995
+ z.literal([undefined]),
3996
+ z.literal([1n]),
3997
+ z.string().catch(() => {
3998
+ throw new Error("dynamic");
3999
+ }),
4000
+ // z.function() is not a ZodType, but its processor is reachable through the same path
4001
+ z.function() as unknown as z.ZodType,
4002
+ ];
4003
+ for (const schema of schemas) z.toJSONSchema(schema, { unrepresentable: collect });
4004
+
4005
+ expect(seen).toEqual([
4006
+ "bigint",
4007
+ "symbol",
4008
+ "undefined",
4009
+ "void",
4010
+ "date",
4011
+ "nan",
4012
+ "custom",
4013
+ "map",
4014
+ "set",
4015
+ "transform",
4016
+ "literal",
4017
+ "literal",
4018
+ "catch",
4019
+ "function",
4020
+ ]);
4021
+ });
4022
+
4023
+ test("returned JSON Schema replaces the unrepresentable node", () => {
4024
+ // the motivating case: represent dates, keep throwing for everything else
4025
+ const params: z.core.ToJSONSchemaParams = {
4026
+ unrepresentable: ({ zodSchema }) =>
4027
+ zodSchema._zod.def.type === "date" ? { type: "string", format: "date-time" } : "throw",
4028
+ };
4029
+ expect(z.toJSONSchema(z.object({ when: z.date() }), params)).toMatchInlineSnapshot(`
4030
+ {
4031
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4032
+ "additionalProperties": false,
4033
+ "properties": {
4034
+ "when": {
4035
+ "format": "date-time",
4036
+ "type": "string",
4037
+ },
4038
+ },
4039
+ "required": [
4040
+ "when",
4041
+ ],
4042
+ "type": "object",
4043
+ }
4044
+ `);
4045
+ expect(() => z.toJSONSchema(z.object({ id: z.bigint() }), params)).toThrow(
4046
+ "BigInt cannot be represented in JSON Schema"
4047
+ );
4048
+ });
4049
+
4050
+ test("`throw` and `undefined` returns produce the default error", () => {
4051
+ expect(() => z.toJSONSchema(z.date(), { unrepresentable: () => "throw" })).toThrow(
4052
+ "Date cannot be represented in JSON Schema"
4053
+ );
4054
+ expect(() => z.toJSONSchema(z.date(), { unrepresentable: () => undefined })).toThrow(
4055
+ "Date cannot be represented in JSON Schema"
4056
+ );
4057
+ });
4058
+
4059
+ test("`any` return matches the string option", () => {
4060
+ expect(z.toJSONSchema(z.date(), { unrepresentable: () => "any" })).toEqual(
4061
+ z.toJSONSchema(z.date(), { unrepresentable: "any" })
4062
+ );
4063
+ });
4064
+
4065
+ test("`message` distinguishes sites that share a schema", () => {
4066
+ const seen: string[] = [];
4067
+ expect(
4068
+ z.toJSONSchema(z.literal([undefined, 1n, "a"]), {
4069
+ unrepresentable: ({ zodSchema, message }) => {
4070
+ seen.push(`${zodSchema._zod.def.type}: ${message}`);
4071
+ return "any";
4072
+ },
4073
+ })
4074
+ ).toMatchInlineSnapshot(`
4075
+ {
4076
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4077
+ "enum": [
4078
+ 1,
4079
+ "a",
4080
+ ],
4081
+ }
4082
+ `);
4083
+ // same `zodSchema`, different message -- the only way to tell the two literal sites apart
4084
+ expect(seen).toEqual([
4085
+ "literal: Literal `undefined` cannot be represented in JSON Schema",
4086
+ "literal: BigInt literals cannot be represented in JSON Schema",
4087
+ ]);
4088
+ });
4089
+
4090
+ test("errors thrown by the callback propagate", () => {
4091
+ expect(() =>
4092
+ z.toJSONSchema(z.object({ when: z.date() }), {
4093
+ unrepresentable: ({ zodSchema, path }) => {
4094
+ throw new Error(`${zodSchema._zod.def.type} at /${path.join("/")}`);
4095
+ },
4096
+ })
4097
+ ).toThrow("date at /properties/when");
4098
+ });
4099
+
4100
+ test("runs before `override`", () => {
4101
+ const order: string[] = [];
4102
+ expect(
4103
+ z.toJSONSchema(z.date(), {
4104
+ unrepresentable: () => {
4105
+ order.push("unrepresentable");
4106
+ return { type: "string" };
4107
+ },
4108
+ override: (ctx) => {
4109
+ order.push("override");
4110
+ if (ctx.jsonSchema.type === "string") ctx.jsonSchema.format = "date-time";
4111
+ },
4112
+ })
4113
+ ).toMatchInlineSnapshot(`
4114
+ {
4115
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4116
+ "format": "date-time",
4117
+ "type": "string",
4118
+ }
4119
+ `);
4120
+ expect(order).toEqual(["unrepresentable", "override"]);
4121
+ });
4122
+
4123
+ test("a returned schema replaces the whole literal", () => {
4124
+ expect(
4125
+ z.toJSONSchema(z.literal(["a", 1n]), {
4126
+ unrepresentable: () => ({ type: "string", pattern: "^\\d+$" }),
4127
+ })
4128
+ ).toMatchInlineSnapshot(`
4129
+ {
4130
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4131
+ "pattern": "^\\d+$",
4132
+ "type": "string",
4133
+ }
4134
+ `);
4135
+
4136
+ // "any" keeps the existing per-value behavior: undefined dropped, bigint coerced
4137
+ expect(z.toJSONSchema(z.literal(["a", 1n, undefined]), { unrepresentable: () => "any" })).toEqual(
4138
+ z.toJSONSchema(z.literal(["a", 1n, undefined]), { unrepresentable: "any" })
4139
+ );
4140
+ });
4141
+
4142
+ const dateToString: z.core.ToJSONSchemaParams["unrepresentable"] = ({ zodSchema }) =>
4143
+ zodSchema._zod.def.type === "date" ? { type: "string", format: "date-time" } : "throw";
4144
+
4145
+ test("emits a valid OpenAPI 3.0 schema", async () => {
4146
+ const jsonSchema = z.toJSONSchema(z.object({ start: z.date() }), {
4147
+ target: "openapi-3.0",
4148
+ unrepresentable: dateToString,
4149
+ });
4150
+ expect(jsonSchema).toMatchInlineSnapshot(`
4151
+ {
4152
+ "additionalProperties": false,
4153
+ "properties": {
4154
+ "start": {
4155
+ "format": "date-time",
4156
+ "type": "string",
4157
+ },
4158
+ },
4159
+ "required": [
4160
+ "start",
4161
+ ],
4162
+ "type": "object",
4163
+ }
4164
+ `);
4165
+ await expect(validateOpenAPI30Schema(jsonSchema)).resolves.toBe(true);
4166
+ });
4167
+
4168
+ test("the returned schema survives extraction into $defs", () => {
4169
+ const When = z.date().meta({ id: "When" });
4170
+ expect(
4171
+ z.toJSONSchema(z.object({ start: When, end: When }), { unrepresentable: dateToString })
4172
+ ).toMatchInlineSnapshot(`
4173
+ {
4174
+ "$defs": {
4175
+ "When": {
4176
+ "format": "date-time",
4177
+ "type": "string",
4178
+ },
4179
+ },
4180
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4181
+ "additionalProperties": false,
4182
+ "properties": {
4183
+ "end": {
4184
+ "$ref": "#/$defs/When",
4185
+ },
4186
+ "start": {
4187
+ "$ref": "#/$defs/When",
4188
+ },
4189
+ },
4190
+ "required": [
4191
+ "start",
4192
+ "end",
4193
+ ],
4194
+ "type": "object",
4195
+ }
4196
+ `);
4197
+ });
4198
+
4199
+ test("applies to dynamic catch values", () => {
4200
+ const schema = z.string().catch(() => {
4201
+ throw new Error("dynamic");
4202
+ });
4203
+ expect(
4204
+ z.toJSONSchema(schema, {
4205
+ unrepresentable: () => ({ default: "fallback" }),
4206
+ })
4207
+ ).toMatchInlineSnapshot(`
4208
+ {
4209
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4210
+ "default": "fallback",
4211
+ "type": "string",
4212
+ }
4213
+ `);
4214
+ });
4215
+ });
4216
+
4217
+ describe("intersection folding", () => {
4218
+ const TARGETS = ["draft-2020-12", "draft-07", "draft-04", "openapi-3.0"] as const;
4219
+ const body = (schema: z.ZodType, params?: Parameters<typeof z.toJSONSchema>[1]) => {
4220
+ const { $schema, ...rest } = z.toJSONSchema(schema, params) as Record<string, unknown>;
4221
+ return rest;
4222
+ };
4223
+
4224
+ test("two objects become one object", () => {
4225
+ expect(body(z.object({ name: z.string() }).and(z.object({ age: z.number() })))).toMatchInlineSnapshot(`
4226
+ {
4227
+ "additionalProperties": false,
4228
+ "properties": {
4229
+ "age": {
4230
+ "type": "number",
4231
+ },
4232
+ "name": {
4233
+ "type": "string",
4234
+ },
4235
+ },
4236
+ "required": [
4237
+ "name",
4238
+ "age",
4239
+ ],
4240
+ "type": "object",
4241
+ }
4242
+ `);
4243
+ });
4244
+
4245
+ test("the folded shape is identical on every target", () => {
4246
+ const schema = z.object({ name: z.string() }).and(z.object({ age: z.number() }));
4247
+ const bodies = TARGETS.map((target) => body(schema, { target }));
4248
+ for (const emitted of bodies) expect(emitted).toEqual(bodies[0]);
4249
+ });
4250
+
4251
+ test("closed only when every member is closed", () => {
4252
+ expect(body(z.strictObject({ a: z.string() }).and(z.strictObject({ b: z.number() })))).toMatchObject({
4253
+ additionalProperties: false,
4254
+ });
4255
+ // A loose member keeps the intersection open, which is what the parser does: it merges both results, so the loose side's extra keys survive.
4256
+ expect(body(z.looseObject({ a: z.string() }).and(z.object({ b: z.number() })))).not.toHaveProperty(
4257
+ "additionalProperties"
4258
+ );
4259
+ });
4260
+
4261
+ test("chained and nested intersections fold flat", () => {
4262
+ const chained = z
4263
+ .object({ a: z.string() })
4264
+ .and(z.object({ b: z.string() }))
4265
+ .and(z.object({ c: z.string() }));
4266
+ expect(body(chained)).toMatchObject({ properties: { a: {}, b: {}, c: {} }, required: ["a", "b", "c"] });
4267
+ const nested = z.object({ a: z.string() }).and(z.object({ b: z.string() }).and(z.object({ c: z.string() })));
4268
+ expect(body(nested)).toEqual(body(chained));
4269
+ });
4270
+
4271
+ test("required is the union, and an optional key stays optional", () => {
4272
+ expect(body(z.object({ a: z.string().optional() }).and(z.object({ b: z.string() })))).toMatchObject({
4273
+ properties: { a: { type: "string" }, b: { type: "string" } },
4274
+ required: ["b"],
4275
+ });
4276
+ });
4277
+
4278
+ test("a key both members declare has to satisfy both", () => {
4279
+ // identical declarations collapse
4280
+ expect(body(z.object({ k: z.string() }).and(z.object({ k: z.string() })))).toMatchObject({
4281
+ properties: { k: { type: "string" } },
4282
+ });
4283
+ // object declarations fold, matching the parser's deep merge
4284
+ expect(
4285
+ body(z.object({ k: z.object({ a: z.string() }) }).and(z.object({ k: z.object({ b: z.string() }) })))
4286
+ ).toMatchObject({
4287
+ properties: { k: { type: "object", properties: { a: {}, b: {} }, required: ["a", "b"] } },
4288
+ });
4289
+ // anything else stays an intersection one level down
4290
+ expect(body(z.object({ k: z.string() }).and(z.object({ k: z.number() })))).toMatchObject({
4291
+ properties: { k: { allOf: [{ type: "string" }, { type: "number" }] } },
4292
+ });
4293
+ });
4294
+
4295
+ test("an intersection distributes over a union", () => {
4296
+ const schema = z
4297
+ .object({ name: z.string() })
4298
+ .and(
4299
+ z.discriminatedUnion("type", [
4300
+ z.object({ type: z.literal("a"), value: z.string() }),
4301
+ z.object({ type: z.literal("b"), count: z.number() }),
4302
+ ])
4303
+ );
4304
+ expect(body(schema)).toMatchObject({
4305
+ oneOf: [
4306
+ { type: "object", properties: { name: {}, type: {}, value: {} }, additionalProperties: false },
4307
+ { type: "object", properties: { name: {}, type: {}, count: {} }, additionalProperties: false },
4308
+ ],
4309
+ });
4310
+ const inclusive = z
4311
+ .object({ name: z.string() })
4312
+ .and(z.union([z.object({ v: z.string() }), z.object({ c: z.number() })]));
4313
+ expect(body(inclusive)).toMatchObject({
4314
+ anyOf: [{ properties: { name: {}, v: {} } }, { properties: { name: {}, c: {} } }],
4315
+ });
4316
+ });
4317
+
4318
+ test("input conversion has nothing to close", () => {
4319
+ expect(body(z.object({ a: z.string() }).and(z.object({ b: z.string() })), { io: "input" })).toEqual({
4320
+ type: "object",
4321
+ properties: { a: { type: "string" }, b: { type: "string" } },
4322
+ required: ["a", "b"],
4323
+ });
4324
+ });
4325
+
4326
+ test("folds through a property and through z.lazy", () => {
4327
+ expect(body(z.object({ inner: z.object({ a: z.string() }).and(z.object({ b: z.string() })) }))).toMatchObject({
4328
+ properties: { inner: { type: "object", properties: { a: {}, b: {} } } },
4329
+ });
4330
+ const self: z.ZodType = z.lazy(() => z.object({ a: z.string() }).and(z.object({ next: z.optional(self) })));
4331
+ expect(body(self)).toMatchObject({ type: "object", properties: { a: {}, next: { $ref: "#" } } });
4332
+ });
4333
+
4334
+ test("metadata on the intersection itself survives", () => {
4335
+ expect(
4336
+ body(
4337
+ z
4338
+ .object({ a: z.string() })
4339
+ .and(z.object({ b: z.string() }))
4340
+ .meta({ title: "T" })
4341
+ )
4342
+ ).toMatchObject({
4343
+ title: "T",
4344
+ type: "object",
4345
+ properties: { a: {}, b: {} },
4346
+ });
4347
+ });
4348
+
4349
+ test("a catchall constrains the sibling's keys too", () => {
4350
+ // The catchall member does not declare `b`, so its `additionalProperties` is what it demands of `b`. Folding `b` into `properties` has to carry that demand across, or the key would escape it.
4351
+ const schema = z
4352
+ .object({ a: z.string() })
4353
+ .catchall(z.number())
4354
+ .and(z.object({ b: z.string() }));
4355
+ expect(body(schema)).toEqual({
4356
+ type: "object",
4357
+ properties: { a: { type: "string" }, b: { allOf: [{ type: "number" }, { type: "string" }] } },
4358
+ required: ["a", "b"],
4359
+ additionalProperties: { type: "number" },
4360
+ });
4361
+ });
4362
+
4363
+ test("two catchalls both constrain the keys neither declares", () => {
4364
+ const schema = z
4365
+ .object({})
4366
+ .catchall(z.number())
4367
+ .and(z.object({}).catchall(z.number().min(0)));
4368
+ expect(body(schema)).toEqual({
4369
+ type: "object",
4370
+ properties: {},
4371
+ additionalProperties: { allOf: [{ type: "number" }, { type: "number", minimum: 0 }] },
4372
+ });
4373
+ expect(schema.safeParse({ zz: 5 }).success).toBe(true);
4374
+ expect(schema.safeParse({ zz: -1 }).success).toBe(false);
4375
+ });
4376
+
4377
+ test("the emitted openness agrees with the parser for every pair of object modes", () => {
4378
+ const modes = {
4379
+ strip: (shape: z.ZodRawShape) => z.object(shape),
4380
+ strict: (shape: z.ZodRawShape) => z.strictObject(shape),
4381
+ loose: (shape: z.ZodRawShape) => z.looseObject(shape),
4382
+ catchall: (shape: z.ZodRawShape) => z.object(shape).catchall(z.number()),
4383
+ };
4384
+ const grid: Record<string, unknown> = {};
4385
+ for (const [leftName, left] of Object.entries(modes)) {
4386
+ for (const [rightName, right] of Object.entries(modes)) {
4387
+ const schema = left({ a: z.string() }).and(right({ b: z.number() }));
4388
+ const emitted = body(schema) as { additionalProperties?: unknown };
4389
+ grid[`${leftName} & ${rightName}`] = emitted.additionalProperties ?? "open";
4390
+
4391
+ // Whatever the emitted keyword says, it has to agree with what the parser does with a key neither member declares.
4392
+ const parsed = schema.safeParse({ a: "s", b: 1, zz: 7 });
4393
+ const keepsUnknown = parsed.success && Object.prototype.hasOwnProperty.call(parsed.data, "zz");
4394
+ if (keepsUnknown) expect(emitted.additionalProperties).not.toBe(false);
4395
+ }
4396
+ }
4397
+ expect(grid).toMatchInlineSnapshot(`
4398
+ {
4399
+ "catchall & catchall": {
4400
+ "type": "number",
4401
+ },
4402
+ "catchall & loose": {
4403
+ "type": "number",
4404
+ },
4405
+ "catchall & strict": {
4406
+ "type": "number",
4407
+ },
4408
+ "catchall & strip": {
4409
+ "type": "number",
4410
+ },
4411
+ "loose & catchall": {
4412
+ "type": "number",
4413
+ },
4414
+ "loose & loose": "open",
4415
+ "loose & strict": "open",
4416
+ "loose & strip": "open",
4417
+ "strict & catchall": {
4418
+ "type": "number",
4419
+ },
4420
+ "strict & loose": "open",
4421
+ "strict & strict": false,
4422
+ "strict & strip": false,
4423
+ "strip & catchall": {
4424
+ "type": "number",
4425
+ },
4426
+ "strip & loose": "open",
4427
+ "strip & strict": false,
4428
+ "strip & strip": false,
4429
+ }
4430
+ `);
4431
+ });
4432
+
4433
+ test("a __proto__ key stays an own property", () => {
4434
+ const folded = body(z.object({ ["__proto__"]: z.string() }).and(z.object({ b: z.number() }))) as any;
4435
+ expect(Object.prototype.hasOwnProperty.call(folded.properties, "__proto__")).toBe(true);
4436
+ expect(folded.required).toEqual(["__proto__", "b"]);
4437
+ });
4438
+ });
4439
+
4440
+ describe("intersection folding declines", () => {
4441
+ // Every case here keeps the `allOf` it produces today. The fold only understands the four object keywords, so a member carrying anything else is left alone rather than having a constraint dropped or an annotation re-scoped.
4442
+ const allOf = (schema: z.ZodType, params?: Parameters<typeof z.toJSONSchema>[1]) =>
4443
+ (z.toJSONSchema(schema, params) as any).allOf;
4444
+
4445
+ test("a member that is a reference keeps its reference", () => {
4446
+ const named = z.object({ a: z.string() }).meta({ id: "Named" });
4447
+ expect(allOf(named.and(z.object({ b: z.string() })))[0]).toEqual({ $ref: "#/$defs/Named" });
4448
+
4449
+ const shared = z.object({ c: z.string() });
4450
+ const reused = z.toJSONSchema(z.object({ x: shared.and(z.object({ d: z.string() })), y: shared }), {
4451
+ reused: "ref",
4452
+ }) as any;
4453
+ expect(reused.properties.x.allOf[0]).toEqual({ $ref: "#/$defs/__schema0" });
4454
+
4455
+ const cyclic: any = z.object({
4456
+ get next() {
4457
+ return z.optional(cyclic);
4458
+ },
4459
+ n: z.string(),
4460
+ });
4461
+ expect(allOf(cyclic.and(z.object({ m: z.string() })))[0].$ref).toBe("#/$defs/__schema0");
4462
+ });
4463
+
4464
+ test("an annotated member keeps its place", () => {
4465
+ expect(
4466
+ allOf(
4467
+ z
4468
+ .object({ a: z.string() })
4469
+ .describe("A")
4470
+ .and(z.object({ b: z.string() }))
4471
+ )[0]
4472
+ ).toMatchObject({
4473
+ description: "A",
4474
+ });
4475
+ });
4476
+
4477
+ test("members that are not plain objects are left alone", () => {
4478
+ expect(allOf(z.intersection(z.string().min(2), z.string().max(5)))).toHaveLength(2);
4479
+ expect(allOf(z.object({ a: z.string() }).and(z.nullable(z.object({ b: z.string() }))))).toHaveLength(2);
4480
+ expect(
4481
+ allOf(z.object({ label: z.string() }).and(z.looseRecord(z.string().regex(/^label:[a-z]{2}$/), z.string())))
4482
+ ).toHaveLength(2);
4483
+ });
4484
+
4485
+ test("a shared member is never rewritten for its other uses", () => {
4486
+ const shared = z.object({ c: z.string() });
4487
+ const result = z.toJSONSchema(z.object({ x: shared.and(z.object({ d: z.string() })), y: shared })) as any;
4488
+ expect(result.properties.x).toMatchObject({ properties: { c: {}, d: {} }, additionalProperties: false });
4489
+ // `y` is the same Zod schema, emitted separately, and keeps the closedness it had on its own.
4490
+ expect(result.properties.y).toEqual({
4491
+ type: "object",
4492
+ properties: { c: { type: "string" } },
4493
+ required: ["c"],
4494
+ additionalProperties: false,
4495
+ });
4496
+ });
4497
+
4498
+ test("registry conversion keeps its cross-references", () => {
4499
+ const registry = z.registry<{ id: string }>();
4500
+ const left = z.object({ p: z.string() });
4501
+ const right = z.object({ q: z.string() });
4502
+ registry.add(left, { id: "P" });
4503
+ registry.add(right, { id: "Q" });
4504
+ registry.add(left.and(right), { id: "PQ" });
4505
+ expect((z.toJSONSchema(registry) as any).schemas.PQ.allOf).toEqual([{ $ref: "P" }, { $ref: "Q" }]);
4506
+ });
4507
+
4508
+ test("override still runs, and sees the intersection before it folds", () => {
4509
+ const schema = z.object({ a: z.string() }).and(z.object({ b: z.string() }));
4510
+ const result = z.toJSONSchema(schema, {
4511
+ override(ctx) {
4512
+ if ((ctx.jsonSchema as any).allOf) (ctx.jsonSchema as any).title = "intersection";
4513
+ },
4514
+ }) as any;
4515
+ expect(result).toMatchObject({ title: "intersection", type: "object", properties: { a: {}, b: {} } });
4516
+ });
4517
+
4518
+ test("an override that writes object keywords wins over the fold", () => {
4519
+ // The override runs first, so anything it puts on the intersection is deliberate. Folding would overwrite it silently, so the fold stands down instead.
4520
+ const result = z.toJSONSchema(z.object({ a: z.string() }).and(z.object({ b: z.string() })), {
4521
+ override(ctx) {
4522
+ if ((ctx.jsonSchema as any).allOf) (ctx.jsonSchema as any).additionalProperties = true;
4523
+ },
4524
+ }) as any;
4525
+ expect(result.additionalProperties).toBe(true);
4526
+ expect(result.allOf).toHaveLength(2);
4527
+ });
4528
+
4529
+ test("more than one union member is left alone rather than multiplied out", () => {
4530
+ // The second union lands among the members the first is distributed across, and a union is not an object, so every branch fails to fold and the whole intersection stands down.
4531
+ const schema = z
4532
+ .object({ a: z.string() })
4533
+ .and(z.union([z.object({ v: z.string() }), z.object({ w: z.string() })]))
4534
+ .and(z.union([z.object({ x: z.string() }), z.object({ y: z.string() })]));
4535
+ expect(allOf(schema)).toHaveLength(3);
4536
+ });
4537
+ });