@sinclair/typebox 0.32.0-dev-20 → 0.32.0-dev-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 (208) hide show
  1. package/build/import/compiler/compiler.mjs +62 -62
  2. package/build/import/errors/errors.mjs +62 -62
  3. package/build/import/index.d.mts +6 -6
  4. package/build/import/index.mjs +1 -1
  5. package/build/import/type/awaited/awaited.d.mts +4 -6
  6. package/build/import/type/awaited/awaited.mjs +3 -3
  7. package/build/import/type/composite/composite.d.mts +8 -8
  8. package/build/import/type/const/const.d.mts +4 -7
  9. package/build/import/type/constructor/constructor.d.mts +4 -4
  10. package/build/import/type/deref/deref.d.mts +2 -2
  11. package/build/import/type/deref/deref.mjs +26 -36
  12. package/build/import/type/exclude/exclude-from-mapped-result.d.mts +4 -6
  13. package/build/import/type/exclude/exclude.d.mts +7 -8
  14. package/build/import/type/extends/extends-from-mapped-key.d.mts +5 -8
  15. package/build/import/type/extends/extends-from-mapped-key.mjs +3 -3
  16. package/build/import/type/extends/extends-from-mapped-result.d.mts +4 -6
  17. package/build/import/type/extends/extends.d.mts +2 -3
  18. package/build/import/type/extract/extract-from-mapped-result.d.mts +4 -6
  19. package/build/import/type/extract/extract.d.mts +8 -8
  20. package/build/import/type/function/function.d.mts +1 -1
  21. package/build/import/type/helpers/helpers.d.mts +1 -1
  22. package/build/import/type/index.d.mts +0 -1
  23. package/build/import/type/index.mjs +0 -1
  24. package/build/import/type/indexed/indexed-from-mapped-key.d.mts +5 -8
  25. package/build/import/type/indexed/indexed-from-mapped-key.mjs +3 -6
  26. package/build/import/type/indexed/indexed-property-keys.d.mts +5 -8
  27. package/build/import/type/indexed/indexed-property-keys.mjs +6 -11
  28. package/build/import/type/indexed/indexed.d.mts +13 -23
  29. package/build/import/type/indexed/indexed.mjs +13 -13
  30. package/build/import/type/intersect/intersect-create.mjs +0 -1
  31. package/build/import/type/intersect/intersect-evaluated.d.mts +7 -11
  32. package/build/import/type/intersect/intersect-evaluated.mjs +12 -7
  33. package/build/import/type/intersect/intersect-type.d.mts +2 -2
  34. package/build/import/type/intersect/intersect.mjs +1 -2
  35. package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +7 -9
  36. package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +3 -3
  37. package/build/import/type/intrinsic/intrinsic.d.mts +6 -8
  38. package/build/import/type/intrinsic/intrinsic.mjs +8 -6
  39. package/build/import/type/keyof/keyof-from-mapped-result.d.mts +4 -6
  40. package/build/import/type/keyof/keyof-property-keys.d.mts +9 -13
  41. package/build/import/type/keyof/keyof-property-keys.mjs +12 -9
  42. package/build/import/type/keyof/keyof.d.mts +7 -8
  43. package/build/import/type/keyof/keyof.mjs +8 -6
  44. package/build/import/type/mapped/mapped.d.mts +9 -13
  45. package/build/import/type/mapped/mapped.mjs +9 -9
  46. package/build/import/type/omit/omit-from-mapped-key.d.mts +5 -8
  47. package/build/import/type/omit/omit-from-mapped-key.mjs +3 -3
  48. package/build/import/type/omit/omit.d.mts +6 -9
  49. package/build/import/type/omit/omit.mjs +0 -1
  50. package/build/import/type/operators/operators.d.mts +16 -16
  51. package/build/import/type/operators/operators.mjs +21 -25
  52. package/build/import/type/optional/optional-from-mapped-result.d.mts +4 -6
  53. package/build/import/type/optional/optional.d.mts +3 -7
  54. package/build/import/type/partial/partial-from-mapped-result.d.mts +4 -6
  55. package/build/import/type/partial/partial.d.mts +4 -7
  56. package/build/import/type/partial/partial.mjs +6 -7
  57. package/build/import/type/pick/pick-from-mapped-key.d.mts +5 -8
  58. package/build/import/type/pick/pick-from-mapped-key.mjs +3 -3
  59. package/build/import/type/pick/pick.d.mts +4 -4
  60. package/build/import/type/readonly/readonly-from-mapped-result.d.mts +4 -6
  61. package/build/import/type/readonly/readonly.d.mts +3 -7
  62. package/build/import/type/record/record.d.mts +14 -20
  63. package/build/import/type/record/record.mjs +2 -4
  64. package/build/import/type/ref/ref.mjs +3 -0
  65. package/build/import/type/required/required-from-mapped-result.d.mts +4 -6
  66. package/build/import/type/required/required.d.mts +5 -9
  67. package/build/import/type/required/required.mjs +6 -7
  68. package/build/import/type/rest/rest.d.mts +3 -3
  69. package/build/import/type/schema/schema.d.mts +1 -1
  70. package/build/import/type/static/static.d.mts +1 -1
  71. package/build/import/type/symbol/symbol.d.mts +1 -1
  72. package/build/import/type/template-literal/finite.d.mts +7 -5
  73. package/build/import/type/template-literal/finite.mjs +14 -5
  74. package/build/import/type/template-literal/generate.d.mts +14 -9
  75. package/build/import/type/template-literal/generate.mjs +19 -9
  76. package/build/import/type/template-literal/index.d.mts +1 -1
  77. package/build/import/type/template-literal/index.mjs +1 -1
  78. package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
  79. package/build/import/type/template-literal/syntax.d.mts +3 -3
  80. package/build/import/type/template-literal/syntax.mjs +2 -3
  81. package/build/import/type/template-literal/template-literal.d.mts +2 -2
  82. package/build/import/type/template-literal/template-literal.mjs +1 -1
  83. package/build/import/type/template-literal/union.d.mts +2 -2
  84. package/build/import/type/template-literal/union.mjs +5 -10
  85. package/build/import/type/transform/transform.mjs +0 -1
  86. package/build/import/type/tuple/tuple.d.mts +1 -2
  87. package/build/import/type/type/json.d.mts +2 -2
  88. package/build/import/type/union/union-evaluated.d.mts +6 -10
  89. package/build/import/type/union/union-evaluated.mjs +7 -2
  90. package/build/import/value/cast/cast.mjs +20 -20
  91. package/build/import/value/check/check.mjs +62 -62
  92. package/build/import/value/clean/clean.mjs +16 -16
  93. package/build/import/value/convert/convert.mjs +36 -36
  94. package/build/import/value/create/create.mjs +66 -67
  95. package/build/import/value/default/default.mjs +16 -16
  96. package/build/import/value/transform/decode.mjs +18 -18
  97. package/build/import/value/transform/encode.mjs +18 -18
  98. package/build/import/value/transform/has.mjs +28 -28
  99. package/build/require/compiler/compiler.js +62 -62
  100. package/build/require/errors/errors.js +62 -62
  101. package/build/require/index.d.ts +6 -6
  102. package/build/require/index.js +4 -2
  103. package/build/require/type/awaited/awaited.d.ts +4 -6
  104. package/build/require/type/awaited/awaited.js +3 -3
  105. package/build/require/type/composite/composite.d.ts +8 -8
  106. package/build/require/type/const/const.d.ts +4 -7
  107. package/build/require/type/constructor/constructor.d.ts +4 -4
  108. package/build/require/type/deref/deref.d.ts +2 -2
  109. package/build/require/type/deref/deref.js +25 -35
  110. package/build/require/type/exclude/exclude-from-mapped-result.d.ts +4 -6
  111. package/build/require/type/exclude/exclude.d.ts +7 -8
  112. package/build/require/type/extends/extends-from-mapped-key.d.ts +5 -8
  113. package/build/require/type/extends/extends-from-mapped-key.js +3 -3
  114. package/build/require/type/extends/extends-from-mapped-result.d.ts +4 -6
  115. package/build/require/type/extends/extends.d.ts +2 -3
  116. package/build/require/type/extract/extract-from-mapped-result.d.ts +4 -6
  117. package/build/require/type/extract/extract.d.ts +8 -8
  118. package/build/require/type/function/function.d.ts +1 -1
  119. package/build/require/type/helpers/helpers.d.ts +1 -1
  120. package/build/require/type/index.d.ts +0 -1
  121. package/build/require/type/index.js +0 -1
  122. package/build/require/type/indexed/indexed-from-mapped-key.d.ts +5 -8
  123. package/build/require/type/indexed/indexed-from-mapped-key.js +3 -6
  124. package/build/require/type/indexed/indexed-property-keys.d.ts +5 -8
  125. package/build/require/type/indexed/indexed-property-keys.js +4 -9
  126. package/build/require/type/indexed/indexed.d.ts +13 -23
  127. package/build/require/type/indexed/indexed.js +13 -13
  128. package/build/require/type/intersect/intersect-create.js +0 -1
  129. package/build/require/type/intersect/intersect-evaluated.d.ts +7 -11
  130. package/build/require/type/intersect/intersect-evaluated.js +9 -4
  131. package/build/require/type/intersect/intersect-type.d.ts +2 -2
  132. package/build/require/type/intersect/intersect.js +0 -1
  133. package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +7 -9
  134. package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +3 -3
  135. package/build/require/type/intrinsic/intrinsic.d.ts +6 -8
  136. package/build/require/type/intrinsic/intrinsic.js +7 -5
  137. package/build/require/type/keyof/keyof-from-mapped-result.d.ts +4 -6
  138. package/build/require/type/keyof/keyof-property-keys.d.ts +9 -13
  139. package/build/require/type/keyof/keyof-property-keys.js +12 -9
  140. package/build/require/type/keyof/keyof.d.ts +7 -8
  141. package/build/require/type/keyof/keyof.js +8 -6
  142. package/build/require/type/mapped/mapped.d.ts +9 -13
  143. package/build/require/type/mapped/mapped.js +9 -9
  144. package/build/require/type/omit/omit-from-mapped-key.d.ts +5 -8
  145. package/build/require/type/omit/omit-from-mapped-key.js +3 -3
  146. package/build/require/type/omit/omit.d.ts +6 -9
  147. package/build/require/type/omit/omit.js +0 -1
  148. package/build/require/type/operators/operators.d.ts +16 -16
  149. package/build/require/type/operators/operators.js +21 -25
  150. package/build/require/type/optional/optional-from-mapped-result.d.ts +4 -6
  151. package/build/require/type/optional/optional.d.ts +3 -7
  152. package/build/require/type/partial/partial-from-mapped-result.d.ts +4 -6
  153. package/build/require/type/partial/partial.d.ts +4 -7
  154. package/build/require/type/partial/partial.js +6 -7
  155. package/build/require/type/pick/pick-from-mapped-key.d.ts +5 -8
  156. package/build/require/type/pick/pick-from-mapped-key.js +3 -3
  157. package/build/require/type/pick/pick.d.ts +4 -4
  158. package/build/require/type/readonly/readonly-from-mapped-result.d.ts +4 -6
  159. package/build/require/type/readonly/readonly.d.ts +3 -7
  160. package/build/require/type/record/record.d.ts +14 -20
  161. package/build/require/type/record/record.js +1 -3
  162. package/build/require/type/ref/ref.js +3 -0
  163. package/build/require/type/required/required-from-mapped-result.d.ts +4 -6
  164. package/build/require/type/required/required.d.ts +5 -9
  165. package/build/require/type/required/required.js +6 -7
  166. package/build/require/type/rest/rest.d.ts +3 -3
  167. package/build/require/type/schema/schema.d.ts +1 -1
  168. package/build/require/type/static/static.d.ts +1 -1
  169. package/build/require/type/symbol/symbol.d.ts +1 -1
  170. package/build/require/type/template-literal/finite.d.ts +7 -5
  171. package/build/require/type/template-literal/finite.js +16 -6
  172. package/build/require/type/template-literal/generate.d.ts +14 -9
  173. package/build/require/type/template-literal/generate.js +22 -11
  174. package/build/require/type/template-literal/index.d.ts +1 -1
  175. package/build/require/type/template-literal/index.js +1 -1
  176. package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
  177. package/build/require/type/template-literal/syntax.d.ts +3 -3
  178. package/build/require/type/template-literal/syntax.js +1 -2
  179. package/build/require/type/template-literal/template-literal.d.ts +2 -2
  180. package/build/require/type/template-literal/template-literal.js +1 -1
  181. package/build/require/type/template-literal/union.d.ts +2 -2
  182. package/build/require/type/template-literal/union.js +5 -10
  183. package/build/require/type/transform/transform.js +0 -1
  184. package/build/require/type/tuple/tuple.d.ts +1 -2
  185. package/build/require/type/type/json.d.ts +2 -2
  186. package/build/require/type/union/union-evaluated.d.ts +6 -10
  187. package/build/require/type/union/union-evaluated.js +7 -2
  188. package/build/require/value/cast/cast.js +20 -20
  189. package/build/require/value/check/check.js +62 -62
  190. package/build/require/value/clean/clean.js +16 -16
  191. package/build/require/value/convert/convert.js +36 -36
  192. package/build/require/value/create/create.js +65 -66
  193. package/build/require/value/default/default.js +16 -16
  194. package/build/require/value/transform/decode.js +18 -18
  195. package/build/require/value/transform/encode.js +18 -18
  196. package/build/require/value/transform/has.js +28 -28
  197. package/package.json +1 -1
  198. package/readme.md +47 -47
  199. package/build/import/type/modifiers/index.d.mts +0 -1
  200. package/build/import/type/modifiers/index.mjs +0 -1
  201. package/build/import/type/modifiers/modifiers.d.mts +0 -18
  202. package/build/import/type/modifiers/modifiers.mjs +0 -50
  203. package/build/require/type/modifiers/index.d.ts +0 -1
  204. package/build/require/type/modifiers/index.js +0 -18
  205. package/build/require/type/modifiers/modifiers.d.ts +0 -18
  206. package/build/require/type/modifiers/modifiers.js +0 -56
  207. /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
  208. /package/build/require/type/template-literal/{parser.d.ts → parse.d.ts} +0 -0
