@rayondigital/nest-dapr 0.9.29 → 0.9.31
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/dapr-pubsub.decorator.d.ts +1 -1
- package/dist/dapr-pubsub.decorator.js +1 -5
- package/dist/dapr.loader.js +6 -3
- package/dist/dapr.module.d.ts +5 -1
- package/dist/dapr.module.js +21 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/pubsub/dapr-pubsub-client.service.d.ts +20 -0
- package/dist/pubsub/dapr-pubsub-client.service.js +152 -0
- package/dist/pubsub/publish.message.d.ts +7 -0
- package/dist/pubsub/publish.message.js +2 -0
- package/package.json +3 -2
|
@@ -3,9 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DaprPubSub = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
-
const DaprPubSub = (
|
|
7
|
-
name,
|
|
8
|
-
topicName,
|
|
9
|
-
route,
|
|
10
|
-
});
|
|
6
|
+
const DaprPubSub = (options) => (0, common_1.SetMetadata)(constants_1.DAPR_PUBSUB_METADATA, options);
|
|
11
7
|
exports.DaprPubSub = DaprPubSub;
|
package/dist/dapr.loader.js
CHANGED
|
@@ -127,14 +127,17 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
|
|
|
127
127
|
}));
|
|
128
128
|
}
|
|
129
129
|
subscribeToDaprPubSubEventIfListener(instance, methodKey) {
|
|
130
|
+
var _a, _b;
|
|
130
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
132
|
const daprPubSubMetadata = this.daprMetadataAccessor.getDaprPubSubHandlerMetadata(instance[methodKey]);
|
|
132
133
|
if (!daprPubSubMetadata) {
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
|
-
const
|
|
136
|
+
const name = (_a = daprPubSubMetadata.name) !== null && _a !== void 0 ? _a : (_b = this.options.pubsubOptions) === null || _b === void 0 ? void 0 : _b.defaultName;
|
|
137
|
+
const { topicName, route } = daprPubSubMetadata;
|
|
136
138
|
this.logger.log(`Subscribing to Dapr: ${name}, Topic: ${topicName}${route ? ' on route ' + route : ''}`);
|
|
137
139
|
yield this.daprServer.pubsub.subscribe(name, topicName, (data) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
var _c, _d;
|
|
138
141
|
try {
|
|
139
142
|
const result = yield instance[methodKey].call(instance, data);
|
|
140
143
|
if (result && result in dapr_1.DaprPubSubStatusEnum) {
|
|
@@ -144,8 +147,8 @@ let DaprLoader = DaprLoader_1 = class DaprLoader {
|
|
|
144
147
|
}
|
|
145
148
|
catch (err) {
|
|
146
149
|
this.logger.error(err, `Error in pubsub handler ${topicName}`);
|
|
147
|
-
if (this.options.
|
|
148
|
-
const response = this.options.
|
|
150
|
+
if ((_c = this.options.pubsubOptions) === null || _c === void 0 ? void 0 : _c.onError) {
|
|
151
|
+
const response = (_d = this.options.pubsubOptions) === null || _d === void 0 ? void 0 : _d.onError(name, topicName, err);
|
|
149
152
|
if (response == dapr_1.DaprPubSubStatusEnum.RETRY) {
|
|
150
153
|
this.logger.log(`Retrying pubsub handler ${topicName} operation`);
|
|
151
154
|
}
|
package/dist/dapr.module.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export interface DaprModuleOptions {
|
|
|
7
7
|
serverPort?: string;
|
|
8
8
|
communicationProtocol?: CommunicationProtocolEnum;
|
|
9
9
|
clientOptions?: DaprClientOptions;
|
|
10
|
-
onPubSubError?: (name: string, topicName: string, error: any) => DaprPubSubStatusEnum;
|
|
11
10
|
actorOptions?: DaprModuleActorOptions;
|
|
11
|
+
pubsubOptions?: DaprModulePubSubOptions;
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
contextProvider?: DaprContextProvider;
|
|
14
14
|
catchErrors?: boolean;
|
|
@@ -19,6 +19,10 @@ export interface DaprModuleActorOptions {
|
|
|
19
19
|
typeNamePrefix?: string;
|
|
20
20
|
allowInternalCalls?: boolean;
|
|
21
21
|
}
|
|
22
|
+
export interface DaprModulePubSubOptions {
|
|
23
|
+
defaultName?: string;
|
|
24
|
+
onError?: (name: string, topicName: string, error: any) => DaprPubSubStatusEnum;
|
|
25
|
+
}
|
|
22
26
|
export declare enum DaprContextProvider {
|
|
23
27
|
None = "none",
|
|
24
28
|
ALS = "als",
|
package/dist/dapr.module.js
CHANGED
|
@@ -27,6 +27,7 @@ const nest_actor_manager_1 = require("./actors/nest-actor-manager");
|
|
|
27
27
|
const dapr_context_service_1 = require("./dapr-context-service");
|
|
28
28
|
const dapr_metadata_accessor_1 = require("./dapr-metadata.accessor");
|
|
29
29
|
const dapr_loader_1 = require("./dapr.loader");
|
|
30
|
+
const dapr_pubsub_client_service_1 = require("./pubsub/dapr-pubsub-client.service");
|
|
30
31
|
exports.DAPR_MODULE_OPTIONS_TOKEN = 'DAPR_MODULE_OPTIONS_TOKEN';
|
|
31
32
|
var DaprContextProvider;
|
|
32
33
|
(function (DaprContextProvider) {
|
|
@@ -75,9 +76,18 @@ let DaprModule = DaprModule_1 = class DaprModule {
|
|
|
75
76
|
dapr_loader_1.DaprLoader,
|
|
76
77
|
dapr_metadata_accessor_1.DaprMetadataAccessor,
|
|
77
78
|
dapr_context_service_1.DaprContextService,
|
|
79
|
+
dapr_actor_client_service_1.DaprActorClient,
|
|
80
|
+
{
|
|
81
|
+
provide: dapr_pubsub_client_service_1.DaprPubSubClient,
|
|
82
|
+
scope: common_1.Scope.DEFAULT,
|
|
83
|
+
inject: [exports.DAPR_MODULE_OPTIONS_TOKEN, dapr_1.DaprClient],
|
|
84
|
+
useFactory: (options, daprClient) => {
|
|
85
|
+
return new dapr_pubsub_client_service_1.DaprPubSubClient(options, daprClient);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
78
88
|
core_1.Reflector,
|
|
79
89
|
],
|
|
80
|
-
exports: [dapr_1.DaprClient],
|
|
90
|
+
exports: [dapr_1.DaprClient, dapr_pubsub_client_service_1.DaprPubSubClient, exports.DAPR_MODULE_OPTIONS_TOKEN],
|
|
81
91
|
};
|
|
82
92
|
}
|
|
83
93
|
static registerAsync(options) {
|
|
@@ -107,10 +117,19 @@ let DaprModule = DaprModule_1 = class DaprModule {
|
|
|
107
117
|
dapr_loader_1.DaprLoader,
|
|
108
118
|
dapr_metadata_accessor_1.DaprMetadataAccessor,
|
|
109
119
|
dapr_context_service_1.DaprContextService,
|
|
120
|
+
dapr_actor_client_service_1.DaprActorClient,
|
|
121
|
+
{
|
|
122
|
+
provide: dapr_pubsub_client_service_1.DaprPubSubClient,
|
|
123
|
+
scope: common_1.Scope.DEFAULT,
|
|
124
|
+
inject: [exports.DAPR_MODULE_OPTIONS_TOKEN, dapr_1.DaprClient],
|
|
125
|
+
useFactory: (options, daprClient) => {
|
|
126
|
+
return new dapr_pubsub_client_service_1.DaprPubSubClient(options, daprClient);
|
|
127
|
+
},
|
|
128
|
+
},
|
|
110
129
|
core_1.Reflector,
|
|
111
130
|
...(options.extraProviders || []),
|
|
112
131
|
],
|
|
113
|
-
exports: [dapr_1.DaprClient],
|
|
132
|
+
exports: [dapr_1.DaprClient, dapr_pubsub_client_service_1.DaprPubSubClient, exports.DAPR_MODULE_OPTIONS_TOKEN],
|
|
114
133
|
};
|
|
115
134
|
}
|
|
116
135
|
static createAsyncProviders(options) {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ import { DaprMetadataAccessor } from './dapr-metadata.accessor';
|
|
|
12
12
|
import { DaprPubSub, DaprPubSubMetadata } from './dapr-pubsub.decorator';
|
|
13
13
|
import { DaprLoader } from './dapr.loader';
|
|
14
14
|
import { DaprContextProvider, DaprModule } from './dapr.module';
|
|
15
|
-
|
|
15
|
+
import { DaprPubSubClient } from './pubsub/dapr-pubsub-client.service';
|
|
16
|
+
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, StatefulActor, StatefulActorOf, IState, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatefulActorOf = exports.StatefulActor = exports.DaprClientCache = 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.StatefulActorOf = exports.StatefulActor = 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");
|
|
@@ -33,3 +33,5 @@ Object.defineProperty(exports, "DaprLoader", { enumerable: true, get: function (
|
|
|
33
33
|
const dapr_module_1 = require("./dapr.module");
|
|
34
34
|
Object.defineProperty(exports, "DaprContextProvider", { enumerable: true, get: function () { return dapr_module_1.DaprContextProvider; } });
|
|
35
35
|
Object.defineProperty(exports, "DaprModule", { enumerable: true, get: function () { return dapr_module_1.DaprModule; } });
|
|
36
|
+
const dapr_pubsub_client_service_1 = require("./pubsub/dapr-pubsub-client.service");
|
|
37
|
+
Object.defineProperty(exports, "DaprPubSubClient", { enumerable: true, get: function () { return dapr_pubsub_client_service_1.DaprPubSubClient; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DaprClient } from '@dapr/dapr';
|
|
2
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
3
|
+
import { DaprModuleOptions } from '../dapr.module';
|
|
4
|
+
export declare class DaprPubSubClient implements OnApplicationShutdown {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly daprClient;
|
|
7
|
+
private readonly defaultName;
|
|
8
|
+
private readonly buffer;
|
|
9
|
+
private subscription;
|
|
10
|
+
private readonly bufferSize;
|
|
11
|
+
private readonly bufferTimeSpan;
|
|
12
|
+
constructor(options: DaprModuleOptions, daprClient: DaprClient);
|
|
13
|
+
onApplicationShutdown(signal?: string): Promise<void>;
|
|
14
|
+
private setupBufferSubscription;
|
|
15
|
+
private publishBulkDirectly;
|
|
16
|
+
private publishDirectly;
|
|
17
|
+
publish(name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
|
|
18
|
+
publish(producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
|
|
19
|
+
publish(producerId: string, topic: string, payload: any): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.DaprPubSubClient = void 0;
|
|
25
|
+
const dapr_1 = require("@dapr/dapr");
|
|
26
|
+
const common_1 = require("@nestjs/common");
|
|
27
|
+
const rxjs_1 = require("rxjs");
|
|
28
|
+
const operators_1 = require("rxjs/operators");
|
|
29
|
+
const dapr_module_1 = require("../dapr.module");
|
|
30
|
+
let DaprPubSubClient = class DaprPubSubClient {
|
|
31
|
+
constructor(options, daprClient) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
this.options = options;
|
|
34
|
+
this.daprClient = daprClient;
|
|
35
|
+
this.buffer = new rxjs_1.Subject();
|
|
36
|
+
this.bufferSize = 10;
|
|
37
|
+
this.bufferTimeSpan = 1000;
|
|
38
|
+
this.defaultName = (_b = (_a = this.options.pubsubOptions) === null || _a === void 0 ? void 0 : _a.defaultName) !== null && _b !== void 0 ? _b : 'pubsub';
|
|
39
|
+
this.setupBufferSubscription();
|
|
40
|
+
}
|
|
41
|
+
onApplicationShutdown(signal) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
this.subscription.unsubscribe();
|
|
44
|
+
const flushPromise = new Promise((resolve, reject) => {
|
|
45
|
+
const messages = [];
|
|
46
|
+
this.buffer.pipe((0, rxjs_1.toArray)()).subscribe({
|
|
47
|
+
next: (msgs) => messages.push(...msgs),
|
|
48
|
+
error: reject,
|
|
49
|
+
complete: () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
yield this.publishBulkDirectly(messages);
|
|
52
|
+
resolve();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
reject(error);
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
this.buffer.complete();
|
|
60
|
+
});
|
|
61
|
+
yield flushPromise;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
setupBufferSubscription() {
|
|
65
|
+
if (this.subscription) {
|
|
66
|
+
this.subscription.unsubscribe();
|
|
67
|
+
}
|
|
68
|
+
this.subscription = this.buffer
|
|
69
|
+
.pipe((0, operators_1.bufferTime)(this.bufferTimeSpan, null, this.bufferSize))
|
|
70
|
+
.subscribe((messages) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (messages.length > 0) {
|
|
72
|
+
yield this.publishBulkDirectly(messages);
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
publishBulkDirectly(messages) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
if (messages.length === 1) {
|
|
79
|
+
const message = messages[0];
|
|
80
|
+
yield this.publishDirectly(message.name, message.topic, message.payload, message.producerId, message.metadata);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const grouped = messages.reduce((acc, message) => {
|
|
84
|
+
const key = `${message.name}:${message.topic}:${message.producerId}`;
|
|
85
|
+
if (!acc[key]) {
|
|
86
|
+
acc[key] = [];
|
|
87
|
+
}
|
|
88
|
+
acc[key].push(message);
|
|
89
|
+
return acc;
|
|
90
|
+
}, {});
|
|
91
|
+
for (const key in grouped) {
|
|
92
|
+
const [name, topic, producerId] = key.split(':');
|
|
93
|
+
const messages = grouped[key];
|
|
94
|
+
if (messages.length === 1) {
|
|
95
|
+
yield this.publishDirectly(name, topic, messages[0].payload, producerId, messages[0].metadata);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId } } : undefined);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (!name)
|
|
105
|
+
name = this.defaultName;
|
|
106
|
+
const options = {};
|
|
107
|
+
if (metadata) {
|
|
108
|
+
options['metadata'] = metadata;
|
|
109
|
+
}
|
|
110
|
+
if (producerId) {
|
|
111
|
+
options['metadata'] = Object.assign({ partitionKey: producerId }, metadata);
|
|
112
|
+
}
|
|
113
|
+
if (fireAndForget) {
|
|
114
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
116
|
+
}));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
publish(...args) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
let name;
|
|
125
|
+
let producerId;
|
|
126
|
+
let topic;
|
|
127
|
+
let payload;
|
|
128
|
+
let buffer;
|
|
129
|
+
let metadata;
|
|
130
|
+
if (args.length === 6) {
|
|
131
|
+
[name, producerId, topic, payload, buffer, metadata] = args;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
[producerId, topic, payload, buffer, metadata] = args;
|
|
135
|
+
name = this.defaultName;
|
|
136
|
+
}
|
|
137
|
+
if (!name)
|
|
138
|
+
name = this.defaultName;
|
|
139
|
+
if (buffer === undefined || buffer) {
|
|
140
|
+
this.buffer.next({ name, producerId, topic, payload, metadata });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
yield this.publishDirectly(name, topic, payload, producerId, true);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
DaprPubSubClient = __decorate([
|
|
148
|
+
(0, common_1.Injectable)(),
|
|
149
|
+
__param(0, (0, common_1.Inject)(dapr_module_1.DAPR_MODULE_OPTIONS_TOKEN)),
|
|
150
|
+
__metadata("design:paramtypes", [Object, dapr_1.DaprClient])
|
|
151
|
+
], DaprPubSubClient);
|
|
152
|
+
exports.DaprPubSubClient = DaprPubSubClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rayondigital/nest-dapr",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.31",
|
|
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,8 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@nestjs/common": "^10.0.0",
|
|
26
26
|
"@nestjs/core": "^10.0.0",
|
|
27
|
-
"nestjs-cls": "^3.0.0"
|
|
27
|
+
"nestjs-cls": "^3.0.0",
|
|
28
|
+
"rxjs": "^7.1.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@nestjs/platform-express": "^10.0.0",
|