arktype 2.0.0-rc.1 → 2.0.0-rc.11

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 (141) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +47 -48
  3. package/out/generic.js +6 -8
  4. package/out/index.d.ts +4 -4
  5. package/out/index.js +2 -2
  6. package/out/keywords/builtins.js +2 -2
  7. package/out/keywords/constructors/Array.d.ts +2 -2
  8. package/out/keywords/constructors/Array.js +7 -7
  9. package/out/keywords/constructors/Date.d.ts +32 -0
  10. package/out/keywords/constructors/FormData.d.ts +2 -2
  11. package/out/keywords/constructors/FormData.js +8 -8
  12. package/out/keywords/constructors/TypedArray.js +2 -2
  13. package/out/keywords/constructors/constructors.d.ts +0 -1
  14. package/out/keywords/constructors/constructors.js +2 -2
  15. package/out/keywords/inference.d.ts +228 -0
  16. package/out/keywords/keywords.d.ts +62 -0
  17. package/out/keywords/{ark.js → keywords.js} +11 -8
  18. package/out/keywords/number/epoch.d.ts +1 -2
  19. package/out/keywords/number/epoch.js +2 -2
  20. package/out/keywords/number/integer.js +2 -2
  21. package/out/keywords/number/number.d.ts +32 -6
  22. package/out/keywords/number/number.js +17 -5
  23. package/out/keywords/string/alpha.d.ts +1 -1
  24. package/out/keywords/string/alphanumeric.d.ts +1 -1
  25. package/out/keywords/string/capitalize.d.ts +2 -2
  26. package/out/keywords/string/capitalize.js +4 -4
  27. package/out/keywords/string/creditCard.d.ts +1 -1
  28. package/out/keywords/string/creditCard.js +2 -2
  29. package/out/keywords/string/date.d.ts +4 -8
  30. package/out/keywords/string/date.js +16 -16
  31. package/out/keywords/string/digits.d.ts +1 -1
  32. package/out/keywords/string/email.d.ts +1 -1
  33. package/out/keywords/string/integer.d.ts +2 -2
  34. package/out/keywords/string/integer.js +7 -7
  35. package/out/keywords/string/ip.d.ts +2 -2
  36. package/out/keywords/string/ip.js +5 -5
  37. package/out/keywords/string/json.d.ts +3 -2
  38. package/out/keywords/string/json.js +24 -16
  39. package/out/keywords/string/lower.d.ts +2 -2
  40. package/out/keywords/string/lower.js +4 -4
  41. package/out/keywords/string/normalize.d.ts +23 -27
  42. package/out/keywords/string/normalize.js +14 -14
  43. package/out/keywords/string/numeric.d.ts +2 -2
  44. package/out/keywords/string/numeric.js +7 -7
  45. package/out/keywords/string/semver.d.ts +1 -1
  46. package/out/keywords/string/string.d.ts +39 -42
  47. package/out/keywords/string/string.js +3 -3
  48. package/out/keywords/string/trim.d.ts +2 -2
  49. package/out/keywords/string/trim.js +4 -4
  50. package/out/keywords/string/upper.d.ts +2 -2
  51. package/out/keywords/string/upper.js +4 -4
  52. package/out/keywords/string/url.d.ts +2 -2
  53. package/out/keywords/string/url.js +8 -8
  54. package/out/keywords/string/uuid.d.ts +11 -11
  55. package/out/keywords/string/uuid.js +3 -3
  56. package/out/keywords/ts.d.ts +38 -1
  57. package/out/keywords/ts.js +20 -4
  58. package/out/keywords/utils.d.ts +1 -1
  59. package/out/keywords/utils.js +1 -1
  60. package/out/{subtypes → methods}/array.d.ts +6 -6
  61. package/out/methods/base.d.ts +96 -0
  62. package/out/{subtypes → methods}/date.d.ts +5 -5
  63. package/out/{subtypes → methods}/instantiate.d.ts +5 -4
  64. package/out/methods/morph.d.ts +12 -0
  65. package/out/{subtypes → methods}/number.d.ts +6 -6
  66. package/out/methods/object.d.ts +81 -0
  67. package/out/{subtypes → methods}/string.d.ts +7 -7
  68. package/out/{subtypes → methods}/validator.d.ts +2 -2
  69. package/out/module.d.ts +2 -2
  70. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  71. package/out/parser/ast/default.d.ts +8 -0
  72. package/out/parser/{semantic → ast}/infer.d.ts +11 -11
  73. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  74. package/out/parser/{semantic → ast}/validate.d.ts +6 -6
  75. package/out/parser/definition.d.ts +8 -9
  76. package/out/parser/objectLiteral.d.ts +11 -37
  77. package/out/parser/objectLiteral.js +6 -24
  78. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
  79. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  80. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  81. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  82. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  83. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
  84. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  85. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  86. package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
  87. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  88. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  89. package/out/parser/{string/shift → shift}/operator/default.js +1 -6
  90. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  91. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  92. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  93. package/out/parser/{string/string.js → string.js} +2 -0
  94. package/out/parser/tuple.d.ts +54 -43
  95. package/out/parser/tuple.js +36 -30
  96. package/out/scope.d.ts +32 -39
  97. package/out/scope.js +43 -35
  98. package/out/type.d.ts +24 -21
  99. package/out/type.js +14 -10
  100. package/package.json +3 -3
  101. package/out/intersect.d.ts +0 -28
  102. package/out/keys.d.ts +0 -16
  103. package/out/keywords/ark.d.ts +0 -39
  104. package/out/keywords/ast.d.ts +0 -193
  105. package/out/parser/semantic/default.d.ts +0 -9
  106. package/out/parser/semantic/default.js +0 -1
  107. package/out/subtypes/base.d.ts +0 -85
  108. package/out/subtypes/morph.d.ts +0 -13
  109. package/out/subtypes/object.d.ts +0 -33
  110. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  111. /package/out/keywords/{ast.js → inference.js} +0 -0
  112. /package/out/{subtypes → methods}/array.js +0 -0
  113. /package/out/{subtypes → methods}/base.js +0 -0
  114. /package/out/{subtypes → methods}/date.js +0 -0
  115. /package/out/{subtypes → methods}/instantiate.js +0 -0
  116. /package/out/{subtypes → methods}/morph.js +0 -0
  117. /package/out/{subtypes → methods}/number.js +0 -0
  118. /package/out/{subtypes → methods}/object.js +0 -0
  119. /package/out/{subtypes → methods}/string.js +0 -0
  120. /package/out/{subtypes → methods}/validator.js +0 -0
  121. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  122. /package/out/{keys.js → parser/ast/default.js} +0 -0
  123. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  124. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  125. /package/out/parser/{semantic → ast}/infer.js +0 -0
  126. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  127. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  128. /package/out/parser/{semantic → ast}/utils.js +0 -0
  129. /package/out/parser/{semantic → ast}/validate.js +0 -0
  130. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  131. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  132. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  133. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  134. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  135. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  136. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  137. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  138. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  139. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  140. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  141. /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  import type { number } from "../number/number.ts";
