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
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type array, type conform, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type Primitive, type show } from "@ark/util";
|
|
3
|
+
import type { arkPrototypes } from "./keywords/constructors/constructors.ts";
|
|
4
|
+
import type { Date } from "./keywords/constructors/Date.ts";
|
|
5
|
+
import type { type } from "./keywords/keywords.ts";
|
|
6
|
+
import type { number } from "./keywords/number/number.ts";
|
|
7
|
+
import type { Matching, string } from "./keywords/string/string.ts";
|
|
8
|
+
import type { Type } from "./type.ts";
|
|
9
|
+
export type { arkPrototypes as object } from "./keywords/constructors/constructors.ts";
|
|
10
|
+
export type { number } from "./keywords/number/number.ts";
|
|
11
|
+
export type { string } from "./keywords/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 declare const attributesKey: " attributes";
|
|
16
|
+
export type attributesKey = typeof attributesKey;
|
|
17
|
+
export type of<base, attributes extends Attributes> = base & {
|
|
18
|
+
[attributesKey]: {
|
|
19
|
+
base: base;
|
|
20
|
+
attributes: attributes;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type brand<base, attributes extends Attributes> = base & {
|
|
24
|
+
[attributesKey]: {
|
|
25
|
+
base: base;
|
|
26
|
+
attributes: attributes;
|
|
27
|
+
brand: true;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export interface ConstrainingAttributeValuesByKind {
|
|
31
|
+
divisibleBy: number;
|
|
32
|
+
moreThan: number;
|
|
33
|
+
atLeast: number;
|
|
34
|
+
atMost: number;
|
|
35
|
+
lessThan: number;
|
|
36
|
+
matching: string;
|
|
37
|
+
moreThanLength: number;
|
|
38
|
+
atLeastLength: number;
|
|
39
|
+
atMostLength: number;
|
|
40
|
+
lessThanLength: number;
|
|
41
|
+
atOrAfter: string;
|
|
42
|
+
after: string;
|
|
43
|
+
atOrBefore: string;
|
|
44
|
+
before: string;
|
|
45
|
+
nominal: string;
|
|
46
|
+
}
|
|
47
|
+
export type ConstrainingAttributeKind = keyof ConstrainingAttributeValuesByKind;
|
|
48
|
+
export type ConstrainingAttributesByKind = {
|
|
49
|
+
[k in ConstrainingAttributeKind]?: Record<ConstrainingAttributeValuesByKind[k], true>;
|
|
50
|
+
};
|
|
51
|
+
export interface MetaAttributeValuesByKind extends Optional, Default {
|
|
52
|
+
}
|
|
53
|
+
export type MetaAttributeKind = keyof MetaAttributeValuesByKind;
|
|
54
|
+
export type MetaAttributesByKind = Partial<MetaAttributeValuesByKind>;
|
|
55
|
+
export interface Attributes extends ConstrainingAttributesByKind, MetaAttributesByKind {
|
|
56
|
+
}
|
|
57
|
+
export type AttributeKind = keyof Attributes;
|
|
58
|
+
export type LimitLiteral = number | DateLiteral;
|
|
59
|
+
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
60
|
+
export type constraint<rule> = {
|
|
61
|
+
[k in rule & PropertyKey]: true;
|
|
62
|
+
};
|
|
63
|
+
export type Anonymous = Nominal<"?">;
|
|
64
|
+
export type Nominal<name> = {
|
|
65
|
+
nominal: constraint<name>;
|
|
66
|
+
};
|
|
67
|
+
export type AtLeast<rule> = {
|
|
68
|
+
atLeast: constraint<rule>;
|
|
69
|
+
};
|
|
70
|
+
export type AtMost<rule> = {
|
|
71
|
+
atMost: constraint<rule>;
|
|
72
|
+
};
|
|
73
|
+
export type MoreThan<rule> = {
|
|
74
|
+
moreThan: constraint<rule>;
|
|
75
|
+
};
|
|
76
|
+
export type LessThan<rule> = {
|
|
77
|
+
lessThan: constraint<rule>;
|
|
78
|
+
};
|
|
79
|
+
export type DivisibleBy<rule> = {
|
|
80
|
+
divisibleBy: constraint<rule>;
|
|
81
|
+
};
|
|
82
|
+
export type AtOrAfter<rule> = {
|
|
83
|
+
atOrAfter: constraint<rule>;
|
|
84
|
+
};
|
|
85
|
+
export type AtOrBefore<rule> = {
|
|
86
|
+
atOrBefore: constraint<rule>;
|
|
87
|
+
};
|
|
88
|
+
export type After<rule> = {
|
|
89
|
+
after: constraint<rule>;
|
|
90
|
+
};
|
|
91
|
+
export type Before<rule> = {
|
|
92
|
+
before: constraint<rule>;
|
|
93
|
+
};
|
|
94
|
+
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
95
|
+
export type AtLeastLength<rule> = {
|
|
96
|
+
atLeastLength: constraint<rule>;
|
|
97
|
+
};
|
|
98
|
+
export type AtMostLength<rule> = {
|
|
99
|
+
atMostLength: constraint<rule>;
|
|
100
|
+
};
|
|
101
|
+
export type MoreThanLength<rule> = {
|
|
102
|
+
moreThanLength: constraint<rule>;
|
|
103
|
+
};
|
|
104
|
+
export type LessThanLength<rule> = {
|
|
105
|
+
lessThanLength: constraint<rule>;
|
|
106
|
+
};
|
|
107
|
+
export type ExactlyLength<rule> = {
|
|
108
|
+
atLeastLength: constraint<rule>;
|
|
109
|
+
atMostLength: constraint<rule>;
|
|
110
|
+
};
|
|
111
|
+
export type AttributeInferenceBehavior = "brand" | "associate";
|
|
112
|
+
export type associateAttributes<t, attributes extends Attributes> = attachAttributes<t, attributes, "associate">;
|
|
113
|
+
export type brandAttributes<t, attributes extends Attributes> = attachAttributes<t, attributes, "brand">;
|
|
114
|
+
type attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior = "associate", unmorphedT = Exclude<t, InferredMorph>> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _attachAttributes<i, attributes, behavior>>) => o : leftIfEqual<unmorphedT, _attachAttributes<unmorphedT, attributes, behavior>>;
|
|
115
|
+
type _attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior, distributed = t> = distributed extends null | undefined ? distributed : distributed extends of<infer base, infer existingAttributes> ? "brand" extends keyof distributed[attributesKey] | behavior ? brandMultiple<base, existingAttributes & attributes> : associateMultiple<base, existingAttributes & attributes> : extractIfSingleAttributeEntry<attributes> extends (AttributeEntry<infer kind, infer value>) ? "brand" extends behavior ? brandSingle<t, attributes, kind, value> : associateSingle<t, attributes, kind, value> : "brand" extends behavior ? brandMultiple<t, attributes> : associateMultiple<t, attributes>;
|
|
116
|
+
type associateMultiple<t, attributes extends Attributes> = [
|
|
117
|
+
t,
|
|
118
|
+
string
|
|
119
|
+
] extends [string, t] ? string.is<attributes> : [t, number] extends [number, t] ? number.is<attributes> : [t, Date] extends [Date, t] ? Date.is<attributes> : of<t, attributes>;
|
|
120
|
+
type brandMultiple<t, attributes extends Attributes> = [
|
|
121
|
+
t,
|
|
122
|
+
string
|
|
123
|
+
] extends [string, t] ? string.branded.is<attributes> : [t, number] extends [number, t] ? number.branded.is<attributes> : [t, Date] extends [Date, t] ? Date.branded.is<attributes> : brand<t, attributes>;
|
|
124
|
+
type associateSingle<t, attributes extends Attributes, kind extends AttributeKind, value> = [
|
|
125
|
+
t,
|
|
126
|
+
string
|
|
127
|
+
] extends [string, t] ? string.raw.withSingleAttribute<kind, value> : [t, number] extends [number, t] ? number.raw.withSingleAttribute<kind, value> : [t, Date] extends [Date, t] ? Date.raw.withSingleAttribute<kind, value> : of<t, attributes>;
|
|
128
|
+
type brandSingle<t, attributes extends Attributes, kind extends AttributeKind, value> = [
|
|
129
|
+
t,
|
|
130
|
+
string
|
|
131
|
+
] extends [string, t] ? string.branded.raw.withSingleAttribute<kind, value> : [t, number] extends [number, t] ? number.branded.raw.withSingleAttribute<kind, value> : [t, Date] extends [Date, t] ? Date.branded.raw.withSingleAttribute<kind, value> : brand<t, attributes>;
|
|
132
|
+
type AttributeEntry<kind extends AttributeKind, value> = [kind, value];
|
|
133
|
+
/**
|
|
134
|
+
* Check if attributes is a single attribute kind + value that can be collapsed
|
|
135
|
+
* for display purposes, e.g.:
|
|
136
|
+
*
|
|
137
|
+
* // has multiple attribute kinds
|
|
138
|
+
* { divisibleBy: { 2: true }, moreThan: { 3: true } } => null
|
|
139
|
+
*
|
|
140
|
+
* // has multiple attribute values of a single kind
|
|
141
|
+
* { divisibleBy: { 2: true, 3: true } } => null
|
|
142
|
+
*
|
|
143
|
+
* // has a single attribute kind + value, can be collapsed
|
|
144
|
+
* { divisibleBy: { 2: true } } => ["divisibleBy", 2]
|
|
145
|
+
*/
|
|
146
|
+
type extractIfSingleAttributeEntry<attributes extends Attributes> = extractIfSingleEntry<attributes> extends (AttributeEntry<infer kind, infer attributesValue>) ? extractIfSingleEntry<attributesValue> extends [infer key, infer value] ? AttributeEntry<kind, kind extends MetaAttributeKind ? value : key> : null : null;
|
|
147
|
+
type extractIfSingleEntry<o> = {
|
|
148
|
+
[k in keyof o]: keyof o extends k ? [key: k, value: o[k]] : null;
|
|
149
|
+
}[keyof o];
|
|
150
|
+
export interface LengthAttributeValuesByKind {
|
|
151
|
+
moreThanLength: number;
|
|
152
|
+
atLeastLength: number;
|
|
153
|
+
atMostLength: number;
|
|
154
|
+
lessThanLength: number;
|
|
155
|
+
}
|
|
156
|
+
export type LengthAttributeKind = keyof LengthAttributeValuesByKind;
|
|
157
|
+
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
158
|
+
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
159
|
+
exclusive: true;
|
|
160
|
+
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
161
|
+
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
162
|
+
exclusive: true;
|
|
163
|
+
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
164
|
+
export type associateAttributesFromSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = associateAttributes<t, schemaToAttributes<kind, schema>>;
|
|
165
|
+
export type associateAttributesFromStringSchema<t extends string, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, string>;
|
|
166
|
+
export type associateAttributesFromNumberSchema<t extends number, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, number>;
|
|
167
|
+
export type associateAttributesFromDateSchema<t extends Date, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, Date>;
|
|
168
|
+
export type associateAttributesFromArraySchema<t extends readonly unknown[], kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, readonly unknown[]>;
|
|
169
|
+
export type schemaToAttributes<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "min" ? number.minSchemaToConstraint<schema, rule> : kind extends "max" ? number.maxSchemaToConstraint<schema, rule> : kind extends "minLength" ? minLengthSchemaToConstraint<schema, rule> : kind extends "maxLength" ? maxLengthSchemaToConstraint<schema, rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? Date.afterSchemaToConstraint<schema, rule> : kind extends "before" ? Date.beforeSchemaToConstraint<schema, rule> : Anonymous : never;
|
|
170
|
+
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
171
|
+
export declare namespace distill {
|
|
172
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
173
|
+
type Options = {
|
|
174
|
+
endpoint?: Endpoint;
|
|
175
|
+
attributes?: "preserve" | "brand" | "unbrand";
|
|
176
|
+
};
|
|
177
|
+
type In<t> = distill<t, {
|
|
178
|
+
endpoint: "in";
|
|
179
|
+
}>;
|
|
180
|
+
type Out<t> = distill<t, {
|
|
181
|
+
endpoint: "out";
|
|
182
|
+
}>;
|
|
183
|
+
namespace withAttributes {
|
|
184
|
+
type In<t> = distill<t, {
|
|
185
|
+
endpoint: "in";
|
|
186
|
+
attributes: "preserve";
|
|
187
|
+
}>;
|
|
188
|
+
type Out<t> = distill<t, {
|
|
189
|
+
endpoint: "out";
|
|
190
|
+
attributes: "preserve";
|
|
191
|
+
}>;
|
|
192
|
+
namespace introspectable {
|
|
193
|
+
type Out<t> = distill<t, {
|
|
194
|
+
endpoint: "out.introspectable";
|
|
195
|
+
attributes: "preserve";
|
|
196
|
+
}>;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
type brand<t> = distill<t, {
|
|
200
|
+
attributes: "brand";
|
|
201
|
+
}>;
|
|
202
|
+
type unbrand<t> = distill<t, {
|
|
203
|
+
attributes: "unbrand";
|
|
204
|
+
}>;
|
|
205
|
+
namespace introspectable {
|
|
206
|
+
type Out<t> = distill<t, {
|
|
207
|
+
endpoint: "out.introspectable";
|
|
208
|
+
}>;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
212
|
+
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : t extends of<infer base, infer attributes> ? opts["attributes"] extends "preserve" ? associateAttributes<_distill<base, opts>, attributes> : opts["attributes"] extends "unbrand" ? associateAttributes<_distill<base, opts>, attributes> : opts["attributes"] extends "brand" ? brand<_distill<base, opts>, attributes> : "brand" extends keyof t[attributesKey] ? brand<_distill<base, opts>, attributes> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? distillIo<i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
|
|
213
|
+
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
|
|
214
|
+
[k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
215
|
+
} & {
|
|
216
|
+
[k in inferredOptionalOrDefaultKeyOf<o>]?: _distill<o[k], opts>;
|
|
217
|
+
}> : show<{
|
|
218
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
219
|
+
} & {
|
|
220
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
|
|
221
|
+
}>;
|
|
222
|
+
type distillIo<i, o extends Out, opts extends distill.Options> = opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never;
|
|
223
|
+
export type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
|
|
224
|
+
type inExtends<v, t> = [
|
|
225
|
+
v
|
|
226
|
+
] extends [anyOrNever] ? false : [v] extends [t] ? true : [v] extends [InferredMorph<infer i>] ? inExtends<i, t> : false;
|
|
227
|
+
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredDefault> extends true ? k : never : never : never;
|
|
228
|
+
type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredOptional> extends true ? k : never : never : never;
|
|
229
|
+
type distillArray<t extends array, opts extends distill.Options> = t[number][] extends t ? alignReadonly<_distill<t[number], opts>[], t> : distillNonArraykeys<t, alignReadonly<_distillArray<[...t], opts, []>, t>, opts>;
|
|
230
|
+
type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
|
|
231
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | attributesKey ? distilledArray : distilledArray & _distill<{
|
|
232
|
+
[k in keyof originalArray as k extends (keyof distilledArray | (opts["attributes"] extends true ? never : attributesKey)) ? never : k]: originalArray[k];
|
|
233
|
+
}, opts>;
|
|
234
|
+
type _distillArray<t extends array, opts extends distill.Options, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, opts, [...prefix, _distill<head, opts>]> : [...prefix, ...distillPostfix<t, opts>];
|
|
235
|
+
type distillPostfix<t extends array, opts extends distill.Options, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, opts, [_distill<last, opts>, ...postfix]> : [...{
|
|
236
|
+
[i in keyof t]: _distill<t[i], opts>;
|
|
237
|
+
}, ...postfix];
|
|
238
|
+
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
239
|
+
/** Objects we don't want to expand during inference like Date or Promise */
|
|
240
|
+
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
241
|
+
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends of<unknown, infer constraints> ? "brand" extends keyof t[attributesKey] ? brand<narrowed, constraints> : of<narrowed, constraints> : narrowed : associateAttributes<t, Anonymous>;
|
|
242
|
+
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distill.withAttributes.In<t>) => Out<out> : never, tail> : t;
|
|
243
|
+
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
244
|
+
export type Out<o = any> = ["=>", o, boolean];
|
|
245
|
+
export type To<o = any> = ["=>", o, true];
|
|
246
|
+
export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
|
|
247
|
+
export type Optional = {
|
|
248
|
+
optional: {
|
|
249
|
+
"=": true;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
export type InferredOptional<t = unknown> = of<t, Optional>;
|
|
253
|
+
export type Default<v = any> = {
|
|
254
|
+
defaultsTo: {
|
|
255
|
+
value: v;
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
export type DefaultFor<t> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
|
|
259
|
+
export type InferredDefault<t = unknown, v = any> = of<t, Default<v>>;
|
|
260
|
+
export type termOrType<t> = t | Type<t, any>;
|
|
261
|
+
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
262
|
+
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
263
|
+
type _inferIntersection<l, r, piped extends boolean> = [
|
|
264
|
+
l & r
|
|
265
|
+
] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : l extends of<infer lBase, infer lAttributes> ? r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<lBase, rBase, piped>, lAttributes & rAttributes> : of<_inferIntersection<lBase, r, piped>, lAttributes> : r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<rBase, l, piped>, rAttributes> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
266
|
+
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
267
|
+
body: _inferIntersection<this[0], this[1], piped>;
|
|
268
|
+
}
|
|
269
|
+
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
|
|
270
|
+
l & r : r extends array ? l & r : show<{
|
|
271
|
+
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
272
|
+
} & {
|
|
273
|
+
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
274
|
+
}>;
|
package/out/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkSchemaRegistry } from "@ark/schema";
|
|
2
|
-
import type { Ark } from "./keywords/
|
|
2
|
+
import type { Ark } from "./keywords/keywords.ts";
|
|
3
3
|
import type { exportScope } from "./module.ts";
|
|
4
4
|
export * from "@ark/schema/config";
|
|
5
5
|
export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
|
package/out/generic.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
|
-
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type
|
|
1
|
+
import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
|
+
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhitespaceChar } from "@ark/util";
|
|
3
|
+
import type { type } from "./keywords/keywords.ts";
|
|
4
|
+
import type { inferAstRoot } from "./parser/ast/infer.ts";
|
|
5
|
+
import type { validateAst } from "./parser/ast/validate.ts";
|
|
3
6
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import type { ParseContext, Scope } from "./scope.ts";
|
|
10
|
-
import type { inferTypeRoot, Type, validateTypeRoot } from "./type.ts";
|
|
7
|
+
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
+
import type { ArkTypeScanner } from "./parser/shift/scanner.ts";
|
|
9
|
+
import { parseUntilFinalizer } from "./parser/string.ts";
|
|
10
|
+
import type { Scope } from "./scope.ts";
|
|
11
|
+
import type { Type } from "./type.ts";
|
|
11
12
|
export type ParameterString<params extends string = string> = `<${params}>`;
|
|
12
13
|
export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
|
|
13
14
|
export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
|
|
14
|
-
export type validateGenericArg<arg, param extends GenericParamAst, $> =
|
|
15
|
+
export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
|
|
15
16
|
export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
|
|
16
|
-
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a:
|
|
17
|
+
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
|
|
17
18
|
} : params["length"] extends 2 ? {
|
|
18
|
-
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
19
|
-
validateGenericArg<a, params[0], args$>,
|
|
20
|
-
validateGenericArg<b, params[1], args$>
|
|
19
|
+
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
20
|
+
type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
|
|
21
|
+
type.validate<b, args$> & validateGenericArg<b, params[1], args$>
|
|
21
22
|
]): r;
|
|
22
23
|
} : params["length"] extends 3 ? {
|
|
23
24
|
<const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
type.validate<a, args$>,
|
|
26
|
+
type.validate<b, args$>,
|
|
27
|
+
type.validate<c, args$>
|
|
27
28
|
] & [
|
|
28
29
|
validateGenericArg<a, params[0], args$>,
|
|
29
30
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -31,10 +32,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
31
32
|
]): r;
|
|
32
33
|
} : params["length"] extends 4 ? {
|
|
33
34
|
<const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
type.validate<a, args$>,
|
|
36
|
+
type.validate<b, args$>,
|
|
37
|
+
type.validate<c, args$>,
|
|
38
|
+
type.validate<d, args$>
|
|
38
39
|
] & [
|
|
39
40
|
validateGenericArg<a, params[0], args$>,
|
|
40
41
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -43,11 +44,11 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
43
44
|
]): r;
|
|
44
45
|
} : params["length"] extends 4 ? {
|
|
45
46
|
<const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
type.validate<a, args$>,
|
|
48
|
+
type.validate<b, args$>,
|
|
49
|
+
type.validate<c, args$>,
|
|
50
|
+
type.validate<d, args$>,
|
|
51
|
+
type.validate<e, args$>
|
|
51
52
|
] & [
|
|
52
53
|
validateGenericArg<a, params[0], args$>,
|
|
53
54
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -57,12 +58,12 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
57
58
|
]): r;
|
|
58
59
|
} : params["length"] extends 5 ? {
|
|
59
60
|
<const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
type.validate<a, args$>,
|
|
62
|
+
type.validate<b, args$>,
|
|
63
|
+
type.validate<c, args$>,
|
|
64
|
+
type.validate<d, args$>,
|
|
65
|
+
type.validate<e, args$>,
|
|
66
|
+
type.validate<f, args$>
|
|
66
67
|
] & [
|
|
67
68
|
validateGenericArg<a, params[0], args$>,
|
|
68
69
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -73,13 +74,13 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
73
74
|
]): r;
|
|
74
75
|
} : params["length"] extends 6 ? {
|
|
75
76
|
<const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
type.validate<a, args$>,
|
|
78
|
+
type.validate<b, args$>,
|
|
79
|
+
type.validate<c, args$>,
|
|
80
|
+
type.validate<d, args$>,
|
|
81
|
+
type.validate<e, args$>,
|
|
82
|
+
type.validate<f, args$>,
|
|
83
|
+
type.validate<g, args$>
|
|
83
84
|
] & [
|
|
84
85
|
validateGenericArg<a, params[0], args$>,
|
|
85
86
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -93,10 +94,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
93
94
|
type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
|
|
94
95
|
def
|
|
95
96
|
] extends [Hkt] ? Hkt.apply<def, {
|
|
96
|
-
[i in keyof args]:
|
|
97
|
+
[i in keyof args]: type.infer<args[i], args$>;
|
|
97
98
|
}> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
|
|
98
99
|
type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
|
|
99
|
-
[i in keyof params & `${number}` as params[i][0]]:
|
|
100
|
+
[i in keyof params & `${number}` as params[i][0]]: type.infer<args[i & keyof args], $>;
|
|
100
101
|
};
|
|
101
102
|
type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGenericConstraints<params> extends infer baseConstraints ? {
|
|
102
103
|
[k in keyof baseConstraints]: Type<baseConstraints[k], $>;
|
|
@@ -126,34 +127,30 @@ export type GenericDeclaration<name extends string = string, params extends Para
|
|
|
126
127
|
export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
|
|
127
128
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
128
129
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
129
|
-
export
|
|
130
|
-
export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
|
|
130
|
+
export type parseGenericParams<def extends string, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<def>, "", [
|
|
131
131
|
], $>;
|
|
132
|
-
type ParamsTerminator =
|
|
133
|
-
declare const
|
|
134
|
-
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<
|
|
135
|
-
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends
|
|
132
|
+
type ParamsTerminator = WhitespaceChar | ",";
|
|
133
|
+
export declare const parseGenericParamName: (scanner: ArkTypeScanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
134
|
+
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<unscanned>, "", result, $>;
|
|
135
|
+
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhitespaceChar ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
|
|
136
136
|
declare const extendsToken = "extends ";
|
|
137
137
|
type extendsToken = typeof extendsToken;
|
|
138
|
-
declare const _parseOptionalConstraint: (scanner:
|
|
139
|
-
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> =
|
|
138
|
+
declare const _parseOptionalConstraint: (scanner: ArkTypeScanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
139
|
+
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = ArkTypeScanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
|
|
140
140
|
...result,
|
|
141
141
|
[name, inferAstRoot<finalArgState["root"], $, {}>]
|
|
142
|
-
], $> : never : parseName<
|
|
142
|
+
], $> : never : parseName<ArkTypeScanner.skipWhitespace<unscanned> extends (`,${infer nextUnscanned}`) ? nextUnscanned : unscanned, [
|
|
143
143
|
...result,
|
|
144
144
|
[name, unknown]
|
|
145
145
|
], $>;
|
|
146
|
-
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
|
|
147
|
-
name,
|
|
148
|
-
inferTypeRoot<def, $>
|
|
149
|
-
] : never;
|
|
146
|
+
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
|
|
150
147
|
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
|
|
151
148
|
...{
|
|
152
149
|
[i in keyof defs]: genericParamDefToAst<defs[i], $>;
|
|
153
150
|
}
|
|
154
151
|
];
|
|
155
152
|
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
156
|
-
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name,
|
|
153
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
157
154
|
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
158
155
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
159
156
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
package/out/generic.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { GenericRoot } from "@ark/schema";
|
|
2
2
|
import { throwParseError } from "@ark/util";
|
|
3
|
-
import { DynamicState } from "./parser/
|
|
4
|
-
import {
|
|
5
|
-
import { parseUntilFinalizer } from "./parser/string/string.js";
|
|
3
|
+
import { DynamicState } from "./parser/reduce/dynamic.js";
|
|
4
|
+
import { parseUntilFinalizer } from "./parser/string.js";
|
|
6
5
|
export const Generic = GenericRoot;
|
|
7
6
|
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
8
|
-
export const
|
|
9
|
-
const parseName = (scanner, result, ctx) => {
|
|
7
|
+
export const parseGenericParamName = (scanner, result, ctx) => {
|
|
10
8
|
scanner.shiftUntilNonWhitespace();
|
|
11
9
|
const name = scanner.shiftUntilNextTerminator();
|
|
12
10
|
if (name === "") {
|
|
@@ -30,9 +28,9 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
|
30
28
|
if (scanner.lookahead === ",")
|
|
31
29
|
scanner.shift();
|
|
32
30
|
result.push(name);
|
|
33
|
-
return
|
|
31
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
34
32
|
}
|
|
35
|
-
const s = parseUntilFinalizer(new DynamicState(scanner, ctx
|
|
33
|
+
const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
|
|
36
34
|
result.push([name, s.root]);
|
|
37
|
-
return
|
|
35
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
38
36
|
};
|
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.ts";
|
|
4
|
-
export {
|
|
4
|
+
export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
|
|
5
5
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
|
-
export { module, scope, type Scope
|
|
7
|
-
export { Type
|
|
6
|
+
export { module, scope, type Scope } from "./scope.ts";
|
|
7
|
+
export { Type } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.js";
|
|
4
|
-
export {
|
|
4
|
+
export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
|
|
5
5
|
export { Module } from "./module.js";
|
|
6
6
|
export { module, scope } from "./scope.js";
|
|
7
7
|
export { Type } from "./type.js";
|
package/out/keywords/builtins.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
4
|
class MergeHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
|
|
7
|
-
export const arkBuiltins =
|
|
7
|
+
export const arkBuiltins = arkModule({
|
|
8
8
|
Key: intrinsic.key,
|
|
9
9
|
Merge
|
|
10
10
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hkt, liftArray, type Digit } from "@ark/util";
|
|
2
|
+
import type { To } from "../../attributes.ts";
|
|
2
3
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { To } from "../ast.ts";
|
|
4
4
|
declare class liftFromHkt extends Hkt<[element: unknown]> {
|
|
5
5
|
body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
|
|
6
6
|
}
|
|
@@ -10,7 +10,7 @@ export declare namespace arkArray {
|
|
|
10
10
|
type module = Module<submodule>;
|
|
11
11
|
type submodule = Submodule<$>;
|
|
12
12
|
type $ = {
|
|
13
|
-
|
|
13
|
+
root: unknown[];
|
|
14
14
|
readonly: readonly unknown[];
|
|
15
15
|
index: NonNegativeIntegerString;
|
|
16
16
|
liftFrom: typeof liftFrom.t;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { genericNode, intrinsic,
|
|
1
|
+
import { genericNode, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { Hkt, liftArray } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
class liftFromHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const liftFrom = genericNode("element")(args => {
|
|
7
7
|
const nonArrayElement = args.element.exclude(intrinsic.Array);
|
|
8
8
|
const lifted = nonArrayElement.array();
|
|
9
9
|
return nonArrayElement
|
|
10
|
-
.
|
|
10
|
+
.rawOr(lifted)
|
|
11
11
|
.pipe(liftArray)
|
|
12
|
-
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted),
|
|
12
|
+
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootSchema);
|
|
13
13
|
}, liftFromHkt);
|
|
14
|
-
export const arkArray =
|
|
15
|
-
|
|
16
|
-
readonly: "
|
|
14
|
+
export const arkArray = arkModule({
|
|
15
|
+
root: intrinsic.Array,
|
|
16
|
+
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
18
18
|
liftFrom
|
|
19
19
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { satisfy } from "@ark/util";
|
|
2
|
+
import type { After, Anonymous, AtOrAfter, AtOrBefore, AttributeKind, Attributes, Before, brand, Default, Nominal, normalizeLimit, of, Optional } from "../../attributes.ts";
|
|
3
|
+
export declare namespace Date {
|
|
4
|
+
type atOrAfter<rule> = of<Date, AtOrAfter<rule>>;
|
|
5
|
+
type after<rule> = of<Date, After<rule>>;
|
|
6
|
+
type atOrBefore<rule> = of<Date, AtOrBefore<rule>>;
|
|
7
|
+
type before<rule> = of<Date, Before<rule>>;
|
|
8
|
+
type anonymous = of<Date, Anonymous>;
|
|
9
|
+
type nominal<rule> = of<Date, Nominal<rule>>;
|
|
10
|
+
type optional = of<Date, Optional>;
|
|
11
|
+
type defaultsTo<rule> = of<Date, Default<rule>>;
|
|
12
|
+
type is<attributes extends Attributes> = of<Date, attributes>;
|
|
13
|
+
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
14
|
+
exclusive: true;
|
|
15
|
+
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
16
|
+
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
17
|
+
exclusive: true;
|
|
18
|
+
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
19
|
+
type AttributableKind = satisfy<AttributeKind, "after" | "atOrAfter" | "before" | "atOrBefore">;
|
|
20
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
21
|
+
namespace raw {
|
|
22
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
|
|
23
|
+
}
|
|
24
|
+
type branded<rule> = brand<Date, Nominal<rule>>;
|
|
25
|
+
namespace branded {
|
|
26
|
+
type atOrAfter<rule> = brand<Date, AtOrAfter<rule>>;
|
|
27
|
+
type after<rule> = brand<Date, After<rule>>;
|
|
28
|
+
type atOrBefore<rule> = brand<Date, AtOrBefore<rule>>;
|
|
29
|
+
type before<rule> = brand<Date, Before<rule>>;
|
|
30
|
+
type anonymous = brand<Date, Anonymous>;
|
|
31
|
+
type is<attributes extends Attributes> = brand<Date, attributes>;
|
|
32
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
33
|
+
namespace raw {
|
|
34
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : never;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|