@rayondigital/nest-dapr 0.9.52 → 0.9.53

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,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
43
50
  }
44
51
  }
45
52
  catch (error) {
46
- console.error(error);
53
+ common_1.Logger.error(error);
47
54
  throw error;
48
55
  }
49
56
  return instance;
@@ -57,6 +64,10 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
57
64
  return;
58
65
  }
59
66
  yield originalDeactivateActor.bind(this)(actorId);
67
+ if (isLoggingEnabled) {
68
+ const actorTypeName = this.actorCls.name;
69
+ common_1.Logger.verbose(`Deactivating actor ${actorId}`, actorTypeName);
70
+ }
60
71
  }
61
72
  catch (error) {
62
73
  common_1.Logger.error(`Error deactivating actor ${actorId}`);
@@ -65,7 +76,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
65
76
  });
66
77
  };
67
78
  }
68
- setupReentrancy() {
79
+ setupReentrancy(options) {
69
80
  ActorClientHTTP_1.default.prototype.invoke = function (actorType, actorId, methodName, body, reentrancyId) {
70
81
  return __awaiter(this, void 0, void 0, function* () {
71
82
  const urlSafeId = actorId.getURLSafeId();
@@ -80,15 +91,21 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
80
91
  });
81
92
  };
82
93
  }
83
- setupCSLWrapper(contextService, invokeWrapperFn) {
94
+ setupCSLWrapper(options, contextService, invokeWrapperFn) {
95
+ var _a, _b;
84
96
  const clsService = contextService.getService();
85
97
  if (!clsService) {
86
98
  throw new Error(`Unable to resolve a CLS from the NestJS DI container`);
87
99
  }
100
+ 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
101
  const originalCallActor = ActorManager_1.default.prototype.callActorMethod;
89
102
  ActorManager_1.default.prototype.callActorMethod = function (actorId, methodName, data) {
90
103
  return __awaiter(this, void 0, void 0, function* () {
91
104
  try {
105
+ if (isLoggingEnabled) {
106
+ const actorTypeName = this.actorCls.name;
107
+ common_1.Logger.verbose(`Invoking ${actorId}/${methodName}`, actorTypeName);
108
+ }
92
109
  if (clsService.isActive()) {
93
110
  if (invokeWrapperFn) {
94
111
  return yield invokeWrapperFn(actorId, methodName, data, originalCallActor.bind(this));
@@ -150,7 +167,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
150
167
  }
151
168
  }
152
169
  catch (error) {
153
- console.error(error);
170
+ common_1.Logger.error(error);
154
171
  throw error;
155
172
  }
156
173
  });
@@ -179,7 +196,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
179
196
  return undefined;
180
197
  }
181
198
  catch (error) {
182
- console.error(error);
199
+ common_1.Logger.error(error);
183
200
  return undefined;
184
201
  }
185
202
  }
@@ -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.53",
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
  },