arktype 2.0.0-dev.10 → 2.0.0-dev.12
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/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +1 -1
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +3 -3
- package/out/match.js +1 -1
- package/out/module.d.ts +7 -6
- package/out/module.js +2 -3
- package/out/parser/definition.d.ts +11 -9
- package/out/parser/definition.js +2 -2
- package/out/parser/objectLiteral.d.ts +8 -13
- package/out/parser/objectLiteral.js +20 -23
- package/out/parser/semantic/bounds.d.ts +3 -3
- package/out/parser/semantic/divisor.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +1 -1
- package/out/parser/semantic/validate.d.ts +6 -4
- package/out/parser/string/reduce/dynamic.d.ts +6 -6
- package/out/parser/string/reduce/shared.d.ts +16 -16
- package/out/parser/string/reduce/shared.js +4 -2
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.d.ts +17 -3
- package/out/parser/string/shift/operand/enclosed.js +2 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/unenclosed.d.ts +9 -7
- package/out/parser/string/shift/operand/unenclosed.js +2 -2
- package/out/parser/string/shift/operator/bounds.d.ts +5 -5
- package/out/parser/string/shift/operator/bounds.js +3 -3
- package/out/parser/string/shift/operator/divisor.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/string.d.ts +2 -2
- package/out/parser/tuple.d.ts +11 -11
- package/out/parser/tuple.js +3 -3
- package/out/scope.d.ts +15 -13
- package/out/scope.js +7 -7
- package/out/type.d.ts +4 -4
- package/out/type.js +3 -3
- package/package.json +8 -10
- package/__tests__/array.test.ts +0 -391
- package/__tests__/badDefinitionType.test.ts +0 -58
- package/__tests__/basis.test.ts +0 -50
- package/__tests__/bounds.test.ts +0 -318
- package/__tests__/cast.test.ts +0 -37
- package/__tests__/completions.test.ts +0 -51
- package/__tests__/config.test.ts +0 -96
- package/__tests__/dateLiteral.test.ts +0 -36
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -114
- package/__tests__/enclosed.test.ts +0 -107
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -210
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -313
- package/__tests__/group.test.ts +0 -85
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -126
- package/__tests__/instanceof.test.ts +0 -104
- package/__tests__/intersection.test.ts +0 -108
- package/__tests__/keyTraversal.test.ts +0 -77
- package/__tests__/keyof.test.ts +0 -150
- package/__tests__/keywords.test.ts +0 -214
- package/__tests__/literal.test.ts +0 -90
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -234
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/narrow.test.ts +0 -100
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -442
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/pipe.test.ts +0 -501
- package/__tests__/realWorld.test.ts +0 -63
- package/__tests__/regex.test.ts +0 -68
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -374
- package/__tests__/serialization.test.ts +0 -19
- package/__tests__/string.test.ts +0 -52
- package/__tests__/submodule.test.ts +0 -86
- package/__tests__/this.test.ts +0 -83
- package/__tests__/thunk.test.ts +0 -86
- package/__tests__/traverse.test.ts +0 -141
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/type.test.ts +0 -36
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -136
- package/__tests__/union.test.ts +0 -214
- package/ark.ts +0 -47
- package/generic.ts +0 -69
- package/main.ts +0 -6
- package/match.ts +0 -218
- package/module.ts +0 -15
- package/out/ark.js.map +0 -1
- package/out/generic.js.map +0 -1
- package/out/main.js.map +0 -1
- package/out/match.js.map +0 -1
- package/out/module.js.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/infer.js.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/type.js.map +0 -1
- package/parser/definition.ts +0 -143
- package/parser/generic.ts +0 -66
- package/parser/objectLiteral.ts +0 -233
- package/parser/semantic/bounds.ts +0 -62
- package/parser/semantic/divisor.ts +0 -11
- package/parser/semantic/infer.ts +0 -141
- package/parser/semantic/utils.ts +0 -15
- package/parser/semantic/validate.ts +0 -117
- package/parser/string/reduce/dynamic.ts +0 -208
- package/parser/string/reduce/shared.ts +0 -99
- package/parser/string/reduce/static.ts +0 -296
- package/parser/string/shift/operand/date.ts +0 -55
- package/parser/string/shift/operand/enclosed.ts +0 -123
- package/parser/string/shift/operand/genericArgs.ts +0 -128
- package/parser/string/shift/operand/operand.ts +0 -42
- package/parser/string/shift/operand/unenclosed.ts +0 -217
- package/parser/string/shift/operator/bounds.ts +0 -270
- package/parser/string/shift/operator/divisor.ts +0 -33
- package/parser/string/shift/operator/operator.ts +0 -71
- package/parser/string/shift/scanner.ts +0 -210
- package/parser/string/string.ts +0 -85
- package/parser/tuple.ts +0 -542
- package/scope.ts +0 -291
- package/type.ts +0 -266
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BaseRoot, type BoundKind, type LimitLiteral } from "@arktype/schema";
|
|
2
2
|
import { type keySet } from "@arktype/util";
|
|
3
3
|
import type { astToString } from "../../../semantic/utils.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.js";
|
|
@@ -17,13 +17,13 @@ export type ComparatorStartChar = Comparator extends `${infer char}${string}` ?
|
|
|
17
17
|
export declare const comparatorStartChars: keySet<ComparatorStartChar>;
|
|
18
18
|
declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) => Comparator;
|
|
19
19
|
type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends OneCharComparator ? [start, unscanned] : state.error<singleEqualsMessage>;
|
|
20
|
-
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) =>
|
|
21
|
-
export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root:
|
|
20
|
+
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
21
|
+
export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
|
|
22
22
|
export declare const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
|
|
23
23
|
type singleEqualsMessage = typeof singleEqualsMessage;
|
|
24
24
|
export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => void;
|
|
25
25
|
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends `${infer limit extends LimitLiteral}` ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : state.error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : state.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
|
|
26
|
-
export declare const writeInvalidLimitMessage: <comparator extends "
|
|
27
|
-
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was
|
|
26
|
+
export declare const writeInvalidLimitMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==", limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
27
|
+
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
28
28
|
export type BoundExpressionKind = "left" | "right";
|
|
29
29
|
export {};
|
|
@@ -58,7 +58,7 @@ export const getBoundKinds = (comparator, limit, root, boundKind) => {
|
|
|
58
58
|
return throwParseError(writeUnboundableMessage(root.expression));
|
|
59
59
|
};
|
|
60
60
|
export const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
|
|
61
|
-
const
|
|
61
|
+
const openLeftBoundToRoot = (leftBound) => ({
|
|
62
62
|
rule: isDateLiteral(leftBound.limit) ?
|
|
63
63
|
extractDateLiteralSource(leftBound.limit)
|
|
64
64
|
: leftBound.limit,
|
|
@@ -89,7 +89,7 @@ export const parseRightBound = (s, comparator) => {
|
|
|
89
89
|
if (!isKeyOf(comparator, maxComparators))
|
|
90
90
|
return s.error(writeUnpairableComparatorMessage(comparator));
|
|
91
91
|
const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
|
|
92
|
-
s.constrainRoot(lowerBoundKind[0],
|
|
92
|
+
s.constrainRoot(lowerBoundKind[0], openLeftBoundToRoot(s.branches.leftBound));
|
|
93
93
|
s.branches.leftBound = null;
|
|
94
94
|
};
|
|
95
|
-
export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was
|
|
95
|
+
export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
@@ -3,5 +3,5 @@ import type { StaticState, state } from "../../reduce/static.js";
|
|
|
3
3
|
import type { Scanner } from "../scanner.js";
|
|
4
4
|
export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
|
|
5
5
|
export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
6
|
-
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) =>
|
|
6
|
+
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
7
7
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -5,7 +5,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.js";
|
|
|
5
5
|
import { parseDivisor } from "./divisor.js";
|
|
6
6
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
7
7
|
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
8
|
-
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) =>
|
|
8
|
+
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
9
9
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
10
10
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
11
11
|
type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot } from "@arktype/schema";
|
|
2
2
|
import { type ErrorMessage } from "@arktype/util";
|
|
3
3
|
import type { inferAstRoot } from "../semantic/infer.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
|
|
@@ -16,7 +16,7 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? def
|
|
|
16
16
|
] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
|
|
17
17
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
18
18
|
export type BaseCompletions<$, args, otherSuggestions extends string = never> = (keyof $ & string) | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
19
|
-
export declare const fullStringParse: (s: DynamicState) =>
|
|
19
|
+
export declare const fullStringParse: (s: DynamicState) => BaseRoot;
|
|
20
20
|
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
|
|
21
21
|
export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
|
|
22
22
|
export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
|
package/out/parser/tuple.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { type BaseMeta, type
|
|
1
|
+
import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferNarrow } from "@arktype/schema";
|
|
2
2
|
import { type Constructor, type Domain, type ErrorMessage, type array, type conform, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
5
5
|
import type { InfixOperator, PostfixExpression } from "./semantic/infer.js";
|
|
6
6
|
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
|
|
7
7
|
import type { BaseCompletions } from "./string/string.js";
|
|
8
|
-
export declare const parseTuple: (def: array, ctx: ParseContext) =>
|
|
9
|
-
export declare const parseTupleLiteral: (def: array, ctx: ParseContext) =>
|
|
8
|
+
export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
|
|
9
|
+
export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
|
|
10
10
|
type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
|
|
11
11
|
export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
|
|
12
12
|
def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
|
|
13
13
|
def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
|
|
14
14
|
] : validateTupleLiteral<def, $, args>;
|
|
15
|
-
export type validateTupleLiteral<def extends array, $, args> =
|
|
16
|
-
type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args>["inferred"];
|
|
15
|
+
export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
|
|
16
|
+
type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
|
|
17
17
|
type SequenceParseState = {
|
|
18
18
|
unscanned: array;
|
|
19
19
|
inferred: array;
|
|
@@ -86,8 +86,8 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
|
|
|
86
86
|
] : [])
|
|
87
87
|
];
|
|
88
88
|
}, $, args> : s;
|
|
89
|
-
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) =>
|
|
90
|
-
type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? `(was ${operand})` : ""}`;
|
|
89
|
+
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
|
|
90
|
+
type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
|
|
91
91
|
export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
92
92
|
type multipleVariadicMessage = typeof multipleVariadicMesage;
|
|
93
93
|
export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
@@ -112,8 +112,8 @@ export type UnparsedTupleExpressionInput = {
|
|
|
112
112
|
export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
|
|
113
113
|
export declare const parseKeyOfTuple: PrefixParser<"keyof">;
|
|
114
114
|
export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
|
|
115
|
-
export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) =>
|
|
116
|
-
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) =>
|
|
115
|
+
export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => BaseRoot;
|
|
116
|
+
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => BaseRoot;
|
|
117
117
|
export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
118
118
|
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
119
119
|
export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
@@ -121,10 +121,10 @@ export type TuplePostfixOperator = "[]";
|
|
|
121
121
|
export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
|
|
122
122
|
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
123
123
|
export declare const parseMorphTuple: PostfixParser<"=>">;
|
|
124
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) =>
|
|
124
|
+
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
125
125
|
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<inferMorphOut<morph>> : never;
|
|
126
126
|
export declare const parseNarrowTuple: PostfixParser<":">;
|
|
127
127
|
export type IndexZeroOperator = "keyof" | "instanceof" | "===";
|
|
128
128
|
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
129
|
-
export declare const writeInvalidConstructorMessage: <actual extends Domain |
|
|
129
|
+
export declare const writeInvalidConstructorMessage: <actual extends Domain | keyof import("@arktype/util").builtinConstructors>(actual: actual) => string;
|
|
130
130
|
export {};
|
package/out/parser/tuple.js
CHANGED
|
@@ -42,7 +42,7 @@ export const parseTupleLiteral = (def, ctx) => {
|
|
|
42
42
|
const appendElement = (base, kind, element) => {
|
|
43
43
|
switch (kind) {
|
|
44
44
|
case "required":
|
|
45
|
-
if (base.
|
|
45
|
+
if (base.optionals)
|
|
46
46
|
// e.g. [string?, number]
|
|
47
47
|
return throwParseError(requiredPostOptionalMessage);
|
|
48
48
|
if (base.variadic) {
|
|
@@ -59,7 +59,7 @@ const appendElement = (base, kind, element) => {
|
|
|
59
59
|
// e.g. [...string[], number?]
|
|
60
60
|
return throwParseError(optionalPostVariadicMessage);
|
|
61
61
|
// e.g. [string, number?]
|
|
62
|
-
base.
|
|
62
|
+
base.optionals = append(base.optionals, element);
|
|
63
63
|
return base;
|
|
64
64
|
case "variadic":
|
|
65
65
|
// e.g. [...string[], number, ...string[]]
|
|
@@ -87,7 +87,7 @@ const appendSpreadBranch = (base, branch) => {
|
|
|
87
87
|
return appendElement(base, "variadic", tsKeywords.unknown);
|
|
88
88
|
}
|
|
89
89
|
spread.prefix.forEach(node => appendElement(base, "required", node));
|
|
90
|
-
spread.
|
|
90
|
+
spread.optionals.forEach(node => appendElement(base, "optional", node));
|
|
91
91
|
spread.variadic && appendElement(base, "variadic", spread.variadic);
|
|
92
92
|
spread.postfix.forEach(node => appendElement(base, "required", node));
|
|
93
93
|
return base;
|
package/out/scope.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type ArkConfig, type
|
|
2
|
-
import { type
|
|
1
|
+
import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@arktype/schema";
|
|
2
|
+
import { type anyOrNever, type keyError, type nominal, type show } from "@arktype/util";
|
|
3
3
|
import type { type } from "./ark.js";
|
|
4
4
|
import { Generic } from "./generic.js";
|
|
5
5
|
import { type MatchParser } from "./match.js";
|
|
6
6
|
import type { Module } from "./module.js";
|
|
7
7
|
import { type inferDefinition, type validateDefinition } from "./parser/definition.js";
|
|
8
|
-
import { type GenericDeclaration, type GenericParamsParseError
|
|
9
|
-
import { type DeclarationParser, type DefinitionParser,
|
|
8
|
+
import { parseGenericParams, type GenericDeclaration, type GenericParamsParseError } from "./parser/generic.js";
|
|
9
|
+
import { _TypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.js";
|
|
10
10
|
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<inferBootstrapped<bootstrapAliases<def>>>;
|
|
11
11
|
type validateScope<def> = {
|
|
12
12
|
[k in keyof def]: k extends symbol ? unknown : parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? keyError<writeDuplicateAliasError<name>> : validateDefinition<def[k], ambient & bootstrapAliases<def>, {}> : parseScopeKey<k>["params"] extends GenericParamsParseError ? parseScopeKey<k>["params"][0] : validateDefinition<def[k], ambient & bootstrapAliases<def>, {
|
|
@@ -32,7 +32,9 @@ type inferBootstrapped<$> = show<{
|
|
|
32
32
|
}>;
|
|
33
33
|
type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
|
|
34
34
|
type extractGenericParameters<k> = k extends GenericDeclaration<string, infer params> ? params : never;
|
|
35
|
-
export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ?
|
|
35
|
+
export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? [
|
|
36
|
+
resolution
|
|
37
|
+
] extends [anyOrNever] ? resolution : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution : never;
|
|
36
38
|
export type moduleKeyOf<$> = {
|
|
37
39
|
[k in keyof $]: $[k] extends {
|
|
38
40
|
[arkKind]: "module";
|
|
@@ -41,10 +43,10 @@ export type moduleKeyOf<$> = {
|
|
|
41
43
|
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] extends type.cast<infer t> ? t : never : never : never;
|
|
42
44
|
export interface ParseContext {
|
|
43
45
|
$: RawScope;
|
|
44
|
-
args?: Record<string,
|
|
46
|
+
args?: Record<string, UnknownRoot>;
|
|
45
47
|
}
|
|
46
48
|
export declare const scope: ScopeParser;
|
|
47
|
-
export interface Scope<$ = any> extends
|
|
49
|
+
export interface Scope<$ = any> extends RootScope<$> {
|
|
48
50
|
type: TypeParser<$>;
|
|
49
51
|
match: MatchParser<$>;
|
|
50
52
|
declare: DeclarationParser<$>;
|
|
@@ -52,19 +54,19 @@ export interface Scope<$ = any> extends SchemaScope<$> {
|
|
|
52
54
|
import<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredImportContext<$, names>>>;
|
|
53
55
|
export<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredExportContext<$, names>>>;
|
|
54
56
|
}
|
|
55
|
-
export declare class RawScope<$ extends
|
|
57
|
+
export declare class RawScope<$ extends RawRootResolutions = RawRootResolutions> extends RawRootScope<$> {
|
|
56
58
|
private parseCache;
|
|
57
59
|
constructor(def: Record<string, unknown>, config?: ArkConfig);
|
|
58
|
-
type:
|
|
60
|
+
type: _TypeParser;
|
|
59
61
|
match: MatchParser<$>;
|
|
60
62
|
declare: () => {
|
|
61
|
-
type:
|
|
63
|
+
type: _TypeParser;
|
|
62
64
|
};
|
|
63
65
|
define: (def: unknown) => unknown;
|
|
64
66
|
preparseRoot(def: unknown): unknown;
|
|
65
|
-
parseRoot(def: unknown):
|
|
66
|
-
parse(def: unknown, ctx: ParseContext):
|
|
67
|
-
parseString(def: string, ctx: ParseContext):
|
|
67
|
+
parseRoot(def: unknown): BaseRoot;
|
|
68
|
+
parse(def: unknown, ctx: ParseContext): BaseRoot;
|
|
69
|
+
parseString(def: string, ctx: ParseContext): BaseRoot;
|
|
68
70
|
}
|
|
69
71
|
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
|
|
70
72
|
export type ParsedScopeKey = {
|
package/out/scope.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawRootScope, hasArkKind } from "@arktype/schema";
|
|
2
2
|
import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
|
|
3
3
|
import { Generic } from "./generic.js";
|
|
4
4
|
import { createMatchParser } from "./match.js";
|
|
@@ -6,9 +6,9 @@ import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.
|
|
|
6
6
|
import { parseGenericParams } from "./parser/generic.js";
|
|
7
7
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
8
8
|
import { fullStringParse } from "./parser/string/string.js";
|
|
9
|
-
import {
|
|
9
|
+
import { _TypeParser } from "./type.js";
|
|
10
10
|
export const scope = ((def, config = {}) => new RawScope(def, config));
|
|
11
|
-
export class RawScope extends
|
|
11
|
+
export class RawScope extends RawRootScope {
|
|
12
12
|
parseCache = {};
|
|
13
13
|
constructor(def, config) {
|
|
14
14
|
const aliases = {};
|
|
@@ -22,7 +22,7 @@ export class RawScope extends RawSchemaScope {
|
|
|
22
22
|
}
|
|
23
23
|
super(aliases, config);
|
|
24
24
|
}
|
|
25
|
-
type = new
|
|
25
|
+
type = new _TypeParser(this);
|
|
26
26
|
match = createMatchParser(this);
|
|
27
27
|
declare = (() => ({
|
|
28
28
|
type: this.type
|
|
@@ -34,7 +34,7 @@ export class RawScope extends RawSchemaScope {
|
|
|
34
34
|
return def;
|
|
35
35
|
}
|
|
36
36
|
parseRoot(def) {
|
|
37
|
-
// args: { this: {} as
|
|
37
|
+
// args: { this: {} as RawRoot },
|
|
38
38
|
return this.parse(def, {
|
|
39
39
|
$: this,
|
|
40
40
|
args: {}
|
|
@@ -58,9 +58,9 @@ export class RawScope extends RawSchemaScope {
|
|
|
58
58
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
59
59
|
}
|
|
60
60
|
parseString(def, ctx) {
|
|
61
|
-
return (this.
|
|
61
|
+
return (this.maybeResolveRoot(def) ??
|
|
62
62
|
((def.endsWith("[]") &&
|
|
63
|
-
this.
|
|
63
|
+
this.maybeResolveRoot(def.slice(0, -2))?.array()) ||
|
|
64
64
|
fullStringParse(new DynamicState(def, ctx))));
|
|
65
65
|
}
|
|
66
66
|
}
|
package/out/type.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArkErrors, type BaseMeta, type
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type InnerRoot, type Morph, type NodeSchema, type Out, type Predicate, type PrimitiveConstraintKind, type Root, 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
2
|
import { Callable, type Constructor, type array, type conform } from "@arktype/util";
|
|
3
3
|
import { Generic, type validateParameterString } from "./generic.js";
|
|
4
4
|
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
|
|
@@ -15,13 +15,13 @@ export interface TypeParser<$> extends TypeParserAttachments {
|
|
|
15
15
|
[param in parseGenericParams<params>[number]]: unknown;
|
|
16
16
|
}>): Generic<parseGenericParams<params>, def, $>;
|
|
17
17
|
}
|
|
18
|
-
export declare class
|
|
18
|
+
export declare class _TypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
|
|
19
19
|
constructor($: RawScope);
|
|
20
20
|
}
|
|
21
21
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
22
22
|
type: <def>(def: validateDeclared<preinferred, def, $ & ambient, bindThis<def>>) => Type<preinferred, $>;
|
|
23
23
|
};
|
|
24
|
-
declare class _Type<t = unknown, $ = any> extends
|
|
24
|
+
declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> implements internalImplementationOf<Root> {
|
|
25
25
|
$: Scope<$>;
|
|
26
26
|
get in(): Type<this["tIn"], $>;
|
|
27
27
|
get out(): Type<this["tOut"], $>;
|
|
@@ -42,7 +42,7 @@ declare class _Type<t = unknown, $ = any> extends BaseRoot<t, $> implements inte
|
|
|
42
42
|
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
43
43
|
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
44
44
|
extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
45
|
-
constrain<kind extends PrimitiveConstraintKind, const def extends
|
|
45
|
+
constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
|
|
46
46
|
}
|
|
47
47
|
export interface Type<
|
|
48
48
|
/** @ts-expect-error allow instantiation assignment to the base type */
|
package/out/type.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ArkErrors,
|
|
1
|
+
import { ArkErrors, BaseRoot } from "@arktype/schema";
|
|
2
2
|
import { Callable } from "@arktype/util";
|
|
3
3
|
import { Generic } from "./generic.js";
|
|
4
4
|
import { parseGenericParams } from "./parser/generic.js";
|
|
5
5
|
const typeParserAttachments = Object.freeze({
|
|
6
6
|
errors: ArkErrors
|
|
7
7
|
});
|
|
8
|
-
export class
|
|
8
|
+
export class _TypeParser extends Callable {
|
|
9
9
|
constructor($) {
|
|
10
10
|
super((...args) => {
|
|
11
11
|
if (args.length === 1) {
|
|
@@ -30,4 +30,4 @@ export class RawTypeParser extends Callable {
|
|
|
30
30
|
}, { bind: $, attach: typeParserAttachments });
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
export const Type =
|
|
33
|
+
export const Type = BaseRoot;
|
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.
|
|
4
|
+
"version": "2.0.0-dev.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"url": "https://github.com/arktypeio/arktype.git"
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
|
-
"main": "./out/
|
|
17
|
-
"types": "./out/
|
|
16
|
+
"main": "./out/api.js",
|
|
17
|
+
"types": "./out/api.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./out/
|
|
21
|
-
"default": "./out/
|
|
20
|
+
"types": "./out/api.d.ts",
|
|
21
|
+
"default": "./out/api.js"
|
|
22
22
|
},
|
|
23
23
|
"./config": {
|
|
24
24
|
"types": "./out/config.d.ts",
|
|
@@ -29,16 +29,14 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
|
-
"out"
|
|
33
|
-
"!__tests__",
|
|
34
|
-
"**/*.ts"
|
|
32
|
+
"out"
|
|
35
33
|
],
|
|
36
34
|
"scripts": {
|
|
37
35
|
"build": "tsx ../repo/build.ts",
|
|
38
36
|
"test": "tsx ../repo/testPackage.ts"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@arktype/util": "0.0.
|
|
42
|
-
"@arktype/schema": "0.1.
|
|
39
|
+
"@arktype/util": "0.0.41",
|
|
40
|
+
"@arktype/schema": "0.1.4"
|
|
43
41
|
}
|
|
44
42
|
}
|