CreateQueueSheet.schema.ts30 lines · main
| 1 | import z from 'zod' |
| 2 | |
| 3 | import { QueueNameSchema } from '../Queues.utils' |
| 4 | |
| 5 | const normalQueueSchema = z.object({ |
| 6 | type: z.literal('basic'), |
| 7 | }) |
| 8 | |
| 9 | const partitionedQueueSchema = z.object({ |
| 10 | type: z.literal('partitioned'), |
| 11 | partitionInterval: z.coerce.number().int().positive(), |
| 12 | retentionInterval: z.coerce.number().int().positive(), |
| 13 | }) |
| 14 | |
| 15 | const unloggedQueueSchema = z.object({ |
| 16 | type: z.literal('unlogged'), |
| 17 | }) |
| 18 | |
| 19 | export const FormSchema = z.object({ |
| 20 | name: QueueNameSchema, |
| 21 | enableRls: z.boolean(), |
| 22 | values: z.discriminatedUnion('type', [ |
| 23 | normalQueueSchema, |
| 24 | partitionedQueueSchema, |
| 25 | unloggedQueueSchema, |
| 26 | ]), |
| 27 | }) |
| 28 | |
| 29 | export type CreateQueueForm = z.infer<typeof FormSchema> |
| 30 | export type QueueType = CreateQueueForm['values'] |