arktype 2.0.0-rc.2 → 2.0.0-rc.21

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 (151) hide show
  1. package/out/attributes.d.ts +274 -0
  2. package/out/attributes.js +2 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +45 -48
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +4 -4
  7. package/out/index.js +2 -2
  8. package/out/keywords/builtins.js +2 -2
  9. package/out/keywords/constructors/Array.d.ts +2 -2
  10. package/out/keywords/constructors/Array.js +7 -7
  11. package/out/keywords/constructors/Date.d.ts +37 -0
  12. package/out/keywords/constructors/FormData.d.ts +2 -2
  13. package/out/keywords/constructors/FormData.js +8 -8
  14. package/out/keywords/constructors/TypedArray.js +2 -2
  15. package/out/keywords/constructors/constructors.d.ts +0 -1
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/keywords.d.ts +64 -0
  18. package/out/keywords/{ark.js → keywords.js} +14 -9
  19. package/out/keywords/number/epoch.d.ts +1 -1
  20. package/out/keywords/number/epoch.js +2 -2
  21. package/out/keywords/number/integer.js +2 -2
  22. package/out/keywords/number/number.d.ts +44 -14
  23. package/out/keywords/number/number.js +17 -5
  24. package/out/keywords/string/alpha.d.ts +2 -2
  25. package/out/keywords/string/alphanumeric.d.ts +2 -2
  26. package/out/keywords/string/base64.d.ts +21 -0
  27. package/out/keywords/string/base64.js +6 -0
  28. package/out/keywords/string/capitalize.d.ts +3 -3
  29. package/out/keywords/string/capitalize.js +4 -4
  30. package/out/keywords/string/creditCard.d.ts +2 -2
  31. package/out/keywords/string/creditCard.js +2 -2
  32. package/out/keywords/string/date.d.ts +7 -11
  33. package/out/keywords/string/date.js +16 -16
  34. package/out/keywords/string/digits.d.ts +2 -2
  35. package/out/keywords/string/email.d.ts +2 -2
  36. package/out/keywords/string/integer.d.ts +3 -3
  37. package/out/keywords/string/integer.js +7 -7
  38. package/out/keywords/string/ip.d.ts +5 -5
  39. package/out/keywords/string/ip.js +5 -5
  40. package/out/keywords/string/json.d.ts +4 -3
  41. package/out/keywords/string/json.js +39 -30
  42. package/out/keywords/string/lower.d.ts +3 -3
  43. package/out/keywords/string/lower.js +4 -4
  44. package/out/keywords/string/normalize.d.ts +27 -31
  45. package/out/keywords/string/normalize.js +14 -14
  46. package/out/keywords/string/numeric.d.ts +3 -3
  47. package/out/keywords/string/numeric.js +7 -7
  48. package/out/keywords/string/semver.d.ts +2 -2
  49. package/out/keywords/string/string.d.ts +74 -51
  50. package/out/keywords/string/string.js +5 -3
  51. package/out/keywords/string/trim.d.ts +3 -3
  52. package/out/keywords/string/trim.js +4 -4
  53. package/out/keywords/string/upper.d.ts +3 -3
  54. package/out/keywords/string/upper.js +4 -4
  55. package/out/keywords/string/url.d.ts +3 -3
  56. package/out/keywords/string/url.js +8 -8
  57. package/out/keywords/string/uuid.d.ts +20 -20
  58. package/out/keywords/string/uuid.js +3 -3
  59. package/out/keywords/ts.d.ts +38 -1
  60. package/out/keywords/ts.js +20 -4
  61. package/out/keywords/utils.d.ts +1 -1
  62. package/out/keywords/utils.js +1 -1
  63. package/out/{subtypes → methods}/array.d.ts +6 -6
  64. package/out/methods/base.d.ts +183 -0
  65. package/out/{subtypes → methods}/date.d.ts +5 -5
  66. package/out/methods/instantiate.d.ts +17 -0
  67. package/out/methods/morph.d.ts +12 -0
  68. package/out/methods/number.d.ts +12 -0
  69. package/out/methods/object.d.ts +106 -0
  70. package/out/methods/string.d.ts +13 -0
  71. package/out/module.d.ts +2 -2
  72. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  73. package/out/parser/ast/default.d.ts +8 -0
  74. package/out/parser/ast/infer.d.ts +39 -0
  75. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  76. package/out/parser/{semantic → ast}/validate.d.ts +10 -10
  77. package/out/parser/ast/validate.js +1 -0
  78. package/out/parser/definition.d.ts +8 -9
  79. package/out/parser/objectLiteral.d.ts +11 -37
  80. package/out/parser/objectLiteral.js +6 -24
  81. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
  82. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  83. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  84. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  85. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  86. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -3
  87. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  88. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
  89. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  90. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  91. package/out/parser/shift/operator/brand.d.ts +6 -0
  92. package/out/parser/shift/operator/brand.js +5 -0
  93. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  94. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  95. package/out/parser/{string/shift → shift}/operator/operator.d.ts +2 -1
  96. package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
  97. package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
  98. package/out/parser/{string/shift → shift}/scanner.js +6 -3
  99. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  100. package/out/parser/{string/string.js → string.js} +2 -0
  101. package/out/parser/tuple.d.ts +56 -44
  102. package/out/parser/tuple.js +36 -30
  103. package/out/scope.d.ts +38 -39
  104. package/out/scope.js +47 -36
  105. package/out/type.d.ts +45 -21
  106. package/out/type.js +14 -10
  107. package/package.json +3 -3
  108. package/out/intersect.d.ts +0 -28
  109. package/out/keys.d.ts +0 -16
  110. package/out/keywords/ark.d.ts +0 -39
  111. package/out/keywords/ast.d.ts +0 -193
  112. package/out/keywords/ast.js +0 -2
  113. package/out/parser/semantic/default.d.ts +0 -9
  114. package/out/parser/semantic/default.js +0 -1
  115. package/out/parser/semantic/infer.d.ts +0 -39
  116. package/out/parser/semantic/validate.js +0 -1
  117. package/out/subtypes/base.d.ts +0 -85
  118. package/out/subtypes/instantiate.d.ts +0 -16
  119. package/out/subtypes/morph.d.ts +0 -13
  120. package/out/subtypes/number.d.ts +0 -12
  121. package/out/subtypes/object.d.ts +0 -33
  122. package/out/subtypes/string.d.ts +0 -13
  123. package/out/subtypes/validator.d.ts +0 -11
  124. package/out/subtypes/validator.js +0 -1
  125. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  126. /package/out/{subtypes → methods}/array.js +0 -0
  127. /package/out/{subtypes → methods}/base.js +0 -0
  128. /package/out/{subtypes → methods}/date.js +0 -0
  129. /package/out/{subtypes → methods}/instantiate.js +0 -0
  130. /package/out/{subtypes → methods}/morph.js +0 -0
  131. /package/out/{subtypes → methods}/number.js +0 -0
  132. /package/out/{subtypes → methods}/object.js +0 -0
  133. /package/out/{subtypes → methods}/string.js +0 -0
  134. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  135. /package/out/{keys.js → parser/ast/default.js} +0 -0
  136. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  137. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  138. /package/out/parser/{semantic → ast}/infer.js +0 -0
  139. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  140. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  141. /package/out/parser/{semantic → ast}/utils.js +0 -0
  142. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  143. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  144. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  145. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  146. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  147. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  148. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  149. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  150. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  151. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,14 +1,15 @@
