mirror of
https://gitlab.com/upRootNutrition/zookeeper.git
synced 2025-06-16 10:25:12 -05:00
feat: init
This commit is contained in:
parent
8379d09058
commit
2cfa016090
2929 changed files with 299087 additions and 3 deletions
192
node_modules/@discordjs/rest/LICENSE
generated
vendored
Normal file
192
node_modules/@discordjs/rest/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,192 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2021 Noel Buechler
|
||||
Copyright 2021 Vlad Frangu
|
||||
Copyright 2021 Aura Román
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
139
node_modules/@discordjs/rest/README.md
generated
vendored
Normal file
139
node_modules/@discordjs/rest/README.md
generated
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
<div align="center">
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
|
||||
<a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/v/@discordjs/rest.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/dt/@discordjs/rest.svg?maxAge=3600" alt="npm downloads" /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Tests status" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=rest" alt="Code coverage" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
|
||||
<a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## About
|
||||
|
||||
`@discordjs/rest` is a module that allows you to easily make REST requests to the Discord API.
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 16.11.0 or newer is required.**
|
||||
|
||||
Note: native fetch (not recommended) is unavailable in this node version, either use a newer node version or use the more performant `undiciRequest` strategy (default)
|
||||
|
||||
```sh
|
||||
npm install @discordjs/rest
|
||||
yarn add @discordjs/rest
|
||||
pnpm add @discordjs/rest
|
||||
bun add @discordjs/rest
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Install all required dependencies:
|
||||
|
||||
```sh
|
||||
npm install @discordjs/rest discord-api-types
|
||||
yarn add @discordjs/rest discord-api-types
|
||||
pnpm add @discordjs/rest discord-api-types
|
||||
bun add @discordjs/rest discord-api-types
|
||||
```
|
||||
|
||||
Send a basic message:
|
||||
|
||||
```js
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v10';
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
await rest.post(Routes.channelMessages(CHANNEL_ID), {
|
||||
body: {
|
||||
content: 'A message via REST!',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
```
|
||||
|
||||
Create a thread from an existing message to be archived after 60 minutes of inactivity:
|
||||
|
||||
```js
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v10';
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
await rest.post(Routes.threads(CHANNEL_ID, MESSAGE_ID), {
|
||||
body: {
|
||||
name: 'Thread',
|
||||
auto_archive_duration: 60,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
```
|
||||
|
||||
Send a basic message in an edge environment:
|
||||
|
||||
```js
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v10';
|
||||
|
||||
const rest = new REST({ version: '10', makeRequest: fetch }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
await rest.post(Routes.channelMessages(CHANNEL_ID), {
|
||||
body: {
|
||||
content: 'A message via REST from the edge!',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Website][website] ([source][website-source])
|
||||
- [Documentation][documentation]
|
||||
- [Guide][guide] ([source][guide-source])
|
||||
Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library.
|
||||
- [discord.js Discord server][discord]
|
||||
- [Discord API Discord server][discord-api]
|
||||
- [GitHub][source]
|
||||
- [npm][npm]
|
||||
- [Related libraries][related-libs]
|
||||
|
||||
## Contributing
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation][documentation].
|
||||
See [the contribution guide][contributing] if you'd like to submit a PR.
|
||||
|
||||
## Help
|
||||
|
||||
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord].
|
||||
|
||||
[website]: https://discord.js.org
|
||||
[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website
|
||||
[documentation]: https://discord.js.org/docs/packages/rest/stable
|
||||
[guide]: https://discordjs.guide/
|
||||
[guide-source]: https://github.com/discordjs/guide
|
||||
[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
|
||||
[discord]: https://discord.gg/djs
|
||||
[discord-api]: https://discord.gg/discord-api
|
||||
[source]: https://github.com/discordjs/discord.js/tree/main/packages/rest
|
||||
[npm]: https://www.npmjs.com/package/@discordjs/rest
|
||||
[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries
|
||||
[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
|
904
node_modules/@discordjs/rest/dist/index.d.mts
generated
vendored
Normal file
904
node_modules/@discordjs/rest/dist/index.d.mts
generated
vendored
Normal file
|
@ -0,0 +1,904 @@
|
|||
import * as url from 'url';
|
||||
import { Snowflake } from 'discord-api-types/v10';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { Awaitable } from '@discordjs/util';
|
||||
import * as undici from 'undici';
|
||||
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
|
||||
interface IHandler {
|
||||
/**
|
||||
* The unique id of the handler
|
||||
*/
|
||||
readonly id: string;
|
||||
/**
|
||||
* If the bucket is currently inactive (no pending requests)
|
||||
*/
|
||||
get inactive(): boolean;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param routeId - The generalized api route with literal ids for major parameters
|
||||
* @param url - The url to do the request on
|
||||
* @param options - All the information needed to make a request
|
||||
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
||||
*/
|
||||
queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>;
|
||||
}
|
||||
|
||||
interface RestEvents {
|
||||
handlerSweep: [sweptHandlers: Collection<string, IHandler>];
|
||||
hashSweep: [sweptHashes: Collection<string, HashData>];
|
||||
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
||||
rateLimited: [rateLimitInfo: RateLimitData];
|
||||
response: [request: APIRequest, response: ResponseLike];
|
||||
restDebug: [info: string];
|
||||
}
|
||||
interface RestEventsMap extends RestEvents {
|
||||
}
|
||||
/**
|
||||
* Options to be passed when creating the REST instance
|
||||
*/
|
||||
interface RESTOptions {
|
||||
/**
|
||||
* The agent to set globally
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
/**
|
||||
* The base api path, without version
|
||||
*
|
||||
* @defaultValue `'https://discord.com/api'`
|
||||
*/
|
||||
api: string;
|
||||
/**
|
||||
* The authorization prefix to use for requests, useful if you want to use
|
||||
* bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The cdn path
|
||||
*
|
||||
* @defaultValue `'https://cdn.discordapp.com'`
|
||||
*/
|
||||
cdn: string;
|
||||
/**
|
||||
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
globalRequestsPerSecond: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
||||
*
|
||||
* @defaultValue `3_600_000`
|
||||
*/
|
||||
handlerSweepInterval: number;
|
||||
/**
|
||||
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
||||
*
|
||||
* @defaultValue `86_400_000`
|
||||
*/
|
||||
hashLifetime: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
||||
*
|
||||
* @defaultValue `14_400_000`
|
||||
*/
|
||||
hashSweepInterval: number;
|
||||
/**
|
||||
* Additional headers to send for all API requests
|
||||
*
|
||||
* @defaultValue `{}`
|
||||
*/
|
||||
headers: Record<string, string>;
|
||||
/**
|
||||
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
||||
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
||||
*
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
invalidRequestWarningInterval: number;
|
||||
/**
|
||||
* The method called to perform the actual HTTP request given a url and web `fetch` options
|
||||
* For example, to use global fetch, simply provide `makeRequest: fetch`
|
||||
*/
|
||||
makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
/**
|
||||
* The extra offset to add to rate limits in milliseconds
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
offset: GetRateLimitOffsetFunction | number;
|
||||
/**
|
||||
* Determines how rate limiting and pre-emptive throttling should be handled.
|
||||
* When an array of strings, each element is treated as a prefix for the request route
|
||||
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
||||
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
||||
*
|
||||
* @defaultValue `null`
|
||||
*/
|
||||
rejectOnRateLimit: RateLimitQueueFilter | string[] | null;
|
||||
/**
|
||||
* The number of retries for errors with the 500 code, or errors
|
||||
* that timeout
|
||||
*
|
||||
* @defaultValue `3`
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The time to wait in milliseconds before a request is aborted
|
||||
*
|
||||
* @defaultValue `15_000`
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* Extra information to add to the user agent
|
||||
*
|
||||
* @defaultValue DefaultUserAgentAppendix
|
||||
*/
|
||||
userAgentAppendix: string;
|
||||
/**
|
||||
* The version of the API to use
|
||||
*
|
||||
* @defaultValue `'10'`
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
/**
|
||||
* Data emitted on `RESTEvents.RateLimited`
|
||||
*/
|
||||
interface RateLimitData {
|
||||
/**
|
||||
* Whether the rate limit that was reached was the global limit
|
||||
*/
|
||||
global: boolean;
|
||||
/**
|
||||
* The bucket hash for this request
|
||||
*/
|
||||
hash: string;
|
||||
/**
|
||||
* The amount of requests we can perform before locking requests
|
||||
*/
|
||||
limit: number;
|
||||
/**
|
||||
* The major parameter of the route
|
||||
*
|
||||
* For example, in `/channels/x`, this will be `x`.
|
||||
* If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
|
||||
*/
|
||||
majorParameter: string;
|
||||
/**
|
||||
* The HTTP method being performed
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before this specific request can be retried
|
||||
*/
|
||||
retryAfter: number;
|
||||
/**
|
||||
* The route being hit in this request
|
||||
*/
|
||||
route: string;
|
||||
/**
|
||||
* The scope of the rate limit that was hit.
|
||||
*
|
||||
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
|
||||
* are shared per resource.
|
||||
*/
|
||||
scope: 'global' | 'shared' | 'user';
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
|
||||
* can be retried
|
||||
*
|
||||
* This is only present on certain sublimits, and `0` otherwise
|
||||
*/
|
||||
sublimitTimeout: number;
|
||||
/**
|
||||
* The time, in milliseconds, until the route's request-lock is reset
|
||||
*/
|
||||
timeToReset: number;
|
||||
/**
|
||||
* The full URL for this request
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
/**
|
||||
* A function that determines whether the rate limit hit should throw an Error
|
||||
*/
|
||||
type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
|
||||
/**
|
||||
* A function that determines the rate limit offset for a given request.
|
||||
*/
|
||||
type GetRateLimitOffsetFunction = (route: string) => number;
|
||||
interface APIRequest {
|
||||
/**
|
||||
* The data that was used to form the body of this request
|
||||
*/
|
||||
data: HandlerRequestData;
|
||||
/**
|
||||
* The HTTP method used in this request
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* Additional HTTP options for this request
|
||||
*/
|
||||
options: RequestInit;
|
||||
/**
|
||||
* The full path used to make the request
|
||||
*/
|
||||
path: RouteLike;
|
||||
/**
|
||||
* The number of times this request has been attempted
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The API route identifying the ratelimit for this request
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
interface InvalidRequestWarningData {
|
||||
/**
|
||||
* Number of invalid requests that have been made in the window
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* Time in milliseconds remaining before the count resets
|
||||
*/
|
||||
remainingTime: number;
|
||||
}
|
||||
/**
|
||||
* Represents a file to be added to the request
|
||||
*/
|
||||
interface RawFile {
|
||||
/**
|
||||
* Content-Type of the file
|
||||
*/
|
||||
contentType?: string;
|
||||
/**
|
||||
* The actual data for the file
|
||||
*/
|
||||
data: Buffer | Uint8Array | boolean | number | string;
|
||||
/**
|
||||
* An explicit key to use for key of the formdata field for this file.
|
||||
* When not provided, the index of the file in the files array is used in the form `files[${index}]`.
|
||||
* If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* The name of the file
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents possible data to be given to an endpoint
|
||||
*/
|
||||
interface RequestData {
|
||||
/**
|
||||
* Whether to append JSON data to form data instead of `payload_json` when sending files
|
||||
*/
|
||||
appendToFormData?: boolean;
|
||||
/**
|
||||
* If this request needs the `Authorization` header
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
auth?: boolean;
|
||||
/**
|
||||
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix?: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The body to send to this request.
|
||||
* If providing as BodyInit, set `passThroughBody: true`
|
||||
*/
|
||||
body?: BodyInit | unknown;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||
*/
|
||||
dispatcher?: Agent;
|
||||
/**
|
||||
* Files to be attached to this request
|
||||
*/
|
||||
files?: RawFile[] | undefined;
|
||||
/**
|
||||
* Additional headers to add to this request
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
/**
|
||||
* Whether to pass-through the body property directly to `fetch()`.
|
||||
* <warn>This only applies when files is NOT present</warn>
|
||||
*/
|
||||
passThroughBody?: boolean;
|
||||
/**
|
||||
* Query string parameters to append to the called endpoint
|
||||
*/
|
||||
query?: URLSearchParams;
|
||||
/**
|
||||
* Reason to show in the audit logs
|
||||
*/
|
||||
reason?: string | undefined;
|
||||
/**
|
||||
* The signal to abort the queue entry or the REST call, where applicable
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/**
|
||||
* If this request should be versioned
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
versioned?: boolean;
|
||||
}
|
||||
/**
|
||||
* Possible headers for an API call
|
||||
*/
|
||||
interface RequestHeaders {
|
||||
Authorization?: string;
|
||||
'User-Agent': string;
|
||||
'X-Audit-Log-Reason'?: string;
|
||||
}
|
||||
/**
|
||||
* Possible API methods to be used when doing requests
|
||||
*/
|
||||
declare enum RequestMethod {
|
||||
Delete = "DELETE",
|
||||
Get = "GET",
|
||||
Patch = "PATCH",
|
||||
Post = "POST",
|
||||
Put = "PUT"
|
||||
}
|
||||
type RouteLike = `/${string}`;
|
||||
/**
|
||||
* Internal request options
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface InternalRequest extends RequestData {
|
||||
fullRoute: RouteLike;
|
||||
method: RequestMethod;
|
||||
}
|
||||
type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
|
||||
/**
|
||||
* Parsed route data for an endpoint
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface RouteData {
|
||||
bucketRoute: string;
|
||||
majorParameter: string;
|
||||
original: RouteLike;
|
||||
}
|
||||
/**
|
||||
* Represents a hash and its associated fields
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface HashData {
|
||||
lastAccess: number;
|
||||
value: string;
|
||||
}
|
||||
|
||||
declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`;
|
||||
/**
|
||||
* The default string to append onto the user agent.
|
||||
*/
|
||||
declare const DefaultUserAgentAppendix: string;
|
||||
declare const DefaultRestOptions: {
|
||||
readonly agent: null;
|
||||
readonly api: "https://discord.com/api";
|
||||
readonly authPrefix: "Bot";
|
||||
readonly cdn: "https://cdn.discordapp.com";
|
||||
readonly headers: {};
|
||||
readonly invalidRequestWarningInterval: 0;
|
||||
readonly globalRequestsPerSecond: 50;
|
||||
readonly offset: 50;
|
||||
readonly rejectOnRateLimit: null;
|
||||
readonly retries: 3;
|
||||
readonly timeout: 15000;
|
||||
readonly userAgentAppendix: string;
|
||||
readonly version: "10";
|
||||
readonly hashSweepInterval: 14400000;
|
||||
readonly hashLifetime: 86400000;
|
||||
readonly handlerSweepInterval: 3600000;
|
||||
readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>;
|
||||
};
|
||||
/**
|
||||
* The events that the REST manager emits
|
||||
*/
|
||||
declare enum RESTEvents {
|
||||
Debug = "restDebug",
|
||||
HandlerSweep = "handlerSweep",
|
||||
HashSweep = "hashSweep",
|
||||
InvalidRequestWarning = "invalidRequestWarning",
|
||||
RateLimited = "rateLimited",
|
||||
Response = "response"
|
||||
}
|
||||
declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
|
||||
declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
|
||||
declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
|
||||
type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];
|
||||
type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];
|
||||
type ImageSize = (typeof ALLOWED_SIZES)[number];
|
||||
declare const OverwrittenMimeTypes: {
|
||||
readonly 'image/apng': "image/png";
|
||||
};
|
||||
declare const BurstHandlerMajorIdKey = "burst";
|
||||
/**
|
||||
* Prefix for deprecation warnings.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
||||
|
||||
/**
|
||||
* The options used for image URLs
|
||||
*/
|
||||
interface BaseImageURLOptions {
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: ImageExtension;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The options used for image URLs with animated content
|
||||
*/
|
||||
interface ImageURLOptions extends BaseImageURLOptions {
|
||||
/**
|
||||
* Whether or not to prefer the static version of an image asset.
|
||||
*/
|
||||
forceStatic?: boolean;
|
||||
}
|
||||
/**
|
||||
* The options to use when making a CDN URL
|
||||
*/
|
||||
interface MakeURLOptions {
|
||||
/**
|
||||
* The allowed extensions that can be used
|
||||
*/
|
||||
allowedExtensions?: readonly string[];
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: string | undefined;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The CDN link builder
|
||||
*/
|
||||
declare class CDN {
|
||||
private readonly base;
|
||||
constructor(base?: string);
|
||||
/**
|
||||
* Generates an app asset URL for a client's asset.
|
||||
*
|
||||
* @param clientId - The client id that has the asset
|
||||
* @param assetHash - The hash provided by Discord for this asset
|
||||
* @param options - Optional options for the asset
|
||||
*/
|
||||
appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an app icon URL for a client's icon.
|
||||
*
|
||||
* @param clientId - The client id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an avatar URL, e.g. for a user or a webhook.
|
||||
*
|
||||
* @param id - The id that has the icon
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a user avatar decoration URL.
|
||||
*
|
||||
* @param userId - The id of the user
|
||||
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
||||
* @param options - Optional options for the avatar decoration
|
||||
*/
|
||||
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a banner URL, e.g. for a user or a guild.
|
||||
*
|
||||
* @param id - The id that has the banner splash
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL for a channel, e.g. a group DM.
|
||||
*
|
||||
* @param channelId - The channel id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this channel
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a default avatar URL
|
||||
*
|
||||
* @param index - The default avatar index
|
||||
* @remarks
|
||||
* To calculate the index for a user do `(userId >> 22) % 6`,
|
||||
* or `discriminator % 5` if they're using the legacy username system.
|
||||
*/
|
||||
defaultAvatar(index: number): string;
|
||||
/**
|
||||
* Generates a discovery splash URL for a guild's discovery splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the discovery splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param options - Optional options for the emoji
|
||||
*/
|
||||
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param extension - The extension of the emoji
|
||||
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
||||
*/
|
||||
emoji(emojiId: string, extension?: ImageExtension): string;
|
||||
/**
|
||||
* Generates a guild member avatar URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild member banner URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL, e.g. for a guild.
|
||||
*
|
||||
* @param id - The id that has the icon splash
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a URL for the icon of a role
|
||||
*
|
||||
* @param roleId - The id of the role that has the icon
|
||||
* @param roleIconHash - The hash provided by Discord for this role icon
|
||||
* @param options - Optional options for the role icon
|
||||
*/
|
||||
roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild invite splash URL for a guild's invite splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the invite splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a sticker URL.
|
||||
*
|
||||
* @param stickerId - The sticker id
|
||||
* @param extension - The extension of the sticker
|
||||
* @privateRemarks
|
||||
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
||||
*/
|
||||
sticker(stickerId: string, extension?: StickerExtension): string;
|
||||
/**
|
||||
* Generates a sticker pack banner URL.
|
||||
*
|
||||
* @param bannerId - The banner id
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a team icon URL for a team's icon.
|
||||
*
|
||||
* @param teamId - The team id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a cover image for a guild scheduled event.
|
||||
*
|
||||
* @param scheduledEventId - The scheduled event id
|
||||
* @param coverHash - The hash provided by discord for this cover image
|
||||
* @param options - Optional options for the cover image
|
||||
*/
|
||||
guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param hash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the link
|
||||
*/
|
||||
private dynamicMakeURL;
|
||||
/**
|
||||
* Constructs the URL for the resource
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param options - The extension/size options for the link
|
||||
*/
|
||||
private makeURL;
|
||||
}
|
||||
|
||||
interface DiscordErrorFieldInformation {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
interface DiscordErrorGroupWrapper {
|
||||
_errors: DiscordError[];
|
||||
}
|
||||
type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | {
|
||||
[k: string]: DiscordError;
|
||||
};
|
||||
interface DiscordErrorData {
|
||||
code: number;
|
||||
errors?: DiscordError;
|
||||
message: string;
|
||||
}
|
||||
interface OAuthErrorData {
|
||||
error: string;
|
||||
error_description?: string;
|
||||
}
|
||||
interface RequestBody {
|
||||
files: RawFile[] | undefined;
|
||||
json: unknown | undefined;
|
||||
}
|
||||
/**
|
||||
* Represents an API error returned by Discord
|
||||
*/
|
||||
declare class DiscordAPIError extends Error {
|
||||
rawError: DiscordErrorData | OAuthErrorData;
|
||||
code: number | string;
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
/**
|
||||
* @param rawError - The error reported by Discord
|
||||
* @param code - The error code reported by Discord
|
||||
* @param status - The status code of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
private static getMessage;
|
||||
private static flattenDiscordError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a HTTP error
|
||||
*/
|
||||
declare class HTTPError extends Error {
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
name: string;
|
||||
/**
|
||||
* @param status - The status code of the response
|
||||
* @param statusText - The status text of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
}
|
||||
|
||||
declare class RateLimitError extends Error implements RateLimitData {
|
||||
timeToReset: number;
|
||||
limit: number;
|
||||
method: string;
|
||||
hash: string;
|
||||
url: string;
|
||||
route: string;
|
||||
majorParameter: string;
|
||||
global: boolean;
|
||||
retryAfter: number;
|
||||
sublimitTimeout: number;
|
||||
scope: RateLimitData['scope'];
|
||||
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the class that manages handlers for endpoints
|
||||
*/
|
||||
declare class REST extends AsyncEventEmitter<RestEvents> {
|
||||
#private;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
||||
* performed by this manager.
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
readonly cdn: CDN;
|
||||
/**
|
||||
* The number of requests remaining in the global bucket
|
||||
*/
|
||||
globalRemaining: number;
|
||||
/**
|
||||
* The promise used to wait out the global rate limit
|
||||
*/
|
||||
globalDelay: Promise<void> | null;
|
||||
/**
|
||||
* The timestamp at which the global bucket resets
|
||||
*/
|
||||
globalReset: number;
|
||||
/**
|
||||
* API bucket hashes that are cached from provided routes
|
||||
*/
|
||||
readonly hashes: Collection<string, HashData>;
|
||||
/**
|
||||
* Request handlers created from the bucket hash and the major parameters
|
||||
*/
|
||||
readonly handlers: Collection<string, IHandler>;
|
||||
private hashTimer;
|
||||
private handlerTimer;
|
||||
readonly options: RESTOptions;
|
||||
constructor(options?: Partial<RESTOptions>);
|
||||
private setupSweepers;
|
||||
/**
|
||||
* Runs a get request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a delete request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a post request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a put request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a patch request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a request from the api
|
||||
*
|
||||
* @param options - Request options
|
||||
*/
|
||||
request(options: InternalRequest): Promise<unknown>;
|
||||
/**
|
||||
* Sets the default agent to use for requests performed by this manager
|
||||
*
|
||||
* @param agent - The agent to use
|
||||
*/
|
||||
setAgent(agent: Dispatcher): this;
|
||||
/**
|
||||
* Sets the authorization token that should be used for requests
|
||||
*
|
||||
* @param token - The authorization token to use
|
||||
*/
|
||||
setToken(token: string): this;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param request - All the information needed to make a request
|
||||
* @returns The response from the api request
|
||||
*/
|
||||
queueRequest(request: InternalRequest): Promise<ResponseLike>;
|
||||
/**
|
||||
* Creates a new rate limit handler from a hash, based on the hash and the major parameter
|
||||
*
|
||||
* @param hash - The hash for the route
|
||||
* @param majorParameter - The major parameter for this handler
|
||||
* @internal
|
||||
*/
|
||||
private createHandler;
|
||||
/**
|
||||
* Formats the request data to a usable format for fetch
|
||||
*
|
||||
* @param request - The request data
|
||||
*/
|
||||
private resolveRequest;
|
||||
/**
|
||||
* Stops the hash sweeping interval
|
||||
*/
|
||||
clearHashSweeper(): void;
|
||||
/**
|
||||
* Stops the request handler sweeping interval
|
||||
*/
|
||||
clearHandlerSweeper(): void;
|
||||
/**
|
||||
* Generates route data for an endpoint:method
|
||||
*
|
||||
* @param endpoint - The raw endpoint to generalize
|
||||
* @param method - The HTTP method this endpoint is called without
|
||||
* @internal
|
||||
*/
|
||||
private static generateRouteData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and populates an URLSearchParams instance from an object, stripping
|
||||
* out null and undefined values, while also coercing non-strings to strings.
|
||||
*
|
||||
* @param options - The options to use
|
||||
* @returns A populated URLSearchParams instance
|
||||
*/
|
||||
declare function makeURLSearchParams<OptionsType extends object>(options?: Readonly<OptionsType>): url.URLSearchParams;
|
||||
/**
|
||||
* Converts the response to usable data
|
||||
*
|
||||
* @param res - The fetch response
|
||||
*/
|
||||
declare function parseResponse(res: ResponseLike): Promise<unknown>;
|
||||
/**
|
||||
* Calculates the default avatar index for a given user id.
|
||||
*
|
||||
* @param userId - The user id to calculate the default avatar index for
|
||||
*/
|
||||
declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest#readme | @discordjs/rest} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
904
node_modules/@discordjs/rest/dist/index.d.ts
generated
vendored
Normal file
904
node_modules/@discordjs/rest/dist/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,904 @@
|
|||
import * as url from 'url';
|
||||
import { Snowflake } from 'discord-api-types/v10';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { Awaitable } from '@discordjs/util';
|
||||
import * as undici from 'undici';
|
||||
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
|
||||
interface IHandler {
|
||||
/**
|
||||
* The unique id of the handler
|
||||
*/
|
||||
readonly id: string;
|
||||
/**
|
||||
* If the bucket is currently inactive (no pending requests)
|
||||
*/
|
||||
get inactive(): boolean;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param routeId - The generalized api route with literal ids for major parameters
|
||||
* @param url - The url to do the request on
|
||||
* @param options - All the information needed to make a request
|
||||
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
||||
*/
|
||||
queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>;
|
||||
}
|
||||
|
||||
interface RestEvents {
|
||||
handlerSweep: [sweptHandlers: Collection<string, IHandler>];
|
||||
hashSweep: [sweptHashes: Collection<string, HashData>];
|
||||
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
||||
rateLimited: [rateLimitInfo: RateLimitData];
|
||||
response: [request: APIRequest, response: ResponseLike];
|
||||
restDebug: [info: string];
|
||||
}
|
||||
interface RestEventsMap extends RestEvents {
|
||||
}
|
||||
/**
|
||||
* Options to be passed when creating the REST instance
|
||||
*/
|
||||
interface RESTOptions {
|
||||
/**
|
||||
* The agent to set globally
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
/**
|
||||
* The base api path, without version
|
||||
*
|
||||
* @defaultValue `'https://discord.com/api'`
|
||||
*/
|
||||
api: string;
|
||||
/**
|
||||
* The authorization prefix to use for requests, useful if you want to use
|
||||
* bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The cdn path
|
||||
*
|
||||
* @defaultValue `'https://cdn.discordapp.com'`
|
||||
*/
|
||||
cdn: string;
|
||||
/**
|
||||
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
globalRequestsPerSecond: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
||||
*
|
||||
* @defaultValue `3_600_000`
|
||||
*/
|
||||
handlerSweepInterval: number;
|
||||
/**
|
||||
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
||||
*
|
||||
* @defaultValue `86_400_000`
|
||||
*/
|
||||
hashLifetime: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
||||
*
|
||||
* @defaultValue `14_400_000`
|
||||
*/
|
||||
hashSweepInterval: number;
|
||||
/**
|
||||
* Additional headers to send for all API requests
|
||||
*
|
||||
* @defaultValue `{}`
|
||||
*/
|
||||
headers: Record<string, string>;
|
||||
/**
|
||||
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
||||
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
||||
*
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
invalidRequestWarningInterval: number;
|
||||
/**
|
||||
* The method called to perform the actual HTTP request given a url and web `fetch` options
|
||||
* For example, to use global fetch, simply provide `makeRequest: fetch`
|
||||
*/
|
||||
makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
/**
|
||||
* The extra offset to add to rate limits in milliseconds
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
offset: GetRateLimitOffsetFunction | number;
|
||||
/**
|
||||
* Determines how rate limiting and pre-emptive throttling should be handled.
|
||||
* When an array of strings, each element is treated as a prefix for the request route
|
||||
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
||||
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
||||
*
|
||||
* @defaultValue `null`
|
||||
*/
|
||||
rejectOnRateLimit: RateLimitQueueFilter | string[] | null;
|
||||
/**
|
||||
* The number of retries for errors with the 500 code, or errors
|
||||
* that timeout
|
||||
*
|
||||
* @defaultValue `3`
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The time to wait in milliseconds before a request is aborted
|
||||
*
|
||||
* @defaultValue `15_000`
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* Extra information to add to the user agent
|
||||
*
|
||||
* @defaultValue DefaultUserAgentAppendix
|
||||
*/
|
||||
userAgentAppendix: string;
|
||||
/**
|
||||
* The version of the API to use
|
||||
*
|
||||
* @defaultValue `'10'`
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
/**
|
||||
* Data emitted on `RESTEvents.RateLimited`
|
||||
*/
|
||||
interface RateLimitData {
|
||||
/**
|
||||
* Whether the rate limit that was reached was the global limit
|
||||
*/
|
||||
global: boolean;
|
||||
/**
|
||||
* The bucket hash for this request
|
||||
*/
|
||||
hash: string;
|
||||
/**
|
||||
* The amount of requests we can perform before locking requests
|
||||
*/
|
||||
limit: number;
|
||||
/**
|
||||
* The major parameter of the route
|
||||
*
|
||||
* For example, in `/channels/x`, this will be `x`.
|
||||
* If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
|
||||
*/
|
||||
majorParameter: string;
|
||||
/**
|
||||
* The HTTP method being performed
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before this specific request can be retried
|
||||
*/
|
||||
retryAfter: number;
|
||||
/**
|
||||
* The route being hit in this request
|
||||
*/
|
||||
route: string;
|
||||
/**
|
||||
* The scope of the rate limit that was hit.
|
||||
*
|
||||
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
|
||||
* are shared per resource.
|
||||
*/
|
||||
scope: 'global' | 'shared' | 'user';
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
|
||||
* can be retried
|
||||
*
|
||||
* This is only present on certain sublimits, and `0` otherwise
|
||||
*/
|
||||
sublimitTimeout: number;
|
||||
/**
|
||||
* The time, in milliseconds, until the route's request-lock is reset
|
||||
*/
|
||||
timeToReset: number;
|
||||
/**
|
||||
* The full URL for this request
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
/**
|
||||
* A function that determines whether the rate limit hit should throw an Error
|
||||
*/
|
||||
type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
|
||||
/**
|
||||
* A function that determines the rate limit offset for a given request.
|
||||
*/
|
||||
type GetRateLimitOffsetFunction = (route: string) => number;
|
||||
interface APIRequest {
|
||||
/**
|
||||
* The data that was used to form the body of this request
|
||||
*/
|
||||
data: HandlerRequestData;
|
||||
/**
|
||||
* The HTTP method used in this request
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* Additional HTTP options for this request
|
||||
*/
|
||||
options: RequestInit;
|
||||
/**
|
||||
* The full path used to make the request
|
||||
*/
|
||||
path: RouteLike;
|
||||
/**
|
||||
* The number of times this request has been attempted
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The API route identifying the ratelimit for this request
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
interface InvalidRequestWarningData {
|
||||
/**
|
||||
* Number of invalid requests that have been made in the window
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* Time in milliseconds remaining before the count resets
|
||||
*/
|
||||
remainingTime: number;
|
||||
}
|
||||
/**
|
||||
* Represents a file to be added to the request
|
||||
*/
|
||||
interface RawFile {
|
||||
/**
|
||||
* Content-Type of the file
|
||||
*/
|
||||
contentType?: string;
|
||||
/**
|
||||
* The actual data for the file
|
||||
*/
|
||||
data: Buffer | Uint8Array | boolean | number | string;
|
||||
/**
|
||||
* An explicit key to use for key of the formdata field for this file.
|
||||
* When not provided, the index of the file in the files array is used in the form `files[${index}]`.
|
||||
* If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* The name of the file
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents possible data to be given to an endpoint
|
||||
*/
|
||||
interface RequestData {
|
||||
/**
|
||||
* Whether to append JSON data to form data instead of `payload_json` when sending files
|
||||
*/
|
||||
appendToFormData?: boolean;
|
||||
/**
|
||||
* If this request needs the `Authorization` header
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
auth?: boolean;
|
||||
/**
|
||||
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix?: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The body to send to this request.
|
||||
* If providing as BodyInit, set `passThroughBody: true`
|
||||
*/
|
||||
body?: BodyInit | unknown;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||
*/
|
||||
dispatcher?: Agent;
|
||||
/**
|
||||
* Files to be attached to this request
|
||||
*/
|
||||
files?: RawFile[] | undefined;
|
||||
/**
|
||||
* Additional headers to add to this request
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
/**
|
||||
* Whether to pass-through the body property directly to `fetch()`.
|
||||
* <warn>This only applies when files is NOT present</warn>
|
||||
*/
|
||||
passThroughBody?: boolean;
|
||||
/**
|
||||
* Query string parameters to append to the called endpoint
|
||||
*/
|
||||
query?: URLSearchParams;
|
||||
/**
|
||||
* Reason to show in the audit logs
|
||||
*/
|
||||
reason?: string | undefined;
|
||||
/**
|
||||
* The signal to abort the queue entry or the REST call, where applicable
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/**
|
||||
* If this request should be versioned
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
versioned?: boolean;
|
||||
}
|
||||
/**
|
||||
* Possible headers for an API call
|
||||
*/
|
||||
interface RequestHeaders {
|
||||
Authorization?: string;
|
||||
'User-Agent': string;
|
||||
'X-Audit-Log-Reason'?: string;
|
||||
}
|
||||
/**
|
||||
* Possible API methods to be used when doing requests
|
||||
*/
|
||||
declare enum RequestMethod {
|
||||
Delete = "DELETE",
|
||||
Get = "GET",
|
||||
Patch = "PATCH",
|
||||
Post = "POST",
|
||||
Put = "PUT"
|
||||
}
|
||||
type RouteLike = `/${string}`;
|
||||
/**
|
||||
* Internal request options
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface InternalRequest extends RequestData {
|
||||
fullRoute: RouteLike;
|
||||
method: RequestMethod;
|
||||
}
|
||||
type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
|
||||
/**
|
||||
* Parsed route data for an endpoint
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface RouteData {
|
||||
bucketRoute: string;
|
||||
majorParameter: string;
|
||||
original: RouteLike;
|
||||
}
|
||||
/**
|
||||
* Represents a hash and its associated fields
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface HashData {
|
||||
lastAccess: number;
|
||||
value: string;
|
||||
}
|
||||
|
||||
declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`;
|
||||
/**
|
||||
* The default string to append onto the user agent.
|
||||
*/
|
||||
declare const DefaultUserAgentAppendix: string;
|
||||
declare const DefaultRestOptions: {
|
||||
readonly agent: null;
|
||||
readonly api: "https://discord.com/api";
|
||||
readonly authPrefix: "Bot";
|
||||
readonly cdn: "https://cdn.discordapp.com";
|
||||
readonly headers: {};
|
||||
readonly invalidRequestWarningInterval: 0;
|
||||
readonly globalRequestsPerSecond: 50;
|
||||
readonly offset: 50;
|
||||
readonly rejectOnRateLimit: null;
|
||||
readonly retries: 3;
|
||||
readonly timeout: 15000;
|
||||
readonly userAgentAppendix: string;
|
||||
readonly version: "10";
|
||||
readonly hashSweepInterval: 14400000;
|
||||
readonly hashLifetime: 86400000;
|
||||
readonly handlerSweepInterval: 3600000;
|
||||
readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>;
|
||||
};
|
||||
/**
|
||||
* The events that the REST manager emits
|
||||
*/
|
||||
declare enum RESTEvents {
|
||||
Debug = "restDebug",
|
||||
HandlerSweep = "handlerSweep",
|
||||
HashSweep = "hashSweep",
|
||||
InvalidRequestWarning = "invalidRequestWarning",
|
||||
RateLimited = "rateLimited",
|
||||
Response = "response"
|
||||
}
|
||||
declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
|
||||
declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
|
||||
declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
|
||||
type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];
|
||||
type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];
|
||||
type ImageSize = (typeof ALLOWED_SIZES)[number];
|
||||
declare const OverwrittenMimeTypes: {
|
||||
readonly 'image/apng': "image/png";
|
||||
};
|
||||
declare const BurstHandlerMajorIdKey = "burst";
|
||||
/**
|
||||
* Prefix for deprecation warnings.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
||||
|
||||
/**
|
||||
* The options used for image URLs
|
||||
*/
|
||||
interface BaseImageURLOptions {
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: ImageExtension;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The options used for image URLs with animated content
|
||||
*/
|
||||
interface ImageURLOptions extends BaseImageURLOptions {
|
||||
/**
|
||||
* Whether or not to prefer the static version of an image asset.
|
||||
*/
|
||||
forceStatic?: boolean;
|
||||
}
|
||||
/**
|
||||
* The options to use when making a CDN URL
|
||||
*/
|
||||
interface MakeURLOptions {
|
||||
/**
|
||||
* The allowed extensions that can be used
|
||||
*/
|
||||
allowedExtensions?: readonly string[];
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: string | undefined;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The CDN link builder
|
||||
*/
|
||||
declare class CDN {
|
||||
private readonly base;
|
||||
constructor(base?: string);
|
||||
/**
|
||||
* Generates an app asset URL for a client's asset.
|
||||
*
|
||||
* @param clientId - The client id that has the asset
|
||||
* @param assetHash - The hash provided by Discord for this asset
|
||||
* @param options - Optional options for the asset
|
||||
*/
|
||||
appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an app icon URL for a client's icon.
|
||||
*
|
||||
* @param clientId - The client id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an avatar URL, e.g. for a user or a webhook.
|
||||
*
|
||||
* @param id - The id that has the icon
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a user avatar decoration URL.
|
||||
*
|
||||
* @param userId - The id of the user
|
||||
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
||||
* @param options - Optional options for the avatar decoration
|
||||
*/
|
||||
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a banner URL, e.g. for a user or a guild.
|
||||
*
|
||||
* @param id - The id that has the banner splash
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL for a channel, e.g. a group DM.
|
||||
*
|
||||
* @param channelId - The channel id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this channel
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a default avatar URL
|
||||
*
|
||||
* @param index - The default avatar index
|
||||
* @remarks
|
||||
* To calculate the index for a user do `(userId >> 22) % 6`,
|
||||
* or `discriminator % 5` if they're using the legacy username system.
|
||||
*/
|
||||
defaultAvatar(index: number): string;
|
||||
/**
|
||||
* Generates a discovery splash URL for a guild's discovery splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the discovery splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param options - Optional options for the emoji
|
||||
*/
|
||||
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param extension - The extension of the emoji
|
||||
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
||||
*/
|
||||
emoji(emojiId: string, extension?: ImageExtension): string;
|
||||
/**
|
||||
* Generates a guild member avatar URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild member banner URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL, e.g. for a guild.
|
||||
*
|
||||
* @param id - The id that has the icon splash
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a URL for the icon of a role
|
||||
*
|
||||
* @param roleId - The id of the role that has the icon
|
||||
* @param roleIconHash - The hash provided by Discord for this role icon
|
||||
* @param options - Optional options for the role icon
|
||||
*/
|
||||
roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild invite splash URL for a guild's invite splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the invite splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a sticker URL.
|
||||
*
|
||||
* @param stickerId - The sticker id
|
||||
* @param extension - The extension of the sticker
|
||||
* @privateRemarks
|
||||
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
||||
*/
|
||||
sticker(stickerId: string, extension?: StickerExtension): string;
|
||||
/**
|
||||
* Generates a sticker pack banner URL.
|
||||
*
|
||||
* @param bannerId - The banner id
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a team icon URL for a team's icon.
|
||||
*
|
||||
* @param teamId - The team id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a cover image for a guild scheduled event.
|
||||
*
|
||||
* @param scheduledEventId - The scheduled event id
|
||||
* @param coverHash - The hash provided by discord for this cover image
|
||||
* @param options - Optional options for the cover image
|
||||
*/
|
||||
guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param hash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the link
|
||||
*/
|
||||
private dynamicMakeURL;
|
||||
/**
|
||||
* Constructs the URL for the resource
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param options - The extension/size options for the link
|
||||
*/
|
||||
private makeURL;
|
||||
}
|
||||
|
||||
interface DiscordErrorFieldInformation {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
interface DiscordErrorGroupWrapper {
|
||||
_errors: DiscordError[];
|
||||
}
|
||||
type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | {
|
||||
[k: string]: DiscordError;
|
||||
};
|
||||
interface DiscordErrorData {
|
||||
code: number;
|
||||
errors?: DiscordError;
|
||||
message: string;
|
||||
}
|
||||
interface OAuthErrorData {
|
||||
error: string;
|
||||
error_description?: string;
|
||||
}
|
||||
interface RequestBody {
|
||||
files: RawFile[] | undefined;
|
||||
json: unknown | undefined;
|
||||
}
|
||||
/**
|
||||
* Represents an API error returned by Discord
|
||||
*/
|
||||
declare class DiscordAPIError extends Error {
|
||||
rawError: DiscordErrorData | OAuthErrorData;
|
||||
code: number | string;
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
/**
|
||||
* @param rawError - The error reported by Discord
|
||||
* @param code - The error code reported by Discord
|
||||
* @param status - The status code of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
private static getMessage;
|
||||
private static flattenDiscordError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a HTTP error
|
||||
*/
|
||||
declare class HTTPError extends Error {
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
name: string;
|
||||
/**
|
||||
* @param status - The status code of the response
|
||||
* @param statusText - The status text of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
}
|
||||
|
||||
declare class RateLimitError extends Error implements RateLimitData {
|
||||
timeToReset: number;
|
||||
limit: number;
|
||||
method: string;
|
||||
hash: string;
|
||||
url: string;
|
||||
route: string;
|
||||
majorParameter: string;
|
||||
global: boolean;
|
||||
retryAfter: number;
|
||||
sublimitTimeout: number;
|
||||
scope: RateLimitData['scope'];
|
||||
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the class that manages handlers for endpoints
|
||||
*/
|
||||
declare class REST extends AsyncEventEmitter<RestEvents> {
|
||||
#private;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
||||
* performed by this manager.
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
readonly cdn: CDN;
|
||||
/**
|
||||
* The number of requests remaining in the global bucket
|
||||
*/
|
||||
globalRemaining: number;
|
||||
/**
|
||||
* The promise used to wait out the global rate limit
|
||||
*/
|
||||
globalDelay: Promise<void> | null;
|
||||
/**
|
||||
* The timestamp at which the global bucket resets
|
||||
*/
|
||||
globalReset: number;
|
||||
/**
|
||||
* API bucket hashes that are cached from provided routes
|
||||
*/
|
||||
readonly hashes: Collection<string, HashData>;
|
||||
/**
|
||||
* Request handlers created from the bucket hash and the major parameters
|
||||
*/
|
||||
readonly handlers: Collection<string, IHandler>;
|
||||
private hashTimer;
|
||||
private handlerTimer;
|
||||
readonly options: RESTOptions;
|
||||
constructor(options?: Partial<RESTOptions>);
|
||||
private setupSweepers;
|
||||
/**
|
||||
* Runs a get request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a delete request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a post request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a put request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a patch request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a request from the api
|
||||
*
|
||||
* @param options - Request options
|
||||
*/
|
||||
request(options: InternalRequest): Promise<unknown>;
|
||||
/**
|
||||
* Sets the default agent to use for requests performed by this manager
|
||||
*
|
||||
* @param agent - The agent to use
|
||||
*/
|
||||
setAgent(agent: Dispatcher): this;
|
||||
/**
|
||||
* Sets the authorization token that should be used for requests
|
||||
*
|
||||
* @param token - The authorization token to use
|
||||
*/
|
||||
setToken(token: string): this;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param request - All the information needed to make a request
|
||||
* @returns The response from the api request
|
||||
*/
|
||||
queueRequest(request: InternalRequest): Promise<ResponseLike>;
|
||||
/**
|
||||
* Creates a new rate limit handler from a hash, based on the hash and the major parameter
|
||||
*
|
||||
* @param hash - The hash for the route
|
||||
* @param majorParameter - The major parameter for this handler
|
||||
* @internal
|
||||
*/
|
||||
private createHandler;
|
||||
/**
|
||||
* Formats the request data to a usable format for fetch
|
||||
*
|
||||
* @param request - The request data
|
||||
*/
|
||||
private resolveRequest;
|
||||
/**
|
||||
* Stops the hash sweeping interval
|
||||
*/
|
||||
clearHashSweeper(): void;
|
||||
/**
|
||||
* Stops the request handler sweeping interval
|
||||
*/
|
||||
clearHandlerSweeper(): void;
|
||||
/**
|
||||
* Generates route data for an endpoint:method
|
||||
*
|
||||
* @param endpoint - The raw endpoint to generalize
|
||||
* @param method - The HTTP method this endpoint is called without
|
||||
* @internal
|
||||
*/
|
||||
private static generateRouteData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and populates an URLSearchParams instance from an object, stripping
|
||||
* out null and undefined values, while also coercing non-strings to strings.
|
||||
*
|
||||
* @param options - The options to use
|
||||
* @returns A populated URLSearchParams instance
|
||||
*/
|
||||
declare function makeURLSearchParams<OptionsType extends object>(options?: Readonly<OptionsType>): url.URLSearchParams;
|
||||
/**
|
||||
* Converts the response to usable data
|
||||
*
|
||||
* @param res - The fetch response
|
||||
*/
|
||||
declare function parseResponse(res: ResponseLike): Promise<unknown>;
|
||||
/**
|
||||
* Calculates the default avatar index for a given user id.
|
||||
*
|
||||
* @param userId - The user id to calculate the default avatar index for
|
||||
*/
|
||||
declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest#readme | @discordjs/rest} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
1486
node_modules/@discordjs/rest/dist/index.js
generated
vendored
Normal file
1486
node_modules/@discordjs/rest/dist/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@discordjs/rest/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1444
node_modules/@discordjs/rest/dist/index.mjs
generated
vendored
Normal file
1444
node_modules/@discordjs/rest/dist/index.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@discordjs/rest/dist/index.mjs.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
13
node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.mts
generated
vendored
Normal file
13
node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.mts
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Response, request, RequestInit } from 'undici';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
|
||||
type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;
|
||||
declare function makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
declare function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>>;
|
||||
|
||||
export { type RequestOptions, makeRequest, resolveBody };
|
13
node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.ts
generated
vendored
Normal file
13
node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Response, request, RequestInit } from 'undici';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
|
||||
type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;
|
||||
declare function makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
declare function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>>;
|
||||
|
||||
export { type RequestOptions, makeRequest, resolveBody };
|
94
node_modules/@discordjs/rest/dist/strategies/undiciRequest.js
generated
vendored
Normal file
94
node_modules/@discordjs/rest/dist/strategies/undiciRequest.js
generated
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/strategies/undiciRequest.ts
|
||||
var undiciRequest_exports = {};
|
||||
__export(undiciRequest_exports, {
|
||||
makeRequest: () => makeRequest,
|
||||
resolveBody: () => resolveBody
|
||||
});
|
||||
module.exports = __toCommonJS(undiciRequest_exports);
|
||||
var import_node_http = require("http");
|
||||
var import_node_url = require("url");
|
||||
var import_node_util = require("util");
|
||||
var import_undici = require("undici");
|
||||
async function makeRequest(url, init) {
|
||||
const options = {
|
||||
...init,
|
||||
body: await resolveBody(init.body)
|
||||
};
|
||||
const res = await (0, import_undici.request)(url, options);
|
||||
return {
|
||||
body: res.body,
|
||||
async arrayBuffer() {
|
||||
return res.body.arrayBuffer();
|
||||
},
|
||||
async json() {
|
||||
return res.body.json();
|
||||
},
|
||||
async text() {
|
||||
return res.body.text();
|
||||
},
|
||||
get bodyUsed() {
|
||||
return res.body.bodyUsed;
|
||||
},
|
||||
headers: new import_undici.Headers(res.headers),
|
||||
status: res.statusCode,
|
||||
statusText: import_node_http.STATUS_CODES[res.statusCode],
|
||||
ok: res.statusCode >= 200 && res.statusCode < 300
|
||||
};
|
||||
}
|
||||
__name(makeRequest, "makeRequest");
|
||||
async function resolveBody(body) {
|
||||
if (body == null) {
|
||||
return null;
|
||||
} else if (typeof body === "string") {
|
||||
return body;
|
||||
} else if (import_node_util.types.isUint8Array(body)) {
|
||||
return body;
|
||||
} else if (import_node_util.types.isArrayBuffer(body)) {
|
||||
return new Uint8Array(body);
|
||||
} else if (body instanceof import_node_url.URLSearchParams) {
|
||||
return body.toString();
|
||||
} else if (body instanceof DataView) {
|
||||
return new Uint8Array(body.buffer);
|
||||
} else if (body instanceof Blob) {
|
||||
return new Uint8Array(await body.arrayBuffer());
|
||||
} else if (body instanceof FormData) {
|
||||
return body;
|
||||
} else if (body[Symbol.iterator]) {
|
||||
const chunks = [...body];
|
||||
return Buffer.concat(chunks);
|
||||
} else if (body[Symbol.asyncIterator]) {
|
||||
const chunks = [];
|
||||
for await (const chunk of body) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
return Buffer.concat(chunks);
|
||||
}
|
||||
throw new TypeError(`Unable to resolve body.`);
|
||||
}
|
||||
__name(resolveBody, "resolveBody");
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
makeRequest,
|
||||
resolveBody
|
||||
});
|
||||
//# sourceMappingURL=undiciRequest.js.map
|
1
node_modules/@discordjs/rest/dist/strategies/undiciRequest.js.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/strategies/undiciRequest.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../src/strategies/undiciRequest.ts"],"sourcesContent":["import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\t\treturn Buffer.concat(chunks);\n\t}\n\n\tthrow new TypeError(`Unable to resolve body.`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA6B;AAC7B,sBAAgC;AAChC,uBAAsB;AACtB,oBAAmD;AAKnD,eAAsB,YAAY,KAAa,MAA0C;AAGxF,QAAM,UAAU;AAAA,IACf,GAAG;AAAA,IACH,MAAM,MAAM,YAAY,KAAK,IAAI;AAAA,EAClC;AACA,QAAM,MAAM,UAAM,uBAAQ,KAAK,OAAO;AACtC,SAAO;AAAA,IACN,MAAM,IAAI;AAAA,IACV,MAAM,cAAc;AACnB,aAAO,IAAI,KAAK,YAAY;AAAA,IAC7B;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,IAAI,WAAW;AACd,aAAO,IAAI,KAAK;AAAA,IACjB;AAAA,IACA,SAAS,IAAI,sBAAQ,IAAI,OAA4C;AAAA,IACrE,QAAQ,IAAI;AAAA,IACZ,YAAY,8BAAa,IAAI,UAAU;AAAA,IACvC,IAAI,IAAI,cAAc,OAAO,IAAI,aAAa;AAAA,EAC/C;AACD;AA3BsB;AA6BtB,eAAsB,YAAY,MAAgF;AAEjH,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR,WAAW,OAAO,SAAS,UAAU;AACpC,WAAO;AAAA,EACR,WAAW,uBAAM,aAAa,IAAI,GAAG;AACpC,WAAO;AAAA,EACR,WAAW,uBAAM,cAAc,IAAI,GAAG;AACrC,WAAO,IAAI,WAAW,IAAI;AAAA,EAC3B,WAAW,gBAAgB,iCAAiB;AAC3C,WAAO,KAAK,SAAS;AAAA,EACtB,WAAW,gBAAgB,UAAU;AACpC,WAAO,IAAI,WAAW,KAAK,MAAM;AAAA,EAClC,WAAW,gBAAgB,MAAM;AAChC,WAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC;AAAA,EAC/C,WAAW,gBAAgB,UAAU;AACpC,WAAO;AAAA,EACR,WAAY,KAA8B,OAAO,QAAQ,GAAG;AAC3D,UAAM,SAAS,CAAC,GAAI,IAA6B;AAEjD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B,WAAY,KAAmC,OAAO,aAAa,GAAG;AACrE,UAAM,SAAuB,CAAC;AAE9B,qBAAiB,SAAS,MAAmC;AAC5D,aAAO,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAEA,QAAM,IAAI,UAAU,yBAAyB;AAC9C;AAjCsB;","names":[]}
|
70
node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs
generated
vendored
Normal file
70
node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
// src/strategies/undiciRequest.ts
|
||||
import { STATUS_CODES } from "node:http";
|
||||
import { URLSearchParams } from "node:url";
|
||||
import { types } from "node:util";
|
||||
import { request, Headers } from "undici";
|
||||
async function makeRequest(url, init) {
|
||||
const options = {
|
||||
...init,
|
||||
body: await resolveBody(init.body)
|
||||
};
|
||||
const res = await request(url, options);
|
||||
return {
|
||||
body: res.body,
|
||||
async arrayBuffer() {
|
||||
return res.body.arrayBuffer();
|
||||
},
|
||||
async json() {
|
||||
return res.body.json();
|
||||
},
|
||||
async text() {
|
||||
return res.body.text();
|
||||
},
|
||||
get bodyUsed() {
|
||||
return res.body.bodyUsed;
|
||||
},
|
||||
headers: new Headers(res.headers),
|
||||
status: res.statusCode,
|
||||
statusText: STATUS_CODES[res.statusCode],
|
||||
ok: res.statusCode >= 200 && res.statusCode < 300
|
||||
};
|
||||
}
|
||||
__name(makeRequest, "makeRequest");
|
||||
async function resolveBody(body) {
|
||||
if (body == null) {
|
||||
return null;
|
||||
} else if (typeof body === "string") {
|
||||
return body;
|
||||
} else if (types.isUint8Array(body)) {
|
||||
return body;
|
||||
} else if (types.isArrayBuffer(body)) {
|
||||
return new Uint8Array(body);
|
||||
} else if (body instanceof URLSearchParams) {
|
||||
return body.toString();
|
||||
} else if (body instanceof DataView) {
|
||||
return new Uint8Array(body.buffer);
|
||||
} else if (body instanceof Blob) {
|
||||
return new Uint8Array(await body.arrayBuffer());
|
||||
} else if (body instanceof FormData) {
|
||||
return body;
|
||||
} else if (body[Symbol.iterator]) {
|
||||
const chunks = [...body];
|
||||
return Buffer.concat(chunks);
|
||||
} else if (body[Symbol.asyncIterator]) {
|
||||
const chunks = [];
|
||||
for await (const chunk of body) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
return Buffer.concat(chunks);
|
||||
}
|
||||
throw new TypeError(`Unable to resolve body.`);
|
||||
}
|
||||
__name(resolveBody, "resolveBody");
|
||||
export {
|
||||
makeRequest,
|
||||
resolveBody
|
||||
};
|
||||
//# sourceMappingURL=undiciRequest.mjs.map
|
1
node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../src/strategies/undiciRequest.ts"],"sourcesContent":["import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\t\treturn Buffer.concat(chunks);\n\t}\n\n\tthrow new TypeError(`Unable to resolve body.`);\n}\n"],"mappings":";;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAA2B,SAAS,eAAe;AAKnD,eAAsB,YAAY,KAAa,MAA0C;AAGxF,QAAM,UAAU;AAAA,IACf,GAAG;AAAA,IACH,MAAM,MAAM,YAAY,KAAK,IAAI;AAAA,EAClC;AACA,QAAM,MAAM,MAAM,QAAQ,KAAK,OAAO;AACtC,SAAO;AAAA,IACN,MAAM,IAAI;AAAA,IACV,MAAM,cAAc;AACnB,aAAO,IAAI,KAAK,YAAY;AAAA,IAC7B;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,IAAI,WAAW;AACd,aAAO,IAAI,KAAK;AAAA,IACjB;AAAA,IACA,SAAS,IAAI,QAAQ,IAAI,OAA4C;AAAA,IACrE,QAAQ,IAAI;AAAA,IACZ,YAAY,aAAa,IAAI,UAAU;AAAA,IACvC,IAAI,IAAI,cAAc,OAAO,IAAI,aAAa;AAAA,EAC/C;AACD;AA3BsB;AA6BtB,eAAsB,YAAY,MAAgF;AAEjH,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR,WAAW,OAAO,SAAS,UAAU;AACpC,WAAO;AAAA,EACR,WAAW,MAAM,aAAa,IAAI,GAAG;AACpC,WAAO;AAAA,EACR,WAAW,MAAM,cAAc,IAAI,GAAG;AACrC,WAAO,IAAI,WAAW,IAAI;AAAA,EAC3B,WAAW,gBAAgB,iBAAiB;AAC3C,WAAO,KAAK,SAAS;AAAA,EACtB,WAAW,gBAAgB,UAAU;AACpC,WAAO,IAAI,WAAW,KAAK,MAAM;AAAA,EAClC,WAAW,gBAAgB,MAAM;AAChC,WAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC;AAAA,EAC/C,WAAW,gBAAgB,UAAU;AACpC,WAAO;AAAA,EACR,WAAY,KAA8B,OAAO,QAAQ,GAAG;AAC3D,UAAM,SAAS,CAAC,GAAI,IAA6B;AAEjD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B,WAAY,KAAmC,OAAO,aAAa,GAAG;AACrE,UAAM,SAAuB,CAAC;AAE9B,qBAAiB,SAAS,MAAmC;AAC5D,aAAO,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAEA,QAAM,IAAI,UAAU,yBAAyB;AAC9C;AAjCsB;","names":[]}
|
904
node_modules/@discordjs/rest/dist/web.d.mts
generated
vendored
Normal file
904
node_modules/@discordjs/rest/dist/web.d.mts
generated
vendored
Normal file
|
@ -0,0 +1,904 @@
|
|||
import * as url from 'url';
|
||||
import { Snowflake } from 'discord-api-types/v10';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { Awaitable } from '@discordjs/util';
|
||||
import * as undici from 'undici';
|
||||
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
|
||||
interface IHandler {
|
||||
/**
|
||||
* The unique id of the handler
|
||||
*/
|
||||
readonly id: string;
|
||||
/**
|
||||
* If the bucket is currently inactive (no pending requests)
|
||||
*/
|
||||
get inactive(): boolean;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param routeId - The generalized api route with literal ids for major parameters
|
||||
* @param url - The url to do the request on
|
||||
* @param options - All the information needed to make a request
|
||||
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
||||
*/
|
||||
queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>;
|
||||
}
|
||||
|
||||
interface RestEvents {
|
||||
handlerSweep: [sweptHandlers: Collection<string, IHandler>];
|
||||
hashSweep: [sweptHashes: Collection<string, HashData>];
|
||||
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
||||
rateLimited: [rateLimitInfo: RateLimitData];
|
||||
response: [request: APIRequest, response: ResponseLike];
|
||||
restDebug: [info: string];
|
||||
}
|
||||
interface RestEventsMap extends RestEvents {
|
||||
}
|
||||
/**
|
||||
* Options to be passed when creating the REST instance
|
||||
*/
|
||||
interface RESTOptions {
|
||||
/**
|
||||
* The agent to set globally
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
/**
|
||||
* The base api path, without version
|
||||
*
|
||||
* @defaultValue `'https://discord.com/api'`
|
||||
*/
|
||||
api: string;
|
||||
/**
|
||||
* The authorization prefix to use for requests, useful if you want to use
|
||||
* bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The cdn path
|
||||
*
|
||||
* @defaultValue `'https://cdn.discordapp.com'`
|
||||
*/
|
||||
cdn: string;
|
||||
/**
|
||||
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
globalRequestsPerSecond: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
||||
*
|
||||
* @defaultValue `3_600_000`
|
||||
*/
|
||||
handlerSweepInterval: number;
|
||||
/**
|
||||
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
||||
*
|
||||
* @defaultValue `86_400_000`
|
||||
*/
|
||||
hashLifetime: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
||||
*
|
||||
* @defaultValue `14_400_000`
|
||||
*/
|
||||
hashSweepInterval: number;
|
||||
/**
|
||||
* Additional headers to send for all API requests
|
||||
*
|
||||
* @defaultValue `{}`
|
||||
*/
|
||||
headers: Record<string, string>;
|
||||
/**
|
||||
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
||||
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
||||
*
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
invalidRequestWarningInterval: number;
|
||||
/**
|
||||
* The method called to perform the actual HTTP request given a url and web `fetch` options
|
||||
* For example, to use global fetch, simply provide `makeRequest: fetch`
|
||||
*/
|
||||
makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
/**
|
||||
* The extra offset to add to rate limits in milliseconds
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
offset: GetRateLimitOffsetFunction | number;
|
||||
/**
|
||||
* Determines how rate limiting and pre-emptive throttling should be handled.
|
||||
* When an array of strings, each element is treated as a prefix for the request route
|
||||
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
||||
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
||||
*
|
||||
* @defaultValue `null`
|
||||
*/
|
||||
rejectOnRateLimit: RateLimitQueueFilter | string[] | null;
|
||||
/**
|
||||
* The number of retries for errors with the 500 code, or errors
|
||||
* that timeout
|
||||
*
|
||||
* @defaultValue `3`
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The time to wait in milliseconds before a request is aborted
|
||||
*
|
||||
* @defaultValue `15_000`
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* Extra information to add to the user agent
|
||||
*
|
||||
* @defaultValue DefaultUserAgentAppendix
|
||||
*/
|
||||
userAgentAppendix: string;
|
||||
/**
|
||||
* The version of the API to use
|
||||
*
|
||||
* @defaultValue `'10'`
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
/**
|
||||
* Data emitted on `RESTEvents.RateLimited`
|
||||
*/
|
||||
interface RateLimitData {
|
||||
/**
|
||||
* Whether the rate limit that was reached was the global limit
|
||||
*/
|
||||
global: boolean;
|
||||
/**
|
||||
* The bucket hash for this request
|
||||
*/
|
||||
hash: string;
|
||||
/**
|
||||
* The amount of requests we can perform before locking requests
|
||||
*/
|
||||
limit: number;
|
||||
/**
|
||||
* The major parameter of the route
|
||||
*
|
||||
* For example, in `/channels/x`, this will be `x`.
|
||||
* If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
|
||||
*/
|
||||
majorParameter: string;
|
||||
/**
|
||||
* The HTTP method being performed
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before this specific request can be retried
|
||||
*/
|
||||
retryAfter: number;
|
||||
/**
|
||||
* The route being hit in this request
|
||||
*/
|
||||
route: string;
|
||||
/**
|
||||
* The scope of the rate limit that was hit.
|
||||
*
|
||||
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
|
||||
* are shared per resource.
|
||||
*/
|
||||
scope: 'global' | 'shared' | 'user';
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
|
||||
* can be retried
|
||||
*
|
||||
* This is only present on certain sublimits, and `0` otherwise
|
||||
*/
|
||||
sublimitTimeout: number;
|
||||
/**
|
||||
* The time, in milliseconds, until the route's request-lock is reset
|
||||
*/
|
||||
timeToReset: number;
|
||||
/**
|
||||
* The full URL for this request
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
/**
|
||||
* A function that determines whether the rate limit hit should throw an Error
|
||||
*/
|
||||
type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
|
||||
/**
|
||||
* A function that determines the rate limit offset for a given request.
|
||||
*/
|
||||
type GetRateLimitOffsetFunction = (route: string) => number;
|
||||
interface APIRequest {
|
||||
/**
|
||||
* The data that was used to form the body of this request
|
||||
*/
|
||||
data: HandlerRequestData;
|
||||
/**
|
||||
* The HTTP method used in this request
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* Additional HTTP options for this request
|
||||
*/
|
||||
options: RequestInit;
|
||||
/**
|
||||
* The full path used to make the request
|
||||
*/
|
||||
path: RouteLike;
|
||||
/**
|
||||
* The number of times this request has been attempted
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The API route identifying the ratelimit for this request
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
interface InvalidRequestWarningData {
|
||||
/**
|
||||
* Number of invalid requests that have been made in the window
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* Time in milliseconds remaining before the count resets
|
||||
*/
|
||||
remainingTime: number;
|
||||
}
|
||||
/**
|
||||
* Represents a file to be added to the request
|
||||
*/
|
||||
interface RawFile {
|
||||
/**
|
||||
* Content-Type of the file
|
||||
*/
|
||||
contentType?: string;
|
||||
/**
|
||||
* The actual data for the file
|
||||
*/
|
||||
data: Buffer | Uint8Array | boolean | number | string;
|
||||
/**
|
||||
* An explicit key to use for key of the formdata field for this file.
|
||||
* When not provided, the index of the file in the files array is used in the form `files[${index}]`.
|
||||
* If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* The name of the file
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents possible data to be given to an endpoint
|
||||
*/
|
||||
interface RequestData {
|
||||
/**
|
||||
* Whether to append JSON data to form data instead of `payload_json` when sending files
|
||||
*/
|
||||
appendToFormData?: boolean;
|
||||
/**
|
||||
* If this request needs the `Authorization` header
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
auth?: boolean;
|
||||
/**
|
||||
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix?: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The body to send to this request.
|
||||
* If providing as BodyInit, set `passThroughBody: true`
|
||||
*/
|
||||
body?: BodyInit | unknown;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||
*/
|
||||
dispatcher?: Agent;
|
||||
/**
|
||||
* Files to be attached to this request
|
||||
*/
|
||||
files?: RawFile[] | undefined;
|
||||
/**
|
||||
* Additional headers to add to this request
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
/**
|
||||
* Whether to pass-through the body property directly to `fetch()`.
|
||||
* <warn>This only applies when files is NOT present</warn>
|
||||
*/
|
||||
passThroughBody?: boolean;
|
||||
/**
|
||||
* Query string parameters to append to the called endpoint
|
||||
*/
|
||||
query?: URLSearchParams;
|
||||
/**
|
||||
* Reason to show in the audit logs
|
||||
*/
|
||||
reason?: string | undefined;
|
||||
/**
|
||||
* The signal to abort the queue entry or the REST call, where applicable
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/**
|
||||
* If this request should be versioned
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
versioned?: boolean;
|
||||
}
|
||||
/**
|
||||
* Possible headers for an API call
|
||||
*/
|
||||
interface RequestHeaders {
|
||||
Authorization?: string;
|
||||
'User-Agent': string;
|
||||
'X-Audit-Log-Reason'?: string;
|
||||
}
|
||||
/**
|
||||
* Possible API methods to be used when doing requests
|
||||
*/
|
||||
declare enum RequestMethod {
|
||||
Delete = "DELETE",
|
||||
Get = "GET",
|
||||
Patch = "PATCH",
|
||||
Post = "POST",
|
||||
Put = "PUT"
|
||||
}
|
||||
type RouteLike = `/${string}`;
|
||||
/**
|
||||
* Internal request options
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface InternalRequest extends RequestData {
|
||||
fullRoute: RouteLike;
|
||||
method: RequestMethod;
|
||||
}
|
||||
type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
|
||||
/**
|
||||
* Parsed route data for an endpoint
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface RouteData {
|
||||
bucketRoute: string;
|
||||
majorParameter: string;
|
||||
original: RouteLike;
|
||||
}
|
||||
/**
|
||||
* Represents a hash and its associated fields
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface HashData {
|
||||
lastAccess: number;
|
||||
value: string;
|
||||
}
|
||||
|
||||
declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`;
|
||||
/**
|
||||
* The default string to append onto the user agent.
|
||||
*/
|
||||
declare const DefaultUserAgentAppendix: string;
|
||||
declare const DefaultRestOptions: {
|
||||
readonly agent: null;
|
||||
readonly api: "https://discord.com/api";
|
||||
readonly authPrefix: "Bot";
|
||||
readonly cdn: "https://cdn.discordapp.com";
|
||||
readonly headers: {};
|
||||
readonly invalidRequestWarningInterval: 0;
|
||||
readonly globalRequestsPerSecond: 50;
|
||||
readonly offset: 50;
|
||||
readonly rejectOnRateLimit: null;
|
||||
readonly retries: 3;
|
||||
readonly timeout: 15000;
|
||||
readonly userAgentAppendix: string;
|
||||
readonly version: "10";
|
||||
readonly hashSweepInterval: 14400000;
|
||||
readonly hashLifetime: 86400000;
|
||||
readonly handlerSweepInterval: 3600000;
|
||||
readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>;
|
||||
};
|
||||
/**
|
||||
* The events that the REST manager emits
|
||||
*/
|
||||
declare enum RESTEvents {
|
||||
Debug = "restDebug",
|
||||
HandlerSweep = "handlerSweep",
|
||||
HashSweep = "hashSweep",
|
||||
InvalidRequestWarning = "invalidRequestWarning",
|
||||
RateLimited = "rateLimited",
|
||||
Response = "response"
|
||||
}
|
||||
declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
|
||||
declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
|
||||
declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
|
||||
type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];
|
||||
type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];
|
||||
type ImageSize = (typeof ALLOWED_SIZES)[number];
|
||||
declare const OverwrittenMimeTypes: {
|
||||
readonly 'image/apng': "image/png";
|
||||
};
|
||||
declare const BurstHandlerMajorIdKey = "burst";
|
||||
/**
|
||||
* Prefix for deprecation warnings.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
||||
|
||||
/**
|
||||
* The options used for image URLs
|
||||
*/
|
||||
interface BaseImageURLOptions {
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: ImageExtension;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The options used for image URLs with animated content
|
||||
*/
|
||||
interface ImageURLOptions extends BaseImageURLOptions {
|
||||
/**
|
||||
* Whether or not to prefer the static version of an image asset.
|
||||
*/
|
||||
forceStatic?: boolean;
|
||||
}
|
||||
/**
|
||||
* The options to use when making a CDN URL
|
||||
*/
|
||||
interface MakeURLOptions {
|
||||
/**
|
||||
* The allowed extensions that can be used
|
||||
*/
|
||||
allowedExtensions?: readonly string[];
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: string | undefined;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The CDN link builder
|
||||
*/
|
||||
declare class CDN {
|
||||
private readonly base;
|
||||
constructor(base?: string);
|
||||
/**
|
||||
* Generates an app asset URL for a client's asset.
|
||||
*
|
||||
* @param clientId - The client id that has the asset
|
||||
* @param assetHash - The hash provided by Discord for this asset
|
||||
* @param options - Optional options for the asset
|
||||
*/
|
||||
appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an app icon URL for a client's icon.
|
||||
*
|
||||
* @param clientId - The client id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an avatar URL, e.g. for a user or a webhook.
|
||||
*
|
||||
* @param id - The id that has the icon
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a user avatar decoration URL.
|
||||
*
|
||||
* @param userId - The id of the user
|
||||
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
||||
* @param options - Optional options for the avatar decoration
|
||||
*/
|
||||
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a banner URL, e.g. for a user or a guild.
|
||||
*
|
||||
* @param id - The id that has the banner splash
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL for a channel, e.g. a group DM.
|
||||
*
|
||||
* @param channelId - The channel id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this channel
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a default avatar URL
|
||||
*
|
||||
* @param index - The default avatar index
|
||||
* @remarks
|
||||
* To calculate the index for a user do `(userId >> 22) % 6`,
|
||||
* or `discriminator % 5` if they're using the legacy username system.
|
||||
*/
|
||||
defaultAvatar(index: number): string;
|
||||
/**
|
||||
* Generates a discovery splash URL for a guild's discovery splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the discovery splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param options - Optional options for the emoji
|
||||
*/
|
||||
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param extension - The extension of the emoji
|
||||
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
||||
*/
|
||||
emoji(emojiId: string, extension?: ImageExtension): string;
|
||||
/**
|
||||
* Generates a guild member avatar URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild member banner URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL, e.g. for a guild.
|
||||
*
|
||||
* @param id - The id that has the icon splash
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a URL for the icon of a role
|
||||
*
|
||||
* @param roleId - The id of the role that has the icon
|
||||
* @param roleIconHash - The hash provided by Discord for this role icon
|
||||
* @param options - Optional options for the role icon
|
||||
*/
|
||||
roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild invite splash URL for a guild's invite splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the invite splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a sticker URL.
|
||||
*
|
||||
* @param stickerId - The sticker id
|
||||
* @param extension - The extension of the sticker
|
||||
* @privateRemarks
|
||||
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
||||
*/
|
||||
sticker(stickerId: string, extension?: StickerExtension): string;
|
||||
/**
|
||||
* Generates a sticker pack banner URL.
|
||||
*
|
||||
* @param bannerId - The banner id
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a team icon URL for a team's icon.
|
||||
*
|
||||
* @param teamId - The team id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a cover image for a guild scheduled event.
|
||||
*
|
||||
* @param scheduledEventId - The scheduled event id
|
||||
* @param coverHash - The hash provided by discord for this cover image
|
||||
* @param options - Optional options for the cover image
|
||||
*/
|
||||
guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param hash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the link
|
||||
*/
|
||||
private dynamicMakeURL;
|
||||
/**
|
||||
* Constructs the URL for the resource
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param options - The extension/size options for the link
|
||||
*/
|
||||
private makeURL;
|
||||
}
|
||||
|
||||
interface DiscordErrorFieldInformation {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
interface DiscordErrorGroupWrapper {
|
||||
_errors: DiscordError[];
|
||||
}
|
||||
type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | {
|
||||
[k: string]: DiscordError;
|
||||
};
|
||||
interface DiscordErrorData {
|
||||
code: number;
|
||||
errors?: DiscordError;
|
||||
message: string;
|
||||
}
|
||||
interface OAuthErrorData {
|
||||
error: string;
|
||||
error_description?: string;
|
||||
}
|
||||
interface RequestBody {
|
||||
files: RawFile[] | undefined;
|
||||
json: unknown | undefined;
|
||||
}
|
||||
/**
|
||||
* Represents an API error returned by Discord
|
||||
*/
|
||||
declare class DiscordAPIError extends Error {
|
||||
rawError: DiscordErrorData | OAuthErrorData;
|
||||
code: number | string;
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
/**
|
||||
* @param rawError - The error reported by Discord
|
||||
* @param code - The error code reported by Discord
|
||||
* @param status - The status code of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
private static getMessage;
|
||||
private static flattenDiscordError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a HTTP error
|
||||
*/
|
||||
declare class HTTPError extends Error {
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
name: string;
|
||||
/**
|
||||
* @param status - The status code of the response
|
||||
* @param statusText - The status text of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
}
|
||||
|
||||
declare class RateLimitError extends Error implements RateLimitData {
|
||||
timeToReset: number;
|
||||
limit: number;
|
||||
method: string;
|
||||
hash: string;
|
||||
url: string;
|
||||
route: string;
|
||||
majorParameter: string;
|
||||
global: boolean;
|
||||
retryAfter: number;
|
||||
sublimitTimeout: number;
|
||||
scope: RateLimitData['scope'];
|
||||
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the class that manages handlers for endpoints
|
||||
*/
|
||||
declare class REST extends AsyncEventEmitter<RestEvents> {
|
||||
#private;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
||||
* performed by this manager.
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
readonly cdn: CDN;
|
||||
/**
|
||||
* The number of requests remaining in the global bucket
|
||||
*/
|
||||
globalRemaining: number;
|
||||
/**
|
||||
* The promise used to wait out the global rate limit
|
||||
*/
|
||||
globalDelay: Promise<void> | null;
|
||||
/**
|
||||
* The timestamp at which the global bucket resets
|
||||
*/
|
||||
globalReset: number;
|
||||
/**
|
||||
* API bucket hashes that are cached from provided routes
|
||||
*/
|
||||
readonly hashes: Collection<string, HashData>;
|
||||
/**
|
||||
* Request handlers created from the bucket hash and the major parameters
|
||||
*/
|
||||
readonly handlers: Collection<string, IHandler>;
|
||||
private hashTimer;
|
||||
private handlerTimer;
|
||||
readonly options: RESTOptions;
|
||||
constructor(options?: Partial<RESTOptions>);
|
||||
private setupSweepers;
|
||||
/**
|
||||
* Runs a get request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a delete request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a post request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a put request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a patch request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a request from the api
|
||||
*
|
||||
* @param options - Request options
|
||||
*/
|
||||
request(options: InternalRequest): Promise<unknown>;
|
||||
/**
|
||||
* Sets the default agent to use for requests performed by this manager
|
||||
*
|
||||
* @param agent - The agent to use
|
||||
*/
|
||||
setAgent(agent: Dispatcher): this;
|
||||
/**
|
||||
* Sets the authorization token that should be used for requests
|
||||
*
|
||||
* @param token - The authorization token to use
|
||||
*/
|
||||
setToken(token: string): this;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param request - All the information needed to make a request
|
||||
* @returns The response from the api request
|
||||
*/
|
||||
queueRequest(request: InternalRequest): Promise<ResponseLike>;
|
||||
/**
|
||||
* Creates a new rate limit handler from a hash, based on the hash and the major parameter
|
||||
*
|
||||
* @param hash - The hash for the route
|
||||
* @param majorParameter - The major parameter for this handler
|
||||
* @internal
|
||||
*/
|
||||
private createHandler;
|
||||
/**
|
||||
* Formats the request data to a usable format for fetch
|
||||
*
|
||||
* @param request - The request data
|
||||
*/
|
||||
private resolveRequest;
|
||||
/**
|
||||
* Stops the hash sweeping interval
|
||||
*/
|
||||
clearHashSweeper(): void;
|
||||
/**
|
||||
* Stops the request handler sweeping interval
|
||||
*/
|
||||
clearHandlerSweeper(): void;
|
||||
/**
|
||||
* Generates route data for an endpoint:method
|
||||
*
|
||||
* @param endpoint - The raw endpoint to generalize
|
||||
* @param method - The HTTP method this endpoint is called without
|
||||
* @internal
|
||||
*/
|
||||
private static generateRouteData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and populates an URLSearchParams instance from an object, stripping
|
||||
* out null and undefined values, while also coercing non-strings to strings.
|
||||
*
|
||||
* @param options - The options to use
|
||||
* @returns A populated URLSearchParams instance
|
||||
*/
|
||||
declare function makeURLSearchParams<OptionsType extends object>(options?: Readonly<OptionsType>): url.URLSearchParams;
|
||||
/**
|
||||
* Converts the response to usable data
|
||||
*
|
||||
* @param res - The fetch response
|
||||
*/
|
||||
declare function parseResponse(res: ResponseLike): Promise<unknown>;
|
||||
/**
|
||||
* Calculates the default avatar index for a given user id.
|
||||
*
|
||||
* @param userId - The user id to calculate the default avatar index for
|
||||
*/
|
||||
declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest#readme | @discordjs/rest} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
904
node_modules/@discordjs/rest/dist/web.d.ts
generated
vendored
Normal file
904
node_modules/@discordjs/rest/dist/web.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,904 @@
|
|||
import * as url from 'url';
|
||||
import { Snowflake } from 'discord-api-types/v10';
|
||||
import { Readable } from 'node:stream';
|
||||
import { ReadableStream } from 'node:stream/web';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { Awaitable } from '@discordjs/util';
|
||||
import * as undici from 'undici';
|
||||
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
|
||||
interface IHandler {
|
||||
/**
|
||||
* The unique id of the handler
|
||||
*/
|
||||
readonly id: string;
|
||||
/**
|
||||
* If the bucket is currently inactive (no pending requests)
|
||||
*/
|
||||
get inactive(): boolean;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param routeId - The generalized api route with literal ids for major parameters
|
||||
* @param url - The url to do the request on
|
||||
* @param options - All the information needed to make a request
|
||||
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
||||
*/
|
||||
queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>;
|
||||
}
|
||||
|
||||
interface RestEvents {
|
||||
handlerSweep: [sweptHandlers: Collection<string, IHandler>];
|
||||
hashSweep: [sweptHashes: Collection<string, HashData>];
|
||||
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
||||
rateLimited: [rateLimitInfo: RateLimitData];
|
||||
response: [request: APIRequest, response: ResponseLike];
|
||||
restDebug: [info: string];
|
||||
}
|
||||
interface RestEventsMap extends RestEvents {
|
||||
}
|
||||
/**
|
||||
* Options to be passed when creating the REST instance
|
||||
*/
|
||||
interface RESTOptions {
|
||||
/**
|
||||
* The agent to set globally
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
/**
|
||||
* The base api path, without version
|
||||
*
|
||||
* @defaultValue `'https://discord.com/api'`
|
||||
*/
|
||||
api: string;
|
||||
/**
|
||||
* The authorization prefix to use for requests, useful if you want to use
|
||||
* bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The cdn path
|
||||
*
|
||||
* @defaultValue `'https://cdn.discordapp.com'`
|
||||
*/
|
||||
cdn: string;
|
||||
/**
|
||||
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
globalRequestsPerSecond: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
||||
*
|
||||
* @defaultValue `3_600_000`
|
||||
*/
|
||||
handlerSweepInterval: number;
|
||||
/**
|
||||
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
||||
*
|
||||
* @defaultValue `86_400_000`
|
||||
*/
|
||||
hashLifetime: number;
|
||||
/**
|
||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
||||
*
|
||||
* @defaultValue `14_400_000`
|
||||
*/
|
||||
hashSweepInterval: number;
|
||||
/**
|
||||
* Additional headers to send for all API requests
|
||||
*
|
||||
* @defaultValue `{}`
|
||||
*/
|
||||
headers: Record<string, string>;
|
||||
/**
|
||||
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
||||
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
||||
*
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
invalidRequestWarningInterval: number;
|
||||
/**
|
||||
* The method called to perform the actual HTTP request given a url and web `fetch` options
|
||||
* For example, to use global fetch, simply provide `makeRequest: fetch`
|
||||
*/
|
||||
makeRequest(url: string, init: RequestInit): Promise<ResponseLike>;
|
||||
/**
|
||||
* The extra offset to add to rate limits in milliseconds
|
||||
*
|
||||
* @defaultValue `50`
|
||||
*/
|
||||
offset: GetRateLimitOffsetFunction | number;
|
||||
/**
|
||||
* Determines how rate limiting and pre-emptive throttling should be handled.
|
||||
* When an array of strings, each element is treated as a prefix for the request route
|
||||
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
||||
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
||||
*
|
||||
* @defaultValue `null`
|
||||
*/
|
||||
rejectOnRateLimit: RateLimitQueueFilter | string[] | null;
|
||||
/**
|
||||
* The number of retries for errors with the 500 code, or errors
|
||||
* that timeout
|
||||
*
|
||||
* @defaultValue `3`
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The time to wait in milliseconds before a request is aborted
|
||||
*
|
||||
* @defaultValue `15_000`
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* Extra information to add to the user agent
|
||||
*
|
||||
* @defaultValue DefaultUserAgentAppendix
|
||||
*/
|
||||
userAgentAppendix: string;
|
||||
/**
|
||||
* The version of the API to use
|
||||
*
|
||||
* @defaultValue `'10'`
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
/**
|
||||
* Data emitted on `RESTEvents.RateLimited`
|
||||
*/
|
||||
interface RateLimitData {
|
||||
/**
|
||||
* Whether the rate limit that was reached was the global limit
|
||||
*/
|
||||
global: boolean;
|
||||
/**
|
||||
* The bucket hash for this request
|
||||
*/
|
||||
hash: string;
|
||||
/**
|
||||
* The amount of requests we can perform before locking requests
|
||||
*/
|
||||
limit: number;
|
||||
/**
|
||||
* The major parameter of the route
|
||||
*
|
||||
* For example, in `/channels/x`, this will be `x`.
|
||||
* If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
|
||||
*/
|
||||
majorParameter: string;
|
||||
/**
|
||||
* The HTTP method being performed
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before this specific request can be retried
|
||||
*/
|
||||
retryAfter: number;
|
||||
/**
|
||||
* The route being hit in this request
|
||||
*/
|
||||
route: string;
|
||||
/**
|
||||
* The scope of the rate limit that was hit.
|
||||
*
|
||||
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
|
||||
* are shared per resource.
|
||||
*/
|
||||
scope: 'global' | 'shared' | 'user';
|
||||
/**
|
||||
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
|
||||
* can be retried
|
||||
*
|
||||
* This is only present on certain sublimits, and `0` otherwise
|
||||
*/
|
||||
sublimitTimeout: number;
|
||||
/**
|
||||
* The time, in milliseconds, until the route's request-lock is reset
|
||||
*/
|
||||
timeToReset: number;
|
||||
/**
|
||||
* The full URL for this request
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
/**
|
||||
* A function that determines whether the rate limit hit should throw an Error
|
||||
*/
|
||||
type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
|
||||
/**
|
||||
* A function that determines the rate limit offset for a given request.
|
||||
*/
|
||||
type GetRateLimitOffsetFunction = (route: string) => number;
|
||||
interface APIRequest {
|
||||
/**
|
||||
* The data that was used to form the body of this request
|
||||
*/
|
||||
data: HandlerRequestData;
|
||||
/**
|
||||
* The HTTP method used in this request
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* Additional HTTP options for this request
|
||||
*/
|
||||
options: RequestInit;
|
||||
/**
|
||||
* The full path used to make the request
|
||||
*/
|
||||
path: RouteLike;
|
||||
/**
|
||||
* The number of times this request has been attempted
|
||||
*/
|
||||
retries: number;
|
||||
/**
|
||||
* The API route identifying the ratelimit for this request
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
|
||||
body: Readable | ReadableStream | null;
|
||||
}
|
||||
interface InvalidRequestWarningData {
|
||||
/**
|
||||
* Number of invalid requests that have been made in the window
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* Time in milliseconds remaining before the count resets
|
||||
*/
|
||||
remainingTime: number;
|
||||
}
|
||||
/**
|
||||
* Represents a file to be added to the request
|
||||
*/
|
||||
interface RawFile {
|
||||
/**
|
||||
* Content-Type of the file
|
||||
*/
|
||||
contentType?: string;
|
||||
/**
|
||||
* The actual data for the file
|
||||
*/
|
||||
data: Buffer | Uint8Array | boolean | number | string;
|
||||
/**
|
||||
* An explicit key to use for key of the formdata field for this file.
|
||||
* When not provided, the index of the file in the files array is used in the form `files[${index}]`.
|
||||
* If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* The name of the file
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents possible data to be given to an endpoint
|
||||
*/
|
||||
interface RequestData {
|
||||
/**
|
||||
* Whether to append JSON data to form data instead of `payload_json` when sending files
|
||||
*/
|
||||
appendToFormData?: boolean;
|
||||
/**
|
||||
* If this request needs the `Authorization` header
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
auth?: boolean;
|
||||
/**
|
||||
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
||||
*
|
||||
* @defaultValue `'Bot'`
|
||||
*/
|
||||
authPrefix?: 'Bearer' | 'Bot';
|
||||
/**
|
||||
* The body to send to this request.
|
||||
* If providing as BodyInit, set `passThroughBody: true`
|
||||
*/
|
||||
body?: BodyInit | unknown;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||
*/
|
||||
dispatcher?: Agent;
|
||||
/**
|
||||
* Files to be attached to this request
|
||||
*/
|
||||
files?: RawFile[] | undefined;
|
||||
/**
|
||||
* Additional headers to add to this request
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
/**
|
||||
* Whether to pass-through the body property directly to `fetch()`.
|
||||
* <warn>This only applies when files is NOT present</warn>
|
||||
*/
|
||||
passThroughBody?: boolean;
|
||||
/**
|
||||
* Query string parameters to append to the called endpoint
|
||||
*/
|
||||
query?: URLSearchParams;
|
||||
/**
|
||||
* Reason to show in the audit logs
|
||||
*/
|
||||
reason?: string | undefined;
|
||||
/**
|
||||
* The signal to abort the queue entry or the REST call, where applicable
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/**
|
||||
* If this request should be versioned
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
versioned?: boolean;
|
||||
}
|
||||
/**
|
||||
* Possible headers for an API call
|
||||
*/
|
||||
interface RequestHeaders {
|
||||
Authorization?: string;
|
||||
'User-Agent': string;
|
||||
'X-Audit-Log-Reason'?: string;
|
||||
}
|
||||
/**
|
||||
* Possible API methods to be used when doing requests
|
||||
*/
|
||||
declare enum RequestMethod {
|
||||
Delete = "DELETE",
|
||||
Get = "GET",
|
||||
Patch = "PATCH",
|
||||
Post = "POST",
|
||||
Put = "PUT"
|
||||
}
|
||||
type RouteLike = `/${string}`;
|
||||
/**
|
||||
* Internal request options
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface InternalRequest extends RequestData {
|
||||
fullRoute: RouteLike;
|
||||
method: RequestMethod;
|
||||
}
|
||||
type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
|
||||
/**
|
||||
* Parsed route data for an endpoint
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface RouteData {
|
||||
bucketRoute: string;
|
||||
majorParameter: string;
|
||||
original: RouteLike;
|
||||
}
|
||||
/**
|
||||
* Represents a hash and its associated fields
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface HashData {
|
||||
lastAccess: number;
|
||||
value: string;
|
||||
}
|
||||
|
||||
declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`;
|
||||
/**
|
||||
* The default string to append onto the user agent.
|
||||
*/
|
||||
declare const DefaultUserAgentAppendix: string;
|
||||
declare const DefaultRestOptions: {
|
||||
readonly agent: null;
|
||||
readonly api: "https://discord.com/api";
|
||||
readonly authPrefix: "Bot";
|
||||
readonly cdn: "https://cdn.discordapp.com";
|
||||
readonly headers: {};
|
||||
readonly invalidRequestWarningInterval: 0;
|
||||
readonly globalRequestsPerSecond: 50;
|
||||
readonly offset: 50;
|
||||
readonly rejectOnRateLimit: null;
|
||||
readonly retries: 3;
|
||||
readonly timeout: 15000;
|
||||
readonly userAgentAppendix: string;
|
||||
readonly version: "10";
|
||||
readonly hashSweepInterval: 14400000;
|
||||
readonly hashLifetime: 86400000;
|
||||
readonly handlerSweepInterval: 3600000;
|
||||
readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>;
|
||||
};
|
||||
/**
|
||||
* The events that the REST manager emits
|
||||
*/
|
||||
declare enum RESTEvents {
|
||||
Debug = "restDebug",
|
||||
HandlerSweep = "handlerSweep",
|
||||
HashSweep = "hashSweep",
|
||||
InvalidRequestWarning = "invalidRequestWarning",
|
||||
RateLimited = "rateLimited",
|
||||
Response = "response"
|
||||
}
|
||||
declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
|
||||
declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
|
||||
declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
|
||||
type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];
|
||||
type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];
|
||||
type ImageSize = (typeof ALLOWED_SIZES)[number];
|
||||
declare const OverwrittenMimeTypes: {
|
||||
readonly 'image/apng': "image/png";
|
||||
};
|
||||
declare const BurstHandlerMajorIdKey = "burst";
|
||||
/**
|
||||
* Prefix for deprecation warnings.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
||||
|
||||
/**
|
||||
* The options used for image URLs
|
||||
*/
|
||||
interface BaseImageURLOptions {
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: ImageExtension;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The options used for image URLs with animated content
|
||||
*/
|
||||
interface ImageURLOptions extends BaseImageURLOptions {
|
||||
/**
|
||||
* Whether or not to prefer the static version of an image asset.
|
||||
*/
|
||||
forceStatic?: boolean;
|
||||
}
|
||||
/**
|
||||
* The options to use when making a CDN URL
|
||||
*/
|
||||
interface MakeURLOptions {
|
||||
/**
|
||||
* The allowed extensions that can be used
|
||||
*/
|
||||
allowedExtensions?: readonly string[];
|
||||
/**
|
||||
* The extension to use for the image URL
|
||||
*
|
||||
* @defaultValue `'webp'`
|
||||
*/
|
||||
extension?: string | undefined;
|
||||
/**
|
||||
* The size specified in the image URL
|
||||
*/
|
||||
size?: ImageSize;
|
||||
}
|
||||
/**
|
||||
* The CDN link builder
|
||||
*/
|
||||
declare class CDN {
|
||||
private readonly base;
|
||||
constructor(base?: string);
|
||||
/**
|
||||
* Generates an app asset URL for a client's asset.
|
||||
*
|
||||
* @param clientId - The client id that has the asset
|
||||
* @param assetHash - The hash provided by Discord for this asset
|
||||
* @param options - Optional options for the asset
|
||||
*/
|
||||
appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an app icon URL for a client's icon.
|
||||
*
|
||||
* @param clientId - The client id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an avatar URL, e.g. for a user or a webhook.
|
||||
*
|
||||
* @param id - The id that has the icon
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a user avatar decoration URL.
|
||||
*
|
||||
* @param userId - The id of the user
|
||||
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
||||
* @param options - Optional options for the avatar decoration
|
||||
*/
|
||||
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a banner URL, e.g. for a user or a guild.
|
||||
*
|
||||
* @param id - The id that has the banner splash
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL for a channel, e.g. a group DM.
|
||||
*
|
||||
* @param channelId - The channel id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this channel
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a default avatar URL
|
||||
*
|
||||
* @param index - The default avatar index
|
||||
* @remarks
|
||||
* To calculate the index for a user do `(userId >> 22) % 6`,
|
||||
* or `discriminator % 5` if they're using the legacy username system.
|
||||
*/
|
||||
defaultAvatar(index: number): string;
|
||||
/**
|
||||
* Generates a discovery splash URL for a guild's discovery splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the discovery splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param options - Optional options for the emoji
|
||||
*/
|
||||
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param extension - The extension of the emoji
|
||||
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
||||
*/
|
||||
emoji(emojiId: string, extension?: ImageExtension): string;
|
||||
/**
|
||||
* Generates a guild member avatar URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param avatarHash - The hash provided by Discord for this avatar
|
||||
* @param options - Optional options for the avatar
|
||||
*/
|
||||
guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild member banner URL.
|
||||
*
|
||||
* @param guildId - The id of the guild
|
||||
* @param userId - The id of the user
|
||||
* @param bannerHash - The hash provided by Discord for this banner
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates an icon URL, e.g. for a guild.
|
||||
*
|
||||
* @param id - The id that has the icon splash
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a URL for the icon of a role
|
||||
*
|
||||
* @param roleId - The id of the role that has the icon
|
||||
* @param roleIconHash - The hash provided by Discord for this role icon
|
||||
* @param options - Optional options for the role icon
|
||||
*/
|
||||
roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a guild invite splash URL for a guild's invite splash.
|
||||
*
|
||||
* @param guildId - The guild id that has the invite splash
|
||||
* @param splashHash - The hash provided by Discord for this splash
|
||||
* @param options - Optional options for the splash
|
||||
*/
|
||||
splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a sticker URL.
|
||||
*
|
||||
* @param stickerId - The sticker id
|
||||
* @param extension - The extension of the sticker
|
||||
* @privateRemarks
|
||||
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
||||
*/
|
||||
sticker(stickerId: string, extension?: StickerExtension): string;
|
||||
/**
|
||||
* Generates a sticker pack banner URL.
|
||||
*
|
||||
* @param bannerId - The banner id
|
||||
* @param options - Optional options for the banner
|
||||
*/
|
||||
stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a team icon URL for a team's icon.
|
||||
*
|
||||
* @param teamId - The team id that has the icon
|
||||
* @param iconHash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the icon
|
||||
*/
|
||||
teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Generates a cover image for a guild scheduled event.
|
||||
*
|
||||
* @param scheduledEventId - The scheduled event id
|
||||
* @param coverHash - The hash provided by discord for this cover image
|
||||
* @param options - Optional options for the cover image
|
||||
*/
|
||||
guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
/**
|
||||
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param hash - The hash provided by Discord for this icon
|
||||
* @param options - Optional options for the link
|
||||
*/
|
||||
private dynamicMakeURL;
|
||||
/**
|
||||
* Constructs the URL for the resource
|
||||
*
|
||||
* @param route - The base cdn route
|
||||
* @param options - The extension/size options for the link
|
||||
*/
|
||||
private makeURL;
|
||||
}
|
||||
|
||||
interface DiscordErrorFieldInformation {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
interface DiscordErrorGroupWrapper {
|
||||
_errors: DiscordError[];
|
||||
}
|
||||
type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | {
|
||||
[k: string]: DiscordError;
|
||||
};
|
||||
interface DiscordErrorData {
|
||||
code: number;
|
||||
errors?: DiscordError;
|
||||
message: string;
|
||||
}
|
||||
interface OAuthErrorData {
|
||||
error: string;
|
||||
error_description?: string;
|
||||
}
|
||||
interface RequestBody {
|
||||
files: RawFile[] | undefined;
|
||||
json: unknown | undefined;
|
||||
}
|
||||
/**
|
||||
* Represents an API error returned by Discord
|
||||
*/
|
||||
declare class DiscordAPIError extends Error {
|
||||
rawError: DiscordErrorData | OAuthErrorData;
|
||||
code: number | string;
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
/**
|
||||
* @param rawError - The error reported by Discord
|
||||
* @param code - The error code reported by Discord
|
||||
* @param status - The status code of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
private static getMessage;
|
||||
private static flattenDiscordError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a HTTP error
|
||||
*/
|
||||
declare class HTTPError extends Error {
|
||||
status: number;
|
||||
method: string;
|
||||
url: string;
|
||||
requestBody: RequestBody;
|
||||
name: string;
|
||||
/**
|
||||
* @param status - The status code of the response
|
||||
* @param statusText - The status text of the response
|
||||
* @param method - The method of the request that erred
|
||||
* @param url - The url of the request that erred
|
||||
* @param bodyData - The unparsed data for the request that errored
|
||||
*/
|
||||
constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>);
|
||||
}
|
||||
|
||||
declare class RateLimitError extends Error implements RateLimitData {
|
||||
timeToReset: number;
|
||||
limit: number;
|
||||
method: string;
|
||||
hash: string;
|
||||
url: string;
|
||||
route: string;
|
||||
majorParameter: string;
|
||||
global: boolean;
|
||||
retryAfter: number;
|
||||
sublimitTimeout: number;
|
||||
scope: RateLimitData['scope'];
|
||||
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
|
||||
/**
|
||||
* The name of the error
|
||||
*/
|
||||
get name(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the class that manages handlers for endpoints
|
||||
*/
|
||||
declare class REST extends AsyncEventEmitter<RestEvents> {
|
||||
#private;
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
||||
* performed by this manager.
|
||||
*/
|
||||
agent: Dispatcher | null;
|
||||
readonly cdn: CDN;
|
||||
/**
|
||||
* The number of requests remaining in the global bucket
|
||||
*/
|
||||
globalRemaining: number;
|
||||
/**
|
||||
* The promise used to wait out the global rate limit
|
||||
*/
|
||||
globalDelay: Promise<void> | null;
|
||||
/**
|
||||
* The timestamp at which the global bucket resets
|
||||
*/
|
||||
globalReset: number;
|
||||
/**
|
||||
* API bucket hashes that are cached from provided routes
|
||||
*/
|
||||
readonly hashes: Collection<string, HashData>;
|
||||
/**
|
||||
* Request handlers created from the bucket hash and the major parameters
|
||||
*/
|
||||
readonly handlers: Collection<string, IHandler>;
|
||||
private hashTimer;
|
||||
private handlerTimer;
|
||||
readonly options: RESTOptions;
|
||||
constructor(options?: Partial<RESTOptions>);
|
||||
private setupSweepers;
|
||||
/**
|
||||
* Runs a get request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a delete request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a post request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a put request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a patch request from the api
|
||||
*
|
||||
* @param fullRoute - The full route to query
|
||||
* @param options - Optional request options
|
||||
*/
|
||||
patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
|
||||
/**
|
||||
* Runs a request from the api
|
||||
*
|
||||
* @param options - Request options
|
||||
*/
|
||||
request(options: InternalRequest): Promise<unknown>;
|
||||
/**
|
||||
* Sets the default agent to use for requests performed by this manager
|
||||
*
|
||||
* @param agent - The agent to use
|
||||
*/
|
||||
setAgent(agent: Dispatcher): this;
|
||||
/**
|
||||
* Sets the authorization token that should be used for requests
|
||||
*
|
||||
* @param token - The authorization token to use
|
||||
*/
|
||||
setToken(token: string): this;
|
||||
/**
|
||||
* Queues a request to be sent
|
||||
*
|
||||
* @param request - All the information needed to make a request
|
||||
* @returns The response from the api request
|
||||
*/
|
||||
queueRequest(request: InternalRequest): Promise<ResponseLike>;
|
||||
/**
|
||||
* Creates a new rate limit handler from a hash, based on the hash and the major parameter
|
||||
*
|
||||
* @param hash - The hash for the route
|
||||
* @param majorParameter - The major parameter for this handler
|
||||
* @internal
|
||||
*/
|
||||
private createHandler;
|
||||
/**
|
||||
* Formats the request data to a usable format for fetch
|
||||
*
|
||||
* @param request - The request data
|
||||
*/
|
||||
private resolveRequest;
|
||||
/**
|
||||
* Stops the hash sweeping interval
|
||||
*/
|
||||
clearHashSweeper(): void;
|
||||
/**
|
||||
* Stops the request handler sweeping interval
|
||||
*/
|
||||
clearHandlerSweeper(): void;
|
||||
/**
|
||||
* Generates route data for an endpoint:method
|
||||
*
|
||||
* @param endpoint - The raw endpoint to generalize
|
||||
* @param method - The HTTP method this endpoint is called without
|
||||
* @internal
|
||||
*/
|
||||
private static generateRouteData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and populates an URLSearchParams instance from an object, stripping
|
||||
* out null and undefined values, while also coercing non-strings to strings.
|
||||
*
|
||||
* @param options - The options to use
|
||||
* @returns A populated URLSearchParams instance
|
||||
*/
|
||||
declare function makeURLSearchParams<OptionsType extends object>(options?: Readonly<OptionsType>): url.URLSearchParams;
|
||||
/**
|
||||
* Converts the response to usable data
|
||||
*
|
||||
* @param res - The fetch response
|
||||
*/
|
||||
declare function parseResponse(res: ResponseLike): Promise<unknown>;
|
||||
/**
|
||||
* Calculates the default avatar index for a given user id.
|
||||
*
|
||||
* @param userId - The user id to calculate the default avatar index for
|
||||
*/
|
||||
declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest#readme | @discordjs/rest} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
1418
node_modules/@discordjs/rest/dist/web.js
generated
vendored
Normal file
1418
node_modules/@discordjs/rest/dist/web.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@discordjs/rest/dist/web.js.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/web.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1374
node_modules/@discordjs/rest/dist/web.mjs
generated
vendored
Normal file
1374
node_modules/@discordjs/rest/dist/web.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@discordjs/rest/dist/web.mjs.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/dist/web.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
191
node_modules/@discordjs/rest/node_modules/@discordjs/collection/LICENSE
generated
vendored
Normal file
191
node_modules/@discordjs/rest/node_modules/@discordjs/collection/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,191 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2021 Noel Buechler
|
||||
Copyright 2015 Amish Shah
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
67
node_modules/@discordjs/rest/node_modules/@discordjs/collection/README.md
generated
vendored
Normal file
67
node_modules/@discordjs/rest/node_modules/@discordjs/collection/README.md
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
<div align="center">
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
|
||||
<a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/v/@discordjs/collection.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/dt/@discordjs/collection.svg?maxAge=3600" alt="npm downloads" /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=collection" alt="Code coverage" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
|
||||
<a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## About
|
||||
|
||||
`@discordjs/collection` is a powerful utility data structure used in discord.js.
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 18 or newer is required.**
|
||||
|
||||
```sh
|
||||
npm install @discordjs/collection
|
||||
yarn add @discordjs/collection
|
||||
pnpm add @discordjs/collection
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Website][website] ([source][website-source])
|
||||
- [Documentation][documentation]
|
||||
- [Guide][guide] ([source][guide-source])
|
||||
Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library.
|
||||
- [discord.js Discord server][discord]
|
||||
- [Discord API Discord server][discord-api]
|
||||
- [GitHub][source]
|
||||
- [npm][npm]
|
||||
- [Related libraries][related-libs]
|
||||
|
||||
## Contributing
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation][documentation].
|
||||
See [the contribution guide][contributing] if you'd like to submit a PR.
|
||||
|
||||
## Help
|
||||
|
||||
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord].
|
||||
|
||||
[website]: https://discord.js.org
|
||||
[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website
|
||||
[documentation]: https://discord.js.org/docs/packages/collection/stable
|
||||
[guide]: https://discordjs.guide/
|
||||
[guide-source]: https://github.com/discordjs/guide
|
||||
[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
|
||||
[discord]: https://discord.gg/djs
|
||||
[discord-api]: https://discord.gg/discord-api
|
||||
[source]: https://github.com/discordjs/discord.js/tree/main/packages/collection
|
||||
[npm]: https://www.npmjs.com/package/@discordjs/collection
|
||||
[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries
|
||||
[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
|
535
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.d.mts
generated
vendored
Normal file
535
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.d.mts
generated
vendored
Normal file
|
@ -0,0 +1,535 @@
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface CollectionConstructor {
|
||||
new (): Collection<unknown, unknown>;
|
||||
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
|
||||
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
|
||||
readonly prototype: Collection<unknown, unknown>;
|
||||
readonly [Symbol.species]: CollectionConstructor;
|
||||
}
|
||||
/**
|
||||
* Represents an immutable version of a collection
|
||||
*/
|
||||
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
|
||||
/**
|
||||
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface Collection<Key, Value> extends Map<Key, Value> {
|
||||
constructor: CollectionConstructor;
|
||||
}
|
||||
/**
|
||||
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
||||
* an ID, for significantly improved performance and ease-of-use.
|
||||
*
|
||||
* @typeParam Key - The key type this collection holds
|
||||
* @typeParam Value - The value type this collection holds
|
||||
*/
|
||||
declare class Collection<Key, Value> extends Map<Key, Value> {
|
||||
/**
|
||||
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
||||
*
|
||||
* @param key - The key to get if it exists, or set otherwise
|
||||
* @param defaultValueGenerator - A function that generates the default value
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||
* ```
|
||||
*/
|
||||
ensure(key: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
|
||||
/**
|
||||
* Checks if all of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
||||
*/
|
||||
hasAll(...keys: Key[]): boolean;
|
||||
/**
|
||||
* Checks if any of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if any of the elements exist, `false` if none exist.
|
||||
*/
|
||||
hasAny(...keys: Key[]): boolean;
|
||||
/**
|
||||
* Obtains the first value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the beginning
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
|
||||
*/
|
||||
first(): Value | undefined;
|
||||
first(amount: number): Value[];
|
||||
/**
|
||||
* Obtains the first key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the beginning
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the end if
|
||||
* amount is negative
|
||||
*/
|
||||
firstKey(): Key | undefined;
|
||||
firstKey(amount: number): Key[];
|
||||
/**
|
||||
* Obtains the last value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the end
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
last(): Value | undefined;
|
||||
last(amount: number): Value[];
|
||||
/**
|
||||
* Obtains the last key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the end
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
lastKey(): Key | undefined;
|
||||
lastKey(amount: number): Key[];
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the item at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the element to obtain
|
||||
*/
|
||||
at(index: number): Value | undefined;
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the key at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the key to obtain
|
||||
*/
|
||||
keyAt(index: number): Key | undefined;
|
||||
/**
|
||||
* Obtains unique random value(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain randomly
|
||||
* @returns A single value if no amount is provided or an array of values
|
||||
*/
|
||||
random(): Value | undefined;
|
||||
random(amount: number): Value[];
|
||||
/**
|
||||
* Obtains unique random key(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain randomly
|
||||
* @returns A single key if no amount is provided or an array
|
||||
*/
|
||||
randomKey(): Key | undefined;
|
||||
randomKey(amount: number): Key[];
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
reverse(): this;
|
||||
/**
|
||||
* Searches for a single item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}.
|
||||
* All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you
|
||||
* should use the `get` method. See
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.find(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
|
||||
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
|
||||
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
|
||||
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
|
||||
/**
|
||||
* Searches for the key of a single item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
|
||||
* but returns the key rather than the positional index.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.findKey(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
|
||||
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
|
||||
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
|
||||
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
|
||||
/**
|
||||
* Searches for a last item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast | Array.findLast()}.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
*/
|
||||
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
|
||||
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
|
||||
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
|
||||
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
|
||||
/**
|
||||
* Searches for the key of a last item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | Array.findLastIndex()},
|
||||
* but returns the key rather than the positional index.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
*/
|
||||
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
|
||||
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
|
||||
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
|
||||
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
|
||||
/**
|
||||
* Removes items that satisfy the provided filter function.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @returns The number of removed entries
|
||||
*/
|
||||
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
|
||||
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): number;
|
||||
/**
|
||||
* Identical to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
|
||||
* but returns a Collection instead of an Array.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.filter(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
|
||||
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
|
||||
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
|
||||
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
|
||||
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
|
||||
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
|
||||
/**
|
||||
* Partitions the collection into two collections where the first collection
|
||||
* contains the items that passed and the second contains the items that failed.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
||||
* ```
|
||||
*/
|
||||
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
|
||||
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
|
||||
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
|
||||
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
|
||||
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
|
||||
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
|
||||
/**
|
||||
* Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
|
||||
*
|
||||
* @param fn - Function that produces a new Collection
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.flatMap(guild => guild.members.cache);
|
||||
* ```
|
||||
*/
|
||||
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
|
||||
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
|
||||
/**
|
||||
* Maps each item to another value into an array. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
||||
*
|
||||
* @param fn - Function that produces an element of the new array, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.map(user => user.tag);
|
||||
* ```
|
||||
*/
|
||||
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
|
||||
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
|
||||
/**
|
||||
* Maps each item to another value into a collection. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
||||
*
|
||||
* @param fn - Function that produces an element of the new collection, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.mapValues(user => user.tag);
|
||||
* ```
|
||||
*/
|
||||
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
|
||||
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
|
||||
/**
|
||||
* Checks if there exists an item that passes a test. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.some(user => user.discriminator === '0000');
|
||||
* ```
|
||||
*/
|
||||
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
|
||||
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
|
||||
/**
|
||||
* Checks if all items passes a test. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.every(user => !user.bot);
|
||||
* ```
|
||||
*/
|
||||
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
|
||||
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
|
||||
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
|
||||
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
|
||||
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
|
||||
every<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
* ```
|
||||
*/
|
||||
reduce<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
*/
|
||||
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
||||
/**
|
||||
* Identical to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
|
||||
* but returns the collection instead of undefined.
|
||||
*
|
||||
* @param fn - Function to execute for each element
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
* .each(user => console.log(user.username))
|
||||
* .filter(user => user.bot)
|
||||
* .each(user => console.log(user.username));
|
||||
* ```
|
||||
*/
|
||||
each(fn: (value: Value, key: Key, collection: this) => void): this;
|
||||
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): this;
|
||||
/**
|
||||
* Runs a function on the collection and returns the collection.
|
||||
*
|
||||
* @param fn - Function to execute
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
* .tap(coll => console.log(coll.size))
|
||||
* .filter(user => user.bot)
|
||||
* .tap(coll => console.log(coll.size))
|
||||
* ```
|
||||
*/
|
||||
tap(fn: (collection: this) => void): this;
|
||||
tap<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.clone();
|
||||
* ```
|
||||
*/
|
||||
clone(): Collection<Key, Value>;
|
||||
/**
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
*
|
||||
* @param collections - Collections to merge
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
* ```
|
||||
*/
|
||||
concat(...collections: ReadonlyCollection<Key, Value>[]): Collection<Key, Value>;
|
||||
/**
|
||||
* Checks if this collection shares identical items with another.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but contain the same data.
|
||||
*
|
||||
* @param collection - Collection to compare with
|
||||
* @returns Whether the collections have identical contents
|
||||
*/
|
||||
equals(collection: ReadonlyCollection<Key, Value>): boolean;
|
||||
/**
|
||||
* The sort method sorts the items of a collection in place and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
sort(compareFunction?: Comparator<Key, Value>): this;
|
||||
/**
|
||||
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const intersection = col1.intersection(col2);
|
||||
* console.log(col1.intersection(col2));
|
||||
* // => Collection { 'a' => 1 }
|
||||
* ```
|
||||
*/
|
||||
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in either of the collections.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* If the collections have any items with the same key, the value from the first collection will be used.
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
||||
* const union = col1.union(col2);
|
||||
* console.log(union);
|
||||
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* console.log(col1.difference(col2));
|
||||
* // => Collection { 'b' => 2 }
|
||||
* console.log(col2.difference(col1));
|
||||
* // => Collection { 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
||||
/**
|
||||
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const symmetricDifference = col1.symmetricDifference(col2);
|
||||
* console.log(col1.symmetricDifference(col2));
|
||||
* // => Collection { 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
||||
/**
|
||||
* Merges two Collections together into a new Collection.
|
||||
*
|
||||
* @param other - The other Collection to merge with
|
||||
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
|
||||
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
|
||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||
* @example
|
||||
* ```ts
|
||||
* // Sums up the entries in two collections.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: true, value: x }),
|
||||
* y => ({ keep: true, value: y }),
|
||||
* (x, y) => ({ keep: true, value: x + y }),
|
||||
* );
|
||||
* ```
|
||||
* @example
|
||||
* ```ts
|
||||
* // Intersects two collections in a left-biased manner.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: false }),
|
||||
* y => ({ keep: false }),
|
||||
* (x, _) => ({ keep: true, value: x }),
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
merge<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
toReversed(): Collection<Key, Value>;
|
||||
/**
|
||||
* The sorted method sorts the items of a collection and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
|
||||
toJSON(): [Key, Value][];
|
||||
private static defaultSort;
|
||||
/**
|
||||
* Creates a Collection from a list of entries.
|
||||
*
|
||||
* @param entries - The list of entries
|
||||
* @param combine - Function to combine an existing entry with a new one
|
||||
* @example
|
||||
* ```ts
|
||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||
* // returns Collection { "a" => 3, "b" => 2 }
|
||||
* ```
|
||||
*/
|
||||
static combineEntries<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type Keep<Value> = {
|
||||
keep: false;
|
||||
} | {
|
||||
keep: true;
|
||||
value: Value;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection#readme | @discordjs/collection} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { Collection, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };
|
535
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.d.ts
generated
vendored
Normal file
535
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,535 @@
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface CollectionConstructor {
|
||||
new (): Collection<unknown, unknown>;
|
||||
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
|
||||
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
|
||||
readonly prototype: Collection<unknown, unknown>;
|
||||
readonly [Symbol.species]: CollectionConstructor;
|
||||
}
|
||||
/**
|
||||
* Represents an immutable version of a collection
|
||||
*/
|
||||
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
|
||||
/**
|
||||
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface Collection<Key, Value> extends Map<Key, Value> {
|
||||
constructor: CollectionConstructor;
|
||||
}
|
||||
/**
|
||||
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
||||
* an ID, for significantly improved performance and ease-of-use.
|
||||
*
|
||||
* @typeParam Key - The key type this collection holds
|
||||
* @typeParam Value - The value type this collection holds
|
||||
*/
|
||||
declare class Collection<Key, Value> extends Map<Key, Value> {
|
||||
/**
|
||||
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
||||
*
|
||||
* @param key - The key to get if it exists, or set otherwise
|
||||
* @param defaultValueGenerator - A function that generates the default value
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||
* ```
|
||||
*/
|
||||
ensure(key: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
|
||||
/**
|
||||
* Checks if all of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
||||
*/
|
||||
hasAll(...keys: Key[]): boolean;
|
||||
/**
|
||||
* Checks if any of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if any of the elements exist, `false` if none exist.
|
||||
*/
|
||||
hasAny(...keys: Key[]): boolean;
|
||||
/**
|
||||
* Obtains the first value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the beginning
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
|
||||
*/
|
||||
first(): Value | undefined;
|
||||
first(amount: number): Value[];
|
||||
/**
|
||||
* Obtains the first key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the beginning
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the end if
|
||||
* amount is negative
|
||||
*/
|
||||
firstKey(): Key | undefined;
|
||||
firstKey(amount: number): Key[];
|
||||
/**
|
||||
* Obtains the last value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the end
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
last(): Value | undefined;
|
||||
last(amount: number): Value[];
|
||||
/**
|
||||
* Obtains the last key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the end
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
lastKey(): Key | undefined;
|
||||
lastKey(amount: number): Key[];
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the item at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the element to obtain
|
||||
*/
|
||||
at(index: number): Value | undefined;
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the key at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the key to obtain
|
||||
*/
|
||||
keyAt(index: number): Key | undefined;
|
||||
/**
|
||||
* Obtains unique random value(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain randomly
|
||||
* @returns A single value if no amount is provided or an array of values
|
||||
*/
|
||||
random(): Value | undefined;
|
||||
random(amount: number): Value[];
|
||||
/**
|
||||
* Obtains unique random key(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain randomly
|
||||
* @returns A single key if no amount is provided or an array
|
||||
*/
|
||||
randomKey(): Key | undefined;
|
||||
randomKey(amount: number): Key[];
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
reverse(): this;
|
||||
/**
|
||||
* Searches for a single item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}.
|
||||
* All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you
|
||||
* should use the `get` method. See
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.find(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
|
||||
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
|
||||
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
|
||||
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
|
||||
/**
|
||||
* Searches for the key of a single item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},
|
||||
* but returns the key rather than the positional index.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.findKey(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
|
||||
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
|
||||
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
|
||||
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
|
||||
/**
|
||||
* Searches for a last item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast | Array.findLast()}.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
*/
|
||||
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
|
||||
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
|
||||
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
|
||||
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
|
||||
/**
|
||||
* Searches for the key of a last item where the given function returns a truthy value. This behaves like
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | Array.findLastIndex()},
|
||||
* but returns the key rather than the positional index.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
*/
|
||||
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
|
||||
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
|
||||
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
|
||||
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
|
||||
/**
|
||||
* Removes items that satisfy the provided filter function.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @returns The number of removed entries
|
||||
*/
|
||||
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
|
||||
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): number;
|
||||
/**
|
||||
* Identical to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},
|
||||
* but returns a Collection instead of an Array.
|
||||
*
|
||||
* @param fn - The function to test with (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.filter(user => user.username === 'Bob');
|
||||
* ```
|
||||
*/
|
||||
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
|
||||
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
|
||||
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
|
||||
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
|
||||
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
|
||||
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
|
||||
/**
|
||||
* Partitions the collection into two collections where the first collection
|
||||
* contains the items that passed and the second contains the items that failed.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
||||
* ```
|
||||
*/
|
||||
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
|
||||
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
|
||||
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
|
||||
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
|
||||
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
|
||||
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
|
||||
/**
|
||||
* Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.
|
||||
*
|
||||
* @param fn - Function that produces a new Collection
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.flatMap(guild => guild.members.cache);
|
||||
* ```
|
||||
*/
|
||||
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
|
||||
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
|
||||
/**
|
||||
* Maps each item to another value into an array. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
||||
*
|
||||
* @param fn - Function that produces an element of the new array, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.map(user => user.tag);
|
||||
* ```
|
||||
*/
|
||||
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
|
||||
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
|
||||
/**
|
||||
* Maps each item to another value into a collection. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.
|
||||
*
|
||||
* @param fn - Function that produces an element of the new collection, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.mapValues(user => user.tag);
|
||||
* ```
|
||||
*/
|
||||
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
|
||||
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
|
||||
/**
|
||||
* Checks if there exists an item that passes a test. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.some(user => user.discriminator === '0000');
|
||||
* ```
|
||||
*/
|
||||
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
|
||||
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
|
||||
/**
|
||||
* Checks if all items passes a test. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.every(user => !user.bot);
|
||||
* ```
|
||||
*/
|
||||
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
|
||||
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
|
||||
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
|
||||
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
|
||||
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
|
||||
every<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): boolean;
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
* ```
|
||||
*/
|
||||
reduce<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
*/
|
||||
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
|
||||
/**
|
||||
* Identical to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},
|
||||
* but returns the collection instead of undefined.
|
||||
*
|
||||
* @param fn - Function to execute for each element
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
* .each(user => console.log(user.username))
|
||||
* .filter(user => user.bot)
|
||||
* .each(user => console.log(user.username));
|
||||
* ```
|
||||
*/
|
||||
each(fn: (value: Value, key: Key, collection: this) => void): this;
|
||||
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): this;
|
||||
/**
|
||||
* Runs a function on the collection and returns the collection.
|
||||
*
|
||||
* @param fn - Function to execute
|
||||
* @param thisArg - Value to use as `this` when executing the function
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
* .tap(coll => console.log(coll.size))
|
||||
* .filter(user => user.bot)
|
||||
* .tap(coll => console.log(coll.size))
|
||||
* ```
|
||||
*/
|
||||
tap(fn: (collection: this) => void): this;
|
||||
tap<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.clone();
|
||||
* ```
|
||||
*/
|
||||
clone(): Collection<Key, Value>;
|
||||
/**
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
*
|
||||
* @param collections - Collections to merge
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
* ```
|
||||
*/
|
||||
concat(...collections: ReadonlyCollection<Key, Value>[]): Collection<Key, Value>;
|
||||
/**
|
||||
* Checks if this collection shares identical items with another.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but contain the same data.
|
||||
*
|
||||
* @param collection - Collection to compare with
|
||||
* @returns Whether the collections have identical contents
|
||||
*/
|
||||
equals(collection: ReadonlyCollection<Key, Value>): boolean;
|
||||
/**
|
||||
* The sort method sorts the items of a collection in place and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
sort(compareFunction?: Comparator<Key, Value>): this;
|
||||
/**
|
||||
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const intersection = col1.intersection(col2);
|
||||
* console.log(col1.intersection(col2));
|
||||
* // => Collection { 'a' => 1 }
|
||||
* ```
|
||||
*/
|
||||
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in either of the collections.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* If the collections have any items with the same key, the value from the first collection will be used.
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
||||
* const union = col1.union(col2);
|
||||
* console.log(union);
|
||||
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* console.log(col1.difference(col2));
|
||||
* // => Collection { 'b' => 2 }
|
||||
* console.log(col2.difference(col1));
|
||||
* // => Collection { 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
|
||||
/**
|
||||
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const symmetricDifference = col1.symmetricDifference(col2);
|
||||
* console.log(col1.symmetricDifference(col2));
|
||||
* // => Collection { 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
|
||||
/**
|
||||
* Merges two Collections together into a new Collection.
|
||||
*
|
||||
* @param other - The other Collection to merge with
|
||||
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
|
||||
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
|
||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||
* @example
|
||||
* ```ts
|
||||
* // Sums up the entries in two collections.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: true, value: x }),
|
||||
* y => ({ keep: true, value: y }),
|
||||
* (x, y) => ({ keep: true, value: x + y }),
|
||||
* );
|
||||
* ```
|
||||
* @example
|
||||
* ```ts
|
||||
* // Intersects two collections in a left-biased manner.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: false }),
|
||||
* y => ({ keep: false }),
|
||||
* (x, _) => ({ keep: true, value: x }),
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
merge<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
toReversed(): Collection<Key, Value>;
|
||||
/**
|
||||
* The sorted method sorts the items of a collection and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
|
||||
toJSON(): [Key, Value][];
|
||||
private static defaultSort;
|
||||
/**
|
||||
* Creates a Collection from a list of entries.
|
||||
*
|
||||
* @param entries - The list of entries
|
||||
* @param combine - Function to combine an existing entry with a new one
|
||||
* @example
|
||||
* ```ts
|
||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||
* // returns Collection { "a" => 3, "b" => 2 }
|
||||
* ```
|
||||
*/
|
||||
static combineEntries<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type Keep<Value> = {
|
||||
keep: false;
|
||||
} | {
|
||||
keep: true;
|
||||
value: Value;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => number;
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection#readme | @discordjs/collection} version
|
||||
* that you are currently using.
|
||||
*/
|
||||
declare const version: string;
|
||||
|
||||
export { Collection, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };
|
654
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.js
generated
vendored
Normal file
654
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.js
generated
vendored
Normal file
|
@ -0,0 +1,654 @@
|
|||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
Collection: () => Collection,
|
||||
version: () => version
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
|
||||
// src/collection.ts
|
||||
var Collection = class _Collection extends Map {
|
||||
static {
|
||||
__name(this, "Collection");
|
||||
}
|
||||
/**
|
||||
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
||||
*
|
||||
* @param key - The key to get if it exists, or set otherwise
|
||||
* @param defaultValueGenerator - A function that generates the default value
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||
* ```
|
||||
*/
|
||||
ensure(key, defaultValueGenerator) {
|
||||
if (this.has(key))
|
||||
return this.get(key);
|
||||
if (typeof defaultValueGenerator !== "function")
|
||||
throw new TypeError(`${defaultValueGenerator} is not a function`);
|
||||
const defaultValue = defaultValueGenerator(key, this);
|
||||
this.set(key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
/**
|
||||
* Checks if all of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
||||
*/
|
||||
hasAll(...keys) {
|
||||
return keys.every((key) => super.has(key));
|
||||
}
|
||||
/**
|
||||
* Checks if any of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if any of the elements exist, `false` if none exist.
|
||||
*/
|
||||
hasAny(...keys) {
|
||||
return keys.some((key) => super.has(key));
|
||||
}
|
||||
first(amount) {
|
||||
if (amount === void 0)
|
||||
return this.values().next().value;
|
||||
if (amount < 0)
|
||||
return this.last(amount * -1);
|
||||
amount = Math.min(this.size, amount);
|
||||
const iter = this.values();
|
||||
return Array.from({ length: amount }, () => iter.next().value);
|
||||
}
|
||||
firstKey(amount) {
|
||||
if (amount === void 0)
|
||||
return this.keys().next().value;
|
||||
if (amount < 0)
|
||||
return this.lastKey(amount * -1);
|
||||
amount = Math.min(this.size, amount);
|
||||
const iter = this.keys();
|
||||
return Array.from({ length: amount }, () => iter.next().value);
|
||||
}
|
||||
last(amount) {
|
||||
const arr = [...this.values()];
|
||||
if (amount === void 0)
|
||||
return arr[arr.length - 1];
|
||||
if (amount < 0)
|
||||
return this.first(amount * -1);
|
||||
if (!amount)
|
||||
return [];
|
||||
return arr.slice(-amount);
|
||||
}
|
||||
lastKey(amount) {
|
||||
const arr = [...this.keys()];
|
||||
if (amount === void 0)
|
||||
return arr[arr.length - 1];
|
||||
if (amount < 0)
|
||||
return this.firstKey(amount * -1);
|
||||
if (!amount)
|
||||
return [];
|
||||
return arr.slice(-amount);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the item at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the element to obtain
|
||||
*/
|
||||
at(index) {
|
||||
index = Math.floor(index);
|
||||
const arr = [...this.values()];
|
||||
return arr.at(index);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the key at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the key to obtain
|
||||
*/
|
||||
keyAt(index) {
|
||||
index = Math.floor(index);
|
||||
const arr = [...this.keys()];
|
||||
return arr.at(index);
|
||||
}
|
||||
random(amount) {
|
||||
const arr = [...this.values()];
|
||||
if (amount === void 0)
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!arr.length || !amount)
|
||||
return [];
|
||||
return Array.from(
|
||||
{ length: Math.min(amount, arr.length) },
|
||||
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
||||
);
|
||||
}
|
||||
randomKey(amount) {
|
||||
const arr = [...this.keys()];
|
||||
if (amount === void 0)
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!arr.length || !amount)
|
||||
return [];
|
||||
return Array.from(
|
||||
{ length: Math.min(amount, arr.length) },
|
||||
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
reverse() {
|
||||
const entries = [...this.entries()].reverse();
|
||||
this.clear();
|
||||
for (const [key, value] of entries)
|
||||
this.set(key, value);
|
||||
return this;
|
||||
}
|
||||
find(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return val;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findKey(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return key;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findLast(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const entries = [...this.entries()];
|
||||
for (let index = entries.length - 1; index >= 0; index--) {
|
||||
const val = entries[index][1];
|
||||
const key = entries[index][0];
|
||||
if (fn(val, key, this))
|
||||
return val;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findLastKey(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const entries = [...this.entries()];
|
||||
for (let index = entries.length - 1; index >= 0; index--) {
|
||||
const key = entries[index][0];
|
||||
const val = entries[index][1];
|
||||
if (fn(val, key, this))
|
||||
return key;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
sweep(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const previousSize = this.size;
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
this.delete(key);
|
||||
}
|
||||
return previousSize - this.size;
|
||||
}
|
||||
filter(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const results = new this.constructor[Symbol.species]();
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
results.set(key, val);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
partition(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const results = [
|
||||
new this.constructor[Symbol.species](),
|
||||
new this.constructor[Symbol.species]()
|
||||
];
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) {
|
||||
results[0].set(key, val);
|
||||
} else {
|
||||
results[1].set(key, val);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
flatMap(fn, thisArg) {
|
||||
const collections = this.map(fn, thisArg);
|
||||
return new this.constructor[Symbol.species]().concat(...collections);
|
||||
}
|
||||
map(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const iter = this.entries();
|
||||
return Array.from({ length: this.size }, () => {
|
||||
const [key, value] = iter.next().value;
|
||||
return fn(value, key, this);
|
||||
});
|
||||
}
|
||||
mapValues(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, val] of this)
|
||||
coll.set(key, fn(val, key, this));
|
||||
return coll;
|
||||
}
|
||||
some(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
every(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (!fn(val, key, this))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
* ```
|
||||
*/
|
||||
reduce(fn, initialValue) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
let accumulator;
|
||||
const iterator = this.entries();
|
||||
if (initialValue === void 0) {
|
||||
if (this.size === 0)
|
||||
throw new TypeError("Reduce of empty collection with no initial value");
|
||||
accumulator = iterator.next().value[1];
|
||||
} else {
|
||||
accumulator = initialValue;
|
||||
}
|
||||
for (const [key, value] of iterator) {
|
||||
accumulator = fn(accumulator, value, key, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
*/
|
||||
reduceRight(fn, initialValue) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
const entries = [...this.entries()];
|
||||
let accumulator;
|
||||
let index;
|
||||
if (initialValue === void 0) {
|
||||
if (entries.length === 0)
|
||||
throw new TypeError("Reduce of empty collection with no initial value");
|
||||
accumulator = entries[entries.length - 1][1];
|
||||
index = entries.length - 1;
|
||||
} else {
|
||||
accumulator = initialValue;
|
||||
index = entries.length;
|
||||
}
|
||||
while (--index >= 0) {
|
||||
const key = entries[index][0];
|
||||
const val = entries[index][1];
|
||||
accumulator = fn(accumulator, val, key, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
each(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, value] of this) {
|
||||
fn(value, key, this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
tap(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
fn(this);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.clone();
|
||||
* ```
|
||||
*/
|
||||
clone() {
|
||||
return new this.constructor[Symbol.species](this);
|
||||
}
|
||||
/**
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
*
|
||||
* @param collections - Collections to merge
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
* ```
|
||||
*/
|
||||
concat(...collections) {
|
||||
const newColl = this.clone();
|
||||
for (const coll of collections) {
|
||||
for (const [key, val] of coll)
|
||||
newColl.set(key, val);
|
||||
}
|
||||
return newColl;
|
||||
}
|
||||
/**
|
||||
* Checks if this collection shares identical items with another.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but contain the same data.
|
||||
*
|
||||
* @param collection - Collection to compare with
|
||||
* @returns Whether the collections have identical contents
|
||||
*/
|
||||
equals(collection) {
|
||||
if (!collection)
|
||||
return false;
|
||||
if (this === collection)
|
||||
return true;
|
||||
if (this.size !== collection.size)
|
||||
return false;
|
||||
for (const [key, value] of this) {
|
||||
if (!collection.has(key) || value !== collection.get(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The sort method sorts the items of a collection in place and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
sort(compareFunction = _Collection.defaultSort) {
|
||||
const entries = [...this.entries()];
|
||||
entries.sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]));
|
||||
super.clear();
|
||||
for (const [key, value] of entries) {
|
||||
super.set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const intersection = col1.intersection(col2);
|
||||
* console.log(col1.intersection(col2));
|
||||
* // => Collection { 'a' => 1 }
|
||||
* ```
|
||||
*/
|
||||
intersection(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in either of the collections.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* If the collections have any items with the same key, the value from the first collection will be used.
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
||||
* const union = col1.union(col2);
|
||||
* console.log(union);
|
||||
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
union(other) {
|
||||
const coll = new this.constructor[Symbol.species](this);
|
||||
for (const [key, value] of other) {
|
||||
if (!coll.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* console.log(col1.difference(col2));
|
||||
* // => Collection { 'b' => 2 }
|
||||
* console.log(col2.difference(col1));
|
||||
* // => Collection { 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
difference(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (!other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const symmetricDifference = col1.symmetricDifference(col2);
|
||||
* console.log(col1.symmetricDifference(col2));
|
||||
* // => Collection { 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
symmetricDifference(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (!other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
for (const [key, value] of other) {
|
||||
if (!this.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Merges two Collections together into a new Collection.
|
||||
*
|
||||
* @param other - The other Collection to merge with
|
||||
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
|
||||
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
|
||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||
* @example
|
||||
* ```ts
|
||||
* // Sums up the entries in two collections.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: true, value: x }),
|
||||
* y => ({ keep: true, value: y }),
|
||||
* (x, y) => ({ keep: true, value: x + y }),
|
||||
* );
|
||||
* ```
|
||||
* @example
|
||||
* ```ts
|
||||
* // Intersects two collections in a left-biased manner.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: false }),
|
||||
* y => ({ keep: false }),
|
||||
* (x, _) => ({ keep: true, value: x }),
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
merge(other, whenInSelf, whenInOther, whenInBoth) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
const keys = /* @__PURE__ */ new Set([...this.keys(), ...other.keys()]);
|
||||
for (const key of keys) {
|
||||
const hasInSelf = this.has(key);
|
||||
const hasInOther = other.has(key);
|
||||
if (hasInSelf && hasInOther) {
|
||||
const result = whenInBoth(this.get(key), other.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
} else if (hasInSelf) {
|
||||
const result = whenInSelf(this.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
} else if (hasInOther) {
|
||||
const result = whenInOther(other.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
}
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
toReversed() {
|
||||
return new this.constructor[Symbol.species](this).reverse();
|
||||
}
|
||||
/**
|
||||
* The sorted method sorts the items of a collection and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
toSorted(compareFunction = _Collection.defaultSort) {
|
||||
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
|
||||
}
|
||||
toJSON() {
|
||||
return [...this.entries()];
|
||||
}
|
||||
static defaultSort(firstValue, secondValue) {
|
||||
return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;
|
||||
}
|
||||
/**
|
||||
* Creates a Collection from a list of entries.
|
||||
*
|
||||
* @param entries - The list of entries
|
||||
* @param combine - Function to combine an existing entry with a new one
|
||||
* @example
|
||||
* ```ts
|
||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||
* // returns Collection { "a" => 3, "b" => 2 }
|
||||
* ```
|
||||
*/
|
||||
static combineEntries(entries, combine) {
|
||||
const coll = new _Collection();
|
||||
for (const [key, value] of entries) {
|
||||
if (coll.has(key)) {
|
||||
coll.set(key, combine(coll.get(key), value, key));
|
||||
} else {
|
||||
coll.set(key, value);
|
||||
}
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var version = "2.1.0";
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Collection,
|
||||
version
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
628
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.mjs
generated
vendored
Normal file
628
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.mjs
generated
vendored
Normal file
|
@ -0,0 +1,628 @@
|
|||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
// src/collection.ts
|
||||
var Collection = class _Collection extends Map {
|
||||
static {
|
||||
__name(this, "Collection");
|
||||
}
|
||||
/**
|
||||
* Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
|
||||
*
|
||||
* @param key - The key to get if it exists, or set otherwise
|
||||
* @param defaultValueGenerator - A function that generates the default value
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||
* ```
|
||||
*/
|
||||
ensure(key, defaultValueGenerator) {
|
||||
if (this.has(key))
|
||||
return this.get(key);
|
||||
if (typeof defaultValueGenerator !== "function")
|
||||
throw new TypeError(`${defaultValueGenerator} is not a function`);
|
||||
const defaultValue = defaultValueGenerator(key, this);
|
||||
this.set(key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
/**
|
||||
* Checks if all of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
||||
*/
|
||||
hasAll(...keys) {
|
||||
return keys.every((key) => super.has(key));
|
||||
}
|
||||
/**
|
||||
* Checks if any of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
* @returns `true` if any of the elements exist, `false` if none exist.
|
||||
*/
|
||||
hasAny(...keys) {
|
||||
return keys.some((key) => super.has(key));
|
||||
}
|
||||
first(amount) {
|
||||
if (amount === void 0)
|
||||
return this.values().next().value;
|
||||
if (amount < 0)
|
||||
return this.last(amount * -1);
|
||||
amount = Math.min(this.size, amount);
|
||||
const iter = this.values();
|
||||
return Array.from({ length: amount }, () => iter.next().value);
|
||||
}
|
||||
firstKey(amount) {
|
||||
if (amount === void 0)
|
||||
return this.keys().next().value;
|
||||
if (amount < 0)
|
||||
return this.lastKey(amount * -1);
|
||||
amount = Math.min(this.size, amount);
|
||||
const iter = this.keys();
|
||||
return Array.from({ length: amount }, () => iter.next().value);
|
||||
}
|
||||
last(amount) {
|
||||
const arr = [...this.values()];
|
||||
if (amount === void 0)
|
||||
return arr[arr.length - 1];
|
||||
if (amount < 0)
|
||||
return this.first(amount * -1);
|
||||
if (!amount)
|
||||
return [];
|
||||
return arr.slice(-amount);
|
||||
}
|
||||
lastKey(amount) {
|
||||
const arr = [...this.keys()];
|
||||
if (amount === void 0)
|
||||
return arr[arr.length - 1];
|
||||
if (amount < 0)
|
||||
return this.firstKey(amount * -1);
|
||||
if (!amount)
|
||||
return [];
|
||||
return arr.slice(-amount);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the item at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the element to obtain
|
||||
*/
|
||||
at(index) {
|
||||
index = Math.floor(index);
|
||||
const arr = [...this.values()];
|
||||
return arr.at(index);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
|
||||
* Returns the key at a given index, allowing for positive and negative integers.
|
||||
* Negative integers count back from the last item in the collection.
|
||||
*
|
||||
* @param index - The index of the key to obtain
|
||||
*/
|
||||
keyAt(index) {
|
||||
index = Math.floor(index);
|
||||
const arr = [...this.keys()];
|
||||
return arr.at(index);
|
||||
}
|
||||
random(amount) {
|
||||
const arr = [...this.values()];
|
||||
if (amount === void 0)
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!arr.length || !amount)
|
||||
return [];
|
||||
return Array.from(
|
||||
{ length: Math.min(amount, arr.length) },
|
||||
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
||||
);
|
||||
}
|
||||
randomKey(amount) {
|
||||
const arr = [...this.keys()];
|
||||
if (amount === void 0)
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!arr.length || !amount)
|
||||
return [];
|
||||
return Array.from(
|
||||
{ length: Math.min(amount, arr.length) },
|
||||
() => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
reverse() {
|
||||
const entries = [...this.entries()].reverse();
|
||||
this.clear();
|
||||
for (const [key, value] of entries)
|
||||
this.set(key, value);
|
||||
return this;
|
||||
}
|
||||
find(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return val;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findKey(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return key;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findLast(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const entries = [...this.entries()];
|
||||
for (let index = entries.length - 1; index >= 0; index--) {
|
||||
const val = entries[index][1];
|
||||
const key = entries[index][0];
|
||||
if (fn(val, key, this))
|
||||
return val;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
findLastKey(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const entries = [...this.entries()];
|
||||
for (let index = entries.length - 1; index >= 0; index--) {
|
||||
const key = entries[index][0];
|
||||
const val = entries[index][1];
|
||||
if (fn(val, key, this))
|
||||
return key;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
sweep(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const previousSize = this.size;
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
this.delete(key);
|
||||
}
|
||||
return previousSize - this.size;
|
||||
}
|
||||
filter(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const results = new this.constructor[Symbol.species]();
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
results.set(key, val);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
partition(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const results = [
|
||||
new this.constructor[Symbol.species](),
|
||||
new this.constructor[Symbol.species]()
|
||||
];
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) {
|
||||
results[0].set(key, val);
|
||||
} else {
|
||||
results[1].set(key, val);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
flatMap(fn, thisArg) {
|
||||
const collections = this.map(fn, thisArg);
|
||||
return new this.constructor[Symbol.species]().concat(...collections);
|
||||
}
|
||||
map(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const iter = this.entries();
|
||||
return Array.from({ length: this.size }, () => {
|
||||
const [key, value] = iter.next().value;
|
||||
return fn(value, key, this);
|
||||
});
|
||||
}
|
||||
mapValues(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, val] of this)
|
||||
coll.set(key, fn(val, key, this));
|
||||
return coll;
|
||||
}
|
||||
some(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
every(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, val] of this) {
|
||||
if (!fn(val, key, this))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
* ```
|
||||
*/
|
||||
reduce(fn, initialValue) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
let accumulator;
|
||||
const iterator = this.entries();
|
||||
if (initialValue === void 0) {
|
||||
if (this.size === 0)
|
||||
throw new TypeError("Reduce of empty collection with no initial value");
|
||||
accumulator = iterator.next().value[1];
|
||||
} else {
|
||||
accumulator = initialValue;
|
||||
}
|
||||
for (const [key, value] of iterator) {
|
||||
accumulator = fn(accumulator, value, key, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.reduceRight()}.
|
||||
*
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
*/
|
||||
reduceRight(fn, initialValue) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
const entries = [...this.entries()];
|
||||
let accumulator;
|
||||
let index;
|
||||
if (initialValue === void 0) {
|
||||
if (entries.length === 0)
|
||||
throw new TypeError("Reduce of empty collection with no initial value");
|
||||
accumulator = entries[entries.length - 1][1];
|
||||
index = entries.length - 1;
|
||||
} else {
|
||||
accumulator = initialValue;
|
||||
index = entries.length;
|
||||
}
|
||||
while (--index >= 0) {
|
||||
const key = entries[index][0];
|
||||
const val = entries[index][1];
|
||||
accumulator = fn(accumulator, val, key, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
each(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
for (const [key, value] of this) {
|
||||
fn(value, key, this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
tap(fn, thisArg) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError(`${fn} is not a function`);
|
||||
if (thisArg !== void 0)
|
||||
fn = fn.bind(thisArg);
|
||||
fn(this);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.clone();
|
||||
* ```
|
||||
*/
|
||||
clone() {
|
||||
return new this.constructor[Symbol.species](this);
|
||||
}
|
||||
/**
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
*
|
||||
* @param collections - Collections to merge
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
* ```
|
||||
*/
|
||||
concat(...collections) {
|
||||
const newColl = this.clone();
|
||||
for (const coll of collections) {
|
||||
for (const [key, val] of coll)
|
||||
newColl.set(key, val);
|
||||
}
|
||||
return newColl;
|
||||
}
|
||||
/**
|
||||
* Checks if this collection shares identical items with another.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but contain the same data.
|
||||
*
|
||||
* @param collection - Collection to compare with
|
||||
* @returns Whether the collections have identical contents
|
||||
*/
|
||||
equals(collection) {
|
||||
if (!collection)
|
||||
return false;
|
||||
if (this === collection)
|
||||
return true;
|
||||
if (this.size !== collection.size)
|
||||
return false;
|
||||
for (const [key, value] of this) {
|
||||
if (!collection.has(key) || value !== collection.get(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The sort method sorts the items of a collection in place and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
sort(compareFunction = _Collection.defaultSort) {
|
||||
const entries = [...this.entries()];
|
||||
entries.sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]));
|
||||
super.clear();
|
||||
for (const [key, value] of entries) {
|
||||
super.set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The intersection method returns a new collection containing the items where the key is present in both collections.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const intersection = col1.intersection(col2);
|
||||
* console.log(col1.intersection(col2));
|
||||
* // => Collection { 'a' => 1 }
|
||||
* ```
|
||||
*/
|
||||
intersection(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in either of the collections.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* If the collections have any items with the same key, the value from the first collection will be used.
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
|
||||
* const union = col1.union(col2);
|
||||
* console.log(union);
|
||||
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
union(other) {
|
||||
const coll = new this.constructor[Symbol.species](this);
|
||||
for (const [key, value] of other) {
|
||||
if (!coll.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing the items where the key is present in this collection but not the other.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* console.log(col1.difference(col2));
|
||||
* // => Collection { 'b' => 2 }
|
||||
* console.log(col2.difference(col1));
|
||||
* // => Collection { 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
difference(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (!other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
* @example
|
||||
* ```ts
|
||||
* const col1 = new Collection([['a', 1], ['b', 2]]);
|
||||
* const col2 = new Collection([['a', 1], ['c', 3]]);
|
||||
* const symmetricDifference = col1.symmetricDifference(col2);
|
||||
* console.log(col1.symmetricDifference(col2));
|
||||
* // => Collection { 'b' => 2, 'c' => 3 }
|
||||
* ```
|
||||
*/
|
||||
symmetricDifference(other) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
for (const [key, value] of this) {
|
||||
if (!other.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
for (const [key, value] of other) {
|
||||
if (!this.has(key))
|
||||
coll.set(key, value);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Merges two Collections together into a new Collection.
|
||||
*
|
||||
* @param other - The other Collection to merge with
|
||||
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
|
||||
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
|
||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||
* @example
|
||||
* ```ts
|
||||
* // Sums up the entries in two collections.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: true, value: x }),
|
||||
* y => ({ keep: true, value: y }),
|
||||
* (x, y) => ({ keep: true, value: x + y }),
|
||||
* );
|
||||
* ```
|
||||
* @example
|
||||
* ```ts
|
||||
* // Intersects two collections in a left-biased manner.
|
||||
* coll.merge(
|
||||
* other,
|
||||
* x => ({ keep: false }),
|
||||
* y => ({ keep: false }),
|
||||
* (x, _) => ({ keep: true, value: x }),
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
merge(other, whenInSelf, whenInOther, whenInBoth) {
|
||||
const coll = new this.constructor[Symbol.species]();
|
||||
const keys = /* @__PURE__ */ new Set([...this.keys(), ...other.keys()]);
|
||||
for (const key of keys) {
|
||||
const hasInSelf = this.has(key);
|
||||
const hasInOther = other.has(key);
|
||||
if (hasInSelf && hasInOther) {
|
||||
const result = whenInBoth(this.get(key), other.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
} else if (hasInSelf) {
|
||||
const result = whenInSelf(this.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
} else if (hasInOther) {
|
||||
const result = whenInOther(other.get(key), key);
|
||||
if (result.keep)
|
||||
coll.set(key, result.value);
|
||||
}
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
/**
|
||||
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
toReversed() {
|
||||
return new this.constructor[Symbol.species](this).reverse();
|
||||
}
|
||||
/**
|
||||
* The sorted method sorts the items of a collection and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
* ```
|
||||
*/
|
||||
toSorted(compareFunction = _Collection.defaultSort) {
|
||||
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
|
||||
}
|
||||
toJSON() {
|
||||
return [...this.entries()];
|
||||
}
|
||||
static defaultSort(firstValue, secondValue) {
|
||||
return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;
|
||||
}
|
||||
/**
|
||||
* Creates a Collection from a list of entries.
|
||||
*
|
||||
* @param entries - The list of entries
|
||||
* @param combine - Function to combine an existing entry with a new one
|
||||
* @example
|
||||
* ```ts
|
||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||
* // returns Collection { "a" => 3, "b" => 2 }
|
||||
* ```
|
||||
*/
|
||||
static combineEntries(entries, combine) {
|
||||
const coll = new _Collection();
|
||||
for (const [key, value] of entries) {
|
||||
if (coll.has(key)) {
|
||||
coll.set(key, combine(coll.get(key), value, key));
|
||||
} else {
|
||||
coll.set(key, value);
|
||||
}
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var version = "2.1.0";
|
||||
export {
|
||||
Collection,
|
||||
version
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
1
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.mjs.map
generated
vendored
Normal file
1
node_modules/@discordjs/rest/node_modules/@discordjs/collection/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
86
node_modules/@discordjs/rest/node_modules/@discordjs/collection/package.json
generated
vendored
Normal file
86
node_modules/@discordjs/rest/node_modules/@discordjs/collection/package.json
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@discordjs/collection",
|
||||
"version": "2.1.0",
|
||||
"description": "Utility data structure used in discord.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"map",
|
||||
"collection",
|
||||
"utility"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git",
|
||||
"directory": "packages/collection"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^3.0.2",
|
||||
"@types/node": "18.18.8",
|
||||
"@vitest/coverage-v8": "^1.5.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"esbuild-plugin-version-injector": "^1.2.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-neon": "^0.1.62",
|
||||
"eslint-formatter-pretty": "^6.0.1",
|
||||
"prettier": "^3.2.5",
|
||||
"tsup": "^8.0.2",
|
||||
"turbo": "^1.13.2",
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^1.5.0",
|
||||
"@discordjs/api-extractor": "^7.38.1",
|
||||
"@discordjs/scripts": "^0.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "tsc --noEmit && tsup",
|
||||
"build:docs": "tsc -p tsconfig.docs.json",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
|
||||
"fmt": "pnpm run format",
|
||||
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
|
||||
"release": "cliff-jumper"
|
||||
}
|
||||
}
|
119
node_modules/@discordjs/rest/package.json
generated
vendored
Normal file
119
node_modules/@discordjs/rest/package.json
generated
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@discordjs/rest",
|
||||
"version": "2.3.0",
|
||||
"description": "The REST API for discord.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"require": {
|
||||
"types": "./dist/web.d.ts",
|
||||
"default": "./dist/web.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/web.d.mts",
|
||||
"default": "./dist/web.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"./*": {
|
||||
"require": {
|
||||
"types": "./dist/strategies/*.d.ts",
|
||||
"default": "./dist/strategies/*.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/strategies/*.d.mts",
|
||||
"default": "./dist/strategies/*.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"rest",
|
||||
"discordapp",
|
||||
"discordjs"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git",
|
||||
"directory": "packages/rest"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"@sapphire/async-queue": "^1.5.2",
|
||||
"@sapphire/snowflake": "^3.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.2.4",
|
||||
"discord-api-types": "0.37.83",
|
||||
"magic-bytes.js": "^1.10.0",
|
||||
"tslib": "^2.6.2",
|
||||
"undici": "6.13.0",
|
||||
"@discordjs/collection": "^2.1.0",
|
||||
"@discordjs/util": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^3.0.2",
|
||||
"@types/node": "18.17.9",
|
||||
"@vitest/coverage-v8": "^1.5.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"esbuild-plugin-version-injector": "^1.2.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-neon": "^0.1.62",
|
||||
"eslint-formatter-pretty": "^6.0.1",
|
||||
"prettier": "^3.2.5",
|
||||
"tsup": "^8.0.2",
|
||||
"turbo": "^1.13.2",
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^1.5.0",
|
||||
"@discordjs/scripts": "^0.1.0",
|
||||
"@discordjs/api-extractor": "^7.38.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.11.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "tsc --noEmit && tsup",
|
||||
"build:docs": "tsc -p tsconfig.docs.json",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
|
||||
"fmt": "pnpm run format",
|
||||
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'",
|
||||
"release": "cliff-jumper"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue