Skip to content

Commit 9a1d51e

Browse files
authored
Merge branch 'main' into main
2 parents 3eec8fa + 960a80d commit 9a1d51e

File tree

273 files changed

+5693
-6630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+5693
-6630
lines changed

apps/website/src/util/fetchDependencies.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function fetchDependencies({
2020

2121
return Object.entries<string>(parsedDependencies)
2222
.filter(([key]) => key.startsWith('@discordjs/') && !key.includes('api-extractor'))
23-
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${value.replaceAll('.', '-')}`);
23+
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${sanitizeVersion(value)}`);
2424
} catch {
2525
return [];
2626
}
@@ -36,8 +36,12 @@ export async function fetchDependencies({
3636

3737
return Object.entries<string>(parsedDependencies)
3838
.filter(([key]) => key.startsWith('@discordjs/') && !key.includes('api-extractor'))
39-
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${value.replaceAll('.', '-')}`);
39+
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${sanitizeVersion(value)}`);
4040
} catch {
4141
return [];
4242
}
4343
}
44+
45+
function sanitizeVersion(version: string) {
46+
return version.replaceAll('.', '-').replace(/^[\^~]/, '');
47+
}

packages/api-extractor/src/generators/ApiModelGenerator.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ interface DocgenEventJson {
114114
}
115115

