@rayondigital/nest-dapr 0.9.16 → 0.9.17
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.
- package/dist/actors/actor-proxy-builder.js +5 -7
- package/dist/actors/client-cache.d.ts +18 -0
- package/dist/actors/client-cache.js +77 -0
- package/dist/actors/dapr-actor-client.service.d.ts +2 -2
- package/dist/actors/dapr-actor-client.service.js +10 -11
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -8,14 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.ActorProxyBuilder = void 0;
|
|
16
|
-
const ActorClient_1 = __importDefault(require("@dapr/dapr/actors/client/ActorClient/ActorClient"));
|
|
17
|
-
const dapr_context_service_1 = require("../dapr-context-service");
|
|
18
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
+
const dapr_context_service_1 = require("../dapr-context-service");
|
|
15
|
+
const client_cache_1 = require("./client-cache");
|
|
19
16
|
class ActorProxyBuilder {
|
|
20
17
|
constructor(moduleRef, actorTypeClass, ...args) {
|
|
21
18
|
this.moduleRef = moduleRef;
|
|
@@ -25,11 +22,12 @@ class ActorProxyBuilder {
|
|
|
25
22
|
this.actorTypeClass = actorTypeClass;
|
|
26
23
|
if (args.length == 1) {
|
|
27
24
|
const [daprClient] = args;
|
|
28
|
-
this.actorClient =
|
|
25
|
+
this.actorClient = client_cache_1.DaprClientCache.getOrCreateActorClientFromClient(daprClient);
|
|
29
26
|
}
|
|
30
27
|
else {
|
|
31
28
|
const [host, port, communicationProtocol, clientOptions] = args;
|
|
32
|
-
|
|
29
|
+
const options = Object.assign({ daprHost: host, daprPort: port, communicationProtocol: communicationProtocol }, clientOptions);
|
|
30
|
+
this.actorClient = client_cache_1.DaprClientCache.getOrCreateActorClientFromOptions(options);
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
build(actorId, actorTypeName) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DaprClient, DaprClientOptions } from '@dapr/dapr';
|
|
2
|
+
import ActorClient from '@dapr/dapr/actors/client/ActorClient/ActorClient';
|
|
3
|
+
import StateProvider from '@dapr/dapr/actors/runtime/StateProvider';
|
|
4
|
+
export declare class DaprClientCache {
|
|
5
|
+
private static clients;
|
|
6
|
+
private static actorClients;
|
|
7
|
+
private static stateProviders;
|
|
8
|
+
static getAllClients(): DaprClient[];
|
|
9
|
+
static getAllActorClients(): ActorClient[];
|
|
10
|
+
static getAllStateProviders(): StateProvider[];
|
|
11
|
+
static getClientByHost(host: string): DaprClient | undefined;
|
|
12
|
+
static getActorClientByHost(host: string): ActorClient | undefined;
|
|
13
|
+
static getStateProviderByHost(host: string): StateProvider | undefined;
|
|
14
|
+
static getOrCreateActorClientFromClient(daprClient: DaprClient): ActorClient;
|
|
15
|
+
static getOrCreateStateProviderFromOptions(options: DaprClientOptions): StateProvider;
|
|
16
|
+
static getOrCreateActorClientFromOptions(options: DaprClientOptions): ActorClient;
|
|
17
|
+
static getOrCreateClientFromOptions(options: DaprClientOptions): DaprClient;
|
|
18
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DaprClientCache = void 0;
|
|
13
|
+
const dapr_1 = require("@dapr/dapr");
|
|
14
|
+
const ActorClient_1 = __importDefault(require("@dapr/dapr/actors/client/ActorClient/ActorClient"));
|
|
15
|
+
const StateProvider_1 = __importDefault(require("@dapr/dapr/actors/runtime/StateProvider"));
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
let DaprClientCache = class DaprClientCache {
|
|
18
|
+
static getAllClients() {
|
|
19
|
+
return Array.from(this.clients.values());
|
|
20
|
+
}
|
|
21
|
+
static getAllActorClients() {
|
|
22
|
+
return Array.from(this.actorClients.values());
|
|
23
|
+
}
|
|
24
|
+
static getAllStateProviders() {
|
|
25
|
+
return Array.from(this.stateProviders.values());
|
|
26
|
+
}
|
|
27
|
+
static getClientByHost(host) {
|
|
28
|
+
return this.clients.get(host);
|
|
29
|
+
}
|
|
30
|
+
static getActorClientByHost(host) {
|
|
31
|
+
return this.actorClients.get(host);
|
|
32
|
+
}
|
|
33
|
+
static getStateProviderByHost(host) {
|
|
34
|
+
return this.stateProviders.get(host);
|
|
35
|
+
}
|
|
36
|
+
static getOrCreateActorClientFromClient(daprClient) {
|
|
37
|
+
if (this.actorClients.has(daprClient.options.daprHost)) {
|
|
38
|
+
return this.actorClients.get(daprClient.options.daprHost);
|
|
39
|
+
}
|
|
40
|
+
if (!this.clients.has(daprClient.options.daprHost)) {
|
|
41
|
+
this.clients.set(daprClient.options.daprHost, daprClient);
|
|
42
|
+
}
|
|
43
|
+
return this.getOrCreateActorClientFromOptions(daprClient.options);
|
|
44
|
+
}
|
|
45
|
+
static getOrCreateStateProviderFromOptions(options) {
|
|
46
|
+
if (this.stateProviders.has(options.daprHost)) {
|
|
47
|
+
return this.stateProviders.get(options.daprHost);
|
|
48
|
+
}
|
|
49
|
+
const actorClient = this.getOrCreateActorClientFromOptions(options);
|
|
50
|
+
const stateProvider = new StateProvider_1.default(actorClient);
|
|
51
|
+
this.stateProviders.set(options.daprHost, stateProvider);
|
|
52
|
+
return stateProvider;
|
|
53
|
+
}
|
|
54
|
+
static getOrCreateActorClientFromOptions(options) {
|
|
55
|
+
if (this.actorClients.has(options.daprHost)) {
|
|
56
|
+
return this.actorClients.get(options.daprHost);
|
|
57
|
+
}
|
|
58
|
+
const client = new ActorClient_1.default(options.daprHost, options.daprPort, options.communicationProtocol, options);
|
|
59
|
+
this.actorClients.set(options.daprHost, client);
|
|
60
|
+
return client;
|
|
61
|
+
}
|
|
62
|
+
static getOrCreateClientFromOptions(options) {
|
|
63
|
+
if (this.clients.has(options.daprHost)) {
|
|
64
|
+
return this.clients.get(options.daprHost);
|
|
65
|
+
}
|
|
66
|
+
const client = new dapr_1.DaprClient(options);
|
|
67
|
+
this.clients.set(options.daprHost, client);
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
DaprClientCache.clients = new Map();
|
|
72
|
+
DaprClientCache.actorClients = new Map();
|
|
73
|
+
DaprClientCache.stateProviders = new Map();
|
|
74
|
+
DaprClientCache = __decorate([
|
|
75
|
+
(0, common_1.Injectable)()
|
|
76
|
+
], DaprClientCache);
|
|
77
|
+
exports.DaprClientCache = DaprClientCache;
|
|
@@ -4,7 +4,7 @@ import { ModuleRef } from '@nestjs/core';
|
|
|
4
4
|
export declare class DaprActorClient {
|
|
5
5
|
private readonly moduleRef;
|
|
6
6
|
private readonly daprClient;
|
|
7
|
-
private
|
|
7
|
+
private actorProxyBuilders;
|
|
8
8
|
private interfaces;
|
|
9
9
|
private interfaceToActorTypeNames;
|
|
10
10
|
private prefix;
|
|
@@ -21,5 +21,5 @@ export declare class DaprActorClient {
|
|
|
21
21
|
getActorTypeName(typeName: string): string;
|
|
22
22
|
contains(actorTypeName: string): boolean;
|
|
23
23
|
private formatActorTypeName;
|
|
24
|
-
private
|
|
24
|
+
private getActorClientProxyBuilder;
|
|
25
25
|
}
|
|
@@ -18,7 +18,7 @@ let DaprActorClient = class DaprActorClient {
|
|
|
18
18
|
constructor(moduleRef, daprClient) {
|
|
19
19
|
this.moduleRef = moduleRef;
|
|
20
20
|
this.daprClient = daprClient;
|
|
21
|
-
this.
|
|
21
|
+
this.actorProxyBuilders = new Map();
|
|
22
22
|
this.interfaces = new Map();
|
|
23
23
|
this.interfaceToActorTypeNames = new Map();
|
|
24
24
|
this.prefix = '';
|
|
@@ -34,7 +34,7 @@ let DaprActorClient = class DaprActorClient {
|
|
|
34
34
|
}
|
|
35
35
|
register(actorTypeName, actorType, daprClient) {
|
|
36
36
|
this.interfaces.set(this.formatActorTypeName(actorTypeName), actorType);
|
|
37
|
-
this.
|
|
37
|
+
this.actorProxyBuilders.set(this.formatActorTypeName(actorTypeName), new actor_proxy_builder_1.ActorProxyBuilder(this.moduleRef, actorType, daprClient !== null && daprClient !== void 0 ? daprClient : this.daprClient));
|
|
38
38
|
}
|
|
39
39
|
registerInterface(actorType, interfaceType, daprClient) {
|
|
40
40
|
var _a, _b;
|
|
@@ -42,7 +42,7 @@ let DaprActorClient = class DaprActorClient {
|
|
|
42
42
|
const actorTypeName = (_b = actorType.name) !== null && _b !== void 0 ? _b : actorType.constructor.name;
|
|
43
43
|
this.interfaceToActorTypeNames.set(interfaceTypeName, actorTypeName);
|
|
44
44
|
this.interfaces.set(this.formatActorTypeName(interfaceTypeName), actorType);
|
|
45
|
-
this.
|
|
45
|
+
this.actorProxyBuilders.set(this.formatActorTypeName(interfaceTypeName), new actor_proxy_builder_1.ActorProxyBuilder(this.moduleRef, actorType, daprClient !== null && daprClient !== void 0 ? daprClient : this.daprClient));
|
|
46
46
|
}
|
|
47
47
|
getActorId(actorId) {
|
|
48
48
|
var _a;
|
|
@@ -62,7 +62,7 @@ let DaprActorClient = class DaprActorClient {
|
|
|
62
62
|
throw new Error(`Actor ${actorTypeName} not found`);
|
|
63
63
|
}
|
|
64
64
|
const fullActorId = this.getActorId(actorId);
|
|
65
|
-
const actorClient = this.
|
|
65
|
+
const actorClient = this.getActorClientProxyBuilder(actorTypeName);
|
|
66
66
|
return actorClient.build(fullActorId, actorTypeName);
|
|
67
67
|
}
|
|
68
68
|
getActorByTypeName(actorTypeName, actorId) {
|
|
@@ -76,13 +76,13 @@ let DaprActorClient = class DaprActorClient {
|
|
|
76
76
|
throw new Error(`Actor ${actorTypeName} not found`);
|
|
77
77
|
}
|
|
78
78
|
const fullActorId = this.getActorId(actorId);
|
|
79
|
-
const actorClient = this.
|
|
79
|
+
const actorClient = this.getActorClientProxyBuilder(actorTypeName);
|
|
80
80
|
return actorClient.build(fullActorId, actorTypeName);
|
|
81
81
|
}
|
|
82
82
|
getActorTypeName(typeName) {
|
|
83
83
|
if (this.interfaceToActorTypeNames.has(typeName)) {
|
|
84
84
|
const actorTypeName = this.interfaceToActorTypeNames.get(typeName);
|
|
85
|
-
if (this.
|
|
85
|
+
if (this.actorProxyBuilders.has(actorTypeName)) {
|
|
86
86
|
return actorTypeName;
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
@@ -95,18 +95,17 @@ let DaprActorClient = class DaprActorClient {
|
|
|
95
95
|
return typeName;
|
|
96
96
|
}
|
|
97
97
|
contains(actorTypeName) {
|
|
98
|
-
return this.
|
|
98
|
+
return this.actorProxyBuilders.has(this.formatActorTypeName(actorTypeName));
|
|
99
99
|
}
|
|
100
100
|
formatActorTypeName(actorTypeName) {
|
|
101
101
|
return actorTypeName.toLowerCase();
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
return this.
|
|
103
|
+
getActorClientProxyBuilder(actorTypeName) {
|
|
104
|
+
return this.actorProxyBuilders.get(this.formatActorTypeName(actorTypeName));
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
DaprActorClient = __decorate([
|
|
108
108
|
(0, common_1.Injectable)(),
|
|
109
|
-
__metadata("design:paramtypes", [core_1.ModuleRef,
|
|
110
|
-
dapr_1.DaprClient])
|
|
109
|
+
__metadata("design:paramtypes", [core_1.ModuleRef, dapr_1.DaprClient])
|
|
111
110
|
], DaprActorClient);
|
|
112
111
|
exports.DaprActorClient = DaprActorClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DaprClientCache } from './actors/client-cache';
|
|
1
2
|
import { DaprActorClient } from './actors/dapr-actor-client.service';
|
|
2
3
|
import { StatefulActorOf } from './actors/stateful-actor-of';
|
|
3
4
|
import { IState, StatefulActor } from './actors/stateful.actor';
|
|
@@ -10,4 +11,4 @@ import { DaprMetadataAccessor } from './dapr-metadata.accessor';
|
|
|
10
11
|
import { DaprPubSub, DaprPubSubMetadata } from './dapr-pubsub.decorator';
|
|
11
12
|
import { DaprLoader } from './dapr.loader';
|
|
12
13
|
import { DaprModule } from './dapr.module';
|
|
13
|
-
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, StatefulActor, StatefulActorOf, IState, };
|
|
14
|
+
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, DaprClientCache, StatefulActor, StatefulActorOf, IState, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatefulActorOf = exports.StatefulActor = 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.StatefulActorOf = exports.StatefulActor = exports.DaprClientCache = 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
|
+
const client_cache_1 = require("./actors/client-cache");
|
|
5
|
+
Object.defineProperty(exports, "DaprClientCache", { enumerable: true, get: function () { return client_cache_1.DaprClientCache; } });
|
|
4
6
|
const dapr_actor_client_service_1 = require("./actors/dapr-actor-client.service");
|
|
5
7
|
Object.defineProperty(exports, "DaprActorClient", { enumerable: true, get: function () { return dapr_actor_client_service_1.DaprActorClient; } });
|
|
6
8
|
const stateful_actor_of_1 = require("./actors/stateful-actor-of");
|
package/package.json
CHANGED