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 <github@almeidx.dev>
This commit is contained in:
Asad
2026-01-28 01:08:43 +00:00
committed by GitHub
parent b0e413c116
commit c71228aab3
10 changed files with 100 additions and 6 deletions

View File

@@ -55,14 +55,18 @@ export class AutoModerationRule<Omitted extends keyof APIAutoModerationRule | ''
}
/**
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types | event type}
* The rule event type
*
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types}
*/
public get eventType() {
return this[kData].event_type;
}
/**
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | trigger type}
* The rule trigger type
*
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types}
*/
public get triggerType() {
return this[kData].trigger_type;

View File

@@ -26,7 +26,9 @@ export class AutoModerationAction<Omitted extends keyof APIAutoModerationAction
}
/**
* The {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types | action type}
* The action type
*
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types}
*/
public get type() {
return this[kData].type;

View File

@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
/**
* Data structure that makes it easy to interact with a {@link Attachment#flags} bitfield.
*/
export class AttachmentFlagsBitField extends BitField<keyof AttachmentFlags> {
export class AttachmentFlagsBitField extends BitField<keyof typeof AttachmentFlags> {
/**
* Numeric attachment flags.
*/

View File

@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
/**
* Data structure that makes it easy to interact with a {@link (Channel:class).flags} bitfield.
*/
export class ChannelFlagsBitField extends BitField<keyof ChannelFlags> {
export class ChannelFlagsBitField extends BitField<keyof typeof ChannelFlags> {
/**
* Numeric guild channel flags.
*/

View File

@@ -4,7 +4,7 @@ import { BitField } from './BitField.js';
/**
* Data structure that makes it easy to interact with a {@link Message#flags} bitfield.
*/
export class MessageFlagsBitField extends BitField<keyof MessageFlags> {
export class MessageFlagsBitField extends BitField<keyof typeof MessageFlags> {
/**
* Numeric message flags.
*/

View File

@@ -0,0 +1,16 @@
import { SKUFlags } from 'discord-api-types/v10';
import { BitField } from './BitField.js';
/**
* Data structure that makes it easy to interact with an {@link SKUFlags} bitfield.
*/
export class SKUFlagsBitField extends BitField<keyof typeof SKUFlags> {
/**
* Numeric SKU flags.
*/
public static override readonly Flags = SKUFlags;
public override toJSON() {
return super.toJSON(true);
}
}

View File

@@ -4,3 +4,4 @@ export * from './AttachmentFlagsBitField.js';
export * from './ChannelFlagsBitField.js';
export * from './MessageFlagsBitField.js';
export * from './PermissionsBitField.js';
export * from './SKUFlagsBitField.js';

View File

@@ -7,6 +7,7 @@ export * from './interactions/index.js';
export * from './invites/index.js';
export * from './messages/index.js';
export * from './polls/index.js';
export * from './skus/index.js';
export * from './soundboards/index.js';
export * from './stageInstances/index.js';
export * from './stickers/index.js';

View File

@@ -0,0 +1,69 @@
import type { SKUFlags, APISKU } from 'discord-api-types/v10';
import { Structure } from '../Structure.js';
import { SKUFlagsBitField } from '../bitfields/SKUFlagsBitField.js';
import { kData } from '../utils/symbols.js';
import { isFieldSet } from '../utils/type-guards.js';
import type { Partialize } from '../utils/types.js';
/**
* Represents any SKU (stock-keeping units) on Discord.
*
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
*/
export class SKU<Omitted extends keyof APISKU | '' = ''> extends Structure<APISKU, Omitted> {
/**
* The template used for removing data from the raw data stored for each SKU
*/
public static override readonly DataTemplate: Partial<APISKU> = {};
/**
* @param data - The raw data received from the API for the SKU
*/
public constructor(data: Partialize<APISKU, Omitted>) {
super(data);
}
/**
* Id of the SKU
*/
public get id() {
return this[kData].id;
}
/**
* Type of SKU
*
* @see {@link https://discord.com/developers/docs/resources/sku#sku-object-sku-types}
*/
public get type() {
return this[kData].type;
}
/**
* Id of the parent application
*/
public get applicationId() {
return this[kData].application_id;
}
/**
* Customer-facing name of your premium offering
*/
public get name() {
return this[kData].name;
}
/**
* System-generated URL slug based on the SKU's name
*/
public get slug() {
return this[kData].slug;
}
/**
* SKU flags combined as a bitfield
*/
public get flags() {
return isFieldSet(this[kData], 'flags', 'number') ? new SKUFlagsBitField(this[kData].flags as SKUFlags) : null;
}
}

View File

@@ -0,0 +1 @@
export * from './SKU.js';