arktype 2.0.0-dev.10 → 2.0.0-dev.12
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 +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +1 -1
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +3 -3
- package/out/match.js +1 -1
- package/out/module.d.ts +7 -6
- package/out/module.js +2 -3
- package/out/parser/definition.d.ts +11 -9
- package/out/parser/definition.js +2 -2
- package/out/parser/objectLiteral.d.ts +8 -13
- package/out/parser/objectLiteral.js +20 -23
- package/out/parser/semantic/bounds.d.ts +3 -3
- package/out/parser/semantic/divisor.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +1 -1
- package/out/parser/semantic/validate.d.ts +6 -4
- package/out/parser/string/reduce/dynamic.d.ts +6 -6
- package/out/parser/string/reduce/shared.d.ts +16 -16
- package/out/parser/string/reduce/shared.js +4 -2
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.d.ts +17 -3
- package/out/parser/string/shift/operand/enclosed.js +2 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/unenclosed.d.ts +9 -7
- package/out/parser/string/shift/operand/unenclosed.js +2 -2
- package/out/parser/string/shift/operator/bounds.d.ts +5 -5
- 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 +2 -2
- package/out/parser/tuple.d.ts +11 -11
- package/out/parser/tuple.js +3 -3
- package/out/scope.d.ts +15 -13
- package/out/scope.js +7 -7
- package/out/type.d.ts +4 -4
- package/out/type.js +3 -3
- package/package.json +8 -10
- package/__tests__/array.test.ts +0 -391
- package/__tests__/badDefinitionType.test.ts +0 -58
- package/__tests__/basis.test.ts +0 -50
- package/__tests__/bounds.test.ts +0 -318
- package/__tests__/cast.test.ts +0 -37
- package/__tests__/completions.test.ts +0 -51
- package/__tests__/config.test.ts +0 -96
- package/__tests__/dateLiteral.test.ts +0 -36
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -114
- package/__tests__/enclosed.test.ts +0 -107
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -210
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -313
- package/__tests__/group.test.ts +0 -85
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -126
- package/__tests__/instanceof.test.ts +0 -104
- package/__tests__/intersection.test.ts +0 -108
- package/__tests__/keyTraversal.test.ts +0 -77
- package/__tests__/keyof.test.ts +0 -150
- package/__tests__/keywords.test.ts +0 -214
- package/__tests__/literal.test.ts +0 -90
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -234
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/narrow.test.ts +0 -100
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -442
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/pipe.test.ts +0 -501
- package/__tests__/realWorld.test.ts +0 -63
- package/__tests__/regex.test.ts +0 -68
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -374
- package/__tests__/serialization.test.ts +0 -19
- package/__tests__/string.test.ts +0 -52
- package/__tests__/submodule.test.ts +0 -86
- package/__tests__/this.test.ts +0 -83
- package/__tests__/thunk.test.ts +0 -86
- package/__tests__/traverse.test.ts +0 -141
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/type.test.ts +0 -36
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -136
- package/__tests__/union.test.ts +0 -214
- package/ark.ts +0 -47
- package/generic.ts +0 -69
- package/main.ts +0 -6
- package/match.ts +0 -218
- package/module.ts +0 -15
- package/out/ark.js.map +0 -1
- package/out/generic.js.map +0 -1
- package/out/main.js.map +0 -1
- package/out/match.js.map +0 -1
- package/out/module.js.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/infer.js.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/type.js.map +0 -1
- package/parser/definition.ts +0 -143
- package/parser/generic.ts +0 -66
- package/parser/objectLiteral.ts +0 -233
- package/parser/semantic/bounds.ts +0 -62
- package/parser/semantic/divisor.ts +0 -11
- package/parser/semantic/infer.ts +0 -141
- package/parser/semantic/utils.ts +0 -15
- package/parser/semantic/validate.ts +0 -117
- package/parser/string/reduce/dynamic.ts +0 -208
- package/parser/string/reduce/shared.ts +0 -99
- package/parser/string/reduce/static.ts +0 -296
- package/parser/string/shift/operand/date.ts +0 -55
- package/parser/string/shift/operand/enclosed.ts +0 -123
- package/parser/string/shift/operand/genericArgs.ts +0 -128
- package/parser/string/shift/operand/operand.ts +0 -42
- package/parser/string/shift/operand/unenclosed.ts +0 -217
- package/parser/string/shift/operator/bounds.ts +0 -270
- package/parser/string/shift/operator/divisor.ts +0 -33
- package/parser/string/shift/operator/operator.ts +0 -71
- package/parser/string/shift/scanner.ts +0 -210
- package/parser/string/string.ts +0 -85
- package/parser/tuple.ts +0 -542
- package/scope.ts +0 -291
- package/type.ts +0 -266
package/out/api.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ArkError as ArkError, ArkErrors } 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/api.js
ADDED
package/out/ark.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type TsGenericsExports<$ = Ark> = {
|
|
|
12
12
|
"[K]": "V";
|
|
13
13
|
}, $>;
|
|
14
14
|
};
|
|
15
|
-
export declare const tsGenerics: Module<TsGenericsExports
|
|
15
|
+
export declare const tsGenerics: Module<TsGenericsExports<Ark>>;
|
|
16
16
|
export declare const ambient: Scope<Ark>;
|
|
17
17
|
export declare const ark: Module<Ark>;
|
|
18
18
|
export declare const type: TypeParser<{}>;
|
package/out/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@arktype/schema/config";
|
package/out/config.js
ADDED
package/out/generic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GenericNodeInstantiation, type GenericProps, type
|
|
1
|
+
import { type GenericNodeInstantiation, type GenericProps, type RootScope, arkKind } from "@arktype/schema";
|
|
2
2
|
import { Callable, type conform } from "@arktype/util";
|
|
3
3
|
import type { inferDefinition } from "./parser/definition.js";
|
|
4
4
|
import type { GenericParamsParseError, parseGenericParams } from "./parser/generic.js";
|
|
@@ -14,8 +14,8 @@ type bindGenericInstantiation<params extends string[], $, args> = {
|
|
|
14
14
|
export declare class Generic<params extends string[] = string[], def = unknown, $ = any> extends Callable<GenericInstantiation<params, def, $>> implements GenericProps<params, def, $> {
|
|
15
15
|
params: params;
|
|
16
16
|
def: def;
|
|
17
|
-
$:
|
|
17
|
+
$: RootScope<$>;
|
|
18
18
|
readonly [arkKind] = "generic";
|
|
19
|
-
constructor(params: params, def: def, $:
|
|
19
|
+
constructor(params: params, def: def, $: RootScope<$>);
|
|
20
20
|
}
|
|
21
21
|
export {};
|
package/out/match.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const createMatchParser = ($) => {
|
|
2
2
|
return (() => { }).bind($);
|
|
3
3
|
// const matchParser = (isRestricted: boolean) => {
|
|
4
|
-
// const handledCases: { when:
|
|
4
|
+
// const handledCases: { when: RawRoot; then: Morph }[] = []
|
|
5
5
|
// let defaultCase: ((x: unknown) => unknown) | null = null
|
|
6
6
|
// const parser = {
|
|
7
7
|
// when: (when: unknown, then: Morph) => {
|
package/out/module.d.ts
CHANGED
|
@@ -1,10 +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
|
-
[k in keyof $]: $[k] extends PreparsedNodeResolution ?
|
|
5
|
+
[k in keyof $]: $[k] extends PreparsedNodeResolution ? [
|
|
6
|
+
$[k]
|
|
7
|
+
] extends [anyOrNever] ? Type<$[k], $> : $[k] : Type<$[k], $>;
|
|
6
8
|
};
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
}
|
|
9
|
+
export declare const Module: new <$ = {}>(types: exportScope<$>) => Module<$>;
|
|
10
|
+
export type Module<$ = {}> = RootModule<exportScope<$>>;
|
|
10
11
|
export {};
|
package/out/module.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
}
|
|
1
|
+
import { RootModule } from "@arktype/schema";
|
|
2
|
+
export const Module = RootModule;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ErrorMessage, type Primitive, type
|
|
1
|
+
import { type BaseRoot, type string } from "@arktype/schema";
|
|
2
|
+
import { type ErrorMessage, type Primitive, type anyOrNever, type array, type defined, type equals, type isUnknown, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@arktype/util";
|
|
3
3
|
import type { type } from "../ark.js";
|
|
4
4
|
import type { ParseContext } from "../scope.js";
|
|
5
5
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.js";
|
|
6
6
|
import type { validateString } from "./semantic/validate.js";
|
|
7
7
|
import type { BaseCompletions, inferString } from "./string/string.js";
|
|
8
8
|
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.js";
|
|
9
|
-
export declare const parseObject: (def: object, ctx: ParseContext) =>
|
|
10
|
-
export type inferDefinition<def, $, args> =
|
|
11
|
-
|
|
9
|
+
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
10
|
+
export type inferDefinition<def, $, args> = [
|
|
11
|
+
def
|
|
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 ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : isUnknown<def> extends true ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
12
14
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
13
15
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
14
|
-
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> :
|
|
16
|
+
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
|
15
17
|
} : show<declarationMismatch<def, declared, $, args>> : def extends object ? show<{
|
|
16
|
-
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> :
|
|
18
|
+
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> : declared[k];
|
|
17
19
|
} & {
|
|
18
|
-
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> :
|
|
20
|
+
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> : declared[k];
|
|
19
21
|
}> : validateShallowInference<def, declared, $, args>;
|
|
20
22
|
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def : show<declarationMismatch<def, declared, $, args>>;
|
|
21
23
|
type declarationMismatch<def, declared, $, args> = {
|
|
@@ -25,6 +27,6 @@ type declarationMismatch<def, declared, $, args> = {
|
|
|
25
27
|
type Terminal = RegExp | type.cast<unknown> | ((...args: never[]) => unknown);
|
|
26
28
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
27
29
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
28
|
-
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) =>
|
|
30
|
+
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
29
31
|
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
|
|
30
32
|
export {};
|
package/out/parser/definition.js
CHANGED
|
@@ -6,7 +6,7 @@ export const parseObject = (def, ctx) => {
|
|
|
6
6
|
const objectKind = objectKindOf(def);
|
|
7
7
|
switch (objectKind) {
|
|
8
8
|
case undefined:
|
|
9
|
-
if (hasArkKind(def, "
|
|
9
|
+
if (hasArkKind(def, "root"))
|
|
10
10
|
return def;
|
|
11
11
|
return parseObjectLiteral(def, ctx);
|
|
12
12
|
case "Array":
|
|
@@ -18,7 +18,7 @@ export const parseObject = (def, ctx) => {
|
|
|
18
18
|
}, { prereduced: true });
|
|
19
19
|
case "Function": {
|
|
20
20
|
const resolvedDef = isThunk(def) ? def() : def;
|
|
21
|
-
if (hasArkKind(resolvedDef, "
|
|
21
|
+
if (hasArkKind(resolvedDef, "root"))
|
|
22
22
|
return resolvedDef;
|
|
23
23
|
return throwParseError(writeBadDefinitionTypeMessage("Function"));
|
|
24
24
|
}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Dict, type ErrorMessage, type Key, type merge, type show } from "@arktype/util";
|
|
1
|
+
import type { BaseRoot, writeInvalidPropertyKeyMessage } from "@arktype/schema";
|
|
2
|
+
import { type Dict, type ErrorMessage, type Key, type keyError, type merge, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
5
5
|
import type { astToString } from "./semantic/utils.js";
|
|
6
6
|
import type { validateString } from "./semantic/validate.js";
|
|
7
7
|
import { Scanner } from "./string/shift/scanner.js";
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) =>
|
|
8
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
9
9
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
10
|
+
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
10
11
|
/**
|
|
11
12
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
12
|
-
* You probably want to use {@link inferObjectLiteral} instead.
|
|
13
13
|
*/
|
|
14
|
-
type
|
|
14
|
+
type _inferObjectLiteral<def extends object, $, args> = {
|
|
15
15
|
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: inferDefinition<def[k], $, args>;
|
|
16
16
|
} & {
|
|
17
17
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
18
18
|
};
|
|
19
|
-
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, inferObjectLiteralInner<def, $, args>> : inferObjectLiteralInner<def, $, args>>;
|
|
20
19
|
export type validateObjectLiteral<def, $, args> = {
|
|
21
|
-
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ?
|
|
20
|
+
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? keyError<message> : inferDefinition<indexDef, $, args> extends 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]>>> : validateDefinition<def[k], $, args>;
|
|
22
21
|
};
|
|
23
22
|
type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> & Key : never;
|
|
24
23
|
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
@@ -35,7 +34,7 @@ type PreparsedEntry = PreparsedKey & {
|
|
|
35
34
|
value: unknown;
|
|
36
35
|
};
|
|
37
36
|
export declare const parseEntry: (entry: readonly [Key, unknown]) => PreparsedEntry;
|
|
38
|
-
declare const parseKey: (key: Key) => PreparsedKey
|
|
37
|
+
declare const parseKey: (key: Key) => PreparsedKey;
|
|
39
38
|
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${Scanner.EscapeToken}` ? PreparsedKey.from<{
|
|
40
39
|
kind: "required";
|
|
41
40
|
inner: `${baseName}?`;
|
|
@@ -55,10 +54,6 @@ type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName
|
|
|
55
54
|
kind: "required";
|
|
56
55
|
inner: k extends (`${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
57
56
|
}>;
|
|
58
|
-
declare const
|
|
59
|
-
export type indexParseError<message extends string = string> = {
|
|
60
|
-
[indexParseSymbol]: message;
|
|
61
|
-
};
|
|
62
|
-
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
57
|
+
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
63
58
|
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
64
59
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { printable, spliterate, stringAndSymbolicEntriesOf, throwParseError } from "@arktype/util";
|
|
1
|
+
import { append, printable, spliterate, stringAndSymbolicEntriesOf, throwParseError } from "@arktype/util";
|
|
3
2
|
import { Scanner } from "./string/shift/scanner.js";
|
|
4
3
|
export const parseObjectLiteral = (def, ctx) => {
|
|
5
|
-
|
|
6
|
-
const
|
|
4
|
+
let spread;
|
|
5
|
+
const structure = {};
|
|
7
6
|
// We only allow a spread operator to be used as the first key in an object
|
|
8
7
|
// because to match JS behavior any keys before the spread are overwritten
|
|
9
8
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
@@ -14,15 +13,12 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
14
13
|
// expecting non-spread entries
|
|
15
14
|
const spreadEntry = parsedEntries.shift();
|
|
16
15
|
const spreadNode = ctx.$.parse(spreadEntry.value, ctx);
|
|
17
|
-
if (!spreadNode.hasKind("intersection") ||
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (!spreadNode.hasKind("intersection") || !spreadNode.structure) {
|
|
17
|
+
return throwParseError(writeInvalidSpreadTypeMessage(typeof spreadEntry.value === "string" ?
|
|
18
|
+
spreadEntry.value
|
|
19
|
+
: printable(spreadEntry.value)));
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
// For each key on spreadNode, add it to our object.
|
|
23
|
-
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
24
|
-
// because the currently parsed definition will overwrite them.
|
|
25
|
-
spreadNode.prop?.forEach(spreadRequired => !parsedEntries.some(({ inner: innerKey }) => innerKey === spreadRequired.key) && propNodes.push(spreadRequired));
|
|
21
|
+
spread = spreadNode.structure;
|
|
26
22
|
}
|
|
27
23
|
for (const entry of parsedEntries) {
|
|
28
24
|
if (entry.kind === "spread")
|
|
@@ -32,28 +28,29 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
32
28
|
const key = ctx.$.parse(entry.inner, ctx);
|
|
33
29
|
const value = ctx.$.parse(entry.value, ctx);
|
|
34
30
|
// extract enumerable named props from the index signature
|
|
35
|
-
const [enumerable, nonEnumerable] = spliterate(key.branches, k => k.hasKind("unit"));
|
|
31
|
+
const [enumerable, nonEnumerable] = spliterate(key.branches, (k) => k.hasKind("unit"));
|
|
36
32
|
if (enumerable.length) {
|
|
37
|
-
|
|
38
|
-
if (nonEnumerable.length)
|
|
39
|
-
|
|
33
|
+
structure.required = append(structure.required, enumerable.map(k => ctx.$.node("required", { key: k.unit, value })));
|
|
34
|
+
if (nonEnumerable.length) {
|
|
35
|
+
structure.index = append(structure.index, ctx.$.node("index", { index: nonEnumerable, value }));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
structure.index = append(structure.index, ctx.$.node("index", { index: key, value }));
|
|
40
40
|
}
|
|
41
|
-
else
|
|
42
|
-
indexNodes.push(ctx.$.node("index", { key, value }));
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
43
|
const value = ctx.$.parse(entry.value, ctx);
|
|
46
|
-
|
|
44
|
+
structure[entry.kind] = append(structure[entry.kind], {
|
|
47
45
|
key: entry.inner,
|
|
48
|
-
value
|
|
49
|
-
optional: entry.kind === "optional"
|
|
46
|
+
value
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
49
|
}
|
|
50
|
+
const structureNode = ctx.$.node("structure", structure);
|
|
53
51
|
return ctx.$.schema({
|
|
54
52
|
domain: "object",
|
|
55
|
-
|
|
56
|
-
index: indexNodes
|
|
53
|
+
structure: spread?.merge(structureNode) ?? structureNode
|
|
57
54
|
});
|
|
58
55
|
};
|
|
59
56
|
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { LimitLiteral, writeUnboundableMessage } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage, array } from "@arktype/util";
|
|
3
|
-
import type { Comparator
|
|
3
|
+
import type { Comparator } from "../string/reduce/shared.js";
|
|
4
4
|
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.js";
|
|
5
5
|
import type { inferAstIn } from "./infer.js";
|
|
6
6
|
import type { astToString } from "./utils.js";
|
|
7
7
|
import type { validateAst } from "./validate.js";
|
|
8
|
-
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r,
|
|
8
|
+
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r, comparator, l, "left", $, args> : l extends [infer leftAst, Comparator, unknown] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
|
|
9
9
|
export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> = inferAstIn<boundedAst, $, args> extends infer bounded ? isNumericallyBoundable<bounded> extends true ? limit extends number ? validateAst<boundedAst, $, args> : ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>> : bounded extends Date ? validateAst<boundedAst, $, args> : ErrorMessage<writeUnboundableMessage<astToString<boundKind extends "left" ? boundedAst[0 & keyof boundedAst] : boundedAst>>> : never;
|
|
10
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) => `Expression ${root} must have at most one right bound`;
|
|
14
14
|
type writeDoubleRightBoundMessage<root extends string> = `Expression ${root} must have at most one right bound`;
|
|
15
15
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Root, writeIndivisibleMessage } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage } from "@arktype/util";
|
|
3
3
|
import type { inferAstIn } from "./infer.js";
|
|
4
4
|
import type { validateAst } from "./validate.js";
|
|
5
5
|
export type validateDivisor<l, $, args> = inferAstIn<l, $, args> extends infer data ? [
|
|
6
6
|
data
|
|
7
|
-
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<
|
|
7
|
+
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<Root<data>>> : never;
|
|
@@ -8,7 +8,7 @@ export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>;
|
|
|
8
8
|
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
|
|
9
9
|
export type inferConstrainableAst<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : ast extends string ? inferTerminal<ast, $, args> : never;
|
|
10
10
|
export type GenericInstantiationAst<generic extends GenericProps = GenericProps, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
11
|
-
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? inferDefinition<generic["def"], generic["$"]["
|
|
11
|
+
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? inferDefinition<generic["def"], generic["$"]["t"] extends UnparsedScope ? $ : generic["$"]["t"], {
|
|
12
12
|
[i in keyof generic["params"] & `${number}` as generic["params"][i]]: inferConstrainableAst<argAsts[i & keyof argAsts], $, args>;
|
|
13
13
|
}> : ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[] : ast[1] extends "|" ? inferConstrainableAst<ast[0], $, args> | inferConstrainableAst<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferConstrainableAst<ast[0], $, args>, inferConstrainableAst<ast[2], $, args>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]> : ast[1] extends "%" ? constrain<inferConstrainableAst<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args> : never;
|
|
14
14
|
export type constrainBound<constrainableIn, comparator extends Comparator, limit> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : constrain<constrainableIn, "exactLength", limit & number> : constrain<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { arkKind, GenericProps, PrivateDeclaration, writeMissingSubmoduleAccessMessage } from "@arktype/schema";
|
|
2
|
-
import type { BigintLiteral, charsAfterFirst, Completion, ErrorMessage,
|
|
2
|
+
import type { anyOrNever, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, writeMalformedNumericLiteralMessage } from "@arktype/util";
|
|
3
3
|
import type { Comparator } from "../string/reduce/shared.js";
|
|
4
4
|
import type { writeInvalidGenericArgsMessage } from "../string/shift/operand/genericArgs.js";
|
|
5
5
|
import type { parseString } from "../string/string.js";
|
|
@@ -12,11 +12,13 @@ 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) => `${expression} results in an unsatisfiable type`;
|
|
16
16
|
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
17
|
-
export declare const writePrefixedPrivateReferenceMessage: <def extends `#${string}`>(def: def) =>
|
|
17
|
+
export declare const writePrefixedPrivateReferenceMessage: <def extends `#${string}`>(def: def) => `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
18
18
|
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
19
|
-
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ?
|
|
19
|
+
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
|
|
20
|
+
$[alias]
|
|
21
|
+
] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends GenericProps ? ErrorMessage<writeInvalidGenericArgsMessage<def, $[alias]["params"], []>> : $[alias] extends {
|
|
20
22
|
[arkKind]: "module";
|
|
21
23
|
} ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
22
24
|
export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot, LimitLiteral } from "@arktype/schema";
|
|
2
2
|
import { type requireKeys } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../../../scope.js";
|
|
4
4
|
import type { InfixOperator } from "../../semantic/infer.js";
|
|
@@ -7,23 +7,23 @@ import { type Comparator, type MinComparator, type OpenLeftBound, type Stringifi
|
|
|
7
7
|
type BranchState = {
|
|
8
8
|
prefixes: StringifiablePrefixOperator[];
|
|
9
9
|
leftBound: OpenLeftBound | null;
|
|
10
|
-
intersection:
|
|
11
|
-
union:
|
|
10
|
+
intersection: BaseRoot | null;
|
|
11
|
+
union: BaseRoot | null;
|
|
12
12
|
};
|
|
13
13
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
14
14
|
export declare class DynamicState {
|
|
15
15
|
readonly ctx: ParseContext;
|
|
16
16
|
readonly scanner: Scanner;
|
|
17
|
-
root:
|
|
17
|
+
root: BaseRoot<any> | undefined;
|
|
18
18
|
branches: BranchState;
|
|
19
19
|
finalizer: Scanner.FinalizingLookahead | undefined;
|
|
20
20
|
groups: BranchState[];
|
|
21
21
|
constructor(def: string, ctx: ParseContext);
|
|
22
22
|
error(message: string): never;
|
|
23
23
|
hasRoot(): this is DynamicStateWithRoot;
|
|
24
|
-
setRoot(root:
|
|
24
|
+
setRoot(root: BaseRoot): void;
|
|
25
25
|
unsetRoot(): this["root"];
|
|
26
|
-
constrainRoot(...args: Parameters<
|
|
26
|
+
constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
|
|
27
27
|
finalize(finalizer: Scanner.FinalizingLookahead): void;
|
|
28
28
|
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
|
|
29
29
|
finalizeBranches(): void;
|
|
@@ -11,32 +11,32 @@ export declare const maxComparators: {
|
|
|
11
11
|
};
|
|
12
12
|
export type MaxComparator = keyof typeof maxComparators;
|
|
13
13
|
export declare const comparators: {
|
|
14
|
+
">": boolean;
|
|
15
|
+
">=": boolean;
|
|
16
|
+
"<": boolean;
|
|
17
|
+
"<=": boolean;
|
|
14
18
|
"==": boolean;
|
|
15
|
-
"<": true;
|
|
16
|
-
"<=": true;
|
|
17
|
-
">": true;
|
|
18
|
-
">=": true;
|
|
19
19
|
};
|
|
20
20
|
export type Comparator = keyof typeof comparators;
|
|
21
|
-
export declare const invertedComparators:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
export declare const invertedComparators: InvertedComparators;
|
|
22
|
+
export type InvertedComparators = {
|
|
23
|
+
"<": ">";
|
|
24
|
+
">": "<";
|
|
25
|
+
"<=": ">=";
|
|
26
|
+
">=": "<=";
|
|
27
|
+
"==": "==";
|
|
27
28
|
};
|
|
28
|
-
export type InvertedComparators = typeof invertedComparators;
|
|
29
29
|
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) => `Unmatched )${unscanned extends "" ? "" : ` before ${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) => `Missing ${missingChar}`;
|
|
36
36
|
export type writeUnclosedGroupMessage<missingChar extends string> = `Missing ${missingChar}`;
|
|
37
|
-
export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends ">" | ">=">(min: min, comparator: comparator) =>
|
|
37
|
+
export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends ">" | ">=">(min: min, comparator: comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
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 ">" | ">=", limit extends LimitLiteral, comparator extends ">" | ">=">(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) =>
|
|
40
|
+
export declare const writeUnpairableComparatorMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==">(comparator: comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
41
|
+
export declare const writeMultipleLeftBoundsMessage: <openLimit extends LimitLiteral, openComparator extends ">" | ">=", limit extends LimitLiteral, comparator extends ">" | ">=">(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[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]})`;
|
|
@@ -3,9 +3,9 @@ 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
5
|
type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
|
|
6
|
-
export declare const writeInvalidDateMessage: <source extends string>(source: source) =>
|
|
6
|
+
export declare const writeInvalidDateMessage: <source extends string>(source: source) => `'${source}' could not be parsed by the Date constructor`;
|
|
7
7
|
export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
|
|
8
8
|
export type DateInput = ConstructorParameters<typeof Date>[0];
|
|
9
9
|
export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
|
|
10
|
-
export declare const tryParseDate: <errorOnFail extends string | boolean>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
|
|
10
|
+
export declare const tryParseDate: <errorOnFail extends string | boolean>(source: string, errorOnFail?: errorOnFail | undefined) => DateParseResult<errorOnFail>;
|
|
11
11
|
export {};
|
|
@@ -12,9 +12,9 @@ export declare const enclosingQuote: {
|
|
|
12
12
|
};
|
|
13
13
|
export type EnclosingQuote = keyof typeof enclosingQuote;
|
|
14
14
|
export declare const enclosingChar: {
|
|
15
|
+
readonly "/": 1;
|
|
15
16
|
readonly "'": 1;
|
|
16
17
|
readonly '"': 1;
|
|
17
|
-
readonly "/": 1;
|
|
18
18
|
};
|
|
19
19
|
export declare const enclosingTokens: {
|
|
20
20
|
readonly "d'": "'";
|
|
@@ -27,8 +27,22 @@ export type EnclosingTokens = typeof enclosingTokens;
|
|
|
27
27
|
export type EnclosingStartToken = keyof EnclosingTokens;
|
|
28
28
|
export type EnclosingEndToken = EnclosingTokens[keyof EnclosingTokens];
|
|
29
29
|
export declare const untilLookaheadIsClosing: Record<EnclosingEndToken, Scanner.UntilCondition>;
|
|
30
|
-
declare const enclosingCharDescriptions:
|
|
30
|
+
declare const enclosingCharDescriptions: {
|
|
31
|
+
readonly '"': "double-quote";
|
|
32
|
+
readonly "'": "single-quote";
|
|
33
|
+
readonly "/": "forward slash";
|
|
34
|
+
};
|
|
31
35
|
type enclosingCharDescriptions = typeof enclosingCharDescriptions;
|
|
32
|
-
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends "'" | "\"" | "/" | "d'" | "d\"">(fragment: fragment, enclosingStart: enclosingStart) =>
|
|
36
|
+
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends "'" | "\"" | "/" | "d'" | "d\"">(fragment: fragment, enclosingStart: enclosingStart) => `${enclosingStart}${fragment} requires a closing ${{
|
|
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]]}`;
|
|
33
47
|
export type writeUnterminatedEnclosedMessage<fragment extends string, enclosingStart extends EnclosingStartToken> = `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[EnclosingTokens[enclosingStart]]}`;
|
|
34
48
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage, join } from "@arktype/util";
|
|
3
3
|
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
4
4
|
import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
|
|
@@ -8,9 +8,9 @@ export type ParsedArgs<result extends unknown[] = unknown[], unscanned extends s
|
|
|
8
8
|
result: result;
|
|
9
9
|
unscanned: unscanned;
|
|
10
10
|
};
|
|
11
|
-
export declare const parseGenericArgs: (name: string, params: string[], s: DynamicState) => ParsedArgs<
|
|
11
|
+
export declare const parseGenericArgs: (name: string, params: string[], s: DynamicState) => ParsedArgs<BaseRoot[]>;
|
|
12
12
|
export type parseGenericArgs<name extends string, params extends string[], unscanned extends string, $, args> = _parseGenericArgs<name, params, unscanned, $, args, [], []>;
|
|
13
|
-
declare const _parseGenericArgs: (name: string, params: string[], s: DynamicState, argDefs: string[], argNodes:
|
|
13
|
+
declare const _parseGenericArgs: (name: string, params: string[], s: DynamicState, argDefs: string[], argNodes: BaseRoot[]) => ParsedArgs<BaseRoot[]>;
|
|
14
14
|
type _parseGenericArgs<name extends string, params extends string[], unscanned extends string, $, args, argDefs extends string[], argAsts extends unknown[]> = parseUntilFinalizer<state.initialize<unscanned>, $, args> extends (infer finalArgState extends StaticState) ? {
|
|
15
15
|
defs: [
|
|
16
16
|
...argDefs,
|
|
@@ -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) => `${name}<${join<params, ", ", "">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends 0 ? "" : `: ${join<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,15 +1,17 @@
|
|
|
1
|
-
import { type GenericProps,
|
|
2
|
-
import { type BigintLiteral, type Completion, type ErrorMessage, type
|
|
1
|
+
import { BaseRoot, writeUnresolvableMessage, type GenericProps, type arkKind, type writeNonSubmoduleDotMessage } from "@arktype/schema";
|
|
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";
|
|
5
5
|
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
6
6
|
import type { StaticState, state } from "../../reduce/static.js";
|
|
7
7
|
import type { BaseCompletions } from "../../string.js";
|
|
8
8
|
import type { Scanner } from "../scanner.js";
|
|
9
|
-
import {
|
|
9
|
+
import { parseGenericArgs, writeInvalidGenericArgsMessage, type ParsedArgs } from "./genericArgs.js";
|
|
10
10
|
export declare const parseUnenclosed: (s: DynamicState) => void;
|
|
11
|
-
export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends keyof $ ?
|
|
12
|
-
|
|
11
|
+
export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends keyof $ ? [
|
|
12
|
+
$[result]
|
|
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
|
+
export declare const parseGenericInstantiation: (name: string, g: Generic, s: DynamicState) => BaseRoot;
|
|
13
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"], []>>;
|
|
14
16
|
type tryResolve<s extends StaticState, token extends string, $, args> = 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 $ & string}.${infer reference}`) ? $[submodule] extends {
|
|
15
17
|
[arkKind]: "module";
|
|
@@ -21,7 +23,7 @@ type qualifiedReference<reference extends string, submodulePath extends string[]
|
|
|
21
23
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath extends [] ? BaseCompletions<$, args> : keyof $, `${token}${string}`>;
|
|
22
24
|
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|
|
23
25
|
export type writeMissingRightOperandMessage<token extends string, unscanned extends string = ""> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
24
|
-
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) =>
|
|
25
|
-
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) =>
|
|
26
|
+
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) => `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
27
|
+
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
26
28
|
export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
27
29
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRoot, hasArkKind, writeUnresolvableMessage } from "@arktype/schema";
|
|
2
2
|
import { printable, throwParseError, tryParseNumber, tryParseWellFormedBigint } from "@arktype/util";
|
|
3
3
|
import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
|
|
4
4
|
import { parseGenericArgs, writeInvalidGenericArgsMessage } from "./genericArgs.js";
|
|
@@ -30,7 +30,7 @@ const maybeParseReference = (s, token) => {
|
|
|
30
30
|
if (s.ctx.args?.[token])
|
|
31
31
|
return s.ctx.args[token].raw;
|
|
32
32
|
const resolution = s.ctx.$.maybeResolve(token);
|
|
33
|
-
if (resolution instanceof
|
|
33
|
+
if (resolution instanceof BaseRoot)
|
|
34
34
|
return resolution;
|
|
35
35
|
if (resolution === undefined)
|
|
36
36
|
return;
|