@sapphire/fetch 3.0.6-next.ff2c792d → 4.0.0-pr-935.7da5c8bb

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,KAAA;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAM,CAAA;AAAA,EAY9B,WAAY,CAAA,GAAA,EAAa,IAAc,EAAA,QAAA,EAAoB,IAAc,EAAA;AAC/E,IAAA,KAAA,CAAM,CAAsB,mBAAA,EAAA,GAAG,CAAe,YAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAXtD;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAEhB,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAIC,IAAA,IAAA,CAAK,GAAM,GAAA,GAAA;AACX,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA;AAChB,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;AAAA;AACd,EAEO,MAAS,GAAA;AACf,IAAA,OAAO,mBAAK,KAAU,CAAA,IAAA,YAAA,CAAA,IAAA,EAAK,OAAQ,IAAK,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA,CAAA;AAAA;AAEzD,CAAA;AAdC,KAAA,GAAA,IAAA,OAA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AiB,cAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAAA;AAE3C;AAxCsB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AAgDtB,SAAS,oBAAoB,KAAyB,EAAA;AAErD,EAAI,IAAA,OAAO,KAAU,KAAA,QAAA,EAAiB,OAAA,KAAA;AAEtC,EAAA,IAAI,OAAO,MAAW,KAAA,WAAA,IAAe,OAAO,QAAS,CAAA,KAAK,GAAU,OAAA,KAAA;AAGpE,EAAI,IAAA,KAAA,KAAU,MAAa,OAAA,IAAA;AAE3B,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,KAAA,CAAA,EAAkB,OAAA,IAAA;AAE5C,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,MAAA,EAAe,OAAA,IAAA;AAEzC,EAAA,IAAI,YAAY,KAAS,IAAA,OAAO,KAAM,CAAA,MAAA,KAAW,YAAmB,OAAA,IAAA;AAEpE,EAAA,IAAI,MAAM,OAAQ,CAAA,KAAK,GAAU,OAAA,KAAA,CAAM,MAAM,mBAAmB,CAAA;AAGhE,EAAO,OAAA,KAAA;AACR;AAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.cjs","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,KAAA;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;AAAA,EAY9B,WAAA,CAAY,GAAA,EAAa,IAAA,EAAc,QAAA,EAAoB,IAAA,EAAc;AAC/E,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,GAAG,CAAA,YAAA,EAAe,IAAI,CAAA,CAAA,CAAG,CAAA;AAXtD;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,KAAA,CAAA;AAEhB;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA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KAAK,GAAG,OAAO,KAAA,CAAM,MAAM,mBAAmB,CAAA;AAGhE,EAAA,OAAO,KAAA;AACR;AAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.cjs","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;AAAA,IAAA,KAAA;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAM,CAAA;AAAA,EAY9B,WAAY,CAAA,GAAA,EAAa,IAAc,EAAA,QAAA,EAAoB,IAAc,EAAA;AAC/E,IAAA,KAAA,CAAM,CAAsB,mBAAA,EAAA,GAAG,CAAe,YAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAXtD;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAEhB;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAEhB,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAIC,IAAA,IAAA,CAAK,GAAM,GAAA,GAAA;AACX,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA;AAChB,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;AAAA;AACd,EAEO,MAAS,GAAA;AACf,IAAA,OAAO,mBAAK,KAAU,CAAA,IAAA,YAAA,CAAA,IAAA,EAAK,OAAQ,IAAK,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA,CAAA;AAAA;AAEzD,CAAA;AAdC,KAAA,GAAA,IAAA,OAAA,EAA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AAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAAA;AAE3C;AAxCsB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AAgDtB,SAAS,oBAAoB,KAAyB,EAAA;AAErD,EAAI,IAAA,OAAO,KAAU,KAAA,QAAA,EAAiB,OAAA,KAAA;AAEtC,EAAA,IAAI,OAAO,MAAW,KAAA,WAAA,IAAe,OAAO,QAAS,CAAA,KAAK,GAAU,OAAA,KAAA;AAGpE,EAAI,IAAA,KAAA,KAAU,MAAa,OAAA,IAAA;AAE3B,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,KAAA,CAAA,EAAkB,OAAA,IAAA;AAE5C,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,MAAA,EAAe,OAAA,IAAA;AAEzC,EAAA,IAAI,YAAY,KAAS,IAAA,OAAO,KAAM,CAAA,MAAA,KAAW,YAAmB,OAAA,IAAA;AAEpE,EAAA,IAAI,MAAM,OAAQ,CAAA,KAAK,GAAU,OAAA,KAAA,CAAM,MAAM,mBAAmB,CAAA;AAGhE,EAAO,OAAA,KAAA;AACR;AAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.mjs","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;AAAA,IAAA,KAAA;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;AAAA,EAY9B,WAAA,CAAY,GAAA,EAAa,IAAA,EAAc,QAAA,EAAoB,IAAA,EAAc;AAC/E,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,GAAG,CAAA,YAAA,EAAe,IAAI,CAAA,CAAA,CAAG,CAAA;AAXtD;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,KAAA,CAAA;AAEhB;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;A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AG,OAAO,KAAA,CAAM,MAAM,mBAAmB,CAAA;AAGhE,EAAA,OAAO,KAAA;AACR;AAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.mjs","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;;;;EAAA,IAAA,KAAA;EAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAM,CAAA;EAAA,EAY9B,WAAY,CAAA,GAAA,EAAa,IAAc,EAAA,QAAA,EAAoB,IAAc,EAAA;EAC/E,IAAA,KAAA,CAAM,CAAsB,mBAAA,EAAA,GAAG,CAAe,YAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;EAXtD;EAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;EAEhB;EAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;EAEhB;EAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;EAEhB;EAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;EAEhB,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;EAIC,IAAA,IAAA,CAAK,GAAM,GAAA,GAAA;EACX,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;EACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;EACZ,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA;EAChB,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;EAAA;EACd,EAEO,MAAS,GAAA;EACf,IAAA,OAAO,mBAAK,KAAU,CAAA,IAAA,YAAA,CAAA,IAAA,EAAK,OAAQ,IAAK,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA,CAAA;EAAA;EAEzD,CAAA;EAdC,KAAA,GAAA,IAAA,OAAA,EAAA;EA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EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;EAAA;EAE3C;EAxCsB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;EAgDtB,SAAS,oBAAoB,KAAyB,EAAA;EAErD,EAAI,IAAA,OAAO,KAAU,KAAA,QAAA,EAAiB,OAAA,KAAA;EAEtC,EAAA,IAAI,OAAO,MAAW,KAAA,WAAA,IAAe,OAAO,QAAS,CAAA,KAAK,GAAU,OAAA,KAAA;EAGpE,EAAI,IAAA,KAAA,KAAU,MAAa,OAAA,IAAA;EAE3B,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,KAAA,CAAA,EAAkB,OAAA,IAAA;EAE5C,EAAI,IAAA,KAAA,CAAM,WAAgB,KAAA,MAAA,EAAe,OAAA,IAAA;EAEzC,EAAA,IAAI,YAAY,KAAS,IAAA,OAAO,KAAM,CAAA,MAAA,KAAW,YAAmB,OAAA,IAAA;EAEpE,EAAA,IAAI,MAAM,OAAQ,CAAA,KAAK,GAAU,OAAA,KAAA,CAAM,MAAM,mBAAmB,CAAA;EAGhE,EAAO,OAAA,KAAA;EACR;EAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.global.js","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/QueryError.ts","../../src/lib/types.ts","../../src/lib/fetch.ts"],"names":["FetchResultTypes","FetchMethods","FetchMediaContentTypes"],"mappings":";;;;;;;;;;;;;;;;EAAA,IAAA,KAAA;EAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;EAAA,EAY9B,WAAA,CAAY,GAAA,EAAa,IAAA,EAAc,QAAA,EAAoB,IAAA,EAAc;EAC/E,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,GAAG,CAAA,YAAA,EAAe,IAAI,CAAA,CAAA,CAAG,CAAA;EAXtD;EAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,KAAA,CAAA;EAEhB;EAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;EA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G,OAAO,KAAA,CAAM,MAAM,mBAAmB,CAAA;EAGhE,EAAA,OAAO,KAAA;EACR;EAnBS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"index.global.js","sourcesContent":["// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The QueryError class which is thrown by the `fetch` method\n */\nexport class QueryError extends Error {\n\t/** The requested url. */\n\tpublic readonly url: string;\n\t/** The HTTP status code. */\n\tpublic readonly code: number;\n\t/** The returned response body as a string */\n\tpublic readonly body: string;\n\t/** The original {@link Response} object */\n\tpublic readonly response: Response;\n\n\t#json: unknown;\n\n\tpublic constructor(url: string, code: number, response: Response, body: string) {\n\t\tsuper(`Failed to request '${url}' with code ${code}.`);\n\t\tthis.url = url;\n\t\tthis.code = code;\n\t\tthis.body = body;\n\t\tthis.response = response;\n\t\tthis.#json = null;\n\t}\n\n\tpublic toJSON() {\n\t\treturn this.#json ?? (this.#json = JSON.parse(this.body));\n\t}\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\n/**\n * The supported return types for the `fetch` method\n */\nexport enum FetchResultTypes {\n\t/**\n\t * Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).\n\t *\n\t * You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define\n\t * the JSON structure, otherwise the result will be `unknown`.\n\t */\n\tJSON = 'json',\n\t/**\n\t * Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).\n\t * @remark Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.\n\t * If you use this type in a Browsers environment a {@link ReferenceError `ReferenceError: Buffer is not defined`} will be thrown!\n\t */\n\tBuffer = 'buffer',\n\t/**\n\t * Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\t * @remark For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.\n\t */\n\tBlob = 'blob',\n\t/**\n\t * Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).\n\t */\n\tText = 'text',\n\t/**\n\t * Returns the entire response and doesn't parse the `body` in any way.\n\t */\n\tResult = 'result'\n}\n\n/**\n * The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n */\nexport enum FetchMethods {\n\t/**\n\t * The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.\n\t * @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)\n\t */\n\tGet = 'GET',\n\t/**\n\t * The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get `GET`} request, but without the response body.\n\t * @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)\n\t */\n\tHead = 'HEAD',\n\t/**\n\t * The `POST` method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.\n\t * @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)\n\t */\n\tPost = 'POST',\n\t/**\n\t * The `PUT` method replaces all current representations of the target resource with the request payload.\n\t * @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)\n\t */\n\tPut = 'PUT',\n\t/**\n\t * The `DELETE` method deletes the specified resource.\n\t * @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)\n\t */\n\tDelete = 'DELETE',\n\t/**\n\t * The `CONNECT` method establishes a tunnel to the server identified by the target resource\n\t * @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)\n\t */\n\tConnect = 'CONNECT',\n\t/**\n\t * The `OPTIONS` method is used to describe the communication options for the target resource.\n\t * @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)\n\t */\n\tOptions = 'OPTIONS',\n\t/**\n\t * The `TRACE` method performs a message loop-back test along the path to the target resource.\n\t * @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)\n\t */\n\tTrace = 'TRACE',\n\t/**\n\t * The `PATCH` method is used to apply partial modifications to a resource.\n\t * @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)\n\t */\n\tPatch = 'PATCH'\n}\n\n/**\n * A list of common [Media Content Types](https://www.iana.org/assignments/media-types/media-types.xhtml) as defined by the [IANA](https://www.iana.org/).\n * Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type\n * Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).\n */\nexport enum FetchMediaContentTypes {\n\t/**\n\t * The `audio/aac` media content type.\n\t * @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)\n\t */\n\tAudioAac = 'audio/aac',\n\t/**\n\t * The `audio/mp4` media content type.\n\t * @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tAudioMp4 = 'audio/mp4',\n\t/**\n\t * The `audio/mpeg` media content type.\n\t * @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)\n\t * @see [[RFC3003](https://www.iana.org/go/rfc3003)]\n\t */\n\tAudioMpeg = 'audio/mpeg',\n\t/**\n\t * The `audio/ogg` media content type.\n\t * @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tAudioOgg = 'audio/ogg',\n\t/**\n\t * The `audio/opus` media content type.\n\t * @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)\n\t * @see [[RFC7587](https://www.iana.org/go/rfc7587)]\n\t */\n\tAudioOpus = 'audio/opus',\n\t/**\n\t * The `audio/vorbis` media content type.\n\t * @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)\n\t * @see [[RFC5215](https://www.iana.org/go/rfc5215)]\n\t */\n\tAudioVorbis = 'audio/vorbis',\n\t/**\n\t * The `audio/wav` media content type.\n\t */\n\tAudioWav = 'audio/wav',\n\t/**\n\t * The `audio/webm` media content type.\n\t */\n\tAudioWebm = 'audio/webm',\n\t/**\n\t * The `font/otf` media content type.\n\t * @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontOtf = 'font/otf',\n\t/**\n\t * The `font/ttf` media content type.\n\t * @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontTtf = 'font/ttf',\n\t/**\n\t * The `font/woff` media content type.\n\t * @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff = 'font/woff',\n\t/**\n\t * The `font/woff2` media content type.\n\t * @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)\n\t * @see [[RFC8081](https://www.iana.org/go/rfc8081)]\n\t */\n\tFontWoff2 = 'font/woff2',\n\t/**\n\t * The `multipart/form-data` media content type.\n\t * @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)\n\t * @see [[RFC7578](https://www.iana.org/go/rfc7578)]\n\t */\n\tFormData = 'multipart/form-data',\n\t/**\n\t * The `x-www-form-urlencoded` media content type.\n\t * @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)\n\t */\n\tFormURLEncoded = 'application/x-www-form-urlencoded',\n\t/**\n\t * The `image/apng` media content type.\n\t * @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)\n\t */\n\tImageAPNG = 'image/apng',\n\t/**\n\t * The `image/gif` media content type.\n\t * @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageGIF = 'image/gif',\n\t/**\n\t * The `image/jpeg` media content type.\n\t * @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]\n\t */\n\tImageJPEG = 'image/jpeg',\n\t/**\n\t * The `image/png` media content type.\n\t * @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)\n\t */\n\tImagePNG = 'image/png',\n\t/**\n\t * The `image/webp` media content type.\n\t * @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)\n\t */\n\tImageWEBP = 'image/webp',\n\t/**\n\t * The `application/json` media content type.\n\t * @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)\n\t * @see [[RFC8259](https://www.iana.org/go/rfc8259)]\n\t */\n\tJSON = 'application/json',\n\t/**\n\t * The `application/javascript` media content type.\n\t * @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)\n\t * @see [[RFC4329](https://www.iana.org/go/rfc4329)]\n\t */\n\tJavaScript = 'application/javascript',\n\t/**\n\t * The `application/octet-stream` media content type.\n\t * @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)\n\t * @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]\n\t */\n\tOctetStream = 'application/octet-stream',\n\t/**\n\t * The `text/css` media content type.\n\t * @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)\n\t * @see [[RFC2318](https://www.iana.org/go/rfc2318)]\n\t */\n\tTextCSS = 'text/css',\n\t/**\n\t * The `text/HTML` media content type.\n\t * @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)\n\t */\n\tTextHTML = 'text/html',\n\t/**\n\t * The `text/plain` media content type.\n\t * @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)\n\t * @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]\n\t */\n\tTextPlain = 'text/plain',\n\t/**\n\t * The `video/h264` media content type.\n\t * @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)\n\t * @see [[RFC6184](https://www.iana.org/go/rfc6184)]\n\t */\n\tVideoH264 = 'video/h264',\n\t/**\n\t * The `video/h265` media content type.\n\t * @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)\n\t * @see [[RFC7798](https://www.iana.org/go/rfc7798)]\n\t */\n\tVideoH265 = 'video/h265',\n\t/**\n\t * The `video/mp4` media content type.\n\t * @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)\n\t * @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]\n\t */\n\tVideoMp4 = 'video/mp4',\n\t/**\n\t * The `video/ogg` media content type.\n\t * @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)\n\t * @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]\n\t */\n\tVideoOgg = 'video/ogg',\n\t/**\n\t * The `video/webm` media content type.\n\t */\n\tVideoWebm = 'video/webm',\n\t/**\n\t * The `application/xml` media content type.\n\t * @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)\n\t * @see [[RFC7303](https://www.iana.org/go/rfc7303)]\n\t */\n\tXML = 'application/xml'\n}\n\nexport interface RequestOptions extends Omit<RequestInit, 'body'> {\n\tbody?: RequestInit['body'] | Record<any, any>;\n}\n","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes, type RequestOptions } from './types';\n\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://nodejs.org/api/buffer.html `Buffer`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns A {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`} of the response body\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The response body as a raw `string`.\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The raw {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript).\n */\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\n/**\n * Performs an HTTP(S) fetch\n *\n * @param url - The URL to send the request to. Can be either a `string` or an `URL` object.\n * `url` should be an absolute url, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.\n * @param options - The {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Request `Request`} ({@link RequestInit} for TypeScript)\n * @param type - The {@link FetchResultTypes}\n *\n * @returns The return type is determined by the provided `type`.\n * - When using `FetchResultTypes.JSON` then the return type is `unknown` by default. The type should be specified by filling in the generic type of the function, or casting the result.\n * - When using `FetchResultTypes.Buffer` the return type will be {@linkplain https://nodejs.org/api/buffer.html `Buffer`}.\n * - When using `FetchResultTypes.Blob` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Blob `Blob`}.\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a {@linkplain https://developer.mozilla.org/en-US/docs/Web/API/Response `Response`} ({@link Response} in typescript)\n */\nexport async function fetch(url: URL | string, options?: RequestOptions | FetchResultTypes, type?: FetchResultTypes) {\n\tif (typeof options === 'undefined') {\n\t\toptions = {};\n\t\ttype = FetchResultTypes.JSON;\n\t} else if (typeof options === 'string') {\n\t\ttype = options;\n\t\toptions = {};\n\t} else if (typeof type === 'undefined') {\n\t\ttype = FetchResultTypes.JSON;\n\t}\n\n\tlet { body } = options;\n\n\tif (shouldJsonStringify(body)) {\n\t\tbody = JSON.stringify(body);\n\t}\n\n\t// Transform the URL to a String, in case an URL object was passed\n\tconst stringUrl = String(url);\n\n\tconst result: Response = await globalThis.fetch(stringUrl, {\n\t\t...options,\n\t\tbody: body as RequestInit['body']\n\t});\n\tif (!result.ok) throw new QueryError(stringUrl, result.status, result, await result.clone().text());\n\n\tswitch (type) {\n\t\tcase FetchResultTypes.Result:\n\t\t\treturn result;\n\t\tcase FetchResultTypes.Buffer:\n\t\t\treturn Buffer.from(await (await result.blob()).arrayBuffer());\n\t\tcase FetchResultTypes.Blob:\n\t\t\treturn result.blob();\n\t\tcase FetchResultTypes.JSON:\n\t\t\treturn result.json();\n\t\tcase FetchResultTypes.Text:\n\t\t\treturn result.text();\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown type \"${type}\"`);\n\t}\n}\n\n/**\n * Determines whether a value should be stringified as JSON.\n *\n * @param value - The value to check.\n * @returns A boolean indicating whether the value should be stringified as JSON.\n */\nfunction shouldJsonStringify(value: unknown): boolean {\n\t// If the value is not an object, it should not be stringified\n\tif (typeof value !== 'object') return false;\n\t// Buffers should not be stringified\n\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) return false;\n\n\t// null object\n\tif (value === null) return true;\n\t// Object.create(null)\n\tif (value.constructor === undefined) return true;\n\t// Plain objects\n\tif (value.constructor === Object) return true;\n\t// Has toJSON method\n\tif ('toJSON' in value && typeof value.toJSON === 'function') return true;\n\t// Array of items, check if every item in the array is serializable\n\tif (Array.isArray(value)) return value.every(shouldJsonStringify);\n\n\t// Anything else (such as streams or unserializables)\n\treturn false;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/fetch",
3
- "version": "3.0.6-next.ff2c792d",
3
+ "version": "4.0.0-pr-935.7da5c8bb",
4
4
  "description": "Tiny wrapper around globalThis.fetch for improved TypeScript and data type support",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -61,13 +61,13 @@
61
61
  "access": "public"
62
62
  },
63
63
  "devDependencies": {
64
- "@favware/cliff-jumper": "^5.0.0",
65
- "@vitest/coverage-v8": "^2.1.8",
66
- "tsup": "^8.3.5",
67
- "tsx": "^4.19.2",
64
+ "@favware/cliff-jumper": "^6.0.0",
65
+ "@vitest/coverage-v8": "^3.2.4",
66
+ "tsup": "^8.5.0",
67
+ "tsx": "^4.20.6",
68
68
  "typedoc": "^0.26.11",
69
69
  "typedoc-json-parser": "^10.2.0",
70
70
  "typescript": "~5.4.5",
71
- "vitest": "^2.1.8"
71
+ "vitest": "^3.2.4"
72
72
  }
73
73
  }