@sinclair/typebox 0.32.0-dev-11 → 0.32.0-dev-13

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 (152) hide show
  1. package/build/import/compiler/compiler.mjs +3 -3
  2. package/build/import/errors/errors.mjs +3 -3
  3. package/build/import/index.d.mts +6 -6
  4. package/build/import/index.mjs +4 -4
  5. package/build/import/type/composite/composite.d.mts +2 -2
  6. package/build/import/type/composite/composite.mjs +2 -2
  7. package/build/import/type/extends/extends-mapped-result-from-result.d.mts +13 -0
  8. package/build/import/type/extends/extends-mapped-result-from-result.mjs +14 -0
  9. package/build/import/type/extends/extends-mapped-result.d.mts +17 -0
  10. package/build/import/type/extends/extends-mapped-result.mjs +21 -0
  11. package/build/import/type/extends/extends.d.mts +8 -2
  12. package/build/import/type/extends/extends.mjs +7 -3
  13. package/build/import/type/extends/index.d.mts +2 -0
  14. package/build/import/type/extends/index.mjs +2 -0
  15. package/build/import/type/guard/type.d.mts +5 -1
  16. package/build/import/type/guard/type.mjs +18 -2
  17. package/build/import/type/indexed/index.d.mts +3 -2
  18. package/build/import/type/indexed/index.mjs +3 -2
  19. package/build/import/type/indexed/indexed-mapped-result.d.mts +16 -0
  20. package/build/import/type/indexed/indexed-mapped-result.mjs +18 -0
  21. package/build/import/type/indexed/{indexed-key.d.mts → indexed-property-keys.d.mts} +3 -3
  22. package/build/import/type/indexed/{indexed-key.mjs → indexed-property-keys.mjs} +2 -2
  23. package/build/import/type/indexed/{indexed-type.d.mts → indexed-result.d.mts} +2 -2
  24. package/build/import/type/indexed/{indexed-type.mjs → indexed-result.mjs} +1 -1
  25. package/build/import/type/indexed/indexed.d.mts +7 -4
  26. package/build/import/type/indexed/indexed.mjs +7 -6
  27. package/build/import/type/intrinsic/capitalize.d.mts +4 -0
  28. package/build/import/type/intrinsic/capitalize.mjs +5 -0
  29. package/build/import/type/intrinsic/index.d.mts +5 -0
  30. package/build/import/type/intrinsic/index.mjs +5 -0
  31. package/build/import/type/intrinsic/intrinsic-mapped-result.d.mts +15 -0
  32. package/build/import/type/intrinsic/intrinsic-mapped-result.mjs +21 -0
  33. package/build/import/type/intrinsic/intrinsic.d.mts +9 -14
  34. package/build/import/type/intrinsic/intrinsic.mjs +10 -21
  35. package/build/import/type/intrinsic/lowercase.d.mts +4 -0
  36. package/build/import/type/intrinsic/lowercase.mjs +5 -0
  37. package/build/import/type/intrinsic/uncapitalize.d.mts +4 -0
  38. package/build/import/type/intrinsic/uncapitalize.mjs +5 -0
  39. package/build/import/type/intrinsic/uppercase.d.mts +4 -0
  40. package/build/import/type/intrinsic/uppercase.mjs +5 -0
  41. package/build/import/type/keyof/index.d.mts +1 -2
  42. package/build/import/type/keyof/index.mjs +1 -2
  43. package/build/import/type/keyof/{keyof-string.d.mts → keyof-property-keys.d.mts} +4 -4
  44. package/build/import/type/keyof/{keyof-string.mjs → keyof-property-keys.mjs} +4 -4
  45. package/build/import/type/keyof/keyof.d.mts +12 -4
  46. package/build/import/type/keyof/keyof.mjs +14 -3
  47. package/build/import/type/mapped/index.d.mts +2 -0
  48. package/build/import/type/mapped/index.mjs +2 -0
  49. package/build/import/type/mapped/mapped-key.d.mts +8 -0
  50. package/build/import/type/mapped/mapped-key.mjs +7 -0
  51. package/build/import/type/mapped/mapped-result.d.mts +9 -0
  52. package/build/import/type/mapped/mapped-result.mjs +7 -0
  53. package/build/import/type/mapped/mapped.d.mts +39 -23
  54. package/build/import/type/mapped/mapped.mjs +65 -11
  55. package/build/import/type/omit/index.d.mts +1 -0
  56. package/build/import/type/omit/index.mjs +1 -0
  57. package/build/import/type/omit/omit-mapped-result.d.mts +15 -0
  58. package/build/import/type/omit/omit-mapped-result.mjs +20 -0
  59. package/build/import/type/omit/omit.d.mts +5 -2
  60. package/build/import/type/omit/omit.mjs +12 -6
  61. package/build/import/type/pick/index.d.mts +1 -0
  62. package/build/import/type/pick/index.mjs +1 -0
  63. package/build/import/type/pick/pick-mapped-result.d.mts +15 -0
  64. package/build/import/type/pick/pick-mapped-result.mjs +20 -0
  65. package/build/import/type/pick/pick.d.mts +5 -2
  66. package/build/import/type/pick/pick.mjs +12 -6
  67. package/build/import/type/record/record.mjs +4 -4
  68. package/build/import/type/type/json.d.mts +17 -8
  69. package/build/import/type/type/json.mjs +6 -2
  70. package/build/import/value/check/check.mjs +3 -3
  71. package/build/import/value/clean/clean.mjs +2 -2
  72. package/build/import/value/transform/decode.mjs +5 -5
  73. package/build/import/value/transform/encode.mjs +5 -5
  74. package/build/require/compiler/compiler.js +2 -2
  75. package/build/require/errors/errors.js +2 -2
  76. package/build/require/index.d.ts +6 -6
  77. package/build/require/index.js +9 -8
  78. package/build/require/type/composite/composite.d.ts +2 -2
  79. package/build/require/type/composite/composite.js +1 -1
  80. package/build/require/type/extends/extends-mapped-result-from-result.d.ts +13 -0
  81. package/build/require/type/extends/extends-mapped-result-from-result.js +18 -0
  82. package/build/require/type/extends/extends-mapped-result.d.ts +17 -0
  83. package/build/require/type/extends/extends-mapped-result.js +25 -0
  84. package/build/require/type/extends/extends.d.ts +8 -2
  85. package/build/require/type/extends/extends.js +8 -5
  86. package/build/require/type/extends/index.d.ts +2 -0
  87. package/build/require/type/extends/index.js +2 -0
  88. package/build/require/type/guard/type.d.ts +5 -1
  89. package/build/require/type/guard/type.js +53 -34
  90. package/build/require/type/indexed/index.d.ts +3 -2
  91. package/build/require/type/indexed/index.js +3 -2
  92. package/build/require/type/indexed/indexed-mapped-result.d.ts +16 -0
  93. package/build/require/type/indexed/indexed-mapped-result.js +22 -0
  94. package/build/require/type/indexed/{indexed-key.d.ts → indexed-property-keys.d.ts} +3 -3
  95. package/build/require/type/indexed/{indexed-key.js → indexed-property-keys.js} +4 -4
  96. package/build/require/type/indexed/{indexed-type.d.ts → indexed-result.d.ts} +2 -2
  97. package/build/require/type/indexed/{indexed-type.js → indexed-result.js} +3 -3
  98. package/build/require/type/indexed/indexed.d.ts +7 -4
  99. package/build/require/type/indexed/indexed.js +8 -7
  100. package/build/require/type/intrinsic/capitalize.d.ts +4 -0
  101. package/build/require/type/intrinsic/capitalize.js +9 -0
  102. package/build/require/type/intrinsic/index.d.ts +5 -0
  103. package/build/require/type/intrinsic/index.js +5 -0
  104. package/build/require/type/intrinsic/intrinsic-mapped-result.d.ts +15 -0
  105. package/build/require/type/intrinsic/intrinsic-mapped-result.js +25 -0
  106. package/build/require/type/intrinsic/intrinsic.d.ts +9 -14
  107. package/build/require/type/intrinsic/intrinsic.js +10 -25
  108. package/build/require/type/intrinsic/lowercase.d.ts +4 -0
  109. package/build/require/type/intrinsic/lowercase.js +9 -0
  110. package/build/require/type/intrinsic/uncapitalize.d.ts +4 -0
  111. package/build/require/type/intrinsic/uncapitalize.js +9 -0
  112. package/build/require/type/intrinsic/uppercase.d.ts +4 -0
  113. package/build/require/type/intrinsic/uppercase.js +9 -0
  114. package/build/require/type/keyof/index.d.ts +1 -2
  115. package/build/require/type/keyof/index.js +1 -2
  116. package/build/require/type/keyof/{keyof-string.d.ts → keyof-property-keys.d.ts} +4 -4
  117. package/build/require/type/keyof/{keyof-string.js → keyof-property-keys.js} +7 -7
  118. package/build/require/type/keyof/keyof.d.ts +12 -4
  119. package/build/require/type/keyof/keyof.js +14 -3
  120. package/build/require/type/mapped/index.d.ts +2 -0
  121. package/build/require/type/mapped/index.js +2 -0
  122. package/build/require/type/mapped/mapped-key.d.ts +8 -0
  123. package/build/require/type/mapped/mapped-key.js +11 -0
  124. package/build/require/type/mapped/mapped-result.d.ts +9 -0
  125. package/build/require/type/mapped/mapped-result.js +11 -0
  126. package/build/require/type/mapped/mapped.d.ts +39 -23
  127. package/build/require/type/mapped/mapped.js +65 -11
  128. package/build/require/type/omit/index.d.ts +1 -0
  129. package/build/require/type/omit/index.js +1 -0
  130. package/build/require/type/omit/omit-mapped-result.d.ts +15 -0
  131. package/build/require/type/omit/omit-mapped-result.js +24 -0
  132. package/build/require/type/omit/omit.d.ts +5 -2
  133. package/build/require/type/omit/omit.js +10 -4
  134. package/build/require/type/pick/index.d.ts +1 -0
  135. package/build/require/type/pick/index.js +1 -0
  136. package/build/require/type/pick/pick-mapped-result.d.ts +15 -0
  137. package/build/require/type/pick/pick-mapped-result.js +24 -0
  138. package/build/require/type/pick/pick.d.ts +5 -2
  139. package/build/require/type/pick/pick.js +10 -4
  140. package/build/require/type/record/record.js +2 -2
  141. package/build/require/type/type/json.d.ts +17 -8
  142. package/build/require/type/type/json.js +54 -50
  143. package/build/require/value/check/check.js +2 -2
  144. package/build/require/value/clean/clean.js +15 -15
  145. package/build/require/value/transform/decode.js +3 -3
  146. package/build/require/value/transform/encode.js +3 -3
  147. package/package.json +1 -1
  148. package/readme.md +115 -47
  149. package/build/import/type/keyof/keyof-type.d.mts +0 -11
  150. package/build/import/type/keyof/keyof-type.mjs +0 -15
  151. package/build/require/type/keyof/keyof-type.d.ts +0 -11
  152. package/build/require/type/keyof/keyof-type.js +0 -19
