@nestia/fetcher 2.4.5 → 2.4.6
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/lib/internal/FetcherBase.js.map +1 -1
- package/package.json +1 -1
- package/src/AesPkcs5.ts +50 -50
- package/src/EncryptedFetcher.ts +175 -175
- package/src/HttpError.ts +85 -85
- package/src/IConnection.ts +21 -21
- package/src/IEncryptionPassword.ts +50 -50
- package/src/IPropagation.ts +6 -6
- package/src/IRandomGenerator.ts +38 -38
- package/src/PlainFetcher.ts +106 -106
- package/src/Primitive.ts +48 -47
- package/src/Resolved.ts +59 -58
- package/src/index.ts +7 -7
- package/src/internal/FetcherBase.ts +2 -2
- package/src/internal/IFetchRoute.ts +61 -61
- package/src/internal/Singleton.ts +20 -20
package/src/IConnection.ts
CHANGED
|
@@ -209,28 +209,28 @@ export namespace IConnection {
|
|
|
209
209
|
? T[P] | undefined
|
|
210
210
|
: never
|
|
211
211
|
: Lowercase<P> extends
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
212
|
+
| "age"
|
|
213
|
+
| "authorization"
|
|
214
|
+
| "content-length"
|
|
215
|
+
| "content-type"
|
|
216
|
+
| "etag"
|
|
217
|
+
| "expires"
|
|
218
|
+
| "from"
|
|
219
|
+
| "host"
|
|
220
|
+
| "if-modified-since"
|
|
221
|
+
| "if-unmodified-since"
|
|
222
|
+
| "last-modified"
|
|
223
|
+
| "location"
|
|
224
|
+
| "max-forwards"
|
|
225
|
+
| "proxy-authorization"
|
|
226
|
+
| "referer"
|
|
227
|
+
| "retry-after"
|
|
228
|
+
| "server"
|
|
229
|
+
| "user-agent"
|
|
230
|
+
? T[P] extends Array<HeaderValue>
|
|
231
|
+
? never
|
|
232
|
+
: T[P] | undefined
|
|
232
233
|
: T[P] | undefined
|
|
233
|
-
: T[P] | undefined
|
|
234
234
|
: never
|
|
235
235
|
: never;
|
|
236
236
|
};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { IConnection } from "./IConnection";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Encryption password.
|
|
5
|
-
*
|
|
6
|
-
* `IEncryptionPassword` is a type of interface who represents encryption password used by
|
|
7
|
-
* the {@link Fetcher} with AES-128/256 algorithm. If your encryption password is not fixed
|
|
8
|
-
* but changes according to the input content, you can utilize the
|
|
9
|
-
* {@link IEncryptionPassword.Closure} function type.
|
|
10
|
-
*
|
|
11
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
-
*/
|
|
13
|
-
export interface IEncryptionPassword {
|
|
14
|
-
/**
|
|
15
|
-
* Secret key.
|
|
16
|
-
*/
|
|
17
|
-
key: string;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Initialization Vector.
|
|
21
|
-
*/
|
|
22
|
-
iv: string;
|
|
23
|
-
}
|
|
24
|
-
export namespace IEncryptionPassword {
|
|
25
|
-
/**
|
|
26
|
-
* Type of a closure function returning the {@link IEncryptionPassword} object.
|
|
27
|
-
*
|
|
28
|
-
* `IEncryptionPassword.Closure` is a type of closure function who are returning the
|
|
29
|
-
* {@link IEncryptionPassword} object. It would be used when your encryption password
|
|
30
|
-
* be changed according to the input content.
|
|
31
|
-
*/
|
|
32
|
-
export interface Closure {
|
|
33
|
-
/**
|
|
34
|
-
* Encryption password getter.
|
|
35
|
-
*
|
|
36
|
-
* @param props Properties for predication
|
|
37
|
-
* @returns Encryption password
|
|
38
|
-
*/
|
|
39
|
-
(props: IProps): IEncryptionPassword;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Properties for the closure.
|
|
44
|
-
*/
|
|
45
|
-
export interface IProps {
|
|
46
|
-
headers: Record<string, IConnection.HeaderValue | undefined>;
|
|
47
|
-
body: string;
|
|
48
|
-
direction: "encode" | "decode";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
import { IConnection } from "./IConnection";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encryption password.
|
|
5
|
+
*
|
|
6
|
+
* `IEncryptionPassword` is a type of interface who represents encryption password used by
|
|
7
|
+
* the {@link Fetcher} with AES-128/256 algorithm. If your encryption password is not fixed
|
|
8
|
+
* but changes according to the input content, you can utilize the
|
|
9
|
+
* {@link IEncryptionPassword.Closure} function type.
|
|
10
|
+
*
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
*/
|
|
13
|
+
export interface IEncryptionPassword {
|
|
14
|
+
/**
|
|
15
|
+
* Secret key.
|
|
16
|
+
*/
|
|
17
|
+
key: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Initialization Vector.
|
|
21
|
+
*/
|
|
22
|
+
iv: string;
|
|
23
|
+
}
|
|
24
|
+
export namespace IEncryptionPassword {
|
|
25
|
+
/**
|
|
26
|
+
* Type of a closure function returning the {@link IEncryptionPassword} object.
|
|
27
|
+
*
|
|
28
|
+
* `IEncryptionPassword.Closure` is a type of closure function who are returning the
|
|
29
|
+
* {@link IEncryptionPassword} object. It would be used when your encryption password
|
|
30
|
+
* be changed according to the input content.
|
|
31
|
+
*/
|
|
32
|
+
export interface Closure {
|
|
33
|
+
/**
|
|
34
|
+
* Encryption password getter.
|
|
35
|
+
*
|
|
36
|
+
* @param props Properties for predication
|
|
37
|
+
* @returns Encryption password
|
|
38
|
+
*/
|
|
39
|
+
(props: IProps): IEncryptionPassword;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Properties for the closure.
|
|
44
|
+
*/
|
|
45
|
+
export interface IProps {
|
|
46
|
+
headers: Record<string, IConnection.HeaderValue | undefined>;
|
|
47
|
+
body: string;
|
|
48
|
+
direction: "encode" | "decode";
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/IPropagation.ts
CHANGED
|
@@ -71,8 +71,8 @@ export namespace IPropagation {
|
|
|
71
71
|
status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX"
|
|
72
72
|
? StatusRange<StatusValue>
|
|
73
73
|
: StatusValue extends number
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
? StatusValue
|
|
75
|
+
: never;
|
|
76
76
|
data: Primitive<BodyData>;
|
|
77
77
|
headers: Record<string, string | string[]>;
|
|
78
78
|
}
|
|
@@ -83,10 +83,10 @@ export namespace IPropagation {
|
|
|
83
83
|
export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0
|
|
84
84
|
? IntRange<200, 299>
|
|
85
85
|
: T extends 3
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
? IntRange<300, 399>
|
|
87
|
+
: T extends 4
|
|
88
|
+
? IntRange<400, 499>
|
|
89
|
+
: IntRange<500, 599>;
|
|
90
90
|
|
|
91
91
|
type IntRange<F extends number, T extends number> = Exclude<
|
|
92
92
|
Enumerate<T>,
|
package/src/IRandomGenerator.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export interface IRandomGenerator {
|
|
2
|
-
boolean(): boolean;
|
|
3
|
-
integer(minimum?: number, maximum?: number): number;
|
|
4
|
-
number(minimum?: number, maximum?: number): number;
|
|
5
|
-
bigint(minimum?: bigint, maximum?: bigint): bigint;
|
|
6
|
-
string(length?: number): string;
|
|
7
|
-
array<T>(closure: (index: number) => T, count?: number): T[];
|
|
8
|
-
length(): number;
|
|
9
|
-
|
|
10
|
-
uuid(): string;
|
|
11
|
-
email(): string;
|
|
12
|
-
url(): string;
|
|
13
|
-
ipv4(): string;
|
|
14
|
-
ipv6(): string;
|
|
15
|
-
pattern(regex: RegExp): string;
|
|
16
|
-
date(minimum?: number, maximum?: number): string;
|
|
17
|
-
datetime(minimum?: number, maximum?: number): string;
|
|
18
|
-
|
|
19
|
-
customs?: IRandomGenerator.CustomMap;
|
|
20
|
-
}
|
|
21
|
-
export namespace IRandomGenerator {
|
|
22
|
-
export type CustomMap = {
|
|
23
|
-
[Type in keyof Customizable]?: (
|
|
24
|
-
tags: ICommentTag[],
|
|
25
|
-
) => Customizable[Type] | undefined;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type Customizable = {
|
|
29
|
-
number: number;
|
|
30
|
-
string: string;
|
|
31
|
-
bigint: bigint;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export interface ICommentTag {
|
|
35
|
-
name: string;
|
|
36
|
-
value?: string;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
export interface IRandomGenerator {
|
|
2
|
+
boolean(): boolean;
|
|
3
|
+
integer(minimum?: number, maximum?: number): number;
|
|
4
|
+
number(minimum?: number, maximum?: number): number;
|
|
5
|
+
bigint(minimum?: bigint, maximum?: bigint): bigint;
|
|
6
|
+
string(length?: number): string;
|
|
7
|
+
array<T>(closure: (index: number) => T, count?: number): T[];
|
|
8
|
+
length(): number;
|
|
9
|
+
|
|
10
|
+
uuid(): string;
|
|
11
|
+
email(): string;
|
|
12
|
+
url(): string;
|
|
13
|
+
ipv4(): string;
|
|
14
|
+
ipv6(): string;
|
|
15
|
+
pattern(regex: RegExp): string;
|
|
16
|
+
date(minimum?: number, maximum?: number): string;
|
|
17
|
+
datetime(minimum?: number, maximum?: number): string;
|
|
18
|
+
|
|
19
|
+
customs?: IRandomGenerator.CustomMap;
|
|
20
|
+
}
|
|
21
|
+
export namespace IRandomGenerator {
|
|
22
|
+
export type CustomMap = {
|
|
23
|
+
[Type in keyof Customizable]?: (
|
|
24
|
+
tags: ICommentTag[],
|
|
25
|
+
) => Customizable[Type] | undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type Customizable = {
|
|
29
|
+
number: number;
|
|
30
|
+
string: string;
|
|
31
|
+
bigint: bigint;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface ICommentTag {
|
|
35
|
+
name: string;
|
|
36
|
+
value?: string;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/PlainFetcher.ts
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { IConnection } from "./IConnection";
|
|
2
|
-
import { IPropagation } from "./IPropagation";
|
|
3
|
-
import { Primitive } from "./Primitive";
|
|
4
|
-
import { FetcherBase } from "./internal/FetcherBase";
|
|
5
|
-
import { IFetchRoute } from "./internal/IFetchRoute";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Utility class for `fetch` functions used in `@nestia/sdk`.
|
|
9
|
-
*
|
|
10
|
-
* `PlainFetcher` is a utility class designed for SDK functions generated by
|
|
11
|
-
* [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
|
|
12
|
-
* HTTP sever API. In other words, this is a collection of dedicated `fetch()`
|
|
13
|
-
* functions for `@nestia/sdk`.
|
|
14
|
-
*
|
|
15
|
-
* For reference, `PlainFetcher` class does not encrypt or decrypt the body data
|
|
16
|
-
* at all. It just delivers plain data without any post processing. If you've
|
|
17
|
-
* defined a controller method through `@EncryptedRoute` or `@EncryptedBody`
|
|
18
|
-
* decorator, then {@liink EncryptedFetcher} class would be used instead.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
*/
|
|
22
|
-
export namespace PlainFetcher {
|
|
23
|
-
/**
|
|
24
|
-
* Fetch function only for `HEAD` method.
|
|
25
|
-
*
|
|
26
|
-
* @param connection Connection information for the remote HTTP server
|
|
27
|
-
* @param route Route information about the target API
|
|
28
|
-
* @return Nothing because of `HEAD` method
|
|
29
|
-
*/
|
|
30
|
-
export function fetch(
|
|
31
|
-
connection: IConnection,
|
|
32
|
-
route: IFetchRoute<"HEAD">,
|
|
33
|
-
): Promise<void>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Fetch function only for `GET` method.
|
|
37
|
-
*
|
|
38
|
-
* @param connection Connection information for the remote HTTP server
|
|
39
|
-
* @param route Route information about the target API
|
|
40
|
-
* @return Response body data from the remote API
|
|
41
|
-
*/
|
|
42
|
-
export function fetch<Output>(
|
|
43
|
-
connection: IConnection,
|
|
44
|
-
route: IFetchRoute<"GET">,
|
|
45
|
-
): Promise<Primitive<Output>>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
|
|
49
|
-
*
|
|
50
|
-
* @param connection Connection information for the remote HTTP server
|
|
51
|
-
* @param route Route information about the target API
|
|
52
|
-
* @return Response body data from the remote API
|
|
53
|
-
*/
|
|
54
|
-
export function fetch<Input, Output>(
|
|
55
|
-
connection: IConnection,
|
|
56
|
-
route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">,
|
|
57
|
-
input?: Input,
|
|
58
|
-
stringify?: (input: Input) => string,
|
|
59
|
-
): Promise<Primitive<Output>>;
|
|
60
|
-
|
|
61
|
-
export async function fetch<Input, Output>(
|
|
62
|
-
connection: IConnection,
|
|
63
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
64
|
-
input?: Input,
|
|
65
|
-
stringify?: (input: Input) => string,
|
|
66
|
-
): Promise<Primitive<Output>> {
|
|
67
|
-
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
68
|
-
throw new Error(
|
|
69
|
-
"Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
70
|
-
);
|
|
71
|
-
return FetcherBase.fetch({
|
|
72
|
-
className: "PlainFetcher",
|
|
73
|
-
encode: (input) => input,
|
|
74
|
-
decode: (input) => input,
|
|
75
|
-
})(connection, route, input, stringify);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function propagate<Output extends IPropagation<any, any>>(
|
|
79
|
-
connection: IConnection,
|
|
80
|
-
route: IFetchRoute<"GET" | "HEAD">,
|
|
81
|
-
): Promise<Output>;
|
|
82
|
-
|
|
83
|
-
export function propagate<Input, Output extends IPropagation<any, any>>(
|
|
84
|
-
connection: IConnection,
|
|
85
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
86
|
-
input?: Input,
|
|
87
|
-
stringify?: (input: Input) => string,
|
|
88
|
-
): Promise<Output>;
|
|
89
|
-
|
|
90
|
-
export async function propagate<Input, Output extends IPropagation<any, any>>(
|
|
91
|
-
connection: IConnection,
|
|
92
|
-
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
93
|
-
input?: Input,
|
|
94
|
-
stringify?: (input: Input) => string,
|
|
95
|
-
): Promise<Output> {
|
|
96
|
-
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
97
|
-
throw new Error(
|
|
98
|
-
"Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
99
|
-
);
|
|
100
|
-
return FetcherBase.propagate({
|
|
101
|
-
className: "PlainFetcher",
|
|
102
|
-
encode: (input) => input,
|
|
103
|
-
decode: (input) => input,
|
|
104
|
-
})(connection, route, input, stringify) as Promise<Output>;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
import { IConnection } from "./IConnection";
|
|
2
|
+
import { IPropagation } from "./IPropagation";
|
|
3
|
+
import { Primitive } from "./Primitive";
|
|
4
|
+
import { FetcherBase } from "./internal/FetcherBase";
|
|
5
|
+
import { IFetchRoute } from "./internal/IFetchRoute";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Utility class for `fetch` functions used in `@nestia/sdk`.
|
|
9
|
+
*
|
|
10
|
+
* `PlainFetcher` is a utility class designed for SDK functions generated by
|
|
11
|
+
* [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
|
|
12
|
+
* HTTP sever API. In other words, this is a collection of dedicated `fetch()`
|
|
13
|
+
* functions for `@nestia/sdk`.
|
|
14
|
+
*
|
|
15
|
+
* For reference, `PlainFetcher` class does not encrypt or decrypt the body data
|
|
16
|
+
* at all. It just delivers plain data without any post processing. If you've
|
|
17
|
+
* defined a controller method through `@EncryptedRoute` or `@EncryptedBody`
|
|
18
|
+
* decorator, then {@liink EncryptedFetcher} class would be used instead.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
*/
|
|
22
|
+
export namespace PlainFetcher {
|
|
23
|
+
/**
|
|
24
|
+
* Fetch function only for `HEAD` method.
|
|
25
|
+
*
|
|
26
|
+
* @param connection Connection information for the remote HTTP server
|
|
27
|
+
* @param route Route information about the target API
|
|
28
|
+
* @return Nothing because of `HEAD` method
|
|
29
|
+
*/
|
|
30
|
+
export function fetch(
|
|
31
|
+
connection: IConnection,
|
|
32
|
+
route: IFetchRoute<"HEAD">,
|
|
33
|
+
): Promise<void>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Fetch function only for `GET` method.
|
|
37
|
+
*
|
|
38
|
+
* @param connection Connection information for the remote HTTP server
|
|
39
|
+
* @param route Route information about the target API
|
|
40
|
+
* @return Response body data from the remote API
|
|
41
|
+
*/
|
|
42
|
+
export function fetch<Output>(
|
|
43
|
+
connection: IConnection,
|
|
44
|
+
route: IFetchRoute<"GET">,
|
|
45
|
+
): Promise<Primitive<Output>>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
|
|
49
|
+
*
|
|
50
|
+
* @param connection Connection information for the remote HTTP server
|
|
51
|
+
* @param route Route information about the target API
|
|
52
|
+
* @return Response body data from the remote API
|
|
53
|
+
*/
|
|
54
|
+
export function fetch<Input, Output>(
|
|
55
|
+
connection: IConnection,
|
|
56
|
+
route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">,
|
|
57
|
+
input?: Input,
|
|
58
|
+
stringify?: (input: Input) => string,
|
|
59
|
+
): Promise<Primitive<Output>>;
|
|
60
|
+
|
|
61
|
+
export async function fetch<Input, Output>(
|
|
62
|
+
connection: IConnection,
|
|
63
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
64
|
+
input?: Input,
|
|
65
|
+
stringify?: (input: Input) => string,
|
|
66
|
+
): Promise<Primitive<Output>> {
|
|
67
|
+
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
68
|
+
throw new Error(
|
|
69
|
+
"Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
70
|
+
);
|
|
71
|
+
return FetcherBase.fetch({
|
|
72
|
+
className: "PlainFetcher",
|
|
73
|
+
encode: (input) => input,
|
|
74
|
+
decode: (input) => input,
|
|
75
|
+
})(connection, route, input, stringify);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function propagate<Output extends IPropagation<any, any>>(
|
|
79
|
+
connection: IConnection,
|
|
80
|
+
route: IFetchRoute<"GET" | "HEAD">,
|
|
81
|
+
): Promise<Output>;
|
|
82
|
+
|
|
83
|
+
export function propagate<Input, Output extends IPropagation<any, any>>(
|
|
84
|
+
connection: IConnection,
|
|
85
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
86
|
+
input?: Input,
|
|
87
|
+
stringify?: (input: Input) => string,
|
|
88
|
+
): Promise<Output>;
|
|
89
|
+
|
|
90
|
+
export async function propagate<Input, Output extends IPropagation<any, any>>(
|
|
91
|
+
connection: IConnection,
|
|
92
|
+
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
93
|
+
input?: Input,
|
|
94
|
+
stringify?: (input: Input) => string,
|
|
95
|
+
): Promise<Output> {
|
|
96
|
+
if (route.request?.encrypted === true || route.response?.encrypted === true)
|
|
97
|
+
throw new Error(
|
|
98
|
+
"Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
99
|
+
);
|
|
100
|
+
return FetcherBase.propagate({
|
|
101
|
+
className: "PlainFetcher",
|
|
102
|
+
encode: (input) => input,
|
|
103
|
+
decode: (input) => input,
|
|
104
|
+
})(connection, route, input, stringify) as Promise<Output>;
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/Primitive.ts
CHANGED
|
@@ -32,61 +32,62 @@
|
|
|
32
32
|
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
33
33
|
* @author Michael - https://github.com/8471919
|
|
34
34
|
*/
|
|
35
|
-
export type Primitive<T> =
|
|
36
|
-
? T
|
|
37
|
-
: PrimitiveMain<T>;
|
|
35
|
+
export type Primitive<T> =
|
|
36
|
+
Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
|
|
38
37
|
|
|
39
38
|
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
40
39
|
|
|
41
40
|
type PrimitiveMain<Instance> = Instance extends [never]
|
|
42
41
|
? never // (special trick for jsonable | null) type
|
|
43
42
|
: ValueOf<Instance> extends bigint
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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>;
|
|
62
61
|
|
|
63
|
-
type PrimitiveObject<Instance extends object> =
|
|
64
|
-
|
|
65
|
-
?
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
70
|
|
|
71
71
|
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
72
72
|
? []
|
|
73
73
|
: T extends [infer F]
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
82
|
|
|
83
|
-
type ValueOf<Instance> =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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;
|
|
90
91
|
|
|
91
92
|
type NativeClass =
|
|
92
93
|
| Set<any>
|
|
@@ -113,10 +114,10 @@ type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
|
113
114
|
]
|
|
114
115
|
? false
|
|
115
116
|
: T extends readonly any[]
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
? number extends T["length"]
|
|
118
|
+
? false
|
|
119
|
+
: true
|
|
120
|
+
: false;
|
|
120
121
|
|
|
121
122
|
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
122
123
|
? Object extends IValueOf<infer U>
|