arktype 2.0.0-dev.9 → 2.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 (263) hide show
  1. package/LICENSE +7 -0
  2. package/out/config.d.ts +25 -0
  3. package/out/config.js +2 -0
  4. package/out/generic.d.ts +154 -18
  5. package/out/generic.js +37 -23
  6. package/out/index.d.ts +7 -0
  7. package/out/index.js +6 -0
  8. package/out/intersect.d.ts +28 -0
  9. package/out/intersect.js +1 -0
  10. package/out/keys.d.ts +16 -0
  11. package/out/keys.js +1 -0
  12. package/out/keywords/ark.d.ts +33 -0
  13. package/out/keywords/ark.js +18 -0
  14. package/out/keywords/ast.d.ts +193 -0
  15. package/out/keywords/ast.js +2 -0
  16. package/out/keywords/builtin.d.ts +13 -0
  17. package/out/keywords/builtin.js +10 -0
  18. package/out/keywords/constructors/Array.d.ts +16 -0
  19. package/out/keywords/constructors/Array.js +19 -0
  20. package/out/keywords/constructors/FormData.d.ts +9 -0
  21. package/out/keywords/constructors/FormData.js +25 -0
  22. package/out/keywords/constructors/TypedArray.d.ts +15 -0
  23. package/out/keywords/constructors/TypedArray.js +14 -0
  24. package/out/keywords/constructors/constructors.d.ts +41 -0
  25. package/out/keywords/constructors/constructors.js +31 -0
  26. package/out/keywords/number/epoch.d.ts +10 -0
  27. package/out/keywords/number/epoch.js +26 -0
  28. package/out/keywords/number/integer.d.ts +3 -0
  29. package/out/keywords/number/integer.js +5 -0
  30. package/out/keywords/number/number.d.ts +26 -0
  31. package/out/keywords/number/number.js +9 -0
  32. package/out/keywords/string/alpha.d.ts +7 -0
  33. package/out/keywords/string/alpha.js +2 -0
  34. package/out/keywords/string/alphanumeric.d.ts +7 -0
  35. package/out/keywords/string/alphanumeric.js +2 -0
  36. package/out/keywords/string/capitalize.d.ts +14 -0
  37. package/out/keywords/string/capitalize.js +12 -0
  38. package/out/keywords/string/creditCard.d.ts +8 -0
  39. package/out/keywords/string/creditCard.js +37 -0
  40. package/out/keywords/string/date.d.ts +54 -0
  41. package/out/keywords/string/date.js +98 -0
  42. package/out/keywords/string/digits.d.ts +7 -0
  43. package/out/keywords/string/digits.js +2 -0
  44. package/out/keywords/string/email.d.ts +7 -0
  45. package/out/keywords/string/email.js +4 -0
  46. package/out/keywords/string/integer.d.ts +15 -0
  47. package/out/keywords/string/integer.js +16 -0
  48. package/out/keywords/string/ip.d.ts +20 -0
  49. package/out/keywords/string/ip.js +23 -0
  50. package/out/keywords/string/json.d.ts +14 -0
  51. package/out/keywords/string/json.js +45 -0
  52. package/out/keywords/string/lower.d.ts +14 -0
  53. package/out/keywords/string/lower.js +12 -0
  54. package/out/keywords/string/normalize.d.ts +72 -0
  55. package/out/keywords/string/normalize.js +43 -0
  56. package/out/keywords/string/numeric.d.ts +14 -0
  57. package/out/keywords/string/numeric.js +13 -0
  58. package/out/keywords/string/semver.d.ts +7 -0
  59. package/out/keywords/string/semver.js +4 -0
  60. package/out/keywords/string/string.d.ts +57 -0
  61. package/out/keywords/string/string.js +41 -0
  62. package/out/keywords/string/trim.d.ts +14 -0
  63. package/out/keywords/string/trim.js +14 -0
  64. package/out/keywords/string/upper.d.ts +14 -0
  65. package/out/keywords/string/upper.js +12 -0
  66. package/out/keywords/string/url.d.ts +14 -0
  67. package/out/keywords/string/url.js +37 -0
  68. package/out/keywords/string/utils.d.ts +2 -0
  69. package/out/keywords/string/utils.js +10 -0
  70. package/out/keywords/string/uuid.d.ts +38 -0
  71. package/out/keywords/string/uuid.js +19 -0
  72. package/out/keywords/ts.d.ts +53 -0
  73. package/out/keywords/ts.js +51 -0
  74. package/out/keywords/utils.d.ts +1 -0
  75. package/out/keywords/utils.js +2 -0
  76. package/out/module.d.ts +21 -9
  77. package/out/module.js +3 -3
  78. package/out/parser/definition.d.ts +20 -15
  79. package/out/parser/definition.js +5 -5
  80. package/out/parser/objectLiteral.d.ts +53 -35
  81. package/out/parser/objectLiteral.js +75 -50
  82. package/out/parser/semantic/bounds.d.ts +10 -9
  83. package/out/parser/semantic/default.d.ts +8 -0
  84. package/out/parser/semantic/default.js +1 -0
  85. package/out/parser/semantic/divisor.d.ts +5 -5
  86. package/out/parser/semantic/divisor.js +1 -0
  87. package/out/parser/semantic/infer.d.ts +21 -12
  88. package/out/parser/semantic/infer.js +1 -0
  89. package/out/parser/semantic/keyof.d.ts +7 -0
  90. package/out/parser/semantic/keyof.js +1 -0
  91. package/out/parser/semantic/utils.d.ts +3 -3
  92. package/out/parser/semantic/utils.js +1 -0
  93. package/out/parser/semantic/validate.d.ts +21 -17
  94. package/out/parser/semantic/validate.js +0 -1
  95. package/out/parser/string/reduce/dynamic.d.ts +16 -14
  96. package/out/parser/string/reduce/dynamic.js +8 -7
  97. package/out/parser/string/reduce/shared.d.ts +15 -15
  98. package/out/parser/string/reduce/shared.js +4 -2
  99. package/out/parser/string/reduce/static.d.ts +22 -23
  100. package/out/parser/string/reduce/static.js +1 -0
  101. package/out/parser/string/shift/operand/date.d.ts +2 -4
  102. package/out/parser/string/shift/operand/date.js +1 -1
  103. package/out/parser/string/shift/operand/enclosed.d.ts +10 -6
  104. package/out/parser/string/shift/operand/enclosed.js +5 -4
  105. package/out/parser/string/shift/operand/genericArgs.d.ts +13 -13
  106. package/out/parser/string/shift/operand/genericArgs.js +7 -12
  107. package/out/parser/string/shift/operand/operand.d.ts +8 -7
  108. package/out/parser/string/shift/operand/operand.js +5 -6
  109. package/out/parser/string/shift/operand/unenclosed.d.ts +29 -16
  110. package/out/parser/string/shift/operand/unenclosed.js +9 -12
  111. package/out/parser/string/shift/operator/bounds.d.ts +15 -20
  112. package/out/parser/string/shift/operator/bounds.js +11 -16
  113. package/out/parser/string/shift/operator/default.d.ts +19 -0
  114. package/out/parser/string/shift/operator/default.js +17 -0
  115. package/out/parser/string/shift/operator/divisor.d.ts +3 -3
  116. package/out/parser/string/shift/operator/divisor.js +1 -1
  117. package/out/parser/string/shift/operator/operator.d.ts +7 -6
  118. package/out/parser/string/shift/operator/operator.js +1 -1
  119. package/out/parser/string/shift/scanner.d.ts +26 -30
  120. package/out/parser/string/shift/scanner.js +23 -20
  121. package/out/parser/string/string.d.ts +14 -11
  122. package/out/parser/string/string.js +5 -2
  123. package/out/parser/tuple.d.ts +21 -19
  124. package/out/parser/tuple.js +12 -23
  125. package/out/scope.d.ts +102 -55
  126. package/out/scope.js +61 -60
  127. package/out/subtypes/array.d.ts +13 -0
  128. package/out/subtypes/array.js +1 -0
  129. package/out/subtypes/base.d.ts +84 -0
  130. package/out/subtypes/base.js +1 -0
  131. package/out/subtypes/date.d.ts +11 -0
  132. package/out/subtypes/date.js +1 -0
  133. package/out/subtypes/instantiate.d.ts +16 -0
  134. package/out/subtypes/instantiate.js +1 -0
  135. package/out/subtypes/morph.d.ts +13 -0
  136. package/out/subtypes/morph.js +1 -0
  137. package/out/subtypes/number.d.ts +12 -0
  138. package/out/subtypes/number.js +1 -0
  139. package/out/subtypes/object.d.ts +33 -0
  140. package/out/subtypes/object.js +1 -0
  141. package/out/subtypes/string.d.ts +13 -0
  142. package/out/subtypes/string.js +1 -0
  143. package/out/subtypes/validator.d.ts +11 -0
  144. package/out/subtypes/validator.js +1 -0
  145. package/out/type.d.ts +30 -49
  146. package/out/type.js +19 -14
  147. package/package.json +46 -45
  148. package/__tests__/array.test.ts +0 -391
  149. package/__tests__/badDefinitionType.test.ts +0 -58
  150. package/__tests__/basis.test.ts +0 -50
  151. package/__tests__/bounds.test.ts +0 -318
  152. package/__tests__/cast.test.ts +0 -37
  153. package/__tests__/completions.test.ts +0 -51
  154. package/__tests__/config.test.ts +0 -96
  155. package/__tests__/dateLiteral.test.ts +0 -36
  156. package/__tests__/declared.test.ts +0 -124
  157. package/__tests__/discrimination.test.ts +0 -74
  158. package/__tests__/divisor.test.ts +0 -114
  159. package/__tests__/enclosed.test.ts +0 -107
  160. package/__tests__/examples.test.ts +0 -56
  161. package/__tests__/expressions.test.ts +0 -210
  162. package/__tests__/generateBenchData.ts +0 -89
  163. package/__tests__/generated/cyclic.ts +0 -3058
  164. package/__tests__/generic.test.ts +0 -313
  165. package/__tests__/group.test.ts +0 -85
  166. package/__tests__/hkt.test.ts +0 -22
  167. package/__tests__/imports.test.ts +0 -126
  168. package/__tests__/instanceof.test.ts +0 -104
  169. package/__tests__/intersection.test.ts +0 -108
  170. package/__tests__/keyTraversal.test.ts +0 -77
  171. package/__tests__/keyof.test.ts +0 -150
  172. package/__tests__/keywords.test.ts +0 -214
  173. package/__tests__/literal.test.ts +0 -90
  174. package/__tests__/match.bench.ts +0 -31
  175. package/__tests__/match.test.ts +0 -234
  176. package/__tests__/methods.bench.ts +0 -22
  177. package/__tests__/narrow.test.ts +0 -100
  178. package/__tests__/object.bench.ts +0 -28
  179. package/__tests__/objectLiteral.test.ts +0 -442
  180. package/__tests__/operand.bench.ts +0 -45
  181. package/__tests__/operator.bench.ts +0 -130
  182. package/__tests__/pipe.test.ts +0 -501
  183. package/__tests__/realWorld.test.ts +0 -63
  184. package/__tests__/regex.test.ts +0 -68
  185. package/__tests__/scope.bench.ts +0 -39
  186. package/__tests__/scope.test.ts +0 -374
  187. package/__tests__/serialization.test.ts +0 -19
  188. package/__tests__/string.test.ts +0 -52
  189. package/__tests__/submodule.test.ts +0 -86
  190. package/__tests__/this.test.ts +0 -83
  191. package/__tests__/thunk.test.ts +0 -86
  192. package/__tests__/traverse.test.ts +0 -141
  193. package/__tests__/tsGenerics.test.ts +0 -12
  194. package/__tests__/type.test.ts +0 -36
  195. package/__tests__/typeReference.test.ts +0 -39
  196. package/__tests__/unenclosed.test.ts +0 -136
  197. package/__tests__/union.test.ts +0 -214
  198. package/ark.ts +0 -47
  199. package/generic.ts +0 -69
  200. package/main.ts +0 -6
  201. package/match.ts +0 -218
  202. package/module.ts +0 -15
  203. package/out/ark.d.ts +0 -28
  204. package/out/ark.js +0 -10
  205. package/out/ark.js.map +0 -1
  206. package/out/generic.js.map +0 -1
  207. package/out/main.d.ts +0 -6
  208. package/out/main.js +0 -5
  209. package/out/main.js.map +0 -1
  210. package/out/match.d.ts +0 -71
  211. package/out/match.js +0 -52
  212. package/out/match.js.map +0 -1
  213. package/out/module.js.map +0 -1
  214. package/out/parser/definition.js.map +0 -1
  215. package/out/parser/generic.d.ts +0 -16
  216. package/out/parser/generic.js +0 -15
  217. package/out/parser/generic.js.map +0 -1
  218. package/out/parser/objectLiteral.js.map +0 -1
  219. package/out/parser/semantic/bounds.js.map +0 -1
  220. package/out/parser/semantic/divisor.js.map +0 -1
  221. package/out/parser/semantic/infer.js.map +0 -1
  222. package/out/parser/semantic/utils.js.map +0 -1
  223. package/out/parser/semantic/validate.js.map +0 -1
  224. package/out/parser/string/reduce/dynamic.js.map +0 -1
  225. package/out/parser/string/reduce/shared.js.map +0 -1
  226. package/out/parser/string/reduce/static.js.map +0 -1
  227. package/out/parser/string/shift/operand/date.js.map +0 -1
  228. package/out/parser/string/shift/operand/enclosed.js.map +0 -1
  229. package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
  230. package/out/parser/string/shift/operand/operand.js.map +0 -1
  231. package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
  232. package/out/parser/string/shift/operator/bounds.js.map +0 -1
  233. package/out/parser/string/shift/operator/divisor.js.map +0 -1
  234. package/out/parser/string/shift/operator/operator.js.map +0 -1
  235. package/out/parser/string/shift/scanner.js.map +0 -1
  236. package/out/parser/string/string.js.map +0 -1
  237. package/out/parser/tuple.js.map +0 -1
  238. package/out/scope.js.map +0 -1
  239. package/out/type.js.map +0 -1
  240. package/parser/definition.ts +0 -143
  241. package/parser/generic.ts +0 -66
  242. package/parser/objectLiteral.ts +0 -233
  243. package/parser/semantic/bounds.ts +0 -62
  244. package/parser/semantic/divisor.ts +0 -11
  245. package/parser/semantic/infer.ts +0 -141
  246. package/parser/semantic/utils.ts +0 -15
  247. package/parser/semantic/validate.ts +0 -117
  248. package/parser/string/reduce/dynamic.ts +0 -208
  249. package/parser/string/reduce/shared.ts +0 -99
  250. package/parser/string/reduce/static.ts +0 -296
  251. package/parser/string/shift/operand/date.ts +0 -55
  252. package/parser/string/shift/operand/enclosed.ts +0 -123
  253. package/parser/string/shift/operand/genericArgs.ts +0 -128
  254. package/parser/string/shift/operand/operand.ts +0 -42
  255. package/parser/string/shift/operand/unenclosed.ts +0 -217
  256. package/parser/string/shift/operator/bounds.ts +0 -270
  257. package/parser/string/shift/operator/divisor.ts +0 -33
  258. package/parser/string/shift/operator/operator.ts +0 -71
  259. package/parser/string/shift/scanner.ts +0 -210
  260. package/parser/string/string.ts +0 -85
  261. package/parser/tuple.ts +0 -542
  262. package/scope.ts +0 -291
  263. package/type.ts +0 -266