116116
interface DocgenParamJson {
117-
default?: string;
117+
default?: boolean | number | string;
118118
description: string;
119119
name: string;
120120
nullable?: boolean;
@@ -155,7 +155,7 @@ interface DocgenMethodJson {
155155
interface DocgenPropertyJson {
156156
abstract?: boolean;
157157
access?: DocgenAccess;
158-
default?: string;
158+
default?: boolean | number | string;
159159
deprecated?: DocgenDeprecated;
160160
description: string;
161161
meta: DocgenMetaJson;
@@ -1264,7 +1264,7 @@ export class ApiModelGenerator {
12641264
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
12651265
const docComment: tsdoc.DocComment | undefined = jsDoc
12661266
? this._tsDocParser.parseString(
1267-
`/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}\n${
1267+
`/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}${jsDoc.default ? ` (default: ${this._escapeSpecialChars(jsDoc.default)})` : ''}\n${
12681268
'see' in jsDoc ? jsDoc.see.map((see) => ` * @see ${see}\n`).join('') : ''
12691269
}${'readonly' in jsDoc && jsDoc.readonly ? ' * @readonly\n' : ''}${
12701270
'deprecated' in jsDoc && jsDoc.deprecated
@@ -1342,7 +1342,7 @@ export class ApiModelGenerator {
13421342
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
13431343
const docComment: tsdoc.DocComment | undefined = jsDoc
13441344
? this._tsDocParser.parseString(
1345-
`/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}\n${
1345+
`/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}${jsDoc.default ? ` (default: ${this._escapeSpecialChars(jsDoc.default)})` : ''}\n${
13461346
'see' in jsDoc ? jsDoc.see.map((see) => ` * @see ${see}\n`).join('') : ''
13471347
}${'readonly' in jsDoc && jsDoc.readonly ? ' * @readonly\n' : ''}${
13481348
'deprecated' in jsDoc && jsDoc.deprecated
@@ -1510,15 +1510,17 @@ export class ApiModelGenerator {
15101510
const excerptTokens: IExcerptToken[] = [
15111511
{
15121512
kind: ExcerptTokenKind.Content,
1513-
text: `on('${name}', (${
1514-
jsDoc.params?.length ? `${jsDoc.params[0]?.name}${jsDoc.params[0]?.nullable ? '?' : ''}: ` : ') => {})'
1513+
text: `public on(eventName: '${name}', listener: (${
1514+
jsDoc.params?.length
1515+
? `${jsDoc.params[0]?.name}${jsDoc.params[0]?.optional ? '?' : ''}: `
1516+
: ') => void): this;'
15151517
}`,
15161518
},
15171519
];
15181520
const parameters: IApiParameterOptions[] = [];
15191521
for (let index = 0; index < (jsDoc.params?.length ?? 0) - 1; index++) {
15201522
const parameter = jsDoc.params![index]!;
1521-
const newTokens = this._mapVarType(parameter.type);
1523+
const newTokens = this._mapVarType(parameter.type, parameter.nullable);
15221524
parameters.push({
15231525
parameterName: parameter.name,
15241526
parameterTypeTokenRange: {
@@ -1537,7 +1539,7 @@ export class ApiModelGenerator {
15371539

15381540
if (jsDoc.params?.length) {
15391541
const parameter = jsDoc.params![jsDoc.params.length - 1]!;
1540-
const newTokens = this._mapVarType(parameter.type);
1542+
const newTokens = this._mapVarType(parameter.type, parameter.nullable);
15411543
parameters.push({
15421544
parameterName: parameter.name,
15431545
parameterTypeTokenRange: {
@@ -1550,7 +1552,7 @@ export class ApiModelGenerator {
15501552
excerptTokens.push(...newTokens);
15511553
excerptTokens.push({
15521554
kind: ExcerptTokenKind.Content,
1553-
text: `) => {})`,
1555+
text: `) => void): this;`,
15541556
});
15551557
}
15561558

@@ -1746,6 +1748,14 @@ export class ApiModelGenerator {
17461748
return sourceLocation;
17471749
}
17481750

1751+
private _escapeSpecialChars(input: boolean | number | string) {
1752+
if (typeof input !== 'string') {
1753+
return input;
1754+
}
1755+
1756+
return input.replaceAll(/(?<char>[{}])/g, '\\$<char>');
1757+
}
1758+
17491759
private _fixLinkTags(input?: string): string | undefined {
17501760
return input
17511761
?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
@@ -1765,7 +1775,7 @@ export class ApiModelGenerator {
17651775
.replaceAll('* ', '\n * * ');
17661776
}
17671777

1768-
private _mapVarType(typey: DocgenVarTypeJson): IExcerptToken[] {
1778+
private _mapVarType(typey: DocgenVarTypeJson, nullable?: boolean): IExcerptToken[] {
17691779
const mapper = Array.isArray(typey) ? typey : (typey.types ?? []);
17701780
const lookup: { [K in ts.SyntaxKind]?: string } = {
17711781
[ts.SyntaxKind.ClassDeclaration]: 'class',
@@ -1808,7 +1818,22 @@ export class ApiModelGenerator {
18081818
{ kind: ExcerptTokenKind.Content, text: symbol ?? '' },
18091819
];
18101820
}, []);
1811-
return index === 0 ? result : [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
1821+
return index === 0
1822+
? mapper.length === 1 && (nullable || ('nullable' in typey && typey.nullable))
1823+
? [
1824+
...result,
1825+
{ kind: ExcerptTokenKind.Content, text: ' | ' },
1826+
{ kind: ExcerptTokenKind.Reference, text: 'null' },
1827+
]
1828+
: result
1829+
: index === mapper.length - 1 && (nullable || ('nullable' in typey && typey.nullable))
1830+
? [
1831+
{ kind: ExcerptTokenKind.Content, text: ' | ' },
1832+
...result,
1833+
{ kind: ExcerptTokenKind.Content, text: ' | ' },
1834+
{ kind: ExcerptTokenKind.Reference, text: 'null' },
1835+
]
1836+
: [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
18121837
})
18131838
.filter((excerpt) => excerpt.text.length);
18141839
}
@@ -1823,7 +1848,7 @@ export class ApiModelGenerator {
18231848
isOptional: Boolean(prop.nullable),
18241849
isReadonly: Boolean(prop.readonly),
18251850
docComment: this._tsDocParser.parseString(
1826-
`/**\n * ${this._fixLinkTags(prop.description) ?? ''}\n${
1851+
`/**\n * ${this._fixLinkTags(prop.description) ?? ''}${prop.default ? ` (default: ${this._escapeSpecialChars(prop.default)})` : ''}\n${
18271852
prop.see?.map((see) => ` * @see ${see}\n`).join('') ?? ''
18281853
}${prop.readonly ? ' * @readonly\n' : ''} */`,
18291854
).docComment,

packages/brokers/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [@discordjs/brokers@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/[email protected]...@discordjs/[email protected]) - (2024-09-01)
6+
7+
## Refactor
8+
9+
- **brokers:** Re-design API to make groups a constructor option (#10297) ([38a37b5](https://github.com/discordjs/discord.js/commit/38a37b5caf06913131c6dc2dc5cc258aecfe2266))
10+
- **brokers:** Make option props more correct (#10242) ([393ded4](https://github.com/discordjs/discord.js/commit/393ded4ea14e73b2bb42226f57896130329f88ca))
11+
- **BREAKING CHANGE:** Classes now take redis client as standalone parameter, various props from the base option interface moved to redis options
12+
513
# [@discordjs/brokers@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/[email protected]...@discordjs/[email protected]) - (2024-05-04)
614

715
## Bug Fixes

packages/brokers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
## Installation
2525

26-
**Node.js 18 or newer is required.**
26+
**Node.js 20 or newer is required.**
2727

2828
```sh
2929
npm install @discordjs/brokers

packages/brokers/cliff.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@ body = """
2828
**{{commit.scope}}:** \
2929
{% endif %}\
3030
{{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\
31+
{% if commit.github.username %} by @{{ commit.github.username }}{%- endif %}\
3132
{% if commit.breaking %}\
32-
{% for breakingChange in commit.footers %}\
33-
\n{% raw %} {% endraw %}- **{{ breakingChange.token }}{{ breakingChange.separator }}** {{ breakingChange.value }}\
33+
{% for footer in commit.footers %}\
34+
{% if footer.breaking %}\
35+
\n{% raw %} {% endraw %}- **{{ footer.token }}{{ footer.separator }}** {{ footer.value }}\
36+
{% endif %}\
3437
{% endfor %}\
3538
{% endif %}\
3639
{% endfor %}
37-
{% endfor %}\n
40+
{% endfor %}\
41+
{% if github.contributors | filter(attribute="is_first_time", value=true) | length %}\
42+
\n### New Contributors\n
43+
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}\
44+
* @{{ contributor.username }} made their first contribution in #{{ contributor.pr_number }}
45+
{% endfor %}\
46+
{% endif %}\n
3847
"""
3948
trim = true
4049
footer = ""

packages/brokers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "@discordjs/brokers",
4-
"version": "0.3.0",
4+
"version": "1.0.0",
55
"description": "Powerful set of message brokers",
66
"scripts": {
77
"test": "vitest run",
@@ -89,7 +89,7 @@
8989
"vitest": "^2.0.5"
9090
},
9191
"engines": {
92-
"node": ">=18"
92+
"node": ">=20"
9393
},
9494
"publishConfig": {
9595
"access": "public",

packages/builders/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [@discordjs/builders@1.9.0](https://github.com/discordjs/discord.js/compare/@discordjs/[email protected]...@discordjs/[email protected]) - (2024-09-01)
6+
7+
## Features
8+
9+
- User-installable apps (#10227) ([fc0b6f7](https://github.com/discordjs/discord.js/commit/fc0b6f7f8ebd94a4a05fac0c76e49b23752a8e65))
10+
- **builders:** Update to @sapphire/shapeshift v4 (#10291) ([2d5531f](https://github.com/discordjs/discord.js/commit/2d5531f35c6b4d70f83e46b99c284030108dcf5c))
11+
- **SlashCommandBuilder:** Add explicit command type when building (#10395) ([b2970bb](https://github.com/discordjs/discord.js/commit/b2970bb2dddf70d2d918fda825059315f35d23f3))
12+
- Premium buttons (#10353) ([4f59b74](https://github.com/discordjs/discord.js/commit/4f59b740d01b9ff2213949708a36e17da32b89c3))
13+
- Add user-installable apps support (#10348) ([9c76bbe](https://github.com/discordjs/discord.js/commit/9c76bbea172d49320f7fdac19ec1a43a49d05116))
14+
515
# [@discordjs/builders@1.8.2](https://github.com/discordjs/discord.js/compare/@discordjs/[email protected]...@discordjs/[email protected]) - (2024-06-02)
616

717
## Bug Fixes

packages/builders/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
## Installation
2525

26-
**Node.js 16.11.0 or newer is required.**
26+
**Node.js 18 or newer is required.**
2727

2828
```sh
2929
npm install @discordjs/builders

packages/builders/__tests__/components/actionRow.test.ts

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
import { describe, test, expect } from 'vitest';
88
import {
99
ActionRowBuilder,
10-
ButtonBuilder,
1110
createComponentBuilder,
11+
PrimaryButtonBuilder,
1212
StringSelectMenuBuilder,
1313
StringSelectMenuOptionBuilder,
1414
} from '../../src/index.js';
@@ -41,21 +41,14 @@ const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent>
4141
value: 'two',
4242
},
4343
],
44-
max_values: 10,
45-
min_values: 12,
44+
max_values: 2,
45+
min_values: 2,
4646
},
4747
],
4848
};
4949

5050
describe('Action Row Components', () => {
5151
describe('Assertion Tests', () => {
52-
test('GIVEN valid components THEN do not throw', () => {
53-
expect(() => new ActionRowBuilder().addComponents(new ButtonBuilder())).not.toThrowError();
54-
expect(() => new ActionRowBuilder().setComponents(new ButtonBuilder())).not.toThrowError();
55-
expect(() => new ActionRowBuilder().addComponents([new ButtonBuilder()])).not.toThrowError();
56-
expect(() => new ActionRowBuilder().setComponents([new ButtonBuilder()])).not.toThrowError();
57-
});
58-
5952
test('GIVEN valid JSON input THEN valid JSON output is given', () => {
6053
const actionRowData: APIActionRowComponent<APIMessageActionRowComponent> = {
6154
type: ComponentType.ActionRow,
@@ -72,22 +65,10 @@ describe('Action Row Components', () => {
7265
style: ButtonStyle.Link,
7366
url: 'https://google.com',
7467
},
75-
{
76-
type: ComponentType.StringSelect,
77-
placeholder: 'test',
78-
custom_id: 'test',
79-
options: [
80-
{
81-
label: 'option',
82-
value: 'option',
83-
},
84-
],
85-
},
8668
],
8769
};
8870

8971
expect(new ActionRowBuilder(actionRowData).toJSON()).toEqual(actionRowData);
90-
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
9172
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
9273
});
9374

@@ -120,24 +101,23 @@ describe('Action Row Components', () => {
120101
value: 'two',
121102
},
122103
],
123-
max_values: 10,
124-
min_values: 12,
104+
max_values: 1,
105+
min_values: 1,
125106
},
126107
],
127108
};
128109

129110
expect(new ActionRowBuilder(rowWithButtonData).toJSON()).toEqual(rowWithButtonData);
130111
expect(new ActionRowBuilder(rowWithSelectMenuData).toJSON()).toEqual(rowWithSelectMenuData);
131-
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
132112
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
133113
});
134114

135115
test('GIVEN valid builder options THEN valid JSON output is given 2', () => {
136-
const button = new ButtonBuilder().setLabel('test').setStyle(ButtonStyle.Primary).setCustomId('123');
116+
const button = new PrimaryButtonBuilder().setLabel('test').setCustomId('123');
137117
const selectMenu = new StringSelectMenuBuilder()
138118
.setCustomId('1234')
139-
.setMaxValues(10)
140-
.setMinValues(12)
119+
.setMaxValues(2)
120+
.setMinValues(2)
141121
.setOptions(
142122
new StringSelectMenuOptionBuilder().setLabel('one').setValue('one'),
143123
new StringSelectMenuOptionBuilder().setLabel('two').setValue('two'),
@@ -147,10 +127,39 @@ describe('Action Row Components', () => {
147127
new StringSelectMenuOptionBuilder().setLabel('two').setValue('two'),
148128
]);
149129

150-
expect(new ActionRowBuilder().addComponents(button).toJSON()).toEqual(rowWithButtonData);
151-
expect(new ActionRowBuilder().addComponents(selectMenu).toJSON()).toEqual(rowWithSelectMenuData);
152-
expect(new ActionRowBuilder().addComponents([button]).toJSON()).toEqual(rowWithButtonData);
153-
expect(new ActionRowBuilder().addComponents([selectMenu]).toJSON()).toEqual(rowWithSelectMenuData);
130+
expect(new ActionRowBuilder().addPrimaryButtonComponents(button).toJSON()).toEqual(rowWithButtonData);
131+
expect(new ActionRowBuilder().addStringSelectMenuComponent(selectMenu).toJSON()).toEqual(rowWithSelectMenuData);
132+
expect(new ActionRowBuilder().addPrimaryButtonComponents([button]).toJSON()).toEqual(rowWithButtonData);
133+
});
134+
135+
test('GIVEN 2 select menus THEN it throws', () => {
136+
const selectMenu = new StringSelectMenuBuilder()
137+
.setCustomId('1234')
138+
.setOptions(
139+
new StringSelectMenuOptionBuilder().setLabel('one').setValue('one'),
140+
new StringSelectMenuOptionBuilder().setLabel('two').setValue('two'),
141+
);
142+
143+
expect(() =>
144+
new ActionRowBuilder()
145+
.addStringSelectMenuComponent(selectMenu)
146+
.addStringSelectMenuComponent(selectMenu)
147+
.toJSON(),
148+
).toThrowError();
149+
});
150+
151+
test('GIVEN a button and a select menu THEN it throws', () => {
152+
const button = new PrimaryButtonBuilder().setLabel('test').setCustomId('123');
153+
const selectMenu = new StringSelectMenuBuilder()
154+
.setCustomId('1234')
155+
.setOptions(
156+
new StringSelectMenuOptionBuilder().setLabel('one').setValue('one'),
157+
new StringSelectMenuOptionBuilder().setLabel('two').setValue('two'),
158+
);
159+
160+
expect(() =>
161+
new ActionRowBuilder().addStringSelectMenuComponent(selectMenu).addPrimaryButtonComponents(button).toJSON(),
162+
).toThrowError();
154163
});
155164
});
156165
});

0 commit comments

Comments
 (0)