arktype 2.0.0-rc.1 → 2.0.0-rc.10
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/config.d.ts +1 -1
- package/out/generic.d.ts +47 -48
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +32 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/inference.d.ts +227 -0
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/{ark.js → keywords.js} +10 -8
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +32 -6
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +1 -1
- package/out/keywords/string/alphanumeric.d.ts +1 -1
- package/out/keywords/string/capitalize.d.ts +2 -2
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +1 -1
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +4 -8
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +1 -1
- package/out/keywords/string/email.d.ts +1 -1
- package/out/keywords/string/integer.d.ts +2 -2
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +2 -2
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +3 -2
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +2 -2
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +23 -27
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +2 -2
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +39 -42
- package/out/keywords/string/string.js +3 -3
- package/out/keywords/string/trim.d.ts +2 -2
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +2 -2
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +2 -2
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +11 -11
- package/out/keywords/string/uuid.js +3 -3
- 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/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +96 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/instantiate.d.ts +5 -4
- package/out/methods/morph.d.ts +12 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/methods/object.d.ts +81 -0
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/{semantic → ast}/infer.d.ts +11 -11
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +6 -6
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +11 -37
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +1 -6
- package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
- package/out/parser/{string/shift → shift}/scanner.js +5 -3
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +54 -43
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +32 -39
- package/out/scope.js +43 -35
- package/out/type.d.ts +24 -21
- package/out/type.js +14 -10
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/object.d.ts +0 -33
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/keywords/{ast.js → inference.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/{subtypes → methods}/validator.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{semantic → ast}/validate.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
package/out/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkSchemaRegistry } from "@ark/schema";
|
|
2
|
-
import type { Ark } from "./keywords/
|
|
2
|
+
import type { Ark } from "./keywords/keywords.ts";
|
|
3
3
|
import type { exportScope } from "./module.ts";
|
|
4
4
|
export * from "@ark/schema/config";
|
|
5
5
|
export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
|
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/keywords.ts";
|
|
4
|
+
import type { inferAstRoot } from "./parser/ast/infer.ts";
|
|
5
|
+
import type { validateAst } from "./parser/ast/validate.ts";
|
|
3
6
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import type { ParseContext, Scope } from "./scope.ts";
|
|
10
|
-
import type { inferTypeRoot, Type, validateTypeRoot } from "./type.ts";
|
|
7
|
+
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
+
import type { Scanner } from "./parser/shift/scanner.ts";
|
|
9
|
+
import { parseUntilFinalizer } from "./parser/string.ts";
|
|
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
|
-
validateGenericArg<a, params[0], args$>,
|
|
20
|
-
validateGenericArg<b, params[1], args$>
|
|
19
|
+
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
20
|
+
type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
|
|
21
|
+
type.validate<b, args$> & 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,16 +143,15 @@ 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
|
-
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params:
|
|
152
|
+
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
153
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
154
|
+
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
156
155
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
157
156
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
|
158
157
|
<hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
|
package/out/generic.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { GenericRoot } from "@ark/schema";
|
|
2
2
|
import { throwParseError } from "@ark/util";
|
|
3
|
-
import { DynamicState } from "./parser/
|
|
4
|
-
import {
|
|
5
|
-
import { parseUntilFinalizer } from "./parser/string/string.js";
|
|
3
|
+
import { DynamicState } from "./parser/reduce/dynamic.js";
|
|
4
|
+
import { parseUntilFinalizer } from "./parser/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
|
-
const s = parseUntilFinalizer(new DynamicState(scanner, ctx
|
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.ts";
|
|
4
|
-
export {
|
|
4
|
+
export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.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/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.js";
|
|
4
|
-
export {
|
|
4
|
+
export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
|
|
5
5
|
export { Module } from "./module.js";
|
|
6
6
|
export { module, scope } from "./scope.js";
|
|
7
7
|
export { Type } from "./type.js";
|
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 { Hkt, liftArray, type Digit } from "@ark/util";
|
|
2
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { To } from "../
|
|
3
|
+
import type { To } from "../inference.ts";
|
|
4
4
|
declare class liftFromHkt extends Hkt<[element: unknown]> {
|
|
5
5
|
body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
|
|
6
6
|
}
|
|
@@ -10,7 +10,7 @@ export declare namespace arkArray {
|
|
|
10
10
|
type module = Module<submodule>;
|
|
11
11
|
type submodule = Submodule<$>;
|
|
12
12
|
type $ = {
|
|
13
|
-
|
|
13
|
+
root: unknown[];
|
|
14
14
|
readonly: readonly unknown[];
|
|
15
15
|
index: NonNegativeIntegerString;
|
|
16
16
|
liftFrom: typeof liftFrom.t;
|
|
@@ -1,19 +1,19 @@
|
|
|
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 =
|
|
15
|
-
|
|
16
|
-
readonly: "
|
|
14
|
+
export const arkArray = arkModule({
|
|
15
|
+
root: intrinsic.Array,
|
|
16
|
+
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
18
18
|
liftFrom
|
|
19
19
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
|
|
2
|
+
export type AtOrAfter<rule> = {
|
|
3
|
+
atOrAfter: constraint<rule>;
|
|
4
|
+
};
|
|
5
|
+
export type AtOrBefore<rule> = {
|
|
6
|
+
atOrBefore: constraint<rule>;
|
|
7
|
+
};
|
|
8
|
+
export type After<rule> = {
|
|
9
|
+
after: constraint<rule>;
|
|
10
|
+
};
|
|
11
|
+
export type Before<rule> = {
|
|
12
|
+
before: constraint<rule>;
|
|
13
|
+
};
|
|
14
|
+
export declare namespace Date {
|
|
15
|
+
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
16
|
+
type after<rule> = constrain<Date, After<rule>>;
|
|
17
|
+
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
18
|
+
type before<rule> = constrain<Date, Before<rule>>;
|
|
19
|
+
type narrowed = constrain<Date, Narrowed>;
|
|
20
|
+
type optional = constrain<Date, Optional>;
|
|
21
|
+
type defaultsTo<rule> = constrain<Date, Default<rule>>;
|
|
22
|
+
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
23
|
+
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
24
|
+
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
25
|
+
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
26
|
+
exclusive: true;
|
|
27
|
+
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
28
|
+
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
29
|
+
exclusive: true;
|
|
30
|
+
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
31
|
+
type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
|
|
32
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { To } from "../
|
|
2
|
+
import type { To } from "../inference.ts";
|
|
3
3
|
export type FormDataValue = string | File;
|
|
4
4
|
export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
|
|
5
5
|
export declare const arkFormData: arkFormData.module;
|
|
@@ -7,7 +7,7 @@ export declare namespace arkFormData {
|
|
|
7
7
|
type module = Module<submodule>;
|
|
8
8
|
type submodule = Submodule<$>;
|
|
9
9
|
type $ = {
|
|
10
|
-
|
|
10
|
+
root: FormData;
|
|
11
11
|
value: FormDataValue;
|
|
12
12
|
parse: (In: FormData) => To<ParsedFormData>;
|
|
13
13
|
parsed: ParsedFormData;
|
|
@@ -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 =
|
|
15
|
-
|
|
14
|
+
export const arkFormData = arkModule({
|
|
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,
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type array, type conform, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util";
|
|
3
|
+
import type { Type } from "../type.ts";
|
|
4
|
+
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
5
|
+
import type { Date } from "./constructors/Date.ts";
|
|
6
|
+
import type { type } from "./keywords.ts";
|
|
7
|
+
import type { DivisibleBy, number } from "./number/number.ts";
|
|
8
|
+
import type { Matching, string } from "./string/string.ts";
|
|
9
|
+
export type { arkPrototypes as object } from "./constructors/constructors.ts";
|
|
10
|
+
export type { number } from "./number/number.ts";
|
|
11
|
+
export type { string } from "./string/string.ts";
|
|
12
|
+
export type Comparator = "<" | "<=" | ">" | ">=" | "==";
|
|
13
|
+
export type RegexLiteral<source extends string = string> = `/${source}/`;
|
|
14
|
+
export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
|
|
15
|
+
export type ConstraintSet = Record<PropertyKey, 1>;
|
|
16
|
+
export type Constraints = Record<string, ConstraintSet> | {
|
|
17
|
+
default?: unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare const constrained: " arkConstrained";
|
|
20
|
+
export type constrained = typeof constrained;
|
|
21
|
+
export type constrain<base, constraints extends Constraints> = base & {
|
|
22
|
+
[constrained]: constraints;
|
|
23
|
+
};
|
|
24
|
+
export type LimitLiteral = number | DateLiteral;
|
|
25
|
+
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
26
|
+
export type constraint<rule> = {
|
|
27
|
+
[k in rule & PropertyKey]: 1;
|
|
28
|
+
};
|
|
29
|
+
export type Literal<rule> = {
|
|
30
|
+
literal: constraint<rule>;
|
|
31
|
+
};
|
|
32
|
+
export type Narrowed = {
|
|
33
|
+
predicate: {
|
|
34
|
+
"?": 1;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type Branded<rule> = {
|
|
38
|
+
predicate: constraint<rule>;
|
|
39
|
+
};
|
|
40
|
+
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
41
|
+
export type AtLeastLength<rule> = {
|
|
42
|
+
atLeastLength: constraint<rule>;
|
|
43
|
+
};
|
|
44
|
+
export type AtMostLength<rule> = {
|
|
45
|
+
atMostLength: constraint<rule>;
|
|
46
|
+
};
|
|
47
|
+
export type MoreThanLength<rule> = {
|
|
48
|
+
moreThanLength: constraint<rule>;
|
|
49
|
+
};
|
|
50
|
+
export type LessThanLength<rule> = {
|
|
51
|
+
lessThanLength: constraint<rule>;
|
|
52
|
+
};
|
|
53
|
+
export type ExactlyLength<rule> = {
|
|
54
|
+
atLeastLength: constraint<rule>;
|
|
55
|
+
atMostLength: constraint<rule>;
|
|
56
|
+
};
|
|
57
|
+
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyConstraint<t, schemaToConstraint<kind, schema>>;
|
|
58
|
+
export type applyConstraint<t, constraint> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, constraint>>) => o : leftIfEqual<t, _applyConstraint<t, constraint>>;
|
|
59
|
+
type _applyConstraint<t, constraint> = parseConstraints<t> extends ([
|
|
60
|
+
infer base,
|
|
61
|
+
infer constraints extends Constraints
|
|
62
|
+
]) ? [
|
|
63
|
+
number,
|
|
64
|
+
base
|
|
65
|
+
] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.withConstraint<constraint> : [string, t] extends [t, string] ? string.withConstraint<constraint> : [Date, t] extends [t, Date] ? Date.withConstraint<constraint> : constrain<t, conform<constraint, Constraints>>;
|
|
66
|
+
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
67
|
+
[constrained]: constraints;
|
|
68
|
+
}> extends true ? [
|
|
69
|
+
number,
|
|
70
|
+
constraints
|
|
71
|
+
] : equals<t, string & {
|
|
72
|
+
[constrained]: constraints;
|
|
73
|
+
}> extends true ? [
|
|
74
|
+
string,
|
|
75
|
+
constraints
|
|
76
|
+
] : equals<t, bigint & {
|
|
77
|
+
[constrained]: constraints;
|
|
78
|
+
}> extends true ? [
|
|
79
|
+
bigint,
|
|
80
|
+
constraints
|
|
81
|
+
] : equals<t, symbol & {
|
|
82
|
+
[constrained]: constraints;
|
|
83
|
+
}> extends true ? [
|
|
84
|
+
symbol,
|
|
85
|
+
constraints
|
|
86
|
+
] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [
|
|
87
|
+
arkPrototypes.instanceOf<kind>,
|
|
88
|
+
constraints
|
|
89
|
+
] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null;
|
|
90
|
+
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
91
|
+
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
92
|
+
exclusive: true;
|
|
93
|
+
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
94
|
+
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
95
|
+
exclusive: true;
|
|
96
|
+
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
97
|
+
export type schemaToConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "min" ? number.minSchemaToConstraint<schema, rule> : kind extends "max" ? number.maxSchemaToConstraint<schema, rule> : kind extends "minLength" ? minLengthSchemaToConstraint<schema, rule> : kind extends "maxLength" ? maxLengthSchemaToConstraint<schema, rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? Date.afterSchemaToConstraint<schema, rule> : kind extends "before" ? Date.beforeSchemaToConstraint<schema, rule> : Narrowed : never;
|
|
98
|
+
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
99
|
+
export declare namespace distill {
|
|
100
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
101
|
+
type Options = {
|
|
102
|
+
endpoint?: Endpoint;
|
|
103
|
+
branded?: true;
|
|
104
|
+
};
|
|
105
|
+
type In<t> = distill<t, {
|
|
106
|
+
endpoint: "in";
|
|
107
|
+
}>;
|
|
108
|
+
type Out<t> = distill<t, {
|
|
109
|
+
endpoint: "out";
|
|
110
|
+
}>;
|
|
111
|
+
namespace brandable {
|
|
112
|
+
type In<t> = distill<t, {
|
|
113
|
+
endpoint: "in";
|
|
114
|
+
branded: true;
|
|
115
|
+
}>;
|
|
116
|
+
type Out<t> = distill<t, {
|
|
117
|
+
endpoint: "out";
|
|
118
|
+
branded: true;
|
|
119
|
+
}>;
|
|
120
|
+
namespace introspectable {
|
|
121
|
+
type Out<t> = distill<t, {
|
|
122
|
+
endpoint: "out.introspectable";
|
|
123
|
+
branded: true;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
type unbranded<t> = distill<t>;
|
|
128
|
+
namespace introspectable {
|
|
129
|
+
type Out<t> = distill<t, {
|
|
130
|
+
endpoint: "out.introspectable";
|
|
131
|
+
}>;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
135
|
+
export type includesMorphs<t> = [
|
|
136
|
+
_distill<t, {
|
|
137
|
+
endpoint: "in";
|
|
138
|
+
branded: true;
|
|
139
|
+
}>,
|
|
140
|
+
_distill<t, {
|
|
141
|
+
endpoint: "out";
|
|
142
|
+
branded: true;
|
|
143
|
+
}>
|
|
144
|
+
] extends ([
|
|
145
|
+
_distill<t, {
|
|
146
|
+
endpoint: "out";
|
|
147
|
+
branded: true;
|
|
148
|
+
}>,
|
|
149
|
+
_distill<t, {
|
|
150
|
+
endpoint: "in";
|
|
151
|
+
branded: true;
|
|
152
|
+
}>
|
|
153
|
+
]) ? false : true;
|
|
154
|
+
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
155
|
+
infer base,
|
|
156
|
+
infer constraints extends Constraints
|
|
157
|
+
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<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 Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
|
|
158
|
+
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
|
|
159
|
+
[k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
160
|
+
} & {
|
|
161
|
+
[k in inferredOptionalOrDefaultKeyOf<o>]?: _distill<o[k], opts>;
|
|
162
|
+
}> : show<{
|
|
163
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
164
|
+
} & {
|
|
165
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
|
|
166
|
+
}>;
|
|
167
|
+
type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
|
|
168
|
+
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;
|
|
169
|
+
type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
|
|
170
|
+
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
|
|
171
|
+
o[k]
|
|
172
|
+
] extends [anyOrNever] ? never : o[k] extends InferredDefault ? k : never : never : never;
|
|
173
|
+
type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
|
|
174
|
+
o[k]
|
|
175
|
+
] extends [anyOrNever] ? never : o[k] extends InferredOptional ? k : never : never : never;
|
|
176
|
+
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;
|
|
177
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
|
|
178
|
+
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
|
|
179
|
+
}, opts>;
|
|
180
|
+
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>];
|
|
181
|
+
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]> : [...{
|
|
182
|
+
[i in keyof t]: _distill<t[i], opts>;
|
|
183
|
+
}, ...postfix];
|
|
184
|
+
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
185
|
+
/** Objects we don't want to expand during inference like Date or Promise */
|
|
186
|
+
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
187
|
+
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>;
|
|
188
|
+
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
189
|
+
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;
|
|
190
|
+
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
191
|
+
export type Out<o = any> = ["=>", o, boolean];
|
|
192
|
+
export type To<o = any> = ["=>", o, true];
|
|
193
|
+
export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
|
|
194
|
+
export type Optional = {
|
|
195
|
+
optional?: {};
|
|
196
|
+
};
|
|
197
|
+
export type InferredOptional<t = unknown> = constrain<t, Optional>;
|
|
198
|
+
export type Default<v = any> = {
|
|
199
|
+
default?: {
|
|
200
|
+
value: v;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>;
|
|
204
|
+
export type termOrType<t> = t | Type<t, any>;
|
|
205
|
+
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
206
|
+
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
207
|
+
type _inferIntersection<l, r, piped extends boolean> = [
|
|
208
|
+
l & r
|
|
209
|
+
] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
|
|
210
|
+
infer lBase,
|
|
211
|
+
infer lConstraints extends Constraints
|
|
212
|
+
]) ? parseConstraints<r> extends ([
|
|
213
|
+
infer rBase,
|
|
214
|
+
infer rConstraints extends Constraints
|
|
215
|
+
]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
|
|
216
|
+
infer rBase,
|
|
217
|
+
infer rConstraints extends Constraints
|
|
218
|
+
]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
219
|
+
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
220
|
+
body: _inferIntersection<this[0], this[1], piped>;
|
|
221
|
+
}
|
|
222
|
+
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[],
|
|
223
|
+
l & r : r extends array ? l & r : show<{
|
|
224
|
+
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
225
|
+
} & {
|
|
226
|
+
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
227
|
+
}>;
|