arktype 2.1.8 → 2.1.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.
- package/README.md +1 -1
- package/out/config.d.ts +2 -4
- package/out/methods/base.d.ts +5 -5
- package/out/parser/ast/infer.d.ts +2 -2
- package/out/parser/ast/validate.d.ts +2 -2
- package/out/parser/reduce/dynamic.d.ts +3 -2
- package/out/parser/reduce/dynamic.js +28 -13
- package/out/parser/reduce/shared.d.ts +1 -0
- package/out/parser/reduce/static.d.ts +14 -6
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/operator/operator.js +13 -9
- package/out/parser/tupleExpressions.d.ts +9 -11
- package/out/parser/tupleExpressions.js +6 -9
- package/out/parser/tupleLiteral.js +1 -1
- package/out/scope.d.ts +5 -7
- package/out/scope.js +2 -1
- package/out/type.d.ts +10 -3
- package/out/type.js +2 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<h1 align="center">ArkType</h1>
|
|
2
|
-
<h3 align="center"><i>
|
|
2
|
+
<h3 align="center"><i>TypeScript's 1:1 validator, optimized from editor to runtime</i></h1>
|
|
3
3
|
|
|
4
4
|
ArkType is a runtime validation library that parses optimized validators from familiar, type-safe syntax.
|
|
5
5
|
|
package/out/config.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { arkKind } from "@ark/schema";
|
|
1
|
+
import type { arkKind, TypeMeta } from "@ark/schema";
|
|
2
2
|
import type { Ark } from "./keywords/keywords.ts";
|
|
3
3
|
import { type ArkSchemaConfig } from "@ark/schema/config";
|
|
4
4
|
import type { anyOrNever } from "@ark/util";
|
|
5
|
-
export type TypeMeta = Omit<ArkEnv.meta, "onFail">;
|
|
6
|
-
export type TypeMetaInput = string | TypeMeta;
|
|
7
5
|
export type KeywordConfig = {
|
|
8
|
-
[k in keyof Ark.flat as parseConfigurableFlatAlias<k, Ark.flat[k]>]?:
|
|
6
|
+
[k in keyof Ark.flat as parseConfigurableFlatAlias<k, Ark.flat[k]>]?: TypeMeta.Collapsible;
|
|
9
7
|
};
|
|
10
8
|
type parseConfigurableFlatAlias<k extends string, v> = [
|
|
11
9
|
v
|
package/out/methods/base.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { BaseRoot, Disjoint, JsonSchema, Morph, Predicate, StandardSchemaV1, UndeclaredKeyBehavior } from "@ark/schema";
|
|
1
|
+
import type { BaseRoot, Disjoint, JsonSchema, Morph, NodeSelector, Predicate, StandardSchemaV1, TypeMeta, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, JsonStructure, unset } from "@ark/util";
|
|
3
3
|
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPipe, inferPipes, InferredMorph, Out, To } from "../attributes.ts";
|
|
4
|
-
import type { ArkAmbient
|
|
4
|
+
import type { ArkAmbient } from "../config.ts";
|
|
5
5
|
import type { type } from "../keywords/keywords.ts";
|
|
6
6
|
import type { Scope } from "../scope.ts";
|
|
7
7
|
import type { ArrayType } from "./array.ts";
|
|
@@ -174,7 +174,7 @@ export interface Inferred<out t = unknown, $ = {}> {
|
|
|
174
174
|
* // error message at root is affected, leading to a misleading description
|
|
175
175
|
* const nonObject = notOddBox(null) // must be not odd (was null)
|
|
176
176
|
*/
|
|
177
|
-
configure
|
|
177
|
+
configure: NodeSelector.SelectableFn<TypeMeta.MappableInput, this>;
|
|
178
178
|
/**
|
|
179
179
|
* #### add description to shallow references
|
|
180
180
|
*
|
|
@@ -187,7 +187,7 @@ export interface Inferred<out t = unknown, $ = {}> {
|
|
|
187
187
|
* // ArkErrors: must be a string like 'a...z' (was "albatross")
|
|
188
188
|
* const badPattern = aToZ("albatross")
|
|
189
189
|
*/
|
|
190
|
-
describe
|
|
190
|
+
describe: NodeSelector.SelectableFn<string, this>;
|
|
191
191
|
/**
|
|
192
192
|
* #### apply undeclared key behavior
|
|
193
193
|
*
|
|
@@ -383,7 +383,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
383
383
|
/**
|
|
384
384
|
* #### union with the parsed Type
|
|
385
385
|
*
|
|
386
|
-
* ⚠️ a union that could apply different morphs to the same data is a ParseError (
|
|
386
|
+
* ⚠️ a union that could apply different morphs to the same data is a ParseError ({@link https://arktype.io/docs/expressions#union-morphs | docs})
|
|
387
387
|
*
|
|
388
388
|
* @example
|
|
389
389
|
* // Type<string | { box: string }>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { arkKeyOf, array } from "@ark/util";
|
|
2
|
-
import type { distill, inferIntersection, LimitLiteral, withDefault } from "../../attributes.ts";
|
|
2
|
+
import type { distill, inferIntersection, inferPipe, LimitLiteral, withDefault } from "../../attributes.ts";
|
|
3
3
|
import type { type } from "../../keywords/keywords.ts";
|
|
4
4
|
import type { inferDefinition } from "../definition.ts";
|
|
5
5
|
import type { Comparator } from "../reduce/shared.ts";
|
|
@@ -18,7 +18,7 @@ export type InferredAst<t = unknown, def extends string = string> = [
|
|
|
18
18
|
"inferred",
|
|
19
19
|
def
|
|
20
20
|
];
|
|
21
|
-
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> ? inferGenericInstantiation<g, argAsts, $, args> : 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 "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
21
|
+
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> ? inferGenericInstantiation<g, argAsts, $, args> : 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 "|>" ? inferPipe<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
22
22
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
23
23
|
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
24
24
|
export type PostfixExpression<operator extends ArkTypeScanner.PostfixToken = ArkTypeScanner.PostfixToken, operand = unknown> = readonly [operand, operator];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { arkKind, PrivateDeclaration, writeMissingSubmoduleAccessMessage } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, BigintLiteral, Completion, ErrorMessage, NumberLiteral, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
3
|
import type { Generic } from "../../generic.ts";
|
|
4
|
-
import type { Comparator } from "../reduce/shared.ts";
|
|
4
|
+
import type { BranchOperator, Comparator } from "../reduce/shared.ts";
|
|
5
5
|
import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
|
|
6
6
|
import type { UnitLiteral } from "../shift/operator/default.ts";
|
|
7
7
|
import type { parseString } from "../string.ts";
|
|
@@ -12,7 +12,7 @@ import type { GenericInstantiationAst, validateGenericInstantiation } from "./ge
|
|
|
12
12
|
import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
13
13
|
import type { validateKeyof } from "./keyof.ts";
|
|
14
14
|
import type { astToString } from "./utils.ts";
|
|
15
|
-
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends
|
|
15
|
+
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends BranchOperator ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
16
16
|
ast: ast;
|
|
17
17
|
};
|
|
18
18
|
type writeUnexpectedExpressionMessage<expression extends string> = `Failed to parse the expression resulting from ${expression}`;
|
|
@@ -2,12 +2,13 @@ import type { BaseParseContext, BaseRoot } from "@ark/schema";
|
|
|
2
2
|
import { type requireKeys } from "@ark/util";
|
|
3
3
|
import type { LimitLiteral } from "../../attributes.ts";
|
|
4
4
|
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
5
|
-
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
5
|
+
import { type BranchOperator, type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
6
6
|
type BranchState = {
|
|
7
7
|
prefixes: StringifiablePrefixOperator[];
|
|
8
8
|
leftBound: OpenLeftBound | null;
|
|
9
9
|
intersection: BaseRoot | null;
|
|
10
10
|
union: BaseRoot | null;
|
|
11
|
+
pipe: BaseRoot | null;
|
|
11
12
|
};
|
|
12
13
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
13
14
|
export declare class DynamicState {
|
|
@@ -29,7 +30,7 @@ export declare class DynamicState {
|
|
|
29
30
|
finalizeGroup(): void;
|
|
30
31
|
addPrefix(prefix: StringifiablePrefixOperator): void;
|
|
31
32
|
applyPrefixes(): void;
|
|
32
|
-
pushRootToBranch(token:
|
|
33
|
+
pushRootToBranch(token: BranchOperator): void;
|
|
33
34
|
parseUntilFinalizer(): DynamicStateWithRoot;
|
|
34
35
|
parseOperator(this: DynamicStateWithRoot): void;
|
|
35
36
|
parseOperand(): void;
|
|
@@ -10,7 +10,8 @@ export class DynamicState {
|
|
|
10
10
|
prefixes: [],
|
|
11
11
|
leftBound: null,
|
|
12
12
|
intersection: null,
|
|
13
|
-
union: null
|
|
13
|
+
union: null,
|
|
14
|
+
pipe: null
|
|
14
15
|
};
|
|
15
16
|
finalizer;
|
|
16
17
|
groups = [];
|
|
@@ -57,16 +58,22 @@ export class DynamicState {
|
|
|
57
58
|
}
|
|
58
59
|
finalizeBranches() {
|
|
59
60
|
this.assertRangeUnset();
|
|
61
|
+
if (this.branches.pipe) {
|
|
62
|
+
this.pushRootToBranch("|>");
|
|
63
|
+
this.root = this.branches.pipe;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
60
66
|
if (this.branches.union) {
|
|
61
67
|
this.pushRootToBranch("|");
|
|
62
68
|
this.root = this.branches.union;
|
|
69
|
+
return;
|
|
63
70
|
}
|
|
64
|
-
|
|
71
|
+
if (this.branches.intersection) {
|
|
65
72
|
this.pushRootToBranch("&");
|
|
66
73
|
this.root = this.branches.intersection;
|
|
74
|
+
return;
|
|
67
75
|
}
|
|
68
|
-
|
|
69
|
-
this.applyPrefixes();
|
|
76
|
+
this.applyPrefixes();
|
|
70
77
|
}
|
|
71
78
|
finalizeGroup() {
|
|
72
79
|
this.finalizeBranches();
|
|
@@ -91,15 +98,21 @@ export class DynamicState {
|
|
|
91
98
|
this.assertRangeUnset();
|
|
92
99
|
this.applyPrefixes();
|
|
93
100
|
const root = this.root;
|
|
101
|
+
this.root = undefined;
|
|
94
102
|
this.branches.intersection =
|
|
95
103
|
this.branches.intersection?.rawAnd(root) ?? root;
|
|
96
|
-
if (token === "
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
if (token === "&")
|
|
105
|
+
return;
|
|
106
|
+
this.branches.union =
|
|
107
|
+
this.branches.union?.rawOr(this.branches.intersection) ??
|
|
108
|
+
this.branches.intersection;
|
|
109
|
+
this.branches.intersection = null;
|
|
110
|
+
if (token === "|")
|
|
111
|
+
return;
|
|
112
|
+
this.branches.pipe =
|
|
113
|
+
this.branches.pipe?.rawPipeOnce(this.branches.union) ??
|
|
114
|
+
this.branches.union;
|
|
115
|
+
this.branches.union = null;
|
|
103
116
|
}
|
|
104
117
|
parseUntilFinalizer() {
|
|
105
118
|
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx));
|
|
@@ -121,7 +134,8 @@ export class DynamicState {
|
|
|
121
134
|
prefixes: [],
|
|
122
135
|
leftBound: null,
|
|
123
136
|
union: null,
|
|
124
|
-
intersection: null
|
|
137
|
+
intersection: null,
|
|
138
|
+
pipe: null
|
|
125
139
|
};
|
|
126
140
|
}
|
|
127
141
|
previousOperator() {
|
|
@@ -129,7 +143,8 @@ export class DynamicState {
|
|
|
129
143
|
this.branches.prefixes.at(-1) ??
|
|
130
144
|
(this.branches.intersection ? "&"
|
|
131
145
|
: this.branches.union ? "|"
|
|
132
|
-
:
|
|
146
|
+
: this.branches.pipe ? "|>"
|
|
147
|
+
: undefined));
|
|
133
148
|
}
|
|
134
149
|
shiftedByOne() {
|
|
135
150
|
this.scanner.shift();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Completion, ErrorMessage, defined } from "@ark/util";
|
|
2
2
|
import type { LimitLiteral } from "../../attributes.ts";
|
|
3
3
|
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
4
|
-
import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
|
|
4
|
+
import type { BranchOperator, Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
|
|
5
5
|
export type StaticState = {
|
|
6
6
|
root: unknown;
|
|
7
7
|
branches: BranchState;
|
|
@@ -14,6 +14,7 @@ type BranchState = {
|
|
|
14
14
|
prefixes: StringifiablePrefixOperator[];
|
|
15
15
|
leftBound: OpenLeftBound | undefined;
|
|
16
16
|
intersection: unknown;
|
|
17
|
+
pipe: unknown;
|
|
17
18
|
union: unknown;
|
|
18
19
|
};
|
|
19
20
|
export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
|
|
@@ -46,6 +47,7 @@ export declare namespace state {
|
|
|
46
47
|
prefixes: [];
|
|
47
48
|
leftBound: undefined;
|
|
48
49
|
intersection: undefined;
|
|
50
|
+
pipe: undefined;
|
|
49
51
|
union: undefined;
|
|
50
52
|
}>;
|
|
51
53
|
type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
|
|
@@ -63,6 +65,7 @@ export declare namespace state {
|
|
|
63
65
|
prefixes: [...s["branches"]["prefixes"], prefix];
|
|
64
66
|
leftBound: s["branches"]["leftBound"];
|
|
65
67
|
intersection: s["branches"]["intersection"];
|
|
68
|
+
pipe: s["branches"]["pipe"];
|
|
66
69
|
union: s["branches"]["union"];
|
|
67
70
|
};
|
|
68
71
|
groups: s["groups"];
|
|
@@ -70,13 +73,14 @@ export declare namespace state {
|
|
|
70
73
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
71
74
|
unscanned: unscanned;
|
|
72
75
|
}>;
|
|
73
|
-
type reduceBranch<s extends StaticState, token extends
|
|
76
|
+
type reduceBranch<s extends StaticState, token extends BranchOperator, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
74
77
|
root: undefined;
|
|
75
78
|
branches: {
|
|
76
79
|
prefixes: [];
|
|
77
80
|
leftBound: undefined;
|
|
78
81
|
intersection: token extends "&" ? mergeToIntersection<s> : undefined;
|
|
79
|
-
union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"];
|
|
82
|
+
union: token extends "|" ? mergeToUnion<s> : token extends "|>" ? undefined : s["branches"]["union"];
|
|
83
|
+
pipe: token extends "|>" ? mergeToPipe<s> : s["branches"]["pipe"];
|
|
80
84
|
};
|
|
81
85
|
groups: s["groups"];
|
|
82
86
|
finalizer: s["finalizer"];
|
|
@@ -92,6 +96,7 @@ export declare namespace state {
|
|
|
92
96
|
comparator: InvertedComparators[comparator];
|
|
93
97
|
};
|
|
94
98
|
intersection: s["branches"]["intersection"];
|
|
99
|
+
pipe: s["branches"]["pipe"];
|
|
95
100
|
union: s["branches"]["union"];
|
|
96
101
|
};
|
|
97
102
|
groups: s["groups"];
|
|
@@ -105,6 +110,7 @@ export declare namespace state {
|
|
|
105
110
|
prefixes: s["branches"]["prefixes"];
|
|
106
111
|
leftBound: undefined;
|
|
107
112
|
intersection: s["branches"]["intersection"];
|
|
113
|
+
pipe: s["branches"]["pipe"];
|
|
108
114
|
union: s["branches"]["union"];
|
|
109
115
|
};
|
|
110
116
|
groups: s["groups"];
|
|
@@ -118,6 +124,7 @@ export declare namespace state {
|
|
|
118
124
|
prefixes: s["branches"]["prefixes"];
|
|
119
125
|
leftBound: undefined;
|
|
120
126
|
intersection: s["branches"]["intersection"];
|
|
127
|
+
pipe: s["branches"]["pipe"];
|
|
121
128
|
union: s["branches"]["union"];
|
|
122
129
|
};
|
|
123
130
|
groups: s["groups"];
|
|
@@ -125,8 +132,9 @@ export declare namespace state {
|
|
|
125
132
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
126
133
|
unscanned: unscanned;
|
|
127
134
|
}>;
|
|
128
|
-
type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
|
|
129
135
|
type mergeToIntersection<s extends StaticState> = s["branches"]["intersection"] extends undefined ? mergePrefixes<s> : [s["branches"]["intersection"], "&", mergePrefixes<s>];
|
|
136
|
+
type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
|
|
137
|
+
type mergeToPipe<s extends StaticState> = s["branches"]["pipe"] extends undefined ? mergeToUnion<s> : [s["branches"]["pipe"], "|>", mergeToUnion<s>];
|
|
130
138
|
type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [
|
|
131
139
|
head,
|
|
132
140
|
mergePrefixes<s, tail>
|
|
@@ -138,7 +146,7 @@ export declare namespace state {
|
|
|
138
146
|
type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
|
|
139
147
|
groups: stack;
|
|
140
148
|
branches: top;
|
|
141
|
-
root:
|
|
149
|
+
root: mergeToPipe<s>;
|
|
142
150
|
finalizer: s["finalizer"];
|
|
143
151
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
144
152
|
unscanned: unscanned;
|
|
@@ -152,7 +160,7 @@ export declare namespace state {
|
|
|
152
160
|
unscanned: unscanned;
|
|
153
161
|
}>;
|
|
154
162
|
type finalize<s extends StaticState, finalizer extends ArkTypeScanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
155
|
-
root:
|
|
163
|
+
root: mergeToPipe<s>;
|
|
156
164
|
groups: s["groups"];
|
|
157
165
|
branches: initialBranches;
|
|
158
166
|
finalizer: finalizer;
|
|
@@ -6,7 +6,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.ts";
|
|
|
6
6
|
import { parseBrand } from "./brand.ts";
|
|
7
7
|
import { parseDivisor } from "./divisor.ts";
|
|
8
8
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
9
|
-
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|"
|
|
9
|
+
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" ? unscanned extends ArkTypeScanner.shift<">", infer nextUnscanned> ? state.reduceBranch<s, "|>", nextUnscanned> : state.reduceBranch<s, lookahead, unscanned> : lookahead extends "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : ArkTypeScanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & ArkTypeScanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
10
10
|
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
11
11
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
12
12
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
@@ -10,15 +10,19 @@ export const parseOperator = (s) => {
|
|
|
10
10
|
s.scanner.shift() === "]" ?
|
|
11
11
|
s.setRoot(s.root.array())
|
|
12
12
|
: s.error(incompleteArrayTokenMessage)
|
|
13
|
-
: lookahead === "|"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
: lookahead === "|" ?
|
|
14
|
+
s.scanner.lookahead === ">" ?
|
|
15
|
+
s.shiftedByOne().pushRootToBranch("|>")
|
|
16
|
+
: s.pushRootToBranch(lookahead)
|
|
17
|
+
: lookahead === "&" ? s.pushRootToBranch(lookahead)
|
|
18
|
+
: lookahead === ")" ? s.finalizeGroup()
|
|
19
|
+
: ArkTypeScanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
|
|
20
|
+
s.finalize(lookahead)
|
|
21
|
+
: isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
|
|
22
|
+
: lookahead === "%" ? parseDivisor(s)
|
|
23
|
+
: lookahead === "#" ? parseBrand(s)
|
|
24
|
+
: lookahead in whitespaceChars ? parseOperator(s)
|
|
25
|
+
: s.error(writeUnexpectedCharacterMessage(lookahead)));
|
|
22
26
|
};
|
|
23
27
|
export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
|
|
24
28
|
export const incompleteArrayTokenMessage = `Missing expected ']'`;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type BaseParseContext, type BaseRoot, type Morph, type Predicate, type unwrapDefault } from "@ark/schema";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type Morph, type Predicate, type TypeMeta, type unwrapDefault } from "@ark/schema";
|
|
2
2
|
import { type array, type BuiltinObjectKind, type Constructor, type Domain, type show } from "@ark/util";
|
|
3
3
|
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPipe, inferPredicate, Out, withDefault } from "../attributes.ts";
|
|
4
|
-
import type { TypeMetaInput } from "../config.ts";
|
|
5
4
|
import type { type } from "../keywords/keywords.ts";
|
|
6
5
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
7
6
|
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
@@ -17,7 +16,7 @@ export type validatePrefixExpression<def extends IndexZeroExpression, $, args> =
|
|
|
17
16
|
export type validateIndexOneExpression<def extends IndexOneExpression, $, args> = def[1] extends TuplePostfixOperator ? readonly [validateDefinition<def[0], $, args>, def[1]] : readonly [
|
|
18
17
|
validateDefinition<def[0], $, args>,
|
|
19
18
|
def["length"] extends 2 ? writeMissingRightOperandMessage<def[1]> : def[1],
|
|
20
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "|>" ? validateDefinition<def[2], $, args> : def[1] extends "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ?
|
|
19
|
+
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "|>" ? validateDefinition<def[2], $, args> : def[1] extends "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ? TypeMeta.MappableInput : validateDefinition<def[2], $, args>
|
|
21
20
|
];
|
|
22
21
|
export type UnparsedTupleExpressionInput = {
|
|
23
22
|
instanceof: Constructor;
|
|
@@ -30,8 +29,7 @@ export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
|
30
29
|
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
31
30
|
export type ArgTwoOperator = Exclude<IndexOneOperator, "?" | "=">;
|
|
32
31
|
export declare const parseMorphTuple: IndexOneParser<"=>">;
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>" | "|>", value: unknown) => string;
|
|
32
|
+
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
35
33
|
export type parseTo<inDef, outDef, $, args> = inferPipe<inferDefinition<inDef, $, args>, inferDefinition<outDef, $, args>>;
|
|
36
34
|
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
37
35
|
export declare const parseNarrowTuple: IndexOneParser<":">;
|
|
@@ -43,22 +41,22 @@ declare const postfixParsers: {
|
|
|
43
41
|
};
|
|
44
42
|
export type TuplePostfixOperator = keyof typeof postfixParsers;
|
|
45
43
|
declare const infixParsers: {
|
|
46
|
-
"=": IndexOneParser<"=">;
|
|
47
|
-
"|": IndexOneParser<"|">;
|
|
48
44
|
"&": IndexOneParser<"&">;
|
|
45
|
+
"|": IndexOneParser<"|">;
|
|
46
|
+
"|>": IndexOneParser<"|>">;
|
|
47
|
+
"=": IndexOneParser<"=">;
|
|
49
48
|
":": IndexOneParser<":">;
|
|
50
49
|
"=>": IndexOneParser<"=>">;
|
|
51
|
-
"|>": IndexOneParser<"|>">;
|
|
52
50
|
"@": IndexOneParser<"@">;
|
|
53
51
|
};
|
|
54
52
|
export type TupleInfixOperator = keyof typeof infixParsers;
|
|
55
53
|
declare const indexOneParsers: {
|
|
56
|
-
"=": IndexOneParser<"=">;
|
|
57
|
-
"|": IndexOneParser<"|">;
|
|
58
54
|
"&": IndexOneParser<"&">;
|
|
55
|
+
"|": IndexOneParser<"|">;
|
|
56
|
+
"|>": IndexOneParser<"|>">;
|
|
57
|
+
"=": IndexOneParser<"=">;
|
|
59
58
|
":": IndexOneParser<":">;
|
|
60
59
|
"=>": IndexOneParser<"=>">;
|
|
61
|
-
"|>": IndexOneParser<"|>">;
|
|
62
60
|
"@": IndexOneParser<"@">;
|
|
63
61
|
"?": IndexOneParser<"?">;
|
|
64
62
|
"[]": IndexOneParser<"[]">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Disjoint, intersectNodesRoot } from "@ark/schema";
|
|
1
|
+
import { Disjoint, intersectNodesRoot, pipeNodesRoot } from "@ark/schema";
|
|
2
2
|
import { objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
3
|
import { shallowDefaultableMessage, shallowOptionalMessage } from "./ast/validate.js";
|
|
4
4
|
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
|
|
@@ -13,7 +13,9 @@ const parseBranchTuple = (def, ctx) => {
|
|
|
13
13
|
const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
|
|
14
14
|
if (def[1] === "|")
|
|
15
15
|
return ctx.$.node("union", { branches: [l, r] });
|
|
16
|
-
const result =
|
|
16
|
+
const result = def[1] === "&" ?
|
|
17
|
+
intersectNodesRoot(l, r, ctx.$)
|
|
18
|
+
: pipeNodesRoot(l, r, ctx.$);
|
|
17
19
|
if (result instanceof Disjoint)
|
|
18
20
|
return result.throw();
|
|
19
21
|
return result;
|
|
@@ -25,11 +27,6 @@ export const parseMorphTuple = (def, ctx) => {
|
|
|
25
27
|
}
|
|
26
28
|
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
|
|
27
29
|
};
|
|
28
|
-
export const parseToTuple = (def, ctx) => {
|
|
29
|
-
const node = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
|
|
30
|
-
const outputValidator = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
|
|
31
|
-
return node.to(outputValidator);
|
|
32
|
-
};
|
|
33
30
|
export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
|
|
34
31
|
export const parseNarrowTuple = (def, ctx) => {
|
|
35
32
|
if (typeof def[2] !== "function") {
|
|
@@ -37,7 +34,7 @@ export const parseNarrowTuple = (def, ctx) => {
|
|
|
37
34
|
}
|
|
38
35
|
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
|
|
39
36
|
};
|
|
40
|
-
const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).
|
|
37
|
+
const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configureDescendants(def[2], "shallow");
|
|
41
38
|
const defineIndexOneParsers = (parsers) => parsers;
|
|
42
39
|
const postfixParsers = defineIndexOneParsers({
|
|
43
40
|
"[]": parseArrayTuple,
|
|
@@ -48,7 +45,7 @@ const infixParsers = defineIndexOneParsers({
|
|
|
48
45
|
"&": parseBranchTuple,
|
|
49
46
|
":": parseNarrowTuple,
|
|
50
47
|
"=>": parseMorphTuple,
|
|
51
|
-
"|>":
|
|
48
|
+
"|>": parseBranchTuple,
|
|
52
49
|
"@": parseAttributeTuple,
|
|
53
50
|
// since object and tuple literals parse there via `parseProperty`,
|
|
54
51
|
// they must be shallow if parsed directly as a tuple expression
|
|
@@ -101,7 +101,7 @@ const appendVariadicElement = (base, element) => {
|
|
|
101
101
|
return base;
|
|
102
102
|
};
|
|
103
103
|
const appendSpreadBranch = (base, branch) => {
|
|
104
|
-
const spread = branch.
|
|
104
|
+
const spread = branch.select({ method: "find", kind: "sequence" });
|
|
105
105
|
if (!spread) {
|
|
106
106
|
// the only array with no sequence reference is unknown[]
|
|
107
107
|
return appendVariadicElement(base, $ark.intrinsic.unknown);
|
package/out/scope.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BaseScope, type AliasDefEntry, type ArkSchemaRegistry, type ArkSchemaScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type
|
|
1
|
+
import { BaseScope, type AliasDefEntry, type ArkSchemaRegistry, type ArkSchemaScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
|
|
2
2
|
import { type Brand, type ErrorType, type JsonStructure, type anyOrNever, type array, type flattenListable, type noSuggest } from "@ark/util";
|
|
3
|
-
import type { TypeMetaInput } from "./config.ts";
|
|
4
3
|
import { type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
|
|
5
4
|
import type { Ark, type } from "./keywords/keywords.ts";
|
|
6
5
|
import { InternalMatchParser, type MatchParser } from "./match.ts";
|
|
@@ -9,7 +8,7 @@ import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
|
|
|
9
8
|
import { type inferDefinition } from "./parser/definition.ts";
|
|
10
9
|
import type { ParsedOptionalProperty } from "./parser/property.ts";
|
|
11
10
|
import type { ParsedDefaultableProperty } from "./parser/shift/operator/default.ts";
|
|
12
|
-
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
|
|
11
|
+
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser, type ValueOfTypeParser } from "./type.ts";
|
|
13
12
|
/** The convenience properties attached to `scope` */
|
|
14
13
|
export type ScopeParserAttachments = Omit<ScopeParser, never>;
|
|
15
14
|
export interface ArkScopeConfig extends ArkSchemaScopeConfig {
|
|
@@ -68,11 +67,7 @@ export declare const $arkTypeRegistry: ArkTypeRegistry;
|
|
|
68
67
|
export interface InternalScope {
|
|
69
68
|
constructor: typeof InternalScope;
|
|
70
69
|
}
|
|
71
|
-
interface ResolvedTypeScopeConfig extends ResolvedScopeConfig {
|
|
72
|
-
keywords?: Record<string, TypeMetaInput>;
|
|
73
|
-
}
|
|
74
70
|
export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
75
|
-
resolvedConfig: ResolvedTypeScopeConfig;
|
|
76
71
|
get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
|
|
77
72
|
protected preparseOwnAliasEntry(alias: string, def: unknown): AliasDefEntry;
|
|
78
73
|
parseGenericParams(def: string, opts: BaseParseOptions): array<GenericParamDef>;
|
|
@@ -80,6 +75,7 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
80
75
|
protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
|
|
81
76
|
parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
|
|
82
77
|
unit: UnitTypeParser<$>;
|
|
78
|
+
valueOf: ValueOfTypeParser<$>;
|
|
83
79
|
enumerated: EnumeratedTypeParser<$>;
|
|
84
80
|
instanceOf: InstanceOfTypeParser<$>;
|
|
85
81
|
match: InternalMatchParser;
|
|
@@ -113,6 +109,8 @@ export interface Scope<$ = {}> {
|
|
|
113
109
|
node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: BaseParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
|
|
114
110
|
unit: UnitTypeParser<$>;
|
|
115
111
|
enumerated: EnumeratedTypeParser<$>;
|
|
112
|
+
valueOf: ValueOfTypeParser<$>;
|
|
113
|
+
instanceOf: InstanceOfTypeParser<$>;
|
|
116
114
|
type: TypeParser<$>;
|
|
117
115
|
match: MatchParser<$>;
|
|
118
116
|
declare: DeclarationParser<$>;
|
package/out/scope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
|
|
2
|
-
import { flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
|
|
2
|
+
import { enumValues, flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
|
|
3
3
|
import { parseGenericParamName } from "./generic.js";
|
|
4
4
|
import { InternalMatchParser } from "./match.js";
|
|
5
5
|
import { shallowDefaultableMessage, shallowOptionalMessage } from "./parser/ast/validate.js";
|
|
@@ -81,6 +81,7 @@ export class InternalScope extends BaseScope {
|
|
|
81
81
|
return result;
|
|
82
82
|
}
|
|
83
83
|
unit = value => this.units([value]);
|
|
84
|
+
valueOf = tsEnum => this.units(enumValues(tsEnum));
|
|
84
85
|
enumerated = (...values) => this.units(values);
|
|
85
86
|
instanceOf = ctor => this.node("proto", { proto: ctor }, { prereduced: true });
|
|
86
87
|
match = new InternalMatchParser(this);
|
package/out/type.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ArkErrors, BaseRoot, type BaseParseOptions, type Morph, type Predicate, type RootSchema } from "@ark/schema";
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseParseOptions, type Morph, type Predicate, type RootSchema, type TypeMeta } 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";
|
|
5
4
|
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
|
|
6
5
|
import type { Ark, keywords, type } from "./keywords/keywords.ts";
|
|
7
6
|
import type { MatchParser } from "./match.ts";
|
|
@@ -38,7 +37,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
|
38
37
|
*
|
|
39
38
|
* @example type("string", "|", { foo: "number" })
|
|
40
39
|
*/
|
|
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 "@" ? [
|
|
40
|
+
<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 "@" ? [TypeMeta.MappableInput] : [type.validate<rest[0], $>] : []): r extends infer _ ? _ : never;
|
|
42
41
|
/**
|
|
43
42
|
* An alias of the {@link ArkErrors} class, an instance of which is returned when a {@link Type}
|
|
44
43
|
* is invoked with invalid input.
|
|
@@ -81,6 +80,13 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
|
81
80
|
* @example const argsForm = type('===', 'foo', 'bar', obj)
|
|
82
81
|
*/
|
|
83
82
|
enumerated: EnumeratedTypeParser<$>;
|
|
83
|
+
/**
|
|
84
|
+
* Create a {@link Type} that is satisfied only by one of the Object.values() of the argument passed to this function.
|
|
85
|
+
*
|
|
86
|
+
* ⚠️ For TypeScript enum compatibility, values at numeric keys with corresponding numeric values will not be included.
|
|
87
|
+
* @example const myEnum = type.valueOf(myTsEnum)
|
|
88
|
+
*/
|
|
89
|
+
valueOf: ValueOfTypeParser<$>;
|
|
84
90
|
/**
|
|
85
91
|
* Create a {@link Type} that is satisfied only by a value of a specific class.
|
|
86
92
|
* @example const array = type.instanceOf(Array)
|
|
@@ -96,6 +102,7 @@ export type DeclarationParser<$> = <preinferred>() => {
|
|
|
96
102
|
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
|
|
97
103
|
export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>;
|
|
98
104
|
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
|
|
105
|
+
export type ValueOfTypeParser<$> = <const o extends object>(o: o) => Type<o[keyof o], $>;
|
|
99
106
|
export type DefinitionParser<$> = <const def>(def: type.validate<def, $>) => def;
|
|
100
107
|
export type SchemaParser<$> = (schema: RootSchema, opts?: BaseParseOptions) => Type<unknown, $>;
|
|
101
108
|
export type Type<t = unknown, $ = {}> = instantiateType<t, $>;
|
package/out/type.js
CHANGED
|
@@ -17,7 +17,8 @@ export class InternalTypeParser extends Callable {
|
|
|
17
17
|
keywords: $.ambient,
|
|
18
18
|
unit: $.unit,
|
|
19
19
|
enumerated: $.enumerated,
|
|
20
|
-
instanceOf: $.instanceOf
|
|
20
|
+
instanceOf: $.instanceOf,
|
|
21
|
+
valueOf: $.valueOf
|
|
21
22
|
},
|
|
22
23
|
// also won't be defined during bootstrapping
|
|
23
24
|
$.ambientAttachments);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "2.1.
|
|
3
|
+
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
+
"version": "2.1.10",
|
|
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.45.0",
|
|
38
|
+
"@ark/schema": "0.45.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|