@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.
@@ -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
- * Secret key.
16
- */
17
- key: string;
14
+ /**
15
+ * Secret key.
16
+ */
17
+ key: string;
18
18
 
19
- /**
20
- * Initialization Vector.
21
- */
22
- iv: string;
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
- * Type of a closure function returning the {@link IEncryptionPassword} object.
34
+ * Encryption password getter.
27
35
  *
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.
36
+ * @param props Properties for predication
37
+ * @returns Encryption password
31
38
  */
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
- }
39
+ (props: IProps): IEncryptionPassword;
40
+ }
41
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
- }
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
  }
@@ -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
- 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"> =
84
- T extends 0
85
- ? IntRange<200, 299>
86
- : T extends 3
87
- ? IntRange<300, 399>
88
- : T extends 4
89
- ? IntRange<400, 499>
90
- : IntRange<500, 599>;
91
-
92
- type IntRange<F extends number, T extends number> = Exclude<
93
- Enumerate<T>,
94
- Enumerate<F>
95
- >;
96
-
97
- type Enumerate<
98
- N extends number,
99
- Acc extends number[] = [],
100
- > = Acc["length"] extends N
101
- ? Acc[number]
102
- : Enumerate<N, [...Acc, Acc["length"]]>;
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
+ }
@@ -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
+ }
@@ -1,122 +1,106 @@
1
- import { IConnection } from "./IConnection";
2
- import { Primitive } from "./Primitive";
3
-
4
- import { IFetchRoute } from "./internal/IFetchRoute";
5
- import { FetcherBase } from "./internal/FetcherBase";
6
- import { IPropagation } from "./IPropagation";
7
-
8
- /**
9
- * Utility class for `fetch` functions used in `@nestia/sdk`.
10
- *
11
- * `PlainFetcher` is a utility class designed for SDK functions generated by
12
- * [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
13
- * HTTP sever API. In other words, this is a collection of dedicated `fetch()`
14
- * functions for `@nestia/sdk`.
15
- *
16
- * For reference, `PlainFetcher` class does not encrypt or decrypt the body data
17
- * at all. It just delivers plain data without any post processing. If you've
18
- * defined a controller method through `@EncryptedRoute` or `@EncryptedBody`
19
- * decorator, then {@liink EncryptedFetcher} class would be used instead.
20
- *
21
- * @author Jeongho Nam - https://github.com/samchon
22
- */
23
- export namespace PlainFetcher {
24
- /**
25
- * Fetch function only for `HEAD` method.
26
- *
27
- * @param connection Connection information for the remote HTTP server
28
- * @param route Route information about the target API
29
- * @return Nothing because of `HEAD` method
30
- */
31
- export function fetch(
32
- connection: IConnection,
33
- route: IFetchRoute<"HEAD">,
34
- ): Promise<void>;
35
-
36
- /**
37
- * Fetch function only for `GET` method.
38
- *
39
- * @param connection Connection information for the remote HTTP server
40
- * @param route Route information about the target API
41
- * @return Response body data from the remote API
42
- */
43
- export function fetch<Output>(
44
- connection: IConnection,
45
- route: IFetchRoute<"GET">,
46
- ): Promise<Primitive<Output>>;
47
-
48
- /**
49
- * Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
50
- *
51
- * @param connection Connection information for the remote HTTP server
52
- * @param route Route information about the target API
53
- * @return Response body data from the remote API
54
- */
55
- export function fetch<Input, Output>(
56
- connection: IConnection,
57
- route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">,
58
- input?: Input,
59
- stringify?: (input: Input) => string,
60
- ): Promise<Primitive<Output>>;
61
-
62
- export async function fetch<Input, Output>(
63
- connection: IConnection,
64
- route: IFetchRoute<
65
- "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"
66
- >,
67
- input?: Input,
68
- stringify?: (input: Input) => string,
69
- ): Promise<Primitive<Output>> {
70
- if (
71
- route.request?.encrypted === true ||
72
- route.response?.encrypted === true
73
- )
74
- throw new Error(
75
- "Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.",
76
- );
77
- return FetcherBase.fetch({
78
- className: "PlainFetcher",
79
- encode: (input) => input,
80
- decode: (input) => input,
81
- })(connection, route, input, stringify);
82
- }
83
-
84
- export function propagate<Output extends IPropagation<any, any>>(
85
- connection: IConnection,
86
- route: IFetchRoute<"GET" | "HEAD">,
87
- ): Promise<Output>;
88
-
89
- export function propagate<Input, Output extends IPropagation<any, any>>(
90
- connection: IConnection,
91
- route: IFetchRoute<
92
- "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"
93
- >,
94
- input?: Input,
95
- stringify?: (input: Input) => string,
96
- ): Promise<Output>;
97
-
98
- export async function propagate<
99
- Input,
100
- Output extends IPropagation<any, any>,
101
- >(
102
- connection: IConnection,
103
- route: IFetchRoute<
104
- "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"
105
- >,
106
- input?: Input,
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
+ }