@xeno-js/shared 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +675 -678
- package/dist/axios.cjs +2230 -0
- package/dist/axios.cjs.map +1 -0
- package/dist/axios.d.cts +19 -0
- package/dist/axios.d.ts +19 -0
- package/dist/axios.js +2203 -0
- package/dist/axios.js.map +1 -0
- package/dist/common.types-DT8JtZ0E.d.cts +214 -0
- package/dist/common.types-DT8JtZ0E.d.ts +214 -0
- package/dist/iauth-service.contracts-DotziBbm.d.ts +230 -0
- package/dist/iauth-service.contracts-DyFYvLdb.d.cts +230 -0
- package/dist/ihttp-client.contracts-DX2hDTW6.d.ts +299 -0
- package/dist/ihttp-client.contracts-KMkYuIHH.d.cts +299 -0
- package/dist/index.cjs +2 -348
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +973 -2295
- package/dist/index.d.ts +973 -2295
- package/dist/index.js +1 -341
- package/dist/index.js.map +1 -1
- package/dist/ivalidator-service.contracts-DGMounqU.d.cts +102 -0
- package/dist/ivalidator-service.contracts-ulue7FGh.d.ts +102 -0
- package/dist/result.types-BNTzjCgR.d.cts +381 -0
- package/dist/result.types-DRyxvpQs.d.ts +381 -0
- package/dist/supabase.cjs +2431 -0
- package/dist/supabase.cjs.map +1 -0
- package/dist/supabase.d.cts +53 -0
- package/dist/supabase.d.ts +53 -0
- package/dist/supabase.js +2402 -0
- package/dist/supabase.js.map +1 -0
- package/dist/zod.cjs +2372 -0
- package/dist/zod.cjs.map +1 -0
- package/dist/zod.d.cts +63 -0
- package/dist/zod.d.ts +63 -0
- package/dist/zod.js +2344 -0
- package/dist/zod.js.map +1 -0
- package/package.json +17 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { O as Optional } from './common.types-DT8JtZ0E.cjs';
|
|
2
|
+
import { R as ResultType } from './result.types-BNTzjCgR.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description Interface for a logger that provides methods for logging messages at different levels (info, warn, error, debug) and tracking exceptions. Each logging method accepts a message and an optional context, while the error method also accepts an optional Error object.
|
|
6
|
+
|
|
7
|
+
*
|
|
8
|
+
* @author Xeno
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
* @since 2025-09-30
|
|
11
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
12
|
+
*/
|
|
13
|
+
interface ILogger {
|
|
14
|
+
/**
|
|
15
|
+
* Log a message at the info level with an optional context.
|
|
16
|
+
* @param message The message to log.
|
|
17
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
18
|
+
|
|
19
|
+
*
|
|
20
|
+
* @author Xeno
|
|
21
|
+
* @version 1.0.0
|
|
22
|
+
* @since 2025-09-30
|
|
23
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
24
|
+
*/
|
|
25
|
+
info(message: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log a message at the warning level with an optional context.
|
|
28
|
+
* @param message The message to log.
|
|
29
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
30
|
+
|
|
31
|
+
*
|
|
32
|
+
* @author Xeno
|
|
33
|
+
* @version 1.0.0
|
|
34
|
+
* @since 2025-09-30
|
|
35
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
36
|
+
*/
|
|
37
|
+
warn(message: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Log a message at the error level with an optional error object and context.
|
|
40
|
+
* @param message The message to log.
|
|
41
|
+
* @param error An optional unknown object associated with the log message.
|
|
42
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
43
|
+
|
|
44
|
+
*
|
|
45
|
+
* @author Xeno
|
|
46
|
+
* @version 1.0.0
|
|
47
|
+
* @since 2025-09-30
|
|
48
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
49
|
+
*/
|
|
50
|
+
error(message: string, error: Optional<unknown>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Log a message at the debug level with an optional context.
|
|
53
|
+
* @param message The message to log.
|
|
54
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
55
|
+
|
|
56
|
+
*
|
|
57
|
+
* @author Xeno
|
|
58
|
+
* @version 1.0.0
|
|
59
|
+
* @since 2025-09-30
|
|
60
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
61
|
+
*/
|
|
62
|
+
debug(message: string): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description Interface for a validation service that provides methods to check for the existence of validation schemas and to validate data against those schemas. The IValidatorService interface defines two methods: hasSchema, which checks if a validation schema exists for a given key, and validate, which validates data against a specified schema key and returns a ResultType indicating the success or failure of the validation process. This interface can be implemented by various validation services that utilize different schema validation libraries or custom validation logic to ensure that incoming data meets the required criteria before being processed further in the application.
|
|
67
|
+
|
|
68
|
+
*
|
|
69
|
+
* @author Xeno
|
|
70
|
+
* @version 1.0.0
|
|
71
|
+
* @since 2025-09-30
|
|
72
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
73
|
+
*/
|
|
74
|
+
interface IValidatorService {
|
|
75
|
+
/**
|
|
76
|
+
* @description Validates the provided data against the validation schema associated with the specified key. This method performs the actual validation logic, checking if the data conforms to the rules defined in the corresponding schema. It returns a ResultType indicating whether the validation was successful or if it failed, along with any relevant error information if the validation did not pass.
|
|
77
|
+
* @param key The key representing the type of data or request for which the validation is being performed. This key is used to identify the appropriate validation schema to apply to the data.
|
|
78
|
+
* @param data The data to be validated against the schema. This can be any type of data that needs to be checked for conformity with the validation rules defined in the schema.
|
|
79
|
+
* @returns A ResultType indicating the outcome of the validation. If the validation is successful, it returns a ResultType with a value of true; if the validation fails, it returns a ResultType with a value of false and includes error information.
|
|
80
|
+
|
|
81
|
+
*
|
|
82
|
+
* @author Xeno
|
|
83
|
+
* @version 1.0.0
|
|
84
|
+
* @since 2025-09-30
|
|
85
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
86
|
+
*/
|
|
87
|
+
validate<T>(key: string, data: T): Promise<ResultType<boolean>>;
|
|
88
|
+
/**
|
|
89
|
+
* @description Adds a new validation schema to the service's registry, associating it with the specified key. This method allows for dynamically registering validation schemas that can be used later for validating incoming data. The schema must conform to the expected structure defined by the validation library being used (e.g., Zod schemas). By adding schemas to the service, it enables the application to perform validation checks against those schemas when processing requests or data that require validation.
|
|
90
|
+
* @param key The key representing the type of data or request for which the validation schema is being added. This key is used to identify the schema when performing validation checks.
|
|
91
|
+
* @param schema The validation schema to be added, which defines the rules and structure that incoming data must conform to in order to pass validation. The specific type of the schema will depend on the validation library being used (e.g., ZodType for Zod schemas).
|
|
92
|
+
|
|
93
|
+
*
|
|
94
|
+
* @author Xeno
|
|
95
|
+
* @version 1.0.0
|
|
96
|
+
* @since 2025-09-30
|
|
97
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
98
|
+
*/
|
|
99
|
+
addSchema(key: string, schema: unknown): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { ILogger as I, IValidatorService as a };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { O as Optional } from './common.types-DT8JtZ0E.js';
|
|
2
|
+
import { R as ResultType } from './result.types-DRyxvpQs.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description Interface for a logger that provides methods for logging messages at different levels (info, warn, error, debug) and tracking exceptions. Each logging method accepts a message and an optional context, while the error method also accepts an optional Error object.
|
|
6
|
+
|
|
7
|
+
*
|
|
8
|
+
* @author Xeno
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
* @since 2025-09-30
|
|
11
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
12
|
+
*/
|
|
13
|
+
interface ILogger {
|
|
14
|
+
/**
|
|
15
|
+
* Log a message at the info level with an optional context.
|
|
16
|
+
* @param message The message to log.
|
|
17
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
18
|
+
|
|
19
|
+
*
|
|
20
|
+
* @author Xeno
|
|
21
|
+
* @version 1.0.0
|
|
22
|
+
* @since 2025-09-30
|
|
23
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
24
|
+
*/
|
|
25
|
+
info(message: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log a message at the warning level with an optional context.
|
|
28
|
+
* @param message The message to log.
|
|
29
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
30
|
+
|
|
31
|
+
*
|
|
32
|
+
* @author Xeno
|
|
33
|
+
* @version 1.0.0
|
|
34
|
+
* @since 2025-09-30
|
|
35
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
36
|
+
*/
|
|
37
|
+
warn(message: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Log a message at the error level with an optional error object and context.
|
|
40
|
+
* @param message The message to log.
|
|
41
|
+
* @param error An optional unknown object associated with the log message.
|
|
42
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
43
|
+
|
|
44
|
+
*
|
|
45
|
+
* @author Xeno
|
|
46
|
+
* @version 1.0.0
|
|
47
|
+
* @since 2025-09-30
|
|
48
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
49
|
+
*/
|
|
50
|
+
error(message: string, error: Optional<unknown>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Log a message at the debug level with an optional context.
|
|
53
|
+
* @param message The message to log.
|
|
54
|
+
* @param context An optional dictionary containing additional context for the log message.
|
|
55
|
+
|
|
56
|
+
*
|
|
57
|
+
* @author Xeno
|
|
58
|
+
* @version 1.0.0
|
|
59
|
+
* @since 2025-09-30
|
|
60
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
61
|
+
*/
|
|
62
|
+
debug(message: string): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description Interface for a validation service that provides methods to check for the existence of validation schemas and to validate data against those schemas. The IValidatorService interface defines two methods: hasSchema, which checks if a validation schema exists for a given key, and validate, which validates data against a specified schema key and returns a ResultType indicating the success or failure of the validation process. This interface can be implemented by various validation services that utilize different schema validation libraries or custom validation logic to ensure that incoming data meets the required criteria before being processed further in the application.
|
|
67
|
+
|
|
68
|
+
*
|
|
69
|
+
* @author Xeno
|
|
70
|
+
* @version 1.0.0
|
|
71
|
+
* @since 2025-09-30
|
|
72
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
73
|
+
*/
|
|
74
|
+
interface IValidatorService {
|
|
75
|
+
/**
|
|
76
|
+
* @description Validates the provided data against the validation schema associated with the specified key. This method performs the actual validation logic, checking if the data conforms to the rules defined in the corresponding schema. It returns a ResultType indicating whether the validation was successful or if it failed, along with any relevant error information if the validation did not pass.
|
|
77
|
+
* @param key The key representing the type of data or request for which the validation is being performed. This key is used to identify the appropriate validation schema to apply to the data.
|
|
78
|
+
* @param data The data to be validated against the schema. This can be any type of data that needs to be checked for conformity with the validation rules defined in the schema.
|
|
79
|
+
* @returns A ResultType indicating the outcome of the validation. If the validation is successful, it returns a ResultType with a value of true; if the validation fails, it returns a ResultType with a value of false and includes error information.
|
|
80
|
+
|
|
81
|
+
*
|
|
82
|
+
* @author Xeno
|
|
83
|
+
* @version 1.0.0
|
|
84
|
+
* @since 2025-09-30
|
|
85
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
86
|
+
*/
|
|
87
|
+
validate<T>(key: string, data: T): Promise<ResultType<boolean>>;
|
|
88
|
+
/**
|
|
89
|
+
* @description Adds a new validation schema to the service's registry, associating it with the specified key. This method allows for dynamically registering validation schemas that can be used later for validating incoming data. The schema must conform to the expected structure defined by the validation library being used (e.g., Zod schemas). By adding schemas to the service, it enables the application to perform validation checks against those schemas when processing requests or data that require validation.
|
|
90
|
+
* @param key The key representing the type of data or request for which the validation schema is being added. This key is used to identify the schema when performing validation checks.
|
|
91
|
+
* @param schema The validation schema to be added, which defines the rules and structure that incoming data must conform to in order to pass validation. The specific type of the schema will depend on the validation library being used (e.g., ZodType for Zod schemas).
|
|
92
|
+
|
|
93
|
+
*
|
|
94
|
+
* @author Xeno
|
|
95
|
+
* @version 1.0.0
|
|
96
|
+
* @since 2025-09-30
|
|
97
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
98
|
+
*/
|
|
99
|
+
addSchema(key: string, schema: unknown): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { ILogger as I, IValidatorService as a };
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { O as Optional, M as Maybe } from './common.types-DT8JtZ0E.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A class representing an application error, which extends the built-in Error class.
|
|
5
|
+
* It includes additional properties such as an error code and an HTTP status code.
|
|
6
|
+
|
|
7
|
+
*
|
|
8
|
+
* @author Xeno
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
* @since 2025-09-30
|
|
11
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
12
|
+
*/
|
|
13
|
+
interface ErrorPayload {
|
|
14
|
+
/** The error message describing the error.
|
|
15
|
+
*
|
|
16
|
+
* @author Xeno
|
|
17
|
+
* @version 1.0.0
|
|
18
|
+
* @since 2025-09-30
|
|
19
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
20
|
+
*/
|
|
21
|
+
message: string;
|
|
22
|
+
/** The error code representing the type of error.
|
|
23
|
+
*
|
|
24
|
+
* @author Xeno
|
|
25
|
+
* @version 1.0.0
|
|
26
|
+
* @since 2025-09-30
|
|
27
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
28
|
+
*/
|
|
29
|
+
code: string;
|
|
30
|
+
/** The HTTP status code associated with the error.
|
|
31
|
+
*
|
|
32
|
+
* @author Xeno
|
|
33
|
+
* @version 1.0.0
|
|
34
|
+
* @since 2025-09-30
|
|
35
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
36
|
+
*/
|
|
37
|
+
status: number;
|
|
38
|
+
/** The name of the error, typically the class name.
|
|
39
|
+
*
|
|
40
|
+
* @author Xeno
|
|
41
|
+
* @version 1.0.0
|
|
42
|
+
* @since 2025-09-30
|
|
43
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
44
|
+
*/
|
|
45
|
+
name: string;
|
|
46
|
+
/** An optional property to hold the original error or any additional context.
|
|
47
|
+
*
|
|
48
|
+
* @author Xeno
|
|
49
|
+
* @version 1.0.0
|
|
50
|
+
* @since 2025-09-30
|
|
51
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
52
|
+
*/
|
|
53
|
+
cause: Optional<unknown>;
|
|
54
|
+
/** A Dictionary to hold any additional context or information related to the error.
|
|
55
|
+
*
|
|
56
|
+
* @author Xeno
|
|
57
|
+
* @version 1.0.0
|
|
58
|
+
* @since 2025-09-30
|
|
59
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
60
|
+
*/
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A class representing an application error, which extends the built-in Error class.
|
|
65
|
+
* It includes additional properties such as an error code and an HTTP status code.
|
|
66
|
+
|
|
67
|
+
*
|
|
68
|
+
* @author Xeno
|
|
69
|
+
* @version 1.0.0
|
|
70
|
+
* @since 2025-09-30
|
|
71
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
72
|
+
*/
|
|
73
|
+
declare class AppError extends Error {
|
|
74
|
+
/**
|
|
75
|
+
* The error code representing the type of error.
|
|
76
|
+
|
|
77
|
+
*
|
|
78
|
+
* @author Xeno
|
|
79
|
+
* @version 1.0.0
|
|
80
|
+
* @since 2025-09-30
|
|
81
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
82
|
+
*/
|
|
83
|
+
readonly code: string;
|
|
84
|
+
/**
|
|
85
|
+
* The HTTP status code associated with the error.
|
|
86
|
+
|
|
87
|
+
*
|
|
88
|
+
* @author Xeno
|
|
89
|
+
* @version 1.0.0
|
|
90
|
+
* @since 2025-09-30
|
|
91
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
92
|
+
*/
|
|
93
|
+
readonly status: number;
|
|
94
|
+
/**
|
|
95
|
+
* A Dictionary to hold any additional context or information related to the error.
|
|
96
|
+
*
|
|
97
|
+
* @author Xeno
|
|
98
|
+
* @version 1.0.0
|
|
99
|
+
* @since 2025-09-30
|
|
100
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
101
|
+
*/
|
|
102
|
+
readonly [key: string]: unknown;
|
|
103
|
+
/**
|
|
104
|
+
* Private constructor to prevent direct instantiation. Use the static methods `create` and `throw` to create instances.
|
|
105
|
+
*
|
|
106
|
+
* @param payload - The payload containing error details.
|
|
107
|
+
|
|
108
|
+
*
|
|
109
|
+
* @author Xeno
|
|
110
|
+
* @version 1.0.0
|
|
111
|
+
* @since 2025-09-30
|
|
112
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
113
|
+
*/
|
|
114
|
+
private constructor();
|
|
115
|
+
/**
|
|
116
|
+
* Creates an AppError instance with the given error payload.
|
|
117
|
+
*
|
|
118
|
+
* @param payload - The payload containing error details.
|
|
119
|
+
* @returns An AppError instance representing the error.
|
|
120
|
+
|
|
121
|
+
*
|
|
122
|
+
* @author Xeno
|
|
123
|
+
* @version 1.0.0
|
|
124
|
+
* @since 2025-09-30
|
|
125
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
126
|
+
*/
|
|
127
|
+
static create(payload: ErrorPayload): AppError;
|
|
128
|
+
/**
|
|
129
|
+
* Creates an AppError instance and throws it immediately.
|
|
130
|
+
* @param payload - The payload containing error details.
|
|
131
|
+
* @throws An AppError instance representing the error.
|
|
132
|
+
|
|
133
|
+
*
|
|
134
|
+
* @author Xeno
|
|
135
|
+
* @version 1.0.0
|
|
136
|
+
* @since 2025-09-30
|
|
137
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
138
|
+
*/
|
|
139
|
+
static throw(payload: ErrorPayload): never;
|
|
140
|
+
/**
|
|
141
|
+
* Creates an AppError instance representing an aborted request.
|
|
142
|
+
* @param name - The name of the error, typically the class name or context where the error occurred.
|
|
143
|
+
* @returns An AppError instance representing the aborted request error.
|
|
144
|
+
|
|
145
|
+
*
|
|
146
|
+
* @author Xeno
|
|
147
|
+
* @version 1.0.0
|
|
148
|
+
* @since 2025-09-30
|
|
149
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
150
|
+
*/
|
|
151
|
+
static aborted(name: string): AppError;
|
|
152
|
+
/**
|
|
153
|
+
* Utility method to check if an AbortSignal has been triggered and throw an AppError if it has.
|
|
154
|
+
* @param signal - The AbortSignal to check for abortion.
|
|
155
|
+
* @param name - The name of the error, typically the class name or context where the error occurred.
|
|
156
|
+
|
|
157
|
+
*
|
|
158
|
+
* @author Xeno
|
|
159
|
+
* @version 1.0.0
|
|
160
|
+
* @since 2025-09-30
|
|
161
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
162
|
+
*/
|
|
163
|
+
static throwIfAborted(signal: Maybe<AbortSignal>, name: string): void;
|
|
164
|
+
/** @description Creates an AppError instance representing an unauthorized access error. This method is used to generate a standardized error response when a user attempts to access a resource or perform an action without the necessary authentication or authorization.
|
|
165
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
166
|
+
* @param message A custom message describing the reason for the unauthorized access. This message is included in the AppError's cause for detailed error reporting.
|
|
167
|
+
* @returns An AppError instance representing the unauthorized access error.
|
|
168
|
+
*
|
|
169
|
+
* @author Xeno
|
|
170
|
+
* @version 1.0.0
|
|
171
|
+
* @since 2025-09-30
|
|
172
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
173
|
+
*/
|
|
174
|
+
static unauthorized(name: string, message: string): AppError;
|
|
175
|
+
static notSupported(name: string, message: string): AppError;
|
|
176
|
+
/** @description Creates an AppError instance representing a forbidden access error. This method is used to generate a standardized error response when a user attempts to access a resource or perform an action that they are not authorized to access, even if they are authenticated.
|
|
177
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
178
|
+
* @param message A custom message describing the reason for the forbidden access. This message is included in the AppError's cause for detailed error reporting.
|
|
179
|
+
* @returns An AppError instance representing the forbidden access error.
|
|
180
|
+
*
|
|
181
|
+
* @author Xeno
|
|
182
|
+
* @version 1.0.0
|
|
183
|
+
* @since 2025-09-30
|
|
184
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
185
|
+
*/
|
|
186
|
+
static forbidden(name: string, message: string): AppError;
|
|
187
|
+
/** @description Creates an AppError instance representing a bad request error. This method is used to generate a standardized error response when a request made by the client is invalid or cannot be processed due to client-side issues, such as validation errors or malformed requests.
|
|
188
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
189
|
+
* @param message A custom message describing the reason for the bad request. This message is included in the AppError's cause for detailed error reporting.
|
|
190
|
+
* @returns An AppError instance representing the bad request error.
|
|
191
|
+
*
|
|
192
|
+
* @author Xeno
|
|
193
|
+
* @version 1.0.0
|
|
194
|
+
* @since 2025-09-30
|
|
195
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
196
|
+
*/
|
|
197
|
+
static badRequest(name: string, message: string): AppError;
|
|
198
|
+
/** @description Creates an AppError instance representing a validation error. This method is used to generate a standardized error response when one or more input fields fail invariant or schema validation, indicating that the request cannot be processed due to invalid data.
|
|
199
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
200
|
+
* @param message A custom message describing the reason for the validation failure. This message is included in the AppError's cause for detailed error reporting.
|
|
201
|
+
* @returns An AppError instance representing the validation error.
|
|
202
|
+
*
|
|
203
|
+
* @author Xeno
|
|
204
|
+
* @version 1.0.0
|
|
205
|
+
* @since 2025-09-30
|
|
206
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
207
|
+
*/
|
|
208
|
+
static validationError(name: string, message: string): AppError;
|
|
209
|
+
/** @description Creates an AppError instance representing a conflict error. This method is used to generate a standardized error response when a request conflicts with the current state of the resource, such as when attempting to create a resource that already exists or update a resource that has been modified by another process.
|
|
210
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
211
|
+
* @param message A custom message describing the reason for the conflict. This message is included in the AppError's cause for detailed error reporting.
|
|
212
|
+
* @returns An AppError instance representing the conflict error.
|
|
213
|
+
*
|
|
214
|
+
* @author Xeno
|
|
215
|
+
* @version 1.0.0
|
|
216
|
+
* @since 2025-09-30
|
|
217
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
218
|
+
*/
|
|
219
|
+
static conflict(name: string, message: string): AppError;
|
|
220
|
+
/** @description Creates an AppError instance representing a not found error. This method is used to generate a standardized error response when a requested resource does not exist, indicating that the client attempted to access a resource that could not be found on the server.
|
|
221
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
222
|
+
* @param message A custom message describing the reason for the not found error. This message is included in the AppError's cause for detailed error reporting.
|
|
223
|
+
* @returns An AppError instance representing the not found error.
|
|
224
|
+
*
|
|
225
|
+
* @author Xeno
|
|
226
|
+
* @version 1.0.0
|
|
227
|
+
* @since 2025-09-30
|
|
228
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
229
|
+
*/
|
|
230
|
+
static notFound(name: string, message: string): AppError;
|
|
231
|
+
/** @description Creates an AppError instance representing a Authentication failed. This method is used to generate a standardized error response when an auth requested produce an error..
|
|
232
|
+
* @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
|
|
233
|
+
* @param message A custom message describing the reason for the Authentication failed. This message is included in the AppError's cause for detailed error reporting.
|
|
234
|
+
* @returns An AppError instance representing the Authentication failed.
|
|
235
|
+
*
|
|
236
|
+
* @author Xeno
|
|
237
|
+
* @version 1.0.0
|
|
238
|
+
* @since 2025-09-30
|
|
239
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
240
|
+
*/
|
|
241
|
+
static authFailed(name: string, message: string): AppError;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A class representing the result of an operation, which can either be a success or a failure.
|
|
246
|
+
* It encapsulates the value of a successful operation or the error of a failed operation.
|
|
247
|
+
*
|
|
248
|
+
* @template TValue - The type of the value in case of a successful operation.
|
|
249
|
+
* @template TError - The type of the error in case of a failed operation (default is never).
|
|
250
|
+
|
|
251
|
+
*
|
|
252
|
+
* @author Xeno
|
|
253
|
+
* @version 1.0.0
|
|
254
|
+
* @since 2025-09-30
|
|
255
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
256
|
+
*/
|
|
257
|
+
declare class Result<TValue, TError = never> {
|
|
258
|
+
/**
|
|
259
|
+
* Indicates whether the operation was successful or not.
|
|
260
|
+
|
|
261
|
+
*
|
|
262
|
+
* @author Xeno
|
|
263
|
+
* @version 1.0.0
|
|
264
|
+
* @since 2025-09-30
|
|
265
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
266
|
+
*/
|
|
267
|
+
private readonly _isSuccess;
|
|
268
|
+
/**
|
|
269
|
+
* The error of the operation in case it failed.
|
|
270
|
+
|
|
271
|
+
*
|
|
272
|
+
* @author Xeno
|
|
273
|
+
* @version 1.0.0
|
|
274
|
+
* @since 2025-09-30
|
|
275
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
276
|
+
*/
|
|
277
|
+
private readonly _error;
|
|
278
|
+
/**
|
|
279
|
+
* The value of the operation in case it succeeded.
|
|
280
|
+
|
|
281
|
+
*
|
|
282
|
+
* @author Xeno
|
|
283
|
+
* @version 1.0.0
|
|
284
|
+
* @since 2025-09-30
|
|
285
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
286
|
+
*/
|
|
287
|
+
private readonly _value;
|
|
288
|
+
/**
|
|
289
|
+
* Private constructor to prevent direct instantiation. Use the static methods `ok` and `fail` to create instances.
|
|
290
|
+
*
|
|
291
|
+
* @param isSuccess - A boolean indicating whether the operation was successful.
|
|
292
|
+
* @param error - The error of the operation in case it failed (optional).
|
|
293
|
+
* @param value - The value of the operation in case it succeeded (optional).
|
|
294
|
+
|
|
295
|
+
*
|
|
296
|
+
* @author Xeno
|
|
297
|
+
* @version 1.0.0
|
|
298
|
+
* @since 2025-09-30
|
|
299
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
300
|
+
*/
|
|
301
|
+
private constructor();
|
|
302
|
+
/**
|
|
303
|
+
* Creates a successful result with the given value.
|
|
304
|
+
*
|
|
305
|
+
* @param value - The value of the successful operation.
|
|
306
|
+
* @returns A Result instance representing a successful operation.
|
|
307
|
+
|
|
308
|
+
*
|
|
309
|
+
* @author Xeno
|
|
310
|
+
* @version 1.0.0
|
|
311
|
+
* @since 2025-09-30
|
|
312
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
313
|
+
*/
|
|
314
|
+
static ok<U>(value?: U): Result<U>;
|
|
315
|
+
/**
|
|
316
|
+
* Creates a failed result with the given error.
|
|
317
|
+
*
|
|
318
|
+
* @param error - The error of the failed operation.
|
|
319
|
+
* @returns A Result instance representing a failed operation.
|
|
320
|
+
|
|
321
|
+
*
|
|
322
|
+
* @author Xeno
|
|
323
|
+
* @version 1.0.0
|
|
324
|
+
* @since 2025-09-30
|
|
325
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
326
|
+
*/
|
|
327
|
+
static fail<U, V = never>(error: V): Result<U, V>;
|
|
328
|
+
/**
|
|
329
|
+
* Checks if the result is a success.
|
|
330
|
+
*
|
|
331
|
+
* @returns True if the result is a success, false otherwise.
|
|
332
|
+
|
|
333
|
+
*
|
|
334
|
+
* @author Xeno
|
|
335
|
+
* @version 1.0.0
|
|
336
|
+
* @since 2025-09-30
|
|
337
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
338
|
+
*/
|
|
339
|
+
isOk(): boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Gets the value of the result or throws an error if the result is a failure.
|
|
342
|
+
*
|
|
343
|
+
* @returns The value of the result.
|
|
344
|
+
* @throws An error if the result is a failure.
|
|
345
|
+
|
|
346
|
+
*
|
|
347
|
+
* @author Xeno
|
|
348
|
+
* @version 1.0.0
|
|
349
|
+
* @since 2025-09-30
|
|
350
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
351
|
+
*/
|
|
352
|
+
getValueOrThrow(): Optional<TValue>;
|
|
353
|
+
/**
|
|
354
|
+
* Gets the error of the result or throws an error if the result is a success.
|
|
355
|
+
*
|
|
356
|
+
* @returns The error of the result.
|
|
357
|
+
* @throws An error if the result is a success.
|
|
358
|
+
|
|
359
|
+
*
|
|
360
|
+
* @author Xeno
|
|
361
|
+
* @version 1.0.0
|
|
362
|
+
* @since 2025-09-30
|
|
363
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
364
|
+
*/
|
|
365
|
+
getErrorOrThrow(): TError;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* A utility type to extract the value type from a Result instance.
|
|
370
|
+
*
|
|
371
|
+
* @template T - The type of the Result instance.
|
|
372
|
+
|
|
373
|
+
*
|
|
374
|
+
* @author Xeno
|
|
375
|
+
* @version 1.0.0
|
|
376
|
+
* @since 2025-09-30
|
|
377
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
378
|
+
*/
|
|
379
|
+
type ResultType<T, E = AppError> = Result<T, E>;
|
|
380
|
+
|
|
381
|
+
export { AppError as A, type ResultType as R, Result as a };
|