mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-03 05:09:16 +01:00
* feat: add pi hole summary integration * feat: add pi hole summary widget * fix: type issues with integrations and integrationIds * feat: add middleware for integrations and improve cache redis channel * feat: add error boundary for widgets * fix: broken lock file * fix: format format issues * fix: typecheck issue * fix: deepsource issues * fix: widget sandbox without error boundary * chore: address pull request feedback * chore: remove todo comment and created issue * fix: format issues * fix: deepsource issue
58 lines
1.6 KiB
TypeScript
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(),
|
|
integrationIds: z.array(z.string()),
|
|
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)]);
|