arktype 2.0.0-dev.1 → 2.0.0-dev.10

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 (219) hide show
  1. package/__tests__/array.test.ts +270 -151
  2. package/__tests__/badDefinitionType.test.ts +10 -3
  3. package/__tests__/basis.test.ts +6 -2
  4. package/__tests__/bounds.test.ts +282 -352
  5. package/__tests__/cast.test.ts +7 -2
  6. package/__tests__/completions.test.ts +8 -3
  7. package/__tests__/config.test.ts +95 -167
  8. package/__tests__/dateLiteral.test.ts +8 -4
  9. package/__tests__/declared.test.ts +7 -6
  10. package/__tests__/discrimination.test.ts +1 -1
  11. package/__tests__/divisor.test.ts +46 -22
  12. package/__tests__/enclosed.test.ts +39 -25
  13. package/__tests__/examples.test.ts +56 -56
  14. package/__tests__/expressions.test.ts +184 -112
  15. package/__tests__/generic.test.ts +307 -288
  16. package/__tests__/group.test.ts +67 -54
  17. package/__tests__/imports.test.ts +62 -49
  18. package/__tests__/instanceof.test.ts +25 -23
  19. package/__tests__/intersection.test.ts +52 -48
  20. package/__tests__/keyTraversal.test.ts +77 -73
  21. package/__tests__/keyof.test.ts +68 -52
  22. package/__tests__/keywords.test.ts +164 -138
  23. package/__tests__/literal.test.ts +60 -21
  24. package/__tests__/match.bench.ts +31 -0
  25. package/__tests__/match.test.ts +222 -22
  26. package/__tests__/narrow.test.ts +52 -54
  27. package/__tests__/objectLiteral.test.ts +347 -205
  28. package/__tests__/operator.bench.ts +4 -4
  29. package/__tests__/pipe.test.ts +501 -0
  30. package/__tests__/realWorld.test.ts +63 -0
  31. package/__tests__/regex.test.ts +17 -7
  32. package/__tests__/scope.bench.ts +1 -1
  33. package/__tests__/scope.test.ts +257 -23
  34. package/__tests__/serialization.test.ts +19 -0
  35. package/__tests__/string.test.ts +11 -7
  36. package/__tests__/submodule.test.ts +26 -39
  37. package/__tests__/this.test.ts +83 -57
  38. package/__tests__/thunk.test.ts +13 -7
  39. package/__tests__/traverse.test.ts +76 -54
  40. package/__tests__/tsGenerics.test.ts +12 -12
  41. package/__tests__/type.test.ts +36 -0
  42. package/__tests__/typeReference.test.ts +7 -7
  43. package/__tests__/unenclosed.test.ts +116 -100
  44. package/__tests__/union.test.ts +171 -104
  45. package/ark.ts +21 -65
  46. package/generic.ts +69 -0
  47. package/main.ts +6 -18
  48. package/match.ts +195 -93
  49. package/module.ts +15 -0
  50. package/out/ark.d.ts +15 -39
  51. package/out/ark.js +9 -18
  52. package/out/ark.js.map +1 -1
  53. package/out/generic.d.ts +21 -0
  54. package/out/generic.js +24 -0
  55. package/out/generic.js.map +1 -0
  56. package/out/main.d.ts +6 -7
  57. package/out/main.js +4 -3
  58. package/out/main.js.map +1 -1
  59. package/out/match.d.ts +57 -34
  60. package/out/match.js +51 -17
  61. package/out/match.js.map +1 -1
  62. package/out/module.d.ts +10 -0
  63. package/out/module.js +3 -0
  64. package/out/module.js.map +1 -0
  65. package/out/parser/definition.d.ts +11 -13
  66. package/out/parser/definition.js +10 -13
  67. package/out/parser/definition.js.map +1 -1
  68. package/out/parser/generic.d.ts +5 -7
  69. package/out/parser/generic.js +7 -11
  70. package/out/parser/generic.js.map +1 -1
  71. package/out/parser/objectLiteral.d.ts +45 -14
  72. package/out/parser/objectLiteral.js +61 -52
  73. package/out/parser/objectLiteral.js.map +1 -1
  74. package/out/parser/semantic/bounds.d.ts +10 -8
  75. package/out/parser/semantic/bounds.js +0 -1
  76. package/out/parser/semantic/bounds.js.map +1 -1
  77. package/out/parser/semantic/divisor.d.ts +5 -7
  78. package/out/parser/semantic/divisor.js +0 -1
  79. package/out/parser/semantic/infer.d.ts +24 -0
  80. package/out/parser/semantic/infer.js +1 -0
  81. package/out/parser/semantic/infer.js.map +1 -0
  82. package/out/parser/semantic/utils.d.ts +3 -7
  83. package/out/parser/semantic/utils.js +0 -1
  84. package/out/parser/semantic/validate.d.ts +15 -14
  85. package/out/parser/semantic/validate.js +1 -1
  86. package/out/parser/semantic/validate.js.map +1 -1
  87. package/out/parser/string/reduce/dynamic.d.ts +13 -13
  88. package/out/parser/string/reduce/dynamic.js +31 -26
  89. package/out/parser/string/reduce/dynamic.js.map +1 -1
  90. package/out/parser/string/reduce/shared.d.ts +6 -20
  91. package/out/parser/string/reduce/shared.js +0 -1
  92. package/out/parser/string/reduce/shared.js.map +1 -1
  93. package/out/parser/string/reduce/static.d.ts +27 -24
  94. package/out/parser/string/reduce/static.js +0 -1
  95. package/out/parser/string/shift/operand/date.d.ts +3 -3
  96. package/out/parser/string/shift/operand/date.js +4 -7
  97. package/out/parser/string/shift/operand/date.js.map +1 -1
  98. package/out/parser/string/shift/operand/enclosed.d.ts +4 -19
  99. package/out/parser/string/shift/operand/enclosed.js +12 -13
  100. package/out/parser/string/shift/operand/enclosed.js.map +1 -1
  101. package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
  102. package/out/parser/string/shift/operand/genericArgs.js +6 -10
  103. package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
  104. package/out/parser/string/shift/operand/operand.d.ts +3 -4
  105. package/out/parser/string/shift/operand/operand.js +8 -12
  106. package/out/parser/string/shift/operand/operand.js.map +1 -1
  107. package/out/parser/string/shift/operand/unenclosed.d.ts +15 -22
  108. package/out/parser/string/shift/operand/unenclosed.js +24 -36
  109. package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
  110. package/out/parser/string/shift/operator/bounds.d.ts +9 -13
  111. package/out/parser/string/shift/operator/bounds.js +43 -54
  112. package/out/parser/string/shift/operator/bounds.js.map +1 -1
  113. package/out/parser/string/shift/operator/divisor.d.ts +2 -4
  114. package/out/parser/string/shift/operator/divisor.js +1 -3
  115. package/out/parser/string/shift/operator/divisor.js.map +1 -1
  116. package/out/parser/string/shift/operator/operator.d.ts +2 -3
  117. package/out/parser/string/shift/operator/operator.js +12 -19
  118. package/out/parser/string/shift/operator/operator.js.map +1 -1
  119. package/out/parser/string/shift/scanner.d.ts +2 -2
  120. package/out/parser/string/shift/scanner.js +14 -16
  121. package/out/parser/string/shift/scanner.js.map +1 -1
  122. package/out/parser/string/string.d.ts +8 -6
  123. package/out/parser/string/string.js +1 -3
  124. package/out/parser/string/string.js.map +1 -1
  125. package/out/parser/tuple.d.ts +102 -43
  126. package/out/parser/tuple.js +119 -87
  127. package/out/parser/tuple.js.map +1 -1
  128. package/out/scope.d.ts +43 -120
  129. package/out/scope.js +39 -209
  130. package/out/scope.js.map +1 -1
  131. package/out/type.d.ts +43 -64
  132. package/out/type.js +30 -131
  133. package/out/type.js.map +1 -1
  134. package/package.json +7 -3
  135. package/parser/definition.ts +77 -93
  136. package/parser/generic.ts +38 -40
  137. package/parser/objectLiteral.ts +172 -136
  138. package/parser/semantic/bounds.ts +33 -32
  139. package/parser/semantic/divisor.ts +8 -10
  140. package/parser/semantic/infer.ts +141 -0
  141. package/parser/semantic/utils.ts +12 -23
  142. package/parser/semantic/validate.ts +81 -73
  143. package/parser/string/reduce/dynamic.ts +67 -55
  144. package/parser/string/reduce/shared.ts +1 -3
  145. package/parser/string/reduce/static.ts +67 -69
  146. package/parser/string/shift/operand/date.ts +15 -14
  147. package/parser/string/shift/operand/enclosed.ts +30 -25
  148. package/parser/string/shift/operand/genericArgs.ts +46 -45
  149. package/parser/string/shift/operand/operand.ts +32 -38
  150. package/parser/string/shift/operand/unenclosed.ts +107 -158
  151. package/parser/string/shift/operator/bounds.ts +118 -112
  152. package/parser/string/shift/operator/divisor.ts +14 -17
  153. package/parser/string/shift/operator/operator.ts +35 -46
  154. package/parser/string/shift/scanner.ts +51 -50
  155. package/parser/string/string.ts +30 -35
  156. package/parser/tuple.ts +375 -307
  157. package/scope.ts +170 -453
  158. package/type.ts +193 -274
  159. package/__tests__/astUtils.test.ts +0 -17
  160. package/__tests__/cyclic.test.ts +0 -144
  161. package/__tests__/jsdoc.test.ts +0 -64
  162. package/__tests__/morph.test.ts +0 -409
  163. package/__tests__/nodeDefinitions.test.ts +0 -190
  164. package/__tests__/typeMethods.test.ts +0 -69
  165. package/out/ark.d.ts.map +0 -1
  166. package/out/arkConfig.d.ts +0 -2
  167. package/out/arkConfig.d.ts.map +0 -1
  168. package/out/arkConfig.js +0 -10
  169. package/out/arkConfig.js.map +0 -1
  170. package/out/main.d.ts.map +0 -1
  171. package/out/match.d.ts.map +0 -1
  172. package/out/parser/definition.d.ts.map +0 -1
  173. package/out/parser/generic.d.ts.map +0 -1
  174. package/out/parser/objectLiteral.d.ts.map +0 -1
  175. package/out/parser/semantic/bounds.d.ts.map +0 -1
  176. package/out/parser/semantic/divisor.d.ts.map +0 -1
  177. package/out/parser/semantic/intersections.d.ts +0 -14
  178. package/out/parser/semantic/intersections.d.ts.map +0 -1
  179. package/out/parser/semantic/intersections.js +0 -2
  180. package/out/parser/semantic/intersections.js.map +0 -1
  181. package/out/parser/semantic/semantic.d.ts +0 -33
  182. package/out/parser/semantic/semantic.d.ts.map +0 -1
  183. package/out/parser/semantic/semantic.js +0 -2
  184. package/out/parser/semantic/semantic.js.map +0 -1
  185. package/out/parser/semantic/utils.d.ts.map +0 -1
  186. package/out/parser/semantic/validate.d.ts.map +0 -1
  187. package/out/parser/shared.d.ts +0 -54
  188. package/out/parser/shared.d.ts.map +0 -1
  189. package/out/parser/shared.js +0 -47
  190. package/out/parser/shared.js.map +0 -1
  191. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  192. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  193. package/out/parser/string/reduce/static.d.ts.map +0 -1
  194. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  195. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  196. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  197. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  198. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  199. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  200. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  201. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  202. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  203. package/out/parser/string/string.d.ts.map +0 -1
  204. package/out/parser/tuple.d.ts.map +0 -1
  205. package/out/scope.d.ts.map +0 -1
  206. package/out/test.d.ts +0 -2
  207. package/out/test.d.ts.map +0 -1
  208. package/out/test.js +0 -7
  209. package/out/test.js.map +0 -1
  210. package/out/tsconfig.build.tsbuildinfo +0 -1
  211. package/out/type.d.ts.map +0 -1
  212. package/out/util.d.ts +0 -19
  213. package/out/util.d.ts.map +0 -1
  214. package/out/util.js +0 -7
  215. package/out/util.js.map +0 -1
  216. package/parser/semantic/intersections.ts +0 -46
  217. package/parser/semantic/semantic.ts +0 -144
  218. package/parser/shared.ts +0 -152
  219. package/util.ts +0 -36
