@sinclair/typebox 0.34.20 → 0.34.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/type/module/compute.d.ts +4 -4
- package/build/cjs/type/module/compute.js +54 -50
- package/build/cjs/type/partial/partial.d.ts +10 -1
- package/build/cjs/type/partial/partial.js +25 -12
- package/build/cjs/type/record/record.d.ts +2 -2
- package/build/cjs/type/required/required.d.ts +10 -1
- package/build/cjs/type/required/required.js +21 -8
- package/build/esm/type/module/compute.d.mts +4 -4
- package/build/esm/type/module/compute.mjs +15 -11
- package/build/esm/type/partial/partial.d.mts +10 -1
- package/build/esm/type/partial/partial.mjs +25 -12
- package/build/esm/type/record/record.d.mts +2 -2
- package/build/esm/type/required/required.d.mts +10 -1
- package/build/esm/type/required/required.mjs +21 -8
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ import { type TPick } from '../pick/index';
|
|
|
18
18
|
import { type TNever } from '../never/index';
|
|
19
19
|
import { TPartial } from '../partial/index';
|
|
20
20
|
import { type TReadonly } from '../readonly/index';
|
|
21
|
-
import { type TRecordOrObject } from '../record/index';
|
|
21
|
+
import { type TRecordOrObject, type TRecord } from '../record/index';
|
|
22
22
|
import { type TRef } from '../ref/index';
|
|
23
23
|
import { TRequired } from '../required/index';
|
|
24
24
|
import { type TTuple } from '../tuple/index';
|
|
@@ -31,12 +31,12 @@ type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 ex
|
|
|
31
31
|
type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
|
|
32
32
|
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
|
33
33
|
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
|
34
|
-
type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
|
|
35
34
|
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
|
36
|
-
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends '
|
|
35
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
|
37
36
|
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
|
38
37
|
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
|
39
38
|
}>>>;
|
|
39
|
+
type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
|
|
40
40
|
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
|
41
41
|
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
|
42
42
|
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
|
|
@@ -46,7 +46,7 @@ type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (E
|
|
|
46
46
|
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
47
47
|
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
48
48
|
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
49
|
-
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
49
|
+
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
50
50
|
export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
|
|
51
51
|
export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
|
52
52
|
export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
|
|
@@ -5,26 +5,27 @@ exports.FromType = FromType;
|
|
|
5
5
|
exports.ComputeType = ComputeType;
|
|
6
6
|
exports.ComputeModuleProperties = ComputeModuleProperties;
|
|
7
7
|
const index_1 = require("../create/index");
|
|
8
|
-
const index_2 = require("../
|
|
9
|
-
const index_3 = require("../
|
|
10
|
-
const index_4 = require("../
|
|
11
|
-
const index_5 = require("../
|
|
12
|
-
const index_6 = require("../
|
|
13
|
-
const index_7 = require("../
|
|
14
|
-
const index_8 = require("../
|
|
15
|
-
const index_9 = require("../
|
|
16
|
-
const index_10 = require("../
|
|
17
|
-
const index_11 = require("../
|
|
18
|
-
const index_12 = require("../
|
|
19
|
-
const index_13 = require("../
|
|
20
|
-
const index_14 = require("../
|
|
21
|
-
const index_15 = require("../
|
|
22
|
-
const index_16 = require("../
|
|
23
|
-
const index_17 = require("../
|
|
24
|
-
const index_18 = require("../
|
|
25
|
-
const index_19 = require("../
|
|
26
|
-
const index_20 = require("../
|
|
27
|
-
const index_21 = require("../
|
|
8
|
+
const index_2 = require("../clone/index");
|
|
9
|
+
const index_3 = require("../discard/index");
|
|
10
|
+
const index_4 = require("../array/index");
|
|
11
|
+
const index_5 = require("../awaited/index");
|
|
12
|
+
const index_6 = require("../async-iterator/index");
|
|
13
|
+
const index_7 = require("../constructor/index");
|
|
14
|
+
const index_8 = require("../indexed/index");
|
|
15
|
+
const index_9 = require("../function/index");
|
|
16
|
+
const index_10 = require("../intersect/index");
|
|
17
|
+
const index_11 = require("../iterator/index");
|
|
18
|
+
const index_12 = require("../keyof/index");
|
|
19
|
+
const index_13 = require("../object/index");
|
|
20
|
+
const index_14 = require("../omit/index");
|
|
21
|
+
const index_15 = require("../pick/index");
|
|
22
|
+
const index_16 = require("../never/index");
|
|
23
|
+
const index_17 = require("../partial/index");
|
|
24
|
+
const index_18 = require("../record/index");
|
|
25
|
+
const index_19 = require("../required/index");
|
|
26
|
+
const index_20 = require("../tuple/index");
|
|
27
|
+
const index_21 = require("../union/index");
|
|
28
|
+
const index_22 = require("../symbols/index");
|
|
28
29
|
// ------------------------------------------------------------------
|
|
29
30
|
// KindGuard
|
|
30
31
|
// ------------------------------------------------------------------
|
|
@@ -43,39 +44,35 @@ function Deref(moduleProperties, ref) {
|
|
|
43
44
|
? KindGuard.IsRef(moduleProperties[ref])
|
|
44
45
|
? Deref(moduleProperties, moduleProperties[ref].$ref)
|
|
45
46
|
: FromType(moduleProperties, moduleProperties[ref])
|
|
46
|
-
: (0,
|
|
47
|
+
: (0, index_16.Never)());
|
|
47
48
|
}
|
|
48
49
|
// prettier-ignore
|
|
49
50
|
function FromAwaited(parameters) {
|
|
50
|
-
return (0,
|
|
51
|
+
return (0, index_5.Awaited)(parameters[0]);
|
|
51
52
|
}
|
|
52
53
|
// prettier-ignore
|
|
53
54
|
function FromIndex(parameters) {
|
|
54
|
-
return (0,
|
|
55
|
+
return (0, index_8.Index)(parameters[0], parameters[1]);
|
|
55
56
|
}
|
|
56
57
|
// prettier-ignore
|
|
57
58
|
function FromKeyOf(parameters) {
|
|
58
|
-
return (0,
|
|
59
|
+
return (0, index_12.KeyOf)(parameters[0]);
|
|
59
60
|
}
|
|
60
61
|
// prettier-ignore
|
|
61
62
|
function FromPartial(parameters) {
|
|
62
|
-
return (0,
|
|
63
|
+
return (0, index_17.Partial)(parameters[0]);
|
|
63
64
|
}
|
|
64
65
|
// prettier-ignore
|
|
65
66
|
function FromOmit(parameters) {
|
|
66
|
-
return (0,
|
|
67
|
+
return (0, index_14.Omit)(parameters[0], parameters[1]);
|
|
67
68
|
}
|
|
68
69
|
// prettier-ignore
|
|
69
70
|
function FromPick(parameters) {
|
|
70
|
-
return (0,
|
|
71
|
-
}
|
|
72
|
-
// prettier-ignore
|
|
73
|
-
function FromRecord(parameters) {
|
|
74
|
-
return (0, index_17.Record)(parameters[0], parameters[1]);
|
|
71
|
+
return (0, index_15.Pick)(parameters[0], parameters[1]);
|
|
75
72
|
}
|
|
76
73
|
// prettier-ignore
|
|
77
74
|
function FromRequired(parameters) {
|
|
78
|
-
return (0,
|
|
75
|
+
return (0, index_19.Required)(parameters[0]);
|
|
79
76
|
}
|
|
80
77
|
// prettier-ignore
|
|
81
78
|
function FromComputed(moduleProperties, target, parameters) {
|
|
@@ -86,40 +83,46 @@ function FromComputed(moduleProperties, target, parameters) {
|
|
|
86
83
|
target === 'Partial' ? FromPartial(dereferenced) :
|
|
87
84
|
target === 'Omit' ? FromOmit(dereferenced) :
|
|
88
85
|
target === 'Pick' ? FromPick(dereferenced) :
|
|
89
|
-
target === '
|
|
90
|
-
|
|
91
|
-
(0, index_15.Never)());
|
|
86
|
+
target === 'Required' ? FromRequired(dereferenced) :
|
|
87
|
+
(0, index_16.Never)());
|
|
92
88
|
}
|
|
93
89
|
function FromObject(moduleProperties, properties) {
|
|
94
|
-
return (0,
|
|
90
|
+
return (0, index_13.Object)(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
95
91
|
return { ...result, [key]: FromType(moduleProperties, properties[key]) };
|
|
96
92
|
}, {}));
|
|
97
93
|
}
|
|
98
94
|
// prettier-ignore
|
|
95
|
+
function FromRecord(moduleProperties, type) {
|
|
96
|
+
const [value, pattern] = [FromType(moduleProperties, (0, index_18.RecordValue)(type)), (0, index_18.RecordPattern)(type)];
|
|
97
|
+
const result = (0, index_2.CloneType)(type);
|
|
98
|
+
result.patternProperties[pattern] = value;
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
// prettier-ignore
|
|
99
102
|
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
100
|
-
return (0,
|
|
103
|
+
return (0, index_7.Constructor)(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
101
104
|
}
|
|
102
105
|
// prettier-ignore
|
|
103
106
|
function FromFunction(moduleProperties, parameters, returnType) {
|
|
104
|
-
return (0,
|
|
107
|
+
return (0, index_9.Function)(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
105
108
|
}
|
|
106
109
|
function FromTuple(moduleProperties, types) {
|
|
107
|
-
return (0,
|
|
110
|
+
return (0, index_20.Tuple)(FromRest(moduleProperties, types));
|
|
108
111
|
}
|
|
109
112
|
function FromIntersect(moduleProperties, types) {
|
|
110
|
-
return (0,
|
|
113
|
+
return (0, index_10.Intersect)(FromRest(moduleProperties, types));
|
|
111
114
|
}
|
|
112
115
|
function FromUnion(moduleProperties, types) {
|
|
113
|
-
return (0,
|
|
116
|
+
return (0, index_21.Union)(FromRest(moduleProperties, types));
|
|
114
117
|
}
|
|
115
118
|
function FromArray(moduleProperties, type) {
|
|
116
|
-
return (0,
|
|
119
|
+
return (0, index_4.Array)(FromType(moduleProperties, type));
|
|
117
120
|
}
|
|
118
121
|
function FromAsyncIterator(moduleProperties, type) {
|
|
119
|
-
return (0,
|
|
122
|
+
return (0, index_6.AsyncIterator)(FromType(moduleProperties, type));
|
|
120
123
|
}
|
|
121
124
|
function FromIterator(moduleProperties, type) {
|
|
122
|
-
return (0,
|
|
125
|
+
return (0, index_11.Iterator)(FromType(moduleProperties, type));
|
|
123
126
|
}
|
|
124
127
|
function FromRest(moduleProperties, types) {
|
|
125
128
|
return types.map((type) => FromType(moduleProperties, type));
|
|
@@ -128,8 +131,8 @@ function FromRest(moduleProperties, types) {
|
|
|
128
131
|
function FromType(moduleProperties, type) {
|
|
129
132
|
return (
|
|
130
133
|
// Modifier Unwrap - Reapplied via CreateType Options
|
|
131
|
-
KindGuard.IsOptional(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0,
|
|
132
|
-
KindGuard.IsReadonly(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0,
|
|
134
|
+
KindGuard.IsOptional(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.OptionalKind])), type) :
|
|
135
|
+
KindGuard.IsReadonly(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.ReadonlyKind])), type) :
|
|
133
136
|
// Traveral
|
|
134
137
|
KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
|
|
135
138
|
KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
|
|
@@ -139,15 +142,16 @@ function FromType(moduleProperties, type) {
|
|
|
139
142
|
KindGuard.IsIntersect(type) ? (0, index_1.CreateType)(FromIntersect(moduleProperties, type.allOf), type) :
|
|
140
143
|
KindGuard.IsIterator(type) ? (0, index_1.CreateType)(FromIterator(moduleProperties, type.items), type) :
|
|
141
144
|
KindGuard.IsObject(type) ? (0, index_1.CreateType)(FromObject(moduleProperties, type.properties), type) :
|
|
142
|
-
KindGuard.
|
|
143
|
-
KindGuard.
|
|
144
|
-
type)
|
|
145
|
+
KindGuard.IsRecord(type) ? (0, index_1.CreateType)(FromRecord(moduleProperties, type)) :
|
|
146
|
+
KindGuard.IsTuple(type) ? (0, index_1.CreateType)(FromTuple(moduleProperties, type.items || []), type) :
|
|
147
|
+
KindGuard.IsUnion(type) ? (0, index_1.CreateType)(FromUnion(moduleProperties, type.anyOf), type) :
|
|
148
|
+
type);
|
|
145
149
|
}
|
|
146
150
|
// prettier-ignore
|
|
147
151
|
function ComputeType(moduleProperties, key) {
|
|
148
152
|
return (key in moduleProperties
|
|
149
153
|
? FromType(moduleProperties, moduleProperties[key])
|
|
150
|
-
: (0,
|
|
154
|
+
: (0, index_16.Never)());
|
|
151
155
|
}
|
|
152
156
|
// prettier-ignore
|
|
153
157
|
function ComputeModuleProperties(moduleProperties) {
|
|
@@ -10,6 +10,15 @@ import { type TObject, type TProperties } from '../object/index';
|
|
|
10
10
|
import { type TIntersect } from '../intersect/index';
|
|
11
11
|
import { type TUnion } from '../union/index';
|
|
12
12
|
import { type TRef } from '../ref/index';
|
|
13
|
+
import { type TBigInt } from '../bigint/index';
|
|
14
|
+
import { type TBoolean } from '../boolean/index';
|
|
15
|
+
import { type TInteger } from '../integer/index';
|
|
16
|
+
import { type TLiteral } from '../literal/index';
|
|
17
|
+
import { type TNull } from '../null/index';
|
|
18
|
+
import { type TNumber } from '../number/index';
|
|
19
|
+
import { type TString } from '../string/index';
|
|
20
|
+
import { type TSymbol } from '../symbol/index';
|
|
21
|
+
import { type TUndefined } from '../undefined/index';
|
|
13
22
|
import { type TPartialFromMappedResult } from './partial-from-mapped-result';
|
|
14
23
|
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Partial', [TComputed<Target, Parameters>]>>;
|
|
15
24
|
type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
|
|
@@ -18,7 +27,7 @@ type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
|
18
27
|
}>;
|
|
19
28
|
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
29
|
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<
|
|
30
|
+
export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<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>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
22
31
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
23
32
|
export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
24
33
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
@@ -13,9 +13,9 @@ const index_7 = require("../discard/index");
|
|
|
13
13
|
const index_8 = require("../symbols/index");
|
|
14
14
|
const partial_from_mapped_result_1 = require("./partial-from-mapped-result");
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
//
|
|
16
|
+
// KindGuard
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
|
-
const
|
|
18
|
+
const KindGuard = require("../guard/kind");
|
|
19
19
|
// prettier-ignore
|
|
20
20
|
function FromComputed(target, parameters) {
|
|
21
21
|
return (0, index_1.Computed)('Partial', [(0, index_1.Computed)(target, parameters)]);
|
|
@@ -32,9 +32,9 @@ function FromProperties(properties) {
|
|
|
32
32
|
return partialProperties;
|
|
33
33
|
}
|
|
34
34
|
// prettier-ignore
|
|
35
|
-
function FromObject(
|
|
36
|
-
const options = (0, index_7.Discard)(
|
|
37
|
-
const properties = FromProperties(
|
|
35
|
+
function FromObject(type) {
|
|
36
|
+
const options = (0, index_7.Discard)(type, [index_8.TransformKind, '$id', 'required', 'properties']);
|
|
37
|
+
const properties = FromProperties(type['properties']);
|
|
38
38
|
return (0, index_3.Object)(properties, options);
|
|
39
39
|
}
|
|
40
40
|
// prettier-ignore
|
|
@@ -46,16 +46,29 @@ function FromRest(types) {
|
|
|
46
46
|
// ------------------------------------------------------------------
|
|
47
47
|
// prettier-ignore
|
|
48
48
|
function PartialResolve(type) {
|
|
49
|
-
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
return (
|
|
50
|
+
// Mappable
|
|
51
|
+
KindGuard.IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
52
|
+
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
53
|
+
KindGuard.IsIntersect(type) ? (0, index_4.Intersect)(FromRest(type.allOf)) :
|
|
54
|
+
KindGuard.IsUnion(type) ? (0, index_5.Union)(FromRest(type.anyOf)) :
|
|
55
|
+
KindGuard.IsObject(type) ? FromObject(type) :
|
|
56
|
+
// Intrinsic
|
|
57
|
+
KindGuard.IsBigInt(type) ? type :
|
|
58
|
+
KindGuard.IsBoolean(type) ? type :
|
|
59
|
+
KindGuard.IsInteger(type) ? type :
|
|
60
|
+
KindGuard.IsLiteral(type) ? type :
|
|
61
|
+
KindGuard.IsNull(type) ? type :
|
|
62
|
+
KindGuard.IsNumber(type) ? type :
|
|
63
|
+
KindGuard.IsString(type) ? type :
|
|
64
|
+
KindGuard.IsSymbol(type) ? type :
|
|
65
|
+
KindGuard.IsUndefined(type) ? type :
|
|
66
|
+
// Passthrough
|
|
67
|
+
(0, index_3.Object)({}));
|
|
55
68
|
}
|
|
56
69
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
57
70
|
function Partial(type, options) {
|
|
58
|
-
if (
|
|
71
|
+
if (KindGuard.IsMappedResult(type)) {
|
|
59
72
|
return (0, partial_from_mapped_result_1.PartialFromMappedResult)(type, options);
|
|
60
73
|
}
|
|
61
74
|
else {
|
|
@@ -61,11 +61,11 @@ export declare function Record<Key extends TSchema, Type extends TSchema>(key: K
|
|
|
61
61
|
/** Gets the Records Pattern */
|
|
62
62
|
export declare function RecordPattern(record: TRecord): string;
|
|
63
63
|
/** Gets the Records Key Type */
|
|
64
|
-
export type TRecordKey<Type extends TRecord
|
|
64
|
+
export type TRecordKey<Type extends TRecord, Result extends TSchema = Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString> = Result;
|
|
65
65
|
/** Gets the Records Key Type */
|
|
66
66
|
export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
|
|
67
67
|
/** Gets a Record Value Type */
|
|
68
|
-
export type TRecordValue<Type extends TRecord
|
|
68
|
+
export type TRecordValue<Type extends TRecord, Result extends TSchema = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever)> = Result;
|
|
69
69
|
/** Gets a Record Value Type */
|
|
70
70
|
export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
|
|
71
71
|
export {};
|
|
@@ -10,6 +10,15 @@ import { type TObject, type TProperties } from '../object/index';
|
|
|
10
10
|
import { type TIntersect } from '../intersect/index';
|
|
11
11
|
import { type TUnion } from '../union/index';
|
|
12
12
|
import { type TRef } from '../ref/index';
|
|
13
|
+
import { type TBigInt } from '../bigint/index';
|
|
14
|
+
import { type TBoolean } from '../boolean/index';
|
|
15
|
+
import { type TInteger } from '../integer/index';
|
|
16
|
+
import { type TLiteral } from '../literal/index';
|
|
17
|
+
import { type TNull } from '../null/index';
|
|
18
|
+
import { type TNumber } from '../number/index';
|
|
19
|
+
import { type TString } from '../string/index';
|
|
20
|
+
import { type TSymbol } from '../symbol/index';
|
|
21
|
+
import { type TUndefined } from '../undefined/index';
|
|
13
22
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result';
|
|
14
23
|
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
|
|
15
24
|
type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
|
@@ -18,7 +27,7 @@ type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
|
18
27
|
}>;
|
|
19
28
|
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
29
|
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<{}>);
|
|
30
|
+
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>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
22
31
|
/** `[Json]` Constructs a type where all properties are required */
|
|
23
32
|
export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
24
33
|
/** `[Json]` Constructs a type where all properties are required */
|
|
@@ -14,7 +14,7 @@ const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
// TypeGuard
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
-
const
|
|
17
|
+
const KindGuard = require("../guard/kind");
|
|
18
18
|
// prettier-ignore
|
|
19
19
|
function FromComputed(target, parameters) {
|
|
20
20
|
return (0, index_1.Computed)('Required', [(0, index_1.Computed)(target, parameters)]);
|
|
@@ -45,16 +45,29 @@ function FromRest(types) {
|
|
|
45
45
|
// ------------------------------------------------------------------
|
|
46
46
|
// prettier-ignore
|
|
47
47
|
function RequiredResolve(type) {
|
|
48
|
-
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
return (
|
|
49
|
+
// Mappable
|
|
50
|
+
KindGuard.IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
51
|
+
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
52
|
+
KindGuard.IsIntersect(type) ? (0, index_3.Intersect)(FromRest(type.allOf)) :
|
|
53
|
+
KindGuard.IsUnion(type) ? (0, index_4.Union)(FromRest(type.anyOf)) :
|
|
54
|
+
KindGuard.IsObject(type) ? FromObject(type) :
|
|
55
|
+
// Intrinsic
|
|
56
|
+
KindGuard.IsBigInt(type) ? type :
|
|
57
|
+
KindGuard.IsBoolean(type) ? type :
|
|
58
|
+
KindGuard.IsInteger(type) ? type :
|
|
59
|
+
KindGuard.IsLiteral(type) ? type :
|
|
60
|
+
KindGuard.IsNull(type) ? type :
|
|
61
|
+
KindGuard.IsNumber(type) ? type :
|
|
62
|
+
KindGuard.IsString(type) ? type :
|
|
63
|
+
KindGuard.IsSymbol(type) ? type :
|
|
64
|
+
KindGuard.IsUndefined(type) ? type :
|
|
65
|
+
// Passthrough
|
|
66
|
+
(0, index_2.Object)({}));
|
|
54
67
|
}
|
|
55
68
|
/** `[Json]` Constructs a type where all properties are required */
|
|
56
69
|
function Required(type, options) {
|
|
57
|
-
if (
|
|
70
|
+
if (KindGuard.IsMappedResult(type)) {
|
|
58
71
|
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(type, options);
|
|
59
72
|
}
|
|
60
73
|
else {
|
|
@@ -18,7 +18,7 @@ import { type TPick } from '../pick/index.mjs';
|
|
|
18
18
|
import { type TNever } from '../never/index.mjs';
|
|
19
19
|
import { TPartial } from '../partial/index.mjs';
|
|
20
20
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
21
|
-
import { type TRecordOrObject } from '../record/index.mjs';
|
|
21
|
+
import { type TRecordOrObject, type TRecord } from '../record/index.mjs';
|
|
22
22
|
import { type TRef } from '../ref/index.mjs';
|
|
23
23
|
import { TRequired } from '../required/index.mjs';
|
|
24
24
|
import { type TTuple } from '../tuple/index.mjs';
|
|
@@ -31,12 +31,12 @@ type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 ex
|
|
|
31
31
|
type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
|
|
32
32
|
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
|
33
33
|
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
|
34
|
-
type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
|
|
35
34
|
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
|
36
|
-
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends '
|
|
35
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
|
37
36
|
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
|
38
37
|
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
|
39
38
|
}>>>;
|
|
39
|
+
type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
|
|
40
40
|
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
|
41
41
|
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
|
42
42
|
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
|
|
@@ -46,7 +46,7 @@ type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (E
|
|
|
46
46
|
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
47
47
|
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
48
48
|
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
49
|
-
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
49
|
+
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
50
50
|
export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
|
|
51
51
|
export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
|
52
52
|
export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateType } from '../create/index.mjs';
|
|
2
|
+
import { CloneType } from '../clone/index.mjs';
|
|
2
3
|
import { Discard } from '../discard/index.mjs';
|
|
3
4
|
import { Array } from '../array/index.mjs';
|
|
4
5
|
import { Awaited } from '../awaited/index.mjs';
|
|
@@ -14,7 +15,7 @@ import { Omit } from '../omit/index.mjs';
|
|
|
14
15
|
import { Pick } from '../pick/index.mjs';
|
|
15
16
|
import { Never } from '../never/index.mjs';
|
|
16
17
|
import { Partial } from '../partial/index.mjs';
|
|
17
|
-
import {
|
|
18
|
+
import { RecordValue, RecordPattern } from '../record/index.mjs';
|
|
18
19
|
import { Required } from '../required/index.mjs';
|
|
19
20
|
import { Tuple } from '../tuple/index.mjs';
|
|
20
21
|
import { Union } from '../union/index.mjs';
|
|
@@ -64,10 +65,6 @@ function FromPick(parameters) {
|
|
|
64
65
|
return Pick(parameters[0], parameters[1]);
|
|
65
66
|
}
|
|
66
67
|
// prettier-ignore
|
|
67
|
-
function FromRecord(parameters) {
|
|
68
|
-
return Record(parameters[0], parameters[1]);
|
|
69
|
-
}
|
|
70
|
-
// prettier-ignore
|
|
71
68
|
function FromRequired(parameters) {
|
|
72
69
|
return Required(parameters[0]);
|
|
73
70
|
}
|
|
@@ -80,9 +77,8 @@ function FromComputed(moduleProperties, target, parameters) {
|
|
|
80
77
|
target === 'Partial' ? FromPartial(dereferenced) :
|
|
81
78
|
target === 'Omit' ? FromOmit(dereferenced) :
|
|
82
79
|
target === 'Pick' ? FromPick(dereferenced) :
|
|
83
|
-
target === '
|
|
84
|
-
|
|
85
|
-
Never());
|
|
80
|
+
target === 'Required' ? FromRequired(dereferenced) :
|
|
81
|
+
Never());
|
|
86
82
|
}
|
|
87
83
|
function FromObject(moduleProperties, properties) {
|
|
88
84
|
return Object(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
@@ -90,6 +86,13 @@ function FromObject(moduleProperties, properties) {
|
|
|
90
86
|
}, {}));
|
|
91
87
|
}
|
|
92
88
|
// prettier-ignore
|
|
89
|
+
function FromRecord(moduleProperties, type) {
|
|
90
|
+
const [value, pattern] = [FromType(moduleProperties, RecordValue(type)), RecordPattern(type)];
|
|
91
|
+
const result = CloneType(type);
|
|
92
|
+
result.patternProperties[pattern] = value;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
// prettier-ignore
|
|
93
96
|
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
94
97
|
return Constructor(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
95
98
|
}
|
|
@@ -133,9 +136,10 @@ export function FromType(moduleProperties, type) {
|
|
|
133
136
|
KindGuard.IsIntersect(type) ? CreateType(FromIntersect(moduleProperties, type.allOf), type) :
|
|
134
137
|
KindGuard.IsIterator(type) ? CreateType(FromIterator(moduleProperties, type.items), type) :
|
|
135
138
|
KindGuard.IsObject(type) ? CreateType(FromObject(moduleProperties, type.properties), type) :
|
|
136
|
-
KindGuard.
|
|
137
|
-
KindGuard.
|
|
138
|
-
type)
|
|
139
|
+
KindGuard.IsRecord(type) ? CreateType(FromRecord(moduleProperties, type)) :
|
|
140
|
+
KindGuard.IsTuple(type) ? CreateType(FromTuple(moduleProperties, type.items || []), type) :
|
|
141
|
+
KindGuard.IsUnion(type) ? CreateType(FromUnion(moduleProperties, type.anyOf), type) :
|
|
142
|
+
type);
|
|
139
143
|
}
|
|
140
144
|
// prettier-ignore
|
|
141
145
|
export function ComputeType(moduleProperties, key) {
|
|
@@ -10,6 +10,15 @@ import { type TObject, type TProperties } from '../object/index.mjs';
|
|
|
10
10
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
11
11
|
import { type TUnion } from '../union/index.mjs';
|
|
12
12
|
import { type TRef } from '../ref/index.mjs';
|
|
13
|
+
import { type TBigInt } from '../bigint/index.mjs';
|
|
14
|
+
import { type TBoolean } from '../boolean/index.mjs';
|
|
15
|
+
import { type TInteger } from '../integer/index.mjs';
|
|
16
|
+
import { type TLiteral } from '../literal/index.mjs';
|
|
17
|
+
import { type TNull } from '../null/index.mjs';
|
|
18
|
+
import { type TNumber } from '../number/index.mjs';
|
|
19
|
+
import { type TString } from '../string/index.mjs';
|
|
20
|
+
import { type TSymbol } from '../symbol/index.mjs';
|
|
21
|
+
import { type TUndefined } from '../undefined/index.mjs';
|
|
13
22
|
import { type TPartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
14
23
|
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Partial', [TComputed<Target, Parameters>]>>;
|
|
15
24
|
type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
|
|
@@ -18,7 +27,7 @@ type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
|
18
27
|
}>;
|
|
19
28
|
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
29
|
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<
|
|
30
|
+
export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<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>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
22
31
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
23
32
|
export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
24
33
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
@@ -9,9 +9,9 @@ import { Discard } from '../discard/index.mjs';
|
|
|
9
9
|
import { TransformKind } from '../symbols/index.mjs';
|
|
10
10
|
import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
|
-
//
|
|
12
|
+
// KindGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
|
-
import
|
|
14
|
+
import * as KindGuard from '../guard/kind.mjs';
|
|
15
15
|
// prettier-ignore
|
|
16
16
|
function FromComputed(target, parameters) {
|
|
17
17
|
return Computed('Partial', [Computed(target, parameters)]);
|
|
@@ -28,9 +28,9 @@ function FromProperties(properties) {
|
|
|
28
28
|
return partialProperties;
|
|
29
29
|
}
|
|
30
30
|
// prettier-ignore
|
|
31
|
-
function FromObject(
|
|
32
|
-
const options = Discard(
|
|
33
|
-
const properties = FromProperties(
|
|
31
|
+
function FromObject(type) {
|
|
32
|
+
const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
|
|
33
|
+
const properties = FromProperties(type['properties']);
|
|
34
34
|
return Object(properties, options);
|
|
35
35
|
}
|
|
36
36
|
// prettier-ignore
|
|
@@ -42,16 +42,29 @@ function FromRest(types) {
|
|
|
42
42
|
// ------------------------------------------------------------------
|
|
43
43
|
// prettier-ignore
|
|
44
44
|
function PartialResolve(type) {
|
|
45
|
-
return (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
return (
|
|
46
|
+
// Mappable
|
|
47
|
+
KindGuard.IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
48
|
+
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
49
|
+
KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
50
|
+
KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
51
|
+
KindGuard.IsObject(type) ? FromObject(type) :
|
|
52
|
+
// Intrinsic
|
|
53
|
+
KindGuard.IsBigInt(type) ? type :
|
|
54
|
+
KindGuard.IsBoolean(type) ? type :
|
|
55
|
+
KindGuard.IsInteger(type) ? type :
|
|
56
|
+
KindGuard.IsLiteral(type) ? type :
|
|
57
|
+
KindGuard.IsNull(type) ? type :
|
|
58
|
+
KindGuard.IsNumber(type) ? type :
|
|
59
|
+
KindGuard.IsString(type) ? type :
|
|
60
|
+
KindGuard.IsSymbol(type) ? type :
|
|
61
|
+
KindGuard.IsUndefined(type) ? type :
|
|
62
|
+
// Passthrough
|
|
63
|
+
Object({}));
|
|
51
64
|
}
|
|
52
65
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
53
66
|
export function Partial(type, options) {
|
|
54
|
-
if (IsMappedResult(type)) {
|
|
67
|
+
if (KindGuard.IsMappedResult(type)) {
|
|
55
68
|
return PartialFromMappedResult(type, options);
|
|
56
69
|
}
|
|
57
70
|
else {
|
|
@@ -61,11 +61,11 @@ export declare function Record<Key extends TSchema, Type extends TSchema>(key: K
|
|
|
61
61
|
/** Gets the Records Pattern */
|
|
62
62
|
export declare function RecordPattern(record: TRecord): string;
|
|
63
63
|
/** Gets the Records Key Type */
|
|
64
|
-
export type TRecordKey<Type extends TRecord
|
|
64
|
+
export type TRecordKey<Type extends TRecord, Result extends TSchema = Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString> = Result;
|
|
65
65
|
/** Gets the Records Key Type */
|
|
66
66
|
export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
|
|
67
67
|
/** Gets a Record Value Type */
|
|
68
|
-
export type TRecordValue<Type extends TRecord
|
|
68
|
+
export type TRecordValue<Type extends TRecord, Result extends TSchema = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever)> = Result;
|
|
69
69
|
/** Gets a Record Value Type */
|
|
70
70
|
export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
|
|
71
71
|
export {};
|
|
@@ -10,6 +10,15 @@ import { type TObject, type TProperties } from '../object/index.mjs';
|
|
|
10
10
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
11
11
|
import { type TUnion } from '../union/index.mjs';
|
|
12
12
|
import { type TRef } from '../ref/index.mjs';
|
|
13
|
+
import { type TBigInt } from '../bigint/index.mjs';
|
|
14
|
+
import { type TBoolean } from '../boolean/index.mjs';
|
|
15
|
+
import { type TInteger } from '../integer/index.mjs';
|
|
16
|
+
import { type TLiteral } from '../literal/index.mjs';
|
|
17
|
+
import { type TNull } from '../null/index.mjs';
|
|
18
|
+
import { type TNumber } from '../number/index.mjs';
|
|
19
|
+
import { type TString } from '../string/index.mjs';
|
|
20
|
+
import { type TSymbol } from '../symbol/index.mjs';
|
|
21
|
+
import { type TUndefined } from '../undefined/index.mjs';
|
|
13
22
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
14
23
|
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
|
|
15
24
|
type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
|
@@ -18,7 +27,7 @@ type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
|
18
27
|
}>;
|
|
19
28
|
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
29
|
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<{}>);
|
|
30
|
+
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>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
22
31
|
/** `[Json]` Constructs a type where all properties are required */
|
|
23
32
|
export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
24
33
|
/** `[Json]` Constructs a type where all properties are required */
|
|
@@ -10,7 +10,7 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// TypeGuard
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
import
|
|
13
|
+
import * as KindGuard from '../guard/kind.mjs';
|
|
14
14
|
// prettier-ignore
|
|
15
15
|
function FromComputed(target, parameters) {
|
|
16
16
|
return Computed('Required', [Computed(target, parameters)]);
|
|
@@ -41,16 +41,29 @@ function FromRest(types) {
|
|
|
41
41
|
// ------------------------------------------------------------------
|
|
42
42
|
// prettier-ignore
|
|
43
43
|
function RequiredResolve(type) {
|
|
44
|
-
return (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
return (
|
|
45
|
+
// Mappable
|
|
46
|
+
KindGuard.IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
47
|
+
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
48
|
+
KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
49
|
+
KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
50
|
+
KindGuard.IsObject(type) ? FromObject(type) :
|
|
51
|
+
// Intrinsic
|
|
52
|
+
KindGuard.IsBigInt(type) ? type :
|
|
53
|
+
KindGuard.IsBoolean(type) ? type :
|
|
54
|
+
KindGuard.IsInteger(type) ? type :
|
|
55
|
+
KindGuard.IsLiteral(type) ? type :
|
|
56
|
+
KindGuard.IsNull(type) ? type :
|
|
57
|
+
KindGuard.IsNumber(type) ? type :
|
|
58
|
+
KindGuard.IsString(type) ? type :
|
|
59
|
+
KindGuard.IsSymbol(type) ? type :
|
|
60
|
+
KindGuard.IsUndefined(type) ? type :
|
|
61
|
+
// Passthrough
|
|
62
|
+
Object({}));
|
|
50
63
|
}
|
|
51
64
|
/** `[Json]` Constructs a type where all properties are required */
|
|
52
65
|
export function Required(type, options) {
|
|
53
|
-
if (IsMappedResult(type)) {
|
|
66
|
+
if (KindGuard.IsMappedResult(type)) {
|
|
54
67
|
return RequiredFromMappedResult(type, options);
|
|
55
68
|
}
|
|
56
69
|
else {
|