Skip to content

Commit 63a0752

Browse files
committed
fix: fully update to shapeshift v4 and set custom error messages
1 parent ef035fc commit 63a0752

14 files changed

+76
-36
lines changed

src/lib/validations/fuzzyArgs/base.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@ export interface BaseFuzzyArgs {
2525
}
2626

2727
export const baseFuzzySchema: SchemaOf<BaseFuzzyArgs> = s.object({
28-
take: s.number
29-
.greaterThanOrEqual(1)
30-
.lessThanOrEqual(50)
31-
.nullish.transform((v) => v ?? 1),
32-
offset: s.number.greaterThanOrEqual(0).nullish.transform((v) => v ?? 0),
33-
reverse: s.boolean.nullish.transform((v) => v ?? false)
28+
take: s
29+
.number({ message: 'The amount to take has to be a number' })
30+
.greaterThanOrEqual(1, { message: 'You have to take at least 1 result' })
31+
.lessThanOrEqual(50, { message: 'You can only take up to 50 results' })
32+
.nullish({ message: 'The amount to take has to be a number' })
33+
.transform((v) => v ?? 1),
34+
offset: s
35+
.number({ message: 'The offset has to be a number' })
36+
.greaterThanOrEqual(0, { message: 'The offset has to be at least 0' })
37+
.nullish({ message: 'The offset has to be a number' })
38+
.transform((v) => v ?? 0),
39+
reverse: s
40+
.boolean({ message: 'The reverse flag has to be a boolean' })
41+
.nullish({ message: 'The reverse flag has to be a boolean' })
42+
.transform((v) => v ?? false)
3443
});

src/lib/validations/fuzzyArgs/fuzzyAbilityArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface GetFuzzyAbilityArgs extends BaseFuzzyArgs {
99
}
1010

1111
const getFuzzyAbilitySchema: SchemaOf<GetFuzzyAbilityArgs> = baseFuzzySchema.extend({
12-
ability: s.string
12+
ability: s.string({ message: 'The ability has to be a string' })
1313
});
1414

