arktype 2.0.0-rc.2 → 2.0.0-rc.21
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/attributes.d.ts +274 -0
- package/out/attributes.js +2 -0
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +45 -48
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +37 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/keywords.d.ts +64 -0
- package/out/keywords/{ark.js → keywords.js} +14 -9
- package/out/keywords/number/epoch.d.ts +1 -1
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +44 -14
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +2 -2
- package/out/keywords/string/alphanumeric.d.ts +2 -2
- package/out/keywords/string/base64.d.ts +21 -0
- package/out/keywords/string/base64.js +6 -0
- package/out/keywords/string/capitalize.d.ts +3 -3
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +2 -2
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +7 -11
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +2 -2
- package/out/keywords/string/email.d.ts +2 -2
- package/out/keywords/string/integer.d.ts +3 -3
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +5 -5
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +4 -3
- package/out/keywords/string/json.js +39 -30
- package/out/keywords/string/lower.d.ts +3 -3
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +27 -31
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +3 -3
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +2 -2
- package/out/keywords/string/string.d.ts +74 -51
- package/out/keywords/string/string.js +5 -3
- package/out/keywords/string/trim.d.ts +3 -3
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +3 -3
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +3 -3
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +20 -20
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +38 -1
- package/out/keywords/ts.js +20 -4
- 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 +183 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +12 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +13 -0
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +10 -10
- package/out/parser/ast/validate.js +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +11 -37
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -3
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/operator.d.ts +2 -1
- package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
- package/out/parser/{string/shift → shift}/scanner.js +6 -3
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +56 -44
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +38 -39
- package/out/scope.js +47 -36
- package/out/type.d.ts +45 -21
- package/out/type.js +14 -10
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -39
- package/out/parser/semantic/validate.js +0 -1
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/instantiate.d.ts +0 -16
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/number.d.ts +0 -12
- package/out/subtypes/object.d.ts +0 -33
- package/out/subtypes/string.d.ts +0 -13
- package/out/subtypes/validator.d.ts +0 -11
- package/out/subtypes/validator.js +0 -1
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
|
|
2
|
+
import type { ErrorMessage } from "@ark/util";
|
|
3
|
+
import type { type } from "../../keywords/keywords.ts";
|
|
4
|
+
import type { UnitLiteral } from "../shift/operator/default.ts";
|
|
5
|
+
import type { inferAstIn } from "./infer.ts";
|
|
6
|
+
import type { astToString } from "./utils.ts";
|
|
7
|
+
import type { validateAst } from "./validate.ts";
|
|
8
|
+
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { GenericAst } from "@ark/schema";
|
|
2
|
+
import type { Hkt, arkKeyOf, array } from "@ark/util";
|
|
3
|
+
import type { After, AtLeast, AtLeastLength, AtMost, AtMostLength, AtOrAfter, AtOrBefore, Before, Default, DivisibleBy, ExactlyLength, LessThan, LessThanLength, LimitLiteral, MoreThan, MoreThanLength, Nominal, Optional, associateAttributes, brandAttributes, distill, inferIntersection, normalizeLimit } from "../../attributes.ts";
|
|
4
|
+
import type { Date } from "../../keywords/constructors/Date.ts";
|
|
5
|
+
import type { type } from "../../keywords/keywords.ts";
|
|
6
|
+
import type { UnparsedScope } from "../../scope.ts";
|
|
7
|
+
import type { inferDefinition } from "../definition.ts";
|
|
8
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
9
|
+
import type { Scanner } from "../shift/scanner.ts";
|
|
10
|
+
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
11
|
+
export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
|
|
12
|
+
export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
|
|
13
|
+
export type DefAst<def = unknown, alias extends string = string> = [
|
|
14
|
+
def,
|
|
15
|
+
"def",
|
|
16
|
+
alias
|
|
17
|
+
];
|
|
18
|
+
export type InferredAst<t = unknown, def extends string = string> = [
|
|
19
|
+
t,
|
|
20
|
+
"inferred",
|
|
21
|
+
def
|
|
22
|
+
];
|
|
23
|
+
export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
24
|
+
type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
|
|
25
|
+
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> ? g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
|
|
26
|
+
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
27
|
+
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
28
|
+
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
29
|
+
}> : 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 ? associateAttributes<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends "#" ? brandAttributes<inferExpression<ast[0], $, args>, Nominal<ast[2]>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? attachBoundAttributes<inferExpression<ast[2], $, args>, ast[1], ast[0]> : attachBoundAttributes<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? associateAttributes<inferExpression<ast[0], $, args>, DivisibleBy<ast[2]>> : ast[1] extends "?" ? associateAttributes<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
30
|
+
export type attachBoundAttributes<inWithAttributes, comparator extends Comparator, limit extends LimitLiteral> = distill.In<inWithAttributes> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.nominal<normalizeLimit<limit>> : associateAttributes<inWithAttributes, ExactlyLength<limit>> : associateAttributes<inWithAttributes, boundToAttributes<In, comparator, limit>> : never;
|
|
31
|
+
export type boundToAttributes<In, comparator extends Comparator, limit extends LimitLiteral> = In extends string | array ? lengthBoundToAttributes<comparator, limit & number> : In extends Date ? dateBoundToAttributes<comparator, normalizeLimit<limit>> : numericBoundToAttributes<comparator, limit & number>;
|
|
32
|
+
type lengthBoundToAttributes<comparator extends Comparator, limit extends number> = comparator extends "<" ? LessThanLength<limit> : comparator extends "<=" ? AtMostLength<limit> : comparator extends ">" ? MoreThanLength<limit> : AtLeastLength<limit>;
|
|
33
|
+
type dateBoundToAttributes<comparator extends Comparator, limit extends string | number> = comparator extends "<" ? Before<limit> : comparator extends "<=" ? AtOrBefore<limit> : comparator extends ">" ? After<limit> : AtOrAfter<limit>;
|
|
34
|
+
type numericBoundToAttributes<comparator extends Comparator, limit extends number> = comparator extends "<" ? LessThan<limit> : comparator extends "<=" ? AtMost<limit> : comparator extends ">" ? MoreThan<limit> : AtLeast<limit>;
|
|
35
|
+
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
36
|
+
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
37
|
+
export type PostfixExpression<operator extends Scanner.PostfixToken = Scanner.PostfixToken, operand = unknown> = readonly [operand, operator];
|
|
38
|
+
export type InfixExpression<operator extends Scanner.InfixToken = Scanner.InfixToken, l = unknown, r = unknown> = [l, operator, r];
|
|
39
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Stringifiable } from "@ark/util";
|
|
2
|
-
import type { Comparator } from "../
|
|
2
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
3
3
|
import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
4
4
|
export type astToString<ast> = ast extends InferredAst | DefAst ? ast[2] : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
|
|
2
|
-
import type { anyOrNever, array, BigintLiteral,
|
|
2
|
+
import type { anyOrNever, array, BigintLiteral, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
3
|
import type { Generic } from "../../generic.ts";
|
|
4
|
-
import type { Comparator } from "../
|
|
5
|
-
import type { writeInvalidGenericArgCountMessage } from "../
|
|
6
|
-
import type { UnitLiteral } from "../
|
|
7
|
-
import type { parseString } from "../string
|
|
4
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
5
|
+
import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
|
|
6
|
+
import type { UnitLiteral } from "../shift/operator/default.ts";
|
|
7
|
+
import type { parseString } from "../string.ts";
|
|
8
8
|
import type { validateRange } from "./bounds.ts";
|
|
9
9
|
import type { validateDefault } from "./default.ts";
|
|
10
10
|
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<
|
|
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<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : 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> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : 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}`;
|
|
18
18
|
type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
|
|
19
|
-
export declare const writePrefixedPrivateReferenceMessage: <
|
|
20
|
-
export type writePrefixedPrivateReferenceMessage<
|
|
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<
|
|
19
|
+
export declare const writePrefixedPrivateReferenceMessage: <name extends string>(name: name) => writePrefixedPrivateReferenceMessage<name>;
|
|
20
|
+
export type writePrefixedPrivateReferenceMessage<name extends string> = `Private type references should not include '#'. Use '${name}' instead.`;
|
|
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<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : 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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { type BaseRoot } from "@ark/schema";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot } from "@ark/schema";
|
|
2
2
|
import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
|
|
3
|
-
import type { type } from "../keywords/
|
|
3
|
+
import type { type } from "../keywords/keywords.ts";
|
|
4
4
|
import type { string } from "../keywords/string/string.ts";
|
|
5
|
-
import type {
|
|
5
|
+
import type { validateString } from "./ast/validate.ts";
|
|
6
6
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
|
|
7
|
-
import type {
|
|
8
|
-
import type { BaseCompletions, inferString } from "./string/string.ts";
|
|
7
|
+
import type { BaseCompletions, inferString } from "./string.ts";
|
|
9
8
|
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
|
|
10
|
-
export declare const parseObject: (def: object, ctx:
|
|
9
|
+
export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
|
|
11
10
|
export type inferDefinition<def, $, args> = [
|
|
12
11
|
def
|
|
13
|
-
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<
|
|
14
|
-
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
12
|
+
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
13
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : RegExp extends def ? def : validateObjectLiteral<def, $, args>;
|
|
15
14
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
16
15
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
17
16
|
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
|
@@ -25,7 +24,7 @@ type declarationMismatch<def, declared, $, args> = {
|
|
|
25
24
|
declared: declared;
|
|
26
25
|
inferred: inferDefinition<def, $, args>;
|
|
27
26
|
};
|
|
28
|
-
type Terminal =
|
|
27
|
+
type Terminal = type.cast<unknown> | Fn;
|
|
29
28
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
30
29
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
31
30
|
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
|
+
import type { of } from "../attributes.ts";
|
|
4
|
+
import type { astToString } from "./ast/utils.ts";
|
|
5
|
+
import type { validateString } from "./ast/validate.ts";
|
|
5
6
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
|
-
|
|
7
|
-
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
7
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
|
|
9
8
|
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
10
9
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
11
10
|
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
@@ -13,41 +12,18 @@ export type inferObjectLiteral<def extends object, $, args> = show<"..." extends
|
|
|
13
12
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
14
13
|
*/
|
|
15
14
|
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]:
|
|
15
|
+
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: [
|
|
17
16
|
def[k]
|
|
18
|
-
] extends [anyOrNever] ? def[k] :
|
|
17
|
+
] extends [anyOrNever] ? def[k] : inferDefinition<def[k], $, args>;
|
|
19
18
|
} & {
|
|
20
19
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
21
20
|
};
|
|
22
21
|
export type validateObjectLiteral<def, $, args> = {
|
|
23
|
-
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key |
|
|
22
|
+
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | of<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>;
|
|
24
23
|
};
|
|
25
|
-
type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? [
|
|
26
|
-
def[k]
|
|
27
|
-
] extends [anyOrNever] ?
|
|
28
|
-
/** this extra [anyOrNever] check is required to ensure that nested `type` invocations
|
|
29
|
-
* like the following are not prematurely validated by the outer call:
|
|
30
|
-
*
|
|
31
|
-
* ```ts
|
|
32
|
-
* type({
|
|
33
|
-
* "test?": type("string").pipe(x => x === "true")
|
|
34
|
-
* })
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
def[k] : validateDefaultValueTuple<def[k], k, $, args> : validateDefinition<def[k], $, args>;
|
|
38
|
-
type DefaultValueTuple<baseDef = unknown, defaultValue = unknown> = readonly [
|
|
39
|
-
baseDef,
|
|
40
|
-
"=",
|
|
41
|
-
defaultValue
|
|
42
|
-
];
|
|
43
|
-
type validateDefaultValueTuple<def extends DefaultValueTuple, k extends PropertyKey, $, args> = parseKey<k>["kind"] extends "required" ? conform<def, readonly [
|
|
44
|
-
validateDefinition<def[0], $, args>,
|
|
45
|
-
"=",
|
|
46
|
-
inferDefinition<def[0], $, args>
|
|
47
|
-
]> : ErrorMessage<invalidDefaultKeyKindMessage>;
|
|
48
24
|
type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
|
|
49
25
|
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
50
|
-
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
26
|
+
export type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
51
27
|
kind: kind;
|
|
52
28
|
key: key;
|
|
53
29
|
};
|
|
@@ -66,9 +42,7 @@ export type ParsedSpreadEntry = {
|
|
|
66
42
|
kind: "spread";
|
|
67
43
|
node: BaseRoot;
|
|
68
44
|
};
|
|
69
|
-
export declare const parseEntry: (key: Key, value: unknown, ctx:
|
|
70
|
-
export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
|
|
71
|
-
export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
|
|
45
|
+
export declare const parseEntry: (key: Key, value: unknown, ctx: BaseParseContext) => listable<ParsedEntry>;
|
|
72
46
|
declare const parseKey: (key: Key) => PreparsedKey;
|
|
73
47
|
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
|
|
74
48
|
kind: "required";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { append, escapeToken,
|
|
3
|
-
import { writeUnassignableDefaultValueMessage } from "./semantic/default.js";
|
|
1
|
+
import { normalizeIndex } from "@ark/schema";
|
|
2
|
+
import { append, escapeToken, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
|
|
4
3
|
export const parseObjectLiteral = (def, ctx) => {
|
|
5
4
|
let spread;
|
|
6
5
|
const structure = {};
|
|
@@ -29,7 +28,7 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
29
28
|
structure[entry.kind] = append(structure[entry.kind], entry);
|
|
30
29
|
}
|
|
31
30
|
const structureNode = ctx.$.node("structure", structure);
|
|
32
|
-
return ctx.$.
|
|
31
|
+
return ctx.$.parseSchema({
|
|
33
32
|
domain: "object",
|
|
34
33
|
structure: spread?.merge(structureNode) ?? structureNode
|
|
35
34
|
});
|
|
@@ -44,25 +43,10 @@ export const parseEntry = (key, value, ctx) => {
|
|
|
44
43
|
return { kind: "undeclared", behavior: value };
|
|
45
44
|
}
|
|
46
45
|
if (parsedKey.kind === "...")
|
|
47
|
-
return { kind: "spread", node: ctx.$.
|
|
48
|
-
const parsedValue =
|
|
49
|
-
[ctx.$.parse(value[0], ctx), "=", value[2]]
|
|
50
|
-
: ctx.$.parse(value, ctx, true);
|
|
51
|
-
if (isArray(parsedValue)) {
|
|
52
|
-
if (parsedKey.kind !== "required")
|
|
53
|
-
throwParseError(invalidDefaultKeyKindMessage);
|
|
54
|
-
const out = parsedValue[0].traverse(parsedValue[2]);
|
|
55
|
-
if (out instanceof ArkErrors) {
|
|
56
|
-
throwParseError(writeUnassignableDefaultValueMessage(printable(parsedKey.key), out.message));
|
|
57
|
-
}
|
|
58
|
-
return ctx.$.node("optional", {
|
|
59
|
-
key: parsedKey.key,
|
|
60
|
-
value: parsedValue[0],
|
|
61
|
-
default: parsedValue[2]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
46
|
+
return { kind: "spread", node: ctx.$.parseOwnDefinitionFormat(value, ctx) };
|
|
47
|
+
const parsedValue = ctx.$.parseOwnDefinitionFormat(value, ctx);
|
|
64
48
|
if (parsedKey.kind === "index") {
|
|
65
|
-
const signature = ctx.$.
|
|
49
|
+
const signature = ctx.$.parseOwnDefinitionFormat(parsedKey.key, ctx);
|
|
66
50
|
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
67
51
|
return (normalized.index ?
|
|
68
52
|
normalized.required ?
|
|
@@ -75,8 +59,6 @@ export const parseEntry = (key, value, ctx) => {
|
|
|
75
59
|
value: parsedValue
|
|
76
60
|
});
|
|
77
61
|
};
|
|
78
|
-
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
79
|
-
export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
|
|
80
62
|
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
81
63
|
: key.at(-1) === "?" ?
|
|
82
64
|
key.at(-2) === escapeToken ?
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { BaseRoot } from "@ark/schema";
|
|
1
|
+
import type { BaseParseContext, BaseRoot } from "@ark/schema";
|
|
2
2
|
import { type requireKeys } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "
|
|
4
|
-
import type { ParseContext } from "../../../scope.ts";
|
|
5
|
-
import type { InfixOperator } from "../../semantic/infer.ts";
|
|
3
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
6
4
|
import type { Scanner } from "../shift/scanner.ts";
|
|
7
5
|
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
8
6
|
type BranchState = {
|
|
@@ -18,9 +16,8 @@ export declare class DynamicState {
|
|
|
18
16
|
finalizer: Scanner.FinalizingLookahead | undefined;
|
|
19
17
|
groups: BranchState[];
|
|
20
18
|
scanner: Scanner;
|
|
21
|
-
ctx:
|
|
22
|
-
|
|
23
|
-
constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
|
|
19
|
+
ctx: BaseParseContext;
|
|
20
|
+
constructor(scanner: Scanner, ctx: BaseParseContext);
|
|
24
21
|
error(message: string): never;
|
|
25
22
|
hasRoot(): this is DynamicStateWithRoot;
|
|
26
23
|
setRoot(root: BaseRoot): void;
|
|
@@ -38,7 +35,7 @@ export declare class DynamicState {
|
|
|
38
35
|
parseOperand(): void;
|
|
39
36
|
private assertRangeUnset;
|
|
40
37
|
reduceGroupOpen(): void;
|
|
41
|
-
previousOperator(): MinComparator | StringifiablePrefixOperator |
|
|
38
|
+
previousOperator(): MinComparator | StringifiablePrefixOperator | Scanner.InfixToken | undefined;
|
|
42
39
|
shiftedByOne(): this;
|
|
43
40
|
}
|
|
44
41
|
export {};
|
|
@@ -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);
|
|
@@ -93,17 +91,18 @@ export class DynamicState {
|
|
|
93
91
|
this.assertRangeUnset();
|
|
94
92
|
this.applyPrefixes();
|
|
95
93
|
const root = this.root;
|
|
96
|
-
this.branches.intersection =
|
|
94
|
+
this.branches.intersection =
|
|
95
|
+
this.branches.intersection?.rawAnd(root) ?? root;
|
|
97
96
|
if (token === "|") {
|
|
98
97
|
this.branches.union =
|
|
99
|
-
this.branches.union?.
|
|
98
|
+
this.branches.union?.rawOr(this.branches.intersection) ??
|
|
100
99
|
this.branches.intersection;
|
|
101
100
|
this.branches.intersection = null;
|
|
102
101
|
}
|
|
103
102
|
this.root = undefined;
|
|
104
103
|
}
|
|
105
104
|
parseUntilFinalizer() {
|
|
106
|
-
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx
|
|
105
|
+
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx));
|
|
107
106
|
}
|
|
108
107
|
parseOperator() {
|
|
109
108
|
return parseOperator(this);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Completion, ErrorMessage, defined } from "@ark/util";
|
|
2
|
-
import type { LimitLiteral } from "
|
|
2
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
3
3
|
import type { Scanner } from "../shift/scanner.ts";
|
|
4
4
|
import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
|
|
5
5
|
export type StaticState = {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { DateLiteral } from "
|
|
1
|
+
import type { DateLiteral } from "../../../attributes.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,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { string } from "../../../attributes.ts";
|
|
2
|
+
import type { Date } from "../../../keywords/constructors/Date.ts";
|
|
3
|
+
import type { InferredAst } from "../../ast/infer.ts";
|
|
3
4
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
4
5
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
5
6
|
import type { Scanner } from "../scanner.ts";
|
|
@@ -7,7 +8,7 @@ export type StringLiteral<Text extends string = string> = DoubleQuotedStringLite
|
|
|
7
8
|
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
8
9
|
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
9
10
|
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
|
|
10
|
-
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.
|
|
11
|
+
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.nominal<scanned>, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
11
12
|
export declare const enclosingQuote: {
|
|
12
13
|
readonly "'": 1;
|
|
13
14
|
readonly '"': 1;
|
|
@@ -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,8 +1,9 @@
|
|
|
1
1
|
import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema";
|
|
2
2
|
import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "@ark/util";
|
|
3
|
-
import type { ArkAmbient } from "
|
|
4
|
-
import type { resolutionToAst } from "
|
|
5
|
-
import type { GenericInstantiationAst, InferredAst } from "
|
|
3
|
+
import type { ArkAmbient } from "../../../config.ts";
|
|
4
|
+
import type { resolutionToAst } from "../../../scope.ts";
|
|
5
|
+
import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
|
|
6
|
+
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
|
|
6
7
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
7
8
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
8
9
|
import type { BaseCompletions } from "../../string.ts";
|
|
@@ -27,7 +28,10 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
|
|
|
27
28
|
]> : unresolvableState<s, reference, resolution, {}, submodulePath> : state.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
|
|
28
29
|
/** Provide valid completions for the current token, or fallback to an
|
|
29
30
|
* unresolvable error if there are none */
|
|
30
|
-
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> =
|
|
31
|
+
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
|
|
32
|
+
token,
|
|
33
|
+
s["unscanned"]
|
|
34
|
+
] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntilNextTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? state.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
|
|
31
35
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
32
36
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
|
|
33
37
|
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
|
|
2
2
|
import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
|
|
3
|
-
import { writePrefixedPrivateReferenceMessage } from "
|
|
3
|
+
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.js";
|
|
4
4
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
|
|
5
5
|
export const parseUnenclosed = (s) => {
|
|
6
6
|
const token = s.scanner.shiftUntilNextTerminator();
|
|
@@ -19,13 +19,18 @@ export const parseGenericInstantiation = (name, g, s) => {
|
|
|
19
19
|
};
|
|
20
20
|
const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
|
|
21
21
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
22
|
-
s.error(token === "" ?
|
|
23
|
-
|
|
24
|
-
writePrefixedPrivateReferenceMessage(
|
|
25
|
-
:
|
|
22
|
+
s.error(token === "" ?
|
|
23
|
+
s.scanner.lookahead === "#" ?
|
|
24
|
+
writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilNextTerminator())
|
|
25
|
+
: writeMissingOperandMessage(s)
|
|
26
|
+
: writeUnresolvableMessage(token));
|
|
26
27
|
const maybeParseReference = (s, token) => {
|
|
27
|
-
if (s.ctx.args?.[token])
|
|
28
|
-
|
|
28
|
+
if (s.ctx.args?.[token]) {
|
|
29
|
+
const arg = s.ctx.args[token];
|
|
30
|
+
if (typeof arg !== "string")
|
|
31
|
+
return arg;
|
|
32
|
+
return s.ctx.$.node("alias", { reference: arg }, { prereduced: true });
|
|
33
|
+
}
|
|
29
34
|
const resolution = s.ctx.$.maybeResolve(token);
|
|
30
35
|
if (hasArkKind(resolution, "root"))
|
|
31
36
|
return resolution;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type BaseRoot, type BoundKind } from "@ark/schema";
|
|
2
2
|
import { type keySet } from "@ark/util";
|
|
3
|
-
import type { DateLiteral } from "
|
|
4
|
-
import type { InferredAst } from "
|
|
5
|
-
import type { astToString } from "
|
|
3
|
+
import type { DateLiteral } from "../../../attributes.ts";
|
|
4
|
+
import type { InferredAst } from "../../ast/infer.ts";
|
|
5
|
+
import type { astToString } from "../../ast/utils.ts";
|
|
6
6
|
import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
7
7
|
import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
|
|
8
8
|
import type { state, StaticState } from "../../reduce/static.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { emptyBrandNameMessage } from "@ark/schema";
|
|
2
|
+
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
3
|
+
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
+
import type { Scanner } from "../scanner.ts";
|
|
5
|
+
export declare const parseBrand: (s: DynamicStateWithRoot) => void;
|
|
6
|
+
export type parseBrand<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned>) ? brandName extends "" ? state.error<emptyBrandNameMessage> : state.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { BaseRoot } from "@ark/schema";
|
|
2
|
-
import {
|
|
3
|
-
import type { DateLiteral } from "
|
|
2
|
+
import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
|
|
3
|
+
import type { DateLiteral } from "../../../attributes.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,9 @@ 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
|
-
|
|
10
|
+
const defaultValue = defaultNode.unit instanceof Date ?
|
|
11
|
+
() => new Date(defaultNode.unit)
|
|
12
|
+
: defaultNode.unit;
|
|
13
|
+
return baseNode.default(defaultValue);
|
|
15
14
|
};
|
|
16
15
|
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' }`;
|
|
@@ -3,9 +3,10 @@ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
|
3
3
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
4
|
import { Scanner } from "../scanner.ts";
|
|
5
5
|
import { parseBound, type ComparatorStartChar } from "./bounds.ts";
|
|
6
|
+
import { parseBrand } from "./brand.ts";
|
|
6
7
|
import { parseDivisor } from "./divisor.ts";
|
|
7
8
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
8
|
-
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 WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
9
|
+
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 "#" ? parseBrand<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
9
10
|
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
10
11
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
11
12
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isKeyOf, whiteSpaceTokens } from "@ark/util";
|
|
2
2
|
import { Scanner } from "../scanner.js";
|
|
3
3
|
import { comparatorStartChars, parseBound } from "./bounds.js";
|
|
4
|
+
import { parseBrand } from "./brand.js";
|
|
4
5
|
import { parseDivisor } from "./divisor.js";
|
|
5
6
|
export const parseOperator = (s) => {
|
|
6
7
|
const lookahead = s.scanner.shift();
|
|
@@ -15,8 +16,9 @@ export const parseOperator = (s) => {
|
|
|
15
16
|
s.finalize(lookahead)
|
|
16
17
|
: isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
|
|
17
18
|
: lookahead === "%" ? parseDivisor(s)
|
|
18
|
-
: lookahead
|
|
19
|
-
: s
|
|
19
|
+
: lookahead === "#" ? parseBrand(s)
|
|
20
|
+
: lookahead in whiteSpaceTokens ? parseOperator(s)
|
|
21
|
+
: s.error(writeUnexpectedCharacterMessage(lookahead)));
|
|
20
22
|
};
|
|
21
23
|
export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
|
|
22
24
|
export const incompleteArrayTokenMessage = `Missing expected ']'`;
|