arktype 2.0.0-rc.2 → 2.0.0-rc.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/attributes.d.ts +274 -0
- package/out/attributes.js +2 -0
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +52 -55
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +37 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/keywords.d.ts +64 -0
- package/out/keywords/{ark.js → keywords.js} +14 -9
- package/out/keywords/number/epoch.d.ts +1 -1
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +44 -14
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +2 -2
- package/out/keywords/string/alphanumeric.d.ts +2 -2
- package/out/keywords/string/base64.d.ts +21 -0
- package/out/keywords/string/base64.js +6 -0
- package/out/keywords/string/capitalize.d.ts +3 -3
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +2 -2
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +7 -11
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +2 -2
- package/out/keywords/string/email.d.ts +2 -2
- package/out/keywords/string/integer.d.ts +3 -3
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +5 -5
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +4 -3
- package/out/keywords/string/json.js +39 -30
- package/out/keywords/string/lower.d.ts +3 -3
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +27 -31
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +3 -3
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +2 -2
- package/out/keywords/string/string.d.ts +74 -51
- package/out/keywords/string/string.js +5 -3
- package/out/keywords/string/trim.d.ts +3 -3
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +3 -3
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +3 -3
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +20 -20
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +38 -1
- package/out/keywords/ts.js +20 -4
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +183 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +12 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +13 -0
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +10 -10
- package/out/parser/ast/validate.js +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +14 -40
- package/out/parser/objectLiteral.js +8 -26
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +9 -12
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +6 -4
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/shift/operand/operand.d.ts +9 -0
- package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +14 -7
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +14 -0
- package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +47 -0
- package/out/parser/shift/scanner.js +42 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +60 -44
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +38 -39
- package/out/scope.js +47 -36
- package/out/type.d.ts +45 -21
- package/out/type.js +14 -10
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -39
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -9
- package/out/parser/string/shift/operator/operator.d.ts +0 -13
- package/out/parser/string/shift/scanner.d.ts +0 -69
- package/out/parser/string/shift/scanner.js +0 -100
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/instantiate.d.ts +0 -16
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/number.d.ts +0 -12
- package/out/subtypes/object.d.ts +0 -33
- package/out/subtypes/string.d.ts +0 -13
- package/out/subtypes/validator.d.ts +0 -11
- package/out/subtypes/validator.js +0 -1
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
package/out/parser/tuple.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
|
|
2
|
-
import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
|
-
import { writeMissingRightOperandMessage } from "./
|
|
1
|
+
import { $ark, Disjoint, intersectNodesRoot, makeRootAndArrayPropertiesMutable } from "@ark/schema";
|
|
2
|
+
import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
|
+
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
|
|
4
4
|
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
|
|
5
5
|
export const parseTupleLiteral = (def, ctx) => {
|
|
6
6
|
let sequences = [{}];
|
|
7
7
|
let i = 0;
|
|
8
8
|
while (i < def.length) {
|
|
9
9
|
let spread = false;
|
|
10
|
-
let optional = false;
|
|
11
10
|
if (def[i] === "..." && i < def.length - 1) {
|
|
12
11
|
spread = true;
|
|
13
12
|
i++;
|
|
14
13
|
}
|
|
15
|
-
const element = ctx.$.
|
|
14
|
+
const element = ctx.$.parseOwnDefinitionFormat(def[i], ctx);
|
|
16
15
|
i++;
|
|
17
|
-
if (def[i] === "?") {
|
|
18
|
-
if (spread)
|
|
19
|
-
return throwParseError(spreadOptionalMessage);
|
|
20
|
-
optional = true;
|
|
21
|
-
i++;
|
|
22
|
-
}
|
|
23
16
|
if (spread) {
|
|
24
17
|
if (!element.extends($ark.intrinsic.Array))
|
|
25
18
|
return throwParseError(writeNonArraySpreadMessage(element.expression));
|
|
@@ -31,13 +24,18 @@ export const parseTupleLiteral = (def, ctx) => {
|
|
|
31
24
|
element.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
|
|
32
25
|
}
|
|
33
26
|
else {
|
|
34
|
-
sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
|
|
27
|
+
sequences = sequences.map(base => appendElement(base, element.meta.optional ? "optional" : "required", element));
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
|
-
return ctx.$.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
return ctx.$.parseSchema(sequences.map(sequence => isEmptyObject(sequence) ?
|
|
31
|
+
{
|
|
32
|
+
proto: Array,
|
|
33
|
+
exactLength: 0
|
|
34
|
+
}
|
|
35
|
+
: {
|
|
36
|
+
proto: Array,
|
|
37
|
+
sequence
|
|
38
|
+
}));
|
|
41
39
|
};
|
|
42
40
|
const appendElement = (base, kind, element) => {
|
|
43
41
|
switch (kind) {
|
|
@@ -86,11 +84,11 @@ const appendSpreadBranch = (base, branch) => {
|
|
|
86
84
|
// the only array with no sequence reference is unknown[]
|
|
87
85
|
return appendElement(base, "variadic", $ark.intrinsic.unknown);
|
|
88
86
|
}
|
|
89
|
-
spread.prefix
|
|
90
|
-
spread.optionals
|
|
87
|
+
spread.prefix?.forEach(node => appendElement(base, "required", node));
|
|
88
|
+
spread.optionals?.forEach(node => appendElement(base, "optional", node));
|
|
91
89
|
if (spread.variadic)
|
|
92
90
|
appendElement(base, "variadic", spread.variadic);
|
|
93
|
-
spread.postfix
|
|
91
|
+
spread.postfix?.forEach(node => appendElement(base, "required", node));
|
|
94
92
|
return base;
|
|
95
93
|
};
|
|
96
94
|
const maybeParseTupleExpression = (def, ctx) => {
|
|
@@ -104,38 +102,46 @@ export const multipleVariadicMesage = "A tuple may have at most one variadic ele
|
|
|
104
102
|
export const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
105
103
|
export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
|
|
106
104
|
export const spreadOptionalMessage = "A spread element cannot be optional";
|
|
107
|
-
export const parseKeyOfTuple = (def, ctx) => ctx.$.
|
|
105
|
+
export const parseKeyOfTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[1], ctx).keyof();
|
|
108
106
|
const parseBranchTuple = (def, ctx) => {
|
|
109
107
|
if (def[2] === undefined)
|
|
110
108
|
return throwParseError(writeMissingRightOperandMessage(def[1], ""));
|
|
111
|
-
const l = ctx.$.
|
|
112
|
-
const r = ctx.$.
|
|
113
|
-
|
|
109
|
+
const l = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
|
|
110
|
+
const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
|
|
111
|
+
if (def[1] === "|")
|
|
112
|
+
return ctx.$.node("union", { branches: [l, r] });
|
|
113
|
+
const result = intersectNodesRoot(l, r, ctx.$);
|
|
114
|
+
if (result instanceof Disjoint)
|
|
115
|
+
return result.throw();
|
|
116
|
+
return result;
|
|
114
117
|
};
|
|
115
|
-
const parseArrayTuple = (def, ctx) => ctx.$.
|
|
118
|
+
const parseArrayTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).array();
|
|
116
119
|
const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
|
|
117
120
|
export const parseMorphTuple = (def, ctx) => {
|
|
118
121
|
if (typeof def[2] !== "function") {
|
|
119
122
|
return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
return ctx.$.parse(def[0], ctx).pipe(def[2]);
|
|
124
|
+
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
|
|
123
125
|
};
|
|
124
126
|
export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
|
|
125
127
|
export const parseNarrowTuple = (def, ctx) => {
|
|
126
128
|
if (typeof def[2] !== "function") {
|
|
127
129
|
return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
|
|
128
130
|
}
|
|
129
|
-
return ctx.$.
|
|
131
|
+
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
|
|
130
132
|
};
|
|
131
|
-
const parseAttributeTuple = (def, ctx) => ctx.$.
|
|
133
|
+
const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configureShallowDescendants(def[2]);
|
|
134
|
+
const parseDefaultTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).default(def[2]);
|
|
135
|
+
const parseOptionalTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).optional();
|
|
132
136
|
const indexOneParsers = {
|
|
137
|
+
"[]": parseArrayTuple,
|
|
138
|
+
"?": parseOptionalTuple,
|
|
133
139
|
"|": parseBranchTuple,
|
|
134
140
|
"&": parseBranchTuple,
|
|
135
|
-
"[]": parseArrayTuple,
|
|
136
141
|
":": parseNarrowTuple,
|
|
137
142
|
"=>": parseMorphTuple,
|
|
138
|
-
"@": parseAttributeTuple
|
|
143
|
+
"@": parseAttributeTuple,
|
|
144
|
+
"=": parseDefaultTuple
|
|
139
145
|
};
|
|
140
146
|
const prefixParsers = {
|
|
141
147
|
keyof: parseKeyOfTuple,
|
package/out/scope.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type
|
|
2
|
-
import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type { Ark, type } from "./keywords/
|
|
1
|
+
import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, 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 noSuggest, type nominal } from "@ark/util";
|
|
3
|
+
import type { ArkSchemaRegistry } from "./config.ts";
|
|
4
|
+
import { type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
|
|
5
|
+
import type { Ark, type } from "./keywords/keywords.ts";
|
|
6
6
|
import type { BoundModule, Module, Submodule, instantiateExport } from "./module.ts";
|
|
7
|
+
import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
|
|
7
8
|
import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
|
|
8
|
-
import type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
9
|
+
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
|
|
10
|
+
/** The convenience properties attached to `scope` */
|
|
11
|
+
export type ScopeParserAttachments = Omit<ScopeParser, never>;
|
|
12
|
+
export interface ScopeParser {
|
|
13
|
+
<const def>(def: scope.validate<def>, config?: ArkScopeConfig): Scope<scope.infer<def>>;
|
|
14
|
+
define: <const def>(def: scope.validate<def>) => def;
|
|
15
|
+
}
|
|
16
|
+
export type ModuleParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => scope.infer<def> extends infer $ ? Module<{
|
|
13
17
|
[k in exportedNameOf<$>]: $[k];
|
|
14
18
|
}> : never;
|
|
15
|
-
export type
|
|
16
|
-
|
|
19
|
+
export type bindThis<def> = {
|
|
20
|
+
this: Def<def>;
|
|
17
21
|
};
|
|
18
|
-
export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
19
|
-
export type bindThis<def> = {};
|
|
20
22
|
/** nominal type for an unparsed definition used during scope bootstrapping */
|
|
21
23
|
type Def<def = {}> = nominal<def, "unparsed">;
|
|
22
24
|
/** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
|
|
@@ -26,9 +28,9 @@ type PreparsedResolution = PreparsedNodeResolution;
|
|
|
26
28
|
type bootstrapAliases<def> = {
|
|
27
29
|
[k in Exclude<keyof def, GenericDeclaration>]: def[k] extends (PreparsedResolution) ? def[k] extends {
|
|
28
30
|
t: infer g extends GenericAst;
|
|
29
|
-
} ? g : def[k] extends Module<infer $> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
|
|
31
|
+
} ? g : def[k] extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
|
|
30
32
|
t: infer g extends GenericAst;
|
|
31
|
-
} ? g : thunkReturn extends Module<infer $> ? Submodule<$> : thunkReturn : Def<def[k]>;
|
|
33
|
+
} ? g : thunkReturn extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : thunkReturn : Def<def[k]>;
|
|
32
34
|
} & {
|
|
33
35
|
[k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericAst<parseValidGenericParams<extractGenericParameters<k>, bootstrapAliases<def>>, def[k], UnparsedScope>;
|
|
34
36
|
};
|
|
@@ -40,18 +42,12 @@ type inferBootstrapped<$> = {
|
|
|
40
42
|
export type bindGenericToScope<g extends GenericAst, $> = GenericAst<g["paramsAst"], g["bodyDef"], g["$"] extends UnparsedScope ? $ : g["$"], $>;
|
|
41
43
|
type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
|
|
42
44
|
type extractGenericParameters<k> = k extends `${string}<${infer params}>` ? ParameterString<params> : never;
|
|
43
|
-
export type resolve<reference extends keyof $ | keyof args, $, args> = inferResolution<reference extends keyof args ? args[reference] : $[reference & keyof $], $, args>;
|
|
44
45
|
export type resolutionToAst<alias extends string, resolution> = [
|
|
45
46
|
resolution
|
|
46
47
|
] extends [anyOrNever] ? InferredAst<resolution, alias> : resolution extends Def<infer def> ? DefAst<def, alias> : resolution extends {
|
|
47
48
|
[arkKind]: "module";
|
|
48
|
-
|
|
49
|
+
root: infer root;
|
|
49
50
|
} ? InferredAst<root, alias> : resolution extends GenericAst ? resolution : InferredAst<resolution, alias>;
|
|
50
|
-
export type inferResolution<resolution, $, args> = [
|
|
51
|
-
resolution
|
|
52
|
-
] extends [anyOrNever] ? resolution : resolution extends {
|
|
53
|
-
[inferred]: infer t;
|
|
54
|
-
} ? t : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution;
|
|
55
51
|
export type moduleKeyOf<$> = {
|
|
56
52
|
[k in keyof $]: $[k] extends {
|
|
57
53
|
[arkKind]: "module";
|
|
@@ -59,30 +55,26 @@ export type moduleKeyOf<$> = {
|
|
|
59
55
|
$[k]
|
|
60
56
|
] extends [anyOrNever] ? never : k & string : never;
|
|
61
57
|
}[keyof $];
|
|
62
|
-
type unwrapPreinferred<t> = t extends type.cast<infer inferred> ? inferred : t;
|
|
63
|
-
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;
|
|
64
58
|
export interface ArkTypeRegistry extends ArkSchemaRegistry {
|
|
65
59
|
typeAttachments?: Ark.boundTypeAttachments<any>;
|
|
66
60
|
}
|
|
67
61
|
export declare const $arkTypeRegistry: ArkTypeRegistry;
|
|
68
|
-
export interface ParseContext extends TypeParseOptions {
|
|
69
|
-
$: InternalScope;
|
|
70
|
-
}
|
|
71
|
-
export interface TypeParseOptions {
|
|
72
|
-
args?: GenericArgResolutions;
|
|
73
|
-
}
|
|
74
62
|
export interface InternalScope {
|
|
75
63
|
constructor: typeof InternalScope;
|
|
76
64
|
}
|
|
77
65
|
export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
78
66
|
private parseCache;
|
|
79
|
-
preparseAlias(k: string, v: unknown): AliasDefEntry;
|
|
80
67
|
protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
|
|
81
|
-
preparseRoot(def: unknown): unknown;
|
|
82
68
|
get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
protected preparseOwnAliasEntry(k: string, v: unknown): AliasDefEntry;
|
|
70
|
+
parseGenericParams(def: string, opts: BaseParseOptions): array<GenericParamDef>;
|
|
71
|
+
protected normalizeRootScopeValue(resolution: unknown): unknown;
|
|
72
|
+
protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
|
|
73
|
+
parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
|
|
74
|
+
parseString(def: string, ctx: BaseParseContext): BaseRoot;
|
|
75
|
+
unit: UnitTypeParser<$>;
|
|
76
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
77
|
+
instanceOf: InstanceOfTypeParser<$>;
|
|
86
78
|
type: InternalTypeParser;
|
|
87
79
|
declare: () => {
|
|
88
80
|
type: InternalTypeParser;
|
|
@@ -92,6 +84,12 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
92
84
|
static module: ModuleParser;
|
|
93
85
|
}
|
|
94
86
|
export declare const scope: ScopeParser;
|
|
87
|
+
export declare namespace scope {
|
|
88
|
+
type validate<def> = {
|
|
89
|
+
[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;
|
|
90
|
+
};
|
|
91
|
+
type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
92
|
+
}
|
|
95
93
|
export declare const module: ModuleParser;
|
|
96
94
|
export interface Scope<$ = {}> {
|
|
97
95
|
t: $;
|
|
@@ -105,12 +103,14 @@ export interface Scope<$ = {}> {
|
|
|
105
103
|
aliases: Record<string, unknown>;
|
|
106
104
|
internal: toInternalScope<$>;
|
|
107
105
|
defineSchema<const def extends RootSchema>(schema: def): def;
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: BaseParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
|
|
107
|
+
unit: UnitTypeParser<$>;
|
|
108
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
110
109
|
type: TypeParser<$>;
|
|
111
110
|
declare: DeclarationParser<$>;
|
|
112
111
|
define: DefinitionParser<$>;
|
|
113
112
|
generic: GenericParser<$>;
|
|
113
|
+
schema: SchemaParser<$>;
|
|
114
114
|
import(): Module<{
|
|
115
115
|
[k in exportedNameOf<$> as PrivateDeclaration<k>]: $[k];
|
|
116
116
|
}>;
|
|
@@ -131,7 +131,6 @@ export interface ScopeConstructor {
|
|
|
131
131
|
module: ModuleParser;
|
|
132
132
|
}
|
|
133
133
|
export declare const Scope: ScopeConstructor;
|
|
134
|
-
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
|
|
135
134
|
export type parseScopeKey<k, def> = k extends `${infer name}<${infer params}>` ? parseGenericScopeKey<name, params, def> : {
|
|
136
135
|
name: k;
|
|
137
136
|
params: [];
|
package/out/scope.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
|
|
2
2
|
import { domainOf, flatMorph, hasDomain, isThunk, throwParseError } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { parseGenericParamName } from "./generic.js";
|
|
4
4
|
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
5
|
-
import { DynamicState } from "./parser/
|
|
6
|
-
import { writeUnexpectedCharacterMessage } from "./parser/
|
|
7
|
-
import {
|
|
8
|
-
import { fullStringParse } from "./parser/string
|
|
5
|
+
import { DynamicState } from "./parser/reduce/dynamic.js";
|
|
6
|
+
import { writeUnexpectedCharacterMessage } from "./parser/shift/operator/operator.js";
|
|
7
|
+
import { ArkTypeScanner } from "./parser/shift/scanner.js";
|
|
8
|
+
import { fullStringParse } from "./parser/string.js";
|
|
9
9
|
import { InternalTypeParser } from "./type.js";
|
|
10
10
|
export const $arkTypeRegistry = $ark;
|
|
11
11
|
export class InternalScope extends BaseScope {
|
|
12
12
|
parseCache = {};
|
|
13
|
-
|
|
13
|
+
cacheGetter(name, value) {
|
|
14
|
+
Object.defineProperty(this, name, { value });
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
get ambientAttachments() {
|
|
18
|
+
if (!$arkTypeRegistry.typeAttachments)
|
|
19
|
+
return;
|
|
20
|
+
return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
|
|
21
|
+
k,
|
|
22
|
+
this.bindReference(v)
|
|
23
|
+
]));
|
|
24
|
+
}
|
|
25
|
+
preparseOwnAliasEntry(k, v) {
|
|
14
26
|
const firstParamIndex = k.indexOf("<");
|
|
15
27
|
if (firstParamIndex === -1)
|
|
16
28
|
return [k, v];
|
|
@@ -24,47 +36,46 @@ export class InternalScope extends BaseScope {
|
|
|
24
36
|
// use a thunk definition for the generic so that we can parse
|
|
25
37
|
// constraints within the current scope
|
|
26
38
|
() => {
|
|
27
|
-
const params = parseGenericParams(paramString, {
|
|
28
|
-
$: this,
|
|
29
|
-
args: {}
|
|
30
|
-
});
|
|
39
|
+
const params = this.parseGenericParams(paramString, { alias: name });
|
|
31
40
|
const generic = parseGeneric(params, v, this);
|
|
32
41
|
return generic;
|
|
33
42
|
}
|
|
34
43
|
];
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return value;
|
|
45
|
+
parseGenericParams(def, opts) {
|
|
46
|
+
return parseGenericParamName(new ArkTypeScanner(def), [], this.createParseContext({ ...opts, def, prefix: "generic" }));
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
if (isThunk(
|
|
42
|
-
return
|
|
43
|
-
return
|
|
48
|
+
normalizeRootScopeValue(resolution) {
|
|
49
|
+
if (isThunk(resolution) && !hasArkKind(resolution, "generic"))
|
|
50
|
+
return resolution();
|
|
51
|
+
return resolution;
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]));
|
|
53
|
+
preparseOwnDefinitionFormat(def, opts) {
|
|
54
|
+
return {
|
|
55
|
+
...opts,
|
|
56
|
+
def,
|
|
57
|
+
prefix: opts.alias ?? "type"
|
|
58
|
+
};
|
|
52
59
|
}
|
|
53
|
-
|
|
60
|
+
parseOwnDefinitionFormat(def, ctx) {
|
|
61
|
+
const isScopeAlias = ctx.alias && ctx.alias in this.aliases;
|
|
62
|
+
// if the definition being parsed is not a scope alias and is not a
|
|
63
|
+
// generic instantiation (i.e. opts don't include args), add this as a resolution.
|
|
64
|
+
if (!isScopeAlias && !ctx.args)
|
|
65
|
+
ctx.args = { this: ctx.id };
|
|
54
66
|
if (typeof def === "string") {
|
|
55
67
|
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
56
68
|
// we can only rely on the cache if there are no contextual
|
|
57
69
|
// resolutions like "this" or generic args
|
|
58
|
-
return this.parseString(def, ctx
|
|
70
|
+
return this.parseString(def, ctx);
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
|
|
72
|
+
return (this.parseCache[def] ??= this.parseString(def, ctx));
|
|
62
73
|
}
|
|
63
74
|
return hasDomain(def, "object") ?
|
|
64
75
|
parseObject(def, ctx)
|
|
65
76
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
66
77
|
}
|
|
67
|
-
parseString(def, ctx
|
|
78
|
+
parseString(def, ctx) {
|
|
68
79
|
const aliasResolution = this.maybeResolveRoot(def);
|
|
69
80
|
if (aliasResolution)
|
|
70
81
|
return aliasResolution;
|
|
@@ -73,16 +84,15 @@ export class InternalScope extends BaseScope {
|
|
|
73
84
|
: undefined;
|
|
74
85
|
if (aliasArrayResolution)
|
|
75
86
|
return aliasArrayResolution;
|
|
76
|
-
const s = new DynamicState(new
|
|
87
|
+
const s = new DynamicState(new ArkTypeScanner(def), ctx);
|
|
77
88
|
const node = fullStringParse(s);
|
|
78
89
|
if (s.finalizer === ">")
|
|
79
90
|
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
80
91
|
return node;
|
|
81
92
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
93
|
+
unit = value => this.units([value]);
|
|
94
|
+
enumerated = (...values) => this.units(values);
|
|
95
|
+
instanceOf = ctor => this.node("proto", { proto: ctor }, { prereduced: true });
|
|
86
96
|
type = new InternalTypeParser(this);
|
|
87
97
|
declare = () => ({
|
|
88
98
|
type: this.type
|
|
@@ -91,7 +101,8 @@ export class InternalScope extends BaseScope {
|
|
|
91
101
|
static scope = ((def, config = {}) => new InternalScope(def, config));
|
|
92
102
|
static module = ((def, config = {}) => this.scope(def, config).export());
|
|
93
103
|
}
|
|
94
|
-
export const scope = InternalScope.scope
|
|
104
|
+
export const scope = Object.assign(InternalScope.scope, {
|
|
105
|
+
define: def => def
|
|
106
|
+
});
|
|
95
107
|
export const module = InternalScope.module;
|
|
96
108
|
export const Scope = InternalScope;
|
|
97
|
-
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
|
package/out/type.d.ts
CHANGED
|
@@ -1,25 +1,52 @@
|
|
|
1
|
-
import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
|
|
2
|
-
import { Callable, type Constructor, type array, type conform } from "@ark/util";
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
1
|
+
import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";
|
|
2
|
+
import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
|
|
3
|
+
import type { DefaultFor, distill } from "./attributes.ts";
|
|
4
|
+
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
|
|
5
|
+
import type { Ark, keywords, type } from "./keywords/keywords.ts";
|
|
6
|
+
import type { BaseType } from "./methods/base.ts";
|
|
7
|
+
import type { instantiateType } from "./methods/instantiate.ts";
|
|
8
|
+
import type { validateDeclared, validateDefinition } from "./parser/definition.ts";
|
|
7
9
|
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";
|
|
8
10
|
import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";
|
|
9
|
-
import type { BaseType } from "./subtypes/base.ts";
|
|
10
|
-
import type { instantiateType } from "./subtypes/instantiate.ts";
|
|
11
11
|
/** The convenience properties attached to `type` */
|
|
12
12
|
export type TypeParserAttachments = Omit<TypeParser, never>;
|
|
13
13
|
export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
14
|
-
<const def, r = Type<
|
|
15
|
-
<params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
|
|
16
|
-
<const zero, const one, const rest extends array, r = Type<
|
|
17
|
-
|
|
14
|
+
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
|
|
15
|
+
<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
|
|
16
|
+
<const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [DefaultFor<distill.In<type.infer<NoInfer<zero>, $>>>] : [type.validate<rest[0], $>] : []): r;
|
|
17
|
+
/**
|
|
18
|
+
* Error class for validation errors
|
|
19
|
+
* Calling type instance returns an instance of this class on failure
|
|
20
|
+
* @example if ( T(data) instanceof type.errors ) { ... }
|
|
21
|
+
*/
|
|
18
22
|
errors: typeof ArkErrors;
|
|
23
|
+
hkt: typeof Hkt;
|
|
24
|
+
keywords: typeof keywords;
|
|
25
|
+
$: Scope<$>;
|
|
26
|
+
raw(def: unknown): BaseType<any, $>;
|
|
19
27
|
module: ModuleParser;
|
|
20
28
|
scope: ScopeParser;
|
|
29
|
+
define: DefinitionParser<$>;
|
|
21
30
|
generic: GenericParser<$>;
|
|
22
|
-
|
|
31
|
+
schema: SchemaParser<$>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a `Type` that is satisfied only by a value strictly equal (`===`) to the argument passed to this function.
|
|
34
|
+
* @example const foo = type.unit('foo') // Type<'foo'>
|
|
35
|
+
* @example const sym: unique symbol = Symbol(); type.unit(sym) // Type<typeof sym>
|
|
36
|
+
*/
|
|
37
|
+
unit: UnitTypeParser<$>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a `Type` that is satisfied only by a value strictly equal (`===`) to one of the arguments passed to this function.
|
|
40
|
+
* @example const enum = type.enumerated('foo', 'bar', obj) // obj is a by-reference object
|
|
41
|
+
* @example const tupleForm = type(['===', 'foo', 'bar', obj])
|
|
42
|
+
* @example const argsForm = type('===', 'foo', 'bar', obj)
|
|
43
|
+
*/
|
|
44
|
+
enumerated: EnumeratedTypeParser<$>;
|
|
45
|
+
/**
|
|
46
|
+
* Create a `Type` that is satisfied only by a value of a specific class.
|
|
47
|
+
* @example const array = type.instanceOf(Array)
|
|
48
|
+
*/
|
|
49
|
+
instanceOf: InstanceOfTypeParser<$>;
|
|
23
50
|
}
|
|
24
51
|
export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
|
|
25
52
|
constructor($: InternalScope);
|
|
@@ -27,14 +54,11 @@ export declare class InternalTypeParser extends Callable<(...args: unknown[]) =>
|
|
|
27
54
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
28
55
|
type: <const def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
|
|
29
56
|
};
|
|
30
|
-
export type
|
|
31
|
-
export type
|
|
32
|
-
export type
|
|
33
|
-
export type
|
|
34
|
-
export type
|
|
57
|
+
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
|
|
58
|
+
export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>;
|
|
59
|
+
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
|
|
60
|
+
export type DefinitionParser<$> = <const def>(def: type.validate<def, $>) => def;
|
|
61
|
+
export type SchemaParser<$> = (schema: RootSchema, opts?: BaseParseOptions) => Type<unknown, $>;
|
|
35
62
|
export type Type<t = unknown, $ = {}> = instantiateType<t, $>;
|
|
36
|
-
export declare namespace Type {
|
|
37
|
-
type Any<t = any> = BaseType<t, any>;
|
|
38
|
-
}
|
|
39
63
|
export type TypeConstructor<t = unknown, $ = {}> = new (def: unknown, $: Scope<$>) => Type<t, $>;
|
|
40
64
|
export declare const Type: TypeConstructor;
|
package/out/type.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { ArkErrors, BaseRoot, GenericRoot } from "@ark/schema";
|
|
2
|
-
import { Callable } from "@ark/util";
|
|
3
|
-
import { parseGenericParams } from "./generic.js";
|
|
2
|
+
import { Callable, Hkt } from "@ark/util";
|
|
4
3
|
export class InternalTypeParser extends Callable {
|
|
5
4
|
constructor($) {
|
|
6
5
|
const attach = Object.assign({
|
|
7
6
|
errors: ArkErrors,
|
|
8
|
-
|
|
7
|
+
hkt: Hkt,
|
|
8
|
+
$: $,
|
|
9
|
+
raw: $.parse,
|
|
9
10
|
module: $.constructor.module,
|
|
10
11
|
scope: $.constructor.scope,
|
|
12
|
+
define: $.define,
|
|
11
13
|
generic: $.generic,
|
|
14
|
+
schema: $.schema,
|
|
12
15
|
// this won't be defined during bootstrapping, but externally always will be
|
|
13
|
-
|
|
16
|
+
keywords: $.ambient,
|
|
17
|
+
unit: $.unit,
|
|
18
|
+
enumerated: $.enumerated,
|
|
19
|
+
instanceOf: $.instanceOf
|
|
14
20
|
},
|
|
15
21
|
// also won't be defined during bootstrapping
|
|
16
22
|
$.ambientAttachments);
|
|
17
23
|
super((...args) => {
|
|
18
24
|
if (args.length === 1) {
|
|
19
25
|
// treat as a simple definition
|
|
20
|
-
return $.
|
|
26
|
+
return $.parse(args[0]);
|
|
21
27
|
}
|
|
22
28
|
if (args.length === 2 &&
|
|
23
29
|
typeof args[0] === "string" &&
|
|
@@ -25,16 +31,14 @@ export class InternalTypeParser extends Callable {
|
|
|
25
31
|
args[0].at(-1) === ">") {
|
|
26
32
|
// if there are exactly two args, the first of which looks like <${string}>,
|
|
27
33
|
// treat as a generic
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
args: {}
|
|
31
|
-
});
|
|
34
|
+
const paramString = args[0].slice(1, -1);
|
|
35
|
+
const params = $.parseGenericParams(paramString, {});
|
|
32
36
|
return new GenericRoot(params, args[1], $, $);
|
|
33
37
|
}
|
|
34
38
|
// otherwise, treat as a tuple expression. technically, this also allows
|
|
35
39
|
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
36
40
|
// part of the API as specified by the associated types
|
|
37
|
-
return $.
|
|
41
|
+
return $.parse(args);
|
|
38
42
|
}, {
|
|
39
43
|
bind: $,
|
|
40
44
|
attach
|
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-rc.
|
|
4
|
+
"version": "2.0.0-rc.22",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"out"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ark/util": "0.
|
|
38
|
-
"@ark/schema": "0.
|
|
37
|
+
"@ark/util": "0.22.0",
|
|
38
|
+
"@ark/schema": "0.22.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
package/out/intersect.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
|
|
2
|
-
import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./keywords/ast.ts";
|
|
3
|
-
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
4
|
-
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
5
|
-
type _inferIntersection<l, r, piped extends boolean> = [
|
|
6
|
-
l & r
|
|
7
|
-
] extends [infer t extends anyOrNever] ? t : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends MorphAst<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
|
|
8
|
-
infer lBase,
|
|
9
|
-
infer lConstraints extends Constraints
|
|
10
|
-
]) ? parseConstraints<r> extends ([
|
|
11
|
-
infer rBase,
|
|
12
|
-
infer rConstraints extends Constraints
|
|
13
|
-
]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
|
|
14
|
-
infer rBase,
|
|
15
|
-
infer rConstraints extends Constraints
|
|
16
|
-
]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
17
|
-
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
18
|
-
body: _inferIntersection<this[0], this[1], piped>;
|
|
19
|
-
}
|
|
20
|
-
type intersectObjects<l, r, piped extends boolean> = [
|
|
21
|
-
l,
|
|
22
|
-
r
|
|
23
|
-
] extends [infer lList extends array, infer rList extends array] ? intersectArrays<lList, rList, MorphableIntersection<piped>> : show<{
|
|
24
|
-
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
25
|
-
} & {
|
|
26
|
-
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
27
|
-
}>;
|
|
28
|
-
export {};
|
package/out/keys.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { array, join, Key, NonNegativeIntegerLiteral, typeToString } from "@ark/util";
|
|
2
|
-
import type { type } from "./keywords/ark.ts";
|
|
3
|
-
import type { termOrType } from "./keywords/ast.ts";
|
|
4
|
-
export type toArkKey<o, k extends keyof o> = k extends number ? [
|
|
5
|
-
o,
|
|
6
|
-
number
|
|
7
|
-
] extends [array, k] ? NonNegativeIntegerLiteral : `${k}` : k;
|
|
8
|
-
export type arkKeyOf<o> = o extends array ? (number extends o["length"] ? NonNegativeIntegerLiteral : never) | {
|
|
9
|
-
[k in keyof o]-?: k extends `${infer index extends number}` ? index | k : never;
|
|
10
|
-
}[keyof o & `${number}`] : {
|
|
11
|
-
[k in keyof o]: k extends number ? k | `${k}` : k;
|
|
12
|
-
}[keyof o];
|
|
13
|
-
export type getArkKey<o, k extends arkKeyOf<o>> = o[Extract<k extends NonNegativeIntegerLiteral ? number : k, keyof o>];
|
|
14
|
-
export type TypeKey = termOrType<Key>;
|
|
15
|
-
export type typeKeyToString<k extends TypeKey> = typeToString<k extends type.cast<infer t> ? t : k>;
|
|
16
|
-
export type writeInvalidKeysMessage<o extends string, keys extends array<string>> = `Key${keys["length"] extends 1 ? "" : "s"} ${join<keys, ", ">} ${keys["length"] extends 1 ? "does" : "do"} not exist on ${o}`;
|