@@ -9,7 +9,6 @@ const index_3 = require("../union/index");
9
9
  // ------------------------------------------------------------------
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
- // prettier-ignore
13
12
  const type_1 = require("../guard/type");
14
13
  // ------------------------------------------------------------------
15
14
  // Apply
@@ -32,10 +31,10 @@ function FromTemplateLiteral(schema, mode, options) {
32
31
  // note: template literals require special runtime handling as they are encoded in string patterns.
33
32
  // This diverges from the mapped type which would otherwise map on the template literal kind.
34
33
  const expression = (0, index_1.TemplateLiteralParseExact)(schema.pattern);
35
- const finite = (0, index_1.IsTemplateLiteralFinite)(expression);
34
+ const finite = (0, index_1.IsTemplateLiteralExpressionFinite)(expression);
36
35
  if (!finite)
37
36
  return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
38
- const strings = [...(0, index_1.TemplateLiteralGenerate)(expression)];
37
+ const strings = [...(0, index_1.TemplateLiteralExpressionGenerate)(expression)];
39
38
  const literals = strings.map((value) => (0, index_2.Literal)(value));
40
39
  const mapped = FromRest(literals, mode);
41
40
  const union = (0, index_3.Union)(mapped);
@@ -49,9 +48,12 @@ function FromLiteralValue(value, mode) {
49
48
  mode === 'Lowercase' ? ApplyLowercase(value) :
50
49
  value) : value.toString());
