@es-joy/jsoe 0.24.3 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (524) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.ncurc.cjs +2 -2
  3. package/CHANGES.md +51 -0
  4. package/README.md +23 -13
  5. package/badges/coverage-badge.svg +1 -1
  6. package/dist/eslint.config.d.ts +3 -0
  7. package/dist/eslint.config.d.ts.map +1 -0
  8. package/dist/formatAndTypeChoices.d.ts +28 -30
  9. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  10. package/dist/formats/indexedDBKey.d.ts.map +1 -1
  11. package/dist/formats/schema.d.ts +46 -3
  12. package/dist/formats/schema.d.ts.map +1 -1
  13. package/dist/formats/structuredCloning.d.ts +3 -0
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/formats.d.ts +24 -6
  16. package/dist/formats.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  18. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  20. package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/arrayType.d.ts +7 -0
  22. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -1
  24. package/dist/fundamentalTypes/bigintType.d.ts +10 -0
  25. package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
  26. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  27. package/dist/fundamentalTypes/booleanType.d.ts.map +1 -1
  28. package/dist/fundamentalTypes/catchType.d.ts +2 -2
  29. package/dist/fundamentalTypes/catchType.d.ts.map +1 -1
  30. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  31. package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
  32. package/dist/fundamentalTypes/enumType.d.ts +2 -2
  33. package/dist/fundamentalTypes/enumType.d.ts.map +1 -1
  34. package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
  35. package/dist/fundamentalTypes/fileType.d.ts +6 -0
  36. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  37. package/dist/fundamentalTypes/functionType.d.ts.map +1 -1
  38. package/dist/fundamentalTypes/literalType.d.ts +3 -2
  39. package/dist/fundamentalTypes/literalType.d.ts.map +1 -1
  40. package/dist/fundamentalTypes/looseRecordType.d.ts +6 -0
  41. package/dist/fundamentalTypes/looseRecordType.d.ts.map +1 -0
  42. package/dist/fundamentalTypes/nanType.d.ts.map +1 -1
  43. package/dist/fundamentalTypes/neverType.d.ts +2 -2
  44. package/dist/fundamentalTypes/neverType.d.ts.map +1 -1
  45. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
  46. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  47. package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
  48. package/dist/fundamentalTypes/promiseType.d.ts.map +1 -1
  49. package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
  50. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  51. package/dist/fundamentalTypes/symbolType.d.ts.map +1 -1
  52. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  53. package/dist/fundamentalTypes/voidType.d.ts +2 -2
  54. package/dist/fundamentalTypes/voidType.d.ts.map +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +6 -1
  57. package/dist/index.js.map +1 -1
  58. package/dist/rollup.config.d.ts +30 -0
  59. package/dist/rollup.config.d.ts.map +1 -0
  60. package/dist/server.d.ts +2 -0
  61. package/dist/server.d.ts.map +1 -0
  62. package/dist/src/formatAndTypeChoices.d.ts +108 -0
  63. package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
  64. package/dist/src/formats/arbitraryJS.d.ts +4 -0
  65. package/dist/src/formats/arbitraryJS.d.ts.map +1 -0
  66. package/dist/src/formats/indexedDBKey.d.ts +4 -0
  67. package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
  68. package/dist/src/formats/json.d.ts +4 -0
  69. package/dist/src/formats/json.d.ts.map +1 -0
  70. package/dist/src/formats/schema.d.ts +17 -0
  71. package/dist/src/formats/schema.d.ts.map +1 -0
  72. package/dist/src/formats/structuredCloning.d.ts +19 -0
  73. package/dist/src/formats/structuredCloning.d.ts.map +1 -0
  74. package/dist/src/formats.d.ts +135 -0
  75. package/dist/src/formats.d.ts.map +1 -0
  76. package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +8 -0
  77. package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
  78. package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
  79. package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
  80. package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
  81. package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
  82. package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +8 -0
  83. package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
  84. package/dist/src/fundamentalTypes/arrayType.d.ts +29 -0
  85. package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
  86. package/dist/src/fundamentalTypes/bigintObjectType.d.ts +6 -0
  87. package/dist/src/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
  88. package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
  89. package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
  90. package/dist/src/fundamentalTypes/blobType.d.ts +11 -0
  91. package/dist/src/fundamentalTypes/blobType.d.ts.map +1 -0
  92. package/dist/src/fundamentalTypes/booleanType.d.ts +8 -0
  93. package/dist/src/fundamentalTypes/booleanType.d.ts.map +1 -0
  94. package/dist/src/fundamentalTypes/catchType.d.ts +6 -0
  95. package/dist/src/fundamentalTypes/catchType.d.ts.map +1 -0
  96. package/dist/src/fundamentalTypes/dateType.d.ts +26 -0
  97. package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
  98. package/dist/src/fundamentalTypes/domexceptionType.d.ts +6 -0
  99. package/dist/src/fundamentalTypes/domexceptionType.d.ts.map +1 -0
  100. package/dist/src/fundamentalTypes/enumType.d.ts +6 -0
  101. package/dist/src/fundamentalTypes/enumType.d.ts.map +1 -0
  102. package/dist/src/fundamentalTypes/errorType.d.ts +6 -0
  103. package/dist/src/fundamentalTypes/errorType.d.ts.map +1 -0
  104. package/dist/src/fundamentalTypes/fileType.d.ts +13 -0
  105. package/dist/src/fundamentalTypes/fileType.d.ts.map +1 -0
  106. package/dist/src/fundamentalTypes/filelistType.d.ts +6 -0
  107. package/dist/src/fundamentalTypes/filelistType.d.ts.map +1 -0
  108. package/dist/src/fundamentalTypes/functionType.d.ts +7 -0
  109. package/dist/src/fundamentalTypes/functionType.d.ts.map +1 -0
  110. package/dist/src/fundamentalTypes/literalType.d.ts +6 -0
  111. package/dist/src/fundamentalTypes/literalType.d.ts.map +1 -0
  112. package/dist/src/fundamentalTypes/mapType.d.ts +6 -0
  113. package/dist/src/fundamentalTypes/mapType.d.ts.map +1 -0
  114. package/dist/src/fundamentalTypes/nanType.d.ts +6 -0
  115. package/dist/src/fundamentalTypes/nanType.d.ts.map +1 -0
  116. package/dist/src/fundamentalTypes/neverType.d.ts +6 -0
  117. package/dist/src/fundamentalTypes/neverType.d.ts.map +1 -0
  118. package/dist/src/fundamentalTypes/noneditableType.d.ts +6 -0
  119. package/dist/src/fundamentalTypes/noneditableType.d.ts.map +1 -0
  120. package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
  121. package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
  122. package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
  123. package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
  124. package/dist/src/fundamentalTypes/objectReferenceType.d.ts +8 -0
  125. package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
  126. package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
  127. package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
  128. package/dist/src/fundamentalTypes/promiseType.d.ts +6 -0
  129. package/dist/src/fundamentalTypes/promiseType.d.ts.map +1 -0
  130. package/dist/src/fundamentalTypes/recordType.d.ts +6 -0
  131. package/dist/src/fundamentalTypes/recordType.d.ts.map +1 -0
  132. package/dist/src/fundamentalTypes/regexpType.d.ts +8 -0
  133. package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
  134. package/dist/src/fundamentalTypes/setType.d.ts +6 -0
  135. package/dist/src/fundamentalTypes/setType.d.ts.map +1 -0
  136. package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
  137. package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
  138. package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
  139. package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
  140. package/dist/src/fundamentalTypes/symbolType.d.ts +8 -0
  141. package/dist/src/fundamentalTypes/symbolType.d.ts.map +1 -0
  142. package/dist/src/fundamentalTypes/tupleType.d.ts +6 -0
  143. package/dist/src/fundamentalTypes/tupleType.d.ts.map +1 -0
  144. package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
  145. package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
  146. package/dist/src/fundamentalTypes/voidType.d.ts +6 -0
  147. package/dist/src/fundamentalTypes/voidType.d.ts.map +1 -0
  148. package/dist/src/index.d.ts +12 -0
  149. package/dist/src/index.d.ts.map +1 -0
  150. package/dist/src/subTypes/blobHTMLType.d.ts +20 -0
  151. package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
  152. package/dist/src/subTypes/falseType.d.ts +8 -0
  153. package/dist/src/subTypes/falseType.d.ts.map +1 -0
  154. package/dist/src/subTypes/trueType.d.ts +8 -0
  155. package/dist/src/subTypes/trueType.d.ts.map +1 -0
  156. package/dist/src/superTypes/SpecialNumberType.d.ts +6 -0
  157. package/dist/src/superTypes/SpecialNumberType.d.ts.map +1 -0
  158. package/dist/src/superTypes/SpecialRealNumberType.d.ts +6 -0
  159. package/dist/src/superTypes/SpecialRealNumberType.d.ts.map +1 -0
  160. package/dist/src/superTypes/buffersourceType.d.ts +8 -0
  161. package/dist/src/superTypes/buffersourceType.d.ts.map +1 -0
  162. package/dist/src/superTypes/dommatrixType.d.ts +6 -0
  163. package/dist/src/superTypes/dommatrixType.d.ts.map +1 -0
  164. package/dist/src/superTypes/dompointType.d.ts +6 -0
  165. package/dist/src/superTypes/dompointType.d.ts.map +1 -0
  166. package/dist/src/superTypes/domrectType.d.ts +6 -0
  167. package/dist/src/superTypes/domrectType.d.ts.map +1 -0
  168. package/dist/src/superTypes/errorsSpecialType.d.ts +8 -0
  169. package/dist/src/superTypes/errorsSpecialType.d.ts.map +1 -0
  170. package/dist/src/typeChoices.d.ts +140 -0
  171. package/dist/src/typeChoices.d.ts.map +1 -0
  172. package/dist/src/types.d.ts +758 -0
  173. package/dist/src/types.d.ts.map +1 -0
  174. package/dist/src/utils/FileList.d.ts +26 -0
  175. package/dist/src/utils/FileList.d.ts.map +1 -0
  176. package/dist/src/utils/dialogs.d.ts +111 -0
  177. package/dist/src/utils/dialogs.d.ts.map +1 -0
  178. package/dist/src/utils/jsonPointer.d.ts +46 -0
  179. package/dist/src/utils/jsonPointer.d.ts.map +1 -0
  180. package/dist/src/utils/media.d.ts +18 -0
  181. package/dist/src/utils/media.d.ts.map +1 -0
  182. package/dist/src/utils/objects.d.ts +16 -0
  183. package/dist/src/utils/objects.d.ts.map +1 -0
  184. package/dist/src/utils/templateUtils.d.ts +59 -0
  185. package/dist/src/utils/templateUtils.d.ts.map +1 -0
  186. package/dist/src/utils/types.d.ts +2 -0
  187. package/dist/src/utils/types.d.ts.map +1 -0
  188. package/dist/src/vendor-imports.d.ts +4 -0
  189. package/dist/src/vendor-imports.d.ts.map +1 -0
  190. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  191. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  192. package/dist/superTypes/buffersourceType.d.ts.map +1 -1
  193. package/dist/superTypes/dommatrixType.d.ts.map +1 -1
  194. package/dist/superTypes/dompointType.d.ts.map +1 -1
  195. package/dist/superTypes/domrectType.d.ts.map +1 -1
  196. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  197. package/dist/typeChoices.d.ts +21 -87
  198. package/dist/typeChoices.d.ts.map +1 -1
  199. package/dist/types.d.ts +90 -64
  200. package/dist/types.d.ts.map +1 -1
  201. package/dist/utils/FileList.d.ts +4 -3
  202. package/dist/utils/FileList.d.ts.map +1 -1
  203. package/dist/utils/dialogs.d.ts +4 -4
  204. package/dist/utils/dialogs.d.ts.map +1 -1
  205. package/dist/utils/media.d.ts.map +1 -1
  206. package/dist/utils/schemaMeta.d.ts +92 -0
  207. package/dist/utils/schemaMeta.d.ts.map +1 -0
  208. package/dist/utils/templateUtils.d.ts +3 -3
  209. package/dist/utils/templateUtils.d.ts.map +1 -1
  210. package/dist/utils/timing.d.ts +2 -0
  211. package/dist/utils/timing.d.ts.map +1 -0
  212. package/dist/utils/types.d.ts +1 -0
  213. package/dist/utils/types.d.ts.map +1 -1
  214. package/dist/vendor-imports.d.ts +3 -1
  215. package/docs/proposals/schema-meta.md +233 -0
  216. package/eslint.config.js +51 -4
  217. package/licenseInfo.json +1 -1
  218. package/package.json +52 -42
  219. package/pnpm-workspace.yaml +57 -0
  220. package/rollup.config.js +20 -18
  221. package/server.js +3 -3
  222. package/src/deepEqual.js.map +1 -1
  223. package/src/formatAndTypeChoices.js +62 -58
  224. package/src/formats/indexedDBKey.js +3 -4
  225. package/src/formats/schema.js +824 -475
  226. package/src/formats/structuredCloning.js +189 -79
  227. package/src/formats.js +17 -5
  228. package/src/fundamentalTypes/BooleanObjectType.js +4 -5
  229. package/src/fundamentalTypes/NumberObjectType.js +4 -4
  230. package/src/fundamentalTypes/StringObjectType.js +3 -4
  231. package/src/fundamentalTypes/arrayReferenceType.js +0 -2
  232. package/src/fundamentalTypes/arrayType.js +624 -389
  233. package/src/fundamentalTypes/bigintObjectType.js +3 -2
  234. package/src/fundamentalTypes/bigintType.js +79 -17
  235. package/src/fundamentalTypes/blobType.js +35 -35
  236. package/src/fundamentalTypes/booleanType.js +16 -8
  237. package/src/fundamentalTypes/dateType.js +6 -8
  238. package/src/fundamentalTypes/domexceptionType.js +5 -4
  239. package/src/fundamentalTypes/errorType.js +39 -32
  240. package/src/fundamentalTypes/fileType.js +238 -52
  241. package/src/fundamentalTypes/functionType.js +61 -41
  242. package/src/fundamentalTypes/nanType.js +5 -4
  243. package/src/fundamentalTypes/noneditableType.js +4 -3
  244. package/src/fundamentalTypes/nullType.js +3 -2
  245. package/src/fundamentalTypes/numberType.js +72 -20
  246. package/src/fundamentalTypes/promiseType.js +16 -40
  247. package/src/fundamentalTypes/regexpType.js +7 -13
  248. package/src/fundamentalTypes/stringType.js +176 -110
  249. package/src/fundamentalTypes/symbolType.js +3 -2
  250. package/src/fundamentalTypes/undefinedType.js +3 -2
  251. package/src/index.js +6 -5
  252. package/src/jsoe.css +107 -8
  253. package/src/subTypes/blobHTMLType.js +23 -10
  254. package/src/superTypes/SpecialNumberType.js +6 -6
  255. package/src/superTypes/SpecialRealNumberType.js +10 -9
  256. package/src/superTypes/buffersourceType.js +86 -75
  257. package/src/superTypes/dommatrixType.js +6 -5
  258. package/src/superTypes/dompointType.js +6 -5
  259. package/src/superTypes/domrectType.js +6 -5
  260. package/src/superTypes/errorsSpecialType.js +54 -35
  261. package/src/typeChoices.js +399 -54
  262. package/src/types.js +157 -97
  263. package/src/utils/FileList.js +3 -3
  264. package/src/utils/dialogs.js +5 -7
  265. package/src/utils/jsonPointer.js +1 -1
  266. package/src/utils/media.js +1 -0
  267. package/src/utils/schemaMeta.js +257 -0
  268. package/src/utils/templateUtils.js +3 -3
  269. package/src/utils/timing.js +12 -0
  270. package/src/utils/types.js +19 -0
  271. package/src/vendor-imports.js +10 -2
  272. package/tsconfig.json +2 -0
  273. package/vendor/acorn/dist/acorn.d.mts +46 -5
  274. package/vendor/acorn/dist/acorn.d.ts +46 -5
  275. package/vendor/acorn/dist/acorn.js +394 -117
  276. package/vendor/acorn/dist/acorn.mjs +394 -117
  277. package/vendor/acorn/dist/bin.js +1 -1
  278. package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +590 -312
  279. package/vendor/jamilih/package.json +1 -1
  280. package/vendor/mime/dist/types/other.js +719 -0
  281. package/vendor/mime/dist/types/standard.js +366 -0
  282. package/vendor/typeson-registry/dist/index.js +519 -99
  283. package/vendor/zod/classic/checks.d.ts +1 -0
  284. package/vendor/zod/classic/checks.js +1 -0
  285. package/vendor/zod/classic/coerce.d.ts +17 -0
  286. package/vendor/zod/classic/coerce.js +17 -0
  287. package/vendor/zod/classic/compat.d.ts +48 -0
  288. package/vendor/zod/classic/compat.js +31 -0
  289. package/vendor/zod/classic/deep-partial.d.ts +14 -0
  290. package/vendor/zod/classic/deep-partial.js +13 -0
  291. package/vendor/zod/classic/errors.d.ts +29 -0
  292. package/vendor/zod/classic/errors.js +57 -0
  293. package/vendor/zod/classic/external.d.ts +19 -0
  294. package/vendor/zod/classic/external.js +17 -0
  295. package/vendor/zod/classic/from-json-schema.d.ts +12 -0
  296. package/vendor/zod/classic/from-json-schema.js +660 -0
  297. package/vendor/zod/classic/in-out.d.ts +8 -0
  298. package/vendor/zod/classic/in-out.js +36 -0
  299. package/vendor/zod/classic/index.d.ts +3 -0
  300. package/vendor/zod/classic/index.js +4 -0
  301. package/vendor/zod/classic/iso.d.ts +7 -0
  302. package/vendor/zod/classic/iso.js +15 -0
  303. package/vendor/zod/classic/package.json +7 -0
  304. package/vendor/zod/classic/parse.d.ts +44 -0
  305. package/vendor/zod/classic/parse.js +16 -0
  306. package/vendor/zod/classic/schemas.d.ts +802 -0
  307. package/vendor/zod/classic/schemas.js +1491 -0
  308. package/vendor/zod/core/api.d.ts +329 -0
  309. package/vendor/zod/core/api.js +1104 -0
  310. package/vendor/zod/core/checks.d.ts +278 -0
  311. package/vendor/zod/core/checks.js +581 -0
  312. package/vendor/zod/core/compile.d.ts +51 -0
  313. package/vendor/zod/core/compile.js +1783 -0
  314. package/vendor/zod/core/core.d.ts +82 -0
  315. package/vendor/zod/core/core.js +141 -0
  316. package/vendor/zod/core/doc.d.ts +16 -0
  317. package/vendor/zod/core/doc.js +33 -0
  318. package/vendor/zod/core/errors.d.ts +225 -0
  319. package/vendor/zod/core/errors.js +270 -0
  320. package/vendor/zod/core/index.d.ts +19 -0
  321. package/vendor/zod/core/index.js +19 -0
  322. package/vendor/zod/core/json-schema-generator.d.ts +65 -0
  323. package/vendor/zod/core/json-schema-generator.js +99 -0
  324. package/vendor/zod/core/json-schema-processors.d.ts +49 -0
  325. package/vendor/zod/core/json-schema-processors.js +747 -0
  326. package/vendor/zod/core/json-schema.d.ts +89 -0
  327. package/vendor/zod/core/memoizer.d.ts +15 -0
  328. package/vendor/zod/core/memoizer.js +265 -0
  329. package/vendor/zod/core/package.json +7 -0
  330. package/vendor/zod/core/parse.d.ts +52 -0
  331. package/vendor/zod/core/parse.js +154 -0
  332. package/vendor/zod/core/regexes.d.ts +87 -0
  333. package/vendor/zod/core/regexes.js +150 -0
  334. package/vendor/zod/core/registries.d.ts +35 -0
  335. package/vendor/zod/core/registries.js +51 -0
  336. package/vendor/zod/core/schemas.d.ts +1253 -0
  337. package/vendor/zod/core/schemas.js +2440 -0
  338. package/vendor/zod/core/standard-schema.d.ts +126 -0
  339. package/vendor/zod/core/to-json-schema.d.ts +153 -0
  340. package/vendor/zod/core/to-json-schema.js +650 -0
  341. package/vendor/zod/core/util.d.ts +257 -0
  342. package/vendor/zod/core/util.js +846 -0
  343. package/vendor/zod/core/versions.d.ts +5 -0
  344. package/vendor/zod/core/versions.js +5 -0
  345. package/vendor/zod/core/visit.d.ts +30 -0
  346. package/vendor/zod/core/visit.js +169 -0
  347. package/vendor/zod/index.d.ts +3 -0
  348. package/vendor/zod/index.js +4 -0
  349. package/vendor/zod/locales/ar.d.ts +4 -0
  350. package/vendor/zod/locales/ar.js +109 -0
  351. package/vendor/zod/locales/az.d.ts +4 -0
  352. package/vendor/zod/locales/az.js +108 -0
  353. package/vendor/zod/locales/be.d.ts +4 -0
  354. package/vendor/zod/locales/be.js +166 -0
  355. package/vendor/zod/locales/bg.d.ts +4 -0
  356. package/vendor/zod/locales/bg.js +123 -0
  357. package/vendor/zod/locales/bn.d.ts +4 -0
  358. package/vendor/zod/locales/bn.js +111 -0
  359. package/vendor/zod/locales/ca.d.ts +4 -0
  360. package/vendor/zod/locales/ca.js +110 -0
  361. package/vendor/zod/locales/ckb.d.ts +4 -0
  362. package/vendor/zod/locales/ckb.js +131 -0
  363. package/vendor/zod/locales/cs.d.ts +4 -0
  364. package/vendor/zod/locales/cs.js +114 -0
  365. package/vendor/zod/locales/da.d.ts +4 -0
  366. package/vendor/zod/locales/da.js +118 -0
  367. package/vendor/zod/locales/de.d.ts +4 -0
  368. package/vendor/zod/locales/de.js +111 -0
  369. package/vendor/zod/locales/el.d.ts +4 -0
  370. package/vendor/zod/locales/el.js +110 -0
  371. package/vendor/zod/locales/en.d.ts +4 -0
  372. package/vendor/zod/locales/en.js +123 -0
  373. package/vendor/zod/locales/eo.d.ts +4 -0
  374. package/vendor/zod/locales/eo.js +112 -0
  375. package/vendor/zod/locales/es.d.ts +4 -0
  376. package/vendor/zod/locales/es.js +134 -0
  377. package/vendor/zod/locales/fa.d.ts +4 -0
  378. package/vendor/zod/locales/fa.js +117 -0
  379. package/vendor/zod/locales/fi.d.ts +4 -0
  380. package/vendor/zod/locales/fi.js +115 -0
  381. package/vendor/zod/locales/fr-CA.d.ts +4 -0
  382. package/vendor/zod/locales/fr-CA.js +110 -0
  383. package/vendor/zod/locales/fr.d.ts +4 -0
  384. package/vendor/zod/locales/fr.js +127 -0
  385. package/vendor/zod/locales/gu.d.ts +4 -0
  386. package/vendor/zod/locales/gu.js +111 -0
  387. package/vendor/zod/locales/he.d.ts +4 -0
  388. package/vendor/zod/locales/he.js +219 -0
  389. package/vendor/zod/locales/hi.d.ts +4 -0
  390. package/vendor/zod/locales/hi.js +109 -0
  391. package/vendor/zod/locales/hr.d.ts +4 -0
  392. package/vendor/zod/locales/hr.js +124 -0
  393. package/vendor/zod/locales/hu.d.ts +4 -0
  394. package/vendor/zod/locales/hu.js +111 -0
  395. package/vendor/zod/locales/hy.d.ts +4 -0
  396. package/vendor/zod/locales/hy.js +156 -0
  397. package/vendor/zod/locales/id.d.ts +4 -0
  398. package/vendor/zod/locales/id.js +109 -0
  399. package/vendor/zod/locales/index.d.ts +62 -0
  400. package/vendor/zod/locales/index.js +62 -0
  401. package/vendor/zod/locales/is.d.ts +4 -0
  402. package/vendor/zod/locales/is.js +112 -0
  403. package/vendor/zod/locales/it.d.ts +4 -0
  404. package/vendor/zod/locales/it.js +111 -0
  405. package/vendor/zod/locales/ja.d.ts +4 -0
  406. package/vendor/zod/locales/ja.js +110 -0
  407. package/vendor/zod/locales/ka.d.ts +4 -0
  408. package/vendor/zod/locales/ka.js +115 -0
  409. package/vendor/zod/locales/kh.d.ts +5 -0
  410. package/vendor/zod/locales/kh.js +5 -0
  411. package/vendor/zod/locales/km.d.ts +4 -0
  412. package/vendor/zod/locales/km.js +113 -0
  413. package/vendor/zod/locales/kn.d.ts +4 -0
  414. package/vendor/zod/locales/kn.js +114 -0
  415. package/vendor/zod/locales/ko.d.ts +4 -0
  416. package/vendor/zod/locales/ko.js +114 -0
  417. package/vendor/zod/locales/lt.d.ts +4 -0
  418. package/vendor/zod/locales/lt.js +205 -0
  419. package/vendor/zod/locales/mk.d.ts +4 -0
  420. package/vendor/zod/locales/mk.js +112 -0
  421. package/vendor/zod/locales/ms.d.ts +4 -0
  422. package/vendor/zod/locales/ms.js +110 -0
  423. package/vendor/zod/locales/ne.d.ts +4 -0
  424. package/vendor/zod/locales/ne.js +109 -0
  425. package/vendor/zod/locales/nl.d.ts +4 -0
  426. package/vendor/zod/locales/nl.js +113 -0
  427. package/vendor/zod/locales/nn.d.ts +4 -0
  428. package/vendor/zod/locales/nn.js +111 -0
  429. package/vendor/zod/locales/no.d.ts +4 -0
  430. package/vendor/zod/locales/no.js +111 -0
  431. package/vendor/zod/locales/ota.d.ts +4 -0
  432. package/vendor/zod/locales/ota.js +112 -0
  433. package/vendor/zod/locales/package.json +7 -0
  434. package/vendor/zod/locales/pl.d.ts +4 -0
  435. package/vendor/zod/locales/pl.js +112 -0
  436. package/vendor/zod/locales/ps.d.ts +4 -0
  437. package/vendor/zod/locales/ps.js +117 -0
  438. package/vendor/zod/locales/pt-BR.d.ts +4 -0
  439. package/vendor/zod/locales/pt-BR.js +141 -0
  440. package/vendor/zod/locales/pt.d.ts +4 -0
  441. package/vendor/zod/locales/pt.js +140 -0
  442. package/vendor/zod/locales/ro.d.ts +4 -0
  443. package/vendor/zod/locales/ro.js +120 -0
  444. package/vendor/zod/locales/ru.d.ts +4 -0
  445. package/vendor/zod/locales/ru.js +166 -0
  446. package/vendor/zod/locales/sk.d.ts +4 -0
  447. package/vendor/zod/locales/sk.js +114 -0
  448. package/vendor/zod/locales/sl.d.ts +4 -0
  449. package/vendor/zod/locales/sl.js +112 -0
  450. package/vendor/zod/locales/sv.d.ts +4 -0
  451. package/vendor/zod/locales/sv.js +113 -0
  452. package/vendor/zod/locales/ta.d.ts +4 -0
  453. package/vendor/zod/locales/ta.js +113 -0
  454. package/vendor/zod/locales/th.d.ts +4 -0
  455. package/vendor/zod/locales/th.js +113 -0
  456. package/vendor/zod/locales/tk.d.ts +4 -0
  457. package/vendor/zod/locales/tk.js +105 -0
  458. package/vendor/zod/locales/tr.d.ts +4 -0
  459. package/vendor/zod/locales/tr.js +108 -0
  460. package/vendor/zod/locales/ua.d.ts +5 -0
  461. package/vendor/zod/locales/ua.js +5 -0
  462. package/vendor/zod/locales/uk.d.ts +4 -0
  463. package/vendor/zod/locales/uk.js +111 -0
  464. package/vendor/zod/locales/ur.d.ts +4 -0
  465. package/vendor/zod/locales/ur.js +113 -0
  466. package/vendor/zod/locales/uz.d.ts +4 -0
  467. package/vendor/zod/locales/uz.js +111 -0
  468. package/vendor/zod/locales/vi.d.ts +4 -0
  469. package/vendor/zod/locales/vi.js +111 -0
  470. package/vendor/zod/locales/yo.d.ts +4 -0
  471. package/vendor/zod/locales/yo.js +110 -0
  472. package/vendor/zod/locales/zh-CN.d.ts +4 -0
  473. package/vendor/zod/locales/zh-CN.js +112 -0
  474. package/vendor/zod/locales/zh-TW.d.ts +4 -0
  475. package/vendor/zod/locales/zh-TW.js +110 -0
  476. package/vendor/zod/mini/checks.d.ts +1 -0
  477. package/vendor/zod/mini/checks.js +1 -0
  478. package/vendor/zod/mini/coerce.d.ts +7 -0
  479. package/vendor/zod/mini/coerce.js +22 -0
  480. package/vendor/zod/mini/deep-partial.d.ts +14 -0
  481. package/vendor/zod/mini/deep-partial.js +13 -0
  482. package/vendor/zod/mini/external.d.ts +16 -0
  483. package/vendor/zod/mini/external.js +16 -0
  484. package/vendor/zod/mini/in-out.d.ts +8 -0
  485. package/vendor/zod/mini/in-out.js +36 -0
  486. package/vendor/zod/mini/index.d.ts +3 -0
  487. package/vendor/zod/mini/index.js +3 -0
  488. package/vendor/zod/mini/iso.d.ts +22 -0
  489. package/vendor/zod/mini/iso.js +34 -0
  490. package/vendor/zod/mini/package.json +7 -0
  491. package/vendor/zod/mini/parse.d.ts +1 -0
  492. package/vendor/zod/mini/parse.js +1 -0
  493. package/vendor/zod/mini/schemas.d.ts +475 -0
  494. package/vendor/zod/mini/schemas.js +987 -0
  495. package/vendor/zod/package.json +7 -0
  496. package/vendor/zodexy/dist/esm/index.js +1274 -0
  497. package/vendor/zodexy/dist/index.js +1088 -0
  498. package/vendor/zodexy/dist/schema.zodexy.json +1036 -0
  499. package/dist/fundamentalTypes/nativeEnumType.d.ts +0 -6
  500. package/dist/fundamentalTypes/nativeEnumType.d.ts.map +0 -1
  501. package/src/fundamentalTypes/catchType.js +0 -140
  502. package/src/fundamentalTypes/enumType.js +0 -52
  503. package/src/fundamentalTypes/literalType.js +0 -81
  504. package/src/fundamentalTypes/nativeEnumType.js +0 -157
  505. package/src/fundamentalTypes/neverType.js +0 -49
  506. package/src/fundamentalTypes/recordType.js +0 -42
  507. package/src/fundamentalTypes/tupleType.js +0 -39
  508. package/src/fundamentalTypes/voidType.js +0 -48
  509. package/vendor/zod/lib/index.mjs +0 -4236
  510. package/vendor/zodex/dist/esm/dezerialize.d.ts +0 -26
  511. package/vendor/zodex/dist/esm/dezerialize.js +0 -393
  512. package/vendor/zodex/dist/esm/index.d.ts +0 -9
  513. package/vendor/zodex/dist/esm/index.js +0 -4
  514. package/vendor/zodex/dist/esm/infer.d.ts +0 -29
  515. package/vendor/zodex/dist/esm/package.json +0 -1
  516. package/vendor/zodex/dist/esm/types.d.ts +0 -201
  517. package/vendor/zodex/dist/esm/types.js +0 -13
  518. package/vendor/zodex/dist/esm/ui.d.ts +0 -23
  519. package/vendor/zodex/dist/esm/ui.js +0 -10
  520. package/vendor/zodex/dist/esm/zerialize.d.ts +0 -50
  521. package/vendor/zodex/dist/esm/zerialize.js +0 -417
  522. package/vendor/zodex/dist/esm/zod-types.d.ts +0 -11
  523. /package/vendor/{zodex/dist/esm/infer.js → zod/core/json-schema.js} +0 -0
  524. /package/vendor/{zodex/dist/esm/zod-types.js → zod/core/standard-schema.js} +0 -0
