@rayondigital/nest-dapr 0.9.13 → 0.9.14

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.
@@ -13,5 +13,5 @@ export declare class StatefulActor extends AbstractActor {
13
13
  getAllState(): Promise<void>;
14
14
  setAllStateFromProperties(): Promise<void>;
15
15
  getState<T>(stateName: string, defaultValue?: T): Promise<T | undefined>;
16
- private createInstance;
16
+ private createStatePropertyInstance;
17
17
  }
@@ -59,18 +59,12 @@ class StatefulActor extends dapr_1.AbstractActor {
59
59
  this[property.key] = property.defaultValue;
60
60
  }
61
61
  else {
62
- this[property.key] = this.createInstance(property.type);
62
+ this[property.key] = this.createStatePropertyInstance(property);
63
63
  }
64
64
  }
65
65
  else {
66
66
  if (property.serializable) {
67
- let instance;
68
- if (typeof property.defaultValue === 'function') {
69
- instance = property.defaultValue();
70
- }
71
- else {
72
- instance = this.createInstance(property.type);
73
- }
67
+ const instance = this.createStatePropertyInstance(property);
74
68
  this[property.key] = (_a = instance.fromJSON(rawValue)) !== null && _a !== void 0 ? _a : instance;
75
69
  }
76
70
  else {
@@ -110,9 +104,18 @@ class StatefulActor extends dapr_1.AbstractActor {
110
104
  }
111
105
  });
112
106
  }
113
- createInstance(type) {
107
+ createStatePropertyInstance(property) {
114
108
  try {
115
- return new type();
109
+ if (property.defaultValue !== undefined) {
110
+ if (property.defaultValue instanceof Function || typeof property.defaultValue === 'function') {
111
+ return property.defaultValue();
112
+ }
113
+ return property.defaultValue;
114
+ }
115
+ if (property.type || property.serializable) {
116
+ const type = property.type;
117
+ return new type();
118
+ }
116
119
  }
117
120
  catch (e) {
118
121
  return undefined;
@@ -3,10 +3,10 @@ export interface StateProperty {
3
3
  key: string | symbol;
4
4
  name: string;
5
5
  type: Function | Type<any>;
6
- defaultValue?: any;
6
+ defaultValue?: (() => any) | Function | Type<any>;
7
7
  serializable?: boolean;
8
8
  }
9
9
  export declare function State(options?: {
10
- defaultValue?: any;
10
+ defaultValue?: (() => any) | Function | Type<any>;
11
11
  name?: string;
12
12
  }): PropertyDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.13",
3
+ "version": "0.9.14",
4
4
  "description": "Develop NestJs microservices using Dapr pubsub, actors and other bindings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",