@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
@@ -2,14 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import type { TProperties } from '../object/index.mjs';
3
3
  import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
4
4
  import { type TOmit } from './omit.mjs';
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 {};
@@ -7,11 +7,11 @@ function FromPropertyKey(T, K, options) {
7
7
  };
8
8
  }
9
9
  // prettier-ignore
10
- function FromPropertyKeys(T, K, options) {
10
+ function FromPropertyKeys(T, K, options, Acc = {}) {
11
11
  const [LK, ...RK] = K;
12
12
  return (K.length > 0
13
- ? { ...FromPropertyKey(T, LK, options), ...FromPropertyKeys(T, RK, options) }
14
- : {});
13
+ ? FromPropertyKeys(T, RK, options, { ...Acc, ...FromPropertyKey(T, LK, options) })
14
+ : Acc);
15
15
  }
16
16
  // prettier-ignore
17
17
  function FromMappedKey(T, K, options) {
@@ -7,15 +7,12 @@ import { type TObject, type TProperties } from '../object/index.mjs';
7
7
  import { type TIndexPropertyKeys } from '../indexed/index.mjs';
8
8
  import { TMappedKey } from '../mapped/index.mjs';
9
9
  import { type TOmitFromMappedKey } from './omit-from-mapped-key.mjs';
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 */
@@ -9,7 +9,6 @@ import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
- // prettier-ignore
13
12
  import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/type.mjs';
14
13
  // prettier-ignore
15
14
  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>;
@@ -9,9 +9,9 @@ export function OperatorIncludes(T, S) {
9
9
  : false);
10
10
  }
11
11
  /** Returns true if T is a subset of S */
