framework-do-dede 1.0.17 → 1.0.19
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 +9 -0
- package/dist/decorators/index.d.ts +3 -3
- package/dist/decorators/index.js +3 -3
- package/dist/decorators/usecase.d.ts +1 -1
- package/dist/decorators/usecase.js +3 -3
- package/dist/domain/Entity.js +15 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function Restrict(): (target: any, propertyKey: string) => void;
|
|
2
|
+
export declare function VirtualProperty(propertyName: string): (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
2
3
|
export declare function DbColumn(mapping: string | Record<string, string>): (target: Object, propertyKey: string) => void;
|
|
@@ -6,6 +6,15 @@ export function Restrict() {
|
|
|
6
6
|
target.constructor._restrictedProperties.add(propertyKey);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
+
export function VirtualProperty(propertyName) {
|
|
10
|
+
return function (target, methodName, descriptor) {
|
|
11
|
+
const ctor = target.constructor;
|
|
12
|
+
if (!ctor._exposedProperties) {
|
|
13
|
+
ctor._exposedProperties = new Map();
|
|
14
|
+
}
|
|
15
|
+
ctor._exposedProperties.set(propertyName, methodName);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
9
18
|
export function DbColumn(mapping) {
|
|
10
19
|
return function (target, propertyKey) {
|
|
11
20
|
const ctor = target.constructor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metrics, OffConsoleLog } from './controller';
|
|
2
|
-
import {
|
|
2
|
+
import { Context } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
import { Restrict, DbColumn } from './entity';
|
|
5
|
-
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch,
|
|
4
|
+
import { Restrict, DbColumn, VirtualProperty } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, VirtualProperty };
|
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
|
-
import {
|
|
2
|
+
import { Context } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
import { Restrict, DbColumn } from './entity';
|
|
5
|
-
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch,
|
|
4
|
+
import { Restrict, DbColumn, VirtualProperty } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, VirtualProperty };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function Context(middlewareKey: string): (target: any, propertyKey: string) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function Context(middlewareKey) {
|
|
2
2
|
return function (target, propertyKey) {
|
|
3
|
-
const metadata = Reflect.getMetadata('
|
|
3
|
+
const metadata = Reflect.getMetadata('context', target.constructor) || [];
|
|
4
4
|
metadata.push({ propertyKey, middlewareKey });
|
|
5
|
-
Reflect.defineMetadata('
|
|
5
|
+
Reflect.defineMetadata('context', metadata, target.constructor);
|
|
6
6
|
};
|
|
7
7
|
}
|
package/dist/domain/Entity.js
CHANGED
|
@@ -2,7 +2,21 @@ export class Entity {
|
|
|
2
2
|
attributes() {
|
|
3
3
|
const ctor = this.constructor;
|
|
4
4
|
const restrictedProps = ctor._restrictedProperties || new Set();
|
|
5
|
-
|
|
5
|
+
const exposedProps = ctor._exposedProperties || new Map();
|
|
6
|
+
const attributes = {};
|
|
7
|
+
for (const [key, value] of Object.entries(this)) {
|
|
8
|
+
if (!restrictedProps.has(key)) {
|
|
9
|
+
attributes[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const [propName, methodName] of exposedProps) {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!restrictedProps.has(propName) && typeof this[methodName] === "function") {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
attributes[propName] = this[methodName]();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return attributes;
|
|
6
20
|
}
|
|
7
21
|
toSave() {
|
|
8
22
|
this.beforeSave();
|
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,
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsById, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, 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, ExistsById, RestoreManyRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware,
|
|
9
|
+
export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, ExistsById, RestoreManyRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, 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,
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, 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';
|
|
@@ -7,8 +7,8 @@ class UseCaseHandler {
|
|
|
7
7
|
static load(useCaseClass, request) {
|
|
8
8
|
const instance = Registry.classLoader(useCaseClass);
|
|
9
9
|
const context = request;
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const contextMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
11
|
+
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
12
12
|
if (context?.middlewareData?.[middlewareKey]) {
|
|
13
13
|
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
14
14
|
}
|
|
@@ -16,4 +16,4 @@ class UseCaseHandler {
|
|
|
16
16
|
return instance;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware,
|
|
19
|
+
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog };
|