arktype 2.0.0-rc.2 → 2.0.0-rc.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/out/attributes.d.ts +274 -0
  2. package/out/attributes.js +2 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +52 -55
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +4 -4
  7. package/out/index.js +2 -2
  8. package/out/keywords/builtins.js +2 -2
  9. package/out/keywords/constructors/Array.d.ts +2 -2
  10. package/out/keywords/constructors/Array.js +7 -7
  11. package/out/keywords/constructors/Date.d.ts +37 -0
  12. package/out/keywords/constructors/FormData.d.ts +2 -2
  13. package/out/keywords/constructors/FormData.js +8 -8
  14. package/out/keywords/constructors/TypedArray.js +2 -2
  15. package/out/keywords/constructors/constructors.d.ts +0 -1
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/keywords.d.ts +64 -0
  18. package/out/keywords/{ark.js → keywords.js} +14 -9
  19. package/out/keywords/number/epoch.d.ts +1 -1
  20. package/out/keywords/number/epoch.js +2 -2
  21. package/out/keywords/number/integer.js +2 -2
  22. package/out/keywords/number/number.d.ts +44 -14
  23. package/out/keywords/number/number.js +17 -5
  24. package/out/keywords/string/alpha.d.ts +2 -2
  25. package/out/keywords/string/alphanumeric.d.ts +2 -2
  26. package/out/keywords/string/base64.d.ts +21 -0
  27. package/out/keywords/string/base64.js +6 -0
  28. package/out/keywords/string/capitalize.d.ts +3 -3
  29. package/out/keywords/string/capitalize.js +4 -4
  30. package/out/keywords/string/creditCard.d.ts +2 -2
  31. package/out/keywords/string/creditCard.js +2 -2
  32. package/out/keywords/string/date.d.ts +7 -11
  33. package/out/keywords/string/date.js +16 -16
  34. package/out/keywords/string/digits.d.ts +2 -2
  35. package/out/keywords/string/email.d.ts +2 -2
  36. package/out/keywords/string/integer.d.ts +3 -3
  37. package/out/keywords/string/integer.js +7 -7
  38. package/out/keywords/string/ip.d.ts +5 -5
  39. package/out/keywords/string/ip.js +5 -5
  40. package/out/keywords/string/json.d.ts +4 -3
  41. package/out/keywords/string/json.js +39 -30
  42. package/out/keywords/string/lower.d.ts +3 -3
  43. package/out/keywords/string/lower.js +4 -4
  44. package/out/keywords/string/normalize.d.ts +27 -31
  45. package/out/keywords/string/normalize.js +14 -14
  46. package/out/keywords/string/numeric.d.ts +3 -3
  47. package/out/keywords/string/numeric.js +7 -7
  48. package/out/keywords/string/semver.d.ts +2 -2
  49. package/out/keywords/string/string.d.ts +74 -51
  50. package/out/keywords/string/string.js +5 -3
  51. package/out/keywords/string/trim.d.ts +3 -3
  52. package/out/keywords/string/trim.js +4 -4
  53. package/out/keywords/string/upper.d.ts +3 -3
  54. package/out/keywords/string/upper.js +4 -4
  55. package/out/keywords/string/url.d.ts +3 -3
  56. package/out/keywords/string/url.js +8 -8
  57. package/out/keywords/string/uuid.d.ts +20 -20
  58. package/out/keywords/string/uuid.js +3 -3
  59. package/out/keywords/ts.d.ts +38 -1
  60. package/out/keywords/ts.js +20 -4
  61. package/out/keywords/utils.d.ts +1 -1
  62. package/out/keywords/utils.js +1 -1
  63. package/out/{subtypes → methods}/array.d.ts +6 -6
  64. package/out/methods/base.d.ts +183 -0
  65. package/out/{subtypes → methods}/date.d.ts +5 -5
  66. package/out/methods/instantiate.d.ts +17 -0
  67. package/out/methods/morph.d.ts +12 -0
  68. package/out/methods/number.d.ts +12 -0
  69. package/out/methods/object.d.ts +106 -0
  70. package/out/methods/string.d.ts +13 -0
  71. package/out/module.d.ts +2 -2
  72. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  73. package/out/parser/ast/default.d.ts +8 -0
  74. package/out/parser/ast/infer.d.ts +39 -0
  75. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  76. package/out/parser/{semantic → ast}/validate.d.ts +10 -10
  77. package/out/parser/ast/validate.js +1 -0
  78. package/out/parser/definition.d.ts +8 -9
  79. package/out/parser/objectLiteral.d.ts +14 -40
  80. package/out/parser/objectLiteral.js +8 -26
  81. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +9 -12
  82. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  83. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  84. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  85. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  86. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +6 -4
  87. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  88. package/out/parser/shift/operand/operand.d.ts +9 -0
  89. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  90. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +14 -7
  91. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  92. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  93. package/out/parser/shift/operator/brand.d.ts +6 -0
  94. package/out/parser/shift/operator/brand.js +5 -0
  95. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  96. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  97. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  98. package/out/parser/shift/operator/operator.d.ts +14 -0
  99. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  100. package/out/parser/shift/scanner.d.ts +47 -0
  101. package/out/parser/shift/scanner.js +42 -0
  102. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  103. package/out/parser/{string/string.js → string.js} +2 -0
  104. package/out/parser/tuple.d.ts +60 -44
  105. package/out/parser/tuple.js +36 -30
  106. package/out/scope.d.ts +38 -39
  107. package/out/scope.js +47 -36
  108. package/out/type.d.ts +45 -21
  109. package/out/type.js +14 -10
  110. package/package.json +3 -3
  111. package/out/intersect.d.ts +0 -28
  112. package/out/keys.d.ts +0 -16
  113. package/out/keywords/ark.d.ts +0 -39
  114. package/out/keywords/ast.d.ts +0 -193
  115. package/out/keywords/ast.js +0 -2
  116. package/out/parser/semantic/default.d.ts +0 -9
  117. package/out/parser/semantic/default.js +0 -1
  118. package/out/parser/semantic/infer.d.ts +0 -39
  119. package/out/parser/semantic/validate.js +0 -1
  120. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  121. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  122. package/out/parser/string/shift/scanner.d.ts +0 -69
  123. package/out/parser/string/shift/scanner.js +0 -100
  124. package/out/subtypes/base.d.ts +0 -85
  125. package/out/subtypes/instantiate.d.ts +0 -16
  126. package/out/subtypes/morph.d.ts +0 -13
  127. package/out/subtypes/number.d.ts +0 -12
  128. package/out/subtypes/object.d.ts +0 -33
  129. package/out/subtypes/string.d.ts +0 -13
  130. package/out/subtypes/validator.d.ts +0 -11
  131. package/out/subtypes/validator.js +0 -1
  132. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  133. /package/out/{subtypes → methods}/array.js +0 -0
  134. /package/out/{subtypes → methods}/base.js +0 -0
  135. /package/out/{subtypes → methods}/date.js +0 -0
  136. /package/out/{subtypes → methods}/instantiate.js +0 -0
  137. /package/out/{subtypes → methods}/morph.js +0 -0
  138. /package/out/{subtypes → methods}/number.js +0 -0
  139. /package/out/{subtypes → methods}/object.js +0 -0
  140. /package/out/{subtypes → methods}/string.js +0 -0
  141. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  142. /package/out/{keys.js → parser/ast/default.js} +0 -0
  143. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  144. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  145. /package/out/parser/{semantic → ast}/infer.js +0 -0
  146. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  147. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  148. /package/out/parser/{semantic → ast}/utils.js +0 -0
  149. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  150. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  151. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  152. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  153. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  154. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  155. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,5 +1,5 @@
