-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unsafe embed builder field normalization (#7418)
- Loading branch information
1 parent
a921ec7
commit b936103
Showing
4 changed files
with
22 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import type { APIMessageComponent, ComponentType } from 'discord-api-types/v9'; | ||
import type { JSONEncodable } from '../util/jsonEncodable'; | ||
|
||
/** | ||
* Represents a discord component | ||
*/ | ||
export interface Component { | ||
export interface Component extends JSONEncodable<APIMessageComponent> { | ||
/** | ||
* The type of this component | ||
*/ | ||
readonly type: ComponentType; | ||
/** | ||
* Converts this component to an API-compatible JSON object | ||
*/ | ||
toJSON: () => APIMessageComponent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface JSONEncodable<T> { | ||
/** | ||
* Transforms this object to its JSON format | ||
*/ | ||
toJSON: () => T; | ||
} | ||
|
||
/** | ||
* Indicates if an object is encodable or not. | ||
* @param maybeEncodable The object to check against | ||
*/ | ||
export function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> { | ||
return maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable; | ||
} |