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