arktype 2.0.0-rc.0 → 2.0.0-rc.1

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 (53) hide show
  1. package/out/generic.d.ts +9 -6
  2. package/out/generic.js +3 -3
  3. package/out/index.d.ts +2 -2
  4. package/out/index.js +1 -0
  5. package/out/keywords/ark.d.ts +13 -7
  6. package/out/keywords/ark.js +11 -5
  7. package/out/keywords/{builtin.d.ts → builtins.d.ts} +9 -5
  8. package/out/keywords/{builtin.js → builtins.js} +1 -1
  9. package/out/keywords/constructors/Array.d.ts +11 -7
  10. package/out/keywords/constructors/Array.js +1 -1
  11. package/out/keywords/constructors/FormData.d.ts +12 -6
  12. package/out/keywords/constructors/FormData.js +15 -2
  13. package/out/keywords/constructors/TypedArray.d.ts +18 -14
  14. package/out/keywords/constructors/constructors.d.ts +21 -31
  15. package/out/keywords/constructors/constructors.js +11 -26
  16. package/out/keywords/number/number.d.ts +5 -3
  17. package/out/keywords/string/capitalize.d.ts +10 -9
  18. package/out/keywords/string/date.d.ts +30 -25
  19. package/out/keywords/string/date.js +1 -1
  20. package/out/keywords/string/integer.d.ts +10 -9
  21. package/out/keywords/string/ip.d.ts +11 -11
  22. package/out/keywords/string/json.d.ts +10 -9
  23. package/out/keywords/string/lower.d.ts +10 -9
  24. package/out/keywords/string/normalize.d.ts +49 -29
  25. package/out/keywords/string/numeric.d.ts +10 -9
  26. package/out/keywords/string/string.d.ts +73 -18
  27. package/out/keywords/string/string.js +2 -2
  28. package/out/keywords/string/trim.d.ts +10 -9
  29. package/out/keywords/string/upper.d.ts +10 -9
  30. package/out/keywords/string/url.d.ts +10 -9
  31. package/out/keywords/string/uuid.d.ts +17 -13
  32. package/out/keywords/ts.d.ts +33 -22
  33. package/out/keywords/ts.js +15 -13
  34. package/out/parser/definition.d.ts +2 -4
  35. package/out/parser/objectLiteral.d.ts +13 -1
  36. package/out/parser/semantic/bounds.d.ts +3 -1
  37. package/out/parser/semantic/default.d.ts +3 -2
  38. package/out/parser/semantic/infer.d.ts +20 -14
  39. package/out/parser/semantic/utils.d.ts +2 -2
  40. package/out/parser/semantic/validate.d.ts +5 -8
  41. package/out/parser/string/shift/operand/enclosed.d.ts +3 -1
  42. package/out/parser/string/shift/operand/unenclosed.d.ts +6 -7
  43. package/out/parser/string/shift/operator/bounds.d.ts +6 -5
  44. package/out/parser/string/shift/operator/operator.js +2 -2
  45. package/out/parser/string/shift/scanner.d.ts +3 -1
  46. package/out/parser/string/shift/scanner.js +2 -2
  47. package/out/parser/string/string.d.ts +3 -2
  48. package/out/scope.d.ts +18 -4
  49. package/out/scope.js +15 -2
  50. package/out/subtypes/base.d.ts +2 -1
  51. package/out/type.d.ts +3 -1
  52. package/out/type.js +11 -6
  53. package/package.json +3 -3
@@ -1,14 +1,15 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
4
  type lowercase = constrain<string, Branded<"lowercase">>;
5
5
  }
6
- export type lower = Submodule<{
7
- $root: (In: string) => To<string.lowercase>;
8
- preformatted: string.lowercase;
9
- }>;
10
- export declare const lower: import("../../module.ts").Module<{
11
- $root: object;
12
- preformatted: object;
13
- }>;
6
+ export declare const lower: lower.module;
7
+ export declare namespace lower {
8
+ type module = Module<submodule>;
9
+ type submodule = Submodule<$>;
10
+ type $ = {
11
+ $root: (In: string) => To<string.lowercase>;
12
+ preformatted: string.lowercase;
13
+ };
14
+ }
14
15
  export {};
@@ -1,4 +1,5 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
+ import type { type } from "../ark.ts";
2
3
  import type { Branded, constrain, To } from "../ast.ts";
