|
| 1 | +import { z } from "zod"; |
| 2 | +/** |
| 3 | + * Common Zod validators for Atlas tools |
| 4 | + * These can be reused across different Atlas tools for consistent validation |
| 5 | + */ |
| 6 | +export const AtlasArgs = { |
| 7 | + objectId: (fieldName: string): z.ZodString => |
| 8 | + z |
| 9 | + .string() |
| 10 | + .min(1, `${fieldName} is required`) |
| 11 | + .regex(/^[0-9a-fA-F]{24}$/, `${fieldName} must be a valid 24-character hexadecimal string`), |
| 12 | + |
| 13 | + projectId: (): z.ZodString => AtlasArgs.objectId("Project ID"), |
| 14 | + |
| 15 | + organizationId: (): z.ZodString => AtlasArgs.objectId("Organization ID"), |
| 16 | + |
| 17 | + clusterName: (): z.ZodString => |
| 18 | + z |
| 19 | + .string() |
| 20 | + .min(1, "Cluster name is required") |
| 21 | + .max(64, "Cluster name must be 64 characters or less") |
| 22 | + .regex(/^[a-zA-Z0-9_-]+$/, "Cluster name can only contain letters, numbers, hyphens, and underscores"), |
| 23 | + |
| 24 | + username: (): z.ZodString => |
| 25 | + z |
| 26 | + .string() |
| 27 | + .min(1, "Username is required") |
| 28 | + .max(100, "Username must be 100 characters or less") |
| 29 | + .regex(/^[a-zA-Z0-9._-]+$/, "Username can only contain letters, numbers, dots, hyphens, and underscores"), |
| 30 | + |
| 31 | + ipAddress: (): z.ZodString => z.string().ip({ version: "v4" }), |
| 32 | + |
| 33 | + cidrBlock: (): z.ZodString => |
| 34 | + z.string().regex(/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/, "Must be a valid CIDR block (e.g., 192.168.1.0/24)"), |
| 35 | + |
| 36 | + region: (): z.ZodString => |
| 37 | + z.string().regex(/^[a-zA-Z0-9_-]+$/, "Region can only contain letters, numbers, hyphens, and underscores"), |
| 38 | +}; |
0 commit comments