@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
|
@@ -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 type { Factory } from 'singa';
|
|
9
|
-
import { singa } from 'singa';
|
|
10
|
-
import type { LogStore } from './types';
|
|
11
|
-
import { LokiLogStore, MemoryLogStore } from './entities';
|
|
12
|
-
import { isLokiClientUsable, useLokiClient } from '../loki';
|
|
13
|
-
|
|
14
|
-
const instance = singa<LogStore>({
|
|
15
|
-
name: 'logStore',
|
|
16
|
-
factory: () => {
|
|
17
|
-
if (isLokiClientUsable()) {
|
|
18
|
-
const loki = useLokiClient();
|
|
19
|
-
return new LokiLogStore(loki);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return new MemoryLogStore();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export function isLogStoreUsable() {
|
|
27
|
-
return instance.has() || instance.hasFactory();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function setLogStoreFactory(input: Factory<LogStore>) {
|
|
31
|
-
instance.setFactory(input);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function useLogStore(): LogStore {
|
|
35
|
-
return instance.use();
|
|
36
|
-
}
|
|
@@ -1,42 +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, LogLevel } from '@privateaim/kit';
|
|
9
|
-
|
|
10
|
-
export type LogStoreQueryOptions = {
|
|
11
|
-
labels?: Record<string, string>
|
|
12
|
-
start?: number,
|
|
13
|
-
end?: number,
|
|
14
|
-
sort?: 'DESC' | 'ASC',
|
|
15
|
-
limit?: number
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type LogStoreDeleteOptions = {
|
|
19
|
-
labels?: Record<string, string>
|
|
20
|
-
start?: number,
|
|
21
|
-
end?: number,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type LogInput = Omit<Log, 'labels' | 'time' | 'level'> & {
|
|
25
|
-
time?: bigint,
|
|
26
|
-
level?: `${LogLevel}`,
|
|
27
|
-
labels?: Record<string, string>
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export interface LogStore {
|
|
31
|
-
setLabels(labels: Record<string, string>): void;
|
|
32
|
-
|
|
33
|
-
getLabels() : Record<string, string>;
|
|
34
|
-
|
|
35
|
-
extendLabels(labels: Record<string, string>): void;
|
|
36
|
-
|
|
37
|
-
write(message: string | LogInput, labels?: Record<string, string>) : Promise<Log>;
|
|
38
|
-
|
|
39
|
-
query(options?: LogStoreQueryOptions) : Promise<[Log[], number]>;
|
|
40
|
-
|
|
41
|
-
delete(options?: LogStoreDeleteOptions) : Promise<void>;
|
|
42
|
-
}
|
|
@@ -1,70 +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 { TransportStreamOptions } from 'winston-transport';
|
|
9
|
-
import WinstonTransport from 'winston-transport';
|
|
10
|
-
import type { LogInput, LogStore } from '../log-store';
|
|
11
|
-
|
|
12
|
-
type LogStoreTransportOptions = TransportStreamOptions & {
|
|
13
|
-
labels?: Record<string, string>
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export class LogStoreTransport extends WinstonTransport {
|
|
17
|
-
protected instance : LogStore;
|
|
18
|
-
|
|
19
|
-
protected labels : Record<string, string>;
|
|
20
|
-
|
|
21
|
-
constructor(store: LogStore, options: LogStoreTransportOptions = {}) {
|
|
22
|
-
super(options);
|
|
23
|
-
|
|
24
|
-
this.instance = store;
|
|
25
|
-
this.labels = options.labels || {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
log(info: Record<PropertyKey, any>, next: () => void): any {
|
|
29
|
-
const {
|
|
30
|
-
message, timestamp, stack, ...data
|
|
31
|
-
} = info;
|
|
32
|
-
|
|
33
|
-
const labels : Record<string, string> = {
|
|
34
|
-
...this.labels,
|
|
35
|
-
};
|
|
36
|
-
const keys = Object.keys(data);
|
|
37
|
-
for (let i = 0; i < keys.length; i++) {
|
|
38
|
-
if (typeof keys[i] !== 'string') {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const value = data[keys[i]];
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
typeof value === 'string' ||
|
|
46
|
-
typeof value === 'number' ||
|
|
47
|
-
typeof value === 'boolean'
|
|
48
|
-
) {
|
|
49
|
-
labels[keys[i]] = `${value}`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let date : Date;
|
|
54
|
-
if (typeof timestamp === 'string') {
|
|
55
|
-
date = new Date(`${timestamp}`);
|
|
56
|
-
} else {
|
|
57
|
-
date = new Date();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const payload : LogInput = {
|
|
61
|
-
message: stack || message,
|
|
62
|
-
time: BigInt(date.getTime()) * 1_000_000n,
|
|
63
|
-
labels,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
Promise.resolve()
|
|
67
|
-
.then(() => this.instance.write(payload))
|
|
68
|
-
.then(() => next());
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,30 +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 {
|
|
9
|
-
LokiClient,
|
|
10
|
-
CompactorDeletionRequestCreate as LokiCompactorDeletionRequestCreate,
|
|
11
|
-
Config as LokiConfig,
|
|
12
|
-
ConfigInput as LokiConfigInput,
|
|
13
|
-
DistributorPushStream as LokiDistributorPushStream,
|
|
14
|
-
QuerierQueryRangeOptions as LokiQuerierQueryRangeOptions,
|
|
15
|
-
QuerierQueryResult as LokiQuerierQueryResult,
|
|
16
|
-
createClient as createLokiClient,
|
|
17
|
-
nanoSeconds,
|
|
18
|
-
} from '@hapic/loki';
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
LokiClient,
|
|
22
|
-
LokiConfig,
|
|
23
|
-
LokiConfigInput,
|
|
24
|
-
LokiCompactorDeletionRequestCreate,
|
|
25
|
-
LokiDistributorPushStream,
|
|
26
|
-
LokiQuerierQueryRangeOptions,
|
|
27
|
-
LokiQuerierQueryResult,
|
|
28
|
-
createLokiClient,
|
|
29
|
-
nanoSeconds,
|
|
30
|
-
};
|
|
@@ -1,21 +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 { MemoryLogStore } from '../../src';
|
|
9
|
-
|
|
10
|
-
describe('log-store', () => {
|
|
11
|
-
it('should permit label management', () => {
|
|
12
|
-
const store = new MemoryLogStore();
|
|
13
|
-
store.setLabels({ app: 'app' });
|
|
14
|
-
store.extendLabels({ foo: 'bar' });
|
|
15
|
-
|
|
16
|
-
expect(store.getLabels()).toEqual({
|
|
17
|
-
app: 'app',
|
|
18
|
-
foo: 'bar',
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/test/unit/logger.spec.ts
DELETED
|
@@ -1,36 +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 { wait } from '@privateaim/kit';
|
|
9
|
-
import { MemoryLogStore, createLogger } from '../../src';
|
|
10
|
-
|
|
11
|
-
describe('logger', () => {
|
|
12
|
-
it('should work with store', async () => {
|
|
13
|
-
const store = new MemoryLogStore();
|
|
14
|
-
store.setLabels({ app: 'app' });
|
|
15
|
-
|
|
16
|
-
const logger = createLogger({
|
|
17
|
-
store,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
logger.info('foo', { meta: 'bar' });
|
|
21
|
-
|
|
22
|
-
await wait(0);
|
|
23
|
-
|
|
24
|
-
expect(store.items).toHaveLength(1);
|
|
25
|
-
|
|
26
|
-
const [item] = store.items;
|
|
27
|
-
|
|
28
|
-
expect(item.level).toEqual('info');
|
|
29
|
-
expect(item.message).toEqual('foo');
|
|
30
|
-
expect(item.labels).toEqual({
|
|
31
|
-
app: 'app',
|
|
32
|
-
meta: 'bar',
|
|
33
|
-
});
|
|
34
|
-
expect(item.time).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
});
|