@privateaim/server-kit 0.8.13 → 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.
- package/CHANGELOG.md +37 -0
- package/dist/index.cjs +494 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +452 -65
- package/dist/index.mjs.map +1 -1
- package/dist/services/domain-event/index.d.ts +1 -1
- package/dist/services/domain-event/index.d.ts.map +1 -1
- package/dist/services/domain-event/module.d.ts +4 -4
- package/dist/services/domain-event/module.d.ts.map +1 -1
- package/dist/services/domain-event/redis/module.d.ts +2 -2
- package/dist/services/domain-event/redis/module.d.ts.map +1 -1
- package/dist/services/domain-event/singleton.d.ts +1 -0
- package/dist/services/domain-event/singleton.d.ts.map +1 -1
- package/dist/services/domain-event/socket/module.d.ts +2 -2
- package/dist/services/domain-event/socket/module.d.ts.map +1 -1
- package/dist/services/domain-event/types.d.ts +29 -0
- package/dist/services/domain-event/types.d.ts.map +1 -0
- package/dist/services/domain-event/utils.d.ts +2 -2
- package/dist/services/domain-event/utils.d.ts.map +1 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/log-store/entities/base.d.ts +7 -0
- package/dist/services/log-store/entities/base.d.ts.map +1 -0
- package/dist/services/log-store/entities/index.d.ts +3 -0
- package/dist/services/log-store/entities/index.d.ts.map +1 -0
- package/dist/services/log-store/entities/loki.d.ts +13 -0
- package/dist/services/log-store/entities/loki.d.ts.map +1 -0
- package/dist/services/log-store/entities/memory.d.ts +11 -0
- package/dist/services/log-store/entities/memory.d.ts.map +1 -0
- package/dist/services/log-store/index.d.ts +4 -0
- package/dist/services/log-store/index.d.ts.map +1 -0
- package/dist/services/log-store/singleton.d.ts +6 -0
- package/dist/services/log-store/singleton.d.ts.map +1 -0
- package/dist/services/log-store/types.d.ts +27 -0
- package/dist/services/log-store/types.d.ts.map +1 -0
- package/dist/services/logger/module.d.ts.map +1 -1
- package/dist/services/logger/store.d.ts +14 -0
- package/dist/services/logger/store.d.ts.map +1 -0
- package/dist/services/logger/types.d.ts +3 -0
- package/dist/services/logger/types.d.ts.map +1 -1
- package/dist/services/loki/index.d.ts +3 -0
- package/dist/services/loki/index.d.ts.map +1 -0
- package/dist/services/loki/module.d.ts +3 -0
- package/dist/services/loki/module.d.ts.map +1 -0
- package/dist/services/loki/singleton.d.ts +6 -0
- package/dist/services/loki/singleton.d.ts.map +1 -0
- package/package.json +12 -9
- package/src/services/domain-event/index.ts +1 -1
- package/src/services/domain-event/module.ts +8 -8
- package/src/services/domain-event/redis/module.ts +28 -9
- package/src/services/domain-event/singleton.ts +6 -2
- package/src/services/domain-event/socket/module.ts +20 -9
- package/src/services/domain-event/types.ts +50 -0
- package/src/services/domain-event/utils.ts +2 -2
- package/src/services/index.ts +2 -0
- package/src/services/log-store/entities/base.ts +25 -0
- package/src/services/log-store/entities/index.ts +9 -0
- package/src/services/log-store/entities/loki.ts +158 -0
- package/src/services/log-store/entities/memory.ts +100 -0
- package/src/services/log-store/index.ts +10 -0
- package/src/services/log-store/singleton.ts +36 -0
- package/src/services/log-store/types.ts +42 -0
- package/src/services/logger/module.ts +20 -5
- package/src/services/logger/store.ts +70 -0
- package/src/services/logger/types.ts +4 -1
- package/src/services/loki/index.ts +9 -0
- package/src/services/loki/module.ts +30 -0
- package/src/services/loki/singleton.ts +26 -0
- package/test/unit/log-store.spec.ts +21 -0
- package/test/unit/logger.spec.ts +36 -0
- package/dist/services/domain-event/type.d.ts +0 -15
- package/dist/services/domain-event/type.d.ts.map +0 -1
- package/src/services/domain-event/type.ts +0 -27
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,8 @@ 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 WinstonTransport = require('winston-transport');
|
|
15
|
+
var loki = require('@hapic/loki');
|
|
14
16
|
var redisEmitter = require('@socket.io/redis-emitter');
|
|
15
17
|
|
|
16
18
|
/*
|
|
@@ -18,7 +20,7 @@ var redisEmitter = require('@socket.io/redis-emitter');
|
|
|
18
20
|
* Author Peter Placzek (tada5hi)
|
|
19
21
|
* For the full copyright and license information,
|
|
20
22
|
* view the LICENSE file that was distributed with this source code.
|
|
21
|
-
*/ function _define_property$
|
|
23
|
+
*/ function _define_property$b(obj, key, value) {
|
|
22
24
|
if (key in obj) {
|
|
23
25
|
Object.defineProperty(obj, key, {
|
|
24
26
|
value: value,
|
|
@@ -35,7 +37,7 @@ class ComponentError extends Error {
|
|
|
35
37
|
constructor(input){
|
|
36
38
|
super(input.message, {
|
|
37
39
|
cause: input.cause
|
|
38
|
-
}), _define_property$
|
|
40
|
+
}), _define_property$b(this, "code", void 0);
|
|
39
41
|
this.code = input.code;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
@@ -83,30 +85,30 @@ function isQueueRouterPayload(input) {
|
|
|
83
85
|
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);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
const instance$
|
|
88
|
+
const instance$b = singa.singa({
|
|
87
89
|
name: 'amqp'
|
|
88
90
|
});
|
|
89
91
|
function setAmqpClientFactory(factory) {
|
|
90
|
-
instance$
|
|
92
|
+
instance$b.setFactory(factory);
|
|
91
93
|
}
|
|
92
94
|
function isAmqpClientUsable() {
|
|
93
|
-
return instance$
|
|
95
|
+
return instance$b.has() || instance$b.hasFactory();
|
|
94
96
|
}
|
|
95
97
|
function useAmqpClient() {
|
|
96
|
-
return instance$
|
|
98
|
+
return instance$b.use();
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
const instance$
|
|
101
|
+
const instance$a = singa.singa({
|
|
100
102
|
name: 'vault'
|
|
101
103
|
});
|
|
102
104
|
function setVaultFactory(factory) {
|
|
103
|
-
instance$
|
|
105
|
+
instance$a.setFactory(factory);
|
|
104
106
|
}
|
|
105
107
|
function isVaultClientUsable() {
|
|
106
|
-
return instance$
|
|
108
|
+
return instance$a.has() || instance$a.hasFactory();
|
|
107
109
|
}
|
|
108
110
|
function useVaultClient() {
|
|
109
|
-
return instance$
|
|
111
|
+
return instance$a.use();
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
function guessAuthupTokenCreatorOptions() {
|
|
@@ -127,17 +129,17 @@ function guessAuthupTokenCreatorOptions() {
|
|
|
127
129
|
return options;
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
const instance$
|
|
132
|
+
const instance$9 = singa.singa({
|
|
131
133
|
name: 'clientAuthenticationHook'
|
|
132
134
|
});
|
|
133
135
|
function setClientAuthenticationHookFactory(factory) {
|
|
134
|
-
instance$
|
|
136
|
+
instance$9.setFactory(factory);
|
|
135
137
|
}
|
|
136
138
|
function isClientAuthenticationHookUsable() {
|
|
137
|
-
return instance$
|
|
139
|
+
return instance$9.has() || instance$9.hasFactory();
|
|
138
140
|
}
|
|
139
141
|
function useClientAuthenticationHook() {
|
|
140
|
-
return instance$
|
|
142
|
+
return instance$9.use();
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
class AuthupClient extends coreHttpKit.Client {
|
|
@@ -154,49 +156,49 @@ class AuthupClient extends coreHttpKit.Client {
|
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
const instance$
|
|
159
|
+
const instance$8 = singa.singa({
|
|
158
160
|
name: 'authup'
|
|
159
161
|
});
|
|
160
162
|
function useAuthupClient() {
|
|
161
|
-
return instance$
|
|
163
|
+
return instance$8.use();
|
|
162
164
|
}
|
|
163
165
|
function isAuthupClientUsable() {
|
|
164
|
-
return instance$
|
|
166
|
+
return instance$8.has() || instance$8.hasFactory();
|
|
165
167
|
}
|
|
166
168
|
function setAuthupClientFactory(factory) {
|
|
167
|
-
instance$
|
|
169
|
+
instance$8.setFactory(factory);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
const instance$
|
|
172
|
+
const instance$7 = singa.singa({
|
|
171
173
|
name: 'redis'
|
|
172
174
|
});
|
|
173
175
|
function setRedisFactory(factory) {
|
|
174
|
-
instance$
|
|
176
|
+
instance$7.setFactory(factory);
|
|
175
177
|
}
|
|
176
178
|
function isRedisClientUsable() {
|
|
177
|
-
return instance$
|
|
179
|
+
return instance$7.has() || instance$7.hasFactory();
|
|
178
180
|
}
|
|
179
181
|
function setRedisClient(input) {
|
|
180
|
-
instance$
|
|
182
|
+
instance$7.set(input);
|
|
181
183
|
}
|
|
182
184
|
function useRedisClient() {
|
|
183
|
-
return instance$
|
|
185
|
+
return instance$7.use();
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
const instance$
|
|
188
|
+
const instance$6 = singa.singa({
|
|
187
189
|
name: 'redisPublish',
|
|
188
190
|
factory: ()=>useRedisClient().duplicate()
|
|
189
191
|
});
|
|
190
192
|
function useRedisPublishClient() {
|
|
191
|
-
return instance$
|
|
193
|
+
return instance$6.use();
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
const instance$
|
|
196
|
+
const instance$5 = singa.singa({
|
|
195
197
|
name: 'redisSubscribe',
|
|
196
198
|
factory: ()=>useRedisClient().duplicate()
|
|
197
199
|
});
|
|
198
200
|
function useRedisSubscribeClient() {
|
|
199
|
-
return instance$
|
|
201
|
+
return instance$5.use();
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
/*
|
|
@@ -204,7 +206,7 @@ function useRedisSubscribeClient() {
|
|
|
204
206
|
* Author Peter Placzek (tada5hi)
|
|
205
207
|
* For the full copyright and license information,
|
|
206
208
|
* view the LICENSE file that was distributed with this source code.
|
|
207
|
-
*/ function _define_property$
|
|
209
|
+
*/ function _define_property$a(obj, key, value) {
|
|
208
210
|
if (key in obj) {
|
|
209
211
|
Object.defineProperty(obj, key, {
|
|
210
212
|
value: value,
|
|
@@ -252,7 +254,7 @@ class MemoryCacheAdapter {
|
|
|
252
254
|
this.instance.clear();
|
|
253
255
|
}
|
|
254
256
|
constructor(options = {}){
|
|
255
|
-
_define_property$
|
|
257
|
+
_define_property$a(this, "instance", void 0);
|
|
256
258
|
this.instance = new TTLCache({
|
|
257
259
|
checkAgeOnGet: true,
|
|
258
260
|
ttl: Infinity,
|
|
@@ -266,7 +268,7 @@ class MemoryCacheAdapter {
|
|
|
266
268
|
* Author Peter Placzek (tada5hi)
|
|
267
269
|
* For the full copyright and license information,
|
|
268
270
|
* view the LICENSE file that was distributed with this source code.
|
|
269
|
-
*/ function _define_property$
|
|
271
|
+
*/ function _define_property$9(obj, key, value) {
|
|
270
272
|
if (key in obj) {
|
|
271
273
|
Object.defineProperty(obj, key, {
|
|
272
274
|
value: value,
|
|
@@ -315,8 +317,8 @@ class RedisCacheAdapter {
|
|
|
315
317
|
await this.client.flushdb();
|
|
316
318
|
}
|
|
317
319
|
constructor(){
|
|
318
|
-
_define_property$
|
|
319
|
-
_define_property$
|
|
320
|
+
_define_property$9(this, "client", void 0);
|
|
321
|
+
_define_property$9(this, "instance", void 0);
|
|
320
322
|
this.client = useRedisClient();
|
|
321
323
|
this.instance = new redisExtension.JsonAdapter(this.client);
|
|
322
324
|
}
|
|
@@ -338,7 +340,7 @@ function buildCacheKey(options) {
|
|
|
338
340
|
* Author Peter Placzek (tada5hi)
|
|
339
341
|
* For the full copyright and license information,
|
|
340
342
|
* view the LICENSE file that was distributed with this source code.
|
|
341
|
-
*/ function _define_property$
|
|
343
|
+
*/ function _define_property$8(obj, key, value) {
|
|
342
344
|
if (key in obj) {
|
|
343
345
|
Object.defineProperty(obj, key, {
|
|
344
346
|
value: value,
|
|
@@ -371,12 +373,12 @@ class Cache {
|
|
|
371
373
|
return this.adapter.clear(options);
|
|
372
374
|
}
|
|
373
375
|
constructor(adapter){
|
|
374
|
-
_define_property$
|
|
376
|
+
_define_property$8(this, "adapter", void 0);
|
|
375
377
|
this.adapter = adapter;
|
|
376
378
|
}
|
|
377
379
|
}
|
|
378
380
|
|
|
379
|
-
const instance$
|
|
381
|
+
const instance$4 = singa.singa({
|
|
380
382
|
name: 'cache',
|
|
381
383
|
factory: ()=>{
|
|
382
384
|
let adapter;
|
|
@@ -389,11 +391,365 @@ const instance$3 = singa.singa({
|
|
|
389
391
|
}
|
|
390
392
|
});
|
|
391
393
|
function useCache() {
|
|
394
|
+
return instance$4.use();
|
|
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() {
|
|
392
461
|
return instance$3.use();
|
|
393
462
|
}
|
|
394
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
|
+
|
|
395
751
|
function createLogger(ctx = {}) {
|
|
396
|
-
const
|
|
752
|
+
const store = ctx.store || useLogStore();
|
|
397
753
|
let loggerTransports;
|
|
398
754
|
if (envix.read('env') === typeormExtension.EnvironmentName.PRODUCTION) {
|
|
399
755
|
loggerTransports = [
|
|
@@ -401,50 +757,58 @@ function createLogger(ctx = {}) {
|
|
|
401
757
|
level: 'info'
|
|
402
758
|
}),
|
|
403
759
|
new winston.transports.File({
|
|
404
|
-
filename: path.join(directory || process.cwd(), 'access.log'),
|
|
760
|
+
filename: path.join(ctx.directory || process.cwd(), 'access.log'),
|
|
405
761
|
level: 'http',
|
|
406
762
|
maxsize: 10 * 1024 * 1024,
|
|
407
763
|
maxFiles: 5
|
|
408
764
|
}),
|
|
409
765
|
new winston.transports.File({
|
|
410
|
-
filename: path.join(directory || process.cwd(), 'error.log'),
|
|
766
|
+
filename: path.join(ctx.directory || process.cwd(), 'error.log'),
|
|
411
767
|
level: 'warn',
|
|
412
768
|
maxsize: 10 * 1024 * 1024,
|
|
413
769
|
maxFiles: 5
|
|
770
|
+
}),
|
|
771
|
+
new LogStoreTransport(store, {
|
|
772
|
+
level: 'http',
|
|
773
|
+
labels: ctx.labels
|
|
414
774
|
})
|
|
415
775
|
];
|
|
416
776
|
} else {
|
|
417
777
|
loggerTransports = [
|
|
418
778
|
new winston.transports.Console({
|
|
419
779
|
level: 'debug'
|
|
780
|
+
}),
|
|
781
|
+
new LogStoreTransport(store, {
|
|
782
|
+
level: 'http',
|
|
783
|
+
labels: ctx.labels
|
|
420
784
|
})
|
|
421
785
|
];
|
|
422
786
|
}
|
|
423
787
|
return winston.createLogger({
|
|
424
788
|
format: winston.format.combine(winston.format.errors({
|
|
425
789
|
stack: true
|
|
426
|
-
}), winston.format.timestamp(), winston.format.
|
|
790
|
+
}), winston.format.timestamp(), winston.format.simple()),
|
|
427
791
|
level: 'debug',
|
|
428
792
|
transports: loggerTransports,
|
|
429
793
|
// todo: deeply merge options
|
|
430
|
-
...options || {}
|
|
794
|
+
...ctx.options || {}
|
|
431
795
|
});
|
|
432
796
|
}
|
|
433
797
|
|
|
434
|
-
const instance$
|
|
798
|
+
const instance$1 = singa.singa({
|
|
435
799
|
name: 'logger'
|
|
436
800
|
});
|
|
437
801
|
function setLoggerFactory(factory) {
|
|
438
|
-
instance$
|
|
802
|
+
instance$1.setFactory(factory);
|
|
439
803
|
}
|
|
440
804
|
function isLoggerUsable() {
|
|
441
|
-
return instance$
|
|
805
|
+
return instance$1.has() || instance$1.hasFactory();
|
|
442
806
|
}
|
|
443
807
|
function setLogger(input) {
|
|
444
|
-
instance$
|
|
808
|
+
instance$1.set(input);
|
|
445
809
|
}
|
|
446
810
|
function useLogger() {
|
|
447
|
-
return instance$
|
|
811
|
+
return instance$1.use();
|
|
448
812
|
}
|
|
449
813
|
|
|
450
814
|
/*
|
|
@@ -474,14 +838,14 @@ class DomainEventPublisher {
|
|
|
474
838
|
await this.publish(ctx);
|
|
475
839
|
} catch (e) {
|
|
476
840
|
if (isLoggerUsable()) {
|
|
477
|
-
useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.
|
|
841
|
+
useLogger().error(`Publishing event ${kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)} failed`);
|
|
478
842
|
useLogger().error(e);
|
|
479
843
|
}
|
|
480
844
|
}
|
|
481
845
|
}
|
|
482
846
|
async publish(ctx) {
|
|
483
847
|
if (isLoggerUsable()) {
|
|
484
|
-
useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.
|
|
848
|
+
useLogger().info(`Publishing event ${kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event)}`);
|
|
485
849
|
}
|
|
486
850
|
const publishers = this.publishers.values();
|
|
487
851
|
while(true){
|
|
@@ -537,15 +901,29 @@ function buildEventChannelName(input, id) {
|
|
|
537
901
|
}
|
|
538
902
|
class DomainEventRedisPublisher {
|
|
539
903
|
async publish(ctx) {
|
|
540
|
-
const
|
|
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);
|
|
541
910
|
const pipeline = this.driver.pipeline();
|
|
542
911
|
for(let i = 0; i < ctx.destinations.length; i++){
|
|
543
|
-
const
|
|
544
|
-
let
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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);
|
|
549
927
|
}
|
|
550
928
|
}
|
|
551
929
|
await pipeline.exec();
|
|
@@ -578,23 +956,28 @@ class DomainEventSocketPublisher {
|
|
|
578
956
|
async publish(ctx) {
|
|
579
957
|
ctx.data = transformEventData(ctx.data);
|
|
580
958
|
for(let i = 0; i < ctx.destinations.length; i++){
|
|
959
|
+
const destination = ctx.destinations[i];
|
|
581
960
|
let namespace;
|
|
582
|
-
if (
|
|
583
|
-
namespace = ctx.
|
|
961
|
+
if (destination.namespace) {
|
|
962
|
+
namespace = typeof destination.namespace === 'function' ? destination.namespace(ctx.data) : destination.namespace;
|
|
584
963
|
} else {
|
|
585
964
|
namespace = '/';
|
|
586
965
|
}
|
|
587
966
|
const emitter = new redisEmitter.Emitter(this.client, {}, namespace);
|
|
588
|
-
const fullEventName = kit.buildDomainEventFullName(ctx.
|
|
967
|
+
const fullEventName = kit.buildDomainEventFullName(ctx.metadata.domain, ctx.metadata.event);
|
|
589
968
|
const rooms = [
|
|
590
|
-
buildEventChannelName(
|
|
969
|
+
buildEventChannelName(destination.channel)
|
|
591
970
|
];
|
|
592
|
-
if (typeof
|
|
593
|
-
rooms.push(buildEventChannelName(
|
|
971
|
+
if (typeof destination.channel === 'function') {
|
|
972
|
+
rooms.push(buildEventChannelName(destination.channel, ctx.data.id));
|
|
594
973
|
}
|
|
595
974
|
for(let j = 0; j < rooms.length; j++){
|
|
596
975
|
emitter.in(rooms[j]).emit(fullEventName, {
|
|
597
|
-
|
|
976
|
+
data: {
|
|
977
|
+
data: ctx.data,
|
|
978
|
+
type: ctx.metadata.domain,
|
|
979
|
+
event: ctx.metadata.event
|
|
980
|
+
},
|
|
598
981
|
meta: {
|
|
599
982
|
namespace,
|
|
600
983
|
roomName: rooms[j]
|
|
@@ -609,7 +992,7 @@ class DomainEventSocketPublisher {
|
|
|
609
992
|
}
|
|
610
993
|
}
|
|
611
994
|
|
|
612
|
-
const
|
|
995
|
+
const singaInstance = singa.singa({
|
|
613
996
|
name: 'domainEventPublisher',
|
|
614
997
|
factory: ()=>{
|
|
615
998
|
const publisher = new DomainEventPublisher();
|
|
@@ -621,8 +1004,11 @@ const instance$1 = singa.singa({
|
|
|
621
1004
|
return publisher;
|
|
622
1005
|
}
|
|
623
1006
|
});
|
|
1007
|
+
function useDomainEventPublisherSinga() {
|
|
1008
|
+
return singaInstance;
|
|
1009
|
+
}
|
|
624
1010
|
function useDomainEventPublisher() {
|
|
625
|
-
return
|
|
1011
|
+
return singaInstance.use();
|
|
626
1012
|
}
|
|
627
1013
|
|
|
628
1014
|
/*
|
|
@@ -769,13 +1155,51 @@ Object.defineProperty(exports, "createRedisClient", {
|
|
|
769
1155
|
enumerable: true,
|
|
770
1156
|
get: function () { return redisExtension.createClient; }
|
|
771
1157
|
});
|
|
1158
|
+
Object.defineProperty(exports, "LokiClient", {
|
|
1159
|
+
enumerable: true,
|
|
1160
|
+
get: function () { return loki.LokiClient; }
|
|
1161
|
+
});
|
|
1162
|
+
Object.defineProperty(exports, "LokiCompactorDeletionRequestCreate", {
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
get: function () { return loki.CompactorDeletionRequestCreate; }
|
|
1165
|
+
});
|
|
1166
|
+
Object.defineProperty(exports, "LokiConfig", {
|
|
1167
|
+
enumerable: true,
|
|
1168
|
+
get: function () { return loki.Config; }
|
|
1169
|
+
});
|
|
1170
|
+
Object.defineProperty(exports, "LokiConfigInput", {
|
|
1171
|
+
enumerable: true,
|
|
1172
|
+
get: function () { return loki.ConfigInput; }
|
|
1173
|
+
});
|
|
1174
|
+
Object.defineProperty(exports, "LokiDistributorPushStream", {
|
|
1175
|
+
enumerable: true,
|
|
1176
|
+
get: function () { return loki.DistributorPushStream; }
|
|
1177
|
+
});
|
|
1178
|
+
Object.defineProperty(exports, "LokiQuerierQueryRangeOptions", {
|
|
1179
|
+
enumerable: true,
|
|
1180
|
+
get: function () { return loki.QuerierQueryRangeOptions; }
|
|
1181
|
+
});
|
|
1182
|
+
Object.defineProperty(exports, "LokiQuerierQueryResult", {
|
|
1183
|
+
enumerable: true,
|
|
1184
|
+
get: function () { return loki.QuerierQueryResult; }
|
|
1185
|
+
});
|
|
1186
|
+
Object.defineProperty(exports, "createLokiClient", {
|
|
1187
|
+
enumerable: true,
|
|
1188
|
+
get: function () { return loki.createClient; }
|
|
1189
|
+
});
|
|
1190
|
+
Object.defineProperty(exports, "nanoSeconds", {
|
|
1191
|
+
enumerable: true,
|
|
1192
|
+
get: function () { return loki.nanoSeconds; }
|
|
1193
|
+
});
|
|
772
1194
|
exports.AuthupClient = AuthupClient;
|
|
773
1195
|
exports.Cache = Cache;
|
|
774
1196
|
exports.ComponentError = ComponentError;
|
|
775
1197
|
exports.DomainEventPublisher = DomainEventPublisher;
|
|
776
1198
|
exports.DomainEventRedisPublisher = DomainEventRedisPublisher;
|
|
777
1199
|
exports.DomainEventSocketPublisher = DomainEventSocketPublisher;
|
|
1200
|
+
exports.LokiLogStore = LokiLogStore;
|
|
778
1201
|
exports.MemoryCacheAdapter = MemoryCacheAdapter;
|
|
1202
|
+
exports.MemoryLogStore = MemoryLogStore;
|
|
779
1203
|
exports.QueueRouter = QueueRouter;
|
|
780
1204
|
exports.QueueRouterRoutingType = QueueRouterRoutingType;
|
|
781
1205
|
exports.RedisCacheAdapter = RedisCacheAdapter;
|
|
@@ -789,7 +1213,9 @@ exports.isAmqpClientUsable = isAmqpClientUsable;
|
|
|
789
1213
|
exports.isAuthupClientUsable = isAuthupClientUsable;
|
|
790
1214
|
exports.isClientAuthenticationHookUsable = isClientAuthenticationHookUsable;
|
|
791
1215
|
exports.isComponentError = isComponentError;
|
|
1216
|
+
exports.isLogStoreUsable = isLogStoreUsable;
|
|
792
1217
|
exports.isLoggerUsable = isLoggerUsable;
|
|
1218
|
+
exports.isLokiClientUsable = isLokiClientUsable;
|
|
793
1219
|
exports.isQueuePayload = isQueuePayload;
|
|
794
1220
|
exports.isQueueRouterPayload = isQueueRouterPayload;
|
|
795
1221
|
exports.isQueueRouterUsable = isQueueRouterUsable;
|
|
@@ -798,8 +1224,10 @@ exports.isVaultClientUsable = isVaultClientUsable;
|
|
|
798
1224
|
exports.setAmqpClientFactory = setAmqpClientFactory;
|
|
799
1225
|
exports.setAuthupClientFactory = setAuthupClientFactory;
|
|
800
1226
|
exports.setClientAuthenticationHookFactory = setClientAuthenticationHookFactory;
|
|
1227
|
+
exports.setLogStoreFactory = setLogStoreFactory;
|
|
801
1228
|
exports.setLogger = setLogger;
|
|
802
1229
|
exports.setLoggerFactory = setLoggerFactory;
|
|
1230
|
+
exports.setLokiFactory = setLokiFactory;
|
|
803
1231
|
exports.setRedisClient = setRedisClient;
|
|
804
1232
|
exports.setRedisFactory = setRedisFactory;
|
|
805
1233
|
exports.setVaultFactory = setVaultFactory;
|
|
@@ -808,7 +1236,10 @@ exports.useAuthupClient = useAuthupClient;
|
|
|
808
1236
|
exports.useCache = useCache;
|
|
809
1237
|
exports.useClientAuthenticationHook = useClientAuthenticationHook;
|
|
810
1238
|
exports.useDomainEventPublisher = useDomainEventPublisher;
|
|
1239
|
+
exports.useDomainEventPublisherSinga = useDomainEventPublisherSinga;
|
|
1240
|
+
exports.useLogStore = useLogStore;
|
|
811
1241
|
exports.useLogger = useLogger;
|
|
1242
|
+
exports.useLokiClient = useLokiClient;
|
|
812
1243
|
exports.useQueueRouter = useQueueRouter;
|
|
813
1244
|
exports.useRedisClient = useRedisClient;
|
|
814
1245
|
exports.useRedisPublishClient = useRedisPublishClient;
|