@privateaim/server-kit 0.8.16 → 0.8.18

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 (92) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/index.cjs +165 -142
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.mjs +156 -135
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/services/entity-event/handlers/index.d.ts +3 -0
  11. package/dist/services/entity-event/handlers/index.d.ts.map +1 -0
  12. package/dist/services/entity-event/handlers/redis/helpers.d.ts +2 -0
  13. package/dist/services/entity-event/handlers/redis/helpers.d.ts.map +1 -0
  14. package/dist/services/entity-event/handlers/redis/index.d.ts.map +1 -0
  15. package/dist/services/entity-event/handlers/redis/module.d.ts +8 -0
  16. package/dist/services/entity-event/handlers/redis/module.d.ts.map +1 -0
  17. package/dist/services/entity-event/handlers/socket/index.d.ts +2 -0
  18. package/dist/services/entity-event/handlers/socket/index.d.ts.map +1 -0
  19. package/dist/services/entity-event/handlers/socket/module.d.ts +10 -0
  20. package/dist/services/entity-event/handlers/socket/module.d.ts.map +1 -0
  21. package/dist/services/entity-event/index.d.ts +5 -0
  22. package/dist/services/entity-event/index.d.ts.map +1 -0
  23. package/dist/services/entity-event/module.d.ts +10 -0
  24. package/dist/services/{domain-event → entity-event}/module.d.ts.map +1 -1
  25. package/dist/services/entity-event/singleton.d.ts +5 -0
  26. package/dist/services/entity-event/singleton.d.ts.map +1 -0
  27. package/dist/services/entity-event/types.d.ts +38 -0
  28. package/dist/services/entity-event/types.d.ts.map +1 -0
  29. package/dist/services/entity-event/utils.d.ts +2 -0
  30. package/dist/services/entity-event/utils.d.ts.map +1 -0
  31. package/dist/services/index.d.ts +1 -1
  32. package/dist/services/logger/index.d.ts +1 -0
  33. package/dist/services/logger/index.d.ts.map +1 -1
  34. package/dist/services/logger/module.d.ts +1 -2
  35. package/dist/services/logger/module.d.ts.map +1 -1
  36. package/dist/services/logger/singleton.d.ts +1 -1
  37. package/dist/services/logger/transports/console.d.ts +8 -0
  38. package/dist/services/logger/transports/console.d.ts.map +1 -0
  39. package/dist/services/logger/transports/index.d.ts +3 -0
  40. package/dist/services/logger/transports/index.d.ts.map +1 -0
  41. package/dist/services/logger/transports/memory.d.ts +6 -0
  42. package/dist/services/logger/transports/memory.d.ts.map +1 -0
  43. package/dist/services/logger/types.d.ts +27 -4
  44. package/dist/services/logger/types.d.ts.map +1 -1
  45. package/package.json +4 -3
  46. package/src/constants.ts +12 -0
  47. package/src/index.ts +1 -0
  48. package/src/services/entity-event/handlers/index.ts +9 -0
  49. package/src/services/{domain-event → entity-event/handlers}/redis/helpers.ts +4 -4
  50. package/src/services/{domain-event → entity-event/handlers}/redis/module.ts +8 -8
  51. package/src/services/{domain-event → entity-event/handlers}/socket/index.ts +0 -1
  52. package/src/services/entity-event/handlers/socket/module.ts +71 -0
  53. package/src/services/{domain-event → entity-event}/index.ts +1 -2
  54. package/src/services/{domain-event → entity-event}/module.ts +24 -20
  55. package/src/services/entity-event/singleton.ts +22 -0
  56. package/src/services/{domain-event → entity-event}/types.ts +18 -16
  57. package/src/services/{domain-event → entity-event}/utils.ts +1 -1
  58. package/src/services/index.ts +1 -1
  59. package/src/services/logger/index.ts +1 -0
  60. package/src/services/logger/module.ts +12 -25
  61. package/src/services/logger/singleton.ts +1 -1
  62. package/src/services/logger/transports/console.ts +27 -0
  63. package/src/services/logger/transports/index.ts +9 -0
  64. package/src/services/logger/transports/memory.ts +18 -0
  65. package/src/services/logger/types.ts +27 -5
  66. package/test/data/error.ts +16 -0
  67. package/test/unit/logger.spec.ts +57 -0
  68. package/dist/services/domain-event/index.d.ts +0 -6
  69. package/dist/services/domain-event/index.d.ts.map +0 -1
  70. package/dist/services/domain-event/module.d.ts +0 -10
  71. package/dist/services/domain-event/redis/helpers.d.ts +0 -2
  72. package/dist/services/domain-event/redis/helpers.d.ts.map +0 -1
  73. package/dist/services/domain-event/redis/index.d.ts.map +0 -1
  74. package/dist/services/domain-event/redis/module.d.ts +0 -8
  75. package/dist/services/domain-event/redis/module.d.ts.map +0 -1
  76. package/dist/services/domain-event/singleton.d.ts +0 -4
  77. package/dist/services/domain-event/singleton.d.ts.map +0 -1
  78. package/dist/services/domain-event/socket/helpers.d.ts +0 -3
  79. package/dist/services/domain-event/socket/helpers.d.ts.map +0 -1
  80. package/dist/services/domain-event/socket/index.d.ts +0 -3
  81. package/dist/services/domain-event/socket/index.d.ts.map +0 -1
  82. package/dist/services/domain-event/socket/module.d.ts +0 -8
  83. package/dist/services/domain-event/socket/module.d.ts.map +0 -1
  84. package/dist/services/domain-event/types.d.ts +0 -37
  85. package/dist/services/domain-event/types.d.ts.map +0 -1
  86. package/dist/services/domain-event/utils.d.ts +0 -2
  87. package/dist/services/domain-event/utils.d.ts.map +0 -1
  88. package/src/services/domain-event/singleton.ts +0 -36
  89. package/src/services/domain-event/socket/helpers.ts +0 -26
  90. package/src/services/domain-event/socket/module.ts +0 -53
  91. /package/dist/services/{domain-event → entity-event/handlers}/redis/index.d.ts +0 -0
  92. /package/src/services/{domain-event → entity-event/handlers}/redis/index.ts +0 -0
