@nullix/zod-mongoose-studio 3.3.2 → 3.3.3

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 (322) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{B7ScFmDB.js → 5ZXm4f56.js} +1 -1
  3. package/.output/public/_nuxt/{DbqvVYbv.js → B2fcLSyW.js} +1 -1
  4. package/.output/public/_nuxt/{DKK0Mrrg.js → BBN7l5Hn.js} +1 -1
  5. package/.output/public/_nuxt/BBTTtb8r.js +41 -0
  6. package/.output/public/_nuxt/{C8xmwXC2.js → BDbISGvP.js} +1 -1
  7. package/.output/public/_nuxt/{DJa7_7Hz.js → BijI4RNx.js} +1 -1
  8. package/.output/public/_nuxt/{BlZ0x31M.js → Bp9qkJ9m.js} +1 -1
  9. package/.output/public/_nuxt/{BcYnCaqL.js → Bu3-sqCf.js} +1 -1
  10. package/.output/public/_nuxt/{C919AVYR.js → C-FtTvwz.js} +1 -1
  11. package/.output/public/_nuxt/C02JV0Aj.js +1 -0
  12. package/.output/public/_nuxt/{Bbi9UBvi.js → C1UkIsDc.js} +1 -1
  13. package/.output/public/_nuxt/{PXBhK7S_.js → CJT28r6J.js} +1 -1
  14. package/.output/public/_nuxt/{BC9tFNFa.js → CL7qtgl2.js} +3 -3
  15. package/.output/public/_nuxt/{B6lqezyA.js → CRMd2YH2.js} +3 -3
  16. package/.output/public/_nuxt/{YC-RLggm.js → CRkdQgFz.js} +1 -1
  17. package/.output/public/_nuxt/{iKW_mt0p.js → Cw1XFOz5.js} +1 -1
  18. package/.output/public/_nuxt/{d1NBz903.js → D5yWk6Ly.js} +1 -1
  19. package/.output/public/_nuxt/{iGzUozbF.js → DA9GjKpR.js} +1 -1
  20. package/.output/public/_nuxt/{JkiDMdYG.js → DaWAlZhp.js} +1 -1
  21. package/.output/public/_nuxt/{OVQ3C2Ge.js → DafLMUHo.js} +1 -1
  22. package/.output/public/_nuxt/{Bw82IGM8.js → Dyaldc-t.js} +1 -1
  23. package/.output/public/_nuxt/{CsQL5F-l.js → UU9fpRNQ.js} +1 -1
  24. package/.output/public/_nuxt/builds/latest.json +1 -1
  25. package/.output/public/_nuxt/builds/meta/717459d8-0da1-42ed-af0b-9ec5395e8fdc.json +1 -0
  26. package/.output/public/_nuxt/entry.CDPplHzk.css +1 -0
  27. package/.output/public/_nuxt/error-404.hPtlUQpd.css +1 -0
  28. package/.output/public/_nuxt/error-500.E-PXUb6B.css +1 -0
  29. package/.output/public/_nuxt/{DbUZZZZu.js → kFZJW2-u.js} +2 -2
  30. package/.output/public/_nuxt/{B8gqXD2U.js → u3DlT5Mh.js} +1 -1
  31. package/.output/server/chunks/_/error-500.mjs.map +1 -1
  32. package/.output/server/chunks/_/parse-request.mjs +29 -0
  33. package/.output/server/chunks/_/parse-request.mjs.map +1 -0
  34. package/.output/server/chunks/build/client.precomputed.mjs +1 -1
  35. package/.output/server/chunks/build/{error-404-KRkA0DPI.mjs → error-404-aQ5PiVuX.mjs} +6 -12
  36. package/.output/server/chunks/build/error-404-aQ5PiVuX.mjs.map +1 -0
  37. package/.output/server/chunks/build/error-404-styles.DIZfBVBR.mjs +8 -0
  38. package/.output/server/chunks/build/error-404-styles.DIZfBVBR.mjs.map +1 -0
  39. package/.output/server/chunks/build/{error-500-DIIFf55p.mjs → error-500-BY6ZAZZ2.mjs} +6 -12
  40. package/.output/server/chunks/build/error-500-BY6ZAZZ2.mjs.map +1 -0
  41. package/.output/server/chunks/build/error-500-styles.BZXgEzR5.mjs +8 -0
  42. package/.output/server/chunks/build/error-500-styles.BZXgEzR5.mjs.map +1 -0
  43. package/.output/server/chunks/build/index-57_mtIua.mjs +235 -0
  44. package/.output/server/chunks/build/index-57_mtIua.mjs.map +1 -0
  45. package/.output/server/chunks/build/{index-CB1N4gax.mjs → index-Qa-4KqCB.mjs} +7 -13
  46. package/.output/server/chunks/build/index-Qa-4KqCB.mjs.map +1 -0
  47. package/.output/server/chunks/build/server.mjs +3913 -3378
  48. package/.output/server/chunks/build/server.mjs.map +1 -1
  49. package/.output/server/chunks/build/styles.mjs +4 -4
  50. package/.output/server/chunks/nitro/nitro.mjs +562 -2188
  51. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  52. package/.output/server/chunks/routes/api/editor-types.get.mjs +0 -6
  53. package/.output/server/chunks/routes/api/editor-types.get.mjs.map +1 -1
  54. package/.output/server/chunks/routes/api/parse.post.mjs +1599 -7
  55. package/.output/server/chunks/routes/api/parse.post.mjs.map +1 -1
  56. package/.output/server/chunks/routes/api/resolve.get.mjs +0 -6
  57. package/.output/server/chunks/routes/api/resolve.get.mjs.map +1 -1
  58. package/.output/server/chunks/routes/api/studio/run.post.mjs +41 -8
  59. package/.output/server/chunks/routes/api/studio/run.post.mjs.map +1 -1
  60. package/.output/server/chunks/routes/renderer.mjs +21 -44
  61. package/.output/server/chunks/routes/renderer.mjs.map +1 -1
  62. package/.output/server/index.mjs +1 -7
  63. package/.output/server/index.mjs.map +1 -1
  64. package/.output/server/node_modules/.nitro/@vue/compiler-core@3.5.43/dist/compiler-core.cjs.prod.js +6801 -0
  65. package/.output/server/node_modules/.nitro/@vue/compiler-core@3.5.43/package.json +58 -0
  66. package/.output/server/node_modules/.nitro/@vue/compiler-dom@3.5.43/dist/compiler-dom.cjs.prod.js +692 -0
  67. package/.output/server/node_modules/.nitro/@vue/compiler-dom@3.5.43/package.json +57 -0
  68. package/.output/server/node_modules/.nitro/@vue/reactivity@3.5.43/dist/reactivity.cjs.prod.js +1905 -0
  69. package/.output/server/node_modules/.nitro/@vue/reactivity@3.5.43/package.json +55 -0
  70. package/.output/server/node_modules/.nitro/@vue/runtime-core@3.5.43/dist/runtime-core.cjs.prod.js +7006 -0
  71. package/.output/server/node_modules/.nitro/@vue/runtime-core@3.5.43/package.json +52 -0
  72. package/.output/server/node_modules/.nitro/@vue/runtime-dom@3.5.43/dist/runtime-dom.cjs.prod.js +1867 -0
  73. package/.output/server/node_modules/.nitro/@vue/runtime-dom@3.5.43/package.json +60 -0
  74. package/.output/server/node_modules/.nitro/@vue/shared@3.5.43/dist/shared.cjs.prod.js +655 -0
  75. package/.output/server/node_modules/.nitro/@vue/shared@3.5.43/package.json +47 -0
  76. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/array-set.js +121 -0
  77. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/base64-vlq.js +140 -0
  78. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/base64.js +67 -0
  79. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/binary-search.js +111 -0
  80. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/mapping-list.js +79 -0
  81. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/quick-sort.js +141 -0
  82. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-map-consumer.js +1236 -0
  83. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-map-generator.js +446 -0
  84. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-node.js +420 -0
  85. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/util.js +594 -0
  86. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/package.json +71 -0
  87. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/source-map.js +8 -0
  88. package/.output/server/node_modules/.nitro/vue@3.5.43/dist/vue.cjs.js +80 -0
  89. package/.output/server/node_modules/.nitro/vue@3.5.43/dist/vue.cjs.prod.js +66 -0
  90. package/.output/server/node_modules/.nitro/vue@3.5.43/index.js +7 -0
  91. package/.output/server/node_modules/.nitro/vue@3.5.43/index.mjs +1 -0
  92. package/.output/server/node_modules/.nitro/vue@3.5.43/package.json +112 -0
  93. package/.output/server/node_modules/@babel/parser/lib/index.js +55 -21
  94. package/.output/server/node_modules/@babel/parser/package.json +7 -7
  95. package/.output/server/node_modules/@esbuild/linux-x64/bin/esbuild +0 -0
  96. package/.output/server/node_modules/@esbuild/linux-x64/package.json +1 -1
  97. package/.output/server/node_modules/@iconify/utils/lib/colors/index.js +19 -16
  98. package/.output/server/node_modules/@iconify/utils/lib/colors/keywords.js +3 -4
  99. package/.output/server/node_modules/@iconify/utils/lib/css/common.js +16 -16
  100. package/.output/server/node_modules/@iconify/utils/lib/css/format.js +1 -2
  101. package/.output/server/node_modules/@iconify/utils/lib/css/icon.js +11 -14
  102. package/.output/server/node_modules/@iconify/utils/lib/css/icons.js +13 -16
  103. package/.output/server/node_modules/@iconify/utils/lib/customisations/bool.js +1 -2
  104. package/.output/server/node_modules/@iconify/utils/lib/customisations/defaults.js +1 -3
  105. package/.output/server/node_modules/@iconify/utils/lib/customisations/flip.js +2 -5
  106. package/.output/server/node_modules/@iconify/utils/lib/customisations/merge.js +1 -3
  107. package/.output/server/node_modules/@iconify/utils/lib/customisations/rotate.js +4 -5
  108. package/.output/server/node_modules/@iconify/utils/lib/emoji/cleanup.js +1 -3
  109. package/.output/server/node_modules/@iconify/utils/lib/emoji/convert.js +9 -11
  110. package/.output/server/node_modules/@iconify/utils/lib/emoji/data.js +1 -2
  111. package/.output/server/node_modules/@iconify/utils/lib/emoji/format.js +1 -3
  112. package/.output/server/node_modules/@iconify/utils/lib/emoji/parse.js +1 -3
  113. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/base.js +12 -18
  114. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/create.js +3 -4
  115. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.js +5 -7
  116. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/similar.js +1 -8
  117. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/tree.js +11 -12
  118. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/find.js +5 -7
  119. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/replace.js +1 -3
  120. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/components.js +1 -3
  121. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/missing.js +7 -7
  122. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/name.js +2 -4
  123. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/parse.js +5 -9
  124. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/similar.js +3 -5
  125. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/tree.js +2 -4
  126. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/variations.js +7 -8
  127. package/.output/server/node_modules/@iconify/utils/lib/icon/defaults.js +1 -2
  128. package/.output/server/node_modules/@iconify/utils/lib/icon/merge.js +1 -3
  129. package/.output/server/node_modules/@iconify/utils/lib/icon/name.js +3 -4
  130. package/.output/server/node_modules/@iconify/utils/lib/icon/square.js +1 -2
  131. package/.output/server/node_modules/@iconify/utils/lib/icon/transformations.js +1 -2
  132. package/.output/server/node_modules/@iconify/utils/lib/icon-set/convert-info.js +10 -15
  133. package/.output/server/node_modules/@iconify/utils/lib/icon-set/expand.js +1 -3
  134. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icon.js +3 -5
  135. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icons.js +1 -3
  136. package/.output/server/node_modules/@iconify/utils/lib/icon-set/minify.js +1 -3
  137. package/.output/server/node_modules/@iconify/utils/lib/icon-set/parse.js +1 -3
  138. package/.output/server/node_modules/@iconify/utils/lib/icon-set/tree.js +1 -2
  139. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.js +1 -3
  140. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate.js +21 -13
  141. package/.output/server/node_modules/@iconify/utils/lib/index.js +1 -2
  142. package/.output/server/node_modules/@iconify/utils/lib/loader/custom.js +3 -3
  143. package/.output/server/node_modules/@iconify/utils/lib/loader/hmr-utils.js +33 -0
  144. package/.output/server/node_modules/@iconify/utils/lib/loader/loader.js +22 -22
  145. package/.output/server/node_modules/@iconify/utils/lib/loader/modern.js +7 -22
  146. package/.output/server/node_modules/@iconify/utils/lib/loader/utils.js +60 -16
  147. package/.output/server/node_modules/@iconify/utils/lib/misc/objects.js +1 -2
  148. package/.output/server/node_modules/@iconify/utils/lib/misc/strings.js +1 -2
  149. package/.output/server/node_modules/@iconify/utils/lib/misc/title.js +1 -2
  150. package/.output/server/node_modules/@iconify/utils/lib/svg/build.js +9 -11
  151. package/.output/server/node_modules/@iconify/utils/lib/svg/defs.js +1 -2
  152. package/.output/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js +1 -3
  153. package/.output/server/node_modules/@iconify/utils/lib/svg/html.js +1 -2
  154. package/.output/server/node_modules/@iconify/utils/lib/svg/id.js +1 -2
  155. package/.output/server/node_modules/@iconify/utils/lib/svg/inner-html.js +1 -2
  156. package/.output/server/node_modules/@iconify/utils/lib/svg/parse.js +3 -5
  157. package/.output/server/node_modules/@iconify/utils/lib/svg/pretty.js +5 -4
  158. package/.output/server/node_modules/@iconify/utils/lib/svg/size.js +1 -2
  159. package/.output/server/node_modules/@iconify/utils/lib/svg/trim.js +1 -2
  160. package/.output/server/node_modules/@iconify/utils/lib/svg/url.js +1 -2
  161. package/.output/server/node_modules/@iconify/utils/lib/svg/viewbox.js +2 -3
  162. package/.output/server/node_modules/@iconify/utils/package.json +15 -13
  163. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +8 -1
  164. package/.output/server/node_modules/@vue/compiler-ssr/package.json +3 -3
  165. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +34 -13
  166. package/.output/server/node_modules/@vue/server-renderer/package.json +4 -6
  167. package/.output/server/node_modules/devalue/index.js +15 -2
  168. package/.output/server/node_modules/devalue/package.json +5 -3
  169. package/.output/server/node_modules/devalue/src/base64.js +46 -96
  170. package/.output/server/node_modules/devalue/src/constants.js +5 -0
  171. package/.output/server/node_modules/devalue/src/operations.js +221 -0
  172. package/.output/server/node_modules/devalue/src/parse.js +76 -62
  173. package/.output/server/node_modules/devalue/src/stringify.js +164 -81
  174. package/.output/server/node_modules/devalue/src/uneval.js +312 -104
  175. package/.output/server/node_modules/devalue/src/utils.js +61 -19
  176. package/.output/server/node_modules/esbuild/lib/main.js +12 -8
  177. package/.output/server/node_modules/esbuild/package.json +50 -50
  178. package/.output/server/node_modules/hookable/dist/index.mjs +2 -11
  179. package/.output/server/node_modules/hookable/package.json +23 -22
  180. package/.output/server/node_modules/ip-address/dist/ipv4.js +7 -0
  181. package/.output/server/node_modules/ip-address/package.json +1 -1
  182. package/.output/server/node_modules/zod/package.json +20 -8
  183. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -1
  184. package/.output/server/node_modules/zod/v4/classic/deep-partial.js +13 -0
  185. package/.output/server/node_modules/zod/v4/classic/errors.js +44 -35
  186. package/.output/server/node_modules/zod/v4/classic/external.js +5 -8
  187. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +375 -78
  188. package/.output/server/node_modules/zod/v4/classic/in-out.js +36 -0
  189. package/.output/server/node_modules/zod/v4/classic/index.js +2 -2
  190. package/.output/server/node_modules/zod/v4/classic/iso.js +2 -17
  191. package/.output/server/node_modules/zod/v4/classic/package.json +2 -1
  192. package/.output/server/node_modules/zod/v4/classic/parse.js +1 -0
  193. package/.output/server/node_modules/zod/v4/classic/schemas.js +601 -223
  194. package/.output/server/node_modules/zod/v4/core/api.js +51 -26
  195. package/.output/server/node_modules/zod/v4/core/checks.js +68 -127
  196. package/.output/server/node_modules/zod/v4/core/compile.js +1858 -0
  197. package/.output/server/node_modules/zod/v4/core/core.js +87 -22
  198. package/.output/server/node_modules/zod/v4/core/doc.js +12 -9
  199. package/.output/server/node_modules/zod/v4/core/errors.js +127 -42
  200. package/.output/server/node_modules/zod/v4/core/index.js +3 -0
  201. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +6 -2
  202. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +413 -175
  203. package/.output/server/node_modules/zod/v4/core/memoizer.js +311 -0
  204. package/.output/server/node_modules/zod/v4/core/package.json +2 -1
  205. package/.output/server/node_modules/zod/v4/core/parse.js +130 -48
  206. package/.output/server/node_modules/zod/v4/core/regexes.js +39 -16
  207. package/.output/server/node_modules/zod/v4/core/registries.js +2 -2
  208. package/.output/server/node_modules/zod/v4/core/schemas.js +895 -382
  209. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +253 -39
  210. package/.output/server/node_modules/zod/v4/core/util.js +383 -175
  211. package/.output/server/node_modules/zod/v4/core/versions.js +2 -2
  212. package/.output/server/node_modules/zod/v4/core/visit.js +169 -0
  213. package/.output/server/node_modules/zod/v4/index.js +3 -2
  214. package/.output/server/node_modules/zod/v4/locales/ar.js +5 -0
  215. package/.output/server/node_modules/zod/v4/locales/az.js +5 -0
  216. package/.output/server/node_modules/zod/v4/locales/be.js +12 -0
  217. package/.output/server/node_modules/zod/v4/locales/bg.js +5 -0
  218. package/.output/server/node_modules/zod/v4/locales/bn.js +113 -0
  219. package/.output/server/node_modules/zod/v4/locales/ca.js +5 -0
  220. package/.output/server/node_modules/zod/v4/locales/ckb.js +133 -0
  221. package/.output/server/node_modules/zod/v4/locales/cs.js +5 -0
  222. package/.output/server/node_modules/zod/v4/locales/da.js +7 -2
  223. package/.output/server/node_modules/zod/v4/locales/de.js +5 -0
  224. package/.output/server/node_modules/zod/v4/locales/el.js +112 -0
  225. package/.output/server/node_modules/zod/v4/locales/en.js +20 -4
  226. package/.output/server/node_modules/zod/v4/locales/eo.js +5 -0
  227. package/.output/server/node_modules/zod/v4/locales/es.js +4 -0
  228. package/.output/server/node_modules/zod/v4/locales/fa.js +5 -0
  229. package/.output/server/node_modules/zod/v4/locales/fi.js +5 -0
  230. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +5 -0
  231. package/.output/server/node_modules/zod/v4/locales/fr.js +38 -17
  232. package/.output/server/node_modules/zod/v4/locales/gu.js +113 -0
  233. package/.output/server/node_modules/zod/v4/locales/he.js +7 -0
  234. package/.output/server/node_modules/zod/v4/locales/hi.js +111 -0
  235. package/.output/server/node_modules/zod/v4/locales/hr.js +126 -0
  236. package/.output/server/node_modules/zod/v4/locales/hu.js +5 -0
  237. package/.output/server/node_modules/zod/v4/locales/hy.js +11 -0
  238. package/.output/server/node_modules/zod/v4/locales/id.js +5 -0
  239. package/.output/server/node_modules/zod/v4/locales/index.js +14 -0
  240. package/.output/server/node_modules/zod/v4/locales/is.js +5 -0
  241. package/.output/server/node_modules/zod/v4/locales/it.js +6 -1
  242. package/.output/server/node_modules/zod/v4/locales/ja.js +5 -0
  243. package/.output/server/node_modules/zod/v4/locales/ka.js +13 -8
  244. package/.output/server/node_modules/zod/v4/locales/km.js +5 -0
  245. package/.output/server/node_modules/zod/v4/locales/kn.js +116 -0
  246. package/.output/server/node_modules/zod/v4/locales/ko.js +5 -0
  247. package/.output/server/node_modules/zod/v4/locales/lt.js +4 -0
  248. package/.output/server/node_modules/zod/v4/locales/mk.js +5 -0
  249. package/.output/server/node_modules/zod/v4/locales/ms.js +5 -0
  250. package/.output/server/node_modules/zod/v4/locales/ne.js +111 -0
  251. package/.output/server/node_modules/zod/v4/locales/nl.js +5 -0
  252. package/.output/server/node_modules/zod/v4/locales/nn.js +113 -0
  253. package/.output/server/node_modules/zod/v4/locales/no.js +7 -2
  254. package/.output/server/node_modules/zod/v4/locales/ota.js +5 -0
  255. package/.output/server/node_modules/zod/v4/locales/package.json +2 -1
  256. package/.output/server/node_modules/zod/v4/locales/pl.js +5 -0
  257. package/.output/server/node_modules/zod/v4/locales/ps.js +5 -0
  258. package/.output/server/node_modules/zod/v4/locales/pt-BR.js +143 -0
  259. package/.output/server/node_modules/zod/v4/locales/pt.js +89 -55
  260. package/.output/server/node_modules/zod/v4/locales/ro.js +122 -0
  261. package/.output/server/node_modules/zod/v4/locales/ru.js +12 -0
  262. package/.output/server/node_modules/zod/v4/locales/sk.js +116 -0
  263. package/.output/server/node_modules/zod/v4/locales/sl.js +5 -0
  264. package/.output/server/node_modules/zod/v4/locales/sv.js +7 -2
  265. package/.output/server/node_modules/zod/v4/locales/ta.js +5 -0
  266. package/.output/server/node_modules/zod/v4/locales/tg.js +117 -0
  267. package/.output/server/node_modules/zod/v4/locales/th.js +5 -0
  268. package/.output/server/node_modules/zod/v4/locales/tk.js +107 -0
  269. package/.output/server/node_modules/zod/v4/locales/tr.js +5 -0
  270. package/.output/server/node_modules/zod/v4/locales/uk.js +5 -0
  271. package/.output/server/node_modules/zod/v4/locales/ur.js +5 -0
  272. package/.output/server/node_modules/zod/v4/locales/uz.js +4 -0
  273. package/.output/server/node_modules/zod/v4/locales/vi.js +5 -0
  274. package/.output/server/node_modules/zod/v4/locales/yo.js +5 -0
  275. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +5 -0
  276. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +5 -0
  277. package/.output/server/node_modules/zod/v4/package.json +2 -1
  278. package/.output/server/package.json +18 -18
  279. package/README.md +9 -0
  280. package/package.json +8 -8
  281. package/.output/public/_nuxt/Czp4_2o-.js +0 -33
  282. package/.output/public/_nuxt/builds/meta/46174b5e-cab6-4a73-95f8-66a1c9b1be2b.json +0 -1
  283. package/.output/public/_nuxt/entry.DaqrxXuH.css +0 -1
  284. package/.output/public/_nuxt/error-404.CTSXlFYa.css +0 -1
  285. package/.output/public/_nuxt/error-500.DqEfQnVZ.css +0 -1
  286. package/.output/server/chunks/build/error-404-KRkA0DPI.mjs.map +0 -1
  287. package/.output/server/chunks/build/error-404-styles.I0NYw-Bn.mjs +0 -8
  288. package/.output/server/chunks/build/error-404-styles.I0NYw-Bn.mjs.map +0 -1
  289. package/.output/server/chunks/build/error-500-DIIFf55p.mjs.map +0 -1
  290. package/.output/server/chunks/build/error-500-styles.D1cs9hQy.mjs +0 -8
  291. package/.output/server/chunks/build/error-500-styles.D1cs9hQy.mjs.map +0 -1
  292. package/.output/server/chunks/build/index-CB1N4gax.mjs.map +0 -1
  293. /package/.output/server/node_modules/{@vue/compiler-core → .nitro/@vue/compiler-core@3.5.32}/dist/compiler-core.cjs.prod.js +0 -0
  294. /package/.output/server/node_modules/{@vue/compiler-core → .nitro/@vue/compiler-core@3.5.32}/package.json +0 -0
  295. /package/.output/server/node_modules/{@vue/compiler-dom → .nitro/@vue/compiler-dom@3.5.32}/dist/compiler-dom.cjs.prod.js +0 -0
  296. /package/.output/server/node_modules/{@vue/compiler-dom → .nitro/@vue/compiler-dom@3.5.32}/package.json +0 -0
  297. /package/.output/server/node_modules/{@vue/reactivity → .nitro/@vue/reactivity@3.5.32}/dist/reactivity.cjs.prod.js +0 -0
  298. /package/.output/server/node_modules/{@vue/reactivity → .nitro/@vue/reactivity@3.5.32}/package.json +0 -0
  299. /package/.output/server/node_modules/{@vue/runtime-core → .nitro/@vue/runtime-core@3.5.32}/dist/runtime-core.cjs.prod.js +0 -0
  300. /package/.output/server/node_modules/{@vue/runtime-core → .nitro/@vue/runtime-core@3.5.32}/package.json +0 -0
  301. /package/.output/server/node_modules/{@vue/runtime-dom → .nitro/@vue/runtime-dom@3.5.32}/dist/runtime-dom.cjs.prod.js +0 -0
  302. /package/.output/server/node_modules/{@vue/runtime-dom → .nitro/@vue/runtime-dom@3.5.32}/package.json +0 -0
  303. /package/.output/server/node_modules/{@vue/shared → .nitro/@vue/shared@3.5.32}/dist/shared.cjs.prod.js +0 -0
  304. /package/.output/server/node_modules/{@vue/shared → .nitro/@vue/shared@3.5.32}/package.json +0 -0
  305. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/array-set.js +0 -0
  306. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/base64-vlq.js +0 -0
  307. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/base64.js +0 -0
  308. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/binary-search.js +0 -0
  309. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/mapping-list.js +0 -0
  310. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/quick-sort.js +0 -0
  311. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-map-consumer.js +0 -0
  312. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-map-generator.js +0 -0
  313. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-node.js +0 -0
  314. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/util.js +0 -0
  315. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/package.json +0 -0
  316. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/source-map.js +0 -0
  317. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/dist/vue.cjs.js +0 -0
  318. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/dist/vue.cjs.prod.js +0 -0
  319. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/index.js +0 -0
  320. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/index.mjs +0 -0
  321. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/package.json +0 -0
  322. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.43}/server-renderer/index.mjs +0 -0