1
+ import type { Nominal, To, of } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../ast.ts";
3
3
  declare namespace string {
4
- type json = constrain<string, Branded<"json">>;
4
+ type json = of<string, Nominal<"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,45 +1,54 @@
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
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
- }
13
+ predicate: (s, ctx) => {
32
14
  try {
33
- return JSON.parse(s);
15
+ JSON.parse(s);
16
+ return true;
34
17
  }
35
18
  catch (e) {
36
- return ctx.error({
19
+ return ctx.reject({
37
20
  code: "predicate",
38
21
  expected: jsonStringDescription,
39
- problem: `must be ${jsonStringDescription} (${e})`
22
+ problem: writeJsonSyntaxErrorProblem(e)
40
23
  });
41
24
  }
42
- },
25
+ }
26
+ }
27
+ });
28
+ const parseJson = (s, ctx) => {
29
+ if (s.length === 0) {
30
+ return ctx.error({
31
+ code: "predicate",
32
+ expected: jsonStringDescription,
33
+ actual: "empty"
34
+ });
35
+ }
36
+ try {
37
+ return JSON.parse(s);
38
+ }
39
+ catch (e) {
40
+ return ctx.error({
41
+ code: "predicate",
42
+ expected: jsonStringDescription,
43
+ problem: writeJsonSyntaxErrorProblem(e)
44
+ });
45
+ }
46
+ };
47
+ export const json = arkModule({
48
+ root,
49
+ parse: rootSchema({
50
+ in: "string",
51
+ morphs: parseJson,
43
52
  declaredOut: intrinsic.json
44
53
  })
45
54
  });
@@ -1,14 +1,14 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
- type lowercase = constrain<string, Branded<"lowercase">>;
4
+ type lowercase = of<string, Nominal<"lowercase">>;
5
5
  }
6
6
  export declare const lower: lower.module;