1
+ import type { To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { To } from "../ast.ts";
3
3
  export type FormDataValue = string | File;
4
4
  export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
5
5
  export declare const arkFormData: arkFormData.module;
@@ -7,7 +7,7 @@ export declare namespace arkFormData {
7
7
  type module = Module<submodule>;
8
8
  type submodule = Submodule<$>;
9
9
  type $ = {
10
- $root: FormData;
10
+ root: FormData;
11
11
  value: FormDataValue;
12
12
  parse: (In: FormData) => To<ParsedFormData>;
13
13
  parsed: ParsedFormData;
@@ -1,9 +1,9 @@
1
- import { rootNode } from "@ark/schema";
1
+ import { rootSchema } from "@ark/schema";
2
2
  import { registry } from "@ark/util";
3
- import { submodule } from "../utils.js";
4
- const value = rootNode(["string", registry.FileConstructor]);
5
- const parsedFormDataValue = value.or(value.array());
6
- const parsed = rootNode({
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 = submodule({
15
- $root: ["instanceof", FormData],
14
+ export const arkFormData = arkModule({
15
+ root: ["instanceof", FormData],
16
16
  value,
17
17
  parsed,
18
- parse: rootNode({
18
+ parse: rootSchema({
19
19
  in: FormData,
20
20
  morphs: (data) => {
21
21
  const result = {};
@@ -1,5 +1,5 @@
1
- import { submodule } from "../utils.js";
2
- export const TypedArray = submodule({
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 { submodule } from "../utils.js";
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 = submodule({
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 ambient = scope({
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 ark = ambient.export();
21
- export const type = ambient.type;
22
- export const generic = ambient.generic;
23
- export const define = ambient.define;
24
- export const declare = ambient.declare;
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,4 +1,4 @@
1
- import type { AtLeast, AtMost, DivisibleBy } from "../ast.ts";
1
+ import type { AtLeast, AtMost, DivisibleBy } from "../../attributes.ts";
2
2
  import type { number } from "./number.ts";
3
3
  /**
4
4
  * As per the ECMA-262 specification:
@@ -1,11 +1,11 @@
1
- import { rootNode } from "@ark/schema";
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 = rootNode({
8
+ export const epoch = rootSchema({
9
9
  domain: {
10
10
  domain: "number",
11
11
  meta: "a number representing a Unix timestamp"
@@ -1,5 +1,5 @@
1
- import { rootNode } from "@ark/schema";
2
- export const integer = rootNode({
1
+ import { rootSchema } from "@ark/schema";
2
+ export const integer = rootSchema({
3
3
  domain: "number",
4
4
  divisor: 1
5
5
  });
@@ -1,28 +1,58 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
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> = constrain<number, AtLeast<rule>>;
9
- type moreThan<rule> = constrain<number, MoreThan<rule>>;
10
- type atMost<rule> = constrain<number, AtMost<rule>>;
11
- type lessThan<rule> = constrain<number, LessThan<rule>>;
12
- type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
13
- type narrowed = constrain<number, Narrowed>;
14
- type branded<rule> = constrain<number, Branded<rule>>;
15
- type is<constraints extends Constraints> = constrain<number, constraints>;
16
- type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "min" ? schema extends {
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
- } ? moreThan<rule> : atLeast<rule> : kind extends "max" ? schema extends {
25
+ } ? MoreThan<rule> : AtLeast<rule>;
26
+ type maxSchemaToConstraint<schema, rule> = schema extends {
19
27
  exclusive: true;
20
- } ? lessThan<rule> : atMost<rule> : kind extends "divisor" ? divisibleBy<rule> : narrowed : never;
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
- $root: number;
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 { submodule } from "../utils.js";
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 = submodule({
6
- $root: intrinsic.number,
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 { Branded, constrain } from "../ast.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type alpha = constrain<string, Branded<"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 { Branded, constrain } from "../ast.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type alphanumeric = constrain<string, Branded<"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 = constrain<string, Branded<"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
- $root: (In: string) => To<string.capitalized>;
11
+ root: (In: string) => To<string.capitalized>;
12
12
  preformatted: string.capitalized;
13
13
  };
14
14
  }
@@ -1,9 +1,9 @@
1
- import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
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 = submodule({
6
- $root: rootNode({
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 { Branded, constrain } from "../ast.ts";
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 = constrain<string, Branded<"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 { rootNode } from "@ark/schema";
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 = rootNode({
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 = constrain<string, Branded<"date">>;
24
+ type date = of<string, Nominal<"date">>;
26
25
  namespace date {
27
- type epoch = constrain<string, Branded<"date.epoch">>;
28
- type iso = constrain<string, Branded<"date.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
- $root: string.date;
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
- $root: string.date.iso;
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
- $root: string.date.epoch;
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, rootNode } from "@ark/schema";
1
+ import { ArkErrors, intrinsic, rootSchema } from "@ark/schema";
2
2
  import { number } from "../number/number.js";
3
- import { submodule } from "../utils.js";
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 = rootNode({
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 epoch$root = integer.$root.internal
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 = submodule({
67
- $root: epoch$root,
68
- parse: rootNode({
69
- in: epoch$root,
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 iso$root = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
75
- const iso = submodule({
76
- $root: iso$root,
77
- parse: rootNode({
78
- in: iso$root,
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 = submodule({
84
- $root: parsableDate,
85
- parse: rootNode({
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 { Branded, constrain } from "../ast.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type digits = constrain<string, Branded<"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 { Branded, constrain } from "../ast.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type email = constrain<string, Branded<"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 = constrain<string, Branded<"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
- $root: string.integer;
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, rootNode } from "@ark/schema";
1
+ import { intrinsic, rootSchema } from "@ark/schema";
2
2
  import { wellFormedIntegerMatcher } from "@ark/util";
3
- import { submodule } from "../utils.js";
3
+ import { arkModule } from "../utils.js";
4
4
  import { regexStringNode } from "./utils.js";
5
- const $root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
- export const integer = submodule({
7
- $root,
8
- parse: rootNode({
9
- in: $root,
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 = constrain<string, Branded<"ip">>;
4
+ type ip = of<string, Nominal<"ip">>;
5
5
  namespace ip {
6
- type v4 = constrain<string, Branded<"ip.v4">>;
7
- type v6 = constrain<string, Branded<"ip.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
- $root: string.ip;
15
+ root: string.ip;
16
16
  v4: string.ip.v4;
17
17
  v6: string.ip.v6;
18
18
  };