package/out/type.d.ts CHANGED
@@ -1,77 +1,56 @@
1
- import { inferred, type ArkResult, type BaseMeta, type KeyCheckKind, type Morph, type Out, type Predicate, type TypeNode, type distill, type extractIn, type extractOut, type includesMorphs, type inferMorphOut, type inferNarrow } from "@arktype/schema";
2
- import { Callable, type Constructor, type Json, type conform } from "@arktype/util";
1
+ import { ArkErrors, type BaseMeta, type BaseRoot, type Disjoint, type Morph, type NodeDef, type Out, type Predicate, type PrimitiveConstraintKind, RawSchema, type Schema, type ambient, type constrain, type constraintKindOf, type distillConstrainableOut, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
2
+ import { Callable, type Constructor, type array, type conform } from "@arktype/util";
3
+ import { Generic, type validateParameterString } from "./generic.js";
3
4
  import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
4
- import { parseGenericParams, type GenericParamsParseError } from "./parser/generic.js";
5
- import type { inferIntersection } from "./parser/semantic/intersections.js";
5
+ import { parseGenericParams } from "./parser/generic.js";
6
6
  import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.js";
7
- import type { Scope, bindThis } from "./scope.js";
8
- import { arkKind } from "./util.js";
9
- export type TypeParser<$> = {
7
+ import type { RawScope, Scope, bindThis } from "./scope.js";
8
+ export interface TypeParserAttachments {
9
+ errors: typeof ArkErrors;
10
+ }
11
+ export interface TypeParser<$> extends TypeParserAttachments {
10
12
  <const def>(def: validateTypeRoot<def, $>): Type<inferTypeRoot<def, $>, $>;
11
- <const zero, const one, const rest extends readonly unknown[]>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<extractIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [
12
- Morph<extractOut<inferTypeRoot<zero, $>>, unknown>
13
- ] : one extends "@" ? [string | BaseMeta] : [validateTypeRoot<rest[0], $>] : []): Type<inferTypeRoot<[zero, one, ...rest], $>, $>;
13
+ <const zero, const one, const rest extends array>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distillIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distillOut<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [string | BaseMeta] : [validateTypeRoot<rest[0], $>] : []): Type<inferTypeRoot<[zero, one, ...rest], $>, $>;
14
14
  <params extends string, const def>(params: `<${validateParameterString<params>}>`, def: validateDefinition<def, $, {
15
15
  [param in parseGenericParams<params>[number]]: unknown;
16
16
  }>): Generic<parseGenericParams<params>, def, $>;
17
- };
17
+ }
18
+ export declare class RawTypeParser extends Callable<(...args: unknown[]) => RawSchema | Generic, TypeParserAttachments> {
19
+ constructor($: RawScope);
20
+ }
18
21
  export type DeclarationParser<$> = <preinferred>() => {
19
- type: <def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
22
+ type: <def>(def: validateDeclared<preinferred, def, $ & ambient, bindThis<def>>) => Type<preinferred, $>;
20
23
  };
