UNPKG

@zimic/fetch

Version:

Next-gen TypeScript-first Fetch client

1 lines 52.1 kB
{"version":3,"sources":["../../zimic-utils/src/url/createRegexFromPath.ts","../../zimic-utils/src/url/excludeNonPathParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/utils/objects.ts","../src/client/request/FetchRequest.ts","../src/client/response/error/FetchResponseError.ts","../src/client/response/FetchResponse.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["FetchRequest","request","FetchResponse","HttpHeaders","Request"],"mappings":";;;;;AAAO,SAAS,iCAAA,GAAoC;AAClD,EAAA,OAAO,cAAA;AACT;AAEO,SAAS,oBAAoB,IAAA,EAAc;AAGhD,EAAA,MAAM,gBAAgB,CAAA,KAAA,EAAQ,IAAA,CAAK,WAAW,GAAG,CAAA,GAAI,KAAK,GAAG,CAAA,CAAA;AAC7D,EAAA,MAAM,YAAY,IAAI,GAAA,CAAI,GAAG,aAAa,CAAA,EAAG,IAAI,CAAA,CAAE,CAAA;AACnD,EAAA,MAAM,WAAA,GAAc,SAAA,CAAU,IAAA,CAAK,OAAA,CAAQ,eAAe,EAAE,CAAA;AAE5D,EAAA,OAAO,WAAA,CAAY,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA,CAAE,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA,CAAE,OAAA,CAAQ,iCAAA,EAAA,EAAqC,MAAM,CAAA;AAClH;AAIO,SAAS,oBAAA,GAAuB;AACrC,EAAA,OAAO,gFAAA;AACT;AAEO,SAAS,6BAAA,GAAgC;AAC9C,EAAA,OAAO,yEAAA;AACT;AAEO,SAAS,4BAAA,GAA+B;AAC7C,EAAA,OAAO,gHAAA;AACT;AAEO,SAAS,qCAAA,GAAwC;AACtD,EAAA,OAAO,gHAAA;AACT;AAEA,SAAS,oBAAoB,IAAA,EAAc;AACzC,EAAA,MAAM,gBAAA,GAAmB,mBAAA,CAAoB,IAAI,CAAA,CAC9C,OAAA;IACC,qCAAA,EAAA;AACA,IAAA,CACE,M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AAA,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;;;ACxKf,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":["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 { parseHttpBody } from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequestObject } from '../request/types';\nimport { FetchResponseObject } from '../response/types';\n\nconst BODY_METHOD = ['json', 'formData', 'text', 'arrayBuffer', 'blob', 'bytes'] satisfies (keyof Body)[];\ntype BodyMethod = (typeof BODY_METHOD)[number];\n\nexport function isBodyMethod(property: string | symbol, value: unknown): value is Body[BodyMethod] {\n return BODY_METHOD.includes(property as BodyMethod) && typeof value === 'function';\n}\n\nexport function getOrSetBoundBodyMethod(\n resource: Request | Response,\n property: string | symbol,\n value: Body[BodyMethod],\n) {\n // We cache the bound function on the proxy instance to avoid re-binding it on every access.\n const isValueAlreadyBound = Object.prototype.hasOwnProperty.call(resource, property);\n\n if (isValueAlreadyBound) {\n return value;\n }\n\n const boundValue = value.bind(resource) as unknown;\n\n Object.defineProperty(resource, property, {\n value: boundValue,\n configurable: true,\n enumerable: false,\n writable: true,\n });\n\n return boundValue;\n}\n\nexport function withIncludedBodyIfAvailable(\n resource: Request,\n resourceObject: FetchRequestObject,\n): PossiblePromise<FetchRequestObject>;\nexport function withIncludedBodyIfAvailable(\n resource: Response,\n resourceObject: FetchResponseObject,\n): PossiblePromise<FetchResponseObject>;\nexport function withIncludedBodyIfAvailable(\n resource: Request | Response,\n resourceObject: FetchRequestObject | FetchResponseObject,\n): PossiblePromise<FetchRequestObject | FetchResponseObject> {\n const resourceType = resource instanceof Request ? '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 `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.clone())\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","import {\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n HttpRequest,\n HttpRequestBodySchema,\n HttpRequestHeadersSchema,\n HttpHeaders,\n HttpSearchParams,\n HttpMethod,\n AllowAnyStringInPathParams,\n LiteralHttpSchemaPathFromNonLiteral,\n HttpHeadersInit,\n HttpSearchParamsInit,\n HttpHeadersSchema,\n} from '@zimic/http';\nimport { Default, PossiblePromise } from '@zimic/utils/types';\nimport { excludeNonPathParams, joinURL } from '@zimic/utils/url';\n\nimport { Fetch, FetchInput } from '../types/public';\nimport { getOrSetBoundBodyMethod, isBodyMethod, withIncludedBodyIfAvailable } from '../utils/objects';\nimport { FetchRequestBodySchema, FetchRequestInit, FetchRequestObject, FetchRequestObjectOptions } from './types';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-request `FetchRequest` API reference} */\nexport interface FetchRequest<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n> extends HttpRequest<\n HttpRequestBodySchema<Default<Schema[Path][Method]>>,\n Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>\n> {\n raw: Request;\n path: AllowAnyStringInPathParams<Path>;\n method: Method;\n clone: () => FetchRequest<Schema, Method, Path>;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-request#requesttoobject `request.toObject()` API reference} */\n toObject: ((options: FetchRequestObjectOptions.WithBody) => Promise<FetchRequestObject>) &\n ((options?: FetchRequestObjectOptions.WithoutBody) => FetchRequestObject) &\n ((options?: FetchRequestObjectOptions) => PossiblePromise<FetchRequestObject>);\n}\n\nexport namespace FetchRequest {\n /** A loosely typed version of a {@link FetchRequest `FetchRequest`}. */\n export interface Loose extends Request {\n raw: Request;\n path: string;\n method: HttpMethod;\n clone: () => Loose;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-request#requesttoobject `request.toObject()` API reference} */\n toObject: ((options: FetchRequestObjectOptions.WithBody) => Promise<FetchRequestObject>) &\n ((options?: FetchRequestObjectOptions.WithoutBody) => FetchRequestObject) &\n ((options?: FetchRequestObjectOptions) => PossiblePromise<FetchRequestObject>);\n }\n}\n\ninterface FetchRequestClass {\n new <\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n fetch: Fetch<Schema>,\n input: FetchInput<Schema, Method, Path>,\n init?: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ): FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;\n\n prototype: Request;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [Symbol.hasInstance]: (instance: unknown) => instance is FetchRequest<any, any, any>;\n}\n\nconst FETCH_REQUEST_BRAND = Symbol.for('FetchRequest');\n\nconst FETCH_REQUEST_EXTRA_PROPERTIES = [FETCH_REQUEST_BRAND, 'raw', 'path', 'toObject'] as const;\ntype FetchRequestExtraProperty = (typeof FETCH_REQUEST_EXTRA_PROPERTIES)[number];\n\nfunction createFetchRequestClass() {\n const FetchRequestClass = function FetchRequest<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n >(\n fetch: Fetch<Schema>,\n input: FetchInput<Schema, Method, Path>,\n init?: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> & {\n headers?: HttpHeadersInit<Default<Schema[Path][Method]>>;\n searchParams?: HttpSearchParamsInit<Default<Schema[Path][Method]>>;\n body?: FetchRequestBodySchema<Default<Default<Schema[Path][Method]>['request']>>;\n },\n ) {\n let actualInput: URL | 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 !== undefined) {\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 Request) {\n const request = input as Request;\n\n actualInit.headers.assign(new HttpHeaders<FetchRequestInit.DefaultHeaders<Schema>>(request.headers));\n\n url = new URL(input.url);\n\n actualInput = request instanceof FetchRequestClass ? request.raw : 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 !== undefined) {\n actualInit.searchParams.assign(new HttpSearchParams(init.searchParams));\n }\n\n url.search = actualInit.searchParams.toString();\n\n actualInput = url;\n }\n\n const request = new Request(actualInput, actualInit);\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n const path = excludeNonPathParams(url).toString().replace(baseURLWithoutTrailingSlash, '');\n\n function clone() {\n return new FetchRequestClass(fetch, request.clone() as FetchInput<Schema, Method, Path>);\n }\n\n function toObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n function toObject(options?: { includeBody?: false }): FetchRequestObject;\n function toObject(options?: { includeBody?: boolean }): PossiblePromise<FetchRequestObject>;\n function toObject(options?: { includeBody?: boolean }): PossiblePromise<FetchRequestObject> {\n const requestObject: FetchRequestObject = {\n url: request.url,\n path,\n method: request.method as HttpMethod,\n headers: HttpHeaders.prototype.toObject.call(request.headers) as HttpHeadersSchema,\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 withIncludedBodyIfAvailable(request, requestObject);\n }\n\n type FetchRequestInstance = FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;\n\n const fetchRequest = new Proxy(request, {\n get(target, property) {\n if (property === FETCH_REQUEST_BRAND) {\n return true;\n }\n\n if (property === ('raw' satisfies keyof FetchRequestInstance)) {\n return request satisfies FetchRequestInstance['raw'];\n }\n\n if (property === ('path' satisfies keyof FetchRequestInstance)) {\n return path as AllowAnyStringInPathParams<\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n > satisfies FetchRequestInstance['path'];\n }\n\n if (property === ('clone' satisfies keyof FetchRequestInstance)) {\n return clone satisfies FetchRequestInstance['clone'];\n }\n\n if (property === ('toObject' satisfies keyof FetchRequestInstance)) {\n return toObject satisfies FetchRequestInstance['toObject'];\n }\n\n // Fallback other properties to the original `Request` instance.\n const value = Reflect.get(target, property, target) as unknown;\n\n if (isBodyMethod(property, value)) {\n return getOrSetBoundBodyMethod(request, property, value);\n }\n\n return value;\n },\n\n has(target, property) {\n return (\n FETCH_REQUEST_EXTRA_PROPERTIES.includes(property as FetchRequestExtraProperty) ||\n Reflect.has(target, property)\n );\n },\n }) as unknown as FetchRequest<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>;\n\n return fetchRequest;\n } as unknown as FetchRequestClass;\n\n Object.defineProperty(FetchRequestClass, Symbol.hasInstance, {\n value(instance: unknown): boolean {\n return instance instanceof Request && FETCH_REQUEST_BRAND in instance && instance[FETCH_REQUEST_BRAND] === true;\n },\n writable: false,\n enumerable: false,\n configurable: false,\n });\n\n Object.setPrototypeOf(FetchRequestClass.prototype, Request.prototype);\n\n return FetchRequestClass;\n}\n\nexport const FetchRequest = createFetchRequestClass();\n","import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http';\nimport { PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest } from '../../request/FetchRequest';\nimport { FetchResponse } from '../FetchResponse';\nimport { FetchResponseErrorObjectOptions, FetchResponseErrorObject } from './types';\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}.`);\n this.name = 'FetchResponseError';\n }\n\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response-error#errortoobject `response.error.toObject()` API reference} */\n toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject>;\n toObject(options?: FetchResponseErrorObjectOptions): PossiblePromise<FetchResponseErrorObject> {\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!options?.includeRequestBody && !options?.includeResponseBody) {\n return {\n ...partialObject,\n request: this.request.toObject({ includeBody: false }),\n response: this.response.toObject({ includeBody: false }),\n };\n }\n\n return Promise.all([\n Promise.resolve(this.request.toObject({ includeBody: options.includeRequestBody })),\n Promise.resolve(this.response.toObject({ includeBody: options.includeResponseBody })),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n}\n\nexport default FetchResponseError;\n","import {\n HttpHeaders,\n HttpHeadersSchema,\n HttpResponse,\n HttpResponseBodySchema,\n HttpResponseHeadersSchema,\n HttpSchema,\n HttpSchemaMethod,\n HttpSchemaPath,\n HttpStatusCode,\n} from '@zimic/http';\nimport { Default, PossiblePromise } from '@zimic/utils/types';\n\nimport { FetchRequest } from '../request/FetchRequest';\nimport { getOrSetBoundBodyMethod, isBodyMethod, withIncludedBodyIfAvailable } from '../utils/objects';\nimport FetchResponseError from './error/FetchResponseError';\nimport {\n FetchResponseBodySchema,\n FetchResponseInit,\n FetchResponseObject,\n FetchResponseObjectOptions,\n FetchResponseStatusCode,\n} from './types';\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */\nexport interface FetchResponsePerStatusCode<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n StatusCode extends HttpStatusCode = HttpStatusCode,\n> extends HttpResponse<\n HttpResponseBodySchema<Default<Schema[Path][Method]>, StatusCode>,\n Default<HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>>,\n StatusCode\n> {\n raw: Response;\n request: FetchRequest<Schema, Method, Path>;\n error: FetchResponseError<Schema, Method, Path>;\n clone: () => FetchResponsePerStatusCode<Schema, Method, Path, StatusCode>;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response#responsetoobject `response.toObject()` API reference} */\n toObject: ((options: FetchResponseObjectOptions.WithBody) => Promise<FetchResponseObject>) &\n ((options?: FetchResponseObjectOptions.WithoutBody) => FetchResponseObject) &\n ((options?: FetchResponseObjectOptions) => PossiblePromise<FetchResponseObject>);\n}\n\n/** @see {@link https://zimic.dev/docs/fetch/api/fetch-response `FetchResponse` API reference} */\nexport type FetchResponse<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n /** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */\n ErrorOnly extends boolean = false,\n Redirect extends RequestRedirect = 'follow',\n StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> =\n FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>,\n> = StatusCode extends StatusCode ? FetchResponsePerStatusCode<Schema, Method, Path, StatusCode> : never;\n\nexport namespace FetchResponse {\n /** A loosely typed version of a {@link FetchResponse}. */\n export interface Loose extends Response {\n raw: Response;\n request: FetchRequest.Loose;\n error: FetchResponseError<any, any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n clone: () => Loose;\n /** @see {@link https://zimic.dev/docs/fetch/api/fetch-response#responsetoobject `response.toObject()` API reference} */\n toObject: ((options: FetchResponseObjectOptions.WithBody) => Promise<FetchResponseObject>) &\n ((options?: FetchResponseObjectOptions.WithoutBody) => FetchResponseObject) &\n ((options?: FetchResponseObjectOptions) => PossiblePromise<FetchResponseObject>);\n }\n}\n\ninterface FetchResponseClass {\n new <\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n /** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */\n ErrorOnly extends boolean = false,\n Redirect extends RequestRedirect = 'follow',\n StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> =\n FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>,\n >(\n fetchRequest: FetchRequest<Schema, Method, Path>,\n response?: Response,\n ): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;\n new <\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n /** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */\n ErrorOnly extends boolean = false,\n Redirect extends RequestRedirect = 'follow',\n StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> =\n FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>,\n >(\n fetchRequest: FetchRequest<Schema, Method, Path>,\n body?: FetchResponseBodySchema<Default<Default<Default<Schema[Path][Method]>['response']>[StatusCode]>>,\n init?: FetchResponseInit<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>,\n ): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;\n\n prototype: Response;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [Symbol.hasInstance]: (instance: unknown) => instance is FetchResponse<any, any, any, any, any, any>;\n}\n\nconst FETCH_RESPONSE_BRAND = Symbol.for('FetchResponse');\n\nconst FETCH_RESPONSE_EXTRA_PROPERTIES = [FETCH_RESPONSE_BRAND, 'raw', 'request', 'error', 'toObject'] as const;\ntype FetchResponseExtraProperty = (typeof FETCH_RESPONSE_EXTRA_PROPERTIES)[number];\n\nfunction createFetchResponseClass() {\n const FetchResponseClass = function FetchResponse<\n Schema extends HttpSchema,\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n /** @deprecated The type parameter `ErrorOnly` will be removed in the next major version. */\n ErrorOnly extends boolean = false,\n Redirect extends RequestRedirect = 'follow',\n StatusCode extends FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect> =\n FetchResponseStatusCode<Default<Schema[Path][Method]>, ErrorOnly, Redirect>,\n >(\n fetchRequest: FetchRequest<Schema, Method, Path>,\n responseOrBody?:\n | Response\n | FetchResponseBodySchema<Default<Default<Default<Schema[Path][Method]>['response']>[StatusCode]>>,\n init?: FetchResponseInit<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>,\n ): FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode> {\n const response =\n responseOrBody instanceof Response\n ? responseOrBody\n : new Response(responseOrBody as BodyInit | null, init as ResponseInit);\n\n let error: FetchResponseError<Schema, Method, Path> | null = null;\n\n function clone() {\n return new FetchResponseClass(fetchRequest, response.clone());\n }\n\n function toObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n function toObject(options?: { includeBody?: false }): FetchResponseObject;\n function toObject(options?: { includeBody?: boolean }): PossiblePromise<FetchResponseObject>;\n function toObject(options?: { includeBody?: boolean }): PossiblePromise<FetchResponseObject> {\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: HttpHeaders.prototype.toObject.call(response.headers) as HttpHeadersSchema,\n redirected: response.redirected,\n };\n\n if (!options?.includeBody) {\n return responseObject;\n }\n\n return withIncludedBodyIfAvailable(response, responseObject);\n }\n\n type FetchResponseInstance = FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;\n\n const fetchResponse = new Proxy(response, {\n get(target, property, receiver) {\n if (property === FETCH_RESPONSE_BRAND) {\n return true;\n }\n\n if (property === ('raw' satisfies keyof FetchResponseInstance)) {\n return response satisfies FetchResponseInstance['raw'];\n }\n\n if (property === ('request' satisfies keyof FetchResponseInstance)) {\n return fetchRequest satisfies FetchResponseInstance['request'];\n }\n\n if (property === ('error' satisfies keyof FetchResponseInstance)) {\n // We create the error lazily to preserve the stack trace from the point where it was first accessed.\n error ??= new FetchResponseError(fetchRequest, receiver as FetchResponse<Schema, Method, Path>);\n return error satisfies FetchResponseInstance['error'];\n }\n\n if (property === ('clone' satisfies keyof FetchResponseInstance)) {\n // The `clone` method is not compatible with the mapping we do in `FetchResponse`(i.e.\n // `StatusCode extends StatusCode ? ... : ...`), so we need a type assertion here.\n return clone as FetchResponseInstance['clone'];\n }\n\n if (property === ('toObject' satisfies keyof FetchResponseInstance)) {\n return toObject satisfies FetchResponseInstance['toObject'];\n }\n\n // Fallback other properties to the original `Response` instance.\n const value = Reflect.get(target, property, target) as unknown;\n\n if (isBodyMethod(property, value)) {\n return getOrSetBoundBodyMethod(response, property, value);\n }\n\n return value;\n },\n\n has(target, property) {\n return (\n FETCH_RESPONSE_EXTRA_PROPERTIES.includes(property as FetchResponseExtraProperty) ||\n Reflect.has(target, property)\n );\n },\n }) as unknown as FetchResponse<Schema, Method, Path, ErrorOnly, Redirect, StatusCode>;\n\n return fetchResponse;\n } as unknown as FetchResponseClass;\n\n Object.defineProperty(FetchResponseClass, Symbol.hasInstance, {\n value(instance: unknown): boolean {\n return (\n instance instanceof Response && FETCH_RESPONSE_BRAND in instance && instance[FETCH_RESPONSE_BRAND] === true\n );\n },\n writable: false,\n enumerable: false,\n configurable: false,\n });\n\n Object.setPrototypeOf(FetchResponseClass.prototype, Response.prototype);\n\n return FetchResponseClass;\n}\n\nexport const FetchResponse = createFetchResponseClass();\n\nObject.setPrototypeOf(FetchResponse.prototype, Response.prototype);\n","import { HttpSchemaPath, HttpSchemaMethod, LiteralHttpSchemaPathFromNonLiteral, HttpSchema } from '@zimic/http';\nimport { createRegexFromPath } from '@zimic/utils/url';\n\nimport { FetchRequest } from './request/FetchRequest';\nimport { FetchRequestInit } from './request/types';\nimport FetchResponseError from './response/error/FetchResponseError';\nimport { FetchResponse } from './response/FetchResponse';\nimport { FetchInput, FetchOptions, Fetch, FetchDefaults, FetchRequestConstructor } from './types/public';\n\nconst FETCH_OPTIONS_DEFAULT_PROPERTIES = [\n 'baseURL',\n 'onRequest',\n 'onResponse',\n 'body',\n 'cache',\n 'credentials',\n 'integrity',\n 'keepalive',\n 'mode',\n 'priority',\n 'redirect',\n 'referrer',\n 'referrerPolicy',\n 'signal',\n 'window',\n 'duplex',\n] satisfies (keyof FetchOptions<never>)[];\n\nclass FetchClient<Schema extends HttpSchema> implements Omit<Fetch<Schema>, 'loose' | 'Request' | keyof FetchDefaults> {\n fetch: Fetch<Schema>;\n\n constructor(options: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n this.assignDefaults(this.fetch, options);\n this.fetch.loose = this.fetch as unknown as Fetch.Loose;\n this.fetch.Request = this.createFetchRequestConstructor(this.fetch);\n }\n\n private assignDefaults(\n fetch: Fetch<Schema>,\n { headers = {}, searchParams = {}, ...otherOptions }: FetchOptions<Schema>,\n ) {\n fetch.headers = headers;\n fetch.searchParams = searchParams;\n\n for (const property of FETCH_OPTIONS_DEFAULT_PROPERTIES) {\n const propertyValue = otherOptions[property];\n\n if (propertyValue !== undefined) {\n fetch[property] = propertyValue as never;\n }\n }\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 Redirect extends RequestRedirect = 'follow',\n >(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>,\n ) => {\n const fetchRequest = await this.createFetchRequest<Method, Path>(input, init);\n\n const response = await globalThis.fetch(fetchRequest.raw.clone());\n const fetchResponse = await this.createFetchResponse<\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >(fetchRequest, response);\n\n return fetchResponse;\n };\n\n return Object.setPrototypeOf(fetch, this) as Fetch<Schema>;\n }\n\n private createFetchRequestConstructor<Schema extends HttpSchema>(fetch: Fetch<Schema>) {\n function Request<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n Redirect extends RequestRedirect = 'follow',\n >(\n input: FetchInput<Schema, Method, Path>,\n init?: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>, Redirect>,\n ) {\n return new FetchRequest(fetch, input, init);\n }\n\n Object.setPrototypeOf(Request.prototype, FetchRequest.prototype);\n\n return Request as unknown as FetchRequestConstructor<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 fetchRequest = new this.fetch.Request(input, init);\n\n if (this.fetch.onRequest) {\n const newRequest = await this.fetch.onRequest(fetchRequest as FetchRequest.Loose);\n\n if (newRequest !== fetchRequest) {\n if (newRequest instanceof FetchRequest) {\n fetchRequest = newRequest as typeof fetchRequest;\n } else {\n fetchRequest = new this.fetch.Request(newRequest as FetchInput<Schema, Method, Path>, init);\n }\n }\n }\n\n return fetchRequest;\n }\n\n private async createFetchResponse<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.Literal<Schema, Method>,\n >(fetchRequest: FetchRequest<Schema, Method, Path>, response: Response) {