arktype 2.0.0-rc.3 → 2.0.0-rc.5

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 (80) hide show
  1. package/out/generic.js +1 -1
  2. package/out/index.d.ts +1 -1
  3. package/out/index.js +1 -1
  4. package/out/keywords/ark.d.ts +17 -1
  5. package/out/keywords/ast.d.ts +94 -101
  6. package/out/keywords/constructors/Array.d.ts +1 -1
  7. package/out/keywords/constructors/Array.js +2 -2
  8. package/out/keywords/constructors/Date.d.ts +31 -0
  9. package/out/keywords/constructors/FormData.d.ts +1 -1
  10. package/out/keywords/constructors/FormData.js +1 -1
  11. package/out/keywords/number/epoch.d.ts +1 -2
  12. package/out/keywords/number/number.d.ts +23 -6
  13. package/out/keywords/number/number.js +1 -1
  14. package/out/keywords/string/capitalize.d.ts +1 -1
  15. package/out/keywords/string/capitalize.js +1 -1
  16. package/out/keywords/string/date.d.ts +3 -3
  17. package/out/keywords/string/date.js +7 -7
  18. package/out/keywords/string/integer.d.ts +1 -1
  19. package/out/keywords/string/integer.js +3 -3
  20. package/out/keywords/string/ip.d.ts +1 -1
  21. package/out/keywords/string/ip.js +1 -1
  22. package/out/keywords/string/json.d.ts +1 -1
  23. package/out/keywords/string/json.js +2 -2
  24. package/out/keywords/string/lower.d.ts +1 -1
  25. package/out/keywords/string/lower.js +1 -1
  26. package/out/keywords/string/normalize.d.ts +22 -22
  27. package/out/keywords/string/normalize.js +5 -5
  28. package/out/keywords/string/numeric.d.ts +1 -1
  29. package/out/keywords/string/numeric.js +3 -3
  30. package/out/keywords/string/string.d.ts +35 -36
  31. package/out/keywords/string/string.js +1 -1
  32. package/out/keywords/string/trim.d.ts +1 -1
  33. package/out/keywords/string/trim.js +1 -1
  34. package/out/keywords/string/upper.d.ts +1 -1
  35. package/out/keywords/string/upper.js +1 -1
  36. package/out/keywords/string/url.d.ts +1 -1
  37. package/out/keywords/string/url.js +3 -3
  38. package/out/keywords/string/uuid.d.ts +10 -10
  39. package/out/keywords/string/uuid.js +1 -1
  40. package/out/{subtypes → methods}/array.d.ts +6 -6
  41. package/out/{subtypes → methods}/base.d.ts +17 -15
  42. package/out/{subtypes → methods}/date.d.ts +5 -5
  43. package/out/{subtypes → methods}/morph.d.ts +2 -2
  44. package/out/{subtypes → methods}/number.d.ts +6 -6
  45. package/out/{subtypes → methods}/string.d.ts +7 -7
  46. package/out/{subtypes → methods}/validator.d.ts +2 -2
  47. package/out/methods/validator.js +1 -0
  48. package/out/module.d.ts +2 -2
  49. package/out/parser/definition.d.ts +1 -1
  50. package/out/parser/objectLiteral.d.ts +5 -30
  51. package/out/parser/objectLiteral.js +18 -21
  52. package/out/parser/semantic/default.d.ts +1 -2
  53. package/out/parser/semantic/default.js +1 -1
  54. package/out/parser/semantic/infer.d.ts +7 -6
  55. package/out/parser/semantic/validate.d.ts +2 -2
  56. package/out/parser/string/reduce/dynamic.d.ts +1 -2
  57. package/out/parser/string/reduce/dynamic.js +2 -4
  58. package/out/parser/string/shift/operand/date.d.ts +2 -0
  59. package/out/parser/string/shift/operand/enclosed.d.ts +2 -1
  60. package/out/parser/string/shift/operator/default.d.ts +2 -5
  61. package/out/parser/string/shift/operator/default.js +1 -6
  62. package/out/parser/string/string.d.ts +2 -3
  63. package/out/parser/tuple.d.ts +6 -5
  64. package/out/parser/tuple.js +3 -1
  65. package/out/scope.d.ts +8 -5
  66. package/out/scope.js +7 -6
  67. package/out/type.d.ts +8 -4
  68. package/out/type.js +3 -1
  69. package/package.json +3 -3
  70. /package/out/{subtypes/array.js → keywords/constructors/Date.js} +0 -0
  71. /package/out/{subtypes/base.js → methods/array.js} +0 -0
  72. /package/out/{subtypes/date.js → methods/base.js} +0 -0
  73. /package/out/{subtypes/instantiate.js → methods/date.js} +0 -0
  74. /package/out/{subtypes → methods}/instantiate.d.ts +0 -0
  75. /package/out/{subtypes/morph.js → methods/instantiate.js} +0 -0
  76. /package/out/{subtypes/number.js → methods/morph.js} +0 -0
  77. /package/out/{subtypes/object.js → methods/number.js} +0 -0
  78. /package/out/{subtypes → methods}/object.d.ts +0 -0
  79. /package/out/{subtypes/string.js → methods/object.js} +0 -0
  80. /package/out/{subtypes/validator.js → methods/string.js} +0 -0
