@sinclair/typebox 0.32.0-dev-13 → 0.32.0-dev-15
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.
- package/build/import/index.d.mts +10 -10
- package/build/import/index.mjs +3 -3
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +13 -0
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +14 -0
- package/build/import/type/exclude/exclude.d.mts +4 -1
- package/build/import/type/exclude/exclude.mjs +10 -4
- package/build/import/type/exclude/index.d.mts +1 -0
- package/build/import/type/exclude/index.mjs +1 -0
- package/build/import/type/extends/extends-from-mapped-key.d.mts +17 -0
- package/build/import/type/extends/extends-from-mapped-key.mjs +21 -0
- package/build/import/type/extends/extends-from-mapped-result.d.mts +13 -0
- package/build/import/type/extends/extends-from-mapped-result.mjs +14 -0
- package/build/import/type/extends/extends.d.mts +4 -4
- package/build/import/type/extends/extends.mjs +4 -4
- package/build/import/type/extends/index.d.mts +2 -2
- package/build/import/type/extends/index.mjs +2 -2
- package/build/import/type/extract/extract-from-mapped-result.d.mts +13 -0
- package/build/import/type/extract/extract-from-mapped-result.mjs +14 -0
- package/build/import/type/extract/extract.d.mts +3 -0
- package/build/import/type/extract/extract.mjs +9 -3
- package/build/import/type/extract/index.d.mts +1 -0
- package/build/import/type/extract/index.mjs +1 -0
- package/build/import/type/guard/type.d.mts +47 -46
- package/build/import/type/guard/type.mjs +294 -293
- package/build/import/type/indexed/index.d.mts +1 -1
- package/build/import/type/indexed/index.mjs +1 -1
- package/build/import/type/indexed/{indexed-mapped-result.d.mts → indexed-from-mapped-key.d.mts} +6 -6
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +18 -0
- package/build/import/type/indexed/indexed-result.d.mts +2 -2
- package/build/import/type/indexed/indexed-result.mjs +3 -2
- package/build/import/type/indexed/indexed.d.mts +2 -2
- package/build/import/type/indexed/indexed.mjs +4 -4
- package/build/import/type/intrinsic/capitalize.mjs +1 -2
- package/build/import/type/intrinsic/index.d.mts +1 -1
- package/build/import/type/intrinsic/index.mjs +1 -1
- package/build/import/type/intrinsic/{intrinsic-mapped-result.d.mts → intrinsic-from-mapped-key.d.mts} +6 -5
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +21 -0
- package/build/import/type/intrinsic/intrinsic.d.mts +6 -6
- package/build/import/type/intrinsic/intrinsic.mjs +8 -8
- package/build/import/type/intrinsic/lowercase.mjs +1 -2
- package/build/import/type/intrinsic/uncapitalize.mjs +1 -2
- package/build/import/type/intrinsic/uppercase.mjs +1 -2
- package/build/import/type/keyof/index.d.mts +1 -0
- package/build/import/type/keyof/index.mjs +1 -0
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +13 -0
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +14 -0
- package/build/import/type/keyof/keyof.d.mts +3 -0
- package/build/import/type/keyof/keyof.mjs +9 -2
- package/build/import/type/mapped/mapped.d.mts +9 -6
- package/build/import/type/mapped/mapped.mjs +11 -4
- package/build/import/type/omit/index.d.mts +1 -1
- package/build/import/type/omit/index.mjs +1 -1
- package/build/import/type/omit/omit-from-mapped-key.d.mts +15 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +20 -0
- package/build/import/type/omit/omit.d.mts +2 -2
- package/build/import/type/omit/omit.mjs +2 -2
- package/build/import/type/partial/index.d.mts +1 -0
- package/build/import/type/partial/index.mjs +1 -0
- package/build/import/type/partial/partial-from-mapped-result.d.mts +13 -0
- package/build/import/type/partial/partial-from-mapped-result.mjs +14 -0
- package/build/import/type/partial/partial.d.mts +5 -2
- package/build/import/type/partial/partial.mjs +11 -5
- package/build/import/type/pick/index.d.mts +1 -1
- package/build/import/type/pick/index.mjs +1 -1
- package/build/import/type/pick/pick-from-mapped-key.d.mts +15 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +20 -0
- package/build/import/type/pick/pick.d.mts +2 -2
- package/build/import/type/pick/pick.mjs +2 -2
- package/build/import/type/required/index.d.mts +1 -0
- package/build/import/type/required/index.mjs +1 -0
- package/build/import/type/required/required-from-mapped-result.d.mts +13 -0
- package/build/import/type/required/required-from-mapped-result.mjs +14 -0
- package/build/import/type/required/required.d.mts +5 -2
- package/build/import/type/required/required.mjs +11 -5
- package/build/import/type/type/json.d.mts +21 -16
- package/build/import/type/type/json.mjs +3 -3
- package/build/require/index.d.ts +10 -10
- package/build/require/index.js +5 -3
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +13 -0
- package/build/require/type/exclude/exclude-from-mapped-result.js +18 -0
- package/build/require/type/exclude/exclude.d.ts +4 -1
- package/build/require/type/exclude/exclude.js +9 -4
- package/build/require/type/exclude/index.d.ts +1 -0
- package/build/require/type/exclude/index.js +1 -0
- package/build/require/type/extends/extends-from-mapped-key.d.ts +17 -0
- package/build/require/type/extends/extends-from-mapped-key.js +25 -0
- package/build/require/type/extends/extends-from-mapped-result.d.ts +13 -0
- package/build/require/type/extends/extends-from-mapped-result.js +18 -0
- package/build/require/type/extends/extends.d.ts +4 -4
- package/build/require/type/extends/extends.js +4 -4
- package/build/require/type/extends/index.d.ts +2 -2
- package/build/require/type/extends/index.js +2 -2
- package/build/require/type/extract/extract-from-mapped-result.d.ts +13 -0
- package/build/require/type/extract/extract-from-mapped-result.js +18 -0
- package/build/require/type/extract/extract.d.ts +3 -0
- package/build/require/type/extract/extract.js +8 -2
- package/build/require/type/extract/index.d.ts +1 -0
- package/build/require/type/extract/index.js +1 -0
- package/build/require/type/guard/type.d.ts +47 -46
- package/build/require/type/guard/type.js +252 -250
- package/build/require/type/indexed/index.d.ts +1 -1
- package/build/require/type/indexed/index.js +1 -1
- package/build/require/type/indexed/{indexed-mapped-result.d.ts → indexed-from-mapped-key.d.ts} +6 -6
- package/build/require/type/indexed/indexed-from-mapped-key.js +22 -0
- package/build/require/type/indexed/indexed-result.d.ts +2 -2
- package/build/require/type/indexed/indexed-result.js +11 -10
- package/build/require/type/indexed/indexed.d.ts +2 -2
- package/build/require/type/indexed/indexed.js +4 -4
- package/build/require/type/intrinsic/capitalize.js +1 -2
- package/build/require/type/intrinsic/index.d.ts +1 -1
- package/build/require/type/intrinsic/index.js +1 -1
- package/build/require/type/intrinsic/{intrinsic-mapped-result.d.ts → intrinsic-from-mapped-key.d.ts} +6 -5
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +25 -0
- package/build/require/type/intrinsic/intrinsic.d.ts +6 -6
- package/build/require/type/intrinsic/intrinsic.js +8 -8
- package/build/require/type/intrinsic/lowercase.js +1 -2
- package/build/require/type/intrinsic/uncapitalize.js +1 -2
- package/build/require/type/intrinsic/uppercase.js +1 -2
- package/build/require/type/keyof/index.d.ts +1 -0
- package/build/require/type/keyof/index.js +1 -0
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +13 -0
- package/build/require/type/keyof/keyof-from-mapped-result.js +18 -0
- package/build/require/type/keyof/keyof.d.ts +3 -0
- package/build/require/type/keyof/keyof.js +9 -2
- package/build/require/type/mapped/mapped.d.ts +9 -6
- package/build/require/type/mapped/mapped.js +24 -17
- package/build/require/type/omit/index.d.ts +1 -1
- package/build/require/type/omit/index.js +1 -1
- package/build/require/type/omit/omit-from-mapped-key.d.ts +15 -0
- package/build/require/type/omit/omit-from-mapped-key.js +24 -0
- package/build/require/type/omit/omit.d.ts +2 -2
- package/build/require/type/omit/omit.js +2 -2
- package/build/require/type/partial/index.d.ts +1 -0
- package/build/require/type/partial/index.js +1 -0
- package/build/require/type/partial/partial-from-mapped-result.d.ts +13 -0
- package/build/require/type/partial/partial-from-mapped-result.js +18 -0
- package/build/require/type/partial/partial.d.ts +5 -2
- package/build/require/type/partial/partial.js +10 -5
- package/build/require/type/pick/index.d.ts +1 -1
- package/build/require/type/pick/index.js +1 -1
- package/build/require/type/pick/pick-from-mapped-key.d.ts +15 -0
- package/build/require/type/pick/pick-from-mapped-key.js +24 -0
- package/build/require/type/pick/pick.d.ts +2 -2
- package/build/require/type/pick/pick.js +2 -2
- package/build/require/type/required/index.d.ts +1 -0
- package/build/require/type/required/index.js +1 -0
- package/build/require/type/required/required-from-mapped-result.d.ts +13 -0
- package/build/require/type/required/required-from-mapped-result.js +18 -0
- package/build/require/type/required/required.d.ts +5 -2
- package/build/require/type/required/required.js +10 -5
- package/build/require/type/type/json.d.ts +21 -16
- package/build/require/type/type/json.js +3 -3
- package/package.json +1 -1
- package/readme.md +79 -91
- package/build/import/type/extends/extends-mapped-result-from-result.d.mts +0 -13
- package/build/import/type/extends/extends-mapped-result-from-result.mjs +0 -14
- package/build/import/type/extends/extends-mapped-result.d.mts +0 -17
- package/build/import/type/extends/extends-mapped-result.mjs +0 -21
- package/build/import/type/indexed/indexed-mapped-result.mjs +0 -18
- package/build/import/type/intrinsic/intrinsic-mapped-result.mjs +0 -21
- package/build/import/type/omit/omit-mapped-result.d.mts +0 -15
- package/build/import/type/omit/omit-mapped-result.mjs +0 -20
- package/build/import/type/pick/pick-mapped-result.d.mts +0 -15
- package/build/import/type/pick/pick-mapped-result.mjs +0 -20
- package/build/require/type/extends/extends-mapped-result-from-result.d.ts +0 -13
- package/build/require/type/extends/extends-mapped-result-from-result.js +0 -18
- package/build/require/type/extends/extends-mapped-result.d.ts +0 -17
- package/build/require/type/extends/extends-mapped-result.js +0 -25
- package/build/require/type/indexed/indexed-mapped-result.js +0 -22
- package/build/require/type/intrinsic/intrinsic-mapped-result.js +0 -25
- package/build/require/type/omit/omit-mapped-result.d.ts +0 -15
- package/build/require/type/omit/omit-mapped-result.js +0 -24
- package/build/require/type/pick/pick-mapped-result.d.ts +0 -15
- package/build/require/type/pick/pick-mapped-result.js +0 -24
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IndexResult } from './indexed-result.mjs';
|
|
2
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
3
|
+
function MappedIndexPropertyKey(T, K, options) {
|
|
4
|
+
return { [K]: IndexResult(T, [K], options) };
|
|
5
|
+
}
|
|
6
|
+
function MappedIndexPropertyKeys(T, K, options) {
|
|
7
|
+
const [L, ...R] = K;
|
|
8
|
+
return (K.length > 0
|
|
9
|
+
? { ...MappedIndexPropertyKey(T, L, options), ...MappedIndexPropertyKeys(T, R, options) }
|
|
10
|
+
: {});
|
|
11
|
+
}
|
|
12
|
+
function MappedIndexProperties(T, K, options) {
|
|
13
|
+
return MappedIndexPropertyKeys(T, K.keys, options);
|
|
14
|
+
}
|
|
15
|
+
export function IndexFromMappedKey(T, K, options) {
|
|
16
|
+
const P = MappedIndexProperties(T, K, options);
|
|
17
|
+
return MappedResult(P);
|
|
18
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TSchema } from '../schema/index.mjs';
|
|
1
|
+
import { type TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TNever } from '../never/index.mjs';
|
|
4
4
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
@@ -29,5 +29,5 @@ declare function FromKey<T extends TSchema, K extends PropertyKey>(T: T, K: K):
|
|
|
29
29
|
type FromKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? [FromKey<T, L>, ...FromKeys<T, R>] : []);
|
|
30
30
|
declare function FromKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromKeys<T, K>;
|
|
31
31
|
export type TIndexResult<T extends TSchema, K extends PropertyKey[]> = (UnionResolve<FromKeys<T, K>>);
|
|
32
|
-
export declare function IndexResult<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TIndexResult<T, K>;
|
|
32
|
+
export declare function IndexResult<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K], options: SchemaOptions): TIndexResult<T, K>;
|
|
33
33
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Never } from '../never/index.mjs';
|
|
2
2
|
import { IntersectResolve } from '../intersect/index.mjs';
|
|
3
3
|
import { UnionResolve } from '../union/index.mjs';
|
|
4
|
+
import { CloneType } from '../clone/type.mjs';
|
|
4
5
|
import { TIntersect as IsIntersectType, TUnion as IsUnionType, TTuple as IsTupleType, TArray as IsArrayType, TObject as IsObjectType, TNever as IsNeverType } from '../guard/type.mjs';
|
|
5
6
|
function FromRest(T, K) {
|
|
6
7
|
const [L, ...R] = T;
|
|
@@ -59,6 +60,6 @@ function FromKeys(T, K) {
|
|
|
59
60
|
? [FromKey(T, L), ...FromKeys(T, R)]
|
|
60
61
|
: []);
|
|
61
62
|
}
|
|
62
|
-
export function IndexResult(T, K) {
|
|
63
|
-
return (UnionResolve(FromKeys(T, K)));
|
|
63
|
+
export function IndexResult(T, K, options) {
|
|
64
|
+
return (CloneType(UnionResolve(FromKeys(T, K)), options));
|
|
64
65
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import { type TIndexResult } from './indexed-result.mjs';
|
|
3
3
|
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
-
import { type
|
|
4
|
+
import { type TIndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
5
5
|
import { TMappedKey } from '../mapped/index.mjs';
|
|
6
6
|
export type TIndex<T extends TSchema, K extends PropertyKey[]> = TIndexResult<T, K>;
|
|
7
|
-
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K):
|
|
7
|
+
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
|
|
8
8
|
export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
9
9
|
export declare function Index<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TIndex<T, K>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TSchema as IsSchemaType, TMappedKey as IsMappedKey } from '../guard/type.mjs';
|
|
2
2
|
import { IndexResult } from './indexed-result.mjs';
|
|
3
3
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
export function Index(T, K, options = {}) {
|
|
7
|
-
return (IsMappedKey(K) ? CloneType(
|
|
8
|
-
IsSchemaType(K) ?
|
|
9
|
-
|
|
7
|
+
return (IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
|
|
8
|
+
IsSchemaType(K) ? IndexResult(T, IndexPropertyKeys(K), options) :
|
|
9
|
+
IndexResult(T, K, options));
|
|
10
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
1
2
|
import type { TProperties } from '../object/index.mjs';
|
|
2
3
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
3
4
|
import { type TIntrinsic, type IntrinsicMode } from './intrinsic.mjs';
|
|
@@ -5,11 +6,11 @@ import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
|
5
6
|
type MappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode, P extends TLiteralValue = K extends TLiteralValue ? K : never> = {
|
|
6
7
|
[_ in K]: TIntrinsic<TLiteral<P>, M>;
|
|
7
8
|
};
|
|
8
|
-
declare function MappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode>(K: K, M: M): MappedIntrinsicPropertyKey<K, M>;
|
|
9
|
+
declare function MappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode>(K: K, M: M, options: SchemaOptions): MappedIntrinsicPropertyKey<K, M>;
|
|
9
10
|
type MappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? MappedIntrinsicPropertyKey<L, M> & MappedIntrinsicPropertyKeys<R, M> : {});
|
|
10
|
-
declare function MappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode>(K: [...K], M: M): MappedIntrinsicPropertyKeys<K, M>;
|
|
11
|
+
declare function MappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode>(K: [...K], M: M, options: SchemaOptions): MappedIntrinsicPropertyKeys<K, M>;
|
|
11
12
|
type MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode> = (MappedIntrinsicPropertyKeys<K['keys'], M>);
|
|
12
|
-
declare function MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode>(T: K, M: M): MappedIntrinsicProperties<K, M>;
|
|
13
|
-
export type
|
|
14
|
-
export declare function
|
|
13
|
+
declare function MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode>(T: K, M: M, options: SchemaOptions): MappedIntrinsicProperties<K, M>;
|
|
14
|
+
export type TIntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>> = (TMappedResult<P>);
|
|
15
|
+
export declare function IntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>>(T: K, M: M, options: SchemaOptions): TMappedResult<P>;
|
|
15
16
|
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Intrinsic } from './intrinsic.mjs';
|
|
3
|
+
import { Literal } from '../literal/index.mjs';
|
|
4
|
+
function MappedIntrinsicPropertyKey(K, M, options) {
|
|
5
|
+
return {
|
|
6
|
+
[K]: Intrinsic(Literal(K), M, options)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
10
|
+
const [L, ...R] = K;
|
|
11
|
+
return (K.length > 0
|
|
12
|
+
? { ...MappedIntrinsicPropertyKey(L, M, options), ...MappedIntrinsicPropertyKeys(R, M, options) }
|
|
13
|
+
: {});
|
|
14
|
+
}
|
|
15
|
+
function MappedIntrinsicProperties(T, M, options) {
|
|
16
|
+
return MappedIntrinsicPropertyKeys(T['keys'], M, options);
|
|
17
|
+
}
|
|
18
|
+
export function IntrinsicFromMappedKey(T, M, options) {
|
|
19
|
+
const P = MappedIntrinsicProperties(T, M, options);
|
|
20
|
+
return MappedResult(P);
|
|
21
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { TSchema } from '../schema/index.mjs';
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import { type TTemplateLiteral, type TTemplateLiteralKind } from '../template-literal/index.mjs';
|
|
3
|
-
import { type
|
|
3
|
+
import { type TIntrinsicFromMappedKey } from './intrinsic-from-mapped-key.mjs';
|
|
4
4
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
5
5
|
import { type TUnion } from '../union/index.mjs';
|
|
6
6
|
import { type TMappedKey } from '../mapped/index.mjs';
|
|
7
7
|
export type IntrinsicMode = 'Uppercase' | 'Lowercase' | 'Capitalize' | 'Uncapitalize';
|
|
8
8
|
type FromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode> = M extends IntrinsicMode ? T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? [TIntrinsic<L, M>, ...FromTemplateLiteral<R, M>] : T : T;
|
|
9
|
-
declare function FromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode>(schema: TTemplateLiteral, mode: IntrinsicMode): FromTemplateLiteral<T, M>;
|
|
9
|
+
declare function FromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode>(schema: TTemplateLiteral, mode: IntrinsicMode, options: SchemaOptions): FromTemplateLiteral<T, M>;
|
|
10
10
|
type FromLiteralValue<T, M extends IntrinsicMode> = (T extends string ? M extends 'Uncapitalize' ? Uncapitalize<T> : M extends 'Capitalize' ? Capitalize<T> : M extends 'Uppercase' ? Uppercase<T> : M extends 'Lowercase' ? Lowercase<T> : string : T);
|
|
11
11
|
declare function FromLiteralValue(value: TLiteralValue, mode: IntrinsicMode): string;
|
|
12
12
|
type FromRest<T extends TSchema[], M extends IntrinsicMode> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [TIntrinsic<L, M>, ...FromRest<R, M>] : [];
|
|
13
13
|
declare function FromRest<T extends TSchema[], M extends IntrinsicMode>(T: [...T], mode: M): FromRest<T, M>;
|
|
14
|
-
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ?
|
|
15
|
-
export declare function Intrinsic<T extends TMappedKey, M extends IntrinsicMode>(schema: T, mode: M):
|
|
16
|
-
export declare function Intrinsic<T extends TSchema, M extends IntrinsicMode>(schema: T, mode: M): TIntrinsic<T, M>;
|
|
14
|
+
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicFromMappedKey<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<FromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<FromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<FromLiteralValue<S, M>> : T;
|
|
15
|
+
export declare function Intrinsic<T extends TMappedKey, M extends IntrinsicMode>(schema: T, mode: M, options?: SchemaOptions): TIntrinsicFromMappedKey<T, M>;
|
|
16
|
+
export declare function Intrinsic<T extends TSchema, M extends IntrinsicMode>(schema: T, mode: M, options?: SchemaOptions): TIntrinsic<T, M>;
|
|
17
17
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TemplateLiteral, TemplateLiteralParseExact, IsTemplateLiteralFinite, TemplateLiteralGenerate } from '../template-literal/index.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { IntrinsicFromMappedKey } from './intrinsic-from-mapped-key.mjs';
|
|
3
3
|
import { Literal } from '../literal/index.mjs';
|
|
4
4
|
import { Union } from '../union/index.mjs';
|
|
5
5
|
import { TMappedKey as IsMappedKeyType, TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, TLiteral as IsLiteralType } from '../guard/type.mjs';
|
|
@@ -17,7 +17,7 @@ function ApplyUppercase(value) {
|
|
|
17
17
|
function ApplyLowercase(value) {
|
|
18
18
|
return value.toLowerCase();
|
|
19
19
|
}
|
|
20
|
-
function FromTemplateLiteral(schema, mode) {
|
|
20
|
+
function FromTemplateLiteral(schema, mode, options) {
|
|
21
21
|
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
22
22
|
const finite = IsTemplateLiteralFinite(expression);
|
|
23
23
|
if (!finite)
|
|
@@ -26,7 +26,7 @@ function FromTemplateLiteral(schema, mode) {
|
|
|
26
26
|
const literals = strings.map((value) => Literal(value));
|
|
27
27
|
const mapped = FromRest(literals, mode);
|
|
28
28
|
const union = Union(mapped);
|
|
29
|
-
return TemplateLiteral([union]);
|
|
29
|
+
return TemplateLiteral([union], options);
|
|
30
30
|
}
|
|
31
31
|
function FromLiteralValue(value, mode) {
|
|
32
32
|
return (typeof value === 'string' ? (mode === 'Uncapitalize' ? ApplyUncapitalize(value) :
|
|
@@ -39,10 +39,10 @@ function FromRest(T, mode) {
|
|
|
39
39
|
const [L, ...R] = T;
|
|
40
40
|
return (T.length > 0 ? [Intrinsic(L, mode), ...FromRest(R, mode)] : []);
|
|
41
41
|
}
|
|
42
|
-
export function Intrinsic(schema, mode) {
|
|
43
|
-
return (IsMappedKeyType(schema) ?
|
|
44
|
-
IsTemplateLiteralType(schema) ? FromTemplateLiteral(schema, mode) :
|
|
45
|
-
IsUnionType(schema) ? Union(FromRest(schema.anyOf, mode)) :
|
|
46
|
-
IsLiteralType(schema) ? Literal(FromLiteralValue(schema.const, mode)) :
|
|
42
|
+
export function Intrinsic(schema, mode, options = {}) {
|
|
43
|
+
return (IsMappedKeyType(schema) ? IntrinsicFromMappedKey(schema, mode, options) :
|
|
44
|
+
IsTemplateLiteralType(schema) ? FromTemplateLiteral(schema, mode, schema) :
|
|
45
|
+
IsUnionType(schema) ? Union(FromRest(schema.anyOf, mode), options) :
|
|
46
|
+
IsLiteralType(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
|
|
47
47
|
schema);
|
|
48
48
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TKeyOf } from './keyof.mjs';
|
|
5
|
+
type FromProperties<K extends TProperties> = ({
|
|
6
|
+
[K2 in keyof K]: TKeyOf<K[K2]>;
|
|
7
|
+
});
|
|
8
|
+
declare function FromProperties<K extends TProperties>(K: K, options: SchemaOptions): FromProperties<K>;
|
|
9
|
+
type FromMappedResult<K extends TMappedResult> = (FromProperties<K['properties']>);
|
|
10
|
+
declare function FromMappedResult<K extends TMappedResult>(K: K, options: SchemaOptions): FromMappedResult<K>;
|
|
11
|
+
export type TKeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
|
|
12
|
+
export declare function KeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { KeyOf } from './keyof.mjs';
|
|
3
|
+
function FromProperties(K, options) {
|
|
4
|
+
return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
|
|
5
|
+
return { ...Acc, [K2]: KeyOf(K[K2], options) };
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
function FromMappedResult(K, options) {
|
|
9
|
+
return FromProperties(K.properties, options);
|
|
10
|
+
}
|
|
11
|
+
export function KeyOfFromMappedResult(T, options) {
|
|
12
|
+
const P = FromMappedResult(T, options);
|
|
13
|
+
return MappedResult(P);
|
|
14
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
2
|
import type { Ensure } from '../helpers/index.mjs';
|
|
3
|
+
import type { TMappedResult } from '../mapped/index.mjs';
|
|
3
4
|
import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
4
5
|
import { type TNumber } from '../number/index.mjs';
|
|
5
6
|
import { type SchemaOptions } from '../schema/index.mjs';
|
|
6
7
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
7
8
|
import { UnionResolve } from '../union/index.mjs';
|
|
9
|
+
import { type TKeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
8
10
|
type FromLiterals<T extends TLiteralValue[]> = (T extends [infer L extends TLiteralValue, ...infer R extends TLiteralValue[]] ? L extends '[number]' ? [TNumber, ...FromLiterals<R>] : [TLiteral<L>, ...FromLiterals<R>] : []);
|
|
9
11
|
declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
|
|
10
12
|
export type TKeyOf<T extends TSchema> = (Ensure<UnionResolve<FromLiterals<KeyOfPropertyKeys<T>>>>);
|
|
13
|
+
export declare function KeyOf<T extends TMappedResult>(T: T, options?: SchemaOptions): TKeyOfFromMappedResult<T>;
|
|
11
14
|
export declare function KeyOf<T extends TSchema>(T: T, options?: SchemaOptions): TKeyOf<T>;
|
|
12
15
|
export {};
|
|
@@ -3,6 +3,8 @@ import { Number } from '../number/index.mjs';
|
|
|
3
3
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
4
4
|
import { UnionResolve } from '../union/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
|
+
import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
7
|
+
import { TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
6
8
|
function FromLiterals(T) {
|
|
7
9
|
const [L, ...R] = T;
|
|
8
10
|
return (T.length > 0
|
|
@@ -12,6 +14,11 @@ function FromLiterals(T) {
|
|
|
12
14
|
: []);
|
|
13
15
|
}
|
|
14
16
|
export function KeyOf(T, options = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
if (IsMappedResultType(T)) {
|
|
18
|
+
return KeyOfFromMappedResult(T, options);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const K = UnionResolve(FromLiterals(KeyOfPropertyKeys(T)));
|
|
22
|
+
return CloneType(K, options);
|
|
23
|
+
}
|
|
17
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
2
|
+
import type { Ensure, Evaluate, Assert } from '../helpers/index.mjs';
|
|
3
3
|
import { type TArray } from '../array/index.mjs';
|
|
4
4
|
import { type TAsyncIterator } from '../async-iterator/index.mjs';
|
|
5
5
|
import { type TConstructor } from '../constructor/index.mjs';
|
|
@@ -8,19 +8,22 @@ import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
|
8
8
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
9
9
|
import { type TIterator } from '../iterator/index.mjs';
|
|
10
10
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
11
|
-
import { type TNever } from '../never/index.mjs';
|
|
12
11
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
13
12
|
import { type TOptional } from '../optional/index.mjs';
|
|
14
13
|
import { type TPromise } from '../promise/index.mjs';
|
|
15
14
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
16
15
|
import { type TTuple } from '../tuple/index.mjs';
|
|
17
16
|
import { type TUnion } from '../union/index.mjs';
|
|
18
|
-
import type
|
|
17
|
+
import { type TMappedResult } from './mapped-result.mjs';
|
|
19
18
|
import type { TMappedKey } from './mapped-key.mjs';
|
|
20
|
-
type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> :
|
|
19
|
+
type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
|
|
21
20
|
declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
|
|
22
|
-
type
|
|
23
|
-
|
|
21
|
+
type MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
|
|
22
|
+
[_ in L]: TLiteral<Assert<L, TLiteralValue>>;
|
|
23
|
+
} & MappedKeyToMappedResultProperties<K, R> : {});
|
|
24
|
+
declare function MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): MappedKeyToMappedResultProperties<K, P>;
|
|
25
|
+
type FromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = MappedKeyToMappedResultProperties<K, P>> = (FromMappedResult<K, R>);
|
|
26
|
+
declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): FromMappedResult<K, MappedKeyToMappedResultProperties<K, P>>;
|
|
24
27
|
type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
|
|
25
28
|
declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
|
|
26
29
|
type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
|
|
@@ -10,21 +10,28 @@ import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
|
10
10
|
import { Intersect } from '../intersect/index.mjs';
|
|
11
11
|
import { Iterator } from '../iterator/index.mjs';
|
|
12
12
|
import { Literal } from '../literal/index.mjs';
|
|
13
|
-
import { Never } from '../never/index.mjs';
|
|
14
13
|
import { Object } from '../object/index.mjs';
|
|
15
14
|
import { Optional } from '../optional/index.mjs';
|
|
16
15
|
import { Promise } from '../promise/index.mjs';
|
|
17
16
|
import { Readonly } from '../readonly/index.mjs';
|
|
18
17
|
import { Tuple } from '../tuple/index.mjs';
|
|
19
18
|
import { Union } from '../union/index.mjs';
|
|
19
|
+
import { MappedResult } from './mapped-result.mjs';
|
|
20
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
21
|
function FromMappedResult(K, P) {
|
|
22
22
|
return (K in P
|
|
23
23
|
? FromSchemaType(K, P[K])
|
|
24
|
-
:
|
|
24
|
+
: MappedResult(P));
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
26
|
+
function MappedKeyToMappedResultProperties(K, P) {
|
|
27
|
+
const [L, ...R] = P;
|
|
28
|
+
return (P.length > 0
|
|
29
|
+
? { [L]: Literal(L), ...MappedKeyToMappedResultProperties(K, R) }
|
|
30
|
+
: {});
|
|
31
|
+
}
|
|
32
|
+
function FromMappedKey(K, P) {
|
|
33
|
+
const R = MappedKeyToMappedResultProperties(K, P);
|
|
34
|
+
return FromMappedResult(K, R);
|
|
28
35
|
}
|
|
29
36
|
function FromRest(K, T) {
|
|
30
37
|
const [L, ...R] = T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './omit-mapped-
|
|
1
|
+
export * from './omit-from-mapped-key.mjs';
|
|
2
2
|
export * from './omit.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './omit-mapped-
|
|
1
|
+
export * from './omit-from-mapped-key.mjs';
|
|
2
2
|
export * from './omit.mjs';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } 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 FromPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
6
|
+
[_ in K]: TOmit<T, [K]>;
|
|
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>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Omit } from './omit.mjs';
|
|
3
|
+
function FromPropertyKey(T, K, options) {
|
|
4
|
+
return {
|
|
5
|
+
[K]: Omit(T, [K], options)
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function FromPropertyKeys(T, K, options) {
|
|
9
|
+
const [LK, ...RK] = K;
|
|
10
|
+
return (K.length > 0
|
|
11
|
+
? { ...FromPropertyKey(T, LK, options), ...FromPropertyKeys(T, RK, options) }
|
|
12
|
+
: {});
|
|
13
|
+
}
|
|
14
|
+
function FromMappedKey(T, K, options) {
|
|
15
|
+
return FromPropertyKeys(T, K.keys, options);
|
|
16
|
+
}
|
|
17
|
+
export function OmitFromMappedKey(T, K, options) {
|
|
18
|
+
const P = FromMappedKey(T, K, options);
|
|
19
|
+
return MappedResult(P);
|
|
20
|
+
}
|
|
@@ -6,7 +6,7 @@ import { type TUnion } from '../union/index.mjs';
|
|
|
6
6
|
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
|
-
import { type
|
|
9
|
+
import { type TOmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
10
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
11
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
|
|
12
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>] : [];
|
|
@@ -16,7 +16,7 @@ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(
|
|
|
16
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
17
|
export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): OmitResolve<T, K>;
|
|
18
18
|
export type TOmit<T extends TSchema, K extends PropertyKey[]> = OmitResolve<T, K>;
|
|
19
|
-
export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K):
|
|
19
|
+
export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K): TOmitFromMappedKey<T, K>;
|
|
20
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>;
|
|
21
21
|
export declare function Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
22
22
|
export {};
|
|
@@ -5,7 +5,7 @@ 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 {
|
|
8
|
+
import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
9
9
|
import { TMappedKey as IsMappedKeyType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
10
10
|
function FromIntersect(T, K) {
|
|
11
11
|
return T.map((T) => OmitResolve(T, K));
|
|
@@ -30,7 +30,7 @@ export function OmitResolve(T, K) {
|
|
|
30
30
|
}
|
|
31
31
|
export function Omit(T, K, options = {}) {
|
|
32
32
|
if (IsMappedKeyType(K)) {
|
|
33
|
-
return
|
|
33
|
+
return OmitFromMappedKey(T, K, options);
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
const I = IsSchemaType(K) ? IndexPropertyKeys(K) : K;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TPartial } from './partial.mjs';
|
|
5
|
+
type FromProperties<K extends TProperties> = ({
|
|
6
|
+
[K2 in keyof K]: TPartial<K[K2]>;
|
|
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>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Partial } from './partial.mjs';
|
|
3
|
+
function FromProperties(K, options) {
|
|
4
|
+
return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
|
|
5
|
+
return { ...Acc, [K2]: Partial(K[K2], options) };
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
function FromMappedResult(K, options) {
|
|
9
|
+
return FromProperties(K.properties, options);
|
|
10
|
+
}
|
|
11
|
+
export function PartialFromMappedResult(T, options) {
|
|
12
|
+
const P = FromMappedResult(T, options);
|
|
13
|
+
return MappedResult(P);
|
|
14
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Evaluate } from '../helpers/index.mjs';
|
|
3
|
+
import type { TMappedResult } from '../mapped/index.mjs';
|
|
3
4
|
import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
|
|
4
5
|
import { type TOptional } from '../optional/index.mjs';
|
|
5
6
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
@@ -7,6 +8,7 @@ import { type TRecursive } from '../recursive/index.mjs';
|
|
|
7
8
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
8
9
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
9
10
|
import { type TUnion } from '../union/index.mjs';
|
|
11
|
+
import { type TPartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
10
12
|
type FromIntersect<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PartialResolve<L>, ...FromIntersect<R>] : []);
|
|
11
13
|
declare function FromIntersect<T extends TSchema[]>(T: [...T]): FromIntersect<T>;
|
|
12
14
|
type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PartialResolve<L>, ...FromUnion<R>] : []);
|
|
@@ -15,8 +17,9 @@ type FromProperties<T extends TProperties> = Evaluate<{
|
|
|
15
17
|
[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]>;
|
|
16
18
|
}>;
|
|
17
19
|
declare function FromProperties<T extends TProperties>(T: T): TProperties;
|
|
18
|
-
|
|
19
|
-
|
|
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<{}>);
|
|
21
|
+
declare function PartialResolve<T extends TSchema>(T: T): PartialResolve<T>;
|
|
20
22
|
export type TPartial<T extends TSchema> = PartialResolve<T>;
|
|
23
|
+
export declare function Partial<T extends TMappedResult>(T: T, options?: SchemaOptions): TPartialFromMappedResult<T>;
|
|
21
24
|
export declare function Partial<T extends TSchema>(T: T, options?: SchemaOptions): TPartial<T>;
|
|
22
25
|
export {};
|
|
@@ -5,7 +5,8 @@ import { Union } from '../union/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 {
|
|
8
|
+
import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
9
|
+
import { TMappedResult as IsMappedResultType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType } from '../guard/type.mjs';
|
|
9
10
|
function FromIntersect(T) {
|
|
10
11
|
const [L, ...R] = T;
|
|
11
12
|
return (T.length > 0
|
|
@@ -23,14 +24,19 @@ function FromProperties(T) {
|
|
|
23
24
|
return { ...Acc, [K]: Optional(T[K]) };
|
|
24
25
|
}, {});
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
function PartialResolve(T) {
|
|
27
28
|
return (IsIntersectType(T) ? Intersect(FromIntersect(T.allOf)) :
|
|
28
29
|
IsUnionType(T) ? Union(FromUnion(T.anyOf)) :
|
|
29
30
|
IsObjectType(T) ? Object(FromProperties(T.properties)) :
|
|
30
31
|
Object({}));
|
|
31
32
|
}
|
|
32
33
|
export function Partial(T, options = {}) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (IsMappedResultType(T)) {
|
|
35
|
+
return PartialFromMappedResult(T, options);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
39
|
+
const R = CloneType(PartialResolve(T), options);
|
|
40
|
+
return { ...D, ...R };
|
|
41
|
+
}
|
|
36
42
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './pick-mapped-
|
|
1
|
+
export * from './pick-from-mapped-key.mjs';
|
|
2
2
|
export * from './pick.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './pick-mapped-
|
|
1
|
+
export * from './pick-from-mapped-key.mjs';
|
|
2
2
|
export * from './pick.mjs';
|