framework-do-dede 1.0.21 → 1.0.22

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.
@@ -2,4 +2,5 @@ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metri
2
2
  import { Context } from './usecase';
3
3
  import { Inject } from './di';
4
4
  import { Restrict, DbColumn, VirtualProperty } from './entity';
5
- export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, VirtualProperty };
5
+ import { Storage } from './services';
6
+ export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, Storage, VirtualProperty };
@@ -2,4 +2,5 @@ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metri
2
2
  import { Context } from './usecase';
3
3
  import { Inject } from './di';
4
4
  import { Restrict, DbColumn, VirtualProperty } from './entity';
5
- export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, VirtualProperty };
5
+ import { Storage } from './services';
6
+ export { Controller, Middleware, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, Storage, VirtualProperty };
@@ -0,0 +1 @@
1
+ export declare function Storage(): (target: any, propertyKey: string) => void;
@@ -0,0 +1,29 @@
1
+ import { Registry } from "../di/registry";
2
+ import { StorageGateway } from "../protocols/StorageGateway";
3
+ export function Storage() {
4
+ return function (target, propertyKey) {
5
+ const designType = Reflect.getMetadata('design:type', target, propertyKey);
6
+ if (!(designType?.prototype instanceof StorageGateway)) {
7
+ throw new Error(`@Storage() can only be used with StorageGateway subclasses`);
8
+ }
9
+ const gatewayName = designType.name;
10
+ if (!Registry.has(gatewayName)) {
11
+ throw new Error(`StorageGateway ${gatewayName} not registered`);
12
+ }
13
+ const instanceSymbol = Symbol();
14
+ Object.defineProperty(target, propertyKey, {
15
+ get: function () {
16
+ if (!this[instanceSymbol]) {
17
+ const GatewayClass = Registry.resolve(gatewayName);
18
+ this[instanceSymbol] = GatewayClass;
19
+ }
20
+ return this[instanceSymbol];
21
+ },
22
+ set: () => {
23
+ throw new Error('Cannot assign new value to @Storage() property');
24
+ },
25
+ enumerable: true,
26
+ configurable: true
27
+ });
28
+ };
29
+ }
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, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog } from './decorators';
2
+ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage } from './decorators';
3
3
  import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
4
- import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsById, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, RequestMetricsHandler, RequestData, RequestMetrics, HttpServerError } from './protocols';
4
+ import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsById, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, RequestMetricsHandler, RequestData, RequestMetrics, HttpServerError, StorageGateway } 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, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog };
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, StorageGateway, Storage };
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, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog } from './decorators';
2
+ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage } 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';
@@ -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, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog };
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, Storage };
@@ -0,0 +1,5 @@
1
+ export declare abstract class StorageGateway {
2
+ save(file: File, path: string): Promise<void>;
3
+ get(key: string): Promise<void>;
4
+ delete(key: string): Promise<void>;
5
+ }
@@ -0,0 +1,11 @@
1
+ export class StorageGateway {
2
+ save(file, path) {
3
+ throw new Error(this.constructor.name + ' save method not implemented');
4
+ }
5
+ get(key) {
6
+ throw new Error(this.constructor.name + ' get method not implemented');
7
+ }
8
+ delete(key) {
9
+ throw new Error(this.constructor.name + ' delete method not implemented');
10
+ }
11
+ }
@@ -11,4 +11,5 @@ import type { RequestMetricsHandler } from './RequestMetricsHandler';
11
11
  import type { RequestData } from './RequestData';
12
12
  import type { RequestMetrics } from './RequestMetrics';
13
13
  import type { HttpServerError } from './HttpServerError';
14
- export type { RequestData, RequestMetrics, HttpMiddleware, UseCase, Validation, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, RequestMetricsHandler, HttpServerError, ExistsById };
14
+ import type { StorageGateway } from './StorageGateway';
15
+ export type { RequestData, RequestMetrics, HttpMiddleware, UseCase, Validation, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, RequestMetricsHandler, HttpServerError, StorageGateway, ExistsById };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",