51
50
  }
52
- function FromRest(T, mode) {
51
+ // prettier-ignore
52
+ function FromRest(T, M, Acc = []) {
53
53
  const [L, ...R] = T;
54
- return (T.length > 0 ? [Intrinsic(L, mode), ...FromRest(R, mode)] : []);
54
+ return (T.length > 0
55
+ ? FromRest(R, M, [...Acc, Intrinsic(L, M)])
56
+ : Acc);
55
57
  }
56
58
  /** Applies an intrinsic string manipulation to the given type. */
57
59
  function Intrinsic(schema, mode, options = {}) {
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index';
2
2
  import type { TProperties } from '../object/index';
3
3
  import { type TMappedResult } from '../mapped/index';
4
4
  import { type TKeyOf } from './keyof';
5
- type FromProperties<K extends TProperties> = ({
5
+ type TFromProperties<K extends TProperties> = ({
6
6
  [K2 in keyof K]: TKeyOf<K[K2]>;
7
7
  });
8
- declare function FromProperties<K extends TProperties>(K: K, options: SchemaOptions): FromProperties<K>;
9
- type FromMappedResult<K extends TMappedResult> = (FromProperties<K['properties']>);
10
- declare function FromMappedResult<K extends TMappedResult>(K: K, options: SchemaOptions): FromMappedResult<K>;
11
- export type TKeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
12
- export declare function KeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
8
+ type TFromMappedResult<K extends TMappedResult> = (TFromProperties<K['properties']>);
9
+ export type TKeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
10
+ export declare function KeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
13
11
  export {};
@@ -7,24 +7,20 @@ import type { TTuple } from '../tuple/index';
7
7
  import type { TArray } from '../array/index';
8
8
  import type { TObject, TProperties } from '../object/index';
9
9
  import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index';
10
- type FromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [KeyOfPropertyKeys<L>, ...FromRest<R>] : []);
11
- declare function FromRest<T extends TSchema[]>(T: [...T]): FromRest<T>;
12
- type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = FromRest<T>> = (OperatorUnionMany<C>);
13
- declare function FromIntersect<T extends TSchema[]>(T: [...T], C?: FromRest<T>): FromIntersect<T>;
14
- type FromUnion<T extends TSchema[], C extends PropertyKey[][] = FromRest<T>> = (OperatorIntersectMany<C>);
10
+ type TFromRest<T extends TSchema[], Acc extends PropertyKey[][] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TKeyOfPropertyKeys<L>]> : Acc);
11
+ type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = OperatorUnionMany<C>> = R;
12
+ declare function FromIntersect<T extends TSchema[]>(T: [...T]): FromIntersect<T>;
13
+ type FromUnion<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = OperatorIntersectMany<C>> = R;
15
14
  declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
16
- type FromTuple<T extends TSchema[], I extends string = ZeroString> = T extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? [I, ...FromTuple<R, Increment<I>>] : [];
17
- declare function FromTuple<T extends TSchema[]>(T: [...T], I?: string): FromTuple<T>;
18
- type FromArray<_ extends TSchema> = ([
15
+ type TFromTuple<T extends TSchema[], I extends string = ZeroString, Acc extends PropertyKey[] = []> = T extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? TFromTuple<R, Increment<I>, [...Acc, I]> : Acc;
16
+ type TFromArray<_ extends TSchema> = ([
19
17
  '[number]'
20
18
  ]);
21
- declare function FromArray<_ extends TSchema>(_: _): FromArray<_>;
22
- type FromProperties<T extends TProperties> = (UnionToTuple<keyof T>);
23
- declare function FromProperties<T extends TProperties>(T: T): FromProperties<T>;
24
- export type KeyOfPropertyKeys<T extends TSchema> = (T extends TRecursive<infer S> ? KeyOfPropertyKeys<S> : T extends TIntersect<infer S> ? FromIntersect<S> : T extends TUnion<infer S> ? FromUnion<S> : T extends TTuple<infer S> ? FromTuple<S> : T extends TArray<infer S> ? FromArray<S> : T extends TObject<infer S> ? FromProperties<S> : [
19
+ type TFromProperties<T extends TProperties> = (UnionToTuple<keyof T>);
20
+ export type TKeyOfPropertyKeys<T extends TSchema> = (T extends TRecursive<infer S> ? TKeyOfPropertyKeys<S> : T extends TIntersect<infer S> ? FromIntersect<S> : T extends TUnion<infer S> ? FromUnion<S> : T extends TTuple<infer S> ? TFromTuple<S> : T extends TArray<infer S> ? TFromArray<S> : T extends TObject<infer S> ? TFromProperties<S> : [
25
21
  ]);
26
22
  /** Returns a tuple of PropertyKeys derived from the given TSchema. */
27
- export declare function KeyOfPropertyKeys<T extends TSchema>(T: T): KeyOfPropertyKeys<T>;
23
+ export declare function KeyOfPropertyKeys<T extends TSchema>(T: T): TKeyOfPropertyKeys<T>;
28
24
  /** Returns a regular expression pattern derived from the given TSchema */
29
25
  export declare function KeyOfPattern(schema: TSchema): string;
30
26
  export {};
@@ -10,27 +10,30 @@ const index_2 = require("../operators/index");
10
10
  // prettier-ignore
11
11
  const type_1 = require("../guard/type");
12
12
  // prettier-ignore
13
- function FromRest(T) {
13
+ function FromRest(T, Acc = []) {
14
14
  const [L, ...R] = T;
15
15
  return (T.length > 0
16
- ? [KeyOfPropertyKeys(L), ...FromRest(R)]
17
- : []);
16
+ ? FromRest(R, [...Acc, KeyOfPropertyKeys(L)])
17
+ : Acc);
18
18
  }
19
19
  // prettier-ignore
20
- function FromIntersect(T, C = FromRest(T)) {
21
- return (0, index_2.OperatorUnionMany)(C);
20
+ function FromIntersect(T) {
21
+ const C = FromRest(T);
22
+ const R = (0, index_2.OperatorUnionMany)(C);
23
+ return R;
22
24
  }
23
25
  // prettier-ignore
24
26
  function FromUnion(T) {
25
27
  const C = FromRest(T);
26
- return (0, index_2.OperatorIntersectMany)(C);
28
+ const R = (0, index_2.OperatorIntersectMany)(C);
29
+ return R;
27
30
  }
28
31
  // prettier-ignore
29
- function FromTuple(T, I = '0') {
32
+ function FromTuple(T, I = '0', Acc = []) {
30
33
  const [_, ...R] = T;
31
34
  return (T.length > 0
32
- ? [I, ...FromTuple(R, (0, index_1.Increment)(I))]
33
- : []);
35
+ ? FromTuple(R, (0, index_1.Increment)(I), [...Acc, I])
36
+ : Acc);
34
37
  }
35
38
  // prettier-ignore
36
39
  function FromArray(_) {
@@ -1,15 +1,14 @@
1
1
  import type { TSchema } from '../schema/index';
2
- import type { Ensure } from '../helpers/index';
2
+ import type { Assert, Ensure } from '../helpers/index';
3
3
  import type { TMappedResult } from '../mapped/index';
4
- import { type TLiteral, TLiteralValue } from '../literal/index';
4
+ import type { SchemaOptions } from '../schema/index';
5
+ import { type TLiteral, type TLiteralValue } from '../literal/index';
5
6
  import { type TNumber } from '../number/index';
6
- import { type SchemaOptions } from '../schema/index';
7
- import { KeyOfPropertyKeys } from './keyof-property-keys';
8
- import { UnionEvaluated } from '../union/index';
7
+ import { type TKeyOfPropertyKeys } from './keyof-property-keys';
8
+ import { type TUnionEvaluated } from '../union/index';
9
9
  import { type TKeyOfFromMappedResult } from './keyof-from-mapped-result';
10
- type FromLiterals<T extends TLiteralValue[]> = (T extends [infer L extends TLiteralValue, ...infer R extends TLiteralValue[]] ? L extends '[number]' ? [TNumber, ...FromLiterals<R>] : [TLiteral<L>, ...FromLiterals<R>] : []);
11
- declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
12
- export type TKeyOf<T extends TSchema> = (Ensure<UnionEvaluated<FromLiterals<KeyOfPropertyKeys<T>>>>);
10
+ type TFromPropertyKeys<T extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? L extends '[number]' ? TFromPropertyKeys<R, [...Acc, TNumber]> : TFromPropertyKeys<R, [...Acc, TLiteral<Assert<L, TLiteralValue>>]> : Acc);
11
+ export type TKeyOf<T extends TSchema, K extends PropertyKey[] = TKeyOfPropertyKeys<T>, S extends TSchema[] = TFromPropertyKeys<K>, U = TUnionEvaluated<S>> = (Ensure<U>);
13
12
  /** `[Json]` Creates a KeyOf type */
14
13
  export declare function KeyOf<T extends TMappedResult>(T: T, options?: SchemaOptions): TKeyOfFromMappedResult<T>;
15
14
  /** `[Json]` Creates a KeyOf type */
@@ -14,13 +14,13 @@ const keyof_from_mapped_result_1 = require("./keyof-from-mapped-result");
14
14
  // prettier-ignore
15
15
  const type_2 = require("../guard/type");
16
16
  // prettier-ignore
17
- function FromLiterals(T) {
17
+ function FromPropertyKeys(T, Acc = []) {
18
18
  const [L, ...R] = T;
19
19
  return (T.length > 0
20
20
  ? L === '[number]'
21
- ? [(0, index_2.Number)(), ...FromLiterals(R)]
22
- : [(0, index_1.Literal)(L), ...FromLiterals(R)]
23
- : []);
21
+ ? FromPropertyKeys(R, [...Acc, (0, index_2.Number)()])
22
+ : FromPropertyKeys(R, [...Acc, (0, index_1.Literal)(L)])
23
+ : Acc);
24
24
  }
25
25
  /** `[Json]` Creates a KeyOf type */
26
26
  function KeyOf(T, options = {}) {
@@ -28,8 +28,10 @@ function KeyOf(T, options = {}) {
28
28
  return (0, keyof_from_mapped_result_1.KeyOfFromMappedResult)(T, options);
29
29
  }
30
30
  else {
31
- const K = (0, index_3.UnionEvaluated)(FromLiterals((0, keyof_property_keys_1.KeyOfPropertyKeys)(T)));
32
- return (0, type_1.CloneType)(K, options);
31
+ const K = (0, keyof_property_keys_1.KeyOfPropertyKeys)(T);
32
+ const S = FromPropertyKeys(K);
33
+ const U = (0, index_3.UnionEvaluated)(S);
34
+ return (0, type_1.CloneType)(U, options);
33
35
  }
34
36
  }
35
37
  exports.KeyOf = KeyOf;
@@ -16,26 +16,22 @@ import { type TTuple } from '../tuple/index';
16
16
  import { type TUnion } from '../union/index';
17
17
  import { type TMappedResult } from './mapped-result';
18
18
  import type { TMappedKey } from './mapped-key';
19
- type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
20
- declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
21
- type MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
19
+ type TFromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
20
+ type TMappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[], Acc extends TProperties = {}> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedKeyToMappedResultProperties<K, R, Acc & {
22
21
  [_ in L]: TLiteral<Assert<L, TLiteralValue>>;
23
- } & MappedKeyToMappedResultProperties<K, R> : {});
24
- declare function MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): MappedKeyToMappedResultProperties<K, P>;
25
- type FromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = MappedKeyToMappedResultProperties<K, P>> = (FromMappedResult<K, R>);
26
- declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): FromMappedResult<K, MappedKeyToMappedResultProperties<K, P>>;
27
- type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
28
- declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
22
+ }> : Acc);
23
+ type TFromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = TMappedKeyToMappedResultProperties<K, P>> = (TFromMappedResult<K, R>);
24
+ type TFromRest<K extends PropertyKey, T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<K, R, [...Acc, FromSchemaType<K, L>]> : Acc);
29
25
  type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
