arktype 2.1.8 → 2.1.9
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/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 +7 -8
- package/out/parser/tupleExpressions.js +5 -8
- package/package.json +3 -3
|
@@ -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 ']'`;
|
|
@@ -30,8 +30,7 @@ export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
|
30
30
|
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
31
31
|
export type ArgTwoOperator = Exclude<IndexOneOperator, "?" | "=">;
|
|
32
32
|
export declare const parseMorphTuple: IndexOneParser<"=>">;
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>" | "|>", value: unknown) => string;
|
|
33
|
+
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
35
34
|
export type parseTo<inDef, outDef, $, args> = inferPipe<inferDefinition<inDef, $, args>, inferDefinition<outDef, $, args>>;
|
|
36
35
|
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
36
|
export declare const parseNarrowTuple: IndexOneParser<":">;
|
|
@@ -43,22 +42,22 @@ declare const postfixParsers: {
|
|
|
43
42
|
};
|
|
44
43
|
export type TuplePostfixOperator = keyof typeof postfixParsers;
|
|
45
44
|
declare const infixParsers: {
|
|
46
|
-
"=": IndexOneParser<"=">;
|
|
47
|
-
"|": IndexOneParser<"|">;
|
|
48
45
|
"&": IndexOneParser<"&">;
|
|
46
|
+
"|": IndexOneParser<"|">;
|
|
47
|
+
"|>": IndexOneParser<"|>">;
|
|
48
|
+
"=": IndexOneParser<"=">;
|
|
49
49
|
":": IndexOneParser<":">;
|
|
50
50
|
"=>": IndexOneParser<"=>">;
|
|
51
|
-
"|>": IndexOneParser<"|>">;
|
|
52
51
|
"@": IndexOneParser<"@">;
|
|
53
52
|
};
|
|
54
53
|
export type TupleInfixOperator = keyof typeof infixParsers;
|
|
55
54
|
declare const indexOneParsers: {
|
|
56
|
-
"=": IndexOneParser<"=">;
|
|
57
|
-
"|": IndexOneParser<"|">;
|
|
58
55
|
"&": IndexOneParser<"&">;
|
|
56
|
+
"|": IndexOneParser<"|">;
|
|
57
|
+
"|>": IndexOneParser<"|>">;
|
|
58
|
+
"=": IndexOneParser<"=">;
|
|
59
59
|
":": IndexOneParser<":">;
|
|
60
60
|
"=>": IndexOneParser<"=>">;
|
|
61
|
-
"|>": IndexOneParser<"|>">;
|
|
62
61
|
"@": IndexOneParser<"@">;
|
|
63
62
|
"?": IndexOneParser<"?">;
|
|
64
63
|
"[]": 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") {
|
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "Optimized runtime validation for TypeScript syntax",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.9",
|
|
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.44.
|
|
38
|
-
"@ark/schema": "0.44.
|
|
37
|
+
"@ark/util": "0.44.4",
|
|
38
|
+
"@ark/schema": "0.44.4"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|