4
4
  declare namespace string {
5
5
  type integer = constrain<string, Branded<"integer">>;
@@ -9,7 +9,7 @@ export declare namespace stringInteger {
9
9
  type module = Module<submodule>;
10
10
  type submodule = Submodule<$>;
11
11
  type $ = {
12
- $root: string.integer;
12
+ root: string.integer;
13
13
  parse: (In: string.integer) => To<number.divisibleBy<1>>;
14
14
  };
15
15
  }
@@ -1,12 +1,12 @@
1
- import { intrinsic, rootNode } from "@ark/schema";
1
+ import { intrinsic, rootSchema } from "@ark/schema";
2
2
  import { wellFormedIntegerMatcher } from "@ark/util";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
4
  import { regexStringNode } from "./utils.js";
5
- const $root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
- export const integer = submodule({
7
- $root,
8
- parse: rootNode({
9
- in: $root,
5
+ const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
+ export const integer = arkModule({
7
+ root,
8
+ parse: rootSchema({
9
+ in: root,
10
10
  morphs: (s, ctx) => {
11
11
  const parsed = Number.parseInt(s);
12
12
  return Number.isSafeInteger(parsed) ? parsed : (ctx.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER"));
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../ast.ts";
2
+ import type { Branded, constrain } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type ip = constrain<string, Branded<"ip">>;
5
5
  namespace ip {
@@ -12,7 +12,7 @@ export declare namespace ip {
12
12
  type module = Module<submodule>;
13
13
  type submodule = Submodule<$>;
14
14
  type $ = {
15
- $root: string.ip;
15
+ root: string.ip;
16
16
  v4: string.ip.v4;
17
17
  v6: string.ip.v6;
18
18
  };
@@ -1,6 +1,7 @@
1
- import { submodule } from "../utils.js";
1
+ import { arkModule } from "../utils.js";
2
2
  import { regexStringNode } from "./utils.js";
3
3
  // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
4
+ // Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
4
5
  const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
5
6
  const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
6
7
  const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
@@ -14,10 +15,9 @@ const ipv6Matcher = new RegExp("^(" +
14
15
  `(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
15
16
  `(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
16
17
  `(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
17
- ")(%[0-9a-zA-Z-.:]{1,})?$");
18
- // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
19
- export const ip = submodule({
20
- $root: ["v4 | v6", "@", "an IP address"],
18
+ ")(%[0-9a-zA-Z.]{1,})?$");
19
+ export const ip = arkModule({
20
+ root: ["v4 | v6", "@", "an IP address"],
21
21
  v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
22
22
  v6: regexStringNode(ipv6Matcher, "an IPv6 address")
23
23
  });
@@ -1,14 +1,15 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../ast.ts";
2
+ import type { Branded, To, constrain } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type json = constrain<string, Branded<"json">>;
5
5
  }
6
+ export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
6
7
  export declare const json: stringJson.module;
7
8
  export declare namespace stringJson {
8
9
  type module = Module<submodule>;
9
10
  type submodule = Submodule<$>;
10
11
  type $ = {
11
- $root: string.json;
12
+ root: string.json;
12
13
  parse: (In: string.json) => To<object>;
13
14
  };
14
15
  }
@@ -1,25 +1,33 @@
1
- import { intrinsic, rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
1
+ import { intrinsic, rootSchema } from "@ark/schema";
2
+ import { arkModule } from "../utils.js";
3
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
- }
4
+ export const writeJsonSyntaxErrorProblem = (error) => {
5
+ if (!(error instanceof SyntaxError))
6
+ throw error;
7
+ return `must be ${jsonStringDescription} (${error})`;
12
8
  };
13
- const $root = rootNode({
9
+ const root = rootSchema({
14
10
  domain: "string",
15
11
  predicate: {
16
12
  meta: jsonStringDescription,
17
- predicate: isParsableJson
13
+ predicate: (s, ctx) => {
14
+ try {
15
+ JSON.parse(s);
16
+ return true;
17
+ }
18
+ catch (e) {
19
+ return ctx.reject({
20
+ code: "predicate",
21
+ expected: jsonStringDescription,
22
+ problem: writeJsonSyntaxErrorProblem(e)
23
+ });
24
+ }
25
+ }
18
26
  }
19
27
  });
20
- export const json = submodule({
21
- $root,
22
- parse: rootNode({
28
+ export const json = arkModule({
29
+ root,
30
+ parse: rootSchema({
23
31
  in: "string",
24
32
  morphs: (s, ctx) => {
25
33
  if (s.length === 0) {
@@ -36,7 +44,7 @@ export const json = submodule({
36
44
  return ctx.error({
37
45
  code: "predicate",
38
46
  expected: jsonStringDescription,
39
- problem: `must be ${jsonStringDescription} (${e})`
47
+ problem: writeJsonSyntaxErrorProblem(e)
40
48
  });
41
49
  }
42
50
  },
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type lowercase = constrain<string, Branded<"lowercase">>;
5
5
  }
@@ -8,7 +8,7 @@ export declare namespace lower {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: (In: string) => To<string.lowercase>;
11
+ root: (In: string) => To<string.lowercase>;
12
12
  preformatted: string.lowercase;
13
13
  };
14
14
  }
@@ -1,9 +1,9 @@
1
- import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
1
+ import { rootSchema } from "@ark/schema";
2
+ import { arkModule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
5
- export const lower = submodule({
6
- $root: rootNode({
5
+ export const lower = arkModule({
6
+ root: rootSchema({
7
7
  in: "string",
8
8
  morphs: (s) => s.toLowerCase(),
9
9
  declaredOut: preformatted
@@ -1,6 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { type } from "../ark.ts";
3
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
4
3
  declare namespace string {
5
4
  type normalized = normalized.NFC;
6
5
  namespace normalized {
@@ -13,78 +12,75 @@ declare namespace string {
13
12
  export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
14
13
  export type NormalizedForm = (typeof normalizedForms)[number];
15
14
  export declare const NFC: Module<{
16
- $root: object;
17
- preformatted: object;
15
+ root: unknown;
16
+ preformatted: unknown;
18
17
  }>;
19
18
  export declare const NFD: Module<{
20
- $root: object;
21
- preformatted: object;
19
+ root: unknown;
20
+ preformatted: unknown;
22
21
  }>;
23
22
  export declare const NFKC: Module<{
24
- $root: object;
25
- preformatted: object;
23
+ root: unknown;
24
+ preformatted: unknown;
26
25
  }>;
27
26
  export declare const NFKD: Module<{
28
- $root: object;
29
- preformatted: object;
27
+ root: unknown;
28
+ preformatted: unknown;
30
29
  }>;
31
30
  export declare const normalize: Module<{
32
- $root: object;
31
+ root: unknown;
33
32
  NFC: Submodule<{
34
- $root: object;
35
- preformatted: object;
33
+ root: unknown;
34
+ preformatted: unknown;
36
35
  }>;
37
36
  NFD: Submodule<{
38
- $root: object;
39
- preformatted: object;
37
+ root: unknown;
38
+ preformatted: unknown;
40
39
  }>;
41
40
  NFKC: Submodule<{
42
- $root: object;
43
- preformatted: object;
41
+ root: unknown;
42
+ preformatted: unknown;
44
43
  }>;
45
44
  NFKD: Submodule<{
46
- $root: object;
47
- preformatted: object;
45
+ root: unknown;
46
+ preformatted: unknown;
48
47
  }>;
49
48
  }>;
50
49
  export declare namespace normalize {
51
50
  type module = Module<submodule>;
52
51
  type submodule = Submodule<$>;
53
52
  type $ = {
54
- $root: (In: string) => To<string.normalized.NFC>;
53
+ root: (In: string) => To<string.normalized.NFC>;
55
54
  NFC: NFC.submodule;
56
55
  NFD: NFD.submodule;
57
56
  NFKC: NFKC.submodule;
58
57
  NFKD: NFKD.submodule;
59
58
  };
60
- type shallowResolutions = {
61
- [k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
62
- };
63
59
  namespace NFC {
64
60
  type submodule = Submodule<$>;
65
61
  type $ = {
66
- $root: (In: string) => To<string.normalized.NFC>;
62
+ root: (In: string) => To<string.normalized.NFC>;
67
63
  preformatted: string.normalized.NFC;
68
64
  };
69
65
  }
70
66
  namespace NFD {
71
67
  type submodule = Submodule<$>;
72
68
  type $ = {
73
- $root: (In: string) => To<string.normalized.NFD>;
69
+ root: (In: string) => To<string.normalized.NFD>;
74
70
  preformatted: string.normalized.NFD;
75
71
  };
76
72
  }
77
73
  namespace NFKC {
78
74
  type submodule = Submodule<$>;
79
75
  type $ = {
80
- $root: (In: string) => To<string.normalized.NFKC>;
76
+ root: (In: string) => To<string.normalized.NFKC>;
81
77
  preformatted: string.normalized.NFKC;
82
78
  };
83
79
  }
84
80
  namespace NFKD {
85
81
  type submodule = Submodule<$>;
86
82
  type $ = {
87
- $root: (In: string) => To<string.normalized.NFKD>;
83
+ root: (In: string) => To<string.normalized.NFKD>;
88
84
  preformatted: string.normalized.NFKD;
89
85
  };
90
86
  }
@@ -1,10 +1,10 @@
1
- import { rootNode } from "@ark/schema";
1
+ import { rootSchema } from "@ark/schema";
2
2
  import { flatMorph } from "@ark/util";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
4
  export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
5
5
  const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
6
6
  form,
7
- rootNode({
7
+ rootSchema({
8
8
  domain: "string",
9
9
  predicate: (s) => s.normalize(form) === s,
10
10
  meta: `${form}-normalized unicode`
@@ -12,30 +12,30 @@ const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
12
12
  ]);
13
13
  const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
14
14
  form,
15
- rootNode({
15
+ rootSchema({
16
16
  in: "string",
17
17
  morphs: (s) => s.normalize(form),
18
18
  declaredOut: preformattedNodes[form]
19
19
  })
20
20
  ]);
21
- export const NFC = submodule({
22
- $root: normalizeNodes.NFC,
21
+ export const NFC = arkModule({
22
+ root: normalizeNodes.NFC,
23
23
  preformatted: preformattedNodes.NFC
24
24
  });
25
- export const NFD = submodule({
26
- $root: normalizeNodes.NFD,
25
+ export const NFD = arkModule({
26
+ root: normalizeNodes.NFD,
27
27
  preformatted: preformattedNodes.NFD
28
28
  });
29
- export const NFKC = submodule({
30
- $root: normalizeNodes.NFKC,
29
+ export const NFKC = arkModule({
30
+ root: normalizeNodes.NFKC,
31
31
  preformatted: preformattedNodes.NFKC
32
32
  });
33
- export const NFKD = submodule({
34
- $root: normalizeNodes.NFKD,
33
+ export const NFKD = arkModule({
34
+ root: normalizeNodes.NFKD,
35
35
  preformatted: preformattedNodes.NFKD
36
36
  });
37
- export const normalize = submodule({
38
- $root: "NFC",
37
+ export const normalize = arkModule({
38
+ root: "NFC",
39
39
  NFC,
40
40
  NFD,
41
41
  NFKC,
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type numeric = constrain<string, Branded<"numeric">>;
5
5
  }
@@ -8,7 +8,7 @@ export declare namespace stringNumeric {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: string.numeric;
11
+ root: string.numeric;
12
12
  parse: (In: string.numeric) => To<number>;
13
13
  };
14
14
  }
@@ -1,12 +1,12 @@
1
- import { intrinsic, rootNode } from "@ark/schema";
1
+ import { intrinsic, rootSchema } from "@ark/schema";
2
2
  import { wellFormedNumberMatcher } from "@ark/util";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
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,
5
+ const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
+ export const numeric = arkModule({
7
+ root,
8
+ parse: rootSchema({
9
+ in: root,
10
10
  morphs: (s) => Number.parseFloat(s),
11
11
  declaredOut: intrinsic.number
12
12
  })
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Branded, constrain } from "../inference.ts";
2
2
  declare namespace string {
3
3
  type semver = constrain<string, Branded<"semver">>;
4
4
  }
@@ -1,7 +1,5 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
2
1
  import type { Module, Submodule } from "../../module.ts";
3
- import type { type } from "../ark.ts";
4
- import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
2
+ import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
5
3
  import { alpha } from "./alpha.ts";
6
4
  import { alphanumeric } from "./alphanumeric.ts";
7
5
  import { capitalize } from "./capitalize.ts";
@@ -21,54 +19,57 @@ import { upper } from "./upper.ts";
21
19
  import { url } from "./url.ts";
22
20
  import { uuid } from "./uuid.ts";
23
21
  export declare const string: Module<{
22
+ root: unknown;
24
23
  trim: Submodule<trim.submodule>;
25
24
  normalize: Submodule<{
26
- $root: object;
25
+ root: unknown;
27
26
  NFC: Submodule<{
28
- $root: object;
29
- preformatted: object;
27
+ root: unknown;
28
+ preformatted: unknown;
30
29
  }>;
31
30
  NFD: Submodule<{
32
- $root: object;
33
- preformatted: object;
31
+ root: unknown;
32
+ preformatted: unknown;
34
33
  }>;
35
34
  NFKC: Submodule<{
36
- $root: object;
37
- preformatted: object;
35
+ root: unknown;
36
+ preformatted: unknown;
38
37
  }>;
39
38
  NFKD: Submodule<{
40
- $root: object;
41
- preformatted: object;
39
+ root: unknown;
40
+ preformatted: unknown;
42
41
  }>;
43
42
  }>;
43
+ alpha: unknown;
44
+ alphanumeric: unknown;
44
45
  json: Submodule<stringJson.submodule>;
45
- $root: object;
46
+ creditCard: unknown;
46
47
  integer: Submodule<stringInteger.submodule>;
47
- alpha: object;
48
- alphanumeric: object;
49
- digits: object;
48
+ date: Submodule<stringDate.submodule>;
49
+ digits: unknown;
50
+ email: unknown;
51
+ ip: Submodule<ip.submodule>;
50
52
  numeric: Submodule<stringNumeric.submodule>;
51
- creditCard: object;
52
- email: object;
53
+ semver: unknown;
54
+ url: Submodule<url.submodule>;
53
55
  uuid: Submodule<{
54
- $root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
55
- v4: object;
56
- v6: object;
57
- v1: object;
58
- v2: object;
59
- v3: object;
60
- v5: object;
61
- v7: object;
62
- v8: object;
56
+ root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
57
+ v4: unknown;
58
+ v6: unknown;
59
+ v1: unknown;
60
+ v2: unknown;
61
+ v3: unknown;
62
+ v5: unknown;
63
+ v7: unknown;
64
+ v8: unknown;
63
65
  }>;
64
- semver: object;
65
- ip: Submodule<ip.submodule>;
66
- date: Submodule<stringDate.submodule>;
67
- capitalize: Submodule<capitalize.submodule>;
68
- lower: Submodule<lower.submodule>;
69
66
  upper: Submodule<upper.submodule>;
70
- url: Submodule<url.submodule>;
67
+ lower: Submodule<lower.submodule>;
68
+ capitalize: Submodule<capitalize.submodule>;
71
69
  }>;
70
+ export type Matching<rule> = {
71
+ matching: constraint<rule>;
72
+ };
72
73
  export declare namespace string {
73
74
  type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
74
75
  type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
@@ -77,17 +78,15 @@ export declare namespace string {
77
78
  type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
78
79
  type matching<rule> = constrain<string, Matching<rule>>;
79
80
  type narrowed = constrain<string, Narrowed>;
81
+ type optional = constrain<string, Optional>;
82
+ type defaultsTo<rule> = constrain<string, Default<rule>>;
80
83
  type branded<rule> = constrain<string, Branded<rule>>;
81
84
  type is<constraints extends Constraints> = constrain<string, constraints>;
82
- type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
83
- exclusive: true;
84
- } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
85
- exclusive: true;
86
- } ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
85
+ type withConstraint<constraint> = constraint extends ExactlyLength<infer rule> ? exactlyLength<rule> : constraint extends MoreThanLength<infer rule> ? moreThanLength<rule> : constraint extends AtLeastLength<infer rule> ? atLeastLength<rule> : constraint extends AtMostLength<infer rule> ? atMostLength<rule> : constraint extends LessThanLength<infer rule> ? lessThanLength<rule> : constraint extends Matching<infer rule> ? matching<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
87
86
  type module = Module<string.submodule>;
88
87
  type submodule = Submodule<$>;
89
88
  type $ = {
90
- $root: string;
89
+ root: string;
91
90
  alpha: alpha;
92
91
  alphanumeric: alphanumeric;
93
92
  digits: digits;
@@ -100,13 +99,11 @@ export declare namespace string {
100
99
  ip: ip.submodule;
101
100
  json: stringJson.submodule;
102
101
  date: stringDate.submodule;
102
+ url: url.submodule;
103
103
  trim: trim.submodule;
104
104
  normalize: normalize.submodule;
105
105
  capitalize: capitalize.submodule;
106
106
  lower: lower.submodule;
107
107
  upper: upper.submodule;
108
108
  };
109
- type shallowResolutions = {
110
- [k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
111
- };
112
109
  }
@@ -1,5 +1,5 @@
1
1
  import { intrinsic } from "@ark/schema";
2
- import { submodule } from "../utils.js";
2
+ import { arkModule } from "../utils.js";
3
3
  import { alpha } from "./alpha.js";
4
4
  import { alphanumeric } from "./alphanumeric.js";
5
5
  import { capitalize } from "./capitalize.js";
@@ -18,8 +18,8 @@ import { trim } from "./trim.js";
18
18
  import { upper } from "./upper.js";
19
19
  import { url } from "./url.js";
20
20
  import { uuid } from "./uuid.js";
21
- export const string = submodule({
22
- $root: intrinsic.string,
21
+ export const string = arkModule({
22
+ root: intrinsic.string,
23
23
  numeric,
24
24
  integer,
25
25
  alpha,
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type trimmed = constrain<string, Branded<"trimmed">>;
5
5
  }
@@ -8,7 +8,7 @@ export declare namespace trim {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: (In: string) => To<string.trimmed>;
11
+ root: (In: string) => To<string.trimmed>;
12
12
  preformatted: string.trimmed;
13
13
  };
14
14
  }
@@ -1,11 +1,11 @@
1
- import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
1
+ import { rootSchema } from "@ark/schema";
2
+ import { arkModule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(
5
5
  // no leading or trailing whitespace
6
6
  /^\S.*\S$|^\S?$/, "trimmed");
7
- export const trim = submodule({
8
- $root: rootNode({
7
+ export const trim = arkModule({
8
+ root: rootSchema({
9
9
  in: "string",
10
10
  morphs: (s) => s.trim(),
11
11
  declaredOut: preformatted
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type uppercase = constrain<string, Branded<"uppercase">>;
5
5
  }
@@ -8,7 +8,7 @@ export declare namespace upper {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: (In: string) => To<string.uppercase>;
11
+ root: (In: string) => To<string.uppercase>;
12
12
  preformatted: string.uppercase;
13
13
  };
14
14
  }
@@ -1,9 +1,9 @@
1
- import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
1
+ import { rootSchema } from "@ark/schema";
2
+ import { arkModule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
5
- export const upper = submodule({
6
- $root: rootNode({
5
+ export const upper = arkModule({
6
+ root: rootSchema({
7
7
  in: "string",
8
8
  morphs: (s) => s.toUpperCase(),
9
9
  declaredOut: preformatted
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
2
+ import type { Branded, constrain, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type url = constrain<string, Branded<"url">>;
5
5
  }
@@ -8,7 +8,7 @@ export declare namespace url {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: string.url;
11
+ root: string.url;
12
12
  parse: (In: string.url) => To<URL>;
13
13
  };
14
14
  }