arktype 2.0.0-rc.14 → 2.0.0-rc.16
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/{keywords/inference.d.ts → attributes.d.ts} +143 -54
- package/out/attributes.js +2 -0
- package/out/keywords/constructors/Array.d.ts +1 -1
- package/out/keywords/constructors/Date.d.ts +23 -18
- package/out/keywords/constructors/FormData.d.ts +1 -1
- package/out/keywords/keywords.d.ts +4 -4
- package/out/keywords/number/epoch.d.ts +2 -1
- package/out/keywords/number/number.d.ts +28 -28
- package/out/keywords/string/alpha.d.ts +2 -2
- package/out/keywords/string/alphanumeric.d.ts +2 -2
- package/out/keywords/string/base64.d.ts +3 -3
- package/out/keywords/string/capitalize.d.ts +2 -2
- package/out/keywords/string/creditCard.d.ts +2 -2
- package/out/keywords/string/date.d.ts +4 -4
- package/out/keywords/string/digits.d.ts +2 -2
- package/out/keywords/string/email.d.ts +2 -2
- package/out/keywords/string/integer.d.ts +2 -2
- package/out/keywords/string/ip.d.ts +4 -4
- package/out/keywords/string/json.d.ts +2 -2
- package/out/keywords/string/lower.d.ts +2 -2
- package/out/keywords/string/normalize.d.ts +5 -5
- package/out/keywords/string/numeric.d.ts +2 -2
- package/out/keywords/string/semver.d.ts +2 -2
- package/out/keywords/string/string.d.ts +26 -7
- package/out/keywords/string/trim.d.ts +2 -2
- package/out/keywords/string/upper.d.ts +2 -2
- package/out/keywords/string/url.d.ts +2 -2
- package/out/keywords/string/uuid.d.ts +10 -10
- package/out/keywords/ts.d.ts +1 -1
- package/out/methods/array.d.ts +6 -6
- package/out/methods/base.d.ts +96 -12
- package/out/methods/date.d.ts +5 -5
- package/out/methods/instantiate.d.ts +1 -1
- package/out/methods/morph.d.ts +5 -1
- package/out/methods/number.d.ts +6 -6
- package/out/methods/object.d.ts +31 -3
- package/out/methods/string.d.ts +7 -7
- package/out/parser/ast/bounds.d.ts +1 -1
- package/out/parser/ast/infer.d.ts +8 -7
- package/out/parser/objectLiteral.d.ts +1 -1
- package/out/parser/reduce/dynamic.d.ts +1 -1
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +1 -1
- package/out/parser/shift/operand/date.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/shift/operator/bounds.d.ts +1 -1
- package/out/parser/shift/operator/default.d.ts +1 -1
- package/out/parser/tuple.d.ts +4 -4
- package/out/scope.d.ts +6 -1
- package/out/scope.js +3 -1
- package/out/type.d.ts +17 -1
- package/package.json +3 -3
- package/out/keywords/inference.js +0 -2
- package/out/keywords/string/brands.d.ts +0 -17
- package/out/keywords/string/brands.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, To, of } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Predicate, To, of } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type json = of<string,
|
|
4
|
+
type json = of<string, Nominal<"json">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
|
|
7
7
|
export declare const json: stringJson.module;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type lowercase = of<string,
|
|
4
|
+
type lowercase = of<string, Nominal<"lowercase">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const lower: lower.module;
|
|
7
7
|
export declare namespace lower {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type normalized = normalized.NFC;
|
|
5
5
|
namespace normalized {
|
|
6
|
-
type NFC = of<string,
|
|
7
|
-
type NFD = of<string,
|
|
8
|
-
type NFKC = of<string,
|
|
9
|
-
type NFKD = of<string,
|
|
6
|
+
type NFC = of<string, Nominal<"normalized.NFC">>;
|
|
7
|
+
type NFD = of<string, Nominal<"normalized.NFD">>;
|
|
8
|
+
type NFKC = of<string, Nominal<"normalized.NFKC">>;
|
|
9
|
+
type NFKD = of<string, Nominal<"normalized.NFKD">>;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type numeric = of<string,
|
|
4
|
+
type numeric = of<string, Nominal<"numeric">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const numeric: stringNumeric.module;
|
|
7
7
|
export declare namespace stringNumeric {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type semver = of<string,
|
|
3
|
+
type semver = of<string, Nominal<"semver">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const semver: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type semver = string.semver;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { satisfy } from "@ark/util";
|
|
2
|
+
import type { Anonymous, AtLeastLength, AtMostLength, AttributeKind, Attributes, Default, ExactlyLength, LengthAttributeKind, LessThanLength, MoreThanLength, Nominal, Optional, brand, constraint, of } from "../../attributes.ts";
|
|
1
3
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { AtLeastLength, AtMostLength, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, Predicate, constraint, of } from "../inference.ts";
|
|
3
4
|
import { alpha } from "./alpha.ts";
|
|
4
5
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
5
6
|
import { base64 } from "./base64.ts";
|
|
@@ -20,7 +21,6 @@ import { upper } from "./upper.ts";
|
|
|
20
21
|
import { url } from "./url.ts";
|
|
21
22
|
import { uuid } from "./uuid.ts";
|
|
22
23
|
export declare const string: Module<{
|
|
23
|
-
root: unknown;
|
|
24
24
|
trim: Submodule<trim.submodule>;
|
|
25
25
|
normalize: Submodule<{
|
|
26
26
|
root: unknown;
|
|
@@ -43,6 +43,7 @@ export declare const string: Module<{
|
|
|
43
43
|
}>;
|
|
44
44
|
alpha: unknown;
|
|
45
45
|
alphanumeric: unknown;
|
|
46
|
+
root: unknown;
|
|
46
47
|
url: Submodule<url.submodule>;
|
|
47
48
|
json: Submodule<stringJson.submodule>;
|
|
48
49
|
base64: Submodule<{
|
|
@@ -82,12 +83,16 @@ export declare namespace string {
|
|
|
82
83
|
type lessThanLength<rule> = of<string, LessThanLength<rule>>;
|
|
83
84
|
type exactlyLength<rule> = of<string, ExactlyLength<rule>>;
|
|
84
85
|
type matching<rule> = of<string, Matching<rule>>;
|
|
85
|
-
type
|
|
86
|
+
type anonymous = of<string, Anonymous>;
|
|
86
87
|
type optional = of<string, Optional>;
|
|
87
88
|
type defaultsTo<rule> = of<string, Default<rule>>;
|
|
88
|
-
type
|
|
89
|
-
type is<attributes> = of<string, attributes>;
|
|
90
|
-
type
|
|
89
|
+
type nominal<rule> = of<string, Nominal<rule>>;
|
|
90
|
+
type is<attributes extends Attributes> = of<string, attributes>;
|
|
91
|
+
type AttributableKind = satisfy<AttributeKind, "matching" | LengthAttributeKind>;
|
|
92
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
93
|
+
namespace raw {
|
|
94
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
|
|
95
|
+
}
|
|
91
96
|
type module = Module<string.submodule>;
|
|
92
97
|
type submodule = Submodule<$>;
|
|
93
98
|
type $ = {
|
|
@@ -112,5 +117,19 @@ export declare namespace string {
|
|
|
112
117
|
lower: lower.submodule;
|
|
113
118
|
upper: upper.submodule;
|
|
114
119
|
};
|
|
120
|
+
type branded<rule> = brand<string, Nominal<rule>>;
|
|
121
|
+
namespace branded {
|
|
122
|
+
type atLeastLength<rule> = brand<string, AtLeastLength<rule>>;
|
|
123
|
+
type moreThanLength<rule> = brand<string, MoreThanLength<rule>>;
|
|
124
|
+
type atMostLength<rule> = brand<string, AtMostLength<rule>>;
|
|
125
|
+
type lessThanLength<rule> = brand<string, LessThanLength<rule>>;
|
|
126
|
+
type exactlyLength<rule> = brand<string, ExactlyLength<rule>>;
|
|
127
|
+
type matching<rule> = brand<string, Matching<rule>>;
|
|
128
|
+
type anonymous = brand<string, Anonymous>;
|
|
129
|
+
type is<attributes extends Attributes> = brand<string, attributes>;
|
|
130
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
131
|
+
namespace raw {
|
|
132
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : never;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
115
135
|
}
|
|
116
|
-
export type { brandedString } from "./brands.ts";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type trimmed = of<string,
|
|
4
|
+
type trimmed = of<string, Nominal<"trimmed">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const trim: trim.module;
|
|
7
7
|
export declare namespace trim {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type uppercase = of<string,
|
|
4
|
+
type uppercase = of<string, Nominal<"uppercase">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const upper: upper.module;
|
|
7
7
|
export declare namespace upper {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { of, Predicate, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type url = of<string,
|
|
4
|
+
type url = of<string, Nominal<"url">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const url: url.module;
|
|
7
7
|
export declare namespace url {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Predicate, of } from "../inference.ts";
|
|
3
3
|
export declare const uuid: Module<{
|
|
4
4
|
root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
5
5
|
v4: unknown;
|
|
@@ -12,16 +12,16 @@ export declare const uuid: Module<{
|
|
|
12
12
|
v8: unknown;
|
|
13
13
|
}>;
|
|
14
14
|
declare namespace string {
|
|
15
|
-
type uuid = of<string,
|
|
15
|
+
type uuid = of<string, Nominal<"uuid">>;
|
|
16
16
|
namespace uuid {
|
|
17
|
-
type v1 = of<string,
|
|
18
|
-
type v2 = of<string,
|
|
19
|
-
type v3 = of<string,
|
|
20
|
-
type v4 = of<string,
|
|
21
|
-
type v5 = of<string,
|
|
22
|
-
type v6 = of<string,
|
|
23
|
-
type v7 = of<string,
|
|
24
|
-
type v8 = of<string,
|
|
17
|
+
type v1 = of<string, Nominal<"uuid.v1">>;
|
|
18
|
+
type v2 = of<string, Nominal<"uuid.v2">>;
|
|
19
|
+
type v3 = of<string, Nominal<"uuid.v3">>;
|
|
20
|
+
type v4 = of<string, Nominal<"uuid.v4">>;
|
|
21
|
+
type v5 = of<string, Nominal<"uuid.v5">>;
|
|
22
|
+
type v6 = of<string, Nominal<"uuid.v6">>;
|
|
23
|
+
type v7 = of<string, Nominal<"uuid.v7">>;
|
|
24
|
+
type v8 = of<string, Nominal<"uuid.v8">>;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
export declare namespace uuid {
|
package/out/keywords/ts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hkt, type Json, type Key, type omit, type pick, type show } from "@ark/util";
|
|
2
|
+
import type { To } from "../attributes.ts";
|
|
2
3
|
import type { Module, Submodule } from "../module.ts";
|
|
3
|
-
import type { To } from "./inference.ts";
|
|
4
4
|
export declare const arkTsKeywords: arkTsKeywords;
|
|
5
5
|
export type arkTsKeywords = Module<arkTsKeywords.$>;
|
|
6
6
|
export declare namespace arkTsKeywords {
|
package/out/methods/array.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { associateAttributesFromSchema } from "../attributes.ts";
|
|
3
3
|
import type { ObjectType } from "./object.ts";
|
|
4
4
|
interface Type<
|
|
5
5
|
/** @ts-ignore cast variance */
|
|
6
6
|
out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> {
|
|
7
|
-
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
11
|
-
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<
|
|
7
|
+
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", schema>, $>;
|
|
8
|
+
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", schema>, $>;
|
|
9
|
+
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
|
|
11
|
+
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "exactLength", schema>, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as ArrayType };
|
package/out/methods/base.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, PredicateCast,
|
|
1
|
+
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, Predicate, PredicateCast, StandardSchema, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
+
import type { associateAttributes, associateAttributesFromSchema, brandAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Nominal, Optional, Out, To } from "../attributes.ts";
|
|
3
4
|
import type { ArkAmbient } from "../config.ts";
|
|
4
|
-
import type { applyAttribute, applyConstraintSchema, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, Out, To } from "../keywords/inference.ts";
|
|
5
5
|
import type { type } from "../keywords/keywords.ts";
|
|
6
6
|
import type { Scope } from "../scope.ts";
|
|
7
7
|
import type { ArrayType } from "./array.ts";
|
|
8
8
|
import type { instantiateType } from "./instantiate.ts";
|
|
9
9
|
/** @ts-ignore cast variance */
|
|
10
|
-
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
|
|
10
|
+
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors, StandardSchema.ConstantProps> {
|
|
11
11
|
[inferred]: t;
|
|
12
12
|
t: t;
|
|
13
13
|
infer: this["inferOut"];
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
inferInWithAttributes: distill.withAttributes.In<t>;
|
|
15
|
+
inferOutWithAttributes: distill.withAttributes.Out<t>;
|
|
16
16
|
inferIntrospectableOut: distill.introspectable.Out<t>;
|
|
17
17
|
inferOut: distill.Out<t>;
|
|
18
18
|
inferIn: distill.In<t>;
|
|
19
19
|
inferredOutIsIntrospectable: t extends InferredMorph<any, infer o> ? [
|
|
20
20
|
o
|
|
21
21
|
] extends [anyOrNever] ? true : o extends To ? true : false : unknown extends t ? boolean : true;
|
|
22
|
+
/** Internal JSON representation of this `Type` */
|
|
22
23
|
json: Json;
|
|
23
24
|
toJSON(): Json;
|
|
24
25
|
meta: ArkAmbient.meta;
|
|
@@ -28,24 +29,97 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
28
29
|
expression: string;
|
|
29
30
|
internal: BaseRoot;
|
|
30
31
|
$: Scope<$>;
|
|
32
|
+
/**
|
|
33
|
+
* Validate data, throwing `type.errors` instance on failure
|
|
34
|
+
* @returns a valid value
|
|
35
|
+
* @example const validData = T.assert(rawData)
|
|
36
|
+
*/
|
|
31
37
|
assert(data: unknown): this["infer"];
|
|
38
|
+
/**
|
|
39
|
+
* Check if data matches the input shape.
|
|
40
|
+
* Doesn't process any morphs, but does check narrows.
|
|
41
|
+
* @example type({ foo: "number" }).allows({ foo: "bar" }) // false
|
|
42
|
+
*/
|
|
32
43
|
allows(data: unknown): data is this["inferIn"];
|
|
33
44
|
traverse(data: unknown): this["infer"] | ArkErrors;
|
|
34
|
-
brandable(): this;
|
|
35
45
|
configure(meta: MetaSchema): this;
|
|
36
46
|
describe(description: string): this;
|
|
47
|
+
/**
|
|
48
|
+
* Create a copy of this `Type` with updated unknown key behavior
|
|
49
|
+
* - `ignore`: ignore unknown properties (default)
|
|
50
|
+
* - 'reject': disallow objects with unknown properties
|
|
51
|
+
* - 'delete': clone the object and keep only known properties
|
|
52
|
+
*/
|
|
37
53
|
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
54
|
+
/**
|
|
55
|
+
* Create a copy of this `Type` with updated unknown key behavior\
|
|
56
|
+
* The behavior applies to the whole object tree, not just the immediate properties.
|
|
57
|
+
* - `ignore`: ignore unknown properties (default)
|
|
58
|
+
* - 'reject': disallow objects with unknown properties
|
|
59
|
+
* - 'delete': clone the object and keep only known properties
|
|
60
|
+
*/
|
|
38
61
|
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
62
|
+
/**
|
|
63
|
+
* Identical to `assert`, but with a typed input as a convenience for providing a typed value.
|
|
64
|
+
* @example const ConfigT = type({ foo: "string" }); export const config = ConfigT.from({ foo: "bar" })
|
|
65
|
+
*/
|
|
39
66
|
from(literal: this["inferIn"]): this["infer"];
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Cast the way this `Type` is inferred (has no effect at runtime).
|
|
69
|
+
* const branded = type(/^a/).as<`a${string}`>() // Type<`a${string}`>
|
|
70
|
+
*/
|
|
71
|
+
as<castTo = unset>(...args: validateChainedAsArgs<castTo>): instantiateType<castTo, $>;
|
|
72
|
+
brand<const name extends string, r = brandAttributes<t, Nominal<name>>>(name: name): instantiateType<r, $>;
|
|
73
|
+
brandAttributes(): instantiateType<distill.brand<t>, $>;
|
|
74
|
+
unbrandAttributes(): instantiateType<distill.unbrand<t>, $>;
|
|
75
|
+
/**
|
|
76
|
+
* A `Type` representing the deeply-extracted input of the `Type` (before morphs are applied).
|
|
77
|
+
* @example const inputT = T.in
|
|
78
|
+
*/
|
|
79
|
+
get in(): instantiateType<this["inferInWithAttributes"], $>;
|
|
80
|
+
/**
|
|
81
|
+
* A `Type` representing the deeply-extracted output of the `Type` (after morphs are applied).\
|
|
82
|
+
* **IMPORTANT**: If your type includes morphs, their output will likely be unknown
|
|
83
|
+
* unless they were defined with an explicit output validator via `.to(outputType)`, `.pipe(morph, outputType)`, etc.
|
|
84
|
+
* @example const outputT = T.out
|
|
85
|
+
*/
|
|
42
86
|
get out(): instantiateType<this["inferIntrospectableOut"], $>;
|
|
87
|
+
/**
|
|
88
|
+
* Intersect another `Type` definition, returning an introspectable `Disjoint` if the result is unsatisfiable.
|
|
89
|
+
* @example const intersection = type({ foo: "number" }).intersect({ bar: "string" }) // Type<{ foo: number; bar: string }>
|
|
90
|
+
* @example const intersection = type({ foo: "number" }).intersect({ foo: "string" }) // Disjoint
|
|
91
|
+
*/
|
|
43
92
|
intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
|
|
93
|
+
/**
|
|
94
|
+
* Intersect another `Type` definition, throwing an error if the result is unsatisfiable.
|
|
95
|
+
* @example const intersection = type({ foo: "number" }).intersect({ bar: "string" }) // Type<{ foo: number; bar: string }>
|
|
96
|
+
*/
|
|
44
97
|
and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
|
|
98
|
+
/**
|
|
99
|
+
* Union another `Type` definition.\
|
|
100
|
+
* If the types contain morphs, input shapes should be distinct. Otherwise an error will be thrown.
|
|
101
|
+
* @example const union = type({ foo: "number" }).or({ foo: "string" }) // Type<{ foo: number } | { foo: string }>
|
|
102
|
+
* @example const union = type("string.numeric.parse").or("number") // Type<((In: string) => Out<number>) | number>
|
|
103
|
+
*/
|
|
45
104
|
or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
|
|
46
|
-
|
|
47
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Add a custom predicate to this `Type`.
|
|
107
|
+
* @example const nan = type('number').narrow(n => Number.isNaN(n)) // Type<number>
|
|
108
|
+
* @example const foo = type("string").narrow((s): s is `foo${string}` => s.startsWith('foo') || ctx.mustBe('string starting with "foo"')) // Type<"foo${string}">
|
|
109
|
+
* @example const unique = type('string[]').narrow((a, ctx) => new Set(a).size === a.length || ctx.mustBe('array with unique elements'))
|
|
110
|
+
*/
|
|
111
|
+
narrow<narrowed extends this["infer"] = never, r = [narrowed] extends [never] ? t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<associateAttributesFromSchema<o[1], "predicate", Predicate>> : (In: i) => Out<associateAttributesFromSchema<o[1], "predicate", Predicate>> : associateAttributesFromSchema<t, "predicate", Predicate> : t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<narrowed> : (In: i) => Out<narrowed> : narrowed>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<r, $>;
|
|
112
|
+
satisfying<narrowed extends this["inferIn"] = never, r = [narrowed] extends [never] ? associateAttributesFromSchema<t, "predicate", Predicate> : t extends InferredMorph<any, infer o> ? (In: narrowed) => o : narrowed>(predicate: Predicate<this["inferIn"]> | PredicateCast<this["inferIn"], narrowed>): instantiateType<r, $>;
|
|
113
|
+
/**
|
|
114
|
+
* Create a `Type` for array with elements of this `Type`
|
|
115
|
+
* @example const T = type(/^foo/); const array = T.array() // Type<string[]>
|
|
116
|
+
*/
|
|
48
117
|
array(): ArrayType<t[], $>;
|
|
118
|
+
/**
|
|
119
|
+
* Morph this `Type` through a chain of morphs.
|
|
120
|
+
* @example const dedupe = type('string[]').pipe(a => Array.from(new Set(a)))
|
|
121
|
+
* @example type({codes: 'string.numeric[]'}).pipe(obj => obj.codes).to('string.numeric.parse[]')
|
|
122
|
+
*/
|
|
49
123
|
pipe: ChainedPipes<t, $>;
|
|
50
124
|
equals<const def>(def: type.validate<def, $>): boolean;
|
|
51
125
|
ifEquals<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<r, $> | undefined;
|
|
@@ -55,8 +129,18 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
55
129
|
extract<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Extract<t, r>, $>;
|
|
56
130
|
exclude<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Exclude<t, r>, $>;
|
|
57
131
|
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
|
|
58
|
-
optional<r =
|
|
59
|
-
|
|
132
|
+
optional<r = associateAttributes<t, Optional>>(): instantiateType<r, $>;
|
|
133
|
+
/**
|
|
134
|
+
* Add a default value for this `Type` when it is used as a property.\
|
|
135
|
+
* Default value should be a valid input value for this `Type, or a function that returns a valid input value.\
|
|
136
|
+
* If the type has a morph, it will be applied to the default value.
|
|
137
|
+
* @example const withDefault = type({ foo: type("string").default("bar") }); withDefault({}) // { foo: "bar" }
|
|
138
|
+
* @example const withFactory = type({ foo: type("number[]").default(() => [1])) }); withFactory({baz: 'a'}) // { foo: [1], baz: 'a' }
|
|
139
|
+
* @example const withMorph = type({ foo: type("string.numeric.parse").default("123") }); withMorph({}) // { foo: 123 }
|
|
140
|
+
*/
|
|
141
|
+
default<const value extends this["inferIn"], r = associateAttributes<t, Default<value>>>(value: DefaultFor<value>): instantiateType<r, $>;
|
|
142
|
+
"~validate": StandardSchema.Validator<this["inferOut"]>;
|
|
143
|
+
"~types": StandardSchema.Types<this["inferIn"], this["inferOut"]>;
|
|
60
144
|
/** @deprecated */
|
|
61
145
|
apply: Function["apply"];
|
|
62
146
|
/** @deprecated */
|
package/out/methods/date.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { associateAttributesFromSchema } from "../attributes.ts";
|
|
3
3
|
import type { ObjectType } from "./object.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
|
|
6
|
-
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<
|
|
7
|
-
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<
|
|
8
|
-
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<
|
|
9
|
-
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<
|
|
6
|
+
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "after", schema>, $>;
|
|
7
|
+
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "before", schema>, $>;
|
|
8
|
+
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "after", exclusivizeRangeSchema<schema>>, $>;
|
|
9
|
+
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "before", exclusivizeRangeSchema<schema>>, $>;
|
|
10
10
|
}
|
|
11
11
|
export type { Type as DateType };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { anyOrNever, array } from "@ark/util";
|
|
2
|
-
import type { InferredMorph } from "../
|
|
2
|
+
import type { InferredMorph } from "../attributes.ts";
|
|
3
3
|
import type { ArrayType } from "./array.ts";
|
|
4
4
|
import type { BaseType } from "./base.ts";
|
|
5
5
|
import type { DateType } from "./date.ts";
|
package/out/methods/morph.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { inferPipe } from "../
|
|
1
|
+
import type { inferPipe } from "../attributes.ts";
|
|
2
2
|
import type { type } from "../keywords/keywords.ts";
|
|
3
3
|
import type { BaseType } from "./base.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
6
|
+
/**
|
|
7
|
+
* Append extra validation shape on the pipe output
|
|
8
|
+
* @example type({codes: 'string.numeric[]'}).pipe(obj => obj.codes).to('string.numeric.parse[]')
|
|
9
|
+
*/
|
|
6
10
|
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
|
|
7
11
|
}
|
|
8
12
|
export type { Type as MorphType };
|
package/out/methods/number.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { associateAttributesFromSchema } from "../attributes.ts";
|
|
3
3
|
import type { BaseType } from "./base.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends number = number, $ = {}> extends BaseType<t, $> {
|
|
6
|
-
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<
|
|
7
|
-
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
6
|
+
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "divisor", schema>, $>;
|
|
7
|
+
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "min", schema>, $>;
|
|
8
|
+
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "max", schema>, $>;
|
|
9
|
+
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "min", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "max", exclusivizeRangeSchema<schema>>, $>;
|
|
11
11
|
}
|
|
12
12
|
export type { Type as NumberType };
|
package/out/methods/object.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
|
|
2
2
|
import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
|
|
3
|
-
import type {
|
|
3
|
+
import type { associateAttributes, Attributes, Default, of, Optional } from "../attributes.ts";
|
|
4
4
|
import type { type } from "../keywords/keywords.ts";
|
|
5
5
|
import type { ArrayType } from "./array.ts";
|
|
6
6
|
import type { BaseType } from "./base.ts";
|
|
@@ -13,27 +13,55 @@ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
|
|
|
13
13
|
readonly [k in keyof t]: t[k];
|
|
14
14
|
}, $>;
|
|
15
15
|
keyof(): instantiateType<arkKeyOf<t>, $>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the `Type` of a property of this `Type<object>`.
|
|
18
|
+
* @example type({ foo: "string" }).get("foo") // Type<string>
|
|
19
|
+
*/
|
|
16
20
|
get<const k1 extends arkIndexableOf<t>, r = arkGet<t, k1>>(k1: k1 | type.cast<k1>): instantiateType<r, $>;
|
|
17
21
|
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): instantiateType<arkGet<arkGet<t, k1>, k2>, $> extends infer r ? r : never;
|
|
18
22
|
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = arkGet<arkGet<arkGet<t, k1>, k2>, k3>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<r, $>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a copy of this `Type` with only the specified properties.
|
|
25
|
+
* @example type({ foo: "string", bar: "number" }).pick("foo") // Type<{ foo: string }>
|
|
26
|
+
*/
|
|
19
27
|
pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
20
28
|
[k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
|
|
21
29
|
}, $>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a copy of this `Type` with all properties except the specified ones.
|
|
32
|
+
* @example type({ foo: "string", bar: "number" }).omit("foo") // Type<{ bar: number }>
|
|
33
|
+
*/
|
|
22
34
|
omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
23
35
|
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
|
|
24
36
|
}, $>;
|
|
37
|
+
/**
|
|
38
|
+
* Merge another `Type` definition, overriding properties of this `Type` with the duplicate keys.
|
|
39
|
+
* @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1, b: 3, c: 4 }>
|
|
40
|
+
*/
|
|
25
41
|
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a copy of this `Type` with all properties required.
|
|
44
|
+
* @example const T = type({ "foo?"": "string" }).required() // Type<{ foo: string }>
|
|
45
|
+
*/
|
|
26
46
|
required(): Type<{
|
|
27
47
|
[k in keyof t]-?: t[k];
|
|
28
48
|
}, $>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a copy of this `Type` with all properties optional.
|
|
51
|
+
* @example: const T = type({ foo: "string" }).optional() // Type<{ foo?: string }>
|
|
52
|
+
*/
|
|
29
53
|
partial(): Type<{
|
|
30
54
|
[k in keyof t]?: t[k];
|
|
31
55
|
}, $>;
|
|
32
56
|
map<transformed extends listable<MappedTypeProp>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
|
|
57
|
+
/**
|
|
58
|
+
* List of property info of this `Type<object>`.
|
|
59
|
+
* @example type({ foo: "string = "" }).props // [{ kind: "required", key: "foo", value: Type<string>, default: "" }]
|
|
60
|
+
*/
|
|
33
61
|
props: array<typePropOf<t, $>>;
|
|
34
62
|
}
|
|
35
63
|
type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
|
|
36
|
-
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default
|
|
64
|
+
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default> extends (infer attributes extends Attributes) ? attributes : never>, defaultValue, $> : attributes extends Optional ? BaseTypeProp<"optional", k & Key, keyof attributes extends keyof Optional ? base : of<base, Omit<attributes, keyof Default> extends (infer attributes extends Attributes) ? attributes : never>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
|
|
37
65
|
export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
|
|
38
66
|
/** @ts-ignore cast variance */
|
|
39
67
|
out v = unknown, $ = {}> {
|
|
@@ -70,7 +98,7 @@ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
|
|
|
70
98
|
[prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
|
|
71
99
|
kind: "optional";
|
|
72
100
|
default: unknown;
|
|
73
|
-
}>["key"]]:
|
|
101
|
+
}>["key"]]: associateAttributes<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
|
|
74
102
|
}>;
|
|
75
103
|
type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
|
|
76
104
|
kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
|
package/out/methods/string.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { associateAttributesFromSchema } from "../attributes.ts";
|
|
3
3
|
import type { BaseType } from "./base.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> {
|
|
6
|
-
matching<const schema extends Pattern.Schema>(schema: schema): Type<
|
|
7
|
-
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
11
|
-
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<
|
|
6
|
+
matching<const schema extends Pattern.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "pattern", schema>, $>;
|
|
7
|
+
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", schema>, $>;
|
|
8
|
+
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", schema>, $>;
|
|
9
|
+
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
|
|
11
|
+
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "exactLength", schema>, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as StringType };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { writeUnboundableMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage, array, typeToString } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "../../
|
|
3
|
+
import type { LimitLiteral } from "../../attributes.ts";
|
|
4
4
|
import type { Comparator } from "../reduce/shared.ts";
|
|
5
5
|
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../shift/operator/bounds.ts";
|
|
6
6
|
import type { inferAstIn } from "./infer.ts";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { GenericAst } from "@ark/schema";
|
|
2
2
|
import type { Hkt, arkKeyOf, array } from "@ark/util";
|
|
3
|
+
import type { After, AtLeast, AtLeastLength, AtMost, AtMostLength, AtOrAfter, AtOrBefore, Before, Default, DivisibleBy, ExactlyLength, LessThan, LessThanLength, LimitLiteral, MoreThan, MoreThanLength, Nominal, Optional, associateAttributes, brandAttributes, distill, inferIntersection, normalizeLimit } from "../../attributes.ts";
|
|
3
4
|
import type { Date } from "../../keywords/constructors/Date.ts";
|
|
4
|
-
import type { Default, LimitLiteral, Optional, Predicate, applyAttribute, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
|
|
5
5
|
import type { type } from "../../keywords/keywords.ts";
|
|
6
6
|
import type { UnparsedScope } from "../../scope.ts";
|
|
7
7
|
import type { inferDefinition } from "../definition.ts";
|
|
8
|
-
import type { Comparator
|
|
8
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
9
9
|
import type { Scanner } from "../shift/scanner.ts";
|
|
10
10
|
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
11
11
|
export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
|
|
@@ -26,11 +26,12 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
|
|
|
26
26
|
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
27
27
|
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
28
28
|
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
29
|
-
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ?
|
|
30
|
-
export type
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? associateAttributes<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends "#" ? brandAttributes<inferExpression<ast[0], $, args>, Nominal<ast[2]>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? attachBoundAttributes<inferExpression<ast[2], $, args>, ast[1], ast[0]> : attachBoundAttributes<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? associateAttributes<inferExpression<ast[0], $, args>, DivisibleBy<ast[2]>> : ast[1] extends "?" ? associateAttributes<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
30
|
+
export type attachBoundAttributes<inWithAttributes, comparator extends Comparator, limit extends LimitLiteral> = distill.In<inWithAttributes> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.nominal<normalizeLimit<limit>> : associateAttributes<inWithAttributes, ExactlyLength<limit>> : associateAttributes<inWithAttributes, boundToAttributes<In, comparator, limit>> : never;
|
|
31
|
+
export type boundToAttributes<In, comparator extends Comparator, limit extends LimitLiteral> = In extends string | array ? lengthBoundToAttributes<comparator, limit & number> : In extends Date ? dateBoundToAttributes<comparator, normalizeLimit<limit>> : numericBoundToAttributes<comparator, limit & number>;
|
|
32
|
+
type lengthBoundToAttributes<comparator extends Comparator, limit extends number> = comparator extends "<" ? LessThanLength<limit> : comparator extends "<=" ? AtMostLength<limit> : comparator extends ">" ? MoreThanLength<limit> : AtLeastLength<limit>;
|
|
33
|
+
type dateBoundToAttributes<comparator extends Comparator, limit extends string | number> = comparator extends "<" ? Before<limit> : comparator extends "<=" ? AtOrBefore<limit> : comparator extends ">" ? After<limit> : AtOrAfter<limit>;
|
|
34
|
+
type numericBoundToAttributes<comparator extends Comparator, limit extends number> = comparator extends "<" ? LessThan<limit> : comparator extends "<=" ? AtMost<limit> : comparator extends ">" ? MoreThan<limit> : AtLeast<limit>;
|
|
34
35
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
35
36
|
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
36
37
|
export type PostfixExpression<operator extends Scanner.PostfixToken = Scanner.PostfixToken, operand = unknown> = readonly [operand, operator];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
2
|
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
|
-
import type { of } from "../
|
|
3
|
+
import type { of } from "../attributes.ts";
|
|
4
4
|
import type { astToString } from "./ast/utils.ts";
|
|
5
5
|
import type { validateString } from "./ast/validate.ts";
|
|
6
6
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|