@sapphire/fetch 3.0.6-next.fff340cc → 4.0.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 +51 -0
- package/README.md +30 -32
- package/dist/index.d.mts +439 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +400 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -29
- package/dist/cjs/index.cjs +0 -154
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -410
- package/dist/esm/index.d.mts +0 -410
- package/dist/esm/index.mjs +0 -148
- package/dist/esm/index.mjs.map +0 -1
- package/dist/iife/index.global.js +0 -159
- package/dist/iife/index.global.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
# [@sapphire/fetch@4.0.0](https://github.com/sapphiredev/utilities/compare/@sapphire/fetch@3.0.5...@sapphire/fetch@4.0.0) - (2026-11-15)
|
|
6
|
+
|
|
7
|
+
## 🏠 Refactor
|
|
8
|
+
|
|
9
|
+
- **eslint:** Allow globals to be used ([3f08d87](https://github.com/sapphiredev/utilities/commit/3f08d87496c885a851cb48ec59a5d8c8822c5284))
|
|
10
|
+
- Revert back to using globals instead of `node:X` imports ([25e18d0](https://github.com/sapphiredev/utilities/commit/25e18d0bf975e311d1baae2e5645355f4ffbdd0d))
|
|
11
|
+
- **tsdown:** Integrate nodeGlobals plugin in configs ([84502f6](https://github.com/sapphiredev/utilities/commit/84502f6bdaf7a031961a969f5602b509862408bf))
|
|
12
|
+
- Update to ESLint v10 ([991c466](https://github.com/sapphiredev/utilities/commit/991c4665ff10d9efa32d34cab134570fa7d2dd22))
|
|
13
|
+
- ***:** All round repository upgrade ([44c5c90](https://github.com/sapphiredev/utilities/commit/44c5c900ecd6f9164e073c09630a7800d69f745a))
|
|
14
|
+
- 💥 **BREAKING CHANGE:** Build system has been changed from tsup to tsdown. There may be unexpected changes in the build output.
|
|
15
|
+
- 💥 **BREAKING CHANGE:** CJS support has been entirely dropped, all packages in this repository are now ESM-only.
|
|
16
|
+
- 💥 **BREAKING CHANGE:** The `tslib` dependency has been removed from all packages.
|
|
17
|
+
- 💥 **BREAKING CHANGE:** TypeScript has been internally updated to v7.
|
|
18
|
+
- ***:** All round repository upgrade ([a58424e](https://github.com/sapphiredev/utilities/commit/a58424eadcea4990a730b0f89ce2d45f5d896c65))
|
|
19
|
+
- 💥 **BREAKING CHANGE:** Build system has been changed from tsup to tsdown. There may be unexpected changes in the build output.
|
|
20
|
+
- 💥 **BREAKING CHANGE:** CJS support has been entirely dropped, all packages in this repository are now ESM-only.
|
|
21
|
+
- 💥 **BREAKING CHANGE:** The `tslib` dependency has been removed from all packages.
|
|
22
|
+
- 💥 **BREAKING CHANGE:** TypeScript has been internally updated to v7.
|
|
23
|
+
|
|
24
|
+
## 🐛 Bug Fixes
|
|
25
|
+
|
|
26
|
+
- **fetch:** Ensure Buffer check is safe in shouldJsonStringify ([8c2f728](https://github.com/sapphiredev/utilities/commit/8c2f7289d49e57bc00965caf2dd943102cc298d3))
|
|
27
|
+
- **deps:** Update all non-major dependencies ([09c1811](https://github.com/sapphiredev/utilities/commit/09c1811dae117f501f4e03b2015d8288e28734f8)) ([#982](https://github.com/sapphiredev/utilities/pull/982) by @renovate[bot])
|
|
28
|
+
- **deps:** Update all non-major dependencies ([72499d9](https://github.com/sapphiredev/utilities/commit/72499d99a9feb107fd3dccea601da462f1f725c1)) ([#980](https://github.com/sapphiredev/utilities/pull/980) by @renovate[bot])
|
|
29
|
+
- **deps:** Update all non-major dependencies ([e6d4bac](https://github.com/sapphiredev/utilities/commit/e6d4bac47e65e9e0ec95ebaaa1b679cfc01bd107)) ([#953](https://github.com/sapphiredev/utilities/pull/953) by @renovate[bot])
|
|
30
|
+
- **deps:** Update all non-major dependencies ([3f9fe93](https://github.com/sapphiredev/utilities/commit/3f9fe93b770479fd72b7fd56f476244c040fcb41)) ([#952](https://github.com/sapphiredev/utilities/pull/952) by @renovate[bot])
|
|
31
|
+
- **deps:** Update all non-major dependencies ([841436f](https://github.com/sapphiredev/utilities/commit/841436f1b501f468b002790283a25298561768d6)) ([#946](https://github.com/sapphiredev/utilities/pull/946) by @renovate[bot])
|
|
32
|
+
- **deps:** Update all non-major dependencies ([636a5ee](https://github.com/sapphiredev/utilities/commit/636a5eed0939fd96a82213bf8459846aedd54037)) ([#897](https://github.com/sapphiredev/utilities/pull/897) by @renovate[bot])
|
|
33
|
+
- **deps:** Update all non-major dependencies ([4bc5591](https://github.com/sapphiredev/utilities/commit/4bc55911f95456a2caee10a3588c7b5f1542fb00)) ([#879](https://github.com/sapphiredev/utilities/pull/879) by @renovate[bot])
|
|
34
|
+
- **deps:** Update all non-major dependencies ([bc2f01c](https://github.com/sapphiredev/utilities/commit/bc2f01ce7d6932c9a0e02faa7cc081ecbae9640d)) ([#869](https://github.com/sapphiredev/utilities/pull/869) by @renovate[bot])
|
|
35
|
+
|
|
36
|
+
## 📝 Documentation
|
|
37
|
+
|
|
38
|
+
- **fetch:** Remove redundant import examples in README ([3857095](https://github.com/sapphiredev/utilities/commit/3857095117fe20d642bb4ce86c48c50a9cae4a45))
|
|
39
|
+
- **readme:** Update feature descriptions across packages ([302730a](https://github.com/sapphiredev/utilities/commit/302730a5b8eccb763b7b9761c3de1db9d3857394))
|
|
40
|
+
- Update typedoc to proper tsdoc ([1d29dd6](https://github.com/sapphiredev/utilities/commit/1d29dd63bc2ffd1ea25093ca2d0a9ab7d6efc9e9))
|
|
41
|
+
- **fetch:** Add TypeScript configuration instructions ([44085de](https://github.com/sapphiredev/utilities/commit/44085def19b1f750e58e668e431760853a9da69b))
|
|
42
|
+
|
|
43
|
+
## 🚀 Features
|
|
44
|
+
|
|
45
|
+
- Target es2024 when bundling ([293e6b9](https://github.com/sapphiredev/utilities/commit/293e6b9eddbed5db178017d5ddedaaad0cfb3395))
|
|
46
|
+
- 💥 **BREAKING CHANGE:** if your project is not full ES2024 compatible this new version will not work
|
|
47
|
+
- Update eslint rules ([901aca9](https://github.com/sapphiredev/utilities/commit/901aca995e28bf5f4b343b441ab658d9c6511195))
|
|
48
|
+
- 💥 **BREAKING CHANGE:** ESLint has been updated to v10
|
|
49
|
+
- 💥 **BREAKING CHANGE:** ESLint configuration has been changed to a flat config
|
|
50
|
+
- 💥 **BREAKING CHANGE:** Our ESLint config is now a small layer on top of [eslint-config-neon](https://www.npmjs.com/package/eslint-config-neon) which brings a LOT more rules and stricter linting.
|
|
51
|
+
|
|
52
|
+
## 🪞 Styling
|
|
53
|
+
|
|
54
|
+
- Apply linting rules ([d049345](https://github.com/sapphiredev/utilities/commit/d049345fd19a1bcbf8e466c1f9141ef6ecc32dc4))
|
|
55
|
+
|
|
5
56
|
# [@sapphire/fetch@3.0.4](https://github.com/sapphiredev/utilities/compare/@sapphire/fetch@3.0.3...@sapphire/fetch@3.0.4) - (2024-11-02)
|
|
6
57
|
|
|
7
58
|
## 🐛 Bug Fixes
|
package/README.md
CHANGED
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
**Table of Contents**
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
17
|
+
- [Description](#description)
|
|
18
|
+
- [Features](#features)
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Usage](#usage)
|
|
21
|
+
- [`GET`ting JSON data](#getting-json-data)
|
|
22
|
+
- [`GET`ting Buffer data (images, etc.)](#getting-buffer-data-images-etc)
|
|
23
|
+
- [`POST`ing JSON data](#posting-json-data)
|
|
24
|
+
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
|
25
|
+
- [Contributors](#contributors)
|
|
26
26
|
|
|
27
27
|
## Description
|
|
28
28
|
|
|
@@ -30,12 +30,11 @@ Node has a great global `fetch` (powered by [undici]) for making API calls, but
|
|
|
30
30
|
|
|
31
31
|
## Features
|
|
32
32
|
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
- Uses global `fetch`, which for NodeJS is [undici] and for browsers is the [Fetch API][fetch-mdn]
|
|
33
|
+
- Wraps global `fetch` with helpers for JSON, text, and binary response data
|
|
34
|
+
- Exported `enum` for the common return data types
|
|
35
|
+
- Provides typed JSON responses and serializes plain-object request bodies
|
|
36
|
+
- Throws a descriptive error when a response has a non-success status
|
|
37
|
+
- Uses the platform's global Fetch API implementation
|
|
39
38
|
|
|
40
39
|
## Installation
|
|
41
40
|
|
|
@@ -45,30 +44,29 @@ You can use the following command to install this package, or replace `npm insta
|
|
|
45
44
|
npm install @sapphire/fetch
|
|
46
45
|
```
|
|
47
46
|
|
|
48
|
-
##
|
|
47
|
+
## TypeScript configuration
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
> ```
|
|
49
|
+
When using `@sapphire/fetch` with TypeScript, include `dom` in the `lib` option of your `tsconfig.json`. The package uses Fetch API types such as `RequestInit` and `Response`.
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"compilerOptions": {
|
|
54
|
+
"lib": ["ES2022", "dom"]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
62
60
|
|
|
63
61
|
> [!IMPORTANT]
|
|
64
62
|
> When providing a serializable object to the `body` option, `@sapphire/fetch` will automatically call `JSON.stringify` on the object. This means you can pass an object directly to the `body` option without having to call `JSON.stringify` yourself.
|
|
65
63
|
> If the body is _not_ serializable (such as a `File`, `Buffer`, or `Blob`), the body will be sent as-is.
|
|
66
64
|
> Serializability is calculated based on:
|
|
67
65
|
>
|
|
68
|
-
> -
|
|
69
|
-
> -
|
|
70
|
-
> -
|
|
71
|
-
> -
|
|
66
|
+
> - If the body is `null`
|
|
67
|
+
> - If the body's `.constructor` property is `undefined`
|
|
68
|
+
> - If the body's `.constructor.name` property is `Object`
|
|
69
|
+
> - If the body has a function property named `toJSON`
|
|
72
70
|
|
|
73
71
|
> [!WARNING]
|
|
74
72
|
> Because `@sapphire/fetch` aims to be as close to global fetch as possible, it doesn't support proxy options that a library like undici does. If you want to use a proxy, you should use undici directly.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The supported return types for the `fetch` method
|
|
3
|
+
*/
|
|
4
|
+
export declare enum FetchResultTypes {
|
|
5
|
+
/**
|
|
6
|
+
* Returns only the body, as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
7
|
+
*
|
|
8
|
+
* For NodeJS environment other `FetchResultTypes` are recommended, but you can use a Blob if you want to.
|
|
9
|
+
*/
|
|
10
|
+
Blob = "blob",
|
|
11
|
+
/**
|
|
12
|
+
* Returns only the body, as a [Buffer](https://nodejs.org/api/buffer.html).
|
|
13
|
+
*
|
|
14
|
+
* Does not work in a Browser environment. For browsers use {@link FetchResultTypes.Blob} instead.
|
|
15
|
+
* If you use this type in a Browsers environment a `ReferenceError: Buffer is not defined` will be thrown!
|
|
16
|
+
*/
|
|
17
|
+
Buffer = "buffer",
|
|
18
|
+
/**
|
|
19
|
+
* Returns only the body, as JSON. Similar to [`Body.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/json).
|
|
20
|
+
*
|
|
21
|
+
* You should provide your own type cast (either through the generic return type, or with `as <type>`) to the response to define
|
|
22
|
+
* the JSON structure, otherwise the result will be `unknown`.
|
|
23
|
+
*/
|
|
24
|
+
JSON = "json",
|
|
25
|
+
/**
|
|
26
|
+
* Returns the entire response and doesn't parse the `body` in any way.
|
|
27
|
+
*/
|
|
28
|
+
Result = "result",
|
|
29
|
+
/**
|
|
30
|
+
* Returns only the body, as plain text. Similar to [`Body.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Body/text).
|
|
31
|
+
*/
|
|
32
|
+
Text = "text"
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The list of [HTTP Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
|
|
36
|
+
*/
|
|
37
|
+
export declare enum FetchMethods {
|
|
38
|
+
/**
|
|
39
|
+
* The `CONNECT` method establishes a tunnel to the server identified by the target resource
|
|
40
|
+
*
|
|
41
|
+
* @see [MDN / Web / HTTP / Methods / CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT)
|
|
42
|
+
*/
|
|
43
|
+
Connect = "CONNECT",
|
|
44
|
+
/**
|
|
45
|
+
* The `DELETE` method deletes the specified resource.
|
|
46
|
+
*
|
|
47
|
+
* @see [MDN / Web / HTTP / Methods / DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE)
|
|
48
|
+
*/
|
|
49
|
+
Delete = "DELETE",
|
|
50
|
+
/**
|
|
51
|
+
* The `GET` method requests a representation of the specified resource. Requests using `GET` should only retrieve data.
|
|
52
|
+
*
|
|
53
|
+
* @see [MDN / Web / HTTP / Methods / GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET)
|
|
54
|
+
*/
|
|
55
|
+
Get = "GET",
|
|
56
|
+
/**
|
|
57
|
+
* The `HEAD` method asks for a response identical to that of a {@link FetchMethods.Get | `GET`} request, but without the response body.
|
|
58
|
+
*
|
|
59
|
+
* @see [MDN / Web / HTTP / Methods / HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)
|
|
60
|
+
*/
|
|
61
|
+
Head = "HEAD",
|
|
62
|
+
/**
|
|
63
|
+
* The `OPTIONS` method is used to describe the communication options for the target resource.
|
|
64
|
+
*
|
|
65
|
+
* @see [MDN / Web / HTTP / Methods / OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)
|
|
66
|
+
*/
|
|
67
|
+
Options = "OPTIONS",
|
|
68
|
+
/**
|
|
69
|
+
* The `PATCH` method is used to apply partial modifications to a resource.
|
|
70
|
+
*
|
|
71
|
+
* @see [MDN / Web / HTTP / Methods / PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)
|
|
72
|
+
*/
|
|
73
|
+
Patch = "PATCH",
|
|
74
|
+
/**
|
|
75
|
+
* 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.
|
|
76
|
+
*
|
|
77
|
+
* @see [MDN / Web / HTTP / Methods / POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)
|
|
78
|
+
*/
|
|
79
|
+
Post = "POST",
|
|
80
|
+
/**
|
|
81
|
+
* The `PUT` method replaces all current representations of the target resource with the request payload.
|
|
82
|
+
*
|
|
83
|
+
* @see [MDN / Web / HTTP / Methods / PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT)
|
|
84
|
+
*/
|
|
85
|
+
Put = "PUT",
|
|
86
|
+
/**
|
|
87
|
+
* The `TRACE` method performs a message loop-back test along the path to the target resource.
|
|
88
|
+
*
|
|
89
|
+
* @see [MDN / Web / HTTP / Methods / TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)
|
|
90
|
+
*/
|
|
91
|
+
Trace = "TRACE"
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 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/).
|
|
95
|
+
* Media Content Types are also known as a Multipurpose Internet Mail Extensions or MIME type
|
|
96
|
+
* Media Content Types are defined and standardized in IETF's [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).
|
|
97
|
+
*/
|
|
98
|
+
export declare enum FetchMediaContentTypes {
|
|
99
|
+
/**
|
|
100
|
+
* The `audio/aac` media content type.
|
|
101
|
+
*
|
|
102
|
+
* @see [Media-Types / audio / aac](https://www.iana.org/assignments/media-types/audio/aac)
|
|
103
|
+
*/
|
|
104
|
+
AudioAac = "audio/aac",
|
|
105
|
+
/**
|
|
106
|
+
* The `audio/mp4` media content type.
|
|
107
|
+
*
|
|
108
|
+
* @see [Media-Types / audio / mp4](https://www.iana.org/assignments/media-types/audio/mp4)
|
|
109
|
+
* @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]
|
|
110
|
+
*/
|
|
111
|
+
AudioMp4 = "audio/mp4",
|
|
112
|
+
/**
|
|
113
|
+
* The `audio/mpeg` media content type.
|
|
114
|
+
*
|
|
115
|
+
* @see [Media-Types / audio / mpeg](https://www.iana.org/assignments/media-types/audio/mpeg)
|
|
116
|
+
* @see [[RFC3003](https://www.iana.org/go/rfc3003)]
|
|
117
|
+
*/
|
|
118
|
+
AudioMpeg = "audio/mpeg",
|
|
119
|
+
/**
|
|
120
|
+
* The `audio/ogg` media content type.
|
|
121
|
+
*
|
|
122
|
+
* @see [Media-Types / audio / ogg](https://www.iana.org/assignments/media-types/audio/ogg)
|
|
123
|
+
* @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]
|
|
124
|
+
*/
|
|
125
|
+
AudioOgg = "audio/ogg",
|
|
126
|
+
/**
|
|
127
|
+
* The `audio/opus` media content type.
|
|
128
|
+
*
|
|
129
|
+
* @see [Media-Types / audio / opus](https://www.iana.org/assignments/media-types/audio/opus)
|
|
130
|
+
* @see [[RFC7587](https://www.iana.org/go/rfc7587)]
|
|
131
|
+
*/
|
|
132
|
+
AudioOpus = "audio/opus",
|
|
133
|
+
/**
|
|
134
|
+
* The `audio/vorbis` media content type.
|
|
135
|
+
*
|
|
136
|
+
* @see [Media-Types / audio / vorbis](https://www.iana.org/assignments/media-types/audio/vorbis)
|
|
137
|
+
* @see [[RFC5215](https://www.iana.org/go/rfc5215)]
|
|
138
|
+
*/
|
|
139
|
+
AudioVorbis = "audio/vorbis",
|
|
140
|
+
/**
|
|
141
|
+
* The `audio/wav` media content type.
|
|
142
|
+
*/
|
|
143
|
+
AudioWav = "audio/wav",
|
|
144
|
+
/**
|
|
145
|
+
* The `audio/webm` media content type.
|
|
146
|
+
*/
|
|
147
|
+
AudioWebm = "audio/webm",
|
|
148
|
+
/**
|
|
149
|
+
* The `font/otf` media content type.
|
|
150
|
+
*
|
|
151
|
+
* @see [Media-Types / font / otf](https://www.iana.org/assignments/media-types/font/otf)
|
|
152
|
+
* @see [[RFC8081](https://www.iana.org/go/rfc8081)]
|
|
153
|
+
*/
|
|
154
|
+
FontOtf = "font/otf",
|
|
155
|
+
/**
|
|
156
|
+
* The `font/ttf` media content type.
|
|
157
|
+
*
|
|
158
|
+
* @see [Media-Types / font / ttf](https://www.iana.org/assignments/media-types/font/ttf)
|
|
159
|
+
* @see [[RFC8081](https://www.iana.org/go/rfc8081)]
|
|
160
|
+
*/
|
|
161
|
+
FontTtf = "font/ttf",
|
|
162
|
+
/**
|
|
163
|
+
* The `font/woff` media content type.
|
|
164
|
+
*
|
|
165
|
+
* @see [Media-Types / font / woff](https://www.iana.org/assignments/media-types/font/woff)
|
|
166
|
+
* @see [[RFC8081](https://www.iana.org/go/rfc8081)]
|
|
167
|
+
*/
|
|
168
|
+
FontWoff = "font/woff",
|
|
169
|
+
/**
|
|
170
|
+
* The `font/woff2` media content type.
|
|
171
|
+
*
|
|
172
|
+
* @see [Media-Types / font / woff2](https://www.iana.org/assignments/media-types/font/woff2)
|
|
173
|
+
* @see [[RFC8081](https://www.iana.org/go/rfc8081)]
|
|
174
|
+
*/
|
|
175
|
+
FontWoff2 = "font/woff2",
|
|
176
|
+
/**
|
|
177
|
+
* The `multipart/form-data` media content type.
|
|
178
|
+
*
|
|
179
|
+
* @see [Media-Types / multipart / form-data](https://www.iana.org/assignments/media-types/multipart/form-data)
|
|
180
|
+
* @see [[RFC7578](https://www.iana.org/go/rfc7578)]
|
|
181
|
+
*/
|
|
182
|
+
FormData = "multipart/form-data",
|
|
183
|
+
/**
|
|
184
|
+
* The `x-www-form-urlencoded` media content type.
|
|
185
|
+
*
|
|
186
|
+
* @see [Media-Types / application / x-www-form-urlencoded](https://www.iana.org/assignments/media-types/application/x-www-form-urlencoded)
|
|
187
|
+
*/
|
|
188
|
+
FormURLEncoded = "application/x-www-form-urlencoded",
|
|
189
|
+
/**
|
|
190
|
+
* The `image/apng` media content type.
|
|
191
|
+
*
|
|
192
|
+
* @see [Media-Types / image / apng](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics)
|
|
193
|
+
*/
|
|
194
|
+
ImageAPNG = "image/apng",
|
|
195
|
+
/**
|
|
196
|
+
* The `image/gif` media content type.
|
|
197
|
+
*
|
|
198
|
+
* @see [Media-Types / image / gif](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format)
|
|
199
|
+
* @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]
|
|
200
|
+
*/
|
|
201
|
+
ImageGIF = "image/gif",
|
|
202
|
+
/**
|
|
203
|
+
* The `image/jpeg` media content type.
|
|
204
|
+
*
|
|
205
|
+
* @see [Media-Types / image / jpeg](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image)
|
|
206
|
+
* @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046](https://www.iana.org/go/rfc2046)]
|
|
207
|
+
*/
|
|
208
|
+
ImageJPEG = "image/jpeg",
|
|
209
|
+
/**
|
|
210
|
+
* The `image/png` media content type.
|
|
211
|
+
*
|
|
212
|
+
* @see [Media-Types / image / png](https://www.iana.org/assignments/media-types/image/png)
|
|
213
|
+
*/
|
|
214
|
+
ImagePNG = "image/png",
|
|
215
|
+
/**
|
|
216
|
+
* The `image/webp` media content type.
|
|
217
|
+
*
|
|
218
|
+
* @see [Media-Types / image / webp](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image)
|
|
219
|
+
*/
|
|
220
|
+
ImageWEBP = "image/webp",
|
|
221
|
+
/**
|
|
222
|
+
* The `application/json` media content type.
|
|
223
|
+
*
|
|
224
|
+
* @see [Media-Types / application / json](https://www.iana.org/assignments/media-types/application/json)
|
|
225
|
+
* @see [[RFC8259](https://www.iana.org/go/rfc8259)]
|
|
226
|
+
*/
|
|
227
|
+
JSON = "application/json",
|
|
228
|
+
/**
|
|
229
|
+
* The `application/javascript` media content type.
|
|
230
|
+
*
|
|
231
|
+
* @see [Media-Types / application / javascript](https://www.iana.org/assignments/media-types/application/javascript)
|
|
232
|
+
* @see [[RFC4329](https://www.iana.org/go/rfc4329)]
|
|
233
|
+
*/
|
|
234
|
+
JavaScript = "application/javascript",
|
|
235
|
+
/**
|
|
236
|
+
* The `application/octet-stream` media content type.
|
|
237
|
+
*
|
|
238
|
+
* @see [Media-Types / application / octet-stream](https://www.iana.org/assignments/media-types/application/octet-stream)
|
|
239
|
+
* @see [[RFC2045](https://www.iana.org/go/rfc2045)] [[RFC2046(https://www.iana.org/go/rfc2046)]
|
|
240
|
+
*/
|
|
241
|
+
OctetStream = "application/octet-stream",
|
|
242
|
+
/**
|
|
243
|
+
* The `text/css` media content type.
|
|
244
|
+
*
|
|
245
|
+
* @see [Media-Types / text / css](https://www.iana.org/assignments/media-types/text/css)
|
|
246
|
+
* @see [[RFC2318](https://www.iana.org/go/rfc2318)]
|
|
247
|
+
*/
|
|
248
|
+
TextCSS = "text/css",
|
|
249
|
+
/**
|
|
250
|
+
* The `text/HTML` media content type.
|
|
251
|
+
*
|
|
252
|
+
* @see [Media-Types / text / html](https://www.iana.org/assignments/media-types/text/html)
|
|
253
|
+
*/
|
|
254
|
+
TextHTML = "text/html",
|
|
255
|
+
/**
|
|
256
|
+
* The `text/plain` media content type.
|
|
257
|
+
*
|
|
258
|
+
* @see [Media-Types / text / plain](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textplain)
|
|
259
|
+
* @see [[RFC2046](https://www.iana.org/go/rfc2046)] [[RFC3676](https://www.iana.org/go/rfc3676)] [[RFC5147](https://www.iana.org/go/rfc5147)]
|
|
260
|
+
*/
|
|
261
|
+
TextPlain = "text/plain",
|
|
262
|
+
/**
|
|
263
|
+
* The `video/h264` media content type.
|
|
264
|
+
*
|
|
265
|
+
* @see [Media-Types / video / h264](https://www.iana.org/assignments/media-types/video/H264)
|
|
266
|
+
* @see [[RFC6184](https://www.iana.org/go/rfc6184)]
|
|
267
|
+
*/
|
|
268
|
+
VideoH264 = "video/h264",
|
|
269
|
+
/**
|
|
270
|
+
* The `video/h265` media content type.
|
|
271
|
+
*
|
|
272
|
+
* @see [Media-Types / video / h265](https://www.iana.org/assignments/media-types/video/H265)
|
|
273
|
+
* @see [[RFC7798](https://www.iana.org/go/rfc7798)]
|
|
274
|
+
*/
|
|
275
|
+
VideoH265 = "video/h265",
|
|
276
|
+
/**
|
|
277
|
+
* The `video/mp4` media content type.
|
|
278
|
+
*
|
|
279
|
+
* @see [Media-Types / video / mp4](https://www.iana.org/assignments/media-types/video/mp4)
|
|
280
|
+
* @see [[RFC4337](https://www.iana.org/go/rfc4337)] [[RFC6381](https://www.iana.org/go/rfc6381)]
|
|
281
|
+
*/
|
|
282
|
+
VideoMp4 = "video/mp4",
|
|
283
|
+
/**
|
|
284
|
+
* The `video/ogg` media content type.
|
|
285
|
+
*
|
|
286
|
+
* @see [Media-Types / video / ogg](https://www.iana.org/assignments/media-types/video/ogg)
|
|
287
|
+
* @see [[RFC5334](https://www.iana.org/go/rfc5334)] [[RFC7845](https://www.iana.org/go/rfc7845)]
|
|
288
|
+
*/
|
|
289
|
+
VideoOgg = "video/ogg",
|
|
290
|
+
/**
|
|
291
|
+
* The `video/webm` media content type.
|
|
292
|
+
*/
|
|
293
|
+
VideoWebm = "video/webm",
|
|
294
|
+
/**
|
|
295
|
+
* The `application/xml` media content type.
|
|
296
|
+
*
|
|
297
|
+
* @see [Media-Types / application / xml](https://www.iana.org/assignments/media-types/application/xml)
|
|
298
|
+
* @see [[RFC7303](https://www.iana.org/go/rfc7303)]
|
|
299
|
+
*/
|
|
300
|
+
XML = "application/xml"
|
|
301
|
+
}
|
|
302
|
+
export interface RequestOptions extends Omit<RequestInit, 'body'> {
|
|
303
|
+
body?: Record<any, any> | RequestInit['body'];
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Performs an HTTP(S) fetch
|
|
307
|
+
*
|
|
308
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
309
|
+
* `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`.
|
|
310
|
+
* @param type - The {@link FetchResultTypes}
|
|
311
|
+
* @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.
|
|
312
|
+
*/
|
|
313
|
+
export declare function fetch<R>(url: URL | string, type?: FetchResultTypes.JSON): Promise<R>;
|
|
314
|
+
/**
|
|
315
|
+
* Performs an HTTP(S) fetch
|
|
316
|
+
*
|
|
317
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
318
|
+
* `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`.
|
|
319
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
320
|
+
* @param type - The {@link FetchResultTypes}
|
|
321
|
+
* @returns A JSON of the response body. Defaults to `unknown`, with the type set by passing the generic type of this function, or casting the result.
|
|
322
|
+
*/
|
|
323
|
+
export declare function fetch<R>(url: URL | string, options: RequestOptions, type?: FetchResultTypes.JSON): Promise<R>;
|
|
324
|
+
/**
|
|
325
|
+
* Performs an HTTP(S) fetch
|
|
326
|
+
*
|
|
327
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
328
|
+
* `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`.
|
|
329
|
+
* @param type - The {@link FetchResultTypes}
|
|
330
|
+
* @returns A {@link https://nodejs.org/api/buffer.html | `Buffer`} of the response body
|
|
331
|
+
*/
|
|
332
|
+
export declare function fetch(url: URL | string, type: FetchResultTypes.Buffer): Promise<Buffer>;
|
|
333
|
+
/**
|
|
334
|
+
* Performs an HTTP(S) fetch
|
|
335
|
+
*
|
|
336
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
337
|
+
* `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`.
|
|
338
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
339
|
+
* @param type - The {@link FetchResultTypes}
|
|
340
|
+
* @returns A {@link https://nodejs.org/api/buffer.html | `Buffer`} of the response body
|
|
341
|
+
*/
|
|
342
|
+
export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Buffer): Promise<Buffer>;
|
|
343
|
+
/**
|
|
344
|
+
* Performs an HTTP(S) fetch
|
|
345
|
+
*
|
|
346
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
347
|
+
* `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`.
|
|
348
|
+
* @param type - The {@link FetchResultTypes}
|
|
349
|
+
* @returns A {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob | `Blob`} of the response body
|
|
350
|
+
*/
|
|
351
|
+
export declare function fetch(url: URL | string, type: FetchResultTypes.Blob): Promise<Blob>;
|
|
352
|
+
/**
|
|
353
|
+
* Performs an HTTP(S) fetch
|
|
354
|
+
*
|
|
355
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
356
|
+
* `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`.
|
|
357
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
358
|
+
* @param type - The {@link FetchResultTypes}
|
|
359
|
+
* @returns A {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob | `Blob`} of the response body
|
|
360
|
+
*/
|
|
361
|
+
export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Blob): Promise<Blob>;
|
|
362
|
+
/**
|
|
363
|
+
* Performs an HTTP(S) fetch
|
|
364
|
+
*
|
|
365
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
366
|
+
* `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`.
|
|
367
|
+
* @param type - The {@link FetchResultTypes}
|
|
368
|
+
* @returns The response body as a raw `string`.
|
|
369
|
+
*/
|
|
370
|
+
export declare function fetch(url: URL | string, type: FetchResultTypes.Text): Promise<string>;
|
|
371
|
+
/**
|
|
372
|
+
* Performs an HTTP(S) fetch
|
|
373
|
+
*
|
|
374
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
375
|
+
* `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`.
|
|
376
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
377
|
+
* @param type - The {@link FetchResultTypes}
|
|
378
|
+
* @returns The response body as a raw `string`.
|
|
379
|
+
*/
|
|
380
|
+
export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Text): Promise<string>;
|
|
381
|
+
/**
|
|
382
|
+
* Performs an HTTP(S) fetch
|
|
383
|
+
*
|
|
384
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
385
|
+
* `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`.
|
|
386
|
+
* @param type - The {@link FetchResultTypes}
|
|
387
|
+
* @returns The raw {@link https://developer.mozilla.org/en-US/docs/Web/API/Response | `Response`} ({@link Response} in typescript).
|
|
388
|
+
*/
|
|
389
|
+
export declare function fetch(url: URL | string, type: FetchResultTypes.Result): Promise<Response>;
|
|
390
|
+
/**
|
|
391
|
+
* Performs an HTTP(S) fetch
|
|
392
|
+
*
|
|
393
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
394
|
+
* `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`.
|
|
395
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
396
|
+
* @param type - The {@link FetchResultTypes}
|
|
397
|
+
* @returns The raw {@link https://developer.mozilla.org/en-US/docs/Web/API/Response | `Response`} ({@link Response} in typescript).
|
|
398
|
+
*/
|
|
399
|
+
export declare function fetch(url: URL | string, options: RequestOptions, type: FetchResultTypes.Result): Promise<Response>;
|
|
400
|
+
/**
|
|
401
|
+
* Performs an HTTP(S) fetch
|
|
402
|
+
*
|
|
403
|
+
* @param url - The URL to send the request to. Can be either a `string` or an `URL` object.
|
|
404
|
+
* `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`.
|
|
405
|
+
* @param options - The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request`} ({@link RequestOptions} for TypeScript)
|
|
406
|
+
* @param type - The {@link FetchResultTypes}
|
|
407
|
+
* @returns The return type is determined by the provided `type`.
|
|
408
|
+
* - 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.
|
|
409
|
+
* - When using `FetchResultTypes.Buffer` the return type will be {@link https://nodejs.org/api/buffer.html | `Buffer`}.
|
|
410
|
+
* - When using `FetchResultTypes.Blob` the return type will be a {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob | `Blob`}.
|
|
411
|
+
* - When using `FetchResultTypes.Text` the return type will be a `string`
|
|
412
|
+
* - When using `FetchResultTypes.Result` the return type will be a {@link https://developer.mozilla.org/en-US/docs/Web/API/Response | `Response`} ({@link Response} in typescript)
|
|
413
|
+
*/
|
|
414
|
+
export declare function fetch<R>(url: URL | string, options: RequestOptions, type: FetchResultTypes): Promise<Blob | Buffer | R | Response | string>;
|
|
415
|
+
/**
|
|
416
|
+
* The QueryError class which is thrown by the `fetch` method
|
|
417
|
+
*/
|
|
418
|
+
export declare class QueryError extends Error {
|
|
419
|
+
#private;
|
|
420
|
+
/**
|
|
421
|
+
* The requested url.
|
|
422
|
+
*/
|
|
423
|
+
readonly url: string;
|
|
424
|
+
/**
|
|
425
|
+
* The HTTP status code.
|
|
426
|
+
*/
|
|
427
|
+
readonly code: number;
|
|
428
|
+
/**
|
|
429
|
+
* The returned response body as a string
|
|
430
|
+
*/
|
|
431
|
+
readonly body: string;
|
|
432
|
+
/**
|
|
433
|
+
* The original {@link Response} object
|
|
434
|
+
*/
|
|
435
|
+
readonly response: Response;
|
|
436
|
+
constructor(url: string, code: number, response: Response, body: string);
|
|
437
|
+
toJSON(): any;
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/types.ts","../src/lib/fetch.ts","../src/lib/QueryError.ts"],"mappings":";;;oBAMY;;;;;;EAMX;;;;;;;EAOA;;;;;;;EAOA;;;;EAIA;;;;EAIA;;;;;oBAMW;;;;;;EAMX;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;oBAQW;;;;;;EAMX;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;EAIA;;;;;;;EAOA;;iBAGgB,uBAAuB,KAAK;EAC5C,OAAO,mBAAmB;;;;;;;;;;wBCvSL,MAAM,GAAG,KAAK,cAAc,OAAO,iBAAiB,OAAO,QAAQ;;;;;;;;;;wBAUnE,MAAM,GAAG,KAAK,cAAc,SAAS,gBAAgB,OAAO,iBAAiB,OAAO,QAAQ;;;;;;;;;wBAS5F,MAAM,KAAK,cAAc,MAAM,iBAAiB,SAAS,QAAQ;;;;;;;;;;wBAUjE,MAAM,KAAK,cAAc,SAAS,gBAAgB,MAAM,iBAAiB,SAAS,QAAQ;;;;;;;;;wBAS1F,MAAM,KAAK,cAAc,MAAM,iBAAiB,OAAO,QAAQ;;;;;;;;;;wBAU/D,MAAM,KAAK,cAAc,SAAS,gBAAgB,MAAM,iBAAiB,OAAO,QAAQ;;;;;;;;;wBASxF,MAAM,KAAK,cAAc,MAAM,iBAAiB,OAAO;;;;;;;;;;wBAUvD,MAAM,KAAK,cAAc,SAAS,gBAAgB,MAAM,iBAAiB,OAAO;;;;;;;;;wBAShF,MAAM,KAAK,cAAc,MAAM,iBAAiB,SAAS,QAAQ;;;;;;;;;;wBAUjE,MAAM,KAAK,cAAc,SAAS,gBAAgB,MAAM,iBAAiB,SAAS,QAAQ;;;;;;;;;;;;;;;wBAe1F,MAAM,GAAG,KAAK,cAAc,SAAS,gBAAgB,MAAM,mBAAmB,QAAQ,OAAO,SAAS,IAAI;;;;qBC5GnH,mBAAmB;;;;;WAIf;;;;WAKA;;;;WAKA;;;;WAKA,UAAU;EAIP,YAAA,aAAa,cAAc,UAAU,UAAU;EAS3D"}
|