@sinclair/typebox 0.34.0 → 0.34.2
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/cjs/syntax/runtime.d.ts +4 -1
- package/build/cjs/syntax/runtime.js +3 -1
- package/build/cjs/syntax/static.d.ts +3 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/computed/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -4
- package/build/cjs/type/guard/kind.js +10 -0
- package/build/cjs/type/guard/type.d.ts +6 -3
- package/build/cjs/type/guard/type.js +6 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +8 -52
- package/build/cjs/type/module/module.js +14 -11
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +41 -51
- package/build/cjs/type/type/json.js +40 -40
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/check/check.js +3 -3
- package/build/cjs/value/transform/decode.js +7 -7
- package/build/cjs/value/transform/encode.js +7 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/syntax/runtime.d.mts +4 -1
- package/build/esm/syntax/runtime.mjs +3 -1
- package/build/esm/syntax/static.d.mts +3 -3
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +9 -4
- package/build/esm/type/guard/kind.mjs +8 -0
- package/build/esm/type/guard/type.d.mts +6 -3
- package/build/esm/type/guard/type.mjs +5 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +8 -52
- package/build/esm/type/module/module.mjs +14 -11
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +41 -51
- package/build/esm/type/type/json.mjs +40 -40
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/check/check.mjs +2 -2
- package/build/esm/value/transform/decode.mjs +2 -2
- package/build/esm/value/transform/encode.mjs +2 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +30 -19
|
@@ -1,60 +1,71 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Discard } from '../discard/discard.mjs';
|
|
3
|
+
import { TransformKind } from '../symbols/symbols.mjs';
|
|
4
|
+
import { Computed } from '../computed/index.mjs';
|
|
5
|
+
import { Literal } from '../literal/index.mjs';
|
|
6
|
+
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
3
7
|
import { Intersect } from '../intersect/index.mjs';
|
|
4
8
|
import { Union } from '../union/index.mjs';
|
|
5
9
|
import { Object } from '../object/index.mjs';
|
|
6
|
-
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
// Mapped
|
|
12
|
+
// ------------------------------------------------------------------
|
|
7
13
|
import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
8
14
|
import { OmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
9
|
-
import { TransformKind } from '../symbols/symbols.mjs';
|
|
10
15
|
// ------------------------------------------------------------------
|
|
11
16
|
// TypeGuard
|
|
12
17
|
// ------------------------------------------------------------------
|
|
13
|
-
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/kind.mjs';
|
|
18
|
+
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult, IsLiteralValue, IsRef } from '../guard/kind.mjs';
|
|
19
|
+
import { IsArray as IsArrayValue } from '../guard/value.mjs';
|
|
14
20
|
// prettier-ignore
|
|
15
|
-
function FromIntersect(
|
|
16
|
-
return
|
|
21
|
+
function FromIntersect(types, propertyKeys) {
|
|
22
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
17
23
|
}
|
|
18
24
|
// prettier-ignore
|
|
19
|
-
function FromUnion(
|
|
20
|
-
return
|
|
25
|
+
function FromUnion(types, propertyKeys) {
|
|
26
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
21
27
|
}
|
|
22
28
|
// ------------------------------------------------------------------
|
|
23
29
|
// FromProperty
|
|
24
30
|
// ------------------------------------------------------------------
|
|
25
31
|
// prettier-ignore
|
|
26
|
-
function FromProperty(
|
|
27
|
-
const { [
|
|
32
|
+
function FromProperty(properties, key) {
|
|
33
|
+
const { [key]: _, ...R } = properties;
|
|
28
34
|
return R;
|
|
29
35
|
}
|
|
30
36
|
// prettier-ignore
|
|
31
|
-
function FromProperties(
|
|
32
|
-
return
|
|
37
|
+
function FromProperties(properties, propertyKeys) {
|
|
38
|
+
return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
|
|
33
39
|
}
|
|
34
40
|
// prettier-ignore
|
|
35
|
-
function FromObject(
|
|
36
|
-
const options = Discard(
|
|
37
|
-
const
|
|
38
|
-
return Object(
|
|
41
|
+
function FromObject(properties, propertyKeys) {
|
|
42
|
+
const options = Discard(properties, [TransformKind, '$id', 'required', 'properties']);
|
|
43
|
+
const omittedProperties = FromProperties(properties['properties'], propertyKeys);
|
|
44
|
+
return Object(omittedProperties, options);
|
|
39
45
|
}
|
|
40
|
-
// ------------------------------------------------------------------
|
|
41
|
-
// OmitResolve
|
|
42
|
-
// ------------------------------------------------------------------
|
|
43
46
|
// prettier-ignore
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
function UnionFromPropertyKeys(propertyKeys) {
|
|
48
|
+
const result = propertyKeys.reduce((result, key) => IsLiteralValue(key) ? [...result, Literal(key)] : result, []);
|
|
49
|
+
return Union(result);
|
|
50
|
+
}
|
|
51
|
+
// prettier-ignore
|
|
52
|
+
function OmitResolve(properties, propertyKeys) {
|
|
53
|
+
return (IsIntersect(properties) ? Intersect(FromIntersect(properties.allOf, propertyKeys)) :
|
|
54
|
+
IsUnion(properties) ? Union(FromUnion(properties.anyOf, propertyKeys)) :
|
|
55
|
+
IsObject(properties) ? FromObject(properties, propertyKeys) :
|
|
48
56
|
Object({}));
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
59
|
+
// prettier-ignore
|
|
60
|
+
export function Omit(type, key, options) {
|
|
61
|
+
const typeKey = IsArrayValue(key) ? UnionFromPropertyKeys(key) : key;
|
|
62
|
+
const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
63
|
+
const isTypeRef = IsRef(type);
|
|
64
|
+
const isKeyRef = IsRef(key);
|
|
65
|
+
return (IsMappedResult(type) ? OmitFromMappedResult(type, propertyKeys, options) :
|
|
66
|
+
IsMappedKey(key) ? OmitFromMappedKey(type, key, options) :
|
|
67
|
+
(isTypeRef && isKeyRef) ? Computed('Omit', [type, typeKey], options) :
|
|
68
|
+
(!isTypeRef && isKeyRef) ? Computed('Omit', [type, typeKey], options) :
|
|
69
|
+
(isTypeRef && !isKeyRef) ? Computed('Omit', [type, typeKey], options) :
|
|
70
|
+
CreateType({ ...OmitResolve(type, propertyKeys), ...options }));
|
|
60
71
|
}
|
|
@@ -2,21 +2,25 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Evaluate, Ensure } from '../helpers/index.mjs';
|
|
3
3
|
import type { TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
|
|
5
|
+
import { type TComputed } from '../computed/index.mjs';
|
|
5
6
|
import { type TOptional } from '../optional/index.mjs';
|
|
6
7
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
7
8
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
8
9
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
9
10
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
10
11
|
import { type TUnion } from '../union/index.mjs';
|
|
12
|
+
import { type TRef } from '../ref/index.mjs';
|
|
11
13
|
import { type TPartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
14
|
+
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Partial', [TComputed<Target, Parameters>]>>;
|
|
15
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
|
|
16
|
+
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
17
|
+
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<Properties[K]>;
|
|
15
18
|
}>;
|
|
16
|
-
type TFromObject<
|
|
17
|
-
|
|
19
|
+
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
|
+
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TPartial<L>]> : Result);
|
|
21
|
+
export type TPartial<T extends TSchema> = (T extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : T extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : T extends TRef<infer Ref extends string> ? TFromRef<Ref> : T extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : T extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : T extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : TObject<{}>);
|
|
18
22
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
19
|
-
export declare function Partial<
|
|
23
|
+
export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
20
24
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
21
|
-
export declare function Partial<
|
|
25
|
+
export declare function Partial<Type extends TSchema>(type: Type, options?: SchemaOptions): TPartial<Type>;
|
|
22
26
|
export {};
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
|
+
import { Computed } from '../computed/index.mjs';
|
|
2
3
|
import { Optional } from '../optional/index.mjs';
|
|
3
4
|
import { Object } from '../object/index.mjs';
|
|
4
5
|
import { Intersect } from '../intersect/index.mjs';
|
|
5
6
|
import { Union } from '../union/index.mjs';
|
|
7
|
+
import { Ref } from '../ref/index.mjs';
|
|
6
8
|
import { Discard } from '../discard/index.mjs';
|
|
7
9
|
import { TransformKind } from '../symbols/index.mjs';
|
|
8
10
|
import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
9
11
|
// ------------------------------------------------------------------
|
|
10
12
|
// TypeGuard
|
|
11
13
|
// ------------------------------------------------------------------
|
|
12
|
-
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
|
|
14
|
+
import { IsMappedResult, IsIntersect, IsUnion, IsObject, IsRef, IsComputed } from '../guard/kind.mjs';
|
|
13
15
|
// prettier-ignore
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
+
function FromComputed(target, parameters) {
|
|
17
|
+
return Computed('Partial', [Computed(target, parameters)]);
|
|
16
18
|
}
|
|
17
19
|
// prettier-ignore
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
function FromRef($ref) {
|
|
21
|
+
return Computed('Partial', [Ref($ref)]);
|
|
22
|
+
}
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
function FromProperties(properties) {
|
|
25
|
+
const partialProperties = {};
|
|
26
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
27
|
+
partialProperties[K] = Optional(properties[K]);
|
|
28
|
+
return partialProperties;
|
|
23
29
|
}
|
|
24
30
|
// prettier-ignore
|
|
25
31
|
function FromObject(T) {
|
|
@@ -27,23 +33,29 @@ function FromObject(T) {
|
|
|
27
33
|
const properties = FromProperties(T['properties']);
|
|
28
34
|
return Object(properties, options);
|
|
29
35
|
}
|
|
36
|
+
// prettier-ignore
|
|
37
|
+
function FromRest(types) {
|
|
38
|
+
return types.map(type => PartialResolve(type));
|
|
39
|
+
}
|
|
30
40
|
// ------------------------------------------------------------------
|
|
31
41
|
// PartialResolve
|
|
32
42
|
// ------------------------------------------------------------------
|
|
33
43
|
// prettier-ignore
|
|
34
|
-
function PartialResolve(
|
|
35
|
-
return (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
function PartialResolve(type) {
|
|
45
|
+
return (IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
46
|
+
IsRef(type) ? FromRef(type.$ref) :
|
|
47
|
+
IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
48
|
+
IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
49
|
+
IsObject(type) ? FromObject(type) :
|
|
50
|
+
Object({}));
|
|
39
51
|
}
|
|
40
52
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
41
|
-
export function Partial(
|
|
42
|
-
if (IsMappedResult(
|
|
43
|
-
return PartialFromMappedResult(
|
|
53
|
+
export function Partial(type, options) {
|
|
54
|
+
if (IsMappedResult(type)) {
|
|
55
|
+
return PartialFromMappedResult(type, options);
|
|
44
56
|
}
|
|
45
57
|
else {
|
|
46
58
|
// special: mapping types require overridable options
|
|
47
|
-
return CreateType({ ...PartialResolve(
|
|
59
|
+
return CreateType({ ...PartialResolve(type), ...options });
|
|
48
60
|
}
|
|
49
61
|
}
|
|
@@ -2,11 +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 TFromPropertyKey<
|
|
6
|
-
[_ in
|
|
5
|
+
type TFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
|
|
6
|
+
[_ in Key]: TPick<Type, [Key]>;
|
|
7
7
|
};
|
|
8
|
-
type TFromPropertyKeys<
|
|
9
|
-
type TFromMappedKey<
|
|
10
|
-
export type TPickFromMappedKey<
|
|
11
|
-
export declare function PickFromMappedKey<
|
|
8
|
+
type TFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer LeftKey extends PropertyKey, ...infer RightKeys extends PropertyKey[]] ? TFromPropertyKeys<Type, RightKeys, Result & TFromPropertyKey<Type, LeftKey>> : Result);
|
|
9
|
+
type TFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey> = (TFromPropertyKeys<Type, MappedKey['keys']>);
|
|
10
|
+
export type TPickFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey<Type, MappedKey>> = (TMappedResult<Properties>);
|
|
11
|
+
export declare function PickFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey<Type, MappedKey>>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -2,23 +2,23 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Pick } from './pick.mjs';
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function FromPropertyKey(
|
|
5
|
+
function FromPropertyKey(type, key, options) {
|
|
6
6
|
return {
|
|
7
|
-
[
|
|
7
|
+
[key]: Pick(type, [key], Clone(options))
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
function FromPropertyKeys(
|
|
12
|
-
return
|
|
13
|
-
return { ...
|
|
11
|
+
function FromPropertyKeys(type, propertyKeys, options) {
|
|
12
|
+
return propertyKeys.reduce((result, leftKey) => {
|
|
13
|
+
return { ...result, ...FromPropertyKey(type, leftKey, options) };
|
|
14
14
|
}, {});
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
|
-
function FromMappedKey(
|
|
18
|
-
return FromPropertyKeys(
|
|
17
|
+
function FromMappedKey(type, mappedKey, options) {
|
|
18
|
+
return FromPropertyKeys(type, mappedKey.keys, options);
|
|
19
19
|
}
|
|
20
20
|
// prettier-ignore
|
|
21
|
-
export function PickFromMappedKey(
|
|
22
|
-
const
|
|
23
|
-
return MappedResult(
|
|
21
|
+
export function PickFromMappedKey(type, mappedKey, options) {
|
|
22
|
+
const properties = FromMappedKey(type, mappedKey, options);
|
|
23
|
+
return MappedResult(properties);
|
|
24
24
|
}
|
|
@@ -3,10 +3,10 @@ import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
|
3
3
|
import type { TProperties } from '../object/index.mjs';
|
|
4
4
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
5
5
|
import { type TPick } from './pick.mjs';
|
|
6
|
-
type TFromProperties<
|
|
7
|
-
[K2 in keyof
|
|
6
|
+
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = ({
|
|
7
|
+
[K2 in keyof Properties]: TPick<Properties[K2], PropertyKeys>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<
|
|
10
|
-
export type TPickFromMappedResult<
|
|
11
|
-
export declare function PickFromMappedResult<
|
|
9
|
+
type TFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[]> = (Evaluate<TFromProperties<MappedResult['properties'], PropertyKeys>>);
|
|
10
|
+
export type TPickFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult<MappedResult, PropertyKeys>> = (Ensure<TMappedResult<Properties>>);
|
|
11
|
+
export declare function PickFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult<MappedResult, PropertyKeys>>(mappedResult: MappedResult, propertyKeys: [...PropertyKeys], options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -2,18 +2,18 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Pick } from './pick.mjs';
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function FromProperties(
|
|
6
|
-
const
|
|
7
|
-
for (const K2 of globalThis.Object.getOwnPropertyNames(
|
|
8
|
-
|
|
9
|
-
return
|
|
5
|
+
function FromProperties(properties, propertyKeys, options) {
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
8
|
+
result[K2] = Pick(properties[K2], propertyKeys, Clone(options));
|
|
9
|
+
return result;
|
|
10
10
|
}
|
|
11
11
|
// prettier-ignore
|
|
12
|
-
function FromMappedResult(
|
|
13
|
-
return FromProperties(
|
|
12
|
+
function FromMappedResult(mappedResult, propertyKeys, options) {
|
|
13
|
+
return FromProperties(mappedResult.properties, propertyKeys, options);
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
export function PickFromMappedResult(
|
|
17
|
-
const
|
|
18
|
-
return MappedResult(
|
|
16
|
+
export function PickFromMappedResult(mappedResult, propertyKeys, options) {
|
|
17
|
+
const properties = FromMappedResult(mappedResult, propertyKeys, options);
|
|
18
|
+
return MappedResult(properties);
|
|
19
19
|
}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index.mjs';
|
|
3
3
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
4
|
+
import { type TComputed } from '../computed/index.mjs';
|
|
4
5
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
5
|
-
import { type
|
|
6
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
6
7
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
7
|
-
import
|
|
8
|
+
import { type TUnion } from '../union/index.mjs';
|
|
9
|
+
import { type TMappedKey, type TMappedResult } from '../mapped/index.mjs';
|
|
10
|
+
import { type TRef } from '../ref/index.mjs';
|
|
8
11
|
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
9
12
|
import { type TPickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
10
13
|
import { type TPickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
|
15
|
+
type TFromUnion<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
|
16
|
+
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKeys extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Pick<Properties, UnionKeys & keyof Properties>>);
|
|
17
|
+
type TFromObject<Type extends TObject, Key extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, Key>)>>;
|
|
18
|
+
type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
|
|
19
|
+
export type TPickResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
|
|
20
|
+
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
|
21
|
+
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
|
22
|
+
export type TPick<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TPickFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TPickFromMappedKey<Type, Key> : [
|
|
23
|
+
IsTypeRef,
|
|
24
|
+
IsKeyRef
|
|
25
|
+
] extends [true, true] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : [
|
|
26
|
+
IsTypeRef,
|
|
27
|
+
IsKeyRef
|
|
28
|
+
] extends [false, true] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : [
|
|
29
|
+
IsTypeRef,
|
|
30
|
+
IsKeyRef
|
|
31
|
+
] extends [true, false] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : TPickResolve<Type, TResolvePropertyKeys<Key>>);
|
|
22
32
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
23
|
-
export declare function Pick<
|
|
33
|
+
export declare function Pick<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
|
24
34
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
25
|
-
export declare function Pick<
|
|
35
|
+
export declare function Pick<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TPick<Type, Key>;
|
|
26
36
|
export {};
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Discard } from '../discard/discard.mjs';
|
|
3
|
+
import { Computed } from '../computed/index.mjs';
|
|
3
4
|
import { Intersect } from '../intersect/index.mjs';
|
|
4
|
-
import {
|
|
5
|
+
import { Literal } from '../literal/index.mjs';
|
|
5
6
|
import { Object } from '../object/index.mjs';
|
|
7
|
+
import { Union } from '../union/index.mjs';
|
|
6
8
|
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
7
|
-
import { PickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
8
|
-
import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
9
9
|
import { TransformKind } from '../symbols/symbols.mjs';
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
|
-
//
|
|
11
|
+
// Guards
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/kind.mjs';
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema, IsLiteralValue, IsRef } from '../guard/kind.mjs';
|
|
14
|
+
import { IsArray as IsArrayValue } from '../guard/value.mjs';
|
|
15
|
+
// ------------------------------------------------------------------
|
|
16
|
+
// Infrastructure
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
import { PickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
19
|
+
import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
20
|
+
function FromIntersect(types, propertyKeys) {
|
|
21
|
+
return types.map((type) => PickResolve(type, propertyKeys));
|
|
16
22
|
}
|
|
17
23
|
// prettier-ignore
|
|
18
|
-
function FromUnion(
|
|
19
|
-
return
|
|
24
|
+
function FromUnion(types, propertyKeys) {
|
|
25
|
+
return types.map((type) => PickResolve(type, propertyKeys));
|
|
20
26
|
}
|
|
21
27
|
// prettier-ignore
|
|
22
|
-
function FromProperties(
|
|
23
|
-
const
|
|
24
|
-
for (const K2 of
|
|
25
|
-
if (K2 in
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
+
function FromProperties(properties, propertyKeys) {
|
|
29
|
+
const result = {};
|
|
30
|
+
for (const K2 of propertyKeys)
|
|
31
|
+
if (K2 in properties)
|
|
32
|
+
result[K2] = properties[K2];
|
|
33
|
+
return result;
|
|
28
34
|
}
|
|
29
35
|
// prettier-ignore
|
|
30
36
|
function FromObject(T, K) {
|
|
@@ -32,24 +38,29 @@ function FromObject(T, K) {
|
|
|
32
38
|
const properties = FromProperties(T['properties'], K);
|
|
33
39
|
return Object(properties, options);
|
|
34
40
|
}
|
|
35
|
-
// ------------------------------------------------------------------
|
|
36
|
-
// PickResolve
|
|
37
|
-
// ------------------------------------------------------------------
|
|
38
41
|
// prettier-ignore
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
function UnionFromPropertyKeys(propertyKeys) {
|
|
43
|
+
const result = propertyKeys.reduce((result, key) => IsLiteralValue(key) ? [...result, Literal(key)] : result, []);
|
|
44
|
+
return Union(result);
|
|
45
|
+
}
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
function PickResolve(properties, propertyKeys) {
|
|
48
|
+
return (IsIntersect(properties) ? Intersect(FromIntersect(properties.allOf, propertyKeys)) :
|
|
49
|
+
IsUnion(properties) ? Union(FromUnion(properties.anyOf, propertyKeys)) :
|
|
50
|
+
IsObject(properties) ? FromObject(properties, propertyKeys) :
|
|
43
51
|
Object({}));
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
export function Pick(type, key, options) {
|
|
56
|
+
const typeKey = IsArrayValue(key) ? UnionFromPropertyKeys(key) : key;
|
|
57
|
+
const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
58
|
+
const isTypeRef = IsRef(type);
|
|
59
|
+
const isKeyRef = IsRef(key);
|
|
60
|
+
return (IsMappedResult(type) ? PickFromMappedResult(type, propertyKeys, options) :
|
|
61
|
+
IsMappedKey(key) ? PickFromMappedKey(type, key, options) :
|
|
62
|
+
(isTypeRef && isKeyRef) ? Computed('Pick', [type, typeKey], options) :
|
|
63
|
+
(!isTypeRef && isKeyRef) ? Computed('Pick', [type, typeKey], options) :
|
|
64
|
+
(isTypeRef && !isKeyRef) ? Computed('Pick', [type, typeKey], options) :
|
|
65
|
+
CreateType({ ...PickResolve(type, propertyKeys), ...options }));
|
|
55
66
|
}
|
|
@@ -2,6 +2,7 @@ import type { TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import type { Evaluate, Ensure, Assert } from '../helpers/index.mjs';
|
|
4
4
|
import { type TAny } from '../any/index.mjs';
|
|
5
|
+
import { type TComputed } from '../computed/index.mjs';
|
|
5
6
|
import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
|
|
6
7
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
7
8
|
import { type TNever } from '../never/index.mjs';
|
|
@@ -11,6 +12,7 @@ import { type TString } from '../string/index.mjs';
|
|
|
11
12
|
import { type TInteger } from '../integer/index.mjs';
|
|
12
13
|
import { type TNumber } from '../number/index.mjs';
|
|
13
14
|
import { type TEnum } from '../enum/index.mjs';
|
|
15
|
+
import { type TRef } from '../ref/index.mjs';
|
|
14
16
|
import { TIsTemplateLiteralFinite, type TTemplateLiteral } from '../template-literal/index.mjs';
|
|
15
17
|
import { Kind } from '../symbols/index.mjs';
|
|
16
18
|
type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
@@ -50,7 +52,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
|
|
|
50
52
|
};
|
|
51
53
|
additionalProperties: TAdditionalProperties;
|
|
52
54
|
}
|
|
53
|
-
export type TRecordOrObject<
|
|
55
|
+
export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = Type extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer S> ? TFromEnumKey<S, Type> : Key extends TUnion<infer S> ? TFromUnionKey<S, Type> : Key extends TLiteral<infer S> ? TFromLiteralKey<S, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever;
|
|
54
56
|
/** `[Json]` Creates a Record type */
|
|
55
|
-
export declare function Record<
|
|
57
|
+
export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
|
|
56
58
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
|
+
import { Computed } from '../computed/index.mjs';
|
|
2
3
|
import { Object } from '../object/index.mjs';
|
|
3
4
|
import { Never } from '../never/index.mjs';
|
|
4
5
|
import { Union } from '../union/index.mjs';
|
|
@@ -13,7 +14,7 @@ import { IsUndefined } from '../guard/value.mjs';
|
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
// TypeGuard
|
|
15
16
|
// ------------------------------------------------------------------
|
|
16
|
-
import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
|
|
17
|
+
import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion, IsRef } from '../guard/kind.mjs';
|
|
17
18
|
// ------------------------------------------------------------------
|
|
18
19
|
// RecordCreateFromPattern
|
|
19
20
|
// ------------------------------------------------------------------
|
|
@@ -78,16 +79,18 @@ function FromNumberKey(_, T, options) {
|
|
|
78
79
|
// TRecordOrObject
|
|
79
80
|
// ------------------------------------------------------------------
|
|
80
81
|
/** `[Json]` Creates a Record type */
|
|
81
|
-
export function Record(
|
|
82
|
+
export function Record(key, type, options = {}) {
|
|
82
83
|
// prettier-ignore
|
|
83
|
-
return (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
return (IsRef(type) ? Computed('Record', [key, type]) :
|
|
85
|
+
IsRef(key) ? Computed('Record', [key, type]) :
|
|
86
|
+
IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
|
|
87
|
+
IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
|
|
88
|
+
IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
|
|
89
|
+
IsInteger(key) ? FromIntegerKey(key, type, options) :
|
|
90
|
+
IsNumber(key) ? FromNumberKey(key, type, options) :
|
|
91
|
+
IsRegExp(key) ? FromRegExpKey(key, type, options) :
|
|
92
|
+
IsString(key) ? FromStringKey(key, type, options) :
|
|
93
|
+
IsAny(key) ? FromAnyKey(key, type, options) :
|
|
94
|
+
IsNever(key) ? FromNeverKey(key, type, options) :
|
|
95
|
+
Never(options));
|
|
93
96
|
}
|
|
@@ -2,21 +2,25 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Evaluate, Ensure } from '../helpers/index.mjs';
|
|
3
3
|
import type { TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
|
|
5
|
+
import { type TComputed } from '../computed/index.mjs';
|
|
5
6
|
import { type TOptional } from '../optional/index.mjs';
|
|
6
7
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
7
8
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
9
|
+
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
8
10
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
9
11
|
import { type TUnion } from '../union/index.mjs';
|
|
10
|
-
import { type
|
|
12
|
+
import { type TRef } from '../ref/index.mjs';
|
|
11
13
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
14
|
+
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
|
|
15
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
|
16
|
+
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
17
|
+
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
|
|
15
18
|
}>;
|
|
16
|
-
type TFromObject<
|
|
17
|
-
|
|
19
|
+
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
|
+
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
|
|
21
|
+
export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : TObject<{}>);
|
|
18
22
|
/** `[Json]` Constructs a type where all properties are required */
|
|
19
|
-
export declare function Required<
|
|
23
|
+
export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
20
24
|
/** `[Json]` Constructs a type where all properties are required */
|
|
21
|
-
export declare function Required<
|
|
25
|
+
export declare function Required<Type extends TSchema>(type: Type, options?: SchemaOptions): TRequired<Type>;
|
|
22
26
|
export {};
|