arktype 2.0.0-rc.4 → 2.0.0-rc.6

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 (92) hide show
  1. package/out/generic.d.ts +34 -36
  2. package/out/generic.js +1 -1
  3. package/out/index.d.ts +2 -2
  4. package/out/index.js +1 -1
  5. package/out/intersect.d.ts +2 -4
  6. package/out/keywords/ark.d.ts +20 -3
  7. package/out/keywords/ark.js +3 -2
  8. package/out/keywords/ast.d.ts +97 -102
  9. package/out/keywords/builtins.js +2 -2
  10. package/out/keywords/constructors/Array.d.ts +1 -1
  11. package/out/keywords/constructors/Array.js +4 -4
  12. package/out/keywords/constructors/Date.d.ts +31 -0
  13. package/out/keywords/constructors/FormData.d.ts +1 -1
  14. package/out/keywords/constructors/FormData.js +3 -3
  15. package/out/keywords/constructors/TypedArray.js +2 -2
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/number/epoch.d.ts +1 -2
  18. package/out/keywords/number/number.d.ts +31 -6
  19. package/out/keywords/number/number.js +17 -5
  20. package/out/keywords/string/capitalize.d.ts +1 -1
  21. package/out/keywords/string/capitalize.js +3 -3
  22. package/out/keywords/string/date.d.ts +3 -7
  23. package/out/keywords/string/date.js +11 -11
  24. package/out/keywords/string/integer.d.ts +1 -1
  25. package/out/keywords/string/integer.js +5 -5
  26. package/out/keywords/string/ip.d.ts +1 -1
  27. package/out/keywords/string/ip.js +3 -3
  28. package/out/keywords/string/json.d.ts +1 -1
  29. package/out/keywords/string/json.js +4 -4
  30. package/out/keywords/string/lower.d.ts +1 -1
  31. package/out/keywords/string/lower.js +3 -3
  32. package/out/keywords/string/normalize.d.ts +14 -18
  33. package/out/keywords/string/normalize.js +11 -11
  34. package/out/keywords/string/numeric.d.ts +1 -1
  35. package/out/keywords/string/numeric.js +5 -5
  36. package/out/keywords/string/string.d.ts +18 -22
  37. package/out/keywords/string/string.js +3 -3
  38. package/out/keywords/string/trim.d.ts +1 -1
  39. package/out/keywords/string/trim.js +3 -3
  40. package/out/keywords/string/upper.d.ts +1 -1
  41. package/out/keywords/string/upper.js +3 -3
  42. package/out/keywords/string/url.d.ts +1 -1
  43. package/out/keywords/string/url.js +5 -5
  44. package/out/keywords/string/uuid.d.ts +2 -2
  45. package/out/keywords/string/uuid.js +3 -3
  46. package/out/keywords/ts.d.ts +11 -0
  47. package/out/keywords/ts.js +7 -3
  48. package/out/keywords/utils.d.ts +1 -1
  49. package/out/keywords/utils.js +1 -1
  50. package/out/{subtypes → methods}/array.d.ts +6 -6
  51. package/out/methods/base.d.ts +87 -0
  52. package/out/{subtypes → methods}/date.d.ts +5 -5
  53. package/out/methods/morph.d.ts +13 -0
  54. package/out/{subtypes → methods}/number.d.ts +6 -6
  55. package/out/{subtypes → methods}/object.d.ts +1 -2
  56. package/out/{subtypes → methods}/string.d.ts +7 -7
  57. package/out/{subtypes → methods}/validator.d.ts +2 -2
  58. package/out/methods/validator.js +1 -0
  59. package/out/module.d.ts +2 -2
  60. package/out/parser/objectLiteral.d.ts +5 -30
  61. package/out/parser/objectLiteral.js +18 -21
  62. package/out/parser/semantic/default.d.ts +3 -4
  63. package/out/parser/semantic/default.js +1 -1
  64. package/out/parser/semantic/infer.d.ts +8 -7
  65. package/out/parser/semantic/validate.d.ts +2 -2
  66. package/out/parser/string/reduce/dynamic.d.ts +1 -2
  67. package/out/parser/string/reduce/dynamic.js +2 -4
  68. package/out/parser/string/shift/operand/date.d.ts +2 -0
  69. package/out/parser/string/shift/operand/enclosed.d.ts +2 -1
  70. package/out/parser/string/shift/operand/enclosed.js +7 -3
  71. package/out/parser/string/shift/operator/default.d.ts +2 -5
  72. package/out/parser/string/shift/operator/default.js +1 -6
  73. package/out/parser/string/string.d.ts +2 -3
  74. package/out/parser/tuple.d.ts +6 -5
  75. package/out/parser/tuple.js +13 -6
  76. package/out/scope.d.ts +9 -5
  77. package/out/scope.js +12 -8
  78. package/out/type.d.ts +13 -12
  79. package/out/type.js +4 -1
  80. package/package.json +3 -3
  81. package/out/subtypes/base.d.ts +0 -85
  82. package/out/subtypes/morph.d.ts +0 -13
  83. /package/out/{subtypes/array.js → keywords/constructors/Date.js} +0 -0
  84. /package/out/{subtypes/base.js → methods/array.js} +0 -0
  85. /package/out/{subtypes/date.js → methods/base.js} +0 -0
  86. /package/out/{subtypes/instantiate.js → methods/date.js} +0 -0
  87. /package/out/{subtypes → methods}/instantiate.d.ts +0 -0
  88. /package/out/{subtypes/morph.js → methods/instantiate.js} +0 -0
  89. /package/out/{subtypes/number.js → methods/morph.js} +0 -0
  90. /package/out/{subtypes/object.js → methods/number.js} +0 -0
  91. /package/out/{subtypes/string.js → methods/object.js} +0 -0
  92. /package/out/{subtypes/validator.js → methods/string.js} +0 -0
