Files
homarr/packages/validation/src/shared.ts
Meier Lukas 26b1c4a319 feat: add custom css for board and custom classes in advanced options for items (#512)
* feat: add custom css for board and custom classes in advanced options for items

* chore: add mysql migration

* fix: test not working

* fix: format issues

* fix: typecheck issue

* fix: build issue

* chore: add missing translations

* fix: merge issues related to migrations

* fix: format issues

* fix: merge issue with migration

* fix: format issue
2024-05-19 23:01:26 +02:00

58 lines
1.6 KiB
TypeScript

import { z } from "zod";
import { integrationKinds, widgetKinds } from "@homarr/definitions";
import { zodEnumFromArray } from "./enums";
export const integrationSchema = z.object({
id: z.string(),
kind: zodEnumFromArray(integrationKinds),
name: z.string(),
url: z.string(),
});
export type BoardItemIntegration = z.infer<typeof integrationSchema>;
export const itemAdvancedOptionsSchema = z.object({
customCssClasses: z.array(z.string()).default([]),
});
export type BoardItemAdvancedOptions = z.infer<typeof itemAdvancedOptionsSchema>;
export const sharedItemSchema = z.object({
id: z.string(),
xOffset: z.number(),
yOffset: z.number(),
height: z.number(),
width: z.number(),
integrations: z.array(integrationSchema),
advancedOptions: itemAdvancedOptionsSchema,
});
export const commonItemSchema = z
.object({
kind: zodEnumFromArray(widgetKinds),
options: z.record(z.unknown()),
})
.and(sharedItemSchema);
const createCategorySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
z.object({
id: z.string(),
name: z.string(),
kind: z.literal("category"),
position: z.number(),
items: z.array(itemSchema),
});
const createEmptySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
z.object({
id: z.string(),
kind: z.literal("empty"),
position: z.number(),
items: z.array(itemSchema),
});
export const createSectionSchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
z.union([createCategorySchema(itemSchema), createEmptySchema(itemSchema)]);