mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
refactor: replace zod with shapeshift (#7547)
This commit is contained in:
@@ -1,56 +1,55 @@
|
||||
import { APIMessageComponentEmoji, ButtonStyle } from 'discord-api-types/v10';
|
||||
import { z } from 'zod';
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import type { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption';
|
||||
import { UnsafeSelectMenuOptionBuilder } from './selectMenu/UnsafeSelectMenuOption';
|
||||
|
||||
export const customIdValidator = z.string().min(1).max(100);
|
||||
export const customIdValidator = s.string.lengthGe(1).lengthLe(100);
|
||||
|
||||
export const emojiValidator = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
animated: z.boolean(),
|
||||
})
|
||||
.partial()
|
||||
.strict();
|
||||
export const emojiValidator = s.object({
|
||||
id: s.string,
|
||||
name: s.string,
|
||||
animated: s.boolean,
|
||||
}).partial.strict;
|
||||
|
||||
export const disabledValidator = z.boolean();
|
||||
export const disabledValidator = s.boolean;
|
||||
|
||||
export const buttonLabelValidator = z.string().nonempty().max(80);
|
||||
export const buttonLabelValidator = s.string.lengthGe(1).lengthLe(80);
|
||||
|
||||
export const buttonStyleValidator = z.number().int().min(ButtonStyle.Primary).max(ButtonStyle.Link);
|
||||
export const buttonStyleValidator = s.nativeEnum(ButtonStyle);
|
||||
|
||||
export const placeholderValidator = z.string().max(150);
|
||||
export const minMaxValidator = z.number().int().min(0).max(25);
|
||||
export const placeholderValidator = s.string.lengthLe(150);
|
||||
export const minMaxValidator = s.number.int.ge(0).le(25);
|
||||
|
||||
export const labelValueDescriptionValidator = z.string().min(1).max(100);
|
||||
export const optionValidator = z.union([
|
||||
z.object({
|
||||
export const labelValueDescriptionValidator = s.string.lengthGe(1).lengthLe(100);
|
||||
export const optionValidator = s.union(
|
||||
s.object({
|
||||
label: labelValueDescriptionValidator,
|
||||
value: labelValueDescriptionValidator,
|
||||
description: labelValueDescriptionValidator.optional(),
|
||||
emoji: emojiValidator.optional(),
|
||||
default: z.boolean().optional(),
|
||||
description: labelValueDescriptionValidator.optional,
|
||||
emoji: emojiValidator.optional,
|
||||
default: s.boolean.optional,
|
||||
}),
|
||||
z.instanceof(UnsafeSelectMenuOptionBuilder),
|
||||
]);
|
||||
export const optionsValidator = optionValidator.array().nonempty();
|
||||
export const optionsLengthValidator = z.number().int().min(0).max(25);
|
||||
s.instance(UnsafeSelectMenuOptionBuilder),
|
||||
);
|
||||
export const optionsValidator = optionValidator.array.lengthGe(0);
|
||||
export const optionsLengthValidator = s.number.int.ge(0).le(25);
|
||||
|
||||
export function validateRequiredSelectMenuParameters(options: SelectMenuOptionBuilder[], customId?: string) {
|
||||
customIdValidator.parse(customId);
|
||||
optionsValidator.parse(options);
|
||||
}
|
||||
|
||||
export const labelValueValidator = z.string().min(1).max(100);
|
||||
export const defaultValidator = z.boolean();
|
||||
export const labelValueValidator = s.string.lengthGe(1).lengthLe(100);
|
||||
export const defaultValidator = s.boolean;
|
||||
|
||||
export function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {
|
||||
labelValueValidator.parse(label);
|
||||
labelValueValidator.parse(value);
|
||||
}
|
||||
|
||||
export const urlValidator = z.string().url();
|
||||
export const urlValidator = s.string.url({
|
||||
allowedProtocols: ['http:', 'https:', 'discord:'],
|
||||
});
|
||||
|
||||
export function validateRequiredButtonParameters(
|
||||
style?: ButtonStyle,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { TextInputStyle } from 'discord-api-types/v10';
|
||||
import { z } from 'zod';
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { customIdValidator } from '../Assertions';
|
||||
|
||||
export const textInputStyleValidator = z.nativeEnum(TextInputStyle);
|
||||
export const minLengthValidator = z.number().int().min(0).max(4000);
|
||||
export const maxLengthValidator = z.number().int().min(1).max(4000);
|
||||
export const requiredValidator = z.boolean();
|
||||
export const valueValidator = z.string().max(4000);
|
||||
export const placeholderValidator = z.string().max(100);
|
||||
export const labelValidator = z.string().min(1).max(45);
|
||||
export const textInputStyleValidator = s.nativeEnum(TextInputStyle);
|
||||
export const minLengthValidator = s.number.int.ge(0).le(4000);
|
||||
export const maxLengthValidator = s.number.int.ge(1).le(4000);
|
||||
export const requiredValidator = s.boolean;
|
||||
export const valueValidator = s.string.lengthLe(4000);
|
||||
export const placeholderValidator = s.string.lengthLe(100);
|
||||
export const labelValidator = s.string.lengthGe(1).lengthLe(45);
|
||||
|
||||
export function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {
|
||||
customIdValidator.parse(customId);
|
||||
|
||||
Reference in New Issue
Block a user