@privateaim/server-kit 0.8.15 → 0.8.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/core/component/handler/check.d.ts +4 -0
- package/dist/core/component/handler/check.d.ts.map +1 -0
- package/dist/core/component/handler/index.d.ts +3 -0
- package/dist/core/component/handler/index.d.ts.map +1 -0
- package/dist/core/component/handler/module.d.ts +11 -0
- package/dist/core/component/handler/module.d.ts.map +1 -0
- package/dist/core/component/handler/types.d.ts +11 -0
- package/dist/core/component/handler/types.d.ts.map +1 -0
- package/dist/core/component/index.d.ts +1 -0
- package/dist/core/component/index.d.ts.map +1 -1
- package/dist/core/queue-router/module.d.ts +3 -2
- package/dist/core/queue-router/module.d.ts.map +1 -1
- package/dist/core/queue-router/types.d.ts +7 -4
- package/dist/core/queue-router/types.d.ts.map +1 -1
- package/dist/index.cjs +214 -526
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +208 -484
- package/dist/index.mjs.map +1 -1
- package/dist/services/amqp/index.d.ts +1 -0
- package/dist/services/amqp/index.d.ts.map +1 -1
- package/dist/services/amqp/module.d.ts +2 -5
- package/dist/services/amqp/module.d.ts.map +1 -1
- package/dist/services/amqp/singleton.d.ts +6 -0
- package/dist/services/amqp/singleton.d.ts.map +1 -0
- package/dist/services/domain-event/module.d.ts +3 -3
- package/dist/services/domain-event/module.d.ts.map +1 -1
- package/dist/services/domain-event/redis/helpers.d.ts +2 -0
- package/dist/services/domain-event/redis/helpers.d.ts.map +1 -0
- package/dist/services/domain-event/redis/index.d.ts +1 -0
- package/dist/services/domain-event/redis/index.d.ts.map +1 -1
- package/dist/services/domain-event/redis/module.d.ts +3 -3
- package/dist/services/domain-event/redis/module.d.ts.map +1 -1
- package/dist/services/domain-event/socket/helpers.d.ts +3 -0
- package/dist/services/domain-event/socket/helpers.d.ts.map +1 -0
- package/dist/services/domain-event/socket/index.d.ts +1 -0
- package/dist/services/domain-event/socket/index.d.ts.map +1 -1
- package/dist/services/domain-event/socket/module.d.ts +3 -3
- package/dist/services/domain-event/socket/module.d.ts.map +1 -1
- package/dist/services/domain-event/types.d.ts +22 -14
- package/dist/services/domain-event/types.d.ts.map +1 -1
- package/dist/services/domain-event/utils.d.ts +0 -2
- package/dist/services/domain-event/utils.d.ts.map +1 -1
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/logger/module.d.ts.map +1 -1
- package/dist/services/logger/types.d.ts +2 -5
- package/dist/services/logger/types.d.ts.map +1 -1
- package/package.json +3 -5
- package/src/core/component/handler/check.ts +23 -0
- package/src/{services/loki → core/component/handler}/index.ts +2 -2
- package/src/core/component/handler/module.ts +57 -0
- package/src/core/component/handler/types.ts +28 -0
- package/src/core/component/index.ts +1 -0
- package/src/core/queue-router/module.ts +30 -4
- package/src/core/queue-router/types.ts +12 -5
- package/src/services/amqp/index.ts +1 -0
- package/src/services/amqp/module.ts +5 -19
- package/src/services/{loki → amqp}/singleton.ts +6 -6
- package/src/services/domain-event/module.ts +25 -8
- package/src/services/domain-event/redis/helpers.ts +28 -0
- package/src/services/domain-event/redis/index.ts +1 -0
- package/src/services/domain-event/redis/module.ts +10 -22
- package/src/services/domain-event/singleton.ts +3 -3
- package/src/services/domain-event/socket/helpers.ts +26 -0
- package/src/services/domain-event/socket/index.ts +1 -0
- package/src/services/domain-event/socket/module.ts +21 -36
- package/src/services/domain-event/types.ts +30 -21
- package/src/services/domain-event/utils.ts +0 -12
- package/src/services/index.ts +0 -2
- package/src/services/logger/module.ts +6 -31
- package/src/services/logger/types.ts +3 -6
- package/dist/services/log-store/entities/base.d.ts +0 -7
- package/dist/services/log-store/entities/base.d.ts.map +0 -1
- package/dist/services/log-store/entities/index.d.ts +0 -3
- package/dist/services/log-store/entities/index.d.ts.map +0 -1
- package/dist/services/log-store/entities/loki.d.ts +0 -13
- package/dist/services/log-store/entities/loki.d.ts.map +0 -1
- package/dist/services/log-store/entities/memory.d.ts +0 -11
- package/dist/services/log-store/entities/memory.d.ts.map +0 -1
- package/dist/services/log-store/index.d.ts +0 -4
- package/dist/services/log-store/index.d.ts.map +0 -1
- package/dist/services/log-store/singleton.d.ts +0 -6
- package/dist/services/log-store/singleton.d.ts.map +0 -1
- package/dist/services/log-store/types.d.ts +0 -27
- package/dist/services/log-store/types.d.ts.map +0 -1
- package/dist/services/logger/store.d.ts +0 -14
- package/dist/services/logger/store.d.ts.map +0 -1
- package/dist/services/loki/index.d.ts +0 -3
- package/dist/services/loki/index.d.ts.map +0 -1
- package/dist/services/loki/module.d.ts +0 -3
- package/dist/services/loki/module.d.ts.map +0 -1
- package/dist/services/loki/singleton.d.ts +0 -6
- package/dist/services/loki/singleton.d.ts.map +0 -1
- package/src/services/log-store/entities/base.ts +0 -25
- package/src/services/log-store/entities/index.ts +0 -9
- package/src/services/log-store/entities/loki.ts +0 -158
- package/src/services/log-store/entities/memory.ts +0 -100
- package/src/services/log-store/index.ts +0 -10
- package/src/services/log-store/singleton.ts +0 -36
- package/src/services/log-store/types.ts +0 -42
- package/src/services/logger/store.ts +0 -70
- package/src/services/loki/module.ts +0 -30
- package/test/unit/log-store.spec.ts +0 -21
- package/test/unit/logger.spec.ts +0 -36
|
@@ -7,33 +7,29 @@
|
|
|
7
7
|
|
|
8
8
|
import type { ObjectLiteral } from '@privateaim/kit';
|
|
9
9
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
> = string | ((data: T) => string);
|
|
14
|
-
|
|
15
|
-
export type DomainEventDestination<
|
|
16
|
-
T extends ObjectLiteral = ObjectLiteral,
|
|
17
|
-
> = {
|
|
18
|
-
namespace?: DomainEventNamespaceName<T>,
|
|
19
|
-
channel: DomainEventChannelName
|
|
10
|
+
export type DomainEventDestination = {
|
|
11
|
+
namespace?: string | string[],
|
|
12
|
+
channel: string | string[]
|
|
20
13
|
};
|
|
21
14
|
|
|
22
|
-
export type DomainEventDestinations
|
|
23
|
-
T extends ObjectLiteral =ObjectLiteral,
|
|
24
|
-
> = DomainEventDestination<T>[];
|
|
15
|
+
export type DomainEventDestinations = DomainEventDestination[];
|
|
25
16
|
|
|
26
|
-
export type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type?: string,
|
|
30
|
-
ipAddress?: string,
|
|
31
|
-
};
|
|
17
|
+
export type DomainEventDestinationsFn<
|
|
18
|
+
T extends ObjectLiteral =ObjectLiteral,
|
|
19
|
+
> = (data: T) => DomainEventDestination[];
|
|
32
20
|
|
|
33
21
|
export type DomainEventMetadata = {
|
|
34
22
|
domain: string,
|
|
35
23
|
event: string,
|
|
36
|
-
|
|
24
|
+
|
|
25
|
+
request_path?: string | null,
|
|
26
|
+
request_method?: string | null;
|
|
27
|
+
request_ip_address?: string | null;
|
|
28
|
+
request_user_agent?: string | null;
|
|
29
|
+
|
|
30
|
+
actor_type?: string | null;
|
|
31
|
+
actor_id?: string | null;
|
|
32
|
+
actor_name?: string | null;
|
|
37
33
|
};
|
|
38
34
|
|
|
39
35
|
export type DomainEventPublishOptions<
|
|
@@ -42,9 +38,22 @@ export type DomainEventPublishOptions<
|
|
|
42
38
|
data: T,
|
|
43
39
|
dataPrevious?: T,
|
|
44
40
|
metadata: DomainEventMetadata,
|
|
45
|
-
destinations: DomainEventDestinations<T
|
|
41
|
+
destinations: DomainEventDestinations | DomainEventDestinationsFn<T>
|
|
46
42
|
};
|
|
47
43
|
|
|
48
44
|
export interface IDomainEventPublisher {
|
|
49
45
|
publish(ctx: DomainEventPublishOptions) : Promise<void>;
|
|
50
46
|
}
|
|
47
|
+
|
|
48
|
+
export type DomainEventConsumeOptions<
|
|
49
|
+
T extends ObjectLiteral = ObjectLiteral,
|
|
50
|
+
> = {
|
|
51
|
+
data: T,
|
|
52
|
+
dataPrevious?: T,
|
|
53
|
+
metadata: DomainEventMetadata,
|
|
54
|
+
destinations: DomainEventDestinations
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export interface IDomainEventConsumer {
|
|
58
|
+
consume(ctx: DomainEventConsumeOptions) : Promise<void>;
|
|
59
|
+
}
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { isObject } from '@privateaim/kit';
|
|
9
|
-
import type { DomainEventChannelName } from './types';
|
|
10
9
|
|
|
11
10
|
export function transformEventData<T>(input: T) : T {
|
|
12
11
|
if (isObject(input)) {
|
|
@@ -21,14 +20,3 @@ export function transformEventData<T>(input: T) : T {
|
|
|
21
20
|
|
|
22
21
|
return input;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
export function buildEventChannelName(
|
|
26
|
-
input: DomainEventChannelName,
|
|
27
|
-
id?: string,
|
|
28
|
-
) : string {
|
|
29
|
-
if (typeof input === 'string') {
|
|
30
|
-
return input;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return input(id);
|
|
34
|
-
}
|
package/src/services/index.ts
CHANGED
|
@@ -10,8 +10,6 @@ export * from './authup';
|
|
|
10
10
|
export * from './authup-client-authentication-hook';
|
|
11
11
|
export * from './cache';
|
|
12
12
|
export * from './domain-event';
|
|
13
|
-
export * from './loki';
|
|
14
|
-
export * from './log-store';
|
|
15
13
|
export * from './logger';
|
|
16
14
|
export * from './redis';
|
|
17
15
|
export * from './vault';
|
|
@@ -6,55 +6,30 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { read } from 'envix';
|
|
9
|
-
import path from 'node:path';
|
|
10
9
|
import { EnvironmentName } from 'typeorm-extension';
|
|
11
10
|
import type { Logger } from 'winston';
|
|
12
11
|
import { createLogger as create, format, transports } from 'winston';
|
|
13
12
|
import type { LoggerCreateContext, LoggerTransports } from './types';
|
|
14
|
-
import { LogStoreTransport } from './store';
|
|
15
|
-
import { useLogStore } from '../log-store';
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function toTransports(input: LoggerTransports) {
|
|
15
|
+
return Array.isArray(input) ? input : [input];
|
|
16
|
+
}
|
|
19
17
|
|
|
18
|
+
export function createLogger(ctx: LoggerCreateContext = {}) : Logger {
|
|
20
19
|
let loggerTransports : LoggerTransports;
|
|
21
20
|
if (read('env') === EnvironmentName.PRODUCTION) {
|
|
22
21
|
loggerTransports = [
|
|
23
22
|
new transports.Console({
|
|
24
23
|
level: 'info',
|
|
25
24
|
}),
|
|
26
|
-
|
|
27
|
-
filename: path.join(ctx.directory || process.cwd(), 'access.log'),
|
|
28
|
-
level: 'http',
|
|
29
|
-
maxsize: 10 * 1024 * 1024, // 10MB
|
|
30
|
-
maxFiles: 5,
|
|
31
|
-
}),
|
|
32
|
-
new transports.File({
|
|
33
|
-
filename: path.join(ctx.directory || process.cwd(), 'error.log'),
|
|
34
|
-
level: 'warn',
|
|
35
|
-
maxsize: 10 * 1024 * 1024, // 10MB
|
|
36
|
-
maxFiles: 5,
|
|
37
|
-
}),
|
|
38
|
-
new LogStoreTransport(
|
|
39
|
-
store,
|
|
40
|
-
{
|
|
41
|
-
level: 'http',
|
|
42
|
-
labels: ctx.labels,
|
|
43
|
-
},
|
|
44
|
-
),
|
|
25
|
+
...(ctx.transports ? toTransports(ctx.transports) : []),
|
|
45
26
|
];
|
|
46
27
|
} else {
|
|
47
28
|
loggerTransports = [
|
|
48
29
|
new transports.Console({
|
|
49
30
|
level: 'debug',
|
|
50
31
|
}),
|
|
51
|
-
|
|
52
|
-
store,
|
|
53
|
-
{
|
|
54
|
-
level: 'http',
|
|
55
|
-
labels: ctx.labels,
|
|
56
|
-
},
|
|
57
|
-
),
|
|
32
|
+
...(ctx.transports ? toTransports(ctx.transports) : []),
|
|
58
33
|
];
|
|
59
34
|
}
|
|
60
35
|
|
|
@@ -6,17 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { Logger, LoggerOptions } from 'winston';
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
export type LoggerTransports = LoggerOptions['transports'];
|
|
10
11
|
|
|
11
12
|
export type LoggerCreateContext = {
|
|
12
|
-
directory?: string,
|
|
13
13
|
options?: Partial<LoggerOptions>,
|
|
14
|
-
|
|
15
|
-
labels?: Record<string, string>,
|
|
14
|
+
transports?: LoggerTransports
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export type LoggerTransports = LoggerOptions['transports'];
|
|
19
|
-
|
|
20
17
|
export type {
|
|
21
18
|
Logger,
|
|
22
19
|
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare abstract class BaseLogStore {
|
|
2
|
-
protected labels: Record<string, string>;
|
|
3
|
-
setLabels(labels: Record<string, string>): void;
|
|
4
|
-
getLabels(): Record<string, string>;
|
|
5
|
-
extendLabels(labels: Record<string, string>): void;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/services/log-store/entities/base.ts"],"names":[],"mappings":"AAOA,8BAAsB,YAAY;IAC9B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEzC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAI/C,SAAS,IAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIpC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAMrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/log-store/entities/index.ts"],"names":[],"mappings":"AAOA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Log } from '@privateaim/kit';
|
|
2
|
-
import type { LokiClient } from '../../loki';
|
|
3
|
-
import type { LogInput, LogStore, LogStoreDeleteOptions, LogStoreQueryOptions } from '../types';
|
|
4
|
-
import { BaseLogStore } from './base';
|
|
5
|
-
export declare class LokiLogStore extends BaseLogStore implements LogStore {
|
|
6
|
-
protected instance: LokiClient;
|
|
7
|
-
constructor(instance: LokiClient, labels?: Record<string, string>);
|
|
8
|
-
write(message: string | LogInput, labels?: Record<string, string>): Promise<Log>;
|
|
9
|
-
delete(options: LogStoreDeleteOptions): Promise<void>;
|
|
10
|
-
query(input: LogStoreQueryOptions): Promise<[Log[], number]>;
|
|
11
|
-
protected buildQuery(labels: Record<string, any>): string;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=loki.d.ts.map
|
|
@@ -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 +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 +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,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,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
|
-
}
|
|
@@ -1,100 +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 {
|
|
11
|
-
LogInput, LogStore, LogStoreQueryOptions,
|
|
12
|
-
} from '../types';
|
|
13
|
-
import { nanoSeconds } from '../../loki';
|
|
14
|
-
import { BaseLogStore } from './base';
|
|
15
|
-
|
|
16
|
-
export class MemoryLogStore extends BaseLogStore implements LogStore {
|
|
17
|
-
public readonly items : Log[];
|
|
18
|
-
|
|
19
|
-
constructor(labels?: Record<string, string>) {
|
|
20
|
-
super();
|
|
21
|
-
|
|
22
|
-
this.items = [];
|
|
23
|
-
this.labels = labels;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// todo: apply query options
|
|
27
|
-
async delete(): Promise<void> {
|
|
28
|
-
return Promise.resolve();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async query(options: LogStoreQueryOptions = {}): Promise<[Log[], number]> {
|
|
32
|
-
// todo: apply all query options
|
|
33
|
-
|
|
34
|
-
const data = this.items.filter((item) => {
|
|
35
|
-
if (options.labels) {
|
|
36
|
-
if (!item.labels) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const labelKeys = Object.keys(options.labels);
|
|
41
|
-
for (let i = 0; i < labelKeys.length; i++) {
|
|
42
|
-
if (!item.labels[labelKeys[i]]) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (item.labels[labelKeys[i]] !== options.labels[labelKeys[i]]) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return true;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return [
|
|
56
|
-
data,
|
|
57
|
-
data.length,
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async write(message: string | LogInput, labels?: Record<string, string>): Promise<Log> {
|
|
62
|
-
let data : Log;
|
|
63
|
-
|
|
64
|
-
if (typeof message === 'string') {
|
|
65
|
-
const labelsNormalized = {
|
|
66
|
-
...this.labels,
|
|
67
|
-
...(labels || {}),
|
|
68
|
-
};
|
|
69
|
-
const level = (labelsNormalized.level || LogLevel.DEBUG) as LogLevel;
|
|
70
|
-
delete labelsNormalized.level;
|
|
71
|
-
|
|
72
|
-
data = {
|
|
73
|
-
message,
|
|
74
|
-
level,
|
|
75
|
-
time: nanoSeconds(),
|
|
76
|
-
labels: labelsNormalized,
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
const labelsNormalized = {
|
|
80
|
-
...this.labels,
|
|
81
|
-
...(message.labels || {}),
|
|
82
|
-
...(labels || {}),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const level = (message.level || labelsNormalized.level || LogLevel.DEBUG) as LogLevel;
|
|
86
|
-
delete labelsNormalized.level;
|
|
87
|
-
|
|
88
|
-
data = {
|
|
89
|
-
...message,
|
|
90
|
-
level,
|
|
91
|
-
time: message.time || nanoSeconds(),
|
|
92
|
-
labels: labelsNormalized,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this.items.push(data);
|
|
97
|
-
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,10 +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 './entities';
|
|
9
|
-
export * from './singleton';
|
|
10
|
-
export * from './types';
|