arktype 2.2.10 → 3.0.0-beta.1

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 (164) hide show
  1. package/README.md +181 -15
  2. package/out/attributes.d.ts +50 -14
  3. package/out/checkers.d.ts +172 -0
  4. package/out/chunk-2U2AWCI3.js +626 -0
  5. package/out/chunk-4CUA5XIP.js +7 -0
  6. package/out/chunk-5U2ZMDNI.js +1566 -0
  7. package/out/chunk-DLWCO4RV.js +18 -0
  8. package/out/chunk-E3DZXEZK.js +72 -0
  9. package/out/chunk-EVCML554.js +47 -0
  10. package/out/chunk-G45P2CLE.js +63 -0
  11. package/out/chunk-GPNK5353.js +2529 -0
  12. package/out/chunk-MLKGABMK.js +9 -0
  13. package/out/chunk-NRIGTMPM.js +7 -0
  14. package/out/chunk-PRTMQCHS.js +3 -0
  15. package/out/chunk-R5G57XC7.js +7 -0
  16. package/out/chunk-RAZ3TXOE.js +313 -0
  17. package/out/chunk-SWOOCAHN.js +4 -0
  18. package/out/chunk-TAHPKDNM.js +3 -0
  19. package/out/chunk-UETB6YE2.js +14 -0
  20. package/out/chunk-UK5UGFOX.js +254 -0
  21. package/out/chunk-VV6YDN2D.js +6118 -0
  22. package/out/codecs.d.ts +21 -0
  23. package/out/codecs.js +7 -0
  24. package/out/config.d.ts +8 -3
  25. package/out/config.js +2 -3
  26. package/out/declare.d.ts +17 -3
  27. package/out/deferred.d.ts +10 -0
  28. package/out/errors.d.ts +1 -0
  29. package/out/errors.js +2 -0
  30. package/out/fn.d.ts +1 -1
  31. package/out/generic.d.ts +3 -3
  32. package/out/i18n.d.ts +2 -0
  33. package/out/i18n.js +2 -0
  34. package/out/index.d.ts +5 -4
  35. package/out/index.js +8 -9
  36. package/out/internal.d.ts +70 -0
  37. package/out/internal.js +17 -0
  38. package/out/island.d.ts +2 -0
  39. package/out/island.js +6 -0
  40. package/out/islandDependency.d.ts +2 -0
  41. package/out/islandDependency.js +18 -0
  42. package/out/keywords/Array.d.ts +2 -2
  43. package/out/keywords/builtins.d.ts +5 -3
  44. package/out/keywords/constructors.d.ts +9 -1
  45. package/out/keywords/functions.d.ts +254 -0
  46. package/out/keywords/keywords.d.ts +8 -9
  47. package/out/keywords/number.d.ts +2 -8
  48. package/out/keywords/phrases.d.ts +245 -0
  49. package/out/keywords/string.d.ts +14 -113
  50. package/out/keywords/ts.d.ts +35 -33
  51. package/out/keywords/ts.js +4 -82
  52. package/out/locale.d.ts +19 -0
  53. package/out/locales/de.d.ts +2 -0
  54. package/out/locales/de.js +2 -0
  55. package/out/locales/en.d.ts +4 -0
  56. package/out/locales/en.js +5 -0
  57. package/out/match.d.ts +6 -6
  58. package/out/module.d.ts +1 -1
  59. package/out/mutatesInput.js +3 -0
  60. package/out/parser/ast/generic.d.ts +6 -3
  61. package/out/parser/ast/infer.d.ts +1 -1
  62. package/out/parser/ast/validate.d.ts +11 -6
  63. package/out/parser/definition.d.ts +68 -7
  64. package/out/parser/objectLiteral.d.ts +40 -12
  65. package/out/parser/property.d.ts +3 -5
  66. package/out/parser/reduce/dynamic.d.ts +16 -7
  67. package/out/parser/reduce/shared.d.ts +4 -0
  68. package/out/parser/reduce/static.d.ts +13 -13
  69. package/out/parser/shift/operand/date.d.ts +0 -5
  70. package/out/parser/shift/operand/operand.d.ts +2 -1
  71. package/out/parser/shift/operand/unenclosed.d.ts +9 -6
  72. package/out/parser/shift/operand/unresolvable.d.ts +68 -0
  73. package/out/parser/shift/operator/bounds.d.ts +9 -4
  74. package/out/parser/shift/operator/brand.d.ts +2 -2
  75. package/out/parser/shift/operator/default.d.ts +2 -2
  76. package/out/parser/shift/operator/divisor.d.ts +2 -2
  77. package/out/parser/shift/operator/operator.d.ts +1 -1
  78. package/out/parser/shift/tokens.d.ts +9 -2
  79. package/out/parser/string.d.ts +61 -7
  80. package/out/parser/tupleExpressions.d.ts +7 -3
  81. package/out/precompiled.d.ts +1 -0
  82. package/out/precompiled.js +2 -0
  83. package/out/runtime.d.ts +181 -0
  84. package/out/runtime.js +4 -0
  85. package/out/runtimeDevelopment.d.ts +1 -0
  86. package/out/runtimeDevelopment.js +133 -0
  87. package/out/runtimeExports.d.ts +1 -0
  88. package/out/scope.d.ts +40 -11
  89. package/out/standalone/artifact.d.ts +265 -0
  90. package/out/standalone/baking.d.ts +201 -0
  91. package/out/standalone/combinators.d.ts +13 -0
  92. package/out/standalone/compilers.d.ts +23 -0
  93. package/out/standalone/creators.d.ts +41 -0
  94. package/out/standalone/fallbacks.d.ts +48 -0
  95. package/out/standalone/keys.d.ts +31 -0
  96. package/out/standalone/modules.d.ts +26 -0
  97. package/out/standalone/sites.d.ts +52 -0
  98. package/out/standalone/units.d.ts +31 -0
  99. package/out/standalone/values.d.ts +60 -0
  100. package/out/standalone.d.ts +16 -0
  101. package/out/type.d.ts +45 -6
  102. package/out/variants/array.d.ts +1 -1
  103. package/out/variants/base.d.ts +47 -27
  104. package/out/variants/date.d.ts +1 -1
  105. package/out/variants/instantiate.d.ts +4 -2
  106. package/out/variants/number.d.ts +1 -1
  107. package/out/variants/object.d.ts +17 -12
  108. package/out/variants/string.d.ts +1 -1
  109. package/package.json +169 -8
  110. package/skills/arktype/SKILL.md +278 -43
  111. package/skills/arktype/references/migrating.md +1296 -0
  112. package/skills/arktype/references/precompile.md +191 -0
  113. package/out/attributes.js +0 -3
  114. package/out/fn.js +0 -58
  115. package/out/generic.js +0 -37
  116. package/out/keywords/Array.js +0 -21
  117. package/out/keywords/FormData.js +0 -40
  118. package/out/keywords/TypedArray.js +0 -16
  119. package/out/keywords/builtins.js +0 -11
  120. package/out/keywords/constructors.js +0 -16
  121. package/out/keywords/keywords.js +0 -48
  122. package/out/keywords/number.js +0 -49
  123. package/out/keywords/string.js +0 -467
  124. package/out/match.js +0 -95
  125. package/out/module.js +0 -3
  126. package/out/nary.js +0 -1
  127. package/out/parser/ast/bounds.js +0 -1
  128. package/out/parser/ast/default.js +0 -1
  129. package/out/parser/ast/divisor.js +0 -1
  130. package/out/parser/ast/generic.js +0 -1
  131. package/out/parser/ast/infer.js +0 -1
  132. package/out/parser/ast/keyof.js +0 -1
  133. package/out/parser/ast/utils.js +0 -1
  134. package/out/parser/ast/validate.js +0 -3
  135. package/out/parser/definition.js +0 -78
  136. package/out/parser/objectLiteral.js +0 -113
  137. package/out/parser/property.js +0 -16
  138. package/out/parser/reduce/dynamic.js +0 -153
  139. package/out/parser/reduce/shared.js +0 -25
  140. package/out/parser/reduce/static.js +0 -1
  141. package/out/parser/shift/operand/date.js +0 -23
  142. package/out/parser/shift/operand/enclosed.js +0 -82
  143. package/out/parser/shift/operand/genericArgs.js +0 -16
  144. package/out/parser/shift/operand/operand.js +0 -16
  145. package/out/parser/shift/operand/unenclosed.js +0 -59
  146. package/out/parser/shift/operator/bounds.js +0 -91
  147. package/out/parser/shift/operator/brand.js +0 -6
  148. package/out/parser/shift/operator/default.js +0 -29
  149. package/out/parser/shift/operator/divisor.js +0 -13
  150. package/out/parser/shift/operator/operator.js +0 -28
  151. package/out/parser/shift/tokens.js +0 -37
  152. package/out/parser/string.js +0 -42
  153. package/out/parser/tupleExpressions.js +0 -75
  154. package/out/parser/tupleLiteral.js +0 -128
  155. package/out/scope.js +0 -106
  156. package/out/type.js +0 -55
  157. package/out/variants/array.js +0 -1
  158. package/out/variants/base.js +0 -1
  159. package/out/variants/date.js +0 -1
  160. package/out/variants/instantiate.js +0 -1
  161. package/out/variants/number.js +0 -1
  162. package/out/variants/object.js +0 -1
  163. package/out/variants/string.js +0 -1
  164. /package/out/{declare.js → mutatesInput.d.ts} +0 -0
