@rayondigital/nest-dapr 0.9.54 → 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;
|
|
@@ -59,28 +63,8 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
59
63
|
return instance;
|
|
60
64
|
});
|
|
61
65
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
try {
|
|
66
|
-
if (!this.actors.has(actorId.getId())) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
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
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
common_1.Logger.error(`Error deactivating actor ${actorId}`);
|
|
77
|
-
common_1.Logger.error(error);
|
|
78
|
-
if (error.stack) {
|
|
79
|
-
common_1.Logger.error(error.stack);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
66
|
+
this.patchDeactivate(options);
|
|
67
|
+
this.patchToSupportSerializableError(options);
|
|
84
68
|
}
|
|
85
69
|
setupReentrancy(options) {
|
|
86
70
|
ActorClientHTTP_1.default.prototype.invoke = function (actorType, actorId, methodName, body, reentrancyId) {
|
|
@@ -152,6 +136,61 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
152
136
|
});
|
|
153
137
|
};
|
|
154
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
|
+
}
|
|
155
194
|
resolveDependencies(moduleRef, instance) {
|
|
156
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
196
|
const type = instance.constructor;
|
|
@@ -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",
|