@eqxjs/nest-logger 3.1.0-beta.12 → 3.1.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +646 -78
  2. package/dist/constants/action-message.constant.d.ts +171 -0
  3. package/dist/constants/action-message.constant.js +171 -0
  4. package/dist/constants/action-message.constant.js.map +1 -1
  5. package/dist/core/formatters/logger.formatter.d.ts +107 -0
  6. package/dist/core/formatters/logger.formatter.js +107 -0
  7. package/dist/core/formatters/logger.formatter.js.map +1 -1
  8. package/dist/core/loggers/app.logger.d.ts +33 -0
  9. package/dist/core/loggers/app.logger.js +51 -0
  10. package/dist/core/loggers/app.logger.js.map +1 -1
  11. package/dist/core/loggers/base-app.logger.js +2 -3
  12. package/dist/core/loggers/base-app.logger.js.map +1 -1
  13. package/dist/core/loggers/custom.logger.d.ts +111 -0
  14. package/dist/core/loggers/custom.logger.js +119 -0
  15. package/dist/core/loggers/custom.logger.js.map +1 -1
  16. package/dist/helpers/datetime.helper.d.ts +23 -0
  17. package/dist/helpers/datetime.helper.js +23 -0
  18. package/dist/helpers/datetime.helper.js.map +1 -1
  19. package/dist/helpers/log.helper.d.ts +81 -0
  20. package/dist/helpers/log.helper.js +81 -0
  21. package/dist/helpers/log.helper.js.map +1 -1
  22. package/dist/helpers/logger-builder.helper.d.ts +207 -2
  23. package/dist/helpers/logger-builder.helper.js +207 -2
  24. package/dist/helpers/logger-builder.helper.js.map +1 -1
  25. package/dist/helpers/message-formatter.helper.d.ts +74 -7
  26. package/dist/helpers/message-formatter.helper.js +74 -7
  27. package/dist/helpers/message-formatter.helper.js.map +1 -1
  28. package/dist/helpers/time-performance.helper.d.ts +61 -0
  29. package/dist/helpers/time-performance.helper.js +62 -1
  30. package/dist/helpers/time-performance.helper.js.map +1 -1
  31. package/dist/models/logger.dto.d.ts +43 -0
  32. package/dist/models/logger.dto.js +43 -0
  33. package/dist/models/logger.dto.js.map +1 -1
  34. package/package.json +1 -1
@@ -3,101 +3,265 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoggerDtoBuilder = void 0;
4
4
  const logger_dto_1 = require("../models/logger.dto");
5
5
  const logger_constants_1 = require("../constants/logger.constants");