@@ -1,8 +1,8 @@
1
1
  import { TemplateLiteral, TemplateLiteralParseExact, IsTemplateLiteralFinite, TemplateLiteralGenerate } from '../template-literal/index.mjs';
2
+ import { IntrinsicMappedResult } from './intrinsic-mapped-result.mjs';
2
3
  import { Literal } from '../literal/index.mjs';
3
4
  import { Union } from '../union/index.mjs';
4
- import { TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, TLiteral as IsLiteralType } from '../guard/type.mjs';
5
- import { CloneType } from '../clone/type.mjs';
5
+ import { TMappedKey as IsMappedKeyType, TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, TLiteral as IsLiteralType } from '../guard/type.mjs';
6
6
  function ApplyUncapitalize(value) {
7
7
  const [first, rest] = [value.slice(0, 1), value.slice(1)];
8
8
  return [first.toLowerCase(), rest].join('');
@@ -37,23 +37,12 @@ function FromLiteralValue(value, mode) {
37
37
  }
38
38
  function FromRest(T, mode) {
39
39
  const [L, ...R] = T;
40
- return (T.length > 0 ? [IntrinsicResolve(L, mode), ...FromRest(R, mode)] : []);
41
- }
42
- export function IntrinsicResolve(schema, mode) {
43
- return (IsTemplateLiteralType(schema) ? FromTemplateLiteral(schema, mode) :
44
- IsUnionType(schema) ? Union(FromRest(schema.anyOf, mode)) :
45
- IsLiteralType(schema) ? Literal(FromLiteralValue(schema.const, mode)) :
46
- schema);
47
- }
48
- export function Uncapitalize(T, options = {}) {
49
- return CloneType(IntrinsicResolve(T, 'Uncapitalize'), options);
50
- }
51
- export function Uppercase(T, options = {}) {
52
- return CloneType(IntrinsicResolve(T, 'Uppercase'), options);
53
- }
54
- export function Lowercase(T, options = {}) {
55
- return CloneType(IntrinsicResolve(T, 'Lowercase'), options);
56
- }
57
- export function Capitalize(T, options = {}) {
58
- return CloneType(IntrinsicResolve(T, 'Capitalize'), options);
40
+ return (T.length > 0 ? [Intrinsic(L, mode), ...FromRest(R, mode)] : []);
41
+ }
42
+ export function Intrinsic(schema, mode) {
43
+ return (IsMappedKeyType(schema) ? IntrinsicMappedResult(schema, mode) :
44
+ IsTemplateLiteralType(schema) ? FromTemplateLiteral(schema, mode) :
45
+ IsUnionType(schema) ? Union(FromRest(schema.anyOf, mode)) :
46
+ IsLiteralType(schema) ? Literal(FromLiteralValue(schema.const, mode)) :
47
+ schema);
59
48
  }
@@ -0,0 +1,4 @@
1
+ import { TSchema, SchemaOptions } from '../schema/index.mjs';
2
+ import { TIntrinsic } from './intrinsic.mjs';
3
+ export type TLowercase<T extends TSchema> = TIntrinsic<T, 'Lowercase'>;
4
+ export declare function Lowercase<T extends TSchema>(T: T, options?: SchemaOptions): TLowercase<T>;
@@ -0,0 +1,5 @@
1
+ import { Intrinsic } from './intrinsic.mjs';
2
+ import { CloneType } from '../clone/type.mjs';
3
+ export function Lowercase(T, options = {}) {
4
+ return CloneType(Intrinsic(T, 'Lowercase'), options);
5
+ }
@@ -0,0 +1,4 @@
1
+ import { TSchema, SchemaOptions } from '../schema/index.mjs';
2
+ import { TIntrinsic } from './intrinsic.mjs';
3
+ export type TUncapitalize<T extends TSchema> = TIntrinsic<T, 'Uncapitalize'>;
4
+ export declare function Uncapitalize<T extends TSchema>(T: T, options?: SchemaOptions): TUncapitalize<T>;
@@ -0,0 +1,5 @@
1
+ import { Intrinsic } from './intrinsic.mjs';
2
+ import { CloneType } from '../clone/type.mjs';
3
+ export function Uncapitalize(T, options = {}) {
4
+ return CloneType(Intrinsic(T, 'Uncapitalize'), options);
5
+ }
@@ -0,0 +1,4 @@
1
+ import { TSchema, SchemaOptions } from '../schema/index.mjs';
2
+ import { TIntrinsic } from './intrinsic.mjs';
3
+ export type TUppercase<T extends TSchema> = TIntrinsic<T, 'Uppercase'>;
4
+ export declare function Uppercase<T extends TSchema>(T: T, options?: SchemaOptions): TUppercase<T>;
@@ -0,0 +1,5 @@
1
+ import { Intrinsic } from './intrinsic.mjs';
2
+ import { CloneType } from '../clone/type.mjs';
3
+ export function Uppercase(T, options = {}) {
4
+ return CloneType(Intrinsic(T, 'Uppercase'), options);
5
+ }
@@ -1,3 +1,2 @@
1
- export * from './keyof-string.mjs';
2
- export * from './keyof-type.mjs';
1
+ export * from './keyof-property-keys.mjs';
3
2
  export * from './keyof.mjs';
@@ -1,3 +1,2 @@
1
- export * from './keyof-string.mjs';
2
- export * from './keyof-type.mjs';
1
+ export * from './keyof-property-keys.mjs';
3
2
  export * from './keyof.mjs';
@@ -7,7 +7,7 @@ import type { TTuple } from '../tuple/index.mjs';
7
7
  import type { TArray } from '../array/index.mjs';
8
8
  import type { TObject, TProperties } from '../object/index.mjs';
9
9
  import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs';
10
- type FromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [KeyOfStringResolve<L>, ...FromRest<R>] : []);
10
+ type FromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [KeyOfPropertyKeys<L>, ...FromRest<R>] : []);
11
11
  declare function FromRest<T extends TSchema[]>(T: [...T]): FromRest<T>;
