@tambo-ai/react 0.68.0 → 0.69.1

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 (326) hide show
  1. package/README.md +1 -1
  2. package/dist/context-helpers/context-helpers.test.js +16 -4
  3. package/dist/context-helpers/context-helpers.test.js.map +1 -1
  4. package/dist/context-helpers/current-interactables-context-helper.d.ts +2 -2
  5. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  6. package/dist/context-helpers/current-interactables-context-helper.js +31 -15
  7. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
  8. package/dist/context-helpers/registry.d.ts +2 -2
  9. package/dist/context-helpers/registry.d.ts.map +1 -1
  10. package/dist/context-helpers/registry.js.map +1 -1
  11. package/dist/context-helpers/types.d.ts +2 -2
  12. package/dist/context-helpers/types.d.ts.map +1 -1
  13. package/dist/context-helpers/types.js.map +1 -1
  14. package/dist/hooks/use-message-images.test.js +174 -37
  15. package/dist/hooks/use-message-images.test.js.map +1 -1
  16. package/dist/hooks/use-tambo-voice.d.ts +1 -1
  17. package/dist/hooks/use-tambo-voice.js +1 -1
  18. package/dist/hooks/use-tambo-voice.js.map +1 -1
  19. package/dist/hooks/use-tambo-voice.test.d.ts +2 -0
  20. package/dist/hooks/use-tambo-voice.test.d.ts.map +1 -0
  21. package/dist/hooks/use-tambo-voice.test.js +239 -0
  22. package/dist/hooks/use-tambo-voice.test.js.map +1 -0
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/mcp/elicitation.d.ts.map +1 -1
  27. package/dist/mcp/elicitation.js +12 -0
  28. package/dist/mcp/elicitation.js.map +1 -1
  29. package/dist/mcp/elicitation.test.js +8 -1
  30. package/dist/mcp/elicitation.test.js.map +1 -1
  31. package/dist/mcp/mcp-client.d.ts +6 -10
  32. package/dist/mcp/mcp-client.d.ts.map +1 -1
  33. package/dist/mcp/mcp-client.js.map +1 -1
  34. package/dist/mcp/mcp-hooks.d.ts +12 -60
  35. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  36. package/dist/mcp/mcp-hooks.js +90 -10
  37. package/dist/mcp/mcp-hooks.js.map +1 -1
  38. package/dist/mcp/mcp-hooks.test.js +423 -0
  39. package/dist/mcp/mcp-hooks.test.js.map +1 -1
  40. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  41. package/dist/mcp/tambo-mcp-provider.js +3 -0
  42. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  43. package/dist/mcp/tambo-mcp-provider.test.js +37 -0
  44. package/dist/mcp/tambo-mcp-provider.test.js.map +1 -1
  45. package/dist/model/component-metadata.d.ts +53 -20
  46. package/dist/model/component-metadata.d.ts.map +1 -1
  47. package/dist/model/component-metadata.js.map +1 -1
  48. package/dist/model/tambo-interactable.d.ts +6 -0
  49. package/dist/model/tambo-interactable.d.ts.map +1 -1
  50. package/dist/model/tambo-interactable.js.map +1 -1
  51. package/dist/providers/index.d.ts +1 -1
  52. package/dist/providers/index.d.ts.map +1 -1
  53. package/dist/providers/index.js.map +1 -1
  54. package/dist/providers/tambo-client-provider.d.ts +8 -0
  55. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  56. package/dist/providers/tambo-client-provider.js +10 -11
  57. package/dist/providers/tambo-client-provider.js.map +1 -1
  58. package/dist/providers/tambo-client-provider.test.d.ts +2 -0
  59. package/dist/providers/tambo-client-provider.test.d.ts.map +1 -0
  60. package/dist/providers/tambo-client-provider.test.js +208 -0
  61. package/dist/providers/tambo-client-provider.test.js.map +1 -0
  62. package/dist/providers/tambo-context-attachment-provider.d.ts +34 -92
  63. package/dist/providers/tambo-context-attachment-provider.d.ts.map +1 -1
  64. package/dist/providers/tambo-context-attachment-provider.js +62 -105
  65. package/dist/providers/tambo-context-attachment-provider.js.map +1 -1
  66. package/dist/providers/tambo-context-attachment-provider.test.js +229 -463
  67. package/dist/providers/tambo-context-attachment-provider.test.js.map +1 -1
  68. package/dist/providers/tambo-interactable-provider.d.ts +2 -0
  69. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  70. package/dist/providers/tambo-interactable-provider.js +29 -4
  71. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  72. package/dist/providers/tambo-interactable-provider.test.js +1 -1
  73. package/dist/providers/tambo-interactable-provider.test.js.map +1 -1
  74. package/dist/providers/tambo-interactables-additional-context.test.js +2 -5
  75. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  76. package/dist/providers/tambo-provider.d.ts +2 -3
  77. package/dist/providers/tambo-provider.d.ts.map +1 -1
  78. package/dist/providers/tambo-provider.js +5 -6
  79. package/dist/providers/tambo-provider.js.map +1 -1
  80. package/dist/providers/tambo-registry-provider.test.js +16 -0
  81. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  82. package/dist/providers/tambo-registry-schema-compat.test.js +31 -0
  83. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  84. package/dist/providers/tambo-thread-input-provider.d.ts +1 -1
  85. package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
  86. package/dist/providers/tambo-thread-input-provider.js +5 -1
  87. package/dist/providers/tambo-thread-input-provider.js.map +1 -1
  88. package/dist/providers/tambo-thread-provider-initial-messages.test.js +84 -2
  89. package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  90. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  91. package/dist/providers/tambo-thread-provider.js +56 -43
  92. package/dist/providers/tambo-thread-provider.js.map +1 -1
  93. package/dist/providers/tambo-thread-provider.test.js +456 -262
  94. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  95. package/dist/schema/json-schema.js +29 -29
  96. package/dist/schema/json-schema.js.map +1 -1
  97. package/dist/schema/schema.test.js +237 -0
  98. package/dist/schema/schema.test.js.map +1 -1
  99. package/dist/schema/standard-schema.d.ts +1 -0
  100. package/dist/schema/standard-schema.d.ts.map +1 -1
  101. package/dist/schema/standard-schema.js +18 -13
  102. package/dist/schema/standard-schema.js.map +1 -1
  103. package/dist/schema/standard-schema.test.d.ts +2 -0
  104. package/dist/schema/standard-schema.test.d.ts.map +1 -0
  105. package/dist/schema/standard-schema.test.js +165 -0
  106. package/dist/schema/standard-schema.test.js.map +1 -0
  107. package/dist/schema/validate.test.js +149 -0
  108. package/dist/schema/validate.test.js.map +1 -1
  109. package/dist/schema/zod.d.ts +7 -4
  110. package/dist/schema/zod.d.ts.map +1 -1
  111. package/dist/schema/zod.js +65 -22
  112. package/dist/schema/zod.js.map +1 -1
  113. package/dist/schema/zod.test.js +112 -0
  114. package/dist/schema/zod.test.js.map +1 -1
  115. package/dist/testing/tools.d.ts +4 -1
  116. package/dist/testing/tools.d.ts.map +1 -1
  117. package/dist/testing/tools.js +6 -1
  118. package/dist/testing/tools.js.map +1 -1
  119. package/dist/util/generate-component.d.ts.map +1 -1
  120. package/dist/util/generate-component.js +18 -3
  121. package/dist/util/generate-component.js.map +1 -1
  122. package/dist/util/generate-component.test.d.ts +2 -0
  123. package/dist/util/generate-component.test.d.ts.map +1 -0
  124. package/dist/util/generate-component.test.js +340 -0
  125. package/dist/util/generate-component.test.js.map +1 -0
  126. package/dist/util/is-promise.d.ts +9 -0
  127. package/dist/util/is-promise.d.ts.map +1 -0
  128. package/dist/util/is-promise.js +20 -0
  129. package/dist/util/is-promise.js.map +1 -0
  130. package/dist/util/is-promise.test.d.ts +2 -0
  131. package/dist/util/is-promise.test.d.ts.map +1 -0
  132. package/dist/util/is-promise.test.js +48 -0
  133. package/dist/util/is-promise.test.js.map +1 -0
  134. package/dist/util/query-utils.test.d.ts +2 -0
  135. package/dist/util/query-utils.test.d.ts.map +1 -0
  136. package/dist/util/query-utils.test.js +382 -0
  137. package/dist/util/query-utils.test.js.map +1 -0
  138. package/dist/util/registry-validators.d.ts.map +1 -1
  139. package/dist/util/registry-validators.js +7 -0
  140. package/dist/util/registry-validators.js.map +1 -1
  141. package/dist/util/registry-validators.test.js +57 -0
  142. package/dist/util/registry-validators.test.js.map +1 -1
  143. package/dist/util/registry.d.ts.map +1 -1
  144. package/dist/util/registry.js +9 -0
  145. package/dist/util/registry.js.map +1 -1
  146. package/dist/util/registry.test.js +323 -1
  147. package/dist/util/registry.test.js.map +1 -1
  148. package/dist/util/resource-validators.test.d.ts +2 -0
  149. package/dist/util/resource-validators.test.d.ts.map +1 -0
  150. package/dist/util/resource-validators.test.js +90 -0
  151. package/dist/util/resource-validators.test.js.map +1 -0
  152. package/dist/util/tool-caller.d.ts +2 -2
  153. package/dist/util/tool-caller.d.ts.map +1 -1
  154. package/dist/util/tool-caller.js +8 -8
  155. package/dist/util/tool-caller.js.map +1 -1
  156. package/dist/util/validate-component-name.test.d.ts +2 -0
  157. package/dist/util/validate-component-name.test.d.ts.map +1 -0
  158. package/dist/util/validate-component-name.test.js +35 -0
  159. package/dist/util/validate-component-name.test.js.map +1 -0
  160. package/esm/context-helpers/context-helpers.test.js +16 -4
  161. package/esm/context-helpers/context-helpers.test.js.map +1 -1
  162. package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
  163. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  164. package/esm/context-helpers/current-interactables-context-helper.js +31 -15
  165. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  166. package/esm/context-helpers/registry.d.ts +2 -2
  167. package/esm/context-helpers/registry.d.ts.map +1 -1
  168. package/esm/context-helpers/registry.js.map +1 -1
  169. package/esm/context-helpers/types.d.ts +2 -2
  170. package/esm/context-helpers/types.d.ts.map +1 -1
  171. package/esm/context-helpers/types.js.map +1 -1
  172. package/esm/hooks/use-message-images.test.js +174 -37
  173. package/esm/hooks/use-message-images.test.js.map +1 -1
  174. package/esm/hooks/use-tambo-voice.d.ts +1 -1
  175. package/esm/hooks/use-tambo-voice.js +1 -1
  176. package/esm/hooks/use-tambo-voice.js.map +1 -1
  177. package/esm/hooks/use-tambo-voice.test.d.ts +2 -0
  178. package/esm/hooks/use-tambo-voice.test.d.ts.map +1 -0
  179. package/esm/hooks/use-tambo-voice.test.js +234 -0
  180. package/esm/hooks/use-tambo-voice.test.js.map +1 -0
  181. package/esm/index.d.ts +2 -2
  182. package/esm/index.d.ts.map +1 -1
  183. package/esm/index.js.map +1 -1
  184. package/esm/mcp/elicitation.d.ts.map +1 -1
  185. package/esm/mcp/elicitation.js +12 -0
  186. package/esm/mcp/elicitation.js.map +1 -1
  187. package/esm/mcp/elicitation.test.js +8 -1
  188. package/esm/mcp/elicitation.test.js.map +1 -1
  189. package/esm/mcp/mcp-client.d.ts +6 -10
  190. package/esm/mcp/mcp-client.d.ts.map +1 -1
  191. package/esm/mcp/mcp-client.js.map +1 -1
  192. package/esm/mcp/mcp-hooks.d.ts +12 -60
  193. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  194. package/esm/mcp/mcp-hooks.js +57 -10
  195. package/esm/mcp/mcp-hooks.js.map +1 -1
  196. package/esm/mcp/mcp-hooks.test.js +423 -0
  197. package/esm/mcp/mcp-hooks.test.js.map +1 -1
  198. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  199. package/esm/mcp/tambo-mcp-provider.js +3 -0
  200. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  201. package/esm/mcp/tambo-mcp-provider.test.js +37 -0
  202. package/esm/mcp/tambo-mcp-provider.test.js.map +1 -1
  203. package/esm/model/component-metadata.d.ts +53 -20
  204. package/esm/model/component-metadata.d.ts.map +1 -1
  205. package/esm/model/component-metadata.js.map +1 -1
  206. package/esm/model/tambo-interactable.d.ts +6 -0
  207. package/esm/model/tambo-interactable.d.ts.map +1 -1
  208. package/esm/model/tambo-interactable.js.map +1 -1
  209. package/esm/providers/index.d.ts +1 -1
  210. package/esm/providers/index.d.ts.map +1 -1
  211. package/esm/providers/index.js.map +1 -1
  212. package/esm/providers/tambo-client-provider.d.ts +8 -0
  213. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  214. package/esm/providers/tambo-client-provider.js +11 -12
  215. package/esm/providers/tambo-client-provider.js.map +1 -1
  216. package/esm/providers/tambo-client-provider.test.d.ts +2 -0
  217. package/esm/providers/tambo-client-provider.test.d.ts.map +1 -0
  218. package/esm/providers/tambo-client-provider.test.js +203 -0
  219. package/esm/providers/tambo-client-provider.test.js.map +1 -0
  220. package/esm/providers/tambo-context-attachment-provider.d.ts +34 -92
  221. package/esm/providers/tambo-context-attachment-provider.d.ts.map +1 -1
  222. package/esm/providers/tambo-context-attachment-provider.js +63 -106
  223. package/esm/providers/tambo-context-attachment-provider.js.map +1 -1
  224. package/esm/providers/tambo-context-attachment-provider.test.js +230 -464
  225. package/esm/providers/tambo-context-attachment-provider.test.js.map +1 -1
  226. package/esm/providers/tambo-interactable-provider.d.ts +2 -0
  227. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  228. package/esm/providers/tambo-interactable-provider.js +29 -4
  229. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  230. package/esm/providers/tambo-interactable-provider.test.js +1 -1
  231. package/esm/providers/tambo-interactable-provider.test.js.map +1 -1
  232. package/esm/providers/tambo-interactables-additional-context.test.js +2 -5
  233. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  234. package/esm/providers/tambo-provider.d.ts +2 -3
  235. package/esm/providers/tambo-provider.d.ts.map +1 -1
  236. package/esm/providers/tambo-provider.js +5 -6
  237. package/esm/providers/tambo-provider.js.map +1 -1
  238. package/esm/providers/tambo-registry-provider.test.js +16 -0
  239. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  240. package/esm/providers/tambo-registry-schema-compat.test.js +31 -0
  241. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  242. package/esm/providers/tambo-thread-input-provider.d.ts +1 -1
  243. package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
  244. package/esm/providers/tambo-thread-input-provider.js +5 -1
  245. package/esm/providers/tambo-thread-input-provider.js.map +1 -1
  246. package/esm/providers/tambo-thread-provider-initial-messages.test.js +84 -2
  247. package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  248. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  249. package/esm/providers/tambo-thread-provider.js +56 -43
  250. package/esm/providers/tambo-thread-provider.js.map +1 -1
  251. package/esm/providers/tambo-thread-provider.test.js +456 -262
  252. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  253. package/esm/schema/json-schema.js +1 -1
  254. package/esm/schema/json-schema.js.map +1 -1
  255. package/esm/schema/schema.test.js +238 -1
  256. package/esm/schema/schema.test.js.map +1 -1
  257. package/esm/schema/standard-schema.d.ts +1 -0
  258. package/esm/schema/standard-schema.d.ts.map +1 -1
  259. package/esm/schema/standard-schema.js +18 -13
  260. package/esm/schema/standard-schema.js.map +1 -1
  261. package/esm/schema/standard-schema.test.d.ts +2 -0
  262. package/esm/schema/standard-schema.test.d.ts.map +1 -0
  263. package/esm/schema/standard-schema.test.js +130 -0
  264. package/esm/schema/standard-schema.test.js.map +1 -0
  265. package/esm/schema/validate.test.js +149 -0
  266. package/esm/schema/validate.test.js.map +1 -1
  267. package/esm/schema/zod.d.ts +7 -4
  268. package/esm/schema/zod.d.ts.map +1 -1
  269. package/esm/schema/zod.js +65 -22
  270. package/esm/schema/zod.js.map +1 -1
  271. package/esm/schema/zod.test.js +113 -1
  272. package/esm/schema/zod.test.js.map +1 -1
  273. package/esm/testing/tools.d.ts +4 -1
  274. package/esm/testing/tools.d.ts.map +1 -1
  275. package/esm/testing/tools.js +6 -1
  276. package/esm/testing/tools.js.map +1 -1
  277. package/esm/util/generate-component.d.ts.map +1 -1
  278. package/esm/util/generate-component.js +18 -3
  279. package/esm/util/generate-component.js.map +1 -1
  280. package/esm/util/generate-component.test.d.ts +2 -0
  281. package/esm/util/generate-component.test.d.ts.map +1 -0
  282. package/esm/util/generate-component.test.js +302 -0
  283. package/esm/util/generate-component.test.js.map +1 -0
  284. package/esm/util/is-promise.d.ts +9 -0
  285. package/esm/util/is-promise.d.ts.map +1 -0
  286. package/esm/util/is-promise.js +17 -0
  287. package/esm/util/is-promise.js.map +1 -0
  288. package/esm/util/is-promise.test.d.ts +2 -0
  289. package/esm/util/is-promise.test.d.ts.map +1 -0
  290. package/esm/util/is-promise.test.js +46 -0
  291. package/esm/util/is-promise.test.js.map +1 -0
  292. package/esm/util/query-utils.test.d.ts +2 -0
  293. package/esm/util/query-utils.test.d.ts.map +1 -0
  294. package/esm/util/query-utils.test.js +380 -0
  295. package/esm/util/query-utils.test.js.map +1 -0
  296. package/esm/util/registry-validators.d.ts.map +1 -1
  297. package/esm/util/registry-validators.js +7 -0
  298. package/esm/util/registry-validators.js.map +1 -1
  299. package/esm/util/registry-validators.test.js +57 -0
  300. package/esm/util/registry-validators.test.js.map +1 -1
  301. package/esm/util/registry.d.ts.map +1 -1
  302. package/esm/util/registry.js +9 -0
  303. package/esm/util/registry.js.map +1 -1
  304. package/esm/util/registry.test.js +324 -2
  305. package/esm/util/registry.test.js.map +1 -1
  306. package/esm/util/resource-validators.test.d.ts +2 -0
  307. package/esm/util/resource-validators.test.d.ts.map +1 -0
  308. package/esm/util/resource-validators.test.js +88 -0
  309. package/esm/util/resource-validators.test.js.map +1 -0
  310. package/esm/util/tool-caller.d.ts +2 -2
  311. package/esm/util/tool-caller.d.ts.map +1 -1
  312. package/esm/util/tool-caller.js +8 -8
  313. package/esm/util/tool-caller.js.map +1 -1
  314. package/esm/util/validate-component-name.test.d.ts +2 -0
  315. package/esm/util/validate-component-name.test.d.ts.map +1 -0
  316. package/esm/util/validate-component-name.test.js +33 -0
  317. package/esm/util/validate-component-name.test.js.map +1 -0
  318. package/package.json +15 -23
  319. package/dist/schema/alias.d.ts +0 -3
  320. package/dist/schema/alias.d.ts.map +0 -1
  321. package/dist/schema/alias.js +0 -6
  322. package/dist/schema/alias.js.map +0 -1
  323. package/esm/schema/alias.d.ts +0 -3
  324. package/esm/schema/alias.d.ts.map +0 -1
  325. package/esm/schema/alias.js +0 -13
  326. package/esm/schema/alias.js.map +0 -1
