arktype 2.0.0-rc.2 → 2.0.0-rc.22
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 +274 -0
- package/out/attributes.js +2 -0
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +52 -55
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +37 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/keywords.d.ts +64 -0
- package/out/keywords/{ark.js → keywords.js} +14 -9
- package/out/keywords/number/epoch.d.ts +1 -1
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +44 -14
- package/out/keywords/number/number.js +17 -5
- 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 +21 -0
- package/out/keywords/string/base64.js +6 -0
- package/out/keywords/string/capitalize.d.ts +3 -3
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +2 -2
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +7 -11
- package/out/keywords/string/date.js +16 -16
- 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 +3 -3
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +5 -5
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +4 -3
- package/out/keywords/string/json.js +39 -30
- package/out/keywords/string/lower.d.ts +3 -3
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +27 -31
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +3 -3
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +2 -2
- package/out/keywords/string/string.d.ts +74 -51
- package/out/keywords/string/string.js +5 -3
- package/out/keywords/string/trim.d.ts +3 -3
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +3 -3
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +3 -3
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +20 -20
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +38 -1
- package/out/keywords/ts.js +20 -4
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +183 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +12 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +13 -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/infer.d.ts +39 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +10 -10
- package/out/parser/ast/validate.js +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +14 -40
- package/out/parser/objectLiteral.js +8 -26
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +9 -12
- 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 +6 -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 +14 -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/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 +3 -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 +42 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +60 -44
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +38 -39
- package/out/scope.js +47 -36
- package/out/type.d.ts +45 -21
- package/out/type.js +14 -10
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.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.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/subtypes/base.d.ts +0 -85
- 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/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{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/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
package/out/keywords/ark.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ArkErrors, arkKind } from "@ark/schema";
|
|
2
|
-
import type { inferred } from "@ark/util";
|
|
3
|
-
import type { GenericParser } from "../generic.ts";
|
|
4
|
-
import type { BoundModule, Module } from "../module.ts";
|
|
5
|
-
import { type Scope } from "../scope.ts";
|
|
6
|
-
import type { DeclarationParser, DefinitionParser, TypeParser } from "../type.ts";
|
|
7
|
-
import { arkBuiltins } from "./builtins.ts";
|
|
8
|
-
import { arkPrototypes } from "./constructors/constructors.ts";
|
|
9
|
-
import { number } from "./number/number.ts";
|
|
10
|
-
import { string } from "./string/string.ts";
|
|
11
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.ts";
|
|
12
|
-
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
13
|
-
}
|
|
14
|
-
export declare namespace Ark {
|
|
15
|
-
interface keywords extends arkTsKeywords.$, arkTsGenerics.$, arkPrototypes.keywords, arkBuiltins.$ {
|
|
16
|
-
}
|
|
17
|
-
interface wrapped extends arkPrototypes.wrapped {
|
|
18
|
-
string: string.submodule;
|
|
19
|
-
number: number.submodule;
|
|
20
|
-
}
|
|
21
|
-
interface typeAttachments extends arkTsKeywords.$ {
|
|
22
|
-
Key: arkBuiltins.$["Key"];
|
|
23
|
-
Record: arkTsGenerics.$["Record"];
|
|
24
|
-
}
|
|
25
|
-
interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export declare const ambient: Scope<Ark>;
|
|
29
|
-
export declare const ark: Module<Ark>;
|
|
30
|
-
export declare const type: TypeParser<{}>;
|
|
31
|
-
export declare namespace type {
|
|
32
|
-
type cast<t> = {
|
|
33
|
-
[inferred]?: t;
|
|
34
|
-
};
|
|
35
|
-
type errors = ArkErrors;
|
|
36
|
-
}
|
|
37
|
-
export declare const generic: GenericParser<{}>;
|
|
38
|
-
export declare const define: DefinitionParser<{}>;
|
|
39
|
-
export declare const declare: DeclarationParser<{}>;
|
package/out/keywords/ast.d.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type conform, type equals, type leftIfEqual, type Primitive, type show } from "@ark/util";
|
|
3
|
-
import type { inferPipe } from "../intersect.ts";
|
|
4
|
-
import type { Type } from "../type.ts";
|
|
5
|
-
import type { type } from "./ark.ts";
|
|
6
|
-
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
7
|
-
import type { number } from "./number/number.ts";
|
|
8
|
-
import type { string } from "./string/string.ts";
|
|
9
|
-
export type { arkPrototypes as object } from "./constructors/constructors.ts";
|
|
10
|
-
export type { number } from "./number/number.ts";
|
|
11
|
-
export type { string } from "./string/string.ts";
|
|
12
|
-
export type Comparator = "<" | "<=" | ">" | ">=" | "==";
|
|
13
|
-
export type RegexLiteral<source extends string = string> = `/${source}/`;
|
|
14
|
-
export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
|
|
15
|
-
export type ConstraintSet = Record<PropertyKey, 1>;
|
|
16
|
-
export type Constraints = Record<string, ConstraintSet>;
|
|
17
|
-
export declare const constrained: " arkConstrained";
|
|
18
|
-
export type constrained = typeof constrained;
|
|
19
|
-
export type constrain<base, constraints extends Constraints> = base & {
|
|
20
|
-
[constrained]: constraints;
|
|
21
|
-
};
|
|
22
|
-
export type LimitLiteral = number | DateLiteral;
|
|
23
|
-
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
24
|
-
type constraint<rule> = {
|
|
25
|
-
[k in rule & PropertyKey]: 1;
|
|
26
|
-
};
|
|
27
|
-
export type AtLeast<rule> = {
|
|
28
|
-
atLeast: constraint<rule>;
|
|
29
|
-
};
|
|
30
|
-
export type AtMost<rule> = {
|
|
31
|
-
atMost: constraint<rule>;
|
|
32
|
-
};
|
|
33
|
-
export type MoreThan<rule> = {
|
|
34
|
-
moreThan: constraint<rule>;
|
|
35
|
-
};
|
|
36
|
-
export type LessThan<rule> = {
|
|
37
|
-
lessThan: constraint<rule>;
|
|
38
|
-
};
|
|
39
|
-
export type Literal<rule> = {
|
|
40
|
-
literal: constraint<rule>;
|
|
41
|
-
};
|
|
42
|
-
export type DivisibleBy<rule> = {
|
|
43
|
-
divisibleBy: constraint<rule>;
|
|
44
|
-
};
|
|
45
|
-
export type Length<rule> = {
|
|
46
|
-
length: constraint<rule>;
|
|
47
|
-
};
|
|
48
|
-
export type Matching<rule> = {
|
|
49
|
-
matching: constraint<rule>;
|
|
50
|
-
};
|
|
51
|
-
export type Narrowed = {
|
|
52
|
-
predicate: {
|
|
53
|
-
[k in "?"]: 1;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
export type Branded<rule> = {
|
|
57
|
-
predicate: constraint<rule>;
|
|
58
|
-
};
|
|
59
|
-
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
60
|
-
export type AtLeastLength<rule> = {
|
|
61
|
-
atLeastLength: constraint<rule>;
|
|
62
|
-
};
|
|
63
|
-
export type AtMostLength<rule> = {
|
|
64
|
-
atMostLength: constraint<rule>;
|
|
65
|
-
};
|
|
66
|
-
export type MoreThanLength<rule> = {
|
|
67
|
-
moreThanLength: constraint<rule>;
|
|
68
|
-
};
|
|
69
|
-
export type LessThanLength<rule> = {
|
|
70
|
-
lessThanLength: constraint<rule>;
|
|
71
|
-
};
|
|
72
|
-
export type ExactlyLength<rule> = {
|
|
73
|
-
atLeastLength: constraint<rule>;
|
|
74
|
-
atMostLength: constraint<rule>;
|
|
75
|
-
};
|
|
76
|
-
export type AtOrAfter<rule> = {
|
|
77
|
-
atOrAfter: constraint<rule>;
|
|
78
|
-
};
|
|
79
|
-
export type AtOrBefore<rule> = {
|
|
80
|
-
atOrBefore: constraint<rule>;
|
|
81
|
-
};
|
|
82
|
-
export type After<rule> = {
|
|
83
|
-
after: constraint<rule>;
|
|
84
|
-
};
|
|
85
|
-
export type Before<rule> = {
|
|
86
|
-
before: constraint<rule>;
|
|
87
|
-
};
|
|
88
|
-
export declare namespace Date {
|
|
89
|
-
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
90
|
-
type after<rule> = constrain<Date, After<rule>>;
|
|
91
|
-
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
92
|
-
type before<rule> = constrain<Date, Before<rule>>;
|
|
93
|
-
type narrowed = constrain<Date, Narrowed>;
|
|
94
|
-
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
95
|
-
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
96
|
-
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
97
|
-
type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "after" ? schema extends {
|
|
98
|
-
exclusive: true;
|
|
99
|
-
} ? after<normalizeLimit<rule>> : atOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
|
|
100
|
-
exclusive: true;
|
|
101
|
-
} ? before<normalizeLimit<rule>> : atOrBefore<normalizeLimit<rule>> : narrowed : never;
|
|
102
|
-
}
|
|
103
|
-
export type applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, kind, schema>>) => o : leftIfEqual<t, _applyConstraint<t, kind, schema>>;
|
|
104
|
-
type _applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = schemaToConstraint<kind, schema> extends infer constraint ? parseConstraints<t> extends ([
|
|
105
|
-
infer base,
|
|
106
|
-
infer constraints extends Constraints
|
|
107
|
-
]) ? [
|
|
108
|
-
number,
|
|
109
|
-
base
|
|
110
|
-
] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.parseConstraint<kind, schema> : [string, t] extends [t, string] ? string.parseConstraint<kind, schema> : [Date, t] extends [t, Date] ? Date.parseConstraint<kind, schema> : constrain<t, conform<constraint, Constraints>> : never;
|
|
111
|
-
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
112
|
-
[constrained]: constraints;
|
|
113
|
-
}> extends true ? [
|
|
114
|
-
number,
|
|
115
|
-
constraints
|
|
116
|
-
] : equals<t, string & {
|
|
117
|
-
[constrained]: constraints;
|
|
118
|
-
}> extends true ? [
|
|
119
|
-
string,
|
|
120
|
-
constraints
|
|
121
|
-
] : equals<t, Date & {
|
|
122
|
-
[constrained]: constraints;
|
|
123
|
-
}> extends true ? [
|
|
124
|
-
Date,
|
|
125
|
-
constraints
|
|
126
|
-
] : [base, constraints] : null;
|
|
127
|
-
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
128
|
-
export type schemaToConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "exactLength" ? Length<rule> : kind extends "min" ? schema extends {
|
|
129
|
-
exclusive: true;
|
|
130
|
-
} ? MoreThan<rule> : AtLeast<rule> : kind extends "max" ? schema extends {
|
|
131
|
-
exclusive: true;
|
|
132
|
-
} ? LessThan<rule> : AtMost<rule> : kind extends "minLength" ? schema extends {
|
|
133
|
-
exclusive: true;
|
|
134
|
-
} ? MoreThanLength<rule> : AtLeastLength<rule> : kind extends "maxLength" ? schema extends {
|
|
135
|
-
exclusive: true;
|
|
136
|
-
} ? LessThanLength<rule> : AtMostLength<rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? schema extends {
|
|
137
|
-
exclusive: true;
|
|
138
|
-
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
|
|
139
|
-
exclusive: true;
|
|
140
|
-
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>> : Narrowed : never;
|
|
141
|
-
export type distillIn<t> = finalizeDistillation<t, _distill<t, "in", "base">>;
|
|
142
|
-
export type distillOut<t> = finalizeDistillation<t, _distill<t, "out", "base">>;
|
|
143
|
-
export type distillConstrainableIn<t> = finalizeDistillation<t, _distill<t, "in", "constrainable">>;
|
|
144
|
-
export type distillConstrainableOut<t> = finalizeDistillation<t, _distill<t, "out", "constrainable">>;
|
|
145
|
-
export type distillValidatedOut<t> = finalizeDistillation<t, _distill<t, "validatedOut", "constrainable">>;
|
|
146
|
-
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
147
|
-
export type includesMorphs<t> = [
|
|
148
|
-
_distill<t, "in", "constrainable">,
|
|
149
|
-
_distill<t, "out", "constrainable">
|
|
150
|
-
] extends ([
|
|
151
|
-
_distill<t, "out", "constrainable">,
|
|
152
|
-
_distill<t, "in", "constrainable">
|
|
153
|
-
]) ? false : true;
|
|
154
|
-
type IoKind = "in" | "out" | "validatedOut";
|
|
155
|
-
type DistilledKind = "base" | "constrainable";
|
|
156
|
-
type _distill<t, io extends IoKind, distilledKind extends DistilledKind> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
157
|
-
infer base,
|
|
158
|
-
infer constraints extends Constraints
|
|
159
|
-
]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : constrain<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : io extends "validatedOut" ? o extends To<infer validatedOut> ? _distill<validatedOut, io, distilledKind> : unknown : _distill<o[1], io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : {
|
|
160
|
-
[k in keyof t]: t[k];
|
|
161
|
-
} extends t ? io extends "in" ? show<{
|
|
162
|
-
[k in keyof t as k extends defaultableKeyOf<t> ? never : k]: _distill<t[k], io, distilledKind>;
|
|
163
|
-
} & {
|
|
164
|
-
[k in defaultableKeyOf<t>]?: _distill<t[k], io, distilledKind>;
|
|
165
|
-
}> : {
|
|
166
|
-
[k in keyof t]: _distill<t[k], io, distilledKind>;
|
|
167
|
-
} : t;
|
|
168
|
-
export type defaultableKeyOf<t> = {
|
|
169
|
-
[k in keyof t]: [t[k]] extends [anyOrNever] ? never : t[k] extends DefaultableAst ? k : never;
|
|
170
|
-
}[keyof t];
|
|
171
|
-
type distillArray<t extends array, io extends IoKind, constraints extends DistilledKind, prefix extends array> = _distillArray<t, io, constraints, prefix> extends infer result ? t extends unknown[] ? result : Readonly<t> : never;
|
|
172
|
-
type _distillArray<t extends array, io extends IoKind, constraints extends DistilledKind, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, io, constraints, [
|
|
173
|
-
...prefix,
|
|
174
|
-
_distill<head, io, constraints>
|
|
175
|
-
]> : [...prefix, ...distillPostfix<t, io, constraints>];
|
|
176
|
-
type distillPostfix<t extends array, io extends IoKind, constraints extends DistilledKind, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, io, constraints, [
|
|
177
|
-
_distill<last, io, constraints>,
|
|
178
|
-
...postfix
|
|
179
|
-
]> : [...{
|
|
180
|
-
[i in keyof t]: _distill<t[i], io, constraints>;
|
|
181
|
-
}, ...postfix];
|
|
182
|
-
/** Objects we don't want to expand during inference like Date or Promise */
|
|
183
|
-
type TerminallyInferredObjectKind = arkPrototypes.instanceOfExcluding<"Array" | "Function"> | ArkEnv.prototypes;
|
|
184
|
-
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<narrowed, constraints>, "predicate", any> : applyConstraint<narrowed, "predicate", any> : applyConstraint<t, "predicate", any>;
|
|
185
|
-
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<t, constraints>, "predicate", any> : applyConstraint<t, "predicate", any>;
|
|
186
|
-
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t;
|
|
187
|
-
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
188
|
-
export type Out<o = any> = ["=>", o, boolean];
|
|
189
|
-
export type To<o = any> = ["=>", o, true];
|
|
190
|
-
export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
|
|
191
|
-
export type Default<v = any> = ["=", v];
|
|
192
|
-
export type DefaultableAst<t = any, v = any> = (In?: t) => Default<v>;
|
|
193
|
-
export type termOrType<t> = t | Type<t, any>;
|
package/out/keywords/ast.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ErrorMessage } from "@ark/util";
|
|
2
|
-
import type { inferAmbient } from "../../type.ts";
|
|
3
|
-
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
4
|
-
import type { inferAstOut } from "./infer.ts";
|
|
5
|
-
import type { astToString } from "./utils.ts";
|
|
6
|
-
import type { validateAst } from "./validate.ts";
|
|
7
|
-
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferAmbient<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
8
|
-
export declare const writeUnassignableDefaultValueMessage: <key extends string, message extends string>(key: key, message: message) => string;
|
|
9
|
-
export type writeUnassignableDefaultValueMessage<baseDef extends string, defaultValue extends string> = `Default value ${defaultValue} is not assignable to ${baseDef}`;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const writeUnassignableDefaultValueMessage = (key, message) => `Default value at ${key} ${message}`;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { GenericAst } from "@ark/schema";
|
|
2
|
-
import type { Hkt, array } from "@ark/util";
|
|
3
|
-
import type { inferIntersection } from "../../intersect.ts";
|
|
4
|
-
import type { Date, Default, LimitLiteral, applyConstraint, distillIn, distillOut, normalizeLimit } from "../../keywords/ast.ts";
|
|
5
|
-
import type { UnparsedScope } from "../../scope.ts";
|
|
6
|
-
import type { inferAmbient } from "../../type.ts";
|
|
7
|
-
import type { inferDefinition } from "../definition.ts";
|
|
8
|
-
import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
|
|
9
|
-
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
10
|
-
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
|
|
11
|
-
export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
|
|
12
|
-
export type DefAst<def = unknown, alias extends string = string> = [
|
|
13
|
-
def,
|
|
14
|
-
"def",
|
|
15
|
-
alias
|
|
16
|
-
];
|
|
17
|
-
export type InferredAst<t = unknown, def extends string = string> = [
|
|
18
|
-
t,
|
|
19
|
-
"inferred",
|
|
20
|
-
def
|
|
21
|
-
];
|
|
22
|
-
export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
23
|
-
type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
|
|
24
|
-
export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
|
|
25
|
-
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
26
|
-
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
27
|
-
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
28
|
-
}> : 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 "=" ? inferAmbient<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraint<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferExpression<ast[1], $, args> : never : never;
|
|
29
|
-
export type constrainBound<constrainableIn, comparator extends Comparator, limit extends LimitLiteral> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraint<constrainableIn, "exactLength", limit & number> : applyConstraint<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
30
|
-
rule: normalizeLimit<limit>;
|
|
31
|
-
exclusive: comparator extends ">" | "<" ? true : false;
|
|
32
|
-
}> : never;
|
|
33
|
-
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
34
|
-
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
35
|
-
export type PostfixOperator = "[]";
|
|
36
|
-
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
37
|
-
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
38
|
-
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
39
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type WhiteSpaceToken } from "@ark/util";
|
|
2
|
-
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
3
|
-
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
-
import type { BaseCompletions } from "../../string.ts";
|
|
5
|
-
import type { Scanner } from "../scanner.ts";
|
|
6
|
-
import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
|
|
7
|
-
import { parseUnenclosed } from "./unenclosed.ts";
|
|
8
|
-
export declare const parseOperand: (s: DynamicState) => void;
|
|
9
|
-
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type WhiteSpaceToken } from "@ark/util";
|
|
2
|
-
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
3
|
-
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
-
import { Scanner } from "../scanner.ts";
|
|
5
|
-
import { parseBound, type ComparatorStartChar } from "./bounds.ts";
|
|
6
|
-
import { parseDivisor } from "./divisor.ts";
|
|
7
|
-
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
8
|
-
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
9
|
-
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
10
|
-
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
11
|
-
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
12
|
-
type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
|
|
13
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { type Dict, type EscapeToken, type WhiteSpaceToken } from "@ark/util";
|
|
2
|
-
import type { Comparator } from "../reduce/shared.ts";
|
|
3
|
-
export declare class Scanner<lookahead extends string = string> {
|
|
4
|
-
private chars;
|
|
5
|
-
private i;
|
|
6
|
-
constructor(def: string);
|
|
7
|
-
/** Get lookahead and advance scanner by one */
|
|
8
|
-
shift(): lookahead;
|
|
9
|
-
get lookahead(): lookahead;
|
|
10
|
-
get nextLookahead(): string;
|
|
11
|
-
get length(): number;
|
|
12
|
-
shiftUntil(condition: Scanner.UntilCondition): string;
|
|
13
|
-
shiftUntilNextTerminator(): string;
|
|
14
|
-
shiftUntilNonWhitespace(): string;
|
|
15
|
-
jumpToIndex(i: number): void;
|
|
16
|
-
jumpForward(count: number): void;
|
|
17
|
-
get location(): number;
|
|
18
|
-
get unscanned(): string;
|
|
19
|
-
get scanned(): string;
|
|
20
|
-
sliceChars(start: number, end?: number): string;
|
|
21
|
-
lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
|
|
22
|
-
lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
|
|
23
|
-
static terminatingChars: {
|
|
24
|
-
readonly " ": true;
|
|
25
|
-
readonly "\n": true;
|
|
26
|
-
readonly "\t": true;
|
|
27
|
-
readonly "<": true;
|
|
28
|
-
readonly ">": true;
|
|
29
|
-
readonly "=": true;
|
|
30
|
-
readonly "|": true;
|
|
31
|
-
readonly "&": true;
|
|
32
|
-
readonly ")": true;
|
|
33
|
-
readonly "[": true;
|
|
34
|
-
readonly "%": true;
|
|
35
|
-
readonly ",": true;
|
|
36
|
-
readonly ":": true;
|
|
37
|
-
};
|
|
38
|
-
static finalizingLookaheads: {
|
|
39
|
-
readonly ">": true;
|
|
40
|
-
readonly ",": true;
|
|
41
|
-
readonly "": true;
|
|
42
|
-
readonly "=": true;
|
|
43
|
-
};
|
|
44
|
-
static lookaheadIsTerminator: Scanner.UntilCondition;
|
|
45
|
-
static lookaheadIsNotWhitespace: Scanner.UntilCondition;
|
|
46
|
-
static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
|
|
47
|
-
}
|
|
48
|
-
export declare namespace Scanner {
|
|
49
|
-
type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," ? true : false;
|
|
50
|
-
type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
|
|
51
|
-
type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
|
|
52
|
-
type ShiftUntilOptions = {
|
|
53
|
-
onInputEnd?: OnInputEndFn;
|
|
54
|
-
};
|
|
55
|
-
type TerminatingChar = keyof typeof Scanner.terminatingChars;
|
|
56
|
-
type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
|
|
57
|
-
type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
|
|
58
|
-
type PostfixToken = "[]";
|
|
59
|
-
type OperatorToken = InfixToken | PostfixToken;
|
|
60
|
-
type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
|
|
61
|
-
type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
|
|
62
|
-
type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
|
|
63
|
-
type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<unscanned, TerminatingChar>;
|
|
64
|
-
type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned, WhiteSpaceToken>[1];
|
|
65
|
-
type shiftResult<scanned extends string, unscanned extends string> = [
|
|
66
|
-
scanned,
|
|
67
|
-
unscanned
|
|
68
|
-
];
|
|
69
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { escapeToken, isKeyOf, whiteSpaceTokens } from "@ark/util";
|
|
2
|
-
export class Scanner {
|
|
3
|
-
chars;
|
|
4
|
-
i;
|
|
5
|
-
constructor(def) {
|
|
6
|
-
this.chars = [...def];
|
|
7
|
-
this.i = 0;
|
|
8
|
-
}
|
|
9
|
-
/** Get lookahead and advance scanner by one */
|
|
10
|
-
shift() {
|
|
11
|
-
return (this.chars[this.i++] ?? "");
|
|
12
|
-
}
|
|
13
|
-
get lookahead() {
|
|
14
|
-
return (this.chars[this.i] ?? "");
|
|
15
|
-
}
|
|
16
|
-
get nextLookahead() {
|
|
17
|
-
return this.chars[this.i + 1] ?? "";
|
|
18
|
-
}
|
|
19
|
-
get length() {
|
|
20
|
-
return this.chars.length;
|
|
21
|
-
}
|
|
22
|
-
shiftUntil(condition) {
|
|
23
|
-
let shifted = "";
|
|
24
|
-
while (this.lookahead) {
|
|
25
|
-
if (condition(this, shifted)) {
|
|
26
|
-
if (shifted[shifted.length - 1] === escapeToken)
|
|
27
|
-
shifted = shifted.slice(0, -1);
|
|
28
|
-
else
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
shifted += this.shift();
|
|
32
|
-
}
|
|
33
|
-
return shifted;
|
|
34
|
-
}
|
|
35
|
-
shiftUntilNextTerminator() {
|
|
36
|
-
this.shiftUntilNonWhitespace();
|
|
37
|
-
return this.shiftUntil(Scanner.lookaheadIsTerminator);
|
|
38
|
-
}
|
|
39
|
-
shiftUntilNonWhitespace() {
|
|
40
|
-
return this.shiftUntil(Scanner.lookaheadIsNotWhitespace);
|
|
41
|
-
}
|
|
42
|
-
jumpToIndex(i) {
|
|
43
|
-
this.i = i < 0 ? this.length + i : i;
|
|
44
|
-
}
|
|
45
|
-
jumpForward(count) {
|
|
46
|
-
this.i += count;
|
|
47
|
-
}
|
|
48
|
-
get location() {
|
|
49
|
-
return this.i;
|
|
50
|
-
}
|
|
51
|
-
get unscanned() {
|
|
52
|
-
return this.chars.slice(this.i, this.length).join("");
|
|
53
|
-
}
|
|
54
|
-
get scanned() {
|
|
55
|
-
return this.chars.slice(0, this.i).join("");
|
|
56
|
-
}
|
|
57
|
-
sliceChars(start, end) {
|
|
58
|
-
return this.chars.slice(start, end).join("");
|
|
59
|
-
}
|
|
60
|
-
lookaheadIs(char) {
|
|
61
|
-
return this.lookahead === char;
|
|
62
|
-
}
|
|
63
|
-
lookaheadIsIn(tokens) {
|
|
64
|
-
return this.lookahead in tokens;
|
|
65
|
-
}
|
|
66
|
-
static terminatingChars = {
|
|
67
|
-
"<": true,
|
|
68
|
-
">": true,
|
|
69
|
-
"=": true,
|
|
70
|
-
"|": true,
|
|
71
|
-
"&": true,
|
|
72
|
-
")": true,
|
|
73
|
-
"[": true,
|
|
74
|
-
"%": true,
|
|
75
|
-
",": true,
|
|
76
|
-
":": true,
|
|
77
|
-
...whiteSpaceTokens
|
|
78
|
-
};
|
|
79
|
-
static finalizingLookaheads = {
|
|
80
|
-
">": true,
|
|
81
|
-
",": true,
|
|
82
|
-
"": true,
|
|
83
|
-
"=": true
|
|
84
|
-
};
|
|
85
|
-
static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
|
|
86
|
-
static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
|
|
87
|
-
static lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
|
|
88
|
-
unscanned[0] === "=" ?
|
|
89
|
-
// >== would only occur in an expression like Array<number>==5
|
|
90
|
-
// otherwise, >= would only occur as part of a bound like number>=5
|
|
91
|
-
unscanned[1] === "="
|
|
92
|
-
// if > is the end of a generic instantiation, the next token will be an operator or the end of the string
|
|
93
|
-
: unscanned.trimStart() === "" ||
|
|
94
|
-
isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
|
|
95
|
-
// "=" is a finalizer on its own (representing a default value),
|
|
96
|
-
// but not with a second "=" (an equality comparator)
|
|
97
|
-
: lookahead === "=" ? unscanned[0] !== "="
|
|
98
|
-
// ","" is unambiguously a finalizer
|
|
99
|
-
: lookahead === ",";
|
|
100
|
-
}
|
package/out/subtypes/base.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
-
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
-
import type { inferIntersection } from "../intersect.ts";
|
|
4
|
-
import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes } from "../keywords/ast.ts";
|
|
5
|
-
import type { Scope } from "../scope.ts";
|
|
6
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
|
-
import type { ArrayType } from "./array.ts";
|
|
8
|
-
import type { instantiateType } from "./instantiate.ts";
|
|
9
|
-
/** @ts-ignore cast variance */
|
|
10
|
-
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> {
|
|
11
|
-
t: t;
|
|
12
|
-
tIn: distillConstrainableIn<t>;
|
|
13
|
-
tOut: distillConstrainableOut<t>;
|
|
14
|
-
tValidatedOut: distillValidatedOut<t>;
|
|
15
|
-
infer: distillOut<t>;
|
|
16
|
-
inferIn: distillIn<t>;
|
|
17
|
-
[inferred]: t;
|
|
18
|
-
json: Json;
|
|
19
|
-
toJsonSchema(): JsonSchema;
|
|
20
|
-
description: string;
|
|
21
|
-
expression: string;
|
|
22
|
-
internal: BaseRoot;
|
|
23
|
-
$: Scope<$>;
|
|
24
|
-
assert(data: unknown): this["infer"];
|
|
25
|
-
allows(data: unknown): data is this["inferIn"];
|
|
26
|
-
traverse(data: unknown): distillOut<t> | ArkErrors;
|
|
27
|
-
configure(meta: MetaSchema): this;
|
|
28
|
-
describe(description: string): this;
|
|
29
|
-
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
30
|
-
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
31
|
-
from(literal: this["inferIn"]): this["infer"];
|
|
32
|
-
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
|
|
33
|
-
get in(): instantiateType<this["tIn"], $>;
|
|
34
|
-
get out(): instantiateType<this["tValidatedOut"], $>;
|
|
35
|
-
intersect<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
|
|
36
|
-
and<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $>;
|
|
37
|
-
or<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<t | r, $>;
|
|
38
|
-
array(): ArrayType<t[], $>;
|
|
39
|
-
pipe: ChainedPipes<t, $>;
|
|
40
|
-
equals<def>(def: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
|
|
41
|
-
extract<def>(r: validateTypeRoot<def, $>): instantiateType<Extract<t, inferTypeRoot<def, $>>, $>;
|
|
42
|
-
exclude<def>(r: validateTypeRoot<def, $>): instantiateType<Exclude<t, inferTypeRoot<def, $>>, $>;
|
|
43
|
-
extends<def>(other: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
|
|
44
|
-
overlaps<def>(r: validateTypeRoot<def, $>): boolean;
|
|
45
|
-
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
|
|
46
|
-
/** @deprecated */
|
|
47
|
-
apply: Function["apply"];
|
|
48
|
-
/** @deprecated */
|
|
49
|
-
bind: Function["bind"];
|
|
50
|
-
/** @deprecated */
|
|
51
|
-
call: Function["call"];
|
|
52
|
-
/** @deprecated */
|
|
53
|
-
caller: Function;
|
|
54
|
-
/** @deprecated */
|
|
55
|
-
length: number;
|
|
56
|
-
/** @deprecated */
|
|
57
|
-
name: string;
|
|
58
|
-
/** @deprecated */
|
|
59
|
-
prototype: Function["prototype"];
|
|
60
|
-
/** @deprecated */
|
|
61
|
-
arguments: Function["arguments"];
|
|
62
|
-
/** @deprecated */
|
|
63
|
-
Symbol: never;
|
|
64
|
-
}
|
|
65
|
-
interface ChainedPipeSignature<t, $> {
|
|
66
|
-
<a extends Morph<distillOut<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
|
|
67
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
|
|
68
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
|
|
69
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): r;
|
|
70
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): r;
|
|
71
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): r;
|
|
72
|
-
<a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): r;
|
|
73
|
-
}
|
|
74
|
-
export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
|
|
75
|
-
try: ChainedPipeSignature<t, $>;
|
|
76
|
-
}
|
|
77
|
-
type validateChainedAsArgs<t> = [
|
|
78
|
-
t
|
|
79
|
-
] extends [unset] ? [
|
|
80
|
-
t
|
|
81
|
-
] extends [anyOrNever] ? [
|
|
82
|
-
] : [
|
|
83
|
-
ErrorMessage<"as requires an explicit type parameter like myType.as<t>()">
|
|
84
|
-
] : [];
|
|
85
|
-
export type { Type as BaseType };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { anyOrNever, array } from "@ark/util";
|
|
2
|
-
import type { MorphAst } from "../keywords/ast.ts";
|
|
3
|
-
import type { ArrayType } from "./array.ts";
|
|
4
|
-
import type { DateType } from "./date.ts";
|
|
5
|
-
import type { MorphType } from "./morph.ts";
|
|
6
|
-
import type { NumberType } from "./number.ts";
|
|
7
|
-
import type { ObjectType } from "./object.ts";
|
|
8
|
-
import type { StringType } from "./string.ts";
|
|
9
|
-
import type { ValidatorType } from "./validator.ts";
|
|
10
|
-
export type instantiateType<t, $> = [
|
|
11
|
-
Extract<t, MorphAst>
|
|
12
|
-
] extends [anyOrNever] ? [
|
|
13
|
-
t
|
|
14
|
-
] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
|
|
15
|
-
t
|
|
16
|
-
] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : ValidatorType<t, $> : MorphType<t, $>;
|
package/out/subtypes/morph.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type { inferPipe } from "../intersect.ts";
|
|
3
|
-
import type { applyConstraint, Out, To } from "../keywords/ast.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
|
-
import type { BaseType } from "./base.ts";
|
|
6
|
-
/** @ts-ignore cast variance */
|
|
7
|
-
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
8
|
-
to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
|
|
9
|
-
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
10
|
-
narrowed
|
|
11
|
-
] extends [never] ? applyConstraint<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
|
|
12
|
-
}
|
|
13
|
-
export type { Type as MorphType };
|
package/out/subtypes/number.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type { applyConstraint } from "../keywords/ast.ts";
|
|
3
|
-
import type { ValidatorType } from "./validator.ts";
|
|
4
|
-
/** @ts-ignore cast variance */
|
|
5
|
-
interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
|
|
6
|
-
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraint<t, "divisor", schema>, $>;
|
|
7
|
-
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", schema>, $>;
|
|
8
|
-
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "max", schema>, $>;
|
|
9
|
-
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
-
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "max", exclusivizeRangeSchema<schema>>, $>;
|
|
11
|
-
}
|
|
12
|
-
export type { Type as NumberType };
|