@@ -0,0 +1,18 @@
1
+ import {
2
+ parseDate,
3
+ parseInteger,
4
+ parseIsoDate,
5
+ parseJson,
6
+ parseUrl
7
+ } from "./chunk-UK5UGFOX.js";
8
+
9
+ // out/mutatesInput.js
10
+ import { inputOnlyMorphs } from "@ark/schema/mutatesInput";
11
+ for (const morph of [
12
+ parseDate,
13
+ parseInteger,
14
+ parseIsoDate,
15
+ parseJson,
16
+ parseUrl
17
+ ])
18
+ inputOnlyMorphs.add(morph);
@@ -0,0 +1,72 @@
1
+ import {
2
+ raisedErrorPhrases
3
+ } from "./chunk-UK5UGFOX.js";
4
+
5
+ // out/keywords/phrases.js
6
+ import { en } from "@ark/schema";
7
+ var epoch = "an integer representing a safe Unix timestamp";
8
+ var keywordPhrases = {
9
+ "FormData.parsed": "an object representing parsed form data",
10
+ "number.epoch": {
11
+ noun: epoch,
12
+ expected: function (e) { return e.code === "domain" ? "a number representing a Unix timestamp" : e.code === "divisor" ? "an integer representing a Unix timestamp" : e.code === "min" ? `a Unix timestamp after ${e.rule}` : e.code === "max" ? `a Unix timestamp before ${e.rule}` : epoch }
13
+ },
14
+ "object.json": "a plain object or array",
15
+ "string.alpha": "only letters",
16
+ "string.alphanumeric": "only letters and digits 0-9",
17
+ "string.base58": "base58-encoded",
18
+ "string.base64": "base64-encoded",
19
+ "string.base64.url": "base64url-encoded",
20
+ "string.capitalize.preformatted": "capitalized",
21
+ "string.creditCard": "a credit card number",
22
+ "string.date": "a parsable date",
23
+ "string.date.epoch": "an integer string representing a safe Unix timestamp",
24
+ "string.date.iso": "an ISO 8601 date or date-time",
25
+ "string.date.parse": "a parsable date",
26
+ "string.digits": "only digits 0-9",
27
+ "string.email": "an email address",
28
+ "string.hex": "hex characters only",
29
+ "string.integer": "a well-formed integer string",
30
+ "string.integer.parse": "an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER",
31
+ "string.ip": "an IP address",
32
+ "string.ip.v4": "an IPv4 address",
33
+ "string.ip.v6": "an IPv6 address",
34
+ "string.json": raisedErrorPhrases["string.json"],
35
+ "string.json.parse": raisedErrorPhrases["string.json.parse"],
36
+ "string.lower.preformatted": "lowercase",
37
+ "string.normalize.NFC.preformatted": "NFC-normalized unicode",
38
+ "string.normalize.NFD.preformatted": "NFD-normalized unicode",
39
+ "string.normalize.NFKC.preformatted": "NFKC-normalized unicode",
40
+ "string.normalize.NFKD.preformatted": "NFKD-normalized unicode",
41
+ "string.numeric": "a well-formed numeric string",
42
+ "string.numeric.parse": "finite",
43
+ "string.regex": raisedErrorPhrases["string.regex"],
44
+ "string.semver": "a semantic version (see https://semver.org/)",
45
+ "string.trim.preformatted": "trimmed",
46
+ "string.upper.preformatted": "uppercase",
47
+ "string.url": "a URL string",
48
+ "string.url.parse": "a URL string",
49
+ "string.uuid": "a UUID",
50
+ "string.uuid.v1": "a UUIDv1",
51
+ "string.uuid.v2": "a UUIDv2",
52
+ "string.uuid.v3": "a UUIDv3",
53
+ "string.uuid.v4": "a UUIDv4",
54
+ "string.uuid.v5": "a UUIDv5",
55
+ "string.uuid.v6": "a UUIDv6",
56
+ "string.uuid.v7": "a UUIDv7",
57
+ "string.uuid.v8": "a UUIDv8"
58
+ };
59
+ Object.assign(en.keywordPhrases, keywordPhrases);
60
+ var nounOf = (alias) => {
61
+ const phrase = keywordPhrases[alias];
62
+ return typeof phrase === "string" ? phrase : phrase.noun;
63
+ };
64
+ var keywordMeta = (alias) => ({
65
+ description: nounOf(alias),
66
+ keyword: alias
67
+ });
68
+
69
+ export {
70
+ keywordPhrases,
71
+ keywordMeta
72
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ type
3
+ } from "./chunk-2U2AWCI3.js";
4
+ import {
5
+ capitalizeString,
6
+ keepFormatted,
7
+ lowercaseString,
8
+ normalizationsByForm,
9
+ parseDate,
10
+ parseEpoch,
11
+ parseInteger,
12
+ parseIsoDate,
13
+ parseJson,
14
+ parseNumeric,
15
+ parseUrl,
16
+ stringifyJson,
17
+ trimString,
18
+ uppercaseString,
19
+ writeEpoch,
20
+ writeIsoDate,
21
+ writeUrl
22
+ } from "./chunk-UK5UGFOX.js";
23
+
24
+ // out/codecs.js
25
+ import { inverses } from "@ark/schema/codecs";
26
+ var codec = function (i, o, { decode, encode }) {
27
+ const In = type(i).internal;
28
+ return In.$.node("morph", { morphs: [In, decode], inverse: encode }).pipe(type(o));
29
+ };
30
+ inverses.set(parseDate, writeIsoDate);
31
+ inverses.set(parseIsoDate, writeIsoDate);
32
+ inverses.set(parseEpoch, writeEpoch);
33
+ inverses.set(parseInteger, String);
34
+ inverses.set(parseNumeric, String);
35
+ inverses.set(parseJson, stringifyJson);
36
+ inverses.set(stringifyJson, parseJson);
37
+ inverses.set(parseUrl, writeUrl);
38
+ inverses.set(trimString, keepFormatted);
39
+ inverses.set(lowercaseString, keepFormatted);
40
+ inverses.set(uppercaseString, keepFormatted);
41
+ inverses.set(capitalizeString, keepFormatted);
42
+ for (const { morphs } of Object.values(normalizationsByForm))
43
+ inverses.set(morphs, keepFormatted);
44
+
45
+ export {
46
+ codec
47
+ };
@@ -0,0 +1,63 @@
1
+ // out/fn.js
2
+ import { Callable, functionNameOf, throwParseError } from "@ark/util";
3
+ var InternalFnParser = class extends Callable {
4
+ constructor($) {
5
+ const parse = (...signature) => {
6
+ const returnOperatorIndex = signature.indexOf(":");
7
+ const lastParamIndex = returnOperatorIndex === -1 ? signature.length - 1 : returnOperatorIndex - 1;
8
+ const paramDefs = signature.slice(0, lastParamIndex + 1);
9
+ const paramTuple = $.parse(paramDefs).assertIs("intersection");
10
+ let returnType = $.intrinsic.unknown;
11
+ if (returnOperatorIndex !== -1) {
12
+ if (returnOperatorIndex !== signature.length - 2)
13
+ return throwParseError(badFnReturnTypeMessage);
14
+ returnType = $.parse(signature[returnOperatorIndex + 1]);
15
+ }
16
+ return (impl) => new InternalTypedFn(impl, paramTuple, returnType);
17
+ };
18
+ const attach = {
19
+ $,
20
+ raw: parse
21
+ };
22
+ super(parse, { attach });
23
+ }
24
+ };
25
+ var InternalTypedFn = class extends Callable {
26
+ raw;
27
+ params;
28
+ returns;
29
+ constructor(raw, params, returns) {
30
+ const typedName = `typed ${functionNameOf(raw)}`;
31
+ const typed = {
32
+ // assign to a key with the expected name to force it to be created that way
33
+ [typedName]: (...args) => {
34
+ const validatedArgs = params.assert(args);
35
+ const returned = raw(...validatedArgs);
36
+ return returns.assert(returned);
37
+ }
38
+ }[typedName];
39
+ super(typed);
40
+ this.raw = raw;
41
+ this.params = params;
42
+ this.returns = returns;
43
+ }
44
+ // a standalone validator may lack an expression
45
+ get expression() {
46
+ let argsExpression = this.params.expression;
47
+ if (argsExpression === void 0)
48
+ return argsExpression;
49
+ if (argsExpression[0] === "[" && argsExpression[argsExpression.length - 1] === "]")
50
+ argsExpression = argsExpression.slice(1, -1);
51
+ else if (argsExpression.endsWith("[]"))
52
+ argsExpression = `...${argsExpression}`;
53
+ return `(${argsExpression}) => ${this.returns?.expression ?? "unknown"}`;
54
+ }
55
+ };
56
+ var badFnReturnTypeMessage = `":" must be followed by exactly one return type e.g:
57
+ fn("string", ":", "number")(s => s.length)`;
58
+
59
+ export {
60
+ InternalFnParser,
61
+ InternalTypedFn,
62
+ badFnReturnTypeMessage
63
+ };