import { InferSchemaType, LiteralSchema, ObjectSchema, Schema, StringSchema, z, } from "@shared/utils/validator.ts"; type ErrorDefinition> = ObjectSchema< { type: LiteralSchema; info: I } >; export function defineError< T extends string, I extends Schema = StringSchema, >( type: T, info?: I, ): ErrorDefinition { return z.obj({ type: z.literal(type), info: (info ?? z.string()) as I, }); } export function createErrorFactory< T extends string, I extends Schema, >( errorDefinition: ErrorDefinition, ): (info: InferSchemaType) => InferSchemaType> { return (info: InferSchemaType) => { return { type: errorDefinition.shape.type.literal, info, }; }; }