12
- // prettier-ignore
13
12
  export function OperatorSubset(T, S) {
14
13
  const [L, ...R] = T;
14
+ // prettier-ignore
15
15
  return (T.length > 0
16
16
  ? OperatorIncludes(S, L) === true
17
17
  ? OperatorSubset(R, S)
@@ -19,19 +19,18 @@ export function OperatorSubset(T, S) {
19
19
  : true);
20
20
  }
21
21
  /** Returns a distinct set of elements */
22
- // prettier-ignore
23
22
  export function OperatorDistinct(T, Acc = []) {
24
23
  const [L, ...R] = T;
25
- return (T.length > 0
26
- ? OperatorIncludes(Acc, L) === false
24
+ // prettier-ignore
25
+ return (T.length > 0 ?
26
+ (OperatorIncludes(Acc, L) === false
27
27
  ? OperatorDistinct(R, [...Acc, L])
28
- : OperatorDistinct(R, [...Acc])
29
- : Acc);
28
+ : OperatorDistinct(R, [...Acc])) : Acc);
30
29
  }
31
30
  /** Returns the Intersect of the given sets */
32
- // prettier-ignore
33
31
  export function OperatorIntersect(T, S) {
34
32
  const [L, ...R] = T;
33
+ // prettier-ignore
35
34
  return (T.length > 0
36
35
  ? OperatorIncludes(S, L) === true
37
36
  ? [L, ...OperatorIntersect(R, S)]
@@ -39,28 +38,26 @@ export function OperatorIntersect(T, S) {
39
38
  : []);
40
39
  }
41
40
  /** Returns the Union of the given sets */
42
- // prettier-ignore
43
- export function OperatorUnion(T, S) {
41
+ export function OperatorUnion(T, S, Acc = S) {
44
42
  const [L, ...R] = T;
43
+ // prettier-ignore
45
44
  return (T.length > 0
46
- ? OperatorIncludes(S, L) === true
47
- ? [...OperatorUnion(R, S)]
48
- : [L, ...OperatorUnion(R, S)]
49
- : S);
45
+ ? OperatorUnion(R, S, [...Acc, L])
46
+ : Acc);
50
47
  }
51
48
  /** Returns the Complement by omitting elements in T that are in S */
52
49
  // prettier-ignore
53
- export function OperatorComplement(T, S) {
50
+ export function OperatorComplement(T, S, Acc = []) {
54
51
  const [L, ...R] = T;
55
52
  return (T.length > 0
56
53
  ? OperatorIncludes(S, L) === true
57
- ? [...OperatorComplement(R, S)]
58
- : [L, ...OperatorComplement(R, S)]
59
- : []);
54
+ ? OperatorComplement(R, S, [...Acc])
55
+ : OperatorComplement(R, S, [L, ...Acc])
56
+ : Acc);
60
57
  }
61
58
  /** Returns the Intersect of multiple sets */
62
59
  // prettier-ignore
63
- export function OperatorIntersectMany(T) {
60
+ export function OperatorIntersectMany(T, Acc = []) {
64
61
  return (T.length === 1
65
62
  ? T[0]
66
63
  : (() => {
@@ -71,11 +68,10 @@ export function OperatorIntersectMany(T) {
71
68
  })());
72
69
  }
73
70
  /** Returns the Union of multiple sets */
74
- export function OperatorUnionMany(T) {
75
- return (T.length === 1
76
- ? T[0]
77
- : (() => {
78
- const [L, ...R] = T;
79
- return T.length > 0 ? OperatorUnion(L, OperatorUnionMany(R)) : [];
80
- })());
71
+ export function OperatorUnionMany(T, Acc = []) {
72
+ const [L, ...R] = T;
73
+ // prettier-ignore
74
+ return (T.length > 0
75
+ ? OperatorUnionMany(R, OperatorUnion(Acc, L))
76
+ : Acc);
81
77
  }
@@ -1,12 +1,10 @@
1
1
  import type { TProperties } from '../object/index.mjs';
2
2
  import { type TMappedResult } from '../mapped/index.mjs';
3
3
  import { type TOptionalWithFlag } from './optional.mjs';
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.mjs';
3
3
  import { OptionalKind } from '../symbols/index.mjs';
4
4
  import type { TMappedResult } from '../mapped/index.mjs';
5
5
  import { type TOptionalFromMappedResult } from './optional-from-mapped-result.mjs';
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.mjs';
2
2
  import type { TProperties } from '../object/index.mjs';
3
3
  import { type TMappedResult } from '../mapped/index.mjs';
4
4
  import { type TPartial } from './partial.mjs';
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.mjs';
9
9
  import { type TIntersect } from '../intersect/index.mjs';
10
10
  import { type TUnion } from '../union/index.mjs';
11
11
  import { type TPartialFromMappedResult } from './partial-from-mapped-result.mjs';
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 */
@@ -9,21 +9,20 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
- // prettier-ignore
13
12
  import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
14
13
  // prettier-ignore
15
- function FromIntersect(T) {
14
+ function FromIntersect(T, Acc = []) {
16
15
  const [L, ...R] = T;
17
16
  return (T.length > 0
18
- ? [PartialResolve(L), ...FromIntersect(R)]
19
- : []);
17
+ ? FromIntersect(R, [...Acc, PartialResolve(L)])
18
+ : Acc);
20
19
  }
21
20
  // prettier-ignore
22
- function FromUnion(T) {
21
+ function FromUnion(T, Acc = []) {
23
22
  const [L, ...R] = T;
24
23
  return (T.length > 0
25
- ? [PartialResolve(L), ...FromUnion(R)]
26
- : []);
24
+ ? FromUnion(R, [...Acc, PartialResolve(L)])
25
+ : Acc);
27
26
  }
28
27
  // prettier-ignore
29
28
  function FromProperties(T) {
@@ -2,14 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import type { TProperties } from '../object/index.mjs';
3
3
  import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
4
4
  import { type TPick } from './pick.mjs';
5
- type FromPropertyKey<T extends TSchema, K extends PropertyKey> = {
5
+ type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
6
6
  [_ in K]: TPick<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 TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>> = (TMappedResult<P>);
14
- export declare function PickFromMappedKey<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 TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
11
+ export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
15
12
  export {};
@@ -7,11 +7,11 @@ function FromPropertyKey(T, K, options) {
7
7
  };
8
8
  }
9
9
  // prettier-ignore
10
- function FromPropertyKeys(T, K, options) {
10
+ function FromPropertyKeys(T, K, options, Acc = {}) {
11
11
  const [LK, ...RK] = K;
12
12
  return (K.length > 0
13
- ? { ...FromPropertyKey(T, LK, options), ...FromPropertyKeys(T, RK, options) }
14
- : {});
13
+ ? FromPropertyKeys(T, RK, options, { ...Acc, ...FromPropertyKey(T, LK, options) })
14
+ : Acc);
15
15
  }
16
16
  // prettier-ignore
17
17
  function FromMappedKey(T, K, options) {
@@ -7,10 +7,10 @@ import { type TObject, type TProperties } from '../object/index.mjs';
7
7
  import { type TIndexPropertyKeys } from '../indexed/index.mjs';
8
8
  import { TMappedKey } from '../mapped/index.mjs';
9
9
  import { type TPickFromMappedKey } from './pick-from-mapped-key.mjs';
10
- type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PickResolve<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[]] ? [PickResolve<L, K>, ...FromUnion<R, K>] : [];
13
- declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K>;
10
+ type FromIntersect<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromIntersect<R, K, [...Acc, PickResolve<L, K>]> : Acc;
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[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromUnion<R, K, [...Acc, PickResolve<L, K>]> : Acc;
13
+ declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
14
14
  type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
15
15
  declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
16
16
  export type PickResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<PickResolve<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<{}>;
@@ -1,12 +1,10 @@
1
1
  import type { TProperties } from '../object/index.mjs';
2
2
  import { type TMappedResult } from '../mapped/index.mjs';
3
3
  import { type TReadonlyWithFlag } from './readonly.mjs';
4
- type FromProperties<K extends TProperties, F extends boolean> = ({
4
+ type TFromProperties<K extends TProperties, F extends boolean> = ({
5
5
  [K2 in keyof K]: TReadonlyWithFlag<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 TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
11
- export declare function ReadonlyFromMappedResult<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 TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>> = (TMappedResult<P>);
9
+ export declare function ReadonlyFromMappedResult<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.mjs';
3
3
  import { ReadonlyKind } from '../symbols/index.mjs';
4
4
  import type { TMappedResult } from '../mapped/index.mjs';
5
5
  import { type TReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
6
- type RemoveReadonly<T extends TSchema> = T extends TReadonly<infer S> ? S : T;
7
- declare function RemoveReadonly<T extends TSchema>(schema: T): Record<PropertyKey, any>;
8
- type AddReadonly<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<S> : Ensure<TReadonly<T>>;
9
- declare function AddReadonly<T extends TSchema>(schema: T): T & {
10
- [ReadonlyKind]: string;
11
- };
12
- export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveReadonly<T> : AddReadonly<T>;
6
+ type TRemoveReadonly<T extends TSchema> = T extends TReadonly<infer S> ? S : T;
7
+ type TAddReadonly<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<S> : Ensure<TReadonly<T>>;
8
+ export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? TRemoveReadonly<T> : TAddReadonly<T>;
13
9
  export type TReadonly<T extends TSchema> = T & {
14
10
  [ReadonlyKind]: 'Readonly';
15
11
  };
@@ -9,36 +9,30 @@ import { type TString } from '../string/index.mjs';
9
9
  import { type TInteger } from '../integer/index.mjs';
10
10
  import { type TNumber } from '../number/index.mjs';
11
11
  import { type TEnum } from '../enum/index.mjs';
12
- import { TTemplateLiteral, IsTemplateLiteralFinite } from '../template-literal/index.mjs';
12
+ import { TTemplateLiteral, TIsTemplateLiteralFinite } from '../template-literal/index.mjs';
13
13
  import { Kind } from '../symbols/index.mjs';
14
- type FromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
15
- type FromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
14
+ type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
15
+ type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
16
16
  [_ in I]: T;
17
17
  }>>>);
18
- type FromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = IsTemplateLiteralFinite<K> extends false ? FromTemplateLiteralKeyInfinite<K, T> : FromTemplateLiteralKeyFinite<K, T>;
19
- declare function FromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema>(K: K, T: T, options: ObjectOptions): FromTemplateLiteralKey<K, T>;
20
- type FromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
18
+ type TFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? TFromTemplateLiteralKeyInfinite<K, T> : TFromTemplateLiteralKeyFinite<K, T>;
19
+ type TFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
21
20
  [_ in K[keyof K]]: T;
22
21
  }>>;
23
- type FromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
22
+ type TFromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
24
23
  [_ in K['const']]: T;
25
24
  };
26
- type FromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
25
+ type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
27
26
  [_ in K['const']]: T;
28
27
  };
29
- type FromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? FromUnionKeyRest<S, T> & FromUnionKeyRest<R, T> : L extends TLiteral<string> ? FromUnionKeyLiteralString<L, T> & FromUnionKeyRest<R, T> : L extends TLiteral<number> ? FromUnionKeyLiteralNumber<L, T> & FromUnionKeyRest<R, T> : {}) : {};
30
- type FromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = FromUnionKeyRest<K, T>> = (Ensure<TObject<P>>);
31
- declare function FromUnionKey<K extends TSchema[], T extends TSchema>(K: K, T: T, options: ObjectOptions): FromUnionKey<K, T>;
32
- type FromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
28
+ type TFromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? TFromUnionKeyRest<S, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<string> ? TFromUnionKeyLiteralString<L, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<number> ? TFromUnionKeyLiteralNumber<L, T> & TFromUnionKeyRest<R, T> : {}) : {};
29
+ type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<P>>);
30
+ type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
33
31
  [_ in Assert<K, PropertyKey>]: T;
34
32
  }>>);
35
- declare function FromLiteralKey<K extends TLiteralValue, T extends TSchema>(K: K, T: T, options: ObjectOptions): FromLiteralKey<K, T>;
36
- type FromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
37
- declare function FromStringKey<K extends TString, T extends TSchema>(K: K, T: T, options: ObjectOptions): FromStringKey<K, T>;
38
- type FromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
39
- declare function FromIntegerKey<K extends TInteger, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
40
- type FromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
41
- declare function FromNumberKey<K extends TNumber, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
33
+ type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
34
+ type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
35
+ type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
42
36
  type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Record<Assert<Static<K>, PropertyKey>, Static<T, P>>);
43
37
  export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
44
38
  [Kind]: 'Record';
@@ -49,7 +43,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
49
43
  };
