arktype 2.0.4 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -93
- package/out/attributes.d.ts +2 -2
- package/out/config.d.ts +17 -5
- package/out/config.js +2 -1
- package/out/index.d.ts +2 -2
- package/out/index.js +1 -1
- package/out/keywords/Array.js +2 -0
- package/out/keywords/FormData.js +2 -0
- package/out/keywords/TypedArray.js +2 -0
- package/out/keywords/keywords.d.ts +9 -4
- package/out/keywords/keywords.js +27 -11
- package/out/keywords/number.js +2 -0
- package/out/keywords/string.d.ts +20 -17
- package/out/keywords/string.js +43 -1
- package/out/keywords/ts.js +8 -2
- package/out/match.d.ts +101 -54
- package/out/match.js +70 -50
- package/out/methods/base.d.ts +75 -54
- package/out/methods/instantiate.d.ts +3 -8
- package/out/methods/object.d.ts +5 -5
- package/out/parser/definition.js +1 -1
- package/out/parser/property.d.ts +1 -3
- package/out/parser/shift/scanner.d.ts +1 -1
- package/out/parser/tupleExpressions.d.ts +50 -14
- package/out/parser/tupleExpressions.js +20 -9
- package/out/scope.d.ts +14 -6
- package/out/scope.js +18 -9
- package/out/type.d.ts +7 -4
- package/out/type.js +1 -0
- package/package.json +8 -5
- package/out/methods/morph.d.ts +0 -12
- package/out/methods/morph.js +0 -1
package/out/type.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ArkErrors, BaseRoot, type BaseParseOptions, type
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseParseOptions, type Morph, type Predicate, type RootSchema } from "@ark/schema";
|
|
2
2
|
import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
|
|
3
3
|
import type { distill } from "./attributes.ts";
|
|
4
|
+
import type { TypeMetaInput } from "./config.ts";
|
|
4
5
|
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
|
|
5
6
|
import type { Ark, keywords, type } from "./keywords/keywords.ts";
|
|
7
|
+
import type { MatchParser } from "./match.ts";
|
|
6
8
|
import type { BaseType } from "./methods/base.ts";
|
|
7
9
|
import type { instantiateType } from "./methods/instantiate.ts";
|
|
8
10
|
import type { validateDeclared } from "./parser/definition.ts";
|
|
@@ -16,7 +18,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
|
16
18
|
*
|
|
17
19
|
* @example const person = type({ name: "string" })
|
|
18
20
|
*/
|
|
19
|
-
<const def, r =
|
|
21
|
+
<const def, r = type.instantiate<def, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
|
|
20
22
|
/**
|
|
21
23
|
* Create a {@link Generic} from a parameter string and body definition.
|
|
22
24
|
*
|
|
@@ -29,14 +31,14 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
|
29
31
|
*
|
|
30
32
|
* @example const boxOf = type("<t extends string | number>", { contents: "t" })
|
|
31
33
|
*/
|
|
32
|
-
<const params extends ParameterString, const def
|
|
34
|
+
<const params extends ParameterString, const def, r = Generic<parseValidGenericParams<params, $>, def, $>>(params: validateParameterString<params, $>, def: type.validate<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): r extends infer _ ? _ : never;
|
|
33
35
|
/**
|
|
34
36
|
* Create a {@link Type} from a [tuple expression](http://localhost:3000/docs/expressions)
|
|
35
37
|
* spread as this function's arguments.
|
|
36
38
|
*
|
|
37
39
|
* @example type("string", "|", { foo: "number" })
|
|
38
40
|
*/
|
|
39
|
-
<const zero, const one, const rest extends array, r =
|
|
41
|
+
<const zero, const one, const rest extends array, r = type.instantiate<[zero, one, ...rest], $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, ArgTwoOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "|>" ? [type.validate<rest[0], $>] : one extends "@" ? [TypeMetaInput] : [type.validate<rest[0], $>] : []): r extends infer _ ? _ : never;
|
|
40
42
|
/**
|
|
41
43
|
* An alias of the {@link ArkErrors} class, an instance of which is returned when a {@link Type}
|
|
42
44
|
* is invoked with invalid input.
|
|
@@ -64,6 +66,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
|
64
66
|
scope: ScopeParser;
|
|
65
67
|
define: DefinitionParser<$>;
|
|
66
68
|
generic: GenericParser<$>;
|
|
69
|
+
match: MatchParser<$>;
|
|
67
70
|
schema: SchemaParser<$>;
|
|
68
71
|
/**
|
|
69
72
|
* Create a {@link Type} that is satisfied only by a value strictly equal (`===`) to the argument passed to this function.
|
package/out/type.js
CHANGED
|
@@ -10,6 +10,7 @@ export class InternalTypeParser extends Callable {
|
|
|
10
10
|
module: $.constructor.module,
|
|
11
11
|
scope: $.constructor.scope,
|
|
12
12
|
define: $.define,
|
|
13
|
+
match: $.match,
|
|
13
14
|
generic: $.generic,
|
|
14
15
|
schema: $.schema,
|
|
15
16
|
// this won't be defined during bootstrapping, but externally always will be
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "2.
|
|
3
|
+
"description": "Optimized runtime validation for TypeScript syntax",
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"out"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ark/util": "0.
|
|
38
|
-
"@ark/schema": "0.
|
|
37
|
+
"@ark/util": "0.42.0",
|
|
38
|
+
"@ark/schema": "0.42.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "ts ../repo/build.ts",
|
|
45
45
|
"test": "ts ../repo/testPackage.ts; pnpm testIntegration",
|
|
46
|
-
"testIntegration": "
|
|
46
|
+
"testIntegration": "pnpm testSimpleConfig && pnpm testAllConfig && pnpm testOnFailConfig",
|
|
47
|
+
"testSimpleConfig": "ts ./__tests__/integration/testSimpleConfig.ts",
|
|
48
|
+
"testAllConfig": "ts ./__tests__/integration/testAllConfig.ts",
|
|
49
|
+
"testOnFailConfig": "ts ./__tests__/integration/testOnFailConfig.ts"
|
|
47
50
|
}
|
|
48
51
|
}
|
package/out/methods/morph.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { inferPipe } from "../attributes.ts";
|
|
2
|
-
import type { type } from "../keywords/keywords.ts";
|
|
3
|
-
import type { BaseType } from "./base.ts";
|
|
4
|
-
/** @ts-ignore cast variance */
|
|
5
|
-
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
6
|
-
/**
|
|
7
|
-
* Append extra validation shape on the pipe output
|
|
8
|
-
* @example type({codes: 'string.numeric[]'}).pipe(obj => obj.codes).to('string.numeric.parse[]')
|
|
9
|
-
*/
|
|
10
|
-
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
|
|
11
|
-
}
|
|
12
|
-
export type { Type as MorphType };
|
package/out/methods/morph.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|