arktype 2.0.0-rc.9 → 2.0.1
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 +94 -0
- package/out/attributes.js +3 -0
- package/out/generic.d.ts +13 -13
- package/out/index.d.ts +3 -1
- package/out/index.js +2 -1
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +2 -2
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +14 -13
- package/out/keywords/keywords.js +9 -5
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +22 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +31 -4
- package/out/keywords/ts.js +21 -8
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +461 -35
- package/out/methods/date.d.ts +5 -6
- package/out/methods/instantiate.d.ts +4 -4
- package/out/methods/morph.d.ts +6 -6
- package/out/methods/number.d.ts +8 -9
- package/out/methods/object.d.ts +39 -15
- package/out/methods/string.d.ts +9 -10
- package/out/parser/ast/bounds.d.ts +1 -1
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +8 -22
- package/out/parser/ast/validate.d.ts +13 -9
- package/out/parser/ast/validate.js +3 -1
- package/out/parser/definition.d.ts +17 -8
- package/out/parser/definition.js +38 -3
- package/out/parser/objectLiteral.d.ts +39 -39
- package/out/parser/objectLiteral.js +83 -67
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/reduce/dynamic.d.ts +8 -9
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +4 -4
- package/out/parser/shift/operand/date.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/shift/operand/operand.d.ts +3 -3
- package/out/parser/shift/operand/operand.js +2 -2
- package/out/parser/shift/operand/unenclosed.d.ts +13 -5
- package/out/parser/shift/operand/unenclosed.js +5 -4
- package/out/parser/shift/operator/bounds.d.ts +5 -5
- package/out/parser/shift/operator/bounds.js +5 -4
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/shift/operator/default.d.ts +3 -2
- package/out/parser/shift/operator/default.js +4 -1
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +4 -3
- package/out/parser/shift/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +31 -55
- package/out/parser/shift/scanner.js +24 -83
- package/out/parser/string.d.ts +5 -4
- package/out/parser/string.js +18 -1
- package/out/parser/tupleExpressions.d.ts +48 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +95 -0
- package/out/parser/tupleLiteral.js +122 -0
- package/out/scope.d.ts +17 -12
- package/out/scope.js +25 -41
- package/out/type.d.ts +63 -5
- package/out/type.js +3 -2
- package/package.json +8 -8
- package/out/keywords/constructors/Date.d.ts +0 -31
- package/out/keywords/inference.d.ts +0 -220
- package/out/keywords/inference.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -9
- package/out/keywords/number/integer.d.ts +0 -3
- package/out/keywords/number/integer.js +0 -5
- package/out/keywords/number/number.d.ts +0 -53
- package/out/keywords/number/number.js +0 -21
- package/out/keywords/string/alpha.d.ts +0 -7
- package/out/keywords/string/alpha.js +0 -2
- package/out/keywords/string/alphanumeric.d.ts +0 -7
- package/out/keywords/string/alphanumeric.js +0 -2
- package/out/keywords/string/capitalize.d.ts +0 -15
- package/out/keywords/string/capitalize.js +0 -12
- package/out/keywords/string/creditCard.d.ts +0 -8
- package/out/keywords/string/creditCard.js +0 -37
- package/out/keywords/string/date.d.ts +0 -55
- package/out/keywords/string/date.js +0 -98
- package/out/keywords/string/digits.d.ts +0 -7
- package/out/keywords/string/digits.js +0 -2
- package/out/keywords/string/email.d.ts +0 -7
- package/out/keywords/string/email.js +0 -4
- package/out/keywords/string/integer.d.ts +0 -16
- package/out/keywords/string/integer.js +0 -16
- package/out/keywords/string/ip.d.ts +0 -20
- package/out/keywords/string/ip.js +0 -23
- package/out/keywords/string/json.d.ts +0 -16
- package/out/keywords/string/json.js +0 -53
- package/out/keywords/string/lower.d.ts +0 -15
- package/out/keywords/string/lower.js +0 -12
- package/out/keywords/string/normalize.d.ts +0 -88
- package/out/keywords/string/normalize.js +0 -43
- package/out/keywords/string/numeric.d.ts +0 -15
- package/out/keywords/string/numeric.js +0 -13
- package/out/keywords/string/semver.d.ts +0 -7
- package/out/keywords/string/semver.js +0 -4
- package/out/keywords/string/string.d.ts +0 -108
- package/out/keywords/string/string.js +0 -41
- package/out/keywords/string/trim.d.ts +0 -15
- package/out/keywords/string/trim.js +0 -14
- package/out/keywords/string/upper.d.ts +0 -15
- package/out/keywords/string/upper.js +0 -12
- package/out/keywords/string/url.d.ts +0 -15
- package/out/keywords/string/url.js +0 -37
- package/out/keywords/string/utils.d.ts +0 -2
- package/out/keywords/string/utils.js +0 -10
- package/out/keywords/string/uuid.d.ts +0 -42
- package/out/keywords/string/uuid.js +0 -19
- package/out/keywords/utils.d.ts +0 -1
- package/out/keywords/utils.js +0 -2
- package/out/methods/validator.d.ts +0 -11
- package/out/methods/validator.js +0 -1
- package/out/parser/tuple.d.ts +0 -143
- package/out/parser/tuple.js +0 -164
- /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
package/out/methods/object.d.ts
CHANGED
|
@@ -1,43 +1,67 @@
|
|
|
1
1
|
import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Default,
|
|
2
|
+
import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, JsonStructure, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
|
|
3
|
+
import type { Default, withDefault } from "../attributes.ts";
|
|
4
4
|
import type { type } from "../keywords/keywords.ts";
|
|
5
5
|
import type { ArrayType } from "./array.ts";
|
|
6
|
+
import type { BaseType } from "./base.ts";
|
|
6
7
|
import type { instantiateType } from "./instantiate.ts";
|
|
7
|
-
import type { ValidatorType } from "./validator.ts";
|
|
8
8
|
/** @ts-ignore cast variance */
|
|
9
|
-
interface Type<out t extends object = object, $ = {}> extends
|
|
9
|
+
interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
|
|
10
10
|
readonly(): t extends array ? ArrayType<{
|
|
11
11
|
readonly [i in keyof t]: t[i];
|
|
12
12
|
}, $> : Type<{
|
|
13
13
|
readonly [k in keyof t]: t[k];
|
|
14
14
|
}, $>;
|
|
15
15
|
keyof(): instantiateType<arkKeyOf<t>, $>;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Get the `Type` of a property of this `Type<object>`.
|
|
18
|
+
* @example type({ foo: "string" }).get("foo") // Type<string>
|
|
19
|
+
*/
|
|
20
|
+
get<const k1 extends arkIndexableOf<t>, r = arkGet<t, k1>>(k1: k1 | type.cast<k1>): instantiateType<r, $>;
|
|
17
21
|
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): instantiateType<arkGet<arkGet<t, k1>, k2>, $> extends infer r ? r : never;
|
|
18
|
-
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2
|
|
22
|
+
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = arkGet<arkGet<arkGet<t, k1>, k2>, k3>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<r, $>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a copy of this `Type` with only the specified properties.
|
|
25
|
+
* @example type({ foo: "string", bar: "number" }).pick("foo") // Type<{ foo: string }>
|
|
26
|
+
*/
|
|
19
27
|
pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
20
28
|
[k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
|
|
21
29
|
}, $>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a copy of this `Type` with all properties except the specified ones.
|
|
32
|
+
* @example type({ foo: "string", bar: "number" }).omit("foo") // Type<{ bar: number }>
|
|
33
|
+
*/
|
|
22
34
|
omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
23
35
|
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
|
|
24
36
|
}, $>;
|
|
25
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Merge another `Type` definition, overriding properties of this `Type` with the duplicate keys.
|
|
39
|
+
* @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1, b: 3, c: 4 }>
|
|
40
|
+
*/
|
|
41
|
+
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a copy of this `Type` with all properties required.
|
|
44
|
+
* @example const T = type({ "foo?"": "string" }).required() // Type<{ foo: string }>
|
|
45
|
+
*/
|
|
26
46
|
required(): Type<{
|
|
27
47
|
[k in keyof t]-?: t[k];
|
|
28
48
|
}, $>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a copy of this `Type` with all properties optional.
|
|
51
|
+
* @example: const T = type({ foo: "string" }).optional() // Type<{ foo?: string }>
|
|
52
|
+
*/
|
|
29
53
|
partial(): Type<{
|
|
30
54
|
[k in keyof t]?: t[k];
|
|
31
55
|
}, $>;
|
|
32
56
|
map<transformed extends listable<MappedTypeProp>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
|
|
57
|
+
/**
|
|
58
|
+
* List of property info of this `Type<object>`.
|
|
59
|
+
* @example type({ foo: "string = "" }).props // [{ kind: "required", key: "foo", value: Type<string>, default: "" }]
|
|
60
|
+
*/
|
|
33
61
|
props: array<typePropOf<t, $>>;
|
|
34
62
|
}
|
|
35
|
-
type typePropOf<o, $> =
|
|
36
|
-
|
|
37
|
-
}[keyof o] & unknown;
|
|
38
|
-
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends InferredDefault<infer v, infer defaultValue> ? DefaultedTypeProp<k & Key, v, defaultValue, $> : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : t extends InferredOptional ? [
|
|
39
|
-
t
|
|
40
|
-
] extends [anyOrNever] ? "required" : "optional" : "required", k & Key, t, $>;
|
|
63
|
+
type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
|
|
64
|
+
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends Default<infer t, infer defaultValue> ? DefaultedTypeProp<k & Key, t, defaultValue, $> : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
|
|
41
65
|
export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
|
|
42
66
|
/** @ts-ignore cast variance */
|
|
43
67
|
out v = unknown, $ = {}> {
|
|
@@ -45,7 +69,7 @@ out v = unknown, $ = {}> {
|
|
|
45
69
|
key: k;
|
|
46
70
|
value: instantiateType<v, $>;
|
|
47
71
|
meta: ArkEnv.meta;
|
|
48
|
-
toJSON: () =>
|
|
72
|
+
toJSON: () => JsonStructure;
|
|
49
73
|
}
|
|
50
74
|
export interface DefaultedTypeProp<k extends Key = Key, v = unknown, defaultValue = v, $ = {}> extends BaseTypeProp<"optional", k, v, $> {
|
|
51
75
|
default: defaultValue;
|
|
@@ -74,7 +98,7 @@ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
|
|
|
74
98
|
[prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
|
|
75
99
|
kind: "optional";
|
|
76
100
|
default: unknown;
|
|
77
|
-
}>["key"]]:
|
|
101
|
+
}>["key"]]: withDefault<prop["value"][inferred], prop["default" & keyof prop]>;
|
|
78
102
|
}>;
|
|
79
103
|
type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
|
|
80
104
|
kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
|
package/out/methods/string.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type { ExactLength, ExclusiveNumericRangeSchema,
|
|
2
|
-
import type {
|
|
3
|
-
import type { ValidatorType } from "./validator.ts";
|
|
1
|
+
import type { ExactLength, ExclusiveNumericRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
|
|
2
|
+
import type { BaseType } from "./base.ts";
|
|
4
3
|
/** @ts-ignore cast variance */
|
|
5
|
-
interface Type<out t extends string = string, $ = {}> extends
|
|
6
|
-
matching
|
|
7
|
-
atLeastLength
|
|
8
|
-
atMostLength
|
|
9
|
-
moreThanLength
|
|
10
|
-
lessThanLength
|
|
11
|
-
exactlyLength
|
|
4
|
+
interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> {
|
|
5
|
+
matching(schema: Pattern.Schema): this;
|
|
6
|
+
atLeastLength(schema: InclusiveNumericRangeSchema): this;
|
|
7
|
+
atMostLength(schema: InclusiveNumericRangeSchema): this;
|
|
8
|
+
moreThanLength(schema: ExclusiveNumericRangeSchema): this;
|
|
9
|
+
lessThanLength(schema: ExclusiveNumericRangeSchema): this;
|
|
10
|
+
exactlyLength(schema: ExactLength.Schema): this;
|
|
12
11
|
}
|
|
13
12
|
export type { Type as StringType };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { writeUnboundableMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage, array, typeToString } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "../../
|
|
3
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
4
4
|
import type { Comparator } from "../reduce/shared.ts";
|
|
5
5
|
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../shift/operator/bounds.ts";
|
|
6
6
|
import type { inferAstIn } from "./infer.ts";
|
|
@@ -2,7 +2,7 @@ import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
|
|
|
2
2
|
import type { ErrorMessage } from "@ark/util";
|
|
3
3
|
import type { type } from "../../keywords/keywords.ts";
|
|
4
4
|
import type { UnitLiteral } from "../shift/operator/default.ts";
|
|
5
|
-
import type {
|
|
5
|
+
import type { inferAstIn } from "./infer.ts";
|
|
6
6
|
import type { astToString } from "./utils.ts";
|
|
7
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
|
|
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,17 @@
|
|
|
1
|
+
import type { GenericAst, GenericParamAst, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
|
|
2
|
+
import type { array, ErrorMessage, Hkt, typeToString } from "@ark/util";
|
|
3
|
+
import type { UnparsedScope } from "../../scope.ts";
|
|
4
|
+
import type { inferDefinition } from "../definition.ts";
|
|
5
|
+
import type { inferAstRoot, inferExpression } from "./infer.ts";
|
|
6
|
+
import type { astToString } from "./utils.ts";
|
|
7
|
+
import type { validateAst } from "./validate.ts";
|
|
8
|
+
export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
9
|
+
export type inferGenericInstantiation<g extends GenericAst, argAsts extends unknown[], $, args> = g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
|
|
10
|
+
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
11
|
+
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
12
|
+
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
13
|
+
}>;
|
|
14
|
+
export type validateGenericInstantiation<g extends GenericAst, argAsts extends unknown[], $, args> = validateGenericArgs<g["paramsAst"], argAsts, $, args, []>;
|
|
15
|
+
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;
|
|
16
|
+
type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
|
|
17
|
+
export {};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { Date } from "../../keywords/constructors/Date.ts";
|
|
4
|
-
import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
|
|
1
|
+
import type { arkKeyOf, array } from "@ark/util";
|
|
2
|
+
import type { distill, inferIntersection, LimitLiteral, withDefault } from "../../attributes.ts";
|
|
5
3
|
import type { type } from "../../keywords/keywords.ts";
|
|
6
|
-
import type { UnparsedScope } from "../../scope.ts";
|
|
7
4
|
import type { inferDefinition } from "../definition.ts";
|
|
8
|
-
import type { Comparator
|
|
5
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
6
|
+
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
7
|
+
import type { GenericInstantiationAst, inferGenericInstantiation } from "./generic.ts";
|
|
9
8
|
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
10
9
|
export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
|
|
11
10
|
export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
|
|
@@ -19,21 +18,8 @@ export type InferredAst<t = unknown, def extends string = string> = [
|
|
|
19
18
|
"inferred",
|
|
20
19
|
def
|
|
21
20
|
];
|
|
22
|
-
export type
|
|
23
|
-
type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
|
|
24
|
-
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"], {
|
|
25
|
-
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
26
|
-
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
27
|
-
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
28
|
-
}> : 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 ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
29
|
-
export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
30
|
-
rule: normalizeLimit<limit>;
|
|
31
|
-
exclusive: comparator extends ">" | "<" ? true : false;
|
|
32
|
-
}> : never;
|
|
21
|
+
export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? inferGenericInstantiation<g, argAsts, $, args> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
33
22
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
34
23
|
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
35
|
-
export type
|
|
36
|
-
export type
|
|
37
|
-
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
|
|
38
|
-
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
39
|
-
export {};
|
|
24
|
+
export type PostfixExpression<operator extends ArkTypeScanner.PostfixToken = ArkTypeScanner.PostfixToken, operand = unknown> = readonly [operand, operator];
|
|
25
|
+
export type InfixExpression<operator extends ArkTypeScanner.InfixToken = ArkTypeScanner.InfixToken, l = unknown, r = unknown> = [l, operator, r];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { arkKind,
|
|
2
|
-
import type { anyOrNever,
|
|
1
|
+
import type { arkKind, PrivateDeclaration, writeMissingSubmoduleAccessMessage } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, BigintLiteral, Completion, ErrorMessage, NumberLiteral, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
3
|
import type { Generic } from "../../generic.ts";
|
|
4
4
|
import type { Comparator } from "../reduce/shared.ts";
|
|
5
5
|
import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
|
|
@@ -8,19 +8,23 @@ 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
|
-
import type {
|
|
11
|
+
import type { GenericInstantiationAst, validateGenericInstantiation } from "./generic.ts";
|
|
12
|
+
import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
12
13
|
import type { validateKeyof } from "./keyof.ts";
|
|
13
14
|
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<
|
|
15
|
+
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
15
16
|
ast: ast;
|
|
16
17
|
};
|
|
17
18
|
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
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 {
|
|
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
|
-
export type validateString<def extends string, $, args> =
|
|
24
|
+
export type validateString<def extends string, $, args> = parseString<def, $, args> extends infer ast ? validateAst<ast, $, args> extends infer result extends ErrorMessage ? result extends Completion<infer text> ? text : result : def : never;
|
|
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
|
+
export declare const shallowOptionalMessage = "Optional definitions like 'string?' are only valid as properties in an object or tuple";
|
|
27
|
+
export type shallowOptionalMessage = typeof shallowOptionalMessage;
|
|
28
|
+
export declare const shallowDefaultableMessage = "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple";
|
|
29
|
+
export type shallowDefaultableMessage = typeof shallowDefaultableMessage;
|
|
26
30
|
export {};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export const writePrefixedPrivateReferenceMessage = (
|
|
1
|
+
export const writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
|
|
2
|
+
export const shallowOptionalMessage = "Optional definitions like 'string?' are only valid as properties in an object or tuple";
|
|
3
|
+
export const shallowDefaultableMessage = "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple";
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { type BaseParseContext, type BaseRoot } from "@ark/schema";
|
|
2
|
-
import { type
|
|
2
|
+
import { type anyOrNever, type array, type defined, type equals, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type Primitive, type requiredKeyOf, type show } from "@ark/util";
|
|
3
3
|
import type { type } from "../keywords/keywords.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type { validateString } from "./ast/validate.ts";
|
|
4
|
+
import type { InnerParseResult } from "../scope.ts";
|
|
5
|
+
import type { shallowDefaultableMessage, shallowOptionalMessage, validateString } from "./ast/validate.ts";
|
|
6
6
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
|
|
7
|
-
import type {
|
|
8
|
-
import { type
|
|
7
|
+
import type { isDefaultable, OptionalPropertyDefinition } from "./property.ts";
|
|
8
|
+
import { type BaseCompletions, type inferString } from "./string.ts";
|
|
9
|
+
import { type inferTupleExpression, type maybeValidateTupleExpression, type TupleExpression } from "./tupleExpressions.ts";
|
|
10
|
+
import { type inferTupleLiteral, type validateTupleLiteral } from "./tupleLiteral.ts";
|
|
11
|
+
export declare const parseInnerDefinition: (def: unknown, ctx: BaseParseContext) => InnerParseResult;
|
|
9
12
|
export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
|
|
10
13
|
export type inferDefinition<def, $, args> = [
|
|
11
14
|
def
|
|
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
|
|
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 [
|
|
14
|
-
export type
|
|
15
|
+
] 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 : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
16
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [anyOrNever] ? def : def extends OptionalPropertyDefinition ? ErrorMessage<shallowOptionalMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<shallowDefaultableMessage> : validateInnerDefinition<def, $, args>;
|
|
17
|
+
export type validateInnerDefinition<def, $, args> = [
|
|
18
|
+
def
|
|
19
|
+
] 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>;
|
|
20
|
+
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
21
|
+
export type validateTuple<def extends array, $, args> = maybeValidateTupleExpression<def, $, args> extends infer result ? result extends null ? validateTupleLiteral<def, $, args> : result : never;
|
|
22
|
+
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
|
|
23
|
+
export type validateDeclared<declared, def, $, args> = def extends type.validate<def, $, args> ? validateInference<def, declared, $, args> : type.validate<def, $, args>;
|
|
15
24
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
16
25
|
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
|
17
26
|
} : show<declarationMismatch<def, declared, $, args>> : def extends object ? show<{
|
package/out/parser/definition.js
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
|
-
import { hasArkKind } from "@ark/schema";
|
|
2
|
-
import { isThunk, objectKindOf, printable, throwParseError } from "@ark/util";
|
|
1
|
+
import { hasArkKind, isNode } from "@ark/schema";
|
|
2
|
+
import { domainOf, hasDomain, isThunk, objectKindOf, printable, throwParseError } from "@ark/util";
|
|
3
3
|
import { parseObjectLiteral } from "./objectLiteral.js";
|
|
4
|
-
import {
|
|
4
|
+
import { parseString } from "./string.js";
|
|
5
|
+
import { maybeParseTupleExpression } from "./tupleExpressions.js";
|
|
6
|
+
import { parseTupleLiteral } from "./tupleLiteral.js";
|
|
7
|
+
const parseCache = {};
|
|
8
|
+
export const parseInnerDefinition = (def, ctx) => {
|
|
9
|
+
if (typeof def === "string") {
|
|
10
|
+
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
11
|
+
// we can only rely on the cache if there are no contextual
|
|
12
|
+
// resolutions like "this" or generic args
|
|
13
|
+
return parseString(def, ctx);
|
|
14
|
+
}
|
|
15
|
+
// include parseConfigHash in cacheId to ensure that if global config
|
|
16
|
+
// is updated, we reparse strings
|
|
17
|
+
const cacheId = `${ctx.$.id}:${ctx.$.configSnapshot.hash}`;
|
|
18
|
+
const scopeCache = (parseCache[cacheId] ??= {});
|
|
19
|
+
const cachedResult = scopeCache[def];
|
|
20
|
+
if (cachedResult) {
|
|
21
|
+
// even though we know $ is the same, we still need to call bindReference
|
|
22
|
+
// to ensure config changes have been reflected
|
|
23
|
+
if (isNode(cachedResult))
|
|
24
|
+
scopeCache[def] = ctx.$.bindReference(cachedResult);
|
|
25
|
+
else {
|
|
26
|
+
// update node element of optional or defaultable tuple
|
|
27
|
+
;
|
|
28
|
+
cachedResult[0] = ctx.$.bindReference(cachedResult[0]);
|
|
29
|
+
}
|
|
30
|
+
return scopeCache[def];
|
|
31
|
+
}
|
|
32
|
+
// if we're parsing from scratch, we don't need to worry about binding
|
|
33
|
+
return (scopeCache[def] ??= parseString(def, ctx));
|
|
34
|
+
}
|
|
35
|
+
return hasDomain(def, "object") ?
|
|
36
|
+
parseObject(def, ctx)
|
|
37
|
+
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
38
|
+
};
|
|
5
39
|
export const parseObject = (def, ctx) => {
|
|
6
40
|
const objectKind = objectKindOf(def);
|
|
7
41
|
switch (objectKind) {
|
|
@@ -26,4 +60,5 @@ export const parseObject = (def, ctx) => {
|
|
|
26
60
|
return throwParseError(writeBadDefinitionTypeMessage(objectKind ?? printable(def)));
|
|
27
61
|
}
|
|
28
62
|
};
|
|
63
|
+
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
|
|
29
64
|
export const writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { type BaseParseContext, type BaseRoot, type
|
|
2
|
-
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type
|
|
3
|
-
import type { constrain } from "../keywords/inference.ts";
|
|
4
|
-
import type { astToString } from "./ast/utils.ts";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeChar, type Key, type merge, type show } from "@ark/util";
|
|
5
3
|
import type { validateString } from "./ast/validate.ts";
|
|
6
|
-
import type { inferDefinition
|
|
4
|
+
import type { inferDefinition } from "./definition.ts";
|
|
5
|
+
import { type OptionalPropertyDefinition, type validateProperty } from "./property.ts";
|
|
7
6
|
export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
|
|
8
|
-
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
9
|
-
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
10
7
|
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
11
8
|
/**
|
|
12
9
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
13
10
|
*/
|
|
14
11
|
type _inferObjectLiteral<def extends object, $, args> = {
|
|
15
|
-
-readonly [k in keyof def as
|
|
16
|
-
def[k]
|
|
17
|
-
] extends [anyOrNever] ? def[k] : inferDefinition<def[k], $, args>;
|
|
12
|
+
-readonly [k in keyof def as nonOptionalKeyFromEntry<k, def[k], $, args>]: inferDefinition<def[k], $, args>;
|
|
18
13
|
} & {
|
|
19
|
-
-readonly [k in keyof def as
|
|
14
|
+
-readonly [k in keyof def as optionalKeyFromEntry<k, def[k]>]?: def[k] extends OptionalPropertyDefinition<infer baseDef> ? inferDefinition<baseDef, $, args> : inferDefinition<def[k], $, args>;
|
|
20
15
|
};
|
|
21
16
|
export type validateObjectLiteral<def, $, args> = {
|
|
22
|
-
[k in keyof def]: k extends
|
|
17
|
+
[k in keyof def]: preparseKey<k> extends (infer parsedKey extends PreparsedKey) ? parsedKey extends PreparsedEntryKey<"index"> ? validateString<parsedKey["normalized"], $, args> extends (ErrorMessage<infer message>) ? ErrorType<message> : inferDefinition<parsedKey["normalized"], $, args> extends Key ? validateProperty<def[k], parsedKey["kind"], $, args> : ErrorMessage<writeInvalidPropertyKeyMessage<parsedKey["normalized"]>> : validateProperty<def[k], parsedKey["kind"], $, args> : never;
|
|
23
18
|
};
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
type nonOptionalKeyFromEntry<k extends PropertyKey, v, $, args> = preparseKey<k> extends (infer parsedKey extends PreparsedEntryKey<"required" | "index">) ? parsedKey["kind"] extends "index" ? inferDefinition<parsedKey["normalized"], $, args> & Key : [v] extends [OptionalPropertyDefinition] ? [
|
|
20
|
+
v
|
|
21
|
+
] extends [anyOrNever] ? parsedKey["normalized"] : never : parsedKey["normalized"] : never;
|
|
22
|
+
type optionalKeyFromEntry<k extends PropertyKey, v> = preparseKey<k> extends PreparsedEntryKey<"optional", infer name> ? name : v extends OptionalPropertyDefinition ? k : never;
|
|
23
|
+
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
24
|
+
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
25
|
+
export type PreparsedKey = PreparsedEntryKey | PreparsedSpecialKey;
|
|
26
|
+
type normalizedKeyKind<kind extends EntryKeyKind> = kind extends "index" ? string : Key;
|
|
27
|
+
export type PreparsedEntryKey<kind extends EntryKeyKind = EntryKeyKind, normalized extends normalizedKeyKind<kind> = normalizedKeyKind<kind>> = {
|
|
28
|
+
kind: kind;
|
|
29
|
+
normalized: normalized;
|
|
30
|
+
};
|
|
31
|
+
export type PreparsedSpecialKey<kind extends SpecialKeyKind = SpecialKeyKind> = {
|
|
27
32
|
kind: kind;
|
|
28
|
-
key: key;
|
|
29
33
|
};
|
|
30
34
|
declare namespace PreparsedKey {
|
|
31
35
|
type from<t extends PreparsedKey> = t;
|
|
32
36
|
}
|
|
33
|
-
type ParsedKeyKind =
|
|
37
|
+
export type ParsedKeyKind = EntryKeyKind | SpecialKeyKind;
|
|
38
|
+
export type EntryKeyKind = "required" | "optional" | "index";
|
|
39
|
+
export type SpecialKeyKind = "spread" | "undeclared";
|
|
34
40
|
export type MetaKey = "..." | "+";
|
|
35
41
|
export type IndexKey<def extends string = string> = `[${def}]`;
|
|
36
|
-
export
|
|
37
|
-
export type
|
|
38
|
-
kind: "undeclared";
|
|
39
|
-
behavior: UndeclaredKeyBehavior;
|
|
40
|
-
};
|
|
41
|
-
export type ParsedSpreadEntry = {
|
|
42
|
-
kind: "spread";
|
|
43
|
-
node: BaseRoot;
|
|
44
|
-
};
|
|
45
|
-
export declare const parseEntry: (key: Key, value: unknown, ctx: BaseParseContext) => listable<ParsedEntry>;
|
|
46
|
-
declare const parseKey: (key: Key) => PreparsedKey;
|
|
47
|
-
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
|
|
42
|
+
export declare const preparseKey: (key: Key) => PreparsedKey;
|
|
43
|
+
export type preparseKey<k> = k extends symbol ? PreparsedKey.from<{
|
|
48
44
|
kind: "required";
|
|
49
|
-
|
|
45
|
+
normalized: k;
|
|
46
|
+
}> : k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeChar}` ? PreparsedKey.from<{
|
|
47
|
+
kind: "required";
|
|
48
|
+
normalized: `${baseName}?`;
|
|
50
49
|
}> : PreparsedKey.from<{
|
|
51
50
|
kind: "optional";
|
|
52
|
-
|
|
53
|
-
}> : k extends
|
|
54
|
-
kind:
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
normalized: inner;
|
|
52
|
+
}> : k extends "+" ? {
|
|
53
|
+
kind: "undeclared";
|
|
54
|
+
} : k extends "..." ? {
|
|
55
|
+
kind: "spread";
|
|
56
|
+
} : k extends `${EscapeChar}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
|
|
57
57
|
kind: "required";
|
|
58
|
-
|
|
58
|
+
normalized: escapedMeta;
|
|
59
59
|
}> : k extends IndexKey<infer def> ? PreparsedKey.from<{
|
|
60
60
|
kind: "index";
|
|
61
|
-
|
|
61
|
+
normalized: def;
|
|
62
62
|
}> : PreparsedKey.from<{
|
|
63
63
|
kind: "required";
|
|
64
|
-
|
|
64
|
+
normalized: k extends (`${EscapeChar}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
65
65
|
}>;
|
|
66
66
|
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
67
|
-
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
67
|
+
export type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
68
68
|
export {};
|