![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@lambda-middleware/compose
Advanced tools
A compose function for lambda middleware. This is a pure convenience copy of ramda's compose, using it directly or using other compose functions works as well.
This middleware is part of the lambda middleware series. It can be used independently.
import { compose } from "@lambda-middleware/compose";
import { PromiseHandler } from "@lambda-middleware/utils";
import { Context, ProxyHandler, APIGatewayEvent } from "aws-lambda";
// This is your AWS handler
async function helloWorld(): Promise<object> {
return {
message: "Hello world!",
};
}
// Write your own middleware
const stringifyToBody = () => (
handle: PromiseHandler<APIGatewayEvent, object>
) => async (event: APIGatewayEvent, context: Context) => {
const response = await handle(event, context);
return {
body: JSON.stringify(response),
};
};
const addStatusCode = (statusCode: number) => (
handle: PromiseHandler<APIGatewayEvent, { body: string }>
) => async (event: APIGatewayEvent, context: Context) => {
const response = await handle(event, context);
return {
...response,
statusCode,
};
};
// Wrap the handler with the middleware.
// With compose you can wrap multiple middlewares around one handler.
export const handler: ProxyHandler = compose(
addStatusCode(200),
stringifyToBody()
)(helloWorld);
There's a known issue with TypeScript that pipe and compose functions cannot
infer types correctly if the innermost function is generic (in this case the last argument to compose
).
To get around it, this package also exports composeHandler
:
import "reflect-metadata";
import { classValidator } from "@lambda-middleware/class-validator";
import { compose } from "@lambda-middleware/compose";
import { errorHandler } from "@lambda-middleware/http-error-handler";
import { IsString } from "class-validator";
import { APIGatewayProxyResult } from "aws-lambda";
class NameBody {
constructor(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName;
}
@IsString()
public firstName: string;
@IsString()
public lastName: string;
}
async function helloWorld(event: {
body: NameBody;
}): Promise<APIGatewayProxyResult> {
return {
body: `Hello ${event.body.firstName} ${event.body.lastName}`,
headers: {
"content-type": "text",
},
statusCode: 200,
};
}
export const handler = composeHandler(
errorHandler(),
classValidator({
bodyType: NameBody,
}),
// The following function solves the type trouble:
helloWorld
);
FAQs
A compose function for functional lambda middleware.
The npm package @lambda-middleware/compose receives a total of 8,253 weekly downloads. As such, @lambda-middleware/compose popularity was classified as popular.
We found that @lambda-middleware/compose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.