Skip to content

Commit c71228a

Browse files
AsadHumayunalmeidx
andauthored
feat(structures): add SKU structure (#11389)
* feat(structures): update barrel exports in preparation for SKU structure * feat(structures): add SKUFlagsBitField to /bitfields * feat(structures): add SKU structure * chore(structures): correct barrel exports * chore(structures): export SKUBitfieldFlags * docs(structures): correct usage of see/link doc comments * chore(structures): correct usage of bitfields in extending classes * docs(structures): remove unnecessary links * fix(structures): correctly apply bitfields, introduced in #11404 --------- Co-authored-by: Almeida <[email protected]>
1 parent b0e413c commit c71228a

File tree

10 files changed

+100
-6
lines changed

10 files changed

+100
-6
lines changed

packages/structures/src/automoderation/AutoModerationRule.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ export class AutoModerationRule<Omitted extends keyof APIAutoModerationRule | ''
5555
}
5656

5757
/**
58-
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types | event type}
58+
* The rule event type
59+
*
60+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types}
5961
*/
6062
public get eventType() {
6163
return this[kData].event_type;
6264
}
6365

6466
/**
65-
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | trigger type}
67+
* The rule trigger type
68+
*
69+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types}
6670
*/
6771
public get triggerType() {
6872
return this[kData].trigger_type;

packages/structures/src/automoderation/actions/AutoModerationAction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export class AutoModerationAction<Omitted extends keyof APIAutoModerationAction
2626
}
2727

2828
/**
29-
* The {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types | action type}
29+
* The action type
30+
*
31+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types}
3032
*/
3133
public get type() {
3234
return this[kData].type;

packages/structures/src/bitfields/AttachmentFlagsBitField.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
44
/**
55
* Data structure that makes it easy to interact with a {@link Attachment#flags} bitfield.
66
*/
7-
export class AttachmentFlagsBitField extends BitField<keyof AttachmentFlags> {
7+
export class AttachmentFlagsBitField extends BitField<keyof typeof AttachmentFlags> {
88
/**
99
* Numeric attachment flags.
1010
*/

packages/structures/src/bitfields/ChannelFlagsBitField.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
44
/**
55
* Data structure that makes it easy to interact with a {@link (Channel:class).flags} bitfield.
66
*/
7-
export class ChannelFlagsBitField extends BitField<keyof ChannelFlags> {
7+
export class ChannelFlagsBitField extends BitField<keyof typeof ChannelFlags> {
88
/**
99
* Numeric guild channel flags.
1010
*/

packages/structures/src/bitfields/MessageFlagsBitField.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
44
/**
55
* Data structure that makes it easy to interact with a {@link Message#flags} bitfield.
66
*/
7-
export class MessageFlagsBitField extends BitField<keyof MessageFlags> {
7+
export class MessageFlagsBitField extends BitField<keyof typeof MessageFlags> {
88
/**
99
* Numeric message flags.
1010
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { SKUFlags } from 'discord-api-types/v10';
2+
import { BitField } from './BitField.js';
3+
4+
/**
5+
* Data structure that makes it easy to interact with an {@link SKUFlags} bitfield.
6+
*/
7+
export class SKUFlagsBitField extends BitField<keyof typeof SKUFlags> {
8+
/**
9+
* Numeric SKU flags.
10+
*/
11+
public static override readonly Flags = SKUFlags;
12+
13+
public override toJSON() {
14+
return super.toJSON(true);
15+
}
16+
}

packages/structures/src/bitfields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './AttachmentFlagsBitField.js';
44
export * from './ChannelFlagsBitField.js';
55
export * from './MessageFlagsBitField.js';
66
export * from './PermissionsBitField.js';
7+
export * from './SKUFlagsBitField.js';

packages/structures/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from './interactions/index.js';
77
export * from './invites/index.js';
88
export * from './messages/index.js';
99
export * from './polls/index.js';
10+
export * from './skus/index.js';
1011
export * from './soundboards/index.js';
1112
export * from './stageInstances/index.js';
1213
export * from './stickers/index.js';
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { SKUFlags, APISKU } from 'discord-api-types/v10';
2+
import { Structure } from '../Structure.js';
3+
import { SKUFlagsBitField } from '../bitfields/SKUFlagsBitField.js';
4+
import { kData } from '../utils/symbols.js';
5+
import { isFieldSet } from '../utils/type-guards.js';
6+
import type { Partialize } from '../utils/types.js';
7+
8+
/**
9+
* Represents any SKU (stock-keeping units) on Discord.
10+
*
11+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
12+
*/
13+
export class SKU<Omitted extends keyof APISKU | '' = ''> extends Structure<APISKU, Omitted> {
14+
/**
15+
* The template used for removing data from the raw data stored for each SKU
16+
*/
17+
public static override readonly DataTemplate: Partial<APISKU> = {};
18+
19+
/**
20+
* @param data - The raw data received from the API for the SKU
21+
*/
22+
public constructor(data: Partialize<APISKU, Omitted>) {
23+
super(data);
24+
}
25+
26+
/**
27+
* Id of the SKU
28+
*/
29+
public get id() {
30+
return this[kData].id;
31+
}
32+
33+
/**
34+
* Type of SKU
35+
*
36+
* @see {@link https://discord.com/developers/docs/resources/sku#sku-object-sku-types}
37+
*/
38+
public get type() {
39+
return this[kData].type;
40+
}
41+
42+
/**
43+
* Id of the parent application
44+
*/
45+
public get applicationId() {
46+
return this[kData].application_id;
47+
}
48+
49+
/**
50+
* Customer-facing name of your premium offering
51+
*/
52+
public get name() {
53+
return this[kData].name;
54+
}
55+
56+
/**
57+
* System-generated URL slug based on the SKU's name
58+
*/
59+
public get slug() {
60+
return this[kData].slug;
61+
}
62+
63+
/**
64+
* SKU flags combined as a bitfield
65+
*/
66+
public get flags() {
67+
return isFieldSet(this[kData], 'flags', 'number') ? new SKUFlagsBitField(this[kData].flags as SKUFlags) : null;
68+
}
69+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './SKU.js';

0 commit comments

Comments
 (0)