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
@@ -0,0 +1,383 @@
1
+ import type { contains, ErrorMessage, noSuggest, NumberLiteral, setIndex, unionKeyOf, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, ZeroWidthSpace } from "../util/index.js";
2
+ import type { writeUnresolvableBackreferenceMessage } from "./escape.ts";
3
+ import type { quantify, QuantifyingChar } from "./quantify.ts";
4
+ import type { Flags, IndexedCaptures, NamedCaptures, Regex, RegexContext } from "./regex.ts";
5
+ export interface State extends State.Group {
6
+ unscanned: string;
7
+ groups: State.Group[];
8
+ /** the initial flags passed to the root of the expression */
9
+ flags: Flags;
10
+ }
11
+ export declare namespace State {
12
+ type from<s extends State> = s;
13
+ type initialize<source extends string, flags extends Flags> = from<{
14
+ unscanned: source;
15
+ groups: [];
16
+ capture: never;
17
+ branches: [];
18
+ sequence: SequenceTree.Empty;
19
+ root: "";
20
+ caseInsensitive: contains<flags, "i">;
21
+ flags: flags;
22
+ }>;
23
+ enum UnnamedCaptureKind {
24
+ indexed,
25
+ lookaround,
26
+ negativeLookaround,
27
+ noncapturing
28
+ }
29
+ type CaptureKind = string | UnnamedCaptureKind;
30
+ type Group = {
31
+ /** the name of the group or its kind */
32
+ capture: CaptureKind;
33
+ branches: RegexAst[];
34
+ sequence: RegexAst;
35
+ root: RegexAst;
36
+ caseInsensitive: boolean;
37
+ };
38
+ namespace Group {
39
+ type from<g extends Group> = g;
40
+ type pop<init extends Group, last extends Group[]> = [...last, init];
41
+ type finalize<g extends Group> = g["branches"] extends [] ? pushQuantifiable<g["sequence"], g["root"]> : [...g["branches"], pushQuantifiable<g["sequence"], g["root"]>] extends (infer branches extends RegexAst[]) ? finalizeUnion<branches, []> : never;
42
+ type finalizeUnion<remaining extends RegexAst[], flattened extends RegexAst[]> = remaining extends ([
43
+ infer head extends RegexAst,
44
+ ...infer tail extends RegexAst[]
45
+ ]) ? head extends UnionTree<infer headBranches> ? finalizeUnion<tail, [...flattened, ...headBranches]> : finalizeUnion<tail, [...flattened, head]> : UnionTree<flattened>;
46
+ }
47
+ }
48
+ export type Boundary = Anchor | "(" | ")" | "[" | "]";
49
+ export type Anchor = "^" | "$";
50
+ export type Control = QuantifyingChar | Boundary | "|" | "." | "{" | "}" | "-" | "\\";
51
+ export type AnchorMarker<inner extends Anchor = Anchor> = `<${ZeroWidthSpace}${inner}${ZeroWidthSpace}>`;
52
+ export type StartAnchorMarker = AnchorMarker<"^">;
53
+ export type EndAnchorMarker = AnchorMarker<"$">;
54
+ export declare namespace s {
55
+ type error<message extends string> = State.from<{
56
+ unscanned: ErrorMessage<message>;
57
+ groups: [];
58
+ capture: never;
59
+ branches: [];
60
+ sequence: SequenceTree.Empty;
61
+ root: "";
62
+ caseInsensitive: false;
63
+ flags: "";
64
+ }>;
65
+ type shiftQuantifiable<s extends State, root extends RegexAst, unscanned extends string> = State.from<{
66
+ unscanned: unscanned;
67
+ groups: s["groups"];
68
+ capture: s["capture"];
69
+ branches: s["branches"];
70
+ sequence: pushQuantifiable<s["sequence"], s["root"]>;
71
+ root: root;
72
+ caseInsensitive: s["caseInsensitive"];
73
+ flags: s["flags"];
74
+ }>;
75
+ type pushQuantified<s extends State, quantified extends RegexAst, unscanned extends string> = State.from<{
76
+ unscanned: unscanned;
77
+ groups: s["groups"];
78
+ capture: s["capture"];
79
+ branches: s["branches"];
80
+ sequence: pushQuantifiable<s["sequence"], quantified>;
81
+ root: "";
82
+ caseInsensitive: s["caseInsensitive"];
83
+ flags: s["flags"];
84
+ }>;
85
+ type pushQuantifier<s extends State, min extends number, max extends number | null, unscanned extends string> = State.from<{
86
+ unscanned: unscanned;
87
+ groups: s["groups"];
88
+ capture: s["capture"];
89
+ branches: s["branches"];
90
+ sequence: pushQuantifiable<s["sequence"], {
91
+ kind: "quantifier";
92
+ ast: s["root"];
93
+ min: min;
94
+ max: max;
95
+ }>;
96
+ root: "";
97
+ caseInsensitive: s["caseInsensitive"];
98
+ flags: s["flags"];
99
+ }>;
100
+ type finalizeBranch<s extends State, unscanned extends string> = State.from<{
101
+ unscanned: unscanned;
102
+ groups: s["groups"];
103
+ capture: s["capture"];
104
+ branches: [...s["branches"], pushQuantifiable<s["sequence"], s["root"]>];
105
+ sequence: SequenceTree.Empty;
106
+ root: "";
107
+ caseInsensitive: s["caseInsensitive"];
108
+ flags: s["flags"];
109
+ }>;
110
+ type anchor<s extends State, a extends AnchorMarker, unscanned extends string> = State.from<{
111
+ unscanned: unscanned;
112
+ groups: s["groups"];
113
+ capture: s["capture"];
114
+ branches: s["branches"];
115
+ sequence: pushQuantifiable<s["sequence"], pushQuantifiable<s["root"], a>>;
116
+ root: "";
117
+ caseInsensitive: s["caseInsensitive"];
118
+ flags: s["flags"];
119
+ }>;
120
+ type pushGroup<s extends State, capture extends string | State.UnnamedCaptureKind, unscanned extends string, caseInsensitive extends boolean | undefined> = State.from<{
121
+ unscanned: unscanned;
122
+ groups: [...s["groups"], s];
123
+ capture: capture;
124
+ branches: [];
125
+ sequence: SequenceTree.Empty;
126
+ root: "";
127
+ caseInsensitive: caseInsensitive extends boolean ? caseInsensitive : s["caseInsensitive"];
128
+ flags: s["flags"];
129
+ }>;
130
+ type popGroup<s extends State, unscanned extends string> = s["groups"] extends State.Group.pop<infer last, infer init> ? State.from<{
131
+ unscanned: unscanned;
132
+ groups: init;
133
+ capture: last["capture"];
134
+ branches: last["branches"];
135
+ sequence: s["capture"] extends LookaroundKind ? pushQuantifiable<pushQuantifiable<last["sequence"], last["root"]>, GroupTree<State.Group.finalize<s>, s["capture"]>> : pushQuantifiable<last["sequence"], last["root"]>;
136
+ root: s["capture"] extends CapturedGroupKind ? GroupTree<State.Group.finalize<s>, s["capture"]> : s["capture"] extends LookaroundKind ? "" : State.Group.finalize<s>;
137
+ caseInsensitive: last["caseInsensitive"];
138
+ flags: s["flags"];
139
+ }> : s.error<writeUnmatchedGroupCloseMessage<")", unscanned>>;
140
+ type finalize<s extends State> = s["groups"] extends [unknown, ...unknown[]] ? ErrorMessage<writeUnclosedGroupMessage<")">> : finalizeRegexOrError<finalizeTree<State.Group.finalize<s>, {
141
+ captures: EmptyCaptures;
142
+ names: {};
143
+ flags: s["flags"];
144
+ errors: [];
145
+ }>>;
146
+ type finalizeRegexOrError<r extends FinalizationResult> = r["ctx"]["errors"] extends [] ? applyAnchors<r["pattern"]> extends infer pattern extends string ? contains<pattern, StartAnchorMarker> extends false ? contains<pattern, EndAnchorMarker> extends false ? Regex<pattern, finalizeContext<r["ctx"]>> : ErrorMessage<writeMidAnchorError<"$">> : ErrorMessage<writeMidAnchorError<"^">> : never : r["ctx"]["errors"][0];
147
+ type finalizeContext<ctx extends FinalizationContext> = ctx["captures"] extends EmptyCaptures ? finalizeContextWithoutCaptures<ctx> : finalizeContextWithCaptures<{
148
+ captures: ctx["captures"] extends ([
149
+ IndexedCaptureOffset,
150
+ ...infer rest extends IndexedCaptures
151
+ ]) ? rest : never;
152
+ names: ctx["names"];
153
+ flags: ctx["flags"];
154
+ errors: ctx["errors"];
155
+ }>;
156
+ type finalizeContextWithoutCaptures<ctx extends FinalizationContext> = ctx["flags"] extends "" ? {} : {
157
+ flags: ctx["flags"];
158
+ };
159
+ type finalizeContextWithCaptures<ctx extends FinalizationContext> = keyof ctx["names"] extends never ? ctx["flags"] extends "" ? {
160
+ captures: ctx["captures"];
161
+ } : {
162
+ captures: ctx["captures"];
163
+ flags: ctx["flags"];
164
+ } : ctx["flags"] extends "" ? {
165
+ captures: ctx["captures"];
166
+ names: ctx["names"];
167
+ } : {
168
+ captures: ctx["captures"];
169
+ names: ctx["names"];
170
+ flags: ctx["flags"];
171
+ };
172
+ }
173
+ export type RegexAst = string | ReferenceNode | UnionTree | SequenceTree | GroupTree | QuantifierTree;
174
+ export interface ReferenceNode<to extends string = string> {
175
+ kind: "reference";
176
+ to: to;
177
+ }
178
+ export declare namespace ReferenceNode {
179
+ type finalize<self extends ReferenceNode, ctx extends FinalizationContext, to extends string = self["to"]> = to extends NumberLiteral & keyof ctx["captures"] ? ctx["captures"][to] extends IncompleteCaptureGroup ? FinalizationResult.error<ctx, writeIncompleteReferenceError<to>> : FinalizationResult.from<{
180
+ pattern: inferReference<ctx["captures"][to]>;
181
+ ctx: ctx;
182
+ }> : to extends keyof ctx["names"] ? ctx["names"][to] extends IncompleteCaptureGroup ? FinalizationResult.error<ctx, writeIncompleteReferenceError<to>> : FinalizationResult.from<{
183
+ pattern: inferReference<ctx["names"][to]>;
184
+ ctx: ctx;
185
+ }> : FinalizationResult.error<ctx, writeUnresolvableBackreferenceMessage<to>>;
186
+ type inferReference<to extends string | undefined> = to extends string ? to : "";
187
+ }
188
+ export declare const writeIncompleteReferenceError: <ref extends string>(ref: ref) => writeIncompleteReferenceError<ref>;
189
+ export type writeIncompleteReferenceError<ref extends string> = `Reference to incomplete group '${ref}' has no effect`;
190
+ export interface SequenceTree<ast extends RegexAst[] = RegexAst[]> {
191
+ kind: "sequence";
192
+ ast: ast;
193
+ }
194
+ export declare namespace SequenceTree {
195
+ type Empty = SequenceTree<[]>;
196
+ type finalize<self extends SequenceTree, ctx extends FinalizationContext> = _finalize<self["ast"], "", ctx>;
197
+ type _finalize<tree extends unknown[], pattern extends string, ctx extends FinalizationContext> = tree extends [infer head, ...infer tail] ? finalizeTree<head, ctx> extends infer r ? r extends FinalizationResult ? _finalize<tail, appendNonRedundant<pattern, r["pattern"]>, r["ctx"]> : never : never : FinalizationResult.from<{
198
+ pattern: pattern;
199
+ ctx: ctx;
200
+ }>;
201
+ }
202
+ export interface UnionTree<ast extends RegexAst[] = RegexAst[]> {
203
+ kind: "union";
204
+ ast: ast;
205
+ }
206
+ export declare namespace UnionTree {
207
+ type finalize<self extends UnionTree, ctx extends FinalizationContext> = _finalize<self["ast"], [], ctx, ctx["captures"]>;
208
+ type FinalizedBranch = {
209
+ pattern: string;
210
+ captures: IndexedCaptures;
211
+ names: NamedCaptures;
212
+ };
213
+ namespace FinalizedBranch {
214
+ type from<b extends FinalizedBranch> = b;
215
+ }
216
+ type _finalize<astBranches extends unknown[], acc extends FinalizedBranch[], ctx extends FinalizationContext, priorCaptures extends IndexedCaptures> = astBranches extends [infer head, ...infer tail] ? finalizeTree<head, branchContextOf<ctx, priorCaptures>> extends (infer r extends FinalizationResult) ? _finalize<tail, [
217
+ ...acc,
218
+ finalizeBranch<ctx, r>
219
+ ], ctx, r["ctx"]["captures"]> : never : finalizeBranches<keyof acc, acc, ctx, extractNewCaptures<ctx["captures"], priorCaptures>>;
220
+ type branchContextOf<ctx extends FinalizationContext, priorCaptures extends IndexedCaptures> = priorCaptures["length"] extends ctx["captures"]["length"] ? ctx : FinalizationContext.from<{
221
+ captures: {
222
+ [i in keyof priorCaptures]: i extends keyof ctx["captures"] ? priorCaptures[i] : undefined;
223
+ };
224
+ names: ctx["names"];
225
+ flags: ctx["flags"];
226
+ errors: ctx["errors"];
227
+ }>;
228
+ type finalizeBranch<ctx extends FinalizationContext, r extends FinalizationResult> = r extends unknown ? FinalizedBranch.from<{
229
+ pattern: r["pattern"];
230
+ captures: extractNewCaptures<ctx["captures"], r["ctx"]["captures"]>;
231
+ names: r["ctx"]["names"];
232
+ }> : never;
233
+ type finalizeBranches<i, acc extends FinalizedBranch[], ctx extends FinalizationContext, unionCaptures extends IndexedCaptures> = i extends keyof acc & NumberLiteral ? finalizeBranchResult<acc[i], acc, ctx, unionCaptures> : never;
234
+ type finalizeBranchResult<branch extends FinalizedBranch, acc extends FinalizedBranch[], ctx extends FinalizationContext, unionCaptures extends IndexedCaptures> = branch extends unknown ? FinalizationResult.from<{
235
+ pattern: branch["pattern"];
236
+ ctx: {
237
+ flags: ctx["flags"];
238
+ captures: [
239
+ ...ctx["captures"],
240
+ ...{
241
+ [j in keyof unionCaptures]: j extends keyof branch["captures"] ? branch["captures"][j] : undefined;
242
+ }
243
+ ];
244
+ names: {
245
+ [k in unionKeyOf<acc[number]["names"]>]: k extends (keyof branch["names"]) ? branch["names"][k] : undefined;
246
+ };
247
+ errors: ctx["errors"];
248
+ };
249
+ }> : never;
250
+ }
251
+ export type CapturedGroupKind = string | State.UnnamedCaptureKind.indexed;
252
+ export type LookaroundKind = State.UnnamedCaptureKind.lookaround | State.UnnamedCaptureKind.negativeLookaround;
253
+ export type IncompleteCaptureGroup = noSuggest<"incompleteCaptureGroup">;
254
+ export type IndexedCaptureOffset = noSuggest<"indexedCaptureOffset">;
255
+ /**
256
+ * Offset captures to match 1-based indexing for references
257
+ * (i.e so that \1 would match the first capture group)
258
+ */
259
+ export type EmptyCaptures = [IndexedCaptureOffset];
260
+ export interface GroupTree<ast extends RegexAst = RegexAst, capture extends CapturedGroupKind | LookaroundKind = CapturedGroupKind | LookaroundKind> {
261
+ kind: "group";
262
+ capture: capture;
263
+ ast: ast;
264
+ }
265
+ export declare namespace GroupTree {
266
+ type finalize<self extends GroupTree, ctx extends FinalizationContext> = finalizeGroupAst<self, ctx> extends infer r ? r extends FinalizationResult ? finalizeGroupResult<self, ctx, r> : never : never;
267
+ type finalizeGroupAst<self extends GroupTree, ctx extends FinalizationContext> = finalizeTree<self["ast"], self["capture"] extends string ? {
268
+ captures: [...ctx["captures"], IncompleteCaptureGroup];
269
+ names: ctx["names"] & {
270
+ [_ in self["capture"]]: IncompleteCaptureGroup;
271
+ };
272
+ flags: ctx["flags"];
273
+ errors: ctx["errors"];
274
+ } : self["capture"] extends State.UnnamedCaptureKind.indexed ? {
275
+ captures: [...ctx["captures"], IncompleteCaptureGroup];
276
+ names: ctx["names"];
277
+ flags: ctx["flags"];
278
+ errors: ctx["errors"];
279
+ } : ctx>;
280
+ type finalizeGroupResult<self extends GroupTree, ctx extends FinalizationContext, r extends FinalizationResult> = FinalizationResult.from<{
281
+ pattern: self["capture"] extends LookaroundKind ? "" : r["pattern"];
282
+ ctx: self["capture"] extends string ? finalizeNamedCapture<self["capture"], ctx["captures"]["length"], r["pattern"], r["ctx"]> : self["capture"] extends State.UnnamedCaptureKind.indexed ? finalizeUnnamedCapture<ctx["captures"]["length"], r["pattern"], r["ctx"]> : self["capture"] extends State.UnnamedCaptureKind.negativeLookaround ? finalizeNegativeLookaround<ctx, r["ctx"]> : r["ctx"];
283
+ }>;
284
+ type finalizeNegativeLookaround<base extends FinalizationContext, result extends FinalizationContext, lookaroundCaptures extends IndexedCaptures = extractNewCaptures<base["captures"], result["captures"]>> = FinalizationContext.from<{
285
+ captures: [
286
+ ...base["captures"],
287
+ ...{
288
+ [i in keyof lookaroundCaptures]: undefined;
289
+ }
290
+ ];
291
+ names: {
292
+ [k in keyof result["names"]]: k extends keyof base["names"] ? result["names"][k] : undefined;
293
+ };
294
+ flags: result["flags"];
295
+ errors: result["errors"];
296
+ }>;
297
+ type finalizeNamedCapture<name extends string, index extends number, pattern extends string, ctx extends FinalizationContext> = FinalizationContext.from<{
298
+ captures: setIndex<ctx["captures"], index, anchorsAway<pattern>>;
299
+ names: {
300
+ [k in keyof ctx["names"]]: k extends name ? anchorsAway<pattern> : ctx["names"][k];
301
+ };
302
+ flags: ctx["flags"];
303
+ errors: ctx["errors"];
304
+ }>;
305
+ type finalizeUnnamedCapture<index extends number, pattern extends string, ctx extends FinalizationContext> = FinalizationContext.from<{
306
+ captures: setIndex<ctx["captures"], index, anchorsAway<pattern>>;
307
+ names: ctx["names"];
308
+ flags: ctx["flags"];
309
+ errors: ctx["errors"];
310
+ }>;
311
+ }
312
+ export interface QuantifierTree<ast extends RegexAst = RegexAst> {
313
+ kind: "quantifier";
314
+ ast: ast;
315
+ min: number;
316
+ max: number | null;
317
+ }
318
+ export declare namespace QuantifierTree {
319
+ type finalize<self extends QuantifierTree, ctx extends FinalizationContext> = finalizeTree<self["ast"], ctx> extends infer r extends FinalizationResult ? finalizeQuantifierResult<self, ctx, r> : never;
320
+ type finalizeQuantifierResult<self extends QuantifierTree, ctx extends FinalizationContext, r extends FinalizationResult, quantifiedCaptures extends IndexedCaptures = extractNewCaptures<ctx["captures"], r["ctx"]["captures"]>> = self["min"] extends 0 ? quantifiedCaptures extends [] ? finalizeNonZeroMinQuantified<self, r> : finalizeZeroMinQuantifiedWithCaptures<self, ctx, r, quantifiedCaptures> : finalizeNonZeroMinQuantified<self, r>;
321
+ type finalizeNonZeroMinQuantified<self extends QuantifierTree, r extends FinalizationResult> = FinalizationResult.from<{
322
+ pattern: quantify<r["pattern"], self["min"], self["max"]>;
323
+ ctx: r["ctx"];
324
+ }>;
325
+ type finalizeZeroMinQuantifiedWithCaptures<self extends QuantifierTree, ctx extends FinalizationContext, r extends FinalizationResult, quantifiedCaptures extends IndexedCaptures> = finalizeZeroQuantified<ctx, r, quantifiedCaptures> | finalizeOnePlusQuantified<self["max"], r>;
326
+ type finalizeZeroQuantified<ctx extends FinalizationContext, r extends FinalizationResult, quantifiedCaptures extends IndexedCaptures> = FinalizationResult.from<{
327
+ pattern: "";
328
+ ctx: {
329
+ captures: [
330
+ ...ctx["captures"],
331
+ ...{
332
+ [i in keyof quantifiedCaptures]: undefined;
333
+ }
334
+ ];
335
+ flags: r["ctx"]["flags"];
336
+ names: zeroQuantifiedNames<ctx["names"], r["ctx"]["names"]>;
337
+ errors: r["ctx"]["errors"];
338
+ };
339
+ }>;
340
+ type zeroQuantifiedNames<base extends NamedCaptures, result extends NamedCaptures> = {
341
+ [k in keyof result]: k extends keyof base ? result[k] : undefined;
342
+ } & unknown;
343
+ type finalizeOnePlusQuantified<max extends number | null, r extends FinalizationResult> = max extends 1 ? r : FinalizationResult.from<{
344
+ pattern: quantify<r["pattern"], 1, max>;
345
+ ctx: r["ctx"];
346
+ }>;
347
+ }
348
+ export type pushQuantifiable<sequence extends RegexAst, root extends RegexAst> = root extends "" ? sequence : sequence extends string ? sequence extends "" ? root : root extends string ? appendNonRedundant<sequence, root> : SequenceTree<[sequence, root]> : sequence extends SequenceTree ? pushToSequence<sequence, root> : SequenceTree<[sequence, root]>;
349
+ type pushToSequence<sequence extends SequenceTree, root extends RegexAst> = sequence extends SequenceTree.Empty ? root : root extends SequenceTree ? SequenceTree<[...sequence["ast"], ...root["ast"]]> : SequenceTree<[...sequence["ast"], root]>;
350
+ type extractNewCaptures<base extends IndexedCaptures, result extends IndexedCaptures> = result extends readonly [...base, ...infer elements extends IndexedCaptures] ? elements : [];
351
+ export interface FinalizationContext extends Required<RegexContext> {
352
+ errors: ErrorMessage[];
353
+ }
354
+ export declare namespace FinalizationContext {
355
+ type from<ctx extends FinalizationContext> = ctx;
356
+ }
357
+ export type FinalizationResult = {
358
+ pattern: string;
359
+ ctx: FinalizationContext;
360
+ };
361
+ export declare namespace FinalizationResult {
362
+ type from<r extends FinalizationResult> = r;
363
+ type error<ctx extends FinalizationContext, message extends string> = from<{
364
+ pattern: string;
365
+ ctx: {
366
+ captures: ctx["captures"];
367
+ names: ctx["names"];
368
+ flags: ctx["flags"];
369
+ errors: [...ctx["errors"], ErrorMessage<message>];
370
+ };
371
+ }>;
372
+ }
373
+ export type finalizeTree<tree, ctx extends FinalizationContext> = tree extends string ? FinalizationResult.from<{
374
+ pattern: tree;
375
+ ctx: ctx;
376
+ }> : tree extends SequenceTree ? SequenceTree.finalize<tree, ctx> : tree extends UnionTree ? UnionTree.finalize<tree, ctx> : tree extends GroupTree ? GroupTree.finalize<tree, ctx> : tree extends QuantifierTree ? QuantifierTree.finalize<tree, ctx> : tree extends ReferenceNode ? ReferenceNode.finalize<tree, ctx> : never;
377
+ type applyAnchors<pattern extends string> = pattern extends `${StartAnchorMarker}${infer startStripped}` ? startStripped extends `${infer bothStripped}${EndAnchorMarker}` ? bothStripped : appendNonRedundant<startStripped, string> : pattern extends `${infer endStripped}${EndAnchorMarker}` ? prependNonRedundant<endStripped, string> : prependNonRedundant<appendNonRedundant<pattern, string>, string>;
378
+ type anchorsAway<pattern extends string> = pattern extends `${StartAnchorMarker}${infer startStripped}` ? startStripped extends `${infer bothStripped}${EndAnchorMarker}` ? bothStripped : startStripped : pattern extends `${infer endStripped}${EndAnchorMarker}` ? endStripped : pattern;
379
+ type appendNonRedundant<base extends string, suffix extends string> = string extends base ? string extends suffix ? string : `${base}${suffix}` : `${number}` extends base ? `${number}` extends suffix ? `${number}` : `${base}${suffix}` : `${base}${suffix}`;
380
+ type prependNonRedundant<base extends string, prefix extends string> = string extends base ? string extends prefix ? string : `${prefix}${base}` : `${number}` extends base ? `${number}` extends prefix ? `${number}` : `${prefix}${base}` : `${prefix}${base}`;
381
+ export declare const writeMidAnchorError: <anchor extends Anchor>(anchor: anchor) => writeMidAnchorError<anchor>;
382
+ type writeMidAnchorError<anchor extends Anchor> = `Anchor ${anchor} may not appear mid-pattern`;
383
+ export {};
@@ -0,0 +1,2 @@
1
+ import "./index.ts";
2
+ export * from "./shared/codecs.ts";
@@ -0,0 +1,103 @@
1
+ import { type ArkRegistry, type requireKeys, type show } from "../util/index.js";
2
+ import type { intrinsic } from "./intrinsic.ts";
3
+ import type { BaseNode } from "./node.ts";
4
+ import type { nodesById } from "./parse.ts";
5
+ import type { BaseRoot } from "./roots/root.ts";
6
+ import type { RootApplyRuntime } from "./shared/rootApply.ts";
7
+ import type { BaseScope } from "./scope.ts";
8
+ import type { TypeMeta } from "./shared/declare.ts";
9
+ import { type ActualConfig, type ArkErrorCode, type ArkErrors, type ExpectedConfig, type MessageConfig } from "./shared/errors.ts";
10
+ import { type DescriptionWriter, type NodeKind } from "./shared/implement.ts";
11
+ import type { Locale } from "./shared/locale.ts";
12
+ import type { SetEngine } from "./shared/sets.ts";
13
+ import type { InPlaceTransforms } from "./shared/transform.ts";
14
+ import { ToJsonSchema } from "./shared/toJsonSchema.ts";
15
+ import type { UndeclaredKeyBehavior } from "./structure/structure.ts";
16
+ export interface ArkSchemaRegistry extends ArkRegistry {
17
+ /** the intrinsic nodes keywords are built from, like `unknown` and `string` */
18
+ kw: typeof intrinsic;
19
+ config: ArkSchemaConfig;
20
+ defaultConfig: ResolvedConfig;
21
+ cfg?: ResolvedConfig;
22
+ nodesById: typeof nodesById;
23
+ sets?: SetEngine;
24
+ encode?: (node: BaseRoot) => BaseRoot;
25
+ inPlace?: InPlaceTransforms;
26
+ deferDefaultCheck?: ((node: BaseRoot, value: unknown, key: PropertyKey | null, owner: BaseNode | undefined) => boolean) | undefined;
27
+ reached?: CacheReach | undefined;
28
+ eagerTypes?: boolean | undefined;
29
+ errorModes?: Record<"first" | "none", RootApplyRuntime>;
30
+ }
31
+ export interface CacheReach {
32
+ node: (node: BaseNode) => void;
33
+ cached: (cache: object, key: unknown) => void;
34
+ alias: ($: BaseScope, alias: string) => void;
35
+ mark: () => number | undefined;
36
+ store: (mark: number | undefined, cache: object, key: unknown) => void;
37
+ }
38
+ type nodeConfigForKind<kind extends NodeKind> = Readonly<show<{
39
+ description?: DescriptionWriter<kind>;
40
+ } & (kind extends ArkErrorCode ? ErrorConfig<kind> : {})>>;
41
+ export type ErrorConfig<code extends ArkErrorCode = ArkErrorCode> = {
42
+ expected?: ExpectedConfig<code>;
43
+ actual?: ActualConfig<code>;
44
+ message?: MessageConfig<code>;
45
+ };
46
+ type NodeConfigsByKind = {
47
+ [kind in NodeKind]: nodeConfigForKind<kind>;
48
+ };
49
+ export type NodeConfig<kind extends NodeKind = NodeKind> = NodeConfigsByKind[kind];
50
+ export interface UnknownErrorConfigs {
51
+ expected?: ExpectedConfig;
52
+ actual?: ActualConfig;
53
+ message?: MessageConfig;
54
+ }
55
+ interface UnknownNodeConfig extends UnknownErrorConfigs {
56
+ description?: DescriptionWriter;
57
+ }
58
+ export type ResolvedUnknownNodeConfig = requireKeys<UnknownNodeConfig, "description">;
59
+ export declare const writeUnknownConfigOptionMessage: <name extends string>(name: name) => writeUnknownConfigOptionMessage<name>;
60
+ export type writeUnknownConfigOptionMessage<name extends string> = `configure() has no option '${name}'`;
61
+ export declare const writeInvalidUndeclaredKeyBehaviorMessage: (actual: unknown) => string;
62
+ /**
63
+ * @internal throws for 2.x's `problem` in a code's config, which a cast or
64
+ * JavaScript still passes, and which would otherwise be kept and never read
65
+ */
66
+ export declare const assertNoProblemConfig: (config: ArkSchemaConfig | undefined) => void;
67
+ export declare const configureSchema: (config: ArkSchemaConfig) => ArkSchemaConfig;
68
+ /** $ark.config merged over base, with its static locale */
69
+ export declare const resolveGlobalConfig: (base: ResolvedConfig) => ResolvedConfig;
70
+ export declare const writeInvalidLocaleMessage: (locale: unknown) => string;
71
+ export declare const mergeConfigs: <base extends ArkSchemaConfig>(base: base, merged: ArkSchemaConfig | undefined) => base;
72
+ type MergeToJsonSchemaConfigs = <base extends ToJsonSchema.Options | undefined>(baseConfig: base, mergedConfig: ToJsonSchema.Options | undefined) => base extends ToJsonSchema.Context ? ToJsonSchema.Context : ToJsonSchema.Options;
73
+ export declare const mergeToJsonSchemaConfigs: MergeToJsonSchemaConfigs;
74
+ export type ErrorDetail = "all" | "first" | "none";
75
+ /**
76
+ * #### whether a valid input is transformed in place
77
+ *
78
+ * - `false`: transforms copy what they change, so the input is never written
79
+ * - `true`: writes where no other place can read what it wrote, else copies
80
+ * - `"always"`: writes every transform into the input
81
+ */
82
+ export type MutatesInput = boolean | "always";
83
+ export interface ArkSchemaConfig extends Partial<Readonly<NodeConfigsByKind>> {
84
+ readonly undeclared?: Readonly<ErrorConfig<"undeclared">>;
85
+ readonly discriminant?: Readonly<ErrorConfig<"discriminant">>;
86
+ readonly jitless?: boolean;
87
+ readonly onUndeclaredKey?: UndeclaredKeyBehavior;
88
+ readonly numberAllowsNaN?: boolean;
89
+ readonly numberAllowsInfinity?: boolean;
90
+ readonly dateAllowsInvalid?: boolean;
91
+ readonly exactOptionalPropertyTypes?: boolean;
92
+ readonly onFail?: ArkErrors.Handler | null;
93
+ readonly errors?: ErrorDetail;
94
+ readonly mutatesInput?: MutatesInput;
95
+ readonly keywords?: Record<string, TypeMeta.Collapsible | undefined>;
96
+ readonly toJsonSchema?: ToJsonSchema.Options;
97
+ readonly locale?: Locale | (() => Locale | undefined);
98
+ }
99
+ export type resolveConfig<config extends ArkSchemaConfig> = show<{
100
+ [k in keyof ArkSchemaConfig]-?: k extends NodeKind | ArkErrorCode ? Required<config[k]> : k extends "keywords" ? Record<string, TypeMeta | undefined> : k extends "toJsonSchema" ? ToJsonSchema.Context : k extends "locale" ? Locale.Resolved : config[k];
101
+ } & Omit<config, keyof ArkSchemaConfig>>;
102
+ export type ResolvedConfig = resolveConfig<ArkSchemaConfig>;
103
+ export {};
@@ -0,0 +1,78 @@
1
+ import { arkKind, type array, type describe } from "../util/index.js";
2
+ import type { NodeInput, Prerequisite, nodeOfKind } from "./kinds.ts";
3
+ import { BaseNode } from "./node.ts";
4
+ import type { Predicate } from "./predicate.ts";
5
+ import type { After } from "./refinements/after.ts";
6
+ import type { Before } from "./refinements/before.ts";
7
+ import type { Divisor } from "./refinements/divisor.ts";
8
+ import type { ExactLength } from "./refinements/exactLength.ts";
9
+ import type { Max } from "./refinements/max.ts";
10
+ import type { MaxLength } from "./refinements/maxLength.ts";
11
+ import type { Min } from "./refinements/min.ts";
12
+ import type { MinLength } from "./refinements/minLength.ts";
13
+ import type { NotEqual } from "./refinements/notEqual.ts";
14
+ import type { NotEqualLength } from "./refinements/notEqualLength.ts";
15
+ import type { Pattern } from "./refinements/pattern.ts";
16
+ import type { Intersection } from "./roots/intersection.ts";
17
+ import type { BaseRoot } from "./roots/root.ts";
18
+ import type { NodeCompiler } from "./shared/compile.ts";
19
+ import type { BaseNodeDeclaration } from "./shared/declare.ts";
20
+ import type { Disjoint } from "./shared/disjoint.ts";
21
+ import { type ConstraintKind, type StructuralKind, type kindLeftOf } from "./shared/implement.ts";
22
+ import type { AliasDepth, InternalTraversal } from "./shared/traversal.ts";
23
+ export declare namespace Constraint {
24
+ interface Declaration extends BaseNodeDeclaration {
25
+ kind: ConstraintKind;
26
+ }
27
+ type ReductionResult = BaseRoot | Disjoint | Intersection.Inner.mutable;
28
+ interface Attachments {
29
+ /** the basis it constrains, which an intersection holding it must have */
30
+ implied: BaseRoot | null;
31
+ /** the constraints an intersection holding it must also hold */
32
+ impliedBy?: array<BaseConstraint> | null;
33
+ }
34
+ type PrimitiveKind = Exclude<ConstraintKind, StructuralKind>;
35
+ type Schema<kind extends PrimitiveKind = PrimitiveKind> = SchemasByKind[kind];
36
+ interface SchemasByKind {
37
+ pattern: Pattern.Schema;
38
+ divisor: Divisor.Schema;
39
+ exactLength: ExactLength.Schema;
40
+ max: Max.Schema;
41
+ min: Min.Schema;
42
+ maxLength: MaxLength.Schema;
43
+ minLength: MinLength.Schema;
44
+ before: Before.Schema;
45
+ after: After.Schema;
46
+ notEqual: NotEqual.Schema;
47
+ notEqualLength: NotEqualLength.Schema;
48
+ structure: NodeInput<"structure">;
49
+ predicate: Predicate.Schema;
50
+ }
51
+ }
52
+ export declare abstract class BaseConstraint<
53
+ /** @ts-ignore allow instantiation assignment to the base type */
54
+ out d extends Constraint.Declaration = Constraint.Declaration> extends BaseNode<d> {
55
+ get [arkKind](): "constraint";
56
+ abstract readonly implied: BaseRoot | null;
57
+ readonly impliedBy?: array<BaseConstraint>;
58
+ intersect<r extends BaseConstraint>(r: r): intersectConstraintKinds<d["kind"], r["kind"]>;
59
+ }
60
+ export declare abstract class InternalPrimitiveConstraint<d extends Constraint.Declaration> extends BaseConstraint<d> {
61
+ abstract tAllows(data: d["prerequisite"], ctx: InternalTraversal | AliasDepth): boolean;
62
+ abstract jsCond(js: NodeCompiler, data: string): string;
63
+ tApply(data: d["prerequisite"], ctx: InternalTraversal): void;
64
+ compile(js: NodeCompiler): void;
65
+ /** `errorCtx`, once read */
66
+ private _errorCtx;
67
+ /** the context of the error it reports when data fails it */
68
+ get errorCtx(): d["errorCtx"];
69
+ /** `errorCtx` written as JavaScript, as compiled code reports it */
70
+ get jsErrorCtx(): string;
71
+ }
72
+ export declare const constraintInputOf: <kind extends Constraint.PrimitiveKind>(kind: kind, schema: Constraint.Schema<kind>) => NodeInput<kind>;
73
+ export type constraintKindLeftOf<kind extends ConstraintKind> = ConstraintKind & kindLeftOf<kind>;
74
+ export type constraintKindOrLeftOf<kind extends ConstraintKind> = kind | constraintKindLeftOf<kind>;
75
+ export type intersectConstraintKinds<l extends ConstraintKind, r extends ConstraintKind> = nodeOfKind<l | r | "unit" | "union"> | Disjoint | null;
76
+ export declare const throwInvalidOperandError: (...args: Parameters<typeof writeInvalidOperandMessage>) => never;
77
+ export declare const writeInvalidOperandMessage: <kind extends ConstraintKind, expected extends BaseRoot, actual extends BaseRoot>(kind: kind, expected: expected, actual: actual) => string;
78
+ export type writeInvalidOperandMessage<kind extends ConstraintKind, actual> = `${Capitalize<kind>} operand must be ${describe<Prerequisite<kind>>} (was ${describe<Exclude<actual, Prerequisite<kind>>>})`;
@@ -0,0 +1 @@
1
+ export { ArkFirstIssueTraversal, UndetailedErrors, UndetailedTraversal } from "./shared/errorModes.ts";
@@ -0,0 +1,85 @@
1
+ import { arkKind, Callable, type array, type Hkt, type JsonStructure } from "../util/index.js";
2
+ import type { RootSchema } from "./parseSchema.ts";
3
+ import { type BaseNode } from "./node.ts";
4
+ import { type NodeId } from "./parse.ts";
5
+ import type { BaseRoot } from "./roots/root.ts";
6
+ import type { BaseScope } from "./scope.ts";
7
+ export type GenericParamAst<name extends string = string, constraint = unknown> = [name: name, constraint: constraint];
8
+ export type GenericParamDef<name extends string = string> = name | readonly [name, unknown];
9
+ export declare const parseGeneric: (paramDefs: array<GenericParamDef>, bodyDef: unknown, $: BaseScope, alias?: string) => GenericRoot;
10
+ export type genericParamNames<params extends array<GenericParamAst>> = {
11
+ [i in keyof params]: params[i][0];
12
+ };
13
+ export type genericParamConstraints<params extends array<GenericParamAst>> = {
14
+ [i in keyof params]: params[i][1];
15
+ };
16
+ export type GenericArgResolutions<params extends array<GenericParamAst> = array<GenericParamAst>> = {
17
+ [i in keyof params as params[i & `${number}`][0]]: BaseRoot;
18
+ };
19
+ export declare class LazyGenericBody<argResolutions = {}, returns = unknown> extends Callable<(args: argResolutions) => returns> {
20
+ }
21
+ export declare class LazyGenericRoot extends Callable<() => GenericRoot, {
22
+ paramsDef: string;
23
+ bodyDef: unknown;
24
+ }> {
25
+ }
26
+ export interface GenericAst<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = unknown, arg$ = $> {
27
+ [arkKind]: "generic";
28
+ paramsAst: params;
29
+ bodyDef: bodyDef;
30
+ $: $;
31
+ arg$: arg$;
32
+ names: genericParamNames<params>;
33
+ t: this;
34
+ }
35
+ export declare class GenericRoot<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown> extends Callable<(...args: {
36
+ [i in keyof params]: BaseRoot;
37
+ }) => BaseRoot> {
38
+ readonly [arkKind] = "generic";
39
+ readonly paramsAst: params;
40
+ readonly t: GenericAst<params, bodyDef, {}, {}>;
41
+ paramDefs: array<GenericParamDef>;
42
+ bodyDef: bodyDef;
43
+ $: BaseScope;
44
+ arg$: BaseScope;
45
+ hkt: Hkt.constructor | null;
46
+ description: string;
47
+ alias: string | undefined;
48
+ private instantiations;
49
+ private openInstances;
50
+ constructor(paramDefs: array<GenericParamDef>, bodyDef: bodyDef, $: BaseScope, arg$: BaseScope, hkt: Hkt.constructor | null, alias?: string);
51
+ get id(): NodeId;
52
+ get baseInstance(): BaseRoot;
53
+ private instantiate;
54
+ private checkArgs;
55
+ defIsLazy(): this is GenericRoot<params, LazyGenericBody>;
56
+ protected memo<name extends keyof this>(name: name, value: this[name]): this[name];
57
+ get json(): JsonStructure;
58
+ get params(): {
59
+ [i in keyof params]: [params[i][0], BaseRoot];
60
+ };
61
+ get names(): genericParamNames<params>;
62
+ get constraints(): {
63
+ [i in keyof params]: BaseRoot;
64
+ };
65
+ get internal(): this;
66
+ get byId(): Record<string, BaseNode>;
67
+ get references(): BaseNode[];
68
+ }
69
+ export type genericParamSchemasToAst<schemas extends readonly GenericParamDef[]> = {
70
+ [i in keyof schemas]: schemas[i] extends GenericParamDef<infer name> ? [
71
+ name,
72
+ unknown
73
+ ] : never;
74
+ };
75
+ export type genericHktToConstraints<hkt extends abstract new () => Hkt> = InstanceType<hkt>["constraints"];
76
+ export type GenericRootParser = <const paramsDef extends readonly GenericParamDef[]>(...params: paramsDef) => GenericRootBodyParser<genericParamSchemasToAst<paramsDef>>;
77
+ export type GenericRootBodyParser<params extends array<GenericParamAst>> = {
78
+ <const body>(body: RootSchema): GenericRoot<params, body>;
79
+ <hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<GenericArgResolutions<params>>, hkt: hkt): GenericRoot<{
80
+ [i in keyof params]: [params[i][0], genericHktToConstraints<hkt>[i]];
81
+ }, InstanceType<hkt>>;
82
+ };
83
+ export declare const writeUnclosedGenericCycleMessage: (name: string) => string;
84
+ export declare const writeUnsatisfiedParameterConstraintMessage: <name extends string, constraint extends string, arg extends string>(name: name, constraint: constraint, arg: arg) => writeUnsatisfiedParameterConstraintMessage<name, constraint, arg>;
85
+ export type writeUnsatisfiedParameterConstraintMessage<name extends string, constraint extends string, arg extends string> = `${name} must be assignable to ${constraint} (was ${arg})`;