arktype 2.0.0-rc.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +18 -18
  5. package/out/generic.js +2 -2
  6. package/out/index.d.ts +4 -2
  7. package/out/index.js +3 -2
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  9. package/out/keywords/{constructors/Array.js → Array.js} +2 -2
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
  12. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  13. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  14. package/out/keywords/builtins.js +2 -2
  15. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/{ark.d.ts → keywords.d.ts} +16 -15
  18. package/out/keywords/keywords.js +30 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +22 -1
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +31 -4
  24. package/out/keywords/ts.js +21 -8
  25. package/out/methods/array.d.ts +6 -7
  26. package/out/methods/base.d.ts +461 -34
  27. package/out/methods/date.d.ts +5 -6
  28. package/out/methods/instantiate.d.ts +5 -5
  29. package/out/methods/morph.d.ts +6 -7
  30. package/out/methods/number.d.ts +8 -9
  31. package/out/methods/object.d.ts +80 -31
  32. package/out/methods/string.d.ts +9 -10
  33. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  34. package/out/parser/{semantic → ast}/default.d.ts +4 -4
  35. package/out/parser/ast/generic.d.ts +17 -0
  36. package/out/parser/ast/infer.d.ts +25 -0
  37. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  38. package/out/parser/ast/validate.d.ts +30 -0
  39. package/out/parser/ast/validate.js +3 -0
  40. package/out/parser/definition.d.ts +18 -9
  41. package/out/parser/definition.js +38 -3
  42. package/out/parser/objectLiteral.d.ts +40 -40
  43. package/out/parser/objectLiteral.js +83 -67
  44. package/out/parser/property.d.ts +36 -0
  45. package/out/parser/property.js +16 -0
  46. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +8 -9
  47. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  48. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  49. package/out/parser/{string/shift → shift}/operand/date.d.ts +1 -1
  50. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -5
  51. package/out/parser/shift/operand/operand.d.ts +9 -0
  52. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  53. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  54. package/out/parser/{string/shift → shift}/operand/unenclosed.js +6 -5
  55. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  56. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  57. package/out/parser/shift/operator/brand.d.ts +6 -0
  58. package/out/parser/shift/operator/brand.js +5 -0
  59. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -2
  60. package/out/parser/{string/shift → shift}/operator/default.js +4 -1
  61. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  62. package/out/parser/shift/operator/operator.d.ts +14 -0
  63. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  64. package/out/parser/shift/scanner.d.ts +47 -0
  65. package/out/parser/shift/scanner.js +43 -0
  66. package/out/parser/{string/string.d.ts → string.d.ts} +7 -6
  67. package/out/parser/{string/string.js → string.js} +18 -1
  68. package/out/parser/tupleExpressions.d.ts +48 -0
  69. package/out/parser/tupleExpressions.js +67 -0
  70. package/out/parser/tupleLiteral.d.ts +95 -0
  71. package/out/parser/tupleLiteral.js +122 -0
  72. package/out/scope.d.ts +19 -14
  73. package/out/scope.js +25 -41
  74. package/out/type.d.ts +67 -9
  75. package/out/type.js +4 -3
  76. package/package.json +8 -8
  77. package/out/intersect.d.ts +0 -26
  78. package/out/keys.d.ts +0 -18
  79. package/out/keys.js +0 -1
  80. package/out/keywords/ark.js +0 -26
  81. package/out/keywords/ast.d.ts +0 -198
  82. package/out/keywords/ast.js +0 -2
  83. package/out/keywords/constructors/Date.d.ts +0 -31
  84. package/out/keywords/constructors/Date.js +0 -1
  85. package/out/keywords/number/epoch.d.ts +0 -9
  86. package/out/keywords/number/integer.d.ts +0 -3
  87. package/out/keywords/number/integer.js +0 -5
  88. package/out/keywords/number/number.d.ts +0 -53
  89. package/out/keywords/number/number.js +0 -21
  90. package/out/keywords/string/alpha.d.ts +0 -7
  91. package/out/keywords/string/alpha.js +0 -2
  92. package/out/keywords/string/alphanumeric.d.ts +0 -7
  93. package/out/keywords/string/alphanumeric.js +0 -2
  94. package/out/keywords/string/capitalize.d.ts +0 -15
  95. package/out/keywords/string/capitalize.js +0 -12
  96. package/out/keywords/string/creditCard.d.ts +0 -8
  97. package/out/keywords/string/creditCard.js +0 -37
  98. package/out/keywords/string/date.d.ts +0 -55
  99. package/out/keywords/string/date.js +0 -98
  100. package/out/keywords/string/digits.d.ts +0 -7
  101. package/out/keywords/string/digits.js +0 -2
  102. package/out/keywords/string/email.d.ts +0 -7
  103. package/out/keywords/string/email.js +0 -4
  104. package/out/keywords/string/integer.d.ts +0 -16
  105. package/out/keywords/string/integer.js +0 -16
  106. package/out/keywords/string/ip.d.ts +0 -20
  107. package/out/keywords/string/ip.js +0 -23
  108. package/out/keywords/string/json.d.ts +0 -16
  109. package/out/keywords/string/json.js +0 -53
  110. package/out/keywords/string/lower.d.ts +0 -15
  111. package/out/keywords/string/lower.js +0 -12
  112. package/out/keywords/string/normalize.d.ts +0 -88
  113. package/out/keywords/string/normalize.js +0 -43
  114. package/out/keywords/string/numeric.d.ts +0 -15
  115. package/out/keywords/string/numeric.js +0 -13
  116. package/out/keywords/string/semver.d.ts +0 -7
  117. package/out/keywords/string/semver.js +0 -4
  118. package/out/keywords/string/string.d.ts +0 -108
  119. package/out/keywords/string/string.js +0 -41
  120. package/out/keywords/string/trim.d.ts +0 -15
  121. package/out/keywords/string/trim.js +0 -14
  122. package/out/keywords/string/upper.d.ts +0 -15
  123. package/out/keywords/string/upper.js +0 -12
  124. package/out/keywords/string/url.d.ts +0 -15
  125. package/out/keywords/string/url.js +0 -37
  126. package/out/keywords/string/utils.d.ts +0 -2
  127. package/out/keywords/string/utils.js +0 -10
  128. package/out/keywords/string/uuid.d.ts +0 -42
  129. package/out/keywords/string/uuid.js +0 -19
  130. package/out/keywords/utils.d.ts +0 -1
  131. package/out/keywords/utils.js +0 -2
  132. package/out/methods/validator.d.ts +0 -11
  133. package/out/methods/validator.js +0 -1
  134. package/out/parser/semantic/infer.d.ts +0 -41
  135. package/out/parser/semantic/validate.d.ts +0 -26
  136. package/out/parser/semantic/validate.js +0 -1
  137. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  138. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  139. package/out/parser/string/shift/scanner.d.ts +0 -71
  140. package/out/parser/string/shift/scanner.js +0 -102
  141. package/out/parser/tuple.d.ts +0 -144
  142. package/out/parser/tuple.js +0 -164
  143. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  144. /package/out/parser/{semantic → ast}/default.js +0 -0
  145. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  146. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  147. /package/out/{intersect.js → parser/ast/generic.js} +0 -0
  148. /package/out/parser/{semantic → ast}/infer.js +0 -0
  149. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  150. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  151. /package/out/parser/{semantic → ast}/utils.js +0 -0
  152. /package/out/parser/{string/reduce → reduce}/dynamic.js +0 -0
  153. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  154. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  155. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  156. /package/out/parser/{string/shift → shift}/operand/enclosed.js +0 -0
  157. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  158. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  159. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,43 +0,0 @@
