@zimic/fetch 1.0.5 → 1.0.6-canary.1
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 +3 -2
- package/dist/index.js +37 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/client/errors/FetchResponseError.ts +48 -43
package/dist/index.d.ts
CHANGED
|
@@ -206,8 +206,9 @@ declare class FetchResponseError<Schema extends HttpSchema, Method extends HttpS
|
|
|
206
206
|
toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;
|
|
207
207
|
toObject(options: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;
|
|
208
208
|
toObject(options?: FetchResponseErrorObjectOptions): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;
|
|
209
|
-
private
|
|
210
|
-
private
|
|
209
|
+
private requestToObject;
|
|
210
|
+
private responseToObject;
|
|
211
|
+
private headersToObject;
|
|
211
212
|
}
|
|
212
213
|
type AnyFetchRequestError = FetchResponseError<any, any, any>;
|
|
213
214
|
|
package/dist/index.js
CHANGED
|
@@ -14,67 +14,72 @@ var FetchResponseError = class extends Error {
|
|
|
14
14
|
static {
|
|
15
15
|
__name(this, "FetchResponseError");
|
|
16
16
|
}
|
|
17
|
-
toObject(
|
|
18
|
-
const includeRequestBody = options?.includeRequestBody ?? false;
|
|
19
|
-
const includeResponseBody = options?.includeResponseBody ?? false;
|
|
17
|
+
toObject({ includeRequestBody = false, includeResponseBody = false } = {}) {
|
|
20
18
|
const partialObject = {
|
|
21
19
|
name: this.name,
|
|
22
20
|
message: this.message
|
|
23
21
|
};
|
|
24
22
|
if (!includeRequestBody && !includeResponseBody) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return {
|
|
24
|
+
...partialObject,
|
|
25
|
+
request: this.requestToObject({ includeBody: false }),
|
|
26
|
+
response: this.responseToObject({ includeBody: false })
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
29
|
return Promise.all([
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
30
|
+
Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),
|
|
31
|
+
Promise.resolve(this.responseToObject({ includeBody: includeResponseBody }))
|
|
32
32
|
]).then(([request, response]) => ({ ...partialObject, request, response }));
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
requestToObject(options) {
|
|
35
|
+
const request = this.request;
|
|
35
36
|
const requestObject = {
|
|
36
|
-
url:
|
|
37
|
-
path:
|
|
38
|
-
method:
|
|
39
|
-
headers:
|
|
40
|
-
cache:
|
|
41
|
-
destination:
|
|
42
|
-
credentials:
|
|
43
|
-
integrity:
|
|
44
|
-
keepalive:
|
|
45
|
-
mode:
|
|
46
|
-
redirect:
|
|
47
|
-
referrer:
|
|
48
|
-
referrerPolicy:
|
|
37
|
+
url: request.url,
|
|
38
|
+
path: request.path,
|
|
39
|
+
method: request.method,
|
|
40
|
+
headers: this.headersToObject(request.headers),
|
|
41
|
+
cache: request.cache,
|
|
42
|
+
destination: request.destination,
|
|
43
|
+
credentials: request.credentials,
|
|
44
|
+
integrity: request.integrity,
|
|
45
|
+
keepalive: request.keepalive,
|
|
46
|
+
mode: request.mode,
|
|
47
|
+
redirect: request.redirect,
|
|
48
|
+
referrer: request.referrer,
|
|
49
|
+
referrerPolicy: request.referrerPolicy
|
|
49
50
|
};
|
|
50
51
|
if (!options.includeBody) {
|
|
51
52
|
return requestObject;
|
|
52
53
|
}
|
|
53
|
-
const bodyAsTextPromise =
|
|
54
|
+
const bodyAsTextPromise = request.text();
|
|
54
55
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
55
56
|
requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
56
57
|
return requestObject;
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
responseToObject(options) {
|
|
61
|
+
const response = this.response;
|
|
60
62
|
const responseObject = {
|
|
61
|
-
url:
|
|
62
|
-
type:
|
|
63
|
-
status:
|
|
64
|
-
statusText:
|
|
65
|
-
ok:
|
|
66
|
-
headers:
|
|
67
|
-
redirected:
|
|
63
|
+
url: response.url,
|
|
64
|
+
type: response.type,
|
|
65
|
+
status: response.status,
|
|
66
|
+
statusText: response.statusText,
|
|
67
|
+
ok: response.ok,
|
|
68
|
+
headers: this.headersToObject(response.headers),
|
|
69
|
+
redirected: response.redirected
|
|
68
70
|
};
|
|
69
71
|
if (!options.includeBody) {
|
|
70
72
|
return responseObject;
|
|
71
73
|
}
|
|
72
|
-
const bodyAsTextPromise =
|
|
74
|
+
const bodyAsTextPromise = response.text();
|
|
73
75
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
74
76
|
responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
75
77
|
return responseObject;
|
|
76
78
|
});
|
|
77
79
|
}
|
|
80
|
+
headersToObject(headers) {
|
|
81
|
+
return http.HttpHeaders.prototype.toObject.call(headers);
|
|
82
|
+
}
|
|
78
83
|
};
|
|
79
84
|
var FetchResponseError_default = FetchResponseError;
|
|
80
85
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/dist/chunk-2D3UJWOA.mjs","../../zimic-utils/src/url/createParametrizedPathPattern.ts","../../zimic-utils/src/url/excludeURLParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["HttpHeaders","__defProp","__name","Request","HttpSearchParams"],"mappings":";;;;;;AA0CA,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,C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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;AAGlD,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACzQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAKT,IAAO,eAAA,GAAQ","file":"index.js","sourcesContent":["import { HttpHeaders, HttpHeadersSchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http';\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): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): Promise<FetchResponseErrorObject> | FetchResponseErrorObject {\n const includeRequestBody = options?.includeRequestBody ?? false;\n const includeResponseBody = options?.includeResponseBody ?? false;\n\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n const request = this.convertRequestToObject({ includeBody: false });\n const response = this.convertResponseToObject({ includeBody: false });\n return { ...partialObject, request, response };\n }\n\n return Promise.all([\n this.convertRequestToObject({ includeBody: includeRequestBody }),\n this.convertResponseToObject({ includeBody: includeResponseBody }),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private convertRequestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private convertRequestToObject(options: { includeBody: false }): FetchRequestObject;\n private convertRequestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject;\n private convertRequestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject {\n const requestObject: FetchRequestObject = {\n url: this.request.url,\n path: this.request.path,\n method: this.request.method,\n headers: HttpHeaders.prototype.toObject.call(this.request.headers) as HttpHeadersSchema,\n cache: this.request.cache,\n destination: this.request.destination,\n credentials: this.request.credentials,\n integrity: this.request.integrity,\n keepalive: this.request.keepalive,\n mode: this.request.mode,\n redirect: this.request.redirect,\n referrer: this.request.referrer,\n referrerPolicy: this.request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = this.request.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return requestObject;\n });\n }\n\n private convertResponseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private convertResponseToObject(options: { includeBody: false }): FetchResponseObject;\n private convertResponseToObject(options: {\n includeBody: boolean;\n }): Promise<FetchResponseObject> | FetchResponseObject;\n private convertResponseToObject(options: {\n includeBody: boolean;\n }): Promise<FetchResponseObject> | FetchResponseObject {\n const responseObject: FetchResponseObject = {\n url: this.response.url,\n type: this.response.type,\n status: this.response.status,\n statusText: this.response.statusText,\n ok: this.response.ok,\n headers: HttpHeaders.prototype.toObject.call(this.response.headers) as HttpHeadersSchema,\n redirected: this.response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = this.response.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return responseObject;\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","var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\nvar __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\n\nexport { __commonJS, __name, __toESM };\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map","export function getExtraPatternsToEscape() {\n return /([.(){}+$])/g;\n}\n\nexport function getURIEncodedBackSlashPattern() {\n return /%5C/g;\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 getPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)/gu;\n}\n\nexport function getRepeatingPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\+/gu;\n}\n\nexport function getOptionalPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function getOptionalRepeatingPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createParametrizedPathPattern(path: string) {\n const replacedURL = encodeURI(path)\n .replace(/^\\/+/g, '')\n .replace(/\\/+$/g, '')\n .replace(getExtraPatternsToEscape(), '\\\\$1')\n .replace(getURIEncodedBackSlashPattern(), '\\\\')\n .replace(\n getOptionalRepeatingPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getRepeatingPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>.+)`;\n })\n .replace(\n getOptionalPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${replacedURL}/?$`);\n}\n\nexport default createParametrizedPathPattern;\n","function excludeURLParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeURLParams;\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 createParametrizedPathPattern from '@zimic/utils/url/createParametrizedPathPattern';\nimport excludeURLParams from '@zimic/utils/url/excludeURLParams';\nimport joinURL from '@zimic/utils/url/joinURL';\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>, 'defaults' | 'loose' | 'Request'> {\n fetch: Fetch<Schema>;\n\n constructor({ onRequest, onResponse, ...defaults }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n\n this.fetch.defaults = {\n ...defaults,\n headers: defaults.headers ?? {},\n searchParams: defaults.searchParams ?? {},\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n\n this.fetch.Request = this.createRequestClass(this.fetch.defaults);\n this.fetch.onRequest = onRequest;\n this.fetch.onResponse = onResponse;\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(defaults: FetchDefaults) {\n class Request<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n > extends globalThis.Request {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n const initWithDefaults = { ...defaults, ...init };\n\n const headersFromDefaults = new HttpHeaders(defaults.headers);\n const headersFromInit = new HttpHeaders((init satisfies RequestInit as RequestInit).headers);\n\n let url: URL;\n const baseURL = new URL(initWithDefaults.baseURL);\n\n if (input instanceof globalThis.Request) {\n // Optimize type checking by narrowing the type of input\n const request = input as globalThis.Request;\n\n // Optimize type checking by narrowing the type of headers\n const headersFromRequest = new HttpHeaders(input.headers as Headers);\n\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromRequest.toObject(),\n ...headersFromInit.toObject(),\n };\n\n super(request, initWithDefaults);\n\n url = new URL(input.url);\n } else {\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromInit.toObject(),\n };\n\n url = input instanceof URL ? new URL(input) : new URL(joinURL(baseURL, input));\n\n const searchParamsFromDefaults = new HttpSearchParams(defaults.searchParams);\n const searchParamsFromInit = new HttpSearchParams(initWithDefaults.searchParams);\n\n initWithDefaults.searchParams = {\n ...searchParamsFromDefaults.toObject(),\n ...searchParamsFromInit.toObject(),\n };\n\n url.search = new HttpSearchParams(initWithDefaults.searchParams).toString();\n\n super(url, initWithDefaults);\n }\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeURLParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): Request<Method, Path> {\n const rawClone = super.clone();\n\n return new Request<Method, Path>(\n rawClone as unknown as FetchInput<Schema, Method, Path>,\n rawClone as unknown as FetchRequestInit<\n Schema,\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >,\n );\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 createParametrizedPathPattern(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/dist/chunk-2D3UJWOA.mjs","../../zimic-utils/src/url/createParametrizedPathPattern.ts","../../zimic-utils/src/url/excludeURLParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["HttpHeaders","__defProp","__name","Request","HttpSearchParams"],"mappings":";;;;;;AA0CA,IAAM,kBAAA,GAAN,cAIU,KAAA,CAAM;AAAA,EACd,WAAA,CACS,SACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,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SAAA,CAAU,MAAM,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA,IAC1C,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAAA;AAGlD,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACzQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAKT,IAAO,eAAA,GAAQ","file":"index.js","sourcesContent":["import { HttpHeaders, HttpHeadersSchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http';\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): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;\n toObject({ includeRequestBody = false, includeResponseBody = false }: FetchResponseErrorObjectOptions = {}):\n | Promise<FetchResponseErrorObject>\n | 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 }): Promise<FetchRequestObject> | FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | 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.headersToObject(request.headers),\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 // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = request.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return requestObject;\n });\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | 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.headersToObject(response.headers),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = response.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return responseObject;\n });\n }\n\n private headersToObject(headers: typeof this.request.headers | typeof this.response.headers): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(headers) as HttpHeadersSchema;\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","var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\nvar __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\n\nexport { __commonJS, __name, __toESM };\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map","export function getExtraPatternsToEscape() {\n return /([.(){}+$])/g;\n}\n\nexport function getURIEncodedBackSlashPattern() {\n return /%5C/g;\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 getPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)/gu;\n}\n\nexport function getRepeatingPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\+/gu;\n}\n\nexport function getOptionalPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function getOptionalRepeatingPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createParametrizedPathPattern(path: string) {\n const replacedURL = encodeURI(path)\n .replace(/^\\/+/g, '')\n .replace(/\\/+$/g, '')\n .replace(getExtraPatternsToEscape(), '\\\\$1')\n .replace(getURIEncodedBackSlashPattern(), '\\\\')\n .replace(\n getOptionalRepeatingPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getRepeatingPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>.+)`;\n })\n .replace(\n getOptionalPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${replacedURL}/?$`);\n}\n\nexport default createParametrizedPathPattern;\n","function excludeURLParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeURLParams;\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 createParametrizedPathPattern from '@zimic/utils/url/createParametrizedPathPattern';\nimport excludeURLParams from '@zimic/utils/url/excludeURLParams';\nimport joinURL from '@zimic/utils/url/joinURL';\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>, 'defaults' | 'loose' | 'Request'> {\n fetch: Fetch<Schema>;\n\n constructor({ onRequest, onResponse, ...defaults }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n\n this.fetch.defaults = {\n ...defaults,\n headers: defaults.headers ?? {},\n searchParams: defaults.searchParams ?? {},\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n\n this.fetch.Request = this.createRequestClass(this.fetch.defaults);\n this.fetch.onRequest = onRequest;\n this.fetch.onResponse = onResponse;\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(defaults: FetchDefaults) {\n class Request<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n > extends globalThis.Request {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n const initWithDefaults = { ...defaults, ...init };\n\n const headersFromDefaults = new HttpHeaders(defaults.headers);\n const headersFromInit = new HttpHeaders((init satisfies RequestInit as RequestInit).headers);\n\n let url: URL;\n const baseURL = new URL(initWithDefaults.baseURL);\n\n if (input instanceof globalThis.Request) {\n // Optimize type checking by narrowing the type of input\n const request = input as globalThis.Request;\n\n // Optimize type checking by narrowing the type of headers\n const headersFromRequest = new HttpHeaders(input.headers as Headers);\n\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromRequest.toObject(),\n ...headersFromInit.toObject(),\n };\n\n super(request, initWithDefaults);\n\n url = new URL(input.url);\n } else {\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromInit.toObject(),\n };\n\n url = input instanceof URL ? new URL(input) : new URL(joinURL(baseURL, input));\n\n const searchParamsFromDefaults = new HttpSearchParams(defaults.searchParams);\n const searchParamsFromInit = new HttpSearchParams(initWithDefaults.searchParams);\n\n initWithDefaults.searchParams = {\n ...searchParamsFromDefaults.toObject(),\n ...searchParamsFromInit.toObject(),\n };\n\n url.search = new HttpSearchParams(initWithDefaults.searchParams).toString();\n\n super(url, initWithDefaults);\n }\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeURLParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): Request<Method, Path> {\n const rawClone = super.clone();\n\n return new Request<Method, Path>(\n rawClone as unknown as FetchInput<Schema, Method, Path>,\n rawClone as unknown as FetchRequestInit<\n Schema,\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >,\n );\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 createParametrizedPathPattern(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
|
@@ -12,67 +12,72 @@ var FetchResponseError = class extends Error {
|
|
|
12
12
|
static {
|
|
13
13
|
__name(this, "FetchResponseError");
|
|
14
14
|
}
|
|
15
|
-
toObject(
|
|
16
|
-
const includeRequestBody = options?.includeRequestBody ?? false;
|
|
17
|
-
const includeResponseBody = options?.includeResponseBody ?? false;
|
|
15
|
+
toObject({ includeRequestBody = false, includeResponseBody = false } = {}) {
|
|
18
16
|
const partialObject = {
|
|
19
17
|
name: this.name,
|
|
20
18
|
message: this.message
|
|
21
19
|
};
|
|
22
20
|
if (!includeRequestBody && !includeResponseBody) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
return {
|
|
22
|
+
...partialObject,
|
|
23
|
+
request: this.requestToObject({ includeBody: false }),
|
|
24
|
+
response: this.responseToObject({ includeBody: false })
|
|
25
|
+
};
|
|
26
26
|
}
|
|
27
27
|
return Promise.all([
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
28
|
+
Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),
|
|
29
|
+
Promise.resolve(this.responseToObject({ includeBody: includeResponseBody }))
|
|
30
30
|
]).then(([request, response]) => ({ ...partialObject, request, response }));
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
requestToObject(options) {
|
|
33
|
+
const request = this.request;
|
|
33
34
|
const requestObject = {
|
|
34
|
-
url:
|
|
35
|
-
path:
|
|
36
|
-
method:
|
|
37
|
-
headers:
|
|
38
|
-
cache:
|
|
39
|
-
destination:
|
|
40
|
-
credentials:
|
|
41
|
-
integrity:
|
|
42
|
-
keepalive:
|
|
43
|
-
mode:
|
|
44
|
-
redirect:
|
|
45
|
-
referrer:
|
|
46
|
-
referrerPolicy:
|
|
35
|
+
url: request.url,
|
|
36
|
+
path: request.path,
|
|
37
|
+
method: request.method,
|
|
38
|
+
headers: this.headersToObject(request.headers),
|
|
39
|
+
cache: request.cache,
|
|
40
|
+
destination: request.destination,
|
|
41
|
+
credentials: request.credentials,
|
|
42
|
+
integrity: request.integrity,
|
|
43
|
+
keepalive: request.keepalive,
|
|
44
|
+
mode: request.mode,
|
|
45
|
+
redirect: request.redirect,
|
|
46
|
+
referrer: request.referrer,
|
|
47
|
+
referrerPolicy: request.referrerPolicy
|
|
47
48
|
};
|
|
48
49
|
if (!options.includeBody) {
|
|
49
50
|
return requestObject;
|
|
50
51
|
}
|
|
51
|
-
const bodyAsTextPromise =
|
|
52
|
+
const bodyAsTextPromise = request.text();
|
|
52
53
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
53
54
|
requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
54
55
|
return requestObject;
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
responseToObject(options) {
|
|
59
|
+
const response = this.response;
|
|
58
60
|
const responseObject = {
|
|
59
|
-
url:
|
|
60
|
-
type:
|
|
61
|
-
status:
|
|
62
|
-
statusText:
|
|
63
|
-
ok:
|
|
64
|
-
headers:
|
|
65
|
-
redirected:
|
|
61
|
+
url: response.url,
|
|
62
|
+
type: response.type,
|
|
63
|
+
status: response.status,
|
|
64
|
+
statusText: response.statusText,
|
|
65
|
+
ok: response.ok,
|
|
66
|
+
headers: this.headersToObject(response.headers),
|
|
67
|
+
redirected: response.redirected
|
|
66
68
|
};
|
|
67
69
|
if (!options.includeBody) {
|
|
68
70
|
return responseObject;
|
|
69
71
|
}
|
|
70
|
-
const bodyAsTextPromise =
|
|
72
|
+
const bodyAsTextPromise = response.text();
|
|
71
73
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
72
74
|
responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
73
75
|
return responseObject;
|
|
74
76
|
});
|
|
75
77
|
}
|
|
78
|
+
headersToObject(headers) {
|
|
79
|
+
return HttpHeaders.prototype.toObject.call(headers);
|
|
80
|
+
}
|
|
76
81
|
};
|
|
77
82
|
var FetchResponseError_default = FetchResponseError;
|
|
78
83
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/errors/FetchResponseError.ts","../../zimic-utils/dist/chunk-2D3UJWOA.mjs","../../zimic-utils/src/url/createParametrizedPathPattern.ts","../../zimic-utils/src/url/excludeURLParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["__defProp","__name","Request","HttpHeaders"],"mappings":";;;;AA0CA,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,MAA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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;AAGlD,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACzQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAKT,IAAO,eAAA,GAAQ","file":"index.mjs","sourcesContent":["import { HttpHeaders, HttpHeadersSchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http';\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): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;\n toObject(options?: FetchResponseErrorObjectOptions): Promise<FetchResponseErrorObject> | FetchResponseErrorObject {\n const includeRequestBody = options?.includeRequestBody ?? false;\n const includeResponseBody = options?.includeResponseBody ?? false;\n\n const partialObject = {\n name: this.name,\n message: this.message,\n } satisfies Partial<FetchResponseErrorObject>;\n\n if (!includeRequestBody && !includeResponseBody) {\n const request = this.convertRequestToObject({ includeBody: false });\n const response = this.convertResponseToObject({ includeBody: false });\n return { ...partialObject, request, response };\n }\n\n return Promise.all([\n this.convertRequestToObject({ includeBody: includeRequestBody }),\n this.convertResponseToObject({ includeBody: includeResponseBody }),\n ]).then(([request, response]) => ({ ...partialObject, request, response }));\n }\n\n private convertRequestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;\n private convertRequestToObject(options: { includeBody: false }): FetchRequestObject;\n private convertRequestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject;\n private convertRequestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject {\n const requestObject: FetchRequestObject = {\n url: this.request.url,\n path: this.request.path,\n method: this.request.method,\n headers: HttpHeaders.prototype.toObject.call(this.request.headers) as HttpHeadersSchema,\n cache: this.request.cache,\n destination: this.request.destination,\n credentials: this.request.credentials,\n integrity: this.request.integrity,\n keepalive: this.request.keepalive,\n mode: this.request.mode,\n redirect: this.request.redirect,\n referrer: this.request.referrer,\n referrerPolicy: this.request.referrerPolicy,\n };\n\n if (!options.includeBody) {\n return requestObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = this.request.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return requestObject;\n });\n }\n\n private convertResponseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private convertResponseToObject(options: { includeBody: false }): FetchResponseObject;\n private convertResponseToObject(options: {\n includeBody: boolean;\n }): Promise<FetchResponseObject> | FetchResponseObject;\n private convertResponseToObject(options: {\n includeBody: boolean;\n }): Promise<FetchResponseObject> | FetchResponseObject {\n const responseObject: FetchResponseObject = {\n url: this.response.url,\n type: this.response.type,\n status: this.response.status,\n statusText: this.response.statusText,\n ok: this.response.ok,\n headers: HttpHeaders.prototype.toObject.call(this.response.headers) as HttpHeadersSchema,\n redirected: this.response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = this.response.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return responseObject;\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","var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\nvar __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\n\nexport { __commonJS, __name, __toESM };\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map","export function getExtraPatternsToEscape() {\n return /([.(){}+$])/g;\n}\n\nexport function getURIEncodedBackSlashPattern() {\n return /%5C/g;\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 getPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)/gu;\n}\n\nexport function getRepeatingPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\+/gu;\n}\n\nexport function getOptionalPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function getOptionalRepeatingPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createParametrizedPathPattern(path: string) {\n const replacedURL = encodeURI(path)\n .replace(/^\\/+/g, '')\n .replace(/\\/+$/g, '')\n .replace(getExtraPatternsToEscape(), '\\\\$1')\n .replace(getURIEncodedBackSlashPattern(), '\\\\')\n .replace(\n getOptionalRepeatingPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getRepeatingPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>.+)`;\n })\n .replace(\n getOptionalPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${replacedURL}/?$`);\n}\n\nexport default createParametrizedPathPattern;\n","function excludeURLParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeURLParams;\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 createParametrizedPathPattern from '@zimic/utils/url/createParametrizedPathPattern';\nimport excludeURLParams from '@zimic/utils/url/excludeURLParams';\nimport joinURL from '@zimic/utils/url/joinURL';\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>, 'defaults' | 'loose' | 'Request'> {\n fetch: Fetch<Schema>;\n\n constructor({ onRequest, onResponse, ...defaults }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n\n this.fetch.defaults = {\n ...defaults,\n headers: defaults.headers ?? {},\n searchParams: defaults.searchParams ?? {},\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n\n this.fetch.Request = this.createRequestClass(this.fetch.defaults);\n this.fetch.onRequest = onRequest;\n this.fetch.onResponse = onResponse;\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(defaults: FetchDefaults) {\n class Request<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n > extends globalThis.Request {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n const initWithDefaults = { ...defaults, ...init };\n\n const headersFromDefaults = new HttpHeaders(defaults.headers);\n const headersFromInit = new HttpHeaders((init satisfies RequestInit as RequestInit).headers);\n\n let url: URL;\n const baseURL = new URL(initWithDefaults.baseURL);\n\n if (input instanceof globalThis.Request) {\n // Optimize type checking by narrowing the type of input\n const request = input as globalThis.Request;\n\n // Optimize type checking by narrowing the type of headers\n const headersFromRequest = new HttpHeaders(input.headers as Headers);\n\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromRequest.toObject(),\n ...headersFromInit.toObject(),\n };\n\n super(request, initWithDefaults);\n\n url = new URL(input.url);\n } else {\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromInit.toObject(),\n };\n\n url = input instanceof URL ? new URL(input) : new URL(joinURL(baseURL, input));\n\n const searchParamsFromDefaults = new HttpSearchParams(defaults.searchParams);\n const searchParamsFromInit = new HttpSearchParams(initWithDefaults.searchParams);\n\n initWithDefaults.searchParams = {\n ...searchParamsFromDefaults.toObject(),\n ...searchParamsFromInit.toObject(),\n };\n\n url.search = new HttpSearchParams(initWithDefaults.searchParams).toString();\n\n super(url, initWithDefaults);\n }\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeURLParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): Request<Method, Path> {\n const rawClone = super.clone();\n\n return new Request<Method, Path>(\n rawClone as unknown as FetchInput<Schema, Method, Path>,\n rawClone as unknown as FetchRequestInit<\n Schema,\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >,\n );\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 createParametrizedPathPattern(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/dist/chunk-2D3UJWOA.mjs","../../zimic-utils/src/url/createParametrizedPathPattern.ts","../../zimic-utils/src/url/excludeURLParams.ts","../../zimic-utils/src/url/joinURL.ts","../src/client/FetchClient.ts","../src/client/factory.ts"],"names":["__defProp","__name","Request","HttpHeaders"],"mappings":";;;;AA0CA,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,CAA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EAAS,MAAA,EAAQ,IAAI,CAAA,IAC1C,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAAA;AAGlD,CAAA;AAEA,IAAO,mBAAA,GAAQ,WAAA;;;ACzQf,SAAS,YAAuC,OAAA,EAA8C;AAC5F,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAI,oBAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,KAAA;AACT;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAKT,IAAO,eAAA,GAAQ","file":"index.mjs","sourcesContent":["import { HttpHeaders, HttpHeadersSchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http';\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): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;\n toObject({ includeRequestBody = false, includeResponseBody = false }: FetchResponseErrorObjectOptions = {}):\n | Promise<FetchResponseErrorObject>\n | 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 }): Promise<FetchRequestObject> | FetchRequestObject;\n private requestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | 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.headersToObject(request.headers),\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 // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = request.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return requestObject;\n });\n }\n\n private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;\n private responseToObject(options: { includeBody: false }): FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | FetchResponseObject;\n private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | 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.headersToObject(response.headers),\n redirected: response.redirected,\n };\n\n if (!options.includeBody) {\n return responseObject;\n }\n\n // Optimize type checking by narrowing the type of the body\n const bodyAsTextPromise = response.text() as Promise<string>;\n\n return bodyAsTextPromise.then((bodyAsText) => {\n responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;\n return responseObject;\n });\n }\n\n private headersToObject(headers: typeof this.request.headers | typeof this.response.headers): HttpHeadersSchema {\n return HttpHeaders.prototype.toObject.call(headers) as HttpHeadersSchema;\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","var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\nvar __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\n\nexport { __commonJS, __name, __toESM };\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map\n//# sourceMappingURL=chunk-2D3UJWOA.mjs.map","export function getExtraPatternsToEscape() {\n return /([.(){}+$])/g;\n}\n\nexport function getURIEncodedBackSlashPattern() {\n return /%5C/g;\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 getPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)/gu;\n}\n\nexport function getRepeatingPathParamPattern() {\n return /(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\\\+/gu;\n}\n\nexport function getOptionalPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\?(?<trailingSlash>\\/)?/gu;\n}\n\nexport function getOptionalRepeatingPathParamPattern() {\n return /(?<leadingSlash>\\/)?(?<escape>\\\\)?:(?<identifier>[$_\\p{ID_Start}][$\\p{ID_Continue}]+)\\*(?<trailingSlash>\\/)?/gu;\n}\n\nfunction createParametrizedPathPattern(path: string) {\n const replacedURL = encodeURI(path)\n .replace(/^\\/+/g, '')\n .replace(/\\/+$/g, '')\n .replace(getExtraPatternsToEscape(), '\\\\$1')\n .replace(getURIEncodedBackSlashPattern(), '\\\\')\n .replace(\n getOptionalRepeatingPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getRepeatingPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>.+)`;\n })\n .replace(\n getOptionalPathParamPattern(),\n (\n _match,\n leadingSlash: string | undefined,\n escape: string | undefined,\n identifier: string,\n trailingSlash: string | undefined,\n ) => {\n if (escape) {\n return `:${identifier}`;\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(getPathParamPattern(), (_match, escape: string | undefined, identifier: string) => {\n return escape ? `:${identifier}` : `(?<${identifier}>[^\\\\/]+?)`;\n });\n\n return new RegExp(`^/?${replacedURL}/?$`);\n}\n\nexport default createParametrizedPathPattern;\n","function excludeURLParams(url: URL) {\n url.hash = '';\n url.search = '';\n url.username = '';\n url.password = '';\n return url;\n}\n\nexport default excludeURLParams;\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 createParametrizedPathPattern from '@zimic/utils/url/createParametrizedPathPattern';\nimport excludeURLParams from '@zimic/utils/url/excludeURLParams';\nimport joinURL from '@zimic/utils/url/joinURL';\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>, 'defaults' | 'loose' | 'Request'> {\n fetch: Fetch<Schema>;\n\n constructor({ onRequest, onResponse, ...defaults }: FetchOptions<Schema>) {\n this.fetch = this.createFetchFunction();\n\n this.fetch.defaults = {\n ...defaults,\n headers: defaults.headers ?? {},\n searchParams: defaults.searchParams ?? {},\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.fetch.loose = this.fetch as Fetch<any> as Fetch.Loose;\n\n this.fetch.Request = this.createRequestClass(this.fetch.defaults);\n this.fetch.onRequest = onRequest;\n this.fetch.onResponse = onResponse;\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(defaults: FetchDefaults) {\n class Request<\n Method extends HttpSchemaMethod<Schema>,\n Path extends HttpSchemaPath.NonLiteral<Schema, Method>,\n > extends globalThis.Request {\n path: LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n\n constructor(\n input: FetchInput<Schema, Method, Path>,\n init: FetchRequestInit<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>>,\n ) {\n const initWithDefaults = { ...defaults, ...init };\n\n const headersFromDefaults = new HttpHeaders(defaults.headers);\n const headersFromInit = new HttpHeaders((init satisfies RequestInit as RequestInit).headers);\n\n let url: URL;\n const baseURL = new URL(initWithDefaults.baseURL);\n\n if (input instanceof globalThis.Request) {\n // Optimize type checking by narrowing the type of input\n const request = input as globalThis.Request;\n\n // Optimize type checking by narrowing the type of headers\n const headersFromRequest = new HttpHeaders(input.headers as Headers);\n\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromRequest.toObject(),\n ...headersFromInit.toObject(),\n };\n\n super(request, initWithDefaults);\n\n url = new URL(input.url);\n } else {\n initWithDefaults.headers = {\n ...headersFromDefaults.toObject(),\n ...headersFromInit.toObject(),\n };\n\n url = input instanceof URL ? new URL(input) : new URL(joinURL(baseURL, input));\n\n const searchParamsFromDefaults = new HttpSearchParams(defaults.searchParams);\n const searchParamsFromInit = new HttpSearchParams(initWithDefaults.searchParams);\n\n initWithDefaults.searchParams = {\n ...searchParamsFromDefaults.toObject(),\n ...searchParamsFromInit.toObject(),\n };\n\n url.search = new HttpSearchParams(initWithDefaults.searchParams).toString();\n\n super(url, initWithDefaults);\n }\n\n const baseURLWithoutTrailingSlash = baseURL.toString().replace(/\\/$/, '');\n\n this.path = excludeURLParams(url)\n .toString()\n .replace(baseURLWithoutTrailingSlash, '') as LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>;\n }\n\n clone(): Request<Method, Path> {\n const rawClone = super.clone();\n\n return new Request<Method, Path>(\n rawClone as unknown as FetchInput<Schema, Method, Path>,\n rawClone as unknown as FetchRequestInit<\n Schema,\n Method,\n LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>\n >,\n );\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 createParametrizedPathPattern(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
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"api",
|
|
14
14
|
"static"
|
|
15
15
|
],
|
|
16
|
-
"version": "1.0.
|
|
16
|
+
"version": "1.0.6-canary.1",
|
|
17
17
|
"homepage": "https://zimic.dev/docs/fetch",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
"./package.json": "./package.json"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/node": "^24.
|
|
65
|
+
"@types/node": "^24.5.2",
|
|
66
66
|
"@vitest/browser": "^3.2.4",
|
|
67
67
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
68
68
|
"dotenv-cli": "^10.0.0",
|
|
69
|
-
"eslint": "^9.
|
|
69
|
+
"eslint": "^9.36.0",
|
|
70
70
|
"playwright": "^1.55.0",
|
|
71
71
|
"tsup": "^8.4.0",
|
|
72
72
|
"typescript": "^5.9.2",
|
|
73
73
|
"vitest": "^3.2.4",
|
|
74
74
|
"@zimic/eslint-config-node": "0.0.0",
|
|
75
|
-
"@zimic/interceptor": "1.1.1-canary.1",
|
|
76
75
|
"@zimic/lint-staged-config": "0.0.0",
|
|
76
|
+
"@zimic/interceptor": "1.1.2-canary.0",
|
|
77
77
|
"@zimic/tsconfig": "0.0.0",
|
|
78
78
|
"@zimic/utils": "0.0.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"typescript": ">=5.0.0",
|
|
82
|
-
"@zimic/http": "^1.1.0 || 1.1.
|
|
82
|
+
"@zimic/http": "^1.1.0 || 1.1.2-canary.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|
|
85
85
|
"typescript": {
|
|
@@ -57,45 +57,48 @@ class FetchResponseError<
|
|
|
57
57
|
toObject(options: FetchResponseErrorObjectOptions.WithBody): Promise<FetchResponseErrorObject>;
|
|
58
58
|
toObject(options: FetchResponseErrorObjectOptions.WithoutBody): FetchResponseErrorObject;
|
|
59
59
|
toObject(options?: FetchResponseErrorObjectOptions): Promise<FetchResponseErrorObject> | FetchResponseErrorObject;
|
|
60
|
-
toObject(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
toObject({ includeRequestBody = false, includeResponseBody = false }: FetchResponseErrorObjectOptions = {}):
|
|
61
|
+
| Promise<FetchResponseErrorObject>
|
|
62
|
+
| FetchResponseErrorObject {
|
|
64
63
|
const partialObject = {
|
|
65
64
|
name: this.name,
|
|
66
65
|
message: this.message,
|
|
67
66
|
} satisfies Partial<FetchResponseErrorObject>;
|
|
68
67
|
|
|
69
68
|
if (!includeRequestBody && !includeResponseBody) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
return {
|
|
70
|
+
...partialObject,
|
|
71
|
+
request: this.requestToObject({ includeBody: false }),
|
|
72
|
+
response: this.responseToObject({ includeBody: false }),
|
|
73
|
+
};
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
return Promise.all([
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
77
|
+
Promise.resolve(this.requestToObject({ includeBody: includeRequestBody })),
|
|
78
|
+
Promise.resolve(this.responseToObject({ includeBody: includeResponseBody })),
|
|
78
79
|
]).then(([request, response]) => ({ ...partialObject, request, response }));
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
private
|
|
82
|
-
private
|
|
83
|
-
private
|
|
84
|
-
private
|
|
82
|
+
private requestToObject(options: { includeBody: true }): Promise<FetchRequestObject>;
|
|
83
|
+
private requestToObject(options: { includeBody: false }): FetchRequestObject;
|
|
84
|
+
private requestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject;
|
|
85
|
+
private requestToObject(options: { includeBody: boolean }): Promise<FetchRequestObject> | FetchRequestObject {
|
|
86
|
+
const request = this.request;
|
|
87
|
+
|
|
85
88
|
const requestObject: FetchRequestObject = {
|
|
86
|
-
url:
|
|
87
|
-
path:
|
|
88
|
-
method:
|
|
89
|
-
headers:
|
|
90
|
-
cache:
|
|
91
|
-
destination:
|
|
92
|
-
credentials:
|
|
93
|
-
integrity:
|
|
94
|
-
keepalive:
|
|
95
|
-
mode:
|
|
96
|
-
redirect:
|
|
97
|
-
referrer:
|
|
98
|
-
referrerPolicy:
|
|
89
|
+
url: request.url,
|
|
90
|
+
path: request.path,
|
|
91
|
+
method: request.method,
|
|
92
|
+
headers: this.headersToObject(request.headers),
|
|
93
|
+
cache: request.cache,
|
|
94
|
+
destination: request.destination,
|
|
95
|
+
credentials: request.credentials,
|
|
96
|
+
integrity: request.integrity,
|
|
97
|
+
keepalive: request.keepalive,
|
|
98
|
+
mode: request.mode,
|
|
99
|
+
redirect: request.redirect,
|
|
100
|
+
referrer: request.referrer,
|
|
101
|
+
referrerPolicy: request.referrerPolicy,
|
|
99
102
|
};
|
|
100
103
|
|
|
101
104
|
if (!options.includeBody) {
|
|
@@ -103,7 +106,7 @@ class FetchResponseError<
|
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
// Optimize type checking by narrowing the type of the body
|
|
106
|
-
const bodyAsTextPromise =
|
|
109
|
+
const bodyAsTextPromise = request.text() as Promise<string>;
|
|
107
110
|
|
|
108
111
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
109
112
|
requestObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
@@ -111,22 +114,20 @@ class FetchResponseError<
|
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
private
|
|
115
|
-
private
|
|
116
|
-
private
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
includeBody: boolean;
|
|
121
|
-
}): Promise<FetchResponseObject> | FetchResponseObject {
|
|
117
|
+
private responseToObject(options: { includeBody: true }): Promise<FetchResponseObject>;
|
|
118
|
+
private responseToObject(options: { includeBody: false }): FetchResponseObject;
|
|
119
|
+
private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | FetchResponseObject;
|
|
120
|
+
private responseToObject(options: { includeBody: boolean }): Promise<FetchResponseObject> | FetchResponseObject {
|
|
121
|
+
const response = this.response;
|
|
122
|
+
|
|
122
123
|
const responseObject: FetchResponseObject = {
|
|
123
|
-
url:
|
|
124
|
-
type:
|
|
125
|
-
status:
|
|
126
|
-
statusText:
|
|
127
|
-
ok:
|
|
128
|
-
headers:
|
|
129
|
-
redirected:
|
|
124
|
+
url: response.url,
|
|
125
|
+
type: response.type,
|
|
126
|
+
status: response.status,
|
|
127
|
+
statusText: response.statusText,
|
|
128
|
+
ok: response.ok,
|
|
129
|
+
headers: this.headersToObject(response.headers),
|
|
130
|
+
redirected: response.redirected,
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
if (!options.includeBody) {
|
|
@@ -134,13 +135,17 @@ class FetchResponseError<
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
// Optimize type checking by narrowing the type of the body
|
|
137
|
-
const bodyAsTextPromise =
|
|
138
|
+
const bodyAsTextPromise = response.text() as Promise<string>;
|
|
138
139
|
|
|
139
140
|
return bodyAsTextPromise.then((bodyAsText) => {
|
|
140
141
|
responseObject.body = bodyAsText.length > 0 ? bodyAsText : null;
|
|
141
142
|
return responseObject;
|
|
142
143
|
});
|
|
143
144
|
}
|
|
145
|
+
|
|
146
|
+
private headersToObject(headers: typeof this.request.headers | typeof this.response.headers): HttpHeadersSchema {
|
|
147
|
+
return HttpHeaders.prototype.toObject.call(headers) as HttpHeadersSchema;
|
|
148
|
+
}
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|