@mrxsys/mrx-core 2.11.0-1-and-267-20250925 → 2.11.1-1-and-275-20251023
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/dist/{chunk-fp8xg6kq.js → chunk-441xs5k1.js} +1 -1
- package/dist/{chunk-bdcsh435.js → chunk-4v86f7gp.js} +5 -5
- package/dist/{chunk-00s6t4tw.js → chunk-7t524zqh.js} +4 -4
- package/dist/{chunk-d1vp74n0.js → chunk-afd82epa.js} +2 -2
- package/dist/{chunk-v9kvw5x7.js → chunk-afyz8rg5.js} +2 -2
- package/dist/{chunk-6sfnrhfs.js → chunk-pjv1ekwr.js} +33 -1
- package/dist/chunk-rz5p4j3p.js +13 -0
- package/dist/{chunk-h9t48r9q.js → chunk-sqts8vyk.js} +16 -2
- package/dist/errors/enums/http-status-codes.d.ts +15 -1
- package/dist/errors/enums/index.d.ts +1 -1
- package/dist/errors/enums/index.js +3 -3
- package/dist/errors/http-error.d.ts +3 -3
- package/dist/errors/index.js +2 -2
- package/dist/errors/utils/index.js +2 -2
- package/dist/modules/database/enums/database-error-keys.d.ts +2 -2
- package/dist/modules/database/enums/index.js +1 -1
- package/dist/modules/database/index.js +5 -5
- package/dist/modules/elysia/cache/cache.d.ts +8 -14
- package/dist/modules/elysia/cache/index.js +66 -46
- package/dist/modules/elysia/cache/types/cache-item.d.ts +0 -1
- package/dist/modules/elysia/cache/types/cache-options.d.ts +2 -11
- package/dist/modules/elysia/crud/index.js +16 -16
- package/dist/modules/elysia/crud/operations/count.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/delete.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/deleteOne.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/find.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/findOne.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/index.js +7 -7
- package/dist/modules/elysia/crud/operations/insert.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/update.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/updateOne.d.ts +1 -1
- package/dist/modules/elysia/db-resolver/db-resolver.d.ts +1 -1
- package/dist/modules/elysia/db-resolver/index.js +6 -6
- package/dist/modules/elysia/error/index.js +2 -2
- package/dist/modules/elysia/microservice/microservice.d.ts +12 -12
- package/dist/modules/elysia/rate-limit/index.js +53 -28
- package/dist/modules/elysia/rate-limit/rate-limit.d.ts +361 -32
- package/dist/modules/elysia/rate-limit/types/rate-limit-options.d.ts +0 -9
- package/dist/modules/jwt/index.js +2 -2
- package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +25 -0
- package/dist/modules/kv-store/bun-redis/index.d.ts +1 -0
- package/dist/modules/kv-store/bun-redis/index.js +76 -0
- package/dist/modules/kv-store/ioredis/index.js +4 -10
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +0 -82
- package/dist/modules/kv-store/memory/index.js +98 -4
- package/dist/modules/kv-store/memory/memory-store.d.ts +0 -84
- package/dist/modules/kv-store/types/kv-store.d.ts +2 -2
- package/dist/modules/logger/enums/index.js +1 -1
- package/dist/modules/logger/enums/logger-error-keys.d.ts +6 -3
- package/dist/modules/logger/events/logger-events.d.ts +12 -3
- package/dist/modules/logger/index.js +173 -81
- package/dist/modules/logger/logger.d.ts +115 -133
- package/dist/modules/logger/sinks/console-logger.d.ts +2 -16
- package/dist/modules/logger/sinks/devnull-logger.d.ts +8 -0
- package/dist/modules/logger/sinks/file-logger/enums/file-logger-error-keys.d.ts +3 -0
- package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +25 -0
- package/dist/modules/logger/sinks/index.d.ts +4 -2
- package/dist/modules/logger/sinks/index.js +54 -31
- package/dist/modules/logger/types/index.d.ts +6 -6
- package/dist/modules/logger/types/log-levels.d.ts +1 -4
- package/dist/modules/logger/types/logger-options.d.ts +41 -0
- package/dist/modules/logger/types/logger-sink.d.ts +12 -3
- package/dist/modules/logger/types/sink-bodies-intersection.d.ts +2 -0
- package/dist/modules/logger/types/sink-body.d.ts +1 -1
- package/dist/modules/logger/types/sink-map.d.ts +1 -1
- package/dist/modules/repository/index.js +4 -4
- package/dist/modules/repository/types/query-options.d.ts +2 -2
- package/package.json +30 -25
- package/dist/chunk-b23dvm2d.js +0 -29
- package/dist/chunk-b96fm9ph.js +0 -10
- package/dist/chunk-e30paw8a.js +0 -101
- package/dist/modules/elysia/cache/utils/index.d.ts +0 -1
- package/dist/modules/elysia/cache/utils/index.js +0 -7
- package/dist/modules/logger/sinks/file-logger.d.ts +0 -25
- package/dist/modules/logger/types/bodies-intersection.d.ts +0 -2
- package/dist/modules/logger/types/log-stream-chunk.d.ts +0 -15
|
@@ -1,189 +1,171 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '../../modules/typed-event-emitter/typed-event-emitter';
|
|
2
2
|
import type { LoggerEvent } from './events/logger-events';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoggerOptions } from './types/logger-options';
|
|
4
4
|
import type { LoggerSink } from './types/logger-sink';
|
|
5
|
+
import type { SinkBodiesIntersection } from './types/sink-bodies-intersection';
|
|
5
6
|
import type { SinkMap } from './types/sink-map';
|
|
6
|
-
/**
|
|
7
|
-
* Logger provides a flexible, type-safe logging system that allows multiple sinks for log output.
|
|
8
|
-
* The logger uses a transform stream to process log entries and execute the logging sinks.
|
|
9
|
-
*
|
|
10
|
-
* Logger extends the TypedEventEmitter class to emit typed events when an error occurs or when the logger ends.
|
|
11
|
-
* The logger can log messages with different levels: error, warn, info, debug, and log.
|
|
12
|
-
*
|
|
13
|
-
* @template TSinks - The map of sink names to LoggerStrategy types.
|
|
14
|
-
*/
|
|
15
7
|
export declare class Logger<TSinks extends SinkMap = {}> extends TypedEventEmitter<LoggerEvent> {
|
|
16
8
|
/**
|
|
17
|
-
*
|
|
9
|
+
* Map of registered sinks (logging destinations)
|
|
18
10
|
*/
|
|
19
11
|
private readonly _sinks;
|
|
20
12
|
/**
|
|
21
|
-
*
|
|
13
|
+
* List of registered sink keys for quick access
|
|
22
14
|
*/
|
|
23
|
-
private readonly
|
|
15
|
+
private readonly _sinkKeys;
|
|
24
16
|
/**
|
|
25
|
-
*
|
|
17
|
+
* Worker instance handling log processing
|
|
26
18
|
*/
|
|
27
|
-
private readonly
|
|
19
|
+
private readonly _worker;
|
|
28
20
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @defaultValue 10_000
|
|
21
|
+
* Maximum number of pending log messages allowed in the queue
|
|
31
22
|
*/
|
|
32
23
|
private readonly _maxPendingLogs;
|
|
33
24
|
/**
|
|
34
|
-
*
|
|
25
|
+
* Maximum number of messages in flight to the worker
|
|
26
|
+
*/
|
|
27
|
+
private readonly _maxMessagesInFlight;
|
|
28
|
+
/**
|
|
29
|
+
* Number of logs to batch before sending to worker
|
|
30
|
+
*/
|
|
31
|
+
private readonly _batchSize;
|
|
32
|
+
/**
|
|
33
|
+
* Timeout in milliseconds before flushing incomplete batch
|
|
34
|
+
*/
|
|
35
|
+
private readonly _batchTimeout;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to auto flush and close on process exit
|
|
38
|
+
*/
|
|
39
|
+
private readonly _autoEnd;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to flush before process exit
|
|
42
|
+
*/
|
|
43
|
+
private readonly _flushOnBeforeExit;
|
|
44
|
+
/**
|
|
45
|
+
* Queue of pending log messages
|
|
46
|
+
*/
|
|
47
|
+
private readonly _pendingLogs;
|
|
48
|
+
/**
|
|
49
|
+
* Number of log messages currently being processed by the worker
|
|
50
|
+
*/
|
|
51
|
+
private _messagesInFlight;
|
|
52
|
+
/**
|
|
53
|
+
* Timer for batching log messages
|
|
54
|
+
*/
|
|
55
|
+
private _batchTimer;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the logger is currently writing log messages to the worker
|
|
35
58
|
*/
|
|
36
59
|
private _isWriting;
|
|
37
60
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @template TStrategies - The map of sink names to LoggerStrategy types.
|
|
41
|
-
*
|
|
42
|
-
* @param sinks - Initial sinks map.
|
|
43
|
-
*
|
|
44
|
-
* @param maxPendingLogs - Maximum number of logs in the queue (default: 10_000)
|
|
61
|
+
* Resolvers for flush promises
|
|
45
62
|
*/
|
|
46
|
-
|
|
63
|
+
private readonly _flushResolvers;
|
|
47
64
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @template Key - The name of the sink.
|
|
51
|
-
* @template Sink - The sink type.
|
|
52
|
-
*
|
|
53
|
-
* @param name - The name of the sink.
|
|
54
|
-
* @param sink - The sink to add. It must implement {@link LoggerSink}.
|
|
55
|
-
*
|
|
56
|
-
* @throws ({@link BaseError}) - If the sink is already added.
|
|
57
|
-
*
|
|
58
|
-
* @returns A new Logger instance with the added sink.
|
|
65
|
+
* Resolver for the close promise
|
|
59
66
|
*/
|
|
60
|
-
|
|
67
|
+
private _closeResolver;
|
|
61
68
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @template Key - The name of the sink.
|
|
65
|
-
*
|
|
66
|
-
* @param name - The name of the sink to remove.
|
|
67
|
-
*
|
|
68
|
-
* @throws ({@link BaseError}) - If the sink is not found.
|
|
69
|
-
*
|
|
70
|
-
* @returns A new Logger instance without the removed sink.
|
|
69
|
+
* Resolver for backpressure when maxMessagesInFlight is reached
|
|
71
70
|
*/
|
|
72
|
-
|
|
71
|
+
private _backpressureResolver;
|
|
73
72
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @template TNew - The new sinks to add.
|
|
77
|
-
*
|
|
78
|
-
* @param sinks - An array of tuples where each tuple contains the sink name and the sink instance.
|
|
79
|
-
*
|
|
80
|
-
* @throws ({@link BaseError}) - If any sink is already added.
|
|
81
|
-
*
|
|
82
|
-
* @returns A new Logger instance with the added sinks.
|
|
73
|
+
* Handle the exit event
|
|
83
74
|
*/
|
|
84
|
-
|
|
85
|
-
[K in TNew[number][0]]: Extract<TNew[number], [K, LoggerSink]>[1];
|
|
86
|
-
}>;
|
|
75
|
+
private readonly _handleExit;
|
|
87
76
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @template Keys - The names of the sinks to remove.
|
|
91
|
-
*
|
|
92
|
-
* @param names - An array of sink names to remove.
|
|
93
|
-
*
|
|
94
|
-
* @throws ({@link BaseError}) - If any sink is not found.
|
|
95
|
-
*
|
|
96
|
-
* @returns A new Logger instance without the removed sinks.
|
|
77
|
+
* Handle the worker close event
|
|
97
78
|
*/
|
|
98
|
-
|
|
79
|
+
private readonly _handleWorkerClose;
|
|
99
80
|
/**
|
|
100
|
-
*
|
|
81
|
+
* Creates a new Logger instance with the specified options.
|
|
101
82
|
*
|
|
102
|
-
* @
|
|
83
|
+
* @param options - Configuration options for the logger
|
|
103
84
|
*/
|
|
104
|
-
|
|
85
|
+
constructor(options?: LoggerOptions);
|
|
105
86
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @template SNames - The names of the sinks to use.
|
|
87
|
+
* Registers a new sink (logging destination) with the logger.
|
|
109
88
|
*
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
89
|
+
* @param sinkName - The name of the sink
|
|
90
|
+
* @param sinkConstructor - The sink class constructor
|
|
91
|
+
* @param sinkArgs - The sink constructor arguments
|
|
112
92
|
*
|
|
113
|
-
* @
|
|
93
|
+
* @returns The logger instance with new type (for chaining)
|
|
114
94
|
*/
|
|
115
|
-
|
|
95
|
+
registerSink<TSinkName extends string, TSink extends LoggerSink, TSinkArgs extends unknown[]>(sinkName: TSinkName, sinkConstructor: new (...args: TSinkArgs) => TSink, ...sinkArgs: TSinkArgs): Logger<TSinks & Record<TSinkName, new (...args: TSinkArgs) => TSink>>;
|
|
116
96
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @template SNames - The names of the sinks to use.
|
|
120
|
-
*
|
|
121
|
-
* @param object - The object to log.
|
|
122
|
-
* @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
|
|
97
|
+
* Logs a message at the ERROR level to the specified sinks.
|
|
123
98
|
*
|
|
124
|
-
* @
|
|
99
|
+
* @param object - The log message object
|
|
100
|
+
* @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
|
|
125
101
|
*/
|
|
126
|
-
|
|
102
|
+
error<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
|
|
127
103
|
/**
|
|
128
|
-
*
|
|
104
|
+
* Logs a message at the WARN level to the specified sinks.
|
|
129
105
|
*
|
|
130
|
-
* @
|
|
131
|
-
*
|
|
132
|
-
* @param object - The object to log.
|
|
133
|
-
* @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
|
|
134
|
-
*
|
|
135
|
-
* @throws ({@link BaseError}) - If no sink is added.
|
|
106
|
+
* @param object - The log message object
|
|
107
|
+
* @param sinkNames - Optionnal array of sink names to log to; logs to all sinks if omitted
|
|
136
108
|
*/
|
|
137
|
-
|
|
109
|
+
warn<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
|
|
138
110
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @template SNames - The names of the sinks to use.
|
|
142
|
-
*
|
|
143
|
-
* @param object - The object to log.
|
|
144
|
-
* @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
|
|
111
|
+
* Logs a message at the INFO level to the specified sinks.
|
|
145
112
|
*
|
|
146
|
-
* @
|
|
113
|
+
* @param object - The log message object
|
|
114
|
+
* @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
|
|
147
115
|
*/
|
|
148
|
-
|
|
116
|
+
info<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
|
|
149
117
|
/**
|
|
150
|
-
*
|
|
118
|
+
* Logs a message at the DEBUG level to the specified sinks.
|
|
151
119
|
*
|
|
152
|
-
* @
|
|
153
|
-
*
|
|
154
|
-
* @param object - The object to log.
|
|
155
|
-
* @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
|
|
156
|
-
*
|
|
157
|
-
* @throws ({@link BaseError}) - If no sink is added.
|
|
120
|
+
* @param object - The log message object
|
|
121
|
+
* @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
|
|
158
122
|
*/
|
|
159
|
-
|
|
123
|
+
debug<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
|
|
160
124
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @template TLogObject - The type of the log object.
|
|
164
|
-
*
|
|
165
|
-
* @param level - The log level.
|
|
166
|
-
* @param date - The date of the log event.
|
|
167
|
-
* @param object - The object to log.
|
|
168
|
-
* @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
|
|
125
|
+
* Logs a message at the TRACE level to the specified sinks.
|
|
169
126
|
*
|
|
170
|
-
* @
|
|
127
|
+
* @param object - The log message object
|
|
128
|
+
* @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
|
|
171
129
|
*/
|
|
172
|
-
|
|
130
|
+
log<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
|
|
173
131
|
/**
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
132
|
+
* Flushes all pending logs and waits for them to be processed.
|
|
133
|
+
*/
|
|
134
|
+
flush(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Closes the logger, flushes pending logs, and releases resources.
|
|
137
|
+
*/
|
|
138
|
+
close(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Enqueues a log message to be processed by the worker.
|
|
181
141
|
*
|
|
182
|
-
* @
|
|
142
|
+
* @param level - The log level
|
|
143
|
+
* @param object - The log message object
|
|
144
|
+
* @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
|
|
145
|
+
*/
|
|
146
|
+
private _enqueue;
|
|
147
|
+
/**
|
|
148
|
+
* Triggers processing of pending logs.
|
|
149
|
+
*/
|
|
150
|
+
private _triggerProcessing;
|
|
151
|
+
/**
|
|
152
|
+
* Processes pending log messages by sending them to the worker in batches.
|
|
153
|
+
*/
|
|
154
|
+
private _processPendingLogs;
|
|
155
|
+
/**
|
|
156
|
+
* Releases a batch by decrementing the in-flight counter and resolving backpressure if needed.
|
|
157
|
+
*/
|
|
158
|
+
private _releaseBatch;
|
|
159
|
+
/**
|
|
160
|
+
* Sets up message handling for the worker.
|
|
161
|
+
*/
|
|
162
|
+
private _setupWorkerMessages;
|
|
163
|
+
/**
|
|
164
|
+
* Sets up automatic flushing and closing of the logger on process exit.
|
|
183
165
|
*/
|
|
184
|
-
private
|
|
166
|
+
private _setupAutoEnd;
|
|
185
167
|
/**
|
|
186
|
-
*
|
|
168
|
+
* Handles the beforeExit event.
|
|
187
169
|
*/
|
|
188
|
-
private
|
|
170
|
+
private readonly _handleBeforeExit;
|
|
189
171
|
}
|
|
@@ -3,20 +3,6 @@ import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
|
|
|
3
3
|
/**
|
|
4
4
|
* ConsoleLoggerSink implements LoggerSink to provide logging functionality to the console.
|
|
5
5
|
*/
|
|
6
|
-
export declare class ConsoleLoggerSink implements LoggerSink {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the ConsoleLoggerSink.
|
|
10
|
-
*
|
|
11
|
-
* @param colorize - Indicates if the output should be colorized. (Default is false.)
|
|
12
|
-
*/
|
|
13
|
-
constructor(colorize?: boolean);
|
|
14
|
-
/**
|
|
15
|
-
* Logs a message to the console with the specified log level.
|
|
16
|
-
*
|
|
17
|
-
* @param level - The log level at which the message should be logged.
|
|
18
|
-
* @param date - The date at which the message was logged.
|
|
19
|
-
* @param object - The object to log.
|
|
20
|
-
*/
|
|
21
|
-
log(level: LogLevels, date: Date, object: unknown): void;
|
|
6
|
+
export declare class ConsoleLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
|
|
7
|
+
log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void>;
|
|
22
8
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
|
|
2
|
+
/**
|
|
3
|
+
* DevNullLoggerSink implements LoggerSink to discard all logs (like /dev/null).
|
|
4
|
+
* Useful for benchmarking the logger overhead without I/O.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DevNullLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
|
|
7
|
+
log(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LogLevels } from '../../../../modules/logger/types/log-levels';
|
|
2
|
+
import type { LoggerSink } from '../../../../modules/logger/types/logger-sink';
|
|
3
|
+
export interface FileLoggerConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Path to the file to log to.
|
|
6
|
+
*/
|
|
7
|
+
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* Buffer size before flushing to disk (default: 16KB)
|
|
10
|
+
* Higher = better throughput, lower = less memory
|
|
11
|
+
*/
|
|
12
|
+
bufferSize?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* FileLoggerSink implements LoggerSink to provide logging functionality to the file system.
|
|
16
|
+
* Uses a WriteStream for efficient buffered writes (like Pino's sonic-boom).
|
|
17
|
+
*/
|
|
18
|
+
export declare class FileLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
|
|
19
|
+
readonly config: FileLoggerConfig;
|
|
20
|
+
private readonly _stream;
|
|
21
|
+
private _isClosed;
|
|
22
|
+
constructor(config: FileLoggerConfig);
|
|
23
|
+
log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { ConsoleLoggerSink } from './console-logger
|
|
2
|
-
export {
|
|
1
|
+
export { ConsoleLoggerSink } from './console-logger';
|
|
2
|
+
export { DevNullLoggerSink } from './devnull-logger';
|
|
3
|
+
export { FILE_LOGGER_ERROR_KEYS } from './file-logger/enums/file-logger-error-keys';
|
|
4
|
+
export { FileLoggerSink, type FileLoggerConfig } from './file-logger/file-logger';
|
|
@@ -1,44 +1,67 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
BaseError
|
|
4
|
+
} from "../../../chunk-9cgzhc50.js";
|
|
5
|
+
|
|
2
6
|
// source/modules/logger/sinks/console-logger.ts
|
|
3
7
|
class ConsoleLoggerSink {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
log(level, date, object) {
|
|
9
|
-
const colors = {
|
|
10
|
-
ERROR: "\x1B[31m",
|
|
11
|
-
WARN: "\x1B[33m",
|
|
12
|
-
INFO: "\x1B[36m",
|
|
13
|
-
DEBUG: "\x1B[34m",
|
|
14
|
-
LOG: "\x1B[35m"
|
|
15
|
-
};
|
|
16
|
-
const dateColor = this._colorize ? "\x1B[33m" : "";
|
|
17
|
-
const colorReset = this._colorize ? "\x1B[0m" : "";
|
|
18
|
-
const logLevelColor = this._colorize ? colors[level] : "";
|
|
19
|
-
const sanitizedObject = typeof object === "string" ? object : JSON.stringify(object);
|
|
20
|
-
const prefixDate = `[${dateColor}${date.toISOString().replace(/T/, " ").replace(/\..+/, "")}${colorReset}]`;
|
|
21
|
-
const message = `${prefixDate} ${logLevelColor}${level}${colorReset} : ${sanitizedObject}`;
|
|
22
|
-
console[level.toLowerCase()](message);
|
|
8
|
+
async log(level, timestamp, object) {
|
|
9
|
+
const sanitizedContent = typeof object === "string" ? object : JSON.stringify(object);
|
|
10
|
+
await Bun.write(Bun.stdout, `{"timestamp":${timestamp},"level":"${level}","content":${sanitizedContent}}
|
|
11
|
+
`);
|
|
23
12
|
}
|
|
24
13
|
}
|
|
25
|
-
// source/modules/logger/sinks/
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
// source/modules/logger/sinks/devnull-logger.ts
|
|
15
|
+
class DevNullLoggerSink {
|
|
16
|
+
log() {}
|
|
17
|
+
}
|
|
18
|
+
// source/modules/logger/sinks/file-logger/enums/file-logger-error-keys.ts
|
|
19
|
+
var FILE_LOGGER_ERROR_KEYS = {
|
|
20
|
+
FAILED_TO_CLOSE_STREAM: "mrx-core.file_logger.error.failed_to_close_stream"
|
|
21
|
+
};
|
|
22
|
+
// source/modules/logger/sinks/file-logger/file-logger.ts
|
|
23
|
+
import { createWriteStream } from "fs";
|
|
28
24
|
class FileLoggerSink {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
config;
|
|
26
|
+
_stream;
|
|
27
|
+
_isClosed = false;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
this._stream = createWriteStream(config.path, {
|
|
31
|
+
flags: "a",
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
highWaterMark: config.bufferSize ?? 16 * 1024
|
|
34
|
+
});
|
|
32
35
|
}
|
|
33
|
-
async log(level,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
async log(level, timestamp, object) {
|
|
37
|
+
if (this._isClosed)
|
|
38
|
+
return;
|
|
39
|
+
const sanitizedContent = typeof object === "string" ? object : JSON.stringify(object);
|
|
40
|
+
const message = `{"timestamp":${timestamp},"level":"${level}","content":${sanitizedContent}}
|
|
41
|
+
`;
|
|
42
|
+
const canContinue = this._stream.write(message);
|
|
43
|
+
if (!canContinue)
|
|
44
|
+
await new Promise((resolve) => {
|
|
45
|
+
this._stream.once("drain", resolve);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
if (this._isClosed)
|
|
50
|
+
return;
|
|
51
|
+
this._isClosed = true;
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
this._stream.end((err) => {
|
|
54
|
+
if (err)
|
|
55
|
+
reject(new BaseError(FILE_LOGGER_ERROR_KEYS.FAILED_TO_CLOSE_STREAM, err.message));
|
|
56
|
+
else
|
|
57
|
+
resolve();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
39
60
|
}
|
|
40
61
|
}
|
|
41
62
|
export {
|
|
42
63
|
FileLoggerSink,
|
|
64
|
+
FILE_LOGGER_ERROR_KEYS,
|
|
65
|
+
DevNullLoggerSink,
|
|
43
66
|
ConsoleLoggerSink
|
|
44
67
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export type {
|
|
3
|
-
export type {
|
|
4
|
-
export type {
|
|
5
|
-
export type { SinkBody } from './sink-body
|
|
6
|
-
export type { SinkMap } from './sink-map
|
|
1
|
+
export type { LogLevels } from './log-levels';
|
|
2
|
+
export type { LoggerOptions } from './logger-options';
|
|
3
|
+
export type { LoggerSink } from './logger-sink';
|
|
4
|
+
export type { SinkBodiesIntersection } from './sink-bodies-intersection';
|
|
5
|
+
export type { SinkBody } from './sink-body';
|
|
6
|
+
export type { SinkMap } from './sink-map';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the Logger instance.
|
|
3
|
+
*/
|
|
4
|
+
export interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Maximum number of log messages that can be queued in memory before dropping new logs.
|
|
7
|
+
* @default 10_000
|
|
8
|
+
*/
|
|
9
|
+
maxPendingLogs?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of messages that can be sent to the worker without acknowledgment.
|
|
12
|
+
* Controls backpressure to prevent overwhelming the worker thread.
|
|
13
|
+
* @default 100
|
|
14
|
+
*/
|
|
15
|
+
maxMessagesInFlight?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of logs to batch together before sending to the worker.
|
|
18
|
+
* Higher values = better throughput but higher latency.
|
|
19
|
+
* @default 100
|
|
20
|
+
*/
|
|
21
|
+
batchSize?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum time in milliseconds to wait before flushing a partial batch.
|
|
24
|
+
* Prevents logs from being delayed indefinitely when batch size is not reached.
|
|
25
|
+
* Set to 0 to disable time-based flushing.
|
|
26
|
+
* @default 0.1 (100 microseconds)
|
|
27
|
+
*/
|
|
28
|
+
batchTimeout?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to automatically flush and close the logger when the process exits.
|
|
31
|
+
* When enabled, hooks are installed on `process.on('beforeExit')` and `process.on('exit')`.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
autoEnd?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to flush pending logs before the process exits.
|
|
37
|
+
* Only applies when `autoEnd` is true.
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
flushOnBeforeExit?: boolean;
|
|
41
|
+
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import type { LogLevels } from './log-levels';
|
|
2
|
-
export interface LoggerSink<TLogObject = unknown> {
|
|
2
|
+
export interface LoggerSink<TLogObject = unknown, TConfig = unknown> {
|
|
3
|
+
/** Optional configuration for the sink */
|
|
4
|
+
readonly config?: TConfig;
|
|
3
5
|
/**
|
|
4
6
|
* Logs a message with the sink's implementation.
|
|
7
|
+
* si vous voulez créer votre propre sink vous devrez implémenter cette méthode et tout ce qui est importation doit etre sous forme d'importation dynamique
|
|
5
8
|
*
|
|
6
9
|
* @param level - The log level at which the message should be logged.
|
|
7
|
-
* @param
|
|
10
|
+
* @param timestamp - The date at which the message was logged.
|
|
8
11
|
* @param object - The object to log.
|
|
9
12
|
*/
|
|
10
|
-
log(level: LogLevels,
|
|
13
|
+
log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void> | void;
|
|
14
|
+
/**
|
|
15
|
+
* Closes the sink and flushes any pending logs.
|
|
16
|
+
* This method is called when the logger is closing to ensure all resources are properly released.
|
|
17
|
+
* Optional - implement this if your sink needs cleanup (e.g., closing file handles, database connections).
|
|
18
|
+
*/
|
|
19
|
+
close?(): Promise<void> | void;
|
|
11
20
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { LoggerSink } from './logger-sink';
|
|
2
|
-
export type SinkBody<TSink, Key extends keyof TSink> = TSink[Key] extends LoggerSink<infer TBody> ? TBody : never;
|
|
2
|
+
export type SinkBody<TSink, Key extends keyof TSink> = TSink[Key] extends new (...args: any[]) => LoggerSink<infer TBody> ? TBody : TSink[Key] extends LoggerSink<infer TBody> ? TBody : never;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { LoggerSink } from './logger-sink';
|
|
2
|
-
export type SinkMap = Record<string, LoggerSink>;
|
|
2
|
+
export type SinkMap = Record<string, new (...args: any[]) => LoggerSink>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
Repository
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-afyz8rg5.js";
|
|
5
5
|
import"../../chunk-grfyngq0.js";
|
|
6
|
-
import"../../chunk-
|
|
7
|
-
import"../../chunk-
|
|
8
|
-
import"../../chunk-
|
|
6
|
+
import"../../chunk-4v86f7gp.js";
|
|
7
|
+
import"../../chunk-7t524zqh.js";
|
|
8
|
+
import"../../chunk-sqts8vyk.js";
|
|
9
9
|
import"../../chunk-9cgzhc50.js";
|
|
10
10
|
export {
|
|
11
11
|
Repository
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HTTP_STATUS_CODES } from '../../../errors/enums/http-status-codes';
|
|
2
2
|
import type { Filter } from './filter';
|
|
3
3
|
import type { OrderByItem } from './order-by-item';
|
|
4
4
|
import type { SelectedFields } from './selected-fields';
|
|
@@ -31,7 +31,7 @@ export interface QueryOptions<TModel> {
|
|
|
31
31
|
*/
|
|
32
32
|
readonly throwIfNoResult?: boolean | {
|
|
33
33
|
message?: string;
|
|
34
|
-
httpStatusCode?: keyof typeof
|
|
34
|
+
httpStatusCode?: keyof typeof HTTP_STATUS_CODES | typeof HTTP_STATUS_CODES[keyof typeof HTTP_STATUS_CODES];
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* The transaction context for the query. ({@link Transaction})
|