@zimic/fetch 1.4.1 → 1.4.3-canary.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.
- package/dist/index.d.ts +105 -40
- package/dist/index.js +313 -199
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +313 -201
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/client/FetchClient.ts +89 -173
- package/src/client/request/FetchRequest.ts +242 -0
- package/src/client/request/types.ts +143 -0
- package/src/client/response/FetchResponse.ts +225 -0
- package/src/client/response/error/FetchResponseError.ts +47 -0
- package/src/client/response/error/types.ts +29 -0
- package/src/client/response/types.ts +111 -0
- package/src/client/types/public.ts +38 -3
- package/src/client/utils/objects.ts +71 -0
- package/src/index.ts +19 -10
- package/src/client/errors/FetchResponseError.ts +0 -185
- package/src/client/types/requests.ts +0 -256
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpMethodSchema, HttpHeadersSchema, HttpHeadersInit, HttpRequestHeadersSchema, HttpSearchParamsSchema, HttpSearchParamsInit, HttpRequestSearchParamsSchema, HttpBody, HttpRequestSchema, HttpSearchParams, HttpFormData, HttpRequest, HttpRequestBodySchema, AllowAnyStringInPathParams, HttpMethod, HttpStatusCode, HttpResponseSchemaStatusCode,
|
|
1
|
+
import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpMethodSchema, HttpHeadersSchema, HttpHeadersInit, HttpRequestHeadersSchema, HttpSearchParamsSchema, HttpSearchParamsInit, HttpRequestSearchParamsSchema, HttpBody, HttpRequestSchema, HttpSearchParams, HttpFormData, HttpHeadersSerialized, HttpRequest, HttpRequestBodySchema, AllowAnyStringInPathParams, HttpMethod, LiteralHttpSchemaPathFromNonLiteral, HttpStatusCode, HttpResponseSchemaStatusCode, HttpResponseSchema, HttpResponseHeadersSchema, HttpResponse, HttpResponseBodySchema } from '@zimic/http';
|
|
2
2
|
|
|
3
3
|
type JSON = {
|
|
4
4
|
[key: string]: JSON;
|
|
@@ -88,7 +88,9 @@ type UnionToIntersection<Union> = (Union extends unknown ? (union: Union) => voi
|
|
|
88
88
|
type IndexUnion<Union, Key> = Union extends Union ? (Key extends keyof Union ? Union[Key] : never) : never;
|
|
89
89
|
type RequiredByKey<Type, Key extends keyof Type> = Omit<Type, Key> & Required<Pick<Type, Key>>;
|
|
90
90
|
|
|
91
|
-
type FetchRequestInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = [HeadersSchema] extends [
|
|
91
|
+
type FetchRequestInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = [HeadersSchema] extends [
|
|
92
|
+
never
|
|
93
|
+
] ? {
|
|
92
94
|
headers?: undefined;
|
|
93
95
|
} : undefined extends HeadersSchema ? {
|
|
94
96
|
headers?: HttpHeadersInit<Default<HeadersSchema>>;
|
|
@@ -120,7 +122,6 @@ type FetchRequestInit<Schema extends HttpSchema, Method extends HttpSchemaMethod
|
|
|
120
122
|
redirect?: Redirect;
|
|
121
123
|
duplex?: 'half';
|
|
122
124
|
} & (Path extends Path ? FetchRequestInitPerPath<Default<Schema[Path][Method]>> : never);
|
|
123
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
124
125
|
declare namespace FetchRequestInit {
|
|
125
126
|
type DefaultHeadersSchema<Schema extends HttpSchema> = {
|
|
126
127
|
[Path in HttpSchemaPath.Literal<Schema>]: {
|
|
@@ -155,32 +156,103 @@ declare namespace FetchRequestInit {
|
|
|
155
156
|
export type Loose = Partial<Defaults>;
|
|
156
157
|
export { };
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
-
type
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request#requesttoobject `request.toObject()`} */
|
|
160
|
+
type FetchRequestObject = Pick<FetchRequest.Loose, 'url' | 'path' | 'method' | 'cache' | 'destination' | 'credentials' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'> & {
|
|
161
|
+
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
162
|
+
body?: HttpBody | null;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
interface FetchRequestClass {
|
|
166
|
+
new <Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(fetch: Fetch<Schema>, input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>): FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
167
|
+
prototype: Request;
|
|
168
|
+
[Symbol.hasInstance]: (instance: unknown) => instance is FetchRequest<any, any, any>;
|
|
169
|
+
}
|
|
162
170
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request `FetchRequest` API reference} */
|
|
163
171
|
interface FetchRequest<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>> extends HttpRequest<HttpRequestBodySchema<Default<Schema[Path][Method]>>, Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>> {
|
|
172
|
+
raw: Request;
|
|
164
173
|
path: AllowAnyStringInPathParams<Path>;
|
|
165
174
|
method: Method;
|
|
175
|
+
clone: () => FetchRequest<Schema, Method, Path>;
|
|
176
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request#requesttoobject `request.toObject()` API reference} */
|
|
177
|
+
toObject: ((options: {
|
|
178
|
+
includeBody: true;
|
|
179
|
+
}) => Promise<FetchRequestObject>) & ((options?: {
|
|
180
|
+
includeBody?: false;
|
|
181
|
+
}) => FetchRequestObject) & ((options?: {
|
|
182
|
+
includeBody?: boolean;
|
|
183
|
+
}) => PossiblePromise<FetchRequestObject>);
|
|
166
184
|
}
|
|
167
185
|
declare namespace FetchRequest {
|
|
168
186
|
/** A loosely typed version of a {@link FetchRequest `FetchRequest`}. */
|
|
169
187
|
interface Loose extends Request {
|
|
188
|
+
raw: Request;
|
|
170
189
|
path: string;
|
|
171
190
|
method: HttpMethod;
|
|
172
191
|
clone: () => Loose;
|
|
192
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request#requesttoobject `request.toObject()` API reference} */
|
|
193
|
+
toObject: ((options: {
|
|
194
|
+
includeBody: true;
|
|
195
|
+
}) => Promise<FetchRequestObject>) & ((options?: {
|
|
196
|
+
includeBody?: false;
|
|
197
|
+
}) => FetchRequestObject);
|
|
173
198
|
}
|
|
174
199
|
}
|
|
175
|
-
|
|
176
|
-
|
|
200
|
+
declare const FetchRequest: FetchRequestClass;
|
|
201
|
+
|
|
202
|
+
type AllFetchResponseStatusCode<MethodSchema extends HttpMethodSchema> = HttpResponseSchemaStatusCode<Default<MethodSchema['response']>>;
|
|
203
|
+
type FilterFetchResponseStatusCodeByError<StatusCode extends HttpStatusCode, ErrorOnly extends boolean> = ErrorOnly extends true ? Extract<StatusCode, HttpStatusCode.ClientError | HttpStatusCode.ServerError> : StatusCode;
|
|
204
|
+
type FilterFetchResponseStatusCodeByRedirect<StatusCode extends HttpStatusCode, Redirect extends RequestRedirect> = Redirect extends 'error' ? FilterFetchResponseStatusCodeByRedirect<StatusCode, 'follow'> : Redirect extends 'follow' ? Exclude<StatusCode, Exclude<HttpStatusCode.Redirection, 304>> : StatusCode;
|
|
205
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
206
|
+
type FetchResponseStatusCode<MethodSchema extends HttpMethodSchema, ErrorOnly extends boolean, Redirect extends RequestRedirect> = FilterFetchResponseStatusCodeByRedirect<FilterFetchResponseStatusCodeByError<AllFetchResponseStatusCode<MethodSchema>, ErrorOnly>, Redirect>;
|
|
207
|
+
type FetchResponseInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = FetchRequestInitWithHeaders<HeadersSchema>;
|
|
208
|
+
type FetchResponseBodySchema<ResponseSchema extends HttpResponseSchema> = FetchRequestBodySchema<ResponseSchema>;
|
|
209
|
+
type FetchResponseInitPerStatusCode<MethodSchema extends HttpMethodSchema, StatusCode extends AllFetchResponseStatusCode<MethodSchema>> = {
|
|
210
|
+
status: StatusCode;
|
|
211
|
+
} & FetchResponseInitWithHeaders<HttpResponseHeadersSchema<MethodSchema, StatusCode>>;
|
|
212
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
213
|
+
type FetchResponseInit<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>,
|
|
214
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
215
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>> = Omit<ResponseInit, 'headers' | 'status'> & (StatusCode extends StatusCode ? FetchResponseInitPerStatusCode<Default<Schema[Path][Method]>, StatusCode> : never);
|
|
216
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
217
|
+
interface FetchResponseConstructor {
|
|
218
|
+
new <Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
219
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
220
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>>(fetchRequest: FetchRequest<Schema, Method, Path>, response?: Response): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;
|
|
221
|
+
new <Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
222
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
223
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>>(fetchRequest: FetchRequest<Schema, Method, Path>, body?: FetchResponseBodySchema<Default<Default<Default<Schema[Path][Method]>['response']>[StatusCode]>>, init?: FetchResponseInit<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;
|
|
224
|
+
[Symbol.hasInstance]: (instance: unknown) => boolean;
|
|
225
|
+
}
|
|
226
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response#responsetoobject `response.toObject()`} */
|
|
227
|
+
type FetchResponseObject = Pick<FetchResponse.Loose, 'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'> & {
|
|
177
228
|
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
178
229
|
body?: HttpBody | null;
|
|
179
230
|
};
|
|
231
|
+
|
|
180
232
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
181
233
|
interface FetchResponsePerStatusCode<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>, StatusCode extends HttpStatusCode = HttpStatusCode> extends HttpResponse<HttpResponseBodySchema<Default<Schema[Path][Method]>, StatusCode>, Default<HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>>, StatusCode> {
|
|
234
|
+
raw: Response;
|
|
182
235
|
request: FetchRequest<Schema, Method, Path>;
|
|
183
236
|
error: FetchResponseError<Schema, Method, Path>;
|
|
237
|
+
clone: () => FetchResponsePerStatusCode<Schema, Method, Path, StatusCode>;
|
|
238
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response#responsetoobject `response.toObject()` API reference} */
|
|
239
|
+
toObject: ((options: {
|
|
240
|
+
includeBody: true;
|
|
241
|
+
}) => Promise<FetchResponseObject>) & ((options?: {
|
|
242
|
+
includeBody?: false;
|
|
243
|
+
}) => FetchResponseObject) & ((options?: {
|
|
244
|
+
includeBody?: boolean;
|
|
245
|
+
}) => PossiblePromise<FetchResponseObject>);
|
|
246
|
+
}
|
|
247
|
+
interface FetchResponseClass {
|
|
248
|
+
new <Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
249
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
250
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>>(fetchRequest: FetchRequest<Schema, Method, Path>, response?: Response): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;
|
|
251
|
+
new <Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
252
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
253
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>>(fetchRequest: FetchRequest<Schema, Method, Path>, body?: FetchResponseBodySchema<Default<Default<Default<Schema[Path][Method]>['response']>[StatusCode]>>, init?: FetchResponseInit<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;
|
|
254
|
+
prototype: Response;
|
|
255
|
+
[Symbol.hasInstance]: (instance: unknown) => instance is FetchResponse<any, any, any, any, any, any>;
|
|
184
256
|
}
|
|
185
257
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
186
258
|
type FetchResponse<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
@@ -189,75 +261,68 @@ ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow',
|
|
|
189
261
|
declare namespace FetchResponse {
|
|
190
262
|
/** A loosely typed version of a {@link FetchResponse}. */
|
|
191
263
|
interface Loose extends Response {
|
|
264
|
+
raw: Response;
|
|
192
265
|
request: FetchRequest.Loose;
|
|
193
266
|
error: FetchResponseError<any, any, any>;
|
|
194
267
|
clone: () => Loose;
|
|
268
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response#responsetoobject `response.toObject()` API reference} */
|
|
269
|
+
toObject: ((options: {
|
|
270
|
+
includeBody: true;
|
|
271
|
+
}) => Promise<FetchResponseObject>) & ((options?: {
|
|
272
|
+
includeBody?: false;
|
|
273
|
+
}) => FetchResponseObject);
|
|
195
274
|
}
|
|
196
275
|
}
|
|
197
|
-
|
|
198
|
-
type FetchResponseObject = Pick<FetchResponse.Loose, 'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'> & {
|
|
199
|
-
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
200
|
-
body?: HttpBody | null;
|
|
201
|
-
};
|
|
202
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch#fetchrequest `fetch.Request` API reference} */
|
|
203
|
-
type FetchRequestConstructor<Schema extends HttpSchema> = new <Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(input: FetchInput<Schema, Method, Path>, init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>) => FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
276
|
+
declare const FetchResponse: FetchResponseClass;
|
|
204
277
|
|
|
205
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `
|
|
278
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
206
279
|
interface FetchResponseErrorObjectOptions {
|
|
207
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `
|
|
280
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
208
281
|
includeRequestBody?: boolean;
|
|
209
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `
|
|
282
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
210
283
|
includeResponseBody?: boolean;
|
|
211
284
|
}
|
|
212
285
|
declare namespace FetchResponseErrorObjectOptions {
|
|
213
|
-
/**
|
|
214
|
-
* Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, including the body of
|
|
215
|
-
* the request and/or response.
|
|
216
|
-
*/
|
|
286
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
217
287
|
type WithBody = FetchResponseErrorObjectOptions & ({
|
|
218
288
|
includeRequestBody: true;
|
|
219
289
|
} | {
|
|
220
290
|
includeResponseBody: true;
|
|
221
291
|
});
|
|
222
|
-
/**
|
|
223
|
-
* Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, excluding the body of
|
|
224
|
-
* the request and/or response.
|
|
225
|
-
*/
|
|
292
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
226
293
|
type WithoutBody = FetchResponseErrorObjectOptions & ({
|
|
227
294
|
includeRequestBody?: false;
|
|
228
295
|
} | {
|
|
229
296
|
includeResponseBody?: false;
|
|
230
297
|
});
|
|
231
298
|
}
|
|
232
|
-
/**
|
|
233
|
-
* A plain object representation of a {@link FetchResponseError `FetchResponseError`}, compatible with JSON. It is useful
|
|
234
|
-
* for serialization, debugging, and logging purposes.
|
|
235
|
-
*
|
|
236
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference}
|
|
237
|
-
*/
|
|
299
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
238
300
|
interface FetchResponseErrorObject {
|
|
239
301
|
name: string;
|
|
240
302
|
message: string;
|
|
241
303
|
request: FetchRequestObject;
|
|
242
304
|
response: FetchResponseObject;
|
|
243
305
|
}
|
|
306
|
+
|
|
244
307
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */
|
|
245
308
|
declare class FetchResponseError<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>> extends Error {
|
|
246
309
|
request: FetchRequest<Schema, Method, Path>;
|
|
247
310
|
response: FetchResponse<Schema, Method, Path>;
|
|
248
311
|
constructor(request: FetchRequest<Schema, Method, Path>, response: FetchResponse<Schema, Method, Path>);
|
|
249
|
-
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `
|
|
312
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */
|
|
250
313
|
toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;
|
|
251
314
|
toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;
|
|
252
315
|
toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;
|
|
253
|
-
private requestToObject;
|
|
254
|
-
private responseToObject;
|
|
255
|
-
private convertHeadersToObject;
|
|
256
|
-
private withIncludedBodyIfAvailable;
|
|
257
316
|
}
|
|
258
317
|
|
|
318
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch#fetchrequest `fetch.Request` API reference} */
|
|
319
|
+
interface FetchRequestConstructor<Schema extends HttpSchema> {
|
|
320
|
+
new <Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>, Redirect extends RequestRedirect = 'follow'>(input: Path | URL, init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>): FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
321
|
+
new <Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>, Redirect extends RequestRedirect = 'follow'>(input: FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>, init?: Omit<FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>, 'baseURL' | 'searchParams'>): FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
322
|
+
new <Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>, Redirect extends RequestRedirect = 'follow'>(input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>): FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
323
|
+
}
|
|
259
324
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
260
|
-
type FetchInput<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath
|
|
325
|
+
type FetchInput<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = Path | URL | FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
|
261
326
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
262
327
|
interface Fetch<Schema extends HttpSchema> extends Pick<FetchOptions<Schema>, 'onRequest' | 'onResponse'>, FetchDefaults<Schema> {
|
|
263
328
|
<Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>, Redirect extends RequestRedirect = 'follow'>(input: Path | URL, init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>): Promise<FetchResponse<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, false, Redirect>>;
|
|
@@ -327,4 +392,4 @@ type InferFetchSchema<FetchInstance> = FetchInstance extends Fetch<infer Schema>
|
|
|
327
392
|
/** @see {@link https://zimic.dev/docs/fetch/api/create-fetch `createFetch` API reference} */
|
|
328
393
|
declare function createFetch<Schema extends HttpSchema>(options: FetchOptions<Schema>): Fetch<Schema>;
|
|
329
394
|
|
|
330
|
-
export { Fetch, type FetchDefaults, type FetchInput, type FetchOptions, FetchRequest, type FetchRequestConstructor, FetchRequestInit, type FetchRequestObject, FetchResponse, FetchResponseError, type FetchResponseErrorObject, FetchResponseErrorObjectOptions, type FetchResponseObject, type FetchResponsePerStatusCode, type InferFetchSchema, type JSONStringified, createFetch };
|
|
395
|
+
export { Fetch, type FetchDefaults, type FetchInput, type FetchOptions, FetchRequest, type FetchRequestConstructor, FetchRequestInit, type FetchRequestObject, FetchResponse, type FetchResponseConstructor, FetchResponseError, type FetchResponseErrorObject, FetchResponseErrorObjectOptions, type FetchResponseInit, type FetchResponseObject, type FetchResponsePerStatusCode, type FetchResponseStatusCode, type InferFetchSchema, type JSONStringified, createFetch };
|