21
- export declare const createTypeParser: <$>(scope: Scope) => TypeParser<$>;
22
- export type DefinitionParser<$> = <def>(def: validateDefinition<def, $, bindThis<def>>) => def;
23
- export type TypeConfig = {
24
- keys?: KeyCheckKind;
25
- mustBe?: string;
26
- };
27
- export declare class Type<t = unknown, $ = any> extends Callable<(data: unknown) => ArkResult<distill<extractOut<t>>>> {
28
- definition: unknown;
29
- scope: Scope;
30
- [inferred]: t;
31
- infer: distill<extractOut<t>>;
32
- config: TypeConfig;
33
- root: TypeNode<t>;
34
- allows: this["root"]["allows"];
35
- expected: string;
36
- json: Json;
37
- constructor(definition: unknown, scope: Scope);
38
- configure(config: TypeConfig): this;
39
- from(literal: this["in"]["infer"]): this["in"]["infer"];
24
+ declare class _Type<t = unknown, $ = any> extends BaseRoot<t, $> implements internalImplementationOf<Schema> {
25
+ $: Scope<$>;
26
+ get in(): Type<this["tIn"], $>;
27
+ get out(): Type<this["tOut"], $>;
28
+ intersect<def>(def: validateTypeRoot<def, $>): Type<inferIntersection<t, inferTypeRoot<def, $>>> | Disjoint;
40
29
  and<def>(def: validateTypeRoot<def, $>): Type<inferIntersection<t, inferTypeRoot<def, $>>, $>;
41
30
  or<def>(def: validateTypeRoot<def, $>): Type<t | inferTypeRoot<def, $>, $>;
42
- morph<morph extends Morph<this["infer"]>>(morph: morph): Type<(In: this["in"]["infer"]) => Out<inferMorphOut<ReturnType<morph>>>, $>;
43
- morph<morph extends Morph<this["infer"]>, def>(morph: morph, outValidator: validateTypeRoot<def, $>): Type<(In: this["in"]["infer"]) => Out<extractOut<inferTypeRoot<def, $>>>, $>;
44
- narrow<def extends Predicate<extractOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["in"]["infer"]) => Out<inferNarrow<this["infer"], def>> : inferNarrow<this["infer"], def>, $>;
45
31
  array(): Type<t[], $>;
46
- keyof(): Type<keyof this["in"]["infer"], $>;
47
- assert(data: unknown): this["infer"];
48
- equals<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def, $>, $>;
49
- extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def, $>, $>;
50
- private inCache?;
51
- get in(): Type<extractIn<t>, $>;
52
- outCache?: Type<extractOut<t>, $>;
53
- get out(): Type<extractOut<t>, $>;
32
+ keyof(): Type<keyof this["inferIn"], $>;
33
+ pipe<a extends Morph<this["infer"]>>(a: a): Type<inferPipes<t, [a]>, $>;
34
+ pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>>(a: a, b: b): Type<inferPipes<t, [a, b]>, $>;
35
+ pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>>(a: a, b: b, c: c): Type<inferPipes<t, [a, b, c]>, $>;
36
+ pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>>(a: a, b: b, c: c, d: d): Type<inferPipes<t, [a, b, c, d]>, $>;
37
+ pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>;
38
+ pipe<a extends Morph<this["infer"]>, 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>>>(a: a, b: b, c: c, d: d, e: e, f: f): Type<inferPipes<t, [a, b, c, d, e, f]>, $>;
39
+ pipe<a extends Morph<this["infer"]>, 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>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>;
40
+ narrow<def extends Predicate<distillConstrainableOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["tIn"]) => Out<inferNarrow<this["infer"], def>> : inferNarrow<this["infer"], def>, $>;
41
+ equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
42
+ extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
43
+ exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
44
+ extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
45
+ constrain<kind extends PrimitiveConstraintKind, const def extends NodeDef<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
54
46
  }
