@nestia/fetcher 2.4.3 → 3.0.0-dev.20231209

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