UNPKG

@uni-ts/model

Version:

Utils for creating data models in TypeScript.

45 lines 1.51 kB
import type { StandardSchemaV1 } from './standard-schema.js'; /** * Error thrown when data validation fails against a model's schema. * * Contains detailed information about all validation issues that occurred during validation. * The error message is set to the first issue's message for convenience. * * @example * ```typescript * import { createModel, ModelValidationError } from '@uni-ts/model'; * import { z } from 'zod'; * * const User = createModel(z.object({ * name: z.string().min(1), * email: z.string().email(), * })); * * try { * User.from({ name: '', email: 'invalid-email' }); * } catch (ex) { * if (ex instanceof ModelValidationError) { * console.error('Issues:', ex.issues); * } * } * ``` */ export declare class ModelValidationError extends Error { /** * Used to distinguish this error from others with the same shape. */ readonly type = "ModelValidationError"; /** * Array of all validation issues that caused the error. * Each issue contains details about what validation rule failed and where. */ readonly issues: StandardSchemaV1.FailureResult['issues']; /** * Creates a new ModelValidationError with the provided validation issues. * * @param issues - Array of validation issues from the schema validation */ constructor(issues: StandardSchemaV1.FailureResult['issues']); } export declare function prettifyError(error: ModelValidationError): string; //# sourceMappingURL=error.d.ts.map