12
12
  type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = FromRest<T>> = (OperatorUnionMany<C>);
13
13
  declare function FromIntersect<T extends TSchema[]>(T: [...T], C?: FromRest<T>): FromIntersect<T>;
@@ -21,8 +21,8 @@ type FromArray<_ extends TSchema> = ([
21
21
  declare function FromArray<_ extends TSchema>(_: _): FromArray<_>;
22
22
  type FromProperties<T extends TProperties> = (UnionToTuple<keyof T>);
23
23
  declare function FromProperties<T extends TProperties>(T: T): FromProperties<T>;
24
- export type KeyOfStringResolve<T extends TSchema> = (T extends TRecursive<infer S> ? KeyOfStringResolve<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> : [
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> : [
25
25
  ]);
26
- export declare function KeyOfStringResolve<T extends TSchema>(T: T): KeyOfStringResolve<T>;
27
- export declare function KeyOfStringResolvePattern(schema: TSchema): string;
26
+ export declare function KeyOfPropertyKeys<T extends TSchema>(T: T): KeyOfPropertyKeys<T>;
27
+ export declare function KeyOfPattern(schema: TSchema): string;
28
28
  export {};
@@ -4,7 +4,7 @@ import { TIntersect as IsIntersectType, TUnion as IsUnionType, TTuple as IsTuple
4
4
  function FromRest(T) {
5
5
  const [L, ...R] = T;
6
6
  return (T.length > 0
7
- ? [KeyOfStringResolve(L), ...FromRest(R)]
7
+ ? [KeyOfPropertyKeys(L), ...FromRest(R)]
8
8
  : []);
9
9
  }
10
10
  function FromIntersect(T, C = FromRest(T)) {
@@ -36,7 +36,7 @@ function FromPatternProperties(patternProperties) {
36
36
  : key;
37
37
  });
38
38
  }
39
- export function KeyOfStringResolve(T) {
39
+ export function KeyOfPropertyKeys(T) {
40
40
  return (IsIntersectType(T) ? FromIntersect(T.allOf) :
41
41
  IsUnionType(T) ? FromUnion(T.anyOf) :
42
42
  IsTupleType(T) ? FromTuple(T.items ?? []) :
@@ -46,9 +46,9 @@ export function KeyOfStringResolve(T) {
46
46
  []);
47
47
  }
48
48
  let includePatternProperties = false;
49
- export function KeyOfStringResolvePattern(schema) {
49
+ export function KeyOfPattern(schema) {
50
50
  includePatternProperties = true;
51
- const keys = KeyOfStringResolve(schema);
51
+ const keys = KeyOfPropertyKeys(schema);
52
52
  includePatternProperties = false;
53
53
  const pattern = keys.map((key) => `(${key})`);
54
54
  return `^(${pattern.join('|')})$`;
@@ -1,4 +1,12 @@
1
- import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
- import { KeyOfTypeResolve } from './keyof-type.mjs';
3
- export type TKeyOf<T extends TSchema> = KeyOfTypeResolve<T>;
4
- export declare function KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): KeyOfTypeResolve<T>;
1
+ import type { TSchema } from '../schema/index.mjs';
2
+ import type { Ensure } from '../helpers/index.mjs';
3
+ import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
4
+ import { type TNumber } from '../number/index.mjs';
5
+ import { type SchemaOptions } from '../schema/index.mjs';
6
+ import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
7
+ import { UnionResolve } from '../union/index.mjs';
8
+ 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>] : []);
9
+ declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
10
+ export type TKeyOf<T extends TSchema> = (Ensure<UnionResolve<FromLiterals<KeyOfPropertyKeys<T>>>>);
11
+ export declare function KeyOf<T extends TSchema>(T: T, options?: SchemaOptions): TKeyOf<T>;
12
+ export {};
@@ -1,6 +1,17 @@
1
- import { KeyOfTypeResolve } from './keyof-type.mjs';
1
+ import { Literal } from '../literal/index.mjs';
2
+ import { Number } from '../number/index.mjs';
3
+ import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
4
+ import { UnionResolve } from '../union/index.mjs';
2
5
  import { CloneType } from '../clone/type.mjs';
3
- export function KeyOf(schema, options = {}) {
4
- const K = KeyOfTypeResolve(schema);
6
+ function FromLiterals(T) {
7
+ const [L, ...R] = T;
8
+ return (T.length > 0
9
+ ? L === '[number]'
10
+ ? [Number(), ...FromLiterals(R)]
11
+ : [Literal(L), ...FromLiterals(R)]
12
+ : []);
13
+ }
14
+ export function KeyOf(T, options = {}) {
15
+ const K = UnionResolve(FromLiterals(KeyOfPropertyKeys(T)));
5
16
  return CloneType(K, options);
6
17
  }
@@ -1 +1,3 @@
1
+ export * from './mapped-key.mjs';
2
+ export * from './mapped-result.mjs';
1
3
  export * from './mapped.mjs';
@@ -1 +1,3 @@
1
+ export * from './mapped-key.mjs';
2
+ export * from './mapped-result.mjs';
1
3
  export * from './mapped.mjs';
@@ -0,0 +1,8 @@
1
+ import type { TSchema } from '../schema/index.mjs';
2
+ import { Kind } from '../symbols/index.mjs';
3
+ export interface TMappedKey<T extends PropertyKey[] = PropertyKey[]> extends TSchema {
4
+ [Kind]: 'MappedKey';
5
+ static: T[number];
6
+ keys: T;
7
+ }
8
+ export declare function MappedKey<T extends PropertyKey[]>(T: [...T]): TMappedKey<T>;
@@ -0,0 +1,7 @@
1
+ import { Kind } from '../symbols/index.mjs';
2
+ export function MappedKey(T) {
3
+ return {
4
+ [Kind]: 'MappedKey',
5
+ keys: T
6
+ };
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { TSchema } from '../schema/index.mjs';
2
+ import type { TProperties } from '../object/index.mjs';
3
+ import { Kind } from '../symbols/index.mjs';
4
+ export interface TMappedResult<T extends TProperties = TProperties> extends TSchema {
5
+ [Kind]: 'MappedResult';
6
+ properties: T;
7
+ static: unknown;
8
+ }
9
+ export declare function MappedResult<T extends TProperties>(properties: T): TMappedResult<T>;
@@ -0,0 +1,7 @@
1
+ import { Kind } from '../symbols/index.mjs';
2
+ export function MappedResult(properties) {
3
+ return {
4
+ [Kind]: 'MappedResult',
5
+ properties
6
+ };
7
+ }
@@ -1,24 +1,40 @@
1
1
  import type { TSchema } from '../schema/index.mjs';
2
- import type { Evaluate } from '../helpers/index.mjs';
3
- import type { Static } from '../static/index.mjs';
4
- import { type TObject, type TProperties } from '../object/index.mjs';
5
- import { IndexedKeyResolve } from '../indexed/indexed-key.mjs';
6
- import { Kind } from '../symbols/index.mjs';
7
- export interface TMappedKey<T extends PropertyKey[] = PropertyKey[]> extends TSchema {
8
- [Kind]: 'MappedKey';
9
- static: T[number];
10
- anyOf: [];
11
- }
12
- export type MappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
13
- export type MappedResultProperties<K extends PropertyKey[], T extends TSchema> = K extends [infer L extends string, ...infer R extends PropertyKey[]] ? {
14
- [_ in `${L}`]: T;
15
- } & MappedResultProperties<R, T> : {};
16
- export type UnevaluatedMappedResult<T extends TSchema> = T;
17
- export type EvaluatedMappedResult<K extends PropertyKey[], T extends TSchema> = T;
18
- export interface TMappedResult<K extends PropertyKey[], F extends MappedFunction<K>, S extends TSchema = ReturnType<F>, R extends TSchema = EvaluatedMappedResult<K, S>, P extends TProperties = Evaluate<MappedResultProperties<K, R>>, O extends TObject = TObject<P>> extends TSchema {
19
- [Kind]: 'MappedResult';
20
- static: Static<O, this['params']>;
21
- properties: P;
22
- }
23
- export declare function Mapped<K extends TSchema, I extends PropertyKey[] = IndexedKeyResolve<K>, F extends MappedFunction<I> = MappedFunction<I>, R extends TMappedResult<I, F> = TMappedResult<I, F>>(key: K, map: F): R;
24
- export declare function Mapped<K extends PropertyKey[], F extends MappedFunction<K> = MappedFunction<K>, R extends TMappedResult<K, F> = TMappedResult<K, F>>(key: [...K], map: F): R;
2
+ import type { Ensure, Evaluate } from '../helpers/index.mjs';
3
+ import { type TArray } from '../array/index.mjs';
4
+ import { type TAsyncIterator } from '../async-iterator/index.mjs';
5
+ import { type TConstructor } from '../constructor/index.mjs';
6
+ import { type TFunction } from '../function/index.mjs';
7
+ import { type TIndexPropertyKeys } from '../indexed/index.mjs';
8
+ import { type TIntersect } from '../intersect/index.mjs';
9
+ import { type TIterator } from '../iterator/index.mjs';
10
+ import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
11
+ import { type TNever } from '../never/index.mjs';
12
+ import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
13
+ import { type TOptional } from '../optional/index.mjs';
14
+ import { type TPromise } from '../promise/index.mjs';
15
+ import { type TReadonly } from '../readonly/index.mjs';
16
+ import { type TTuple } from '../tuple/index.mjs';
17
+ import { type TUnion } from '../union/index.mjs';
18
+ import type { TMappedResult } from './mapped-result.mjs';
19
+ import type { TMappedKey } from './mapped-key.mjs';
20
+ type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TNever);
21
+ declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
22
+ type FromMappedKey<K extends PropertyKey, _ extends PropertyKey[]> = (K extends TLiteralValue ? TLiteral<K> : TLiteral<'never'>);
23
+ declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, _: [...P]): TLiteral<TLiteralValue>;
24
+ type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
25
+ declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
26
+ type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
27
+ [K2 in keyof T]: FromSchemaType<K, T[K2]>;
28
+ }>> = R;
29
+ declare function FromProperties<K extends PropertyKey, T extends TProperties>(K: K, T: T): FromProperties<K, T>;
30
+ 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);
31
+ declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K, T: T): FromSchemaType<K, T>;
32
+ type FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
33
+ [_ in L]: FromSchemaType<L, T>;
34
+ } & FromMappedFunctionReturnType<R, T> : {});
35
+ declare function FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): FromMappedFunctionReturnType<K, T>;
36
+ export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
37
+ export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<FromMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
38
+ export declare function Mapped<K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>, F extends TMappedFunction<I> = TMappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
39
+ export declare function Mapped<K extends PropertyKey[], F extends TMappedFunction<K> = TMappedFunction<K>, R extends TMapped<K, F> = TMapped<K, F>>(key: [...K], map: F, options?: ObjectOptions): R;
40
+ export {};
@@ -1,14 +1,68 @@
1
- import { Object } from '../object/index.mjs';
2
- import { Literal } from '../literal/index.mjs';
3
- import { IndexedKeyResolve } from '../indexed/indexed-key.mjs';
4
1
  import { TSchema as IsSchemaType } from '../guard/type.mjs';
