mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 12:00:09 +00:00
Compare commits
10 Commits
@discordjs
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf92172d80 | ||
|
|
b2ec865765 | ||
|
|
3f8656115b | ||
|
|
883f6e9202 | ||
|
|
2ea2a85e63 | ||
|
|
f063625836 | ||
|
|
6398e46043 | ||
|
|
d24dbf7d22 | ||
|
|
3c231ae81a | ||
|
|
9f63eb977f |
4
.github/labeler.yml
vendored
4
.github/labeler.yml
vendored
@@ -37,3 +37,7 @@
|
||||
'packages:ws':
|
||||
- packages/ws/*
|
||||
- packages/ws/**/*
|
||||
|
||||
'packages:util':
|
||||
- packages/util/*
|
||||
- packages/util/**/*
|
||||
|
||||
2
.github/labels.yml
vendored
2
.github/labels.yml
vendored
@@ -66,6 +66,8 @@
|
||||
color: 'fbca04'
|
||||
- name: 'packages:ws'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:util'
|
||||
color: 'fbca04'
|
||||
- name: 'performance'
|
||||
color: '80c042'
|
||||
- name: 'permissions'
|
||||
|
||||
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
@@ -79,7 +79,7 @@ jobs:
|
||||
max-parallel: 1
|
||||
fail-fast: false
|
||||
matrix:
|
||||
package: ['builders', 'collection', 'discord.js', 'proxy', 'rest', 'voice', 'ws']
|
||||
package: ['builders', 'collection', 'discord.js', 'proxy', 'rest', 'util', 'voice', 'ws']
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
|
||||
2
.github/workflows/npm-auto-deprecate.yml
vendored
2
.github/workflows/npm-auto-deprecate.yml
vendored
@@ -22,6 +22,6 @@ jobs:
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Deprecate versions
|
||||
run: 'yarn npm-deprecate --name "*dev*" --package @discordjs/builders @discordjs/collection discord.js @discordjs/proxy @discordjs/rest @discordjs/voice'
|
||||
run: 'yarn npm-deprecate --name "*dev*" --package @discordjs/builders @discordjs/collection discord.js @discordjs/proxy @discordjs/rest @discordjs/util @discordjs/voice'
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
2
.github/workflows/publish-dev.yml
vendored
2
.github/workflows/publish-dev.yml
vendored
@@ -20,6 +20,8 @@ jobs:
|
||||
folder: 'proxy'
|
||||
- package: '@discordjs/rest'
|
||||
folder: 'rest'
|
||||
- package: '@discordjs/util'
|
||||
folder: 'util'
|
||||
- package: '@discordjs/voice'
|
||||
folder: 'voice'
|
||||
- package: '@discordjs/ws'
|
||||
|
||||
@@ -11,4 +11,4 @@ outputs:
|
||||
description: 'The semver string that was extracted from this tag'
|
||||
runs:
|
||||
using: node16
|
||||
main: ../../dist/index.mjs
|
||||
main: ../../dist/formatTag/index.mjs
|
||||
|
||||
@@ -51,6 +51,12 @@ runs:
|
||||
files: ./packages/ws/coverage/cobertura-coverage.xml
|
||||
flags: ws
|
||||
|
||||
- name: Upload Util Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/util/coverage/cobertura-coverage.xml
|
||||
flags: util
|
||||
|
||||
- name: Upload Utilities Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
|
||||
@@ -15,7 +15,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e))
|
||||
|
||||
# [@discordjs/builders@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.0.0...@discordjs/builders@1.1.0) - (2022-07-29)
|
||||
# [@discordjs/builders@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.16.0...@discordjs/builders@1.1.0) - (2022-07-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
@@ -31,11 +31,9 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Add channel & message URL formatters (#8371) ([a7deb8f](https://github.com/discordjs/discord.js/commit/a7deb8f89830ead6185c5fb46a49688b6d209ed1))
|
||||
|
||||
# [@discordjs/builders@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.16.0...@discordjs/builders@1.0.0) - (2022-07-17)
|
||||
## Testing
|
||||
|
||||
## Info
|
||||
|
||||
- 1.0.0 release bump, no new features.
|
||||
- **builders:** Improve coverage (#8274) ([b7e6238](https://github.com/discordjs/discord.js/commit/b7e62380f2e6b9324d6bba9b9eaa5315080bf66a))
|
||||
|
||||
# [@discordjs/builders@0.16.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.15.0...@discordjs/builders@0.16.0) - (2022-07-17)
|
||||
|
||||
@@ -76,14 +74,6 @@ All notable changes to this project will be documented in this file.
|
||||
- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b))
|
||||
- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b))
|
||||
|
||||
# [@discordjs/builders@0.15.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.14.0...@discordjs/builders@0.15.0) - (2022-06-05)
|
||||
|
||||
## Features
|
||||
|
||||
- Allow builders to accept rest params and arrays (#7874) ([ad75be9](https://github.com/discordjs/discord.js/commit/ad75be9a9cf90c8624495df99b75177e6c24022f))
|
||||
- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b))
|
||||
- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b))
|
||||
|
||||
# [@discordjs/builders@0.14.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.13.0...@discordjs/builders@0.14.0) - (2022-06-04)
|
||||
|
||||
## Bug Fixes
|
||||
@@ -174,108 +164,3 @@ All notable changes to this project will be documented in this file.
|
||||
## Typings
|
||||
|
||||
- Make `required` a boolean (#7307) ([c10afea](https://github.com/discordjs/discord.js/commit/c10afeadc702ab98bec5e077b3b92494a9596f9c))
|
||||
|
||||
# [0.11.0](https://github.com/discordjs/builders/compare/v0.10.0...v0.11.0) (2021-12-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **ApplicationCommandOptions:** clean up code for builder options ([#68](https://github.com/discordjs/builders/issues/68)) ([b5d0b15](https://github.com/discordjs/builders/commit/b5d0b157b1262bd01fa011f8e0cf33adb82776e7))
|
||||
|
||||
# [0.10.0](https://github.com/discordjs/builders/compare/v0.9.0...v0.10.0) (2021-12-24)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- use zod instead of ow for max/min option validation ([#66](https://github.com/discordjs/builders/issues/66)) ([beb35fb](https://github.com/discordjs/builders/commit/beb35fb1f65bd6be2321e17cc792f67e8615fd48))
|
||||
|
||||
## Features
|
||||
|
||||
- add max/min option for int and number builder options ([#47](https://github.com/discordjs/builders/issues/47)) ([2e1e860](https://github.com/discordjs/builders/commit/2e1e860b46e3453398b20df63dabb6d4325e32d1))
|
||||
|
||||
# [0.9.0](https://github.com/discordjs/builders/compare/v0.8.2...v0.9.0) (2021-12-02)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- replace ow with zod ([#58](https://github.com/discordjs/builders/issues/58)) ([0b6fb81](https://github.com/discordjs/builders/commit/0b6fb8161b858e42781855fb73aaa873fec58160))
|
||||
|
||||
## Features
|
||||
|
||||
- **SlashCommandBuilder:** add autocomplete ([#53](https://github.com/discordjs/builders/issues/53)) ([05b07a7](https://github.com/discordjs/builders/commit/05b07a7e88848188c27d7380d9f948cba25ef778))
|
||||
|
||||
## [0.8.2](https://github.com/discordjs/builders/compare/v0.8.1...v0.8.2) (2021-10-30)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- downgrade ow because of esm issues ([#55](https://github.com/discordjs/builders/issues/55)) ([3722d2c](https://github.com/discordjs/builders/commit/3722d2c1109a7a5c0abad63c1a7eb944df6e46c8))
|
||||
|
||||
## [0.8.1](https://github.com/discordjs/builders/compare/v0.8.0...v0.8.1) (2021-10-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- documentation ([e33ec8d](https://github.com/discordjs/builders/commit/e33ec8dfd5785312f82e0afb017a3dac614fd71d))
|
||||
|
||||
# [0.7.0](https://github.com/discordjs/builders/compare/v0.6.0...v0.7.0) (2021-10-18)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- properly type `toJSON` methods ([#34](https://github.com/discordjs/builders/issues/34)) ([7723ad0](https://github.com/discordjs/builders/commit/7723ad0da169386e638188de220451a97513bc25))
|
||||
|
||||
## Features
|
||||
|
||||
- **ContextMenus:** add context menu command builder ([#29](https://github.com/discordjs/builders/issues/29)) ([f0641e5](https://github.com/discordjs/builders/commit/f0641e55733de8992600f3082bcf054e6f815cf7))
|
||||
- add support for channel types on channel options ([#41](https://github.com/discordjs/builders/issues/41)) ([f6c187e](https://github.com/discordjs/builders/commit/f6c187e0ad6ebe03e65186ece3e95cb1db5aeb50))
|
||||
|
||||
# [0.6.0](https://github.com/discordjs/builders/compare/v0.5.0...v0.6.0) (2021-08-24)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **SlashCommandBuilder:** allow subcommands and groups to coexist at the root level ([#26](https://github.com/discordjs/builders/issues/26)) ([0be4daf](https://github.com/discordjs/builders/commit/0be4dafdfc0b5747c880be0078c00ada913eb4fb))
|
||||
|
||||
## Features
|
||||
|
||||
- create `Embed` builder ([#11](https://github.com/discordjs/builders/issues/11)) ([eb942a4](https://github.com/discordjs/builders/commit/eb942a4d1f3bcec9a4e370b6af602a713ad8f9b7))
|
||||
- **SlashCommandBuilder:** create setDefaultPermission function ([#19](https://github.com/discordjs/builders/issues/19)) ([5d53759](https://github.com/discordjs/builders/commit/5d537593937a8da330153ce4711b7d093a80330e))
|
||||
- **SlashCommands:** add number option type ([#23](https://github.com/discordjs/builders/issues/23)) ([1563991](https://github.com/discordjs/builders/commit/1563991d421bb07bf7a412c87e7613692d770f04))
|
||||
|
||||
# [0.5.0](https://github.com/discordjs/builders/compare/v0.3.0...v0.5.0) (2021-08-10)
|
||||
|
||||
## Features
|
||||
|
||||
- **Formatters:** add `formatEmoji` ([#20](https://github.com/discordjs/builders/issues/20)) ([c3d8bb5](https://github.com/discordjs/builders/commit/c3d8bb5363a1d46b45c0def4277da6921e2ba209))
|
||||
|
||||
# [0.4.0](https://github.com/discordjs/builders/compare/v0.3.0...v0.4.0) (2021-08-05)
|
||||
|
||||
## Features
|
||||
|
||||
- `sub command` => `subcommand` ([#18](https://github.com/discordjs/builders/pull/18)) ([95599c5](https://github.com/discordjs/builders/commit/95599c5b5366ebd054c4c277c52f1a44cda1209d))
|
||||
|
||||
# [0.3.0](https://github.com/discordjs/builders/compare/v0.2.0...v0.3.0) (2021-08-01)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **Shrug:** Update comment ([#14](https://github.com/discordjs/builders/issues/14)) ([6fa6c40](https://github.com/discordjs/builders/commit/6fa6c405f2ea733811677d3d1bfb1e2806d504d5))
|
||||
- shrug face rendering ([#13](https://github.com/discordjs/builders/issues/13)) ([6ad24ec](https://github.com/discordjs/builders/commit/6ad24ecd96c82b0f576e78e9e53fc7bf9c36ef5d))
|
||||
|
||||
## Features
|
||||
|
||||
- **formatters:** mentions ([#9](https://github.com/discordjs/builders/issues/9)) ([f83fe99](https://github.com/discordjs/builders/commit/f83fe99b83188ed999845751ffb005c687dbd60a))
|
||||
- **Formatters:** Add a spoiler function ([#16](https://github.com/discordjs/builders/issues/16)) ([c213a6a](https://github.com/discordjs/builders/commit/c213a6abb114f65653017a4edec4bdba2162d771))
|
||||
- **SlashCommands:** add slash command builders ([#3](https://github.com/discordjs/builders/issues/3)) ([6aa3af0](https://github.com/discordjs/builders/commit/6aa3af07b0ee342fff91f080914bb12b3ab773f8))
|
||||
- shrug, tableflip and unflip strings ([#5](https://github.com/discordjs/builders/issues/5)) ([de5fa82](https://github.com/discordjs/builders/commit/de5fa823cd6f1feba5b2d0a63b2cb1761dfd1814))
|
||||
|
||||
# [0.2.0](https://github.com/discordjs/builders/compare/v0.1.1...v0.2.0) (2021-07-03)
|
||||
|
||||
## Features
|
||||
|
||||
- **Formatters:** added `hyperlink` and `hideLinkEmbed` ([#4](https://github.com/discordjs/builders/issues/4)) ([c532daf](https://github.com/discordjs/builders/commit/c532daf2ba2feae75bf9668f63462e96a5314cff))
|
||||
|
||||
# [0.1.1](https://github.com/discordjs/builders/compare/v0.1.0...v0.1.1) (2021-06-30)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **Deps:** added `tslib` as dependency ([#2](https://github.com/discordjs/builders/issues/2)) ([5576ff3](https://github.com/discordjs/builders/commit/5576ff3b67136b957bed0ab8a4c655d5de322813))
|
||||
|
||||
# 0.1.0 (2021-06-30)
|
||||
|
||||
## Features
|
||||
|
||||
- added message formatters ([#1](https://github.com/discordjs/builders/issues/1)) ([765e46d](https://github.com/discordjs/builders/commit/765e46dac96c4e49d350243e5fad34c2bc738a7c))
|
||||
|
||||
@@ -1,33 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
isJSONEncodable,
|
||||
isEquatable,
|
||||
ActionRowBuilder,
|
||||
enableValidators,
|
||||
disableValidators,
|
||||
isValidationEnabled,
|
||||
} from '../src/index.js';
|
||||
|
||||
describe('isEquatable', () => {
|
||||
test('returns true if the object is equatable', () => {
|
||||
expect(isEquatable({ equals: () => true })).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns false if the object is not equatable', () => {
|
||||
expect(isEquatable({})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isJSONEncodable', () => {
|
||||
test('returns true if the object is JSON encodable', () => {
|
||||
expect(isJSONEncodable({ toJSON: () => ({}) })).toBeTruthy();
|
||||
expect(isJSONEncodable(new ActionRowBuilder())).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns false if the object is not JSON encodable', () => {
|
||||
expect(isJSONEncodable({})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
import { enableValidators, disableValidators, isValidationEnabled } from '../src/index.js';
|
||||
|
||||
describe('validation', () => {
|
||||
test('enables validation', () => {
|
||||
|
||||
@@ -54,8 +54,9 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/shapeshift": "^3.6.0",
|
||||
"discord-api-types": "^0.37.10",
|
||||
"discord-api-types": "^0.37.11",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"ts-mixer": "^6.0.1",
|
||||
"tslib": "^2.4.0"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
APIActionRowComponentTypes,
|
||||
APIBaseComponent,
|
||||
ComponentType,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { JSONEncodable } from '../util/jsonEncodable';
|
||||
|
||||
export type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';
|
||||
import type { JSONEncodable } from '../../util/jsonEncodable.js';
|
||||
import {
|
||||
defaultValidator,
|
||||
emojiValidator,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isJSONEncodable, type Equatable, type JSONEncodable } from '@discordjs/util';
|
||||
import { ComponentType, type TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';
|
||||
import isEqual from 'fast-deep-equal';
|
||||
import type { Equatable } from '../../util/equatable';
|
||||
import { isJSONEncodable, type JSONEncodable } from '../../util/jsonEncodable.js';
|
||||
import { customIdValidator } from '../Assertions.js';
|
||||
import { ComponentBuilder } from '../Component.js';
|
||||
import {
|
||||
|
||||
@@ -36,8 +36,7 @@ export * from './interactions/slashCommands/mixins/SharedSlashCommandOptions.js'
|
||||
export * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions.js';
|
||||
export * from './interactions/contextMenuCommands/ContextMenuCommandBuilder.js';
|
||||
|
||||
export * from './util/jsonEncodable.js';
|
||||
export * from './util/equatable.js';
|
||||
export * from './util/componentUtil.js';
|
||||
export * from './util/normalizeArray.js';
|
||||
export * from './util/validation.js';
|
||||
export * from '@discordjs/util';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
APIModalActionRowComponent,
|
||||
@@ -6,7 +7,6 @@ import type {
|
||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';
|
||||
import { customIdValidator } from '../../components/Assertions.js';
|
||||
import { createComponentBuilder } from '../../components/Components.js';
|
||||
import type { JSONEncodable } from '../../util/jsonEncodable';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { titleValidator, validateRequiredParameters } from './Assertions.js';
|
||||
|
||||
|
||||
@@ -78,36 +78,3 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Add `ReadonlyCollection` (#7245) ([db25f52](https://github.com/discordjs/discord.js/commit/db25f529b26d7c819c1c42ad3e26c2263ea2da0e))
|
||||
- **Collection:** Union types on `intersect` and `difference` (#7196) ([1f9b922](https://github.com/discordjs/discord.js/commit/1f9b9225f2066e9cc66c3355417139fd25cc403c))
|
||||
|
||||
# [0.4.0](https://github.com/discordjs/collection/compare/v0.3.2...v0.4.0) (2021-12-24)
|
||||
|
||||
## Features
|
||||
|
||||
- add #reverse ([#48](https://github.com/discordjs/collection/issues/48)) ([8bcb5e2](https://github.com/discordjs/collection/commit/8bcb5e21bcc15f5b77612d8ff03dec6c37f4d449))
|
||||
- add Collection#ensure ([#52](https://github.com/discordjs/collection/issues/52)) ([3809eb4](https://github.com/discordjs/collection/commit/3809eb4d18e70459355d310919a3f57747eee3dd))
|
||||
|
||||
# [0.3.2](https://github.com/discordjs/collection/compare/v0.3.1...v0.3.2) (2021-10-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- update doc engine ([4c0e24f](https://github.com/discordjs/collection/commit/4c0e24fae0323db9de1991db9cfacc093d529abc))
|
||||
|
||||
# [0.3.0](https://github.com/discordjs/collection/compare/v0.2.4...v0.3.0) (2021-10-29)
|
||||
|
||||
## Features
|
||||
|
||||
- add Collection#at() and Collection#keyAt() ([#46](https://github.com/discordjs/collection/issues/46)) ([66b30b9](https://github.com/discordjs/collection/commit/66b30b91069502493383c059cc38e27c152bf541))
|
||||
- improve documentation and resolve [#49](https://github.com/discordjs/collection/issues/49) ([aec01c6](https://github.com/discordjs/collection/commit/aec01c6ae3ff50b0b5f7c070bff10f01bf98d803))
|
||||
- ts-docgen ([463b131](https://github.com/discordjs/collection/commit/463b1314e60f2debc526454a6ccd7ce8a9a4ae8a))
|
||||
|
||||
# [0.2.4](https://github.com/discordjs/collection/compare/v0.2.3...v0.2.4) (2021-10-27)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- minification of names ([bd2fe2a](https://github.com/discordjs/collection/commit/bd2fe2a47c38f634b0334fe6e89f30f6f6a0b1f5))
|
||||
|
||||
# [0.2.3](https://github.com/discordjs/collection/compare/v0.2.2...v0.2.3) (2021-10-27)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- building with useDefineForClassFields false ([2a571d5](https://github.com/discordjs/collection/commit/2a571d5a2c90ed8b708c3c5c017e2f225cd494e9))
|
||||
|
||||
@@ -2,6 +2,35 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [14.5.0](https://github.com/discordjs/discord.js/compare/14.4.0...14.5.0) - (2022-09-25)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **ThreadChannel:** Add forum channel to parent (#8664) ([0126d9b](https://github.com/discordjs/discord.js/commit/0126d9b810a156c4bf1b8b93f2121f3319855bac))
|
||||
- **GuildChannelManager:** Allow creating webhooks on forums (#8661) ([16fcdc3](https://github.com/discordjs/discord.js/commit/16fcdc36877d1a65ce9995c9fe3502aa268c9388))
|
||||
- **ForumChannel:** Implement missing properties and methods (#8662) ([8622939](https://github.com/discordjs/discord.js/commit/862293922924f453f69b0b0f8efe87ddebbd387d))
|
||||
- RepliableInteraction respect cached generic (#8667) ([578bc95](https://github.com/discordjs/discord.js/commit/578bc951bdcdc21ec5aee86e7a47a17e8c867dfc))
|
||||
- **ThreadChannel:** Allow editing flags (#8671) ([1244854](https://github.com/discordjs/discord.js/commit/1244854e1365d7e4a8d01703a7ec13610ed100c7))
|
||||
- **GuildChannelManager:** Typo in `flags` property name when editing (#8669) ([fc8ed81](https://github.com/discordjs/discord.js/commit/fc8ed816e643754a938211a17b41a2cec95df265))
|
||||
|
||||
## Documentation
|
||||
|
||||
- Fix duplicate typedefs (#8677) ([d79aa2d](https://github.com/discordjs/discord.js/commit/d79aa2d0d0b186bd28cbfc82f3d6ecf3deb41c50))
|
||||
- **ForumChannel:** Add `@implements` (#8678) ([8ca407e](https://github.com/discordjs/discord.js/commit/8ca407e089c3050b61a51a52b9100e4613ad1666))
|
||||
|
||||
## Features
|
||||
|
||||
- **GuildChannelManager:** Allow editing `flags` (#8637) ([abb7226](https://github.com/discordjs/discord.js/commit/abb7226af3445f5b724815bb2f7a121a52a563b5))
|
||||
|
||||
## Refactor
|
||||
|
||||
- **GuildBanManager:** Add deprecation warning for `deleteMessageDays` (#8659) ([e993122](https://github.com/discordjs/discord.js/commit/e9931229ae62a120ae0761ee2a2c10ea0cb1a6fb))
|
||||
|
||||
## Typings
|
||||
|
||||
- **GuildChannelManager:** Handle forum channel overload (#8660) ([1486bc9](https://github.com/discordjs/discord.js/commit/1486bc9336369d229972df5e28b9428365b92bff))
|
||||
- **Caches:** Allow `GuildForumThreadManager` and `GuildTextThreadManager` (#8665) ([2487e3b](https://github.com/discordjs/discord.js/commit/2487e3bf76260a4a2fbf375e0b01a43f347922a3))
|
||||
|
||||
# [14.4.0](https://github.com/discordjs/discord.js/compare/14.3.0...14.4.0) - (2022-09-21)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "14.4.0",
|
||||
"version": "14.5.0",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"scripts": {
|
||||
"test": "yarn docs:test && yarn test:typescript",
|
||||
@@ -52,9 +52,10 @@
|
||||
"@discordjs/builders": "workspace:^",
|
||||
"@discordjs/collection": "workspace:^",
|
||||
"@discordjs/rest": "workspace:^",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/snowflake": "^3.2.2",
|
||||
"@types/ws": "^8.5.3",
|
||||
"discord-api-types": "^0.37.10",
|
||||
"discord-api-types": "^0.37.11",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"lodash.snakecase": "^4.1.1",
|
||||
"tslib": "^2.4.0",
|
||||
|
||||
@@ -53,6 +53,7 @@ class CategoryChannelChildManager extends DataManager {
|
||||
* @property {GuildForumTagData[]} [availableTags] The tags that can be used in this channel (forum only).
|
||||
* @property {DefaultReactionEmoji} [defaultReactionEmoji]
|
||||
* The emoji to show in the add reaction button on a thread in a guild forum channel.
|
||||
* @property {SortOrderType} [defaultSortOrder] The default sort order mode used to order posts (forum only).
|
||||
* @property {string} [reason] Reason for creating the new channel
|
||||
*/
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ class GuildChannelManager extends CachedManager {
|
||||
videoQualityMode,
|
||||
availableTags,
|
||||
defaultReactionEmoji,
|
||||
defaultSortOrder,
|
||||
reason,
|
||||
}) {
|
||||
parent &&= this.client.channels.resolveId(parent);
|
||||
@@ -162,6 +163,7 @@ class GuildChannelManager extends CachedManager {
|
||||
video_quality_mode: videoQualityMode,
|
||||
available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
|
||||
default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
|
||||
default_sort_order: defaultSortOrder,
|
||||
},
|
||||
reason,
|
||||
});
|
||||
@@ -229,6 +231,7 @@ class GuildChannelManager extends CachedManager {
|
||||
* @property {?DefaultReactionEmoji} [defaultReactionEmoji] The emoji to set as the default reaction emoji
|
||||
* @property {number} [defaultThreadRateLimitPerUser] The rate limit per user (slowmode) to set on forum posts
|
||||
* @property {ChannelFlagsResolvable} [flags] The flags to set on the channel
|
||||
* @property {?SortOrderType} [defaultSortOrder] The default sort order mode to set on the channel
|
||||
* @property {string} [reason] Reason for editing this channel
|
||||
*/
|
||||
|
||||
@@ -289,6 +292,7 @@ class GuildChannelManager extends CachedManager {
|
||||
default_reaction_emoji: data.defaultReactionEmoji && transformGuildDefaultReaction(data.defaultReactionEmoji),
|
||||
default_thread_rate_limit_per_user: data.defaultThreadRateLimitPerUser,
|
||||
flags: 'flags' in data ? ChannelFlagsBitField.resolve(data.flags) : undefined,
|
||||
default_sort_order: data.defaultSortOrder,
|
||||
},
|
||||
reason: data.reason,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const { ApplicationCommandOptionType } = require('discord-api-types/v10');
|
||||
const CommandInteraction = require('./CommandInteraction');
|
||||
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
|
||||
const { lazy } = require('../util/Util');
|
||||
|
||||
const getMessage = lazy(() => require('./Message').Message);
|
||||
|
||||
|
||||
@@ -124,6 +124,16 @@ class ForumChannel extends GuildChannel {
|
||||
*/
|
||||
this.topic = data.topic;
|
||||
}
|
||||
|
||||
if ('default_sort_order' in data) {
|
||||
/**
|
||||
* The default sort order mode used to order posts
|
||||
* @type {?SortOrderType}
|
||||
*/
|
||||
this.defaultSortOrder = data.default_sort_order;
|
||||
} else {
|
||||
this.defaultSortOrder ??= null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,6 +215,16 @@ class ForumChannel extends GuildChannel {
|
||||
return this.edit({ topic, reason });
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default sort order mode used to order posts
|
||||
* @param {?SortOrderType} defaultSortOrder The default sort order mode to set on this channel
|
||||
* @param {string} [reason] Reason for changing the default sort order
|
||||
* @returns {Promise<ForumChannel>}
|
||||
*/
|
||||
setDefaultSortOrder(defaultSortOrder, reason) {
|
||||
return this.edit({ defaultSortOrder, reason });
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
createWebhook() {}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const BaseInteraction = require('./BaseInteraction');
|
||||
const InteractionWebhook = require('./InteractionWebhook');
|
||||
const InteractionResponses = require('./interfaces/InteractionResponses');
|
||||
const { lazy } = require('../util/Util');
|
||||
|
||||
const getMessage = lazy(() => require('./Message').Message);
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
const { Buffer } = require('node:buffer');
|
||||
const { isJSONEncodable } = require('@discordjs/builders');
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const { MessageFlags } = require('discord-api-types/v10');
|
||||
const ActionRowBuilder = require('./ActionRowBuilder');
|
||||
const { RangeError, ErrorCodes } = require('../errors');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const MessageFlagsBitField = require('../util/MessageFlagsBitField');
|
||||
const { basename, verifyString, lazy } = require('../util/Util');
|
||||
const { basename, verifyString } = require('../util/Util');
|
||||
|
||||
const getBaseInteraction = lazy(() => require('./BaseInteraction'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const BaseInteraction = require('./BaseInteraction');
|
||||
const InteractionWebhook = require('./InteractionWebhook');
|
||||
const ModalSubmitFields = require('./ModalSubmitFields');
|
||||
const InteractionResponses = require('./interfaces/InteractionResponses');
|
||||
const { lazy } = require('../util/Util');
|
||||
|
||||
const getMessage = lazy(() => require('./Message').Message);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const { Routes, WebhookType } = require('discord-api-types/v10');
|
||||
const MessagePayload = require('./MessagePayload');
|
||||
const { Error, ErrorCodes } = require('../errors');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const { lazy } = require('../util/Util');
|
||||
|
||||
const getMessage = lazy(() => require('./Message').Message);
|
||||
|
||||
|
||||
@@ -333,6 +333,11 @@
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-rest/common/enum/RESTJSONErrorCodes}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external SortOrderType
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/SortOrderType}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external StageInstancePrivacyLevel
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/StageInstancePrivacyLevel}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { lazy } = require('@discordjs/util');
|
||||
const { ChannelType } = require('discord-api-types/v10');
|
||||
const { lazy } = require('./Util');
|
||||
|
||||
const getCategoryChannel = lazy(() => require('../structures/CategoryChannel'));
|
||||
const getDMChannel = lazy(() => require('../structures/DMChannel'));
|
||||
|
||||
@@ -509,16 +509,6 @@ function cleanCodeBlockContent(text) {
|
||||
return text.replaceAll('```', '`\u200b``');
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily evaluates a callback function
|
||||
* @param {Function} cb The callback to lazily evaluate
|
||||
* @returns {Function}
|
||||
*/
|
||||
function lazy(cb) {
|
||||
let defaultValue;
|
||||
return () => (defaultValue ??= cb());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a webhook URL for the id and token.
|
||||
* @param {string} url The URL to parse
|
||||
@@ -562,7 +552,6 @@ module.exports = {
|
||||
basename,
|
||||
cleanContent,
|
||||
cleanCodeBlockContent,
|
||||
lazy,
|
||||
parseWebhookURL,
|
||||
};
|
||||
|
||||
|
||||
12
packages/discord.js/typings/index.d.ts
vendored
12
packages/discord.js/typings/index.d.ts
vendored
@@ -12,7 +12,6 @@ import {
|
||||
hyperlink,
|
||||
inlineCode,
|
||||
italic,
|
||||
JSONEncodable,
|
||||
quote,
|
||||
roleMention,
|
||||
SelectMenuBuilder as BuilderSelectMenuComponent,
|
||||
@@ -31,6 +30,7 @@ import {
|
||||
ComponentBuilder,
|
||||
type RestOrArray,
|
||||
} from '@discordjs/builders';
|
||||
import { Awaitable, JSONEncodable } from '@discordjs/util';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
|
||||
import {
|
||||
@@ -125,6 +125,7 @@ import {
|
||||
AuditLogOptionsType,
|
||||
TextChannelType,
|
||||
ChannelFlags,
|
||||
SortOrderType,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ChildProcess } from 'node:child_process';
|
||||
import { EventEmitter } from 'node:events';
|
||||
@@ -621,7 +622,7 @@ export class SelectMenuOptionBuilder extends BuildersSelectMenuOption {
|
||||
}
|
||||
|
||||
export class ModalBuilder extends BuildersModal {
|
||||
public constructor(data?: Partial<ModalComponentData> | Partial<APIModalComponent>);
|
||||
public constructor(data?: Partial<ModalComponentData> | Partial<APIModalInteractionResponseCallbackData>);
|
||||
public static from(other: JSONEncodable<APIModalComponent> | APIModalComponent): ModalBuilder;
|
||||
}
|
||||
|
||||
@@ -2097,6 +2098,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
||||
public defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null;
|
||||
public nsfw: boolean;
|
||||
public topic: string | null;
|
||||
public defaultSortOrder: SortOrderType | null;
|
||||
|
||||
public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise<this>;
|
||||
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
|
||||
@@ -2108,6 +2110,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
||||
reason?: string,
|
||||
): Promise<this>;
|
||||
public setTopic(topic: string | null, reason?: string): Promise<this>;
|
||||
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
|
||||
}
|
||||
|
||||
export class PermissionOverwrites extends Base {
|
||||
@@ -4141,8 +4144,6 @@ export interface AuditLogChange {
|
||||
new?: APIAuditLogChange['new_value'];
|
||||
}
|
||||
|
||||
export type Awaitable<T> = T | PromiseLike<T>;
|
||||
|
||||
export type AwaitMessageComponentOptions<T extends CollectedMessageInteraction> = Omit<
|
||||
MessageComponentCollectorOptions<T>,
|
||||
'max' | 'maxComponents' | 'maxUsers'
|
||||
@@ -4251,6 +4252,7 @@ export interface CategoryCreateChannelOptions {
|
||||
videoQualityMode?: VideoQualityMode;
|
||||
availableTags?: GuildForumTagData[];
|
||||
defaultReactionEmoji?: DefaultReactionEmoji;
|
||||
defaultSortOrder?: SortOrderType;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -4932,6 +4934,7 @@ export interface GuildChannelEditOptions {
|
||||
defaultReactionEmoji?: DefaultReactionEmoji | null;
|
||||
defaultThreadRateLimitPerUser?: number;
|
||||
flags?: ChannelFlagsResolvable;
|
||||
defaultSortOrder?: SortOrderType | null;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -5830,3 +5833,4 @@ export type InternalDiscordGatewayAdapterCreator = (
|
||||
export * from 'discord-api-types/v10';
|
||||
export * from '@discordjs/builders';
|
||||
export * from '@discordjs/rest';
|
||||
export * from '@discordjs/util';
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src --ext mjs,js,ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||
"fmt": "yarn format",
|
||||
"prepack": "yarn format && yarn build",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/docgen/*'",
|
||||
"release": "cliff-jumper"
|
||||
"prepack": "yarn format && yarn build"
|
||||
},
|
||||
"bin": "./dist/cli.js",
|
||||
"directories": {
|
||||
|
||||
@@ -29,16 +29,25 @@ Use it:
|
||||
|
||||
```ts
|
||||
import { Client } from 'discord.js';
|
||||
import { ProxyAgent } from 'undici';
|
||||
|
||||
const client = new Client({
|
||||
// other options,
|
||||
rest: {
|
||||
agent: new ProxyAgent('https://localhost:8080'),
|
||||
api: 'http://localhost:8080/api',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Or with just `@discordjs/rest`:
|
||||
|
||||
```ts
|
||||
import { REST } from '@discordjs/rest';
|
||||
|
||||
const rest = new REST({
|
||||
api: 'http://localhost:8080/api',
|
||||
});
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src --ext mjs,js,ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||
"fmt": "yarn format",
|
||||
"prepack": "yarn lint && yarn test && yarn build",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy-container/*'"
|
||||
"prepack": "yarn lint && yarn test && yarn build"
|
||||
},
|
||||
"type": "module",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -16,7 +16,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e))
|
||||
|
||||
# [@discordjs/proxy@1.0.0](https://github.com/discordjs/discord.js/tree/@discordjs/proxy@1.0.0) - (2022-07-17)
|
||||
# [@discordjs/proxy@1.0.1](https://github.com/discordjs/discord.js/tree/@discordjs/proxy@1.0.1) - (2022-07-27)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
|
||||
@@ -57,8 +57,7 @@ commit_parsers = [
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
filter_commits = true
|
||||
tag_pattern = "@discordjs\\/proxy@.*"
|
||||
skip_tags = "v[0-9]*|11|12"
|
||||
tag_pattern = "@discordjs/proxy@[0-9]*"
|
||||
ignore_tags = ""
|
||||
date_order = true
|
||||
sort_commits = "newest"
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^1.0.0",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"tslib": "^2.4.0",
|
||||
"undici": "^5.10.0"
|
||||
},
|
||||
|
||||
@@ -32,8 +32,9 @@ export function proxyRequests(rest: REST): RequestHandler {
|
||||
|
||||
// The 2nd parameter is here so the URL constructor doesn't complain about an "invalid url" when the origin is missing
|
||||
// we don't actually care about the origin and the value passed is irrelevant
|
||||
// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex
|
||||
const fullRoute = new URL(url, 'http://noop').pathname.replace(/^\/api(\/v\d+)?/, '') as RouteLike;
|
||||
const parsedUrl = new URL(url, 'http://noop');
|
||||
// eslint-disable-next-line unicorn/no-unsafe-regex, prefer-named-capture-group
|
||||
const fullRoute = parsedUrl.pathname.replace(/^\/api(\/v\d+)?/, '') as RouteLike;
|
||||
|
||||
try {
|
||||
const discordResponse = await rest.raw({
|
||||
@@ -42,6 +43,7 @@ export function proxyRequests(rest: REST): RequestHandler {
|
||||
// This type cast is technically incorrect, but we want Discord to throw Method Not Allowed for us
|
||||
method: method as RequestMethod,
|
||||
passThroughBody: true,
|
||||
query: parsedUrl.searchParams,
|
||||
headers: {
|
||||
'Content-Type': req.headers['content-type']!,
|
||||
},
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||
|
||||
/**
|
||||
* Represents a potentially awaitable value
|
||||
*/
|
||||
export type Awaitable<T> = PromiseLike<T> | T;
|
||||
import type { Awaitable } from '@discordjs/util';
|
||||
|
||||
/**
|
||||
* Represents a simple HTTP request handler
|
||||
|
||||
@@ -127,42 +127,3 @@ All notable changes to this project will be documented in this file.
|
||||
## Testing
|
||||
|
||||
- **voice:** Fix tests ([62c74b8](https://github.com/discordjs/discord.js/commit/62c74b8333066465e5bd295b8b102b35a506751d))
|
||||
|
||||
# [0.2.0-canary.0](https://github.com/discordjs/discord.js-modules/compare/@discordjs/rest@0.1.1-canary.0...@discordjs/rest@0.2.0-canary.0) (2021-12-08)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **CDN#icon:** remove `guild` prefixes ([#67](https://github.com/discordjs/discord.js-modules/issues/67)) ([8882686](https://github.com/discordjs/discord.js-modules/commit/88826869d8ed3695f2b9475bea8d3b851df270bd))
|
||||
- **Cdn:** make parameters immutable ([#84](https://github.com/discordjs/discord.js-modules/issues/84)) ([3105b61](https://github.com/discordjs/discord.js-modules/commit/3105b614da603dd3c8479dea089b5953d3c8b89b))
|
||||
- **CDN:** use correct types ([#86](https://github.com/discordjs/discord.js-modules/issues/86)) ([64b02d4](https://github.com/discordjs/discord.js-modules/commit/64b02d4649a38802dd1a4e7a738ec64c27dea760))
|
||||
- **Rest:** lint errors ([53c0cce](https://github.com/discordjs/discord.js-modules/commit/53c0ccefee80225ca7640cf88f44c68da99f31e7))
|
||||
- use hash instead of animatedHash for default avatar test ([#74](https://github.com/discordjs/discord.js-modules/issues/74)) ([4852838](https://github.com/discordjs/discord.js-modules/commit/485283824cf368874096d59a64131970401218e9))
|
||||
|
||||
## Features
|
||||
|
||||
- **CDN#guildIcon:** implement dynamic logic ([#53](https://github.com/discordjs/discord.js-modules/issues/53)) ([c4b2803](https://github.com/discordjs/discord.js-modules/commit/c4b280366b0c5920c147126ccb9068f16fc898aa))
|
||||
- **CDN:** add role icon endpoint ([#64](https://github.com/discordjs/discord.js-modules/issues/64)) ([4d7d692](https://github.com/discordjs/discord.js-modules/commit/4d7d692b4954c373941d2d8f3e3335a9a8543220))
|
||||
- **CDN:** add sticker endpoints ([#60](https://github.com/discordjs/discord.js-modules/issues/60)) ([3b714ba](https://github.com/discordjs/discord.js-modules/commit/3b714bada415a7987dd6aa50c938751c66dc05be))
|
||||
- **CDN:** guild member avatars ([#68](https://github.com/discordjs/discord.js-modules/issues/68)) ([90c25ad](https://github.com/discordjs/discord.js-modules/commit/90c25ad4afa5ec5906867f431afcaf11fb56355a))
|
||||
- **Errors:** show data sent when an error occurs ([#72](https://github.com/discordjs/discord.js-modules/issues/72)) ([3e2edc8](https://github.com/discordjs/discord.js-modules/commit/3e2edc8974e2c62c324db0c151da4d34c289c40a))
|
||||
- expose https agent options ([#82](https://github.com/discordjs/discord.js-modules/issues/82)) ([7f1c9be](https://github.com/discordjs/discord.js-modules/commit/7f1c9be817bbc6a4a11a726c952580dd3cb7b149))
|
||||
- **RateLimits:** optionally error on ratelimits ([#77](https://github.com/discordjs/discord.js-modules/issues/77)) ([a371f0b](https://github.com/discordjs/discord.js-modules/commit/a371f0bc6c76cffaf048fd0fbf9c64a6c4d6619e))
|
||||
- **RequestManager:** support setting global headers in options ([#70](https://github.com/discordjs/discord.js-modules/issues/70)) ([d1758c7](https://github.com/discordjs/discord.js-modules/commit/d1758c74b00a3f83c39745cd9af147a7f8f2b12b))
|
||||
- **Requests:** add attachment keys and form data for stickers ([#81](https://github.com/discordjs/discord.js-modules/issues/81)) ([7c2b0c0](https://github.com/discordjs/discord.js-modules/commit/7c2b0c0e432b82776bb57c1708f3be6b4affde56))
|
||||
- **Rest:** add response and request events ([#85](https://github.com/discordjs/discord.js-modules/issues/85)) ([c3aba56](https://github.com/discordjs/discord.js-modules/commit/c3aba567572e73548c38cd7c7f9945e9361833de))
|
||||
- **REST:** change api version to v9 ([#62](https://github.com/discordjs/discord.js-modules/issues/62)) ([4c980e6](https://github.com/discordjs/discord.js-modules/commit/4c980e6ad6c0297519ec0f09ec27953764a4a12d))
|
||||
- **Rest:** improve global rate limit and invalid request tracking ([#51](https://github.com/discordjs/discord.js-modules/issues/51)) ([b73cc06](https://github.com/discordjs/discord.js-modules/commit/b73cc060daa701de71815a824ebaccdc9ebf2859))
|
||||
- **Rest:** use native Node.js AbortController ([#66](https://github.com/discordjs/discord.js-modules/issues/66)) ([3b53910](https://github.com/discordjs/discord.js-modules/commit/3b539102f07c413ffd3ee60718ac8e5a709bdd0e))
|
||||
- **SequentialHandler:** add more info to debug when rate limit was hit ([#78](https://github.com/discordjs/discord.js-modules/issues/78)) ([a4e404b](https://github.com/discordjs/discord.js-modules/commit/a4e404b2e6df625a48176b9f1bfac6cfe86c5d66))
|
||||
|
||||
# [0.1.1-canary.0](https://github.com/discordjs/discord.js-modules/compare/@discordjs/rest@0.1.0-canary.0...@discordjs/rest@0.1.1-canary.0) (2021-08-24)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **Rest:** use reference type for DOM ([#55](https://github.com/discordjs/discord.js-modules/issues/55)) ([07f5aa7](https://github.com/discordjs/discord.js-modules/commit/07f5aa744092c16b0f05b05055e5d4bbd49754e7))
|
||||
|
||||
# 0.1.0-canary.0 (2021-06-29)
|
||||
|
||||
## Features
|
||||
|
||||
- **rest:** Implement rest module ([#34](https://github.com/discordjs/discord.js-modules/issues/34)) ([6990f0f](https://github.com/discordjs/discord.js-modules/commit/6990f0f7f3ca958a95f9b1b19681b42669743427))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable id-length */
|
||||
/* eslint-disable promise/prefer-await-to-then */
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import { setInterval, clearInterval } from 'node:timers';
|
||||
import { setInterval, clearInterval, setTimeout } from 'node:timers';
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor';
|
||||
import { beforeEach, afterEach, test, expect, vitest } from 'vitest';
|
||||
@@ -548,3 +548,30 @@ test('malformedRequest', async () => {
|
||||
|
||||
await expect(api.get('/malformedRequest')).rejects.toBeInstanceOf(DiscordAPIError);
|
||||
});
|
||||
|
||||
test('abort', async () => {
|
||||
mockPool
|
||||
.intercept({
|
||||
path: genPath('/abort'),
|
||||
method: 'GET',
|
||||
})
|
||||
.reply(200, { message: 'Hello World' }, responseOptions)
|
||||
.delay(100)
|
||||
.times(3);
|
||||
|
||||
const controller = new AbortController();
|
||||
const [aP2, bP2, cP2] = [
|
||||
api.get('/abort', { signal: controller.signal }),
|
||||
api.get('/abort', { signal: controller.signal }),
|
||||
api.get('/abort', { signal: controller.signal }),
|
||||
];
|
||||
|
||||
await expect(aP2).resolves.toStrictEqual({ message: 'Hello World' });
|
||||
controller.abort();
|
||||
|
||||
// Abort mid-execution:
|
||||
await expect(bP2).rejects.toThrowError('Request aborted');
|
||||
|
||||
// Abort scheduled:
|
||||
await expect(cP2).rejects.toThrowError('Request aborted');
|
||||
});
|
||||
|
||||
@@ -53,9 +53,10 @@
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "workspace:^",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/async-queue": "^1.5.0",
|
||||
"@sapphire/snowflake": "^3.2.2",
|
||||
"discord-api-types": "^0.37.10",
|
||||
"discord-api-types": "^0.37.11",
|
||||
"file-type": "^18.0.0",
|
||||
"tslib": "^2.4.0",
|
||||
"undici": "^5.10.0"
|
||||
|
||||
@@ -3,6 +3,7 @@ import { EventEmitter } from 'node:events';
|
||||
import { setInterval, clearInterval } from 'node:timers';
|
||||
import type { URLSearchParams } from 'node:url';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { lazy } from '@discordjs/util';
|
||||
import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||
import { FormData, type RequestInit, type BodyInit, type Dispatcher, type Agent } from 'undici';
|
||||
import type { RESTOptions, RestEvents, RequestOptions } from './REST.js';
|
||||
@@ -12,12 +13,7 @@ import { DefaultRestOptions, DefaultUserAgent, RESTEvents } from './utils/consta
|
||||
import { resolveBody } from './utils/utils.js';
|
||||
|
||||
// Make this a lazy dynamic import as file-type is a pure ESM package
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
const getFileType = async (): Promise<typeof import('file-type')> => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
let cached: Promise<typeof import('file-type')>;
|
||||
return (cached ??= import('file-type'));
|
||||
};
|
||||
const getFileType = lazy(async () => import('file-type'));
|
||||
|
||||
/**
|
||||
* Represents a file to be added to the request
|
||||
@@ -93,6 +89,10 @@ export interface RequestData {
|
||||
* Reason to show in the audit logs
|
||||
*/
|
||||
reason?: string;
|
||||
/**
|
||||
* The signal to abort the queue entry or the REST call, where applicable
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/**
|
||||
* If this request should be versioned
|
||||
*
|
||||
@@ -133,7 +133,7 @@ export interface InternalRequest extends RequestData {
|
||||
method: RequestMethod;
|
||||
}
|
||||
|
||||
export type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files'>;
|
||||
export type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
|
||||
|
||||
/**
|
||||
* Parsed route data for an endpoint
|
||||
@@ -338,6 +338,7 @@ export class RequestManager extends EventEmitter {
|
||||
body: request.body,
|
||||
files: request.files,
|
||||
auth: request.auth !== false,
|
||||
signal: request.signal,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { STATUS_CODES } from 'node:http';
|
||||
import type { InternalRequest } from '../RequestManager.js';
|
||||
import type { RequestBody } from './DiscordAPIError.js';
|
||||
|
||||
@@ -7,21 +8,21 @@ import type { RequestBody } from './DiscordAPIError.js';
|
||||
export class HTTPError extends Error {
|
||||
public requestBody: RequestBody;
|
||||
|
||||
public override name = HTTPError.name;
|
||||
|
||||
/**
|
||||
* @param name - The name of the error
|
||||
* @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
|
||||
*/
|
||||
public constructor(
|
||||
public override name: string,
|
||||
public status: number,
|
||||
public method: string,
|
||||
public url: string,
|
||||
bodyData: Pick<InternalRequest, 'body' | 'files'>,
|
||||
) {
|
||||
super();
|
||||
super(STATUS_CODES[status]);
|
||||
|
||||
this.requestBody = { files: bodyData.files, json: bodyData.body };
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ export class SequentialHandler implements IHandler {
|
||||
}
|
||||
|
||||
// Wait for any previous requests to be completed before this one is run
|
||||
await queue.wait();
|
||||
await queue.wait({ signal: requestData.signal });
|
||||
// This set handles retroactively sublimiting requests
|
||||
if (queueType === QueueType.Standard) {
|
||||
if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {
|
||||
@@ -293,8 +293,17 @@ export class SequentialHandler implements IHandler {
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), this.manager.options.timeout).unref();
|
||||
let res: Dispatcher.ResponseData;
|
||||
if (requestData.signal) {
|
||||
// The type polyfill is required because Node.js's types are incomplete.
|
||||
const signal = requestData.signal as PolyFillAbortSignal;
|
||||
// If the user signal was aborted, abort the controller, else abort the local signal.
|
||||
// The reason why we don't re-use the user's signal, is because users may use the same signal for multiple
|
||||
// requests, and we do not want to cause unexpected side-effects.
|
||||
if (signal.aborted) controller.abort();
|
||||
else signal.addEventListener('abort', () => controller.abort());
|
||||
}
|
||||
|
||||
let res: Dispatcher.ResponseData;
|
||||
try {
|
||||
res = await request(url, { ...options, signal: controller.signal });
|
||||
} catch (error: unknown) {
|
||||
@@ -473,7 +482,7 @@ export class SequentialHandler implements IHandler {
|
||||
}
|
||||
|
||||
// We are out of retries, throw an error
|
||||
throw new HTTPError(res.constructor.name, status, method, url, requestData);
|
||||
throw new HTTPError(status, method, url, requestData);
|
||||
} else {
|
||||
// Handle possible malformed requests
|
||||
if (status >= 400 && status < 500) {
|
||||
@@ -492,3 +501,9 @@ export class SequentialHandler implements IHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface PolyFillAbortSignal {
|
||||
readonly aborted: boolean;
|
||||
addEventListener(type: 'abort', listener: () => void): void;
|
||||
removeEventListener(type: 'abort', listener: () => void): void;
|
||||
}
|
||||
|
||||
3
packages/util/.eslintrc.json
Normal file
3
packages/util/.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
26
packages/util/.gitignore
vendored
Normal file
26
packages/util/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
docs/**/*
|
||||
!docs/index.json
|
||||
!docs/README.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
coverage/
|
||||
1
packages/util/.lintstagedrc.js
Normal file
1
packages/util/.lintstagedrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.lintstagedrc.json');
|
||||
8
packages/util/.prettierignore
Normal file
8
packages/util/.prettierignore
Normal file
@@ -0,0 +1,8 @@
|
||||
# Autogenerated
|
||||
CHANGELOG.md
|
||||
.turbo
|
||||
dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
1
packages/util/.prettierrc.js
Normal file
1
packages/util/.prettierrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.prettierrc.json');
|
||||
9
packages/util/CHANGELOG.md
Normal file
9
packages/util/CHANGELOG.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [@discordjs/util@0.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/util@0.1.0) - (2022-10-03)
|
||||
|
||||
## Features
|
||||
|
||||
- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3))
|
||||
190
packages/util/LICENSE
Normal file
190
packages/util/LICENSE
Normal file
@@ -0,0 +1,190 @@
|
||||
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 2022 Noel Buechler
|
||||
|
||||
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.
|
||||
34
packages/util/README.md
Normal file
34
packages/util/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
<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://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
|
||||
- [Documentation](https://discord.js.org/#/docs)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
|
||||
- [discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/scripts)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
## Contributing
|
||||
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) 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](https://discord.gg/djs).
|
||||
18
packages/util/__tests__/Equatable.test.ts
Normal file
18
packages/util/__tests__/Equatable.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { isEquatable } from '../src/index.js';
|
||||
|
||||
describe('isEquatable', () => {
|
||||
test('returns true if the object is equatable', () => {
|
||||
expect(isEquatable({ equals: () => true })).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns false if the object is not equatable', () => {
|
||||
expect(isEquatable({})).toBeFalsy();
|
||||
expect(isEquatable(null)).toBeFalsy();
|
||||
expect(isEquatable(undefined)).toBeFalsy();
|
||||
expect(isEquatable(1)).toBeFalsy();
|
||||
expect(isEquatable('')).toBeFalsy();
|
||||
expect(isEquatable([])).toBeFalsy();
|
||||
expect(isEquatable(() => {})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
25
packages/util/__tests__/JSONEncodable.test.ts
Normal file
25
packages/util/__tests__/JSONEncodable.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { isJSONEncodable, type JSONEncodable } from '../src/index.js';
|
||||
|
||||
class Encodable implements JSONEncodable<{}> {
|
||||
public toJSON() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
describe('isJSONEncodable', () => {
|
||||
test('returns true if the object is JSON encodable', () => {
|
||||
expect(isJSONEncodable({ toJSON: () => ({}) })).toBeTruthy();
|
||||
expect(isJSONEncodable(new Encodable())).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns false if the object is not JSON encodable', () => {
|
||||
expect(isJSONEncodable({})).toBeFalsy();
|
||||
expect(isJSONEncodable(null)).toBeFalsy();
|
||||
expect(isJSONEncodable(undefined)).toBeFalsy();
|
||||
expect(isJSONEncodable(1)).toBeFalsy();
|
||||
expect(isJSONEncodable('')).toBeFalsy();
|
||||
expect(isJSONEncodable([])).toBeFalsy();
|
||||
expect(isJSONEncodable(() => {})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
32
packages/util/__tests__/lazy.test.ts
Normal file
32
packages/util/__tests__/lazy.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2020 The Sapphire Community and its contributors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://github.com/sapphiredev/utilities/blob/main/LICENSE.md.
|
||||
*/
|
||||
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { lazy } from '../src/index.js';
|
||||
|
||||
describe('lazy', () => {
|
||||
test('GIVEN string callback THEN returns the same', () => {
|
||||
const callback = vi.fn(() => 'Lorem Ipsum');
|
||||
|
||||
const lazyStoredValue = lazy(callback);
|
||||
|
||||
expect(lazyStoredValue()).toEqual('Lorem Ipsum');
|
||||
});
|
||||
|
||||
test('GIVEN string callback with cached value THEN returns the same', () => {
|
||||
const callback = vi.fn(() => 'Lorem Ipsum');
|
||||
|
||||
const lazyStoredValue = lazy(callback);
|
||||
|
||||
lazyStoredValue();
|
||||
const cachedValue = lazyStoredValue();
|
||||
|
||||
expect(callback).toHaveBeenCalledOnce();
|
||||
expect(cachedValue).toEqual('Lorem Ipsum');
|
||||
});
|
||||
});
|
||||
12
packages/util/__tests__/range.test.ts
Normal file
12
packages/util/__tests__/range.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { range } from '../src/index.js';
|
||||
|
||||
describe('range', () => {
|
||||
test('GIVEN valid range THEN valid array is returned', () => {
|
||||
expect(range(0, 5)).toEqual([0, 1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
test('GIVEN valid range with step THEN valid array is returned', () => {
|
||||
expect(range(0, 10, 2)).toEqual([0, 2, 4, 6, 8, 10]);
|
||||
});
|
||||
});
|
||||
10
packages/util/__tests__/types/Equatable.test-d.ts
Normal file
10
packages/util/__tests__/types/Equatable.test-d.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { expectType } from 'tsd';
|
||||
import type { Equatable } from '../../dist';
|
||||
import { isEquatable } from '../../src/index.js';
|
||||
|
||||
declare const unknownObj: unknown;
|
||||
|
||||
if (isEquatable(unknownObj)) {
|
||||
expectType<Equatable<unknown>>(unknownObj);
|
||||
expectType<boolean>(unknownObj.equals(unknownObj));
|
||||
}
|
||||
10
packages/util/__tests__/types/JSONEncodable.test-d.ts
Normal file
10
packages/util/__tests__/types/JSONEncodable.test-d.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { expectType } from 'tsd';
|
||||
import type { JSONEncodable } from '../../dist';
|
||||
import { isJSONEncodable } from '../../src/index.js';
|
||||
|
||||
declare const unknownObj: unknown;
|
||||
|
||||
if (isJSONEncodable(unknownObj)) {
|
||||
expectType<JSONEncodable<unknown>>(unknownObj);
|
||||
expectType<unknown>(unknownObj.toJSON());
|
||||
}
|
||||
376
packages/util/api-extractor.json
Normal file
376
packages/util/api-extractor.json
Normal file
@@ -0,0 +1,376 @@
|
||||
/**
|
||||
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
|
||||
*/
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||
|
||||
/**
|
||||
* Optionally specifies another JSON config file that this file extends from. This provides a way for
|
||||
* standard settings to be shared across multiple projects.
|
||||
*
|
||||
* If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
|
||||
* the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
|
||||
* resolved using NodeJS require().
|
||||
*
|
||||
* SUPPORTED TOKENS: none
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "extends": "./shared/api-extractor-base.json"
|
||||
// "extends": "my-package/include/api-extractor-base.json"
|
||||
|
||||
/**
|
||||
* Determines the "<projectFolder>" token that can be used with other config file settings. The project folder
|
||||
* typically contains the tsconfig.json and package.json config files, but the path is user-defined.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting.
|
||||
*
|
||||
* The default value for "projectFolder" is the token "<lookup>", which means the folder is determined by traversing
|
||||
* parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder
|
||||
* that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error
|
||||
* will be reported.
|
||||
*
|
||||
* SUPPORTED TOKENS: <lookup>
|
||||
* DEFAULT VALUE: "<lookup>"
|
||||
*/
|
||||
// "projectFolder": "..",
|
||||
|
||||
/**
|
||||
* (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
|
||||
* analyzes the symbols exported by this module.
|
||||
*
|
||||
* The file extension must be ".d.ts" and not ".ts".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
*/
|
||||
"mainEntryPointFilePath": "<projectFolder>/docs/dist/index.d.ts",
|
||||
|
||||
/**
|
||||
* A list of NPM package names whose exports should be treated as part of this package.
|
||||
*
|
||||
* For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
|
||||
* and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
|
||||
* of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
|
||||
* imports library2. To avoid this, we can specify:
|
||||
*
|
||||
* "bundledPackages": [ "library2" ],
|
||||
*
|
||||
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
|
||||
* local files for library1.
|
||||
*/
|
||||
"bundledPackages": [],
|
||||
|
||||
/**
|
||||
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
|
||||
*/
|
||||
"compiler": {
|
||||
/**
|
||||
* Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* Note: This setting will be ignored if "overrideTsconfig" is used.
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/tsconfig.json"
|
||||
*/
|
||||
// "tsconfigFilePath": "<projectFolder>/tsconfig.json",
|
||||
/**
|
||||
* Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
|
||||
* The object must conform to the TypeScript tsconfig schema:
|
||||
*
|
||||
* http://json.schemastore.org/tsconfig
|
||||
*
|
||||
* If omitted, then the tsconfig.json file will be read from the "projectFolder".
|
||||
*
|
||||
* DEFAULT VALUE: no overrideTsconfig section
|
||||
*/
|
||||
// "overrideTsconfig": {
|
||||
// . . .
|
||||
// }
|
||||
/**
|
||||
* This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended
|
||||
* and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when
|
||||
* dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses
|
||||
* for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "skipLibCheck": true,
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the API report file (*.api.md) will be generated.
|
||||
*/
|
||||
"apiReport": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate an API report.
|
||||
*/
|
||||
"enabled": false
|
||||
|
||||
/**
|
||||
* The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
|
||||
* a full file path.
|
||||
*
|
||||
* The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
|
||||
*
|
||||
* SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<unscopedPackageName>.api.md"
|
||||
*/
|
||||
// "reportFileName": "<unscopedPackageName>.api.md",
|
||||
|
||||
/**
|
||||
* Specifies the folder where the API report file is written. The file name portion is determined by
|
||||
* the "reportFileName" setting.
|
||||
*
|
||||
* The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
|
||||
* e.g. for an API review.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/temp/"
|
||||
*/
|
||||
// "reportFolder": "<projectFolder>/temp/",
|
||||
|
||||
/**
|
||||
* Specifies the folder where the temporary report file is written. The file name portion is determined by
|
||||
* the "reportFileName" setting.
|
||||
*
|
||||
* After the temporary file is written to disk, it is compared with the file in the "reportFolder".
|
||||
* If they are different, a production build will fail.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/temp/"
|
||||
*/
|
||||
// "reportTempFolder": "<projectFolder>/temp/"
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the doc model file (*.api.json) will be generated.
|
||||
*/
|
||||
"docModel": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate a doc model file.
|
||||
*/
|
||||
"enabled": true,
|
||||
|
||||
/**
|
||||
* The output path for the doc model file. The file extension should be ".api.json".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
||||
*/
|
||||
"apiJsonFilePath": "<projectFolder>/docs/docs.api.json"
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the .d.ts rollup file will be generated.
|
||||
*/
|
||||
"dtsRollup": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate the .d.ts rollup file.
|
||||
*/
|
||||
"enabled": false
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated without any trimming.
|
||||
* This file will include all declarations that are exported by the main entry point.
|
||||
*
|
||||
* If the path is an empty string, then this file will not be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
|
||||
*/
|
||||
// "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated with trimming for an "alpha" release.
|
||||
* This file will include only declarations that are marked as "@public", "@beta", or "@alpha".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "alphaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-alpha.d.ts",
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
|
||||
* This file will include only declarations that are marked as "@public" or "@beta".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
|
||||
* This file will include only declarations that are marked as "@public".
|
||||
*
|
||||
* If the path is an empty string, then this file will not be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts",
|
||||
|
||||
/**
|
||||
* When a declaration is trimmed, by default it will be replaced by a code comment such as
|
||||
* "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
|
||||
* declaration completely.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "omitTrimmingComments": true
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the tsdoc-metadata.json file will be generated.
|
||||
*/
|
||||
"tsdocMetadata": {
|
||||
/**
|
||||
* Whether to generate the tsdoc-metadata.json file.
|
||||
*
|
||||
* DEFAULT VALUE: true
|
||||
*/
|
||||
// "enabled": true,
|
||||
/**
|
||||
* Specifies where the TSDoc metadata file should be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* The default value is "<lookup>", which causes the path to be automatically inferred from the "tsdocMetadata",
|
||||
* "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup
|
||||
* falls back to "tsdoc-metadata.json" in the package folder.
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<lookup>"
|
||||
*/
|
||||
// "tsdocMetadataFilePath": "<projectFolder>/dist/tsdoc-metadata.json"
|
||||
},
|
||||
|
||||
/**
|
||||
* Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
|
||||
* will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
|
||||
* To use the OS's default newline kind, specify "os".
|
||||
*
|
||||
* DEFAULT VALUE: "crlf"
|
||||
*/
|
||||
"newlineKind": "lf",
|
||||
|
||||
/**
|
||||
* Configures how API Extractor reports error and warning messages produced during analysis.
|
||||
*
|
||||
* There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
|
||||
*/
|
||||
"messages": {
|
||||
/**
|
||||
* Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
|
||||
* the input .d.ts files.
|
||||
*
|
||||
* TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
|
||||
*
|
||||
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
|
||||
*/
|
||||
"compilerMessageReporting": {
|
||||
/**
|
||||
* Configures the default routing for messages that don't match an explicit rule in this table.
|
||||
*/
|
||||
"default": {
|
||||
/**
|
||||
* Specifies whether the message should be written to the the tool's output log. Note that
|
||||
* the "addToApiReportFile" property may supersede this option.
|
||||
*
|
||||
* Possible values: "error", "warning", "none"
|
||||
*
|
||||
* Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail
|
||||
* and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes
|
||||
* the "--local" option), the warning is displayed but the build will not fail.
|
||||
*
|
||||
* DEFAULT VALUE: "warning"
|
||||
*/
|
||||
"logLevel": "warning"
|
||||
|
||||
/**
|
||||
* When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
|
||||
* then the message will be written inside that file; otherwise, the message is instead logged according to
|
||||
* the "logLevel" option.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "addToApiReportFile": false
|
||||
}
|
||||
|
||||
// "TS2551": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures handling of messages reported by API Extractor during its analysis.
|
||||
*
|
||||
* API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
|
||||
*
|
||||
* DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
|
||||
*/
|
||||
"extractorMessageReporting": {
|
||||
"default": {
|
||||
"logLevel": "warning"
|
||||
// "addToApiReportFile": false
|
||||
}
|
||||
|
||||
// "ae-extra-release-tag": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures handling of messages reported by the TSDoc parser when analyzing code comments.
|
||||
*
|
||||
* TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text"
|
||||
*
|
||||
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
|
||||
*/
|
||||
"tsdocMessageReporting": {
|
||||
"default": {
|
||||
"logLevel": "warning"
|
||||
// "addToApiReportFile": false
|
||||
}
|
||||
|
||||
// "tsdoc-link-tag-unescaped-text": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ body = """
|
||||
{% if previous %}\
|
||||
{% if previous.version %}\
|
||||
(https://github.com/discordjs/discord.js/compare/{{ previous.version }}...{{ version }})\
|
||||
{% else %}
|
||||
{% else %}\
|
||||
(https://github.com/discordjs/discord.js/tree/{{ version }})\
|
||||
{% endif %}\
|
||||
{% endif %} \
|
||||
@@ -57,8 +57,7 @@ commit_parsers = [
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
filter_commits = true
|
||||
tag_pattern = "@discordjs\\/proxy-container@.*"
|
||||
skip_tags = "v[0-9]*|11|12"
|
||||
tag_pattern = "@discordjs/util@[0-9]*"
|
||||
ignore_tags = ""
|
||||
date_order = true
|
||||
sort_commits = "newest"
|
||||
1
packages/util/docs/README.md
Normal file
1
packages/util/docs/README.md
Normal file
@@ -0,0 +1 @@
|
||||
## [View the documentation here.](https://discord.js.org/#/docs/rest)
|
||||
1
packages/util/docs/index.json
Normal file
1
packages/util/docs/index.json
Normal file
@@ -0,0 +1 @@
|
||||
[{ "name": "General", "files": [{ "name": "Welcome", "id": "welcome", "path": "../../README.md" }] }]
|
||||
78
packages/util/package.json
Normal file
78
packages/util/package.json
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"name": "@discordjs/util",
|
||||
"version": "0.1.0",
|
||||
"description": "Utilities shared across Discord.js packages",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"test": "vitest run && tsd",
|
||||
"lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts",
|
||||
"format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||
"fmt": "yarn format",
|
||||
"docs": "downlevel-dts dist docs/dist --to=3.7 && api-extractor run --local",
|
||||
"prepack": "yarn lint && yarn test && yarn build",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/util/*'",
|
||||
"release": "cliff-jumper"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "src"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordjs"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^1.8.8",
|
||||
"@microsoft/api-extractor": "^7.32.0",
|
||||
"@types/node": "^16.11.56",
|
||||
"@vitest/coverage-c8": "^0.22.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"downlevel-dts": "^0.10.1",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-neon": "^0.1.31",
|
||||
"prettier": "^2.7.1",
|
||||
"tsd": "^0.23.0",
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.2",
|
||||
"vitest": "^0.22.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "__tests__/types"
|
||||
}
|
||||
}
|
||||
2
packages/util/src/functions/index.ts
Normal file
2
packages/util/src/functions/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './lazy.js';
|
||||
export * from './range.js';
|
||||
18
packages/util/src/functions/lazy.ts
Normal file
18
packages/util/src/functions/lazy.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Lazy is a wrapper around a value that is computed lazily. It is useful for
|
||||
* cases where the value is expensive to compute and the computation may not
|
||||
* be needed at all.
|
||||
*
|
||||
* @param cb - The callback to lazily evaluate
|
||||
* @typeParam T - The type of the value
|
||||
* @example
|
||||
* ```ts
|
||||
* const value = lazy(() => computeExpensiveValue());
|
||||
* ```
|
||||
*/
|
||||
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
||||
export function lazy<T>(cb: () => T): () => T {
|
||||
let defaultValue: T;
|
||||
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
||||
return () => (defaultValue ??= cb());
|
||||
}
|
||||
20
packages/util/src/functions/range.ts
Normal file
20
packages/util/src/functions/range.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Yields the numbers in the given range as an array
|
||||
*
|
||||
* @param start - The start of the range
|
||||
* @param end - The end of the range (inclusive)
|
||||
* @param step - The amount to increment between each number
|
||||
* @example
|
||||
* Basic range
|
||||
* ```ts
|
||||
* range(3, 5); // [3, 4, 5]
|
||||
* ```
|
||||
* @example
|
||||
* Range with a step
|
||||
* ```ts
|
||||
* range(3, 10, 2); // [3, 5, 7, 9]
|
||||
* ```
|
||||
*/
|
||||
export function range(start: number, end: number, step = 1): number[] {
|
||||
return Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);
|
||||
}
|
||||
4
packages/util/src/index.ts
Normal file
4
packages/util/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './types.js';
|
||||
export * from './functions/index.js';
|
||||
export * from './JSONEncodable.js';
|
||||
export * from './Equatable.js';
|
||||
4
packages/util/src/types.ts
Normal file
4
packages/util/src/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Represents a type that may or may not be a promise
|
||||
*/
|
||||
export type Awaitable<T> = PromiseLike<T> | T;
|
||||
20
packages/util/tsconfig.eslint.json
Normal file
20
packages/util/tsconfig.eslint.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
4
packages/util/tsconfig.json
Normal file
4
packages/util/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
3
packages/util/tsup.config.js
Normal file
3
packages/util/tsup.config.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig();
|
||||
@@ -36,19 +36,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- **voice:** Bring back typed events (#8109) ([70b42bb](https://github.com/discordjs/discord.js/commit/70b42bb64a4f83da0da242569b9c7921c8d1e26f))
|
||||
|
||||
# [@discordjs/voice@0.10.0](https://github.com/discordjs/discord.js/compare/@discordjs/voice@0.9.0...@discordjs/voice@0.10.0) - (2022-06-04)
|
||||
|
||||
## Styling
|
||||
|
||||
- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629))
|
||||
|
||||
# [@discordjs/voice@0.10.0](https://github.com/discordjs/discord.js/compare/@discordjs/voice@0.9.0...@discordjs/voice@0.10.0) - (2022-06-04)
|
||||
|
||||
## Styling
|
||||
|
||||
- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629))
|
||||
|
||||
# [@discordjs/voice@0.9.0](https://github.com/discordjs/discord.js/compare/@discordjs/voice@0.8.0...@discordjs/voice@0.9.0) - (2022-04-17)
|
||||
# [@discordjs/voice@0.10.0](https://github.com/discordjs/discord.js/compare/@discordjs/voice@0.8.0...@discordjs/voice@0.10.0) - (2022-06-04)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
@@ -76,39 +64,3 @@ All notable changes to this project will be documented in this file.
|
||||
- **voice:** Fix tests ([62c74b8](https://github.com/discordjs/discord.js/commit/62c74b8333066465e5bd295b8b102b35a506751d))
|
||||
- Fix voice secretbox tests ([4a2dbd6](https://github.com/discordjs/discord.js/commit/4a2dbd62382f904d596b34da0116d50e724b81c4))
|
||||
- Fix voice tests ([b593bd3](https://github.com/discordjs/discord.js/commit/b593bd32a98282a92fa28f2fb0a8ef239866622c))
|
||||
|
||||
# [0.7.5](https://github.com/discordjs/voice/compare/v0.7.4...v0.7.5) (2021-11-12)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- postbuild script ([644af95](https://github.com/discordjs/voice/commit/644af9579f02724c489514f482640b8413d2c305))
|
||||
|
||||
# [0.7.4](https://github.com/discordjs/voice/compare/v0.7.3...v0.7.4) (2021-11-12)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- conditionally apply banner only to esm build ([8c4e8c4](https://github.com/discordjs/voice/commit/8c4e8c4ba5b9013a90de0238a7f2771e9113a62d))
|
||||
|
||||
# [0.7.3](https://github.com/discordjs/voice/compare/v0.7.2...v0.7.3) (2021-11-11)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **esm:** resolve esm imports ([#229](https://github.com/discordjs/voice/issues/229)) ([616f2bc](https://github.com/discordjs/voice/commit/616f2bcfde47e55ac7b09f4faaa07f15d78c11a5))
|
||||
|
||||
# [0.7.2](https://github.com/discordjs/voice/compare/v0.7.1...v0.7.2) (2021-10-30)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- prism imports for ems ([0bfd6d5](https://github.com/discordjs/voice/commit/0bfd6d5247f89cfc125e7645e9fb7ebfed94bb2f))
|
||||
|
||||
# [0.7.1](https://github.com/discordjs/voice/compare/v0.7.0...v0.7.1) (2021-10-30)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- prism imports for esm ([9222dbf](https://github.com/discordjs/voice/commit/9222dbfedd8bfaeb679133dfa41330ea75a03a70))
|
||||
|
||||
# [0.7.0](https://github.com/discordjs/voice/compare/v0.6.0...v0.7.0) (2021-10-30)
|
||||
|
||||
## Features
|
||||
|
||||
- export some types so they render in docs ([#211](https://github.com/discordjs/voice/issues/211)) ([a6dad47](https://github.com/discordjs/voice/commit/a6dad4781fb479d22d7bff99888e42368d6d6411))
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@types/ws": "^8.5.3",
|
||||
"discord-api-types": "^0.37.10",
|
||||
"discord-api-types": "^0.37.11",
|
||||
"prism-media": "^1.3.4",
|
||||
"tslib": "^2.4.0",
|
||||
"ws": "^8.9.0"
|
||||
|
||||
@@ -280,5 +280,5 @@ export default function SlugPage(props: Partial<SidebarLayoutProps & { error?: s
|
||||
}
|
||||
|
||||
export const config = {
|
||||
unstable_includeFiles: ['../{builders,collection,proxy,rest,voice,ws}/README.md'],
|
||||
unstable_includeFiles: ['../{builders,collection,proxy,rest,util,voice,ws}/README.md'],
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const PACKAGES = ['builders', 'collection', 'proxy', 'rest', 'voice', 'ws'];
|
||||
export const PACKAGES = ['builders', 'collection', 'proxy', 'rest', 'util', 'voice', 'ws'];
|
||||
|
||||
export const DESCRIPTION =
|
||||
"discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.";
|
||||
|
||||
@@ -27,16 +27,11 @@ All notable changes to this project will be documented in this file.
|
||||
- **website:** Adjust typography (#8503) ([0f83402](https://github.com/discordjs/discord.js/commit/0f834029850d2448981596cf082ff59917018d66))
|
||||
- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e))
|
||||
|
||||
# [@discordjs/ws@0.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.1.0...@discordjs/ws@0.2.0) - (2022-07-30)
|
||||
# [@discordjs/ws@0.2.0](https://github.com/discordjs/discord.js/tree/@discordjs/ws@0.2.0) - (2022-07-30)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **WebSocketShard:** Account code 1000 with no prior indication (#8399) ([5137bfc](https://github.com/discordjs/discord.js/commit/5137bfc17d763488083b76ee9008611df333272a))
|
||||
|
||||
# [@discordjs/ws@0.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/ws@0.1.0) - (2022-07-27)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **WebSocketShard:** Use correct import (#8357) ([78d4295](https://github.com/discordjs/discord.js/commit/78d4295a40b83ea4f7cc830ff81927cba2d1d3f0))
|
||||
|
||||
## Features
|
||||
|
||||
@@ -54,10 +54,11 @@
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "workspace:^",
|
||||
"@discordjs/rest": "workspace:^",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/async-queue": "^1.5.0",
|
||||
"@types/ws": "^8.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.1.2",
|
||||
"discord-api-types": "^0.37.10",
|
||||
"discord-api-types": "^0.37.11",
|
||||
"tslib": "^2.4.0",
|
||||
"ws": "^8.9.0"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,6 @@ export * from './strategies/sharding/WorkerShardingStrategy.js';
|
||||
|
||||
export * from './utils/constants.js';
|
||||
export * from './utils/IdentifyThrottler.js';
|
||||
export * from './utils/utils.js';
|
||||
|
||||
export * from './ws/WebSocketManager.js';
|
||||
export * from './ws/WebSocketShard.js';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Awaitable } from '@vladfrangu/async_event_emitter';
|
||||
import type { Awaitable } from '@discordjs/util';
|
||||
import type { APIGatewayBotInfo } from 'discord-api-types/v10';
|
||||
import type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../../ws/WebSocketManager';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Awaitable } from '@discordjs/util';
|
||||
import type { GatewaySendPayload } from 'discord-api-types/v10';
|
||||
import type { Awaitable } from '../../utils/utils';
|
||||
import type { WebSocketShardDestroyOptions } from '../../ws/WebSocketShard';
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,9 @@ import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { lazy } from '@discordjs/util';
|
||||
import { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';
|
||||
import type { OptionalWebSocketManagerOptions, SessionInfo } from '../ws/WebSocketManager.js';
|
||||
import { lazy } from './utils.js';
|
||||
|
||||
/**
|
||||
* Valid encoding types
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import type { ShardRange } from '../ws/WebSocketManager';
|
||||
|
||||
export type Awaitable<T> = Promise<T> | T;
|
||||
|
||||
/**
|
||||
* Yields the numbers in the given range as an array
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* range({ start: 3, end: 5 }); // [3, 4, 5]
|
||||
* ```
|
||||
*/
|
||||
export function range({ start, end }: ShardRange): number[] {
|
||||
return Array.from({ length: end - start + 1 }, (_, index) => index + start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily evaluate a callback, storing its result
|
||||
*/
|
||||
export function lazy<T>(cb: () => T): () => T {
|
||||
let defaultValue: T;
|
||||
return () => (defaultValue ??= cb());
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import { range, type Awaitable } from '@discordjs/util';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
import {
|
||||
Routes,
|
||||
@@ -12,7 +13,6 @@ import {
|
||||
import type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy';
|
||||
import { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';
|
||||
import { DefaultWebSocketManagerOptions, type CompressionMethod, type Encoding } from '../utils/constants.js';
|
||||
import { range, type Awaitable } from '../utils/utils.js';
|
||||
import type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard.js';
|
||||
|
||||
/**
|
||||
@@ -264,11 +264,11 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {
|
||||
if (Array.isArray(this.options.shardIds)) {
|
||||
shardIds = this.options.shardIds;
|
||||
} else {
|
||||
shardIds = range(this.options.shardIds);
|
||||
shardIds = range(this.options.shardIds.start, this.options.shardIds.end);
|
||||
}
|
||||
} else {
|
||||
const data = await this.fetchGatewayInformation();
|
||||
shardIds = range({ start: 0, end: (this.options.shardCount ?? data.shards) - 1 });
|
||||
shardIds = range(0, (this.options.shardCount ?? data.shards) - 1);
|
||||
}
|
||||
|
||||
this.shardIds = shardIds;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { URLSearchParams } from 'node:url';
|
||||
import { TextDecoder } from 'node:util';
|
||||
import { inflate } from 'node:zlib';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { lazy } from '@discordjs/util';
|
||||
import { AsyncQueue } from '@sapphire/async-queue';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
import {
|
||||
@@ -22,7 +23,6 @@ import { WebSocket, type RawData } from 'ws';
|
||||
import type { Inflate } from 'zlib-sync';
|
||||
import type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy';
|
||||
import { ImportantGatewayOpcodes } from '../utils/constants.js';
|
||||
import { lazy } from '../utils/utils.js';
|
||||
import type { SessionInfo } from './WebSocketManager.js';
|
||||
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
|
||||
Reference in New Issue
Block a user