arktype 2.0.0-rc.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/attributes.d.ts +94 -0
- package/out/attributes.js +3 -0
- package/out/generic.d.ts +13 -13
- package/out/index.d.ts +3 -1
- package/out/index.js +2 -1
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +2 -2
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +14 -13
- package/out/keywords/keywords.js +9 -5
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +22 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +31 -4
- package/out/keywords/ts.js +21 -8
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +461 -35
- package/out/methods/date.d.ts +5 -6
- package/out/methods/instantiate.d.ts +4 -4
- package/out/methods/morph.d.ts +6 -6
- package/out/methods/number.d.ts +8 -9
- package/out/methods/object.d.ts +39 -15
- package/out/methods/string.d.ts +9 -10
- package/out/parser/ast/bounds.d.ts +1 -1
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +8 -22
- package/out/parser/ast/validate.d.ts +13 -9
- package/out/parser/ast/validate.js +3 -1
- package/out/parser/definition.d.ts +17 -8
- package/out/parser/definition.js +38 -3
- package/out/parser/objectLiteral.d.ts +39 -39
- package/out/parser/objectLiteral.js +83 -67
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/reduce/dynamic.d.ts +8 -9
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +4 -4
- package/out/parser/shift/operand/date.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/shift/operand/operand.d.ts +3 -3
- package/out/parser/shift/operand/operand.js +2 -2
- package/out/parser/shift/operand/unenclosed.d.ts +13 -5
- package/out/parser/shift/operand/unenclosed.js +5 -4
- package/out/parser/shift/operator/bounds.d.ts +5 -5
- package/out/parser/shift/operator/bounds.js +5 -4
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/shift/operator/default.d.ts +3 -2
- package/out/parser/shift/operator/default.js +4 -1
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +4 -3
- package/out/parser/shift/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +31 -55
- package/out/parser/shift/scanner.js +24 -83
- package/out/parser/string.d.ts +5 -4
- package/out/parser/string.js +18 -1
- package/out/parser/tupleExpressions.d.ts +48 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +95 -0
- package/out/parser/tupleLiteral.js +122 -0
- package/out/scope.d.ts +17 -12
- package/out/scope.js +25 -41
- package/out/type.d.ts +63 -5
- package/out/type.js +3 -2
- package/package.json +8 -8
- package/out/keywords/constructors/Date.d.ts +0 -31
- package/out/keywords/inference.d.ts +0 -220
- package/out/keywords/inference.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -9
- package/out/keywords/number/integer.d.ts +0 -3
- package/out/keywords/number/integer.js +0 -5
- package/out/keywords/number/number.d.ts +0 -53
- package/out/keywords/number/number.js +0 -21
- package/out/keywords/string/alpha.d.ts +0 -7
- package/out/keywords/string/alpha.js +0 -2
- package/out/keywords/string/alphanumeric.d.ts +0 -7
- package/out/keywords/string/alphanumeric.js +0 -2
- package/out/keywords/string/capitalize.d.ts +0 -15
- package/out/keywords/string/capitalize.js +0 -12
- package/out/keywords/string/creditCard.d.ts +0 -8
- package/out/keywords/string/creditCard.js +0 -37
- package/out/keywords/string/date.d.ts +0 -55
- package/out/keywords/string/date.js +0 -98
- package/out/keywords/string/digits.d.ts +0 -7
- package/out/keywords/string/digits.js +0 -2
- package/out/keywords/string/email.d.ts +0 -7
- package/out/keywords/string/email.js +0 -4
- package/out/keywords/string/integer.d.ts +0 -16
- package/out/keywords/string/integer.js +0 -16
- package/out/keywords/string/ip.d.ts +0 -20
- package/out/keywords/string/ip.js +0 -23
- package/out/keywords/string/json.d.ts +0 -16
- package/out/keywords/string/json.js +0 -53
- package/out/keywords/string/lower.d.ts +0 -15
- package/out/keywords/string/lower.js +0 -12
- package/out/keywords/string/normalize.d.ts +0 -88
- package/out/keywords/string/normalize.js +0 -43
- package/out/keywords/string/numeric.d.ts +0 -15
- package/out/keywords/string/numeric.js +0 -13
- package/out/keywords/string/semver.d.ts +0 -7
- package/out/keywords/string/semver.js +0 -4
- package/out/keywords/string/string.d.ts +0 -108
- package/out/keywords/string/string.js +0 -41
- package/out/keywords/string/trim.d.ts +0 -15
- package/out/keywords/string/trim.js +0 -14
- package/out/keywords/string/upper.d.ts +0 -15
- package/out/keywords/string/upper.js +0 -12
- package/out/keywords/string/url.d.ts +0 -15
- package/out/keywords/string/url.js +0 -37
- package/out/keywords/string/utils.d.ts +0 -2
- package/out/keywords/string/utils.js +0 -10
- package/out/keywords/string/uuid.d.ts +0 -42
- package/out/keywords/string/uuid.js +0 -19
- package/out/keywords/utils.d.ts +0 -1
- package/out/keywords/utils.js +0 -2
- package/out/methods/validator.d.ts +0 -11
- package/out/methods/validator.js +0 -1
- package/out/parser/tuple.d.ts +0 -143
- package/out/parser/tuple.js +0 -164
- /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ArkError, ArkErrors, Morph } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type array, type Brand, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type Primitive, type show } from "@ark/util";
|
|
3
|
+
import type { arkPrototypes } from "./keywords/constructors.ts";
|
|
4
|
+
import type { type } from "./keywords/keywords.ts";
|
|
5
|
+
import type { Type } from "./type.ts";
|
|
6
|
+
export type { arkPrototypes as object } from "./keywords/constructors.ts";
|
|
7
|
+
export type Comparator = "<" | "<=" | ">" | ">=" | "==";
|
|
8
|
+
export type RegexLiteral<source extends string = string> = `/${source}/`;
|
|
9
|
+
export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
|
|
10
|
+
export type LimitLiteral = number | DateLiteral;
|
|
11
|
+
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
12
|
+
export type distill<t, endpoint extends distill.Endpoint> = finalizeDistillation<t, _distill<t, endpoint, never>>;
|
|
13
|
+
export declare namespace distill {
|
|
14
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
15
|
+
type In<t> = distill<t, "in">;
|
|
16
|
+
type Out<t> = distill<t, "out">;
|
|
17
|
+
namespace introspectable {
|
|
18
|
+
type Out<t> = distill<t, "out.introspectable">;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
22
|
+
type _distill<t, endpoint extends distill.Endpoint, seen> = t extends undefined ? t : [t] extends [anyOrNever | seen] ? t : unknown extends t ? unknown : t extends Brand<infer base> ? endpoint extends "in" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends InferredMorph<infer i, infer o> ? distillIo<i, o, endpoint, seen> : t : t extends Default<infer constraint> ? _distill<constraint, endpoint, seen> : t extends array ? distillArray<t, endpoint, seen | t> : isSafelyMappable<t> extends true ? distillMappable<t, endpoint, seen | t> : t;
|
|
23
|
+
type distillMappable<o, endpoint extends distill.Endpoint, seen> = endpoint extends "in" ? show<{
|
|
24
|
+
[k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], endpoint, seen>;
|
|
25
|
+
} & {
|
|
26
|
+
[k in inferredDefaultKeyOf<o>]?: _distill<o[k], endpoint, seen>;
|
|
27
|
+
}> : {
|
|
28
|
+
[k in keyof o]: _distill<o[k], endpoint, seen>;
|
|
29
|
+
};
|
|
30
|
+
type distillIo<i, o extends Out, endpoint extends distill.Endpoint, seen> = endpoint extends "out" ? _distill<o["t"], endpoint, seen> : endpoint extends "in" ? _distill<i, endpoint, seen> : o extends To<infer validatedOut> ? _distill<validatedOut, endpoint, seen> : unknown;
|
|
31
|
+
type unwrapInput<t> = t extends InferredMorph<infer i> ? t extends anyOrNever ? t : i : t;
|
|
32
|
+
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? unwrapInput<o[k]> extends Default<infer t> ? [
|
|
33
|
+
t
|
|
34
|
+
] extends [anyOrNever] ? never : k : never : never : never;
|
|
35
|
+
type distillArray<t extends array, endpoint extends distill.Endpoint, seen> = t[number][] extends t ? alignReadonly<_distill<t[number], endpoint, seen>[], t> : distillNonArraykeys<t, alignReadonly<distillArrayFromPrefix<[...t], endpoint, seen, []>, t>, endpoint, seen>;
|
|
36
|
+
type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
|
|
37
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, endpoint extends distill.Endpoint, seen> = keyof originalArray extends keyof distilledArray ? distilledArray : distilledArray & _distill<{
|
|
38
|
+
[k in keyof originalArray as k extends keyof distilledArray ? never : k]: originalArray[k];
|
|
39
|
+
}, endpoint, seen>;
|
|
40
|
+
type distillArrayFromPrefix<t extends array, endpoint extends distill.Endpoint, seen, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArrayFromPrefix<tail, endpoint, seen, [
|
|
41
|
+
...prefix,
|
|
42
|
+
_distill<head, endpoint, seen>
|
|
43
|
+
]> : [...prefix, ...distillArrayFromPostfix<t, endpoint, seen, []>];
|
|
44
|
+
type distillArrayFromPostfix<t extends array, endpoint extends distill.Endpoint, seen, postfix extends array> = t extends readonly [...infer init, infer last] ? distillArrayFromPostfix<init, endpoint, seen, [
|
|
45
|
+
_distill<last, endpoint, seen>,
|
|
46
|
+
...postfix
|
|
47
|
+
]> : [...{
|
|
48
|
+
[i in keyof t]: _distill<t[i], endpoint, seen>;
|
|
49
|
+
}, ...postfix];
|
|
50
|
+
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
51
|
+
/** Objects we don't want to expand during inference like Date or Promise */
|
|
52
|
+
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
53
|
+
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? narrowed : t;
|
|
54
|
+
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<head extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distill.In<t>) => Out<out> : never, tail> : t;
|
|
55
|
+
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
56
|
+
declare const isMorphOutKey: " isMorphOut";
|
|
57
|
+
export interface Out<o = any> {
|
|
58
|
+
[isMorphOutKey]: true;
|
|
59
|
+
t: o;
|
|
60
|
+
introspectable: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface To<o = any> extends Out<o> {
|
|
63
|
+
introspectable: true;
|
|
64
|
+
}
|
|
65
|
+
export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
|
|
66
|
+
declare const defaultsToKey: " defaultsTo";
|
|
67
|
+
export type Default<t = unknown, v = unknown> = {
|
|
68
|
+
[defaultsToKey]: [t, v];
|
|
69
|
+
};
|
|
70
|
+
export type withDefault<t, v, undistributed = t> = t extends InferredMorph ? addDefaultToMorph<t, v> : Default<Exclude<undistributed, InferredMorph>, v>;
|
|
71
|
+
type addDefaultToMorph<t extends InferredMorph, v> = [
|
|
72
|
+
normalizeMorphDistribution<t>
|
|
73
|
+
] extends [InferredMorph<infer i, infer o>] ? (In: Default<i, v>) => o : never;
|
|
74
|
+
type normalizeMorphDistribution<t, undistributedIn = t extends InferredMorph<infer i> ? i : never, undistributedOut extends Out = [t] extends [InferredMorph<any, infer o>] ? [
|
|
75
|
+
o
|
|
76
|
+
] extends [To<infer unwrappedOut>] ? To<unwrappedOut> : o : never> = (Extract<t, InferredMorph> extends anyOrNever ? never : Extract<t, InferredMorph> extends InferredMorph<infer i, infer o> ? [
|
|
77
|
+
undistributedOut
|
|
78
|
+
] extends [o] ? (In: undistributedIn) => undistributedOut : [undistributedIn] extends [i] ? (In: undistributedIn) => undistributedOut : t : never) | Exclude<t, InferredMorph>;
|
|
79
|
+
export type defaultFor<t = unknown> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
|
|
80
|
+
export type termOrType<t> = t | Type<t, any>;
|
|
81
|
+
export type inferIntersection<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, false>>;
|
|
82
|
+
export type inferPipe<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, true>>;
|
|
83
|
+
type _inferIntersection<l, r, piped extends boolean> = [
|
|
84
|
+
l & r
|
|
85
|
+
] 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 : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
86
|
+
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
87
|
+
body: _inferIntersection<this[0], this[1], piped>;
|
|
88
|
+
}
|
|
89
|
+
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[],
|
|
90
|
+
l & r : r extends array ? l & r : show<{
|
|
91
|
+
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
92
|
+
} & {
|
|
93
|
+
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
94
|
+
}>;
|
package/out/generic.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
|
-
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type
|
|
2
|
+
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type JsonStructure, type WhitespaceChar } from "@ark/util";
|
|
3
3
|
import type { type } from "./keywords/keywords.ts";
|
|
4
4
|
import type { inferAstRoot } from "./parser/ast/infer.ts";
|
|
5
5
|
import type { validateAst } from "./parser/ast/validate.ts";
|
|
6
|
-
import type { inferDefinition
|
|
6
|
+
import type { inferDefinition } from "./parser/definition.ts";
|
|
7
7
|
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { ArkTypeScanner } from "./parser/shift/scanner.ts";
|
|
9
9
|
import { parseUntilFinalizer } from "./parser/string.ts";
|
|
10
10
|
import type { Scope } from "./scope.ts";
|
|
11
11
|
import type { Type } from "./type.ts";
|
|
@@ -119,7 +119,7 @@ export interface Generic<params extends array<GenericParamAst> = array<GenericPa
|
|
|
119
119
|
$: Scope<$>;
|
|
120
120
|
arg$: Scope<arg$>;
|
|
121
121
|
internal: GenericRoot;
|
|
122
|
-
json:
|
|
122
|
+
json: JsonStructure;
|
|
123
123
|
}
|
|
124
124
|
export type GenericConstructor<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = {}> = new () => Generic<params, bodyDef, $, arg$>;
|
|
125
125
|
export declare const Generic: GenericConstructor;
|
|
@@ -127,19 +127,19 @@ export type GenericDeclaration<name extends string = string, params extends Para
|
|
|
127
127
|
export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
|
|
128
128
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
129
129
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
130
|
-
export type parseGenericParams<def extends string, $> = parseNextNameChar<
|
|
130
|
+
export type parseGenericParams<def extends string, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<def>, "", [
|
|
131
131
|
], $>;
|
|
132
|
-
type ParamsTerminator =
|
|
133
|
-
export declare const parseGenericParamName: (scanner:
|
|
134
|
-
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<
|
|
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
|
|
132
|
+
type ParamsTerminator = WhitespaceChar | ",";
|
|
133
|
+
export declare const parseGenericParamName: (scanner: ArkTypeScanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
134
|
+
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<unscanned>, "", result, $>;
|
|
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 WhitespaceChar ? _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:
|
|
139
|
-
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> =
|
|
138
|
+
declare const _parseOptionalConstraint: (scanner: ArkTypeScanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
139
|
+
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = ArkTypeScanner.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"], $, {}>]
|
|
142
|
-
], $> : never : parseName<
|
|
142
|
+
], $> : never : parseName<ArkTypeScanner.skipWhitespace<unscanned> extends (`,${infer nextUnscanned}`) ? nextUnscanned : unscanned, [
|
|
143
143
|
...result,
|
|
144
144
|
[name, unknown]
|
|
145
145
|
], $>;
|
|
@@ -153,7 +153,7 @@ export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamD
|
|
|
153
153
|
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
154
154
|
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
155
155
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
156
|
-
<const body>(body:
|
|
156
|
+
<const body>(body: type.validate<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
|
157
157
|
<hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
|
|
158
158
|
}
|
|
159
159
|
export {};
|
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
|
|
2
2
|
export { Hkt, inferred } from "@ark/util";
|
|
3
|
+
export type { distill } from "./attributes.ts";
|
|
4
|
+
export * from "./config.ts";
|
|
3
5
|
export { Generic } from "./generic.ts";
|
|
4
6
|
export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
|
|
5
7
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
|
-
export {
|
|
8
|
+
export { scope, type Scope } from "./scope.ts";
|
|
7
9
|
export { Type } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
2
|
export { Hkt, inferred } from "@ark/util";
|
|
3
|
+
export * from "./config.js";
|
|
3
4
|
export { Generic } from "./generic.js";
|
|
4
5
|
export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
|
|
5
6
|
export { Module } from "./module.js";
|
|
6
|
-
export {
|
|
7
|
+
export { scope } from "./scope.js";
|
|
7
8
|
export { Type } from "./type.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hkt, liftArray, type Digit } from "@ark/util";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { To } from "../attributes.ts";
|
|
3
|
+
import type { Module, Submodule } from "../module.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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { genericNode, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { Hkt, liftArray } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { Scope } from "../scope.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), rootSchema);
|
|
13
13
|
}, liftFromHkt);
|
|
14
|
-
export const arkArray =
|
|
14
|
+
export const arkArray = Scope.module({
|
|
15
15
|
root: intrinsic.Array,
|
|
16
16
|
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { To } from "../attributes.ts";
|
|
2
|
+
import type { Module, Submodule } from "../module.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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { Scope } from "../scope.js";
|
|
4
4
|
const value = rootSchema(["string", registry.FileConstructor]);
|
|
5
5
|
const parsedFormDataValue = value.rawOr(value.array());
|
|
6
6
|
const parsed = rootSchema({
|
|
@@ -11,7 +11,7 @@ const parsed = rootSchema({
|
|
|
11
11
|
value: parsedFormDataValue
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
export const arkFormData =
|
|
14
|
+
export const arkFormData = Scope.module({
|
|
15
15
|
root: ["instanceof", FormData],
|
|
16
16
|
value,
|
|
17
17
|
parsed,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const TypedArray =
|
|
1
|
+
import { Scope } from "../scope.js";
|
|
2
|
+
export const TypedArray = Scope.module({
|
|
3
3
|
Int8: ["instanceof", Int8Array],
|
|
4
4
|
Uint8: ["instanceof", Uint8Array],
|
|
5
5
|
Uint8Clamped: ["instanceof", Uint8ClampedArray],
|
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 { Scope } from "../scope.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 = Scope.module({
|
|
8
8
|
Key: intrinsic.key,
|
|
9
9
|
Merge
|
|
10
10
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EcmascriptObjects, type PlatformObjects } from "@ark/util";
|
|
2
|
-
import type { Module, Submodule } from "
|
|
2
|
+
import type { Module, Submodule } from "../module.ts";
|
|
3
3
|
import { arkArray } from "./Array.ts";
|
|
4
4
|
import { arkFormData } from "./FormData.ts";
|
|
5
5
|
import { TypedArray } from "./TypedArray.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
|
|
2
|
-
import {
|
|
2
|
+
import { Scope } from "../scope.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 = Scope.module({
|
|
12
12
|
...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
|
|
13
13
|
Array: arkArray,
|
|
14
14
|
TypedArray,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ArkErrors, arkKind } from "@ark/schema";
|
|
2
|
-
import type { inferred } from "@ark/util";
|
|
2
|
+
import type { Brand, inferred } from "@ark/util";
|
|
3
|
+
import type { distill, InferredMorph, Out, To } from "../attributes.ts";
|
|
3
4
|
import type { GenericParser } from "../generic.ts";
|
|
4
5
|
import type { BaseType } from "../methods/base.ts";
|
|
5
6
|
import type { BoundModule, Module } from "../module.ts";
|
|
@@ -7,11 +8,10 @@ import type { inferDefinition, validateDefinition } from "../parser/definition.t
|
|
|
7
8
|
import { type bindThis, type Scope } from "../scope.ts";
|
|
8
9
|
import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
|
|
9
10
|
import { arkBuiltins } from "./builtins.ts";
|
|
10
|
-
import { arkPrototypes } from "./constructors
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
|
|
11
|
+
import { arkPrototypes } from "./constructors.ts";
|
|
12
|
+
import { number } from "./number.ts";
|
|
13
|
+
import { string } from "./string.ts";
|
|
14
|
+
import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.ts";
|
|
15
15
|
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
16
16
|
}
|
|
17
17
|
export declare namespace Ark {
|
|
@@ -20,11 +20,15 @@ export declare namespace Ark {
|
|
|
20
20
|
interface wrapped extends arkPrototypes.wrapped {
|
|
21
21
|
string: string.submodule;
|
|
22
22
|
number: number.submodule;
|
|
23
|
+
object: object.submodule;
|
|
23
24
|
unknown: unknown.submodule;
|
|
24
25
|
}
|
|
25
26
|
interface typeAttachments extends arkTsKeywords.$ {
|
|
27
|
+
arrayIndex: arkPrototypes.$["Array"]["index"];
|
|
26
28
|
Key: arkBuiltins.$["Key"];
|
|
27
29
|
Record: arkTsGenerics.$["Record"];
|
|
30
|
+
Date: arkPrototypes.$["Date"];
|
|
31
|
+
Array: arkPrototypes.$["Array"]["root"];
|
|
28
32
|
}
|
|
29
33
|
interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
|
|
30
34
|
}
|
|
@@ -33,9 +37,9 @@ export declare const ark: Scope<Ark>;
|
|
|
33
37
|
export declare const keywords: Module<Ark>;
|
|
34
38
|
export declare const type: TypeParser<{}>;
|
|
35
39
|
export declare namespace type {
|
|
36
|
-
|
|
37
|
-
[inferred]?:
|
|
38
|
-
}
|
|
40
|
+
interface cast<to> {
|
|
41
|
+
[inferred]?: to;
|
|
42
|
+
}
|
|
39
43
|
type errors = ArkErrors;
|
|
40
44
|
/** @ts-ignore cast variance */
|
|
41
45
|
interface Any<out t = any> extends BaseType<t, any> {
|
|
@@ -44,15 +48,12 @@ export declare namespace type {
|
|
|
44
48
|
namespace infer {
|
|
45
49
|
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
46
50
|
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
47
|
-
namespace brandable {
|
|
48
|
-
type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
|
|
49
|
-
type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
|
|
50
|
-
}
|
|
51
51
|
namespace introspectable {
|
|
52
52
|
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
56
|
+
type brand<t, id> = t extends InferredMorph<infer i, infer o> ? o["introspectable"] extends true ? (In: i) => To<Brand<o["t"], id>> : (In: i) => Out<Brand<o["t"], id>> : Brand<t, id>;
|
|
56
57
|
}
|
|
57
58
|
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
58
59
|
export declare const generic: GenericParser<{}>;
|
package/out/keywords/keywords.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { $arkTypeRegistry, scope } from "../scope.js";
|
|
2
2
|
import { arkBuiltins } from "./builtins.js";
|
|
3
|
-
import { arkPrototypes } from "./constructors
|
|
4
|
-
import { number } from "./number
|
|
5
|
-
import { string } from "./string
|
|
6
|
-
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.js";
|
|
3
|
+
import { arkPrototypes } from "./constructors.js";
|
|
4
|
+
import { number } from "./number.js";
|
|
5
|
+
import { string } from "./string.js";
|
|
6
|
+
import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.js";
|
|
7
7
|
$arkTypeRegistry.typeAttachments = {
|
|
8
8
|
...arkTsKeywords,
|
|
9
|
+
arrayIndex: arkPrototypes.Array.index,
|
|
9
10
|
Key: arkBuiltins.Key,
|
|
10
|
-
Record: arkTsGenerics.Record
|
|
11
|
+
Record: arkTsGenerics.Record,
|
|
12
|
+
Array: arkPrototypes.Array.root,
|
|
13
|
+
Date: arkPrototypes.Date
|
|
11
14
|
};
|
|
12
15
|
export const ark = scope({
|
|
13
16
|
...arkTsKeywords,
|
|
@@ -16,6 +19,7 @@ export const ark = scope({
|
|
|
16
19
|
...arkBuiltins,
|
|
17
20
|
string,
|
|
18
21
|
number,
|
|
22
|
+
object,
|
|
19
23
|
unknown
|
|
20
24
|
}, { prereducedAliases: true, ambient: true });
|
|
21
25
|
export const keywords = ark.export();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Module, Submodule } from "../module.ts";
|
|
2
|
+
/**
|
|
3
|
+
* As per the ECMA-262 specification:
|
|
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
|
+
*
|
|
6
|
+
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
7
|
+
*/
|
|
8
|
+
export declare const epoch: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
9
|
+
export declare const integer: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
10
|
+
export declare const number: number.module;
|
|
11
|
+
export declare namespace number {
|
|
12
|
+
type module = Module<submodule>;
|
|
13
|
+
type submodule = Submodule<$>;
|
|
14
|
+
type $ = {
|
|
15
|
+
root: number;
|
|
16
|
+
epoch: number;
|
|
17
|
+
integer: number;
|
|
18
|
+
safe: number;
|
|
19
|
+
NaN: number;
|
|
20
|
+
Infinity: number;
|
|
21
|
+
NegativeInfinity: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
+
import { Scope } from "../scope.js";
|
|
2
3
|
/**
|
|
3
4
|
* As per the ECMA-262 specification:
|
|
4
5
|
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
@@ -24,3 +25,23 @@ export const epoch = rootSchema({
|
|
|
24
25
|
},
|
|
25
26
|
meta: "an integer representing a safe Unix timestamp"
|
|
26
27
|
});
|
|
28
|
+
export const integer = rootSchema({
|
|
29
|
+
domain: "number",
|
|
30
|
+
divisor: 1
|
|
31
|
+
});
|
|
32
|
+
export const number = Scope.module({
|
|
33
|
+
root: intrinsic.number,
|
|
34
|
+
integer,
|
|
35
|
+
epoch,
|
|
36
|
+
safe: rootSchema({
|
|
37
|
+
domain: {
|
|
38
|
+
domain: "number",
|
|
39
|
+
numberAllowsNaN: false
|
|
40
|
+
},
|
|
41
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
42
|
+
max: Number.MAX_SAFE_INTEGER
|
|
43
|
+
}),
|
|
44
|
+
NaN: ["===", Number.NaN],
|
|
45
|
+
Infinity: ["===", Number.POSITIVE_INFINITY],
|
|
46
|
+
NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
|
|
47
|
+
});
|