package/dist/index.mjs CHANGED
@@ -7,17 +7,29 @@ import { Client, ClientAuthenticationHook } from '@authup/core-http-kit';
7
7
  import { JsonAdapter, buildKeyPath } from 'redis-extension';
8
8
  export { Client as RedisClient, ClientOptions as RedisClientOptions, buildKeyPath as buildRedisKeyPath, createClient as createRedisClient } from 'redis-extension';
9
9
  import TTLCache from '@isaacs/ttlcache';
10
- import { read } from 'envix';
11
- import { EnvironmentName } from 'typeorm-extension';
12
10
  import { transports, createLogger as createLogger$1, format } from 'winston';
11
+ import { read } from 'envix';
12
+ import Transport from 'winston-transport';
13
13
  import { Emitter } from '@socket.io/redis-emitter';
14
14
 
15
+ /*
16
+ * Copyright (c) 2025.
17
+ * Author Peter Placzek (tada5hi)
18
+ * For the full copyright and license information,
19
+ * view the LICENSE file that was distributed with this source code.
20
+ */ var EnvironmentName = /*#__PURE__*/ function(EnvironmentName) {
21
+ EnvironmentName["TEST"] = "test";
22
+ EnvironmentName["DEVELOPMENT"] = "development";
23
+ EnvironmentName["PRODUCTION"] = "production";
24
+ return EnvironmentName;
25
+ }({});
26
+
15
27
  /*
16
28
  * Copyright (c) 2023-2024.
17
29
  * Author Peter Placzek (tada5hi)
18
30
  * For the full copyright and license information,
19
31
  * view the LICENSE file that was distributed with this source code.
20
- */ function _define_property$8(obj, key, value) {
32
+ */ function _define_property$9(obj, key, value) {
21
33
  if (key in obj) {
22
34
  Object.defineProperty(obj, key, {
23
35
  value: value,
@@ -34,7 +46,7 @@ class ComponentError extends Error {
34
46
  constructor(input){
35
47
  super(input.message, {
36
48
  cause: input.cause
37
- }), _define_property$8(this, "code", void 0);
49
+ }), _define_property$9(this, "code", void 0);
38
50
  this.code = input.code;
39
51
  }
40
52
  }
@@ -57,7 +69,7 @@ function isComponentHandlerFn(input) {
57
69
  * Author Peter Placzek (tada5hi)
58
70
  * For the full copyright and license information,
59
71
  * view the LICENSE file that was distributed with this source code.
60
- */ function _define_property$7(obj, key, value) {
72
+ */ function _define_property$8(obj, key, value) {
61
73
  if (key in obj) {
62
74
  Object.defineProperty(obj, key, {
63
75
  value: value,
@@ -104,7 +116,7 @@ class ComponentHandlers {
104
116
  }
105
117
  }
106
118
  constructor(){
107
- _define_property$7(this, "handlers", void 0);
119
+ _define_property$8(this, "handlers", void 0);
108
120
  this.handlers = {};
109
121
  }
110
122
  }
@@ -152,30 +164,30 @@ function isQueueRouterPayload(input) {
152
164
  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);
153
165
  }
154
166
 
155
- const instance$9 = singa({
167
+ const instance$a = singa({
156
168
  name: 'amqp'
157
169
  });
158
170
  function setAmqpClientFactory(factory) {
159
- instance$9.setFactory(factory);
171
+ instance$a.setFactory(factory);
160
172
  }
161
173
  function isAmqpClientUsable() {
162
- return instance$9.has() || instance$9.hasFactory();
174
+ return instance$a.has() || instance$a.hasFactory();
163
175
  }
164
176
  function useAmqpClient() {
165
- return instance$9.use();
177
+ return instance$a.use();
166
178
  }
167
179
 
168
- const instance$8 = singa({
180
+ const instance$9 = singa({
169
181
  name: 'vault'
170
182
  });
171
183
  function setVaultFactory(factory) {
172
- instance$8.setFactory(factory);
184
+ instance$9.setFactory(factory);
173
185
  }
174
186
  function isVaultClientUsable() {
175
- return instance$8.has() || instance$8.hasFactory();
187
+ return instance$9.has() || instance$9.hasFactory();
176
188
  }
177
189
  function useVaultClient() {
178
- return instance$8.use();
190
+ return instance$9.use();
179
191
  }
180
192
 
181
193
  function guessAuthupTokenCreatorOptions() {
@@ -196,17 +208,17 @@ function guessAuthupTokenCreatorOptions() {
196
208
  return options;
197
209
  }
198
210
 
199
- const instance$7 = singa({
211
+ const instance$8 = singa({
200
212
  name: 'clientAuthenticationHook'
201
213
  });
202
214
  function setClientAuthenticationHookFactory(factory) {
203
- instance$7.setFactory(factory);
215
+ instance$8.setFactory(factory);
204
216
  }
205
217
  function isClientAuthenticationHookUsable() {
206
- return instance$7.has() || instance$7.hasFactory();
218
+ return instance$8.has() || instance$8.hasFactory();
207
219
  }
208
220
  function useClientAuthenticationHook() {
209
- return instance$7.use();
221
+ return instance$8.use();
210
222
  }
211
223
 
212
224
  class AuthupClient extends Client {
@@ -223,49 +235,49 @@ class AuthupClient extends Client {
223
235
  }
224
236
  }
225
237
 
226
- const instance$6 = singa({
238
+ const instance$7 = singa({
227
239
  name: 'authup'
228
240
  });
229
241
  function useAuthupClient() {
230
- return instance$6.use();
242
+ return instance$7.use();
231
243
  }
232
244
  function isAuthupClientUsable() {
233
- return instance$6.has() || instance$6.hasFactory();
245
+ return instance$7.has() || instance$7.hasFactory();
234
246
  }
235
247
  function setAuthupClientFactory(factory) {
236
- instance$6.setFactory(factory);
248
+ instance$7.setFactory(factory);
237
249
  }
238
250
 
239
- const instance$5 = singa({
251
+ const instance$6 = singa({
240
252
  name: 'redis'
241
253
  });
242
254
  function setRedisFactory(factory) {
243
- instance$5.setFactory(factory);
255
+ instance$6.setFactory(factory);
244
256
  }
245
257
  function isRedisClientUsable() {
246
- return instance$5.has() || instance$5.hasFactory();
258
+ return instance$6.has() || instance$6.hasFactory();
247
259
  }
248
260
  function setRedisClient(input) {
249
- instance$5.set(input);
261
+ instance$6.set(input);
250
262
  }
251
263
  function useRedisClient() {
252
- return instance$5.use();
264
+ return instance$6.use();
253
265
  }
254
266
 
255
- const instance$4 = singa({
267
+ const instance$5 = singa({
256
268
  name: 'redisPublish',
257
269
  factory: ()=>useRedisClient().duplicate()
258
270
  });
259
271
  function useRedisPublishClient() {
260
- return instance$4.use();
272
+ return instance$5.use();
261
273
  }
262
274
 
263
- const instance$3 = singa({
275
+ const instance$4 = singa({
264
276
  name: 'redisSubscribe',
265
277
  factory: ()=>useRedisClient().duplicate()
266
278
  });
267
279
  function useRedisSubscribeClient() {
268
- return instance$3.use();
280
+ return instance$4.use();
269
281
  }
270
282
 
271
283
  /*
@@ -273,7 +285,7 @@ function useRedisSubscribeClient() {
273
285
  * Author Peter Placzek (tada5hi)
274
286
  * For the full copyright and license information,
275
287
  * view the LICENSE file that was distributed with this source code.
276
- */ function _define_property$6(obj, key, value) {
288
+ */ function _define_property$7(obj, key, value) {
277
289
  if (key in obj) {
278
290
  Object.defineProperty(obj, key, {
279
291
  value: value,
@@ -321,7 +333,7 @@ class MemoryCacheAdapter {
321
333
  this.instance.clear();
322
334
  }
323
335
  constructor(options = {}){
324
- _define_property$6(this, "instance", void 0);
336
+ _define_property$7(this, "instance", void 0);
325
337
  this.instance = new TTLCache({
326
338
  checkAgeOnGet: true,
327
339
  ttl: Infinity,
@@ -335,7 +347,7 @@ class MemoryCacheAdapter {
335
347
  * Author Peter Placzek (tada5hi)
336
348
  * For the full copyright and license information,
337
349
  * view the LICENSE file that was distributed with this source code.
338
- */ function _define_property$5(obj, key, value) {
350
+ */ function _define_property$6(obj, key, value) {
339
351
  if (key in obj) {
340
352
  Object.defineProperty(obj, key, {
341
353
  value: value,
@@ -384,8 +396,8 @@ class RedisCacheAdapter {
384
396
  await this.client.flushdb();
385
397
  }
386
398
  constructor(){
387
- _define_property$5(this, "client", void 0);
388
- _define_property$5(this, "instance", void 0);
399
+ _define_property$6(this, "client", void 0);
400
+ _define_property$6(this, "instance", void 0);
389
401
  this.client = useRedisClient();
390
402
  this.instance = new JsonAdapter(this.client);
391
403
  }
@@ -407,7 +419,7 @@ function buildCacheKey(options) {
407
419
  * Author Peter Placzek (tada5hi)
408
420
  * For the full copyright and license information,
409
421
  * view the LICENSE file that was distributed with this source code.
410
- */ function _define_property$4(obj, key, value) {
422
+ */ function _define_property$5(obj, key, value) {
411
423
  if (key in obj) {
412
424
  Object.defineProperty(obj, key, {
413
425
  value: value,
@@ -440,12 +452,12 @@ class Cache {
440
452
  return this.adapter.clear(options);
441
453
  }
442
454
  constructor(adapter){
443
- _define_property$4(this, "adapter", void 0);
455
+ _define_property$5(this, "adapter", void 0);
444
456
  this.adapter = adapter;
445
457
  }
446
458
  }
447
459
 
448
- const instance$2 = singa({
460
+ const instance$3 = singa({
449
461
  name: 'cache',
450
462
  factory: ()=>{
451
463
  let adapter;
@@ -458,60 +470,85 @@ const instance$2 = singa({
458
470
  }
459
471
  });
460
472
  function useCache() {
461
- return instance$2.use();
473
+ return instance$3.use();
462
474
  }
463
475
 
464
- function toTransports(input) {
465
- return Array.isArray(input) ? input : [
466
- input
467
- ];
476
+ class LoggerConsoleTransport extends transports.Console {
477
+ constructor(options = {}){
478
+ super({
479
+ level: read('env') === EnvironmentName.PRODUCTION ? 'info' : 'debug',
480
+ ...options
481
+ });
482
+ }
468
483
  }
469
- function createLogger(ctx = {}) {
470
- let loggerTransports;
471
- if (read('env') === EnvironmentName.PRODUCTION) {
472
- loggerTransports = [
473
- new transports.Console({
474
- level: 'info'
475
- }),
476
- ...ctx.transports ? toTransports(ctx.transports) : []
477
- ];
484
+ function createLoggerConsoleTransport(options = {}) {
485
+ return new LoggerConsoleTransport(options);
486
+ }
487
+
488
+ /*
489
+ * Copyright (c) 2025.
490
+ * Author Peter Placzek (tada5hi)
491
+ * For the full copyright and license information,
492
+ * view the LICENSE file that was distributed with this source code.
493
+ */ function _define_property$4(obj, key, value) {
494
+ if (key in obj) {
495
+ Object.defineProperty(obj, key, {
496
+ value: value,
497
+ enumerable: true,
498
+ configurable: true,
499
+ writable: true
500
+ });
478
501
  } else {
479
- loggerTransports = [
480
- new transports.Console({
481
- level: 'debug'
482
- }),
483
- ...ctx.transports ? toTransports(ctx.transports) : []
484
- ];
502
+ obj[key] = value;
503
+ }
504
+ return obj;
505
+ }
506
+ class LoggerMemoryTransport extends Transport {
507
+ log(info, next) {
508
+ this.items.push(info);
509
+ next();
510
+ }
511
+ constructor(...args){
512
+ super(...args), _define_property$4(this, "items", []);
513
+ }
514
+ }
515
+
516
+ function createLogger(ctx = {}) {
517
+ const transports = [
518
+ ...ctx.transports || []
519
+ ];
520
+ if (transports.length === 0) {
521
+ transports.push(createLoggerConsoleTransport());
485
522
  }
486
523
  return createLogger$1({
487
524
  format: format.combine(format.errors({
488
525
  stack: true
489
526
  }), format.timestamp(), format.simple()),
490
527
  level: 'debug',
491
- transports: loggerTransports,
528
+ transports,
492
529
  // todo: deeply merge options
493
530
  ...ctx.options || {}
494
531
  });
495
532
  }
496
533
 
497
- const instance$1 = singa({
534
+ const instance$2 = singa({
498
535
  name: 'logger'
499
536
  });
500
537
  function setLoggerFactory(factory) {
501
- instance$1.setFactory(factory);
538
+ instance$2.setFactory(factory);
502
539
  }
503
540
  function isLoggerUsable() {
504
- return instance$1.has() || instance$1.hasFactory();
541
+ return instance$2.has() || instance$2.hasFactory();
505
542
  }
506
543
  function setLogger(input) {
507
- instance$1.set(input);
544
+ instance$2.set(input);
508
545
  }
509
546
  function useLogger() {
510
- return instance$1.use();
547
+ return instance$2.use();
511
548
  }
512
549
 
513
550
  /*
514
- * Copyright (c) 2024-2024.
551
+ * Copyright (c) 2024-2025.
515
552
  * Author Peter Placzek (tada5hi)
516
553
  * For the full copyright and license information,
517
554
  * view the LICENSE file that was distributed with this source code.
@@ -528,23 +565,23 @@ function useLogger() {
528
565
  }
529
566
  return obj;
530
567
  }
531
- class DomainEventPublisher {
532
- addConsumer(consumer) {
533
- this.consumers.add(consumer);
568
+ class EntityEventPublisher {
569
+ register(consumer) {
570
+ this.handlers.add(consumer);
534
571
  }
535
572
  async safePublish(ctx) {
536
573
  try {
537
574
  await this.publish(ctx);
538
575
  } catch (e) {
539
576
  if (isLoggerUsable()) {
540
- useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
577
+ useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.metadata.ref_type, ctx.metadata.event)} failed`);
541
578
  useLogger().error(e);
542
579
  }
543
580
  }
544
581
  }
545
582
  async publish(ctx) {
546
583
  if (isLoggerUsable()) {
547
- useLogger().info(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)}`);
584
+ useLogger().debug(`Publishing event ${buildDomainEventFullName(ctx.metadata.ref_type, ctx.metadata.event)}`);
548
585
  }
549
586
  let destinations = [];
550
587
  if (typeof ctx.destinations === 'function') {
@@ -556,22 +593,22 @@ class DomainEventPublisher {
556
593
  ...ctx,
557
594
  destinations
558
595
  };
559
- const consumers = this.consumers.values();
596
+ const handlers = this.handlers.values();
560
597
  while(true){
561
- const it = consumers.next();
562
- if (it.done) {
598
+ const handler = handlers.next();
599
+ if (handler.done) {
563
600
  return;
564
601
  }
565
- await it.value.consume(consumeContext);
602
+ await handler.value.handle(consumeContext);
566
603
  }
567
604
  }
568
605
  constructor(){
569
- _define_property$3(this, "consumers", void 0);
570
- this.consumers = new Set();
606
+ _define_property$3(this, "handlers", void 0);
607
+ this.handlers = new Set();
571
608
  }
572
609
  }
573
610
 
574
- function transformEventData(input) {
611
+ function transformEntityEventData(input) {
575
612
  if (isObject(input)) {
576
613
  const keys = Object.keys(input);
577
614
  for(let i = 0; i < keys.length; i++){
@@ -586,13 +623,13 @@ function transformEventData(input) {
586
623
 
587
624
  /*
588
625
  * 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.
626
+ * Author Peter Placzek (tada5hi)
627
+ * For the full copyright and license information,
628
+ * view the LICENSE file that was distributed with this source code.
592
629
  */ function stringify(input) {
593
630
  return typeof input === 'string' ? input : input.join('/');
594
631
  }
595
- function buildDomainEventRedisChannel(channel, namespace) {
632
+ function buildEntityEventRedisChannel(channel, namespace) {
596
633
  const channelNormalized = stringify(channel);
597
634
  let namespaceNormalized;
598
635
  if (namespace) {
@@ -622,18 +659,18 @@ function buildDomainEventRedisChannel(channel, namespace) {
622
659
  }
623
660
  return obj;
624
661
  }
625
- class DomainEventRedisPublisher {
626
- async consume(ctx) {
662
+ class EntityEventRedisHandler {
663
+ async handle(ctx) {
627
664
  const payload = {
628
- type: ctx.metadata.domain,
665
+ type: ctx.metadata.ref_type,
629
666
  event: ctx.metadata.event,
630
- data: transformEventData(ctx.data)
667
+ data: transformEntityEventData(ctx.data)
631
668
  };
632
669
  const payloadSerialized = JSON.stringify(payload);
633
670
  const pipeline = this.driver.pipeline();
634
671
  for(let i = 0; i < ctx.destinations.length; i++){
635
672
  const destination = ctx.destinations[i];
636
- const key = buildDomainEventRedisChannel(destination.channel, destination.namespace);
673
+ const key = buildEntityEventRedisChannel(destination.channel, destination.namespace);
637
674
  pipeline.publish(key, payloadSerialized);
638
675
  }
639
676
  await pipeline.exec();
@@ -644,27 +681,6 @@ class DomainEventRedisPublisher {
644
681
  }
645
682
  }
646
683
 
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
-
668
684
  /*
669
685
  * Copyright (c) 2022-2024.
670
686
  * Author Peter Placzek (tada5hi)
@@ -683,51 +699,56 @@ function buildDomainEventSocketChannel(channel) {
683
699
  }
684
700
  return obj;
685
701
  }
686
- class DomainEventSocketConsumer {
687
- async consume(ctx) {
688
- ctx.data = transformEventData(ctx.data);
702
+ class EntityEventSocketHandler {
703
+ async handle(ctx) {
704
+ ctx.data = transformEntityEventData(ctx.data);
689
705
  for(let i = 0; i < ctx.destinations.length; i++){
690
706
  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);
707
+ const namespace = this.buildNamespace(destination.namespace);
708
+ const roomName = this.buildChannel(destination.channel);
709
+ const fullEventName = buildDomainEventFullName(ctx.metadata.ref_type, ctx.metadata.event);
694
710
  const emitter = new Emitter(this.client, {}, namespace);
695
711
  emitter.in(roomName).emit(fullEventName, {
696
- data: {
697
- data: ctx.data,
698
- type: ctx.metadata.domain,
699
- event: ctx.metadata.event
700
- },
712
+ data: ctx.data,
701
713
  meta: {
714
+ refType: ctx.metadata.ref_type,
715
+ refId: ctx.metadata.ref_id,
716
+ event: ctx.metadata.event,
702
717
  namespace,
703
718
  roomName
704
719
  }
705
720
  });
706
721
  }
707
722
  }
723
+ buildNamespace(namespace) {
724
+ if (typeof namespace === 'undefined') {
725
+ return '/';
726
+ }
727
+ if (typeof namespace === 'string') {
728
+ return namespace.startsWith('/') ? namespace : `/${namespace}`;
729
+ }
730
+ return `/${namespace.join('/')}`;
731
+ }
732
+ buildChannel(channel) {
733
+ if (typeof channel === 'string') {
734
+ return channel;
735
+ }
736
+ return channel.join('/');
737
+ }
708
738
  constructor(client){
709
739
  _define_property$1(this, "client", void 0);
710
740
  this.client = client;
711
741
  }
712
742
  }
713
743
 
714
- const singaInstance = singa({
715
- name: 'domainEventPublisher',
716
- factory: ()=>{
717
- const publisher = new DomainEventPublisher();
718
- if (isRedisClientUsable()) {
719
- const client = useRedisClient();
720
- publisher.addConsumer(new DomainEventRedisPublisher(client));
721
- publisher.addConsumer(new DomainEventSocketConsumer(client));
722
- }
723
- return publisher;
724
- }
744
+ const instance$1 = singa({
745
+ name: 'entityEventPublisher'
725
746
  });
726
- function useDomainEventPublisherSinga() {
727
- return singaInstance;
747
+ function setEntityEventPublisherFactory(factory) {
748
+ instance$1.setFactory(factory);
728
749
  }
729
- function useDomainEventPublisher() {
730
- return singaInstance.use();
750
+ function useEntityEventPublisher() {
751
+ return instance$1.use();
731
752
  }
732
753
 
733
754
  /*
@@ -855,5 +876,5 @@ function useQueueRouter() {
855
876
  return instance.use();
856
877
  }
857
878
 
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 };
879
+ export { AuthupClient, Cache, ComponentError, ComponentHandlers, EntityEventPublisher, EntityEventRedisHandler, EntityEventSocketHandler, EnvironmentName, LoggerConsoleTransport, LoggerMemoryTransport, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildEntityEventRedisChannel, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, createLoggerConsoleTransport, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isClientAuthenticationHookUsable, isComponentError, isLoggerUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable, setAmqpClientFactory, setAuthupClientFactory, setClientAuthenticationHookFactory, setEntityEventPublisherFactory, setLogger, setLoggerFactory, setRedisClient, setRedisFactory, setVaultFactory, useAmqpClient, useAuthupClient, useCache, useClientAuthenticationHook, useEntityEventPublisher, useLogger, useQueueRouter, useRedisClient, useRedisPublishClient, useRedisSubscribeClient, useVaultClient };
859
880
  //# sourceMappingURL=index.mjs.map