@rayondigital/nest-dapr 0.9.63 → 0.9.65

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.
@@ -10,6 +10,7 @@ export declare abstract class AbstractActor {
10
10
  private readonly actorClient;
11
11
  private readonly daprStateProvider;
12
12
  private readonly actorType;
13
+ private readonly stateName;
13
14
  private readonly daprLogger;
14
15
  constructor(daprClient: DaprClient, id: ActorId);
15
16
  registerActorReminder<_Type>(reminderName: string, dueTime: Temporal.Duration, period?: Temporal.Duration, ttl?: Temporal.Duration, state?: any): Promise<void>;
@@ -19,13 +19,14 @@ const polyfill_1 = require("@js-temporal/polyfill");
19
19
  const client_cache_1 = require("./client-cache");
20
20
  class AbstractActor {
21
21
  constructor(daprClient, id) {
22
+ this.actorType = this.constructor.name;
23
+ this.stateName = this.constructor.name;
22
24
  this.daprClient = daprClient;
23
25
  this.actorClient = client_cache_1.DaprClientCache.getOrCreateActorClientFromOptions(daprClient.options);
24
26
  this.daprLogger = new Logger_1.Logger('Actors', 'AbstractActor', daprClient.options.logger);
25
27
  this.id = id;
26
28
  this.stateManager = new ActorStateManager_1.default(this);
27
29
  this.daprStateProvider = client_cache_1.DaprClientCache.getOrCreateStateProviderFromOptions(daprClient.options);
28
- this.actorType = this.constructor.name;
29
30
  }
30
31
  registerActorReminder(reminderName, dueTime, period, ttl, state) {
31
32
  return __awaiter(this, void 0, void 0, function* () {
@@ -134,7 +135,8 @@ class AbstractActor {
134
135
  return this.id;
135
136
  }
136
137
  getActorType() {
137
- return this.actorType;
138
+ var _a;
139
+ return (_a = this.stateName) !== null && _a !== void 0 ? _a : this.actorType;
138
140
  }
139
141
  getId() {
140
142
  return this.getActorId().getId();
@@ -64,7 +64,11 @@ class ActorProxyBuilder {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  const actorManager = this.actorRuntimeService.getActorManager(actorTypeClassName);
66
66
  const requestBody = JSON.stringify(args);
67
- return yield actorManager.invoke(actorId, methodName, Buffer.from(requestBody));
67
+ const result = yield actorManager.invoke(actorId, methodName, Buffer.from(requestBody));
68
+ if (serializable_error_1.SerializableError.isSerializableError(result)) {
69
+ throw serializable_error_1.SerializableError.fromJSON(result);
70
+ }
71
+ return result;
68
72
  });
69
73
  }
70
74
  callExternalActorMethod(actorTypeClassName, actorId, methodName, args) {
@@ -78,7 +82,10 @@ class ActorProxyBuilder {
78
82
  const body = yield this.prepareBody(this.daprContextService, args, originalBody);
79
83
  const result = yield this.actorClient.actor.invoke(actorTypeClassName, actorId, methodName, body, correlationId, traceId);
80
84
  if (serializable_error_1.SerializableError.isSerializableError(result)) {
81
- throw serializable_error_1.SerializableError.fromJSON(result);
85
+ const error = serializable_error_1.SerializableError.fromJSON(result);
86
+ error.correlationId = correlationId;
87
+ error.traceId = traceId;
88
+ throw error;
82
89
  }
83
90
  return result;
84
91
  });
@@ -161,10 +161,10 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
161
161
  actor_1.default.prototype.handlerMethod = function (req, res) {
162
162
  var _a;
163
163
  return __awaiter(this, void 0, void 0, function* () {
164
- const { actorTypeName, actorId, methodName } = req.params;
165
- const body = req.body;
166
- const dataSerialized = this.serializer.serialize(body);
167
164
  try {
165
+ const { actorTypeName, actorId, methodName } = req.params;
166
+ const body = req.body;
167
+ const dataSerialized = this.serializer.serialize(body);
168
168
  const result = yield ActorRuntime_1.default.getInstance(this.client.daprClient).invoke(actorTypeName, actorId, methodName, dataSerialized);
169
169
  res.statusCode = HttpStatusCode_enum_1.default.OK;
170
170
  return this.handleResult(res, result);
@@ -1,11 +1,17 @@
1
1
  export declare class SerializableError extends Error {
2
2
  statusCode: number;
3
3
  $type: string;
4
+ correlationId?: string;
5
+ traceId?: string;
4
6
  constructor(message: string, statusCode?: number);
5
7
  toJSON(): {
6
8
  name: string;
7
9
  message: string;
8
10
  statusCode: number;
11
+ correlationId: string;
12
+ traceId: string;
13
+ stack: string;
14
+ $type: string;
9
15
  };
10
16
  static fromJSON(json: any): SerializableError;
11
17
  static isSerializableError(error: any): error is SerializableError;
@@ -1,21 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SerializableError = void 0;
4
+ const serializableErrorTypeName = 'SerializableError';
4
5
  class SerializableError extends Error {
5
6
  constructor(message, statusCode = 400) {
6
7
  super(message);
7
8
  this.statusCode = statusCode;
8
- this.$type = 'SerializableError';
9
+ this.$type = serializableErrorTypeName;
9
10
  }
10
11
  toJSON() {
12
+ if (!this.stack) {
13
+ Error.captureStackTrace(this, SerializableError);
14
+ }
11
15
  return {
12
16
  name: this.name,
13
17
  message: this.message,
14
18
  statusCode: this.statusCode,
19
+ correlationId: this.correlationId,
20
+ traceId: this.traceId,
21
+ stack: this.stack,
22
+ $type: serializableErrorTypeName,
15
23
  };
16
24
  }
17
25
  static fromJSON(json) {
18
- return new SerializableError(json.message, json.statusCode);
26
+ var _a;
27
+ const error = new SerializableError(json.message, json.statusCode);
28
+ error.$type = (_a = json.$type) !== null && _a !== void 0 ? _a : serializableErrorTypeName;
29
+ error.correlationId = json.correlationId;
30
+ error.traceId = json.traceId;
31
+ error.stack = json.stack;
32
+ error.name = json.name;
33
+ return error;
19
34
  }
20
35
  static isSerializableError(error) {
21
36
  if (error instanceof SerializableError) {
@@ -2,5 +2,7 @@ import { Type } from '@nestjs/common';
2
2
  export interface DaprActorMetadata {
3
3
  interfaceType: Type<any> | Function;
4
4
  name?: string;
5
+ stateName?: string;
5
6
  }
6
7
  export declare function DaprActor(options: DaprActorMetadata): ClassDecorator;
8
+ export declare function getActorMetadata(target: Type<any>): DaprActorMetadata;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DaprActor = void 0;
3
+ exports.getActorMetadata = exports.DaprActor = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const constants_1 = require("./constants");
6
6
  function DaprActor(options) {
@@ -8,9 +8,14 @@ function DaprActor(options) {
8
8
  var _a;
9
9
  (0, common_1.SetMetadata)(constants_1.DAPR_ACTOR_METADATA, {
10
10
  name: (_a = options.name) !== null && _a !== void 0 ? _a : target.constructor.name,
11
+ stateName: options.stateName,
11
12
  interfaceType: options.interfaceType,
12
13
  })(target);
13
14
  (0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT })(target);
14
15
  };
15
16
  }
16
17
  exports.DaprActor = DaprActor;
18
+ function getActorMetadata(target) {
19
+ return Reflect.getMetadata(constants_1.DAPR_ACTOR_METADATA, target);
20
+ }
21
+ exports.getActorMetadata = getActorMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.63",
3
+ "version": "0.9.65",
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",