arktype 2.0.0-dev.23 → 2.0.0-dev.25
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/ark.d.ts +1 -1
- package/out/ark.js +1 -2
- package/out/parser/definition.d.ts +1 -1
- package/out/parser/objectLiteral.d.ts +34 -15
- package/out/parser/objectLiteral.js +62 -5
- package/out/parser/semantic/bounds.d.ts +1 -1
- package/out/parser/semantic/infer.d.ts +2 -2
- package/out/parser/semantic/validate.d.ts +2 -2
- package/out/parser/string/reduce/shared.d.ts +5 -5
- package/out/parser/string/shift/operand/date.d.ts +2 -4
- package/out/parser/string/shift/operand/enclosed.d.ts +1 -11
- package/out/parser/string/shift/operand/genericArgs.d.ts +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +4 -4
- package/out/parser/string/shift/operand/unenclosed.js +6 -5
- package/out/parser/string/shift/operator/bounds.d.ts +3 -3
- package/out/parser/string/shift/operator/bounds.js +3 -3
- package/out/parser/string/shift/operator/divisor.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/string.d.ts +4 -4
- package/out/parser/tuple.d.ts +6 -6
- package/out/parser/tuple.js +2 -2
- package/out/scope.d.ts +2 -2
- package/out/scope.js +98 -54
- package/out/type.d.ts +7 -5
- package/out/type.js +7 -4
- package/package.json +6 -6
- /package/out/{api.d.ts → index.d.ts} +0 -0
- /package/out/{api.js → index.js} +0 -0
package/out/ark.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ type TsGenericsExports<$ = Ark> = {
|
|
|
13
13
|
"[K]": "V";
|
|
14
14
|
}, $>;
|
|
15
15
|
};
|
|
16
|
-
export declare const tsGenerics: Module<TsGenericsExports
|
|
16
|
+
export declare const tsGenerics: Module<TsGenericsExports>;
|
|
17
17
|
export declare const ambient: Scope<Ark>;
|
|
18
18
|
export declare const ark: Module<Ark>;
|
|
19
19
|
export declare const type: TypeParser<{}>;
|
package/out/ark.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { keywordNodes } from "@arktype/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { scope } from "./scope.js";
|
|
3
3
|
export const tsGenerics = {};
|
|
4
4
|
export const ambient = scope(keywordNodes);
|
|
5
|
-
RawScope.ambient = ambient.raw;
|
|
6
5
|
export const ark = ambient.export();
|
|
7
6
|
export const type = ambient.type;
|
|
8
7
|
export const match = ambient.match;
|
|
@@ -27,6 +27,6 @@ type declarationMismatch<def, declared, $, args> = {
|
|
|
27
27
|
type Terminal = RegExp | type.cast<unknown> | ((...args: never[]) => unknown);
|
|
28
28
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
29
29
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
30
|
-
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) =>
|
|
30
|
+
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
|
|
31
31
|
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
|
|
32
32
|
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type BaseRoot, type Default, type of, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@arktype/schema";
|
|
2
|
-
import { type anyOrNever, type Dict, type ErrorMessage, type Key, type keyError, type merge, type show } from "@arktype/util";
|
|
1
|
+
import { type BaseRoot, type DateLiteral, type Default, type distillOut, type of, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@arktype/schema";
|
|
2
|
+
import { type anyOrNever, type BigintLiteral, type Dict, type ErrorMessage, type Key, type keyError, type merge, type NumberLiteral, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
5
5
|
import type { astToString } from "./semantic/utils.js";
|
|
6
6
|
import type { validateString } from "./semantic/validate.js";
|
|
7
|
+
import type { StringLiteral } from "./string/shift/operand/enclosed.js";
|
|
7
8
|
import { Scanner } from "./string/shift/scanner.js";
|
|
9
|
+
import type { inferString } from "./string/string.js";
|
|
8
10
|
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
9
11
|
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
10
12
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
@@ -13,19 +15,31 @@ export type inferObjectLiteral<def extends object, $, args> = show<"..." extends
|
|
|
13
15
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
14
16
|
*/
|
|
15
17
|
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (
|
|
18
|
+
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ? def[k] extends anyOrNever ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : def[k] extends DefaultValueString<infer baseDef, infer defaultDef> ? (In?: inferDefinition<baseDef, $, args>) => Default<inferDefinition<defaultDef, $, args>> : inferDefinition<def[k], $, args>;
|
|
17
19
|
} & {
|
|
18
20
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
19
21
|
};
|
|
20
22
|
export type validateObjectLiteral<def, $, args> = {
|
|
21
|
-
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? keyError<message> : inferDefinition<indexDef, $, args> extends (PropertyKey | of<PropertyKey, {}>) ? validateDefinition<def[k], $, args> : keyError<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : keyError<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior :
|
|
23
|
+
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? keyError<message> : inferDefinition<indexDef, $, args> extends (PropertyKey | of<PropertyKey, {}>) ? validateDefinition<def[k], $, args> : keyError<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : keyError<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefaultableValue<def, k, $, args>;
|
|
22
24
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
+
type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? validateDefaultValueTuple<def[k], k, $, args> : def[k] extends DefaultValueString ? validateDefaultValueString<def[k], k, $, args> : validateDefinition<def[k], $, args>;
|
|
26
|
+
type DefaultValueTuple<baseDef = unknown, defaultValue = unknown> = readonly [
|
|
27
|
+
baseDef,
|
|
25
28
|
"=",
|
|
26
|
-
|
|
27
|
-
]
|
|
28
|
-
type
|
|
29
|
+
defaultValue
|
|
30
|
+
];
|
|
31
|
+
type validateDefaultValueTuple<def extends DefaultValueTuple, k extends PropertyKey, $, args> = parseKey<k>["kind"] extends "required" ? readonly [
|
|
32
|
+
validateDefinition<def[0], $, args>,
|
|
33
|
+
"=",
|
|
34
|
+
inferDefinition<def[0], $, args>
|
|
35
|
+
] : ErrorMessage<invalidDefaultKeyKindMessage>;
|
|
36
|
+
type DefaultValueString<baseDef extends string = string, defaultDef extends UnitLiteral = UnitLiteral> = `${baseDef}${typeof defaultValueStringOperator}${defaultDef}`;
|
|
37
|
+
declare const defaultValueStringOperator = " = ";
|
|
38
|
+
type validateDefaultValueString<def extends DefaultValueString, k extends PropertyKey, $, args> = def extends DefaultValueString<infer baseDef, infer defaultDef> ? parseKey<k>["kind"] extends "required" ? validateDefinition<baseDef, $, args> extends (infer e extends ErrorMessage) ? e : [
|
|
39
|
+
distillOut<inferString<baseDef, {}, args>>,
|
|
40
|
+
distillOut<inferString<defaultDef, {}, args>>
|
|
41
|
+
] extends [infer base, infer defaultValue] ? defaultValue extends base ? def : ErrorMessage<`${defaultDef} is not assignable to ${baseDef}`> : never : ErrorMessage<invalidDefaultKeyKindMessage> : never;
|
|
42
|
+
type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? Extract<inferDefinition<inner, $, args>, Key> : never;
|
|
29
43
|
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
30
44
|
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, inner extends Key = Key> = {
|
|
31
45
|
kind: kind;
|
|
@@ -41,11 +55,16 @@ interface PreparsedEntry extends PreparsedKey {
|
|
|
41
55
|
value: unknown;
|
|
42
56
|
default: unknown;
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
declare const unitLiteralKeywords: {
|
|
59
|
+
readonly null: null;
|
|
60
|
+
readonly undefined: undefined;
|
|
61
|
+
readonly true: true;
|
|
62
|
+
readonly false: false;
|
|
63
|
+
};
|
|
64
|
+
type UnitLiteralKeyword = keyof typeof unitLiteralKeywords;
|
|
65
|
+
export type UnitLiteral = StringLiteral | BigintLiteral | NumberLiteral | DateLiteral | UnitLiteralKeyword;
|
|
66
|
+
export declare const parseEntry: (key: Key, value: unknown) => PreparsedEntry;
|
|
67
|
+
export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
|
|
49
68
|
export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
|
|
50
69
|
declare const parseKey: (key: Key) => PreparsedKey;
|
|
51
70
|
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${Scanner.EscapeToken}` ? PreparsedKey.from<{
|
|
@@ -67,6 +86,6 @@ type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName
|
|
|
67
86
|
kind: "required";
|
|
68
87
|
key: k extends (`${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
69
88
|
}>;
|
|
70
|
-
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) =>
|
|
89
|
+
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
71
90
|
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
72
91
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArkErrors, normalizeIndex } from "@arktype/schema";
|
|
2
|
-
import { append, isArray, printable, stringAndSymbolicEntriesOf, throwParseError, unset } from "@arktype/util";
|
|
2
|
+
import { anchoredRegex, append, deanchoredSource, integerLikeMatcher, isArray, keysOf, numberLikeMatcher, printable, stringAndSymbolicEntriesOf, throwInternalError, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber, unset } from "@arktype/util";
|
|
3
3
|
import { Scanner } from "./string/shift/scanner.js";
|
|
4
4
|
export const parseObjectLiteral = (def, ctx) => {
|
|
5
5
|
let spread;
|
|
@@ -8,7 +8,7 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
8
8
|
// because to match JS behavior any keys before the spread are overwritten
|
|
9
9
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
10
10
|
// anywhere except for the beginning.
|
|
11
|
-
const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry);
|
|
11
|
+
const parsedEntries = stringAndSymbolicEntriesOf(def).map(entry => parseEntry(entry[0], entry[1]));
|
|
12
12
|
if (parsedEntries[0]?.kind === "...") {
|
|
13
13
|
// remove the spread entry so we can iterate over the remaining entries
|
|
14
14
|
// expecting non-spread entries
|
|
@@ -47,7 +47,7 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
47
47
|
const value = ctx.$.parse(entry.value, ctx);
|
|
48
48
|
const inner = { key: entry.key, value };
|
|
49
49
|
if (entry.default !== unset) {
|
|
50
|
-
const out = value(entry.default);
|
|
50
|
+
const out = value.traverse(entry.default);
|
|
51
51
|
if (out instanceof ArkErrors)
|
|
52
52
|
throwParseError(`Default value at ${printable(entry.key)} ${out}`);
|
|
53
53
|
value.assert(entry.default);
|
|
@@ -64,7 +64,28 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
64
64
|
};
|
|
65
65
|
export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
|
|
66
66
|
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
67
|
-
|
|
67
|
+
const defaultValueStringOperator = " = ";
|
|
68
|
+
const unitLiteralKeywords = {
|
|
69
|
+
null: null,
|
|
70
|
+
undefined,
|
|
71
|
+
true: true,
|
|
72
|
+
false: false
|
|
73
|
+
};
|
|
74
|
+
/** Matches a single or double-quoted date or string literal */
|
|
75
|
+
const stringLiteral = anchoredRegex(/(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/);
|
|
76
|
+
/** Matches a definition including a valid default value expression */
|
|
77
|
+
const defaultExpressionMatcher = new RegExp(`^(?<baseDef>[\\s\\S]*) = (` +
|
|
78
|
+
`(?<string>${deanchoredSource(stringLiteral)})` +
|
|
79
|
+
`|(?<date>d${deanchoredSource(stringLiteral)})` +
|
|
80
|
+
`|(?<bigint>${deanchoredSource(integerLikeMatcher)}n)` +
|
|
81
|
+
`|(?<number>${deanchoredSource(numberLikeMatcher)})` +
|
|
82
|
+
`|(?<keyword>${keysOf(unitLiteralKeywords).join("|")})` +
|
|
83
|
+
`)$`);
|
|
84
|
+
const parsePossibleDefaultExpression = (s) => {
|
|
85
|
+
const result = defaultExpressionMatcher.exec(s);
|
|
86
|
+
return result && result.groups;
|
|
87
|
+
};
|
|
88
|
+
export const parseEntry = (key, value) => {
|
|
68
89
|
const parsedKey = parseKey(key);
|
|
69
90
|
if (isArray(value) && value[1] === "=") {
|
|
70
91
|
if (parsedKey.kind !== "required")
|
|
@@ -76,6 +97,13 @@ export const parseEntry = ([key, value]) => {
|
|
|
76
97
|
default: value[2]
|
|
77
98
|
};
|
|
78
99
|
}
|
|
100
|
+
// if a string includes " = ", it might have a default value,
|
|
101
|
+
// but it could also be a string literal like "' = '"
|
|
102
|
+
if (typeof value === "string" && value.includes(defaultValueStringOperator)) {
|
|
103
|
+
const result = parsePossibleDefaultExpression(value);
|
|
104
|
+
if (result)
|
|
105
|
+
return parseDefaultValueStringExpression(parsedKey, result);
|
|
106
|
+
}
|
|
79
107
|
return {
|
|
80
108
|
kind: parsedKey.kind,
|
|
81
109
|
key: parsedKey.key,
|
|
@@ -83,8 +111,37 @@ export const parseEntry = ([key, value]) => {
|
|
|
83
111
|
default: unset
|
|
84
112
|
};
|
|
85
113
|
};
|
|
114
|
+
const parseDefaultValueStringExpression = (parsedKey, match) => {
|
|
115
|
+
if (parsedKey.kind !== "required")
|
|
116
|
+
throwParseError(invalidDefaultKeyKindMessage);
|
|
117
|
+
let defaultValue;
|
|
118
|
+
if (match.keyword)
|
|
119
|
+
defaultValue = unitLiteralKeywords[match.keyword];
|
|
120
|
+
else if (match.string)
|
|
121
|
+
defaultValue = match.string.slice(1, -1);
|
|
122
|
+
else if (match.number) {
|
|
123
|
+
defaultValue = tryParseWellFormedNumber(match.number, {
|
|
124
|
+
errorOnFail: true
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (match.date)
|
|
128
|
+
defaultValue = new Date(match.date);
|
|
129
|
+
else if (match.bigint) {
|
|
130
|
+
defaultValue =
|
|
131
|
+
tryParseWellFormedBigint(match.bigint) ??
|
|
132
|
+
throwInternalError(`Unexpected default bigint parse result ${match.bigint}`);
|
|
133
|
+
}
|
|
134
|
+
else
|
|
135
|
+
throwInternalError(`Unexpected default expression parse result ${match}`);
|
|
136
|
+
return {
|
|
137
|
+
kind: "optional",
|
|
138
|
+
key: parsedKey.key,
|
|
139
|
+
value: match.baseDef,
|
|
140
|
+
default: defaultValue
|
|
141
|
+
};
|
|
142
|
+
};
|
|
86
143
|
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
87
|
-
export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. {
|
|
144
|
+
export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
|
|
88
145
|
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
89
146
|
: key.at(-1) === "?" ?
|
|
90
147
|
key.at(-2) === Scanner.escapeToken ?
|
|
@@ -10,6 +10,6 @@ export type validateBound<boundedAst, comparator extends Comparator, limit exten
|
|
|
10
10
|
type isNumericallyBoundable<bounded> = [
|
|
11
11
|
bounded
|
|
12
12
|
] extends [number] ? true : [bounded] extends [string] ? true : [bounded] extends [array] ? true : false;
|
|
13
|
-
export declare const writeDoubleRightBoundMessage: <root extends string>(root: root) =>
|
|
13
|
+
export declare const writeDoubleRightBoundMessage: <root extends string>(root: root) => writeDoubleRightBoundMessage<root>;
|
|
14
14
|
type writeDoubleRightBoundMessage<root extends string> = `Expression ${root} must have at most one right bound`;
|
|
15
15
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Date, DateLiteral, GenericProps, LimitLiteral, RegexLiteral,
|
|
1
|
+
import type { Date, DateLiteral, GenericProps, LimitLiteral, RegexLiteral, constrain, distillIn, inferIntersection, normalizeLimit, string } from "@arktype/schema";
|
|
2
2
|
import type { BigintLiteral, array } from "@arktype/util";
|
|
3
3
|
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.js";
|
|
4
4
|
import type { inferDefinition } from "../definition.js";
|
|
@@ -21,4 +21,4 @@ export type PostfixOperator = "[]";
|
|
|
21
21
|
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
22
22
|
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
23
23
|
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
24
|
-
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof
|
|
24
|
+
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof ArkEnv.$ ? ArkEnv.$[token] : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
|
|
@@ -12,9 +12,9 @@ export type validateAst<ast, $, args> = ast extends string ? validateStringAst<a
|
|
|
12
12
|
};
|
|
13
13
|
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
14
14
|
type validateGenericArgs<argAsts extends unknown[], $, args> = argAsts extends [infer head, ...infer tail] ? validateAst<head, $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateGenericArgs<tail, $, args> : undefined;
|
|
15
|
-
export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) =>
|
|
15
|
+
export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) => writeUnsatisfiableExpressionError<expression>;
|
|
16
16
|
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
17
|
-
export declare const writePrefixedPrivateReferenceMessage: <def extends
|
|
17
|
+
export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
|
|
18
18
|
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
19
19
|
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
|
|
20
20
|
$[alias]
|
|
@@ -30,13 +30,13 @@ export type OpenLeftBound = {
|
|
|
30
30
|
limit: LimitLiteral;
|
|
31
31
|
comparator: MinComparator;
|
|
32
32
|
};
|
|
33
|
-
export declare const writeUnmatchedGroupCloseMessage: <unscanned extends string>(unscanned: unscanned) =>
|
|
33
|
+
export declare const writeUnmatchedGroupCloseMessage: <unscanned extends string>(unscanned: unscanned) => writeUnmatchedGroupCloseMessage<unscanned>;
|
|
34
34
|
export type writeUnmatchedGroupCloseMessage<unscanned extends string> = `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`;
|
|
35
|
-
export declare const writeUnclosedGroupMessage: <missingChar extends string>(missingChar: missingChar) =>
|
|
35
|
+
export declare const writeUnclosedGroupMessage: <missingChar extends string>(missingChar: missingChar) => writeUnclosedGroupMessage<missingChar>;
|
|
36
36
|
export type writeUnclosedGroupMessage<missingChar extends string> = `Missing ${missingChar}`;
|
|
37
|
-
export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends
|
|
37
|
+
export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends MinComparator>(min: min, comparator: comparator) => writeOpenRangeMessage<min, comparator>;
|
|
38
38
|
export type writeOpenRangeMessage<min extends LimitLiteral, comparator extends MinComparator> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
39
39
|
export type writeUnpairableComparatorMessage<comparator extends Comparator> = `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
40
|
-
export declare const writeUnpairableComparatorMessage: <comparator extends
|
|
41
|
-
export declare const writeMultipleLeftBoundsMessage: <openLimit extends LimitLiteral, openComparator extends
|
|
40
|
+
export declare const writeUnpairableComparatorMessage: <comparator extends Comparator>(comparator: comparator) => writeUnpairableComparatorMessage<comparator>;
|
|
41
|
+
export declare const writeMultipleLeftBoundsMessage: <openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator>(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => writeMultipleLeftBoundsMessage<openLimit, openComparator, limit, comparator>;
|
|
42
42
|
export type writeMultipleLeftBoundsMessage<openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator> = `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[comparator]})`;
|
|
@@ -2,10 +2,8 @@ import type { DateLiteral } from "@arktype/schema";
|
|
|
2
2
|
export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
|
|
3
3
|
export declare const isValidDate: (d: Date) => boolean;
|
|
4
4
|
export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
|
|
5
|
-
|
|
6
|
-
export declare const writeInvalidDateMessage: <source extends string>(source: source) => `'${source}' could not be parsed by the Date constructor`;
|
|
5
|
+
export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
|
|
7
6
|
export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
|
|
8
7
|
export type DateInput = ConstructorParameters<typeof Date>[0];
|
|
9
8
|
export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
|
|
10
|
-
export declare const tryParseDate: <errorOnFail extends
|
|
11
|
-
export {};
|
|
9
|
+
export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
|
|
@@ -33,16 +33,6 @@ declare const enclosingCharDescriptions: {
|
|
|
33
33
|
readonly "/": "forward slash";
|
|
34
34
|
};
|
|
35
35
|
type enclosingCharDescriptions = typeof enclosingCharDescriptions;
|
|
36
|
-
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends
|
|
37
|
-
readonly '"': "double-quote";
|
|
38
|
-
readonly "'": "single-quote";
|
|
39
|
-
readonly "/": "forward slash";
|
|
40
|
-
}[{
|
|
41
|
-
readonly "d'": "'";
|
|
42
|
-
readonly 'd"': "\"";
|
|
43
|
-
readonly "'": "'";
|
|
44
|
-
readonly '"': "\"";
|
|
45
|
-
readonly "/": "/";
|
|
46
|
-
}[enclosingStart]]}`;
|
|
36
|
+
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends EnclosingStartToken>(fragment: fragment, enclosingStart: enclosingStart) => writeUnterminatedEnclosedMessage<fragment, enclosingStart>;
|
|
47
37
|
export type writeUnterminatedEnclosedMessage<fragment extends string, enclosingStart extends EnclosingStartToken> = `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[EnclosingTokens[enclosingStart]]}`;
|
|
48
38
|
export {};
|
|
@@ -23,6 +23,6 @@ type _parseGenericArgs<name extends string, params extends string[], unscanned e
|
|
|
23
23
|
asts: infer nextAsts extends unknown[];
|
|
24
24
|
unscanned: infer nextUnscanned extends string;
|
|
25
25
|
}) ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends params["length"] ? ParsedArgs<nextAsts, nextUnscanned> : state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>> : finalArgState["finalizer"] extends "," ? _parseGenericArgs<name, params, nextUnscanned, $, args, nextDefs, nextAsts> : finalArgState["finalizer"] extends ErrorMessage ? finalArgState : state.error<writeUnclosedGroupMessage<">">> : never : never;
|
|
26
|
-
export declare const writeInvalidGenericArgsMessage: <name extends string, params extends string[], argDefs extends string[]>(name: name, params: params, argDefs: argDefs) =>
|
|
26
|
+
export declare const writeInvalidGenericArgsMessage: <name extends string, params extends string[], argDefs extends string[]>(name: name, params: params, argDefs: argDefs) => writeInvalidGenericArgsMessage<name, params, argDefs>;
|
|
27
27
|
export type writeInvalidGenericArgsMessage<name extends string, params extends string[], argDefs extends string[]> = `${name}<${join<params, ", ">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends (0) ? "" : `: ${join<argDefs, ",">}`})`;
|
|
28
28
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseRoot, writeUnresolvableMessage, type GenericProps, type
|
|
1
|
+
import { BaseRoot, writeUnresolvableMessage, type GenericProps, type arkKind, type writeNonSubmoduleDotMessage } from "@arktype/schema";
|
|
2
2
|
import { type BigintLiteral, type Completion, type ErrorMessage, type anyOrNever, type join } from "@arktype/util";
|
|
3
3
|
import type { Generic } from "../../../../generic.js";
|
|
4
4
|
import type { GenericInstantiationAst } from "../../../semantic/infer.js";
|
|
@@ -13,7 +13,7 @@ export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntil
|
|
|
13
13
|
] extends [anyOrNever] ? state.setRoot<s, result, unscanned> : $[result] extends GenericProps ? parseGenericInstantiation<token, $[result], state.scanTo<s, unscanned>, $, args> : state.setRoot<s, result, unscanned> : state.setRoot<s, result, unscanned> : never : never;
|
|
14
14
|
export declare const parseGenericInstantiation: (name: string, g: Generic, s: DynamicState) => BaseRoot;
|
|
15
15
|
export type parseGenericInstantiation<name extends string, g extends GenericProps, s extends StaticState, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g["params"], unscanned, $, args> extends (infer result) ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgsMessage<name, g["params"], []>>;
|
|
16
|
-
type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof
|
|
16
|
+
type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof ArkEnv.$ ? token : token extends keyof $ ? token : `#${token}` extends keyof $ ? token : token extends keyof args ? token : token extends `${number}` ? token : token extends BigintLiteral ? token : token extends (`${infer submodule extends (keyof $ | keyof ArkEnv.$) & string}.${infer reference}`) ? tryResolveSubmodule<token, submodule, reference, s, $ & ArkEnv.$, args> : unresolvableError<s, token, $, args, []>;
|
|
17
17
|
type tryResolveSubmodule<token, submodule extends keyof $ & string, reference extends string, s extends StaticState, $, args> = $[submodule] extends {
|
|
18
18
|
[arkKind]: "module";
|
|
19
19
|
} ? reference extends keyof $[submodule] ? token : unresolvableError<s, reference, $[submodule], args, [submodule]> : ErrorMessage<writeNonSubmoduleDotMessage<submodule>>;
|
|
@@ -24,7 +24,7 @@ type qualifiedReference<reference extends string, submodulePath extends string[]
|
|
|
24
24
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath extends [] ? BaseCompletions<$, args> : keyof $, `${token}${string}`>;
|
|
25
25
|
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|
|
26
26
|
export type writeMissingRightOperandMessage<token extends string, unscanned extends string = ""> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
27
|
-
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) =>
|
|
28
|
-
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) =>
|
|
27
|
+
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) => writeMissingRightOperandMessage<token, unscanned>;
|
|
28
|
+
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => writeExpressionExpectedMessage<unscanned>;
|
|
29
29
|
export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
30
30
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRoot, hasArkKind, writeUnresolvableMessage } from "@arktype/schema";
|
|
2
|
-
import { printable, throwParseError,
|
|
2
|
+
import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@arktype/util";
|
|
3
3
|
import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
|
|
4
4
|
import { parseGenericArgs, writeInvalidGenericArgsMessage } from "./genericArgs.js";
|
|
5
5
|
export const parseUnenclosed = (s) => {
|
|
@@ -28,18 +28,19 @@ const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
|
|
|
28
28
|
: writeUnresolvableMessage(token));
|
|
29
29
|
const maybeParseReference = (s, token) => {
|
|
30
30
|
if (s.ctx.args?.[token])
|
|
31
|
-
return s.ctx.args[token].
|
|
31
|
+
return s.ctx.args[token].internal;
|
|
32
32
|
const resolution = s.ctx.$.maybeResolve(token);
|
|
33
33
|
if (resolution instanceof BaseRoot)
|
|
34
34
|
return resolution;
|
|
35
35
|
if (resolution === undefined)
|
|
36
36
|
return;
|
|
37
|
-
if (hasArkKind(resolution, "generic"))
|
|
38
|
-
return parseGenericInstantiation(token,
|
|
37
|
+
if (hasArkKind(resolution, "generic")) {
|
|
38
|
+
return parseGenericInstantiation(token, throwParseError("Generics unsupported"), s);
|
|
39
|
+
}
|
|
39
40
|
return throwParseError(`Unexpected resolution ${printable(resolution)}`);
|
|
40
41
|
};
|
|
41
42
|
const maybeParseUnenclosedLiteral = (s, token) => {
|
|
42
|
-
const maybeNumber =
|
|
43
|
+
const maybeNumber = tryParseWellFormedNumber(token);
|
|
43
44
|
if (maybeNumber !== undefined)
|
|
44
45
|
return s.ctx.$.node("unit", { unit: maybeNumber });
|
|
45
46
|
const maybeBigint = tryParseWellFormedBigint(token);
|
|
@@ -2,7 +2,7 @@ import { type BaseRoot, type BoundKind, type LimitLiteral } from "@arktype/schem
|
|
|
2
2
|
import { type keySet } from "@arktype/util";
|
|
3
3
|
import type { astToString } from "../../../semantic/utils.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.js";
|
|
5
|
-
import { type Comparator, type InvertedComparators, type MaxComparator
|
|
5
|
+
import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.js";
|
|
6
6
|
import type { StaticState, state } from "../../reduce/static.js";
|
|
7
7
|
import type { parseOperand } from "../operand/operand.js";
|
|
8
8
|
import type { Scanner } from "../scanner.js";
|
|
@@ -19,11 +19,11 @@ declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) =>
|
|
|
19
19
|
type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends OneCharComparator ? [start, unscanned] : state.error<singleEqualsMessage>;
|
|
20
20
|
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
21
21
|
export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
|
|
22
|
-
export declare const singleEqualsMessage = "= is not
|
|
22
|
+
export declare const singleEqualsMessage = "= is not valid here. Default values must be specified on objects like { isAdmin: 'boolean = false' }";
|
|
23
23
|
type singleEqualsMessage = typeof singleEqualsMessage;
|
|
24
24
|
export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => void;
|
|
25
25
|
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends `${infer limit extends LimitLiteral}` ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : state.error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : state.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
|
|
26
|
-
export declare const writeInvalidLimitMessage: <comparator extends
|
|
26
|
+
export declare const writeInvalidLimitMessage: <comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => writeInvalidLimitMessage<comparator, limit, boundKind>;
|
|
27
27
|
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
28
28
|
export type BoundExpressionKind = "left" | "right";
|
|
29
29
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { internal, jsObjects, tsKeywords, writeUnboundableMessage } from "@arktype/schema";
|
|
2
2
|
import { isKeyOf, throwParseError } from "@arktype/util";
|
|
3
3
|
import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
4
4
|
import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
|
|
@@ -41,7 +41,7 @@ export const getBoundKinds = (comparator, limit, root, boundKind) => {
|
|
|
41
41
|
: comparator[0] === ">" ? ["min"]
|
|
42
42
|
: ["max"]);
|
|
43
43
|
}
|
|
44
|
-
if (root.extends(
|
|
44
|
+
if (root.extends(internal.lengthBoundable)) {
|
|
45
45
|
if (typeof limit !== "number") {
|
|
46
46
|
return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
|
|
47
47
|
}
|
|
@@ -57,7 +57,7 @@ export const getBoundKinds = (comparator, limit, root, boundKind) => {
|
|
|
57
57
|
}
|
|
58
58
|
return throwParseError(writeUnboundableMessage(root.expression));
|
|
59
59
|
};
|
|
60
|
-
export const singleEqualsMessage =
|
|
60
|
+
export const singleEqualsMessage = `= is not valid here. Default values must be specified on objects like { isAdmin: 'boolean = false' }`;
|
|
61
61
|
const openLeftBoundToRoot = (leftBound) => ({
|
|
62
62
|
rule: isDateLiteral(leftBound.limit) ?
|
|
63
63
|
extractDateLiteralSource(leftBound.limit)
|
|
@@ -3,5 +3,5 @@ import type { StaticState, state } from "../../reduce/static.js";
|
|
|
3
3
|
import type { Scanner } from "../scanner.js";
|
|
4
4
|
export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
|
|
5
5
|
export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
6
|
-
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) =>
|
|
6
|
+
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
|
|
7
7
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -5,7 +5,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.js";
|
|
|
5
5
|
import { parseDivisor } from "./divisor.js";
|
|
6
6
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
7
7
|
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
8
|
-
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) =>
|
|
8
|
+
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
9
9
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
10
10
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
11
11
|
type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot, resolvableReferenceIn } from "@arktype/schema";
|
|
2
2
|
import { type ErrorMessage } from "@arktype/util";
|
|
3
3
|
import type { inferAstRoot } from "../semantic/infer.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
|
|
5
5
|
import type { StringifiablePrefixOperator } from "./reduce/shared.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { StaticState, state } from "./reduce/static.js";
|
|
7
7
|
import type { parseOperand } from "./shift/operand/operand.js";
|
|
8
|
-
import { type parseOperator
|
|
8
|
+
import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.js";
|
|
9
9
|
/**
|
|
10
10
|
* Try to parse the definition from right to left using the most common syntax.
|
|
11
11
|
* This can be much more efficient for simple definitions.
|
|
@@ -15,7 +15,7 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? def
|
|
|
15
15
|
"[]"
|
|
16
16
|
] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
|
|
17
17
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
18
|
-
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<
|
|
18
|
+
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkEnv.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
19
19
|
export declare const fullStringParse: (s: DynamicState) => BaseRoot;
|
|
20
20
|
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
|
|
21
21
|
export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
|
package/out/parser/tuple.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type
|
|
2
|
-
import { type Constructor, type Domain, type ErrorMessage, type array, type conform, type show } from "@arktype/util";
|
|
1
|
+
import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillOut, type inferIntersection, type inferMorphOut, type inferPredicate } from "@arktype/schema";
|
|
2
|
+
import { type BuiltinObjectKind, type Constructor, type Domain, type ErrorMessage, type array, type conform, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
5
5
|
import type { InfixOperator, PostfixExpression } from "./semantic/infer.js";
|
|
@@ -86,7 +86,7 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
|
|
|
86
86
|
] : [])
|
|
87
87
|
];
|
|
88
88
|
}, $, args> : s;
|
|
89
|
-
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) =>
|
|
89
|
+
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
|
|
90
90
|
type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
|
|
91
91
|
export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
92
92
|
type multipleVariadicMessage = typeof multipleVariadicMesage;
|
|
@@ -103,7 +103,7 @@ export type validatePostfixExpression<def extends PostfixExpression, $, args> =
|
|
|
103
103
|
export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
|
|
104
104
|
validateDefinition<def[0], $, args>,
|
|
105
105
|
def[1],
|
|
106
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<
|
|
106
|
+
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillOut<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? BaseMeta | string : validateDefinition<def[2], $, args>
|
|
107
107
|
];
|
|
108
108
|
export type UnparsedTupleExpressionInput = {
|
|
109
109
|
instanceof: Constructor;
|
|
@@ -122,9 +122,9 @@ export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
|
|
|
122
122
|
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
123
123
|
export declare const parseMorphTuple: PostfixParser<"=>">;
|
|
124
124
|
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
125
|
-
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<
|
|
125
|
+
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
126
126
|
export declare const parseNarrowTuple: PostfixParser<":">;
|
|
127
127
|
export type IndexZeroOperator = "keyof" | "instanceof" | "===";
|
|
128
128
|
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
129
|
-
export declare const writeInvalidConstructorMessage: <actual extends Domain |
|
|
129
|
+
export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;
|
|
130
130
|
export {};
|
package/out/parser/tuple.js
CHANGED
|
@@ -34,7 +34,7 @@ export const parseTupleLiteral = (def, ctx) => {
|
|
|
34
34
|
sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return ctx.$.
|
|
37
|
+
return ctx.$.internal.schema(sequences.map(sequence => ({
|
|
38
38
|
proto: Array,
|
|
39
39
|
sequence
|
|
40
40
|
})));
|
|
@@ -75,7 +75,7 @@ const appendElement = (base, kind, element) => {
|
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
// e.g. [string, ...number[]]
|
|
78
|
-
base.variadic = element.
|
|
78
|
+
base.variadic = element.internal;
|
|
79
79
|
}
|
|
80
80
|
return base;
|
|
81
81
|
}
|
package/out/scope.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, type
|
|
1
|
+
import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, 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
3
|
import { Generic } from "./generic.js";
|
|
4
4
|
import { type MatchParser } from "./match.js";
|
|
@@ -40,7 +40,7 @@ export type moduleKeyOf<$> = {
|
|
|
40
40
|
[arkKind]: "module";
|
|
41
41
|
} ? k & string : never;
|
|
42
42
|
}[keyof $];
|
|
43
|
-
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : token extends
|
|
43
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : token extends `${infer submodule}.${infer subalias}` ? submodule extends moduleKeyOf<ArkEnv.$> ? subalias extends keyof ArkEnv.$[submodule] ? ArkEnv.$[submodule][subalias] : never : never : never;
|
|
44
44
|
export interface ParseContext {
|
|
45
45
|
$: RawScope;
|
|
46
46
|
args?: Record<string, UnknownRoot>;
|
package/out/scope.js
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
1
35
|
import { RawRootScope, hasArkKind } from "@arktype/schema";
|
|
2
|
-
import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
|
|
36
|
+
import { bound, domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
|
|
3
37
|
import { Generic } from "./generic.js";
|
|
4
38
|
import { createMatchParser } from "./match.js";
|
|
5
39
|
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
@@ -8,62 +42,72 @@ import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
|
8
42
|
import { fullStringParse } from "./parser/string/string.js";
|
|
9
43
|
import { RawTypeParser } from "./type.js";
|
|
10
44
|
export const scope = ((def, config = {}) => new RawScope(def, config));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: def[k];
|
|
45
|
+
let RawScope = (() => {
|
|
46
|
+
let _classSuper = RawRootScope;
|
|
47
|
+
let _instanceExtraInitializers = [];
|
|
48
|
+
let _parseRoot_decorators;
|
|
49
|
+
return class RawScope extends _classSuper {
|
|
50
|
+
static {
|
|
51
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
52
|
+
_parseRoot_decorators = [bound];
|
|
53
|
+
__esDecorate(this, null, _parseRoot_decorators, { kind: "method", name: "parseRoot", static: false, private: false, access: { has: obj => "parseRoot" in obj, get: obj => obj.parseRoot }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
54
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
22
55
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return def();
|
|
34
|
-
return def;
|
|
35
|
-
}
|
|
36
|
-
parseRoot(def) {
|
|
37
|
-
// args: { this: {} as RawRoot },
|
|
38
|
-
return this.parse(def, {
|
|
39
|
-
$: this,
|
|
40
|
-
args: {}
|
|
41
|
-
// type parsing can bypass nodes if it hits the cache,
|
|
42
|
-
// so bind it directly (could be optimized)
|
|
43
|
-
}).bindScope(this);
|
|
44
|
-
}
|
|
45
|
-
parse(def, ctx) {
|
|
46
|
-
if (typeof def === "string") {
|
|
47
|
-
if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
|
|
48
|
-
// we can only rely on the cache if there are no contextual
|
|
49
|
-
// resolutions like "this" or generic args
|
|
50
|
-
return this.parseString(def, ctx);
|
|
56
|
+
parseCache = (__runInitializers(this, _instanceExtraInitializers), {});
|
|
57
|
+
constructor(def, config) {
|
|
58
|
+
const aliases = {};
|
|
59
|
+
for (const k in def) {
|
|
60
|
+
const parsedKey = parseScopeKey(k);
|
|
61
|
+
aliases[parsedKey.name] =
|
|
62
|
+
parsedKey.params.length ?
|
|
63
|
+
// TODO: this
|
|
64
|
+
new Generic(parsedKey.params, def[k], {})
|
|
65
|
+
: def[k];
|
|
51
66
|
}
|
|
52
|
-
|
|
53
|
-
this.parseCache[def] = this.parseString(def, ctx);
|
|
54
|
-
return this.parseCache[def];
|
|
67
|
+
super(aliases, config);
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
69
|
+
type = new RawTypeParser(this);
|
|
70
|
+
match = createMatchParser(this);
|
|
71
|
+
declare = (() => ({
|
|
72
|
+
type: this.type
|
|
73
|
+
})).bind(this);
|
|
74
|
+
define = ((def) => def).bind(this);
|
|
75
|
+
preparseRoot(def) {
|
|
76
|
+
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
77
|
+
return def();
|
|
78
|
+
return def;
|
|
79
|
+
}
|
|
80
|
+
parseRoot(def) {
|
|
81
|
+
return this.parse(def, {
|
|
82
|
+
$: this,
|
|
83
|
+
// args: { this: {} as RawRoot },
|
|
84
|
+
args: {}
|
|
85
|
+
}).bindScope(this);
|
|
86
|
+
}
|
|
87
|
+
parse(def, ctx) {
|
|
88
|
+
if (typeof def === "string") {
|
|
89
|
+
if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
|
|
90
|
+
// we can only rely on the cache if there are no contextual
|
|
91
|
+
// resolutions like "this" or generic args
|
|
92
|
+
return this.parseString(def, ctx);
|
|
93
|
+
}
|
|
94
|
+
if (!this.parseCache[def])
|
|
95
|
+
this.parseCache[def] = this.parseString(def, ctx);
|
|
96
|
+
return this.parseCache[def];
|
|
97
|
+
}
|
|
98
|
+
return hasDomain(def, "object") ?
|
|
99
|
+
parseObject(def, ctx)
|
|
100
|
+
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
101
|
+
}
|
|
102
|
+
parseString(def, ctx) {
|
|
103
|
+
return (this.maybeResolveRoot(def) ??
|
|
104
|
+
((def.endsWith("[]") &&
|
|
105
|
+
this.maybeResolveRoot(def.slice(0, -2))?.array()) ||
|
|
106
|
+
fullStringParse(new DynamicState(def, ctx))));
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
})();
|
|
110
|
+
export { RawScope };
|
|
67
111
|
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
|
|
68
112
|
export const parseScopeKey = (k) => {
|
|
69
113
|
const firstParamIndex = k.indexOf("<");
|
package/out/type.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArkErrors, BaseRoot, type BaseMeta, type ConstraintKind, type Disjoint, type DivisorSchema, type ExactLengthSchema, type ExclusiveDateRangeSchema, type ExclusiveNumericRangeSchema, type InclusiveDateRangeSchema, type InclusiveNumericRangeSchema, type InnerRoot, type Morph, type MorphAst, type NodeSchema, type Out, type PatternSchema, type Predicate, type Prerequisite, type PrimitiveConstraintKind, type Root, type constrain, type constraintKindOf, type distillIn, type distillOut, type exclusivizeRangeSchema, type inferIntersection, type inferMorphOut, type inferPipes, type inferPredicate, type writeInvalidOperandMessage } from "@arktype/schema";
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseMeta, type ConstraintKind, type Disjoint, type DivisorSchema, type ExactLengthSchema, type ExclusiveDateRangeSchema, type ExclusiveNumericRangeSchema, type InclusiveDateRangeSchema, type InclusiveNumericRangeSchema, type InnerRoot, type Morph, type MorphAst, type NodeSchema, type Out, type PatternSchema, type Predicate, type Prerequisite, type PrimitiveConstraintKind, type Root, type constrain, type constraintKindOf, type distillIn, type distillOut, type exclusivizeRangeSchema, type indexInto, type indexOf, type inferIntersection, type inferMorphOut, type inferPipes, type inferPredicate, type writeInvalidOperandMessage } from "@arktype/schema";
|
|
2
2
|
import { Callable, type Constructor, type ErrorMessage, type array, type conform } from "@arktype/util";
|
|
3
3
|
import { Generic, type validateParameterString } from "./generic.js";
|
|
4
4
|
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
|
|
@@ -13,6 +13,7 @@ export interface TypeParser<$ = {}> {
|
|
|
13
13
|
<params extends string, const def>(params: `<${validateParameterString<params>}>`, def: validateDefinition<def, $, {
|
|
14
14
|
[param in parseGenericParams<params>[number]]: unknown;
|
|
15
15
|
}>): Generic<parseGenericParams<params>, def, $>;
|
|
16
|
+
raw(def: unknown): Type<any, $>;
|
|
16
17
|
errors: typeof ArkErrors;
|
|
17
18
|
}
|
|
18
19
|
export declare class RawTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
|
|
@@ -40,12 +41,15 @@ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> {
|
|
|
40
41
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>;
|
|
41
42
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): Type<inferPipes<t, [a, b, c, d, e, f]>, $>;
|
|
42
43
|
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>;
|
|
43
|
-
narrow<
|
|
44
|
+
narrow<predicate extends Predicate<distillOut<t>>>(predicate: predicate): Type<t extends MorphAst ? inferPredicate<this["tOut"], predicate> extends infer narrowed ? (In: this["tIn"]) => Out<narrowed> : never : inferPredicate<t, predicate>, $>;
|
|
44
45
|
equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
45
46
|
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
46
47
|
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
47
48
|
extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
48
49
|
overlaps<def>(r: validateTypeRoot<def, $>): boolean;
|
|
50
|
+
get<k1 extends indexOf<t>>(k1: k1 | AnyType<k1>): Type<indexInto<t, k1>, $>;
|
|
51
|
+
get<k1 extends indexOf<t>, k2 extends indexOf<indexInto<t, k1>>>(k1: k1 | AnyType<k1>, k2: k2 | AnyType<k2>): Type<indexInto<indexInto<t, k1>, k2>, $>;
|
|
52
|
+
get<k1 extends indexOf<t>, k2 extends indexOf<indexInto<t, k1>>, k3 extends indexOf<indexInto<indexInto<t, k1>, k2>>>(k1: k1 | AnyType<k1>, k2: k2 | AnyType<k2>, k3: k3 | AnyType<k3>): Type<indexInto<indexInto<indexInto<t, k1>, k2>, k3>, $>;
|
|
49
53
|
constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
|
|
50
54
|
satisfying<predicate extends Predicate<distillIn<t>>>(predicate: predicate): Type<t extends MorphAst ? (In: inferPredicate<this["tIn"], predicate>) => Out<this["tOut"]> : inferPredicate<t, predicate>, $>;
|
|
51
55
|
divisibleBy<const schema extends DivisorSchema>(this: validateChainedConstraint<"divisor", this>, schema: schema): Type<constrain<t, "divisor", schema>, $>;
|
|
@@ -69,9 +73,7 @@ export interface Type<
|
|
|
69
73
|
out t = unknown, $ = {}> extends _Type<t, $> {
|
|
70
74
|
}
|
|
71
75
|
export type TypeConstructor<t = unknown, $ = {}> = new (def: unknown, $: Scope<$>) => Type<t, $>;
|
|
72
|
-
export type AnyType<
|
|
73
|
-
/** @ts-expect-error allow instantiation assignment to the base type */
|
|
74
|
-
out t = unknown, $ = any> = Type<t, $>;
|
|
76
|
+
export type AnyType<out t = unknown> = Type<t, any>;
|
|
75
77
|
export declare const Type: TypeConstructor;
|
|
76
78
|
export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
|
|
77
79
|
export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $, bindThis<def>>;
|
package/out/type.js
CHANGED
|
@@ -2,9 +2,6 @@ import { ArkErrors, BaseRoot } from "@arktype/schema";
|
|
|
2
2
|
import { Callable } from "@arktype/util";
|
|
3
3
|
import { Generic } from "./generic.js";
|
|
4
4
|
import { parseGenericParams } from "./parser/generic.js";
|
|
5
|
-
const typeParserAttachments = Object.freeze({
|
|
6
|
-
errors: ArkErrors
|
|
7
|
-
});
|
|
8
5
|
export class RawTypeParser extends Callable {
|
|
9
6
|
constructor($) {
|
|
10
7
|
super((...args) => {
|
|
@@ -27,7 +24,13 @@ export class RawTypeParser extends Callable {
|
|
|
27
24
|
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
28
25
|
// part of the API as specified by the associated types
|
|
29
26
|
return $.parseRoot(args);
|
|
30
|
-
}, {
|
|
27
|
+
}, {
|
|
28
|
+
bind: $,
|
|
29
|
+
attach: {
|
|
30
|
+
errors: ArkErrors,
|
|
31
|
+
raw: $.parseRoot
|
|
32
|
+
}
|
|
33
|
+
});
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
export const Type = BaseRoot;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
-
"version": "2.0.0-dev.
|
|
4
|
+
"version": "2.0.0-dev.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"url": "https://github.com/arktypeio/arktype.git"
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
|
-
"main": "./out/
|
|
17
|
-
"types": "./out/
|
|
16
|
+
"main": "./out/index.js",
|
|
17
|
+
"types": "./out/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./out/
|
|
19
|
+
".": "./out/index.js",
|
|
20
20
|
"./config": "./out/config.js",
|
|
21
21
|
"./internal/*": "./out/*"
|
|
22
22
|
},
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"out"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@arktype/util": "0.0.
|
|
28
|
-
"@arktype/schema": "0.1.
|
|
27
|
+
"@arktype/util": "0.0.50",
|
|
28
|
+
"@arktype/schema": "0.1.17"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsx ../repo/build.ts",
|
|
File without changes
|
/package/out/{api.js → index.js}
RENAMED
|
File without changes
|