3
4
  declare namespace string {
4
5
  type normalized = normalized.NFC;
@@ -11,39 +12,23 @@ declare namespace string {
11
12
  }
12
13
  export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
13
14
  export type NormalizedForm = (typeof normalizedForms)[number];
14
- export type NFC = Submodule<{
15
- $root: (In: string) => To<string.normalized.NFC>;
16
- preformatted: string.normalized.NFC;
17
- }>;
18
- export declare const NFC: import("../../module.ts").Module<{
15
+ export declare const NFC: Module<{
19
16
  $root: object;
20
17
  preformatted: object;
21
18
  }>;
22
- export type NFD = Submodule<{
23
- $root: (In: string) => To<string.normalized.NFD>;
24
- preformatted: string.normalized.NFD;
25
- }>;
26
- export declare const NFD: import("../../module.ts").Module<{
19
+ export declare const NFD: Module<{
27
20
  $root: object;
28
21
  preformatted: object;
29
22
  }>;
30
- export type NFKC = Submodule<{
31
- $root: (In: string) => To<string.normalized.NFKC>;
32
- preformatted: string.normalized.NFKC;
33
- }>;
34
- export declare const NFKC: import("../../module.ts").Module<{
23
+ export declare const NFKC: Module<{
35
24
  $root: object;
36
25
  preformatted: object;
37
26
  }>;
38
- export type NFKD = Submodule<{
39
- $root: (In: string) => To<string.normalized.NFKD>;
40
- preformatted: string.normalized.NFKD;
41
- }>;
42
- export declare const NFKD: import("../../module.ts").Module<{
27
+ export declare const NFKD: Module<{
43
28
  $root: object;
44
29
  preformatted: object;
45
30
  }>;
46
- export declare const normalize: import("../../module.ts").Module<{
31
+ export declare const normalize: Module<{
47
32
  $root: object;
48
33
  NFC: Submodule<{
49
34
  $root: object;
@@ -62,11 +47,46 @@ export declare const normalize: import("../../module.ts").Module<{
62
47
  preformatted: object;
63
48
  }>;
64
49
  }>;
65
- export type normalize = Submodule<{
66
- $root: (In: string) => To<string.normalized.NFC>;
67
- NFC: NFC;
68
- NFD: NFD;
69
- NFKC: NFKC;
70
- NFKD: NFKD;
71
- }>;
50
+ export declare namespace normalize {
51
+ type module = Module<submodule>;
52
+ type submodule = Submodule<$>;
53
+ type $ = {
54
+ $root: (In: string) => To<string.normalized.NFC>;
55
+ NFC: NFC.submodule;
56
+ NFD: NFD.submodule;
57
+ NFKC: NFKC.submodule;
58
+ NFKD: NFKD.submodule;
59
+ };
60
+ type shallowResolutions = {
61
+ [k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
62
+ };
63
+ namespace NFC {
64
+ type submodule = Submodule<$>;
65
+ type $ = {
66
+ $root: (In: string) => To<string.normalized.NFC>;
67
+ preformatted: string.normalized.NFC;
68
+ };
69
+ }
70
+ namespace NFD {
71
+ type submodule = Submodule<$>;
72
+ type $ = {
73
+ $root: (In: string) => To<string.normalized.NFD>;
74
+ preformatted: string.normalized.NFD;
75
+ };
76
+ }
77
+ namespace NFKC {
78
+ type submodule = Submodule<$>;
79
+ type $ = {
80
+ $root: (In: string) => To<string.normalized.NFKC>;
81
+ preformatted: string.normalized.NFKC;
82
+ };
83
+ }
84
+ namespace NFKD {
85
+ type submodule = Submodule<$>;
86
+ type $ = {
87
+ $root: (In: string) => To<string.normalized.NFKD>;
88
+ preformatted: string.normalized.NFKD;
89
+ };
90
+ }
91
+ }
72
92
  export {};
@@ -1,14 +1,15 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
4
  type numeric = constrain<string, Branded<"numeric">>;
5
5
  }
6
- export declare const numeric: import("../../module.ts").Module<{
7
- $root: object;
8
- parse: object;
9
- }>;
10
- export type numeric = Submodule<{
11
- $root: string.numeric;
12
- parse: (In: string.numeric) => To<number>;
13
- }>;
6
+ export declare const numeric: stringNumeric.module;
7
+ export declare namespace stringNumeric {
8
+ type module = Module<submodule>;
9
+ type submodule = Submodule<$>;
10
+ type $ = {
11
+ $root: string.numeric;
12
+ parse: (In: string.numeric) => To<number>;
13
+ };
14
+ }
14
15
  export {};
@@ -1,24 +1,74 @@
1
1
  import { type Constraint, type NodeSchema } from "@ark/schema";
2
2
  import type { Module, Submodule } from "../../module.ts";
3
+ import type { type } from "../ark.ts";
3
4
  import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
4
5
  import { alpha } from "./alpha.ts";
5
6
  import { alphanumeric } from "./alphanumeric.ts";
6
7
  import { capitalize } from "./capitalize.ts";
7
8
  import { creditCard } from "./creditCard.ts";
8
- import { date } from "./date.ts";
9
+ import { stringDate } from "./date.ts";
9
10
  import { digits } from "./digits.ts";
10
11
  import { email } from "./email.ts";
11
- import { integer } from "./integer.ts";
12
+ import { type stringInteger } from "./integer.ts";
12
13
  import { ip } from "./ip.ts";
13
- import { json } from "./json.ts";
14
+ import { type stringJson } from "./json.ts";
14
15
  import { lower } from "./lower.ts";
15
16
  import { normalize } from "./normalize.ts";
16
- import { numeric } from "./numeric.ts";
17
+ import { type stringNumeric } from "./numeric.ts";
17
18
  import { semver } from "./semver.ts";
18
19
  import { trim } from "./trim.ts";
19
20
  import { upper } from "./upper.ts";
21
+ import { url } from "./url.ts";
20
22
  import { uuid } from "./uuid.ts";
21
- export declare const string: Module<string.submodule>;
23
+ export declare const string: Module<{
24
+ trim: Submodule<trim.submodule>;
25
+ normalize: Submodule<{
26
+ $root: object;
27
+ NFC: Submodule<{
28
+ $root: object;
29
+ preformatted: object;
30
+ }>;
31
+ NFD: Submodule<{
32
+ $root: object;
33
+ preformatted: object;
34
+ }>;
35
+ NFKC: Submodule<{
36
+ $root: object;
37
+ preformatted: object;
38
+ }>;
39
+ NFKD: Submodule<{
40
+ $root: object;
41
+ preformatted: object;
42
+ }>;
43
+ }>;
44
+ json: Submodule<stringJson.submodule>;
45
+ $root: object;
46
+ integer: Submodule<stringInteger.submodule>;
47
+ alpha: object;
48
+ alphanumeric: object;
49
+ digits: object;
50
+ numeric: Submodule<stringNumeric.submodule>;
51
+ creditCard: object;
52
+ email: object;
53
+ uuid: Submodule<{
54
+ $root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
55
+ v4: object;
56
+ v6: object;
57
+ v1: object;
58
+ v2: object;
59
+ v3: object;
60
+ v5: object;
61
+ v7: object;
62
+ v8: object;
63
+ }>;
64
+ semver: object;
65
+ ip: Submodule<ip.submodule>;
66
+ date: Submodule<stringDate.submodule>;
67
+ capitalize: Submodule<capitalize.submodule>;
68
+ lower: Submodule<lower.submodule>;
69
+ upper: Submodule<upper.submodule>;
70
+ url: Submodule<url.submodule>;
71
+ }>;
22
72
  export declare namespace string {
23
73
  type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
24
74
  type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
@@ -34,24 +84,29 @@ export declare namespace string {
34
84
  } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
35
85
  exclusive: true;
36
86
  } ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
37
- type submodule = Submodule<{
87
+ type module = Module<string.submodule>;
88
+ type submodule = Submodule<$>;
89
+ type $ = {
38
90
  $root: string;
39
91
  alpha: alpha;
40
92
  alphanumeric: alphanumeric;
41
93
  digits: digits;
42
- numeric: numeric;
43
- integer: integer;
94
+ numeric: stringNumeric.submodule;
95
+ integer: stringInteger.submodule;
44
96
  creditCard: creditCard;
45
97
  email: email;
46
- uuid: uuid;
98
+ uuid: uuid.submodule;
47
99
  semver: semver;
48
- ip: ip;
49
- json: json;
50
- date: date;
51
- trim: trim;
52
- normalize: normalize;
53
- capitalize: capitalize;
54
- lower: lower;
55
- upper: upper;
56
- }>;
100
+ ip: ip.submodule;
101
+ json: stringJson.submodule;
102
+ date: stringDate.submodule;
103
+ trim: trim.submodule;
104
+ normalize: normalize.submodule;
105
+ capitalize: capitalize.submodule;
106
+ lower: lower.submodule;
107
+ upper: upper.submodule;
108
+ };
109
+ type shallowResolutions = {
110
+ [k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
111
+ };
57
112
  }
@@ -4,7 +4,7 @@ import { alpha } from "./alpha.js";
4
4
  import { alphanumeric } from "./alphanumeric.js";
5
5
  import { capitalize } from "./capitalize.js";
6
6
  import { creditCard } from "./creditCard.js";
7
- import { date } from "./date.js";
7
+ import { stringDate } from "./date.js";
8
8
  import { digits } from "./digits.js";
9
9
  import { email } from "./email.js";
10
10
  import { integer } from "./integer.js";
@@ -37,5 +37,5 @@ export const string = submodule({
37
37
  lower,
38
38
  normalize,
39
39
  capitalize,
40
- date
40
+ date: stringDate
41
41
  });
@@ -1,14 +1,15 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
4
  type trimmed = constrain<string, Branded<"trimmed">>;
5
5
  }
6
- export type trim = Submodule<{
7
- $root: (In: string) => To<string.trimmed>;
8
- preformatted: string.trimmed;
9
- }>;
10
- export declare const trim: import("../../module.ts").Module<{
11
- $root: object;
12
- preformatted: object;
13
- }>;
6
+ export declare const trim: trim.module;
7
+ export declare namespace trim {
8
+ type module = Module<submodule>;
9
+ type submodule = Submodule<$>;
10
+ type $ = {
11
+ $root: (In: string) => To<string.trimmed>;
12
+ preformatted: string.trimmed;
13
+ };
14
+ }
14
15
  export {};
@@ -1,14 +1,15 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
4
  type uppercase = constrain<string, Branded<"uppercase">>;
5
5
  }
6
- export type upper = Submodule<{
7
- $root: (In: string) => To<string.uppercase>;
8
- preformatted: string.uppercase;
9
- }>;
10
- export declare const upper: import("../../module.ts").Module<{
11
- $root: object;
12
- preformatted: object;
13
- }>;
6
+ export declare const upper: upper.module;
7
+ export declare namespace upper {
8
+ type module = Module<submodule>;
9
+ type submodule = Submodule<$>;
10
+ type $ = {
11
+ $root: (In: string) => To<string.uppercase>;
12
+ preformatted: string.uppercase;
13
+ };
14
+ }
14
15
  export {};
@@ -1,14 +1,15 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain, To } from "../ast.ts";
3
3
  declare namespace string {
4
4
  type url = constrain<string, Branded<"url">>;
5
5
  }
6
- export declare const url: import("../../module.ts").Module<{
7
- $root: object;
8
- parse: object;
9
- }>;
10
- export type url = Submodule<{
11
- $root: string.url;
12
- parse: (In: string.url) => To<URL>;
13
- }>;
6
+ export declare const url: url.module;
7
+ export declare namespace url {
8
+ type module = Module<submodule>;
9
+ type submodule = Submodule<$>;
10
+ type $ = {
11
+ $root: string.url;
12
+ parse: (In: string.url) => To<URL>;
13
+ };
14
+ }
14
15
  export {};
@@ -1,6 +1,6 @@
1
- import type { Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../../module.ts";
2
2
  import type { Branded, constrain } from "../ast.ts";
3
- export declare const uuid: import("../../module.ts").Module<{
3
+ export declare const uuid: Module<{
4
4
  $root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
5
  v4: object;
6
6
  v6: object;
@@ -24,15 +24,19 @@ declare namespace string {
24
24
  type v8 = constrain<string, Branded<"uuid.v8">>;
25
25
  }
26
26
  }
27
- export type uuid = Submodule<{
28
- $root: string.uuid;
29
- v1: string.uuid.v1;
30
- v2: string.uuid.v2;
31
- v3: string.uuid.v3;
32
- v4: string.uuid.v4;
33
- v5: string.uuid.v5;
34
- v6: string.uuid.v6;
35
- v7: string.uuid.v7;
36
- v8: string.uuid.v8;
37
- }>;
27
+ export declare namespace uuid {
28
+ type module = Module<submodule>;
29
+ type submodule = Submodule<$>;
30
+ type $ = {
31
+ $root: string.uuid;
32
+ v1: string.uuid.v1;
33
+ v2: string.uuid.v2;
34
+ v3: string.uuid.v3;
35
+ v4: string.uuid.v4;
36
+ v5: string.uuid.v5;
37
+ v6: string.uuid.v6;
38
+ v7: string.uuid.v7;
39
+ v8: string.uuid.v8;
40
+ };
41
+ }
38
42
  export {};
@@ -1,5 +1,24 @@
1
1
  import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
2
2
  import type { Module, Submodule } from "../module.ts";
3
+ export declare const arkTsKeywords: arkTsKeywords;
4
+ export type arkTsKeywords = Module<arkTsKeywords.$>;
5
+ export declare namespace arkTsKeywords {
6
+ type submodule = Submodule<$>;
7
+ type $ = {
8
+ bigint: bigint;
9
+ boolean: boolean;
10
+ false: false;
11
+ never: never;
12
+ null: null;
13
+ number: number;
14
+ object: object;
15
+ string: string;
16
+ symbol: symbol;
17
+ true: true;
18
+ unknown: unknown;
19
+ undefined: undefined;
20
+ };
21
+ }
3
22
  declare class RecordHkt extends Hkt<[Key, unknown]> {
4
23
  body: Record<this[0], this[1]>;
5
24
  }
@@ -28,26 +47,18 @@ declare class ExtractHkt extends Hkt<[unknown, unknown]> {
28
47
  body: Extract<this[0], this[1]>;
29
48
  }
30
49
  declare const Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
31
- export declare const arkTs: Module<arkTs>;
32
- export type arkTs = Submodule<{
33
- bigint: bigint;
34
- boolean: boolean;
35
- false: false;
36
- never: never;
37
- null: null;
38
- number: number;
39
- object: object;
40
- string: string;
41
- symbol: symbol;
42
- true: true;
43
- unknown: unknown;
44
- undefined: undefined;
45
- Record: typeof Record.t;
46
- Pick: typeof Pick.t;
47
- Omit: typeof Omit.t;
48
- Exclude: typeof Exclude.t;
49
- Extract: typeof Extract.t;
50
- Partial: typeof Partial.t;
51
- Required: typeof Required.t;
52
- }>;
50
+ export declare const arkTsGenerics: arkTsGenerics.module;
51
+ export declare namespace arkTsGenerics {
52
+ type module = Module<arkTsGenerics.$>;
53
+ type submodule = Submodule<$>;
54
+ type $ = {
55
+ Record: typeof Record.t;
56
+ Pick: typeof Pick.t;
57
+ Omit: typeof Omit.t;
58
+ Exclude: typeof Exclude.t;
59
+ Extract: typeof Extract.t;
60
+ Partial: typeof Partial.t;
61
+ Required: typeof Required.t;
62
+ };
63
+ }
53
64
  export {};
@@ -1,6 +1,20 @@
1
1
  import { genericNode, intrinsic } from "@ark/schema";
2
2
  import { Hkt } from "@ark/util";
3
3
  import { submodule } from "./utils.js";
4
+ export const arkTsKeywords = submodule({
5
+ bigint: intrinsic.bigint,
6
+ boolean: intrinsic.boolean,
7
+ false: intrinsic.false,
8
+ never: intrinsic.never,
9
+ null: intrinsic.null,
10
+ number: intrinsic.number,
11
+ object: intrinsic.object,
12
+ string: intrinsic.string,
13
+ symbol: intrinsic.symbol,
14
+ true: intrinsic.true,
15
+ unknown: intrinsic.unknown,
16
+ undefined: intrinsic.undefined
17
+ });
4
18
  class RecordHkt extends Hkt {
5
19
  }
6
20
  const Record = genericNode(["K", intrinsic.key], "V")(args => ({
@@ -28,19 +42,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
28
42
  class ExtractHkt extends Hkt {
29
43
  }
30
44
  const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
31
- export const arkTs = submodule({
32
- bigint: intrinsic.bigint,
33
- boolean: intrinsic.boolean,
34
- false: intrinsic.false,
35
- never: intrinsic.never,
36
- null: intrinsic.null,
37
- number: intrinsic.number,
38
- object: intrinsic.object,
39
- string: intrinsic.string,
40
- symbol: intrinsic.symbol,
41
- true: intrinsic.true,
42
- unknown: intrinsic.unknown,
43
- undefined: intrinsic.undefined,
45
+ export const arkTsGenerics = submodule({
44
46
  Record,
45
47
  Pick,
46
48
  Omit,
@@ -1,5 +1,5 @@
1
1
  import { type BaseRoot } from "@ark/schema";
2
- import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
2
+ import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
3
3
  import type { type } from "../keywords/ark.ts";
4
4
  import type { string } from "../keywords/string/string.ts";
5
5
  import type { ParseContext } from "../scope.ts";
@@ -10,9 +10,7 @@ import { type TupleExpression, type inferTuple, type validateTuple } from "./tup
10
10
  export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
11
11
  export type inferDefinition<def, $, args> = [
12
12
  def
13
- ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? {} extends t ? [
14
- t
15
- ] extends [anyOrNever] ? t : object : t : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
13
+ ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<t, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
16
14
  export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
17
15
  export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
18
16
  type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
@@ -22,7 +22,19 @@ type _inferObjectLiteral<def extends object, $, args> = {
22
22
  export type validateObjectLiteral<def, $, args> = {
23
23
  [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefaultableValue<def, k, $, args>;
24
24
  };
25
- type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? validateDefaultValueTuple<def[k], k, $, args> : validateDefinition<def[k], $, args>;
25
+ type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? [
26
+ def[k]
27
+ ] extends [anyOrNever] ?
28
+ /** this extra [anyOrNever] check is required to ensure that nested `type` invocations
29
+ * like the following are not prematurely validated by the outer call:
30
+ *
31
+ * ```ts
32
+ * type({
33
+ * "test?": type("string").pipe(x => x === "true")
34
+ * })
35
+ * ```
36
+ */
37
+ def[k] : validateDefaultValueTuple<def[k], k, $, args> : validateDefinition<def[k], $, args>;
26
38
  type DefaultValueTuple<baseDef = unknown, defaultValue = unknown> = readonly [
27
39
  baseDef,
28
40
  "=",
@@ -6,7 +6,9 @@ import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/sh
6
6
  import type { inferAstIn } from "./infer.ts";
7
7
  import type { astToString } from "./utils.ts";
8
8
  import type { validateAst } from "./validate.ts";
9
- export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r, comparator, l, "left", $, args> : l extends [infer leftAst, Comparator, unknown] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
9
+ export type validateRange<l, comparator extends Comparator, r, $, args> = [
10
+ l
11
+ ] extends [LimitLiteral] ? validateBound<r, comparator, l, "left", $, args> : [l] extends [[infer leftAst, Comparator, unknown]] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
10
12
  export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> = inferAstIn<boundedAst, $, args> extends infer bounded ? isNumericallyBoundable<bounded> extends true ? limit extends number ? validateAst<boundedAst, $, args> : ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>> : [bounded] extends [Date] ? validateAst<boundedAst, $, args> : ErrorMessage<writeUnboundableMessage<typeToString<bounded>>> : never;
11
13
  type isNumericallyBoundable<bounded> = [
12
14
  bounded
@@ -1,8 +1,9 @@
1
1
  import type { ErrorMessage } from "@ark/util";
2
+ import type { inferAmbient } from "../../type.ts";
2
3
  import type { UnitLiteral } from "../string/shift/operator/default.ts";
3
- import type { inferAstOut, inferTerminal } from "./infer.ts";
4
+ import type { inferAstOut } from "./infer.ts";
4
5
  import type { astToString } from "./utils.ts";
5
6
  import type { validateAst } from "./validate.ts";
6
- export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferTerminal<unitLiteral, $, args> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
7
+ export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferAmbient<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
7
8
  export declare const writeUnassignableDefaultValueMessage: <key extends string, message extends string>(key: key, message: message) => string;
8
9
  export type writeUnassignableDefaultValueMessage<baseDef extends string, defaultValue extends string> = `Default value ${defaultValue} is not assignable to ${baseDef}`;