5
- import { Kind } from '../symbols/index.mjs';
6
- export function Mapped(key, map) {
7
- const keys = IsSchemaType(key) ? IndexedKeyResolve(key) : key;
8
- const anyOf = keys.map(key => Literal(key));
9
- const mapped = { [Kind]: 'MappedKey', anyOf };
10
- const properties = keys.reduce((acc, key) => {
11
- return { ...acc, [key]: map(mapped) };
2
+ import { Kind, OptionalKind, ReadonlyKind } from '../symbols/index.mjs';
3
+ import { CloneType } from '../clone/type.mjs';
4
+ import { Discard } from '../discard/index.mjs';
5
+ import { Array } from '../array/index.mjs';
6
+ import { AsyncIterator } from '../async-iterator/index.mjs';
7
+ import { Constructor } from '../constructor/index.mjs';
8
+ import { Function as FunctionType } from '../function/index.mjs';
9
+ import { IndexPropertyKeys } from '../indexed/index.mjs';
10
+ import { Intersect } from '../intersect/index.mjs';
11
+ import { Iterator } from '../iterator/index.mjs';
12
+ import { Literal } from '../literal/index.mjs';
13
+ import { Never } from '../never/index.mjs';
14
+ import { Object } from '../object/index.mjs';
15
+ import { Optional } from '../optional/index.mjs';
16
+ import { Promise } from '../promise/index.mjs';
17
+ import { Readonly } from '../readonly/index.mjs';
18
+ import { Tuple } from '../tuple/index.mjs';
19
+ import { Union } from '../union/index.mjs';
20
+ import { TArray as IsArrayType, TAsyncIterator as IsAsyncIteratorType, TConstructor as IsConstructorType, TFunction as IsFunctionType, TIntersect as IsIntersectType, TIterator as IsIteratorType, TReadonly as IsReadonlyType, TMappedResult as IsMappedResultType, TMappedKey as IsMappedKeyType, TObject as IsObjectType, TOptional as IsOptionalType, TPromise as IsPromiseType, TTuple as IsTupleType, TUnion as IsUnionType, } from '../guard/type.mjs';
21
+ function FromMappedResult(K, P) {
22
+ return (K in P
23
+ ? FromSchemaType(K, P[K])
24
+ : Never());
25
+ }
26
+ function FromMappedKey(K, _) {
27
+ return Literal(K);
28
+ }
29
+ function FromRest(K, T) {
30
+ const [L, ...R] = T;
31
+ return (T.length > 0
32
+ ? [FromSchemaType(K, L), ...FromRest(K, R)]
33
+ : []);
34
+ }
35
+ function FromProperties(K, T) {
36
+ return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K2) => {
37
+ return { ...Acc, [K2]: FromSchemaType(K, T[K2]) };
12
38
  }, {});
13
- return Object(properties);
39
+ }
40
+ function FromSchemaType(K, T) {
41
+ return (IsOptionalType(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) :
42
+ IsReadonlyType(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) :
43
+ IsMappedResultType(T) ? FromMappedResult(K, T.properties) :
44
+ IsMappedKeyType(T) ? FromMappedKey(K, T.keys) :
45
+ IsConstructorType(T) ? Constructor(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
46
+ IsFunctionType(T) ? FunctionType(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
47
+ IsAsyncIteratorType(T) ? AsyncIterator(FromSchemaType(K, T.items)) :
48
+ IsIteratorType(T) ? Iterator(FromSchemaType(K, T.items)) :
49
+ IsIntersectType(T) ? Intersect(FromRest(K, T.allOf)) :
50
+ IsUnionType(T) ? Union(FromRest(K, T.anyOf)) :
51
+ IsTupleType(T) ? Tuple(FromRest(K, T.items ?? [])) :
52
+ IsObjectType(T) ? Object(FromProperties(K, T.properties)) :
53
+ IsArrayType(T) ? Array(FromSchemaType(K, T.items)) :
54
+ IsPromiseType(T) ? Promise(FromSchemaType(K, T.item)) :
55
+ T);
56
+ }
57
+ function FromMappedFunctionReturnType(K, T) {
58
+ const [L, ...R] = K;
59
+ return (K.length > 0
60
+ ? { [L]: FromSchemaType(L, T), ...FromMappedFunctionReturnType(R, T) }
61
+ : {});
62
+ }
63
+ export function Mapped(key, map, options = {}) {
64
+ const K = IsSchemaType(key) ? IndexPropertyKeys(key) : key;
65
+ const RT = map({ [Kind]: 'MappedKey', keys: K });
66
+ const R = FromMappedFunctionReturnType(K, RT);
67
+ return CloneType(Object(R), options);
14
68
  }
@@ -1 +1,2 @@
1
+ export * from './omit-mapped-result.mjs';
1
2
  export * from './omit.mjs';
@@ -1 +1,2 @@
1
+ export * from './omit-mapped-result.mjs';
1
2
  export * from './omit.mjs';
@@ -0,0 +1,15 @@
1
+ import type { TSchema } from '../schema/index.mjs';
2
+ import type { TProperties } from '../object/index.mjs';
3
+ import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
4
+ import { type TOmit } from './omit.mjs';
5
+ type MappedOmitPropertyKey<T extends TSchema, K extends PropertyKey> = {
6
+ [_ in K]: TOmit<T, [K]>;
7
+ };
8
+ declare function MappedOmitPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): MappedOmitPropertyKey<T, K>;
9
+ type MappedOmitPropertyKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? MappedOmitPropertyKey<T, LK> & MappedOmitPropertyKeys<T, RK> : {});
10
+ declare function MappedOmitPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): MappedOmitPropertyKeys<T, K>;
11
+ type MappedOmitProperties<T extends TSchema, K extends TMappedKey> = (MappedOmitPropertyKeys<T, K['keys']>);
12
+ declare function MappedOmitProperties<T extends TSchema, K extends TMappedKey>(T: T, K: K): MappedOmitProperties<T, K>;
13
+ export type TOmitMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedOmitProperties<T, K>> = (TMappedResult<P>);
14
+ export declare function OmitMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedOmitProperties<T, K>>(T: T, K: K): TMappedResult<P>;
15
+ export {};
@@ -0,0 +1,20 @@
1
+ import { MappedResult } from '../mapped/index.mjs';
2
+ import { Omit } from './omit.mjs';
3
+ function MappedOmitPropertyKey(T, K) {
4
+ return {
5
+ [K]: Omit(T, [K])
6
+ };
7
+ }
8
+ function MappedOmitPropertyKeys(T, K) {
9
+ const [LK, ...RK] = K;
10
+ return (K.length > 0
11
+ ? { ...MappedOmitPropertyKey(T, LK), ...MappedOmitPropertyKeys(T, RK) }
12
+ : {});
13
+ }
14
+ function MappedOmitProperties(T, K) {
15
+ return MappedOmitPropertyKeys(T, K.keys);
16
+ }
17
+ export function OmitMappedResult(T, K) {
18
+ const P = MappedOmitProperties(T, K);
19
+ return MappedResult(P);
20
+ }
@@ -4,7 +4,9 @@ import { type TRecursive } from '../recursive/index.mjs';
4
4
  import { type TIntersect } from '../intersect/index.mjs';
