arktype 2.0.0-rc.2 → 2.0.0-rc.21
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 +45 -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 +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 +11 -37
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
- 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 +4 -3
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- 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/operator.d.ts +2 -1
- package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
- package/out/parser/{string/shift → shift}/scanner.js +6 -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 +56 -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/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}/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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
4
|
-
const value =
|
|
5
|
-
const parsedFormDataValue = value.
|
|
6
|
-
const parsed =
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
|
+
const value = rootSchema(["string", registry.FileConstructor]);
|
|
5
|
+
const parsedFormDataValue = value.rawOr(value.array());
|
|
6
|
+
const parsed = rootSchema({
|
|
7
7
|
meta: "an object representing parsed form data",
|
|
8
8
|
domain: "object",
|
|
9
9
|
index: {
|
|
@@ -11,11 +11,11 @@ const parsed = rootNode({
|
|
|
11
11
|
value: parsedFormDataValue
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
export const arkFormData =
|
|
15
|
-
|
|
14
|
+
export const arkFormData = arkModule({
|
|
15
|
+
root: ["instanceof", FormData],
|
|
16
16
|
value,
|
|
17
17
|
parsed,
|
|
18
|
-
parse:
|
|
18
|
+
parse: rootSchema({
|
|
19
19
|
in: FormData,
|
|
20
20
|
morphs: (data) => {
|
|
21
21
|
const result = {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const TypedArray =
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
|
+
export const TypedArray = arkModule({
|
|
3
3
|
Int8: ["instanceof", Int8Array],
|
|
4
4
|
Uint8: ["instanceof", Uint8Array],
|
|
5
5
|
Uint8Clamped: ["instanceof", Uint8ClampedArray],
|
|
@@ -26,6 +26,5 @@ export declare namespace arkPrototypes {
|
|
|
26
26
|
interface instances extends ecmascript, platform {
|
|
27
27
|
}
|
|
28
28
|
type instanceOf<name extends keyof instances = keyof instances> = instances[name];
|
|
29
|
-
type instanceOfExcluding<name extends keyof instances = keyof instances> = instances[Exclude<keyof instances, name>];
|
|
30
29
|
}
|
|
31
30
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { arkArray } from "./Array.js";
|
|
4
4
|
import { arkFormData } from "./FormData.js";
|
|
5
5
|
import { TypedArray } from "./TypedArray.js";
|
|
@@ -8,7 +8,7 @@ const omittedPrototypes = {
|
|
|
8
8
|
Number: 1,
|
|
9
9
|
String: 1
|
|
10
10
|
};
|
|
11
|
-
export const arkPrototypes =
|
|
11
|
+
export const arkPrototypes = arkModule({
|
|
12
12
|
...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
|
|
13
13
|
Array: arkArray,
|
|
14
14
|
TypedArray,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ArkErrors, arkKind } from "@ark/schema";
|
|
2
|
+
import type { inferred } from "@ark/util";
|
|
3
|
+
import type { distill } from "../attributes.ts";
|
|
4
|
+
import type { GenericParser } from "../generic.ts";
|
|
5
|
+
import type { BaseType } from "../methods/base.ts";
|
|
6
|
+
import type { BoundModule, Module } from "../module.ts";
|
|
7
|
+
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
|
|
8
|
+
import { type bindThis, type Scope } from "../scope.ts";
|
|
9
|
+
import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
|
|
10
|
+
import { arkBuiltins } from "./builtins.ts";
|
|
11
|
+
import { arkPrototypes } from "./constructors/constructors.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
|
+
Date: arkPrototypes.$["Date"];
|
|
30
|
+
Array: arkPrototypes.$["Array"]["root"];
|
|
31
|
+
}
|
|
32
|
+
interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export declare const ark: Scope<Ark>;
|
|
36
|
+
export declare const keywords: Module<Ark>;
|
|
37
|
+
export declare const type: TypeParser<{}>;
|
|
38
|
+
export declare namespace type {
|
|
39
|
+
type cast<t> = {
|
|
40
|
+
[inferred]?: t;
|
|
41
|
+
};
|
|
42
|
+
type errors = ArkErrors;
|
|
43
|
+
/** @ts-ignore cast variance */
|
|
44
|
+
interface Any<out t = any> extends BaseType<t, any> {
|
|
45
|
+
}
|
|
46
|
+
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
|
|
47
|
+
namespace infer {
|
|
48
|
+
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
49
|
+
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
50
|
+
namespace withAttributes {
|
|
51
|
+
type In<def, $ = {}, args = {}> = distill.withAttributes.In<inferDefinition<def, $, args>>;
|
|
52
|
+
type Out<def, $ = {}, args = {}> = distill.withAttributes.Out<inferDefinition<def, $, args>>;
|
|
53
|
+
}
|
|
54
|
+
namespace introspectable {
|
|
55
|
+
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
59
|
+
}
|
|
60
|
+
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
61
|
+
export declare const generic: GenericParser<{}>;
|
|
62
|
+
export declare const schema: SchemaParser<{}>;
|
|
63
|
+
export declare const define: DefinitionParser<{}>;
|
|
64
|
+
export declare const declare: DeclarationParser<{}>;
|
|
@@ -3,22 +3,27 @@ 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
|
-
Record: arkTsGenerics.Record
|
|
10
|
+
Record: arkTsGenerics.Record,
|
|
11
|
+
Array: arkPrototypes.Array.root,
|
|
12
|
+
Date: arkPrototypes.Date
|
|
11
13
|
};
|
|
12
|
-
export const
|
|
14
|
+
export const ark = scope({
|
|
13
15
|
...arkTsKeywords,
|
|
14
16
|
...arkTsGenerics,
|
|
15
17
|
...arkPrototypes,
|
|
16
18
|
...arkBuiltins,
|
|
17
19
|
string,
|
|
18
|
-
number
|
|
20
|
+
number,
|
|
21
|
+
object,
|
|
22
|
+
unknown
|
|
19
23
|
}, { prereducedAliases: true, ambient: true });
|
|
20
|
-
export const
|
|
21
|
-
export const type =
|
|
22
|
-
export const generic =
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
24
|
+
export const keywords = ark.export();
|
|
25
|
+
export const type = ark.type;
|
|
26
|
+
export const generic = ark.generic;
|
|
27
|
+
export const schema = ark.schema;
|
|
28
|
+
export const define = ark.define;
|
|
29
|
+
export const declare = ark.declare;
|
|
@@ -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,28 +1,58 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { satisfy } from "@ark/util";
|
|
2
|
+
import type { Anonymous, AtLeast, AtMost, AttributeKind, Attributes, brand, Default, DivisibleBy, LessThan, MoreThan, Nominal, of, Optional } from "../../attributes.ts";
|
|
2
3
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { AtLeast, AtMost, Branded, constrain, Constraints, DivisibleBy, LessThan, MoreThan, Narrowed, normalizePrimitiveConstraintRoot } from "../ast.ts";
|
|
4
4
|
import { epoch } from "./epoch.ts";
|
|
5
5
|
import { integer } from "./integer.ts";
|
|
6
6
|
export declare const number: number.module;
|
|
7
7
|
export declare namespace number {
|
|
8
|
-
type atLeast<rule> =
|
|
9
|
-
type moreThan<rule> =
|
|
10
|
-
type atMost<rule> =
|
|
11
|
-
type lessThan<rule> =
|
|
12
|
-
type divisibleBy<rule> =
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
type
|
|
8
|
+
type atLeast<rule> = of<number, AtLeast<rule>>;
|
|
9
|
+
type moreThan<rule> = of<number, MoreThan<rule>>;
|
|
10
|
+
type atMost<rule> = of<number, AtMost<rule>>;
|
|
11
|
+
type lessThan<rule> = of<number, LessThan<rule>>;
|
|
12
|
+
type divisibleBy<rule> = of<number, DivisibleBy<rule>>;
|
|
13
|
+
type anonymous = of<number, Anonymous>;
|
|
14
|
+
type optional = of<number, Optional>;
|
|
15
|
+
type defaultsTo<rule> = of<number, Default<rule>>;
|
|
16
|
+
type nominal<rule> = of<number, Nominal<rule>>;
|
|
17
|
+
type NaN = nominal<"NaN">;
|
|
18
|
+
type Infinity = nominal<"Infinity">;
|
|
19
|
+
type NegativeInfinity = nominal<"NegativeInfinity">;
|
|
20
|
+
type safe = nominal<"safe">;
|
|
21
|
+
type is<attributes extends Attributes> = of<number, attributes>;
|
|
22
|
+
type AttributableKind = satisfy<AttributeKind, "divisibleBy" | "moreThan" | "atLeast" | "atMost" | "lessThan">;
|
|
23
|
+
type minSchemaToConstraint<schema, rule> = schema extends {
|
|
17
24
|
exclusive: true;
|
|
18
|
-
} ?
|
|
25
|
+
} ? MoreThan<rule> : AtLeast<rule>;
|
|
26
|
+
type maxSchemaToConstraint<schema, rule> = schema extends {
|
|
19
27
|
exclusive: true;
|
|
20
|
-
} ?
|
|
28
|
+
} ? LessThan<rule> : AtMost<rule>;
|
|
29
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
30
|
+
namespace raw {
|
|
31
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "divisibleBy" ? divisibleBy<value> : kind extends "moreThan" ? moreThan<value> : kind extends "atLeast" ? atLeast<value> : kind extends "atMost" ? atMost<value> : kind extends "lessThan" ? lessThan<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
|
|
32
|
+
}
|
|
21
33
|
type module = Module<submodule>;
|
|
22
34
|
type submodule = Submodule<$>;
|
|
23
35
|
type $ = {
|
|
24
|
-
|
|
36
|
+
root: number;
|
|
25
37
|
epoch: epoch;
|
|
26
38
|
integer: integer;
|
|
39
|
+
safe: safe;
|
|
40
|
+
NaN: NaN;
|
|
41
|
+
Infinity: Infinity;
|
|
42
|
+
NegativeInfinity: NegativeInfinity;
|
|
27
43
|
};
|
|
44
|
+
type branded<rule> = brand<number, Nominal<rule>>;
|
|
45
|
+
namespace branded {
|
|
46
|
+
type atLeast<rule> = brand<number, AtLeast<rule>>;
|
|
47
|
+
type moreThan<rule> = brand<number, MoreThan<rule>>;
|
|
48
|
+
type atMost<rule> = brand<number, AtMost<rule>>;
|
|
49
|
+
type lessThan<rule> = brand<number, LessThan<rule>>;
|
|
50
|
+
type divisibleBy<rule> = brand<number, DivisibleBy<rule>>;
|
|
51
|
+
type is<attributes extends Attributes> = brand<number, attributes>;
|
|
52
|
+
type anonymous = brand<number, Anonymous>;
|
|
53
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
54
|
+
namespace raw {
|
|
55
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "divisibleBy" ? divisibleBy<value> : kind extends "moreThan" ? moreThan<value> : kind extends "atLeast" ? atLeast<value> : kind extends "atMost" ? atMost<value> : kind extends "lessThan" ? lessThan<value> : never;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
28
58
|
}
|
|
@@ -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,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type alpha =
|
|
3
|
+
type alpha = of<string, Nominal<"alpha">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const alpha: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type alpha = string.alpha;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type alphanumeric =
|
|
3
|
+
type alphanumeric = of<string, Nominal<"alphanumeric">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const alphanumeric: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type alphanumeric = string.alphanumeric;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
+
export declare const base64: Module<{
|
|
4
|
+
root: unknown;
|
|
5
|
+
url: unknown;
|
|
6
|
+
}>;
|
|
7
|
+
declare namespace string {
|
|
8
|
+
type base64 = of<string, Nominal<"base64">>;
|
|
9
|
+
namespace base64 {
|
|
10
|
+
type url = of<string, Nominal<"base64.url">>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare namespace base64 {
|
|
14
|
+
type module = Module<submodule>;
|
|
15
|
+
type submodule = Submodule<$>;
|
|
16
|
+
type $ = {
|
|
17
|
+
root: string.base64;
|
|
18
|
+
url: string.base64.url;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
|
+
import { regexStringNode } from "./utils.js";
|
|
3
|
+
export const base64 = arkModule({
|
|
4
|
+
root: regexStringNode(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, "base64-encoded"),
|
|
5
|
+
url: regexStringNode(/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==|%3D%3D)?|[A-Za-z0-9_-]{3}(?:=|%3D)?)?$/, "base64url-encoded")
|
|
6
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type capitalized =
|
|
4
|
+
type capitalized = of<string, Nominal<"capitalized">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const capitalize: capitalize.module;
|
|
7
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,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
export declare const isLuhnValid: (creditCardInput: string) => boolean;
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type creditCard =
|
|
4
|
+
type creditCard = of<string, Nominal<"creditCard">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const creditCard: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
7
7
|
export type creditCard = string.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
|
+
import type { Nominal, To, of } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
|
-
import type { Branded, To, constrain } from "../ast.ts";
|
|
4
3
|
type DayDelimiter = "." | "/" | "-";
|
|
5
4
|
type DayPart = DayPatterns[PartKey];
|
|
6
5
|
type PartKey = keyof DayPatterns;
|
|
@@ -22,10 +21,10 @@ export type DateOptions = {
|
|
|
22
21
|
export declare const iso8601Matcher: RegExp;
|
|
23
22
|
export declare const tryParseDatePattern: (data: string, opts?: DateOptions) => Date | string;
|
|
24
23
|
declare namespace string {
|
|
25
|
-
type date =
|
|
24
|
+
type date = of<string, Nominal<"date">>;
|
|
26
25
|
namespace date {
|
|
27
|
-
type epoch =
|
|
28
|
-
type iso =
|
|
26
|
+
type epoch = of<string, Nominal<"date.epoch">>;
|
|
27
|
+
type iso = of<string, Nominal<"date.iso">>;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
export declare const stringDate: stringDate.module;
|
|
@@ -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) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type digits =
|
|
3
|
+
type digits = of<string, Nominal<"digits">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const digits: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type digits = string.digits;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type email =
|
|
3
|
+
type email = of<string, Nominal<"email">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const email: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type email = string.email;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
import type { number } from "../number/number.ts";
|
|
4
4
|
declare namespace string {
|
|
5
|
-
type integer =
|
|
5
|
+
type integer = of<string, Nominal<"integer">>;
|
|
6
6
|
}
|
|
7
7
|
export declare const integer: stringInteger.module;
|
|
8
8
|
export declare namespace stringInteger {
|
|
9
9
|
type module = Module<submodule>;
|
|
10
10
|
type submodule = Submodule<$>;
|
|
11
11
|
type $ = {
|
|
12
|
-
|
|
12
|
+
root: string.integer;
|
|
13
13
|
parse: (In: string.integer) => To<number.divisibleBy<1>>;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { intrinsic,
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { wellFormedIntegerMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
6
|
-
export const integer =
|
|
7
|
-
|
|
8
|
-
parse:
|
|
9
|
-
in:
|
|
5
|
+
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
6
|
+
export const integer = arkModule({
|
|
7
|
+
root,
|
|
8
|
+
parse: rootSchema({
|
|
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"));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type ip =
|
|
4
|
+
type ip = of<string, Nominal<"ip">>;
|
|
5
5
|
namespace ip {
|
|
6
|
-
type v4 =
|
|
7
|
-
type v6 =
|
|
6
|
+
type v4 = of<string, Nominal<"ip.v4">>;
|
|
7
|
+
type v6 = of<string, Nominal<"ip.v6">>;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare const ip: ip.module;
|
|
@@ -12,7 +12,7 @@ export declare namespace ip {
|
|
|
12
12
|
type module = Module<submodule>;
|
|
13
13
|
type submodule = Submodule<$>;
|
|
14
14
|
type $ = {
|
|
15
|
-
|
|
15
|
+
root: string.ip;
|
|
16
16
|
v4: string.ip.v4;
|
|
17
17
|
v6: string.ip.v6;
|
|
18
18
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
2
|
import { regexStringNode } from "./utils.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
4
|
+
// Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
|
|
4
5
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
5
6
|
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
6
7
|
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
@@ -14,10 +15,9 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
14
15
|
`(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
|
|
15
16
|
`(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
|
|
16
17
|
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
17
|
-
")(%[0-9a-zA-Z
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$root: ["v4 | v6", "@", "an IP address"],
|
|
18
|
+
")(%[0-9a-zA-Z.]{1,})?$");
|
|
19
|
+
export const ip = arkModule({
|
|
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
|
});
|