mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
chore: bump shapeshift for faster object validation (#7914)
This commit is contained in:
@@ -325,7 +325,7 @@ describe('Embed', () => {
|
|||||||
embed.addFields([{ name: 'foo', value: 'bar' }]);
|
embed.addFields([{ name: 'foo', value: 'bar' }]);
|
||||||
|
|
||||||
expect(embed.toJSON()).toStrictEqual({
|
expect(embed.toJSON()).toStrictEqual({
|
||||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
fields: [{ name: 'foo', value: 'bar' }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ describe('Embed', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
expect(embed.spliceFields(0, 1).toJSON()).toStrictEqual({
|
expect(embed.spliceFields(0, 1).toJSON()).toStrictEqual({
|
||||||
fields: [{ name: 'foo', value: 'baz', inline: undefined }],
|
fields: [{ name: 'foo', value: 'baz' }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://discord.js.org",
|
"homepage": "https://discord.js.org",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sapphire/shapeshift": "^2.0.0",
|
"@sapphire/shapeshift": "^3.0.0",
|
||||||
"@sindresorhus/is": "^4.6.0",
|
"@sindresorhus/is": "^4.6.0",
|
||||||
"discord-api-types": "^0.31.1",
|
"discord-api-types": "^0.31.1",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { APIMessageComponentEmoji, ButtonStyle } from 'discord-api-types/v10';
|
|||||||
import type { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption';
|
import type { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption';
|
||||||
import { UnsafeSelectMenuOptionBuilder } from './selectMenu/UnsafeSelectMenuOption';
|
import { UnsafeSelectMenuOptionBuilder } from './selectMenu/UnsafeSelectMenuOption';
|
||||||
|
|
||||||
export const customIdValidator = s.string.lengthGe(1).lengthLe(100);
|
export const customIdValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
|
||||||
|
|
||||||
export const emojiValidator = s.object({
|
export const emojiValidator = s.object({
|
||||||
id: s.string,
|
id: s.string,
|
||||||
@@ -13,14 +13,14 @@ export const emojiValidator = s.object({
|
|||||||
|
|
||||||
export const disabledValidator = s.boolean;
|
export const disabledValidator = s.boolean;
|
||||||
|
|
||||||
export const buttonLabelValidator = s.string.lengthGe(1).lengthLe(80);
|
export const buttonLabelValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(80);
|
||||||
|
|
||||||
export const buttonStyleValidator = s.nativeEnum(ButtonStyle);
|
export const buttonStyleValidator = s.nativeEnum(ButtonStyle);
|
||||||
|
|
||||||
export const placeholderValidator = s.string.lengthLe(150);
|
export const placeholderValidator = s.string.lengthLessThanOrEqual(150);
|
||||||
export const minMaxValidator = s.number.int.ge(0).le(25);
|
export const minMaxValidator = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(25);
|
||||||
|
|
||||||
export const labelValueDescriptionValidator = s.string.lengthGe(1).lengthLe(100);
|
export const labelValueDescriptionValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
|
||||||
export const optionValidator = s.union(
|
export const optionValidator = s.union(
|
||||||
s.object({
|
s.object({
|
||||||
label: labelValueDescriptionValidator,
|
label: labelValueDescriptionValidator,
|
||||||
@@ -31,15 +31,15 @@ export const optionValidator = s.union(
|
|||||||
}),
|
}),
|
||||||
s.instance(UnsafeSelectMenuOptionBuilder),
|
s.instance(UnsafeSelectMenuOptionBuilder),
|
||||||
);
|
);
|
||||||
export const optionsValidator = optionValidator.array.lengthGe(0);
|
export const optionsValidator = optionValidator.array.lengthGreaterThanOrEqual(0);
|
||||||
export const optionsLengthValidator = s.number.int.ge(0).le(25);
|
export const optionsLengthValidator = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(25);
|
||||||
|
|
||||||
export function validateRequiredSelectMenuParameters(options: SelectMenuOptionBuilder[], customId?: string) {
|
export function validateRequiredSelectMenuParameters(options: SelectMenuOptionBuilder[], customId?: string) {
|
||||||
customIdValidator.parse(customId);
|
customIdValidator.parse(customId);
|
||||||
optionsValidator.parse(options);
|
optionsValidator.parse(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const labelValueValidator = s.string.lengthGe(1).lengthLe(100);
|
export const labelValueValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
|
||||||
export const defaultValidator = s.boolean;
|
export const defaultValidator = s.boolean;
|
||||||
|
|
||||||
export function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {
|
export function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { TextInputStyle } from 'discord-api-types/v10';
|
|||||||
import { customIdValidator } from '../Assertions';
|
import { customIdValidator } from '../Assertions';
|
||||||
|
|
||||||
export const textInputStyleValidator = s.nativeEnum(TextInputStyle);
|
export const textInputStyleValidator = s.nativeEnum(TextInputStyle);
|
||||||
export const minLengthValidator = s.number.int.ge(0).le(4000);
|
export const minLengthValidator = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(4000);
|
||||||
export const maxLengthValidator = s.number.int.ge(1).le(4000);
|
export const maxLengthValidator = s.number.int.greaterThanOrEqual(1).lessThanOrEqual(4000);
|
||||||
export const requiredValidator = s.boolean;
|
export const requiredValidator = s.boolean;
|
||||||
export const valueValidator = s.string.lengthLe(4000);
|
export const valueValidator = s.string.lengthLessThanOrEqual(4000);
|
||||||
export const placeholderValidator = s.string.lengthLe(100);
|
export const placeholderValidator = s.string.lengthLessThanOrEqual(100);
|
||||||
export const labelValidator = s.string.lengthGe(1).lengthLe(45);
|
export const labelValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45);
|
||||||
|
|
||||||
export function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {
|
export function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {
|
||||||
customIdValidator.parse(customId);
|
customIdValidator.parse(customId);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { ApplicationCommandType } from 'discord-api-types/v10';
|
|||||||
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
|
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
|
||||||
|
|
||||||
const namePredicate = s.string
|
const namePredicate = s.string
|
||||||
.lengthGe(1)
|
.lengthGreaterThanOrEqual(1)
|
||||||
.lengthLe(32)
|
.lengthLessThanOrEqual(32)
|
||||||
.regex(/^( *[\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+ *)+$/u);
|
.regex(/^( *[\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+ *)+$/u);
|
||||||
|
|
||||||
const typePredicate = s.union(s.literal(ApplicationCommandType.User), s.literal(ApplicationCommandType.Message));
|
const typePredicate = s.union(s.literal(ApplicationCommandType.User), s.literal(ApplicationCommandType.Message));
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { s } from '@sapphire/shapeshift';
|
|||||||
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../..';
|
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../..';
|
||||||
import { customIdValidator } from '../../components/Assertions';
|
import { customIdValidator } from '../../components/Assertions';
|
||||||
|
|
||||||
export const titleValidator = s.string.lengthGe(1).lengthLe(45);
|
export const titleValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45);
|
||||||
export const componentsValidator = s.instance(ActionRowBuilder).array.lengthGe(1);
|
export const componentsValidator = s.instance(ActionRowBuilder).array.lengthGreaterThanOrEqual(1);
|
||||||
|
|
||||||
export function validateRequiredParameters(
|
export function validateRequiredParameters(
|
||||||
customId?: string,
|
customId?: string,
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder
|
|||||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
||||||
|
|
||||||
const namePredicate = s.string
|
const namePredicate = s.string
|
||||||
.lengthGe(1)
|
.lengthGreaterThanOrEqual(1)
|
||||||
.lengthLe(32)
|
.lengthLessThanOrEqual(32)
|
||||||
.regex(/^[\P{Lu}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u);
|
.regex(/^[\P{Lu}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u);
|
||||||
|
|
||||||
export function validateName(name: unknown): asserts name is string {
|
export function validateName(name: unknown): asserts name is string {
|
||||||
namePredicate.parse(name);
|
namePredicate.parse(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const descriptionPredicate = s.string.lengthGe(1).lengthLe(100);
|
const descriptionPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
|
||||||
const localePredicate = s.nativeEnum(Locale);
|
const localePredicate = s.nativeEnum(Locale);
|
||||||
|
|
||||||
export function validateDescription(description: unknown): asserts description is string {
|
export function validateDescription(description: unknown): asserts description is string {
|
||||||
descriptionPredicate.parse(description);
|
descriptionPredicate.parse(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxArrayLengthPredicate = s.unknown.array.lengthLe(25);
|
const maxArrayLengthPredicate = s.unknown.array.lengthLessThanOrEqual(25);
|
||||||
export function validateLocale(locale: unknown) {
|
export function validateLocale(locale: unknown) {
|
||||||
return localePredicate.parse(locale);
|
return localePredicate.parse(locale);
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ export function validateRequired(required: unknown): asserts required is boolean
|
|||||||
booleanPredicate.parse(required);
|
booleanPredicate.parse(required);
|
||||||
}
|
}
|
||||||
|
|
||||||
const choicesLengthPredicate = s.number.le(25);
|
const choicesLengthPredicate = s.number.lessThanOrEqual(25);
|
||||||
|
|
||||||
export function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {
|
export function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {
|
||||||
choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);
|
choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { s } from '@sapphire/shapeshift';
|
|||||||
import { APIApplicationCommandOptionChoice, ApplicationCommandOptionType } from 'discord-api-types/v10';
|
import { APIApplicationCommandOptionChoice, ApplicationCommandOptionType } from 'discord-api-types/v10';
|
||||||
import { localizationMapPredicate, validateChoicesLength } from '../Assertions';
|
import { localizationMapPredicate, validateChoicesLength } from '../Assertions';
|
||||||
|
|
||||||
const stringPredicate = s.string.lengthGe(1).lengthLe(100);
|
const stringPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
|
||||||
const numberPredicate = s.number.gt(-Infinity).lt(Infinity);
|
const numberPredicate = s.number.greaterThan(-Infinity).lessThan(Infinity);
|
||||||
const choicesPredicate = s.object({
|
const choicesPredicate = s.object({
|
||||||
name: stringPredicate,
|
name: stringPredicate,
|
||||||
name_localizations: localizationMapPredicate,
|
name_localizations: localizationMapPredicate,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { s } from '@sapphire/shapeshift';
|
import { s } from '@sapphire/shapeshift';
|
||||||
import type { APIEmbedField } from 'discord-api-types/v10';
|
import type { APIEmbedField } from 'discord-api-types/v10';
|
||||||
|
|
||||||
export const fieldNamePredicate = s.string.lengthGe(1).lengthLe(256);
|
export const fieldNamePredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(256);
|
||||||
|
|
||||||
export const fieldValuePredicate = s.string.lengthGe(1).lengthLe(1024);
|
export const fieldValuePredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(1024);
|
||||||
|
|
||||||
export const fieldInlinePredicate = s.boolean.optional;
|
export const fieldInlinePredicate = s.boolean.optional;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export const embedFieldPredicate = s.object({
|
|||||||
|
|
||||||
export const embedFieldsArrayPredicate = embedFieldPredicate.array;
|
export const embedFieldsArrayPredicate = embedFieldPredicate.array;
|
||||||
|
|
||||||
export const fieldLengthPredicate = s.number.le(25);
|
export const fieldLengthPredicate = s.number.lessThanOrEqual(25);
|
||||||
|
|
||||||
export function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void {
|
export function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void {
|
||||||
fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding);
|
fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding);
|
||||||
@@ -37,15 +37,15 @@ export const embedAuthorPredicate = s.object({
|
|||||||
url: urlPredicate,
|
url: urlPredicate,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const RGBPredicate = s.number.int.ge(0).le(255);
|
export const RGBPredicate = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(255);
|
||||||
export const colorPredicate = s.number.int
|
export const colorPredicate = s.number.int
|
||||||
.ge(0)
|
.greaterThanOrEqual(0)
|
||||||
.le(0xffffff)
|
.lessThanOrEqual(0xffffff)
|
||||||
.or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable;
|
.or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable;
|
||||||
|
|
||||||
export const descriptionPredicate = s.string.lengthGe(1).lengthLe(4096).nullable;
|
export const descriptionPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(4096).nullable;
|
||||||
|
|
||||||
export const footerTextPredicate = s.string.lengthGe(1).lengthLe(2048).nullable;
|
export const footerTextPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(2048).nullable;
|
||||||
|
|
||||||
export const embedFooterPredicate = s.object({
|
export const embedFooterPredicate = s.object({
|
||||||
text: footerTextPredicate,
|
text: footerTextPredicate,
|
||||||
|
|||||||
10
yarn.lock
10
yarn.lock
@@ -1823,7 +1823,7 @@ __metadata:
|
|||||||
"@babel/preset-env": ^7.16.11
|
"@babel/preset-env": ^7.16.11
|
||||||
"@babel/preset-typescript": ^7.16.7
|
"@babel/preset-typescript": ^7.16.7
|
||||||
"@discordjs/ts-docgen": ^0.4.1
|
"@discordjs/ts-docgen": ^0.4.1
|
||||||
"@sapphire/shapeshift": ^2.0.0
|
"@sapphire/shapeshift": ^3.0.0
|
||||||
"@sindresorhus/is": ^4.6.0
|
"@sindresorhus/is": ^4.6.0
|
||||||
"@types/jest": ^27.4.1
|
"@types/jest": ^27.4.1
|
||||||
"@types/node": ^16.11.27
|
"@types/node": ^16.11.27
|
||||||
@@ -2389,10 +2389,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@sapphire/shapeshift@npm:^2.0.0":
|
"@sapphire/shapeshift@npm:^3.0.0":
|
||||||
version: 2.0.0
|
version: 3.0.0
|
||||||
resolution: "@sapphire/shapeshift@npm:2.0.0"
|
resolution: "@sapphire/shapeshift@npm:3.0.0"
|
||||||
checksum: e866aa714d70b0c0d607ed9ad831c039b396cca30611691c59a6e43cb369cf23d69404560105101231f56128022b0030a5201c074193da324ad4345c6d06992c
|
checksum: f5ebf3991a2bb6e80242b58a488343f25147ba79e8ac227e3d26cbed3402e7e06c326eb9afddd5804be3b0a4e714366c7e60842d2072395da2cb6e754d28bda7
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user