mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 20:10:08 +00:00
Compare commits
337 Commits
@discordjs
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41d1c2eefc | ||
|
|
60c70389a4 | ||
|
|
f06d12fd73 | ||
|
|
dc31b76465 | ||
|
|
ba90f14f9b | ||
|
|
7b76b0b7e7 | ||
|
|
63939f8219 | ||
|
|
33ec49d5bf | ||
|
|
d923d0ab96 | ||
|
|
62332c2720 | ||
|
|
7af3c3b6f1 | ||
|
|
5730866073 | ||
|
|
9f68d73706 | ||
|
|
0ac3e766bd | ||
|
|
76a7021452 | ||
|
|
103cb16be0 | ||
|
|
baa6c69835 | ||
|
|
f85022162d | ||
|
|
35bfba0c50 | ||
|
|
ecfe4e3f1c | ||
|
|
2628659747 | ||
|
|
01d75c8b8b | ||
|
|
b64d657241 | ||
|
|
7e51ea0ada | ||
|
|
aec44a0c93 | ||
|
|
e745b95677 | ||
|
|
9effd82abe | ||
|
|
628759bcff | ||
|
|
a306219673 | ||
|
|
c0f7a1a89a | ||
|
|
a7eab50ee3 | ||
|
|
ace974fc1f | ||
|
|
d9137c3658 | ||
|
|
b7fadb350a | ||
|
|
1f944b889f | ||
|
|
b187a18e9c | ||
|
|
0b8651cf85 | ||
|
|
bf92172d80 | ||
|
|
b2ec865765 | ||
|
|
3f8656115b | ||
|
|
883f6e9202 | ||
|
|
2ea2a85e63 | ||
|
|
f063625836 | ||
|
|
6398e46043 | ||
|
|
d24dbf7d22 | ||
|
|
3c231ae81a | ||
|
|
9f63eb977f | ||
|
|
c69f512450 | ||
|
|
4a07f9eaa1 | ||
|
|
64cd53c4c2 | ||
|
|
d79aa2d0d0 | ||
|
|
822b7f234a | ||
|
|
8ca407e089 | ||
|
|
0126d9b810 | ||
|
|
e9931229ae | ||
|
|
1486bc9336 | ||
|
|
16fcdc3687 | ||
|
|
8622939229 | ||
|
|
2487e3bf76 | ||
|
|
578bc951bd | ||
|
|
1244854e13 | ||
|
|
b1e190c4f0 | ||
|
|
fc8ed816e6 | ||
|
|
abb7226af3 | ||
|
|
30ceaf7e47 | ||
|
|
9b40a79b3e | ||
|
|
0b12d6fa10 | ||
|
|
b106956308 | ||
|
|
6f1f465a77 | ||
|
|
eb98372dcd | ||
|
|
5048a3d17a | ||
|
|
f0497343f1 | ||
|
|
f6f15d8e87 | ||
|
|
14bbc9150a | ||
|
|
a7f816eeb7 | ||
|
|
802b2394b0 | ||
|
|
c446a84570 | ||
|
|
9cf0a4904b | ||
|
|
25dc146247 | ||
|
|
a2b08aaf3b | ||
|
|
eba9cc6038 | ||
|
|
145eb2fc5d | ||
|
|
8444576f45 | ||
|
|
6d43e26676 | ||
|
|
2fc3d86f56 | ||
|
|
8a8d519c9c | ||
|
|
669c3cd256 | ||
|
|
678ceaa014 | ||
|
|
0785353efe | ||
|
|
8323926304 | ||
|
|
bccc2c8e89 | ||
|
|
1d72663e92 | ||
|
|
d0a2a6227d | ||
|
|
735e0bf52e | ||
|
|
1c5b78fd21 | ||
|
|
053da5bc91 | ||
|
|
fc9653f5ae | ||
|
|
22ac6b4660 | ||
|
|
d14d47b62f | ||
|
|
a9f003ac9b | ||
|
|
1d4cdee321 | ||
|
|
8e1afaebdb | ||
|
|
32523325c6 | ||
|
|
7a9e52e63a | ||
|
|
d11edc6397 | ||
|
|
96304d7cc8 | ||
|
|
f9e9bfdedc | ||
|
|
ce1f5c8d47 | ||
|
|
03fb5b0a2f | ||
|
|
ce991dd1d8 | ||
|
|
dbca93098c | ||
|
|
dd5a08944c | ||
|
|
8e98ba94d2 | ||
|
|
74dc8c10d5 | ||
|
|
8d07ea9a62 | ||
|
|
d8e774138d | ||
|
|
55c3ee20ae | ||
|
|
c3341570d9 | ||
|
|
f3ce4a75d0 | ||
|
|
4ffdada4f7 | ||
|
|
8b3d006118 | ||
|
|
d08a57cadd | ||
|
|
0dc68445a1 | ||
|
|
a7ad7e75ce | ||
|
|
f79ccb4971 | ||
|
|
6f2b223c8b | ||
|
|
a4777aa9b0 | ||
|
|
f072d3d916 | ||
|
|
0238588067 | ||
|
|
1d460e0434 | ||
|
|
b9c62ac0f0 | ||
|
|
df46ab8061 | ||
|
|
b7eb96d456 | ||
|
|
f77612a55e | ||
|
|
9b4116b659 | ||
|
|
8a91d7c256 | ||
|
|
3b7ba4062e | ||
|
|
edadb9fe5d | ||
|
|
4bdb0593ae | ||
|
|
fd97da9b6c | ||
|
|
d5dcddd350 | ||
|
|
40324574eb | ||
|
|
1398af66f0 | ||
|
|
682e0e1802 | ||
|
|
13baf75cae | ||
|
|
1d6b31b78d | ||
|
|
5f093dde24 | ||
|
|
b58e6a65ad | ||
|
|
204f4dd7c4 | ||
|
|
249ba0a9a6 | ||
|
|
92933c2b61 | ||
|
|
abd3fc8ceb | ||
|
|
84059b6b25 | ||
|
|
6da405668f | ||
|
|
58d2a1e6d7 | ||
|
|
7b5c688844 | ||
|
|
28bc4f42c6 | ||
|
|
5b4672bad3 | ||
|
|
a57b9ba5c4 | ||
|
|
32da9b3868 | ||
|
|
70806b401e | ||
|
|
0674820723 | ||
|
|
2d5bce274c | ||
|
|
331dedcb9d | ||
|
|
103e1bd843 | ||
|
|
ffafde0b6b | ||
|
|
28422eea58 | ||
|
|
c826ad3ade | ||
|
|
17559becef | ||
|
|
b31a23b37c | ||
|
|
8e4f77a63b | ||
|
|
b16ab8c69f | ||
|
|
cf8570c19c | ||
|
|
f0ab393411 | ||
|
|
11e02f1e5d | ||
|
|
206523587a | ||
|
|
ac3bc6a2db | ||
|
|
af295acedc | ||
|
|
caa5c0332f | ||
|
|
434f696397 | ||
|
|
6062d361fb | ||
|
|
2ecb862e76 | ||
|
|
360936140b | ||
|
|
0b56184ba7 | ||
|
|
a55545850a | ||
|
|
f16b11a91d | ||
|
|
0fb2694871 | ||
|
|
ee030003ec | ||
|
|
29c51be1f4 | ||
|
|
43a78be70b | ||
|
|
92c0c60519 | ||
|
|
ba3e0ed348 | ||
|
|
f7ce9f8533 | ||
|
|
00990c93ae | ||
|
|
c076b0d8cb | ||
|
|
d297fb0b69 | ||
|
|
24c128d649 | ||
|
|
ec7c6e3d3e | ||
|
|
6dfb9bbc48 | ||
|
|
4644e45e85 | ||
|
|
1e001601c8 | ||
|
|
1aec243b1d | ||
|
|
191951ac28 | ||
|
|
4fb4492b17 | ||
|
|
abb968de81 | ||
|
|
d9e53093f5 | ||
|
|
e5678f4656 | ||
|
|
9f18036078 | ||
|
|
474eae0afc | ||
|
|
caeb66e150 | ||
|
|
7623fc552e | ||
|
|
230c43e97d | ||
|
|
4e3fa586b5 | ||
|
|
6bb1474d20 | ||
|
|
27bbc8fe68 | ||
|
|
e2cde5daa0 | ||
|
|
0960457108 | ||
|
|
cd6b365b17 | ||
|
|
19e1f5d0ca | ||
|
|
3621e5efbd | ||
|
|
d2f5b5b539 | ||
|
|
9ed11a4c19 | ||
|
|
e42fd16369 | ||
|
|
dd44e8b6ec | ||
|
|
3bef9018c0 | ||
|
|
23a0b6ccf2 | ||
|
|
b3f7c32f7f | ||
|
|
0dba8adbd2 | ||
|
|
2b8074dd12 | ||
|
|
16bbc8aa20 | ||
|
|
7a3d18dd6d | ||
|
|
4882b17a77 | ||
|
|
8028813825 | ||
|
|
47f2990b89 | ||
|
|
e475b63f25 | ||
|
|
673262d38c | ||
|
|
7f415a2502 | ||
|
|
cda3f005b1 | ||
|
|
f9c25ddcfe | ||
|
|
74740260a7 | ||
|
|
1008e3d4a7 | ||
|
|
17ab0e652c | ||
|
|
872ce801a0 | ||
|
|
0bf3df30da | ||
|
|
20680efbc9 | ||
|
|
7701331b1c | ||
|
|
0be85fd101 | ||
|
|
e147c5bd64 | ||
|
|
2f1ec7401c | ||
|
|
0f83402985 | ||
|
|
d97cd936fd | ||
|
|
812f7f1ea8 | ||
|
|
7d2507279c | ||
|
|
c31a5cfcc8 | ||
|
|
acdafe60c7 | ||
|
|
4fd42528fe | ||
|
|
ebaf158006 | ||
|
|
7116647947 | ||
|
|
c99b808882 | ||
|
|
a1dddd6b2c | ||
|
|
b3db9eef32 | ||
|
|
501945215b | ||
|
|
e82b2e49f5 | ||
|
|
5f42b5af30 | ||
|
|
35e79b389d | ||
|
|
5dc7946df2 | ||
|
|
1e00f5789e | ||
|
|
85cb0f25c7 | ||
|
|
3cc893a282 | ||
|
|
fc99bf431a | ||
|
|
4ab1d09997 | ||
|
|
d09ef1e425 | ||
|
|
d56590a11d | ||
|
|
c052f56f3e | ||
|
|
cb856860b7 | ||
|
|
4cf265c7c6 | ||
|
|
3ec7ef07a0 | ||
|
|
90e7aea443 | ||
|
|
1211c7fc10 | ||
|
|
84a4b1f58a | ||
|
|
193b252672 | ||
|
|
bc06cc638d | ||
|
|
d08da8a212 | ||
|
|
5360099e5f | ||
|
|
fd4844ddb9 | ||
|
|
8e69efde04 | ||
|
|
2447165c82 | ||
|
|
c97977a3e8 | ||
|
|
7666a6c341 | ||
|
|
9d8966fe24 | ||
|
|
4d128acac5 | ||
|
|
831d6506cb | ||
|
|
c5b96a185c | ||
|
|
afa27b15c5 | ||
|
|
4d7283933d | ||
|
|
452e94fd3e | ||
|
|
6c6fe74dd8 | ||
|
|
0e2a09571c | ||
|
|
0fab869e51 | ||
|
|
64a4041a05 | ||
|
|
38275fc53d | ||
|
|
aac8acc22b | ||
|
|
6ef4754d40 | ||
|
|
b8a31360a2 | ||
|
|
5b053cf82e | ||
|
|
e72b986939 | ||
|
|
3a96ce7970 | ||
|
|
359f688555 | ||
|
|
3161e1a1ac | ||
|
|
4d8361c711 | ||
|
|
d6e4d149fd | ||
|
|
480c85c9c3 | ||
|
|
b45b99f92b | ||
|
|
5137bfc17d | ||
|
|
fca3dada2a | ||
|
|
d070de6da7 | ||
|
|
a3183cfad4 | ||
|
|
aba307341d | ||
|
|
c479d39a6b | ||
|
|
52c2818b25 | ||
|
|
d03cf6176c | ||
|
|
11e77f7f86 | ||
|
|
2b1e88b5fa | ||
|
|
e5bfe2c7c2 | ||
|
|
a7deb8f898 | ||
|
|
b4e2c0c4d5 | ||
|
|
33113614e0 | ||
|
|
26556390a3 | ||
|
|
5494791313 | ||
|
|
c258bdf083 | ||
|
|
ff5dd1fcb4 | ||
|
|
a38c58dbd0 | ||
|
|
ec43c184fe | ||
|
|
c25e8ad78b | ||
|
|
3f17ff23bf | ||
|
|
a7dc588d9f | ||
|
|
2291429d30 |
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": "marine/prettier/node",
|
||||
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.eslint.json"
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/consistent-type-definitions": ["error", "interface"]
|
||||
},
|
||||
"ignorePatterns": ["**/dist/*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
|
||||
11
.github/.kodiak.toml
vendored
Normal file
11
.github/.kodiak.toml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
version = 1
|
||||
|
||||
[merge]
|
||||
require_automerge_label = false
|
||||
blocking_labels = ['blocked']
|
||||
method = 'squash'
|
||||
|
||||
[merge.message]
|
||||
title = 'pull_request_title'
|
||||
strip_html_comments = true
|
||||
include_coauthors = true
|
||||
11
.github/CONTRIBUTING.md
vendored
11
.github/CONTRIBUTING.md
vendored
@@ -16,3 +16,14 @@ To get ready to work on the codebase, please do the following:
|
||||
4. Code your heart out!
|
||||
5. Run `yarn test` to run ESLint and ensure any JSDoc changes are valid
|
||||
6. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js/blob/main/.github/COMMIT_CONVENTION.md))
|
||||
|
||||
## Adding new packages
|
||||
|
||||
If you'd like to create another package under the `@discordjs` organization run the following command:
|
||||
|
||||
```bash
|
||||
yarn create-package <package-name> [package-description]
|
||||
```
|
||||
|
||||
This will create new package directory under `packages/` with the required configuration files. You can
|
||||
begin to make changes within the `src/` directory.
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -52,7 +52,7 @@ body:
|
||||
id: djs-version
|
||||
attributes:
|
||||
label: Package version
|
||||
description: Which version of are you using? Run `npm list <package>` in your project directory and paste the output.
|
||||
description: Which version of the package are you using? Run `npm list <package>` in your project directory and paste the output.
|
||||
placeholder: We no longer support version 12 or earlier of discord.js
|
||||
validations:
|
||||
required: true
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@@ -5,7 +5,7 @@ body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
We can only implement features that Discord publishes, documents and merges into the Discord API documentation.
|
||||
We can only implement features that Discord publishes, documents, and merges into the Discord API documentation.
|
||||
We do not implement unreleased features.
|
||||
Use Discord for questions: https://discord.gg/djs
|
||||
- type: dropdown
|
||||
|
||||
13
.github/check_deploy_branch.sh
vendored
13
.github/check_deploy_branch.sh
vendored
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
git diff HEAD^ HEAD --quiet .
|
||||
|
||||
if [[ "$VERCEL_GIT_COMMIT_REF" == "main" || $? -eq 1 ]]; then
|
||||
# Proceed with the build
|
||||
echo "✅ - Proceed"
|
||||
exit 1;
|
||||
else
|
||||
# Don't build
|
||||
echo "🛑 - Build cancelled"
|
||||
exit 0;
|
||||
fi
|
||||
42
.github/labeler.yml
vendored
42
.github/labeler.yml
vendored
@@ -1,43 +1,39 @@
|
||||
chore:
|
||||
- any: ['*']
|
||||
all: ['!packages/*', '!packages/**/*']
|
||||
|
||||
'packages:builders':
|
||||
packages:builders:
|
||||
- packages/builders/*
|
||||
- packages/builders/**/*
|
||||
|
||||
'packages:collection':
|
||||
packages:collection:
|
||||
- packages/collection/*
|
||||
- packages/collection/**/*
|
||||
|
||||
'packages:discord.js':
|
||||
packages:discord.js:
|
||||
- packages/discord.js/*
|
||||
- packages/discord.js/**/*
|
||||
|
||||
'packages:docgen':
|
||||
packages:docgen:
|
||||
- packages/docgen/*
|
||||
- packages/docgen/**/*
|
||||
|
||||
'packages:proxy':
|
||||
packages:guide:
|
||||
- packages/guide/*
|
||||
- packages/guide/**/*
|
||||
packages:proxy:
|
||||
- packages/proxy/*
|
||||
- packages/proxy/**/*
|
||||
|
||||
'packages:proxy-container':
|
||||
packages:proxy-container:
|
||||
- packages/proxy-container/*
|
||||
- packages/proxy-container/**/*
|
||||
|
||||
'packages:rest':
|
||||
packages:rest:
|
||||
- packages/rest/*
|
||||
- packages/rest/**/*
|
||||
|
||||
'packages:voice':
|
||||
packages:util:
|
||||
- packages/util/*
|
||||
- packages/util/**/*
|
||||
packages:voice:
|
||||
- packages/voice/*
|
||||
- packages/voice/**/*
|
||||
|
||||
'packages:website':
|
||||
packages:website:
|
||||
- packages/website/*
|
||||
- packages/website/**/*
|
||||
|
||||
'packages:ws':
|
||||
packages/web-components:
|
||||
- packages:web-components/*
|
||||
- packages:web-components/**/*
|
||||
packages:ws:
|
||||
- packages/ws/*
|
||||
- packages/ws/**/*
|
||||
|
||||
202
.github/labels.yml
vendored
202
.github/labels.yml
vendored
@@ -1,102 +1,108 @@
|
||||
- name: 'api changes'
|
||||
- name: api changes
|
||||
color: '5663e9'
|
||||
- name: 'api support'
|
||||
- name: api support
|
||||
color: '5663e9'
|
||||
- name: 'backlog'
|
||||
color: '7ef7ef'
|
||||
- name: 'blocked'
|
||||
color: 'fc1423'
|
||||
- name: 'bug'
|
||||
color: 'd73a4a'
|
||||
- name: 'caching'
|
||||
color: '80c042'
|
||||
- name: 'chore'
|
||||
color: 'ffffff'
|
||||
- name: 'ci'
|
||||
color: '0075ca'
|
||||
- name: 'dependencies'
|
||||
color: '276bd1'
|
||||
- name: 'discussion'
|
||||
color: 'b6b1f9'
|
||||
- name: 'discord'
|
||||
- name: backlog
|
||||
color: 7ef7ef
|
||||
- name: blocked
|
||||
color: fc1423
|
||||
- name: bug
|
||||
color: d73a4a
|
||||
- name: caching
|
||||
color: 80c042
|
||||
- name: chore
|
||||
color: ffffff
|
||||
- name: ci
|
||||
color: 0075ca
|
||||
- name: dependencies
|
||||
color: 276bd1
|
||||
- name: discussion
|
||||
color: b6b1f9
|
||||
- name: discord
|
||||
color: '5663e9'
|
||||
- name: 'documentation'
|
||||
color: '0075ca'
|
||||
- name: 'duplicate'
|
||||
color: 'cfd3d7'
|
||||
- name: 'error handling'
|
||||
color: '80c042'
|
||||
- name: 'feature request'
|
||||
color: 'fcf95a'
|
||||
- name: 'gateway'
|
||||
color: '80c042'
|
||||
- name: 'good first issue'
|
||||
color: '7057ff'
|
||||
- name: 'has PR'
|
||||
color: '4b1f8e'
|
||||
- name: 'help wanted'
|
||||
- name: documentation
|
||||
color: 0075ca
|
||||
- name: duplicate
|
||||
color: cfd3d7
|
||||
- name: error handling
|
||||
color: 80c042
|
||||
- name: feature request
|
||||
color: fcf95a
|
||||
- name: gateway
|
||||
color: 80c042
|
||||
- name: good first issue
|
||||
color: 7057ff
|
||||
- name: has PR
|
||||
color: 4b1f8e
|
||||
- name: help wanted
|
||||
color: '008672'
|
||||
- name: 'interactions'
|
||||
color: '80c042'
|
||||
- name: 'in progress'
|
||||
color: 'ffccd7'
|
||||
- name: 'in review'
|
||||
color: 'aed5fc'
|
||||
- name: 'invalid'
|
||||
color: 'e4e669'
|
||||
- name: 'need repro'
|
||||
color: 'c66037'
|
||||
- name: 'packages:builders'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:collection'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:discord.js'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:docgen'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:proxy'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:proxy-container'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:rest'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:voice'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:website'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:ws'
|
||||
color: 'fbca04'
|
||||
- name: 'performance'
|
||||
color: '80c042'
|
||||
- name: 'permissions'
|
||||
color: '80c042'
|
||||
- name: 'priority:high'
|
||||
color: 'fc1423'
|
||||
- name: 'question (please use Discord instead)'
|
||||
color: 'd876e3'
|
||||
- name: 'ratelimits'
|
||||
color: '80c042'
|
||||
- name: 'refactor'
|
||||
color: '1d637f'
|
||||
- name: 'regression'
|
||||
color: 'ea8785'
|
||||
- name: 'REST'
|
||||
color: '80c042'
|
||||
- name: 'semver:major'
|
||||
color: 'c10f47'
|
||||
- name: 'semver:minor'
|
||||
color: 'e4f486'
|
||||
- name: 'semver:patch'
|
||||
color: 'e8be8b'
|
||||
- name: 'sharding'
|
||||
color: '80c042'
|
||||
- name: 'tests'
|
||||
color: 'f06dff'
|
||||
- name: 'threads'
|
||||
color: '80c042'
|
||||
- name: 'typings'
|
||||
color: '80c042'
|
||||
- name: 'utility'
|
||||
color: '80c042'
|
||||
- name: 'wontfix'
|
||||
color: 'ffffff'
|
||||
- name: interactions
|
||||
color: 80c042
|
||||
- name: in progress
|
||||
color: ffccd7
|
||||
- name: in review
|
||||
color: aed5fc
|
||||
- name: invalid
|
||||
color: e4e669
|
||||
- name: need repro
|
||||
color: c66037
|
||||
- name: packages:builders
|
||||
color: fbca04
|
||||
- name: packages:collection
|
||||
color: fbca04
|
||||
- name: packages:discord.js
|
||||
color: fbca04
|
||||
- name: packages:docgen
|
||||
color: fbca04
|
||||
- name: packages:guide
|
||||
color: fbca04
|
||||
- name: packages:proxy
|
||||
color: fbca04
|
||||
- name: packages:proxy-container
|
||||
color: fbca04
|
||||
- name: packages:rest
|
||||
color: fbca04
|
||||
- name: packages:util
|
||||
color: fbca04
|
||||
- name: packages:voice
|
||||
color: fbca04
|
||||
- name: packages:website
|
||||
color: fbca04
|
||||
- name: packages:web-components
|
||||
color: fbca04
|
||||
- name: packages:ws
|
||||
color: fbca04
|
||||
- name: performance
|
||||
color: 80c042
|
||||
- name: permissions
|
||||
color: 80c042
|
||||
- name: priority:high
|
||||
color: fc1423
|
||||
- name: question (please use Discord instead)
|
||||
color: d876e3
|
||||
- name: ratelimits
|
||||
color: 80c042
|
||||
- name: refactor
|
||||
color: 1d637f
|
||||
- name: regression
|
||||
color: ea8785
|
||||
- name: REST
|
||||
color: 80c042
|
||||
- name: semver:major
|
||||
color: c10f47
|
||||
- name: semver:minor
|
||||
color: e4f486
|
||||
- name: semver:patch
|
||||
color: e8be8b
|
||||
- name: sharding
|
||||
color: 80c042
|
||||
- name: tests
|
||||
color: f06dff
|
||||
- name: threads
|
||||
color: 80c042
|
||||
- name: typings
|
||||
color: 80c042
|
||||
- name: utility
|
||||
color: 80c042
|
||||
- name: wontfix
|
||||
color: ffffff
|
||||
|
||||
57
.github/workflows/documentation.yml
vendored
57
.github/workflows/documentation.yml
vendored
@@ -3,8 +3,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'stable'
|
||||
- '!docs'
|
||||
tags:
|
||||
- '**'
|
||||
workflow_dispatch:
|
||||
@@ -12,15 +10,24 @@ on:
|
||||
ref:
|
||||
description: 'The branch, tag or SHA to checkout'
|
||||
required: true
|
||||
ref_type:
|
||||
type: choice
|
||||
description: 'Branch or tag'
|
||||
options:
|
||||
- branch
|
||||
- tag
|
||||
required: true
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
build:
|
||||
name: Build documentation
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
outputs:
|
||||
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ steps.env.outputs.SHA }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
@@ -32,7 +39,6 @@ jobs:
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
@@ -55,13 +61,6 @@ jobs:
|
||||
name: api-extractor
|
||||
path: packages/*/docs/docs.api.json
|
||||
|
||||
- name: Set outputs for upload job
|
||||
id: env
|
||||
run: |
|
||||
echo "::set-output name=BRANCH_NAME::${GITHUB_REF_NAME}"
|
||||
echo "::set-output name=BRANCH_OR_TAG::${GITHUB_REF_TYPE}"
|
||||
echo "::set-output name=SHA::${GITHUB_SHA}"
|
||||
|
||||
upload:
|
||||
name: Upload Documentation
|
||||
needs: build
|
||||
@@ -69,12 +68,13 @@ 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 }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
BRANCH_NAME: ${{ github.event.inputs.ref || needs.build.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ needs.build.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ needs.build.outputs.SHA }}
|
||||
BRANCH_OR_TAG: ${{ github.event.inputs.ref_type || needs.build.outputs.BRANCH_OR_TAG }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
@@ -84,13 +84,12 @@ jobs:
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Build actions
|
||||
run: yarn build
|
||||
run: yarn workspace @discordjs/actions build
|
||||
|
||||
- name: Download docgen artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
@@ -112,33 +111,37 @@ jobs:
|
||||
path: 'out'
|
||||
|
||||
- name: Extract package and semver from tag
|
||||
if: ${{ github.event.inputs.ref || env.BRANCH_OR_TAG == 'tag' }}
|
||||
if: ${{ env.GITHUB_REF_TYPE == 'tag' }}
|
||||
id: extract-tag
|
||||
uses: ./packages/actions/src/formatTag
|
||||
with:
|
||||
tag: ${{ env.BRANCH_NAME }}
|
||||
tag: ${{ env.GITHUB_REF_NAME }}
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ (github.event.inputs.ref || env.BRANCH_OR_TAG == 'tag') && matrix.package == steps.extract-tag.outputs.package }}
|
||||
if: ${{ env.GITHUB_REF_TYPE == 'tag' && matrix.package == steps.extract-tag.outputs.package }}
|
||||
env:
|
||||
PACKAGE: ${{ steps.extract-tag.outputs.package }}
|
||||
SEMVER: ${{ steps.extract-tag.outputs.semver }}
|
||||
run: |
|
||||
mkdir -p out/${PACKAGE}
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${SEMVER}.json
|
||||
if [[ $PACKAGE == "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${SEMVER}.json
|
||||
fi
|
||||
if [[ $PACKAGE != "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.api.json out/${PACKAGE}/${SEMVER}.api.json
|
||||
fi
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ !github.event.inputs.ref && env.BRANCH_OR_TAG == 'branch' }}
|
||||
if: ${{ env.GITHUB_REF_TYPE == 'branch' }}
|
||||
env:
|
||||
PACKAGE: ${{ matrix.package }}
|
||||
run: |
|
||||
mkdir -p out/${PACKAGE}
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${BRANCH_NAME}.json
|
||||
if [[ $PACKAGE == "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${GITHUB_REF_NAME}.json
|
||||
fi
|
||||
if [[ $PACKAGE != "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.api.json out/${PACKAGE}/${BRANCH_NAME}.api.json
|
||||
mv docs/${PACKAGE}/docs/docs.api.json out/${PACKAGE}/${GITHUB_REF_NAME}.api.json
|
||||
fi
|
||||
|
||||
- name: Commit and push
|
||||
@@ -147,5 +150,5 @@ jobs:
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
git add .
|
||||
git commit -m "Docs build for ${BRANCH_OR_TAG} ${BRANCH_NAME}: ${SHA}" || true
|
||||
git commit -m "Docs build for ${GITHUB_REF_TYPE} ${GITHUB_REF_NAME}: ${GITHUB_SHA}" || true
|
||||
git push
|
||||
|
||||
5
.github/workflows/npm-auto-deprecate.yml
vendored
5
.github/workflows/npm-auto-deprecate.yml
vendored
@@ -1,8 +1,8 @@
|
||||
name: npm auto deprecate
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 1 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
npm-auto-deprecate:
|
||||
name: npm auto deprecate
|
||||
@@ -17,12 +17,11 @@ jobs:
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
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-docker.yml
vendored
2
.github/workflows/publish-dev-docker.yml
vendored
@@ -1,8 +1,8 @@
|
||||
name: Publish dev docker images
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
docker-publish:
|
||||
name: Docker publish
|
||||
|
||||
8
.github/workflows/publish-dev.yml
vendored
8
.github/workflows/publish-dev.yml
vendored
@@ -1,8 +1,8 @@
|
||||
name: Publish dev
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
npm-publish:
|
||||
name: npm publish
|
||||
@@ -20,11 +20,16 @@ jobs:
|
||||
folder: 'proxy'
|
||||
- package: '@discordjs/rest'
|
||||
folder: 'rest'
|
||||
- package: '@discordjs/util'
|
||||
folder: 'util'
|
||||
- package: '@discordjs/voice'
|
||||
folder: 'voice'
|
||||
- package: '@discordjs/ws'
|
||||
folder: 'ws'
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
@@ -36,7 +41,6 @@ jobs:
|
||||
node-version: 16
|
||||
registry-url: https://registry.npmjs.org/
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
16
.github/workflows/tests.yml
vendored
16
.github/workflows/tests.yml
vendored
@@ -1,9 +1,18 @@
|
||||
name: Tests
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
NEXT_PUBLIC_LOCAL_DEV: true
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
@@ -13,10 +22,9 @@ jobs:
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
run: yarn install --immutable
|
||||
|
||||
- name: Build dependencies
|
||||
run: yarn build
|
||||
@@ -28,5 +36,5 @@ jobs:
|
||||
run: yarn test
|
||||
|
||||
- name: Upload Coverage
|
||||
uses: ./packages/actions/src/uploadCoverage
|
||||
if: github.repository_owner == 'discordjs'
|
||||
uses: ./packages/actions/src/uploadCoverage
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"*": "prettier --ignore-unknown --write",
|
||||
"{src/**,__tests__/**}.{mjs,js,ts}": "eslint --ext mjs,js,ts --fix",
|
||||
"src/**.ts": "vitest related"
|
||||
"{src/**,__tests__/**}.{mjs,js,cjs,ts,tsx,astro}": "eslint --ext .mjs,.js,.cjs,.ts,.tsx,.astro --fix",
|
||||
"src/**.ts": "vitest related --run --config ./vitest.config.ts"
|
||||
}
|
||||
|
||||
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@@ -8,6 +8,7 @@
|
||||
"eamodio.gitlens",
|
||||
"christian-kohler.npm-intellisense",
|
||||
"christian-kohler.path-intellisense",
|
||||
"antfu.unocss"
|
||||
"antfu.unocss",
|
||||
"astro-build.astro-vscode"
|
||||
]
|
||||
}
|
||||
|
||||
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@@ -1,11 +1,16 @@
|
||||
{
|
||||
"eslint.workingDirectories": [{ "pattern": "./packages/*" }],
|
||||
"eslint.validate": ["javascript", "javascriptreact", "astro", "typescript", "typescriptreact"],
|
||||
"prettier.documentSelectors": ["**/*.astro"],
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll": true,
|
||||
"source.organizeImports": false
|
||||
},
|
||||
"unocss.root": "./packages/website",
|
||||
"files.associations": {
|
||||
"*.mdx": "markdown"
|
||||
},
|
||||
"unocss.root": "./packages/web-components",
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js
|
||||
index 9ab972b041cc76f8f786d6a20f3efb53c364cad6..13e056a3c0971eb18b307d91fad096a9f3b9de79 100644
|
||||
--- a/dist/rollup-plugin-typescript2.cjs.js
|
||||
+++ b/dist/rollup-plugin-typescript2.cjs.js
|
||||
@@ -29799,6 +29799,13 @@ const typescript = (options) => {
|
||||
declarations[key] = { type: result.dts, map: result.dtsmap };
|
||||
context.debug(() => `${safe.exports.blue("generated declarations")} for '${key}'`);
|
||||
}
|
||||
+ // if a user sets this compilerOption, they probably want another plugin (e.g. Babel, ESBuild) to transform their TS instead, while rpt2 just type-checks and/or outputs declarations
|
||||
+ // note that result.code is non-existent if emitDeclarationOnly per https://github.com/ezolenko/rollup-plugin-typescript2/issues/268
|
||||
+ if (parsedConfig.options.emitDeclarationOnly)
|
||||
+ {
|
||||
+ context.debug(() => `${blue("emitDeclarationOnly")} enabled, not transforming TS'`);
|
||||
+ return undefined;
|
||||
+ }
|
||||
const transformResult = { code: result.code, map: { mappings: "" } };
|
||||
if (result.map) {
|
||||
if (pluginOptions.sourceMapCallback)
|
||||
diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js
|
||||
index e43bf8f03bc6792b61d8352e04bb6466712426c2..420e8f0d0d109076bc72e9d60240077235a9ba11 100644
|
||||
--- a/dist/rollup-plugin-typescript2.es.js
|
||||
+++ b/dist/rollup-plugin-typescript2.es.js
|
||||
@@ -29770,6 +29770,13 @@ const typescript = (options) => {
|
||||
declarations[key] = { type: result.dts, map: result.dtsmap };
|
||||
context.debug(() => `${safe.exports.blue("generated declarations")} for '${key}'`);
|
||||
}
|
||||
+ // if a user sets this compilerOption, they probably want another plugin (e.g. Babel, ESBuild) to transform their TS instead, while rpt2 just type-checks and/or outputs declarations
|
||||
+ // note that result.code is non-existent if emitDeclarationOnly per https://github.com/ezolenko/rollup-plugin-typescript2/issues/268
|
||||
+ if (parsedConfig.options.emitDeclarationOnly)
|
||||
+ {
|
||||
+ context.debug(() => `${blue("emitDeclarationOnly")} enabled, not transforming TS'`);
|
||||
+ return undefined;
|
||||
+ }
|
||||
const transformResult = { code: result.code, map: { mappings: "" } };
|
||||
if (result.map) {
|
||||
if (pluginOptions.sourceMapCallback)
|
||||
338
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
338
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
File diff suppressed because one or more lines are too long
6
.yarn/plugins/@yarnpkg/plugin-version.cjs
vendored
6
.yarn/plugins/@yarnpkg/plugin-version.cjs
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
786
.yarn/releases/yarn-3.2.1.cjs
vendored
786
.yarn/releases/yarn-3.2.1.cjs
vendored
File diff suppressed because one or more lines are too long
801
.yarn/releases/yarn-3.2.4.cjs
vendored
Normal file
801
.yarn/releases/yarn-3.2.4.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -8,4 +8,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.2.1.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.2.4.cjs
|
||||
|
||||
13
README.md
13
README.md
@@ -46,19 +46,18 @@ pnpm add discord.js
|
||||
|
||||
## Example usage
|
||||
|
||||
Install all required dependencies:
|
||||
Install discord.js:
|
||||
|
||||
```sh-session
|
||||
npm install discord.js @discordjs/rest
|
||||
yarn add discord.js @discordjs/rest
|
||||
pnpm add discord.js @discordjs/rest
|
||||
npm install discord.js
|
||||
yarn add discord.js
|
||||
pnpm add discord.js
|
||||
```
|
||||
|
||||
Register a slash command against the Discord API:
|
||||
|
||||
```js
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord.js');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
|
||||
const commands = [
|
||||
{
|
||||
@@ -73,7 +72,7 @@ const rest = new REST({ version: '10' }).setToken('token');
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
|
||||
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
import { relative, resolve } from 'node:path';
|
||||
import glob from 'fast-glob';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import { defineBuildConfig, BuildEntry } from 'unbuild';
|
||||
|
||||
interface ConfigOptions {
|
||||
entries: (BuildEntry | string)[];
|
||||
minify: boolean;
|
||||
emitCJS: boolean;
|
||||
externals: string[];
|
||||
cjsBridge: boolean;
|
||||
sourcemap: boolean;
|
||||
preserveModules: boolean;
|
||||
preserveModulesRoot: string;
|
||||
declaration: boolean;
|
||||
typeCheck: boolean;
|
||||
}
|
||||
|
||||
export function createUnbuildConfig({
|
||||
entries = [{ builder: 'rollup', input: 'src/index' }],
|
||||
minify = false,
|
||||
emitCJS = true,
|
||||
cjsBridge = true,
|
||||
externals = [],
|
||||
sourcemap = true,
|
||||
preserveModules = true,
|
||||
preserveModulesRoot = 'src',
|
||||
declaration = true,
|
||||
typeCheck = false,
|
||||
}: Partial<ConfigOptions> = {}) {
|
||||
const files = glob
|
||||
.sync('**', { cwd: 'src' })
|
||||
.map((file) => [`${file.slice(0, -2)}cjs`, `${file.slice(0, -2)}mjs`])
|
||||
.flat();
|
||||
|
||||
return defineBuildConfig({
|
||||
entries,
|
||||
clean: true,
|
||||
rollup: {
|
||||
esbuild: {
|
||||
minify,
|
||||
minifyIdentifiers: false,
|
||||
},
|
||||
emitCJS,
|
||||
cjsBridge,
|
||||
json: {
|
||||
namedExports: false,
|
||||
},
|
||||
},
|
||||
|
||||
externals: [...files, ...externals],
|
||||
|
||||
hooks: {
|
||||
'rollup:options': (_, options) => {
|
||||
// @ts-expect-error: This will always be an array
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
options.output![0] = {
|
||||
// @ts-expect-error: This will always be an array
|
||||
...options.output![0],
|
||||
sourcemap,
|
||||
preserveModules,
|
||||
preserveModulesRoot,
|
||||
};
|
||||
|
||||
if (emitCJS) {
|
||||
// @ts-expect-error: This will always be an array
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
options.output![1] = {
|
||||
// @ts-expect-error: This will always be an array
|
||||
...options.output![1],
|
||||
sourcemap,
|
||||
preserveModules,
|
||||
preserveModulesRoot,
|
||||
};
|
||||
}
|
||||
|
||||
if (declaration) {
|
||||
options.plugins?.unshift(
|
||||
typescript({
|
||||
check: typeCheck,
|
||||
tsconfig: relative(__dirname, resolve(process.cwd(), 'tsconfig.json')),
|
||||
tsconfigOverride: {
|
||||
compilerOptions: {
|
||||
emitDeclarationOnly: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
41
package.json
41
package.json
@@ -4,21 +4,22 @@
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "yarn workspaces foreach --parallel --topological run build",
|
||||
"test": "yarn workspaces foreach --parallel --topological run test",
|
||||
"lint": "yarn workspaces foreach --parallel --topological run lint",
|
||||
"format": "yarn workspaces foreach --parallel --topological run format",
|
||||
"fmt": "yarn format",
|
||||
"build": "turbo run build",
|
||||
"test": "turbo run test --parallel",
|
||||
"lint": "turbo run lint --parallel",
|
||||
"format": "turbo run format --parallel",
|
||||
"fmt": "turbo run format --parallel",
|
||||
"postinstall": "is-ci || husky install",
|
||||
"docs": "yarn workspaces foreach --parallel --topological run docs",
|
||||
"update": "yarn upgrade-interactive"
|
||||
"docs": "turbo run docs --parallel",
|
||||
"update": "yarn upgrade-interactive",
|
||||
"create-package": "node packages/scripts/src/packageScript.mjs"
|
||||
},
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Antonio Roman <kyradiscord@gmail.com>"
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"keywords": [
|
||||
"discord",
|
||||
@@ -37,27 +38,19 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.0.3",
|
||||
"@commitlint/config-angular": "^17.0.3",
|
||||
"@favware/cliff-jumper": "^1.8.5",
|
||||
"@favware/npm-deprecate": "^1.0.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||
"@typescript-eslint/parser": "^5.31.0",
|
||||
"@commitlint/cli": "^17.1.2",
|
||||
"@commitlint/config-angular": "^17.1.0",
|
||||
"@favware/cliff-jumper": "^1.8.8",
|
||||
"@favware/npm-deprecate": "^1.0.5",
|
||||
"conventional-changelog-cli": "^2.2.2",
|
||||
"eslint": "^8.20.0",
|
||||
"eslint-config-marine": "^9.4.1",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-import-resolver-typescript": "^3.3.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"fast-glob": "^3.2.11",
|
||||
"husky": "^8.0.1",
|
||||
"is-ci": "^3.0.1",
|
||||
"lint-staged": "^13.0.3",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^4.7.4"
|
||||
"tsup": "^6.2.3",
|
||||
"turbo": "^1.5.5",
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"resolutions": {
|
||||
"rollup-plugin-typescript2@0.32.1": "patch:rollup-plugin-typescript2@npm:0.32.1#.yarn/patches/rollup-plugin-typescript2-npm-0.32.1-b5887420f2.patch",
|
||||
"@microsoft/tsdoc-config": "patch:@microsoft/tsdoc-config@npm:0.16.1#.yarn/patches/@microsoft-tsdoc-config-npm-0.16.1-81031b1bbf.patch"
|
||||
},
|
||||
"engines": {
|
||||
@@ -66,5 +59,5 @@
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"packageManager": "yarn@3.2.1"
|
||||
"packageManager": "yarn@3.2.4"
|
||||
}
|
||||
|
||||
@@ -5,5 +5,4 @@ dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
tsup.config.*.mjs
|
||||
coverage/
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { formatTag } from '../src';
|
||||
import { formatTag } from '../src/index.js';
|
||||
|
||||
describe('Format Tag', () => {
|
||||
test('GIVEN tag with a prefix THEN format tag to not contain the prefix', () => {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { createUnbuildConfig } from '../../build.config';
|
||||
|
||||
export default createUnbuildConfig({ minify: true });
|
||||
@@ -5,19 +5,13 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "unbuild",
|
||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
||||
"build": "tsup",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix",
|
||||
"fmt": "yarn format"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
@@ -45,19 +39,19 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.0",
|
||||
"@actions/core": "^1.10.0",
|
||||
"tslib": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.45",
|
||||
"c8": "^7.12.0",
|
||||
"eslint": "^8.20.0",
|
||||
"@types/node": "^16.11.64",
|
||||
"@vitest/coverage-c8": "^0.24.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-neon": "^0.1.35",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup-plugin-typescript2": "0.32.1",
|
||||
"tsup": "^6.2.0",
|
||||
"typescript": "^4.7.4",
|
||||
"unbuild": "^0.7.6",
|
||||
"vitest": "^0.19.1"
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.4",
|
||||
"vitest": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
|
||||
@@ -11,4 +11,4 @@ outputs:
|
||||
description: 'The semver string that was extracted from this tag'
|
||||
runs:
|
||||
using: node16
|
||||
main: ../../dist/formatTag/index.js
|
||||
main: ../../dist/formatTag/index.mjs
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export function formatTag(tag: string) {
|
||||
// eslint-disable-next-line unicorn/no-unsafe-regex, prefer-named-capture-group
|
||||
const parsed = /(^@.*\/(?<package>.*)@v?)?(?<semver>\d+.\d+.\d+)-?.*/.exec(tag);
|
||||
|
||||
if (parsed?.groups) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getInput, setOutput } from '@actions/core';
|
||||
import { formatTag } from './formatTag';
|
||||
import { formatTag } from './formatTag.js';
|
||||
|
||||
const tag = getInput('tag', { required: true });
|
||||
const parsed = formatTag(tag);
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './formatTag/formatTag';
|
||||
export * from './formatTag/formatTag.js';
|
||||
|
||||
@@ -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:
|
||||
|
||||
7
packages/actions/tsup.config.js
Normal file
7
packages/actions/tsup.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig({
|
||||
entry: ['src/index.ts', 'src/formatTag/index.ts'],
|
||||
format: ['esm'],
|
||||
minify: true,
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
import { createTsupConfig } from '../../tsup.config';
|
||||
|
||||
export default createTsupConfig({
|
||||
entry: ['src/index.ts', 'src/formatTag/index.ts'],
|
||||
format: ['cjs'],
|
||||
skipNodeModulesBundle: false,
|
||||
noExternal: ['@actions/core'],
|
||||
minify: true,
|
||||
});
|
||||
3
packages/api-extractor-utils/.eslintrc.json
Normal file
3
packages/api-extractor-utils/.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
27
packages/api-extractor-utils/.gitignore
vendored
Normal file
27
packages/api-extractor-utils/.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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/
|
||||
tsconfig.tsbuildinfo
|
||||
8
packages/api-extractor-utils/.prettierignore
Normal file
8
packages/api-extractor-utils/.prettierignore
Normal file
@@ -0,0 +1,8 @@
|
||||
# Autogenerated
|
||||
CHANGELOG.md
|
||||
.turbo
|
||||
dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
190
packages/api-extractor-utils/LICENSE
Normal file
190
packages/api-extractor-utils/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/api-extractor-utils/README.md
Normal file
34
packages/api-extractor-utils/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).
|
||||
52
packages/api-extractor-utils/package.json
Normal file
52
packages/api-extractor-utils/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@discordjs/api-extractor-utils",
|
||||
"version": "1.0.0",
|
||||
"description": "Utilities for api-extractor",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"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"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "src"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Suneet Tipirneni <suneettipirneni@icloud.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@microsoft/api-extractor-model": "7.24.0",
|
||||
"@microsoft/tsdoc": "0.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.64",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-neon": "^0.1.35",
|
||||
"prettier": "^2.7.1",
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
416
packages/api-extractor-utils/src/ApiNodeJSONEncoder.ts
Normal file
416
packages/api-extractor-utils/src/ApiNodeJSONEncoder.ts
Normal file
@@ -0,0 +1,416 @@
|
||||
import type { ApiReturnTypeMixin } from '@microsoft/api-extractor-model';
|
||||
import {
|
||||
type ApiModel,
|
||||
ApiDeclaredItem,
|
||||
type ApiPropertyItem,
|
||||
type ApiMethod,
|
||||
type ApiParameterListMixin,
|
||||
type ApiTypeParameterListMixin,
|
||||
type ApiClass,
|
||||
type ApiFunction,
|
||||
ApiItemKind,
|
||||
type ApiTypeAlias,
|
||||
type ApiEnum,
|
||||
type ApiInterface,
|
||||
type ApiMethodSignature,
|
||||
type ApiPropertySignature,
|
||||
type ApiVariable,
|
||||
type ApiItem,
|
||||
type ApiConstructor,
|
||||
type ApiItemContainerMixin,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import { generateTypeParamData } from './TypeParameterJSONEncoder.js';
|
||||
import { type TokenDocumentation, resolveName, genReference, genToken, genParameter, generatePath } from './parse.js';
|
||||
import type { DocBlockJSON } from './tsdoc/CommentBlock.js';
|
||||
import type { AnyDocNodeJSON } from './tsdoc/CommentNode.js';
|
||||
import { type DocNodeContainerJSON, nodeContainer } from './tsdoc/CommentNodeContainer.js';
|
||||
import { createCommentNode } from './tsdoc/index.js';
|
||||
|
||||
export interface ReferenceData {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface InheritanceData {
|
||||
parentKey: string;
|
||||
parentName: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface ApiInheritableJSON {
|
||||
inheritanceData: InheritanceData | null;
|
||||
}
|
||||
|
||||
export interface ApiItemJSON {
|
||||
comment: AnyDocNodeJSON | null;
|
||||
containerKey: string;
|
||||
deprecated: DocNodeContainerJSON | null;
|
||||
excerpt: string;
|
||||
excerptTokens: TokenDocumentation[];
|
||||
kind: string;
|
||||
name: string;
|
||||
path: string[];
|
||||
referenceData: ReferenceData;
|
||||
remarks: DocNodeContainerJSON | null;
|
||||
summary: DocNodeContainerJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiPropertyItemJSON extends ApiItemJSON, ApiInheritableJSON {
|
||||
optional: boolean;
|
||||
propertyTypeTokens: TokenDocumentation[];
|
||||
readonly: boolean;
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterListJSON {
|
||||
typeParameters: ApiTypeParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterJSON {
|
||||
commentBlock: DocBlockJSON | null;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export interface ApiParameterListJSON {
|
||||
parameters: ApiParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiMethodSignatureJSON
|
||||
extends ApiItemJSON,
|
||||
ApiTypeParameterListJSON,
|
||||
ApiParameterListJSON,
|
||||
ApiInheritableJSON {
|
||||
mergedSiblings: ApiMethodSignatureJSON[];
|
||||
optional: boolean;
|
||||
overloadIndex: number;
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiMethodJSON extends ApiMethodSignatureJSON {
|
||||
mergedSiblings: ApiMethodJSON[];
|
||||
protected: boolean;
|
||||
static: boolean;
|
||||
}
|
||||
|
||||
export interface ApiParameterJSON {
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
paramCommentBlock: DocBlockJSON | null;
|
||||
tokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiClassJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
constructor: ApiConstructorJSON | null;
|
||||
extendsTokens: TokenDocumentation[];
|
||||
implementsTokens: TokenDocumentation[][];
|
||||
methods: ApiMethodJSON[];
|
||||
properties: ApiPropertyItemJSON[];
|
||||
}
|
||||
|
||||
export interface ApiTypeAliasJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
typeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface EnumMemberData {
|
||||
initializerTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
summary: DocNodeContainerJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiEnumJSON extends ApiItemJSON {
|
||||
members: EnumMemberData[];
|
||||
}
|
||||
|
||||
export interface ApiInterfaceJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
extendsTokens: TokenDocumentation[][] | null;
|
||||
methods: ApiMethodSignatureJSON[];
|
||||
properties: ApiPropertyItemJSON[];
|
||||
}
|
||||
|
||||
export interface ApiVariableJSON extends ApiItemJSON {
|
||||
readonly: boolean;
|
||||
typeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiFunctionJSON extends ApiItemJSON, ApiTypeParameterListJSON, ApiParameterListJSON {
|
||||
mergedSiblings: ApiFunctionJSON[];
|
||||
overloadIndex: number;
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiConstructorJSON extends ApiItemJSON, ApiParameterListJSON {
|
||||
protected: boolean;
|
||||
}
|
||||
|
||||
export type FunctionLike = ApiDeclaredItem & ApiParameterListMixin & ApiReturnTypeMixin & ApiTypeParameterListMixin;
|
||||
|
||||
export class ApiNodeJSONEncoder {
|
||||
public static encode(model: ApiModel, node: ApiItem, version: string) {
|
||||
if (!(node instanceof ApiDeclaredItem)) {
|
||||
console.log(`Cannot serialize node of type ${node.kind}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case ApiItemKind.Class:
|
||||
return this.encodeClass(model, node as ApiClass, version);
|
||||
case ApiItemKind.Function:
|
||||
return this.encodeFunction(model, node as ApiFunction, version);
|
||||
case ApiItemKind.Interface:
|
||||
return this.encodeInterface(model, node as ApiInterface, version);
|
||||
case ApiItemKind.TypeAlias:
|
||||
return this.encodeTypeAlias(model, node as ApiTypeAlias, version);
|
||||
case ApiItemKind.Enum:
|
||||
return this.encodeEnum(model, node as ApiEnum, version);
|
||||
case ApiItemKind.Variable:
|
||||
return this.encodeVariable(model, node as ApiVariable, version);
|
||||
default:
|
||||
// console.log(`Unknown API item kind: ${node.kind}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public static encodeItem(model: ApiModel, item: ApiDeclaredItem, version: string): ApiItemJSON {
|
||||
const path = [];
|
||||
for (const _item of item.getHierarchy()) {
|
||||
switch (_item.kind) {
|
||||
case 'None':
|
||||
case 'EntryPoint':
|
||||
case 'Model':
|
||||
break;
|
||||
default:
|
||||
path.push(resolveName(_item));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: item.kind,
|
||||
name: resolveName(item),
|
||||
referenceData: genReference(item, version),
|
||||
excerpt: item.excerpt.text,
|
||||
excerptTokens: item.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
remarks: item.tsdocComment?.remarksBlock
|
||||
? (createCommentNode(item.tsdocComment.remarksBlock, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
summary: item.tsdocComment?.summarySection
|
||||
? (createCommentNode(item.tsdocComment.summarySection, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
deprecated: item.tsdocComment?.deprecatedBlock
|
||||
? (createCommentNode(item.tsdocComment.deprecatedBlock, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
path,
|
||||
containerKey: item.containerKey,
|
||||
comment: item.tsdocComment ? createCommentNode(item.tsdocComment, model, version, item.parent) : null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeParameterList(
|
||||
model: ApiModel,
|
||||
item: ApiDeclaredItem & ApiParameterListMixin,
|
||||
version: string,
|
||||
): { parameters: ApiParameterJSON[] } {
|
||||
return {
|
||||
parameters: item.parameters.map((param) => genParameter(model, param, version)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeParameterList(
|
||||
model: ApiModel,
|
||||
item: ApiDeclaredItem & ApiTypeParameterListMixin,
|
||||
version: string,
|
||||
): ApiTypeParameterListJSON {
|
||||
return {
|
||||
typeParameters: item.typeParameters.map((param) => generateTypeParamData(model, param, version, item.parent)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeProperty(
|
||||
model: ApiModel,
|
||||
item: ApiPropertyItem,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
): ApiPropertyItemJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeInheritanceData(item, parent, version),
|
||||
propertyTypeTokens: item.propertyTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
readonly: item.isReadonly,
|
||||
optional: item.isOptional,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInheritanceData(
|
||||
item: ApiDeclaredItem,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
): ApiInheritableJSON {
|
||||
return {
|
||||
inheritanceData:
|
||||
item.parent && item.parent.containerKey !== parent.containerKey
|
||||
? {
|
||||
parentKey: item.parent.containerKey,
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy(), version),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeFunctionLike(model: ApiModel, item: FunctionLike, version: string) {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeParameterList(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
returnTypeTokens: item.returnTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
overloadIndex: item.overloadIndex,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeFunction(model: ApiModel, item: FunctionLike, version: string, nested = false): ApiFunctionJSON {
|
||||
return {
|
||||
...this.encodeFunctionLike(model, item, version),
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item.getMergedSiblings().map((item) => this.encodeFunction(model, item as ApiFunction, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethodSignature(
|
||||
model: ApiModel,
|
||||
item: ApiMethodSignature,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
nested = false,
|
||||
): ApiMethodSignatureJSON {
|
||||
return {
|
||||
...this.encodeFunctionLike(model, item, version),
|
||||
...this.encodeInheritanceData(item, parent, version),
|
||||
optional: item.isOptional,
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item
|
||||
.getMergedSiblings()
|
||||
.map((item) => this.encodeMethodSignature(model, item as ApiMethodSignature, parent, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethod(
|
||||
model: ApiModel,
|
||||
item: ApiMethod,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
nested = false,
|
||||
): ApiMethodJSON {
|
||||
return {
|
||||
...this.encodeMethodSignature(model, item, parent, version),
|
||||
static: item.isStatic,
|
||||
protected: item.isProtected,
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item.getMergedSiblings().map((item) => this.encodeMethod(model, item as ApiMethod, parent, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeClass(model: ApiModel, item: ApiClass, version: string): ApiClassJSON {
|
||||
const extendsExcerpt = item.extendsType?.excerpt;
|
||||
|
||||
const methods: ApiMethodJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
let constructor: ApiConstructor | undefined;
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Method:
|
||||
methods.push(this.encodeMethod(model, member as ApiMethod, item, version));
|
||||
break;
|
||||
case ApiItemKind.Property:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertyItem, item, version));
|
||||
break;
|
||||
case ApiItemKind.Constructor:
|
||||
constructor = member as ApiConstructor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
constructor: constructor ? this.encodeConstructor(model, constructor, version) : null,
|
||||
extendsTokens: extendsExcerpt ? extendsExcerpt.spannedTokens.map((token) => genToken(model, token, version)) : [],
|
||||
implementsTokens: item.implementsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeAlias(model: ApiModel, item: ApiTypeAlias, version: string): ApiTypeAliasJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
typeTokens: item.typeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeEnum(model: ApiModel, item: ApiEnum, version: string): ApiEnumJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
members: item.members.map((member) => ({
|
||||
name: member.name,
|
||||
initializerTokens:
|
||||
member.initializerExcerpt?.spannedTokens.map((token) => genToken(model, token, version)) ?? [],
|
||||
summary: member.tsdocComment ? nodeContainer(member.tsdocComment.summarySection, model, version, member) : null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInterface(model: ApiModel, item: ApiInterface, version: string): ApiInterfaceJSON {
|
||||
const methods: ApiMethodSignatureJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.MethodSignature:
|
||||
methods.push(this.encodeMethodSignature(model, member as ApiMethodSignature, item, version));
|
||||
break;
|
||||
case ApiItemKind.PropertySignature:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertySignature, item, version));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
extendsTokens: item.extendsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeVariable(model: ApiModel, item: ApiVariable, version: string): ApiVariableJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
typeTokens: item.variableTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
readonly: item.isReadonly,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeConstructor(model: ApiModel, item: ApiConstructor, version: string): ApiConstructorJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeParameterList(model, item, version),
|
||||
protected: item.isProtected,
|
||||
};
|
||||
}
|
||||
}
|
||||
31
packages/api-extractor-utils/src/TypeParameterJSONEncoder.ts
Normal file
31
packages/api-extractor-utils/src/TypeParameterJSONEncoder.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { TypeParameter, ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import { type TokenDocumentation, genToken } from './parse.js';
|
||||
import { type DocBlockJSON, block } from './tsdoc/CommentBlock.js';
|
||||
|
||||
export interface TypeParameterData {
|
||||
commentBlock: DocBlockJSON | null;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export function generateTypeParamData(
|
||||
model: ApiModel,
|
||||
typeParam: TypeParameter,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): TypeParameterData {
|
||||
const constraintTokens = typeParam.constraintExcerpt.spannedTokens.map((token) => genToken(model, token, version));
|
||||
const defaultTokens = typeParam.defaultTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version));
|
||||
|
||||
return {
|
||||
name: typeParam.name,
|
||||
constraintTokens,
|
||||
defaultTokens,
|
||||
optional: typeParam.isOptional,
|
||||
commentBlock: typeParam.tsdocTypeParamBlock
|
||||
? block(typeParam.tsdocTypeParamBlock, model, version, parentItem)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
4
packages/api-extractor-utils/src/index.ts
Normal file
4
packages/api-extractor-utils/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './ApiNodeJSONEncoder.js';
|
||||
export * from './parse.js';
|
||||
export * from './tsdoc/index.js';
|
||||
export * from './TypeParameterJSONEncoder.js';
|
||||
@@ -10,10 +10,12 @@ import {
|
||||
type ApiPropertyItem,
|
||||
type ExcerptToken,
|
||||
type Parameter,
|
||||
type TypeParameter,
|
||||
type ApiFunction,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import type { DocNode, DocParagraph, DocPlainText } from '@microsoft/tsdoc';
|
||||
import { Meaning, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import { type Meaning, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import type { DocBlockJSON } from './tsdoc/CommentBlock.js';
|
||||
import { createCommentNode } from './tsdoc/index.js';
|
||||
|
||||
export function findPackage(model: ApiModel, name: string): ApiPackage | undefined {
|
||||
return (model.findMembersByName(name)[0] ?? model.findMembersByName(`@discordjs/${name}`)[0]) as
|
||||
@@ -21,8 +23,9 @@ export function findPackage(model: ApiModel, name: string): ApiPackage | undefin
|
||||
| undefined;
|
||||
}
|
||||
|
||||
function generatePath(items: readonly ApiItem[]) {
|
||||
let path = '/docs/main/packages/';
|
||||
export function generatePath(items: readonly ApiItem[], version: string) {
|
||||
let path = '/docs/packages';
|
||||
|
||||
for (const item of items) {
|
||||
switch (item.kind) {
|
||||
case ApiItemKind.Model:
|
||||
@@ -30,14 +33,29 @@ function generatePath(items: readonly ApiItem[]) {
|
||||
case ApiItemKind.EnumMember:
|
||||
break;
|
||||
case ApiItemKind.Package:
|
||||
path += `${item.displayName}/`;
|
||||
path += `/${item.displayName}`;
|
||||
break;
|
||||
case ApiItemKind.Function:
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const functionItem = item as ApiFunction;
|
||||
path += `/${functionItem.displayName}${
|
||||
functionItem.overloadIndex && functionItem.overloadIndex > 1 ? `:${functionItem.overloadIndex}` : ''
|
||||
}:${item.kind}`;
|
||||
break;
|
||||
case ApiItemKind.Property:
|
||||
case ApiItemKind.Method:
|
||||
case ApiItemKind.MethodSignature:
|
||||
case ApiItemKind.PropertySignature:
|
||||
// TODO: Take overloads into account
|
||||
path += `#${item.displayName}`;
|
||||
break;
|
||||
default:
|
||||
path += `${item.displayName}/`;
|
||||
path += `/${item.displayName}:${item.kind}`;
|
||||
}
|
||||
}
|
||||
|
||||
return path.replace(/@discordjs\//, '');
|
||||
// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex
|
||||
return path.replace(/@discordjs\/(.*)\/(.*)?/, `$1/${version}/$2`);
|
||||
}
|
||||
|
||||
export function resolveDocComment(item: ApiDocumentedItem) {
|
||||
@@ -53,26 +71,22 @@ export function resolveDocComment(item: ApiDocumentedItem) {
|
||||
|
||||
const { summarySection } = tsdocComment;
|
||||
|
||||
function recurseNodes(nodes: readonly DocNode[] | undefined): string | null {
|
||||
if (!nodes) {
|
||||
function recurseNodes(node: DocNode | undefined): string | null {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const node of nodes) {
|
||||
switch (node.kind) {
|
||||
case 'Paragraph':
|
||||
return recurseNodes((node as DocParagraph).nodes);
|
||||
case 'PlainText':
|
||||
return (node as DocPlainText).text;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case 'Paragraph':
|
||||
return recurseNodes(node as DocParagraph);
|
||||
case 'PlainText':
|
||||
return (node as DocPlainText).text;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return recurseNodes(summarySection.nodes);
|
||||
return recurseNodes(summarySection);
|
||||
}
|
||||
|
||||
export function findReferences(model: ApiModel, excerpt: Excerpt) {
|
||||
@@ -90,6 +104,7 @@ export function findReferences(model: ApiModel, excerpt: Excerpt) {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -125,14 +140,15 @@ export function getProperties(item: ApiItem) {
|
||||
}
|
||||
|
||||
export interface TokenDocumentation {
|
||||
text: string;
|
||||
path: string | null;
|
||||
kind: string;
|
||||
path: string | null;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface ParameterDocumentation {
|
||||
name: string;
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
paramCommentBlock: DocBlockJSON | null;
|
||||
tokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
@@ -147,16 +163,16 @@ function createDapiTypesURL(meaning: Meaning, name: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function genReference(item: ApiItem) {
|
||||
export function genReference(item: ApiItem, version: string) {
|
||||
return {
|
||||
name: resolveName(item),
|
||||
path: generatePath(item.getHierarchy()),
|
||||
path: generatePath(item.getHierarchy(), version),
|
||||
};
|
||||
}
|
||||
|
||||
export function genToken(model: ApiModel, token: ExcerptToken) {
|
||||
export function genToken(model: ApiModel, token: ExcerptToken, version: string) {
|
||||
if (token.canonicalReference) {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Symbol is not publicly accessible
|
||||
token.canonicalReference._navigation = '.';
|
||||
}
|
||||
|
||||
@@ -180,41 +196,27 @@ export function genToken(model: ApiModel, token: ExcerptToken) {
|
||||
return {
|
||||
kind: token.kind,
|
||||
text: token.text,
|
||||
path: item ? generatePath(item.getHierarchy()) : null,
|
||||
path: item ? generatePath(item.getHierarchy(), version) : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function genParameter(model: ApiModel, param: Parameter): ParameterDocumentation {
|
||||
export function genParameter(model: ApiModel, param: Parameter, version: string): ParameterDocumentation {
|
||||
return {
|
||||
name: param.name,
|
||||
isOptional: param.isOptional,
|
||||
tokens: param.parameterTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
tokens: param.parameterTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
paramCommentBlock: param.tsdocParamBlock
|
||||
? (createCommentNode(param.tsdocParamBlock, model, version) as DocBlockJSON)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function getMembers(pkg: ApiPackage) {
|
||||
export function getMembers(pkg: ApiPackage, version: string) {
|
||||
return pkg.members[0]!.members.map((member) => ({
|
||||
name: member.displayName,
|
||||
kind: member.kind,
|
||||
path: generatePath(member.getHierarchy()),
|
||||
kind: member.kind as string,
|
||||
path: generatePath(member.getHierarchy(), version),
|
||||
containerKey: member.containerKey,
|
||||
overloadIndex: member.kind === 'Function' ? (member as ApiFunction).overloadIndex : null,
|
||||
}));
|
||||
}
|
||||
|
||||
export interface TypeParameterData {
|
||||
name: string;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export function generateTypeParamData(model: ApiModel, typeParam: TypeParameter): TypeParameterData {
|
||||
const constraintTokens = typeParam.constraintExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
const defaultTokens = typeParam.defaultTypeExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
|
||||
return {
|
||||
name: typeParam.name,
|
||||
constraintTokens,
|
||||
defaultTokens,
|
||||
optional: typeParam.isOptional,
|
||||
};
|
||||
}
|
||||
18
packages/api-extractor-utils/src/tsdoc/CommentBlock.ts
Normal file
18
packages/api-extractor-utils/src/tsdoc/CommentBlock.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import type { DocBlock } from '@microsoft/tsdoc';
|
||||
import { blockTag, type DocBlockTagJSON } from './CommentBlockTag.js';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocBlockJSON extends DocNodeJSON {
|
||||
content: AnyDocNodeJSON[];
|
||||
tag: DocBlockTagJSON;
|
||||
}
|
||||
|
||||
export function block(block: DocBlock, model: ApiModel, version: string, parentItem?: ApiItem) {
|
||||
return {
|
||||
...node(block),
|
||||
content: block.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
tag: blockTag(block.blockTag),
|
||||
};
|
||||
}
|
||||
13
packages/api-extractor-utils/src/tsdoc/CommentBlockTag.ts
Normal file
13
packages/api-extractor-utils/src/tsdoc/CommentBlockTag.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { DocBlockTag } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocBlockTagJSON extends DocNodeJSON {
|
||||
tagName: string;
|
||||
}
|
||||
|
||||
export function blockTag(blockTag: DocBlockTag): DocBlockTagJSON {
|
||||
return {
|
||||
...node(blockTag),
|
||||
tagName: blockTag.tagName,
|
||||
};
|
||||
}
|
||||
13
packages/api-extractor-utils/src/tsdoc/CommentCodeSpan.ts
Normal file
13
packages/api-extractor-utils/src/tsdoc/CommentCodeSpan.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { DocCodeSpan } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocCodeSpanJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export function codeSpan(codeSpan: DocCodeSpan): DocCodeSpanJSON {
|
||||
return {
|
||||
...node(codeSpan),
|
||||
code: codeSpan.code,
|
||||
};
|
||||
}
|
||||
28
packages/api-extractor-utils/src/tsdoc/CommentNode.ts
Normal file
28
packages/api-extractor-utils/src/tsdoc/CommentNode.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { DocNode, DocNodeKind } from '@microsoft/tsdoc';
|
||||
import type { DocBlockJSON } from './CommentBlock.js';
|
||||
import type { DocCodeSpanJSON } from './CommentCodeSpan.js';
|
||||
import type { DocNodeContainerJSON } from './CommentNodeContainer.js';
|
||||
import type { DocFencedCodeJSON } from './FencedCodeCommentNode.js';
|
||||
import type { DocLinkTagJSON } from './LinkTagCommentNode.js';
|
||||
import type { DocPlainTextJSON } from './PlainTextCommentNode.js';
|
||||
import type { DocCommentJSON } from './RootComment.js';
|
||||
|
||||
export interface DocNodeJSON {
|
||||
kind: DocNodeKind;
|
||||
}
|
||||
|
||||
export type AnyDocNodeJSON =
|
||||
| DocBlockJSON
|
||||
| DocCodeSpanJSON
|
||||
| DocCommentJSON
|
||||
| DocFencedCodeJSON
|
||||
| DocLinkTagJSON
|
||||
| DocNodeContainerJSON
|
||||
| DocNodeJSON
|
||||
| DocPlainTextJSON;
|
||||
|
||||
export function node(node: DocNode): DocNodeJSON {
|
||||
return {
|
||||
kind: node.kind as DocNodeKind,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocNodeContainer } from '@microsoft/tsdoc';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocNodeContainerJSON extends DocNodeJSON {
|
||||
nodes: AnyDocNodeJSON[];
|
||||
}
|
||||
|
||||
export function nodeContainer(
|
||||
container: DocNodeContainer,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocNodeContainerJSON {
|
||||
return {
|
||||
...node(container),
|
||||
nodes: container.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { DocFencedCode } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocFencedCodeJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
language: string;
|
||||
}
|
||||
|
||||
export function fencedCode(fencedCode: DocFencedCode) {
|
||||
return {
|
||||
...node(fencedCode),
|
||||
language: fencedCode.language,
|
||||
code: fencedCode.code,
|
||||
};
|
||||
}
|
||||
60
packages/api-extractor-utils/src/tsdoc/LinkTagCommentNode.ts
Normal file
60
packages/api-extractor-utils/src/tsdoc/LinkTagCommentNode.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocDeclarationReference, DocLinkTag } from '@microsoft/tsdoc';
|
||||
import { resolveName, generatePath } from '../parse.js';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
interface LinkTagCodeLink {
|
||||
kind: string;
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface DocLinkTagJSON extends DocNodeJSON {
|
||||
codeDestination: LinkTagCodeLink | null;
|
||||
text: string | null;
|
||||
urlDestination: string | null;
|
||||
}
|
||||
|
||||
export function genLinkToken(
|
||||
model: ApiModel,
|
||||
ref: DocDeclarationReference,
|
||||
context: ApiItem | null,
|
||||
version: string,
|
||||
): LinkTagCodeLink | null {
|
||||
const item = model.resolveDeclarationReference(ref, context ?? undefined).resolvedApiItem ?? null;
|
||||
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
name: resolveName(item),
|
||||
kind: item.kind,
|
||||
path: generatePath(item.getHierarchy(), version),
|
||||
};
|
||||
}
|
||||
|
||||
export function linkTagNode(
|
||||
linkNode: DocLinkTag,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocLinkTagJSON {
|
||||
// If we weren't provided a parent object, fallback to the package entrypoint.
|
||||
const packageEntryPoint = linkNode.codeDestination?.importPath
|
||||
? model.getAssociatedPackage()?.findEntryPointsByPath(linkNode.codeDestination.importPath)[0]
|
||||
: null;
|
||||
|
||||
const codeDestination = linkNode.codeDestination
|
||||
? genLinkToken(model, linkNode.codeDestination, parentItem ?? packageEntryPoint ?? null, version)
|
||||
: null;
|
||||
const text = linkNode.linkText ?? null;
|
||||
const urlDestination = linkNode.urlDestination ?? null;
|
||||
|
||||
return {
|
||||
...node(linkNode),
|
||||
text,
|
||||
codeDestination,
|
||||
urlDestination,
|
||||
};
|
||||
}
|
||||
19
packages/api-extractor-utils/src/tsdoc/ParamBlock.ts
Normal file
19
packages/api-extractor-utils/src/tsdoc/ParamBlock.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocParamBlock } from '@microsoft/tsdoc';
|
||||
import { block, type DocBlockJSON } from './CommentBlock.js';
|
||||
|
||||
interface DocParamBlockJSON extends DocBlockJSON {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function paramBlock(
|
||||
paramBlock: DocParamBlock,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocParamBlockJSON {
|
||||
return {
|
||||
...block(paramBlock, model, version, parentItem),
|
||||
name: paramBlock.parameterName,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { DocPlainText } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocPlainTextJSON extends DocNodeJSON {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export function plainTextNode(plainTextNode: DocPlainText): DocPlainTextJSON {
|
||||
return {
|
||||
...node(plainTextNode),
|
||||
text: plainTextNode.text,
|
||||
};
|
||||
}
|
||||
24
packages/api-extractor-utils/src/tsdoc/RootComment.ts
Normal file
24
packages/api-extractor-utils/src/tsdoc/RootComment.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocComment } from '@microsoft/tsdoc';
|
||||
import { block, type DocBlockJSON } from './CommentBlock.js';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocCommentJSON extends DocNodeJSON {
|
||||
customBlocks: DocBlockJSON[];
|
||||
deprecated: DocNodeJSON[];
|
||||
remarks: DocNodeJSON[];
|
||||
summary: DocNodeJSON[];
|
||||
}
|
||||
|
||||
export function comment(comment: DocComment, model: ApiModel, version: string, parentItem?: ApiItem): DocCommentJSON {
|
||||
return {
|
||||
...node(comment),
|
||||
summary: comment.summarySection.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
remarks:
|
||||
comment.remarksBlock?.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)) ?? [],
|
||||
deprecated:
|
||||
comment.deprecatedBlock?.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)) ?? [],
|
||||
customBlocks: comment.customBlocks.map((_block) => block(_block, model, version, parentItem)),
|
||||
};
|
||||
}
|
||||
62
packages/api-extractor-utils/src/tsdoc/index.ts
Normal file
62
packages/api-extractor-utils/src/tsdoc/index.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import {
|
||||
type DocNode,
|
||||
type DocPlainText,
|
||||
type DocLinkTag,
|
||||
type DocParagraph,
|
||||
type DocFencedCode,
|
||||
DocNodeKind,
|
||||
type DocBlock,
|
||||
type DocComment,
|
||||
type DocCodeSpan,
|
||||
type DocParamBlock,
|
||||
} from '@microsoft/tsdoc';
|
||||
import { block } from './CommentBlock.js';
|
||||
import { codeSpan } from './CommentCodeSpan.js';
|
||||
import { node as _node, type AnyDocNodeJSON } from './CommentNode.js';
|
||||
import { nodeContainer } from './CommentNodeContainer.js';
|
||||
import { fencedCode } from './FencedCodeCommentNode.js';
|
||||
import { linkTagNode } from './LinkTagCommentNode.js';
|
||||
import { paramBlock } from './ParamBlock.js';
|
||||
import { plainTextNode } from './PlainTextCommentNode.js';
|
||||
import { comment } from './RootComment.js';
|
||||
|
||||
export function createCommentNode(
|
||||
node: DocNode,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): AnyDocNodeJSON {
|
||||
switch (node.kind) {
|
||||
case DocNodeKind.PlainText:
|
||||
return plainTextNode(node as DocPlainText);
|
||||
case DocNodeKind.LinkTag:
|
||||
return linkTagNode(node as DocLinkTag, model, version, parentItem);
|
||||
case DocNodeKind.Paragraph:
|
||||
case DocNodeKind.Section:
|
||||
return nodeContainer(node as DocParagraph, model, version, parentItem);
|
||||
case DocNodeKind.FencedCode:
|
||||
return fencedCode(node as DocFencedCode);
|
||||
case DocNodeKind.CodeSpan:
|
||||
return codeSpan(node as DocCodeSpan);
|
||||
case DocNodeKind.Block:
|
||||
return block(node as DocBlock, model, version, parentItem);
|
||||
case DocNodeKind.ParamBlock:
|
||||
return paramBlock(node as DocParamBlock, model, version, parentItem);
|
||||
case DocNodeKind.Comment:
|
||||
return comment(node as DocComment, model, version, parentItem);
|
||||
default:
|
||||
return _node(node);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './CommentNode.js';
|
||||
export * from './CommentNodeContainer.js';
|
||||
export * from './CommentBlock.js';
|
||||
export * from './CommentBlockTag.js';
|
||||
export * from './CommentCodeSpan.js';
|
||||
export * from './FencedCodeCommentNode.js';
|
||||
export * from './LinkTagCommentNode.js';
|
||||
export * from './ParamBlock.js';
|
||||
export * from './PlainTextCommentNode.js';
|
||||
export * from './RootComment.js';
|
||||
20
packages/api-extractor-utils/tsconfig.eslint.json
Normal file
20
packages/api-extractor-utils/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": []
|
||||
}
|
||||
8
packages/api-extractor-utils/tsconfig.json
Normal file
8
packages/api-extractor-utils/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"skipDefaultLibCheck": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
5
packages/api-extractor-utils/tsup.config.js
Normal file
5
packages/api-extractor-utils/tsup.config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig({
|
||||
minify: true,
|
||||
});
|
||||
@@ -5,5 +5,4 @@ dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
tsup.config.*.mjs
|
||||
coverage/
|
||||
@@ -2,11 +2,72 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [@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)
|
||||
# [@discordjs/builders@1.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.2.0...@discordjs/builders@1.3.0) - (2022-10-08)
|
||||
|
||||
## Info
|
||||
## Bug Fixes
|
||||
|
||||
- 1.0.0 release bump, no new features.
|
||||
- Allow adding forums to `channelTypes` (#8658) ([b1e190c](https://github.com/discordjs/discord.js/commit/b1e190c4f0773a1a739625f5b41026f593515370))
|
||||
- **SlashCommandBuilder:** Missing methods in subcommand builder (#8583) ([1c5b78f](https://github.com/discordjs/discord.js/commit/1c5b78fd2130f09c951459cf4c2d637f46c3c2c9))
|
||||
- Footer / sidebar / deprecation alert ([ba3e0ed](https://github.com/discordjs/discord.js/commit/ba3e0ed348258fe8e51eefb4aa7379a1230616a9))
|
||||
|
||||
## Documentation
|
||||
|
||||
- **builders/components:** Document constructors (#8636) ([8444576](https://github.com/discordjs/discord.js/commit/8444576f45da5fdddbf8ba2d91b4cb31a3b51c04))
|
||||
- Change name (#8604) ([dd5a089](https://github.com/discordjs/discord.js/commit/dd5a08944c258a847fc4377f1d5e953264ab47d0))
|
||||
- Use remarks instead of `Note` in descriptions (#8597) ([f3ce4a7](https://github.com/discordjs/discord.js/commit/f3ce4a75d0c4eafc89a1f0ce9f4964bcbcdae6da))
|
||||
|
||||
## Features
|
||||
|
||||
- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2))
|
||||
- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3))
|
||||
- Add `chatInputApplicationCommandMention` formatter (#8546) ([d08a57c](https://github.com/discordjs/discord.js/commit/d08a57cadd9d69a734077cc1902d931ab10336db))
|
||||
|
||||
## Refactor
|
||||
|
||||
- Replace usage of deprecated `ChannelType`s (#8625) ([669c3cd](https://github.com/discordjs/discord.js/commit/669c3cd2566eac68ef38ab522dd6378ba761e8b3))
|
||||
- Website components (#8600) ([c334157](https://github.com/discordjs/discord.js/commit/c3341570d983aea9ecc419979d5a01de658c9d67))
|
||||
- Use `eslint-config-neon` for packages. (#8579) ([edadb9f](https://github.com/discordjs/discord.js/commit/edadb9fe5dfd9ff51a3cfc9b25cb242d3f9f5241))
|
||||
|
||||
## Testing
|
||||
|
||||
- Rename incorrect test (#8596) ([ce991dd](https://github.com/discordjs/discord.js/commit/ce991dd1d883f6785b5f4b4b3ac80ef21cb304e7))
|
||||
|
||||
## Typings
|
||||
|
||||
- **interactions:** Fix `{Slash,ContextMenu}CommandBuilder#toJSON` (#8568) ([b7eb96d](https://github.com/discordjs/discord.js/commit/b7eb96d45670616521fbcca28a657793d91605c7))
|
||||
|
||||
# [@discordjs/builders@1.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.1.0...@discordjs/builders@1.2.0) - (2022-08-22)
|
||||
|
||||
## Features
|
||||
|
||||
- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007))
|
||||
- **website:** Show descriptions for `@typeParam` blocks (#8523) ([e475b63](https://github.com/discordjs/discord.js/commit/e475b63f257f6261d73cb89fee9ecbcdd84e2a6b))
|
||||
- **website:** Show parameter descriptions (#8519) ([7f415a2](https://github.com/discordjs/discord.js/commit/7f415a2502bf7ce2025dbcfed9017b0635a19966))
|
||||
- **WebSocketShard:** Support new resume url (#8480) ([bc06cc6](https://github.com/discordjs/discord.js/commit/bc06cc638d2f57ab5c600e8cdb6afc8eb2180166))
|
||||
|
||||
## Refactor
|
||||
|
||||
- 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@0.16.0...@discordjs/builders@1.1.0) - (2022-07-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Use proper format for `@link` text (#8384) ([2655639](https://github.com/discordjs/discord.js/commit/26556390a3800e954974a00c1328ff47d3e67e9a))
|
||||
- **Formatters:** Add newline in `codeBlock` (#8369) ([5d8bd03](https://github.com/discordjs/discord.js/commit/5d8bd030d60ef364de3ef5f9963da8bda5c4efd4))
|
||||
- **selectMenu:** Allow json to be used for select menu options (#8322) ([6a2d0d8](https://github.com/discordjs/discord.js/commit/6a2d0d8e96d157d5b85cee7f17bffdfff4240074))
|
||||
|
||||
## Documentation
|
||||
|
||||
- Use link tags (#8382) ([5494791](https://github.com/discordjs/discord.js/commit/549479131318c659f86f0eb18578d597e22522d3))
|
||||
|
||||
## Features
|
||||
|
||||
- Add channel & message URL formatters (#8371) ([a7deb8f](https://github.com/discordjs/discord.js/commit/a7deb8f89830ead6185c5fb46a49688b6d209ed1))
|
||||
|
||||
## Testing
|
||||
|
||||
- **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)
|
||||
|
||||
@@ -47,14 +108,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
|
||||
@@ -145,108 +198,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,4 +1,9 @@
|
||||
import { APIActionRowComponent, APIMessageActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v10';
|
||||
import {
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
type APIActionRowComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
@@ -6,7 +11,7 @@ import {
|
||||
createComponentBuilder,
|
||||
SelectMenuBuilder,
|
||||
SelectMenuOptionBuilder,
|
||||
} from '../../src';
|
||||
} from '../../src/index.js';
|
||||
|
||||
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
APIButtonComponentWithCustomId,
|
||||
APIButtonComponentWithURL,
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
type APIButtonComponentWithCustomId,
|
||||
type APIButtonComponentWithURL,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions';
|
||||
import { ButtonBuilder } from '../../src/components/button/Button';
|
||||
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions.js';
|
||||
import { ButtonBuilder } from '../../src/components/button/Button.js';
|
||||
|
||||
const buttonComponent = () => new ButtonBuilder();
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('Button Components', () => {
|
||||
expect(() => buttonStyleValidator.parse(ButtonStyle.Secondary)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid style THEN validator does not throw', () => {
|
||||
test('GIVEN invalid style THEN validator does throw', () => {
|
||||
expect(() => buttonStyleValidator.parse(7)).toThrowError();
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('Button Components', () => {
|
||||
}).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
const button = buttonComponent().setEmoji('test');
|
||||
button.toJSON();
|
||||
}).toThrowError();
|
||||
@@ -103,9 +103,9 @@ describe('Button Components', () => {
|
||||
|
||||
expect(() => buttonComponent().setStyle(24)).toThrowError();
|
||||
expect(() => buttonComponent().setLabel(longStr)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid parameter for disabled
|
||||
expect(() => buttonComponent().setDisabled(0)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
expect(() => buttonComponent().setEmoji('foo')).toThrowError();
|
||||
|
||||
expect(() => buttonComponent().setURL('foobar')).toThrowError();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
APIActionRowComponent,
|
||||
APIButtonComponent,
|
||||
APIMessageActionRowComponent,
|
||||
APISelectMenuComponent,
|
||||
APITextInputComponent,
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
TextInputStyle,
|
||||
type APIButtonComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
type APISelectMenuComponent,
|
||||
type APITextInputComponent,
|
||||
type APIActionRowComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
createComponentBuilder,
|
||||
SelectMenuBuilder,
|
||||
TextInputBuilder,
|
||||
} from '../../src/index';
|
||||
} from '../../src/index.js';
|
||||
|
||||
describe('createComponentBuilder', () => {
|
||||
test.each([ButtonBuilder, SelectMenuBuilder, TextInputBuilder])(
|
||||
@@ -67,7 +67,7 @@ describe('createComponentBuilder', () => {
|
||||
});
|
||||
|
||||
test('GIVEN an unknown component type THEN throws error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Unknown component type
|
||||
expect(() => createComponentBuilder({ type: 'invalid' })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { APISelectMenuComponent, APISelectMenuOption, ComponentType } from 'discord-api-types/v10';
|
||||
import { ComponentType, type APISelectMenuComponent, type APISelectMenuOption } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { SelectMenuBuilder, SelectMenuOptionBuilder } from '../../src/index';
|
||||
import { SelectMenuBuilder, SelectMenuOptionBuilder } from '../../src/index.js';
|
||||
|
||||
const selectMenu = () => new SelectMenuBuilder();
|
||||
const selectMenuOption = () => new SelectMenuOptionBuilder();
|
||||
@@ -74,7 +74,8 @@ describe('Select Menu Components', () => {
|
||||
]),
|
||||
).not.toThrowError();
|
||||
|
||||
const options = new Array<APISelectMenuOption>(25).fill({ label: 'test', value: 'test' });
|
||||
const options = Array.from<APISelectMenuOption>({ length: 25 }).fill({ label: 'test', value: 'test' });
|
||||
|
||||
expect(() => selectMenu().addOptions(...options)).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions(...options)).not.toThrowError();
|
||||
expect(() => selectMenu().addOptions(options)).not.toThrowError();
|
||||
@@ -83,12 +84,13 @@ describe('Select Menu Components', () => {
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions({ label: 'test', value: 'test' })
|
||||
.addOptions(...new Array<APISelectMenuOption>(24).fill({ label: 'test', value: 'test' })),
|
||||
|
||||
.addOptions(...Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
|
||||
).not.toThrowError();
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions([{ label: 'test', value: 'test' }])
|
||||
.addOptions(new Array<APISelectMenuOption>(24).fill({ label: 'test', value: 'test' })),
|
||||
.addOptions(Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
@@ -96,33 +98,34 @@ describe('Select Menu Components', () => {
|
||||
expect(() => selectMenu().setCustomId(longStr)).toThrowError();
|
||||
expect(() => selectMenu().setMaxValues(30)).toThrowError();
|
||||
expect(() => selectMenu().setMinValues(-20)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid disabled value
|
||||
expect(() => selectMenu().setDisabled(0)).toThrowError();
|
||||
expect(() => selectMenu().setPlaceholder(longStr)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ label: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ label: longStr, value: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ value: longStr, label: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', description: longStr })).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', default: 100 })).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ value: 'test' })).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ default: true })).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ label: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ label: longStr, value: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ value: longStr, label: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ label: 'test', value: 'test', description: longStr }])).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ label: 'test', value: 'test', default: 100 }])).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ value: 'test' }])).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ default: true }])).toThrowError();
|
||||
|
||||
const tooManyOptions = new Array<APISelectMenuOption>(26).fill({ label: 'test', value: 'test' });
|
||||
const tooManyOptions = Array.from<APISelectMenuOption>({ length: 26 }).fill({ label: 'test', value: 'test' });
|
||||
|
||||
expect(() => selectMenu().setOptions(...tooManyOptions)).toThrowError();
|
||||
expect(() => selectMenu().setOptions(tooManyOptions)).toThrowError();
|
||||
|
||||
@@ -141,9 +144,9 @@ describe('Select Menu Components', () => {
|
||||
selectMenuOption()
|
||||
.setLabel(longStr)
|
||||
.setValue(longStr)
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid default value
|
||||
.setDefault(-1)
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
.setEmoji({ name: 1 })
|
||||
.setDescription(longStr);
|
||||
}).toThrowError();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { APITextInputComponent, ComponentType, TextInputStyle } from 'discord-api-types/v10';
|
||||
import { ComponentType, TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
labelValidator,
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
placeholderValidator,
|
||||
valueValidator,
|
||||
textInputStyleValidator,
|
||||
} from '../../src/components/textInput/Assertions';
|
||||
import { TextInputBuilder } from '../../src/components/textInput/TextInput';
|
||||
} from '../../src/components/textInput/Assertions.js';
|
||||
import { TextInputBuilder } from '../../src/components/textInput/TextInput.js';
|
||||
|
||||
const superLongStr = 'a'.repeat(5000);
|
||||
const superLongStr = 'a'.repeat(5_000);
|
||||
|
||||
const textInputComponent = () => new TextInputBuilder();
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('Text Input Components', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid min length THEN validator does throw 2', () => {
|
||||
expect(() => maxLengthValidator.parse(4001)).toThrowError();
|
||||
expect(() => maxLengthValidator.parse(4_001)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid value THEN validator does not throw', () => {
|
||||
@@ -85,7 +85,7 @@ describe('Text Input Components', () => {
|
||||
|
||||
expect(() => {
|
||||
// Issue #8107
|
||||
// @ts-expect-error: shapeshift maps the enum key to the value when parsing
|
||||
// @ts-expect-error: Shapeshift maps the enum key to the value when parsing
|
||||
textInputComponent().setCustomId('Custom').setLabel('Guess').setStyle('Short').toJSON();
|
||||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PermissionFlagsBits } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index';
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index.js';
|
||||
|
||||
const getBuilder = () => new ContextMenuCommandBuilder();
|
||||
|
||||
@@ -105,9 +105,9 @@ describe('Context Menu Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid name localizations THEN does throw error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import {
|
||||
APIApplicationCommandAttachmentOption,
|
||||
APIApplicationCommandBooleanOption,
|
||||
APIApplicationCommandChannelOption,
|
||||
APIApplicationCommandIntegerOption,
|
||||
APIApplicationCommandMentionableOption,
|
||||
APIApplicationCommandNumberOption,
|
||||
APIApplicationCommandRoleOption,
|
||||
APIApplicationCommandStringOption,
|
||||
APIApplicationCommandUserOption,
|
||||
ApplicationCommandOptionType,
|
||||
ChannelType,
|
||||
type APIApplicationCommandAttachmentOption,
|
||||
type APIApplicationCommandBooleanOption,
|
||||
type APIApplicationCommandChannelOption,
|
||||
type APIApplicationCommandIntegerOption,
|
||||
type APIApplicationCommandMentionableOption,
|
||||
type APIApplicationCommandNumberOption,
|
||||
type APIApplicationCommandRoleOption,
|
||||
type APIApplicationCommandStringOption,
|
||||
type APIApplicationCommandUserOption,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
} from '../../../src/index.js';
|
||||
|
||||
const getBooleanOption = () =>
|
||||
new SlashCommandBooleanOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
@@ -101,7 +101,8 @@ describe('Application Command toJSON() results', () => {
|
||||
max_value: 10,
|
||||
min_value: -1,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
// TODO
|
||||
// @ts-expect-error You *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
@@ -145,7 +146,8 @@ describe('Application Command toJSON() results', () => {
|
||||
max_value: 10,
|
||||
min_value: -1.23,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
// TODO
|
||||
// @ts-expect-error You *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
@@ -187,7 +189,8 @@ describe('Application Command toJSON() results', () => {
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
// TODO
|
||||
// @ts-expect-error you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { APIApplicationCommandOptionChoice, ChannelType, PermissionFlagsBits } from 'discord-api-types/v10';
|
||||
import { ChannelType, PermissionFlagsBits, type APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
SlashCommandAssertions,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
} from '../../../src/index.js';
|
||||
|
||||
const largeArray = Array.from({ length: 26 }, () => 1 as unknown as APIApplicationCommandOptionChoice);
|
||||
|
||||
@@ -33,9 +33,7 @@ const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setNam
|
||||
const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123');
|
||||
|
||||
class Collection {
|
||||
public get [Symbol.toStringTag]() {
|
||||
return 'Map';
|
||||
}
|
||||
public readonly [Symbol.toStringTag] = 'Map';
|
||||
}
|
||||
|
||||
describe('Slash Commands', () => {
|
||||
@@ -178,7 +176,7 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid autocomplete THEN does throw an error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addStringOption(getStringOption().setAutocomplete('not a boolean'))).toThrowError();
|
||||
});
|
||||
|
||||
@@ -236,7 +234,7 @@ describe('Slash Commands', () => {
|
||||
|
||||
expect(() => {
|
||||
getBuilder().addChannelOption(
|
||||
getChannelOption().addChannelTypes(ChannelType.GuildNews, ChannelType.GuildText),
|
||||
getChannelOption().addChannelTypes(ChannelType.GuildAnnouncement, ChannelType.GuildText),
|
||||
);
|
||||
}).not.toThrowError();
|
||||
});
|
||||
@@ -248,16 +246,16 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid number min/max options THEN does throw an error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid max value
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid max value
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid min value
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid min value
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue(1.5))).toThrowError();
|
||||
@@ -294,10 +292,10 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addOption method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(getRoleOption())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -318,18 +316,18 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid returns for builder THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(true)).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(null)).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(undefined)).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => SlashCommandStringOption)).toThrowError();
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => new Collection())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -373,6 +371,18 @@ describe('Slash Commands', () => {
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with subcommand THEN has regular slash command fields', () => {
|
||||
expect(() =>
|
||||
getBuilder()
|
||||
.setName('name')
|
||||
.setDescription('description')
|
||||
.addSubcommand((option) => option.setName('ye').setDescription('ye'))
|
||||
.addSubcommand((option) => option.setName('no').setDescription('no'))
|
||||
.setDMPermission(false)
|
||||
.setDefaultMemberPermissions(1n),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with already built subcommand group THEN does not throw error', () => {
|
||||
expect(() => getNamedBuilder().addSubcommandGroup(getSubcommandGroup())).not.toThrowError();
|
||||
});
|
||||
@@ -389,30 +399,29 @@ describe('Slash Commands', () => {
|
||||
|
||||
test('GIVEN builder with a subcommand that tries to add an invalid result THEN throw error', () => {
|
||||
expect(() =>
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
||||
// @ts-expect-error: Checking if check works JS-side too
|
||||
getNamedBuilder().addSubcommand(getSubcommand()).addInteger(getInteger()),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addSubcommand(Group) method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommandGroup()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subcommand group builder', () => {
|
||||
test('GIVEN no valid subcommand THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -444,9 +453,9 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid name localizations THEN does throw error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
@@ -467,9 +476,9 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid description localizations THEN does throw error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization description
|
||||
expect(() => getBuilder().setDescriptionLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid localization description
|
||||
expect(() => getBuilder().setDescriptionLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import {
|
||||
APIModalInteractionResponseCallbackData,
|
||||
APITextInputComponent,
|
||||
ComponentType,
|
||||
TextInputStyle,
|
||||
type APIModalInteractionResponseCallbackData,
|
||||
type APITextInputComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ModalBuilder,
|
||||
ModalActionRowComponentBuilder,
|
||||
TextInputBuilder,
|
||||
} from '../../src';
|
||||
type ModalActionRowComponentBuilder,
|
||||
} from '../../src/index.js';
|
||||
import {
|
||||
componentsValidator,
|
||||
titleValidator,
|
||||
validateRequiredParameters,
|
||||
} from '../../src/interactions/modals/Assertions';
|
||||
} from '../../src/interactions/modals/Assertions.js';
|
||||
|
||||
const modal = () => new ModalBuilder();
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Modals', () => {
|
||||
|
||||
test('GIVEN invalid required parameters THEN validator does throw', () => {
|
||||
expect(() =>
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Missing required parameter
|
||||
validateRequiredParameters('123', undefined, [new ActionRowBuilder(), new ButtonBuilder()]),
|
||||
).toThrowError();
|
||||
});
|
||||
@@ -66,7 +66,7 @@ describe('Modals', () => {
|
||||
test('GIVEN invalid fields THEN builder does throw', () => {
|
||||
expect(() => modal().setTitle('test').setCustomId('foobar').toJSON()).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: CustomId is invalid
|
||||
expect(() => modal().setTitle('test').setCustomId(42).toJSON()).toThrowError();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { EmbedBuilder, embedLength } from '../../src';
|
||||
import { EmbedBuilder, embedLength } from '../../src/index.js';
|
||||
|
||||
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('Embed', () => {
|
||||
test('GIVEN an embed with an invalid description THEN throws error', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setDescription('a'.repeat(4097))).toThrowError();
|
||||
expect(() => embed.setDescription('a'.repeat(4_097))).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -130,11 +130,11 @@ describe('Embed', () => {
|
||||
test('GIVEN an embed with an invalid color THEN throws error', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid color
|
||||
expect(() => embed.setColor('RED')).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid color
|
||||
expect(() => embed.setColor([42, 36])).toThrowError();
|
||||
expect(() => embed.setColor([42, 36, 1000])).toThrowError();
|
||||
expect(() => embed.setColor([42, 36, 1_000])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -307,7 +307,7 @@ describe('Embed', () => {
|
||||
test('GIVEN an embed with invalid footer text THEN throws error', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setFooter({ text: 'a'.repeat(2049) })).toThrowError();
|
||||
expect(() => embed.setFooter({ text: 'a'.repeat(2_049) })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -411,7 +411,7 @@ describe('Embed', () => {
|
||||
test('4', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.addFields({ name: '', value: 'a'.repeat(1025) })).toThrowError();
|
||||
expect(() => embed.addFields({ name: '', value: 'a'.repeat(1_025) })).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import { URL } from 'node:url';
|
||||
import { describe, test, expect, vitest } from 'vitest';
|
||||
import {
|
||||
chatInputApplicationCommandMention,
|
||||
blockQuote,
|
||||
bold,
|
||||
channelLink,
|
||||
channelMention,
|
||||
codeBlock,
|
||||
Faces,
|
||||
@@ -11,6 +14,7 @@ import {
|
||||
hyperlink,
|
||||
inlineCode,
|
||||
italic,
|
||||
messageLink,
|
||||
quote,
|
||||
roleMention,
|
||||
spoiler,
|
||||
@@ -19,7 +23,7 @@ import {
|
||||
TimestampStyles,
|
||||
underscore,
|
||||
userMention,
|
||||
} from '../../src';
|
||||
} from '../../src/index.js';
|
||||
|
||||
describe('Message formatters', () => {
|
||||
describe('codeBlock', () => {
|
||||
@@ -134,6 +138,26 @@ describe('Message formatters', () => {
|
||||
expect(roleMention('815434166602170409')).toEqual('<@&815434166602170409>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chatInputApplicationCommandMention', () => {
|
||||
test('GIVEN commandName and commandId THEN returns "</[commandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', '815434166602170409')).toEqual(
|
||||
'</airhorn:815434166602170409>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN commandName, subcommandName, and commandId THEN returns "</[commandName] [subcommandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', 'sub', '815434166602170409')).toEqual(
|
||||
'</airhorn sub:815434166602170409>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN commandName, subcommandGroupName, subcommandName, and commandId THEN returns "</[commandName] [subcommandGroupName] [subcommandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', 'group', 'sub', '815434166602170409')).toEqual(
|
||||
'</airhorn group sub:815434166602170409>',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatEmoji', () => {
|
||||
@@ -150,10 +174,38 @@ describe('Message formatters', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('channelLink', () => {
|
||||
test('GIVEN channelId THEN returns "https://discord.com/channels/@me/${channelId}"', () => {
|
||||
expect<'https://discord.com/channels/@me/123456789012345678'>(channelLink('123456789012345678')).toEqual(
|
||||
'https://discord.com/channels/@me/123456789012345678',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN channelId WITH guildId THEN returns "https://discord.com/channels/${guildId}/${channelId}"', () => {
|
||||
expect<'https://discord.com/channels/987654321987654/123456789012345678'>(
|
||||
channelLink('123456789012345678', '987654321987654'),
|
||||
).toEqual('https://discord.com/channels/987654321987654/123456789012345678');
|
||||
});
|
||||
});
|
||||
|
||||
describe('messageLink', () => {
|
||||
test('GIVEN channelId AND messageId THEN returns "https://discord.com/channels/@me/${channelId}/${messageId}"', () => {
|
||||
expect<'https://discord.com/channels/@me/123456789012345678/102938475657483'>(
|
||||
messageLink('123456789012345678', '102938475657483'),
|
||||
).toEqual('https://discord.com/channels/@me/123456789012345678/102938475657483');
|
||||
});
|
||||
|
||||
test('GIVEN channelId AND messageId WITH guildId THEN returns "https://discord.com/channels/${guildId}/${channelId}/${messageId}"', () => {
|
||||
expect<'https://discord.com/channels/987654321987654/123456789012345678/102938475657483'>(
|
||||
messageLink('123456789012345678', '102938475657483', '987654321987654'),
|
||||
).toEqual('https://discord.com/channels/987654321987654/123456789012345678/102938475657483');
|
||||
});
|
||||
});
|
||||
|
||||
describe('time', () => {
|
||||
test('GIVEN no arguments THEN returns "<t:${bigint}>"', () => {
|
||||
vitest.useFakeTimers();
|
||||
vitest.setSystemTime(1566424897579);
|
||||
vitest.setSystemTime(1_566_424_897_579);
|
||||
|
||||
expect<`<t:${bigint}>`>(time()).toEqual('<t:1566424897>');
|
||||
|
||||
@@ -161,29 +213,29 @@ describe('Message formatters', () => {
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${bigint}>"', () => {
|
||||
expect<`<t:${bigint}>`>(time(new Date(1867424897579))).toEqual('<t:1867424897>');
|
||||
expect<`<t:${bigint}>`>(time(new Date(1_867_424_897_579))).toEqual('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:d>`>(time(new Date(1867424897579), 'd')).toEqual('<t:1867424897:d>');
|
||||
expect<`<t:${bigint}:d>`>(time(new Date(1_867_424_897_579), 'd')).toEqual('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:R>`>(time(new Date(1867424897579), TimestampStyles.RelativeTime)).toEqual(
|
||||
expect<`<t:${bigint}:R>`>(time(new Date(1_867_424_897_579), TimestampStyles.RelativeTime)).toEqual(
|
||||
'<t:1867424897:R>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${time}>"', () => {
|
||||
expect<'<t:1867424897>'>(time(1867424897)).toEqual('<t:1867424897>');
|
||||
expect<'<t:1867424897>'>(time(1_867_424_897)).toEqual('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:d>'>(time(1867424897, 'd')).toEqual('<t:1867424897:d>');
|
||||
expect<'<t:1867424897:d>'>(time(1_867_424_897, 'd')).toEqual('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:R>'>(time(1867424897, TimestampStyles.RelativeTime)).toEqual('<t:1867424897:R>');
|
||||
expect<'<t:1867424897:R>'>(time(1_867_424_897, TimestampStyles.RelativeTime)).toEqual('<t:1867424897:R>');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,33 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
isJSONEncodable,
|
||||
isEquatable,
|
||||
ActionRowBuilder,
|
||||
enableValidators,
|
||||
disableValidators,
|
||||
isValidationEnabled,
|
||||
} from '../src/index';
|
||||
|
||||
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', () => {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { createUnbuildConfig } from '../../build.config';
|
||||
|
||||
export default createUnbuildConfig();
|
||||
@@ -59,5 +59,5 @@ commit_parsers = [
|
||||
filter_commits = true
|
||||
tag_pattern = "@discordjs/builders@[0-9]*"
|
||||
ignore_tags = ""
|
||||
topo_order = false
|
||||
date_order = true
|
||||
sort_commits = "newest"
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"name": "@discordjs/builders",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.0",
|
||||
"description": "A set of builders that you can use when creating your bot",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "unbuild",
|
||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
||||
"build": "tsup",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix",
|
||||
"fmt": "yarn format",
|
||||
"docs": "downlevel-dts . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||
"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/builders/*'",
|
||||
"release": "cliff-jumper"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"directories": {
|
||||
@@ -33,7 +33,7 @@
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Antonio Roman <kyradiscord@gmail.com>"
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
@@ -54,26 +54,27 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@sapphire/shapeshift": "^3.5.1",
|
||||
"discord-api-types": "^0.36.3",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/shapeshift": "^3.7.0",
|
||||
"discord-api-types": "^0.37.12",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"ts-mixer": "^6.0.1",
|
||||
"tslib": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordjs/docgen": "workspace:^",
|
||||
"@favware/cliff-jumper": "^1.8.5",
|
||||
"@microsoft/api-extractor": "^7.28.6",
|
||||
"@types/node": "^16.11.45",
|
||||
"c8": "^7.12.0",
|
||||
"downlevel-dts": "^0.10.0",
|
||||
"eslint": "^8.20.0",
|
||||
"@favware/cliff-jumper": "^1.8.8",
|
||||
"@microsoft/api-extractor": "^7.32.0",
|
||||
"@types/node": "^16.11.64",
|
||||
"@vitest/coverage-c8": "^0.24.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"downlevel-dts": "^0.10.1",
|
||||
"esbuild-plugin-version-injector": "^1.0.0",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-neon": "^0.1.35",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup-plugin-typescript2": "0.32.1",
|
||||
"tsup": "^6.2.0",
|
||||
"typescript": "^4.7.4",
|
||||
"unbuild": "^0.7.6",
|
||||
"vitest": "^0.19.1"
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.4",
|
||||
"vitest": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import {
|
||||
type APIActionRowComponent,
|
||||
ComponentType,
|
||||
APIMessageActionRowComponent,
|
||||
APIModalActionRowComponent,
|
||||
APIActionRowComponentTypes,
|
||||
type APIMessageActionRowComponent,
|
||||
type APIModalActionRowComponent,
|
||||
type APIActionRowComponentTypes,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ComponentBuilder } from './Component';
|
||||
import { createComponentBuilder } from './Components';
|
||||
import type { ButtonBuilder } from './button/Button';
|
||||
import type { SelectMenuBuilder } from './selectMenu/SelectMenu';
|
||||
import type { TextInputBuilder } from './textInput/TextInput';
|
||||
import { normalizeArray, type RestOrArray } from '../util/normalizeArray';
|
||||
import { normalizeArray, type RestOrArray } from '../util/normalizeArray.js';
|
||||
import { ComponentBuilder } from './Component.js';
|
||||
import { createComponentBuilder } from './Components.js';
|
||||
import type { ButtonBuilder } from './button/Button.js';
|
||||
import type { SelectMenuBuilder } from './selectMenu/SelectMenu.js';
|
||||
import type { TextInputBuilder } from './textInput/TextInput.js';
|
||||
|
||||
export type MessageComponentBuilder =
|
||||
| MessageActionRowComponentBuilder
|
||||
| ActionRowBuilder<MessageActionRowComponentBuilder>;
|
||||
export type ModalComponentBuilder = ModalActionRowComponentBuilder | ActionRowBuilder<ModalActionRowComponentBuilder>;
|
||||
| ActionRowBuilder<MessageActionRowComponentBuilder>
|
||||
| MessageActionRowComponentBuilder;
|
||||
export type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder;
|
||||
export type MessageActionRowComponentBuilder = ButtonBuilder | SelectMenuBuilder;
|
||||
export type ModalActionRowComponentBuilder = TextInputBuilder;
|
||||
export type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder;
|
||||
|
||||
/**
|
||||
* Represents an action row component
|
||||
*
|
||||
* @typeParam T - The types of components this action row holds
|
||||
*/
|
||||
export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<
|
||||
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
||||
@@ -31,9 +35,43 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
*/
|
||||
public readonly components: T[];
|
||||
|
||||
/**
|
||||
* Creates a new action row from API data
|
||||
*
|
||||
* @param data - The API data to create this action row with
|
||||
* @example
|
||||
* Creating an action row from an API data object
|
||||
* ```ts
|
||||
* const actionRow = new ActionRowBuilder({
|
||||
* components: [
|
||||
* {
|
||||
* custom_id: "custom id",
|
||||
* label: "Type something",
|
||||
* style: TextInputStyle.Short,
|
||||
* type: ComponentType.TextInput,
|
||||
* },
|
||||
* ],
|
||||
* });
|
||||
* ```
|
||||
* @example
|
||||
* Creating an action row using setters and API data
|
||||
* ```ts
|
||||
* const actionRow = new ActionRowBuilder({
|
||||
* components: [
|
||||
* {
|
||||
* custom_id: "custom id",
|
||||
* label: "Click me",
|
||||
* style: ButtonStyle.Primary,
|
||||
* type: ComponentType.Button,
|
||||
* },
|
||||
* ],
|
||||
* })
|
||||
* .addComponents(button2, button3);
|
||||
* ```
|
||||
*/
|
||||
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
|
||||
super({ type: ComponentType.ActionRow, ...data });
|
||||
this.components = (components?.map((c) => createComponentBuilder(c)) ?? []) as T[];
|
||||
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +94,10 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return {
|
||||
...this.data,
|
||||
components: this.components.map((component) => component.toJSON()),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { APIMessageComponentEmoji, ButtonStyle } from 'discord-api-types/v10';
|
||||
import { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption';
|
||||
import { isValidationEnabled } from '../util/validation';
|
||||
import { ButtonStyle, type APIMessageComponentEmoji } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../util/validation.js';
|
||||
import { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption.js';
|
||||
|
||||
export const customIdValidator = s.string
|
||||
.lengthGreaterThanOrEqual(1)
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
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 = APIActionRowComponentTypes | APIActionRowComponent<APIActionRowComponentTypes>;
|
||||
export type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes;
|
||||
|
||||
/**
|
||||
* Represents a discord component
|
||||
*
|
||||
* @typeParam DataType - The type of internal API data that is stored within the component
|
||||
*/
|
||||
export abstract class ComponentBuilder<
|
||||
DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,
|
||||
@@ -20,6 +22,13 @@ export abstract class ComponentBuilder<
|
||||
*/
|
||||
public readonly data: Partial<DataType>;
|
||||
|
||||
/**
|
||||
* Serializes this component to an API-compatible JSON object
|
||||
*
|
||||
* @remarks
|
||||
* This method runs validations on the data before serializing it.
|
||||
* As such, it may throw an error if the data is invalid.
|
||||
*/
|
||||
public abstract toJSON(): AnyAPIActionRowComponent;
|
||||
|
||||
public constructor(data: Partial<DataType>) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { APIMessageComponent, APIModalComponent, ComponentType } from 'discord-api-types/v10';
|
||||
import { ComponentType, type APIMessageComponent, type APIModalComponent } from 'discord-api-types/v10';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
type AnyComponentBuilder,
|
||||
type MessageComponentBuilder,
|
||||
type ModalComponentBuilder,
|
||||
} from './ActionRow';
|
||||
import { ComponentBuilder } from './Component';
|
||||
import { ButtonBuilder } from './button/Button';
|
||||
import { SelectMenuBuilder } from './selectMenu/SelectMenu';
|
||||
import { TextInputBuilder } from './textInput/TextInput';
|
||||
} from './ActionRow.js';
|
||||
import { ComponentBuilder } from './Component.js';
|
||||
import { ButtonBuilder } from './button/Button.js';
|
||||
import { SelectMenuBuilder } from './selectMenu/SelectMenu.js';
|
||||
import { TextInputBuilder } from './textInput/TextInput.js';
|
||||
|
||||
export interface MappedComponentTypes {
|
||||
[ComponentType.ActionRow]: ActionRowBuilder<AnyComponentBuilder>;
|
||||
@@ -23,7 +23,8 @@ export interface MappedComponentTypes {
|
||||
* @param data - The api data to transform to a component class
|
||||
*/
|
||||
export function createComponentBuilder<T extends keyof MappedComponentTypes>(
|
||||
data: (APIMessageComponent | APIModalComponent) & { type: T },
|
||||
// eslint-disable-next-line @typescript-eslint/sort-type-union-intersection-members
|
||||
data: (APIModalComponent | APIMessageComponent) & { type: T },
|
||||
): MappedComponentTypes[T];
|
||||
export function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C;
|
||||
export function createComponentBuilder(
|
||||
@@ -43,8 +44,7 @@ export function createComponentBuilder(
|
||||
case ComponentType.TextInput:
|
||||
return new TextInputBuilder(data);
|
||||
default:
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
// @ts-expect-error: This case can still occur if we get a newer unsupported component type
|
||||
throw new Error(`Cannot properly serialize component type: ${data.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
ComponentType,
|
||||
ButtonStyle,
|
||||
type APIMessageComponentEmoji,
|
||||
type APIButtonComponent,
|
||||
type APIButtonComponentWithURL,
|
||||
type APIButtonComponentWithCustomId,
|
||||
type ButtonStyle,
|
||||
} from 'discord-api-types/v10';
|
||||
import {
|
||||
buttonLabelValidator,
|
||||
@@ -14,13 +14,41 @@ import {
|
||||
emojiValidator,
|
||||
urlValidator,
|
||||
validateRequiredButtonParameters,
|
||||
} from '../Assertions';
|
||||
import { ComponentBuilder } from '../Component';
|
||||
} from '../Assertions.js';
|
||||
import { ComponentBuilder } from '../Component.js';
|
||||
|
||||
/**
|
||||
* Represents a button component
|
||||
*/
|
||||
export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Creates a new button from API data
|
||||
*
|
||||
* @param data - The API data to create this button with
|
||||
* @example
|
||||
* Creating a button from an API data object
|
||||
* ```ts
|
||||
* const button = new ButtonBuilder({
|
||||
* custom_id: 'a cool button',
|
||||
* style: ButtonStyle.Primary,
|
||||
* label: 'Click Me',
|
||||
* emoji: {
|
||||
* name: 'smile',
|
||||
* id: '123456789012345678',
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
* @example
|
||||
* Creating a button using setters and API data
|
||||
* ```ts
|
||||
* const button = new ButtonBuilder({
|
||||
* style: ButtonStyle.Secondary,
|
||||
* label: 'Click Me',
|
||||
* })
|
||||
* .setEmoji({ name: '🙂' })
|
||||
* .setCustomId('another cool button');
|
||||
* ```
|
||||
*/
|
||||
public constructor(data?: Partial<APIButtonComponent>) {
|
||||
super({ type: ComponentType.Button, ...data });
|
||||
}
|
||||
@@ -38,6 +66,9 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Sets the URL for this button
|
||||
*
|
||||
* @remarks
|
||||
* This method is only available to buttons using the `Link` button style.
|
||||
* Only three types of URL schemes are currently supported: `https://`, `http://` and `discord://`
|
||||
* @param url - The URL to open when this button is clicked
|
||||
*/
|
||||
public setURL(url: string) {
|
||||
@@ -48,6 +79,8 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Sets the custom id for this button
|
||||
*
|
||||
* @remarks
|
||||
* This method is only applicable to buttons that are not using the `Link` button style.
|
||||
* @param customId - The custom id to use for this button
|
||||
*/
|
||||
public setCustomId(customId: string) {
|
||||
@@ -85,6 +118,9 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIButtonComponent {
|
||||
validateRequiredButtonParameters(
|
||||
this.data.style,
|
||||
@@ -93,7 +129,7 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
(this.data as APIButtonComponentWithCustomId).custom_id,
|
||||
(this.data as APIButtonComponentWithURL).url,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
return {
|
||||
...this.data,
|
||||
} as APIButtonComponent;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { APISelectMenuOption, ComponentType, type APISelectMenuComponent } from 'discord-api-types/v10';
|
||||
import { SelectMenuOptionBuilder } from './SelectMenuOption';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray';
|
||||
import { ComponentType, type APISelectMenuComponent, type APISelectMenuOption } from 'discord-api-types/v10';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||
import {
|
||||
customIdValidator,
|
||||
disabledValidator,
|
||||
@@ -9,8 +8,9 @@ import {
|
||||
optionsLengthValidator,
|
||||
placeholderValidator,
|
||||
validateRequiredSelectMenuParameters,
|
||||
} from '../Assertions';
|
||||
import { ComponentBuilder } from '../Component';
|
||||
} from '../Assertions.js';
|
||||
import { ComponentBuilder } from '../Component.js';
|
||||
import { SelectMenuOptionBuilder } from './SelectMenuOption.js';
|
||||
|
||||
/**
|
||||
* Represents a select menu component
|
||||
@@ -21,10 +21,41 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
||||
*/
|
||||
public readonly options: SelectMenuOptionBuilder[];
|
||||
|
||||
/**
|
||||
* Creates a new select menu from API data
|
||||
*
|
||||
* @param data - The API data to create this select menu with
|
||||
* @example
|
||||
* Creating a select menu from an API data object
|
||||
* ```ts
|
||||
* const selectMenu = new SelectMenuBuilder({
|
||||
* custom_id: 'a cool select menu',
|
||||
* placeholder: 'select an option',
|
||||
* max_values: 2,
|
||||
* options: [
|
||||
* { label: 'option 1', value: '1' },
|
||||
* { label: 'option 2', value: '2' },
|
||||
* { label: 'option 3', value: '3' },
|
||||
* ],
|
||||
* });
|
||||
* ```
|
||||
* @example
|
||||
* Creating a select menu using setters and API data
|
||||
* ```ts
|
||||
* const selectMenu = new SelectMenuBuilder({
|
||||
* custom_id: 'a cool select menu',
|
||||
* })
|
||||
* .setMinValues(1)
|
||||
* .addOptions({
|
||||
* label: 'Catchy',
|
||||
* value: 'catch',
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
public constructor(data?: Partial<APISelectMenuComponent>) {
|
||||
const { options, ...initData } = data ?? {};
|
||||
super({ type: ComponentType.SelectMenu, ...initData });
|
||||
this.options = options?.map((o) => new SelectMenuOptionBuilder(o)) ?? [];
|
||||
this.options = options?.map((option) => new SelectMenuOptionBuilder(option)) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +114,8 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
||||
* @param options - The options to add to this select menu
|
||||
* @returns
|
||||
*/
|
||||
public addOptions(...options: RestOrArray<SelectMenuOptionBuilder | APISelectMenuOption>) {
|
||||
public addOptions(...options: RestOrArray<APISelectMenuOption | SelectMenuOptionBuilder>) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = normalizeArray(options);
|
||||
optionsLengthValidator.parse(this.options.length + options.length);
|
||||
this.options.push(
|
||||
@@ -101,7 +133,8 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
||||
*
|
||||
* @param options - The options to set on this select menu
|
||||
*/
|
||||
public setOptions(...options: RestOrArray<SelectMenuOptionBuilder | APISelectMenuOption>) {
|
||||
public setOptions(...options: RestOrArray<APISelectMenuOption | SelectMenuOptionBuilder>) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = normalizeArray(options);
|
||||
optionsLengthValidator.parse(options.length);
|
||||
this.options.splice(
|
||||
@@ -116,12 +149,15 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APISelectMenuComponent {
|
||||
validateRequiredSelectMenuParameters(this.options, this.data.custom_id);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
return {
|
||||
...this.data,
|
||||
options: this.options.map((o) => o.toJSON()),
|
||||
options: this.options.map((option) => option.toJSON()),
|
||||
} as APISelectMenuComponent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';
|
||||
|
||||
import {
|
||||
defaultValidator,
|
||||
emojiValidator,
|
||||
labelValueDescriptionValidator,
|
||||
validateRequiredSelectMenuOptionParameters,
|
||||
} from '../Assertions';
|
||||
} from '../Assertions.js';
|
||||
|
||||
/**
|
||||
* Represents a option within a select menu component
|
||||
*/
|
||||
export class SelectMenuOptionBuilder {
|
||||
export class SelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
|
||||
/**
|
||||
* Creates a new select menu option from API data
|
||||
*
|
||||
* @param data - The API data to create this select menu option with
|
||||
* @example
|
||||
* Creating a select menu option from an API data object
|
||||
* ```ts
|
||||
* const selectMenuOption = new SelectMenuOptionBuilder({
|
||||
* label: 'catchy label',
|
||||
* value: '1',
|
||||
* });
|
||||
* ```
|
||||
* @example
|
||||
* Creating a select menu option using setters and API data
|
||||
* ```ts
|
||||
* const selectMenuOption = new SelectMenuOptionBuilder({
|
||||
* default: true,
|
||||
* value: '1',
|
||||
* })
|
||||
* .setLabel('woah')
|
||||
* ```
|
||||
*/
|
||||
public constructor(public data: Partial<APISelectMenuOption> = {}) {}
|
||||
|
||||
/**
|
||||
@@ -63,9 +85,12 @@ export class SelectMenuOptionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APISelectMenuOption {
|
||||
validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
return {
|
||||
...this.data,
|
||||
} as APISelectMenuOption;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { TextInputStyle } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation';
|
||||
import { customIdValidator } from '../Assertions';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import { customIdValidator } from '../Assertions.js';
|
||||
|
||||
export const textInputStyleValidator = s.nativeEnum(TextInputStyle);
|
||||
export const minLengthValidator = s.number.int
|
||||
.greaterThanOrEqual(0)
|
||||
.lessThanOrEqual(4000)
|
||||
.lessThanOrEqual(4_000)
|
||||
.setValidationEnabled(isValidationEnabled);
|
||||
export const maxLengthValidator = s.number.int
|
||||
.greaterThanOrEqual(1)
|
||||
.lessThanOrEqual(4000)
|
||||
.lessThanOrEqual(4_000)
|
||||
.setValidationEnabled(isValidationEnabled);
|
||||
export const requiredValidator = s.boolean;
|
||||
export const valueValidator = s.string.lengthLessThanOrEqual(4000).setValidationEnabled(isValidationEnabled);
|
||||
export const valueValidator = s.string.lengthLessThanOrEqual(4_000).setValidationEnabled(isValidationEnabled);
|
||||
export const placeholderValidator = s.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled);
|
||||
export const labelValidator = s.string
|
||||
.lengthGreaterThanOrEqual(1)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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 { customIdValidator } from '../Assertions.js';
|
||||
import { ComponentBuilder } from '../Component.js';
|
||||
import {
|
||||
maxLengthValidator,
|
||||
minLengthValidator,
|
||||
@@ -9,12 +12,35 @@ import {
|
||||
validateRequiredParameters,
|
||||
labelValidator,
|
||||
textInputStyleValidator,
|
||||
} from './Assertions';
|
||||
import { isJSONEncodable, type JSONEncodable } from '../../util/jsonEncodable';
|
||||
import { customIdValidator } from '../Assertions';
|
||||
import { ComponentBuilder } from '../Component';
|
||||
} from './Assertions.js';
|
||||
|
||||
export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
|
||||
export class TextInputBuilder
|
||||
extends ComponentBuilder<APITextInputComponent>
|
||||
implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>>
|
||||
{
|
||||
/**
|
||||
* Creates a new text input from API data
|
||||
*
|
||||
* @param data - The API data to create this text input with
|
||||
* @example
|
||||
* Creating a select menu option from an API data object
|
||||
* ```ts
|
||||
* const textInput = new TextInputBuilder({
|
||||
* custom_id: 'a cool select menu',
|
||||
* label: 'Type something',
|
||||
* style: TextInputStyle.Short,
|
||||
* });
|
||||
* ```
|
||||
* @example
|
||||
* Creating a select menu option using setters and API data
|
||||
* ```ts
|
||||
* const textInput = new TextInputBuilder({
|
||||
* label: 'Type something else',
|
||||
* })
|
||||
* .setCustomId('woah')
|
||||
* .setStyle(TextInputStyle.Paragraph);
|
||||
* ```
|
||||
*/
|
||||
public constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {
|
||||
super({ type: ComponentType.TextInput, ...data });
|
||||
}
|
||||
@@ -99,15 +125,21 @@ export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APITextInputComponent {
|
||||
validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
return {
|
||||
...this.data,
|
||||
} as APITextInputComponent;
|
||||
}
|
||||
|
||||
public equals(other: JSONEncodable<APITextInputComponent> | APITextInputComponent): boolean {
|
||||
/**
|
||||
* {@inheritDoc Equatable.equals}
|
||||
*/
|
||||
public equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean {
|
||||
if (isJSONEncodable(other)) {
|
||||
return isEqual(other.toJSON(), this.data);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,51 @@
|
||||
export * as EmbedAssertions from './messages/embed/Assertions';
|
||||
export * from './messages/embed/Embed';
|
||||
export * from './messages/formatters';
|
||||
export * as EmbedAssertions from './messages/embed/Assertions.js';
|
||||
export * from './messages/embed/Embed.js';
|
||||
export * from './messages/formatters.js';
|
||||
|
||||
export * as ComponentAssertions from './components/Assertions';
|
||||
export * from './components/ActionRow';
|
||||
export * from './components/button/Button';
|
||||
export * from './components/Component';
|
||||
export * from './components/Components';
|
||||
export * from './components/textInput/TextInput';
|
||||
export * as TextInputAssertions from './components/textInput/Assertions';
|
||||
export * from './interactions/modals/Modal';
|
||||
export * as ModalAssertions from './interactions/modals/Assertions';
|
||||
export * from './components/selectMenu/SelectMenu';
|
||||
export * from './components/selectMenu/SelectMenuOption';
|
||||
export * as ComponentAssertions from './components/Assertions.js';
|
||||
export * from './components/ActionRow.js';
|
||||
export * from './components/button/Button.js';
|
||||
export * from './components/Component.js';
|
||||
export * from './components/Components.js';
|
||||
export * from './components/textInput/TextInput.js';
|
||||
export * as TextInputAssertions from './components/textInput/Assertions.js';
|
||||
export * from './interactions/modals/Modal.js';
|
||||
export * as ModalAssertions from './interactions/modals/Assertions.js';
|
||||
export * from './components/selectMenu/SelectMenu.js';
|
||||
export * from './components/selectMenu/SelectMenuOption.js';
|
||||
|
||||
export * as SlashCommandAssertions from './interactions/slashCommands/Assertions';
|
||||
export * from './interactions/slashCommands/SlashCommandBuilder';
|
||||
export * from './interactions/slashCommands/SlashCommandSubcommands';
|
||||
export * from './interactions/slashCommands/options/boolean';
|
||||
export * from './interactions/slashCommands/options/channel';
|
||||
export * from './interactions/slashCommands/options/integer';
|
||||
export * from './interactions/slashCommands/options/mentionable';
|
||||
export * from './interactions/slashCommands/options/number';
|
||||
export * from './interactions/slashCommands/options/role';
|
||||
export * from './interactions/slashCommands/options/attachment';
|
||||
export * from './interactions/slashCommands/options/string';
|
||||
export * from './interactions/slashCommands/options/user';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionBase';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';
|
||||
export * from './interactions/slashCommands/mixins/NameAndDescription';
|
||||
export * from './interactions/slashCommands/mixins/SharedSlashCommandOptions';
|
||||
export * as SlashCommandAssertions from './interactions/slashCommands/Assertions.js';
|
||||
export * from './interactions/slashCommands/SlashCommandBuilder.js';
|
||||
export * from './interactions/slashCommands/SlashCommandSubcommands.js';
|
||||
export * from './interactions/slashCommands/options/boolean.js';
|
||||
export * from './interactions/slashCommands/options/channel.js';
|
||||
export * from './interactions/slashCommands/options/integer.js';
|
||||
export * from './interactions/slashCommands/options/mentionable.js';
|
||||
export * from './interactions/slashCommands/options/number.js';
|
||||
export * from './interactions/slashCommands/options/role.js';
|
||||
export * from './interactions/slashCommands/options/attachment.js';
|
||||
export * from './interactions/slashCommands/options/string.js';
|
||||
export * from './interactions/slashCommands/options/user.js';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionBase.js';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.js';
|
||||
export * from './interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';
|
||||
export * from './interactions/slashCommands/mixins/NameAndDescription.js';
|
||||
export * from './interactions/slashCommands/mixins/SharedSlashCommandOptions.js';
|
||||
|
||||
export * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions';
|
||||
export * from './interactions/contextMenuCommands/ContextMenuCommandBuilder';
|
||||
export * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions.js';
|
||||
export * from './interactions/contextMenuCommands/ContextMenuCommandBuilder.js';
|
||||
|
||||
export * from './util/jsonEncodable';
|
||||
export * from './util/equatable';
|
||||
export * from './util/componentUtil';
|
||||
export * from './util/normalizeArray';
|
||||
export * from './util/validation';
|
||||
export * from './util/componentUtil.js';
|
||||
export * from './util/normalizeArray.js';
|
||||
export * from './util/validation.js';
|
||||
export * from '@discordjs/util';
|
||||
|
||||
/**
|
||||
* The [\@discordjs/builders](https://github.com/discordjs/discord.js/blob/main/packages/builders/#readme) version
|
||||
* that you are currently using.
|
||||
*
|
||||
* Note to developers: This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
||||
export const version: string = '[VI]{{inject}}[/VI]';
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { ApplicationCommandType } from 'discord-api-types/v10';
|
||||
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
|
||||
import { isValidationEnabled } from '../../util/validation';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder.js';
|
||||
|
||||
const namePredicate = s.string
|
||||
.lengthGreaterThanOrEqual(1)
|
||||
.lengthLessThanOrEqual(32)
|
||||
// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex
|
||||
.regex(/^( *[\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+ *)+$/u)
|
||||
.setValidationEnabled(isValidationEnabled);
|
||||
const typePredicate = s
|
||||
|
||||
@@ -3,8 +3,9 @@ import type {
|
||||
LocaleString,
|
||||
LocalizationMap,
|
||||
Permissions,
|
||||
RESTPostAPIApplicationCommandsJSONBody,
|
||||
RESTPostAPIContextMenuApplicationCommandsJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import { validateLocale, validateLocalizationMap } from '../slashCommands/Assertions.js';
|
||||
import {
|
||||
validateRequiredParameters,
|
||||
validateName,
|
||||
@@ -12,8 +13,7 @@ import {
|
||||
validateDefaultPermission,
|
||||
validateDefaultMemberPermissions,
|
||||
validateDMPermission,
|
||||
} from './Assertions';
|
||||
import { validateLocale, validateLocalizationMap } from '../slashCommands/Assertions';
|
||||
} from './Assertions.js';
|
||||
|
||||
export class ContextMenuCommandBuilder {
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ export class ContextMenuCommandBuilder {
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @deprecated This property is deprecated and will be removed in the future.
|
||||
* You should use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* You should use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
|
||||
*/
|
||||
public readonly default_permission: boolean | undefined = undefined;
|
||||
|
||||
@@ -81,12 +81,11 @@ export class ContextMenuCommandBuilder {
|
||||
/**
|
||||
* Sets whether the command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
* **Note**: If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
*
|
||||
* @remarks
|
||||
* If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
* @param value - Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
* @deprecated Use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
@@ -100,10 +99,9 @@ export class ContextMenuCommandBuilder {
|
||||
/**
|
||||
* Sets the default permissions a member should have in order to run the command.
|
||||
*
|
||||
* **Note:** You can set this to `'0'` to disable the command by default.
|
||||
*
|
||||
* @remarks
|
||||
* You can set this to `'0'` to disable the command by default.
|
||||
* @param permissions - The permissions bit field to set
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {
|
||||
@@ -120,7 +118,6 @@ export class ContextMenuCommandBuilder {
|
||||
* By default, commands are visible.
|
||||
*
|
||||
* @param enabled - If the command should be enabled in DMs
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDMPermission(enabled: boolean | null | undefined) {
|
||||
@@ -169,18 +166,19 @@ export class ContextMenuCommandBuilder {
|
||||
|
||||
Reflect.set(this, 'name_localizations', {});
|
||||
|
||||
Object.entries(localizedNames).forEach((args) =>
|
||||
this.setNameLocalization(...(args as [LocaleString, string | null])),
|
||||
);
|
||||
for (const args of Object.entries(localizedNames))
|
||||
this.setNameLocalization(...(args as [LocaleString, string | null]));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the final data that should be sent to Discord.
|
||||
*
|
||||
* **Note:** Calling this function will validate required properties based on their conditions.
|
||||
* @remarks
|
||||
* This method runs validations on the data before serializing it.
|
||||
* As such, it may throw an error if the data is invalid.
|
||||
*/
|
||||
public toJSON(): RESTPostAPIApplicationCommandsJSONBody {
|
||||
public toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody {
|
||||
validateRequiredParameters(this.name, this.type);
|
||||
|
||||
validateLocalizationMap(this.name_localizations);
|
||||
@@ -189,4 +187,4 @@ export class ContextMenuCommandBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
export type ContextMenuCommandType = ApplicationCommandType.User | ApplicationCommandType.Message;
|
||||
export type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow';
|
||||
import { customIdValidator } from '../../components/Assertions';
|
||||
import { isValidationEnabled } from '../../util/validation';
|
||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';
|
||||
import { customIdValidator } from '../../components/Assertions.js';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
|
||||
export const titleValidator = s.string
|
||||
.lengthGreaterThanOrEqual(1)
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
APIModalActionRowComponent,
|
||||
APIModalInteractionResponseCallbackData,
|
||||
} from 'discord-api-types/v10';
|
||||
import { titleValidator, validateRequiredParameters } from './Assertions';
|
||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow';
|
||||
import { customIdValidator } from '../../components/Assertions';
|
||||
import { createComponentBuilder } from '../../components/Components';
|
||||
import type { JSONEncodable } from '../../util/jsonEncodable';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray';
|
||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';
|
||||
import { customIdValidator } from '../../components/Assertions.js';
|
||||
import { createComponentBuilder } from '../../components/Components.js';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { titleValidator, validateRequiredParameters } from './Assertions.js';
|
||||
|
||||
export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {
|
||||
public readonly data: Partial<APIModalInteractionResponseCallbackData>;
|
||||
|
||||
public readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[] = [];
|
||||
|
||||
public constructor({ components, ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {
|
||||
this.data = { ...data };
|
||||
this.components = (components?.map((c) => createComponentBuilder(c)) ??
|
||||
this.components = (components?.map((component) => createComponentBuilder(component)) ??
|
||||
[]) as ActionRowBuilder<ModalActionRowComponentBuilder>[];
|
||||
}
|
||||
|
||||
@@ -70,9 +71,12 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIModalInteractionResponseCallbackData {
|
||||
validateRequiredParameters(this.data.custom_id, this.data.title, this.components);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
return {
|
||||
...this.data,
|
||||
components: this.components.map((component) => component.toJSON()),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { type APIApplicationCommandOptionChoice, Locale, LocalizationMap } from 'discord-api-types/v10';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
|
||||
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
||||
import { isValidationEnabled } from '../../util/validation';
|
||||
import { Locale, type APIApplicationCommandOptionChoice, type LocalizationMap } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';
|
||||
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';
|
||||
|
||||
const namePredicate = s.string
|
||||
.lengthGreaterThanOrEqual(1)
|
||||
|
||||
@@ -2,7 +2,7 @@ import type {
|
||||
APIApplicationCommandOption,
|
||||
LocalizationMap,
|
||||
Permissions,
|
||||
RESTPostAPIApplicationCommandsJSONBody,
|
||||
RESTPostAPIChatInputApplicationCommandsJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import { mix } from 'ts-mixer';
|
||||
import {
|
||||
@@ -13,10 +13,10 @@ import {
|
||||
validateDMPermission,
|
||||
validateMaxOptionsLength,
|
||||
validateRequiredParameters,
|
||||
} from './Assertions';
|
||||
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions';
|
||||
} from './Assertions.js';
|
||||
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';
|
||||
|
||||
@mix(SharedSlashCommandOptions, SharedNameAndDescription)
|
||||
export class SlashCommandBuilder {
|
||||
@@ -49,7 +49,7 @@ export class SlashCommandBuilder {
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @deprecated This property is deprecated and will be removed in the future.
|
||||
* You should use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* You should use {@link (SlashCommandBuilder:class).setDefaultMemberPermissions} or {@link (SlashCommandBuilder:class).setDMPermission} instead.
|
||||
*/
|
||||
public readonly default_permission: boolean | undefined = undefined;
|
||||
|
||||
@@ -67,9 +67,11 @@ export class SlashCommandBuilder {
|
||||
/**
|
||||
* Returns the final data that should be sent to Discord.
|
||||
*
|
||||
* **Note:** Calling this function will validate required properties based on their conditions.
|
||||
* @remarks
|
||||
* This method runs validations on the data before serializing it.
|
||||
* As such, it may throw an error if the data is invalid.
|
||||
*/
|
||||
public toJSON(): RESTPostAPIApplicationCommandsJSONBody {
|
||||
public toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
|
||||
validateRequiredParameters(this.name, this.description, this.options);
|
||||
|
||||
validateLocalizationMap(this.name_localizations);
|
||||
@@ -84,12 +86,11 @@ export class SlashCommandBuilder {
|
||||
/**
|
||||
* Sets whether the command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
* **Note**: If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
*
|
||||
* @remarks
|
||||
* If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
* @param value - Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
* @deprecated Use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* @deprecated Use {@link (SlashCommandBuilder:class).setDefaultMemberPermissions} or {@link (SlashCommandBuilder:class).setDMPermission} instead.
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
@@ -103,10 +104,9 @@ export class SlashCommandBuilder {
|
||||
/**
|
||||
* Sets the default permissions a member should have in order to run the command.
|
||||
*
|
||||
* **Note:** You can set this to `'0'` to disable the command by default.
|
||||
*
|
||||
* @remarks
|
||||
* You can set this to `'0'` to disable the command by default.
|
||||
* @param permissions - The permissions bit field to set
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {
|
||||
@@ -123,7 +123,6 @@ export class SlashCommandBuilder {
|
||||
* By default, commands are visible.
|
||||
*
|
||||
* @param enabled - If the command should be enabled in DMs
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDMPermission(enabled: boolean | null | undefined) {
|
||||
@@ -191,8 +190,7 @@ export class SlashCommandBuilder {
|
||||
export interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}
|
||||
|
||||
export interface SlashCommandSubcommandsOnlyBuilder
|
||||
extends SharedNameAndDescription,
|
||||
Pick<SlashCommandBuilder, 'toJSON' | 'addSubcommand' | 'addSubcommandGroup'> {}
|
||||
extends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> {}
|
||||
|
||||
export interface SlashCommandOptionsOnlyBuilder
|
||||
extends SharedNameAndDescription,
|
||||
@@ -200,5 +198,5 @@ export interface SlashCommandOptionsOnlyBuilder
|
||||
Pick<SlashCommandBuilder, 'toJSON'> {}
|
||||
|
||||
export interface ToAPIApplicationCommandOptions {
|
||||
toJSON: () => APIApplicationCommandOption;
|
||||
toJSON(): APIApplicationCommandOption;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {
|
||||
APIApplicationCommandSubcommandGroupOption,
|
||||
APIApplicationCommandSubcommandOption,
|
||||
ApplicationCommandOptionType,
|
||||
type APIApplicationCommandSubcommandGroupOption,
|
||||
type APIApplicationCommandSubcommandOption,
|
||||
} from 'discord-api-types/v10';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions';
|
||||
import { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions.js';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';
|
||||
|
||||
/**
|
||||
* Represents a folder for subcommands
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export abstract class ApplicationCommandNumericOptionMinMaxValueMixin {
|
||||
public readonly max_value?: number;
|
||||
|
||||
public readonly min_value?: number;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { APIApplicationCommandBasicOption, ApplicationCommandOptionType } from 'discord-api-types/v10';
|
||||
import { SharedNameAndDescription } from './NameAndDescription';
|
||||
import { validateRequiredParameters, validateRequired, validateLocalizationMap } from '../Assertions';
|
||||
import { validateRequiredParameters, validateRequired, validateLocalizationMap } from '../Assertions.js';
|
||||
import { SharedNameAndDescription } from './NameAndDescription.js';
|
||||
|
||||
export abstract class ApplicationCommandOptionBase extends SharedNameAndDescription {
|
||||
public abstract readonly type: ApplicationCommandOptionType;
|
||||
|
||||
@@ -6,11 +6,12 @@ const allowedChannelTypes = [
|
||||
ChannelType.GuildText,
|
||||
ChannelType.GuildVoice,
|
||||
ChannelType.GuildCategory,
|
||||
ChannelType.GuildNews,
|
||||
ChannelType.GuildNewsThread,
|
||||
ChannelType.GuildPublicThread,
|
||||
ChannelType.GuildPrivateThread,
|
||||
ChannelType.GuildAnnouncement,
|
||||
ChannelType.AnnouncementThread,
|
||||
ChannelType.PublicThread,
|
||||
ChannelType.PrivateThread,
|
||||
ChannelType.GuildStageVoice,
|
||||
ChannelType.GuildForum,
|
||||
] as const;
|
||||
|
||||
export type ApplicationCommandOptionAllowedChannelTypes = typeof allowedChannelTypes[number];
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user