11import { z , type ZodString } from "zod" ;
22
3+ // Shared validation constants
4+ const NO_SLASH_REGEX = / ^ [ ^ / ] * $ / ;
5+ const NO_SLASH_ERROR = "String cannot contain '/'" ;
6+
37export const CommonArgs = {
48 string : ( ) : ZodString =>
59 z . string ( ) . regex ( / ^ [ \x20 - \x7E ] * $ / , "String cannot contain special characters or Unicode symbols" ) ,
@@ -19,21 +23,21 @@ export const AtlasArgs = {
1923 CommonArgs . string ( )
2024 . min ( 1 , "Cluster name is required" )
2125 . max ( 64 , "Cluster name must be 64 characters or less" )
22- . regex ( / ^ [ ^ / ] * $ / , "String cannot contain '/'" )
26+ . regex ( NO_SLASH_REGEX , NO_SLASH_ERROR )
2327 . regex ( / ^ [ a - z A - Z 0 - 9 _ - ] + $ / , "Cluster name can only contain letters, numbers, hyphens, and underscores" ) ,
2428
2529 projectName : ( ) : z . ZodString =>
2630 CommonArgs . string ( )
2731 . min ( 1 , "Project name is required" )
2832 . max ( 64 , "Project name must be 64 characters or less" )
29- . regex ( / ^ [ ^ / ] * $ / , "String cannot contain '/'" )
33+ . regex ( NO_SLASH_REGEX , NO_SLASH_ERROR )
3034 . regex ( / ^ [ a - z A - Z 0 - 9 _ - ] + $ / , "Project name can only contain letters, numbers, hyphens, and underscores" ) ,
3135
3236 username : ( ) : z . ZodString =>
3337 CommonArgs . string ( )
3438 . min ( 1 , "Username is required" )
3539 . max ( 100 , "Username must be 100 characters or less" )
36- . regex ( / ^ [ ^ / ] * $ / , "String cannot contain '/'" )
40+ . regex ( NO_SLASH_REGEX , NO_SLASH_ERROR )
3741 . regex ( / ^ [ a - z A - Z 0 - 9 . _ - ] + $ / , "Username can only contain letters, numbers, dots, hyphens, and underscores" ) ,
3842
3943 ipAddress : ( ) : z . ZodString => CommonArgs . string ( ) . ip ( { version : "v4" } ) ,
@@ -50,6 +54,6 @@ export const AtlasArgs = {
5054 CommonArgs . string ( )
5155 . min ( 1 , "Password is required" )
5256 . max ( 100 , "Password must be 100 characters or less" )
53- . regex ( / ^ [ ^ / ] * $ / , "String cannot contain '/'" )
57+ . regex ( NO_SLASH_REGEX , NO_SLASH_ERROR )
5458 . regex ( / ^ [ a - z A - Z 0 - 9 . _ - ] + $ / , "Password can only contain letters, numbers, dots, hyphens, and underscores" ) ,
5559} ;
0 commit comments