@rayondigital/nest-dapr 0.9.53 → 0.9.55
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.
|
@@ -6,6 +6,8 @@ export declare class NestActorManager {
|
|
|
6
6
|
setup(moduleRef: ModuleRef, options: DaprModuleOptions, onActivateFn?: (actorId: ActorId, instance: AbstractActor) => Promise<void>): void;
|
|
7
7
|
setupReentrancy(options: DaprModuleOptions): void;
|
|
8
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
|
+
private patchToSupportSerializableError;
|
|
10
|
+
private patchDeactivate;
|
|
9
11
|
private resolveDependencies;
|
|
10
12
|
private static extractContext;
|
|
11
13
|
}
|
|
@@ -23,9 +23,13 @@ exports.NestActorManager = void 0;
|
|
|
23
23
|
const crypto_1 = require("crypto");
|
|
24
24
|
const ActorClientHTTP_1 = __importDefault(require("@dapr/dapr/actors/client/ActorClient/ActorClientHTTP"));
|
|
25
25
|
const ActorManager_1 = __importDefault(require("@dapr/dapr/actors/runtime/ActorManager"));
|
|
26
|
+
const ActorRuntime_1 = __importDefault(require("@dapr/dapr/actors/runtime/ActorRuntime"));
|
|
27
|
+
const HttpStatusCode_enum_1 = __importDefault(require("@dapr/dapr/enum/HttpStatusCode.enum"));
|
|
28
|
+
const actor_1 = __importDefault(require("@dapr/dapr/implementation/Server/HTTPServer/actor"));
|
|
26
29
|
const common_1 = require("@nestjs/common");
|
|
27
30
|
const instance_wrapper_1 = require("@nestjs/core/injector/instance-wrapper");
|
|
28
31
|
const dapr_context_service_1 = require("../dapr-context-service");
|
|
32
|
+
const serializable_error_1 = require("./serializable-error");
|
|
29
33
|
let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
30
34
|
setup(moduleRef, options, onActivateFn) {
|
|
31
35
|
var _a, _b;
|
|
@@ -51,30 +55,16 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
51
55
|
}
|
|
52
56
|
catch (error) {
|
|
53
57
|
common_1.Logger.error(error);
|
|
58
|
+
if (error.stack) {
|
|
59
|
+
common_1.Logger.error(error.stack);
|
|
60
|
+
}
|
|
54
61
|
throw error;
|
|
55
62
|
}
|
|
56
63
|
return instance;
|
|
57
64
|
});
|
|
58
65
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
try {
|
|
63
|
-
if (!this.actors.has(actorId.getId())) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
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
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
common_1.Logger.error(`Error deactivating actor ${actorId}`);
|
|
74
|
-
common_1.Logger.error(error);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
66
|
+
this.patchDeactivate(options);
|
|
67
|
+
this.patchToSupportSerializableError(options);
|
|
78
68
|
}
|
|
79
69
|
setupReentrancy(options) {
|
|
80
70
|
ActorClientHTTP_1.default.prototype.invoke = function (actorType, actorId, methodName, body, reentrancyId) {
|
|
@@ -138,11 +128,69 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
138
128
|
catch (error) {
|
|
139
129
|
common_1.Logger.error(`Error invoking actor method ${actorId}/${methodName}`);
|
|
140
130
|
common_1.Logger.error(error);
|
|
131
|
+
if (error.stack) {
|
|
132
|
+
common_1.Logger.error(error.stack);
|
|
133
|
+
}
|
|
141
134
|
throw error;
|
|
142
135
|
}
|
|
143
136
|
});
|
|
144
137
|
};
|
|
145
138
|
}
|
|
139
|
+
patchToSupportSerializableError(options) {
|
|
140
|
+
const originalHandlerMethod = actor_1.default.prototype.handlerMethod;
|
|
141
|
+
if (!originalHandlerMethod)
|
|
142
|
+
return;
|
|
143
|
+
actor_1.default.prototype.handlerMethod = function (req, res) {
|
|
144
|
+
var _a;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const { actorTypeName, actorId, methodName } = req.params;
|
|
147
|
+
const body = req.body;
|
|
148
|
+
const dataSerialized = this.serializer.serialize(body);
|
|
149
|
+
try {
|
|
150
|
+
const result = yield ActorRuntime_1.default.getInstance(this.client.daprClient).invoke(actorTypeName, actorId, methodName, dataSerialized);
|
|
151
|
+
res.statusCode = HttpStatusCode_enum_1.default.OK;
|
|
152
|
+
return this.handleResult(res, result);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error instanceof serializable_error_1.SerializableError) {
|
|
156
|
+
error.statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : HttpStatusCode_enum_1.default.BAD_REQUEST;
|
|
157
|
+
}
|
|
158
|
+
else if (error instanceof Error) {
|
|
159
|
+
res.statusCode = HttpStatusCode_enum_1.default.INTERNAL_SERVER_ERROR;
|
|
160
|
+
}
|
|
161
|
+
return this.handleResult(res, error);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
patchDeactivate(options) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
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;
|
|
169
|
+
const originalDeactivateActor = ActorManager_1.default.prototype.deactivateActor;
|
|
170
|
+
if (!originalDeactivateActor)
|
|
171
|
+
return;
|
|
172
|
+
ActorManager_1.default.prototype.deactivateActor = function (actorId) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
try {
|
|
175
|
+
if (!this.actors.has(actorId.getId())) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
yield originalDeactivateActor.bind(this)(actorId);
|
|
179
|
+
if (isLoggingEnabled) {
|
|
180
|
+
const actorTypeName = this.actorCls.name;
|
|
181
|
+
common_1.Logger.verbose(`Deactivating actor ${actorId}`, actorTypeName);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
common_1.Logger.error(`Error deactivating actor ${actorId}`);
|
|
186
|
+
common_1.Logger.error(error);
|
|
187
|
+
if (error.stack) {
|
|
188
|
+
common_1.Logger.error(error.stack);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
}
|
|
146
194
|
resolveDependencies(moduleRef, instance) {
|
|
147
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
196
|
const type = instance.constructor;
|
|
@@ -168,6 +216,9 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
168
216
|
}
|
|
169
217
|
catch (error) {
|
|
170
218
|
common_1.Logger.error(error);
|
|
219
|
+
if (error.stack) {
|
|
220
|
+
common_1.Logger.error(error.stack);
|
|
221
|
+
}
|
|
171
222
|
throw error;
|
|
172
223
|
}
|
|
173
224
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializableError = void 0;
|
|
4
|
+
class SerializableError extends Error {
|
|
5
|
+
constructor(message, statusCode = 400) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
}
|
|
9
|
+
toJSON() {
|
|
10
|
+
return {
|
|
11
|
+
name: this.name,
|
|
12
|
+
message: this.message,
|
|
13
|
+
statusCode: this.statusCode,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.SerializableError = SerializableError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ActorRuntimeService } from './actors/actor-runtime.service';
|
|
2
2
|
import { DaprClientCache } from './actors/client-cache';
|
|
3
3
|
import { DaprActorClient } from './actors/dapr-actor-client.service';
|
|
4
|
+
import { SerializableError } from './actors/serializable-error';
|
|
4
5
|
import { StatefulActorOf } from './actors/stateful-actor-of';
|
|
5
6
|
import { IState, StatefulActor } from './actors/stateful.actor';
|
|
6
7
|
import { DAPR_BINDING_METADATA, DAPR_PUBSUB_METADATA, DAPR_ACTOR_METADATA, DAPR_ACTOR_STATE_METADATA } from './constants';
|
|
@@ -14,4 +15,4 @@ import { DaprPubSub, DaprPubSubMetadata } from './dapr-pubsub.decorator';
|
|
|
14
15
|
import { DaprLoader } from './dapr.loader';
|
|
15
16
|
import { DaprContextProvider, DaprModule } from './dapr.module';
|
|
16
17
|
import { DaprPubSubClient } from './pubsub/dapr-pubsub-client.service';
|
|
17
|
-
export { DAPR_BINDING_METADATA, DAPR_PUBSUB_METADATA, DAPR_ACTOR_METADATA, DAPR_ACTOR_STATE_METADATA, DaprMetadataAccessor, DaprBindingMetadata, DaprBinding, DaprPubSubMetadata, DaprPubSub, DaprActorMetadata, State, DaprActor, DaprLoader, DaprModule, DaprActorClient, DaprContextService, DaprContextProvider, ActorRuntimeService, DaprPubSubClient, DaprClientCache, DaprEventEmitter, StatefulActor, StatefulActorOf, IState, };
|
|
18
|
+
export { DAPR_BINDING_METADATA, DAPR_PUBSUB_METADATA, DAPR_ACTOR_METADATA, DAPR_ACTOR_STATE_METADATA, DaprMetadataAccessor, DaprBindingMetadata, DaprBinding, DaprPubSubMetadata, DaprPubSub, DaprActorMetadata, State, DaprActor, DaprLoader, DaprModule, DaprActorClient, DaprContextService, DaprContextProvider, ActorRuntimeService, DaprPubSubClient, DaprClientCache, DaprEventEmitter, StatefulActor, StatefulActorOf, IState, SerializableError, };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatefulActorOf = exports.StatefulActor = exports.DaprEventEmitter = exports.DaprClientCache = exports.DaprPubSubClient = exports.ActorRuntimeService = exports.DaprContextProvider = exports.DaprContextService = exports.DaprActorClient = exports.DaprModule = exports.DaprLoader = exports.DaprActor = exports.State = exports.DaprPubSub = exports.DaprBinding = exports.DaprMetadataAccessor = exports.DAPR_ACTOR_STATE_METADATA = exports.DAPR_ACTOR_METADATA = exports.DAPR_PUBSUB_METADATA = exports.DAPR_BINDING_METADATA = void 0;
|
|
3
|
+
exports.SerializableError = exports.StatefulActorOf = exports.StatefulActor = exports.DaprEventEmitter = exports.DaprClientCache = exports.DaprPubSubClient = exports.ActorRuntimeService = exports.DaprContextProvider = exports.DaprContextService = exports.DaprActorClient = exports.DaprModule = exports.DaprLoader = exports.DaprActor = exports.State = exports.DaprPubSub = exports.DaprBinding = exports.DaprMetadataAccessor = exports.DAPR_ACTOR_STATE_METADATA = exports.DAPR_ACTOR_METADATA = exports.DAPR_PUBSUB_METADATA = exports.DAPR_BINDING_METADATA = void 0;
|
|
4
4
|
const actor_runtime_service_1 = require("./actors/actor-runtime.service");
|
|
5
5
|
Object.defineProperty(exports, "ActorRuntimeService", { enumerable: true, get: function () { return actor_runtime_service_1.ActorRuntimeService; } });
|
|
6
6
|
const client_cache_1 = require("./actors/client-cache");
|
|
7
7
|
Object.defineProperty(exports, "DaprClientCache", { enumerable: true, get: function () { return client_cache_1.DaprClientCache; } });
|
|
8
8
|
const dapr_actor_client_service_1 = require("./actors/dapr-actor-client.service");
|
|
9
9
|
Object.defineProperty(exports, "DaprActorClient", { enumerable: true, get: function () { return dapr_actor_client_service_1.DaprActorClient; } });
|
|
10
|
+
const serializable_error_1 = require("./actors/serializable-error");
|
|
11
|
+
Object.defineProperty(exports, "SerializableError", { enumerable: true, get: function () { return serializable_error_1.SerializableError; } });
|
|
10
12
|
const stateful_actor_of_1 = require("./actors/stateful-actor-of");
|
|
11
13
|
Object.defineProperty(exports, "StatefulActorOf", { enumerable: true, get: function () { return stateful_actor_of_1.StatefulActorOf; } });
|
|
12
14
|
const stateful_actor_1 = require("./actors/stateful.actor");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rayondigital/nest-dapr",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.55",
|
|
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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@nestjs/common": "^10.0.0",
|
|
26
26
|
"@nestjs/core": "^10.0.0",
|
|
27
|
-
"nestjs-cls": "^3.
|
|
27
|
+
"nestjs-cls": "^3.4.0",
|
|
28
28
|
"rxjs": "^7.1.0",
|
|
29
29
|
"eventemitter2": "^6.0.0"
|
|
30
30
|
},
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"typescript": "^4.7.4"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"nestjs-cls": "^3.
|
|
54
|
+
"nestjs-cls": "^3.4.0"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public",
|