1
- import { rootSchema } from "@ark/schema";
2
- import { flatMorph } from "@ark/util";
3
- import { arkModule } from "../utils.js";
4
- export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
5
- const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
6
- form,
7
- rootSchema({
8
- domain: "string",
9
- predicate: (s) => s.normalize(form) === s,
10
- meta: `${form}-normalized unicode`
11
- })
12
- ]);
13
- const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
14
- form,
15
- rootSchema({
16
- in: "string",
17
- morphs: (s) => s.normalize(form),
18
- declaredOut: preformattedNodes[form]
19
- })
20
- ]);
21
- export const NFC = arkModule({
22
- root: normalizeNodes.NFC,
23
- preformatted: preformattedNodes.NFC
24
- });
25
- export const NFD = arkModule({
26
- root: normalizeNodes.NFD,
27
- preformatted: preformattedNodes.NFD
28
- });
29
- export const NFKC = arkModule({
30
- root: normalizeNodes.NFKC,
31
- preformatted: preformattedNodes.NFKC
32
- });
33
- export const NFKD = arkModule({
34
- root: normalizeNodes.NFKD,
35
- preformatted: preformattedNodes.NFKD
36
- });
37
- export const normalize = arkModule({
38
- root: "NFC",
39
- NFC,
40
- NFD,
41
- NFKC,
42
- NFKD
43
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type numeric = constrain<string, Branded<"numeric">>;
5
- }
6
- export declare const numeric: stringNumeric.module;
7
- export declare namespace stringNumeric {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- root: string.numeric;
12
- parse: (In: string.numeric) => To<number>;
13
- };
14
- }
15
- export {};
@@ -1,13 +0,0 @@
1
- import { intrinsic, rootSchema } from "@ark/schema";
2
- import { wellFormedNumberMatcher } from "@ark/util";
3
- import { arkModule } from "../utils.js";
4
- import { regexStringNode } from "./utils.js";
5
- const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
- export const numeric = arkModule({
7
- root,
8
- parse: rootSchema({
9
- in: root,
10
- morphs: (s) => Number.parseFloat(s),
11
- declaredOut: intrinsic.number
12
- })
13
- });
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../ast.ts";
2
- declare namespace string {
3
- type semver = constrain<string, Branded<"semver">>;
4
- }
5
- export declare const semver: import("@ark/schema").IntersectionNode;
6
- export type semver = string.semver;
7
- export {};
@@ -1,4 +0,0 @@
1
- import { regexStringNode } from "./utils.js";
2
- // https://semver.org/
3
- const semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
4
- export const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
@@ -1,108 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
3
- import { alpha } from "./alpha.ts";
4
- import { alphanumeric } from "./alphanumeric.ts";
5
- import { capitalize } from "./capitalize.ts";
6
- import { creditCard } from "./creditCard.ts";
7
- import { stringDate } from "./date.ts";
8
- import { digits } from "./digits.ts";
9
- import { email } from "./email.ts";
10
- import { type stringInteger } from "./integer.ts";
11
- import { ip } from "./ip.ts";
12
- import { type stringJson } from "./json.ts";
13
- import { lower } from "./lower.ts";
14
- import { normalize } from "./normalize.ts";
15
- import { type stringNumeric } from "./numeric.ts";
16
- import { semver } from "./semver.ts";
17
- import { trim } from "./trim.ts";
18
- import { upper } from "./upper.ts";
19
- import { url } from "./url.ts";
20
- import { uuid } from "./uuid.ts";
21
- export declare const string: Module<{
22
- trim: Submodule<trim.submodule>;
23
- normalize: Submodule<{
24
- root: unknown;
25
- NFC: Submodule<{
26
- root: unknown;
27
- preformatted: unknown;
28
- }>;
29
- NFD: Submodule<{
30
- root: unknown;
31
- preformatted: unknown;
32
- }>;
33
- NFKC: Submodule<{
34
- root: unknown;
35
- preformatted: unknown;
36
- }>;
37
- NFKD: Submodule<{
38
- root: unknown;
39
- preformatted: unknown;
40
- }>;
41
- }>;
42
- root: unknown;
43
- date: Submodule<stringDate.submodule>;
44
- lower: Submodule<lower.submodule>;
45
- upper: Submodule<upper.submodule>;
46
- integer: Submodule<stringInteger.submodule>;
47
- json: Submodule<stringJson.submodule>;
48
- alpha: unknown;
49
- alphanumeric: unknown;
50
- creditCard: unknown;
51
- digits: unknown;
52
- email: unknown;
53
- ip: Submodule<ip.submodule>;
54
- numeric: Submodule<stringNumeric.submodule>;
55
- semver: unknown;
56
- url: Submodule<url.submodule>;
57
- uuid: Submodule<{
58
- root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
59
- v4: unknown;
60
- v6: unknown;
61
- v1: unknown;
62
- v2: unknown;
63
- v3: unknown;
64
- v5: unknown;
65
- v7: unknown;
66
- v8: unknown;
67
- }>;
68
- capitalize: Submodule<capitalize.submodule>;
69
- }>;
70
- export type Matching<rule> = {
71
- matching: constraint<rule>;
72
- };
73
- export declare namespace string {
74
- type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
75
- type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
76
- type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
77
- type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
78
- type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
79
- type matching<rule> = constrain<string, Matching<rule>>;
80
- type narrowed = constrain<string, Narrowed>;
81
- type optional = constrain<string, Optional>;
82
- type branded<rule> = constrain<string, Branded<rule>>;
83
- type is<constraints extends Constraints> = constrain<string, constraints>;
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;
85
- type module = Module<string.submodule>;
86
- type submodule = Submodule<$>;
87
- type $ = {
88
- root: string;
89
- alpha: alpha;
90
- alphanumeric: alphanumeric;
91
- digits: digits;
92
- numeric: stringNumeric.submodule;
93
- integer: stringInteger.submodule;
94
- creditCard: creditCard;
95
- email: email;
96
- uuid: uuid.submodule;
97
- semver: semver;
98
- ip: ip.submodule;
99
- json: stringJson.submodule;
100
- date: stringDate.submodule;
101
- url: url.submodule;
102
- trim: trim.submodule;
103
- normalize: normalize.submodule;
104
- capitalize: capitalize.submodule;
105
- lower: lower.submodule;
106
- upper: upper.submodule;
107
- };
108
- }
@@ -1,41 +0,0 @@
1
- import { intrinsic } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- import { alpha } from "./alpha.js";
4
- import { alphanumeric } from "./alphanumeric.js";
5
- import { capitalize } from "./capitalize.js";
6
- import { creditCard } from "./creditCard.js";
7
- import { stringDate } from "./date.js";
8
- import { digits } from "./digits.js";
9
- import { email } from "./email.js";
10
- import { integer } from "./integer.js";
11
- import { ip } from "./ip.js";
12
- import { json } from "./json.js";
13
- import { lower } from "./lower.js";
14
- import { normalize } from "./normalize.js";
15
- import { numeric } from "./numeric.js";
16
- import { semver } from "./semver.js";
17
- import { trim } from "./trim.js";
18
- import { upper } from "./upper.js";
19
- import { url } from "./url.js";
20
- import { uuid } from "./uuid.js";
21
- export const string = arkModule({
22
- root: intrinsic.string,
23
- numeric,
24
- integer,
25
- alpha,
26
- alphanumeric,
27
- digits,
28
- semver,
29
- ip,
30
- creditCard,
31
- email,
32
- uuid,
33
- url,
34
- json,
35
- trim,
36
- upper,
37
- lower,
38
- normalize,
39
- capitalize,
40
- date: stringDate
41
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type trimmed = constrain<string, Branded<"trimmed">>;
5
- }
6
- export declare const trim: trim.module;
7
- export declare namespace trim {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- root: (In: string) => To<string.trimmed>;
12
- preformatted: string.trimmed;
13
- };
14
- }
15
- export {};
@@ -1,14 +0,0 @@
1
- import { rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- import { regexStringNode } from "./utils.js";
4
- const preformatted = regexStringNode(
5
- // no leading or trailing whitespace
6
- /^\S.*\S$|^\S?$/, "trimmed");
7
- export const trim = arkModule({
8
- root: rootSchema({
9
- in: "string",
10
- morphs: (s) => s.trim(),
11
- declaredOut: preformatted
12
- }),
13
- preformatted
14
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type uppercase = constrain<string, Branded<"uppercase">>;
5
- }
6
- export declare const upper: upper.module;
7
- export declare namespace upper {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- root: (In: string) => To<string.uppercase>;
12
- preformatted: string.uppercase;
13
- };
14
- }
15
- export {};
@@ -1,12 +0,0 @@
1
- import { rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- import { regexStringNode } from "./utils.js";
4
- const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
5
- export const upper = arkModule({
6
- root: rootSchema({
7
- in: "string",
8
- morphs: (s) => s.toUpperCase(),
9
- declaredOut: preformatted
10
- }),
11
- preformatted
12
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type url = constrain<string, Branded<"url">>;
5
- }
6
- export declare const url: url.module;
7
- export declare namespace url {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- root: string.url;
12
- parse: (In: string.url) => To<URL>;
13
- };
14
- }
15
- export {};
@@ -1,37 +0,0 @@
1
- import { rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- const isParsableUrl = (s) => {
4
- if (URL.canParse)
5
- return URL.canParse(s);
6
- // Can be removed once Node 18 is EOL
7
- try {
8
- new URL(s);
9
- return true;
10
- }
11
- catch {
12
- return false;
13
- }
14
- };
15
- const root = rootSchema({
16
- domain: "string",
17
- predicate: {
18
- meta: "a URL string",
19
- predicate: isParsableUrl
20
- }
21
- });
22
- export const url = arkModule({
23
- root,
24
- parse: rootSchema({
25
- declaredIn: root,
26
- in: "string",
27
- morphs: (s, ctx) => {
28
- try {
29
- return new URL(s);
30
- }
31
- catch {
32
- return ctx.error("a URL string");
33
- }
34
- },
35
- declaredOut: rootSchema(URL)
36
- })
37
- });
@@ -1,2 +0,0 @@
1
- import { type IntersectionNode } from "@ark/schema";
2
- export declare const regexStringNode: (regex: RegExp, description: string) => IntersectionNode;
@@ -1,10 +0,0 @@
1
- import { node } from "@ark/schema";
2
- // Non-trivial expressions should have an explanation or attribution
3
- export const regexStringNode = (regex, description) => node("intersection", {
4
- domain: "string",
5
- pattern: {
6
- rule: regex.source,
7
- flags: regex.flags,
8
- meta: description
9
- }
10
- });
@@ -1,42 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../ast.ts";
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: unknown;
6
- v6: unknown;
7
- v1: unknown;
8
- v2: unknown;
9
- v3: unknown;
10
- v5: unknown;
11
- v7: unknown;
12
- v8: unknown;
13
- }>;
14
- declare namespace string {
15
- type uuid = constrain<string, Branded<"uuid">>;
16
- namespace uuid {
17
- type v1 = constrain<string, Branded<"uuid.v1">>;
18
- type v2 = constrain<string, Branded<"uuid.v2">>;
19
- type v3 = constrain<string, Branded<"uuid.v3">>;
20
- type v4 = constrain<string, Branded<"uuid.v4">>;
21
- type v5 = constrain<string, Branded<"uuid.v5">>;
22
- type v6 = constrain<string, Branded<"uuid.v6">>;
23
- type v7 = constrain<string, Branded<"uuid.v7">>;
24
- type v8 = constrain<string, Branded<"uuid.v8">>;
25
- }
26
- }
27
- export declare namespace uuid {
28
- type module = Module<submodule>;
29
- type submodule = Submodule<$>;
30
- type $ = {
31
- root: string.uuid;
32
- v1: string.uuid.v1;
33
- v2: string.uuid.v2;
34
- v3: string.uuid.v3;
35
- v4: string.uuid.v4;
36
- v5: string.uuid.v5;
37
- v6: string.uuid.v6;
38
- v7: string.uuid.v7;
39
- v8: string.uuid.v8;
40
- };
41
- }
42
- export {};
@@ -1,19 +0,0 @@
1
- import { arkModule } from "../utils.js";
2
- import { regexStringNode } from "./utils.js";
3
- // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
4
- export const uuid = arkModule({
5
- // the meta tuple expression ensures the error message does not delegate
6
- // to the individual branches, which are too detailed
7
- root: ["versioned | nil | max", "@", "a UUID"],
8
- "#nil": "'00000000-0000-0000-0000-000000000000'",
9
- "#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
10
- "#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
11
- v1: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv1"),
12
- v2: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-2[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv2"),
13
- v3: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv3"),
14
- v4: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv4"),
15
- v5: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv5"),
16
- v6: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv6"),
17
- v7: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv7"),
18
- v8: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv8")
19
- });
@@ -1 +0,0 @@
1
- export declare const arkModule: import("../scope.ts").ModuleParser;
@@ -1,2 +0,0 @@
1
- import { module } from "../scope.js";
2
- export const arkModule = module;
@@ -1,11 +0,0 @@
1
- import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
3
- import type { BaseType } from "./base.ts";
4
- import type { instantiateType } from "./instantiate.ts";
5
- /** @ts-ignore cast variance */
6
- interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
7
- narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<[
8
- narrowed
9
- ] extends [never] ? applyConstraintSchema<t, "predicate", Predicate> : narrowed, $>;
10
- }
11
- export type { Type as ValidatorType };
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- import type { GenericAst } from "@ark/schema";
2
- import type { Hkt, array } from "@ark/util";
3
- import type { inferIntersection } from "../../intersect.ts";
4
- import type { arkKeyOf } from "../../keys.ts";
5
- import type { type } from "../../keywords/ark.ts";
6
- import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, normalizeLimit } from "../../keywords/ast.ts";
7
- import type { Date } from "../../keywords/constructors/Date.ts";
8
- import type { UnparsedScope } from "../../scope.ts";
9
- import type { inferDefinition } from "../definition.ts";
10
- import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
11
- export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
12
- export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
13
- export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
14
- export type DefAst<def = unknown, alias extends string = string> = [
15
- def,
16
- "def",
17
- alias
18
- ];
19
- export type InferredAst<t = unknown, def extends string = string> = [
20
- t,
21
- "inferred",
22
- def
23
- ];
24
- export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
25
- type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
26
- export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
27
- [i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
28
- }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
29
- [i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
30
- }> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
31
- export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
32
- rule: normalizeLimit<limit>;
33
- exclusive: comparator extends ">" | "<" ? true : false;
34
- }> : never;
35
- export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
36
- export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
37
- export type PostfixOperator = "[]" | "?";
38
- export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
39
- export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
40
- export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
41
- export {};
@@ -1,26 +0,0 @@
1
- import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
- import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
- import type { Generic } from "../../generic.ts";
4
- import type { Comparator } from "../string/reduce/shared.ts";
5
- import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.ts";
6
- import type { UnitLiteral } from "../string/shift/operator/default.ts";
7
- import type { parseString } from "../string/string.ts";
8
- import type { validateRange } from "./bounds.ts";
9
- import type { validateDefault } from "./default.ts";
10
- import type { validateDivisor } from "./divisor.ts";
11
- import type { DefAst, GenericInstantiationAst, inferAstRoot, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
12
- import type { validateKeyof } from "./keyof.ts";
13
- import type { astToString } from "./utils.ts";
14
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
- ast: ast;
16
- };
17
- type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
18
- type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
19
- export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
20
- export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
21
- type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
22
- [arkKind]: "module";
23
- } ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
24
- export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
25
- type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends infer e extends ErrorMessage ? e : validateAst<ast[2], $, args> extends infer e extends ErrorMessage ? e : undefined;
26
- export {};
@@ -1 +0,0 @@
1
- export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
@@ -1,9 +0,0 @@
1
- import { type WhiteSpaceToken } from "@ark/util";
2
- import type { DynamicState } from "../../reduce/dynamic.ts";
3
- import type { StaticState, state } from "../../reduce/static.ts";
4
- import type { BaseCompletions } from "../../string.ts";
5
- import type { Scanner } from "../scanner.ts";
6
- import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
7
- import { parseUnenclosed } from "./unenclosed.ts";
8
- export declare const parseOperand: (s: DynamicState) => void;
9
- export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
@@ -1,13 +0,0 @@
1
- import { type WhiteSpaceToken } from "@ark/util";
2
- import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
- import type { StaticState, state } from "../../reduce/static.ts";
4
- import { Scanner } from "../scanner.ts";
5
- import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
- import { parseDivisor } from "./divisor.ts";
7
- export declare const parseOperator: (s: DynamicStateWithRoot) => void;
8
- export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
- export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
10
- export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
11
- export declare const incompleteArrayTokenMessage = "Missing expected ']'";
12
- type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
13
- export {};
@@ -1,71 +0,0 @@
1
- import { type Dict, type EscapeToken, type WhiteSpaceToken } from "@ark/util";
2
- import type { Comparator } from "../reduce/shared.ts";
3
- export declare class Scanner<lookahead extends string = string> {
4
- private chars;
5
- private i;
6
- constructor(def: string);
7
- /** Get lookahead and advance scanner by one */
8
- shift(): lookahead;
9
- get lookahead(): lookahead;
10
- get nextLookahead(): string;
11
- get length(): number;
12
- shiftUntil(condition: Scanner.UntilCondition): string;
13
- shiftUntilNextTerminator(): string;
14
- shiftUntilNonWhitespace(): string;
15
- jumpToIndex(i: number): void;
16
- jumpForward(count: number): void;
17
- get location(): number;
18
- get unscanned(): string;
19
- get scanned(): string;
20
- sliceChars(start: number, end?: number): string;
21
- lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
22
- lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
23
- static terminatingChars: {
24
- readonly " ": true;
25
- readonly "\n": true;
26
- readonly "\t": true;
27
- readonly "<": true;
28
- readonly ">": true;
29
- readonly "=": true;
30
- readonly "|": true;
31
- readonly "&": true;
32
- readonly ")": true;
33
- readonly "[": true;
34
- readonly "%": true;
35
- readonly ",": true;
36
- readonly ":": true;
37
- readonly "?": true;
38
- };
39
- static finalizingLookaheads: {
40
- readonly ">": true;
41
- readonly ",": true;
42
- readonly "": true;
43
- readonly "=": true;
44
- readonly "?": true;
45
- };
46
- static lookaheadIsTerminator: Scanner.UntilCondition;
47
- static lookaheadIsNotWhitespace: Scanner.UntilCondition;
48
- static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
49
- }
50
- export declare namespace Scanner {
51
- type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
52
- type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
53
- type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
54
- type ShiftUntilOptions = {
55
- onInputEnd?: OnInputEndFn;
56
- };
57
- type TerminatingChar = keyof typeof Scanner.terminatingChars;
58
- type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
59
- type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
60
- type PostfixToken = "[]";
61
- type OperatorToken = InfixToken | PostfixToken;
62
- type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
63
- type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
64
- type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
65
- type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<unscanned, TerminatingChar>;
66
- type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned, WhiteSpaceToken>[1];
67
- type shiftResult<scanned extends string, unscanned extends string> = [
68
- scanned,
69
- unscanned
70
- ];
71
- }