@energica-city/shared-amplify-utils
Version:
Shared utilities for AWS Amplify projects
38 lines • 1.63 kB
JavaScript
import { MiddlewareChain } from '../middlewareChain';
/**
* Creates a new REST middleware chain with type-safe model support
*
* Initializes a composable middleware chain for REST API handlers
* with support for Amplify Data models and custom return types.
*
* @template TTypes - Record of all available Amplify model types
* @template TSelected - Subset of model types to initialize
* @template TReturn - Handler return type (defaults to RestHandlerReturn)
* @param config - Configuration options for the middleware chain
* @param config.enableDebugLogging - Enable detailed middleware execution logging
* @param config.onError - Custom error handler for middleware failures
* @returns Configured REST middleware chain instance
*/
export function createRestChain(config = {}) {
return new MiddlewareChain(config);
}
/**
* Wraps a REST handler function with middleware chain execution
*
* Converts a middleware chain and handler into a Lambda-compatible
* function that executes middleware before the handler.
*
* @template TTypes - Record of all available Amplify model types
* @template TSelected - Subset of model types to initialize
* @template TReturn - Handler return type
* @param chain - Configured REST middleware chain
* @param handler - Handler function to execute after middleware
* @returns Lambda-compatible function with middleware execution
*/
export function wrapRestHandler(chain, handler) {
return async (event, context) => {
const input = { event, context };
return await chain.execute(input, handler);
};
}
//# sourceMappingURL=RestMiddlewareChain.js.map