arktype 2.0.0-rc.4 → 2.0.0-rc.5
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/generic.js +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/keywords/ark.d.ts +17 -1
- package/out/keywords/ast.d.ts +94 -101
- package/out/keywords/constructors/Array.d.ts +1 -1
- package/out/keywords/constructors/Array.js +2 -2
- package/out/keywords/constructors/Date.d.ts +31 -0
- package/out/keywords/constructors/FormData.d.ts +1 -1
- package/out/keywords/constructors/FormData.js +1 -1
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/number.d.ts +23 -6
- package/out/keywords/number/number.js +1 -1
- package/out/keywords/string/capitalize.d.ts +1 -1
- package/out/keywords/string/capitalize.js +1 -1
- package/out/keywords/string/date.d.ts +3 -3
- package/out/keywords/string/date.js +7 -7
- package/out/keywords/string/integer.d.ts +1 -1
- package/out/keywords/string/integer.js +3 -3
- package/out/keywords/string/ip.d.ts +1 -1
- package/out/keywords/string/ip.js +1 -1
- package/out/keywords/string/json.d.ts +1 -1
- package/out/keywords/string/json.js +2 -2
- package/out/keywords/string/lower.d.ts +1 -1
- package/out/keywords/string/lower.js +1 -1
- package/out/keywords/string/normalize.d.ts +14 -14
- package/out/keywords/string/normalize.js +5 -5
- package/out/keywords/string/numeric.d.ts +1 -1
- package/out/keywords/string/numeric.js +3 -3
- package/out/keywords/string/string.d.ts +17 -18
- package/out/keywords/string/string.js +1 -1
- package/out/keywords/string/trim.d.ts +1 -1
- package/out/keywords/string/trim.js +1 -1
- package/out/keywords/string/upper.d.ts +1 -1
- package/out/keywords/string/upper.js +1 -1
- package/out/keywords/string/url.d.ts +1 -1
- package/out/keywords/string/url.js +3 -3
- package/out/keywords/string/uuid.d.ts +2 -2
- package/out/keywords/string/uuid.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/{subtypes → methods}/base.d.ts +17 -15
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/morph.d.ts +2 -2
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/methods/validator.js +1 -0
- package/out/module.d.ts +2 -2
- package/out/parser/objectLiteral.d.ts +5 -30
- package/out/parser/objectLiteral.js +18 -21
- package/out/parser/semantic/default.d.ts +1 -2
- package/out/parser/semantic/default.js +1 -1
- package/out/parser/semantic/infer.d.ts +7 -6
- package/out/parser/semantic/validate.d.ts +2 -2
- package/out/parser/string/reduce/dynamic.d.ts +1 -2
- package/out/parser/string/reduce/dynamic.js +2 -4
- package/out/parser/string/shift/operand/date.d.ts +2 -0
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -1
- package/out/parser/string/shift/operator/default.d.ts +2 -5
- package/out/parser/string/shift/operator/default.js +1 -6
- package/out/parser/string/string.d.ts +2 -3
- package/out/parser/tuple.d.ts +6 -5
- package/out/parser/tuple.js +3 -1
- package/out/scope.d.ts +8 -5
- package/out/scope.js +7 -6
- package/out/type.d.ts +8 -4
- package/out/type.js +3 -1
- package/package.json +3 -3
- /package/out/{subtypes/array.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes/base.js → methods/array.js} +0 -0
- /package/out/{subtypes/date.js → methods/base.js} +0 -0
- /package/out/{subtypes/instantiate.js → methods/date.js} +0 -0
- /package/out/{subtypes → methods}/instantiate.d.ts +0 -0
- /package/out/{subtypes/morph.js → methods/instantiate.js} +0 -0
- /package/out/{subtypes/number.js → methods/morph.js} +0 -0
- /package/out/{subtypes/object.js → methods/number.js} +0 -0
- /package/out/{subtypes → methods}/object.d.ts +0 -0
- /package/out/{subtypes/string.js → methods/object.js} +0 -0
- /package/out/{subtypes/validator.js → methods/string.js} +0 -0
package/out/generic.js
CHANGED
|
@@ -32,7 +32,7 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
|
32
32
|
result.push(name);
|
|
33
33
|
return parseName(scanner, result, ctx);
|
|
34
34
|
}
|
|
35
|
-
const s = parseUntilFinalizer(new DynamicState(scanner, ctx
|
|
35
|
+
const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
|
|
36
36
|
result.push([name, s.root]);
|
|
37
37
|
return parseName(scanner, result, ctx);
|
|
38
38
|
};
|
package/out/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
export { ambient, ark, declare, define, generic, type, type Ark } from "./keywords/ark.ts";
|
|
5
5
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
package/out/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
export { ambient, ark, declare, define, generic, type } from "./keywords/ark.js";
|
|
5
5
|
export { Module } from "./module.js";
|
package/out/keywords/ark.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ import type { ArkErrors, arkKind } from "@ark/schema";
|
|
|
2
2
|
import type { inferred } from "@ark/util";
|
|
3
3
|
import type { GenericParser } from "../generic.ts";
|
|
4
4
|
import type { BoundModule, Module } from "../module.ts";
|
|
5
|
+
import type { inferDefinition } from "../parser/definition.ts";
|
|
5
6
|
import { type Scope } from "../scope.ts";
|
|
6
|
-
import type { DeclarationParser, DefinitionParser, TypeParser } from "../type.ts";
|
|
7
|
+
import type { DeclarationParser, DefinitionParser, Type, TypeParser, validateTypeRoot } from "../type.ts";
|
|
8
|
+
import type { distill } from "./ast.ts";
|
|
7
9
|
import { arkBuiltins } from "./builtins.ts";
|
|
8
10
|
import { arkPrototypes } from "./constructors/constructors.ts";
|
|
9
11
|
import { number } from "./number/number.ts";
|
|
@@ -33,7 +35,21 @@ export declare namespace type {
|
|
|
33
35
|
[inferred]?: t;
|
|
34
36
|
};
|
|
35
37
|
type errors = ArkErrors;
|
|
38
|
+
type infer<def, $ = {}, args = {}> = inferDefinition<def, $, args>;
|
|
39
|
+
namespace infer {
|
|
40
|
+
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
41
|
+
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
42
|
+
namespace brandable {
|
|
43
|
+
type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
|
|
44
|
+
type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
|
|
45
|
+
}
|
|
46
|
+
namespace introspectable {
|
|
47
|
+
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
type validate<def, $ = {}> = validateTypeRoot<def, $>;
|
|
36
51
|
}
|
|
52
|
+
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
37
53
|
export declare const generic: GenericParser<{}>;
|
|
38
54
|
export declare const define: DefinitionParser<{}>;
|
|
39
55
|
export declare const declare: DeclarationParser<{}>;
|
package/out/keywords/ast.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import type { inferPipe } from "../intersect.ts";
|
|
|
4
4
|
import type { Type } from "../type.ts";
|
|
5
5
|
import type { type } from "./ark.ts";
|
|
6
6
|
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { Date } from "./constructors/Date.ts";
|
|
8
|
+
import type { DivisibleBy, number } from "./number/number.ts";
|
|
9
|
+
import type { Matching, string } from "./string/string.ts";
|
|
9
10
|
export type { arkPrototypes as object } from "./constructors/constructors.ts";
|
|
10
11
|
export type { number } from "./number/number.ts";
|
|
11
12
|
export type { string } from "./string/string.ts";
|
|
@@ -21,36 +22,15 @@ export type constrain<base, constraints extends Constraints> = base & {
|
|
|
21
22
|
};
|
|
22
23
|
export type LimitLiteral = number | DateLiteral;
|
|
23
24
|
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
24
|
-
type constraint<rule> = {
|
|
25
|
+
export type constraint<rule> = {
|
|
25
26
|
[k in rule & PropertyKey]: 1;
|
|
26
27
|
};
|
|
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
28
|
export type Literal<rule> = {
|
|
40
29
|
literal: constraint<rule>;
|
|
41
30
|
};
|
|
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
31
|
export type Narrowed = {
|
|
52
32
|
predicate: {
|
|
53
|
-
|
|
33
|
+
"?": 1;
|
|
54
34
|
};
|
|
55
35
|
};
|
|
56
36
|
export type Branded<rule> = {
|
|
@@ -73,41 +53,14 @@ export type ExactlyLength<rule> = {
|
|
|
73
53
|
atLeastLength: constraint<rule>;
|
|
74
54
|
atMostLength: constraint<rule>;
|
|
75
55
|
};
|
|
76
|
-
export type
|
|
77
|
-
|
|
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 ([
|
|
56
|
+
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
|
|
57
|
+
export type applyConstraint<t, constraint> = parseConstraints<t> extends ([
|
|
105
58
|
infer base,
|
|
106
59
|
infer constraints extends Constraints
|
|
107
60
|
]) ? [
|
|
108
61
|
number,
|
|
109
62
|
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.
|
|
63
|
+
] 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.withConstraint<constraint> : [string, t] extends [t, string] ? string.withConstraint<constraint> : [Date, t] extends [t, Date] ? Date.withConstraint<constraint> : constrain<t, conform<constraint, Constraints>>;
|
|
111
64
|
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
112
65
|
[constrained]: constraints;
|
|
113
66
|
}> extends true ? [
|
|
@@ -125,69 +78,109 @@ export type parseConstraints<t> = t extends constrain<infer base, infer constrai
|
|
|
125
78
|
constraints
|
|
126
79
|
] : [base, constraints] : null;
|
|
127
80
|
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
128
|
-
|
|
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 {
|
|
81
|
+
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
135
82
|
exclusive: true;
|
|
136
|
-
} ?
|
|
83
|
+
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
84
|
+
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
137
85
|
exclusive: true;
|
|
138
|
-
} ?
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
86
|
+
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
87
|
+
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 "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> : Narrowed : never;
|
|
88
|
+
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
89
|
+
export declare namespace distill {
|
|
90
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
91
|
+
type Options = {
|
|
92
|
+
endpoint?: Endpoint;
|
|
93
|
+
branded?: true;
|
|
94
|
+
};
|
|
95
|
+
type In<t> = distill<t, {
|
|
96
|
+
endpoint: "in";
|
|
97
|
+
}>;
|
|
98
|
+
type Out<t> = distill<t, {
|
|
99
|
+
endpoint: "out";
|
|
100
|
+
}>;
|
|
101
|
+
namespace brandable {
|
|
102
|
+
type In<t> = distill<t, {
|
|
103
|
+
endpoint: "in";
|
|
104
|
+
branded: true;
|
|
105
|
+
}>;
|
|
106
|
+
type Out<t> = distill<t, {
|
|
107
|
+
endpoint: "out";
|
|
108
|
+
branded: true;
|
|
109
|
+
}>;
|
|
110
|
+
namespace introspectable {
|
|
111
|
+
type Out<t> = distill<t, {
|
|
112
|
+
endpoint: "out.introspectable";
|
|
113
|
+
branded: true;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
type unbranded<t> = distill<t>;
|
|
118
|
+
namespace introspectable {
|
|
119
|
+
type Out<t> = distill<t, {
|
|
120
|
+
endpoint: "out.introspectable";
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
146
124
|
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
147
125
|
export type includesMorphs<t> = [
|
|
148
|
-
_distill<t,
|
|
149
|
-
|
|
126
|
+
_distill<t, {
|
|
127
|
+
endpoint: "in";
|
|
128
|
+
branded: true;
|
|
129
|
+
}>,
|
|
130
|
+
_distill<t, {
|
|
131
|
+
endpoint: "out";
|
|
132
|
+
branded: true;
|
|
133
|
+
}>
|
|
150
134
|
] extends ([
|
|
151
|
-
_distill<t,
|
|
152
|
-
|
|
135
|
+
_distill<t, {
|
|
136
|
+
endpoint: "out";
|
|
137
|
+
branded: true;
|
|
138
|
+
}>,
|
|
139
|
+
_distill<t, {
|
|
140
|
+
endpoint: "in";
|
|
141
|
+
branded: true;
|
|
142
|
+
}>
|
|
153
143
|
]) ? false : true;
|
|
154
|
-
type
|
|
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 ([
|
|
144
|
+
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
157
145
|
infer base,
|
|
158
146
|
infer constraints extends Constraints
|
|
159
|
-
]) ?
|
|
147
|
+
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? 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 : t extends DefaultedAst<infer t> ? _distill<t, opts> : t extends array ? distillArray<t, opts, []> : t extends Function ? t : {
|
|
160
148
|
[k in keyof t]: t[k];
|
|
161
|
-
} extends t ?
|
|
162
|
-
[k in keyof t as k extends
|
|
149
|
+
} extends t ? opts["endpoint"] extends "in" ? show<{
|
|
150
|
+
[k in keyof t as k extends defaultedKeyOf<t> | metaOptionalKey<t> ? never : k]: _distill<t[k], opts>;
|
|
163
151
|
} & {
|
|
164
|
-
[k in
|
|
165
|
-
}> : {
|
|
166
|
-
[k in keyof t]: _distill<t[k],
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
152
|
+
[k in defaultedKeyOf<t> | metaOptionalKey<t>]?: _distill<t[k], opts>;
|
|
153
|
+
}> : show<{
|
|
154
|
+
[k in keyof t as k extends metaOptionalKey<t> ? never : k]: _distill<t[k], opts>;
|
|
155
|
+
} & {
|
|
156
|
+
[k in keyof t as k extends metaOptionalKey<t> ? k : never]?: _distill<t[k], opts>;
|
|
157
|
+
}> : t;
|
|
158
|
+
type defaultedKeyOf<t> = {
|
|
159
|
+
[k in keyof t]: [t[k]] extends [anyOrNever] ? never : t[k] extends DefaultedAst ? k : never;
|
|
170
160
|
}[keyof t];
|
|
171
|
-
type
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
type
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
]
|
|
180
|
-
[i in keyof t]: _distill<t[i], io, constraints>;
|
|
161
|
+
type metaOptionalKey<o> = {
|
|
162
|
+
[k in keyof o]: o[k] extends OptionalAst ? [
|
|
163
|
+
o[k]
|
|
164
|
+
] extends [anyOrNever] ? never : k : never;
|
|
165
|
+
}[keyof o];
|
|
166
|
+
type distillArray<t extends array, opts extends distill.Options, prefix extends array> = _distillArray<t, opts, prefix> extends infer result ? t extends unknown[] ? result : Readonly<t> : never;
|
|
167
|
+
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>];
|
|
168
|
+
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]> : [...{
|
|
169
|
+
[i in keyof t]: _distill<t[i], opts>;
|
|
181
170
|
}, ...postfix];
|
|
182
171
|
/** Objects we don't want to expand during inference like Date or Promise */
|
|
183
172
|
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> ?
|
|
185
|
-
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ?
|
|
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:
|
|
173
|
+
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
174
|
+
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
175
|
+
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.brandable.In<t>) => Out<out> : never, tail> : t;
|
|
187
176
|
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
188
177
|
export type Out<o = any> = ["=>", o, boolean];
|
|
189
178
|
export type To<o = any> = ["=>", o, true];
|
|
190
179
|
export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
|
|
180
|
+
export type Optional = {
|
|
181
|
+
optional?: {};
|
|
182
|
+
};
|
|
183
|
+
export type OptionalAst<t = unknown> = constrain<t, Optional>;
|
|
191
184
|
export type Default<v = any> = ["=", v];
|
|
192
|
-
export type
|
|
185
|
+
export type DefaultedAst<t = any, v = any> = (In?: t) => Default<v>;
|
|
193
186
|
export type termOrType<t> = t | Type<t, any>;
|
|
@@ -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;
|
|
@@ -12,8 +12,8 @@ const liftFrom = genericNode("element")(args => {
|
|
|
12
12
|
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootNode);
|
|
13
13
|
}, liftFromHkt);
|
|
14
14
|
export const arkArray = submodule({
|
|
15
|
-
|
|
16
|
-
readonly: "
|
|
15
|
+
root: intrinsic.Array,
|
|
16
|
+
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
18
18
|
liftFrom
|
|
19
19
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../ast.ts";
|
|
2
|
+
export type AtOrAfter<rule> = {
|
|
3
|
+
atOrAfter: constraint<rule>;
|
|
4
|
+
};
|
|
5
|
+
export type AtOrBefore<rule> = {
|
|
6
|
+
atOrBefore: constraint<rule>;
|
|
7
|
+
};
|
|
8
|
+
export type After<rule> = {
|
|
9
|
+
after: constraint<rule>;
|
|
10
|
+
};
|
|
11
|
+
export type Before<rule> = {
|
|
12
|
+
before: constraint<rule>;
|
|
13
|
+
};
|
|
14
|
+
export declare namespace Date {
|
|
15
|
+
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
16
|
+
type after<rule> = constrain<Date, After<rule>>;
|
|
17
|
+
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
18
|
+
type before<rule> = constrain<Date, Before<rule>>;
|
|
19
|
+
type narrowed = constrain<Date, Narrowed>;
|
|
20
|
+
type optional = constrain<Date, Optional>;
|
|
21
|
+
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
22
|
+
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
23
|
+
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
24
|
+
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
25
|
+
exclusive: true;
|
|
26
|
+
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
27
|
+
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
28
|
+
exclusive: true;
|
|
29
|
+
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
30
|
+
type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Narrowed ? narrowed : never;
|
|
31
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { AtLeast, AtMost, DivisibleBy } from "
|
|
2
|
-
import type { number } from "./number.ts";
|
|
1
|
+
import type { AtLeast, AtMost, DivisibleBy, number } from "./number.ts";
|
|
3
2
|
/**
|
|
4
3
|
* As per the ECMA-262 specification:
|
|
5
4
|
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
import { type Constraint, type NodeSchema } from "@ark/schema";
|
|
2
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type {
|
|
2
|
+
import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../ast.ts";
|
|
4
3
|
import { epoch } from "./epoch.ts";
|
|
5
4
|
import { integer } from "./integer.ts";
|
|
6
5
|
export declare const number: number.module;
|
|
6
|
+
export type AtLeast<rule> = {
|
|
7
|
+
atLeast: constraint<rule>;
|
|
8
|
+
};
|
|
9
|
+
export type AtMost<rule> = {
|
|
10
|
+
atMost: constraint<rule>;
|
|
11
|
+
};
|
|
12
|
+
export type MoreThan<rule> = {
|
|
13
|
+
moreThan: constraint<rule>;
|
|
14
|
+
};
|
|
15
|
+
export type LessThan<rule> = {
|
|
16
|
+
lessThan: constraint<rule>;
|
|
17
|
+
};
|
|
18
|
+
export type DivisibleBy<rule> = {
|
|
19
|
+
divisibleBy: constraint<rule>;
|
|
20
|
+
};
|
|
7
21
|
export declare namespace number {
|
|
8
22
|
type atLeast<rule> = constrain<number, AtLeast<rule>>;
|
|
9
23
|
type moreThan<rule> = constrain<number, MoreThan<rule>>;
|
|
@@ -11,17 +25,20 @@ export declare namespace number {
|
|
|
11
25
|
type lessThan<rule> = constrain<number, LessThan<rule>>;
|
|
12
26
|
type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
|
|
13
27
|
type narrowed = constrain<number, Narrowed>;
|
|
28
|
+
type optional = constrain<number, Optional>;
|
|
14
29
|
type branded<rule> = constrain<number, Branded<rule>>;
|
|
15
30
|
type is<constraints extends Constraints> = constrain<number, constraints>;
|
|
16
|
-
type
|
|
31
|
+
type minSchemaToConstraint<schema, rule> = schema extends {
|
|
17
32
|
exclusive: true;
|
|
18
|
-
} ?
|
|
33
|
+
} ? MoreThan<rule> : AtLeast<rule>;
|
|
34
|
+
type maxSchemaToConstraint<schema, rule> = schema extends {
|
|
19
35
|
exclusive: true;
|
|
20
|
-
} ?
|
|
36
|
+
} ? LessThan<rule> : AtMost<rule>;
|
|
37
|
+
type withConstraint<constraint> = constraint extends MoreThan<infer rule> ? moreThan<rule> : constraint extends AtLeast<infer rule> ? atLeast<rule> : constraint extends AtMost<infer rule> ? atMost<rule> : constraint extends LessThan<infer rule> ? lessThan<rule> : constraint extends DivisibleBy<infer rule> ? divisibleBy<rule> : constraint extends Optional ? optional : constraint extends Narrowed ? narrowed : never;
|
|
21
38
|
type module = Module<submodule>;
|
|
22
39
|
type submodule = Submodule<$>;
|
|
23
40
|
type $ = {
|
|
24
|
-
|
|
41
|
+
root: number;
|
|
25
42
|
epoch: epoch;
|
|
26
43
|
integer: integer;
|
|
27
44
|
};
|
|
@@ -8,7 +8,7 @@ export declare namespace capitalize {
|
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.capitalized>;
|
|
12
12
|
preformatted: string.capitalized;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -3,7 +3,7 @@ import { submodule } from "../utils.js";
|
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z].*$/, "capitalized");
|
|
5
5
|
export const capitalize = submodule({
|
|
6
|
-
|
|
6
|
+
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -33,7 +33,7 @@ export declare namespace stringDate {
|
|
|
33
33
|
type module = Module<stringDate.submodule>;
|
|
34
34
|
type submodule = Submodule<$>;
|
|
35
35
|
type $ = {
|
|
36
|
-
|
|
36
|
+
root: string.date;
|
|
37
37
|
parse: (In: string.date) => To<Date>;
|
|
38
38
|
iso: iso.submodule;
|
|
39
39
|
epoch: epoch.submodule;
|
|
@@ -44,14 +44,14 @@ export declare namespace stringDate {
|
|
|
44
44
|
namespace iso {
|
|
45
45
|
type submodule = Submodule<$>;
|
|
46
46
|
type $ = {
|
|
47
|
-
|
|
47
|
+
root: string.date.iso;
|
|
48
48
|
parse: (In: string.date.iso) => To<Date>;
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
namespace epoch {
|
|
52
52
|
type submodule = Submodule<$>;
|
|
53
53
|
type $ = {
|
|
54
|
-
|
|
54
|
+
root: string.date.epoch;
|
|
55
55
|
parse: (In: string.date.epoch) => To<Date>;
|
|
56
56
|
};
|
|
57
57
|
}
|
|
@@ -47,7 +47,7 @@ const parsableDate = rootNode({
|
|
|
47
47
|
predicate: isParsableDate
|
|
48
48
|
}
|
|
49
49
|
}).assertHasKind("intersection");
|
|
50
|
-
const
|
|
50
|
+
const epochroot = integer.root.internal
|
|
51
51
|
.narrow((s, ctx) => {
|
|
52
52
|
// we know this is safe since it has already
|
|
53
53
|
// been validated as an integer string
|
|
@@ -64,24 +64,24 @@ const epoch$root = integer.$root.internal
|
|
|
64
64
|
})
|
|
65
65
|
.assertHasKind("intersection");
|
|
66
66
|
const epoch = submodule({
|
|
67
|
-
|
|
67
|
+
root: epochroot,
|
|
68
68
|
parse: rootNode({
|
|
69
|
-
in:
|
|
69
|
+
in: epochroot,
|
|
70
70
|
morphs: (s) => new Date(s),
|
|
71
71
|
declaredOut: intrinsic.Date
|
|
72
72
|
})
|
|
73
73
|
});
|
|
74
|
-
const
|
|
74
|
+
const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
|
|
75
75
|
const iso = submodule({
|
|
76
|
-
|
|
76
|
+
root: isoroot,
|
|
77
77
|
parse: rootNode({
|
|
78
|
-
in:
|
|
78
|
+
in: isoroot,
|
|
79
79
|
morphs: (s) => new Date(s),
|
|
80
80
|
declaredOut: intrinsic.Date
|
|
81
81
|
})
|
|
82
82
|
});
|
|
83
83
|
export const stringDate = submodule({
|
|
84
|
-
|
|
84
|
+
root: parsableDate,
|
|
85
85
|
parse: rootNode({
|
|
86
86
|
declaredIn: parsableDate,
|
|
87
87
|
in: "string",
|
|
@@ -2,11 +2,11 @@ import { intrinsic, rootNode } from "@ark/schema";
|
|
|
2
2
|
import { wellFormedIntegerMatcher } from "@ark/util";
|
|
3
3
|
import { submodule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
5
|
+
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
6
6
|
export const integer = submodule({
|
|
7
|
-
|
|
7
|
+
root,
|
|
8
8
|
parse: rootNode({
|
|
9
|
-
in:
|
|
9
|
+
in: root,
|
|
10
10
|
morphs: (s, ctx) => {
|
|
11
11
|
const parsed = Number.parseInt(s);
|
|
12
12
|
return Number.isSafeInteger(parsed) ? parsed : (ctx.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER"));
|
|
@@ -17,7 +17,7 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
17
17
|
")(%[0-9a-zA-Z-.:]{1,})?$");
|
|
18
18
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
19
19
|
export const ip = submodule({
|
|
20
|
-
|
|
20
|
+
root: ["v4 | v6", "@", "an IP address"],
|
|
21
21
|
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
22
|
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
23
23
|
});
|
|
@@ -10,7 +10,7 @@ const isParsableJson = (s) => {
|
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const root = rootNode({
|
|
14
14
|
domain: "string",
|
|
15
15
|
predicate: {
|
|
16
16
|
meta: jsonStringDescription,
|
|
@@ -18,7 +18,7 @@ const $root = rootNode({
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
export const json = submodule({
|
|
21
|
-
|
|
21
|
+
root,
|
|
22
22
|
parse: rootNode({
|
|
23
23
|
in: "string",
|
|
24
24
|
morphs: (s, ctx) => {
|