framework-do-dede 2.0.21 → 3.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 (91) hide show
  1. package/dist/application/controller.d.ts +70 -0
  2. package/dist/{decorators → application}/controller.js +45 -33
  3. package/dist/application/entity.d.ts +21 -0
  4. package/dist/application/entity.js +161 -0
  5. package/dist/application/index.d.ts +5 -0
  6. package/dist/application/index.js +4 -0
  7. package/dist/{protocols/StorageGateway.d.ts → application/services.d.ts} +2 -0
  8. package/dist/application/services.js +20 -0
  9. package/dist/application/usecase.d.ts +11 -0
  10. package/dist/application/usecase.js +24 -0
  11. package/dist/dede.d.ts +5 -4
  12. package/dist/dede.js +22 -26
  13. package/dist/{handlers → http}/controller.handler.d.ts +2 -2
  14. package/dist/http/controller.handler.js +160 -0
  15. package/dist/http/{ExpressHttpServer.d.ts → elysia-server.adapter.d.ts} +2 -2
  16. package/dist/http/{ElysiaHttpServer.js → elysia-server.adapter.js} +2 -2
  17. package/dist/http/{ElysiaHttpServer.d.ts → express-server.adapter.d.ts} +2 -2
  18. package/dist/http/express-server.adapter.js +25 -0
  19. package/dist/http/{HttpServer.d.ts → http-server.d.ts} +13 -0
  20. package/dist/http/{HttpServer.js → http-server.js} +4 -2
  21. package/dist/http/index.d.ts +2 -2
  22. package/dist/http/index.js +2 -2
  23. package/dist/infra/di/registry.d.ts +11 -0
  24. package/dist/infra/di/registry.js +32 -0
  25. package/package.json +5 -4
  26. package/dist/decorators/controller.d.ts +0 -38
  27. package/dist/decorators/di.d.ts +0 -1
  28. package/dist/decorators/di.js +0 -7
  29. package/dist/decorators/entity.d.ts +0 -12
  30. package/dist/decorators/entity.js +0 -65
  31. package/dist/decorators/index.d.ts +0 -6
  32. package/dist/decorators/index.js +0 -6
  33. package/dist/decorators/services.d.ts +0 -1
  34. package/dist/decorators/services.js +0 -27
  35. package/dist/decorators/usecase.d.ts +0 -4
  36. package/dist/decorators/usecase.js +0 -15
  37. package/dist/di/registry.d.ts +0 -17
  38. package/dist/di/registry.js +0 -51
  39. package/dist/domain/Entity.d.ts +0 -5
  40. package/dist/domain/Entity.js +0 -132
  41. package/dist/handlers/controller.handler.js +0 -215
  42. package/dist/handlers/index.d.ts +0 -3
  43. package/dist/handlers/index.js +0 -3
  44. package/dist/handlers/usecase.handler.d.ts +0 -4
  45. package/dist/handlers/usecase.handler.js +0 -43
  46. package/dist/http/ExpressHttpServer.js +0 -19
  47. package/dist/index.d.ts +0 -7
  48. package/dist/index.js +0 -6
  49. package/dist/protocols/Controller.d.ts +0 -17
  50. package/dist/protocols/Controller.js +0 -1
  51. package/dist/protocols/CreateRepository.d.ts +0 -4
  52. package/dist/protocols/CreateRepository.js +0 -1
  53. package/dist/protocols/DeleteRepository.d.ts +0 -3
  54. package/dist/protocols/DeleteRepository.js +0 -1
  55. package/dist/protocols/DeleteRepositoryBy.d.ts +0 -3
  56. package/dist/protocols/DeleteRepositoryBy.js +0 -1
  57. package/dist/protocols/ExistsBy.d.ts +0 -3
  58. package/dist/protocols/ExistsBy.js +0 -1
  59. package/dist/protocols/HttpMiddleware.d.ts +0 -3
  60. package/dist/protocols/HttpMiddleware.js +0 -1
  61. package/dist/protocols/HttpServerError.d.ts +0 -5
  62. package/dist/protocols/HttpServerError.js +0 -1
  63. package/dist/protocols/NotExistsBy.d.ts +0 -3
  64. package/dist/protocols/NotExistsBy.js +0 -1
  65. package/dist/protocols/Request.d.ts +0 -5
  66. package/dist/protocols/Request.js +0 -1
  67. package/dist/protocols/RequestMetrics.d.ts +0 -18
  68. package/dist/protocols/RequestMetrics.js +0 -1
  69. package/dist/protocols/RequestMetricsHandler.d.ts +0 -5
  70. package/dist/protocols/RequestMetricsHandler.js +0 -1
  71. package/dist/protocols/RestoreManyRepository.d.ts +0 -9
  72. package/dist/protocols/RestoreManyRepository.js +0 -1
  73. package/dist/protocols/RestoreRepository.d.ts +0 -3
  74. package/dist/protocols/RestoreRepository.js +0 -1
  75. package/dist/protocols/RestoreRepositoryBy.d.ts +0 -3
  76. package/dist/protocols/RestoreRepositoryBy.js +0 -1
  77. package/dist/protocols/StorageGateway.js +0 -1
  78. package/dist/protocols/UpdateRepository.d.ts +0 -4
  79. package/dist/protocols/UpdateRepository.js +0 -1
  80. package/dist/protocols/UseCase.d.ts +0 -3
  81. package/dist/protocols/UseCase.js +0 -1
  82. package/dist/protocols/Validation.d.ts +0 -3
  83. package/dist/protocols/Validation.js +0 -1
  84. package/dist/protocols/index.d.ts +0 -18
  85. package/dist/protocols/index.js +0 -1
  86. package/dist/utils/Log.d.ts +0 -6
  87. package/dist/utils/Log.js +0 -42
  88. /package/dist/http/{FrameworkError.d.ts → errors/framework.d.ts} +0 -0
  89. /package/dist/http/{FrameworkError.js → errors/framework.js} +0 -0
  90. /package/dist/http/{ServerError.d.ts → errors/server.d.ts} +0 -0
  91. /package/dist/http/{ServerError.js → errors/server.js} +0 -0
