arktype 2.0.0-dev.11 → 2.0.0-dev.12-cjs
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/api.d.ts +1 -1
- package/out/api.js +19 -5
- package/out/ark.js +13 -10
- package/out/config.js +17 -1
- package/out/generic.js +8 -4
- package/out/match.js +5 -1
- package/out/module.d.ts +4 -5
- package/out/module.js +5 -3
- package/out/package.json +3 -0
- package/out/parser/definition.d.ts +1 -1
- package/out/parser/definition.js +19 -14
- package/out/parser/generic.js +11 -7
- package/out/parser/objectLiteral.js +23 -17
- package/out/parser/semantic/bounds.js +5 -1
- package/out/parser/semantic/divisor.js +2 -1
- package/out/parser/semantic/infer.js +2 -1
- package/out/parser/semantic/utils.js +2 -1
- package/out/parser/semantic/validate.js +7 -2
- package/out/parser/string/reduce/dynamic.js +24 -20
- package/out/parser/string/reduce/shared.js +17 -9
- package/out/parser/string/reduce/static.js +2 -1
- package/out/parser/string/shift/operand/date.js +18 -10
- package/out/parser/string/shift/operand/enclosed.js +17 -12
- package/out/parser/string/shift/operand/genericArgs.js +10 -5
- package/out/parser/string/shift/operand/operand.js +15 -11
- package/out/parser/string/shift/operand/unenclosed.d.ts +2 -2
- package/out/parser/string/shift/operand/unenclosed.js +30 -22
- package/out/parser/string/shift/operator/bounds.js +35 -27
- package/out/parser/string/shift/operator/divisor.js +11 -6
- package/out/parser/string/shift/operator/operator.js +18 -13
- package/out/parser/string/shift/scanner.js +8 -4
- package/out/parser/string/string.js +12 -7
- package/out/parser/tuple.js +46 -35
- package/out/scope.js +30 -24
- package/out/type.js +13 -9
- package/package.json +6 -14
package/out/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ArkError, ArkErrors
|
|
1
|
+
export { ArkError as ArkError, ArkErrors } from "@arktype/schema";
|
|
2
2
|
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
3
|
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
4
|
export { Module } from "./module.js";
|
package/out/api.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Type = exports.scope = exports.Module = exports.type = exports.match = exports.define = exports.declare = exports.ark = exports.ambient = exports.ArkErrors = exports.ArkError = void 0;
|
|
4
|
+
var schema_1 = require("@arktype/schema");
|
|
5
|
+
Object.defineProperty(exports, "ArkError", { enumerable: true, get: function () { return schema_1.ArkError; } });
|
|
6
|
+
Object.defineProperty(exports, "ArkErrors", { enumerable: true, get: function () { return schema_1.ArkErrors; } });
|
|
7
|
+
var ark_js_1 = require("./ark.js");
|
|
8
|
+
Object.defineProperty(exports, "ambient", { enumerable: true, get: function () { return ark_js_1.ambient; } });
|
|
9
|
+
Object.defineProperty(exports, "ark", { enumerable: true, get: function () { return ark_js_1.ark; } });
|
|
10
|
+
Object.defineProperty(exports, "declare", { enumerable: true, get: function () { return ark_js_1.declare; } });
|
|
11
|
+
Object.defineProperty(exports, "define", { enumerable: true, get: function () { return ark_js_1.define; } });
|
|
12
|
+
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return ark_js_1.match; } });
|
|
13
|
+
Object.defineProperty(exports, "type", { enumerable: true, get: function () { return ark_js_1.type; } });
|
|
14
|
+
var module_js_1 = require("./module.js");
|
|
15
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_js_1.Module; } });
|
|
16
|
+
var scope_js_1 = require("./scope.js");
|
|
17
|
+
Object.defineProperty(exports, "scope", { enumerable: true, get: function () { return scope_js_1.scope; } });
|
|
18
|
+
var type_js_1 = require("./type.js");
|
|
19
|
+
Object.defineProperty(exports, "Type", { enumerable: true, get: function () { return type_js_1.Type; } });
|
package/out/ark.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.declare = exports.define = exports.match = exports.type = exports.ark = exports.ambient = exports.tsGenerics = void 0;
|
|
4
|
+
const schema_1 = require("@arktype/schema");
|
|
5
|
+
const scope_js_1 = require("./scope.js");
|
|
6
|
+
exports.tsGenerics = {};
|
|
7
|
+
exports.ambient = (0, scope_js_1.scope)(schema_1.keywordNodes);
|
|
8
|
+
scope_js_1.RawScope.ambient = exports.ambient.raw;
|
|
9
|
+
exports.ark = exports.ambient.export();
|
|
10
|
+
exports.type = exports.ambient.type;
|
|
11
|
+
exports.match = exports.ambient.match;
|
|
12
|
+
exports.define = exports.ambient.define;
|
|
13
|
+
exports.declare = exports.ambient.declare;
|
package/out/config.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
17
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
2
|
-
|
|
18
|
+
__exportStar(require("@arktype/schema/config"), exports);
|
package/out/generic.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Generic = void 0;
|
|
4
|
+
const schema_1 = require("@arktype/schema");
|
|
5
|
+
const util_1 = require("@arktype/util");
|
|
6
|
+
class Generic extends util_1.Callable {
|
|
4
7
|
params;
|
|
5
8
|
def;
|
|
6
9
|
$;
|
|
7
|
-
[arkKind] = "generic";
|
|
10
|
+
[schema_1.arkKind] = "generic";
|
|
8
11
|
constructor(params, def,
|
|
9
12
|
// TODO: should be Scope<$>, but breaks inference
|
|
10
13
|
$) {
|
|
@@ -22,3 +25,4 @@ export class Generic extends Callable {
|
|
|
22
25
|
this.$ = $;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.Generic = Generic;
|
package/out/match.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMatchParser = void 0;
|
|
4
|
+
const createMatchParser = ($) => {
|
|
2
5
|
return (() => { }).bind($);
|
|
3
6
|
// const matchParser = (isRestricted: boolean) => {
|
|
4
7
|
// const handledCases: { when: RawRoot; then: Morph }[] = []
|
|
@@ -50,3 +53,4 @@ export const createMatchParser = ($) => {
|
|
|
50
53
|
// only: () => matchParser(true)
|
|
51
54
|
// }) as never
|
|
52
55
|
};
|
|
56
|
+
exports.createMatchParser = createMatchParser;
|
package/out/module.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { RootModule, type PreparsedNodeResolution } from "@arktype/schema";
|
|
2
|
+
import type { anyOrNever } from "@arktype/util";
|
|
3
3
|
import type { Type } from "./type.js";
|
|
4
4
|
type exportScope<$> = {
|
|
5
5
|
[k in keyof $]: $[k] extends PreparsedNodeResolution ? [
|
|
6
6
|
$[k]
|
|
7
7
|
] extends [anyOrNever] ? Type<$[k], $> : $[k] : Type<$[k], $>;
|
|
8
8
|
};
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
export declare const Module: new <$ = {}>(types: exportScope<$>) => Module<$>;
|
|
10
|
+
export type Module<$ = {}> = RootModule<exportScope<$>>;
|
|
12
11
|
export {};
|
package/out/module.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = void 0;
|
|
4
|
+
const schema_1 = require("@arktype/schema");
|
|
5
|
+
exports.Module = schema_1.RootModule;
|
package/out/package.json
ADDED
|
@@ -10,7 +10,7 @@ export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
|
10
10
|
export type inferDefinition<def, $, args> = [
|
|
11
11
|
def
|
|
12
12
|
] extends [anyOrNever] ? def : def extends type.cast<infer t> | ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
13
|
-
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOrDomainOf<def
|
|
13
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : isUnknown<def> extends true ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
14
14
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
15
15
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
16
16
|
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
package/out/parser/definition.js
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeBadDefinitionTypeMessage = exports.parseObject = void 0;
|
|
4
|
+
const schema_1 = require("@arktype/schema");
|
|
5
|
+
const util_1 = require("@arktype/util");
|
|
6
|
+
const objectLiteral_js_1 = require("./objectLiteral.js");
|
|
7
|
+
const tuple_js_1 = require("./tuple.js");
|
|
8
|
+
const parseObject = (def, ctx) => {
|
|
9
|
+
const objectKind = (0, util_1.objectKindOf)(def);
|
|
7
10
|
switch (objectKind) {
|
|
8
11
|
case undefined:
|
|
9
|
-
if (hasArkKind(def, "root"))
|
|
12
|
+
if ((0, schema_1.hasArkKind)(def, "root"))
|
|
10
13
|
return def;
|
|
11
|
-
return parseObjectLiteral(def, ctx);
|
|
14
|
+
return (0, objectLiteral_js_1.parseObjectLiteral)(def, ctx);
|
|
12
15
|
case "Array":
|
|
13
|
-
return parseTuple(def, ctx);
|
|
16
|
+
return (0, tuple_js_1.parseTuple)(def, ctx);
|
|
14
17
|
case "RegExp":
|
|
15
18
|
return ctx.$.node("intersection", {
|
|
16
19
|
domain: "string",
|
|
17
20
|
regex: def
|
|
18
21
|
}, { prereduced: true });
|
|
19
22
|
case "Function": {
|
|
20
|
-
const resolvedDef = isThunk(def) ? def() : def;
|
|
21
|
-
if (hasArkKind(resolvedDef, "root"))
|
|
23
|
+
const resolvedDef = (0, util_1.isThunk)(def) ? def() : def;
|
|
24
|
+
if ((0, schema_1.hasArkKind)(resolvedDef, "root"))
|
|
22
25
|
return resolvedDef;
|
|
23
|
-
return throwParseError(writeBadDefinitionTypeMessage("Function"));
|
|
26
|
+
return (0, util_1.throwParseError)((0, exports.writeBadDefinitionTypeMessage)("Function"));
|
|
24
27
|
}
|
|
25
28
|
default:
|
|
26
|
-
return throwParseError(writeBadDefinitionTypeMessage(objectKind ?? printable(def)));
|
|
29
|
+
return (0, util_1.throwParseError)((0, exports.writeBadDefinitionTypeMessage)(objectKind ?? (0, util_1.printable)(def)));
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
|
-
|
|
32
|
+
exports.parseObject = parseObject;
|
|
33
|
+
const writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
34
|
+
exports.writeBadDefinitionTypeMessage = writeBadDefinitionTypeMessage;
|
package/out/parser/generic.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emptyGenericParameterMessage = exports.parseGenericParams = void 0;
|
|
4
|
+
const util_1 = require("@arktype/util");
|
|
5
|
+
const operator_js_1 = require("./string/shift/operator/operator.js");
|
|
6
|
+
const scanner_js_1 = require("./string/shift/scanner.js");
|
|
7
|
+
const parseGenericParams = (def) => _parseGenericParams(new scanner_js_1.Scanner(def));
|
|
8
|
+
exports.parseGenericParams = parseGenericParams;
|
|
9
|
+
exports.emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
6
10
|
const _parseGenericParams = (scanner) => {
|
|
7
11
|
const param = scanner.shiftUntilNextTerminator();
|
|
8
12
|
if (param === "")
|
|
9
|
-
throwParseError(emptyGenericParameterMessage);
|
|
13
|
+
(0, util_1.throwParseError)(exports.emptyGenericParameterMessage);
|
|
10
14
|
scanner.shiftUntilNonWhitespace();
|
|
11
15
|
const nextNonWhitespace = scanner.shift();
|
|
12
16
|
return (nextNonWhitespace === "" ? [param]
|
|
13
17
|
: nextNonWhitespace === "," ? [param, ..._parseGenericParams(scanner)]
|
|
14
|
-
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ",")));
|
|
18
|
+
: (0, util_1.throwParseError)((0, operator_js_1.writeUnexpectedCharacterMessage)(nextNonWhitespace, ",")));
|
|
15
19
|
};
|
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeInvalidSpreadTypeMessage = exports.parseEntry = exports.nonLeadingSpreadError = exports.parseObjectLiteral = void 0;
|
|
4
|
+
const util_1 = require("@arktype/util");
|
|
5
|
+
const scanner_js_1 = require("./string/shift/scanner.js");
|
|
6
|
+
const parseObjectLiteral = (def, ctx) => {
|
|
4
7
|
let spread;
|
|
5
8
|
const structure = {};
|
|
6
9
|
// We only allow a spread operator to be used as the first key in an object
|
|
7
10
|
// because to match JS behavior any keys before the spread are overwritten
|
|
8
11
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
9
12
|
// anywhere except for the beginning.
|
|
10
|
-
const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry);
|
|
13
|
+
const parsedEntries = (0, util_1.stringAndSymbolicEntriesOf)(def).map(exports.parseEntry);
|
|
11
14
|
if (parsedEntries[0]?.kind === "spread") {
|
|
12
15
|
// remove the spread entry so we can iterate over the remaining entries
|
|
13
16
|
// expecting non-spread entries
|
|
14
17
|
const spreadEntry = parsedEntries.shift();
|
|
15
18
|
const spreadNode = ctx.$.parse(spreadEntry.value, ctx);
|
|
16
19
|
if (!spreadNode.hasKind("intersection") || !spreadNode.structure) {
|
|
17
|
-
return throwParseError(writeInvalidSpreadTypeMessage(typeof spreadEntry.value === "string" ?
|
|
20
|
+
return (0, util_1.throwParseError)((0, exports.writeInvalidSpreadTypeMessage)(typeof spreadEntry.value === "string" ?
|
|
18
21
|
spreadEntry.value
|
|
19
|
-
: printable(spreadEntry.value)));
|
|
22
|
+
: (0, util_1.printable)(spreadEntry.value)));
|
|
20
23
|
}
|
|
21
24
|
spread = spreadNode.structure;
|
|
22
25
|
}
|
|
23
26
|
for (const entry of parsedEntries) {
|
|
24
27
|
if (entry.kind === "spread")
|
|
25
|
-
return throwParseError(nonLeadingSpreadError);
|
|
28
|
+
return (0, util_1.throwParseError)(exports.nonLeadingSpreadError);
|
|
26
29
|
if (entry.kind === "index") {
|
|
27
30
|
// handle key parsing first to match type behavior
|
|
28
31
|
const key = ctx.$.parse(entry.inner, ctx);
|
|
29
32
|
const value = ctx.$.parse(entry.value, ctx);
|
|
30
33
|
// extract enumerable named props from the index signature
|
|
31
|
-
const [enumerable, nonEnumerable] = spliterate(key.branches, (k) => k.hasKind("unit"));
|
|
34
|
+
const [enumerable, nonEnumerable] = (0, util_1.spliterate)(key.branches, (k) => k.hasKind("unit"));
|
|
32
35
|
if (enumerable.length) {
|
|
33
|
-
structure.required = append(structure.required, enumerable.map(k => ctx.$.node("required", { key: k.unit, value })));
|
|
36
|
+
structure.required = (0, util_1.append)(structure.required, enumerable.map(k => ctx.$.node("required", { key: k.unit, value })));
|
|
34
37
|
if (nonEnumerable.length) {
|
|
35
|
-
structure.index = append(structure.index, ctx.$.node("index", { index: nonEnumerable, value }));
|
|
38
|
+
structure.index = (0, util_1.append)(structure.index, ctx.$.node("index", { index: nonEnumerable, value }));
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
39
|
-
structure.index = append(structure.index, ctx.$.node("index", { index: key, value }));
|
|
42
|
+
structure.index = (0, util_1.append)(structure.index, ctx.$.node("index", { index: key, value }));
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
else {
|
|
43
46
|
const value = ctx.$.parse(entry.value, ctx);
|
|
44
|
-
structure[entry.kind] = append(structure[entry.kind], {
|
|
47
|
+
structure[entry.kind] = (0, util_1.append)(structure[entry.kind], {
|
|
45
48
|
key: entry.inner,
|
|
46
49
|
value
|
|
47
50
|
});
|
|
@@ -53,11 +56,13 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
53
56
|
structure: spread?.merge(structureNode) ?? structureNode
|
|
54
57
|
});
|
|
55
58
|
};
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
exports.parseObjectLiteral = parseObjectLiteral;
|
|
60
|
+
exports.nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
61
|
+
const parseEntry = (entry) => Object.assign(parseKey(entry[0]), { value: entry[1] });
|
|
62
|
+
exports.parseEntry = parseEntry;
|
|
58
63
|
const parseKey = (key) => typeof key === "symbol" ? { inner: key, kind: "required" }
|
|
59
64
|
: key.at(-1) === "?" ?
|
|
60
|
-
key.at(-2) === Scanner.escapeToken ?
|
|
65
|
+
key.at(-2) === scanner_js_1.Scanner.escapeToken ?
|
|
61
66
|
{ inner: `${key.slice(0, -2)}?`, kind: "required" }
|
|
62
67
|
: {
|
|
63
68
|
inner: key.slice(0, -1),
|
|
@@ -65,8 +70,9 @@ const parseKey = (key) => typeof key === "symbol" ? { inner: key, kind: "require
|
|
|
65
70
|
}
|
|
66
71
|
: key[0] === "[" && key.at(-1) === "]" ?
|
|
67
72
|
{ inner: key.slice(1, -1), kind: "index" }
|
|
68
|
-
: key[0] === Scanner.escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
73
|
+
: key[0] === scanner_js_1.Scanner.escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
69
74
|
{ inner: key.slice(1), kind: "required" }
|
|
70
75
|
: key === "..." ? { inner: "...", kind: "spread" }
|
|
71
76
|
: { inner: key === "\\..." ? "..." : key, kind: "required" };
|
|
72
|
-
|
|
77
|
+
const writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
78
|
+
exports.writeInvalidSpreadTypeMessage = writeInvalidSpreadTypeMessage;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeDoubleRightBoundMessage = void 0;
|
|
4
|
+
const writeDoubleRightBoundMessage = (root) => `Expression ${root} must have at most one right bound`;
|
|
5
|
+
exports.writeDoubleRightBoundMessage = writeDoubleRightBoundMessage;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writePrefixedPrivateReferenceMessage = exports.writeUnsatisfiableExpressionError = void 0;
|
|
4
|
+
const writeUnsatisfiableExpressionError = (expression) => `${expression} results in an unsatisfiable type`;
|
|
5
|
+
exports.writeUnsatisfiableExpressionError = writeUnsatisfiableExpressionError;
|
|
6
|
+
const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
|
|
7
|
+
exports.writePrefixedPrivateReferenceMessage = writePrefixedPrivateReferenceMessage;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicState = void 0;
|
|
4
|
+
const util_1 = require("@arktype/util");
|
|
5
|
+
const operand_js_1 = require("../shift/operand/operand.js");
|
|
6
|
+
const operator_js_1 = require("../shift/operator/operator.js");
|
|
7
|
+
const scanner_js_1 = require("../shift/scanner.js");
|
|
8
|
+
const string_js_1 = require("../string.js");
|
|
9
|
+
const shared_js_1 = require("./shared.js");
|
|
10
|
+
class DynamicState {
|
|
8
11
|
ctx;
|
|
9
12
|
scanner;
|
|
10
13
|
// set root type to `any` so that all constraints can be applied
|
|
@@ -19,10 +22,10 @@ export class DynamicState {
|
|
|
19
22
|
groups = [];
|
|
20
23
|
constructor(def, ctx) {
|
|
21
24
|
this.ctx = ctx;
|
|
22
|
-
this.scanner = new Scanner(def);
|
|
25
|
+
this.scanner = new scanner_js_1.Scanner(def);
|
|
23
26
|
}
|
|
24
27
|
error(message) {
|
|
25
|
-
return throwParseError(message);
|
|
28
|
+
return (0, util_1.throwParseError)(message);
|
|
26
29
|
}
|
|
27
30
|
hasRoot() {
|
|
28
31
|
return this.root !== undefined;
|
|
@@ -40,16 +43,16 @@ export class DynamicState {
|
|
|
40
43
|
}
|
|
41
44
|
finalize(finalizer) {
|
|
42
45
|
if (this.groups.length)
|
|
43
|
-
return this.error(writeUnclosedGroupMessage(")"));
|
|
46
|
+
return this.error((0, shared_js_1.writeUnclosedGroupMessage)(")"));
|
|
44
47
|
this.finalizeBranches();
|
|
45
48
|
this.finalizer = finalizer;
|
|
46
49
|
}
|
|
47
50
|
reduceLeftBound(limit, comparator) {
|
|
48
|
-
const invertedComparator = invertedComparators[comparator];
|
|
49
|
-
if (!isKeyOf(invertedComparator, minComparators))
|
|
50
|
-
return this.error(writeUnpairableComparatorMessage(comparator));
|
|
51
|
+
const invertedComparator = shared_js_1.invertedComparators[comparator];
|
|
52
|
+
if (!(0, util_1.isKeyOf)(invertedComparator, shared_js_1.minComparators))
|
|
53
|
+
return this.error((0, shared_js_1.writeUnpairableComparatorMessage)(comparator));
|
|
51
54
|
if (this.branches.leftBound) {
|
|
52
|
-
return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
|
|
55
|
+
return this.error((0, shared_js_1.writeMultipleLeftBoundsMessage)(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
|
|
53
56
|
}
|
|
54
57
|
this.branches.leftBound = {
|
|
55
58
|
comparator: invertedComparator,
|
|
@@ -73,7 +76,7 @@ export class DynamicState {
|
|
|
73
76
|
this.finalizeBranches();
|
|
74
77
|
const topBranchState = this.groups.pop();
|
|
75
78
|
if (!topBranchState)
|
|
76
|
-
return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned));
|
|
79
|
+
return this.error((0, shared_js_1.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
|
|
77
80
|
this.branches = topBranchState;
|
|
78
81
|
}
|
|
79
82
|
addPrefix(prefix) {
|
|
@@ -85,7 +88,7 @@ export class DynamicState {
|
|
|
85
88
|
this.root =
|
|
86
89
|
lastPrefix === "keyof" ?
|
|
87
90
|
this.root.keyof()
|
|
88
|
-
: throwInternalError(`Unexpected prefix '${lastPrefix}'`);
|
|
91
|
+
: (0, util_1.throwInternalError)(`Unexpected prefix '${lastPrefix}'`);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
pushRootToBranch(token) {
|
|
@@ -102,17 +105,17 @@ export class DynamicState {
|
|
|
102
105
|
this.root = undefined;
|
|
103
106
|
}
|
|
104
107
|
parseUntilFinalizer() {
|
|
105
|
-
return parseUntilFinalizer(new DynamicState(this.scanner.unscanned, this.ctx));
|
|
108
|
+
return (0, string_js_1.parseUntilFinalizer)(new DynamicState(this.scanner.unscanned, this.ctx));
|
|
106
109
|
}
|
|
107
110
|
parseOperator() {
|
|
108
|
-
return parseOperator(this);
|
|
111
|
+
return (0, operator_js_1.parseOperator)(this);
|
|
109
112
|
}
|
|
110
113
|
parseOperand() {
|
|
111
|
-
return parseOperand(this);
|
|
114
|
+
return (0, operand_js_1.parseOperand)(this);
|
|
112
115
|
}
|
|
113
116
|
assertRangeUnset() {
|
|
114
117
|
if (this.branches.leftBound) {
|
|
115
|
-
return this.error(writeOpenRangeMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator));
|
|
118
|
+
return this.error((0, shared_js_1.writeOpenRangeMessage)(this.branches.leftBound.limit, this.branches.leftBound.comparator));
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
reduceGroupOpen() {
|
|
@@ -136,3 +139,4 @@ export class DynamicState {
|
|
|
136
139
|
return this;
|
|
137
140
|
}
|
|
138
141
|
}
|
|
142
|
+
exports.DynamicState = DynamicState;
|
|
@@ -1,27 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeMultipleLeftBoundsMessage = exports.writeUnpairableComparatorMessage = exports.writeOpenRangeMessage = exports.writeUnclosedGroupMessage = exports.writeUnmatchedGroupCloseMessage = exports.invertedComparators = exports.comparators = exports.maxComparators = exports.minComparators = void 0;
|
|
4
|
+
exports.minComparators = {
|
|
2
5
|
">": true,
|
|
3
6
|
">=": true
|
|
4
7
|
};
|
|
5
|
-
|
|
8
|
+
exports.maxComparators = {
|
|
6
9
|
"<": true,
|
|
7
10
|
"<=": true
|
|
8
11
|
};
|
|
9
|
-
|
|
12
|
+
exports.comparators = {
|
|
10
13
|
">": true,
|
|
11
14
|
">=": true,
|
|
12
15
|
"<": true,
|
|
13
16
|
"<=": true,
|
|
14
17
|
"==": true
|
|
15
18
|
};
|
|
16
|
-
|
|
19
|
+
exports.invertedComparators = {
|
|
17
20
|
"<": ">",
|
|
18
21
|
">": "<",
|
|
19
22
|
"<=": ">=",
|
|
20
23
|
">=": "<=",
|
|
21
24
|
"==": "=="
|
|
22
25
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const writeUnmatchedGroupCloseMessage = (unscanned) => `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`)}`;
|
|
27
|
+
exports.writeUnmatchedGroupCloseMessage = writeUnmatchedGroupCloseMessage;
|
|
28
|
+
const writeUnclosedGroupMessage = (missingChar) => `Missing ${missingChar}`;
|
|
29
|
+
exports.writeUnclosedGroupMessage = writeUnclosedGroupMessage;
|
|
30
|
+
const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
31
|
+
exports.writeOpenRangeMessage = writeOpenRangeMessage;
|
|
32
|
+
const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
33
|
+
exports.writeUnpairableComparatorMessage = writeUnpairableComparatorMessage;
|
|
34
|
+
const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${exports.invertedComparators[openComparator]}, ${limit}${exports.invertedComparators[comparator]})`;
|
|
35
|
+
exports.writeMultipleLeftBoundsMessage = writeMultipleLeftBoundsMessage;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryParseDate = exports.writeInvalidDateMessage = exports.extractDateLiteralSource = exports.isValidDate = exports.isDateLiteral = void 0;
|
|
4
|
+
const util_1 = require("@arktype/util");
|
|
5
|
+
const isDateLiteral = (value) => typeof value === "string" &&
|
|
3
6
|
value[0] === "d" &&
|
|
4
7
|
(value[1] === "'" || value[1] === '"') &&
|
|
5
8
|
value.at(-1) === value[1];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
exports.isDateLiteral = isDateLiteral;
|
|
10
|
+
const isValidDate = (d) => d.toString() !== "Invalid Date";
|
|
11
|
+
exports.isValidDate = isValidDate;
|
|
12
|
+
const extractDateLiteralSource = (literal) => literal.slice(2, -1);
|
|
13
|
+
exports.extractDateLiteralSource = extractDateLiteralSource;
|
|
14
|
+
const writeInvalidDateMessage = (source) => `'${source}' could not be parsed by the Date constructor`;
|
|
15
|
+
exports.writeInvalidDateMessage = writeInvalidDateMessage;
|
|
16
|
+
const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
|
|
17
|
+
exports.tryParseDate = tryParseDate;
|
|
10
18
|
const maybeParseDate = (source, errorOnFail) => {
|
|
11
19
|
const stringParsedDate = new Date(source);
|
|
12
|
-
if (isValidDate(stringParsedDate))
|
|
20
|
+
if ((0, exports.isValidDate)(stringParsedDate))
|
|
13
21
|
return stringParsedDate;
|
|
14
|
-
const epochMillis = tryParseNumber(source);
|
|
22
|
+
const epochMillis = (0, util_1.tryParseNumber)(source);
|
|
15
23
|
if (epochMillis !== undefined) {
|
|
16
24
|
const numberParsedDate = new Date(epochMillis);
|
|
17
|
-
if (isValidDate(numberParsedDate))
|
|
25
|
+
if ((0, exports.isValidDate)(numberParsedDate))
|
|
18
26
|
return numberParsedDate;
|
|
19
27
|
}
|
|
20
28
|
return errorOnFail ?
|
|
21
|
-
throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
|
|
29
|
+
(0, util_1.throwParseError)(errorOnFail === true ? (0, exports.writeInvalidDateMessage)(source) : errorOnFail)
|
|
22
30
|
: undefined;
|
|
23
31
|
};
|