@zimic/fetch 1.3.0 → 1.4.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 +12 -62
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client/FetchClient.ts +1 -8
- package/src/client/errors/FetchResponseError.ts +2 -5
- package/src/client/types/requests.ts +9 -64
package/dist/index.d.ts
CHANGED
|
@@ -115,15 +115,12 @@ type FetchRequestInitWithBody<BodySchema extends HttpBody> = [BodySchema] extend
|
|
|
115
115
|
type FetchRequestInitPerPath<MethodSchema extends HttpMethodSchema> = FetchRequestInitWithHeaders<HttpRequestHeadersSchema<MethodSchema>> & FetchRequestInitWithSearchParams<HttpRequestSearchParamsSchema<MethodSchema>> & FetchRequestInitWithBody<FetchRequestBodySchema<Default<MethodSchema['request']>>>;
|
|
116
116
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
117
117
|
type FetchRequestInit<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, Redirect extends RequestRedirect = 'follow'> = Omit<RequestInit, 'method' | 'headers' | 'body'> & {
|
|
118
|
-
/** The HTTP method of the request. */
|
|
119
118
|
method: Method;
|
|
120
|
-
/** The base URL to prefix the path of the request. */
|
|
121
119
|
baseURL?: string;
|
|
122
|
-
/** The redirect mode of the request. */
|
|
123
120
|
redirect?: Redirect;
|
|
124
|
-
/** The duplex mode of the request. */
|
|
125
121
|
duplex?: 'half';
|
|
126
122
|
} & (Path extends Path ? FetchRequestInitPerPath<Default<Schema[Path][Method]>> : never);
|
|
123
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
127
124
|
declare namespace FetchRequestInit {
|
|
128
125
|
type DefaultHeadersSchema<Schema extends HttpSchema> = {
|
|
129
126
|
[Path in HttpSchemaPath.Literal<Schema>]: {
|
|
@@ -146,19 +143,15 @@ declare namespace FetchRequestInit {
|
|
|
146
143
|
[Method in keyof Schema[Path]]: FetchRequestBodySchema<Default<Schema[Path][Method]> extends HttpMethodSchema ? Default<Default<Schema[Path][Method]>['request']> : never>;
|
|
147
144
|
}[keyof Schema[Path]];
|
|
148
145
|
}[HttpSchemaPath.Literal<Schema>];
|
|
149
|
-
/**
|
|
146
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch#fetch-defaults `fetch` defaults API reference} */
|
|
150
147
|
export interface Defaults<Schema extends HttpSchema = HttpSchema> extends Omit<RequestInit, 'headers' | 'body'> {
|
|
151
148
|
baseURL: string;
|
|
152
|
-
/** The headers of the request. */
|
|
153
149
|
headers?: DefaultHeaders<Schema>;
|
|
154
|
-
/** The search parameters of the request. */
|
|
155
150
|
searchParams?: DefaultSearchParams<Schema>;
|
|
156
|
-
/** The body of the request. */
|
|
157
151
|
body?: DefaultBody<Schema>;
|
|
158
|
-
/** The duplex mode of the request. */
|
|
159
152
|
duplex?: 'half';
|
|
160
153
|
}
|
|
161
|
-
/**
|
|
154
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
162
155
|
export type Loose = Partial<Defaults>;
|
|
163
156
|
export { };
|
|
164
157
|
}
|
|
@@ -168,84 +161,42 @@ type FilterFetchResponseStatusCodeByRedirect<StatusCode extends HttpStatusCode,
|
|
|
168
161
|
type FetchResponseStatusCode<MethodSchema extends HttpMethodSchema, ErrorOnly extends boolean, Redirect extends RequestRedirect> = FilterFetchResponseStatusCodeByRedirect<FilterFetchResponseStatusCodeByError<AllFetchResponseStatusCode<MethodSchema>, ErrorOnly>, Redirect>;
|
|
169
162
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request `FetchRequest` API reference} */
|
|
170
163
|
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]>>>> {
|
|
171
|
-
/** The path of the request, excluding the base URL. */
|
|
172
164
|
path: AllowAnyStringInPathParams<Path>;
|
|
173
|
-
/** The HTTP method of the request. */
|
|
174
165
|
method: Method;
|
|
175
166
|
}
|
|
176
167
|
declare namespace FetchRequest {
|
|
177
168
|
/** A loosely typed version of a {@link FetchRequest `FetchRequest`}. */
|
|
178
169
|
interface Loose extends Request {
|
|
179
|
-
/** The path of the request, excluding the base URL. */
|
|
180
170
|
path: string;
|
|
181
|
-
/** The HTTP method of the request. */
|
|
182
171
|
method: HttpMethod;
|
|
183
|
-
/** Clones the request instance, returning a new instance with the same properties. */
|
|
184
172
|
clone: () => Loose;
|
|
185
173
|
}
|
|
186
174
|
}
|
|
187
|
-
/**
|
|
188
|
-
* A plain object representation of a {@link FetchRequest `FetchRequest`}, compatible with JSON.
|
|
189
|
-
*
|
|
190
|
-
* If the body is included in the object, it is automatically parsed based on the `content-type` header of the request.
|
|
191
|
-
*
|
|
192
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
193
|
-
*/
|
|
175
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`} */
|
|
194
176
|
type FetchRequestObject = Pick<FetchRequest.Loose, 'url' | 'path' | 'method' | 'cache' | 'destination' | 'credentials' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'> & {
|
|
195
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
|
|
196
177
|
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
197
|
-
/**
|
|
198
|
-
* The body of the request. It is automatically parsed based on the `content-type` header of the request.
|
|
199
|
-
*
|
|
200
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
201
|
-
*/
|
|
202
178
|
body?: HttpBody | null;
|
|
203
179
|
};
|
|
204
180
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
205
181
|
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> {
|
|
206
|
-
/** The request that originated the response. */
|
|
207
182
|
request: FetchRequest<Schema, Method, Path>;
|
|
208
|
-
|
|
209
|
-
* An error representing a response with a failure status code (4XX or 5XX). It can be thrown to handle the error
|
|
210
|
-
* upper in the call stack.
|
|
211
|
-
*
|
|
212
|
-
* If the response has a success status code (1XX, 2XX or 3XX), this property will be null.
|
|
213
|
-
*/
|
|
214
|
-
error: StatusCode extends HttpStatusCode.ClientError | HttpStatusCode.ServerError ? FetchResponseError<Schema, Method, Path> : null;
|
|
183
|
+
error: FetchResponseError<Schema, Method, Path>;
|
|
215
184
|
}
|
|
216
185
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
217
|
-
type FetchResponse<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
186
|
+
type FetchResponse<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
187
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
188
|
+
ErrorOnly extends boolean = false, Redirect extends RequestRedirect = 'follow', StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> = FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>> = StatusCode extends StatusCode ? FetchResponsePerStatusCode<Schema, Method, Path, StatusCode> : never;
|
|
218
189
|
declare namespace FetchResponse {
|
|
219
190
|
/** A loosely typed version of a {@link FetchResponse}. */
|
|
220
191
|
interface Loose extends Response {
|
|
221
|
-
/** The request that originated the response. */
|
|
222
192
|
request: FetchRequest.Loose;
|
|
223
|
-
|
|
224
|
-
* An error representing a response with a failure status code (4XX or 5XX). It can be thrown to handle the error
|
|
225
|
-
* upper in the call stack.
|
|
226
|
-
*
|
|
227
|
-
* If the response has a success status code (1XX, 2XX or 3XX), this property will be null.
|
|
228
|
-
*/
|
|
229
|
-
error: AnyFetchRequestError | null;
|
|
230
|
-
/** Clones the request instance, returning a new instance with the same properties. */
|
|
193
|
+
error: FetchResponseError<any, any, any>;
|
|
231
194
|
clone: () => Loose;
|
|
232
195
|
}
|
|
233
196
|
}
|
|
234
|
-
/**
|
|
235
|
-
* A plain object representation of a {@link FetchResponse `FetchResponse`}, compatible with JSON.
|
|
236
|
-
*
|
|
237
|
-
* If the body is included in the object, it is automatically parsed based on the `content-type` header of the response.
|
|
238
|
-
*
|
|
239
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
240
|
-
*/
|
|
197
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`} */
|
|
241
198
|
type FetchResponseObject = Pick<FetchResponse.Loose, 'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'> & {
|
|
242
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
|
|
243
199
|
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
244
|
-
/**
|
|
245
|
-
* The body of the response. It is automatically parsed based on the `content-type` header of the response.
|
|
246
|
-
*
|
|
247
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
248
|
-
*/
|
|
249
200
|
body?: HttpBody | null;
|
|
250
201
|
};
|
|
251
202
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch#fetchrequest `fetch.Request` API reference} */
|
|
@@ -293,8 +244,8 @@ interface FetchResponseErrorObject {
|
|
|
293
244
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */
|
|
294
245
|
declare class FetchResponseError<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>> extends Error {
|
|
295
246
|
request: FetchRequest<Schema, Method, Path>;
|
|
296
|
-
response: FetchResponse<Schema, Method, Path
|
|
297
|
-
constructor(request: FetchRequest<Schema, Method, Path>, response: FetchResponse<Schema, Method, Path
|
|
247
|
+
response: FetchResponse<Schema, Method, Path>;
|
|
248
|
+
constructor(request: FetchRequest<Schema, Method, Path>, response: FetchResponse<Schema, Method, Path>);
|
|
298
249
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */
|
|
299
250
|
toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;
|
|
300
251
|
toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;
|
|
@@ -304,7 +255,6 @@ declare class FetchResponseError<Schema extends HttpSchema, Method extends HttpS
|
|
|
304
255
|
private convertHeadersToObject;
|
|
305
256
|
private withIncludedBodyIfAvailable;
|
|
306
257
|
}
|
|
307
|
-
type AnyFetchRequestError = FetchResponseError<any, any, any>;
|
|
308
258
|
|
|
309
259
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
310
260
|
type FetchInput<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>> = Path | URL | FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;
|
package/dist/index.js
CHANGED
|
@@ -253,12 +253,7 @@ var FetchClient = class {
|
|
|
253
253
|
let responseError;
|
|
254
254
|
Object.defineProperty(fetchResponse, "error", {
|
|
255
255
|
get() {
|
|
256
|
-
|
|
257
|
-
responseError = fetchResponse.ok ? null : new FetchResponseError_default(
|
|
258
|
-
fetchRequest,
|
|
259
|
-
fetchResponse
|
|
260
|
-
);
|
|
261
|
-
}
|
|
256
|
+
responseError ??= new FetchResponseError_default(fetchRequest, fetchResponse);
|
|
262
257
|
return responseError;
|
|
263
258
|
},
|
|
264
259
|
enumerable: true,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/src/url/createRegexFromPath.ts","../../zimic-utils/src/url/excludeNonPathParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["HttpHeaders","parseHttpBody","Request","HttpSearchParams"],"mappings":";;;;;AAkDA,IAAM,kBAAA,GAAN,cAIU,KAAA,CAAM;AAAA,EACd,WAAA,CACS,SACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,OAAA,CAAQ,GAAG,CAAA,oBAAA,EAAuB,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,QAAA,CAAS,UAAU,CAAA,CAAE,CAAA;AAH/F,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGP,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AAAA,EAMA,QAAA,CAAS;AAAA,IACP,kBAAA,GAAqB,KAAA;AAAA,IACrB,mBAAA,GAAsB;AAAA,GACxB,GAAqC,EAAC,EAA8C;AAClF,IAAA,MAAM,aAAA,GAAgB;AAAA,MACpB,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,SAAS,IAAA,CAAK;AAAA,KAChB;AAEA,IAAA,IAAI,CAAC,kBAAA,IAAsB,CAAC,mBAAA,EAAqB;AAC/C,MAAA,OAAO;AAAA,QACL,GAAG,aAAA;AAAA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Q,IAAI,CAAA;AAAA,EAEhD;AACF,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACnQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,eAAA,GAAQ","file":"index.js","sourcesContent":["import {\n HttpHeaders,\n HttpHeadersSchema,\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n parseHttpBody,\n} from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest, FetchRequestObject, FetchResponse, FetchResponseObject } from '../types/requests';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\nexport interface FetchResponseErrorObjectOptions {\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeRequestBody?: boolean;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeResponseBody?: boolean;\n}\n\nexport namespace FetchResponseErrorObjectOptions {\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, including the body of\n * the request and/or response.\n */\n export type WithBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody: true } | { includeResponseBody: true });\n\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, excluding the body of\n * the request and/or response.\n */\n export type WithoutBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody?: false } | { includeResponseBody?: false });\n}\n\n/**\n * A plain object representation of a {@link FetchResponseError `FetchResponseError`}, compatible with JSON. It is useful\n * for serialization, debugging, and logging purposes.\n *\n * @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference}\n */\nexport interface FetchResponseErrorObject {\n name: string;\n message: string;\n request: FetchRequestObject;\n response: FetchResponseObject;\n}\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */\nclass FetchResponseError<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n> extends Error {\n constructor(\n public request: FetchRequest<Schema, Method, Path>,\n public response: FetchResponse<Schema, Method, Path, true, 'manual'>,\n ) {\n super(`${request.method} ${request.url} failed with status ${response.status}: ${response.statusText}`);\n this.name = 'FetchResponseError';\n }\n\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;\n toObject({\n includeRequestBody = false,\n includeResponseBody = false,\n }: FetchResponseErrorObjectOptions = {}): PossiblePromise<FetchResponseErrorObject> {\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n return {\n ...partialObject,\n request: this.requestToObject({ includeBody: false }),\n response: this.responseToObject({ includeBody: false }),\n };\n }\n\n return Promise.all([\n Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),\n Promise.resolve(this.responseToObject({ includeBody: includeResponseBody })),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private requestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private requestToObject(options: { includeBody: false }): FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject>;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject> {\n const request = this.request;\n\n const requestObject: FetchRequestObject = {\n url: request.url,\n path: request.path,\n method: request.method,\n headers: this.convertHeadersToObject(request),\n cache: request.cache,\n destination: request.destination,\n credentials: request.credentials,\n integrity: request.integrity,\n keepalive: request.keepalive,\n mode: request.mode,\n redirect: request.redirect,\n referrer: request.referrer,\n referrerPolicy: request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n return this.withIncludedBodyIfAvailable('request', requestObject);\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject>;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject> {\n const response = this.response;\n\n const responseObject: FetchResponseObject = {\n url: response.url,\n type: response.type,\n status: response.status,\n statusText: response.statusText,\n ok: response.ok,\n headers: this.convertHeadersToObject(response),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n return this.withIncludedBodyIfAvailable('response', responseObject);\n }\n\n private convertHeadersToObject(\n resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path, true, 'manual'>,\n ): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(resource.headers) as HttpHeadersSchema;\n }\n\n private withIncludedBodyIfAvailable(\n resourceType: 'request',\n resourceObject: FetchRequestObject,\n ): PossiblePromise<FetchRequestObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'response',\n resourceObject: FetchResponseObject,\n ): PossiblePromise<FetchResponseObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'request' | 'response',\n resourceObject: FetchRequestObject | FetchResponseObject,\n ): PossiblePromise<FetchRequestObject | FetchResponseObject> {\n const resource = this[resourceType] as Request | Response;\n\n if (resource.bodyUsed) {\n console.warn(\n '[@zimic/fetch]',\n `Could not include the ${resourceType} body because it is already used. ` +\n 'If you access the body before calling `error.toObject()`, consider reading it from a cloned ' +\n `${resourceType}.\\n\\nLearn more: https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject`,\n );\n return resourceObject;\n }\n\n return parseHttpBody(resource)\n .then((body) => {\n resourceObject.body = body;\n return resourceObject;\n })\n .catch((error: unknown) => {\n console.error('[@zimic/fetch]', `Failed to parse ${resourceType} body:`, error);\n return resourceObject;\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFetchRequestError = FetchResponseError<any, any, any>;\n\nexport default FetchResponseError;\n","export function createPathCharactersToEscapeRegex() {\n return /([.(){}+$])/g;\n}\n\nexport function preparePathForRegex(path: string) {\n // We encode the path using the URL API because, differently from encodeURI and encodeURIComponent, URL does not\n // re-encode already encoded characters. Since URL requires a full URL, we use a data scheme and strip it later.\n const pathURLPrefix = `data:${path.startsWith('/') ? '' : '/'}`;\n const pathAsURL = new URL(`${pathURLPrefix}${path}`);\n const encodedPath = pathAsURL.href.replace(pathURLPrefix, '');\n\n return encodedPath.replace(/^\\/+/g, '').replace(/\\/+$/g, '').replace(createPathCharactersToEscapeRegex(), '\\\\$1');\n}\n\n// Path params names must match the JavaScript identifier pattern.\n// See // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers.\nexport function createPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)(?!\\\\[*+?])/gu;\n}\n\nexport function createRepeatingPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\\\+/gu;\n}\n\nexport function createOptionalPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function createOptionalRepeatingPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createRegexFromPath(path: string) {\n const pathRegexContent = preparePathForRegex(path)\n .replace(\n createOptionalRepeatingPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\*${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?)?${suffixExpression})?`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>.+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>.+?)?`;\n }\n },\n )\n .replace(createRepeatingPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}\\\\+` : `(?<${identifier}>.+)`;\n })\n .replace(\n createOptionalPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\?${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?)?${suffixExpression})`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>[^\\\\/]+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>[^\\\\/]+?)?`;\n }\n },\n )\n .replace(createPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${pathRegexContent}/?$`);\n}\n\nexport default createRegexFromPath;\n","function excludeNonPathParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeNonPathParams;\n","function joinURL(...parts: (URL | string)[]) {\n return parts\n .map((part, index) => {\n const isFirstPart = index === 0;\n const isLastPart = index === parts.length - 1;\n\n let partAsString = part.toString();\n\n if (!isFirstPart) {\n partAsString = partAsString.replace(/^\\//, '');\n }\n if (!isLastPart) {\n partAsString = partAsString.replace(/\\/$/, '');\n }\n\n return partAsString;\n })\n .filter((part) => part.length > 0)\n .join('/');\n}\n\nexport default joinURL;\n","import {\n HttpSchemaPath,\n HttpSchemaMethod,\n HttpSearchParams,\n LiteralHttpSchemaPathFromNonLiteral,\n HttpSchema,\n HttpHeaders,\n} from '@zimic/http';\nimport { createRegexFromPath, excludeNonPathParams, joinURL } from '@zimic/utils/url';\n\nimport FetchResponseError from './errors/FetchResponseError';\nimport { FetchInput, FetchOptions, Fetch, FetchDefaults } from './types/public';\nimport { FetchRequestConstructor, FetchRequestInit, FetchRequest, FetchResponse } from './types/requests';\n\nclass FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loose' | 'Request' | keyof FetchDefaults> {\n fetch: Fetch<Schema>;\n\n constructor({ headers = {}, searchParams = {}, ...otherOptions }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n this.fetch.headers = headers;\n this.fetch.searchParams = searchParams;\n Object.assign(this.fetch, otherOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n this.fetch.Request = this.createRequestClass(this.fetch);\n }\n\n get defaults(): FetchDefaults<Schema> {\n return this.fetch;\n }\n\n private createFetchFunction() {\n const fetch = async <\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) => {\n const request = await this.createFetchRequest<Method, Path>(input, init);\n const requestClone = request.clone();\n\n const rawResponse = await globalThis.fetch(\n // Optimize type checking by narrowing the type of request\n requestClone as Request,\n );\n const response = await this.createFetchResponse<\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >(request, rawResponse);\n\n return response;\n };\n\n Object.setPrototypeOf(fetch, this);\n\n return fetch as Fetch<Schema>;\n }\n\n private async createFetchRequest<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n let request = input instanceof Request ? input : new this.fetch.Request(input, init);\n\n if (this.fetch.onRequest) {\n const requestAfterInterceptor = await this.fetch.onRequest(\n // Optimize type checking by narrowing the type of request\n request as FetchRequest.Loose,\n );\n\n if (requestAfterInterceptor !== request) {\n const isFetchRequest = requestAfterInterceptor instanceof this.fetch.Request;\n\n request = isFetchRequest\n ? (requestAfterInterceptor as Request as typeof request)\n : new this.fetch.Request(requestAfterInterceptor as FetchInput<Schema, Method, Path>, init);\n }\n }\n\n return request;\n }\n\n private async createFetchResponse<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, rawResponse: Response) {\n let response = this.defineFetchResponseProperties<Method, Path>(fetchRequest, rawResponse);\n\n if (this.fetch.onResponse) {\n const responseAfterInterceptor = await this.fetch.onResponse(\n // Optimize type checking by narrowing the type of response\n response as FetchResponse.Loose,\n );\n\n const isFetchResponse =\n responseAfterInterceptor instanceof Response &&\n 'request' in responseAfterInterceptor &&\n responseAfterInterceptor.request instanceof this.fetch.Request;\n\n response = isFetchResponse\n ? (responseAfterInterceptor as typeof response)\n : this.defineFetchResponseProperties<Method, Path>(fetchRequest, responseAfterInterceptor);\n }\n\n return response;\n }\n\n private defineFetchResponseProperties<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, response: Response) {\n const fetchResponse = response as FetchResponse<Schema, Method, Path>;\n\n Object.defineProperty(fetchResponse, 'request', {\n value: fetchRequest,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n let responseError: FetchResponse.Loose['error'] | undefined;\n\n Object.defineProperty(fetchResponse, 'error', {\n get() {\n if (responseError === undefined) {\n responseError = fetchResponse.ok\n ? null\n : new FetchResponseError(\n fetchRequest,\n fetchResponse as FetchResponse<Schema, Method, Path, true, 'manual'>,\n );\n }\n return responseError;\n },\n enumerable: true,\n configurable: false,\n });\n\n return fetchResponse;\n }\n\n private createRequestClass(fetch: Fetch<Schema>) {\n class Request<Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>\n extends globalThis.Request\n {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit.Loose) {\n let actualInput: URL | globalThis.Request;\n\n const actualInit = {\n baseURL: init?.baseURL ?? fetch.baseURL,\n method: init?.method ?? fetch.method,\n headers: new HttpHeaders(fetch.headers),\n searchParams: new HttpSearchParams(fetch.searchParams),\n body: (init?.body ?? fetch.body) as BodyInit | null,\n mode: init?.mode ?? fetch.mode,\n cache: init?.cache ?? fetch.cache,\n credentials: init?.credentials ?? fetch.credentials,\n integrity: init?.integrity ?? fetch.integrity,\n keepalive: init?.keepalive ?? fetch.keepalive,\n priority: init?.priority ?? fetch.priority,\n redirect: init?.redirect ?? fetch.redirect,\n referrer: init?.referrer ?? fetch.referrer,\n referrerPolicy: init?.referrerPolicy ?? fetch.referrerPolicy,\n signal: init?.signal ?? fetch.signal,\n window: init?.window === undefined ? fetch.window : init.window,\n duplex: init?.duplex ?? fetch.duplex,\n };\n\n if (init?.headers) {\n actualInit.headers.assign(new HttpHeaders(init.headers));\n }\n\n let url: URL;\n const baseURL = new URL(actualInit.baseURL);\n\n if (input instanceof globalThis.Request) {\n const request = input as globalThis.Request;\n\n actualInit.headers.assign(new HttpHeaders<FetchRequestInit.DefaultHeaders<Schema>>(request.headers));\n\n url = new URL(input.url);\n\n actualInput = request;\n } else {\n url = new URL(input instanceof URL ? input : joinURL(baseURL, input));\n\n actualInit.searchParams.assign(\n new HttpSearchParams<FetchRequestInit.DefaultSearchParams<Schema>>(url.searchParams),\n );\n\n if (init?.searchParams) {\n actualInit.searchParams.assign(new HttpSearchParams(init.searchParams));\n }\n\n url.search = actualInit.searchParams.toString();\n\n actualInput = url;\n }\n\n super(actualInput, actualInit);\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeNonPathParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): this {\n const rawClone = super.clone();\n return new Request(rawClone as FetchInput<Schema, Method, Path>) as this;\n }\n }\n\n return Request as FetchRequestConstructor<Schema>;\n }\n\n isRequest<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n request: unknown,\n method: Method,\n path: Path,\n ): request is FetchRequest<Schema, Method, Path> {\n return (\n request instanceof Request &&\n request.method === method &&\n 'path' in request &&\n typeof request.path === 'string' &&\n createRegexFromPath(path).test(request.path)\n );\n }\n\n isResponse<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n response: unknown,\n method: Method,\n path: Path,\n ): response is FetchResponse<Schema, Method, Path> {\n return (\n response instanceof Response &&\n 'request' in response &&\n this.isRequest(response.request, method, path) &&\n 'error' in response &&\n (response.error === null || response.error instanceof FetchResponseError)\n );\n }\n\n isResponseError<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n error: unknown,\n method: Method,\n path: Path,\n ): error is FetchResponseError<Schema, Method, Path> {\n return (\n error instanceof FetchResponseError &&\n this.isRequest(error.request, method, path) &&\n this.isResponse(error.response, method, path)\n );\n }\n}\n\nexport default FetchClient;\n","import { HttpSchema } from '@zimic/http';\n\nimport FetchClient from './FetchClient';\nimport { FetchOptions, Fetch } from './types/public';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/create-fetch `createFetch` API reference} */\nfunction createFetch<Schema extends HttpSchema>(options: FetchOptions<Schema>): Fetch<Schema> {\n const { fetch } = new FetchClient<Schema>(options);\n return fetch;\n}\n\nexport default createFetch;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/src/url/createRegexFromPath.ts","../../zimic-utils/src/url/excludeNonPathParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["HttpHeaders","parseHttpBody","Request","HttpSearchParams"],"mappings":";;;;;AAkDA,IAAM,kBAAA,GAAN,cAIU,KAAA,CAAM;AAAA,EACd,WAAA,CACS,SACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,OAAA,CAAQ,GAAG,CAAA,oBAAA,EAAuB,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,QAAA,CAAS,UAAU,CAAA,CAAE,CAAA;AAH/F,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGP,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AAAA,EAMA,QAAA,CAAS;AAAA,IACP,kBAAA,GAAqB,KAAA;AAAA,IACrB,mBAAA,GAAsB;AAAA,GACxB,GAAqC,EAAC,EAA8C;AAClF,IA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AAA,CAAU,MAAM,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA,IAC1C,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAAA,EAEhD;AACF,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;AC5Pf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,eAAA,GAAQ","file":"index.js","sourcesContent":["import {\n HttpHeaders,\n HttpHeadersSchema,\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n parseHttpBody,\n} from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest, FetchRequestObject, FetchResponse, FetchResponseObject } from '../types/requests';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\nexport interface FetchResponseErrorObjectOptions {\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeRequestBody?: boolean;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeResponseBody?: boolean;\n}\n\nexport namespace FetchResponseErrorObjectOptions {\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, including the body of\n * the request and/or response.\n */\n export type WithBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody: true } | { includeResponseBody: true });\n\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, excluding the body of\n * the request and/or response.\n */\n export type WithoutBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody?: false } | { includeResponseBody?: false });\n}\n\n/**\n * A plain object representation of a {@link FetchResponseError `FetchResponseError`}, compatible with JSON. It is useful\n * for serialization, debugging, and logging purposes.\n *\n * @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference}\n */\nexport interface FetchResponseErrorObject {\n name: string;\n message: string;\n request: FetchRequestObject;\n response: FetchResponseObject;\n}\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */\nclass FetchResponseError<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n> extends Error {\n constructor(\n public request: FetchRequest<Schema, Method, Path>,\n public response: FetchResponse<Schema, Method, Path>,\n ) {\n super(`${request.method} ${request.url} failed with status ${response.status}: ${response.statusText}`);\n this.name = 'FetchResponseError';\n }\n\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;\n toObject({\n includeRequestBody = false,\n includeResponseBody = false,\n }: FetchResponseErrorObjectOptions = {}): PossiblePromise<FetchResponseErrorObject> {\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n return {\n ...partialObject,\n request: this.requestToObject({ includeBody: false }),\n response: this.responseToObject({ includeBody: false }),\n };\n }\n\n return Promise.all([\n Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),\n Promise.resolve(this.responseToObject({ includeBody: includeResponseBody })),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private requestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private requestToObject(options: { includeBody: false }): FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject>;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject> {\n const request = this.request;\n\n const requestObject: FetchRequestObject = {\n url: request.url,\n path: request.path,\n method: request.method,\n headers: this.convertHeadersToObject(request),\n cache: request.cache,\n destination: request.destination,\n credentials: request.credentials,\n integrity: request.integrity,\n keepalive: request.keepalive,\n mode: request.mode,\n redirect: request.redirect,\n referrer: request.referrer,\n referrerPolicy: request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n return this.withIncludedBodyIfAvailable('request', requestObject);\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject>;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject> {\n const response = this.response;\n\n const responseObject: FetchResponseObject = {\n url: response.url,\n type: response.type,\n status: response.status,\n statusText: response.statusText,\n ok: response.ok,\n headers: this.convertHeadersToObject(response),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n return this.withIncludedBodyIfAvailable('response', responseObject);\n }\n\n private convertHeadersToObject(\n resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path>,\n ): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(resource.headers) as HttpHeadersSchema;\n }\n\n private withIncludedBodyIfAvailable(\n resourceType: 'request',\n resourceObject: FetchRequestObject,\n ): PossiblePromise<FetchRequestObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'response',\n resourceObject: FetchResponseObject,\n ): PossiblePromise<FetchResponseObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'request' | 'response',\n resourceObject: FetchRequestObject | FetchResponseObject,\n ): PossiblePromise<FetchRequestObject | FetchResponseObject> {\n const resource = this[resourceType] as Request | Response;\n\n if (resource.bodyUsed) {\n console.warn(\n '[@zimic/fetch]',\n `Could not include the ${resourceType} body because it is already used. ` +\n 'If you access the body before calling `error.toObject()`, consider reading it from a cloned ' +\n `${resourceType}.\\n\\nLearn more: https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject`,\n );\n return resourceObject;\n }\n\n return parseHttpBody(resource)\n .then((body) => {\n resourceObject.body = body;\n return resourceObject;\n })\n .catch((error: unknown) => {\n console.error('[@zimic/fetch]', `Failed to parse ${resourceType} body:`, error);\n return resourceObject;\n });\n }\n}\n\nexport default FetchResponseError;\n","export function createPathCharactersToEscapeRegex() {\n return /([.(){}+$])/g;\n}\n\nexport function preparePathForRegex(path: string) {\n // We encode the path using the URL API because, differently from encodeURI and encodeURIComponent, URL does not\n // re-encode already encoded characters. Since URL requires a full URL, we use a data scheme and strip it later.\n const pathURLPrefix = `data:${path.startsWith('/') ? '' : '/'}`;\n const pathAsURL = new URL(`${pathURLPrefix}${path}`);\n const encodedPath = pathAsURL.href.replace(pathURLPrefix, '');\n\n return encodedPath.replace(/^\\/+/g, '').replace(/\\/+$/g, '').replace(createPathCharactersToEscapeRegex(), '\\\\$1');\n}\n\n// Path params names must match the JavaScript identifier pattern.\n// See // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers.\nexport function createPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)(?!\\\\[*+?])/gu;\n}\n\nexport function createRepeatingPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\\\+/gu;\n}\n\nexport function createOptionalPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function createOptionalRepeatingPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createRegexFromPath(path: string) {\n const pathRegexContent = preparePathForRegex(path)\n .replace(\n createOptionalRepeatingPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\*${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?)?${suffixExpression})?`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>.+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>.+?)?`;\n }\n },\n )\n .replace(createRepeatingPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}\\\\+` : `(?<${identifier}>.+)`;\n })\n .replace(\n createOptionalPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\?${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?)?${suffixExpression})`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>[^\\\\/]+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>[^\\\\/]+?)?`;\n }\n },\n )\n .replace(createPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${pathRegexContent}/?$`);\n}\n\nexport default createRegexFromPath;\n","function excludeNonPathParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeNonPathParams;\n","function joinURL(...parts: (URL | string)[]) {\n return parts\n .map((part, index) => {\n const isFirstPart = index === 0;\n const isLastPart = index === parts.length - 1;\n\n let partAsString = part.toString();\n\n if (!isFirstPart) {\n partAsString = partAsString.replace(/^\\//, '');\n }\n if (!isLastPart) {\n partAsString = partAsString.replace(/\\/$/, '');\n }\n\n return partAsString;\n })\n .filter((part) => part.length > 0)\n .join('/');\n}\n\nexport default joinURL;\n","import {\n HttpSchemaPath,\n HttpSchemaMethod,\n HttpSearchParams,\n LiteralHttpSchemaPathFromNonLiteral,\n HttpSchema,\n HttpHeaders,\n} from '@zimic/http';\nimport { createRegexFromPath, excludeNonPathParams, joinURL } from '@zimic/utils/url';\n\nimport FetchResponseError from './errors/FetchResponseError';\nimport { FetchInput, FetchOptions, Fetch, FetchDefaults } from './types/public';\nimport { FetchRequestConstructor, FetchRequestInit, FetchRequest, FetchResponse } from './types/requests';\n\nclass FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loose' | 'Request' | keyof FetchDefaults> {\n fetch: Fetch<Schema>;\n\n constructor({ headers = {}, searchParams = {}, ...otherOptions }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n this.fetch.headers = headers;\n this.fetch.searchParams = searchParams;\n Object.assign(this.fetch, otherOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n this.fetch.Request = this.createRequestClass(this.fetch);\n }\n\n get defaults(): FetchDefaults<Schema> {\n return this.fetch;\n }\n\n private createFetchFunction() {\n const fetch = async <\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) => {\n const request = await this.createFetchRequest<Method, Path>(input, init);\n const requestClone = request.clone();\n\n const rawResponse = await globalThis.fetch(\n // Optimize type checking by narrowing the type of request\n requestClone as Request,\n );\n const response = await this.createFetchResponse<\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >(request, rawResponse);\n\n return response;\n };\n\n Object.setPrototypeOf(fetch, this);\n\n return fetch as Fetch<Schema>;\n }\n\n private async createFetchRequest<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n let request = input instanceof Request ? input : new this.fetch.Request(input, init);\n\n if (this.fetch.onRequest) {\n const requestAfterInterceptor = await this.fetch.onRequest(\n // Optimize type checking by narrowing the type of request\n request as FetchRequest.Loose,\n );\n\n if (requestAfterInterceptor !== request) {\n const isFetchRequest = requestAfterInterceptor instanceof this.fetch.Request;\n\n request = isFetchRequest\n ? (requestAfterInterceptor as Request as typeof request)\n : new this.fetch.Request(requestAfterInterceptor as FetchInput<Schema, Method, Path>, init);\n }\n }\n\n return request;\n }\n\n private async createFetchResponse<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, rawResponse: Response) {\n let response = this.defineFetchResponseProperties<Method, Path>(fetchRequest, rawResponse);\n\n if (this.fetch.onResponse) {\n const responseAfterInterceptor = await this.fetch.onResponse(\n // Optimize type checking by narrowing the type of response\n response as FetchResponse.Loose,\n );\n\n const isFetchResponse =\n responseAfterInterceptor instanceof Response &&\n 'request' in responseAfterInterceptor &&\n responseAfterInterceptor.request instanceof this.fetch.Request;\n\n response = isFetchResponse\n ? (responseAfterInterceptor as typeof response)\n : this.defineFetchResponseProperties<Method, Path>(fetchRequest, responseAfterInterceptor);\n }\n\n return response;\n }\n\n private defineFetchResponseProperties<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, response: Response) {\n const fetchResponse = response as FetchResponse<Schema, Method, Path>;\n\n Object.defineProperty(fetchResponse, 'request', {\n value: fetchRequest,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n let responseError: FetchResponse.Loose['error'] | undefined;\n\n Object.defineProperty(fetchResponse, 'error', {\n get() {\n responseError ??= new FetchResponseError(fetchRequest, fetchResponse);\n return responseError;\n },\n enumerable: true,\n configurable: false,\n });\n\n return fetchResponse;\n }\n\n private createRequestClass(fetch: Fetch<Schema>) {\n class Request<Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>\n extends globalThis.Request\n {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit.Loose) {\n let actualInput: URL | globalThis.Request;\n\n const actualInit = {\n baseURL: init?.baseURL ?? fetch.baseURL,\n method: init?.method ?? fetch.method,\n headers: new HttpHeaders(fetch.headers),\n searchParams: new HttpSearchParams(fetch.searchParams),\n body: (init?.body ?? fetch.body) as BodyInit | null,\n mode: init?.mode ?? fetch.mode,\n cache: init?.cache ?? fetch.cache,\n credentials: init?.credentials ?? fetch.credentials,\n integrity: init?.integrity ?? fetch.integrity,\n keepalive: init?.keepalive ?? fetch.keepalive,\n priority: init?.priority ?? fetch.priority,\n redirect: init?.redirect ?? fetch.redirect,\n referrer: init?.referrer ?? fetch.referrer,\n referrerPolicy: init?.referrerPolicy ?? fetch.referrerPolicy,\n signal: init?.signal ?? fetch.signal,\n window: init?.window === undefined ? fetch.window : init.window,\n duplex: init?.duplex ?? fetch.duplex,\n };\n\n if (init?.headers) {\n actualInit.headers.assign(new HttpHeaders(init.headers));\n }\n\n let url: URL;\n const baseURL = new URL(actualInit.baseURL);\n\n if (input instanceof globalThis.Request) {\n const request = input as globalThis.Request;\n\n actualInit.headers.assign(new HttpHeaders<FetchRequestInit.DefaultHeaders<Schema>>(request.headers));\n\n url = new URL(input.url);\n\n actualInput = request;\n } else {\n url = new URL(input instanceof URL ? input : joinURL(baseURL, input));\n\n actualInit.searchParams.assign(\n new HttpSearchParams<FetchRequestInit.DefaultSearchParams<Schema>>(url.searchParams),\n );\n\n if (init?.searchParams) {\n actualInit.searchParams.assign(new HttpSearchParams(init.searchParams));\n }\n\n url.search = actualInit.searchParams.toString();\n\n actualInput = url;\n }\n\n super(actualInput, actualInit);\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeNonPathParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): this {\n const rawClone = super.clone();\n return new Request(rawClone as FetchInput<Schema, Method, Path>) as this;\n }\n }\n\n return Request as FetchRequestConstructor<Schema>;\n }\n\n isRequest<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n request: unknown,\n method: Method,\n path: Path,\n ): request is FetchRequest<Schema, Method, Path> {\n return (\n request instanceof Request &&\n request.method === method &&\n 'path' in request &&\n typeof request.path === 'string' &&\n createRegexFromPath(path).test(request.path)\n );\n }\n\n isResponse<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n response: unknown,\n method: Method,\n path: Path,\n ): response is FetchResponse<Schema, Method, Path> {\n return (\n response instanceof Response &&\n 'request' in response &&\n this.isRequest(response.request, method, path) &&\n 'error' in response &&\n (response.error === null || response.error instanceof FetchResponseError)\n );\n }\n\n isResponseError<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n error: unknown,\n method: Method,\n path: Path,\n ): error is FetchResponseError<Schema, Method, Path> {\n return (\n error instanceof FetchResponseError &&\n this.isRequest(error.request, method, path) &&\n this.isResponse(error.response, method, path)\n );\n }\n}\n\nexport default FetchClient;\n","import { HttpSchema } from '@zimic/http';\n\nimport FetchClient from './FetchClient';\nimport { FetchOptions, Fetch } from './types/public';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/create-fetch `createFetch` API reference} */\nfunction createFetch<Schema extends HttpSchema>(options: FetchOptions<Schema>): Fetch<Schema> {\n const { fetch } = new FetchClient<Schema>(options);\n return fetch;\n}\n\nexport default createFetch;\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -251,12 +251,7 @@ var FetchClient = class {
|
|
|
251
251
|
let responseError;
|
|
252
252
|
Object.defineProperty(fetchResponse, "error", {
|
|
253
253
|
get() {
|
|
254
|
-
|
|
255
|
-
responseError = fetchResponse.ok ? null : new FetchResponseError_default(
|
|
256
|
-
fetchRequest,
|
|
257
|
-
fetchResponse
|
|
258
|
-
);
|
|
259
|
-
}
|
|
254
|
+
responseError ??= new FetchResponseError_default(fetchRequest, fetchResponse);
|
|
260
255
|
return responseError;
|
|
261
256
|
},
|
|
262
257
|
enumerable: true,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/src/url/createRegexFromPath.ts","../../zimic-utils/src/url/excludeNonPathParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["Request","HttpHeaders"],"mappings":";;;AAkDA,IAAM,kBAAA,GAAN,cAIU,KAAA,CAAM;AAAA,EACd,WAAA,CACS,SACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,OAAA,CAAQ,GAAG,CAAA,oBAAA,EAAuB,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A;AAAA,EAE/C;AAAA,EAEA,UAAA,CACE,QAAA,EACA,MAAA,EACA,IAAA,EACiD;AACjD,IAAA,OACE,oBAAoB,QAAA,IACpB,SAAA,IAAa,QAAA,IACb,IAAA,CAAK,UAAU,QAAA,CAAS,OAAA,EAAS,MAAA,EAAQ,IAAI,KAC7C,OAAA,IAAW,QAAA,KACV,SAAS,KAAA,KAAU,IAAA,IAAQ,SAAS,KAAA,YAAiB,0BAAA,CAAA;AAAA,EAE1D;AAAA,EAEA,eAAA,CACE,KAAA,EACA,MAAA,EACA,IAAA,EACmD;AACnD,IAAA,OACE,KAAA,YAAiB,0BAAA,IACjB,IAAA,CAAK,SAAA,CAAU,MAAM,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA,IAC1C,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAAA,EAEhD;AACF,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACnQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,eAAA,GAAQ","file":"index.mjs","sourcesContent":["import {\n HttpHeaders,\n HttpHeadersSchema,\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n parseHttpBody,\n} from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest, FetchRequestObject, FetchResponse, FetchResponseObject } from '../types/requests';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\nexport interface FetchResponseErrorObjectOptions {\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeRequestBody?: boolean;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeResponseBody?: boolean;\n}\n\nexport namespace FetchResponseErrorObjectOptions {\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, including the body of\n * the request and/or response.\n */\n export type WithBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody: true } | { includeResponseBody: true });\n\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, excluding the body of\n * the request and/or response.\n */\n export type WithoutBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody?: false } | { includeResponseBody?: false });\n}\n\n/**\n * A plain object representation of a {@link FetchResponseError `FetchResponseError`}, compatible with JSON. It is useful\n * for serialization, debugging, and logging purposes.\n *\n * @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference}\n */\nexport interface FetchResponseErrorObject {\n name: string;\n message: string;\n request: FetchRequestObject;\n response: FetchResponseObject;\n}\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */\nclass FetchResponseError<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n> extends Error {\n constructor(\n public request: FetchRequest<Schema, Method, Path>,\n public response: FetchResponse<Schema, Method, Path, true, 'manual'>,\n ) {\n super(`${request.method} ${request.url} failed with status ${response.status}: ${response.statusText}`);\n this.name = 'FetchResponseError';\n }\n\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;\n toObject({\n includeRequestBody = false,\n includeResponseBody = false,\n }: FetchResponseErrorObjectOptions = {}): PossiblePromise<FetchResponseErrorObject> {\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n return {\n ...partialObject,\n request: this.requestToObject({ includeBody: false }),\n response: this.responseToObject({ includeBody: false }),\n };\n }\n\n return Promise.all([\n Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),\n Promise.resolve(this.responseToObject({ includeBody: includeResponseBody })),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private requestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private requestToObject(options: { includeBody: false }): FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject>;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject> {\n const request = this.request;\n\n const requestObject: FetchRequestObject = {\n url: request.url,\n path: request.path,\n method: request.method,\n headers: this.convertHeadersToObject(request),\n cache: request.cache,\n destination: request.destination,\n credentials: request.credentials,\n integrity: request.integrity,\n keepalive: request.keepalive,\n mode: request.mode,\n redirect: request.redirect,\n referrer: request.referrer,\n referrerPolicy: request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n return this.withIncludedBodyIfAvailable('request', requestObject);\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject>;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject> {\n const response = this.response;\n\n const responseObject: FetchResponseObject = {\n url: response.url,\n type: response.type,\n status: response.status,\n statusText: response.statusText,\n ok: response.ok,\n headers: this.convertHeadersToObject(response),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n return this.withIncludedBodyIfAvailable('response', responseObject);\n }\n\n private convertHeadersToObject(\n resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path, true, 'manual'>,\n ): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(resource.headers) as HttpHeadersSchema;\n }\n\n private withIncludedBodyIfAvailable(\n resourceType: 'request',\n resourceObject: FetchRequestObject,\n ): PossiblePromise<FetchRequestObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'response',\n resourceObject: FetchResponseObject,\n ): PossiblePromise<FetchResponseObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'request' | 'response',\n resourceObject: FetchRequestObject | FetchResponseObject,\n ): PossiblePromise<FetchRequestObject | FetchResponseObject> {\n const resource = this[resourceType] as Request | Response;\n\n if (resource.bodyUsed) {\n console.warn(\n '[@zimic/fetch]',\n `Could not include the ${resourceType} body because it is already used. ` +\n 'If you access the body before calling `error.toObject()`, consider reading it from a cloned ' +\n `${resourceType}.\\n\\nLearn more: https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject`,\n );\n return resourceObject;\n }\n\n return parseHttpBody(resource)\n .then((body) => {\n resourceObject.body = body;\n return resourceObject;\n })\n .catch((error: unknown) => {\n console.error('[@zimic/fetch]', `Failed to parse ${resourceType} body:`, error);\n return resourceObject;\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFetchRequestError = FetchResponseError<any, any, any>;\n\nexport default FetchResponseError;\n","export function createPathCharactersToEscapeRegex() {\n return /([.(){}+$])/g;\n}\n\nexport function preparePathForRegex(path: string) {\n // We encode the path using the URL API because, differently from encodeURI and encodeURIComponent, URL does not\n // re-encode already encoded characters. Since URL requires a full URL, we use a data scheme and strip it later.\n const pathURLPrefix = `data:${path.startsWith('/') ? '' : '/'}`;\n const pathAsURL = new URL(`${pathURLPrefix}${path}`);\n const encodedPath = pathAsURL.href.replace(pathURLPrefix, '');\n\n return encodedPath.replace(/^\\/+/g, '').replace(/\\/+$/g, '').replace(createPathCharactersToEscapeRegex(), '\\\\$1');\n}\n\n// Path params names must match the JavaScript identifier pattern.\n// See // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers.\nexport function createPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)(?!\\\\[*+?])/gu;\n}\n\nexport function createRepeatingPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\\\+/gu;\n}\n\nexport function createOptionalPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function createOptionalRepeatingPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createRegexFromPath(path: string) {\n const pathRegexContent = preparePathForRegex(path)\n .replace(\n createOptionalRepeatingPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\*${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?)?${suffixExpression})?`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>.+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>.+?)?`;\n }\n },\n )\n .replace(createRepeatingPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}\\\\+` : `(?<${identifier}>.+)`;\n })\n .replace(\n createOptionalPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\?${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?)?${suffixExpression})`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>[^\\\\/]+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>[^\\\\/]+?)?`;\n }\n },\n )\n .replace(createPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${pathRegexContent}/?$`);\n}\n\nexport default createRegexFromPath;\n","function excludeNonPathParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeNonPathParams;\n","function joinURL(...parts: (URL | string)[]) {\n return parts\n .map((part, index) => {\n const isFirstPart = index === 0;\n const isLastPart = index === parts.length - 1;\n\n let partAsString = part.toString();\n\n if (!isFirstPart) {\n partAsString = partAsString.replace(/^\\//, '');\n }\n if (!isLastPart) {\n partAsString = partAsString.replace(/\\/$/, '');\n }\n\n return partAsString;\n })\n .filter((part) => part.length > 0)\n .join('/');\n}\n\nexport default joinURL;\n","import {\n HttpSchemaPath,\n HttpSchemaMethod,\n HttpSearchParams,\n LiteralHttpSchemaPathFromNonLiteral,\n HttpSchema,\n HttpHeaders,\n} from '@zimic/http';\nimport { createRegexFromPath, excludeNonPathParams, joinURL } from '@zimic/utils/url';\n\nimport FetchResponseError from './errors/FetchResponseError';\nimport { FetchInput, FetchOptions, Fetch, FetchDefaults } from './types/public';\nimport { FetchRequestConstructor, FetchRequestInit, FetchRequest, FetchResponse } from './types/requests';\n\nclass FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loose' | 'Request' | keyof FetchDefaults> {\n fetch: Fetch<Schema>;\n\n constructor({ headers = {}, searchParams = {}, ...otherOptions }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n this.fetch.headers = headers;\n this.fetch.searchParams = searchParams;\n Object.assign(this.fetch, otherOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n this.fetch.Request = this.createRequestClass(this.fetch);\n }\n\n get defaults(): FetchDefaults<Schema> {\n return this.fetch;\n }\n\n private createFetchFunction() {\n const fetch = async <\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) => {\n const request = await this.createFetchRequest<Method, Path>(input, init);\n const requestClone = request.clone();\n\n const rawResponse = await globalThis.fetch(\n // Optimize type checking by narrowing the type of request\n requestClone as Request,\n );\n const response = await this.createFetchResponse<\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >(request, rawResponse);\n\n return response;\n };\n\n Object.setPrototypeOf(fetch, this);\n\n return fetch as Fetch<Schema>;\n }\n\n private async createFetchRequest<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n let request = input instanceof Request ? input : new this.fetch.Request(input, init);\n\n if (this.fetch.onRequest) {\n const requestAfterInterceptor = await this.fetch.onRequest(\n // Optimize type checking by narrowing the type of request\n request as FetchRequest.Loose,\n );\n\n if (requestAfterInterceptor !== request) {\n const isFetchRequest = requestAfterInterceptor instanceof this.fetch.Request;\n\n request = isFetchRequest\n ? (requestAfterInterceptor as Request as typeof request)\n : new this.fetch.Request(requestAfterInterceptor as FetchInput<Schema, Method, Path>, init);\n }\n }\n\n return request;\n }\n\n private async createFetchResponse<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, rawResponse: Response) {\n let response = this.defineFetchResponseProperties<Method, Path>(fetchRequest, rawResponse);\n\n if (this.fetch.onResponse) {\n const responseAfterInterceptor = await this.fetch.onResponse(\n // Optimize type checking by narrowing the type of response\n response as FetchResponse.Loose,\n );\n\n const isFetchResponse =\n responseAfterInterceptor instanceof Response &&\n 'request' in responseAfterInterceptor &&\n responseAfterInterceptor.request instanceof this.fetch.Request;\n\n response = isFetchResponse\n ? (responseAfterInterceptor as typeof response)\n : this.defineFetchResponseProperties<Method, Path>(fetchRequest, responseAfterInterceptor);\n }\n\n return response;\n }\n\n private defineFetchResponseProperties<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, response: Response) {\n const fetchResponse = response as FetchResponse<Schema, Method, Path>;\n\n Object.defineProperty(fetchResponse, 'request', {\n value: fetchRequest,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n let responseError: FetchResponse.Loose['error'] | undefined;\n\n Object.defineProperty(fetchResponse, 'error', {\n get() {\n if (responseError === undefined) {\n responseError = fetchResponse.ok\n ? null\n : new FetchResponseError(\n fetchRequest,\n fetchResponse as FetchResponse<Schema, Method, Path, true, 'manual'>,\n );\n }\n return responseError;\n },\n enumerable: true,\n configurable: false,\n });\n\n return fetchResponse;\n }\n\n private createRequestClass(fetch: Fetch<Schema>) {\n class Request<Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>\n extends globalThis.Request\n {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit.Loose) {\n let actualInput: URL | globalThis.Request;\n\n const actualInit = {\n baseURL: init?.baseURL ?? fetch.baseURL,\n method: init?.method ?? fetch.method,\n headers: new HttpHeaders(fetch.headers),\n searchParams: new HttpSearchParams(fetch.searchParams),\n body: (init?.body ?? fetch.body) as BodyInit | null,\n mode: init?.mode ?? fetch.mode,\n cache: init?.cache ?? fetch.cache,\n credentials: init?.credentials ?? fetch.credentials,\n integrity: init?.integrity ?? fetch.integrity,\n keepalive: init?.keepalive ?? fetch.keepalive,\n priority: init?.priority ?? fetch.priority,\n redirect: init?.redirect ?? fetch.redirect,\n referrer: init?.referrer ?? fetch.referrer,\n referrerPolicy: init?.referrerPolicy ?? fetch.referrerPolicy,\n signal: init?.signal ?? fetch.signal,\n window: init?.window === undefined ? fetch.window : init.window,\n duplex: init?.duplex ?? fetch.duplex,\n };\n\n if (init?.headers) {\n actualInit.headers.assign(new HttpHeaders(init.headers));\n }\n\n let url: URL;\n const baseURL = new URL(actualInit.baseURL);\n\n if (input instanceof globalThis.Request) {\n const request = input as globalThis.Request;\n\n actualInit.headers.assign(new HttpHeaders<FetchRequestInit.DefaultHeaders<Schema>>(request.headers));\n\n url = new URL(input.url);\n\n actualInput = request;\n } else {\n url = new URL(input instanceof URL ? input : joinURL(baseURL, input));\n\n actualInit.searchParams.assign(\n new HttpSearchParams<FetchRequestInit.DefaultSearchParams<Schema>>(url.searchParams),\n );\n\n if (init?.searchParams) {\n actualInit.searchParams.assign(new HttpSearchParams(init.searchParams));\n }\n\n url.search = actualInit.searchParams.toString();\n\n actualInput = url;\n }\n\n super(actualInput, actualInit);\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeNonPathParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): this {\n const rawClone = super.clone();\n return new Request(rawClone as FetchInput<Schema, Method, Path>) as this;\n }\n }\n\n return Request as FetchRequestConstructor<Schema>;\n }\n\n isRequest<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n request: unknown,\n method: Method,\n path: Path,\n ): request is FetchRequest<Schema, Method, Path> {\n return (\n request instanceof Request &&\n request.method === method &&\n 'path' in request &&\n typeof request.path === 'string' &&\n createRegexFromPath(path).test(request.path)\n );\n }\n\n isResponse<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n response: unknown,\n method: Method,\n path: Path,\n ): response is FetchResponse<Schema, Method, Path> {\n return (\n response instanceof Response &&\n 'request' in response &&\n this.isRequest(response.request, method, path) &&\n 'error' in response &&\n (response.error === null || response.error instanceof FetchResponseError)\n );\n }\n\n isResponseError<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n error: unknown,\n method: Method,\n path: Path,\n ): error is FetchResponseError<Schema, Method, Path> {\n return (\n error instanceof FetchResponseError &&\n this.isRequest(error.request, method, path) &&\n this.isResponse(error.response, method, path)\n );\n }\n}\n\nexport default FetchClient;\n","import { HttpSchema } from '@zimic/http';\n\nimport FetchClient from './FetchClient';\nimport { FetchOptions, Fetch } from './types/public';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/create-fetch `createFetch` API reference} */\nfunction createFetch<Schema extends HttpSchema>(options: FetchOptions<Schema>): Fetch<Schema> {\n const { fetch } = new FetchClient<Schema>(options);\n return fetch;\n}\n\nexport default createFetch;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/src/url/createRegexFromPath.ts","../../zimic-utils/src/url/excludeNonPathParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["Request","HttpHeaders"],"mappings":";;;AAkDA,IAAM,kBAAA,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,IAAA,KAAS,YACxB,2BAAA,CAAoB,IAAI,CAAA,CAAE,IAAA,CAAK,QAAQ,IAAI,CAAA;AAAA,EAE/C;AAAA,EAEA,UAAA,CACE,QAAA,EACA,MAAA,EACA,IAAA,EACiD;AACjD,IAAA,OACE,oBAAoB,QAAA,IACpB,SAAA,IAAa,QAAA,IACb,IAAA,CAAK,UAAU,QAAA,CAAS,OAAA,EAAS,MAAA,EAAQ,IAAI,KAC7C,OAAA,IAAW,QAAA,KACV,SAAS,KAAA,KAAU,IAAA,IAAQ,SAAS,KAAA,YAAiB,0BAAA,CAAA;AAAA,EAE1D;AAAA,EAEA,eAAA,CACE,KAAA,EACA,MAAA,EACA,IAAA,EACmD;AACnD,IAAA,OACE,KAAA,YAAiB,0BAAA,IACjB,IAAA,CAAK,SAAA,CAAU,MAAM,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA,IAC1C,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAAA,EAEhD;AACF,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;AC5Pf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,eAAA,GAAQ","file":"index.mjs","sourcesContent":["import {\n HttpHeaders,\n HttpHeadersSchema,\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n parseHttpBody,\n} from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest, FetchRequestObject, FetchResponse, FetchResponseObject } from '../types/requests';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\nexport interface FetchResponseErrorObjectOptions {\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeRequestBody?: boolean;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n includeResponseBody?: boolean;\n}\n\nexport namespace FetchResponseErrorObjectOptions {\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, including the body of\n * the request and/or response.\n */\n export type WithBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody: true } | { includeResponseBody: true });\n\n /**\n * Options for converting a {@link FetchResponseError `FetchResponseError`} into a plain object, excluding the body of\n * the request and/or response.\n */\n export type WithoutBody = FetchResponseErrorObjectOptions &\n ({ includeRequestBody?: false } | { includeResponseBody?: false });\n}\n\n/**\n * A plain object representation of a {@link FetchResponseError `FetchResponseError`}, compatible with JSON. It is useful\n * for serialization, debugging, and logging purposes.\n *\n * @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference}\n */\nexport interface FetchResponseErrorObject {\n name: string;\n message: string;\n request: FetchRequestObject;\n response: FetchResponseObject;\n}\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error `FetchResponseError` API reference} */\nclass FetchResponseError<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n> extends Error {\n constructor(\n public request: FetchRequest<Schema, Method, Path>,\n public response: FetchResponse<Schema, Method, Path>,\n ) {\n super(`${request.method} ${request.url} failed with status ${response.status}: ${response.statusText}`);\n this.name = 'FetchResponseError';\n }\n\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `fetchResponseError.toObject()` API reference} */\n toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;\n toObject({\n includeRequestBody = false,\n includeResponseBody = false,\n }: FetchResponseErrorObjectOptions = {}): PossiblePromise<FetchResponseErrorObject> {\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n return {\n ...partialObject,\n request: this.requestToObject({ includeBody: false }),\n response: this.responseToObject({ includeBody: false }),\n };\n }\n\n return Promise.all([\n Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),\n Promise.resolve(this.responseToObject({ includeBody: includeResponseBody })),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private requestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private requestToObject(options: { includeBody: false }): FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject>;\n private requestToObject(options: { includeBody: boolean }): PossiblePromise<FetchRequestObject> {\n const request = this.request;\n\n const requestObject: FetchRequestObject = {\n url: request.url,\n path: request.path,\n method: request.method,\n headers: this.convertHeadersToObject(request),\n cache: request.cache,\n destination: request.destination,\n credentials: request.credentials,\n integrity: request.integrity,\n keepalive: request.keepalive,\n mode: request.mode,\n redirect: request.redirect,\n referrer: request.referrer,\n referrerPolicy: request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n return this.withIncludedBodyIfAvailable('request', requestObject);\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject>;\n private responseToObject(options: { includeBody: boolean }): PossiblePromise<FetchResponseObject> {\n const response = this.response;\n\n const responseObject: FetchResponseObject = {\n url: response.url,\n type: response.type,\n status: response.status,\n statusText: response.statusText,\n ok: response.ok,\n headers: this.convertHeadersToObject(response),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n return this.withIncludedBodyIfAvailable('response', responseObject);\n }\n\n private convertHeadersToObject(\n resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path>,\n ): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(resource.headers) as HttpHeadersSchema;\n }\n\n private withIncludedBodyIfAvailable(\n resourceType: 'request',\n resourceObject: FetchRequestObject,\n ): PossiblePromise<FetchRequestObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'response',\n resourceObject: FetchResponseObject,\n ): PossiblePromise<FetchResponseObject>;\n private withIncludedBodyIfAvailable(\n resourceType: 'request' | 'response',\n resourceObject: FetchRequestObject | FetchResponseObject,\n ): PossiblePromise<FetchRequestObject | FetchResponseObject> {\n const resource = this[resourceType] as Request | Response;\n\n if (resource.bodyUsed) {\n console.warn(\n '[@zimic/fetch]',\n `Could not include the ${resourceType} body because it is already used. ` +\n 'If you access the body before calling `error.toObject()`, consider reading it from a cloned ' +\n `${resourceType}.\\n\\nLearn more: https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject`,\n );\n return resourceObject;\n }\n\n return parseHttpBody(resource)\n .then((body) => {\n resourceObject.body = body;\n return resourceObject;\n })\n .catch((error: unknown) => {\n console.error('[@zimic/fetch]', `Failed to parse ${resourceType} body:`, error);\n return resourceObject;\n });\n }\n}\n\nexport default FetchResponseError;\n","export function createPathCharactersToEscapeRegex() {\n return /([.(){}+$])/g;\n}\n\nexport function preparePathForRegex(path: string) {\n // We encode the path using the URL API because, differently from encodeURI and encodeURIComponent, URL does not\n // re-encode already encoded characters. Since URL requires a full URL, we use a data scheme and strip it later.\n const pathURLPrefix = `data:${path.startsWith('/') ? '' : '/'}`;\n const pathAsURL = new URL(`${pathURLPrefix}${path}`);\n const encodedPath = pathAsURL.href.replace(pathURLPrefix, '');\n\n return encodedPath.replace(/^\\/+/g, '').replace(/\\/+$/g, '').replace(createPathCharactersToEscapeRegex(), '\\\\$1');\n}\n\n// Path params names must match the JavaScript identifier pattern.\n// See // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers.\nexport function createPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)(?!\\\\[*+?])/gu;\n}\n\nexport function createRepeatingPathParamRegex() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\\\+/gu;\n}\n\nexport function createOptionalPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function createOptionalRepeatingPathParamRegex() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createRegexFromPath(path: string) {\n const pathRegexContent = preparePathForRegex(path)\n .replace(\n createOptionalRepeatingPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\*${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?)?${suffixExpression})?`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>.+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>.+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>.+?)?`;\n }\n },\n )\n .replace(createRepeatingPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}\\\\+` : `(?<${identifier}>.+)`;\n })\n .replace(\n createOptionalPathParamRegex(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `${leadingSlash ?? ''}:${identifier}\\\\?${trailingSlash ?? ''}`;\n }\n\n const hasSegmentBeforePrefix = leadingSlash === '/';\n const prefixExpression = hasSegmentBeforePrefix ? '/?' : leadingSlash;\n\n const hasSegmentAfterSuffix = trailingSlash === '/';\n const suffixExpression = hasSegmentAfterSuffix ? '/?' : trailingSlash;\n\n if (prefixExpression && suffixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?)?${suffixExpression})`;\n } else if (prefixExpression) {\n return `(?:${prefixExpression}(?<${identifier}>[^\\\\/]+?))?`;\n } else if (suffixExpression) {\n return `(?:(?<${identifier}>[^\\\\/]+?)${suffixExpression})?`;\n } else {\n return `(?<${identifier}>[^\\\\/]+?)?`;\n }\n },\n )\n .replace(createPathParamRegex(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${pathRegexContent}/?$`);\n}\n\nexport default createRegexFromPath;\n","function excludeNonPathParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeNonPathParams;\n","function joinURL(...parts: (URL | string)[]) {\n return parts\n .map((part, index) => {\n const isFirstPart = index === 0;\n const isLastPart = index === parts.length - 1;\n\n let partAsString = part.toString();\n\n if (!isFirstPart) {\n partAsString = partAsString.replace(/^\\//, '');\n }\n if (!isLastPart) {\n partAsString = partAsString.replace(/\\/$/, '');\n }\n\n return partAsString;\n })\n .filter((part) => part.length > 0)\n .join('/');\n}\n\nexport default joinURL;\n","import {\n HttpSchemaPath,\n HttpSchemaMethod,\n HttpSearchParams,\n LiteralHttpSchemaPathFromNonLiteral,\n HttpSchema,\n HttpHeaders,\n} from '@zimic/http';\nimport { createRegexFromPath, excludeNonPathParams, joinURL } from '@zimic/utils/url';\n\nimport FetchResponseError from './errors/FetchResponseError';\nimport { FetchInput, FetchOptions, Fetch, FetchDefaults } from './types/public';\nimport { FetchRequestConstructor, FetchRequestInit, FetchRequest, FetchResponse } from './types/requests';\n\nclass FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loose' | 'Request' | keyof FetchDefaults> {\n fetch: Fetch<Schema>;\n\n constructor({ headers = {}, searchParams = {}, ...otherOptions }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n this.fetch.headers = headers;\n this.fetch.searchParams = searchParams;\n Object.assign(this.fetch, otherOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n this.fetch.Request = this.createRequestClass(this.fetch);\n }\n\n get defaults(): FetchDefaults<Schema> {\n return this.fetch;\n }\n\n private createFetchFunction() {\n const fetch = async <\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) => {\n const request = await this.createFetchRequest<Method, Path>(input, init);\n const requestClone = request.clone();\n\n const rawResponse = await globalThis.fetch(\n // Optimize type checking by narrowing the type of request\n requestClone as Request,\n );\n const response = await this.createFetchResponse<\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >(request, rawResponse);\n\n return response;\n };\n\n Object.setPrototypeOf(fetch, this);\n\n return fetch as Fetch<Schema>;\n }\n\n private async createFetchRequest<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n let request = input instanceof Request ? input : new this.fetch.Request(input, init);\n\n if (this.fetch.onRequest) {\n const requestAfterInterceptor = await this.fetch.onRequest(\n // Optimize type checking by narrowing the type of request\n request as FetchRequest.Loose,\n );\n\n if (requestAfterInterceptor !== request) {\n const isFetchRequest = requestAfterInterceptor instanceof this.fetch.Request;\n\n request = isFetchRequest\n ? (requestAfterInterceptor as Request as typeof request)\n : new this.fetch.Request(requestAfterInterceptor as FetchInput<Schema, Method, Path>, init);\n }\n }\n\n return request;\n }\n\n private async createFetchResponse<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, rawResponse: Response) {\n let response = this.defineFetchResponseProperties<Method, Path>(fetchRequest, rawResponse);\n\n if (this.fetch.onResponse) {\n const responseAfterInterceptor = await this.fetch.onResponse(\n // Optimize type checking by narrowing the type of response\n response as FetchResponse.Loose,\n );\n\n const isFetchResponse =\n responseAfterInterceptor instanceof Response &&\n 'request' in responseAfterInterceptor &&\n responseAfterInterceptor.request instanceof this.fetch.Request;\n\n response = isFetchResponse\n ? (responseAfterInterceptor as typeof response)\n : this.defineFetchResponseProperties<Method, Path>(fetchRequest, responseAfterInterceptor);\n }\n\n return response;\n }\n\n private defineFetchResponseProperties<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, response: Response) {\n const fetchResponse = response as FetchResponse<Schema, Method, Path>;\n\n Object.defineProperty(fetchResponse, 'request', {\n value: fetchRequest,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n let responseError: FetchResponse.Loose['error'] | undefined;\n\n Object.defineProperty(fetchResponse, 'error', {\n get() {\n responseError ??= new FetchResponseError(fetchRequest, fetchResponse);\n return responseError;\n },\n enumerable: true,\n configurable: false,\n });\n\n return fetchResponse;\n }\n\n private createRequestClass(fetch: Fetch<Schema>) {\n class Request<Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.NonLiteral<Schema, Method>>\n extends globalThis.Request\n {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(input: FetchInput<Schema, Method, Path>, init?: FetchRequestInit.Loose) {\n let actualInput: URL | globalThis.Request;\n\n const actualInit = {\n baseURL: init?.baseURL ?? fetch.baseURL,\n method: init?.method ?? fetch.method,\n headers: new HttpHeaders(fetch.headers),\n searchParams: new HttpSearchParams(fetch.searchParams),\n body: (init?.body ?? fetch.body) as BodyInit | null,\n mode: init?.mode ?? fetch.mode,\n cache: init?.cache ?? fetch.cache,\n credentials: init?.credentials ?? fetch.credentials,\n integrity: init?.integrity ?? fetch.integrity,\n keepalive: init?.keepalive ?? fetch.keepalive,\n priority: init?.priority ?? fetch.priority,\n redirect: init?.redirect ?? fetch.redirect,\n referrer: init?.referrer ?? fetch.referrer,\n referrerPolicy: init?.referrerPolicy ?? fetch.referrerPolicy,\n signal: init?.signal ?? fetch.signal,\n window: init?.window === undefined ? fetch.window : init.window,\n duplex: init?.duplex ?? fetch.duplex,\n };\n\n if (init?.headers) {\n actualInit.headers.assign(new HttpHeaders(init.headers));\n }\n\n let url: URL;\n const baseURL = new URL(actualInit.baseURL);\n\n if (input instanceof globalThis.Request) {\n const request = input as globalThis.Request;\n\n actualInit.headers.assign(new HttpHeaders<FetchRequestInit.DefaultHeaders<Schema>>(request.headers));\n\n url = new URL(input.url);\n\n actualInput = request;\n } else {\n url = new URL(input instanceof URL ? input : joinURL(baseURL, input));\n\n actualInit.searchParams.assign(\n new HttpSearchParams<FetchRequestInit.DefaultSearchParams<Schema>>(url.searchParams),\n );\n\n if (init?.searchParams) {\n actualInit.searchParams.assign(new HttpSearchParams(init.searchParams));\n }\n\n url.search = actualInit.searchParams.toString();\n\n actualInput = url;\n }\n\n super(actualInput, actualInit);\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeNonPathParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): this {\n const rawClone = super.clone();\n return new Request(rawClone as FetchInput<Schema, Method, Path>) as this;\n }\n }\n\n return Request as FetchRequestConstructor<Schema>;\n }\n\n isRequest<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n request: unknown,\n method: Method,\n path: Path,\n ): request is FetchRequest<Schema, Method, Path> {\n return (\n request instanceof Request &&\n request.method === method &&\n 'path' in request &&\n typeof request.path === 'string' &&\n createRegexFromPath(path).test(request.path)\n );\n }\n\n isResponse<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n response: unknown,\n method: Method,\n path: Path,\n ): response is FetchResponse<Schema, Method, Path> {\n return (\n response instanceof Response &&\n 'request' in response &&\n this.isRequest(response.request, method, path) &&\n 'error' in response &&\n (response.error === null || response.error instanceof FetchResponseError)\n );\n }\n\n isResponseError<Path extends HttpSchemaPath.Literal<Schema, Method>, Method extends HttpSchemaMethod<Schema>>(\n error: unknown,\n method: Method,\n path: Path,\n ): error is FetchResponseError<Schema, Method, Path> {\n return (\n error instanceof FetchResponseError &&\n this.isRequest(error.request, method, path) &&\n this.isResponse(error.response, method, path)\n );\n }\n}\n\nexport default FetchClient;\n","import { HttpSchema } from '@zimic/http';\n\nimport FetchClient from './FetchClient';\nimport { FetchOptions, Fetch } from './types/public';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/create-fetch `createFetch` API reference} */\nfunction createFetch<Schema extends HttpSchema>(options: FetchOptions<Schema>): Fetch<Schema> {\n const { fetch } = new FetchClient<Schema>(options);\n return fetch;\n}\n\nexport default createFetch;\n"]}
|
package/package.json
CHANGED
|
@@ -127,14 +127,7 @@ class FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loo
|
|
|
127
127
|
|
|
128
128
|
Object.defineProperty(fetchResponse, 'error', {
|
|
129
129
|
get() {
|
|
130
|
-
|
|
131
|
-
responseError = fetchResponse.ok
|
|
132
|
-
? null
|
|
133
|
-
: new FetchResponseError(
|
|
134
|
-
fetchRequest,
|
|
135
|
-
fetchResponse as FetchResponse<Schema, Method, Path, true, 'manual'>,
|
|
136
|
-
);
|
|
137
|
-
}
|
|
130
|
+
responseError ??= new FetchResponseError(fetchRequest, fetchResponse);
|
|
138
131
|
return responseError;
|
|
139
132
|
},
|
|
140
133
|
enumerable: true,
|
|
@@ -55,7 +55,7 @@ class FetchResponseError<
|
|
|
55
55
|
> extends Error {
|
|
56
56
|
constructor(
|
|
57
57
|
public request: FetchRequest<Schema, Method, Path>,
|
|
58
|
-
public response: FetchResponse<Schema, Method, Path
|
|
58
|
+
public response: FetchResponse<Schema, Method, Path>,
|
|
59
59
|
) {
|
|
60
60
|
super(`${request.method} ${request.url} failed with status ${response.status}: ${response.statusText}`);
|
|
61
61
|
this.name = 'FetchResponseError';
|
|
@@ -141,7 +141,7 @@ class FetchResponseError<
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
private convertHeadersToObject(
|
|
144
|
-
resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path
|
|
144
|
+
resource: FetchRequest<Schema, Method, Path> | FetchResponse<Schema, Method, Path>,
|
|
145
145
|
): HttpHeadersSchema {
|
|
146
146
|
return HttpHeaders.prototype.toObject.call(resource.headers) as HttpHeadersSchema;
|
|
147
147
|
}
|
|
@@ -182,7 +182,4 @@ class FetchResponseError<
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
186
|
-
export type AnyFetchRequestError = FetchResponseError<any, any, any>;
|
|
187
|
-
|
|
188
185
|
export default FetchResponseError;
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from '@zimic/http';
|
|
28
28
|
import { Default, IndexUnion, JSONStringified, UnionToIntersection } from '@zimic/utils/types';
|
|
29
29
|
|
|
30
|
-
import FetchResponseError
|
|
30
|
+
import FetchResponseError from '../errors/FetchResponseError';
|
|
31
31
|
import { FetchInput } from './public';
|
|
32
32
|
|
|
33
33
|
type FetchRequestInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = [HeadersSchema] extends [never]
|
|
@@ -75,16 +75,13 @@ export type FetchRequestInit<
|
|
|
75
75
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
76
76
|
Redirect extends RequestRedirect = 'follow',
|
|
77
77
|
> = Omit<RequestInit, 'method' | 'headers' | 'body'> & {
|
|
78
|
-
/** The HTTP method of the request. */
|
|
79
78
|
method: Method;
|
|
80
|
-
/** The base URL to prefix the path of the request. */
|
|
81
79
|
baseURL?: string;
|
|
82
|
-
/** The redirect mode of the request. */
|
|
83
80
|
redirect?: Redirect;
|
|
84
|
-
/** The duplex mode of the request. */
|
|
85
81
|
duplex?: 'half';
|
|
86
82
|
} & (Path extends Path ? FetchRequestInitPerPath<Default<Schema[Path][Method]>> : never);
|
|
87
83
|
|
|
84
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
88
85
|
export namespace FetchRequestInit {
|
|
89
86
|
type DefaultHeadersSchema<Schema extends HttpSchema> = {
|
|
90
87
|
[Path in HttpSchemaPath.Literal<Schema>]: {
|
|
@@ -122,20 +119,16 @@ export namespace FetchRequestInit {
|
|
|
122
119
|
}[keyof Schema[Path]];
|
|
123
120
|
}[HttpSchemaPath.Literal<Schema>];
|
|
124
121
|
|
|
125
|
-
/**
|
|
122
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch#fetch-defaults `fetch` defaults API reference} */
|
|
126
123
|
export interface Defaults<Schema extends HttpSchema = HttpSchema> extends Omit<RequestInit, 'headers' | 'body'> {
|
|
127
124
|
baseURL: string;
|
|
128
|
-
/** The headers of the request. */
|
|
129
125
|
headers?: DefaultHeaders<Schema>;
|
|
130
|
-
/** The search parameters of the request. */
|
|
131
126
|
searchParams?: DefaultSearchParams<Schema>;
|
|
132
|
-
/** The body of the request. */
|
|
133
127
|
body?: DefaultBody<Schema>;
|
|
134
|
-
/** The duplex mode of the request. */
|
|
135
128
|
duplex?: 'half';
|
|
136
129
|
}
|
|
137
130
|
|
|
138
|
-
/**
|
|
131
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch `fetch` API reference} */
|
|
139
132
|
export type Loose = Partial<Defaults>;
|
|
140
133
|
}
|
|
141
134
|
|
|
@@ -175,31 +168,20 @@ export interface FetchRequest<
|
|
|
175
168
|
HttpRequestBodySchema<Default<Schema[Path][Method]>>,
|
|
176
169
|
Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>
|
|
177
170
|
> {
|
|
178
|
-
/** The path of the request, excluding the base URL. */
|
|
179
171
|
path: AllowAnyStringInPathParams<Path>;
|
|
180
|
-
/** The HTTP method of the request. */
|
|
181
172
|
method: Method;
|
|
182
173
|
}
|
|
183
174
|
|
|
184
175
|
export namespace FetchRequest {
|
|
185
176
|
/** A loosely typed version of a {@link FetchRequest `FetchRequest`}. */
|
|
186
177
|
export interface Loose extends Request {
|
|
187
|
-
/** The path of the request, excluding the base URL. */
|
|
188
178
|
path: string;
|
|
189
|
-
/** The HTTP method of the request. */
|
|
190
179
|
method: HttpMethod;
|
|
191
|
-
/** Clones the request instance, returning a new instance with the same properties. */
|
|
192
180
|
clone: () => Loose;
|
|
193
181
|
}
|
|
194
182
|
}
|
|
195
183
|
|
|
196
|
-
/**
|
|
197
|
-
* A plain object representation of a {@link FetchRequest `FetchRequest`}, compatible with JSON.
|
|
198
|
-
*
|
|
199
|
-
* If the body is included in the object, it is automatically parsed based on the `content-type` header of the request.
|
|
200
|
-
*
|
|
201
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
202
|
-
*/
|
|
184
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`} */
|
|
203
185
|
export type FetchRequestObject = Pick<
|
|
204
186
|
FetchRequest.Loose,
|
|
205
187
|
| 'url'
|
|
@@ -215,13 +197,7 @@ export type FetchRequestObject = Pick<
|
|
|
215
197
|
| 'referrer'
|
|
216
198
|
| 'referrerPolicy'
|
|
217
199
|
> & {
|
|
218
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
|
|
219
200
|
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
220
|
-
/**
|
|
221
|
-
* The body of the request. It is automatically parsed based on the `content-type` header of the request.
|
|
222
|
-
*
|
|
223
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
224
|
-
*/
|
|
225
201
|
body?: HttpBody | null;
|
|
226
202
|
};
|
|
227
203
|
|
|
@@ -236,18 +212,8 @@ export interface FetchResponsePerStatusCode<
|
|
|
236
212
|
Default<HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>>,
|
|
237
213
|
StatusCode
|
|
238
214
|
> {
|
|
239
|
-
/** The request that originated the response. */
|
|
240
215
|
request: FetchRequest<Schema, Method, Path>;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* An error representing a response with a failure status code (4XX or 5XX). It can be thrown to handle the error
|
|
244
|
-
* upper in the call stack.
|
|
245
|
-
*
|
|
246
|
-
* If the response has a success status code (1XX, 2XX or 3XX), this property will be null.
|
|
247
|
-
*/
|
|
248
|
-
error: StatusCode extends HttpStatusCode.ClientError | HttpStatusCode.ServerError
|
|
249
|
-
? FetchResponseError<Schema, Method, Path>
|
|
250
|
-
: null;
|
|
216
|
+
error: FetchResponseError<Schema, Method, Path>;
|
|
251
217
|
}
|
|
252
218
|
|
|
253
219
|
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */
|
|
@@ -255,6 +221,7 @@ export type FetchResponse<
|
|
|
255
221
|
Schema extends HttpSchema,
|
|
256
222
|
Method extends HttpSchemaMethod<Schema>,
|
|
257
223
|
Path extends HttpSchemaPath.Literal<Schema, Method>,
|
|
224
|
+
/** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */
|
|
258
225
|
ErrorOnly extends boolean = false,
|
|
259
226
|
Redirect extends RequestRedirect = 'follow',
|
|
260
227
|
StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> =
|
|
@@ -264,40 +231,18 @@ export type FetchResponse<
|
|
|
264
231
|
export namespace FetchResponse {
|
|
265
232
|
/** A loosely typed version of a {@link FetchResponse}. */
|
|
266
233
|
export interface Loose extends Response {
|
|
267
|
-
/** The request that originated the response. */
|
|
268
234
|
request: FetchRequest.Loose;
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* An error representing a response with a failure status code (4XX or 5XX). It can be thrown to handle the error
|
|
272
|
-
* upper in the call stack.
|
|
273
|
-
*
|
|
274
|
-
* If the response has a success status code (1XX, 2XX or 3XX), this property will be null.
|
|
275
|
-
*/
|
|
276
|
-
error: AnyFetchRequestError | null;
|
|
277
|
-
|
|
278
|
-
/** Clones the request instance, returning a new instance with the same properties. */
|
|
235
|
+
error: FetchResponseError<any, any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
279
236
|
clone: () => Loose;
|
|
280
237
|
}
|
|
281
238
|
}
|
|
282
239
|
|
|
283
|
-
/**
|
|
284
|
-
* A plain object representation of a {@link FetchResponse `FetchResponse`}, compatible with JSON.
|
|
285
|
-
*
|
|
286
|
-
* If the body is included in the object, it is automatically parsed based on the `content-type` header of the response.
|
|
287
|
-
*
|
|
288
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
289
|
-
*/
|
|
240
|
+
/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`} */
|
|
290
241
|
export type FetchResponseObject = Pick<
|
|
291
242
|
FetchResponse.Loose,
|
|
292
243
|
'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'
|
|
293
244
|
> & {
|
|
294
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
|
|
295
245
|
headers: HttpHeadersSerialized<HttpHeadersSchema>;
|
|
296
|
-
/**
|
|
297
|
-
* The body of the response. It is automatically parsed based on the `content-type` header of the response.
|
|
298
|
-
*
|
|
299
|
-
* @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `error.toObject()`}
|
|
300
|
-
*/
|
|
301
246
|
body?: HttpBody | null;
|
|
302
247
|
};
|
|
303
248
|
|