@rayondigital/nest-dapr 0.9.23 → 0.9.25

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,6 @@ 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 createInstanceFromProperty;
16
17
  private createInstance;
17
18
  }
@@ -47,7 +47,6 @@ class StatefulActor extends abstract_actor_1.AbstractActor {
47
47
  });
48
48
  }
49
49
  getAllState() {
50
- var _a;
51
50
  return __awaiter(this, void 0, void 0, function* () {
52
51
  for (const property of this.stateProperties) {
53
52
  const rawValue = yield this.getState(property.name);
@@ -63,15 +62,9 @@ class StatefulActor extends abstract_actor_1.AbstractActor {
63
62
  }
64
63
  }
65
64
  else {
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
- }
74
- this[property.key] = (_a = instance.fromJSON(rawValue)) !== null && _a !== void 0 ? _a : instance;
65
+ const instance = this.createInstanceFromProperty(property, rawValue);
66
+ if (instance !== undefined) {
67
+ this[property.key] = instance;
75
68
  }
76
69
  else {
77
70
  this[property.key] = rawValue;
@@ -110,6 +103,47 @@ class StatefulActor extends abstract_actor_1.AbstractActor {
110
103
  }
111
104
  });
112
105
  }
106
+ createInstanceFromProperty(property, rawValue) {
107
+ var _a;
108
+ try {
109
+ if (property.serializable) {
110
+ let instance;
111
+ if (typeof property.defaultValue === 'function') {
112
+ instance = property.defaultValue();
113
+ }
114
+ else {
115
+ instance = this.createInstance(property.type);
116
+ }
117
+ if (instance.fromJSON) {
118
+ this[property.key] = (_a = instance.fromJSON(rawValue)) !== null && _a !== void 0 ? _a : instance;
119
+ }
120
+ else {
121
+ this[property.key] = instance;
122
+ for (const key of Object.keys(rawValue)) {
123
+ instance[key] = rawValue[key];
124
+ }
125
+ }
126
+ }
127
+ else {
128
+ let instance;
129
+ if (typeof property.defaultValue === 'function') {
130
+ instance = property.defaultValue();
131
+ }
132
+ else if (property.type) {
133
+ instance = this.createInstance(property.type);
134
+ }
135
+ if (instance !== undefined) {
136
+ for (const key of Object.keys(rawValue)) {
137
+ instance[key] = rawValue[key];
138
+ }
139
+ return instance;
140
+ }
141
+ }
142
+ }
143
+ catch (e) {
144
+ return undefined;
145
+ }
146
+ }
113
147
  createInstance(type) {
114
148
  try {
115
149
  return new type();
@@ -72,12 +72,24 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
72
72
  }
73
73
  }
74
74
  yield this.daprServer.actor.init();
75
+ this.daprServer.daprServer.getServerImpl();
75
76
  this.loadDaprHandlers();
76
77
  if (this.options.serverPort === '0') {
77
78
  this.logger.log('Dapr server will not be started');
78
79
  return;
79
80
  }
80
81
  this.logger.log('Starting Dapr server');
82
+ if (this.options.catchErrors) {
83
+ const server = this.daprServer.daprServer.getServer();
84
+ if (server) {
85
+ server.use((err, req, res, next) => {
86
+ if (err) {
87
+ this.logger.error(err, err.stack, 'DaprServer');
88
+ res.status(500).send(err);
89
+ }
90
+ });
91
+ }
92
+ }
81
93
  yield this.daprServer.start();
82
94
  this.logger.log('Dapr server started');
83
95
  const resRegisteredActors = yield this.daprServer.actor.getRegisteredActors();
@@ -11,6 +11,7 @@ export interface DaprModuleOptions {
11
11
  actorOptions?: DaprModuleActorOptions;
12
12
  disabled?: boolean;
13
13
  contextProvider?: DaprContextProvider;
14
+ catchErrors?: boolean;
14
15
  }
15
16
  export interface DaprModuleActorOptions {
16
17
  prefix?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.23",
3
+ "version": "0.9.25",
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",