@nestia/fetcher 2.4.2 → 2.4.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/lib/AesPkcs5.js.map +1 -1
- package/lib/EncryptedFetcher.js +6 -6
- package/lib/EncryptedFetcher.js.map +1 -1
- package/lib/HttpError.js.map +1 -1
- package/lib/IConnection.js +0 -1
- package/lib/IConnection.js.map +1 -1
- package/lib/PlainFetcher.d.ts +1 -1
- package/lib/PlainFetcher.js +2 -4
- package/lib/PlainFetcher.js.map +1 -1
- package/lib/internal/FetcherBase.d.ts +1 -1
- package/lib/internal/FetcherBase.js +2 -4
- package/lib/internal/FetcherBase.js.map +1 -1
- package/lib/internal/Singleton.js.map +1 -1
- package/package.json +2 -4
- package/src/AesPkcs5.ts +34 -34
- package/src/EncryptedFetcher.ts +143 -162
- package/src/HttpError.ts +85 -85
- package/src/IConnection.ts +237 -238
- package/src/IEncryptionPassword.ts +29 -29
- package/src/IPropagation.ts +102 -103
- package/src/IRandomGenerator.ts +38 -38
- package/src/PlainFetcher.ts +106 -122
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/index.ts +7 -7
- package/src/internal/FetcherBase.ts +180 -192
- package/src/internal/IFetchRoute.ts +46 -46
- package/src/internal/Singleton.ts +20 -20
|
@@ -11,40 +11,40 @@ import { IConnection } from "./IConnection";
|
|
|
11
11
|
* @author Jeongho Nam - https://github.com/samchon
|
|
12
12
|
*/
|
|
13
13
|
export interface IEncryptionPassword {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Secret key.
|
|
16
|
+
*/
|
|
17
|
+
key: string;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Initialization Vector.
|
|
21
|
+
*/
|
|
22
|
+
iv: string;
|
|
23
23
|
}
|
|
24
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 {
|
|
25
33
|
/**
|
|
26
|
-
*
|
|
34
|
+
* Encryption password getter.
|
|
27
35
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* be changed according to the input content.
|
|
36
|
+
* @param props Properties for predication
|
|
37
|
+
* @returns Encryption password
|
|
31
38
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Encryption password getter.
|
|
35
|
-
*
|
|
36
|
-
* @param props Properties for predication
|
|
37
|
-
* @returns Encryption password
|
|
38
|
-
*/
|
|
39
|
-
(props: IProps): IEncryptionPassword;
|
|
40
|
-
}
|
|
39
|
+
(props: IProps): IEncryptionPassword;
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
50
|
}
|
package/src/IPropagation.ts
CHANGED
|
@@ -1,103 +1,102 @@
|
|
|
1
|
-
import { Primitive } from "./Primitive";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Propagation type.
|
|
5
|
-
*
|
|
6
|
-
* `IPropagation` is a type gathering all possible status codes and their body
|
|
7
|
-
* data types as a discriminated union type. You can specify the status code and
|
|
8
|
-
* its body data type just by using conditional statement like below.
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* type Output = IPropagation<{
|
|
12
|
-
* 200: ISeller.IAuthorized;
|
|
13
|
-
* 400: TypeGuardError.IProps;
|
|
14
|
-
* >};
|
|
15
|
-
*
|
|
16
|
-
* const output: Output = await sdk.sellers.authenticate.join(input);
|
|
17
|
-
* if (output.success) {
|
|
18
|
-
* // automatically casted to "ISeller.IAuthorized" type
|
|
19
|
-
* const authorized: ISeller.IAuthorized = output.data;
|
|
20
|
-
* } else if (output.status === 400) {
|
|
21
|
-
* // automatically casted to "TypeGuardError.IProps" type
|
|
22
|
-
* const error: TypeGuardError.IProps = output.data;
|
|
23
|
-
* } else {
|
|
24
|
-
* // unknown type when out of pre-defined status codes
|
|
25
|
-
* const result: unknown = output.data;
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* For reference, this `IPropagation` type is utilized by SDK library generated by
|
|
30
|
-
* `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
|
|
31
|
-
* In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
|
|
32
|
-
* typed data directly, but returns this `IPropagation` typed object instead.
|
|
33
|
-
*
|
|
34
|
-
* @template StatusMap Map of status code and its body data type.
|
|
35
|
-
* @template Success Default success status code.
|
|
36
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
37
|
-
*/
|
|
38
|
-
export type IPropagation<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
> =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export namespace IPropagation {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
1
|
+
import { Primitive } from "./Primitive";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Propagation type.
|
|
5
|
+
*
|
|
6
|
+
* `IPropagation` is a type gathering all possible status codes and their body
|
|
7
|
+
* data types as a discriminated union type. You can specify the status code and
|
|
8
|
+
* its body data type just by using conditional statement like below.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* type Output = IPropagation<{
|
|
12
|
+
* 200: ISeller.IAuthorized;
|
|
13
|
+
* 400: TypeGuardError.IProps;
|
|
14
|
+
* >};
|
|
15
|
+
*
|
|
16
|
+
* const output: Output = await sdk.sellers.authenticate.join(input);
|
|
17
|
+
* if (output.success) {
|
|
18
|
+
* // automatically casted to "ISeller.IAuthorized" type
|
|
19
|
+
* const authorized: ISeller.IAuthorized = output.data;
|
|
20
|
+
* } else if (output.status === 400) {
|
|
21
|
+
* // automatically casted to "TypeGuardError.IProps" type
|
|
22
|
+
* const error: TypeGuardError.IProps = output.data;
|
|
23
|
+
* } else {
|
|
24
|
+
* // unknown type when out of pre-defined status codes
|
|
25
|
+
* const result: unknown = output.data;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* For reference, this `IPropagation` type is utilized by SDK library generated by
|
|
30
|
+
* `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
|
|
31
|
+
* In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
|
|
32
|
+
* typed data directly, but returns this `IPropagation` typed object instead.
|
|
33
|
+
*
|
|
34
|
+
* @template StatusMap Map of status code and its body data type.
|
|
35
|
+
* @template Success Default success status code.
|
|
36
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
37
|
+
*/
|
|
38
|
+
export type IPropagation<
|
|
39
|
+
StatusMap extends {
|
|
40
|
+
[P in IPropagation.Status]?: any;
|
|
41
|
+
},
|
|
42
|
+
Success extends number = 200 | 201,
|
|
43
|
+
> =
|
|
44
|
+
| {
|
|
45
|
+
[P in keyof StatusMap]: IPropagation.IBranch<
|
|
46
|
+
P extends Success ? true : false,
|
|
47
|
+
P,
|
|
48
|
+
StatusMap[P]
|
|
49
|
+
>;
|
|
50
|
+
}[keyof StatusMap]
|
|
51
|
+
| IPropagation.IBranch<false, unknown, unknown>;
|
|
52
|
+
export namespace IPropagation {
|
|
53
|
+
/**
|
|
54
|
+
* Type of configurable status codes.
|
|
55
|
+
*
|
|
56
|
+
* The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the range
|
|
57
|
+
* of status codes. If `5XX` is specified, it means the status code is in the
|
|
58
|
+
* range of `500` to `599`.
|
|
59
|
+
*/
|
|
60
|
+
export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Branch type of propagation.
|
|
64
|
+
*
|
|
65
|
+
* `IPropagation.IBranch` is a branch type composing `IPropagation` type,
|
|
66
|
+
* which is gathering all possible status codes and their body data types
|
|
67
|
+
* as a union type.
|
|
68
|
+
*/
|
|
69
|
+
export interface IBranch<Success extends boolean, StatusValue, BodyData> {
|
|
70
|
+
success: Success;
|
|
71
|
+
status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX"
|
|
72
|
+
? StatusRange<StatusValue>
|
|
73
|
+
: StatusValue extends number
|
|
74
|
+
? StatusValue
|
|
75
|
+
: never;
|
|
76
|
+
data: Primitive<BodyData>;
|
|
77
|
+
headers: Record<string, string | string[]>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Range of status codes by the first digit.
|
|
82
|
+
*/
|
|
83
|
+
export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0
|
|
84
|
+
? IntRange<200, 299>
|
|
85
|
+
: T extends 3
|
|
86
|
+
? IntRange<300, 399>
|
|
87
|
+
: T extends 4
|
|
88
|
+
? IntRange<400, 499>
|
|
89
|
+
: IntRange<500, 599>;
|
|
90
|
+
|
|
91
|
+
type IntRange<F extends number, T extends number> = Exclude<
|
|
92
|
+
Enumerate<T>,
|
|
93
|
+
Enumerate<F>
|
|
94
|
+
>;
|
|
95
|
+
|
|
96
|
+
type Enumerate<
|
|
97
|
+
N extends number,
|
|
98
|
+
Acc extends number[] = [],
|
|
99
|
+
> = Acc["length"] extends N
|
|
100
|
+
? Acc[number]
|
|
101
|
+
: Enumerate<N, [...Acc, Acc["length"]]>;
|
|
102
|
+
}
|
package/src/IRandomGenerator.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export interface IRandomGenerator {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
export namespace IRandomGenerator {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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,122 +1,106 @@
|
|
|
1
|
-
import { IConnection } from "./IConnection";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
stringify?: (input: Input) => string,
|
|
108
|
-
): Promise<Output> {
|
|
109
|
-
if (
|
|
110
|
-
route.request?.encrypted === true ||
|
|
111
|
-
route.response?.encrypted === true
|
|
112
|
-
)
|
|
113
|
-
throw new Error(
|
|
114
|
-
"Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
|
|
115
|
-
);
|
|
116
|
-
return FetcherBase.propagate({
|
|
117
|
-
className: "PlainFetcher",
|
|
118
|
-
encode: (input) => input,
|
|
119
|
-
decode: (input) => input,
|
|
120
|
-
})(connection, route, input, stringify) as Promise<Output>;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
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
|
+
}
|