framework-do-dede 3.4.0 → 4.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/README.md +77 -14
- package/dist/application/controller.d.ts +6 -2
- package/dist/application/controller.js +10 -18
- package/dist/application/index.d.ts +1 -1
- package/dist/application/index.js +1 -1
- package/dist/application/services.d.ts +2 -1
- package/dist/application/services.js +3 -3
- package/dist/dede.d.ts +10 -1
- package/dist/dede.js +30 -9
- package/dist/domain/entity.d.ts +4 -0
- package/dist/domain/entity.js +25 -0
- package/dist/domain/errors/app-error.d.ts +12 -0
- package/dist/domain/errors/app-error.js +14 -0
- package/dist/domain/errors/http-errors.d.ts +42 -0
- package/dist/domain/errors/http-errors.js +40 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.js +2 -0
- package/dist/http/controller.handler.d.ts +4 -5
- package/dist/http/controller.handler.js +27 -119
- package/dist/http/errors/server.d.ts +2 -28
- package/dist/http/errors/server.js +2 -49
- package/dist/http/http-server.d.ts +2 -0
- package/dist/http/http-server.js +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/infra/di/registry.d.ts +4 -6
- package/dist/infra/di/registry.js +7 -10
- package/dist/{application → infra/serialization}/entity.d.ts +3 -1
- package/dist/{application → infra/serialization}/entity.js +7 -25
- package/dist/interface/errors/http-error-mapper.d.ts +10 -0
- package/dist/interface/errors/http-error-mapper.js +31 -0
- package/dist/interface/http/middleware-executor.d.ts +10 -0
- package/dist/interface/http/middleware-executor.js +33 -0
- package/dist/interface/http/request-mapper.d.ts +21 -0
- package/dist/interface/http/request-mapper.js +55 -0
- package/dist/interface/validation/class-validator.d.ts +6 -0
- package/dist/interface/validation/class-validator.js +28 -0
- package/dist/interface/validation/validator.d.ts +5 -0
- package/dist/interface/validation/validator.js +1 -0
- package/dist/protocols/repository.d.ts +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UnprocessableEntity } from '../../domain/errors/http-errors';
|
|
2
|
+
import { validate } from 'class-validator';
|
|
3
|
+
export async function validateWithClassValidator(dtoClass, input) {
|
|
4
|
+
const instance = Object.assign(new dtoClass(), input);
|
|
5
|
+
const errors = await validate(instance);
|
|
6
|
+
if (errors.length === 0)
|
|
7
|
+
return;
|
|
8
|
+
const details = flattenErrors(errors);
|
|
9
|
+
throw new UnprocessableEntity('Validation error', {
|
|
10
|
+
code: 'validation_error',
|
|
11
|
+
details
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function flattenErrors(errors, parentPath = '') {
|
|
15
|
+
const output = [];
|
|
16
|
+
for (const error of errors) {
|
|
17
|
+
const path = parentPath ? `${parentPath}.${error.property}` : error.property;
|
|
18
|
+
if (error.constraints) {
|
|
19
|
+
for (const [rule, message] of Object.entries(error.constraints)) {
|
|
20
|
+
output.push({ path, rule, message });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (error.children && error.children.length > 0) {
|
|
24
|
+
output.push(...flattenErrors(error.children, path));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return output;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "framework-do-dede",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
"test:watch": "jest --watch",
|
|
17
17
|
"clean": "rimraf dist",
|
|
18
18
|
"build": "npm run clean && tsc -p tsconfig.build.json && tsc-alias",
|
|
19
|
-
"prepare": "npm run build"
|
|
19
|
+
"prepare": "npm run build",
|
|
20
|
+
"bench": "node bench/benchmark.mjs",
|
|
21
|
+
"bench:compare": "node bench/run.mjs"
|
|
20
22
|
},
|
|
21
23
|
"files": [
|
|
22
24
|
"dist"
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"typescript": "^5.8.2"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
51
|
+
"class-validator": "^0.14.3",
|
|
49
52
|
"elysia": "^1.3.5",
|
|
50
53
|
"express": "^5.1.0",
|
|
51
54
|
"typescript": "^5.8.2"
|