arktype 2.0.0-rc.3 → 2.0.0-rc.31

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 (176) 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 +55 -58
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +6 -4
  7. package/out/index.js +4 -3
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
  9. package/out/keywords/{constructors/Array.js → Array.js} +7 -7
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
  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 -2
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/keywords.d.ts +61 -0
  18. package/out/keywords/keywords.js +29 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +24 -2
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +42 -4
  24. package/out/keywords/ts.js +24 -7
  25. package/out/methods/array.d.ts +12 -0
  26. package/out/methods/base.d.ts +178 -0
  27. package/out/methods/date.d.ts +10 -0
  28. package/out/methods/instantiate.d.ts +17 -0
  29. package/out/methods/morph.d.ts +12 -0
  30. package/out/methods/number.d.ts +11 -0
  31. package/out/methods/object.d.ts +106 -0
  32. package/out/methods/string.d.ts +12 -0
  33. package/out/module.d.ts +2 -2
  34. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  35. package/out/parser/ast/default.d.ts +8 -0
  36. package/out/parser/ast/generic.d.ts +17 -0
  37. package/out/parser/ast/infer.d.ts +25 -0
  38. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  39. package/out/parser/ast/validate.d.ts +30 -0
  40. package/out/parser/ast/validate.js +3 -0
  41. package/out/parser/definition.d.ts +21 -13
  42. package/out/parser/definition.js +20 -2
  43. package/out/parser/objectLiteral.d.ts +41 -67
  44. package/out/parser/objectLiteral.js +84 -71
  45. package/out/parser/property.d.ts +36 -0
  46. package/out/parser/property.js +16 -0
  47. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
  48. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  49. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  50. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  51. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  52. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
  53. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  54. package/out/parser/shift/operand/operand.d.ts +9 -0
  55. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  57. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  58. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  59. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  60. package/out/parser/shift/operator/brand.d.ts +6 -0
  61. package/out/parser/shift/operator/brand.js +5 -0
  62. package/out/parser/{string/shift → shift}/operator/default.d.ts +4 -6
  63. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  64. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  65. package/out/parser/shift/operator/operator.d.ts +14 -0
  66. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  67. package/out/parser/shift/scanner.d.ts +47 -0
  68. package/out/parser/shift/scanner.js +43 -0
  69. package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
  70. package/out/parser/{string/string.js → string.js} +19 -0
  71. package/out/parser/tupleExpressions.d.ts +47 -0
  72. package/out/parser/tupleExpressions.js +67 -0
  73. package/out/parser/tupleLiteral.d.ts +95 -0
  74. package/out/parser/tupleLiteral.js +122 -0
  75. package/out/scope.d.ts +41 -34
  76. package/out/scope.js +54 -62
  77. package/out/type.d.ts +46 -22
  78. package/out/type.js +15 -11
  79. package/package.json +3 -3
  80. package/out/intersect.d.ts +0 -28
  81. package/out/keys.d.ts +0 -16
  82. package/out/keywords/ark.d.ts +0 -39
  83. package/out/keywords/ark.js +0 -24
  84. package/out/keywords/ast.d.ts +0 -193
  85. package/out/keywords/ast.js +0 -2
  86. package/out/keywords/number/epoch.d.ts +0 -10
  87. package/out/keywords/number/integer.d.ts +0 -3
  88. package/out/keywords/number/integer.js +0 -5
  89. package/out/keywords/number/number.d.ts +0 -28
  90. package/out/keywords/number/number.js +0 -9
  91. package/out/keywords/string/alpha.d.ts +0 -7
  92. package/out/keywords/string/alpha.js +0 -2
  93. package/out/keywords/string/alphanumeric.d.ts +0 -7
  94. package/out/keywords/string/alphanumeric.js +0 -2
  95. package/out/keywords/string/capitalize.d.ts +0 -15
  96. package/out/keywords/string/capitalize.js +0 -12
  97. package/out/keywords/string/creditCard.d.ts +0 -8
  98. package/out/keywords/string/creditCard.js +0 -37
  99. package/out/keywords/string/date.d.ts +0 -59
  100. package/out/keywords/string/date.js +0 -98
  101. package/out/keywords/string/digits.d.ts +0 -7
  102. package/out/keywords/string/digits.js +0 -2
  103. package/out/keywords/string/email.d.ts +0 -7
  104. package/out/keywords/string/email.js +0 -4
  105. package/out/keywords/string/integer.d.ts +0 -16
  106. package/out/keywords/string/integer.js +0 -16
  107. package/out/keywords/string/ip.d.ts +0 -20
  108. package/out/keywords/string/ip.js +0 -23
  109. package/out/keywords/string/json.d.ts +0 -15
  110. package/out/keywords/string/json.js +0 -45
  111. package/out/keywords/string/lower.d.ts +0 -15
  112. package/out/keywords/string/lower.js +0 -12
  113. package/out/keywords/string/normalize.d.ts +0 -92
  114. package/out/keywords/string/normalize.js +0 -43
  115. package/out/keywords/string/numeric.d.ts +0 -15
  116. package/out/keywords/string/numeric.js +0 -13
  117. package/out/keywords/string/semver.d.ts +0 -7
  118. package/out/keywords/string/semver.js +0 -4
  119. package/out/keywords/string/string.d.ts +0 -112
  120. package/out/keywords/string/string.js +0 -41
  121. package/out/keywords/string/trim.d.ts +0 -15
  122. package/out/keywords/string/trim.js +0 -14
  123. package/out/keywords/string/upper.d.ts +0 -15
  124. package/out/keywords/string/upper.js +0 -12
  125. package/out/keywords/string/url.d.ts +0 -15
  126. package/out/keywords/string/url.js +0 -37
  127. package/out/keywords/string/utils.d.ts +0 -2
  128. package/out/keywords/string/utils.js +0 -10
  129. package/out/keywords/string/uuid.d.ts +0 -42
  130. package/out/keywords/string/uuid.js +0 -19
  131. package/out/keywords/utils.d.ts +0 -1
  132. package/out/keywords/utils.js +0 -2
  133. package/out/parser/semantic/default.d.ts +0 -9
  134. package/out/parser/semantic/default.js +0 -1
  135. package/out/parser/semantic/infer.d.ts +0 -39
  136. package/out/parser/semantic/validate.d.ts +0 -26
  137. package/out/parser/semantic/validate.js +0 -1
  138. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  139. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  140. package/out/parser/string/shift/scanner.d.ts +0 -69
  141. package/out/parser/string/shift/scanner.js +0 -100
  142. package/out/parser/tuple.d.ts +0 -132
  143. package/out/parser/tuple.js +0 -158
  144. package/out/subtypes/array.d.ts +0 -13
  145. package/out/subtypes/base.d.ts +0 -85
  146. package/out/subtypes/date.d.ts +0 -11
  147. package/out/subtypes/instantiate.d.ts +0 -16
  148. package/out/subtypes/morph.d.ts +0 -13
  149. package/out/subtypes/number.d.ts +0 -12
  150. package/out/subtypes/object.d.ts +0 -33
  151. package/out/subtypes/string.d.ts +0 -13
  152. package/out/subtypes/validator.d.ts +0 -11
  153. package/out/subtypes/validator.js +0 -1
  154. /package/out/{subtypes → methods}/array.js +0 -0
  155. /package/out/{subtypes → methods}/base.js +0 -0
  156. /package/out/{subtypes → methods}/date.js +0 -0
  157. /package/out/{subtypes → methods}/instantiate.js +0 -0
  158. /package/out/{subtypes → methods}/morph.js +0 -0
  159. /package/out/{subtypes → methods}/number.js +0 -0
  160. /package/out/{subtypes → methods}/object.js +0 -0
  161. /package/out/{subtypes → methods}/string.js +0 -0
  162. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  163. /package/out/{intersect.js → parser/ast/default.js} +0 -0
  164. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  165. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  166. /package/out/{keys.js → parser/ast/generic.js} +0 -0
  167. /package/out/parser/{semantic → ast}/infer.js +0 -0
  168. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  169. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  170. /package/out/parser/{semantic → ast}/utils.js +0 -0
  171. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  172. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  173. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  174. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  175. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  176. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,158 +0,0 @@
