21 lines
712 B
TypeScript
21 lines
712 B
TypeScript
import { ParseError } from "@homarr/common/server";
|
|
import type { z } from "zod/v4";
|
|
|
|
/**
|
|
* Server-only: pulled out of `unifi-os-types.ts` because `ParseError` comes
|
|
* from `@homarr/common/server`, which drags in `ioredis` and Node's `dns`.
|
|
* `unifi-os-types.ts` is re-exported by `packages/integrations/src/types.ts`,
|
|
* which client components import, so it must stay free of server-only code.
|
|
*/
|
|
export const parseUnifiOsAsync = async <TOutput>(
|
|
value: unknown,
|
|
schema: z.ZodType<TOutput>,
|
|
message: string,
|
|
): Promise<TOutput> => {
|
|
const result = await schema.safeParseAsync(value);
|
|
if (!result.success) {
|
|
throw new ParseError(message, { cause: result.error });
|
|
}
|
|
return result.data;
|
|
};
|