framework-do-dede 2.0.20 → 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.
- package/dist/application/controller.d.ts +70 -0
- package/dist/{decorators → application}/controller.js +45 -33
- package/dist/application/entity.d.ts +21 -0
- package/dist/application/entity.js +161 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.js +4 -0
- package/dist/{protocols/StorageGateway.d.ts → application/services.d.ts} +2 -0
- package/dist/application/services.js +20 -0
- package/dist/application/usecase.d.ts +11 -0
- package/dist/application/usecase.js +24 -0
- package/dist/dede.d.ts +5 -4
- package/dist/dede.js +22 -26
- package/dist/{handlers → http}/controller.handler.d.ts +2 -2
- package/dist/http/controller.handler.js +160 -0
- package/dist/http/{ExpressHttpServer.d.ts → elysia-server.adapter.d.ts} +2 -2
- package/dist/http/{ElysiaHttpServer.js → elysia-server.adapter.js} +2 -2
- package/dist/http/{ElysiaHttpServer.d.ts → express-server.adapter.d.ts} +2 -2
- package/dist/http/express-server.adapter.js +25 -0
- package/dist/http/{HttpServer.d.ts → http-server.d.ts} +13 -0
- package/dist/http/{HttpServer.js → http-server.js} +4 -2
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +2 -2
- package/dist/infra/di/registry.d.ts +11 -0
- package/dist/infra/di/registry.js +32 -0
- package/package.json +5 -4
- package/dist/decorators/controller.d.ts +0 -38
- package/dist/decorators/di.d.ts +0 -1
- package/dist/decorators/di.js +0 -7
- package/dist/decorators/entity.d.ts +0 -12
- package/dist/decorators/entity.js +0 -65
- package/dist/decorators/index.d.ts +0 -6
- package/dist/decorators/index.js +0 -6
- package/dist/decorators/services.d.ts +0 -7
- package/dist/decorators/services.js +0 -41
- package/dist/decorators/usecase.d.ts +0 -4
- package/dist/decorators/usecase.js +0 -15
- package/dist/di/registry.d.ts +0 -17
- package/dist/di/registry.js +0 -51
- package/dist/domain/Entity.d.ts +0 -5
- package/dist/domain/Entity.js +0 -132
- package/dist/handlers/controller.handler.js +0 -215
- package/dist/handlers/index.d.ts +0 -3
- package/dist/handlers/index.js +0 -3
- package/dist/handlers/usecase.handler.d.ts +0 -4
- package/dist/handlers/usecase.handler.js +0 -43
- package/dist/http/ExpressHttpServer.js +0 -19
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -6
- package/dist/protocols/Controller.d.ts +0 -17
- package/dist/protocols/Controller.js +0 -1
- package/dist/protocols/CreateRepository.d.ts +0 -4
- package/dist/protocols/CreateRepository.js +0 -1
- package/dist/protocols/DeleteRepository.d.ts +0 -3
- package/dist/protocols/DeleteRepository.js +0 -1
- package/dist/protocols/DeleteRepositoryBy.d.ts +0 -3
- package/dist/protocols/DeleteRepositoryBy.js +0 -1
- package/dist/protocols/ExistsBy.d.ts +0 -3
- package/dist/protocols/ExistsBy.js +0 -1
- package/dist/protocols/HttpMiddleware.d.ts +0 -3
- package/dist/protocols/HttpMiddleware.js +0 -1
- package/dist/protocols/HttpServerError.d.ts +0 -5
- package/dist/protocols/HttpServerError.js +0 -1
- package/dist/protocols/NotExistsBy.d.ts +0 -3
- package/dist/protocols/NotExistsBy.js +0 -1
- package/dist/protocols/Request.d.ts +0 -5
- package/dist/protocols/Request.js +0 -1
- package/dist/protocols/RequestMetrics.d.ts +0 -18
- package/dist/protocols/RequestMetrics.js +0 -1
- package/dist/protocols/RequestMetricsHandler.d.ts +0 -5
- package/dist/protocols/RequestMetricsHandler.js +0 -1
- package/dist/protocols/RestoreManyRepository.d.ts +0 -9
- package/dist/protocols/RestoreManyRepository.js +0 -1
- package/dist/protocols/RestoreRepository.d.ts +0 -3
- package/dist/protocols/RestoreRepository.js +0 -1
- package/dist/protocols/RestoreRepositoryBy.d.ts +0 -3
- package/dist/protocols/RestoreRepositoryBy.js +0 -1
- package/dist/protocols/StorageGateway.js +0 -1
- package/dist/protocols/UpdateRepository.d.ts +0 -4
- package/dist/protocols/UpdateRepository.js +0 -1
- package/dist/protocols/UseCase.d.ts +0 -3
- package/dist/protocols/UseCase.js +0 -1
- package/dist/protocols/Validation.d.ts +0 -3
- package/dist/protocols/Validation.js +0 -1
- package/dist/protocols/index.d.ts +0 -18
- package/dist/protocols/index.js +0 -1
- package/dist/utils/Log.d.ts +0 -6
- package/dist/utils/Log.js +0 -42
- /package/dist/http/{FrameworkError.d.ts → errors/framework.d.ts} +0 -0
- /package/dist/http/{FrameworkError.js → errors/framework.js} +0 -0
- /package/dist/http/{ServerError.d.ts → errors/server.d.ts} +0 -0
- /package/dist/http/{ServerError.js → errors/server.js} +0 -0
package/dist/domain/Entity.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
export class Entity {
|
|
2
|
-
async get() {
|
|
3
|
-
const ctor = this.constructor;
|
|
4
|
-
const restrictedProps = ctor._restrictedProperties || new Set();
|
|
5
|
-
const virtualProperties = ctor._virtualProperties || new Map();
|
|
6
|
-
const exposeConfigs = ctor._exposeConfigs || new Map();
|
|
7
|
-
const attributes = {};
|
|
8
|
-
for (const [key, value] of Object.entries(this)) {
|
|
9
|
-
if (!restrictedProps.has(key)) {
|
|
10
|
-
attributes[key] = value;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
for await (const [propName, methodName] of virtualProperties) {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
if (!restrictedProps.has(propName) && typeof this[methodName] === "function") {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
attributes[propName] = await this[methodName]();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
for (const [propertyKey, configs] of exposeConfigs) {
|
|
21
|
-
if (restrictedProps.has(propertyKey))
|
|
22
|
-
continue;
|
|
23
|
-
const rawValue = this[propertyKey];
|
|
24
|
-
for (const config of configs) {
|
|
25
|
-
try {
|
|
26
|
-
let value = config.deserialize ? await config.deserialize(rawValue) : rawValue;
|
|
27
|
-
if (!value)
|
|
28
|
-
continue;
|
|
29
|
-
if (config.mapping) {
|
|
30
|
-
if (typeof config.mapping === "string") {
|
|
31
|
-
attributes[config.mapping] = value;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
Object.entries(config.mapping).forEach(([srcKey, destKey]) => {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
attributes[destKey] = value[srcKey];
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
if (typeof value === "object" && value !== null) {
|
|
42
|
-
Object.assign(attributes, value);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
attributes[propertyKey] = value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
console.error(`Error in @Expose for ${String(propertyKey)}:`, error);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return attributes;
|
|
55
|
-
}
|
|
56
|
-
async toEntity() {
|
|
57
|
-
const ctor = this.constructor;
|
|
58
|
-
const dbColumnConfigs = ctor._dbColumnConfigs || new Map();
|
|
59
|
-
const dbRecord = {};
|
|
60
|
-
for (const [key, value] of Object.entries(this)) {
|
|
61
|
-
dbRecord[key] = value;
|
|
62
|
-
}
|
|
63
|
-
for (const [propertyKey, configs] of dbColumnConfigs) {
|
|
64
|
-
const rawValue = this[propertyKey];
|
|
65
|
-
for (const config of configs) {
|
|
66
|
-
try {
|
|
67
|
-
let serializedValue = config.serialize ? await config.serialize(rawValue, dbRecord) : rawValue;
|
|
68
|
-
if (!serializedValue)
|
|
69
|
-
continue;
|
|
70
|
-
if (config.column) {
|
|
71
|
-
if (typeof config.column === "string") {
|
|
72
|
-
dbRecord[config.column] = serializedValue;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
for (const [srcKey, destKey] of Object.entries(config.column)) {
|
|
76
|
-
dbRecord[destKey] = serializedValue[srcKey];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
dbRecord[propertyKey] = serializedValue;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
console.error(`Error in @DbColumn for ${String(propertyKey)}:`, error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return dbRecord;
|
|
90
|
-
}
|
|
91
|
-
async toMap(properties) {
|
|
92
|
-
const ctor = this.constructor;
|
|
93
|
-
const exposeConfigs = ctor._exposeConfigs || new Map();
|
|
94
|
-
const attributes = {};
|
|
95
|
-
for (const property of properties) {
|
|
96
|
-
const rawValue = this[property];
|
|
97
|
-
if (!rawValue)
|
|
98
|
-
continue;
|
|
99
|
-
attributes[property] = rawValue;
|
|
100
|
-
if (exposeConfigs.has(property)) {
|
|
101
|
-
const rawValue = this[property];
|
|
102
|
-
const config = exposeConfigs.get(property);
|
|
103
|
-
try {
|
|
104
|
-
let value = config.deserialize ? await config.deserialize(rawValue) : rawValue;
|
|
105
|
-
if (config.mapping) {
|
|
106
|
-
if (typeof config.mapping === "string") {
|
|
107
|
-
attributes[config.mapping] = value;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
Object.entries(config.mapping).forEach(([srcKey, destKey]) => {
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
attributes[destKey] = value[srcKey];
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
if (typeof value === "object" && value !== null) {
|
|
118
|
-
Object.assign(attributes, value);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
attributes[property] = value;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
console.error(`Error in @Expose for ${String(property)}:`, error);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return attributes;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Registry } from "../di/registry";
|
|
2
|
-
import { InternalServerError, ServerError } from "../http";
|
|
3
|
-
import { Log } from "../utils/Log";
|
|
4
|
-
export default class ControllerHandler {
|
|
5
|
-
constructor(httpServer, port) {
|
|
6
|
-
for (const { instance, instanceMethod, middlewares, method, route, statusCode, params, query, validation, offLogs, metricsHandlers } of this.registryControllers()) {
|
|
7
|
-
httpServer.register({
|
|
8
|
-
method,
|
|
9
|
-
route,
|
|
10
|
-
statusCode,
|
|
11
|
-
params,
|
|
12
|
-
query,
|
|
13
|
-
}, async (input) => {
|
|
14
|
-
let wasError = false;
|
|
15
|
-
const startTime = performance.now();
|
|
16
|
-
const requestMetrics = {
|
|
17
|
-
date: new Date(),
|
|
18
|
-
elapsedTime: '0 ms',
|
|
19
|
-
method,
|
|
20
|
-
route,
|
|
21
|
-
agent: input.headers['user-agent'],
|
|
22
|
-
ip: input.headers['ip'],
|
|
23
|
-
contentLength: input.headers['content-length'],
|
|
24
|
-
handler: {
|
|
25
|
-
instance: instance.constructor.name,
|
|
26
|
-
method: instanceMethod
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
const logger = {
|
|
30
|
-
date: requestMetrics.date,
|
|
31
|
-
method: requestMetrics.method.toLocaleUpperCase(),
|
|
32
|
-
route: requestMetrics.route,
|
|
33
|
-
handler: requestMetrics.handler
|
|
34
|
-
};
|
|
35
|
-
if (!offLogs) {
|
|
36
|
-
Log.info(`🏳️ [LOG] Init: "${logger.handler.instance}.${logger.handler.method}"`);
|
|
37
|
-
Log.info(JSON.stringify(logger));
|
|
38
|
-
}
|
|
39
|
-
const filterParams = this.filter(input.params, params);
|
|
40
|
-
const filterQueryParams = this.filter(input.query, query);
|
|
41
|
-
let mergedParams = { ...filterParams, ...filterQueryParams, ...(input.body || {}) };
|
|
42
|
-
const request = { headers: input.headers, data: mergedParams, middlewareData: {} };
|
|
43
|
-
try {
|
|
44
|
-
if (validation) {
|
|
45
|
-
if (!offLogs)
|
|
46
|
-
Log.info(`⏳ [LOG] Executing validations`);
|
|
47
|
-
mergedParams = validation.validate({ ...filterParams, ...filterQueryParams, ...(input.body || {}) });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
const capturedError = this.extractError(error, httpServer);
|
|
52
|
-
requestMetrics.error = capturedError;
|
|
53
|
-
input.setStatus(capturedError.statusCode);
|
|
54
|
-
const endTime = performance.now();
|
|
55
|
-
if (!offLogs) {
|
|
56
|
-
Log.error(`❌ [LOG] Error validations: "${logger.handler.instance}.${logger.handler.method}"` + ` - in: ${(endTime - startTime).toFixed(2)} ms`);
|
|
57
|
-
Log.error(JSON.stringify(this.transformErrorOnJSON(error)));
|
|
58
|
-
}
|
|
59
|
-
wasError = true;
|
|
60
|
-
return {
|
|
61
|
-
message: capturedError.message,
|
|
62
|
-
statusCode: capturedError.statusCode
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
if (wasError) {
|
|
67
|
-
const endTime = performance.now();
|
|
68
|
-
requestMetrics.elapsedTime = `${(endTime - startTime).toFixed(2)} ms`;
|
|
69
|
-
if (metricsHandlers?.length) {
|
|
70
|
-
await Promise.all(metricsHandlers.map((handler) => handler.handle(requestMetrics, request)));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
let middlewareData = {};
|
|
75
|
-
if (middlewares) {
|
|
76
|
-
if (!offLogs)
|
|
77
|
-
Log.info(`⏳ [LOG] Executing middlewares`);
|
|
78
|
-
let count = 0;
|
|
79
|
-
for (const middleware of middlewares) {
|
|
80
|
-
try {
|
|
81
|
-
const endTime = performance.now();
|
|
82
|
-
const middlewareResult = await middleware.execute({ headers: input.headers, ...mergedParams });
|
|
83
|
-
Log.info(` ${++count} - middleware : ${(endTime - startTime).toFixed(2)} ms`);
|
|
84
|
-
middlewareData = Object.assign(middlewareData, middlewareResult);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
wasError = true;
|
|
88
|
-
const capturedError = this.extractError(error, httpServer);
|
|
89
|
-
requestMetrics.error = capturedError;
|
|
90
|
-
input.setStatus(capturedError.statusCode);
|
|
91
|
-
const endTime = performance.now();
|
|
92
|
-
if (!offLogs) {
|
|
93
|
-
Log.error(`❌ [LOG] Error middleware: "${logger.handler.instance}.${logger.handler.method}"` + ` - in: ${(endTime - startTime).toFixed(2)} ms`);
|
|
94
|
-
Log.error(JSON.stringify(this.transformErrorOnJSON(error)));
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
message: capturedError.message,
|
|
98
|
-
statusCode: capturedError.statusCode
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
if (wasError) {
|
|
103
|
-
const endTime = performance.now();
|
|
104
|
-
requestMetrics.elapsedTime = `${(endTime - startTime).toFixed(2)} ms`;
|
|
105
|
-
if (metricsHandlers?.length) {
|
|
106
|
-
await Promise.all(metricsHandlers.map((handler) => handler.handle(requestMetrics, request)));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (middlewareData)
|
|
113
|
-
request.middlewareData = middlewareData;
|
|
114
|
-
try {
|
|
115
|
-
const response = await instance[instanceMethod]({ input: mergedParams, request });
|
|
116
|
-
if (!offLogs) {
|
|
117
|
-
const endTime = performance.now();
|
|
118
|
-
Log.success(`✅ [LOG] Finish: "${logger.handler.instance}.${logger.handler.method}" - in: ${(endTime - startTime).toFixed(2)} ms`);
|
|
119
|
-
}
|
|
120
|
-
return response;
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
const capturedError = this.extractError(error, httpServer);
|
|
124
|
-
requestMetrics.error = capturedError;
|
|
125
|
-
input.setStatus(capturedError.statusCode);
|
|
126
|
-
if (!offLogs) {
|
|
127
|
-
const endTime = performance.now();
|
|
128
|
-
Log.error(`❌ [LOG] Error: "${logger.handler.instance}.${logger.handler.method}"` + ` - in: ${(endTime - startTime).toFixed(2)} ms`);
|
|
129
|
-
Log.error(JSON.stringify(this.transformErrorOnJSON(error)));
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
message: capturedError.message,
|
|
133
|
-
statusCode: capturedError.statusCode
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
const endTime = performance.now();
|
|
138
|
-
requestMetrics.elapsedTime = `${(endTime - startTime).toFixed(2)} ms`;
|
|
139
|
-
if (metricsHandlers?.length) {
|
|
140
|
-
await Promise.all(metricsHandlers.map((handler) => handler.handle(requestMetrics, request)));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
httpServer.listen(port);
|
|
146
|
-
}
|
|
147
|
-
transformErrorOnJSON(error) {
|
|
148
|
-
return error instanceof ServerError ? error : { message: error.message, stack: error.stack };
|
|
149
|
-
}
|
|
150
|
-
registryControllers() {
|
|
151
|
-
const registryControllers = Registry.resolve('controllers');
|
|
152
|
-
const controllers = [];
|
|
153
|
-
for (const controller of registryControllers) {
|
|
154
|
-
const basePath = Reflect.getMetadata('basePath', controller);
|
|
155
|
-
const injections = Reflect.getMetadata('injections', controller) || [];
|
|
156
|
-
const args = injections.map((token) => Registry.resolve(token));
|
|
157
|
-
const instance = new controller(...args);
|
|
158
|
-
const methodNames = Object.getOwnPropertyNames(controller.prototype).filter(method => method !== 'constructor');
|
|
159
|
-
for (const methodName of methodNames) {
|
|
160
|
-
const validation = Reflect.getMetadata('validation', controller.prototype, methodName);
|
|
161
|
-
const routeConfig = Reflect.getMetadata('route', controller.prototype, methodName);
|
|
162
|
-
const middlewares = Reflect.getMetadata('middlewares', controller.prototype, methodName);
|
|
163
|
-
const metricsHandlers = Reflect.getMetadata('metricsHandlers', controller.prototype, methodName);
|
|
164
|
-
const offConsoleLog = Reflect.getMetadata('offConsoleLog', controller.prototype, methodName) || false;
|
|
165
|
-
controllers.push({
|
|
166
|
-
method: routeConfig.method,
|
|
167
|
-
route: basePath + routeConfig.path,
|
|
168
|
-
params: routeConfig.params,
|
|
169
|
-
query: routeConfig.query,
|
|
170
|
-
statusCode: routeConfig.statusCode,
|
|
171
|
-
instance,
|
|
172
|
-
instanceMethod: methodName,
|
|
173
|
-
middlewares: middlewares ? middlewares.map(middleware => Registry.classLoader(middleware)) : [],
|
|
174
|
-
validation,
|
|
175
|
-
metricsHandlers: metricsHandlers ? metricsHandlers.map(metricsHandler => Registry.classLoader(metricsHandler)) : [],
|
|
176
|
-
offLogs: offConsoleLog
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return controllers;
|
|
181
|
-
}
|
|
182
|
-
filter(params, filterParams) {
|
|
183
|
-
const filter = {};
|
|
184
|
-
for (const paramName of filterParams || []) {
|
|
185
|
-
const [paramNameFiltered, type] = paramName.split('|');
|
|
186
|
-
let value = params[paramName] || params[paramNameFiltered];
|
|
187
|
-
if (!value)
|
|
188
|
-
continue;
|
|
189
|
-
if (type === 'boolean')
|
|
190
|
-
value = value === 'true';
|
|
191
|
-
if (type === 'integer') {
|
|
192
|
-
value = value.replace(/[^0-9]/g, '');
|
|
193
|
-
value = value ? parseInt(value) : 0;
|
|
194
|
-
}
|
|
195
|
-
if (type === 'string')
|
|
196
|
-
value = value.toString();
|
|
197
|
-
filter[paramNameFiltered] = value;
|
|
198
|
-
}
|
|
199
|
-
return filter;
|
|
200
|
-
}
|
|
201
|
-
extractError(error, httpServer) {
|
|
202
|
-
if (error instanceof ServerError) {
|
|
203
|
-
return {
|
|
204
|
-
message: error.message,
|
|
205
|
-
statusCode: error.getStatusCode()
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
error = new InternalServerError(error.message, httpServer.getDefaultMessageError());
|
|
209
|
-
return {
|
|
210
|
-
message: error.message,
|
|
211
|
-
statusCode: error.getStatusCode(),
|
|
212
|
-
unexpectedError: error instanceof InternalServerError ? error.getUnexpectedError() : undefined,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
package/dist/handlers/index.d.ts
DELETED
package/dist/handlers/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { USE_CASE_DECORATORS } from "../decorators/usecase";
|
|
2
|
-
import { Registry } from "../di/registry";
|
|
3
|
-
export default class UseCaseHandler {
|
|
4
|
-
static load(useCaseClass, request) {
|
|
5
|
-
const useCaseDecorators = Reflect.getMetadata(USE_CASE_DECORATORS, useCaseClass) || [];
|
|
6
|
-
const useCaseDecoratorsInstances = [];
|
|
7
|
-
// Processa decorators
|
|
8
|
-
for (const useCaseDecorator of useCaseDecorators) {
|
|
9
|
-
let instance;
|
|
10
|
-
if (typeof useCaseDecorator === 'function') {
|
|
11
|
-
// Cria instância via DI
|
|
12
|
-
instance = Registry.classLoader(useCaseDecorator);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
// Usa instância existente
|
|
16
|
-
instance = useCaseDecorator;
|
|
17
|
-
}
|
|
18
|
-
// Injeta contexto na instância (seja nova ou existente)
|
|
19
|
-
injectContext(instance, request);
|
|
20
|
-
useCaseDecoratorsInstances.push(instance);
|
|
21
|
-
}
|
|
22
|
-
// Cria e configura a instância principal
|
|
23
|
-
const instance = Registry.classLoader(useCaseClass);
|
|
24
|
-
injectContext(instance, request);
|
|
25
|
-
// Decora o método execute
|
|
26
|
-
const originalExecute = instance.execute.bind(instance);
|
|
27
|
-
instance.execute = async (input) => {
|
|
28
|
-
for (const decoratorInstance of useCaseDecoratorsInstances) {
|
|
29
|
-
await decoratorInstance.execute(input);
|
|
30
|
-
}
|
|
31
|
-
return originalExecute(input);
|
|
32
|
-
};
|
|
33
|
-
return instance;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function injectContext(instance, request) {
|
|
37
|
-
const contextMetadata = Reflect.getMetadata('context', instance.constructor) || [];
|
|
38
|
-
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
39
|
-
if (request?.middlewareData?.[middlewareKey]) {
|
|
40
|
-
instance[propertyKey] = request.middlewareData[middlewareKey];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import express from "express";
|
|
3
|
-
import HttpServer from "./HttpServer";
|
|
4
|
-
const app = express();
|
|
5
|
-
export class ExpressHttpServer extends HttpServer {
|
|
6
|
-
async close() {
|
|
7
|
-
await this.framework.close();
|
|
8
|
-
console.log('server closed');
|
|
9
|
-
}
|
|
10
|
-
constructor(uses) {
|
|
11
|
-
super(app, 'express');
|
|
12
|
-
this.framework.use(express.json());
|
|
13
|
-
uses?.forEach(use => this.framework.use(use));
|
|
14
|
-
}
|
|
15
|
-
listen(port) {
|
|
16
|
-
super.listen(port);
|
|
17
|
-
console.log(`Server listening on port ${port}`);
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, StorageMock, Expose } from './decorators';
|
|
3
|
-
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
|
-
import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsBy, NotExistsBy, DeleteRepository, DeleteRepositoryBy, UpdateRepository, RestoreRepository, RestoreRepositoryBy, RestoreManyRepository, RequestMetricsHandler, Request, RequestMetrics, HttpServerError, StorageGateway } from './protocols';
|
|
5
|
-
import { Entity } from './domain/Entity';
|
|
6
|
-
import { UseCaseHandler } from './handlers';
|
|
7
|
-
export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, DeleteRepositoryBy, UpdateRepository, RestoreRepository, RestoreRepositoryBy, ExistsBy, NotExistsBy, RestoreManyRepository, Request, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage, StorageMock, Expose };
|
package/dist/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Dede } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, StorageMock, Expose } from './decorators';
|
|
3
|
-
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
|
-
import { Entity } from './domain/Entity';
|
|
5
|
-
import { UseCaseHandler } from './handlers';
|
|
6
|
-
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, Storage, StorageMock, Expose };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AllowedMethods, HttpStatusCode } from "../http/HttpServer";
|
|
2
|
-
import type { Validation } from "./Validation";
|
|
3
|
-
import type { HttpMiddleware } from "./HttpMiddleware";
|
|
4
|
-
import { RequestMetricsHandler } from "./RequestMetricsHandler";
|
|
5
|
-
export type Controller = {
|
|
6
|
-
instance: any;
|
|
7
|
-
instanceMethod: string;
|
|
8
|
-
route: string;
|
|
9
|
-
method: AllowedMethods;
|
|
10
|
-
middlewares?: HttpMiddleware[];
|
|
11
|
-
statusCode?: HttpStatusCode;
|
|
12
|
-
validation?: Validation;
|
|
13
|
-
params?: any;
|
|
14
|
-
query?: any;
|
|
15
|
-
metricsHandlers?: RequestMetricsHandler[];
|
|
16
|
-
offLogs?: boolean;
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type RequestMetrics = {
|
|
2
|
-
elapsedTime: string;
|
|
3
|
-
date: Date;
|
|
4
|
-
method: string;
|
|
5
|
-
route: string;
|
|
6
|
-
agent: string;
|
|
7
|
-
ip: string;
|
|
8
|
-
contentLength: string;
|
|
9
|
-
error?: {
|
|
10
|
-
message: string;
|
|
11
|
-
statusCode: number;
|
|
12
|
-
unexpectedError?: string;
|
|
13
|
-
};
|
|
14
|
-
handler: {
|
|
15
|
-
instance: string;
|
|
16
|
-
method: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|