@@ -1,23 +1,24 @@
1
1
  // import {z} from 'zod';
2
- import {dezerialize} from 'zodex';
2
+ import {dezerialize} from 'zodexy';
3
+ import deepEqual from 'fast-deep-equal/es6/index.js';
3
4
 
4
5
  import structuredCloning from './structuredCloning.js';
5
6
 
6
7
  import {resolveJSONPointer} from '../utils/jsonPointer.js';
7
8
  import {copyObject} from '../utils/objects.js';
9
+ import {isUnionLike} from '../utils/types.js';
10
+ import FileList from '../utils/FileList.js';
8
11
 
9
- /* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
10
12
  /**
11
13
  * @typedef {T[keyof T]} ValueOf<T>
12
14
  * @template T
13
15
  */
14
- /* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
15
16
 
16
17
  /**
17
18
  * @typedef {ValueOf<
18
- * Pick<import('zodex').SzType, "type">
19
- * >} AvailableZodexType
20
- */
19
+ * Pick<import('zodexy').SzType, "type">
20
+ * >} AvailableZodexType
21
+ */
21
22
 
22
23
  /**
23
24
  * @type {Map<
@@ -33,40 +34,338 @@ const zodexToStructuredCloningTypeMap = new Map([
33
34
  ['bigInt', 'bigint'],
34
35
  ['string', 'string'],
35
36
  ['date', 'date'],
37
+ ['file', 'file'],
36
38
  ['undefined', 'undef'],
37
- ['void', 'void'],
39
+ ['void', 'undef'],
38
40
  ['null', 'null'],
39
41
 
40
42
  // ['array', 'array'],
41
43
  ['array', 'arrayNonindexKeys'],
42
44
 
43
45
  ['object', 'object'],
44
- ['enum', 'enum'],
45
- ['literal', 'literal'],
46
46
 
47
- ['tuple', 'tuple'],
48
- ['record', 'record'],
47
+ ['tuple', 'array'],
48
+ ['record', 'object'],
49
+ ['looseRecord', 'object'],
49
50
  ['map', 'map'],
50
51
  ['set', 'set'],
51
52
 
52
- ['never', 'never'],
53
-
54
53
  // Todo: Filter out for cloning-only
55
- ['symbol', 'symbol'],
56
54
  ['promise', 'promise'],
57
- ['function', 'function'],
58
-
59
- ['catch', 'catch'],
60
- ['nativeEnum', 'nativeEnum']
55
+ ['function', 'function']
61
56
  ]);
62
57
 
63
58
  /**
64
- * @typedef {import('zodex').SzType} ZodexSchema
59
+ * @param {unknown} value
60
+ * @returns {import('../types.js').AvailableArbitraryType|undefined}
61
+ */
62
+ function getValueType (value) {
63
+ if (value === null) {
64
+ return 'null';
65
+ }
66
+ switch (typeof value) {
67
+ case 'undefined':
68
+ return 'undef';
69
+ case 'bigint':
70
+ return 'bigint';
71
+ case 'boolean':
72
+ return 'boolean';
73
+ case 'number':
74
+ return 'number';
75
+ case 'string':
76
+ return 'string';
77
+ default:
78
+ return undefined;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @param {import('zodexy').SzLiteral<any>|import('zodexy').SzEnum<any>} schema
84
+ * @returns {Set<ZodexSchema>}
85
+ */
86
+ function splitConstrainedSchema (schema) {
87
+ const values = /** @type {unknown[]} */ (schema.type === 'literal'
88
+ ? schema.values
89
+ : Object.values(schema.values));
90
+ const valueTypes = new Set(values.map((value) => getValueType(value)));
91
+ return new Set([...valueTypes].flatMap((type) => {
92
+ if (!type) {
93
+ return [];
94
+ }
95
+ const typeValues = values.filter((value) => {
96
+ return getValueType(value) === type;
97
+ });
98
+ const {defaultValue} = schema;
99
+ return [{
100
+ ...schema,
101
+ values: schema.type === 'literal'
102
+ ? typeValues
103
+ : Object.fromEntries(Object.entries(schema.values).filter(([, value]) => {
104
+ return getValueType(value) === type;
105
+ })),
106
+ defaultValue: typeValues.includes(defaultValue)
107
+ ? defaultValue
108
+ : typeValues[0]
109
+ }];
110
+ }));
111
+ }
112
+
113
+ /**
114
+ * @param {ZodexSchema} schemaObject
115
+ * @returns {import('../types.js').AvailableType|undefined}
116
+ */
117
+ function getCheckedType (schemaObject) {
118
+ return /** @type {import('../types.js').AvailableType|undefined} */ (
119
+ schemaObject.checks?.[0]?.name
120
+ );
121
+ }
122
+
123
+ /**
124
+ * `z.stringbool()` serializes as a `pipe` (a string -> boolean codec) whose
125
+ * `inner` is a plain string, `outer` is a boolean, and which carries the
126
+ * `truthy`/`falsy`/`case` options on the pipe itself. jsoe edits the encoded
127
+ * (string) side, so this is treated as a refinement of the String type -
128
+ * a `kind` of string - rather than its own type or a boolean.
129
+ * @param {ZodexSchema} schemaObject
130
+ * @returns {boolean}
131
+ */
132
+ function isStringboolSchema (schemaObject) {
133
+ return schemaObject.type === 'pipe' &&
134
+ schemaObject.inner?.type === 'string' &&
135
+ schemaObject.outer?.type === 'boolean' &&
136
+ 'case' in schemaObject &&
137
+ 'falsy' in schemaObject &&
138
+ 'truthy' in schemaObject;
139
+ }
140
+
141
+ /**
142
+ * @param {ZodexSchema} schemaObject
143
+ * @returns {import('../types.js').AvailableArbitraryType|undefined}
144
+ */
145
+ function getSchemaType (schemaObject) {
146
+ if (isStringboolSchema(schemaObject)) {
147
+ return 'string';
148
+ }
149
+ if (schemaObject.type === 'codec' && schemaObject.name === 'filelist') {
150
+ return 'filelist';
151
+ }
152
+ if (schemaObject.type === 'instanceof') {
153
+ return /** @type {import('../types.js').AvailableArbitraryType} */ (
154
+ schemaObject.name
155
+ );
156
+ }
157
+ if (schemaObject.type === 'literal') {
158
+ return getValueType(schemaObject.values[0]);
159
+ }
160
+ if (schemaObject.type === 'enum') {
161
+ return getValueType(Object.values(schemaObject.values)[0]);
162
+ }
163
+ if (schemaObject.type === 'templateLiteral') {
164
+ return 'string';
165
+ }
166
+ return (
167
+ getCheckedType(schemaObject) ??
168
+ zodexToStructuredCloningTypeMap.get(schemaObject.type)
169
+ );
170
+ }
171
+
172
+ const dezerializerInstances = {filelist: FileList};
173
+ const dezerializerCodecs = {
174
+ filelist: {
175
+ /**
176
+ * @param {FileList} value
177
+ * @returns {File[]}
178
+ */
179
+ decode (value) {
180
+ return Array.from({length: value.length}, (_, idx) => value.item(idx));
181
+ },
182
+ /**
183
+ * @param {File[]} value
184
+ * @returns {FileList}
185
+ */
186
+ encode (value) {
187
+ return new FileList(value);
188
+ }
189
+ }
190
+ };
191
+
192
+ /**
193
+ * @param {InstanceType<typeof import('../types.js').default>} types
194
+ * @param {ZodexSchema} schemaObject
195
+ * @param {ZodexSchema} originalShape
196
+ * @param {unknown} value
197
+ * @returns {ReturnType<ReturnType<typeof dezerialize>['safeParse']>}
198
+ */
199
+ function parseValue (types, schemaObject, originalShape, value) {
200
+ return dezerialize(schemaObject, {
201
+ checks: getChecks(types),
202
+ codecs: dezerializerCodecs,
203
+ instances: dezerializerInstances,
204
+ originalShape
205
+ }).safeParse(value);
206
+ }
207
+
208
+ /**
209
+ * @param {InstanceType<typeof import('../types.js').default>} types
210
+ * @param {ZodexSchema} schemaObject
211
+ * @param {ZodexSchema} originalShape
212
+ * @param {unknown} value
213
+ * @returns {ZodexSchema|undefined}
214
+ */
215
+ function getInvalidIntersectionBranch (
216
+ types, schemaObject, originalShape, value
217
+ ) {
218
+ if (schemaObject.type === 'intersection') {
219
+ return getInvalidIntersectionBranch(
220
+ types, schemaObject.left, originalShape, value
221
+ ) ?? getInvalidIntersectionBranch(
222
+ types, schemaObject.right, originalShape, value
223
+ );
224
+ }
225
+ return parseValue(types, schemaObject, originalShape, value).success
226
+ ? undefined
227
+ : schemaObject;
228
+ }
229
+
230
+ /**
231
+ * Checks whether a record property name satisfies the record's `key` schema.
232
+ *
233
+ * For a strict `record` every key must conform, so the distinction is
234
+ * irrelevant. For a `looseRecord`, Zod validates the `value` schema only
235
+ * against entries whose key conforms; entries with a non-conforming key are
236
+ * passed through untyped. Both the child-schema resolver in `arrayType.js` and
237
+ * `convertFromTypeson` below use this to avoid imposing the `value` schema on
238
+ * those pass-through entries.
239
+ * @param {InstanceType<typeof import('../types.js').default>} types
240
+ * @param {ZodexSchema|undefined} keySchema
241
+ * @param {string|number|undefined} key
242
+ * @returns {boolean}
243
+ */
244
+ export function recordKeyConforms (types, keySchema, key) {
245
+ if (!keySchema || key === undefined) {
246
+ return true;
247
+ }
248
+ if (parseValue(types, keySchema, keySchema, key).success) {
249
+ return true;
250
+ }
251
+ // Mirror Zod's numeric-string key fallback: an object property name is always
252
+ // a string, so a `number`/`bigInt`/`nan` key schema is retried against the
253
+ // coerced value.
254
+ return typeof key === 'string' && key.trim() !== '' &&
255
+ Number.isFinite(Number(key)) &&
256
+ parseValue(types, keySchema, keySchema, Number(key)).success;
257
+ }
258
+
259
+ /**
260
+ * Count how many branches of an `xor` (exclusive union) the value satisfies.
261
+ * `xor` is valid only when exactly one matches; the count drives the editor's
262
+ * live match indicator so an ambiguous value reads as a rule, not a glitch.
263
+ * @param {InstanceType<typeof import('../types.js').default>} types
264
+ * @param {import('zodexy').SzUnion} xorSchema
265
+ * @param {unknown} value
266
+ * @returns {{matched: number, total: number}}
267
+ */
268
+ export function getXorBranchMatchInfo (types, xorSchema, value) {
269
+ const options = /** @type {ZodexSchema[]} */ (xorSchema.options ?? []);
270
+ let matched = 0;
271
+ for (const option of options) {
272
+ if (parseValue(types, option, xorSchema, value).success) {
273
+ matched++;
274
+ }
275
+ }
276
+ return {matched, total: options.length};
277
+ }
278
+
279
+ /**
280
+ * Whether a value satisfies a single (already-flattened) schema branch. Used
281
+ * to check the value against the specific `xor` branch the user chose, not
282
+ * merely against some branch.
283
+ * @param {InstanceType<typeof import('../types.js').default>} types
284
+ * @param {ZodexSchema} schema
285
+ * @param {unknown} value
286
+ * @returns {boolean}
287
+ */
288
+ export function valueMatchesSchema (types, schema, value) {
289
+ return parseValue(types, schema, schema, value).success;
290
+ }
291
+
292
+ /**
293
+ * @param {InstanceType<typeof import('../types.js').default>} types
294
+ * @returns {NonNullable<
295
+ * import('zodexy').DezerializerOptions['checks']
296
+ * >}
297
+ */
298
+ function getChecks (types) {
299
+ return Object.fromEntries(Object.entries(types.availableTypes).map(([
300
+ name, typeObject
301
+ ]) => {
302
+ return [name, (payload) => {
303
+ if (!Array.isArray(typeObject) && typeObject.valueMatch &&
304
+ !typeObject.valueMatch(payload.value)) {
305
+ payload.issues.push({
306
+ code: 'custom',
307
+ input: payload.value,
308
+ message: `Value does not match ${name}`
309
+ });
310
+ }
311
+ }];
312
+ }));
313
+ }
314
+
315
+ /**
316
+ * @typedef {import('zodexy').SzType} ZodexSchema
65
317
  */
66
318
  /**
67
319
  * @typedef {import('../utils/objects.js').NestedObject} NestedObject
68
320
  */
69
321
 
322
+ /** @type {WeakMap<ZodexSchema, ZodexSchema>} */
323
+ const intersectionSchemas = new WeakMap();
324
+
325
+ /**
326
+ * @param {ZodexSchema} schemaObject
327
+ * @returns {ZodexSchema}
328
+ */
329
+ export function getValidationSchema (schemaObject) {
330
+ return intersectionSchemas.get(schemaObject) ?? schemaObject;
331
+ }
332
+
333
+ /**
334
+ * @param {ZodexSchema['type']} type
335
+ * @param {any} value
336
+ * @returns {any}
337
+ */
338
+ function getComparableConstraint (type, value) {
339
+ return type === 'bigInt' ? BigInt(value) : value;
340
+ }
341
+
342
+ /**
343
+ * Merge a serialized schema's `meta` bag from a wrapping or intersecting
344
+ * schema into an inner one. `title`/`description` concatenate with `" and "`
345
+ * (mirroring how a bare `description` is merged), skipping Zodexy's
346
+ * `"Modifiers"` sentinel; any other key is taken from the source only when the
347
+ * target lacks it.
348
+ * @param {{[key: string]: any}|undefined} target
349
+ * @param {{[key: string]: any}} source
350
+ * @returns {{[key: string]: any}}
351
+ */
352
+ function mergeMeta (target, source) {
353
+ const merged = {...target};
354
+ for (const [key, val] of Object.entries(source)) {
355
+ if (key === 'title' || key === 'description') {
356
+ if (typeof val === 'string' && val !== 'Modifiers') {
357
+ merged[key] = typeof merged[key] === 'string' &&
358
+ merged[key] !== 'Modifiers'
359
+ ? merged[key] + ' and ' + val
360
+ : val;
361
+ }
362
+ } else if (!Object.hasOwn(merged, key)) {
363
+ merged[key] = val && typeof val === 'object' ? copyObject(val) : val;
364
+ }
365
+ }
366
+ return merged;
367
+ }
368
+
70
369
  /**
71
370
  * @param {ZodexSchema} leftItem
72
371
  * @param {ZodexSchema} rightItem
@@ -74,36 +373,61 @@ const zodexToStructuredCloningTypeMap = new Map([
74
373
  * @returns {ZodexSchema}
75
374
  */
76
375
  function mergeSchema (leftItem, rightItem) {
77
- /* istanbul ignore if -- Guard */
78
- if (leftItem.type !== 'object') {
79
- console.log('leftItem', leftItem);
80
- throw new Error('Unexpected leftItem of type ' + leftItem.type);
81
- }
82
- /* istanbul ignore if -- Guard */
83
- if (rightItem.type !== 'object') {
84
- console.log('rightItem', rightItem);
85
- throw new Error('Unexpected rightItem of type ' + rightItem.type);
376
+ if (leftItem.type !== rightItem.type) {
377
+ throw new Error(
378
+ 'Cannot merge intersection types ' + leftItem.type + ' and ' +
379
+ rightItem.type
380
+ );
86
381
  }
87
382
 
88
383
  const newLeftObj = copyObject(leftItem);
89
384
 
90
385
  for (const [prop, val] of Object.entries(rightItem)) {
91
- if (prop !== 'type' && prop !== 'properties') {
386
+ if (prop !== 'type' && prop !== 'properties' && prop !== 'error') {
92
387
  if (prop === 'description') {
93
388
  if (val !== 'Modifiers') { // A bit cleaner
94
- newLeftObj[prop] = newLeftObj[prop]
95
- ? newLeftObj[prop] + ' and ' + val
389
+ const existingDescription = newLeftObj[prop];
390
+ newLeftObj[prop] = existingDescription
391
+ ? existingDescription + ' and ' + val
96
392
  : val;
97
393
  }
98
- } else { // catchall, unknownKeys
99
- if (prop in newLeftObj) {
100
- throw new Error(
101
- 'Duplicate property ' + prop + ' of value ' +
102
- JSON.stringify(val) + ' and ' +
103
- JSON.stringify(newLeftObj[prop])
104
- );
394
+ } else if (prop === 'meta') {
395
+ newLeftObj.meta = mergeMeta(
396
+ /** @type {{[key: string]: any}} */ (newLeftObj.meta),
397
+ /** @type {{[key: string]: any}} */ (val)
398
+ );
399
+ } else if (Object.hasOwn(newLeftObj, prop)) {
400
+ if (newLeftObj[prop] !== val && !deepEqual(newLeftObj[prop], val)) {
401
+ if (leftItem.type === 'object') {
402
+ throw new Error(
403
+ 'Duplicate property ' + prop + ' of value ' +
404
+ JSON.stringify(val) + ' and ' +
405
+ JSON.stringify(newLeftObj[prop])
406
+ );
407
+ }
408
+ if (prop === 'min' || prop === 'minLength') {
409
+ const existingConstraint = getComparableConstraint(
410
+ leftItem.type, newLeftObj[prop]
411
+ );
412
+ const rightConstraint = getComparableConstraint(
413
+ rightItem.type, val
414
+ );
415
+ newLeftObj[prop] = existingConstraint > rightConstraint
416
+ ? newLeftObj[prop]
417
+ : val;
418
+ } else if (prop === 'max' || prop === 'maxLength') {
419
+ const existingConstraint = getComparableConstraint(
420
+ leftItem.type, newLeftObj[prop]
421
+ );
422
+ const rightConstraint = getComparableConstraint(
423
+ rightItem.type, val
424
+ );
425
+ newLeftObj[prop] = existingConstraint < rightConstraint
426
+ ? newLeftObj[prop]
427
+ : val;
428
+ }
105
429
  }
106
-
430
+ } else {
107
431
  newLeftObj[prop] = val && typeof val === 'object'
108
432
  ? copyObject(val)
109
433
  /* istanbul ignore next -- Guard */
@@ -112,9 +436,19 @@ function mergeSchema (leftItem, rightItem) {
112
436
  }
113
437
  }
114
438
 
439
+ if (leftItem.type !== 'object' || rightItem.type !== 'object') {
440
+ delete newLeftObj.error;
441
+ return newLeftObj;
442
+ }
443
+
115
444
  for (const [prop, val] of Object.entries(rightItem.properties)) {
116
445
  if (typeof newLeftObj.properties !== 'string' &&
117
- prop in newLeftObj.properties) {
446
+ Object.hasOwn(newLeftObj.properties, prop)) {
447
+ if (deepEqual(newLeftObj.properties[prop], val)) {
448
+ // Identical property schemas from both intersection branches merge to
449
+ // themselves; nothing to reconcile
450
+ continue;
451
+ }
118
452
  throw new Error(
119
453
  'Duplicate property ' + prop + ' of value ' +
120
454
  JSON.stringify(val) + ' and ' +
@@ -200,6 +534,15 @@ function addModifiers (schemaObject, set) {
200
534
  : schemaObject.description;
201
535
  }
202
536
  }
537
+
538
+ if (schemaObject.meta && typeof schemaObject.meta === 'object') {
539
+ for (const obj of set) {
540
+ obj.meta = mergeMeta(
541
+ /** @type {{[key: string]: any}} */ (obj.meta),
542
+ /** @type {{[key: string]: any}} */ (schemaObject.meta)
543
+ );
544
+ }
545
+ }
203
546
  }
204
547
 
205
548
  /**
@@ -208,376 +551,314 @@ function addModifiers (schemaObject, set) {
208
551
  * @returns {Set<ZodexSchema>}
209
552
  */
210
553
  export function getTypesForSchema (schemaObject, originalJSON) {
211
- switch (schemaObject.type) {
212
- case 'never':
213
- return new Set();
214
- case 'object': {
215
- const set = new Set();
216
- // const {properties} = schemaObject;
217
- // if (
218
- // 'type' in properties && properties.type.type === 'enum' &&
219
- // properties.type.values.length === 1
220
- // ) {
221
- // set.add(schemaObject);
222
- // set.add(properties.type.defaultValue);
223
- // }
224
- set.add(schemaObject);
225
- return set;
226
- }
227
- case 'discriminatedUnion':
228
- case 'union': {
229
- /** @type {(ZodexSchema & {$discriminator?: string})[]} */
230
- let set = [];
231
- for (const option of schemaObject.options) {
232
- set = [...set, ...getTypesForSchema(option, originalJSON)];
554
+ for (;;) {
555
+ if (getCheckedType(schemaObject)) {
556
+ return new Set([schemaObject]);
233
557
  }
234
-
235
- if (schemaObject.type === 'discriminatedUnion') {
236
- for (const obj of set) {
237
- // Todo: Use to confirm the object has the discriminator
238
- obj.$discriminator = schemaObject.discriminator;
239
- }
558
+ switch (schemaObject.type) {
559
+ case 'never':
560
+ return new Set();
561
+ case 'literal':
562
+ case 'enum':
563
+ return splitConstrainedSchema(schemaObject);
564
+ case 'catch': {
565
+ const catchSchema = schemaObject;
566
+ const innerSchemas = [...getTypesForSchema(
567
+ catchSchema.innerType, originalJSON
568
+ )].map((innerSchema) => ({...innerSchema}));
569
+ addModifiers(schemaObject, innerSchemas);
570
+ const fallbackSchemas = [...getTypesForSchema({
571
+ type: 'literal',
572
+ values: [catchSchema.value]
573
+ }, originalJSON)];
574
+ addModifiers(schemaObject, fallbackSchemas);
575
+ return new Set([...innerSchemas, ...fallbackSchemas]);
576
+ }
577
+ case 'object': {
578
+ const set = new Set();
579
+ // const {properties} = schemaObject;
580
+ // if (
581
+ // 'type' in properties && properties.type.type === 'enum' &&
582
+ // properties.type.values.length === 1
583
+ // ) {
584
+ // set.add(schemaObject);
585
+ // set.add(properties.type.defaultValue);
586
+ // }
587
+ // eslint-disable-next-line unicorn/no-immediate-mutation -- May add above
588
+ set.add(schemaObject);
589
+ return set;
240
590
  }
591
+ case 'discriminatedUnion':
592
+ case 'xor':
593
+ case 'union': {
594
+ /** @type {(ZodexSchema & {$discriminator?: string})[]} */
595
+ let set = [];
596
+ for (const option of schemaObject.options) {
597
+ set = [...set, ...getTypesForSchema(option, originalJSON)];
598
+ }
241
599
 
242
- addModifiers(schemaObject, set);
243
- return new Set(set);
244
- } case 'intersection': {
245
- const left = getTypesForSchema(schemaObject.left, originalJSON);
246
- const right = getTypesForSchema(schemaObject.right, originalJSON);
247
-
248
- const set = flattenIntersection(left, right);
249
- addModifiers(schemaObject, set);
250
- return new Set(set);
251
- } case 'any': case 'unknown':
252
- return new Set([
253
- {
254
- type: 'boolean'
255
- },
256
- {
257
- type: 'number'
258
- },
259
- {
260
- type: 'nan'
261
- },
262
- {
263
- type: 'bigInt'
264
- },
265
- {
266
- type: 'string'
267
- },
268
- {
269
- description: 'Email',
270
- type: 'string',
271
- kind: 'email'
272
- },
273
- {
274
- description: 'URL',
275
- type: 'string',
276
- kind: 'url'
277
- },
278
- {
279
- description: 'Date',
280
- type: 'string',
281
- kind: 'date'
282
- },
283
- {
284
- type: 'date'
285
- },
286
- // {
287
- // type: 'void'
288
- // },
289
- {
290
- type: 'undefined'
291
- },
292
- {
293
- type: 'null'
294
- },
295
- {
296
- type: 'object',
297
- properties: {},
298
- unknownKeys: 'passthrough'
299
- },
300
-
301
- // Todo: support these types separately
302
- // {
303
- // type: 'symbol'
304
- // },
305
- // {
306
- // type: 'promise',
307
- // value: {
308
- // type: 'any'
309
- // }
310
- // },
311
- // {
312
- // type: 'function',
313
- // args: {
314
- // type: 'tuple',
315
- // items: [],
316
- // rest: {
317
- // type: 'any'
318
- // }
319
- // },
320
- // returns: {
321
- // type: 'any'
322
- // }
323
- // },
324
- {
325
- type: 'nativeEnum',
326
- values: {
327
- type: 'union',
328
- options: [
329
- {
330
- description: 'Numeric',
331
- type: 'record',
332
- key: {
333
- type: 'number'
334
- },
335
- value: {
336
- type: 'string'
337
- }
338
- },
339
- {
340
- description: 'String',
341
- type: 'record',
342
- key: {
343
- type: 'string'
344
- },
345
- value: {
346
- type: 'union',
347
- options: [
348
- {
349
- type: 'string'
350
- },
351
- {
352
- type: 'number'
353
- }
354
- ]
355
- }
356
- }
357
- ]
358
- }
359
- },
360
- {
361
- type: 'array',
362
- element: {
363
- type: 'any'
364
- }
365
- },
366
- {
367
- type: 'set',
368
- value: {
369
- type: 'any'
600
+ if (schemaObject.type === 'discriminatedUnion') {
601
+ for (const obj of set) {
602
+ // Todo: Use to confirm the object has the discriminator
603
+ obj.$discriminator = schemaObject.discriminator;
370
604
  }
371
- },
372
- {
373
- type: 'map',
374
- key: {
375
- type: 'any'
376
- },
377
- value: {
378
- type: 'any'
379
- }
380
- },
381
- {
382
- type: 'never'
383
- },
384
- {
385
- type: 'effect',
386
- effects: [
387
- {
388
- name: 'regexp',
389
- type: 'refinement'
390
- }
391
- ],
392
- inner: {type: 'any'}
393
- },
394
- {
395
- type: 'effect',
396
- effects: [
397
- {
398
- name: 'blob',
399
- type: 'refinement'
400
- }
401
- ],
402
- inner: {type: 'any'}
403
- },
404
- {
405
- type: 'effect',
406
- effects: [
407
- {
408
- name: 'BooleanObject',
409
- type: 'refinement'
410
- }
411
- ],
412
- inner: {type: 'any'}
413
- },
414
- {
415
- type: 'effect',
416
- effects: [
417
- {
418
- name: 'NumberObject',
419
- type: 'refinement'
420
- }
421
- ],
422
- inner: {type: 'any'}
423
- },
424
- {
425
- type: 'effect',
426
- effects: [
427
- {
428
- name: 'StringObject',
429
- type: 'refinement'
430
- }
431
- ],
432
- inner: {type: 'any'}
433
- },
434
- {
435
- type: 'effect',
436
- effects: [
437
- {
438
- name: 'SpecialRealNumber',
439
- type: 'refinement'
440
- }
441
- ],
442
- inner: {type: 'any'}
443
- },
444
- {
445
- type: 'effect',
446
- effects: [
447
- {
448
- name: 'domexception',
449
- type: 'refinement'
450
- }
451
- ],
452
- inner: {type: 'any'}
453
- },
454
- {
455
- type: 'effect',
456
- effects: [
457
- {
458
- name: 'error',
459
- type: 'refinement'
460
- }
461
- ],
462
- inner: {type: 'any'}
463
- },
464
- {
465
- type: 'effect',
466
- effects: [
467
- {
468
- name: 'filelist',
469
- type: 'refinement'
470
- }
471
- ],
472
- inner: {type: 'any'}
473
- },
474
- {
475
- type: 'effect',
476
- effects: [
477
- {
478
- name: 'file',
479
- type: 'refinement'
480
- }
481
- ],
482
- inner: {type: 'any'}
483
- },
484
- {
485
- type: 'effect',
486
- effects: [
487
- {
488
- name: 'resurrectable', // noneditable
489
- type: 'refinement'
490
- }
491
- ],
492
- inner: {type: 'any'}
493
- },
494
- {
495
- type: 'effect',
496
- effects: [
497
- {
498
- name: 'blobHTML',
499
- type: 'refinement'
500
- }
501
- ],
502
- inner: {type: 'any'}
503
- },
504
- {
505
- type: 'effect',
506
- effects: [
507
- {
508
- name: 'buffersource',
509
- type: 'refinement'
510
- }
511
- ],
512
- inner: {type: 'any'}
513
- },
514
- {
515
- type: 'effect',
516
- effects: [
517
- {
518
- name: 'dommatrix',
519
- type: 'refinement'
605
+ }
606
+
607
+ addModifiers(schemaObject, set);
608
+ return new Set(set);
609
+ } case 'intersection': {
610
+ const left = getTypesForSchema(schemaObject.left, originalJSON);
611
+ const right = getTypesForSchema(schemaObject.right, originalJSON);
612
+
613
+ const set = flattenIntersection(left, right);
614
+ for (const item of set) {
615
+ intersectionSchemas.set(item, schemaObject);
616
+ }
617
+ addModifiers(schemaObject, set);
618
+ return new Set(set);
619
+ } case 'pipe': {
620
+ if (isStringboolSchema(schemaObject)) {
621
+ // Keep the whole `pipe` as the schema object: `getSchemaType` reports it
622
+ // as a String, `stringType` reads its `truthy`/`falsy`/`case` to
623
+ // validate the value, and `dezerialize` still rebuilds
624
+ // `z.stringbool({truthy, falsy})` for value parsing. Drop the
625
+ // `description` first so `addModifiers` re-adds it once rather than
626
+ // concatenating it with itself.
627
+ const stringboolSchema = {...schemaObject};
628
+ delete stringboolSchema.description;
629
+ const set = [stringboolSchema];
630
+ addModifiers(schemaObject, set);
631
+ return new Set(set);
632
+ }
633
+ const set = [...getTypesForSchema(schemaObject.inner, originalJSON)];
634
+ addModifiers(schemaObject, set);
635
+ return new Set(set);
636
+ } case 'any': case 'unknown':
637
+ return new Set([
638
+ {
639
+ type: 'boolean'
640
+ },
641
+ {
642
+ type: 'number'
643
+ },
644
+ {
645
+ type: 'nan'
646
+ },
647
+ {
648
+ type: 'bigInt'
649
+ },
650
+ {
651
+ type: 'string'
652
+ },
653
+ {
654
+ description: 'Email',
655
+ type: 'string',
656
+ kind: 'email'
657
+ },
658
+ {
659
+ description: 'URL',
660
+ type: 'string',
661
+ kind: 'url'
662
+ },
663
+ {
664
+ description: 'Date',
665
+ type: 'string',
666
+ kind: 'date'
667
+ },
668
+ {
669
+ type: 'date'
670
+ },
671
+ // {
672
+ // type: 'void'
673
+ // },
674
+ {
675
+ type: 'undefined'
676
+ },
677
+ {
678
+ type: 'null'
679
+ },
680
+ {
681
+ type: 'object',
682
+ properties: {},
683
+ catchall: {
684
+ type: 'unknown'
520
685
  }
521
- ],
522
- inner: {type: 'any'}
523
- },
524
- {
525
- type: 'effect',
526
- effects: [
527
- {
528
- name: 'dompoint',
529
- type: 'refinement'
686
+ },
687
+
688
+ // Todo: support these types separately
689
+ // {
690
+ // type: 'symbol'
691
+ // },
692
+ // {
693
+ // type: 'promise',
694
+ // value: {
695
+ // type: 'any'
696
+ // }
697
+ // },
698
+ // {
699
+ // type: 'function',
700
+ // args: {
701
+ // type: 'tuple',
702
+ // items: [],
703
+ // rest: {
704
+ // type: 'any'
705
+ // }
706
+ // },
707
+ // returns: {
708
+ // type: 'any'
709
+ // }
710
+ // },
711
+ {
712
+ type: 'array',
713
+ element: {
714
+ type: 'any'
530
715
  }
531
- ],
532
- inner: {type: 'any'}
533
- },
534
- {
535
- type: 'effect',
536
- effects: [
537
- {
538
- name: 'domrect',
539
- type: 'refinement'
716
+ },
717
+ {
718
+ type: 'set',
719
+ value: {
720
+ type: 'any'
540
721
  }
541
- ],
542
- inner: {type: 'any'}
543
- },
544
- {
545
- type: 'effect',
546
- effects: [
547
- {
548
- name: 'errors',
549
- type: 'refinement'
722
+ },
723
+ {
724
+ type: 'map',
725
+ key: {
726
+ type: 'any'
727
+ },
728
+ value: {
729
+ type: 'any'
550
730
  }
551
- ],
552
- inner: {type: 'any'}
553
- },
554
- // Todo: Adapt into a widget to drag to point back to another object
555
- {
556
- description: 'JSON Reference',
557
- type: 'object',
558
- properties: {
559
- $ref: {
560
- type: 'string'
731
+ },
732
+
733
+ {
734
+ type: 'any',
735
+ checks: [{name: 'regexp'}]
736
+ },
737
+ {
738
+ type: 'any',
739
+ checks: [{name: 'blob'}]
740
+ },
741
+ {
742
+ type: 'any',
743
+ checks: [{name: 'BooleanObject'}]
744
+ },
745
+ {
746
+ type: 'any',
747
+ checks: [{name: 'NumberObject'}]
748
+ },
749
+ {
750
+ type: 'any',
751
+ checks: [{name: 'StringObject'}]
752
+ },
753
+ {
754
+ type: 'any',
755
+ checks: [{name: 'SpecialRealNumber'}]
756
+ },
757
+ {
758
+ type: 'any',
759
+ checks: [{name: 'domexception'}]
760
+ },
761
+ {
762
+ type: 'any',
763
+ checks: [{name: 'error'}]
764
+ },
765
+ {
766
+ type: 'any',
767
+ checks: [{name: 'filelist'}]
768
+ },
769
+ {
770
+ type: 'any',
771
+ checks: [{name: 'file'}]
772
+ },
773
+ {
774
+ type: 'any',
775
+ checks: [{name: 'resurrectable'}] // noneditable
776
+ },
777
+ {
778
+ type: 'any',
779
+ checks: [{name: 'blobHTML'}]
780
+ },
781
+ {
782
+ type: 'any',
783
+ checks: [{name: 'buffersource'}]
784
+ },
785
+ {
786
+ type: 'any',
787
+ checks: [{name: 'dommatrix'}]
788
+ },
789
+ {
790
+ type: 'any',
791
+ checks: [{name: 'dompoint'}]
792
+ },
793
+ {
794
+ type: 'any',
795
+ checks: [{name: 'domrect'}]
796
+ },
797
+ {
798
+ type: 'any',
799
+ checks: [{name: 'errors'}]
800
+ },
801
+
802
+ // Todo: Adapt into a widget to drag to point back to another object
803
+ {
804
+ description: 'JSON Reference',
805
+ type: 'object',
806
+ properties: {
807
+ $ref: {
808
+ type: 'string'
809
+ }
561
810
  }
562
811
  }
812
+ ]);
813
+ default: {
814
+ if ('$ref' in schemaObject) {
815
+ // console.log('originalJSON', originalJSON, schemaObject.$ref);
816
+ const refObj = resolveJSONPointer({
817
+ obj: originalJSON,
818
+ path: /** @type {import('zodexy').SzRef} */ (
819
+ schemaObject
820
+ ).$ref
821
+ });
822
+ schemaObject = refObj;
823
+ // eslint-disable-next-line unicorn/no-break-in-nested-loop -- Intentional, continues the `for` loop
824
+ continue;
563
825
  }
564
- ]);
565
- default: {
566
- if ('$ref' in schemaObject) {
567
- // console.log('originalJSON', originalJSON, schemaObject.$ref);
568
- const refObj = resolveJSONPointer({
569
- obj: originalJSON,
570
- path: /** @type {import('zodex').SzRef} */ (schemaObject).$ref
571
- });
572
- return getTypesForSchema(refObj, originalJSON);
826
+ return new Set([schemaObject]);
827
+ }
573
828
  }
574
- return new Set([schemaObject]);
575
- }
576
829
  }
577
830
  }
578
831
 
579
832
  /** @type {import('../formats.js').Format} */
580
833
  const schema = {
834
+ isValueValidationRequired (schemaObject) {
835
+ // `record`/`tuple` refine the `object`/`array` UI, whose structure does not
836
+ // by itself enforce the key schema, positional item schemas, or `rest`;
837
+ // so the assembled value must be parsed to surface those failures on the
838
+ // form control.
839
+ if (['record', 'looseRecord', 'tuple'].includes(schemaObject.type)) {
840
+ return true;
841
+ }
842
+ return schemaObject.type !== 'object' &&
843
+ intersectionSchemas.has(schemaObject);
844
+ },
845
+ validateValue (types, schemaObject, value) {
846
+ const validationSchema = getValidationSchema(schemaObject);
847
+ const parsed = parseValue(
848
+ types, validationSchema, validationSchema, value
849
+ );
850
+ return parsed.success
851
+ ? {valid: true}
852
+ : {
853
+ valid: false,
854
+ message: parsed.error.issues[0]?.message,
855
+ schema: validationSchema.type === 'intersection'
856
+ ? getInvalidIntersectionBranch(
857
+ types, validationSchema, validationSchema, value
858
+ )
859
+ : validationSchema
860
+ };
861
+ },
581
862
  iterate (records, stateObj) {
582
863
  // console.log('records', records, stateObj);
583
864
  stateObj.format = 'schema';
@@ -603,131 +884,207 @@ const schema = {
603
884
 
604
885
  // We shouldn't have to reprocess intersections, etc., as this is our own
605
886
  // union
606
- if (typeof parentSchemaIdx === 'number' && parentSchema?.type === 'union') {
607
- parentSchema = parentSchema.options[parentSchemaIdx];
887
+ if (typeof parentSchemaIdx === 'number' && isUnionLike(parentSchema?.type)) {
888
+ parentSchema = /** @type {import('zodexy').SzUnion} */ (
889
+ parentSchema
890
+ ).options[parentSchemaIdx];
608
891
  }
609
892
 
610
893
  switch (parentSchema?.type) {
611
894
  case 'object':
612
- currentSchema = /** @type {import('zodex').SzObject} */ (
895
+ currentSchema = /** @type {import('zodexy').SzObject} */ (
613
896
  parentSchema
614
897
  ).properties[
615
898
  /** @type {string} */ (arrayOrObjectPropertyName)
616
899
  ];
617
900
  if (!currentSchema) {
618
- currentSchema = /** @type {import('zodex').SzObject} */ (
901
+ currentSchema = /** @type {import('zodexy').SzObject} */ (
619
902
  parentSchema
620
903
  ).catchall;
621
904
  mustBeOptional = true;
622
905
  }
623
906
  break;
624
907
  case 'array':
625
- currentSchema = /** @type {import('zodex').SzArray} */ (
908
+ currentSchema = /** @type {import('zodexy').SzArray} */ (
626
909
  parentSchema
627
910
  ).element;
628
911
  break;
629
912
  case 'set':
630
- currentSchema = /** @type {import('zodex').SzSet} */ (
913
+ currentSchema = /** @type {import('zodexy').SzSet} */ (
631
914
  parentSchema
632
915
  ).value;
633
916
  break;
634
- case 'effect':
635
- currentSchema = /** @type {import('zodex').SzEffect} */ (
636
- parentSchema
637
- ).inner;
917
+ case 'codec':
918
+ if (parentSchema.name === 'filelist' &&
919
+ parentSchema.output.type === 'array') {
920
+ currentSchema = typesonType === 'file'
921
+ ? parentSchema.output.element
922
+ : parentSchema;
923
+ }
638
924
  break;
925
+ // No need to handle differently?
926
+ // case 'instanceof':
927
+ // currentSchema = /** @type {import('zodexy').SzInstanceOf} */ (
928
+ // parentSchema
929
+ // );
930
+ // break;
639
931
  // eslint-disable-next-line sonarjs/no-duplicated-branches -- Maintenance
640
932
  case 'promise':
641
- currentSchema = /** @type {import('zodex').SzPromise} */ (
933
+ currentSchema = /** @type {import('zodexy').SzPromise} */ (
642
934
  parentSchema
643
935
  ).value;
644
936
  break;
645
937
  case 'tuple':
646
- currentSchema = /** @type {import('zodex').SzTuple} */ (
938
+ currentSchema = /** @type {import('zodexy').SzTuple} */ (
647
939
  parentSchema
648
940
  ).items[Number(arrayOrObjectPropertyName)] ??
649
- /** @type {import('zodex').SzTuple} */ (
941
+ /** @type {import('zodexy').SzTuple} */ (
650
942
  parentSchema
651
943
  ).rest;
652
944
  break;
945
+ case 'record':
946
+ // Every own property of a record shares the single `value` schema; the
947
+ // `key` schema constrains the property name and is enforced by
948
+ // value-level validation (`isValueValidationRequired`). Record keys are
949
+ // dynamic, so no individual property is required.
950
+ currentSchema = /** @type {import('zodexy').SzRecord<any, any>} */ (
951
+ parentSchema
952
+ ).value;
953
+ mustBeOptional = true;
954
+ break;
955
+ case 'looseRecord':
956
+ // As `record`, but only for keys that satisfy the `key` schema. Zod's
957
+ // loose mode passes non-conforming keys through untyped, so the `value`
958
+ // schema must not be imposed on them; leaving `currentSchema` unset
959
+ // falls back to the value's own runtime type (`{type: typesonType}`).
960
+ mustBeOptional = true;
961
+ currentSchema = recordKeyConforms(
962
+ types,
963
+ /** @type {import('zodexy').SzLooseRecord<any, any>} */ (
964
+ parentSchema
965
+ ).key,
966
+ arrayOrObjectPropertyName
967
+ )
968
+ ? /** @type {import('zodexy').SzLooseRecord<any, any>} */ (
969
+ parentSchema
970
+ ).value
971
+ : undefined;
972
+ break;
653
973
  // Todo:
654
- // 'record': key, value
655
974
  // 'map': key, value
656
975
  // 'function': args, returns
657
976
  default:
658
977
  break;
659
978
  }
660
979
 
661
- /* istanbul ignore if -- Guard */
980
+ // Reached when there is no governing schema for this child: an unschema'd
981
+ // parent, or a `looseRecord` entry whose key does not satisfy the `key`
982
+ // schema (Zod's loose mode passes such entries through untyped). Fall back
983
+ // to the value's own runtime type.
662
984
  if (!currentSchema) {
663
985
  return {type: typesonType};
664
986
  }
665
987
  const schemaObjects = [...getTypesForSchema(
666
- /** @type {import('zodex').SzType} */ (currentSchema),
667
- /** @type {import('zodex').SzType} */ (stateObj.schemaContent)
988
+ currentSchema,
989
+ /** @type {import('zodexy').SzType} */ (
990
+ stateObj.schemaContent
991
+ )
668
992
  )];
669
993
  // console.log(
670
994
  // 'vvv', v, currentSchema,
671
995
  // arrayOrObjectPropertyName, parentSchema, schemaObjects
672
996
  // );
673
997
  // console.log('schemaObjects', schemaObjects);
998
+
999
+ // When several union options accept the value, the first structural match
1000
+ // is not necessarily the best one: a bare `{type: 'object', properties:
1001
+ // {}}` option strips unrecognized keys, so it parses successfully (with
1002
+ // data loss) even when a sibling option describes the value's actual
1003
+ // shape. Prefer an option that round-trips the value losslessly, then one
1004
+ // that at least parses, and only then one that merely matches the value's
1005
+ // kind. Preserving that last tier matters for a preloaded value that is
1006
+ // the right type but violates a refinement (a `File` whose MIME type is
1007
+ // outside the schema's `mime`, an array shorter than `min`, …): the
1008
+ // control should still carry its schema (and description), with the
1009
+ // violation surfaced by value-level validation, rather than degrading to
1010
+ // an untyped control.
1011
+ let fallbackMatch;
1012
+ let structuralMatch;
674
1013
  for (const [schemaIdx, schema] of schemaObjects.entries()) {
675
- let unknownKeys;
676
- if (schema.type === 'object') {
677
- ({unknownKeys} = schema);
678
- // We don't want to eagerly match, e.g., if there are other objects
679
- // which include the optional properties; this could cause a problem,
680
- // however, if the tested object has extra non-standard properties
681
- schema.unknownKeys = 'strict';
1014
+ const type = getSchemaType(schema);
1015
+
1016
+ const typeObject =
1017
+ /** @type {Required<import('../types.js').TypeObject>} */ (
1018
+ types.getTypeObject(
1019
+ /** @type {import('../types.js').AvailableType} */ (type)
1020
+ )
1021
+ );
1022
+
1023
+ if (!typeObject.valueMatch?.(v)) {
1024
+ continue;
682
1025
  }
1026
+
683
1027
  const dezSchema = dezerialize(schema, {
1028
+ checks: getChecks(types),
1029
+ codecs: dezerializerCodecs,
1030
+ instances: dezerializerInstances,
684
1031
  originalShape: stateObj.schemaContent
685
1032
  });
686
- const parsed = dezSchema.safeParse(v);
687
-
688
- if (schema.type === 'object') {
689
- schema.unknownKeys = unknownKeys;
690
- }
1033
+ const parsed = type === 'promise'
1034
+ ? {success: true}
1035
+ : dezSchema.safeParse(v);
691
1036
  // console.log('parsed', parsed.success, v, schema);
692
- if (parsed.success) {
693
- let type = zodexToStructuredCloningTypeMap.get(schema.type);
694
- if (!type && schema.type === 'effect') {
695
- type = /** @type {import('../types.js').AvailableType} */ (
696
- schema.effects[0].name
697
- );
698
- }
699
1037
 
700
- const typeObject =
701
- /** @type {Required<import('../types.js').TypeObject>} */ (
702
- types.getTypeObject(
703
- /** @type {import('../types.js').AvailableType} */ (type)
704
- )
705
- );
706
-
707
- if (typeObject.valueMatch && typeObject.valueMatch(v)) {
708
- // console.log(
709
- // 'matched', v, v?.length, type, schema, schemaIdx, schemaObjects
710
- // );
711
- // console.log('ssss', !stateObj.rootUI ||
712
- // (stateObj.readonly || schemaObjects.length === 1),
713
- // schema, schemaObjects);
714
- return {
715
- type,
716
- schemaIdx,
717
- // For `readonly`, we just want to show the current type (no
718
- // pull-down)
719
- schema: !stateObj.rootUI ||
720
- (stateObj.readonly || schemaObjects.length === 1)
721
- ? schema
722
- : {
723
- type: 'union',
724
- options: schemaObjects
725
- },
726
- mustBeOptional
727
- };
1038
+ /**
1039
+ * @type {{
1040
+ * type: import('../types.js').AvailableArbitraryType|undefined,
1041
+ * schema?: import('zodexy').SzType,
1042
+ * mustBeOptional?: boolean,
1043
+ * schemaIdx?: number
1044
+ * }}
1045
+ */
1046
+ const match = {
1047
+ type,
1048
+ schemaIdx,
1049
+ // For `readonly`, we just want to show the current type (no
1050
+ // pull-down)
1051
+ schema: !stateObj.rootUI ||
1052
+ (stateObj.readonly || schemaObjects.length === 1)
1053
+ ? schema
1054
+ // This synthesized schema only drives the type-choices pull-down;
1055
+ // it is deliberately a plain `union` of the flattened leaf
1056
+ // candidates. Exclusive (`xor`) / keyed (`discriminatedUnion`)
1057
+ // enforcement stays with the original schema node, which
1058
+ // `getValidationSchema` passes through untouched to
1059
+ // `validateValue`.
1060
+ : {
1061
+ type: 'union',
1062
+ options: schemaObjects
1063
+ },
1064
+ mustBeOptional
1065
+ };
1066
+
1067
+ if (parsed.success) {
1068
+ // console.log(
1069
+ // 'matched', v, v?.length, type, schema, schemaIdx, schemaObjects
1070
+ // );
1071
+ if (
1072
+ type === 'promise' ||
1073
+ ('data' in parsed && deepEqual(parsed.data, v))
1074
+ ) {
1075
+ return match;
728
1076
  }
1077
+ fallbackMatch ??= match;
1078
+ } else {
1079
+ structuralMatch ??= match;
729
1080
  }
730
1081
  }
1082
+ if (fallbackMatch) {
1083
+ return fallbackMatch;
1084
+ }
1085
+ if (structuralMatch) {
1086
+ return structuralMatch;
1087
+ }
731
1088
  return {type: typesonType};
732
1089
  },
733
1090
 
@@ -749,34 +1106,26 @@ const schema = {
749
1106
  );
750
1107
  }
751
1108
 
752
- // alert(JSON.stringify(schemaObject));
1109
+ // console.log(JSON.stringify(schemaObject));
753
1110
  const schemaObjects = [...getTypesForSchema(
754
1111
  schemaObject,
755
- /** @type {import('zodex').SzType} */ (schemaOriginal) ?? schemaObject
1112
+ /** @type {import('zodexy').SzType} */ (
1113
+ schemaOriginal
1114
+ ) ?? schemaObject
756
1115
  )];
757
1116
 
758
1117
  // Note: Zod does not support array/object references
759
1118
 
760
- // Todo: implement schema restrictions like tuple on array, record on object
1119
+ // `tuple`/`record` restrictions on `array`/`object` are applied via
1120
+ // `getSchemaType` (type mapping) plus `arrayType.js` reading
1121
+ // `specificSchemaObject.type`, and enforced by `isValueValidationRequired`.
761
1122
  // Todo: Fix `iterate` for schemas (e.g., inject a value method in demo)
762
1123
 
763
- /** @type {AvailableZodexType[]} */
764
- const typeArray = schemaObjects.map(({type}) => {
765
- return type;
766
- });
767
-
768
1124
  return {
769
1125
  schemaObjects,
770
- types: typeArray.map((item, idx) => {
771
- if (item === 'effect') {
772
- return /** @type {import('../types.js').AvailableType} */ (
773
- /** @type {import('zodex').SzEffect} */ (
774
- schemaObjects[idx]
775
- ).effects[0].name
776
- );
777
- }
778
- return /** @type {import('../types.js').AvailableType} */ (
779
- zodexToStructuredCloningTypeMap.get(item)
1126
+ types: schemaObjects.map((schemaItem) => {
1127
+ return /** @type {import('../types.js').AvailableArbitraryType} */ (
1128
+ getSchemaType(schemaItem)
780
1129
  );
781
1130
  })
782
1131
  };