UNPKG

@energica-city/shared-amplify-utils

Version:

Shared utilities for AWS Amplify projects

25 lines 1.38 kB
import type { RestModelInitializerConfig, RestInputWithModels, RestHandlerReturn, RestResponse } from './types'; import type { Middleware } from '../middlewareChain'; import type { AmplifyModelType } from '../../queries/types'; /** * Creates REST model initializer middleware * * Creates a middleware function that initializes Amplify Data models * for use in REST API handlers. Provides connection pooling, timeout * handling, optional caching, and type-safe model access through the middleware chain. * * **Key Feature**: Automatically wraps all models with REST-aware error handling * that converts database errors to appropriate HTTP status codes (404, 400, 409, 500). * * Features: * - Lazy initialization with caching * - Connection timeout protection * - Optional in-memory caching with LRU eviction * - Type-safe model selection * - Automatic REST error conversion * - Structured logging integration */ export declare function createRestModelInitializer<TSchema extends { models: Record<string, unknown>; }, TTypes extends Record<string, AmplifyModelType>, TSelected extends keyof TTypes & string = keyof TTypes & string, TReturn extends RestHandlerReturn = RestResponse>(config: RestModelInitializerConfig<TSchema, TTypes, TSelected>): Middleware<RestInputWithModels<TTypes, TSelected>, TReturn>; //# sourceMappingURL=RestModelInitializer.d.ts.map