-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace zod with shapeshift (#7547)
- Loading branch information
1 parent
3f3e432
commit 3c0bbac
Showing
14 changed files
with
105 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
packages/builders/src/interactions/contextMenuCommands/Assertions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
...eractions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/builders/src/interactions/slashCommands/options/integer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/builders/src/interactions/slashCommands/options/number.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,46 @@ | ||
import type { APIEmbedField } from 'discord-api-types/v10'; | ||
import { z } from 'zod'; | ||
import { s } from '@sapphire/shapeshift'; | ||
|
||
export const fieldNamePredicate = z.string().min(1).max(256); | ||
export const fieldNamePredicate = s.string.lengthGe(1).lengthLe(256); | ||
|
||
export const fieldValuePredicate = z.string().min(1).max(1024); | ||
export const fieldValuePredicate = s.string.lengthGe(1).lengthLe(1024); | ||
|
||
export const fieldInlinePredicate = z.boolean().optional(); | ||
export const fieldInlinePredicate = s.boolean.optional; | ||
|
||
export const embedFieldPredicate = z.object({ | ||
export const embedFieldPredicate = s.object({ | ||
name: fieldNamePredicate, | ||
value: fieldValuePredicate, | ||
inline: fieldInlinePredicate, | ||
}); | ||
|
||
export const embedFieldsArrayPredicate = embedFieldPredicate.array(); | ||
export const embedFieldsArrayPredicate = embedFieldPredicate.array; | ||
|
||
export const fieldLengthPredicate = z.number().lte(25); | ||
export const fieldLengthPredicate = s.number.le(25); | ||
|
||
export function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void { | ||
fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding); | ||
} | ||
|
||
export const authorNamePredicate = fieldNamePredicate.nullable(); | ||
export const authorNamePredicate = fieldNamePredicate.nullable; | ||
|
||
export const urlPredicate = z.string().url().nullish(); | ||
export const imageURLPredicate = s.string.url({ | ||
allowedProtocols: ['http:', 'https:', 'attachment:'], | ||
}).nullish; | ||
|
||
export const RGBPredicate = z.number().int().gte(0).lte(255); | ||
export const colorPredicate = z | ||
.number() | ||
.int() | ||
.gte(0) | ||
.lte(0xffffff) | ||
.nullable() | ||
.or(z.tuple([RGBPredicate, RGBPredicate, RGBPredicate])); | ||
export const urlPredicate = s.string.url({ | ||
allowedProtocols: ['http:', 'https:'], | ||
}).nullish; | ||
|
||
export const descriptionPredicate = z.string().min(1).max(4096).nullable(); | ||
export const RGBPredicate = s.number.int.ge(0).le(255); | ||
export const colorPredicate = s.number.int | ||
.ge(0) | ||
.le(0xffffff) | ||
.or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable; | ||
|
||
export const footerTextPredicate = z.string().min(1).max(2048).nullable(); | ||
export const descriptionPredicate = s.string.lengthGe(1).lengthLe(4096).nullable; | ||
|
||
export const timestampPredicate = z.union([z.number(), z.date()]).nullable(); | ||
export const footerTextPredicate = s.string.lengthGe(1).lengthLe(2048).nullable; | ||
|
||
export const titlePredicate = fieldNamePredicate.nullable(); | ||
export const timestampPredicate = s.union(s.number, s.date).nullable; | ||
|
||
export const titlePredicate = fieldNamePredicate.nullable; |
Oops, something went wrong.