@privateaim/server-kit 0.8.14 → 0.8.16

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/core/component/handler/check.d.ts +4 -0
  3. package/dist/core/component/handler/check.d.ts.map +1 -0
  4. package/dist/core/component/handler/index.d.ts +3 -0
  5. package/dist/core/component/handler/index.d.ts.map +1 -0
  6. package/dist/core/component/handler/module.d.ts +11 -0
  7. package/dist/core/component/handler/module.d.ts.map +1 -0
  8. package/dist/core/component/handler/types.d.ts +11 -0
  9. package/dist/core/component/handler/types.d.ts.map +1 -0
  10. package/dist/core/component/index.d.ts +1 -0
  11. package/dist/core/component/index.d.ts.map +1 -1
  12. package/dist/core/queue-router/module.d.ts +3 -2
  13. package/dist/core/queue-router/module.d.ts.map +1 -1
  14. package/dist/core/queue-router/types.d.ts +7 -4
  15. package/dist/core/queue-router/types.d.ts.map +1 -1
  16. package/dist/index.cjs +233 -167
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.mjs +225 -128
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/services/amqp/index.d.ts +1 -0
  21. package/dist/services/amqp/index.d.ts.map +1 -1
  22. package/dist/services/amqp/module.d.ts +2 -5
  23. package/dist/services/amqp/module.d.ts.map +1 -1
  24. package/dist/services/amqp/singleton.d.ts +6 -0
  25. package/dist/services/amqp/singleton.d.ts.map +1 -0
  26. package/dist/services/domain-event/index.d.ts +1 -1
  27. package/dist/services/domain-event/index.d.ts.map +1 -1
  28. package/dist/services/domain-event/module.d.ts +6 -6
  29. package/dist/services/domain-event/module.d.ts.map +1 -1
  30. package/dist/services/domain-event/redis/helpers.d.ts +2 -0
  31. package/dist/services/domain-event/redis/helpers.d.ts.map +1 -0
  32. package/dist/services/domain-event/redis/index.d.ts +1 -0
  33. package/dist/services/domain-event/redis/index.d.ts.map +1 -1
  34. package/dist/services/domain-event/redis/module.d.ts +3 -3
  35. package/dist/services/domain-event/redis/module.d.ts.map +1 -1
  36. package/dist/services/domain-event/singleton.d.ts +1 -0
  37. package/dist/services/domain-event/singleton.d.ts.map +1 -1
  38. package/dist/services/domain-event/socket/helpers.d.ts +3 -0
  39. package/dist/services/domain-event/socket/helpers.d.ts.map +1 -0
  40. package/dist/services/domain-event/socket/index.d.ts +1 -0
  41. package/dist/services/domain-event/socket/index.d.ts.map +1 -1
  42. package/dist/services/domain-event/socket/module.d.ts +3 -3
  43. package/dist/services/domain-event/socket/module.d.ts.map +1 -1
  44. package/dist/services/domain-event/types.d.ts +37 -0
  45. package/dist/services/domain-event/types.d.ts.map +1 -0
  46. package/dist/services/domain-event/utils.d.ts +0 -2
  47. package/dist/services/domain-event/utils.d.ts.map +1 -1
  48. package/dist/services/index.d.ts +0 -1
  49. package/dist/services/index.d.ts.map +1 -1
  50. package/dist/services/logger/module.d.ts.map +1 -1
  51. package/dist/services/logger/types.d.ts +2 -2
  52. package/dist/services/logger/types.d.ts.map +1 -1
  53. package/package.json +6 -6
  54. package/src/core/component/handler/check.ts +23 -0
  55. package/src/{services/loki → core/component/handler}/index.ts +2 -2
  56. package/src/core/component/handler/module.ts +57 -0
  57. package/src/core/component/handler/types.ts +28 -0
  58. package/src/core/component/index.ts +1 -0
  59. package/src/core/queue-router/module.ts +30 -4
  60. package/src/core/queue-router/types.ts +12 -5
  61. package/src/services/amqp/index.ts +1 -0
  62. package/src/services/amqp/module.ts +5 -19
  63. package/src/services/{loki → amqp}/singleton.ts +6 -6
  64. package/src/services/domain-event/index.ts +1 -1
  65. package/src/services/domain-event/module.ts +32 -15
  66. package/src/services/domain-event/redis/helpers.ts +28 -0
  67. package/src/services/domain-event/redis/index.ts +1 -0
  68. package/src/services/domain-event/redis/module.ts +19 -12
  69. package/src/services/domain-event/singleton.ts +9 -5
  70. package/src/services/domain-event/socket/helpers.ts +26 -0
  71. package/src/services/domain-event/socket/index.ts +1 -0
  72. package/src/services/domain-event/socket/module.ts +27 -31
  73. package/src/services/domain-event/types.ts +59 -0
  74. package/src/services/domain-event/utils.ts +0 -12
  75. package/src/services/index.ts +0 -1
  76. package/src/services/logger/module.ts +7 -17
  77. package/src/services/logger/types.ts +4 -4
  78. package/dist/services/domain-event/type.d.ts +0 -15
  79. package/dist/services/domain-event/type.d.ts.map +0 -1
  80. package/dist/services/loki/index.d.ts +0 -3
  81. package/dist/services/loki/index.d.ts.map +0 -1
  82. package/dist/services/loki/module.d.ts +0 -3
  83. package/dist/services/loki/module.d.ts.map +0 -1
  84. package/dist/services/loki/singleton.d.ts +0 -6
  85. package/dist/services/loki/singleton.d.ts.map +0 -1
  86. package/src/services/domain-event/type.ts +0 -27
  87. package/src/services/loki/module.ts +0 -30
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isObject, hasOwnProperty as hasOwnProperty$1, createNanoID, buildDomainEventFullName } from '@privateaim/kit';
2
2
  import { ExchangeType } from 'amqp-extension';
