arktype 2.0.0-rc.5 → 2.0.0-rc.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/generic.d.ts +34 -36
- package/out/index.d.ts +1 -1
- package/out/intersect.d.ts +2 -4
- package/out/keywords/ark.d.ts +7 -6
- package/out/keywords/ark.js +3 -2
- package/out/keywords/ast.d.ts +14 -12
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.js +2 -2
- package/out/keywords/constructors/FormData.js +2 -2
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/number/number.d.ts +8 -0
- package/out/keywords/number/number.js +16 -4
- package/out/keywords/string/capitalize.js +2 -2
- package/out/keywords/string/date.d.ts +0 -4
- package/out/keywords/string/date.js +4 -4
- package/out/keywords/string/integer.js +2 -2
- package/out/keywords/string/ip.js +2 -2
- package/out/keywords/string/json.js +2 -2
- package/out/keywords/string/lower.js +2 -2
- package/out/keywords/string/normalize.d.ts +0 -4
- package/out/keywords/string/normalize.js +6 -6
- package/out/keywords/string/numeric.js +2 -2
- package/out/keywords/string/string.d.ts +1 -4
- package/out/keywords/string/string.js +2 -2
- package/out/keywords/string/trim.js +2 -2
- package/out/keywords/string/upper.js +2 -2
- package/out/keywords/string/url.js +2 -2
- package/out/keywords/string/uuid.js +2 -2
- package/out/keywords/ts.d.ts +11 -0
- package/out/keywords/ts.js +7 -3
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/methods/base.d.ts +15 -15
- package/out/methods/morph.d.ts +3 -3
- package/out/methods/object.d.ts +1 -2
- package/out/parser/semantic/default.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.js +7 -3
- package/out/parser/tuple.js +10 -5
- package/out/scope.d.ts +1 -0
- package/out/scope.js +5 -2
- package/out/type.d.ts +6 -9
- package/out/type.js +1 -0
- package/package.json +3 -3
package/out/generic.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
2
|
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhiteSpaceToken } from "@ark/util";
|
|
3
|
+
import type { type } from "./keywords/ark.ts";
|
|
3
4
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
4
5
|
import type { inferAstRoot } from "./parser/semantic/infer.ts";
|
|
5
6
|
import type { validateAst } from "./parser/semantic/validate.ts";
|
|
@@ -7,23 +8,23 @@ import type { state, StaticState } from "./parser/string/reduce/static.ts";
|
|
|
7
8
|
import { Scanner } from "./parser/string/shift/scanner.ts";
|
|
8
9
|
import { parseUntilFinalizer } from "./parser/string/string.ts";
|
|
9
10
|
import type { ParseContext, Scope } from "./scope.ts";
|
|
10
|
-
import type {
|
|
11
|
+
import type { Type } from "./type.ts";
|
|
11
12
|
export type ParameterString<params extends string = string> = `<${params}>`;
|
|
12
13
|
export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
|
|
13
14
|
export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
|
|
14
|
-
export type validateGenericArg<arg, param extends GenericParamAst, $> =
|
|
15
|
+
export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
|
|
15
16
|
export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
|
|
16
|
-
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a:
|
|
17
|
+
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
|
|
17
18
|
} : params["length"] extends 2 ? {
|
|
18
|
-
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
19
|
+
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [type.validate<a, args$>, type.validate<b, args$>] & [
|
|
19
20
|
validateGenericArg<a, params[0], args$>,
|
|
20
21
|
validateGenericArg<b, params[1], args$>
|
|
21
22
|
]): r;
|
|
22
23
|
} : params["length"] extends 3 ? {
|
|
23
24
|
<const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
type.validate<a, args$>,
|
|
26
|
+
type.validate<b, args$>,
|
|
27
|
+
type.validate<c, args$>
|
|
27
28
|
] & [
|
|
28
29
|
validateGenericArg<a, params[0], args$>,
|
|
29
30
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -31,10 +32,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
31
32
|
]): r;
|
|
32
33
|
} : params["length"] extends 4 ? {
|
|
33
34
|
<const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
type.validate<a, args$>,
|
|
36
|
+
type.validate<b, args$>,
|
|
37
|
+
type.validate<c, args$>,
|
|
38
|
+
type.validate<d, args$>
|
|
38
39
|
] & [
|
|
39
40
|
validateGenericArg<a, params[0], args$>,
|
|
40
41
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -43,11 +44,11 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
43
44
|
]): r;
|
|
44
45
|
} : params["length"] extends 4 ? {
|
|
45
46
|
<const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
type.validate<a, args$>,
|
|
48
|
+
type.validate<b, args$>,
|
|
49
|
+
type.validate<c, args$>,
|
|
50
|
+
type.validate<d, args$>,
|
|
51
|
+
type.validate<e, args$>
|
|
51
52
|
] & [
|
|
52
53
|
validateGenericArg<a, params[0], args$>,
|
|
53
54
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -57,12 +58,12 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
57
58
|
]): r;
|
|
58
59
|
} : params["length"] extends 5 ? {
|
|
59
60
|
<const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
type.validate<a, args$>,
|
|
62
|
+
type.validate<b, args$>,
|
|
63
|
+
type.validate<c, args$>,
|
|
64
|
+
type.validate<d, args$>,
|
|
65
|
+
type.validate<e, args$>,
|
|
66
|
+
type.validate<f, args$>
|
|
66
67
|
] & [
|
|
67
68
|
validateGenericArg<a, params[0], args$>,
|
|
68
69
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -73,13 +74,13 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
73
74
|
]): r;
|
|
74
75
|
} : params["length"] extends 6 ? {
|
|
75
76
|
<const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
type.validate<a, args$>,
|
|
78
|
+
type.validate<b, args$>,
|
|
79
|
+
type.validate<c, args$>,
|
|
80
|
+
type.validate<d, args$>,
|
|
81
|
+
type.validate<e, args$>,
|
|
82
|
+
type.validate<f, args$>,
|
|
83
|
+
type.validate<g, args$>
|
|
83
84
|
] & [
|
|
84
85
|
validateGenericArg<a, params[0], args$>,
|
|
85
86
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -93,10 +94,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
93
94
|
type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
|
|
94
95
|
def
|
|
95
96
|
] extends [Hkt] ? Hkt.apply<def, {
|
|
96
|
-
[i in keyof args]:
|
|
97
|
+
[i in keyof args]: type.infer<args[i], args$>;
|
|
97
98
|
}> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
|
|
98
99
|
type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
|
|
99
|
-
[i in keyof params & `${number}` as params[i][0]]:
|
|
100
|
+
[i in keyof params & `${number}` as params[i][0]]: type.infer<args[i & keyof args], $>;
|
|
100
101
|
};
|
|
101
102
|
type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGenericConstraints<params> extends infer baseConstraints ? {
|
|
102
103
|
[k in keyof baseConstraints]: Type<baseConstraints[k], $>;
|
|
@@ -143,17 +144,14 @@ type _parseOptionalConstraint<unscanned extends string, name extends string, res
|
|
|
143
144
|
...result,
|
|
144
145
|
[name, unknown]
|
|
145
146
|
], $>;
|
|
146
|
-
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
|
|
147
|
-
name,
|
|
148
|
-
inferTypeRoot<def, $>
|
|
149
|
-
] : never;
|
|
147
|
+
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
|
|
150
148
|
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
|
|
151
149
|
...{
|
|
152
150
|
[i in keyof defs]: genericParamDefToAst<defs[i], $>;
|
|
153
151
|
}
|
|
154
152
|
];
|
|
155
153
|
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
156
|
-
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name,
|
|
154
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
157
155
|
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
158
156
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
159
157
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
package/out/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { Generic } from "./generic.ts";
|
|
|
4
4
|
export { ambient, ark, declare, define, generic, type, type Ark } from "./keywords/ark.ts";
|
|
5
5
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
6
|
export { module, scope, type Scope, type inferScope, type validateScope } from "./scope.ts";
|
|
7
|
-
export { Type
|
|
7
|
+
export { Type } from "./type.ts";
|
package/out/intersect.d.ts
CHANGED
|
@@ -17,10 +17,8 @@ type _inferIntersection<l, r, piped extends boolean> = [
|
|
|
17
17
|
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
18
18
|
body: _inferIntersection<this[0], this[1], piped>;
|
|
19
19
|
}
|
|
20
|
-
type intersectObjects<l, r, piped extends boolean> = [
|
|
21
|
-
|
|
22
|
-
r
|
|
23
|
-
] extends [infer lList extends array, infer rList extends array] ? intersectArrays<lList, rList, MorphableIntersection<piped>> : show<{
|
|
20
|
+
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
|
|
21
|
+
l & r : r extends array ? l & r : show<{
|
|
24
22
|
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
25
23
|
} & {
|
|
26
24
|
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
package/out/keywords/ark.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import type { ArkErrors, arkKind } from "@ark/schema";
|
|
|
2
2
|
import type { inferred } from "@ark/util";
|
|
3
3
|
import type { GenericParser } from "../generic.ts";
|
|
4
4
|
import type { BoundModule, Module } from "../module.ts";
|
|
5
|
-
import type { inferDefinition } from "../parser/definition.ts";
|
|
6
|
-
import { type Scope } from "../scope.ts";
|
|
7
|
-
import type { DeclarationParser, DefinitionParser, Type, TypeParser
|
|
5
|
+
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
|
|
6
|
+
import { type bindThis, type Scope } from "../scope.ts";
|
|
7
|
+
import type { DeclarationParser, DefinitionParser, Type, TypeParser } from "../type.ts";
|
|
8
8
|
import type { distill } from "./ast.ts";
|
|
9
9
|
import { arkBuiltins } from "./builtins.ts";
|
|
10
10
|
import { arkPrototypes } from "./constructors/constructors.ts";
|
|
11
11
|
import { number } from "./number/number.ts";
|
|
12
12
|
import { string } from "./string/string.ts";
|
|
13
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.ts";
|
|
13
|
+
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
|
|
14
14
|
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
15
15
|
}
|
|
16
16
|
export declare namespace Ark {
|
|
@@ -19,6 +19,7 @@ export declare namespace Ark {
|
|
|
19
19
|
interface wrapped extends arkPrototypes.wrapped {
|
|
20
20
|
string: string.submodule;
|
|
21
21
|
number: number.submodule;
|
|
22
|
+
unknown: unknown.submodule;
|
|
22
23
|
}
|
|
23
24
|
interface typeAttachments extends arkTsKeywords.$ {
|
|
24
25
|
Key: arkBuiltins.$["Key"];
|
|
@@ -35,7 +36,7 @@ export declare namespace type {
|
|
|
35
36
|
[inferred]?: t;
|
|
36
37
|
};
|
|
37
38
|
type errors = ArkErrors;
|
|
38
|
-
type infer<def, $ = {}, args =
|
|
39
|
+
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
|
|
39
40
|
namespace infer {
|
|
40
41
|
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
41
42
|
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
@@ -47,7 +48,7 @@ export declare namespace type {
|
|
|
47
48
|
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
type validate<def, $ = {}
|
|
51
|
+
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
51
52
|
}
|
|
52
53
|
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
53
54
|
export declare const generic: GenericParser<{}>;
|
package/out/keywords/ark.js
CHANGED
|
@@ -3,7 +3,7 @@ import { arkBuiltins } from "./builtins.js";
|
|
|
3
3
|
import { arkPrototypes } from "./constructors/constructors.js";
|
|
4
4
|
import { number } from "./number/number.js";
|
|
5
5
|
import { string } from "./string/string.js";
|
|
6
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.js";
|
|
6
|
+
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.js";
|
|
7
7
|
$arkTypeRegistry.typeAttachments = {
|
|
8
8
|
...arkTsKeywords,
|
|
9
9
|
Key: arkBuiltins.Key,
|
|
@@ -15,7 +15,8 @@ export const ambient = scope({
|
|
|
15
15
|
...arkPrototypes,
|
|
16
16
|
...arkBuiltins,
|
|
17
17
|
string,
|
|
18
|
-
number
|
|
18
|
+
number,
|
|
19
|
+
unknown
|
|
19
20
|
}, { prereducedAliases: true, ambient: true });
|
|
20
21
|
export const ark = ambient.export();
|
|
21
22
|
export const type = ambient.type;
|
package/out/keywords/ast.d.ts
CHANGED
|
@@ -147,23 +147,25 @@ type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] e
|
|
|
147
147
|
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never : t extends DefaultedAst<infer t> ? _distill<t, opts> : t extends array ? distillArray<t, opts, []> : t extends Function ? t : {
|
|
148
148
|
[k in keyof t]: t[k];
|
|
149
149
|
} extends t ? opts["endpoint"] extends "in" ? show<{
|
|
150
|
-
[k in keyof t as k extends
|
|
150
|
+
[k in keyof t as k extends optionalInputKeyOf<t> ? never : k]: _distill<t[k], opts>;
|
|
151
151
|
} & {
|
|
152
|
-
[k in
|
|
152
|
+
[k in optionalInputKeyOf<t>]?: _distill<t[k], opts>;
|
|
153
153
|
}> : show<{
|
|
154
|
-
[k in keyof t as k extends
|
|
154
|
+
[k in keyof t as k extends metaOptionalKeyOf<t> ? never : k]: _distill<t[k], opts>;
|
|
155
155
|
} & {
|
|
156
|
-
[k in keyof t as k extends
|
|
156
|
+
[k in keyof t as k extends metaOptionalKeyOf<t> ? k : never]?: _distill<t[k], opts>;
|
|
157
157
|
}> : t;
|
|
158
|
-
type
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
type metaOptionalKey<o> = {
|
|
162
|
-
[k in keyof o]: o[k] extends OptionalAst ? [
|
|
163
|
-
o[k]
|
|
164
|
-
] extends [anyOrNever] ? never : k : never;
|
|
158
|
+
type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
|
|
159
|
+
type metaDefaultedKeyOf<o> = {
|
|
160
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
|
|
165
161
|
}[keyof o];
|
|
166
|
-
type
|
|
162
|
+
type metaOptionalKeyOf<o> = {
|
|
163
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
|
|
164
|
+
}[keyof o];
|
|
165
|
+
type distillArray<t extends array, opts extends distill.Options, prefix extends array> = _distillArray<t, opts, prefix> extends infer result ? (t extends unknown[] ? result : Readonly<t>) & // re-intersect non-array props for a type like `{ name: string } & string[]`
|
|
166
|
+
_distill<{
|
|
167
|
+
[k in keyof t as k extends keyof unknown[] ? never : k]: t[k];
|
|
168
|
+
}, opts> : never;
|
|
167
169
|
type _distillArray<t extends array, opts extends distill.Options, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, opts, [...prefix, _distill<head, opts>]> : [...prefix, ...distillPostfix<t, opts>];
|
|
168
170
|
type distillPostfix<t extends array, opts extends distill.Options, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, opts, [_distill<last, opts>, ...postfix]> : [...{
|
|
169
171
|
[i in keyof t]: _distill<t[i], opts>;
|
package/out/keywords/builtins.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
4
|
class MergeHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
|
|
7
|
-
export const arkBuiltins =
|
|
7
|
+
export const arkBuiltins = arkModule({
|
|
8
8
|
Key: intrinsic.key,
|
|
9
9
|
Merge
|
|
10
10
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { genericNode, intrinsic, rootNode } from "@ark/schema";
|
|
2
2
|
import { Hkt, liftArray } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
class liftFromHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const liftFrom = genericNode("element")(args => {
|
|
@@ -11,7 +11,7 @@ const liftFrom = genericNode("element")(args => {
|
|
|
11
11
|
.pipe(liftArray)
|
|
12
12
|
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootNode);
|
|
13
13
|
}, liftFromHkt);
|
|
14
|
-
export const arkArray =
|
|
14
|
+
export const arkArray = arkModule({
|
|
15
15
|
root: intrinsic.Array,
|
|
16
16
|
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
const value = rootNode(["string", registry.FileConstructor]);
|
|
5
5
|
const parsedFormDataValue = value.or(value.array());
|
|
6
6
|
const parsed = rootNode({
|
|
@@ -11,7 +11,7 @@ const parsed = rootNode({
|
|
|
11
11
|
value: parsedFormDataValue
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
export const arkFormData =
|
|
14
|
+
export const arkFormData = arkModule({
|
|
15
15
|
root: ["instanceof", FormData],
|
|
16
16
|
value,
|
|
17
17
|
parsed,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const TypedArray =
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
|
+
export const TypedArray = arkModule({
|
|
3
3
|
Int8: ["instanceof", Int8Array],
|
|
4
4
|
Uint8: ["instanceof", Uint8Array],
|
|
5
5
|
Uint8Clamped: ["instanceof", Uint8ClampedArray],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { arkArray } from "./Array.js";
|
|
4
4
|
import { arkFormData } from "./FormData.js";
|
|
5
5
|
import { TypedArray } from "./TypedArray.js";
|
|
@@ -8,7 +8,7 @@ const omittedPrototypes = {
|
|
|
8
8
|
Number: 1,
|
|
9
9
|
String: 1
|
|
10
10
|
};
|
|
11
|
-
export const arkPrototypes =
|
|
11
|
+
export const arkPrototypes = arkModule({
|
|
12
12
|
...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
|
|
13
13
|
Array: arkArray,
|
|
14
14
|
TypedArray,
|
|
@@ -27,6 +27,10 @@ export declare namespace number {
|
|
|
27
27
|
type narrowed = constrain<number, Narrowed>;
|
|
28
28
|
type optional = constrain<number, Optional>;
|
|
29
29
|
type branded<rule> = constrain<number, Branded<rule>>;
|
|
30
|
+
type NaN = branded<"NaN">;
|
|
31
|
+
type Infinity = branded<"Infinity">;
|
|
32
|
+
type NegativeInfinity = branded<"NegativeInfinity">;
|
|
33
|
+
type safe = branded<"safe">;
|
|
30
34
|
type is<constraints extends Constraints> = constrain<number, constraints>;
|
|
31
35
|
type minSchemaToConstraint<schema, rule> = schema extends {
|
|
32
36
|
exclusive: true;
|
|
@@ -41,5 +45,9 @@ export declare namespace number {
|
|
|
41
45
|
root: number;
|
|
42
46
|
epoch: epoch;
|
|
43
47
|
integer: integer;
|
|
48
|
+
safe: safe;
|
|
49
|
+
NaN: NaN;
|
|
50
|
+
Infinity: Infinity;
|
|
51
|
+
NegativeInfinity: NegativeInfinity;
|
|
44
52
|
};
|
|
45
53
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import {
|
|
1
|
+
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { epoch } from "./epoch.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
|
-
export const number =
|
|
5
|
+
export const number = arkModule({
|
|
6
6
|
root: intrinsic.number,
|
|
7
7
|
integer,
|
|
8
|
-
epoch
|
|
8
|
+
epoch,
|
|
9
|
+
safe: rootNode({
|
|
10
|
+
domain: "number",
|
|
11
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
12
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
13
|
+
predicate: {
|
|
14
|
+
predicate: n => !Number.isNaN(n),
|
|
15
|
+
meta: "a safe number"
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
NaN: ["===", Number.NaN],
|
|
19
|
+
Infinity: ["===", Number.POSITIVE_INFINITY],
|
|
20
|
+
NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
|
|
9
21
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z].*$/, "capitalized");
|
|
5
|
-
export const capitalize =
|
|
5
|
+
export const capitalize = arkModule({
|
|
6
6
|
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
2
|
import type { Branded, To, constrain } from "../ast.ts";
|
|
4
3
|
type DayDelimiter = "." | "/" | "-";
|
|
5
4
|
type DayPart = DayPatterns[PartKey];
|
|
@@ -38,9 +37,6 @@ export declare namespace stringDate {
|
|
|
38
37
|
iso: iso.submodule;
|
|
39
38
|
epoch: epoch.submodule;
|
|
40
39
|
};
|
|
41
|
-
type shallowResolutions = {
|
|
42
|
-
[k in keyof $ as `string.date.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
43
|
-
};
|
|
44
40
|
namespace iso {
|
|
45
41
|
type submodule = Submodule<$>;
|
|
46
42
|
type $ = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArkErrors, intrinsic, rootNode } from "@ark/schema";
|
|
2
2
|
import { number } from "../number/number.js";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
5
|
import { regexStringNode } from "./utils.js";
|
|
6
6
|
const dayDelimiterMatcher = /^[./-]$/;
|
|
@@ -63,7 +63,7 @@ const epochroot = integer.root.internal
|
|
|
63
63
|
description: "an integer string representing a safe Unix timestamp"
|
|
64
64
|
})
|
|
65
65
|
.assertHasKind("intersection");
|
|
66
|
-
const epoch =
|
|
66
|
+
const epoch = arkModule({
|
|
67
67
|
root: epochroot,
|
|
68
68
|
parse: rootNode({
|
|
69
69
|
in: epochroot,
|
|
@@ -72,7 +72,7 @@ const epoch = submodule({
|
|
|
72
72
|
})
|
|
73
73
|
});
|
|
74
74
|
const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
|
|
75
|
-
const iso =
|
|
75
|
+
const iso = arkModule({
|
|
76
76
|
root: isoroot,
|
|
77
77
|
parse: rootNode({
|
|
78
78
|
in: isoroot,
|
|
@@ -80,7 +80,7 @@ const iso = submodule({
|
|
|
80
80
|
declaredOut: intrinsic.Date
|
|
81
81
|
})
|
|
82
82
|
});
|
|
83
|
-
export const stringDate =
|
|
83
|
+
export const stringDate = arkModule({
|
|
84
84
|
root: parsableDate,
|
|
85
85
|
parse: rootNode({
|
|
86
86
|
declaredIn: parsableDate,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
2
|
import { wellFormedIntegerMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
5
|
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
6
|
-
export const integer =
|
|
6
|
+
export const integer = arkModule({
|
|
7
7
|
root,
|
|
8
8
|
parse: rootNode({
|
|
9
9
|
in: root,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
2
|
import { regexStringNode } from "./utils.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
4
4
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
@@ -16,7 +16,7 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
16
16
|
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
17
17
|
")(%[0-9a-zA-Z-.:]{1,})?$");
|
|
18
18
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
19
|
-
export const ip =
|
|
19
|
+
export const ip = arkModule({
|
|
20
20
|
root: ["v4 | v6", "@", "an IP address"],
|
|
21
21
|
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
22
|
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
const jsonStringDescription = "a JSON string";
|
|
4
4
|
const isParsableJson = (s) => {
|
|
5
5
|
try {
|
|
@@ -17,7 +17,7 @@ const root = rootNode({
|
|
|
17
17
|
predicate: isParsableJson
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
export const json =
|
|
20
|
+
export const json = arkModule({
|
|
21
21
|
root,
|
|
22
22
|
parse: rootNode({
|
|
23
23
|
in: "string",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
|
|
5
|
-
export const lower =
|
|
5
|
+
export const lower = arkModule({
|
|
6
6
|
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toLowerCase(),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
2
|
import type { Branded, constrain, To } from "../ast.ts";
|
|
4
3
|
declare namespace string {
|
|
5
4
|
type normalized = normalized.NFC;
|
|
@@ -57,9 +56,6 @@ export declare namespace normalize {
|
|
|
57
56
|
NFKC: NFKC.submodule;
|
|
58
57
|
NFKD: NFKD.submodule;
|
|
59
58
|
};
|
|
60
|
-
type shallowResolutions = {
|
|
61
|
-
[k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
62
|
-
};
|
|
63
59
|
namespace NFC {
|
|
64
60
|
type submodule = Submodule<$>;
|
|
65
61
|
type $ = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
2
|
import { flatMorph } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
5
|
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
6
|
form,
|
|
@@ -18,23 +18,23 @@ const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
|
18
18
|
declaredOut: preformattedNodes[form]
|
|
19
19
|
})
|
|
20
20
|
]);
|
|
21
|
-
export const NFC =
|
|
21
|
+
export const NFC = arkModule({
|
|
22
22
|
root: normalizeNodes.NFC,
|
|
23
23
|
preformatted: preformattedNodes.NFC
|
|
24
24
|
});
|
|
25
|
-
export const NFD =
|
|
25
|
+
export const NFD = arkModule({
|
|
26
26
|
root: normalizeNodes.NFD,
|
|
27
27
|
preformatted: preformattedNodes.NFD
|
|
28
28
|
});
|
|
29
|
-
export const NFKC =
|
|
29
|
+
export const NFKC = arkModule({
|
|
30
30
|
root: normalizeNodes.NFKC,
|
|
31
31
|
preformatted: preformattedNodes.NFKC
|
|
32
32
|
});
|
|
33
|
-
export const NFKD =
|
|
33
|
+
export const NFKD = arkModule({
|
|
34
34
|
root: normalizeNodes.NFKD,
|
|
35
35
|
preformatted: preformattedNodes.NFKD
|
|
36
36
|
});
|
|
37
|
-
export const normalize =
|
|
37
|
+
export const normalize = arkModule({
|
|
38
38
|
root: "NFC",
|
|
39
39
|
NFC,
|
|
40
40
|
NFD,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
2
|
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
5
|
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
-
export const numeric =
|
|
6
|
+
export const numeric = arkModule({
|
|
7
7
|
root,
|
|
8
8
|
parse: rootNode({
|
|
9
9
|
in: root,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
2
|
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
|
|
4
3
|
import { alpha } from "./alpha.ts";
|
|
5
4
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
@@ -99,13 +98,11 @@ export declare namespace string {
|
|
|
99
98
|
ip: ip.submodule;
|
|
100
99
|
json: stringJson.submodule;
|
|
101
100
|
date: stringDate.submodule;
|
|
101
|
+
url: url.submodule;
|
|
102
102
|
trim: trim.submodule;
|
|
103
103
|
normalize: normalize.submodule;
|
|
104
104
|
capitalize: capitalize.submodule;
|
|
105
105
|
lower: lower.submodule;
|
|
106
106
|
upper: upper.submodule;
|
|
107
107
|
};
|
|
108
|
-
type shallowResolutions = {
|
|
109
|
-
[k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
110
|
-
};
|
|
111
108
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { alpha } from "./alpha.js";
|
|
4
4
|
import { alphanumeric } from "./alphanumeric.js";
|
|
5
5
|
import { capitalize } from "./capitalize.js";
|
|
@@ -18,7 +18,7 @@ import { trim } from "./trim.js";
|
|
|
18
18
|
import { upper } from "./upper.js";
|
|
19
19
|
import { url } from "./url.js";
|
|
20
20
|
import { uuid } from "./uuid.js";
|
|
21
|
-
export const string =
|
|
21
|
+
export const string = arkModule({
|
|
22
22
|
root: intrinsic.string,
|
|
23
23
|
numeric,
|
|
24
24
|
integer,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(
|
|
5
5
|
// no leading or trailing whitespace
|
|
6
6
|
/^\S.*\S$|^\S?$/, "trimmed");
|
|
7
|
-
export const trim =
|
|
7
|
+
export const trim = arkModule({
|
|
8
8
|
root: rootNode({
|
|
9
9
|
in: "string",
|
|
10
10
|
morphs: (s) => s.trim(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper =
|
|
5
|
+
export const upper = arkModule({
|
|
6
6
|
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toUpperCase(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
const isParsableUrl = (s) => {
|
|
4
4
|
if (URL.canParse)
|
|
5
5
|
return URL.canParse(s);
|
|
@@ -19,7 +19,7 @@ const root = rootNode({
|
|
|
19
19
|
predicate: isParsableUrl
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
export const url =
|
|
22
|
+
export const url = arkModule({
|
|
23
23
|
root,
|
|
24
24
|
parse: rootNode({
|
|
25
25
|
declaredIn: root,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
2
|
import { regexStringNode } from "./utils.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
4
|
-
export const uuid =
|
|
4
|
+
export const uuid = arkModule({
|
|
5
5
|
// the meta tuple expression ensures the error message does not delegate
|
|
6
6
|
// to the individual branches, which are too detailed
|
|
7
7
|
root: ["versioned | nil | max", "@", "a UUID"],
|
package/out/keywords/ts.d.ts
CHANGED
|
@@ -19,6 +19,17 @@ export declare namespace arkTsKeywords {
|
|
|
19
19
|
undefined: undefined;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
export declare const unknown: Module<{
|
|
23
|
+
root: unknown;
|
|
24
|
+
any: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
export declare namespace unknown {
|
|
27
|
+
type submodule = Submodule<$>;
|
|
28
|
+
type $ = {
|
|
29
|
+
root: unknown;
|
|
30
|
+
any: any;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
22
33
|
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
23
34
|
body: Record<this[0], this[1]>;
|
|
24
35
|
}
|
package/out/keywords/ts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
4
|
-
export const arkTsKeywords =
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
|
+
export const arkTsKeywords = arkModule({
|
|
5
5
|
bigint: intrinsic.bigint,
|
|
6
6
|
boolean: intrinsic.boolean,
|
|
7
7
|
false: intrinsic.false,
|
|
@@ -15,6 +15,10 @@ export const arkTsKeywords = submodule({
|
|
|
15
15
|
unknown: intrinsic.unknown,
|
|
16
16
|
undefined: intrinsic.undefined
|
|
17
17
|
});
|
|
18
|
+
export const unknown = arkModule({
|
|
19
|
+
root: intrinsic.unknown,
|
|
20
|
+
any: intrinsic.unknown
|
|
21
|
+
});
|
|
18
22
|
class RecordHkt extends Hkt {
|
|
19
23
|
}
|
|
20
24
|
const Record = genericNode(["K", intrinsic.key], "V")(args => ({
|
|
@@ -42,7 +46,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
|
|
|
42
46
|
class ExtractHkt extends Hkt {
|
|
43
47
|
}
|
|
44
48
|
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
45
|
-
export const arkTsGenerics =
|
|
49
|
+
export const arkTsGenerics = arkModule({
|
|
46
50
|
Record,
|
|
47
51
|
Pick,
|
|
48
52
|
Omit,
|
package/out/keywords/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const arkModule: import("../scope.ts").ModuleParser;
|
package/out/keywords/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { module } from "../scope.js";
|
|
2
|
-
export const
|
|
2
|
+
export const arkModule = module;
|
package/out/methods/base.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
3
|
import type { inferIntersection } from "../intersect.ts";
|
|
4
|
+
import type { type } from "../keywords/ark.ts";
|
|
4
5
|
import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
|
|
5
6
|
import type { Scope } from "../scope.ts";
|
|
6
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
7
|
import type { ArrayType } from "./array.ts";
|
|
8
8
|
import type { instantiateType } from "./instantiate.ts";
|
|
9
9
|
/** @ts-ignore cast variance */
|
|
10
10
|
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
|
|
11
11
|
t: t;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
inferBrandableIn: distill.brandable.In<t>;
|
|
13
|
+
inferBrandableOut: distill.brandable.Out<t>;
|
|
14
|
+
inferIntrospectableOut: distill.introspectable.Out<t>;
|
|
15
15
|
infer: distill.Out<t>;
|
|
16
16
|
inferIn: distill.In<t>;
|
|
17
17
|
[inferred]: t;
|
|
@@ -27,23 +27,23 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
27
27
|
configure(meta: MetaSchema): this;
|
|
28
28
|
describe(description: string): this;
|
|
29
29
|
optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
|
|
30
|
-
default<value extends this["infer"], r = (In?: this["
|
|
30
|
+
default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
|
|
31
31
|
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
32
32
|
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
33
33
|
from(literal: this["inferIn"]): this["infer"];
|
|
34
34
|
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
|
|
35
|
-
get in(): instantiateType<this["
|
|
36
|
-
get out(): instantiateType<this["
|
|
37
|
-
intersect<const def, r =
|
|
38
|
-
and<const def, r =
|
|
39
|
-
or<const def, r =
|
|
35
|
+
get in(): instantiateType<this["inferBrandableIn"], $>;
|
|
36
|
+
get out(): instantiateType<this["inferIntrospectableOut"], $>;
|
|
37
|
+
intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
|
|
38
|
+
and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
|
|
39
|
+
or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
|
|
40
40
|
array(): ArrayType<t[], $>;
|
|
41
41
|
pipe: ChainedPipes<t, $>;
|
|
42
|
-
equals<def>(def:
|
|
43
|
-
extract<def>(r:
|
|
44
|
-
exclude<def>(r:
|
|
45
|
-
extends<def>(other:
|
|
46
|
-
overlaps<def>(r:
|
|
42
|
+
equals<def>(def: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
|
|
43
|
+
extract<def>(r: type.validate<def, $>): instantiateType<Extract<t, type.infer<def, $>>, $>;
|
|
44
|
+
exclude<def>(r: type.validate<def, $>): instantiateType<Exclude<t, type.infer<def, $>>, $>;
|
|
45
|
+
extends<def>(other: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
|
|
46
|
+
overlaps<def>(r: type.validate<def, $>): boolean;
|
|
47
47
|
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
|
|
48
48
|
/** @deprecated */
|
|
49
49
|
apply: Function["apply"];
|
package/out/methods/morph.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
2
|
import type { inferPipe } from "../intersect.ts";
|
|
3
|
+
import type { type } from "../keywords/ark.ts";
|
|
3
4
|
import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
5
|
import type { BaseType } from "./base.ts";
|
|
6
6
|
/** @ts-ignore cast variance */
|
|
7
7
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
8
|
-
to<const def, r =
|
|
8
|
+
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
|
|
9
9
|
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
10
10
|
narrowed
|
|
11
|
-
] extends [never] ? applyConstraintSchema<this["
|
|
11
|
+
] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferIntrospectableOut"] extends this["inferBrandableOut"] ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as MorphType };
|
package/out/methods/object.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { array, ErrorType, merge } from "@ark/util";
|
|
2
2
|
import type { arkKeyOf, getArkKey, toArkKey } from "../keys.ts";
|
|
3
3
|
import type { type } from "../keywords/ark.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
4
|
import type { ArrayType } from "./array.ts";
|
|
6
5
|
import type { instantiateType } from "./instantiate.ts";
|
|
7
6
|
import type { ValidatorType } from "./validator.ts";
|
|
@@ -22,7 +21,7 @@ interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $
|
|
|
22
21
|
omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
23
22
|
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
|
|
24
23
|
}, $>;
|
|
25
|
-
merge<const def, r =
|
|
24
|
+
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
|
|
26
25
|
required(): Type<{
|
|
27
26
|
[k in keyof t]-?: t[k];
|
|
28
27
|
}, $>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage } from "@ark/util";
|
|
3
|
-
import type {
|
|
3
|
+
import type { type } from "../../keywords/ark.ts";
|
|
4
4
|
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
5
5
|
import type { inferAstOut } from "./infer.ts";
|
|
6
6
|
import type { astToString } from "./utils.ts";
|
|
7
7
|
import type { validateAst } from "./validate.ts";
|
|
8
|
-
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e :
|
|
8
|
+
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { GenericAst } from "@ark/schema";
|
|
2
2
|
import type { Hkt, array } from "@ark/util";
|
|
3
3
|
import type { inferIntersection } from "../../intersect.ts";
|
|
4
|
+
import type { type } from "../../keywords/ark.ts";
|
|
4
5
|
import type { Default, LimitLiteral, applyConstraintSchema, distill, normalizeLimit } from "../../keywords/ast.ts";
|
|
5
6
|
import type { Date } from "../../keywords/constructors/Date.ts";
|
|
6
7
|
import type { UnparsedScope } from "../../scope.ts";
|
|
7
|
-
import type { inferAmbient } from "../../type.ts";
|
|
8
8
|
import type { inferDefinition } from "../definition.ts";
|
|
9
9
|
import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
|
|
10
10
|
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
@@ -26,7 +26,7 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
|
|
|
26
26
|
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
27
27
|
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
28
28
|
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
29
|
-
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ?
|
|
29
|
+
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferExpression<ast[1], $, args> : never : never;
|
|
30
30
|
export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
31
31
|
rule: normalizeLimit<limit>;
|
|
32
32
|
exclusive: comparator extends ">" | "<" ? true : false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isKeyOf } from "@ark/util";
|
|
1
|
+
import { isKeyOf, throwParseError } from "@ark/util";
|
|
2
2
|
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
3
3
|
export const parseEnclosed = (s, enclosing) => {
|
|
4
4
|
const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
|
|
@@ -7,8 +7,12 @@ export const parseEnclosed = (s, enclosing) => {
|
|
|
7
7
|
// Shift the scanner one additional time for the second enclosing token
|
|
8
8
|
s.scanner.shift();
|
|
9
9
|
if (enclosing === "/") {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
try {
|
|
11
|
+
new RegExp(enclosed);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
throwParseError(String(e));
|
|
15
|
+
}
|
|
12
16
|
s.root = s.ctx.$.node("intersection", {
|
|
13
17
|
domain: "string",
|
|
14
18
|
pattern: enclosed
|
package/out/parser/tuple.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
|
|
2
|
-
import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
2
|
+
import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
3
|
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
|
|
4
4
|
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
|
|
5
5
|
export const parseTupleLiteral = (def, ctx) => {
|
|
@@ -34,10 +34,15 @@ export const parseTupleLiteral = (def, ctx) => {
|
|
|
34
34
|
sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return ctx.$.internal.rootNode(sequences.map(sequence => (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
return ctx.$.internal.rootNode(sequences.map(sequence => isEmptyObject(sequence) ?
|
|
38
|
+
{
|
|
39
|
+
proto: Array,
|
|
40
|
+
exactLength: 0
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
proto: Array,
|
|
44
|
+
sequence
|
|
45
|
+
}));
|
|
41
46
|
};
|
|
42
47
|
const appendElement = (base, kind, element) => {
|
|
43
48
|
switch (kind) {
|
package/out/scope.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
72
72
|
preparseRoot(def: unknown): unknown;
|
|
73
73
|
get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
|
|
74
74
|
parse(def: unknown, ctx: ParseContext): BaseRoot;
|
|
75
|
+
private _parse;
|
|
75
76
|
parseString(def: string, ctx: ParseContext): BaseRoot;
|
|
76
77
|
parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;
|
|
77
78
|
unit: UnitTypeParser<$>;
|
package/out/scope.js
CHANGED
|
@@ -47,10 +47,13 @@ export class InternalScope extends BaseScope {
|
|
|
47
47
|
return;
|
|
48
48
|
return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
|
|
49
49
|
k,
|
|
50
|
-
|
|
50
|
+
this.bindReference(v)
|
|
51
51
|
]));
|
|
52
52
|
}
|
|
53
53
|
parse(def, ctx) {
|
|
54
|
+
return this.bindReference(this._parse(def, ctx));
|
|
55
|
+
}
|
|
56
|
+
_parse(def, ctx) {
|
|
54
57
|
if (typeof def === "string") {
|
|
55
58
|
if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
|
|
56
59
|
// we can only rely on the cache if there are no contextual
|
|
@@ -79,7 +82,7 @@ export class InternalScope extends BaseScope {
|
|
|
79
82
|
return node;
|
|
80
83
|
}
|
|
81
84
|
parseRoot = (def, opts = {}) => {
|
|
82
|
-
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this }))
|
|
85
|
+
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this }));
|
|
83
86
|
return node;
|
|
84
87
|
};
|
|
85
88
|
unit = value => this.units([value]);
|
package/out/type.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
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
3
|
import { type Generic, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.ts";
|
|
4
|
-
import type { Ark, ark } from "./keywords/ark.ts";
|
|
4
|
+
import type { Ark, ark, type } from "./keywords/ark.ts";
|
|
5
5
|
import type { distill } from "./keywords/ast.ts";
|
|
6
6
|
import type { BaseType } from "./methods/base.ts";
|
|
7
7
|
import type { instantiateType } from "./methods/instantiate.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { validateDeclared, validateDefinition } from "./parser/definition.ts";
|
|
9
9
|
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";
|
|
10
10
|
import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.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<
|
|
14
|
+
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
|
|
15
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<
|
|
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] : [type.validate<rest[0], $>] : []): r;
|
|
17
|
+
$: Scope<$>;
|
|
17
18
|
raw(def: unknown): BaseType<any, $>;
|
|
18
19
|
errors: typeof ArkErrors;
|
|
19
20
|
module: ModuleParser;
|
|
@@ -31,11 +32,7 @@ export type DeclarationParser<$> = <preinferred>() => {
|
|
|
31
32
|
};
|
|
32
33
|
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
|
|
33
34
|
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
|
|
34
|
-
export type DefinitionParser<$> = <def>(def:
|
|
35
|
-
export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $, bindThis<def>>;
|
|
36
|
-
export type inferTypeRoot<def, $> = inferDefinition<def, $, bindThis<def>>;
|
|
37
|
-
export type validateAmbient<def> = validateTypeRoot<def, {}>;
|
|
38
|
-
export type inferAmbient<def> = inferTypeRoot<def, {}>;
|
|
35
|
+
export type DefinitionParser<$> = <def>(def: type.validate<def, $>) => def;
|
|
39
36
|
export type Type<t = unknown, $ = {}> = instantiateType<t, $>;
|
|
40
37
|
export declare namespace Type {
|
|
41
38
|
type Any<t = any> = BaseType<t, any>;
|
package/out/type.js
CHANGED
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.6",
|
|
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/
|
|
38
|
-
"@ark/
|
|
37
|
+
"@ark/util": "0.8.0",
|
|
38
|
+
"@ark/schema": "0.8.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|