@nestia/fetcher 7.1.1-dev.20250714 → 7.2.0

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.
@@ -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
+ }
@@ -1,31 +1,31 @@
1
- // import { IConnection } from "./IConnection";
2
- import { IFetchRoute } from "./IFetchRoute";
3
-
4
- export interface IFetchEvent {
5
- route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">;
6
- path: string;
7
- status: number | null;
8
- input: any;
9
- output: any;
10
- started_at: Date;
11
- respond_at: Date | null;
12
- completed_at: Date;
13
- }
14
- // export namespace IFetchEvent {
15
- // export interface IFunction {
16
- // (connection: IConnection, ...args: any[]): Promise<any>;
17
- // METADATA: {
18
- // method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
19
- // path: string;
20
- // request: null | {
21
- // type: string;
22
- // encrypted: boolean;
23
- // };
24
- // response: null | {
25
- // type: string;
26
- // encrypted: boolean;
27
- // };
28
- // };
29
- // status: null | number;
30
- // }
31
- // }
1
+ // import { IConnection } from "./IConnection";
2
+ import { IFetchRoute } from "./IFetchRoute";
3
+
4
+ export interface IFetchEvent {
5
+ route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">;
6
+ path: string;
7
+ status: number | null;
8
+ input: any;
9
+ output: any;
10
+ started_at: Date;
11
+ respond_at: Date | null;
12
+ completed_at: Date;
13
+ }
14
+ // export namespace IFetchEvent {
15
+ // export interface IFunction {
16
+ // (connection: IConnection, ...args: any[]): Promise<any>;
17
+ // METADATA: {
18
+ // method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
19
+ // path: string;
20
+ // request: null | {
21
+ // type: string;
22
+ // encrypted: boolean;
23
+ // };
24
+ // response: null | {
25
+ // type: string;
26
+ // encrypted: boolean;
27
+ // };
28
+ // };
29
+ // status: null | number;
30
+ // }
31
+ // }
@@ -1,69 +1,69 @@
1
- /**
2
- * Properties of remote API route.
3
- *
4
- * @author Jeongho Nam - https://github.com/samchon
5
- */
6
- export interface IFetchRoute<
7
- Method extends "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
8
- > {
9
- /**
10
- * Method of the HTTP request.
11
- */
12
- method: Method;
13
-
14
- /**
15
- * Path of the HTTP request.
16
- */
17
- path: string;
18
-
19
- /**
20
- * Path template.
21
- *
22
- * Filled since 3.2.2 version.
23
- */
24
- template?: string;
25
-
26
- /**
27
- * Request body data info.
28
- */
29
- request: Method extends "DELETE" | "POST" | "PUT" | "PATCH"
30
- ? IFetchRoute.IBody | null
31
- : null;
32
-
33
- /**
34
- * Response body data info.
35
- */
36
- response: Method extends "HEAD" ? null : IFetchRoute.IBody;
37
-
38
- /**
39
- * When special status code being used.
40
- */
41
- status: number | null;
42
-
43
- /**
44
- * Parser of the query string.
45
- *
46
- * If content type of response body is `application/x-www-form-urlencoded`,
47
- * then this `parseQuery` function would be called.
48
- *
49
- * If you've forgotten to configuring this `parseQuery` property about the
50
- * `application/x-www-form-urlencoded` typed response body data, then
51
- * only the `URLSearchParams` typed instance would be returned instead.
52
- */
53
- parseQuery?(input: URLSearchParams): any;
54
- }
55
- export namespace IFetchRoute {
56
- /**
57
- * Metadata of body.
58
- *
59
- * Describes how content-type being used in body, and whether encrypted or not.
60
- */
61
- export interface IBody {
62
- type:
63
- | "application/json"
64
- | "application/x-www-form-urlencoded"
65
- | "multipart/form-data"
66
- | "text/plain";
67
- encrypted?: boolean;
68
- }
69
- }
1
+ /**
2
+ * Properties of remote API route.
3
+ *
4
+ * @author Jeongho Nam - https://github.com/samchon
5
+ */
6
+ export interface IFetchRoute<
7
+ Method extends "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
8
+ > {
9
+ /**
10
+ * Method of the HTTP request.
11
+ */
12
+ method: Method;
13
+
14
+ /**
15
+ * Path of the HTTP request.
16
+ */
17
+ path: string;
18
+
19
+ /**
20
+ * Path template.
21
+ *
22
+ * Filled since 3.2.2 version.
23
+ */
24
+ template?: string;
25
+
26
+ /**
27
+ * Request body data info.
28
+ */
29
+ request: Method extends "DELETE" | "POST" | "PUT" | "PATCH"
30
+ ? IFetchRoute.IBody | null
31
+ : null;
32
+
33
+ /**
34
+ * Response body data info.
35
+ */
36
+ response: Method extends "HEAD" ? null : IFetchRoute.IBody;
37
+
38
+ /**
39
+ * When special status code being used.
40
+ */
41
+ status: number | null;
42
+
43
+ /**
44
+ * Parser of the query string.
45
+ *
46
+ * If content type of response body is `application/x-www-form-urlencoded`,
47
+ * then this `parseQuery` function would be called.
48
+ *
49
+ * If you've forgotten to configuring this `parseQuery` property about the
50
+ * `application/x-www-form-urlencoded` typed response body data, then
51
+ * only the `URLSearchParams` typed instance would be returned instead.
52
+ */
53
+ parseQuery?(input: URLSearchParams): any;
54
+ }
55
+ export namespace IFetchRoute {
56
+ /**
57
+ * Metadata of body.
58
+ *
59
+ * Describes how content-type being used in body, and whether encrypted or not.
60
+ */
61
+ export interface IBody {
62
+ type:
63
+ | "application/json"
64
+ | "application/x-www-form-urlencoded"
65
+ | "multipart/form-data"
66
+ | "text/plain";
67
+ encrypted?: boolean;
68
+ }
69
+ }
@@ -1,100 +1,100 @@
1
- /**
2
- * Propagation type.
3
- *
4
- * `IPropagation` is a type gathering all possible status codes and their body
5
- * data types as a discriminated union type. You can specify the status code and
6
- * its body data type just by using conditional statement like below.
7
- *
8
- * ```typescript
9
- * type Output = IPropagation<{
10
- * 200: ISeller.IAuthorized;
11
- * 400: TypeGuardError.IProps;
12
- * >};
13
- *
14
- * const output: Output = await sdk.sellers.authenticate.join(input);
15
- * if (output.success) {
16
- * // automatically casted to "ISeller.IAuthorized" type
17
- * const authorized: ISeller.IAuthorized = output.data;
18
- * } else if (output.status === 400) {
19
- * // automatically casted to "TypeGuardError.IProps" type
20
- * const error: TypeGuardError.IProps = output.data;
21
- * } else {
22
- * // unknown type when out of pre-defined status codes
23
- * const result: unknown = output.data;
24
- * }
25
- * ```
26
- *
27
- * For reference, this `IPropagation` type is utilized by SDK library generated by
28
- * `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
29
- * In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
30
- * typed data directly, but returns this `IPropagation` typed object instead.
31
- *
32
- * @template StatusMap Map of status code and its body data type.
33
- * @template Success Default success status code.
34
- * @author Jeongho Nam - https://github.com/samchon
35
- */
36
- export type IPropagation<
37
- StatusMap extends {
38
- [P in IPropagation.Status]?: any;
39
- },
40
- Success extends number = 200 | 201,
41
- > =
42
- | {
43
- [P in keyof StatusMap]: IPropagation.IBranch<
44
- P extends Success ? true : false,
45
- P,
46
- StatusMap[P]
47
- >;
48
- }[keyof StatusMap]
49
- | IPropagation.IBranch<false, unknown, unknown>;
50
- export namespace IPropagation {
51
- /**
52
- * Type of configurable status codes.
53
- *
54
- * The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the range
55
- * of status codes. If `5XX` is specified, it means the status code is in the
56
- * range of `500` to `599`.
57
- */
58
- export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
59
-
60
- /**
61
- * Branch type of propagation.
62
- *
63
- * `IPropagation.IBranch` is a branch type composing `IPropagation` type,
64
- * which is gathering all possible status codes and their body data types
65
- * as a union type.
66
- */
67
- export interface IBranch<Success extends boolean, StatusValue, BodyData> {
68
- success: Success;
69
- status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX"
70
- ? StatusRange<StatusValue>
71
- : StatusValue extends number
72
- ? StatusValue
73
- : never;
74
- data: BodyData;
75
- headers: Record<string, string | string[]>;
76
- }
77
-
78
- /**
79
- * Range of status codes by the first digit.
80
- */
81
- export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0
82
- ? IntRange<200, 299>
83
- : T extends 3
84
- ? IntRange<300, 399>
85
- : T extends 4
86
- ? IntRange<400, 499>
87
- : IntRange<500, 599>;
88
-
89
- type IntRange<F extends number, T extends number> = Exclude<
90
- Enumerate<T>,
91
- Enumerate<F>
92
- >;
93
-
94
- type Enumerate<
95
- N extends number,
96
- Acc extends number[] = [],
97
- > = Acc["length"] extends N
98
- ? Acc[number]
99
- : Enumerate<N, [...Acc, Acc["length"]]>;
100
- }
1
+ /**
2
+ * Propagation type.
3
+ *
4
+ * `IPropagation` is a type gathering all possible status codes and their body
5
+ * data types as a discriminated union type. You can specify the status code and
6
+ * its body data type just by using conditional statement like below.
7
+ *
8
+ * ```typescript
9
+ * type Output = IPropagation<{
10
+ * 200: ISeller.IAuthorized;
11
+ * 400: TypeGuardError.IProps;
12
+ * >};
13
+ *
14
+ * const output: Output = await sdk.sellers.authenticate.join(input);
15
+ * if (output.success) {
16
+ * // automatically casted to "ISeller.IAuthorized" type
17
+ * const authorized: ISeller.IAuthorized = output.data;
18
+ * } else if (output.status === 400) {
19
+ * // automatically casted to "TypeGuardError.IProps" type
20
+ * const error: TypeGuardError.IProps = output.data;
21
+ * } else {
22
+ * // unknown type when out of pre-defined status codes
23
+ * const result: unknown = output.data;
24
+ * }
25
+ * ```
26
+ *
27
+ * For reference, this `IPropagation` type is utilized by SDK library generated by
28
+ * `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
29
+ * In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
30
+ * typed data directly, but returns this `IPropagation` typed object instead.
31
+ *
32
+ * @template StatusMap Map of status code and its body data type.
33
+ * @template Success Default success status code.
34
+ * @author Jeongho Nam - https://github.com/samchon
35
+ */
36
+ export type IPropagation<
37
+ StatusMap extends {
38
+ [P in IPropagation.Status]?: any;
39
+ },
40
+ Success extends number = 200 | 201,
41
+ > =
42
+ | {
43
+ [P in keyof StatusMap]: IPropagation.IBranch<
44
+ P extends Success ? true : false,
45
+ P,
46
+ StatusMap[P]
47
+ >;
48
+ }[keyof StatusMap]
49
+ | IPropagation.IBranch<false, unknown, unknown>;
50
+ export namespace IPropagation {
51
+ /**
52
+ * Type of configurable status codes.
53
+ *
54
+ * The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the range
55
+ * of status codes. If `5XX` is specified, it means the status code is in the
56
+ * range of `500` to `599`.
57
+ */
58
+ export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
59
+
60
+ /**
61
+ * Branch type of propagation.
62
+ *
63
+ * `IPropagation.IBranch` is a branch type composing `IPropagation` type,
64
+ * which is gathering all possible status codes and their body data types
65
+ * as a union type.
66
+ */
67
+ export interface IBranch<Success extends boolean, StatusValue, BodyData> {
68
+ success: Success;
69
+ status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX"
70
+ ? StatusRange<StatusValue>
71
+ : StatusValue extends number
72
+ ? StatusValue
73
+ : never;
74
+ data: BodyData;
75
+ headers: Record<string, string | string[]>;
76
+ }
77
+
78
+ /**
79
+ * Range of status codes by the first digit.
80
+ */
81
+ export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0
82
+ ? IntRange<200, 299>
83
+ : T extends 3
84
+ ? IntRange<300, 399>
85
+ : T extends 4
86
+ ? IntRange<400, 499>
87
+ : IntRange<500, 599>;
88
+
89
+ type IntRange<F extends number, T extends number> = Exclude<
90
+ Enumerate<T>,
91
+ Enumerate<F>
92
+ >;
93
+
94
+ type Enumerate<
95
+ N extends number,
96
+ Acc extends number[] = [],
97
+ > = Acc["length"] extends N
98
+ ? Acc[number]
99
+ : Enumerate<N, [...Acc, Acc["length"]]>;
100
+ }