3
+ export { Client as AmqpClient } from 'amqp-extension';
3
4
  import { singa } from 'singa';
4
5
  export { VaultClient, createClient as createVaultClient } from '@hapic/vault';
5
6
  import { Client, ClientAuthenticationHook } from '@authup/core-http-kit';
@@ -7,18 +8,16 @@ import { JsonAdapter, buildKeyPath } from 'redis-extension';
7
8
  export { Client as RedisClient, ClientOptions as RedisClientOptions, buildKeyPath as buildRedisKeyPath, createClient as createRedisClient } from 'redis-extension';
8
9
  import TTLCache from '@isaacs/ttlcache';
9
10
  import { read } from 'envix';
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
13
  import { Emitter } from '@socket.io/redis-emitter';
14
- export { LokiClient, CompactorDeletionRequestCreate as LokiCompactorDeletionRequestCreate, Config as LokiConfig, ConfigInput as LokiConfigInput, DistributorPushStream as LokiDistributorPushStream, QuerierQueryRangeOptions as LokiQuerierQueryRangeOptions, QuerierQueryResult as LokiQuerierQueryResult, createClient as createLokiClient, nanoSeconds } from '@hapic/loki';
15
14
 
16
15
  /*
17
16
  * Copyright (c) 2023-2024.
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$7(obj, key, value) {
20
+ */ function _define_property$8(obj, key, value) {
22
21
  if (key in obj) {
23
22
  Object.defineProperty(obj, key, {
24
23
  value: value,
@@ -35,11 +34,81 @@ class ComponentError extends Error {
35
34
  constructor(input){
36
35
  super(input.message, {
37
36
  cause: input.cause
38
- }), _define_property$7(this, "code", void 0);
37
+ }), _define_property$8(this, "code", void 0);
39
38
  this.code = input.code;
40
39
  }
41
40
  }
42
41
 
42
+ /*
43
+ * Copyright (c) 2022-2024.
44
+ * Author Peter Placzek (tada5hi)
45
+ * For the full copyright and license information,
46
+ * view the LICENSE file that was distributed with this source code.
47
+ */ function hasOwnProperty(obj, prop) {
48
+ return Object.prototype.hasOwnProperty.call(obj, prop);
49
+ }
50
+
51
+ function isComponentHandlerFn(input) {
52
+ return typeof input === 'function';
53
+ }
54
+
55
+ /*
56
+ * Copyright (c) 2025.
57
+ * Author Peter Placzek (tada5hi)
58
+ * For the full copyright and license information,
59
+ * view the LICENSE file that was distributed with this source code.
60
+ */ function _define_property$7(obj, key, value) {
61
+ if (key in obj) {
62
+ Object.defineProperty(obj, key, {
63
+ value: value,
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true
67
+ });
68
+ } else {
69
+ obj[key] = value;
70
+ }
71
+ return obj;
72
+ }
73
+ class ComponentHandlers {
74
+ mount(key, fn) {
75
+ this.handlers[key] = fn;
76
+ }
77
+ unmount(key) {
78
+ delete this.handlers[key];
79
+ }
80
+ async setup() {
81
+ const keys = Object.keys(this.handlers);
82
+ for(let i = 0; i < keys.length; i++){
83
+ const handler = this.handlers[keys[i]];
84
+ if (!isComponentHandlerFn(handler) && handler.setup) {
85
+ await handler.setup();
86
+ }
87
+ }
88
+ }
89
+ async execute(key, value = {}, metadata = {}) {
90
+ const handler = this.handlers[key];
91
+ if (!handler) {
92
+ return;
93
+ }
94
+ if (isComponentHandlerFn(handler)) {
95
+ await handler(value, {
96
+ key,
97
+ metadata
98
+ });
99
+ } else {
100
+ await handler.handle(value, {
101
+ key,
102
+ metadata
103
+ });
104
+ }
105
+ }
106
+ constructor(){
107
+ _define_property$7(this, "handlers", void 0);
108
+ this.handlers = {};
109
+ }
110
+ }
111
+
43
112
  function isComponentError(input) {
44
113
  if (!isObject(input)) {
45
114
  return false;
@@ -83,30 +152,30 @@ function isQueueRouterPayload(input) {
83
152
  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
153
  }
85
154
 
86
- const instance$b = singa({
155
+ const instance$9 = singa({
87
156
  name: 'amqp'
88
157
  });
89
158
  function setAmqpClientFactory(factory) {
90
- instance$b.setFactory(factory);
159
+ instance$9.setFactory(factory);
91
160
  }
92
161
  function isAmqpClientUsable() {
93
- return instance$b.has() || instance$b.hasFactory();
162
+ return instance$9.has() || instance$9.hasFactory();
94
163
  }
95
164
  function useAmqpClient() {
96
- return instance$b.use();
165
+ return instance$9.use();
97
166
  }
98
167
 
99
- const instance$a = singa({
168
+ const instance$8 = singa({
100
169
  name: 'vault'
101
170
  });
102
171
  function setVaultFactory(factory) {
103
- instance$a.setFactory(factory);
172
+ instance$8.setFactory(factory);
104
173
  }
105
174
  function isVaultClientUsable() {
106
- return instance$a.has() || instance$a.hasFactory();
175
+ return instance$8.has() || instance$8.hasFactory();
107
176
  }
108
177
  function useVaultClient() {
109
- return instance$a.use();
178
+ return instance$8.use();
110
179
  }
111
180
 
112
181
  function guessAuthupTokenCreatorOptions() {
@@ -127,17 +196,17 @@ function guessAuthupTokenCreatorOptions() {
127
196
  return options;
128
197
  }
129
198
 
130
- const instance$9 = singa({
199
+ const instance$7 = singa({
131
200
  name: 'clientAuthenticationHook'
132
201
  });
133
202
  function setClientAuthenticationHookFactory(factory) {
134
- instance$9.setFactory(factory);
203
+ instance$7.setFactory(factory);
135
204
  }
136
205
  function isClientAuthenticationHookUsable() {
137
- return instance$9.has() || instance$9.hasFactory();
206
+ return instance$7.has() || instance$7.hasFactory();
138
207
  }
139
208
  function useClientAuthenticationHook() {
140
- return instance$9.use();
209
+ return instance$7.use();
141
210
  }
142
211
 
143
212
  class AuthupClient extends Client {
@@ -154,49 +223,49 @@ class AuthupClient extends Client {
154
223
  }
155
224
  }
156
225
 
157
- const instance$8 = singa({
226
+ const instance$6 = singa({
158
227
  name: 'authup'
159
228
  });
160
229
  function useAuthupClient() {
161
- return instance$8.use();
230
+ return instance$6.use();
162
231
  }
163
232
  function isAuthupClientUsable() {
164
- return instance$8.has() || instance$8.hasFactory();
233
+ return instance$6.has() || instance$6.hasFactory();
165
234
  }
166
235
  function setAuthupClientFactory(factory) {
167
- instance$8.setFactory(factory);
236
+ instance$6.setFactory(factory);
168
237
  }
169
238
 
170
- const instance$7 = singa({
239
+ const instance$5 = singa({
171
240
  name: 'redis'
172
241
  });
173
242
  function setRedisFactory(factory) {
174
- instance$7.setFactory(factory);
243
+ instance$5.setFactory(factory);
175
244
  }
176
245
  function isRedisClientUsable() {
177
- return instance$7.has() || instance$7.hasFactory();
246
+ return instance$5.has() || instance$5.hasFactory();
178
247
  }
179
248
  function setRedisClient(input) {
180
- instance$7.set(input);
249
+ instance$5.set(input);
181
250
  }
182
251
  function useRedisClient() {
183
- return instance$7.use();
252
+ return instance$5.use();
184
253
  }
185
254
 
186
- const instance$6 = singa({
255
+ const instance$4 = singa({
187
256
  name: 'redisPublish',
188
257
  factory: ()=>useRedisClient().duplicate()
189
258
  });
190
259
  function useRedisPublishClient() {
191
- return instance$6.use();
260
+ return instance$4.use();
192
261
  }
193
262
 
194
- const instance$5 = singa({
263
+ const instance$3 = singa({
195
264
  name: 'redisSubscribe',
196
265
  factory: ()=>useRedisClient().duplicate()
197
266
  });
198
267
  function useRedisSubscribeClient() {
199
- return instance$5.use();
268
+ return instance$3.use();
200
269
  }
201
270
 
202
271
  /*
@@ -376,7 +445,7 @@ class Cache {
376
445
  }
377
446
  }
378
447
 
379
- const instance$4 = singa({
448
+ const instance$2 = singa({
380
449
  name: 'cache',
381
450
  factory: ()=>{
382
451
  let adapter;
@@ -389,62 +458,56 @@ const instance$4 = singa({
389
458
  }
390
459
  });
391
460
  function useCache() {
392
- return instance$4.use();
461
+ return instance$2.use();
393
462
  }
394
463
 
464
+ function toTransports(input) {
465
+ return Array.isArray(input) ? input : [
466
+ input
467
+ ];
468
+ }
395
469
  function createLogger(ctx = {}) {
396
- const { directory, options = {} } = ctx;
397
470
  let loggerTransports;
398
471
  if (read('env') === EnvironmentName.PRODUCTION) {
399
472
  loggerTransports = [
400
473
  new transports.Console({
401
474
  level: 'info'
402
475
  }),
403
- new transports.File({
404
- filename: path.join(directory || process.cwd(), 'access.log'),
405
- level: 'http',
406
- maxsize: 10 * 1024 * 1024,
407
- maxFiles: 5
408
- }),
409
- new transports.File({
410
- filename: path.join(directory || process.cwd(), 'error.log'),
411
- level: 'warn',
412
- maxsize: 10 * 1024 * 1024,
413
- maxFiles: 5
414
- })
476
+ ...ctx.transports ? toTransports(ctx.transports) : []
415
477
  ];
416
478
  } else {
417
479
  loggerTransports = [
418
480
  new transports.Console({
419
481
  level: 'debug'
420
- })
482
+ }),
483
+ ...ctx.transports ? toTransports(ctx.transports) : []
421
484
  ];
422
485
  }
423
486
  return createLogger$1({
424
487
  format: format.combine(format.errors({
425
488
  stack: true
426
- }), format.timestamp(), format.colorize(), format.simple()),
489
+ }), format.timestamp(), format.simple()),
427
490
  level: 'debug',
428
491
  transports: loggerTransports,
429
492
  // todo: deeply merge options
430
- ...options || {}
493
+ ...ctx.options || {}
431
494
  });
432
495
  }
433
496
 
434
- const instance$3 = singa({
497
+ const instance$1 = singa({
435
498
  name: 'logger'
436
499
  });
437
500
  function setLoggerFactory(factory) {
438
- instance$3.setFactory(factory);
501
+ instance$1.setFactory(factory);
439
502
  }
440
503
  function isLoggerUsable() {
441
- return instance$3.has() || instance$3.hasFactory();
504
+ return instance$1.has() || instance$1.hasFactory();
442
505
  }
443
506
  function setLogger(input) {
444
- instance$3.set(input);
507
+ instance$1.set(input);
445
508
  }
446
509
  function useLogger() {
447
- return instance$3.use();
510
+ return instance$1.use();
448
511
  }
449
512
 
450
513
  /*
@@ -466,35 +529,45 @@ function useLogger() {
466
529
  return obj;
467
530
  }
468
531
  class DomainEventPublisher {
469
- addPublisher(publisher) {
470
- this.publishers.add(publisher);
532
+ addConsumer(consumer) {
533
+ this.consumers.add(consumer);
471
534
  }
472
535
  async safePublish(ctx) {
473
536
  try {
474
537
  await this.publish(ctx);
475
538
  } catch (e) {
476
539
  if (isLoggerUsable()) {
477
- useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.data.type, ctx.data.event)} failed`);
540
+ useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
478
541
  useLogger().error(e);
479
542
  }
480
543
  }
481
544
  }
482
545
  async publish(ctx) {
483
546
  if (isLoggerUsable()) {
484
- useLogger().info(`Publishing event ${buildDomainEventFullName(ctx.data.type, ctx.data.event)}`);
547
+ useLogger().info(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)}`);
548
+ }
549
+ let destinations = [];
550
+ if (typeof ctx.destinations === 'function') {
551
+ destinations = ctx.destinations(ctx.data);
552
+ } else {
553
+ destinations = ctx.destinations;
485
554
  }
486
- const publishers = this.publishers.values();
555
+ const consumeContext = {
556
+ ...ctx,
557
+ destinations
558
+ };
559
+ const consumers = this.consumers.values();
487
560
  while(true){
488
- const it = publishers.next();
561
+ const it = consumers.next();
489
562
  if (it.done) {
490
563
  return;
491
564
  }
492
- await it.value.publish(ctx);
565
+ await it.value.consume(consumeContext);
493
566
  }
494
567
  }
495
568
  constructor(){
496
- _define_property$3(this, "publishers", void 0);
497
- this.publishers = new Set();
569
+ _define_property$3(this, "consumers", void 0);
570
+ this.consumers = new Set();
498
571
  }
499
572
  }
500
573
 
@@ -510,11 +583,25 @@ function transformEventData(input) {
510
583
  }
511
584
  return input;
512
585
  }
513
- function buildEventChannelName(input, id) {
514
- if (typeof input === 'string') {
515
- return input;
586
+
587
+ /*
588
+ * Copyright (c) 2025.
589
+ * Author Peter Placzek (tada5hi)
590
+ * For the full copyright and license information,
591
+ * view the LICENSE file that was distributed with this source code.
592
+ */ function stringify(input) {
593
+ return typeof input === 'string' ? input : input.join('/');
594
+ }
595
+ function buildDomainEventRedisChannel(channel, namespace) {
596
+ const channelNormalized = stringify(channel);
597
+ let namespaceNormalized;
598
+ if (namespace) {
599
+ namespaceNormalized = stringify(namespace);
516
600
  }
517
- return input(id);
601
+ if (typeof namespaceNormalized === 'undefined') {
602
+ return channelNormalized;
603
+ }
604
+ return `${namespaceNormalized}/${channelNormalized}`;
518
605
  }
519
606
 
520
607
  /*
@@ -536,17 +623,18 @@ function buildEventChannelName(input, id) {
536
623
  return obj;
537
624
  }
538
625
  class DomainEventRedisPublisher {
539
- async publish(ctx) {
540
- const data = JSON.stringify(transformEventData(ctx.data));
626
+ async consume(ctx) {
627
+ const payload = {
628
+ type: ctx.metadata.domain,
629
+ event: ctx.metadata.event,
630
+ data: transformEventData(ctx.data)
631
+ };
632
+ const payloadSerialized = JSON.stringify(payload);
541
633
  const pipeline = this.driver.pipeline();
542
634
  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
- }
635
+ const destination = ctx.destinations[i];
636
+ const key = buildDomainEventRedisChannel(destination.channel, destination.namespace);
637
+ pipeline.publish(key, payloadSerialized);
550
638
  }
551
639
  await pipeline.exec();
552
640
  }
@@ -556,6 +644,27 @@ class DomainEventRedisPublisher {
556
644
  }
557
645
  }
558
646
 
647
+ /*
648
+ * Copyright (c) 2025.
649
+ * Author Peter Placzek (tada5hi)
650
+ * For the full copyright and license information,
651
+ * view the LICENSE file that was distributed with this source code.
652
+ */ function buildDomainEventSocketNamespace(namespace) {
653
+ if (typeof namespace === 'undefined') {
654
+ return '/';
655
+ }
656
+ if (typeof namespace === 'string') {
657
+ return namespace.startsWith('/') ? namespace : `/${namespace}`;
658
+ }
659
+ return `/${namespace.join('/')}`;
660
+ }
661
+ function buildDomainEventSocketChannel(channel) {
662
+ if (typeof channel === 'string') {
663
+ return channel;
664
+ }
665
+ return channel.join('/');
666
+ }
667
+
559
668
  /*
560
669
  * Copyright (c) 2022-2024.
561
670
  * Author Peter Placzek (tada5hi)
@@ -574,33 +683,26 @@ class DomainEventRedisPublisher {
574
683
  }
575
684
  return obj;
576
685
  }
577
- class DomainEventSocketPublisher {
578
- async publish(ctx) {
686
+ class DomainEventSocketConsumer {
687
+ async consume(ctx) {
579
688
  ctx.data = transformEventData(ctx.data);
580
689
  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
- }
690
+ const destination = ctx.destinations[i];
691
+ const namespace = buildDomainEventSocketNamespace(destination.namespace);
692
+ const roomName = buildDomainEventSocketChannel(destination.channel);
693
+ const fullEventName = buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event);
587
694
  const emitter = new Emitter(this.client, {}, namespace);
588
- const fullEventName = 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
- }
695
+ emitter.in(roomName).emit(fullEventName, {
696
+ data: {
697
+ data: ctx.data,
698
+ type: ctx.metadata.domain,
699
+ event: ctx.metadata.event
700
+ },
701
+ meta: {
702
+ namespace,
703
+ roomName
704
+ }
705
+ });
604
706
  }
605
707
  }
606
708
  constructor(client){
@@ -609,33 +711,23 @@ class DomainEventSocketPublisher {
609
711
  }
610
712
  }
611
713
 
612
- const instance$2 = singa({
714
+ const singaInstance = singa({
613
715
  name: 'domainEventPublisher',
614
716
  factory: ()=>{
615
717
  const publisher = new DomainEventPublisher();
616
718
  if (isRedisClientUsable()) {
617
719
  const client = useRedisClient();
618
- publisher.addPublisher(new DomainEventRedisPublisher(client));
619
- publisher.addPublisher(new DomainEventSocketPublisher(client));
720
+ publisher.addConsumer(new DomainEventRedisPublisher(client));
721
+ publisher.addConsumer(new DomainEventSocketConsumer(client));
620
722
  }
621
723
  return publisher;
622
724
  }
623
725
  });
624
- function useDomainEventPublisher() {
625
- return instance$2.use();
626
- }
627
-
628
- const instance$1 = singa({
629
- name: 'loki'
630
- });
631
- function setLokiFactory(factory) {
632
- instance$1.setFactory(factory);
633
- }
634
- function isLokiClientUsable() {
635
- return instance$1.has() || instance$1.hasFactory();
726
+ function useDomainEventPublisherSinga() {
727
+ return singaInstance;
636
728
  }
637
- function useLokiClient() {
638
- return instance$1.use();
729
+ function useDomainEventPublisher() {
730
+ return singaInstance.use();
639
731
  }
640
732
 
641
733
  /*
@@ -658,7 +750,9 @@ function useLokiClient() {
658
750
  }
659
751
  class QueueRouter {
660
752
  //----------------------------------------------------------------
661
- publish(message) {
753
+ publish(message, options = {}) {
754
+ var _options;
755
+ (_options = options).logging ?? (_options.logging = true);
662
756
  let exchange;
663
757
  if (message.metadata.routing.type === 'work') {
664
758
  exchange = this.driver.of({
@@ -671,7 +765,7 @@ class QueueRouter {
671
765
  name: message.metadata.routing.namespace || 'FLAME'
672
766
  });
673
767
  }
674
- if (isLoggerUsable()) {
768
+ if (options.logging && isLoggerUsable()) {
675
769
  useLogger().debug(`Publishing queue message ${message.type} in ${message.metadata.routing.key}`);
676
770
  }
677
771
  return exchange.publish(message.metadata.routing.key, message, {
@@ -680,6 +774,11 @@ class QueueRouter {
680
774
  persistent: message.metadata.persistent ?? message.metadata.routing.type === QueueRouterRoutingType.WORK
681
775
  });
682
776
  }
777
+ consumeAny(routing, fn) {
778
+ return this.consume(routing, {
779
+ $any: (payload)=>fn(payload)
780
+ });
781
+ }
683
782
  consume(routing, handlers) {
684
783
  let exchange;
685
784
  if (routing.type === 'work') {
@@ -724,7 +823,14 @@ class QueueRouter {
724
823
  }
725
824
  return;
726
825
  }
727
- await handler(payload);
826
+ try {
827
+ await handler(payload);
828
+ } catch (e) {
829
+ if (isLoggerUsable()) {
830
+ useLogger().error(e);
831
+ }
832
+ throw e;
833
+ }
728
834
  }
729
835
  });
730
836
  }
@@ -749,14 +855,5 @@ function useQueueRouter() {
749
855
  return instance.use();
750
856
  }
751
857
 
752
- /*
753
- * Copyright (c) 2022-2024.
754
- * Author Peter Placzek (tada5hi)
755
- * For the full copyright and license information,
756
- * view the LICENSE file that was distributed with this source code.
757
- */ function hasOwnProperty(obj, prop) {
758
- return Object.prototype.hasOwnProperty.call(obj, prop);
759
- }
760
-
761
- export { AuthupClient, Cache, ComponentError, DomainEventPublisher, DomainEventRedisPublisher, DomainEventSocketPublisher, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isClientAuthenticationHookUsable, isComponentError, isLoggerUsable, isLokiClientUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable, setAmqpClientFactory, setAuthupClientFactory, setClientAuthenticationHookFactory, setLogger, setLoggerFactory, setLokiFactory, setRedisClient, setRedisFactory, setVaultFactory, useAmqpClient, useAuthupClient, useCache, useClientAuthenticationHook, useDomainEventPublisher, useLogger, useLokiClient, useQueueRouter, useRedisClient, useRedisPublishClient, useRedisSubscribeClient, useVaultClient };
858
+ export { AuthupClient, Cache, ComponentError, ComponentHandlers, DomainEventPublisher, DomainEventRedisPublisher, DomainEventSocketConsumer, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildDomainEventRedisChannel, buildDomainEventSocketChannel, buildDomainEventSocketNamespace, 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, useDomainEventPublisherSinga, useLogger, useQueueRouter, useRedisClient, useRedisPublishClient, useRedisSubscribeClient, useVaultClient };
762
859
  //# sourceMappingURL=index.mjs.map