framework-do-dede 3.3.1 → 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 +515 -4
- package/dist/application/controller.d.ts +6 -2
- package/dist/application/controller.js +10 -18
- package/dist/application/index.d.ts +2 -2
- package/dist/application/index.js +2 -2
- 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 +8 -1
- package/dist/{application → infra/serialization}/entity.js +87 -23
- 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
package/dist/dede.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Container } from "./infra/di/registry";
|
|
1
2
|
export type Register = {
|
|
2
3
|
name: string;
|
|
3
4
|
classLoader: any;
|
|
@@ -8,15 +9,23 @@ export type Options = {
|
|
|
8
9
|
port?: number;
|
|
9
10
|
middlewares?: CallableFunction[];
|
|
10
11
|
};
|
|
12
|
+
controllers?: any[];
|
|
11
13
|
registries: Register[];
|
|
12
14
|
defaultServerError?: string;
|
|
15
|
+
container?: Container;
|
|
13
16
|
};
|
|
14
17
|
export declare class Dede {
|
|
15
18
|
private readonly framework;
|
|
16
19
|
private readonly defaultServerError?;
|
|
20
|
+
private readonly container;
|
|
17
21
|
private readonly httpServer;
|
|
22
|
+
private readonly port?;
|
|
23
|
+
private controllersRegistered;
|
|
18
24
|
private constructor();
|
|
19
|
-
static
|
|
25
|
+
static create({ framework, registries, defaultServerError, container }: Options): Promise<Dede>;
|
|
26
|
+
static start({ framework, registries, defaultServerError, container, controllers }: Options): Promise<Dede>;
|
|
20
27
|
stop(): Promise<void>;
|
|
28
|
+
registerControllers(controllers: any[]): void;
|
|
29
|
+
listen(port?: number): void;
|
|
21
30
|
private static loadRegistries;
|
|
22
31
|
}
|
package/dist/dede.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import ControllerHandler from "./http/controller.handler";
|
|
2
2
|
import { ElysiaServerAdapter } from "./http/elysia-server.adapter";
|
|
3
3
|
import { ExpressServerAdapter } from "./http/express-server.adapter";
|
|
4
|
-
import {
|
|
4
|
+
import { Container, DefaultContainer, setDefaultContainer } from "./infra/di/registry";
|
|
5
5
|
export class Dede {
|
|
6
|
-
constructor(framework, defaultServerError) {
|
|
6
|
+
constructor(framework, defaultServerError, container = DefaultContainer) {
|
|
7
7
|
this.framework = framework;
|
|
8
8
|
this.defaultServerError = defaultServerError;
|
|
9
|
+
this.container = container;
|
|
10
|
+
this.controllersRegistered = false;
|
|
11
|
+
this.port = framework.port;
|
|
9
12
|
if (framework.use === 'elysia') {
|
|
10
13
|
this.httpServer = new ElysiaServerAdapter(framework.middlewares || []);
|
|
11
14
|
}
|
|
@@ -14,19 +17,37 @@ export class Dede {
|
|
|
14
17
|
}
|
|
15
18
|
if (defaultServerError)
|
|
16
19
|
this.httpServer.setDefaultMessageError(defaultServerError);
|
|
17
|
-
new ControllerHandler(this.httpServer, framework.port || 80);
|
|
18
20
|
}
|
|
19
|
-
static async
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
static async create({ framework, registries, defaultServerError, container }) {
|
|
22
|
+
const appContainer = container ?? new Container();
|
|
23
|
+
setDefaultContainer(appContainer);
|
|
24
|
+
await this.loadRegistries(appContainer, registries);
|
|
25
|
+
return new Dede(framework, defaultServerError, appContainer);
|
|
26
|
+
}
|
|
27
|
+
static async start({ framework, registries, defaultServerError, container, controllers }) {
|
|
28
|
+
const app = await Dede.create({ framework, registries, defaultServerError, container, controllers });
|
|
29
|
+
if (controllers && controllers.length > 0) {
|
|
30
|
+
app.registerControllers(controllers);
|
|
31
|
+
}
|
|
32
|
+
app.listen();
|
|
33
|
+
return app;
|
|
22
34
|
}
|
|
23
35
|
async stop() {
|
|
24
36
|
await this.httpServer.close();
|
|
25
37
|
}
|
|
26
|
-
|
|
38
|
+
registerControllers(controllers) {
|
|
39
|
+
if (this.controllersRegistered)
|
|
40
|
+
return;
|
|
41
|
+
new ControllerHandler(this.httpServer, controllers);
|
|
42
|
+
this.controllersRegistered = true;
|
|
43
|
+
}
|
|
44
|
+
listen(port) {
|
|
45
|
+
const resolvedPort = port ?? this.port ?? 80;
|
|
46
|
+
this.httpServer.listen(resolvedPort);
|
|
47
|
+
}
|
|
48
|
+
static async loadRegistries(container, registries) {
|
|
27
49
|
registries.forEach(({ classLoader, name }) => {
|
|
28
|
-
|
|
50
|
+
container.load(name, classLoader);
|
|
29
51
|
});
|
|
30
|
-
return new Promise(resolve => setTimeout(resolve, 500));
|
|
31
52
|
}
|
|
32
53
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class Entity {
|
|
2
|
+
generateGetters() {
|
|
3
|
+
for (const property of Object.keys(this)) {
|
|
4
|
+
if (typeof this[property] === 'function')
|
|
5
|
+
continue;
|
|
6
|
+
let prefixName = null;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (this.constructor.propertiesConfigs && this.constructor.propertiesConfigs[property] && this.constructor.propertiesConfigs[property].prefix) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
prefixName = this.constructor.propertiesConfigs[property].prefix;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const isBoolean = this[property] ? typeof this[property] === 'boolean' : false;
|
|
14
|
+
prefixName = isBoolean ? 'is' : 'get';
|
|
15
|
+
}
|
|
16
|
+
let getterName = null;
|
|
17
|
+
if (property[0]) {
|
|
18
|
+
getterName = `${prefixName}${property[0].toUpperCase()}${property.slice(1)}`;
|
|
19
|
+
if (this[getterName])
|
|
20
|
+
continue;
|
|
21
|
+
this[getterName] = () => this[property];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type AppErrorData = {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
details?: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
export declare abstract class AppError extends Error {
|
|
7
|
+
private readonly statusCode;
|
|
8
|
+
private readonly data?;
|
|
9
|
+
constructor(message: string, statusCode: number, data?: AppErrorData);
|
|
10
|
+
getStatusCode(): number;
|
|
11
|
+
getData(): AppErrorData | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class AppError extends Error {
|
|
2
|
+
constructor(message, statusCode, data) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
this.statusCode = statusCode;
|
|
6
|
+
this.data = data;
|
|
7
|
+
}
|
|
8
|
+
getStatusCode() {
|
|
9
|
+
return this.statusCode;
|
|
10
|
+
}
|
|
11
|
+
getData() {
|
|
12
|
+
return this.data;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AppError } from './app-error';
|
|
2
|
+
export declare class BadRequest extends AppError {
|
|
3
|
+
constructor(message: string, data?: {
|
|
4
|
+
code?: string;
|
|
5
|
+
details?: Record<string, any>;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export declare class Unauthorized extends AppError {
|
|
9
|
+
constructor(message: string, data?: {
|
|
10
|
+
code?: string;
|
|
11
|
+
details?: Record<string, any>;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export declare class Forbidden extends AppError {
|
|
15
|
+
constructor(message: string, data?: {
|
|
16
|
+
code?: string;
|
|
17
|
+
details?: Record<string, any>;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export declare class NotFound extends AppError {
|
|
21
|
+
constructor(message: string, data?: {
|
|
22
|
+
code?: string;
|
|
23
|
+
details?: Record<string, any>;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export declare class Conflict extends AppError {
|
|
27
|
+
constructor(message: string, data?: {
|
|
28
|
+
code?: string;
|
|
29
|
+
details?: Record<string, any>;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export declare class UnprocessableEntity extends AppError {
|
|
33
|
+
constructor(message: string, data?: {
|
|
34
|
+
code?: string;
|
|
35
|
+
details?: Record<string, any>;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export declare class InternalServerError extends AppError {
|
|
39
|
+
private readonly unexpectedError;
|
|
40
|
+
constructor(unexpectedError: string, defaultMessage?: string);
|
|
41
|
+
getUnexpectedError(): string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AppError } from './app-error';
|
|
2
|
+
export class BadRequest extends AppError {
|
|
3
|
+
constructor(message, data) {
|
|
4
|
+
super(message, 400, data ? { message, ...data } : undefined);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class Unauthorized extends AppError {
|
|
8
|
+
constructor(message, data) {
|
|
9
|
+
super(message, 401, data ? { message, ...data } : undefined);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class Forbidden extends AppError {
|
|
13
|
+
constructor(message, data) {
|
|
14
|
+
super(message, 403, data ? { message, ...data } : undefined);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class NotFound extends AppError {
|
|
18
|
+
constructor(message, data) {
|
|
19
|
+
super(message, 404, data ? { message, ...data } : undefined);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class Conflict extends AppError {
|
|
23
|
+
constructor(message, data) {
|
|
24
|
+
super(message, 409, data ? { message, ...data } : undefined);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class UnprocessableEntity extends AppError {
|
|
28
|
+
constructor(message, data) {
|
|
29
|
+
super(message, 422, data ? { message, ...data } : undefined);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class InternalServerError extends AppError {
|
|
33
|
+
constructor(unexpectedError, defaultMessage = 'Ops, An unexpected error occurred') {
|
|
34
|
+
super(defaultMessage, 500, { message: defaultMessage });
|
|
35
|
+
this.unexpectedError = unexpectedError;
|
|
36
|
+
}
|
|
37
|
+
getUnexpectedError() {
|
|
38
|
+
return this.unexpectedError;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import HttpServer from "../http/http-server";
|
|
2
2
|
export default class ControllerHandler {
|
|
3
|
-
|
|
4
|
-
private
|
|
3
|
+
private readonly requestMapper;
|
|
4
|
+
private readonly middlewareExecutor;
|
|
5
|
+
private readonly errorMapper;
|
|
6
|
+
constructor(httpServer: HttpServer, controllers?: any[]);
|
|
5
7
|
private registryControllers;
|
|
6
8
|
private resolveMiddleware;
|
|
7
|
-
private filter;
|
|
8
|
-
private extractError;
|
|
9
|
-
private normalizeBracketNotation;
|
|
10
9
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { InternalServerError, ServerError } from "../http";
|
|
2
|
-
import { flushControllers, getControllers } from "../application/controller";
|
|
3
1
|
import { FrameworkError } from "../http/errors/framework";
|
|
4
|
-
import {
|
|
2
|
+
import { HttpRequestMapper } from "../interface/http/request-mapper";
|
|
3
|
+
import { MiddlewareExecutor } from "../interface/http/middleware-executor";
|
|
4
|
+
import { HttpErrorMapper } from "../interface/errors/http-error-mapper";
|
|
5
|
+
import { validateWithClassValidator } from "../interface/validation/class-validator";
|
|
5
6
|
export default class ControllerHandler {
|
|
6
|
-
constructor(httpServer,
|
|
7
|
-
|
|
7
|
+
constructor(httpServer, controllers = []) {
|
|
8
|
+
this.requestMapper = new HttpRequestMapper();
|
|
9
|
+
this.middlewareExecutor = new MiddlewareExecutor();
|
|
10
|
+
this.errorMapper = new HttpErrorMapper();
|
|
11
|
+
for (const { handler, middlewares, validator, method, route, statusCode, params, query, headers, body, bodyFilter, responseType } of this.registryControllers(controllers)) {
|
|
8
12
|
httpServer.register({
|
|
9
13
|
method,
|
|
10
14
|
route,
|
|
@@ -14,6 +18,7 @@ export default class ControllerHandler {
|
|
|
14
18
|
query,
|
|
15
19
|
headers,
|
|
16
20
|
middlewares,
|
|
21
|
+
validator,
|
|
17
22
|
responseType
|
|
18
23
|
}, async (input) => {
|
|
19
24
|
let requestedAt = new Date();
|
|
@@ -25,23 +30,26 @@ export default class ControllerHandler {
|
|
|
25
30
|
let middlewaresExecuted = [];
|
|
26
31
|
try {
|
|
27
32
|
startTime = performance.now();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
request = this.requestMapper.map(input, { params, query, headers, body, bodyFilter });
|
|
34
|
+
if (validator) {
|
|
35
|
+
if (typeof validator === 'function') {
|
|
36
|
+
await validateWithClassValidator(validator, request.data);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof validator.validate === 'function') {
|
|
39
|
+
await validator.validate(request.data);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new FrameworkError('Validator must be a class or implement validate()');
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
|
-
mergedParams =
|
|
37
|
-
|
|
38
|
-
middlewaresExecuted = await this.executeMiddlewares(middlewares, request);
|
|
45
|
+
mergedParams = request.data;
|
|
46
|
+
middlewaresExecuted = await this.middlewareExecutor.execute(middlewares, request);
|
|
39
47
|
const response = await handler.instance[handler.methodName](request);
|
|
40
48
|
endTime = performance.now();
|
|
41
49
|
return response;
|
|
42
50
|
}
|
|
43
51
|
catch (error) {
|
|
44
|
-
capturedError = this.
|
|
52
|
+
capturedError = this.errorMapper.map(error, httpServer);
|
|
45
53
|
input.setStatus(capturedError.statusCode);
|
|
46
54
|
endTime = performance.now();
|
|
47
55
|
if (capturedError?.custom) {
|
|
@@ -70,42 +78,10 @@ export default class ControllerHandler {
|
|
|
70
78
|
}
|
|
71
79
|
});
|
|
72
80
|
}
|
|
73
|
-
httpServer.listen(port);
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
const executed = [];
|
|
77
|
-
if (middlewares && middlewares.length > 0) {
|
|
78
|
-
for (const middleware of middlewares) {
|
|
79
|
-
let startTime = 0;
|
|
80
|
-
let endTime = 0;
|
|
81
|
-
let elapsedTime;
|
|
82
|
-
try {
|
|
83
|
-
startTime = performance.now();
|
|
84
|
-
const middlewareResult = await middleware.execute(request);
|
|
85
|
-
request.context = Object.assign(request.context, middlewareResult);
|
|
86
|
-
endTime = performance.now();
|
|
87
|
-
elapsedTime = `${(endTime - startTime).toFixed(2)} ms`;
|
|
88
|
-
executed.push({
|
|
89
|
-
elapsedTime,
|
|
90
|
-
middleware: middleware.constructor.name
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
elapsedTime = `${(endTime - startTime).toFixed(2)} ms`;
|
|
95
|
-
executed.push({
|
|
96
|
-
elapsedTime,
|
|
97
|
-
middleware: middleware.constructor.name,
|
|
98
|
-
error
|
|
99
|
-
});
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return executed;
|
|
105
|
-
}
|
|
106
|
-
registryControllers() {
|
|
82
|
+
registryControllers(controllersList) {
|
|
107
83
|
const controllers = [];
|
|
108
|
-
for (const controller of
|
|
84
|
+
for (const controller of controllersList) {
|
|
109
85
|
const basePath = Reflect.getMetadata('basePath', controller);
|
|
110
86
|
const methodNames = Object.getOwnPropertyNames(controller.prototype).filter(method => method !== 'constructor');
|
|
111
87
|
let tracer = Reflect.getMetadata('tracer', controller) || null;
|
|
@@ -124,6 +100,7 @@ export default class ControllerHandler {
|
|
|
124
100
|
body: routeConfig.body,
|
|
125
101
|
bodyFilter: routeConfig.bodyFilter,
|
|
126
102
|
statusCode: routeConfig.statusCode,
|
|
103
|
+
validator: routeConfig.validator,
|
|
127
104
|
handler: {
|
|
128
105
|
instance,
|
|
129
106
|
methodName,
|
|
@@ -134,7 +111,6 @@ export default class ControllerHandler {
|
|
|
134
111
|
});
|
|
135
112
|
}
|
|
136
113
|
}
|
|
137
|
-
flushControllers();
|
|
138
114
|
return controllers;
|
|
139
115
|
}
|
|
140
116
|
resolveMiddleware(middleware) {
|
|
@@ -158,72 +134,4 @@ export default class ControllerHandler {
|
|
|
158
134
|
}
|
|
159
135
|
return middleware;
|
|
160
136
|
}
|
|
161
|
-
filter(params, filterParams) {
|
|
162
|
-
const filter = {};
|
|
163
|
-
for (const paramName of filterParams || []) {
|
|
164
|
-
const [paramNameFiltered, type] = paramName.split('|');
|
|
165
|
-
let value = params[paramName] || params[paramNameFiltered];
|
|
166
|
-
if (!value)
|
|
167
|
-
continue;
|
|
168
|
-
if (type === 'boolean')
|
|
169
|
-
value = value === 'true';
|
|
170
|
-
if (type === 'integer') {
|
|
171
|
-
value = value.replace(/[^0-9]/g, '');
|
|
172
|
-
value = value ? parseInt(value) : 0;
|
|
173
|
-
}
|
|
174
|
-
if (type === 'string')
|
|
175
|
-
value = value.toString();
|
|
176
|
-
if (type === 'number')
|
|
177
|
-
value = parseFloat(value);
|
|
178
|
-
filter[paramNameFiltered] = value;
|
|
179
|
-
}
|
|
180
|
-
return filter;
|
|
181
|
-
}
|
|
182
|
-
extractError(error, httpServer) {
|
|
183
|
-
if (error instanceof ServerError) {
|
|
184
|
-
return {
|
|
185
|
-
message: error.message,
|
|
186
|
-
statusCode: error.getStatusCode()
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (error instanceof CustomServerError) {
|
|
190
|
-
return {
|
|
191
|
-
...error.getCustom(),
|
|
192
|
-
statusCode: error.getStatusCode(),
|
|
193
|
-
custom: true
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const debugError = {
|
|
197
|
-
sourceUrl: error.sourceURL,
|
|
198
|
-
line: error.line,
|
|
199
|
-
column: error.column,
|
|
200
|
-
};
|
|
201
|
-
error = new InternalServerError(error.message, httpServer.getDefaultMessageError());
|
|
202
|
-
return {
|
|
203
|
-
message: error.message,
|
|
204
|
-
statusCode: error.getStatusCode(),
|
|
205
|
-
unexpectedError: error instanceof InternalServerError ? error.getUnexpectedError() : undefined,
|
|
206
|
-
...debugError
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
normalizeBracketNotation(data) {
|
|
210
|
-
if (!data || typeof data !== "object")
|
|
211
|
-
return data;
|
|
212
|
-
const normalized = {};
|
|
213
|
-
for (const [rawKey, value] of Object.entries(data)) {
|
|
214
|
-
const key = String(rawKey);
|
|
215
|
-
const match = key.match(/^([^\[\]]+)\[([^\[\]]+)\]$/);
|
|
216
|
-
if (match) {
|
|
217
|
-
const parent = match[1];
|
|
218
|
-
const child = match[2];
|
|
219
|
-
if (!normalized[parent] || typeof normalized[parent] !== "object") {
|
|
220
|
-
normalized[parent] = {};
|
|
221
|
-
}
|
|
222
|
-
normalized[parent][child] = value;
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
normalized[key] = value;
|
|
226
|
-
}
|
|
227
|
-
return normalized;
|
|
228
|
-
}
|
|
229
137
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
constructor(message: string, statusCode: number);
|
|
4
|
-
getStatusCode(): number;
|
|
5
|
-
}
|
|
1
|
+
export { AppError as ServerError } from "../../domain/errors/app-error";
|
|
2
|
+
export { BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, InternalServerError } from "../../domain/errors/http-errors";
|
|
6
3
|
export declare class CustomServerError extends Error {
|
|
7
4
|
private statusCode;
|
|
8
5
|
private custom;
|
|
@@ -10,26 +7,3 @@ export declare class CustomServerError extends Error {
|
|
|
10
7
|
getStatusCode(): number;
|
|
11
8
|
getCustom(): any;
|
|
12
9
|
}
|
|
13
|
-
export declare class NotFound extends ServerError {
|
|
14
|
-
constructor(message: string);
|
|
15
|
-
}
|
|
16
|
-
export declare class Forbidden extends ServerError {
|
|
17
|
-
constructor(message: string);
|
|
18
|
-
}
|
|
19
|
-
export declare class UnprocessableEntity extends ServerError {
|
|
20
|
-
constructor(message: string);
|
|
21
|
-
}
|
|
22
|
-
export declare class Conflict extends ServerError {
|
|
23
|
-
constructor(message: string);
|
|
24
|
-
}
|
|
25
|
-
export declare class Unauthorized extends ServerError {
|
|
26
|
-
constructor(message: string);
|
|
27
|
-
}
|
|
28
|
-
export declare class BadRequest extends ServerError {
|
|
29
|
-
constructor(message: string);
|
|
30
|
-
}
|
|
31
|
-
export declare class InternalServerError extends ServerError {
|
|
32
|
-
private unexpectedError;
|
|
33
|
-
constructor(unexpectedError: string, defaultMessage?: string);
|
|
34
|
-
getUnexpectedError(): string;
|
|
35
|
-
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = this.constructor.name;
|
|
5
|
-
this.statusCode = statusCode;
|
|
6
|
-
}
|
|
7
|
-
getStatusCode() {
|
|
8
|
-
return this.statusCode;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export { AppError as ServerError } from "../../domain/errors/app-error";
|
|
2
|
+
export { BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, InternalServerError } from "../../domain/errors/http-errors";
|
|
11
3
|
export class CustomServerError extends Error {
|
|
12
4
|
constructor(custom, statusCode, nameError = '') {
|
|
13
5
|
super();
|
|
@@ -22,42 +14,3 @@ export class CustomServerError extends Error {
|
|
|
22
14
|
return this.custom;
|
|
23
15
|
}
|
|
24
16
|
}
|
|
25
|
-
export class NotFound extends ServerError {
|
|
26
|
-
constructor(message) {
|
|
27
|
-
super(message, 404);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class Forbidden extends ServerError {
|
|
31
|
-
constructor(message) {
|
|
32
|
-
super(message, 403);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export class UnprocessableEntity extends ServerError {
|
|
36
|
-
constructor(message) {
|
|
37
|
-
super(message, 422);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export class Conflict extends ServerError {
|
|
41
|
-
constructor(message) {
|
|
42
|
-
super(message, 409);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export class Unauthorized extends ServerError {
|
|
46
|
-
constructor(message) {
|
|
47
|
-
super(message, 401);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export class BadRequest extends ServerError {
|
|
51
|
-
constructor(message) {
|
|
52
|
-
super(message, 400);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export class InternalServerError extends ServerError {
|
|
56
|
-
constructor(unexpectedError, defaultMessage = 'Ops, An unexpected error occurred') {
|
|
57
|
-
super(defaultMessage, 500);
|
|
58
|
-
this.unexpectedError = unexpectedError;
|
|
59
|
-
}
|
|
60
|
-
getUnexpectedError() {
|
|
61
|
-
return this.unexpectedError;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Middleware, Tracer } from "../application/controller";
|
|
2
|
+
import type { ValidatorLike } from "../interface/validation/validator";
|
|
2
3
|
export type Request = {
|
|
3
4
|
data: any;
|
|
4
5
|
context: any;
|
|
@@ -15,6 +16,7 @@ export type HttpServerParams = {
|
|
|
15
16
|
};
|
|
16
17
|
responseType: 'json' | 'text' | 'html';
|
|
17
18
|
middlewares?: Middleware[];
|
|
19
|
+
validator?: ValidatorLike;
|
|
18
20
|
statusCode?: number;
|
|
19
21
|
params?: string[];
|
|
20
22
|
query?: string[];
|
package/dist/http/http-server.js
CHANGED
|
@@ -53,7 +53,7 @@ export default class HttpServer {
|
|
|
53
53
|
express(httpServerParams, route, handler) {
|
|
54
54
|
const method = httpServerParams.method;
|
|
55
55
|
this.framework[method](route, async (request, res) => {
|
|
56
|
-
request.headers['ip'] = request.ip
|
|
56
|
+
request.headers['ip'] = request.ip;
|
|
57
57
|
res.status(httpServerParams.statusCode ?? 200);
|
|
58
58
|
const output = await handler({
|
|
59
59
|
setStatus: (statusCode) => res.status(statusCode),
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import HttpServer from "./http-server";
|
|
2
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from "./errors/server";
|
|
3
|
-
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError };
|
|
2
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from "./errors/server";
|
|
3
|
+
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError, CustomServerError };
|
package/dist/http/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import HttpServer from "./http-server";
|
|
2
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from "./errors/server";
|
|
3
|
-
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError };
|
|
2
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from "./errors/server";
|
|
3
|
+
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError, CustomServerError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Post, Get, Put, Delete, Patch, Controller, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, StorageGateway } from "./application";
|
|
2
|
-
import { Inject } from './infra/di/registry';
|
|
2
|
+
import { Container, DefaultContainer, Inject, setDefaultContainer } from './infra/di/registry';
|
|
3
3
|
import { Dede, type Options, Register } from './dede';
|
|
4
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from './http/errors/server';
|
|
4
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from './http/errors/server';
|
|
5
|
+
import { AppError } from './domain/errors/app-error';
|
|
5
6
|
import type { RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryExistsBy, RepositoryRestore, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination } from './protocols/repository';
|
|
6
|
-
export { Controller, Post, Get, Put, Delete, Patch, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, StorageGateway, Inject, Dede, Options, Register, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryRestore, RepositoryExistsBy, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination };
|
|
7
|
+
export { Controller, Post, Get, Put, Delete, Patch, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, StorageGateway, Inject, Container, DefaultContainer, setDefaultContainer, Dede, Options, Register, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError, AppError, RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryRestore, RepositoryExistsBy, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination };
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ UseCase, DecorateUseCase,
|
|
|
10
10
|
// usecase
|
|
11
11
|
// storage
|
|
12
12
|
Storage } from "./application";
|
|
13
|
-
import { Inject } from './infra/di/registry';
|
|
13
|
+
import { Container, DefaultContainer, Inject, setDefaultContainer } from './infra/di/registry';
|
|
14
14
|
import { Dede } from './dede';
|
|
15
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from './http/errors/server';
|
|
16
|
-
|
|
15
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from './http/errors/server';
|
|
16
|
+
import { AppError } from './domain/errors/app-error';
|
|
17
|
+
export { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, Inject, Container, DefaultContainer, setDefaultContainer, Dede, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError, AppError };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
declare class
|
|
2
|
-
private static instance;
|
|
1
|
+
export declare class Container {
|
|
3
2
|
private dependencies;
|
|
4
|
-
static getInstance(): ComponentRegistry;
|
|
5
3
|
load(name: string, dependency: any): void;
|
|
6
4
|
inject(name: string): any;
|
|
7
5
|
remove(name: string): void;
|
|
8
6
|
}
|
|
9
|
-
export declare
|
|
10
|
-
export declare function
|
|
11
|
-
export
|
|
7
|
+
export declare let DefaultContainer: Container;
|
|
8
|
+
export declare function setDefaultContainer(container: Container): void;
|
|
9
|
+
export declare function Inject(name: string, container?: Container): (target: any, propertyKey: string) => void;
|