30
26
  [K2 in keyof T]: FromSchemaType<K, T[K2]>;
31
27
  }>> = R;
32
28
  declare function FromProperties<K extends PropertyKey, T extends TProperties>(K: K, T: T): FromProperties<K, T>;
33
- type FromSchemaType<K extends PropertyKey, T extends TSchema> = (T extends TReadonly<infer S> ? TReadonly<FromSchemaType<K, S>> : T extends TOptional<infer S> ? TOptional<FromSchemaType<K, S>> : T extends TMappedResult<infer P> ? FromMappedResult<K, P> : T extends TMappedKey<infer P> ? FromMappedKey<K, P> : T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<FromRest<K, S>, FromSchemaType<K, R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<FromRest<K, S>, FromSchemaType<K, R>> : T extends TAsyncIterator<infer S> ? TAsyncIterator<FromSchemaType<K, S>> : T extends TIterator<infer S> ? TIterator<FromSchemaType<K, S>> : T extends TIntersect<infer S> ? TIntersect<FromRest<K, S>> : T extends TUnion<infer S> ? TUnion<FromRest<K, S>> : T extends TTuple<infer S> ? TTuple<FromRest<K, S>> : T extends TObject<infer S> ? TObject<FromProperties<K, S>> : T extends TArray<infer S> ? TArray<FromSchemaType<K, S>> : T extends TPromise<infer S> ? TPromise<FromSchemaType<K, S>> : T);
29
+ type FromSchemaType<K extends PropertyKey, T extends TSchema> = (T extends TReadonly<infer S> ? TReadonly<FromSchemaType<K, S>> : T extends TOptional<infer S> ? TOptional<FromSchemaType<K, S>> : T extends TMappedResult<infer P> ? TFromMappedResult<K, P> : T extends TMappedKey<infer P> ? TFromMappedKey<K, P> : T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<TFromRest<K, S>, FromSchemaType<K, R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<TFromRest<K, S>, FromSchemaType<K, R>> : T extends TAsyncIterator<infer S> ? TAsyncIterator<FromSchemaType<K, S>> : T extends TIterator<infer S> ? TIterator<FromSchemaType<K, S>> : T extends TIntersect<infer S> ? TIntersect<TFromRest<K, S>> : T extends TUnion<infer S> ? TUnion<TFromRest<K, S>> : T extends TTuple<infer S> ? TTuple<TFromRest<K, S>> : T extends TObject<infer S> ? TObject<FromProperties<K, S>> : T extends TArray<infer S> ? TArray<FromSchemaType<K, S>> : T extends TPromise<infer S> ? TPromise<FromSchemaType<K, S>> : T);
34
30
  declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K, T: T): FromSchemaType<K, T>;
