UNPKG

@ocubist/error-alchemy

Version:

A powerful Node.js error-handling-framework with custom error types for easy debugging, enhanced error management, strong zod-support and useful quality-of-life-functionality for asserting and validating values.

24 lines (18 loc) 664 B
import z from "zod"; import { severitySelector } from "./severitySelector"; // Helper type to extract values from a type type ValueOf<T> = T[keyof T]; // Derive the Severity type from the values of severitySelector export type Severity = ValueOf<typeof severitySelector>; // * Zod-Schema // Extract the values from severitySelector into an array const values = Object.values(severitySelector) as Severity[]; // Cast values to a tuple type expected by Zod const severityTuple: [Severity, ...Severity[]] = values as unknown as [ Severity, ...Severity[] ]; /** * Zod schema for validating severity levels. */ export const Severity = z.enum(severityTuple);