arktype 2.0.0-rc.1 → 2.0.0-rc.11
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/config.d.ts +1 -1
- package/out/generic.d.ts +47 -48
- 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 +32 -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/inference.d.ts +228 -0
- package/out/keywords/keywords.d.ts +62 -0
- package/out/keywords/{ark.js → keywords.js} +11 -8
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +32 -6
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +1 -1
- package/out/keywords/string/alphanumeric.d.ts +1 -1
- package/out/keywords/string/capitalize.d.ts +2 -2
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +1 -1
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +4 -8
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +1 -1
- package/out/keywords/string/email.d.ts +1 -1
- package/out/keywords/string/integer.d.ts +2 -2
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +2 -2
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +3 -2
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +2 -2
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +23 -27
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +2 -2
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +39 -42
- package/out/keywords/string/string.js +3 -3
- package/out/keywords/string/trim.d.ts +2 -2
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +2 -2
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +2 -2
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +11 -11
- 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 +96 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/instantiate.d.ts +5 -4
- package/out/methods/morph.d.ts +12 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/methods/object.d.ts +81 -0
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- 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/{semantic → ast}/infer.d.ts +11 -11
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +6 -6
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +11 -37
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
- 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 +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +1 -6
- package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
- package/out/parser/{string/shift → shift}/scanner.js +5 -3
- 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 +54 -43
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +32 -39
- package/out/scope.js +43 -35
- package/out/type.d.ts +24 -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/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/object.d.ts +0 -33
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/keywords/{ast.js → inference.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/{subtypes → methods}/validator.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/{semantic → ast}/validate.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}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
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 objectKindOf, type Primitive, type show } from "@ark/util";
|
|
3
|
+
import type { Type } from "../type.ts";
|
|
4
|
+
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
5
|
+
import type { Date } from "./constructors/Date.ts";
|
|
6
|
+
import type { type } from "./keywords.ts";
|
|
7
|
+
import type { DivisibleBy, number } from "./number/number.ts";
|
|
8
|
+
import type { Matching, 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
|
+
default?: unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare const constrained: " arkConstrained";
|
|
20
|
+
export type constrained = typeof constrained;
|
|
21
|
+
export type constrain<base, constraints extends Constraints> = base & {
|
|
22
|
+
[constrained]: constraints;
|
|
23
|
+
};
|
|
24
|
+
export type LimitLiteral = number | DateLiteral;
|
|
25
|
+
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
26
|
+
export type constraint<rule> = {
|
|
27
|
+
[k in rule & PropertyKey]: 1;
|
|
28
|
+
};
|
|
29
|
+
export type Literal<rule> = {
|
|
30
|
+
literal: constraint<rule>;
|
|
31
|
+
};
|
|
32
|
+
export type Narrowed = {
|
|
33
|
+
predicate: {
|
|
34
|
+
"?": 1;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type Branded<rule> = {
|
|
38
|
+
predicate: constraint<rule>;
|
|
39
|
+
};
|
|
40
|
+
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
41
|
+
export type AtLeastLength<rule> = {
|
|
42
|
+
atLeastLength: constraint<rule>;
|
|
43
|
+
};
|
|
44
|
+
export type AtMostLength<rule> = {
|
|
45
|
+
atMostLength: constraint<rule>;
|
|
46
|
+
};
|
|
47
|
+
export type MoreThanLength<rule> = {
|
|
48
|
+
moreThanLength: constraint<rule>;
|
|
49
|
+
};
|
|
50
|
+
export type LessThanLength<rule> = {
|
|
51
|
+
lessThanLength: constraint<rule>;
|
|
52
|
+
};
|
|
53
|
+
export type ExactlyLength<rule> = {
|
|
54
|
+
atLeastLength: constraint<rule>;
|
|
55
|
+
atMostLength: constraint<rule>;
|
|
56
|
+
};
|
|
57
|
+
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyConstraint<t, schemaToConstraint<kind, schema>>;
|
|
58
|
+
export type applyConstraint<t, constraint> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, constraint>>) => o : leftIfEqual<t, _applyConstraint<t, constraint>>;
|
|
59
|
+
type _applyConstraint<t, constraint> = parseConstraints<t> extends ([
|
|
60
|
+
infer base,
|
|
61
|
+
infer constraints extends Constraints
|
|
62
|
+
]) ? [
|
|
63
|
+
number,
|
|
64
|
+
base
|
|
65
|
+
] 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>>;
|
|
66
|
+
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
67
|
+
[constrained]: constraints;
|
|
68
|
+
}> extends true ? [
|
|
69
|
+
number,
|
|
70
|
+
constraints
|
|
71
|
+
] : equals<t, string & {
|
|
72
|
+
[constrained]: constraints;
|
|
73
|
+
}> extends true ? [
|
|
74
|
+
string,
|
|
75
|
+
constraints
|
|
76
|
+
] : equals<t, bigint & {
|
|
77
|
+
[constrained]: constraints;
|
|
78
|
+
}> extends true ? [
|
|
79
|
+
bigint,
|
|
80
|
+
constraints
|
|
81
|
+
] : equals<t, symbol & {
|
|
82
|
+
[constrained]: constraints;
|
|
83
|
+
}> extends true ? [
|
|
84
|
+
symbol,
|
|
85
|
+
constraints
|
|
86
|
+
] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [
|
|
87
|
+
arkPrototypes.instanceOf<kind>,
|
|
88
|
+
constraints
|
|
89
|
+
] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null;
|
|
90
|
+
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
91
|
+
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
92
|
+
exclusive: true;
|
|
93
|
+
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
94
|
+
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
95
|
+
exclusive: true;
|
|
96
|
+
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
97
|
+
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;
|
|
98
|
+
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
99
|
+
export declare namespace distill {
|
|
100
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
101
|
+
type Options = {
|
|
102
|
+
endpoint?: Endpoint;
|
|
103
|
+
branded?: true;
|
|
104
|
+
};
|
|
105
|
+
type In<t> = distill<t, {
|
|
106
|
+
endpoint: "in";
|
|
107
|
+
}>;
|
|
108
|
+
type Out<t> = distill<t, {
|
|
109
|
+
endpoint: "out";
|
|
110
|
+
}>;
|
|
111
|
+
namespace brandable {
|
|
112
|
+
type In<t> = distill<t, {
|
|
113
|
+
endpoint: "in";
|
|
114
|
+
branded: true;
|
|
115
|
+
}>;
|
|
116
|
+
type Out<t> = distill<t, {
|
|
117
|
+
endpoint: "out";
|
|
118
|
+
branded: true;
|
|
119
|
+
}>;
|
|
120
|
+
namespace introspectable {
|
|
121
|
+
type Out<t> = distill<t, {
|
|
122
|
+
endpoint: "out.introspectable";
|
|
123
|
+
branded: true;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
type unbranded<t> = distill<t>;
|
|
128
|
+
namespace introspectable {
|
|
129
|
+
type Out<t> = distill<t, {
|
|
130
|
+
endpoint: "out.introspectable";
|
|
131
|
+
}>;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
135
|
+
export type includesMorphs<t> = [
|
|
136
|
+
_distill<t, {
|
|
137
|
+
endpoint: "in";
|
|
138
|
+
branded: true;
|
|
139
|
+
}>,
|
|
140
|
+
_distill<t, {
|
|
141
|
+
endpoint: "out";
|
|
142
|
+
branded: true;
|
|
143
|
+
}>
|
|
144
|
+
] extends ([
|
|
145
|
+
_distill<t, {
|
|
146
|
+
endpoint: "out";
|
|
147
|
+
branded: true;
|
|
148
|
+
}>,
|
|
149
|
+
_distill<t, {
|
|
150
|
+
endpoint: "in";
|
|
151
|
+
branded: true;
|
|
152
|
+
}>
|
|
153
|
+
]) ? false : true;
|
|
154
|
+
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
155
|
+
infer base,
|
|
156
|
+
infer constraints extends Constraints
|
|
157
|
+
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
|
|
158
|
+
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
|
|
159
|
+
[k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
160
|
+
} & {
|
|
161
|
+
[k in inferredOptionalOrDefaultKeyOf<o>]?: _distill<o[k], opts>;
|
|
162
|
+
}> : show<{
|
|
163
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
164
|
+
} & {
|
|
165
|
+
[k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
|
|
166
|
+
}>;
|
|
167
|
+
type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
|
|
168
|
+
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;
|
|
169
|
+
type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
|
|
170
|
+
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
|
|
171
|
+
o[k]
|
|
172
|
+
] extends [anyOrNever] ? never : o[k] extends InferredDefault ? k : never : never : never;
|
|
173
|
+
type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
|
|
174
|
+
o[k]
|
|
175
|
+
] extends [anyOrNever] ? never : o[k] extends InferredOptional ? k : never : never : never;
|
|
176
|
+
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>;
|
|
177
|
+
type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
|
|
178
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
|
|
179
|
+
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
|
|
180
|
+
}, opts>;
|
|
181
|
+
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>];
|
|
182
|
+
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]> : [...{
|
|
183
|
+
[i in keyof t]: _distill<t[i], opts>;
|
|
184
|
+
}, ...postfix];
|
|
185
|
+
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
186
|
+
/** Objects we don't want to expand during inference like Date or Promise */
|
|
187
|
+
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
188
|
+
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>;
|
|
189
|
+
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
190
|
+
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;
|
|
191
|
+
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
192
|
+
export type Out<o = any> = ["=>", o, boolean];
|
|
193
|
+
export type To<o = any> = ["=>", o, true];
|
|
194
|
+
export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
|
|
195
|
+
export type Optional = {
|
|
196
|
+
optional?: {};
|
|
197
|
+
};
|
|
198
|
+
export type InferredOptional<t = unknown> = constrain<t, Optional>;
|
|
199
|
+
export type Default<v = any> = {
|
|
200
|
+
default?: {
|
|
201
|
+
value: v;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>;
|
|
205
|
+
export type termOrType<t> = t | Type<t, any>;
|
|
206
|
+
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
207
|
+
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
208
|
+
type _inferIntersection<l, r, piped extends boolean> = [
|
|
209
|
+
l & r
|
|
210
|
+
] 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 : parseConstraints<l> extends ([
|
|
211
|
+
infer lBase,
|
|
212
|
+
infer lConstraints extends Constraints
|
|
213
|
+
]) ? parseConstraints<r> extends ([
|
|
214
|
+
infer rBase,
|
|
215
|
+
infer rConstraints extends Constraints
|
|
216
|
+
]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
|
|
217
|
+
infer rBase,
|
|
218
|
+
infer rConstraints extends Constraints
|
|
219
|
+
]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
220
|
+
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
221
|
+
body: _inferIntersection<this[0], this[1], piped>;
|
|
222
|
+
}
|
|
223
|
+
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[],
|
|
224
|
+
l & r : r extends array ? l & r : show<{
|
|
225
|
+
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
226
|
+
} & {
|
|
227
|
+
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
228
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { BaseType } from "../methods/base.ts";
|
|
5
|
+
import type { BoundModule, Module } from "../module.ts";
|
|
6
|
+
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
|
|
7
|
+
import { type bindThis, type Scope } from "../scope.ts";
|
|
8
|
+
import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
|
|
9
|
+
import { arkBuiltins } from "./builtins.ts";
|
|
10
|
+
import { arkPrototypes } from "./constructors/constructors.ts";
|
|
11
|
+
import type { distill } from "./inference.ts";
|
|
12
|
+
import { number } from "./number/number.ts";
|
|
13
|
+
import { string } from "./string/string.ts";
|
|
14
|
+
import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.ts";
|
|
15
|
+
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
16
|
+
}
|
|
17
|
+
export declare namespace Ark {
|
|
18
|
+
interface keywords extends arkTsKeywords.$, arkTsGenerics.$, arkPrototypes.keywords, arkBuiltins.$ {
|
|
19
|
+
}
|
|
20
|
+
interface wrapped extends arkPrototypes.wrapped {
|
|
21
|
+
string: string.submodule;
|
|
22
|
+
number: number.submodule;
|
|
23
|
+
object: object.submodule;
|
|
24
|
+
unknown: unknown.submodule;
|
|
25
|
+
}
|
|
26
|
+
interface typeAttachments extends arkTsKeywords.$ {
|
|
27
|
+
Key: arkBuiltins.$["Key"];
|
|
28
|
+
Record: arkTsGenerics.$["Record"];
|
|
29
|
+
}
|
|
30
|
+
interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export declare const ark: Scope<Ark>;
|
|
34
|
+
export declare const keywords: Module<Ark>;
|
|
35
|
+
export declare const type: TypeParser<{}>;
|
|
36
|
+
export declare namespace type {
|
|
37
|
+
type cast<t> = {
|
|
38
|
+
[inferred]?: t;
|
|
39
|
+
};
|
|
40
|
+
type errors = ArkErrors;
|
|
41
|
+
/** @ts-ignore cast variance */
|
|
42
|
+
interface Any<out t = any> extends BaseType<t, any> {
|
|
43
|
+
}
|
|
44
|
+
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
|
|
45
|
+
namespace infer {
|
|
46
|
+
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
47
|
+
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
48
|
+
namespace brandable {
|
|
49
|
+
type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
|
|
50
|
+
type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
|
|
51
|
+
}
|
|
52
|
+
namespace introspectable {
|
|
53
|
+
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
57
|
+
}
|
|
58
|
+
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
59
|
+
export declare const generic: GenericParser<{}>;
|
|
60
|
+
export declare const schema: SchemaParser<{}>;
|
|
61
|
+
export declare const define: DefinitionParser<{}>;
|
|
62
|
+
export declare const declare: DeclarationParser<{}>;
|
|
@@ -3,22 +3,25 @@ import { arkBuiltins } from "./builtins.js";
|
|
|
3
3
|
import { arkPrototypes } from "./constructors/constructors.js";
|
|
4
4
|
import { number } from "./number/number.js";
|
|
5
5
|
import { string } from "./string/string.js";
|
|
6
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.js";
|
|
6
|
+
import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.js";
|
|
7
7
|
$arkTypeRegistry.typeAttachments = {
|
|
8
8
|
...arkTsKeywords,
|
|
9
9
|
Key: arkBuiltins.Key,
|
|
10
10
|
Record: arkTsGenerics.Record
|
|
11
11
|
};
|
|
12
|
-
export const
|
|
12
|
+
export const ark = scope({
|
|
13
13
|
...arkTsKeywords,
|
|
14
14
|
...arkTsGenerics,
|
|
15
15
|
...arkPrototypes,
|
|
16
16
|
...arkBuiltins,
|
|
17
17
|
string,
|
|
18
|
-
number
|
|
18
|
+
number,
|
|
19
|
+
object,
|
|
20
|
+
unknown
|
|
19
21
|
}, { prereducedAliases: true, ambient: true });
|
|
20
|
-
export const
|
|
21
|
-
export const type =
|
|
22
|
-
export const generic =
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
22
|
+
export const keywords = ark.export();
|
|
23
|
+
export const type = ark.type;
|
|
24
|
+
export const generic = ark.generic;
|
|
25
|
+
export const schema = ark.schema;
|
|
26
|
+
export const define = ark.define;
|
|
27
|
+
export const declare = ark.declare;
|
|
@@ -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,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
/**
|
|
3
3
|
* As per the ECMA-262 specification:
|
|
4
4
|
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
5
5
|
*
|
|
6
6
|
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
7
7
|
*/
|
|
8
|
-
export const epoch =
|
|
8
|
+
export const epoch = rootSchema({
|
|
9
9
|
domain: {
|
|
10
10
|
domain: "number",
|
|
11
11
|
meta: "a number representing a Unix timestamp"
|
|
@@ -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, Default, Narrowed, Optional } from "../inference.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,18 +25,30 @@ 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>;
|
|
29
|
+
type defaultsTo<rule> = constrain<number, Default<rule>>;
|
|
14
30
|
type branded<rule> = constrain<number, Branded<rule>>;
|
|
31
|
+
type NaN = branded<"NaN">;
|
|
32
|
+
type Infinity = branded<"Infinity">;
|
|
33
|
+
type NegativeInfinity = branded<"NegativeInfinity">;
|
|
34
|
+
type safe = branded<"safe">;
|
|
15
35
|
type is<constraints extends Constraints> = constrain<number, constraints>;
|
|
16
|
-
type
|
|
36
|
+
type minSchemaToConstraint<schema, rule> = schema extends {
|
|
17
37
|
exclusive: true;
|
|
18
|
-
} ?
|
|
38
|
+
} ? MoreThan<rule> : AtLeast<rule>;
|
|
39
|
+
type maxSchemaToConstraint<schema, rule> = schema extends {
|
|
19
40
|
exclusive: true;
|
|
20
|
-
} ?
|
|
41
|
+
} ? LessThan<rule> : AtMost<rule>;
|
|
42
|
+
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 Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
|
|
21
43
|
type module = Module<submodule>;
|
|
22
44
|
type submodule = Submodule<$>;
|
|
23
45
|
type $ = {
|
|
24
|
-
|
|
46
|
+
root: number;
|
|
25
47
|
epoch: epoch;
|
|
26
48
|
integer: integer;
|
|
49
|
+
safe: safe;
|
|
50
|
+
NaN: NaN;
|
|
51
|
+
Infinity: Infinity;
|
|
52
|
+
NegativeInfinity: NegativeInfinity;
|
|
27
53
|
};
|
|
28
54
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import {
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { epoch } from "./epoch.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
|
-
export const number =
|
|
6
|
-
|
|
5
|
+
export const number = arkModule({
|
|
6
|
+
root: intrinsic.number,
|
|
7
7
|
integer,
|
|
8
|
-
epoch
|
|
8
|
+
epoch,
|
|
9
|
+
safe: rootSchema({
|
|
10
|
+
domain: "number",
|
|
11
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
12
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
13
|
+
predicate: {
|
|
14
|
+
predicate: n => !Number.isNaN(n),
|
|
15
|
+
meta: "a safe number"
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
NaN: ["===", Number.NaN],
|
|
19
|
+
Infinity: ["===", Number.POSITIVE_INFINITY],
|
|
20
|
+
NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
|
|
9
21
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type capitalized = constrain<string, Branded<"capitalized">>;
|
|
5
5
|
}
|
|
@@ -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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z].*$/, "capitalized");
|
|
5
|
-
export const capitalize =
|
|
6
|
-
|
|
5
|
+
export const capitalize = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Branded, constrain } from "../
|
|
1
|
+
import type { Branded, constrain } from "../inference.ts";
|
|
2
2
|
export declare const isLuhnValid: (creditCardInput: string) => boolean;
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type creditCard = constrain<string, Branded<"creditCard">>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isLuhnNumber.js
|
|
3
3
|
export const isLuhnValid = (creditCardInput) => {
|
|
4
4
|
const sanitized = creditCardInput.replace(/[- ]+/g, "");
|
|
@@ -24,7 +24,7 @@ export const isLuhnValid = (creditCardInput) => {
|
|
|
24
24
|
};
|
|
25
25
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
|
|
26
26
|
const creditCardMatcher = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
|
|
27
|
-
export const creditCard =
|
|
27
|
+
export const creditCard = rootSchema({
|
|
28
28
|
domain: "string",
|
|
29
29
|
pattern: {
|
|
30
30
|
meta: "a credit card number",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Branded, To, constrain } from "../ast.ts";
|
|
2
|
+
import type { Branded, To, constrain } from "../inference.ts";
|
|
4
3
|
type DayDelimiter = "." | "/" | "-";
|
|
5
4
|
type DayPart = DayPatterns[PartKey];
|
|
6
5
|
type PartKey = keyof DayPatterns;
|
|
@@ -33,25 +32,22 @@ export declare namespace stringDate {
|
|
|
33
32
|
type module = Module<stringDate.submodule>;
|
|
34
33
|
type submodule = Submodule<$>;
|
|
35
34
|
type $ = {
|
|
36
|
-
|
|
35
|
+
root: string.date;
|
|
37
36
|
parse: (In: string.date) => To<Date>;
|
|
38
37
|
iso: iso.submodule;
|
|
39
38
|
epoch: epoch.submodule;
|
|
40
39
|
};
|
|
41
|
-
type shallowResolutions = {
|
|
42
|
-
[k in keyof $ as `string.date.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
43
|
-
};
|
|
44
40
|
namespace iso {
|
|
45
41
|
type submodule = Submodule<$>;
|
|
46
42
|
type $ = {
|
|
47
|
-
|
|
43
|
+
root: string.date.iso;
|
|
48
44
|
parse: (In: string.date.iso) => To<Date>;
|
|
49
45
|
};
|
|
50
46
|
}
|
|
51
47
|
namespace epoch {
|
|
52
48
|
type submodule = Submodule<$>;
|
|
53
49
|
type $ = {
|
|
54
|
-
|
|
50
|
+
root: string.date.epoch;
|
|
55
51
|
parse: (In: string.date.epoch) => To<Date>;
|
|
56
52
|
};
|
|
57
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArkErrors, intrinsic,
|
|
1
|
+
import { ArkErrors, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { number } from "../number/number.js";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
5
|
import { regexStringNode } from "./utils.js";
|
|
6
6
|
const dayDelimiterMatcher = /^[./-]$/;
|
|
@@ -40,14 +40,14 @@ export const tryParseDatePattern = (data, opts) => {
|
|
|
40
40
|
return writeFormattedExpected(opts.format);
|
|
41
41
|
};
|
|
42
42
|
const isParsableDate = (s) => !Number.isNaN(new Date(s).valueOf());
|
|
43
|
-
const parsableDate =
|
|
43
|
+
const parsableDate = rootSchema({
|
|
44
44
|
domain: "string",
|
|
45
45
|
predicate: {
|
|
46
46
|
meta: "a parsable date",
|
|
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
|
|
@@ -63,26 +63,26 @@ const epoch$root = integer.$root.internal
|
|
|
63
63
|
description: "an integer string representing a safe Unix timestamp"
|
|
64
64
|
})
|
|
65
65
|
.assertHasKind("intersection");
|
|
66
|
-
const epoch =
|
|
67
|
-
|
|
68
|
-
parse:
|
|
69
|
-
in:
|
|
66
|
+
const epoch = arkModule({
|
|
67
|
+
root: epochRoot,
|
|
68
|
+
parse: rootSchema({
|
|
69
|
+
in: epochRoot,
|
|
70
70
|
morphs: (s) => new Date(s),
|
|
71
71
|
declaredOut: intrinsic.Date
|
|
72
72
|
})
|
|
73
73
|
});
|
|
74
|
-
const
|
|
75
|
-
const iso =
|
|
76
|
-
|
|
77
|
-
parse:
|
|
78
|
-
in:
|
|
74
|
+
const isoRoot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
|
|
75
|
+
const iso = arkModule({
|
|
76
|
+
root: isoRoot,
|
|
77
|
+
parse: rootSchema({
|
|
78
|
+
in: isoRoot,
|
|
79
79
|
morphs: (s) => new Date(s),
|
|
80
80
|
declaredOut: intrinsic.Date
|
|
81
81
|
})
|
|
82
82
|
});
|
|
83
|
-
export const stringDate =
|
|
84
|
-
|
|
85
|
-
parse:
|
|
83
|
+
export const stringDate = arkModule({
|
|
84
|
+
root: parsableDate,
|
|
85
|
+
parse: rootSchema({
|
|
86
86
|
declaredIn: parsableDate,
|
|
87
87
|
in: "string",
|
|
88
88
|
morphs: (s, ctx) => {
|