7
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,90 +1,86 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { type } from "../ark.ts";
3
- import type { Branded, constrain, To } from "../ast.ts";
4
3
  declare namespace string {
5
4
  type normalized = normalized.NFC;
6
5
  namespace normalized {
7
- type NFC = constrain<string, Branded<"normalized.NFC">>;
8
- type NFD = constrain<string, Branded<"normalized.NFD">>;
9
- type NFKC = constrain<string, Branded<"normalized.NFKC">>;
10
- type NFKD = constrain<string, Branded<"normalized.NFKD">>;
6
+ type NFC = of<string, Nominal<"normalized.NFC">>;
7
+ type NFD = of<string, Nominal<"normalized.NFD">>;
8
+ type NFKC = of<string, Nominal<"normalized.NFKC">>;
9
+ type NFKD = of<string, Nominal<"normalized.NFKD">>;
11
10
  }
12
11
  }
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,14 +1,14 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
- type numeric = constrain<string, Branded<"numeric">>;
4
+ type numeric = of<string, Nominal<"numeric">>;
5
5
  }
6
6
  export declare const numeric: stringNumeric.module;
7
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,6 +1,6 @@
1
- import type { Branded, constrain } from "../ast.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type semver = constrain<string, Branded<"semver">>;
3
+ type semver = of<string, Nominal<"semver">>;
4
4
  }
5
5
  export declare const semver: import("@ark/schema").IntersectionNode;
6
6
  export type semver = string.semver;
@@ -1,9 +1,9 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
1
+ import type { satisfy } from "@ark/util";
2
+ import type { Anonymous, AtLeastLength, AtMostLength, AttributeKind, Attributes, Default, ExactlyLength, LengthAttributeKind, LessThanLength, MoreThanLength, Nominal, Optional, brand, constraint, of } from "../../attributes.ts";
2
3
  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";
5
4
  import { alpha } from "./alpha.ts";
6
5
  import { alphanumeric } from "./alphanumeric.ts";
6
+ import { base64 } from "./base64.ts";
7
7
  import { capitalize } from "./capitalize.ts";
8
8
  import { creditCard } from "./creditCard.ts";
9
9
  import { stringDate } from "./date.ts";
@@ -23,73 +23,83 @@ import { uuid } from "./uuid.ts";
23
23
  export declare const string: Module<{
24
24
  trim: Submodule<trim.submodule>;
25
25
  normalize: Submodule<{
26
- $root: object;
26
+ root: unknown;
27
27
  NFC: Submodule<{
28
- $root: object;
29
- preformatted: object;
28
+ root: unknown;
29
+ preformatted: unknown;
30
30
  }>;
31
31
  NFD: Submodule<{
32
- $root: object;
33
- preformatted: object;
32
+ root: unknown;
33
+ preformatted: unknown;
34
34
  }>;
35
35
  NFKC: Submodule<{
36
- $root: object;
37
- preformatted: object;
36
+ root: unknown;
37
+ preformatted: unknown;
38
38
  }>;
39
39
  NFKD: Submodule<{
40
- $root: object;
41
- preformatted: object;
40
+ root: unknown;
41
+ preformatted: unknown;
42
42
  }>;
43
43
  }>;
44
+ alpha: unknown;
45
+ alphanumeric: unknown;
46
+ root: unknown;
47
+ url: Submodule<url.submodule>;
44
48
  json: Submodule<stringJson.submodule>;
45
- $root: object;
49
+ base64: Submodule<{
50
+ root: unknown;
51
+ url: unknown;
52
+ }>;
53
+ creditCard: unknown;
46
54
  integer: Submodule<stringInteger.submodule>;
47
- alpha: object;
48
- alphanumeric: object;
49
- digits: object;
55
+ date: Submodule<stringDate.submodule>;
56
+ digits: unknown;
57
+ email: unknown;
58
+ ip: Submodule<ip.submodule>;
50
59
  numeric: Submodule<stringNumeric.submodule>;
51
- creditCard: object;
52
- email: object;
60
+ semver: unknown;
53
61
  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;
62
+ root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
63
+ v4: unknown;
64
+ v6: unknown;
65
+ v1: unknown;
66
+ v2: unknown;
67
+ v3: unknown;
68
+ v5: unknown;
69
+ v7: unknown;
70
+ v8: unknown;
63
71
  }>;
64
- semver: object;
65
- ip: Submodule<ip.submodule>;
66
- date: Submodule<stringDate.submodule>;
67
- capitalize: Submodule<capitalize.submodule>;
68
- lower: Submodule<lower.submodule>;
69
72
  upper: Submodule<upper.submodule>;
70
- url: Submodule<url.submodule>;
73
+ lower: Submodule<lower.submodule>;
74
+ capitalize: Submodule<capitalize.submodule>;
71
75
  }>;
