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,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 url = constrain<string, Branded<"url">>;
4
+ type url = of<string, Nominal<"url">>;
5
5
  }
6
6
  export declare const url: url.module;
7
7
  export declare namespace url {
8
8
  type module = Module<submodule>;
9
9
  type submodule = Submodule<$>;
10
10
  type $ = {
11
- $root: string.url;
11
+ root: string.url;
12
12
  parse: (In: string.url) => To<URL>;
13
13
  };
14
14
  }
@@ -1,5 +1,5 @@
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
  const isParsableUrl = (s) => {
4
4
  if (URL.canParse)
5
5
  return URL.canParse(s);
@@ -12,17 +12,17 @@ const isParsableUrl = (s) => {
12
12
  return false;
13
13
  }
14
14
  };
15
- const $root = rootNode({
15
+ const root = rootSchema({
16
16
  domain: "string",
17
17
  predicate: {
18
18
  meta: "a URL string",
19
19
  predicate: isParsableUrl
20
20
  }
21
21
  });
22
- export const url = submodule({
23
- $root,
24
- parse: rootNode({
25
- declaredIn: $root,
22
+ export const url = arkModule({
23
+ root,
24
+ parse: rootSchema({
25
+ declaredIn: root,
26
26
  in: "string",
27
27
  morphs: (s, ctx) => {
28
28
  try {
@@ -32,6 +32,6 @@ export const url = submodule({
32
32
  return ctx.error("a URL string");
33
33
  }
34
34
  },
35
- declaredOut: rootNode(URL)
35
+ declaredOut: rootSchema(URL)
36
36
  })
37
37
  });
@@ -1,34 +1,34 @@
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
  export declare const uuid: Module<{
4
- $root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
- v4: object;
6
- v6: object;
7
- v1: object;
8
- v2: object;
9
- v3: object;
10
- v5: object;
11
- v7: object;
12
- v8: object;
4
+ root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
+ v4: unknown;
6
+ v6: unknown;
7
+ v1: unknown;
8
+ v2: unknown;
9
+ v3: unknown;
10
+ v5: unknown;
11
+ v7: unknown;
12
+ v8: unknown;
13
13
  }>;
14
14
  declare namespace string {
15
- type uuid = constrain<string, Branded<"uuid">>;
15
+ type uuid = of<string, Nominal<"uuid">>;
16
16
  namespace uuid {
17
- type v1 = constrain<string, Branded<"uuid.v1">>;
18
- type v2 = constrain<string, Branded<"uuid.v2">>;
19
- type v3 = constrain<string, Branded<"uuid.v3">>;
20
- type v4 = constrain<string, Branded<"uuid.v4">>;
21
- type v5 = constrain<string, Branded<"uuid.v5">>;
22
- type v6 = constrain<string, Branded<"uuid.v6">>;
23
- type v7 = constrain<string, Branded<"uuid.v7">>;
24
- type v8 = constrain<string, Branded<"uuid.v8">>;
17
+ type v1 = of<string, Nominal<"uuid.v1">>;
18
+ type v2 = of<string, Nominal<"uuid.v2">>;
19
+ type v3 = of<string, Nominal<"uuid.v3">>;
20
+ type v4 = of<string, Nominal<"uuid.v4">>;
21
+ type v5 = of<string, Nominal<"uuid.v5">>;
22
+ type v6 = of<string, Nominal<"uuid.v6">>;
23
+ type v7 = of<string, Nominal<"uuid.v7">>;
24
+ type v8 = of<string, Nominal<"uuid.v8">>;
25
25
  }
26
26
  }
27
27
  export declare namespace uuid {
28
28
  type module = Module<submodule>;
29
29
  type submodule = Submodule<$>;
30
30
  type $ = {
31
- $root: string.uuid;
31
+ root: string.uuid;
32
32
  v1: string.uuid.v1;
33
33
  v2: string.uuid.v2;
34
34
  v3: string.uuid.v3;
@@ -1,10 +1,10 @@
1
- import { submodule } from "../utils.js";
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/isUUID.js
4
- export const uuid = submodule({
4
+ export const uuid = arkModule({
5
5
  // the meta tuple expression ensures the error message does not delegate
6
6
  // to the individual branches, which are too detailed
7
- $root: ["versioned | nil | max", "@", "a UUID"],
7
+ root: ["versioned | nil | max", "@", "a UUID"],
8
8
  "#nil": "'00000000-0000-0000-0000-000000000000'",
9
9
  "#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
10
10
  "#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
@@ -1,4 +1,5 @@
1
- import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
1
+ import { Hkt, type Json, type Key, type omit, type pick, type show } from "@ark/util";
2
+ import type { To } from "../attributes.ts";
2
3
  import type { Module, Submodule } from "../module.ts";
3
4
  export declare const arkTsKeywords: arkTsKeywords;
4
5
  export type arkTsKeywords = Module<arkTsKeywords.$>;
@@ -19,6 +20,42 @@ export declare namespace arkTsKeywords {
19
20
  undefined: undefined;
20
21
  };
21
22
  }
23
+ export declare const unknown: Module<{
24
+ root: unknown;
25
+ any: unknown;
26
+ }>;
27
+ export declare namespace unknown {
28
+ type submodule = Submodule<$>;
29
+ type $ = {
30
+ root: unknown;
31
+ any: any;
32
+ };
33
+ }
34
+ export declare const json: Module<{
35
+ root: unknown;
36
+ stringify: unknown;
37
+ }>;
38
+ export declare namespace json {
39
+ type submodule = Submodule<$>;
40
+ type $ = {
41
+ root: Json;
42
+ stringify: (In: Json) => To<string>;
43
+ };
44
+ }
45
+ export declare const object: Module<{
46
+ root: unknown;
47
+ json: Submodule<{
48
+ root: unknown;
49
+ stringify: unknown;
50
+ }>;
51
+ }>;
52
+ export declare namespace object {
53
+ type submodule = Submodule<$>;
54
+ type $ = {
55
+ root: object;
56
+ json: json.submodule;
57
+ };
58
+ }
22
59
  declare class RecordHkt extends Hkt<[Key, unknown]> {
23
60
  body: Record<this[0], this[1]>;
24
61
  }
@@ -1,7 +1,7 @@
1
- import { genericNode, intrinsic } from "@ark/schema";
1
+ import { genericNode, intrinsic, node } from "@ark/schema";
2
2
  import { Hkt } from "@ark/util";
3
- import { submodule } from "./utils.js";
4
- export const arkTsKeywords = submodule({
3
+ import { arkModule } from "./utils.js";
4
+ export const arkTsKeywords = arkModule({
5
5
  bigint: intrinsic.bigint,
6
6
  boolean: intrinsic.boolean,
7
7
  false: intrinsic.false,
@@ -15,6 +15,22 @@ export const arkTsKeywords = submodule({
15
15
  unknown: intrinsic.unknown,
16
16
  undefined: intrinsic.undefined
17
17
  });
18
+ export const unknown = arkModule({
19
+ root: intrinsic.unknown,
20
+ any: intrinsic.unknown
21
+ });
22
+ export const json = arkModule({
23
+ root: intrinsic.json,
24
+ stringify: node("morph", {
25
+ in: intrinsic.json,
26
+ morphs: (data) => JSON.stringify(data),
27
+ declaredOut: intrinsic.string
28
+ })
29
+ });
30
+ export const object = arkModule({
31
+ root: intrinsic.object,
32
+ json
33
+ });
18
34
  class RecordHkt extends Hkt {
19
35
  }
20
36
  const Record = genericNode(["K", intrinsic.key], "V")(args => ({
@@ -42,7 +58,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
42
58
  class ExtractHkt extends Hkt {
43
59
  }
44
60
  const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
45
- export const arkTsGenerics = submodule({
61
+ export const arkTsGenerics = arkModule({
46
62
  Record,
47
63
  Pick,
48
64
  Omit,
@@ -1 +1 @@
1
- export declare const submodule: import("../scope.ts").ModuleParser;
1
+ export declare const arkModule: import("../scope.ts").ModuleParser;
@@ -1,2 +1,2 @@
1
1
  import { module } from "../scope.js";
2
- export const submodule = module;
2
+ export const arkModule = module;
@@ -1,13 +1,13 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { associateAttributesFromArraySchema } from "../attributes.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  interface Type<
5
5
  /** @ts-ignore cast variance */
6
6
  out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> {
7
- atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", schema>, $>;
8
- atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", schema>, $>;
9
- moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
- lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
- exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
7
+ atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "minLength", schema>, $>;
8
+ atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "maxLength", schema>, $>;
9
+ moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromArraySchema<t, "exactLength", schema>, $>;
12
12
  }
13
13
  export type { Type as ArrayType };
@@ -0,0 +1,183 @@
1
+ import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, Predicate, PredicateCast, StandardSchema, UndeclaredKeyBehavior } from "@ark/schema";
2
+ import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
3
+ import type { associateAttributes, associateAttributesFromSchema, brandAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Nominal, Optional, Out, To } from "../attributes.ts";
4
+ import type { ArkAmbient } from "../config.ts";
5
+ import type { type } from "../keywords/keywords.ts";
6
+ import type { Scope } from "../scope.ts";
7
+ import type { ArrayType } from "./array.ts";
8
+ import type { instantiateType } from "./instantiate.ts";
9
+ /** @ts-ignore cast variance */
10
+ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors, StandardSchema.ConstantProps> {
11
+ [inferred]: t;
12
+ t: t;
13
+ infer: this["inferOut"];
14
+ inferInWithAttributes: distill.withAttributes.In<t>;
15
+ inferOutWithAttributes: distill.withAttributes.Out<t>;
16
+ inferIntrospectableOut: distill.introspectable.Out<t>;
17
+ inferOut: distill.Out<t>;
18
+ inferIn: distill.In<t>;
19
+ inferredOutIsIntrospectable: t extends InferredMorph<any, infer o> ? [
20
+ o
21
+ ] extends [anyOrNever] ? true : o extends To ? true : false : unknown extends t ? boolean : true;
22
+ /** Internal JSON representation of this `Type` */
23
+ json: Json;
24
+ toJSON(): Json;
25
+ meta: ArkAmbient.meta;
26
+ precompilation: string | undefined;
27
+ toJsonSchema(): JsonSchema;
28
+ description: string;
29
+ expression: string;
30
+ internal: BaseRoot;
31
+ $: Scope<$>;
32
+ /**
33
+ * Validate data, throwing `type.errors` instance on failure
34
+ * @returns a valid value
35
+ * @example const validData = T.assert(rawData)
36
+ */
37
+ assert(data: unknown): this["infer"];
38
+ /**
39
+ * Check if data matches the input shape.
40
+ * Doesn't process any morphs, but does check narrows.
41
+ * @example type({ foo: "number" }).allows({ foo: "bar" }) // false
42
+ */
43
+ allows(data: unknown): data is this["inferIn"];
44
+ traverse(data: unknown): this["infer"] | ArkErrors;
45
+ configure(meta: MetaSchema): this;
46
+ describe(description: string): this;
47
+ /**
48
+ * Create a copy of this `Type` with updated unknown key behavior
49
+ * - `ignore`: ignore unknown properties (default)
50
+ * - 'reject': disallow objects with unknown properties
51
+ * - 'delete': clone the object and keep only known properties
52
+ */
53
+ onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
54
+ /**
55
+ * Create a copy of this `Type` with updated unknown key behavior\
56
+ * The behavior applies to the whole object tree, not just the immediate properties.
57
+ * - `ignore`: ignore unknown properties (default)
58
+ * - 'reject': disallow objects with unknown properties
59
+ * - 'delete': clone the object and keep only known properties
60
+ */
61
+ onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
62
+ /**
63
+ * Identical to `assert`, but with a typed input as a convenience for providing a typed value.
64
+ * @example const ConfigT = type({ foo: "string" }); export const config = ConfigT.from({ foo: "bar" })
65
+ */
66
+ from(literal: this["inferIn"]): this["infer"];
67
+ /**
68
+ * Cast the way this `Type` is inferred (has no effect at runtime).
69
+ * const branded = type(/^a/).as<`a${string}`>() // Type<`a${string}`>
70
+ */
71
+ as<castTo = unset>(...args: validateChainedAsArgs<castTo>): instantiateType<castTo, $>;
72
+ brand<const name extends string, r = brandAttributes<t, Nominal<name>>>(name: name): instantiateType<r, $>;
73
+ brandAttributes(): instantiateType<distill.brand<t>, $>;
74
+ unbrandAttributes(): instantiateType<distill.unbrand<t>, $>;
75
+ /**
76
+ * A `Type` representing the deeply-extracted input of the `Type` (before morphs are applied).
77
+ * @example const inputT = T.in
78
+ */
79
+ get in(): instantiateType<this["inferInWithAttributes"], $>;
80
+ /**
81
+ * A `Type` representing the deeply-extracted output of the `Type` (after morphs are applied).\
82
+ * **IMPORTANT**: If your type includes morphs, their output will likely be unknown
83
+ * unless they were defined with an explicit output validator via `.to(outputType)`, `.pipe(morph, outputType)`, etc.
84
+ * @example const outputT = T.out
85
+ */
86
+ get out(): instantiateType<this["inferIntrospectableOut"], $>;
87
+ /**
88
+ * Intersect another `Type` definition, returning an introspectable `Disjoint` if the result is unsatisfiable.
89
+ * @example const intersection = type({ foo: "number" }).intersect({ bar: "string" }) // Type<{ foo: number; bar: string }>
90
+ * @example const intersection = type({ foo: "number" }).intersect({ foo: "string" }) // Disjoint
91
+ */
92
+ intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
93
+ /**
94
+ * Intersect another `Type` definition, throwing an error if the result is unsatisfiable.
95
+ * @example const intersection = type({ foo: "number" }).intersect({ bar: "string" }) // Type<{ foo: number; bar: string }>
96
+ */
97
+ and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
98
+ /**
99
+ * Union another `Type` definition.\
100
+ * If the types contain morphs, input shapes should be distinct. Otherwise an error will be thrown.
101
+ * @example const union = type({ foo: "number" }).or({ foo: "string" }) // Type<{ foo: number } | { foo: string }>
102
+ * @example const union = type("string.numeric.parse").or("number") // Type<((In: string) => Out<number>) | number>
103
+ */
104
+ or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
105
+ /**
106
+ * Add a custom predicate to this `Type`.
107
+ * @example const nan = type('number').narrow(n => Number.isNaN(n)) // Type<number>
108
+ * @example const foo = type("string").narrow((s): s is `foo${string}` => s.startsWith('foo') || ctx.mustBe('string starting with "foo"')) // Type<"foo${string}">
109
+ * @example const unique = type('string[]').narrow((a, ctx) => new Set(a).size === a.length || ctx.mustBe('array with unique elements'))
110
+ */
111
+ narrow<narrowed extends this["infer"] = never, r = [narrowed] extends [never] ? t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<associateAttributesFromSchema<o[1], "predicate", Predicate>> : (In: i) => Out<associateAttributesFromSchema<o[1], "predicate", Predicate>> : associateAttributesFromSchema<t, "predicate", Predicate> : t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<narrowed> : (In: i) => Out<narrowed> : narrowed>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<r, $>;
112
+ satisfying<narrowed extends this["inferIn"] = never, r = [narrowed] extends [never] ? associateAttributesFromSchema<t, "predicate", Predicate> : t extends InferredMorph<any, infer o> ? (In: narrowed) => o : narrowed>(predicate: Predicate<this["inferIn"]> | PredicateCast<this["inferIn"], narrowed>): instantiateType<r, $>;
113
+ /**
114
+ * Create a `Type` for array with elements of this `Type`
115
+ * @example const T = type(/^foo/); const array = T.array() // Type<string[]>
116
+ */
117
+ array(): ArrayType<t[], $>;
118
+ /**
119
+ * Morph this `Type` through a chain of morphs.
120
+ * @example const dedupe = type('string[]').pipe(a => Array.from(new Set(a)))
121
+ * @example type({codes: 'string.numeric[]'}).pipe(obj => obj.codes).to('string.numeric.parse[]')
122
+ */
123
+ pipe: ChainedPipes<t, $>;
124
+ equals<const def>(def: type.validate<def, $>): boolean;
125
+ ifEquals<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<r, $> | undefined;
126
+ extends<const def>(other: type.validate<def, $>): boolean;
127
+ ifExtends<const def, r = type.infer<def, $>>(other: type.validate<def, $>): instantiateType<r, $> | undefined;
128
+ overlaps<const def>(r: type.validate<def, $>): boolean;
129
+ extract<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Extract<t, r>, $>;
130
+ exclude<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Exclude<t, r>, $>;
131
+ distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
132
+ optional<r = associateAttributes<t, Optional>>(): instantiateType<r, $>;
133
+ /**
134
+ * Add a default value for this `Type` when it is used as a property.\
135
+ * Default value should be a valid input value for this `Type, or a function that returns a valid input value.\
136
+ * If the type has a morph, it will be applied to the default value.
137
+ * @example const withDefault = type({ foo: type("string").default("bar") }); withDefault({}) // { foo: "bar" }
138
+ * @example const withFactory = type({ foo: type("number[]").default(() => [1])) }); withFactory({baz: 'a'}) // { foo: [1], baz: 'a' }
139
+ * @example const withMorph = type({ foo: type("string.numeric.parse").default("123") }); withMorph({}) // { foo: 123 }
140
+ */
141
+ default<const value extends this["inferIn"], r = associateAttributes<t, Default<value>>>(value: DefaultFor<value>): instantiateType<r, $>;
142
+ "~validate": StandardSchema.Validator<this["inferOut"]>;
143
+ "~types": StandardSchema.Types<this["inferIn"], this["inferOut"]>;
144
+ /** @deprecated */
145
+ apply: Function["apply"];
146
+ /** @deprecated */
147
+ bind: Function["bind"];
148
+ /** @deprecated */
149
+ call: Function["call"];
150
+ /** @deprecated */
151
+ caller: Function;
152
+ /** @deprecated */
153
+ length: number;
154
+ /** @deprecated */
155
+ name: string;
156
+ /** @deprecated */
157
+ prototype: Function["prototype"];
158
+ /** @deprecated */
159
+ arguments: Function["arguments"];
160
+ /** @deprecated */
161
+ Symbol: never;
162
+ }
163
+ interface ChainedPipeSignature<t, $> {
164
+ <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r> extends infer result ? result : never;
165
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r> extends infer result ? result : never;
166
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r> extends infer result ? result : never;
167
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r> extends infer result ? result : never;
168
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r> extends infer result ? result : never;
169
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r> extends infer result ? result : never;
170
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r> extends infer result ? result : never;
171
+ }
172
+ export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
173
+ try: ChainedPipeSignature<t, $>;
174
+ }
175
+ type validateChainedAsArgs<t> = [
176
+ t
177
+ ] extends [unset] ? [
178
+ t
179
+ ] extends [anyOrNever] ? [
180
+ ] : [
181
+ ErrorMessage<"as requires an explicit type parameter like myType.as<t>()">
182
+ ] : [];
183
+ export type { Type as BaseType };
@@ -1,11 +1,11 @@
1
1
  import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
2
- import type { applyConstraint } from "../keywords/ast.ts";
2
+ import type { associateAttributesFromDateSchema } from "../attributes.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
6
- atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "after", schema>, $>;
7
- atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "before", schema>, $>;
8
- laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "after", exclusivizeRangeSchema<schema>>, $>;
9
- earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraint<t, "before", exclusivizeRangeSchema<schema>>, $>;
6
+ atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "after", schema>, $>;
7
+ atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "before", schema>, $>;
8
+ laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "after", exclusivizeRangeSchema<schema>>, $>;
9
+ earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "before", exclusivizeRangeSchema<schema>>, $>;
10
10
  }
11
11
  export type { Type as DateType };
@@ -0,0 +1,17 @@
1
+ import type { anyOrNever, array } from "@ark/util";
2
+ import type { InferredMorph } from "../attributes.ts";
3
+ import type { ArrayType } from "./array.ts";
4
+ import type { BaseType } from "./base.ts";
5
+ import type { DateType } from "./date.ts";
6
+ import type { MorphType } from "./morph.ts";
7
+ import type { NumberType } from "./number.ts";
8
+ import type { ObjectType } from "./object.ts";
9
+ import type { StringType } from "./string.ts";
10
+ export type instantiateType<t, $> = NoInfer<_instantiateType<t, $>> extends infer r ? r : never;
11
+ export type _instantiateType<t, $> = [
12
+ Extract<t, InferredMorph>
13
+ ] extends [anyOrNever] ? [
14
+ t
15
+ ] extends [anyOrNever] ? BaseType<t, $> : [t] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
16
+ t
17
+ ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : BaseType<t, $> : MorphType<t, $>;
@@ -0,0 +1,12 @@
1
+ import type { inferPipe } from "../attributes.ts";
2
+ import type { type } from "../keywords/keywords.ts";
3
+ import type { BaseType } from "./base.ts";
4
+ /** @ts-ignore cast variance */
5
+ interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
6
+ /**
7
+ * Append extra validation shape on the pipe output
8
+ * @example type({codes: 'string.numeric[]'}).pipe(obj => obj.codes).to('string.numeric.parse[]')
9
+ */
10
+ to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
11
+ }
12
+ export type { Type as MorphType };
@@ -0,0 +1,12 @@
1
+ import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
+ import type { associateAttributesFromNumberSchema } from "../attributes.ts";
3
+ import type { BaseType } from "./base.ts";
4
+ /** @ts-ignore cast variance */
5
+ interface Type<out t extends number = number, $ = {}> extends BaseType<t, $> {
6
+ divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "divisor", schema>, $>;
7
+ atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "min", schema>, $>;
8
+ atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "max", schema>, $>;
9
+ moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "min", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "max", exclusivizeRangeSchema<schema>>, $>;
11
+ }
12
+ export type { Type as NumberType };
@@ -0,0 +1,106 @@
1
+ import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
2
+ import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
3
+ import type { associateAttributes, Attributes, Default, of, Optional } from "../attributes.ts";
4
+ import type { type } from "../keywords/keywords.ts";
5
+ import type { ArrayType } from "./array.ts";
6
+ import type { BaseType } from "./base.ts";
7
+ import type { instantiateType } from "./instantiate.ts";
8
+ /** @ts-ignore cast variance */
9
+ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
10
+ readonly(): t extends array ? ArrayType<{
11
+ readonly [i in keyof t]: t[i];
12
+ }, $> : Type<{
13
+ readonly [k in keyof t]: t[k];
14
+ }, $>;
15
+ keyof(): instantiateType<arkKeyOf<t>, $>;
16
+ /**
17
+ * Get the `Type` of a property of this `Type<object>`.
18
+ * @example type({ foo: "string" }).get("foo") // Type<string>
19
+ */
20
+ get<const k1 extends arkIndexableOf<t>, r = arkGet<t, k1>>(k1: k1 | type.cast<k1>): instantiateType<r, $>;
21
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): instantiateType<arkGet<arkGet<t, k1>, k2>, $> extends infer r ? r : never;
22
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = arkGet<arkGet<arkGet<t, k1>, k2>, k3>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<r, $>;
23
+ /**
24
+ * Create a copy of this `Type` with only the specified properties.
25
+ * @example type({ foo: "string", bar: "number" }).pick("foo") // Type<{ foo: string }>
26
+ */
27
+ pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
28
+ [k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
29
+ }, $>;
30
+ /**
31
+ * Create a copy of this `Type` with all properties except the specified ones.
32
+ * @example type({ foo: "string", bar: "number" }).omit("foo") // Type<{ bar: number }>
33
+ */
34
+ omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
35
+ [k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
36
+ }, $>;
37
+ /**
38
+ * Merge another `Type` definition, overriding properties of this `Type` with the duplicate keys.
39
+ * @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1, b: 3, c: 4 }>
40
+ */
41
+ merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
42
+ /**
43
+ * Create a copy of this `Type` with all properties required.
44
+ * @example const T = type({ "foo?"": "string" }).required() // Type<{ foo: string }>
45
+ */
46
+ required(): Type<{
47
+ [k in keyof t]-?: t[k];
48
+ }, $>;
49
+ /**
50
+ * Create a copy of this `Type` with all properties optional.
51
+ * @example: const T = type({ foo: "string" }).optional() // Type<{ foo?: string }>
52
+ */
53
+ partial(): Type<{
54
+ [k in keyof t]?: t[k];
55
+ }, $>;
56
+ map<transformed extends listable<MappedTypeProp>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
57
+ /**
58
+ * List of property info of this `Type<object>`.
59
+ * @example type({ foo: "string = "" }).props // [{ kind: "required", key: "foo", value: Type<string>, default: "" }]
60
+ */
61
+ props: array<typePropOf<t, $>>;
62
+ }
63
+ type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
64
+ type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default> extends (infer attributes extends Attributes) ? attributes : never>, defaultValue, $> : attributes extends Optional ? BaseTypeProp<"optional", k & Key, keyof attributes extends keyof Optional ? base : of<base, Omit<attributes, keyof Default> extends (infer attributes extends Attributes) ? attributes : never>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
65
+ export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
66
+ /** @ts-ignore cast variance */
67
+ out v = unknown, $ = {}> {
68
+ kind: kind;
69
+ key: k;
70
+ value: instantiateType<v, $>;
71
+ meta: ArkEnv.meta;
72
+ toJSON: () => Json;
73
+ }
74
+ export interface DefaultedTypeProp<k extends Key = Key, v = unknown, defaultValue = v, $ = {}> extends BaseTypeProp<"optional", k, v, $> {
75
+ default: defaultValue;
76
+ }
77
+ type MappedTypeProp<k extends Key = Key, v = unknown> = BaseMappedTypeProp<k, v> | OptionalMappedTypeProp<k, v>;
78
+ type BaseMappedTypeProp<k extends Key, v> = merge<BaseMappedPropInner, {
79
+ key: k;
80
+ value: type.cast<v>;
81
+ }>;
82
+ type OptionalMappedTypeProp<k extends Key, v> = merge<OptionalMappedPropInner, {
83
+ key: k;
84
+ value: type.cast<v>;
85
+ default?: v;
86
+ }>;
87
+ type constructMapped<t, transformed extends listable<MappedTypeProp>> = show<intersectUnion<fromTypeProps<t, transformed extends array ? transformed : [transformed]>>>;
88
+ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
89
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
90
+ kind: "required";
91
+ }>["key"]]: prop["value"][inferred];
92
+ } & {
93
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
94
+ kind: "optional";
95
+ default?: never;
96
+ }>["key"]]?: prop["value"][inferred];
97
+ } & {
98
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
99
+ kind: "optional";
100
+ default: unknown;
101
+ }>["key"]]: associateAttributes<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
102
+ }>;
103
+ type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
104
+ kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
105
+ };
106
+ export type { Type as ObjectType };
@@ -0,0 +1,13 @@
1
+ import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
+ import type { associateAttributesFromStringSchema } from "../attributes.ts";
3
+ import type { BaseType } from "./base.ts";
4
+ /** @ts-ignore cast variance */
5
+ interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> {
6
+ matching<const schema extends Pattern.Schema>(schema: schema): Type<associateAttributesFromStringSchema<t, "pattern", schema>, $>;
7
+ atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "minLength", schema>, $>;
8
+ atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "maxLength", schema>, $>;
9
+ moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
+ lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromStringSchema<t, "exactLength", schema>, $>;
12
+ }
13
+ export type { Type as StringType };
package/out/module.d.ts CHANGED
@@ -12,8 +12,8 @@ export interface BoundModule<exports extends {}, $> extends RootModule<bindExpor
12
12
  export type bindExportsToScope<exports, $> = {
13
13
  [k in keyof exports]: instantiateExport<exports[k], $>;
14
14
  } & unknown;
15
- export type Submodule<exports extends {}> = RootModule<exports & ("$root" extends keyof exports ? {
16
- [inferred]: exports["$root"];
15
+ export type Submodule<exports extends {}> = RootModule<exports & ("root" extends keyof exports ? {
16
+ [inferred]: exports["root"];
17
17
  } : {})>;
18
18
  export type instantiateExport<t, $> = [
19
19
  t