@@ -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
  }
@@ -3,7 +3,7 @@ import { submodule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
5
5
  export const lower = submodule({
6
- $root: rootNode({
6
+ root: rootNode({
7
7
  in: "string",
8
8
  morphs: (s) => s.toLowerCase(),
9
9
  declaredOut: preformatted
@@ -13,45 +13,45 @@ declare namespace string {
13
13
  export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
14
14
  export type NormalizedForm = (typeof normalizedForms)[number];
15
15
  export declare const NFC: Module<{
16
- $root: object;
17
- preformatted: object;
16
+ root: unknown;
17
+ preformatted: unknown;
18
18
  }>;
19
19
  export declare const NFD: Module<{
20
- $root: object;
21
- preformatted: object;
20
+ root: unknown;
21
+ preformatted: unknown;
22
22
  }>;
23
23
  export declare const NFKC: Module<{
24
- $root: object;
25
- preformatted: object;
24
+ root: unknown;
25
+ preformatted: unknown;
26
26
  }>;
27
27
  export declare const NFKD: Module<{
28
- $root: object;
29
- preformatted: object;
28
+ root: unknown;
29
+ preformatted: unknown;
30
30
  }>;
31
31
  export declare const normalize: Module<{
32
- $root: object;
32
+ root: unknown;
33
33
  NFC: Submodule<{
34
- $root: object;
35
- preformatted: object;
34
+ root: unknown;
35
+ preformatted: unknown;
36
36
  }>;
37
37
  NFD: Submodule<{
38
- $root: object;
39
- preformatted: object;
38
+ root: unknown;
39
+ preformatted: unknown;
40
40
  }>;
41
41
  NFKC: Submodule<{
42
- $root: object;
43
- preformatted: object;
42
+ root: unknown;
43
+ preformatted: unknown;
44
44
  }>;
45
45
  NFKD: Submodule<{
46
- $root: object;
47
- preformatted: object;
46
+ root: unknown;
47
+ preformatted: unknown;
48
48
  }>;
49
49
  }>;
50
50
  export declare namespace normalize {
51
51
  type module = Module<submodule>;
52
52
  type submodule = Submodule<$>;
53
53
  type $ = {
54
- $root: (In: string) => To<string.normalized.NFC>;
54
+ root: (In: string) => To<string.normalized.NFC>;
55
55
  NFC: NFC.submodule;
56
56
  NFD: NFD.submodule;
57
57
  NFKC: NFKC.submodule;
@@ -63,28 +63,28 @@ export declare namespace normalize {
63
63
  namespace NFC {
64
64
  type submodule = Submodule<$>;
65
65
  type $ = {
66
- $root: (In: string) => To<string.normalized.NFC>;
66
+ root: (In: string) => To<string.normalized.NFC>;
67
67
  preformatted: string.normalized.NFC;
68
68
  };
69
69
  }
70
70
  namespace NFD {
71
71
  type submodule = Submodule<$>;
72
72
  type $ = {
73
- $root: (In: string) => To<string.normalized.NFD>;
73
+ root: (In: string) => To<string.normalized.NFD>;
74
74
  preformatted: string.normalized.NFD;
75
75
  };
76
76
  }
77
77
  namespace NFKC {
78
78
  type submodule = Submodule<$>;
79
79
  type $ = {
80
- $root: (In: string) => To<string.normalized.NFKC>;
80
+ root: (In: string) => To<string.normalized.NFKC>;
81
81
  preformatted: string.normalized.NFKC;
82
82
  };
83
83
  }
84
84
  namespace NFKD {
85
85
  type submodule = Submodule<$>;
86
86
  type $ = {
87
- $root: (In: string) => To<string.normalized.NFKD>;
87
+ root: (In: string) => To<string.normalized.NFKD>;
88
88
  preformatted: string.normalized.NFKD;
89
89
  };
90
90
  }
@@ -19,23 +19,23 @@ const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
19
19
  })
20
20
  ]);
21
21
  export const NFC = submodule({
22
- $root: normalizeNodes.NFC,
22
+ root: normalizeNodes.NFC,
23
23
  preformatted: preformattedNodes.NFC
24
24
  });
25
25
  export const NFD = submodule({
26
- $root: normalizeNodes.NFD,
26
+ root: normalizeNodes.NFD,
27
27
  preformatted: preformattedNodes.NFD
28
28
  });
29
29
  export const NFKC = submodule({
30
- $root: normalizeNodes.NFKC,
30
+ root: normalizeNodes.NFKC,
31
31
  preformatted: preformattedNodes.NFKC
32
32
  });
33
33
  export const NFKD = submodule({
34
- $root: normalizeNodes.NFKD,
34
+ root: normalizeNodes.NFKD,
35
35
  preformatted: preformattedNodes.NFKD
36
36
  });
37
37
  export const normalize = submodule({
38
- $root: "NFC",
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
  }
@@ -2,11 +2,11 @@ import { intrinsic, rootNode } from "@ark/schema";
2
2
  import { wellFormedNumberMatcher } from "@ark/util";
3
3
  import { submodule } from "../utils.js";
4
4
  import { regexStringNode } from "./utils.js";
5
- const $root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
5
+ const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
6
  export const numeric = submodule({
7
- $root,
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,6 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
2
1
  import type { Module, Submodule } from "../../module.ts";
3
2
  import type { type } from "../ark.ts";
4
- import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
3
+ import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
5
4
  import { alpha } from "./alpha.ts";
6
5
  import { alphanumeric } from "./alphanumeric.ts";
7
6
  import { capitalize } from "./capitalize.ts";
@@ -23,52 +22,55 @@ import { uuid } from "./uuid.ts";
23
22
  export declare const string: Module<{
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
+ root: unknown;
44
+ date: Submodule<stringDate.submodule>;
45
+ lower: Submodule<lower.submodule>;
46
+ upper: Submodule<upper.submodule>;
44
47
  json: Submodule<stringJson.submodule>;
45
- $root: object;
46
48
  integer: Submodule<stringInteger.submodule>;
47
- alpha: object;
48
- alphanumeric: object;
49
- creditCard: object;
50
- date: Submodule<stringDate.submodule>;
51
- digits: object;
52
- email: object;
49
+ alpha: unknown;
50
+ alphanumeric: unknown;
51
+ creditCard: unknown;
52
+ digits: unknown;
53
+ email: unknown;
53
54
  ip: Submodule<ip.submodule>;
54
55
  numeric: Submodule<stringNumeric.submodule>;
55
- semver: object;
56
+ semver: unknown;
56
57
  url: Submodule<url.submodule>;
57
58
  uuid: Submodule<{
58
- $root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
59
- v4: object;
60
- v6: object;
61
- v1: object;
62
- v2: object;
63
- v3: object;
64
- v5: object;
65
- v7: object;
66
- v8: object;
59
+ root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
60
+ v4: unknown;
61
+ v6: unknown;
62
+ v1: unknown;
63
+ v2: unknown;
64
+ v3: unknown;
65
+ v5: unknown;
66
+ v7: unknown;
67
+ v8: unknown;
67
68
  }>;
68
- upper: Submodule<upper.submodule>;
69
- lower: Submodule<lower.submodule>;
70
69
  capitalize: Submodule<capitalize.submodule>;
71
70
  }>;
71
+ export type Matching<rule> = {
72
+ matching: constraint<rule>;
73
+ };
72
74
  export declare namespace string {
73
75
  type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
74
76
  type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
@@ -77,17 +79,14 @@ export declare namespace string {
77
79
  type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
78
80
  type matching<rule> = constrain<string, Matching<rule>>;
79
81
  type narrowed = constrain<string, Narrowed>;
82
+ type optional = constrain<string, Optional>;
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 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;
@@ -19,7 +19,7 @@ import { upper } from "./upper.js";
19
19
  import { url } from "./url.js";
20
20
  import { uuid } from "./uuid.js";
21
21
  export const string = submodule({
22
- $root: intrinsic.string,
22
+ root: intrinsic.string,
23
23
  numeric,
24
24
  integer,
25
25
  alpha,
@@ -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
  }
@@ -5,7 +5,7 @@ const preformatted = regexStringNode(
5
5
  // no leading or trailing whitespace
6
6
  /^\S.*\S$|^\S?$/, "trimmed");
7
7
  export const trim = submodule({
8
- $root: rootNode({
8
+ root: rootNode({
9
9
  in: "string",
10
10
  morphs: (s) => s.trim(),
11
11
  declaredOut: preformatted
@@ -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
  }
@@ -3,7 +3,7 @@ import { submodule } from "../utils.js";
3
3
  import { regexStringNode } from "./utils.js";
4
4
  const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
5
5
  export const upper = submodule({
6
- $root: rootNode({
6
+ root: rootNode({
7
7
  in: "string",
8
8
  morphs: (s) => s.toUpperCase(),
9
9
  declaredOut: preformatted
@@ -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
  }
@@ -12,7 +12,7 @@ const isParsableUrl = (s) => {
12
12
  return false;
13
13
  }
14
14
  };
15
- const $root = rootNode({
15
+ const root = rootNode({
16
16
  domain: "string",
17
17
  predicate: {
18
18
  meta: "a URL string",
@@ -20,9 +20,9 @@ const $root = rootNode({
20
20
  }
21
21
  });
22
22
  export const url = submodule({
23
- $root,
23
+ root,
24
24
  parse: rootNode({
25
- declaredIn: $root,
25
+ declaredIn: root,
26
26
  in: "string",
27
27
  morphs: (s, ctx) => {
28
28
  try {
@@ -1,15 +1,15 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain } from "../ast.ts";
3
3
  export declare const uuid: Module<{
4
- $root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
- v4: object;
6
- v6: object;
7
- v1: object;
8
- v2: object;
9
- v3: object;
10
- v5: object;
11
- v7: object;
12
- v8: object;
4
+ root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
+ v4: unknown;
6
+ v6: unknown;
7
+ v1: unknown;
8
+ v2: unknown;
9
+ v3: unknown;
10
+ v5: unknown;
11
+ v7: unknown;
12
+ v8: unknown;
13
13
  }>;
14
14
  declare namespace string {
15
15
  type uuid = constrain<string, Branded<"uuid">>;
@@ -28,7 +28,7 @@ export declare namespace uuid {
28
28
  type module = Module<submodule>;
29
29
  type submodule = Submodule<$>;
30
30
  type $ = {
31
- $root: string.uuid;
31
+ root: string.uuid;
32
32
  v1: string.uuid.v1;
33
33
  v2: string.uuid.v2;
34
34
  v3: string.uuid.v3;
@@ -4,7 +4,7 @@ import { regexStringNode } from "./utils.js";
4
4
  export const uuid = submodule({
5
5
  // the meta tuple expression ensures the error message does not delegate
6
6
  // to the individual branches, which are too detailed
7
- $root: ["versioned | nil | max", "@", "a UUID"],
7
+ root: ["versioned | nil | max", "@", "a UUID"],
8
8
  "#nil": "'00000000-0000-0000-0000-000000000000'",
9
9
  "#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
10
10
  "#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
@@ -1,13 +1,13 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/ast.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  interface Type<
5
5
  /** @ts-ignore cast variance */
6
6
  out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> {
7
- atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", schema>, $>;
8
- atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", schema>, $>;
9
- moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
- lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
- exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
7
+ atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", schema>, $>;
8
+ atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", schema>, $>;
9
+ moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraintSchema<t, "exactLength", schema>, $>;
12
12
  }
13
13
  export type { Type as ArrayType };
@@ -1,19 +1,19 @@
1
1
  import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
2
2
  import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
3
3
  import type { inferIntersection } from "../intersect.ts";
4
- import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes } from "../keywords/ast.ts";
4
+ import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
5
5
  import type { Scope } from "../scope.ts";
6
6
  import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
7
7
  import type { ArrayType } from "./array.ts";
8
8
  import type { instantiateType } from "./instantiate.ts";
9
9
  /** @ts-ignore cast variance */
10
- interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> {
10
+ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
11
11
  t: t;
12
- tIn: distillConstrainableIn<t>;
13
- tOut: distillConstrainableOut<t>;
14
- tValidatedOut: distillValidatedOut<t>;
15
- infer: distillOut<t>;
16
- inferIn: distillIn<t>;
12
+ tIn: distill.brandable.In<t>;
13
+ tOut: distill.brandable.Out<t>;
14
+ tValidatedOut: distill.introspectable.Out<t>;
15
+ infer: distill.Out<t>;
16
+ inferIn: distill.In<t>;
17
17
  [inferred]: t;
18
18
  json: Json;
19
19
  toJsonSchema(): JsonSchema;
@@ -23,9 +23,11 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
23
23
  $: Scope<$>;
24
24
  assert(data: unknown): this["infer"];
25
25
  allows(data: unknown): data is this["inferIn"];
26
- traverse(data: unknown): distillOut<t> | ArkErrors;
26
+ traverse(data: unknown): distill.Out<t> | ArkErrors;
27
27
  configure(meta: MetaSchema): this;
28
28
  describe(description: string): this;
29
+ optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
30
+ default<value extends this["infer"], r = (In?: this["tIn"]) => Default<value>>(value: value): instantiateType<r, $>;
29
31
  onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
30
32
  onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
31
33
  from(literal: this["inferIn"]): this["infer"];
@@ -63,13 +65,13 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
63
65
  Symbol: never;
64
66
  }
65
67
  interface ChainedPipeSignature<t, $> {
66
- <a extends Morph<distillOut<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
67
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
68
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
69
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): r;
70
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): r;
71
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): r;
72
- <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): r;
68
+ <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
69
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
70
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
71
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): r;
72
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): r;
73
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): r;
74
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): r;
73
75
  }
74
76
  export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
75
77
  try: ChainedPipeSignature<t, $>;
@@ -1,11 +1,11 @@
1
1
  import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/ast.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
6
- atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "after", schema>, $>;
7
- atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "before", schema>, $>;
8
- laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "after", exclusivizeRangeSchema<schema>>, $>;
9
- earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "before", exclusivizeRangeSchema<schema>>, $>;
6
+ atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "after", schema>, $>;
7
+ atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "before", schema>, $>;
8
+ laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "after", exclusivizeRangeSchema<schema>>, $>;
9
+ earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "before", exclusivizeRangeSchema<schema>>, $>;
10
10
  }
11
11
  export type { Type as DateType };
@@ -1,6 +1,6 @@
1
1
  import type { Predicate, PredicateCast } from "@ark/schema";
2
2
  import type { inferPipe } from "../intersect.ts";
3
- import type { applyConstraint, Out, To } from "../keywords/ast.ts";
3
+ import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
4
4
  import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
5
5
  import type { BaseType } from "./base.ts";
6
6
  /** @ts-ignore cast variance */
@@ -8,6 +8,6 @@ interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
8
8
  to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
9
9
  narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
10
10
  narrowed
11
- ] extends [never] ? applyConstraint<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
11
+ ] extends [never] ? applyConstraintSchema<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
12
12
  }
13
13
  export type { Type as MorphType };
@@ -1,12 +1,12 @@
1
1
  import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/ast.ts";
3
3
  import type { ValidatorType } from "./validator.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
6
- divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraint<t, "divisor", schema>, $>;
7
- atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", schema>, $>;
8
- atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "max", schema>, $>;
9
- moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", exclusivizeRangeSchema<schema>>, $>;
10
- lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "max", exclusivizeRangeSchema<schema>>, $>;
6
+ divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraintSchema<t, "divisor", schema>, $>;
7
+ atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "min", schema>, $>;
8
+ atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "max", schema>, $>;
9
+ moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "min", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "max", exclusivizeRangeSchema<schema>>, $>;
11
11
  }
12
12
  export type { Type as NumberType };
@@ -1,13 +1,13 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/ast.ts";
3
3
  import type { ValidatorType } from "./validator.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
6
- matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraint<t, "pattern", schema>, $>;
7
- atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", schema>, $>;
8
- atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", schema>, $>;
9
- moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
- lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
- exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
6
+ matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraintSchema<t, "pattern", schema>, $>;
7
+ atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", schema>, $>;
8
+ atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", schema>, $>;
9
+ moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraintSchema<t, "exactLength", schema>, $>;
12
12
  }
13
13
  export type { Type as StringType };
@@ -1,11 +1,11 @@
1
1
  import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/ast.ts";
3
3
  import type { BaseType } from "./base.ts";
4
4
  import type { instantiateType } from "./instantiate.ts";
5
5
  /** @ts-ignore cast variance */
6
6
  interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
7
7
  narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<[
8
8
  narrowed
9
- ] extends [never] ? applyConstraint<t, "predicate", Predicate> : narrowed, $>;
9
+ ] extends [never] ? applyConstraintSchema<t, "predicate", Predicate> : narrowed, $>;
10
10
  }
11
11
  export type { Type as ValidatorType };
@@ -0,0 +1 @@
1
+ export {};
package/out/module.d.ts CHANGED
@@ -12,8 +12,8 @@ export interface BoundModule<exports extends {}, $> extends RootModule<bindExpor
12
12
  export type bindExportsToScope<exports, $> = {
13
13
  [k in keyof exports]: instantiateExport<exports[k], $>;
14
14
  } & unknown;
15
- export type Submodule<exports extends {}> = RootModule<exports & ("$root" extends keyof exports ? {
16
- [inferred]: exports["$root"];
15
+ export type Submodule<exports extends {}> = RootModule<exports & ("root" extends keyof exports ? {
16
+ [inferred]: exports["root"];
17
17
  } : {})>;
18
18
  export type instantiateExport<t, $> = [
19
19
  t
@@ -10,7 +10,7 @@ import { type TupleExpression, type inferTuple, type validateTuple } from "./tup
10
10
  export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
11
11
  export type inferDefinition<def, $, args> = [
12
12
  def
13
- ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<t, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
13
+ ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
14
14
  export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
15
15
  export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
16
16
  type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {