arktype 2.0.0-rc.5 → 2.0.0-rc.7
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 +39 -42
- package/out/generic.js +3 -5
- package/out/index.d.ts +2 -2
- package/out/intersect.d.ts +2 -4
- package/out/keys.d.ts +5 -3
- package/out/keywords/ark.d.ts +8 -6
- package/out/keywords/ark.js +4 -2
- package/out/keywords/ast.d.ts +33 -21
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.js +5 -5
- package/out/keywords/constructors/FormData.js +7 -7
- 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/number/epoch.js +2 -2
- package/out/keywords/number/integer.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 +4 -4
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +0 -4
- package/out/keywords/string/date.js +9 -9
- package/out/keywords/string/integer.js +4 -4
- package/out/keywords/string/ip.js +4 -4
- package/out/keywords/string/json.js +5 -5
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +0 -4
- package/out/keywords/string/normalize.js +9 -9
- package/out/keywords/string/numeric.js +4 -4
- package/out/keywords/string/string.d.ts +2 -5
- package/out/keywords/string/string.js +2 -2
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.js +6 -6
- 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 +18 -15
- package/out/methods/morph.d.ts +3 -3
- package/out/methods/object.d.ts +32 -8
- package/out/parser/definition.d.ts +2 -3
- package/out/parser/objectLiteral.d.ts +4 -5
- package/out/parser/objectLiteral.js +4 -4
- package/out/parser/semantic/default.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +3 -2
- package/out/parser/string/reduce/dynamic.d.ts +3 -4
- package/out/parser/string/reduce/dynamic.js +3 -2
- package/out/parser/string/shift/operand/enclosed.js +7 -3
- package/out/parser/string/shift/operand/unenclosed.js +6 -2
- package/out/parser/tuple.d.ts +5 -6
- package/out/parser/tuple.js +29 -20
- package/out/scope.d.ts +21 -23
- package/out/scope.js +33 -26
- package/out/type.d.ts +12 -12
- package/out/type.js +9 -9
- package/package.json +3 -3
package/out/generic.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
1
|
+
import { GenericRoot, type arkKind, type BaseParseContext, 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";
|
|
6
7
|
import type { state, StaticState } from "./parser/string/reduce/static.ts";
|
|
7
|
-
import { Scanner } from "./parser/string/shift/scanner.ts";
|
|
8
|
+
import type { Scanner } from "./parser/string/shift/scanner.ts";
|
|
8
9
|
import { parseUntilFinalizer } from "./parser/string/string.ts";
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
10
|
+
import type { Scope } from "./scope.ts";
|
|
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], $>;
|
|
@@ -126,16 +127,15 @@ export type GenericDeclaration<name extends string = string, params extends Para
|
|
|
126
127
|
export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
|
|
127
128
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
128
129
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
129
|
-
export declare const parseGenericParams: (def: string, ctx: ParseContext) => array<GenericParamDef>;
|
|
130
130
|
export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
|
|
131
131
|
], $>;
|
|
132
132
|
type ParamsTerminator = WhiteSpaceToken | ",";
|
|
133
|
-
declare const
|
|
133
|
+
export declare const parseGenericParamName: (scanner: Scanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
134
134
|
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<Scanner.skipWhitespace<unscanned>, "", result, $>;
|
|
135
135
|
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhiteSpaceToken ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
|
|
136
136
|
declare const extendsToken = "extends ";
|
|
137
137
|
type extendsToken = typeof extendsToken;
|
|
138
|
-
declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx:
|
|
138
|
+
declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
139
139
|
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = Scanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
|
|
140
140
|
...result,
|
|
141
141
|
[name, inferAstRoot<finalArgState["root"], $, {}>]
|
|
@@ -143,17 +143,14 @@ type _parseOptionalConstraint<unscanned extends string, name extends string, res
|
|
|
143
143
|
...result,
|
|
144
144
|
[name, unknown]
|
|
145
145
|
], $>;
|
|
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;
|
|
146
|
+
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
|
|
150
147
|
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
|
|
151
148
|
...{
|
|
152
149
|
[i in keyof defs]: genericParamDefToAst<defs[i], $>;
|
|
153
150
|
}
|
|
154
151
|
];
|
|
155
152
|
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
156
|
-
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name,
|
|
153
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
157
154
|
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
158
155
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
159
156
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
package/out/generic.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { GenericRoot } from "@ark/schema";
|
|
2
2
|
import { throwParseError } from "@ark/util";
|
|
3
3
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
4
|
-
import { Scanner } from "./parser/string/shift/scanner.js";
|
|
5
4
|
import { parseUntilFinalizer } from "./parser/string/string.js";
|
|
6
5
|
export const Generic = GenericRoot;
|
|
7
6
|
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
8
|
-
export const
|
|
9
|
-
const parseName = (scanner, result, ctx) => {
|
|
7
|
+
export const parseGenericParamName = (scanner, result, ctx) => {
|
|
10
8
|
scanner.shiftUntilNonWhitespace();
|
|
11
9
|
const name = scanner.shiftUntilNextTerminator();
|
|
12
10
|
if (name === "") {
|
|
@@ -30,9 +28,9 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
|
30
28
|
if (scanner.lookahead === ",")
|
|
31
29
|
scanner.shift();
|
|
32
30
|
result.push(name);
|
|
33
|
-
return
|
|
31
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
34
32
|
}
|
|
35
33
|
const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
|
|
36
34
|
result.push([name, s.root]);
|
|
37
|
-
return
|
|
35
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
38
36
|
};
|
package/out/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { Hkt, inferred } from "@ark/util";
|
|
|
3
3
|
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
|
-
export { module, scope, type Scope
|
|
7
|
-
export { Type
|
|
6
|
+
export { module, scope, type Scope } from "./scope.ts";
|
|
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/keys.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export type toArkKey<o, k extends keyof o> = k extends number ? [
|
|
|
5
5
|
o,
|
|
6
6
|
number
|
|
7
7
|
] extends [array, k] ? NonNegativeIntegerLiteral : `${k}` : k;
|
|
8
|
-
export type arkKeyOf<o> =
|
|
8
|
+
export type arkKeyOf<o> = [
|
|
9
|
+
o
|
|
10
|
+
] extends [array] ? (number extends o["length"] ? NonNegativeIntegerLiteral : never) | {
|
|
9
11
|
[k in keyof o]-?: k extends `${infer index extends number}` ? index | k : never;
|
|
10
12
|
}[keyof o & `${number}`] : {
|
|
11
|
-
[k in keyof o]
|
|
13
|
+
[k in keyof o]-?: k extends number ? k | `${k}` : k;
|
|
12
14
|
}[keyof o];
|
|
13
|
-
export type
|
|
15
|
+
export type arkGet<o, k extends arkKeyOf<o>> = o[Extract<k extends NonNegativeIntegerLiteral ? number : k, keyof o>];
|
|
14
16
|
export type TypeKey = termOrType<Key>;
|
|
15
17
|
export type typeKeyToString<k extends TypeKey> = typeToString<k extends type.cast<infer t> ? t : k>;
|
|
16
18
|
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}`;
|
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, SchemaParser, 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,9 +48,10 @@ 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<{}>;
|
|
55
|
+
export declare const schema: SchemaParser<{}>;
|
|
54
56
|
export declare const define: DefinitionParser<{}>;
|
|
55
57
|
export declare const declare: DeclarationParser<{}>;
|
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,10 +15,12 @@ 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;
|
|
22
23
|
export const generic = ambient.generic;
|
|
24
|
+
export const schema = ambient.schema;
|
|
23
25
|
export const define = ambient.define;
|
|
24
26
|
export const declare = ambient.declare;
|
package/out/keywords/ast.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type conform, type equals, type leftIfEqual, type Primitive, type show } from "@ark/util";
|
|
2
|
+
import { type anyOrNever, type array, type conform, type equals, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util";
|
|
3
3
|
import type { inferPipe } from "../intersect.ts";
|
|
4
4
|
import type { Type } from "../type.ts";
|
|
5
5
|
import type { type } from "./ark.ts";
|
|
@@ -71,12 +71,20 @@ export type parseConstraints<t> = t extends constrain<infer base, infer constrai
|
|
|
71
71
|
}> extends true ? [
|
|
72
72
|
string,
|
|
73
73
|
constraints
|
|
74
|
-
] : equals<t,
|
|
74
|
+
] : equals<t, bigint & {
|
|
75
75
|
[constrained]: constraints;
|
|
76
76
|
}> extends true ? [
|
|
77
|
-
|
|
77
|
+
bigint,
|
|
78
78
|
constraints
|
|
79
|
-
] :
|
|
79
|
+
] : equals<t, symbol & {
|
|
80
|
+
[constrained]: constraints;
|
|
81
|
+
}> extends true ? [
|
|
82
|
+
symbol,
|
|
83
|
+
constraints
|
|
84
|
+
] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [
|
|
85
|
+
arkPrototypes.instanceOf<kind>,
|
|
86
|
+
constraints
|
|
87
|
+
] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null;
|
|
80
88
|
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
81
89
|
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
82
90
|
exclusive: true;
|
|
@@ -144,32 +152,36 @@ export type includesMorphs<t> = [
|
|
|
144
152
|
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
145
153
|
infer base,
|
|
146
154
|
infer constraints extends Constraints
|
|
147
|
-
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> :
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
[k in keyof t as k extends defaultedKeyOf<t> | metaOptionalKey<t> ? never : k]: _distill<t[k], opts>;
|
|
155
|
+
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends MorphAst<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends DefaultedAst<infer t> ? _distill<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
|
|
156
|
+
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
|
|
157
|
+
[k in keyof o as k extends optionalInputKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
151
158
|
} & {
|
|
152
|
-
[k in
|
|
159
|
+
[k in optionalInputKeyOf<o>]?: _distill<o[k], opts>;
|
|
153
160
|
}> : show<{
|
|
154
|
-
[k in keyof
|
|
161
|
+
[k in keyof o as k extends metaOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
155
162
|
} & {
|
|
156
|
-
[k in keyof
|
|
157
|
-
}
|
|
158
|
-
type
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
type
|
|
162
|
-
[k in keyof o]: o[k] extends
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
[k in keyof o as k extends metaOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
|
|
164
|
+
}>;
|
|
165
|
+
type distillUnbrandedIo<t extends MorphAst, i, o extends Out, opts extends distill.Options> = t extends (MorphAst<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends MorphAst<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends MorphAst<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
|
|
166
|
+
type distillIo<i, o extends Out, opts extends distill.Options> = 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;
|
|
167
|
+
type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
|
|
168
|
+
type metaDefaultedKeyOf<o> = {
|
|
169
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
|
|
170
|
+
}[keyof o];
|
|
171
|
+
type metaOptionalKeyOf<o> = {
|
|
172
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
|
|
165
173
|
}[keyof o];
|
|
166
|
-
type distillArray<t extends array, opts extends distill.Options
|
|
174
|
+
type distillArray<t extends array, opts extends distill.Options> = _distillArray<[...t], opts, []> extends infer result ? distillNonArraykeys<t, t extends unknown[] ? result : Readonly<t>, opts> : never;
|
|
175
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
|
|
176
|
+
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
|
|
177
|
+
}, opts>;
|
|
167
178
|
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
179
|
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
180
|
[i in keyof t]: _distill<t[i], opts>;
|
|
170
181
|
}, ...postfix];
|
|
182
|
+
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
171
183
|
/** Objects we don't want to expand during inference like Date or Promise */
|
|
172
|
-
type
|
|
184
|
+
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
173
185
|
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
174
186
|
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
175
187
|
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distill.brandable.In<t>) => Out<out> : never, tail> : t;
|
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,17 +1,17 @@
|
|
|
1
|
-
import { genericNode, intrinsic,
|
|
1
|
+
import { genericNode, intrinsic, rootSchema } 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 => {
|
|
7
7
|
const nonArrayElement = args.element.exclude(intrinsic.Array);
|
|
8
8
|
const lifted = nonArrayElement.array();
|
|
9
9
|
return nonArrayElement
|
|
10
|
-
.
|
|
10
|
+
.rawOr(lifted)
|
|
11
11
|
.pipe(liftArray)
|
|
12
|
-
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted),
|
|
12
|
+
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootSchema);
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
4
|
-
const value =
|
|
5
|
-
const parsedFormDataValue = value.
|
|
6
|
-
const parsed =
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
|
+
const value = rootSchema(["string", registry.FileConstructor]);
|
|
5
|
+
const parsedFormDataValue = value.rawOr(value.array());
|
|
6
|
+
const parsed = rootSchema({
|
|
7
7
|
meta: "an object representing parsed form data",
|
|
8
8
|
domain: "object",
|
|
9
9
|
index: {
|
|
@@ -11,11 +11,11 @@ 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,
|
|
18
|
-
parse:
|
|
18
|
+
parse: rootSchema({
|
|
19
19
|
in: FormData,
|
|
20
20
|
morphs: (data) => {
|
|
21
21
|
const result = {};
|
|
@@ -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],
|
|
@@ -26,6 +26,5 @@ export declare namespace arkPrototypes {
|
|
|
26
26
|
interface instances extends ecmascript, platform {
|
|
27
27
|
}
|
|
28
28
|
type instanceOf<name extends keyof instances = keyof instances> = instances[name];
|
|
29
|
-
type instanceOfExcluding<name extends keyof instances = keyof instances> = instances[Exclude<keyof instances, name>];
|
|
30
29
|
}
|
|
31
30
|
export {};
|
|
@@ -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,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
/**
|
|
3
3
|
* As per the ECMA-262 specification:
|
|
4
4
|
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
5
5
|
*
|
|
6
6
|
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
7
7
|
*/
|
|
8
|
-
export const epoch =
|
|
8
|
+
export const epoch = rootSchema({
|
|
9
9
|
domain: {
|
|
10
10
|
domain: "number",
|
|
11
11
|
meta: "a number representing a Unix timestamp"
|
|
@@ -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, rootSchema } 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: rootSchema({
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
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 =
|
|
6
|
-
root:
|
|
5
|
+
export const capitalize = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isLuhnNumber.js
|
|
3
3
|
export const isLuhnValid = (creditCardInput) => {
|
|
4
4
|
const sanitized = creditCardInput.replace(/[- ]+/g, "");
|
|
@@ -24,7 +24,7 @@ export const isLuhnValid = (creditCardInput) => {
|
|
|
24
24
|
};
|
|
25
25
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
|
|
26
26
|
const creditCardMatcher = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
|
|
27
|
-
export const creditCard =
|
|
27
|
+
export const creditCard = rootSchema({
|
|
28
28
|
domain: "string",
|
|
29
29
|
pattern: {
|
|
30
30
|
meta: "a credit card number",
|
|
@@ -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 $ = {
|