1
- import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
- import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
3
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
4
- export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
5
- export const parseTupleLiteral = (def, ctx) => {
6
- let sequences = [{}];
7
- let i = 0;
8
- while (i < def.length) {
9
- let spread = false;
10
- let optional = false;
11
- if (def[i] === "..." && i < def.length - 1) {
12
- spread = true;
13
- i++;
14
- }
15
- const element = ctx.$.parse(def[i], ctx);
16
- i++;
17
- if (def[i] === "?") {
18
- if (spread)
19
- return throwParseError(spreadOptionalMessage);
20
- optional = true;
21
- i++;
22
- }
23
- if (spread) {
24
- if (!element.extends($ark.intrinsic.Array))
25
- return throwParseError(writeNonArraySpreadMessage(element.expression));
26
- // a spread must be distributed over branches e.g.:
27
- // def: [string, ...(number[] | [true, false])]
28
- // nodes: [string, ...number[]] | [string, true, false]
29
- sequences = sequences.flatMap(base =>
30
- // since appendElement mutates base, we have to shallow-ish clone it for each branch
31
- element.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
32
- }
33
- else {
34
- sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
35
- }
36
- }
37
- return ctx.$.internal.rootNode(sequences.map(sequence => ({
38
- proto: Array,
39
- sequence
40
- })));
41
- };
42
- const appendElement = (base, kind, element) => {
43
- switch (kind) {
44
- case "required":
45
- if (base.optionals)
46
- // e.g. [string?, number]
47
- return throwParseError(requiredPostOptionalMessage);
48
- if (base.variadic) {
49
- // e.g. [...string[], number]
50
- base.postfix = append(base.postfix, element);
51
- }
52
- else {
53
- // e.g. [string, number]
54
- base.prefix = append(base.prefix, element);
55
- }
56
- return base;
57
- case "optional":
58
- if (base.variadic)
59
- // e.g. [...string[], number?]
60
- return throwParseError(optionalPostVariadicMessage);
61
- // e.g. [string, number?]
62
- base.optionals = append(base.optionals, element);
63
- return base;
64
- case "variadic":
65
- // e.g. [...string[], number, ...string[]]
66
- if (base.postfix)
67
- throwParseError(multipleVariadicMesage);
68
- if (base.variadic) {
69
- if (!base.variadic.equals(element)) {
70
- // e.g. [...string[], ...number[]]
71
- throwParseError(multipleVariadicMesage);
72
- }
73
- // e.g. [...string[], ...string[]]
74
- // do nothing, second spread doesn't change the type
75
- }
76
- else {
77
- // e.g. [string, ...number[]]
78
- base.variadic = element.internal;
79
- }
80
- return base;
81
- }
82
- };
83
- const appendSpreadBranch = (base, branch) => {
84
- const spread = branch.firstReferenceOfKind("sequence");
85
- if (!spread) {
86
- // the only array with no sequence reference is unknown[]
87
- return appendElement(base, "variadic", $ark.intrinsic.unknown);
88
- }
89
- spread.prefix.forEach(node => appendElement(base, "required", node));
90
- spread.optionals.forEach(node => appendElement(base, "optional", node));
91
- if (spread.variadic)
92
- appendElement(base, "variadic", spread.variadic);
93
- spread.postfix.forEach(node => appendElement(base, "required", node));
94
- return base;
95
- };
96
- const maybeParseTupleExpression = (def, ctx) => {
97
- const tupleExpressionResult = isIndexZeroExpression(def) ? prefixParsers[def[0]](def, ctx)
98
- : isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx)
99
- : undefined;
100
- return tupleExpressionResult;
101
- };
102
- export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
103
- export const multipleVariadicMesage = "A tuple may have at most one variadic element";
104
- export const requiredPostOptionalMessage = "A required element may not follow an optional element";
105
- export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
106
- export const spreadOptionalMessage = "A spread element cannot be optional";
107
- export const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
108
- const parseBranchTuple = (def, ctx) => {
109
- if (def[2] === undefined)
110
- return throwParseError(writeMissingRightOperandMessage(def[1], ""));
111
- const l = ctx.$.parse(def[0], ctx);
112
- const r = ctx.$.parse(def[2], ctx);
113
- return def[1] === "&" ? l.and(r) : l.or(r);
114
- };
115
- const parseArrayTuple = (def, ctx) => ctx.$.parse(def[0], ctx).array();
116
- const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
117
- export const parseMorphTuple = (def, ctx) => {
118
- if (typeof def[2] !== "function") {
119
- return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
120
- }
121
- // TODO: nested morphs?
122
- return ctx.$.parse(def[0], ctx).pipe(def[2]);
123
- };
124
- export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
125
- export const parseNarrowTuple = (def, ctx) => {
126
- if (typeof def[2] !== "function") {
127
- return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
128
- }
129
- return ctx.$.parse(def[0], ctx).constrain("predicate", def[2]);
130
- };
131
- const parseAttributeTuple = (def, ctx) => ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2]);
132
- const indexOneParsers = {
133
- "|": parseBranchTuple,
134
- "&": parseBranchTuple,
135
- "[]": parseArrayTuple,
136
- ":": parseNarrowTuple,
137
- "=>": parseMorphTuple,
138
- "@": parseAttributeTuple
139
- };
140
- const prefixParsers = {
141
- keyof: parseKeyOfTuple,
142
- instanceof: (def, ctx) => {
143
- if (typeof def[1] !== "function") {
144
- return throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(def[1])));
145
- }
146
- const branches = def
147
- .slice(1)
148
- .map(ctor => typeof ctor === "function" ?
149
- ctx.$.node("proto", { proto: ctor })
150
- : throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))));
151
- return branches.length === 1 ?
152
- branches[0]
153
- : ctx.$.node("union", { branches });
154
- },
155
- "===": (def, ctx) => ctx.$.units(def.slice(1))
156
- };
157
- const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
158
- export const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
@@ -1,13 +0,0 @@
1
- import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
3
- import type { ObjectType } from "./object.ts";
4
- interface Type<
5
- /** @ts-ignore cast variance */
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>, $>;
12
- }
13
- export type { Type as ArrayType };
@@ -1,85 +0,0 @@
1
- import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
2
- import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
3
- import type { inferIntersection } from "../intersect.ts";
4
- import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes } from "../keywords/ast.ts";
5
- import type { Scope } from "../scope.ts";
6
- import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
7
- import type { ArrayType } from "./array.ts";
8
- import type { instantiateType } from "./instantiate.ts";
9
- /** @ts-ignore cast variance */
10
- interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> {
11
- t: t;
12
- tIn: distillConstrainableIn<t>;
13
- tOut: distillConstrainableOut<t>;
14
- tValidatedOut: distillValidatedOut<t>;
15
- infer: distillOut<t>;
16
- inferIn: distillIn<t>;
17
- [inferred]: t;
18
- json: Json;
19
- toJsonSchema(): JsonSchema;
20
- description: string;
21
- expression: string;
22
- internal: BaseRoot;
23
- $: Scope<$>;
24
- assert(data: unknown): this["infer"];
25
- allows(data: unknown): data is this["inferIn"];
26
- traverse(data: unknown): distillOut<t> | ArkErrors;
27
- configure(meta: MetaSchema): this;
28
- describe(description: string): this;
29
- onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
30
- onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
31
- from(literal: this["inferIn"]): this["infer"];
32
- as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
33
- get in(): instantiateType<this["tIn"], $>;
34
- get out(): instantiateType<this["tValidatedOut"], $>;
35
- intersect<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
36
- and<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $>;
37
- or<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<t | r, $>;
38
- array(): ArrayType<t[], $>;
39
- pipe: ChainedPipes<t, $>;
40
- equals<def>(def: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
41
- extract<def>(r: validateTypeRoot<def, $>): instantiateType<Extract<t, inferTypeRoot<def, $>>, $>;
42
- exclude<def>(r: validateTypeRoot<def, $>): instantiateType<Exclude<t, inferTypeRoot<def, $>>, $>;
43
- extends<def>(other: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
44
- overlaps<def>(r: validateTypeRoot<def, $>): boolean;
45
- distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
46
- /** @deprecated */
47
- apply: Function["apply"];
48
- /** @deprecated */
49
- bind: Function["bind"];
50
- /** @deprecated */
51
- call: Function["call"];
52
- /** @deprecated */
53
- caller: Function;
54
- /** @deprecated */
55
- length: number;
56
- /** @deprecated */
57
- name: string;
58
- /** @deprecated */
59
- prototype: Function["prototype"];
60
- /** @deprecated */
61
- arguments: Function["arguments"];
62
- /** @deprecated */
63
- Symbol: never;
64
- }
65
- 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;
73
- }
74
- export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
75
- try: ChainedPipeSignature<t, $>;
76
- }
77
- type validateChainedAsArgs<t> = [
78
- t
79
- ] extends [unset] ? [
80
- t
81
- ] extends [anyOrNever] ? [
82
- ] : [
83
- ErrorMessage<"as requires an explicit type parameter like myType.as<t>()">
84
- ] : [];
85
- export type { Type as BaseType };
@@ -1,11 +0,0 @@
1
- import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
3
- import type { ObjectType } from "./object.ts";
4
- /** @ts-ignore cast variance */
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>>, $>;
10
- }
11
- export type { Type as DateType };
@@ -1,16 +0,0 @@
1
- import type { anyOrNever, array } from "@ark/util";
2
- import type { MorphAst } from "../keywords/ast.ts";
3
- import type { ArrayType } from "./array.ts";
4
- import type { DateType } from "./date.ts";
5
- import type { MorphType } from "./morph.ts";
6
- import type { NumberType } from "./number.ts";
7
- import type { ObjectType } from "./object.ts";
8
- import type { StringType } from "./string.ts";
9
- import type { ValidatorType } from "./validator.ts";
10
- export type instantiateType<t, $> = [
11
- Extract<t, MorphAst>
12
- ] extends [anyOrNever] ? [
13
- t
14
- ] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
15
- t
16
- ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : ValidatorType<t, $> : MorphType<t, $>;
@@ -1,13 +0,0 @@
1
- import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { inferPipe } from "../intersect.ts";
3
- import type { applyConstraint, Out, To } from "../keywords/ast.ts";
4
- import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
5
- import type { BaseType } from "./base.ts";
6
- /** @ts-ignore cast variance */
7
- interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
8
- to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
9
- narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
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, $>;
12
- }
13
- export type { Type as MorphType };
@@ -1,12 +0,0 @@
1
- import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
3
- import type { ValidatorType } from "./validator.ts";
4
- /** @ts-ignore cast variance */
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>>, $>;
11
- }
12
- export type { Type as NumberType };
@@ -1,33 +0,0 @@
1
- import type { array, ErrorType, merge } from "@ark/util";
2
- import type { arkKeyOf, getArkKey, toArkKey } from "../keys.ts";
3
- import type { type } from "../keywords/ark.ts";
4
- import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
5
- import type { ArrayType } from "./array.ts";
6
- import type { instantiateType } from "./instantiate.ts";
7
- import type { ValidatorType } from "./validator.ts";
8
- /** @ts-ignore cast variance */
9
- interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $> {
10
- readonly(): t extends array ? ArrayType<{
11
- readonly [i in keyof t]: t[i];
12
- }, $> : Type<{
13
- readonly [k in keyof t]: t[k];
14
- }, $>;
15
- keyof(): instantiateType<keyof t, $>;
16
- get<k1 extends arkKeyOf<t>, r = instantiateType<getArkKey<t, k1>, $>>(k1: k1 | type.cast<k1>): r;
17
- get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>, r = instantiateType<getArkKey<getArkKey<t, k1>, k2>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): r;
18
- get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>, k3 extends arkKeyOf<getArkKey<getArkKey<t, k1>, k2>>, r = instantiateType<getArkKey<getArkKey<getArkKey<t, k1>, k2>, k3>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r;
19
- pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
20
- [k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
21
- }, $>;
22
- omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
23
- [k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
24
- }, $>;
25
- merge<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
26
- required(): Type<{
27
- [k in keyof t]-?: t[k];
28
- }, $>;
29
- partial(): Type<{
30
- [k in keyof t]?: t[k];
31
- }, $>;
32
- }
33
- export type { Type as ObjectType };
@@ -1,13 +0,0 @@
1
- import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
3
- import type { ValidatorType } from "./validator.ts";
4
- /** @ts-ignore cast variance */
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>, $>;
12
- }
13
- export type { Type as StringType };
@@ -1,11 +0,0 @@
1
- import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraint } 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] ? applyConstraint<t, "predicate", Predicate> : narrowed, $>;
10
- }
11
- export type { Type as ValidatorType };
@@ -1 +0,0 @@
1
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes