initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

21
node_modules/ofetch/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Pooya Parsa <pooya@pi0.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

284
node_modules/ofetch/README.md generated vendored Normal file
View File

@@ -0,0 +1,284 @@
# ofetch
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]
[![bundle][bundle-src]][bundle-href]
> A better fetch API. Works on node, browser and workers.
## 🚀 Quick Start
Install:
```bash
# npm
npm i ofetch
# yarn
yarn add ofetch
```
Import:
```js
// ESM / Typescript
import { ofetch } from 'ofetch'
// CommonJS
const { ofetch } = require('ofetch')
```
<details>
<summary>Spoiler</summary>
<img src="https://media.giphy.com/media/Dn1QRA9hqMcoMz9zVZ/giphy.gif">
</details>
## ✔️ Works with Node.js
We use [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) to detect Node.js
and automatically use [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).
### `keepAlive` support
By setting the `FETCH_KEEP_ALIVE` environment variable to `true`, an http/https agent will be registered that keeps sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection.
**Note:** This option can potentially introduce memory leaks. Please check [node-fetch/node-fetch#1325](https://github.com/node-fetch/node-fetch/pull/1325).
## ✔️ Parsing Response
`ofetch` will smartly parse JSON and native values using [destr](https://github.com/unjs/destr), falling back to text if it fails to parse.
```js
const { users } = await ofetch('/api/users')
```
For binary content types, `ofetch` will instead return a `Blob` object.
You can optionally provide a different parser than destr, or specify `blob`, `arrayBuffer` or `text` to force parsing the body with the respective `FetchResponse` method.
```js
// Use JSON.parse
await ofetch('/movie?lang=en', { parseResponse: JSON.parse })
// Return text as is
await ofetch('/movie?lang=en', { parseResponse: txt => txt })
// Get the blob version of the response
await ofetch('/api/generate-image', { responseType: 'blob' })
```
## ✔️ JSON Body
`ofetch` automatically stringifies request body (if an object is passed) and adds JSON `Content-Type` and `Accept` headers (for `put`, `patch` and `post` requests).
```js
const { users } = await ofetch('/api/users', { method: 'POST', body: { some: 'json' } })
```
## ✔️ Handling Errors
`ofetch` Automatically throw errors when `response.ok` is `false` with a friendly error message and compact stack (hiding internals).
Parsed error body is available with `error.data`. You may also use `FetchError` type.
```ts
await ofetch('http://google.com/404')
// FetchError: 404 Not Found (http://google.com/404)
// at async main (/project/playground.ts:4:3)
```
In order to bypass errors as response you can use `error.data`:
```ts
await ofetch(...).catch((error) => error.data)
```
## ✔️ Auto Retry
`ofetch` Automatically retries the request if an error happens. Default is `1` (except for `POST`, `PUT` and `PATCH` methods that is `0`)
```ts
await ofetch('http://google.com/404', {
retry: 3
})
```
## ✔️ Type Friendly
Response can be type assisted:
```ts
const article = await ofetch<Article>(`/api/article/${id}`)
// Auto complete working with article.id
```
## ✔️ Adding `baseURL`
By using `baseURL` option, `ofetch` prepends it with respecting to trailing/leading slashes and query search params for baseURL using [ufo](https://github.com/unjs/ufo):
```js
await ofetch('/config', { baseURL })
```
## ✔️ Adding Query Search Params
By using `query` option (or `params` as alias), `ofetch` adds query search params to URL by preserving query in request itself using [ufo](https://github.com/unjs/ufo):
```js
await ofetch('/movie?lang=en', { query: { id: 123 } })
```
## ✔️ Interceptors
It is possible to provide async interceptors to hook into lifecycle events of `ofetch` call.
You might want to use `ofetch.create` to set set shared interceptors.
### `onRequest({ request, options })`
`onRequest` is called as soon as `ofetch` is being called, allowing to modify options or just do simple logging.
```js
await ofetch('/api', {
async onRequest({ request, options }) {
// Log request
console.log('[fetch request]', request, options)
// Add `?t=1640125211170` to query search params
options.query = options.query || {}
options.query.t = new Date()
}
})
```
### `onRequestError({ request, options, error })`
`onRequestError` will be called when fetch request fails.
```js
await ofetch('/api', {
async onRequestError({ request, options, error }) {
// Log error
console.log('[fetch request error]', request, error)
}
})
```
### `onResponse({ request, options, response })`
`onResponse` will be called after `fetch` call and parsing body.
```js
await ofetch('/api', {
async onResponse({ request, response, options }) {
// Log response
console.log('[fetch response]', request, response.status, response.body)
}
})
```
### `onResponseError({ request, options, response })`
`onResponseError` is same as `onResponse` but will be called when fetch happens but `response.ok` is not `true`.
```js
await ofetch('/api', {
async onResponseError({ request, response, options }) {
// Log error
console.log('[fetch response error]', request, response.status, response.body)
}
})
```
## ✔️ Create fetch with default options
This utility is useful if you need to use common options across serveral fetch calls.
**Note:** Defaults will be cloned at one level and inherrited. Be careful about nested options like `headers`.
```js
const apiFetch = ofetch.create({ baseURL: '/api' })
apiFetch('/test') // Same as ofetch('/test', { baseURL: '/api' })
```
## 💡 Adding headers
By using `headers` option, `ofetch` adds extra headers in addition to the request default headers:
```js
await ofetch('/movies', {
headers: {
Accept: 'application/json',
'Cache-Control': 'no-cache'
}
})
```
## 🍣 Access to Raw Response
If you need to access raw response (for headers, etc), can use `ofetch.raw`:
```js
const response = await ofetch.raw('/sushi')
// response.data
// response.headers
// ...
```
## Native fetch
As a shortcut, you can use `ofetch.native` that provides native `fetch` API
```js
const json = await ofetch.native('/sushi').then(r => r.json())
```
## 📦 Bundler Notes
- All targets are exported with Module and CommonJS format and named exports
- No export is transpiled for sake of modern syntax
- You probably need to transpile `ofetch`, `destr` and `ufo` packages with babel for ES5 support
- You need to polyfill `fetch` global for supporting legacy browsers like using [unfetch](https://github.com/developit/unfetch)
## ❓ FAQ
**Why export is called `ofetch` instead of `fetch`?**
Using the same name of `fetch` can be confusing since API is different but still it is a fetch so using closest possible alternative. You can however, import `{ fetch }` from `ofetch` which is auto polyfilled for Node.js and using native otherwise.
**Why not having default export?**
Default exports are always risky to be mixed with CommonJS exports.
This also guarantees we can introduce more utils without breaking the package and also encourage using `ofetch` name.
**Why not transpiled?**
By keep transpiling libraries we push web backward with legacy code which is unneeded for most of the users.
If you need to support legacy users, you can optionally transpile the library in your build pipeline.
## License
MIT. Made with 💖
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/ofetch?style=flat-square
[npm-version-href]: https://npmjs.com/package/ofetch
[npm-downloads-src]: https://img.shields.io/npm/dm/ofetch?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/ofetch
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ofetch/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/ofetch/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ofetch/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/ofetch
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ofetch?style=flat-square
[bundle-href]: https://bundlephobia.com/result?p=ofetch

8
node_modules/ofetch/cjs/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,8 @@
const getExport = name => import("../dist/index.mjs").then(r => r[name]);
const createCaller = name => (input, init) => getExport(name).then(function_ => function_(input, init));
exports.fetch = createCaller("fetch");
exports.ofetch = createCaller("ofetch");
exports.$fetch = createCaller("$fetch");
exports.$fetch.raw = (input, init) => getExport("$fetch").then($fetch => $fetch.raw(input, init));
exports.$fetch.native = (input, init) => getExport("$fetch").then($fetch => $fetch.native(input, init));

8
node_modules/ofetch/cjs/node.cjs generated vendored Normal file
View File

@@ -0,0 +1,8 @@
const getExport = name => import("../dist/node.mjs").then(r => r[name]);
const createCaller = name => (input, init) => getExport(name).then(function_ => function_(input, init));
exports.fetch = createCaller("fetch");
exports.ofetch = createCaller("ofetch");
exports.$fetch = createCaller("$fetch");
exports.$fetch.raw = (input, init) => getExport("$fetch").then($fetch => $fetch.raw(input, init));
exports.$fetch.native = (input, init) => getExport("$fetch").then($fetch => $fetch.native(input, init));

73
node_modules/ofetch/dist/error-8a55452d.d.ts generated vendored Normal file
View File

@@ -0,0 +1,73 @@
declare type Fetch = typeof globalThis.fetch;
declare type RequestInfo = globalThis.RequestInfo;
declare type RequestInit = globalThis.RequestInit;
declare type Response = globalThis.Response;
interface ResponseMap {
blob: Blob;
text: string;
arrayBuffer: ArrayBuffer;
stream: ReadableStream<Uint8Array>;
}
declare type ResponseType = keyof ResponseMap | "json";
declare type MappedType<R extends ResponseType, JsonType = any> = R extends keyof ResponseMap ? ResponseMap[R] : JsonType;
interface CreateFetchOptions {
defaults?: FetchOptions;
fetch: Fetch;
Headers: typeof Headers;
}
declare type FetchRequest = RequestInfo;
interface FetchResponse<T> extends Response {
_data?: T;
}
interface SearchParameters {
[key: string]: any;
}
interface FetchContext<T = any, R extends ResponseType = ResponseType> {
request: FetchRequest;
options: FetchOptions<R>;
response?: FetchResponse<T>;
error?: Error;
}
interface FetchOptions<R extends ResponseType = ResponseType> extends Omit<RequestInit, "body"> {
baseURL?: string;
body?: RequestInit["body"] | Record<string, any>;
params?: SearchParameters;
query?: SearchParameters;
parseResponse?: (responseText: string) => any;
responseType?: R;
response?: boolean;
retry?: number | false;
onRequest?(context: FetchContext): Promise<void> | void;
onRequestError?(context: FetchContext & {
error: Error;
}): Promise<void> | void;
onResponse?(context: FetchContext & {
response: FetchResponse<R>;
}): Promise<void> | void;
onResponseError?(context: FetchContext & {
response: FetchResponse<R>;
}): Promise<void> | void;
}
interface $Fetch {
<T = any, R extends ResponseType = "json">(request: FetchRequest, options?: FetchOptions<R>): Promise<MappedType<R, T>>;
raw<T = any, R extends ResponseType = "json">(request: FetchRequest, options?: FetchOptions<R>): Promise<FetchResponse<MappedType<R, T>>>;
native: Fetch;
create(defaults: FetchOptions): $Fetch;
}
declare function createFetch(globalOptions: CreateFetchOptions): $Fetch;
declare class FetchError<T = any> extends Error {
name: "FetchError";
request?: FetchRequest;
response?: FetchResponse<T>;
data?: T;
status?: number;
statusText?: string;
statusCode?: number;
statusMessage?: string;
}
declare function createFetchError<T = any>(request: FetchRequest, error?: Error, response?: FetchResponse<T>): FetchError<T>;
export { $Fetch as $, CreateFetchOptions as C, FetchRequest as F, SearchParameters as S, FetchResponse as a, FetchContext as b, FetchOptions as c, createFetch as d, FetchError as e, createFetchError as f };

33
node_modules/ofetch/dist/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
const fetch$1 = require('./shared/ofetch.db55feb3.cjs');
require('destr');
require('ufo');
const _globalThis = function() {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("unable to locate global object");
}();
const fetch = _globalThis.fetch || (() => Promise.reject(new Error("[ofetch] global.fetch is not supported!")));
const Headers = _globalThis.Headers;
const ofetch = fetch$1.createFetch({ fetch, Headers });
const $fetch = ofetch;
exports.FetchError = fetch$1.FetchError;
exports.createFetch = fetch$1.createFetch;
exports.createFetchError = fetch$1.createFetchError;
exports.$fetch = $fetch;
exports.Headers = Headers;
exports.fetch = fetch;
exports.ofetch = ofetch;

12
node_modules/ofetch/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { $ as $Fetch } from './error-8a55452d.js';
export { $ as $Fetch, C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './error-8a55452d.js';
declare const fetch: typeof globalThis.fetch;
declare const Headers: {
new (init?: HeadersInit | undefined): Headers;
prototype: Headers;
};
declare const ofetch: $Fetch;
declare const $fetch: $Fetch;
export { $fetch, Headers, fetch, ofetch };

26
node_modules/ofetch/dist/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import { c as createFetch } from './shared/ofetch.5cb01515.mjs';
export { F as FetchError, c as createFetch, a as createFetchError } from './shared/ofetch.5cb01515.mjs';
import 'destr';
import 'ufo';
const _globalThis = function() {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("unable to locate global object");
}();
const fetch = _globalThis.fetch || (() => Promise.reject(new Error("[ofetch] global.fetch is not supported!")));
const Headers = _globalThis.Headers;
const ofetch = createFetch({ fetch, Headers });
const $fetch = ofetch;
export { $fetch, Headers, fetch, ofetch };

39
node_modules/ofetch/dist/node.cjs generated vendored Normal file
View File

@@ -0,0 +1,39 @@
'use strict';
const http = require('node:http');
const https = require('node:https');
const nodeFetch = require('node-fetch-native');
const fetch$1 = require('./shared/ofetch.db55feb3.cjs');
require('destr');
require('ufo');
function createNodeFetch() {
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
if (!useKeepAlive) {
return nodeFetch;
}
const agentOptions = { keepAlive: true };
const httpAgent = new http.Agent(agentOptions);
const httpsAgent = new https.Agent(agentOptions);
const nodeFetchOptions = {
agent(parsedURL) {
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
}
};
return function nodeFetchWithKeepAlive(input, init) {
return nodeFetch(input, { ...nodeFetchOptions, ...init });
};
}
const fetch = globalThis.fetch || createNodeFetch();
const Headers = globalThis.Headers || nodeFetch.Headers;
const ofetch = fetch$1.createFetch({ fetch, Headers });
const $fetch = ofetch;
exports.FetchError = fetch$1.FetchError;
exports.createFetch = fetch$1.createFetch;
exports.createFetchError = fetch$1.createFetchError;
exports.$fetch = $fetch;
exports.Headers = Headers;
exports.createNodeFetch = createNodeFetch;
exports.fetch = fetch;
exports.ofetch = ofetch;

13
node_modules/ofetch/dist/node.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { $ as $Fetch } from './error-8a55452d.js';
export { $ as $Fetch, C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './error-8a55452d.js';
declare function createNodeFetch(): (input: RequestInfo, init?: RequestInit) => any;
declare const fetch: typeof globalThis.fetch;
declare const Headers: {
new (init?: HeadersInit | undefined): Headers;
prototype: Headers;
};
declare const ofetch: $Fetch;
declare const $fetch: $Fetch;
export { $fetch, Headers, createNodeFetch, fetch, ofetch };

31
node_modules/ofetch/dist/node.mjs generated vendored Normal file
View File

@@ -0,0 +1,31 @@
import http from 'node:http';
import https from 'node:https';
import nodeFetch, { Headers as Headers$1 } from 'node-fetch-native';
import { c as createFetch } from './shared/ofetch.5cb01515.mjs';
export { F as FetchError, c as createFetch, a as createFetchError } from './shared/ofetch.5cb01515.mjs';
import 'destr';
import 'ufo';
function createNodeFetch() {
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
if (!useKeepAlive) {
return nodeFetch;
}
const agentOptions = { keepAlive: true };
const httpAgent = new http.Agent(agentOptions);
const httpsAgent = new https.Agent(agentOptions);
const nodeFetchOptions = {
agent(parsedURL) {
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
}
};
return function nodeFetchWithKeepAlive(input, init) {
return nodeFetch(input, { ...nodeFetchOptions, ...init });
};
}
const fetch = globalThis.fetch || createNodeFetch();
const Headers = globalThis.Headers || Headers$1;
const ofetch = createFetch({ fetch, Headers });
const $fetch = ofetch;
export { $fetch, Headers, createNodeFetch, fetch, ofetch };

185
node_modules/ofetch/dist/shared/ofetch.5cb01515.mjs generated vendored Normal file
View File

@@ -0,0 +1,185 @@
import destr from 'destr';
import { withBase, withQuery } from 'ufo';
class FetchError extends Error {
constructor() {
super(...arguments);
this.name = "FetchError";
}
}
function createFetchError(request, error, response) {
let message = "";
if (request && response) {
message = `${response.status} ${response.statusText} (${request.toString()})`;
}
if (error) {
message = `${error.message} (${message})`;
}
const fetchError = new FetchError(message);
Object.defineProperty(fetchError, "request", { get() {
return request;
} });
Object.defineProperty(fetchError, "response", { get() {
return response;
} });
Object.defineProperty(fetchError, "data", { get() {
return response && response._data;
} });
Object.defineProperty(fetchError, "status", { get() {
return response && response.status;
} });
Object.defineProperty(fetchError, "statusText", { get() {
return response && response.statusText;
} });
Object.defineProperty(fetchError, "statusCode", { get() {
return response && response.status;
} });
Object.defineProperty(fetchError, "statusMessage", { get() {
return response && response.statusText;
} });
return fetchError;
}
const payloadMethods = new Set(Object.freeze(["PATCH", "POST", "PUT", "DELETE"]));
function isPayloadMethod(method = "GET") {
return payloadMethods.has(method.toUpperCase());
}
function isJSONSerializable(value) {
if (value === void 0) {
return false;
}
const t = typeof value;
if (t === "string" || t === "number" || t === "boolean" || t === null) {
return true;
}
if (t !== "object") {
return false;
}
if (Array.isArray(value)) {
return true;
}
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
}
const textTypes = /* @__PURE__ */ new Set([
"image/svg",
"application/xml",
"application/xhtml",
"application/html"
]);
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
function detectResponseType(_contentType = "") {
if (!_contentType) {
return "json";
}
const contentType = _contentType.split(";").shift();
if (JSON_RE.test(contentType)) {
return "json";
}
if (textTypes.has(contentType) || contentType.startsWith("text/")) {
return "text";
}
return "blob";
}
const retryStatusCodes = /* @__PURE__ */ new Set([
408,
409,
425,
429,
500,
502,
503,
504
]);
function createFetch(globalOptions) {
const { fetch, Headers } = globalOptions;
function onError(context) {
const isAbort = context.error && context.error.name === "AbortError" || false;
if (context.options.retry !== false && !isAbort) {
const retries = typeof context.options.retry === "number" ? context.options.retry : isPayloadMethod(context.options.method) ? 0 : 1;
const responseCode = context.response && context.response.status || 500;
if (retries > 0 && retryStatusCodes.has(responseCode)) {
return $fetchRaw(context.request, {
...context.options,
retry: retries - 1
});
}
}
const error = createFetchError(context.request, context.error, context.response);
if (Error.captureStackTrace) {
Error.captureStackTrace(error, $fetchRaw);
}
throw error;
}
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
const context = {
request: _request,
options: { ...globalOptions.defaults, ..._options },
response: void 0,
error: void 0
};
if (context.options.onRequest) {
await context.options.onRequest(context);
}
if (typeof context.request === "string") {
if (context.options.baseURL) {
context.request = withBase(context.request, context.options.baseURL);
}
if (context.options.query || context.options.params) {
context.request = withQuery(context.request, { ...context.options.params, ...context.options.query });
}
if (context.options.body && isPayloadMethod(context.options.method) && isJSONSerializable(context.options.body)) {
context.options.body = typeof context.options.body === "string" ? context.options.body : JSON.stringify(context.options.body);
context.options.headers = new Headers(context.options.headers);
if (!context.options.headers.has("content-type")) {
context.options.headers.set("content-type", "application/json");
}
if (!context.options.headers.has("accept")) {
context.options.headers.set("accept", "application/json");
}
}
}
context.response = await fetch(context.request, context.options).catch(async (error) => {
context.error = error;
if (context.options.onRequestError) {
await context.options.onRequestError(context);
}
return onError(context);
});
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
if (responseType === "json") {
const data = await context.response.text();
const parseFunction = context.options.parseResponse || destr;
context.response._data = parseFunction(data);
} else if (responseType === "stream") {
context.response._data = context.response.body;
} else {
context.response._data = await context.response[responseType]();
}
if (context.options.onResponse) {
await context.options.onResponse(context);
}
if (context.response.status >= 400 && context.response.status < 600) {
if (context.options.onResponseError) {
await context.options.onResponseError(context);
}
return onError(context);
}
return context.response;
};
const $fetch = function $fetch2(request, options) {
return $fetchRaw(request, options).then((r) => r._data);
};
$fetch.raw = $fetchRaw;
$fetch.native = fetch;
$fetch.create = (defaultOptions = {}) => createFetch({
...globalOptions,
defaults: {
...globalOptions.defaults,
...defaultOptions
}
});
return $fetch;
}
export { FetchError as F, createFetchError as a, createFetch as c };

189
node_modules/ofetch/dist/shared/ofetch.db55feb3.cjs generated vendored Normal file
View File

@@ -0,0 +1,189 @@
'use strict';
const destr = require('destr');
const ufo = require('ufo');
class FetchError extends Error {
constructor() {
super(...arguments);
this.name = "FetchError";
}
}
function createFetchError(request, error, response) {
let message = "";
if (request && response) {
message = `${response.status} ${response.statusText} (${request.toString()})`;
}
if (error) {
message = `${error.message} (${message})`;
}
const fetchError = new FetchError(message);
Object.defineProperty(fetchError, "request", { get() {
return request;
} });
Object.defineProperty(fetchError, "response", { get() {
return response;
} });
Object.defineProperty(fetchError, "data", { get() {
return response && response._data;
} });
Object.defineProperty(fetchError, "status", { get() {
return response && response.status;
} });
Object.defineProperty(fetchError, "statusText", { get() {
return response && response.statusText;
} });
Object.defineProperty(fetchError, "statusCode", { get() {
return response && response.status;
} });
Object.defineProperty(fetchError, "statusMessage", { get() {
return response && response.statusText;
} });
return fetchError;
}
const payloadMethods = new Set(Object.freeze(["PATCH", "POST", "PUT", "DELETE"]));
function isPayloadMethod(method = "GET") {
return payloadMethods.has(method.toUpperCase());
}
function isJSONSerializable(value) {
if (value === void 0) {
return false;
}
const t = typeof value;
if (t === "string" || t === "number" || t === "boolean" || t === null) {
return true;
}
if (t !== "object") {
return false;
}
if (Array.isArray(value)) {
return true;
}
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
}
const textTypes = /* @__PURE__ */ new Set([
"image/svg",
"application/xml",
"application/xhtml",
"application/html"
]);
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
function detectResponseType(_contentType = "") {
if (!_contentType) {
return "json";
}
const contentType = _contentType.split(";").shift();
if (JSON_RE.test(contentType)) {
return "json";
}
if (textTypes.has(contentType) || contentType.startsWith("text/")) {
return "text";
}
return "blob";
}
const retryStatusCodes = /* @__PURE__ */ new Set([
408,
409,
425,
429,
500,
502,
503,
504
]);
function createFetch(globalOptions) {
const { fetch, Headers } = globalOptions;
function onError(context) {
const isAbort = context.error && context.error.name === "AbortError" || false;
if (context.options.retry !== false && !isAbort) {
const retries = typeof context.options.retry === "number" ? context.options.retry : isPayloadMethod(context.options.method) ? 0 : 1;
const responseCode = context.response && context.response.status || 500;
if (retries > 0 && retryStatusCodes.has(responseCode)) {
return $fetchRaw(context.request, {
...context.options,
retry: retries - 1
});
}
}
const error = createFetchError(context.request, context.error, context.response);
if (Error.captureStackTrace) {
Error.captureStackTrace(error, $fetchRaw);
}
throw error;
}
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
const context = {
request: _request,
options: { ...globalOptions.defaults, ..._options },
response: void 0,
error: void 0
};
if (context.options.onRequest) {
await context.options.onRequest(context);
}
if (typeof context.request === "string") {
if (context.options.baseURL) {
context.request = ufo.withBase(context.request, context.options.baseURL);
}
if (context.options.query || context.options.params) {
context.request = ufo.withQuery(context.request, { ...context.options.params, ...context.options.query });
}
if (context.options.body && isPayloadMethod(context.options.method) && isJSONSerializable(context.options.body)) {
context.options.body = typeof context.options.body === "string" ? context.options.body : JSON.stringify(context.options.body);
context.options.headers = new Headers(context.options.headers);
if (!context.options.headers.has("content-type")) {
context.options.headers.set("content-type", "application/json");
}
if (!context.options.headers.has("accept")) {
context.options.headers.set("accept", "application/json");
}
}
}
context.response = await fetch(context.request, context.options).catch(async (error) => {
context.error = error;
if (context.options.onRequestError) {
await context.options.onRequestError(context);
}
return onError(context);
});
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
if (responseType === "json") {
const data = await context.response.text();
const parseFunction = context.options.parseResponse || destr;
context.response._data = parseFunction(data);
} else if (responseType === "stream") {
context.response._data = context.response.body;
} else {
context.response._data = await context.response[responseType]();
}
if (context.options.onResponse) {
await context.options.onResponse(context);
}
if (context.response.status >= 400 && context.response.status < 600) {
if (context.options.onResponseError) {
await context.options.onResponseError(context);
}
return onError(context);
}
return context.response;
};
const $fetch = function $fetch2(request, options) {
return $fetchRaw(request, options).then((r) => r._data);
};
$fetch.raw = $fetchRaw;
$fetch.native = fetch;
$fetch.create = (defaultOptions = {}) => createFetch({
...globalOptions,
defaults: {
...globalOptions.defaults,
...defaultOptions
}
});
return $fetch;
}
exports.FetchError = FetchError;
exports.createFetch = createFetch;
exports.createFetchError = createFetchError;

1
node_modules/ofetch/node.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export * from "./dist/node";

66
node_modules/ofetch/package.json generated vendored Normal file
View File

@@ -0,0 +1,66 @@
{
"name": "ofetch",
"version": "1.0.0",
"description": "A better fetch API. Works on node, browser and workers.",
"repository": "unjs/ofetch",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs",
"require": "./cjs/node.cjs"
},
"default": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./cjs/index.cjs"
}
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs",
"require": "./cjs/node.cjs"
}
},
"main": "./cjs/node.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"node.d.ts",
"cjs"
],
"scripts": {
"build": "unbuild",
"dev": "vitest",
"lint": "eslint --ext .ts .",
"prepack": "pnpm build",
"play": "jiti playground/index.ts",
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
"test": "pnpm lint && vitest run --coverage"
},
"dependencies": {
"destr": "^1.2.1",
"node-fetch-native": "^1.0.1",
"ufo": "^1.0.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@vitest/coverage-c8": "^0.25.2",
"eslint": "^8.27.0",
"eslint-config-unjs": "^0.0.2",
"fetch-blob": "^3.2.0",
"formdata-polyfill": "^4.0.10",
"h3": "^1.0.1",
"jiti": "^1.16.0",
"listhen": "^1.0.0",
"standard-version": "^9.5.0",
"typescript": "^4.8.4",
"unbuild": "^0.9.4",
"vitest": "^0.25.2"
},
"packageManager": "pnpm@7.16.0"
}