arktype 2.0.0-dev.12-cjs → 2.0.0-dev.14
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 +1 -1
- package/out/api.js +5 -19
- package/out/ark.js +10 -13
- package/out/config.js +1 -17
- package/out/generic.d.ts +1 -1
- package/out/generic.js +4 -8
- package/out/match.js +50 -56
- package/out/module.js +2 -5
- package/out/parser/definition.d.ts +1 -1
- package/out/parser/definition.js +14 -19
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +31 -18
- package/out/parser/objectLiteral.js +72 -43
- package/out/parser/semantic/bounds.js +1 -5
- package/out/parser/semantic/divisor.js +1 -2
- package/out/parser/semantic/infer.js +1 -2
- package/out/parser/semantic/utils.js +1 -2
- package/out/parser/semantic/validate.js +2 -7
- package/out/parser/string/reduce/dynamic.js +20 -24
- package/out/parser/string/reduce/shared.js +9 -17
- package/out/parser/string/reduce/static.js +1 -2
- package/out/parser/string/shift/operand/date.js +10 -18
- package/out/parser/string/shift/operand/enclosed.js +12 -17
- package/out/parser/string/shift/operand/genericArgs.js +5 -10
- package/out/parser/string/shift/operand/operand.d.ts +1 -1
- package/out/parser/string/shift/operand/operand.js +11 -15
- package/out/parser/string/shift/operand/unenclosed.js +22 -30
- package/out/parser/string/shift/operator/bounds.js +27 -35
- package/out/parser/string/shift/operator/divisor.js +6 -11
- package/out/parser/string/shift/operator/operator.js +13 -18
- package/out/parser/string/shift/scanner.d.ts +6 -5
- package/out/parser/string/shift/scanner.js +7 -8
- package/out/parser/string/string.js +7 -12
- package/out/parser/tuple.js +35 -58
- package/out/scope.d.ts +1 -2
- package/out/scope.js +24 -30
- package/out/type.js +9 -13
- package/package.json +33 -33
- package/out/main.d.ts +0 -6
- package/out/main.js +0 -5
- package/out/package.json +0 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type Dict } from "@arktype/util";
|
|
2
2
|
import type { Comparator } from "../reduce/shared.js";
|
|
3
|
-
export declare class Scanner<
|
|
3
|
+
export declare class Scanner<lookahead extends string = string> {
|
|
4
4
|
private chars;
|
|
5
5
|
private i;
|
|
6
6
|
constructor(def: string);
|
|
7
7
|
/** Get lookahead and advance scanner by one */
|
|
8
|
-
shift():
|
|
9
|
-
get lookahead():
|
|
8
|
+
shift(): lookahead;
|
|
9
|
+
get lookahead(): lookahead;
|
|
10
|
+
get nextLookahead(): string;
|
|
10
11
|
get length(): number;
|
|
11
12
|
shiftUntil(condition: Scanner.UntilCondition): string;
|
|
12
13
|
shiftUntilNextTerminator(): string;
|
|
@@ -16,8 +17,8 @@ export declare class Scanner<Lookahead extends string = string> {
|
|
|
16
17
|
get unscanned(): string;
|
|
17
18
|
get scanned(): string;
|
|
18
19
|
sliceChars(start: number, end?: number): string;
|
|
19
|
-
lookaheadIs<
|
|
20
|
-
lookaheadIsIn<
|
|
20
|
+
lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
|
|
21
|
+
lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
|
|
21
22
|
}
|
|
22
23
|
export declare namespace Scanner {
|
|
23
24
|
type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Scanner = void 0;
|
|
4
|
-
const util_1 = require("@arktype/util");
|
|
5
|
-
class Scanner {
|
|
1
|
+
import { isKeyOf } from "@arktype/util";
|
|
2
|
+
export class Scanner {
|
|
6
3
|
chars;
|
|
7
4
|
i;
|
|
8
5
|
constructor(def) {
|
|
@@ -16,6 +13,9 @@ class Scanner {
|
|
|
16
13
|
get lookahead() {
|
|
17
14
|
return (this.chars[this.i] ?? "");
|
|
18
15
|
}
|
|
16
|
+
get nextLookahead() {
|
|
17
|
+
return this.chars[this.i + 1] ?? "";
|
|
18
|
+
}
|
|
19
19
|
get length() {
|
|
20
20
|
return this.chars.length;
|
|
21
21
|
}
|
|
@@ -61,7 +61,6 @@ class Scanner {
|
|
|
61
61
|
return this.lookahead in tokens;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
exports.Scanner = Scanner;
|
|
65
64
|
(function (Scanner) {
|
|
66
65
|
Scanner.lookaheadIsTerminator = (scanner) => scanner.lookahead in Scanner.terminatingChars;
|
|
67
66
|
Scanner.lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in Scanner.whiteSpaceTokens);
|
|
@@ -95,7 +94,7 @@ exports.Scanner = Scanner;
|
|
|
95
94
|
unscanned[1] === "="
|
|
96
95
|
// if > is the end of a generic instantiation, the next token will be an operator or the end of the string
|
|
97
96
|
: unscanned.trimStart() === "" ||
|
|
98
|
-
|
|
97
|
+
isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
|
|
99
98
|
// if the lookahead is a finalizing token but not >, it's unambiguously a finalizer (currently just ",")
|
|
100
99
|
: lookahead === ",";
|
|
101
|
-
})(Scanner || (
|
|
100
|
+
})(Scanner || (Scanner = {}));
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const util_1 = require("@arktype/util");
|
|
5
|
-
const operator_js_1 = require("./shift/operator/operator.js");
|
|
6
|
-
const fullStringParse = (s) => {
|
|
1
|
+
import { throwInternalError, throwParseError } from "@arktype/util";
|
|
2
|
+
import { writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
|
|
3
|
+
export const fullStringParse = (s) => {
|
|
7
4
|
s.parseOperand();
|
|
8
|
-
const result =
|
|
5
|
+
const result = parseUntilFinalizer(s).root;
|
|
9
6
|
if (!result) {
|
|
10
|
-
return
|
|
7
|
+
return throwInternalError(`Root was unexpectedly unset after parsing string '${s.scanner.scanned}'`);
|
|
11
8
|
}
|
|
12
9
|
s.scanner.shiftUntilNonWhitespace();
|
|
13
10
|
if (s.scanner.lookahead) {
|
|
14
11
|
// throw a parse error if non-whitespace characters made it here without being parsed
|
|
15
|
-
|
|
12
|
+
throwParseError(writeUnexpectedCharacterMessage(s.scanner.lookahead));
|
|
16
13
|
}
|
|
17
14
|
return result;
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
const parseUntilFinalizer = (s) => {
|
|
16
|
+
export const parseUntilFinalizer = (s) => {
|
|
21
17
|
while (s.finalizer === undefined)
|
|
22
18
|
next(s);
|
|
23
19
|
return s;
|
|
24
20
|
};
|
|
25
|
-
exports.parseUntilFinalizer = parseUntilFinalizer;
|
|
26
21
|
const next = (s) => s.hasRoot() ? s.parseOperator() : s.parseOperand();
|
package/out/parser/tuple.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const unenclosed_js_1 = require("./string/shift/operand/unenclosed.js");
|
|
7
|
-
const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? (0, exports.parseTupleLiteral)(def, ctx);
|
|
8
|
-
exports.parseTuple = parseTuple;
|
|
9
|
-
const parseTupleLiteral = (def, ctx) => {
|
|
1
|
+
import { jsObjects, makeRootAndArrayPropertiesMutable, tsKeywords } from "@arktype/schema";
|
|
2
|
+
import { append, objectKindOrDomainOf, throwParseError } from "@arktype/util";
|
|
3
|
+
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
|
|
4
|
+
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
|
|
5
|
+
export const parseTupleLiteral = (def, ctx) => {
|
|
10
6
|
let sequences = [{}];
|
|
11
7
|
let i = 0;
|
|
12
8
|
while (i < def.length) {
|
|
@@ -20,19 +16,19 @@ const parseTupleLiteral = (def, ctx) => {
|
|
|
20
16
|
i++;
|
|
21
17
|
if (def[i] === "?") {
|
|
22
18
|
if (spread)
|
|
23
|
-
return
|
|
19
|
+
return throwParseError(spreadOptionalMessage);
|
|
24
20
|
optional = true;
|
|
25
21
|
i++;
|
|
26
22
|
}
|
|
27
23
|
if (spread) {
|
|
28
|
-
if (!element.extends(
|
|
29
|
-
return
|
|
24
|
+
if (!element.extends(jsObjects.Array))
|
|
25
|
+
return throwParseError(writeNonArraySpreadMessage(element.expression));
|
|
30
26
|
// a spread must be distributed over branches e.g.:
|
|
31
27
|
// def: [string, ...(number[] | [true, false])]
|
|
32
28
|
// nodes: [string, ...number[]] | [string, true, false]
|
|
33
29
|
sequences = sequences.flatMap(base =>
|
|
34
30
|
// since appendElement mutates base, we have to shallow-ish clone it for each branch
|
|
35
|
-
element.branches.map(branch => appendSpreadBranch(
|
|
31
|
+
element.branches.map(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
|
|
36
32
|
}
|
|
37
33
|
else {
|
|
38
34
|
sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
|
|
@@ -43,37 +39,36 @@ const parseTupleLiteral = (def, ctx) => {
|
|
|
43
39
|
sequence
|
|
44
40
|
})));
|
|
45
41
|
};
|
|
46
|
-
exports.parseTupleLiteral = parseTupleLiteral;
|
|
47
42
|
const appendElement = (base, kind, element) => {
|
|
48
43
|
switch (kind) {
|
|
49
44
|
case "required":
|
|
50
45
|
if (base.optionals)
|
|
51
46
|
// e.g. [string?, number]
|
|
52
|
-
return
|
|
47
|
+
return throwParseError(requiredPostOptionalMessage);
|
|
53
48
|
if (base.variadic) {
|
|
54
49
|
// e.g. [...string[], number]
|
|
55
|
-
base.postfix =
|
|
50
|
+
base.postfix = append(base.postfix, element);
|
|
56
51
|
}
|
|
57
52
|
else {
|
|
58
53
|
// e.g. [string, number]
|
|
59
|
-
base.prefix =
|
|
54
|
+
base.prefix = append(base.prefix, element);
|
|
60
55
|
}
|
|
61
56
|
return base;
|
|
62
57
|
case "optional":
|
|
63
58
|
if (base.variadic)
|
|
64
59
|
// e.g. [...string[], number?]
|
|
65
|
-
return
|
|
60
|
+
return throwParseError(optionalPostVariadicMessage);
|
|
66
61
|
// e.g. [string, number?]
|
|
67
|
-
base.optionals =
|
|
62
|
+
base.optionals = append(base.optionals, element);
|
|
68
63
|
return base;
|
|
69
64
|
case "variadic":
|
|
70
65
|
// e.g. [...string[], number, ...string[]]
|
|
71
66
|
if (base.postfix)
|
|
72
|
-
|
|
67
|
+
throwParseError(multipleVariadicMesage);
|
|
73
68
|
if (base.variadic) {
|
|
74
69
|
if (!base.variadic.equals(element)) {
|
|
75
70
|
// e.g. [...string[], ...number[]]
|
|
76
|
-
|
|
71
|
+
throwParseError(multipleVariadicMesage);
|
|
77
72
|
}
|
|
78
73
|
// e.g. [...string[], ...string[]]
|
|
79
74
|
// do nothing, second spread doesn't change the type
|
|
@@ -89,7 +84,7 @@ const appendSpreadBranch = (base, branch) => {
|
|
|
89
84
|
const spread = branch.firstReferenceOfKind("sequence");
|
|
90
85
|
if (!spread) {
|
|
91
86
|
// the only array with no sequence reference is unknown[]
|
|
92
|
-
return appendElement(base, "variadic",
|
|
87
|
+
return appendElement(base, "variadic", tsKeywords.unknown);
|
|
93
88
|
}
|
|
94
89
|
spread.prefix.forEach(node => appendElement(base, "required", node));
|
|
95
90
|
spread.optionals.forEach(node => appendElement(base, "optional", node));
|
|
@@ -102,73 +97,56 @@ const maybeParseTupleExpression = (def, ctx) => {
|
|
|
102
97
|
: isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx)
|
|
103
98
|
: undefined;
|
|
104
99
|
return tupleExpressionResult;
|
|
105
|
-
// TODO: remove
|
|
106
|
-
// return tupleExpressionResult.isNever()
|
|
107
|
-
// ? throwParseError(
|
|
108
|
-
// writeUnsatisfiableExpressionError(
|
|
109
|
-
// def
|
|
110
|
-
// .map((def) =>
|
|
111
|
-
// typeof def === "string" ? def : printable(def)
|
|
112
|
-
// )
|
|
113
|
-
// .join(" ")
|
|
114
|
-
// )
|
|
115
|
-
// )
|
|
116
|
-
// : tupleExpressionResult
|
|
117
100
|
};
|
|
118
|
-
const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
|
|
125
|
-
exports.parseKeyOfTuple = parseKeyOfTuple;
|
|
101
|
+
export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
|
|
102
|
+
export const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
103
|
+
export const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
104
|
+
export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
|
|
105
|
+
export const spreadOptionalMessage = "A spread element cannot be optional";
|
|
106
|
+
export const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
|
|
126
107
|
const parseBranchTuple = (def, ctx) => {
|
|
127
108
|
if (def[2] === undefined)
|
|
128
|
-
return
|
|
109
|
+
return throwParseError(writeMissingRightOperandMessage(def[1], ""));
|
|
129
110
|
const l = ctx.$.parse(def[0], ctx);
|
|
130
111
|
const r = ctx.$.parse(def[2], ctx);
|
|
131
112
|
return def[1] === "&" ? l.and(r) : l.or(r);
|
|
132
113
|
};
|
|
133
114
|
const parseArrayTuple = (def, ctx) => ctx.$.parse(def[0], ctx).array();
|
|
134
115
|
const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
|
|
135
|
-
const parseMorphTuple = (def, ctx) => {
|
|
116
|
+
export const parseMorphTuple = (def, ctx) => {
|
|
136
117
|
if (typeof def[2] !== "function") {
|
|
137
|
-
return
|
|
118
|
+
return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
|
|
138
119
|
}
|
|
139
120
|
// TODO: nested morphs?
|
|
140
121
|
return ctx.$.parse(def[0], ctx).pipe(def[2]);
|
|
141
122
|
};
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
exports.writeMalformedFunctionalExpressionMessage = writeMalformedFunctionalExpressionMessage;
|
|
145
|
-
const parseNarrowTuple = (def, ctx) => {
|
|
123
|
+
export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
|
|
124
|
+
export const parseNarrowTuple = (def, ctx) => {
|
|
146
125
|
if (typeof def[2] !== "function") {
|
|
147
|
-
return
|
|
126
|
+
return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
|
|
148
127
|
}
|
|
149
128
|
return ctx.$.parse(def[0], ctx).constrain("predicate", def[2]);
|
|
150
129
|
};
|
|
151
|
-
exports.parseNarrowTuple = parseNarrowTuple;
|
|
152
130
|
const parseAttributeTuple = (def, ctx) => ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2]);
|
|
153
131
|
const indexOneParsers = {
|
|
154
132
|
"|": parseBranchTuple,
|
|
155
133
|
"&": parseBranchTuple,
|
|
156
134
|
"[]": parseArrayTuple,
|
|
157
|
-
":":
|
|
158
|
-
"=>":
|
|
135
|
+
":": parseNarrowTuple,
|
|
136
|
+
"=>": parseMorphTuple,
|
|
159
137
|
"@": parseAttributeTuple
|
|
160
138
|
};
|
|
161
139
|
const prefixParsers = {
|
|
162
|
-
keyof:
|
|
140
|
+
keyof: parseKeyOfTuple,
|
|
163
141
|
instanceof: (def, ctx) => {
|
|
164
142
|
if (typeof def[1] !== "function") {
|
|
165
|
-
return
|
|
143
|
+
return throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(def[1])));
|
|
166
144
|
}
|
|
167
145
|
const branches = def
|
|
168
146
|
.slice(1)
|
|
169
147
|
.map(ctor => typeof ctor === "function" ?
|
|
170
148
|
ctx.$.node("proto", { proto: ctor })
|
|
171
|
-
:
|
|
149
|
+
: throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))));
|
|
172
150
|
return branches.length === 1 ?
|
|
173
151
|
branches[0]
|
|
174
152
|
: ctx.$.node("union", { branches });
|
|
@@ -176,5 +154,4 @@ const prefixParsers = {
|
|
|
176
154
|
"===": (def, ctx) => ctx.$.units(def.slice(1))
|
|
177
155
|
};
|
|
178
156
|
const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
|
|
179
|
-
const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
|
|
180
|
-
exports.writeInvalidConstructorMessage = writeInvalidConstructorMessage;
|
|
157
|
+
export const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
|
package/out/scope.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@arktype/schema";
|
|
2
2
|
import { type anyOrNever, type keyError, type nominal, type show } from "@arktype/util";
|
|
3
|
-
import type { type } from "./ark.js";
|
|
4
3
|
import { Generic } from "./generic.js";
|
|
5
4
|
import { type MatchParser } from "./match.js";
|
|
6
5
|
import type { Module } from "./module.js";
|
|
@@ -40,7 +39,7 @@ export type moduleKeyOf<$> = {
|
|
|
40
39
|
[arkKind]: "module";
|
|
41
40
|
} ? k & string : never;
|
|
42
41
|
}[keyof $];
|
|
43
|
-
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias]
|
|
42
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : never;
|
|
44
43
|
export interface ParseContext {
|
|
45
44
|
$: RawScope;
|
|
46
45
|
args?: Record<string, UnknownRoot>;
|
package/out/scope.js
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const type_js_1 = require("./type.js");
|
|
13
|
-
exports.scope = ((def, config = {}) => new RawScope(def, config));
|
|
14
|
-
class RawScope extends schema_1.RawRootScope {
|
|
1
|
+
import { RawRootScope, hasArkKind } from "@arktype/schema";
|
|
2
|
+
import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
|
|
3
|
+
import { Generic } from "./generic.js";
|
|
4
|
+
import { createMatchParser } from "./match.js";
|
|
5
|
+
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
6
|
+
import { parseGenericParams } from "./parser/generic.js";
|
|
7
|
+
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
8
|
+
import { fullStringParse } from "./parser/string/string.js";
|
|
9
|
+
import { RawTypeParser } from "./type.js";
|
|
10
|
+
export const scope = ((def, config = {}) => new RawScope(def, config));
|
|
11
|
+
export class RawScope extends RawRootScope {
|
|
15
12
|
parseCache = {};
|
|
16
13
|
constructor(def, config) {
|
|
17
14
|
const aliases = {};
|
|
18
15
|
for (const k in def) {
|
|
19
|
-
const parsedKey =
|
|
16
|
+
const parsedKey = parseScopeKey(k);
|
|
20
17
|
aliases[parsedKey.name] =
|
|
21
18
|
parsedKey.params.length ?
|
|
22
19
|
// TODO: this
|
|
23
|
-
new
|
|
20
|
+
new Generic(parsedKey.params, def[k], {})
|
|
24
21
|
: def[k];
|
|
25
22
|
}
|
|
26
23
|
super(aliases, config);
|
|
27
24
|
}
|
|
28
|
-
type = new
|
|
29
|
-
match =
|
|
25
|
+
type = new RawTypeParser(this);
|
|
26
|
+
match = createMatchParser(this);
|
|
30
27
|
declare = (() => ({
|
|
31
28
|
type: this.type
|
|
32
29
|
})).bind(this);
|
|
33
30
|
define = ((def) => def).bind(this);
|
|
34
31
|
preparseRoot(def) {
|
|
35
|
-
if (
|
|
32
|
+
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
36
33
|
return def();
|
|
37
34
|
return def;
|
|
38
35
|
}
|
|
@@ -56,21 +53,19 @@ class RawScope extends schema_1.RawRootScope {
|
|
|
56
53
|
this.parseCache[def] = this.parseString(def, ctx);
|
|
57
54
|
return this.parseCache[def];
|
|
58
55
|
}
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
:
|
|
56
|
+
return hasDomain(def, "object") ?
|
|
57
|
+
parseObject(def, ctx)
|
|
58
|
+
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
62
59
|
}
|
|
63
60
|
parseString(def, ctx) {
|
|
64
61
|
return (this.maybeResolveRoot(def) ??
|
|
65
62
|
((def.endsWith("[]") &&
|
|
66
63
|
this.maybeResolveRoot(def.slice(0, -2))?.array()) ||
|
|
67
|
-
|
|
64
|
+
fullStringParse(new DynamicState(def, ctx))));
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
exports.writeShallowCycleErrorMessage = writeShallowCycleErrorMessage;
|
|
73
|
-
const parseScopeKey = (k) => {
|
|
67
|
+
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
|
|
68
|
+
export const parseScopeKey = (k) => {
|
|
74
69
|
const firstParamIndex = k.indexOf("<");
|
|
75
70
|
if (firstParamIndex === -1) {
|
|
76
71
|
return {
|
|
@@ -79,11 +74,10 @@ const parseScopeKey = (k) => {
|
|
|
79
74
|
};
|
|
80
75
|
}
|
|
81
76
|
if (k.at(-1) !== ">") {
|
|
82
|
-
|
|
77
|
+
throwParseError(`'>' must be the last character of a generic declaration in a scope`);
|
|
83
78
|
}
|
|
84
79
|
return {
|
|
85
80
|
name: k.slice(0, firstParamIndex),
|
|
86
|
-
params:
|
|
81
|
+
params: parseGenericParams(k.slice(firstParamIndex + 1, -1))
|
|
87
82
|
};
|
|
88
83
|
};
|
|
89
|
-
exports.parseScopeKey = parseScopeKey;
|
package/out/type.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const util_1 = require("@arktype/util");
|
|
6
|
-
const generic_js_1 = require("./generic.js");
|
|
7
|
-
const generic_js_2 = require("./parser/generic.js");
|
|
1
|
+
import { ArkErrors, BaseRoot } from "@arktype/schema";
|
|
2
|
+
import { Callable } from "@arktype/util";
|
|
3
|
+
import { Generic } from "./generic.js";
|
|
4
|
+
import { parseGenericParams } from "./parser/generic.js";
|
|
8
5
|
const typeParserAttachments = Object.freeze({
|
|
9
|
-
errors:
|
|
6
|
+
errors: ArkErrors
|
|
10
7
|
});
|
|
11
|
-
class RawTypeParser extends
|
|
8
|
+
export class RawTypeParser extends Callable {
|
|
12
9
|
constructor($) {
|
|
13
10
|
super((...args) => {
|
|
14
11
|
if (args.length === 1) {
|
|
@@ -21,10 +18,10 @@ class RawTypeParser extends util_1.Callable {
|
|
|
21
18
|
args[0].at(-1) === ">") {
|
|
22
19
|
// if there are exactly two args, the first of which looks like <${string}>,
|
|
23
20
|
// treat as a generic
|
|
24
|
-
const params =
|
|
21
|
+
const params = parseGenericParams(args[0].slice(1, -1));
|
|
25
22
|
const def = args[1];
|
|
26
23
|
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
27
|
-
return new
|
|
24
|
+
return new Generic(params, def, $);
|
|
28
25
|
}
|
|
29
26
|
// otherwise, treat as a tuple expression. technically, this also allows
|
|
30
27
|
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
@@ -33,5 +30,4 @@ class RawTypeParser extends util_1.Callable {
|
|
|
33
30
|
}, { bind: $, attach: typeParserAttachments });
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
exports.Type = schema_1.BaseRoot;
|
|
33
|
+
export const Type = BaseRoot;
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
2
|
+
"name": "arktype",
|
|
3
|
+
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
+
"version": "2.0.0-dev.14",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "David Blass",
|
|
8
|
+
"email": "david@arktype.io",
|
|
9
|
+
"url": "https://arktype.io"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/arktypeio/arktype.git"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./out/api.js",
|
|
17
|
+
"types": "./out/api.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./out/api.js",
|
|
20
|
+
"./config": "./out/config.js",
|
|
21
|
+
"./internal/*": "./out/*"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"out"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@arktype/util": "0.0.44",
|
|
28
|
+
"@arktype/schema": "0.1.6"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsx ../repo/build.ts",
|
|
32
|
+
"test": "tsx ../repo/testPackage.ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/out/main.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { ArkError, ArkErrors, ArkTypeError } from "@arktype/schema";
|
|
2
|
-
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
|
-
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
|
-
export { Module } from "./module.js";
|
|
5
|
-
export { scope, type Scope } from "./scope.js";
|
|
6
|
-
export { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
package/out/main.js
DELETED
package/out/package.json
DELETED