Skip to content

Commit

Permalink
Add a example project in the validate package
Browse files Browse the repository at this point in the history
  • Loading branch information
Karibash committed Mar 15, 2023
1 parent 6a6b7a4 commit a938aef
Show file tree
Hide file tree
Showing 21 changed files with 494 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/inject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ This is a example program describing the basic usage of @nestjs-modular/inject p
The example program can be run by executing the following command.

```sh
npm install
npm run start
$ npm install
$ npm run start
```
4 changes: 1 addition & 3 deletions examples/inject/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
"declaration": true,
"removeComments": true,
Expand All @@ -13,9 +14,6 @@
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
Expand Down
35 changes: 35 additions & 0 deletions examples/validate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
12 changes: 12 additions & 0 deletions examples/validate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# nest-js-modular-validate

This is a example program describing the basic usage of @nestjs-modular/validate package.

## Usage

The example program can be run by executing the following command.

```sh
$ npm install
$ npm run start
```
5 changes: 5 additions & 0 deletions examples/validate/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
47 changes: 47 additions & 0 deletions examples/validate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "nest-js-modular-validate-example",
"version": "0.0.0",
"description": "",
"author": "",
"private": true,
"license": "MIT",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"start": "nest start",
"start:mock": "APP_ENV=mock nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main"
},
"dependencies": {
"@nestjs-modular/validate": "1.0.0",
"@nestjs/common": "9.2.1",
"@nestjs/core": "9.2.1",
"@nestjs/platform-express": "9.2.1",
"@valivali/myzod": "1.0.0",
"@valivali/runtypes": "1.0.0",
"@valivali/superstruct": "1.0.0",
"@valivali/yup": "1.0.0",
"@valivali/zod": "1.0.0",
"myzod": "1.10.0",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"runtypes": "6.6.0",
"rxjs": "7.6.0",
"superstruct": "1.0.3",
"yup": "1.0.2",
"zod": "3.20.2"
},
"devDependencies": {
"@nestjs/cli": "9.1.5",
"@nestjs/schematics": "9.0.3",
"@types/express": "4.17.14",
"@types/node": "16.18.8",
"source-map-support": "0.5.21",
"ts-loader": "9.4.2",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.1",
"typescript": "4.9.4"
}
}
26 changes: 26 additions & 0 deletions examples/validate/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { IncomingValidatePipe } from '@nestjs-modular/validate';
import { Module } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';

import { MyzodModule } from './modules/myzod/myzod.module';
import { RuntypesModule } from './modules/runtypes/runtypes.module';
import { SuperstructModule } from './modules/superstruct/superstruct.module';
import { YupModule } from './modules/yup/yup.module';
import { ZodModule } from './modules/zod/zod.module';

@Module({
imports: [
MyzodModule,
RuntypesModule,
SuperstructModule,
YupModule,
ZodModule,
],
providers: [
{
provide: APP_PIPE,
useClass: IncomingValidatePipe,
},
],
})
export class AppModule {}
10 changes: 10 additions & 0 deletions examples/validate/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app.module';

const bootstrap = async () => {
const app = await NestFactory.create(AppModule);
await app.listen(3005);
};

bootstrap().then();
24 changes: 24 additions & 0 deletions examples/validate/src/modules/myzod/myzod.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createIncomingDto } from '@nestjs-modular/validate';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { resolver } from '@valivali/myzod';
import z from 'myzod';

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

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

@Controller('myzod')
export class MyzodController {
@Post(':id')
public endpoint(
@Param() param: ParamDto,
@Body() body: BodyDto,
): void {
console.log({ param, body });
}
}
10 changes: 10 additions & 0 deletions examples/validate/src/modules/myzod/myzod.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { MyzodController } from './myzod.controller';

@Module({
controllers: [
MyzodController,
],
})
export class MyzodModule {}
24 changes: 24 additions & 0 deletions examples/validate/src/modules/runtypes/runtypes.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createIncomingDto } from '@nestjs-modular/validate';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { resolver } from '@valivali/runtypes';
import * as rt from 'runtypes';

class ParamDto extends createIncomingDto(resolver(rt.Record({
id: rt.String,
}))) {}

class BodyDto extends createIncomingDto(resolver(rt.Record({
title: rt.String,
content: rt.String,
}))) {}

@Controller('runtypes')
export class RuntypesController {
@Post(':id')
public endpoint(
@Param() param: ParamDto,
@Body() body: BodyDto,
): void {
console.log({ param, body });
}
}
10 changes: 10 additions & 0 deletions examples/validate/src/modules/runtypes/runtypes.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { RuntypesController } from './runtypes.controller';

@Module({
controllers: [
RuntypesController,
],
})
export class RuntypesModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createIncomingDto } from '@nestjs-modular/validate';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { resolver } from '@valivali/superstruct';
import st from 'superstruct';

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

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

@Controller('superstruct')
export class SuperstructController {
@Post(':id')
public endpoint(
@Param() param: ParamDto,
@Body() body: BodyDto,
): void {
console.log({ param, body });
}
}
10 changes: 10 additions & 0 deletions examples/validate/src/modules/superstruct/superstruct.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { SuperstructController } from './superstruct.controller';

@Module({
controllers: [
SuperstructController,
],
})
export class SuperstructModule {}
24 changes: 24 additions & 0 deletions examples/validate/src/modules/yup/yup.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createIncomingDto } from '@nestjs-modular/validate';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { resolver } from '@valivali/yup';
import * as yup from 'yup';

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

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

@Controller('yup')
export class YupController {
@Post(':id')
public endpoint(
@Param() param: ParamDto,
@Body() body: BodyDto,
): void {
console.log({ param, body });
}
}
10 changes: 10 additions & 0 deletions examples/validate/src/modules/yup/yup.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { YupController } from './yup.controller';

@Module({
controllers: [
YupController,
],
})
export class YupModule {}
24 changes: 24 additions & 0 deletions examples/validate/src/modules/zod/zod.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 });
}
}
10 changes: 10 additions & 0 deletions examples/validate/src/modules/zod/zod.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { ZodController } from './zod.controller';

@Module({
controllers: [
ZodController,
],
})
export class ZodModule {}
4 changes: 4 additions & 0 deletions examples/validate/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
20 changes: 20 additions & 0 deletions examples/validate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
"declaration": true,
"removeComments": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
Loading

0 comments on commit a938aef

Please sign in to comment.