1.0.0 • Published 1 year ago

@nestjs-modular/validate v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@nestjs-modular/validate

npm version codecov license Github Twitter

This module provides a pipe to validate incoming requests using schema validation such as Zod or Yup.

This simplifies validation of incoming requests.

🗒 Examples

🚀 Installation

$ npm install @nestjs-modular/validate

Install the schema validation library of your choice. The following is an example of using zod.

$ npm install @valivali/zod zod

👏 Getting Started

The following is a simple example of using zod.

import { createIncomingDto } from '@nestjs-modular/validate';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { resolver } from '@valivali/zod';
import { z } from 'zod';

class ParamDto extends createIncomingDto(resolver(z.object({
  id: z.string(),
}))) {}

class BodyDto extends createIncomingDto(resolver(z.object({
  title: z.string(),
  content: z.string(),
}))) {}

@Controller('zod')
export class ZodController {
  @Post(':id')
  public endpoint(
    @Param() param: ParamDto,
    @Body() body: BodyDto,
  ): void {
    console.log({ param, body });
  }
}

🤝 Contributing

Contributions, issues and feature requests are welcome.

Feel free to check issues page if you want to contribute.

📝 License

Copyright © 2020 @Karibash.

This project is MIT licensed.