arktype 2.0.0-rc.3 → 2.0.0-rc.30
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/config.d.ts +1 -1
- package/out/generic.d.ts +55 -58
- package/out/generic.js +6 -8
- package/out/index.d.ts +6 -4
- package/out/index.js +4 -3
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
- package/out/keywords/{constructors/Array.js → Array.js} +7 -7
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
- package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
- 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 -2
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +29 -0
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +24 -2
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +42 -4
- package/out/keywords/ts.js +24 -7
- package/out/methods/array.d.ts +12 -0
- package/out/methods/base.d.ts +178 -0
- package/out/methods/date.d.ts +10 -0
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +11 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +12 -0
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +25 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +30 -0
- package/out/parser/ast/validate.js +3 -0
- package/out/parser/definition.d.ts +21 -13
- package/out/parser/definition.js +20 -2
- package/out/parser/objectLiteral.d.ts +41 -67
- package/out/parser/objectLiteral.js +79 -71
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/shift/operand/operand.d.ts +9 -0
- package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
- package/out/parser/{string/shift → 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/{string/shift → shift}/operator/default.d.ts +4 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +14 -0
- package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +47 -0
- package/out/parser/shift/scanner.js +43 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
- package/out/parser/{string/string.js → string.js} +19 -0
- package/out/parser/tupleExpressions.d.ts +47 -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 +41 -34
- package/out/scope.js +54 -62
- package/out/type.d.ts +46 -22
- package/out/type.js +15 -11
- 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/ark.js +0 -24
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -10
- 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 -28
- package/out/keywords/number/number.js +0 -9
- 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 -59
- 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 -15
- package/out/keywords/string/json.js +0 -45
- 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 -92
- 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 -112
- 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/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -39
- package/out/parser/semantic/validate.d.ts +0 -26
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -9
- package/out/parser/string/shift/operator/operator.d.ts +0 -13
- package/out/parser/string/shift/scanner.d.ts +0 -69
- package/out/parser/string/shift/scanner.js +0 -100
- package/out/parser/tuple.d.ts +0 -132
- package/out/parser/tuple.js +0 -158
- package/out/subtypes/array.d.ts +0 -13
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/date.d.ts +0 -11
- package/out/subtypes/instantiate.d.ts +0 -16
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/number.d.ts +0 -12
- package/out/subtypes/object.d.ts +0 -33
- package/out/subtypes/string.d.ts +0 -13
- package/out/subtypes/validator.d.ts +0 -11
- package/out/subtypes/validator.js +0 -1
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{intersect.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/{keys.js → parser/ast/generic.js} +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.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/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";
|
|
2
|
-
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type
|
|
3
|
-
import type {
|
|
4
|
-
import type { inferAstRoot } from "./parser/
|
|
5
|
-
import type { validateAst } from "./parser/
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import type {
|
|
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 JsonStructure, type WhitespaceChar } 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";
|
|
6
|
+
import type { inferDefinition } from "./parser/definition.ts";
|
|
7
|
+
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
+
import type { ArkTypeScanner } 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], $>;
|
|
@@ -118,7 +119,7 @@ export interface Generic<params extends array<GenericParamAst> = array<GenericPa
|
|
|
118
119
|
$: Scope<$>;
|
|
119
120
|
arg$: Scope<arg$>;
|
|
120
121
|
internal: GenericRoot;
|
|
121
|
-
json:
|
|
122
|
+
json: JsonStructure;
|
|
122
123
|
}
|
|
123
124
|
export type GenericConstructor<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = {}> = new () => Generic<params, bodyDef, $, arg$>;
|
|
124
125
|
export declare const Generic: GenericConstructor;
|
|
@@ -126,37 +127,33 @@ 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
|
|
130
|
-
export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
|
|
130
|
+
export type parseGenericParams<def extends string, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<def>, "", [
|
|
131
131
|
], $>;
|
|
132
|
-
type ParamsTerminator =
|
|
133
|
-
declare const
|
|
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
|
], $>;
|
|
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
|
-
<const body>(body:
|
|
156
|
+
<const body>(body: type.validate<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
|
160
157
|
<hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
|
|
161
158
|
}
|
|
162
159
|
export {};
|
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,9 @@
|
|
|
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
|
+
export type { distill } from "./attributes.ts";
|
|
4
|
+
export * from "./config.ts";
|
|
3
5
|
export { Generic } from "./generic.ts";
|
|
4
|
-
export {
|
|
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 {
|
|
7
|
-
export { Type
|
|
8
|
+
export { scope, type Scope } from "./scope.ts";
|
|
9
|
+
export { Type } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
|
+
export * from "./config.js";
|
|
3
4
|
export { Generic } from "./generic.js";
|
|
4
|
-
export {
|
|
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
|
}
|
|
@@ -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 { Scope } from "../scope.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 = Scope.module({
|
|
15
|
+
root: intrinsic.Array,
|
|
16
|
+
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
18
18
|
liftFrom
|
|
19
19
|
});
|
|
@@ -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;
|
|
@@ -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 { Scope } from "../scope.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 = Scope.module({
|
|
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 { 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";
|
|
@@ -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 { 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,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ArkErrors, arkKind } from "@ark/schema";
|
|
2
|
+
import type { Brand, inferred } from "@ark/util";
|
|
3
|
+
import type { distill, InferredMorph, Out, To } from "../attributes.ts";
|
|
4
|
+
import type { GenericParser } from "../generic.ts";
|
|
5
|
+
import type { BaseType } from "../methods/base.ts";
|
|
6
|
+
import type { BoundModule, Module } from "../module.ts";
|
|
7
|
+
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
|
|
8
|
+
import { type bindThis, type Scope } from "../scope.ts";
|
|
9
|
+
import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
|
|
10
|
+
import { arkBuiltins } from "./builtins.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
|
+
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
16
|
+
}
|
|
17
|
+
export declare namespace Ark {
|
|
18
|
+
interface keywords extends arkTsKeywords.$, arkTsGenerics.$, arkPrototypes.keywords, arkBuiltins.$ {
|
|
19
|
+
}
|
|
20
|
+
interface wrapped extends arkPrototypes.wrapped {
|
|
21
|
+
string: string.submodule;
|
|
22
|
+
number: number.submodule;
|
|
23
|
+
object: object.submodule;
|
|
24
|
+
unknown: unknown.submodule;
|
|
25
|
+
}
|
|
26
|
+
interface typeAttachments extends arkTsKeywords.$ {
|
|
27
|
+
Key: arkBuiltins.$["Key"];
|
|
28
|
+
Record: arkTsGenerics.$["Record"];
|
|
29
|
+
Date: arkPrototypes.$["Date"];
|
|
30
|
+
Array: arkPrototypes.$["Array"]["root"];
|
|
31
|
+
}
|
|
32
|
+
interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export declare const ark: Scope<Ark>;
|
|
36
|
+
export declare const keywords: Module<Ark>;
|
|
37
|
+
export declare const type: TypeParser<{}>;
|
|
38
|
+
export declare namespace type {
|
|
39
|
+
interface cast<to> {
|
|
40
|
+
[inferred]?: to;
|
|
41
|
+
}
|
|
42
|
+
type errors = ArkErrors;
|
|
43
|
+
/** @ts-ignore cast variance */
|
|
44
|
+
interface Any<out t = any> extends BaseType<t, any> {
|
|
45
|
+
}
|
|
46
|
+
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
|
|
47
|
+
namespace infer {
|
|
48
|
+
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
49
|
+
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
50
|
+
namespace introspectable {
|
|
51
|
+
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
55
|
+
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
|
+
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
58
|
+
export declare const generic: GenericParser<{}>;
|
|
59
|
+
export declare const schema: SchemaParser<{}>;
|
|
60
|
+
export declare const define: DefinitionParser<{}>;
|
|
61
|
+
export declare const declare: DeclarationParser<{}>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { $arkTypeRegistry, scope } from "../scope.js";
|
|
2
|
+
import { arkBuiltins } from "./builtins.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
|
+
$arkTypeRegistry.typeAttachments = {
|
|
8
|
+
...arkTsKeywords,
|
|
9
|
+
Key: arkBuiltins.Key,
|
|
10
|
+
Record: arkTsGenerics.Record,
|
|
11
|
+
Array: arkPrototypes.Array.root,
|
|
12
|
+
Date: arkPrototypes.Date
|
|
13
|
+
};
|
|
14
|
+
export const ark = scope({
|
|
15
|
+
...arkTsKeywords,
|
|
16
|
+
...arkTsGenerics,
|
|
17
|
+
...arkPrototypes,
|
|
18
|
+
...arkBuiltins,
|
|
19
|
+
string,
|
|
20
|
+
number,
|
|
21
|
+
object,
|
|
22
|
+
unknown
|
|
23
|
+
}, { prereducedAliases: true, ambient: true });
|
|
24
|
+
export const keywords = ark.export();
|
|
25
|
+
export const type = ark.type;
|
|
26
|
+
export const generic = ark.generic;
|
|
27
|
+
export const schema = ark.schema;
|
|
28
|
+
export const define = ark.define;
|
|
29
|
+
export const declare = ark.declare;
|