refactor: replace zod with shapeshift (#7547)

This commit is contained in:
Parbez
2022-04-09 15:07:16 +05:30
committed by GitHub
parent 3f3e4327c8
commit 3c0bbac82f
14 changed files with 105 additions and 116 deletions

View File

@@ -1,27 +1,26 @@
import is from '@sindresorhus/is';
import type { APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
import { z } from 'zod';
import { s } from '@sapphire/shapeshift';
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
const namePredicate = z
.string()
.min(1)
.max(32)
const namePredicate = s.string
.lengthGe(1)
.lengthLe(32)
.regex(/^[\P{Lu}\p{N}_-]+$/u);
export function validateName(name: unknown): asserts name is string {
namePredicate.parse(name);
}
const descriptionPredicate = z.string().min(1).max(100);
const descriptionPredicate = s.string.lengthGe(1).lengthLe(100);
export function validateDescription(description: unknown): asserts description is string {
descriptionPredicate.parse(description);
}
const maxArrayLengthPredicate = z.unknown().array().max(25);
const maxArrayLengthPredicate = s.unknown.array.lengthLe(25);
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
maxArrayLengthPredicate.parse(options);
@@ -42,7 +41,7 @@ export function validateRequiredParameters(
validateMaxOptionsLength(options);
}
const booleanPredicate = z.boolean();
const booleanPredicate = s.boolean;
export function validateDefaultPermission(value: unknown): asserts value is boolean {
booleanPredicate.parse(value);
@@ -52,7 +51,7 @@ export function validateRequired(required: unknown): asserts required is boolean
booleanPredicate.parse(required);
}
const choicesLengthPredicate = z.number().lte(25);
const choicesLengthPredicate = s.number.le(25);
export function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {
choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);