mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-28 06:20:10 +00:00
Compare commits
92 Commits
14.1.2
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
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
|
||||||
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
|
|
||||||
4
.github/labeler.yml
vendored
4
.github/labeler.yml
vendored
@@ -1,7 +1,3 @@
|
|||||||
chore:
|
|
||||||
- any: ['*']
|
|
||||||
all: ['!packages/*', '!packages/**/*']
|
|
||||||
|
|
||||||
'packages:builders':
|
'packages:builders':
|
||||||
- packages/builders/*
|
- packages/builders/*
|
||||||
- packages/builders/**/*
|
- packages/builders/**/*
|
||||||
|
|||||||
29
.github/workflows/documentation.yml
vendored
29
.github/workflows/documentation.yml
vendored
@@ -3,8 +3,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- 'main'
|
||||||
- 'stable'
|
|
||||||
- '!docs'
|
|
||||||
tags:
|
tags:
|
||||||
- '**'
|
- '**'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -12,15 +10,28 @@ on:
|
|||||||
ref:
|
ref:
|
||||||
description: 'The branch, tag or SHA to checkout'
|
description: 'The branch, tag or SHA to checkout'
|
||||||
required: true
|
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:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build documentation
|
name: Build documentation
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.repository_owner == 'discordjs'
|
env:
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||||
outputs:
|
outputs:
|
||||||
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
|
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
|
||||||
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
|
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
|
||||||
SHA: ${{ steps.env.outputs.SHA }}
|
SHA: ${{ steps.env.outputs.SHA }}
|
||||||
|
if: github.repository_owner == 'discordjs'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -32,7 +43,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn --immutable
|
run: yarn --immutable
|
||||||
@@ -72,8 +82,10 @@ jobs:
|
|||||||
package: ['builders', 'collection', 'discord.js', 'proxy', 'rest', 'voice', 'ws']
|
package: ['builders', 'collection', 'discord.js', 'proxy', 'rest', 'voice', 'ws']
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||||
BRANCH_NAME: ${{ github.event.inputs.ref || needs.build.outputs.BRANCH_NAME }}
|
BRANCH_NAME: ${{ github.event.inputs.ref || needs.build.outputs.BRANCH_NAME }}
|
||||||
BRANCH_OR_TAG: ${{ needs.build.outputs.BRANCH_OR_TAG }}
|
BRANCH_OR_TAG: ${{ github.event.inputs.ref_type || needs.build.outputs.BRANCH_OR_TAG }}
|
||||||
SHA: ${{ needs.build.outputs.SHA }}
|
SHA: ${{ needs.build.outputs.SHA }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -84,7 +96,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn --immutable
|
run: yarn --immutable
|
||||||
@@ -112,14 +123,14 @@ jobs:
|
|||||||
path: 'out'
|
path: 'out'
|
||||||
|
|
||||||
- name: Extract package and semver from tag
|
- name: Extract package and semver from tag
|
||||||
if: ${{ github.event.inputs.ref || env.BRANCH_OR_TAG == 'tag' }}
|
if: ${{ github.event.inputs.ref_type == 'tag' || env.BRANCH_OR_TAG == 'tag' }}
|
||||||
id: extract-tag
|
id: extract-tag
|
||||||
uses: ./packages/actions/src/formatTag
|
uses: ./packages/actions/src/formatTag
|
||||||
with:
|
with:
|
||||||
tag: ${{ env.BRANCH_NAME }}
|
tag: ${{ env.BRANCH_NAME }}
|
||||||
|
|
||||||
- name: Move docs to correct directory
|
- name: Move docs to correct directory
|
||||||
if: ${{ (github.event.inputs.ref || env.BRANCH_OR_TAG == 'tag') && matrix.package == steps.extract-tag.outputs.package }}
|
if: ${{ (github.event.inputs.ref_type == 'tag' || env.BRANCH_OR_TAG == 'tag') && matrix.package == steps.extract-tag.outputs.package }}
|
||||||
env:
|
env:
|
||||||
PACKAGE: ${{ steps.extract-tag.outputs.package }}
|
PACKAGE: ${{ steps.extract-tag.outputs.package }}
|
||||||
SEMVER: ${{ steps.extract-tag.outputs.semver }}
|
SEMVER: ${{ steps.extract-tag.outputs.semver }}
|
||||||
@@ -131,7 +142,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Move docs to correct directory
|
- name: Move docs to correct directory
|
||||||
if: ${{ !github.event.inputs.ref && env.BRANCH_OR_TAG == 'branch' }}
|
if: ${{ github.event.inputs.ref_type == 'branch' || env.BRANCH_OR_TAG == 'branch' }}
|
||||||
env:
|
env:
|
||||||
PACKAGE: ${{ matrix.package }}
|
PACKAGE: ${{ matrix.package }}
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.github/workflows/npm-auto-deprecate.yml
vendored
3
.github/workflows/npm-auto-deprecate.yml
vendored
@@ -1,8 +1,8 @@
|
|||||||
name: npm auto deprecate
|
name: npm auto deprecate
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 1 * * *'
|
- cron: '0 1 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
npm-auto-deprecate:
|
npm-auto-deprecate:
|
||||||
name: npm auto deprecate
|
name: npm auto deprecate
|
||||||
@@ -17,7 +17,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn --immutable
|
run: yarn --immutable
|
||||||
|
|||||||
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
|
name: Publish dev docker images
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */12 * * *'
|
- cron: '0 */12 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
docker-publish:
|
docker-publish:
|
||||||
name: Docker publish
|
name: Docker publish
|
||||||
|
|||||||
6
.github/workflows/publish-dev.yml
vendored
6
.github/workflows/publish-dev.yml
vendored
@@ -1,8 +1,8 @@
|
|||||||
name: Publish dev
|
name: Publish dev
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */12 * * *'
|
- cron: '0 */12 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
npm-publish:
|
npm-publish:
|
||||||
name: npm publish
|
name: npm publish
|
||||||
@@ -25,6 +25,9 @@ jobs:
|
|||||||
- package: '@discordjs/ws'
|
- package: '@discordjs/ws'
|
||||||
folder: 'ws'
|
folder: 'ws'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||||
if: github.repository_owner == 'discordjs'
|
if: github.repository_owner == 'discordjs'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -36,7 +39,6 @@ jobs:
|
|||||||
node-version: 16
|
node-version: 16
|
||||||
registry-url: https://registry.npmjs.org/
|
registry-url: https://registry.npmjs.org/
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn --immutable
|
run: yarn --immutable
|
||||||
|
|||||||
16
.github/workflows/tests.yml
vendored
16
.github/workflows/tests.yml
vendored
@@ -1,9 +1,18 @@
|
|||||||
name: Tests
|
name: Tests
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
name: Tests
|
name: Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||||
|
NEXT_PUBLIC_LOCAL_DEV: true
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -13,10 +22,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn --immutable
|
run: yarn install --immutable
|
||||||
|
|
||||||
- name: Build dependencies
|
- name: Build dependencies
|
||||||
run: yarn build
|
run: yarn build
|
||||||
@@ -28,5 +36,5 @@ jobs:
|
|||||||
run: yarn test
|
run: yarn test
|
||||||
|
|
||||||
- name: Upload Coverage
|
- name: Upload Coverage
|
||||||
uses: ./packages/actions/src/uploadCoverage
|
|
||||||
if: github.repository_owner == 'discordjs'
|
if: github.repository_owner == 'discordjs'
|
||||||
|
uses: ./packages/actions/src/uploadCoverage
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"*": "prettier --ignore-unknown --write",
|
"*": "prettier --ignore-unknown --write",
|
||||||
"{src/**,__tests__/**}.{mjs,js,ts}": "eslint --ext mjs,js,ts --fix",
|
"{src/**,__tests__/**}.{mjs,js,ts}": "eslint --ext mjs,js,ts --fix",
|
||||||
"src/**.ts": "vitest related"
|
"src/**.ts": "vitest related --run"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -72,7 +72,7 @@ const rest = new REST({ version: '10' }).setToken('token');
|
|||||||
try {
|
try {
|
||||||
console.log('Started refreshing application (/) commands.');
|
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.');
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { relative, resolve } from 'node:path';
|
import { relative, resolve } from 'node:path';
|
||||||
import glob from 'fast-glob';
|
import glob from 'fast-glob';
|
||||||
|
import isCi from 'is-ci';
|
||||||
import typescript from 'rollup-plugin-typescript2';
|
import typescript from 'rollup-plugin-typescript2';
|
||||||
import { defineBuildConfig, BuildEntry } from 'unbuild';
|
import { defineBuildConfig, BuildEntry } from 'unbuild';
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ export function createUnbuildConfig({
|
|||||||
preserveModules = true,
|
preserveModules = true,
|
||||||
preserveModulesRoot = 'src',
|
preserveModulesRoot = 'src',
|
||||||
declaration = true,
|
declaration = true,
|
||||||
typeCheck = false,
|
typeCheck = isCi,
|
||||||
}: Partial<ConfigOptions> = {}) {
|
}: Partial<ConfigOptions> = {}) {
|
||||||
const files = glob
|
const files = glob
|
||||||
.sync('**', { cwd: 'src' })
|
.sync('**', { cwd: 'src' })
|
||||||
@@ -45,6 +46,7 @@ export function createUnbuildConfig({
|
|||||||
cjsBridge,
|
cjsBridge,
|
||||||
json: {
|
json: {
|
||||||
namedExports: false,
|
namedExports: false,
|
||||||
|
preferConst: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
27
package.json
27
package.json
@@ -4,13 +4,13 @@
|
|||||||
"description": "A powerful library for interacting with the Discord API",
|
"description": "A powerful library for interacting with the Discord API",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn workspaces foreach --parallel --topological run build",
|
"build": "turbo run build",
|
||||||
"test": "yarn workspaces foreach --parallel --topological run test",
|
"test": "turbo run test --parallel",
|
||||||
"lint": "yarn workspaces foreach --parallel --topological run lint",
|
"lint": "turbo run lint --parallel",
|
||||||
"format": "yarn workspaces foreach --parallel --topological run format",
|
"format": "turbo run format --parallel",
|
||||||
"fmt": "yarn format",
|
"fmt": "turbo run format --parallel",
|
||||||
"postinstall": "is-ci || husky install",
|
"postinstall": "is-ci || husky install",
|
||||||
"docs": "yarn workspaces foreach --parallel --topological run docs",
|
"docs": "turbo run docs --parallel",
|
||||||
"update": "yarn upgrade-interactive"
|
"update": "yarn upgrade-interactive"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -39,25 +39,18 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^17.0.3",
|
"@commitlint/cli": "^17.0.3",
|
||||||
"@commitlint/config-angular": "^17.0.3",
|
"@commitlint/config-angular": "^17.0.3",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@favware/npm-deprecate": "^1.0.4",
|
"@favware/npm-deprecate": "^1.0.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
"@types/is-ci": "^3.0.0",
|
||||||
"@typescript-eslint/parser": "^5.31.0",
|
|
||||||
"conventional-changelog-cli": "^2.2.2",
|
"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",
|
"fast-glob": "^3.2.11",
|
||||||
"husky": "^8.0.1",
|
"husky": "^8.0.1",
|
||||||
"is-ci": "^3.0.1",
|
"is-ci": "^3.0.1",
|
||||||
"lint-staged": "^13.0.3",
|
"lint-staged": "^13.0.3",
|
||||||
"prettier": "^2.7.1",
|
"turbo": "^1.4.3",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"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"
|
"@microsoft/tsdoc-config": "patch:@microsoft/tsdoc-config@npm:0.16.1#.yarn/patches/@microsoft-tsdoc-config-npm-0.16.1-81031b1bbf.patch"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
import { createUnbuildConfig } from '../../build.config';
|
import { createUnbuildConfig } from '../../build.config';
|
||||||
|
|
||||||
export default createUnbuildConfig({ minify: true, emitCJS: false });
|
export default createUnbuildConfig({
|
||||||
|
entries: [
|
||||||
|
{ builder: 'rollup', input: 'src/index' },
|
||||||
|
{ builder: 'rollup', input: 'src/formatTag/index' },
|
||||||
|
],
|
||||||
|
preserveModules: false,
|
||||||
|
minify: true,
|
||||||
|
emitCJS: false,
|
||||||
|
});
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format"
|
"fmt": "yarn format"
|
||||||
},
|
},
|
||||||
"main": "./dist/index.mjs",
|
"main": "./dist/index.mjs",
|
||||||
@@ -39,18 +39,24 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.9.0",
|
"@actions/core": "^1.9.1",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
"eslint": "^8.20.0",
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ outputs:
|
|||||||
description: 'The semver string that was extracted from this tag'
|
description: 'The semver string that was extracted from this tag'
|
||||||
runs:
|
runs:
|
||||||
using: node16
|
using: node16
|
||||||
main: ../../dist/formatTag/index.mjs
|
main: ../../dist/index.mjs
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../.eslintrc.json"
|
"extends": "../../.eslintrc.json",
|
||||||
|
"plugins": ["eslint-plugin-tsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"tsdoc/syntax": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"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 . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
@@ -55,24 +55,31 @@
|
|||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sapphire/shapeshift": "^3.5.1",
|
"@sapphire/shapeshift": "^3.5.1",
|
||||||
"discord-api-types": "^0.36.3",
|
"discord-api-types": "^0.37.3",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"ts-mixer": "^6.0.1",
|
"ts-mixer": "^6.0.1",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@microsoft/api-extractor": "^7.28.6",
|
"@microsoft/api-extractor": "^7.29.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
"downlevel-dts": "^0.10.0",
|
"downlevel-dts": "^0.10.0",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalAction
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an action row component
|
* Represents an action row component
|
||||||
|
*
|
||||||
|
* @typeParam T - The types of components this action row holds
|
||||||
*/
|
*/
|
||||||
export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<
|
export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<
|
||||||
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
||||||
@@ -56,6 +58,9 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
|
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export type AnyAPIActionRowComponent = APIActionRowComponentTypes | APIActionRow
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a discord component
|
* Represents a discord component
|
||||||
|
*
|
||||||
|
* @typeParam DataType - The type of internal API data that is stored within the component
|
||||||
*/
|
*/
|
||||||
export abstract class ComponentBuilder<
|
export abstract class ComponentBuilder<
|
||||||
DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,
|
DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,
|
||||||
@@ -20,6 +22,13 @@ export abstract class ComponentBuilder<
|
|||||||
*/
|
*/
|
||||||
public readonly data: Partial<DataType>;
|
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 abstract toJSON(): AnyAPIActionRowComponent;
|
||||||
|
|
||||||
public constructor(data: Partial<DataType>) {
|
public constructor(data: Partial<DataType>) {
|
||||||
|
|||||||
@@ -21,6 +21,35 @@ import { ComponentBuilder } from '../Component';
|
|||||||
* Represents a button component
|
* Represents a button component
|
||||||
*/
|
*/
|
||||||
export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
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({
|
||||||
|
* style: 'primary',
|
||||||
|
* label: 'Click Me',
|
||||||
|
* emoji: {
|
||||||
|
* name: ':smile:',
|
||||||
|
* id: '12345678901234567890123456789012',
|
||||||
|
* },
|
||||||
|
* custom_id: '12345678901234567890123456789012',
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Creating a button using setters and API data
|
||||||
|
* ```ts
|
||||||
|
* const button = new ButtonBuilder({
|
||||||
|
* style: 'primary',
|
||||||
|
* label: 'Click Me',
|
||||||
|
* })
|
||||||
|
* .setEmoji({ name: ':smile:', id: '12345678901234567890123456789012' })
|
||||||
|
* .setCustomId('12345678901234567890123456789012');
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public constructor(data?: Partial<APIButtonComponent>) {
|
public constructor(data?: Partial<APIButtonComponent>) {
|
||||||
super({ type: ComponentType.Button, ...data });
|
super({ type: ComponentType.Button, ...data });
|
||||||
}
|
}
|
||||||
@@ -38,6 +67,10 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||||||
/**
|
/**
|
||||||
* Sets the URL for this button
|
* 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
|
* @param url - The URL to open when this button is clicked
|
||||||
*/
|
*/
|
||||||
public setURL(url: string) {
|
public setURL(url: string) {
|
||||||
@@ -48,6 +81,9 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||||||
/**
|
/**
|
||||||
* Sets the custom id for this button
|
* 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
|
* @param customId - The custom id to use for this button
|
||||||
*/
|
*/
|
||||||
public setCustomId(customId: string) {
|
public setCustomId(customId: string) {
|
||||||
@@ -85,6 +121,9 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APIButtonComponent {
|
public toJSON(): APIButtonComponent {
|
||||||
validateRequiredButtonParameters(
|
validateRequiredButtonParameters(
|
||||||
this.data.style,
|
this.data.style,
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APISelectMenuComponent {
|
public toJSON(): APISelectMenuComponent {
|
||||||
validateRequiredSelectMenuParameters(this.options, this.data.custom_id);
|
validateRequiredSelectMenuParameters(this.options, this.data.custom_id);
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';
|
import type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';
|
||||||
|
import type { JSONEncodable } from '../../util/jsonEncodable';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
defaultValidator,
|
defaultValidator,
|
||||||
@@ -10,7 +11,7 @@ import {
|
|||||||
/**
|
/**
|
||||||
* Represents a option within a select menu component
|
* Represents a option within a select menu component
|
||||||
*/
|
*/
|
||||||
export class SelectMenuOptionBuilder {
|
export class SelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
|
||||||
public constructor(public data: Partial<APISelectMenuOption> = {}) {}
|
public constructor(public data: Partial<APISelectMenuOption> = {}) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +64,9 @@ export class SelectMenuOptionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APISelectMenuOption {
|
public toJSON(): APISelectMenuOption {
|
||||||
validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);
|
validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
|||||||
@@ -10,11 +10,15 @@ import {
|
|||||||
labelValidator,
|
labelValidator,
|
||||||
textInputStyleValidator,
|
textInputStyleValidator,
|
||||||
} from './Assertions';
|
} from './Assertions';
|
||||||
|
import type { Equatable } from '../../util/equatable';
|
||||||
import { isJSONEncodable, type JSONEncodable } from '../../util/jsonEncodable';
|
import { isJSONEncodable, type JSONEncodable } from '../../util/jsonEncodable';
|
||||||
import { customIdValidator } from '../Assertions';
|
import { customIdValidator } from '../Assertions';
|
||||||
import { ComponentBuilder } from '../Component';
|
import { ComponentBuilder } from '../Component';
|
||||||
|
|
||||||
export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
|
export class TextInputBuilder
|
||||||
|
extends ComponentBuilder<APITextInputComponent>
|
||||||
|
implements Equatable<JSONEncodable<APITextInputComponent> | APITextInputComponent>
|
||||||
|
{
|
||||||
public constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {
|
public constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {
|
||||||
super({ type: ComponentType.TextInput, ...data });
|
super({ type: ComponentType.TextInput, ...data });
|
||||||
}
|
}
|
||||||
@@ -99,6 +103,9 @@ export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APITextInputComponent {
|
public toJSON(): APITextInputComponent {
|
||||||
validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);
|
validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
@@ -107,6 +114,9 @@ export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
|
|||||||
} as APITextInputComponent;
|
} as APITextInputComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc Equatable.equals}
|
||||||
|
*/
|
||||||
public equals(other: JSONEncodable<APITextInputComponent> | APITextInputComponent): boolean {
|
public equals(other: JSONEncodable<APITextInputComponent> | APITextInputComponent): boolean {
|
||||||
if (isJSONEncodable(other)) {
|
if (isJSONEncodable(other)) {
|
||||||
return isEqual(other.toJSON(), this.data);
|
return isEqual(other.toJSON(), this.data);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class ContextMenuCommandBuilder {
|
|||||||
* Whether the command is enabled by default when the app is added to a guild
|
* 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.
|
* @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;
|
public readonly default_permission: boolean | undefined = undefined;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ export class ContextMenuCommandBuilder {
|
|||||||
* @param value - Whether or not to enable this command by default
|
* @param value - Whether or not to enable this command by default
|
||||||
*
|
*
|
||||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
* @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) {
|
public setDefaultPermission(value: boolean) {
|
||||||
// Assert the value matches the conditions
|
// Assert the value matches the conditions
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ComponentBuilder.toJSON}
|
||||||
|
*/
|
||||||
public toJSON(): APIModalInteractionResponseCallbackData {
|
public toJSON(): APIModalInteractionResponseCallbackData {
|
||||||
validateRequiredParameters(this.data.custom_id, this.data.title, this.components);
|
validateRequiredParameters(this.data.custom_id, this.data.title, this.components);
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export class SlashCommandBuilder {
|
|||||||
* Whether the command is enabled by default when the app is added to a guild
|
* 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.
|
* @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;
|
public readonly default_permission: boolean | undefined = undefined;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ export class SlashCommandBuilder {
|
|||||||
* @param value - Whether or not to enable this command by default
|
* @param value - Whether or not to enable this command by default
|
||||||
*
|
*
|
||||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
* @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) {
|
public setDefaultPermission(value: boolean) {
|
||||||
// Assert the value matches the conditions
|
// Assert the value matches the conditions
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export class SlashCommandIntegerOption
|
|||||||
{
|
{
|
||||||
public readonly type = ApplicationCommandOptionType.Integer as const;
|
public readonly type = ApplicationCommandOptionType.Integer as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
|
||||||
|
*/
|
||||||
public setMaxValue(max: number): this {
|
public setMaxValue(max: number): this {
|
||||||
numberValidator.parse(max);
|
numberValidator.parse(max);
|
||||||
|
|
||||||
@@ -22,6 +25,9 @@ export class SlashCommandIntegerOption
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
|
||||||
|
*/
|
||||||
public setMinValue(min: number): this {
|
public setMinValue(min: number): this {
|
||||||
numberValidator.parse(min);
|
numberValidator.parse(min);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export class SlashCommandNumberOption
|
|||||||
{
|
{
|
||||||
public readonly type = ApplicationCommandOptionType.Number as const;
|
public readonly type = ApplicationCommandOptionType.Number as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
|
||||||
|
*/
|
||||||
public setMaxValue(max: number): this {
|
public setMaxValue(max: number): this {
|
||||||
numberValidator.parse(max);
|
numberValidator.parse(max);
|
||||||
|
|
||||||
@@ -22,6 +25,9 @@ export class SlashCommandNumberOption
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
|
||||||
|
*/
|
||||||
public setMinValue(min: number): this {
|
public setMinValue(min: number): this {
|
||||||
numberValidator.parse(min);
|
numberValidator.parse(min);
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,31 @@ export class EmbedBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds fields to the embed (max 25)
|
* Appends fields to the embed
|
||||||
*
|
*
|
||||||
* @param fields The fields to add
|
* @remarks
|
||||||
|
* This method accepts either an array of fields or a variable number of field parameters.
|
||||||
|
* The maximum amount of fields that can be added is 25.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Using an array
|
||||||
|
* ```ts
|
||||||
|
* const fields: APIEmbedField[] = ...;
|
||||||
|
* const embed = new EmbedBuilder()
|
||||||
|
* .addFields(fields);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Using rest parameters (variadic)
|
||||||
|
* ```ts
|
||||||
|
* const embed = new EmbedBuilder()
|
||||||
|
* .addFields(
|
||||||
|
* { name: 'Field 1', value: 'Value 1' },
|
||||||
|
* { name: 'Field 2', value: 'Value 2' },
|
||||||
|
* );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param fields - The fields to add
|
||||||
*/
|
*/
|
||||||
public addFields(...fields: RestOrArray<APIEmbedField>): this {
|
public addFields(...fields: RestOrArray<APIEmbedField>): this {
|
||||||
fields = normalizeArray(fields);
|
fields = normalizeArray(fields);
|
||||||
@@ -70,11 +92,37 @@ export class EmbedBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes, replaces, or inserts fields in the embed (max 25)
|
* Removes, replaces, or inserts fields in the embed.
|
||||||
*
|
*
|
||||||
* @param index The index to start at
|
* @remarks
|
||||||
* @param deleteCount The number of fields to remove
|
* This method behaves similarly
|
||||||
* @param fields The replacing field objects
|
* to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice}.
|
||||||
|
* The maximum amount of fields that can be added is 25.
|
||||||
|
*
|
||||||
|
* It's useful for modifying and adjusting order of the already-existing fields of an embed.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Remove the first field
|
||||||
|
* ```ts
|
||||||
|
* embed.spliceFields(0, 1);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Remove the first n fields
|
||||||
|
* ```ts
|
||||||
|
* const n = 4
|
||||||
|
* embed.spliceFields(0, n);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Remove the last field
|
||||||
|
* ```ts
|
||||||
|
* embed.spliceFields(-1, 1);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param index - The index to start at
|
||||||
|
* @param deleteCount - The number of fields to remove
|
||||||
|
* @param fields - The replacing field objects
|
||||||
*/
|
*/
|
||||||
public spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {
|
public spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {
|
||||||
// Ensure adding these fields won't exceed the 25 field limit
|
// Ensure adding these fields won't exceed the 25 field limit
|
||||||
@@ -88,8 +136,15 @@ export class EmbedBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the embed's fields (max 25).
|
* Sets the embed's fields
|
||||||
* @param fields The fields to set
|
*
|
||||||
|
* @remarks
|
||||||
|
* This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically,
|
||||||
|
* it splices the entire array of fields, replacing them with the provided fields.
|
||||||
|
*
|
||||||
|
* You can set a maximum of 25 fields.
|
||||||
|
*
|
||||||
|
* @param fields - The fields to set
|
||||||
*/
|
*/
|
||||||
public setFields(...fields: RestOrArray<APIEmbedField>) {
|
public setFields(...fields: RestOrArray<APIEmbedField>) {
|
||||||
this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));
|
this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));
|
||||||
@@ -99,7 +154,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the author of this embed
|
* Sets the author of this embed
|
||||||
*
|
*
|
||||||
* @param options The options for the author
|
* @param options - The options for the author
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public setAuthor(options: EmbedAuthorOptions | null): this {
|
public setAuthor(options: EmbedAuthorOptions | null): this {
|
||||||
@@ -118,7 +173,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the color of this embed
|
* Sets the color of this embed
|
||||||
*
|
*
|
||||||
* @param color The color of the embed
|
* @param color - The color of the embed
|
||||||
*/
|
*/
|
||||||
public setColor(color: number | RGBTuple | null): this {
|
public setColor(color: number | RGBTuple | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -136,7 +191,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the description of this embed
|
* Sets the description of this embed
|
||||||
*
|
*
|
||||||
* @param description The description
|
* @param description - The description
|
||||||
*/
|
*/
|
||||||
public setDescription(description: string | null): this {
|
public setDescription(description: string | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -149,7 +204,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the footer of this embed
|
* Sets the footer of this embed
|
||||||
*
|
*
|
||||||
* @param options The options for the footer
|
* @param options - The options for the footer
|
||||||
*/
|
*/
|
||||||
public setFooter(options: EmbedFooterOptions | null): this {
|
public setFooter(options: EmbedFooterOptions | null): this {
|
||||||
if (options === null) {
|
if (options === null) {
|
||||||
@@ -167,7 +222,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the image of this embed
|
* Sets the image of this embed
|
||||||
*
|
*
|
||||||
* @param url The URL of the image
|
* @param url - The URL of the image
|
||||||
*/
|
*/
|
||||||
public setImage(url: string | null): this {
|
public setImage(url: string | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -180,7 +235,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the thumbnail of this embed
|
* Sets the thumbnail of this embed
|
||||||
*
|
*
|
||||||
* @param url The URL of the thumbnail
|
* @param url - The URL of the thumbnail
|
||||||
*/
|
*/
|
||||||
public setThumbnail(url: string | null): this {
|
public setThumbnail(url: string | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -193,7 +248,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the timestamp of this embed
|
* Sets the timestamp of this embed
|
||||||
*
|
*
|
||||||
* @param timestamp The timestamp or date
|
* @param timestamp - The timestamp or date
|
||||||
*/
|
*/
|
||||||
public setTimestamp(timestamp: number | Date | null = Date.now()): this {
|
public setTimestamp(timestamp: number | Date | null = Date.now()): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -206,7 +261,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the title of this embed
|
* Sets the title of this embed
|
||||||
*
|
*
|
||||||
* @param title The title
|
* @param title - The title
|
||||||
*/
|
*/
|
||||||
public setTitle(title: string | null): this {
|
public setTitle(title: string | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
@@ -219,7 +274,7 @@ export class EmbedBuilder {
|
|||||||
/**
|
/**
|
||||||
* Sets the URL of this embed
|
* Sets the URL of this embed
|
||||||
*
|
*
|
||||||
* @param url The URL
|
* @param url - The URL
|
||||||
*/
|
*/
|
||||||
public setURL(url: string | null): this {
|
public setURL(url: string | null): this {
|
||||||
// Data assertions
|
// Data assertions
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Represents a structure that can be checked against another
|
||||||
|
* given structure for equality
|
||||||
|
*
|
||||||
|
* @typeParam T - The type of object to compare the current object to
|
||||||
|
*/
|
||||||
export interface Equatable<T> {
|
export interface Equatable<T> {
|
||||||
/**
|
/**
|
||||||
* Whether or not this is equal to another structure
|
* Whether or not this is equal to another structure
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Represents an object capable of representing itself as a JSON object
|
||||||
|
*
|
||||||
|
* @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
|
||||||
|
*/
|
||||||
export interface JSONEncodable<T> {
|
export interface JSONEncodable<T> {
|
||||||
/**
|
/**
|
||||||
* Transforms this object to its JSON format
|
* Transforms this object to its JSON format
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../.eslintrc.json"
|
"extends": "../../.eslintrc.json",
|
||||||
|
"plugins": ["eslint-plugin-tsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"tsdoc/syntax": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"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 . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
@@ -51,17 +51,24 @@
|
|||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@microsoft/api-extractor": "^7.28.6",
|
"@microsoft/api-extractor": "^7.29.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
"downlevel-dts": "^0.10.0",
|
"downlevel-dts": "^0.10.0",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ export interface Collection<K, V> extends Map<K, V> {
|
|||||||
/**
|
/**
|
||||||
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
||||||
* an ID, for significantly improved performance and ease-of-use.
|
* an ID, for significantly improved performance and ease-of-use.
|
||||||
|
*
|
||||||
|
* @typeParam K - The key type this collection holds
|
||||||
|
* @typeParam V - The value type this collection holds
|
||||||
*/
|
*/
|
||||||
export class Collection<K, V> extends Map<K, V> {
|
export class Collection<K, V> extends Map<K, V> {
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +40,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param defaultValueGenerator - A function that generates the default value
|
* @param defaultValueGenerator - A function that generates the default value
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {
|
public ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {
|
||||||
if (this.has(key)) return this.get(key)!;
|
if (this.has(key)) return this.get(key)!;
|
||||||
@@ -230,7 +235,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.find(user => user.username === 'Bob');
|
* collection.find(user => user.username === 'Bob');
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
|
public find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
|
||||||
public find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
|
public find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
|
||||||
@@ -257,7 +264,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.findKey(user => user.username === 'Bob');
|
* collection.findKey(user => user.username === 'Bob');
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
|
public findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
|
||||||
public findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
|
public findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
|
||||||
@@ -304,7 +313,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.filter(user => user.username === 'Bob');
|
* collection.filter(user => user.username === 'Bob');
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;
|
public filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;
|
||||||
public filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;
|
public filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;
|
||||||
@@ -336,7 +347,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public partition<K2 extends K>(
|
public partition<K2 extends K>(
|
||||||
fn: (value: V, key: K, collection: this) => key is K2,
|
fn: (value: V, key: K, collection: this) => key is K2,
|
||||||
@@ -385,7 +398,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.flatMap(guild => guild.members.cache);
|
* collection.flatMap(guild => guild.members.cache);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
|
public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
|
||||||
public flatMap<T, This>(
|
public flatMap<T, This>(
|
||||||
@@ -405,7 +420,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.map(user => user.tag);
|
* collection.map(user => user.tag);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public map<T>(fn: (value: V, key: K, collection: this) => T): T[];
|
public map<T>(fn: (value: V, key: K, collection: this) => T): T[];
|
||||||
public map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
|
public map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
|
||||||
@@ -429,7 +446,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.mapValues(user => user.tag);
|
* collection.mapValues(user => user.tag);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
|
public mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
|
||||||
public mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
|
public mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
|
||||||
@@ -449,7 +468,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.some(user => user.discriminator === '0000');
|
* collection.some(user => user.discriminator === '0000');
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public some(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
public some(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
||||||
public some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
|
public some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
|
||||||
@@ -470,7 +491,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.every(user => !user.bot);
|
* collection.every(user => !user.bot);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;
|
public every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;
|
||||||
public every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;
|
public every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;
|
||||||
@@ -502,7 +525,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param initialValue - Starting value for the accumulator
|
* @param initialValue - Starting value for the accumulator
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {
|
public reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {
|
||||||
if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);
|
if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);
|
||||||
@@ -540,10 +565,12 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection
|
* collection
|
||||||
* .each(user => console.log(user.username))
|
* .each(user => console.log(user.username))
|
||||||
* .filter(user => user.bot)
|
* .filter(user => user.bot)
|
||||||
* .each(user => console.log(user.username));
|
* .each(user => console.log(user.username));
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public each(fn: (value: V, key: K, collection: this) => void): this;
|
public each(fn: (value: V, key: K, collection: this) => void): this;
|
||||||
public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
|
public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
|
||||||
@@ -560,10 +587,12 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param thisArg - Value to use as `this` when executing function
|
* @param thisArg - Value to use as `this` when executing function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection
|
* collection
|
||||||
* .tap(coll => console.log(coll.size))
|
* .tap(coll => console.log(coll.size))
|
||||||
* .filter(user => user.bot)
|
* .filter(user => user.bot)
|
||||||
* .tap(coll => console.log(coll.size))
|
* .tap(coll => console.log(coll.size))
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public tap(fn: (collection: this) => void): this;
|
public tap(fn: (collection: this) => void): this;
|
||||||
public tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
|
public tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
|
||||||
@@ -578,7 +607,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* Creates an identical shallow copy of this collection.
|
* Creates an identical shallow copy of this collection.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* const newColl = someColl.clone();
|
* const newColl = someColl.clone();
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public clone(): Collection<K, V> {
|
public clone(): Collection<K, V> {
|
||||||
return new this.constructor[Symbol.species](this);
|
return new this.constructor[Symbol.species](this);
|
||||||
@@ -590,7 +621,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param collections - Collections to merge
|
* @param collections - Collections to merge
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public concat(...collections: ReadonlyCollection<K, V>[]) {
|
public concat(...collections: ReadonlyCollection<K, V>[]) {
|
||||||
const newColl = this.clone();
|
const newColl = this.clone();
|
||||||
@@ -631,7 +664,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {
|
public sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {
|
||||||
const entries = [...this.entries()];
|
const entries = [...this.entries()];
|
||||||
@@ -686,6 +721,7 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* // Sums up the entries in two collections.
|
* // Sums up the entries in two collections.
|
||||||
* coll.merge(
|
* coll.merge(
|
||||||
* other,
|
* other,
|
||||||
@@ -693,8 +729,10 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* y => ({ keep: true, value: y }),
|
* y => ({ keep: true, value: y }),
|
||||||
* (x, y) => ({ keep: true, value: x + y }),
|
* (x, y) => ({ keep: true, value: x + y }),
|
||||||
* );
|
* );
|
||||||
|
* ```
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* // Intersects two collections in a left-biased manner.
|
* // Intersects two collections in a left-biased manner.
|
||||||
* coll.merge(
|
* coll.merge(
|
||||||
* other,
|
* other,
|
||||||
@@ -702,6 +740,7 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* y => ({ keep: false }),
|
* y => ({ keep: false }),
|
||||||
* (x, _) => ({ keep: true, value: x }),
|
* (x, _) => ({ keep: true, value: x }),
|
||||||
* );
|
* );
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public merge<T, R>(
|
public merge<T, R>(
|
||||||
other: ReadonlyCollection<K, T>,
|
other: ReadonlyCollection<K, T>,
|
||||||
@@ -739,7 +778,9 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* according to the string conversion of each element.
|
* according to the string conversion of each element.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {
|
public sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {
|
||||||
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
|
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
|
||||||
@@ -761,8 +802,10 @@ export class Collection<K, V> extends Map<K, V> {
|
|||||||
* @param combine - Function to combine an existing entry with a new one
|
* @param combine - Function to combine an existing entry with a new one
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* ```ts
|
||||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||||
* // returns Collection { "a" => 3, "b" => 2 }
|
* // returns Collection { "a" => 3, "b" => 2 }
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public static combineEntries<K, V>(
|
public static combineEntries<K, V>(
|
||||||
entries: Iterable<[K, V]>,
|
entries: Iterable<[K, V]>,
|
||||||
|
|||||||
@@ -2,6 +2,34 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
# [14.2.0](https://github.com/discordjs/discord.js/compare/14.1.2...14.2.0) - (2022-08-10)
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
- **ThreadChannel:** Handle possibly `null` parent (#8466) ([afa27b1](https://github.com/discordjs/discord.js/commit/afa27b15c5b92bc8d55b8285834d8e03f6692d06))
|
||||||
|
- Remove DM channels from `Client#messageDeleteBulk`'s types (#8460) ([6c6fe74](https://github.com/discordjs/discord.js/commit/6c6fe74dd84859c5319efa999404e8168f189710))
|
||||||
|
- **Transformers:** Do not transform `Date` objects (#8463) ([0e2a095](https://github.com/discordjs/discord.js/commit/0e2a09571c8e5ee61153b04e45334a226a1b4534))
|
||||||
|
- **ModalSubmitInteraction:** Allow deferUpdate (#8455) ([0fab869](https://github.com/discordjs/discord.js/commit/0fab869e5179dca7ddec75b5519615278e51ad82))
|
||||||
|
- **Guild:** Unable to fetch templates (#8420) ([aac8acc](https://github.com/discordjs/discord.js/commit/aac8acc22be7d7af99933ef099eca7deda43cb40))
|
||||||
|
- **MessageMentions:** Infinite loop in `parsedUsers` getter (#8430) ([b8a3136](https://github.com/discordjs/discord.js/commit/b8a31360a220e3d796f5381bd215d30a379ecb7c))
|
||||||
|
- **DataResolver:** Make `Buffer` from string (#8416) ([e72b986](https://github.com/discordjs/discord.js/commit/e72b986939e2958547c0e54d6d27472c8d111609))
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- Change registration example to use global commands (#8454) ([64a4041](https://github.com/discordjs/discord.js/commit/64a4041a05e9514334a9f9e1f38a1ea18bb676d5))
|
||||||
|
- **Colors:** Provide enum descriptions (#8437) ([6ef4754](https://github.com/discordjs/discord.js/commit/6ef4754d40c5ec65715fc1e00e643c52fe0a6209))
|
||||||
|
- **AttachmentBuilder:** Fix #8407 (#8421) ([5b053cf](https://github.com/discordjs/discord.js/commit/5b053cf82ec2f2b717a490485af052dc956fe3c9))
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Guild:** Add `max_video_channel_users` (#8423) ([3a96ce7](https://github.com/discordjs/discord.js/commit/3a96ce7970947f6268c21a1323d986aac8cb736d))
|
||||||
|
|
||||||
|
## Typings
|
||||||
|
|
||||||
|
- **Message:** Correct `bulkDelete` return type (#8465) ([c5b96a1](https://github.com/discordjs/discord.js/commit/c5b96a185cb8ba836b7cd10526c14059866f218f))
|
||||||
|
- Fix missing types for mentionable options (#8443) ([452e94f](https://github.com/discordjs/discord.js/commit/452e94fd3ecc12de9e3408982c5c7fd931bae634))
|
||||||
|
- **ApplicationCommandOption:** Add `ApplicationCommandBooleanOption` (#8434) ([38275fc](https://github.com/discordjs/discord.js/commit/38275fc53d633ce77ed2b142aff788dcbd4fad8c))
|
||||||
|
|
||||||
# [14.1.2](https://github.com/discordjs/discord.js/compare/14.1.1...14.1.2) - (2022-07-30)
|
# [14.1.2](https://github.com/discordjs/discord.js/compare/14.1.1...14.1.2) - (2022-07-30)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
@@ -67,7 +95,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
- 14.0.1 release bump, no new features.
|
- 14.0.1 release bump, no new features.
|
||||||
|
|
||||||
# [14.0.0](https://github.com/discordjs/discord.js/compare/13.9.2...14.0.0) - (2022-07-17)
|
# [14.0.0](https://github.com/discordjs/discord.js/compare/13.10.2...14.0.0) - (2022-07-17)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
||||||
@@ -473,6 +501,24 @@ All notable changes to this project will be documented in this file.
|
|||||||
- AssertType -> expectType ([3f36746](https://github.com/discordjs/discord.js/commit/3f36746561a40cd61a7cd2e054b7ef80d58fc707))
|
- AssertType -> expectType ([3f36746](https://github.com/discordjs/discord.js/commit/3f36746561a40cd61a7cd2e054b7ef80d58fc707))
|
||||||
- Fix cache types resolving to `never` (#7164) ([c978dbb](https://github.com/discordjs/discord.js/commit/c978dbb6233bcd85408caf0bca7619c9c5d508f0))
|
- Fix cache types resolving to `never` (#7164) ([c978dbb](https://github.com/discordjs/discord.js/commit/c978dbb6233bcd85408caf0bca7619c9c5d508f0))
|
||||||
|
|
||||||
|
# [13.10.2](https://github.com/discordjs/discord.js/compare/13.10.1...13.10.2) - (2022-08-10)
|
||||||
|
|
||||||
|
## Typings
|
||||||
|
|
||||||
|
- **Message:** Correct `bulkDelete` return type (v13) (#8469) ([03c59e3](https://github.com/discordjs/discord.js/commit/03c59e3a837edcaa428549c8387ef4d29e3ef6e4))
|
||||||
|
|
||||||
|
# [13.10.1](https://github.com/discordjs/discord.js/compare/13.10.0...13.10.1) - (2022-08-10)
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
- **ThreadChannel:** Handle possibly `null` parent (v13) (#8467) ([2a46d9f](https://github.com/discordjs/discord.js/commit/2a46d9f58e4714c8580218a3459992bbfec2bcf7))
|
||||||
|
|
||||||
|
# [13.10.0](https://github.com/discordjs/discord.js/compare/13.9.2...13.10.0) - (2022-08-08)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Guild:** Add `max_video_channel_users` (v13) (#8424) ([ae43bca](https://github.com/discordjs/discord.js/commit/ae43bca8b0afd8b90db7a1d99f67205b29338c2d))
|
||||||
|
|
||||||
# [13.9.2](https://github.com/discordjs/discord.js/compare/13.9.1...13.9.2) - (2022-07-29)
|
# [13.9.2](https://github.com/discordjs/discord.js/compare/13.9.1...13.9.2) - (2022-07-29)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ const rest = new REST({ version: '10' }).setToken('token');
|
|||||||
try {
|
try {
|
||||||
console.log('Started refreshing application (/) commands.');
|
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.');
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "14.1.2",
|
"version": "14.2.0",
|
||||||
"description": "A powerful library for interacting with the Discord API",
|
"description": "A powerful library for interacting with the Discord API",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "yarn docs:test && yarn test:typescript",
|
"test": "yarn docs:test && yarn test:typescript",
|
||||||
@@ -54,19 +54,19 @@
|
|||||||
"@discordjs/rest": "workspace:^",
|
"@discordjs/rest": "workspace:^",
|
||||||
"@sapphire/snowflake": "^3.2.2",
|
"@sapphire/snowflake": "^3.2.2",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
"discord-api-types": "^0.36.3",
|
"discord-api-types": "^0.37.3",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"lodash.snakecase": "^4.1.1",
|
"lodash.snakecase": "^4.1.1",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"undici": "^5.8.0",
|
"undici": "^5.9.1",
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"dtslint": "^4.2.1",
|
"dtslint": "^4.2.1",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
"jest": "^28.1.3",
|
"jest": "^28.1.3",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"tsd": "^0.22.0",
|
"tsd": "^0.22.0",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class MessageDeleteBulkAction extends Action {
|
|||||||
* Emitted whenever messages are deleted in bulk.
|
* Emitted whenever messages are deleted in bulk.
|
||||||
* @event Client#messageDeleteBulk
|
* @event Client#messageDeleteBulk
|
||||||
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
|
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
|
||||||
* @param {TextBasedChannels} channel The channel that the messages were deleted in
|
* @param {GuildTextBasedChannel} channel The channel that the messages were deleted in
|
||||||
*/
|
*/
|
||||||
if (messages.size > 0) client.emit(Events.MessageBulkDelete, messages, channel);
|
if (messages.size > 0) client.emit(Events.MessageBulkDelete, messages, channel);
|
||||||
return { messages };
|
return { messages };
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class GuildChannelManager extends CachedManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
|
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
|
||||||
* @property {GuildChannelResolvable} channel The channel to create the webhook for
|
* @property {TextChannel|NewsChannel|VoiceChannel|Snowflake} channel The channel to create the webhook for
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Buffer } = require('node:buffer');
|
|
||||||
const { setTimeout, clearTimeout } = require('node:timers');
|
const { setTimeout, clearTimeout } = require('node:timers');
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const { makeURLSearchParams } = require('@discordjs/rest');
|
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||||
@@ -128,8 +127,12 @@ class GuildMemberManager extends CachedManager {
|
|||||||
resolvedOptions.roles = resolvedRoles;
|
resolvedOptions.roles = resolvedRoles;
|
||||||
}
|
}
|
||||||
const data = await this.client.rest.put(Routes.guildMember(this.guild.id, userId), { body: resolvedOptions });
|
const data = await this.client.rest.put(Routes.guildMember(this.guild.id, userId), { body: resolvedOptions });
|
||||||
// Data is an empty buffer if the member is already part of the guild.
|
// Data is an empty Uint8Array if the member is already part of the guild.
|
||||||
return data instanceof Buffer ? (options.fetchWhenExisting === false ? null : this.fetch(userId)) : this._add(data);
|
return data instanceof Uint8Array
|
||||||
|
? options.fetchWhenExisting === false
|
||||||
|
? null
|
||||||
|
: this.fetch(userId)
|
||||||
|
: this._add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -441,6 +444,42 @@ class GuildMemberManager extends CachedManager {
|
|||||||
return this.guild.bans.remove(user, reason);
|
return this.guild.bans.remove(user, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options used for adding or removing a role from a member.
|
||||||
|
* @typedef {Object} AddOrRemoveGuildMemberRoleOptions
|
||||||
|
* @property {GuildMemberResolvable} user The user to add/remove the role from
|
||||||
|
* @property {RoleResolvable} role The role to add/remove
|
||||||
|
* @property {string} [reason] Reason for adding/removing the role
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a role to a member.
|
||||||
|
* @param {AddOrRemoveGuildMemberRoleOptions} options Options for adding the role
|
||||||
|
* @returns {Promise<GuildMember|User|Snowflake>}
|
||||||
|
*/
|
||||||
|
async addRole(options) {
|
||||||
|
const { user, role, reason } = options;
|
||||||
|
const userId = this.guild.members.resolveId(user);
|
||||||
|
const roleId = this.guild.roles.resolveId(role);
|
||||||
|
await this.client.rest.put(Routes.guildMemberRole(this.guild.id, userId, roleId), { reason });
|
||||||
|
|
||||||
|
return this.resolve(user) ?? this.client.users.resolve(user) ?? userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a role from a member.
|
||||||
|
* @param {AddOrRemoveGuildMemberRoleOptions} options Options for removing the role
|
||||||
|
* @returns {Promise<GuildMember|User|Snowflake>}
|
||||||
|
*/
|
||||||
|
async removeRole(options) {
|
||||||
|
const { user, role, reason } = options;
|
||||||
|
const userId = this.guild.members.resolveId(user);
|
||||||
|
const roleId = this.guild.roles.resolveId(role);
|
||||||
|
await this.client.rest.delete(Routes.guildMemberRole(this.guild.id, userId, roleId), { reason });
|
||||||
|
|
||||||
|
return this.resolve(user) ?? this.client.users.resolve(user) ?? userId;
|
||||||
|
}
|
||||||
|
|
||||||
async _fetchSingle({ user, cache, force = false }) {
|
async _fetchSingle({ user, cache, force = false }) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
const existing = this.cache.get(user);
|
const existing = this.cache.get(user);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { deprecate } = require('node:util');
|
||||||
const { isJSONEncodable } = require('@discordjs/builders');
|
const { isJSONEncodable } = require('@discordjs/builders');
|
||||||
const Component = require('./Component');
|
const Component = require('./Component');
|
||||||
const { createComponent } = require('../util/Components');
|
const { createComponent } = require('../util/Components');
|
||||||
@@ -24,6 +25,7 @@ class ActionRow extends Component {
|
|||||||
* Creates a new action row builder from JSON data
|
* Creates a new action row builder from JSON data
|
||||||
* @param {JSONEncodable<APIActionRowComponent>|APIActionRowComponent} other The other data
|
* @param {JSONEncodable<APIActionRowComponent>|APIActionRowComponent} other The other data
|
||||||
* @returns {ActionRowBuilder}
|
* @returns {ActionRowBuilder}
|
||||||
|
* @deprecated Use {@link ActionRowBuilder.from()} instead.
|
||||||
*/
|
*/
|
||||||
static from(other) {
|
static from(other) {
|
||||||
if (isJSONEncodable(other)) {
|
if (isJSONEncodable(other)) {
|
||||||
@@ -41,4 +43,6 @@ class ActionRow extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActionRow.from = deprecate(ActionRow.from, 'ActionRow.from() is deprecated. Use ActionRowBuilder.from() instead.');
|
||||||
|
|
||||||
module.exports = ActionRow;
|
module.exports = ActionRow;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const { basename, flatten } = require('../util/Util');
|
|||||||
class AttachmentBuilder {
|
class AttachmentBuilder {
|
||||||
/**
|
/**
|
||||||
* @param {BufferResolvable|Stream} attachment The file
|
* @param {BufferResolvable|Stream} attachment The file
|
||||||
* @param {APIAttachment} [data] Extra data
|
* @param {AttachmentData} [data] Extra data
|
||||||
*/
|
*/
|
||||||
constructor(attachment, data = {}) {
|
constructor(attachment, data = {}) {
|
||||||
/**
|
/**
|
||||||
@@ -108,3 +108,9 @@ module.exports = AttachmentBuilder;
|
|||||||
* @external APIAttachment
|
* @external APIAttachment
|
||||||
* @see {@link https://discord.com/developers/docs/resources/channel#attachment-object}
|
* @see {@link https://discord.com/developers/docs/resources/channel#attachment-object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} AttachmentData
|
||||||
|
* @property {string} [name] The name of the attachment
|
||||||
|
* @property {string} [description] The description of the attachment
|
||||||
|
*/
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ class Embed {
|
|||||||
get video() {
|
get video() {
|
||||||
if (!this.data.video) return null;
|
if (!this.data.video) return null;
|
||||||
return {
|
return {
|
||||||
url: this.data.image.url,
|
url: this.data.video.url,
|
||||||
proxyURL: this.data.image.proxy_url,
|
proxyURL: this.data.video.proxy_url,
|
||||||
height: this.data.image.height,
|
height: this.data.video.height,
|
||||||
width: this.data.image.width,
|
width: this.data.video.width,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,8 @@ class Guild extends AnonymousGuild {
|
|||||||
* @type {?boolean}
|
* @type {?boolean}
|
||||||
*/
|
*/
|
||||||
this.widgetEnabled = data.widget_enabled;
|
this.widgetEnabled = data.widget_enabled;
|
||||||
|
} else {
|
||||||
|
this.widgetEnabled ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('widget_channel_id' in data) {
|
if ('widget_channel_id' in data) {
|
||||||
@@ -224,6 +226,8 @@ class Guild extends AnonymousGuild {
|
|||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.widgetChannelId = data.widget_channel_id;
|
this.widgetChannelId = data.widget_channel_id;
|
||||||
|
} else {
|
||||||
|
this.widgetChannelId ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('explicit_content_filter' in data) {
|
if ('explicit_content_filter' in data) {
|
||||||
@@ -287,6 +291,16 @@ class Guild extends AnonymousGuild {
|
|||||||
this.maximumPresences ??= null;
|
this.maximumPresences ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('max_video_channel_users' in data) {
|
||||||
|
/**
|
||||||
|
* The maximum amount of users allowed in a video channel.
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.maxVideoChannelUsers = data.max_video_channel_users;
|
||||||
|
} else {
|
||||||
|
this.maxVideoChannelUsers ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
if ('approximate_member_count' in data) {
|
if ('approximate_member_count' in data) {
|
||||||
/**
|
/**
|
||||||
* The approximate amount of members the guild has
|
* The approximate amount of members the guild has
|
||||||
@@ -479,7 +493,7 @@ class Guild extends AnonymousGuild {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Widget channel for this guild
|
* Widget channel for this guild
|
||||||
* @type {?TextChannel}
|
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel)}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get widgetChannel() {
|
get widgetChannel() {
|
||||||
@@ -550,7 +564,7 @@ class Guild extends AnonymousGuild {
|
|||||||
* @returns {Promise<Collection<string, GuildTemplate>>}
|
* @returns {Promise<Collection<string, GuildTemplate>>}
|
||||||
*/
|
*/
|
||||||
async fetchTemplates() {
|
async fetchTemplates() {
|
||||||
const templates = await this.client.rest.get(Routes.guildTemplate(this.id));
|
const templates = await this.client.rest.get(Routes.guildTemplates(this.id));
|
||||||
return templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection());
|
return templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,14 +660,14 @@ class Guild extends AnonymousGuild {
|
|||||||
* Data for the Guild Widget Settings object
|
* Data for the Guild Widget Settings object
|
||||||
* @typedef {Object} GuildWidgetSettings
|
* @typedef {Object} GuildWidgetSettings
|
||||||
* @property {boolean} enabled Whether the widget is enabled
|
* @property {boolean} enabled Whether the widget is enabled
|
||||||
* @property {?GuildChannel} channel The widget invite channel
|
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel)} channel The widget invite channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Guild Widget Settings object
|
* The Guild Widget Settings object
|
||||||
* @typedef {Object} GuildWidgetSettingsData
|
* @typedef {Object} GuildWidgetSettingsData
|
||||||
* @property {boolean} enabled Whether the widget is enabled
|
* @property {boolean} enabled Whether the widget is enabled
|
||||||
* @property {?GuildChannelResolvable} channel The widget invite channel
|
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|Snowflake)} channel The widget invite channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class GuildAuditLogsEntry {
|
|||||||
this.actionType = GuildAuditLogsEntry.actionType(data.action_type);
|
this.actionType = GuildAuditLogsEntry.actionType(data.action_type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific action type of this entry in its string presentation
|
* The type of action that occured.
|
||||||
* @type {AuditLogEvent}
|
* @type {AuditLogEvent}
|
||||||
*/
|
*/
|
||||||
this.action = data.action_type;
|
this.action = data.action_type;
|
||||||
@@ -220,7 +220,6 @@ class GuildAuditLogsEntry {
|
|||||||
case AuditLogEvent.ApplicationCommandPermissionUpdate:
|
case AuditLogEvent.ApplicationCommandPermissionUpdate:
|
||||||
this.extra = {
|
this.extra = {
|
||||||
applicationId: data.options.application_id,
|
applicationId: data.options.application_id,
|
||||||
guild: guild.client.guilds.cache.get(data.options.guild_id) ?? { id: data.options.guild_id },
|
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ class MessageMentions {
|
|||||||
*/
|
*/
|
||||||
static GlobalChannelsPattern = new RegExp(this.ChannelsPattern.source, 'g');
|
static GlobalChannelsPattern = new RegExp(this.ChannelsPattern.source, 'g');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A global regular expression variant of {@link MessageMentions.UsersPattern}.
|
||||||
|
* @type {RegExp}
|
||||||
|
* @memberof MessageMentions
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
static GlobalUsersPattern = new RegExp(this.UsersPattern.source, 'g');
|
||||||
|
|
||||||
constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
|
constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
|
||||||
/**
|
/**
|
||||||
* The client the message is from
|
* The client the message is from
|
||||||
@@ -225,7 +233,7 @@ class MessageMentions {
|
|||||||
if (this._parsedUsers) return this._parsedUsers;
|
if (this._parsedUsers) return this._parsedUsers;
|
||||||
this._parsedUsers = new Collection();
|
this._parsedUsers = new Collection();
|
||||||
let matches;
|
let matches;
|
||||||
while ((matches = this.constructor.UsersPattern.exec(this._content)) !== null) {
|
while ((matches = this.constructor.GlobalUsersPattern.exec(this._content)) !== null) {
|
||||||
const user = this.client.users.cache.get(matches[1]);
|
const user = this.client.users.cache.get(matches[1]);
|
||||||
if (user) this._parsedUsers.set(user.id, user);
|
if (user) this._parsedUsers.set(user.id, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,10 +283,11 @@ class ThreadChannel extends BaseChannel {
|
|||||||
* <info>This only works when the thread started from a message in the parent channel, otherwise the promise will
|
* <info>This only works when the thread started from a message in the parent channel, otherwise the promise will
|
||||||
* reject. If you just need the id of that message, use {@link ThreadChannel#id} instead.</info>
|
* reject. If you just need the id of that message, use {@link ThreadChannel#id} instead.</info>
|
||||||
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
||||||
* @returns {Promise<Message>}
|
* @returns {Promise<Message|null>}
|
||||||
*/
|
*/
|
||||||
fetchStarterMessage(options) {
|
// eslint-disable-next-line require-await
|
||||||
return this.parent.messages.fetch({ message: this.id, ...options });
|
async fetchStarterMessage(options) {
|
||||||
|
return this.parent?.messages.fetch({ message: this.id, ...options }) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class InteractionResponses {
|
|||||||
});
|
});
|
||||||
this.deferred = true;
|
this.deferred = true;
|
||||||
|
|
||||||
return options.fetchReply ? this.fetchReply() : new InteractionResponse(this, this.message.interaction?.id);
|
return options.fetchReply ? this.fetchReply() : new InteractionResponse(this, this.message?.interaction?.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,7 +255,7 @@ class InteractionResponses {
|
|||||||
* An object containing the same properties as {@link CollectorOptions}, but a few less:
|
* An object containing the same properties as {@link CollectorOptions}, but a few less:
|
||||||
* @typedef {Object} AwaitModalSubmitOptions
|
* @typedef {Object} AwaitModalSubmitOptions
|
||||||
* @property {CollectorFilter} [filter] The filter applied to this collector
|
* @property {CollectorFilter} [filter] The filter applied to this collector
|
||||||
* @property {number} time Time to wait for an interaction before rejecting
|
* @property {number} time Time in milliseconds to wait for an interaction before rejecting
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ class TextBasedChannel {
|
|||||||
* @param {Collection<Snowflake, Message>|MessageResolvable[]|number} messages
|
* @param {Collection<Snowflake, Message>|MessageResolvable[]|number} messages
|
||||||
* Messages or number of messages to delete
|
* Messages or number of messages to delete
|
||||||
* @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically
|
* @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically
|
||||||
* @returns {Promise<Collection<Snowflake, Message>>} Returns the deleted messages
|
* @returns {Promise<Collection<Snowflake, Message|undefined>>} Returns the deleted messages
|
||||||
* @example
|
* @example
|
||||||
* // Bulk delete messages
|
* // Bulk delete messages
|
||||||
* channel.bulkDelete(5)
|
* channel.bulkDelete(5)
|
||||||
|
|||||||
@@ -2,36 +2,36 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Colors
|
* @typedef {Object} Colors
|
||||||
* @property {number} Default
|
* @property {number} Default 0x000000 | rgb(0,0,0)
|
||||||
* @property {number} White
|
* @property {number} White 0xFFFFFF | rgb(255,255,255)
|
||||||
* @property {number} Aqua
|
* @property {number} Aqua 0x1ABC9C | rgb(26,188,156)
|
||||||
* @property {number} Green
|
* @property {number} Green 0x57F287 | rgb(87,242,135)
|
||||||
* @property {number} Blue
|
* @property {number} Blue 0x3498DB | rgb(52,152,219)
|
||||||
* @property {number} Yellow
|
* @property {number} Yellow 0xFEE75C | rgb(254,231,92)
|
||||||
* @property {number} Purple
|
* @property {number} Purple 0x9B59B6 | rgb(155,89,182)
|
||||||
* @property {number} LuminousVividPink
|
* @property {number} LuminousVividPink 0xE91E63 | rgb(233,30,99)
|
||||||
* @property {number} Fuchsia
|
* @property {number} Fuchsia 0xEB459E | rgb(235,69,158)
|
||||||
* @property {number} Gold
|
* @property {number} Gold 0xF1C40F | rgb(241,196,15)
|
||||||
* @property {number} Orange
|
* @property {number} Orange 0xE67E22 | rgb(230,126,34)
|
||||||
* @property {number} Red
|
* @property {number} Red 0xED4245 | rgb(237,66,69)
|
||||||
* @property {number} Grey
|
* @property {number} Grey 0x95A5A6 | rgb(149,165,166)
|
||||||
* @property {number} Navy
|
* @property {number} Navy 0x34495E | rgb(52,73,94)
|
||||||
* @property {number} DarkAqua
|
* @property {number} DarkAqua 0x11806A | rgb(17,128,106)
|
||||||
* @property {number} DarkGreen
|
* @property {number} DarkGreen 0x1F8B4C | rgb(31,139,76)
|
||||||
* @property {number} DarkBlue
|
* @property {number} DarkBlue 0x206694 | rgb(32,102,148)
|
||||||
* @property {number} DarkPurple
|
* @property {number} DarkPurple 0x71368A | rgb(113,54,138)
|
||||||
* @property {number} DarkVividPink
|
* @property {number} DarkVividPink 0xAD1457 | rgb(173,20,87)
|
||||||
* @property {number} DarkGold
|
* @property {number} DarkGold 0xC27C0E | rgb(194,124,14)
|
||||||
* @property {number} DarkOrange
|
* @property {number} DarkOrange 0xA84300 | rgb(168,67,0)
|
||||||
* @property {number} DarkRed
|
* @property {number} DarkRed 0x992D22 | rgb(153,45,34)
|
||||||
* @property {number} DarkGrey
|
* @property {number} DarkGrey 0x979C9F | rgb(151,156,159)
|
||||||
* @property {number} DarkerGrey
|
* @property {number} DarkerGrey 0x7F8C8D | rgb(127,140,141)
|
||||||
* @property {number} LightGrey
|
* @property {number} LightGrey 0xBCC0C0 | rgb(188,192,192)
|
||||||
* @property {number} DarkNavy
|
* @property {number} DarkNavy 0x2C3E50 | rgb(44,62,80)
|
||||||
* @property {number} Blurple
|
* @property {number} Blurple 0x5865F2 | rgb(88,101,242)
|
||||||
* @property {number} Greyple
|
* @property {number} Greyple 0x99AAb5 | rgb(153,170,181)
|
||||||
* @property {number} DarkButNotBlack
|
* @property {number} DarkButNotBlack 0x2C2F33 | rgb(44,47,51)
|
||||||
* @property {number} NotQuiteBlack
|
* @property {number} NotQuiteBlack 0x23272A | rgb(35,39,42)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// JSDoc for IntelliSense purposes
|
// JSDoc for IntelliSense purposes
|
||||||
|
|||||||
@@ -53,13 +53,19 @@ exports.NonSystemMessageTypes = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channels that are text-based.
|
* The guild channels that are text-based.
|
||||||
* * DMChannel
|
|
||||||
* * TextChannel
|
* * TextChannel
|
||||||
* * NewsChannel
|
* * NewsChannel
|
||||||
* * ThreadChannel
|
* * ThreadChannel
|
||||||
* * VoiceChannel
|
* * VoiceChannel
|
||||||
* @typedef {DMChannel|TextChannel|NewsChannel|ThreadChannel|VoiceChannel} TextBasedChannels
|
* @typedef {TextChannel|NewsChannel|ThreadChannel|VoiceChannel} GuildTextBasedChannel
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The channels that are text-based.
|
||||||
|
* * DMChannel
|
||||||
|
* * GuildTextBasedChannel
|
||||||
|
* @typedef {DMChannel|GuildTextBasedChannel} TextBasedChannels
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class DataResolver extends null {
|
|||||||
|
|
||||||
if (typeof resource[Symbol.asyncIterator] === 'function') {
|
if (typeof resource[Symbol.asyncIterator] === 'function') {
|
||||||
const buffers = [];
|
const buffers = [];
|
||||||
for await (const data of resource) buffers.push(data);
|
for await (const data of resource) buffers.push(Buffer.from(data));
|
||||||
return { data: Buffer.concat(buffers) };
|
return { data: Buffer.concat(buffers) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const snakeCase = require('lodash.snakecase');
|
|||||||
*/
|
*/
|
||||||
function toSnakeCase(obj) {
|
function toSnakeCase(obj) {
|
||||||
if (typeof obj !== 'object' || !obj) return obj;
|
if (typeof obj !== 'object' || !obj) return obj;
|
||||||
|
if (obj instanceof Date) return obj;
|
||||||
if (Array.isArray(obj)) return obj.map(toSnakeCase);
|
if (Array.isArray(obj)) return obj.map(toSnakeCase);
|
||||||
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
|
||||||
}
|
}
|
||||||
|
|||||||
172
packages/discord.js/typings/index.d.ts
vendored
172
packages/discord.js/typings/index.d.ts
vendored
@@ -192,7 +192,10 @@ declare module 'node:events' {
|
|||||||
class EventEmitter {
|
class EventEmitter {
|
||||||
// Add type overloads for client events.
|
// Add type overloads for client events.
|
||||||
public static once<K extends keyof ClientEvents>(eventEmitter: Client, eventName: K): Promise<ClientEvents[K]>;
|
public static once<K extends keyof ClientEvents>(eventEmitter: Client, eventName: K): Promise<ClientEvents[K]>;
|
||||||
public static on<K extends keyof ClientEvents>(eventEmitter: Client, eventName: K): AsyncIterator<ClientEvents[K]>;
|
public static on<K extends keyof ClientEvents>(
|
||||||
|
eventEmitter: Client,
|
||||||
|
eventName: K,
|
||||||
|
): AsyncIterableIterator<ClientEvents[K]>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1083,6 +1086,7 @@ export class Guild extends AnonymousGuild {
|
|||||||
public afkChannelId: Snowflake | null;
|
public afkChannelId: Snowflake | null;
|
||||||
public afkTimeout: number;
|
public afkTimeout: number;
|
||||||
public applicationId: Snowflake | null;
|
public applicationId: Snowflake | null;
|
||||||
|
public maxVideoChannelUsers: number | null;
|
||||||
public approximateMemberCount: number | null;
|
public approximateMemberCount: number | null;
|
||||||
public approximatePresenceCount: number | null;
|
public approximatePresenceCount: number | null;
|
||||||
public available: boolean;
|
public available: boolean;
|
||||||
@@ -1123,7 +1127,7 @@ export class Guild extends AnonymousGuild {
|
|||||||
public vanityURLUses: number | null;
|
public vanityURLUses: number | null;
|
||||||
public get voiceAdapterCreator(): InternalDiscordGatewayAdapterCreator;
|
public get voiceAdapterCreator(): InternalDiscordGatewayAdapterCreator;
|
||||||
public voiceStates: VoiceStateManager;
|
public voiceStates: VoiceStateManager;
|
||||||
public get widgetChannel(): TextChannel | null;
|
public get widgetChannel(): TextChannel | NewsChannel | VoiceBasedChannel | null;
|
||||||
public widgetChannelId: Snowflake | null;
|
public widgetChannelId: Snowflake | null;
|
||||||
public widgetEnabled: boolean | null;
|
public widgetEnabled: boolean | null;
|
||||||
public get maximumBitrate(): number;
|
public get maximumBitrate(): number;
|
||||||
@@ -1177,35 +1181,37 @@ export class Guild extends AnonymousGuild {
|
|||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = null> {
|
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = AuditLogEvent> {
|
||||||
private constructor(guild: Guild, data: RawGuildAuditLogData);
|
private constructor(guild: Guild, data: RawGuildAuditLogData);
|
||||||
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
|
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
|
||||||
private webhooks: Collection<Snowflake, Webhook>;
|
private webhooks: Collection<Snowflake, Webhook>;
|
||||||
private integrations: Collection<Snowflake | string, Integration>;
|
private integrations: Collection<Snowflake | string, Integration>;
|
||||||
private guildScheduledEvents: Collection<Snowflake, GuildScheduledEvent>;
|
private guildScheduledEvents: Collection<Snowflake, GuildScheduledEvent>;
|
||||||
public entries: Collection<Snowflake, GuildAuditLogsEntry<T>>;
|
public entries: Collection<Snowflake, GuildAuditLogsEntry<T>>;
|
||||||
public static Entry: typeof GuildAuditLogsEntry;
|
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildAuditLogsEntry<
|
export class GuildAuditLogsEntry<
|
||||||
TAction extends GuildAuditLogsResolvable = null,
|
TAction extends GuildAuditLogsResolvable = AuditLogEvent,
|
||||||
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
|
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
|
||||||
? GuildAuditLogsTypes[TAction][1]
|
? GuildAuditLogsTypes[TAction][1]
|
||||||
: 'All',
|
: GuildAuditLogsActionType,
|
||||||
TTargetType extends GuildAuditLogsTargetType = TAction extends keyof GuildAuditLogsTypes
|
TTargetType extends GuildAuditLogsTargetType = TAction extends keyof GuildAuditLogsTypes
|
||||||
? GuildAuditLogsTypes[TAction][0]
|
? GuildAuditLogsTypes[TAction][0]
|
||||||
: 'Unknown',
|
: GuildAuditLogsTargetType,
|
||||||
|
TResolvedType = TAction extends null ? AuditLogEvent : TAction,
|
||||||
> {
|
> {
|
||||||
private constructor(logs: GuildAuditLogs, guild: Guild, data: RawGuildAuditLogEntryData);
|
private constructor(logs: GuildAuditLogs, guild: Guild, data: RawGuildAuditLogEntryData);
|
||||||
public static Targets: GuildAuditLogsTargets;
|
public static Targets: GuildAuditLogsTargets;
|
||||||
public action: TAction;
|
public action: TResolvedType;
|
||||||
public actionType: TActionType;
|
public actionType: TActionType;
|
||||||
public changes: AuditLogChange[];
|
public changes: AuditLogChange[];
|
||||||
public get createdAt(): Date;
|
public get createdAt(): Date;
|
||||||
public get createdTimestamp(): number;
|
public get createdTimestamp(): number;
|
||||||
public executor: User | null;
|
public executor: User | null;
|
||||||
public extra: TAction extends keyof GuildAuditLogsEntryExtraField ? GuildAuditLogsEntryExtraField[TAction] : null;
|
public extra: TResolvedType extends keyof GuildAuditLogsEntryExtraField
|
||||||
|
? GuildAuditLogsEntryExtraField[TResolvedType]
|
||||||
|
: null;
|
||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
public reason: string | null;
|
public reason: string | null;
|
||||||
public target: TTargetType extends keyof GuildAuditLogsEntryTargetField<TActionType>
|
public target: TTargetType extends keyof GuildAuditLogsEntryTargetField<TActionType>
|
||||||
@@ -1880,8 +1886,9 @@ export class MessageMentions {
|
|||||||
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;
|
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
|
|
||||||
public static ChannelsPattern: typeof FormattingPatterns.Channel;
|
|
||||||
private static GlobalChannelsPattern: RegExp;
|
private static GlobalChannelsPattern: RegExp;
|
||||||
|
private static GlobalUsersPattern: RegExp;
|
||||||
|
public static ChannelsPattern: typeof FormattingPatterns.Channel;
|
||||||
public static EveryonePattern: RegExp;
|
public static EveryonePattern: RegExp;
|
||||||
public static RolesPattern: typeof FormattingPatterns.Role;
|
public static RolesPattern: typeof FormattingPatterns.Role;
|
||||||
public static UsersPattern: typeof FormattingPatterns.User;
|
public static UsersPattern: typeof FormattingPatterns.User;
|
||||||
@@ -1968,12 +1975,11 @@ export class ModalSubmitFields {
|
|||||||
export interface ModalMessageModalSubmitInteraction<Cached extends CacheType = CacheType>
|
export interface ModalMessageModalSubmitInteraction<Cached extends CacheType = CacheType>
|
||||||
extends ModalSubmitInteraction<Cached> {
|
extends ModalSubmitInteraction<Cached> {
|
||||||
message: Message<BooleanCache<Cached>>;
|
message: Message<BooleanCache<Cached>>;
|
||||||
|
channelId: Snowflake;
|
||||||
update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<Message>;
|
update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<Message>;
|
||||||
update(
|
update(
|
||||||
options: string | MessagePayload | InteractionUpdateOptions,
|
options: string | MessagePayload | InteractionUpdateOptions,
|
||||||
): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
||||||
deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message>;
|
|
||||||
deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
|
||||||
inGuild(): this is ModalMessageModalSubmitInteraction<'raw' | 'cached'>;
|
inGuild(): this is ModalMessageModalSubmitInteraction<'raw' | 'cached'>;
|
||||||
inCachedGuild(): this is ModalMessageModalSubmitInteraction<'cached'>;
|
inCachedGuild(): this is ModalMessageModalSubmitInteraction<'cached'>;
|
||||||
inRawGuild(): this is ModalMessageModalSubmitInteraction<'raw'>;
|
inRawGuild(): this is ModalMessageModalSubmitInteraction<'raw'>;
|
||||||
@@ -2004,6 +2010,8 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
|
|||||||
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
||||||
public fetchReply(): Promise<Message<BooleanCache<Cached>>>;
|
public fetchReply(): Promise<Message<BooleanCache<Cached>>>;
|
||||||
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
|
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
|
||||||
|
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message>;
|
||||||
|
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
||||||
public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>;
|
public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is ModalSubmitInteraction<'cached'>;
|
public inCachedGuild(): this is ModalSubmitInteraction<'cached'>;
|
||||||
public inRawGuild(): this is ModalSubmitInteraction<'raw'>;
|
public inRawGuild(): this is ModalSubmitInteraction<'raw'>;
|
||||||
@@ -2538,7 +2546,7 @@ export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, ['fetchWeb
|
|||||||
checkAdmin?: boolean,
|
checkAdmin?: boolean,
|
||||||
): Readonly<PermissionsBitField> | null;
|
): Readonly<PermissionsBitField> | null;
|
||||||
public fetchOwner(options?: BaseFetchOptions): Promise<ThreadMember | null>;
|
public fetchOwner(options?: BaseFetchOptions): Promise<ThreadMember | null>;
|
||||||
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
|
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message | null>;
|
||||||
public setArchived(archived?: boolean, reason?: string): Promise<AnyThreadChannel>;
|
public setArchived(archived?: boolean, reason?: string): Promise<AnyThreadChannel>;
|
||||||
public setAutoArchiveDuration(
|
public setAutoArchiveDuration(
|
||||||
autoArchiveDuration: ThreadAutoArchiveDuration,
|
autoArchiveDuration: ThreadAutoArchiveDuration,
|
||||||
@@ -3404,6 +3412,12 @@ export class GuildManager extends CachedManager<Snowflake, Guild, GuildResolvabl
|
|||||||
public fetch(options?: FetchGuildsOptions): Promise<Collection<Snowflake, OAuth2Guild>>;
|
public fetch(options?: FetchGuildsOptions): Promise<Collection<Snowflake, OAuth2Guild>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AddOrRemoveGuildMemberRoleOptions {
|
||||||
|
user: GuildMemberResolvable;
|
||||||
|
role: RoleResolvable;
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable> {
|
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable> {
|
||||||
private constructor(guild: Guild, iterable?: Iterable<RawGuildMemberData>);
|
private constructor(guild: Guild, iterable?: Iterable<RawGuildMemberData>);
|
||||||
public guild: Guild;
|
public guild: Guild;
|
||||||
@@ -3426,6 +3440,8 @@ export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, Gu
|
|||||||
public prune(options?: GuildPruneMembersOptions): Promise<number>;
|
public prune(options?: GuildPruneMembersOptions): Promise<number>;
|
||||||
public search(options: GuildSearchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
|
public search(options: GuildSearchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
|
||||||
public unban(user: UserResolvable, reason?: string): Promise<User | null>;
|
public unban(user: UserResolvable, reason?: string): Promise<User | null>;
|
||||||
|
public addRole(options: AddOrRemoveGuildMemberRoleOptions): Promise<GuildMember | User | Snowflake>;
|
||||||
|
public removeRole(options: AddOrRemoveGuildMemberRoleOptions): Promise<GuildMember | User | Snowflake>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBanResolvable> {
|
export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBanResolvable> {
|
||||||
@@ -3656,7 +3672,7 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
|
|||||||
bulkDelete(
|
bulkDelete(
|
||||||
messages: Collection<Snowflake, Message> | readonly MessageResolvable[] | number,
|
messages: Collection<Snowflake, Message> | readonly MessageResolvable[] | number,
|
||||||
filterOld?: boolean,
|
filterOld?: boolean,
|
||||||
): Promise<Collection<Snowflake, Message>>;
|
): Promise<Collection<Snowflake, Message | PartialMessage | undefined>>;
|
||||||
createMessageComponentCollector<T extends MessageComponentType>(
|
createMessageComponentCollector<T extends MessageComponentType>(
|
||||||
options?: MessageChannelCollectorOptionsParams<T, true>,
|
options?: MessageChannelCollectorOptionsParams<T, true>,
|
||||||
): InteractionCollector<MappedInteractionTypes[T]>;
|
): InteractionCollector<MappedInteractionTypes[T]>;
|
||||||
@@ -3793,31 +3809,85 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
|
|||||||
channelTypes?: ChannelType[];
|
channelTypes?: ChannelType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandRoleOptionData extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Role;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandRoleOption extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Role;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandUserOptionData extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandUserOption extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandMentionableOptionData extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Mentionable;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandMentionableOption extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Mentionable;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandAttachmentOption extends BaseApplicationCommandOptionsData {
|
export interface ApplicationCommandAttachmentOption extends BaseApplicationCommandOptionsData {
|
||||||
type: ApplicationCommandOptionType.Attachment;
|
type: ApplicationCommandOptionType.Attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandAutocompleteOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
export interface ApplicationCommandAutocompleteNumericOption
|
||||||
type:
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
| ApplicationCommandOptionType.String
|
type: CommandOptionNumericResolvableType;
|
||||||
| ApplicationCommandOptionType.Number
|
minValue?: number;
|
||||||
| ApplicationCommandOptionType.Integer;
|
maxValue?: number;
|
||||||
autocomplete: true;
|
autocomplete: true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandChoicesData extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
export interface ApplicationCommandAutocompleteStringOption
|
||||||
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
|
type: ApplicationCommandOptionType.String;
|
||||||
|
minLength?: number;
|
||||||
|
maxLength?: number;
|
||||||
|
autocomplete: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandAutocompleteNumericOptionData
|
||||||
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
|
type: CommandOptionNumericResolvableType;
|
||||||
|
minValue?: number;
|
||||||
|
min_value?: number;
|
||||||
|
maxValue?: number;
|
||||||
|
max_value?: number;
|
||||||
|
autocomplete: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandAutocompleteStringOptionData
|
||||||
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
|
type: ApplicationCommandOptionType.String;
|
||||||
|
minLength?: number;
|
||||||
|
min_length?: number;
|
||||||
|
maxLength?: number;
|
||||||
|
max_length?: number;
|
||||||
|
autocomplete: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandChoicesData<Type extends string | number = string | number>
|
||||||
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
type: CommandOptionChoiceResolvableType;
|
type: CommandOptionChoiceResolvableType;
|
||||||
choices?: ApplicationCommandOptionChoiceData[];
|
choices?: ApplicationCommandOptionChoiceData<Type>[];
|
||||||
autocomplete?: false;
|
autocomplete?: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandChoicesOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
export interface ApplicationCommandChoicesOption<Type extends string | number = string | number>
|
||||||
|
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||||
type: CommandOptionChoiceResolvableType;
|
type: CommandOptionChoiceResolvableType;
|
||||||
choices?: ApplicationCommandOptionChoiceData[];
|
choices?: ApplicationCommandOptionChoiceData<Type>[];
|
||||||
autocomplete?: false;
|
autocomplete?: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData {
|
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData<number> {
|
||||||
type: CommandOptionNumericResolvableType;
|
type: CommandOptionNumericResolvableType;
|
||||||
minValue?: number;
|
minValue?: number;
|
||||||
min_value?: number;
|
min_value?: number;
|
||||||
@@ -3825,7 +3895,7 @@ export interface ApplicationCommandNumericOptionData extends ApplicationCommandC
|
|||||||
max_value?: number;
|
max_value?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandStringOptionData extends ApplicationCommandChoicesData {
|
export interface ApplicationCommandStringOptionData extends ApplicationCommandChoicesData<string> {
|
||||||
type: ApplicationCommandOptionType.String;
|
type: ApplicationCommandOptionType.String;
|
||||||
minLength?: number;
|
minLength?: number;
|
||||||
min_length?: number;
|
min_length?: number;
|
||||||
@@ -3833,18 +3903,26 @@ export interface ApplicationCommandStringOptionData extends ApplicationCommandCh
|
|||||||
max_length?: number;
|
max_length?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption {
|
export interface ApplicationCommandBooleanOptionData extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption<number> {
|
||||||
type: CommandOptionNumericResolvableType;
|
type: CommandOptionNumericResolvableType;
|
||||||
minValue?: number;
|
minValue?: number;
|
||||||
maxValue?: number;
|
maxValue?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption {
|
export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption<string> {
|
||||||
type: ApplicationCommandOptionType.String;
|
type: ApplicationCommandOptionType.String;
|
||||||
minLength?: number;
|
minLength?: number;
|
||||||
maxLength?: number;
|
maxLength?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandBooleanOption extends BaseApplicationCommandOptionsData {
|
||||||
|
type: ApplicationCommandOptionType.Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
||||||
type: ApplicationCommandOptionType.SubcommandGroup;
|
type: ApplicationCommandOptionType.SubcommandGroup;
|
||||||
options?: ApplicationCommandSubCommandData[];
|
options?: ApplicationCommandSubCommandData[];
|
||||||
@@ -3857,19 +3935,12 @@ export interface ApplicationCommandSubGroup extends Omit<BaseApplicationCommandO
|
|||||||
|
|
||||||
export interface ApplicationCommandSubCommandData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
export interface ApplicationCommandSubCommandData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
||||||
type: ApplicationCommandOptionType.Subcommand;
|
type: ApplicationCommandOptionType.Subcommand;
|
||||||
options?: (
|
options?: Exclude<ApplicationCommandOptionData, ApplicationCommandSubGroupData | ApplicationCommandSubCommandData>[];
|
||||||
| ApplicationCommandChoicesData
|
|
||||||
| ApplicationCommandNonOptionsData
|
|
||||||
| ApplicationCommandChannelOptionData
|
|
||||||
| ApplicationCommandAutocompleteOption
|
|
||||||
| ApplicationCommandNumericOptionData
|
|
||||||
| ApplicationCommandStringOptionData
|
|
||||||
)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandSubCommand extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
export interface ApplicationCommandSubCommand extends Omit<BaseApplicationCommandOptionsData, 'required'> {
|
||||||
type: ApplicationCommandOptionType.Subcommand;
|
type: ApplicationCommandOptionType.Subcommand;
|
||||||
options?: (ApplicationCommandChoicesOption | ApplicationCommandNonOptions | ApplicationCommandChannelOption)[];
|
options?: Exclude<ApplicationCommandOption, ApplicationCommandSubGroup | ApplicationCommandSubCommand>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandNonOptionsData extends BaseApplicationCommandOptionsData {
|
export interface ApplicationCommandNonOptionsData extends BaseApplicationCommandOptionsData {
|
||||||
@@ -3884,26 +3955,35 @@ export type ApplicationCommandOptionData =
|
|||||||
| ApplicationCommandSubGroupData
|
| ApplicationCommandSubGroupData
|
||||||
| ApplicationCommandNonOptionsData
|
| ApplicationCommandNonOptionsData
|
||||||
| ApplicationCommandChannelOptionData
|
| ApplicationCommandChannelOptionData
|
||||||
| ApplicationCommandChoicesData
|
| ApplicationCommandAutocompleteNumericOptionData
|
||||||
| ApplicationCommandAutocompleteOption
|
| ApplicationCommandAutocompleteStringOptionData
|
||||||
| ApplicationCommandNumericOptionData
|
| ApplicationCommandNumericOptionData
|
||||||
| ApplicationCommandStringOptionData
|
| ApplicationCommandStringOptionData
|
||||||
|
| ApplicationCommandRoleOptionData
|
||||||
|
| ApplicationCommandUserOptionData
|
||||||
|
| ApplicationCommandMentionableOptionData
|
||||||
|
| ApplicationCommandBooleanOptionData
|
||||||
| ApplicationCommandSubCommandData;
|
| ApplicationCommandSubCommandData;
|
||||||
|
|
||||||
export type ApplicationCommandOption =
|
export type ApplicationCommandOption =
|
||||||
| ApplicationCommandSubGroup
|
| ApplicationCommandSubGroup
|
||||||
|
| ApplicationCommandAutocompleteNumericOption
|
||||||
|
| ApplicationCommandAutocompleteStringOption
|
||||||
| ApplicationCommandNonOptions
|
| ApplicationCommandNonOptions
|
||||||
| ApplicationCommandChannelOption
|
| ApplicationCommandChannelOption
|
||||||
| ApplicationCommandChoicesOption
|
|
||||||
| ApplicationCommandNumericOption
|
| ApplicationCommandNumericOption
|
||||||
| ApplicationCommandStringOption
|
| ApplicationCommandStringOption
|
||||||
|
| ApplicationCommandRoleOption
|
||||||
|
| ApplicationCommandUserOption
|
||||||
|
| ApplicationCommandMentionableOption
|
||||||
|
| ApplicationCommandBooleanOption
|
||||||
| ApplicationCommandAttachmentOption
|
| ApplicationCommandAttachmentOption
|
||||||
| ApplicationCommandSubCommand;
|
| ApplicationCommandSubCommand;
|
||||||
|
|
||||||
export interface ApplicationCommandOptionChoiceData {
|
export interface ApplicationCommandOptionChoiceData<Value extends string | number = string | number> {
|
||||||
name: string;
|
name: string;
|
||||||
nameLocalizations?: LocalizationMap;
|
nameLocalizations?: LocalizationMap;
|
||||||
value: string | number;
|
value: Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandPermissions {
|
export interface ApplicationCommandPermissions {
|
||||||
@@ -4077,7 +4157,7 @@ export interface ChannelWebhookCreateOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WebhookCreateOptions extends ChannelWebhookCreateOptions {
|
export interface WebhookCreateOptions extends ChannelWebhookCreateOptions {
|
||||||
channel: GuildChannelResolvable;
|
channel: TextChannel | NewsChannel | VoiceChannel | Snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientEvents {
|
export interface ClientEvents {
|
||||||
@@ -4121,7 +4201,7 @@ export interface ClientEvents {
|
|||||||
reactions: Collection<string | Snowflake, MessageReaction>,
|
reactions: Collection<string | Snowflake, MessageReaction>,
|
||||||
];
|
];
|
||||||
messageReactionRemoveEmoji: [reaction: MessageReaction | PartialMessageReaction];
|
messageReactionRemoveEmoji: [reaction: MessageReaction | PartialMessageReaction];
|
||||||
messageDeleteBulk: [messages: Collection<Snowflake, Message | PartialMessage>, channel: TextBasedChannel];
|
messageDeleteBulk: [messages: Collection<Snowflake, Message | PartialMessage>, channel: GuildTextBasedChannel];
|
||||||
messageReactionAdd: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
messageReactionAdd: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
||||||
messageReactionRemove: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
messageReactionRemove: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
|
||||||
messageUpdate: [oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage];
|
messageUpdate: [oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage];
|
||||||
@@ -4658,7 +4738,7 @@ export interface GuildAuditLogsEntryExtraField {
|
|||||||
[AuditLogEvent.StageInstanceCreate]: StageChannel | { id: Snowflake };
|
[AuditLogEvent.StageInstanceCreate]: StageChannel | { id: Snowflake };
|
||||||
[AuditLogEvent.StageInstanceDelete]: StageChannel | { id: Snowflake };
|
[AuditLogEvent.StageInstanceDelete]: StageChannel | { id: Snowflake };
|
||||||
[AuditLogEvent.StageInstanceUpdate]: StageChannel | { id: Snowflake };
|
[AuditLogEvent.StageInstanceUpdate]: StageChannel | { id: Snowflake };
|
||||||
[AuditLogEvent.ApplicationCommandPermissionUpdate]: { applicationId: Snowflake; guild: Guild | { id: Snowflake } };
|
[AuditLogEvent.ApplicationCommandPermissionUpdate]: { applicationId: Snowflake };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
|
export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
|
||||||
@@ -4750,7 +4830,7 @@ export interface GuildCreateOptions {
|
|||||||
|
|
||||||
export interface GuildWidgetSettings {
|
export interface GuildWidgetSettings {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
channel: NonThreadGuildBasedChannel | null;
|
channel: TextChannel | NewsChannel | VoiceBasedChannel | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildEditData {
|
export interface GuildEditData {
|
||||||
@@ -4828,7 +4908,7 @@ export interface GuildPruneMembersOptions {
|
|||||||
|
|
||||||
export interface GuildWidgetSettingsData {
|
export interface GuildWidgetSettingsData {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
channel: GuildChannelResolvable | null;
|
channel: TextChannel | NewsChannel | VoiceBasedChannel | Snowflake | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildSearchMembersOptions {
|
export interface GuildSearchMembersOptions {
|
||||||
|
|||||||
@@ -134,6 +134,8 @@ import {
|
|||||||
Webhook,
|
Webhook,
|
||||||
WebhookClient,
|
WebhookClient,
|
||||||
InteractionWebhook,
|
InteractionWebhook,
|
||||||
|
GuildAuditLogsActionType,
|
||||||
|
GuildAuditLogsTargetType,
|
||||||
} from '.';
|
} from '.';
|
||||||
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||||
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
||||||
@@ -1100,6 +1102,7 @@ expectAssignable<'death'>(ShardEvents.Death);
|
|||||||
expectAssignable<1>(Status.Connecting);
|
expectAssignable<1>(Status.Connecting);
|
||||||
|
|
||||||
declare const applicationCommandData: ApplicationCommandData;
|
declare const applicationCommandData: ApplicationCommandData;
|
||||||
|
declare const applicationCommandOptionData: ApplicationCommandOptionData;
|
||||||
declare const applicationCommandResolvable: ApplicationCommandResolvable;
|
declare const applicationCommandResolvable: ApplicationCommandResolvable;
|
||||||
declare const applicationCommandManager: ApplicationCommandManager;
|
declare const applicationCommandManager: ApplicationCommandManager;
|
||||||
{
|
{
|
||||||
@@ -1119,6 +1122,24 @@ declare const applicationCommandManager: ApplicationCommandManager;
|
|||||||
expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(
|
expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(
|
||||||
applicationCommandManager.set([applicationCommandData], '0'),
|
applicationCommandManager.set([applicationCommandData], '0'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Test inference of choice values.
|
||||||
|
if ('choices' in applicationCommandOptionData) {
|
||||||
|
if (applicationCommandOptionData.type === ApplicationCommandOptionType.String) {
|
||||||
|
expectType<string>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
expectNotType<number>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applicationCommandOptionData.type === ApplicationCommandOptionType.Integer) {
|
||||||
|
expectType<number>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
expectNotType<string>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applicationCommandOptionData.type === ApplicationCommandOptionType.Number) {
|
||||||
|
expectType<number>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
expectNotType<string>(applicationCommandOptionData.choices[0]!.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
|
declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
|
||||||
@@ -1533,7 +1554,7 @@ expectType<Promise<GuildAuditLogs<AuditLogEvent.IntegrationUpdate>>>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs({ type: null }));
|
expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs({ type: null }));
|
||||||
expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs());
|
expectType<Promise<GuildAuditLogs<AuditLogEvent>>>(guild.fetchAuditLogs());
|
||||||
|
|
||||||
expectType<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete', 'User'> | undefined>>(
|
expectType<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete', 'User'> | undefined>>(
|
||||||
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
|
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
|
||||||
@@ -1542,10 +1563,10 @@ expectAssignable<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete',
|
|||||||
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
|
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
|
||||||
);
|
);
|
||||||
|
|
||||||
expectType<Promise<GuildAuditLogsEntry<null, 'All', 'Unknown'> | undefined>>(
|
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||||
guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()),
|
guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()),
|
||||||
);
|
);
|
||||||
expectType<Promise<GuildAuditLogsEntry<null, 'All', 'Unknown'> | undefined>>(
|
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||||
guild.fetchAuditLogs().then(al => al.entries.first()),
|
guild.fetchAuditLogs().then(al => al.entries.first()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
import { createUnbuildConfig } from '../../build.config';
|
import { createUnbuildConfig } from '../../build.config';
|
||||||
|
|
||||||
export default createUnbuildConfig({ minify: true, externals: ['package.cjs', 'package.mjs'] });
|
export default createUnbuildConfig({
|
||||||
|
entries: [
|
||||||
|
{ builder: 'rollup', input: 'src/index' },
|
||||||
|
{ builder: 'rollup', input: 'src/cli' },
|
||||||
|
],
|
||||||
|
minify: true,
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "@discordjs/docgen",
|
"name": "@discordjs/docgen",
|
||||||
"version": "0.12.0",
|
"version": "0.12.1",
|
||||||
"description": "The docs.json generator for discord.js and its related projects",
|
"description": "The docs.json generator for discord.js and its related projects",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"fmt": "yarn format",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn format && yarn build",
|
||||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/docgen/*'",
|
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/docgen/*'",
|
||||||
"release": "cliff-jumper"
|
"release": "cliff-jumper"
|
||||||
},
|
},
|
||||||
"bin": "./dist/index.cjs",
|
"bin": "./dist/cli.cjs",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "src"
|
"lib": "src"
|
||||||
},
|
},
|
||||||
@@ -42,23 +42,31 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/collection": "workspace:^",
|
|
||||||
"commander": "^9.4.0",
|
"commander": "^9.4.0",
|
||||||
"jsdoc-to-markdown": "^7.1.1",
|
"jsdoc-to-markdown": "^7.1.1",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typedoc": "^0.23.9"
|
"typedoc": "^0.23.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@types/jsdoc-to-markdown": "^7.0.3",
|
"@types/jsdoc-to-markdown": "^7.0.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"eslint": "^8.20.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6"
|
"unbuild": "^0.8.9"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
packages/docgen/src/cli.ts
Normal file
25
packages/docgen/src/cli.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { createCommand } from 'commander';
|
||||||
|
import { build } from './index.js';
|
||||||
|
import packageFile from '../package.json';
|
||||||
|
|
||||||
|
export interface CLIOptions {
|
||||||
|
input: string[];
|
||||||
|
custom: string;
|
||||||
|
root: string;
|
||||||
|
output: string;
|
||||||
|
typescript: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const command = createCommand()
|
||||||
|
.version(packageFile.version)
|
||||||
|
.option('-i, --input <string...>', 'Source directories to parse JSDocs in')
|
||||||
|
.option('-c, --custom <string>', 'Custom docs definition file to use')
|
||||||
|
.option('-r, --root [string]', 'Root directory of the project', '.')
|
||||||
|
.option('-o, --output <string>', 'Path to output file')
|
||||||
|
.option('--typescript', '', false);
|
||||||
|
|
||||||
|
const program = command.parse(process.argv);
|
||||||
|
const options = program.opts<CLIOptions>();
|
||||||
|
|
||||||
|
build(options);
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { dirname, join, relative } from 'node:path';
|
import { dirname, join, relative } from 'node:path';
|
||||||
import { Collection } from '@discordjs/collection';
|
|
||||||
import type { DeclarationReflection } from 'typedoc';
|
import type { DeclarationReflection } from 'typedoc';
|
||||||
import type { ChildTypes, Class, Config, CustomDocs, RootTypes } from './interfaces/index.js';
|
import type { ChildTypes, Class, Config, CustomDocs, RootTypes } from './interfaces/index.js';
|
||||||
import { DocumentedClass } from './types/class.js';
|
import { DocumentedClass } from './types/class.js';
|
||||||
@@ -13,15 +12,15 @@ import { DocumentedTypeDef } from './types/typedef.js';
|
|||||||
import packageFile from '../package.json';
|
import packageFile from '../package.json';
|
||||||
|
|
||||||
export class Documentation {
|
export class Documentation {
|
||||||
public readonly classes = new Collection<string, DocumentedClass>();
|
public readonly classes = new Map<string, DocumentedClass>();
|
||||||
|
|
||||||
public readonly functions = new Collection<string, DocumentedMethod>();
|
public readonly functions = new Map<string, DocumentedMethod>();
|
||||||
|
|
||||||
public readonly interfaces = new Collection<string, DocumentedInterface>();
|
public readonly interfaces = new Map<string, DocumentedInterface>();
|
||||||
|
|
||||||
public readonly typedefs = new Collection<string, DocumentedTypeDef>();
|
public readonly typedefs = new Map<string, DocumentedTypeDef>();
|
||||||
|
|
||||||
public readonly externals = new Collection<string, DocumentedExternal>();
|
public readonly externals = new Map<string, DocumentedExternal>();
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
data: RootTypes[] | DeclarationReflection[],
|
data: RootTypes[] | DeclarationReflection[],
|
||||||
@@ -244,11 +243,11 @@ export class Documentation {
|
|||||||
format: Documentation.FORMAT_VERSION,
|
format: Documentation.FORMAT_VERSION,
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
},
|
},
|
||||||
classes: this.classes.map((c) => c.serialize()),
|
classes: [...this.classes.values()].map((c) => c.serialize()),
|
||||||
functions: this.functions.map((f) => f.serialize()),
|
functions: [...this.functions.values()].map((f) => f.serialize()),
|
||||||
interfaces: this.interfaces.map((i) => i.serialize()),
|
interfaces: [...this.interfaces.values()].map((i) => i.serialize()),
|
||||||
typedefs: this.typedefs.map((t) => t.serialize()),
|
typedefs: [...this.typedefs.values()].map((t) => t.serialize()),
|
||||||
externals: this.externals.map((e) => e.serialize()),
|
externals: [...this.externals.values()].map((e) => e.serialize()),
|
||||||
custom: this.custom,
|
custom: this.custom,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,10 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
import { readFileSync, writeFileSync } from 'node:fs';
|
import { readFileSync, writeFileSync } from 'node:fs';
|
||||||
import { join, basename, extname, dirname, relative } from 'node:path';
|
import { dirname, join, extname, basename, relative } from 'node:path';
|
||||||
import { createCommand } from 'commander';
|
|
||||||
import jsdoc2md from 'jsdoc-to-markdown';
|
import jsdoc2md from 'jsdoc-to-markdown';
|
||||||
import { Application, DeclarationReflection, TSConfigReader } from 'typedoc';
|
import { type DeclarationReflection, Application, TSConfigReader } from 'typedoc';
|
||||||
import { Documentation } from './documentation.js';
|
import type { CLIOptions } from './cli';
|
||||||
import type { ChildTypes, CustomDocs, RootTypes } from './interfaces/index.js';
|
import { Documentation } from './documentation';
|
||||||
import packageFile from '../package.json';
|
import type { RootTypes, ChildTypes, CustomDocs } from './interfaces';
|
||||||
|
|
||||||
interface CLIOptions {
|
|
||||||
input: string[];
|
|
||||||
custom: string;
|
|
||||||
root: string;
|
|
||||||
output: string;
|
|
||||||
typescript: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CustomFiles {
|
interface CustomFiles {
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -27,79 +17,70 @@ interface CustomFiles {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = createCommand()
|
export function build({ input, custom: customDocs, root, output, typescript }: CLIOptions) {
|
||||||
.version(packageFile.version)
|
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
|
||||||
.option('-i, --input <string...>', 'Source directories to parse JSDocs in')
|
if (typescript) {
|
||||||
.option('-c, --custom <string>', 'Custom docs definition file to use')
|
console.log('Parsing Typescript in source files...');
|
||||||
.option('-r, --root [string]', 'Root directory of the project', '.')
|
const app = new Application();
|
||||||
.option('-o, --output <string>', 'Path to output file')
|
app.options.addReader(new TSConfigReader());
|
||||||
.option('--typescript', '', false);
|
app.bootstrap({ entryPoints: input });
|
||||||
|
const project = app.convert();
|
||||||
const program = command.parse(process.argv);
|
if (project) {
|
||||||
const options = program.opts<CLIOptions>();
|
// @ts-expect-error
|
||||||
|
data = app.serializer.toObject(project).children!;
|
||||||
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
|
console.log(`${data.length} items parsed.`);
|
||||||
if (options.typescript) {
|
|
||||||
console.log('Parsing Typescript in source files...');
|
|
||||||
const app = new Application();
|
|
||||||
app.options.addReader(new TSConfigReader());
|
|
||||||
app.bootstrap({ entryPoints: options.input });
|
|
||||||
const project = app.convert();
|
|
||||||
if (project) {
|
|
||||||
// @ts-expect-error
|
|
||||||
data = app.serializer.toObject(project).children!;
|
|
||||||
console.log(`${data.length} items parsed.`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('Parsing JSDocs in source files...');
|
|
||||||
data = jsdoc2md.getTemplateDataSync({ files: options.input }) as (RootTypes & ChildTypes)[];
|
|
||||||
console.log(`${data.length} JSDoc items parsed.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const custom: Record<string, CustomDocs> = {};
|
|
||||||
if (options.custom) {
|
|
||||||
console.log('Loading custom docs files...');
|
|
||||||
const customDir = dirname(options.custom);
|
|
||||||
const file = readFileSync(options.custom, 'utf-8');
|
|
||||||
const data = JSON.parse(file) as CustomFiles[];
|
|
||||||
|
|
||||||
for (const category of data) {
|
|
||||||
const categoryId = category.id ?? category.name.toLowerCase();
|
|
||||||
const dir = join(customDir, category.path ?? categoryId);
|
|
||||||
custom[categoryId] = {
|
|
||||||
name: category.name || category.id!,
|
|
||||||
files: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const f of category.files) {
|
|
||||||
const fileRootPath = join(dir, f.path);
|
|
||||||
const extension = extname(f.path);
|
|
||||||
const fileId = f.id ?? basename(f.path, extension);
|
|
||||||
const fileData = readFileSync(fileRootPath, 'utf-8');
|
|
||||||
custom[categoryId]!.files[fileId] = {
|
|
||||||
name: f.name,
|
|
||||||
type: extension.toLowerCase().replace(/^\./, ''),
|
|
||||||
content: fileData,
|
|
||||||
path: relative(options.root, fileRootPath).replace(/\\/g, '/'),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Parsing JSDocs in source files...');
|
||||||
|
data = jsdoc2md.getTemplateDataSync({ files: input }) as (RootTypes & ChildTypes)[];
|
||||||
|
console.log(`${data.length} JSDoc items parsed.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileCount = Object.keys(custom)
|
const custom: Record<string, CustomDocs> = {};
|
||||||
.map((k) => Object.keys(custom[k]!))
|
if (customDocs) {
|
||||||
.reduce((prev, c) => prev + c.length, 0);
|
console.log('Loading custom docs files...');
|
||||||
const categoryCount = Object.keys(custom).length;
|
const customDir = dirname(customDocs);
|
||||||
console.log(
|
const file = readFileSync(customDocs, 'utf-8');
|
||||||
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
|
const data = JSON.parse(file) as CustomFiles[];
|
||||||
`${categoryCount} categor${categoryCount === 1 ? 'y' : 'ies'} loaded.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Serializing documentation with format version ${Documentation.FORMAT_VERSION}...`);
|
for (const category of data) {
|
||||||
const docs = new Documentation(data, options, custom);
|
const categoryId = category.id ?? category.name.toLowerCase();
|
||||||
|
const dir = join(customDir, category.path ?? categoryId);
|
||||||
|
custom[categoryId] = {
|
||||||
|
name: category.name || category.id!,
|
||||||
|
files: {},
|
||||||
|
};
|
||||||
|
|
||||||
if (options.output) {
|
for (const f of category.files) {
|
||||||
console.log(`Writing to ${options.output}...`);
|
const fileRootPath = join(dir, f.path);
|
||||||
writeFileSync(options.output, JSON.stringify(docs.serialize()));
|
const extension = extname(f.path);
|
||||||
|
const fileId = f.id ?? basename(f.path, extension);
|
||||||
|
const fileData = readFileSync(fileRootPath, 'utf-8');
|
||||||
|
custom[categoryId]!.files[fileId] = {
|
||||||
|
name: f.name,
|
||||||
|
type: extension.toLowerCase().replace(/^\./, ''),
|
||||||
|
content: fileData,
|
||||||
|
path: relative(root, fileRootPath).replace(/\\/g, '/'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileCount = Object.keys(custom)
|
||||||
|
.map((k) => Object.keys(custom[k]!))
|
||||||
|
.reduce((prev, c) => prev + c.length, 0);
|
||||||
|
const categoryCount = Object.keys(custom).length;
|
||||||
|
console.log(
|
||||||
|
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
|
||||||
|
`${categoryCount} categor${categoryCount === 1 ? 'y' : 'ies'} loaded.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Serializing documentation with format version ${Documentation.FORMAT_VERSION}...`);
|
||||||
|
const docs = new Documentation(data, { input, custom: customDocs, root, output, typescript }, custom);
|
||||||
|
|
||||||
|
if (output) {
|
||||||
|
console.log(`Writing to ${output}...`);
|
||||||
|
writeFileSync(output, JSON.stringify(docs.serialize()));
|
||||||
|
}
|
||||||
|
console.log('Done!');
|
||||||
}
|
}
|
||||||
console.log('Done!');
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Type } from './index.js';
|
import type { Type } from './index.js';
|
||||||
|
|
||||||
export interface Return {
|
export interface Return {
|
||||||
type: Type;
|
type: Required<Type>;
|
||||||
nullable?: boolean;
|
nullable?: boolean;
|
||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export interface Type {
|
export interface Type {
|
||||||
names?: string[];
|
names?: string[] | undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Type } from './index.js';
|
import type { Type } from './index.js';
|
||||||
|
|
||||||
export interface VarType extends Type {
|
export interface VarType extends Type {
|
||||||
type?: Required<Type>;
|
type?: Required<Type> | undefined;
|
||||||
description?: string;
|
description?: string | undefined;
|
||||||
nullable?: boolean;
|
nullable?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { parse } from 'node:path';
|
import { parse } from 'node:path';
|
||||||
import { Collection } from '@discordjs/collection';
|
|
||||||
import type { DeclarationReflection } from 'typedoc';
|
import type { DeclarationReflection } from 'typedoc';
|
||||||
import { DocumentedConstructor } from './constructor.js';
|
import { DocumentedConstructor } from './constructor.js';
|
||||||
import { DocumentedEvent } from './event.js';
|
import { DocumentedEvent } from './event.js';
|
||||||
@@ -12,11 +11,11 @@ import type { Class, Config } from '../interfaces/index.js';
|
|||||||
import { parseType } from '../util/parseType.js';
|
import { parseType } from '../util/parseType.js';
|
||||||
|
|
||||||
export class DocumentedClass extends DocumentedItem<Class | DeclarationReflection> {
|
export class DocumentedClass extends DocumentedItem<Class | DeclarationReflection> {
|
||||||
public readonly props = new Collection<string, DocumentedMember>();
|
public readonly props = new Map<string, DocumentedMember>();
|
||||||
|
|
||||||
public readonly methods = new Collection<string, DocumentedMethod>();
|
public readonly methods = new Map<string, DocumentedMethod>();
|
||||||
|
|
||||||
public readonly events = new Collection<string, DocumentedEvent>();
|
public readonly events = new Map<string, DocumentedEvent>();
|
||||||
|
|
||||||
public construct: DocumentedConstructor | null = null;
|
public construct: DocumentedConstructor | null = null;
|
||||||
|
|
||||||
@@ -120,9 +119,9 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
|||||||
.trim() ?? true
|
.trim() ?? true
|
||||||
: undefined,
|
: undefined,
|
||||||
construct: this.construct?.serialize(),
|
construct: this.construct?.serialize(),
|
||||||
props: this.props.size ? this.props.map((p) => p.serialize()) : undefined,
|
props: this.props.size ? [...this.props.values()].map((p) => p.serialize()) : undefined,
|
||||||
methods: this.methods.size ? this.methods.map((m) => m.serialize()) : undefined,
|
methods: this.methods.size ? [...this.methods.values()].map((m) => m.serialize()) : undefined,
|
||||||
events: this.events.size ? this.events.map((e) => e.serialize()) : undefined,
|
events: this.events.size ? [...this.events.values()].map((e) => e.serialize()) : undefined,
|
||||||
meta,
|
meta,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -138,9 +137,9 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
|||||||
abstract: data.virtual,
|
abstract: data.virtual,
|
||||||
deprecated: data.deprecated,
|
deprecated: data.deprecated,
|
||||||
construct: this.construct?.serialize(),
|
construct: this.construct?.serialize(),
|
||||||
props: this.props.size ? this.props.map((p) => p.serialize()) : undefined,
|
props: this.props.size ? [...this.props.values()].map((p) => p.serialize()) : undefined,
|
||||||
methods: this.methods.size ? this.methods.map((m) => m.serialize()) : undefined,
|
methods: this.methods.size ? [...this.methods.values()].map((m) => m.serialize()) : undefined,
|
||||||
events: this.events.size ? this.events.map((e) => e.serialize()) : undefined,
|
events: this.events.size ? [...this.events.values()].map((e) => e.serialize()) : undefined,
|
||||||
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
meta: new DocumentedItemMeta(data.meta, this.config).serialize(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
"description": "Lightweight HTTP proxy for Discord's API, brought to you as a container 📦",
|
"description": "Lightweight HTTP proxy for Discord's API, brought to you as a container 📦",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"fmt": "yarn format",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy-container/*'"
|
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy-container/*'"
|
||||||
@@ -49,12 +49,18 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"eslint": "^8.20.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6"
|
"unbuild": "^0.8.9"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../.eslintrc.json"
|
"extends": "../../.eslintrc.json",
|
||||||
|
"plugins": ["eslint-plugin-tsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"tsdoc/syntax": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,40 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
# [@discordjs/proxy@1.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/proxy@1.1.0) - (2022-08-22)
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
- **proxyRequests:** Typo in error message (#8537) ([dd44e8b](https://github.com/discordjs/discord.js/commit/dd44e8b6ec141e630af4543bd3babcce39aa2887))
|
||||||
|
- **proxy-container:** Proper deps (#8120) ([17867f9](https://github.com/discordjs/discord.js/commit/17867f9154d0dd16357f4ff29da641e23a33a9fa))
|
||||||
|
- **proxy:** Add docs script ([a45bef4](https://github.com/discordjs/discord.js/commit/a45bef4cad77dac1a4138fd0d52b769ce09b5678))
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- Add codecov coverage badge to readmes (#8226) ([f6db285](https://github.com/discordjs/discord.js/commit/f6db285c073898a749fe4591cbd4463d1896daf5))
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007))
|
||||||
|
- Codecov (#8219) ([f10f4cd](https://github.com/discordjs/discord.js/commit/f10f4cdcd88ca6be7ec735ed3a415ba13da83db0))
|
||||||
|
- Proxy container (#8000) ([2681929](https://github.com/discordjs/discord.js/commit/2681929e4263032ad34a99ecb42465c320b271ba))
|
||||||
|
- **docgen:** Update typedoc ([b3346f4](https://github.com/discordjs/discord.js/commit/b3346f4b9b3d4f96443506643d4631dc1c6d7b21))
|
||||||
|
- Website (#8043) ([127931d](https://github.com/discordjs/discord.js/commit/127931d1df7a2a5c27923c2f2151dbf3824e50cc))
|
||||||
|
- **docgen:** Typescript support ([3279b40](https://github.com/discordjs/discord.js/commit/3279b40912e6aa61507bedb7db15a2b8668de44b))
|
||||||
|
- Docgen package (#8029) ([8b979c0](https://github.com/discordjs/discord.js/commit/8b979c0245c42fd824d8e98745ee869f5360fc86))
|
||||||
|
- 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/proxy (#7925) ([1ba2d2a](https://github.com/discordjs/discord.js/commit/1ba2d2a898613e5fcc119a97dce935f4db91162c))
|
||||||
|
|
||||||
|
## Refactor
|
||||||
|
|
||||||
|
- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e))
|
||||||
|
- Move all the config files to root (#8033) ([769ea0b](https://github.com/discordjs/discord.js/commit/769ea0bfe78c4f1d413c6b397c604ffe91e39c6a))
|
||||||
|
|
||||||
|
## Styling
|
||||||
|
|
||||||
|
- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629))
|
||||||
|
|
||||||
# [@discordjs/proxy@1.0.0](https://github.com/discordjs/discord.js/tree/@discordjs/proxy@1.1.0) - (2022-07-17)
|
# [@discordjs/proxy@1.0.0](https://github.com/discordjs/discord.js/tree/@discordjs/proxy@1.1.0) - (2022-07-17)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@discordjs/proxy",
|
"name": "@discordjs/proxy",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"description": "Tools for running an HTTP proxy for Discord's API",
|
"description": "Tools for running an HTTP proxy for Discord's API",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"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 . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
@@ -56,23 +56,29 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/rest": "^1.0.0",
|
"@discordjs/rest": "^1.0.0",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"undici": "^5.8.0"
|
"undici": "^5.9.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@microsoft/api-extractor": "^7.28.6",
|
"@microsoft/api-extractor": "^7.29.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"@types/supertest": "^2.0.12",
|
"@types/supertest": "^2.0.12",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
"downlevel-dts": "^0.10.0",
|
"downlevel-dts": "^0.10.0",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"supertest": "^6.2.4",
|
"supertest": "^6.2.4",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function proxyRequests(rest: REST): RequestHandler {
|
|||||||
|
|
||||||
if (!method || !url) {
|
if (!method || !url) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMesage',
|
'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
|
||||||
"exactOptionalPropertyTypes": false
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../.eslintrc.json"
|
"extends": "../../.eslintrc.json",
|
||||||
|
"plugins": ["eslint-plugin-tsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"tsdoc/syntax": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
# [@discordjs/rest@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.0.1...@discordjs/rest@1.1.0) - (2022-08-22)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007))
|
||||||
|
- **website:** Render `@defaultValue` blocks (#8527) ([8028813](https://github.com/discordjs/discord.js/commit/8028813825e7708915ea892760c1003afd60df2f))
|
||||||
|
- **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/rest@0.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.5.0...@discordjs/rest@0.6.0) - (2022-07-17)
|
# [@discordjs/rest@0.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.5.0...@discordjs/rest@0.6.0) - (2022-07-17)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@discordjs/rest",
|
"name": "@discordjs/rest",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"description": "The REST API for discord.js",
|
"description": "The REST API for discord.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"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 . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
@@ -53,26 +53,33 @@
|
|||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/collection": "workspace:^",
|
"@discordjs/collection": "workspace:^",
|
||||||
"@sapphire/async-queue": "^1.3.2",
|
"@sapphire/async-queue": "^1.5.0",
|
||||||
"@sapphire/snowflake": "^3.2.2",
|
"@sapphire/snowflake": "^3.2.2",
|
||||||
"discord-api-types": "^0.36.3",
|
"discord-api-types": "^0.37.3",
|
||||||
"file-type": "^17.1.4",
|
"file-type": "^17.1.6",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"undici": "^5.8.0"
|
"undici": "^5.9.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@microsoft/api-extractor": "^7.28.6",
|
"@microsoft/api-extractor": "^7.29.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
"downlevel-dts": "^0.10.0",
|
"downlevel-dts": "^0.10.0",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export interface BaseImageURLOptions {
|
|||||||
/**
|
/**
|
||||||
* The extension to use for the image URL
|
* The extension to use for the image URL
|
||||||
*
|
*
|
||||||
* @default 'webp'
|
* @defaultValue `'webp'`
|
||||||
*/
|
*/
|
||||||
extension?: ImageExtension;
|
extension?: ImageExtension;
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +41,7 @@ export interface MakeURLOptions {
|
|||||||
/**
|
/**
|
||||||
* The extension to use for the image URL
|
* The extension to use for the image URL
|
||||||
*
|
*
|
||||||
* @default 'webp'
|
* @defaultValue `'webp'`
|
||||||
*/
|
*/
|
||||||
extension?: string | undefined;
|
extension?: string | undefined;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,45 +25,45 @@ export interface RESTOptions {
|
|||||||
agent: Dispatcher;
|
agent: Dispatcher;
|
||||||
/**
|
/**
|
||||||
* The base api path, without version
|
* The base api path, without version
|
||||||
* @default 'https://discord.com/api'
|
* @defaultValue `'https://discord.com/api'`
|
||||||
*/
|
*/
|
||||||
api: string;
|
api: string;
|
||||||
/**
|
/**
|
||||||
* The authorization prefix to use for requests, useful if you want to use
|
* The authorization prefix to use for requests, useful if you want to use
|
||||||
* bearer tokens
|
* bearer tokens
|
||||||
*
|
*
|
||||||
* @default 'Bot'
|
* @defaultValue `'Bot'`
|
||||||
*/
|
*/
|
||||||
authPrefix: 'Bot' | 'Bearer';
|
authPrefix: 'Bot' | 'Bearer';
|
||||||
/**
|
/**
|
||||||
* The cdn path
|
* The cdn path
|
||||||
*
|
*
|
||||||
* @default 'https://cdn.discordapp.com'
|
* @defaultValue 'https://cdn.discordapp.com'
|
||||||
*/
|
*/
|
||||||
cdn: string;
|
cdn: string;
|
||||||
/**
|
/**
|
||||||
* Additional headers to send for all API requests
|
* Additional headers to send for all API requests
|
||||||
*
|
*
|
||||||
* @default {}
|
* @defaultValue `{}`
|
||||||
*/
|
*/
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
/**
|
/**
|
||||||
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
* The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
|
||||||
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
* That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
||||||
*
|
*
|
||||||
* @default 0
|
* @defaultValue `0`
|
||||||
*/
|
*/
|
||||||
invalidRequestWarningInterval: number;
|
invalidRequestWarningInterval: number;
|
||||||
/**
|
/**
|
||||||
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
* How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
|
||||||
*
|
*
|
||||||
* @default 50
|
* @defaultValue `50`
|
||||||
*/
|
*/
|
||||||
globalRequestsPerSecond: number;
|
globalRequestsPerSecond: number;
|
||||||
/**
|
/**
|
||||||
* The extra offset to add to rate limits in milliseconds
|
* The extra offset to add to rate limits in milliseconds
|
||||||
*
|
*
|
||||||
* @default 50
|
* @defaultValue `50`
|
||||||
*/
|
*/
|
||||||
offset: number;
|
offset: number;
|
||||||
/**
|
/**
|
||||||
@@ -72,50 +72,50 @@ export interface RESTOptions {
|
|||||||
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
* (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
|
||||||
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
* for which to throw {@link RateLimitError}s. All other request routes will be queued normally
|
||||||
*
|
*
|
||||||
* @default null
|
* @defaultValue `null`
|
||||||
*/
|
*/
|
||||||
rejectOnRateLimit: string[] | RateLimitQueueFilter | null;
|
rejectOnRateLimit: string[] | RateLimitQueueFilter | null;
|
||||||
/**
|
/**
|
||||||
* The number of retries for errors with the 500 code, or errors
|
* The number of retries for errors with the 500 code, or errors
|
||||||
* that timeout
|
* that timeout
|
||||||
*
|
*
|
||||||
* @default 3
|
* @defaultValue `3`
|
||||||
*/
|
*/
|
||||||
retries: number;
|
retries: number;
|
||||||
/**
|
/**
|
||||||
* The time to wait in milliseconds before a request is aborted
|
* The time to wait in milliseconds before a request is aborted
|
||||||
*
|
*
|
||||||
* @default 15_000
|
* @defaultValue `15_000`
|
||||||
*/
|
*/
|
||||||
timeout: number;
|
timeout: number;
|
||||||
/**
|
/**
|
||||||
* Extra information to add to the user agent
|
* Extra information to add to the user agent
|
||||||
*
|
*
|
||||||
* @default `Node.js ${process.version}`
|
* @defaultValue `Node.js ${process.version}`
|
||||||
*/
|
*/
|
||||||
userAgentAppendix: string;
|
userAgentAppendix: string;
|
||||||
/**
|
/**
|
||||||
* The version of the API to use
|
* The version of the API to use
|
||||||
*
|
*
|
||||||
* @default '10'
|
* @defaultValue `'10'`
|
||||||
*/
|
*/
|
||||||
version: string;
|
version: string;
|
||||||
/**
|
/**
|
||||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
|
||||||
*
|
*
|
||||||
* @default 14_400_000
|
* @defaultValue `14_400_000`
|
||||||
*/
|
*/
|
||||||
hashSweepInterval: number;
|
hashSweepInterval: number;
|
||||||
/**
|
/**
|
||||||
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
* The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
|
||||||
*
|
*
|
||||||
* @default 86_400_000
|
* @defaultValue `86_400_000`
|
||||||
*/
|
*/
|
||||||
hashLifetime: number;
|
hashLifetime: number;
|
||||||
/**
|
/**
|
||||||
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
* The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
|
||||||
*
|
*
|
||||||
* @default 3_600_000
|
* @defaultValue `3_600_000`
|
||||||
*/
|
*/
|
||||||
handlerSweepInterval: number;
|
handlerSweepInterval: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ export interface RequestData {
|
|||||||
/**
|
/**
|
||||||
* If this request needs the `Authorization` header
|
* If this request needs the `Authorization` header
|
||||||
*
|
*
|
||||||
* @default true
|
* @defaultValue `true`
|
||||||
*/
|
*/
|
||||||
auth?: boolean;
|
auth?: boolean;
|
||||||
/**
|
/**
|
||||||
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
||||||
*
|
*
|
||||||
* @default 'Bot'
|
* @defaultValue `'Bot'`
|
||||||
*/
|
*/
|
||||||
authPrefix?: 'Bot' | 'Bearer';
|
authPrefix?: 'Bot' | 'Bearer';
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,7 @@ export interface RequestData {
|
|||||||
*/
|
*/
|
||||||
body?: BodyInit | unknown;
|
body?: BodyInit | unknown;
|
||||||
/**
|
/**
|
||||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} to use for the request.
|
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||||
*/
|
*/
|
||||||
dispatcher?: Agent;
|
dispatcher?: Agent;
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +92,7 @@ export interface RequestData {
|
|||||||
/**
|
/**
|
||||||
* If this request should be versioned
|
* If this request should be versioned
|
||||||
*
|
*
|
||||||
* @default true
|
* @defaultValue `true`
|
||||||
*/
|
*/
|
||||||
versioned?: boolean;
|
versioned?: boolean;
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ export interface RequestManager {
|
|||||||
*/
|
*/
|
||||||
export class RequestManager extends EventEmitter {
|
export class RequestManager extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} for all requests
|
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
||||||
* performed by this manager.
|
* performed by this manager.
|
||||||
*/
|
*/
|
||||||
public agent: Dispatcher | null = null;
|
public agent: Dispatcher | null = null;
|
||||||
@@ -342,7 +342,7 @@ export class RequestManager extends EventEmitter {
|
|||||||
* @param hash - The hash for the route
|
* @param hash - The hash for the route
|
||||||
* @param majorParameter - The major parameter for this handler
|
* @param majorParameter - The major parameter for this handler
|
||||||
*
|
*
|
||||||
* @private
|
* @internal
|
||||||
*/
|
*/
|
||||||
private createHandler(hash: string, majorParameter: string) {
|
private createHandler(hash: string, majorParameter: string) {
|
||||||
// Create the async request queue to handle requests
|
// Create the async request queue to handle requests
|
||||||
@@ -487,7 +487,7 @@ export class RequestManager extends EventEmitter {
|
|||||||
* @param endpoint - The raw endpoint to generalize
|
* @param endpoint - The raw endpoint to generalize
|
||||||
* @param method - The HTTP method this endpoint is called without
|
* @param method - The HTTP method this endpoint is called without
|
||||||
*
|
*
|
||||||
* @private
|
* @internal
|
||||||
*/
|
*/
|
||||||
private static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {
|
private static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {
|
||||||
const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{16,19})/.exec(endpoint);
|
const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{16,19})/.exec(endpoint);
|
||||||
|
|||||||
@@ -3,13 +3,27 @@ import type { RequestOptions } from '../REST';
|
|||||||
import type { HandlerRequestData, RouteData } from '../RequestManager';
|
import type { HandlerRequestData, RouteData } from '../RequestManager';
|
||||||
|
|
||||||
export interface IHandler {
|
export interface IHandler {
|
||||||
|
/**
|
||||||
|
* Queues a request to be sent
|
||||||
|
*
|
||||||
|
* @param routeId - The generalized api route with literal ids for major parameters
|
||||||
|
* @param url - The url to do the request on
|
||||||
|
* @param options - All the information needed to make a request
|
||||||
|
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
||||||
|
*/
|
||||||
queueRequest: (
|
queueRequest: (
|
||||||
routeId: RouteData,
|
routeId: RouteData,
|
||||||
url: string,
|
url: string,
|
||||||
options: RequestOptions,
|
options: RequestOptions,
|
||||||
requestData: HandlerRequestData,
|
requestData: HandlerRequestData,
|
||||||
) => Promise<Dispatcher.ResponseData>;
|
) => Promise<Dispatcher.ResponseData>;
|
||||||
|
/**
|
||||||
|
* If the bucket is currently inactive (no pending requests)
|
||||||
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/method-signature-style -- This is meant to be a getter returning a bool
|
// eslint-disable-next-line @typescript-eslint/method-signature-style -- This is meant to be a getter returning a bool
|
||||||
get inactive(): boolean;
|
get inactive(): boolean;
|
||||||
|
/**
|
||||||
|
* The unique id of the handler
|
||||||
|
*/
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const enum QueueType {
|
|||||||
*/
|
*/
|
||||||
export class SequentialHandler implements IHandler {
|
export class SequentialHandler implements IHandler {
|
||||||
/**
|
/**
|
||||||
* The unique id of the handler
|
* {@inheritDoc IHandler.id}
|
||||||
*/
|
*/
|
||||||
public readonly id: string;
|
public readonly id: string;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ export class SequentialHandler implements IHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the bucket is currently inactive (no pending requests)
|
* {@inheritDoc IHandler.inactive}
|
||||||
*/
|
*/
|
||||||
public get inactive(): boolean {
|
public get inactive(): boolean {
|
||||||
return (
|
return (
|
||||||
@@ -161,12 +161,7 @@ export class SequentialHandler implements IHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queues a request to be sent
|
* {@inheritDoc IHandler.queueRequest}
|
||||||
*
|
|
||||||
* @param routeId - The generalized api route with literal ids for major parameters
|
|
||||||
* @param url - The url to do the request on
|
|
||||||
* @param options - All the information needed to make a request
|
|
||||||
* @param requestData - Extra data from the user's request needed for errors and additional processing
|
|
||||||
*/
|
*/
|
||||||
public async queueRequest(
|
public async queueRequest(
|
||||||
routeId: RouteData,
|
routeId: RouteData,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format"
|
"fmt": "yarn format"
|
||||||
},
|
},
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
@@ -48,14 +48,20 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"c8": "^7.12.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
"eslint": "^8.20.0",
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6",
|
"unbuild": "^0.8.9",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../.eslintrc.json",
|
"extends": "../../.eslintrc.json",
|
||||||
|
"plugins": ["eslint-plugin-tsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"tsdoc/syntax": "warn"
|
||||||
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"project": "./tsconfig.eslint.json",
|
"project": "./tsconfig.eslint.json",
|
||||||
"extraFileExtensions": [".mjs"]
|
"extraFileExtensions": [".mjs"]
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "unbuild",
|
"build": "unbuild",
|
||||||
"test": "jest --coverage",
|
"test": "jest --coverage",
|
||||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
"lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
"format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||||
"fmt": "yarn format",
|
"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 . docs --to=3.7 && docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
|
||||||
"prepack": "yarn lint && yarn test && yarn build",
|
"prepack": "yarn lint && yarn test && yarn build",
|
||||||
@@ -53,31 +53,37 @@
|
|||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
"discord-api-types": "^0.36.3",
|
"discord-api-types": "^0.37.3",
|
||||||
"prism-media": "^1.3.4",
|
"prism-media": "^1.3.4",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.18.9",
|
"@babel/core": "^7.18.10",
|
||||||
"@babel/preset-env": "^7.18.9",
|
"@babel/preset-env": "^7.18.10",
|
||||||
"@babel/preset-typescript": "^7.18.6",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
"@discordjs/docgen": "workspace:^",
|
"@discordjs/docgen": "workspace:^",
|
||||||
"@discordjs/scripts": "workspace:^",
|
"@favware/cliff-jumper": "^1.8.7",
|
||||||
"@favware/cliff-jumper": "^1.8.5",
|
"@microsoft/api-extractor": "^7.29.3",
|
||||||
"@microsoft/api-extractor": "^7.28.6",
|
"@types/jest": "^28.1.7",
|
||||||
"@types/jest": "^28.1.6",
|
"@types/node": "^16.11.52",
|
||||||
"@types/node": "^16.11.46",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
"downlevel-dts": "^0.10.0",
|
"downlevel-dts": "^0.10.0",
|
||||||
"eslint": "^8.20.0",
|
"eslint": "^8.22.0",
|
||||||
|
"eslint-config-marine": "^9.4.1",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"jest": "^28.1.3",
|
"jest": "^28.1.3",
|
||||||
"jest-websocket-mock": "^2.3.0",
|
"jest-websocket-mock": "^2.4.0",
|
||||||
"mock-socket": "^9.1.5",
|
"mock-socket": "^9.1.5",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"rollup-plugin-typescript2": "0.32.1",
|
"rollup-plugin-typescript2": "^0.33.0",
|
||||||
"tweetnacl": "^1.0.3",
|
"tweetnacl": "^1.0.3",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unbuild": "^0.7.6"
|
"unbuild": "^0.8.9"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export enum VoiceConnectionStatus {
|
|||||||
*/
|
*/
|
||||||
export interface VoiceConnectionSignallingState {
|
export interface VoiceConnectionSignallingState {
|
||||||
status: VoiceConnectionStatus.Signalling;
|
status: VoiceConnectionStatus.Signalling;
|
||||||
subscription?: PlayerSubscription;
|
subscription?: PlayerSubscription | undefined;
|
||||||
adapter: DiscordGatewayAdapterImplementerMethods;
|
adapter: DiscordGatewayAdapterImplementerMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ export enum VoiceConnectionDisconnectReason {
|
|||||||
*/
|
*/
|
||||||
export interface VoiceConnectionDisconnectedBaseState {
|
export interface VoiceConnectionDisconnectedBaseState {
|
||||||
status: VoiceConnectionStatus.Disconnected;
|
status: VoiceConnectionStatus.Disconnected;
|
||||||
subscription?: PlayerSubscription;
|
subscription?: PlayerSubscription | undefined;
|
||||||
adapter: DiscordGatewayAdapterImplementerMethods;
|
adapter: DiscordGatewayAdapterImplementerMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ export type VoiceConnectionDisconnectedState =
|
|||||||
export interface VoiceConnectionConnectingState {
|
export interface VoiceConnectionConnectingState {
|
||||||
status: VoiceConnectionStatus.Connecting;
|
status: VoiceConnectionStatus.Connecting;
|
||||||
networking: Networking;
|
networking: Networking;
|
||||||
subscription?: PlayerSubscription;
|
subscription?: PlayerSubscription | undefined;
|
||||||
adapter: DiscordGatewayAdapterImplementerMethods;
|
adapter: DiscordGatewayAdapterImplementerMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ export interface VoiceConnectionConnectingState {
|
|||||||
export interface VoiceConnectionReadyState {
|
export interface VoiceConnectionReadyState {
|
||||||
status: VoiceConnectionStatus.Ready;
|
status: VoiceConnectionStatus.Ready;
|
||||||
networking: Networking;
|
networking: Networking;
|
||||||
subscription?: PlayerSubscription;
|
subscription?: PlayerSubscription | undefined;
|
||||||
adapter: DiscordGatewayAdapterImplementerMethods;
|
adapter: DiscordGatewayAdapterImplementerMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,22 +165,22 @@ export type VoiceConnectionState =
|
|||||||
export interface VoiceConnection extends EventEmitter {
|
export interface VoiceConnection extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* Emitted when there is an error emitted from the voice connection
|
* Emitted when there is an error emitted from the voice connection
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'error', listener: (error: Error) => void): this;
|
on(event: 'error', listener: (error: Error) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted debugging information about the voice connection
|
* Emitted debugging information about the voice connection
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'debug', listener: (message: string) => void): this;
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted when the state of the voice connection changes
|
* Emitted when the state of the voice connection changes
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'stateChange', listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void): this;
|
on(event: 'stateChange', listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted when the state of the voice connection changes to a specific status
|
* Emitted when the state of the voice connection changes to a specific status
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on<T extends VoiceConnectionStatus>(
|
on<T extends VoiceConnectionStatus>(
|
||||||
event: T,
|
event: T,
|
||||||
@@ -688,7 +688,7 @@ export class VoiceConnection extends EventEmitter {
|
|||||||
*
|
*
|
||||||
* @param subscription - The removed subscription
|
* @param subscription - The removed subscription
|
||||||
*/
|
*/
|
||||||
private onSubscriptionRemoved(subscription: PlayerSubscription) {
|
protected onSubscriptionRemoved(subscription: PlayerSubscription) {
|
||||||
if (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {
|
if (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {
|
||||||
this.state = {
|
this.state = {
|
||||||
...this.state,
|
...this.state,
|
||||||
|
|||||||
@@ -154,27 +154,27 @@ export type AudioPlayerState =
|
|||||||
export interface AudioPlayer extends EventEmitter {
|
export interface AudioPlayer extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* Emitted when there is an error emitted from the audio resource played by the audio player
|
* Emitted when there is an error emitted from the audio resource played by the audio player
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'error', listener: (error: AudioPlayerError) => void): this;
|
on(event: 'error', listener: (error: AudioPlayerError) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted debugging information about the audio player
|
* Emitted debugging information about the audio player
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'debug', listener: (message: string) => void): this;
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted when the state of the audio player changes
|
* Emitted when the state of the audio player changes
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'stateChange', listener: (oldState: AudioPlayerState, newState: AudioPlayerState) => void): this;
|
on(event: 'stateChange', listener: (oldState: AudioPlayerState, newState: AudioPlayerState) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted when the audio player is subscribed to a voice connection
|
* Emitted when the audio player is subscribed to a voice connection
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'subscribe' | 'unsubscribe', listener: (subscription: PlayerSubscription) => void): this;
|
on(event: 'subscribe' | 'unsubscribe', listener: (subscription: PlayerSubscription) => void): this;
|
||||||
/**
|
/**
|
||||||
* Emitted when the status of state changes to a specific status
|
* Emitted when the status of state changes to a specific status
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on<T extends AudioPlayerStatus>(
|
on<T extends AudioPlayerStatus>(
|
||||||
event: T,
|
event: T,
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ export class AudioPlayerError extends Error {
|
|||||||
super(error.message);
|
super(error.message);
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
this.name = error.name;
|
this.name = error.name;
|
||||||
this.stack = error.stack;
|
this.stack = error.stack!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { noop } from '../util/util';
|
|||||||
/**
|
/**
|
||||||
* Options that are set when creating a new audio resource.
|
* Options that are set when creating a new audio resource.
|
||||||
*
|
*
|
||||||
* @template T - the type for the metadata (if any) of the audio resource
|
* @typeParam T - the type for the metadata (if any) of the audio resource
|
||||||
*/
|
*/
|
||||||
export interface CreateAudioResourceOptions<T> {
|
export interface CreateAudioResourceOptions<T> {
|
||||||
/**
|
/**
|
||||||
@@ -38,7 +38,7 @@ export interface CreateAudioResourceOptions<T> {
|
|||||||
/**
|
/**
|
||||||
* Represents an audio resource that can be played by an audio player.
|
* Represents an audio resource that can be played by an audio player.
|
||||||
*
|
*
|
||||||
* @template T - the type for the metadata (if any) of the audio resource
|
* @typeParam T - the type for the metadata (if any) of the audio resource
|
||||||
*/
|
*/
|
||||||
export class AudioResource<T = unknown> {
|
export class AudioResource<T = unknown> {
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +73,7 @@ export class AudioResource<T = unknown> {
|
|||||||
/**
|
/**
|
||||||
* The audio player that the resource is subscribed to, if any.
|
* The audio player that the resource is subscribed to, if any.
|
||||||
*/
|
*/
|
||||||
public audioPlayer?: AudioPlayer;
|
public audioPlayer?: AudioPlayer | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The playback duration of this audio resource, given in milliseconds.
|
* The playback duration of this audio resource, given in milliseconds.
|
||||||
@@ -204,7 +204,7 @@ export function inferStreamType(stream: Readable): {
|
|||||||
* @param input - The resource to play
|
* @param input - The resource to play
|
||||||
* @param options - Configurable options for creating the resource
|
* @param options - Configurable options for creating the resource
|
||||||
*
|
*
|
||||||
* @template T - the type for the metadata (if any) of the audio resource
|
* @typeParam T - the type for the metadata (if any) of the audio resource
|
||||||
*/
|
*/
|
||||||
export function createAudioResource<T>(
|
export function createAudioResource<T>(
|
||||||
input: string | Readable,
|
input: string | Readable,
|
||||||
@@ -228,7 +228,7 @@ export function createAudioResource<T>(
|
|||||||
* @param input - The resource to play
|
* @param input - The resource to play
|
||||||
* @param options - Configurable options for creating the resource
|
* @param options - Configurable options for creating the resource
|
||||||
*
|
*
|
||||||
* @template T - the type for the metadata (if any) of the audio resource
|
* @typeParam T - the type for the metadata (if any) of the audio resource
|
||||||
*/
|
*/
|
||||||
export function createAudioResource<T extends null | undefined>(
|
export function createAudioResource<T extends null | undefined>(
|
||||||
input: string | Readable,
|
input: string | Readable,
|
||||||
@@ -248,7 +248,7 @@ export function createAudioResource<T extends null | undefined>(
|
|||||||
* @param input - The resource to play
|
* @param input - The resource to play
|
||||||
* @param options - Configurable options for creating the resource
|
* @param options - Configurable options for creating the resource
|
||||||
*
|
*
|
||||||
* @template T - the type for the metadata (if any) of the audio resource
|
* @typeParam T - the type for the metadata (if any) of the audio resource
|
||||||
*/
|
*/
|
||||||
export function createAudioResource<T>(
|
export function createAudioResource<T>(
|
||||||
input: string | Readable,
|
input: string | Readable,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export interface CreateVoiceConnectionOptions {
|
|||||||
* If true, debug messages will be enabled for the voice connection and its
|
* If true, debug messages will be enabled for the voice connection and its
|
||||||
* related components. Defaults to false.
|
* related components. Defaults to false.
|
||||||
*/
|
*/
|
||||||
debug?: boolean;
|
debug?: boolean | undefined;
|
||||||
|
|
||||||
adapterCreator: DiscordGatewayAdapterCreator;
|
adapterCreator: DiscordGatewayAdapterCreator;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export interface NetworkingReadyState {
|
|||||||
udp: VoiceUDPSocket;
|
udp: VoiceUDPSocket;
|
||||||
connectionOptions: ConnectionOptions;
|
connectionOptions: ConnectionOptions;
|
||||||
connectionData: ConnectionData;
|
connectionData: ConnectionData;
|
||||||
preparedPacket?: Buffer;
|
preparedPacket?: Buffer | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +94,7 @@ export interface NetworkingResumingState {
|
|||||||
udp: VoiceUDPSocket;
|
udp: VoiceUDPSocket;
|
||||||
connectionOptions: ConnectionOptions;
|
connectionOptions: ConnectionOptions;
|
||||||
connectionData: ConnectionData;
|
connectionData: ConnectionData;
|
||||||
preparedPacket?: Buffer;
|
preparedPacket?: Buffer | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,7 +155,7 @@ export interface Networking extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Debug event for Networking.
|
* Debug event for Networking.
|
||||||
*
|
*
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'debug', listener: (message: string) => void): this;
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
on(event: 'error', listener: (error: Error) => void): this;
|
on(event: 'error', listener: (error: Error) => void): this;
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ export interface VoiceWebSocket extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Debug event for VoiceWebSocket.
|
* Debug event for VoiceWebSocket.
|
||||||
*
|
*
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'debug', listener: (message: string) => void): this;
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
/**
|
/**
|
||||||
* Packet event.
|
* Packet event.
|
||||||
*
|
*
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'packet', listener: (packet: any) => void): this;
|
on(event: 'packet', listener: (packet: any) => void): this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { EventEmitter } from 'node:events';
|
|||||||
export interface SpeakingMap extends EventEmitter {
|
export interface SpeakingMap extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* Emitted when a user starts speaking.
|
* Emitted when a user starts speaking.
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'start', listener: (userId: string) => void): this;
|
on(event: 'start', listener: (userId: string) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a user ends speaking.
|
* Emitted when a user ends speaking.
|
||||||
* @event
|
* @eventProperty
|
||||||
*/
|
*/
|
||||||
on(event: 'end', listener: (userId: string) => void): this;
|
on(event: 'end', listener: (userId: string) => void): this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
|
||||||
"exactOptionalPropertyTypes": false
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/website/.env.development
Normal file
1
packages/website/.env.development
Normal file
@@ -0,0 +1 @@
|
|||||||
|
NEXT_PUBLIC_LOCAL_DEV=true
|
||||||
@@ -5,15 +5,16 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"build": "yarn build:css && yarn build:next",
|
"build:local": "yarn run --top-level docs --force && yarn build:prod",
|
||||||
|
"build:prod": "yarn build:css && yarn build:next",
|
||||||
"build:next": "next build",
|
"build:next": "next build",
|
||||||
"build:css": "yarn generate:css",
|
"build:css": "yarn generate:css",
|
||||||
"dev": "concurrently 'yarn dev:css' 'yarn dev:next'",
|
"dev": "yarn run --top-level docs && concurrently 'yarn dev:css' 'yarn dev:next'",
|
||||||
"dev:next": "next dev",
|
"dev:next": "next dev",
|
||||||
"dev:css": "yarn generate:css --watch",
|
"dev:css": "yarn generate:css --watch",
|
||||||
"generate:css": "unocss 'src/**/*.tsx' --out-file ./src/styles/unocss.css",
|
"generate:css": "unocss 'src/**/*.tsx' --out-file ./src/styles/unocss.css",
|
||||||
"lint": "prettier --check . && eslint src --ext mjs,js,ts,tsx",
|
"lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts,tsx",
|
||||||
"format": "prettier --write . && eslint src --ext mjs,js,ts,tsx --fix"
|
"format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts,tsx --fix"
|
||||||
},
|
},
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
@@ -47,12 +48,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@microsoft/api-extractor-model": "^7.22.1",
|
"@emotion/react": "^11.10.0",
|
||||||
|
"@emotion/server": "^11.10.0",
|
||||||
|
"@mantine/core": "^5.2.0",
|
||||||
|
"@mantine/hooks": "^5.2.0",
|
||||||
|
"@mantine/next": "^5.2.0",
|
||||||
|
"@mantine/nprogress": "^5.2.0",
|
||||||
|
"@mantine/spotlight": "^5.2.0",
|
||||||
|
"@microsoft/api-extractor-model": "^7.23.1",
|
||||||
"@microsoft/tsdoc": "0.14.1",
|
"@microsoft/tsdoc": "0.14.1",
|
||||||
"@microsoft/tsdoc-config": "0.16.1",
|
"@microsoft/tsdoc-config": "0.16.1",
|
||||||
"@vscode/codicons": "^0.0.31",
|
"@vscode/codicons": "^0.0.32",
|
||||||
"framer-motion": "^6.5.1",
|
"next": "^12.2.5",
|
||||||
"next": "^12.2.3",
|
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-icons": "^4.4.0",
|
"react-icons": "^4.4.0",
|
||||||
@@ -60,37 +67,32 @@
|
|||||||
"sharp": "^0.30.7"
|
"sharp": "^0.30.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/cypress": "^8.0.3",
|
|
||||||
"@testing-library/dom": "^8.16.0",
|
|
||||||
"@testing-library/jest-dom": "^5.16.4",
|
|
||||||
"@testing-library/react": "^13.3.0",
|
"@testing-library/react": "^13.3.0",
|
||||||
"@testing-library/user-event": "^14.3.0",
|
"@testing-library/user-event": "^14.4.3",
|
||||||
"@types/node": "^16.11.46",
|
"@types/node": "^16.11.52",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/react-syntax-highlighter": "^15.5.4",
|
"@types/react-syntax-highlighter": "^15.5.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||||
"@typescript-eslint/parser": "^5.31.0",
|
"@typescript-eslint/parser": "^5.33.1",
|
||||||
"@unocss/cli": "^0.44.7",
|
"@unocss/cli": "^0.45.9",
|
||||||
"@unocss/preset-web-fonts": "^0.44.7",
|
"@unocss/preset-web-fonts": "^0.45.9",
|
||||||
"@unocss/reset": "^0.44.7",
|
"@unocss/reset": "^0.45.9",
|
||||||
"@vitejs/plugin-react": "^2.0.0",
|
"@vitejs/plugin-react": "^2.0.1",
|
||||||
"c8": "^7.12.0",
|
"@vitest/coverage-c8": "^0.22.1",
|
||||||
"concurrently": "^7.3.0",
|
"concurrently": "^7.3.0",
|
||||||
"cypress": "^10.3.1",
|
"eslint": "^8.22.0",
|
||||||
"eslint": "^8.20.0",
|
|
||||||
"eslint-config-marine": "^9.4.1",
|
"eslint-config-marine": "^9.4.1",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-import-resolver-typescript": "^3.3.0",
|
"eslint-import-resolver-typescript": "^3.4.2",
|
||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"eslint-plugin-react": "^7.30.1",
|
"eslint-plugin-react": "^7.30.1",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"happy-dom": "^6.0.4",
|
"happy-dom": "^6.0.4",
|
||||||
"msw": "^0.44.2",
|
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"unocss": "^0.44.7",
|
"unocss": "^0.45.9",
|
||||||
"vercel": "^27.3.1",
|
"vercel": "^28.1.0",
|
||||||
"vitest": "^0.19.1"
|
"vitest": "^0.22.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
|
|||||||
381
packages/website/src/DocModel/ApiNodeJSONEncoder.ts
Normal file
381
packages/website/src/DocModel/ApiNodeJSONEncoder.ts
Normal file
@@ -0,0 +1,381 @@
|
|||||||
|
import {
|
||||||
|
ApiModel,
|
||||||
|
ApiDeclaredItem,
|
||||||
|
ApiPropertyItem,
|
||||||
|
ApiMethod,
|
||||||
|
ApiParameterListMixin,
|
||||||
|
ApiTypeParameterListMixin,
|
||||||
|
ApiClass,
|
||||||
|
ApiFunction,
|
||||||
|
ApiItemKind,
|
||||||
|
ApiTypeAlias,
|
||||||
|
ApiEnum,
|
||||||
|
ApiInterface,
|
||||||
|
ApiMethodSignature,
|
||||||
|
ApiPropertySignature,
|
||||||
|
ApiVariable,
|
||||||
|
ApiItem,
|
||||||
|
ApiConstructor,
|
||||||
|
ApiItemContainerMixin,
|
||||||
|
} from '@microsoft/api-extractor-model';
|
||||||
|
import { generateTypeParamData } from './TypeParameterMixin';
|
||||||
|
import { Visibility } from './Visibility';
|
||||||
|
import { createCommentNode } from './comment';
|
||||||
|
import type { DocBlockJSON } from './comment/CommentBlock';
|
||||||
|
import type { AnyDocNodeJSON } from './comment/CommentNode';
|
||||||
|
import { DocNodeContainerJSON, nodeContainer } from './comment/CommentNodeContainer';
|
||||||
|
import {
|
||||||
|
generatePath,
|
||||||
|
genParameter,
|
||||||
|
genReference,
|
||||||
|
genToken,
|
||||||
|
resolveName,
|
||||||
|
TokenDocumentation,
|
||||||
|
} from '~/util/parse.server';
|
||||||
|
|
||||||
|
export interface ReferenceData {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InheritanceData {
|
||||||
|
parentName: string;
|
||||||
|
path: string;
|
||||||
|
parentKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiInheritableJSON {
|
||||||
|
inheritanceData: InheritanceData | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiItemJSON {
|
||||||
|
kind: string;
|
||||||
|
name: string;
|
||||||
|
referenceData: ReferenceData;
|
||||||
|
excerpt: string;
|
||||||
|
excerptTokens: TokenDocumentation[];
|
||||||
|
remarks: DocNodeContainerJSON | null;
|
||||||
|
summary: DocNodeContainerJSON | null;
|
||||||
|
deprecated: DocNodeContainerJSON | null;
|
||||||
|
comment: AnyDocNodeJSON | null;
|
||||||
|
containerKey: string;
|
||||||
|
path: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiPropertyItemJSON extends ApiItemJSON, ApiInheritableJSON {
|
||||||
|
propertyTypeTokens: TokenDocumentation[];
|
||||||
|
readonly: boolean;
|
||||||
|
optional: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiTypeParameterListJSON {
|
||||||
|
typeParameters: ApiTypeParameterJSON[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiTypeParameterJSON {
|
||||||
|
name: string;
|
||||||
|
constraintTokens: TokenDocumentation[];
|
||||||
|
defaultTokens: TokenDocumentation[];
|
||||||
|
optional: boolean;
|
||||||
|
commentBlock: DocBlockJSON | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiParameterListJSON {
|
||||||
|
parameters: ApiParameterJSON[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiMethodSignatureJSON
|
||||||
|
extends ApiItemJSON,
|
||||||
|
ApiTypeParameterListJSON,
|
||||||
|
ApiParameterListJSON,
|
||||||
|
ApiInheritableJSON {
|
||||||
|
returnTypeTokens: TokenDocumentation[];
|
||||||
|
optional: boolean;
|
||||||
|
overloadIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiMethodJSON extends ApiMethodSignatureJSON {
|
||||||
|
static: boolean;
|
||||||
|
visibility: Visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiParameterJSON {
|
||||||
|
name: string;
|
||||||
|
isOptional: boolean;
|
||||||
|
tokens: TokenDocumentation[];
|
||||||
|
paramCommentBlock: DocBlockJSON | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiClassJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||||
|
constructor: ApiConstructorJSON | null;
|
||||||
|
properties: ApiPropertyItemJSON[];
|
||||||
|
methods: ApiMethodJSON[];
|
||||||
|
extendsTokens: TokenDocumentation[];
|
||||||
|
implementsTokens: TokenDocumentation[][];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiTypeAliasJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||||
|
typeTokens: TokenDocumentation[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EnumMemberData {
|
||||||
|
name: string;
|
||||||
|
initializerTokens: TokenDocumentation[];
|
||||||
|
summary: DocNodeContainerJSON | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiEnumJSON extends ApiItemJSON {
|
||||||
|
members: EnumMemberData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiInterfaceJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||||
|
properties: ApiPropertyItemJSON[];
|
||||||
|
methods: ApiMethodSignatureJSON[];
|
||||||
|
extendsTokens: TokenDocumentation[][] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiVariableJSON extends ApiItemJSON {
|
||||||
|
typeTokens: TokenDocumentation[];
|
||||||
|
readonly: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiFunctionJSON extends ApiItemJSON, ApiTypeParameterListJSON, ApiParameterListJSON {
|
||||||
|
returnTypeTokens: TokenDocumentation[];
|
||||||
|
overloadIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiConstructorJSON extends ApiItemJSON, ApiParameterListJSON {
|
||||||
|
protected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||||
|
export class ApiNodeJSONEncoder {
|
||||||
|
public static encode(model: ApiModel, node: ApiItem) {
|
||||||
|
if (!(node instanceof ApiDeclaredItem)) {
|
||||||
|
throw new Error(`Cannot serialize node of type ${node.kind}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (node.kind) {
|
||||||
|
case ApiItemKind.Class:
|
||||||
|
return this.encodeClass(model, node as ApiClass);
|
||||||
|
case ApiItemKind.Function:
|
||||||
|
return this.encodeFunction(model, node as ApiFunction);
|
||||||
|
case ApiItemKind.Interface:
|
||||||
|
return this.encodeInterface(model, node as ApiInterface);
|
||||||
|
case ApiItemKind.TypeAlias:
|
||||||
|
return this.encodeTypeAlias(model, node as ApiTypeAlias);
|
||||||
|
case ApiItemKind.Enum:
|
||||||
|
return this.encodeEnum(model, node as ApiEnum);
|
||||||
|
case ApiItemKind.Variable:
|
||||||
|
return this.encodeVariable(model, node as ApiVariable);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown API item kind: ${node.kind}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeItem(model: ApiModel, item: ApiDeclaredItem): 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),
|
||||||
|
excerpt: item.excerpt.text,
|
||||||
|
excerptTokens: item.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
remarks: item.tsdocComment?.remarksBlock
|
||||||
|
? (createCommentNode(item.tsdocComment.remarksBlock, model, item.parent) as DocNodeContainerJSON)
|
||||||
|
: null,
|
||||||
|
summary: item.tsdocComment?.summarySection
|
||||||
|
? (createCommentNode(item.tsdocComment.summarySection, model, item.parent) as DocNodeContainerJSON)
|
||||||
|
: null,
|
||||||
|
deprecated: item.tsdocComment?.deprecatedBlock
|
||||||
|
? (createCommentNode(item.tsdocComment.deprecatedBlock, model, item.parent) as DocNodeContainerJSON)
|
||||||
|
: null,
|
||||||
|
path,
|
||||||
|
containerKey: item.containerKey,
|
||||||
|
comment: item.tsdocComment ? createCommentNode(item.tsdocComment, model, item.parent) : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeParameterList(
|
||||||
|
model: ApiModel,
|
||||||
|
item: ApiParameterListMixin & ApiDeclaredItem,
|
||||||
|
): { parameters: ApiParameterJSON[] } {
|
||||||
|
return {
|
||||||
|
parameters: item.parameters.map((param) => genParameter(model, param)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeTypeParameterList(model: ApiModel, item: ApiTypeParameterListMixin & ApiDeclaredItem) {
|
||||||
|
return {
|
||||||
|
typeParameters: item.typeParameters.map((param) => generateTypeParamData(model, param, item.parent)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeProperty(
|
||||||
|
model: ApiModel,
|
||||||
|
item: ApiPropertyItem,
|
||||||
|
parent: ApiItemContainerMixin,
|
||||||
|
): ApiPropertyItemJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeInheritanceData(item, parent),
|
||||||
|
propertyTypeTokens: item.propertyTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
readonly: item.isReadonly,
|
||||||
|
optional: item.isOptional,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeInheritanceData(item: ApiDeclaredItem, parent: ApiItemContainerMixin): ApiInheritableJSON {
|
||||||
|
return {
|
||||||
|
inheritanceData:
|
||||||
|
item.parent && item.parent.containerKey !== parent.containerKey
|
||||||
|
? {
|
||||||
|
parentKey: item.parent.containerKey,
|
||||||
|
parentName: item.parent.displayName,
|
||||||
|
path: generatePath(item.parent.getHierarchy()),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeFunction(model: ApiModel, item: ApiFunction) {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeParameterList(model, item),
|
||||||
|
...this.encodeTypeParameterList(model, item),
|
||||||
|
returnTypeTokens: item.returnTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
overloadIndex: item.overloadIndex,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeMethodSignature(
|
||||||
|
model: ApiModel,
|
||||||
|
item: ApiMethodSignature,
|
||||||
|
parent: ApiItemContainerMixin,
|
||||||
|
): ApiMethodSignatureJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeFunction(model, item),
|
||||||
|
...this.encodeInheritanceData(item, parent),
|
||||||
|
optional: item.isOptional,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeMethod(model: ApiModel, item: ApiMethod, parent: ApiItemContainerMixin): ApiMethodJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeMethodSignature(model, item, parent),
|
||||||
|
static: item.isStatic,
|
||||||
|
visibility: item.isProtected ? Visibility.Protected : Visibility.Public,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeClass(model: ApiModel, item: ApiClass): 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));
|
||||||
|
break;
|
||||||
|
case ApiItemKind.Property:
|
||||||
|
properties.push(this.encodeProperty(model, member as ApiPropertyItem, item));
|
||||||
|
break;
|
||||||
|
case ApiItemKind.Constructor:
|
||||||
|
constructor = member as ApiConstructor;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeTypeParameterList(model, item),
|
||||||
|
constructor: constructor ? this.encodeConstructor(model, constructor) : null,
|
||||||
|
extendsTokens: extendsExcerpt ? extendsExcerpt.spannedTokens.map((token) => genToken(model, token)) : [],
|
||||||
|
implementsTokens: item.implementsTypes.map((excerpt) =>
|
||||||
|
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
),
|
||||||
|
methods,
|
||||||
|
properties,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeTypeAlias(model: ApiModel, item: ApiTypeAlias): ApiTypeAliasJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeTypeParameterList(model, item),
|
||||||
|
typeTokens: item.typeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeEnum(model: ApiModel, item: ApiEnum): ApiEnumJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
members: item.members.map((member) => ({
|
||||||
|
name: member.name,
|
||||||
|
initializerTokens: member.initializerExcerpt?.spannedTokens.map((token) => genToken(model, token)) ?? [],
|
||||||
|
summary: member.tsdocComment ? nodeContainer(member.tsdocComment.summarySection, model, member) : null,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeInterface(model: ApiModel, item: ApiInterface): 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));
|
||||||
|
break;
|
||||||
|
case ApiItemKind.PropertySignature:
|
||||||
|
properties.push(this.encodeProperty(model, member as ApiPropertySignature, item));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeTypeParameterList(model, item),
|
||||||
|
extendsTokens: item.extendsTypes.map((excerpt) =>
|
||||||
|
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
),
|
||||||
|
methods,
|
||||||
|
properties,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeVariable(model: ApiModel, item: ApiVariable): ApiVariableJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
typeTokens: item.variableTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||||
|
readonly: item.isReadonly,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static encodeConstructor(model: ApiModel, item: ApiConstructor): ApiConstructorJSON {
|
||||||
|
return {
|
||||||
|
...this.encodeItem(model, item),
|
||||||
|
...this.encodeParameterList(model, item),
|
||||||
|
protected: item.isProtected,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import {
|
|
||||||
type ApiClass,
|
|
||||||
type ApiModel,
|
|
||||||
ApiItemKind,
|
|
||||||
type ApiMethod,
|
|
||||||
type ApiPropertyItem,
|
|
||||||
} from '@microsoft/api-extractor-model';
|
|
||||||
import { DocItem } from './DocItem';
|
|
||||||
import { DocMethod } from './DocMethod';
|
|
||||||
import { DocProperty } from './DocProperty';
|
|
||||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
|
||||||
import { type TokenDocumentation, genToken } from '~/util/parse.server';
|
|
||||||
|
|
||||||
export class DocClass extends TypeParameterMixin(DocItem<ApiClass>) {
|
|
||||||
public readonly extendsTokens: TokenDocumentation[] | null;
|
|
||||||
public readonly implementsTokens: TokenDocumentation[][];
|
|
||||||
public readonly methods: DocMethod[] = [];
|
|
||||||
public readonly properties: DocProperty[] = [];
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: ApiClass) {
|
|
||||||
super(model, item);
|
|
||||||
const extendsExcerpt = item.extendsType?.excerpt;
|
|
||||||
|
|
||||||
this.extendsTokens = extendsExcerpt
|
|
||||||
? extendsExcerpt.spannedTokens.map((token) => genToken(this.model, token))
|
|
||||||
: null;
|
|
||||||
|
|
||||||
this.implementsTokens = item.implementsTypes.map((excerpt) =>
|
|
||||||
excerpt.excerpt.spannedTokens.map((token) => genToken(this.model, token)),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const member of item.members) {
|
|
||||||
switch (member.kind) {
|
|
||||||
case ApiItemKind.Method:
|
|
||||||
this.methods.push(new DocMethod(this.model, member as ApiMethod));
|
|
||||||
break;
|
|
||||||
case ApiItemKind.Property:
|
|
||||||
this.properties.push(new DocProperty(this.model, member as ApiPropertyItem));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override toJSON() {
|
|
||||||
return {
|
|
||||||
...super.toJSON(),
|
|
||||||
extendsTokens: this.extendsTokens,
|
|
||||||
implementsTokens: this.implementsTokens,
|
|
||||||
methods: this.methods.map((method) => method.toJSON()),
|
|
||||||
properties: this.properties.map((prop) => prop.toJSON()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import type { ApiEnum, ApiModel } from '@microsoft/api-extractor-model';
|
|
||||||
import { DocItem } from './DocItem';
|
|
||||||
import { CommentNodeContainer } from './comment/CommentNodeContainer';
|
|
||||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
|
||||||
|
|
||||||
export interface EnumMemberData {
|
|
||||||
name: string;
|
|
||||||
initializerTokens: TokenDocumentation[];
|
|
||||||
summary: ReturnType<DocItem['toJSON']>['summary'];
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DocEnum extends DocItem<ApiEnum> {
|
|
||||||
public readonly members: EnumMemberData[] = [];
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: ApiEnum) {
|
|
||||||
super(model, item);
|
|
||||||
|
|
||||||
this.members = item.members.map((member) => ({
|
|
||||||
name: member.name,
|
|
||||||
initializerTokens: member.initializerExcerpt?.spannedTokens.map((token) => genToken(this.model, token)) ?? [],
|
|
||||||
summary: member.tsdocComment
|
|
||||||
? new CommentNodeContainer(member.tsdocComment.summarySection, model, member).toJSON()
|
|
||||||
: null,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override toJSON() {
|
|
||||||
return {
|
|
||||||
...super.toJSON(),
|
|
||||||
members: this.members,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import type { ApiFunction, ApiModel, ApiParameterListMixin } from '@microsoft/api-extractor-model';
|
|
||||||
import { DocItem } from './DocItem';
|
|
||||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
|
||||||
import { type TokenDocumentation, genToken, genParameter, ParameterDocumentation } from '~/util/parse.server';
|
|
||||||
|
|
||||||
export class DocFunction extends TypeParameterMixin(DocItem<ApiFunction>) {
|
|
||||||
public readonly returnTypeTokens: TokenDocumentation[];
|
|
||||||
public readonly overloadIndex: number;
|
|
||||||
public readonly parameters: ParameterDocumentation[];
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: ApiFunction) {
|
|
||||||
super(model, item);
|
|
||||||
this.returnTypeTokens = item.returnTypeExcerpt.spannedTokens.map((token) => genToken(this.model, token));
|
|
||||||
this.overloadIndex = item.overloadIndex;
|
|
||||||
this.parameters = (item as ApiParameterListMixin).parameters.map((param) => genParameter(this.model, param));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override toJSON() {
|
|
||||||
return {
|
|
||||||
...super.toJSON(),
|
|
||||||
parameters: this.parameters,
|
|
||||||
returnTypeTokens: this.returnTypeTokens,
|
|
||||||
overloadIndex: this.overloadIndex,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import { DocItem } from './DocItem';
|
|
||||||
import { DocMethodSignature } from './DocMethodSignature';
|
|
||||||
import { DocProperty } from './DocProperty';
|
|
||||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
|
||||||
import {
|
|
||||||
ApiInterface,
|
|
||||||
ApiItemKind,
|
|
||||||
ApiMethodSignature,
|
|
||||||
ApiModel,
|
|
||||||
ApiPropertySignature,
|
|
||||||
} from '~/util/api-extractor.server';
|
|
||||||
import { type TokenDocumentation, genToken } from '~/util/parse.server';
|
|
||||||
|
|
||||||
export class DocInterface extends TypeParameterMixin(DocItem<ApiInterface>) {
|
|
||||||
public readonly extendsTokens: TokenDocumentation[][] | null;
|
|
||||||
public readonly methods: DocMethodSignature[] = [];
|
|
||||||
public readonly properties: DocProperty[] = [];
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: ApiInterface) {
|
|
||||||
super(model, item);
|
|
||||||
|
|
||||||
this.extendsTokens = item.extendsTypes.map((excerpt) =>
|
|
||||||
excerpt.excerpt.spannedTokens.map((token) => genToken(this.model, token)),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const member of item.members) {
|
|
||||||
switch (member.kind) {
|
|
||||||
case ApiItemKind.MethodSignature:
|
|
||||||
this.methods.push(new DocMethodSignature(this.model, member as ApiMethodSignature));
|
|
||||||
break;
|
|
||||||
case ApiItemKind.PropertySignature:
|
|
||||||
this.properties.push(new DocProperty(this.model, member as ApiPropertySignature));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override toJSON() {
|
|
||||||
return {
|
|
||||||
...super.toJSON(),
|
|
||||||
extendsTokens: this.extendsTokens,
|
|
||||||
methods: this.methods.map((method) => method.toJSON()),
|
|
||||||
properties: this.properties.map((prop) => prop.toJSON()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import type { ApiModel, ApiDeclaredItem } from '@microsoft/api-extractor-model';
|
|
||||||
import { CommentNodeContainer } from './comment/CommentNodeContainer';
|
|
||||||
import type { ReferenceData } from '~/util/model.server';
|
|
||||||
import { resolveName, genReference, TokenDocumentation, genToken } from '~/util/parse.server';
|
|
||||||
|
|
||||||
export type DocItemConstructor<T = DocItem> = new (...args: any[]) => T;
|
|
||||||
|
|
||||||
export class DocItem<T extends ApiDeclaredItem = ApiDeclaredItem> {
|
|
||||||
public readonly item: T;
|
|
||||||
public readonly name: string;
|
|
||||||
public readonly referenceData: ReferenceData;
|
|
||||||
public readonly model: ApiModel;
|
|
||||||
public readonly excerpt: string;
|
|
||||||
public readonly excerptTokens: TokenDocumentation[] = [];
|
|
||||||
public readonly kind: string;
|
|
||||||
public readonly remarks: CommentNodeContainer | null;
|
|
||||||
public readonly summary: CommentNodeContainer | null;
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: T) {
|
|
||||||
this.item = item;
|
|
||||||
this.kind = item.kind;
|
|
||||||
this.model = model;
|
|
||||||
this.name = resolveName(item);
|
|
||||||
this.referenceData = genReference(item);
|
|
||||||
this.excerpt = item.excerpt.text;
|
|
||||||
this.excerptTokens = item.excerpt.spannedTokens.map((token) => genToken(model, token));
|
|
||||||
this.remarks = item.tsdocComment?.remarksBlock
|
|
||||||
? new CommentNodeContainer(item.tsdocComment.remarksBlock.content, model, item.parent)
|
|
||||||
: null;
|
|
||||||
this.summary = item.tsdocComment?.summarySection
|
|
||||||
? new CommentNodeContainer(item.tsdocComment.summarySection, model, item.parent)
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public toJSON() {
|
|
||||||
return {
|
|
||||||
name: this.name,
|
|
||||||
referenceData: this.referenceData,
|
|
||||||
summary: this.summary?.toJSON() ?? null,
|
|
||||||
excerpt: this.excerpt,
|
|
||||||
excerptTokens: this.excerptTokens,
|
|
||||||
kind: this.kind,
|
|
||||||
remarks: this.remarks?.toJSON() ?? null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import type { ApiMethod, ApiModel } from '@microsoft/api-extractor-model';
|
|
||||||
import { DocFunction } from './DocFunction';
|
|
||||||
import { Visibility } from './Visibility';
|
|
||||||
|
|
||||||
export class DocMethod extends DocFunction {
|
|
||||||
public readonly static: boolean;
|
|
||||||
public readonly optional: boolean;
|
|
||||||
public readonly visibility: Visibility;
|
|
||||||
|
|
||||||
public constructor(model: ApiModel, item: ApiMethod) {
|
|
||||||
super(model, item);
|
|
||||||
this.static = item.isStatic;
|
|
||||||
this.optional = item.isOptional;
|
|
||||||
this.visibility = item.isProtected ? Visibility.Protected : Visibility.Public;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override toJSON() {
|
|
||||||
return {
|
|
||||||
...super.toJSON(),
|
|
||||||
static: this.static,
|
|
||||||
optional: this.optional,
|
|
||||||
visibility: this.visibility,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user