@rayondigital/nest-dapr 0.9.52 → 0.9.54

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.
@@ -1,11 +1,11 @@
1
1
  import { AbstractActor, ActorId } from '@dapr/dapr';
2
2
  import { ModuleRef } from '@nestjs/core';
3
3
  import { DaprContextService } from '../dapr-context-service';
4
- import { DaprModuleActorOptions } from '../dapr.module';
4
+ import { DaprModuleOptions } from '../dapr.module';
5
5
  export declare class NestActorManager {
6
- setup(moduleRef: ModuleRef, options: DaprModuleActorOptions, onActivateFn?: (actorId: ActorId, instance: AbstractActor) => Promise<void>): void;
7
- setupReentrancy(): void;
8
- setupCSLWrapper(contextService: DaprContextService, invokeWrapperFn?: (actorId: ActorId, methodName: string, data: any, method: (actorId: ActorId, methodName: string, data: any) => Promise<any>) => Promise<any>): void;
6
+ setup(moduleRef: ModuleRef, options: DaprModuleOptions, onActivateFn?: (actorId: ActorId, instance: AbstractActor) => Promise<void>): void;
7
+ setupReentrancy(options: DaprModuleOptions): void;
8
+ setupCSLWrapper(options: DaprModuleOptions, contextService: DaprContextService, invokeWrapperFn?: (actorId: ActorId, methodName: string, data: any, method: (actorId: ActorId, methodName: string, data: any) => Promise<any>) => Promise<any>): void;
9
9
  private resolveDependencies;
10
10
  private static extractContext;
11
11
  }
@@ -28,14 +28,21 @@ const instance_wrapper_1 = require("@nestjs/core/injector/instance-wrapper");
28
28
  const dapr_context_service_1 = require("../dapr-context-service");
