@org-quicko/core 1.1.0 → 2.0.0
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/README.md +7 -7
- package/dist/browser/beans/BaseObject.js.map +1 -1
- package/dist/browser/exceptions/BadRequestException.js.map +1 -1
- package/dist/browser/exceptions/BaseException.js +1 -21
- package/dist/browser/exceptions/BaseException.js.map +1 -1
- package/dist/browser/exceptions/ClientException.js.map +1 -1
- package/dist/browser/exceptions/ConverterException.js.map +1 -1
- package/dist/browser/exceptions/ForbiddenAccessException.js.map +1 -1
- package/dist/browser/exceptions/HTTPException.js.map +1 -1
- package/dist/browser/exceptions/IllegalArgumentException.js.map +1 -1
- package/dist/browser/exceptions/UnauthorizedException.js.map +1 -1
- package/dist/browser/types/JSONObject.js.map +1 -1
- package/dist/browser/types/LoggingLevel.js.map +1 -1
- package/dist/browser/types/SortOrder.js.map +1 -1
- package/dist/browser/utils/date/DateUtil.js +3 -40
- package/dist/browser/utils/date/DateUtil.js.map +1 -1
- package/dist/cjs/beans/BaseObject.cjs.map +1 -1
- package/dist/cjs/build/node/index.cjs +0 -1
- package/dist/cjs/build/node/index.cjs.map +1 -1
- package/dist/cjs/exceptions/BadRequestException.cjs.map +1 -1
- package/dist/cjs/exceptions/BaseException.cjs +1 -21
- package/dist/cjs/exceptions/BaseException.cjs.map +1 -1
- package/dist/cjs/exceptions/ClientException.cjs.map +1 -1
- package/dist/cjs/exceptions/ConverterException.cjs.map +1 -1
- package/dist/cjs/exceptions/ForbiddenAccessException.cjs.map +1 -1
- package/dist/cjs/exceptions/HTTPException.cjs.map +1 -1
- package/dist/cjs/exceptions/IllegalArgumentException.cjs.map +1 -1
- package/dist/cjs/exceptions/UnauthorizedException.cjs.map +1 -1
- package/dist/cjs/logger/LoggerFactory.cjs +96 -22
- package/dist/cjs/logger/LoggerFactory.cjs.map +1 -1
- package/dist/cjs/logger/format/ErrorFormat.cjs +115 -0
- package/dist/cjs/logger/format/ErrorFormat.cjs.map +1 -0
- package/dist/cjs/logger/index.cjs +0 -1
- package/dist/cjs/logger/index.cjs.map +1 -1
- package/dist/cjs/types/JSONObject.cjs.map +1 -1
- package/dist/cjs/types/LoggingLevel.cjs.map +1 -1
- package/dist/cjs/types/SortOrder.cjs.map +1 -1
- package/dist/cjs/utils/date/DateUtil.cjs +3 -40
- package/dist/cjs/utils/date/DateUtil.cjs.map +1 -1
- package/dist/esm/beans/BaseObject.js.map +1 -1
- package/dist/esm/build/node/index.js +1 -1
- package/dist/esm/exceptions/BadRequestException.js.map +1 -1
- package/dist/esm/exceptions/BaseException.js +1 -21
- package/dist/esm/exceptions/BaseException.js.map +1 -1
- package/dist/esm/exceptions/ClientException.js.map +1 -1
- package/dist/esm/exceptions/ConverterException.js.map +1 -1
- package/dist/esm/exceptions/ForbiddenAccessException.js.map +1 -1
- package/dist/esm/exceptions/HTTPException.js.map +1 -1
- package/dist/esm/exceptions/IllegalArgumentException.js.map +1 -1
- package/dist/esm/exceptions/UnauthorizedException.js.map +1 -1
- package/dist/esm/logger/LoggerFactory.js +97 -22
- package/dist/esm/logger/LoggerFactory.js.map +1 -1
- package/dist/esm/logger/format/ErrorFormat.js +113 -0
- package/dist/esm/logger/format/ErrorFormat.js.map +1 -0
- package/dist/esm/logger/index.js +1 -1
- package/dist/esm/types/JSONObject.js.map +1 -1
- package/dist/esm/types/LoggingLevel.js.map +1 -1
- package/dist/esm/types/SortOrder.js.map +1 -1
- package/dist/esm/utils/date/DateUtil.js +3 -40
- package/dist/esm/utils/date/DateUtil.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/src/exceptions/BaseException.d.ts +0 -6
- package/dist/types/src/logger/LoggerFactory.d.ts +88 -10
- package/dist/types/src/logger/index.d.ts +1 -1
- package/dist/types/src/utils/date/DateUtil.d.ts +9 -52
- package/package.json +140 -136
|
@@ -1,44 +1,118 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var winston = require('winston');
|
|
4
|
-
var
|
|
4
|
+
var BaseException = require('../exceptions/BaseException.cjs');
|
|
5
|
+
var ErrorFormat = require('./format/ErrorFormat.cjs');
|
|
5
6
|
var LoggingLevel = require('../types/LoggingLevel.cjs');
|
|
6
7
|
require('../types/SortOrder.cjs');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Factory class for creating and managing Winston logger instances.
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* Provides a factory for creating Winston logger instances with consistent configuration.
|
|
14
|
+
* Supports custom logging levels, formats, and transports with a default format pipeline
|
|
15
|
+
* that includes timestamp, error handling with cause chains, and JSON formatting.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Create a logger with custom configuration
|
|
20
|
+
* const logger = LoggerFactory.createLogger({
|
|
21
|
+
* level: 'info',
|
|
22
|
+
* transports: [new winston.transports.Console()]
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Create another logger and add a label to it
|
|
26
|
+
* const apiLogger = LoggerFactory.getLogger('api-service');
|
|
27
|
+
* apiLogger.info('Server started');
|
|
28
|
+
* ```
|
|
11
29
|
*/
|
|
12
|
-
const loggers = new Map();
|
|
13
30
|
class LoggerFactory {
|
|
14
31
|
/**
|
|
15
|
-
*
|
|
32
|
+
* Creates and initializes a new logger instance with the provided configuration.
|
|
16
33
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
34
|
+
* @description
|
|
35
|
+
* Creates a new Winston logger with a consistent default format pipeline that includes
|
|
36
|
+
* timestamp, error handling with stack traces and cause chains, custom error formatting,
|
|
37
|
+
* and JSON output. Custom formats are combined with the defaults. If no transports are
|
|
38
|
+
* specified, defaults to Console transport.
|
|
39
|
+
*
|
|
40
|
+
* @param {LoggerOptions} [options] - Optional Winston logger configuration options
|
|
41
|
+
* @param {LoggingLevel} [options.level='info'] - Logging level (error, warn, info, http, debug, verbose, silly)
|
|
42
|
+
* @param {winston.LogFormat} [options.format] - Additional custom format to combine with defaults
|
|
43
|
+
* @param {object} [options.defaultMeta] - Default metadata to include in all log entries from this logger
|
|
44
|
+
* @param {winston.transport[]} [options.transports] - Transport instances (defaults to Console)
|
|
45
|
+
*
|
|
46
|
+
* @returns {winston.Logger} Configured logger instance
|
|
47
|
+
*
|
|
48
|
+
* @throws {BaseException} If logger initialization fails
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Create a logger with custom configuration
|
|
53
|
+
* const logger = LoggerFactory.createLogger({
|
|
54
|
+
* level: 'debug',
|
|
55
|
+
* defaultMeta: { service: 'api' },
|
|
56
|
+
* transports: [
|
|
57
|
+
* new winston.transports.Console(),
|
|
58
|
+
* new winston.transports.File({ filename: 'combined.log' })
|
|
59
|
+
* ]
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
19
62
|
*/
|
|
20
|
-
static createLogger(
|
|
21
|
-
const label = typeof name === "string" ? name : "Unknown";
|
|
22
|
-
if (loggers.has(label)) {
|
|
23
|
-
return loggers.get(label);
|
|
24
|
-
}
|
|
63
|
+
static createLogger(options) {
|
|
25
64
|
try {
|
|
26
|
-
const defaultFormat = winston.format.combine(winston.format.timestamp(), winston.format.json());
|
|
27
|
-
|
|
28
|
-
level: level,
|
|
29
|
-
format: format
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
const defaultFormat = winston.format.combine(winston.format.timestamp(), winston.format.errors({ stack: true, cause: true }), ErrorFormat.ErrorFormat(), winston.format.json());
|
|
66
|
+
LoggerFactory.logger = winston.createLogger({
|
|
67
|
+
level: options?.level ?? LoggingLevel.LoggingLevel.info,
|
|
68
|
+
format: options?.format
|
|
69
|
+
? winston.format.combine(options.format, defaultFormat)
|
|
70
|
+
: defaultFormat,
|
|
71
|
+
defaultMeta: options?.defaultMeta,
|
|
72
|
+
transports: options?.transports
|
|
73
|
+
? options.transports
|
|
74
|
+
: [new winston.transports.Console()],
|
|
32
75
|
});
|
|
33
|
-
|
|
34
|
-
return logger;
|
|
76
|
+
return LoggerFactory.logger;
|
|
35
77
|
}
|
|
36
78
|
catch (error) {
|
|
37
|
-
throw new
|
|
79
|
+
throw new BaseException.BaseException(`Error creating logger`, error, 500);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets a logger instance with a label added to the metadata.
|
|
84
|
+
*
|
|
85
|
+
* @description
|
|
86
|
+
* Returns a logger instance that is a child of the base logger with the provided label
|
|
87
|
+
* added as metadata. Each call creates a new child logger with the specified label.
|
|
88
|
+
* This is useful for identifying the source of log messages by module or service name.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} label - Unique identifier for the logger to include in metadata (e.g., module name, service name)
|
|
91
|
+
*
|
|
92
|
+
* @returns {winston.Logger} Child logger instance with the label in metadata
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Create a logger with a label for the UserService module
|
|
97
|
+
* const logger = LoggerFactory.getLogger('UserService');
|
|
98
|
+
*
|
|
99
|
+
* // Another module can create its own labeled logger
|
|
100
|
+
* const apiLogger = LoggerFactory.getLogger('APIHandler');
|
|
101
|
+
*
|
|
102
|
+
* logger.info('Processing user request'); // Log includes { label: 'UserService' }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
static getLogger(label) {
|
|
106
|
+
let baseLogger;
|
|
107
|
+
if (LoggerFactory.logger) {
|
|
108
|
+
baseLogger = LoggerFactory.logger;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
baseLogger = LoggerFactory.createLogger();
|
|
38
112
|
}
|
|
113
|
+
return baseLogger.child({ label });
|
|
39
114
|
}
|
|
40
115
|
}
|
|
41
116
|
|
|
42
117
|
exports.LoggerFactory = LoggerFactory;
|
|
43
|
-
exports.loggers = loggers;
|
|
44
118
|
//# sourceMappingURL=LoggerFactory.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggerFactory.cjs","sources":["../../../src/logger/LoggerFactory.ts"],"sourcesContent":["import winston from \"winston\";\
|
|
1
|
+
{"version":3,"file":"LoggerFactory.cjs","sources":["../../../src/logger/LoggerFactory.ts"],"sourcesContent":["import winston, { Logger, LoggerOptions } from \"winston\";\nimport { BaseException } from \"../exceptions\";\nimport { ErrorFormat } from \"./format/ErrorFormat\";\nimport { LoggingLevel } from \"../types\";\n\n/**\n * Factory class for creating and managing Winston logger instances.\n *\n * @description\n * Provides a factory for creating Winston logger instances with consistent configuration.\n * Supports custom logging levels, formats, and transports with a default format pipeline\n * that includes timestamp, error handling with cause chains, and JSON formatting.\n *\n * @example\n * ```typescript\n * // Create a logger with custom configuration\n * const logger = LoggerFactory.createLogger({\n * level: 'info',\n * transports: [new winston.transports.Console()]\n * });\n *\n * // Create another logger and add a label to it\n * const apiLogger = LoggerFactory.getLogger('api-service');\n * apiLogger.info('Server started');\n * ```\n */\nexport class LoggerFactory {\n /**\n * Base logger instance used by the factory.\n *\n * @description\n * Currently stores a single base logger instance per execution context.\n * This design can be extended in the future to support multiple base loggers\n * by replacing this single instance with a Map-based container (similar to Winston's Container API)\n * to manage multiple named logger configurations.\n *\n * @type {winston.Logger}\n * @private\n */\n private static logger: winston.Logger;\n\n /**\n * Creates and initializes a new logger instance with the provided configuration.\n *\n * @description\n * Creates a new Winston logger with a consistent default format pipeline that includes\n * timestamp, error handling with stack traces and cause chains, custom error formatting,\n * and JSON output. Custom formats are combined with the defaults. If no transports are\n * specified, defaults to Console transport.\n *\n * @param {LoggerOptions} [options] - Optional Winston logger configuration options\n * @param {LoggingLevel} [options.level='info'] - Logging level (error, warn, info, http, debug, verbose, silly)\n * @param {winston.LogFormat} [options.format] - Additional custom format to combine with defaults\n * @param {object} [options.defaultMeta] - Default metadata to include in all log entries from this logger\n * @param {winston.transport[]} [options.transports] - Transport instances (defaults to Console)\n *\n * @returns {winston.Logger} Configured logger instance\n *\n * @throws {BaseException} If logger initialization fails\n *\n * @example\n * ```typescript\n * // Create a logger with custom configuration\n * const logger = LoggerFactory.createLogger({\n * level: 'debug',\n * defaultMeta: { service: 'api' },\n * transports: [\n * new winston.transports.Console(),\n * new winston.transports.File({ filename: 'combined.log' })\n * ]\n * });\n * ```\n */\n static createLogger(options?: LoggerOptions): winston.Logger {\n try {\n const defaultFormat = winston.format.combine(\n winston.format.timestamp(),\n winston.format.errors({ stack: true, cause: true }),\n ErrorFormat(),\n winston.format.json()\n );\n\n LoggerFactory.logger = winston.createLogger({\n level: options?.level ?? LoggingLevel.info,\n format: options?.format\n ? winston.format.combine(options.format, defaultFormat)\n : defaultFormat,\n defaultMeta: options?.defaultMeta,\n transports: options?.transports\n ? options.transports\n : [new winston.transports.Console()],\n });\n\n return LoggerFactory.logger;\n } catch (error) {\n throw new BaseException(`Error creating logger`, error, 500);\n }\n }\n\n /**\n * Gets a logger instance with a label added to the metadata.\n *\n * @description\n * Returns a logger instance that is a child of the base logger with the provided label\n * added as metadata. Each call creates a new child logger with the specified label.\n * This is useful for identifying the source of log messages by module or service name.\n *\n * @param {string} label - Unique identifier for the logger to include in metadata (e.g., module name, service name)\n *\n * @returns {winston.Logger} Child logger instance with the label in metadata\n *\n * @example\n * ```typescript\n * // Create a logger with a label for the UserService module\n * const logger = LoggerFactory.getLogger('UserService');\n *\n * // Another module can create its own labeled logger\n * const apiLogger = LoggerFactory.getLogger('APIHandler');\n *\n * logger.info('Processing user request'); // Log includes { label: 'UserService' }\n * ```\n */\n static getLogger(label: string): winston.Logger {\n let baseLogger: winston.Logger;\n if (LoggerFactory.logger) {\n baseLogger = LoggerFactory.logger!;\n } else {\n baseLogger = LoggerFactory.createLogger();\n }\n\n return baseLogger.child({ label });\n }\n \n}\n"],"names":["ErrorFormat","LoggingLevel","BaseException"],"mappings":";;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;AAoBG;MACU,aAAa,CAAA;AAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG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;;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var winston = require('winston');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Winston log format for handling Error objects with cause chains.
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* ES2022 supports adding a `cause` property to Error objects for better error context.
|
|
10
|
+
* While `console.log(err)` prints the entire cause chain automatically, Winston only logs
|
|
11
|
+
* the top-level error, losing the cause chain context.
|
|
12
|
+
*
|
|
13
|
+
* This format ensures that error cause chains are fully serialized and included in log output,
|
|
14
|
+
* preserving the complete error context for better debugging and error tracking.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause | MDN: Error.cause}
|
|
17
|
+
* @see {@link https://github.com/winstonjs/winston/issues/2533 | Winston Issue #2533}
|
|
18
|
+
*
|
|
19
|
+
* @param {TransformableInfo} info - The log entry information from Winston
|
|
20
|
+
* @returns {TransformableInfo} The formatted log entry with serialized error chains
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const logger = winston.createLogger({
|
|
25
|
+
* format: winston.format.combine(
|
|
26
|
+
* ErrorFormat,
|
|
27
|
+
* winston.format.json()
|
|
28
|
+
* ),
|
|
29
|
+
* transports: [new winston.transports.Console()]
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* try {
|
|
33
|
+
* throw new Error("Original error");
|
|
34
|
+
* } catch (err) {
|
|
35
|
+
* throw new Error("Wrapper error", { cause: err });
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
const ErrorFormat = winston.format((info) => {
|
|
40
|
+
// If the log entry itself is an error
|
|
41
|
+
if (info instanceof Error) {
|
|
42
|
+
const seen = new WeakSet();
|
|
43
|
+
const serialized = serialize(info, seen);
|
|
44
|
+
// Preserve Winston semantics by setting standard error properties
|
|
45
|
+
info.message = serialized.message;
|
|
46
|
+
info.stack = serialized.stack;
|
|
47
|
+
info.cause = serialized.cause;
|
|
48
|
+
// Copy all other enumerable properties from serialized error
|
|
49
|
+
for (const key of Object.keys(serialized)) {
|
|
50
|
+
if (!["message", "stack", "name", "cause"].includes(key)) {
|
|
51
|
+
info[key] = serialized[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return info;
|
|
55
|
+
}
|
|
56
|
+
// For normal log entries, serialize any nested error fields
|
|
57
|
+
const seen = new WeakSet();
|
|
58
|
+
for (const key of Object.keys(info)) {
|
|
59
|
+
info[key] = serialize(info[key], seen);
|
|
60
|
+
}
|
|
61
|
+
return info;
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Recursively serializes values that may contain Error objects.
|
|
65
|
+
*
|
|
66
|
+
* @description
|
|
67
|
+
* Handles all types of values including Error instances, nested objects, arrays,
|
|
68
|
+
* and primitives. Ensures that Error objects are fully serialized with their
|
|
69
|
+
* stack traces, messages, and cause chains preserved. Includes circular reference
|
|
70
|
+
* detection to prevent infinite recursion.
|
|
71
|
+
*
|
|
72
|
+
* @param {any} value - The value to serialize. Can be any type (Error, object, array, primitive)
|
|
73
|
+
* @param {WeakSet<object>} seen - Set tracking objects already visited to detect circular references
|
|
74
|
+
* @returns {any} The serialized value with all Error objects converted to plain objects
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const error = new Error("Test");
|
|
79
|
+
* const seen = new WeakSet<object>();
|
|
80
|
+
* const serialized = serialize(error, seen);
|
|
81
|
+
* // Returns: { message: "Test", name: "Error", stack: "...", cause: undefined }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function serialize(value, seen = new WeakSet()) {
|
|
85
|
+
// Handle null/undefined
|
|
86
|
+
if (value == null) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
// Error instance - convert to serializable object
|
|
90
|
+
if (value instanceof Error) {
|
|
91
|
+
// Check for circular reference
|
|
92
|
+
if (seen.has(value)) {
|
|
93
|
+
return "[Circular Reference]";
|
|
94
|
+
}
|
|
95
|
+
seen.add(value);
|
|
96
|
+
const serialized = {
|
|
97
|
+
message: value.message,
|
|
98
|
+
name: value.name,
|
|
99
|
+
stack: value.stack,
|
|
100
|
+
cause: value.cause instanceof Error ? serialize(value.cause, seen) : value.cause,
|
|
101
|
+
};
|
|
102
|
+
// Copy enumerable custom properties (e.g., error.code, error.statusCode)
|
|
103
|
+
for (const key of Object.keys(value)) {
|
|
104
|
+
if (!(key in serialized)) {
|
|
105
|
+
serialized[key] = serialize(value[key], seen);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return serialized;
|
|
109
|
+
}
|
|
110
|
+
// Primitive value - return as-is
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.ErrorFormat = ErrorFormat;
|
|
115
|
+
//# sourceMappingURL=ErrorFormat.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorFormat.cjs","sources":["../../../../src/logger/format/ErrorFormat.ts"],"sourcesContent":["import winston from \"winston\";\nimport { TransformableInfo } from \"logform\";\n\n/**\n * Winston log format for handling Error objects with cause chains.\n *\n * @description\n * ES2022 supports adding a `cause` property to Error objects for better error context.\n * While `console.log(err)` prints the entire cause chain automatically, Winston only logs\n * the top-level error, losing the cause chain context.\n *\n * This format ensures that error cause chains are fully serialized and included in log output,\n * preserving the complete error context for better debugging and error tracking.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause | MDN: Error.cause}\n * @see {@link https://github.com/winstonjs/winston/issues/2533 | Winston Issue #2533}\n *\n * @param {TransformableInfo} info - The log entry information from Winston\n * @returns {TransformableInfo} The formatted log entry with serialized error chains\n *\n * @example\n * ```typescript\n * const logger = winston.createLogger({\n * format: winston.format.combine(\n * ErrorFormat,\n * winston.format.json()\n * ),\n * transports: [new winston.transports.Console()]\n * });\n *\n * try {\n * throw new Error(\"Original error\");\n * } catch (err) {\n * throw new Error(\"Wrapper error\", { cause: err });\n * }\n * ```\n */\nexport const ErrorFormat = winston.format((info: TransformableInfo) => {\n // If the log entry itself is an error\n if (info instanceof Error) {\n const seen = new WeakSet<object>();\n const serialized = serialize(info, seen);\n\n // Preserve Winston semantics by setting standard error properties\n info.message = serialized.message;\n info.stack = serialized.stack;\n info.cause = serialized.cause;\n\n // Copy all other enumerable properties from serialized error\n for (const key of Object.keys(serialized)) {\n if (![\"message\", \"stack\", \"name\", \"cause\"].includes(key)) {\n info[key] = serialized[key];\n }\n }\n\n return info;\n }\n\n // For normal log entries, serialize any nested error fields\n const seen = new WeakSet<object>();\n for (const key of Object.keys(info)) {\n info[key] = serialize(info[key], seen);\n }\n\n return info;\n});\n\n/**\n * Recursively serializes values that may contain Error objects.\n *\n * @description\n * Handles all types of values including Error instances, nested objects, arrays,\n * and primitives. Ensures that Error objects are fully serialized with their\n * stack traces, messages, and cause chains preserved. Includes circular reference\n * detection to prevent infinite recursion.\n *\n * @param {any} value - The value to serialize. Can be any type (Error, object, array, primitive)\n * @param {WeakSet<object>} seen - Set tracking objects already visited to detect circular references\n * @returns {any} The serialized value with all Error objects converted to plain objects\n *\n * @example\n * ```typescript\n * const error = new Error(\"Test\");\n * const seen = new WeakSet<object>();\n * const serialized = serialize(error, seen);\n * // Returns: { message: \"Test\", name: \"Error\", stack: \"...\", cause: undefined }\n * ```\n */\nfunction serialize(value: any, seen: WeakSet<object> = new WeakSet<object>()): any {\n // Handle null/undefined\n if (value == null) {\n return value;\n }\n\n // Error instance - convert to serializable object\n if (value instanceof Error) {\n // Check for circular reference\n if (seen.has(value)) {\n return \"[Circular Reference]\";\n }\n seen.add(value);\n\n const serialized: any = {\n message: value.message,\n name: value.name,\n stack: value.stack,\n cause: value.cause instanceof Error ? serialize(value.cause, seen) : value.cause,\n };\n\n // Copy enumerable custom properties (e.g., error.code, error.statusCode)\n for (const key of Object.keys(value)) {\n if (!(key in serialized)) {\n serialized[key] = serialize(value[key], seen);\n }\n }\n\n return serialized;\n }\n\n\n // Primitive value - return as-is\n return value;\n}"],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;AACI,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,IAAuB,KAAI;;AAEpE,IAAA,IAAI,IAAI,YAAY,KAAK,EAAE;AACzB,QAAA,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU;QAClC,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;;AAGxC,QAAA,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO;AACjC,QAAA,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK;AAC7B,QAAA,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK;;QAG7B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACzC,YAAA,IAAI,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACxD,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC;YAC7B;QACF;AAEA,QAAA,OAAO,IAAI;IACb;;AAGA,IAAA,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU;IAClC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACnC,QAAA,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IACxC;AAEA,IAAA,OAAO,IAAI;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;;;;AAoBG;AACH,SAAS,SAAS,CAAC,KAAU,EAAE,IAAA,GAAwB,IAAI,OAAO,EAAU,EAAA;;AAE1E,IAAA,IAAI,KAAK,IAAI,IAAI,EAAE;AACjB,QAAA,OAAO,KAAK;IACd;;AAGA,IAAA,IAAI,KAAK,YAAY,KAAK,EAAE;;AAE1B,QAAA,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AACnB,YAAA,OAAO,sBAAsB;QAC/B;AACA,QAAA,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;AAEf,QAAA,MAAM,UAAU,GAAQ;YACtB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK,YAAY,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK;SACjF;;QAGD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACpC,YAAA,IAAI,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE;AACxB,gBAAA,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;YAC/C;QACF;AAEA,QAAA,OAAO,UAAU;IACnB;;AAIA,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONObject.cjs","sources":["../../../src/types/JSONObject.ts"],"sourcesContent":["import { BaseException, IllegalArgumentException } from '../exceptions';\
|
|
1
|
+
{"version":3,"file":"JSONObject.cjs","sources":["../../../src/types/JSONObject.ts"],"sourcesContent":["import { BaseException, IllegalArgumentException } from '../exceptions';\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | undefined\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\n | Object\n\nexport class JSONObject extends Map<string, JSONValue> {\n\n\n constructor(object?: { [x: string]: JSONValue }) {\n super()\n if (object) {\n for (const [key, value] of Object.entries(object)) {\n if (value === null || value === undefined) {\n // ignore\n } else if (value.constructor == Object) {\n this.set(key, new JSONObject(value as { [x: string]: JSONValue }));\n } else if (value.constructor == Array) {\n this.set(key, new JSONArray(value));\n } else {\n this.set(key, value)\n }\n }\n }\n\n\n }\n\n getJSONObject(key: string): JSONObject {\n if (super.has(key)) {\n if (super.get(key) instanceof JSONObject) {\n return super.get(key) as JSONObject\n } else {\n throw new IllegalArgumentException('Value cannot be converted to JSONObject')\n }\n }\n\n throw new BaseException(`Value for Key: '${key}' not found`);\n }\n\n getString(key: string): string {\n if (super.has(key)) {\n try {\n if (typeof super.get(key) === 'string') {\n return super.get(key) as string;\n }\n\n throw new IllegalArgumentException('Value cannot be converted to string')\n } catch (e) {\n throw new IllegalArgumentException('Value cannot be converted to string', e)\n }\n }\n throw new BaseException(`Value for Key: '${key}' not found`);\n }\n\n getNumber(key: string): number {\n if (super.has(key)) {\n const number = Number(super.get(key));\n if (!isNaN(number)) {\n return number;\n }\n throw new IllegalArgumentException('Value cannot be converted to number')\n }\n throw new BaseException(`Value for Key: '${key}' not found`);\n }\n\n getBoolean(key: string): boolean {\n if (super.has(key)) {\n if (typeof super.get(key) === 'boolean') {\n return super.get(key) as boolean;\n } else if (super.get(key) === 'true' || super.get(key) === 'false') {\n return Boolean(super.get(key));\n }\n throw new IllegalArgumentException('Value cannot be converted to boolean')\n }\n throw new BaseException(`Value for Key: '${key}' not found`);\n }\n\n getArray(key: string): JSONArray {\n if (super.has(key)) {\n if (super.get(key) instanceof JSONArray) {\n return super.get(key) as JSONArray;\n }\n else if (super.get(key) instanceof Array) {\n return new JSONArray(super.get(key) as Array<JSONValue>);\n }\n throw new IllegalArgumentException('Value cannot be converted to array')\n }\n throw new BaseException(`Value for Key: '${key}' not found`);\n }\n\n public toJSON(): { [x: string]: JSONValue } {\n const obj: { [x: string]: JSONValue } = {};\n for (const [key, value] of this.entries()) {\n if (value == null) {\n obj[key] = value;\n } else if (value instanceof JSONObject || value instanceof JSONArray) {\n obj[key] = value.toJSON();\n } else {\n obj[key] = value\n }\n }\n return obj;\n }\n}\n\n\nexport class JSONArray extends Array<JSONValue> {\n\n constructor(array?: Array<JSONValue>) {\n super();\n if (array) {\n for (let item of Object.values(array)) {\n item = JSON.parse(JSON.stringify(item))\n\n if (item == null) {\n this.push(item);\n }\n else if (item.constructor == Object) {\n this.push(new JSONObject(item as { [x: string]: JSONValue }));\n }\n else if (item.constructor == Array) {\n this.push(new JSONArray(item));\n }\n else {\n this.push(item)\n }\n }\n }\n }\n\n public toJSON(): Array<JSONValue> {\n const arr: Array<JSONValue> = [];\n for (const value of this) {\n if (value == null) {\n arr.push(value);\n } else if (value instanceof JSONObject || value instanceof JSONArray) {\n arr.push(value.toJSON());\n } else {\n arr.push(value)\n }\n }\n return arr;\n }\n}"],"names":["IllegalArgumentException","BaseException"],"mappings":";;;;;AAWM,MAAO,UAAW,SAAQ,GAAsB,CAAA;AAGlD,IAAA,WAAA,CAAY,MAAmC,EAAA;AAC3C,QAAA,KAAK,EAAE;QACP,IAAI,MAAM,EAAE;AACR,YAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBAC/C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AAEpC,qBAAA,IAAI,KAAK,CAAC,WAAW,IAAI,MAAM,EAAE;oBACpC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,KAAmC,CAAC,CAAC;gBACtE;AAAO,qBAAA,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,EAAE;oBACnC,IAAI,CAAC,GAAG,CAAC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IACJ;IAEO,MAAM,GAAA;QACT,MAAM,GAAG,GAAqB,EAAE;AAChC,QAAA,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE;AACtB,YAAA,IAAI,KAAK,IAAI,IAAI,EAAE;AACf,gBAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YACnB;iBAAO,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,SAAS,EAAE;gBAClE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC5B;iBAAO;AACH,gBAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YACnB;QACJ;AACA,QAAA,OAAO,GAAG;IACd;AACH;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggingLevel.cjs","sources":["../../../src/types/LoggingLevel.ts"],"sourcesContent":["export enum LoggingLevel {\
|
|
1
|
+
{"version":3,"file":"LoggingLevel.cjs","sources":["../../../src/types/LoggingLevel.ts"],"sourcesContent":["export enum LoggingLevel {\n silly = 'silly',\n debug = 'debug',\n verbose = 'verbose',\n info = 'info',\n warn = 'warn',\n error = 'error',\n}"],"names":["LoggingLevel"],"mappings":";;AAAYA;AAAZ,CAAA,UAAY,YAAY,EAAA;AACpB,IAAA,YAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,YAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,YAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,YAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,YAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,YAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACnB,CAAC,EAPWA,oBAAY,KAAZA,oBAAY,GAAA,EAAA,CAAA,CAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortOrder.cjs","sources":["../../../src/types/SortOrder.ts"],"sourcesContent":["/**\
|
|
1
|
+
{"version":3,"file":"SortOrder.cjs","sources":["../../../src/types/SortOrder.ts"],"sourcesContent":["/**\n * @export\n * @enum {number}\n */\nexport enum SortOrder {\n ASC = 'asc',\n DESC = 'desc'\n}"],"names":["SortOrder"],"mappings":";;AAAA;;;AAGG;AACSA;AAAZ,CAAA,UAAY,SAAS,EAAA;AACjB,IAAA,SAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACjB,CAAC,EAHWA,iBAAS,KAATA,iBAAS,GAAA,EAAA,CAAA,CAAA;;"}
|
|
@@ -8,7 +8,7 @@ var IllegalArgumentException = require('../../exceptions/IllegalArgumentExceptio
|
|
|
8
8
|
* Utility class for date and time operations. Provides methods for parsing,
|
|
9
9
|
* formatting, and performing calculations with dates and times.
|
|
10
10
|
*/
|
|
11
|
-
class
|
|
11
|
+
class DateUtil {
|
|
12
12
|
static { this.ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"; }
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current date and time in the specified time zone.
|
|
@@ -60,7 +60,7 @@ class BaseDateUtil {
|
|
|
60
60
|
*/
|
|
61
61
|
static isValidDate(dateString, dateFormat) {
|
|
62
62
|
try {
|
|
63
|
-
DateUtil.readDate(dateString, dateFormat);
|
|
63
|
+
DateUtil.readDate(dateString, dateFormat, "UTC");
|
|
64
64
|
return true;
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
66
|
}
|
|
@@ -98,7 +98,7 @@ class BaseDateUtil {
|
|
|
98
98
|
* @returns `true` if the year is a leap year, otherwise `false`.
|
|
99
99
|
*/
|
|
100
100
|
static isLeapYear(year) {
|
|
101
|
-
return dateFns.isLeapYear(DateUtil.readDate(year.toString(), 'yyyy'));
|
|
101
|
+
return dateFns.isLeapYear(DateUtil.readDate(year.toString(), 'yyyy', "UTC"));
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Converts a timestamp (in milliseconds) to a Date object.
|
|
@@ -117,43 +117,6 @@ class BaseDateUtil {
|
|
|
117
117
|
return date.getTime();
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Utility class for handling date operations in a fixed time zone.
|
|
122
|
-
* Extends BaseDateUtil with default settings for the 'Asia/Kolkata' time zone.
|
|
123
|
-
*/
|
|
124
|
-
class DateUtil extends BaseDateUtil {
|
|
125
|
-
/** Default time zone used for all date operations. */
|
|
126
|
-
static { this.TIMEZONE = 'Asia/Kolkata'; }
|
|
127
|
-
/**
|
|
128
|
-
* Gets the current date and time in the default time zone.
|
|
129
|
-
* @returns Current date and time as a Date object.
|
|
130
|
-
*/
|
|
131
|
-
static now() {
|
|
132
|
-
return BaseDateUtil.now(this.TIMEZONE);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Parses a date string into a Date object using the default time zone.
|
|
136
|
-
* @param dateString The date string to parse.
|
|
137
|
-
* @param dateFormat Optional format of the date string (default: ISO_8601_FORMAT).
|
|
138
|
-
* @throws {IllegalArgumentException} If the date string is invalid.
|
|
139
|
-
* @returns Parsed Date object.
|
|
140
|
-
*/
|
|
141
|
-
static readDate(dateString, dateFormat) {
|
|
142
|
-
return BaseDateUtil.readDate(dateString, dateFormat || DateUtil.ISO_8601_FORMAT, this.TIMEZONE);
|
|
143
|
-
}
|
|
144
|
-
static printDate(date, dateFormat = DateUtil.ISO_8601_FORMAT) {
|
|
145
|
-
const normalizedDate = typeof date === 'number' ? new Date(date) : date;
|
|
146
|
-
return BaseDateUtil.printDate(normalizedDate, this.TIMEZONE, dateFormat);
|
|
147
|
-
}
|
|
148
|
-
static getStartOfDay(date) {
|
|
149
|
-
const normalizedDate = typeof date === 'number' ? new Date(date) : date;
|
|
150
|
-
return BaseDateUtil.getStartOfDay(normalizedDate, this.TIMEZONE);
|
|
151
|
-
}
|
|
152
|
-
static getEndOfDay(date) {
|
|
153
|
-
const normalizedDate = typeof date === 'number' ? new Date(date) : date;
|
|
154
|
-
return BaseDateUtil.getEndOfDay(normalizedDate, this.TIMEZONE);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
120
|
|
|
158
121
|
exports.DateUtil = DateUtil;
|
|
159
122
|
//# sourceMappingURL=DateUtil.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateUtil.cjs","sources":["../../../../src/utils/date/DateUtil.ts"],"sourcesContent":["import { TZDate } from '@date-fns/tz';\r\nimport { add, compareAsc, differenceInCalendarDays, differenceInCalendarMonths, differenceInCalendarYears, Duration, endOfDay, format, isLeapYear, isValid, parse, startOfDay } from 'date-fns';\r\nimport { IllegalArgumentException } from '../../exceptions';\r\n\r\n/**\r\n * Utility class for date and time operations. Provides methods for parsing,\r\n * formatting, and performing calculations with dates and times.\r\n */\r\nclass BaseDateUtil {\r\n\r\n static readonly ISO_8601_FORMAT = \"yyyy-MM-dd'T'HH:mm:ss.SSSxxx\"\r\n\r\n /**\r\n * Gets the current date and time in the specified time zone.\r\n * @param timeZone The IANA time zone identifier.\r\n * @returns Current date and time in the specified time zone.\r\n */\r\n protected static now(timeZone: string): Date {\r\n return new TZDate(new Date(), timeZone);\r\n }\r\n\r\n /**\r\n * Gets the current time in milliseconds since the Unix epoch.\r\n * @returns Current time in milliseconds.\r\n */\r\n static nowInMillis(): number {\r\n return Date.now();\r\n }\r\n\r\n /**\r\n * Parses a date string into a Date object.\r\n * @param dateString The date string to parse.\r\n * @param dateFormat The format of the date string (default: ISO_8601_FORMAT).\r\n * @param timeZone The IANA time zone identifier.\r\n * @throws {IllegalArgumentException} If the date string is invalid.\r\n * @returns Parsed Date object.\r\n */\r\n protected static readDate(dateString: string, dateFormat = this.ISO_8601_FORMAT, timeZone: string): Date {\r\n const date = parse(dateString, dateFormat, TZDate.tz(timeZone));\r\n if (!isValid(date)) {\r\n throw new IllegalArgumentException('Invalid date string or date format');\r\n }\r\n return date;\r\n }\r\n\r\n /**\r\n * Formats a Date or timestamp into a string.\r\n * @param date The date or timestamp to format.\r\n * @param timeZone The IANA time zone identifier.\r\n * @param dateFormat The desired output format (default: ISO_8601_FORMAT).\r\n * @returns Formatted date string.\r\n */\r\n protected static printDate(date: Date, timeZone: string, dateFormat?: string): string;\r\n protected static printDate(date: number, timeZone: string, dateFormat?: string): string;\r\n protected static printDate(date: Date | number, timeZone: string, dateFormat: string = this.ISO_8601_FORMAT): string {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return format(new TZDate(normalizedDate, timeZone), dateFormat);\r\n }\r\n\r\n /**\r\n * Gets the start of the day for a given date or timestamp.\r\n * @param date The date or timestamp to calculate from.\r\n * @param timeZone The IANA time zone identifier.\r\n * @returns The start of the day as a Date object.\r\n */\r\n protected static getStartOfDay(date: Date, timeZone: string): Date;\r\n protected static getStartOfDay(date: number, timeZone: string): Date;\r\n protected static getStartOfDay(date: Date | number, timeZone: string): Date {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return startOfDay(new TZDate(normalizedDate, timeZone));\r\n }\r\n\r\n /**\r\n * Gets the end of the day for a given date or timestamp.\r\n * @param date The date or timestamp to calculate from.\r\n * @param timeZone The IANA time zone identifier.\r\n * @returns The end of the day as a Date object.\r\n */\r\n protected static getEndOfDay(date: Date, timeZone: string): Date;\r\n protected static getEndOfDay(date: number, timeZone: string): Date;\r\n protected static getEndOfDay(date: Date | number, timeZone: string): Date {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return endOfDay(new TZDate(normalizedDate, timeZone));\r\n }\r\n\r\n /**\r\n * Checks if a date string is valid according to the specified format.\r\n * @param dateString The date string to validate.\r\n * @param dateFormat Optional date format (default: ISO_8601_FORMAT).\r\n * @returns True if the date is valid, false otherwise.\r\n */\r\n static isValidDate(dateString: string, dateFormat?: string): boolean {\r\n try {\r\n DateUtil.readDate(dateString, dateFormat);\r\n return true;\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n } catch (error) {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Calculates the absolute number of days between two dates or timestamps.\r\n * @param firstDate The first date or timestamp.\r\n * @param secondDate The second date or timestamp.\r\n * @returns Number of days between the two dates.\r\n */\r\n static daysInBetween(firstDate: Date, secondDate: Date): number;\r\n static daysInBetween(firstDate: number, secondDate: number): number;\r\n static daysInBetween(firstDate: Date | number, secondDate: Date | number): number {\r\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\r\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\r\n return Math.abs(differenceInCalendarDays(first, second));\r\n }\r\n\r\n /**\r\n * Calculates the absolute number of months between two dates or timestamps.\r\n * @param firstDate The first date or timestamp.\r\n * @param secondDate The second date or timestamp.\r\n * @returns The number of months between the two dates.\r\n */\r\n static monthsInBetween(firstDate: Date, secondDate: Date): number;\r\n static monthsInBetween(firstDate: number, secondDate: number): number;\r\n static monthsInBetween(firstDate: Date | number, secondDate: Date | number): number {\r\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\r\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\r\n return Math.abs(differenceInCalendarMonths(first, second));\r\n }\r\n\r\n /**\r\n * Calculates the absolute number of years between two dates or timestamps.\r\n * @param firstDate The first date or timestamp.\r\n * @param secondDate The second date or timestamp.\r\n * @returns The number of years between the two dates.\r\n */\r\n static yearsInBetween(firstDate: Date, secondDate: Date): number;\r\n static yearsInBetween(firstDate: number, secondDate: number): number;\r\n static yearsInBetween(firstDate: Date | number, secondDate: Date | number): number {\r\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\r\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\r\n return Math.abs(differenceInCalendarYears(first, second));\r\n }\r\n\r\n /**\r\n * Compares two dates or timestamps.\r\n * @param firstDate The first date or timestamp.\r\n * @param secondDate The second date or timestamp.\r\n * @returns `-1` if the first date is earlier, `1` if it is later, or `0` if the two dates are equal.\r\n */\r\n static compareDates(firstDate: Date, secondDate: Date): -1 | 0 | 1;\r\n static compareDates(firstDate: number, secondDate: number): -1 | 0 | 1;\r\n static compareDates(firstDate: Date | number, secondDate: Date | number): -1 | 0 | 1 {\r\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\r\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\r\n\r\n return compareAsc(first, second) as -1 | 0 | 1;\r\n }\r\n\r\n /**\r\n * Adds a duration (e.g., days, months, years) to a given date or timestamp.\r\n * @param date The base date or timestamp to which the duration will be added.\r\n * @param duration An object specifying the duration (e.g., `{ days: 1, months: 2 }`).\r\n * @returns A new Date object with the duration added.\r\n */\r\n static addDuration(date: Date, duration: Duration): Date;\r\n static addDuration(date: number, duration: Duration): Date;\r\n static addDuration(date: Date | number, duration: Duration): Date {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return add(normalizedDate, duration);\r\n }\r\n\r\n /**\r\n * Determines whether a given year is a leap year.\r\n * @param year The year to check.\r\n * @returns `true` if the year is a leap year, otherwise `false`.\r\n */\r\n static isLeapYear(year: number): boolean {\r\n return isLeapYear(DateUtil.readDate(year.toString(), 'yyyy'));\r\n }\r\n\r\n\r\n /**\r\n * Converts a timestamp (in milliseconds) to a Date object.\r\n * @param milliseconds The timestamp in milliseconds since the Unix epoch.\r\n * @returns A Date object representing the provided timestamp.\r\n */\r\n static fromMillis(milliseconds: number): Date {\r\n return new Date(milliseconds);\r\n }\r\n\r\n /**\r\n * Converts a Date object to a timestamp (in milliseconds).\r\n * @param date The Date object to convert.\r\n * @returns The timestamp in milliseconds since the Unix epoch.\r\n */\r\n static toMillis(date: Date): number {\r\n return date.getTime();\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for handling date operations in a fixed time zone.\r\n * Extends BaseDateUtil with default settings for the 'Asia/Kolkata' time zone.\r\n */\r\nexport class DateUtil extends BaseDateUtil {\r\n /** Default time zone used for all date operations. */\r\n static readonly TIMEZONE = 'Asia/Kolkata';\r\n /**\r\n * Gets the current date and time in the default time zone.\r\n * @returns Current date and time as a Date object.\r\n */\r\n static override now(): Date {\r\n return BaseDateUtil.now(this.TIMEZONE);\r\n }\r\n\r\n /**\r\n * Parses a date string into a Date object using the default time zone.\r\n * @param dateString The date string to parse.\r\n * @param dateFormat Optional format of the date string (default: ISO_8601_FORMAT).\r\n * @throws {IllegalArgumentException} If the date string is invalid.\r\n * @returns Parsed Date object.\r\n */\r\n static override readDate(dateString: string, dateFormat?: string): Date {\r\n return BaseDateUtil.readDate(dateString, dateFormat || DateUtil.ISO_8601_FORMAT, this.TIMEZONE);\r\n }\r\n\r\n /**\r\n * Formats a Date or timestamp into a string using the default time zone.\r\n * @param date The date or timestamp to format.\r\n * @param dateFormat Optional desired output format (default: ISO_8601_FORMAT).\r\n * @returns Formatted date string.\r\n */\r\n static override printDate(date: Date, dateFormat?: string): string;\r\n static override printDate(date: number, dateFormat?: string): string;\r\n static override printDate(date: Date | number, dateFormat = DateUtil.ISO_8601_FORMAT): string {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return BaseDateUtil.printDate(normalizedDate, this.TIMEZONE, dateFormat);\r\n }\r\n\r\n /**\r\n * Gets the start of the day for a given date or timestamp using the default time zone.\r\n * @param date The date or timestamp to calculate from.\r\n * @returns A Date object representing the start of the day.\r\n */\r\n static override getStartOfDay(date: Date): Date;\r\n static override getStartOfDay(date: number): Date;\r\n static override getStartOfDay(date: Date | number): Date {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return BaseDateUtil.getStartOfDay(normalizedDate, this.TIMEZONE);\r\n }\r\n\r\n /**\r\n * Gets the end of the day for a given date or timestamp using the default time zone.\r\n * @param date The date or timestamp to calculate from.\r\n * @returns A Date object representing the end of the day.\r\n */\r\n static override getEndOfDay(date: Date): Date;\r\n static override getEndOfDay(date: number): Date;\r\n static override getEndOfDay(date: Date | number): Date {\r\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\r\n return BaseDateUtil.getEndOfDay(normalizedDate, this.TIMEZONE);\r\n }\r\n}\r\n"],"names":["TZDate","parse","isValid","IllegalArgumentException","format","startOfDay","endOfDay","differenceInCalendarDays","differenceInCalendarMonths","differenceInCalendarYears","compareAsc","add","isLeapYear"],"mappings":";;;;;;AAIA;;;AAGG;AACH,MAAM,YAAY,CAAA;aAEE,IAAe,CAAA,eAAA,GAAG,8BAA8B,CAAA;AAEhE;;;;AAIG;IACO,OAAO,GAAG,CAAC,QAAgB,EAAA;QACjC,OAAO,IAAIA,SAAM,CAAC,IAAI,IAAI,EAAE,EAAE,QAAQ,CAAC;;AAG3C;;;AAGG;AACH,IAAA,OAAO,WAAW,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,GAAG,EAAE;;AAGrB;;;;;;;AAOG;IACO,OAAO,QAAQ,CAAC,UAAkB,EAAE,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,QAAgB,EAAA;AAC7F,QAAA,MAAM,IAAI,GAAGC,aAAK,CAAC,UAAU,EAAE,UAAU,EAAED,SAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC/D,QAAA,IAAI,CAACE,eAAO,CAAC,IAAI,CAAC,EAAE;AAChB,YAAA,MAAM,IAAIC,iDAAwB,CAAC,oCAAoC,CAAC;;AAE5E,QAAA,OAAO,IAAI;;IAYL,OAAO,SAAS,CAAC,IAAmB,EAAE,QAAgB,EAAE,UAAA,GAAqB,IAAI,CAAC,eAAe,EAAA;AACvG,QAAA,MAAM,cAAc,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;AACvE,QAAA,OAAOC,cAAM,CAAC,IAAIJ,SAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;;AAWzD,IAAA,OAAO,aAAa,CAAC,IAAmB,EAAE,QAAgB,EAAA;AAChE,QAAA,MAAM,cAAc,GAAG,OAAO,IAAI,KAAK,QAAQ,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til.cjs","sources":["../../../../src/utils/date/DateUtil.ts"],"sourcesContent":["import { TZDate } from '@date-fns/tz';\nimport { add, compareAsc, differenceInCalendarDays, differenceInCalendarMonths, differenceInCalendarYears, Duration, endOfDay, format, isLeapYear, isValid, parse, startOfDay } from 'date-fns';\nimport { IllegalArgumentException } from '../../exceptions';\n\n/**\n * Utility class for date and time operations. Provides methods for parsing,\n * formatting, and performing calculations with dates and times.\n */\nexport class DateUtil {\n\n static readonly ISO_8601_FORMAT = \"yyyy-MM-dd'T'HH:mm:ss.SSSxxx\"\n\n /**\n * Gets the current date and time in the specified time zone.\n * @param timeZone The IANA time zone identifier.\n * @returns Current date and time in the specified time zone.\n */\n static now(timeZone: string): Date {\n return new TZDate(new Date(), timeZone);\n }\n\n /**\n * Gets the current time in milliseconds since the Unix epoch.\n * @returns Current time in milliseconds.\n */\n static nowInMillis(): number {\n return Date.now();\n }\n\n /**\n * Parses a date string into a Date object.\n * @param dateString The date string to parse.\n * @param dateFormat The format of the date string (default: ISO_8601_FORMAT).\n * @param timeZone The IANA time zone identifier.\n * @throws {IllegalArgumentException} If the date string is invalid.\n * @returns Parsed Date object.\n */\n static readDate(dateString: string, dateFormat = this.ISO_8601_FORMAT, timeZone: string): Date {\n const date = parse(dateString, dateFormat, TZDate.tz(timeZone));\n if (!isValid(date)) {\n throw new IllegalArgumentException('Invalid date string or date format');\n }\n return date;\n }\n\n /**\n * Formats a Date or timestamp into a string.\n * @param date The date or timestamp to format.\n * @param timeZone The IANA time zone identifier.\n * @param dateFormat The desired output format (default: ISO_8601_FORMAT).\n * @returns Formatted date string.\n */\n static printDate(date: Date, timeZone: string, dateFormat?: string): string;\n static printDate(date: number, timeZone: string, dateFormat?: string): string;\n static printDate(date: Date | number, timeZone: string, dateFormat: string = this.ISO_8601_FORMAT): string {\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\n return format(new TZDate(normalizedDate, timeZone), dateFormat);\n }\n\n /**\n * Gets the start of the day for a given date or timestamp.\n * @param date The date or timestamp to calculate from.\n * @param timeZone The IANA time zone identifier.\n * @returns The start of the day as a Date object.\n */\n static getStartOfDay(date: Date, timeZone: string): Date;\n static getStartOfDay(date: number, timeZone: string): Date;\n static getStartOfDay(date: Date | number, timeZone: string): Date {\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\n return startOfDay(new TZDate(normalizedDate, timeZone));\n }\n\n /**\n * Gets the end of the day for a given date or timestamp.\n * @param date The date or timestamp to calculate from.\n * @param timeZone The IANA time zone identifier.\n * @returns The end of the day as a Date object.\n */\n static getEndOfDay(date: Date, timeZone: string): Date;\n static getEndOfDay(date: number, timeZone: string): Date;\n static getEndOfDay(date: Date | number, timeZone: string): Date {\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\n return endOfDay(new TZDate(normalizedDate, timeZone));\n }\n\n /**\n * Checks if a date string is valid according to the specified format.\n * @param dateString The date string to validate.\n * @param dateFormat Optional date format (default: ISO_8601_FORMAT).\n * @returns True if the date is valid, false otherwise.\n */\n static isValidDate(dateString: string, dateFormat?: string): boolean {\n try {\n DateUtil.readDate(dateString, dateFormat, \"UTC\");\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Calculates the absolute number of days between two dates or timestamps.\n * @param firstDate The first date or timestamp.\n * @param secondDate The second date or timestamp.\n * @returns Number of days between the two dates.\n */\n static daysInBetween(firstDate: Date, secondDate: Date): number;\n static daysInBetween(firstDate: number, secondDate: number): number;\n static daysInBetween(firstDate: Date | number, secondDate: Date | number): number {\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\n return Math.abs(differenceInCalendarDays(first, second));\n }\n\n /**\n * Calculates the absolute number of months between two dates or timestamps.\n * @param firstDate The first date or timestamp.\n * @param secondDate The second date or timestamp.\n * @returns The number of months between the two dates.\n */\n static monthsInBetween(firstDate: Date, secondDate: Date): number;\n static monthsInBetween(firstDate: number, secondDate: number): number;\n static monthsInBetween(firstDate: Date | number, secondDate: Date | number): number {\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\n return Math.abs(differenceInCalendarMonths(first, second));\n }\n\n /**\n * Calculates the absolute number of years between two dates or timestamps.\n * @param firstDate The first date or timestamp.\n * @param secondDate The second date or timestamp.\n * @returns The number of years between the two dates.\n */\n static yearsInBetween(firstDate: Date, secondDate: Date): number;\n static yearsInBetween(firstDate: number, secondDate: number): number;\n static yearsInBetween(firstDate: Date | number, secondDate: Date | number): number {\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\n return Math.abs(differenceInCalendarYears(first, second));\n }\n\n /**\n * Compares two dates or timestamps.\n * @param firstDate The first date or timestamp.\n * @param secondDate The second date or timestamp.\n * @returns `-1` if the first date is earlier, `1` if it is later, or `0` if the two dates are equal.\n */\n static compareDates(firstDate: Date, secondDate: Date): -1 | 0 | 1;\n static compareDates(firstDate: number, secondDate: number): -1 | 0 | 1;\n static compareDates(firstDate: Date | number, secondDate: Date | number): -1 | 0 | 1 {\n const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;\n const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;\n\n return compareAsc(first, second) as -1 | 0 | 1;\n }\n\n /**\n * Adds a duration (e.g., days, months, years) to a given date or timestamp.\n * @param date The base date or timestamp to which the duration will be added.\n * @param duration An object specifying the duration (e.g., `{ days: 1, months: 2 }`).\n * @returns A new Date object with the duration added.\n */\n static addDuration(date: Date, duration: Duration): Date;\n static addDuration(date: number, duration: Duration): Date;\n static addDuration(date: Date | number, duration: Duration): Date {\n const normalizedDate = typeof date === 'number' ? new Date(date) : date;\n return add(normalizedDate, duration);\n }\n\n /**\n * Determines whether a given year is a leap year.\n * @param year The year to check.\n * @returns `true` if the year is a leap year, otherwise `false`.\n */\n static isLeapYear(year: number): boolean {\n return isLeapYear(DateUtil.readDate(year.toString(), 'yyyy', \"UTC\"));\n }\n\n\n /**\n * Converts a timestamp (in milliseconds) to a Date object.\n * @param milliseconds The timestamp in milliseconds since the Unix epoch.\n * @returns A Date object representing the provided timestamp.\n */\n static fromMillis(milliseconds: number): Date {\n return new Date(milliseconds);\n }\n\n /**\n * Converts a Date object to a timestamp (in milliseconds).\n * @param date The Date object to convert.\n * @returns The timestamp in milliseconds since the Unix epoch.\n */\n static toMillis(date: Date): number {\n return date.getTime();\n }\n}\n"],"names":["TZDate","parse","isValid","IllegalArgumentException","format","startOfDay","endOfDay","differenceInCalendarDays","differenceInCalendarMonths","differenceInCalendarYears","compareAsc","add","isLeapYear"],"mappings":";;;;;;AAIA;;;AAGG;MACU,QAAQ,CAAA;aAED,IAAA,CAAA,eAAe,GAAG,8BAA8B,CAAA;AAEhE;;;;AAIG;IACH,OAAO,GAAG,CAAC,QAAgB,EAAA;QACvB,OAAO,IAAIA,SAAM,CAAC,IAAI,IAAI,EAAE,EAAE,QAAQ,CAAC;IAC3C;AAEA;;;AAGG;AACH,IAAA,OAAO,WAAW,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,GAAG,EAAE;IACrB;AAEA;;;;;;;AAOG;IACH,OAAO,QAAQ,CAAC,UAAkB,EAAE,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,QAAgB,EAAA;AACnF,QAAA,MAAM,IAAI,GAAGC,aAAK,CAAC,UAAU,EAAE,UAAU,EAAED,SAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC/D,QAAA,IAAI,CAACE,eAAO,CAAC,IAAI,CAAC,EAAE;AAChB,YAAA,MAAM,IAAIC,iDAAwB,CAAC,oCAAoC,CAAC;QAC5E;AACA,QAAA,OAAO,IAAI;IACf;IAWA,OAAO,SAAS,CAAC,IAAmB,EAAE,QAAgB,EAAE,UAAA,GAAqB,IAAI,CAAC,eAAe,EAAA;AAC7F,QAAA,MAAM,cAAc,GAAG,O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AAA,OAAOC,WAAG,CAAC,cAAc,EAAE,QAAQ,CAAC;IACxC;AAEA;;;;AAIG;IACH,OAAO,UAAU,CAAC,IAAY,EAAA;AAC1B,QAAA,OAAOC,kBAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACxE;AAGA;;;;AAIG;IACH,OAAO,UAAU,CAAC,YAAoB,EAAA;AAClC,QAAA,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC;IACjC;AAEA;;;;AAIG;IACH,OAAO,QAAQ,CAAC,IAAU,EAAA;AACtB,QAAA,OAAO,IAAI,CAAC,OAAO,EAAE;IACzB;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseObject.js","sources":["../../../src/beans/BaseObject.ts"],"sourcesContent":["import { Expose } from 'class-transformer';\
|
|
1
|
+
{"version":3,"file":"BaseObject.js","sources":["../../../src/beans/BaseObject.ts"],"sourcesContent":["import { Expose } from 'class-transformer';\nimport { IsNumber, IsString } from 'class-validator';\n\n/**\n * The `BaseObject` class serves as a base model for objects with common properties\n * such as `id`, `description`, `createdAt`, and `updatedAt`. It includes validation\n * and transformation decorators for serialization and deserialization.\n *\n * Properties:\n * - `id` (string | undefined): A unique identifier for the object.\n * - `description` (string | undefined): A brief description of the object.\n * - `createdAt` (number | undefined): The timestamp when the object was created.\n * - `updatedAt` (number | undefined): The timestamp when the object was last updated.\n *\n * Methods:\n * - `getId()`: Returns the `id` of the object.\n * - `setId(value: string | undefined)`: Sets the `id` of the object.\n * - `getDescription()`: Returns the `description` of the object.\n * - `setDescription(value: string | undefined)`: Sets the `description` of the object.\n * - `getCreatedAt()`: Returns the `createdAt` timestamp of the object.\n * - `setCreatedAt(value?: number)`: Sets the `createdAt` timestamp of the object.\n * - `getUpdatedAt()`: Returns the `updatedAt` timestamp of the object.\n * - `setUpdatedAt(value?: number)`: Sets the `updatedAt` timestamp of the object.\n */\nexport class BaseObject {\n\n @Expose({ name: 'id' })\n @IsString()\n private id?: string;\n\n @Expose({ name: 'description' })\n @IsString()\n private description?: string;\n\n @Expose({ name: 'created_at' })\n @IsNumber()\n private createdAt?: number;\n\n @Expose({ name: 'updated_at' })\n @IsNumber()\n private updatedAt?: number;\n\n getId() {\n return this.id;\n }\n\n setId(value: string | undefined) {\n this.id = value;\n }\n\n getCreatedAt() {\n return this.createdAt;\n }\n\n setCreatedAt(value?: number) {\n this.createdAt = value;\n }\n\n getUpdatedAt() {\n return this.updatedAt;\n }\n\n setUpdatedAt(value?: number) {\n this.updatedAt = value;\n }\n\n getDescription() {\n return this.description;\n }\n\n setDescription(value?: string) {\n this.description = value;\n }\n}"],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;AAoBG;MACU,UAAU,CAAA;IAkBnB,KAAK,GAAA;QACD,OAAO,IAAI,CAAC,EAAE;IAClB;AAEA,IAAA,KAAK,CAAC,KAAyB,EAAA;AAC3B,QAAA,IAAI,CAAC,EAAE,GAAG,KAAK;IACnB;IAEA,YAAY,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,YAAY,CAAC,KAAc,EAAA;AACvB,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;IAC1B;IAEA,YAAY,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,YAAY,CAAC,KAAc,EAAA;AACvB,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;IAC1B;IAEA,cAAc,GAAA;QACV,OAAO,IAAI,CAAC,WAAW;IAC3B;AAEA,IAAA,cAAc,CAAC,KAAc,EAAA;AACzB,QAAA,IAAI,CAAC,WAAW,GAAG,KAAK;IAC5B;AACH;AA7CW,UAAA,CAAA;AAFP,IAAA,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACtB,IAAA,QAAQ,EAAE;;AACS,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,IAAA,EAAA,MAAA,CAAA;AAIZ,UAAA,CAAA;AAFP,IAAA,MAAM,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AAC/B,IAAA,QAAQ,EAAE;;AACkB,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAIrB,UAAA,CAAA;AAFP,IAAA,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAC9B,IAAA,QAAQ,EAAE;;AACgB,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAInB,UAAA,CAAA;AAFP,IAAA,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAC9B,IAAA,QAAQ,EAAE;;AACgB,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;;;;"}
|
|
@@ -7,7 +7,7 @@ export { HTTPException } from '../../exceptions/HTTPException.js';
|
|
|
7
7
|
export { IllegalArgumentException } from '../../exceptions/IllegalArgumentException.js';
|
|
8
8
|
export { UnauthorizedException } from '../../exceptions/UnauthorizedException.js';
|
|
9
9
|
export { ConverterException } from '../../exceptions/ConverterException.js';
|
|
10
|
-
export { LoggerFactory
|
|
10
|
+
export { LoggerFactory } from '../../logger/LoggerFactory.js';
|
|
11
11
|
export { JSONArray, JSONObject } from '../../types/JSONObject.js';
|
|
12
12
|
export { LoggingLevel } from '../../types/LoggingLevel.js';
|
|
13
13
|
export { SortOrder } from '../../types/SortOrder.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BadRequestException.js","sources":["../../../src/exceptions/BadRequestException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\
|
|
1
|
+
{"version":3,"file":"BadRequestException.js","sources":["../../../src/exceptions/BadRequestException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\n\n/**\n * Exception thrown when a bad request is made to the server.\n * Typically used for HTTP 400 errors.\n */\nexport class BadRequestException extends HTTPException {\n\n constructor(message: string, cause?: unknown, code: number = 400) {\n super(message, cause, code)\n }\n}\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,MAAO,mBAAoB,SAAQ,aAAa,CAAA;AAElD,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;IAC/B;AACH;;;;"}
|
|
@@ -5,30 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
class BaseException extends Error {
|
|
7
7
|
constructor(message, cause, code) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.cause = cause;
|
|
8
|
+
super(message, { cause });
|
|
10
9
|
this.code = code;
|
|
11
10
|
this.name = this.constructor.name;
|
|
12
11
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves the full stack trace of the exception, including causes.
|
|
15
|
-
* @returns A string representation of the stack trace.
|
|
16
|
-
*/
|
|
17
|
-
getStackTrace() {
|
|
18
|
-
let stackTrace = `[${this.code}] ${this.stack}\n`;
|
|
19
|
-
let currentCause = this.cause;
|
|
20
|
-
while (currentCause) {
|
|
21
|
-
if (currentCause instanceof Error) {
|
|
22
|
-
stackTrace += `Caused by: ${currentCause.stack || currentCause.message || String(currentCause)}\n`;
|
|
23
|
-
currentCause = currentCause.cause;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
stackTrace += `Caused by: ${String(currentCause)}\n`;
|
|
27
|
-
currentCause = undefined;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return stackTrace;
|
|
31
|
-
}
|
|
32
12
|
}
|
|
33
13
|
|
|
34
14
|
export { BaseException };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseException.js","sources":["../../../src/exceptions/BaseException.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\
|
|
1
|
+
{"version":3,"file":"BaseException.js","sources":["../../../src/exceptions/BaseException.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * Base class for all custom exceptions in the application.\n * Provides support for error codes and chained exceptions.\n */\nexport class BaseException extends Error {\n code?: number;\n\n constructor(message: string, cause?: unknown, code?: number) {\n super(message,{ cause });\n this.code = code;\n this.name = this.constructor.name;\n }\n}"],"names":[],"mappings":"AAAA;AACA;;;AAGG;AACG,MAAO,aAAc,SAAQ,KAAK,CAAA;AAGpC,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,IAAa,EAAA;AACvD,QAAA,KAAK,CAAC,OAAO,EAAC,EAAE,KAAK,EAAE,CAAC;AACxB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI;IACrC;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientException.js","sources":["../../../src/exceptions/ClientException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\
|
|
1
|
+
{"version":3,"file":"ClientException.js","sources":["../../../src/exceptions/ClientException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\n\n/**\n * Exception thrown for client-side errors.\n * Typically used for HTTP 4xx errors.\n */\nexport class ClientException extends HTTPException {\n\n constructor(message: string, cause?: unknown, code: number = 500) {\n super(message, cause, code);\n }\n}\n\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,MAAO,eAAgB,SAAQ,aAAa,CAAA;AAE9C,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;IAC/B;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConverterException.js","sources":["../../../src/exceptions/ConverterException.ts"],"sourcesContent":["import { BaseException } from \"./BaseException\";\
|
|
1
|
+
{"version":3,"file":"ConverterException.js","sources":["../../../src/exceptions/ConverterException.ts"],"sourcesContent":["import { BaseException } from \"./BaseException\";\n\n/**\n * Exception thrown when a conversion operation fails.\n */\nexport class ConverterException extends BaseException {\n\n constructor(message: string, cause?: unknown) {\n super(message, cause, 500);\n }\n}\n\n"],"names":[],"mappings":";;AAEA;;AAEG;AACG,MAAO,kBAAmB,SAAQ,aAAa,CAAA;IAEjD,WAAA,CAAY,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;IAC9B;AACH;;;;"}
|