35
- type FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
31
+ type FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? FromMappedFunctionReturnType<R, T, Acc & {
36
32
  [_ in L]: FromSchemaType<L, T>;
37
- } & FromMappedFunctionReturnType<R, T> : {});
38
- declare function FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): FromMappedFunctionReturnType<K, T>;
33
+ }> : Acc);
34
+ declare function FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T, Acc?: TProperties): FromMappedFunctionReturnType<K, T>;
39
35
  export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
40
36
  export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<FromMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
41
37
  /** `[Json]` Creates a Mapped object type */
@@ -34,11 +34,11 @@ function FromMappedResult(K, P) {
34
34
  : (0, mapped_result_1.MappedResult)(P));
35
35
  }
36
36
  // prettier-ignore
37
- function MappedKeyToMappedResultProperties(K, P) {
37
+ function MappedKeyToMappedResultProperties(K, P, Acc = {}) {
38
38
  const [L, ...R] = P;
39
39
  return (P.length > 0
40
- ? { [L]: (0, index_10.Literal)(L), ...MappedKeyToMappedResultProperties(K, R) }
41
- : {});
40
+ ? MappedKeyToMappedResultProperties(K, R, { ...Acc, [L]: (0, index_10.Literal)(L) })
41
+ : Acc);
42
42
  }
43
43
  // prettier-ignore
