arktype 2.0.0-dev.21 → 2.0.0-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/api.d.ts +1 -1
- package/out/parser/definition.js +1 -1
- package/out/parser/semantic/infer.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.js +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +4 -3
- package/out/parser/string/string.d.ts +3 -3
- package/out/scope.d.ts +6 -5
- package/out/type.d.ts +5 -5
- package/package.json +2 -2
package/out/api.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { ArkError, ArkErrors as ArkErrors } from "@arktype/schema";
|
|
|
2
2
|
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
3
|
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
4
|
export { Module } from "./module.js";
|
|
5
|
-
export { scope, type Scope } from "./scope.js";
|
|
5
|
+
export { scope, type Scope, type inferScope, type validateScope } from "./scope.js";
|
|
6
6
|
export { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
package/out/parser/definition.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Date, DateLiteral, GenericProps, LimitLiteral, RegexLiteral, constrain, distillIn, inferIntersection, normalizeLimit, string } from "@arktype/schema";
|
|
1
|
+
import type { Date, DateLiteral, GenericProps, LimitLiteral, RegexLiteral, ambient, 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 $ ? 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>;
|
|
24
|
+
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof ambient ? ambient[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>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseRoot, writeUnresolvableMessage, type GenericProps, type arkKind, type writeNonSubmoduleDotMessage } from "@arktype/schema";
|
|
1
|
+
import { BaseRoot, writeUnresolvableMessage, type GenericProps, type ambient, 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,9 +13,10 @@ 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 $ ? 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}`) ? $[
|
|
16
|
+
type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof ambient ? 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 ambient) & string}.${infer reference}`) ? tryResolveSubmodule<token, submodule, reference, s, $ & ambient, args> : unresolvableError<s, token, $, args, []>;
|
|
17
|
+
type tryResolveSubmodule<token, submodule extends keyof $ & string, reference extends string, s extends StaticState, $, args> = $[submodule] extends {
|
|
17
18
|
[arkKind]: "module";
|
|
18
|
-
} ? reference extends keyof $[submodule] ? token : unresolvableError<s, reference, $[submodule], args, [submodule]> : ErrorMessage<writeNonSubmoduleDotMessage<submodule
|
|
19
|
+
} ? reference extends keyof $[submodule] ? token : unresolvableError<s, reference, $[submodule], args, [submodule]> : ErrorMessage<writeNonSubmoduleDotMessage<submodule>>;
|
|
19
20
|
/** Provide valid completions for the current token, or fallback to an
|
|
20
21
|
* unresolvable error if there are none */
|
|
21
22
|
export type unresolvableError<s extends StaticState, token extends string, $, args, submodulePath extends string[]> = validReferenceFromToken<token, $, args, submodulePath> extends never ? ErrorMessage<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : Completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, $, args, submodulePath>, submodulePath>}`>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { BaseRoot, resolvableReferenceIn } from "@arktype/schema";
|
|
1
|
+
import type { ambient, 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 { state, StaticState } from "./reduce/static.js";
|
|
7
7
|
import type { parseOperand } from "./shift/operand/operand.js";
|
|
8
8
|
import { type parseOperator, writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
|
|
9
9
|
/**
|
|
@@ -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<$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
18
|
+
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ambient> | (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/scope.d.ts
CHANGED
|
@@ -6,12 +6,13 @@ import type { Module } from "./module.js";
|
|
|
6
6
|
import { type inferDefinition, type validateDefinition } from "./parser/definition.js";
|
|
7
7
|
import { parseGenericParams, type GenericDeclaration, type GenericParamsParseError } from "./parser/generic.js";
|
|
8
8
|
import { RawTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.js";
|
|
9
|
-
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<
|
|
10
|
-
type validateScope<def> = {
|
|
11
|
-
[k in keyof def]: k extends symbol ? unknown : parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? keyError<writeDuplicateAliasError<name>> : validateDefinition<def[k],
|
|
9
|
+
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<inferScope<def>>;
|
|
10
|
+
export type validateScope<def> = {
|
|
11
|
+
[k in keyof def]: k extends symbol ? unknown : parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? keyError<writeDuplicateAliasError<name>> : validateDefinition<def[k], bootstrapAliases<def>, {}> : parseScopeKey<k>["params"] extends GenericParamsParseError ? parseScopeKey<k>["params"][0] : validateDefinition<def[k], bootstrapAliases<def>, {
|
|
12
12
|
[param in parseScopeKey<k>["params"][number]]: unknown;
|
|
13
13
|
}>;
|
|
14
14
|
};
|
|
15
|
+
export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
15
16
|
export type bindThis<def> = {
|
|
16
17
|
this: Def<def>;
|
|
17
18
|
};
|
|
@@ -27,7 +28,7 @@ type bootstrapAliases<def> = {
|
|
|
27
28
|
[k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericProps<parseGenericParams<extractGenericParameters<k>>, def[k], UnparsedScope>;
|
|
28
29
|
};
|
|
29
30
|
type inferBootstrapped<$> = show<{
|
|
30
|
-
[name in keyof $]: $[name] extends Def<infer def> ? inferDefinition<def,
|
|
31
|
+
[name in keyof $]: $[name] extends Def<infer def> ? inferDefinition<def, $, {}> : $[name] extends GenericProps<infer params, infer def> ? Generic<params, def, $> : $[name];
|
|
31
32
|
}>;
|
|
32
33
|
type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
|
|
33
34
|
type extractGenericParameters<k> = k extends GenericDeclaration<string, infer params> ? params : never;
|
|
@@ -39,7 +40,7 @@ export type moduleKeyOf<$> = {
|
|
|
39
40
|
[arkKind]: "module";
|
|
40
41
|
} ? k & string : never;
|
|
41
42
|
}[keyof $];
|
|
42
|
-
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : never;
|
|
43
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] : never : token extends (`${infer submodule extends moduleKeyOf<ambient>}.${infer subalias}`) ? subalias extends keyof ambient[submodule] ? ambient[submodule][subalias] : never : never;
|
|
43
44
|
export interface ParseContext {
|
|
44
45
|
$: RawScope;
|
|
45
46
|
args?: Record<string, UnknownRoot>;
|
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
|
|
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";
|
|
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";
|
|
@@ -19,7 +19,7 @@ export declare class RawTypeParser extends Callable<(...args: unknown[]) => Base
|
|
|
19
19
|
constructor($: RawScope);
|
|
20
20
|
}
|
|
21
21
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
22
|
-
type: <def>(def: validateDeclared<preinferred, def,
|
|
22
|
+
type: <def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
|
|
23
23
|
};
|
|
24
24
|
type validateChainedConstraint<kind extends ConstraintKind, t extends {
|
|
25
25
|
inferIn: unknown;
|
|
@@ -49,7 +49,7 @@ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> {
|
|
|
49
49
|
constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
|
|
50
50
|
satisfying<predicate extends Predicate<distillIn<t>>>(predicate: predicate): Type<t extends MorphAst ? (In: inferPredicate<this["tIn"], predicate>) => Out<this["tOut"]> : inferPredicate<t, predicate>, $>;
|
|
51
51
|
divisibleBy<const schema extends DivisorSchema>(this: validateChainedConstraint<"divisor", this>, schema: schema): Type<constrain<t, "divisor", schema>, $>;
|
|
52
|
-
matching<const schema extends
|
|
52
|
+
matching<const schema extends PatternSchema>(this: validateChainedConstraint<"pattern", this>, schema: schema): Type<constrain<t, "pattern", schema>, $>;
|
|
53
53
|
atLeast<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"min", this>, schema: schema): Type<constrain<t, "min", schema>, $>;
|
|
54
54
|
atMost<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"max", this>, schema: schema): Type<constrain<t, "max", schema>, $>;
|
|
55
55
|
moreThan<const schema extends ExclusiveNumericRangeSchema>(this: validateChainedConstraint<"min", this>, schema: schema): Type<constrain<t, "min", exclusivizeRangeSchema<schema>>, $>;
|
|
@@ -71,6 +71,6 @@ out t = unknown, $ = {}> extends _Type<t, $> {
|
|
|
71
71
|
export type TypeConstructor<t = unknown, $ = {}> = new (def: unknown, $: Scope<$>) => Type<t, $>;
|
|
72
72
|
export declare const Type: TypeConstructor;
|
|
73
73
|
export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
|
|
74
|
-
export type validateTypeRoot<def, $ = {}> = validateDefinition<def,
|
|
75
|
-
export type inferTypeRoot<def, $ = {}> = inferDefinition<def,
|
|
74
|
+
export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $, bindThis<def>>;
|
|
75
|
+
export type inferTypeRoot<def, $ = {}> = inferDefinition<def, $, bindThis<def>>;
|
|
76
76
|
export {};
|
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.22",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@arktype/util": "0.0.48",
|
|
28
|
-
"@arktype/schema": "0.1.
|
|
28
|
+
"@arktype/schema": "0.1.14"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsx ../repo/build.ts",
|