mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
feat: implement zod-validation-error (#10534)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import type { APIEmbed, APIEmbedAuthor, APIEmbedField, APIEmbedFooter } from 'di
|
||||
import type { RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { normalizeArray } from '../../util/normalizeArray.js';
|
||||
import { resolveBuilder } from '../../util/resolveBuilder.js';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import { validate } from '../../util/validation.js';
|
||||
import { embedPredicate } from './Assertions.js';
|
||||
import { EmbedAuthorBuilder } from './EmbedAuthor.js';
|
||||
import { EmbedFieldBuilder } from './EmbedField.js';
|
||||
@@ -343,9 +343,7 @@ export class EmbedBuilder implements JSONEncodable<APIEmbed> {
|
||||
footer: this.data.footer?.toJSON(false),
|
||||
};
|
||||
|
||||
if (validationOverride ?? isValidationEnabled()) {
|
||||
embedPredicate.parse(data);
|
||||
}
|
||||
validate(embedPredicate, data, validationOverride);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { APIEmbedAuthor } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import { validate } from '../../util/validation.js';
|
||||
import { embedAuthorPredicate } from './Assertions.js';
|
||||
|
||||
/**
|
||||
@@ -72,10 +72,7 @@ export class EmbedAuthorBuilder {
|
||||
*/
|
||||
public toJSON(validationOverride?: boolean): APIEmbedAuthor {
|
||||
const clone = structuredClone(this.data);
|
||||
|
||||
if (validationOverride ?? isValidationEnabled()) {
|
||||
embedAuthorPredicate.parse(clone);
|
||||
}
|
||||
validate(embedAuthorPredicate, clone, validationOverride);
|
||||
|
||||
return clone as APIEmbedAuthor;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { APIEmbedField } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import { validate } from '../../util/validation.js';
|
||||
import { embedFieldPredicate } from './Assertions.js';
|
||||
|
||||
/**
|
||||
@@ -56,10 +56,7 @@ export class EmbedFieldBuilder {
|
||||
*/
|
||||
public toJSON(validationOverride?: boolean): APIEmbedField {
|
||||
const clone = structuredClone(this.data);
|
||||
|
||||
if (validationOverride ?? isValidationEnabled()) {
|
||||
embedFieldPredicate.parse(clone);
|
||||
}
|
||||
validate(embedFieldPredicate, clone, validationOverride);
|
||||
|
||||
return clone as APIEmbedField;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { APIEmbedFooter } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import { validate } from '../../util/validation.js';
|
||||
import { embedFooterPredicate } from './Assertions.js';
|
||||
|
||||
/**
|
||||
@@ -54,10 +54,7 @@ export class EmbedFooterBuilder {
|
||||
*/
|
||||
public toJSON(validationOverride?: boolean): APIEmbedFooter {
|
||||
const clone = structuredClone(this.data);
|
||||
|
||||
if (validationOverride ?? isValidationEnabled()) {
|
||||
embedFooterPredicate.parse(clone);
|
||||
}
|
||||
validate(embedFooterPredicate, clone, validationOverride);
|
||||
|
||||
return clone as APIEmbedFooter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user