50
44
  additionalProperties: TAdditionalProperties;
51
45
  }
52
- export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? FromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? FromEnumKey<S, T> : K extends TUnion<infer S> ? FromUnionKey<S, T> : K extends TLiteral<infer S> ? FromLiteralKey<S, T> : K extends TInteger ? FromIntegerKey<K, T> : K extends TNumber ? FromNumberKey<K, T> : K extends TString ? FromStringKey<K, T> : TNever;
46
+ export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
53
47
  /** `[Json]` Creates a Record type */
54
48
  export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
55
49
  export {};
@@ -1,7 +1,7 @@
1
1
  import { Object } from '../object/index.mjs';
2
2
  import { Never } from '../never/index.mjs';
3
3
  import { Union } from '../union/index.mjs';
4
- import { IsTemplateLiteralFinite, TemplateLiteralParseExact } from '../template-literal/index.mjs';
4
+ import { IsTemplateLiteralFinite } from '../template-literal/index.mjs';
5
5
  import { PatternStringExact, PatternNumberExact } from '../patterns/index.mjs';
6
6
  import { IndexPropertyKeys } from '../indexed/index.mjs';
7
7
  import { Kind, Hint } from '../symbols/index.mjs';
@@ -10,7 +10,6 @@ import { IsUndefined } from '../guard/value.mjs';
10
10
  // ------------------------------------------------------------------
