@org-quicko/core 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/beans/index.js +2 -0
- package/dist/browser/beans/index.js.map +1 -0
- package/dist/browser/build/browser/index.js +1 -2
- package/dist/browser/build/browser/index.js.map +1 -1
- package/dist/browser/exceptions/BadRequestException.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/exceptions/index.js +9 -0
- package/dist/browser/exceptions/index.js.map +1 -0
- package/dist/browser/types/JSONObject.js +6 -6
- package/dist/browser/types/JSONObject.js.map +1 -1
- package/dist/browser/types/index.js +4 -0
- package/dist/browser/types/index.js.map +1 -0
- package/dist/browser/utils/date/DateUtil.js +6 -1
- package/dist/browser/utils/date/DateUtil.js.map +1 -1
- package/dist/browser/utils/date/index.js +2 -0
- package/dist/browser/utils/date/index.js.map +1 -0
- package/dist/browser/utils/index.js +2 -0
- package/dist/browser/utils/index.js.map +1 -0
- package/dist/cjs/beans/index.cjs +8 -0
- package/dist/cjs/beans/index.cjs.map +1 -0
- package/dist/cjs/build/node/index.cjs +5 -11
- package/dist/cjs/build/node/index.cjs.map +1 -1
- package/dist/cjs/exceptions/BadRequestException.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/exceptions/index.cjs +22 -0
- package/dist/cjs/exceptions/index.cjs.map +1 -0
- package/dist/cjs/logger/LoggerFactory.cjs +44 -0
- package/dist/cjs/logger/LoggerFactory.cjs.map +1 -0
- package/dist/cjs/logger/index.cjs +9 -0
- package/dist/cjs/logger/index.cjs.map +1 -0
- package/dist/cjs/types/JSONObject.cjs +6 -6
- package/dist/cjs/types/JSONObject.cjs.map +1 -1
- package/dist/cjs/types/index.cjs +19 -0
- package/dist/cjs/types/index.cjs.map +1 -0
- package/dist/cjs/utils/date/DateUtil.cjs +5 -0
- package/dist/cjs/utils/date/DateUtil.cjs.map +1 -1
- package/dist/cjs/utils/date/index.cjs +8 -0
- package/dist/cjs/utils/date/index.cjs.map +1 -0
- package/dist/cjs/utils/index.cjs +8 -0
- package/dist/cjs/utils/index.cjs.map +1 -0
- package/dist/esm/beans/index.js +2 -0
- package/dist/esm/beans/index.js.map +1 -0
- package/dist/esm/build/node/index.js +2 -5
- package/dist/esm/build/node/index.js.map +1 -1
- package/dist/esm/exceptions/BadRequestException.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/exceptions/index.js +9 -0
- package/dist/esm/exceptions/index.js.map +1 -0
- package/dist/esm/logger/LoggerFactory.js +41 -0
- package/dist/esm/logger/LoggerFactory.js.map +1 -0
- package/dist/esm/logger/index.js +2 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/types/JSONObject.js +6 -6
- package/dist/esm/types/JSONObject.js.map +1 -1
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/date/DateUtil.js +6 -1
- package/dist/esm/utils/date/DateUtil.js.map +1 -1
- package/dist/esm/utils/date/index.js +2 -0
- package/dist/esm/utils/date/index.js.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/types/index.d.ts +14 -18
- package/dist/types/src/beans/index.d.ts +1 -0
- package/dist/types/src/exceptions/index.d.ts +8 -0
- package/dist/types/src/logger/LoggerFactory.d.ts +19 -0
- package/dist/types/src/logger/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/{utils → src/utils}/date/DateUtil.d.ts +8 -0
- package/dist/types/src/utils/date/index.d.ts +1 -0
- package/dist/types/src/utils/index.d.ts +1 -0
- package/package.json +28 -52
- package/dist/browser/exceptions/NullPointerException.js +0 -13
- package/dist/browser/exceptions/NullPointerException.js.map +0 -1
- package/dist/cjs/exceptions/NullPointerException.cjs +0 -15
- package/dist/cjs/exceptions/NullPointerException.cjs.map +0 -1
- package/dist/cjs/logger/MDC.cjs +0 -77
- package/dist/cjs/logger/MDC.cjs.map +0 -1
- package/dist/cjs/logger/factory/ConsoleLoggerProvider.cjs +0 -43
- package/dist/cjs/logger/factory/ConsoleLoggerProvider.cjs.map +0 -1
- package/dist/cjs/logger/factory/LoggerFactory.cjs +0 -31
- package/dist/cjs/logger/factory/LoggerFactory.cjs.map +0 -1
- package/dist/esm/exceptions/NullPointerException.js +0 -13
- package/dist/esm/exceptions/NullPointerException.js.map +0 -1
- package/dist/esm/logger/MDC.js +0 -75
- package/dist/esm/logger/MDC.js.map +0 -1
- package/dist/esm/logger/factory/ConsoleLoggerProvider.js +0 -41
- package/dist/esm/logger/factory/ConsoleLoggerProvider.js.map +0 -1
- package/dist/esm/logger/factory/LoggerFactory.js +0 -28
- package/dist/esm/logger/factory/LoggerFactory.js.map +0 -1
- package/dist/types/exceptions/NullPointerException.d.ts +0 -10
- package/dist/types/logger/MDC.d.ts +0 -53
- package/dist/types/logger/factory/ConsoleLoggerProvider.d.ts +0 -20
- package/dist/types/logger/factory/LoggerFactory.d.ts +0 -25
- package/dist/types/logger/factory/LoggerProvider.d.ts +0 -16
- /package/dist/types/{beans → src/beans}/BaseObject.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/BadRequestException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/BaseException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/ClientException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/ConverterException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/ForbiddenAccessException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/HTTPException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/IllegalArgumentException.d.ts +0 -0
- /package/dist/types/{exceptions → src/exceptions}/UnauthorizedException.d.ts +0 -0
- /package/dist/types/{types → src/types}/JSONObject.d.ts +0 -0
- /package/dist/types/{types → src/types}/LoggingLevel.d.ts +0 -0
- /package/dist/types/{types → src/types}/SortOrder.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { BaseObject } from '../../beans/BaseObject.js';
|
|
1
2
|
export { BadRequestException } from '../../exceptions/BadRequestException.js';
|
|
2
3
|
export { BaseException } from '../../exceptions/BaseException.js';
|
|
3
4
|
export { ClientException } from '../../exceptions/ClientException.js';
|
|
@@ -5,11 +6,9 @@ export { ForbiddenAccessException } from '../../exceptions/ForbiddenAccessExcept
|
|
|
5
6
|
export { HTTPException } from '../../exceptions/HTTPException.js';
|
|
6
7
|
export { IllegalArgumentException } from '../../exceptions/IllegalArgumentException.js';
|
|
7
8
|
export { UnauthorizedException } from '../../exceptions/UnauthorizedException.js';
|
|
8
|
-
export { NullPointerException } from '../../exceptions/NullPointerException.js';
|
|
9
9
|
export { ConverterException } from '../../exceptions/ConverterException.js';
|
|
10
10
|
export { JSONArray, JSONObject } from '../../types/JSONObject.js';
|
|
11
11
|
export { LoggingLevel } from '../../types/LoggingLevel.js';
|
|
12
12
|
export { SortOrder } from '../../types/SortOrder.js';
|
|
13
|
-
export { BaseObject } from '../../beans/BaseObject.js';
|
|
14
13
|
export { DateUtil } from '../../utils/date/DateUtil.js';
|
|
15
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -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';\r\n\r\n/**\r\n * Exception thrown when a bad request is made to the server.\r\n * Typically used for HTTP 400 errors.\r\n */\r\nexport class BadRequestException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 400) {\r\n super(message, cause, code)\r\n }\r\n}\r\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;;AAElC;;;;"}
|
|
@@ -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';\r\n\r\n/**\r\n * Exception thrown for client-side errors.\r\n * Typically used for HTTP 4xx errors.\r\n */\r\nexport class ClientException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 500) {\r\n super(message, cause, code);\r\n }\r\n}\r\n\r\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;;AAElC;;;;"}
|
|
@@ -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\";\r\n\r\n/**\r\n * Exception thrown when a conversion operation fails.\r\n */\r\nexport class ConverterException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 500);\r\n }\r\n}\r\n\r\n"],"names":[],"mappings":";;AAEA;;AAEG;AACG,MAAO,kBAAmB,SAAQ,aAAa,CAAA;IAEjD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForbiddenAccessException.js","sources":["../../../src/exceptions/ForbiddenAccessException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"ForbiddenAccessException.js","sources":["../../../src/exceptions/ForbiddenAccessException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown when access to a resource is forbidden.\r\n * Typically used for HTTP 403 errors.\r\n */\r\nexport class ForbiddenAccessException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 403);\r\n }\r\n}\r\n\r\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,MAAO,wBAAyB,SAAQ,aAAa,CAAA;IAEvD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTTPException.js","sources":["../../../src/exceptions/HTTPException.ts"],"sourcesContent":["import { BaseException } from './BaseException
|
|
1
|
+
{"version":3,"file":"HTTPException.js","sources":["../../../src/exceptions/HTTPException.ts"],"sourcesContent":["import { BaseException } from './BaseException';\r\n\r\n/**\r\n * Base class for HTTP-related exceptions.\r\n * Provides support for HTTP status codes.\r\n */\r\nexport abstract class HTTPException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 500) {\r\n super(message, cause, code);\r\n }\r\n\r\n}"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,MAAgB,aAAc,SAAQ,aAAa,CAAA;AAErD,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;;AAGlC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IllegalArgumentException.js","sources":["../../../src/exceptions/IllegalArgumentException.ts"],"sourcesContent":["import { BaseException } from './BaseException
|
|
1
|
+
{"version":3,"file":"IllegalArgumentException.js","sources":["../../../src/exceptions/IllegalArgumentException.ts"],"sourcesContent":["import { BaseException } from './BaseException';\r\n\r\n/**\r\n * Exception thrown when an illegal or inappropriate argument is passed.\r\n */\r\nexport class IllegalArgumentException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 500);\r\n }\r\n}\r\n\r\n"],"names":[],"mappings":";;AAEA;;AAEG;AACG,MAAO,wBAAyB,SAAQ,aAAa,CAAA;IAEvD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnauthorizedException.js","sources":["../../../src/exceptions/UnauthorizedException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"UnauthorizedException.js","sources":["../../../src/exceptions/UnauthorizedException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown when a request is unauthorized.\r\n * Typically used for HTTP 401 errors.\r\n */\r\nexport class UnauthorizedException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 401);\r\n }\r\n}\r\n\r\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,MAAO,qBAAsB,SAAQ,aAAa,CAAA;IAEpD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { BadRequestException } from './BadRequestException.js';
|
|
2
|
+
export { BaseException } from './BaseException.js';
|
|
3
|
+
export { ClientException } from './ClientException.js';
|
|
4
|
+
export { ForbiddenAccessException } from './ForbiddenAccessException.js';
|
|
5
|
+
export { HTTPException } from './HTTPException.js';
|
|
6
|
+
export { IllegalArgumentException } from './IllegalArgumentException.js';
|
|
7
|
+
export { UnauthorizedException } from './UnauthorizedException.js';
|
|
8
|
+
export { ConverterException } from './ConverterException.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BaseException } from '../exceptions/BaseException.js';
|
|
1
2
|
import { IllegalArgumentException } from '../exceptions/IllegalArgumentException.js';
|
|
2
|
-
import { NullPointerException } from '../exceptions/NullPointerException.js';
|
|
3
3
|
|
|
4
4
|
class JSONObject extends Map {
|
|
5
5
|
constructor(object) {
|
|
@@ -28,7 +28,7 @@ class JSONObject extends Map {
|
|
|
28
28
|
throw new IllegalArgumentException('Value cannot be converted to JSONObject');
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
throw new
|
|
31
|
+
throw new BaseException(`Value for Key: '${key}' not found`);
|
|
32
32
|
}
|
|
33
33
|
getString(key) {
|
|
34
34
|
if (super.has(key)) {
|
|
@@ -42,7 +42,7 @@ class JSONObject extends Map {
|
|
|
42
42
|
throw new IllegalArgumentException('Value cannot be converted to string', e);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
throw new
|
|
45
|
+
throw new BaseException(`Value for Key: '${key}' not found`);
|
|
46
46
|
}
|
|
47
47
|
getNumber(key) {
|
|
48
48
|
if (super.has(key)) {
|
|
@@ -52,7 +52,7 @@ class JSONObject extends Map {
|
|
|
52
52
|
}
|
|
53
53
|
throw new IllegalArgumentException('Value cannot be converted to number');
|
|
54
54
|
}
|
|
55
|
-
throw new
|
|
55
|
+
throw new BaseException(`Value for Key: '${key}' not found`);
|
|
56
56
|
}
|
|
57
57
|
getBoolean(key) {
|
|
58
58
|
if (super.has(key)) {
|
|
@@ -64,7 +64,7 @@ class JSONObject extends Map {
|
|
|
64
64
|
}
|
|
65
65
|
throw new IllegalArgumentException('Value cannot be converted to boolean');
|
|
66
66
|
}
|
|
67
|
-
throw new
|
|
67
|
+
throw new BaseException(`Value for Key: '${key}' not found`);
|
|
68
68
|
}
|
|
69
69
|
getArray(key) {
|
|
70
70
|
if (super.has(key)) {
|
|
@@ -76,7 +76,7 @@ class JSONObject extends Map {
|
|
|
76
76
|
}
|
|
77
77
|
throw new IllegalArgumentException('Value cannot be converted to array');
|
|
78
78
|
}
|
|
79
|
-
throw new
|
|
79
|
+
throw new BaseException(`Value for Key: '${key}' not found`);
|
|
80
80
|
}
|
|
81
81
|
toJSON() {
|
|
82
82
|
const obj = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONObject.js","sources":["../../../src/types/JSONObject.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"JSONObject.js","sources":["../../../src/types/JSONObject.ts"],"sourcesContent":["import { BaseException, IllegalArgumentException } from '../exceptions';\r\n\r\nexport type JSONValue =\r\n | string\r\n | number\r\n | boolean\r\n | null\r\n | undefined\r\n // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\r\n | Object\r\n\r\nexport class JSONObject extends Map<string, JSONValue> {\r\n\r\n\r\n constructor(object?: { [x: string]: JSONValue }) {\r\n super()\r\n if (object) {\r\n for (const [key, value] of Object.entries(object)) {\r\n if (value === null || value === undefined) {\r\n // ignore\r\n } else if (value.constructor == Object) {\r\n this.set(key, new JSONObject(value as { [x: string]: JSONValue }));\r\n } else if (value.constructor == Array) {\r\n this.set(key, new JSONArray(value));\r\n } else {\r\n this.set(key, value)\r\n }\r\n }\r\n }\r\n\r\n\r\n }\r\n\r\n getJSONObject(key: string): JSONObject {\r\n if (super.has(key)) {\r\n if (super.get(key) instanceof JSONObject) {\r\n return super.get(key) as JSONObject\r\n } else {\r\n throw new IllegalArgumentException('Value cannot be converted to JSONObject')\r\n }\r\n }\r\n\r\n throw new BaseException(`Value for Key: '${key}' not found`);\r\n }\r\n\r\n getString(key: string): string {\r\n if (super.has(key)) {\r\n try {\r\n if (typeof super.get(key) === 'string') {\r\n return super.get(key) as string;\r\n }\r\n\r\n throw new IllegalArgumentException('Value cannot be converted to string')\r\n } catch (e) {\r\n throw new IllegalArgumentException('Value cannot be converted to string', e)\r\n }\r\n }\r\n throw new BaseException(`Value for Key: '${key}' not found`);\r\n }\r\n\r\n getNumber(key: string): number {\r\n if (super.has(key)) {\r\n const number = Number(super.get(key));\r\n if (!isNaN(number)) {\r\n return number;\r\n }\r\n throw new IllegalArgumentException('Value cannot be converted to number')\r\n }\r\n throw new BaseException(`Value for Key: '${key}' not found`);\r\n }\r\n\r\n getBoolean(key: string): boolean {\r\n if (super.has(key)) {\r\n if (typeof super.get(key) === 'boolean') {\r\n return super.get(key) as boolean;\r\n } else if (super.get(key) === 'true' || super.get(key) === 'false') {\r\n return Boolean(super.get(key));\r\n }\r\n throw new IllegalArgumentException('Value cannot be converted to boolean')\r\n }\r\n throw new BaseException(`Value for Key: '${key}' not found`);\r\n }\r\n\r\n getArray(key: string): JSONArray {\r\n if (super.has(key)) {\r\n if (super.get(key) instanceof JSONArray) {\r\n return super.get(key) as JSONArray;\r\n }\r\n else if (super.get(key) instanceof Array) {\r\n return new JSONArray(super.get(key) as Array<JSONValue>);\r\n }\r\n throw new IllegalArgumentException('Value cannot be converted to array')\r\n }\r\n throw new BaseException(`Value for Key: '${key}' not found`);\r\n }\r\n\r\n public toJSON(): { [x: string]: JSONValue } {\r\n const obj: { [x: string]: JSONValue } = {};\r\n for (const [key, value] of this.entries()) {\r\n if (value == null) {\r\n obj[key] = value;\r\n } else if (value instanceof JSONObject || value instanceof JSONArray) {\r\n obj[key] = value.toJSON();\r\n } else {\r\n obj[key] = value\r\n }\r\n }\r\n return obj;\r\n }\r\n}\r\n\r\n\r\nexport class JSONArray extends Array<JSONValue> {\r\n\r\n constructor(array?: Array<JSONValue>) {\r\n super();\r\n if (array) {\r\n for (let item of Object.values(array)) {\r\n item = JSON.parse(JSON.stringify(item))\r\n\r\n if (item == null) {\r\n this.push(item);\r\n }\r\n else if (item.constructor == Object) {\r\n this.push(new JSONObject(item as { [x: string]: JSONValue }));\r\n }\r\n else if (item.constructor == Array) {\r\n this.push(new JSONArray(item));\r\n }\r\n else {\r\n this.push(item)\r\n }\r\n }\r\n }\r\n }\r\n\r\n public toJSON(): Array<JSONValue> {\r\n const arr: Array<JSONValue> = [];\r\n for (const value of this) {\r\n if (value == null) {\r\n arr.push(value);\r\n } else if (value instanceof JSONObject || value instanceof JSONArray) {\r\n arr.push(value.toJSON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C,IAAI,CAAC,CAAC;AAEvC,gBAAA,IAAI,IAAI,IAAI,IAAI,EAAE;AACd,oBAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEd,qBAAA,IAAI,IAAI,CAAC,WAAW,IAAI,MAAM,EAAE;oBACjC,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAkC,CAAC,CAAC;;AAE5D,qBAAA,IAAI,IAAI,CAAC,WAAW,IAAI,KAAK,EAAE;oBAChC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;;qBAE7B;AACD,oBAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;IAMxB,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;;iBACZ,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,SAAS,EAAE;gBAClE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;;iBACrB;AACH,gBAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;;;AAGvB,QAAA,OAAO,GAAG;;AAEjB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TZDate } from '@date-fns/tz';
|
|
2
|
-
import { parse, isValid, format, startOfDay, endOfDay, differenceInCalendarDays, differenceInCalendarMonths, differenceInCalendarYears, compareAsc, add, isLeapYear } from 'date-fns';
|
|
2
|
+
import { parse, isValid, format, startOfDay, endOfDay, differenceInCalendarDays, differenceInCalendarMonths, differenceInYears, differenceInCalendarYears, compareAsc, add, isLeapYear } from 'date-fns';
|
|
3
3
|
import { IllegalArgumentException } from '../../exceptions/IllegalArgumentException.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -76,6 +76,11 @@ class BaseDateUtil {
|
|
|
76
76
|
const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;
|
|
77
77
|
return Math.abs(differenceInCalendarMonths(first, second));
|
|
78
78
|
}
|
|
79
|
+
static anniversaryYearsInBetween(firstDate, secondDate) {
|
|
80
|
+
const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;
|
|
81
|
+
const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;
|
|
82
|
+
return Math.abs(differenceInYears(first, second));
|
|
83
|
+
}
|
|
79
84
|
static yearsInBetween(firstDate, secondDate) {
|
|
80
85
|
const first = typeof firstDate === 'number' ? new Date(firstDate) : firstDate;
|
|
81
86
|
const second = typeof secondDate === 'number' ? new Date(secondDate) : secondDate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateUtil.js","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/IllegalArgumentException.js';\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":[],"mappings":";;;;AAIA;;;AAGG;AACH,MAAM,YAAY,CAAA;aAEE,IAAe,CAAA,eAAA,GAAG,8BAA8B,CAAA;AAEhE;;;;AAIG;IACO,OAAO,GAAG,CAAC,QAAgB,EAAA;QACjC,OAAO,IAAI,MAAM,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,GAAG,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC/D,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;AAChB,YAAA,MAAM,IAAI,wBAAwB,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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,CAAC,IAAmB,EAAA;AAC3C,QAAA,MAAM,cAAc,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;QACvE,OAAO,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC;;;;;;"}
|
|
1
|
+
{"version":3,"file":"DateUtil.js","sources":["../../../../src/utils/date/DateUtil.ts"],"sourcesContent":["import { TZDate } from '@date-fns/tz';\r\nimport { add, compareAsc, differenceInCalendarDays, differenceInCalendarMonths, differenceInCalendarYears, differenceInYears, 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 anniversaryYearsInBetween(firstDate: Date, secondDate: Date): number;\r\n static anniversaryYearsInBetween(firstDate: number, secondDate: number): number;\r\n static anniversaryYearsInBetween(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(differenceInYears(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":[],"mappings":";;;;AAIA;;;AAGG;AACH,MAAM,YAAY,CAAA;aAEE,IAAe,CAAA,eAAA,GAAG,8BAA8B,CAAA;AAEhE;;;;AAIG;IACO,OAAO,GAAG,CAAC,QAAgB,EAAA;QACjC,OAAO,IAAI,MAAM,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,GAAG,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC/D,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;AAChB,YAAA,MAAM,IAAI,wBAAwB,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,G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AAI,CAAC,GAAG,IAAI;AACvE,QAAA,OAAO,YAAY,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;;IAU5E,OAAgB,aAAa,CAAC,IAAmB,EAAA;AAC7C,QAAA,MAAM,cAAc,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;QACvE,OAAO,YAAY,CAAC,aAAa,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC;;IAUpE,OAAgB,WAAW,CAAC,IAAmB,EAAA;AAC3C,QAAA,MAAM,cAAc,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;QACvE,OAAO,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var BaseObject = require('../../beans/BaseObject.cjs');
|
|
3
4
|
var BadRequestException = require('../../exceptions/BadRequestException.cjs');
|
|
4
5
|
var BaseException = require('../../exceptions/BaseException.cjs');
|
|
5
6
|
var ClientException = require('../../exceptions/ClientException.cjs');
|
|
@@ -7,19 +8,16 @@ var ForbiddenAccessException = require('../../exceptions/ForbiddenAccessExceptio
|
|
|
7
8
|
var HTTPException = require('../../exceptions/HTTPException.cjs');
|
|
8
9
|
var IllegalArgumentException = require('../../exceptions/IllegalArgumentException.cjs');
|
|
9
10
|
var UnauthorizedException = require('../../exceptions/UnauthorizedException.cjs');
|
|
10
|
-
var NullPointerException = require('../../exceptions/NullPointerException.cjs');
|
|
11
11
|
var ConverterException = require('../../exceptions/ConverterException.cjs');
|
|
12
|
+
var LoggerFactory = require('../../logger/LoggerFactory.cjs');
|
|
12
13
|
var JSONObject = require('../../types/JSONObject.cjs');
|
|
13
14
|
var LoggingLevel = require('../../types/LoggingLevel.cjs');
|
|
14
15
|
var SortOrder = require('../../types/SortOrder.cjs');
|
|
15
|
-
var BaseObject = require('../../beans/BaseObject.cjs');
|
|
16
16
|
var DateUtil = require('../../utils/date/DateUtil.cjs');
|
|
17
|
-
var ConsoleLoggerProvider = require('../../logger/factory/ConsoleLoggerProvider.cjs');
|
|
18
|
-
var LoggerFactory = require('../../logger/factory/LoggerFactory.cjs');
|
|
19
|
-
var MDC = require('../../logger/MDC.cjs');
|
|
20
17
|
|
|
21
18
|
|
|
22
19
|
|
|
20
|
+
exports.BaseObject = BaseObject.BaseObject;
|
|
23
21
|
exports.BadRequestException = BadRequestException.BadRequestException;
|
|
24
22
|
exports.BaseException = BaseException.BaseException;
|
|
25
23
|
exports.ClientException = ClientException.ClientException;
|
|
@@ -27,8 +25,9 @@ exports.ForbiddenAccessException = ForbiddenAccessException.ForbiddenAccessExcep
|
|
|
27
25
|
exports.HTTPException = HTTPException.HTTPException;
|
|
28
26
|
exports.IllegalArgumentException = IllegalArgumentException.IllegalArgumentException;
|
|
29
27
|
exports.UnauthorizedException = UnauthorizedException.UnauthorizedException;
|
|
30
|
-
exports.NullPointerException = NullPointerException.NullPointerException;
|
|
31
28
|
exports.ConverterException = ConverterException.ConverterException;
|
|
29
|
+
exports.LoggerFactory = LoggerFactory.LoggerFactory;
|
|
30
|
+
exports.loggers = LoggerFactory.loggers;
|
|
32
31
|
exports.JSONArray = JSONObject.JSONArray;
|
|
33
32
|
exports.JSONObject = JSONObject.JSONObject;
|
|
34
33
|
Object.defineProperty(exports, "LoggingLevel", {
|
|
@@ -39,10 +38,5 @@ Object.defineProperty(exports, "SortOrder", {
|
|
|
39
38
|
enumerable: true,
|
|
40
39
|
get: function () { return SortOrder.SortOrder; }
|
|
41
40
|
});
|
|
42
|
-
exports.BaseObject = BaseObject.BaseObject;
|
|
43
41
|
exports.DateUtil = DateUtil.DateUtil;
|
|
44
|
-
exports.ConsoleLoggerProvider = ConsoleLoggerProvider.ConsoleLoggerProvider;
|
|
45
|
-
exports.LoggerFactory = LoggerFactory.LoggerFactory;
|
|
46
|
-
exports.LoggerStorage = LoggerFactory.LoggerStorage;
|
|
47
|
-
exports.MDC = MDC.MDC;
|
|
48
42
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -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":"BadRequestException.cjs","sources":["../../../src/exceptions/BadRequestException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"BadRequestException.cjs","sources":["../../../src/exceptions/BadRequestException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown when a bad request is made to the server.\r\n * Typically used for HTTP 400 errors.\r\n */\r\nexport class BadRequestException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 400) {\r\n super(message, cause, code)\r\n }\r\n}\r\n"],"names":["HTTPException"],"mappings":";;;;AAEA;;;AAGG;AACG,MAAO,mBAAoB,SAAQA,2BAAa,CAAA;AAElD,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;;AAElC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientException.cjs","sources":["../../../src/exceptions/ClientException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"ClientException.cjs","sources":["../../../src/exceptions/ClientException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown for client-side errors.\r\n * Typically used for HTTP 4xx errors.\r\n */\r\nexport class ClientException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 500) {\r\n super(message, cause, code);\r\n }\r\n}\r\n\r\n"],"names":["HTTPException"],"mappings":";;;;AAEA;;;AAGG;AACG,MAAO,eAAgB,SAAQA,2BAAa,CAAA;AAE9C,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;;AAElC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConverterException.cjs","sources":["../../../src/exceptions/ConverterException.ts"],"sourcesContent":["import { BaseException } from \"./BaseException
|
|
1
|
+
{"version":3,"file":"ConverterException.cjs","sources":["../../../src/exceptions/ConverterException.ts"],"sourcesContent":["import { BaseException } from \"./BaseException\";\r\n\r\n/**\r\n * Exception thrown when a conversion operation fails.\r\n */\r\nexport class ConverterException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 500);\r\n }\r\n}\r\n\r\n"],"names":["BaseException"],"mappings":";;;;AAEA;;AAEG;AACG,MAAO,kBAAmB,SAAQA,2BAAa,CAAA;IAEjD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForbiddenAccessException.cjs","sources":["../../../src/exceptions/ForbiddenAccessException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"ForbiddenAccessException.cjs","sources":["../../../src/exceptions/ForbiddenAccessException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown when access to a resource is forbidden.\r\n * Typically used for HTTP 403 errors.\r\n */\r\nexport class ForbiddenAccessException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 403);\r\n }\r\n}\r\n\r\n"],"names":["HTTPException"],"mappings":";;;;AAEA;;;AAGG;AACG,MAAO,wBAAyB,SAAQA,2BAAa,CAAA;IAEvD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTTPException.cjs","sources":["../../../src/exceptions/HTTPException.ts"],"sourcesContent":["import { BaseException } from './BaseException
|
|
1
|
+
{"version":3,"file":"HTTPException.cjs","sources":["../../../src/exceptions/HTTPException.ts"],"sourcesContent":["import { BaseException } from './BaseException';\r\n\r\n/**\r\n * Base class for HTTP-related exceptions.\r\n * Provides support for HTTP status codes.\r\n */\r\nexport abstract class HTTPException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown, code: number = 500) {\r\n super(message, cause, code);\r\n }\r\n\r\n}"],"names":["BaseException"],"mappings":";;;;AAEA;;;AAGG;AACG,MAAgB,aAAc,SAAQA,2BAAa,CAAA;AAErD,IAAA,WAAA,CAAY,OAAe,EAAE,KAAe,EAAE,OAAe,GAAG,EAAA;AAC5D,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;;AAGlC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IllegalArgumentException.cjs","sources":["../../../src/exceptions/IllegalArgumentException.ts"],"sourcesContent":["import { BaseException } from './BaseException
|
|
1
|
+
{"version":3,"file":"IllegalArgumentException.cjs","sources":["../../../src/exceptions/IllegalArgumentException.ts"],"sourcesContent":["import { BaseException } from './BaseException';\r\n\r\n/**\r\n * Exception thrown when an illegal or inappropriate argument is passed.\r\n */\r\nexport class IllegalArgumentException extends BaseException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 500);\r\n }\r\n}\r\n\r\n"],"names":["BaseException"],"mappings":";;;;AAEA;;AAEG;AACG,MAAO,wBAAyB,SAAQA,2BAAa,CAAA;IAEvD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnauthorizedException.cjs","sources":["../../../src/exceptions/UnauthorizedException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException
|
|
1
|
+
{"version":3,"file":"UnauthorizedException.cjs","sources":["../../../src/exceptions/UnauthorizedException.ts"],"sourcesContent":["import { HTTPException } from './HTTPException';\r\n\r\n/**\r\n * Exception thrown when a request is unauthorized.\r\n * Typically used for HTTP 401 errors.\r\n */\r\nexport class UnauthorizedException extends HTTPException {\r\n\r\n constructor(message: string, cause?: unknown) {\r\n super(message, cause, 401);\r\n }\r\n}\r\n\r\n"],"names":["HTTPException"],"mappings":";;;;AAEA;;;AAGG;AACG,MAAO,qBAAsB,SAAQA,2BAAa,CAAA;IAEpD,WAAY,CAAA,OAAe,EAAE,KAAe,EAAA;AACxC,QAAA,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;;AAEjC;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var BadRequestException = require('./BadRequestException.cjs');
|
|
4
|
+
var BaseException = require('./BaseException.cjs');
|
|
5
|
+
var ClientException = require('./ClientException.cjs');
|
|
6
|
+
var ForbiddenAccessException = require('./ForbiddenAccessException.cjs');
|
|
7
|
+
var HTTPException = require('./HTTPException.cjs');
|
|
8
|
+
var IllegalArgumentException = require('./IllegalArgumentException.cjs');
|
|
9
|
+
var UnauthorizedException = require('./UnauthorizedException.cjs');
|
|
10
|
+
var ConverterException = require('./ConverterException.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.BadRequestException = BadRequestException.BadRequestException;
|
|
15
|
+
exports.BaseException = BaseException.BaseException;
|
|
16
|
+
exports.ClientException = ClientException.ClientException;
|
|
17
|
+
exports.ForbiddenAccessException = ForbiddenAccessException.ForbiddenAccessException;
|
|
18
|
+
exports.HTTPException = HTTPException.HTTPException;
|
|
19
|
+
exports.IllegalArgumentException = IllegalArgumentException.IllegalArgumentException;
|
|
20
|
+
exports.UnauthorizedException = UnauthorizedException.UnauthorizedException;
|
|
21
|
+
exports.ConverterException = ConverterException.ConverterException;
|
|
22
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var winston = require('winston');
|
|
4
|
+
var ClientException = require('../exceptions/ClientException.cjs');
|
|
5
|
+
var LoggingLevel = require('../types/LoggingLevel.cjs');
|
|
6
|
+
require('../types/SortOrder.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A factory class for managing logger instances.
|
|
10
|
+
* Provides methods to retrieve and store loggers in a shared storage.
|
|
11
|
+
*/
|
|
12
|
+
const loggers = new Map();
|
|
13
|
+
class LoggerFactory {
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a logger instance by its name.
|
|
16
|
+
*
|
|
17
|
+
* @param name The name of the logger to retrieve.
|
|
18
|
+
* @returns The logger instance if found, otherwise `undefined`.
|
|
19
|
+
*/
|
|
20
|
+
static createLogger(name, level = LoggingLevel.LoggingLevel.info, format) {
|
|
21
|
+
const label = typeof name === "string" ? name : "Unknown";
|
|
22
|
+
if (loggers.has(label)) {
|
|
23
|
+
return loggers.get(label);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const defaultFormat = winston.format.combine(winston.format.timestamp(), winston.format.json());
|
|
27
|
+
const logger = winston.createLogger({
|
|
28
|
+
level: level,
|
|
29
|
+
format: format ? winston.format.combine(format, defaultFormat) : defaultFormat,
|
|
30
|
+
defaultMeta: { label },
|
|
31
|
+
transports: [new winston.transports.Console()],
|
|
32
|
+
});
|
|
33
|
+
loggers.set(label, logger);
|
|
34
|
+
return logger;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new ClientException.ClientException(`Error creating logger`, error, 500);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.LoggerFactory = LoggerFactory;
|
|
43
|
+
exports.loggers = loggers;
|
|
44
|
+
//# sourceMappingURL=LoggerFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoggerFactory.cjs","sources":["../../../src/logger/LoggerFactory.ts"],"sourcesContent":["import winston from \"winston\";\r\nimport { ClientException } from \"../exceptions\";\r\nimport { LoggingLevel } from \"../types\";\r\n\r\n/**\r\n * A factory class for managing logger instances.\r\n * Provides methods to retrieve and store loggers in a shared storage.\r\n */\r\nexport const loggers: Map<string, winston.Logger> = new Map<string, winston.Logger>();\r\n\r\nexport class LoggerFactory {\r\n /**\r\n * Retrieves a logger instance by its name.\r\n *\r\n * @param name The name of the logger to retrieve.\r\n * @returns The logger instance if found, otherwise `undefined`.\r\n */\r\n static createLogger(\r\n name: string,\r\n level: LoggingLevel = LoggingLevel.info,\r\n format?: winston.Logform.Format\r\n ): winston.Logger {\r\n\r\n const label = typeof name === \"string\" ? name : \"Unknown\";\r\n\r\n if (loggers.has(label)) {\r\n return loggers.get(label)!;\r\n }\r\n\r\n try {\r\n\r\n const defaultFormat = winston.format.combine(\r\n winston.format.timestamp(),\r\n winston.format.json()\r\n );\r\n\r\n const logger = winston.createLogger({\r\n level: level,\r\n format: format ? winston.format.combine(format, defaultFormat) : defaultFormat,\r\n defaultMeta: { label },\r\n transports: [new winston.transports.Console()],\r\n });\r\n\r\n loggers.set(label, logger);\r\n\r\n return logger;\r\n } catch (error) {\r\n throw new ClientException(`Error creating logger`, error, 500);\r\n }\r\n }\r\n}\r\n"],"names":["LoggingLevel","ClientException"],"mappings":";;;;;;;AAIA;;;AAGG;AACU,MAAA,OAAO,GAAgC,IAAI,GAAG;MAE9C,aAAa,CAAA;AACxB;;;;;AAKG;IACH,OAAO,YAAY,CACjB,IAAY,EACZ,QAAsBA,yBAAY,CAAC,IAAI,EACvC,MAA+B,EAAA;AAG/B,QAAA,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,GAAG,SAAS;AAEzD,QAAA,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AACtB,YAAA,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAE;;AAG5B,QAAA,IAAI;YAEF,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAC1C,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAC1B,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CACtB;AAED,YAAA,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;AAClC,gBAAA,KAAK,EAAE,KAAK;AACZ,gBAAA,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,aAAa;gBAC9E,WAAW,EAAE,EAAE,KAAK,EAAE;gBACtB,UAAU,EAAE,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;AAC/C,aAAA,CAAC;AAEF,YAAA,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC;AAE1B,YAAA,OAAO,MAAM;;QACb,OAAO,KAAK,EAAE;YACd,MAAM,IAAIC,+BAAe,CAAC,CAAA,qBAAA,CAAuB,EAAE,KAAK,EAAE,GAAG,CAAC;;;AAGnE;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var BaseException = require('../exceptions/BaseException.cjs');
|
|
3
4
|
var IllegalArgumentException = require('../exceptions/IllegalArgumentException.cjs');
|
|
4
|
-
var NullPointerException = require('../exceptions/NullPointerException.cjs');
|
|
5
5
|
|
|
6
6
|
class JSONObject extends Map {
|
|
7
7
|
constructor(object) {
|
|
@@ -30,7 +30,7 @@ class JSONObject extends Map {
|
|
|
30
30
|
throw new IllegalArgumentException.IllegalArgumentException('Value cannot be converted to JSONObject');
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
throw new
|
|
33
|
+
throw new BaseException.BaseException(`Value for Key: '${key}' not found`);
|
|
34
34
|
}
|
|
35
35
|
getString(key) {
|
|
36
36
|
if (super.has(key)) {
|
|
@@ -44,7 +44,7 @@ class JSONObject extends Map {
|
|
|
44
44
|
throw new IllegalArgumentException.IllegalArgumentException('Value cannot be converted to string', e);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
throw new
|
|
47
|
+
throw new BaseException.BaseException(`Value for Key: '${key}' not found`);
|
|
48
48
|
}
|
|
49
49
|
getNumber(key) {
|
|
50
50
|
if (super.has(key)) {
|
|
@@ -54,7 +54,7 @@ class JSONObject extends Map {
|
|
|
54
54
|
}
|
|
55
55
|
throw new IllegalArgumentException.IllegalArgumentException('Value cannot be converted to number');
|
|
56
56
|
}
|
|
57
|
-
throw new
|
|
57
|
+
throw new BaseException.BaseException(`Value for Key: '${key}' not found`);
|
|
58
58
|
}
|
|
59
59
|
getBoolean(key) {
|
|
60
60
|
if (super.has(key)) {
|
|
@@ -66,7 +66,7 @@ class JSONObject extends Map {
|
|
|
66
66
|
}
|
|
67
67
|
throw new IllegalArgumentException.IllegalArgumentException('Value cannot be converted to boolean');
|
|
68
68
|
}
|
|
69
|
-
throw new
|
|
69
|
+
throw new BaseException.BaseException(`Value for Key: '${key}' not found`);
|
|
70
70
|
}
|
|
71
71
|
getArray(key) {
|
|
72
72
|
if (super.has(key)) {
|
|
@@ -78,7 +78,7 @@ class JSONObject extends Map {
|
|
|
78
78
|
}
|
|
79
79
|
throw new IllegalArgumentException.IllegalArgumentException('Value cannot be converted to array');
|
|
80
80
|
}
|
|
81
|
-
throw new
|
|
81
|
+
throw new BaseException.BaseException(`Value for Key: '${key}' not found`);
|
|
82
82
|
}
|
|
83
83
|
toJSON() {
|
|
84
84
|
const obj = {};
|