5
5
  import { type TUnion } from '../union/index.mjs';
6
6
  import { type TObject, type TProperties } from '../object/index.mjs';
7
- import { IndexedKeyResolve } from '../indexed/index.mjs';
7
+ import { type TIndexPropertyKeys } from '../indexed/index.mjs';
8
+ import { TMappedKey } from '../mapped/index.mjs';
9
+ import { type TOmitMappedResult } from './omit-mapped-result.mjs';
8
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>] : [];
9
11
  declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
10
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>] : [];
@@ -14,6 +16,7 @@ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(
14
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<{}>;
15
17
  export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): OmitResolve<T, K>;
16
18
  export type TOmit<T extends TSchema, K extends PropertyKey[]> = OmitResolve<T, K>;
17
- export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedKeyResolve<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
19
+ export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K): TOmitMappedResult<T, K>;
20
+ export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
18
21
  export declare function Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
19
22
  export {};
@@ -1,11 +1,12 @@
1
1
  import { Intersect } from '../intersect/index.mjs';
2
2
  import { Union } from '../union/index.mjs';
3
3
  import { Object } from '../object/index.mjs';
4
- import { IndexedKeyResolve } from '../indexed/index.mjs';
4
+ import { IndexPropertyKeys } from '../indexed/index.mjs';
5
5
  import { Discard } from '../discard/index.mjs';
