@inversifyjs/class-validation 2.0.0
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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/pipes/ClassValidationPipe.d.ts +5 -0
- package/lib/cjs/pipes/ClassValidationPipe.d.ts.map +1 -0
- package/lib/cjs/pipes/ClassValidationPipe.int.spec.d.ts +9 -0
- package/lib/cjs/pipes/ClassValidationPipe.int.spec.d.ts.map +1 -0
- package/lib/cjs/pipes/ClassValidationPipe.js +36 -0
- package/lib/cjs/pipes/ClassValidationPipe.js.map +1 -0
- package/lib/cjs/pipes/ClassValidationPipe.spec.d.ts +2 -0
- package/lib/cjs/pipes/ClassValidationPipe.spec.d.ts.map +1 -0
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/package.json +83 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 inversify
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[](https://codecov.io/gh/inversify/monorepo/branch/main/graph/badge.svg?flag=%40inversifyjs%2Fclass-validation) [](https://www.npmjs.com/package/@inversifyjs/class-validation)
|
|
2
|
+
|
|
3
|
+
# @inversifyjs/class-validation
|
|
4
|
+
|
|
5
|
+
Inversify monorepo class validator validation modules.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassValidationPipe = void 0;
|
|
4
|
+
var ClassValidationPipe_1 = require("./pipes/ClassValidationPipe");
|
|
5
|
+
Object.defineProperty(exports, "ClassValidationPipe", { enumerable: true, get: function () { return ClassValidationPipe_1.ClassValidationPipe; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAAzD,0HAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassValidationPipe.d.ts","sourceRoot":"","sources":["../../../src/pipes/ClassValidationPipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AASjE,qBAAa,mBAAoB,YAAW,IAAI;IACjC,OAAO,CAClB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,OAAO,CAAC;CA0CpB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorFilter, Pipe } from '@inversifyjs/framework-core';
|
|
2
|
+
import { Container, Newable } from 'inversify';
|
|
3
|
+
export interface Server {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
shutdown: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildExpressServer(container: Container, errorFilterList: Newable<ErrorFilter>[], pipeList: (Newable<Pipe> | Pipe)[]): Promise<Server>;
|
|
9
|
+
//# sourceMappingURL=ClassValidationPipe.int.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassValidationPipe.int.spec.d.ts","sourceRoot":"","sources":["../../../src/pipes/ClassValidationPipe.int.spec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,WAAW,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAW5E,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAI/C,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,EACvC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,GACjC,OAAO,CAAC,MAAM,CAAC,CAoDjB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassValidationPipe = void 0;
|
|
4
|
+
const reflect_metadata_utils_1 = require("@inversifyjs/reflect-metadata-utils");
|
|
5
|
+
const validation_common_1 = require("@inversifyjs/validation-common");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const class_validator_1 = require("class-validator");
|
|
8
|
+
class ClassValidationPipe {
|
|
9
|
+
async execute(input, metadata) {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
11
|
+
const inputType = (0, reflect_metadata_utils_1.getOwnReflectMetadata)(
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
13
|
+
metadata.targetClass.prototype, 'design:paramtypes', metadata.methodName)?.[metadata.parameterIndex];
|
|
14
|
+
if (inputType === undefined) {
|
|
15
|
+
throw new validation_common_1.InversifyValidationError(validation_common_1.InversifyValidationErrorKind.invalidConfiguration, `Param type metadata for ${metadata.targetClass.name}.${metadata.methodName.toString()}[${metadata.parameterIndex.toString()}] is not defined. Are you enabling "emitDecoratorMetadata" and "experimentalDecorators" Typescript compiler options?`);
|
|
16
|
+
}
|
|
17
|
+
const instance = (0, class_transformer_1.plainToInstance)(inputType, input);
|
|
18
|
+
const validationResult = await (0, class_validator_1.validate)(instance, {
|
|
19
|
+
forbidNonWhitelisted: true,
|
|
20
|
+
forbidUnknownValues: true,
|
|
21
|
+
skipMissingProperties: false,
|
|
22
|
+
skipNullProperties: false,
|
|
23
|
+
skipUndefinedProperties: false,
|
|
24
|
+
stopAtFirstError: false,
|
|
25
|
+
whitelist: true,
|
|
26
|
+
});
|
|
27
|
+
if (validationResult.length > 0) {
|
|
28
|
+
throw new validation_common_1.InversifyValidationError(validation_common_1.InversifyValidationErrorKind.validationFailed, validationResult
|
|
29
|
+
.map((error) => error.toString(false, false))
|
|
30
|
+
.join('\n'));
|
|
31
|
+
}
|
|
32
|
+
return instance;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ClassValidationPipe = ClassValidationPipe;
|
|
36
|
+
//# sourceMappingURL=ClassValidationPipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ClassValidationPipe.ts"],"names":[],"mappings":";;;AACA,gFAA4E;AAC5E,sEAGwC;AACxC,yDAAsE;AACtE,qDAA4D;AAE5D,MAAa,mBAAmB;IACvB,KAAK,CAAC,OAAO,CAClB,KAAc,EACd,QAAsB;QAEtB,sEAAsE;QACtE,MAAM,SAAS,GAAyB,IAAA,8CAAqB;QAC3D,iEAAiE;QACjE,QAAQ,CAAC,WAAW,CAAC,SAAS,EAC9B,mBAAmB,EACnB,QAAQ,CAAC,UAAU,CACpB,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAE7B,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,4CAAwB,CAChC,gDAA4B,CAAC,oBAAoB,EACjD,2BAA2B,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,sHAAsH,CACnP,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAW,IAAA,mCAAe,EACtC,SAAqC,EACrC,KAAK,CACN,CAAC;QAEF,MAAM,gBAAgB,GAAsB,MAAM,IAAA,0BAAQ,EAAC,QAAQ,EAAE;YACnE,oBAAoB,EAAE,IAAI;YAC1B,mBAAmB,EAAE,IAAI;YACzB,qBAAqB,EAAE,KAAK;YAC5B,kBAAkB,EAAE,KAAK;YACzB,uBAAuB,EAAE,KAAK;YAC9B,gBAAgB,EAAE,KAAK;YACvB,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,4CAAwB,CAChC,gDAA4B,CAAC,gBAAgB,EAC7C,gBAAgB;iBACb,GAAG,CAAC,CAAC,KAAsB,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;iBAC7D,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA9CD,kDA8CC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassValidationPipe.spec.d.ts","sourceRoot":"","sources":["../../../src/pipes/ClassValidationPipe.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getOwnReflectMetadata as t}from"@inversifyjs/reflect-metadata-utils";import{InversifyValidationError as e,InversifyValidationErrorKind as r}from"@inversifyjs/validation-common";import{plainToInstance as i}from"class-transformer";import{validate as o}from"class-validator";class a{async execute(a,n){const s=t(n.targetClass.prototype,"design:paramtypes",n.methodName)?.[n.parameterIndex];if(void 0===s)throw new e(r.invalidConfiguration,`Param type metadata for ${n.targetClass.name}.${n.methodName.toString()}[${n.parameterIndex.toString()}] is not defined. Are you enabling "emitDecoratorMetadata" and "experimentalDecorators" Typescript compiler options?`);const m=i(s,a),p=await o(m,{forbidNonWhitelisted:!0,forbidUnknownValues:!0,skipMissingProperties:!1,skipNullProperties:!1,skipUndefinedProperties:!1,stopAtFirstError:!1,whitelist:!0});if(p.length>0)throw new e(r.validationFailed,p.map(t=>t.toString(!1,!1)).join("\n"));return m}}export{a as ClassValidationPipe};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/pipes/ClassValidationPipe.ts"],"sourcesContent":[null],"names":["ClassValidationPipe","execute","input","metadata","inputType","getOwnReflectMetadata","targetClass","prototype","methodName","parameterIndex","undefined","InversifyValidationError","InversifyValidationErrorKind","invalidConfiguration","name","toString","instance","plainToInstance","validationResult","validate","forbidNonWhitelisted","forbidUnknownValues","skipMissingProperties","skipNullProperties","skipUndefinedProperties","stopAtFirstError","whitelist","length","validationFailed","map","error","join"],"mappings":"6RASaA,EACJ,aAAMC,CACXC,EACAC,GAGA,MAAMC,EAAkCC,EAEtCF,EAASG,YAAYC,UACrB,oBACAJ,EAASK,cACPL,EAASM,gBAEb,QAAkBC,IAAdN,EACF,MAAM,IAAIO,EACRC,EAA6BC,qBAC7B,2BAA2BV,EAASG,YAAYQ,QAAQX,EAASK,WAAWO,cAAcZ,EAASM,eAAeM,kIAItH,MAAMC,EAAmBC,EACvBb,EACAF,GAGIgB,QAA4CC,EAASH,EAAU,CACnEI,sBAAsB,EACtBC,qBAAqB,EACrBC,uBAAuB,EACvBC,oBAAoB,EACpBC,yBAAyB,EACzBC,kBAAkB,EAClBC,WAAW,IAGb,GAAIR,EAAiBS,OAAS,EAC5B,MAAM,IAAIhB,EACRC,EAA6BgB,iBAC7BV,EACGW,IAAKC,GAA2BA,EAAMf,UAAS,GAAO,IACtDgB,KAAK,OAIZ,OAAOf,CACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Roberto Pintos López",
|
|
3
|
+
"bugs": {
|
|
4
|
+
"url": "https://github.com/inversify/monorepo/issues"
|
|
5
|
+
},
|
|
6
|
+
"description": "InversifyJs class-validator validation package",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@inversifyjs/framework-core": "1.0.0",
|
|
9
|
+
"@inversifyjs/reflect-metadata-utils": "1.4.0",
|
|
10
|
+
"@inversifyjs/validation-common": "2.0.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@stryker-mutator/core": "9.1.1",
|
|
14
|
+
"@stryker-mutator/typescript-checker": "9.1.1",
|
|
15
|
+
"@stryker-mutator/vitest-runner": "9.1.1",
|
|
16
|
+
"@types/express": "5.0.3",
|
|
17
|
+
"@types/node": "22.18.6",
|
|
18
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
19
|
+
"eslint": "9.36.0",
|
|
20
|
+
"inversify": "^7.10.0",
|
|
21
|
+
"prettier": "3.6.2",
|
|
22
|
+
"rimraf": "6.0.1",
|
|
23
|
+
"rollup": "4.52.0",
|
|
24
|
+
"ts-loader": "9.5.4",
|
|
25
|
+
"tslib": "2.8.1",
|
|
26
|
+
"typescript": "5.9.2",
|
|
27
|
+
"vitest": "3.2.4",
|
|
28
|
+
"@inversifyjs/http-core": "2.0.0",
|
|
29
|
+
"@inversifyjs/http-express": "2.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devEngines": {
|
|
32
|
+
"node": "^22.10.2",
|
|
33
|
+
"pnpm": "^9.12.1"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://inversify.io",
|
|
36
|
+
"keywords": [
|
|
37
|
+
"dependency injection",
|
|
38
|
+
"dependency inversion",
|
|
39
|
+
"di",
|
|
40
|
+
"inversion of control container",
|
|
41
|
+
"ioc",
|
|
42
|
+
"javascript",
|
|
43
|
+
"node",
|
|
44
|
+
"typescript"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"main": "lib/cjs/index.js",
|
|
48
|
+
"module": "lib/esm/index.js",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"import": "./lib/esm/index.js",
|
|
52
|
+
"require": "./lib/cjs/index.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"name": "@inversifyjs/class-validation",
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"class-transformer": "~0.5.1",
|
|
58
|
+
"class-validator": "~0.14.2"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/inversify/monorepo.git"
|
|
66
|
+
},
|
|
67
|
+
"version": "2.0.0",
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "pnpm run build:cjs && pnpm run build:esm",
|
|
70
|
+
"build:cjs": "tsc --build tsconfig.cjs.json && pnpm exec foundation-ts-package-cjs ./lib/cjs",
|
|
71
|
+
"build:esm": "rollup -c ./rollup.config.mjs && pnpm exec foundation-ts-package-esm ./lib/esm",
|
|
72
|
+
"build:clean": "rimraf lib",
|
|
73
|
+
"format": "prettier --write ./src",
|
|
74
|
+
"lint": "eslint ./src",
|
|
75
|
+
"prebuild": "pnpm run build:clean",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"test:integration": "pnpm run test --project Integration",
|
|
78
|
+
"test:coverage": "pnpm run test:unit --coverage",
|
|
79
|
+
"test:mutation": "stryker run",
|
|
80
|
+
"test:uncommitted": "pnpm run test --changed=HEAD",
|
|
81
|
+
"test:unit": "pnpm run test --project Unit"
|
|
82
|
+
}
|
|
83
|
+
}
|