arktype 2.0.0-rc.2 → 2.0.0-rc.21

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 (151) hide show
  1. package/out/attributes.d.ts +274 -0
  2. package/out/attributes.js +2 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +45 -48
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +4 -4
  7. package/out/index.js +2 -2
  8. package/out/keywords/builtins.js +2 -2
  9. package/out/keywords/constructors/Array.d.ts +2 -2
  10. package/out/keywords/constructors/Array.js +7 -7
  11. package/out/keywords/constructors/Date.d.ts +37 -0
  12. package/out/keywords/constructors/FormData.d.ts +2 -2
  13. package/out/keywords/constructors/FormData.js +8 -8
  14. package/out/keywords/constructors/TypedArray.js +2 -2
  15. package/out/keywords/constructors/constructors.d.ts +0 -1
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/keywords.d.ts +64 -0
  18. package/out/keywords/{ark.js → keywords.js} +14 -9
  19. package/out/keywords/number/epoch.d.ts +1 -1
  20. package/out/keywords/number/epoch.js +2 -2
  21. package/out/keywords/number/integer.js +2 -2
  22. package/out/keywords/number/number.d.ts +44 -14
  23. package/out/keywords/number/number.js +17 -5
  24. package/out/keywords/string/alpha.d.ts +2 -2
  25. package/out/keywords/string/alphanumeric.d.ts +2 -2
  26. package/out/keywords/string/base64.d.ts +21 -0
  27. package/out/keywords/string/base64.js +6 -0
  28. package/out/keywords/string/capitalize.d.ts +3 -3
  29. package/out/keywords/string/capitalize.js +4 -4
  30. package/out/keywords/string/creditCard.d.ts +2 -2
  31. package/out/keywords/string/creditCard.js +2 -2
  32. package/out/keywords/string/date.d.ts +7 -11
  33. package/out/keywords/string/date.js +16 -16
  34. package/out/keywords/string/digits.d.ts +2 -2
  35. package/out/keywords/string/email.d.ts +2 -2
  36. package/out/keywords/string/integer.d.ts +3 -3
  37. package/out/keywords/string/integer.js +7 -7
  38. package/out/keywords/string/ip.d.ts +5 -5
  39. package/out/keywords/string/ip.js +5 -5
  40. package/out/keywords/string/json.d.ts +4 -3
  41. package/out/keywords/string/json.js +39 -30
  42. package/out/keywords/string/lower.d.ts +3 -3
  43. package/out/keywords/string/lower.js +4 -4
  44. package/out/keywords/string/normalize.d.ts +27 -31
  45. package/out/keywords/string/normalize.js +14 -14
  46. package/out/keywords/string/numeric.d.ts +3 -3
  47. package/out/keywords/string/numeric.js +7 -7
  48. package/out/keywords/string/semver.d.ts +2 -2
  49. package/out/keywords/string/string.d.ts +74 -51
  50. package/out/keywords/string/string.js +5 -3
  51. package/out/keywords/string/trim.d.ts +3 -3
  52. package/out/keywords/string/trim.js +4 -4
  53. package/out/keywords/string/upper.d.ts +3 -3
  54. package/out/keywords/string/upper.js +4 -4
  55. package/out/keywords/string/url.d.ts +3 -3
  56. package/out/keywords/string/url.js +8 -8
  57. package/out/keywords/string/uuid.d.ts +20 -20
  58. package/out/keywords/string/uuid.js +3 -3
  59. package/out/keywords/ts.d.ts +38 -1
  60. package/out/keywords/ts.js +20 -4
  61. package/out/keywords/utils.d.ts +1 -1
  62. package/out/keywords/utils.js +1 -1
  63. package/out/{subtypes → methods}/array.d.ts +6 -6
  64. package/out/methods/base.d.ts +183 -0
  65. package/out/{subtypes → methods}/date.d.ts +5 -5
  66. package/out/methods/instantiate.d.ts +17 -0
  67. package/out/methods/morph.d.ts +12 -0
  68. package/out/methods/number.d.ts +12 -0
  69. package/out/methods/object.d.ts +106 -0
  70. package/out/methods/string.d.ts +13 -0
  71. package/out/module.d.ts +2 -2
  72. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  73. package/out/parser/ast/default.d.ts +8 -0
  74. package/out/parser/ast/infer.d.ts +39 -0
  75. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  76. package/out/parser/{semantic → ast}/validate.d.ts +10 -10
  77. package/out/parser/ast/validate.js +1 -0
  78. package/out/parser/definition.d.ts +8 -9
  79. package/out/parser/objectLiteral.d.ts +11 -37
  80. package/out/parser/objectLiteral.js +6 -24
  81. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
  82. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  83. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  84. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  85. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  86. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -3
  87. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  88. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
  89. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  90. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  91. package/out/parser/shift/operator/brand.d.ts +6 -0
  92. package/out/parser/shift/operator/brand.js +5 -0
  93. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  94. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  95. package/out/parser/{string/shift → shift}/operator/operator.d.ts +2 -1
  96. package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
  97. package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
  98. package/out/parser/{string/shift → shift}/scanner.js +6 -3
  99. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  100. package/out/parser/{string/string.js → string.js} +2 -0
  101. package/out/parser/tuple.d.ts +56 -44
  102. package/out/parser/tuple.js +36 -30
  103. package/out/scope.d.ts +38 -39
  104. package/out/scope.js +47 -36
  105. package/out/type.d.ts +45 -21
  106. package/out/type.js +14 -10
  107. package/package.json +3 -3
  108. package/out/intersect.d.ts +0 -28
  109. package/out/keys.d.ts +0 -16
  110. package/out/keywords/ark.d.ts +0 -39
  111. package/out/keywords/ast.d.ts +0 -193
  112. package/out/keywords/ast.js +0 -2
  113. package/out/parser/semantic/default.d.ts +0 -9
  114. package/out/parser/semantic/default.js +0 -1
  115. package/out/parser/semantic/infer.d.ts +0 -39
  116. package/out/parser/semantic/validate.js +0 -1
  117. package/out/subtypes/base.d.ts +0 -85
  118. package/out/subtypes/instantiate.d.ts +0 -16
  119. package/out/subtypes/morph.d.ts +0 -13
  120. package/out/subtypes/number.d.ts +0 -12
  121. package/out/subtypes/object.d.ts +0 -33
  122. package/out/subtypes/string.d.ts +0 -13
  123. package/out/subtypes/validator.d.ts +0 -11
  124. package/out/subtypes/validator.js +0 -1
  125. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  126. /package/out/{subtypes → methods}/array.js +0 -0
  127. /package/out/{subtypes → methods}/base.js +0 -0
  128. /package/out/{subtypes → methods}/date.js +0 -0
  129. /package/out/{subtypes → methods}/instantiate.js +0 -0
  130. /package/out/{subtypes → methods}/morph.js +0 -0
  131. /package/out/{subtypes → methods}/number.js +0 -0
  132. /package/out/{subtypes → methods}/object.js +0 -0
  133. /package/out/{subtypes → methods}/string.js +0 -0
  134. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  135. /package/out/{keys.js → parser/ast/default.js} +0 -0
  136. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  137. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  138. /package/out/parser/{semantic → ast}/infer.js +0 -0
  139. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  140. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  141. /package/out/parser/{semantic → ast}/utils.js +0 -0
  142. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  143. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  144. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  145. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  146. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  147. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  148. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  149. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  150. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  151. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,39 +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 { Date, Default, LimitLiteral, applyConstraint, distillIn, distillOut, normalizeLimit } from "../../keywords/ast.ts";
5
- import type { UnparsedScope } from "../../scope.ts";
6
- import type { inferAmbient } from "../../type.ts";
7
- import type { inferDefinition } from "../definition.ts";
8
- import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
9
- export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
10
- export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
11
- export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
12
- export type DefAst<def = unknown, alias extends string = string> = [
13
- def,
14
- "def",
15
- alias
16
- ];
17
- export type InferredAst<t = unknown, def extends string = string> = [
18
- t,
19
- "inferred",
20
- def
21
- ];
22
- export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
23
- type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
24
- 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"], {
25
- [i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
26
- }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
27
- [i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
28
- }> : 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 "=" ? inferAmbient<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraint<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferExpression<ast[1], $, args> : never : never;
29
- export type constrainBound<constrainableIn, comparator extends Comparator, limit extends LimitLiteral> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraint<constrainableIn, "exactLength", limit & number> : applyConstraint<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
30
- rule: normalizeLimit<limit>;
31
- exclusive: comparator extends ">" | "<" ? true : false;
32
- }> : never;
33
- export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
34
- export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
35
- export type PostfixOperator = "[]";
36
- export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
37
- export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
38
- export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
39
- export {};
@@ -1 +0,0 @@
1
- export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
@@ -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,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