6
6
  import { TransformKind } from '../symbols/index.mjs';
7
7
  import { CloneType } from '../clone/type.mjs';
8
- import { TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
8
+ import { OmitMappedResult } from './omit-mapped-result.mjs';
9
+ import { TMappedKey as IsMappedKeyType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
9
10
  function FromIntersect(T, K) {
10
11
  return T.map((T) => OmitResolve(T, K));
11
12
  }
@@ -28,8 +29,13 @@ export function OmitResolve(T, K) {
28
29
  Object({}));
29
30
  }
30
31
  export function Omit(T, K, options = {}) {
31
- const I = IsSchemaType(K) ? IndexedKeyResolve(K) : K;
32
- const D = Discard(T, [TransformKind, '$id', 'required']);
33
- const R = CloneType(OmitResolve(T, I), options);
34
- return { ...D, ...R };
32
+ if (IsMappedKeyType(K)) {
33
+ return OmitMappedResult(T, K);
34
+ }
35
+ else {
36
+ const I = IsSchemaType(K) ? IndexPropertyKeys(K) : K;
37
+ const D = Discard(T, [TransformKind, '$id', 'required']);
38
+ const R = CloneType(OmitResolve(T, I), options);
39
+ return { ...D, ...R };
40
+ }
35
41
  }
@@ -1 +1,2 @@
1
+ export * from './pick-mapped-result.mjs';
1
2
  export * from './pick.mjs';
@@ -1 +1,2 @@
1
+ export * from './pick-mapped-result.mjs';
1
2
  export * from './pick.mjs';
@@ -0,0 +1,15 @@
1
+ import type { TSchema } from '../schema/index.mjs';
2
+ import type { TProperties } from '../object/index.mjs';
3
+ import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
4
+ import { type TPick } from './pick.mjs';
5
+ type MappedPickPropertyKey<T extends TSchema, K extends PropertyKey> = {
6
+ [_ in K]: TPick<T, [K]>;
7
+ };
8
+ declare function MappedPickPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): MappedPickPropertyKey<T, K>;
9
+ type MappedPickPropertyKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? MappedPickPropertyKey<T, LK> & MappedPickPropertyKeys<T, RK> : {});
10
+ declare function MappedPickPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): MappedPickPropertyKeys<T, K>;
11
+ type MappedPickProperties<T extends TSchema, K extends TMappedKey> = (MappedPickPropertyKeys<T, K['keys']>);
12
+ declare function MappedPickProperties<T extends TSchema, K extends TMappedKey>(T: T, K: K): MappedPickProperties<T, K>;
13
+ export type TPickMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedPickProperties<T, K>> = (TMappedResult<P>);
14
+ export declare function PickMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedPickProperties<T, K>>(T: T, K: K): TMappedResult<P>;
15
+ export {};
@@ -0,0 +1,20 @@
1
+ import { MappedResult } from '../mapped/index.mjs';
2
+ import { Pick } from './pick.mjs';
3
+ function MappedPickPropertyKey(T, K) {
4
+ return {
5
+ [K]: Pick(T, [K])
6
+ };
7
+ }
8
+ function MappedPickPropertyKeys(T, K) {
9
+ const [LK, ...RK] = K;
10
+ return (K.length > 0
11
+ ? { ...MappedPickPropertyKey(T, LK), ...MappedPickPropertyKeys(T, RK) }
12
+ : {});
13
+ }
14
+ function MappedPickProperties(T, K) {
15
+ return MappedPickPropertyKeys(T, K.keys);
16
+ }
17
+ export function PickMappedResult(T, K) {
18
+ const P = MappedPickProperties(T, K);
19
+ return MappedResult(P);
20
+ }
@@ -4,7 +4,9 @@ import { type TRecursive } from '../recursive/index.mjs';
4
4
  import { type TIntersect } from '../intersect/index.mjs';
