framework-do-dede 0.0.70 → 1.0.1
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/domain/Entity.js +28 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocols/UpdateRepository.d.ts +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/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 };
|