11
11
  // TypeGuard
12
12
  // ------------------------------------------------------------------
13
- // prettier-ignore
14
13
  import { IsInteger, IsLiteral, IsNumber, IsString, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
15
14
  // ------------------------------------------------------------------
16
15
  // RecordCreateFromPattern
@@ -34,8 +33,7 @@ function RecordCreateFromKeys(K, T, options) {
34
33
  }
35
34
  // prettier-ignore
36
35
  function FromTemplateLiteralKey(K, T, options) {
37
- const expression = TemplateLiteralParseExact(K.pattern);
38
- return (IsTemplateLiteralFinite(expression)
36
+ return (IsTemplateLiteralFinite(K)
39
37
  ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options)
40
38
  : RecordCreateFromPattern(K.pattern, T, options));
41
39
  }
@@ -1,4 +1,7 @@
1
1
  import { Kind } from '../symbols/index.mjs';
2
+ // ------------------------------------------------------------------
3
+ // TypeGuard
4
+ // ------------------------------------------------------------------
2
5
  import { IsString, IsUndefined } from '../guard/value.mjs';
3
6
  /** `[Json]` Creates a Ref type. */
4
7
  export function Ref(unresolved, options = {}) {
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index.mjs';
2
2
  import type { TProperties } from '../object/index.mjs';
3
3
  import { type TMappedResult } from '../mapped/index.mjs';
4
4
  import { type TRequired } from './required.mjs';
5
- type FromProperties<K extends TProperties> = ({
5
+ type TFromProperties<K extends TProperties> = ({
6
6
  [K2 in keyof K]: TRequired<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 TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
12
- export declare function RequiredFromMappedResult<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 TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
10
+ export declare function RequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
13
11
  export {};
@@ -9,17 +9,13 @@ import { type TIntersect } from '../intersect/index.mjs';
9
9
  import { type TUnion } from '../union/index.mjs';
10
10
  import { type TObject, type TProperties } from '../object/index.mjs';
11
11
  import { type TRequiredFromMappedResult } from './required-from-mapped-result.mjs';
12
- type FromIntersect<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [RequiredResolve<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[]] ? [RequiredResolve<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, TRequiredResolve<L>]> : Acc);
13
+ type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, TRequiredResolve<L>]> : Acc);
14
+ type TFromProperties<T extends TProperties> = Evaluate<{
17
15
  [K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
18
16
  }>;
19
- declare function FromProperties<T extends TProperties>(T: T): TProperties;
20
- type RequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<RequiredResolve<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<{}>);
21
- declare function RequiredResolve<T extends TSchema>(T: T): RequiredResolve<T>;
22
- export type TRequired<T extends TSchema> = RequiredResolve<T>;
17
+ type TRequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<TRequiredResolve<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<{}>);
18
+ export type TRequired<T extends TSchema> = TRequiredResolve<T>;
23
19
  /** `[Json]` Constructs a type where all properties are required */
24
20
  export declare function Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>;
25
21
  /** `[Json]` Constructs a type where all properties are required */
@@ -8,21 +8,20 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // TypeGuard
10
10
  // ------------------------------------------------------------------
11
- // prettier-ignore
12
11
  import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
13
12
  // prettier-ignore
14
- function FromIntersect(T) {
13
+ function FromIntersect(T, Acc = []) {
15
14
  const [L, ...R] = T;
16
15
  return (T.length > 0
17
- ? [RequiredResolve(L), ...FromIntersect(R)]
18
- : []);
16
+ ? FromIntersect(R, [...Acc, RequiredResolve(L)])
17
+ : Acc);
19
18
  }
20
19
  // prettier-ignore
21
- function FromUnion(T) {
20
+ function FromUnion(T, Acc = []) {
22
21
  const [L, ...R] = T;
23
22
  return (T.length > 0
24
- ? [RequiredResolve(L), ...FromUnion(R)]
25
- : []);
23
+ ? FromUnion(R, [...Acc, RequiredResolve(L)])
24
+ : Acc);
26
25
  }
27
26
  // prettier-ignore
28
27
  function FromProperties(T) {