@privateaim/server-kit 0.8.8 → 0.8.10
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/CHANGELOG.md +33 -0
- package/dist/index.cjs +222 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +220 -112
- package/dist/index.mjs.map +1 -1
- package/dist/services/domain-event/index.d.ts +6 -0
- package/dist/services/domain-event/index.d.ts.map +1 -0
- package/dist/services/domain-event/module.d.ts +10 -0
- package/dist/services/domain-event/module.d.ts.map +1 -0
- package/dist/services/domain-event/redis/index.d.ts +2 -0
- package/dist/services/domain-event/redis/index.d.ts.map +1 -0
- package/dist/services/domain-event/redis/module.d.ts +8 -0
- package/dist/services/domain-event/redis/module.d.ts.map +1 -0
- package/dist/services/domain-event/singleton.d.ts +3 -0
- package/dist/services/domain-event/singleton.d.ts.map +1 -0
- package/dist/services/domain-event/socket/index.d.ts +2 -0
- package/dist/services/domain-event/socket/index.d.ts.map +1 -0
- package/dist/services/domain-event/socket/module.d.ts +8 -0
- package/dist/services/domain-event/socket/module.d.ts.map +1 -0
- package/dist/services/domain-event/type.d.ts +15 -0
- package/dist/services/domain-event/type.d.ts.map +1 -0
- package/dist/services/domain-event/utils.d.ts +4 -0
- package/dist/services/domain-event/utils.d.ts.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +0 -1
- package/src/{domain-event → services/domain-event}/index.ts +2 -1
- package/src/services/domain-event/module.ts +54 -0
- package/src/{domain-event → services/domain-event}/redis/index.ts +1 -1
- package/src/services/domain-event/redis/module.ts +37 -0
- package/src/services/domain-event/singleton.ts +32 -0
- package/src/{domain-event → services/domain-event}/socket/index.ts +1 -1
- package/src/services/domain-event/socket/module.ts +57 -0
- package/src/{domain-event → services/domain-event}/type.ts +13 -0
- package/src/{domain-event → services/domain-event}/utils.ts +2 -2
- package/src/services/index.ts +1 -0
- package/dist/domain-event/index.d.ts +0 -5
- package/dist/domain-event/index.d.ts.map +0 -1
- package/dist/domain-event/publish.d.ts +0 -5
- package/dist/domain-event/publish.d.ts.map +0 -1
- package/dist/domain-event/redis/index.d.ts +0 -2
- package/dist/domain-event/redis/index.d.ts.map +0 -1
- package/dist/domain-event/redis/publish.d.ts +0 -5
- package/dist/domain-event/redis/publish.d.ts.map +0 -1
- package/dist/domain-event/socket/index.d.ts +0 -2
- package/dist/domain-event/socket/index.d.ts.map +0 -1
- package/dist/domain-event/socket/publish.d.ts +0 -5
- package/dist/domain-event/socket/publish.d.ts.map +0 -1
- package/dist/domain-event/type.d.ts +0 -7
- package/dist/domain-event/type.d.ts.map +0 -1
- package/dist/domain-event/utils.d.ts +0 -4
- package/dist/domain-event/utils.d.ts.map +0 -1
- package/src/domain-event/publish.ts +0 -21
- package/src/domain-event/redis/publish.ts +0 -41
- package/src/domain-event/socket/publish.ts +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.10](https://github.com/PrivateAIM/hub/compare/v0.8.9...v0.8.10) (2025-04-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* introduce safe publish method for domain-event-publisher ([cff0b35](https://github.com/PrivateAIM/hub/commit/cff0b3567ad11fb4a8ee42c58082122185c50c6c))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @privateaim/kit bumped from ^0.8.9 to ^0.8.10
|
|
16
|
+
|
|
17
|
+
## [0.8.9](https://github.com/PrivateAIM/hub/compare/v0.8.8...v0.8.9) (2025-04-17)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* restructure domain event handling ([2ad7318](https://github.com/PrivateAIM/hub/commit/2ad7318930bd342d571105982fc92996443326fa))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **deps:** bump the minorandpatch group across 1 directory with 2 updates ([#1033](https://github.com/PrivateAIM/hub/issues/1033)) ([b228557](https://github.com/PrivateAIM/hub/commit/b228557eb213761ab97d2d9f8e618b86c50ab155))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @privateaim/kit bumped from ^0.8.8 to ^0.8.9
|
|
35
|
+
|
|
3
36
|
## [0.8.8](https://github.com/PrivateAIM/hub/compare/v0.8.7...v0.8.8) (2025-04-15)
|
|
4
37
|
|
|
5
38
|
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,6 @@ var envix = require('envix');
|
|
|
11
11
|
var path = require('node:path');
|
|
12
12
|
var typeormExtension = require('typeorm-extension');
|
|
13
13
|
var winston = require('winston');
|
|
14
|
-
var coreKit = require('@privateaim/core-kit');
|
|
15
14
|
var redisEmitter = require('@socket.io/redis-emitter');
|
|
16
15
|
|
|
17
16
|
/*
|
|
@@ -19,7 +18,7 @@ var redisEmitter = require('@socket.io/redis-emitter');
|
|
|
19
18
|
* Author Peter Placzek (tada5hi)
|
|
20
19
|
* For the full copyright and license information,
|
|
21
20
|
* view the LICENSE file that was distributed with this source code.
|
|
22
|
-
*/ function _define_property$
|
|
21
|
+
*/ function _define_property$7(obj, key, value) {
|
|
23
22
|
if (key in obj) {
|
|
24
23
|
Object.defineProperty(obj, key, {
|
|
25
24
|
value: value,
|
|
@@ -36,7 +35,7 @@ class ComponentError extends Error {
|
|
|
36
35
|
constructor(input){
|
|
37
36
|
super(input.message, {
|
|
38
37
|
cause: input.cause
|
|
39
|
-
}), _define_property$
|
|
38
|
+
}), _define_property$7(this, "code", void 0);
|
|
40
39
|
this.code = input.code;
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -84,30 +83,30 @@ function isQueueRouterPayload(input) {
|
|
|
84
83
|
return kit.isObject(input) && typeof input.id === 'string' && typeof input.type === 'string' && kit.hasOwnProperty(input, 'data') && kit.isObject(input.data) && kit.hasOwnProperty(input, 'metadata') && kit.isObject(input.metadata);
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
const instance$
|
|
86
|
+
const instance$a = singa.singa({
|
|
88
87
|
name: 'amqp'
|
|
89
88
|
});
|
|
90
89
|
function setAmqpClientFactory(factory) {
|
|
91
|
-
instance$
|
|
90
|
+
instance$a.setFactory(factory);
|
|
92
91
|
}
|
|
93
92
|
function isAmqpClientUsable() {
|
|
94
|
-
return instance$
|
|
93
|
+
return instance$a.has() || instance$a.hasFactory();
|
|
95
94
|
}
|
|
96
95
|
function useAmqpClient() {
|
|
97
|
-
return instance$
|
|
96
|
+
return instance$a.use();
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
const instance$
|
|
99
|
+
const instance$9 = singa.singa({
|
|
101
100
|
name: 'vault'
|
|
102
101
|
});
|
|
103
102
|
function setVaultFactory(factory) {
|
|
104
|
-
instance$
|
|
103
|
+
instance$9.setFactory(factory);
|
|
105
104
|
}
|
|
106
105
|
function isVaultClientUsable() {
|
|
107
|
-
return instance$
|
|
106
|
+
return instance$9.has() || instance$9.hasFactory();
|
|
108
107
|
}
|
|
109
108
|
function useVaultClient() {
|
|
110
|
-
return instance$
|
|
109
|
+
return instance$9.use();
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
function guessAuthupTokenCreatorOptions() {
|
|
@@ -128,17 +127,17 @@ function guessAuthupTokenCreatorOptions() {
|
|
|
128
127
|
return options;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
const instance$
|
|
130
|
+
const instance$8 = singa.singa({
|
|
132
131
|
name: 'clientAuthenticationHook'
|
|
133
132
|
});
|
|
134
133
|
function setClientAuthenticationHookFactory(factory) {
|
|
135
|
-
instance$
|
|
134
|
+
instance$8.setFactory(factory);
|
|
136
135
|
}
|
|
137
136
|
function isClientAuthenticationHookUsable() {
|
|
138
|
-
return instance$
|
|
137
|
+
return instance$8.has() || instance$8.hasFactory();
|
|
139
138
|
}
|
|
140
139
|
function useClientAuthenticationHook() {
|
|
141
|
-
return instance$
|
|
140
|
+
return instance$8.use();
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
class AuthupClient extends coreHttpKit.Client {
|
|
@@ -155,49 +154,49 @@ class AuthupClient extends coreHttpKit.Client {
|
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
const instance$
|
|
157
|
+
const instance$7 = singa.singa({
|
|
159
158
|
name: 'authup'
|
|
160
159
|
});
|
|
161
160
|
function useAuthupClient() {
|
|
162
|
-
return instance$
|
|
161
|
+
return instance$7.use();
|
|
163
162
|
}
|
|
164
163
|
function isAuthupClientUsable() {
|
|
165
|
-
return instance$
|
|
164
|
+
return instance$7.has() || instance$7.hasFactory();
|
|
166
165
|
}
|
|
167
166
|
function setAuthupClientFactory(factory) {
|
|
168
|
-
instance$
|
|
167
|
+
instance$7.setFactory(factory);
|
|
169
168
|
}
|
|
170
169
|
|
|
171
|
-
const instance$
|
|
170
|
+
const instance$6 = singa.singa({
|
|
172
171
|
name: 'redis'
|
|
173
172
|
});
|
|
174
173
|
function setRedisFactory(factory) {
|
|
175
|
-
instance$
|
|
174
|
+
instance$6.setFactory(factory);
|
|
176
175
|
}
|
|
177
176
|
function isRedisClientUsable() {
|
|
178
|
-
return instance$
|
|
177
|
+
return instance$6.has() || instance$6.hasFactory();
|
|
179
178
|
}
|
|
180
179
|
function setRedisClient(input) {
|
|
181
|
-
instance$
|
|
180
|
+
instance$6.set(input);
|
|
182
181
|
}
|
|
183
182
|
function useRedisClient() {
|
|
184
|
-
return instance$
|
|
183
|
+
return instance$6.use();
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
const instance$
|
|
186
|
+
const instance$5 = singa.singa({
|
|
188
187
|
name: 'redisPublish',
|
|
189
188
|
factory: ()=>useRedisClient().duplicate()
|
|
190
189
|
});
|
|
191
190
|
function useRedisPublishClient() {
|
|
192
|
-
return instance$
|
|
191
|
+
return instance$5.use();
|
|
193
192
|
}
|
|
194
193
|
|
|
195
|
-
const instance$
|
|
194
|
+
const instance$4 = singa.singa({
|
|
196
195
|
name: 'redisSubscribe',
|
|
197
196
|
factory: ()=>useRedisClient().duplicate()
|
|
198
197
|
});
|
|
199
198
|
function useRedisSubscribeClient() {
|
|
200
|
-
return instance$
|
|
199
|
+
return instance$4.use();
|
|
201
200
|
}
|
|
202
201
|
|
|
203
202
|
/*
|
|
@@ -205,7 +204,7 @@ function useRedisSubscribeClient() {
|
|
|
205
204
|
* Author Peter Placzek (tada5hi)
|
|
206
205
|
* For the full copyright and license information,
|
|
207
206
|
* view the LICENSE file that was distributed with this source code.
|
|
208
|
-
*/ function _define_property$
|
|
207
|
+
*/ function _define_property$6(obj, key, value) {
|
|
209
208
|
if (key in obj) {
|
|
210
209
|
Object.defineProperty(obj, key, {
|
|
211
210
|
value: value,
|
|
@@ -253,7 +252,7 @@ class MemoryCacheAdapter {
|
|
|
253
252
|
this.instance.clear();
|
|
254
253
|
}
|
|
255
254
|
constructor(options = {}){
|
|
256
|
-
_define_property$
|
|
255
|
+
_define_property$6(this, "instance", void 0);
|
|
257
256
|
this.instance = new TTLCache({
|
|
258
257
|
checkAgeOnGet: true,
|
|
259
258
|
ttl: Infinity,
|
|
@@ -267,7 +266,7 @@ class MemoryCacheAdapter {
|
|
|
267
266
|
* Author Peter Placzek (tada5hi)
|
|
268
267
|
* For the full copyright and license information,
|
|
269
268
|
* view the LICENSE file that was distributed with this source code.
|
|
270
|
-
*/ function _define_property$
|
|
269
|
+
*/ function _define_property$5(obj, key, value) {
|
|
271
270
|
if (key in obj) {
|
|
272
271
|
Object.defineProperty(obj, key, {
|
|
273
272
|
value: value,
|
|
@@ -316,8 +315,8 @@ class RedisCacheAdapter {
|
|
|
316
315
|
await this.client.flushdb();
|
|
317
316
|
}
|
|
318
317
|
constructor(){
|
|
319
|
-
_define_property$
|
|
320
|
-
_define_property$
|
|
318
|
+
_define_property$5(this, "client", void 0);
|
|
319
|
+
_define_property$5(this, "instance", void 0);
|
|
321
320
|
this.client = useRedisClient();
|
|
322
321
|
this.instance = new redisExtension.JsonAdapter(this.client);
|
|
323
322
|
}
|
|
@@ -339,7 +338,7 @@ function buildCacheKey(options) {
|
|
|
339
338
|
* Author Peter Placzek (tada5hi)
|
|
340
339
|
* For the full copyright and license information,
|
|
341
340
|
* view the LICENSE file that was distributed with this source code.
|
|
342
|
-
*/ function _define_property$
|
|
341
|
+
*/ function _define_property$4(obj, key, value) {
|
|
343
342
|
if (key in obj) {
|
|
344
343
|
Object.defineProperty(obj, key, {
|
|
345
344
|
value: value,
|
|
@@ -372,12 +371,12 @@ class Cache {
|
|
|
372
371
|
return this.adapter.clear(options);
|
|
373
372
|
}
|
|
374
373
|
constructor(adapter){
|
|
375
|
-
_define_property$
|
|
374
|
+
_define_property$4(this, "adapter", void 0);
|
|
376
375
|
this.adapter = adapter;
|
|
377
376
|
}
|
|
378
377
|
}
|
|
379
378
|
|
|
380
|
-
const instance$
|
|
379
|
+
const instance$3 = singa.singa({
|
|
381
380
|
name: 'cache',
|
|
382
381
|
factory: ()=>{
|
|
383
382
|
let adapter;
|
|
@@ -390,7 +389,7 @@ const instance$2 = singa.singa({
|
|
|
390
389
|
}
|
|
391
390
|
});
|
|
392
391
|
function useCache() {
|
|
393
|
-
return instance$
|
|
392
|
+
return instance$3.use();
|
|
394
393
|
}
|
|
395
394
|
|
|
396
395
|
function createLogger(ctx = {}) {
|
|
@@ -432,19 +431,197 @@ function createLogger(ctx = {}) {
|
|
|
432
431
|
});
|
|
433
432
|
}
|
|
434
433
|
|
|
435
|
-
const instance$
|
|
434
|
+
const instance$2 = singa.singa({
|
|
436
435
|
name: 'logger'
|
|
437
436
|
});
|
|
438
437
|
function setLoggerFactory(factory) {
|
|
439
|
-
instance$
|
|
438
|
+
instance$2.setFactory(factory);
|
|
440
439
|
}
|
|
441
440
|
function isLoggerUsable() {
|
|
442
|
-
return instance$
|
|
441
|
+
return instance$2.has() || instance$2.hasFactory();
|
|
443
442
|
}
|
|
444
443
|
function setLogger(input) {
|
|
445
|
-
instance$
|
|
444
|
+
instance$2.set(input);
|
|
446
445
|
}
|
|
447
446
|
function useLogger() {
|
|
447
|
+
return instance$2.use();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/*
|
|
451
|
+
* Copyright (c) 2024-2024.
|
|
452
|
+
* Author Peter Placzek (tada5hi)
|
|
453
|
+
* For the full copyright and license information,
|
|
454
|
+
* view the LICENSE file that was distributed with this source code.
|
|
455
|
+
*/ function _define_property$3(obj, key, value) {
|
|
456
|
+
if (key in obj) {
|
|
457
|
+
Object.defineProperty(obj, key, {
|
|
458
|
+
value: value,
|
|
459
|
+
enumerable: true,
|
|
460
|
+
configurable: true,
|
|
461
|
+
writable: true
|
|
462
|
+
});
|
|
463
|
+
} else {
|
|
464
|
+
obj[key] = value;
|
|
465
|
+
}
|
|
466
|
+
return obj;
|
|
467
|
+
}
|
|
468
|
+
class DomainEventPublisher {
|
|
469
|
+
addPublisher(publisher) {
|
|
470
|
+
this.publishers.add(publisher);
|
|
471
|
+
}
|
|
472
|
+
async safePublish(ctx) {
|
|
473
|
+
try {
|
|
474
|
+
await this.publish(ctx);
|
|
475
|
+
} catch (e) {
|
|
476
|
+
if (isLoggerUsable()) {
|
|
477
|
+
useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)} failed`);
|
|
478
|
+
useLogger().error(e);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
async publish(ctx) {
|
|
483
|
+
if (isLoggerUsable()) {
|
|
484
|
+
useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)}`);
|
|
485
|
+
}
|
|
486
|
+
const publishers = this.publishers.values();
|
|
487
|
+
while(true){
|
|
488
|
+
const it = publishers.next();
|
|
489
|
+
if (it.done) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
await it.value.publish(ctx);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
constructor(){
|
|
496
|
+
_define_property$3(this, "publishers", void 0);
|
|
497
|
+
this.publishers = new Set();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function transformEventData(input) {
|
|
502
|
+
if (kit.isObject(input)) {
|
|
503
|
+
const keys = Object.keys(input);
|
|
504
|
+
for(let i = 0; i < keys.length; i++){
|
|
505
|
+
const value = input[keys[i]];
|
|
506
|
+
if (value instanceof Date) {
|
|
507
|
+
input[keys[i]] = value.toISOString();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return input;
|
|
512
|
+
}
|
|
513
|
+
function buildEventChannelName(input, id) {
|
|
514
|
+
if (typeof input === 'string') {
|
|
515
|
+
return input;
|
|
516
|
+
}
|
|
517
|
+
return input(id);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/*
|
|
521
|
+
* Copyright (c) 2023-2024.
|
|
522
|
+
* Author Peter Placzek (tada5hi)
|
|
523
|
+
* For the full copyright and license information,
|
|
524
|
+
* view the LICENSE file that was distributed with this source code.
|
|
525
|
+
*/ function _define_property$2(obj, key, value) {
|
|
526
|
+
if (key in obj) {
|
|
527
|
+
Object.defineProperty(obj, key, {
|
|
528
|
+
value: value,
|
|
529
|
+
enumerable: true,
|
|
530
|
+
configurable: true,
|
|
531
|
+
writable: true
|
|
532
|
+
});
|
|
533
|
+
} else {
|
|
534
|
+
obj[key] = value;
|
|
535
|
+
}
|
|
536
|
+
return obj;
|
|
537
|
+
}
|
|
538
|
+
class DomainEventRedisPublisher {
|
|
539
|
+
async publish(ctx) {
|
|
540
|
+
const data = JSON.stringify(transformEventData(ctx.data));
|
|
541
|
+
const pipeline = this.driver.pipeline();
|
|
542
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
543
|
+
const keyPrefix = ctx.destinations[i].namespace ? `${ctx.destinations[i].namespace}:` : '';
|
|
544
|
+
let key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel);
|
|
545
|
+
pipeline.publish(key, data);
|
|
546
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
547
|
+
key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id);
|
|
548
|
+
pipeline.publish(key, data);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
await pipeline.exec();
|
|
552
|
+
}
|
|
553
|
+
constructor(client){
|
|
554
|
+
_define_property$2(this, "driver", void 0);
|
|
555
|
+
this.driver = client;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/*
|
|
560
|
+
* Copyright (c) 2022-2024.
|
|
561
|
+
* Author Peter Placzek (tada5hi)
|
|
562
|
+
* For the full copyright and license information,
|
|
563
|
+
* view the LICENSE file that was distributed with this source code.
|
|
564
|
+
*/ function _define_property$1(obj, key, value) {
|
|
565
|
+
if (key in obj) {
|
|
566
|
+
Object.defineProperty(obj, key, {
|
|
567
|
+
value: value,
|
|
568
|
+
enumerable: true,
|
|
569
|
+
configurable: true,
|
|
570
|
+
writable: true
|
|
571
|
+
});
|
|
572
|
+
} else {
|
|
573
|
+
obj[key] = value;
|
|
574
|
+
}
|
|
575
|
+
return obj;
|
|
576
|
+
}
|
|
577
|
+
class DomainEventSocketPublisher {
|
|
578
|
+
async publish(ctx) {
|
|
579
|
+
ctx.data = transformEventData(ctx.data);
|
|
580
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
581
|
+
let namespace;
|
|
582
|
+
if (ctx.destinations[i].namespace) {
|
|
583
|
+
namespace = ctx.destinations[i].namespace;
|
|
584
|
+
} else {
|
|
585
|
+
namespace = '/';
|
|
586
|
+
}
|
|
587
|
+
const emitter = new redisEmitter.Emitter(this.client, {}, namespace);
|
|
588
|
+
const fullEventName = kit.buildDomainEventFullName(ctx.data.type, ctx.data.event);
|
|
589
|
+
const rooms = [
|
|
590
|
+
buildEventChannelName(ctx.destinations[i].channel)
|
|
591
|
+
];
|
|
592
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
593
|
+
rooms.push(buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id));
|
|
594
|
+
}
|
|
595
|
+
for(let j = 0; j < rooms.length; j++){
|
|
596
|
+
emitter.in(rooms[j]).emit(fullEventName, {
|
|
597
|
+
...ctx.data,
|
|
598
|
+
meta: {
|
|
599
|
+
namespace,
|
|
600
|
+
roomName: rooms[j]
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
constructor(client){
|
|
607
|
+
_define_property$1(this, "client", void 0);
|
|
608
|
+
this.client = client;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const instance$1 = singa.singa({
|
|
613
|
+
name: 'domainEventPublisher',
|
|
614
|
+
factory: ()=>{
|
|
615
|
+
const publisher = new DomainEventPublisher();
|
|
616
|
+
if (isRedisClientUsable()) {
|
|
617
|
+
const client = useRedisClient();
|
|
618
|
+
publisher.addPublisher(new DomainEventRedisPublisher(client));
|
|
619
|
+
publisher.addPublisher(new DomainEventSocketPublisher(client));
|
|
620
|
+
}
|
|
621
|
+
return publisher;
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
function useDomainEventPublisher() {
|
|
448
625
|
return instance$1.use();
|
|
449
626
|
}
|
|
450
627
|
|
|
@@ -559,75 +736,6 @@ function useQueueRouter() {
|
|
|
559
736
|
return instance.use();
|
|
560
737
|
}
|
|
561
738
|
|
|
562
|
-
function transformDomainEventData(input) {
|
|
563
|
-
if (kit.isObject(input)) {
|
|
564
|
-
const keys = Object.keys(input);
|
|
565
|
-
for(let i = 0; i < keys.length; i++){
|
|
566
|
-
const value = input[keys[i]];
|
|
567
|
-
if (value instanceof Date) {
|
|
568
|
-
input[keys[i]] = value.toISOString();
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
return input;
|
|
573
|
-
}
|
|
574
|
-
function buildDomainEventChannelName(input, id) {
|
|
575
|
-
if (typeof input === 'string') {
|
|
576
|
-
return input;
|
|
577
|
-
}
|
|
578
|
-
return input(id);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
async function publishDomainRedisEvent(client, context, destinations) {
|
|
582
|
-
context = transformDomainEventData(context);
|
|
583
|
-
const json = JSON.stringify(context);
|
|
584
|
-
const pipeline = client.pipeline();
|
|
585
|
-
for(let i = 0; i < destinations.length; i++){
|
|
586
|
-
const { namespace } = destinations[i];
|
|
587
|
-
const keyPrefix = namespace ? `${namespace}:` : '';
|
|
588
|
-
let key = keyPrefix + buildDomainEventChannelName(destinations[i].channel);
|
|
589
|
-
pipeline.publish(key, json);
|
|
590
|
-
if (context.event !== coreKit.DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
591
|
-
key = keyPrefix + buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
592
|
-
pipeline.publish(key, json);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return pipeline.exec();
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
function publishDomainSocketEvent(client, context, destinations) {
|
|
599
|
-
context = transformDomainEventData(context);
|
|
600
|
-
for(let i = 0; i < destinations.length; i++){
|
|
601
|
-
let emitter = new redisEmitter.Emitter(client);
|
|
602
|
-
if (destinations[i].namespace) {
|
|
603
|
-
emitter = emitter.of(destinations[i].namespace);
|
|
604
|
-
}
|
|
605
|
-
let roomName = buildDomainEventChannelName(destinations[i].channel);
|
|
606
|
-
const fullEventName = coreKit.buildDomainEventFullName(context.type, context.event);
|
|
607
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
608
|
-
...context,
|
|
609
|
-
meta: {
|
|
610
|
-
roomName
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
if (context.event !== coreKit.DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
614
|
-
roomName = buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
615
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
616
|
-
...context,
|
|
617
|
-
meta: {
|
|
618
|
-
roomName,
|
|
619
|
-
roomId: context.data.id
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
async function publishDomainEvent(client, context, destinations) {
|
|
627
|
-
await publishDomainRedisEvent(client, context, destinations);
|
|
628
|
-
publishDomainSocketEvent(client, context, destinations);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
739
|
/*
|
|
632
740
|
* Copyright (c) 2022-2024.
|
|
633
741
|
* Author Peter Placzek (tada5hi)
|
|
@@ -664,6 +772,9 @@ Object.defineProperty(exports, "createRedisClient", {
|
|
|
664
772
|
exports.AuthupClient = AuthupClient;
|
|
665
773
|
exports.Cache = Cache;
|
|
666
774
|
exports.ComponentError = ComponentError;
|
|
775
|
+
exports.DomainEventPublisher = DomainEventPublisher;
|
|
776
|
+
exports.DomainEventRedisPublisher = DomainEventRedisPublisher;
|
|
777
|
+
exports.DomainEventSocketPublisher = DomainEventSocketPublisher;
|
|
667
778
|
exports.MemoryCacheAdapter = MemoryCacheAdapter;
|
|
668
779
|
exports.QueueRouter = QueueRouter;
|
|
669
780
|
exports.QueueRouterRoutingType = QueueRouterRoutingType;
|
|
@@ -684,9 +795,6 @@ exports.isQueueRouterPayload = isQueueRouterPayload;
|
|
|
684
795
|
exports.isQueueRouterUsable = isQueueRouterUsable;
|
|
685
796
|
exports.isRedisClientUsable = isRedisClientUsable;
|
|
686
797
|
exports.isVaultClientUsable = isVaultClientUsable;
|
|
687
|
-
exports.publishDomainEvent = publishDomainEvent;
|
|
688
|
-
exports.publishDomainRedisEvent = publishDomainRedisEvent;
|
|
689
|
-
exports.publishDomainSocketEvent = publishDomainSocketEvent;
|
|
690
798
|
exports.setAmqpClientFactory = setAmqpClientFactory;
|
|
691
799
|
exports.setAuthupClientFactory = setAuthupClientFactory;
|
|
692
800
|
exports.setClientAuthenticationHookFactory = setClientAuthenticationHookFactory;
|
|
@@ -699,6 +807,7 @@ exports.useAmqpClient = useAmqpClient;
|
|
|
699
807
|
exports.useAuthupClient = useAuthupClient;
|
|
700
808
|
exports.useCache = useCache;
|
|
701
809
|
exports.useClientAuthenticationHook = useClientAuthenticationHook;
|
|
810
|
+
exports.useDomainEventPublisher = useDomainEventPublisher;
|
|
702
811
|
exports.useLogger = useLogger;
|
|
703
812
|
exports.useQueueRouter = useQueueRouter;
|
|
704
813
|
exports.useRedisClient = useRedisClient;
|