1515
export function validateGetFuzzyAbilityArgs(args: GetFuzzyAbilityArgs): GetFuzzyAbilityArgs {

src/lib/validations/fuzzyArgs/fuzzyItemArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface GetFuzzyItemArgs extends BaseFuzzyArgs {
99
}
1010

1111
const getFuzzyItemSchema: SchemaOf<GetFuzzyItemArgs> = baseFuzzySchema.extend({
12-
item: s.string
12+
item: s.string({ message: 'The item has to be a string' })
1313
});
1414

1515
export function validateGetFuzzyItemArgs(args: GetFuzzyItemArgs): GetFuzzyItemArgs {

src/lib/validations/fuzzyArgs/fuzzyMoveArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface GetFuzzyMoveArgs extends BaseFuzzyArgs {
99
}
1010

1111
const getFuzzyMoveSchema: SchemaOf<GetFuzzyMoveArgs> = baseFuzzySchema.extend({
12-
move: s.string
12+
move: s.string({ message: 'The move has to be a string' })
1313
});
1414

1515
export function validateGetFuzzyMoveArgs(args: GetFuzzyMoveArgs): GetFuzzyMoveArgs {

src/lib/validations/getAbilityArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface GetAbilityArgs {
88
}
99

1010
const getAbilitySchema: SchemaOf<GetAbilityArgs> = s.object({
11-
ability: s.string
11+
ability: s.string({ message: 'The ability has to be a string' })
1212
});
1313

1414
export function validateGetAbilityArgs(args: GetAbilityArgs): GetAbilityArgs {

src/lib/validations/getItemArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface GetItemArgs {
88
}
99

1010
const getItemSchema: SchemaOf<GetItemArgs> = s.object({
11-
item: s.string
11+
item: s.string({ message: 'The item has to be a string' })
1212
});
1313

1414
export function validateGetItemArgs(args: GetItemArgs): GetItemArgs {

src/lib/validations/getLearnsetArgs.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ export interface GetLearnsetArgs extends GetPokemonArgs {
1515
}
1616

1717
const getLearnsetSchema: SchemaOf<GetLearnsetArgs> = getPokemonSchema.extend({
18-
moves: s.array(s.string).unique.lengthGreaterThanOrEqual(1),
19-
generation: s.number.int
20-
.greaterThanOrEqual(1)
21-
.lessThanOrEqual(9)
22-
.nullish.transform((v) => v ?? 9)
18+
moves: s
19+
.array(
20+
s.string({ message: 'The move has to be a string' }), //
21+
{ message: 'The list of moves has to be an array' }
22+
)
23+
.unique({ message: 'The list of moves should be a unique list with no duplicates' })
24+
.lengthGreaterThanOrEqual(1, { message: 'The list of moves should have at least one move' }),
25+
generation: s
26+
.number({ message: 'The generation has to be a number' })
27+
.int({ message: 'The generation has to be an integer' })
28+
.greaterThanOrEqual(1, { message: 'The minimum generation is 1' })
29+
.lessThanOrEqual(9, { message: 'The maximum generation is 9' })
30+
.nullish({ message: 'The generation has to be a number' })
31+
.transform((v) => v ?? 9)
2332
});
2433

2534
export function validateGetLearnsetArgs(args: GetLearnsetArgs): NonNullish<GetLearnsetArgs> {

src/lib/validations/getMoveArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface GetMoveArgs {
88
}
99

1010
const getMoveSchema: SchemaOf<GetMoveArgs> = s.object({
11-
move: s.string
11+
move: s.string({ message: 'The move has to be a string' })
1212
});
1313

1414
export function validateGetMoveArgs(args: GetMoveArgs): GetMoveArgs {

src/lib/validations/getTypeMatchupArgs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface GetTypeMatchupArgs {
1414
}
1515

1616
const getTypeMatchupSchema: SchemaOf<GetTypeMatchupArgs> = s.object({
17-
primaryType: s.nativeEnum(TypesEnum),
18-
secondaryType: s.nativeEnum(TypesEnum).nullish
17+
primaryType: s.nativeEnum(TypesEnum, { message: 'The primary type has to be a valid type' }),
18+
secondaryType: s.nativeEnum(TypesEnum, { message: 'The secondary type has to be a valid type' }).nullish()
1919
});
2020

2121
export function validateGetTypeMatchupArgs(args: GetTypeMatchupArgs): GetTypeMatchupArgs {

src/lib/validations/pokemonArgs/base.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ export interface BasePokemonArgs {
2020
}
2121

2222
export const basePokemonArgsSchema: SchemaOf<BasePokemonArgs> = s.object({
23-
offsetFlavorTexts: s.number.greaterThanOrEqual(0).nullish.transform((v) => v ?? 0),
24-
takeFlavorTexts: s.number
25-
.greaterThanOrEqual(1)
26-
.lessThanOrEqual(50)
27-
.nullish.transform((v) => v ?? 1),
28-
reverseFlavorTexts: s.boolean.nullish.transform((v) => v ?? true)
23+
offsetFlavorTexts: s
24+
.number({ message: 'The offset has to be a number' })
25+
.greaterThanOrEqual(0, { message: 'The offset has to be at least 0' })
26+
.nullish({ message: 'The offset has to be a number' })
27+
.transform((v) => v ?? 0),
28+
takeFlavorTexts: s
29+
.number({ message: 'The amount of flavor texts to take has to be a number' })
30+
.greaterThanOrEqual(1, { message: 'You have to take at least 1 result' })
31+
.lessThanOrEqual(50, { message: 'You can only take up to 50 results' })
32+
.nullish({ message: 'The amount of flavor texts to take has to be a number' })
33+
.transform((v) => v ?? 1),
34+
reverseFlavorTexts: s
35+
.boolean({ message: 'The reverse flag has to be a boolean' })
36+
.nullish({ message: 'The reverse flag has to be a boolean' })
37+
.transform((v) => v ?? true)
2938
});

0 commit comments

Comments
 (0)