refactor: Break apart monolithic configuration schema (#1977)
[skip ci]
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { z } from 'zod';
|
||||
import { actionConfigSchema } from './actions/types';
|
||||
import { advancedCameraCardConditionSchema } from './conditions/types';
|
||||
|
||||
const automationActionsSchema = actionConfigSchema.array();
|
||||
export type AutomationActions = z.infer<typeof automationActionsSchema>;
|
||||
|
||||
const automationSchema = z
|
||||
.object({
|
||||
conditions: advancedCameraCardConditionSchema.array(),
|
||||
actions: automationActionsSchema.optional(),
|
||||
actions_not: automationActionsSchema.optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => data.actions?.length || data.actions_not?.length,
|
||||
'Automations must include at least one action',
|
||||
);
|
||||
export type Automation = z.infer<typeof automationSchema>;
|
||||
|
||||
export const automationsSchema = automationSchema.array();
|
||||
Reference in New Issue
Block a user