@privateaim/server-kit 0.8.15 → 0.8.17

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 (154) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/core/component/handler/check.d.ts +4 -0
  5. package/dist/core/component/handler/check.d.ts.map +1 -0
  6. package/dist/core/component/handler/index.d.ts +3 -0
  7. package/dist/core/component/handler/index.d.ts.map +1 -0
  8. package/dist/core/component/handler/module.d.ts +11 -0
  9. package/dist/core/component/handler/module.d.ts.map +1 -0
  10. package/dist/core/component/handler/types.d.ts +11 -0
  11. package/dist/core/component/handler/types.d.ts.map +1 -0
  12. package/dist/core/component/index.d.ts +1 -0
  13. package/dist/core/component/index.d.ts.map +1 -1
  14. package/dist/core/queue-router/module.d.ts +3 -2
  15. package/dist/core/queue-router/module.d.ts.map +1 -1
  16. package/dist/core/queue-router/types.d.ts +7 -4
  17. package/dist/core/queue-router/types.d.ts.map +1 -1
  18. package/dist/index.cjs +262 -550
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.mjs +250 -504
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/services/amqp/index.d.ts +1 -0
  25. package/dist/services/amqp/index.d.ts.map +1 -1
  26. package/dist/services/amqp/module.d.ts +2 -5
  27. package/dist/services/amqp/module.d.ts.map +1 -1
  28. package/dist/services/amqp/singleton.d.ts +6 -0
  29. package/dist/services/amqp/singleton.d.ts.map +1 -0
  30. package/dist/services/entity-event/handlers/index.d.ts +3 -0
  31. package/dist/services/entity-event/handlers/index.d.ts.map +1 -0
  32. package/dist/services/entity-event/handlers/redis/helpers.d.ts +2 -0
  33. package/dist/services/entity-event/handlers/redis/helpers.d.ts.map +1 -0
  34. package/dist/services/entity-event/handlers/redis/index.d.ts +3 -0
  35. package/dist/services/entity-event/handlers/redis/index.d.ts.map +1 -0
  36. package/dist/services/entity-event/handlers/redis/module.d.ts +8 -0
  37. package/dist/services/entity-event/handlers/redis/module.d.ts.map +1 -0
  38. package/dist/services/entity-event/handlers/socket/index.d.ts.map +1 -0
  39. package/dist/services/entity-event/handlers/socket/module.d.ts +10 -0
  40. package/dist/services/entity-event/handlers/socket/module.d.ts.map +1 -0
  41. package/dist/services/entity-event/index.d.ts +5 -0
  42. package/dist/services/entity-event/index.d.ts.map +1 -0
  43. package/dist/services/entity-event/module.d.ts +10 -0
  44. package/dist/services/entity-event/module.d.ts.map +1 -0
  45. package/dist/services/entity-event/singleton.d.ts +5 -0
  46. package/dist/services/entity-event/singleton.d.ts.map +1 -0
  47. package/dist/services/entity-event/types.d.ts +38 -0
  48. package/dist/services/entity-event/types.d.ts.map +1 -0
  49. package/dist/services/entity-event/utils.d.ts +2 -0
  50. package/dist/services/entity-event/utils.d.ts.map +1 -0
  51. package/dist/services/index.d.ts +1 -3
  52. package/dist/services/index.d.ts.map +1 -1
  53. package/dist/services/logger/index.d.ts +1 -0
  54. package/dist/services/logger/index.d.ts.map +1 -1
  55. package/dist/services/logger/module.d.ts +1 -2
  56. package/dist/services/logger/module.d.ts.map +1 -1
  57. package/dist/services/logger/singleton.d.ts +1 -1
  58. package/dist/services/logger/transports/console.d.ts +8 -0
  59. package/dist/services/logger/transports/console.d.ts.map +1 -0
  60. package/dist/services/logger/transports/index.d.ts +3 -0
  61. package/dist/services/logger/transports/index.d.ts.map +1 -0
  62. package/dist/services/logger/transports/memory.d.ts +6 -0
  63. package/dist/services/logger/transports/memory.d.ts.map +1 -0
  64. package/dist/services/logger/types.d.ts +27 -7
  65. package/dist/services/logger/types.d.ts.map +1 -1
  66. package/package.json +2 -3
  67. package/src/constants.ts +12 -0
  68. package/src/core/component/handler/check.ts +23 -0
  69. package/src/{services/loki → core/component/handler}/index.ts +2 -2
  70. package/src/core/component/handler/module.ts +57 -0
  71. package/src/core/component/handler/types.ts +28 -0
  72. package/src/core/component/index.ts +1 -0
  73. package/src/core/queue-router/module.ts +30 -4
  74. package/src/core/queue-router/types.ts +12 -5
  75. package/src/index.ts +1 -0
  76. package/src/services/amqp/index.ts +1 -0
  77. package/src/services/amqp/module.ts +5 -19
  78. package/src/services/{loki → amqp}/singleton.ts +6 -6
  79. package/src/services/entity-event/handlers/index.ts +9 -0
  80. package/src/services/entity-event/handlers/redis/helpers.ts +28 -0
  81. package/src/services/{domain-event → entity-event/handlers}/redis/index.ts +1 -0
  82. package/src/services/entity-event/handlers/redis/module.ts +44 -0
  83. package/src/services/entity-event/handlers/socket/module.ts +72 -0
  84. package/src/services/{domain-event → entity-event}/index.ts +1 -2
  85. package/src/services/entity-event/module.ts +75 -0
  86. package/src/services/entity-event/singleton.ts +22 -0
  87. package/src/services/entity-event/types.ts +61 -0
  88. package/src/services/{domain-event → entity-event}/utils.ts +1 -13
  89. package/src/services/index.ts +1 -3
  90. package/src/services/logger/index.ts +1 -0
  91. package/src/services/logger/module.ts +11 -49
  92. package/src/services/logger/singleton.ts +1 -1
  93. package/src/services/logger/transports/console.ts +27 -0
  94. package/src/services/logger/transports/index.ts +9 -0
  95. package/src/services/logger/transports/memory.ts +18 -0
  96. package/src/services/logger/types.ts +27 -8
  97. package/test/data/error.ts +16 -0
  98. package/test/unit/logger.spec.ts +41 -20
  99. package/dist/services/domain-event/index.d.ts +0 -6
  100. package/dist/services/domain-event/index.d.ts.map +0 -1
  101. package/dist/services/domain-event/module.d.ts +0 -10
  102. package/dist/services/domain-event/module.d.ts.map +0 -1
  103. package/dist/services/domain-event/redis/index.d.ts.map +0 -1
  104. package/dist/services/domain-event/redis/module.d.ts +0 -8
  105. package/dist/services/domain-event/redis/module.d.ts.map +0 -1
  106. package/dist/services/domain-event/singleton.d.ts +0 -4
  107. package/dist/services/domain-event/singleton.d.ts.map +0 -1
  108. package/dist/services/domain-event/socket/index.d.ts +0 -2
  109. package/dist/services/domain-event/socket/index.d.ts.map +0 -1
  110. package/dist/services/domain-event/socket/module.d.ts +0 -8
  111. package/dist/services/domain-event/socket/module.d.ts.map +0 -1
  112. package/dist/services/domain-event/types.d.ts +0 -29
  113. package/dist/services/domain-event/types.d.ts.map +0 -1
  114. package/dist/services/domain-event/utils.d.ts +0 -4
  115. package/dist/services/domain-event/utils.d.ts.map +0 -1
  116. package/dist/services/log-store/entities/base.d.ts +0 -7
  117. package/dist/services/log-store/entities/base.d.ts.map +0 -1
  118. package/dist/services/log-store/entities/index.d.ts +0 -3
  119. package/dist/services/log-store/entities/index.d.ts.map +0 -1
  120. package/dist/services/log-store/entities/loki.d.ts +0 -13
  121. package/dist/services/log-store/entities/loki.d.ts.map +0 -1
  122. package/dist/services/log-store/entities/memory.d.ts +0 -11
  123. package/dist/services/log-store/entities/memory.d.ts.map +0 -1
  124. package/dist/services/log-store/index.d.ts +0 -4
  125. package/dist/services/log-store/index.d.ts.map +0 -1
  126. package/dist/services/log-store/singleton.d.ts +0 -6
  127. package/dist/services/log-store/singleton.d.ts.map +0 -1
  128. package/dist/services/log-store/types.d.ts +0 -27
  129. package/dist/services/log-store/types.d.ts.map +0 -1
  130. package/dist/services/logger/store.d.ts +0 -14
  131. package/dist/services/logger/store.d.ts.map +0 -1
  132. package/dist/services/loki/index.d.ts +0 -3
  133. package/dist/services/loki/index.d.ts.map +0 -1
  134. package/dist/services/loki/module.d.ts +0 -3
  135. package/dist/services/loki/module.d.ts.map +0 -1
  136. package/dist/services/loki/singleton.d.ts +0 -6
  137. package/dist/services/loki/singleton.d.ts.map +0 -1
  138. package/src/services/domain-event/module.ts +0 -54
  139. package/src/services/domain-event/redis/module.ts +0 -56
  140. package/src/services/domain-event/singleton.ts +0 -36
  141. package/src/services/domain-event/socket/module.ts +0 -68
  142. package/src/services/domain-event/types.ts +0 -50
  143. package/src/services/log-store/entities/base.ts +0 -25
  144. package/src/services/log-store/entities/index.ts +0 -9
  145. package/src/services/log-store/entities/loki.ts +0 -158
  146. package/src/services/log-store/entities/memory.ts +0 -100
  147. package/src/services/log-store/index.ts +0 -10
  148. package/src/services/log-store/singleton.ts +0 -36
  149. package/src/services/log-store/types.ts +0 -42
  150. package/src/services/logger/store.ts +0 -70
  151. package/src/services/loki/module.ts +0 -30
  152. package/test/unit/log-store.spec.ts +0 -21
  153. /package/dist/services/{domain-event/redis → entity-event/handlers/socket}/index.d.ts +0 -0
  154. /package/src/services/{domain-event → entity-event/handlers}/socket/index.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"loki.d.ts","sourceRoot":"","sources":["../../../../src/services/log-store/entities/loki.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,UAAU,EAA2D,MAAM,YAAY,CAAC;AAEtG,OAAO,KAAK,EACR,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,EAAE,oBAAoB,EAClE,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,qBAAa,YAAa,SAAQ,YAAa,YAAW,QAAQ;IAC9D,SAAS,CAAC,QAAQ,EAAG,UAAU,CAAC;gBAEpB,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAO3D,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IA+ChF,MAAM,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD,KAAK,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IA+DlE,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAI,MAAM;CAU7D"}
