@rayondigital/nest-dapr 0.9.3 → 0.9.4
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,12 +1,16 @@
|
|
|
1
|
-
import { DaprClient } from '@dapr/dapr';
|
|
1
|
+
import { ActorId, DaprClient } from '@dapr/dapr';
|
|
2
2
|
import { Type } from '@nestjs/common';
|
|
3
3
|
export declare class DaprActorClient {
|
|
4
4
|
private readonly daprClient;
|
|
5
5
|
private actorClients;
|
|
6
6
|
private interfaces;
|
|
7
|
+
private prefix;
|
|
8
|
+
private delimiter;
|
|
7
9
|
constructor(daprClient: DaprClient);
|
|
10
|
+
setPrefix(prefix: string, delimiter?: string): void;
|
|
8
11
|
register<T>(actorTypeName: string, actorType: Type<T> | Function, daprClient?: DaprClient): void;
|
|
9
12
|
registerInterface<T>(actorType: Type<T> | Function, interfaceType: Type<T> | Function, daprClient?: DaprClient): void;
|
|
13
|
+
getActorId(actorId: string): ActorId;
|
|
10
14
|
getActor<TActorInterface>(actorType: Type<TActorInterface> | Function, actorId: string): TActorInterface;
|
|
11
15
|
getActorByTypeName<TActorInterface>(actorTypeName: string, actorId: string): TActorInterface;
|
|
12
16
|
contains(actorTypeName: string): boolean;
|
|
@@ -17,6 +17,12 @@ let DaprActorClient = class DaprActorClient {
|
|
|
17
17
|
this.daprClient = daprClient;
|
|
18
18
|
this.actorClients = new Map();
|
|
19
19
|
this.interfaces = new Map();
|
|
20
|
+
this.prefix = '';
|
|
21
|
+
this.delimiter = '-';
|
|
22
|
+
}
|
|
23
|
+
setPrefix(prefix, delimiter = '-') {
|
|
24
|
+
this.prefix = prefix;
|
|
25
|
+
this.delimiter = delimiter;
|
|
20
26
|
}
|
|
21
27
|
register(actorTypeName, actorType, daprClient) {
|
|
22
28
|
this.interfaces.set(this.formatActorTypeName(actorTypeName), actorType);
|
|
@@ -28,6 +34,13 @@ let DaprActorClient = class DaprActorClient {
|
|
|
28
34
|
this.interfaces.set(this.formatActorTypeName(interfaceTypeName), actorType);
|
|
29
35
|
this.actorClients.set(this.formatActorTypeName(interfaceTypeName), new dapr_1.ActorProxyBuilder(actorType, daprClient !== null && daprClient !== void 0 ? daprClient : this.daprClient));
|
|
30
36
|
}
|
|
37
|
+
getActorId(actorId) {
|
|
38
|
+
var _a;
|
|
39
|
+
if (this.prefix) {
|
|
40
|
+
return new dapr_1.ActorId(`${this.prefix}${(_a = this.delimiter) !== null && _a !== void 0 ? _a : '-'}${actorId}`);
|
|
41
|
+
}
|
|
42
|
+
return new dapr_1.ActorId(actorId);
|
|
43
|
+
}
|
|
31
44
|
getActor(actorType, actorId) {
|
|
32
45
|
var _a;
|
|
33
46
|
const actorTypeName = (_a = actorType.name) !== null && _a !== void 0 ? _a : actorType.constructor.name;
|
|
@@ -38,7 +51,8 @@ let DaprActorClient = class DaprActorClient {
|
|
|
38
51
|
throw new Error(`Actor ${actorTypeName} not found`);
|
|
39
52
|
}
|
|
40
53
|
const actorClient = this.getActorClient(actorTypeName);
|
|
41
|
-
|
|
54
|
+
const fullActorId = this.getActorId(actorId);
|
|
55
|
+
return actorClient.build(fullActorId);
|
|
42
56
|
}
|
|
43
57
|
getActorByTypeName(actorTypeName, actorId) {
|
|
44
58
|
if (!actorTypeName) {
|
|
@@ -48,7 +62,8 @@ let DaprActorClient = class DaprActorClient {
|
|
|
48
62
|
throw new Error(`Actor ${actorTypeName} not found`);
|
|
49
63
|
}
|
|
50
64
|
const actorClient = this.getActorClient(actorTypeName);
|
|
51
|
-
|
|
65
|
+
const fullActorId = this.getActorId(actorId);
|
|
66
|
+
return actorClient.build(fullActorId);
|
|
52
67
|
}
|
|
53
68
|
contains(actorTypeName) {
|
|
54
69
|
return this.actorClients.has(this.formatActorTypeName(actorTypeName));
|
package/dist/dapr.loader.js
CHANGED
|
@@ -42,7 +42,11 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
|
|
|
42
42
|
this.logger = new common_1.Logger(DaprLoader_1.name);
|
|
43
43
|
}
|
|
44
44
|
onApplicationBootstrap() {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
45
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (this.options.actorOptions) {
|
|
48
|
+
this.daprActorClient.setPrefix((_b = (_a = this.options.actorOptions) === null || _a === void 0 ? void 0 : _a.prefix) !== null && _b !== void 0 ? _b : '', (_d = (_c = this.options.actorOptions) === null || _c === void 0 ? void 0 : _c.delimiter) !== null && _d !== void 0 ? _d : '-');
|
|
49
|
+
}
|
|
46
50
|
(0, nest_actor_manager_1.patchActorManagerForNest)(this.moduleRef);
|
|
47
51
|
yield this.daprServer.actor.init();
|
|
48
52
|
this.loadDaprHandlers();
|
package/dist/dapr.module.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface DaprModuleOptions {
|
|
|
8
8
|
communicationProtocol?: CommunicationProtocolEnum;
|
|
9
9
|
clientOptions?: DaprClientOptions;
|
|
10
10
|
onError?: (name: string, topicName: string, error: any) => DaprPubSubStatusEnum;
|
|
11
|
+
actorOptions?: {
|
|
12
|
+
prefix?: string;
|
|
13
|
+
delimiter?: string;
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
export interface DaprModuleOptionsFactory {
|
|
13
17
|
createDaprModuleOptions(): Promise<DaprModuleOptions> | DaprModuleOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rayondigital/nest-dapr",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
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",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@nestjs/core": "^10.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@golevelup/ts-jest": "^0.4.0",
|
|
30
29
|
"@nestjs/platform-express": "^10.0.0",
|
|
31
30
|
"@nestjs/testing": "^10.0.0",
|
|
32
31
|
"@types/jest": "^29.5.7",
|