@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/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, hasOwnProperty as hasOwnProperty$1, createNanoID } from '@privateaim/kit';
|
|
1
|
+
import { isObject, hasOwnProperty as hasOwnProperty$1, createNanoID, buildDomainEventFullName } from '@privateaim/kit';
|
|
2
2
|
import { ExchangeType } from 'amqp-extension';
|
|
3
3
|
import { singa } from 'singa';
|
|
4
4
|
export { VaultClient, createClient as createVaultClient } from '@hapic/vault';
|
|
@@ -10,7 +10,6 @@ import { read } from 'envix';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { EnvironmentName } from 'typeorm-extension';
|
|
12
12
|
import { transports, createLogger as createLogger$1, format } from 'winston';
|
|
13
|
-
import { DomainEventName, buildDomainEventFullName } from '@privateaim/core-kit';
|
|
14
13
|
import { Emitter } from '@socket.io/redis-emitter';
|
|
15
14
|
|
|
16
15
|
/*
|
|
@@ -18,7 +17,7 @@ import { Emitter } from '@socket.io/redis-emitter';
|
|
|
18
17
|
* Author Peter Placzek (tada5hi)
|
|
19
18
|
* For the full copyright and license information,
|
|
20
19
|
* view the LICENSE file that was distributed with this source code.
|
|
21
|
-
*/ function _define_property$
|
|
20
|
+
*/ function _define_property$7(obj, key, value) {
|
|
22
21
|
if (key in obj) {
|
|
23
22
|
Object.defineProperty(obj, key, {
|
|
24
23
|
value: value,
|
|
@@ -35,7 +34,7 @@ class ComponentError extends Error {
|
|
|
35
34
|
constructor(input){
|
|
36
35
|
super(input.message, {
|
|
37
36
|
cause: input.cause
|
|
38
|
-
}), _define_property$
|
|
37
|
+
}), _define_property$7(this, "code", void 0);
|
|
39
38
|
this.code = input.code;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
@@ -83,30 +82,30 @@ function isQueueRouterPayload(input) {
|
|
|
83
82
|
return isObject(input) && typeof input.id === 'string' && typeof input.type === 'string' && hasOwnProperty$1(input, 'data') && isObject(input.data) && hasOwnProperty$1(input, 'metadata') && isObject(input.metadata);
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
const instance$
|
|
85
|
+
const instance$a = singa({
|
|
87
86
|
name: 'amqp'
|
|
88
87
|
});
|
|
89
88
|
function setAmqpClientFactory(factory) {
|
|
90
|
-
instance$
|
|
89
|
+
instance$a.setFactory(factory);
|
|
91
90
|
}
|
|
92
91
|
function isAmqpClientUsable() {
|
|
93
|
-
return instance$
|
|
92
|
+
return instance$a.has() || instance$a.hasFactory();
|
|
94
93
|
}
|
|
95
94
|
function useAmqpClient() {
|
|
96
|
-
return instance$
|
|
95
|
+
return instance$a.use();
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
const instance$
|
|
98
|
+
const instance$9 = singa({
|
|
100
99
|
name: 'vault'
|
|
101
100
|
});
|
|
102
101
|
function setVaultFactory(factory) {
|
|
103
|
-
instance$
|
|
102
|
+
instance$9.setFactory(factory);
|
|
104
103
|
}
|
|
105
104
|
function isVaultClientUsable() {
|
|
106
|
-
return instance$
|
|
105
|
+
return instance$9.has() || instance$9.hasFactory();
|
|
107
106
|
}
|
|
108
107
|
function useVaultClient() {
|
|
109
|
-
return instance$
|
|
108
|
+
return instance$9.use();
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
function guessAuthupTokenCreatorOptions() {
|
|
@@ -127,17 +126,17 @@ function guessAuthupTokenCreatorOptions() {
|
|
|
127
126
|
return options;
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
const instance$
|
|
129
|
+
const instance$8 = singa({
|
|
131
130
|
name: 'clientAuthenticationHook'
|
|
132
131
|
});
|
|
133
132
|
function setClientAuthenticationHookFactory(factory) {
|
|
134
|
-
instance$
|
|
133
|
+
instance$8.setFactory(factory);
|
|
135
134
|
}
|
|
136
135
|
function isClientAuthenticationHookUsable() {
|
|
137
|
-
return instance$
|
|
136
|
+
return instance$8.has() || instance$8.hasFactory();
|
|
138
137
|
}
|
|
139
138
|
function useClientAuthenticationHook() {
|
|
140
|
-
return instance$
|
|
139
|
+
return instance$8.use();
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
class AuthupClient extends Client {
|
|
@@ -154,49 +153,49 @@ class AuthupClient extends Client {
|
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
const instance$
|
|
156
|
+
const instance$7 = singa({
|
|
158
157
|
name: 'authup'
|
|
159
158
|
});
|
|
160
159
|
function useAuthupClient() {
|
|
161
|
-
return instance$
|
|
160
|
+
return instance$7.use();
|
|
162
161
|
}
|
|
163
162
|
function isAuthupClientUsable() {
|
|
164
|
-
return instance$
|
|
163
|
+
return instance$7.has() || instance$7.hasFactory();
|
|
165
164
|
}
|
|
166
165
|
function setAuthupClientFactory(factory) {
|
|
167
|
-
instance$
|
|
166
|
+
instance$7.setFactory(factory);
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
const instance$
|
|
169
|
+
const instance$6 = singa({
|
|
171
170
|
name: 'redis'
|
|
172
171
|
});
|
|
173
172
|
function setRedisFactory(factory) {
|
|
174
|
-
instance$
|
|
173
|
+
instance$6.setFactory(factory);
|
|
175
174
|
}
|
|
176
175
|
function isRedisClientUsable() {
|
|
177
|
-
return instance$
|
|
176
|
+
return instance$6.has() || instance$6.hasFactory();
|
|
178
177
|
}
|
|
179
178
|
function setRedisClient(input) {
|
|
180
|
-
instance$
|
|
179
|
+
instance$6.set(input);
|
|
181
180
|
}
|
|
182
181
|
function useRedisClient() {
|
|
183
|
-
return instance$
|
|
182
|
+
return instance$6.use();
|
|
184
183
|
}
|
|
185
184
|
|
|
186
|
-
const instance$
|
|
185
|
+
const instance$5 = singa({
|
|
187
186
|
name: 'redisPublish',
|
|
188
187
|
factory: ()=>useRedisClient().duplicate()
|
|
189
188
|
});
|
|
190
189
|
function useRedisPublishClient() {
|
|
191
|
-
return instance$
|
|
190
|
+
return instance$5.use();
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
const instance$
|
|
193
|
+
const instance$4 = singa({
|
|
195
194
|
name: 'redisSubscribe',
|
|
196
195
|
factory: ()=>useRedisClient().duplicate()
|
|
197
196
|
});
|
|
198
197
|
function useRedisSubscribeClient() {
|
|
199
|
-
return instance$
|
|
198
|
+
return instance$4.use();
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
/*
|
|
@@ -204,7 +203,7 @@ function useRedisSubscribeClient() {
|
|
|
204
203
|
* Author Peter Placzek (tada5hi)
|
|
205
204
|
* For the full copyright and license information,
|
|
206
205
|
* view the LICENSE file that was distributed with this source code.
|
|
207
|
-
*/ function _define_property$
|
|
206
|
+
*/ function _define_property$6(obj, key, value) {
|
|
208
207
|
if (key in obj) {
|
|
209
208
|
Object.defineProperty(obj, key, {
|
|
210
209
|
value: value,
|
|
@@ -252,7 +251,7 @@ class MemoryCacheAdapter {
|
|
|
252
251
|
this.instance.clear();
|
|
253
252
|
}
|
|
254
253
|
constructor(options = {}){
|
|
255
|
-
_define_property$
|
|
254
|
+
_define_property$6(this, "instance", void 0);
|
|
256
255
|
this.instance = new TTLCache({
|
|
257
256
|
checkAgeOnGet: true,
|
|
258
257
|
ttl: Infinity,
|
|
@@ -266,7 +265,7 @@ class MemoryCacheAdapter {
|
|
|
266
265
|
* Author Peter Placzek (tada5hi)
|
|
267
266
|
* For the full copyright and license information,
|
|
268
267
|
* view the LICENSE file that was distributed with this source code.
|
|
269
|
-
*/ function _define_property$
|
|
268
|
+
*/ function _define_property$5(obj, key, value) {
|
|
270
269
|
if (key in obj) {
|
|
271
270
|
Object.defineProperty(obj, key, {
|
|
272
271
|
value: value,
|
|
@@ -315,8 +314,8 @@ class RedisCacheAdapter {
|
|
|
315
314
|
await this.client.flushdb();
|
|
316
315
|
}
|
|
317
316
|
constructor(){
|
|
318
|
-
_define_property$
|
|
319
|
-
_define_property$
|
|
317
|
+
_define_property$5(this, "client", void 0);
|
|
318
|
+
_define_property$5(this, "instance", void 0);
|
|
320
319
|
this.client = useRedisClient();
|
|
321
320
|
this.instance = new JsonAdapter(this.client);
|
|
322
321
|
}
|
|
@@ -338,7 +337,7 @@ function buildCacheKey(options) {
|
|
|
338
337
|
* Author Peter Placzek (tada5hi)
|
|
339
338
|
* For the full copyright and license information,
|
|
340
339
|
* view the LICENSE file that was distributed with this source code.
|
|
341
|
-
*/ function _define_property$
|
|
340
|
+
*/ function _define_property$4(obj, key, value) {
|
|
342
341
|
if (key in obj) {
|
|
343
342
|
Object.defineProperty(obj, key, {
|
|
344
343
|
value: value,
|
|
@@ -371,12 +370,12 @@ class Cache {
|
|
|
371
370
|
return this.adapter.clear(options);
|
|
372
371
|
}
|
|
373
372
|
constructor(adapter){
|
|
374
|
-
_define_property$
|
|
373
|
+
_define_property$4(this, "adapter", void 0);
|
|
375
374
|
this.adapter = adapter;
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
377
|
|
|
379
|
-
const instance$
|
|
378
|
+
const instance$3 = singa({
|
|
380
379
|
name: 'cache',
|
|
381
380
|
factory: ()=>{
|
|
382
381
|
let adapter;
|
|
@@ -389,7 +388,7 @@ const instance$2 = singa({
|
|
|
389
388
|
}
|
|
390
389
|
});
|
|
391
390
|
function useCache() {
|
|
392
|
-
return instance$
|
|
391
|
+
return instance$3.use();
|
|
393
392
|
}
|
|
394
393
|
|
|
395
394
|
function createLogger(ctx = {}) {
|
|
@@ -431,19 +430,197 @@ function createLogger(ctx = {}) {
|
|
|
431
430
|
});
|
|
432
431
|
}
|
|
433
432
|
|
|
434
|
-
const instance$
|
|
433
|
+
const instance$2 = singa({
|
|
435
434
|
name: 'logger'
|
|
436
435
|
});
|
|
437
436
|
function setLoggerFactory(factory) {
|
|
438
|
-
instance$
|
|
437
|
+
instance$2.setFactory(factory);
|
|
439
438
|
}
|
|
440
439
|
function isLoggerUsable() {
|
|
441
|
-
return instance$
|
|
440
|
+
return instance$2.has() || instance$2.hasFactory();
|
|
442
441
|
}
|
|
443
442
|
function setLogger(input) {
|
|
444
|
-
instance$
|
|
443
|
+
instance$2.set(input);
|
|
445
444
|
}
|
|
446
445
|
function useLogger() {
|
|
446
|
+
return instance$2.use();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/*
|
|
450
|
+
* Copyright (c) 2024-2024.
|
|
451
|
+
* Author Peter Placzek (tada5hi)
|
|
452
|
+
* For the full copyright and license information,
|
|
453
|
+
* view the LICENSE file that was distributed with this source code.
|
|
454
|
+
*/ function _define_property$3(obj, key, value) {
|
|
455
|
+
if (key in obj) {
|
|
456
|
+
Object.defineProperty(obj, key, {
|
|
457
|
+
value: value,
|
|
458
|
+
enumerable: true,
|
|
459
|
+
configurable: true,
|
|
460
|
+
writable: true
|
|
461
|
+
});
|
|
462
|
+
} else {
|
|
463
|
+
obj[key] = value;
|
|
464
|
+
}
|
|
465
|
+
return obj;
|
|
466
|
+
}
|
|
467
|
+
class DomainEventPublisher {
|
|
468
|
+
addPublisher(publisher) {
|
|
469
|
+
this.publishers.add(publisher);
|
|
470
|
+
}
|
|
471
|
+
async safePublish(ctx) {
|
|
472
|
+
try {
|
|
473
|
+
await this.publish(ctx);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
if (isLoggerUsable()) {
|
|
476
|
+
useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.data.type, ctx.data.event)} failed`);
|
|
477
|
+
useLogger().error(e);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
async publish(ctx) {
|
|
482
|
+
if (isLoggerUsable()) {
|
|
483
|
+
useLogger().info(`Publishing event ${buildDomainEventFullName(ctx.data.type, ctx.data.event)}`);
|
|
484
|
+
}
|
|
485
|
+
const publishers = this.publishers.values();
|
|
486
|
+
while(true){
|
|
487
|
+
const it = publishers.next();
|
|
488
|
+
if (it.done) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
await it.value.publish(ctx);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
constructor(){
|
|
495
|
+
_define_property$3(this, "publishers", void 0);
|
|
496
|
+
this.publishers = new Set();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function transformEventData(input) {
|
|
501
|
+
if (isObject(input)) {
|
|
502
|
+
const keys = Object.keys(input);
|
|
503
|
+
for(let i = 0; i < keys.length; i++){
|
|
504
|
+
const value = input[keys[i]];
|
|
505
|
+
if (value instanceof Date) {
|
|
506
|
+
input[keys[i]] = value.toISOString();
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return input;
|
|
511
|
+
}
|
|
512
|
+
function buildEventChannelName(input, id) {
|
|
513
|
+
if (typeof input === 'string') {
|
|
514
|
+
return input;
|
|
515
|
+
}
|
|
516
|
+
return input(id);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/*
|
|
520
|
+
* Copyright (c) 2023-2024.
|
|
521
|
+
* Author Peter Placzek (tada5hi)
|
|
522
|
+
* For the full copyright and license information,
|
|
523
|
+
* view the LICENSE file that was distributed with this source code.
|
|
524
|
+
*/ function _define_property$2(obj, key, value) {
|
|
525
|
+
if (key in obj) {
|
|
526
|
+
Object.defineProperty(obj, key, {
|
|
527
|
+
value: value,
|
|
528
|
+
enumerable: true,
|
|
529
|
+
configurable: true,
|
|
530
|
+
writable: true
|
|
531
|
+
});
|
|
532
|
+
} else {
|
|
533
|
+
obj[key] = value;
|
|
534
|
+
}
|
|
535
|
+
return obj;
|
|
536
|
+
}
|
|
537
|
+
class DomainEventRedisPublisher {
|
|
538
|
+
async publish(ctx) {
|
|
539
|
+
const data = JSON.stringify(transformEventData(ctx.data));
|
|
540
|
+
const pipeline = this.driver.pipeline();
|
|
541
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
542
|
+
const keyPrefix = ctx.destinations[i].namespace ? `${ctx.destinations[i].namespace}:` : '';
|
|
543
|
+
let key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel);
|
|
544
|
+
pipeline.publish(key, data);
|
|
545
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
546
|
+
key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id);
|
|
547
|
+
pipeline.publish(key, data);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
await pipeline.exec();
|
|
551
|
+
}
|
|
552
|
+
constructor(client){
|
|
553
|
+
_define_property$2(this, "driver", void 0);
|
|
554
|
+
this.driver = client;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/*
|
|
559
|
+
* Copyright (c) 2022-2024.
|
|
560
|
+
* Author Peter Placzek (tada5hi)
|
|
561
|
+
* For the full copyright and license information,
|
|
562
|
+
* view the LICENSE file that was distributed with this source code.
|
|
563
|
+
*/ function _define_property$1(obj, key, value) {
|
|
564
|
+
if (key in obj) {
|
|
565
|
+
Object.defineProperty(obj, key, {
|
|
566
|
+
value: value,
|
|
567
|
+
enumerable: true,
|
|
568
|
+
configurable: true,
|
|
569
|
+
writable: true
|
|
570
|
+
});
|
|
571
|
+
} else {
|
|
572
|
+
obj[key] = value;
|
|
573
|
+
}
|
|
574
|
+
return obj;
|
|
575
|
+
}
|
|
576
|
+
class DomainEventSocketPublisher {
|
|
577
|
+
async publish(ctx) {
|
|
578
|
+
ctx.data = transformEventData(ctx.data);
|
|
579
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
580
|
+
let namespace;
|
|
581
|
+
if (ctx.destinations[i].namespace) {
|
|
582
|
+
namespace = ctx.destinations[i].namespace;
|
|
583
|
+
} else {
|
|
584
|
+
namespace = '/';
|
|
585
|
+
}
|
|
586
|
+
const emitter = new Emitter(this.client, {}, namespace);
|
|
587
|
+
const fullEventName = buildDomainEventFullName(ctx.data.type, ctx.data.event);
|
|
588
|
+
const rooms = [
|
|
589
|
+
buildEventChannelName(ctx.destinations[i].channel)
|
|
590
|
+
];
|
|
591
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
592
|
+
rooms.push(buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id));
|
|
593
|
+
}
|
|
594
|
+
for(let j = 0; j < rooms.length; j++){
|
|
595
|
+
emitter.in(rooms[j]).emit(fullEventName, {
|
|
596
|
+
...ctx.data,
|
|
597
|
+
meta: {
|
|
598
|
+
namespace,
|
|
599
|
+
roomName: rooms[j]
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
constructor(client){
|
|
606
|
+
_define_property$1(this, "client", void 0);
|
|
607
|
+
this.client = client;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const instance$1 = singa({
|
|
612
|
+
name: 'domainEventPublisher',
|
|
613
|
+
factory: ()=>{
|
|
614
|
+
const publisher = new DomainEventPublisher();
|
|
615
|
+
if (isRedisClientUsable()) {
|
|
616
|
+
const client = useRedisClient();
|
|
617
|
+
publisher.addPublisher(new DomainEventRedisPublisher(client));
|
|
618
|
+
publisher.addPublisher(new DomainEventSocketPublisher(client));
|
|
619
|
+
}
|
|
620
|
+
return publisher;
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
function useDomainEventPublisher() {
|
|
447
624
|
return instance$1.use();
|
|
448
625
|
}
|
|
449
626
|
|
|
@@ -558,75 +735,6 @@ function useQueueRouter() {
|
|
|
558
735
|
return instance.use();
|
|
559
736
|
}
|
|
560
737
|
|
|
561
|
-
function transformDomainEventData(input) {
|
|
562
|
-
if (isObject(input)) {
|
|
563
|
-
const keys = Object.keys(input);
|
|
564
|
-
for(let i = 0; i < keys.length; i++){
|
|
565
|
-
const value = input[keys[i]];
|
|
566
|
-
if (value instanceof Date) {
|
|
567
|
-
input[keys[i]] = value.toISOString();
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
return input;
|
|
572
|
-
}
|
|
573
|
-
function buildDomainEventChannelName(input, id) {
|
|
574
|
-
if (typeof input === 'string') {
|
|
575
|
-
return input;
|
|
576
|
-
}
|
|
577
|
-
return input(id);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
async function publishDomainRedisEvent(client, context, destinations) {
|
|
581
|
-
context = transformDomainEventData(context);
|
|
582
|
-
const json = JSON.stringify(context);
|
|
583
|
-
const pipeline = client.pipeline();
|
|
584
|
-
for(let i = 0; i < destinations.length; i++){
|
|
585
|
-
const { namespace } = destinations[i];
|
|
586
|
-
const keyPrefix = namespace ? `${namespace}:` : '';
|
|
587
|
-
let key = keyPrefix + buildDomainEventChannelName(destinations[i].channel);
|
|
588
|
-
pipeline.publish(key, json);
|
|
589
|
-
if (context.event !== DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
590
|
-
key = keyPrefix + buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
591
|
-
pipeline.publish(key, json);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return pipeline.exec();
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function publishDomainSocketEvent(client, context, destinations) {
|
|
598
|
-
context = transformDomainEventData(context);
|
|
599
|
-
for(let i = 0; i < destinations.length; i++){
|
|
600
|
-
let emitter = new Emitter(client);
|
|
601
|
-
if (destinations[i].namespace) {
|
|
602
|
-
emitter = emitter.of(destinations[i].namespace);
|
|
603
|
-
}
|
|
604
|
-
let roomName = buildDomainEventChannelName(destinations[i].channel);
|
|
605
|
-
const fullEventName = buildDomainEventFullName(context.type, context.event);
|
|
606
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
607
|
-
...context,
|
|
608
|
-
meta: {
|
|
609
|
-
roomName
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
if (context.event !== DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
613
|
-
roomName = buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
614
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
615
|
-
...context,
|
|
616
|
-
meta: {
|
|
617
|
-
roomName,
|
|
618
|
-
roomId: context.data.id
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
async function publishDomainEvent(client, context, destinations) {
|
|
626
|
-
await publishDomainRedisEvent(client, context, destinations);
|
|
627
|
-
publishDomainSocketEvent(client, context, destinations);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
738
|
/*
|
|
631
739
|
* Copyright (c) 2022-2024.
|
|
632
740
|
* Author Peter Placzek (tada5hi)
|
|
@@ -636,5 +744,5 @@ async function publishDomainEvent(client, context, destinations) {
|
|
|
636
744
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
637
745
|
}
|
|
638
746
|
|
|
639
|
-
export { AuthupClient, Cache, ComponentError, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isClientAuthenticationHookUsable, isComponentError, isLoggerUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable,
|
|
747
|
+
export { AuthupClient, Cache, ComponentError, DomainEventPublisher, DomainEventRedisPublisher, DomainEventSocketPublisher, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isClientAuthenticationHookUsable, isComponentError, isLoggerUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable, setAmqpClientFactory, setAuthupClientFactory, setClientAuthenticationHookFactory, setLogger, setLoggerFactory, setRedisClient, setRedisFactory, setVaultFactory, useAmqpClient, useAuthupClient, useCache, useClientAuthenticationHook, useDomainEventPublisher, useLogger, useQueueRouter, useRedisClient, useRedisPublishClient, useRedisSubscribeClient, useVaultClient };
|
|
640
748
|
//# sourceMappingURL=index.mjs.map
|