-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Karibash/feature/validate
Add a validate package
- Loading branch information
Showing
30 changed files
with
792 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
examples/validate/src/modules/runtypes/runtypes.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
24 changes: 24 additions & 0 deletions
24
examples/validate/src/modules/superstruct/superstruct.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
examples/validate/src/modules/superstruct/superstruct.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.