framework-do-dede 1.0.0 → 1.0.2
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/decorators/entity.d.ts +1 -0
- package/dist/decorators/entity.js +12 -0
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -2
- package/dist/dede.d.ts +2 -1
- package/dist/dede.js +3 -1
- package/dist/domain/Entity.js +28 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -6,3 +6,15 @@ export function Restrict() {
|
|
|
6
6
|
target.constructor._restrictedProperties.add(propertyKey);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
+
export function DbColumn(mapping) {
|
|
10
|
+
return function (target, propertyKey) {
|
|
11
|
+
const ctor = target.constructor;
|
|
12
|
+
if (!Object.prototype.hasOwnProperty.call(ctor, '_dbColumns')) {
|
|
13
|
+
ctor._dbColumns = new Set();
|
|
14
|
+
}
|
|
15
|
+
ctor._dbColumns.add({
|
|
16
|
+
property: propertyKey,
|
|
17
|
+
mapping: mapping
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metrics, OffConsoleLog } from './controller';
|
|
2
2
|
import { Auth } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
import { Restrict } from './entity';
|
|
5
|
-
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict };
|
|
4
|
+
import { Restrict, DbColumn } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict, DbColumn };
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metrics, OffConsoleLog } from './controller';
|
|
2
2
|
import { Auth } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
import { Restrict } from './entity';
|
|
5
|
-
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict };
|
|
4
|
+
import { Restrict, DbColumn } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict, DbColumn };
|
package/dist/dede.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ export type Options = {
|
|
|
10
10
|
middlewares?: CallableFunction[];
|
|
11
11
|
};
|
|
12
12
|
registries: Register[];
|
|
13
|
+
defaultServerError?: string;
|
|
13
14
|
};
|
|
14
15
|
export declare class Dede {
|
|
15
|
-
static init({ framework, registries }: Options): Promise<void>;
|
|
16
|
+
static init({ framework, registries, defaultServerError }: Options): Promise<void>;
|
|
16
17
|
private static clearControllers;
|
|
17
18
|
private static loadRegistries;
|
|
18
19
|
}
|
package/dist/dede.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ControllerHandler } from "./handlers";
|
|
|
3
3
|
import { ElysiaHttpServer } from "./http/ElysiaHttpServer";
|
|
4
4
|
import { ExpressHttpServer } from "./http/ExpressHttpServer";
|
|
5
5
|
export class Dede {
|
|
6
|
-
static async init({ framework, registries }) {
|
|
6
|
+
static async init({ framework, registries, defaultServerError }) {
|
|
7
7
|
await this.loadRegistries(registries);
|
|
8
8
|
let httpServer;
|
|
9
9
|
if (framework.use === 'elysia') {
|
|
@@ -12,6 +12,8 @@ export class Dede {
|
|
|
12
12
|
if (framework.use === 'express') {
|
|
13
13
|
httpServer = new ExpressHttpServer(framework.middlewares || []);
|
|
14
14
|
}
|
|
15
|
+
if (defaultServerError)
|
|
16
|
+
httpServer.setDefaultMessageError(defaultServerError);
|
|
15
17
|
if (Registry.has('controllers')) {
|
|
16
18
|
new ControllerHandler(httpServer, framework.port || 80);
|
|
17
19
|
this.clearControllers();
|
package/dist/domain/Entity.js
CHANGED
|
@@ -5,6 +5,33 @@ export class Entity {
|
|
|
5
5
|
return Object.fromEntries(Object.entries(this).filter(([key]) => !restrictedProps.has(key)));
|
|
6
6
|
}
|
|
7
7
|
toSave() {
|
|
8
|
-
|
|
8
|
+
const result = {};
|
|
9
|
+
const processedKeys = new Set();
|
|
10
|
+
const dbColumns = this.constructor._dbColumns;
|
|
11
|
+
if (dbColumns) {
|
|
12
|
+
for (const { property, mapping } of dbColumns) {
|
|
13
|
+
const value = this[property];
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
continue;
|
|
16
|
+
processedKeys.add(property);
|
|
17
|
+
if (typeof mapping === 'string') {
|
|
18
|
+
result[mapping] = value;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
for (const [subProp, column] of Object.entries(mapping)) {
|
|
22
|
+
const subValue = value[subProp];
|
|
23
|
+
if (subValue !== undefined) {
|
|
24
|
+
result[column] = subValue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const [key, value] of Object.entries(this)) {
|
|
31
|
+
if (!processedKeys.has(key) && value !== undefined) {
|
|
32
|
+
result[key] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
9
36
|
}
|
|
10
37
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict, Metrics, OffConsoleLog } from './decorators';
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict, Metrics, DbColumn, OffConsoleLog } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Validation, HttpMiddleware, UseCase, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestMetricsHandler, RequestData, RequestMetrics, HttpServerError } from './protocols';
|
|
5
5
|
import { Entity } from './domain/Entity';
|
|
6
6
|
declare class UseCaseHandler {
|
|
7
7
|
static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: RequestData): T;
|
|
8
8
|
}
|
|
9
|
-
export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, Metrics, OffConsoleLog };
|
|
9
|
+
export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, DbColumn, Metrics, OffConsoleLog };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dede } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict, Metrics, OffConsoleLog } from './decorators';
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict, Metrics, DbColumn, OffConsoleLog } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Registry } from './di/registry';
|
|
5
5
|
import { Entity } from './domain/Entity';
|
|
@@ -14,4 +14,4 @@ class UseCaseHandler {
|
|
|
14
14
|
return instance;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, Metrics, OffConsoleLog };
|
|
17
|
+
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, DbColumn, Metrics, OffConsoleLog };
|