@sinclair/typebox 0.34.21 → 0.34.23
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/index.d.ts +0 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/syntax/runtime.js +10 -3
- package/build/cjs/syntax/static.d.ts +1 -1
- package/build/cjs/type/instantiate/instantiate.d.ts +43 -18
- package/build/cjs/type/instantiate/instantiate.js +104 -17
- package/build/cjs/type/partial/partial.d.ts +10 -1
- package/build/cjs/type/partial/partial.js +25 -12
- package/build/cjs/type/required/required.d.ts +10 -1
- package/build/cjs/type/required/required.js +21 -8
- package/build/cjs/type/type/type.d.ts +0 -1
- package/build/cjs/type/type/type.js +30 -32
- package/build/esm/index.d.mts +0 -1
- package/build/esm/index.mjs +0 -1
- package/build/esm/syntax/runtime.mjs +10 -3
- package/build/esm/syntax/static.d.mts +1 -1
- package/build/esm/type/instantiate/instantiate.d.mts +43 -18
- package/build/esm/type/instantiate/instantiate.mjs +103 -17
- package/build/esm/type/partial/partial.d.mts +10 -1
- package/build/esm/type/partial/partial.mjs +25 -12
- package/build/esm/type/required/required.d.mts +10 -1
- package/build/esm/type/required/required.mjs +21 -8
- package/build/esm/type/type/type.d.mts +0 -1
- package/build/esm/type/type/type.mjs +0 -1
- package/package.json +1 -1
- package/readme.md +79 -64
- package/build/cjs/type/remap/index.d.ts +0 -1
- package/build/cjs/type/remap/index.js +0 -18
- package/build/cjs/type/remap/remap.d.ts +0 -30
- package/build/cjs/type/remap/remap.js +0 -47
- package/build/esm/type/remap/index.d.mts +0 -1
- package/build/esm/type/remap/index.mjs +0 -1
- package/build/esm/type/remap/remap.d.mts +0 -30
- package/build/esm/type/remap/remap.mjs +0 -43
package/build/cjs/index.d.ts
CHANGED
|
@@ -52,7 +52,6 @@ export * from './type/record/index';
|
|
|
52
52
|
export * from './type/recursive/index';
|
|
53
53
|
export * from './type/ref/index';
|
|
54
54
|
export * from './type/regexp/index';
|
|
55
|
-
export * from './type/remap/index';
|
|
56
55
|
export * from './type/required/index';
|
|
57
56
|
export * from './type/rest/index';
|
|
58
57
|
export * from './type/return-type/index';
|
package/build/cjs/index.js
CHANGED
|
@@ -75,7 +75,6 @@ __exportStar(require("./type/record/index"), exports);
|
|
|
75
75
|
__exportStar(require("./type/recursive/index"), exports);
|
|
76
76
|
__exportStar(require("./type/ref/index"), exports);
|
|
77
77
|
__exportStar(require("./type/regexp/index"), exports);
|
|
78
|
-
__exportStar(require("./type/remap/index"), exports);
|
|
79
78
|
__exportStar(require("./type/required/index"), exports);
|
|
80
79
|
__exportStar(require("./type/rest/index"), exports);
|
|
81
80
|
__exportStar(require("./type/return-type/index"), exports);
|
|
@@ -43,10 +43,17 @@ const Dereference = (context, key) => {
|
|
|
43
43
|
// GenericReference
|
|
44
44
|
// ------------------------------------------------------------------
|
|
45
45
|
function GenericReferenceMapping(results, context) {
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const type = Dereference(context, results[0]);
|
|
47
|
+
const args = results[2];
|
|
48
|
+
return t.Instantiate(type, args);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
const GenericReference = index_1.Runtime.Tuple([
|
|
52
|
+
index_1.Runtime.Ident(),
|
|
53
|
+
index_1.Runtime.Const(LAngle),
|
|
54
|
+
index_1.Runtime.Ref('Elements'),
|
|
55
|
+
index_1.Runtime.Const(RAngle)
|
|
56
|
+
], (results, context) => GenericReferenceMapping(results, context));
|
|
50
57
|
// ------------------------------------------------------------------
|
|
51
58
|
// Reference
|
|
52
59
|
// ------------------------------------------------------------------
|
|
@@ -43,7 +43,7 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
|
|
|
43
43
|
], DelimitMapping>);
|
|
44
44
|
type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
|
|
45
45
|
interface GenericReferenceMapping extends Static.IMapping {
|
|
46
|
-
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer
|
|
46
|
+
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Args extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, Args> : never : never;
|
|
47
47
|
}
|
|
48
48
|
type GenericReference = Static.Tuple<[
|
|
49
49
|
Static.Ident,
|
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type TSchema } from '../schema/index';
|
|
2
|
+
import { type TArgument } from '../argument/index';
|
|
3
3
|
import { type TNever } from '../never/index';
|
|
4
4
|
import { type TReadonlyOptional } from '../readonly-optional/index';
|
|
5
5
|
import { type TReadonly } from '../readonly/index';
|
|
6
6
|
import { type TOptional } from '../optional/index';
|
|
7
|
-
import { type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
import { type TConstructor } from '../constructor/index';
|
|
8
|
+
import { type TFunction } from '../function/index';
|
|
9
|
+
import { type TIntersect } from '../intersect/index';
|
|
10
|
+
import { type TUnion } from '../union/index';
|
|
11
|
+
import { type TTuple } from '../tuple/index';
|
|
12
|
+
import { type TArray } from '../array/index';
|
|
13
|
+
import { type TAsyncIterator } from '../async-iterator/index';
|
|
14
|
+
import { type TIterator } from '../iterator/index';
|
|
15
|
+
import { type TPromise } from '../promise/index';
|
|
16
|
+
import { type TObject, type TProperties } from '../object/index';
|
|
17
|
+
import { type TRecordOrObject, type TRecord } from '../record/index';
|
|
18
|
+
type TFromConstructor<Args extends TSchema[], Parameters extends TSchema[], InstanceType extends TSchema, Result extends TConstructor = TConstructor<TFromTypes<Args, Parameters>, TFromType<Args, InstanceType>>> = Result;
|
|
19
|
+
type TFromFunction<Args extends TSchema[], Parameters extends TSchema[], ReturnType extends TSchema, Result extends TFunction = TFunction<TFromTypes<Args, Parameters>, TFromType<Args, ReturnType>>> = Result;
|
|
20
|
+
type TFromIntersect<Args extends TSchema[], Types extends TSchema[], Result extends TIntersect = TIntersect<TFromTypes<Args, Types>>> = Result;
|
|
21
|
+
type TFromUnion<Args extends TSchema[], Types extends TSchema[], Result extends TUnion = TUnion<TFromTypes<Args, Types>>> = Result;
|
|
22
|
+
type TFromTuple<Args extends TSchema[], Types extends TSchema[], Result extends TTuple = TTuple<TFromTypes<Args, Types>>> = Result;
|
|
23
|
+
type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TArray = TArray<TFromType<Args, Type>>> = Result;
|
|
24
|
+
type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
|
|
25
|
+
type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
|
|
26
|
+
type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
|
|
27
|
+
type TFromObject<Args extends TSchema[], Properties extends TProperties, Result extends TObject = TObject<TFromProperties<Args, Properties>>> = Result;
|
|
28
|
+
type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
|
|
29
|
+
type TFromArgument<Args extends TSchema[], Index extends number> = (Index extends keyof Args ? Args[Index] : TNever);
|
|
30
|
+
type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
|
|
31
|
+
IsReadonly,
|
|
32
|
+
IsOptional
|
|
33
|
+
] extends [true, true] ? TReadonlyOptional<Mapped> : [
|
|
34
|
+
IsReadonly,
|
|
35
|
+
IsOptional
|
|
36
|
+
] extends [true, false] ? TReadonly<Mapped> : [
|
|
37
|
+
IsReadonly,
|
|
38
|
+
IsOptional
|
|
39
|
+
] extends [false, true] ? TOptional<Mapped> : Mapped)> = Result;
|
|
40
|
+
type TFromProperties<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = {
|
|
41
|
+
[Key in keyof Properties]: TFromProperty<Args, Properties[Key]>;
|
|
42
|
+
}> = Result;
|
|
43
|
+
export type TFromTypes<Args extends TSchema[], Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Args, Right, [...Result, TFromType<Args, Left>]> : Result);
|
|
44
|
+
export declare function FromTypes<Args extends TSchema[], Types extends TSchema[]>(args: [...Args], types: [...Types]): TFromTypes<Args, Types>;
|
|
45
|
+
export type TFromType<Args extends TSchema[], Type extends TSchema> = (Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<Args, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<Args, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Args, Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Args, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Args, Types> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Args, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<Args, Type> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<Args, Type> : Type extends TPromise<infer Type extends TSchema> ? TFromPromise<Args, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Args, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<Args, Key, Value> : Type extends TArgument<infer Index extends number> ? TFromArgument<Args, Index> : Type);
|
|
21
46
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
22
|
-
export type TInstantiate<Type extends TSchema,
|
|
47
|
+
export type TInstantiate<Type extends TSchema, Args extends TSchema[], Result extends TSchema = TFromType<Args, Type>> = Result;
|
|
23
48
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
24
|
-
export declare function Instantiate<Type extends TSchema,
|
|
49
|
+
export declare function Instantiate<Type extends TSchema, Args extends TSchema[]>(type: Type, args: [...Args]): TInstantiate<Type, Args>;
|
|
25
50
|
export {};
|
|
@@ -1,32 +1,119 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FromTypes = FromTypes;
|
|
4
5
|
exports.Instantiate = Instantiate;
|
|
6
|
+
const type_1 = require("../clone/type");
|
|
5
7
|
const index_1 = require("../never/index");
|
|
6
8
|
const index_2 = require("../readonly-optional/index");
|
|
7
9
|
const index_3 = require("../readonly/index");
|
|
8
10
|
const index_4 = require("../optional/index");
|
|
9
|
-
const index_5 = require("../
|
|
11
|
+
const index_5 = require("../record/index");
|
|
12
|
+
const ValueGuard = require("../guard/value");
|
|
10
13
|
const KindGuard = require("../guard/kind");
|
|
11
14
|
// prettier-ignore
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function FromConstructor(args, type) {
|
|
16
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
17
|
+
type.returns = FromType(args, type.returns);
|
|
18
|
+
return type;
|
|
19
|
+
}
|
|
20
|
+
// prettier-ignore
|
|
21
|
+
function FromFunction(args, type) {
|
|
22
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
23
|
+
type.returns = FromType(args, type.returns);
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
function FromIntersect(args, type) {
|
|
28
|
+
type.allOf = FromTypes(args, type.allOf);
|
|
29
|
+
return type;
|
|
30
|
+
}
|
|
31
|
+
// prettier-ignore
|
|
32
|
+
function FromUnion(args, type) {
|
|
33
|
+
type.anyOf = FromTypes(args, type.anyOf);
|
|
34
|
+
return type;
|
|
35
|
+
}
|
|
36
|
+
// prettier-ignore
|
|
37
|
+
function FromTuple(args, type) {
|
|
38
|
+
if (ValueGuard.IsUndefined(type.items))
|
|
39
|
+
return type;
|
|
40
|
+
type.items = FromTypes(args, type.items);
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
// prettier-ignore
|
|
44
|
+
function FromArray(args, type) {
|
|
45
|
+
type.items = FromType(args, type.items);
|
|
46
|
+
return type;
|
|
47
|
+
}
|
|
48
|
+
// prettier-ignore
|
|
49
|
+
function FromAsyncIterator(args, type) {
|
|
50
|
+
type.items = FromType(args, type.items);
|
|
51
|
+
return type;
|
|
52
|
+
}
|
|
53
|
+
// prettier-ignore
|
|
54
|
+
function FromIterator(args, type) {
|
|
55
|
+
type.items = FromType(args, type.items);
|
|
56
|
+
return type;
|
|
57
|
+
}
|
|
58
|
+
// prettier-ignore
|
|
59
|
+
function FromPromise(args, type) {
|
|
60
|
+
type.item = FromType(args, type.item);
|
|
61
|
+
return type;
|
|
62
|
+
}
|
|
63
|
+
// prettier-ignore
|
|
64
|
+
function FromObject(args, type) {
|
|
65
|
+
type.properties = FromProperties(args, type.properties);
|
|
66
|
+
return type;
|
|
67
|
+
}
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
function FromRecord(args, type) {
|
|
70
|
+
const mappedKey = FromType(args, (0, index_5.RecordKey)(type));
|
|
71
|
+
const mappedValue = FromType(args, (0, index_5.RecordValue)(type));
|
|
72
|
+
const result = (0, index_5.Record)(mappedKey, mappedValue);
|
|
73
|
+
return { ...type, ...result }; // retain options
|
|
74
|
+
}
|
|
75
|
+
// prettier-ignore
|
|
76
|
+
function FromArgument(args, argument) {
|
|
77
|
+
return argument.index in args ? args[argument.index] : (0, index_1.Never)();
|
|
78
|
+
}
|
|
79
|
+
// prettier-ignore
|
|
80
|
+
function FromProperty(args, type) {
|
|
81
|
+
const isReadonly = KindGuard.IsReadonly(type);
|
|
82
|
+
const isOptional = KindGuard.IsOptional(type);
|
|
83
|
+
const mapped = FromType(args, type);
|
|
84
|
+
return (isReadonly && isOptional ? (0, index_2.ReadonlyOptional)(mapped) :
|
|
85
|
+
isReadonly && !isOptional ? (0, index_3.Readonly)(mapped) :
|
|
86
|
+
!isReadonly && isOptional ? (0, index_4.Optional)(mapped) :
|
|
87
|
+
mapped);
|
|
88
|
+
}
|
|
89
|
+
// prettier-ignore
|
|
90
|
+
function FromProperties(args, properties) {
|
|
91
|
+
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
92
|
+
return { ...result, [key]: FromProperty(args, properties[key]) };
|
|
93
|
+
}, {});
|
|
94
|
+
}
|
|
95
|
+
// prettier-ignore
|
|
96
|
+
function FromTypes(args, types) {
|
|
97
|
+
return types.map(type => FromType(args, type));
|
|
98
|
+
}
|
|
99
|
+
// prettier-ignore
|
|
100
|
+
function FromType(args, type) {
|
|
101
|
+
return (KindGuard.IsConstructor(type) ? FromConstructor(args, type) :
|
|
102
|
+
KindGuard.IsFunction(type) ? FromFunction(args, type) :
|
|
103
|
+
KindGuard.IsIntersect(type) ? FromIntersect(args, type) :
|
|
104
|
+
KindGuard.IsUnion(type) ? FromUnion(args, type) :
|
|
105
|
+
KindGuard.IsTuple(type) ? FromTuple(args, type) :
|
|
106
|
+
KindGuard.IsArray(type) ? FromArray(args, type) :
|
|
107
|
+
KindGuard.IsAsyncIterator(type) ? FromAsyncIterator(args, type) :
|
|
108
|
+
KindGuard.IsIterator(type) ? FromIterator(args, type) :
|
|
109
|
+
KindGuard.IsPromise(type) ? FromPromise(args, type) :
|
|
110
|
+
KindGuard.IsObject(type) ? FromObject(args, type) :
|
|
111
|
+
KindGuard.IsRecord(type) ? FromRecord(args, type) :
|
|
112
|
+
KindGuard.IsArgument(type) ? FromArgument(args, type) :
|
|
113
|
+
type);
|
|
19
114
|
}
|
|
20
115
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
21
116
|
// prettier-ignore
|
|
22
117
|
function Instantiate(type, args) {
|
|
23
|
-
return (0,
|
|
24
|
-
return KindGuard.IsArgument(type)
|
|
25
|
-
? type.index in args
|
|
26
|
-
? KindGuard.IsSchema(args[type.index])
|
|
27
|
-
? InstantiateArgument(type, args[type.index])
|
|
28
|
-
: (0, index_1.Never)()
|
|
29
|
-
: (0, index_1.Never)()
|
|
30
|
-
: type;
|
|
31
|
-
});
|
|
118
|
+
return FromType(args, (0, type_1.CloneType)(type));
|
|
32
119
|
}
|
|
@@ -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 {
|
|
@@ -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 {
|
|
@@ -43,7 +43,6 @@ export { Record } from '../record/index';
|
|
|
43
43
|
export { Recursive } from '../recursive/index';
|
|
44
44
|
export { Ref } from '../ref/index';
|
|
45
45
|
export { RegExp } from '../regexp/index';
|
|
46
|
-
export { Remap } from '../remap/index';
|
|
47
46
|
export { Required } from '../required/index';
|
|
48
47
|
export { Rest } from '../rest/index';
|
|
49
48
|
export { ReturnType } from '../return-type/index';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = exports.String = exports.ReturnType =
|
|
4
|
+
exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Module = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.Instantiate = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Argument = exports.Any = void 0;
|
|
5
|
+
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = exports.String = exports.ReturnType = void 0;
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// Type: Module
|
|
8
8
|
// ------------------------------------------------------------------
|
|
@@ -99,33 +99,31 @@ var index_44 = require("../ref/index");
|
|
|
99
99
|
Object.defineProperty(exports, "Ref", { enumerable: true, get: function () { return index_44.Ref; } });
|
|
100
100
|
var index_45 = require("../regexp/index");
|
|
101
101
|
Object.defineProperty(exports, "RegExp", { enumerable: true, get: function () { return index_45.RegExp; } });
|
|
102
|
-
var index_46 = require("../
|
|
103
|
-
Object.defineProperty(exports, "
|
|
104
|
-
var index_47 = require("../
|
|
105
|
-
Object.defineProperty(exports, "
|
|
106
|
-
var index_48 = require("../
|
|
107
|
-
Object.defineProperty(exports, "
|
|
108
|
-
var index_49 = require("../
|
|
109
|
-
Object.defineProperty(exports, "
|
|
110
|
-
var index_50 = require("../
|
|
111
|
-
Object.defineProperty(exports, "
|
|
112
|
-
var index_51 = require("../
|
|
113
|
-
Object.defineProperty(exports, "
|
|
114
|
-
var index_52 = require("../
|
|
115
|
-
Object.defineProperty(exports, "
|
|
116
|
-
var index_53 = require("../
|
|
117
|
-
Object.defineProperty(exports, "
|
|
118
|
-
var index_54 = require("../
|
|
119
|
-
Object.defineProperty(exports, "
|
|
120
|
-
var index_55 = require("../
|
|
121
|
-
Object.defineProperty(exports, "
|
|
122
|
-
var index_56 = require("../
|
|
123
|
-
Object.defineProperty(exports, "
|
|
124
|
-
var index_57 = require("../
|
|
125
|
-
Object.defineProperty(exports, "
|
|
126
|
-
var index_58 = require("../
|
|
127
|
-
Object.defineProperty(exports, "
|
|
128
|
-
var index_59 = require("../
|
|
129
|
-
Object.defineProperty(exports, "
|
|
130
|
-
var index_60 = require("../void/index");
|
|
131
|
-
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_60.Void; } });
|
|
102
|
+
var index_46 = require("../required/index");
|
|
103
|
+
Object.defineProperty(exports, "Required", { enumerable: true, get: function () { return index_46.Required; } });
|
|
104
|
+
var index_47 = require("../rest/index");
|
|
105
|
+
Object.defineProperty(exports, "Rest", { enumerable: true, get: function () { return index_47.Rest; } });
|
|
106
|
+
var index_48 = require("../return-type/index");
|
|
107
|
+
Object.defineProperty(exports, "ReturnType", { enumerable: true, get: function () { return index_48.ReturnType; } });
|
|
108
|
+
var index_49 = require("../string/index");
|
|
109
|
+
Object.defineProperty(exports, "String", { enumerable: true, get: function () { return index_49.String; } });
|
|
110
|
+
var index_50 = require("../symbol/index");
|
|
111
|
+
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_50.Symbol; } });
|
|
112
|
+
var index_51 = require("../template-literal/index");
|
|
113
|
+
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_51.TemplateLiteral; } });
|
|
114
|
+
var index_52 = require("../transform/index");
|
|
115
|
+
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_52.Transform; } });
|
|
116
|
+
var index_53 = require("../tuple/index");
|
|
117
|
+
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return index_53.Tuple; } });
|
|
118
|
+
var index_54 = require("../uint8array/index");
|
|
119
|
+
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return index_54.Uint8Array; } });
|
|
120
|
+
var index_55 = require("../undefined/index");
|
|
121
|
+
Object.defineProperty(exports, "Undefined", { enumerable: true, get: function () { return index_55.Undefined; } });
|
|
122
|
+
var index_56 = require("../union/index");
|
|
123
|
+
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return index_56.Union; } });
|
|
124
|
+
var index_57 = require("../unknown/index");
|
|
125
|
+
Object.defineProperty(exports, "Unknown", { enumerable: true, get: function () { return index_57.Unknown; } });
|
|
126
|
+
var index_58 = require("../unsafe/index");
|
|
127
|
+
Object.defineProperty(exports, "Unsafe", { enumerable: true, get: function () { return index_58.Unsafe; } });
|
|
128
|
+
var index_59 = require("../void/index");
|
|
129
|
+
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_59.Void; } });
|
package/build/esm/index.d.mts
CHANGED
|
@@ -52,7 +52,6 @@ export * from './type/record/index.mjs';
|
|
|
52
52
|
export * from './type/recursive/index.mjs';
|
|
53
53
|
export * from './type/ref/index.mjs';
|
|
54
54
|
export * from './type/regexp/index.mjs';
|
|
55
|
-
export * from './type/remap/index.mjs';
|
|
56
55
|
export * from './type/required/index.mjs';
|
|
57
56
|
export * from './type/rest/index.mjs';
|
|
58
57
|
export * from './type/return-type/index.mjs';
|
package/build/esm/index.mjs
CHANGED
|
@@ -58,7 +58,6 @@ export * from './type/record/index.mjs';
|
|
|
58
58
|
export * from './type/recursive/index.mjs';
|
|
59
59
|
export * from './type/ref/index.mjs';
|
|
60
60
|
export * from './type/regexp/index.mjs';
|
|
61
|
-
export * from './type/remap/index.mjs';
|
|
62
61
|
export * from './type/required/index.mjs';
|
|
63
62
|
export * from './type/rest/index.mjs';
|
|
64
63
|
export * from './type/return-type/index.mjs';
|
|
@@ -39,10 +39,17 @@ const Dereference = (context, key) => {
|
|
|
39
39
|
// GenericReference
|
|
40
40
|
// ------------------------------------------------------------------
|
|
41
41
|
function GenericReferenceMapping(results, context) {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const type = Dereference(context, results[0]);
|
|
43
|
+
const args = results[2];
|
|
44
|
+
return t.Instantiate(type, args);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
const GenericReference = Runtime.Tuple([
|
|
48
|
+
Runtime.Ident(),
|
|
49
|
+
Runtime.Const(LAngle),
|
|
50
|
+
Runtime.Ref('Elements'),
|
|
51
|
+
Runtime.Const(RAngle)
|
|
52
|
+
], (results, context) => GenericReferenceMapping(results, context));
|
|
46
53
|
// ------------------------------------------------------------------
|
|
47
54
|
// Reference
|
|
48
55
|
// ------------------------------------------------------------------
|
|
@@ -43,7 +43,7 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
|
|
|
43
43
|
], DelimitMapping>);
|
|
44
44
|
type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
|
|
45
45
|
interface GenericReferenceMapping extends Static.IMapping {
|
|
46
|
-
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer
|
|
46
|
+
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Args extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, Args> : never : never;
|
|
47
47
|
}
|
|
48
48
|
type GenericReference = Static.Tuple<[
|
|
49
49
|
Static.Ident,
|