@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.cjs CHANGED
@@ -8,18 +8,16 @@ var coreHttpKit = require('@authup/core-http-kit');
8
8
  var redisExtension = require('redis-extension');
9
9
  var TTLCache = require('@isaacs/ttlcache');
10
10
  var envix = require('envix');
11
- var path = require('node:path');
12
11
  var typeormExtension = require('typeorm-extension');
13
12
  var winston = require('winston');
14
13
  var redisEmitter = require('@socket.io/redis-emitter');
15
- var loki = require('@hapic/loki');
16
14
 
17
15
  /*
18
16
  * Copyright (c) 2023-2024.
19
17
  * Author Peter Placzek (tada5hi)
20
18
  * For the full copyright and license information,
21
19
  * view the LICENSE file that was distributed with this source code.
22
- */ function _define_property$7(obj, key, value) {
20
+ */ function _define_property$8(obj, key, value) {
23
21
  if (key in obj) {
24
22
  Object.defineProperty(obj, key, {
25
23
  value: value,
@@ -36,11 +34,81 @@ class ComponentError extends Error {
36
34
  constructor(input){
37
35
  super(input.message, {
38
36
  cause: input.cause
39
- }), _define_property$7(this, "code", void 0);
37
+ }), _define_property$8(this, "code", void 0);
40
38
  this.code = input.code;
41
39
  }
42
40
  }
43
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
+
44
112
  function isComponentError(input) {
45
113
  if (!kit.isObject(input)) {
46
114
  return false;
@@ -84,30 +152,30 @@ function isQueueRouterPayload(input) {
84
152
  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
153
  }
86
154
 
87
- const instance$b = singa.singa({
155
+ const instance$9 = singa.singa({
88
156
  name: 'amqp'
89
157
  });
90
158
  function setAmqpClientFactory(factory) {
91
- instance$b.setFactory(factory);
159
+ instance$9.setFactory(factory);
92
160
  }
93
161
  function isAmqpClientUsable() {
94
- return instance$b.has() || instance$b.hasFactory();
162
+ return instance$9.has() || instance$9.hasFactory();
95
163
  }
96
164
  function useAmqpClient() {
97
- return instance$b.use();
165
+ return instance$9.use();
98
166
  }
99
167
 
100
- const instance$a = singa.singa({
168
+ const instance$8 = singa.singa({
101
169
  name: 'vault'
102
170
  });
103
171
  function setVaultFactory(factory) {
104
- instance$a.setFactory(factory);
172
+ instance$8.setFactory(factory);
105
173
  }
106
174
  function isVaultClientUsable() {
107
- return instance$a.has() || instance$a.hasFactory();
175
+ return instance$8.has() || instance$8.hasFactory();
108
176
  }
109
177
  function useVaultClient() {
110
- return instance$a.use();
178
+ return instance$8.use();
111
179
  }
112
180
 
113
181
  function guessAuthupTokenCreatorOptions() {
@@ -128,17 +196,17 @@ function guessAuthupTokenCreatorOptions() {
128
196
  return options;
129
197
  }
130
198
 
131
- const instance$9 = singa.singa({
199
+ const instance$7 = singa.singa({
132
200
  name: 'clientAuthenticationHook'
133
201
  });
134
202
  function setClientAuthenticationHookFactory(factory) {
135
- instance$9.setFactory(factory);
203
+ instance$7.setFactory(factory);
136
204
  }
137
205
  function isClientAuthenticationHookUsable() {
138
- return instance$9.has() || instance$9.hasFactory();
206
+ return instance$7.has() || instance$7.hasFactory();
139
207
  }
140
208
  function useClientAuthenticationHook() {
141
- return instance$9.use();
209
+ return instance$7.use();
142
210
  }
143
211
 
144
212
  class AuthupClient extends coreHttpKit.Client {
@@ -155,49 +223,49 @@ class AuthupClient extends coreHttpKit.Client {
155
223
  }
156
224
  }
157
225
 
158
- const instance$8 = singa.singa({
226
+ const instance$6 = singa.singa({
159
227
  name: 'authup'
160
228
  });
161
229
  function useAuthupClient() {
162
- return instance$8.use();
230
+ return instance$6.use();
163
231
  }
164
232
  function isAuthupClientUsable() {
165
- return instance$8.has() || instance$8.hasFactory();
233
+ return instance$6.has() || instance$6.hasFactory();
166
234
  }
167
235
  function setAuthupClientFactory(factory) {
168
- instance$8.setFactory(factory);
236
+ instance$6.setFactory(factory);
169
237
  }
170
238
 
171
- const instance$7 = singa.singa({
239
+ const instance$5 = singa.singa({
172
240
  name: 'redis'
173
241
  });
174
242
  function setRedisFactory(factory) {
175
- instance$7.setFactory(factory);
243
+ instance$5.setFactory(factory);
176
244
  }
177
245
  function isRedisClientUsable() {
178
- return instance$7.has() || instance$7.hasFactory();
246
+ return instance$5.has() || instance$5.hasFactory();
179
247
  }
180
248
  function setRedisClient(input) {
181
- instance$7.set(input);
249
+ instance$5.set(input);
182
250
  }
183
251
  function useRedisClient() {
184
- return instance$7.use();
252
+ return instance$5.use();
185
253
  }
186
254
 
187
- const instance$6 = singa.singa({
255
+ const instance$4 = singa.singa({
188
256
  name: 'redisPublish',
189
257
  factory: ()=>useRedisClient().duplicate()
190
258
  });
191
259
  function useRedisPublishClient() {
192
- return instance$6.use();
260
+ return instance$4.use();
193
261
  }
194
262
 
195
- const instance$5 = singa.singa({
263
+ const instance$3 = singa.singa({
196
264
  name: 'redisSubscribe',
197
265
  factory: ()=>useRedisClient().duplicate()
198
266
  });
199
267
  function useRedisSubscribeClient() {
200
- return instance$5.use();
268
+ return instance$3.use();
201
269
  }
202
270
 
203
271
  /*
@@ -377,7 +445,7 @@ class Cache {
377
445
  }
378
446
  }
379
447
 
380
- const instance$4 = singa.singa({
448
+ const instance$2 = singa.singa({
381
449
  name: 'cache',
382
450
  factory: ()=>{
383
451
  let adapter;
@@ -390,62 +458,56 @@ const instance$4 = singa.singa({
390
458
  }
391
459
  });
392
460
  function useCache() {
393
- return instance$4.use();
461
+ return instance$2.use();
394
462
  }
395
463
 
464
+ function toTransports(input) {
465
+ return Array.isArray(input) ? input : [
466
+ input
467
+ ];
468
+ }
396
469
  function createLogger(ctx = {}) {
397
- const { directory, options = {} } = ctx;
398
470
  let loggerTransports;
399
471
  if (envix.read('env') === typeormExtension.EnvironmentName.PRODUCTION) {
400
472
  loggerTransports = [
401
473
  new winston.transports.Console({
402
474
  level: 'info'
403
475
  }),
404
- new winston.transports.File({
405
- filename: path.join(directory || process.cwd(), 'access.log'),
406
- level: 'http',
407
- maxsize: 10 * 1024 * 1024,
408
- maxFiles: 5
409
- }),
410
- new winston.transports.File({
411
- filename: path.join(directory || process.cwd(), 'error.log'),
412
- level: 'warn',
413
- maxsize: 10 * 1024 * 1024,
414
- maxFiles: 5
415
- })
476
+ ...ctx.transports ? toTransports(ctx.transports) : []
416
477
  ];
417
478
  } else {
418
479
  loggerTransports = [
419
480
  new winston.transports.Console({
420
481
  level: 'debug'
421
- })
482
+ }),
483
+ ...ctx.transports ? toTransports(ctx.transports) : []
422
484
  ];
423
485
  }
424
486
  return winston.createLogger({
425
487
  format: winston.format.combine(winston.format.errors({
426
488
  stack: true
427
- }), winston.format.timestamp(), winston.format.colorize(), winston.format.simple()),
489
+ }), winston.format.timestamp(), winston.format.simple()),
428
490
  level: 'debug',
429
491
  transports: loggerTransports,
430
492
  // todo: deeply merge options
431
- ...options || {}
493
+ ...ctx.options || {}
432
494
  });
433
495
  }
434
496
 
435
- const instance$3 = singa.singa({
497
+ const instance$1 = singa.singa({
436
498
  name: 'logger'
437
499
  });
438
500
  function setLoggerFactory(factory) {
439
- instance$3.setFactory(factory);
501
+ instance$1.setFactory(factory);
440
502
  }
441
503
  function isLoggerUsable() {
442
- return instance$3.has() || instance$3.hasFactory();
504
+ return instance$1.has() || instance$1.hasFactory();
443
505
  }
444
506
  function setLogger(input) {
445
- instance$3.set(input);
507
+ instance$1.set(input);
446
508
  }
447
509
  function useLogger() {
448
- return instance$3.use();
510
+ return instance$1.use();
449
511
  }
450
512
 
451
513
  /*
@@ -467,35 +529,45 @@ function useLogger() {
467
529
  return obj;
468
530
  }
469
531
  class DomainEventPublisher {
470
- addPublisher(publisher) {
471
- this.publishers.add(publisher);
532
+ addConsumer(consumer) {
533
+ this.consumers.add(consumer);
472
534
  }
473
535
  async safePublish(ctx) {
474
536
  try {
475
537
  await this.publish(ctx);
476
538
  } catch (e) {
477
539
  if (isLoggerUsable()) {
478
- useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)} failed`);
540
+ useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
479
541
  useLogger().error(e);
480
542
  }
481
543
  }
482
544
  }
483
545
  async publish(ctx) {
484
546
  if (isLoggerUsable()) {
485
- useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)}`);
547
+ useLogger().info(`Publishing event ${kit.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;
486
554
  }
487
- const publishers = this.publishers.values();
555
+ const consumeContext = {
556
+ ...ctx,
557
+ destinations
558
+ };
559
+ const consumers = this.consumers.values();
488
560
  while(true){
489
- const it = publishers.next();
561
+ const it = consumers.next();
490
562
  if (it.done) {
491
563
  return;
492
564
  }
493
- await it.value.publish(ctx);
565
+ await it.value.consume(consumeContext);
494
566
  }
495
567
  }
496
568
  constructor(){
497
- _define_property$3(this, "publishers", void 0);
498
- this.publishers = new Set();
569
+ _define_property$3(this, "consumers", void 0);
570
+ this.consumers = new Set();
499
571
  }
500
572
  }
501
573
 
@@ -511,11 +583,25 @@ function transformEventData(input) {
511
583
  }
512
584
  return input;
513
585
  }
514
- function buildEventChannelName(input, id) {
515
- if (typeof input === 'string') {
516
- 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);
600
+ }
601
+ if (typeof namespaceNormalized === 'undefined') {
602
+ return channelNormalized;
517
603
  }
518
- return input(id);
604
+ return `${namespaceNormalized}/${channelNormalized}`;
519
605
  }
520
606
 
521
607
  /*
@@ -537,17 +623,18 @@ function buildEventChannelName(input, id) {
537
623
  return obj;
538
624
  }
539
625
  class DomainEventRedisPublisher {
540
- async publish(ctx) {
541
- 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);
542
633
  const pipeline = this.driver.pipeline();
543
634
  for(let i = 0; i < ctx.destinations.length; i++){
544
- const keyPrefix = ctx.destinations[i].namespace ? `${ctx.destinations[i].namespace}:` : '';
545
- let key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel);
546
- pipeline.publish(key, data);
547
- if (typeof ctx.destinations[i].channel === 'function') {
548
- key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id);
549
- pipeline.publish(key, data);
550
- }
635
+ const destination = ctx.destinations[i];
636
+ const key = buildDomainEventRedisChannel(destination.channel, destination.namespace);
637
+ pipeline.publish(key, payloadSerialized);
551
638
  }
552
639
  await pipeline.exec();
553
640
  }
@@ -557,6 +644,27 @@ class DomainEventRedisPublisher {
557
644
  }
558
645
  }
559
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
+
560
668
  /*
561
669
  * Copyright (c) 2022-2024.
562
670
  * Author Peter Placzek (tada5hi)
@@ -575,33 +683,26 @@ class DomainEventRedisPublisher {
575
683
  }
576
684
  return obj;
577
685
  }
578
- class DomainEventSocketPublisher {
579
- async publish(ctx) {
686
+ class DomainEventSocketConsumer {
687
+ async consume(ctx) {
580
688
  ctx.data = transformEventData(ctx.data);
581
689
  for(let i = 0; i < ctx.destinations.length; i++){
582
- let namespace;
583
- if (ctx.destinations[i].namespace) {
584
- namespace = ctx.destinations[i].namespace;
585
- } else {
586
- namespace = '/';
587
- }
690
+ const destination = ctx.destinations[i];
691
+ const namespace = buildDomainEventSocketNamespace(destination.namespace);
692
+ const roomName = buildDomainEventSocketChannel(destination.channel);
693
+ const fullEventName = kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event);
588
694
  const emitter = new redisEmitter.Emitter(this.client, {}, namespace);
589
- const fullEventName = kit.buildDomainEventFullName(ctx.data.type, ctx.data.event);
590
- const rooms = [
591
- buildEventChannelName(ctx.destinations[i].channel)
592
- ];
593
- if (typeof ctx.destinations[i].channel === 'function') {
594
- rooms.push(buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id));
595
- }
596
- for(let j = 0; j < rooms.length; j++){
597
- emitter.in(rooms[j]).emit(fullEventName, {
598
- ...ctx.data,
599
- meta: {
600
- namespace,
601
- roomName: rooms[j]
602
- }
603
- });
604
- }
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
+ });
605
706
  }
606
707
  }
607
708
  constructor(client){
@@ -610,33 +711,23 @@ class DomainEventSocketPublisher {
610
711
  }
611
712
  }
612
713
 
613
- const instance$2 = singa.singa({
714
+ const singaInstance = singa.singa({
614
715
  name: 'domainEventPublisher',
615
716
  factory: ()=>{
616
717
  const publisher = new DomainEventPublisher();
617
718
  if (isRedisClientUsable()) {
618
719
  const client = useRedisClient();
619
- publisher.addPublisher(new DomainEventRedisPublisher(client));
620
- publisher.addPublisher(new DomainEventSocketPublisher(client));
720
+ publisher.addConsumer(new DomainEventRedisPublisher(client));
721
+ publisher.addConsumer(new DomainEventSocketConsumer(client));
621
722
  }
622
723
  return publisher;
623
724
  }
624
725
  });
625
- function useDomainEventPublisher() {
626
- return instance$2.use();
726
+ function useDomainEventPublisherSinga() {
727
+ return singaInstance;
627
728
  }
628
-
629
- const instance$1 = singa.singa({
630
- name: 'loki'
631
- });
632
- function setLokiFactory(factory) {
633
- instance$1.setFactory(factory);
634
- }
635
- function isLokiClientUsable() {
636
- return instance$1.has() || instance$1.hasFactory();
637
- }
638
- function useLokiClient() {
639
- return instance$1.use();
729
+ function useDomainEventPublisher() {
730
+ return singaInstance.use();
640
731
  }
641
732
 
642
733
  /*
@@ -659,7 +750,9 @@ function useLokiClient() {
659
750
  }
660
751
  class QueueRouter {
661
752
  //----------------------------------------------------------------
662
- publish(message) {
753
+ publish(message, options = {}) {
754
+ var _options;
755
+ (_options = options).logging ?? (_options.logging = true);
663
756
  let exchange;
664
757
  if (message.metadata.routing.type === 'work') {
665
758
  exchange = this.driver.of({
@@ -672,7 +765,7 @@ class QueueRouter {
672
765
  name: message.metadata.routing.namespace || 'FLAME'
673
766
  });
674
767
  }
675
- if (isLoggerUsable()) {
768
+ if (options.logging && isLoggerUsable()) {
676
769
  useLogger().debug(`Publishing queue message ${message.type} in ${message.metadata.routing.key}`);
677
770
  }
678
771
  return exchange.publish(message.metadata.routing.key, message, {
@@ -681,6 +774,11 @@ class QueueRouter {
681
774
  persistent: message.metadata.persistent ?? message.metadata.routing.type === QueueRouterRoutingType.WORK
682
775
  });
683
776
  }
777
+ consumeAny(routing, fn) {
778
+ return this.consume(routing, {
779
+ $any: (payload)=>fn(payload)
780
+ });
781
+ }
684
782
  consume(routing, handlers) {
685
783
  let exchange;
686
784
  if (routing.type === 'work') {
@@ -725,7 +823,14 @@ class QueueRouter {
725
823
  }
726
824
  return;
727
825
  }
728
- await handler(payload);
826
+ try {
827
+ await handler(payload);
828
+ } catch (e) {
829
+ if (isLoggerUsable()) {
830
+ useLogger().error(e);
831
+ }
832
+ throw e;
833
+ }
729
834
  }
730
835
  });
731
836
  }
@@ -750,15 +855,10 @@ function useQueueRouter() {
750
855
  return instance.use();
751
856
  }
752
857
 
753
- /*
754
- * Copyright (c) 2022-2024.
755
- * Author Peter Placzek (tada5hi)
756
- * For the full copyright and license information,
757
- * view the LICENSE file that was distributed with this source code.
758
- */ function hasOwnProperty(obj, prop) {
759
- return Object.prototype.hasOwnProperty.call(obj, prop);
760
- }
761
-
858
+ Object.defineProperty(exports, "AmqpClient", {
859
+ enumerable: true,
860
+ get: function () { return amqpExtension.Client; }
861
+ });
762
862
  Object.defineProperty(exports, "VaultClient", {
763
863
  enumerable: true,
764
864
  get: function () { return vault.VaultClient; }
@@ -783,53 +883,21 @@ Object.defineProperty(exports, "createRedisClient", {
783
883
  enumerable: true,
784
884
  get: function () { return redisExtension.createClient; }
785
885
  });
786
- Object.defineProperty(exports, "LokiClient", {
787
- enumerable: true,
788
- get: function () { return loki.LokiClient; }
789
- });
790
- Object.defineProperty(exports, "LokiCompactorDeletionRequestCreate", {
791
- enumerable: true,
792
- get: function () { return loki.CompactorDeletionRequestCreate; }
793
- });
794
- Object.defineProperty(exports, "LokiConfig", {
795
- enumerable: true,
796
- get: function () { return loki.Config; }
797
- });
798
- Object.defineProperty(exports, "LokiConfigInput", {
799
- enumerable: true,
800
- get: function () { return loki.ConfigInput; }
801
- });
802
- Object.defineProperty(exports, "LokiDistributorPushStream", {
803
- enumerable: true,
804
- get: function () { return loki.DistributorPushStream; }
805
- });
806
- Object.defineProperty(exports, "LokiQuerierQueryRangeOptions", {
807
- enumerable: true,
808
- get: function () { return loki.QuerierQueryRangeOptions; }
809
- });
810
- Object.defineProperty(exports, "LokiQuerierQueryResult", {
811
- enumerable: true,
812
- get: function () { return loki.QuerierQueryResult; }
813
- });
814
- Object.defineProperty(exports, "createLokiClient", {
815
- enumerable: true,
816
- get: function () { return loki.createClient; }
817
- });
818
- Object.defineProperty(exports, "nanoSeconds", {
819
- enumerable: true,
820
- get: function () { return loki.nanoSeconds; }
821
- });
822
886
  exports.AuthupClient = AuthupClient;
823
887
  exports.Cache = Cache;
824
888
  exports.ComponentError = ComponentError;
889
+ exports.ComponentHandlers = ComponentHandlers;
825
890
  exports.DomainEventPublisher = DomainEventPublisher;
826
891
  exports.DomainEventRedisPublisher = DomainEventRedisPublisher;
827
- exports.DomainEventSocketPublisher = DomainEventSocketPublisher;
892
+ exports.DomainEventSocketConsumer = DomainEventSocketConsumer;
828
893
  exports.MemoryCacheAdapter = MemoryCacheAdapter;
829
894
  exports.QueueRouter = QueueRouter;
830
895
  exports.QueueRouterRoutingType = QueueRouterRoutingType;
831
896
  exports.RedisCacheAdapter = RedisCacheAdapter;
832
897
  exports.buildCacheKey = buildCacheKey;
898
+ exports.buildDomainEventRedisChannel = buildDomainEventRedisChannel;
899
+ exports.buildDomainEventSocketChannel = buildDomainEventSocketChannel;
900
+ exports.buildDomainEventSocketNamespace = buildDomainEventSocketNamespace;
833
901
  exports.buildQueueRouterPublishPayload = buildQueueRouterPublishPayload;
834
902
  exports.createCacheAdapter = createCacheAdapter;
835
903
  exports.createLogger = createLogger;
@@ -840,7 +908,6 @@ exports.isAuthupClientUsable = isAuthupClientUsable;
840
908
  exports.isClientAuthenticationHookUsable = isClientAuthenticationHookUsable;
841
909
  exports.isComponentError = isComponentError;
842
910
  exports.isLoggerUsable = isLoggerUsable;
843
- exports.isLokiClientUsable = isLokiClientUsable;
844
911
  exports.isQueuePayload = isQueuePayload;
845
912
  exports.isQueueRouterPayload = isQueueRouterPayload;
846
913
  exports.isQueueRouterUsable = isQueueRouterUsable;
@@ -851,7 +918,6 @@ exports.setAuthupClientFactory = setAuthupClientFactory;
851
918
  exports.setClientAuthenticationHookFactory = setClientAuthenticationHookFactory;
852
919
  exports.setLogger = setLogger;
853
920
  exports.setLoggerFactory = setLoggerFactory;
854
- exports.setLokiFactory = setLokiFactory;
855
921
  exports.setRedisClient = setRedisClient;
856
922
  exports.setRedisFactory = setRedisFactory;
857
923
  exports.setVaultFactory = setVaultFactory;
@@ -860,8 +926,8 @@ exports.useAuthupClient = useAuthupClient;
860
926
  exports.useCache = useCache;
861
927
  exports.useClientAuthenticationHook = useClientAuthenticationHook;
862
928
  exports.useDomainEventPublisher = useDomainEventPublisher;
929
+ exports.useDomainEventPublisherSinga = useDomainEventPublisherSinga;
863
930
  exports.useLogger = useLogger;
864
- exports.useLokiClient = useLokiClient;
865
931
  exports.useQueueRouter = useQueueRouter;
866
932
  exports.useRedisClient = useRedisClient;
867
933
  exports.useRedisPublishClient = useRedisPublishClient;