55
- export type validateTypeRoot<def, $> = validateDefinition<def, $, bindThis<def>>;
56
- export type inferTypeRoot<def, $> = inferDefinition<def, $, bindThis<def>>;
57
- type validateParameterString<params extends string> = parseGenericParams<params> extends GenericParamsParseError<infer message> ? message : params;
58
- export declare const validateUninstantiatedGeneric: (g: Generic) => Generic<string[], unknown, any>;
59
- export declare const generic: (parameters: string[], definition: unknown, scope: Scope) => Generic<string[], unknown, any>;
60
- export type GenericProps<params extends string[] = string[], def = unknown, $ = any> = {
61
- [arkKind]: "generic";
62
- $: $;
63
- parameters: params;
64
- definition: def;
65
- scope: Scope;
66
- };
67
- export type BoundArgs = Record<string, TypeNode>;
68
- export type Generic<params extends string[] = string[], def = unknown, $ = any> = {
69
- <args>(...args: conform<args, {
70
- [i in keyof params]: validateTypeRoot<args[i & keyof args], $>;
71
- }>): Type<inferDefinition<def, $, bindGenericInstantiation<params, $, args>>, $>;
72
- } & GenericProps<params, def, $>;
73
- type bindGenericInstantiation<params extends string[], $, args> = {
74
- [i in keyof params & `${number}` as params[i]]: inferTypeRoot<args[i & keyof args], $>;
75
- };
47
+ export interface Type<
48
+ /** @ts-expect-error allow instantiation assignment to the base type */
49
+ out t = unknown, $ = any> extends _Type<t, $> {
50
+ }
51
+ export type TypeConstructor<t = unknown, $ = any> = new (def: unknown, $: Scope<$>) => Type<t, $>;
52
+ export declare const Type: TypeConstructor;
53
+ export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
54
+ export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $ & ambient, bindThis<def>>;
55
+ export type inferTypeRoot<def, $ = {}> = inferDefinition<def, $ & ambient, bindThis<def>>;
76
56
  export {};
