arktype 2.2.10 → 3.0.0-beta.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/README.md +181 -15
- package/out/attributes.d.ts +50 -14
- package/out/checkers.d.ts +172 -0
- package/out/chunk-2U2AWCI3.js +626 -0
- package/out/chunk-4CUA5XIP.js +7 -0
- package/out/chunk-5U2ZMDNI.js +1566 -0
- package/out/chunk-DLWCO4RV.js +18 -0
- package/out/chunk-E3DZXEZK.js +72 -0
- package/out/chunk-EVCML554.js +47 -0
- package/out/chunk-G45P2CLE.js +63 -0
- package/out/chunk-GPNK5353.js +2529 -0
- package/out/chunk-MLKGABMK.js +9 -0
- package/out/chunk-NRIGTMPM.js +7 -0
- package/out/chunk-PRTMQCHS.js +3 -0
- package/out/chunk-R5G57XC7.js +7 -0
- package/out/chunk-RAZ3TXOE.js +313 -0
- package/out/chunk-SWOOCAHN.js +4 -0
- package/out/chunk-TAHPKDNM.js +3 -0
- package/out/chunk-UETB6YE2.js +14 -0
- package/out/chunk-UK5UGFOX.js +254 -0
- package/out/chunk-VV6YDN2D.js +6118 -0
- package/out/codecs.d.ts +21 -0
- package/out/codecs.js +7 -0
- package/out/config.d.ts +8 -3
- package/out/config.js +2 -3
- package/out/declare.d.ts +17 -3
- package/out/deferred.d.ts +10 -0
- package/out/errors.d.ts +1 -0
- package/out/errors.js +2 -0
- package/out/fn.d.ts +1 -1
- package/out/generic.d.ts +3 -3
- package/out/i18n.d.ts +2 -0
- package/out/i18n.js +2 -0
- package/out/index.d.ts +5 -4
- package/out/index.js +8 -9
- package/out/internal.d.ts +70 -0
- package/out/internal.js +17 -0
- package/out/island.d.ts +2 -0
- package/out/island.js +6 -0
- package/out/islandDependency.d.ts +2 -0
- package/out/islandDependency.js +18 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +5 -3
- package/out/keywords/constructors.d.ts +9 -1
- package/out/keywords/functions.d.ts +254 -0
- package/out/keywords/keywords.d.ts +8 -9
- package/out/keywords/number.d.ts +2 -8
- package/out/keywords/phrases.d.ts +245 -0
- package/out/keywords/string.d.ts +14 -113
- package/out/keywords/ts.d.ts +35 -33
- package/out/keywords/ts.js +4 -82
- package/out/locale.d.ts +19 -0
- package/out/locales/de.d.ts +2 -0
- package/out/locales/de.js +2 -0
- package/out/locales/en.d.ts +4 -0
- package/out/locales/en.js +5 -0
- package/out/match.d.ts +6 -6
- package/out/module.d.ts +1 -1
- package/out/mutatesInput.js +3 -0
- package/out/parser/ast/generic.d.ts +6 -3
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +11 -6
- package/out/parser/definition.d.ts +68 -7
- package/out/parser/objectLiteral.d.ts +40 -12
- package/out/parser/property.d.ts +3 -5
- package/out/parser/reduce/dynamic.d.ts +16 -7
- package/out/parser/reduce/shared.d.ts +4 -0
- package/out/parser/reduce/static.d.ts +13 -13
- package/out/parser/shift/operand/date.d.ts +0 -5
- package/out/parser/shift/operand/operand.d.ts +2 -1
- package/out/parser/shift/operand/unenclosed.d.ts +9 -6
- package/out/parser/shift/operand/unresolvable.d.ts +68 -0
- package/out/parser/shift/operator/bounds.d.ts +9 -4
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +9 -2
- package/out/parser/string.d.ts +61 -7
- package/out/parser/tupleExpressions.d.ts +7 -3
- package/out/precompiled.d.ts +1 -0
- package/out/precompiled.js +2 -0
- package/out/runtime.d.ts +181 -0
- package/out/runtime.js +4 -0
- package/out/runtimeDevelopment.d.ts +1 -0
- package/out/runtimeDevelopment.js +133 -0
- package/out/runtimeExports.d.ts +1 -0
- package/out/scope.d.ts +40 -11
- package/out/standalone/artifact.d.ts +265 -0
- package/out/standalone/baking.d.ts +201 -0
- package/out/standalone/combinators.d.ts +13 -0
- package/out/standalone/compilers.d.ts +23 -0
- package/out/standalone/creators.d.ts +41 -0
- package/out/standalone/fallbacks.d.ts +48 -0
- package/out/standalone/keys.d.ts +31 -0
- package/out/standalone/modules.d.ts +26 -0
- package/out/standalone/sites.d.ts +52 -0
- package/out/standalone/units.d.ts +31 -0
- package/out/standalone/values.d.ts +60 -0
- package/out/standalone.d.ts +16 -0
- package/out/type.d.ts +45 -6
- package/out/variants/array.d.ts +1 -1
- package/out/variants/base.d.ts +47 -27
- package/out/variants/date.d.ts +1 -1
- package/out/variants/instantiate.d.ts +4 -2
- package/out/variants/number.d.ts +1 -1
- package/out/variants/object.d.ts +17 -12
- package/out/variants/string.d.ts +1 -1
- package/package.json +169 -8
- package/skills/arktype/SKILL.md +278 -43
- package/skills/arktype/references/migrating.md +1296 -0
- package/skills/arktype/references/precompile.md +191 -0
- package/out/attributes.js +0 -3
- package/out/fn.js +0 -58
- package/out/generic.js +0 -37
- package/out/keywords/Array.js +0 -21
- package/out/keywords/FormData.js +0 -40
- package/out/keywords/TypedArray.js +0 -16
- package/out/keywords/builtins.js +0 -11
- package/out/keywords/constructors.js +0 -16
- package/out/keywords/keywords.js +0 -48
- package/out/keywords/number.js +0 -49
- package/out/keywords/string.js +0 -467
- package/out/match.js +0 -95
- package/out/module.js +0 -3
- package/out/nary.js +0 -1
- package/out/parser/ast/bounds.js +0 -1
- package/out/parser/ast/default.js +0 -1
- package/out/parser/ast/divisor.js +0 -1
- package/out/parser/ast/generic.js +0 -1
- package/out/parser/ast/infer.js +0 -1
- package/out/parser/ast/keyof.js +0 -1
- package/out/parser/ast/utils.js +0 -1
- package/out/parser/ast/validate.js +0 -3
- package/out/parser/definition.js +0 -78
- package/out/parser/objectLiteral.js +0 -113
- package/out/parser/property.js +0 -16
- package/out/parser/reduce/dynamic.js +0 -153
- package/out/parser/reduce/shared.js +0 -25
- package/out/parser/reduce/static.js +0 -1
- package/out/parser/shift/operand/date.js +0 -23
- package/out/parser/shift/operand/enclosed.js +0 -82
- package/out/parser/shift/operand/genericArgs.js +0 -16
- package/out/parser/shift/operand/operand.js +0 -16
- package/out/parser/shift/operand/unenclosed.js +0 -59
- package/out/parser/shift/operator/bounds.js +0 -91
- package/out/parser/shift/operator/brand.js +0 -6
- package/out/parser/shift/operator/default.js +0 -29
- package/out/parser/shift/operator/divisor.js +0 -13
- package/out/parser/shift/operator/operator.js +0 -28
- package/out/parser/shift/tokens.js +0 -37
- package/out/parser/string.js +0 -42
- package/out/parser/tupleExpressions.js +0 -75
- package/out/parser/tupleLiteral.js +0 -128
- package/out/scope.js +0 -106
- package/out/type.js +0 -55
- package/out/variants/array.js +0 -1
- package/out/variants/base.js +0 -1
- package/out/variants/date.js +0 -1
- package/out/variants/instantiate.js +0 -1
- package/out/variants/number.js +0 -1
- package/out/variants/object.js +0 -1
- package/out/variants/string.js +0 -1
- /package/out/{declare.js → mutatesInput.d.ts} +0 -0
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { intrinsic, normalizeIndex } from "@ark/schema";
|
|
2
|
-
import { append, Backslash, isArray, isEmptyObject, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
|
|
3
|
-
import { invalidDefaultableKeyKindMessage, invalidOptionalKeyKindMessage, parseProperty } from "./property.js";
|
|
4
|
-
export const parseObjectLiteral = (def, ctx) => {
|
|
5
|
-
let spread;
|
|
6
|
-
const structure = {};
|
|
7
|
-
// We only allow a spread operator to be used as the first key in an object
|
|
8
|
-
// because to match JS behavior any keys before the spread are overwritten
|
|
9
|
-
// by the values in the target object, so there'd be no useful purpose in having it
|
|
10
|
-
// anywhere except for the beginning.
|
|
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
|
-
// treat object domain as empty for spreading (useful for generic constraints)
|
|
19
|
-
if (operand.equals(intrinsic.object))
|
|
20
|
-
continue;
|
|
21
|
-
if (!operand.hasKind("intersection") ||
|
|
22
|
-
// still error on attempts to spread proto nodes like ...Date
|
|
23
|
-
!operand.basis?.equals(intrinsic.object)) {
|
|
24
|
-
return throwParseError(writeInvalidSpreadTypeMessage(operand.expression));
|
|
25
|
-
}
|
|
26
|
-
spread = operand.structure;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (parsedKey.kind === "undeclared") {
|
|
30
|
-
if (v !== "reject" && v !== "delete" && v !== "ignore")
|
|
31
|
-
throwParseError(writeInvalidUndeclaredBehaviorMessage(v));
|
|
32
|
-
structure.undeclared = v;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const parsedValue = parseProperty(v, ctx);
|
|
36
|
-
const parsedEntryKey = parsedKey;
|
|
37
|
-
if (parsedKey.kind === "required") {
|
|
38
|
-
if (!isArray(parsedValue)) {
|
|
39
|
-
appendNamedProp(structure, "required", {
|
|
40
|
-
key: parsedKey.normalized,
|
|
41
|
-
value: parsedValue
|
|
42
|
-
}, ctx);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
appendNamedProp(structure, "optional", parsedValue[1] === "=" ?
|
|
46
|
-
{
|
|
47
|
-
key: parsedKey.normalized,
|
|
48
|
-
value: parsedValue[0],
|
|
49
|
-
default: parsedValue[2]
|
|
50
|
-
}
|
|
51
|
-
: {
|
|
52
|
-
key: parsedKey.normalized,
|
|
53
|
-
value: parsedValue[0]
|
|
54
|
-
}, ctx);
|
|
55
|
-
}
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (isArray(parsedValue)) {
|
|
59
|
-
if (parsedValue[1] === "?")
|
|
60
|
-
throwParseError(invalidOptionalKeyKindMessage);
|
|
61
|
-
if (parsedValue[1] === "=")
|
|
62
|
-
throwParseError(invalidDefaultableKeyKindMessage);
|
|
63
|
-
}
|
|
64
|
-
// value must be a BaseRoot at this point
|
|
65
|
-
if (parsedKey.kind === "optional") {
|
|
66
|
-
appendNamedProp(structure, "optional", {
|
|
67
|
-
key: parsedKey.normalized,
|
|
68
|
-
value: parsedValue
|
|
69
|
-
}, ctx);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
// must be index at this point
|
|
73
|
-
const signature = ctx.$.parseOwnDefinitionFormat(parsedEntryKey.normalized, ctx);
|
|
74
|
-
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
75
|
-
if (normalized.index)
|
|
76
|
-
structure.index = append(structure.index, normalized.index);
|
|
77
|
-
if (normalized.required)
|
|
78
|
-
structure.required = append(structure.required, normalized.required);
|
|
79
|
-
}
|
|
80
|
-
const structureNode = ctx.$.node("structure", structure);
|
|
81
|
-
return ctx.$.parseSchema({
|
|
82
|
-
domain: "object",
|
|
83
|
-
structure: spread?.merge(structureNode) ?? structureNode
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const appendNamedProp = (structure, kind, inner, ctx) => {
|
|
87
|
-
structure[kind] = append(
|
|
88
|
-
// doesn't seem like this cast should be necessary
|
|
89
|
-
structure[kind], ctx.$.node(kind, inner));
|
|
90
|
-
};
|
|
91
|
-
export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
|
|
92
|
-
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
93
|
-
export const preparseKey = (key) => typeof key === "symbol" ? { kind: "required", normalized: key }
|
|
94
|
-
: key[key.length - 1] === "?" ?
|
|
95
|
-
key[key.length - 2] === Backslash ?
|
|
96
|
-
{ kind: "required", normalized: `${key.slice(0, -2)}?` }
|
|
97
|
-
: {
|
|
98
|
-
kind: "optional",
|
|
99
|
-
normalized: key.slice(0, -1)
|
|
100
|
-
}
|
|
101
|
-
: key[0] === "[" && key[key.length - 1] === "]" ?
|
|
102
|
-
{ kind: "index", normalized: key.slice(1, -1) }
|
|
103
|
-
: key[0] === Backslash && key[1] === "[" && key[key.length - 1] === "]" ?
|
|
104
|
-
{ kind: "required", normalized: key.slice(1) }
|
|
105
|
-
: key === "..." ? { kind: "spread" }
|
|
106
|
-
: key === "+" ? { kind: "undeclared" }
|
|
107
|
-
: {
|
|
108
|
-
kind: "required",
|
|
109
|
-
normalized: key === "\\..." ? "..."
|
|
110
|
-
: key === "\\+" ? "+"
|
|
111
|
-
: key
|
|
112
|
-
};
|
|
113
|
-
export const writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
package/out/parser/property.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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,153 +0,0 @@
|
|
|
1
|
-
import { isKeyOf, throwInternalError, throwParseError, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage } from "@ark/util";
|
|
2
|
-
import { parseOperand } from "../shift/operand/operand.js";
|
|
3
|
-
import { parseOperator } from "../shift/operator/operator.js";
|
|
4
|
-
import { parseUntilFinalizer } from "../string.js";
|
|
5
|
-
import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
6
|
-
export class RuntimeState {
|
|
7
|
-
root;
|
|
8
|
-
branches = {
|
|
9
|
-
prefixes: [],
|
|
10
|
-
leftBound: null,
|
|
11
|
-
intersection: null,
|
|
12
|
-
union: null,
|
|
13
|
-
pipe: null
|
|
14
|
-
};
|
|
15
|
-
finalizer;
|
|
16
|
-
groups = [];
|
|
17
|
-
scanner;
|
|
18
|
-
ctx;
|
|
19
|
-
constructor(scanner, ctx) {
|
|
20
|
-
this.scanner = scanner;
|
|
21
|
-
this.ctx = ctx;
|
|
22
|
-
}
|
|
23
|
-
error(message) {
|
|
24
|
-
return throwParseError(message);
|
|
25
|
-
}
|
|
26
|
-
hasRoot() {
|
|
27
|
-
return this.root !== undefined;
|
|
28
|
-
}
|
|
29
|
-
setRoot(root) {
|
|
30
|
-
this.root = root;
|
|
31
|
-
}
|
|
32
|
-
unsetRoot() {
|
|
33
|
-
const value = this.root;
|
|
34
|
-
this.root = undefined;
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
constrainRoot(...args) {
|
|
38
|
-
this.root = this.root.constrain(args[0], args[1]);
|
|
39
|
-
}
|
|
40
|
-
finalize(finalizer) {
|
|
41
|
-
if (this.groups.length)
|
|
42
|
-
return this.error(writeUnclosedGroupMessage(")"));
|
|
43
|
-
this.finalizeBranches();
|
|
44
|
-
this.finalizer = finalizer;
|
|
45
|
-
}
|
|
46
|
-
reduceLeftBound(limit, comparator) {
|
|
47
|
-
const invertedComparator = invertedComparators[comparator];
|
|
48
|
-
if (!isKeyOf(invertedComparator, minComparators))
|
|
49
|
-
return this.error(writeUnpairableComparatorMessage(comparator));
|
|
50
|
-
if (this.branches.leftBound) {
|
|
51
|
-
return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
|
|
52
|
-
}
|
|
53
|
-
this.branches.leftBound = {
|
|
54
|
-
comparator: invertedComparator,
|
|
55
|
-
limit
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
finalizeBranches() {
|
|
59
|
-
this.assertRangeUnset();
|
|
60
|
-
if (this.branches.pipe) {
|
|
61
|
-
this.pushRootToBranch("|>");
|
|
62
|
-
this.root = this.branches.pipe;
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (this.branches.union) {
|
|
66
|
-
this.pushRootToBranch("|");
|
|
67
|
-
this.root = this.branches.union;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (this.branches.intersection) {
|
|
71
|
-
this.pushRootToBranch("&");
|
|
72
|
-
this.root = this.branches.intersection;
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this.applyPrefixes();
|
|
76
|
-
}
|
|
77
|
-
finalizeGroup() {
|
|
78
|
-
this.finalizeBranches();
|
|
79
|
-
const topBranchState = this.groups.pop();
|
|
80
|
-
if (!topBranchState) {
|
|
81
|
-
return this.error(writeUnmatchedGroupCloseMessage(")", this.scanner.unscanned));
|
|
82
|
-
}
|
|
83
|
-
this.branches = topBranchState;
|
|
84
|
-
}
|
|
85
|
-
addPrefix(prefix) {
|
|
86
|
-
this.branches.prefixes.push(prefix);
|
|
87
|
-
}
|
|
88
|
-
applyPrefixes() {
|
|
89
|
-
while (this.branches.prefixes.length) {
|
|
90
|
-
const lastPrefix = this.branches.prefixes.pop();
|
|
91
|
-
this.root =
|
|
92
|
-
lastPrefix === "keyof" ?
|
|
93
|
-
this.root.keyof()
|
|
94
|
-
: throwInternalError(`Unexpected prefix '${lastPrefix}'`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
pushRootToBranch(token) {
|
|
98
|
-
this.assertRangeUnset();
|
|
99
|
-
this.applyPrefixes();
|
|
100
|
-
const root = this.root;
|
|
101
|
-
this.root = undefined;
|
|
102
|
-
this.branches.intersection =
|
|
103
|
-
this.branches.intersection?.rawAnd(root) ?? root;
|
|
104
|
-
if (token === "&")
|
|
105
|
-
return;
|
|
106
|
-
this.branches.union =
|
|
107
|
-
this.branches.union?.rawOr(this.branches.intersection) ??
|
|
108
|
-
this.branches.intersection;
|
|
109
|
-
this.branches.intersection = null;
|
|
110
|
-
if (token === "|")
|
|
111
|
-
return;
|
|
112
|
-
this.branches.pipe =
|
|
113
|
-
this.branches.pipe?.rawPipeOnce(this.branches.union) ??
|
|
114
|
-
this.branches.union;
|
|
115
|
-
this.branches.union = null;
|
|
116
|
-
}
|
|
117
|
-
parseUntilFinalizer() {
|
|
118
|
-
return parseUntilFinalizer(new RuntimeState(this.scanner, this.ctx));
|
|
119
|
-
}
|
|
120
|
-
parseOperator() {
|
|
121
|
-
return parseOperator(this);
|
|
122
|
-
}
|
|
123
|
-
parseOperand() {
|
|
124
|
-
return parseOperand(this);
|
|
125
|
-
}
|
|
126
|
-
assertRangeUnset() {
|
|
127
|
-
if (this.branches.leftBound) {
|
|
128
|
-
return this.error(writeOpenRangeMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
reduceGroupOpen() {
|
|
132
|
-
this.groups.push(this.branches);
|
|
133
|
-
this.branches = {
|
|
134
|
-
prefixes: [],
|
|
135
|
-
leftBound: null,
|
|
136
|
-
union: null,
|
|
137
|
-
intersection: null,
|
|
138
|
-
pipe: null
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
previousOperator() {
|
|
142
|
-
return (this.branches.leftBound?.comparator ??
|
|
143
|
-
this.branches.prefixes[this.branches.prefixes.length - 1] ??
|
|
144
|
-
(this.branches.intersection ? "&"
|
|
145
|
-
: this.branches.union ? "|"
|
|
146
|
-
: this.branches.pipe ? "|>"
|
|
147
|
-
: undefined));
|
|
148
|
-
}
|
|
149
|
-
shiftedBy(count) {
|
|
150
|
-
this.scanner.jumpForward(count);
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export const minComparators = {
|
|
2
|
-
">": true,
|
|
3
|
-
">=": true
|
|
4
|
-
};
|
|
5
|
-
export const maxComparators = {
|
|
6
|
-
"<": true,
|
|
7
|
-
"<=": true
|
|
8
|
-
};
|
|
9
|
-
export const comparators = {
|
|
10
|
-
">": true,
|
|
11
|
-
">=": true,
|
|
12
|
-
"<": true,
|
|
13
|
-
"<=": true,
|
|
14
|
-
"==": true
|
|
15
|
-
};
|
|
16
|
-
export const invertedComparators = {
|
|
17
|
-
"<": ">",
|
|
18
|
-
">": "<",
|
|
19
|
-
"<=": ">=",
|
|
20
|
-
">=": "<=",
|
|
21
|
-
"==": "=="
|
|
22
|
-
};
|
|
23
|
-
export const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
24
|
-
export const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
25
|
-
export const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { throwParseError, tryParseNumber } from "@ark/util";
|
|
2
|
-
export const isDateLiteral = (value) => typeof value === "string" &&
|
|
3
|
-
value[0] === "d" &&
|
|
4
|
-
(value[1] === "'" || value[1] === '"') &&
|
|
5
|
-
value[value.length - 1] === value[1];
|
|
6
|
-
export const isValidDate = (d) => d.toString() !== "Invalid Date";
|
|
7
|
-
export const extractDateLiteralSource = (literal) => literal.slice(2, -1);
|
|
8
|
-
export const writeInvalidDateMessage = (source) => `'${source}' could not be parsed by the Date constructor`;
|
|
9
|
-
export const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
|
|
10
|
-
const maybeParseDate = (source, errorOnFail) => {
|
|
11
|
-
const stringParsedDate = new Date(source);
|
|
12
|
-
if (isValidDate(stringParsedDate))
|
|
13
|
-
return stringParsedDate;
|
|
14
|
-
const epochMillis = tryParseNumber(source);
|
|
15
|
-
if (epochMillis !== undefined) {
|
|
16
|
-
const numberParsedDate = new Date(epochMillis);
|
|
17
|
-
if (isValidDate(numberParsedDate))
|
|
18
|
-
return numberParsedDate;
|
|
19
|
-
}
|
|
20
|
-
return errorOnFail ?
|
|
21
|
-
throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
|
|
22
|
-
: undefined;
|
|
23
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { Backslash, isKeyOf, throwParseError } from "@ark/util";
|
|
3
|
-
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
4
|
-
const regexExecArray = rootSchema({
|
|
5
|
-
proto: "Array",
|
|
6
|
-
sequence: "string",
|
|
7
|
-
required: {
|
|
8
|
-
key: "groups",
|
|
9
|
-
value: ["object", { unit: undefined }]
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
export const parseEnclosed = (s, enclosing) => {
|
|
13
|
-
const enclosed = s.scanner.shiftUntilEscapable(untilLookaheadIsClosing[enclosingTokens[enclosing]],
|
|
14
|
-
// within a regex literal, `\\` is a literal backslash and must be
|
|
15
|
-
// preserved verbatim in the pattern source; collapsing it to a single
|
|
16
|
-
// backslash would corrupt the regex (e.g. `\\d` -> `\d` digit class)
|
|
17
|
-
enclosing in enclosingRegexTokens ? Backslash : "");
|
|
18
|
-
if (s.scanner.lookahead === "")
|
|
19
|
-
return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
|
|
20
|
-
// Shift the scanner one additional time for the second enclosing token
|
|
21
|
-
s.scanner.shift();
|
|
22
|
-
if (enclosing in enclosingRegexTokens) {
|
|
23
|
-
let regex;
|
|
24
|
-
try {
|
|
25
|
-
regex = new RegExp(enclosed);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
throwParseError(String(e));
|
|
29
|
-
}
|
|
30
|
-
s.root = s.ctx.$.node("intersection", {
|
|
31
|
-
domain: "string",
|
|
32
|
-
pattern: enclosed
|
|
33
|
-
}, { prereduced: true });
|
|
34
|
-
if (enclosing === "x/") {
|
|
35
|
-
s.root = s.ctx.$.node("morph", {
|
|
36
|
-
in: s.root,
|
|
37
|
-
morphs: (s) => regex.exec(s),
|
|
38
|
-
declaredOut: regexExecArray
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else if (isKeyOf(enclosing, enclosingQuote))
|
|
43
|
-
s.root = s.ctx.$.node("unit", { unit: enclosed });
|
|
44
|
-
else {
|
|
45
|
-
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed));
|
|
46
|
-
s.root = s.ctx.$.node("unit", { meta: enclosed, unit: date });
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export const enclosingQuote = {
|
|
50
|
-
"'": 1,
|
|
51
|
-
'"': 1
|
|
52
|
-
};
|
|
53
|
-
export const enclosingChar = {
|
|
54
|
-
"/": 1,
|
|
55
|
-
"'": 1,
|
|
56
|
-
'"': 1
|
|
57
|
-
};
|
|
58
|
-
export const enclosingLiteralTokens = {
|
|
59
|
-
"d'": "'",
|
|
60
|
-
'd"': '"',
|
|
61
|
-
"'": "'",
|
|
62
|
-
'"': '"'
|
|
63
|
-
};
|
|
64
|
-
export const enclosingRegexTokens = {
|
|
65
|
-
"/": "/",
|
|
66
|
-
"x/": "/"
|
|
67
|
-
};
|
|
68
|
-
export const enclosingTokens = {
|
|
69
|
-
...enclosingLiteralTokens,
|
|
70
|
-
...enclosingRegexTokens
|
|
71
|
-
};
|
|
72
|
-
export const untilLookaheadIsClosing = {
|
|
73
|
-
"'": scanner => scanner.lookahead === `'`,
|
|
74
|
-
'"': scanner => scanner.lookahead === `"`,
|
|
75
|
-
"/": scanner => scanner.lookahead === `/`
|
|
76
|
-
};
|
|
77
|
-
const enclosingCharDescriptions = {
|
|
78
|
-
'"': "double-quote",
|
|
79
|
-
"'": "single-quote",
|
|
80
|
-
"/": "forward slash"
|
|
81
|
-
};
|
|
82
|
-
export const writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { writeUnclosedGroupMessage } from "@ark/util";
|
|
2
|
-
export const parseGenericArgs = (name, g, s) => _parseGenericArgs(name, g, s, []);
|
|
3
|
-
const _parseGenericArgs = (name, g, s, argNodes) => {
|
|
4
|
-
const argState = s.parseUntilFinalizer();
|
|
5
|
-
argNodes.push(argState.root);
|
|
6
|
-
if (argState.finalizer === ">") {
|
|
7
|
-
if (argNodes.length !== g.params.length) {
|
|
8
|
-
return s.error(writeInvalidGenericArgCountMessage(name, g.names, argNodes.map(arg => arg.expression)));
|
|
9
|
-
}
|
|
10
|
-
return argNodes;
|
|
11
|
-
}
|
|
12
|
-
if (argState.finalizer === ",")
|
|
13
|
-
return _parseGenericArgs(name, g, s, argNodes);
|
|
14
|
-
return argState.error(writeUnclosedGroupMessage(">"));
|
|
15
|
-
};
|
|
16
|
-
export const writeInvalidGenericArgCountMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})`;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { whitespaceChars } from "@ark/util";
|
|
2
|
-
import { enclosingChar, enclosingQuote, parseEnclosed } from "./enclosed.js";
|
|
3
|
-
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
|
|
4
|
-
export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
5
|
-
: s.scanner.lookahead === "(" ? s.shiftedBy(1).reduceGroupOpen()
|
|
6
|
-
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
|
|
7
|
-
: s.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s.shiftedBy(1))
|
|
8
|
-
: s.scanner.lookahead === "d" ?
|
|
9
|
-
s.scanner.nextLookahead in enclosingQuote ?
|
|
10
|
-
parseEnclosed(s, `${s.scanner.shift()}${s.scanner.shift()}`)
|
|
11
|
-
: parseUnenclosed(s)
|
|
12
|
-
: s.scanner.lookahead === "x" ?
|
|
13
|
-
s.scanner.nextLookahead === "/" ?
|
|
14
|
-
s.shiftedBy(2) && parseEnclosed(s, "x/")
|
|
15
|
-
: parseUnenclosed(s)
|
|
16
|
-
: parseUnenclosed(s);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
|
|
2
|
-
import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
|
|
3
|
-
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.js";
|
|
4
|
-
import { terminatingChars } from "../tokens.js";
|
|
5
|
-
import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
|
|
6
|
-
export const parseUnenclosed = (s) => {
|
|
7
|
-
const token = s.scanner.shiftUntilLookahead(terminatingChars);
|
|
8
|
-
if (token === "keyof")
|
|
9
|
-
s.addPrefix("keyof");
|
|
10
|
-
else
|
|
11
|
-
s.root = unenclosedToNode(s, token);
|
|
12
|
-
};
|
|
13
|
-
export const parseGenericInstantiation = (name, g, s) => {
|
|
14
|
-
s.scanner.shiftUntilNonWhitespace();
|
|
15
|
-
const lookahead = s.scanner.shift();
|
|
16
|
-
if (lookahead !== "<")
|
|
17
|
-
return s.error(writeInvalidGenericArgCountMessage(name, g.names, []));
|
|
18
|
-
const parsedArgs = parseGenericArgs(name, g, s);
|
|
19
|
-
return g(...parsedArgs);
|
|
20
|
-
};
|
|
21
|
-
const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
|
|
22
|
-
maybeParseUnenclosedLiteral(s, token) ??
|
|
23
|
-
s.error(token === "" ?
|
|
24
|
-
s.scanner.lookahead === "#" ?
|
|
25
|
-
writePrefixedPrivateReferenceMessage(s.shiftedBy(1).scanner.shiftUntilLookahead(terminatingChars))
|
|
26
|
-
: writeMissingOperandMessage(s)
|
|
27
|
-
: writeUnresolvableMessage(token));
|
|
28
|
-
const maybeParseReference = (s, token) => {
|
|
29
|
-
if (s.ctx.args?.[token]) {
|
|
30
|
-
const arg = s.ctx.args[token];
|
|
31
|
-
if (typeof arg !== "string")
|
|
32
|
-
return arg;
|
|
33
|
-
return s.ctx.$.node("alias", { reference: arg }, { prereduced: true });
|
|
34
|
-
}
|
|
35
|
-
const resolution = s.ctx.$.maybeResolve(token);
|
|
36
|
-
if (hasArkKind(resolution, "root"))
|
|
37
|
-
return resolution;
|
|
38
|
-
if (resolution === undefined)
|
|
39
|
-
return;
|
|
40
|
-
if (hasArkKind(resolution, "generic"))
|
|
41
|
-
return parseGenericInstantiation(token, resolution, s);
|
|
42
|
-
return throwParseError(`Unexpected resolution ${printable(resolution)}`);
|
|
43
|
-
};
|
|
44
|
-
const maybeParseUnenclosedLiteral = (s, token) => {
|
|
45
|
-
const maybeNumber = tryParseWellFormedNumber(token);
|
|
46
|
-
if (maybeNumber !== undefined)
|
|
47
|
-
return s.ctx.$.node("unit", { unit: maybeNumber });
|
|
48
|
-
const maybeBigint = tryParseWellFormedBigint(token);
|
|
49
|
-
if (maybeBigint !== undefined)
|
|
50
|
-
return s.ctx.$.node("unit", { unit: maybeBigint });
|
|
51
|
-
};
|
|
52
|
-
export const writeMissingOperandMessage = (s) => {
|
|
53
|
-
const operator = s.previousOperator();
|
|
54
|
-
return operator ?
|
|
55
|
-
writeMissingRightOperandMessage(operator, s.scanner.unscanned)
|
|
56
|
-
: writeExpressionExpectedMessage(s.scanner.unscanned);
|
|
57
|
-
};
|
|
58
|
-
export const writeMissingRightOperandMessage = (token, unscanned = "") => `Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
|
|
59
|
-
export const writeExpressionExpectedMessage = (unscanned) => `Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { $ark, writeUnboundableMessage } from "@ark/schema";
|
|
2
|
-
import { isKeyOf, throwParseError } from "@ark/util";
|
|
3
|
-
import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
4
|
-
import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
|
|
5
|
-
export const parseBound = (s, start) => {
|
|
6
|
-
const comparator = shiftComparator(s, start);
|
|
7
|
-
if (s.root.hasKind("unit")) {
|
|
8
|
-
if (typeof s.root.unit === "number") {
|
|
9
|
-
s.reduceLeftBound(s.root.unit, comparator);
|
|
10
|
-
s.unsetRoot();
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (s.root.unit instanceof Date) {
|
|
14
|
-
const literal = `d'${s.root.description ?? s.root.unit.toISOString()}'`;
|
|
15
|
-
s.unsetRoot();
|
|
16
|
-
s.reduceLeftBound(literal, comparator);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return parseRightBound(s, comparator);
|
|
21
|
-
};
|
|
22
|
-
export const comparatorStartChars = {
|
|
23
|
-
"<": 1,
|
|
24
|
-
">": 1,
|
|
25
|
-
"=": 1
|
|
26
|
-
};
|
|
27
|
-
const shiftComparator = (s, start) => s.scanner.lookaheadIs("=") ?
|
|
28
|
-
`${start}${s.scanner.shift()}`
|
|
29
|
-
: start;
|
|
30
|
-
export const writeIncompatibleRangeMessage = (l, r) => `Bound kinds ${l} and ${r} are incompatible`;
|
|
31
|
-
export const getBoundKinds = (comparator, limit, root, boundKind) => {
|
|
32
|
-
if (root.extends($ark.intrinsic.number)) {
|
|
33
|
-
if (typeof limit !== "number") {
|
|
34
|
-
return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
|
|
35
|
-
}
|
|
36
|
-
return (comparator === "==" ? ["min", "max"]
|
|
37
|
-
: comparator[0] === ">" ? ["min"]
|
|
38
|
-
: ["max"]);
|
|
39
|
-
}
|
|
40
|
-
if (root.extends($ark.intrinsic.lengthBoundable)) {
|
|
41
|
-
if (typeof limit !== "number") {
|
|
42
|
-
return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
|
|
43
|
-
}
|
|
44
|
-
return (comparator === "==" ? ["exactLength"]
|
|
45
|
-
: comparator[0] === ">" ? ["minLength"]
|
|
46
|
-
: ["maxLength"]);
|
|
47
|
-
}
|
|
48
|
-
if (root.extends($ark.intrinsic.Date)) {
|
|
49
|
-
// allow either numeric or date limits
|
|
50
|
-
return (comparator === "==" ? ["after", "before"]
|
|
51
|
-
: comparator[0] === ">" ? ["after"]
|
|
52
|
-
: ["before"]);
|
|
53
|
-
}
|
|
54
|
-
return throwParseError(writeUnboundableMessage(root.expression));
|
|
55
|
-
};
|
|
56
|
-
const openLeftBoundToRoot = (leftBound) => ({
|
|
57
|
-
rule: isDateLiteral(leftBound.limit) ?
|
|
58
|
-
extractDateLiteralSource(leftBound.limit)
|
|
59
|
-
: leftBound.limit,
|
|
60
|
-
exclusive: leftBound.comparator.length === 1
|
|
61
|
-
});
|
|
62
|
-
export const parseRightBound = (s, comparator) => {
|
|
63
|
-
// store the node that will be bounded
|
|
64
|
-
const previousRoot = s.unsetRoot();
|
|
65
|
-
const previousScannerIndex = s.scanner.location;
|
|
66
|
-
s.parseOperand();
|
|
67
|
-
const limitNode = s.unsetRoot();
|
|
68
|
-
// after parsing the next operand, use the locations to get the
|
|
69
|
-
// token from which it was parsed
|
|
70
|
-
const limitToken = s.scanner.sliceChars(previousScannerIndex, s.scanner.location);
|
|
71
|
-
s.root = previousRoot;
|
|
72
|
-
if (!limitNode.hasKind("unit") ||
|
|
73
|
-
(typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date)))
|
|
74
|
-
return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"));
|
|
75
|
-
const limit = limitNode.unit;
|
|
76
|
-
// apply the newly-parsed right bound
|
|
77
|
-
const exclusive = comparator.length === 1;
|
|
78
|
-
const boundKinds = getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right");
|
|
79
|
-
for (const kind of boundKinds) {
|
|
80
|
-
s.constrainRoot(kind, comparator === "==" ? { rule: limit } : { rule: limit, exclusive });
|
|
81
|
-
}
|
|
82
|
-
if (!s.branches.leftBound)
|
|
83
|
-
return;
|
|
84
|
-
// if there's an open left bound, perform additional validation and apply it
|
|
85
|
-
if (!isKeyOf(comparator, maxComparators))
|
|
86
|
-
return s.error(writeUnpairableComparatorMessage(comparator));
|
|
87
|
-
const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
|
|
88
|
-
s.constrainRoot(lowerBoundKind[0], openLeftBoundToRoot(s.branches.leftBound));
|
|
89
|
-
s.branches.leftBound = null;
|
|
90
|
-
};
|
|
91
|
-
export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { keysOf } from "@ark/util";
|
|
2
|
-
const emptyCollectionDefaults = {
|
|
3
|
-
"[]": () => [],
|
|
4
|
-
"{}": () => ({})
|
|
5
|
-
};
|
|
6
|
-
const emptyCollectionLiterals = keysOf(emptyCollectionDefaults);
|
|
7
|
-
export const parseDefault = (s) => {
|
|
8
|
-
// store the node that will be bounded
|
|
9
|
-
const baseNode = s.unsetRoot();
|
|
10
|
-
// an empty collection is not a unit literal, so it must be short-circuited
|
|
11
|
-
// here and represented as a thunk to keep each traversal's default distinct
|
|
12
|
-
s.scanner.shiftUntilNonWhitespace();
|
|
13
|
-
const emptyCollection = emptyCollectionLiterals.find(literal => s.scanner.unscanned.startsWith(literal));
|
|
14
|
-
if (emptyCollection !== undefined) {
|
|
15
|
-
s.scanner.jumpForward(emptyCollection.length);
|
|
16
|
-
return [baseNode, "=", emptyCollectionDefaults[emptyCollection]];
|
|
17
|
-
}
|
|
18
|
-
s.parseOperand();
|
|
19
|
-
const defaultNode = s.unsetRoot();
|
|
20
|
-
// after parsing the next operand, use the locations to get the
|
|
21
|
-
// token from which it was parsed
|
|
22
|
-
if (!defaultNode.hasKind("unit"))
|
|
23
|
-
return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
|
|
24
|
-
const defaultValue = defaultNode.unit instanceof Date ?
|
|
25
|
-
() => new Date(defaultNode.unit)
|
|
26
|
-
: defaultNode.unit;
|
|
27
|
-
return [baseNode, "=", defaultValue];
|
|
28
|
-
};
|
|
29
|
-
export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must be a literal value`;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { tryParseInteger } from "@ark/util";
|
|
2
|
-
import { terminatingChars } from "../tokens.js";
|
|
3
|
-
export const parseDivisor = (s) => {
|
|
4
|
-
s.scanner.shiftUntilNonWhitespace();
|
|
5
|
-
const divisorToken = s.scanner.shiftUntilLookahead(terminatingChars);
|
|
6
|
-
const divisor = tryParseInteger(divisorToken, {
|
|
7
|
-
errorOnFail: writeInvalidDivisorMessage(divisorToken)
|
|
8
|
-
});
|
|
9
|
-
if (divisor === 0)
|
|
10
|
-
s.error(writeInvalidDivisorMessage(0));
|
|
11
|
-
s.root = s.root.constrain("divisor", divisor);
|
|
12
|
-
};
|
|
13
|
-
export const writeInvalidDivisorMessage = (divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|