arktype 2.0.0-beta.5 → 2.0.0-beta.6
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/ast.d.ts +7 -10
- package/out/ast.js +0 -1
- package/out/config.d.ts +17 -2
- package/out/generic.d.ts +9 -16
- package/out/generic.js +1 -2
- package/out/index.d.ts +6 -7
- package/out/index.js +1 -1
- package/out/intersect.d.ts +1 -1
- package/out/keys.d.ts +2 -2
- package/out/keywords/ark.d.ts +40 -0
- package/out/keywords/ark.js +28 -0
- package/out/keywords/builtin.d.ts +26 -0
- package/out/keywords/builtin.js +21 -0
- package/out/keywords/format.d.ts +13 -10
- package/out/keywords/format.js +4 -1
- package/out/keywords/js.d.ts +18 -0
- package/out/keywords/{jsObjects.js → js.js} +4 -1
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/number.js +44 -0
- package/out/keywords/parse.d.ts +19 -0
- package/out/keywords/{parsing.js → parse.js} +9 -4
- package/out/keywords/platform.d.ts +16 -0
- package/out/keywords/{platformObjects.js → platform.js} +4 -1
- package/out/keywords/string.d.ts +31 -0
- package/out/keywords/string.js +89 -0
- package/out/keywords/ts.d.ts +58 -0
- package/out/keywords/ts.js +55 -0
- package/out/keywords/typedArray.d.ts +18 -15
- package/out/keywords/typedArray.js +4 -1
- package/out/keywords/utils/date.d.ts +1 -0
- package/out/keywords/utils/date.js +1 -1
- package/out/keywords/utils/ip.d.ts +16 -3
- package/out/keywords/utils/ip.js +10 -4
- package/out/keywords/utils/regex.d.ts +3 -2
- package/out/keywords/utils/uuid.d.ts +30 -0
- package/out/keywords/utils/uuid.js +22 -0
- package/out/module.d.ts +2 -2
- package/out/parser/definition.d.ts +9 -9
- package/out/parser/objectLiteral.d.ts +8 -6
- package/out/parser/semantic/bounds.d.ts +6 -6
- package/out/parser/semantic/default.d.ts +4 -4
- package/out/parser/semantic/divisor.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +8 -8
- package/out/parser/semantic/keyof.d.ts +2 -2
- package/out/parser/semantic/utils.d.ts +2 -2
- package/out/parser/semantic/validate.d.ts +12 -12
- package/out/parser/string/reduce/dynamic.d.ts +8 -8
- package/out/parser/string/reduce/dynamic.js +3 -3
- package/out/parser/string/reduce/shared.d.ts +1 -1
- package/out/parser/string/reduce/static.d.ts +19 -20
- package/out/parser/string/shift/operand/date.d.ts +1 -3
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -3
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/operand.d.ts +6 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts +12 -10
- package/out/parser/string/shift/operand/unenclosed.js +2 -2
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +0 -4
- package/out/parser/string/shift/operator/default.d.ts +4 -10
- package/out/parser/string/shift/operator/default.js +0 -6
- package/out/parser/string/shift/operator/divisor.d.ts +3 -3
- package/out/parser/string/shift/operator/operator.d.ts +5 -5
- package/out/parser/string/shift/scanner.d.ts +16 -16
- package/out/parser/string/shift/scanner.js +6 -8
- package/out/parser/string/string.d.ts +9 -9
- package/out/parser/tuple.d.ts +7 -7
- package/out/parser/tuple.js +2 -1
- package/out/scope.d.ts +24 -19
- package/out/scope.js +65 -111
- package/out/subtypes/array.d.ts +2 -2
- package/out/subtypes/base.d.ts +9 -8
- package/out/subtypes/date.d.ts +2 -2
- package/out/subtypes/instantiate.d.ts +8 -8
- package/out/subtypes/morph.d.ts +4 -4
- package/out/subtypes/number.d.ts +2 -2
- package/out/subtypes/object.d.ts +6 -6
- package/out/subtypes/string.d.ts +2 -2
- package/out/subtypes/validator.d.ts +3 -3
- package/out/type.d.ts +7 -7
- package/package.json +17 -8
- package/out/ark.d.ts +0 -33
- package/out/ark.js +0 -28
- package/out/keywords/arkGenerics.d.ts +0 -19
- package/out/keywords/arkGenerics.js +0 -19
- package/out/keywords/internal.d.ts +0 -11
- package/out/keywords/internal.js +0 -25
- package/out/keywords/jsObjects.d.ts +0 -15
- package/out/keywords/parsing.d.ts +0 -16
- package/out/keywords/platformObjects.d.ts +0 -13
- package/out/keywords/tsGenerics.d.ts +0 -37
- package/out/keywords/tsGenerics.js +0 -45
- package/out/keywords/tsKeywords.d.ts +0 -18
- package/out/keywords/tsKeywords.js +0 -17
- package/out/keywords/validation.d.ts +0 -19
- package/out/keywords/validation.js +0 -84
package/out/scope.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseRoot, type GenericArgResolutions, type GenericAst, type GenericParamAst, type InternalResolutions, type NodeKind, type NodeParseOptions, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
|
|
2
|
-
import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type nominal, type show } from "@ark/util";
|
|
3
|
-
import type {
|
|
4
|
-
import { parseGenericParams, type GenericDeclaration, type GenericHktParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams } from "./generic.
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import type
|
|
8
|
-
import
|
|
2
|
+
import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type inferred, type noSuggest, type nominal, type show } from "@ark/util";
|
|
3
|
+
import type { ArkAmbient } from "./config.ts";
|
|
4
|
+
import { parseGenericParams, type GenericDeclaration, type GenericHktParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams } from "./generic.ts";
|
|
5
|
+
import type { type } from "./keywords/ark.ts";
|
|
6
|
+
import type { BoundModule, Module, Submodule, instantiateExport } from "./module.ts";
|
|
7
|
+
import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
|
|
8
|
+
import type { ParsedDefault } from "./parser/string/shift/operator/default.ts";
|
|
9
|
+
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.ts";
|
|
9
10
|
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkScopeConfig) => Scope<inferScope<def>>;
|
|
10
11
|
export type validateScope<def> = {
|
|
11
|
-
[k in keyof def]: parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends Type.Any | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? ErrorType<writeDuplicateAliasError<name>> : validateDefinition<def[k], bootstrapAliases<def>, {}> : validateDefinition<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
|
|
12
|
+
[k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends Type.Any | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? ErrorType<writeDuplicateAliasError<name>> : validateDefinition<def[k], bootstrapAliases<def>, {}> : validateDefinition<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
|
|
12
13
|
};
|
|
13
14
|
export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
14
15
|
export type bindThis<def> = {
|
|
@@ -23,22 +24,25 @@ type PreparsedResolution = PreparsedNodeResolution;
|
|
|
23
24
|
type bootstrapAliases<def> = {
|
|
24
25
|
[k in Exclude<keyof def, GenericDeclaration>]: def[k] extends (PreparsedResolution) ? def[k] extends {
|
|
25
26
|
t: infer g extends GenericAst;
|
|
26
|
-
} ? g : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
|
|
27
|
+
} ? g : def[k] extends Module<infer $> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
|
|
27
28
|
t: infer g extends GenericAst;
|
|
28
|
-
} ? g : thunkReturn : Def<def[k]>;
|
|
29
|
+
} ? g : thunkReturn extends Module<infer $> ? Submodule<$> : thunkReturn : Def<def[k]>;
|
|
29
30
|
} & {
|
|
30
31
|
[k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericAst<parseValidGenericParams<extractGenericParameters<k>, bootstrapAliases<def>>, def[k], UnparsedScope>;
|
|
31
32
|
};
|
|
32
33
|
type inferBootstrapped<$> = {
|
|
33
34
|
[name in keyof $]: $[name] extends Def<infer def> ? inferDefinition<def, $, {}> : $[name] extends {
|
|
34
|
-
t:
|
|
35
|
-
} ?
|
|
35
|
+
t: infer g extends GenericAst;
|
|
36
|
+
} ? bindGenericToScope<g, $> : $[name];
|
|
36
37
|
} & unknown;
|
|
38
|
+
export type bindGenericToScope<g extends GenericAst, $> = GenericAst<g["paramsAst"], g["bodyDef"], g["$"] extends UnparsedScope ? $ : g["$"], $>;
|
|
37
39
|
type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
|
|
38
40
|
type extractGenericParameters<k> = k extends `${string}<${infer params}>` ? ParameterString<params> : never;
|
|
39
41
|
export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? [
|
|
40
42
|
resolution
|
|
41
|
-
] extends [anyOrNever] ? resolution : resolution extends
|
|
43
|
+
] extends [anyOrNever] ? resolution : resolution extends {
|
|
44
|
+
[inferred]: infer t;
|
|
45
|
+
} ? t : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution : never;
|
|
42
46
|
export type moduleKeyOf<$> = {
|
|
43
47
|
[k in keyof $]: $[k] extends {
|
|
44
48
|
[arkKind]: "module";
|
|
@@ -46,7 +50,8 @@ export type moduleKeyOf<$> = {
|
|
|
46
50
|
$[k]
|
|
47
51
|
] extends [anyOrNever] ? never : k & string : never;
|
|
48
52
|
}[keyof $];
|
|
49
|
-
|
|
53
|
+
type unwrapPreinferred<t> = t extends type.cast<infer inferred> ? inferred : t;
|
|
54
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? unwrapPreinferred<$[submodule][subalias]> : tryInferSubmoduleReference<$[submodule], subalias> : token extends (`${infer submodule extends moduleKeyOf<ArkAmbient.$>}.${infer subalias}`) ? subalias extends keyof ArkAmbient.$[submodule] ? unwrapPreinferred<ArkAmbient.$[submodule][subalias]> : tryInferSubmoduleReference<ArkAmbient.$[submodule], subalias> : never;
|
|
50
55
|
export interface ParseContext extends TypeParseOptions {
|
|
51
56
|
$: InternalScope;
|
|
52
57
|
}
|
|
@@ -56,16 +61,16 @@ export interface TypeParseOptions {
|
|
|
56
61
|
export declare const scope: ScopeParser;
|
|
57
62
|
export declare class InternalScope<$ extends InternalResolutions = InternalResolutions> extends BaseScope<$> {
|
|
58
63
|
private parseCache;
|
|
64
|
+
preparseAlias(k: string, v: unknown): AliasDefEntry;
|
|
65
|
+
preparseRoot(def: unknown): unknown;
|
|
66
|
+
parse<defaultable extends boolean = false>(def: unknown, ctx: ParseContext, defaultable?: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
|
|
67
|
+
parseString<defaultable extends boolean>(def: string, ctx: ParseContext, defaultable: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
|
|
68
|
+
parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;
|
|
59
69
|
type: InternalTypeParser;
|
|
60
70
|
declare: () => {
|
|
61
71
|
type: InternalTypeParser;
|
|
62
72
|
};
|
|
63
73
|
define: (def: unknown) => unknown;
|
|
64
|
-
preparseAlias(k: string, v: unknown): AliasDefEntry;
|
|
65
|
-
preparseRoot(def: unknown): unknown;
|
|
66
|
-
parseRoot(def: unknown, opts?: TypeParseOptions): BaseRoot;
|
|
67
|
-
parse<defaultable extends boolean = false>(def: unknown, ctx: ParseContext, defaultable?: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
|
|
68
|
-
parseString<defaultable extends boolean>(def: string, ctx: ParseContext, defaultable: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
|
|
69
74
|
}
|
|
70
75
|
export interface Scope<$ = {}> {
|
|
71
76
|
t: $;
|
package/out/scope.js
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
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
|
-
};
|
|
35
1
|
import { BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
|
|
36
|
-
import {
|
|
2
|
+
import { domainOf, hasDomain, isThunk, throwParseError } from "@ark/util";
|
|
37
3
|
import { parseGenericParams } from "./generic.js";
|
|
38
4
|
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
39
5
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
@@ -42,86 +8,74 @@ import { Scanner } from "./parser/string/shift/scanner.js";
|
|
|
42
8
|
import { fullStringParse } from "./parser/string/string.js";
|
|
43
9
|
import { InternalTypeParser } from "./type.js";
|
|
44
10
|
export const scope = ((def, config = {}) => new InternalScope(def, config));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 });
|
|
11
|
+
export class InternalScope extends BaseScope {
|
|
12
|
+
parseCache = {};
|
|
13
|
+
preparseAlias(k, v) {
|
|
14
|
+
const firstParamIndex = k.indexOf("<");
|
|
15
|
+
if (firstParamIndex === -1)
|
|
16
|
+
return [k, v];
|
|
17
|
+
if (k.at(-1) !== ">") {
|
|
18
|
+
throwParseError(`'>' must be the last character of a generic declaration in a scope`);
|
|
55
19
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
20
|
+
const name = k.slice(0, firstParamIndex);
|
|
21
|
+
const paramString = k.slice(firstParamIndex + 1, -1);
|
|
22
|
+
return [
|
|
23
|
+
name,
|
|
24
|
+
// use a thunk definition for the generic so that we can parse
|
|
25
|
+
// constraints within the current scope
|
|
26
|
+
() => {
|
|
27
|
+
const params = parseGenericParams(paramString, {
|
|
28
|
+
$: this,
|
|
29
|
+
args: {}
|
|
30
|
+
});
|
|
31
|
+
const generic = parseGeneric(params, v, this);
|
|
32
|
+
return generic;
|
|
68
33
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
preparseRoot(def) {
|
|
86
|
-
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
87
|
-
return def();
|
|
88
|
-
return def;
|
|
89
|
-
}
|
|
90
|
-
parseRoot(def, opts = {}) {
|
|
91
|
-
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this })).bindScope(this);
|
|
92
|
-
return node;
|
|
93
|
-
}
|
|
94
|
-
parse(def, ctx, defaultable = false) {
|
|
95
|
-
if (typeof def === "string") {
|
|
96
|
-
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
97
|
-
// we can only rely on the cache if there are no contextual
|
|
98
|
-
// resolutions like "this" or generic args
|
|
99
|
-
return this.parseString(def, ctx, defaultable);
|
|
100
|
-
}
|
|
101
|
-
const contextKey = `${def}${defaultable}`;
|
|
102
|
-
return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
preparseRoot(def) {
|
|
37
|
+
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
38
|
+
return def();
|
|
39
|
+
return def;
|
|
40
|
+
}
|
|
41
|
+
parse(def, ctx, defaultable = false) {
|
|
42
|
+
if (typeof def === "string") {
|
|
43
|
+
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
44
|
+
// we can only rely on the cache if there are no contextual
|
|
45
|
+
// resolutions like "this" or generic args
|
|
46
|
+
return this.parseString(def, ctx, defaultable);
|
|
103
47
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
107
|
-
}
|
|
108
|
-
parseString(def, ctx, defaultable) {
|
|
109
|
-
const aliasResolution = this.maybeResolveRoot(def);
|
|
110
|
-
if (aliasResolution)
|
|
111
|
-
return aliasResolution;
|
|
112
|
-
const aliasArrayResolution = def.endsWith("[]") ?
|
|
113
|
-
this.maybeResolveRoot(def.slice(0, -2))?.array()
|
|
114
|
-
: undefined;
|
|
115
|
-
if (aliasArrayResolution)
|
|
116
|
-
return aliasArrayResolution;
|
|
117
|
-
const s = new DynamicState(new Scanner(def), ctx, defaultable);
|
|
118
|
-
const node = fullStringParse(s);
|
|
119
|
-
if (s.finalizer === ">")
|
|
120
|
-
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
121
|
-
return node;
|
|
48
|
+
const contextKey = `${def}${defaultable}`;
|
|
49
|
+
return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
|
|
122
50
|
}
|
|
51
|
+
return hasDomain(def, "object") ?
|
|
52
|
+
parseObject(def, ctx)
|
|
53
|
+
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
54
|
+
}
|
|
55
|
+
parseString(def, ctx, defaultable) {
|
|
56
|
+
const aliasResolution = this.maybeResolveRoot(def);
|
|
57
|
+
if (aliasResolution)
|
|
58
|
+
return aliasResolution;
|
|
59
|
+
const aliasArrayResolution = def.endsWith("[]") ?
|
|
60
|
+
this.maybeResolveRoot(def.slice(0, -2))?.array()
|
|
61
|
+
: undefined;
|
|
62
|
+
if (aliasArrayResolution)
|
|
63
|
+
return aliasArrayResolution;
|
|
64
|
+
const s = new DynamicState(new Scanner(def), ctx, defaultable);
|
|
65
|
+
const node = fullStringParse(s);
|
|
66
|
+
if (s.finalizer === ">")
|
|
67
|
+
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
parseRoot = (def, opts = {}) => {
|
|
71
|
+
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this })).bindScope(this);
|
|
72
|
+
return node;
|
|
123
73
|
};
|
|
124
|
-
|
|
125
|
-
|
|
74
|
+
type = new InternalTypeParser(this);
|
|
75
|
+
declare = () => ({
|
|
76
|
+
type: this.type
|
|
77
|
+
});
|
|
78
|
+
define = ((def) => def).bind(this);
|
|
79
|
+
}
|
|
126
80
|
export const Scope = InternalScope;
|
|
127
81
|
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
|
package/out/subtypes/array.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../ast.
|
|
3
|
-
import type { ObjectType } from "./object.
|
|
2
|
+
import type { applyConstraint } from "../ast.ts";
|
|
3
|
+
import type { ObjectType } from "./object.ts";
|
|
4
4
|
interface Type<
|
|
5
5
|
/** @ts-ignore cast variance */
|
|
6
6
|
out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> {
|
package/out/subtypes/base.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { ArkErrors, BaseRoot, Disjoint, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
-
import type { anyOrNever, Callable, ErrorMessage, Json, unset } from "@ark/util";
|
|
3
|
-
import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes
|
|
4
|
-
import type { inferIntersection } from "../intersect.
|
|
5
|
-
import type { Scope } from "../scope.
|
|
6
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.
|
|
7
|
-
import type { ArrayType } from "./array.
|
|
8
|
-
import type { instantiateType } from "./instantiate.
|
|
1
|
+
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
+
import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes } from "../ast.ts";
|
|
4
|
+
import type { inferIntersection } from "../intersect.ts";
|
|
5
|
+
import type { Scope } from "../scope.ts";
|
|
6
|
+
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
|
+
import type { ArrayType } from "./array.ts";
|
|
8
|
+
import type { instantiateType } from "./instantiate.ts";
|
|
9
9
|
/** @ts-ignore cast variance */
|
|
10
10
|
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> {
|
|
11
11
|
t: t;
|
|
@@ -16,6 +16,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
16
16
|
inferIn: distillIn<t>;
|
|
17
17
|
[inferred]: t;
|
|
18
18
|
json: Json;
|
|
19
|
+
toJsonSchema(): JsonSchema;
|
|
19
20
|
description: string;
|
|
20
21
|
expression: string;
|
|
21
22
|
internal: BaseRoot;
|
package/out/subtypes/date.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../ast.
|
|
3
|
-
import type { ObjectType } from "./object.
|
|
2
|
+
import type { applyConstraint } from "../ast.ts";
|
|
3
|
+
import type { ObjectType } from "./object.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
|
|
6
6
|
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "after", schema>, $>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { anyOrNever, array } from "@ark/util";
|
|
2
|
-
import type { MorphAst } from "../ast.
|
|
3
|
-
import type { ArrayType } from "./array.
|
|
4
|
-
import type { DateType } from "./date.
|
|
5
|
-
import type { MorphType } from "./morph.
|
|
6
|
-
import type { NumberType } from "./number.
|
|
7
|
-
import type { ObjectType } from "./object.
|
|
8
|
-
import type { StringType } from "./string.
|
|
9
|
-
import type { ValidatorType } from "./validator.
|
|
2
|
+
import type { MorphAst } from "../ast.ts";
|
|
3
|
+
import type { ArrayType } from "./array.ts";
|
|
4
|
+
import type { DateType } from "./date.ts";
|
|
5
|
+
import type { MorphType } from "./morph.ts";
|
|
6
|
+
import type { NumberType } from "./number.ts";
|
|
7
|
+
import type { ObjectType } from "./object.ts";
|
|
8
|
+
import type { StringType } from "./string.ts";
|
|
9
|
+
import type { ValidatorType } from "./validator.ts";
|
|
10
10
|
export type instantiateType<t, $> = [
|
|
11
11
|
Extract<t, MorphAst>
|
|
12
12
|
] extends [anyOrNever] ? [
|
package/out/subtypes/morph.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint, Out, To } from "../ast.
|
|
3
|
-
import type { inferPipe } from "../intersect.
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.
|
|
5
|
-
import type { BaseType } from "./base.
|
|
2
|
+
import type { applyConstraint, Out, To } from "../ast.ts";
|
|
3
|
+
import type { inferPipe } from "../intersect.ts";
|
|
4
|
+
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
|
+
import type { BaseType } from "./base.ts";
|
|
6
6
|
/** @ts-ignore cast variance */
|
|
7
7
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
8
8
|
to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
|
package/out/subtypes/number.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../ast.
|
|
3
|
-
import type { ValidatorType } from "./validator.
|
|
2
|
+
import type { applyConstraint } from "../ast.ts";
|
|
3
|
+
import type { ValidatorType } from "./validator.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
|
|
6
6
|
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraint<t, "divisor", schema>, $>;
|
package/out/subtypes/object.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { array, ErrorType, merge } from "@ark/util";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.
|
|
5
|
-
import type { ArrayType } from "./array.
|
|
6
|
-
import type { instantiateType } from "./instantiate.
|
|
7
|
-
import type { ValidatorType } from "./validator.
|
|
2
|
+
import type { arkKeyOf, getArkKey, toArkKey } from "../keys.ts";
|
|
3
|
+
import type { type } from "../keywords/ark.ts";
|
|
4
|
+
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
|
+
import type { ArrayType } from "./array.ts";
|
|
6
|
+
import type { instantiateType } from "./instantiate.ts";
|
|
7
|
+
import type { ValidatorType } from "./validator.ts";
|
|
8
8
|
/** @ts-ignore cast variance */
|
|
9
9
|
interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $> {
|
|
10
10
|
readonly(): t extends array ? ArrayType<{
|
package/out/subtypes/string.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../ast.
|
|
3
|
-
import type { ValidatorType } from "./validator.
|
|
2
|
+
import type { applyConstraint } from "../ast.ts";
|
|
3
|
+
import type { ValidatorType } from "./validator.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
|
|
6
6
|
matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraint<t, "pattern", schema>, $>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../ast.
|
|
3
|
-
import type { BaseType } from "./base.
|
|
4
|
-
import type { instantiateType } from "./instantiate.
|
|
2
|
+
import type { applyConstraint } from "../ast.ts";
|
|
3
|
+
import type { BaseType } from "./base.ts";
|
|
4
|
+
import type { instantiateType } from "./instantiate.ts";
|
|
5
5
|
/** @ts-ignore cast variance */
|
|
6
6
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
7
7
|
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<[
|
package/out/type.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
|
|
2
2
|
import { Callable, type Constructor, type array, type conform } from "@ark/util";
|
|
3
|
-
import type { distillIn, distillOut } from "./ast.
|
|
4
|
-
import { type Generic, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.
|
|
5
|
-
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.
|
|
6
|
-
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.
|
|
7
|
-
import type { InternalScope, Scope, bindThis } from "./scope.
|
|
8
|
-
import type { BaseType } from "./subtypes/base.
|
|
9
|
-
import type { instantiateType } from "./subtypes/instantiate.
|
|
3
|
+
import type { distillIn, distillOut } from "./ast.ts";
|
|
4
|
+
import { type Generic, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.ts";
|
|
5
|
+
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.ts";
|
|
6
|
+
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";
|
|
7
|
+
import type { InternalScope, Scope, bindThis } from "./scope.ts";
|
|
8
|
+
import type { BaseType } from "./subtypes/base.ts";
|
|
9
|
+
import type { instantiateType } from "./subtypes/instantiate.ts";
|
|
10
10
|
/** The convenience properties attached to `type` */
|
|
11
11
|
export type TypeParserAttachments = Omit<TypeParser, never>;
|
|
12
12
|
export interface TypeParser<$ = {}> {
|
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-beta.
|
|
4
|
+
"version": "2.0.0-beta.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -17,22 +17,31 @@
|
|
|
17
17
|
"main": "./out/index.js",
|
|
18
18
|
"types": "./out/index.d.ts",
|
|
19
19
|
"exports": {
|
|
20
|
-
".":
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
".": {
|
|
21
|
+
"ark-ts": "./index.ts",
|
|
22
|
+
"default": "./out/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./config": {
|
|
25
|
+
"ark-ts": "./config.ts",
|
|
26
|
+
"default": "./out/config.js"
|
|
27
|
+
},
|
|
28
|
+
"./internal/*.ts": {
|
|
29
|
+
"ark-ts": "./*.ts",
|
|
30
|
+
"default": "./out/*.js"
|
|
31
|
+
}
|
|
23
32
|
},
|
|
24
33
|
"files": [
|
|
25
34
|
"out"
|
|
26
35
|
],
|
|
27
36
|
"dependencies": {
|
|
28
|
-
"@ark/util": "0.2.
|
|
29
|
-
"@ark/schema": "0.3.
|
|
37
|
+
"@ark/util": "0.2.2",
|
|
38
|
+
"@ark/schema": "0.3.3"
|
|
30
39
|
},
|
|
31
40
|
"publishConfig": {
|
|
32
41
|
"access": "public"
|
|
33
42
|
},
|
|
34
43
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
-
"test": "
|
|
44
|
+
"build": "ts ../repo/build.ts",
|
|
45
|
+
"test": "ts ../repo/testPackage.ts"
|
|
37
46
|
}
|
|
38
47
|
}
|
package/out/ark.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ArkErrors } from "@ark/schema";
|
|
2
|
-
import type { inferred } from "./ast.js";
|
|
3
|
-
import type { GenericHktParser } from "./generic.js";
|
|
4
|
-
import { type arkGenericsExports } from "./keywords/arkGenerics.js";
|
|
5
|
-
import { type formattingExports } from "./keywords/format.js";
|
|
6
|
-
import { type internalExports } from "./keywords/internal.js";
|
|
7
|
-
import { type jsObjectExports } from "./keywords/jsObjects.js";
|
|
8
|
-
import { type parsingExports } from "./keywords/parsing.js";
|
|
9
|
-
import { type platformObjectExports } from "./keywords/platformObjects.js";
|
|
10
|
-
import { type tsGenericsExports } from "./keywords/tsGenerics.js";
|
|
11
|
-
import { type tsKeywordExports } from "./keywords/tsKeywords.js";
|
|
12
|
-
import { type typedArrayExports } from "./keywords/typedArray.js";
|
|
13
|
-
import { type validationExports } from "./keywords/validation.js";
|
|
14
|
-
import type { Module, Submodule } from "./module.js";
|
|
15
|
-
import { type Scope } from "./scope.js";
|
|
16
|
-
import type { DeclarationParser, DefinitionParser, TypeParser } from "./type.js";
|
|
17
|
-
export interface Ark extends tsKeywordExports, jsObjectExports, platformObjectExports, validationExports, tsGenericsExports, arkGenericsExports, internalExports {
|
|
18
|
-
TypedArray: Submodule<typedArrayExports>;
|
|
19
|
-
parse: Submodule<parsingExports>;
|
|
20
|
-
format: Submodule<formattingExports>;
|
|
21
|
-
}
|
|
22
|
-
export declare const ambient: Scope<Ark>;
|
|
23
|
-
export declare const ark: Module<Ark>;
|
|
24
|
-
export declare const type: TypeParser<{}>;
|
|
25
|
-
export declare namespace type {
|
|
26
|
-
type cast<t> = {
|
|
27
|
-
[inferred]?: t;
|
|
28
|
-
};
|
|
29
|
-
type errors = ArkErrors;
|
|
30
|
-
}
|
|
31
|
-
export declare const generic: GenericHktParser<{}>;
|
|
32
|
-
export declare const define: DefinitionParser<{}>;
|
|
33
|
-
export declare const declare: DeclarationParser<{}>;
|
package/out/ark.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { arkGenerics } from "./keywords/arkGenerics.js";
|
|
2
|
-
import { formatting } from "./keywords/format.js";
|
|
3
|
-
import { internal } from "./keywords/internal.js";
|
|
4
|
-
import { jsObjects } from "./keywords/jsObjects.js";
|
|
5
|
-
import { parsing } from "./keywords/parsing.js";
|
|
6
|
-
import { platformObjects } from "./keywords/platformObjects.js";
|
|
7
|
-
import { tsGenerics } from "./keywords/tsGenerics.js";
|
|
8
|
-
import { tsKeywords } from "./keywords/tsKeywords.js";
|
|
9
|
-
import { typedArray } from "./keywords/typedArray.js";
|
|
10
|
-
import { validation } from "./keywords/validation.js";
|
|
11
|
-
import { scope } from "./scope.js";
|
|
12
|
-
export const ambient = scope({
|
|
13
|
-
...tsKeywords,
|
|
14
|
-
...jsObjects,
|
|
15
|
-
...platformObjects,
|
|
16
|
-
...validation,
|
|
17
|
-
...internal,
|
|
18
|
-
...tsGenerics,
|
|
19
|
-
...arkGenerics,
|
|
20
|
-
TypedArray: typedArray,
|
|
21
|
-
parse: parsing,
|
|
22
|
-
format: formatting
|
|
23
|
-
}, { prereducedAliases: true, ambient: true });
|
|
24
|
-
export const ark = ambient.export();
|
|
25
|
-
export const type = ambient.type;
|
|
26
|
-
export const generic = ambient.generic;
|
|
27
|
-
export const define = ambient.define;
|
|
28
|
-
export const declare = ambient.declare;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as util from "@ark/util";
|
|
2
|
-
import { Hkt } from "@ark/util";
|
|
3
|
-
import type { Out } from "../ast.js";
|
|
4
|
-
import type { Module } from "../module.js";
|
|
5
|
-
import { type inferScope } from "../scope.js";
|
|
6
|
-
declare class liftArrayHkt extends Hkt<[element: unknown]> {
|
|
7
|
-
body: util.liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => Out<lifted> : never;
|
|
8
|
-
}
|
|
9
|
-
declare class mergeHkt extends Hkt<[base: object, props: object]> {
|
|
10
|
-
body: util.merge<this[0], this[1]>;
|
|
11
|
-
}
|
|
12
|
-
declare const arkGenericsExports: {
|
|
13
|
-
liftArray: import("@ark/schema").GenericRoot<readonly [["element", unknown]], liftArrayHkt>;
|
|
14
|
-
merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], mergeHkt>;
|
|
15
|
-
};
|
|
16
|
-
export type arkGenericsExports = inferScope<typeof arkGenericsExports>;
|
|
17
|
-
export type arkGenerics = Module<arkGenericsExports>;
|
|
18
|
-
export declare const arkGenerics: arkGenerics;
|
|
19
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { genericNode } from "@ark/schema";
|
|
2
|
-
import * as util from "@ark/util";
|
|
3
|
-
import { Hkt } from "@ark/util";
|
|
4
|
-
import { scope } from "../scope.js";
|
|
5
|
-
import { tsKeywords } from "./tsKeywords.js";
|
|
6
|
-
class liftArrayHkt extends Hkt {
|
|
7
|
-
}
|
|
8
|
-
const liftArray = genericNode("element")(args => args.element.or(args.element.array()).pipe(util.liftArray), liftArrayHkt);
|
|
9
|
-
class mergeHkt extends Hkt {
|
|
10
|
-
}
|
|
11
|
-
const merge = genericNode(["base", tsKeywords.object], ["props", tsKeywords.object])(args => args.base.merge(args.props), mergeHkt);
|
|
12
|
-
const arkGenericsExports = {
|
|
13
|
-
liftArray,
|
|
14
|
-
merge
|
|
15
|
-
};
|
|
16
|
-
const $ = scope(arkGenericsExports, {
|
|
17
|
-
prereducedAliases: true
|
|
18
|
-
});
|
|
19
|
-
export const arkGenerics = $.export();
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { array, Digit, Key } from "@ark/util";
|
|
2
|
-
import type { Module } from "../module.js";
|
|
3
|
-
import "./tsKeywords.js";
|
|
4
|
-
export type NonNegativeIntegerString = `${Digit}` | (`${Exclude<Digit, 0>}${string}` & `${bigint}`);
|
|
5
|
-
export interface internalExports {
|
|
6
|
-
lengthBoundable: string | array;
|
|
7
|
-
key: Key;
|
|
8
|
-
nonNegativeIntegerString: NonNegativeIntegerString;
|
|
9
|
-
}
|
|
10
|
-
export type internal = Module<internalExports>;
|
|
11
|
-
export declare const internal: internal;
|