arktype 3.0.0-beta.1 → 3.0.0-rc.0

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 (312) hide show
  1. package/README.md +48 -144
  2. package/out/_internal/regex/charset.d.ts +24 -0
  3. package/out/_internal/regex/escape.d.ts +29 -0
  4. package/out/_internal/regex/execArray.d.ts +24 -0
  5. package/out/_internal/regex/group.d.ts +34 -0
  6. package/out/_internal/regex/index.d.ts +2 -0
  7. package/out/_internal/regex/internal.d.ts +9 -0
  8. package/out/_internal/regex/parse.d.ts +10 -0
  9. package/out/_internal/regex/quantify.d.ts +59 -0
  10. package/out/_internal/regex/regex.d.ts +38 -0
  11. package/out/_internal/regex/state.d.ts +383 -0
  12. package/out/_internal/schema/codecs.d.ts +2 -0
  13. package/out/_internal/schema/config.d.ts +103 -0
  14. package/out/_internal/schema/constraint.d.ts +78 -0
  15. package/out/_internal/schema/errors.d.ts +1 -0
  16. package/out/_internal/schema/generic.d.ts +85 -0
  17. package/out/_internal/schema/i18n.d.ts +3 -0
  18. package/out/_internal/schema/index.d.ts +54 -0
  19. package/out/_internal/schema/internal.d.ts +15 -0
  20. package/out/_internal/schema/intrinsic.d.ts +28 -0
  21. package/out/_internal/schema/kinds.d.ts +76 -0
  22. package/out/_internal/schema/module.d.ts +23 -0
  23. package/out/_internal/schema/mutatesInput.d.ts +2 -0
  24. package/out/_internal/schema/node.d.ts +349 -0
  25. package/out/_internal/schema/parse.d.ts +77 -0
  26. package/out/_internal/schema/parseSchema.d.ts +116 -0
  27. package/out/_internal/schema/predicate.d.ts +46 -0
  28. package/out/_internal/schema/refinements/after.d.ts +32 -0
  29. package/out/_internal/schema/refinements/before.d.ts +32 -0
  30. package/out/_internal/schema/refinements/divisor.d.ts +41 -0
  31. package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
  32. package/out/_internal/schema/refinements/kinds.d.ts +40 -0
  33. package/out/_internal/schema/refinements/max.d.ts +33 -0
  34. package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
  35. package/out/_internal/schema/refinements/min.d.ts +33 -0
  36. package/out/_internal/schema/refinements/minLength.d.ts +32 -0
  37. package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
  38. package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
  39. package/out/_internal/schema/refinements/pattern.d.ts +43 -0
  40. package/out/_internal/schema/refinements/range.d.ts +101 -0
  41. package/out/_internal/schema/roots/alias.d.ts +49 -0
  42. package/out/_internal/schema/roots/basis.d.ts +12 -0
  43. package/out/_internal/schema/roots/domain.d.ts +45 -0
  44. package/out/_internal/schema/roots/intersection.d.ts +72 -0
  45. package/out/_internal/schema/roots/morph.d.ts +59 -0
  46. package/out/_internal/schema/roots/proto.d.ts +42 -0
  47. package/out/_internal/schema/roots/root.d.ts +163 -0
  48. package/out/_internal/schema/roots/union.d.ts +146 -0
  49. package/out/_internal/schema/roots/unit.d.ts +36 -0
  50. package/out/_internal/schema/runtime.d.ts +29 -0
  51. package/out/_internal/schema/runtimeLean.d.ts +2 -0
  52. package/out/_internal/schema/runtimeNone.d.ts +2 -0
  53. package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
  54. package/out/_internal/schema/scope.d.ts +203 -0
  55. package/out/_internal/schema/shared/codecs.d.ts +5 -0
  56. package/out/_internal/schema/shared/compile.d.ts +144 -0
  57. package/out/_internal/schema/shared/configured.d.ts +14 -0
  58. package/out/_internal/schema/shared/declare.d.ts +100 -0
  59. package/out/_internal/schema/shared/disjoint.d.ts +45 -0
  60. package/out/_internal/schema/shared/enWriters.d.ts +30 -0
  61. package/out/_internal/schema/shared/errorModes.d.ts +25 -0
  62. package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
  63. package/out/_internal/schema/shared/errors.d.ts +264 -0
  64. package/out/_internal/schema/shared/implement.d.ts +154 -0
  65. package/out/_internal/schema/shared/inPlace.d.ts +8 -0
  66. package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
  67. package/out/_internal/schema/shared/issues.d.ts +261 -0
  68. package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
  69. package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
  70. package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
  71. package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
  72. package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
  73. package/out/_internal/schema/shared/listed.d.ts +15 -0
  74. package/out/_internal/schema/shared/locale.d.ts +149 -0
  75. package/out/_internal/schema/shared/registry.d.ts +16 -0
  76. package/out/_internal/schema/shared/render.d.ts +3 -0
  77. package/out/_internal/schema/shared/rootApply.d.ts +19 -0
  78. package/out/_internal/schema/shared/sets.d.ts +26 -0
  79. package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
  80. package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
  81. package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
  82. package/out/_internal/schema/shared/transform.d.ts +35 -0
  83. package/out/_internal/schema/shared/traversal.d.ts +288 -0
  84. package/out/_internal/schema/shared/utils.d.ts +59 -0
  85. package/out/_internal/schema/structure/index.d.ts +43 -0
  86. package/out/_internal/schema/structure/optional.d.ts +61 -0
  87. package/out/_internal/schema/structure/prop.d.ts +45 -0
  88. package/out/_internal/schema/structure/required.d.ts +49 -0
  89. package/out/_internal/schema/structure/sequence.d.ts +127 -0
  90. package/out/_internal/schema/structure/shared.d.ts +3 -0
  91. package/out/_internal/schema/structure/structure.d.ts +178 -0
  92. package/out/_internal/schema/units.d.ts +123 -0
  93. package/out/_internal/sets/algebra.d.ts +26 -0
  94. package/out/_internal/sets/constraint.d.ts +19 -0
  95. package/out/_internal/sets/engine.d.ts +2 -0
  96. package/out/_internal/sets/formats.d.ts +23 -0
  97. package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
  98. package/out/_internal/sets/implement.d.ts +16 -0
  99. package/out/_internal/sets/index.d.ts +2 -0
  100. package/out/_internal/sets/internal.d.ts +20 -0
  101. package/out/_internal/sets/intersections.d.ts +5 -0
  102. package/out/_internal/sets/kinds.d.ts +3 -0
  103. package/out/_internal/sets/refinements.d.ts +14 -0
  104. package/out/_internal/sets/roots/alias.d.ts +3 -0
  105. package/out/_internal/sets/roots/domain.d.ts +3 -0
  106. package/out/_internal/sets/roots/intersection.d.ts +4 -0
  107. package/out/_internal/sets/roots/morph.d.ts +4 -0
  108. package/out/_internal/sets/roots/proto.d.ts +3 -0
  109. package/out/_internal/sets/roots/union.d.ts +16 -0
  110. package/out/_internal/sets/roots/unit.d.ts +3 -0
  111. package/out/_internal/sets/structure/index.d.ts +3 -0
  112. package/out/_internal/sets/structure/prop.d.ts +8 -0
  113. package/out/_internal/sets/structure/sequence.d.ts +3 -0
  114. package/out/_internal/sets/structure/structure.d.ts +3 -0
  115. package/out/_internal/sets/toJsonSchema.d.ts +25 -0
  116. package/out/_internal/util/arrays.d.ts +130 -0
  117. package/out/_internal/util/clone.d.ts +4 -0
  118. package/out/_internal/util/describe.d.ts +25 -0
  119. package/out/_internal/util/domain.d.ts +49 -0
  120. package/out/_internal/util/errors.d.ts +29 -0
  121. package/out/_internal/util/facts.d.ts +22 -0
  122. package/out/_internal/util/flatMorph.d.ts +41 -0
  123. package/out/_internal/util/formats.d.ts +8 -0
  124. package/out/_internal/util/functions.d.ts +33 -0
  125. package/out/_internal/util/generics.d.ts +65 -0
  126. package/out/_internal/util/get.d.ts +9 -0
  127. package/out/_internal/util/hkt.d.ts +27 -0
  128. package/out/_internal/util/i18n.d.ts +12 -0
  129. package/out/_internal/util/index.d.ts +28 -0
  130. package/out/_internal/util/internal.d.ts +2 -0
  131. package/out/_internal/util/intersections.d.ts +50 -0
  132. package/out/_internal/util/isomorphic.d.ts +8 -0
  133. package/out/_internal/util/keys.d.ts +18 -0
  134. package/out/_internal/util/lazily.d.ts +7 -0
  135. package/out/_internal/util/numbers.d.ts +82 -0
  136. package/out/_internal/util/objectKinds.d.ts +157 -0
  137. package/out/_internal/util/path.d.ts +16 -0
  138. package/out/_internal/util/primitive.d.ts +16 -0
  139. package/out/_internal/util/records.d.ts +173 -0
  140. package/out/_internal/util/registry.d.ts +13 -0
  141. package/out/_internal/util/scanner.d.ts +110 -0
  142. package/out/_internal/util/serialize.d.ts +40 -0
  143. package/out/_internal/util/strings.d.ts +35 -0
  144. package/out/_internal/util/traits.d.ts +89 -0
  145. package/out/_internal/util/unionToTuple.d.ts +14 -0
  146. package/out/_internal/util/weak.d.ts +8 -0
  147. package/out/attributes.d.ts +15 -11
  148. package/out/checkers.d.ts +1 -1
  149. package/out/chunk-22RQSVV3.js +0 -0
  150. package/out/chunk-3HZC67MT.js +965 -0
  151. package/out/chunk-3KBOPH3J.js +1564 -0
  152. package/out/chunk-3SH2BQ4T.js +15 -0
  153. package/out/chunk-46PLKNON.js +126 -0
  154. package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
  155. package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
  156. package/out/chunk-4NZCLVBD.js +14 -0
  157. package/out/chunk-6FMBO47M.js +7 -0
  158. package/out/chunk-7TALAWYX.js +10 -0
  159. package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
  160. package/out/chunk-BDJVONP7.js +168 -0
  161. package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
  162. package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
  163. package/out/chunk-C3B4IFQL.js +6408 -0
  164. package/out/chunk-CWSF57VM.js +10 -0
  165. package/out/chunk-F5BACUJS.js +7 -0
  166. package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
  167. package/out/chunk-GID3FSQA.js +161 -0
  168. package/out/chunk-I2KLQ2HA.js +22 -0
  169. package/out/chunk-K7SLP5D2.js +84 -0
  170. package/out/chunk-KQPSKGUI.js +9 -0
  171. package/out/chunk-KXOC3JEX.js +8234 -0
  172. package/out/chunk-KXOSUYRA.js +405 -0
  173. package/out/chunk-LHNEY6QW.js +0 -0
  174. package/out/chunk-MTWKGAGO.js +323 -0
  175. package/out/chunk-NU73GNCX.js +170 -0
  176. package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
  177. package/out/chunk-PDLTEX6Z.js +1118 -0
  178. package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
  179. package/out/chunk-R7WXIH5P.js +94 -0
  180. package/out/chunk-TACLEIDM.js +95 -0
  181. package/out/chunk-UJJGG4VQ.js +71 -0
  182. package/out/chunk-US6BWOGJ.js +109 -0
  183. package/out/chunk-VMMMOO4R.js +945 -0
  184. package/out/chunk-VYMXHSFR.js +439 -0
  185. package/out/chunk-W2XOI5DY.js +141 -0
  186. package/out/chunk-WC5L5YRP.js +25 -0
  187. package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
  188. package/out/chunk-XLG66ZDF.js +0 -0
  189. package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
  190. package/out/chunk-ZRYEHGSG.js +79 -0
  191. package/out/cli.d.ts +28 -0
  192. package/out/cli.js +636 -0
  193. package/out/codecs.d.ts +6 -5
  194. package/out/codecs.js +23 -7
  195. package/out/config.d.ts +5 -17
  196. package/out/config.js +11 -2
  197. package/out/declare.d.ts +40 -12
  198. package/out/deferred.d.ts +2 -2
  199. package/out/errors.d.ts +1 -1
  200. package/out/errors.js +10 -2
  201. package/out/fn.d.ts +20 -13
  202. package/out/fromJsonSchema.d.ts +18 -0
  203. package/out/generic.d.ts +9 -6
  204. package/out/i18n.d.ts +2 -2
  205. package/out/i18n.js +9 -2
  206. package/out/index.d.ts +16 -7
  207. package/out/index.js +25 -8
  208. package/out/internal.d.ts +4 -0
  209. package/out/internal.js +41 -17
  210. package/out/island.js +22 -6
  211. package/out/islandDependency.js +42 -18
  212. package/out/jsonSchema/infer.d.ts +805 -0
  213. package/out/jsonSchema/validate.d.ts +416 -0
  214. package/out/keywords/Array.d.ts +2 -2
  215. package/out/keywords/builtins.d.ts +3 -3
  216. package/out/keywords/constructors.d.ts +1 -1
  217. package/out/keywords/functions.d.ts +5 -192
  218. package/out/keywords/keywords.d.ts +3 -3
  219. package/out/keywords/number.d.ts +2 -2
  220. package/out/keywords/phrases.d.ts +4 -191
  221. package/out/keywords/string.d.ts +3 -3
  222. package/out/keywords/ts.d.ts +18 -18
  223. package/out/keywords/ts.js +19 -4
  224. package/out/locale.d.ts +6 -2
  225. package/out/locales/de.js +9 -2
  226. package/out/locales/en.js +21 -5
  227. package/out/match.d.ts +13 -10
  228. package/out/module.d.ts +2 -2
  229. package/out/mutatesInput.js +18 -3
  230. package/out/nary.d.ts +220 -194
  231. package/out/parser/ast/bounds.d.ts +2 -2
  232. package/out/parser/ast/default.d.ts +2 -2
  233. package/out/parser/ast/divisor.d.ts +2 -2
  234. package/out/parser/ast/generic.d.ts +2 -2
  235. package/out/parser/ast/infer.d.ts +1 -1
  236. package/out/parser/ast/keyof.d.ts +2 -2
  237. package/out/parser/ast/utils.d.ts +1 -1
  238. package/out/parser/ast/validate.d.ts +2 -2
  239. package/out/parser/definition.d.ts +4 -4
  240. package/out/parser/objectLiteral.d.ts +2 -2
  241. package/out/parser/property.d.ts +2 -2
  242. package/out/parser/reduce/dynamic.d.ts +2 -2
  243. package/out/parser/reduce/shared.d.ts +1 -1
  244. package/out/parser/reduce/static.d.ts +1 -1
  245. package/out/parser/shift/operand/enclosed.d.ts +2 -2
  246. package/out/parser/shift/operand/genericArgs.d.ts +2 -2
  247. package/out/parser/shift/operand/operand.d.ts +1 -1
  248. package/out/parser/shift/operand/unenclosed.d.ts +2 -2
  249. package/out/parser/shift/operand/unresolvable.d.ts +2 -2
  250. package/out/parser/shift/operator/bounds.d.ts +2 -2
  251. package/out/parser/shift/operator/brand.d.ts +2 -2
  252. package/out/parser/shift/operator/default.d.ts +4 -4
  253. package/out/parser/shift/operator/divisor.d.ts +1 -1
  254. package/out/parser/shift/operator/operator.d.ts +1 -1
  255. package/out/parser/shift/tokens.d.ts +1 -1
  256. package/out/parser/string.d.ts +2 -2
  257. package/out/parser/tupleExpressions.d.ts +6 -8
  258. package/out/parser/tupleLiteral.d.ts +2 -2
  259. package/out/precompiled.d.ts +1 -1
  260. package/out/precompiled.js +16 -2
  261. package/out/regex.d.ts +1 -0
  262. package/out/regex.js +2 -0
  263. package/out/runtime.d.ts +10 -8
  264. package/out/runtime.js +6 -4
  265. package/out/runtimeDevelopment.js +70 -52
  266. package/out/schema.d.ts +1 -0
  267. package/out/schema.js +15 -0
  268. package/out/schemaInternal.d.ts +1 -0
  269. package/out/schemaInternal.js +1401 -0
  270. package/out/schemaIssueFeatures.d.ts +1 -0
  271. package/out/schemaRuntime.d.ts +1 -0
  272. package/out/schemaRuntime.js +7 -0
  273. package/out/schemaRuntimeLean.d.ts +1 -0
  274. package/out/schemaRuntimeLean.js +1870 -0
  275. package/out/schemaRuntimeNone.d.ts +1 -0
  276. package/out/schemaRuntimeNone.js +1774 -0
  277. package/out/schemaRuntimeNoneLean.d.ts +1 -0
  278. package/out/schemaRuntimeNoneLean.js +1767 -0
  279. package/out/scope.d.ts +3 -4
  280. package/out/shared/issueFeatures.d.ts +38 -0
  281. package/out/shared/issueFeatures.js +40 -0
  282. package/out/standalone/artifact.d.ts +6 -6
  283. package/out/standalone/baking.d.ts +2 -2
  284. package/out/standalone/combinators.d.ts +1 -1
  285. package/out/standalone/compilers.d.ts +1 -1
  286. package/out/standalone/fallbacks.d.ts +1 -1
  287. package/out/standalone/keys.d.ts +1 -1
  288. package/out/standalone/sites.d.ts +3 -3
  289. package/out/standalone/units.d.ts +1 -1
  290. package/out/standalone/values.d.ts +1 -1
  291. package/out/type.d.ts +6 -6
  292. package/out/util.d.ts +1 -0
  293. package/out/util.js +137 -0
  294. package/out/variants/array.d.ts +6 -6
  295. package/out/variants/base.d.ts +61 -10
  296. package/out/variants/date.d.ts +5 -5
  297. package/out/variants/instantiate.d.ts +1 -1
  298. package/out/variants/number.d.ts +6 -6
  299. package/out/variants/object.d.ts +25 -12
  300. package/out/variants/string.d.ts +8 -8
  301. package/package.json +183 -8
  302. package/skills/arktype/SKILL.md +93 -93
  303. package/skills/arktype/references/migrating.md +144 -158
  304. package/skills/arktype/references/precompile.md +7 -7
  305. package/out/chunk-4CUA5XIP.js +0 -7
  306. package/out/chunk-GPNK5353.js +0 -2529
  307. package/out/chunk-MLKGABMK.js +0 -9
  308. package/out/chunk-PRTMQCHS.js +0 -3
  309. package/out/chunk-R5G57XC7.js +0 -7
  310. package/out/chunk-SWOOCAHN.js +0 -4
  311. package/out/chunk-TAHPKDNM.js +0 -3
  312. package/out/chunk-UETB6YE2.js +0 -14