@@ -0,0 +1,70 @@
1
+ import 'reflect-metadata';
2
+ export interface Middleware {
3
+ execute(input: Input<any>): Promise<any>;
4
+ }
5
+ export interface TracerData {
6
+ requestedAt: Date;
7
+ elapsedTime: string;
8
+ route: string;
9
+ method: string;
10
+ middlewares: {
11
+ elapsedTime: string;
12
+ middleware: string;
13
+ error?: any;
14
+ }[];
15
+ error?: any;
16
+ headers: Record<string, string>;
17
+ }
18
+ export interface Tracer {
19
+ trace(data: TracerData): Promise<any>;
20
+ }
21
+ export interface Input<T, K = any> {
22
+ data: T;
23
+ context?: K;
24
+ }
25
+ export declare function Controller(basePath?: string): (target: any) => void;
26
+ export declare function Tracing(tracer: Tracer): (target: any, propertyKey?: string) => void;
27
+ export declare function getControllers(): any[];
28
+ export declare function flushControllers(): void;
29
+ export declare function UseMiddleware(middlewareClass: new (...args: any[]) => Middleware): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
30
+ export declare function UseMiddlewares(middlewareClasses: (new (...args: any[]) => Middleware)[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
31
+ export declare function Post(config?: {
32
+ path?: string;
33
+ statusCode?: number;
34
+ params?: string[];
35
+ query?: string[];
36
+ headers?: string[];
37
+ responseType?: 'json' | 'text' | 'html';
38
+ }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
39
+ export declare function Get(config?: {
40
+ path?: string;
41
+ statusCode?: number;
42
+ params?: string[];
43
+ query?: string[];
44
+ headers?: string[];
45
+ responseType?: 'json' | 'text' | 'html';
46
+ }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
47
+ export declare function Put(config?: {
48
+ path?: string;
49
+ statusCode?: number;
50
+ params?: string[];
51
+ query?: string[];
52
+ headers?: string[];
53
+ responseType?: 'json' | 'text' | 'html';
54
+ }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
55
+ export declare function Patch(config?: {
56
+ path?: string;
57
+ statusCode?: number;
58
+ params?: string[];
59
+ query?: string[];
60
+ headers?: string[];
61
+ responseType?: 'json' | 'text' | 'html';
62
+ }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
63
+ export declare function Delete(config?: {
64
+ path?: string;
65
+ statusCode?: number;
66
+ params?: string[];
67
+ query?: string[];
68
+ headers?: string[];
69
+ responseType?: 'json' | 'text' | 'html';
70
+ }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
@@ -1,14 +1,36 @@
1
- import { FrameworkError } from "../http/FrameworkError";
2
- import { Registry } from "../di/registry";
3
- export function Controller(basePath) {
1
+ import 'reflect-metadata';
2
+ import { FrameworkError } from "../http/errors/framework";
3
+ import { Registry } from "../infra/di/registry";
4
+ let controllers = [];
5
+ export function Controller(basePath = '/') {
4
6
  return function (target) {
7
+ if (!basePath)
8
+ throw new FrameworkError('basePath cannot be empty');
5
9
  Reflect.defineMetadata('basePath', basePath, target);
6
- if (!Registry.has('controllers'))
7
- Registry.register('controllers', []);
8
- Registry.addDependency('controllers', target);
10
+ controllers.push(target.name);
11
+ Registry.load(target.name, target);
9
12
  };
10
13
  }
11
- export function Middleware(middlewareClass) {
14
+ export function Tracing(tracer) {
15
+ return function (target, propertyKey) {
16
+ if (!propertyKey) {
17
+ Reflect.defineMetadata('tracer', tracer, target);
18
+ }
19
+ else {
20
+ Reflect.defineMetadata('tracer', tracer, target, propertyKey);
21
+ }
22
+ };
23
+ }
24
+ export function getControllers() {
25
+ return controllers.map((controller) => Registry.inject(controller));
26
+ }
27
+ export function flushControllers() {
28
+ controllers.map((controller) => {
29
+ Registry.remove(controller);
30
+ });
31
+ controllers = [];
32
+ }
33
+ export function UseMiddleware(middlewareClass) {
12
34
  return function (target, propertyKey, descriptor) {
13
35
  if (!middlewareClass.prototype.execute) {
14
36
  throw new FrameworkError('Middleware must implement execute()');
@@ -18,7 +40,7 @@ export function Middleware(middlewareClass) {
18
40
  Reflect.defineMetadata('middlewares', middlewares, target, propertyKey);
19
41
  };
20
42
  }
21
- export function Middlewares(middlewareClasses) {
43
+ export function UseMiddlewares(middlewareClasses) {
22
44
  return function (target, propertyKey, descriptor) {
23
45
  for (const middlewareClass of middlewareClasses) {
24
46
  if (!middlewareClass.prototype.execute) {
@@ -26,9 +48,7 @@ export function Middlewares(middlewareClasses) {
26
48
  }
27
49
  }
28
50
  const existingMiddlewares = Reflect.getMetadata('middlewares', target, propertyKey) || [];
29
- // Add the new middleware classes to the list
30
51
  existingMiddlewares.push(...middlewareClasses);
31
- // Update the metadata with the combined list
32
52
  Reflect.defineMetadata('middlewares', existingMiddlewares, target, propertyKey);
33
53
  };
34
54
  }
@@ -39,7 +59,9 @@ export function Post(config = {}) {
39
59
  path: config.path || '',
40
60
  params: config.params,
41
61
  query: config.query,
42
- statusCode: config.statusCode || 200
62
+ headers: config.headers,
63
+ statusCode: config.statusCode || 200,
64
+ responseType: config.responseType || 'json'
43
65
  }, target, propertyKey);
44
66
  };
45
67
  }
@@ -50,7 +72,9 @@ export function Get(config = {}) {
50
72
  path: config.path || '',
51
73
  params: config.params,
52
74
  query: config.query,
53
- statusCode: config.statusCode || 200
75
+ headers: config.headers,
76
+ statusCode: config.statusCode || 200,
77
+ responseType: config.responseType || 'json'
54
78
  }, target, propertyKey);
55
79
  };
56
80
  }
@@ -61,7 +85,9 @@ export function Put(config = {}) {
61
85
  path: config.path || '',
62
86
  params: config.params,
63
87
  query: config.query,
64
- statusCode: config.statusCode || 200
88
+ headers: config.headers,
89
+ statusCode: config.statusCode || 200,
90
+ responseType: config.responseType || 'json'
65
91
  }, target, propertyKey);
66
92
  };
67
93
  }
@@ -72,7 +98,9 @@ export function Patch(config = {}) {
72
98
  path: config.path || '',
73
99
  params: config.params,
74
100
  query: config.query,
75
- statusCode: config.statusCode || 200
101
+ headers: config.headers,
102
+ statusCode: config.statusCode || 200,
103
+ responseType: config.responseType || 'json'
76
104
  }, target, propertyKey);
77
105
  };
78
106
  }
@@ -83,25 +111,9 @@ export function Delete(config = {}) {
83
111
  path: config.path || '',
84
112
  params: config.params,
85
113
  query: config.query,
86
- statusCode: config.statusCode || 200
114
+ headers: config.headers,
115
+ statusCode: config.statusCode || 200,
116
+ responseType: config.responseType || 'json'
87
117
  }, target, propertyKey);