@@ -1,11 +1,13 @@
1
- import { d as defineEventHandler, u as useRuntimeConfig, c as createError, r as readStudioRequest, e as executeStudio, S as StudioExecutionError } from '../../nitro/nitro.mjs';
1
+ import { d as defineEventHandler, u as useRuntimeConfig, c as createError } from '../../nitro/nitro.mjs';
2
+ import vm from 'node:vm';
3
+ import { transformSync } from 'esbuild';
4
+ import util from 'node:util';
5
+ import { parse } from 'acorn';
6
+ import * as zod from 'zod/v4';
7
+ import { z } from 'zod/v4';
8
+ import mongoose from 'mongoose';
9
+ import { r as readStudioRequest } from '../../_/parse-request.mjs';
2
10
  import 'node:http';
3
- import 'node:vm';
4
- import 'esbuild';
5
- import 'node:util';
6
- import 'acorn';
7
- import 'zod/v4';
8
- import 'mongoose';
9
11
  import 'node:https';
10
12
  import 'node:events';
11
13
  import 'node:buffer';
@@ -16,6 +18,1596 @@ import 'node:url';
16
18
  import '@iconify/utils';
17
19
  import 'consola';
18
20
 
21
+ var __defProp$1 = Object.defineProperty;
22
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
23
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
24
+ function flatHooks(configHooks, hooks2 = {}, parentName) {
25
+ for (const key in configHooks) {
26
+ const subHook = configHooks[key];
27
+ const name = parentName ? `${parentName}:${key}` : key;
28
+ if (typeof subHook === "object" && subHook !== null) flatHooks(subHook, hooks2, name);
29
+ else if (typeof subHook === "function") hooks2[name] = subHook;
30
+ }
31
+ return hooks2;
32
+ }
33
+ const createTask = /* @__PURE__ */ (() => {
34
+ if (console.createTask) return console.createTask;
35
+ const defaultTask = { run: (fn) => fn() };
36
+ return () => defaultTask;
37
+ })();
38
+ function callHooks(hooks2, args, startIndex, task) {
39
+ for (let i = startIndex; i < hooks2.length; i += 1) try {
40
+ const result = task ? task.run(() => hooks2[i](...args)) : hooks2[i](...args);
41
+ if (result && typeof result.then === "function") return Promise.resolve(result).then(() => callHooks(hooks2, args, i + 1, task));
42
+ } catch (error) {
43
+ return Promise.reject(error);
44
+ }
45
+ }
46
+ function serialTaskCaller(hooks2, args, name) {
47
+ if (hooks2.length > 0) return callHooks(hooks2, args, 0, createTask(name));
48
+ }
49
+ function parallelTaskCaller(hooks2, args, name) {
50
+ if (hooks2.length > 0) {
51
+ const task = createTask(name);
52
+ return Promise.all(hooks2.map((hook) => task.run(() => hook(...args))));
53
+ }
54
+ }
55
+ function callEachWith(callbacks, arg0) {
56
+ for (const callback of [...callbacks]) callback(arg0);
57
+ }
58
+ var Hookable = class {
59
+ constructor() {
60
+ __publicField$1(this, "_hooks");
61
+ __publicField$1(this, "_before");
62
+ __publicField$1(this, "_after");
63
+ __publicField$1(this, "_deprecatedHooks");
64
+ __publicField$1(this, "_deprecatedMessages");
65
+ this._hooks = {};
66
+ this._before = void 0;
67
+ this._after = void 0;
68
+ this._deprecatedMessages = void 0;
69
+ this._deprecatedHooks = {};
70
+ this.hook = this.hook.bind(this);
71
+ this.callHook = this.callHook.bind(this);
72
+ this.callHookWith = this.callHookWith.bind(this);
73
+ }
74
+ hook(name, function_, options = {}) {
75
+ if (!name || typeof function_ !== "function") return () => {
76
+ };
77
+ const originalName = name;
78
+ let dep;
79
+ while (this._deprecatedHooks[name]) {
80
+ dep = this._deprecatedHooks[name];
81
+ name = dep.to;
82
+ }
83
+ if (dep && !options.allowDeprecated) {
84
+ let message = dep.message;
85
+ if (!message) message = `${originalName} hook has been deprecated` + (dep.to ? `, please use ${dep.to}` : "");
86
+ if (!this._deprecatedMessages) this._deprecatedMessages = /* @__PURE__ */ new Set();
87
+ if (!this._deprecatedMessages.has(message)) {
88
+ console.warn(message);
89
+ this._deprecatedMessages.add(message);
90
+ }
91
+ }
92
+ if (!function_.name) try {
93
+ Object.defineProperty(function_, "name", {
94
+ get: () => "_" + name.replace(/\W+/g, "_") + "_hook_cb",
95
+ configurable: true
96
+ });
97
+ } catch {
98
+ }
99
+ this._hooks[name] = this._hooks[name] || [];
100
+ this._hooks[name].push(function_);
101
+ return () => {
102
+ if (function_) {
103
+ this.removeHook(name, function_);
104
+ function_ = void 0;
105
+ }
106
+ };
107
+ }
108
+ hookOnce(name, function_) {
109
+ let _unreg;
110
+ let _function = (...arguments_) => {
111
+ if (typeof _unreg === "function") _unreg();
112
+ _unreg = void 0;
113
+ _function = void 0;
114
+ return function_(...arguments_);
115
+ };
116
+ _unreg = this.hook(name, _function);
117
+ return _unreg;
118
+ }
119
+ removeHook(name, function_) {
120
+ const hooks2 = this._hooks[name];
121
+ if (hooks2) {
122
+ const index = hooks2.indexOf(function_);
123
+ if (index !== -1) hooks2.splice(index, 1);
124
+ if (hooks2.length === 0) this._hooks[name] = void 0;
125
+ }
126
+ }
127
+ clearHook(name) {
128
+ this._hooks[name] = void 0;
129
+ }
130
+ deprecateHook(name, deprecated) {
131
+ this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
132
+ const _hooks = this._hooks[name] || [];
133
+ this._hooks[name] = void 0;
134
+ for (const hook of _hooks) this.hook(name, hook);
135
+ }
136
+ deprecateHooks(deprecatedHooks) {
137
+ for (const name in deprecatedHooks) this.deprecateHook(name, deprecatedHooks[name]);
138
+ }
139
+ addHooks(configHooks) {
140
+ const hooks2 = flatHooks(configHooks);
141
+ const removeFns = Object.keys(hooks2).map((key) => this.hook(key, hooks2[key]));
142
+ return () => {
143
+ for (const unreg of removeFns) unreg();
144
+ removeFns.length = 0;
145
+ };
146
+ }
147
+ removeHooks(configHooks) {
148
+ const hooks2 = flatHooks(configHooks);
149
+ for (const key in hooks2) this.removeHook(key, hooks2[key]);
150
+ }
151
+ removeAllHooks() {
152
+ this._hooks = {};
153
+ }
154
+ callHook(name, ...args) {
155
+ return this.callHookWith(serialTaskCaller, name, args);
156
+ }
157
+ callHookParallel(name, ...args) {
158
+ return this.callHookWith(parallelTaskCaller, name, args);
159
+ }
160
+ callHookWith(caller, name, args) {
161
+ const event = this._before || this._after ? {
162
+ name,
163
+ args,
164
+ context: {}
165
+ } : void 0;
166
+ if (this._before) callEachWith(this._before, event);
167
+ const result = caller(this._hooks[name] ? [...this._hooks[name]] : [], args, name);
168
+ if (result instanceof Promise) return result.finally(() => {
169
+ if (this._after && event) callEachWith(this._after, event);
170
+ });
171
+ if (this._after && event) callEachWith(this._after, event);
172
+ return result;
173
+ }
174
+ beforeEach(function_) {
175
+ this._before = this._before || [];
176
+ this._before.push(function_);
177
+ return () => {
178
+ if (this._before !== void 0) {
179
+ const index = this._before.indexOf(function_);
180
+ if (index !== -1) this._before.splice(index, 1);
181
+ }
182
+ };
183
+ }
184
+ afterEach(function_) {
185
+ this._after = this._after || [];
186
+ this._after.push(function_);
187
+ return () => {
188
+ if (this._after !== void 0) {
189
+ const index = this._after.indexOf(function_);
190
+ if (index !== -1) this._after.splice(index, 1);
191
+ }
192
+ };
193
+ }
194
+ };
195
+ function createHooks() {
196
+ return new Hookable();
197
+ }
198
+ const hooks = createHooks();
199
+ function callHookSync(name, ...args) {
200
+ hooks.callHookWith((callbacks, args2) => {
201
+ for (const callback of callbacks) {
202
+ callback(...args2);
203
+ }
204
+ }, name, args);
205
+ }
206
+ const mongooseRegistry = z.registry();
207
+ function withMongoose(schema, meta = {}) {
208
+ callHookSync("registry:get:before", { schema });
209
+ const existing = mongooseRegistry.get(schema) || {};
210
+ callHookSync("registry:get", { schema, meta: existing });
211
+ const merged = { ...existing, ...meta };
212
+ callHookSync("registry:add", { schema, meta: merged });
213
+ mongooseRegistry.add(schema, merged);
214
+ callHookSync("registry:added", { schema, meta: merged });
215
+ return schema;
216
+ }
217
+ function getMongooseMeta(schema) {
218
+ const def = schema._def;
219
+ if (!def) return {};
220
+ let meta = mongooseRegistry.get(schema) || {};
221
+ if (def.innerType) {
222
+ meta = { ...getMongooseMeta(def.innerType), ...meta };
223
+ } else if (def.schema) {
224
+ meta = { ...getMongooseMeta(def.schema), ...meta };
225
+ }
226
+ if (def.type === "pipe") {
227
+ meta = { ...getMongooseMeta(def.in), ...getMongooseMeta(def.out), ...meta };
228
+ }
229
+ return meta;
230
+ }
231
+ function objectStrictness(schema) {
232
+ var _a, _b, _c, _d;
233
+ const catchall = (_b = (_a = schema._zod) == null ? void 0 : _a.def) == null ? void 0 : _b.catchall;
234
+ if (!catchall) return true;
235
+ return ((_d = (_c = catchall._zod) == null ? void 0 : _c.def) == null ? void 0 : _d.type) === "never" ? "throw" : false;
236
+ }
237
+ function unwrapZodSchema(schema, features = { required: true }, visited = /* @__PURE__ */ new Set()) {
238
+ var _a, _b, _c, _d, _e;
239
+ if (!schema) return { schema, features };
240
+ if (visited.has(schema)) return { schema, features };
241
+ const def = schema._def;
242
+ if (!def) return { schema, features };
243
+ if (!(schema instanceof z.ZodOptional) && !(schema instanceof z.ZodNullable) && !(schema instanceof z.ZodDefault) && def.type !== "pipe") {
244
+ visited.add(schema);
245
+ }
246
+ if (schema instanceof z.ZodOptional) {
247
+ const inner = schema.unwrap();
248
+ const result = unwrapZodSchema(
249
+ // @ts-expect-error Zod v4 schema.unwrap() return type mismatch
250
+ inner,
251
+ features,
252
+ visited
253
+ );
254
+ return {
255
+ schema: result.schema,
256
+ features: {
257
+ ...result.features,
258
+ required: false,
259
+ isOptional: true,
260
+ isExactOptional: false,
261
+ isNonOptional: false
262
+ }
263
+ };
264
+ }
265
+ if (schema instanceof z.ZodExactOptional) {
266
+ const result = unwrapZodSchema(schema.unwrap(), features, visited);
267
+ return {
268
+ schema: result.schema,
269
+ features: {
270
+ ...result.features,
271
+ required: false,
272
+ isOptional: true,
273
+ isExactOptional: true,
274
+ isNonOptional: false
275
+ }
276
+ };
277
+ }
278
+ if (schema instanceof z.ZodNonOptional) {
279
+ const result = unwrapZodSchema(schema.unwrap(), features, visited);
280
+ return {
281
+ schema: result.schema,
282
+ features: {
283
+ ...result.features,
284
+ required: true,
285
+ isOptional: false,
286
+ isExactOptional: false,
287
+ isNonOptional: true
288
+ }
289
+ };
290
+ }
291
+ if (schema instanceof z.ZodNullable) {
292
+ return unwrapZodSchema(
293
+ // @ts-expect-error Zod v4 schema.unwrap() return type mismatch
294
+ schema.unwrap(),
295
+ {
296
+ ...features,
297
+ isNullable: true
298
+ },
299
+ visited
300
+ );
301
+ }
302
+ if (schema instanceof z.ZodDefault) {
303
+ const defaultValue = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
304
+ return unwrapZodSchema(
305
+ def.innerType,
306
+ {
307
+ ...features,
308
+ default: defaultValue
309
+ },
310
+ visited
311
+ );
312
+ }
313
+ const { type } = def;
314
+ if (type === "pipe") {
315
+ const inType = (_b = (_a = def.in) == null ? void 0 : _a._def) == null ? void 0 : _b.type;
316
+ const outType = (_d = (_c = def.out) == null ? void 0 : _c._def) == null ? void 0 : _d.type;
317
+ if (inType === "transform") {
318
+ return unwrapZodSchema(def.out, features, visited);
319
+ }
320
+ if (outType === "transform" || outType === "refinement") {
321
+ const transformFeatures = { ...features };
322
+ const outDef = (_e = def.out) == null ? void 0 : _e._def;
323
+ const effects = (outDef == null ? void 0 : outDef.effects) || (outDef == null ? void 0 : outDef.transformations) || (outType === "transform" ? [outDef] : []);
324
+ if (effects && Array.isArray(effects)) {
325
+ transformFeatures.transformations = [
326
+ ...transformFeatures.transformations || [],
327
+ ...effects
328
+ ];
329
+ }
330
+ return unwrapZodSchema(def.in, transformFeatures, visited);
331
+ }
332
+ return unwrapZodSchema(def.out, features, visited);
333
+ }
334
+ if (type === "transform" || type === "preprocess" || type === "refinement" || type === "effects") {
335
+ const transformFeatures = { ...features };
336
+ const effects = def.effects || def.transformations || (def.type === "transform" || type === "transform" ? [def] : []);
337
+ if (effects && Array.isArray(effects)) {
338
+ transformFeatures.transformations = [
339
+ ...transformFeatures.transformations || [],
340
+ ...effects
341
+ ];
342
+ }
343
+ const inner = def.schema || def.innerType;
344
+ if (inner) {
345
+ const result = unwrapZodSchema(inner, transformFeatures, visited);
346
+ return result;
347
+ }
348
+ }
349
+ if (type === "lazy") {
350
+ return { schema, features };
351
+ }
352
+ if (type === "branded" || type === "readonly") {
353
+ return unwrapZodSchema(
354
+ schema.unwrap(),
355
+ {
356
+ ...features,
357
+ ...type === "readonly" ? { readOnly: true } : {}
358
+ },
359
+ visited
360
+ );
361
+ }
362
+ if (def.checks && Array.isArray(def.checks)) {
363
+ features.checks = [...features.checks || [], ...def.checks];
364
+ }
365
+ return { schema, features };
366
+ }
367
+ function prepareForZodValidation(schema, value, mongooseSchema, pathPrefix = "") {
368
+ var _a;
369
+ if (value === null || value === void 0) return value;
370
+ const { schema: unwrapped } = unwrapZodSchema(schema);
371
+ const def = unwrapped == null ? void 0 : unwrapped._def;
372
+ if ((def == null ? void 0 : def.type) === "lazy") {
373
+ return prepareForZodValidation(def.getter(), value, mongooseSchema, pathPrefix);
374
+ }
375
+ if ((def == null ? void 0 : def.type) === "object" && typeof value === "object" && !Array.isArray(value)) {
376
+ const { shape } = unwrapped;
377
+ const result = { ...value };
378
+ if (mongooseSchema && !pathPrefix && mongooseSchema.options._id !== false && !Object.hasOwn(shape, "_id")) {
379
+ delete result._id;
380
+ }
381
+ const versionKey = !pathPrefix && (mongooseSchema == null ? void 0 : mongooseSchema.options.versionKey);
382
+ if (typeof versionKey === "string" && !Object.hasOwn(shape, versionKey)) {
383
+ delete result[versionKey];
384
+ }
385
+ const timestamps = !pathPrefix && (mongooseSchema == null ? void 0 : mongooseSchema.options.timestamps);
386
+ if (timestamps) {
387
+ for (const key of ["createdAt", "updatedAt"]) {
388
+ const configured = typeof timestamps === "object" ? timestamps[key] : void 0;
389
+ if (configured === false) continue;
390
+ const fieldName = typeof configured === "string" ? configured : key;
391
+ if (!Object.hasOwn(shape, fieldName)) delete result[fieldName];
392
+ }
393
+ }
394
+ for (const [key, fieldSchema] of Object.entries(shape)) {
395
+ if (!Object.hasOwn(result, key)) continue;
396
+ const path = pathPrefix ? `${pathPrefix}.${key}` : key;
397
+ const nestedSchema = (_a = mongooseSchema == null ? void 0 : mongooseSchema.path(path)) == null ? void 0 : _a.schema;
398
+ result[key] = prepareForZodValidation(
399
+ fieldSchema,
400
+ result[key],
401
+ nestedSchema || mongooseSchema,
402
+ nestedSchema ? "" : path
403
+ );
404
+ }
405
+ return result;
406
+ }
407
+ if (Array.isArray(value)) {
408
+ if ((def == null ? void 0 : def.type) === "array" || (def == null ? void 0 : def.type) === "set") {
409
+ const element = unwrapped.element || def.valueType;
410
+ return element ? value.map((item) => prepareForZodValidation(element, item, mongooseSchema, pathPrefix)) : value;
411
+ }
412
+ if ((def == null ? void 0 : def.type) === "tuple") {
413
+ return value.map((item, index) => {
414
+ var _a2;
415
+ const element = ((_a2 = def.items) == null ? void 0 : _a2[index]) || def.rest;
416
+ return element ? prepareForZodValidation(element, item, mongooseSchema, pathPrefix) : item;
417
+ });
418
+ }
419
+ }
420
+ return value;
421
+ }
422
+ let mongooseInstance = null;
423
+ let isFrontend;
424
+ const setFrontendMode = (enabled) => {
425
+ console.warn(
426
+ "[zod-mongoose] setFrontendMode() is deprecated and will be removed in v4. Conditional exports select the appropriate implementation automatically."
427
+ );
428
+ isFrontend = enabled;
429
+ };
430
+ const getFrontendMode = () => {
431
+ if (isFrontend === void 0 || isFrontend === null) {
432
+ return globalThis.window !== void 0 && globalThis.document !== void 0;
433
+ }
434
+ return isFrontend;
435
+ };
436
+ const setMongoose = (m) => {
437
+ mongooseInstance = m;
438
+ };
439
+ const getMongoose = () => {
440
+ var _a;
441
+ if (getFrontendMode()) {
442
+ return null;
443
+ }
444
+ if (mongooseInstance) {
445
+ return mongooseInstance;
446
+ }
447
+ try {
448
+ if (typeof require !== "undefined") {
449
+ const m = require("mongoose");
450
+ if (m && (m.Schema || ((_a = m.default) == null ? void 0 : _a.Schema))) {
451
+ return m.default || m;
452
+ }
453
+ return m;
454
+ }
455
+ return null;
456
+ } catch {
457
+ if (globalThis.mongoose) {
458
+ return globalThis.mongoose;
459
+ }
460
+ return null;
461
+ }
462
+ };
463
+ function mapZodChecksToMongoose(checks, mongooseProp) {
464
+ var _a, _b;
465
+ if (!checks || !Array.isArray(checks)) return;
466
+ for (const check of checks) {
467
+ const traitSet = (_a = check._zod) == null ? void 0 : _a.traits;
468
+ const checkDef = (_b = check._zod) == null ? void 0 : _b.def;
469
+ if (!traitSet || !checkDef) continue;
470
+ if (traitSet.has("$ZodCheckMinLength")) {
471
+ mongooseProp.minlength = checkDef.minimum;
472
+ }
473
+ if (traitSet.has("$ZodCheckMaxLength")) {
474
+ mongooseProp.maxlength = checkDef.maximum;
475
+ }
476
+ if (traitSet.has("$ZodCheckLengthEquals")) {
477
+ mongooseProp.minlength = checkDef.length;
478
+ mongooseProp.maxlength = checkDef.length;
479
+ }
480
+ if (traitSet.has("$ZodCheckGreaterThan")) {
481
+ mongooseProp.min = checkDef.value;
482
+ }
483
+ if (traitSet.has("$ZodCheckLessThan")) {
484
+ mongooseProp.max = checkDef.value;
485
+ }
486
+ if (traitSet.has("$ZodCheckRegex")) {
487
+ mongooseProp.match = checkDef.pattern;
488
+ }
489
+ if (traitSet.has("$ZodUUID")) {
490
+ const mongoose = globalThis.mongoose || globalThis.__mongoose;
491
+ if (mongoose == null ? void 0 : mongoose.Schema.Types.UUID) {
492
+ mongooseProp.type = mongoose.Schema.Types.UUID;
493
+ }
494
+ }
495
+ if (traitSet.has("$ZodISODateTime") || traitSet.has("$ZodISODate")) {
496
+ mongooseProp.type = Date;
497
+ }
498
+ if (traitSet.has("$ZodCheckOverwrite") && typeof checkDef.tx === "function") {
499
+ const txStr = checkDef.tx.toString();
500
+ if (txStr.includes(".trim()")) {
501
+ mongooseProp.trim = true;
502
+ } else if (txStr.includes(".toLowerCase()")) {
503
+ mongooseProp.lowercase = true;
504
+ } else if (txStr.includes(".toUpperCase()")) {
505
+ mongooseProp.uppercase = true;
506
+ }
507
+ }
508
+ }
509
+ callHookSync("validation:mappers", { checks, mongooseProp });
510
+ }
511
+ function handleObject(unwrapped, mongooseProp, visited, extractMongooseDef2, isField = false) {
512
+ var _a, _b, _c, _d, _e;
513
+ callHookSync("schema:object:before", { schema: unwrapped, mongooseProp, visited });
514
+ const { shape } = unwrapped;
515
+ const objDef = {};
516
+ const placeholder = mongooseProp.type ? mongooseProp : objDef;
517
+ visited.set(unwrapped, placeholder);
518
+ for (const key in shape) {
519
+ if (!Object.prototype.hasOwnProperty.call(shape, key)) continue;
520
+ if (key === "_id") {
521
+ const idMeta = mongooseRegistry.get(shape[key]) || {};
522
+ const unwrappedId = unwrapZodSchema(shape[key]).schema;
523
+ const unwrappedIdMeta = mongooseRegistry.get(unwrappedId) || {};
524
+ if (idMeta.includeId !== true && unwrappedIdMeta.includeId !== true && mongooseProp.includeId !== true) {
525
+ continue;
526
+ }
527
+ }
528
+ const def = extractMongooseDef2(shape[key], visited);
529
+ if (def && typeof def === "object" && def.__isDiscriminatorUnion) {
530
+ const mongoose = getMongoose();
531
+ if (mongoose) {
532
+ const baseSchema = new mongoose.Schema(def.baseDef, {
533
+ discriminatorKey: def.discriminatorKey,
534
+ _id: false
535
+ });
536
+ const discriminators = {};
537
+ for (const [dKey, dDef] of Object.entries(def.discriminators)) {
538
+ discriminators[dKey] = new mongoose.Schema(dDef, { _id: false });
539
+ }
540
+ objDef[key] = {
541
+ type: baseSchema,
542
+ discriminators
543
+ };
544
+ } else {
545
+ objDef[key] = def;
546
+ }
547
+ } else if (typeof def === "object" && def !== null && !Array.isArray(def)) {
548
+ const { includeId, ...cleanDef } = def;
549
+ objDef[key] = cleanDef;
550
+ } else {
551
+ objDef[key] = def;
552
+ }
553
+ callHookSync("schema:object:field", { key, schema: shape[key], objDef, visited });
554
+ }
555
+ let result;
556
+ const shouldBeSubSchema = isField && mongooseProp.schema !== false;
557
+ if (isField && mongooseProp.schema === false && !mongooseProp.type && objectStrictness(unwrapped) !== true) {
558
+ throw new Error(
559
+ "A strict, loose, or catchall Zod object needs a Mongoose subschema. Remove {schema: false} or provide a Mongoose type override."
560
+ );
561
+ }
562
+ if (shouldBeSubSchema && !mongooseProp.type) {
563
+ const mongoose = getMongoose();
564
+ if (mongoose) {
565
+ const options = typeof mongooseProp.schema === "object" ? mongooseProp.schema : {};
566
+ const { plugins, ...schemaOptions } = options;
567
+ const strict = (_b = (_a = schemaOptions.strict) != null ? _a : mongooseProp.strict) != null ? _b : objectStrictness(unwrapped);
568
+ const minimize = (_d = (_c = schemaOptions.minimize) != null ? _c : mongooseProp.minimize) != null ? _d : objectStrictness(unwrapped) === false ? false : void 0;
569
+ const subSchema = new mongoose.Schema(objDef, {
570
+ ...schemaOptions,
571
+ strict,
572
+ ...minimize === void 0 ? {} : { minimize }
573
+ });
574
+ if (plugins && Array.isArray(plugins)) {
575
+ for (const plugin of plugins) {
576
+ subSchema.plugin(plugin);
577
+ }
578
+ }
579
+ mongooseProp.type = subSchema;
580
+ }
581
+ }
582
+ if (mongooseProp.type) {
583
+ const mongoose = getMongoose();
584
+ const isSchema = mongoose && (mongooseProp.type instanceof mongoose.Schema || ((_e = mongooseProp.type.constructor) == null ? void 0 : _e.name) === "Schema");
585
+ if (!isSchema) {
586
+ Object.assign(mongooseProp, objDef);
587
+ }
588
+ result = mongooseProp;
589
+ } else {
590
+ Object.assign(mongooseProp, objDef);
591
+ const topLevelOptions = /* @__PURE__ */ new Set([
592
+ "collection",
593
+ "versionKey",
594
+ "timestamps",
595
+ "discriminatorKey",
596
+ "strict",
597
+ "id",
598
+ "_id",
599
+ "minimize",
600
+ "validateBeforeSave",
601
+ "schema"
602
+ ]);
603
+ const hasFieldMetadata = Object.keys(mongooseProp).some((k) => {
604
+ if (Object.prototype.hasOwnProperty.call(objDef, k)) return false;
605
+ if (topLevelOptions.has(k)) return false;
606
+ if (k === "required" && mongooseProp[k] === false) return false;
607
+ return true;
608
+ });
609
+ result = hasFieldMetadata ? mongooseProp : objDef;
610
+ }
611
+ callHookSync("schema:object:after", { schema: unwrapped, mongooseProp, objDef, result });
612
+ return result;
613
+ }
614
+ function handleArray(unwrapped, mongooseProp, visited, extractMongooseDef2) {
615
+ var _a;
616
+ callHookSync("schema:array:before", { schema: unwrapped, mongooseProp, visited });
617
+ const element = unwrapped.element || unwrapped._def.valueType || unwrapped._def.rest || ((_a = unwrapped._def.items) == null ? void 0 : _a[0]);
618
+ const mongoose = getMongoose();
619
+ const innerDef = element ? extractMongooseDef2(element, visited) : (mongoose == null ? void 0 : mongoose.Schema.Types.Mixed) || "Mixed";
620
+ if (!mongooseProp.type) {
621
+ if (innerDef && typeof innerDef === "object" && innerDef.__isDiscriminatorUnion && mongoose) {
622
+ const discriminators = {};
623
+ for (const [dKey, dDef] of Object.entries(innerDef.discriminators)) {
624
+ discriminators[dKey] = new mongoose.Schema(dDef, { _id: false });
625
+ }
626
+ mongooseProp.type = [
627
+ new mongoose.Schema(
628
+ {},
629
+ {
630
+ discriminatorKey: innerDef.discriminatorKey,
631
+ _id: false
632
+ }
633
+ )
634
+ ];
635
+ mongooseProp.discriminators = discriminators;
636
+ } else {
637
+ const innerType = innerDef.type || innerDef;
638
+ mongooseProp.type = [innerType];
639
+ if (typeof innerDef === "object") {
640
+ const innerMeta = { ...innerDef };
641
+ delete innerMeta.type;
642
+ Object.assign(mongooseProp, innerMeta);
643
+ mongooseProp.type = [innerType];
644
+ }
645
+ }
646
+ }
647
+ callHookSync("schema:array:after", { schema: unwrapped, mongooseProp, innerDef });
648
+ }
649
+ function handleRecord(unwrapped, mongooseProp, visited, extractMongooseDef2) {
650
+ var _a, _b;
651
+ callHookSync("schema:record:before", { schema: unwrapped, mongooseProp, visited });
652
+ const type = (_a = unwrapped._def) == null ? void 0 : _a.type;
653
+ const isMap = type === "map";
654
+ const valueType = unwrapped.valueType || unwrapped.valueSchema || unwrapped._def.valueType || unwrapped._def.valueSchema || unwrapped._def.innerType;
655
+ let innerDef;
656
+ if (!mongooseProp.type || mongooseProp.type === Map || mongooseProp.type === Object) {
657
+ mongooseProp.type = isMap ? Map : Object;
658
+ const finalValueType = valueType || unwrapped.valueSchema || ((_b = unwrapped._def) == null ? void 0 : _b.valueSchema);
659
+ if (finalValueType) {
660
+ innerDef = extractMongooseDef2(finalValueType, visited);
661
+ mongooseProp.of = innerDef.type || innerDef;
662
+ }
663
+ }
664
+ callHookSync("schema:record:after", { schema: unwrapped, mongooseProp, innerDef });
665
+ }
666
+ function areDefinitionsEqual(left, right, seen = /* @__PURE__ */ new WeakMap()) {
667
+ if (left === right) return true;
668
+ if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
669
+ return false;
670
+ }
671
+ const mongoose = getMongoose();
672
+ const leftIsSchema = mongoose && left instanceof mongoose.Schema;
673
+ const rightIsSchema = mongoose && right instanceof mongoose.Schema;
674
+ if (leftIsSchema || rightIsSchema) {
675
+ return Boolean(
676
+ leftIsSchema && rightIsSchema && areDefinitionsEqual(left.obj, right.obj, seen)
677
+ );
678
+ }
679
+ let seenRight = seen.get(left);
680
+ if (seenRight == null ? void 0 : seenRight.has(right)) return true;
681
+ if (!seenRight) {
682
+ seenRight = /* @__PURE__ */ new WeakSet();
683
+ seen.set(left, seenRight);
684
+ }
685
+ seenRight.add(right);
686
+ if (Array.isArray(left) || Array.isArray(right)) {
687
+ return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => areDefinitionsEqual(value, right[index], seen));
688
+ }
689
+ const leftKeys = Object.keys(left);
690
+ const rightKeys = Object.keys(right);
691
+ return leftKeys.length === rightKeys.length && leftKeys.every(
692
+ (key) => Object.prototype.hasOwnProperty.call(right, key) && areDefinitionsEqual(left[key], right[key], seen)
693
+ );
694
+ }
695
+ function extractMongooseDef(schema, visited = /* @__PURE__ */ new Map(), isField = false, noWrap = false) {
696
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
697
+ if (visited.size === 0) {
698
+ callHookSync("converter:before", { schema, visited });
699
+ }
700
+ callHookSync("converter:start", { schema, visited });
701
+ const { schema: unwrapped, features } = unwrapZodSchema(schema);
702
+ const meta = mongooseRegistry.get(schema) || {};
703
+ const mongooseProp = getMongooseMeta(schema);
704
+ callHookSync("converter:unwrapped", {
705
+ schema,
706
+ unwrapped,
707
+ features,
708
+ meta: mongooseProp,
709
+ mongooseProp
710
+ });
711
+ if (features.isOptional === true && mongooseProp.type && mongooseProp.required !== true) {
712
+ mongooseProp.required = false;
713
+ }
714
+ if (visited.has(schema)) {
715
+ const existing = visited.get(schema);
716
+ if (existing === mongooseProp) {
717
+ return existing;
718
+ }
719
+ if (Object.keys(meta).length > 0) {
720
+ Object.assign(existing, mongooseProp);
721
+ }
722
+ return existing;
723
+ }
724
+ visited.set(schema, mongooseProp);
725
+ if (features.default !== void 0) {
726
+ mongooseProp.default = features.default;
727
+ }
728
+ if (features.required === false) {
729
+ mongooseProp.required = false;
730
+ }
731
+ if (features.isNullable === true && mongooseProp.required === void 0) {
732
+ mongooseProp.required = false;
733
+ }
734
+ if (features.isNonOptional === true && features.isNullable !== true && mongooseProp.required !== false) {
735
+ mongooseProp.required = true;
736
+ }
737
+ if (features.readOnly === true) {
738
+ mongooseProp.readOnly = true;
739
+ }
740
+ if (isField && features.isExactOptional === true) {
741
+ const previousSetter = mongooseProp.set;
742
+ mongooseProp.set = function exactOptionalSetter(value) {
743
+ if (value === void 0) {
744
+ throw new TypeError("An exactOptional field cannot be set to undefined");
745
+ }
746
+ return typeof previousSetter === "function" ? previousSetter.call(this, value) : value;
747
+ };
748
+ }
749
+ mapZodChecksToMongoose(features.checks, mongooseProp);
750
+ const def = unwrapped._def;
751
+ if (!def) {
752
+ callHookSync("converter:after", {
753
+ schema,
754
+ mongooseProp
755
+ });
756
+ return mongooseProp;
757
+ }
758
+ const { type } = def;
759
+ callHookSync("converter:node", {
760
+ schema: unwrapped,
761
+ mongooseProp,
762
+ type
763
+ });
764
+ if (type === "object") {
765
+ const wrapperFn = (s, v) => extractMongooseDef(s, v, true);
766
+ const previousUnwrapped = schema === unwrapped ? void 0 : visited.get(unwrapped);
767
+ const result = handleObject(unwrapped, mongooseProp, visited, wrapperFn, isField && !noWrap);
768
+ visited.set(schema, result);
769
+ if (schema !== unwrapped) {
770
+ if (previousUnwrapped === void 0) visited.delete(unwrapped);
771
+ else visited.set(unwrapped, previousUnwrapped);
772
+ }
773
+ callHookSync("converter:after", {
774
+ schema,
775
+ mongooseProp: result
776
+ });
777
+ if (typeof result === "object" && result !== null && !Array.isArray(result)) {
778
+ delete result.includeId;
779
+ }
780
+ return result;
781
+ }
782
+ if (type === "array" || type === "set" || type === "tuple") {
783
+ handleArray(unwrapped, mongooseProp, visited, (s, v) => extractMongooseDef(s, v, true));
784
+ }
785
+ if (type === "record" || type === "map") {
786
+ handleRecord(unwrapped, mongooseProp, visited, (s, v) => extractMongooseDef(s, v, true));
787
+ }
788
+ if (type === "intersection") {
789
+ const left = extractMongooseDef(unwrapped._def.left, visited, isField, true);
790
+ const right = extractMongooseDef(unwrapped._def.right, visited, isField, true);
791
+ if (typeof left === "object" && typeof right === "object") {
792
+ Object.assign(mongooseProp, left, right);
793
+ if (isField && !noWrap && mongooseProp.schema !== false && !mongooseProp.type) {
794
+ const mongoose = getMongoose();
795
+ if (mongoose) {
796
+ const options = typeof mongooseProp.schema === "object" ? mongooseProp.schema : {};
797
+ const { plugins, ...schemaOptions } = options;
798
+ const definition = { ...mongooseProp };
799
+ delete definition.schema;
800
+ const subSchema = new mongoose.Schema(definition, schemaOptions);
801
+ if (plugins && Array.isArray(plugins)) {
802
+ for (const plugin of plugins) {
803
+ subSchema.plugin(plugin);
804
+ }
805
+ }
806
+ mongooseProp.type = subSchema;
807
+ for (const key of Object.keys(mongooseProp)) {
808
+ if (key !== "type") delete mongooseProp[key];
809
+ }
810
+ }
811
+ }
812
+ } else if (!mongooseProp.type) {
813
+ mongooseProp.type = ((_a = getMongoose()) == null ? void 0 : _a.Schema.Types.Mixed) || "Mixed";
814
+ }
815
+ }
816
+ if ((type === "union" || type === "discriminatedunion" || type === "discriminated_union" || type === "xor") && !mongooseProp.type) {
817
+ const mongoose = getMongoose();
818
+ const options = unwrapped.options || unwrapped._def.options;
819
+ const discriminatorKey = unwrapped._def.discriminator;
820
+ const unionCtx = {
821
+ isSimpleUnion: false,
822
+ isObjectUnion: false,
823
+ isXor: type === "xor" || (((_b = unwrapped._def) == null ? void 0 : _b.inclusive) === false || ((_c = schema._def) == null ? void 0 : _c.inclusive) === false) && !discriminatorKey && !((_d = schema._def) == null ? void 0 : _d.discriminator)
824
+ };
825
+ if (Array.isArray(options) && options.length > 0) {
826
+ unionCtx.isSimpleUnion = options.every((opt) => {
827
+ const { type: type2 } = unwrapZodSchema(opt).schema._def;
828
+ return ["string", "number", "boolean", "date", "bigint", "literal"].includes(type2);
829
+ });
830
+ unionCtx.isObjectUnion = options.every((opt) => {
831
+ const { type: type2 } = unwrapZodSchema(opt).schema._def;
832
+ return type2 === "object";
833
+ });
834
+ }
835
+ callHookSync("schema:union:before", { schema: unwrapped, mongooseProp, ctx: unionCtx });
836
+ if (discriminatorKey && unionCtx.isObjectUnion) {
837
+ const discriminators = {};
838
+ const allOptionDefs = [];
839
+ for (const option of options) {
840
+ const { schema: unwrappedOpt } = unwrapZodSchema(option);
841
+ const { shape } = unwrappedOpt._def;
842
+ const discriminatorProp = shape[discriminatorKey];
843
+ const { schema: unwrappedDisc } = unwrapZodSchema(discriminatorProp);
844
+ const discriminatorValue = (_f = unwrappedDisc._def.value) != null ? _f : (_e = unwrappedDisc._def.values) == null ? void 0 : _e[0];
845
+ const optionDef = extractMongooseDef(option, /* @__PURE__ */ new Map(), true, true);
846
+ if (optionDef && typeof optionDef === "object" && !Array.isArray(optionDef)) {
847
+ const cleanOptionDef = { ...optionDef };
848
+ delete cleanOptionDef[discriminatorKey];
849
+ discriminators[discriminatorValue] = cleanOptionDef;
850
+ allOptionDefs.push(cleanOptionDef);
851
+ }
852
+ }
853
+ const baseDef = {};
854
+ if (allOptionDefs.length > 0) {
855
+ const firstOption = allOptionDefs[0];
856
+ for (const key of Object.keys(firstOption)) {
857
+ const isCommon = allOptionDefs.every((def2) => {
858
+ if (!(key in def2)) return false;
859
+ return areDefinitionsEqual(def2[key], firstOption[key]);
860
+ });
861
+ if (isCommon) {
862
+ baseDef[key] = firstOption[key];
863
+ for (const def2 of allOptionDefs) {
864
+ delete def2[key];
865
+ }
866
+ }
867
+ }
868
+ }
869
+ const result = {
870
+ __isDiscriminatorUnion: true,
871
+ discriminatorKey,
872
+ discriminators,
873
+ baseDef,
874
+ validate: {
875
+ validator(_v) {
876
+ var _a2, _b2;
877
+ try {
878
+ const mongoose2 = getMongoose();
879
+ const doc = mongoose2 && this instanceof mongoose2.Document ? this.toObject() : this || {};
880
+ schema.parse(doc);
881
+ return true;
882
+ } catch (err) {
883
+ const message = ((_b2 = (_a2 = err == null ? void 0 : err.errors) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.message) || err.message;
884
+ if (this && typeof this.invalidate === "function") {
885
+ this.invalidate(discriminatorKey, `Zod validation failed: ${message}`);
886
+ }
887
+ return false;
888
+ }
889
+ },
890
+ message: (props) => `Validation failed for ${props.path}`
891
+ }
892
+ };
893
+ if (mongooseProp && typeof mongooseProp === "object" && !Array.isArray(mongooseProp)) {
894
+ Object.assign(mongooseProp, result);
895
+ callHookSync("schema:union:after", {
896
+ schema: unwrapped,
897
+ mongooseProp,
898
+ ctx: unionCtx
899
+ });
900
+ return mongooseProp;
901
+ }
902
+ callHookSync("schema:union:after", {
903
+ schema: unwrapped,
904
+ mongooseProp: result,
905
+ ctx: unionCtx
906
+ });
907
+ return result;
908
+ }
909
+ if (((_g = getMongoose()) == null ? void 0 : _g.Schema.Types.Union) && unionCtx.isSimpleUnion && options.length > 0 && !unionCtx.isXor) {
910
+ mongooseProp.type = mongoose.Schema.Types.Union;
911
+ mongooseProp.of = options.map((opt) => {
912
+ const def2 = extractMongooseDef(opt, visited, true, true);
913
+ return def2.type || def2;
914
+ });
915
+ } else if (unionCtx.isObjectUnion && options.length > 0) {
916
+ const mergedDef = {};
917
+ for (const opt of options) {
918
+ const def2 = extractMongooseDef(opt, /* @__PURE__ */ new Map(), true, true);
919
+ if (typeof def2 === "object" && def2 !== null) {
920
+ for (const [key, prop] of Object.entries(def2)) {
921
+ if (typeof prop === "object" && prop !== null && !Array.isArray(prop)) {
922
+ prop.required = false;
923
+ }
924
+ if (mergedDef[key] && typeof mergedDef[key] === "object" && typeof prop === "object" && !Array.isArray(mergedDef[key]) && !Array.isArray(prop)) {
925
+ const existingType = mergedDef[key].type || mergedDef[key].instance || (typeof mergedDef[key] === "function" ? mergedDef[key] : null);
926
+ const newType = prop.type || prop.instance || (typeof prop === "function" ? prop : null);
927
+ const isMixed = (t) => {
928
+ var _a2, _b2;
929
+ return !t || t === "Mixed" || t === "SchemaMixed" || (t == null ? void 0 : t.name) === "Mixed" || (t == null ? void 0 : t.instance) === "Mixed" || (t == null ? void 0 : t.name) === "SchemaMixed" || (t == null ? void 0 : t.instance) === "SchemaMixed" || ((_a2 = getMongoose()) == null ? void 0 : _a2.Schema.Types.Mixed) && (t === ((_b2 = getMongoose()) == null ? void 0 : _b2.Schema.Types.Mixed) || (t == null ? void 0 : t.instance) === "Mixed" || (t == null ? void 0 : t.instance) === "SchemaMixed");
930
+ };
931
+ if (isMixed(existingType) && !isMixed(newType)) {
932
+ mergedDef[key] = prop;
933
+ } else if (!isMixed(existingType) && isMixed(newType)) ;
934
+ else {
935
+ Object.assign(mergedDef[key], prop);
936
+ }
937
+ } else if (!mergedDef[key] || typeof mergedDef[key] !== "object" || Array.isArray(mergedDef[key])) {
938
+ mergedDef[key] = prop;
939
+ }
940
+ }
941
+ }
942
+ }
943
+ if (isField && unionCtx.isXor) {
944
+ mongooseProp.type = (mongoose == null ? void 0 : mongoose.Schema.Types.Mixed) || "Mixed";
945
+ mongooseProp.validate = {
946
+ validator(v) {
947
+ try {
948
+ schema.parse(v);
949
+ return true;
950
+ } catch {
951
+ return false;
952
+ }
953
+ },
954
+ message: "XOR validation failed"
955
+ };
956
+ } else {
957
+ if (!mongooseProp.type || mongooseProp.type === (((_h = getMongoose()) == null ? void 0 : _h.Schema.Types.Mixed) || "Mixed")) {
958
+ delete mongooseProp.type;
959
+ }
960
+ Object.assign(mongooseProp, mergedDef);
961
+ if (isField && Object.prototype.hasOwnProperty.call(mongooseProp, "type") && Object.keys(mongooseProp).length > 1) {
962
+ const mongooseInstance22 = getMongoose();
963
+ if (mongooseInstance22) {
964
+ mongooseProp.type = new mongooseInstance22.Schema(mongooseProp, { _id: false });
965
+ for (const key of Object.keys(mongooseProp)) {
966
+ if (key !== "type") delete mongooseProp[key];
967
+ }
968
+ }
969
+ }
970
+ }
971
+ } else {
972
+ mongooseProp.type = (mongoose == null ? void 0 : mongoose.Schema.Types.Mixed) || "Mixed";
973
+ if (isField && (type === "xor" || type === "discriminated_union" || type === "discriminatedunion" || type === "union") && !mongooseProp.ref && // Skip Zod validation for populated fields
974
+ !Array.isArray(mongooseProp.type) && // Skip Zod validation for arrays
975
+ mongooseProp.type !== Map && // Skip Zod validation for maps
976
+ !mongooseProp.of) {
977
+ mongooseProp.validate = {
978
+ validator(v) {
979
+ try {
980
+ schema.parse(v);
981
+ return true;
982
+ } catch (err) {
983
+ return false;
984
+ }
985
+ },
986
+ message: (props) => {
987
+ if (unionCtx.isXor) return "XOR validation failed";
988
+ try {
989
+ schema.parse(props.value);
990
+ } catch (err) {
991
+ return `Union validation failed: ${err.message}`;
992
+ }
993
+ return "Union validation failed";
994
+ }
995
+ };
996
+ }
997
+ }
998
+ callHookSync("schema:union:after", {
999
+ schema: unwrapped,
1000
+ mongooseProp,
1001
+ ctx: unionCtx
1002
+ });
1003
+ }
1004
+ if (type === "literal" && !mongooseProp.type) {
1005
+ mongooseProp.type = ((_i = getMongoose()) == null ? void 0 : _i.Schema.Types.Mixed) || "Mixed";
1006
+ }
1007
+ switch (type) {
1008
+ case "string":
1009
+ case "number":
1010
+ case "boolean":
1011
+ case "date":
1012
+ case "bigint":
1013
+ case "stringbool":
1014
+ case "boolstring":
1015
+ case "booleanstring": {
1016
+ if (!mongooseProp.type) {
1017
+ if (type === "bigint") {
1018
+ mongooseProp.type = typeof BigInt === "undefined" ? Number : BigInt;
1019
+ } else {
1020
+ const typeMap = {
1021
+ string: String,
1022
+ number: Number,
1023
+ boolean: Boolean,
1024
+ date: Date,
1025
+ stringbool: Boolean,
1026
+ boolstring: Boolean,
1027
+ booleanstring: Boolean
1028
+ };
1029
+ mongooseProp.type = typeMap[type];
1030
+ if (mongooseProp.default !== void 0) {
1031
+ const defaultType = typeof mongooseProp.default;
1032
+ if (defaultType === "boolean" && type !== "boolean") {
1033
+ mongooseProp.type = Boolean;
1034
+ } else if (defaultType === "number" && type !== "number") {
1035
+ mongooseProp.type = Number;
1036
+ } else if (defaultType === "string" && type !== "string") {
1037
+ mongooseProp.type = String;
1038
+ } else if (mongooseProp.default instanceof Date && type !== "date") {
1039
+ mongooseProp.type = Date;
1040
+ }
1041
+ }
1042
+ if (mongooseProp.type === String && features.transformations) {
1043
+ for (const tx of features.transformations) {
1044
+ const txStr = ((_j = tx.transform) == null ? void 0 : _j.toString()) || tx.toString();
1045
+ if (txStr.includes("stringbool") || txStr.includes("boolstring") || txStr.includes("booleanstring")) {
1046
+ mongooseProp.type = Boolean;
1047
+ break;
1048
+ }
1049
+ if (txStr.includes('=== "true"') || txStr.includes("=== 'true'")) {
1050
+ mongooseProp.type = Boolean;
1051
+ break;
1052
+ }
1053
+ }
1054
+ }
1055
+ }
1056
+ }
1057
+ if (mongooseProp.required !== false) mongooseProp.required = true;
1058
+ break;
1059
+ }
1060
+ case "enum":
1061
+ case "nativeenum":
1062
+ case "native_enum": {
1063
+ if (!mongooseProp.type) mongooseProp.type = String;
1064
+ mongooseProp.enum = type === "enum" ? unwrapped.options || def.values : Object.values(unwrapped.enum || def.values);
1065
+ if (mongooseProp.required !== false) mongooseProp.required = true;
1066
+ break;
1067
+ }
1068
+ }
1069
+ const mongooseInstance2 = getMongoose();
1070
+ if (type === "any" || type === "unknown" || type === "custom") {
1071
+ const cls = def.cls || unwrapped.cls;
1072
+ if (cls === Buffer || typeof Uint8Array !== "undefined" && cls === Uint8Array) {
1073
+ if (!mongooseProp.type) mongooseProp.type = (mongooseInstance2 == null ? void 0 : mongooseInstance2.Schema.Types.Buffer) || "Buffer";
1074
+ } else if (((cls == null ? void 0 : cls.name) === "ObjectId" || mongooseInstance2 && cls === mongooseInstance2.Types.ObjectId) && !mongooseProp.type) {
1075
+ mongooseProp.type = (mongooseInstance2 == null ? void 0 : mongooseInstance2.Schema.Types.ObjectId) || "ObjectId";
1076
+ }
1077
+ }
1078
+ if (type === "lazy") {
1079
+ const inner = def.getter();
1080
+ const result = extractMongooseDef(inner, visited, isField);
1081
+ if (Object.keys(meta).length > 0 && result !== mongooseProp) {
1082
+ if (typeof result === "object" && !Array.isArray(result)) {
1083
+ Object.assign(mongooseProp, result);
1084
+ } else {
1085
+ mongooseProp.type = result.type || result;
1086
+ }
1087
+ return mongooseProp;
1088
+ }
1089
+ return result;
1090
+ }
1091
+ if (!mongooseProp.type && type !== "object") {
1092
+ mongooseProp.type = ((_k = getMongoose()) == null ? void 0 : _k.Schema.Types.Mixed) || "Mixed";
1093
+ }
1094
+ callHookSync("converter:after", {
1095
+ schema,
1096
+ mongooseProp
1097
+ });
1098
+ if (typeof mongooseProp === "object" && mongooseProp !== null && !Array.isArray(mongooseProp)) {
1099
+ delete mongooseProp.includeId;
1100
+ }
1101
+ return mongooseProp;
1102
+ }
1103
+ function modelNameFromCollection(collection) {
1104
+ const singular = collection.replace(/ies$/i, "y").replace(/(ses|xes|zes|ches|shes)$/i, (suffix) => suffix.slice(0, -2)).replace(/s$/i, "");
1105
+ return singular.slice(0, 1).toUpperCase() + singular.slice(1);
1106
+ }
1107
+ function toMongooseSchema(schema, options) {
1108
+ var _a, _b;
1109
+ const { schema: unwrapped } = unwrapZodSchema(schema);
1110
+ const meta = mongooseRegistry.get(schema) || mongooseRegistry.get(unwrapped) || ((_a = schema.meta) == null ? void 0 : _a.call(schema)) || ((_b = unwrapped.meta) == null ? void 0 : _b.call(unwrapped)) || {};
1111
+ const { plugins, modelName, ...schemaOptions } = options || {};
1112
+ const mergedOptions = {
1113
+ ...unwrapped instanceof z.ZodObject ? { strict: objectStrictness(unwrapped) } : {},
1114
+ ...unwrapped instanceof z.ZodObject && objectStrictness(unwrapped) === false ? { minimize: false } : {},
1115
+ // Also merge other schema options from meta if they exist
1116
+ ...meta.collection ? { collection: meta.collection } : {},
1117
+ // eslint-disable-next-line unicorn/no-negated-condition
1118
+ ...meta.strict !== void 0 ? { strict: meta.strict } : {},
1119
+ // eslint-disable-next-line unicorn/no-negated-condition
1120
+ ...meta.minimize !== void 0 ? { minimize: meta.minimize } : {},
1121
+ // eslint-disable-next-line unicorn/no-negated-condition
1122
+ ...meta.validateBeforeSave !== void 0 ? { validateBeforeSave: meta.validateBeforeSave } : {},
1123
+ // eslint-disable-next-line unicorn/no-negated-condition
1124
+ ...meta.versionKey !== void 0 ? { versionKey: meta.versionKey } : {},
1125
+ ...meta.id === void 0 ? {} : { id: meta.id },
1126
+ ...meta._id === void 0 ? {} : { _id: meta._id },
1127
+ ...meta.timestamps ? { timestamps: meta.timestamps } : {},
1128
+ ...meta.discriminatorKey ? { discriminatorKey: meta.discriminatorKey } : {},
1129
+ ...schemaOptions
1130
+ };
1131
+ let definition = extractMongooseDef(schema, /* @__PURE__ */ new Map(), false);
1132
+ const mongoose = getMongoose();
1133
+ if (!mongoose) {
1134
+ throw new Error(
1135
+ "Mongoose must be installed to use toMongooseSchema. If you are in an ESM environment, ensure mongoose is loaded."
1136
+ );
1137
+ }
1138
+ let mongooseSchema;
1139
+ if (definition && typeof definition === "object" && definition.__isDiscriminatorUnion) {
1140
+ const baseModelName = modelName || (options == null ? void 0 : options.collection) && modelNameFromCollection(options.collection);
1141
+ if (!baseModelName) {
1142
+ throw new Error(
1143
+ "toMongooseSchema() found a top-level discriminated union. Provide `modelName` or `collection` so discriminator model names can be made unique, for example `{ modelName: 'Activity' }`."
1144
+ );
1145
+ }
1146
+ const { discriminatorKey, discriminators, baseDef, validate } = definition;
1147
+ mongooseSchema = new mongoose.Schema(baseDef, {
1148
+ ...mergedOptions,
1149
+ discriminatorKey
1150
+ });
1151
+ if (validate) {
1152
+ if (!mongooseSchema.path(discriminatorKey)) {
1153
+ mongooseSchema.add({ [discriminatorKey]: { type: String } });
1154
+ }
1155
+ mongooseSchema.path(discriminatorKey).validate(validate);
1156
+ }
1157
+ for (const [key, dDef] of Object.entries(discriminators)) {
1158
+ const discriminatorModelName = `${baseModelName}_${key}`;
1159
+ if (mongooseSchema.discriminators && mongooseSchema.discriminators[discriminatorModelName]) {
1160
+ continue;
1161
+ }
1162
+ mongooseSchema.discriminator(
1163
+ discriminatorModelName,
1164
+ new mongoose.Schema(dDef, { _id: false }),
1165
+ { value: key }
1166
+ );
1167
+ }
1168
+ } else {
1169
+ if (typeof definition === "object" && definition !== null) {
1170
+ const { includeId, ...cleanDefinition } = definition;
1171
+ definition = cleanDefinition;
1172
+ for (const value of Object.values(definition)) {
1173
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1174
+ delete value.includeId;
1175
+ }
1176
+ }
1177
+ }
1178
+ mongooseSchema = new mongoose.Schema(definition, mergedOptions);
1179
+ }
1180
+ if (mergedOptions.validateBeforeSave !== false) {
1181
+ mongooseSchema.post("validate", function() {
1182
+ var _a2, _b2, _c, _d;
1183
+ try {
1184
+ schema.parse(prepareForZodValidation(schema, this.toObject(), mongooseSchema));
1185
+ } catch (e) {
1186
+ if (e instanceof z.ZodError) {
1187
+ e.message = JSON.stringify({
1188
+ context: {
1189
+ model: ((_a2 = this.constructor) == null ? void 0 : _a2.modelName) || ((_b2 = this.constructor) == null ? void 0 : _b2.name) || "_unknown_",
1190
+ id: ((_c = this._id) == null ? void 0 : _c.toString()) || ((_d = this.id) == null ? void 0 : _d.toString()) || "_unknown_"
1191
+ },
1192
+ errors: e.issues || e.errors || []
1193
+ });
1194
+ }
1195
+ throw e;
1196
+ }
1197
+ });
1198
+ }
1199
+ if (plugins && Array.isArray(plugins)) {
1200
+ for (const plugin of plugins) {
1201
+ mongooseSchema.plugin(plugin);
1202
+ }
1203
+ }
1204
+ callHookSync("schema:created", {
1205
+ schema,
1206
+ mongooseSchema,
1207
+ options: mergedOptions
1208
+ });
1209
+ return mongooseSchema;
1210
+ }
1211
+ function populateZodSchema(schema, keys) {
1212
+ const { shape } = schema;
1213
+ const newShape = { ...shape };
1214
+ const keysToPopulate = keys || Object.keys(shape);
1215
+ const populateField = (field) => {
1216
+ const meta = getMongooseMeta(field);
1217
+ const { schema: unwrapped, features } = unwrapZodSchema(field);
1218
+ let result = field;
1219
+ if (meta == null ? void 0 : meta.refSchema) {
1220
+ result = meta.refSchema;
1221
+ } else if (unwrapped instanceof z.ZodArray) {
1222
+ const populatedInner = populateField(unwrapped.element);
1223
+ if (populatedInner !== unwrapped.element) {
1224
+ result = z.array(populatedInner);
1225
+ }
1226
+ } else if (unwrapped instanceof z.ZodObject) {
1227
+ result = populateZodSchema(unwrapped);
1228
+ }
1229
+ if (result !== field && result !== unwrapped) {
1230
+ if (features.isOptional && !(result instanceof z.ZodOptional)) result = result.optional();
1231
+ if (features.isNullable && !(result instanceof z.ZodNullable)) result = result.nullable();
1232
+ if (features.default !== void 0 && !(result instanceof z.ZodDefault)) result = result.default(features.default);
1233
+ }
1234
+ return result;
1235
+ };
1236
+ for (const key of keysToPopulate) {
1237
+ newShape[key] = populateField(shape[key]);
1238
+ }
1239
+ return z.object(newShape);
1240
+ }
1241
+ const genTimestampsSchema = (createdAtField = "createdAt", updatedAtField = "updatedAt") => {
1242
+ if (createdAtField != null && updatedAtField != null && createdAtField === updatedAtField) {
1243
+ throw new Error("`createdAt` and `updatedAt` fields must be different");
1244
+ }
1245
+ const shape = {};
1246
+ if (createdAtField != null) shape[createdAtField] = z.date().default(() => /* @__PURE__ */ new Date());
1247
+ if (updatedAtField != null) shape[updatedAtField] = z.date().default(() => /* @__PURE__ */ new Date());
1248
+ return shape;
1249
+ };
1250
+ const bufferMongooseGetter = (value) => value != null && value._bsontype === "Binary" ? value.buffer : value;
1251
+ const position = z.tuple([z.number(), z.number()]);
1252
+ const zPoint = (options) => withMongoose(
1253
+ z.object({
1254
+ type: withMongoose(z.literal("Point"), { type: String, enum: ["Point"], required: true }),
1255
+ coordinates: withMongoose(position, { required: true })
1256
+ }),
1257
+ { schema: { _id: false }, required: true, ...options }
1258
+ );
1259
+ const zPolygon = (options) => withMongoose(
1260
+ z.object({
1261
+ type: withMongoose(z.literal("Polygon"), { type: String, enum: ["Polygon"], required: true }),
1262
+ coordinates: withMongoose(
1263
+ z.array(
1264
+ z.array(position).refine(
1265
+ (ring) => {
1266
+ var _a, _b, _c, _d;
1267
+ return ring.length >= 4 && ((_a = ring[0]) == null ? void 0 : _a[0]) === ((_b = ring.at(-1)) == null ? void 0 : _b[0]) && ((_c = ring[0]) == null ? void 0 : _c[1]) === ((_d = ring.at(-1)) == null ? void 0 : _d[1]);
1268
+ },
1269
+ "Polygon rings must be closed"
1270
+ )
1271
+ ).refine((rings) => rings.length > 0, "Polygon must have at least one ring"),
1272
+ { required: true }
1273
+ )
1274
+ }),
1275
+ { schema: { _id: false }, required: true, ...options }
1276
+ );
1277
+ const preprocessFn = (val) => val === null ? void 0 : val;
1278
+ const zObjectId = (options) => {
1279
+ var _a;
1280
+ const objectIdSchema = z.custom(
1281
+ (val) => {
1282
+ const mongooseInstance2 = getMongoose();
1283
+ return mongooseInstance2 && val instanceof mongooseInstance2.Types.ObjectId;
1284
+ }
1285
+ );
1286
+ const baseUnion = z.preprocess(
1287
+ preprocessFn,
1288
+ z.union([objectIdSchema, z.string().regex(/^[\dA-Fa-f]{24}$/, "Invalid ObjectId")])
1289
+ );
1290
+ const inputSchema = z.codec(baseUnion, objectIdSchema, {
1291
+ decode: (val) => {
1292
+ const mongooseInstance2 = getMongoose();
1293
+ if (!mongooseInstance2) return val;
1294
+ if (val instanceof mongooseInstance2.Types.ObjectId) {
1295
+ return val;
1296
+ }
1297
+ return new mongooseInstance2.Types.ObjectId(val);
1298
+ },
1299
+ encode: (val) => val.toString()
1300
+ });
1301
+ return withMongoose(inputSchema, {
1302
+ type: ((_a = getMongoose()) == null ? void 0 : _a.Schema.Types.ObjectId) || "ObjectId",
1303
+ ...options
1304
+ });
1305
+ };
1306
+ const zBuffer = (options) => {
1307
+ var _a;
1308
+ return withMongoose(
1309
+ z.preprocess(
1310
+ (val) => {
1311
+ var _a2;
1312
+ const Binary = (_a2 = getMongoose()) == null ? void 0 : _a2.mongo.Binary;
1313
+ return Binary && val instanceof Binary ? Buffer.from(val.value()) : val;
1314
+ },
1315
+ z.custom((val) => val instanceof Uint8Array)
1316
+ ),
1317
+ { type: ((_a = getMongoose()) == null ? void 0 : _a.Schema.Types.Buffer) || "Buffer", ...options }
1318
+ );
1319
+ };
1320
+ const zRef = (ref, schema, options) => {
1321
+ var _a;
1322
+ const objectIdSchema = zObjectId();
1323
+ const base = z.codec(z.union([objectIdSchema, schema]), objectIdSchema, {
1324
+ decode: (val) => typeof val === "object" && val !== null && "_id" in val ? val._id : val,
1325
+ encode: (val) => val
1326
+ });
1327
+ return withMongoose(base, {
1328
+ type: ((_a = getMongoose()) == null ? void 0 : _a.Schema.Types.ObjectId) || "ObjectId",
1329
+ ref,
1330
+ refSchema: schema,
1331
+ ...options
1332
+ });
1333
+ };
1334
+ function toStrictModel(name, mongooseSchema) {
1335
+ const m = getMongoose();
1336
+ if (!m) {
1337
+ throw new Error("Mongoose must be installed to use toStrictModel.");
1338
+ }
1339
+ const rawModel = m.model(name, mongooseSchema);
1340
+ return rawModel;
1341
+ }
1342
+
1343
+ const mongooseZod = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1344
+ __proto__: null,
1345
+ bufferMongooseGetter: bufferMongooseGetter,
1346
+ callHookSync: callHookSync,
1347
+ extractMongooseDef: extractMongooseDef,
1348
+ genTimestampsSchema: genTimestampsSchema,
1349
+ getFrontendMode: getFrontendMode,
1350
+ getMongoose: getMongoose,
1351
+ getMongooseMeta: getMongooseMeta,
1352
+ hooks: hooks,
1353
+ mongooseRegistry: mongooseRegistry,
1354
+ objectStrictness: objectStrictness,
1355
+ populateZodSchema: populateZodSchema,
1356
+ setFrontendMode: setFrontendMode,
1357
+ setMongoose: setMongoose,
1358
+ toMongooseSchema: toMongooseSchema,
1359
+ toStrictModel: toStrictModel,
1360
+ unwrapZodSchema: unwrapZodSchema,
1361
+ withMongoose: withMongoose,
1362
+ zBuffer: zBuffer,
1363
+ zObjectId: zObjectId,
1364
+ zPoint: zPoint,
1365
+ zPolygon: zPolygon,
1366
+ zRef: zRef
1367
+ }, Symbol.toStringTag, { value: 'Module' }));
1368
+
1369
+ function checks(schema) {
1370
+ return (schema._def.checks || []).map((check) => {
1371
+ var _a;
1372
+ return ((_a = check._zod) == null ? void 0 : _a.def) || check.def || {};
1373
+ });
1374
+ }
1375
+ function sampleString(schema, key) {
1376
+ var _a;
1377
+ const rules = checks(schema);
1378
+ const format = schema._def.format || ((_a = rules.find((rule) => rule.format)) == null ? void 0 : _a.format);
1379
+ if (format === "email" || /email/i.test(key)) return "alex@example.com";
1380
+ if (format === "uuid") return "123e4567-e89b-42d3-a456-426614174000";
1381
+ if (format === "url") return "https://example.com";
1382
+ if (format === "datetime") return "2026-01-01T12:00:00.000Z";
1383
+ if (format === "date") return "2026-01-01";
1384
+ const minimum = Math.max(1, ...rules.filter((rule) => rule.check === "min_length").map((rule) => rule.minimum));
1385
+ const base = /name/i.test(key) ? "Alex Morgan" : /title/i.test(key) ? "Example title" : "example";
1386
+ return base.padEnd(Math.min(minimum, 100), "x");
1387
+ }
1388
+ function sampleNumber(schema) {
1389
+ const rules = checks(schema);
1390
+ const lower = rules.find((rule) => rule.check === "greater_than");
1391
+ const upper = rules.find((rule) => rule.check === "less_than");
1392
+ const integer = schema._def.type === "int" || rules.some((rule) => rule.check === "number_format" && rule.format === "safeint");
1393
+ const minimum = lower ? Number(lower.value) + (lower.inclusive ? 0 : integer ? 1 : 0.1) : 1;
1394
+ const maximum = upper ? Number(upper.value) - (upper.inclusive ? 0 : integer ? 1 : 0.1) : Infinity;
1395
+ const candidate = Math.min(Math.max(21, minimum), maximum);
1396
+ return integer ? Math.ceil(candidate) : candidate;
1397
+ }
1398
+ function createExample(schema, key = "value", depth = 0, seen = /* @__PURE__ */ new Set()) {
1399
+ var _a;
1400
+ if (depth > 8 || seen.has(schema)) throw new Error("This recursive schema needs a handwritten example.");
1401
+ const nextSeen = new Set(seen).add(schema);
1402
+ const def = schema._def;
1403
+ const mongooseType = getMongooseMeta(schema).type;
1404
+ if (mongooseType === "ObjectId" || (mongooseType == null ? void 0 : mongooseType.schemaName) === "ObjectId") return "507f1f77bcf86cd799439011";
1405
+ switch (def.type) {
1406
+ case "optional":
1407
+ case "default":
1408
+ case "prefault":
1409
+ return depth === 0 ? createExample(def.innerType, key, depth + 1, nextSeen) : void 0;
1410
+ case "nullable":
1411
+ case "nonoptional":
1412
+ case "readonly":
1413
+ case "catch":
1414
+ return createExample(def.innerType, key, depth + 1, nextSeen);
1415
+ case "pipe":
1416
+ return createExample(def.in, key, depth + 1, nextSeen);
1417
+ case "lazy":
1418
+ return createExample(def.getter(), key, depth + 1, nextSeen);
1419
+ case "object": {
1420
+ const result = {};
1421
+ for (const [field, fieldSchema] of Object.entries(schema.shape || def.shape || {})) {
1422
+ const value = createExample(fieldSchema, field, depth + 1, nextSeen);
1423
+ if (value !== void 0) result[field] = value;
1424
+ }
1425
+ return result;
1426
+ }
1427
+ case "array": {
1428
+ const minimum = Math.max(0, ...checks(schema).filter((rule) => rule.check === "min_length").map((rule) => rule.minimum));
1429
+ return Array.from({ length: Math.min(Math.max(1, minimum), 10) }, () => createExample(def.element, key, depth + 1, nextSeen));
1430
+ }
1431
+ case "tuple":
1432
+ return def.items.map((item) => createExample(item, key, depth + 1, nextSeen));
1433
+ case "string":
1434
+ return sampleString(schema, key);
1435
+ case "number":
1436
+ case "int":
1437
+ return sampleNumber(schema);
1438
+ case "boolean":
1439
+ return true;
1440
+ case "enum":
1441
+ return Object.values(def.entries)[0];
1442
+ case "literal":
1443
+ return (_a = def.values) == null ? void 0 : _a[0];
1444
+ case "union":
1445
+ return createExample(def.options[0], key, depth + 1, nextSeen);
1446
+ case "record":
1447
+ return { example: createExample(def.valueType, key, depth + 1, nextSeen) };
1448
+ case "date":
1449
+ return "2026-01-01T12:00:00.000Z";
1450
+ default:
1451
+ throw new Error(`Automatic examples do not yet support ${def.type || "this schema"}.`);
1452
+ }
1453
+ }
1454
+
1455
+ var __defProp = Object.defineProperty;
1456
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1457
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
1458
+ setMongoose(mongoose);
1459
+ class StudioExecutionError extends Error {
1460
+ constructor() {
1461
+ super(...arguments);
1462
+ __publicField(this, "statusCode", 400);
1463
+ }
1464
+ }
1465
+ function errorMessage(error) {
1466
+ return error instanceof Error ? error.message || error.name : String(error);
1467
+ }
1468
+ function declaredNames(jsCode) {
1469
+ const file = parse(jsCode, { ecmaVersion: "latest", sourceType: "script" });
1470
+ const names = [];
1471
+ for (const statement of file.body) {
1472
+ if (statement.type !== "VariableDeclaration") continue;
1473
+ for (const declaration of statement.declarations) {
1474
+ if (declaration.id.type === "Identifier") names.push(declaration.id.name);
1475
+ }
1476
+ }
1477
+ return names;
1478
+ }
1479
+ function displayValue(value) {
1480
+ const seen = /* @__PURE__ */ new WeakSet();
1481
+ return JSON.stringify(value, (_key, item) => {
1482
+ if (typeof item === "bigint") return `${item.toString()}n`;
1483
+ if (typeof item === "undefined") return "[undefined]";
1484
+ if (typeof item === "number" && !Number.isFinite(item)) return String(item);
1485
+ if (typeof item === "object" && item !== null) {
1486
+ if (item instanceof Date) return item.toISOString();
1487
+ if (typeof item.toHexString === "function") return item.toHexString();
1488
+ if (seen.has(item)) return "[Circular]";
1489
+ seen.add(item);
1490
+ }
1491
+ return item;
1492
+ }, 2) || "undefined";
1493
+ }
1494
+ function formatMongoose(value) {
1495
+ if (typeof value === "function") return value.name || value.toString();
1496
+ if (Array.isArray(value)) return value.map(formatMongoose);
1497
+ if (value !== null && typeof value === "object" && value.constructor === Object) {
1498
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, formatMongoose(entry)]));
1499
+ }
1500
+ return value;
1501
+ }
1502
+ function executeStudio(body, timeoutMs) {
1503
+ var _a;
1504
+ const sourceCode = body.sourceCode;
1505
+ hooks.removeAllHooks();
1506
+ try {
1507
+ let jsCode;
1508
+ try {
1509
+ jsCode = transformSync(sourceCode, { loader: "ts", format: "cjs", target: "esnext" }).code;
1510
+ } catch (error) {
1511
+ throw new StudioExecutionError(`Compilation error: ${errorMessage(error)}`);
1512
+ }
1513
+ const names = declaredNames(jsCode);
1514
+ const sandboxRequire = (moduleName) => {
1515
+ if (moduleName === "zod" || moduleName === "zod/v4") return zod;
1516
+ if (moduleName === "@nullix/zod-mongoose") return mongooseZod;
1517
+ if (moduleName === "mongoose") return mongoose;
1518
+ throw new Error(`Module "${moduleName}" is unavailable in Studio.`);
1519
+ };
1520
+ const context = vm.createContext({
1521
+ ...mongooseZod,
1522
+ z: zod.z,
1523
+ mongoose,
1524
+ require: sandboxRequire,
1525
+ console: { log: () => {
1526
+ }, warn: () => {
1527
+ }, error: () => {
1528
+ } },
1529
+ __filename: "/sandbox/main.ts",
1530
+ __dirname: "/sandbox"
1531
+ });
1532
+ const captured = names.map((name) => `${JSON.stringify(name)}: typeof ${name} === "undefined" ? undefined : ${name}`).join(",");
1533
+ const script = new vm.Script(`
1534
+ (() => {
1535
+ let exports = {};
1536
+ let module = { exports };
1537
+ ${jsCode}
1538
+ return { exported: module.exports, declared: { ${captured} } };
1539
+ })()
1540
+ `);
1541
+ const result = script.runInContext(context, { timeout: timeoutMs });
1542
+ const choices = /* @__PURE__ */ new Map();
1543
+ for (const [name, value] of Object.entries(result.declared)) {
1544
+ if (value instanceof zod.ZodType && ![...choices.values()].includes(value)) choices.set(name, value);
1545
+ }
1546
+ for (const [name, value] of Object.entries(result.exported || {})) {
1547
+ if (value instanceof zod.ZodType && ![...choices.values()].includes(value)) choices.set(name, value);
1548
+ }
1549
+ const defaultExport = result.exported instanceof zod.ZodType ? result.exported : (_a = result.exported) == null ? void 0 : _a.default;
1550
+ if (defaultExport instanceof zod.ZodType && ![...choices.values()].includes(defaultExport)) choices.set("default", defaultExport);
1551
+ if (!choices.size) throw new Error("Define a Zod schema, such as const UserSchema = z.object({ name: z.string() }).");
1552
+ const selectedSchema = body.selectedSchema && choices.has(body.selectedSchema) ? body.selectedSchema : choices.keys().next().value;
1553
+ const schema = choices.get(selectedSchema);
1554
+ const schemaNames = [...choices.keys()];
1555
+ let example;
1556
+ let exampleError;
1557
+ let inputData = body.inputData;
1558
+ if (body.action === "example") {
1559
+ try {
1560
+ const fixture = result.declared.exampleInput;
1561
+ const generated = fixture !== void 0 ? fixture : createExample(schema);
1562
+ const exampleResult = schema.safeParse(generated);
1563
+ if (!exampleResult.success) throw new Error("The example does not satisfy this schema. Add or update a valid const exampleInput for custom rules.");
1564
+ example = displayValue(generated);
1565
+ inputData = example;
1566
+ } catch (error) {
1567
+ exampleError = errorMessage(error);
1568
+ }
1569
+ }
1570
+ let validation = { status: "empty" };
1571
+ if (typeof inputData !== "string" || !inputData.trim()) {
1572
+ validation = { status: "empty", message: "Add JSON data to try this schema." };
1573
+ } else {
1574
+ let input;
1575
+ let inputValid = false;
1576
+ try {
1577
+ input = JSON.parse(inputData);
1578
+ inputValid = true;
1579
+ } catch (error) {
1580
+ validation = { status: "json-error", message: errorMessage(error) };
1581
+ }
1582
+ if (inputValid) {
1583
+ try {
1584
+ const parsed = schema.safeParse(input);
1585
+ validation = parsed.success ? { status: "valid", parsed: displayValue(parsed.data) } : { status: "invalid", issues: parsed.error.issues.map((issue) => ({ path: issue.path.length ? issue.path.join(".") : "(root)", message: issue.message, code: issue.code })) };
1586
+ } catch (error) {
1587
+ validation = { status: "parse-error", message: `Validation could not run: ${errorMessage(error)}` };
1588
+ }
1589
+ }
1590
+ }
1591
+ let conversion;
1592
+ try {
1593
+ const extracted = extractMongooseDef(schema);
1594
+ const converted = toMongooseSchema(schema, { modelName: "ParsedSchema" });
1595
+ const inspect = (value) => util.inspect(formatMongoose(value), { depth: null, colors: false, showHidden: false });
1596
+ conversion = {
1597
+ definition: inspect(extracted),
1598
+ schemaObj: inspect(converted.obj),
1599
+ schemaTree: inspect(converted.tree),
1600
+ schemaPaths: inspect(converted.paths)
1601
+ };
1602
+ } catch (error) {
1603
+ conversion = { error: errorMessage(error) };
1604
+ }
1605
+ return { schemaNames, selectedSchema, validation, conversion, example, exampleError };
1606
+ } finally {
1607
+ hooks.removeAllHooks();
1608
+ }
1609
+ }
1610
+
19
1611
  const MAX_PENDING_PARSES = 3;
20
1612
  let parseQueue = Promise.resolve();
21
1613
  let pendingParses = 0;