@@ -19,7 +19,7 @@ To move a whole project off Zod, or another library below, work through it in th
19
19
  - **Objects.** `.passthrough()` and `z.looseObject()` are `"+": "ignore"`, and `.strict()` is `"+": "reject"`. A union throws a `ParseError` saying it's indeterminate where one of its objects overlaps another branch, like a second object with no literal key to tell them apart, or an array of the same object: write it as [Unions of objects](#unions-of-objects) shows. A `.merge()`, `.pick()`, `.omit()` or `.partial()` goes before the object's `.narrow()`, as in [Composing objects](#composing-objects).
20
20
  - **Optional keys.** Before Zod 4.4, any key whose schema accepts `undefined` may be missing, so a `z.unknown()` key is `"key?": "unknown"` and a `z.any()` key is `"key?": "unknown.any"`; from 4.4, only `.optional()` and defaults let a key be missing, so they stay `key: "unknown"`. Check the version the project installs. In Zod 4, `.default(x).optional()` still fills in `x`, as does `.partial()` on a key with a default, so it's `key: T.default(x)`. In Zod 3 neither does: write the first as `"key?": "T"`, and for the second, call `.partial()` on a Type of the keys without their defaults, and `.merge()` the defaults into the full object. `"unknown.any"` infers `any` as Zod's did, so refinements that read its properties type-check without casts.
21
21
  - **Coercions and refinements,** literally, as in [Coercion is a parse](#coercion-is-a-parse). `z.coerce.number()` takes any input, `null` included, so its input stays `"unknown"`, in a tool's input schema too. Keywords like `string.numeric.parse` reject inputs Zod accepted, like `" 1"`, so suggest them rather than substituting them. A `.refine()` after a `.transform()` is a `.narrow()` after a `.pipe()`: `.to("number > 0")` would also check the type, and `number` rejects `Infinity` and `NaN`. An object's `.refine()` stays on that object as a `.narrow()`, not in a second schema, with its `path` as `relativePath`. A `.refine()` that only rejects a literal, like `z.boolean().refine(v => v, "Accept the terms")`, becomes that literal with a `message`; [Refinements](#refinements) has both.
22
- - **Custom messages,** each as a `message`, as in [Custom messages](#custom-messages): `.min(1, "Name is required")` is `["string >= 1", "@", { message: "Name is required" }]` as a key's value, a value with a message for each of several checks names each check, and a `.refine(fn, "...")` message is `ctx.reject({ message: "..." })`. Never pass a Zod message to `ctx.reject()` as a string, to `ctx.mustBe()`, to `.describe()` or as `expected`, each of which writes `must be` before it.
22
+ - **Custom messages,** each as a `message`, as in [Custom messages](#custom-messages): a message beside a check goes beside the same check, so `.min(1, "Name is required")` is `type.string.atLeastLength(1, "Name is required")`, a check without a method, like `.email("...")`'s, names its code, as in `.message("...", "pattern")`, and a `.refine(fn, "...")` message is `ctx.reject({ message: "..." })`. Never pass a Zod message to `ctx.mustBe()`, to `ctx.error()` as a string, to `.describe()` or as `expected`, each of which writes `must be` before it.
23
23
  - **Descriptions.** A `.describe(text)` on a schema given to a model or an OpenAPI generator, like a tool's `inputSchema`, stays one, as [Descriptions](#descriptions) shows, so the JSON Schema they read keeps it. Anywhere else it's a comment.
24
24
  - **Strings.** Zod 4's `.url()` accepts what `URL.canParse` accepts and returns the string trimmed, and by 4.6 without the tabs and line breaks inside it, which 4.1 kept. `string.url` checks with `URL.canParse` too but returns the string as given, so where the output is kept, write `type("string").pipe(s => s.trim().replace(/[\t\n\r]/g, "")).to("string.url")`. From Zod 4.5, `.min()`, `.max()` and `.length()` count code points, so an emoji counts once, where ArkType's bounds count UTF-16 code units, as `.length` does: where text may hold such characters, check the count in a `.narrow()`, as in [Defaults that differ](#defaults-that-differ). `string.email` and Zod 4's `z.email()` disagree on some addresses: Zod rejects `a..b@x.co` and `.a@x.co` and accepts `a'b@x.co`, and ArkType does the opposite. Where that matters, keep Zod's pattern as a regex.
25
25
  - **Arrays as objects.** `z.object()` and `z.record()` reject an array, which ArkType accepts as a `Record`, or as an object whose declared keys are all optional. Where every key is optional, reject arrays with a `.narrow()`, as in [Defaults that differ](#defaults-that-differ).
@@ -114,7 +114,7 @@ const argsSchema = {
114
114
  6. **Compare with the originals while Zod is still installed.** The project's tests check the schemas they use. Check the rest directly, and every schema if there's no `test` script: in a scratch file, import each original from a copy of its file (`git show HEAD:src/schemas.ts > scratch/schemas.zod.ts`) and its conversion, call both on the same inputs and compare which they accept and what they return. Use the project's fixtures or sample data where it has them, plus each case [Defaults that differ](#defaults-that-differ) lists: a missing key, a key present as `undefined`, an undeclared key, a wrong type, an array in place of an object, an empty string and a value at each bound. Fix each difference in the schema, then delete the scratch files. [How to convert](#how-to-convert) shows a check that their types match too.
115
115
  7. **Swap dependencies.** Remove `zod` and the packages that existed only for it, and add their replacements, with the project's package manager, like `pnpm remove zod` or `npm uninstall zod`. Editing `package.json` by hand leaves the lockfile stale, and some package managers then refuse to run scripts. If `arktype` is already a dependency, keep that version. Don't upgrade another dependency to a new major version, like the MCP SDK to v2, so it takes ArkType; keep Zod for it as the table says. If a dependency requires `zod` as a peer dependency, keep it installed for that dependency and say so.
116
116
  8. **Verify.** Run the `typecheck` and `test` scripts in `package.json` until both pass; `npx tsc` alone can miss a second tsconfig. Run the `build` script too, if there is one. If Jest fails with `Must use import to load ES Module`, naming arktype, [have it transform arktype's packages](https://arktype.io/docs/faq#why-does-jest-say-must-use-import-to-load-es-module), which ship ES modules only. If there's no `test` script, step 6's comparison is the behavior check, so say what it covered. Search again for imports of the old library, and check that every file importing `arktype`, `.js` files included, imports the config first if it creates a Type. Change a test only where it asserts the old library itself, like a Zod error message, an issue `code` or `instanceof ZodError`. Never delete a test, weaken an assertion or change an expected value to match new output. The exception is a snapshot of generated JSON Schema, which ArkType writes in a canonical order: required keys, then optional ones, each sorted, and enum and union members sorted. Reorder such a snapshot only when order is its only difference.
117
- 9. **Precompile, if asked.** Set it up as the skill's `references/precompile.md`, or [Precompile setup](https://arktype.io/docs/precompile/setup), says: add `@ark/aot` and the plugin for the bundler, name the config file from step 2 as `config` in `ark.json`, run `npx arktype-precompile --check src` until it accepts every definition, then run the `typecheck`, `test` and `build` scripts again. A library others install doesn't precompile itself: it publishes what `tsc` emits and [opts in](https://arktype.io/docs/precompile/advanced#libraries), so each app's build precompiles it. With `drizzle-arktype`, see [Precompile](#precompile) below.
117
+ 9. **Precompile, if asked.** Set it up as the skill's `references/precompile.md`, or [Precompile setup](https://arktype.io/docs/precompile/setup), says: add `@ark/aot` and the plugin for the bundler, name the config file from step 2 as `config` in `ark.json`, run `npx @ark/aot --check src` until it accepts every definition, then run the `typecheck`, `test` and `build` scripts again. A library others install doesn't precompile itself: it publishes what `tsc` emits and [opts in](https://arktype.io/docs/precompile/advanced#libraries), so each app's build precompiles it. With `drizzle-arktype`, see [Precompile](#precompile) below.
118
118
  10. **Report** what still behaves differently, if anything, such as error message text, any snapshot you reordered, and any dependency you kept Zod for. Where the code ships to a browser and wasn't precompiled, say that arktype's parser now ships with it, which [precompiling](#precompile) removes.
119
119
 
120
120
  ## Zod side by side
@@ -145,9 +145,9 @@ import "./arktype.config.ts"
145
145
  import { type } from "arktype"
146
146
 
147
147
  const User = type({
148
- name: ["string >= 1", "@", { message: "Name is required" }],
148
+ name: type.string.atLeastLength(1, "Name is required"),
149
149
  email: "string.email",
150
- "age?": "number.integer >= 0",
150
+ "age?": "0 <= number.integer <= 9007199254740991",
151
151
  role: "'admin' | 'member' = 'member'"
152
152
  })
153
153
 
@@ -172,7 +172,7 @@ configure({
172
172
  })
173
173
  ```
174
174
 
175
- Import it before anything creates a Type. To convert one schema without it, say both in the definition: `"+": "delete"` in each object, and `"age?": "number.integer >= 0 | undefined"`. [Defaults that differ](#defaults-that-differ) has every default to check, for each library.
175
+ Import it before anything creates a Type. To convert one schema without it, say both in the definition: `"+": "delete"` in each object, `"age?": "0 <= number.integer <= 9007199254740991 | undefined"`, and write `role`'s default as [Defaults that differ](#defaults-that-differ) does, so `undefined` gets it too. [Defaults that differ](#defaults-that-differ) has every default to check, for each library.
176
176
 
177
177
  ## Zod
178
178
 
@@ -240,11 +240,11 @@ Zod Mini spells most methods as functions, so `z.optional(z.string())` maps like
240
240
  | `.extend({ ... })`, `.safeExtend({ ... })`, `.merge(B)` | `.merge({ ... })`, `.merge(B)` |
241
241
  | `.pick({ a: true })`, `.omit({ a: true })` | `.pick("a")`, `.omit("a")` |
242
242
  | `.partial()`, `.required()`, `.keyof()` | same names |
243
- | `.required()` on keys that were optional or defaulted | `.merge()` them in without `?`: its keys still take `undefined` once configured, and lose defaults |
243
+ | `.required()` on a key with a default | `.required()`, which rejects `undefined` there where Zod's still fills in the default |
244
244
  | `.deepPartial()` (Zod 3), `z.deepPartial(T)` | no equivalent: call `.partial()` on each nested object's Type |
245
245
  | any of those on a schema with a `.refine()` | on the object before its `.narrow()`, see [Composing objects](#composing-objects) |
246
246
  | `T.shape.a`, `Object.keys(T.shape)` | `T.get("a")`, `T.props.map(prop => prop.key)` |
247
- | `z.object({ a: T.shape.a, b: B })`, to reuse a key | `T.pick("a").merge({ b: B })`: `T.get("a")` is `a`'s Type without its `?` or default |
247
+ | `z.object({ a: T.shape.a, b: B })`, to reuse a key | `T.pick("a").merge({ b: B })`: `T.get("a")` drops `?` and defaults, adding `\| undefined` |
248
248
  | `.strict()`, `z.strictObject` | `"+": "reject"` in the object, or `T.onUndeclaredKey("reject")` |
249
249
  | `.passthrough()`, `.loose()`, `z.looseObject` | `"+": "ignore"` in the object, or `T.onUndeclaredKey("ignore")` |
250
250
  | the same, where code reads the extra keys | `"[string]": "unknown"` beside it, which infers the index signature Zod's type had |
@@ -290,7 +290,7 @@ Zod Mini spells most methods as functions, so `z.optional(z.string())` maps like
290
290
  | `z.coerce.number()`, `z.coerce.date()` | `type("unknown").pipe(Number).to("number")`, see [Coercion](#coercion-is-a-parse) |
291
291
  | `z.coerce.string()`, `z.coerce.boolean()` | `type("unknown").pipe(String)`, `type("unknown").pipe(Boolean)` |
292
292
  | `z.stringbool()` | a `.pipe()` over the strings you accept, see [Coercion](#coercion-is-a-parse) |
293
- | `z.custom<T>(fn)`, `z.custom<T>(fn, "Message")` | `type("unknown").narrow((v): v is T => fn(v))`, then `.configure({ message: "Message" })` |
293
+ | `z.custom<T>(fn)`, `z.custom<T>(fn, "Message")` | `type("unknown").narrow((v): v is T => fn(v))`, then `.message("Message")` |
294
294
  | `.brand<"Id">()` | `.brand("Id")` or `"string#Id"` |
295
295
  | `z.codec(In, Out, { decode, encode })` | `codec(In, Out, { decode, encode })` from `arktype/codecs` |
296
296
  | `T.decode(x)`, `T.encode(x)`, `T.safeEncode(x)` | `T.assert(x)`, `T.encode.assert(x)`, `T.encode(x)` |
@@ -303,11 +303,11 @@ Every row is in [Custom messages](#custom-messages), with what each says.
303
303
 
304
304
  | Zod | ArkType |
305
305
  | -------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
306
- | `.min(1, "Name is required")`, `{ message }` | `["string >= 1", "@", { message: "Name is required" }]` as a key's value |
307
- | the same, on a Type | `type("string >= 1").configure({ message: "Name is required" })` |
308
- | `.min(8, "Too short").regex(r, "Add a number")` | `.configure({ message: "Too short" }, "minLength")`, then the same for `"pattern"` |
309
- | `z.string({ error: "Enter a name" })` | `["string", "@", { message: "Enter a name" }]`, which a missing key says too |
310
- | `required_error`, `invalid_type_error` (Zod 3) | `.configure({ message }, "self")`, `.configure({ message }, "domain")` |
306
+ | `.min(1, "Name is required")`, `{ message }` | `type.string.atLeastLength(1, "Name is required")` |
307
+ | `.max(50, m)`, `.regex(r, m)`, `.gt(0, m)` | `.atMostLength(50, m)`, `.matching(r, m)`, `.moreThan(0, m)` |
308
+ | `.email("Enter a valid email")` | `type("string.email").message("Enter a valid email", "pattern")` |
309
+ | `z.string({ error: "Enter a name" })` | `type("string").message("Enter a name")`, which a missing key says too |
310
+ | `required_error`, `invalid_type_error` (Zod 3) | `.message(m, "self")`, `.message(m, "domain")` |
311
311
  | `.refine(fn, "Message")` | `ctx.reject({ message: "Message" })` |
312
312
  | `error: issue => ...`, `z.config({ customError })` | `message: error => ...`, or [by code](https://arktype.io/docs/configuration#by-code) in `configure` |
313
313
  | `errorMap`, `z.setErrorMap(fn)` (Zod 3) | the same: `message: error => ...` on the Type, or by code in `configure` |
@@ -380,33 +380,33 @@ A [precompiled](https://arktype.io/docs/precompile) build takes a function for t
380
380
 
381
381
  ### Less common
382
382
 
383
- | Zod | ArkType |
384
- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
385
- | `z.hex()`, `z.base64url()`, `z.uuidv4()` | `"string.hex"`, `"string.base64.url"`, `"string.uuid.v4"` |
386
- | `z.nanoid()`, `z.ulid()`, `z.cuid2()`, `z.e164()`, `z.guid()` | no keyword: a regex, like the one Zod exports as `z.regexes.ulid` |
387
- | `z.iso.time()`, `z.iso.duration()` | the same, from `z.regexes.time({})` and `z.regexes.duration` |
388
- | `z.hostname()`, `z.cidrv4()`, `z.cidrv6()` | the same, from `z.regexes.hostname`, `z.regexes.cidrv4` and `z.regexes.cidrv6` |
389
- | `z.httpUrl()` | `type("string.url").and(/^https?:\/\//i)` |
390
- | `.lowercase()`, `.uppercase()`, `.normalize()` | `"string.lower.preformatted"`, `"string.upper.preformatted"`, `"string.normalize"` |
391
- | `z.templateLiteral(["user-", z.number()])` | a regex, like `/^user-\d+$/` |
392
- | `z.int32()`, `z.uint32()` | `"-2147483648 <= number.integer <= 2147483647"`, `"0 <= number.integer <= 4294967295"` |
393
- | `z.nan()` | `"number.NaN"` |
394
- | `z.bigint().min(5n)` | `"bigint"` with a `.narrow()` |
395
- | `z.file()`, with `.max(n)` or `.mime(type)` | `"File"`, with a `.narrow()` on its `size` and `type` |
396
- | `z.promise(T)`, `z.function()` | `"Promise"`, `"Function"` |
397
- | `z.xor([A, B])` | a `.pipe()` that calls both and rejects unless one passes |
398
- | `.prefault(x)` | `.default(x)`, which is an input as `.prefault()`'s is |
399
- | `.overwrite(fn)` | `.pipe(fn)` |
400
- | `.nonoptional()` | the key without its `?` |
401
- | `.unwrap()` on a nullable or optional schema | `T.exclude("null")`, `T.exclude("undefined")` |
402
- | `T.element` on an array, `T.valueType` on a record | keep that Type in a `const`: `T.get(0)` and `T.get("key")` add `undefined` to it |
403
- | `.isOptional()`, `.isNullable()` | `T.allows(undefined)`, `T.allows(null)` |
404
- | `T.options`, `T.enum.a` on a `z.enum` | `T.select("unit").map(u => u.unit)`, or keep the values in an `as const` array of your own |
405
- | `schema instanceof z.ZodObject` | `T.extends("object")` |
406
- | `.meta({ title, examples })`, a registry | `.configure({ title, examples })`, read back from `T.meta` |
407
- | `z.config(z.locales.de())` | `configure({ locale: de })`, see [i18n](https://arktype.io/docs/i18n); only `en` and `de` ship |
408
- | `zfd.formData({ ... })` from `zod-form-data` | `type("FormData.parse").to({ ... })`, see [Form data](#form-data) |
409
- | `z.fromJSONSchema(schema)` | `jsonSchemaToType(schema)` from [`@ark/json-schema`](https://arktype.io/docs/json-schema/from-json-schema) |
383
+ | Zod | ArkType |
384
+ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
385
+ | `z.hex()`, `z.base64url()`, `z.uuidv4()` | `"string.hex"`, `"string.base64.url"`, `"string.uuid.v4"` |
386
+ | `z.nanoid()`, `z.ulid()`, `z.cuid2()`, `z.e164()`, `z.guid()` | no keyword: a regex, like the one Zod exports as `z.regexes.ulid` |
387
+ | `z.iso.time()`, `z.iso.duration()` | the same, from `z.regexes.time({})` and `z.regexes.duration` |
388
+ | `z.hostname()`, `z.cidrv4()`, `z.cidrv6()` | the same, from `z.regexes.hostname`, `z.regexes.cidrv4` and `z.regexes.cidrv6` |
389
+ | `z.httpUrl()` | `type("string.url").and(/^https?:\/\//i)` |
390
+ | `.lowercase()`, `.uppercase()`, `.normalize()` | `"string.lower.preformatted"`, `"string.upper.preformatted"`, `"string.normalize"` |
391
+ | `z.templateLiteral(["user-", z.number()])` | a regex, like `/^user-\d+$/` |
392
+ | `z.int32()`, `z.uint32()` | `"-2147483648 <= number.integer <= 2147483647"`, `"0 <= number.integer <= 4294967295"` |
393
+ | `z.nan()` | `"number.NaN"` |
394
+ | `z.bigint().min(5n)` | `"bigint"` with a `.narrow()` |
395
+ | `z.file()`, with `.max(n)` or `.mime(type)` | `"File"`, with a `.narrow()` on its `size` and `type` |
396
+ | `z.promise(T)`, `z.function()` | `"Promise"`, `"Function"` |
397
+ | `z.xor([A, B])` | a `.pipe()` that calls both and rejects unless one passes |
398
+ | `.prefault(x)` | `.default(x)`, which is an input as `.prefault()`'s is |
399
+ | `.overwrite(fn)` | `.pipe(fn)` |
400
+ | `.nonoptional()` | the key without its `?` |
401
+ | `.unwrap()` on a nullable or optional schema | `T.exclude("null")`, `T.exclude("undefined")` |
402
+ | `T.element` on an array, `T.valueType` on a record | keep that Type in a `const`: `T.get(0)` and `T.get("key")` add `undefined` to it |
403
+ | `.isOptional()`, `.isNullable()` | `T.allows(undefined)`, `T.allows(null)` |
404
+ | `T.options`, `T.enum.a` on a `z.enum` | `T.select("unit").map(u => u.unit)`, or keep the values in an `as const` array of your own |
405
+ | `schema instanceof z.ZodObject` | `T.extends("object")` |
406
+ | `.meta({ title, examples })`, a registry | `.configure({ title, examples })`, read back from `T.meta` |
407
+ | `z.config(z.locales.de())` | `configure({ locale: de })`, see [i18n](https://arktype.io/docs/i18n); only `en` and `de` ship |
408
+ | `zfd.formData({ ... })` from `zod-form-data` | `type("FormData.parse").to({ ... })`, see [Form data](#form-data) |
409
+ | `z.fromJSONSchema(schema)` | [`fromJsonSchema(schema)`](https://arktype.io/docs/json-schema/from-json-schema) |
410
410
 
411
411
  ## Defaults that differ
412
412
 
@@ -536,7 +536,7 @@ const Flag = type("'true' | 'false'").pipe(s => s === "true")
536
536
  ```
537
537
 
538
538
  - A default is an input, so a transform's default is what it parses, as Zod's `.prefault()` is: `z.stringbool().default(false)` is `Flag.default("false")`.
539
- - `unknown` includes `undefined`, so a coercion at an optional or defaulted key is handed a key that's present as `undefined`, as `process.env`'s may be, where Zod's `.optional()` and `.default()` answer first. Return it or the default from the pipe, as `Server` does: `z.coerce.number().optional()` is `"limit?": type("unknown").pipe(v => (v === undefined ? v : Number(v))).to("number | undefined")`.
539
+ - `unknown` includes `undefined`, so a coercion at an optional key, or at a defaulted one without `exactOptionalPropertyTypes: false`, is handed a key that's present as `undefined`, as `process.env`'s may be, where Zod's `.optional()` and `.default()` answer first. Return it or the default from the pipe, as `Server` does: `z.coerce.number().optional()` is `"limit?": type("unknown").pipe(v => (v === undefined ? v : Number(v))).to("number | undefined")`.
540
540
 
541
541
  ### Form data
542
542
 
@@ -598,13 +598,14 @@ const Order = type({ quantity: "number", price: "number" }).narrow((d, ctx) => {
598
598
 
599
599
  ### Custom messages
600
600
 
601
- A custom Zod message becomes a `message`: one whole sentence, shown as you wrote it. An issue's `message` holds it without its path, as Zod's `issue.message` did, and `summary` and a thrown `TraversalError` write the path and a colon before it:
601
+ A custom Zod message becomes a `message`: one whole sentence, shown as you wrote it. A message Zod takes beside a check, as `.min()`, `.max()`, `.regex()`, `.gt()` or `.multipleOf()` do, goes beside the same check, as the last argument to `.atLeastLength()`, `.atMostLength()`, `.matching()`, `.moreThan()` or `.divisibleBy()`. As in Zod, only that check says it, so a value of the wrong type or a missing key says ArkType's own text, like `must be a string`:
602
602
 
603
603
  ```ts
604
- // Zod: z.object({ name: z.string().min(1, "Name is required") })
604
+ // Zod: z.object({ name: z.string().min(1, "Name is required").max(50, "Name is too long") })
605
605
  const Named = type({
606
- // or type("string >= 1").configure({ message: "Name is required" })
607
- name: ["string >= 1", "@", { message: "Name is required" }]
606
+ name: type.string
607
+ .atLeastLength(1, "Name is required")
608
+ .atMostLength(50, "Name is too long")
608
609
  })
609
610
 
610
611
  const out = Named({ name: "" })
@@ -617,42 +618,31 @@ if (out instanceof type.errors) {
617
618
  }
618
619
  ```
619
620
 
620
- A library reading the Type through [Standard Schema](https://arktype.io/docs/standard-schema), like TanStack Form, react-hook-form's `standardSchemaResolver` or tRPC, gets the same `message` on each issue, beside its `path`.
621
+ An issue's `message` holds it without its path, as Zod's `issue.message` did, and `summary` and a thrown `TraversalError` write the path and a colon before it. A library reading the Type through [Standard Schema](https://arktype.io/docs/standard-schema), like TanStack Form, react-hook-form's `standardSchemaResolver` or tRPC, gets the same `message` on each issue, beside its `path`.
621
622
 
622
- - **Only `message` takes a sentence.** `ctx.reject("a valid zip code")`, `ctx.mustBe("a valid zip code")`, `.describe("a valid zip code")`, `expected` and a string after `"@"` each take what the value must be, so they read `must be a valid zip code`. A Zod message passed to one reads `must be Enter a valid zip code`.
623
- - **It covers the whole value.** A string `message` is written for any value the Type rejects, of the wrong type included, and for a key that's absent: `Named({})` also says `Name is required`. Configure the key's whole value, last, after any `.pipe()` or `.to()`.
623
+ - **Only `message` takes a sentence.** `ctx.mustBe("a valid zip code")`, `ctx.error("a valid zip code")`, `.describe("a valid zip code")`, `expected` and a string after `"@"` each take what the value must be, so they read `must be a valid zip code`. A Zod message passed to one reads `must be Enter a valid zip code`. `ctx.reject()` takes no string, so a `.refine()` message is `ctx.reject({ message })`.
624
+ - **`.message()` covers the whole value.** Like Zod's `z.string({ error })`, `type("string").message("Enter a name")` is said for any value the Type rejects, of the wrong type included, and for a key that's absent. Configure it last, after any `.pipe()` or `.to()`. It replaces the messages of the constraints before it, so beside those, give a wrong type and a missing key theirs [by code](#a-check-without-a-method-takes-its-code).
624
625
  - **With `| null` or `| undefined`, configure the union.** `["string.email | null", "@", { message }]` says the message for any value it rejects. A message on one branch, as in `Email.configure({ message }).or("null")`, is lost for a value of the wrong type, which reads `must be a string or null`. With `exactOptionalPropertyTypes: false`, an optional or defaulted key's value is such a union, so where the message must cover the wrong type too, as a Zod `z.string({ error })` does, write `undefined` into it: `"email?": ["string.email | undefined", "@", { message }]`. Always write a boolean's, a literal's or an enum's message on the union, as in `"role?": ["'admin' | 'user' | undefined", "@", { message }]`: a wrong value is their only error, so a message on `Role` alone is never said beside `null` or `undefined`.
625
626
  - **A parse keyword's own failure keeps its text.** A `message` on `string.date.parse`, `string.url.parse` or `string.json.parse` is said for a value that isn't a string, but a string that doesn't parse still reads `must be a parsable date`. Check the string, then convert it: `type("string.date").pipe(s => new Date(s)).configure({ message })`, or `"string.url"` with `new URL(s)`. For JSON, call `JSON.parse` in a `.pipe()` and report its failure with `ctx.error({ message })`.
626
- - **For a message per check, name the check.** A second argument to `.configure()`, or a fourth element of the `"@"` tuple, is the [code](https://arktype.io/docs/errors#error-codes) of the errors the message is for, like `minLength`, `pattern`, `min` or `divisor`:
627
627
 
628
- ```ts
629
- // Zod: z.string().min(8, "Use 8 or more characters").regex(/[0-9]/, "Include a number")
630
- const Password = type("string >= 8 & /[0-9]/")
631
- .configure({ message: "Use 8 or more characters" }, "minLength")
632
- .configure({ message: "Include a number" }, "pattern")
633
-
634
- const Account = type({
635
- // only an empty name says it, as in Zod
636
- name: ["string >= 1", "@", { message: "Name is required" }, "minLength"],
637
- password: Password
638
- })
639
- ```
628
+ #### A check without a method takes its code
640
629
 
641
- A value of the wrong type, or a missing key, then says ArkType's own text, like `must be a string`, as it said Zod's. To give those their own messages, as Zod 3's `required_error` and `invalid_type_error` do, name `"self"` for a missing key and `"domain"` for a value of the wrong type:
630
+ A keyword's check, like `string.email`'s pattern, or one written in a string definition, has no method to pass a message to. Pass `.message()` its [code](https://arktype.io/docs/errors#error-codes), like `minLength`, `pattern`, `min` or `divisor`, as a second argument, or as a fourth element of the `"@"` tuple. `"self"` names a missing key and `"domain"` a value of the wrong type, as Zod 3's `required_error` and `invalid_type_error` do:
642
631
 
643
632
  ```ts
633
+ // Zod: z.string().email("Enter a valid email")
634
+ const Email = type("string.email").message("Enter a valid email", "pattern")
635
+
644
636
  // Zod 3: z.string({ required_error: "SKU is required", invalid_type_error: "SKU must be text" })
645
637
  // .regex(/^[A-Z]{3}-\d{4}$/, "SKU looks like ABC-1234")
646
- const Sku = type(/^[A-Z]{3}-\d{4}$/)
647
- .configure({ message: "SKU is required" }, "self")
648
- .configure({ message: "SKU must be text" }, "domain")
649
- .configure({ message: "SKU looks like ABC-1234" }, "pattern")
638
+ const Sku = type.string
639
+ .matching(/^[A-Z]{3}-\d{4}$/, "SKU looks like ABC-1234")
640
+ .message("SKU is required", "self")
641
+ .message("SKU must be text", "domain")
650
642
  ```
651
643
 
652
644
  - Zod says `required_error` for a key given `undefined` too, which here is a value of the wrong type. To keep that, write `"domain"`'s message as `error => (error.data === undefined ? "SKU is required" : "SKU must be text")`.
653
- - A code names every check of that kind in the Type, a nested key's included, so configure a key's value rather than the object around it.
654
- - A `message` configured without a code replaces those configured before it, so configure the whole value first and its checks after.
655
- - Two checks with one code share its message, like two patterns, or an array's length and its elements', which are both `minLength`. Configure each as its own Type and intersect them: `HasDigit.and(HasCapital)`, or `Tags` below.
645
+ - A code names every check of that kind in the Type, a nested key's included, so configure a key's value rather than the object around it. A message passed to a constraint's method is that constraint's alone, so two checks of one kind, like two patterns, or an array's length and its elements', each keep their own, as in `Tags` below.
656
646
  - A function, like Zod 4's `error: issue => ...`, receives the error: `error.data` is Zod's `issue.input`, and once `error.code === "min"` is checked, `error.rule` is its `issue.minimum`. A missing key doesn't say a function's message, so give `"self"` a string.
657
647
  - After a `.pipe()` or `.to()`, a code doesn't reach the Type the output is checked with, so configure that Type before passing it to `.to()`. A message for the whole value, or for `"self"`, on the transformed Type replaces the ones inside it, so use one there only where a single message is enough.
658
648
 
@@ -663,33 +653,30 @@ When several checks fail at once, ArkType reports a pattern before a length, whi
663
653
 
664
654
  ```ts
665
655
  // Zod: z.string().min(1, "Email is required").email("Enter a valid email")
666
- const Email = type("string.email").configure(
667
- {
668
- message: error =>
669
- error.data === "" ? "Email is required" : "Enter a valid email"
670
- },
656
+ const Email = type("string.email").message(
657
+ error => (error.data === "" ? "Email is required" : "Enter a valid email"),
671
658
  "pattern"
672
659
  )
673
660
 
674
661
  // Zod: z.string().min(8, "Use 8 or more characters").regex(/[0-9]/, "Include a number")
675
- const Password = type("string >= 8")
676
- .configure({ message: "Use 8 or more characters" }, "minLength")
662
+ const Password = type.string
663
+ .atLeastLength(8, "Use 8 or more characters")
677
664
  .narrow(
678
665
  (s, ctx) => /[0-9]/.test(s) || ctx.reject({ message: "Include a number" })
679
666
  )
680
667
 
681
668
  // Zod: z.string().trim().min(1, "Name is required").max(50, "Name is too long")
682
669
  const Name = type("string.trim").to(
683
- type("0 < string <= 50")
684
- .configure({ message: "Name is required" }, "minLength")
685
- .configure({ message: "Name is too long" }, "maxLength")
670
+ type.string
671
+ .atLeastLength(1, "Name is required")
672
+ .atMostLength(50, "Name is too long")
686
673
  )
687
674
 
688
675
  // Zod: z.array(z.string().min(1, "Tag can't be empty")).min(1, "Add at least one tag")
689
- const Tag = type("string >= 1").configure({ message: "Tag can't be empty" })
690
- const Tags = type("unknown[] >= 1")
691
- .configure({ message: "Add at least one tag" }, "minLength")
692
- .and(Tag.array())
676
+ const Tags = type.string
677
+ .atLeastLength(1, "Tag can't be empty")
678
+ .array()
679
+ .atLeastLength(1, "Add at least one tag")
693
680
  ```
694
681
 
695
682
  Through react-hook-form's resolvers, these four show the same message for each field as their Zod originals.
@@ -782,13 +769,13 @@ const types = scope({
782
769
 
783
770
  Inside a scope, `type()` can't see the scope's names, so write a refinement or a transform there as a tuple: `["Post[]", ":", (posts, ctx) => ...]` for a `.narrow()`, `["string", "=>", s => s.trim()]` for a `.pipe()`.
784
771
 
785
- Delete the hand-written TypeScript type that `z.lazy` needed; `typeof Category.infer` and `typeof types.Post.infer` replace it. Where the module's declarations are emitted, as for a published package or a TypeScript project reference, `tsc` can't write the cycle in a `.d.ts`, so emit them with [`arktype-precompile --declare`](https://arktype.io/docs/precompile/advanced#cyclic-types), or keep the type and [declare the Type with it](https://arktype.io/docs/scopes#cyclic-types), `type.declare<Category>().type({ ... })`. For JSON data, use the `object.json` keyword rather than a recursive type of your own: `z.json()` is `"string | number | boolean | null | object.json"`.
772
+ Delete the hand-written TypeScript type that `z.lazy` needed; `typeof Category.infer` and `typeof types.Post.infer` replace it. Where the module's declarations are emitted, as for a published package or a TypeScript project reference, `tsc` can't write the cycle in a `.d.ts`, so emit them with [`arktype-precompile --declare`](https://arktype.io/docs/precompile/advanced#cyclic-types), or keep the type and [declare the Type with it](https://arktype.io/docs/scopes#cyclic-types), `type.declare<Category>().type({ ... })`. For JSON data, use the `object.json` keyword rather than a recursive type of your own: `z.json()` is `"string | number | boolean | null | object.json"`. Define recursive Types once, at module scope, since each stays in memory for the life of the process.
786
773
 
787
774
  ### Composing objects
788
775
 
789
776
  `.merge()` replaces keys like Zod's `.extend()` or `v.object({ ...a.entries })`. `.and()` intersects, like `Type.Composite`, and throws when a key's types conflict. `.pick()` and `.omit()` take key names, as in `.pick("name", "email")`. Like Zod's, they and `.partial()` keep an object's `"+"`, so a `.strict()` object's are strict too, where `.merge()` takes `"+"` from the object merged in.
790
777
 
791
- A `.narrow()` on an object doesn't survive them. `.merge()`, a `"..."` spread, `.pick()`, `.omit()` and `.partial()` take the object's keys and leave its narrow behind, so a refinement Zod's `.extend()` kept no longer runs. Where the object also deletes undeclared keys, they throw instead: `merge operand must be an object (was (In: { ... }) => To<...>)`. Either way, keep the keys in a Type of their own, derive from that, and add the narrow last:
778
+ A `.narrow()` on an object doesn't survive them. `.merge()`, a `"..."` spread, `.pick()`, `.omit()` and `.partial()` take the object's keys and leave its narrow behind, so a refinement Zod's `.extend()` kept no longer runs. Where the object also transforms its input — deletes undeclared keys, or has a default or morph at a key — they throw instead: `merge operand must be an object (was (In: { ... }) => To<...>)`. Either way, keep the keys in a Type of their own, derive from that, and add the narrow last:
792
779
 
793
780
  ```ts
794
781
  import { type, type Traversal } from "arktype"
@@ -880,7 +867,7 @@ To keep each check's own error, like `limit must be at most 50`, describe the va
880
867
 
881
868
  Where nothing reads the JSON Schema, keep the text in a comment, or in `.configure({ title: text })`, which errors don't say and JSON Schema writes as `title`.
882
869
 
883
- A string `message` or `expected` configured on a whole value is written into the JSON Schema too, as a keyword of that name, so a model provider is sent it and a strict validator like Ajv rejects the schema. A message for one check, like `.configure({ message }, "minLength")`, isn't written, and neither is a function.
870
+ A `message`, `expected` or `actual` isn't written into the JSON Schema, so a model provider is sent only what `.describe()` says.
884
871
 
885
872
  ### OpenAPI documents
886
873
 
@@ -925,7 +912,9 @@ const parameters = (object: JsonSchema, where: "query" | "path") => {
925
912
  }
926
913
  ```
927
914
 
928
- With `onUndeclaredKey: "delete"`, each object's schema says `additionalProperties: false`, which zod-to-openapi left out, and `.in` and `.out` write a registered schema in full where `toJsonSchema()` writes its `$ref`.
915
+ With `onUndeclaredKey: "delete"`, `toJsonSchema()` writes what an object accepts, so without `additionalProperties: false`, which `.out.toJsonSchema()` writes. `.in` and `.out` write a registered schema in full where `toJsonSchema()` writes its `$ref`.
916
+
917
+ Where you call `toJsonSchema` yourself, a scope can be the registry instead: with [`aliasDefs: true`](https://arktype.io/docs/json-schema/to-json-schema#named-aliases), each alias is written once, by name, and a `$ref` wherever it's used, and a [`defs` fallback](https://arktype.io/docs/json-schema/to-json-schema#openapi-30) collects them into `components`.
929
918
 
930
919
  Call `toJsonSchema(openapi)` on each Type by name, as above, rather than in a function that takes any Type. A [precompiled](https://arktype.io/docs/precompile) build can't tell which Types such a function converts, and where objects delete undeclared keys, its call throws for a Type holding a `$ref`.
931
920
 
@@ -952,9 +941,9 @@ Zod 3, and Zod 4 before 4.5, also take `2025-01-01T10:00Z`, so write the seconds
952
941
 
953
942
  Valibot's `v.isoDate()` is `Day` and `v.isoTimestamp()` is `Zoned`. Its `v.isoDateTime()` takes only minutes and no offset, like `2025-01-01T10:00`, so its pattern is `/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/`.
954
943
 
955
- `string.date.iso` checks the format, not the calendar, so `2020-02-30` passes, where Zod and `string.date.iso.parse` reject it.
944
+ `string.date.iso` checks the calendar as Zod does, so `2020-02-30` fails and `2024-02-29` passes.
956
945
 
957
- JSON Schema has one `pattern` for a string, so `toJsonSchema()` throws for these, and the schema a tool reads through Standard Schema keeps only the second. Where one is converted, say what to write, as Zod does: `Instant.configure({ jsonSchema: { type: "string", format: "date-time" } })`, or `format: "date"` for `Day`.
946
+ `toJsonSchema()` throws for these, since it writes one `pattern` for a string, and the schema a tool reads through Standard Schema keeps both, the second in an `allOf`. Where one is converted, say what to write, as Zod does: `Instant.configure({ jsonSchema: { type: "string", format: "date-time" } })`, or `format: "date"` for `Day`.
958
947
 
959
948
  In JSON Schema, `format` is an annotation and validates nothing unless the validator, like ajv with `ajv-formats`, checks it; `string.email` always validates.
960
949
 
@@ -1038,7 +1027,7 @@ export default defineConfig({
1038
1027
  })
1039
1028
  ```
1040
1029
 
1041
- To see what's left, run `npx arktype-precompile --check`, which lists each definition the default build would refuse. See [Dynamic vs Precompiled](https://arktype.io/docs/precompile/dynamic-vs-precompiled).
1030
+ To see what's left, run `npx @ark/aot --check`, which lists each definition the default build would refuse. See [Dynamic vs Precompiled](https://arktype.io/docs/precompile/dynamic-vs-precompiled).
1042
1031
 
1043
1032
  `drizzle-arktype`, from [Swap integrations](#migrating-a-project), creates Types from your tables as the program runs, so the build [runs it on arktype](https://arktype.io/docs/precompile/options#dependencies), shipping the parser. To precompile those Types too, write each one out, with a line that fails to compile if it drifts from the table, like `const matches: Equals<typeof selectTask.infer, typeof tasks.$inferSelect> = true`, `Equals` as in [How to convert](#how-to-convert).
1044
1033
 
@@ -1046,38 +1035,38 @@ To see what's left, run `npx arktype-precompile --check`, which lists each defin
1046
1035
 
1047
1036
  Valibot's defaults are Zod's: `v.object` removes undeclared keys, and `v.optional` accepts `undefined` and replaces it with its default. Set [the same two options](#zod-side-by-side), which the ArkType column assumes. [Semantics to check](#semantics-to-check) applies too, with Valibot's names for Zod's.
1048
1037
 
1049
- | Valibot | ArkType |
1050
- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
1051
- | `v.object`, `v.looseObject`, `v.strictObject` | the default once configured, `"+": "ignore"`, `"+": "reject"` |
1052
- | `v.objectWithRest(entries, rest)` | `"[/^(?!a$\|b$)/]": rest`, `a` and `b` the declared keys |
1053
- | `v.optional(T)`, `v.optional(T, default)` | `"key?": "T"`, `key: "T = default"` |
1054
- | `v.exactOptional(T)` | `"key?": "T"`, without `exactOptionalPropertyTypes: false` in the config |
1055
- | `v.nullable(T)`, `v.nullish(T)` | `"T \| null"`, `"key?": "T \| null"` |
1056
- | `v.literal("a")`, `v.picklist(["a", "b"])`, `v.enum(E)` | `"'a'"`, `"'a' \| 'b'"`, `type.valueOf(E)` |
1057
- | `v.partial(S)`, `v.required(S)`, `v.keyof(S)` | `T.partial()`, `T.required()`, `T.keyof()` |
1058
- | `v.pick(S, ["a"])`, `v.omit(S, ["a"])` | `T.pick("a")`, `T.omit("a")` |
1059
- | `v.union`, `v.variant("type", [...])`, `v.intersect` | `A.or(B)`, `A.or(B)`, `A.and(B)` |
1060
- | `v.array`, `v.strictTuple`, `v.tupleWithRest`, `v.record` | `"T[]"`, `[A, B]`, `[A, "...", "B[]"]`, `"Record<string, T>"` |
1061
- | `v.tuple`, which removes extra elements | `[A, B]`, which rejects them |
1062
- | `v.lazy` | a scope or `this` |
1063
- | `v.pipe(v.string(), v.email(), v.maxLength(255))` | `"string.email <= 255"` |
1064
- | `v.minLength`, `v.maxLength`, `v.length`, `v.nonEmpty` | `"string >= n"`, `"string <= n"`, `"string == n"`, `"string > 0"` |
1065
- | `v.minValue`, `v.maxValue`, `v.integer`, `v.multipleOf` | `"number >= n"`, `"number <= n"`, `"number.integer"`, `"number % n"` |
1066
- | `v.url`, `v.uuid`, `v.regex(r)` | `"string.url"`, `"string.uuid"`, `/r/` |
1067
- | `v.isoDate`, `v.isoDateTime`, `v.isoTimestamp` | `"string.date.iso"` with a pattern for each, see [Dates and formats](#dates-and-formats) |
1068
- | `v.trim()`, `v.toLowerCase()`, `v.toNumber()`, `v.toDate()` | `"string.trim"`, `"string.lower"`, `"string.numeric.parse"`, `"string.date.parse"` |
1069
- | `v.string("Message")`, `v.email("Message")`, `v.minLength(8, "Message")` | a `message` for each check, by its code: see [Custom messages](#custom-messages) |
1070
- | `v.check(fn, msg)`, `v.rawCheck` | `.narrow((x, ctx) => fn(x) \|\| ctx.reject({ message: msg }))` |
1071
- | `v.forward(v.partialCheck(...), ["key"])` | `.narrow(...)` with `ctx.reject({ message, relativePath: ["key"] })`, which runs only once every key is valid |
1072
- | `v.transform(fn)` | `.pipe(fn)` |
1073
- | `v.brand("Id")` | `.brand("Id")` |
1074
- | `v.description(text)`, `v.title(text)` in a pipe | `.describe(text)` where a model or an OpenAPI document reads it, see [Descriptions](#descriptions); `.configure({ title: text })` |
1075
- | `v.instance(C)`, `v.date()`, `v.custom(fn)` | `type.instanceOf(C)`, `"Date"`, `type("unknown").narrow(fn)` |
1076
- | `v.fallback(T, x)` | a `.pipe()` that returns `x` for invalid input, see [Fallbacks](#fallbacks) |
1077
- | `v.InferOutput`, `v.InferInput`, `v.GenericSchema` | `typeof T.infer`, `typeof T.inferIn`, `type.Any` |
1078
- | `v.parse(S, x)`, `v.safeParse(S, x)`, `v.is(S, x)` | `T.assert(x)`, `T(x)`, `T.allows(x)` |
1079
- | `v.isValiError(e)` | `e instanceof TraversalError`, whose `e.arkErrors.issues` holds the issues |
1080
- | `v.flatten(issues).nested` | group `out.issues` by `issue.path.join(".")` |
1038
+ | Valibot | ArkType |
1039
+ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
1040
+ | `v.object`, `v.looseObject`, `v.strictObject` | the default once configured, `"+": "ignore"`, `"+": "reject"` |
1041
+ | `v.objectWithRest(entries, rest)` | `"[/^(?!a$\|b$)/]": rest`, `a` and `b` the declared keys |
1042
+ | `v.optional(T)`, `v.optional(T, default)` | `"key?": "T"`, `key: "T = default"` |
1043
+ | `v.exactOptional(T)` | `"key?": "T"`, without `exactOptionalPropertyTypes: false` in the config |
1044
+ | `v.nullable(T)`, `v.nullish(T)` | `"T \| null"`, `"key?": "T \| null"` |
1045
+ | `v.literal("a")`, `v.picklist(["a", "b"])`, `v.enum(E)` | `"'a'"`, `"'a' \| 'b'"`, `type.valueOf(E)` |
1046
+ | `v.partial(S)`, `v.required(S)`, `v.keyof(S)` | `T.partial()`, `T.required()`, `T.keyof()` |
1047
+ | `v.pick(S, ["a"])`, `v.omit(S, ["a"])` | `T.pick("a")`, `T.omit("a")` |
1048
+ | `v.union`, `v.variant("type", [...])`, `v.intersect` | `A.or(B)`, `A.or(B)`, `A.and(B)` |
1049
+ | `v.array`, `v.strictTuple`, `v.tupleWithRest`, `v.record` | `"T[]"`, `[A, B]`, `[A, "...", "B[]"]`, `"Record<string, T>"` |
1050
+ | `v.tuple`, which removes extra elements | `[A, B]`, which rejects them |
1051
+ | `v.lazy` | a scope or `this` |
1052
+ | `v.pipe(v.string(), v.email(), v.maxLength(255))` | `"string.email <= 255"` |
1053
+ | `v.minLength`, `v.maxLength`, `v.length`, `v.nonEmpty` | `"string >= n"`, `"string <= n"`, `"string == n"`, `"string > 0"` |
1054
+ | `v.minValue`, `v.maxValue`, `v.integer`, `v.multipleOf` | `"number >= n"`, `"number <= n"`, `"number.integer"`, `"number % n"` |
1055
+ | `v.url`, `v.uuid`, `v.regex(r)` | `"string.url"`, `"string.uuid"`, `/r/` |
1056
+ | `v.isoDate`, `v.isoDateTime`, `v.isoTimestamp` | `"string.date.iso"` with a pattern for each, see [Dates and formats](#dates-and-formats) |
1057
+ | `v.trim()`, `v.toLowerCase()`, `v.toNumber()`, `v.toDate()` | `"string.trim"`, `"string.lower"`, `"string.numeric.parse"`, `"string.date.parse"` |
1058
+ | `v.string("Message")`, `v.email("Message")`, `v.minLength(8, "Message")` | `.message("Message", "domain")`, `.message("Message", "pattern")`, `.atLeastLength(8, "Message")`: see [Custom messages](#custom-messages) |
1059
+ | `v.check(fn, msg)`, `v.rawCheck` | `.narrow((x, ctx) => fn(x) \|\| ctx.reject({ message: msg }))` |
1060
+ | `v.forward(v.partialCheck(...), ["key"])` | `.narrow(...)` with `ctx.reject({ message, relativePath: ["key"] })`, which runs only once every key is valid |
1061
+ | `v.transform(fn)` | `.pipe(fn)` |
1062
+ | `v.brand("Id")` | `.brand("Id")` |
1063
+ | `v.description(text)`, `v.title(text)` in a pipe | `.describe(text)` where a model or an OpenAPI document reads it, see [Descriptions](#descriptions); `.configure({ title: text })` |
1064
+ | `v.instance(C)`, `v.date()`, `v.custom(fn)` | `type.instanceOf(C)`, `"Date"`, `type("unknown").narrow(fn)` |
1065
+ | `v.fallback(T, x)` | a `.pipe()` that returns `x` for invalid input, see [Fallbacks](#fallbacks) |
1066
+ | `v.InferOutput`, `v.InferInput`, `v.GenericSchema` | `typeof T.infer`, `typeof T.inferIn`, `type.Any` |
1067
+ | `v.parse(S, x)`, `v.safeParse(S, x)`, `v.is(S, x)` | `T.assert(x)`, `T(x)`, `T.allows(x)` |
1068
+ | `v.isValiError(e)` | `e instanceof TraversalError`, whose `e.arkErrors.issues` holds the issues |
1069
+ | `v.flatten(issues).nested` | group `out.issues` by `issue.path.join(".")` |
1081
1070
 
1082
1071
  `v.partial()` leaves a key with a default missing, where `.partial()` fills it in: call it on a Type of the keys without their defaults, and `.merge()` the defaults into the full object.
1083
1072
 
@@ -1129,7 +1118,7 @@ Yup does more to a value before checking it than ArkType does:
1129
1118
  | `.min(n)`, `.max(n)`, `.length(n)` on strings, arrays | `"string >= n"`, `"T[] <= n"`, `"string == n"` |
1130
1119
  | `.integer()`, `.positive()`, `.moreThan(n)` | `"number.integer"`, `"number > 0"`, `"number > n"` |
1131
1120
  | `number()`, `date()` reading strings | `"number \| string.numeric.parse"`, `"Date \| string.date.parse"` |
1132
- | `.required("m")`, `.typeError("m")`, `.min(n, "m")` | `.configure({ message: "m" }, "self")`, then `"domain"`, then `"minLength"` or `"min"` for a number; see below |
1121
+ | `.required("m")`, `.typeError("m")`, `.min(n, "m")` | `.message("m", "self")`, `.message("m", "domain")`, `.atLeastLength(n, "m")` or `.atLeast(n, "m")` for a number; see below |
1133
1122
  | `.concat(S)`, `.pick(["a"])`, `.omit(["a"])` | `.merge(S)`, `.pick("a")`, `.omit("a")` |
1134
1123
  | `.trim()`, `.lowercase()` | `"string.trim"`, `"string.lower"` |
1135
1124
  | `.oneOf(["a", "b"])` | `"'a' \| 'b'"` |
@@ -1151,15 +1140,12 @@ Yup does more to a value before checking it than ArkType does:
1151
1140
  ```ts
1152
1141
  // yup.string().required("Email is required").email("Enter a valid email")
1153
1142
  const Email = type("string.email")
1154
- .configure(
1155
- {
1156
- message: error =>
1157
- error.data === "" ? "Email is required" : "Enter a valid email"
1158
- },
1143
+ .message(
1144
+ error => (error.data === "" ? "Email is required" : "Enter a valid email"),
1159
1145
  "pattern"
1160
1146
  )
1161
- .configure({ message: "Email is required" }, "self")
1162
- .configure({ message: "Email is required" }, "domain")
1147
+ .message("Email is required", "self")
1148
+ .message("Email is required", "domain")
1163
1149
  ```
1164
1150
 
1165
1151
  A field that transforms, like one with `.trim()` or a `number()` reading strings, says ArkType's text for a missing key unless one message covers its whole value.
@@ -1188,33 +1174,33 @@ const validate = (values: unknown) => {
1188
1174
 
1189
1175
  Joi rejects undeclared keys, rejects empty strings, and converts strings to numbers, booleans and dates unless `convert: false`. ArkType reads an ISO date-time without an offset as UTC, where Joi reads it in local time. Joi also applies a default to a key present as `undefined`; see [Defaults that differ](#defaults-that-differ). It infers no types, so `typeof T.infer` replaces the interfaces written next to Joi schemas. `validate` reports the first error unless `abortEarly: false`, where a Type reports every one. Joi's conversions take a little more than the rows below: `Joi.boolean()` reads `"TRUE"` and `Joi.number()` reads `" 2"`.
1190
1176
 
1191
- | Joi | ArkType |
1192
- | ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
1193
- | `Joi.object({...})`, `.unknown(true)` | `type({ "+": "reject", ... })`, `type({...})` |
1194
- | `Joi.string()` (optional), `.required()` | `"key?": "string > 0 \| undefined"`, `"key": "string > 0"` |
1195
- | `.allow("")`, `.allow(null)` | `"string"`, `"string \| null"` |
1196
- | `.valid("a", "b")` | `"'a' \| 'b'"` |
1197
- | `.email()`, `.uri()`, `.guid()`, `.pattern(r)` | `"string.email"`, `"string.url"`, `"string.uuid"`, `/r/` |
1198
- | `.alphanum()`, `.token()`, `.hex()`, `.ip()`, `.isoDate()` | `"string.alphanumeric > 0"`, `/^\w+$/`, `"string.hex"`, `"string.ip"`, `"string.date.iso"` |
1199
- | `.trim()`, `.lowercase()`, `.uppercase()` | `"string.trim"`, `"string.lower"`, `"string.upper"`, each with `.to("string > 0")` |
1200
- | `.min(n)`, `.max(n)`, `.length(n)` | `"string >= n"`, `"string <= n"`, `"string == n"` |
1201
- | `Joi.number().integer().positive()` | `"number.integer > 0"` |
1202
- | `Joi.number()` reading strings | `"number \| string.numeric.parse"` |
1203
- | `Joi.boolean()` reading strings | `type("boolean \| 'true' \| 'false'").pipe(v => v === true \|\| v === "true")` |
1204
- | `Joi.date()`, `Joi.date().iso()` | `"Date \| string.date.parse"`, `"string.date.iso.parse"` |
1205
- | `Joi.date()` reading milliseconds | `type("number.epoch").pipe(n => new Date(n))` |
1206
- | `Joi.array().items(T)`, `.min(1)` | `T.array()`, `"T[] >= 1"` |
1207
- | `.unique()` | `.narrow((a, ctx) => new Set(a).size === a.length \|\| ctx.reject("unique"))` |
1208
- | `Joi.alternatives().try(A, B)` | `A.or(B)` |
1209
- | `.default(x)` | `"key": "T = x"` |
1210
- | `.custom(fn)` | `.narrow()` or `.pipe()` |
1211
- | `.messages({ "any.required": m })`, `"string.base"`, `"string.min"`, `"number.min"` | `.configure({ message: m }, "self")`, then `"domain"`, `"minLength"`, `"min"`; see [Custom messages](#custom-messages) |
1212
- | `Joi.link("#id")` | a scope or `this` |
1213
- | `.when(...)` | a union of the cases, or a `.narrow()` on the object |
1214
- | `Joi.valid(Joi.ref("a"))`, `.with("a", "b")`, `.xor("a", "b")`, `.or("a", "b")` | a `.narrow()` on the object that compares the keys or checks which are present |
1215
- | `Joi.any()`, `.forbidden()` | `"unknown"`, `"key?": "never"` |
1216
- | `{ stripUnknown: true }` | `"+": "delete"` in each object, or `configure({ onUndeclaredKey: "delete" })` |
1217
- | `schema.validate(x)`, `.attempt(x, schema)` | `T(x)`, `T.assert(x)` |
1177
+ | Joi | ArkType |
1178
+ | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
1179
+ | `Joi.object({...})`, `.unknown(true)` | `type({ "+": "reject", ... })`, `type({...})` |
1180
+ | `Joi.string()` (optional), `.required()` | `"key?": "string > 0 \| undefined"`, `"key": "string > 0"` |
1181
+ | `.allow("")`, `.allow(null)` | `"string"`, `"string \| null"` |
1182
+ | `.valid("a", "b")` | `"'a' \| 'b'"` |
1183
+ | `.email()`, `.uri()`, `.guid()`, `.pattern(r)` | `"string.email"`, `"string.url"`, `"string.uuid"`, `/r/` |
1184
+ | `.alphanum()`, `.token()`, `.hex()`, `.ip()`, `.isoDate()` | `"string.alphanumeric > 0"`, `/^\w+$/`, `"string.hex"`, `"string.ip"`, `"string.date.iso"` |
1185
+ | `.trim()`, `.lowercase()`, `.uppercase()` | `"string.trim"`, `"string.lower"`, `"string.upper"`, each with `.to("string > 0")` |
1186
+ | `.min(n)`, `.max(n)`, `.length(n)` | `"string >= n"`, `"string <= n"`, `"string == n"` |
1187
+ | `Joi.number().integer().positive()` | `"number.integer > 0"` |
1188
+ | `Joi.number()` reading strings | `"number \| string.numeric.parse"` |
1189
+ | `Joi.boolean()` reading strings | `type("boolean \| 'true' \| 'false'").pipe(v => v === true \|\| v === "true")` |
1190
+ | `Joi.date()`, `Joi.date().iso()` | `"Date \| string.date.parse"`, `"string.date.iso.parse"` |
1191
+ | `Joi.date()` reading milliseconds | `type("number.epoch").pipe(n => new Date(n))` |
1192
+ | `Joi.array().items(T)`, `.min(1)` | `T.array()`, `"T[] >= 1"` |
1193
+ | `.unique()` | `.narrow((a, ctx) => new Set(a).size === a.length \|\| ctx.mustBe("unique"))` |
1194
+ | `Joi.alternatives().try(A, B)` | `A.or(B)` |
1195
+ | `.default(x)` | `"key": "T = x"` |
1196
+ | `.custom(fn)` | `.narrow()` or `.pipe()` |
1197
+ | `.messages({ "any.required": m })`, `"string.base"`, `"string.min"`, `"number.min"` | `.message(m, "self")`, `.message(m, "domain")`, `.atLeastLength(n, m)`, `.atLeast(n, m)`; see [Custom messages](#custom-messages) |
1198
+ | `Joi.link("#id")` | a scope or `this` |
1199
+ | `.when(...)` | a union of the cases, or a `.narrow()` on the object |
1200
+ | `Joi.valid(Joi.ref("a"))`, `.with("a", "b")`, `.xor("a", "b")`, `.or("a", "b")` | a `.narrow()` on the object that compares the keys or checks which are present |
1201
+ | `Joi.any()`, `.forbidden()` | `"unknown"`, `"key?": "never"` |
1202
+ | `{ stripUnknown: true }` | `"+": "delete"` in each object, or `configure({ onUndeclaredKey: "delete" })` |
1203
+ | `schema.validate(x)`, `.attempt(x, schema)` | `T(x)`, `T.assert(x)` |
1218
1204
 
1219
1205
  ## Effect Schema
1220
1206
 
@@ -1267,7 +1253,7 @@ To move one schema at a time, wrap an Effect schema as a [Standard Schema](https
1267
1253
 
1268
1254
  ## JSON Schema and ajv
1269
1255
 
1270
- To keep a schema as JSON, convert it at runtime with `jsonSchemaToType` from `@ark/json-schema`; it accepts exactly what a JSON Schema 2020-12 validator accepts, except that lengths count UTF-16 code units, with `format` as an annotation. To rewrite it as definitions:
1256
+ To keep a schema as JSON, convert it at runtime with [`fromJsonSchema`](https://arktype.io/docs/json-schema/from-json-schema) from `arktype`; it accepts exactly what a JSON Schema 2020-12 validator accepts, except that lengths count UTF-16 code units, with `format` as an annotation. To rewrite it as definitions:
1271
1257
 
1272
1258
  | JSON Schema | ArkType |
1273
1259
  | ------------------------------------------------------- | ---------------------------------------------------------------------- |