77
- //# sourceMappingURL=type.d.ts.map
package/out/type.js CHANGED
@@ -1,134 +1,33 @@
1
- import { inferred, keywords } from "@arktype/schema";
2
- import { Callable, CastableBase, map } from "@arktype/util";
1
+ import { ArkErrors, RawSchema } from "@arktype/schema";
2
+ import { Callable } from "@arktype/util";
3
+ import { Generic } from "./generic.js";
3
4
  import { parseGenericParams } from "./parser/generic.js";
4
- import { arkKind } from "./util.js";
5
- export const createTypeParser = (scope) => {
6
- const parser = (...args) => {
7
- if (args.length === 1) {
8
- // treat as a simple definition
9
- return new Type(args[0], scope);
10
- }
11
- if (args.length === 2 &&
12
- typeof args[0] === "string" &&
13
- args[0][0] === "<" &&
14
- args[0].at(-1) === ">") {
15
- // if there are exactly two args, the first of which looks like <${string}>,
16
- // treat as a generic
17
- const params = parseGenericParams(args[0].slice(1, -1));
18
- const def = args[1];
19
- return validateUninstantiatedGeneric(generic(params, def, scope));
20
- }
21
- // otherwise, treat as a tuple expression. technically, this also allows
22
- // non-expression tuple definitions to be parsed, but it's not a supported
23
- // part of the API as specified by the associated types
24
- return new Type(args, scope);
25
- };
26
- return parser;
27
- };
28
- export class Type extends Callable {
29
- definition;
30
- scope;
31
- config;
32
- root;
33
- allows;
34
- expected;
35
- json;
36
- constructor(definition, scope) {
37
- const root = parseTypeRoot(definition, scope);
38
- super(root.apply, root);
39
- this.definition = definition;
40
- this.scope = scope;
41
- this.root = root;
42
- this.allows = root.allows;
43
- this.config = scope.config;
44
- this.json = root.json;
45
- this.expected = this.root.description;
46
- }
47
- configure(config) {
48
- this.config = { ...this.config, ...config };
49
- return this;
50
- }
51
- // TODO: should return out
52
- from(literal) {
53
- return literal;
54
- }
55
- // TODO: Morph intersections, ordering
56
- and(def) {
57
- return new Type(this.root.and(parseTypeRoot(def, this.scope)), this.scope);
58
- }
59
- or(def) {
60
- return new Type(this.root.or(parseTypeRoot(def, this.scope)), this.scope);
61
- }
62
- morph(morph, outValidator) {
63
- // TODO: tuple expression for out validator
64
- outValidator;
65
- return this;
66
- // return new Type(
67
- // this.root.constrain("morph", morph),
68
- // this.scope
69
- // ) as never
70
- }
71
- // TODO: based on below, should maybe narrow morph output if used after
72
- narrow(def) {
73
- return new Type(this.root.constrain("predicate", def), this.scope);
74
- }
75
- array() {
76
- return new Type(this.root.array(), this.scope);
77
- }
78
- keyof() {
79
- return new Type(this.root.keyof(), this.scope);
80
- }
81
- assert(data) {
82
- const result = this.call(null, data);
83
- return result.errors ? result.errors.throw() : result.out;
84
- }
85
- equals(other) {
86
- return this.root.equals(parseTypeRoot(other, this.scope));
87
- }
88
- extends(other) {
89
- return this.root.extends(parseTypeRoot(other, this.scope));
90
- }
91
- inCache;
92
- get in() {
93
- this.inCache ??= new Type(this.root.in, this.scope);
94
- return this.inCache;
95
- }
96
- outCache;
97
- get out() {
98
- this.outCache ??= new Type(this.root.out, this.scope);
99
- return this.outCache;
5
+ const typeParserAttachments = Object.freeze({
6
+ errors: ArkErrors
7
+ });
8
+ export class RawTypeParser extends Callable {
9
+ constructor($) {
10
+ super((...args) => {
11
+ if (args.length === 1) {
12
+ // treat as a simple definition
13
+ return $.parseRoot(args[0]);
14
+ }
15
+ if (args.length === 2 &&
16
+ typeof args[0] === "string" &&
17
+ args[0][0] === "<" &&
18
+ args[0].at(-1) === ">") {
19
+ // if there are exactly two args, the first of which looks like <${string}>,
20
+ // treat as a generic
21
+ const params = parseGenericParams(args[0].slice(1, -1));
22
+ const def = args[1];
23
+ // TODO: validateUninstantiatedGeneric, remove this cast
24
+ return new Generic(params, def, $);
25
+ }
26
+ // otherwise, treat as a tuple expression. technically, this also allows
27
+ // non-expression tuple definitions to be parsed, but it's not a supported
28
+ // part of the API as specified by the associated types
29
+ return $.parseRoot(args);
30
+ }, { bind: $, attach: typeParserAttachments });
100
31
  }
101
32
  }
102
- const parseTypeRoot = (def, scope, args) => scope.parseDefinition(def, {
103
- args: args ?? scope.bindThis(),
104
- baseName: "type"
105
- });
106
- export const validateUninstantiatedGeneric = (g) => {
107
- // the unconstrained instantiation of the generic is not used for now
108
- // other than to eagerly validate that the def does not contain any errors
109
- g.scope.parseDefinition(g.definition,
110
- // once we support constraints on generic parameters, we'd use
111
- // the base type here: https://github.com/arktypeio/arktype/issues/796
112
- {
113
- baseName: "generic",
114
- args: map(g.parameters, (_, name) => [name, keywords.unknown])
115
- });
116
- return g;
117
- };
118
- export const generic = (parameters, definition, scope) => {
119
- return Object.assign((...args) => {
120
- const argNodes = map(parameters, (i, param) => [
121
- param,
122
- parseTypeRoot(args[i], scope)
123
- ]);
124
- const root = parseTypeRoot(definition, scope, argNodes);
125
- return new Type(root, scope);
126
- }, {
127
- [arkKind]: "generic",
128
- parameters,
129
- definition,
130
- scope
131
- // $ is only needed at compile-time
132
- });
133
- };
134
- //# sourceMappingURL=type.js.map
33
+ export const Type = RawSchema;
package/out/type.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,QAAQ,EAcR,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,QAAQ,EACR,YAAY,EACZ,GAAG,EAIH,MAAM,eAAe,CAAA;AAMtB,OAAO,EACN,kBAAkB,EAElB,MAAM,qB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CAAC,CAAC,CAAA;gBACnB,wDAAwD;gBACxD,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,CAAU,CAAU,CAAA;YACrD,CAAC;YACD,wEAAwE;YACxE,0EAA0E;YAC1E,uDAAuD;YACvD,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC,EACD,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAC1C,CAAA;IACF,CAAC;CACD;AAoID,MAAM,CAAC,MAAM,IAAI,GAAoB,SAAkB,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-dev.1",
4
+ "version": "2.0.0-dev.10",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -20,6 +20,10 @@
20
20
  "types": "./out/main.d.ts",
21
21
  "default": "./out/main.js"
22
22
  },
23
+ "./config": {
24
+ "types": "./out/config.d.ts",
25
+ "default": "./out/config.js"
26
+ },
23
27
  "./internal/*": {
24
28
  "default": "./out/*"
25
29
  }
@@ -34,7 +38,7 @@
34
38
  "test": "tsx ../repo/testPackage.ts"
35
39
  },