@@ -0,0 +1,130 @@
1
+ import * as z3 from "zod/v3";
2
+ import * as z4 from "zod/v4";
3
+ import { isStandardSchema } from "./standard-schema";
4
+ describe("isStandardSchema", () => {
5
+ describe("returns true for valid Standard Schema implementations", () => {
6
+ it("recognizes Zod 4 object schema", () => {
7
+ const schema = z4.object({ name: z4.string() });
8
+ expect(isStandardSchema(schema)).toBe(true);
9
+ });
10
+ it("recognizes Zod 3 object schema", () => {
11
+ const schema = z3.object({ name: z3.string() });
12
+ expect(isStandardSchema(schema)).toBe(true);
13
+ });
14
+ it("recognizes Zod 4 string schema", () => {
15
+ const schema = z4.string();
16
+ expect(isStandardSchema(schema)).toBe(true);
17
+ });
18
+ it("recognizes Zod 3 string schema", () => {
19
+ const schema = z3.string();
20
+ expect(isStandardSchema(schema)).toBe(true);
21
+ });
22
+ it("recognizes Zod 4 array schema", () => {
23
+ const schema = z4.array(z4.number());
24
+ expect(isStandardSchema(schema)).toBe(true);
25
+ });
26
+ it("recognizes Zod 3 array schema", () => {
27
+ const schema = z3.array(z3.number());
28
+ expect(isStandardSchema(schema)).toBe(true);
29
+ });
30
+ it("recognizes custom object implementing Standard Schema v1", () => {
31
+ const customSchema = {
32
+ "~standard": {
33
+ version: 1,
34
+ vendor: "custom",
35
+ validate: () => ({ value: {} }),
36
+ },
37
+ };
38
+ expect(isStandardSchema(customSchema)).toBe(true);
39
+ });
40
+ });
41
+ describe("returns false for non-Standard Schema values", () => {
42
+ it("rejects null", () => {
43
+ expect(isStandardSchema(null)).toBe(false);
44
+ });
45
+ it("rejects undefined", () => {
46
+ expect(isStandardSchema(undefined)).toBe(false);
47
+ });
48
+ it("rejects primitives", () => {
49
+ expect(isStandardSchema("string")).toBe(false);
50
+ expect(isStandardSchema(123)).toBe(false);
51
+ expect(isStandardSchema(true)).toBe(false);
52
+ });
53
+ it("rejects plain objects without ~standard", () => {
54
+ expect(isStandardSchema({ foo: "bar" })).toBe(false);
55
+ });
56
+ it("rejects JSON Schema objects", () => {
57
+ const jsonSchema = {
58
+ type: "object",
59
+ properties: { name: { type: "string" } },
60
+ };
61
+ expect(isStandardSchema(jsonSchema)).toBe(false);
62
+ });
63
+ it("rejects objects with ~standard that is not an object", () => {
64
+ expect(isStandardSchema({ "~standard": "invalid" })).toBe(false);
65
+ expect(isStandardSchema({ "~standard": 123 })).toBe(false);
66
+ expect(isStandardSchema({ "~standard": true })).toBe(false);
67
+ });
68
+ it("rejects objects with ~standard that is null", () => {
69
+ expect(isStandardSchema({ "~standard": null })).toBe(false);
70
+ });
71
+ it("rejects objects with wrong version", () => {
72
+ const invalidVersion = {
73
+ "~standard": {
74
+ version: 2, // Wrong version
75
+ vendor: "custom",
76
+ validate: () => ({ value: {} }),
77
+ },
78
+ };
79
+ expect(isStandardSchema(invalidVersion)).toBe(false);
80
+ });
81
+ it("rejects objects with missing version", () => {
82
+ const missingVersion = {
83
+ "~standard": {
84
+ vendor: "custom",
85
+ validate: () => ({ value: {} }),
86
+ },
87
+ };
88
+ expect(isStandardSchema(missingVersion)).toBe(false);
89
+ });
90
+ it("rejects objects with non-string vendor", () => {
91
+ const invalidVendor = {
92
+ "~standard": {
93
+ version: 1,
94
+ vendor: 123, // Not a string
95
+ validate: () => ({ value: {} }),
96
+ },
97
+ };
98
+ expect(isStandardSchema(invalidVendor)).toBe(false);
99
+ });
100
+ it("rejects objects with missing vendor", () => {
101
+ const missingVendor = {
102
+ "~standard": {
103
+ version: 1,
104
+ validate: () => ({ value: {} }),
105
+ },
106
+ };
107
+ expect(isStandardSchema(missingVendor)).toBe(false);
108
+ });
109
+ it("rejects objects with non-function validate", () => {
110
+ const invalidValidate = {
111
+ "~standard": {
112
+ version: 1,
113
+ vendor: "custom",
114
+ validate: "not-a-function",
115
+ },
116
+ };
117
+ expect(isStandardSchema(invalidValidate)).toBe(false);
118
+ });
119
+ it("rejects objects with missing validate", () => {
120
+ const missingValidate = {
121
+ "~standard": {
122
+ version: 1,
123
+ vendor: "custom",
124
+ },
125
+ };
126
+ expect(isStandardSchema(missingValidate)).toBe(false);
127
+ });
128
+ });
129
+ });
130
+ //# sourceMappingURL=standard-schema.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.test.js","sourceRoot":"","sources":["../../src/schema/standard-schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,QAAQ,CAAC,wDAAwD,EAAE,GAAG,EAAE;QACtE,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAChD,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAChD,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EA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AAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;YAC7C,MAAM,aAAa,GAAG;gBACpB,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC;oBACV,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;iBAChC;aACF,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,MAAM,eAAe,GAAG;gBACtB,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC;oBACV,MAAM,EAAE,QAAQ;oBAChB,QAAQ,EAAE,gBAAgB;iBAC3B;aACF,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,eAAe,GAAG;gBACtB,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport { isStandardSchema } from \"./standard-schema\";\n\ndescribe(\"isStandardSchema\", () => {\n describe(\"returns true for valid Standard Schema implementations\", () => {\n it(\"recognizes Zod 4 object schema\", () => {\n const schema = z4.object({ name: z4.string() });\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes Zod 3 object schema\", () => {\n const schema = z3.object({ name: z3.string() });\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes Zod 4 string schema\", () => {\n const schema = z4.string();\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes Zod 3 string schema\", () => {\n const schema = z3.string();\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes Zod 4 array schema\", () => {\n const schema = z4.array(z4.number());\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes Zod 3 array schema\", () => {\n const schema = z3.array(z3.number());\n expect(isStandardSchema(schema)).toBe(true);\n });\n\n it(\"recognizes custom object implementing Standard Schema v1\", () => {\n const customSchema = {\n \"~standard\": {\n version: 1,\n vendor: \"custom\",\n validate: () => ({ value: {} }),\n },\n };\n expect(isStandardSchema(customSchema)).toBe(true);\n });\n });\n\n describe(\"returns false for non-Standard Schema values\", () => {\n it(\"rejects null\", () => {\n expect(isStandardSchema(null)).toBe(false);\n });\n\n it(\"rejects undefined\", () => {\n expect(isStandardSchema(undefined)).toBe(false);\n });\n\n it(\"rejects primitives\", () => {\n expect(isStandardSchema(\"string\")).toBe(false);\n expect(isStandardSchema(123)).toBe(false);\n expect(isStandardSchema(true)).toBe(false);\n });\n\n it(\"rejects plain objects without ~standard\", () => {\n expect(isStandardSchema({ foo: \"bar\" })).toBe(false);\n });\n\n it(\"rejects JSON Schema objects\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: { name: { type: \"string\" } },\n };\n expect(isStandardSchema(jsonSchema)).toBe(false);\n });\n\n it(\"rejects objects with ~standard that is not an object\", () => {\n expect(isStandardSchema({ \"~standard\": \"invalid\" })).toBe(false);\n expect(isStandardSchema({ \"~standard\": 123 })).toBe(false);\n expect(isStandardSchema({ \"~standard\": true })).toBe(false);\n });\n\n it(\"rejects objects with ~standard that is null\", () => {\n expect(isStandardSchema({ \"~standard\": null })).toBe(false);\n });\n\n it(\"rejects objects with wrong version\", () => {\n const invalidVersion = {\n \"~standard\": {\n version: 2, // Wrong version\n vendor: \"custom\",\n validate: () => ({ value: {} }),\n },\n };\n expect(isStandardSchema(invalidVersion)).toBe(false);\n });\n\n it(\"rejects objects with missing version\", () => {\n const missingVersion = {\n \"~standard\": {\n vendor: \"custom\",\n validate: () => ({ value: {} }),\n },\n };\n expect(isStandardSchema(missingVersion)).toBe(false);\n });\n\n it(\"rejects objects with non-string vendor\", () => {\n const invalidVendor = {\n \"~standard\": {\n version: 1,\n vendor: 123, // Not a string\n validate: () => ({ value: {} }),\n },\n };\n expect(isStandardSchema(invalidVendor)).toBe(false);\n });\n\n it(\"rejects objects with missing vendor\", () => {\n const missingVendor = {\n \"~standard\": {\n version: 1,\n validate: () => ({ value: {} }),\n },\n };\n expect(isStandardSchema(missingVendor)).toBe(false);\n });\n\n it(\"rejects objects with non-function validate\", () => {\n const invalidValidate = {\n \"~standard\": {\n version: 1,\n vendor: \"custom\",\n validate: \"not-a-function\",\n },\n };\n expect(isStandardSchema(invalidValidate)).toBe(false);\n });\n\n it(\"rejects objects with missing validate\", () => {\n const missingValidate = {\n \"~standard\": {\n version: 1,\n vendor: \"custom\",\n },\n };\n expect(isStandardSchema(missingValidate)).toBe(false);\n });\n });\n});\n"]}
@@ -1,6 +1,54 @@
1
1
  import { z } from "zod/v4";
