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.
Files changed (43) hide show
  1. package/README.md +77 -14
  2. package/dist/application/controller.d.ts +6 -2
  3. package/dist/application/controller.js +10 -18
  4. package/dist/application/index.d.ts +1 -1
  5. package/dist/application/index.js +1 -1
  6. package/dist/application/services.d.ts +2 -1
  7. package/dist/application/services.js +3 -3
  8. package/dist/dede.d.ts +10 -1
  9. package/dist/dede.js +30 -9
  10. package/dist/domain/entity.d.ts +4 -0
  11. package/dist/domain/entity.js +25 -0
  12. package/dist/domain/errors/app-error.d.ts +12 -0
  13. package/dist/domain/errors/app-error.js +14 -0
  14. package/dist/domain/errors/http-errors.d.ts +42 -0
  15. package/dist/domain/errors/http-errors.js +40 -0
  16. package/dist/domain/index.d.ts +2 -0
  17. package/dist/domain/index.js +2 -0
  18. package/dist/http/controller.handler.d.ts +4 -5
  19. package/dist/http/controller.handler.js +27 -119
  20. package/dist/http/errors/server.d.ts +2 -28
  21. package/dist/http/errors/server.js +2 -49
  22. package/dist/http/http-server.d.ts +2 -0
  23. package/dist/http/http-server.js +1 -1
  24. package/dist/http/index.d.ts +2 -2
  25. package/dist/http/index.js +2 -2
  26. package/dist/index.d.ts +4 -3
  27. package/dist/index.js +4 -3
  28. package/dist/infra/di/registry.d.ts +4 -6
  29. package/dist/infra/di/registry.js +7 -10
  30. package/dist/{application → infra/serialization}/entity.d.ts +3 -1
  31. package/dist/{application → infra/serialization}/entity.js +7 -25
  32. package/dist/interface/errors/http-error-mapper.d.ts +10 -0
  33. package/dist/interface/errors/http-error-mapper.js +31 -0
  34. package/dist/interface/http/middleware-executor.d.ts +10 -0
  35. package/dist/interface/http/middleware-executor.js +33 -0
  36. package/dist/interface/http/request-mapper.d.ts +21 -0
  37. package/dist/interface/http/request-mapper.js +55 -0
  38. package/dist/interface/validation/class-validator.d.ts +6 -0
  39. package/dist/interface/validation/class-validator.js +28 -0
  40. package/dist/interface/validation/validator.d.ts +5 -0
  41. package/dist/interface/validation/validator.js +1 -0
  42. package/dist/protocols/repository.d.ts +1 -1
  43. package/package.json +5 -2
@@ -0,0 +1,6 @@
1
+ export type ValidationErrorDetail = {
2
+ path: string;
3
+ message: string;
4
+ rule: string;
5
+ };
6
+ export declare function validateWithClassValidator<T extends object>(dtoClass: new () => T, input: T): Promise<void>;
@@ -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,5 @@
1
+ export interface Validator<T = any> {
2
+ validate(input: T): void | Promise<void>;
3
+ }
4
+ export type ValidatorClass<T = any> = new () => T;
5
+ export type ValidatorLike<T = any> = Validator<T> | ValidatorClass<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { Entity } from "../application";
1
+ import { Entity } from "../domain";
2
2
  export interface RepositoryCreate<T extends Entity> {
3
3
  create(input: T): Promise<void>;
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "3.4.0",
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"