11import { z , ZodEffects , ZodOptional , ZodString } from "zod" ;
2- import { IdSchema , StringNumberSchema } from "./util" ;
2+ import { IdSchema , nameWithSeparators , slug , StringNumberSchema } from "./util" ;
33import { LanguageSchema } from "./languages" ;
44import {
55 ModeSchema ,
@@ -18,10 +18,7 @@ import { ConnectionSchema } from "./connections";
1818const NoneFilterSchema = z . literal ( "none" ) ;
1919export const ResultFiltersSchema = z . object ( {
2020 _id : IdSchema ,
21- name : z
22- . string ( )
23- . regex ( / ^ [ 0 - 9 a - z A - Z _ . - ] + $ / )
24- . max ( 16 ) ,
21+ name : slug ( ) . max ( 16 ) ,
2522 pb : z
2623 . object ( {
2724 no : z . boolean ( ) ,
@@ -72,11 +69,13 @@ export const UserStreakSchema = z
7269 } )
7370 . strict ( ) ;
7471export type UserStreak = z . infer < typeof UserStreakSchema > ;
72+ export const TagNameSchema = nameWithSeparators ( ) . max ( 16 ) ;
73+ export type TagName = z . infer < typeof TagNameSchema > ;
7574
7675export const UserTagSchema = z
7776 . object ( {
7877 _id : IdSchema ,
79- name : z . string ( ) ,
78+ name : TagNameSchema ,
8079 personalBests : PersonalBestsSchema ,
8180 } )
8281 . strict ( ) ;
@@ -90,19 +89,13 @@ function profileDetailsBase(
9089 . transform ( ( value ) => ( value === null ? undefined : value ) ) ;
9190}
9291
93- export const TwitterProfileSchema = profileDetailsBase (
94- z
95- . string ( )
96- . max ( 20 )
97- . regex ( / ^ [ 0 - 9 a - z A - Z _ . - ] + $ / ) ,
98- ) . or ( z . literal ( "" ) ) ;
92+ export const TwitterProfileSchema = profileDetailsBase ( slug ( ) . max ( 20 ) ) . or (
93+ z . literal ( "" ) ,
94+ ) ;
9995
100- export const GithubProfileSchema = profileDetailsBase (
101- z
102- . string ( )
103- . max ( 39 )
104- . regex ( / ^ [ 0 - 9 a - z A - Z _ . - ] + $ / ) ,
105- ) . or ( z . literal ( "" ) ) ;
96+ export const GithubProfileSchema = profileDetailsBase ( slug ( ) . max ( 39 ) ) . or (
97+ z . literal ( "" ) ,
98+ ) ;
10699
107100export const WebsiteSchema = profileDetailsBase (
108101 z . string ( ) . url ( ) . max ( 200 ) . startsWith ( "https://" ) ,
@@ -125,10 +118,7 @@ export const UserProfileDetailsSchema = z
125118 . strict ( ) ;
126119export type UserProfileDetails = z . infer < typeof UserProfileDetailsSchema > ;
127120
128- export const CustomThemeNameSchema = z
129- . string ( )
130- . regex ( / ^ [ 0 - 9 a - z A - Z _ - ] + $ / )
131- . max ( 16 ) ;
121+ export const CustomThemeNameSchema = nameWithSeparators ( ) . max ( 16 ) ;
132122export type CustomThemeName = z . infer < typeof CustomThemeNameSchema > ;
133123
134124export const CustomThemeSchema = z
@@ -244,14 +234,7 @@ export type FavoriteQuotes = z.infer<typeof FavoriteQuotesSchema>;
244234export const UserEmailSchema = z . string ( ) . email ( ) ;
245235export const UserNameSchema = doesNotContainDisallowedWords (
246236 "substring" ,
247- z
248- . string ( )
249- . min ( 1 )
250- . max ( 16 )
251- . regex (
252- / ^ [ \d a - z A - Z _ - ] + $ / ,
253- "Can only contain lower/uppercase letters, underscore and minus." ,
254- ) ,
237+ slug ( ) . min ( 1 ) . max ( 16 ) ,
255238) ;
256239
257240export const UserSchema = z . object ( {
@@ -297,12 +280,6 @@ export type ResultFiltersGroup = keyof ResultFilters;
297280export type ResultFiltersGroupItem < T extends ResultFiltersGroup > =
298281 keyof ResultFilters [ T ] ;
299282
300- export const TagNameSchema = z
301- . string ( )
302- . regex ( / ^ [ 0 - 9 a - z A - Z _ . - ] + $ / )
303- . max ( 16 ) ;
304- export type TagName = z . infer < typeof TagNameSchema > ;
305-
306283export const TypingStatsSchema = z . object ( {
307284 completedTests : z . number ( ) . int ( ) . nonnegative ( ) . optional ( ) ,
308285 startedTests : z . number ( ) . int ( ) . nonnegative ( ) . optional ( ) ,
0 commit comments