36
40
  "dependencies": {
37
- "@arktype/util": "0.0.17",
38
- "@arktype/schema": "0.0.3"
41
+ "@arktype/util": "0.0.36",
42
+ "@arktype/schema": "0.1.1"
39
43
  }
40
44
  }
@@ -1,60 +1,60 @@
1
- import { isNode, schema, type TypeNode } from "@arktype/schema"
1
+ import { type RawSchema, hasArkKind, type string } from "@arktype/schema"
2
2
  import {
3
- isThunk,
4
- objectKindOf,
5
- printable,
6
- throwParseError,
7
- type defined,
8
3
  type Dict,
9
- type equals,
10
4
  type ErrorMessage,
11
- type evaluate,
5
+ type Primitive,
6
+ type array,
7
+ type defined,
8
+ type equals,
12
9
  type isAny,
10
+ isThunk,
13
11
  type isUnknown,
14
- type List,
12
+ objectKindOf,
15
13
  type objectKindOrDomainOf,
16
14
  type optionalKeyOf,
17
- type Primitive,
18
- type requiredKeyOf
15
+ printable,
16
+ type requiredKeyOf,
17
+ type show,
18
+ throwParseError
19
19
  } from "@arktype/util"
20
20
  import type { type } from "../ark.js"
21
21
  import type { ParseContext } from "../scope.js"