@@ -0,0 +1,45 @@
1
+ import { intrinsic, rootNode } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ const jsonStringDescription = "a JSON string";
4
+ const isParsableJson = (s) => {
5
+ try {
6
+ JSON.parse(s);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ };
13
+ const $root = rootNode({
14
+ domain: "string",
15
+ predicate: {
16
+ meta: jsonStringDescription,
17
+ predicate: isParsableJson
18
+ }
19
+ });
20
+ export const json = submodule({
21
+ $root,
22
+ parse: rootNode({
23
+ in: "string",
24
+ morphs: (s, ctx) => {
25
+ if (s.length === 0) {
26
+ return ctx.error({
27
+ code: "predicate",
28
+ expected: jsonStringDescription,
29
+ actual: "empty"
30
+ });
31
+ }
32
+ try {
33
+ return JSON.parse(s);
34
+ }
35
+ catch (e) {
36
+ return ctx.error({
37
+ code: "predicate",
38
+ expected: jsonStringDescription,
39
+ problem: `must be ${jsonStringDescription} (${e})`
40
+ });
41
+ }
42
+ },
43
+ declaredOut: intrinsic.json
44
+ })
45
+ });
@@ -0,0 +1,14 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type lowercase = constrain<string, Branded<"lowercase">>;
5
+ }
6
+ export type lower = Submodule<{
7
+ $root: (In: string) => To<string.lowercase>;
8
+ preformatted: string.lowercase;
9
+ }>;
10
+ export declare const lower: import("../../module.ts").Module<{
11
+ $root: object;
12
+ preformatted: object;
13
+ }>;
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ import { regexStringNode } from "./utils.js";
4
+ const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
5
+ export const lower = submodule({
6
+ $root: rootNode({
7
+ in: "string",
8
+ morphs: (s) => s.toLowerCase(),
9
+ declaredOut: preformatted
10
+ }),
11
+ preformatted
12
+ });
@@ -0,0 +1,72 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type normalized = normalized.NFC;
5
+ namespace normalized {
6
+ type NFC = constrain<string, Branded<"normalized.NFC">>;
7
+ type NFD = constrain<string, Branded<"normalized.NFD">>;
8
+ type NFKC = constrain<string, Branded<"normalized.NFKC">>;
9
+ type NFKD = constrain<string, Branded<"normalized.NFKD">>;
10
+ }
11
+ }
12
+ export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
13
+ export type NormalizedForm = (typeof normalizedForms)[number];
14
+ export type NFC = Submodule<{
15
+ $root: (In: string) => To<string.normalized.NFC>;
16
+ preformatted: string.normalized.NFC;
17
+ }>;
18
+ export declare const NFC: import("../../module.ts").Module<{
19
+ $root: object;
20
+ preformatted: object;
21
+ }>;
22
+ export type NFD = Submodule<{
23
+ $root: (In: string) => To<string.normalized.NFD>;
24
+ preformatted: string.normalized.NFD;
25
+ }>;
26
+ export declare const NFD: import("../../module.ts").Module<{
27
+ $root: object;
28
+ preformatted: object;
29
+ }>;
30
+ export type NFKC = Submodule<{
31
+ $root: (In: string) => To<string.normalized.NFKC>;
32
+ preformatted: string.normalized.NFKC;
33
+ }>;
34
+ export declare const NFKC: import("../../module.ts").Module<{
35
+ $root: object;
36
+ preformatted: object;
37
+ }>;
38
+ export type NFKD = Submodule<{
39
+ $root: (In: string) => To<string.normalized.NFKD>;
40
+ preformatted: string.normalized.NFKD;
41
+ }>;
42
+ export declare const NFKD: import("../../module.ts").Module<{
43
+ $root: object;
44
+ preformatted: object;
45
+ }>;
46
+ export declare const normalize: import("../../module.ts").Module<{
47
+ $root: object;
48
+ NFC: Submodule<{
49
+ $root: object;
50
+ preformatted: object;
51
+ }>;
52
+ NFD: Submodule<{
53
+ $root: object;
54
+ preformatted: object;
55
+ }>;
56
+ NFKC: Submodule<{
57
+ $root: object;
58
+ preformatted: object;
59
+ }>;
60
+ NFKD: Submodule<{
61
+ $root: object;
62
+ preformatted: object;
63
+ }>;
64
+ }>;
65
+ export type normalize = Submodule<{
66
+ $root: (In: string) => To<string.normalized.NFC>;
67
+ NFC: NFC;
68
+ NFD: NFD;
69
+ NFKC: NFKC;
70
+ NFKD: NFKD;
71
+ }>;
72
+ export {};
@@ -0,0 +1,43 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { flatMorph } from "@ark/util";
3
+ import { submodule } from "../utils.js";
4
+ export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
5
+ const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
6
+ form,
7
+ rootNode({
8
+ domain: "string",
9
+ predicate: (s) => s.normalize(form) === s,
10
+ meta: `${form}-normalized unicode`
11
+ })
12
+ ]);
13
+ const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
14
+ form,
15
+ rootNode({
16
+ in: "string",
17
+ morphs: (s) => s.normalize(form),
18
+ declaredOut: preformattedNodes[form]
19
+ })
20
+ ]);
21
+ export const NFC = submodule({
22
+ $root: normalizeNodes.NFC,
23
+ preformatted: preformattedNodes.NFC
24
+ });
25
+ export const NFD = submodule({
26
+ $root: normalizeNodes.NFD,
27
+ preformatted: preformattedNodes.NFD
28
+ });
29
+ export const NFKC = submodule({
30
+ $root: normalizeNodes.NFKC,
31
+ preformatted: preformattedNodes.NFKC
32
+ });
33
+ export const NFKD = submodule({
34
+ $root: normalizeNodes.NFKD,
35
+ preformatted: preformattedNodes.NFKD
36
+ });
37
+ export const normalize = submodule({
38
+ $root: "NFC",
39
+ NFC,
40
+ NFD,
41
+ NFKC,
42
+ NFKD
43
+ });
@@ -0,0 +1,14 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type numeric = constrain<string, Branded<"numeric">>;
5
+ }
6
+ export declare const numeric: import("../../module.ts").Module<{
7
+ $root: object;
8
+ parse: object;
9
+ }>;
10
+ export type numeric = Submodule<{
11
+ $root: string.numeric;
12
+ parse: (In: string.numeric) => To<number>;
13
+ }>;
14
+ export {};
@@ -0,0 +1,13 @@
1
+ import { intrinsic, rootNode } from "@ark/schema";
2
+ import { wellFormedNumberMatcher } from "@ark/util";
3
+ import { submodule } from "../utils.js";
4
+ import { regexStringNode } from "./utils.js";
5
+ const $root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
+ export const numeric = submodule({
7
+ $root,
8
+ parse: rootNode({
9
+ in: $root,
10
+ morphs: (s) => Number.parseFloat(s),
11
+ declaredOut: intrinsic.number
12
+ })
13
+ });
@@ -0,0 +1,7 @@
1
+ import type { Branded, constrain } from "../ast.ts";
2
+ declare namespace string {
3
+ type semver = constrain<string, Branded<"semver">>;
4
+ }
5
+ export declare const semver: import("@ark/schema").IntersectionNode;
6
+ export type semver = string.semver;
7
+ export {};
@@ -0,0 +1,4 @@
1
+ import { regexStringNode } from "./utils.js";
2
+ // https://semver.org/
3
+ const semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
4
+ export const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
@@ -0,0 +1,57 @@
1
+ import { type Constraint, type NodeSchema } from "@ark/schema";
2
+ import type { Module, Submodule } from "../../module.ts";
3
+ import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
4
+ import { alpha } from "./alpha.ts";
5
+ import { alphanumeric } from "./alphanumeric.ts";
6
+ import { capitalize } from "./capitalize.ts";
7
+ import { creditCard } from "./creditCard.ts";
8
+ import { date } from "./date.ts";
9
+ import { digits } from "./digits.ts";
10
+ import { email } from "./email.ts";
11
+ import { integer } from "./integer.ts";
12
+ import { ip } from "./ip.ts";
13
+ import { json } from "./json.ts";
14
+ import { lower } from "./lower.ts";
15
+ import { normalize } from "./normalize.ts";
16
+ import { numeric } from "./numeric.ts";
17
+ import { semver } from "./semver.ts";
18
+ import { trim } from "./trim.ts";
19
+ import { upper } from "./upper.ts";
20
+ import { uuid } from "./uuid.ts";
21
+ export declare const string: Module<string.submodule>;
22
+ export declare namespace string {
23
+ type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
24
+ type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
25
+ type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
26
+ type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
27
+ type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
28
+ type matching<rule> = constrain<string, Matching<rule>>;
29
+ type narrowed = constrain<string, Narrowed>;
30
+ type branded<rule> = constrain<string, Branded<rule>>;
31
+ type is<constraints extends Constraints> = constrain<string, constraints>;
32
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
33
+ exclusive: true;
34
+ } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
35
+ exclusive: true;
36
+ } ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
37
+ type submodule = Submodule<{
38
+ $root: string;
39
+ alpha: alpha;
40
+ alphanumeric: alphanumeric;
41
+ digits: digits;
42
+ numeric: numeric;
43
+ integer: integer;
44
+ creditCard: creditCard;
45
+ email: email;
46
+ uuid: uuid;
47
+ semver: semver;
48
+ ip: ip;
49
+ json: json;
50
+ date: date;
51
+ trim: trim;
52
+ normalize: normalize;
53
+ capitalize: capitalize;
54
+ lower: lower;
55
+ upper: upper;
56
+ }>;
57
+ }
@@ -0,0 +1,41 @@
1
+ import { intrinsic } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ import { alpha } from "./alpha.js";
4
+ import { alphanumeric } from "./alphanumeric.js";
5
+ import { capitalize } from "./capitalize.js";
6
+ import { creditCard } from "./creditCard.js";
7
+ import { date } from "./date.js";
8
+ import { digits } from "./digits.js";
9
+ import { email } from "./email.js";
10
+ import { integer } from "./integer.js";
11
+ import { ip } from "./ip.js";
12
+ import { json } from "./json.js";
13
+ import { lower } from "./lower.js";
14
+ import { normalize } from "./normalize.js";
15
+ import { numeric } from "./numeric.js";
16
+ import { semver } from "./semver.js";
17
+ import { trim } from "./trim.js";
18
+ import { upper } from "./upper.js";
19
+ import { url } from "./url.js";
20
+ import { uuid } from "./uuid.js";
21
+ export const string = submodule({
22
+ $root: intrinsic.string,
23
+ numeric,
24
+ integer,
25
+ alpha,
26
+ alphanumeric,
27
+ digits,
28
+ semver,
29
+ ip,
30
+ creditCard,
31
+ email,
32
+ uuid,
33
+ url,
34
+ json,
35
+ trim,
36
+ upper,
37
+ lower,
38
+ normalize,
39
+ capitalize,
40
+ date
41
+ });
@@ -0,0 +1,14 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type trimmed = constrain<string, Branded<"trimmed">>;
5
+ }
6
+ export type trim = Submodule<{
7
+ $root: (In: string) => To<string.trimmed>;
8
+ preformatted: string.trimmed;
9
+ }>;
10
+ export declare const trim: import("../../module.ts").Module<{
11
+ $root: object;
12
+ preformatted: object;
13
+ }>;
14
+ export {};
@@ -0,0 +1,14 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ import { regexStringNode } from "./utils.js";
4
+ const preformatted = regexStringNode(
5
+ // no leading or trailing whitespace
6
+ /^\S.*\S$|^\S?$/, "trimmed");
7
+ export const trim = submodule({
8
+ $root: rootNode({
9
+ in: "string",
10
+ morphs: (s) => s.trim(),
11
+ declaredOut: preformatted
12
+ }),
13
+ preformatted
14
+ });
@@ -0,0 +1,14 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type uppercase = constrain<string, Branded<"uppercase">>;
5
+ }
6
+ export type upper = Submodule<{
7
+ $root: (In: string) => To<string.uppercase>;
8
+ preformatted: string.uppercase;
9
+ }>;
10
+ export declare const upper: import("../../module.ts").Module<{
11
+ $root: object;
12
+ preformatted: object;
13
+ }>;
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ import { regexStringNode } from "./utils.js";
4
+ const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
5
+ export const upper = submodule({
6
+ $root: rootNode({
7
+ in: "string",
8
+ morphs: (s) => s.toUpperCase(),
9
+ declaredOut: preformatted
10
+ }),
11
+ preformatted
12
+ });
@@ -0,0 +1,14 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain, To } from "../ast.ts";
3
+ declare namespace string {
4
+ type url = constrain<string, Branded<"url">>;
5
+ }
6
+ export declare const url: import("../../module.ts").Module<{
7
+ $root: object;
8
+ parse: object;
9
+ }>;
10
+ export type url = Submodule<{
11
+ $root: string.url;
12
+ parse: (In: string.url) => To<URL>;
13
+ }>;
14
+ export {};
@@ -0,0 +1,37 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { submodule } from "../utils.js";
3
+ const isParsableUrl = (s) => {
4
+ if (URL.canParse)
5
+ return URL.canParse(s);
6
+ // Can be removed once Node 18 is EOL
7
+ try {
8
+ new URL(s);
9
+ return true;
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ };
15
+ const $root = rootNode({
16
+ domain: "string",
17
+ predicate: {
18
+ meta: "a URL string",
19
+ predicate: isParsableUrl
20
+ }
21
+ });
22
+ export const url = submodule({
23
+ $root,
24
+ parse: rootNode({
25
+ declaredIn: $root,
26
+ in: "string",
27
+ morphs: (s, ctx) => {
28
+ try {
29
+ return new URL(s);
30
+ }
31
+ catch {
32
+ return ctx.error("a URL string");
33
+ }
34
+ },
35
+ declaredOut: rootNode(URL)
36
+ })
37
+ });
@@ -0,0 +1,2 @@
1
+ import { type IntersectionNode } from "@ark/schema";
2
+ export declare const regexStringNode: (regex: RegExp, description: string) => IntersectionNode;
@@ -0,0 +1,10 @@
1
+ import { node } from "@ark/schema";
2
+ // Non-trivial expressions should have an explanation or attribution
3
+ export const regexStringNode = (regex, description) => node("intersection", {
4
+ domain: "string",
5
+ pattern: {
6
+ rule: regex.source,
7
+ flags: regex.flags,
8
+ meta: description
9
+ }
10
+ });
@@ -0,0 +1,38 @@
1
+ import type { Submodule } from "../../module.ts";
2
+ import type { Branded, constrain } from "../ast.ts";
3
+ export declare const uuid: import("../../module.ts").Module<{
4
+ $root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
+ v4: object;
6
+ v6: object;
7
+ v1: object;
8
+ v2: object;
9
+ v3: object;
10
+ v5: object;
11
+ v7: object;
12
+ v8: object;
13
+ }>;
14
+ declare namespace string {
15
+ type uuid = constrain<string, Branded<"uuid">>;
16
+ namespace uuid {
17
+ type v1 = constrain<string, Branded<"uuid.v1">>;
18
+ type v2 = constrain<string, Branded<"uuid.v2">>;
19
+ type v3 = constrain<string, Branded<"uuid.v3">>;
20
+ type v4 = constrain<string, Branded<"uuid.v4">>;
21
+ type v5 = constrain<string, Branded<"uuid.v5">>;
22
+ type v6 = constrain<string, Branded<"uuid.v6">>;
23
+ type v7 = constrain<string, Branded<"uuid.v7">>;
24
+ type v8 = constrain<string, Branded<"uuid.v8">>;
25
+ }
26
+ }
27
+ export type uuid = Submodule<{
28
+ $root: string.uuid;
29
+ v1: string.uuid.v1;
30
+ v2: string.uuid.v2;
31
+ v3: string.uuid.v3;
32
+ v4: string.uuid.v4;
33
+ v5: string.uuid.v5;
34
+ v6: string.uuid.v6;
35
+ v7: string.uuid.v7;
36
+ v8: string.uuid.v8;
37
+ }>;
38
+ export {};
@@ -0,0 +1,19 @@
1
+ import { submodule } from "../utils.js";
2
+ import { regexStringNode } from "./utils.js";
3
+ // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
4
+ export const uuid = submodule({
5
+ // the meta tuple expression ensures the error message does not delegate
6
+ // to the individual branches, which are too detailed
7
+ $root: ["versioned | nil | max", "@", "a UUID"],
8
+ "#nil": "'00000000-0000-0000-0000-000000000000'",
9
+ "#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
10
+ "#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
11
+ v1: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv1"),
12
+ v2: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-2[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv2"),
13
+ v3: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv3"),
14
+ v4: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv4"),
15
+ v5: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv5"),
16
+ v6: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv6"),
17
+ v7: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv7"),
18
+ v8: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv8")
19
+ });
@@ -0,0 +1,53 @@
1
+ import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
2
+ import type { Module, Submodule } from "../module.ts";
3
+ declare class RecordHkt extends Hkt<[Key, unknown]> {
4
+ body: Record<this[0], this[1]>;
5
+ }
6
+ declare const Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], RecordHkt>;
7
+ declare class PickHkt extends Hkt<[object, Key]> {
8
+ body: pick<this[0], this[1] & keyof this[0]>;
9
+ }
10
+ declare const Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], PickHkt>;
11
+ declare class OmitHkt extends Hkt<[object, Key]> {
12
+ body: omit<this[0], this[1] & keyof this[0]>;
13
+ }
14
+ declare const Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], OmitHkt>;
15
+ declare class PartialHkt extends Hkt<[object]> {
16
+ body: show<Partial<this[0]>>;
17
+ }
18
+ declare const Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], PartialHkt>;
19
+ declare class RequiredHkt extends Hkt<[object]> {
20
+ body: show<Required<this[0]>>;
21
+ }
22
+ declare const Required: import("@ark/schema").GenericRoot<readonly [["T", object]], RequiredHkt>;
23
+ declare class ExcludeHkt extends Hkt<[unknown, unknown]> {
24
+ body: Exclude<this[0], this[1]>;
25
+ }
26
+ declare const Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExcludeHkt>;
27
+ declare class ExtractHkt extends Hkt<[unknown, unknown]> {
28
+ body: Extract<this[0], this[1]>;
29
+ }
30
+ declare const Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
31
+ export declare const arkTs: Module<arkTs>;
32
+ export type arkTs = Submodule<{
33
+ bigint: bigint;
34
+ boolean: boolean;
35
+ false: false;
36
+ never: never;
37
+ null: null;
38
+ number: number;
39
+ object: object;
40
+ string: string;
41
+ symbol: symbol;
42
+ true: true;
43
+ unknown: unknown;
44
+ undefined: undefined;
45
+ Record: typeof Record.t;
46
+ Pick: typeof Pick.t;
47
+ Omit: typeof Omit.t;
48
+ Exclude: typeof Exclude.t;
49
+ Extract: typeof Extract.t;
50
+ Partial: typeof Partial.t;
51
+ Required: typeof Required.t;
52
+ }>;
53
+ export {};
@@ -0,0 +1,51 @@
1
+ import { genericNode, intrinsic } from "@ark/schema";
2
+ import { Hkt } from "@ark/util";
3
+ import { submodule } from "./utils.js";
4
+ class RecordHkt extends Hkt {
5
+ }
6
+ const Record = genericNode(["K", intrinsic.key], "V")(args => ({
7
+ domain: "object",
8
+ index: {
9
+ signature: args.K,
10
+ value: args.V
11
+ }
12
+ }), RecordHkt);
13
+ class PickHkt extends Hkt {
14
+ }
15
+ const Pick = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.pick(args.K), PickHkt);
16
+ class OmitHkt extends Hkt {
17
+ }
18
+ const Omit = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.omit(args.K), OmitHkt);
19
+ class PartialHkt extends Hkt {
20
+ }
21
+ const Partial = genericNode(["T", intrinsic.object])(args => args.T.partial(), PartialHkt);
22
+ class RequiredHkt extends Hkt {
23
+ }
24
+ const Required = genericNode(["T", intrinsic.object])(args => args.T.required(), RequiredHkt);
25
+ class ExcludeHkt extends Hkt {
26
+ }
27
+ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt);
28
+ class ExtractHkt extends Hkt {
29
+ }
30
+ const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
31
+ export const arkTs = submodule({
32
+ bigint: intrinsic.bigint,
33
+ boolean: intrinsic.boolean,
34
+ false: intrinsic.false,
35
+ never: intrinsic.never,
36
+ null: intrinsic.null,
37
+ number: intrinsic.number,
38
+ object: intrinsic.object,
39
+ string: intrinsic.string,
40
+ symbol: intrinsic.symbol,
41
+ true: intrinsic.true,
42
+ unknown: intrinsic.unknown,
43
+ undefined: intrinsic.undefined,
44
+ Record,
45
+ Pick,
46
+ Omit,
47
+ Exclude,
48
+ Extract,
49
+ Partial,
50
+ Required
51
+ });
@@ -0,0 +1 @@
1
+ export declare const submodule: import("../scope.ts").ModuleParser;
@@ -0,0 +1,2 @@
1
+ import { module } from "../scope.js";
2
+ export const submodule = module;