@mxweb/core 1.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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/application.d.ts +402 -0
- package/dist/application.js +1 -0
- package/dist/application.mjs +1 -0
- package/dist/common.d.ts +323 -0
- package/dist/common.js +1 -0
- package/dist/common.mjs +1 -0
- package/dist/config.d.ts +258 -0
- package/dist/config.js +1 -0
- package/dist/config.mjs +1 -0
- package/dist/context.d.ts +48 -0
- package/dist/context.js +1 -0
- package/dist/context.mjs +1 -0
- package/dist/controller.d.ts +238 -0
- package/dist/controller.js +1 -0
- package/dist/controller.mjs +1 -0
- package/dist/decorator.d.ts +349 -0
- package/dist/decorator.js +1 -0
- package/dist/decorator.mjs +1 -0
- package/dist/error.d.ts +301 -0
- package/dist/error.js +1 -0
- package/dist/error.mjs +1 -0
- package/dist/execute.d.ts +469 -0
- package/dist/execute.js +1 -0
- package/dist/execute.mjs +1 -0
- package/dist/feature.d.ts +239 -0
- package/dist/feature.js +1 -0
- package/dist/feature.mjs +1 -0
- package/dist/hooks.d.ts +251 -0
- package/dist/hooks.js +1 -0
- package/dist/hooks.mjs +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/logger.d.ts +360 -0
- package/dist/logger.js +1 -0
- package/dist/logger.mjs +1 -0
- package/dist/response.d.ts +665 -0
- package/dist/response.js +1 -0
- package/dist/response.mjs +1 -0
- package/dist/route.d.ts +298 -0
- package/dist/route.js +1 -0
- package/dist/route.mjs +1 -0
- package/dist/router.d.ts +205 -0
- package/dist/router.js +1 -0
- package/dist/router.mjs +1 -0
- package/dist/service.d.ts +261 -0
- package/dist/service.js +1 -0
- package/dist/service.mjs +1 -0
- package/package.json +168 -0
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP error classes for standardized error handling.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a hierarchy of HTTP error classes that can be thrown
|
|
5
|
+
* in handlers, services, or guards. The framework automatically converts
|
|
6
|
+
* these errors into appropriate HTTP responses.
|
|
7
|
+
*
|
|
8
|
+
* @module error
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Base HTTP error class that all specific HTTP errors extend.
|
|
12
|
+
* Throw this directly when you need a custom status code, or use
|
|
13
|
+
* one of the predefined error classes for common HTTP errors.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Throw with custom status code
|
|
18
|
+
* throw new HttpError(418, "I'm a teapot");
|
|
19
|
+
*
|
|
20
|
+
* // With additional error details
|
|
21
|
+
* throw new HttpError(400, "Validation failed", { field: "email", reason: "invalid format" });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class HttpError extends Error {
|
|
25
|
+
readonly statusCode: number;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
readonly error?: unknown | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new HttpError instance.
|
|
30
|
+
*
|
|
31
|
+
* @param statusCode - HTTP status code (e.g., 400, 404, 500)
|
|
32
|
+
* @param message - Human-readable error message (overrides Error.message)
|
|
33
|
+
* @param error - Optional additional error details or original error
|
|
34
|
+
*/
|
|
35
|
+
constructor(statusCode: number, message: string, error?: unknown | undefined);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* HTTP 400 Bad Request error.
|
|
39
|
+
* Use when the request is malformed or contains invalid data.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* if (!request.body) {
|
|
44
|
+
* throw new BadRequestError("Request body is required");
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class BadRequestError extends HttpError {
|
|
49
|
+
constructor(message?: string, error?: unknown);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* HTTP 401 Unauthorized error.
|
|
53
|
+
* Use when authentication is required but not provided or invalid.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* if (!token) {
|
|
58
|
+
* throw new UnauthorizedError("Authentication token required");
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class UnauthorizedError extends HttpError {
|
|
63
|
+
constructor(message?: string, error?: unknown);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* HTTP 403 Forbidden error.
|
|
67
|
+
* Use when the user is authenticated but lacks permission.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* if (!user.isAdmin) {
|
|
72
|
+
* throw new ForbiddenError("Admin access required");
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare class ForbiddenError extends HttpError {
|
|
77
|
+
constructor(message?: string, error?: unknown);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* HTTP 404 Not Found error.
|
|
81
|
+
* Use when the requested resource does not exist.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const product = await this.productService.findById(id);
|
|
86
|
+
* if (!product) {
|
|
87
|
+
* throw new NotFoundError(`Product with id ${id} not found`);
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare class NotFoundError extends HttpError {
|
|
92
|
+
constructor(message?: string, error?: unknown);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* HTTP 405 Method Not Allowed error.
|
|
96
|
+
* Use when the HTTP method is not supported for the resource.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* throw new MethodNotAllowedError("DELETE is not allowed for this resource");
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class MethodNotAllowedError extends HttpError {
|
|
104
|
+
constructor(message?: string, error?: unknown);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* HTTP 406 Not Acceptable error.
|
|
108
|
+
* Use when the server cannot produce a response matching the Accept headers.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* if (acceptHeader !== "application/json") {
|
|
113
|
+
* throw new NotAcceptableError("Only application/json is supported");
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare class NotAcceptableError extends HttpError {
|
|
118
|
+
constructor(message?: string, error?: unknown);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* HTTP 408 Request Timeout error.
|
|
122
|
+
* Use when the server timed out waiting for the request.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* throw new RequestTimeoutError("Request took too long to complete");
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare class RequestTimeoutError extends HttpError {
|
|
130
|
+
constructor(message?: string, error?: unknown);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* HTTP 409 Conflict error.
|
|
134
|
+
* Use when the request conflicts with the current state of the resource.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const existing = await this.userService.findByEmail(email);
|
|
139
|
+
* if (existing) {
|
|
140
|
+
* throw new ConflictError("User with this email already exists");
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare class ConflictError extends HttpError {
|
|
145
|
+
constructor(message?: string, error?: unknown);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* HTTP 410 Gone error.
|
|
149
|
+
* Use when the resource existed but has been permanently deleted.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* if (resource.deletedAt) {
|
|
154
|
+
* throw new GoneError("This resource has been permanently removed");
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare class GoneError extends HttpError {
|
|
159
|
+
constructor(message?: string, error?: unknown);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* HTTP 413 Payload Too Large error.
|
|
163
|
+
* Use when the request body exceeds the server's size limit.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* if (fileSize > MAX_FILE_SIZE) {
|
|
168
|
+
* throw new PayloadTooLargeError(`File size exceeds ${MAX_FILE_SIZE} bytes`);
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare class PayloadTooLargeError extends HttpError {
|
|
173
|
+
constructor(message?: string, error?: unknown);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* HTTP 415 Unsupported Media Type error.
|
|
177
|
+
* Use when the request content type is not supported.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* if (contentType !== "application/json") {
|
|
182
|
+
* throw new UnsupportedMediaTypeError("Only JSON content type is accepted");
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare class UnsupportedMediaTypeError extends HttpError {
|
|
187
|
+
constructor(message?: string, error?: unknown);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* HTTP 422 Unprocessable Entity error.
|
|
191
|
+
* Use when the request is well-formed but semantically invalid.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* if (startDate > endDate) {
|
|
196
|
+
* throw new UnprocessableEntityError("Start date cannot be after end date");
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare class UnprocessableEntityError extends HttpError {
|
|
201
|
+
constructor(message?: string, error?: unknown);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* HTTP 429 Too Many Requests error.
|
|
205
|
+
* Use when the user has exceeded the rate limit.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* if (requestCount > RATE_LIMIT) {
|
|
210
|
+
* throw new TooManyRequestsError("Rate limit exceeded. Please try again later.");
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export declare class TooManyRequestsError extends HttpError {
|
|
215
|
+
constructor(message?: string, error?: unknown);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* HTTP 500 Internal Server Error.
|
|
219
|
+
* Use for unexpected server errors that are not the client's fault.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* try {
|
|
224
|
+
* await this.externalService.call();
|
|
225
|
+
* } catch (error) {
|
|
226
|
+
* throw new InternalServerError("Failed to process request", error);
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare class InternalServerError extends HttpError {
|
|
231
|
+
constructor(message?: string, error?: unknown);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* HTTP 501 Not Implemented error.
|
|
235
|
+
* Use when the server does not support the functionality required.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* throw new NotImplementedError("This feature is not yet implemented");
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare class NotImplementedError extends HttpError {
|
|
243
|
+
constructor(message?: string, error?: unknown);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* HTTP 502 Bad Gateway error.
|
|
247
|
+
* Use when the server received an invalid response from an upstream server.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* try {
|
|
252
|
+
* await fetch(upstreamUrl);
|
|
253
|
+
* } catch (error) {
|
|
254
|
+
* throw new BadGatewayError("Upstream service returned invalid response", error);
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
export declare class BadGatewayError extends HttpError {
|
|
259
|
+
constructor(message?: string, error?: unknown);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* HTTP 503 Service Unavailable error.
|
|
263
|
+
* Use when the server is temporarily unable to handle the request.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* if (isMaintenanceMode) {
|
|
268
|
+
* throw new ServiceUnavailableError("Service is under maintenance");
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export declare class ServiceUnavailableError extends HttpError {
|
|
273
|
+
constructor(message?: string, error?: unknown);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* HTTP 504 Gateway Timeout error.
|
|
277
|
+
* Use when an upstream server timed out.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* throw new GatewayTimeoutError("Upstream service did not respond in time");
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export declare class GatewayTimeoutError extends HttpError {
|
|
285
|
+
constructor(message?: string, error?: unknown);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Validation error (extends BadRequestError - HTTP 400).
|
|
289
|
+
* Use specifically for input validation failures.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const errors = validate(dto);
|
|
294
|
+
* if (errors.length) {
|
|
295
|
+
* throw new ValidateError("Validation failed", errors);
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export declare class ValidateError extends BadRequestError {
|
|
300
|
+
constructor(message?: string, error?: unknown);
|
|
301
|
+
}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class r extends Error{constructor(r,e,s){super(e),this.statusCode=r,this.message=e,this.error=s,this.name=this.constructor.name}}class e extends r{constructor(r="Bad Request",e){super(400,r,e)}}exports.BadGatewayError=class extends r{constructor(r="Bad Gateway",e){super(502,r,e)}},exports.BadRequestError=e,exports.ConflictError=class extends r{constructor(r="Conflict",e){super(409,r,e)}},exports.ForbiddenError=class extends r{constructor(r="Forbidden",e){super(403,r,e)}},exports.GatewayTimeoutError=class extends r{constructor(r="Gateway Timeout",e){super(504,r,e)}},exports.GoneError=class extends r{constructor(r="Gone",e){super(410,r,e)}},exports.HttpError=r,exports.InternalServerError=class extends r{constructor(r="Internal Server Error",e){super(500,r,e)}},exports.MethodNotAllowedError=class extends r{constructor(r="Method Not Allowed",e){super(405,r,e)}},exports.NotAcceptableError=class extends r{constructor(r="Not Acceptable",e){super(406,r,e)}},exports.NotFoundError=class extends r{constructor(r="Not Found",e){super(404,r,e)}},exports.NotImplementedError=class extends r{constructor(r="Not Implemented",e){super(501,r,e)}},exports.PayloadTooLargeError=class extends r{constructor(r="Payload Too Large",e){super(413,r,e)}},exports.RequestTimeoutError=class extends r{constructor(r="Request Timeout",e){super(408,r,e)}},exports.ServiceUnavailableError=class extends r{constructor(r="Service Unavailable",e){super(503,r,e)}},exports.TooManyRequestsError=class extends r{constructor(r="Too Many Requests",e){super(429,r,e)}},exports.UnauthorizedError=class extends r{constructor(r="Unauthorized",e){super(401,r,e)}},exports.UnprocessableEntityError=class extends r{constructor(r="Unprocessable Entity",e){super(422,r,e)}},exports.UnsupportedMediaTypeError=class extends r{constructor(r="Unsupported Media Type",e){super(415,r,e)}},exports.ValidateError=class extends e{constructor(r="Validation Error",e){super(r,e)}};
|
package/dist/error.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class s extends Error{constructor(s,e,t){super(e),this.statusCode=s,this.message=e,this.error=t,this.name=this.constructor.name}}class e extends s{constructor(s="Bad Request",e){super(400,s,e)}}class t extends s{constructor(s="Unauthorized",e){super(401,s,e)}}class r extends s{constructor(s="Forbidden",e){super(403,s,e)}}class o extends s{constructor(s="Not Found",e){super(404,s,e)}}class c extends s{constructor(s="Method Not Allowed",e){super(405,s,e)}}class n extends s{constructor(s="Not Acceptable",e){super(406,s,e)}}class u extends s{constructor(s="Request Timeout",e){super(408,s,e)}}class a extends s{constructor(s="Conflict",e){super(409,s,e)}}class d extends s{constructor(s="Gone",e){super(410,s,e)}}class l extends s{constructor(s="Payload Too Large",e){super(413,s,e)}}class p extends s{constructor(s="Unsupported Media Type",e){super(415,s,e)}}class x extends s{constructor(s="Unprocessable Entity",e){super(422,s,e)}}class i extends s{constructor(s="Too Many Requests",e){super(429,s,e)}}class h extends s{constructor(s="Internal Server Error",e){super(500,s,e)}}class m extends s{constructor(s="Not Implemented",e){super(501,s,e)}}class y extends s{constructor(s="Bad Gateway",e){super(502,s,e)}}class T extends s{constructor(s="Service Unavailable",e){super(503,s,e)}}class b extends s{constructor(s="Gateway Timeout",e){super(504,s,e)}}class E extends e{constructor(s="Validation Error",e){super(s,e)}}export{y as BadGatewayError,e as BadRequestError,a as ConflictError,r as ForbiddenError,b as GatewayTimeoutError,d as GoneError,s as HttpError,h as InternalServerError,c as MethodNotAllowedError,n as NotAcceptableError,o as NotFoundError,m as NotImplementedError,l as PayloadTooLargeError,u as RequestTimeoutError,T as ServiceUnavailableError,i as TooManyRequestsError,t as UnauthorizedError,x as UnprocessableEntityError,p as UnsupportedMediaTypeError,E as ValidateError};
|