@privateaim/server-kit 0.8.14 → 0.8.15

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 (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/index.cjs +429 -51
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +426 -53
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/services/domain-event/index.d.ts +1 -1
  7. package/dist/services/domain-event/index.d.ts.map +1 -1
  8. package/dist/services/domain-event/module.d.ts +4 -4
  9. package/dist/services/domain-event/module.d.ts.map +1 -1
  10. package/dist/services/domain-event/redis/module.d.ts +2 -2
  11. package/dist/services/domain-event/redis/module.d.ts.map +1 -1
  12. package/dist/services/domain-event/singleton.d.ts +1 -0
  13. package/dist/services/domain-event/singleton.d.ts.map +1 -1
  14. package/dist/services/domain-event/socket/module.d.ts +2 -2
  15. package/dist/services/domain-event/socket/module.d.ts.map +1 -1
  16. package/dist/services/domain-event/types.d.ts +29 -0
  17. package/dist/services/domain-event/types.d.ts.map +1 -0
  18. package/dist/services/domain-event/utils.d.ts +2 -2
  19. package/dist/services/domain-event/utils.d.ts.map +1 -1
  20. package/dist/services/index.d.ts +1 -0
  21. package/dist/services/index.d.ts.map +1 -1
  22. package/dist/services/log-store/entities/base.d.ts +7 -0
  23. package/dist/services/log-store/entities/base.d.ts.map +1 -0
  24. package/dist/services/log-store/entities/index.d.ts +3 -0
  25. package/dist/services/log-store/entities/index.d.ts.map +1 -0
  26. package/dist/services/log-store/entities/loki.d.ts +13 -0
  27. package/dist/services/log-store/entities/loki.d.ts.map +1 -0
  28. package/dist/services/log-store/entities/memory.d.ts +11 -0
  29. package/dist/services/log-store/entities/memory.d.ts.map +1 -0
  30. package/dist/services/log-store/index.d.ts +4 -0
  31. package/dist/services/log-store/index.d.ts.map +1 -0
  32. package/dist/services/log-store/singleton.d.ts +6 -0
  33. package/dist/services/log-store/singleton.d.ts.map +1 -0
  34. package/dist/services/log-store/types.d.ts +27 -0
  35. package/dist/services/log-store/types.d.ts.map +1 -0
  36. package/dist/services/logger/module.d.ts.map +1 -1
  37. package/dist/services/logger/store.d.ts +14 -0
  38. package/dist/services/logger/store.d.ts.map +1 -0
  39. package/dist/services/logger/types.d.ts +3 -0
  40. package/dist/services/logger/types.d.ts.map +1 -1
  41. package/package.json +9 -7
  42. package/src/services/domain-event/index.ts +1 -1
  43. package/src/services/domain-event/module.ts +8 -8
  44. package/src/services/domain-event/redis/module.ts +28 -9
  45. package/src/services/domain-event/singleton.ts +6 -2
  46. package/src/services/domain-event/socket/module.ts +20 -9
  47. package/src/services/domain-event/types.ts +50 -0
  48. package/src/services/domain-event/utils.ts +2 -2
  49. package/src/services/index.ts +1 -0
  50. package/src/services/log-store/entities/base.ts +25 -0
  51. package/src/services/log-store/entities/index.ts +9 -0
  52. package/src/services/log-store/entities/loki.ts +158 -0
  53. package/src/services/log-store/entities/memory.ts +100 -0
  54. package/src/services/log-store/index.ts +10 -0
  55. package/src/services/log-store/singleton.ts +36 -0
  56. package/src/services/log-store/types.ts +42 -0
  57. package/src/services/logger/module.ts +20 -5
  58. package/src/services/logger/store.ts +70 -0
  59. package/src/services/logger/types.ts +4 -1
  60. package/test/unit/log-store.spec.ts +21 -0
  61. package/test/unit/logger.spec.ts +36 -0
  62. package/dist/services/domain-event/type.d.ts +0 -15
  63. package/dist/services/domain-event/type.d.ts.map +0 -1
  64. package/src/services/domain-event/type.ts +0 -27
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.15](https://github.com/PrivateAIM/hub/compare/v0.8.14...v0.8.15) (2025-07-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * event (re-) modelling ([#1125](https://github.com/PrivateAIM/hub/issues/1125)) ([621f704](https://github.com/PrivateAIM/hub/commit/621f7041794d0bf6d530445a9c3e7c9b66a373ba))
9
+ * migrated to authup v1.0.0-beta.27 ([f96db78](https://github.com/PrivateAIM/hub/commit/f96db782a5b74e3aa8ab1ada270af770f3c92631))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @privateaim/kit bumped from ^0.8.14 to ^0.8.15
17
+
3
18
  ## [0.8.14](https://github.com/PrivateAIM/hub/compare/v0.8.13...v0.8.14) (2025-07-10)
4
19
 
5
20
 
package/dist/index.cjs CHANGED
@@ -11,15 +11,16 @@ 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 redisEmitter = require('@socket.io/redis-emitter');
14
+ var WinstonTransport = require('winston-transport');
15
15
  var loki = require('@hapic/loki');
16
+ var redisEmitter = require('@socket.io/redis-emitter');
16
17
 
17
18
  /*
18
19
  * Copyright (c) 2023-2024.
19
20
  * Author Peter Placzek (tada5hi)
20
21
  * For the full copyright and license information,
21
22
  * view the LICENSE file that was distributed with this source code.
22
- */ function _define_property$7(obj, key, value) {
23
+ */ function _define_property$b(obj, key, value) {
23
24
  if (key in obj) {
24
25
  Object.defineProperty(obj, key, {
25
26
  value: value,
@@ -36,7 +37,7 @@ class ComponentError extends Error {
36
37
  constructor(input){
37
38
  super(input.message, {
38
39
  cause: input.cause
39
- }), _define_property$7(this, "code", void 0);
40
+ }), _define_property$b(this, "code", void 0);
40
41
  this.code = input.code;
41
42
  }
42
43
  }
@@ -205,7 +206,7 @@ function useRedisSubscribeClient() {
205
206
  * Author Peter Placzek (tada5hi)
206
207
  * For the full copyright and license information,
207
208
  * view the LICENSE file that was distributed with this source code.
208
- */ function _define_property$6(obj, key, value) {
209
+ */ function _define_property$a(obj, key, value) {
209
210
  if (key in obj) {
210
211
  Object.defineProperty(obj, key, {
211
212
  value: value,
@@ -253,7 +254,7 @@ class MemoryCacheAdapter {
253
254
  this.instance.clear();
254
255
  }
255
256
  constructor(options = {}){
256
- _define_property$6(this, "instance", void 0);
257
+ _define_property$a(this, "instance", void 0);
257
258
  this.instance = new TTLCache({
258
259
  checkAgeOnGet: true,
259
260
  ttl: Infinity,
@@ -267,7 +268,7 @@ class MemoryCacheAdapter {
267
268
  * Author Peter Placzek (tada5hi)
268
269
  * For the full copyright and license information,
269
270
  * view the LICENSE file that was distributed with this source code.
270
- */ function _define_property$5(obj, key, value) {
271
+ */ function _define_property$9(obj, key, value) {
271
272
  if (key in obj) {
272
273
  Object.defineProperty(obj, key, {
273
274
  value: value,
@@ -316,8 +317,8 @@ class RedisCacheAdapter {
316
317
  await this.client.flushdb();
317
318
  }
318
319
  constructor(){
319
- _define_property$5(this, "client", void 0);
320
- _define_property$5(this, "instance", void 0);
320
+ _define_property$9(this, "client", void 0);
321
+ _define_property$9(this, "instance", void 0);
321
322
  this.client = useRedisClient();
322
323
  this.instance = new redisExtension.JsonAdapter(this.client);
323
324
  }
@@ -339,7 +340,7 @@ function buildCacheKey(options) {
339
340
  * Author Peter Placzek (tada5hi)
340
341
  * For the full copyright and license information,
341
342
  * view the LICENSE file that was distributed with this source code.
342
- */ function _define_property$4(obj, key, value) {
343
+ */ function _define_property$8(obj, key, value) {
343
344
  if (key in obj) {
344
345
  Object.defineProperty(obj, key, {
345
346
  value: value,
@@ -372,7 +373,7 @@ class Cache {
372
373
  return this.adapter.clear(options);
373
374
  }
374
375
  constructor(adapter){
375
- _define_property$4(this, "adapter", void 0);
376
+ _define_property$8(this, "adapter", void 0);
376
377
  this.adapter = adapter;
377
378
  }
378
379
  }
@@ -393,8 +394,362 @@ function useCache() {
393
394
  return instance$4.use();
394
395
  }
395
396
 
397
+ /*
398
+ * Copyright (c) 2025.
399
+ * Author Peter Placzek (tada5hi)
400
+ * For the full copyright and license information,
401
+ * view the LICENSE file that was distributed with this source code.
402
+ */ function _define_property$7(obj, key, value) {
403
+ if (key in obj) {
404
+ Object.defineProperty(obj, key, {
405
+ value: value,
406
+ enumerable: true,
407
+ configurable: true,
408
+ writable: true
409
+ });
410
+ } else {
411
+ obj[key] = value;
412
+ }
413
+ return obj;
414
+ }
415
+ class LogStoreTransport extends WinstonTransport {
416
+ log(info, next) {
417
+ const { message, timestamp, stack, ...data } = info;
418
+ const labels = {
419
+ ...this.labels
420
+ };
421
+ const keys = Object.keys(data);
422
+ for(let i = 0; i < keys.length; i++){
423
+ if (typeof keys[i] !== 'string') {
424
+ continue;
425
+ }
426
+ const value = data[keys[i]];
427
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
428
+ labels[keys[i]] = `${value}`;
429
+ }
430
+ }
431
+ let date;
432
+ if (typeof timestamp === 'string') {
433
+ date = new Date(`${timestamp}`);
434
+ } else {
435
+ date = new Date();
436
+ }
437
+ const payload = {
438
+ message: stack || message,
439
+ time: BigInt(date.getTime()) * 1000000n,
440
+ labels
441
+ };
442
+ Promise.resolve().then(()=>this.instance.write(payload)).then(()=>next());
443
+ }
444
+ constructor(store, options = {}){
445
+ super(options), _define_property$7(this, "instance", void 0), _define_property$7(this, "labels", void 0);
446
+ this.instance = store;
447
+ this.labels = options.labels || {};
448
+ }
449
+ }
450
+
451
+ const instance$3 = singa.singa({
452
+ name: 'loki'
453
+ });
454
+ function setLokiFactory(factory) {
455
+ instance$3.setFactory(factory);
456
+ }
457
+ function isLokiClientUsable() {
458
+ return instance$3.has() || instance$3.hasFactory();
459
+ }
460
+ function useLokiClient() {
461
+ return instance$3.use();
462
+ }
463
+
464
+ /*
465
+ * Copyright (c) 2025.
466
+ * Author Peter Placzek (tada5hi)
467
+ * For the full copyright and license information,
468
+ * view the LICENSE file that was distributed with this source code.
469
+ */ function _define_property$6(obj, key, value) {
470
+ if (key in obj) {
471
+ Object.defineProperty(obj, key, {
472
+ value: value,
473
+ enumerable: true,
474
+ configurable: true,
475
+ writable: true
476
+ });
477
+ } else {
478
+ obj[key] = value;
479
+ }
480
+ return obj;
481
+ }
482
+ class BaseLogStore {
483
+ setLabels(labels) {
484
+ this.labels = labels;
485
+ }
486
+ getLabels() {
487
+ return this.labels;
488
+ }
489
+ extendLabels(labels) {
490
+ const keys = Object.keys(labels);
491
+ for(let i = 0; i < keys.length; i++){
492
+ this.labels[keys[i]] = labels[keys[i]];
493
+ }
494
+ }
495
+ constructor(){
496
+ _define_property$6(this, "labels", void 0);
497
+ }
498
+ }
499
+
500
+ /*
501
+ * Copyright (c) 2025.
502
+ * Author Peter Placzek (tada5hi)
503
+ * For the full copyright and license information,
504
+ * view the LICENSE file that was distributed with this source code.
505
+ */ function _define_property$5(obj, key, value) {
506
+ if (key in obj) {
507
+ Object.defineProperty(obj, key, {
508
+ value: value,
509
+ enumerable: true,
510
+ configurable: true,
511
+ writable: true
512
+ });
513
+ } else {
514
+ obj[key] = value;
515
+ }
516
+ return obj;
517
+ }
518
+ class LokiLogStore extends BaseLogStore {
519
+ async write(message, labels) {
520
+ let data;
521
+ if (typeof message === 'string') {
522
+ const labelsNormalized = {
523
+ ...this.labels,
524
+ ...labels || {}
525
+ };
526
+ const level = labelsNormalized.level || kit.LogLevel.DEBUG;
527
+ delete labelsNormalized.level;
528
+ data = {
529
+ message,
530
+ level,
531
+ time: loki.nanoSeconds(),
532
+ labels: labelsNormalized
533
+ };
534
+ } else {
535
+ const labelsNormalized = {
536
+ ...this.labels,
537
+ ...message.labels || {},
538
+ ...labels || {}
539
+ };
540
+ const level = message.level || labelsNormalized.level || kit.LogLevel.DEBUG;
541
+ delete labelsNormalized.level;
542
+ data = {
543
+ ...message,
544
+ level,
545
+ time: message.time || loki.nanoSeconds(),
546
+ labels: labelsNormalized
547
+ };
548
+ }
549
+ const stream = {
550
+ stream: data.labels,
551
+ values: [
552
+ [
553
+ data.time,
554
+ data.message,
555
+ {
556
+ level: data.level
557
+ }
558
+ ]
559
+ ]
560
+ };
561
+ await this.instance.distributor.push(stream);
562
+ return data;
563
+ }
564
+ async delete(options) {
565
+ await this.instance.compactor.createDeletionRequest({
566
+ start: options.start,
567
+ ...options.end ? {
568
+ end: options.end
569
+ } : {},
570
+ query: this.buildQuery({
571
+ ...this.labels,
572
+ ...options.labels || {}
573
+ })
574
+ });
575
+ }
576
+ async query(input) {
577
+ const options = {
578
+ query: this.buildQuery({
579
+ ...this.labels,
580
+ ...input.labels || {}
581
+ })
582
+ };
583
+ if (input.sort) {
584
+ options.direction = input.sort === 'DESC' ? 'forward' : 'backward';
585
+ }
586
+ if (input.limit) {
587
+ options.limit = input.limit;
588
+ }
589
+ if (input.start) {
590
+ options.start = BigInt(new Date(`${input.start}`).getTime()) * 1000000n;
591
+ }
592
+ if (input.end) {
593
+ options.end = BigInt(new Date(`${input.end}`).getTime()) * 1000000n;
594
+ }
595
+ const output = [];
596
+ const response = await this.instance.querier.queryRange(options);
597
+ if (response.data.resultType === 'streams') {
598
+ for(let i = 0; i < response.data.result.length; i++){
599
+ const set = response.data.result[i];
600
+ const labels = set.stream;
601
+ let level;
602
+ if (labels.level) {
603
+ level = labels.level;
604
+ } else {
605
+ level = labels.detected_level;
606
+ }
607
+ delete labels.level;
608
+ delete labels.detected_level;
609
+ if (!labels.service) {
610
+ labels.service = labels.service_name;
611
+ }
612
+ delete labels.service_name;
613
+ for(let j = 0; j < set.values.length; j++){
614
+ output.push({
615
+ time: BigInt(set.values[j][0]),
616
+ message: set.values[j][1],
617
+ level,
618
+ labels
619
+ });
620
+ }
621
+ }
622
+ }
623
+ return [
624
+ output,
625
+ output.length
626
+ ];
627
+ }
628
+ // ----------------------------------------------
629
+ buildQuery(labels) {
630
+ const output = [];
631
+ const keys = Object.keys(labels);
632
+ for(let i = 0; i < keys.length; i++){
633
+ output.push(`${keys[i]}="${labels[keys[i]]}"`);
634
+ }
635
+ return `{${output.join(',')}}`;
636
+ }
637
+ constructor(instance, labels){
638
+ super(), _define_property$5(this, "instance", void 0);
639
+ this.instance = instance;
640
+ this.labels = labels || {};
641
+ }
642
+ }
643
+
644
+ /*
645
+ * Copyright (c) 2025.
646
+ * Author Peter Placzek (tada5hi)
647
+ * For the full copyright and license information,
648
+ * view the LICENSE file that was distributed with this source code.
649
+ */ function _define_property$4(obj, key, value) {
650
+ if (key in obj) {
651
+ Object.defineProperty(obj, key, {
652
+ value: value,
653
+ enumerable: true,
654
+ configurable: true,
655
+ writable: true
656
+ });
657
+ } else {
658
+ obj[key] = value;
659
+ }
660
+ return obj;
661
+ }
662
+ class MemoryLogStore extends BaseLogStore {
663
+ // todo: apply query options
664
+ async delete() {
665
+ return Promise.resolve();
666
+ }
667
+ async query(options = {}) {
668
+ // todo: apply all query options
669
+ const data = this.items.filter((item)=>{
670
+ if (options.labels) {
671
+ if (!item.labels) {
672
+ return false;
673
+ }
674
+ const labelKeys = Object.keys(options.labels);
675
+ for(let i = 0; i < labelKeys.length; i++){
676
+ if (!item.labels[labelKeys[i]]) {
677
+ return false;
678
+ }
679
+ if (item.labels[labelKeys[i]] !== options.labels[labelKeys[i]]) {
680
+ return false;
681
+ }
682
+ }
683
+ }
684
+ return true;
685
+ });
686
+ return [
687
+ data,
688
+ data.length
689
+ ];
690
+ }
691
+ async write(message, labels) {
692
+ let data;
693
+ if (typeof message === 'string') {
694
+ const labelsNormalized = {
695
+ ...this.labels,
696
+ ...labels || {}
697
+ };
698
+ const level = labelsNormalized.level || kit.LogLevel.DEBUG;
699
+ delete labelsNormalized.level;
700
+ data = {
701
+ message,
702
+ level,
703
+ time: loki.nanoSeconds(),
704
+ labels: labelsNormalized
705
+ };
706
+ } else {
707
+ const labelsNormalized = {
708
+ ...this.labels,
709
+ ...message.labels || {},
710
+ ...labels || {}
711
+ };
712
+ const level = message.level || labelsNormalized.level || kit.LogLevel.DEBUG;
713
+ delete labelsNormalized.level;
714
+ data = {
715
+ ...message,
716
+ level,
717
+ time: message.time || loki.nanoSeconds(),
718
+ labels: labelsNormalized
719
+ };
720
+ }
721
+ this.items.push(data);
722
+ return data;
723
+ }
724
+ constructor(labels){
725
+ super(), _define_property$4(this, "items", void 0);
726
+ this.items = [];
727
+ this.labels = labels;
728
+ }
729
+ }
730
+
731
+ const instance$2 = singa.singa({
732
+ name: 'logStore',
733
+ factory: ()=>{
734
+ if (isLokiClientUsable()) {
735
+ const loki = useLokiClient();
736
+ return new LokiLogStore(loki);
737
+ }
738
+ return new MemoryLogStore();
739
+ }
740
+ });
741
+ function isLogStoreUsable() {
742
+ return instance$2.has() || instance$2.hasFactory();
743
+ }
744
+ function setLogStoreFactory(input) {
745
+ instance$2.setFactory(input);
746
+ }
747
+ function useLogStore() {
748
+ return instance$2.use();
749
+ }
750
+
396
751
  function createLogger(ctx = {}) {
397
- const { directory, options = {} } = ctx;
752
+ const store = ctx.store || useLogStore();
398
753
  let loggerTransports;
399
754
  if (envix.read('env') === typeormExtension.EnvironmentName.PRODUCTION) {
400
755
  loggerTransports = [
@@ -402,50 +757,58 @@ function createLogger(ctx = {}) {
402
757
  level: 'info'
403
758
  }),
404
759
  new winston.transports.File({
405
- filename: path.join(directory || process.cwd(), 'access.log'),
760
+ filename: path.join(ctx.directory || process.cwd(), 'access.log'),
406
761
  level: 'http',
407
762
  maxsize: 10 * 1024 * 1024,
408
763
  maxFiles: 5
409
764
  }),
410
765
  new winston.transports.File({
411
- filename: path.join(directory || process.cwd(), 'error.log'),
766
+ filename: path.join(ctx.directory || process.cwd(), 'error.log'),
412
767
  level: 'warn',
413
768
  maxsize: 10 * 1024 * 1024,
414
769
  maxFiles: 5
770
+ }),
771
+ new LogStoreTransport(store, {
772
+ level: 'http',
773
+ labels: ctx.labels
415
774
  })
416
775
  ];
417
776
  } else {
418
777
  loggerTransports = [
419
778
  new winston.transports.Console({
420
779
  level: 'debug'
780
+ }),
781
+ new LogStoreTransport(store, {
782
+ level: 'http',
783
+ labels: ctx.labels
421
784
  })
422
785
  ];
423
786
  }
424
787
  return winston.createLogger({
425
788
  format: winston.format.combine(winston.format.errors({
426
789
  stack: true
427
- }), winston.format.timestamp(), winston.format.colorize(), winston.format.simple()),
790
+ }), winston.format.timestamp(), winston.format.simple()),
428
791
  level: 'debug',
429
792
  transports: loggerTransports,
430
793
  // todo: deeply merge options
431
- ...options || {}
794
+ ...ctx.options || {}
432
795
  });
433
796
  }
434
797
 
435
- const instance$3 = singa.singa({
798
+ const instance$1 = singa.singa({
436
799
  name: 'logger'
437
800
  });
438
801
  function setLoggerFactory(factory) {
439
- instance$3.setFactory(factory);
802
+ instance$1.setFactory(factory);
440
803
  }
441
804
  function isLoggerUsable() {
442
- return instance$3.has() || instance$3.hasFactory();
805
+ return instance$1.has() || instance$1.hasFactory();
443
806
  }
444
807
  function setLogger(input) {
445
- instance$3.set(input);
808
+ instance$1.set(input);
446
809
  }
447
810
  function useLogger() {
448
- return instance$3.use();
811
+ return instance$1.use();
449
812
  }
450
813
 
451
814
  /*
@@ -475,14 +838,14 @@ class DomainEventPublisher {
475
838
  await this.publish(ctx);
476
839
  } catch (e) {
477
840
  if (isLoggerUsable()) {
478
- useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)} failed`);
841
+ useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
479
842
  useLogger().error(e);
480
843
  }
481
844
  }
482
845
  }
483
846
  async publish(ctx) {
484
847
  if (isLoggerUsable()) {
485
- useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.data.type, ctx.data.event)}`);
848
+ useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)}`);
486
849
  }
487
850
  const publishers = this.publishers.values();
488
851
  while(true){
@@ -538,15 +901,29 @@ function buildEventChannelName(input, id) {
538
901
  }
539
902
  class DomainEventRedisPublisher {
540
903
  async publish(ctx) {
541
- const data = JSON.stringify(transformEventData(ctx.data));
904
+ const payload = {
905
+ type: ctx.metadata.domain,
906
+ event: ctx.metadata.event,
907
+ data: transformEventData(ctx.data)
908
+ };
909
+ const payloadSerialized = JSON.stringify(payload);
542
910
  const pipeline = this.driver.pipeline();
543
911
  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);
912
+ const destination = ctx.destinations[i];
913
+ let keyPrefix;
914
+ if (destination.namespace) {
915
+ keyPrefix = typeof destination.namespace === 'function' ? destination.namespace(ctx.data) : destination.namespace;
916
+ }
917
+ let key;
918
+ if (keyPrefix) {
919
+ key = keyPrefix + buildEventChannelName(destination.channel);
920
+ } else {
921
+ key = buildEventChannelName(destination.channel);
922
+ }
923
+ pipeline.publish(key, payloadSerialized);
924
+ if (typeof destination.channel === 'function') {
925
+ key = keyPrefix + buildEventChannelName(destination.channel, ctx.data.id);
926
+ pipeline.publish(key, payloadSerialized);
550
927
  }
551
928
  }
552
929
  await pipeline.exec();
@@ -579,23 +956,28 @@ class DomainEventSocketPublisher {
579
956
  async publish(ctx) {
580
957
  ctx.data = transformEventData(ctx.data);
581
958
  for(let i = 0; i < ctx.destinations.length; i++){
959
+ const destination = ctx.destinations[i];
582
960
  let namespace;
583
- if (ctx.destinations[i].namespace) {
584
- namespace = ctx.destinations[i].namespace;
961
+ if (destination.namespace) {
962
+ namespace = typeof destination.namespace === 'function' ? destination.namespace(ctx.data) : destination.namespace;
585
963
  } else {
586
964
  namespace = '/';
587
965
  }
588
966
  const emitter = new redisEmitter.Emitter(this.client, {}, namespace);
589
- const fullEventName = kit.buildDomainEventFullName(ctx.data.type, ctx.data.event);
967
+ const fullEventName = kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event);
590
968
  const rooms = [
591
- buildEventChannelName(ctx.destinations[i].channel)
969
+ buildEventChannelName(destination.channel)
592
970
  ];
593
- if (typeof ctx.destinations[i].channel === 'function') {
594
- rooms.push(buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id));
971
+ if (typeof destination.channel === 'function') {
972
+ rooms.push(buildEventChannelName(destination.channel, ctx.data.id));
595
973
  }
596
974
  for(let j = 0; j < rooms.length; j++){
597
975
  emitter.in(rooms[j]).emit(fullEventName, {
598
- ...ctx.data,
976
+ data: {
977
+ data: ctx.data,
978
+ type: ctx.metadata.domain,
979
+ event: ctx.metadata.event
980
+ },
599
981
  meta: {
600
982
  namespace,
601
983
  roomName: rooms[j]
@@ -610,7 +992,7 @@ class DomainEventSocketPublisher {
610
992
  }
611
993
  }
612
994
 
613
- const instance$2 = singa.singa({
995
+ const singaInstance = singa.singa({
614
996
  name: 'domainEventPublisher',
615
997
  factory: ()=>{
616
998
  const publisher = new DomainEventPublisher();
@@ -622,21 +1004,11 @@ const instance$2 = singa.singa({
622
1004
  return publisher;
623
1005
  }
624
1006
  });
625
- function useDomainEventPublisher() {
626
- return instance$2.use();
627
- }
628
-
629
- const instance$1 = singa.singa({
630
- name: 'loki'
631
- });
632
- function setLokiFactory(factory) {
633
- instance$1.setFactory(factory);
1007
+ function useDomainEventPublisherSinga() {
1008
+ return singaInstance;
634
1009
  }
635
- function isLokiClientUsable() {
636
- return instance$1.has() || instance$1.hasFactory();
637
- }
638
- function useLokiClient() {
639
- return instance$1.use();
1010
+ function useDomainEventPublisher() {
1011
+ return singaInstance.use();
640
1012
  }
641
1013
 
642
1014
  /*
@@ -825,7 +1197,9 @@ exports.ComponentError = ComponentError;
825
1197
  exports.DomainEventPublisher = DomainEventPublisher;
826
1198
  exports.DomainEventRedisPublisher = DomainEventRedisPublisher;
827
1199
  exports.DomainEventSocketPublisher = DomainEventSocketPublisher;
1200
+ exports.LokiLogStore = LokiLogStore;
828
1201
  exports.MemoryCacheAdapter = MemoryCacheAdapter;
1202
+ exports.MemoryLogStore = MemoryLogStore;
829
1203
  exports.QueueRouter = QueueRouter;
830
1204
  exports.QueueRouterRoutingType = QueueRouterRoutingType;
831
1205
  exports.RedisCacheAdapter = RedisCacheAdapter;
@@ -839,6 +1213,7 @@ exports.isAmqpClientUsable = isAmqpClientUsable;
839
1213
  exports.isAuthupClientUsable = isAuthupClientUsable;
840
1214
  exports.isClientAuthenticationHookUsable = isClientAuthenticationHookUsable;
841
1215
  exports.isComponentError = isComponentError;
1216
+ exports.isLogStoreUsable = isLogStoreUsable;
842
1217
  exports.isLoggerUsable = isLoggerUsable;
843
1218
  exports.isLokiClientUsable = isLokiClientUsable;
844
1219
  exports.isQueuePayload = isQueuePayload;
@@ -849,6 +1224,7 @@ exports.isVaultClientUsable = isVaultClientUsable;
849
1224
  exports.setAmqpClientFactory = setAmqpClientFactory;
850
1225
  exports.setAuthupClientFactory = setAuthupClientFactory;
851
1226
  exports.setClientAuthenticationHookFactory = setClientAuthenticationHookFactory;
1227
+ exports.setLogStoreFactory = setLogStoreFactory;
852
1228
  exports.setLogger = setLogger;
853
1229
  exports.setLoggerFactory = setLoggerFactory;
854
1230
  exports.setLokiFactory = setLokiFactory;
@@ -860,6 +1236,8 @@ exports.useAuthupClient = useAuthupClient;
860
1236
  exports.useCache = useCache;
861
1237
  exports.useClientAuthenticationHook = useClientAuthenticationHook;
862
1238
  exports.useDomainEventPublisher = useDomainEventPublisher;
1239
+ exports.useDomainEventPublisherSinga = useDomainEventPublisherSinga;
1240
+ exports.useLogStore = useLogStore;
863
1241
  exports.useLogger = useLogger;
864
1242
  exports.useLokiClient = useLokiClient;
865
1243
  exports.useQueueRouter = useQueueRouter;