44
44
  function FromMappedKey(K, P) {
@@ -46,11 +46,11 @@ function FromMappedKey(K, P) {
46
46
  return FromMappedResult(K, R);
47
47
  }
48
48
  // prettier-ignore
49
- function FromRest(K, T) {
49
+ function FromRest(K, T, Acc = []) {
50
50
  const [L, ...R] = T;
51
51
  return (T.length > 0
52
- ? [FromSchemaType(K, L), ...FromRest(K, R)]
53
- : []);
52
+ ? FromRest(K, R, [...Acc, FromSchemaType(K, L)])
53
+ : Acc);
54
54
  }
55
55
  // prettier-ignore
56
56
  function FromProperties(K, T) {
@@ -81,11 +81,11 @@ function FromSchemaType(K, T) {
81
81
  T);
82
82
  }
83
83
  // prettier-ignore
84
- function FromMappedFunctionReturnType(K, T) {
84
+ function FromMappedFunctionReturnType(K, T, Acc = {}) {
85
85
  const [L, ...R] = K;
86
86
  return (K.length > 0
87
- ? { [L]: FromSchemaType(L, T), ...FromMappedFunctionReturnType(R, T) }
88
- : {});
87
+ ? FromMappedFunctionReturnType(R, T, { ...Acc, [L]: FromSchemaType(L, T) })
88
+ : Acc);
89
89
  }
90
90
  /** `[Json]` Creates a Mapped object type */
91
91
  function Mapped(key, map, options = {}) {
@@ -2,14 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import type { TProperties } from '../object/index';
3
3
  import { type TMappedResult, type TMappedKey } from '../mapped/index';
4
4
  import { type TOmit } from './omit';
5
- type FromPropertyKey<T extends TSchema, K extends PropertyKey> = {
5
+ type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
6
6
  [_ in K]: TOmit<T, [K]>;
7
7
  };
8
- declare function FromPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K, options: SchemaOptions): FromPropertyKey<T, K>;
9
- type FromPropertyKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? FromPropertyKey<T, LK> & FromPropertyKeys<T, RK> : {});
10
- declare function FromPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K], options: SchemaOptions): FromPropertyKeys<T, K>;
11
- type FromMappedKey<T extends TSchema, K extends TMappedKey> = (FromPropertyKeys<T, K['keys']>);
12
- declare function FromMappedKey<T extends TSchema, K extends TMappedKey>(T: T, K: K, options: SchemaOptions): FromMappedKey<T, K>;
13
- export type TOmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>> = (TMappedResult<P>);
14
- export declare function OmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
8
+ type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
9
+ type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
10
+ export type TOmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
11
+ export declare function OmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
15
12
  export {};
@@ -11,11 +11,11 @@ function FromPropertyKey(T, K, options) {
11
11
  };
12
12
  }
13
13
  // prettier-ignore
14
- function FromPropertyKeys(T, K, options) {
14
+ function FromPropertyKeys(T, K, options, Acc = {}) {
15
15
  const [LK, ...RK] = K;
16
16
  return (K.length > 0
17
- ? { ...FromPropertyKey(T, LK, options), ...FromPropertyKeys(T, RK, options) }
18
- : {});
17
+ ? FromPropertyKeys(T, RK, options, { ...Acc, ...FromPropertyKey(T, LK, options) })
18
+ : Acc);
19
19
  }
20
20
  // prettier-ignore
21
21
  function FromMappedKey(T, K, options) {
@@ -7,15 +7,12 @@ import { type TObject, type TProperties } from '../object/index';
7
7
  import { type TIndexPropertyKeys } from '../indexed/index';
8
8
  import { TMappedKey } from '../mapped/index';
9
9
  import { type TOmitFromMappedKey } from './omit-from-mapped-key';
10
- type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [OmitResolve<L, K>, ...FromIntersect<R, K>] : [];
11
- declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
12
- type FromUnion<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [OmitResolve<L, K>, ...FromUnion<R, K>] : [];
13
- declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K>;
14
- type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Omit<T, I>>;
15
- declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): TProperties;
16
- export type OmitResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<OmitResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
17
- export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): OmitResolve<T, K>;
18
- export type TOmit<T extends TSchema, K extends PropertyKey[]> = OmitResolve<T, K>;
10
+ type TFromIntersect<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, K, [...Acc, TOmitResolve<L, K>]> : Acc);
11
+ type TFromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Acc, TOmitResolve<L, K>]> : Acc);
12
+ type TFromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Omit<T, I>>;
13
+ export type TOmitResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TOmitResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S, K>> : T extends TObject<infer S> ? TObject<TFromProperties<S, K>> : TObject<{}>;
14
+ export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TOmitResolve<T, K>;
15
+ export type TOmit<T extends TSchema, K extends PropertyKey[]> = TOmitResolve<T, K>;
19
16
  /** `[Json]` Constructs a type whose keys are picked from the given type */
20
17
  export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K): TOmitFromMappedKey<T, K>;
21
18
  /** `[Json]` Constructs a type whose keys are omitted from the given type */
@@ -13,7 +13,6 @@ const omit_from_mapped_key_1 = require("./omit-from-mapped-key");
13
13
  // ------------------------------------------------------------------
14
14
  // TypeGuard
15
15
  // ------------------------------------------------------------------
16
- // prettier-ignore
17
16
  const type_2 = require("../guard/type");
18
17
  // prettier-ignore
19
18
  function FromIntersect(T, K) {
@@ -1,24 +1,24 @@
1
- export type OperatorIncludes<T extends PropertyKey[], S extends PropertyKey> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? S extends L ? true : OperatorIncludes<R, S> : false);
1
+ export type TOperatorIncludes<T extends PropertyKey[], S extends PropertyKey> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? S extends L ? true : TOperatorIncludes<R, S> : false);
2
2
  /** Returns true if element S is in the set of T */
3
- export declare function OperatorIncludes<T extends PropertyKey[], S extends PropertyKey>(T: [...T], S: S): OperatorIncludes<T, S>;
4
- export type OperatorSubset<T extends PropertyKey[], S extends PropertyKey[]> = T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? OperatorIncludes<S, L> extends true ? OperatorSubset<R, S> : false : true;
3
+ export declare function OperatorIncludes<T extends PropertyKey[], S extends PropertyKey>(T: [...T], S: S): TOperatorIncludes<T, S>;
4
+ export type TOperatorSubset<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? TOperatorSubset<R, S> : false : true);
5
5
  /** Returns true if T is a subset of S */
6
- export declare function OperatorSubset<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): OperatorSubset<T, S>;
7
- export type OperatorDistinct<T extends PropertyKey[], Acc extends PropertyKey[] = []> = T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? OperatorIncludes<Acc, L> extends false ? OperatorDistinct<R, [...Acc, L]> : OperatorDistinct<R, [...Acc]> : Acc;
6
+ export declare function OperatorSubset<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TOperatorSubset<T, S>;
7
+ export type TOperatorDistinct<T extends PropertyKey[], Acc extends PropertyKey[] = []> = T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<Acc, L> extends false ? TOperatorDistinct<R, [...Acc, L]> : TOperatorDistinct<R, [...Acc]> : Acc;
8
8
  /** Returns a distinct set of elements */
