ProjectCreation.schema.ts65 lines · main
1import { z } from 'zod'
2
3import { DEFAULT_MINIMUM_PASSWORD_STRENGTH } from '@/lib/constants'
4
5export const FormSchema = z
6 .object({
7 organization: z.string({
8 required_error: 'Please select an organization',
9 }),
10 projectName: z
11 .string()
12 .trim()
13 .min(1, 'Please enter a project name.') // Required field check
14 .min(3, 'Project name must be at least 3 characters long.') // Minimum length check
15 .max(64, 'Project name must be no longer than 64 characters.'), // Maximum length check
16 highAvailability: z.boolean(),
17 postgresVersion: z.string({
18 required_error: 'Please enter a Postgres version.',
19 }),
20 instanceType: z.string().optional(),
21 dbRegion: z.string({
22 required_error: 'Please select a region.',
23 }),
24 cloudProvider: z.string({
25 required_error: 'Please select a cloud provider.',
26 }),
27
28 dbPass: z
29 .string({ required_error: 'Please enter a database password.' })
30 .min(1, 'Password is required.'),
31 dbPassStrength: z
32 .union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)])
33 .default(0),
34 dbPassStrengthMessage: z.string().default(''),
35 dbPassStrengthWarning: z.string().default(''),
36 instanceSize: z.string().optional(),
37 githubRepositoryId: z.string().optional().default(''),
38 githubInstallationId: z.number().optional(),
39 githubRepositoryName: z.string().optional().default(''),
40 dataApi: z.boolean(),
41 dataApiDefaultPrivileges: z.boolean(),
42 enableRlsEventTrigger: z.boolean(),
43 postgresVersionSelection: z.string(),
44 useOrioleDb: z.boolean(),
45 })
46 .superRefine(
47 ({ dbPassStrength, dbPassStrengthWarning, highAvailability, cloudProvider }, ctx) => {
48 if (dbPassStrength < DEFAULT_MINIMUM_PASSWORD_STRENGTH) {
49 ctx.addIssue({
50 code: z.ZodIssueCode.custom,
51 path: ['dbPass'],
52 message: dbPassStrengthWarning || 'Password not secure enough',
53 })
54 }
55 if (highAvailability && cloudProvider !== 'AWS_K8S') {
56 ctx.addIssue({
57 code: z.ZodIssueCode.custom,
58 path: ['cloudProvider'],
59 message: 'High availability is only supported on AWS (Revamped)',
60 })
61 }
62 }
63 )
64
65export type CreateProjectForm = z.infer<typeof FormSchema>