@energica-city/shared-amplify-utils
Version:
Shared utilities for AWS Amplify projects
57 lines • 1.93 kB
TypeScript
import * as yup from 'yup';
/**
* Base validation configuration interface shared across all validators
*/
export interface BaseValidationConfig {
/** Whether to strip unknown fields from validated data */
stripUnknown?: boolean;
/** Whether to abort validation on first error or collect all errors */
abortEarly?: boolean;
/** Custom error message for validation failures */
errorMessage?: string;
/** Additional context to include with validation errors */
errorContext?: Record<string, unknown>;
}
/**
* Validation error details shared across all validators
*/
export interface ValidationErrorDetail {
/** The field that failed validation */
field: string;
/** Human-readable error message */
message: string;
/** The value that failed validation */
value: unknown;
/** Type of validation that failed */
type: string;
}
/**
* Extracts error details from Yup validation error
* Shared utility function for all validators
*/
export declare function extractYupErrors(error: yup.ValidationError): ValidationErrorDetail[];
/**
* Common validation patterns that can be reused across validators
*/
export declare const ValidationPatterns: {
/** UUID validation pattern */
readonly uuid: () => yup.StringSchema<string, yup.AnyObject, undefined, "">;
/** Email validation pattern */
readonly email: () => yup.StringSchema<string, yup.AnyObject, undefined, "">;
/** Pagination query parameters */
readonly pagination: () => yup.ObjectSchema<{
page: number;
limit: number;
}, yup.AnyObject, {
page: 1;
limit: 10;
}, "">;
/** ID parameter for path parameters */
readonly idParam: () => yup.ObjectSchema<{
id: string;
}, yup.AnyObject, {
id: undefined;
}, "">;
};
export type ValidationPatternsType = typeof ValidationPatterns;
//# sourceMappingURL=validation.d.ts.map