@org-quicko/core 1.0.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/README.md +8 -0
- package/dist/cjs/beans/BaseObject.cjs +76 -0
- package/dist/cjs/beans/BaseObject.cjs.map +1 -0
- package/dist/cjs/exceptions/BadRequestException.cjs +16 -0
- package/dist/cjs/exceptions/BadRequestException.cjs.map +1 -0
- package/dist/cjs/exceptions/BaseException.cjs +37 -0
- package/dist/cjs/exceptions/BaseException.cjs.map +1 -0
- package/dist/cjs/exceptions/ClientException.cjs +16 -0
- package/dist/cjs/exceptions/ClientException.cjs.map +1 -0
- package/dist/cjs/exceptions/ConverterException.cjs +15 -0
- package/dist/cjs/exceptions/ConverterException.cjs.map +1 -0
- package/dist/cjs/exceptions/ForbiddenAccessException.cjs +16 -0
- package/dist/cjs/exceptions/ForbiddenAccessException.cjs.map +1 -0
- package/dist/cjs/exceptions/HTTPException.cjs +16 -0
- package/dist/cjs/exceptions/HTTPException.cjs.map +1 -0
- package/dist/cjs/exceptions/IllegalArgumentException.cjs +15 -0
- package/dist/cjs/exceptions/IllegalArgumentException.cjs.map +1 -0
- package/dist/cjs/exceptions/NullPointerException.cjs +15 -0
- package/dist/cjs/exceptions/NullPointerException.cjs.map +1 -0
- package/dist/cjs/exceptions/UnauthorizedException.cjs +16 -0
- package/dist/cjs/exceptions/UnauthorizedException.cjs.map +1 -0
- package/dist/cjs/index.cjs +48 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/logger/MDC.cjs +77 -0
- package/dist/cjs/logger/MDC.cjs.map +1 -0
- package/dist/cjs/logger/factory/ConsoleLoggerProvider.cjs +43 -0
- package/dist/cjs/logger/factory/ConsoleLoggerProvider.cjs.map +1 -0
- package/dist/cjs/logger/factory/LoggerFactory.cjs +31 -0
- package/dist/cjs/logger/factory/LoggerFactory.cjs.map +1 -0
- package/dist/cjs/types/JSONObject.cjs +139 -0
- package/dist/cjs/types/JSONObject.cjs.map +1 -0
- package/dist/cjs/types/LoggingLevel.cjs +12 -0
- package/dist/cjs/types/LoggingLevel.cjs.map +1 -0
- package/dist/cjs/types/SortOrder.cjs +12 -0
- package/dist/cjs/types/SortOrder.cjs.map +1 -0
- package/dist/cjs/utils/date/DateUtil.cjs +159 -0
- package/dist/cjs/utils/date/DateUtil.cjs.map +1 -0
- package/dist/esm/beans/BaseObject.js +74 -0
- package/dist/esm/beans/BaseObject.js.map +1 -0
- package/dist/esm/exceptions/BadRequestException.js +14 -0
- package/dist/esm/exceptions/BadRequestException.js.map +1 -0
- package/dist/esm/exceptions/BaseException.js +35 -0
- package/dist/esm/exceptions/BaseException.js.map +1 -0
- package/dist/esm/exceptions/ClientException.js +14 -0
- package/dist/esm/exceptions/ClientException.js.map +1 -0
- package/dist/esm/exceptions/ConverterException.js +13 -0
- package/dist/esm/exceptions/ConverterException.js.map +1 -0
- package/dist/esm/exceptions/ForbiddenAccessException.js +14 -0
- package/dist/esm/exceptions/ForbiddenAccessException.js.map +1 -0
- package/dist/esm/exceptions/HTTPException.js +14 -0
- package/dist/esm/exceptions/HTTPException.js.map +1 -0
- package/dist/esm/exceptions/IllegalArgumentException.js +13 -0
- package/dist/esm/exceptions/IllegalArgumentException.js.map +1 -0
- package/dist/esm/exceptions/NullPointerException.js +13 -0
- package/dist/esm/exceptions/NullPointerException.js.map +1 -0
- package/dist/esm/exceptions/UnauthorizedException.js +14 -0
- package/dist/esm/exceptions/UnauthorizedException.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/MDC.js +75 -0
- package/dist/esm/logger/MDC.js.map +1 -0
- package/dist/esm/logger/factory/ConsoleLoggerProvider.js +41 -0
- package/dist/esm/logger/factory/ConsoleLoggerProvider.js.map +1 -0
- package/dist/esm/logger/factory/LoggerFactory.js +28 -0
- package/dist/esm/logger/factory/LoggerFactory.js.map +1 -0
- package/dist/esm/types/JSONObject.js +136 -0
- package/dist/esm/types/JSONObject.js.map +1 -0
- package/dist/esm/types/LoggingLevel.js +12 -0
- package/dist/esm/types/LoggingLevel.js.map +1 -0
- package/dist/esm/types/SortOrder.js +12 -0
- package/dist/esm/types/SortOrder.js.map +1 -0
- package/dist/esm/utils/date/DateUtil.js +157 -0
- package/dist/esm/utils/date/DateUtil.js.map +1 -0
- package/dist/types/beans/BaseObject.d.ts +37 -0
- package/dist/types/exceptions/BadRequestException.d.ts +11 -0
- package/dist/types/exceptions/BaseException.d.ts +16 -0
- package/dist/types/exceptions/ClientException.d.ts +11 -0
- package/dist/types/exceptions/ConverterException.d.ts +10 -0
- package/dist/types/exceptions/ForbiddenAccessException.d.ts +11 -0
- package/dist/types/exceptions/HTTPException.d.ts +11 -0
- package/dist/types/exceptions/IllegalArgumentException.d.ts +10 -0
- package/dist/types/exceptions/NullPointerException.d.ts +10 -0
- package/dist/types/exceptions/UnauthorizedException.d.ts +11 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/logger/MDC.d.ts +53 -0
- package/dist/types/logger/factory/ConsoleLoggerProvider.d.ts +20 -0
- package/dist/types/logger/factory/LoggerFactory.d.ts +25 -0
- package/dist/types/logger/factory/LoggerProvider.d.ts +16 -0
- package/dist/types/types/JSONObject.d.ts +21 -0
- package/dist/types/types/LoggingLevel.d.ts +10 -0
- package/dist/types/types/SortOrder.d.ts +10 -0
- package/dist/types/utils/date/DateUtil.d.ts +164 -0
- package/package.json +166 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `BaseObject` class serves as a base model for objects with common properties
|
|
3
|
+
* such as `id`, `description`, `createdAt`, and `updatedAt`. It includes validation
|
|
4
|
+
* and transformation decorators for serialization and deserialization.
|
|
5
|
+
*
|
|
6
|
+
* Properties:
|
|
7
|
+
* - `id` (string | undefined): A unique identifier for the object.
|
|
8
|
+
* - `description` (string | undefined): A brief description of the object.
|
|
9
|
+
* - `createdAt` (number | undefined): The timestamp when the object was created.
|
|
10
|
+
* - `updatedAt` (number | undefined): The timestamp when the object was last updated.
|
|
11
|
+
*
|
|
12
|
+
* Methods:
|
|
13
|
+
* - `getId()`: Returns the `id` of the object.
|
|
14
|
+
* - `setId(value: string | undefined)`: Sets the `id` of the object.
|
|
15
|
+
* - `getDescription()`: Returns the `description` of the object.
|
|
16
|
+
* - `setDescription(value: string | undefined)`: Sets the `description` of the object.
|
|
17
|
+
* - `getCreatedAt()`: Returns the `createdAt` timestamp of the object.
|
|
18
|
+
* - `setCreatedAt(value?: number)`: Sets the `createdAt` timestamp of the object.
|
|
19
|
+
* - `getUpdatedAt()`: Returns the `updatedAt` timestamp of the object.
|
|
20
|
+
* - `setUpdatedAt(value?: number)`: Sets the `updatedAt` timestamp of the object.
|
|
21
|
+
*/
|
|
22
|
+
declare class BaseObject {
|
|
23
|
+
private id?;
|
|
24
|
+
private description?;
|
|
25
|
+
private createdAt?;
|
|
26
|
+
private updatedAt?;
|
|
27
|
+
getId(): string | undefined;
|
|
28
|
+
setId(value: string | undefined): void;
|
|
29
|
+
getCreatedAt(): number | undefined;
|
|
30
|
+
setCreatedAt(value?: number): void;
|
|
31
|
+
getUpdatedAt(): number | undefined;
|
|
32
|
+
setUpdatedAt(value?: number): void;
|
|
33
|
+
getDescription(): string | undefined;
|
|
34
|
+
setDescription(value?: string): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { BaseObject };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTPException } from './HTTPException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when a bad request is made to the server.
|
|
5
|
+
* Typically used for HTTP 400 errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class BadRequestException extends HTTPException {
|
|
8
|
+
constructor(message: string, cause?: unknown, code?: number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { BadRequestException };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all custom exceptions in the application.
|
|
3
|
+
* Provides support for error codes and chained exceptions.
|
|
4
|
+
*/
|
|
5
|
+
declare class BaseException extends Error {
|
|
6
|
+
code?: number;
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
constructor(message: string, cause?: unknown, code?: number);
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the full stack trace of the exception, including causes.
|
|
11
|
+
* @returns A string representation of the stack trace.
|
|
12
|
+
*/
|
|
13
|
+
getStackTrace(): string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { BaseException };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTPException } from './HTTPException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown for client-side errors.
|
|
5
|
+
* Typically used for HTTP 4xx errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class ClientException extends HTTPException {
|
|
8
|
+
constructor(message: string, cause?: unknown, code?: number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { ClientException };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseException } from './BaseException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when a conversion operation fails.
|
|
5
|
+
*/
|
|
6
|
+
declare class ConverterException extends BaseException {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { ConverterException };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTPException } from './HTTPException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when access to a resource is forbidden.
|
|
5
|
+
* Typically used for HTTP 403 errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class ForbiddenAccessException extends HTTPException {
|
|
8
|
+
constructor(message: string, cause?: unknown);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { ForbiddenAccessException };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseException } from './BaseException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class for HTTP-related exceptions.
|
|
5
|
+
* Provides support for HTTP status codes.
|
|
6
|
+
*/
|
|
7
|
+
declare abstract class HTTPException extends BaseException {
|
|
8
|
+
constructor(message: string, cause?: unknown, code?: number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { HTTPException };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseException } from './BaseException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when an illegal or inappropriate argument is passed.
|
|
5
|
+
*/
|
|
6
|
+
declare class IllegalArgumentException extends BaseException {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { IllegalArgumentException };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseException } from './BaseException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when an operation is attempted on a `null` or `undefined` value.
|
|
5
|
+
*/
|
|
6
|
+
declare class NullPointerException extends BaseException {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { NullPointerException };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTPException } from './HTTPException.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exception thrown when a request is unauthorized.
|
|
5
|
+
* Typically used for HTTP 401 errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class UnauthorizedException extends HTTPException {
|
|
8
|
+
constructor(message: string, cause?: unknown);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { UnauthorizedException };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { BadRequestException } from './exceptions/BadRequestException.js';
|
|
2
|
+
export { BaseException } from './exceptions/BaseException.js';
|
|
3
|
+
export { ClientException } from './exceptions/ClientException.js';
|
|
4
|
+
export { ForbiddenAccessException } from './exceptions/ForbiddenAccessException.js';
|
|
5
|
+
export { HTTPException } from './exceptions/HTTPException.js';
|
|
6
|
+
export { IllegalArgumentException } from './exceptions/IllegalArgumentException.js';
|
|
7
|
+
export { UnauthorizedException } from './exceptions/UnauthorizedException.js';
|
|
8
|
+
export { NullPointerException } from './exceptions/NullPointerException.js';
|
|
9
|
+
export { ConverterException } from './exceptions/ConverterException.js';
|
|
10
|
+
export { ConsoleLoggerProvider } from './logger/factory/ConsoleLoggerProvider.js';
|
|
11
|
+
export { LoggerFactory, LoggerStorage } from './logger/factory/LoggerFactory.js';
|
|
12
|
+
export { LoggerProvider } from './logger/factory/LoggerProvider.js';
|
|
13
|
+
export { ContextMap, MDC } from './logger/MDC.js';
|
|
14
|
+
export { JSONArray, JSONObject, JSONValue } from './types/JSONObject.js';
|
|
15
|
+
export { LoggingLevel } from './types/LoggingLevel.js';
|
|
16
|
+
export { SortOrder } from './types/SortOrder.js';
|
|
17
|
+
export { BaseObject } from './beans/BaseObject.js';
|
|
18
|
+
export { DateUtil } from './utils/date/DateUtil.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
interface ContextMap {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Mapped Diagnostic Context (MDC) implementation using `AsyncLocalStorage`.
|
|
6
|
+
* MDC allows associating contextual information (key-value pairs) with the
|
|
7
|
+
* current execution context, which can be useful for logging and tracing.
|
|
8
|
+
*
|
|
9
|
+
* Methods:
|
|
10
|
+
* - `get(key: string)`: Retrieves the value associated with the given key in the current context.
|
|
11
|
+
* - `put(key: string, value: string)`: Adds or updates a key-value pair in the current context.
|
|
12
|
+
* - `putAll(context: ContextMap)`: Adds or updates multiple key-value pairs in the current context.
|
|
13
|
+
* - `clear()`: Clears all key-value pairs in the current context.
|
|
14
|
+
* - `runWithContext(context: ContextMap, callback: () => T)`: Runs a callback function with the provided context.
|
|
15
|
+
*/
|
|
16
|
+
declare class MDC {
|
|
17
|
+
private static storage;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the value associated with the given key in the current context.
|
|
20
|
+
*
|
|
21
|
+
* @param key The key to retrieve the value for.
|
|
22
|
+
* @returns The value associated with the key, or `undefined` if not found.
|
|
23
|
+
*/
|
|
24
|
+
static get(key: string): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Adds or updates a key-value pair in the current context.
|
|
27
|
+
*
|
|
28
|
+
* @param key The key to add or update.
|
|
29
|
+
* @param value The value to associate with the key.
|
|
30
|
+
*/
|
|
31
|
+
static put(key: string, value: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Adds or updates multiple key-value pairs in the current context.
|
|
34
|
+
*
|
|
35
|
+
* @param context An object containing key-value pairs to add or update.
|
|
36
|
+
*/
|
|
37
|
+
static putAll(context: ContextMap): void;
|
|
38
|
+
/**
|
|
39
|
+
* Clears all key-value pairs in the current context.
|
|
40
|
+
*/
|
|
41
|
+
static clear(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Runs a callback function with the provided context.
|
|
44
|
+
*
|
|
45
|
+
* @param context The context to associate with the callback execution.
|
|
46
|
+
* @param callback The callback function to execute.
|
|
47
|
+
* @returns The result of the callback function.
|
|
48
|
+
*/
|
|
49
|
+
static runWithContext<T>(context: ContextMap, callback: () => T): T;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { MDC };
|
|
53
|
+
export type { ContextMap };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import { LoggerProvider } from './LoggerProvider.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Implementation of the `LoggerProvider` interface that creates
|
|
6
|
+
* a Winston logger configured to log to the console.
|
|
7
|
+
*/
|
|
8
|
+
declare class ConsoleLoggerProvider implements LoggerProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Winston logger instance configured for console logging.
|
|
11
|
+
* The logger includes MDC (Mapped Diagnostic Context) data, timestamps,
|
|
12
|
+
* and JSON formatting.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise that resolves to a Winston logger instance.
|
|
15
|
+
* @throws ClientException If an error occurs while creating the logger.
|
|
16
|
+
*/
|
|
17
|
+
createLogger(): Promise<winston.Logger>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ConsoleLoggerProvider };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import winston, { Logger } from 'winston';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A factory class for managing logger instances.
|
|
5
|
+
* Provides methods to retrieve and store loggers in a shared storage.
|
|
6
|
+
*/
|
|
7
|
+
declare const LoggerStorage: Map<string, winston.Logger>;
|
|
8
|
+
declare class LoggerFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves a logger instance by its name.
|
|
11
|
+
*
|
|
12
|
+
* @param loggerName The name of the logger to retrieve.
|
|
13
|
+
* @returns The logger instance if found, otherwise `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
static getLogger(loggerName: string): winston.Logger | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Stores a logger instance with the specified name.
|
|
18
|
+
*
|
|
19
|
+
* @param loggerName The name to associate with the logger.
|
|
20
|
+
* @param logger The logger instance to store.
|
|
21
|
+
*/
|
|
22
|
+
static setLogger(loggerName: string, logger: Logger): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { LoggerFactory, LoggerStorage };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for creating logger instances.
|
|
5
|
+
* Provides a method to create a logger with optional configuration.
|
|
6
|
+
*/
|
|
7
|
+
interface LoggerProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a logger instance.
|
|
10
|
+
* @param config Optional configuration for the logger.
|
|
11
|
+
* @returns A promise that resolves to a Winston logger instance.
|
|
12
|
+
*/
|
|
13
|
+
createLogger(config?: unknown): Promise<winston.Logger>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type { LoggerProvider };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type JSONValue = string | number | boolean | null | undefined | Object;
|
|
2
|
+
declare class JSONObject extends Map<string, JSONValue> {
|
|
3
|
+
constructor(object?: {
|
|
4
|
+
[x: string]: JSONValue;
|
|
5
|
+
});
|
|
6
|
+
getJSONObject(key: string): JSONObject;
|
|
7
|
+
getString(key: string): string;
|
|
8
|
+
getNumber(key: string): number;
|
|
9
|
+
getBoolean(key: string): boolean;
|
|
10
|
+
getArray(key: string): JSONArray;
|
|
11
|
+
toJSON(): {
|
|
12
|
+
[x: string]: JSONValue;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
declare class JSONArray extends Array<JSONValue> {
|
|
16
|
+
constructor(array?: Array<JSONValue>);
|
|
17
|
+
toJSON(): Array<JSONValue>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { JSONArray, JSONObject };
|
|
21
|
+
export type { JSONValue };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Duration } from 'date-fns';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for date and time operations. Provides methods for parsing,
|
|
5
|
+
* formatting, and performing calculations with dates and times.
|
|
6
|
+
*/
|
|
7
|
+
declare class BaseDateUtil {
|
|
8
|
+
static readonly ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSxxx";
|
|
9
|
+
/**
|
|
10
|
+
* Gets the current date and time in the specified time zone.
|
|
11
|
+
* @param timeZone The IANA time zone identifier.
|
|
12
|
+
* @returns Current date and time in the specified time zone.
|
|
13
|
+
*/
|
|
14
|
+
protected static now(timeZone: string): Date;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the current time in milliseconds since the Unix epoch.
|
|
17
|
+
* @returns Current time in milliseconds.
|
|
18
|
+
*/
|
|
19
|
+
static nowInMillis(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a date string into a Date object.
|
|
22
|
+
* @param dateString The date string to parse.
|
|
23
|
+
* @param dateFormat The format of the date string (default: ISO_8601_FORMAT).
|
|
24
|
+
* @param timeZone The IANA time zone identifier.
|
|
25
|
+
* @throws {IllegalArgumentException} If the date string is invalid.
|
|
26
|
+
* @returns Parsed Date object.
|
|
27
|
+
*/
|
|
28
|
+
protected static readDate(dateString: string, dateFormat: string | undefined, timeZone: string): Date;
|
|
29
|
+
/**
|
|
30
|
+
* Formats a Date or timestamp into a string.
|
|
31
|
+
* @param date The date or timestamp to format.
|
|
32
|
+
* @param timeZone The IANA time zone identifier.
|
|
33
|
+
* @param dateFormat The desired output format (default: ISO_8601_FORMAT).
|
|
34
|
+
* @returns Formatted date string.
|
|
35
|
+
*/
|
|
36
|
+
protected static printDate(date: Date, timeZone: string, dateFormat?: string): string;
|
|
37
|
+
protected static printDate(date: number, timeZone: string, dateFormat?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the start of the day for a given date or timestamp.
|
|
40
|
+
* @param date The date or timestamp to calculate from.
|
|
41
|
+
* @param timeZone The IANA time zone identifier.
|
|
42
|
+
* @returns The start of the day as a Date object.
|
|
43
|
+
*/
|
|
44
|
+
protected static getStartOfDay(date: Date, timeZone: string): Date;
|
|
45
|
+
protected static getStartOfDay(date: number, timeZone: string): Date;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the end of the day for a given date or timestamp.
|
|
48
|
+
* @param date The date or timestamp to calculate from.
|
|
49
|
+
* @param timeZone The IANA time zone identifier.
|
|
50
|
+
* @returns The end of the day as a Date object.
|
|
51
|
+
*/
|
|
52
|
+
protected static getEndOfDay(date: Date, timeZone: string): Date;
|
|
53
|
+
protected static getEndOfDay(date: number, timeZone: string): Date;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a date string is valid according to the specified format.
|
|
56
|
+
* @param dateString The date string to validate.
|
|
57
|
+
* @param dateFormat Optional date format (default: ISO_8601_FORMAT).
|
|
58
|
+
* @returns True if the date is valid, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
static isValidDate(dateString: string, dateFormat?: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Calculates the absolute number of days between two dates or timestamps.
|
|
63
|
+
* @param firstDate The first date or timestamp.
|
|
64
|
+
* @param secondDate The second date or timestamp.
|
|
65
|
+
* @returns Number of days between the two dates.
|
|
66
|
+
*/
|
|
67
|
+
static daysInBetween(firstDate: Date, secondDate: Date): number;
|
|
68
|
+
static daysInBetween(firstDate: number, secondDate: number): number;
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the absolute number of months between two dates or timestamps.
|
|
71
|
+
* @param firstDate The first date or timestamp.
|
|
72
|
+
* @param secondDate The second date or timestamp.
|
|
73
|
+
* @returns The number of months between the two dates.
|
|
74
|
+
*/
|
|
75
|
+
static monthsInBetween(firstDate: Date, secondDate: Date): number;
|
|
76
|
+
static monthsInBetween(firstDate: number, secondDate: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Calculates the absolute number of years between two dates or timestamps.
|
|
79
|
+
* @param firstDate The first date or timestamp.
|
|
80
|
+
* @param secondDate The second date or timestamp.
|
|
81
|
+
* @returns The number of years between the two dates.
|
|
82
|
+
*/
|
|
83
|
+
static yearsInBetween(firstDate: Date, secondDate: Date): number;
|
|
84
|
+
static yearsInBetween(firstDate: number, secondDate: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Compares two dates or timestamps.
|
|
87
|
+
* @param firstDate The first date or timestamp.
|
|
88
|
+
* @param secondDate The second date or timestamp.
|
|
89
|
+
* @returns `-1` if the first date is earlier, `1` if it is later, or `0` if the two dates are equal.
|
|
90
|
+
*/
|
|
91
|
+
static compareDates(firstDate: Date, secondDate: Date): -1 | 0 | 1;
|
|
92
|
+
static compareDates(firstDate: number, secondDate: number): -1 | 0 | 1;
|
|
93
|
+
/**
|
|
94
|
+
* Adds a duration (e.g., days, months, years) to a given date or timestamp.
|
|
95
|
+
* @param date The base date or timestamp to which the duration will be added.
|
|
96
|
+
* @param duration An object specifying the duration (e.g., `{ days: 1, months: 2 }`).
|
|
97
|
+
* @returns A new Date object with the duration added.
|
|
98
|
+
*/
|
|
99
|
+
static addDuration(date: Date, duration: Duration): Date;
|
|
100
|
+
static addDuration(date: number, duration: Duration): Date;
|
|
101
|
+
/**
|
|
102
|
+
* Determines whether a given year is a leap year.
|
|
103
|
+
* @param year The year to check.
|
|
104
|
+
* @returns `true` if the year is a leap year, otherwise `false`.
|
|
105
|
+
*/
|
|
106
|
+
static isLeapYear(year: number): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Converts a timestamp (in milliseconds) to a Date object.
|
|
109
|
+
* @param milliseconds The timestamp in milliseconds since the Unix epoch.
|
|
110
|
+
* @returns A Date object representing the provided timestamp.
|
|
111
|
+
*/
|
|
112
|
+
static fromMillis(milliseconds: number): Date;
|
|
113
|
+
/**
|
|
114
|
+
* Converts a Date object to a timestamp (in milliseconds).
|
|
115
|
+
* @param date The Date object to convert.
|
|
116
|
+
* @returns The timestamp in milliseconds since the Unix epoch.
|
|
117
|
+
*/
|
|
118
|
+
static toMillis(date: Date): number;
|
|
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
|
+
declare class DateUtil extends BaseDateUtil {
|
|
125
|
+
/** Default time zone used for all date operations. */
|
|
126
|
+
static readonly 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(): Date;
|
|
132
|
+
/**
|
|
133
|
+
* Parses a date string into a Date object using the default time zone.
|
|
134
|
+
* @param dateString The date string to parse.
|
|
135
|
+
* @param dateFormat Optional format of the date string (default: ISO_8601_FORMAT).
|
|
136
|
+
* @throws {IllegalArgumentException} If the date string is invalid.
|
|
137
|
+
* @returns Parsed Date object.
|
|
138
|
+
*/
|
|
139
|
+
static readDate(dateString: string, dateFormat?: string): Date;
|
|
140
|
+
/**
|
|
141
|
+
* Formats a Date or timestamp into a string using the default time zone.
|
|
142
|
+
* @param date The date or timestamp to format.
|
|
143
|
+
* @param dateFormat Optional desired output format (default: ISO_8601_FORMAT).
|
|
144
|
+
* @returns Formatted date string.
|
|
145
|
+
*/
|
|
146
|
+
static printDate(date: Date, dateFormat?: string): string;
|
|
147
|
+
static printDate(date: number, dateFormat?: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the start of the day for a given date or timestamp using the default time zone.
|
|
150
|
+
* @param date The date or timestamp to calculate from.
|
|
151
|
+
* @returns A Date object representing the start of the day.
|
|
152
|
+
*/
|
|
153
|
+
static getStartOfDay(date: Date): Date;
|
|
154
|
+
static getStartOfDay(date: number): Date;
|
|
155
|
+
/**
|
|
156
|
+
* Gets the end of the day for a given date or timestamp using the default time zone.
|
|
157
|
+
* @param date The date or timestamp to calculate from.
|
|
158
|
+
* @returns A Date object representing the end of the day.
|
|
159
|
+
*/
|
|
160
|
+
static getEndOfDay(date: Date): Date;
|
|
161
|
+
static getEndOfDay(date: number): Date;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { DateUtil };
|
package/package.json
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@org-quicko/core",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A library in typescript for common entities and utilities across Quicko",
|
|
5
|
+
"author": "Quicko",
|
|
6
|
+
"main": "dist/cjs/index.cjs",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/types/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rm -rf dist && npm cache clean --force",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix",
|
|
14
|
+
"prebuild": "npm run clean && npm run lint",
|
|
15
|
+
"build": "rollup -c"
|
|
16
|
+
},
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
|
+
"node": {
|
|
25
|
+
"import": "./dist/esm/index.js",
|
|
26
|
+
"require": "./dist/cjs/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"browser": {
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"default": "./dist/esm/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./beans": {
|
|
35
|
+
"types": "./dist/types/src/beans/index.d.ts",
|
|
36
|
+
"node": {
|
|
37
|
+
"import": "./dist/esm/src/beans/index.js",
|
|
38
|
+
"require": "./dist/cjs/src/beans/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"browser": {
|
|
41
|
+
"import": "./dist/esm/src/beans/index.js",
|
|
42
|
+
"require": "./dist/cjs/src/beans/index.cjs"
|
|
43
|
+
},
|
|
44
|
+
"default": "./dist/esm/src/beans/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./types": {
|
|
47
|
+
"types": "./dist/types/src/types/index.d.ts",
|
|
48
|
+
"node": {
|
|
49
|
+
"import": "./dist/esm/src/types/index.js",
|
|
50
|
+
"require": "./dist/cjs/src/types/index.cjs"
|
|
51
|
+
},
|
|
52
|
+
"browser": {
|
|
53
|
+
"import": "./dist/esm/src/types/index.js",
|
|
54
|
+
"require": "./dist/cjs/src/types/index.cjs"
|
|
55
|
+
},
|
|
56
|
+
"default": "./dist/esm/src/types/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./utils": {
|
|
59
|
+
"types": "./dist/types/src/utils/index.d.ts",
|
|
60
|
+
"node": {
|
|
61
|
+
"import": "./dist/esm/src/utils/index.js",
|
|
62
|
+
"require": "./dist/cjs/src/utils/index.cjs"
|
|
63
|
+
},
|
|
64
|
+
"browser": {
|
|
65
|
+
"import": "./dist/esm/src/utils/index.js",
|
|
66
|
+
"require": "./dist/cjs/src/utils/index.cjs"
|
|
67
|
+
},
|
|
68
|
+
"default": "./dist/esm/src/utils/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./utils/date": {
|
|
71
|
+
"types": "./dist/types/src/utils/date/index.d.ts",
|
|
72
|
+
"node": {
|
|
73
|
+
"import": "./dist/esm/src/utils/date/index.js",
|
|
74
|
+
"require": "./dist/cjs/src/utils/date/index.cjs"
|
|
75
|
+
},
|
|
76
|
+
"browser": {
|
|
77
|
+
"import": "./dist/esm/src/utils/date/index.js",
|
|
78
|
+
"require": "./dist/cjs/src/utils/date/index.cjs"
|
|
79
|
+
},
|
|
80
|
+
"default": "./dist/esm/src/utils/date/index.js"
|
|
81
|
+
},
|
|
82
|
+
"./logger": {
|
|
83
|
+
"types": "./dist/types/src/logger/index.d.ts",
|
|
84
|
+
"node": {
|
|
85
|
+
"import": "./dist/esm/src/logger/index.js",
|
|
86
|
+
"require": "./dist/cjs/src/logger/index.cjs"
|
|
87
|
+
},
|
|
88
|
+
"browser": {
|
|
89
|
+
"import": "./dist/esm/src/logger/index.js",
|
|
90
|
+
"require": "./dist/cjs/src/logger/index.cjs"
|
|
91
|
+
},
|
|
92
|
+
"default": "./dist/esm/src/logger/index.js"
|
|
93
|
+
},
|
|
94
|
+
"./exceptions": {
|
|
95
|
+
"types": "./dist/types/src/exceptions/index.d.ts",
|
|
96
|
+
"node": {
|
|
97
|
+
"import": "./dist/esm/src/exceptions/index.js",
|
|
98
|
+
"require": "./dist/cjs/src/exceptions/index.cjs"
|
|
99
|
+
},
|
|
100
|
+
"browser": {
|
|
101
|
+
"import": "./dist/esm/src/exceptions/index.js",
|
|
102
|
+
"require": "./dist/cjs/src/exceptions/index.cjs"
|
|
103
|
+
},
|
|
104
|
+
"default": "./dist/esm/src/exceptions/index.js"
|
|
105
|
+
},
|
|
106
|
+
"./package.json": "./package.json"
|
|
107
|
+
},
|
|
108
|
+
"typesVersions": {
|
|
109
|
+
"*": {
|
|
110
|
+
"*": [
|
|
111
|
+
"dist/types/*"
|
|
112
|
+
],
|
|
113
|
+
"beans": [
|
|
114
|
+
"dist/types/src/beans/index.d.ts"
|
|
115
|
+
],
|
|
116
|
+
"types": [
|
|
117
|
+
"dist/types/src/types/index.d.ts"
|
|
118
|
+
],
|
|
119
|
+
"utils": [
|
|
120
|
+
"dist/types/src/utils/index.d.ts"
|
|
121
|
+
],
|
|
122
|
+
"utils/date": [
|
|
123
|
+
"dist/types/src/utils/date/index.d.ts"
|
|
124
|
+
],
|
|
125
|
+
"exceptions": [
|
|
126
|
+
"dist/types/src/exceptions/index.d.ts"
|
|
127
|
+
],
|
|
128
|
+
"logger": [
|
|
129
|
+
"dist/types/src/logger/index.d.ts"
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"directories": {
|
|
134
|
+
"lib": "./dist"
|
|
135
|
+
},
|
|
136
|
+
"engines": {
|
|
137
|
+
"node": ">=14"
|
|
138
|
+
},
|
|
139
|
+
"dependencies": {
|
|
140
|
+
"@date-fns/tz": "^1.1.2",
|
|
141
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
142
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
143
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
144
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
145
|
+
"class-transformer": "^0.5.1",
|
|
146
|
+
"class-validator": "^0.14.1",
|
|
147
|
+
"date-fns": "^4.1.0",
|
|
148
|
+
"rollup-plugin-bundle-size": "^1.0.3",
|
|
149
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
150
|
+
"tslib": "^2.8.1",
|
|
151
|
+
"winston": "^3.17.0"
|
|
152
|
+
},
|
|
153
|
+
"devDependencies": {
|
|
154
|
+
"@types/node": "^22.7.0",
|
|
155
|
+
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
|
156
|
+
"@typescript-eslint/parser": "^8.17.0",
|
|
157
|
+
"esbuild-plugin-eslint": "^0.3.7",
|
|
158
|
+
"eslint": "^8.2.0",
|
|
159
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
160
|
+
"eslint-config-prettier": "^9.1.0",
|
|
161
|
+
"eslint-import-resolver-typescript": "^3.7.0",
|
|
162
|
+
"rollup": "^4.40.2",
|
|
163
|
+
"ts-node": "^10.9.2",
|
|
164
|
+
"typescript": "^5.6.2"
|
|
165
|
+
}
|
|
166
|
+
}
|