@sapphire/fetch 2.3.2-next.fb067bb.0 โ†’ 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@sapphire/fetch@2.4.0](https://github.com/sapphiredev/utilities/compare/@sapphire/fetch@2.3.1...@sapphire/fetch@2.4.0) - (2022-06-05)
6
+
7
+ ## ๐Ÿ› Bug Fixes
8
+
9
+ - **deps:** Update all non-major dependencies ([50cd8de](https://github.com/sapphiredev/utilities/commit/50cd8dea593b6f5ae75571209456b3421e2ca59a))
10
+
11
+ ## ๐Ÿ“ Documentation
12
+
13
+ - Add @MajesticString as a contributor ([295b3e9](https://github.com/sapphiredev/utilities/commit/295b3e9849a4b0fe64074bae02f6426378a303c3))
14
+ - Add @Mzato0001 as a contributor ([c790ef2](https://github.com/sapphiredev/utilities/commit/c790ef25df2d7e22888fa9f8169167aa555e9e19))
15
+ - Add @NotKaskus as a contributor ([00da8f1](https://github.com/sapphiredev/utilities/commit/00da8f199137b9277119823f322d1f2d168d928a))
16
+ - Add @imranbarbhuiya as a contributor ([fb674c2](https://github.com/sapphiredev/utilities/commit/fb674c2c5594d41e71662263553dcb4bac9e37f4))
17
+ - Add @axisiscool as a contributor ([ce1aa31](https://github.com/sapphiredev/utilities/commit/ce1aa316871a88d3663efbdf2a42d3d8dfe6a27f))
18
+ - Add @dhruv-kaushikk as a contributor ([ebbf43f](https://github.com/sapphiredev/utilities/commit/ebbf43f63617daba96e72c50a234bf8b64f6ddc4))
19
+ - Add @Commandtechno as a contributor ([f1d69fa](https://github.com/sapphiredev/utilities/commit/f1d69fabe1ee0abe4be08b19e63dbec03102f7ce))
20
+ - Fix typedoc causing OOM crashes ([63ba41c](https://github.com/sapphiredev/utilities/commit/63ba41c4b6678554b1c7043a22d3296db4f59360))
21
+
22
+ ## ๐Ÿš€ Features
23
+
24
+ - **fetch:** Accept JS objects for the request body (#365) ([a3eee88](https://github.com/sapphiredev/utilities/commit/a3eee88f36192655c50bbde05ecca1e7d07c464d))
25
+
26
+ ## ๐Ÿงช Testing
27
+
28
+ - Fix fetch tests for Node 18 ([e92fb02](https://github.com/sapphiredev/utilities/commit/e92fb025cb1dcb5f33c1ea76fb25a4a1b5b37368))
29
+
5
30
  ## [2.3.1](https://github.com/sapphiredev/utilities/compare/@sapphire/fetch@2.3.0...@sapphire/fetch@2.3.1) (2022-04-01)
6
31
 
7
32
  **Note:** Version bump only for package @sapphire/fetch
@@ -141,8 +141,12 @@ var SapphireFetch = (() => {
141
141
  } else if (typeof type === "undefined") {
142
142
  type = "json" /* JSON */;
143
143
  }
144
+ let { body } = options;
145
+ if (body && typeof body === "object") {
146
+ body = JSON.stringify(body);
147
+ }
144
148
  const stringUrl = String(url);
145
- const result = await globalThis.fetch(stringUrl, options);
149
+ const result = await globalThis.fetch(stringUrl, { ...options, body });
146
150
  if (!result.ok)
147
151
  throw new QueryError(stringUrl, result.status, result, await result.clone().text());
148
152
  switch (type) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"sourcesContent":["export * from './lib/fetch';\nexport * from './lib/QueryError';\nexport * from './lib/types';\n","// 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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes } from './types';\n\n/**\n * Performs an HTTP(S) fetch\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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\nexport async function fetch(url: URL | string, options?: RequestInit | 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\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, options);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAMO,iCAAyB,MAAM;AAAA,IAY9B,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,YAAM,sBAAsB,kBAAkB,OAAO;AAXtC;AAEA;AAEA;AAEA;AAEhB;AAIC,WAAK,MAAM;AACX,WAAK,OAAO;AACZ,WAAK,OAAO;AACZ,WAAK,WAAW;AAChB,yBAAK,OAAQ;AAAA,IACd;AAAA,IAEO,SAAS;AACf,aAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,IACxD;AAAA,EACD;AAxBO;AAUN;;;ACbM,MAAW,mBAAX,kBAAW,sBAAX;AAON,gCAAO;AAMP,kCAAS;AAKT,gCAAO;AAIP,gCAAO;AAIP,kCAAS;AA1BQ;AAAA;AAgCX,MAAW,eAAX,kBAAW,kBAAX;AAKN,2BAAM;AAKN,4BAAO;AAKP,4BAAO;AAKP,2BAAM;AAKN,8BAAS;AAKT,+BAAU;AAKV,+BAAU;AAKV,6BAAQ;AAKR,6BAAQ;AA7CS;AAAA;AAqDX,MAAW,yBAAX,kBAAW,4BAAX;AAKN,0CAAW;AAMX,0CAAW;AAMX,2CAAY;AAMZ,0CAAW;AAMX,2CAAY;AAMZ,6CAAc;AAId,0CAAW;AAIX,2CAAY;AAMZ,yCAAU;AAMV,yCAAU;AAMV,0CAAW;AAMX,2CAAY;AAMZ,0CAAW;AAKX,gDAAiB;AAKjB,2CAAY;AAMZ,0CAAW;AAMX,2CAAY;AAKZ,0CAAW;AAKX,2CAAY;AAMZ,sCAAO;AAMP,4CAAa;AAMb,6CAAc;AAMd,yCAAU;AAKV,0CAAW;AAMX,2CAAY;AAMZ,2CAAY;AAMZ,2CAAY;AAMZ,0CAAW;AAMX,0CAAW;AAIX,2CAAY;AAMZ,qCAAM;AA9KW;AAAA;;;AC1DlB,uBAA4B,KAAmB,SAA0C,MAAyB;AACjH,QAAI,OAAO,YAAY,aAAa;AACnC,gBAAU,CAAC;AACX,aAAO;AAAA,IACR,WAAW,OAAO,YAAY,UAAU;AACvC,aAAO;AACP,gBAAU,CAAC;AAAA,IACZ,WAAW,OAAO,SAAS,aAAa;AACvC,aAAO;AAAA,IACR;AAGA,UAAM,YAAY,OAAO,GAAG;AAE5B,UAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,OAAO;AAClE,QAAI,CAAC,OAAO;AAAI,YAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,YAAQ;AAAA,WACF;AACJ,eAAO;AAAA,WACH;AACJ,eAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,WACxD;AACJ,eAAO,OAAO,KAAK;AAAA,WACf;AACJ,eAAO,OAAO,KAAK;AAAA,WACf;AACJ,eAAO,OAAO,KAAK;AAAA;AAEnB,cAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAAA,EAE3C;AA/BsB;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"sourcesContent":["export * from './lib/fetch';\nexport * from './lib/QueryError';\nexport * from './lib/types';\n","// 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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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?: BodyInit | 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 * @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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\n\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\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 (body && typeof body === 'object') {\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, { ...options, body });\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAMO,MAAM,aAAN,cAAyB,MAAM;AAAA,IAYrC,AAAO,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,YAAM,sBAAsB,kBAAkB,OAAO;AAXtD,0BAAgB;AAEhB,0BAAgB;AAEhB,0BAAgB;AAEhB,0BAAgB;AAEhB;AAIC,WAAK,MAAM;AACX,WAAK,OAAO;AACZ,WAAK,OAAO;AACZ,WAAK,WAAW;AAChB,yBAAK,OAAQ;AAAA,IACd;AAAA,IAEA,AAAO,SAAS;AACf,aAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,IACxD;AAAA,EACD;AAxBa;AAUZ;;;ACbM,MAAW,mBAAX,kBAAW,sBAAX;AAON,gCAAO;AAMP,kCAAS;AAKT,gCAAO;AAIP,gCAAO;AAIP,kCAAS;AA1BQ;AAAA;AAgCX,MAAW,eAAX,kBAAW,kBAAX;AAKN,2BAAM;AAKN,4BAAO;AAKP,4BAAO;AAKP,2BAAM;AAKN,8BAAS;AAKT,+BAAU;AAKV,+BAAU;AAKV,6BAAQ;AAKR,6BAAQ;AA7CS;AAAA;AAqDX,MAAW,yBAAX,kBAAW,4BAAX;AAKN,0CAAW;AAMX,0CAAW;AAMX,2CAAY;AAMZ,0CAAW;AAMX,2CAAY;AAMZ,6CAAc;AAId,0CAAW;AAIX,2CAAY;AAMZ,yCAAU;AAMV,yCAAU;AAMV,0CAAW;AAMX,2CAAY;AAMZ,0CAAW;AAKX,gDAAiB;AAKjB,2CAAY;AAMZ,0CAAW;AAMX,2CAAY;AAKZ,0CAAW;AAKX,2CAAY;AAMZ,sCAAO;AAMP,4CAAa;AAMb,6CAAc;AAMd,yCAAU;AAKV,0CAAW;AAMX,2CAAY;AAMZ,2CAAY;AAMZ,2CAAY;AAMZ,0CAAW;AAMX,0CAAW;AAIX,2CAAY;AAMZ,qCAAM;AA9KW;AAAA;;;ACzDlB,uBAA4B,KAAmB,SAA6C,MAAyB;AACpH,QAAI,OAAO,YAAY,aAAa;AACnC,gBAAU,CAAC;AACX,aAAO;AAAA,IACR,WAAW,OAAO,YAAY,UAAU;AACvC,aAAO;AACP,gBAAU,CAAC;AAAA,IACZ,WAAW,OAAO,SAAS,aAAa;AACvC,aAAO;AAAA,IACR;AAEA,QAAI,EAAE,SAAS;AAEf,QAAI,QAAQ,OAAO,SAAS,UAAU;AACrC,aAAO,KAAK,UAAU,IAAI;AAAA,IAC3B;AAGA,UAAM,YAAY,OAAO,GAAG;AAE5B,UAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,EAAE,GAAG,SAAS,KAAK,CAAC;AAC/E,QAAI,CAAC,OAAO;AAAI,YAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,YAAQ;AAAA,WACF;AACJ,eAAO;AAAA,WACH;AACJ,eAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,WACxD;AACJ,eAAO,OAAO,KAAK;AAAA,WACf;AACJ,eAAO,OAAO,KAAK;AAAA,WACf;AACJ,eAAO,OAAO,KAAK;AAAA;AAEnB,cAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAAA,EAE3C;AArCsB;","names":[]}
package/dist/index.js CHANGED
@@ -143,8 +143,12 @@ async function fetch(url, options, type) {
143
143
  } else if (typeof type === "undefined") {
144
144
  type = "json" /* JSON */;
145
145
  }
146
+ let { body } = options;
147
+ if (body && typeof body === "object") {
148
+ body = JSON.stringify(body);
149
+ }
146
150
  const stringUrl = String(url);
147
- const result = await globalThis.fetch(stringUrl, options);
151
+ const result = await globalThis.fetch(stringUrl, { ...options, body });
148
152
  if (!result.ok)
149
153
  throw new QueryError(stringUrl, result.status, result, await result.clone().text());
150
154
  switch (type) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"sourcesContent":["export * from './lib/fetch';\nexport * from './lib/QueryError';\nexport * from './lib/types';\n","// 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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes } from './types';\n\n/**\n * Performs an HTTP(S) fetch\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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\nexport async function fetch(url: URL | string, options?: RequestInit | 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\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, options);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAMO,+BAAyB,MAAM;AAAA,EAY9B,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,UAAM,sBAAsB,kBAAkB,OAAO;AAXtC;AAEA;AAEA;AAEA;AAEhB;AAIC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,uBAAK,OAAQ;AAAA,EACd;AAAA,EAEO,SAAS;AACf,WAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACxD;AACD;AAxBO;AAUN;;;ACbM,IAAW,mBAAX,kBAAW,sBAAX;AAON,8BAAO;AAMP,gCAAS;AAKT,8BAAO;AAIP,8BAAO;AAIP,gCAAS;AA1BQ;AAAA;AAgCX,IAAW,eAAX,kBAAW,kBAAX;AAKN,yBAAM;AAKN,0BAAO;AAKP,0BAAO;AAKP,yBAAM;AAKN,4BAAS;AAKT,6BAAU;AAKV,6BAAU;AAKV,2BAAQ;AAKR,2BAAQ;AA7CS;AAAA;AAqDX,IAAW,yBAAX,kBAAW,4BAAX;AAKN,wCAAW;AAMX,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAMZ,2CAAc;AAId,wCAAW;AAIX,yCAAY;AAMZ,uCAAU;AAMV,uCAAU;AAMV,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAKX,8CAAiB;AAKjB,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAKZ,wCAAW;AAKX,yCAAY;AAMZ,oCAAO;AAMP,0CAAa;AAMb,2CAAc;AAMd,uCAAU;AAKV,wCAAW;AAMX,yCAAY;AAMZ,yCAAY;AAMZ,yCAAY;AAMZ,wCAAW;AAMX,wCAAW;AAIX,yCAAY;AAMZ,mCAAM;AA9KW;AAAA;;;AC1DlB,qBAA4B,KAAmB,SAA0C,MAAyB;AACjH,MAAI,OAAO,YAAY,aAAa;AACnC,cAAU,CAAC;AACX,WAAO;AAAA,EACR,WAAW,OAAO,YAAY,UAAU;AACvC,WAAO;AACP,cAAU,CAAC;AAAA,EACZ,WAAW,OAAO,SAAS,aAAa;AACvC,WAAO;AAAA,EACR;AAGA,QAAM,YAAY,OAAO,GAAG;AAE5B,QAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,OAAO;AAClE,MAAI,CAAC,OAAO;AAAI,UAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,UAAQ;AAAA,SACF;AACJ,aAAO;AAAA,SACH;AACJ,aAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,SACxD;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA;AAEnB,YAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAE3C;AA/BsB;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"sourcesContent":["export * from './lib/fetch';\nexport * from './lib/QueryError';\nexport * from './lib/types';\n","// 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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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?: BodyInit | 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 * @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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\n\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\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 (body && typeof body === 'object') {\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, { ...options, body });\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAMO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAYrC,AAAO,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,UAAM,sBAAsB,kBAAkB,OAAO;AAXtD,wBAAgB;AAEhB,wBAAgB;AAEhB,wBAAgB;AAEhB,wBAAgB;AAEhB;AAIC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,uBAAK,OAAQ;AAAA,EACd;AAAA,EAEA,AAAO,SAAS;AACf,WAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACxD;AACD;AAxBa;AAUZ;;;ACbM,IAAW,mBAAX,kBAAW,sBAAX;AAON,8BAAO;AAMP,gCAAS;AAKT,8BAAO;AAIP,8BAAO;AAIP,gCAAS;AA1BQ;AAAA;AAgCX,IAAW,eAAX,kBAAW,kBAAX;AAKN,yBAAM;AAKN,0BAAO;AAKP,0BAAO;AAKP,yBAAM;AAKN,4BAAS;AAKT,6BAAU;AAKV,6BAAU;AAKV,2BAAQ;AAKR,2BAAQ;AA7CS;AAAA;AAqDX,IAAW,yBAAX,kBAAW,4BAAX;AAKN,wCAAW;AAMX,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAMZ,2CAAc;AAId,wCAAW;AAIX,yCAAY;AAMZ,uCAAU;AAMV,uCAAU;AAMV,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAKX,8CAAiB;AAKjB,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAKZ,wCAAW;AAKX,yCAAY;AAMZ,oCAAO;AAMP,0CAAa;AAMb,2CAAc;AAMd,uCAAU;AAKV,wCAAW;AAMX,yCAAY;AAMZ,yCAAY;AAMZ,yCAAY;AAMZ,wCAAW;AAMX,wCAAW;AAIX,yCAAY;AAMZ,mCAAM;AA9KW;AAAA;;;ACzDlB,qBAA4B,KAAmB,SAA6C,MAAyB;AACpH,MAAI,OAAO,YAAY,aAAa;AACnC,cAAU,CAAC;AACX,WAAO;AAAA,EACR,WAAW,OAAO,YAAY,UAAU;AACvC,WAAO;AACP,cAAU,CAAC;AAAA,EACZ,WAAW,OAAO,SAAS,aAAa;AACvC,WAAO;AAAA,EACR;AAEA,MAAI,EAAE,SAAS;AAEf,MAAI,QAAQ,OAAO,SAAS,UAAU;AACrC,WAAO,KAAK,UAAU,IAAI;AAAA,EAC3B;AAGA,QAAM,YAAY,OAAO,GAAG;AAE5B,QAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,EAAE,GAAG,SAAS,KAAK,CAAC;AAC/E,MAAI,CAAC,OAAO;AAAI,UAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,UAAQ;AAAA,SACF;AACJ,aAAO;AAAA,SACH;AACJ,aAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,SACxD;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA;AAEnB,YAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAE3C;AArCsB;","names":[]}
package/dist/index.mjs CHANGED
@@ -116,8 +116,12 @@ async function fetch(url, options, type) {
116
116
  } else if (typeof type === "undefined") {
117
117
  type = "json" /* JSON */;
118
118
  }
119
+ let { body } = options;
120
+ if (body && typeof body === "object") {
121
+ body = JSON.stringify(body);
122
+ }
119
123
  const stringUrl = String(url);
120
- const result = await globalThis.fetch(stringUrl, options);
124
+ const result = await globalThis.fetch(stringUrl, { ...options, body });
121
125
  if (!result.ok)
122
126
  throw new QueryError(stringUrl, result.status, result, await result.clone().text());
123
127
  switch (type) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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","// eslint-disable-next-line spaced-comment\n/// <reference lib=\"dom\" />\n\nimport { QueryError } from './QueryError';\nimport { FetchResultTypes } from './types';\n\n/**\n * Performs an HTTP(S) fetch\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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestInit, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\nexport async function fetch(url: URL | string, options?: RequestInit | 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\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, options);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAMO,+BAAyB,MAAM;AAAA,EAY9B,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,UAAM,sBAAsB,kBAAkB,OAAO;AAXtC;AAEA;AAEA;AAEA;AAEhB;AAIC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,uBAAK,OAAQ;AAAA,EACd;AAAA,EAEO,SAAS;AACf,WAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACxD;AACD;AAxBO;AAUN;;;ACbM,IAAW,mBAAX,kBAAW,sBAAX;AAON,8BAAO;AAMP,gCAAS;AAKT,8BAAO;AAIP,8BAAO;AAIP,gCAAS;AA1BQ;AAAA;AAgCX,IAAW,eAAX,kBAAW,kBAAX;AAKN,yBAAM;AAKN,0BAAO;AAKP,0BAAO;AAKP,yBAAM;AAKN,4BAAS;AAKT,6BAAU;AAKV,6BAAU;AAKV,2BAAQ;AAKR,2BAAQ;AA7CS;AAAA;AAqDX,IAAW,yBAAX,kBAAW,4BAAX;AAKN,wCAAW;AAMX,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAMZ,2CAAc;AAId,wCAAW;AAIX,yCAAY;AAMZ,uCAAU;AAMV,uCAAU;AAMV,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAKX,8CAAiB;AAKjB,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAKZ,wCAAW;AAKX,yCAAY;AAMZ,oCAAO;AAMP,0CAAa;AAMb,2CAAc;AAMd,uCAAU;AAKV,wCAAW;AAMX,yCAAY;AAMZ,yCAAY;AAMZ,yCAAY;AAMZ,wCAAW;AAMX,wCAAW;AAIX,yCAAY;AAMZ,mCAAM;AA9KW;AAAA;;;AC1DlB,qBAA4B,KAAmB,SAA0C,MAAyB;AACjH,MAAI,OAAO,YAAY,aAAa;AACnC,cAAU,CAAC;AACX,WAAO;AAAA,EACR,WAAW,OAAO,YAAY,UAAU;AACvC,WAAO;AACP,cAAU,CAAC;AAAA,EACZ,WAAW,OAAO,SAAS,aAAa;AACvC,WAAO;AAAA,EACR;AAGA,QAAM,YAAY,OAAO,GAAG;AAE5B,QAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,OAAO;AAClE,MAAI,CAAC,OAAO;AAAI,UAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,UAAQ;AAAA,SACF;AACJ,aAAO;AAAA,SACH;AACJ,aAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,SACxD;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA;AAEnB,YAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAE3C;AA/BsB;","names":[]}
1
+ {"version":3,"sources":["../src/lib/QueryError.ts","../src/lib/types.ts","../src/lib/fetch.ts"],"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","/**\n * The supported return types for the `fetch` method\n */\nexport const 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 const 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 const 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?: BodyInit | 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 * @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 optionsOrType Either the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript) or one of the {@link FetchResultTypes}\n * @param type Only needs to be provided if the second parameter are [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request) ({@link RequestInit} for TypeScript). One of the {@link FetchResultTypes} that will determine how the result is returned.\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 [`Buffer`](https://nodejs.org/api/buffer.html).\n * - When using `FetchResultTypes.Blob` the return type will be a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n * - When using `FetchResultTypes.Text` the return type will be a `string`\n * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)\n */\n\nexport async function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;\nexport async function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;\nexport async function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;\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 (body && typeof body === 'object') {\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, { ...options, body });\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAMO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAYrC,AAAO,YAAY,KAAa,MAAc,UAAoB,MAAc;AAC/E,UAAM,sBAAsB,kBAAkB,OAAO;AAXtD,wBAAgB;AAEhB,wBAAgB;AAEhB,wBAAgB;AAEhB,wBAAgB;AAEhB;AAIC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,uBAAK,OAAQ;AAAA,EACd;AAAA,EAEA,AAAO,SAAS;AACf,WAAO,mBAAK,UAAU,mBAAK,OAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACxD;AACD;AAxBa;AAUZ;;;ACbM,IAAW,mBAAX,kBAAW,sBAAX;AAON,8BAAO;AAMP,gCAAS;AAKT,8BAAO;AAIP,8BAAO;AAIP,gCAAS;AA1BQ;AAAA;AAgCX,IAAW,eAAX,kBAAW,kBAAX;AAKN,yBAAM;AAKN,0BAAO;AAKP,0BAAO;AAKP,yBAAM;AAKN,4BAAS;AAKT,6BAAU;AAKV,6BAAU;AAKV,2BAAQ;AAKR,2BAAQ;AA7CS;AAAA;AAqDX,IAAW,yBAAX,kBAAW,4BAAX;AAKN,wCAAW;AAMX,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAMZ,2CAAc;AAId,wCAAW;AAIX,yCAAY;AAMZ,uCAAU;AAMV,uCAAU;AAMV,wCAAW;AAMX,yCAAY;AAMZ,wCAAW;AAKX,8CAAiB;AAKjB,yCAAY;AAMZ,wCAAW;AAMX,yCAAY;AAKZ,wCAAW;AAKX,yCAAY;AAMZ,oCAAO;AAMP,0CAAa;AAMb,2CAAc;AAMd,uCAAU;AAKV,wCAAW;AAMX,yCAAY;AAMZ,yCAAY;AAMZ,yCAAY;AAMZ,wCAAW;AAMX,wCAAW;AAIX,yCAAY;AAMZ,mCAAM;AA9KW;AAAA;;;ACzDlB,qBAA4B,KAAmB,SAA6C,MAAyB;AACpH,MAAI,OAAO,YAAY,aAAa;AACnC,cAAU,CAAC;AACX,WAAO;AAAA,EACR,WAAW,OAAO,YAAY,UAAU;AACvC,WAAO;AACP,cAAU,CAAC;AAAA,EACZ,WAAW,OAAO,SAAS,aAAa;AACvC,WAAO;AAAA,EACR;AAEA,MAAI,EAAE,SAAS;AAEf,MAAI,QAAQ,OAAO,SAAS,UAAU;AACrC,WAAO,KAAK,UAAU,IAAI;AAAA,EAC3B;AAGA,QAAM,YAAY,OAAO,GAAG;AAE5B,QAAM,SAAmB,MAAM,WAAW,MAAM,WAAW,EAAE,GAAG,SAAS,KAAK,CAAC;AAC/E,MAAI,CAAC,OAAO;AAAI,UAAM,IAAI,WAAW,WAAW,OAAO,QAAQ,QAAQ,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAElG,UAAQ;AAAA,SACF;AACJ,aAAO;AAAA,SACH;AACJ,aAAO,OAAO,KAAK,MAAO,OAAM,OAAO,KAAK,GAAG,YAAY,CAAC;AAAA,SACxD;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA,SACf;AACJ,aAAO,OAAO,KAAK;AAAA;AAEnB,YAAM,IAAI,MAAM,iBAAiB,OAAO;AAAA;AAE3C;AArCsB;","names":[]}
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference lib="dom" />
3
- import { FetchResultTypes } from './types';
3
+ import { FetchResultTypes, type RequestOptions } from './types';
4
4
  /**
5
5
  * Performs an HTTP(S) fetch
6
6
  * @param url The URL to send the request to. Can be either a `string` or an `URL` object.
@@ -15,14 +15,14 @@ import { FetchResultTypes } from './types';
15
15
  * - When using `FetchResultTypes.Result` the return type will be a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) ({@link Response} in typescript)
16
16
  */
17
17
  export declare function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;
18
- export declare function fetch<R>(url: URL | string, options: RequestInit, type?: FetchResultTypes.JSON): Promise<R>;
18
+ export declare function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;
19
19
  export declare function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;
20
- export declare function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Buffer): Promise<Buffer>;
20
+ export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;
21
21
  export declare function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;
22
- export declare function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Blob): Promise<Blob>;
22
+ export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;
23
23
  export declare function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;
24
- export declare function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Text): Promise<string>;
24
+ export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;
25
25
  export declare function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;
26
- export declare function fetch(url: URL | string, options: RequestInit, type: FetchResultTypes.Result): Promise<Response>;
27
- export declare function fetch<R>(url: URL | string, options: RequestInit, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;
26
+ export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;
27
+ export declare function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Response | Blob | Buffer | string | R>;
28
28
  //# sourceMappingURL=fetch.d.ts.map
@@ -260,4 +260,7 @@ export declare const enum FetchMediaContentTypes {
260
260
  */
261
261
  XML = "application/xml"
262
262
  }
263
+ export interface RequestOptions extends Omit<RequestInit, 'body'> {
264
+ body?: BodyInit | Record<any, any>;
265
+ }
263
266
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/fetch",
3
- "version": "2.3.2-next.fb067bb.0",
3
+ "version": "2.4.0",
4
4
  "description": "Tiny wrapper around cross-fetch (for NodeJS) and window.fetch (for Browsers) for improved TypeScript and data type support",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "access": "public"
59
59
  },
60
60
  "devDependencies": {
61
- "tsup": "^5.12.7",
62
- "typescript": "^4.6.4"
61
+ "tsup": "^6.0.1",
62
+ "typescript": "^4.7.3"
63
63
  }
64
64
  }