arktype 2.0.0-rc.4 → 2.0.0-rc.6
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/generic.d.ts +34 -36
- package/out/generic.js +1 -1
- package/out/index.d.ts +2 -2
- package/out/index.js +1 -1
- package/out/intersect.d.ts +2 -4
- package/out/keywords/ark.d.ts +20 -3
- package/out/keywords/ark.js +3 -2
- package/out/keywords/ast.d.ts +97 -102
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +1 -1
- package/out/keywords/constructors/Array.js +4 -4
- package/out/keywords/constructors/Date.d.ts +31 -0
- package/out/keywords/constructors/FormData.d.ts +1 -1
- package/out/keywords/constructors/FormData.js +3 -3
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/number.d.ts +31 -6
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/capitalize.d.ts +1 -1
- package/out/keywords/string/capitalize.js +3 -3
- package/out/keywords/string/date.d.ts +3 -7
- package/out/keywords/string/date.js +11 -11
- package/out/keywords/string/integer.d.ts +1 -1
- package/out/keywords/string/integer.js +5 -5
- package/out/keywords/string/ip.d.ts +1 -1
- package/out/keywords/string/ip.js +3 -3
- package/out/keywords/string/json.d.ts +1 -1
- package/out/keywords/string/json.js +4 -4
- package/out/keywords/string/lower.d.ts +1 -1
- package/out/keywords/string/lower.js +3 -3
- package/out/keywords/string/normalize.d.ts +14 -18
- package/out/keywords/string/normalize.js +11 -11
- package/out/keywords/string/numeric.d.ts +1 -1
- package/out/keywords/string/numeric.js +5 -5
- package/out/keywords/string/string.d.ts +18 -22
- package/out/keywords/string/string.js +3 -3
- package/out/keywords/string/trim.d.ts +1 -1
- package/out/keywords/string/trim.js +3 -3
- package/out/keywords/string/upper.d.ts +1 -1
- package/out/keywords/string/upper.js +3 -3
- package/out/keywords/string/url.d.ts +1 -1
- package/out/keywords/string/url.js +5 -5
- package/out/keywords/string/uuid.d.ts +2 -2
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +11 -0
- package/out/keywords/ts.js +7 -3
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +87 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/morph.d.ts +13 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/{subtypes → methods}/object.d.ts +1 -2
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/methods/validator.js +1 -0
- package/out/module.d.ts +2 -2
- package/out/parser/objectLiteral.d.ts +5 -30
- package/out/parser/objectLiteral.js +18 -21
- package/out/parser/semantic/default.d.ts +3 -4
- package/out/parser/semantic/default.js +1 -1
- package/out/parser/semantic/infer.d.ts +8 -7
- package/out/parser/semantic/validate.d.ts +2 -2
- package/out/parser/string/reduce/dynamic.d.ts +1 -2
- package/out/parser/string/reduce/dynamic.js +2 -4
- package/out/parser/string/shift/operand/date.d.ts +2 -0
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -1
- package/out/parser/string/shift/operand/enclosed.js +7 -3
- package/out/parser/string/shift/operator/default.d.ts +2 -5
- package/out/parser/string/shift/operator/default.js +1 -6
- package/out/parser/string/string.d.ts +2 -3
- package/out/parser/tuple.d.ts +6 -5
- package/out/parser/tuple.js +13 -6
- package/out/scope.d.ts +9 -5
- package/out/scope.js +12 -8
- package/out/type.d.ts +13 -12
- package/out/type.js +4 -1
- package/package.json +3 -3
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/morph.d.ts +0 -13
- /package/out/{subtypes/array.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes/base.js → methods/array.js} +0 -0
- /package/out/{subtypes/date.js → methods/base.js} +0 -0
- /package/out/{subtypes/instantiate.js → methods/date.js} +0 -0
- /package/out/{subtypes → methods}/instantiate.d.ts +0 -0
- /package/out/{subtypes/morph.js → methods/instantiate.js} +0 -0
- /package/out/{subtypes/number.js → methods/morph.js} +0 -0
- /package/out/{subtypes/object.js → methods/number.js} +0 -0
- /package/out/{subtypes/string.js → methods/object.js} +0 -0
- /package/out/{subtypes/validator.js → methods/string.js} +0 -0
|
@@ -11,7 +11,7 @@ import type { validateDivisor } from "./divisor.ts";
|
|
|
11
11
|
import type { DefAst, GenericInstantiationAst, inferAstRoot, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
12
12
|
import type { validateKeyof } from "./keyof.ts";
|
|
13
13
|
import type { astToString } from "./utils.ts";
|
|
14
|
-
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> :
|
|
14
|
+
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
15
15
|
ast: ast;
|
|
16
16
|
};
|
|
17
17
|
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
@@ -20,7 +20,7 @@ export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateD
|
|
|
20
20
|
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
21
21
|
type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
|
|
22
22
|
[arkKind]: "module";
|
|
23
|
-
} ? "
|
|
23
|
+
} ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
|
|
24
24
|
export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
|
|
25
25
|
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends infer e extends ErrorMessage ? e : validateAst<ast[2], $, args> extends infer e extends ErrorMessage ? e : undefined;
|
|
26
26
|
export {};
|
|
@@ -19,8 +19,7 @@ export declare class DynamicState {
|
|
|
19
19
|
groups: BranchState[];
|
|
20
20
|
scanner: Scanner;
|
|
21
21
|
ctx: ParseContext;
|
|
22
|
-
|
|
23
|
-
constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
|
|
22
|
+
constructor(scanner: Scanner, ctx: ParseContext);
|
|
24
23
|
error(message: string): never;
|
|
25
24
|
hasRoot(): this is DynamicStateWithRoot;
|
|
26
25
|
setRoot(root: BaseRoot): void;
|
|
@@ -16,11 +16,9 @@ export class DynamicState {
|
|
|
16
16
|
groups = [];
|
|
17
17
|
scanner;
|
|
18
18
|
ctx;
|
|
19
|
-
|
|
20
|
-
constructor(scanner, ctx, defaultable) {
|
|
19
|
+
constructor(scanner, ctx) {
|
|
21
20
|
this.scanner = scanner;
|
|
22
21
|
this.ctx = ctx;
|
|
23
|
-
this.defaultable = defaultable;
|
|
24
22
|
}
|
|
25
23
|
error(message) {
|
|
26
24
|
return throwParseError(message);
|
|
@@ -103,7 +101,7 @@ export class DynamicState {
|
|
|
103
101
|
this.root = undefined;
|
|
104
102
|
}
|
|
105
103
|
parseUntilFinalizer() {
|
|
106
|
-
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx
|
|
104
|
+
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx));
|
|
107
105
|
}
|
|
108
106
|
parseOperator() {
|
|
109
107
|
return parseOperator(this);
|
|
@@ -2,8 +2,10 @@ import type { DateLiteral } from "../../../../keywords/ast.ts";
|
|
|
2
2
|
export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
|
|
3
3
|
export declare const isValidDate: (d: Date) => boolean;
|
|
4
4
|
export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
|
|
5
|
+
type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
|
|
5
6
|
export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
|
|
6
7
|
export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
|
|
7
8
|
export type DateInput = ConstructorParameters<typeof Date>[0];
|
|
8
9
|
export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
|
|
9
10
|
export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
|
|
11
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { string } from "../../../../keywords/ast.ts";
|
|
2
|
+
import type { Date } from "../../../../keywords/constructors/Date.ts";
|
|
2
3
|
import type { InferredAst } from "../../../semantic/infer.ts";
|
|
3
4
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
4
5
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isKeyOf } from "@ark/util";
|
|
1
|
+
import { isKeyOf, throwParseError } from "@ark/util";
|
|
2
2
|
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
3
3
|
export const parseEnclosed = (s, enclosing) => {
|
|
4
4
|
const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
|
|
@@ -7,8 +7,12 @@ export const parseEnclosed = (s, enclosing) => {
|
|
|
7
7
|
// Shift the scanner one additional time for the second enclosing token
|
|
8
8
|
s.scanner.shift();
|
|
9
9
|
if (enclosing === "/") {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
try {
|
|
11
|
+
new RegExp(enclosed);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
throwParseError(String(e));
|
|
15
|
+
}
|
|
12
16
|
s.root = s.ctx.$.node("intersection", {
|
|
13
17
|
domain: "string",
|
|
14
18
|
pattern: enclosed
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { BaseRoot } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
|
|
3
3
|
import type { DateLiteral } from "../../../../keywords/ast.ts";
|
|
4
4
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
5
5
|
import type { StringLiteral } from "../operand/enclosed.ts";
|
|
6
6
|
type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
|
|
7
7
|
export type UnitLiteral = StringLiteral | BigintLiteral | NumberLiteral | DateLiteral | UnitLiteralKeyword;
|
|
8
|
-
export
|
|
9
|
-
export declare const parseDefault: (s: DynamicStateWithRoot) => ParsedDefault;
|
|
8
|
+
export declare const parseDefault: (s: DynamicStateWithRoot) => BaseRoot;
|
|
10
9
|
export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultValue extends UnitLiteral ? [
|
|
11
10
|
root,
|
|
12
11
|
"=",
|
|
@@ -14,6 +13,4 @@ export type parseDefault<root, unscanned extends string> = trim<unscanned> exten
|
|
|
14
13
|
] : ErrorMessage<writeNonLiteralDefaultMessage<trim<unscanned>>>;
|
|
15
14
|
export declare const writeNonLiteralDefaultMessage: <defaultDef extends string>(defaultDef: defaultDef) => writeNonLiteralDefaultMessage<defaultDef>;
|
|
16
15
|
export type writeNonLiteralDefaultMessage<defaultDef extends string> = `Default value '${defaultDef}' must a literal value`;
|
|
17
|
-
export declare const shallowDefaultMessage = "Default values must be specified on objects like { isAdmin: 'boolean = false' }";
|
|
18
|
-
export type shallowDefaultMessage = typeof shallowDefaultMessage;
|
|
19
16
|
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { throwParseError } from "@ark/util";
|
|
2
1
|
export const parseDefault = (s) => {
|
|
3
|
-
if (!s.defaultable)
|
|
4
|
-
return throwParseError(shallowDefaultMessage);
|
|
5
2
|
// store the node that will be bounded
|
|
6
3
|
const baseNode = s.unsetRoot();
|
|
7
4
|
s.parseOperand();
|
|
@@ -10,8 +7,6 @@ export const parseDefault = (s) => {
|
|
|
10
7
|
// token from which it was parsed
|
|
11
8
|
if (!defaultNode.hasKind("unit"))
|
|
12
9
|
return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
|
|
13
|
-
|
|
14
|
-
return [baseNode, "=", defaultNode.unit];
|
|
10
|
+
return baseNode.default(defaultNode.unit);
|
|
15
11
|
};
|
|
16
12
|
export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
|
|
17
|
-
export const shallowDefaultMessage = `Default values must be specified on objects like { isAdmin: 'boolean = false' }`;
|
|
@@ -7,7 +7,7 @@ import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.ts";
|
|
|
7
7
|
import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
|
|
8
8
|
import type { state, StaticState } from "./reduce/static.ts";
|
|
9
9
|
import type { parseOperand } from "./shift/operand/operand.ts";
|
|
10
|
-
import { parseDefault
|
|
10
|
+
import { parseDefault } from "./shift/operator/default.ts";
|
|
11
11
|
import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
|
|
12
12
|
/**
|
|
13
13
|
* Try to parse the definition from right to left using the most common syntax.
|
|
@@ -19,8 +19,7 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? res
|
|
|
19
19
|
] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
|
|
20
20
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
21
21
|
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
22
|
-
export
|
|
23
|
-
export declare const fullStringParse: (s: DynamicState) => StringParseResult;
|
|
22
|
+
export declare const fullStringParse: (s: DynamicState) => BaseRoot;
|
|
24
23
|
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
|
|
25
24
|
export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
|
|
26
25
|
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,7 +1,8 @@
|
|
|
1
1
|
import { type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
|
|
2
2
|
import { type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
|
|
3
3
|
import type { inferIntersection } from "../intersect.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { type } from "../keywords/ark.ts";
|
|
5
|
+
import type { Default, distill, inferMorphOut, inferPredicate, Out } from "../keywords/ast.ts";
|
|
5
6
|
import type { ParseContext } from "../scope.ts";
|
|
6
7
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
7
8
|
import type { InfixOperator, PostfixExpression } from "./semantic/infer.ts";
|
|
@@ -99,13 +100,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
|
|
|
99
100
|
export declare const spreadOptionalMessage = "A spread element cannot be optional";
|
|
100
101
|
type spreadOptionalMessage = typeof optionalPostVariadicMessage;
|
|
101
102
|
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
|
|
102
|
-
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
|
|
103
|
+
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? (In?: inferDefinition<def[0], $, args>) => Default<def[2]> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
|
|
103
104
|
export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
|
|
104
105
|
export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]"]>;
|
|
105
106
|
export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
|
|
106
107
|
validateDefinition<def[0], $, args>,
|
|
107
108
|
def[1],
|
|
108
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<
|
|
109
|
+
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 "@" ? MetaSchema : def[1] extends "=" ? type.infer.Out<def[0], $, args> : validateDefinition<def[2], $, args>
|
|
109
110
|
];
|
|
110
111
|
export type UnparsedTupleExpressionInput = {
|
|
111
112
|
instanceof: Constructor;
|
|
@@ -120,11 +121,11 @@ export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
|
120
121
|
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
121
122
|
export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
122
123
|
export type TuplePostfixOperator = "[]";
|
|
123
|
-
export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
|
|
124
|
+
export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
|
|
124
125
|
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
125
126
|
export declare const parseMorphTuple: PostfixParser<"=>">;
|
|
126
127
|
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
127
|
-
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In:
|
|
128
|
+
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.brandable.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
128
129
|
export declare const parseNarrowTuple: PostfixParser<":">;
|
|
129
130
|
export type IndexZeroOperator = "keyof" | "instanceof" | "===";
|
|
130
131
|
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
package/out/parser/tuple.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
|
|
2
|
-
import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
2
|
+
import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
3
|
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
|
|
4
4
|
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
|
|
5
5
|
export const parseTupleLiteral = (def, ctx) => {
|
|
@@ -34,10 +34,15 @@ export const parseTupleLiteral = (def, ctx) => {
|
|
|
34
34
|
sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return ctx.$.internal.rootNode(sequences.map(sequence => (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
return ctx.$.internal.rootNode(sequences.map(sequence => isEmptyObject(sequence) ?
|
|
38
|
+
{
|
|
39
|
+
proto: Array,
|
|
40
|
+
exactLength: 0
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
proto: Array,
|
|
44
|
+
sequence
|
|
45
|
+
}));
|
|
41
46
|
};
|
|
42
47
|
const appendElement = (base, kind, element) => {
|
|
43
48
|
switch (kind) {
|
|
@@ -129,13 +134,15 @@ export const parseNarrowTuple = (def, ctx) => {
|
|
|
129
134
|
return ctx.$.parse(def[0], ctx).constrain("predicate", def[2]);
|
|
130
135
|
};
|
|
131
136
|
const parseAttributeTuple = (def, ctx) => ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2]);
|
|
137
|
+
const parseDefaultTuple = (def, ctx) => ctx.$.parse(def[0], ctx).default(def[2]);
|
|
132
138
|
const indexOneParsers = {
|
|
133
139
|
"|": parseBranchTuple,
|
|
134
140
|
"&": parseBranchTuple,
|
|
135
141
|
"[]": parseArrayTuple,
|
|
136
142
|
":": parseNarrowTuple,
|
|
137
143
|
"=>": parseMorphTuple,
|
|
138
|
-
"@": parseAttributeTuple
|
|
144
|
+
"@": parseAttributeTuple,
|
|
145
|
+
"=": parseDefaultTuple
|
|
139
146
|
};
|
|
140
147
|
const prefixParsers = {
|
|
141
148
|
keyof: parseKeyOfTuple,
|
package/out/scope.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ import type { Ark } from "./keywords/ark.ts";
|
|
|
6
6
|
import type { BoundModule, Module, Submodule, instantiateExport } from "./module.ts";
|
|
7
7
|
import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
|
|
8
8
|
import type { DefAst, InferredAst } from "./parser/semantic/infer.ts";
|
|
9
|
-
import type
|
|
10
|
-
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.ts";
|
|
9
|
+
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type Type, type TypeParser, type UnitTypeParser } from "./type.ts";
|
|
11
10
|
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkScopeConfig) => Scope<inferScope<def>>;
|
|
12
11
|
export type ModuleParser = <const def>(def: validateScope<def>, config?: ArkScopeConfig) => inferScope<def> extends infer $ ? Module<{
|
|
13
12
|
[k in exportedNameOf<$>]: $[k];
|
|
@@ -44,7 +43,7 @@ export type resolutionToAst<alias extends string, resolution> = [
|
|
|
44
43
|
resolution
|
|
45
44
|
] extends [anyOrNever] ? InferredAst<resolution, alias> : resolution extends Def<infer def> ? DefAst<def, alias> : resolution extends {
|
|
46
45
|
[arkKind]: "module";
|
|
47
|
-
|
|
46
|
+
root: infer root;
|
|
48
47
|
} ? InferredAst<root, alias> : resolution extends GenericAst ? resolution : InferredAst<resolution, alias>;
|
|
49
48
|
export type moduleKeyOf<$> = {
|
|
50
49
|
[k in keyof $]: $[k] extends {
|
|
@@ -72,9 +71,12 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
72
71
|
protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
|
|
73
72
|
preparseRoot(def: unknown): unknown;
|
|
74
73
|
get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
|
|
75
|
-
parse
|
|
76
|
-
|
|
74
|
+
parse(def: unknown, ctx: ParseContext): BaseRoot;
|
|
75
|
+
private _parse;
|
|
76
|
+
parseString(def: string, ctx: ParseContext): BaseRoot;
|
|
77
77
|
parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;
|
|
78
|
+
unit: UnitTypeParser<$>;
|
|
79
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
78
80
|
type: InternalTypeParser;
|
|
79
81
|
declare: () => {
|
|
80
82
|
type: InternalTypeParser;
|
|
@@ -99,6 +101,8 @@ export interface Scope<$ = {}> {
|
|
|
99
101
|
defineSchema<const def extends RootSchema>(schema: def): def;
|
|
100
102
|
schema(schema: RootSchema, opts?: NodeParseOptions): BaseRoot;
|
|
101
103
|
node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
|
|
104
|
+
unit: UnitTypeParser<$>;
|
|
105
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
102
106
|
type: TypeParser<$>;
|
|
103
107
|
declare: DeclarationParser<$>;
|
|
104
108
|
define: DefinitionParser<$>;
|
package/out/scope.js
CHANGED
|
@@ -47,24 +47,26 @@ export class InternalScope extends BaseScope {
|
|
|
47
47
|
return;
|
|
48
48
|
return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
|
|
49
49
|
k,
|
|
50
|
-
|
|
50
|
+
this.bindReference(v)
|
|
51
51
|
]));
|
|
52
52
|
}
|
|
53
|
-
parse(def, ctx
|
|
53
|
+
parse(def, ctx) {
|
|
54
|
+
return this.bindReference(this._parse(def, ctx));
|
|
55
|
+
}
|
|
56
|
+
_parse(def, ctx) {
|
|
54
57
|
if (typeof def === "string") {
|
|
55
58
|
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
56
59
|
// we can only rely on the cache if there are no contextual
|
|
57
60
|
// resolutions like "this" or generic args
|
|
58
|
-
return this.parseString(def, ctx
|
|
61
|
+
return this.parseString(def, ctx);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
|
|
63
|
+
return (this.parseCache[def] ??= this.parseString(def, ctx));
|
|
62
64
|
}
|
|
63
65
|
return hasDomain(def, "object") ?
|
|
64
66
|
parseObject(def, ctx)
|
|
65
67
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
66
68
|
}
|
|
67
|
-
parseString(def, ctx
|
|
69
|
+
parseString(def, ctx) {
|
|
68
70
|
const aliasResolution = this.maybeResolveRoot(def);
|
|
69
71
|
if (aliasResolution)
|
|
70
72
|
return aliasResolution;
|
|
@@ -73,16 +75,18 @@ export class InternalScope extends BaseScope {
|
|
|
73
75
|
: undefined;
|
|
74
76
|
if (aliasArrayResolution)
|
|
75
77
|
return aliasArrayResolution;
|
|
76
|
-
const s = new DynamicState(new Scanner(def), ctx
|
|
78
|
+
const s = new DynamicState(new Scanner(def), ctx);
|
|
77
79
|
const node = fullStringParse(s);
|
|
78
80
|
if (s.finalizer === ">")
|
|
79
81
|
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
80
82
|
return node;
|
|
81
83
|
}
|
|
82
84
|
parseRoot = (def, opts = {}) => {
|
|
83
|
-
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this }))
|
|
85
|
+
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this }));
|
|
84
86
|
return node;
|
|
85
87
|
};
|
|
88
|
+
unit = value => this.units([value]);
|
|
89
|
+
enumerated = (...values) => this.units(values);
|
|
86
90
|
type = new InternalTypeParser(this);
|
|
87
91
|
declare = () => ({
|
|
88
92
|
type: this.type
|
package/out/type.d.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
|
|
2
2
|
import { Callable, type Constructor, type array, type conform } from "@ark/util";
|
|
3
3
|
import { type Generic, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.ts";
|
|
4
|
-
import type { Ark, ark } from "./keywords/ark.ts";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
4
|
+
import type { Ark, ark, type } from "./keywords/ark.ts";
|
|
5
|
+
import type { distill } from "./keywords/ast.ts";
|
|
6
|
+
import type { BaseType } from "./methods/base.ts";
|
|
7
|
+
import type { instantiateType } from "./methods/instantiate.ts";
|
|
8
|
+
import type { validateDeclared, validateDefinition } from "./parser/definition.ts";
|
|
7
9
|
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";
|
|
8
10
|
import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";
|
|
9
|
-
import type { BaseType } from "./subtypes/base.ts";
|
|
10
|
-
import type { instantiateType } from "./subtypes/instantiate.ts";
|
|
11
11
|
/** The convenience properties attached to `type` */
|
|
12
12
|
export type TypeParserAttachments = Omit<TypeParser, never>;
|
|
13
13
|
export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
14
|
-
<const def, r = Type<
|
|
14
|
+
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
|
|
15
15
|
<params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
|
|
16
|
-
<const zero, const one, const rest extends array, r = Type<
|
|
16
|
+
<const zero, const one, const rest extends array, r = Type<type.infer<[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, IndexOneOperator>, ..._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 "@" ? [MetaSchema] : [type.validate<rest[0], $>] : []): r;
|
|
17
|
+
$: Scope<$>;
|
|
17
18
|
raw(def: unknown): BaseType<any, $>;
|
|
18
19
|
errors: typeof ArkErrors;
|
|
19
20
|
module: ModuleParser;
|
|
20
21
|
scope: ScopeParser;
|
|
21
22
|
generic: GenericParser<$>;
|
|
22
23
|
ark: typeof ark;
|
|
24
|
+
unit: UnitTypeParser<$>;
|
|
25
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
23
26
|
}
|
|
24
27
|
export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
|
|
25
28
|
constructor($: InternalScope);
|
|
@@ -27,11 +30,9 @@ export declare class InternalTypeParser extends Callable<(...args: unknown[]) =>
|
|
|
27
30
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
28
31
|
type: <const def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
|
|
29
32
|
};
|
|
30
|
-
export type
|
|
31
|
-
export type
|
|
32
|
-
export type
|
|
33
|
-
export type validateAmbient<def> = validateTypeRoot<def, {}>;
|
|
34
|
-
export type inferAmbient<def> = inferTypeRoot<def, {}>;
|
|
33
|
+
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
|
|
34
|
+
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
|
|
35
|
+
export type DefinitionParser<$> = <def>(def: type.validate<def, $>) => def;
|
|
35
36
|
export type Type<t = unknown, $ = {}> = instantiateType<t, $>;
|
|
36
37
|
export declare namespace Type {
|
|
37
38
|
type Any<t = any> = BaseType<t, any>;
|
package/out/type.js
CHANGED
|
@@ -5,12 +5,15 @@ export class InternalTypeParser extends Callable {
|
|
|
5
5
|
constructor($) {
|
|
6
6
|
const attach = Object.assign({
|
|
7
7
|
errors: ArkErrors,
|
|
8
|
+
$: $,
|
|
8
9
|
raw: $.parseRoot,
|
|
9
10
|
module: $.constructor.module,
|
|
10
11
|
scope: $.constructor.scope,
|
|
11
12
|
generic: $.generic,
|
|
12
13
|
// this won't be defined during bootstrapping, but externally always will be
|
|
13
|
-
ark: $.ambient
|
|
14
|
+
ark: $.ambient,
|
|
15
|
+
unit: $.unit,
|
|
16
|
+
enumerated: $.enumerated
|
|
14
17
|
},
|
|
15
18
|
// also won't be defined during bootstrapping
|
|
16
19
|
$.ambientAttachments);
|
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-rc.
|
|
4
|
+
"version": "2.0.0-rc.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"out"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ark/util": "0.
|
|
38
|
-
"@ark/schema": "0.
|
|
37
|
+
"@ark/util": "0.8.0",
|
|
38
|
+
"@ark/schema": "0.8.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
package/out/subtypes/base.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
-
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
-
import type { inferIntersection } from "../intersect.ts";
|
|
4
|
-
import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes } from "../keywords/ast.ts";
|
|
5
|
-
import type { Scope } from "../scope.ts";
|
|
6
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
|
-
import type { ArrayType } from "./array.ts";
|
|
8
|
-
import type { instantiateType } from "./instantiate.ts";
|
|
9
|
-
/** @ts-ignore cast variance */
|
|
10
|
-
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> {
|
|
11
|
-
t: t;
|
|
12
|
-
tIn: distillConstrainableIn<t>;
|
|
13
|
-
tOut: distillConstrainableOut<t>;
|
|
14
|
-
tValidatedOut: distillValidatedOut<t>;
|
|
15
|
-
infer: distillOut<t>;
|
|
16
|
-
inferIn: distillIn<t>;
|
|
17
|
-
[inferred]: t;
|
|
18
|
-
json: Json;
|
|
19
|
-
toJsonSchema(): JsonSchema;
|
|
20
|
-
description: string;
|
|
21
|
-
expression: string;
|
|
22
|
-
internal: BaseRoot;
|
|
23
|
-
$: Scope<$>;
|
|
24
|
-
assert(data: unknown): this["infer"];
|
|
25
|
-
allows(data: unknown): data is this["inferIn"];
|
|
26
|
-
traverse(data: unknown): distillOut<t> | ArkErrors;
|
|
27
|
-
configure(meta: MetaSchema): this;
|
|
28
|
-
describe(description: string): this;
|
|
29
|
-
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
30
|
-
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
31
|
-
from(literal: this["inferIn"]): this["infer"];
|
|
32
|
-
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
|
|
33
|
-
get in(): instantiateType<this["tIn"], $>;
|
|
34
|
-
get out(): instantiateType<this["tValidatedOut"], $>;
|
|
35
|
-
intersect<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
|
|
36
|
-
and<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $>;
|
|
37
|
-
or<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<t | r, $>;
|
|
38
|
-
array(): ArrayType<t[], $>;
|
|
39
|
-
pipe: ChainedPipes<t, $>;
|
|
40
|
-
equals<def>(def: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
|
|
41
|
-
extract<def>(r: validateTypeRoot<def, $>): instantiateType<Extract<t, inferTypeRoot<def, $>>, $>;
|
|
42
|
-
exclude<def>(r: validateTypeRoot<def, $>): instantiateType<Exclude<t, inferTypeRoot<def, $>>, $>;
|
|
43
|
-
extends<def>(other: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
|
|
44
|
-
overlaps<def>(r: validateTypeRoot<def, $>): boolean;
|
|
45
|
-
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
|
|
46
|
-
/** @deprecated */
|
|
47
|
-
apply: Function["apply"];
|
|
48
|
-
/** @deprecated */
|
|
49
|
-
bind: Function["bind"];
|
|
50
|
-
/** @deprecated */
|
|
51
|
-
call: Function["call"];
|
|
52
|
-
/** @deprecated */
|
|
53
|
-
caller: Function;
|
|
54
|
-
/** @deprecated */
|
|
55
|
-
length: number;
|
|
56
|
-
/** @deprecated */
|
|
57
|
-
name: string;
|
|
58
|
-
/** @deprecated */
|
|
59
|
-
prototype: Function["prototype"];
|
|
60
|
-
/** @deprecated */
|
|
61
|
-
arguments: Function["arguments"];
|
|
62
|
-
/** @deprecated */
|
|
63
|
-
Symbol: never;
|
|
64
|
-
}
|
|
65
|
-
interface ChainedPipeSignature<t, $> {
|
|
66
|
-
<a extends Morph<distillOut<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
|
|
67
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
|
|
68
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
|
|
69
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): r;
|
|
70
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): r;
|
|
71
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): r;
|
|
72
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): r;
|
|
73
|
-
}
|
|
74
|
-
export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
|
|
75
|
-
try: ChainedPipeSignature<t, $>;
|
|
76
|
-
}
|
|
77
|
-
type validateChainedAsArgs<t> = [
|
|
78
|
-
t
|
|
79
|
-
] extends [unset] ? [
|
|
80
|
-
t
|
|
81
|
-
] extends [anyOrNever] ? [
|
|
82
|
-
] : [
|
|
83
|
-
ErrorMessage<"as requires an explicit type parameter like myType.as<t>()">
|
|
84
|
-
] : [];
|
|
85
|
-
export type { Type as BaseType };
|
package/out/subtypes/morph.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type { inferPipe } from "../intersect.ts";
|
|
3
|
-
import type { applyConstraint, Out, To } from "../keywords/ast.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
|
-
import type { BaseType } from "./base.ts";
|
|
6
|
-
/** @ts-ignore cast variance */
|
|
7
|
-
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
8
|
-
to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
|
|
9
|
-
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
10
|
-
narrowed
|
|
11
|
-
] extends [never] ? applyConstraint<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
|
|
12
|
-
}
|
|
13
|
-
export type { Type as MorphType };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|