88
118
  };
89
119
  }
90
- export function Validator(validationClass) {
91
- return function (target, propertyKey, descriptor) {
92
- if (typeof validationClass.prototype.validate !== 'function') {
93
- throw new FrameworkError('the concrete class does not implement Validation class".');
94
- }
95
- Reflect.defineMetadata('validation', new validationClass(), target, propertyKey);
96
- };
97
- }
98
- export function Metrics(...handlers) {
99
- return (target, propertyKey, descriptor) => {
100
- Reflect.defineMetadata('metricsHandlers', handlers, target, propertyKey);
101
- };
102
- }
103
- export function OffConsoleLog() {
104
- return function (target, propertyKey, descriptor) {
105
- Reflect.defineMetadata('offConsoleLog', true, target, propertyKey);
106
- };
107
- }
@@ -0,0 +1,21 @@
1
+ export interface EntityIdentifier<T> {
2
+ getValue(): T;
3
+ }
4
+ export declare abstract class Entity {
5
+ [x: string]: any;
6
+ toEntity(): Record<string, any>;
7
+ toAsyncEntity(): Promise<Record<string, any>>;
8
+ toData({ serialize }?: {
9
+ serialize?: boolean;
10
+ }): Record<string, any>;
11
+ toAsyncData({ serialize }?: {
12
+ serialize?: boolean;
13
+ }): Promise<Record<string, any>>;
14
+ protected generateGetters(): void;
15
+ constructor();
16
+ }
17
+ export declare function Restrict(): (target: any, propertyKey: string) => void;
18
+ export declare function VirtualProperty(propertyName: string): (target: any, methodName: string) => void;
19
+ export declare function Serialize(callback: (value: any) => any): PropertyDecorator;
20
+ export declare function GetterPrefix(prefix: string): (target: any, propertyKey: string) => void;
21
+ export declare function Id(): (target: any, propertyKey: string) => void;
@@ -0,0 +1,161 @@
1
+ export class Entity {
2
+ toEntity() {
3
+ // @ts-ignore
4
+ const propertiesConfigs = this.constructor.propertiesConfigs;
5
+ const result = {};
6
+ for (const [propName] of Object.entries(this)) {
7
+ let value = this[propName];
8
+ if (typeof value === 'function')
9
+ continue;
10
+ if (propertiesConfigs[propName]?.serialize && value) {
11
+ value = propertiesConfigs[propName].serialize(value);
12
+ }
13
+ if (!value)
14
+ value = null;
15
+ result[propName] = value;
16
+ }
17
+ return result;
18
+ }
19
+ async toAsyncEntity() {
20
+ // @ts-ignore
21
+ const propertiesConfigs = this.constructor.propertiesConfigs;
22
+ const result = {};
23
+ for (const [propName] of Object.entries(this)) {
24
+ let value = this[propName];
25
+ if (typeof value === 'function')
26
+ continue;
27
+ if (propertiesConfigs[propName]?.serialize && value) {
28
+ value = await propertiesConfigs[propName].serialize(value);
29
+ }
30
+ if (!value)
31
+ value = null;
32
+ result[propName] = value;
33
+ }
34
+ return result;
35
+ }
36
+ toData({ serialize = false } = {}) {
37
+ // @ts-ignore
38
+ const propertiesConfigs = this.constructor.propertiesConfigs;
39
+ // @ts-ignore
40
+ const virtualProperties = this.constructor.virtualProperties;
41
+ const result = {};
42
+ for (const [propName] of Object.entries(this)) {
43
+ if (propertiesConfigs[propName]?.restrict)
44
+ continue;
45
+ if (typeof this[propName] === 'function')
46
+ continue;
47
+ let value = this[propName];
48
+ if (serialize && propertiesConfigs[propName]?.serialize && value) {
49
+ value = propertiesConfigs[propName].serialize(value);
50
+ }
51
+ result[propName] = value;
52
+ }
53
+ if (virtualProperties) {
54
+ for (const [methodName, propName] of Object.entries(virtualProperties)) {
55
+ if (this.__proto__[methodName]) {
56
+ result[propName] = this[methodName]();
57
+ }
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ async toAsyncData({ serialize = false } = {}) {
63
+ // @ts-ignore
64
+ const propertiesConfigs = this.constructor.propertiesConfigs;
65
+ // @ts-ignore
66
+ const virtualProperties = this.constructor.virtualProperties;
67
+ const result = {};
68
+ for (const [propName] of Object.entries(this)) {
69
+ if (typeof this[propName] === 'function')
70
+ continue;
71
+ if (propertiesConfigs[propName]?.restrict)
72
+ continue;
73
+ let value = this[propName];
74
+ if (serialize && propertiesConfigs[propName]?.serialize && value) {
75
+ value = await propertiesConfigs[propName].serialize(value);
76
+ }
77
+ result[propName] = value;
78
+ }
79
+ if (virtualProperties) {
80
+ for (const [methodName, propName] of Object.entries(virtualProperties)) {
81
+ if (this.__proto__[methodName]) {
82
+ result[propName] = await this[methodName]();
83
+ }
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+ generateGetters() {
89
+ // @ts-ignore
90
+ for (const property of Object.keys(this)) {
91
+ if (typeof property === 'function')
92
+ continue;
93
+ // @ts-ignore
94
+ if (this.constructor.strategyId === property) {
95
+ this[property] = this[property].getValue();
96
+ this[`get${property[0].toUpperCase()}${property.slice(1)}`] = () => this[property];
97
+ continue;
98
+ }
99
+ if (!this[property]) {
100
+ // @ts-ignore
101
+ const prefixName = this.constructor.propertiesConfigs[property].prefix;
102
+ const getterName = `${prefixName}${property[0].toUpperCase()}${property.slice(1)}`;
103
+ if (this[getterName])
104
+ continue;
105
+ this[getterName] = () => this[property];
106
+ }
107
+ else {
108
+ // @ts-ignore
109
+ const prefixName = this.constructor.propertiesConfigs[property]?.prefix || (typeof this[property] === 'boolean' ? 'is' : 'get');
110
+ const getterName = `${prefixName}${property[0].toUpperCase()}${property.slice(1)}`;
111
+ if (this[getterName])
112
+ continue;
113
+ this[getterName] = () => this[property];
114
+ }
115
+ }
116
+ }
117
+ constructor() {
118
+ // @ts-ignore
119
+ if (!this.constructor?.strategyId) {
120
+ throw new Error('StrategyId must to be implement.');
121
+ }
122
+ }
123
+ }
124
+ export function Restrict() {
125
+ return function (target, propertyKey) {
126
+ loadPropertiesConfig(target, propertyKey);
127
+ target.constructor.propertiesConfigs[propertyKey].restrict = true;
128
+ };
129
+ }
130
+ export function VirtualProperty(propertyName) {
131
+ return function (target, methodName) {
132
+ const cls = target.constructor;
133
+ cls.virtualProperties = cls.virtualProperties || {};
134
+ cls.virtualProperties[methodName] = propertyName;
135
+ };
136
+ }
137
+ export function Serialize(callback) {
138
+ return function (target, propertyKey) {
139
+ loadPropertiesConfig(target, propertyKey);
140
+ target.constructor.propertiesConfigs[propertyKey].serialize = callback;
141
+ };
142
+ }
143
+ export function GetterPrefix(prefix) {
144
+ return function (target, propertyKey) {
145
+ loadPropertiesConfig(target, propertyKey);
146
+ target.constructor.propertiesConfigs[propertyKey].prefix = prefix;
147
+ };
148
+ }
149
+ export function Id() {
150
+ return function (target, propertyKey) {
151
+ target.constructor.strategyId = propertyKey;
152
+ };
153
+ }
154
+ const loadPropertiesConfig = (target, propertyKey) => {
155
+ if (!target.constructor.propertiesConfigs) {
156
+ target.constructor.propertiesConfigs = {};
157
+ }
158
+ if (!target.constructor.propertiesConfigs[propertyKey]) {
159
+ target.constructor.propertiesConfigs[propertyKey] = {};
160
+ }
161
+ };
@@ -0,0 +1,5 @@
1
+ import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, type Middleware, type Input, type Tracer, type TracerData } from './controller';
2
+ import { DecorateUseCase, type UseCase } from './usecase';
3
+ import { Storage } from './services';
4
+ export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, DecorateUseCase, Storage };
5
+ export type { Middleware, Input, UseCase, Tracer, TracerData };
@@ -0,0 +1,4 @@
1
+ import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing } from './controller';
2
+ import { DecorateUseCase } from './usecase';
3
+ import { Storage } from './services';
4
+ export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, DecorateUseCase, Storage };
@@ -1,5 +1,7 @@
1
+ import 'reflect-metadata';
1
2
  export interface StorageGateway {
2
3
  save(file: File, path: string): Promise<void>;
3
4
  get(key: string): Promise<string>;
4
5
  delete(key: string): Promise<boolean>;
5
6
  }
7
+ export declare function Storage(gatewayName: string): (target: any, propertyKey: string) => void;
@@ -0,0 +1,20 @@
1
+ import { Registry } from "../infra/di/registry";
2
+ import 'reflect-metadata';
3
+ export function Storage(gatewayName) {
4
+ return function (target, propertyKey) {
5
+ let dependency;
6
+ Object.defineProperty(target, propertyKey, {
7
+ get: function () {
8
+ if (!dependency) {
9
+ dependency = Registry.inject(gatewayName);
10
+ }
11
+ if (!dependency.save || !dependency.get || !dependency.delete) {
12
+ throw new Error(`${gatewayName} is not a valid StorageGateway`);
13
+ }
14
+ return dependency;
15
+ },
16
+ enumerable: true,
17
+ configurable: true
18
+ });
19
+ };
20
+ }
@@ -0,0 +1,11 @@
1
+ import { Input } from "./controller";
2
+ export declare const USE_CASE_DECORATORS: unique symbol;
3
+ export declare abstract class UseCase<UseCaseInput, UseCaseOutput, UseCaseContext = any> {
4
+ private readonly data;
5
+ private readonly context?;
6
+ constructor(input: Input<UseCaseInput>);
7
+ protected getData(): UseCaseInput;
8
+ protected getContext(): UseCaseContext;
9
+ abstract execute(): Promise<UseCaseOutput>;
10
+ }
11
+ export declare function DecorateUseCase(useCases: UseCase<any, any> | (new (...args: any[]) => UseCase<any, any>) | Array<UseCase<any, any> | (new (...args: any[]) => UseCase<any, any>)>): ClassDecorator;
@@ -0,0 +1,24 @@
1
+ export const USE_CASE_DECORATORS = Symbol('USE_CASE_DECORATORS');
2
+ export class UseCase {
3
+ data;
4
+ context;
5
+ constructor(input) {
6
+ this.data = input.data;
7
+ if (input.context) {
8
+ this.context = input.context;
9
+ }
10
+ }
11
+ getData() {
12
+ return this.data;
13
+ }
14
+ getContext() {
15
+ return this?.context;
16
+ }
17
+ }
18
+ export function DecorateUseCase(useCases) {
19
+ return function (target) {
20
+ const decorators = Array.isArray(useCases) ? useCases : [useCases];
21
+ Reflect.defineMetadata(USE_CASE_DECORATORS, decorators, target);
22
+ return target;
23
+ };
24
+ }
package/dist/dede.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export type Register = {
2
2
  name: string;
3
3
  classLoader: any;
4
- autoLoad?: boolean;
5
4
  };
6
5
  export type Options = {
7
6
  framework: {
@@ -13,9 +12,11 @@ export type Options = {
13
12
  defaultServerError?: string;
14
13
  };
15
14
  export declare class Dede {
16
- private static httpServer;
15
+ private readonly framework;
16
+ private readonly defaultServerError?;
17
+ private readonly httpServer;
18
+ private constructor();
17
19
  static start({ framework, registries, defaultServerError }: Options): Promise<Dede>;
18
- static stop(): Promise<void>;
19
- private static clearControllers;
20
+ stop(): Promise<void>;
20
21
  private static loadRegistries;
21
22
  }
package/dist/dede.js CHANGED
@@ -1,39 +1,35 @@
1
- import { Registry } from "./di/registry";
2
- import { ControllerHandler } from "./handlers";
3
- import { ElysiaHttpServer } from "./http/ElysiaHttpServer";
4
- import { ExpressHttpServer } from "./http/ExpressHttpServer";
1
+ import ControllerHandler from "./http/controller.handler";
2
+ import { ElysiaServerAdapter } from "./http/elysia-server.adapter";
3
+ import { ExpressServerAdapter } from "./http/express-server.adapter";
4
+ import { Registry } from "./infra/di/registry";
5
5
  export class Dede {
6
- static httpServer;
7
- static async start({ framework, registries, defaultServerError }) {
8
- await this.loadRegistries(registries);
6
+ framework;
7
+ defaultServerError;
8
+ httpServer;
9
+ constructor(framework, defaultServerError) {
10
+ this.framework = framework;
11
+ this.defaultServerError = defaultServerError;
9
12
  if (framework.use === 'elysia') {
10
- Dede.httpServer = new ElysiaHttpServer(framework.middlewares || []);
13
+ this.httpServer = new ElysiaServerAdapter(framework.middlewares || []);
11
14
  }
12
15
  if (framework.use === 'express') {
13
- Dede.httpServer = new ExpressHttpServer(framework.middlewares || []);
16
+ this.httpServer = new ExpressServerAdapter(framework.middlewares || []);
14
17
  }
15
18
  if (defaultServerError)
16
- Dede.httpServer.setDefaultMessageError(defaultServerError);
17
- if (!Registry.has('controllers')) {
18
- throw new Error("No controllers registered");
19
- }
20
- new ControllerHandler(Dede.httpServer, framework.port || 80);
21
- this.clearControllers();
22
- return Dede;
19
+ this.httpServer.setDefaultMessageError(defaultServerError);
20
+ new ControllerHandler(this.httpServer, framework.port || 80);
23
21
  }
24
- static async stop() {
25
- await Dede.httpServer.close();
22
+ static async start({ framework, registries, defaultServerError }) {
23
+ await this.loadRegistries(registries);
24
+ return new Dede(framework, defaultServerError);
26
25
  }
27
- static clearControllers() {
28
- Registry.clear('controllers');
26
+ async stop() {
27
+ await this.httpServer.close();
29
28
  }
30
29
  static async loadRegistries(registries) {
31
- registries.forEach(({ classLoader, name, autoLoad = true }) => {
32
- if (autoLoad)
33
- Registry.register(name, Registry.classLoader(classLoader));
34
- else
35
- Registry.register(name, classLoader);
30
+ registries.forEach(({ classLoader, name }) => {
31
+ Registry.load(name, classLoader);
36
32
  });
37
- Registry.loaded();
33
+ return new Promise(resolve => setTimeout(resolve, 500));
38
34
  }
39
35
  }
@@ -1,7 +1,7 @@
1
- import HttpServer from "../http/HttpServer";
1
+ import HttpServer from "../http/http-server";
2
2
  export default class ControllerHandler {
3
3
  constructor(httpServer: HttpServer, port: number);
4
- private transformErrorOnJSON;
4
+ private executeMiddlewares;
5
5
  private registryControllers;
6
6
  private filter;
7
7
  private extractError;