9
- export declare function OperatorDistinct<T extends PropertyKey[]>(T: [...T], Acc?: PropertyKey[]): OperatorDistinct<T>;
10
- export type OperatorIntersect<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? OperatorIncludes<S, L> extends true ? [L, ...OperatorIntersect<R, S>] : [...OperatorIntersect<R, S>] : []);
9
+ export declare function OperatorDistinct<T extends PropertyKey[]>(T: [...T], Acc?: PropertyKey[]): TOperatorDistinct<T>;
10
+ export type TOperatorIntersect<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? TOperatorIntersect<R, S, [L, ...Acc]> : TOperatorIntersect<R, S, [...Acc]> : Acc);
11
11
  /** Returns the Intersect of the given sets */
12
- export declare function OperatorIntersect<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): OperatorIntersect<T, S>;
13
- export type OperatorUnion<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? OperatorIncludes<S, L> extends true ? [...OperatorUnion<R, S>] : [L, ...OperatorUnion<R, S>] : S);
12
+ export declare function OperatorIntersect<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TOperatorIntersect<T, S>;
13
+ export type TOperatorUnion<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = S> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorUnion<R, S, [...Acc, L]> : Acc);
14
14
  /** Returns the Union of the given sets */
15
- export declare function OperatorUnion<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): OperatorUnion<T, S>;
16
- export type OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? OperatorIncludes<S, L> extends true ? [...OperatorComplement<R, S>] : [L, ...OperatorComplement<R, S>] : []);
15
+ export declare function OperatorUnion<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S], Acc?: PropertyKey[]): TOperatorUnion<T, S>;
16
+ export type OperatorComplement<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? OperatorComplement<R, S, [...Acc]> : OperatorComplement<R, S, [L, ...Acc]> : Acc);
17
17
  /** Returns the Complement by omitting elements in T that are in S */
18
- export declare function OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): OperatorComplement<T, S>;
19
- export type OperatorIntersectMany<T extends PropertyKey[][]> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorIntersect<L, OperatorIntersectMany<R>> : []);
18
+ export declare function OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S], Acc?: PropertyKey[]): OperatorComplement<T, S>;
19
+ export type OperatorIntersectMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorIntersectMany<R, TOperatorIntersect<Acc, L>> : Acc);
20
20
  /** Returns the Intersect of multiple sets */
21
- export declare function OperatorIntersectMany<T extends PropertyKey[][]>(T: [...T]): OperatorIntersectMany<T>;
22
- export type OperatorUnionMany<T extends PropertyKey[][]> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorUnion<L, OperatorUnionMany<R>> : []);
21
+ export declare function OperatorIntersectMany<T extends PropertyKey[][]>(T: [...T], Acc?: PropertyKey[]): OperatorIntersectMany<T>;
22
+ export type OperatorUnionMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorUnionMany<R, TOperatorUnion<Acc, L>> : Acc);
23
23
  /** Returns the Union of multiple sets */
24
- export declare function OperatorUnionMany<T extends PropertyKey[][]>(T: [...T]): OperatorUnionMany<T>;
24
+ export declare function OperatorUnionMany<T extends PropertyKey[][]>(T: [...T], Acc?: PropertyKey[]): OperatorUnionMany<T>;
@@ -14,9 +14,9 @@ function OperatorIncludes(T, S) {
14
14
  }
15
15
  exports.OperatorIncludes = OperatorIncludes;
16
16
  /** Returns true if T is a subset of S */