5
5
  import { type TUnion } from '../union/index.mjs';
6
6
  import { type TObject, type TProperties } from '../object/index.mjs';
7
- import { IndexedKeyResolve } from '../indexed/index.mjs';
7
+ import { type TIndexPropertyKeys } from '../indexed/index.mjs';
8
+ import { TMappedKey } from '../mapped/index.mjs';
9
+ import { type TPickMappedResult } from './pick-mapped-result.mjs';
8
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>] : [];
9
11
  declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
10
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>] : [];
@@ -14,6 +16,7 @@ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(
14
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<{}>;
15
17
  export declare function PickResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): PickResolve<T, K>;
16
18
  export type TPick<T extends TSchema, K extends PropertyKey[]> = PickResolve<T, K>;
17
- export declare function Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedKeyResolve<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
19
+ export declare function Pick<T extends TSchema, K extends TMappedKey>(T: T, K: K): TPickMappedResult<T, K>;
20
+ export declare function Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
18
21
  export declare function Pick<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TPick<T, K>;
19
22
  export {};
@@ -1,11 +1,12 @@
1
1
  import { Intersect } from '../intersect/index.mjs';
2
2
  import { Union } from '../union/index.mjs';
3
3
  import { Object } from '../object/index.mjs';
4
- import { IndexedKeyResolve } from '../indexed/index.mjs';
4
+ import { IndexPropertyKeys } from '../indexed/index.mjs';
5
5
  import { Discard } from '../discard/index.mjs';