29
29
  let NestActorManager = NestActorManager_1 = class NestActorManager {
30
30
  setup(moduleRef, options, onActivateFn) {
31
+ var _a, _b;
32
+ const isLoggingEnabled = (_b = (_a = options === null || options === void 0 ? void 0 : options.logging) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
31
33
  const originalCreateActor = ActorManager_1.default.prototype.createActor;
32
34
  const resolveDependencies = this.resolveDependencies;
33
35
  ActorManager_1.default.prototype.createActor = function (actorId) {
36
+ var _a, _b;
34
37
  return __awaiter(this, void 0, void 0, function* () {
35
38
  const instance = (yield originalCreateActor.bind(this)(actorId));
36
- if (options === null || options === void 0 ? void 0 : options.typeNamePrefix) {
39
+ if ((_a = options === null || options === void 0 ? void 0 : options.actorOptions) === null || _a === void 0 ? void 0 : _a.typeNamePrefix) {
37
40
  instance['actorType'] = `${options.typeNamePrefix}${instance.actorType}`;
38
41
  }
42
+ if (isLoggingEnabled) {
43
+ const actorTypeName = (_b = this.actorCls.name) !== null && _b !== void 0 ? _b : instance.constructor.name;
44
+ common_1.Logger.verbose(`Activating actor ${actorId}`, actorTypeName);
45
+ }
39
46
  try {
40
47
  yield resolveDependencies(moduleRef, instance);
41
48
  if (onActivateFn) {
@@ -43,7 +50,10 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
43
50
  }
44
51
  }
45
52
  catch (error) {
46
- console.error(error);
53
+ common_1.Logger.error(error);
54
+ if (error.stack) {
55
+ common_1.Logger.error(error.stack);
56
+ }
47
57
  throw error;
48
58
  }
49
59
  return instance;
@@ -57,15 +67,22 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
57
67
  return;
58
68
  }
59
69
  yield originalDeactivateActor.bind(this)(actorId);
70
+ if (isLoggingEnabled) {
71
+ const actorTypeName = this.actorCls.name;
72
+ common_1.Logger.verbose(`Deactivating actor ${actorId}`, actorTypeName);
73
+ }
60
74
  }
61
75
  catch (error) {
62
76
  common_1.Logger.error(`Error deactivating actor ${actorId}`);
63
77
  common_1.Logger.error(error);
78
+ if (error.stack) {
79
+ common_1.Logger.error(error.stack);
80
+ }
64
81
  }
65
82
  });
66
83
  };
67
84
  }
68
- setupReentrancy() {
85
+ setupReentrancy(options) {
69
86
  ActorClientHTTP_1.default.prototype.invoke = function (actorType, actorId, methodName, body, reentrancyId) {
70
87
  return __awaiter(this, void 0, void 0, function* () {
71
88
  const urlSafeId = actorId.getURLSafeId();
@@ -80,15 +97,21 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
80
97
  });
81
98
  };
82
99
  }
83
- setupCSLWrapper(contextService, invokeWrapperFn) {
100
+ setupCSLWrapper(options, contextService, invokeWrapperFn) {
101
+ var _a, _b;
84
102
  const clsService = contextService.getService();
85
103
  if (!clsService) {
86
104
  throw new Error(`Unable to resolve a CLS from the NestJS DI container`);
87
105
  }
106
+ const isLoggingEnabled = (_b = (_a = options === null || options === void 0 ? void 0 : options.logging) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
88
107
  const originalCallActor = ActorManager_1.default.prototype.callActorMethod;
89
108
  ActorManager_1.default.prototype.callActorMethod = function (actorId, methodName, data) {
90
109
  return __awaiter(this, void 0, void 0, function* () {
91
110
  try {
111
+ if (isLoggingEnabled) {
112
+ const actorTypeName = this.actorCls.name;
113
+ common_1.Logger.verbose(`Invoking ${actorId}/${methodName}`, actorTypeName);
114
+ }
92
115
  if (clsService.isActive()) {
93
116
  if (invokeWrapperFn) {
94
117
  return yield invokeWrapperFn(actorId, methodName, data, originalCallActor.bind(this));
@@ -121,6 +144,9 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
121
144
  catch (error) {
122
145
  common_1.Logger.error(`Error invoking actor method ${actorId}/${methodName}`);
123
146
  common_1.Logger.error(error);
147
+ if (error.stack) {
148
+ common_1.Logger.error(error.stack);
149
+ }
124
150
  throw error;
125
151
  }
126
152
  });
@@ -150,7 +176,10 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
150
176
  }
151
177
  }
152
178
  catch (error) {
153
- console.error(error);
179
+ common_1.Logger.error(error);
180
+ if (error.stack) {
181
+ common_1.Logger.error(error.stack);
182
+ }
154
183
  throw error;
155
184
  }
156
185
  });
@@ -179,7 +208,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
179
208
  return undefined;
180
209
  }
181
210
  catch (error) {
182
- console.error(error);
211
+ common_1.Logger.error(error);
183
212
  return undefined;
184
213
  }
185
214
  }
@@ -58,12 +58,12 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
58
58
  this.logger.log('Dapr server is disabled');
59
59
  return;
60
60
  }
61
- this.actorManager.setup(this.moduleRef, this.options.actorOptions);
61
+ this.actorManager.setup(this.moduleRef, this.options);
62
62
  if (this.options.contextProvider !== dapr_module_1.DaprContextProvider.None) {
63
- this.actorManager.setupCSLWrapper(this.contextService);
63
+ this.actorManager.setupCSLWrapper(this.options, this.contextService);
64
64
  }
65
65
  if ((_c = (_b = (_a = this.options.clientOptions) === null || _a === void 0 ? void 0 : _a.actor) === null || _b === void 0 ? void 0 : _b.reentrancy) === null || _c === void 0 ? void 0 : _c.enabled) {
66
- this.actorManager.setupReentrancy();
66
+ this.actorManager.setupReentrancy(this.options);
67
67
  }
68
68
  if ((_d = this.options.pubsubOptions) === null || _d === void 0 ? void 0 : _d.defaultName) {
69
69
  this.pubSubClient.setDefaultName(this.options.pubsubOptions.defaultName);
@@ -11,8 +11,12 @@ export interface DaprModuleOptions {
11
11
  pubsubOptions?: DaprModulePubSubOptions;
12
12
  disabled?: boolean;
13
13
  contextProvider?: DaprContextProvider;
14
+ logging?: DaprModuleLoggingOptions;
14
15
  catchErrors?: boolean;
15
16
  }
17
+ export interface DaprModuleLoggingOptions {
18
+ enabled: boolean;
19
+ }
16
20
  export interface DaprModuleActorOptions {
17
21
  prefix?: string;
18
22
  delimiter?: string;
@@ -25,11 +25,11 @@ const actor_runtime_service_1 = require("./actors/actor-runtime.service");
25
25
  const dapr_actor_client_service_1 = require("./actors/dapr-actor-client.service");
26
26
  const nest_actor_manager_1 = require("./actors/nest-actor-manager");
27
27
  const dapr_context_service_1 = require("./dapr-context-service");
28
+ const dapr_event_emitter_service_1 = require("./dapr-event-emitter.service");
28
29
  const dapr_event_subscriber_loader_1 = require("./dapr-event-subscriber.loader");
29
30
  const dapr_metadata_accessor_1 = require("./dapr-metadata.accessor");
30
31
  const dapr_loader_1 = require("./dapr.loader");
31
32
  const dapr_pubsub_client_service_1 = require("./pubsub/dapr-pubsub-client.service");
32
- const dapr_event_emitter_service_1 = require("./dapr-event-emitter.service");
33
33
  exports.DAPR_MODULE_OPTIONS_TOKEN = 'DAPR_MODULE_OPTIONS_TOKEN';
34
34
  var DaprContextProvider;
35
35
  (function (DaprContextProvider) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.52",
3
+ "version": "0.9.54",
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",
@@ -35,18 +35,18 @@
35
35
  "devDependencies": {
36
36
  "@nestjs/platform-express": "^10.0.0",
37
37
  "@nestjs/testing": "^10.0.0",
38
- "@types/jest": "^29.5.7",
38
+ "@types/jest": "^29.5.12",
39
39
  "@typescript-eslint/eslint-plugin": "^5.29.0",
40
40
  "eslint": "^8.4.1",
41
41
  "eslint-config-prettier": "^8.3.0",
42
42
  "eslint-plugin-import": "^2.25.4",
43
- "eslint-plugin-jest": "^27.6.0",
43
+ "eslint-plugin-jest": "^27.9.0",
44
44
  "eslint-plugin-prettier": "^4.0.0",
45
45
  "eslint-plugin-promise": "^6.0.0",
46
46
  "jest": "^29.7.0",
47
47
  "nodemon": "^3.0.1",
48
48
  "rimraf": "^3.0.2",
49
- "ts-jest": "^29.0.3",
49
+ "ts-jest": "^29.1.2",
50
50
  "ts-node": "^10.9.1",
51
51
  "typescript": "^4.7.4"
52
52
  },