arktype 2.0.0-rc.3 → 2.0.0-rc.30
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/config.d.ts +1 -1
- package/out/generic.d.ts +55 -58
- package/out/generic.js +6 -8
- package/out/index.d.ts +6 -4
- package/out/index.js +4 -3
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
- package/out/keywords/{constructors/Array.js → Array.js} +7 -7
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
- package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
- 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 -2
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +29 -0
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +24 -2
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +42 -4
- package/out/keywords/ts.js +24 -7
- package/out/methods/array.d.ts +12 -0
- package/out/methods/base.d.ts +178 -0
- package/out/methods/date.d.ts +10 -0
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +11 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +12 -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/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +25 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +30 -0
- package/out/parser/ast/validate.js +3 -0
- package/out/parser/definition.d.ts +21 -13
- package/out/parser/definition.js +20 -2
- package/out/parser/objectLiteral.d.ts +41 -67
- package/out/parser/objectLiteral.js +79 -71
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
- 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 +4 -4
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/shift/operand/operand.d.ts +9 -0
- package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
- package/out/parser/{string/shift → 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/{string/shift → shift}/operator/default.d.ts +4 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +14 -0
- package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +47 -0
- package/out/parser/shift/scanner.js +43 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
- package/out/parser/{string/string.js → string.js} +19 -0
- package/out/parser/tupleExpressions.d.ts +47 -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 +41 -34
- package/out/scope.js +54 -62
- package/out/type.d.ts +46 -22
- package/out/type.js +15 -11
- 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/ark.js +0 -24
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -10
- 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 -28
- package/out/keywords/number/number.js +0 -9
- 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 -59
- 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 -15
- package/out/keywords/string/json.js +0 -45
- 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 -92
- 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 -112
- 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/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.d.ts +0 -26
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -9
- package/out/parser/string/shift/operator/operator.d.ts +0 -13
- package/out/parser/string/shift/scanner.d.ts +0 -69
- package/out/parser/string/shift/scanner.js +0 -100
- package/out/parser/tuple.d.ts +0 -132
- package/out/parser/tuple.js +0 -158
- package/out/subtypes/array.d.ts +0 -13
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/date.d.ts +0 -11
- 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/{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/{intersect.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/{keys.js → parser/ast/generic.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}/operator/divisor.js +0 -0
|
@@ -1,94 +1,68 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type anyOrNever, type
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type
|
|
6
|
-
|
|
7
|
-
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
9
|
-
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
10
|
-
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
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";
|
|
3
|
+
import type { validateString } from "./ast/validate.ts";
|
|
4
|
+
import type { inferDefinition } from "./definition.ts";
|
|
5
|
+
import { type OptionalPropertyDefinition, type validateProperty } from "./property.ts";
|
|
6
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
|
|
11
7
|
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
12
8
|
/**
|
|
13
9
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
14
10
|
*/
|
|
15
11
|
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
-
-readonly [k in keyof def as
|
|
17
|
-
def[k]
|
|
18
|
-
] extends [anyOrNever] ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : inferDefinition<def[k], $, args>;
|
|
12
|
+
-readonly [k in keyof def as nonOptionalKeyFromEntry<k, def[k], $, args>]: inferDefinition<def[k], $, args>;
|
|
19
13
|
} & {
|
|
20
|
-
-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>;
|
|
21
15
|
};
|
|
22
16
|
export type validateObjectLiteral<def, $, args> = {
|
|
23
|
-
[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;
|
|
24
18
|
};
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
] extends [anyOrNever] ?
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
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
|
-
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
50
|
-
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
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> = {
|
|
51
32
|
kind: kind;
|
|
52
|
-
key: key;
|
|
53
33
|
};
|
|
54
34
|
declare namespace PreparsedKey {
|
|
55
35
|
type from<t extends PreparsedKey> = t;
|
|
56
36
|
}
|
|
57
|
-
type ParsedKeyKind =
|
|
37
|
+
export type ParsedKeyKind = EntryKeyKind | SpecialKeyKind;
|
|
38
|
+
export type EntryKeyKind = "required" | "optional" | "index";
|
|
39
|
+
export type SpecialKeyKind = "spread" | "undeclared";
|
|
58
40
|
export type MetaKey = "..." | "+";
|
|
59
41
|
export type IndexKey<def extends string = string> = `[${def}]`;
|
|
60
|
-
export
|
|
61
|
-
export type
|
|
62
|
-
kind: "undeclared";
|
|
63
|
-
behavior: UndeclaredKeyBehavior;
|
|
64
|
-
};
|
|
65
|
-
export type ParsedSpreadEntry = {
|
|
66
|
-
kind: "spread";
|
|
67
|
-
node: BaseRoot;
|
|
68
|
-
};
|
|
69
|
-
export declare const parseEntry: (key: Key, value: unknown, ctx: ParseContext) => listable<ParsedEntry>;
|
|
70
|
-
export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
|
|
71
|
-
export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
|
|
72
|
-
declare const parseKey: (key: Key) => PreparsedKey;
|
|
73
|
-
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<{
|
|
74
44
|
kind: "required";
|
|
75
|
-
|
|
45
|
+
normalized: k;
|
|
46
|
+
}> : k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeChar}` ? PreparsedKey.from<{
|
|
47
|
+
kind: "required";
|
|
48
|
+
normalized: `${baseName}?`;
|
|
76
49
|
}> : PreparsedKey.from<{
|
|
77
50
|
kind: "optional";
|
|
78
|
-
|
|
79
|
-
}> : k extends
|
|
80
|
-
kind:
|
|
81
|
-
|
|
82
|
-
|
|
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<{
|
|
83
57
|
kind: "required";
|
|
84
|
-
|
|
58
|
+
normalized: escapedMeta;
|
|
85
59
|
}> : k extends IndexKey<infer def> ? PreparsedKey.from<{
|
|
86
60
|
kind: "index";
|
|
87
|
-
|
|
61
|
+
normalized: def;
|
|
88
62
|
}> : PreparsedKey.from<{
|
|
89
63
|
kind: "required";
|
|
90
|
-
|
|
64
|
+
normalized: k extends (`${EscapeChar}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
91
65
|
}>;
|
|
92
66
|
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
93
|
-
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})`;
|
|
94
68
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { append,
|
|
3
|
-
import {
|
|
1
|
+
import { normalizeIndex } from "@ark/schema";
|
|
2
|
+
import { append, escapeChar, isArray, isEmptyObject, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
|
|
3
|
+
import { invalidDefaultableKeyKindMessage, invalidOptionalKeyKindMessage, parseProperty } from "./property.js";
|
|
4
4
|
export const parseObjectLiteral = (def, ctx) => {
|
|
5
5
|
let spread;
|
|
6
6
|
const structure = {};
|
|
@@ -8,92 +8,100 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
8
8
|
// because to match JS behavior any keys before the spread are overwritten
|
|
9
9
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
10
10
|
// anywhere except for the beginning.
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const defEntries = stringAndSymbolicEntriesOf(def);
|
|
12
|
+
for (const [k, v] of defEntries) {
|
|
13
|
+
const parsedKey = preparseKey(k);
|
|
14
|
+
if (parsedKey.kind === "spread") {
|
|
15
|
+
if (!isEmptyObject(structure))
|
|
16
|
+
return throwParseError(nonLeadingSpreadError);
|
|
17
|
+
const operand = ctx.$.parseOwnDefinitionFormat(v, ctx);
|
|
18
|
+
if (!operand.hasKind("intersection") || !operand.structure) {
|
|
19
|
+
return throwParseError(writeInvalidSpreadTypeMessage(operand.expression));
|
|
20
|
+
}
|
|
21
|
+
spread = operand.structure;
|
|
22
|
+
continue;
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (parsedKey.kind === "undeclared") {
|
|
25
|
+
if (v !== "reject" && v !== "delete" && v !== "ignore")
|
|
26
|
+
throwParseError(writeInvalidUndeclaredBehaviorMessage(v));
|
|
27
|
+
structure.undeclared = v;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const parsedValue = parseProperty(v, ctx);
|
|
31
|
+
const parsedEntryKey = parsedKey;
|
|
32
|
+
if (parsedKey.kind === "required") {
|
|
33
|
+
if (!isArray(parsedValue)) {
|
|
34
|
+
appendNamedProp(structure, "required", {
|
|
35
|
+
key: parsedKey.normalized,
|
|
36
|
+
value: parsedValue
|
|
37
|
+
}, ctx);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
appendNamedProp(structure, "optional", parsedValue[1] === "=" ?
|
|
41
|
+
{
|
|
42
|
+
key: parsedKey.normalized,
|
|
43
|
+
value: parsedValue[0],
|
|
44
|
+
default: parsedValue[2]
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
key: parsedKey.normalized,
|
|
48
|
+
value: parsedValue[0]
|
|
49
|
+
}, ctx);
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (isArray(parsedValue)) {
|
|
54
|
+
if (parsedValue[1] === "?")
|
|
55
|
+
throwParseError(invalidOptionalKeyKindMessage);
|
|
56
|
+
if (parsedValue[1] === "=")
|
|
57
|
+
throwParseError(invalidDefaultableKeyKindMessage);
|
|
58
|
+
}
|
|
59
|
+
// value must be a BaseRoot at this point
|
|
60
|
+
if (parsedKey.kind === "optional") {
|
|
61
|
+
appendNamedProp(structure, "optional", {
|
|
62
|
+
key: parsedKey.normalized,
|
|
63
|
+
value: parsedValue
|
|
64
|
+
}, ctx);
|
|
27
65
|
continue;
|
|
28
66
|
}
|
|
29
|
-
|
|
67
|
+
// must be index at this point
|
|
68
|
+
const signature = ctx.$.parseOwnDefinitionFormat(parsedEntryKey.normalized, ctx);
|
|
69
|
+
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
70
|
+
if (normalized.index)
|
|
71
|
+
structure.index = append(structure.index, normalized.index);
|
|
72
|
+
if (normalized.required)
|
|
73
|
+
structure.required = append(structure.required, normalized.required);
|
|
30
74
|
}
|
|
31
75
|
const structureNode = ctx.$.node("structure", structure);
|
|
32
|
-
return ctx.$.
|
|
76
|
+
return ctx.$.parseSchema({
|
|
33
77
|
domain: "object",
|
|
34
78
|
structure: spread?.merge(structureNode) ?? structureNode
|
|
35
79
|
});
|
|
36
80
|
};
|
|
81
|
+
const appendNamedProp = (structure, kind, inner, ctx) => {
|
|
82
|
+
structure[kind] = append(
|
|
83
|
+
// doesn't seem like this cast should be necessary
|
|
84
|
+
structure[kind], ctx.$.node(kind, inner));
|
|
85
|
+
};
|
|
37
86
|
export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
|
|
38
87
|
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
39
|
-
export const
|
|
40
|
-
const parsedKey = parseKey(key);
|
|
41
|
-
if (parsedKey.kind === "+") {
|
|
42
|
-
if (value !== "reject" && value !== "delete" && value !== "ignore")
|
|
43
|
-
throwParseError(writeInvalidUndeclaredBehaviorMessage(value));
|
|
44
|
-
return { kind: "undeclared", behavior: value };
|
|
45
|
-
}
|
|
46
|
-
if (parsedKey.kind === "...")
|
|
47
|
-
return { kind: "spread", node: ctx.$.parse(value, ctx) };
|
|
48
|
-
const parsedValue = isArray(value) && value[1] === "=" ?
|
|
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
|
-
}
|
|
64
|
-
if (parsedKey.kind === "index") {
|
|
65
|
-
const signature = ctx.$.parse(parsedKey.key, ctx);
|
|
66
|
-
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
67
|
-
return (normalized.index ?
|
|
68
|
-
normalized.required ?
|
|
69
|
-
[normalized.index, ...normalized.required]
|
|
70
|
-
: normalized.index
|
|
71
|
-
: (normalized.required ?? []));
|
|
72
|
-
}
|
|
73
|
-
return ctx.$.node(parsedKey.kind, {
|
|
74
|
-
key: parsedKey.key,
|
|
75
|
-
value: parsedValue
|
|
76
|
-
});
|
|
77
|
-
};
|
|
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
|
-
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
88
|
+
export const preparseKey = (key) => typeof key === "symbol" ? { kind: "required", normalized: key }
|
|
81
89
|
: key.at(-1) === "?" ?
|
|
82
|
-
key.at(-2) ===
|
|
83
|
-
{ kind: "required",
|
|
90
|
+
key.at(-2) === escapeChar ?
|
|
91
|
+
{ kind: "required", normalized: `${key.slice(0, -2)}?` }
|
|
84
92
|
: {
|
|
85
93
|
kind: "optional",
|
|
86
|
-
|
|
94
|
+
normalized: key.slice(0, -1)
|
|
87
95
|
}
|
|
88
96
|
: key[0] === "[" && key.at(-1) === "]" ?
|
|
89
|
-
{ kind: "index",
|
|
90
|
-
: key[0] ===
|
|
91
|
-
{ kind: "required",
|
|
92
|
-
: key === "..." ? { kind:
|
|
93
|
-
: key === "+" ? { kind:
|
|
97
|
+
{ kind: "index", normalized: key.slice(1, -1) }
|
|
98
|
+
: key[0] === escapeChar && key[1] === "[" && key.at(-1) === "]" ?
|
|
99
|
+
{ kind: "required", normalized: key.slice(1) }
|
|
100
|
+
: key === "..." ? { kind: "spread" }
|
|
101
|
+
: key === "+" ? { kind: "undeclared" }
|
|
94
102
|
: {
|
|
95
103
|
kind: "required",
|
|
96
|
-
|
|
104
|
+
normalized: key === "\\..." ? "..."
|
|
97
105
|
: key === "\\+" ? "+"
|
|
98
106
|
: key
|
|
99
107
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BaseParseContext, BaseRoot, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type ErrorMessage, type ErrorType, type typeToString } from "@ark/util";
|
|
3
|
+
import { type inferDefinition, type validateInnerDefinition } from "./definition.ts";
|
|
4
|
+
import type { ParsedKeyKind, writeInvalidSpreadTypeMessage } from "./objectLiteral.ts";
|
|
5
|
+
import type { ParsedDefaultableProperty } from "./shift/operator/default.ts";
|
|
6
|
+
import type { parseString } from "./string.ts";
|
|
7
|
+
export type ParsedPropertyKind = "plain" | "optional" | "defaultable";
|
|
8
|
+
export type ParsedProperty = ParsedRequiredProperty | ParsedOptionalProperty | ParsedDefaultableProperty;
|
|
9
|
+
export type ParsedRequiredProperty = BaseRoot;
|
|
10
|
+
export type ParsedOptionalProperty = readonly [BaseRoot, "?"];
|
|
11
|
+
export declare const parseProperty: (def: unknown, ctx: BaseParseContext) => ParsedProperty;
|
|
12
|
+
export type validateProperty<def, keyKind extends ParsedKeyKind, $, args> = [
|
|
13
|
+
def
|
|
14
|
+
] extends [anyOrNever] ?
|
|
15
|
+
/** this extra [anyOrNever] check is required to ensure that nested `type` invocations
|
|
16
|
+
* like the following are not prematurely validated by the outer call:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* type({
|
|
20
|
+
* "test?": type("string").pipe(x => x === "true")
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
def : keyKind extends "spread" ? validateSpread<def, inferDefinition<def, $, args>, $, args> : keyKind extends "undeclared" ? UndeclaredKeyBehavior : keyKind extends "required" ? validateInnerDefinition<def, $, args> : def extends OptionalPropertyDefinition ? ErrorMessage<invalidOptionalKeyKindMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<invalidDefaultableKeyKindMessage> : validateInnerDefinition<def, $, args>;
|
|
25
|
+
export type isDefaultable<def, $, args> = def extends DefaultablePropertyTuple ? true : def extends PossibleDefaultableStringDefinition ? parseString<def, $, args> extends DefaultablePropertyTuple ? true : false : false;
|
|
26
|
+
type validateSpread<def, inferredProperty, $, args> = inferredProperty extends object ? validateInnerDefinition<def, $, args> : ErrorType<writeInvalidSpreadTypeMessage<typeToString<inferredProperty>>>;
|
|
27
|
+
export type OptionalPropertyDefinition<baseDef = unknown> = OptionalPropertyTuple<baseDef> | OptionalPropertyString<baseDef & string>;
|
|
28
|
+
export type OptionalPropertyString<baseDef extends string = string> = `${baseDef}?`;
|
|
29
|
+
export type OptionalPropertyTuple<baseDef = unknown> = readonly [baseDef, "?"];
|
|
30
|
+
export type PossibleDefaultableStringDefinition = `${string}=${string}`;
|
|
31
|
+
export type DefaultablePropertyTuple<baseDef = unknown, thunkableProperty = unknown> = readonly [baseDef, "=", thunkableProperty];
|
|
32
|
+
export declare const invalidOptionalKeyKindMessage = "Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }";
|
|
33
|
+
export type invalidOptionalKeyKindMessage = typeof invalidOptionalKeyKindMessage;
|
|
34
|
+
export declare const invalidDefaultableKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
|
|
35
|
+
export type invalidDefaultableKeyKindMessage = typeof invalidDefaultableKeyKindMessage;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isArray } from "@ark/util";
|
|
2
|
+
import { parseInnerDefinition } from "./definition.js";
|
|
3
|
+
export const parseProperty = (def, ctx) => {
|
|
4
|
+
if (isArray(def)) {
|
|
5
|
+
if (def[1] === "=")
|
|
6
|
+
return [ctx.$.parseOwnDefinitionFormat(def[0], ctx), "=", def[2]];
|
|
7
|
+
if (def[1] === "?")
|
|
8
|
+
return [ctx.$.parseOwnDefinitionFormat(def[0], ctx), "?"];
|
|
9
|
+
}
|
|
10
|
+
// string-embedded defaults/optionals are handled by the string parser
|
|
11
|
+
return parseInnerDefinition(def, ctx);
|
|
12
|
+
};
|
|
13
|
+
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
14
|
+
export const invalidOptionalKeyKindMessage = `Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }`;
|
|
15
|
+
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
16
|
+
export const invalidDefaultableKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
|
|
@@ -1,9 +1,7 @@
|
|
|
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 {
|
|
5
|
-
import type { InfixOperator } from "../../semantic/infer.ts";
|
|
6
|
-
import type { Scanner } from "../shift/scanner.ts";
|
|
3
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
4
|
+
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
7
5
|
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
8
6
|
type BranchState = {
|
|
9
7
|
prefixes: StringifiablePrefixOperator[];
|
|
@@ -13,20 +11,19 @@ type BranchState = {
|
|
|
13
11
|
};
|
|
14
12
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
15
13
|
export declare class DynamicState {
|
|
16
|
-
root: BaseRoot
|
|
14
|
+
root: BaseRoot | undefined;
|
|
17
15
|
branches: BranchState;
|
|
18
|
-
finalizer:
|
|
16
|
+
finalizer: ArkTypeScanner.FinalizingLookahead | undefined;
|
|
19
17
|
groups: BranchState[];
|
|
20
|
-
scanner:
|
|
21
|
-
ctx:
|
|
22
|
-
|
|
23
|
-
constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
|
|
18
|
+
scanner: ArkTypeScanner;
|
|
19
|
+
ctx: BaseParseContext;
|
|
20
|
+
constructor(scanner: ArkTypeScanner, ctx: BaseParseContext);
|
|
24
21
|
error(message: string): never;
|
|
25
22
|
hasRoot(): this is DynamicStateWithRoot;
|
|
26
23
|
setRoot(root: BaseRoot): void;
|
|
27
24
|
unsetRoot(): this["root"];
|
|
28
25
|
constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
|
|
29
|
-
finalize(finalizer:
|
|
26
|
+
finalize(finalizer: ArkTypeScanner.FinalizingLookahead): void;
|
|
30
27
|
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
|
|
31
28
|
finalizeBranches(): void;
|
|
32
29
|
finalizeGroup(): 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 | ArkTypeScanner.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,12 +1,12 @@
|
|
|
1
1
|
import type { Completion, ErrorMessage, defined } from "@ark/util";
|
|
2
|
-
import type { LimitLiteral } from "
|
|
3
|
-
import type {
|
|
2
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
3
|
+
import type { ArkTypeScanner } 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 = {
|
|
6
6
|
root: unknown;
|
|
7
7
|
branches: BranchState;
|
|
8
8
|
groups: BranchState[];
|
|
9
|
-
finalizer:
|
|
9
|
+
finalizer: ArkTypeScanner.FinalizingLookahead | ErrorMessage | undefined;
|
|
10
10
|
scanned: string;
|
|
11
11
|
unscanned: string;
|
|
12
12
|
};
|
|
@@ -151,7 +151,7 @@ export declare namespace state {
|
|
|
151
151
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
152
152
|
unscanned: unscanned;
|
|
153
153
|
}>;
|
|
154
|
-
type finalize<s extends StaticState, finalizer extends
|
|
154
|
+
type finalize<s extends StaticState, finalizer extends ArkTypeScanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
155
155
|
root: mergeToUnion<s>;
|
|
156
156
|
groups: s["groups"];
|
|
157
157
|
branches: initialBranches;
|
|
@@ -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,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { InferredAst } from "
|
|
1
|
+
import { type Scanner } from "@ark/util";
|
|
2
|
+
import type { InferredAst } from "../../ast/infer.ts";
|
|
3
3
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
4
4
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
6
6
|
export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
|
|
7
7
|
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
8
8
|
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
9
9
|
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
|
|
10
|
-
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> =
|
|
10
|
+
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = ArkTypeScanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends ArkTypeScanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string : Date, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends ArkTypeScanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
11
11
|
export declare const enclosingQuote: {
|
|
12
12
|
readonly "'": 1;
|
|
13
13
|
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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type WhitespaceChar } from "@ark/util";
|
|
2
|
+
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
3
|
+
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
+
import type { BaseCompletions } from "../../string.ts";
|
|
5
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
6
|
+
import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
|
|
7
|
+
import { parseUnenclosed } from "./unenclosed.ts";
|
|
8
|
+
export declare const parseOperand: (s: DynamicState) => void;
|
|
9
|
+
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (ArkTypeScanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { whitespaceChars } from "@ark/util";
|
|
2
2
|
import { enclosingChar, enclosingQuote, parseEnclosed } from "./enclosed.js";
|
|
3
3
|
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
|
|
4
4
|
export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
5
5
|
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
|
|
6
6
|
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
|
|
7
|
-
: s.scanner.lookaheadIsIn(
|
|
7
|
+
: s.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s.shiftedByOne())
|
|
8
8
|
: s.scanner.lookahead === "d" ?
|
|
9
9
|
s.scanner.nextLookahead in enclosingQuote ?
|
|
10
10
|
parseEnclosed(s, `${s.scanner.shift()}${s.scanner.shift()}`)
|
|
@@ -1,18 +1,20 @@
|
|
|
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
|
|
3
|
+
import type { ArkAmbient } from "../../../config.ts";
|
|
4
|
+
import type { resolutionToAst } from "../../../scope.ts";
|
|
5
|
+
import type { GenericInstantiationAst } from "../../ast/generic.ts";
|
|
6
|
+
import type { InferredAst } from "../../ast/infer.ts";
|
|
7
|
+
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
|
|
6
8
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
7
9
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
8
10
|
import type { BaseCompletions } from "../../string.ts";
|
|
9
|
-
import type {
|
|
11
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
10
12
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
|
|
11
13
|
export declare const parseUnenclosed: (s: DynamicState) => void;
|
|
12
|
-
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
14
|
+
export type parseUnenclosed<s extends StaticState, $, args> = ArkTypeScanner.shiftUntilNextTerminator<s["unscanned"]> extends (ArkTypeScanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends state.from<infer s> ? s : never : never;
|
|
13
15
|
type parseResolution<s extends StaticState, unscanned extends string, alias extends string, resolution, $, args> = resolutionToAst<alias, resolution> extends infer ast ? ast extends GenericAst ? parseGenericInstantiation<alias, ast, state.scanTo<s, unscanned>, $, args> : state.setRoot<s, ast, unscanned> : never;
|
|
14
16
|
export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot;
|
|
15
|
-
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> =
|
|
17
|
+
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> = ArkTypeScanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g, unscanned, $, args> extends infer result ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
|
|
16
18
|
]>>;
|
|
17
19
|
type tryResolve<s extends StaticState, unscanned extends string, token extends string, $, args> = token extends keyof args ? parseResolution<s, unscanned, token, args[token], $, args> : token extends keyof $ ? parseResolution<s, unscanned, token, $[token], $, args> : `#${token}` extends keyof $ ? parseResolution<s, unscanned, token, $[`#${token}`], $, args> : token extends keyof ArkAmbient.$ ? parseResolution<s, unscanned, token, ArkAmbient.$[token], $, args> : token extends NumberLiteral<infer n> ? state.setRoot<s, InferredAst<n, token>, unscanned> : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? tryResolveSubmodule<token, $[submodule], reference, s, unscanned, $, args, [
|
|
18
20
|
submodule
|
|
@@ -27,7 +29,13 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
|
|
|
27
29
|
]> : unresolvableState<s, reference, resolution, {}, submodulePath> : state.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
|
|
28
30
|
/** Provide valid completions for the current token, or fallback to an
|
|
29
31
|
* unresolvable error if there are none */
|
|
30
|
-
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> =
|
|
32
|
+
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
|
|
33
|
+
token,
|
|
34
|
+
s["unscanned"]
|
|
35
|
+
] extends ([
|
|
36
|
+
"",
|
|
37
|
+
ArkTypeScanner.shift<"#", infer unscanned>
|
|
38
|
+
]) ? ArkTypeScanner.shiftUntilNextTerminator<unscanned> extends (ArkTypeScanner.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
39
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
32
40
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
|
|
33
41
|
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|