@atls/nestjs-validation 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/validation.error.d.ts +5 -0
- package/dist/errors/validation.error.js +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/module/index.d.ts +1 -0
- package/dist/module/index.js +1 -0
- package/dist/module/validation.module.d.ts +4 -0
- package/dist/module/validation.module.js +32 -0
- package/dist/validator/index.d.ts +1 -0
- package/dist/validator/index.js +1 -0
- package/dist/validator/validator.d.ts +5 -0
- package/dist/validator/validator.js +16 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validation.error.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./validation.error.js";
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validation.module.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./validation.module.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var ValidationModule_1;
|
|
8
|
+
import { Module } from '@nestjs/common';
|
|
9
|
+
import { Validator } from '../validator/index.js';
|
|
10
|
+
let ValidationModule = ValidationModule_1 = class ValidationModule {
|
|
11
|
+
static register() {
|
|
12
|
+
return {
|
|
13
|
+
module: ValidationModule_1,
|
|
14
|
+
providers: [
|
|
15
|
+
{
|
|
16
|
+
provide: Validator,
|
|
17
|
+
useClass: Validator,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
exports: [
|
|
21
|
+
{
|
|
22
|
+
provide: Validator,
|
|
23
|
+
useClass: Validator,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
ValidationModule = ValidationModule_1 = __decorate([
|
|
30
|
+
Module({})
|
|
31
|
+
], ValidationModule);
|
|
32
|
+
export { ValidationModule };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validator.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./validator.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { plainToInstance } from 'class-transformer';
|
|
2
|
+
import { validate } from 'class-validator';
|
|
3
|
+
import { ValidationError } from '../errors/index.js';
|
|
4
|
+
export class Validator {
|
|
5
|
+
async transform(metatype, value) {
|
|
6
|
+
return plainToInstance(metatype, value);
|
|
7
|
+
}
|
|
8
|
+
async validate(valueOrObject, metatype) {
|
|
9
|
+
const transformed = metatype ? await this.transform(metatype, valueOrObject) : valueOrObject;
|
|
10
|
+
const errors = await validate(transformed);
|
|
11
|
+
if (errors.length > 0) {
|
|
12
|
+
throw new ValidationError(errors);
|
|
13
|
+
}
|
|
14
|
+
return transformed;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atls/nestjs-validation",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "BSD-3-Clause",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn library build",
|
|
20
|
+
"prepack": "yarn run build",
|
|
21
|
+
"postpack": "rm -rf dist"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@nestjs/common": "^10.0.5",
|
|
25
|
+
"@nestjs/core": "^10.0.5",
|
|
26
|
+
"class-transformer": "0.5.1",
|
|
27
|
+
"class-validator": "^0.14.0",
|
|
28
|
+
"reflect-metadata": "^0.1.13",
|
|
29
|
+
"rxjs": "^7.8.1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@nestjs/common": "^10",
|
|
33
|
+
"@nestjs/core": "^10",
|
|
34
|
+
"class-transformer": "0.5",
|
|
35
|
+
"class-validator": "^0.14",
|
|
36
|
+
"reflect-metadata": "^0.1",
|
|
37
|
+
"rxjs": "^7"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"exports": {
|
|
41
|
+
"./package.json": "./package.json",
|
|
42
|
+
".": {
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"default": "./dist/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"main": "dist/index.js",
|
|
49
|
+
"typings": "dist/index.d.ts"
|
|
50
|
+
},
|
|
51
|
+
"typings": "dist/index.d.ts"
|
|
52
|
+
}
|