UNPKG

@energica-city/shared-amplify-utils

Version:

Shared utilities for AWS Amplify projects

79 lines 3.98 kB
import type { Middleware } from '../middlewareChain'; import type { RestResponse, RestInputWithModels, RestInputWithValidation, RestRequestValidationConfig } from './types'; import type { AmplifyModelType } from '../../queries/types'; /** Symbol key for storing validated request body data */ declare const VALIDATED_BODY_KEY: unique symbol; /** Symbol key for storing validated query parameters */ declare const VALIDATED_QUERY_KEY: unique symbol; /** Symbol key for storing validated path parameters */ declare const VALIDATED_PATH_KEY: unique symbol; /** Symbol key for storing validated headers */ declare const VALIDATED_HEADERS_KEY: unique symbol; export { VALIDATED_BODY_KEY, VALIDATED_QUERY_KEY, VALIDATED_PATH_KEY, VALIDATED_HEADERS_KEY, }; /** * Retrieves validated request body from middleware chain * * Extracts the validated and type-safe request body that was * processed by the validation middleware. * * @template T - Expected type of the validated body * @param input - REST input with validation data * @returns Validated request body data */ export declare function getValidatedBody<T = unknown>(input: RestInputWithValidation): T; /** * Retrieves validated query parameters from middleware chain * * Extracts the validated and type-safe query string parameters * that were processed by the validation middleware. * * @template T - Expected type of the validated query parameters * @param input - REST input with validation data * @returns Validated query parameters object */ export declare function getValidatedQuery<T = Record<string, unknown>>(input: RestInputWithValidation): T; /** * Retrieves validated path parameters from middleware chain * * Extracts the validated and type-safe path parameters * that were processed by the validation middleware. * * @template T - Expected type of the validated path parameters * @param input - REST input with validation data * @returns Validated path parameters object */ export declare function getValidatedPath<T = Record<string, unknown>>(input: RestInputWithValidation): T; /** * Retrieves validated headers from middleware chain * * Extracts the validated and type-safe request headers * that were processed by the validation middleware. * * @template T - Expected type of the validated headers * @param input - REST input with validation data * @returns Validated headers object */ export declare function getValidatedHeaders<T = Record<string, unknown>>(input: RestInputWithValidation): T; /** * Creates REST request validator middleware * * Creates a middleware function that validates different parts of * the HTTP request (body, query, path, headers) using Yup schemas. * Stores validated data for type-safe access in downstream handlers. * * @template TTypes - Record of all available Amplify model types * @template TSelected - Subset of model types to initialize * @param config - Validation configuration with schemas and options * @param config.bodySchema - Yup schema for request body validation * @param config.querySchema - Yup schema for query parameter validation * @param config.pathSchema - Yup schema for path parameter validation * @param config.headersSchema - Yup schema for header validation * @param config.stripUnknown - Remove unknown fields from validated data * @param config.abortEarly - Stop validation on first error * @param config.errorMessage - Custom error message for validation failures * @param config.errorContext - Additional context to include in validation errors * @returns Middleware function for request validation * @throws RestErrors.validation when validation fails */ export declare function createRestRequestValidator<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TSelected extends keyof TTypes = keyof TTypes>(config: RestRequestValidationConfig): Middleware<RestInputWithModels<TTypes, TSelected>, RestResponse>; //# sourceMappingURL=RestRequestValidator.d.ts.map