6
6
  import { TransformKind } from '../symbols/index.mjs';
7
7
  import { CloneType } from '../clone/type.mjs';
8
- import { TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
8
+ import { PickMappedResult } from './pick-mapped-result.mjs';
9
+ import { TMappedKey as IsMappedKeyType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType, } from '../guard/type.mjs';
9
10
  function FromIntersect(T, K) {
10
11
  return T.map((T) => PickResolve(T, K));
11
12
  }
@@ -24,8 +25,13 @@ export function PickResolve(T, K) {
24
25
  Object({}));
25
26
  }
26
27
  export function Pick(T, K, options = {}) {
27
- const I = IsSchemaType(K) ? IndexedKeyResolve(K) : K;
28
- const D = Discard(T, [TransformKind, '$id', 'required']);
29
- const R = CloneType(PickResolve(T, I), options);
30
- return { ...D, ...R };
28
+ if (IsMappedKeyType(K)) {
29
+ return PickMappedResult(T, K);
30
+ }
31
+ else {
32
+ const I = IsSchemaType(K) ? IndexPropertyKeys(K) : K;
33
+ const D = Discard(T, [TransformKind, '$id', 'required']);
34
+ const R = CloneType(PickResolve(T, I), options);
35
+ return { ...D, ...R };
36
+ }
31
37
  }