framework-do-dede 1.0.27 → 1.0.29

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,28 +2,28 @@ import { Registry } from "../di/registry";
2
2
  import { StorageGateway } from "../protocols/StorageGateway";
3
3
  export function Storage(gatewayName) {
4
4
  return function (target, propertyKey) {
5
- // Verifica se a classe está registrada
6
- if (!Registry.has(gatewayName)) {
7
- throw new Error(`StorageGateway ${gatewayName} not registered`);
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
- }
14
- const instanceSymbol = Symbol();
15
- Object.defineProperty(target, propertyKey, {
16
- get: function () {
17
- if (!this[instanceSymbol]) {
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
5
+ Registry.whenLoaded(() => {
6
+ if (!Registry.has(gatewayName)) {
7
+ throw new Error(`StorageGateway ${gatewayName} not registered`);
8
+ }
9
+ const GatewayClass = Registry.resolve(gatewayName);
10
+ if (!(GatewayClass instanceof StorageGateway)) {
11
+ throw new Error(`${gatewayName} is not a valid StorageGateway`);
12
+ }
13
+ const instanceSymbol = Symbol();
14
+ Object.defineProperty(target, propertyKey, {
15
+ get: function () {
16
+ if (!this[instanceSymbol]) {
17
+ this[instanceSymbol] = GatewayClass;
18
+ }
19
+ return this[instanceSymbol];
20
+ },
21
+ set: () => {
22
+ throw new Error('Cannot assign new value to @Storage() property');
23
+ },
24
+ enumerable: true,
25
+ configurable: true
26
+ });
27
27
  });
28
28
  };
29
29
  }
package/dist/dede.js CHANGED
@@ -29,5 +29,6 @@ export class Dede {
29
29
  else
30
30
  Registry.register(name, classLoader);
31
31
  });
32
+ Registry.loaded();
32
33
  }
33
34
  }
@@ -2,6 +2,7 @@ import 'reflect-metadata';
2
2
  declare class ComponentRegistry {
3
3
  private static instance;
4
4
  private dependencies;
5
+ private isLoading;
5
6
  static getInstance(): ComponentRegistry;
6
7
  register(token: string, dependency: any): void;
7
8
  has(token: string): boolean;
@@ -10,6 +11,8 @@ declare class ComponentRegistry {
10
11
  clear(token: string): void;
11
12
  classLoader<T>(target: new (...args: any[]) => T): T;
12
13
  inject(token: string): (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
14
+ loaded(): void;
15
+ whenLoaded(callback: () => void): void;
13
16
  }
14
17
  export declare const Registry: ComponentRegistry;
15
18
  export {};
@@ -3,6 +3,7 @@ import 'reflect-metadata';
3
3
  class ComponentRegistry {
4
4
  static instance;
5
5
  dependencies = new Map();
6
+ isLoading = true;
6
7
  static getInstance() {
7
8
  if (!this.instance) {
8
9
  this.instance = new ComponentRegistry();
@@ -43,5 +44,14 @@ class ComponentRegistry {
43
44
  inject(token) {
44
45
  return Inject(token);
45
46
  }
47
+ loaded() {
48
+ this.isLoading = false;
49
+ }
50
+ whenLoaded(callback) {
51
+ while (this.isLoading) {
52
+ setTimeout(callback, 100);
53
+ }
54
+ callback();
55
+ }
46
56
  }
47
57
  export const Registry = ComponentRegistry.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",