chore: bump shapeshift for faster object validation (#7914)

This commit is contained in:
Parbez
2022-05-12 15:39:50 +05:30
committed by GitHub
parent c1b5e731da
commit 4515a1ea80
10 changed files with 40 additions and 40 deletions

View File

@@ -325,7 +325,7 @@ describe('Embed', () => {
embed.addFields([{ name: 'foo', value: 'bar' }]);
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({
fields: [{ name: 'foo', value: 'baz', inline: undefined }],
fields: [{ name: 'foo', value: 'baz' }],
});
});

View File

@@ -52,7 +52,7 @@
},
"homepage": "https://discord.js.org",
"dependencies": {
"@sapphire/shapeshift": "^2.0.0",
"@sapphire/shapeshift": "^3.0.0",
"@sindresorhus/is": "^4.6.0",
"discord-api-types": "^0.31.1",
"fast-deep-equal": "^3.1.3",

View File

@@ -3,7 +3,7 @@ import { APIMessageComponentEmoji, ButtonStyle } from 'discord-api-types/v10';
import type { SelectMenuOptionBuilder } from './selectMenu/SelectMenuOption';
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({
id: s.string,
@@ -13,14 +13,14 @@ export const emojiValidator = s.object({
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 placeholderValidator = s.string.lengthLe(150);
export const minMaxValidator = s.number.int.ge(0).le(25);
export const placeholderValidator = s.string.lengthLessThanOrEqual(150);
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(
s.object({
label: labelValueDescriptionValidator,
@@ -31,15 +31,15 @@ export const optionValidator = s.union(
}),
s.instance(UnsafeSelectMenuOptionBuilder),
);
export const optionsValidator = optionValidator.array.lengthGe(0);
export const optionsLengthValidator = s.number.int.ge(0).le(25);
export const optionsValidator = optionValidator.array.lengthGreaterThanOrEqual(0);
export const optionsLengthValidator = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(25);
export function validateRequiredSelectMenuParameters(options: SelectMenuOptionBuilder[], customId?: string) {
customIdValidator.parse(customId);
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 function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {

View File

@@ -3,12 +3,12 @@ import { TextInputStyle } from 'discord-api-types/v10';
import { customIdValidator } from '../Assertions';
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 minLengthValidator = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(4000);
export const maxLengthValidator = s.number.int.greaterThanOrEqual(1).lessThanOrEqual(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 const valueValidator = s.string.lengthLessThanOrEqual(4000);
export const placeholderValidator = s.string.lengthLessThanOrEqual(100);
export const labelValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45);
export function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {
customIdValidator.parse(customId);

View File

@@ -3,8 +3,8 @@ import { ApplicationCommandType } from 'discord-api-types/v10';
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
const namePredicate = s.string
.lengthGe(1)
.lengthLe(32)
.lengthGreaterThanOrEqual(1)
.lengthLessThanOrEqual(32)
.regex(/^( *[\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+ *)+$/u);
const typePredicate = s.union(s.literal(ApplicationCommandType.User), s.literal(ApplicationCommandType.Message));

View File

@@ -2,8 +2,8 @@ import { s } from '@sapphire/shapeshift';
import { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../..';
import { customIdValidator } from '../../components/Assertions';
export const titleValidator = s.string.lengthGe(1).lengthLe(45);
export const componentsValidator = s.instance(ActionRowBuilder).array.lengthGe(1);
export const titleValidator = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45);
export const componentsValidator = s.instance(ActionRowBuilder).array.lengthGreaterThanOrEqual(1);
export function validateRequiredParameters(
customId?: string,

View File

@@ -6,22 +6,22 @@ import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
const namePredicate = s.string
.lengthGe(1)
.lengthLe(32)
.lengthGreaterThanOrEqual(1)
.lengthLessThanOrEqual(32)
.regex(/^[\P{Lu}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u);
export function validateName(name: unknown): asserts name is string {
namePredicate.parse(name);
}
const descriptionPredicate = s.string.lengthGe(1).lengthLe(100);
const descriptionPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
const localePredicate = s.nativeEnum(Locale);
export function validateDescription(description: unknown): asserts description is string {
descriptionPredicate.parse(description);
}
const maxArrayLengthPredicate = s.unknown.array.lengthLe(25);
const maxArrayLengthPredicate = s.unknown.array.lengthLessThanOrEqual(25);
export function validateLocale(locale: unknown) {
return localePredicate.parse(locale);
}
@@ -55,7 +55,7 @@ export function validateRequired(required: unknown): asserts required is boolean
booleanPredicate.parse(required);
}
const choicesLengthPredicate = s.number.le(25);
const choicesLengthPredicate = s.number.lessThanOrEqual(25);
export function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {
choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);

View File

@@ -2,8 +2,8 @@ import { s } from '@sapphire/shapeshift';
import { APIApplicationCommandOptionChoice, ApplicationCommandOptionType } from 'discord-api-types/v10';
import { localizationMapPredicate, validateChoicesLength } from '../Assertions';
const stringPredicate = s.string.lengthGe(1).lengthLe(100);
const numberPredicate = s.number.gt(-Infinity).lt(Infinity);
const stringPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
const numberPredicate = s.number.greaterThan(-Infinity).lessThan(Infinity);
const choicesPredicate = s.object({
name: stringPredicate,
name_localizations: localizationMapPredicate,

View File

@@ -1,9 +1,9 @@
import { s } from '@sapphire/shapeshift';
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;
@@ -15,7 +15,7 @@ export const embedFieldPredicate = s.object({
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 {
fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding);
@@ -37,15 +37,15 @@ export const embedAuthorPredicate = s.object({
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
.ge(0)
.le(0xffffff)
.greaterThanOrEqual(0)
.lessThanOrEqual(0xffffff)
.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({
text: footerTextPredicate,

View File

@@ -1823,7 +1823,7 @@ __metadata:
"@babel/preset-env": ^7.16.11
"@babel/preset-typescript": ^7.16.7
"@discordjs/ts-docgen": ^0.4.1
"@sapphire/shapeshift": ^2.0.0
"@sapphire/shapeshift": ^3.0.0
"@sindresorhus/is": ^4.6.0
"@types/jest": ^27.4.1
"@types/node": ^16.11.27
@@ -2389,10 +2389,10 @@ __metadata:
languageName: node
linkType: hard
"@sapphire/shapeshift@npm:^2.0.0":
version: 2.0.0
resolution: "@sapphire/shapeshift@npm:2.0.0"
checksum: e866aa714d70b0c0d607ed9ad831c039b396cca30611691c59a6e43cb369cf23d69404560105101231f56128022b0030a5201c074193da324ad4345c6d06992c
"@sapphire/shapeshift@npm:^3.0.0":
version: 3.0.0
resolution: "@sapphire/shapeshift@npm:3.0.0"
checksum: f5ebf3991a2bb6e80242b58a488343f25147ba79e8ac227e3d26cbed3402e7e06c326eb9afddd5804be3b0a4e714366c7e60842d2072395da2cb6e754d28bda7
languageName: node
linkType: hard