17
- // prettier-ignore
18
17
  function OperatorSubset(T, S) {
19
18
  const [L, ...R] = T;
19
+ // prettier-ignore
20
20
  return (T.length > 0
21
21
  ? OperatorIncludes(S, L) === true
22
22
  ? OperatorSubset(R, S)
@@ -25,20 +25,19 @@ function OperatorSubset(T, S) {
25
25
  }
26
26
  exports.OperatorSubset = OperatorSubset;
27
27
  /** Returns a distinct set of elements */
28
- // prettier-ignore
29
28
  function OperatorDistinct(T, Acc = []) {
30
29
  const [L, ...R] = T;
31
- return (T.length > 0
32
- ? OperatorIncludes(Acc, L) === false
30
+ // prettier-ignore
31
+ return (T.length > 0 ?
32
+ (OperatorIncludes(Acc, L) === false
33
33
  ? OperatorDistinct(R, [...Acc, L])
34
- : OperatorDistinct(R, [...Acc])
35
- : Acc);
34
+ : OperatorDistinct(R, [...Acc])) : Acc);
36
35
  }
37
36
  exports.OperatorDistinct = OperatorDistinct;
38
37
  /** Returns the Intersect of the given sets */
39
- // prettier-ignore
40
38
  function OperatorIntersect(T, S) {
41
39
  const [L, ...R] = T;
40
+ // prettier-ignore
42
41
  return (T.length > 0
43
42
  ? OperatorIncludes(S, L) === true
44
43
  ? [L, ...OperatorIntersect(R, S)]
@@ -47,30 +46,28 @@ function OperatorIntersect(T, S) {
47
46
  }
48
47
  exports.OperatorIntersect = OperatorIntersect;
49
48
  /** Returns the Union of the given sets */
50
- // prettier-ignore
51
- function OperatorUnion(T, S) {
49
+ function OperatorUnion(T, S, Acc = S) {
52
50
  const [L, ...R] = T;
51
+ // prettier-ignore
53
52
  return (T.length > 0
54
- ? OperatorIncludes(S, L) === true
55
- ? [...OperatorUnion(R, S)]
56
- : [L, ...OperatorUnion(R, S)]
57
- : S);
53
+ ? OperatorUnion(R, S, [...Acc, L])
54
+ : Acc);
58
55
  }
59
56
  exports.OperatorUnion = OperatorUnion;
60
57
  /** Returns the Complement by omitting elements in T that are in S */
61
58
  // prettier-ignore
62
- function OperatorComplement(T, S) {
59
+ function OperatorComplement(T, S, Acc = []) {
63
60
  const [L, ...R] = T;
64
61
  return (T.length > 0
65
62
  ? OperatorIncludes(S, L) === true
66
- ? [...OperatorComplement(R, S)]
67
- : [L, ...OperatorComplement(R, S)]
68
- : []);
63
+ ? OperatorComplement(R, S, [...Acc])
64
+ : OperatorComplement(R, S, [L, ...Acc])
65
+ : Acc);
69
66
  }
70
67
  exports.OperatorComplement = OperatorComplement;
71
68
  /** Returns the Intersect of multiple sets */
72
69
  // prettier-ignore
73
- function OperatorIntersectMany(T) {
70
+ function OperatorIntersectMany(T, Acc = []) {
74
71
  return (T.length === 1
75
72
  ? T[0]
76
73
  : (() => {
@@ -82,12 +79,11 @@ function OperatorIntersectMany(T) {
82
79
  }
83
80
  exports.OperatorIntersectMany = OperatorIntersectMany;
84
81
  /** Returns the Union of multiple sets */
85
- function OperatorUnionMany(T) {
86
- return (T.length === 1
87
- ? T[0]
88
- : (() => {
89
- const [L, ...R] = T;
90
- return T.length > 0 ? OperatorUnion(L, OperatorUnionMany(R)) : [];
91
- })());
82
+ function OperatorUnionMany(T, Acc = []) {
83
+ const [L, ...R] = T;
84
+ // prettier-ignore
85
+ return (T.length > 0
86
+ ? OperatorUnionMany(R, OperatorUnion(Acc, L))
87
+ : Acc);
92
88
  }
93
89
  exports.OperatorUnionMany = OperatorUnionMany;
@@ -1,12 +1,10 @@
1
1
  import type { TProperties } from '../object/index';
2
2
  import { type TMappedResult } from '../mapped/index';
3
3
  import { type TOptionalWithFlag } from './optional';
4
- type FromProperties<K extends TProperties, F extends boolean> = ({
4
+ type TFromProperties<K extends TProperties, F extends boolean> = ({
5
5
  [K2 in keyof K]: TOptionalWithFlag<K[K2], F>;
6
6
  });
7
- declare function FromProperties<K extends TProperties, F extends boolean>(K: K, F: F): FromProperties<K, F>;
8
- type FromMappedResult<K extends TMappedResult, F extends boolean> = (FromProperties<K['properties'], F>);
9
- declare function FromMappedResult<K extends TMappedResult, F extends boolean>(K: K, F: F): FromMappedResult<K, F>;
10
- export type TOptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
11
- export declare function OptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
7
+ type TFromMappedResult<K extends TMappedResult, F extends boolean> = (TFromProperties<K['properties'], F>);
8
+ export type TOptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>> = (TMappedResult<P>);
9
+ export declare function OptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
12
10
  export {};
@@ -3,13 +3,9 @@ import type { Ensure } from '../helpers/index';
3
3
  import { OptionalKind } from '../symbols/index';
4
4
  import type { TMappedResult } from '../mapped/index';
5
5
  import { type TOptionalFromMappedResult } from './optional-from-mapped-result';
6
- type RemoveOptional<T extends TSchema> = T extends TOptional<infer S> ? S : T;
7
- declare function RemoveOptional<T extends TSchema>(schema: T): Record<PropertyKey, any>;
8
- type AddOptional<T extends TSchema> = T extends TOptional<infer S> ? TOptional<S> : Ensure<TOptional<T>>;
9
- declare function AddOptional<T extends TSchema>(schema: T): T & {
10
- [OptionalKind]: string;
11
- };
12
- export type TOptionalWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveOptional<T> : AddOptional<T>;
6
+ type TRemoveOptional<T extends TSchema> = T extends TOptional<infer S> ? S : T;
7
+ type TAddOptional<T extends TSchema> = T extends TOptional<infer S> ? TOptional<S> : Ensure<TOptional<T>>;
8
+ export type TOptionalWithFlag<T extends TSchema, F extends boolean> = F extends false ? TRemoveOptional<T> : TAddOptional<T>;
13
9
  export type TOptional<T extends TSchema> = T & {
14
10
  [OptionalKind]: 'Optional';
15
11
  };
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index';
2
2
  import type { TProperties } from '../object/index';
3
3
  import { type TMappedResult } from '../mapped/index';
4
4
  import { type TPartial } from './partial';
5
- type FromProperties<K extends TProperties> = ({
5
+ type TFromProperties<K extends TProperties> = ({
6
6
  [K2 in keyof K]: TPartial<K[K2]>;
7
7
  });
8
- declare function FromProperties<K extends TProperties>(K: K, options: SchemaOptions): FromProperties<K>;
9
- type FromMappedResult<K extends TMappedResult> = (FromProperties<K['properties']>);
10
- declare function FromMappedResult<K extends TMappedResult>(K: K, options: SchemaOptions): FromMappedResult<K>;
11
- export type TPartialFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
12
- export declare function PartialFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
8
+ type TFromMappedResult<K extends TMappedResult> = (TFromProperties<K['properties']>);
9
+ export type TPartialFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
10
+ export declare function PartialFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
13
11
  export {};
@@ -9,15 +9,12 @@ import { type TObject, type TProperties } from '../object/index';
9
9
  import { type TIntersect } from '../intersect/index';
10
10
  import { type TUnion } from '../union/index';
11
11
  import { type TPartialFromMappedResult } from './partial-from-mapped-result';
12
- type FromIntersect<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PartialResolve<L>, ...FromIntersect<R>] : []);
13
- declare function FromIntersect<T extends TSchema[]>(T: [...T]): FromIntersect<T>;
14
- type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PartialResolve<L>, ...FromUnion<R>] : []);
15
- declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
16
- type FromProperties<T extends TProperties> = Evaluate<{
12
+ type TFromIntersect<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, [...Acc, PartialResolve<L>]> : Acc);
13
+ type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, PartialResolve<L>]> : Acc);
14
+ type TFromProperties<T extends TProperties> = Evaluate<{
17
15
  [K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : T[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : T[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<T[K]>;
18
16
  }>;
19
- declare function FromProperties<T extends TProperties>(T: T): TProperties;
20
- type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S>> : T extends TUnion<infer S> ? TUnion<FromUnion<S>> : T extends TObject<infer S> ? TObject<FromProperties<S>> : TObject<{}>);
17
+ type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
21
18
  declare function PartialResolve<T extends TSchema>(T: T): PartialResolve<T>;
22
19
  export type TPartial<T extends TSchema> = PartialResolve<T>;
23
20
  /** `[Json]` Constructs a type where all properties are optional */