@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.
@@ -1,247 +1,247 @@
1
- /// <reference lib="dom" />
2
- import { IEncryptionPassword } from "./IEncryptionPassword";
3
- import { IFetchEvent } from "./IFetchEvent";
4
- import { IRandomGenerator } from "./IRandomGenerator";
5
-
6
- /**
7
- * Connection information.
8
- *
9
- * `IConnection` is an interface ttype who represents connection information of the
10
- * remote HTTP server. You can target the remote HTTP server by wring the
11
- * {@link IConnection.host} variable down. Also, you can configure special header values
12
- * by specializing the {@link IConnection.headers} variable.
13
- *
14
- * If the remote HTTP server encrypts or decrypts its body data through the AES-128/256
15
- * algorithm, specify the {@link IConnection.encryption} with {@link IEncryptionPassword}
16
- * or {@link IEncryptionPassword.Closure} variable.
17
- *
18
- * @author Jenogho Nam - https://github.com/samchon
19
- * @author Seungjun We - https://github.com/SeungjunWe
20
- */
21
- export interface IConnection<Headers extends object = {}> {
22
- /**
23
- * Host address of the remote HTTP server.
24
- */
25
- host: string;
26
-
27
- /**
28
- * Header values delivered to the remote HTTP server.
29
- */
30
- headers?: Record<string, IConnection.HeaderValue> &
31
- IConnection.Headerify<Headers>;
32
-
33
- /**
34
- * Use simulation mode.
35
- *
36
- * If you configure this property to be `true` or assign an {@link IRandomGenerator}
37
- * instance, your SDK library does not send any request to remote backend server,
38
- * but just returns random data generated by `typia.random<T>()` function with
39
- * request data validation.
40
- *
41
- * By the way, to utilize this simulation mode, SDK library must be generated with
42
- * {@link INestiaConfig.simulate} option, too. Open `nestia.config.ts` file, and
43
- * configure {@link INestiaConfig.simulate} property to be `true`. Them, newly
44
- * generated SDK library would have a built-in mock-up data generator.
45
- *
46
- * @default false
47
- */
48
- simulate?: boolean | Partial<IRandomGenerator>;
49
-
50
- /**
51
- * Logger function.
52
- *
53
- * This function is called when the fetch event is completed.
54
- *
55
- * @param event Event information of the fetch event.
56
- */
57
- logger?: (event: IFetchEvent) => Promise<void>;
58
-
59
- /**
60
- * Encryption password of its closure function.
61
- *
62
- * Define it only when target backend server is encrypting body data through
63
- * `@EncryptedRoute` or `@EncryptedBody` decorators of `@nestia/core` for
64
- * security reason.
65
- */
66
- encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
67
-
68
- /**
69
- * Additional options for the `fetch` function.
70
- */
71
- options?: IConnection.IOptions;
72
-
73
- /**
74
- * Custom fetch function.
75
- *
76
- * If you want to use custom `fetch` function instead of built-in function,
77
- * assign your custom `fetch` function into this property.
78
- */
79
- fetch?: typeof fetch;
80
- }
81
- export namespace IConnection {
82
- /**
83
- * Addiotional options for the `fetch` function.
84
- *
85
- * Almost same with {@link RequestInit} type of the {@link fetch} function,
86
- * but `body`, `headers` and `method` properties are omitted.
87
- *
88
- * The reason why defining duplicated definition of {@link RequestInit}
89
- * is for legacy NodeJS environments, which does not have the {@link fetch}
90
- * function type.
91
- */
92
- export interface IOptions {
93
- /**
94
- * A string indicating how the request will interact with the browser's
95
- * cache to set request's cache.
96
- */
97
- cache?:
98
- | "default"
99
- | "force-cache"
100
- | "no-cache"
101
- | "no-store"
102
- | "only-if-cached"
103
- | "reload";
104
-
105
- /**
106
- * A string indicating whether credentials will be sent with the request
107
- * always, never, or only when sent to a same-origin URL. Sets request's
108
- * credentials.
109
- */
110
- credentials?: "omit" | "same-origin" | "include";
111
-
112
- /**
113
- * A cryptographic hash of the resource to be fetched by request.
114
- *
115
- * Sets request's integrity.
116
- */
117
- integrity?: string;
118
-
119
- /**
120
- * A boolean to set request's keepalive.
121
- */
122
- keepalive?: boolean;
123
-
124
- /**
125
- * A string to indicate whether the request will use CORS, or will be
126
- * restricted to same-origin URLs.
127
- *
128
- * Sets request's mode.
129
- */
130
- mode?: "cors" | "navigate" | "no-cors" | "same-origin";
131
-
132
- /**
133
- * A string indicating whether request follows redirects, results in
134
- * an error upon encountering a redirect, or returns the redirect
135
- * (in an opaque fashion).
136
- *
137
- * Sets request's redirect.
138
- */
139
- redirect?: "error" | "follow" | "manual";
140
-
141
- /**
142
- * A string whose value is a same-origin URL, "about:client", or the
143
- * empty string, to set request's referrer.
144
- */
145
- referrer?: string;
146
-
147
- /**
148
- * A referrer policy to set request's referrerPolicy.
149
- */
150
- referrerPolicy?:
151
- | ""
152
- | "no-referrer"
153
- | "no-referrer-when-downgrade"
154
- | "origin"
155
- | "origin-when-cross-origin"
156
- | "same-origin"
157
- | "strict-origin"
158
- | "strict-origin-when-cross-origin"
159
- | "unsafe-url";
160
-
161
- /**
162
- * An AbortSignal to set request's signal.
163
- */
164
- signal?: AbortSignal | null;
165
- }
166
-
167
- /**
168
- * Type of allowed header values.
169
- *
170
- * Only atomic or array of atomic values are allowed.
171
- */
172
- export type HeaderValue =
173
- | string
174
- | boolean
175
- | number
176
- | bigint
177
- | string
178
- | Array<boolean>
179
- | Array<number>
180
- | Array<bigint>
181
- | Array<number>
182
- | Array<string>;
183
-
184
- /**
185
- * Type of headers
186
- *
187
- * `Headerify` removes every properties that are not allowed in the
188
- * HTTP headers type.
189
- *
190
- * Below are list of prohibited in HTTP headers.
191
- *
192
- * 1. Value type one of {@link HeaderValue}
193
- * 2. Key is "set-cookie", but value is not an Array type
194
- * 3. Key is one of them, but value is Array type
195
- * - "age"
196
- * - "authorization"
197
- * - "content-length"
198
- * - "content-type"
199
- * - "etag"
200
- * - "expires"
201
- * - "from"
202
- * - "host"
203
- * - "if-modified-since"
204
- * - "if-unmodified-since"
205
- * - "last-modified"
206
- * - "location"
207
- * - "max-forwards"
208
- * - "proxy-authorization"
209
- * - "referer"
210
- * - "retry-after"
211
- * - "server"
212
- * - "user-agent"
213
- */
214
- export type Headerify<T extends object> = {
215
- [P in keyof T]?: T[P] extends HeaderValue | undefined
216
- ? P extends string
217
- ? Lowercase<P> extends "set-cookie"
218
- ? T[P] extends Array<HeaderValue>
219
- ? T[P] | undefined
220
- : never
221
- : Lowercase<P> extends
222
- | "age"
223
- | "authorization"
224
- | "content-length"
225
- | "content-type"
226
- | "etag"
227
- | "expires"
228
- | "from"
229
- | "host"
230
- | "if-modified-since"
231
- | "if-unmodified-since"
232
- | "last-modified"
233
- | "location"
234
- | "max-forwards"
235
- | "proxy-authorization"
236
- | "referer"
237
- | "retry-after"
238
- | "server"
239
- | "user-agent"
240
- ? T[P] extends Array<HeaderValue>
241
- ? never
242
- : T[P] | undefined
243
- : T[P] | undefined
244
- : never
245
- : never;
246
- };
247
- }
1
+ /// <reference lib="dom" />
2
+ import { IEncryptionPassword } from "./IEncryptionPassword";
3
+ import { IFetchEvent } from "./IFetchEvent";
4
+ import { IRandomGenerator } from "./IRandomGenerator";
5
+
6
+ /**
7
+ * Connection information.
8
+ *
9
+ * `IConnection` is an interface ttype who represents connection information of the
10
+ * remote HTTP server. You can target the remote HTTP server by wring the
11
+ * {@link IConnection.host} variable down. Also, you can configure special header values
12
+ * by specializing the {@link IConnection.headers} variable.
13
+ *
14
+ * If the remote HTTP server encrypts or decrypts its body data through the AES-128/256
15
+ * algorithm, specify the {@link IConnection.encryption} with {@link IEncryptionPassword}
16
+ * or {@link IEncryptionPassword.Closure} variable.
17
+ *
18
+ * @author Jenogho Nam - https://github.com/samchon
19
+ * @author Seungjun We - https://github.com/SeungjunWe
20
+ */
21
+ export interface IConnection<Headers extends object = {}> {
22
+ /**
23
+ * Host address of the remote HTTP server.
24
+ */
25
+ host: string;
26
+
27
+ /**
28
+ * Header values delivered to the remote HTTP server.
29
+ */
30
+ headers?: Record<string, IConnection.HeaderValue> &
31
+ IConnection.Headerify<Headers>;
32
+
33
+ /**
34
+ * Use simulation mode.
35
+ *
36
+ * If you configure this property to be `true` or assign an {@link IRandomGenerator}
37
+ * instance, your SDK library does not send any request to remote backend server,
38
+ * but just returns random data generated by `typia.random<T>()` function with
39
+ * request data validation.
40
+ *
41
+ * By the way, to utilize this simulation mode, SDK library must be generated with
42
+ * {@link INestiaConfig.simulate} option, too. Open `nestia.config.ts` file, and
43
+ * configure {@link INestiaConfig.simulate} property to be `true`. Them, newly
44
+ * generated SDK library would have a built-in mock-up data generator.
45
+ *
46
+ * @default false
47
+ */
48
+ simulate?: boolean | Partial<IRandomGenerator>;
49
+
50
+ /**
51
+ * Logger function.
52
+ *
53
+ * This function is called when the fetch event is completed.
54
+ *
55
+ * @param event Event information of the fetch event.
56
+ */
57
+ logger?: (event: IFetchEvent) => Promise<void>;
58
+
59
+ /**
60
+ * Encryption password of its closure function.
61
+ *
62
+ * Define it only when target backend server is encrypting body data through
63
+ * `@EncryptedRoute` or `@EncryptedBody` decorators of `@nestia/core` for
64
+ * security reason.
65
+ */
66
+ encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
67
+
68
+ /**
69
+ * Additional options for the `fetch` function.
70
+ */
71
+ options?: IConnection.IOptions;
72
+
73
+ /**
74
+ * Custom fetch function.
75
+ *
76
+ * If you want to use custom `fetch` function instead of built-in function,
77
+ * assign your custom `fetch` function into this property.
78
+ */
79
+ fetch?: typeof fetch;
80
+ }
81
+ export namespace IConnection {
82
+ /**
83
+ * Addiotional options for the `fetch` function.
84
+ *
85
+ * Almost same with {@link RequestInit} type of the {@link fetch} function,
86
+ * but `body`, `headers` and `method` properties are omitted.
87
+ *
88
+ * The reason why defining duplicated definition of {@link RequestInit}
89
+ * is for legacy NodeJS environments, which does not have the {@link fetch}
90
+ * function type.
91
+ */
92
+ export interface IOptions {
93
+ /**
94
+ * A string indicating how the request will interact with the browser's
95
+ * cache to set request's cache.
96
+ */
97
+ cache?:
98
+ | "default"
99
+ | "force-cache"
100
+ | "no-cache"
101
+ | "no-store"
102
+ | "only-if-cached"
103
+ | "reload";
104
+
105
+ /**
106
+ * A string indicating whether credentials will be sent with the request
107
+ * always, never, or only when sent to a same-origin URL. Sets request's
108
+ * credentials.
109
+ */
110
+ credentials?: "omit" | "same-origin" | "include";
111
+
112
+ /**
113
+ * A cryptographic hash of the resource to be fetched by request.
114
+ *
115
+ * Sets request's integrity.
116
+ */
117
+ integrity?: string;
118
+
119
+ /**
120
+ * A boolean to set request's keepalive.
121
+ */
122
+ keepalive?: boolean;
123
+
124
+ /**
125
+ * A string to indicate whether the request will use CORS, or will be
126
+ * restricted to same-origin URLs.
127
+ *
128
+ * Sets request's mode.
129
+ */
130
+ mode?: "cors" | "navigate" | "no-cors" | "same-origin";
131
+
132
+ /**
133
+ * A string indicating whether request follows redirects, results in
134
+ * an error upon encountering a redirect, or returns the redirect
135
+ * (in an opaque fashion).
136
+ *
137
+ * Sets request's redirect.
138
+ */
139
+ redirect?: "error" | "follow" | "manual";
140
+
141
+ /**
142
+ * A string whose value is a same-origin URL, "about:client", or the
143
+ * empty string, to set request's referrer.
144
+ */
145
+ referrer?: string;
146
+
147
+ /**
148
+ * A referrer policy to set request's referrerPolicy.
149
+ */
150
+ referrerPolicy?:
151
+ | ""
152
+ | "no-referrer"
153
+ | "no-referrer-when-downgrade"
154
+ | "origin"
155
+ | "origin-when-cross-origin"
156
+ | "same-origin"
157
+ | "strict-origin"
158
+ | "strict-origin-when-cross-origin"
159
+ | "unsafe-url";
160
+
161
+ /**
162
+ * An AbortSignal to set request's signal.
163
+ */
164
+ signal?: AbortSignal | null;
165
+ }
166
+
167
+ /**
168
+ * Type of allowed header values.
169
+ *
170
+ * Only atomic or array of atomic values are allowed.
171
+ */
172
+ export type HeaderValue =
173
+ | string
174
+ | boolean
175
+ | number
176
+ | bigint
177
+ | string
178
+ | Array<boolean>
179
+ | Array<number>
180
+ | Array<bigint>
181
+ | Array<number>
182
+ | Array<string>;
183
+
184
+ /**
185
+ * Type of headers
186
+ *
187
+ * `Headerify` removes every properties that are not allowed in the
188
+ * HTTP headers type.
189
+ *
190
+ * Below are list of prohibited in HTTP headers.
191
+ *
192
+ * 1. Value type one of {@link HeaderValue}
193
+ * 2. Key is "set-cookie", but value is not an Array type
194
+ * 3. Key is one of them, but value is Array type
195
+ * - "age"
196
+ * - "authorization"
197
+ * - "content-length"
198
+ * - "content-type"
199
+ * - "etag"
200
+ * - "expires"
201
+ * - "from"
202
+ * - "host"
203
+ * - "if-modified-since"
204
+ * - "if-unmodified-since"
205
+ * - "last-modified"
206
+ * - "location"
207
+ * - "max-forwards"
208
+ * - "proxy-authorization"
209
+ * - "referer"
210
+ * - "retry-after"
211
+ * - "server"
212
+ * - "user-agent"
213
+ */
214
+ export type Headerify<T extends object> = {
215
+ [P in keyof T]?: T[P] extends HeaderValue | undefined
216
+ ? P extends string
217
+ ? Lowercase<P> extends "set-cookie"
218
+ ? T[P] extends Array<HeaderValue>
219
+ ? T[P] | undefined
220
+ : never
221
+ : Lowercase<P> extends
222
+ | "age"
223
+ | "authorization"
224
+ | "content-length"
225
+ | "content-type"
226
+ | "etag"
227
+ | "expires"
228
+ | "from"
229
+ | "host"
230
+ | "if-modified-since"
231
+ | "if-unmodified-since"
232
+ | "last-modified"
233
+ | "location"
234
+ | "max-forwards"
235
+ | "proxy-authorization"
236
+ | "referer"
237
+ | "retry-after"
238
+ | "server"
239
+ | "user-agent"
240
+ ? T[P] extends Array<HeaderValue>
241
+ ? never
242
+ : T[P] | undefined
243
+ : T[P] | undefined
244
+ : never
245
+ : never;
246
+ };
247
+ }
@@ -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
+ // }