arktype 2.0.0-dev.2 → 2.0.0-dev.20
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/LICENSE +7 -0
- package/out/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/match.d.ts +18 -24
- package/out/match.js +50 -60
- package/out/module.d.ts +11 -0
- package/out/module.js +2 -0
- package/out/parser/definition.d.ts +13 -15
- package/out/parser/definition.js +10 -13
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +57 -18
- package/out/parser/objectLiteral.js +93 -52
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +16 -13
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/shared.d.ts +14 -28
- package/out/parser/string/reduce/shared.js +4 -3
- package/out/parser/string/reduce/static.d.ts +26 -23
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/string/shift/operand/enclosed.js +14 -14
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +9 -13
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -20
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +45 -56
- package/out/parser/string/shift/operator/divisor.d.ts +1 -3
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/scanner.d.ts +8 -7
- package/out/parser/string/shift/scanner.js +17 -16
- package/out/parser/string/string.d.ts +9 -7
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +101 -42
- package/out/parser/tuple.js +107 -86
- package/out/scope.d.ts +44 -115
- package/out/scope.js +39 -188
- package/out/type.d.ts +63 -61
- package/out/type.js +30 -135
- package/package.json +33 -39
- package/__tests__/array.test.ts +0 -310
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/badDefinitionType.test.ts +0 -51
- package/__tests__/basis.test.ts +0 -46
- package/__tests__/bounds.test.ts +0 -388
- package/__tests__/cast.test.ts +0 -32
- package/__tests__/completions.test.ts +0 -46
- package/__tests__/config.test.ts +0 -77
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -90
- package/__tests__/enclosed.test.ts +0 -93
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -138
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -294
- package/__tests__/group.test.ts +0 -72
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -113
- package/__tests__/instanceof.test.ts +0 -102
- package/__tests__/intersection.test.ts +0 -104
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/keyTraversal.test.ts +0 -74
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -224
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/narrow.test.ts +0 -102
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -301
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/regex.test.ts +0 -58
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -140
- package/__tests__/string.test.ts +0 -48
- package/__tests__/submodule.test.ts +0 -99
- package/__tests__/this.test.ts +0 -57
- package/__tests__/thunk.test.ts +0 -80
- package/__tests__/traverse.test.ts +0 -119
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/typeMethods.test.ts +0 -69
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -120
- package/__tests__/union.test.ts +0 -147
- package/ark.ts +0 -91
- package/main.ts +0 -18
- package/match.ts +0 -243
- package/out/ark.d.ts.map +0 -1
- package/out/ark.js.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts +0 -7
- package/out/main.d.ts.map +0 -1
- package/out/main.js +0 -4
- package/out/main.js.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/match.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/shared.d.ts +0 -56
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -55
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/type.js.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/definition.ts +0 -159
- package/parser/generic.ts +0 -68
- package/parser/objectLiteral.ts +0 -197
- package/parser/semantic/bounds.ts +0 -61
- package/parser/semantic/divisor.ts +0 -13
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -143
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -167
- package/parser/string/reduce/dynamic.ts +0 -196
- package/parser/string/reduce/shared.ts +0 -101
- package/parser/string/reduce/static.ts +0 -298
- package/parser/string/shift/operand/date.ts +0 -54
- package/parser/string/shift/operand/enclosed.ts +0 -118
- package/parser/string/shift/operand/genericArgs.ts +0 -127
- package/parser/string/shift/operand/operand.ts +0 -48
- package/parser/string/shift/operand/unenclosed.ts +0 -268
- package/parser/string/shift/operator/bounds.ts +0 -264
- package/parser/string/shift/operator/divisor.ts +0 -36
- package/parser/string/shift/operator/operator.ts +0 -82
- package/parser/string/shift/scanner.ts +0 -209
- package/parser/string/string.ts +0 -90
- package/parser/tuple.ts +0 -475
- package/scope.ts +0 -548
- package/type.ts +0 -349
- package/util.ts +0 -36
|
@@ -1,33 +1,72 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type Dict, type ErrorMessage, type
|
|
1
|
+
import { type BaseRoot, type Default, type of, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@arktype/schema";
|
|
2
|
+
import { type anyOrNever, type Dict, type ErrorMessage, type Key, type keyError, type merge, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
5
5
|
import type { astToString } from "./semantic/utils.js";
|
|
6
6
|
import type { validateString } from "./semantic/validate.js";
|
|
7
|
-
import {
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) =>
|
|
7
|
+
import { Scanner } from "./string/shift/scanner.js";
|
|
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";
|
|
11
|
+
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
9
12
|
/**
|
|
10
13
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
11
|
-
* You probably want to use {@link inferObjectLiteral} instead.
|
|
12
14
|
*/
|
|
13
|
-
type
|
|
14
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, def[k], $, args>
|
|
15
|
+
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
+
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (readonly [infer defaultableDef, "=", infer v]) ? def[k] extends anyOrNever ? def[k] : (In?: inferDefinition<defaultableDef, $, args>) => Default<v> : inferDefinition<def[k], $, args>;
|
|
15
17
|
} & {
|
|
16
|
-
-readonly [k in keyof def as optionalKeyFrom<k
|
|
18
|
+
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
17
19
|
};
|
|
18
|
-
export type inferObjectLiteral<def extends object, $, args> = evaluate<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, inferObjectLiteralInner<def, $, args>> : inferObjectLiteralInner<def, $, args>>;
|
|
19
20
|
export type validateObjectLiteral<def, $, args> = {
|
|
20
|
-
[k in keyof def]: k extends
|
|
21
|
+
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? keyError<message> : inferDefinition<indexDef, $, args> extends (PropertyKey | of<PropertyKey, {}>) ? validateDefinition<def[k], $, args> : keyError<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : keyError<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validatePossibleDefaultValue<def, k, $, args>;
|
|
21
22
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
type validatePossibleDefaultValue<def, k extends keyof def, $, args> = def[k] extends readonly [infer defaultDef, "=", unknown] ? parseKey<k>["kind"] extends "required" ? readonly [
|
|
24
|
+
validateDefinition<defaultDef, $, args>,
|
|
25
|
+
"=",
|
|
26
|
+
inferDefinition<defaultDef, $, args>
|
|
27
|
+
] : ErrorMessage<invalidDefaultKeyKindMessage> : validateDefinition<def[k], $, args>;
|
|
28
|
+
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 ? (t extends of<infer inner, any> ? Extract<inner, string> : Key) & t : never : never;
|
|
29
|
+
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
30
|
+
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, inner extends Key = Key> = {
|
|
31
|
+
kind: kind;
|
|
32
|
+
key: inner;
|
|
27
33
|
};
|
|
28
|
-
|
|
29
|
-
type
|
|
34
|
+
declare namespace PreparsedKey {
|
|
35
|
+
type from<t extends PreparsedKey> = t;
|
|
36
|
+
}
|
|
37
|
+
type ParsedKeyKind = "required" | "optional" | "index" | MetaKey;
|
|
38
|
+
export type MetaKey = "..." | "+";
|
|
39
|
+
export type IndexKey<def extends string = string> = `[${def}]`;
|
|
40
|
+
interface PreparsedEntry extends PreparsedKey {
|
|
41
|
+
value: unknown;
|
|
42
|
+
default: unknown;
|
|
43
|
+
}
|
|
44
|
+
export declare const parseEntry: ([key, value]: readonly [
|
|
45
|
+
Key,
|
|
46
|
+
unknown
|
|
47
|
+
]) => PreparsedEntry;
|
|
48
|
+
export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { ark: ['string', '=', '\u26F5'] }";
|
|
49
|
+
export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
|
|
50
|
+
declare const parseKey: (key: Key) => PreparsedKey;
|
|
51
|
+
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${Scanner.EscapeToken}` ? PreparsedKey.from<{
|
|
52
|
+
kind: "required";
|
|
53
|
+
key: `${baseName}?`;
|
|
54
|
+
}> : PreparsedKey.from<{
|
|
55
|
+
kind: "optional";
|
|
56
|
+
key: inner;
|
|
57
|
+
}> : k extends MetaKey ? PreparsedKey.from<{
|
|
58
|
+
kind: k;
|
|
59
|
+
key: k;
|
|
60
|
+
}> : k extends `${Scanner.EscapeToken}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
|
|
61
|
+
kind: "required";
|
|
62
|
+
key: escapedMeta;
|
|
63
|
+
}> : k extends IndexKey<infer def> ? PreparsedKey.from<{
|
|
64
|
+
kind: "index";
|
|
65
|
+
key: def;
|
|
66
|
+
}> : PreparsedKey.from<{
|
|
67
|
+
kind: "required";
|
|
68
|
+
key: k extends (`${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
69
|
+
}>;
|
|
30
70
|
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
31
71
|
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
32
72
|
export {};
|
|
33
|
-
//# sourceMappingURL=objectLiteral.d.ts.map
|
|
@@ -1,66 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { printable, throwParseError } from "@arktype/util";
|
|
3
|
-
import {
|
|
4
|
-
const stringAndSymbolicEntriesOf = (o) => [
|
|
5
|
-
...Object.entries(o),
|
|
6
|
-
...Object.getOwnPropertySymbols(o).map((k) => [k, o[k]])
|
|
7
|
-
];
|
|
1
|
+
import { ArkErrors, normalizeIndex } from "@arktype/schema";
|
|
2
|
+
import { append, isArray, printable, stringAndSymbolicEntriesOf, throwParseError, unset } from "@arktype/util";
|
|
3
|
+
import { Scanner } from "./string/shift/scanner.js";
|
|
8
4
|
export const parseObjectLiteral = (def, ctx) => {
|
|
9
|
-
|
|
10
|
-
const
|
|
5
|
+
let spread;
|
|
6
|
+
const structure = {};
|
|
11
7
|
// We only allow a spread operator to be used as the first key in an object
|
|
12
8
|
// because to match JS behavior any keys before the spread are overwritten
|
|
13
9
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
14
10
|
// anywhere except for the beginning.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry);
|
|
12
|
+
if (parsedEntries[0]?.kind === "...") {
|
|
13
|
+
// remove the spread entry so we can iterate over the remaining entries
|
|
14
|
+
// expecting non-spread entries
|
|
15
|
+
const spreadEntry = parsedEntries.shift();
|
|
16
|
+
const spreadNode = ctx.$.parse(spreadEntry.value, ctx);
|
|
17
|
+
if (!spreadNode.hasKind("intersection") || !spreadNode.structure) {
|
|
18
|
+
return throwParseError(writeInvalidSpreadTypeMessage(typeof spreadEntry.value === "string" ?
|
|
19
|
+
spreadEntry.value
|
|
20
|
+
: printable(spreadEntry.value)));
|
|
21
|
+
}
|
|
22
|
+
spread = spreadNode.structure;
|
|
23
|
+
}
|
|
24
|
+
for (const entry of parsedEntries) {
|
|
25
|
+
if (entry.kind === "...")
|
|
26
|
+
return throwParseError(nonLeadingSpreadError);
|
|
27
|
+
if (entry.kind === "+") {
|
|
28
|
+
if (entry.value !== "reject" &&
|
|
29
|
+
entry.value !== "delete" &&
|
|
30
|
+
entry.value !== "ignore")
|
|
31
|
+
throwParseError(writeInvalidUndeclaredBehaviorMessage(entry.value));
|
|
32
|
+
structure.undeclared = entry.value;
|
|
37
33
|
continue;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
if (entry.kind === "index") {
|
|
36
|
+
// handle key parsing first to match type behavior
|
|
37
|
+
const key = ctx.$.parse(entry.key, ctx);
|
|
38
|
+
const value = ctx.$.parse(entry.value, ctx);
|
|
39
|
+
const normalizedSignature = normalizeIndex(key, value, ctx.$);
|
|
40
|
+
if (normalizedSignature.required) {
|
|
41
|
+
structure.required = append(structure.required, normalizedSignature.required);
|
|
42
|
+
}
|
|
43
|
+
if (normalizedSignature.index)
|
|
44
|
+
structure.index = append(structure.index, normalizedSignature.index);
|
|
48
45
|
}
|
|
49
46
|
else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
const value = ctx.$.parse(entry.value, ctx);
|
|
48
|
+
const inner = { key: entry.key, value };
|
|
49
|
+
if (entry.default !== unset) {
|
|
50
|
+
const out = value(entry.default);
|
|
51
|
+
if (out instanceof ArkErrors)
|
|
52
|
+
throwParseError(`Default value at ${printable(entry.key)} ${out}`);
|
|
53
|
+
value.assert(entry.default);
|
|
54
|
+
inner.default = entry.default;
|
|
55
|
+
}
|
|
56
|
+
structure[entry.kind] = append(structure[entry.kind], inner);
|
|
54
57
|
}
|
|
55
|
-
ctx.path.pop();
|
|
56
|
-
hasSeenFirstKey ||= true;
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const structureNode = ctx.$.node("structure", structure);
|
|
60
|
+
return ctx.$.schema({
|
|
61
|
+
domain: "object",
|
|
62
|
+
structure: spread?.merge(structureNode) ?? structureNode
|
|
62
63
|
});
|
|
63
64
|
};
|
|
64
|
-
export const
|
|
65
|
+
export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
|
|
66
|
+
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
67
|
+
export const parseEntry = ([key, value]) => {
|
|
68
|
+
const parsedKey = parseKey(key);
|
|
69
|
+
if (isArray(value) && value[1] === "=") {
|
|
70
|
+
if (parsedKey.kind !== "required")
|
|
71
|
+
throwParseError(invalidDefaultKeyKindMessage);
|
|
72
|
+
return {
|
|
73
|
+
kind: "optional",
|
|
74
|
+
key: parsedKey.key,
|
|
75
|
+
value: value[0],
|
|
76
|
+
default: value[2]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
kind: parsedKey.kind,
|
|
81
|
+
key: parsedKey.key,
|
|
82
|
+
value,
|
|
83
|
+
default: unset
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
87
|
+
export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. { ark: ['string', '=', '⛵'] }`;
|
|
88
|
+
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
89
|
+
: key.at(-1) === "?" ?
|
|
90
|
+
key.at(-2) === Scanner.escapeToken ?
|
|
91
|
+
{ kind: "required", key: `${key.slice(0, -2)}?` }
|
|
92
|
+
: {
|
|
93
|
+
kind: "optional",
|
|
94
|
+
key: key.slice(0, -1)
|
|
95
|
+
}
|
|
96
|
+
: key[0] === "[" && key.at(-1) === "]" ?
|
|
97
|
+
{ kind: "index", key: key.slice(1, -1) }
|
|
98
|
+
: key[0] === Scanner.escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
99
|
+
{ kind: "required", key: key.slice(1) }
|
|
100
|
+
: key === "..." || key === "+" ? { kind: key, key }
|
|
101
|
+
: {
|
|
102
|
+
kind: "required",
|
|
103
|
+
key: key === "\\..." ? "..."
|
|
104
|
+
: key === "\\+" ? "+"
|
|
105
|
+
: key
|
|
106
|
+
};
|
|
65
107
|
export const writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
66
|
-
//# sourceMappingURL=objectLiteral.js.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ErrorMessage } from "@arktype/util";
|
|
3
|
-
import type { Comparator
|
|
4
|
-
import type { BoundExpressionKind, writeInvalidLimitMessage
|
|
5
|
-
import type {
|
|
1
|
+
import type { LimitLiteral, writeUnboundableMessage } from "@arktype/schema";
|
|
2
|
+
import type { ErrorMessage, array } from "@arktype/util";
|
|
3
|
+
import type { Comparator } from "../string/reduce/shared.js";
|
|
4
|
+
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.js";
|
|
5
|
+
import type { inferAstIn } from "./infer.js";
|
|
6
6
|
import type { astToString } from "./utils.js";
|
|
7
7
|
import type { validateAst } from "./validate.js";
|
|
8
|
-
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r,
|
|
9
|
-
export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> =
|
|
8
|
+
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r, comparator, l, "left", $, args> : l extends [infer leftAst, Comparator, unknown] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
|
|
9
|
+
export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> = inferAstIn<boundedAst, $, args> extends infer bounded ? isNumericallyBoundable<bounded> extends true ? limit extends number ? validateAst<boundedAst, $, args> : ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>> : bounded extends Date ? validateAst<boundedAst, $, args> : ErrorMessage<writeUnboundableMessage<astToString<boundKind extends "left" ? boundedAst[0 & keyof boundedAst] : boundedAst>>> : never;
|
|
10
|
+
type isNumericallyBoundable<bounded> = [
|
|
11
|
+
bounded
|
|
12
|
+
] extends [number] ? true : [bounded] extends [string] ? true : [bounded] extends [array] ? true : false;
|
|
10
13
|
export declare const writeDoubleRightBoundMessage: <root extends string>(root: root) => `Expression ${root} must have at most one right bound`;
|
|
11
14
|
type writeDoubleRightBoundMessage<root extends string> = `Expression ${root} must have at most one right bound`;
|
|
12
15
|
export {};
|
|
13
|
-
//# sourceMappingURL=bounds.d.ts.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { writeIndivisibleMessage } from "@arktype/schema";
|
|
1
|
+
import type { Root, writeIndivisibleMessage } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage } from "@arktype/util";
|
|
3
|
-
import type {
|
|
4
|
-
import type { astToString } from "./utils.js";
|
|
3
|
+
import type { inferAstIn } from "./infer.js";
|
|
5
4
|
import type { validateAst } from "./validate.js";
|
|
6
|
-
export type validateDivisor<l, $, args> =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=divisor.d.ts.map
|
|
5
|
+
export type validateDivisor<l, $, args> = inferAstIn<l, $, args> extends infer data ? [
|
|
6
|
+
data
|
|
7
|
+
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<Root<data>>> : never;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Date, DateLiteral, GenericProps, LimitLiteral, RegexLiteral, constrain, distillIn, inferIntersection, normalizeLimit, string } from "@arktype/schema";
|
|
2
|
+
import type { BigintLiteral, array } from "@arktype/util";
|
|
3
|
+
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.js";
|
|
4
|
+
import type { inferDefinition } from "../definition.js";
|
|
5
|
+
import type { Comparator, MinComparator } from "../string/reduce/shared.js";
|
|
6
|
+
import type { StringLiteral } from "../string/shift/operand/enclosed.js";
|
|
7
|
+
export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>;
|
|
8
|
+
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
|
|
9
|
+
export type inferConstrainableAst<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : ast extends string ? inferTerminal<ast, $, args> : never;
|
|
10
|
+
export type GenericInstantiationAst<generic extends GenericProps = GenericProps, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
11
|
+
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? inferDefinition<generic["def"], generic["$"]["t"] extends UnparsedScope ? $ : generic["$"]["t"], {
|
|
12
|
+
[i in keyof generic["params"] & `${number}` as generic["params"][i]]: inferConstrainableAst<argAsts[i & keyof argAsts], $, args>;
|
|
13
|
+
}> : ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[] : ast[1] extends "|" ? inferConstrainableAst<ast[0], $, args> | inferConstrainableAst<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferConstrainableAst<ast[0], $, args>, inferConstrainableAst<ast[2], $, args>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]> : ast[1] extends "%" ? constrain<inferConstrainableAst<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args> : never;
|
|
14
|
+
export type constrainBound<constrainableIn, comparator extends Comparator, limit> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : constrain<constrainableIn, "exactLength", limit & number> : constrain<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
15
|
+
rule: normalizeLimit<limit>;
|
|
16
|
+
exclusive: comparator extends ">" | "<" ? true : false;
|
|
17
|
+
}> : never;
|
|
18
|
+
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
19
|
+
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
20
|
+
export type PostfixOperator = "[]";
|
|
21
|
+
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
22
|
+
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
23
|
+
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
24
|
+
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Stringifiable } from "@arktype/util";
|
|
2
2
|
import type { Comparator } from "../string/reduce/shared.js";
|
|
3
|
-
import type { InfixExpression, PostfixExpression } from "./
|
|
4
|
-
export type astToString<ast> = `
|
|
5
|
-
type astToStringRecurse<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${groupAst<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${groupAst<l>}${operator}${groupAst<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
6
|
-
type groupAst<ast> = ast extends List ? ast[1] extends "[]" ? astToStringRecurse<ast> : `(${astToStringRecurse<ast>})` : astToStringRecurse<ast>;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
3
|
+
import type { InfixExpression, PostfixExpression } from "./infer.js";
|
|
4
|
+
export type astToString<ast> = 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,24 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { GenericProps } from "../../type.js";
|
|
1
|
+
import type { arkKind, GenericProps, PrivateDeclaration, writeMissingSubmoduleAccessMessage } from "@arktype/schema";
|
|
2
|
+
import type { anyOrNever, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, writeMalformedNumericLiteralMessage } from "@arktype/util";
|
|
4
3
|
import type { Comparator } from "../string/reduce/shared.js";
|
|
5
4
|
import type { writeInvalidGenericArgsMessage } from "../string/shift/operand/genericArgs.js";
|
|
6
|
-
import type { writeMissingSubmoduleAccessMessage } from "../string/shift/operand/unenclosed.js";
|
|
7
5
|
import type { parseString } from "../string/string.js";
|
|
8
6
|
import type { validateRange } from "./bounds.js";
|
|
9
7
|
import type { validateDivisor } from "./divisor.js";
|
|
10
|
-
import type { GenericInstantiationAst, InfixExpression, PostfixExpression } from "./
|
|
8
|
+
import type { GenericInstantiationAst, InfixExpression, PostfixExpression } from "./infer.js";
|
|
11
9
|
import type { astToString } from "./utils.js";
|
|
12
|
-
export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends readonly ["keyof", infer operand] ? validateAst<operand, $, args> : ast extends GenericInstantiationAst ? validateGenericArgs<ast[
|
|
10
|
+
export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends readonly ["keyof", infer operand] ? validateAst<operand, $, args> : ast extends GenericInstantiationAst ? validateGenericArgs<ast[2], $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
11
|
+
ast: ast;
|
|
12
|
+
};
|
|
13
13
|
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
14
|
-
type validateGenericArgs<argAsts extends unknown[], $, args> = argAsts extends [
|
|
15
|
-
infer head,
|
|
16
|
-
...infer tail
|
|
17
|
-
] ? validateAst<head, $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateGenericArgs<tail, $, args> : undefined;
|
|
14
|
+
type validateGenericArgs<argAsts extends unknown[], $, args> = argAsts extends [infer head, ...infer tail] ? validateAst<head, $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateGenericArgs<tail, $, args> : undefined;
|
|
18
15
|
export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) => `${expression} results in an unsatisfiable type`;
|
|
19
16
|
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
20
|
-
|
|
21
|
-
export type
|
|
17
|
+
export declare const writePrefixedPrivateReferenceMessage: <def extends `#${string}`>(def: def) => `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
18
|
+
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
19
|
+
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
|
|
20
|
+
$[alias]
|
|
21
|
+
] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends GenericProps ? ErrorMessage<writeInvalidGenericArgsMessage<def, $[alias]["params"], []>> : $[alias] extends {
|
|
22
|
+
[arkKind]: "module";
|
|
23
|
+
} ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
24
|
+
export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
|
|
25
|
+
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;
|
|
22
26
|
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateAst<ast[2], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : undefined;
|
|
23
27
|
export {};
|
|
24
|
-
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const writeUnsatisfiableExpressionError = (expression) => `${expression} results in an unsatisfiable type`;
|
|
2
|
-
|
|
2
|
+
export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot, LimitLiteral } from "@arktype/schema";
|
|
2
2
|
import { type requireKeys } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../../../scope.js";
|
|
4
|
+
import type { InfixOperator } from "../../semantic/infer.js";
|
|
4
5
|
import { Scanner } from "../shift/scanner.js";
|
|
5
|
-
import { type Comparator, type
|
|
6
|
+
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.js";
|
|
6
7
|
type BranchState = {
|
|
7
8
|
prefixes: StringifiablePrefixOperator[];
|
|
8
|
-
leftBound
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
leftBound: OpenLeftBound | null;
|
|
10
|
+
intersection: BaseRoot | null;
|
|
11
|
+
union: BaseRoot | null;
|
|
11
12
|
};
|
|
12
13
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
13
14
|
export declare class DynamicState {
|
|
14
15
|
readonly ctx: ParseContext;
|
|
15
16
|
readonly scanner: Scanner;
|
|
16
|
-
root:
|
|
17
|
+
root: BaseRoot<any> | undefined;
|
|
17
18
|
branches: BranchState;
|
|
18
19
|
finalizer: Scanner.FinalizingLookahead | undefined;
|
|
19
20
|
groups: BranchState[];
|
|
20
21
|
constructor(def: string, ctx: ParseContext);
|
|
21
22
|
error(message: string): never;
|
|
22
23
|
hasRoot(): this is DynamicStateWithRoot;
|
|
24
|
+
setRoot(root: BaseRoot): void;
|
|
23
25
|
unsetRoot(): this["root"];
|
|
24
|
-
constrainRoot(...args: Parameters<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): undefined;
|
|
26
|
+
constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
|
|
27
|
+
finalize(finalizer: Scanner.FinalizingLookahead): void;
|
|
28
|
+
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
|
|
28
29
|
finalizeBranches(): void;
|
|
29
|
-
finalizeGroup():
|
|
30
|
+
finalizeGroup(): void;
|
|
30
31
|
addPrefix(prefix: StringifiablePrefixOperator): void;
|
|
31
32
|
applyPrefixes(): void;
|
|
32
33
|
pushRootToBranch(token: "|" | "&"): void;
|
|
@@ -35,8 +36,7 @@ export declare class DynamicState {
|
|
|
35
36
|
parseOperand(): void;
|
|
36
37
|
private assertRangeUnset;
|
|
37
38
|
reduceGroupOpen(): void;
|
|
38
|
-
previousOperator():
|
|
39
|
+
previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
|
|
39
40
|
shiftedByOne(): this;
|
|
40
41
|
}
|
|
41
42
|
export {};
|
|
42
|
-
//# sourceMappingURL=dynamic.d.ts.map
|
|
@@ -7,9 +7,13 @@ import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, wr
|
|
|
7
7
|
export class DynamicState {
|
|
8
8
|
ctx;
|
|
9
9
|
scanner;
|
|
10
|
+
// set root type to `any` so that all constraints can be applied
|
|
10
11
|
root;
|
|
11
12
|
branches = {
|
|
12
|
-
prefixes: []
|
|
13
|
+
prefixes: [],
|
|
14
|
+
leftBound: null,
|
|
15
|
+
intersection: null,
|
|
16
|
+
union: null
|
|
13
17
|
};
|
|
14
18
|
finalizer;
|
|
15
19
|
groups = [];
|
|
@@ -23,29 +27,27 @@ export class DynamicState {
|
|
|
23
27
|
hasRoot() {
|
|
24
28
|
return this.root !== undefined;
|
|
25
29
|
}
|
|
30
|
+
setRoot(root) {
|
|
31
|
+
this.root = root;
|
|
32
|
+
}
|
|
26
33
|
unsetRoot() {
|
|
27
34
|
const value = this.root;
|
|
28
35
|
this.root = undefined;
|
|
29
36
|
return value;
|
|
30
37
|
}
|
|
31
38
|
constrainRoot(...args) {
|
|
32
|
-
this.root = this.root.constrain(
|
|
33
|
-
}
|
|
34
|
-
setRoot(root) {
|
|
35
|
-
this.root = root;
|
|
39
|
+
this.root = this.root.constrain(args[0], args[1]);
|
|
36
40
|
}
|
|
37
41
|
finalize(finalizer) {
|
|
38
|
-
if (this.groups.length)
|
|
42
|
+
if (this.groups.length)
|
|
39
43
|
return this.error(writeUnclosedGroupMessage(")"));
|
|
40
|
-
}
|
|
41
44
|
this.finalizeBranches();
|
|
42
45
|
this.finalizer = finalizer;
|
|
43
46
|
}
|
|
44
47
|
reduceLeftBound(limit, comparator) {
|
|
45
48
|
const invertedComparator = invertedComparators[comparator];
|
|
46
|
-
if (!isKeyOf(invertedComparator, minComparators))
|
|
49
|
+
if (!isKeyOf(invertedComparator, minComparators))
|
|
47
50
|
return this.error(writeUnpairableComparatorMessage(comparator));
|
|
48
|
-
}
|
|
49
51
|
if (this.branches.leftBound) {
|
|
50
52
|
return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
|
|
51
53
|
}
|
|
@@ -56,24 +58,22 @@ export class DynamicState {
|
|
|
56
58
|
}
|
|
57
59
|
finalizeBranches() {
|
|
58
60
|
this.assertRangeUnset();
|
|
59
|
-
if (this.branches
|
|
61
|
+
if (this.branches.union) {
|
|
60
62
|
this.pushRootToBranch("|");
|
|
61
|
-
this.root = this.branches
|
|
63
|
+
this.root = this.branches.union;
|
|
62
64
|
}
|
|
63
|
-
else if (this.branches
|
|
65
|
+
else if (this.branches.intersection) {
|
|
64
66
|
this.pushRootToBranch("&");
|
|
65
|
-
this.root = this.branches
|
|
67
|
+
this.root = this.branches.intersection;
|
|
66
68
|
}
|
|
67
|
-
else
|
|
69
|
+
else
|
|
68
70
|
this.applyPrefixes();
|
|
69
|
-
}
|
|
70
71
|
}
|
|
71
72
|
finalizeGroup() {
|
|
72
73
|
this.finalizeBranches();
|
|
73
74
|
const topBranchState = this.groups.pop();
|
|
74
|
-
if (!topBranchState)
|
|
75
|
+
if (!topBranchState)
|
|
75
76
|
return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned));
|
|
76
|
-
}
|
|
77
77
|
this.branches = topBranchState;
|
|
78
78
|
}
|
|
79
79
|
addPrefix(prefix) {
|
|
@@ -83,8 +83,8 @@ export class DynamicState {
|
|
|
83
83
|
while (this.branches.prefixes.length) {
|
|
84
84
|
const lastPrefix = this.branches.prefixes.pop();
|
|
85
85
|
this.root =
|
|
86
|
-
lastPrefix === "keyof"
|
|
87
|
-
|
|
86
|
+
lastPrefix === "keyof" ?
|
|
87
|
+
this.root.keyof()
|
|
88
88
|
: throwInternalError(`Unexpected prefix '${lastPrefix}'`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -92,11 +92,12 @@ export class DynamicState {
|
|
|
92
92
|
this.assertRangeUnset();
|
|
93
93
|
this.applyPrefixes();
|
|
94
94
|
const root = this.root;
|
|
95
|
-
this.branches
|
|
95
|
+
this.branches.intersection = this.branches.intersection?.and(root) ?? root;
|
|
96
96
|
if (token === "|") {
|
|
97
|
-
this.branches
|
|
98
|
-
this.branches
|
|
99
|
-
|
|
97
|
+
this.branches.union =
|
|
98
|
+
this.branches.union?.or(this.branches.intersection) ??
|
|
99
|
+
this.branches.intersection;
|
|
100
|
+
this.branches.intersection = null;
|
|
100
101
|
}
|
|
101
102
|
this.root = undefined;
|
|
102
103
|
}
|
|
@@ -117,17 +118,21 @@ export class DynamicState {
|
|
|
117
118
|
reduceGroupOpen() {
|
|
118
119
|
this.groups.push(this.branches);
|
|
119
120
|
this.branches = {
|
|
120
|
-
prefixes: []
|
|
121
|
+
prefixes: [],
|
|
122
|
+
leftBound: null,
|
|
123
|
+
union: null,
|
|
124
|
+
intersection: null
|
|
121
125
|
};
|
|
122
126
|
}
|
|
123
127
|
previousOperator() {
|
|
124
128
|
return (this.branches.leftBound?.comparator ??
|
|
125
129
|
this.branches.prefixes.at(-1) ??
|
|
126
|
-
(this.branches
|
|
130
|
+
(this.branches.intersection ? "&"
|
|
131
|
+
: this.branches.union ? "|"
|
|
132
|
+
: undefined));
|
|
127
133
|
}
|
|
128
134
|
shiftedByOne() {
|
|
129
135
|
this.scanner.shift();
|
|
130
136
|
return this;
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
|
-
//# sourceMappingURL=dynamic.js.map
|