![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@lambda-middleware/class-validator
Advanced tools
A validation middleware for AWS http lambda functions based on class-validator.
A validation middleware for AWS http lambda functions based on class-validator and class-transformer.
This middleware is part of the lambda middleware series. It can be used independently.
// When using decorators, don't forget to import this in the very first line of code
import "reflect-metadata";
import { classValidator } from '@lambda-middleware/class-validator'
import { composeHandler } from "@lambda-middleware/compose";
import { errorHandler } from "@lambda-middleware/http-error-handler";
import { IsString } from "class-validator";
// Define a validator for the body via class-validator
class NameBody {
constructor(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName;
}
@IsString()
public firstName: string;
@IsString()
public lastName: string;
}
// This is your AWS handler
async function helloWorld(event: { body: NameBody }) {
// Thanks to the validation middleware you can be sure body is typed correctly
return {
body: `Hello ${event.body.firstName} ${event.body.lastName}`,
headers: {
"content-type": "text",
},
statusCode: 200,
};
}
// Let's add middleware to our handler, then we will be able to attach middlewares to it
export const handler = composeHandler(
// The class validator throws validation errors from http-errors which are compatible with
// the error handler middlewares for middy
errorHandler(),
classValidator({
// Add the validation class here
bodyType: NameBody,
// You can add options to class-transformer. These will be passed through,
// so read the class-transformer documentation for details
transformer: {},
// You can add options to class-validator. For security reasons,
// whitelist by default is set to true. If you set any options, you have
// to set it to true manually as the default for class-validator would be
// false
validator: {},
}),
helloWorld
);
FAQs
A validation middleware for AWS http lambda functions based on class-validator.
The npm package @lambda-middleware/class-validator receives a total of 1,526 weekly downloads. As such, @lambda-middleware/class-validator popularity was classified as popular.
We found that @lambda-middleware/class-validator 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
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.