22
- import { Type } from "../type.js"
23
22
  import {
24
- parseObjectLiteral,
25
23
  type inferObjectLiteral,
24
+ parseObjectLiteral,
26
25
  type validateObjectLiteral
27
26
  } from "./objectLiteral.js"
28
27
  import type { validateString } from "./semantic/validate.js"
29
28
  import type { BaseCompletions, inferString } from "./string/string.js"
30
29
  import {
31
- parseTuple,
32
- type inferTuple,
33
30
  type TupleExpression,
31
+ type inferTuple,
32
+ parseTuple,
34
33
  type validateTuple
35
34
  } from "./tuple.js"
36
35
 
37
- export const parseObject = (def: object, ctx: ParseContext): TypeNode => {
36
+ export const parseObject = (def: object, ctx: ParseContext): RawSchema => {
38
37
  const objectKind = objectKindOf(def)
39
38
  switch (objectKind) {
40
39
  case undefined:
41
- if (def instanceof Type) {
42
- return def.root
43
- }
44
- if (isNode(def) && def.isType()) {
45
- return def
46
- }
40
+ if (hasArkKind(def, "schema")) return def
47
41
  return parseObjectLiteral(def as Dict, ctx)
48
42
  case "Array":
49
- return parseTuple(def as List, ctx)
43
+ return parseTuple(def as array, ctx)
50
44
  case "RegExp":
51
- return schema({ basis: "string", pattern: def as RegExp })
52
- case "Function":
45
+ return ctx.$.node(
46
+ "intersection",
47
+ {
48
+ domain: "string",
49
+ regex: def as RegExp
50
+ },
51
+ { prereduced: true }
52
+ )
53
+ case "Function": {
53
54
  const resolvedDef = isThunk(def) ? def() : def
54
- if (resolvedDef instanceof Type) {
55
- return resolvedDef.root
56
- }
55
+ if (hasArkKind(resolvedDef, "schema")) return resolvedDef
57
56
  return throwParseError(writeBadDefinitionTypeMessage("Function"))
57
+ }
58
58
  default:
59
59
  return throwParseError(
60
60
  writeBadDefinitionTypeMessage(objectKind ?? printable(def))
@@ -62,80 +62,64 @@ export const parseObject = (def: object, ctx: ParseContext): TypeNode => {
62
62
  }
63
63
  }
64
64
 
65
- export type inferDefinition<def, $, args> = isAny<def> extends true
66
- ? never
67
- : def extends type.cast<infer t> | ThunkCast<infer t>
68
- ? t
69
- : def extends string
70
- ? inferString<def, $, args>
71
- : def extends readonly unknown[]
72
- ? inferTuple<def, $, args>
73
- : def extends RegExp
74
- ? string
75
- : def extends object
76
- ? inferObjectLiteral<def, $, args>
65
+ export type inferDefinition<def, $, args> =
66
+ isAny<def> extends true ? never
67
+ : def extends type.cast<infer t> | ThunkCast<infer t> ? t
68
+ : def extends string ? inferString<def, $, args>
69
+ : def extends array ? inferTuple<def, $, args>
70
+ : def extends RegExp ? string.matching<string>
71
+ : def extends object ? inferObjectLiteral<def, $, args>
77
72
  : never
78
73
 
79
- export type validateDefinition<def, $, args> = null extends undefined
80
- ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`>
81
- : [def] extends [Terminal]
82
- ? unknown extends def
83
- ? // if def is any, never is the only way we can make validation fail
84
- // since any would be assignable to a standard error message
85
- never
86
- : def
87
- : def extends string
88
- ? validateString<def, $, args>
89
- : def extends readonly unknown[]
90
- ? validateTuple<def, $, args>
91
- : def extends BadDefinitionType
92
- ? writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>
93
- : isUnknown<def> extends true
94
- ? // this allows the initial list of autocompletions to be populated when a user writes "type()",
95
- // before having specified a definition
96
- BaseCompletions<$, args> | {}
97
- : validateObjectLiteral<def, $, args>
74
+ export type validateDefinition<def, $, args> =
75
+ null extends undefined ?
76
+ ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`>
77
+ : [def] extends [Terminal] ? def
78
+ : def extends string ? validateString<def, $, args>
79
+ : def extends array ? validateTuple<def, $, args>
80
+ : def extends BadDefinitionType ?
81
+ writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>
82
+ : isUnknown<def> extends true ?
83
+ // this allows the initial list of autocompletions to be populated when a user writes "type()",
84
+ // before having specified a definition
85
+ BaseCompletions<$, args> | {}
86
+ : validateObjectLiteral<def, $, args>
98
87
 
99
88
  export type validateDeclared<declared, def, $, args> =
100
- def extends validateDefinition<def, $, args>
101
- ? validateInference<def, declared, $, args>
102
- : validateDefinition<def, $, args>
89
+ def extends validateDefinition<def, $, args> ?
90
+ validateInference<def, declared, $, args>
91
+ : validateDefinition<def, $, args>
103
92
 
104
- type validateInference<def, declared, $, args> = def extends
105
- | RegExp
106
- | type.cast<unknown>
107
- | ThunkCast
108
- | TupleExpression
109
- ? validateShallowInference<def, declared, $, args>
110
- : def extends readonly unknown[]
111
- ? declared extends readonly unknown[]
112
- ? {
113
- [i in keyof declared]: i extends keyof def
114
- ? validateInference<def[i], declared[i], $, args>
115
- : unknown
116
- }
117
- : evaluate<declarationMismatch<def, declared, $, args>>
118
- : def extends object
119
- ? evaluate<
93
+ type validateInference<def, declared, $, args> =
94
+ def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ?
95
+ validateShallowInference<def, declared, $, args>
96
+ : def extends array ?
97
+ declared extends array ?
98
+ {
99
+ [i in keyof declared]: i extends keyof def ?
100
+ validateInference<def[i], declared[i], $, args>
101
+ : unknown
102
+ }
103
+ : show<declarationMismatch<def, declared, $, args>>
104
+ : def extends object ?
105
+ show<
120
106
  {
121
- [k in requiredKeyOf<declared>]: k extends keyof def
122
- ? validateInference<def[k], declared[k], $, args>
123
- : unknown
107
+ [k in requiredKeyOf<declared>]: k extends keyof def ?
108
+ validateInference<def[k], declared[k], $, args>
109
+ : unknown
124
110
  } & {
125
- [k in optionalKeyOf<declared> &
126
- string as `${k}?`]: `${k}?` extends keyof def
127
- ? validateInference<def[`${k}?`], defined<declared[k]>, $, args>
128
- : unknown
111
+ [k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (
112
+ keyof def
113
+ ) ?
114
+ validateInference<def[`${k}?`], defined<declared[k]>, $, args>
115
+ : unknown
129
116
  }
130
- >
131
- : validateShallowInference<def, declared, $, args>
117
+ >
118
+ : validateShallowInference<def, declared, $, args>
132
119
 
133
- type validateShallowInference<def, declared, $, args> = equals<
134
- inferDefinition<def, $, args>,
135
- declared
136
- > extends true
137
- ? def
138
- : evaluate<declarationMismatch<def, declared, $, args>>
120
+ type validateShallowInference<def, declared, $, args> =
121
+ equals<inferDefinition<def, $, args>, declared> extends true ? def
122
+ : show<declarationMismatch<def, declared, $, args>>
139
123
 
140
124
  type declarationMismatch<def, declared, $, args> = {
141
125
  declared: declared