framework-do-dede 1.0.22 → 1.0.23
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 +1 @@
|
|
|
1
|
-
export declare function Storage(): (target: any, propertyKey: string) => void;
|
|
1
|
+
export declare function Storage(gatewayName: string): (target: any, propertyKey: string) => void;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Registry } from "../di/registry";
|
|
2
2
|
import { StorageGateway } from "../protocols/StorageGateway";
|
|
3
|
-
export function Storage() {
|
|
3
|
+
export function Storage(gatewayName) {
|
|
4
4
|
return function (target, propertyKey) {
|
|
5
|
-
|
|
6
|
-
if (!(designType?.prototype instanceof StorageGateway)) {
|
|
7
|
-
throw new Error(`@Storage() can only be used with StorageGateway subclasses`);
|
|
8
|
-
}
|
|
9
|
-
const gatewayName = designType.name;
|
|
5
|
+
// Verifica se a classe está registrada
|
|
10
6
|
if (!Registry.has(gatewayName)) {
|
|
11
7
|
throw new Error(`StorageGateway ${gatewayName} not registered`);
|
|
12
8
|
}
|
|
9
|
+
const GatewayClass = Registry.resolve(gatewayName);
|
|
10
|
+
// Valida se a classe registrada é uma subclasse de StorageGateway
|
|
11
|
+
if (!(GatewayClass instanceof StorageGateway)) {
|
|
12
|
+
throw new Error(`${gatewayName} is not a valid StorageGateway`);
|
|
13
|
+
}
|
|
13
14
|
const instanceSymbol = Symbol();
|
|
14
15
|
Object.defineProperty(target, propertyKey, {
|
|
15
16
|
get: function () {
|
|
16
17
|
if (!this[instanceSymbol]) {
|
|
17
|
-
const GatewayClass = Registry.resolve(gatewayName);
|
|
18
18
|
this[instanceSymbol] = GatewayClass;
|
|
19
19
|
}
|
|
20
20
|
return this[instanceSymbol];
|