@@ -1,11 +0,0 @@
1
- import type { Log } from '@privateaim/kit';
2
- import type { LogInput, LogStore, LogStoreQueryOptions } from '../types';
3
- import { BaseLogStore } from './base';
4
- export declare class MemoryLogStore extends BaseLogStore implements LogStore {
5
- readonly items: Log[];
6
- constructor(labels?: Record<string, string>);
7
- delete(): Promise<void>;
8
- query(options?: LogStoreQueryOptions): Promise<[Log[], number]>;
9
- write(message: string | LogInput, labels?: Record<string, string>): Promise<Log>;
10
- }
11
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/services/log-store/entities/memory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EACR,QAAQ,EAAE,QAAQ,EAAE,oBAAoB,EAC3C,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,qBAAa,cAAe,SAAQ,YAAa,YAAW,QAAQ;IAChE,SAAgB,KAAK,EAAG,GAAG,EAAE,CAAC;gBAElB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQrC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,KAAK,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IA8BnE,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAuCzF"}
@@ -1,4 +0,0 @@
1
- export * from './entities';
2
- export * from './singleton';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/log-store/index.ts"],"names":[],"mappings":"AAOA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -1,6 +0,0 @@
1
- import type { Factory } from 'singa';
2
- import type { LogStore } from './types';
3
- export declare function isLogStoreUsable(): boolean;
4
- export declare function setLogStoreFactory(input: Factory<LogStore>): void;
5
- export declare function useLogStore(): LogStore;
6
- //# sourceMappingURL=singleton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../../src/services/log-store/singleton.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAgBxC,wBAAgB,gBAAgB,YAE/B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,QAE1D;AAED,wBAAgB,WAAW,IAAI,QAAQ,CAEtC"}
@@ -1,27 +0,0 @@
1
- import type { Log, LogLevel } from '@privateaim/kit';
2
- export type LogStoreQueryOptions = {
3
- labels?: Record<string, string>;
4
- start?: number;
5
- end?: number;
6
- sort?: 'DESC' | 'ASC';
7
- limit?: number;
8
- };
9
- export type LogStoreDeleteOptions = {
10
- labels?: Record<string, string>;
11
- start?: number;
12
- end?: number;
13
- };
14
- export type LogInput = Omit<Log, 'labels' | 'time' | 'level'> & {
15
- time?: bigint;
16
- level?: `${LogLevel}`;
17
- labels?: Record<string, string>;
18
- };
19
- export interface LogStore {
20
- setLabels(labels: Record<string, string>): void;
21
- getLabels(): Record<string, string>;
22
- extendLabels(labels: Record<string, string>): void;
23
- write(message: string | LogInput, labels?: Record<string, string>): Promise<Log>;
24
- query(options?: LogStoreQueryOptions): Promise<[Log[], number]>;
25
- delete(options?: LogStoreDeleteOptions): Promise<void>;
26
- }
27
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/log-store/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,MAAM,oBAAoB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAC;AAEF,MAAM,WAAW,QAAQ;IACrB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAEhD,SAAS,IAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAEnD,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAElF,KAAK,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAEjE,MAAM,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D"}
@@ -1,14 +0,0 @@
1
- import type { TransportStreamOptions } from 'winston-transport';
2
- import WinstonTransport from 'winston-transport';
3
- import type { LogStore } from '../log-store';
4
- type LogStoreTransportOptions = TransportStreamOptions & {
5
- labels?: Record<string, string>;
6
- };
7
- export declare class LogStoreTransport extends WinstonTransport {
8
- protected instance: LogStore;
9
- protected labels: Record<string, string>;
10
- constructor(store: LogStore, options?: LogStoreTransportOptions);
11
- log(info: Record<PropertyKey, any>, next: () => void): any;
12
- }
13
- export {};
14
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/services/logger/store.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvD,KAAK,wBAAwB,GAAG,sBAAsB,GAAG;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,gBAAgB;IACnD,SAAS,CAAC,QAAQ,EAAG,QAAQ,CAAC;IAE9B,SAAS,CAAC,MAAM,EAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE9B,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,wBAA6B;IAOnE,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,GAAG;CA0C7D"}
@@ -1,3 +0,0 @@
1
- export * from './module';
2
- export * from './singleton';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/loki/index.ts"],"names":[],"mappings":"AAOA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -1,3 +0,0 @@
1
- import { 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';
2
- export { LokiClient, LokiConfig, LokiConfigInput, LokiCompactorDeletionRequestCreate, LokiDistributorPushStream, LokiQuerierQueryRangeOptions, LokiQuerierQueryResult, createLokiClient, nanoSeconds, };
3
- //# sourceMappingURL=module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/services/loki/module.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,UAAU,EACV,8BAA8B,IAAI,kCAAkC,EACpE,MAAM,IAAI,UAAU,EACpB,WAAW,IAAI,eAAe,EAC9B,qBAAqB,IAAI,yBAAyB,EAClD,wBAAwB,IAAI,4BAA4B,EACxD,kBAAkB,IAAI,sBAAsB,EAC5C,YAAY,IAAI,gBAAgB,EAChC,WAAW,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,UAAU,EACV,UAAU,EACV,eAAe,EACf,kCAAkC,EAClC,yBAAyB,EACzB,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,GACd,CAAC"}
@@ -1,6 +0,0 @@
1
- import type { Factory } from 'singa';
2
- import type { LokiClient } from '@hapic/loki';
3
- export declare function setLokiFactory(factory: Factory<LokiClient>): void;
4
- export declare function isLokiClientUsable(): boolean;
5
- export declare function useLokiClient(): LokiClient;
6
- //# sourceMappingURL=singleton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../../src/services/loki/singleton.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9C,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,QAE1D;AAED,wBAAgB,kBAAkB,YAEjC;AAED,wBAAgB,aAAa,eAE5B"}
@@ -1,54 +0,0 @@
1
- /*
2
- * Copyright (c) 2024-2024.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import type { ObjectLiteral } from '@privateaim/kit';
9
- import { buildDomainEventFullName } from '@privateaim/kit';
10
- import { isLoggerUsable, useLogger } from '../logger';
11
- import type { DomainEventPublishOptions, IDomainEventPublisher } from './types';
12
-
13
- export class DomainEventPublisher implements IDomainEventPublisher {
14
- protected publishers : Set<IDomainEventPublisher>;
15
-
16
- constructor() {
17
- this.publishers = new Set<IDomainEventPublisher>();
18
- }
19
-
20
- addPublisher(publisher: IDomainEventPublisher) {
21
- this.publishers.add(publisher);
22
- }
23
-
24
- async safePublish<T extends ObjectLiteral = ObjectLiteral>(
25
- ctx: DomainEventPublishOptions<T>,
26
- ) : Promise<void> {
27
- try {
28
- await this.publish(ctx);
29
- } catch (e) {
30
- if (isLoggerUsable()) {
31
- useLogger().error(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
32
- useLogger().error(e);
33
- }
34
- }
35
- }
36
-
37
- async publish<T extends ObjectLiteral = ObjectLiteral>(
38
- ctx: DomainEventPublishOptions<T>,
39
- ) : Promise<void> {
40
- if (isLoggerUsable()) {
41
- useLogger().info(`Publishing event ${buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)}`);
42
- }
43
-
44
- const publishers = this.publishers.values();
45
- while (true) {
46
- const it = publishers.next();
47
- if (it.done) {
48
- return;
49
- }
50
-
51
- await it.value.publish(ctx);
52
- }
53
- }
54
- }
@@ -1,56 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2024.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import type { Client } from 'redis-extension';
9
- import type { DomainEventRecord } from '@privateaim/kit';
10
- import type { DomainEventPublishOptions, IDomainEventPublisher } from '../types';
11
- import { buildEventChannelName, transformEventData } from '../utils';
12
-
13
- export class DomainEventRedisPublisher implements IDomainEventPublisher {
14
- protected driver : Client;
15
-
16
- constructor(client: Client) {
17
- this.driver = client;
18
- }
19
-
20
- async publish(ctx: DomainEventPublishOptions) : Promise<void> {
21
- const payload : DomainEventRecord = {
22
- type: ctx.metadata.domain,
23
- event: ctx.metadata.event,
24
- data: transformEventData(ctx.data),
25
- };
26
- const payloadSerialized = JSON.stringify(payload);
27
-
28
- const pipeline = this.driver.pipeline();
29
- for (let i = 0; i < ctx.destinations.length; i++) {
30
- const destination = ctx.destinations[i];
31
-
32
- let keyPrefix : string | undefined;
33
- if (destination.namespace) {
34
- keyPrefix = typeof destination.namespace === 'function' ?
35
- destination.namespace(ctx.data) :
36
- destination.namespace;
37
- }
38
-
39
- let key : string;
40
- if (keyPrefix) {
41
- key = keyPrefix + buildEventChannelName(destination.channel);
42
- } else {
43
- key = buildEventChannelName(destination.channel);
44
- }
45
-
46
- pipeline.publish(key, payloadSerialized);
47
-
48
- if (typeof destination.channel === 'function') {
49
- key = keyPrefix + buildEventChannelName(destination.channel, ctx.data.id);
50
- pipeline.publish(key, payloadSerialized);
51
- }
52
- }
53
-
54
- await pipeline.exec();
55
- }
56
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2024.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import { singa } from 'singa';
9
- import { isRedisClientUsable, useRedisClient } from '../redis';
10
- import { DomainEventPublisher } from './module';
11
- import { DomainEventRedisPublisher } from './redis';
12
- import { DomainEventSocketPublisher } from './socket';
13
-
14
- const singaInstance = singa<DomainEventPublisher>({
15
- name: 'domainEventPublisher',
16
- factory: () => {
17
- const publisher = new DomainEventPublisher();
18
-
19
- if (isRedisClientUsable()) {
20
- const client = useRedisClient();
21
-
22
- publisher.addPublisher(new DomainEventRedisPublisher(client));
23
- publisher.addPublisher(new DomainEventSocketPublisher(client));
24
- }
25
-
26
- return publisher;
27
- },
28
- });
29
-
30
- export function useDomainEventPublisherSinga() {
31
- return singaInstance;
32
- }
33
-
34
- export function useDomainEventPublisher() {
35
- return singaInstance.use();
36
- }
@@ -1,68 +0,0 @@
1
- /*
2
- * Copyright (c) 2022-2024.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import { buildDomainEventFullName } from '@privateaim/kit';
9
- import { Emitter } from '@socket.io/redis-emitter';
10
- import type { Client } from 'redis-extension';
11
- import type { DomainEventPublishOptions, IDomainEventPublisher } from '../types';
12
- import { buildEventChannelName, transformEventData } from '../utils';
13
-
14
- export class DomainEventSocketPublisher implements IDomainEventPublisher {
15
- protected client : Client;
16
-
17
- constructor(client: Client) {
18
- this.client = client;
19
- }
20
-
21
- async publish(ctx: DomainEventPublishOptions) : Promise<void> {
22
- ctx.data = transformEventData(ctx.data);
23
-
24
- for (let i = 0; i < ctx.destinations.length; i++) {
25
- const destination = ctx.destinations[i];
26
-
27
- let namespace : string;
28
- if (destination.namespace) {
29
- namespace = typeof destination.namespace === 'function' ?
30
- destination.namespace(ctx.data) :
31
- destination.namespace;
32
- } else {
33
- namespace = '/';
34
- }
35
-
36
- const emitter = new Emitter(this.client, {}, namespace);
37
-
38
- const fullEventName = buildDomainEventFullName(
39
- ctx.metadata.domain,
40
- ctx.metadata.event,
41
- );
42
-
43
- const rooms : string[] = [
44
- buildEventChannelName(destination.channel),
45
- ];
46
-
47
- if (typeof destination.channel === 'function') {
48
- rooms.push(buildEventChannelName(destination.channel, ctx.data.id));
49
- }
50
-
51
- for (let j = 0; j < rooms.length; j++) {
52
- emitter
53
- .in(rooms[j])
54
- .emit(fullEventName, {
55
- data: {
56
- data: ctx.data,
57
- type: ctx.metadata.domain,
58
- event: ctx.metadata.event,
59
- },
60
- meta: {
61
- namespace,
62
- roomName: rooms[j],
63
- },
64
- });
65
- }
66
- }
67
- }
68
- }
@@ -1,50 +0,0 @@
1
- /*
2
- * Copyright (c) 2022-2024.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import type { ObjectLiteral } from '@privateaim/kit';
9
-
10
- export type DomainEventChannelName = string | ((id?: string) => string);
11
- export type DomainEventNamespaceName<
12
- T extends ObjectLiteral = ObjectLiteral,
13
- > = string | ((data: T) => string);
14
-
15
- export type DomainEventDestination<
16
- T extends ObjectLiteral = ObjectLiteral,
17
- > = {
18
- namespace?: DomainEventNamespaceName<T>,
19
- channel: DomainEventChannelName
20
- };
21
-
22
- export type DomainEventDestinations<
23
- T extends ObjectLiteral =ObjectLiteral,
24
- > = DomainEventDestination<T>[];
25
-
26
- export type DomainEventIdentity = {
27
- id?: string,
28
- name?: string,
29
- type?: string,
30
- ipAddress?: string,
31
- };
32
-
33
- export type DomainEventMetadata = {
34
- domain: string,
35
- event: string,
36
- identity?: DomainEventIdentity,
37
- };
38
-
39
- export type DomainEventPublishOptions<
40
- T extends ObjectLiteral = ObjectLiteral,
41
- > = {
42
- data: T,
43
- dataPrevious?: T,
44
- metadata: DomainEventMetadata,
45
- destinations: DomainEventDestinations<T['data']>
46
- };
47
-
48
- export interface IDomainEventPublisher {
49
- publish(ctx: DomainEventPublishOptions) : Promise<void>;
50
- }
@@ -1,25 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- export abstract class BaseLogStore {
9
- protected labels: Record<string, string>;
10
-
11
- setLabels(labels: Record<string, string>): void {
12
- this.labels = labels;
13
- }
14
-
15
- getLabels() : Record<string, string> {
16
- return this.labels;
17
- }
18
-
19
- extendLabels(labels: Record<string, string>): void {
20
- const keys = Object.keys(labels);
21
- for (let i = 0; i < keys.length; i++) {
22
- this.labels[keys[i]] = labels[keys[i]];
23
- }
24
- }
25
- }
@@ -1,9 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- export * from './loki';
9
- export * from './memory';
@@ -1,158 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import type { Log } from '@privateaim/kit';
9
- import { LogLevel } from '@privateaim/kit';
10
- import type { LokiClient, LokiDistributorPushStream, LokiQuerierQueryRangeOptions } from '../../loki';
11
- import { nanoSeconds } from '../../loki';
12
- import type {
13
- LogInput, LogStore, LogStoreDeleteOptions, LogStoreQueryOptions,
14
- } from '../types';
15
- import { BaseLogStore } from './base';
16
-
17
- export class LokiLogStore extends BaseLogStore implements LogStore {
18
- protected instance : LokiClient;
19
-
20
- constructor(instance: LokiClient, labels?: Record<string, string>) {
21
- super();
22
-
23
- this.instance = instance;
24
- this.labels = labels || {};
25
- }
26
-
27
- async write(message: string | LogInput, labels?: Record<string, string>): Promise<Log> {
28
- let data : Log;
29
-
30
- if (typeof message === 'string') {
31
- const labelsNormalized = {
32
- ...this.labels,
33
- ...(labels || {}),
34
- };
35
- const level = (labelsNormalized.level || LogLevel.DEBUG) as LogLevel;
36
- delete labelsNormalized.level;
37
-
38
- data = {
39
- message,
40
- level,
41
- time: nanoSeconds(),
42
- labels: labelsNormalized,
43
- };
44
- } else {
45
- const labelsNormalized = {
46
- ...this.labels,
47
- ...(message.labels || {}),
48
- ...(labels || {}),
49
- };
50
-
51
- const level = (message.level || labelsNormalized.level || LogLevel.DEBUG) as LogLevel;
52
- delete labelsNormalized.level;
53
-
54
- data = {
55
- ...message,
56
- level,
57
- time: message.time || nanoSeconds(),
58
- labels: labelsNormalized,
59
- };
60
- }
61
-
62
- const stream : LokiDistributorPushStream = {
63
- stream: data.labels,
64
- values: [
65
- [data.time, data.message, { level: data.level }],
66
- ],
67
- };
68
-
69
- await this.instance.distributor.push(stream);
70
-
71
- return data;
72
- }
73
-
74
- async delete(options: LogStoreDeleteOptions): Promise<void> {
75
- await this.instance.compactor.createDeletionRequest({
76
- start: options.start,
77
- ...(options.end ? { end: options.end } : {}),
78
- query: this.buildQuery({
79
- ...this.labels,
80
- ...(options.labels || {}),
81
- }),
82
- });
83
- }
84
-
85
- async query(input: LogStoreQueryOptions): Promise<[Log[], number]> {
86
- const options : LokiQuerierQueryRangeOptions = {
87
- query: this.buildQuery({
88
- ...this.labels,
89
- ...(input.labels || {}),
90
- }),
91
- };
92
-
93
- if (input.sort) {
94
- options.direction = input.sort === 'DESC' ? 'forward' : 'backward';
95
- }
96
-
97
- if (input.limit) {
98
- options.limit = input.limit;
99
- }
100
-
101
- if (input.start) {
102
- options.start = BigInt(new Date(`${input.start}`).getTime()) * 1_000_000n;
103
- }
104
-
105
- if (input.end) {
106
- options.end = BigInt(new Date(`${input.end}`).getTime()) * 1_000_000n;
107
- }
108
-
109
- const output : Log[] = [];
110
-
111
- const response = await this.instance.querier.queryRange(options);
112
- if (response.data.resultType === 'streams') {
113
- for (let i = 0; i < response.data.result.length; i++) {
114
- const set = response.data.result[i];
115
-
116
- const labels = set.stream;
117
- let level : LogLevel;
118
-
119
- if (labels.level) {
120
- level = labels.level as LogLevel;
121
- } else {
122
- level = labels.detected_level as LogLevel;
123
- }
124
- delete labels.level;
125
- delete labels.detected_level;
126
-
127
- if (!labels.service) {
128
- labels.service = labels.service_name;
129
- }
130
- delete labels.service_name;
131
-
132
- for (let j = 0; j < set.values.length; j++) {
133
- output.push({
134
- time: BigInt(set.values[j][0]),
135
- message: set.values[j][1],
136
- level,
137
- labels,
138
- } satisfies Log);
139
- }
140
- }
141
- }
142
-
143
- return [output, output.length];
144
- }
145
-
146
- // ----------------------------------------------
147
-
148
- protected buildQuery(labels: Record<string, any>) : string {
149
- const output : string[] = [];
150
-
151
- const keys = Object.keys(labels);
152
- for (let i = 0; i < keys.length; i++) {
153
- output.push(`${keys[i]}="${labels[keys[i]]}"`);
154
- }
155
-
156
- return `{${output.join(',')}}`;
157
- }
158
- }