@rayondigital/nest-dapr 0.9.12 → 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
  }
@@ -55,19 +55,16 @@ class StatefulActor extends dapr_1.AbstractActor {
55
55
  if (typeof property.defaultValue === 'function') {
56
56
  this[property.key] = property.defaultValue();
57
57
  }
58
- else {
58
+ else if (property.defaultValue !== undefined) {
59
59
  this[property.key] = property.defaultValue;
60
60
  }
61
+ else {
62
+ this[property.key] = this.createStatePropertyInstance(property);
63
+ }
61
64
  }
62
65
  else {
63
66
  if (property.serializable) {
64
- let instance;
65
- if (typeof property.defaultValue === 'function') {
66
- instance = property.defaultValue();
67
- }
68
- else {
69
- instance = this.createInstance(property.type);
70
- }
67
+ const instance = this.createStatePropertyInstance(property);
71
68
  this[property.key] = (_a = instance.fromJSON(rawValue)) !== null && _a !== void 0 ? _a : instance;
72
69
  }
73
70
  else {
@@ -107,8 +104,22 @@ class StatefulActor extends dapr_1.AbstractActor {
107
104
  }
108
105
  });
109
106
  }
110
- createInstance(type) {
111
- return new type();
107
+ createStatePropertyInstance(property) {
108
+ try {
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
+ }
119
+ }
120
+ catch (e) {
121
+ return undefined;
122
+ }
112
123
  }
113
124
  }
114
125
  exports.StatefulActor = StatefulActor;
@@ -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.12",
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",