@@ -1,5 +1,5 @@
1
- import { submodule } from "../utils.js";
2
- export const TypedArray = submodule({
1
+ import { arkModule } from "../utils.js";
2
+ export const TypedArray = arkModule({
3
3
  Int8: ["instanceof", Int8Array],
4
4
  Uint8: ["instanceof", Uint8Array],
5
5
  Uint8Clamped: ["instanceof", Uint8ClampedArray],
@@ -1,5 +1,5 @@
1
1
  import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
2
- import { submodule } from "../utils.js";
2
+ import { arkModule } from "../utils.js";
3
3
  import { arkArray } from "./Array.js";
4
4
  import { arkFormData } from "./FormData.js";
5
5
  import { TypedArray } from "./TypedArray.js";
@@ -8,7 +8,7 @@ const omittedPrototypes = {
8
8
  Number: 1,
9
9
  String: 1
10
10
  };
11
- export const arkPrototypes = submodule({
11
+ export const arkPrototypes = arkModule({
12
12
  ...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
13
13
  Array: arkArray,
14
14
  TypedArray,
@@ -1,5 +1,4 @@
1
- import type { AtLeast, AtMost, DivisibleBy } from "../ast.ts";
2
- import type { number } from "./number.ts";
1
+ import type { AtLeast, AtMost, DivisibleBy, number } from "./number.ts";
3
2
  /**
4
3
  * As per the ECMA-262 specification:
5
4
  * A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
@@ -1,9 +1,23 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
2
1
  import type { Module, Submodule } from "../../module.ts";
3
- import type { AtLeast, AtMost, Branded, constrain, Constraints, DivisibleBy, LessThan, MoreThan, Narrowed, normalizePrimitiveConstraintRoot } from "../ast.ts";
2
+ import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../ast.ts";
4
3
  import { epoch } from "./epoch.ts";
5
4
  import { integer } from "./integer.ts";
6
5
  export declare const number: number.module;
6
+ export type AtLeast<rule> = {
7
+ atLeast: constraint<rule>;
8
+ };
9
+ export type AtMost<rule> = {
10
+ atMost: constraint<rule>;
11
+ };
12
+ export type MoreThan<rule> = {
13
+ moreThan: constraint<rule>;
14
+ };
15
+ export type LessThan<rule> = {
16
+ lessThan: constraint<rule>;
17
+ };
18
+ export type DivisibleBy<rule> = {
19
+ divisibleBy: constraint<rule>;
20
+ };
7
21
  export declare namespace number {
8
22
  type atLeast<rule> = constrain<number, AtLeast<rule>>;
9
23
  type moreThan<rule> = constrain<number, MoreThan<rule>>;
@@ -11,18 +25,29 @@ export declare namespace number {
11
25
  type lessThan<rule> = constrain<number, LessThan<rule>>;
12
26
  type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
13
27
  type narrowed = constrain<number, Narrowed>;
28
+ type optional = constrain<number, Optional>;
14
29
  type branded<rule> = constrain<number, Branded<rule>>;
30
+ type NaN = branded<"NaN">;
31
+ type Infinity = branded<"Infinity">;
32
+ type NegativeInfinity = branded<"NegativeInfinity">;
33
+ type safe = branded<"safe">;
15
34
  type is<constraints extends Constraints> = constrain<number, constraints>;
16
- type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "min" ? schema extends {
35
+ type minSchemaToConstraint<schema, rule> = schema extends {
17
36
  exclusive: true;
18
- } ? moreThan<rule> : atLeast<rule> : kind extends "max" ? schema extends {
37
+ } ? MoreThan<rule> : AtLeast<rule>;
38
+ type maxSchemaToConstraint<schema, rule> = schema extends {
19
39
  exclusive: true;
20
- } ? lessThan<rule> : atMost<rule> : kind extends "divisor" ? divisibleBy<rule> : narrowed : never;
40
+ } ? LessThan<rule> : AtMost<rule>;
41
+ type withConstraint<constraint> = constraint extends MoreThan<infer rule> ? moreThan<rule> : constraint extends AtLeast<infer rule> ? atLeast<rule> : constraint extends AtMost<infer rule> ? atMost<rule> : constraint extends LessThan<infer rule> ? lessThan<rule> : constraint extends DivisibleBy<infer rule> ? divisibleBy<rule> : constraint extends Optional ? optional : constraint extends Narrowed ? narrowed : never;
21
42
  type module = Module<submodule>;
22
43
  type submodule = Submodule<$>;
23
44
  type $ = {
24
- $root: number;
45
+ root: number;
25
46
  epoch: epoch;
26
47
  integer: integer;
48
+ safe: safe;
49
+ NaN: NaN;
50
+ Infinity: Infinity;
51
+ NegativeInfinity: NegativeInfinity;
27
52
  };
28
53
  }
@@ -1,9 +1,21 @@
1
- import { intrinsic } from "@ark/schema";
2
- import { submodule } from "../utils.js";
1
+ import { intrinsic, rootNode } from "@ark/schema";
2
+ import { arkModule } from "../utils.js";
3
3
  import { epoch } from "./epoch.js";
4
4
  import { integer } from "./integer.js";
5
- export const number = submodule({
6
- $root: intrinsic.number,
5
+ export const number = arkModule({
6
+ root: intrinsic.number,
7
7
  integer,
8
- epoch
8
+ epoch,
9
+ safe: rootNode({
10
+ domain: "number",
11
+ min: Number.MIN_SAFE_INTEGER,
12
+ max: Number.MAX_SAFE_INTEGER,
13
+ predicate: {
14
+ predicate: n => !Number.isNaN(n),
15
+ meta: "a safe number"
16
+ }
17
+ }),
18
+ NaN: ["===", Number.NaN],
19
+ Infinity: ["===", Number.POSITIVE_INFINITY],
20
+ NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
9
21
  });
@@ -8,7 +8,7 @@ export declare namespace capitalize {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: (In: string) => To<string.capitalized>;
11
+ root: (In: string) => To<string.capitalized>;
12
12
  preformatted: string.capitalized;
13
13
  };
14
14
  }
@@ -1,9 +1,9 @@
1
1
  import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
2
+ import { arkModule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(/^[A-Z].*$/, "capitalized");
5
- export const capitalize = submodule({
6
- $root: rootNode({
5
+ export const capitalize = arkModule({
6
+ root: rootNode({
7
7
  in: "string",
8
8
  morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
9
9
  declaredOut: preformatted
@@ -1,5 +1,4 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { type } from "../ark.ts";
3
2
  import type { Branded, To, constrain } from "../ast.ts";
4
3
  type DayDelimiter = "." | "/" | "-";
5
4
  type DayPart = DayPatterns[PartKey];
@@ -33,25 +32,22 @@ export declare namespace stringDate {
33
32
  type module = Module<stringDate.submodule>;
34
33
  type submodule = Submodule<$>;
35
34
  type $ = {
36
- $root: string.date;
35
+ root: string.date;
37
36
  parse: (In: string.date) => To<Date>;
38
37
  iso: iso.submodule;
39
38
  epoch: epoch.submodule;
40
39
  };
41
- type shallowResolutions = {
42
- [k in keyof $ as `string.date.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
43
- };
44
40
  namespace iso {
45
41
  type submodule = Submodule<$>;
46
42
  type $ = {
47
- $root: string.date.iso;
43
+ root: string.date.iso;
48
44
  parse: (In: string.date.iso) => To<Date>;
49
45
  };
50
46
  }
51
47
  namespace epoch {
52
48
  type submodule = Submodule<$>;
53
49
  type $ = {
54
- $root: string.date.epoch;
50
+ root: string.date.epoch;
55
51
  parse: (In: string.date.epoch) => To<Date>;
56
52
  };
57
53
  }
@@ -1,6 +1,6 @@
1
1
  import { ArkErrors, intrinsic, rootNode } from "@ark/schema";
2
2
  import { number } from "../number/number.js";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
4
  import { integer } from "./integer.js";
5
5
  import { regexStringNode } from "./utils.js";
6
6
  const dayDelimiterMatcher = /^[./-]$/;
@@ -47,7 +47,7 @@ const parsableDate = rootNode({
47
47
  predicate: isParsableDate
48
48
  }
49
49
  }).assertHasKind("intersection");
50
- const epoch$root = integer.$root.internal
50
+ const epochroot = integer.root.internal
51
51
  .narrow((s, ctx) => {
52
52
  // we know this is safe since it has already
53
53
  // been validated as an integer string
@@ -63,25 +63,25 @@ const epoch$root = integer.$root.internal
63
63
  description: "an integer string representing a safe Unix timestamp"
64
64
  })
65
65
  .assertHasKind("intersection");
66
- const epoch = submodule({
67
- $root: epoch$root,
66
+ const epoch = arkModule({
67
+ root: epochroot,
68
68
  parse: rootNode({
69
- in: epoch$root,
69
+ in: epochroot,
70
70
  morphs: (s) => new Date(s),
71
71
  declaredOut: intrinsic.Date
72
72
  })
73
73
  });
74
- const iso$root = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
75
- const iso = submodule({
76
- $root: iso$root,
74
+ const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
75
+ const iso = arkModule({
76
+ root: isoroot,
77
77
  parse: rootNode({
78
- in: iso$root,
78
+ in: isoroot,
79
79
  morphs: (s) => new Date(s),
80
80
  declaredOut: intrinsic.Date
81
81
  })
82
82
  });
83
- export const stringDate = submodule({
84
- $root: parsableDate,
83
+ export const stringDate = arkModule({
84
+ root: parsableDate,
85
85
  parse: rootNode({
86
86
  declaredIn: parsableDate,
87
87
  in: "string",
@@ -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
1
  import { intrinsic, rootNode } 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,
5
+ const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
+ export const integer = arkModule({
7
+ root,
8
8
  parse: rootNode({
9
- in: $root,
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"));
@@ -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,4 +1,4 @@
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
4
  const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
@@ -16,8 +16,8 @@ const ipv6Matcher = new RegExp("^(" +
16
16
  `(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
17
17
  ")(%[0-9a-zA-Z-.:]{1,})?$");
18
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"],
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
  });
@@ -8,7 +8,7 @@ export declare namespace stringJson {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: string.json;
11
+ root: string.json;
12
12
  parse: (In: string.json) => To<object>;
13
13
  };
14
14
  }
@@ -1,5 +1,5 @@
1
1
  import { intrinsic, rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
2
+ import { arkModule } from "../utils.js";
3
3
  const jsonStringDescription = "a JSON string";
4
4
  const isParsableJson = (s) => {
5
5
  try {
@@ -10,15 +10,15 @@ const isParsableJson = (s) => {
10
10
  return false;
11
11
  }
12
12
  };
13
- const $root = rootNode({
13
+ const root = rootNode({
14
14
  domain: "string",
15
15
  predicate: {
16
16
  meta: jsonStringDescription,
17
17
  predicate: isParsableJson
18
18
  }
19
19
  });
20
- export const json = submodule({
21
- $root,
20
+ export const json = arkModule({
21
+ root,
22
22
  parse: rootNode({
23
23
  in: "string",
24
24
  morphs: (s, ctx) => {
@@ -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
1
  import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
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: rootNode({
7
7
  in: "string",
8
8
  morphs: (s) => s.toLowerCase(),
9
9
  declaredOut: preformatted
@@ -1,5 +1,4 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { type } from "../ark.ts";
3
2
  import type { Branded, constrain, To } from "../ast.ts";
4
3
  declare namespace string {
5
4
  type normalized = normalized.NFC;
@@ -13,37 +12,37 @@ 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: unknown;
15
+ root: unknown;
17
16
  preformatted: unknown;
18
17
  }>;
19
18
  export declare const NFD: Module<{
20
- $root: unknown;
19
+ root: unknown;
21
20
  preformatted: unknown;
22
21
  }>;
23
22
  export declare const NFKC: Module<{
24
- $root: unknown;
23
+ root: unknown;
25
24
  preformatted: unknown;
26
25
  }>;
27
26
  export declare const NFKD: Module<{
28
- $root: unknown;
27
+ root: unknown;
29
28
  preformatted: unknown;
30
29
  }>;
31
30
  export declare const normalize: Module<{
32
- $root: unknown;
31
+ root: unknown;
33
32
  NFC: Submodule<{
34
- $root: unknown;
33
+ root: unknown;
35
34
  preformatted: unknown;
36
35
  }>;
37
36
  NFD: Submodule<{
38
- $root: unknown;
37
+ root: unknown;
39
38
  preformatted: unknown;
40
39
  }>;
41
40
  NFKC: Submodule<{
42
- $root: unknown;
41
+ root: unknown;
43
42
  preformatted: unknown;
44
43
  }>;
45
44
  NFKD: Submodule<{
46
- $root: unknown;
45
+ root: unknown;
47
46
  preformatted: unknown;
48
47
  }>;
49
48
  }>;
@@ -51,40 +50,37 @@ 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,6 +1,6 @@
1
1
  import { rootNode } 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,
@@ -18,24 +18,24 @@ const normalizeNodes = flatMorph(normalizedForms, (i, 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,
@@ -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
1
  import { intrinsic, rootNode } 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,
5
+ const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
+ export const numeric = arkModule({
7
+ root,
8
8
  parse: rootNode({
9
- in: $root,
9
+ in: root,
10
10
  morphs: (s) => Number.parseFloat(s),
11
11
  declaredOut: intrinsic.number
12
12
  })
@@ -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, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
5
3
  import { alpha } from "./alpha.ts";
6
4
  import { alphanumeric } from "./alphanumeric.ts";
7
5
  import { capitalize } from "./capitalize.ts";
@@ -23,31 +21,33 @@ import { uuid } from "./uuid.ts";
23
21
  export declare const string: Module<{
24
22
  trim: Submodule<trim.submodule>;
25
23
  normalize: Submodule<{
26
- $root: unknown;
24
+ root: unknown;
27
25
  NFC: Submodule<{
28
- $root: unknown;
26
+ root: unknown;
29
27
  preformatted: unknown;
30
28
  }>;
31
29
  NFD: Submodule<{
32
- $root: unknown;
30
+ root: unknown;
33
31
  preformatted: unknown;
34
32
  }>;
35
33
  NFKC: Submodule<{
36
- $root: unknown;
34
+ root: unknown;
37
35
  preformatted: unknown;
38
36
  }>;
39
37
  NFKD: Submodule<{
40
- $root: unknown;
38
+ root: unknown;
41
39
  preformatted: unknown;
42
40
  }>;
43
41
  }>;
42
+ root: unknown;
43
+ date: Submodule<stringDate.submodule>;
44
+ lower: Submodule<lower.submodule>;
45
+ upper: Submodule<upper.submodule>;
44
46
  json: Submodule<stringJson.submodule>;
45
- $root: unknown;
46
47
  integer: Submodule<stringInteger.submodule>;
47
48
  alpha: unknown;
48
49
  alphanumeric: unknown;
49
50
  creditCard: unknown;
50
- date: Submodule<stringDate.submodule>;
51
51
  digits: unknown;
52
52
  email: unknown;
53
53
  ip: Submodule<ip.submodule>;
@@ -55,7 +55,7 @@ export declare const string: Module<{
55
55
  semver: unknown;
56
56
  url: Submodule<url.submodule>;
57
57
  uuid: Submodule<{
58
- $root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
58
+ root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
59
59
  v4: unknown;
60
60
  v6: unknown;
61
61
  v1: unknown;
@@ -65,10 +65,11 @@ export declare const string: Module<{
65
65
  v7: unknown;
66
66
  v8: unknown;
67
67
  }>;
68
- upper: Submodule<upper.submodule>;
69
- lower: Submodule<lower.submodule>;
70
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,14 @@ 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>;
80
82
  type branded<rule> = constrain<string, Branded<rule>>;
81
83
  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;
84
+ 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 Narrowed ? narrowed : never;
87
85
  type module = Module<string.submodule>;
88
86
  type submodule = Submodule<$>;
89
87
  type $ = {
90
- $root: string;
88
+ root: string;
91
89
  alpha: alpha;
92
90
  alphanumeric: alphanumeric;
93
91
  digits: digits;
@@ -100,13 +98,11 @@ export declare namespace string {
100
98
  ip: ip.submodule;
101
99
  json: stringJson.submodule;
102
100
  date: stringDate.submodule;
101
+ url: url.submodule;
103
102
  trim: trim.submodule;
104
103
  normalize: normalize.submodule;
105
104
  capitalize: capitalize.submodule;
106
105
  lower: lower.submodule;
107
106
  upper: upper.submodule;
108
107
  };
109
- type shallowResolutions = {
110
- [k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
111
- };
112
108
  }
@@ -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,