6
+ /**
7
+ * LoggerDtoBuilder - Fluent builder for creating LoggerDto instances.
8
+ *
9
+ * Provides a chainable API for constructing logger data transfer objects with all necessary fields.
10
+ * Each setter method returns 'this' to enable method chaining. The builder pattern ensures
11
+ * consistent and readable construction of complex logger DTOs.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const dto = new LoggerDtoBuilder()
16
+ * .setLevel('info')
17
+ * .setTimestamp('2026-01-12T10:00:00.000Z')
18
+ * .setAppName('MyApp')
19
+ * .setComponentName('UserService')
20
+ * .setAction('[USER_CREATE]')
21
+ * .setMessage('User created successfully')
22
+ * .setSessionId('sess-123')
23
+ * .normalizeEmptyFields()
24
+ * .build();
25
+ * ```
26
+ */
6
27
  class LoggerDtoBuilder {
7
28
  dto;
29
+ /**
30
+ * Creates a new LoggerDtoBuilder instance with an empty LoggerDto.
31
+ */
8
32
  constructor() {
9
33
  this.dto = new logger_dto_1.LoggerDto();
10
34
  }
35
+ /**
36
+ * Sets the log level.
37
+ *
38
+ * @param level - Log level (e.g., 'debug', 'info', 'warn', 'error')
39
+ * @returns This builder instance for method chaining
40
+ */
11
41
  setLevel(level) {
12
42
  this.dto.level = level;
13
43
  return this;
14
44
  }
45
+ /**
46
+ * Sets the timestamp for the log entry.
47
+ *
48
+ * @param timestamp - ISO 8601 formatted timestamp string
49
+ * @returns This builder instance for method chaining
50
+ */
15
51
  setTimestamp(timestamp) {
16
52
  this.dto.timestamp = timestamp;
17
53
  return this;
18
54
  }
55
+ /**
56
+ * Sets the application name.
57
+ *
58
+ * @param appName - Name of the application
59
+ * @returns This builder instance for method chaining
60
+ */
19
61
  setAppName(appName) {
20
62
  this.dto.appName = appName;
21
63
  return this;
22
64
  }
65
+ /**
66
+ * Sets the component name (optional).
67
+ * Only sets the value if componentName is provided.
68
+ *
69
+ * @param componentName - Name of the component or service
70
+ * @returns This builder instance for method chaining
71
+ */
23
72
  setComponentName(componentName) {
24
73
  if (componentName) {
25
74
  this.dto.componentName = componentName;
26
75
  }
27
76
  return this;
28
77
  }
78
+ /**
79
+ * Sets the action tag for the log entry.
80
+ *
81
+ * @param action - Action identifier (e.g., '[HTTP_REQUEST]', '[DB_QUERY]')
82
+ * @returns This builder instance for method chaining
83
+ */
29
84
  setAction(action) {
30
85
  this.dto.action = action;
31
86
  return this;
32
87
  }
88
+ /**
89
+ * Sets the log message.
90
+ *
91
+ * @param message - The log message content
92
+ * @returns This builder instance for method chaining
93
+ */
33
94
  setMessage(message) {
34
95
  this.dto.message = message;
35
96
  return this;
36
97
  }
98
+ /**
99
+ * Sets the instance identifier (typically hostname or container ID).
100
+ *
101
+ * @param instance - Instance identifier
102
+ * @returns This builder instance for method chaining
103
+ */
37
104
  setInstance(instance) {
38
105
  this.dto.instance = instance;
39
106
  return this;
40
107
  }
108
+ /**
109
+ * Sets the originating service name.
110
+ *
111
+ * @param originateServiceName - Name of the service that originated the log
112
+ * @returns This builder instance for method chaining
113
+ */
41
114
  setOriginateServiceName(originateServiceName) {
42
115
  this.dto.originateServiceName = originateServiceName;
43
116
  return this;
44
117
  }
118
+ /**
119
+ * Sets the record name or identifier.
120
+ *
121
+ * @param recordName - Record identifier (e.g., order ID, user ID)
122
+ * @returns This builder instance for method chaining
123
+ */
45
124
  setRecordName(recordName) {
46
125
  this.dto.recordName = recordName;
47
126
  return this;
48
127
  }
128
+ /**
129
+ * Sets the record type (e.g., 'detail', 'summary').
130
+ *
131
+ * @param recordType - Type of the log record
132
+ * @returns This builder instance for method chaining
133
+ */
49
134
  setRecordType(recordType) {
50
135
  this.dto.recordType = recordType;
51
136
  return this;
52
137
  }
138
+ /**
139
+ * Sets the session identifier.
140
+ *
141
+ * @param sessionId - Session ID for tracking user sessions
142
+ * @returns This builder instance for method chaining
143
+ */
53
144
  setSessionId(sessionId) {
54
145
  this.dto.sessionId = sessionId;
55
146
  return this;
56
147
  }
148
+ /**
149
+ * Sets the transaction identifier.
150
+ *
151
+ * @param transactionId - Transaction ID for tracking distributed transactions
152
+ * @returns This builder instance for method chaining
153
+ */
57
154
  setTransactionId(transactionId) {
58
155
  this.dto.transactionId = transactionId;
59
156
  return this;
60
157
  }
158
+ /**
159
+ * Sets the communication channel.
160
+ *
161
+ * @param channel - Channel identifier (e.g., 'web', 'mobile', 'api')
162
+ * @returns This builder instance for method chaining
163
+ */
61
164
  setChannel(channel) {
62
165
  this.dto.channel = channel;
63
166
  return this;
64
167
  }
168
+ /**
169
+ * Sets the component version.
170
+ *
171
+ * @param componentVersion - Version of the component (e.g., '1.0.0')
172
+ * @returns This builder instance for method chaining
173
+ */
65
174
  setComponentVersion(componentVersion) {
66
175
  this.dto.componentVersion = componentVersion;
67
176
  return this;
68
177
  }
178
+ /**
179
+ * Sets the use case name.
180
+ *
181
+ * @param useCase - Name of the use case being executed
182
+ * @returns This builder instance for method chaining
183
+ */
69
184
  setUseCase(useCase) {
70
185
  this.dto.useCase = useCase;
71
186
  return this;
72
187
  }
188
+ /**
189
+ * Sets the use case step.
190
+ *
191
+ * @param useCaseStep - Specific step within the use case
192
+ * @returns This builder instance for method chaining
193
+ */
73
194
  setUseCaseStep(useCaseStep) {
74
195
  this.dto.useCaseStep = useCaseStep;
75
196
  return this;
76
197
  }
198
+ /**
199
+ * Sets the user identifier.
200
+ *
201
+ * @param user - User identifier (e.g., email, username, user ID)
202
+ * @returns This builder instance for method chaining
203
+ */
77
204
  setUser(user) {
78
205
  this.dto.user = user;
79
206
  return this;
80
207
  }
208
+ /**
209
+ * Sets the device identifier(s).
210
+ *
211
+ * @param device - Single device identifier or array of identifiers
212
+ * @returns This builder instance for method chaining
213
+ */
81
214
  setDevice(device) {
82
215
  this.dto.device = device;
83
216
  return this;
84
217
  }
218
+ /**
219
+ * Sets the public identifier(s).
220
+ *
221
+ * @param public_ - Single public identifier or array of identifiers
222
+ * @returns This builder instance for method chaining
223
+ */
85
224
  setPublic(public_) {
86
225
  this.dto.public = public_;
87
226
  return this;
88
227
  }
228
+ /**
229
+ * Sets the application result description.
230
+ *
231
+ * @param appResult - Result description (e.g., 'Success', 'Failed')
232
+ * @returns This builder instance for method chaining
233
+ */
89
234
  setAppResult(appResult) {
90
235
  this.dto.appResult = appResult;
91
236
  return this;
92
237
  }
238
+ /**
239
+ * Sets the application result code.
240
+ *
241
+ * @param appResultCode - Result code (e.g., '200', '500', 'ERR_001')
242
+ * @returns This builder instance for method chaining
243
+ */
93
244
  setAppResultCode(appResultCode) {
94
245
  this.dto.appResultCode = appResultCode;
95
246
  return this;
96
247
  }
248
+ /**
249
+ * Sets the service processing time in milliseconds.
250
+ *
251
+ * @param serviceTime - Processing duration in milliseconds
252
+ * @returns This builder instance for method chaining
253
+ */
97
254
  setServiceTime(serviceTime) {
98
255
  this.dto.serviceTime = serviceTime;
99
256
  return this;
100
257
  }
258
+ /**
259
+ * Sets the error stack trace (optional).
260
+ * Only sets the value if stack is provided and not empty.
261
+ *
262
+ * @param stack - Array of stack trace lines
263
+ * @returns This builder instance for method chaining
264
+ */
101
265
  setStack(stack) {
102
266
  if (stack) {
103
267
  this.dto.stack = stack;
@@ -105,7 +269,21 @@ class LoggerDtoBuilder {
105
269
  return this;
106
270
  }
107
271
  /**
108
- * Replace empty strings with 'none'
272
+ * Normalizes empty string fields by replacing them with DEFAULT_VALUES.NONE ('none').
273
+ *
274
+ * Iterates through all DTO properties and replaces any empty string values
275
+ * with the default 'none' value for consistency in log output.
276
+ *
277
+ * @returns This builder instance for method chaining
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * const dto = new LoggerDtoBuilder()
282
+ * .setLevel('info')
283
+ * .setMessage('') // Empty string
284
+ * .normalizeEmptyFields() // Converts empty string to 'none'
285
+ * .build();
286
+ * ```
109
287
  */
110
288
  normalizeEmptyFields() {
111
289
  Object.keys(this.dto).forEach((key) => {
@@ -117,7 +295,21 @@ class LoggerDtoBuilder {
117
295
  return this;
118
296
  }
119
297
  /**
120
- * Merge additional options into the DTO
298
+ * Merges additional options into the DTO.
299
+ *
300
+ * Takes an optional object of additional fields and merges them into the DTO.
301
+ * Empty string values in the options are normalized to DEFAULT_VALUES.NONE.
302
+ *
303
+ * @param opt - Optional record of additional fields to merge
304
+ * @returns This builder instance for method chaining
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const dto = new LoggerDtoBuilder()
309
+ * .setLevel('info')
310
+ * .mergeOptions({ broker: 'kafka', customField: 'value' })
311
+ * .build();
312
+ * ```
121
313
  */
122
314
  mergeOptions(opt) {
123
315
  if (opt) {
@@ -131,6 +323,19 @@ class LoggerDtoBuilder {
131
323
  }
132
324
  return this;
133
325
  }
326
+ /**
327
+ * Builds and returns the final LoggerDto instance.
328
+ *
329
+ * @returns The constructed LoggerDto object
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * const dto = new LoggerDtoBuilder()
334
+ * .setLevel('info')
335
+ * .setMessage('Test message')
336
+ * .build();
337
+ * ```
338
+ */
134
339
  build() {
135
340
  return this.dto;
136
341
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger-builder.helper.js","sourceRoot":"","sources":["../../src/helpers/logger-builder.helper.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,oEAA+D;AAE/D,MAAa,gBAAgB;IACnB,GAAG,CAAY;IAEvB;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,sBAAS,EAAE,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,CAAC,SAAiB;QAC5B,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,G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IACH,oBAAoB;QAClB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;gBAC9C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,iCAAc,CAAC,IAAI,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,GAA6B;QACxC,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,aAAa,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzC,IAAI,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;oBACxE,aAAa,CAAC,GAAG,CAAC,GAAG,iCAAc,CAAC,IAAI,CAAC;gBAC3C,CAAC;YACH,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AA9JD,4CA8JC"}
1
+ {"version":3,"file":"logger-builder.helper.js","sourceRoot":"","sources":["../../src/helpers/logger-builder.helper.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,oEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,gBAAgB;IACnB,GAAG,CAAY;IAEvB;;OAEG;IACH;QACE,IAAI,CAAC,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;YACjC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzC,IAAI,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;oBACxE,aAAa,CAAC,GAAG,CAAC,GAAG,iCAAc,CAAC,IAAI,CAAC;gBAC3C,CAAC;YACH,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AAtVD,4CAsVC"}
@@ -1,20 +1,87 @@
1
1
  /**
2
- * Format a message of any type to string
3
- * Optimized for common cases (strings) for better performance
2
+ * Formats a message of any type to string representation.
3
+ *
4
+ * Optimized for performance with fast paths for common cases (strings, numbers).
5
+ * Handles various input types:
6
+ * - Strings: returned as-is (fast path)
7
+ * - Numbers: converted to string
8
+ * - Functions: executed and result converted to string
9
+ * - null/undefined: returns empty string
10
+ * - Objects: JSON stringified with sensitive field masking
11
+ *
12
+ * @param message - The message to format (can be any type)
13
+ * @returns String representation of the message
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * formatMessage('Hello'); // "Hello"
18
+ * formatMessage(123); // "123"
19
+ * formatMessage({ key: 'value' }); // "{\"key\":\"value\"}"
20
+ * formatMessage(null); // ""
21
+ * formatMessage(() => 'computed'); // "computed"
22
+ * ```
4
23
  */
5
24
  export declare function formatMessage(message: any): string;
6
25
  /**
7
- * Set value or return default 'none'
8
- * Optimized for performance with faster checks
26
+ * Returns the provided value or the default 'none' string if the value is empty.
27
+ *
28
+ * Optimized for performance with faster checks. Returns DEFAULT_VALUES.NONE if:
29
+ * - value is undefined
30
+ * - value is an empty string
31
+ * - value has length of 0
32
+ *
33
+ * @param value - The value to check (optional string)
34
+ * @returns The original value if non-empty, or DEFAULT_VALUES.NONE ('none')
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * setValueOrDefault('test'); // "test"
39
+ * setValueOrDefault(''); // "none"
40
+ * setValueOrDefault(undefined); // "none"
41
+ * setValueOrDefault(' '); // " " (whitespace is considered non-empty)
42
+ * ```
9
43
  */
10
44
  export declare function setValueOrDefault(value?: string): string;
11
45
  /**
12
- * Truncate message if it exceeds max length
13
- * Optimized with early return for messages within limit
46
+ * Truncates a message if it exceeds the specified maximum length.
47
+ *
48
+ * Optimized with early return for messages within the limit. Adds '...' to indicate truncation.
49
+ * Uses DEFAULT_VALUES.MAX_MESSAGE_LENGTH as the default limit.
50
+ *
51
+ * @param message - The message string to truncate
52
+ * @param maxLength - Maximum allowed length (default: DEFAULT_VALUES.MAX_MESSAGE_LENGTH)
53
+ * @returns The original message if within limit, or truncated message with '...' appended
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * truncateMessage('Short', 100); // "Short"
58
+ * truncateMessage('A very long message...', 10); // "A very lon..."
59
+ * truncateMessage('Hello World'); // Uses default max length
60
+ * ```
14
61
  */
15
62
  export declare function truncateMessage(message: string, maxLength?: number): string;
16
63
  /**
17
- * Merge broker option into LoggerOpt
64
+ * Merges broker information into a LoggerOpt object.
65
+ *
66
+ * Creates a new object with the broker field merged in. If opt is provided,
67
+ * spreads its properties and adds/overwrites the broker field. If opt is undefined,
68
+ * creates a new object with only the broker field.
69
+ *
70
+ * @param opt - Optional configuration object to merge with
71
+ * @param broker - Broker identifier to add to the configuration
72
+ * @returns New object with broker field merged in
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // With existing options
77
+ * const opts = { customField: 'value' };
78
+ * mergeBrokerOption(opts, 'kafka');
79
+ * // Result: { customField: 'value', broker: 'kafka' }
80
+ *
81
+ * // Without existing options
82
+ * mergeBrokerOption(undefined, 'rabbitmq');
83
+ * // Result: { broker: 'rabbitmq' }
84
+ * ```
18
85
  */
19
86
  export declare function mergeBrokerOption<T extends {
20
87
  broker?: string;
@@ -40,8 +40,27 @@ exports.mergeBrokerOption = mergeBrokerOption;
40
40
  const logger_constants_1 = require("../constants/logger.constants");
41
41
  const logUtil = __importStar(require("./log.helper"));
42
42
  /**
43
- * Format a message of any type to string
44
- * Optimized for common cases (strings) for better performance
43
+ * Formats a message of any type to string representation.
44
+ *
45
+ * Optimized for performance with fast paths for common cases (strings, numbers).
46
+ * Handles various input types:
47
+ * - Strings: returned as-is (fast path)
48
+ * - Numbers: converted to string
49
+ * - Functions: executed and result converted to string
50
+ * - null/undefined: returns empty string
51
+ * - Objects: JSON stringified with sensitive field masking
52
+ *
53
+ * @param message - The message to format (can be any type)
54
+ * @returns String representation of the message
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * formatMessage('Hello'); // "Hello"
59
+ * formatMessage(123); // "123"
60
+ * formatMessage({ key: 'value' }); // "{\"key\":\"value\"}"
61
+ * formatMessage(null); // ""
62
+ * formatMessage(() => 'computed'); // "computed"
63
+ * ```
45
64
  */
46
65
  function formatMessage(message) {
47
66
  // Fast path for most common case
@@ -63,15 +82,43 @@ function formatMessage(message) {
63
82
  return logUtil.logStringify(message);
64
83
  }
65
84
  /**
66
- * Set value or return default 'none'
67
- * Optimized for performance with faster checks
85
+ * Returns the provided value or the default 'none' string if the value is empty.
86
+ *
87
+ * Optimized for performance with faster checks. Returns DEFAULT_VALUES.NONE if:
88
+ * - value is undefined
89
+ * - value is an empty string
90
+ * - value has length of 0
91
+ *
92
+ * @param value - The value to check (optional string)
93
+ * @returns The original value if non-empty, or DEFAULT_VALUES.NONE ('none')
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * setValueOrDefault('test'); // "test"
98
+ * setValueOrDefault(''); // "none"
99
+ * setValueOrDefault(undefined); // "none"
100
+ * setValueOrDefault(' '); // " " (whitespace is considered non-empty)
101
+ * ```
68
102
  */
69
103
  function setValueOrDefault(value) {
70
104
  return (value && value.length > 0) ? value : logger_constants_1.DEFAULT_VALUES.NONE;
71
105
  }
72
106
  /**
73
- * Truncate message if it exceeds max length
74
- * Optimized with early return for messages within limit
107
+ * Truncates a message if it exceeds the specified maximum length.
108
+ *
109
+ * Optimized with early return for messages within the limit. Adds '...' to indicate truncation.
110
+ * Uses DEFAULT_VALUES.MAX_MESSAGE_LENGTH as the default limit.
111
+ *
112
+ * @param message - The message string to truncate
113
+ * @param maxLength - Maximum allowed length (default: DEFAULT_VALUES.MAX_MESSAGE_LENGTH)
114
+ * @returns The original message if within limit, or truncated message with '...' appended
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * truncateMessage('Short', 100); // "Short"
119
+ * truncateMessage('A very long message...', 10); // "A very lon..."
120
+ * truncateMessage('Hello World'); // Uses default max length
121
+ * ```
75
122
  */
76
123
  function truncateMessage(message, maxLength = logger_constants_1.DEFAULT_VALUES.MAX_MESSAGE_LENGTH) {
77
124
  // Fast path: most messages are within limit
@@ -81,7 +128,27 @@ function truncateMessage(message, maxLength = logger_constants_1.DEFAULT_VALUES.
81
128
  return message.substring(0, maxLength) + '...';
82
129
  }
83
130
  /**
84
- * Merge broker option into LoggerOpt
131
+ * Merges broker information into a LoggerOpt object.
132
+ *
133
+ * Creates a new object with the broker field merged in. If opt is provided,
134
+ * spreads its properties and adds/overwrites the broker field. If opt is undefined,
135
+ * creates a new object with only the broker field.
136
+ *
137
+ * @param opt - Optional configuration object to merge with
138
+ * @param broker - Broker identifier to add to the configuration
139
+ * @returns New object with broker field merged in
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // With existing options
144
+ * const opts = { customField: 'value' };
145
+ * mergeBrokerOption(opts, 'kafka');
146
+ * // Result: { customField: 'value', broker: 'kafka' }
147
+ *
148
+ * // Without existing options
149
+ * mergeBrokerOption(undefined, 'rabbitmq');
150
+ * // Result: { broker: 'rabbitmq' }
151
+ * ```
85
152
  */
86
153
  function mergeBrokerOption(opt, broker) {
87
154
  if (opt) {
@@ -1 +1 @@
1
- {"version":3,"file":"message-formatter.helper.js","sourceRoot":"","sources":["../../src/helpers/message-formatter.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,sCAsBC;AAMD,8CAEC;AAMD,0CAMC;AAKD,8CAQC;AA9DD,oEAA+D;AAC/D,sDAAwC;AAExC;;;GAGG;AACH,SAAgB,aAAa,CAAC,OAAY;IACxC,iCAAiC;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,qBAAqB;IACrB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sCAAsC;IACtC,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,iCAAc,CAAC,IAAI,CAAC;AACnE,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,YAAoB,iCAAc,CAAC,kBAAkB;IACpG,4CAA4C;IAC5C,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,GAAkB,EAClB,MAAe;IAEf,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,MAAM,EAAO,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"message-formatter.helper.js","sourceRoot":"","sources":["../../src/helpers/message-formatter.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,sCAsBC;AAqBD,8CAEC;AAmBD,0CAMC;AAyBD,8CAQC;AAjID,oEAA+D;AAC/D,sDAAwC;AAExC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,aAAa,CAAC,OAAY;IACxC,iCAAiC;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,qBAAqB;IACrB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sCAAsC;IACtC,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,iCAAc,CAAC,IAAI,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,YAAoB,iCAAc,CAAC,kBAAkB;IACpG,4CAA4C;IAC5C,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,iBAAiB,CAC/B,GAAkB,EAClB,MAAe;IAEf,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,MAAM,EAAO,CAAC;AACzB,CAAC"}
@@ -1,7 +1,68 @@
1
+ /**
2
+ * TimeDiff - High-resolution timer for measuring elapsed time.
3
+ *
4
+ * Uses Node.js performance API to provide precise time measurements in milliseconds.
5
+ * Useful for tracking operation duration, performance monitoring, and logging service times.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const timer = new TimeDiff();
10
+ * await someOperation();
11
+ * const duration = timer.diff();
12
+ * console.log(`Operation took ${duration}ms`);
13
+ * ```
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Using static start method
18
+ * const timer = TimeDiff.start();
19
+ * processData();
20
+ * console.log(`Elapsed: ${timer.end()}ms`);
21
+ * ```
22
+ */
1
23
  export declare class TimeDiff {
2
24
  private startTime;
25
+ /**
26
+ * Creates a new TimeDiff instance and starts the timer.
27
+ * The start time is captured immediately using high-resolution performance timer.
28
+ */
3
29
  constructor();
30
+ /**
31
+ * Static factory method to create and start a new timer instance.
32
+ *
33
+ * @returns A new TimeDiff instance with the timer started
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const timer = TimeDiff.start();
38
+ * ```
39
+ */
4
40
  static start(): TimeDiff;
41
+ /**
42
+ * Calculates and returns the elapsed time since the timer was started.
43
+ * Returns the duration in milliseconds with 3 decimal places precision.
44
+ *
45
+ * @returns Elapsed time in milliseconds (e.g., 123.456)
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const timer = new TimeDiff();
50
+ * await operation();
51
+ * const ms = timer.diff(); // e.g., 150.234
52
+ * ```
53
+ */
5
54
  diff(): number;
55
+ /**
56
+ * Alias for diff() method. Returns the elapsed time since the timer was started.
57
+ *
58
+ * @returns Elapsed time in milliseconds
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const timer = TimeDiff.start();
63
+ * processData();
64
+ * const duration = timer.end();
65
+ * ```
66
+ */
6
67
  end(): number;
7
68
  }