2
2
  import { assertNoRecordSchema } from "./validate";
3
3
  describe("assertNoRecordSchema", () => {
4
+ describe("falsy inputs", () => {
5
+ it("should return early for null", () => {
6
+ expect(() => assertNoRecordSchema(null)).not.toThrow();
7
+ });
8
+ it("should return early for undefined", () => {
9
+ expect(() => assertNoRecordSchema(undefined)).not.toThrow();
10
+ });
11
+ it("should return early for empty string", () => {
12
+ expect(() => assertNoRecordSchema("")).not.toThrow();
13
+ });
14
+ it("should return early for zero", () => {
15
+ expect(() => assertNoRecordSchema(0)).not.toThrow();
16
+ });
17
+ });
18
+ describe("unknown schema types", () => {
19
+ it("should skip validation for unknown object types without type property", () => {
20
+ const unknownSchema = { foo: "bar", baz: 123 };
21
+ expect(() => assertNoRecordSchema(unknownSchema)).not.toThrow();
22
+ });
23
+ it("should skip validation for arrays", () => {
24
+ expect(() => assertNoRecordSchema([1, 2, 3])).not.toThrow();
25
+ });
26
+ });
27
+ describe("schema conversion errors", () => {
28
+ it("should skip validation when Standard Schema conversion fails", () => {
29
+ // Create a mock that looks like Standard Schema but will fail conversion
30
+ const brokenSchema = {
31
+ "~standard": {
32
+ version: 1,
33
+ vendor: "broken-vendor",
34
+ validate: () => ({ value: {} }),
35
+ },
36
+ };
37
+ // Should not throw, just skip validation
38
+ expect(() => assertNoRecordSchema(brokenSchema)).not.toThrow();
39
+ });
40
+ });
41
+ describe("empty converted schemas", () => {
42
+ it("should skip validation for function schemas that return empty JSON Schema", () => {
43
+ // Function schemas can't be directly converted to JSON Schema
44
+ const funcSchema = z.function({
45
+ input: [z.string()],
46
+ output: z.void(),
47
+ });
48
+ // Should not throw - function schemas are handled specially
49
+ expect(() => assertNoRecordSchema(funcSchema)).not.toThrow();
50
+ });
51
+ });
4
52
  it("should allow valid schemas without records", () => {
5
53
  const schema = z.object({
6
54
  name: z.string(),
@@ -69,6 +117,107 @@ describe("assertNoRecordSchema", () => {
69
117
  const schema = z.record(z.string(), z.string());
70
118
  expect(() => assertNoRecordSchema(schema, "mySchema")).toThrow('Record types (objects with dynamic keys) are not supported in mySchema. Found at path "(root)". Replace it with an object using explicit keys.');
71
119
  });
120
+ describe("JSON Schema conditional keywords", () => {
121
+ it("should throw when encountering a record in if clause", () => {
122
+ const jsonSchema = {
123
+ type: "object",
124
+ if: {
125
+ type: "object",
126
+ additionalProperties: { type: "string" },
127
+ },
128
+ then: {
129
+ properties: { name: { type: "string" } },
130
+ },
131
+ };
132
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "if". Replace it with an object using explicit keys.');
133
+ });
134
+ it("should throw when encountering a record in then clause", () => {
135
+ const jsonSchema = {
136
+ type: "object",
137
+ if: {
138
+ properties: { type: { const: "map" } },
139
+ },
140
+ then: {
141
+ type: "object",
142
+ additionalProperties: { type: "number" },
143
+ },
144
+ };
145
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "then". Replace it with an object using explicit keys.');
146
+ });
147
+ it("should throw when encountering a record in else clause", () => {
148
+ const jsonSchema = {
149
+ type: "object",
150
+ if: {
151
+ properties: { type: { const: "simple" } },
152
+ },
153
+ then: {
154
+ properties: { value: { type: "string" } },
155
+ },
156
+ else: {
157
+ type: "object",
158
+ additionalProperties: { type: "boolean" },
159
+ },
160
+ };
161
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "else". Replace it with an object using explicit keys.');
162
+ });
163
+ it("should throw when encountering a record in not clause", () => {
164
+ const jsonSchema = {
165
+ type: "object",
166
+ not: {
167
+ type: "object",
168
+ additionalProperties: { type: "string" },
169
+ },
170
+ };
171
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "!". Replace it with an object using explicit keys.');
172
+ });
173
+ it("should throw when encountering a record in oneOf", () => {
174
+ const jsonSchema = {
175
+ type: "object",
176
+ oneOf: [
177
+ { type: "string" },
178
+ {
179
+ type: "object",
180
+ additionalProperties: { type: "number" },
181
+ },
182
+ ],
183
+ };
184
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "|1". Replace it with an object using explicit keys.');
185
+ });
186
+ });
187
+ describe("nested records in additionalProperties", () => {
188
+ it("should throw for nested record inside additionalProperties value schema", () => {
189
+ const jsonSchema = {
190
+ type: "object",
191
+ additionalProperties: {
192
+ type: "object",
193
+ properties: {
194
+ nested: {
195
+ type: "object",
196
+ additionalProperties: { type: "string" },
197
+ },
198
+ },
199
+ },
200
+ };
201
+ // First it finds the root level record
202
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "(root)". Replace it with an object using explicit keys.');
203
+ });
204
+ });
205
+ describe("prefixItems (JSON Schema 2020-12)", () => {
206
+ it("should throw when encountering a record in prefixItems", () => {
207
+ // Using JSON Schema 2020-12 style tuple
208
+ const jsonSchema = {
209
+ type: "array",
210
+ prefixItems: [
211
+ { type: "string" },
212
+ {
213
+ type: "object",
214
+ additionalProperties: { type: "number" },
215
+ },
216
+ ],
217
+ };
218
+ expect(() => assertNoRecordSchema(jsonSchema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "1". Replace it with an object using explicit keys.');
219
+ });
220
+ });
72
221
  it("should handle ZodLazy schemas", () => {
73
222
  const schema = z.lazy(() => z.record(z.string(), z.string()));
74
223
  expect(() => assertNoRecordSchema(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "(root)". Replace it with an object using explicit keys.');
@@ -1 +1 @@
1
- {"version":3,"file":"validate.test.js","sourceRoot":"","sources":["../../src/schema/validate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;YACf,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;gBAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;gBAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;aACjB,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,EAAE,CAAC,oBA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ACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zod/v4\";\nimport { assertNoRecordSchema } from \"./validate\";\n\ndescribe(\"assertNoRecordSchema\", () => {\n it(\"should allow valid schemas without records\", () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n tags: z.array(z.string()),\n address: z.object({\n street: z.string(),\n city: z.string(),\n }),\n });\n\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should throw when encountering a record at root level\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a nested record\", () => {\n const schema = z.object({\n name: z.string(),\n metadata: z.record(z.string(), z.string()),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an array\", () => {\n const schema = z.object({\n items: z.array(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"items.[]\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a union\", () => {\n const schema = z.union([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"|1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an intersection\", () => {\n const schema = z.intersection(\n z.object({ name: z.string() }),\n z.object({ metadata: z.record(z.string(), z.string()) }),\n );\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"(&1\\.)?metadata\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a discriminated union\", () => {\n const schema = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"string\"), value: z.string() }),\n z.object({\n type: z.literal(\"record\"),\n value: z.record(z.string(), z.number()),\n }),\n ]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"\\|1\\.value\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in an optional field\", () => {\n const schema = z.object({\n optional: z.optional(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"optional\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a nullable field\", () => {\n const schema = z.object({\n nullable: z.nullable(z.record(z.string(), z.string())),\n });\n\n // Nullable creates a oneOf in JSON Schema, so the path includes the union index\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"nullable(\\.\\|0)?\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a tuple\", () => {\n const schema = z.tuple([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should use custom context name in error message\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema, \"mySchema\")).toThrow(\n 'Record types (objects with dynamic keys) are not supported in mySchema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should handle ZodLazy schemas\", () => {\n const schema = z.lazy(() => z.record(z.string(), z.string()));\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should allow z.function() with valid arguments\", () => {\n const schema = z.function({\n input: [z.string(), z.number()],\n output: z.string(),\n });\n\n // Function schemas can't be converted to JSON Schema directly,\n // so they should not throw (validation happens on the extracted parameters)\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should allow JSON Schema without records\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n name: { type: \"string\" as const },\n age: { type: \"number\" as const },\n },\n required: [\"name\"],\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).not.toThrow();\n });\n\n it(\"should throw when JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should treat JSON Schema with properties and additionalProperties as a record\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n id: { type: \"string\" as const },\n },\n additionalProperties: { type: \"number\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when nested JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n metadata: {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n});\n"]}
1
+ {"version":3,"file":"validate.test.js","sourceRoot":"","sources":["../../src/schema/validate.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,QAAQ,CAAC,cAAc,EAAE,GAAG,EA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vB,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;SAClD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,8IAA8I,CAC/I,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+EAA+E,EAAE,GAAG,EAAE;QACvF,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;aAChC;YACD,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;SAClD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,8IAA8I,CAC/I,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAiB;oBACvB,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;iBAClD;aACF;SACF,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,gJAAgJ,CACjJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { z } from \"zod/v4\";\nimport { assertNoRecordSchema } from \"./validate\";\n\ndescribe(\"assertNoRecordSchema\", () => {\n describe(\"falsy inputs\", () => {\n it(\"should return early for null\", () => {\n expect(() => assertNoRecordSchema(null)).not.toThrow();\n });\n\n it(\"should return early for undefined\", () => {\n expect(() => assertNoRecordSchema(undefined)).not.toThrow();\n });\n\n it(\"should return early for empty string\", () => {\n expect(() => assertNoRecordSchema(\"\")).not.toThrow();\n });\n\n it(\"should return early for zero\", () => {\n expect(() => assertNoRecordSchema(0)).not.toThrow();\n });\n });\n\n describe(\"unknown schema types\", () => {\n it(\"should skip validation for unknown object types without type property\", () => {\n const unknownSchema = { foo: \"bar\", baz: 123 };\n expect(() => assertNoRecordSchema(unknownSchema)).not.toThrow();\n });\n\n it(\"should skip validation for arrays\", () => {\n expect(() => assertNoRecordSchema([1, 2, 3])).not.toThrow();\n });\n });\n\n describe(\"schema conversion errors\", () => {\n it(\"should skip validation when Standard Schema conversion fails\", () => {\n // Create a mock that looks like Standard Schema but will fail conversion\n const brokenSchema = {\n \"~standard\": {\n version: 1,\n vendor: \"broken-vendor\",\n validate: () => ({ value: {} }),\n },\n };\n\n // Should not throw, just skip validation\n expect(() => assertNoRecordSchema(brokenSchema)).not.toThrow();\n });\n });\n\n describe(\"empty converted schemas\", () => {\n it(\"should skip validation for function schemas that return empty JSON Schema\", () => {\n // Function schemas can't be directly converted to JSON Schema\n const funcSchema = z.function({\n input: [z.string()],\n output: z.void(),\n });\n\n // Should not throw - function schemas are handled specially\n expect(() => assertNoRecordSchema(funcSchema)).not.toThrow();\n });\n });\n\n it(\"should allow valid schemas without records\", () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n tags: z.array(z.string()),\n address: z.object({\n street: z.string(),\n city: z.string(),\n }),\n });\n\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should throw when encountering a record at root level\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a nested record\", () => {\n const schema = z.object({\n name: z.string(),\n metadata: z.record(z.string(), z.string()),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an array\", () => {\n const schema = z.object({\n items: z.array(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"items.[]\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a union\", () => {\n const schema = z.union([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"|1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an intersection\", () => {\n const schema = z.intersection(\n z.object({ name: z.string() }),\n z.object({ metadata: z.record(z.string(), z.string()) }),\n );\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"(&1\\.)?metadata\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a discriminated union\", () => {\n const schema = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"string\"), value: z.string() }),\n z.object({\n type: z.literal(\"record\"),\n value: z.record(z.string(), z.number()),\n }),\n ]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"\\|1\\.value\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in an optional field\", () => {\n const schema = z.object({\n optional: z.optional(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"optional\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a nullable field\", () => {\n const schema = z.object({\n nullable: z.nullable(z.record(z.string(), z.string())),\n });\n\n // Nullable creates a oneOf in JSON Schema, so the path includes the union index\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"nullable(\\.\\|0)?\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a tuple\", () => {\n const schema = z.tuple([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should use custom context name in error message\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema, \"mySchema\")).toThrow(\n 'Record types (objects with dynamic keys) are not supported in mySchema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n describe(\"JSON Schema conditional keywords\", () => {\n it(\"should throw when encountering a record in if clause\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n if: {\n type: \"object\",\n additionalProperties: { type: \"string\" },\n },\n then: {\n properties: { name: { type: \"string\" } },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"if\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in then clause\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n if: {\n properties: { type: { const: \"map\" } },\n },\n then: {\n type: \"object\",\n additionalProperties: { type: \"number\" },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"then\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in else clause\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n if: {\n properties: { type: { const: \"simple\" } },\n },\n then: {\n properties: { value: { type: \"string\" } },\n },\n else: {\n type: \"object\",\n additionalProperties: { type: \"boolean\" },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"else\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in not clause\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n not: {\n type: \"object\",\n additionalProperties: { type: \"string\" },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"!\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in oneOf\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n oneOf: [\n { type: \"string\" },\n {\n type: \"object\",\n additionalProperties: { type: \"number\" },\n },\n ],\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"|1\". Replace it with an object using explicit keys.',\n );\n });\n });\n\n describe(\"nested records in additionalProperties\", () => {\n it(\"should throw for nested record inside additionalProperties value schema\", () => {\n const jsonSchema: JSONSchema7 = {\n type: \"object\",\n additionalProperties: {\n type: \"object\",\n properties: {\n nested: {\n type: \"object\",\n additionalProperties: { type: \"string\" },\n },\n },\n },\n };\n\n // First it finds the root level record\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n });\n\n describe(\"prefixItems (JSON Schema 2020-12)\", () => {\n it(\"should throw when encountering a record in prefixItems\", () => {\n // Using JSON Schema 2020-12 style tuple\n const jsonSchema = {\n type: \"array\",\n prefixItems: [\n { type: \"string\" },\n {\n type: \"object\",\n additionalProperties: { type: \"number\" },\n },\n ],\n } as JSONSchema7;\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"1\". Replace it with an object using explicit keys.',\n );\n });\n });\n\n it(\"should handle ZodLazy schemas\", () => {\n const schema = z.lazy(() => z.record(z.string(), z.string()));\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should allow z.function() with valid arguments\", () => {\n const schema = z.function({\n input: [z.string(), z.number()],\n output: z.string(),\n });\n\n // Function schemas can't be converted to JSON Schema directly,\n // so they should not throw (validation happens on the extracted parameters)\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should allow JSON Schema without records\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n name: { type: \"string\" as const },\n age: { type: \"number\" as const },\n },\n required: [\"name\"],\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).not.toThrow();\n });\n\n it(\"should throw when JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should treat JSON Schema with properties and additionalProperties as a record\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n id: { type: \"string\" as const },\n },\n additionalProperties: { type: \"number\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when nested JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n metadata: {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n});\n"]}
@@ -1,3 +1,4 @@
1
+ import { JSONSchema7 } from "json-schema";
1
2
  import { ZodFunction, ZodTuple, ZodTupleItems, ZodType, ZodTypeAny } from "zod/v3";
2
3
  import { $ZodFunction, $ZodType } from "zod/v4/core";
3
4
  /**
@@ -25,14 +26,14 @@ export declare function getZodFunctionArgs(schema: unknown): import("zod/v4/core
25
26
  * @param schema - The Zod function schema
26
27
  * @returns The return schema, or undefined if not a Zod function schema
27
28
  */
28
- export declare function getZodFunctionReturns(schema: unknown): any;
29
+ export declare function getZodFunctionReturns(schema: unknown): ZodTypeAny | import("zod/v4/core").$ZodFunctionOut;
29
30
  /**
30
31
  * Handles conversion of Zod schemas to JSON Schema.
31
32
  * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).
32
33
  * @param schema - The Zod schema to convert
33
34
  * @returns The JSON Schema representation
34
35
  */
35
- export declare function handleZodSchemaToJson(schema: unknown): any;
36
+ export declare function handleZodSchemaToJson(schema: unknown): JSONSchema7;
36
37
  /**
37
38
  * Checks if a schema is probably a Zod 3 schema.
38
39
  * @param schema - The schema to check
@@ -40,8 +41,10 @@ export declare function handleZodSchemaToJson(schema: unknown): any;
40
41
  */
41
42
  export declare function isZod3Schema(schema: unknown): schema is ZodType;
42
43
  /**
43
- * Detects if a schema is Zod 4 by checking for def.type property.
44
- * Zod 4 uses `def.type` with lowercase type names like "object", "string".
44
+ * Detects if a schema is Zod 4 by checking for Zod 4 markers.
45
+ * - v4.1.x has `_zod` property
46
+ * - v4.0.x (bundled in zod@3.25) has `def` directly but no `_def` for regular schemas
47
+ * - v4.0.x function schemas have both `_def` and `def` (special case)
45
48
  * @returns True if the schema appears to be Zod 4 style
46
49
  */
47
50
  export declare function isZod4Schema(schema: unknown): schema is $ZodType;
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,C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AAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,sDAapD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,eAoBpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CA0BhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,GAAG,QAAQ,CA0CzE"}
package/esm/schema/zod.js CHANGED
@@ -21,7 +21,7 @@ export function isZod4FunctionSchema(schema) {
21
21
  // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include
22
22
  // the types for 4.1 yet (and might not ever).
23
23
  // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48
24
- if ("def" in schema && typeof schema.def !== "object" && schema.def) {
24
+ if ("def" in schema && typeof schema.def === "object" && schema.def) {
25
25
  if (schema.def?.type === "function") {
26
26
  return true;
27
27
  }
@@ -64,8 +64,10 @@ export function getZodFunctionReturns(schema) {
64
64
  return schema._def.returns;
65
65
  }
66
66
  if (isZod4FunctionSchema(schema)) {
67
- // @ts-expect-error -- Error in Zod types for v3 vs v4
68
- return schema._zod.def.output;
67
+ // v4.0.x: output on .def directly
68
+ // v4.1.x: output on ._zod.def
69
+ // @ts-expect-error -- Type differences between v4.0.x and v4.1.x
70
+ return schema.def?.output ?? schema._zod?.def?.output;
69
71
  }
70
72
  throw new Error("Unable to determine return type from zod function schema");
71
73
  }
@@ -77,8 +79,9 @@ export function getZodFunctionReturns(schema) {
77
79
  */
78
80
  export function handleZodSchemaToJson(schema) {
79
81
  // If Zod4 schema detected, use the toJSONSchema function from "zod/v4/core"
80
- if (isZod4Schema(schema))
82
+ if (isZod4Schema(schema)) {
81
83
  return zod4ToJSONSchema(schema, { reused: "inline" });
84
+ }
82
85
  try {
83
86
  // Dynamic require for optional peer dependency
84
87
  // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing
@@ -101,12 +104,36 @@ export function isZod3Schema(schema) {
101
104
  return isZodSchema(schema) && "_def" in schema && !("def" in schema);
102
105
  }
103
106
  /**
104
- * Detects if a schema is Zod 4 by checking for def.type property.
105
- * Zod 4 uses `def.type` with lowercase type names like "object", "string".
107
+ * Detects if a schema is Zod 4 by checking for Zod 4 markers.
108
+ * - v4.1.x has `_zod` property
109
+ * - v4.0.x (bundled in zod@3.25) has `def` directly but no `_def` for regular schemas
110
+ * - v4.0.x function schemas have both `_def` and `def` (special case)
106
111
  * @returns True if the schema appears to be Zod 4 style
107
112
  */
108
113
  export function isZod4Schema(schema) {
109
- return isZodSchema(schema) && "_zod" in schema;
114
+ if (!isZodSchema(schema))
115
+ return false;
116
+ // v4.1.x: has _zod property
117
+ if ("_zod" in schema)
118
+ return true;
119
+ // v4.0.x regular schemas: has def directly but NOT _def (v3 has _def)
120
+ // Also check def.type is a string; in Zod v4 this is typically a string
121
+ // literal like "string"
122
+ if ("def" in schema && !("_def" in schema)) {
123
+ const def = schema.def;
124
+ if (def && typeof def === "object" && "type" in def) {
125
+ return typeof def.type === "string";
126
+ }
127
+ }
128
+ // v4.0.x function schemas: have both _def and def with type "function"
129
+ // This is a special case where _def exists but it's still a v4 schema
130
+ if ("_def" in schema && "def" in schema) {
131
+ const def = schema.def;
132
+ if (def && typeof def === "object" && "type" in def) {
133
+ return def.type === "function";
134
+ }
135
+ }
136
+ return false;
110
137
  }
111
138
  /**
112
139
  * Checks if a schema is a Zod schema
@@ -114,24 +141,40 @@ export function isZod4Schema(schema) {
114
141
  * @returns True if the schema is a Zod schema
115
142
  */
116
143
  export function isZodSchema(schema) {
117
- // schema must be { ~standard: { vendor: "zod" } }
118
144
  if (typeof schema !== "object")
119
145
  return false;
120
146
  if (!schema)
121
147
  return false;
122
- if (!("~standard" in schema))
123
- return false;
124
- if (!schema["~standard"])
125
- return false;
126
- if (typeof schema["~standard"] !== "object")
127
- return false;
128
- if (!("vendor" in schema["~standard"]))
129
- return false;
130
- if (schema["~standard"].vendor !== "zod")
131
- return false;
132
- // Require at least one internal marker to reduce false positives
133
- const looksLikeV3 = "_def" in schema;
134
- const looksLikeV4 = "_zod" in schema || "def" in schema;
135
- return looksLikeV3 || looksLikeV4;
148
+ // Standard detection: schema has { ~standard: { vendor: "zod" } }
149
+ if ("~standard" in schema && schema["~standard"]) {
150
+ const std = schema["~standard"];
151
+ if (typeof std === "object" && "vendor" in std && std.vendor === "zod") {
152
+ // Require at least one internal marker to reduce false positives
153
+ const looksLikeV3 = "_def" in schema;
154
+ const looksLikeV4 = "_zod" in schema || "def" in schema;
155
+ return looksLikeV3 || looksLikeV4;
156
+ }
157
+ }
158
+ // v4.0.x function schemas: have _def and def with type "function"
159
+ // but don't have ~standard at the top level (only on nested schemas)
160
+ if ("_def" in schema && "def" in schema) {
161
+ const def = schema.def;
162
+ if (def &&
163
+ typeof def === "object" &&
164
+ "type" in def &&
165
+ def.type === "function") {
166
+ // Check if nested input/output have zod markers
167
+ const inputIsZod = "input" in def &&
168
+ typeof def.input === "object" &&
169
+ def.input !== null &&
170
+ "~standard" in def.input;
171
+ const outputIsZod = "output" in def &&
172
+ typeof def.output === "object" &&
173
+ def.output !== null &&
174
+ "~standard" in def.output;
175
+ return inputIsZod || outputIsZod;
176
+ }
177
+ }
178
+ return false;
136
179
  }
137
180
  //# sourceMappingURL=zod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC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AC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,MAAM,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,kDAAkD;IAClD,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1D,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAEvD,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,CAAC;IACrC,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;IACxD,OAAO,WAAW,IAAI,WAAW,CAAC;AACpC,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema))\n return zod4ToJSONSchema(schema, { reused: \"inline\" });\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema, { $refStrategy: \"none\" });\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema && !(\"def\" in schema);\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return isZodSchema(schema) && \"_zod\" in schema;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n // schema must be { ~standard: { vendor: \"zod\" } }\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n if (!(\"~standard\" in schema)) return false;\n if (!schema[\"~standard\"]) return false;\n if (typeof schema[\"~standard\"] !== \"object\") return false;\n if (!(\"vendor\" in schema[\"~standard\"])) return false;\n if (schema[\"~standard\"].vendor !== \"zod\") return false;\n\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAQA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,OAAO,CACL,MAAM,IAAI,MAAM;QAChB,UAAU,IAAI,MAAM,CAAC,IAAI;QACzB,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CACvC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACpE,IAAK,MAAM,CAAC,GAAwB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,6EAA6E;IAC7E,mDAAmD;IACnD,OAAQ,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,IAAe,KAAK,UAAU,CAAC;AAC3D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAe;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,IAAI,oBAAoB,CAAC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AAU,IAAI,WAAW,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { JSONSchema7 } from \"json-schema\";\nimport {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def === \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // v4.0.x: output on .def directly\n // v4.1.x: output on ._zod.def\n // @ts-expect-error -- Type differences between v4.0.x and v4.1.x\n return schema.def?.output ?? schema._zod?.def?.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) {\n return zod4ToJSONSchema(schema, { reused: \"inline\" }) as JSONSchema7;\n }\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema, { $refStrategy: \"none\" }) as JSONSchema7;\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema && !(\"def\" in schema);\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for Zod 4 markers.\n * - v4.1.x has `_zod` property\n * - v4.0.x (bundled in zod@3.25) has `def` directly but no `_def` for regular schemas\n * - v4.0.x function schemas have both `_def` and `def` (special case)\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n if (!isZodSchema(schema)) return false;\n\n // v4.1.x: has _zod property\n if (\"_zod\" in schema) return true;\n\n // v4.0.x regular schemas: has def directly but NOT _def (v3 has _def)\n // Also check def.type is a string; in Zod v4 this is typically a string\n // literal like \"string\"\n if (\"def\" in schema && !(\"_def\" in schema)) {\n const def = (schema as { def: unknown }).def;\n if (def && typeof def === \"object\" && \"type\" in def) {\n return typeof def.type === \"string\";\n }\n }\n\n // v4.0.x function schemas: have both _def and def with type \"function\"\n // This is a special case where _def exists but it's still a v4 schema\n if (\"_def\" in schema && \"def\" in schema) {\n const def = (schema as { def: unknown }).def;\n if (def && typeof def === \"object\" && \"type\" in def) {\n return def.type === \"function\";\n }\n }\n\n return false;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n\n // Standard detection: schema has { ~standard: { vendor: \"zod\" } }\n if (\"~standard\" in schema && schema[\"~standard\"]) {\n const std = schema[\"~standard\"];\n if (typeof std === \"object\" && \"vendor\" in std && std.vendor === \"zod\") {\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n }\n }\n\n // v4.0.x function schemas: have _def and def with type \"function\"\n // but don't have ~standard at the top level (only on nested schemas)\n if (\"_def\" in schema && \"def\" in schema) {\n const def = (schema as { def: unknown }).def;\n if (\n def &&\n typeof def === \"object\" &&\n \"type\" in def &&\n def.type === \"function\"\n ) {\n // Check if nested input/output have zod markers\n const inputIsZod =\n \"input\" in def &&\n typeof def.input === \"object\" &&\n def.input !== null &&\n \"~standard\" in def.input;\n\n const outputIsZod =\n \"output\" in def &&\n typeof def.output === \"object\" &&\n def.output !== null &&\n \"~standard\" in def.output;\n return inputIsZod || outputIsZod;\n }\n }\n\n return false;\n}\n"]}