framework-do-dede 4.0.4 → 4.1.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, type Middleware, type Input, type Tracer, type TracerData } from './controller';
|
|
2
2
|
import { Entity, Restrict, VirtualProperty, Serialize, GetterPrefix, BeforeToEntity, AfterToEntity } from '../infra/serialization/entity';
|
|
3
3
|
import { DecorateUseCase, UseCase } from './usecase';
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export type { Middleware, Input,
|
|
4
|
+
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, DecorateUseCase, UseCase, Entity, Restrict, VirtualProperty, Serialize, GetterPrefix, BeforeToEntity, AfterToEntity, };
|
|
5
|
+
export { Storage, CacheGateway } from './services';
|
|
6
|
+
export type { Middleware, Input, Tracer, TracerData };
|
|
7
|
+
export type { StorageGateway } from './services';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing } from './controller';
|
|
2
2
|
import { Entity, Restrict, VirtualProperty, Serialize, GetterPrefix, BeforeToEntity, AfterToEntity } from '../infra/serialization/entity';
|
|
3
3
|
import { DecorateUseCase, UseCase } from './usecase';
|
|
4
|
-
|
|
5
|
-
export {
|
|
4
|
+
export { Controller, UseMiddleware, UseMiddlewares, Post, Get, Put, Delete, Patch, Tracing, DecorateUseCase, UseCase, Entity, Restrict, VirtualProperty, Serialize, GetterPrefix, BeforeToEntity, AfterToEntity, };
|
|
5
|
+
export { Storage, CacheGateway } from './services';
|
|
@@ -5,4 +5,10 @@ export interface StorageGateway {
|
|
|
5
5
|
get(key: string): Promise<string>;
|
|
6
6
|
delete(key: string): Promise<boolean>;
|
|
7
7
|
}
|
|
8
|
+
export interface CacheGateway {
|
|
9
|
+
get<T = unknown>(key: string): Promise<T | null> | T | null;
|
|
10
|
+
set<T = unknown>(key: string, value: T, ttl?: number): Promise<void> | void;
|
|
11
|
+
delete(key: string): Promise<boolean> | boolean;
|
|
12
|
+
}
|
|
8
13
|
export declare function Storage(gatewayName: string, container?: Container): (target: any, propertyKey: string) => void;
|
|
14
|
+
export declare function CacheGateway(gatewayName: string, container?: Container): (target: any, propertyKey?: string) => void;
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { DefaultContainer } from "../infra/di/registry";
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return dependency[prop];
|
|
3
|
+
function defineGatewayProperty(target, propertyKey, gatewayName, container, validator, errorMessage) {
|
|
4
|
+
Object.defineProperty(target, propertyKey, {
|
|
5
|
+
get: function () {
|
|
6
|
+
return new Proxy({}, {
|
|
7
|
+
get(_, prop) {
|
|
8
|
+
const resolvedContainer = container ?? DefaultContainer;
|
|
9
|
+
const dependency = resolvedContainer.inject(gatewayName);
|
|
10
|
+
if (validator && !validator(dependency)) {
|
|
11
|
+
throw new Error(errorMessage ?? `${gatewayName} is not a valid dependency`);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
return dependency[prop];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function Storage(gatewayName, container) {
|
|
22
|
+
return function (target, propertyKey) {
|
|
23
|
+
defineGatewayProperty(target, propertyKey, gatewayName, container, (dependency) => !!dependency?.save && !!dependency?.get && !!dependency?.delete, `${gatewayName} is not a valid StorageGateway`);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function CacheGateway(gatewayName, container) {
|
|
27
|
+
return function (target, propertyKey) {
|
|
28
|
+
const resolvedProperty = propertyKey ?? 'cache';
|
|
29
|
+
const resolvedTarget = propertyKey ? target : target.prototype;
|
|
30
|
+
defineGatewayProperty(resolvedTarget, resolvedProperty, gatewayName, container, (dependency) => !!dependency?.get && !!dependency?.set && !!dependency?.delete, `${gatewayName} is not a valid CacheGateway`);
|
|
20
31
|
};
|
|
21
32
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Post, Get, Put, Delete, Patch, Controller, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage,
|
|
1
|
+
import { Post, Get, Put, Delete, Patch, Controller, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, CacheGateway } from "./application";
|
|
2
2
|
import { Container, DefaultContainer, Inject, setDefaultContainer } from './infra/di/registry';
|
|
3
3
|
import { Dede, type Options, Register } from './dede';
|
|
4
4
|
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from './http/errors/server';
|
|
5
5
|
import { AppError } from './domain/errors/app-error';
|
|
6
6
|
import type { ValidatorDefinition } from './interface/validation/validator';
|
|
7
|
+
import type { StorageGateway } from './application';
|
|
7
8
|
import type { RepositoryCreate, RepositoryUpdate, RepositoryRemove, RepositoryRemoveBy, RepositoryExistsBy, RepositoryRestore, RepositoryRestoreBy, RepositoryNotExistsBy, RepositoryPagination } from './protocols/repository';
|
|
8
|
-
export { Controller, Post, Get, Put, Delete, Patch, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage,
|
|
9
|
-
export type { ValidatorDefinition };
|
|
9
|
+
export { Controller, Post, Get, Put, Delete, Patch, Input, Middleware, UseMiddleware, UseMiddlewares, Tracer, Tracing, TracerData, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, CacheGateway, 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 };
|
|
10
|
+
export type { ValidatorDefinition, StorageGateway };
|
package/dist/index.js
CHANGED
|
@@ -9,9 +9,11 @@ Entity, Restrict, VirtualProperty, GetterPrefix, Serialize,
|
|
|
9
9
|
UseCase, DecorateUseCase,
|
|
10
10
|
// usecase
|
|
11
11
|
// storage
|
|
12
|
-
Storage
|
|
12
|
+
Storage, CacheGateway
|
|
13
|
+
// storage
|
|
14
|
+
} from "./application";
|
|
13
15
|
import { Container, DefaultContainer, Inject, setDefaultContainer } from './infra/di/registry';
|
|
14
16
|
import { Dede } from './dede';
|
|
15
17
|
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError } from './http/errors/server';
|
|
16
18
|
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 };
|
|
19
|
+
export { Controller, Post, Get, Put, Delete, Patch, UseMiddleware, UseMiddlewares, Tracing, Entity, Restrict, VirtualProperty, GetterPrefix, Serialize, UseCase, DecorateUseCase, Storage, CacheGateway, Inject, Container, DefaultContainer, setDefaultContainer, Dede, ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError, CustomServerError, AppError };
|