@nestia/fetcher 2.6.2 → 2.6.3
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/package.json +1 -1
- package/src/EncryptedFetcher.ts +174 -174
- package/src/IConnection.ts +247 -247
- package/src/IFetchEvent.ts +31 -31
- package/src/IFetchRoute.ts +62 -62
- package/src/IPropagation.ts +102 -102
- package/src/NestiaSimulator.ts +82 -82
- package/src/PlainFetcher.ts +105 -105
- package/src/Primitive.ts +136 -136
- package/src/Resolved.ts +119 -119
- package/src/index.ts +9 -9
- package/src/internal/FetcherBase.ts +269 -269
package/src/PlainFetcher.ts
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import { IConnection } from "./IConnection";
|
|
2
|
-
import { IFetchRoute } from "./IFetchRoute";
|
|
3
|
-
import { IPropagation } from "./IPropagation";
|
|
4
|
-
import { FetcherBase } from "./internal/FetcherBase";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Utility class for `fetch` functions used in `@nestia/sdk`.
|
|
8
|
-
*
|
|
9
|
-
* `PlainFetcher` is a utility class designed for SDK functions generated by
|
|
10
|
-
* [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
|
|
11
|
-
* HTTP sever API. In other words, this is a collection of dedicated `fetch()`
|
|
12
|
-
* functions for `@nestia/sdk`.
|
|
13
|
-
*
|
|
14
|
-
* For reference, `PlainFetcher` class does not encrypt or decrypt the body data
|
|
15
|
-
* at all. It just delivers plain data without any post processing. If you've
|
|
16
|
-
* defined a controller method through `@EncryptedRoute` or `@EncryptedBody`
|
|
17
|
-
* decorator, then {@liink EncryptedFetcher} class would be used instead.
|
|
18
|
-
*
|
|
19
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
-
*/
|
|
21
|
-
export namespace PlainFetcher {
|
|
22
|
-
/**
|
|
23
|
-
* Fetch function only for `HEAD` method.
|
|
24
|
-
*
|
|
25
|
-
* @param connection Connection information for the remote HTTP server
|
|
26
|
-
* @param route Route information about the target API
|
|
27
|
-
* @return Nothing because of `HEAD` method
|
|
28
|
-
*/
|
|
29
|
-
export function fetch(
|
|
30
|
-
connection: IConnection,
|
|
31
|
-
route: IFetchRoute<"HEAD">,
|
|
32
|
-
): Promise<void>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Fetch function only for `GET` method.
|
|
36
|
-
*
|
|
37
|
-
* @param connection Connection information for the remote HTTP server
|
|
38
|
-
* @param route Route information about the target API
|
|
39
|
-
* @return Response body data from the remote API
|
|
40
|
-
*/
|
|
41
|
-
export function fetch<Output>(
|
|
42
|
-
connection: IConnection,
|
|
43
|
-
route: IFetchRoute<"GET">,
|
|
44
|
-
): Promise<Output>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
|
|
48
|
-
*
|
|
49
|
-
* @param connection Connection information for the remote HTTP server
|
|
50
|
-
* @param route Route information about the target API
|
|
51
|
-
* @return Response body data from the remote API
|
|
52
|
-
*/
|
|
53
|
-
export function fetch<Input, Output>(
|
|
54
|
-
connection: IConnection,
|
|
55
|
-
route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">,
|
|
56
|
-
input?: Input,
|
|
57
|
-
stringify?: (input: Input) => string,
|
|
58
|
-
): Promise<Output>;
|
|
59
|
-
|
|
60
|
-
export async function fetch<Input, Output>(
|
|
61
|
-
connection: IConnection,
|
|
62
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
63
|
-
input?: Input,
|
|
64
|
-
stringify?: (input: Input) => string,
|
|
65
|
-
): Promise<Output> {
|
|
66
|
-
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
67
|
-
throw new Error(
|
|
68
|
-
"Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
69
|
-
);
|
|
70
|
-
return FetcherBase.fetch({
|
|
71
|
-
className: "PlainFetcher",
|
|
72
|
-
encode: (input) => input,
|
|
73
|
-
decode: (input) => input,
|
|
74
|
-
})(connection, route, input, stringify);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function propagate<Output extends IPropagation<any, any>>(
|
|
78
|
-
connection: IConnection,
|
|
79
|
-
route: IFetchRoute<"GET" | "HEAD">,
|
|
80
|
-
): Promise<Output>;
|
|
81
|
-
|
|
82
|
-
export function propagate<Input, Output extends IPropagation<any, any>>(
|
|
83
|
-
connection: IConnection,
|
|
84
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
85
|
-
input?: Input,
|
|
86
|
-
stringify?: (input: Input) => string,
|
|
87
|
-
): Promise<Output>;
|
|
88
|
-
|
|
89
|
-
export async function propagate<Input, Output extends IPropagation<any, any>>(
|
|
90
|
-
connection: IConnection,
|
|
91
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
92
|
-
input?: Input,
|
|
93
|
-
stringify?: (input: Input) => string,
|
|
94
|
-
): Promise<Output> {
|
|
95
|
-
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
96
|
-
throw new Error(
|
|
97
|
-
"Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
98
|
-
);
|
|
99
|
-
return FetcherBase.propagate({
|
|
100
|
-
className: "PlainFetcher",
|
|
101
|
-
encode: (input) => input,
|
|
102
|
-
decode: (input) => input,
|
|
103
|
-
})(connection, route, input, stringify) as Promise<Output>;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
1
|
+
import { IConnection } from "./IConnection";
|
|
2
|
+
import { IFetchRoute } from "./IFetchRoute";
|
|
3
|
+
import { IPropagation } from "./IPropagation";
|
|
4
|
+
import { FetcherBase } from "./internal/FetcherBase";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Utility class for `fetch` functions used in `@nestia/sdk`.
|
|
8
|
+
*
|
|
9
|
+
* `PlainFetcher` is a utility class designed for SDK functions generated by
|
|
10
|
+
* [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
|
|
11
|
+
* HTTP sever API. In other words, this is a collection of dedicated `fetch()`
|
|
12
|
+
* functions for `@nestia/sdk`.
|
|
13
|
+
*
|
|
14
|
+
* For reference, `PlainFetcher` class does not encrypt or decrypt the body data
|
|
15
|
+
* at all. It just delivers plain data without any post processing. If you've
|
|
16
|
+
* defined a controller method through `@EncryptedRoute` or `@EncryptedBody`
|
|
17
|
+
* decorator, then {@liink EncryptedFetcher} class would be used instead.
|
|
18
|
+
*
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
21
|
+
export namespace PlainFetcher {
|
|
22
|
+
/**
|
|
23
|
+
* Fetch function only for `HEAD` method.
|
|
24
|
+
*
|
|
25
|
+
* @param connection Connection information for the remote HTTP server
|
|
26
|
+
* @param route Route information about the target API
|
|
27
|
+
* @return Nothing because of `HEAD` method
|
|
28
|
+
*/
|
|
29
|
+
export function fetch(
|
|
30
|
+
connection: IConnection,
|
|
31
|
+
route: IFetchRoute<"HEAD">,
|
|
32
|
+
): Promise<void>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fetch function only for `GET` method.
|
|
36
|
+
*
|
|
37
|
+
* @param connection Connection information for the remote HTTP server
|
|
38
|
+
* @param route Route information about the target API
|
|
39
|
+
* @return Response body data from the remote API
|
|
40
|
+
*/
|
|
41
|
+
export function fetch<Output>(
|
|
42
|
+
connection: IConnection,
|
|
43
|
+
route: IFetchRoute<"GET">,
|
|
44
|
+
): Promise<Output>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
|
|
48
|
+
*
|
|
49
|
+
* @param connection Connection information for the remote HTTP server
|
|
50
|
+
* @param route Route information about the target API
|
|
51
|
+
* @return Response body data from the remote API
|
|
52
|
+
*/
|
|
53
|
+
export function fetch<Input, Output>(
|
|
54
|
+
connection: IConnection,
|
|
55
|
+
route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">,
|
|
56
|
+
input?: Input,
|
|
57
|
+
stringify?: (input: Input) => string,
|
|
58
|
+
): Promise<Output>;
|
|
59
|
+
|
|
60
|
+
export async function fetch<Input, Output>(
|
|
61
|
+
connection: IConnection,
|
|
62
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
63
|
+
input?: Input,
|
|
64
|
+
stringify?: (input: Input) => string,
|
|
65
|
+
): Promise<Output> {
|
|
66
|
+
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
67
|
+
throw new Error(
|
|
68
|
+
"Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
69
|
+
);
|
|
70
|
+
return FetcherBase.fetch({
|
|
71
|
+
className: "PlainFetcher",
|
|
72
|
+
encode: (input) => input,
|
|
73
|
+
decode: (input) => input,
|
|
74
|
+
})(connection, route, input, stringify);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function propagate<Output extends IPropagation<any, any>>(
|
|
78
|
+
connection: IConnection,
|
|
79
|
+
route: IFetchRoute<"GET" | "HEAD">,
|
|
80
|
+
): Promise<Output>;
|
|
81
|
+
|
|
82
|
+
export function propagate<Input, Output extends IPropagation<any, any>>(
|
|
83
|
+
connection: IConnection,
|
|
84
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
85
|
+
input?: Input,
|
|
86
|
+
stringify?: (input: Input) => string,
|
|
87
|
+
): Promise<Output>;
|
|
88
|
+
|
|
89
|
+
export async function propagate<Input, Output extends IPropagation<any, any>>(
|
|
90
|
+
connection: IConnection,
|
|
91
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
92
|
+
input?: Input,
|
|
93
|
+
stringify?: (input: Input) => string,
|
|
94
|
+
): Promise<Output> {
|
|
95
|
+
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
98
|
+
);
|
|
99
|
+
return FetcherBase.propagate({
|
|
100
|
+
className: "PlainFetcher",
|
|
101
|
+
encode: (input) => input,
|
|
102
|
+
decode: (input) => input,
|
|
103
|
+
})(connection, route, input, stringify) as Promise<Output>;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/Primitive.ts
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type of JSON.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive<T>` is a TMP (Type Meta Programming) type which converts
|
|
5
|
-
* its argument as a primitive type within framework JSON.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class which returns its origin primitive type
|
|
8
|
-
* through the `valueOf()` method like the `String` or `Number`, its return type would
|
|
9
|
-
* be the `string` or `number`. Otherwise, the built-in class does not have the
|
|
10
|
-
* `valueOf()` method, the return type would be an empty object (`{}`).
|
|
11
|
-
*
|
|
12
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method
|
|
13
|
-
* would be erased and its prototype would be changed to the primitive `object`.
|
|
14
|
-
* Therefore, return type of the TMP type finally be the primitive object.
|
|
15
|
-
*
|
|
16
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
17
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
18
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
19
|
-
*
|
|
20
|
-
* Before | After
|
|
21
|
-
* ------------------------|----------------------------------------
|
|
22
|
-
* `Boolean` | `boolean`
|
|
23
|
-
* `Number` | `number`
|
|
24
|
-
* `String` | `string`
|
|
25
|
-
* `Class` | `object`
|
|
26
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
27
|
-
* Native Class | never
|
|
28
|
-
* Others | No change
|
|
29
|
-
*
|
|
30
|
-
* @template Instance Target argument type.
|
|
31
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
-
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
33
|
-
* @author Michael - https://github.com/8471919
|
|
34
|
-
*/
|
|
35
|
-
export type Primitive<T> =
|
|
36
|
-
Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
|
|
37
|
-
|
|
38
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
39
|
-
|
|
40
|
-
type PrimitiveMain<Instance> = Instance extends [never]
|
|
41
|
-
? never // (special trick for jsonable | null) type
|
|
42
|
-
: ValueOf<Instance> extends bigint
|
|
43
|
-
? never
|
|
44
|
-
: ValueOf<Instance> extends boolean | number | string
|
|
45
|
-
? ValueOf<Instance>
|
|
46
|
-
: Instance extends Function
|
|
47
|
-
? never
|
|
48
|
-
: ValueOf<Instance> extends object
|
|
49
|
-
? Instance extends object
|
|
50
|
-
? Instance extends NativeClass
|
|
51
|
-
? never
|
|
52
|
-
: Instance extends IJsonable<infer Raw>
|
|
53
|
-
? ValueOf<Raw> extends object
|
|
54
|
-
? Raw extends object
|
|
55
|
-
? PrimitiveObject<Raw> // object would be primitified
|
|
56
|
-
: never // cannot be
|
|
57
|
-
: ValueOf<Raw> // atomic value
|
|
58
|
-
: PrimitiveObject<Instance> // object would be primitified
|
|
59
|
-
: never // cannot be
|
|
60
|
-
: ValueOf<Instance>;
|
|
61
|
-
|
|
62
|
-
type PrimitiveObject<Instance extends object> =
|
|
63
|
-
Instance extends Array<infer T>
|
|
64
|
-
? IsTuple<Instance> extends true
|
|
65
|
-
? PrimitiveTuple<Instance>
|
|
66
|
-
: PrimitiveMain<T>[]
|
|
67
|
-
: {
|
|
68
|
-
[P in keyof Instance]: PrimitiveMain<Instance[P]>;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
72
|
-
? []
|
|
73
|
-
: T extends [infer F]
|
|
74
|
-
? [PrimitiveMain<F>]
|
|
75
|
-
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
76
|
-
? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>]
|
|
77
|
-
: T extends [(infer F)?]
|
|
78
|
-
? [PrimitiveMain<F>?]
|
|
79
|
-
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
80
|
-
? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>]
|
|
81
|
-
: [];
|
|
82
|
-
|
|
83
|
-
type ValueOf<Instance> =
|
|
84
|
-
IsValueOf<Instance, Boolean> extends true
|
|
85
|
-
? boolean
|
|
86
|
-
: IsValueOf<Instance, Number> extends true
|
|
87
|
-
? number
|
|
88
|
-
: IsValueOf<Instance, String> extends true
|
|
89
|
-
? string
|
|
90
|
-
: Instance;
|
|
91
|
-
|
|
92
|
-
type NativeClass =
|
|
93
|
-
| Set<any>
|
|
94
|
-
| Map<any, any>
|
|
95
|
-
| WeakSet<any>
|
|
96
|
-
| WeakMap<any, any>
|
|
97
|
-
| Uint8Array
|
|
98
|
-
| Uint8ClampedArray
|
|
99
|
-
| Uint16Array
|
|
100
|
-
| Uint32Array
|
|
101
|
-
| BigUint64Array
|
|
102
|
-
| Int8Array
|
|
103
|
-
| Int16Array
|
|
104
|
-
| Int32Array
|
|
105
|
-
| BigInt64Array
|
|
106
|
-
| Float32Array
|
|
107
|
-
| Float64Array
|
|
108
|
-
| ArrayBuffer
|
|
109
|
-
| SharedArrayBuffer
|
|
110
|
-
| DataView;
|
|
111
|
-
|
|
112
|
-
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
113
|
-
never,
|
|
114
|
-
]
|
|
115
|
-
? false
|
|
116
|
-
: T extends readonly any[]
|
|
117
|
-
? number extends T["length"]
|
|
118
|
-
? false
|
|
119
|
-
: true
|
|
120
|
-
: false;
|
|
121
|
-
|
|
122
|
-
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
123
|
-
? Object extends IValueOf<infer U>
|
|
124
|
-
? Instance extends U
|
|
125
|
-
? false
|
|
126
|
-
: true // not Primitive, but Object
|
|
127
|
-
: false // cannot be
|
|
128
|
-
: false;
|
|
129
|
-
|
|
130
|
-
interface IValueOf<T> {
|
|
131
|
-
valueOf(): T;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
interface IJsonable<T> {
|
|
135
|
-
toJSON(): T;
|
|
136
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type of JSON.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive<T>` is a TMP (Type Meta Programming) type which converts
|
|
5
|
+
* its argument as a primitive type within framework JSON.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class which returns its origin primitive type
|
|
8
|
+
* through the `valueOf()` method like the `String` or `Number`, its return type would
|
|
9
|
+
* be the `string` or `number`. Otherwise, the built-in class does not have the
|
|
10
|
+
* `valueOf()` method, the return type would be an empty object (`{}`).
|
|
11
|
+
*
|
|
12
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method
|
|
13
|
+
* would be erased and its prototype would be changed to the primitive `object`.
|
|
14
|
+
* Therefore, return type of the TMP type finally be the primitive object.
|
|
15
|
+
*
|
|
16
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
17
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
18
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
19
|
+
*
|
|
20
|
+
* Before | After
|
|
21
|
+
* ------------------------|----------------------------------------
|
|
22
|
+
* `Boolean` | `boolean`
|
|
23
|
+
* `Number` | `number`
|
|
24
|
+
* `String` | `string`
|
|
25
|
+
* `Class` | `object`
|
|
26
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
27
|
+
* Native Class | never
|
|
28
|
+
* Others | No change
|
|
29
|
+
*
|
|
30
|
+
* @template Instance Target argument type.
|
|
31
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
+
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
33
|
+
* @author Michael - https://github.com/8471919
|
|
34
|
+
*/
|
|
35
|
+
export type Primitive<T> =
|
|
36
|
+
Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
|
|
37
|
+
|
|
38
|
+
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
39
|
+
|
|
40
|
+
type PrimitiveMain<Instance> = Instance extends [never]
|
|
41
|
+
? never // (special trick for jsonable | null) type
|
|
42
|
+
: ValueOf<Instance> extends bigint
|
|
43
|
+
? never
|
|
44
|
+
: ValueOf<Instance> extends boolean | number | string
|
|
45
|
+
? ValueOf<Instance>
|
|
46
|
+
: Instance extends Function
|
|
47
|
+
? never
|
|
48
|
+
: ValueOf<Instance> extends object
|
|
49
|
+
? Instance extends object
|
|
50
|
+
? Instance extends NativeClass
|
|
51
|
+
? never
|
|
52
|
+
: Instance extends IJsonable<infer Raw>
|
|
53
|
+
? ValueOf<Raw> extends object
|
|
54
|
+
? Raw extends object
|
|
55
|
+
? PrimitiveObject<Raw> // object would be primitified
|
|
56
|
+
: never // cannot be
|
|
57
|
+
: ValueOf<Raw> // atomic value
|
|
58
|
+
: PrimitiveObject<Instance> // object would be primitified
|
|
59
|
+
: never // cannot be
|
|
60
|
+
: ValueOf<Instance>;
|
|
61
|
+
|
|
62
|
+
type PrimitiveObject<Instance extends object> =
|
|
63
|
+
Instance extends Array<infer T>
|
|
64
|
+
? IsTuple<Instance> extends true
|
|
65
|
+
? PrimitiveTuple<Instance>
|
|
66
|
+
: PrimitiveMain<T>[]
|
|
67
|
+
: {
|
|
68
|
+
[P in keyof Instance]: PrimitiveMain<Instance[P]>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
72
|
+
? []
|
|
73
|
+
: T extends [infer F]
|
|
74
|
+
? [PrimitiveMain<F>]
|
|
75
|
+
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
76
|
+
? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>]
|
|
77
|
+
: T extends [(infer F)?]
|
|
78
|
+
? [PrimitiveMain<F>?]
|
|
79
|
+
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
80
|
+
? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>]
|
|
81
|
+
: [];
|
|
82
|
+
|
|
83
|
+
type ValueOf<Instance> =
|
|
84
|
+
IsValueOf<Instance, Boolean> extends true
|
|
85
|
+
? boolean
|
|
86
|
+
: IsValueOf<Instance, Number> extends true
|
|
87
|
+
? number
|
|
88
|
+
: IsValueOf<Instance, String> extends true
|
|
89
|
+
? string
|
|
90
|
+
: Instance;
|
|
91
|
+
|
|
92
|
+
type NativeClass =
|
|
93
|
+
| Set<any>
|
|
94
|
+
| Map<any, any>
|
|
95
|
+
| WeakSet<any>
|
|
96
|
+
| WeakMap<any, any>
|
|
97
|
+
| Uint8Array
|
|
98
|
+
| Uint8ClampedArray
|
|
99
|
+
| Uint16Array
|
|
100
|
+
| Uint32Array
|
|
101
|
+
| BigUint64Array
|
|
102
|
+
| Int8Array
|
|
103
|
+
| Int16Array
|
|
104
|
+
| Int32Array
|
|
105
|
+
| BigInt64Array
|
|
106
|
+
| Float32Array
|
|
107
|
+
| Float64Array
|
|
108
|
+
| ArrayBuffer
|
|
109
|
+
| SharedArrayBuffer
|
|
110
|
+
| DataView;
|
|
111
|
+
|
|
112
|
+
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
113
|
+
never,
|
|
114
|
+
]
|
|
115
|
+
? false
|
|
116
|
+
: T extends readonly any[]
|
|
117
|
+
? number extends T["length"]
|
|
118
|
+
? false
|
|
119
|
+
: true
|
|
120
|
+
: false;
|
|
121
|
+
|
|
122
|
+
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
123
|
+
? Object extends IValueOf<infer U>
|
|
124
|
+
? Instance extends U
|
|
125
|
+
? false
|
|
126
|
+
: true // not Primitive, but Object
|
|
127
|
+
: false // cannot be
|
|
128
|
+
: false;
|
|
129
|
+
|
|
130
|
+
interface IValueOf<T> {
|
|
131
|
+
valueOf(): T;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface IJsonable<T> {
|
|
135
|
+
toJSON(): T;
|
|
136
|
+
}
|