76
+ export type Matching<rule> = {
77
+ matching: constraint<rule>;
78
+ };
72
79
  export declare namespace string {
73
- type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
74
- type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
75
- type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
76
- type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
77
- type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
78
- type matching<rule> = constrain<string, Matching<rule>>;
79
- type narrowed = constrain<string, Narrowed>;
80
- type branded<rule> = constrain<string, Branded<rule>>;
81
- 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;
80
+ type atLeastLength<rule> = of<string, AtLeastLength<rule>>;
81
+ type moreThanLength<rule> = of<string, MoreThanLength<rule>>;
82
+ type atMostLength<rule> = of<string, AtMostLength<rule>>;
83
+ type lessThanLength<rule> = of<string, LessThanLength<rule>>;
84
+ type exactlyLength<rule> = of<string, ExactlyLength<rule>>;
85
+ type matching<rule> = of<string, Matching<rule>>;
86
+ type anonymous = of<string, Anonymous>;
87
+ type optional = of<string, Optional>;
88
+ type defaultsTo<rule> = of<string, Default<rule>>;
89
+ type nominal<rule> = of<string, Nominal<rule>>;
90
+ type is<attributes extends Attributes> = of<string, attributes>;
91
+ type AttributableKind = satisfy<AttributeKind, "matching" | LengthAttributeKind>;
92
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
93
+ namespace raw {
94
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
95
+ }
87
96
  type module = Module<string.submodule>;
88
97
  type submodule = Submodule<$>;
89
98
  type $ = {
90
- $root: string;
99
+ root: string;
91
100
  alpha: alpha;
92
101
  alphanumeric: alphanumeric;
102
+ base64: base64.submodule;
93
103
  digits: digits;
94
104
  numeric: stringNumeric.submodule;
95
105
  integer: stringInteger.submodule;
@@ -100,13 +110,26 @@ export declare namespace string {
100
110
  ip: ip.submodule;
101
111
  json: stringJson.submodule;
102
112
  date: stringDate.submodule;
113
+ url: url.submodule;
103
114
  trim: trim.submodule;
104
115
  normalize: normalize.submodule;
105
116
  capitalize: capitalize.submodule;
106
117
  lower: lower.submodule;
107
118
  upper: upper.submodule;
108
119
  };
109
- type shallowResolutions = {
110
- [k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
111
- };
120
+ type branded<rule> = brand<string, Nominal<rule>>;
121
+ namespace branded {
122
+ type atLeastLength<rule> = brand<string, AtLeastLength<rule>>;
123
+ type moreThanLength<rule> = brand<string, MoreThanLength<rule>>;
124
+ type atMostLength<rule> = brand<string, AtMostLength<rule>>;
125
+ type lessThanLength<rule> = brand<string, LessThanLength<rule>>;
126
+ type exactlyLength<rule> = brand<string, ExactlyLength<rule>>;
127
+ type matching<rule> = brand<string, Matching<rule>>;
128
+ type anonymous = brand<string, Anonymous>;
129
+ type is<attributes extends Attributes> = brand<string, attributes>;
130
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
131
+ namespace raw {
132
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : never;
133
+ }
134
+ }
112
135
  }
@@ -1,7 +1,8 @@
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
+ import { base64 } from "./base64.js";
5
6
  import { capitalize } from "./capitalize.js";
6
7
  import { creditCard } from "./creditCard.js";
7
8
  import { stringDate } from "./date.js";
@@ -18,12 +19,13 @@ import { trim } from "./trim.js";
18
19
  import { upper } from "./upper.js";
19
20
  import { url } from "./url.js";
20
21
  import { uuid } from "./uuid.js";
21
- export const string = submodule({
22
- $root: intrinsic.string,
22
+ export const string = arkModule({
23
+ root: intrinsic.string,
23
24
  numeric,
24
25
  integer,
25
26
  alpha,
26
27
  alphanumeric,
28
+ base64,
27
29
  digits,
28
30
  semver,
29
31
  ip,
@@ -1,14 +1,14 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
- type trimmed = constrain<string, Branded<"trimmed">>;
4
+ type trimmed = of<string, Nominal<"trimmed">>;
5
5
  }
6
6
  export declare const trim: trim.module;
7
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,14 +1,14 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
- type uppercase = constrain<string, Branded<"uppercase">>;
4
+ type uppercase = of<string, Nominal<"uppercase">>;
5
5
  }
6
6
  export declare const upper: upper.module;
7
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,14 +1,14 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
- type url = constrain<string, Branded<"url">>;
4
+ type url = of<string, Nominal<"url">>;
5
5
  }
6
6
  export declare const url: url.module;
7
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
  }