fets 0.4.14 → 0.4.15
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.
- package/cjs/Response.js +80 -0
- package/cjs/client/auth/oauth.js +34 -0
- package/cjs/client/createClient.js +133 -0
- package/cjs/client/index.js +6 -0
- package/cjs/client/plugins/useClientCookieStore.js +31 -0
- package/cjs/client/types.js +0 -0
- package/cjs/createRouter.js +299 -0
- package/cjs/index.js +16 -0
- package/cjs/plugins/ajv.js +213 -0
- package/cjs/plugins/openapi.js +171 -0
- package/cjs/plugins/utils.js +31 -0
- package/cjs/swagger-ui-html.js +3 -0
- package/cjs/typed-fetch.js +0 -0
- package/cjs/types.js +0 -0
- package/cjs/utils.js +73 -0
- package/cjs/zod/types.js +7 -0
- package/cjs/zod/zod.js +92 -0
- package/esm/Response.js +74 -0
- package/esm/client/auth/oauth.js +31 -0
- package/esm/client/createClient.js +128 -0
- package/esm/client/index.js +3 -0
- package/esm/client/plugins/useClientCookieStore.js +27 -0
- package/esm/client/types.js +0 -0
- package/esm/createRouter.js +293 -0
- package/esm/index.js +7 -0
- package/esm/plugins/ajv.js +208 -0
- package/esm/plugins/openapi.js +166 -0
- package/esm/plugins/utils.js +27 -0
- package/esm/swagger-ui-html.js +1 -0
- package/esm/typed-fetch.js +0 -0
- package/esm/types.js +0 -0
- package/esm/utils.js +69 -0
- package/esm/zod/types.js +3 -0
- package/esm/zod/zod.js +88 -0
- package/package.json +1 -1
- package/typings/Response.d.cts +28 -0
- package/typings/Response.d.ts +28 -0
- package/typings/client/auth/oauth.d.cts +150 -0
- package/typings/client/auth/oauth.d.ts +150 -0
- package/typings/client/createClient.d.cts +34 -0
- package/typings/client/createClient.d.ts +34 -0
- package/typings/client/index.d.cts +3 -0
- package/typings/client/index.d.ts +3 -0
- package/typings/client/plugins/useClientCookieStore.d.cts +3 -0
- package/typings/client/plugins/useClientCookieStore.d.ts +3 -0
- package/typings/client/types.d.cts +426 -0
- package/typings/client/types.d.ts +426 -0
- package/typings/createRouter.d.cts +6 -0
- package/typings/createRouter.d.ts +6 -0
- package/typings/index.d.cts +7 -0
- package/typings/index.d.ts +7 -0
- package/typings/plugins/ajv.d.cts +4 -0
- package/typings/plugins/ajv.d.ts +4 -0
- package/typings/plugins/openapi.d.cts +33 -0
- package/typings/plugins/openapi.d.ts +33 -0
- package/typings/plugins/utils.d.cts +1 -0
- package/typings/plugins/utils.d.ts +1 -0
- package/typings/swagger-ui-html.d.cts +2 -0
- package/typings/swagger-ui-html.d.ts +2 -0
- package/typings/typed-fetch.d.cts +232 -0
- package/typings/typed-fetch.d.ts +232 -0
- package/typings/types.d.cts +261 -0
- package/typings/types.d.ts +261 -0
- package/typings/utils.d.cts +31 -0
- package/typings/utils.d.ts +31 -0
- package/typings/zod/types.d.cts +39 -0
- package/typings/zod/types.d.ts +39 -0
- package/typings/zod/zod.d.cts +2 -0
- package/typings/zod/zod.d.ts +2 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { StatusCodeMap } from './types';
|
|
2
|
+
export type OkStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
3
|
+
type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
4
|
+
type ClientErrorStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
5
|
+
type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
6
|
+
export type StatusCode = OkStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode;
|
|
7
|
+
export type NotOkStatusCode = Exclude<StatusCode, OkStatusCode>;
|
|
8
|
+
export type TypedBody<TJSON, TFormData extends Record<string, FormDataEntryValue>, THeaders extends Record<string, string>> = Omit<Body, 'json' | 'formData' | 'headers'> & {
|
|
9
|
+
/**
|
|
10
|
+
* The `json()` method takes the stream and reads it to completion.
|
|
11
|
+
* It returns a promise which resolves with the result of parsing the body text as JSON.
|
|
12
|
+
*
|
|
13
|
+
* Note that despite the method being named `json()`, the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.
|
|
14
|
+
*
|
|
15
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json
|
|
16
|
+
*/
|
|
17
|
+
json(): Promise<TJSON>;
|
|
18
|
+
/**
|
|
19
|
+
* The formData() method takes the stream and reads it to completion. It returns a promise that resolves with a `FormData` object.
|
|
20
|
+
*
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/formData
|
|
22
|
+
*/
|
|
23
|
+
formData(): Promise<TypedFormData<TFormData>>;
|
|
24
|
+
/**
|
|
25
|
+
* The headers read-only property of the Response interface contains the Headers object associated with the response.
|
|
26
|
+
*
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/headers
|
|
28
|
+
*/
|
|
29
|
+
headers: TypedHeaders<THeaders>;
|
|
30
|
+
};
|
|
31
|
+
type DefaultHTTPHeaders = 'accept' | 'accept-language' | 'content-language' | 'content-type' | 'content-length';
|
|
32
|
+
type Maybe = undefined | null;
|
|
33
|
+
type UndefinedToNull<T> = T extends undefined ? Exclude<T, undefined> | null : T;
|
|
34
|
+
export type TypedHeaders<TMap extends Record<string, string>> = {
|
|
35
|
+
append<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
36
|
+
delete<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): void;
|
|
37
|
+
get<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends keyof TMap ? UndefinedToNull<TMap[TName]> : TName extends DefaultHTTPHeaders ? string | null : never;
|
|
38
|
+
has<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends DefaultHTTPHeaders ? boolean : TName extends keyof TMap ? TMap[TName] extends Maybe ? boolean : true : never;
|
|
39
|
+
set<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
40
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName], key: TName, parent: TypedHeaders<TMap>) => void, thisArg?: any): void;
|
|
41
|
+
entries(): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
42
|
+
keys(): IterableIterator<keyof TMap>;
|
|
43
|
+
values(): IterableIterator<TMap[keyof TMap]>;
|
|
44
|
+
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
45
|
+
};
|
|
46
|
+
export type TypedHeadersCtor = new <TMap extends Record<string, string>>(init?: TMap) => TypedHeaders<TMap>;
|
|
47
|
+
export type TypedResponseInit<TStatusCode extends StatusCode = 200> = Omit<ResponseInit, 'status' | 'statusText'> & {
|
|
48
|
+
/**
|
|
49
|
+
* This is the status code that will be set in the response.
|
|
50
|
+
* For example, 200 for success, 404 if the resource could not be found.
|
|
51
|
+
*
|
|
52
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/status
|
|
53
|
+
*/
|
|
54
|
+
status: TStatusCode;
|
|
55
|
+
/**
|
|
56
|
+
* This is the status message that will be set in the response.
|
|
57
|
+
* You don't need to set this value if it's a standard message.
|
|
58
|
+
* For example, this would be OK for a status code 200, Continue for 100, Not Found for 404.
|
|
59
|
+
*
|
|
60
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
61
|
+
*/
|
|
62
|
+
statusText?: TStatusCode extends keyof StatusTextMap ? StatusTextMap[TStatusCode] : string;
|
|
63
|
+
};
|
|
64
|
+
export type StatusTextMap = {
|
|
65
|
+
100: 'Continue';
|
|
66
|
+
101: 'Switching Protocols';
|
|
67
|
+
102: 'Processing';
|
|
68
|
+
103: 'Early Hints';
|
|
69
|
+
200: 'OK';
|
|
70
|
+
201: 'Created';
|
|
71
|
+
202: 'Accepted';
|
|
72
|
+
203: 'Non-Authoritative Information';
|
|
73
|
+
204: 'No Content';
|
|
74
|
+
205: 'Reset Content';
|
|
75
|
+
206: 'Partial Content';
|
|
76
|
+
207: 'Multi-Status';
|
|
77
|
+
208: 'Already Reported';
|
|
78
|
+
226: 'IM Used';
|
|
79
|
+
300: 'Multiple Choices';
|
|
80
|
+
301: 'Moved Permanently';
|
|
81
|
+
302: 'Found';
|
|
82
|
+
303: 'See Other';
|
|
83
|
+
304: 'Not Modified';
|
|
84
|
+
305: 'Use Proxy';
|
|
85
|
+
307: 'Temporary Redirect';
|
|
86
|
+
308: 'Permanent Redirect';
|
|
87
|
+
400: 'Bad Request';
|
|
88
|
+
401: 'Unauthorized';
|
|
89
|
+
402: 'Payment Required';
|
|
90
|
+
403: 'Forbidden';
|
|
91
|
+
404: 'Not Found';
|
|
92
|
+
405: 'Method Not Allowed';
|
|
93
|
+
406: 'Not Acceptable';
|
|
94
|
+
407: 'Proxy Authentication Required';
|
|
95
|
+
408: 'Request Timeout';
|
|
96
|
+
409: 'Conflict';
|
|
97
|
+
410: 'Gone';
|
|
98
|
+
411: 'Length Required';
|
|
99
|
+
412: 'Precondition Failed';
|
|
100
|
+
413: 'Payload Too Large';
|
|
101
|
+
414: 'URI Too Long';
|
|
102
|
+
415: 'Unsupported Media Type';
|
|
103
|
+
416: 'Range Not Satisfiable';
|
|
104
|
+
417: 'Expectation Failed';
|
|
105
|
+
418: "I'm a Teapot";
|
|
106
|
+
421: 'Misdirected Request';
|
|
107
|
+
422: 'Unprocessable Entity';
|
|
108
|
+
423: 'Locked';
|
|
109
|
+
424: 'Failed Dependency';
|
|
110
|
+
425: 'Too Early';
|
|
111
|
+
426: 'Upgrade Required';
|
|
112
|
+
428: 'Precondition Required';
|
|
113
|
+
429: 'Too Many Requests';
|
|
114
|
+
431: 'Request Header Fields Too Large';
|
|
115
|
+
451: 'Unavailable For Legal Reasons';
|
|
116
|
+
500: 'Internal Server Error';
|
|
117
|
+
501: 'Not Implemented';
|
|
118
|
+
502: 'Bad Gateway';
|
|
119
|
+
503: 'Service Unavailable';
|
|
120
|
+
504: 'Gateway Timeout';
|
|
121
|
+
505: 'HTTP Version Not Supported';
|
|
122
|
+
506: 'Variant Also Negotiates';
|
|
123
|
+
507: 'Insufficient Storage';
|
|
124
|
+
508: 'Loop Detected';
|
|
125
|
+
509: 'Bandwidth Limit Exceeded';
|
|
126
|
+
510: 'Not Extended';
|
|
127
|
+
511: 'Network Authentication Required';
|
|
128
|
+
};
|
|
129
|
+
export type TypedResponse<TJSON = unknown, THeaders extends Record<string, string> = Record<string, string>, TStatusCode extends StatusCode = StatusCode> = Omit<Response, 'json' | 'status' | 'ok'> & Omit<TypedBody<TJSON, any, THeaders>, 'formData'> & {
|
|
130
|
+
/**
|
|
131
|
+
* The status read-only property of the Response interface contains the HTTP status codes of the response.
|
|
132
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/status
|
|
133
|
+
*
|
|
134
|
+
* You can use `Response.ok` to check if the status is in the range 200-299.
|
|
135
|
+
*/
|
|
136
|
+
status: TStatusCode;
|
|
137
|
+
/**
|
|
138
|
+
* The statusText read-only property of the Response interface contains the status message corresponding to the HTTP status code in Response.status.
|
|
139
|
+
* For example, this would be OK for a status code 200, Continue for 100, Not Found for 404.
|
|
140
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
141
|
+
*/
|
|
142
|
+
statusText: TStatusCode extends keyof StatusTextMap ? StatusTextMap[TStatusCode] : string;
|
|
143
|
+
} & {
|
|
144
|
+
/**
|
|
145
|
+
* The ok read-only property of the Response interface contains a Boolean stating whether the response was successful (status in the range 200-299) or not.
|
|
146
|
+
*/
|
|
147
|
+
ok: TStatusCode extends OkStatusCode ? true : false;
|
|
148
|
+
};
|
|
149
|
+
export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
150
|
+
new <TStatusCode extends StatusCode = 200>(body: BodyInit | null | undefined, init: (TypedResponseInit<TStatusCode> & {
|
|
151
|
+
status: TStatusCode;
|
|
152
|
+
}) | undefined): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
153
|
+
new (body: BodyInit | null | undefined, init: ResponseInit | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
154
|
+
new (body?: BodyInit | null | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
155
|
+
/**
|
|
156
|
+
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
157
|
+
* and a `Content-Type` header which is set to `application/json`. The response status, status message, and additional headers can also be set.
|
|
158
|
+
* @param data The JSON data to be used as the response body.
|
|
159
|
+
* @param options An options object containing settings for the response, including the status code, status text, and headers. This is the same as the options parameter of the `Response()` constructor.
|
|
160
|
+
*
|
|
161
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
162
|
+
*/
|
|
163
|
+
json<TJSON, TStatusCode extends StatusCode>(data: TJSON, options: TypedResponseInit<TStatusCode>): TypedResponse<TJSON, Record<string, string>, TStatusCode>;
|
|
164
|
+
/**
|
|
165
|
+
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
166
|
+
* and a `Content-Type` header which is set to `application/json`.
|
|
167
|
+
* @param data The JSON data to be used as the response body.
|
|
168
|
+
*
|
|
169
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
170
|
+
*/
|
|
171
|
+
json<TJSON>(data: TJSON): TypedResponse<TJSON, Record<string, string>, 200>;
|
|
172
|
+
/**
|
|
173
|
+
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
174
|
+
* @param url The URL that the new response is to originate from.
|
|
175
|
+
* @param status An optional status code for the response (e.g., 302.)
|
|
176
|
+
*
|
|
177
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
178
|
+
*/
|
|
179
|
+
redirect<TStatusCode extends StatusCode>(url: string | URL, status: TStatusCode): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
180
|
+
/**
|
|
181
|
+
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
182
|
+
* @param url The URL that the new response is to originate from.
|
|
183
|
+
*
|
|
184
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
185
|
+
*/
|
|
186
|
+
redirect(url: string | URL): TypedResponse<any, Record<string, string>, 302>;
|
|
187
|
+
};
|
|
188
|
+
export type TypedResponseWithJSONStatusMap<TResponseJSONStatusMap extends StatusCodeMap<any>> = {
|
|
189
|
+
[TStatusCode in keyof TResponseJSONStatusMap]: TStatusCode extends StatusCode ? TypedResponse<TResponseJSONStatusMap[TStatusCode], Record<string, string>, TStatusCode> : never;
|
|
190
|
+
}[keyof TResponseJSONStatusMap];
|
|
191
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
192
|
+
export type TypedRequestInit<THeaders extends Record<string, string>, TMethod extends HTTPMethod, TFormData extends Record<string, FormDataEntryValue>> = Omit<RequestInit, 'method' | 'headers' | 'body'> & {
|
|
193
|
+
method: TMethod;
|
|
194
|
+
headers: TypedHeaders<THeaders>;
|
|
195
|
+
body?: Exclude<BodyInit, FormData> | TFormData;
|
|
196
|
+
};
|
|
197
|
+
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TPathParams extends Record<string, any> = Record<string, any>> = Omit<Request, 'json' | 'method' | 'headers' | 'formData'> & TypedBody<TJSON, TFormData, THeaders> & {
|
|
198
|
+
method: TMethod;
|
|
199
|
+
parsedUrl: TypedURL<TQueryParams>;
|
|
200
|
+
params: TPathParams;
|
|
201
|
+
query: TQueryParams;
|
|
202
|
+
};
|
|
203
|
+
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod, TQueryParams extends Record<string, string | string[]>, TFormData extends Record<string, FormDataEntryValue>>(input: string | TypedURL<TQueryParams>, init?: TypedRequestInit<THeaders, TMethod, TFormData>) => TypedRequest<any, TFormData, THeaders, TMethod, TQueryParams, any>;
|
|
204
|
+
export interface TypedURLSearchParams<TMap extends Record<string, string | string[]>> {
|
|
205
|
+
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
206
|
+
delete(name: keyof TMap): void;
|
|
207
|
+
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName];
|
|
208
|
+
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : [TMap[TName]];
|
|
209
|
+
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
210
|
+
sort(): void;
|
|
211
|
+
toString(): string;
|
|
212
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName], name: TName, parent: TypedURLSearchParams<TMap>) => void, thisArg?: any): void;
|
|
213
|
+
}
|
|
214
|
+
export type TypedURLSearchParamsCtor = new <TMap extends Record<string, string | string[]>>(init?: TMap) => TypedURLSearchParams<TMap>;
|
|
215
|
+
export type TypedURL<TQueryParams extends Record<string, string | string[]>> = Omit<URL, 'searchParams'> & {
|
|
216
|
+
searchParams: TypedURLSearchParams<TQueryParams>;
|
|
217
|
+
};
|
|
218
|
+
export type TypedURLCtor = new <TQueryParams extends Record<string, string | string[]>>(input: string, base?: string | TypedURL<any>) => TypedURL<TQueryParams>;
|
|
219
|
+
export interface TypedFormData<TMap extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>> {
|
|
220
|
+
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
221
|
+
delete(name: keyof TMap): void;
|
|
222
|
+
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName];
|
|
223
|
+
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : TMap[TName][];
|
|
224
|
+
has<TName extends string>(name: TName): TName extends keyof TMap ? (TMap[TName] extends Maybe ? boolean : true) : false;
|
|
225
|
+
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
226
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName], key: TName, parent: this) => void, thisArg?: any): void;
|
|
227
|
+
entries(): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
228
|
+
keys(): IterableIterator<keyof TMap>;
|
|
229
|
+
values(): IterableIterator<TMap[keyof TMap]>;
|
|
230
|
+
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
231
|
+
}
|
|
232
|
+
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { StatusCodeMap } from './types';
|
|
2
|
+
export type OkStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
3
|
+
type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
4
|
+
type ClientErrorStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
5
|
+
type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
6
|
+
export type StatusCode = OkStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode;
|
|
7
|
+
export type NotOkStatusCode = Exclude<StatusCode, OkStatusCode>;
|
|
8
|
+
export type TypedBody<TJSON, TFormData extends Record<string, FormDataEntryValue>, THeaders extends Record<string, string>> = Omit<Body, 'json' | 'formData' | 'headers'> & {
|
|
9
|
+
/**
|
|
10
|
+
* The `json()` method takes the stream and reads it to completion.
|
|
11
|
+
* It returns a promise which resolves with the result of parsing the body text as JSON.
|
|
12
|
+
*
|
|
13
|
+
* Note that despite the method being named `json()`, the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.
|
|
14
|
+
*
|
|
15
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json
|
|
16
|
+
*/
|
|
17
|
+
json(): Promise<TJSON>;
|
|
18
|
+
/**
|
|
19
|
+
* The formData() method takes the stream and reads it to completion. It returns a promise that resolves with a `FormData` object.
|
|
20
|
+
*
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/formData
|
|
22
|
+
*/
|
|
23
|
+
formData(): Promise<TypedFormData<TFormData>>;
|
|
24
|
+
/**
|
|
25
|
+
* The headers read-only property of the Response interface contains the Headers object associated with the response.
|
|
26
|
+
*
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/headers
|
|
28
|
+
*/
|
|
29
|
+
headers: TypedHeaders<THeaders>;
|
|
30
|
+
};
|
|
31
|
+
type DefaultHTTPHeaders = 'accept' | 'accept-language' | 'content-language' | 'content-type' | 'content-length';
|
|
32
|
+
type Maybe = undefined | null;
|
|
33
|
+
type UndefinedToNull<T> = T extends undefined ? Exclude<T, undefined> | null : T;
|
|
34
|
+
export type TypedHeaders<TMap extends Record<string, string>> = {
|
|
35
|
+
append<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
36
|
+
delete<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): void;
|
|
37
|
+
get<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends keyof TMap ? UndefinedToNull<TMap[TName]> : TName extends DefaultHTTPHeaders ? string | null : never;
|
|
38
|
+
has<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends DefaultHTTPHeaders ? boolean : TName extends keyof TMap ? TMap[TName] extends Maybe ? boolean : true : never;
|
|
39
|
+
set<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
40
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName], key: TName, parent: TypedHeaders<TMap>) => void, thisArg?: any): void;
|
|
41
|
+
entries(): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
42
|
+
keys(): IterableIterator<keyof TMap>;
|
|
43
|
+
values(): IterableIterator<TMap[keyof TMap]>;
|
|
44
|
+
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
45
|
+
};
|
|
46
|
+
export type TypedHeadersCtor = new <TMap extends Record<string, string>>(init?: TMap) => TypedHeaders<TMap>;
|
|
47
|
+
export type TypedResponseInit<TStatusCode extends StatusCode = 200> = Omit<ResponseInit, 'status' | 'statusText'> & {
|
|
48
|
+
/**
|
|
49
|
+
* This is the status code that will be set in the response.
|
|
50
|
+
* For example, 200 for success, 404 if the resource could not be found.
|
|
51
|
+
*
|
|
52
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/status
|
|
53
|
+
*/
|
|
54
|
+
status: TStatusCode;
|
|
55
|
+
/**
|
|
56
|
+
* This is the status message that will be set in the response.
|
|
57
|
+
* You don't need to set this value if it's a standard message.
|
|
58
|
+
* For example, this would be OK for a status code 200, Continue for 100, Not Found for 404.
|
|
59
|
+
*
|
|
60
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
61
|
+
*/
|
|
62
|
+
statusText?: TStatusCode extends keyof StatusTextMap ? StatusTextMap[TStatusCode] : string;
|
|
63
|
+
};
|
|
64
|
+
export type StatusTextMap = {
|
|
65
|
+
100: 'Continue';
|
|
66
|
+
101: 'Switching Protocols';
|
|
67
|
+
102: 'Processing';
|
|
68
|
+
103: 'Early Hints';
|
|
69
|
+
200: 'OK';
|
|
70
|
+
201: 'Created';
|
|
71
|
+
202: 'Accepted';
|
|
72
|
+
203: 'Non-Authoritative Information';
|
|
73
|
+
204: 'No Content';
|
|
74
|
+
205: 'Reset Content';
|
|
75
|
+
206: 'Partial Content';
|
|
76
|
+
207: 'Multi-Status';
|
|
77
|
+
208: 'Already Reported';
|
|
78
|
+
226: 'IM Used';
|
|
79
|
+
300: 'Multiple Choices';
|
|
80
|
+
301: 'Moved Permanently';
|
|
81
|
+
302: 'Found';
|
|
82
|
+
303: 'See Other';
|
|
83
|
+
304: 'Not Modified';
|
|
84
|
+
305: 'Use Proxy';
|
|
85
|
+
307: 'Temporary Redirect';
|
|
86
|
+
308: 'Permanent Redirect';
|
|
87
|
+
400: 'Bad Request';
|
|
88
|
+
401: 'Unauthorized';
|
|
89
|
+
402: 'Payment Required';
|
|
90
|
+
403: 'Forbidden';
|
|
91
|
+
404: 'Not Found';
|
|
92
|
+
405: 'Method Not Allowed';
|
|
93
|
+
406: 'Not Acceptable';
|
|
94
|
+
407: 'Proxy Authentication Required';
|
|
95
|
+
408: 'Request Timeout';
|
|
96
|
+
409: 'Conflict';
|
|
97
|
+
410: 'Gone';
|
|
98
|
+
411: 'Length Required';
|
|
99
|
+
412: 'Precondition Failed';
|
|
100
|
+
413: 'Payload Too Large';
|
|
101
|
+
414: 'URI Too Long';
|
|
102
|
+
415: 'Unsupported Media Type';
|
|
103
|
+
416: 'Range Not Satisfiable';
|
|
104
|
+
417: 'Expectation Failed';
|
|
105
|
+
418: "I'm a Teapot";
|
|
106
|
+
421: 'Misdirected Request';
|
|
107
|
+
422: 'Unprocessable Entity';
|
|
108
|
+
423: 'Locked';
|
|
109
|
+
424: 'Failed Dependency';
|
|
110
|
+
425: 'Too Early';
|
|
111
|
+
426: 'Upgrade Required';
|
|
112
|
+
428: 'Precondition Required';
|
|
113
|
+
429: 'Too Many Requests';
|
|
114
|
+
431: 'Request Header Fields Too Large';
|
|
115
|
+
451: 'Unavailable For Legal Reasons';
|
|
116
|
+
500: 'Internal Server Error';
|
|
117
|
+
501: 'Not Implemented';
|
|
118
|
+
502: 'Bad Gateway';
|
|
119
|
+
503: 'Service Unavailable';
|
|
120
|
+
504: 'Gateway Timeout';
|
|
121
|
+
505: 'HTTP Version Not Supported';
|
|
122
|
+
506: 'Variant Also Negotiates';
|
|
123
|
+
507: 'Insufficient Storage';
|
|
124
|
+
508: 'Loop Detected';
|
|
125
|
+
509: 'Bandwidth Limit Exceeded';
|
|
126
|
+
510: 'Not Extended';
|
|
127
|
+
511: 'Network Authentication Required';
|
|
128
|
+
};
|
|
129
|
+
export type TypedResponse<TJSON = unknown, THeaders extends Record<string, string> = Record<string, string>, TStatusCode extends StatusCode = StatusCode> = Omit<Response, 'json' | 'status' | 'ok'> & Omit<TypedBody<TJSON, any, THeaders>, 'formData'> & {
|
|
130
|
+
/**
|
|
131
|
+
* The status read-only property of the Response interface contains the HTTP status codes of the response.
|
|
132
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/status
|
|
133
|
+
*
|
|
134
|
+
* You can use `Response.ok` to check if the status is in the range 200-299.
|
|
135
|
+
*/
|
|
136
|
+
status: TStatusCode;
|
|
137
|
+
/**
|
|
138
|
+
* The statusText read-only property of the Response interface contains the status message corresponding to the HTTP status code in Response.status.
|
|
139
|
+
* For example, this would be OK for a status code 200, Continue for 100, Not Found for 404.
|
|
140
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
141
|
+
*/
|
|
142
|
+
statusText: TStatusCode extends keyof StatusTextMap ? StatusTextMap[TStatusCode] : string;
|
|
143
|
+
} & {
|
|
144
|
+
/**
|
|
145
|
+
* The ok read-only property of the Response interface contains a Boolean stating whether the response was successful (status in the range 200-299) or not.
|
|
146
|
+
*/
|
|
147
|
+
ok: TStatusCode extends OkStatusCode ? true : false;
|
|
148
|
+
};
|
|
149
|
+
export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
150
|
+
new <TStatusCode extends StatusCode = 200>(body: BodyInit | null | undefined, init: (TypedResponseInit<TStatusCode> & {
|
|
151
|
+
status: TStatusCode;
|
|
152
|
+
}) | undefined): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
153
|
+
new (body: BodyInit | null | undefined, init: ResponseInit | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
154
|
+
new (body?: BodyInit | null | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
155
|
+
/**
|
|
156
|
+
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
157
|
+
* and a `Content-Type` header which is set to `application/json`. The response status, status message, and additional headers can also be set.
|
|
158
|
+
* @param data The JSON data to be used as the response body.
|
|
159
|
+
* @param options An options object containing settings for the response, including the status code, status text, and headers. This is the same as the options parameter of the `Response()` constructor.
|
|
160
|
+
*
|
|
161
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
162
|
+
*/
|
|
163
|
+
json<TJSON, TStatusCode extends StatusCode>(data: TJSON, options: TypedResponseInit<TStatusCode>): TypedResponse<TJSON, Record<string, string>, TStatusCode>;
|
|
164
|
+
/**
|
|
165
|
+
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
166
|
+
* and a `Content-Type` header which is set to `application/json`.
|
|
167
|
+
* @param data The JSON data to be used as the response body.
|
|
168
|
+
*
|
|
169
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
170
|
+
*/
|
|
171
|
+
json<TJSON>(data: TJSON): TypedResponse<TJSON, Record<string, string>, 200>;
|
|
172
|
+
/**
|
|
173
|
+
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
174
|
+
* @param url The URL that the new response is to originate from.
|
|
175
|
+
* @param status An optional status code for the response (e.g., 302.)
|
|
176
|
+
*
|
|
177
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
178
|
+
*/
|
|
179
|
+
redirect<TStatusCode extends StatusCode>(url: string | URL, status: TStatusCode): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
180
|
+
/**
|
|
181
|
+
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
182
|
+
* @param url The URL that the new response is to originate from.
|
|
183
|
+
*
|
|
184
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
185
|
+
*/
|
|
186
|
+
redirect(url: string | URL): TypedResponse<any, Record<string, string>, 302>;
|
|
187
|
+
};
|
|
188
|
+
export type TypedResponseWithJSONStatusMap<TResponseJSONStatusMap extends StatusCodeMap<any>> = {
|
|
189
|
+
[TStatusCode in keyof TResponseJSONStatusMap]: TStatusCode extends StatusCode ? TypedResponse<TResponseJSONStatusMap[TStatusCode], Record<string, string>, TStatusCode> : never;
|
|
190
|
+
}[keyof TResponseJSONStatusMap];
|
|
191
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
192
|
+
export type TypedRequestInit<THeaders extends Record<string, string>, TMethod extends HTTPMethod, TFormData extends Record<string, FormDataEntryValue>> = Omit<RequestInit, 'method' | 'headers' | 'body'> & {
|
|
193
|
+
method: TMethod;
|
|
194
|
+
headers: TypedHeaders<THeaders>;
|
|
195
|
+
body?: Exclude<BodyInit, FormData> | TFormData;
|
|
196
|
+
};
|
|
197
|
+
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TPathParams extends Record<string, any> = Record<string, any>> = Omit<Request, 'json' | 'method' | 'headers' | 'formData'> & TypedBody<TJSON, TFormData, THeaders> & {
|
|
198
|
+
method: TMethod;
|
|
199
|
+
parsedUrl: TypedURL<TQueryParams>;
|
|
200
|
+
params: TPathParams;
|
|
201
|
+
query: TQueryParams;
|
|
202
|
+
};
|
|
203
|
+
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod, TQueryParams extends Record<string, string | string[]>, TFormData extends Record<string, FormDataEntryValue>>(input: string | TypedURL<TQueryParams>, init?: TypedRequestInit<THeaders, TMethod, TFormData>) => TypedRequest<any, TFormData, THeaders, TMethod, TQueryParams, any>;
|
|
204
|
+
export interface TypedURLSearchParams<TMap extends Record<string, string | string[]>> {
|
|
205
|
+
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
206
|
+
delete(name: keyof TMap): void;
|
|
207
|
+
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName];
|
|
208
|
+
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : [TMap[TName]];
|
|
209
|
+
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
210
|
+
sort(): void;
|
|
211
|
+
toString(): string;
|
|
212
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName], name: TName, parent: TypedURLSearchParams<TMap>) => void, thisArg?: any): void;
|
|
213
|
+
}
|
|
214
|
+
export type TypedURLSearchParamsCtor = new <TMap extends Record<string, string | string[]>>(init?: TMap) => TypedURLSearchParams<TMap>;
|
|
215
|
+
export type TypedURL<TQueryParams extends Record<string, string | string[]>> = Omit<URL, 'searchParams'> & {
|
|
216
|
+
searchParams: TypedURLSearchParams<TQueryParams>;
|
|
217
|
+
};
|
|
218
|
+
export type TypedURLCtor = new <TQueryParams extends Record<string, string | string[]>>(input: string, base?: string | TypedURL<any>) => TypedURL<TQueryParams>;
|
|
219
|
+
export interface TypedFormData<TMap extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>> {
|
|
220
|
+
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
221
|
+
delete(name: keyof TMap): void;
|
|
222
|
+
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName];
|
|
223
|
+
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : TMap[TName][];
|
|
224
|
+
has<TName extends string>(name: TName): TName extends keyof TMap ? (TMap[TName] extends Maybe ? boolean : true) : false;
|
|
225
|
+
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
226
|
+
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName], key: TName, parent: this) => void, thisArg?: any): void;
|
|
227
|
+
entries(): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
228
|
+
keys(): IterableIterator<keyof TMap>;
|
|
229
|
+
values(): IterableIterator<TMap[keyof TMap]>;
|
|
230
|
+
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
231
|
+
}
|
|
232
|
+
export {};
|