@mxweb/core 1.0.1 → 1.1.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/CHANGELOG.md +239 -0
- package/dist/application.d.ts +88 -27
- package/dist/application.js +1 -1
- package/dist/application.mjs +1 -1
- package/dist/common.d.ts +50 -3
- package/dist/config.d.ts +18 -0
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/decorator.d.ts +11 -4
- package/dist/execute.d.ts +312 -58
- package/dist/execute.js +1 -1
- package/dist/execute.mjs +1 -1
- package/dist/feature.d.ts +9 -7
- package/dist/feature.js +1 -1
- package/dist/feature.mjs +1 -1
- package/dist/hooks.d.ts +5 -6
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/logger.js +1 -1
- package/dist/logger.mjs +1 -1
- package/dist/response.d.ts +297 -227
- package/dist/response.js +1 -1
- package/dist/response.mjs +1 -1
- package/dist/route.d.ts +107 -3
- package/dist/route.js +1 -1
- package/dist/route.mjs +1 -1
- package/dist/service.d.ts +9 -8
- package/package.json +1 -6
package/dist/response.d.ts
CHANGED
|
@@ -34,18 +34,263 @@
|
|
|
34
34
|
* return response.unauthorized("Token expired");
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Standard response body structure for all API responses.
|
|
39
|
+
* This is the JSON payload that will be sent to the client.
|
|
40
|
+
*/
|
|
41
|
+
export interface CoreResponseBody<T = unknown> {
|
|
42
|
+
/** Whether the request was successful (2xx-3xx = true, 4xx-5xx = false) */
|
|
43
|
+
success: boolean;
|
|
44
|
+
/** Human-readable message describing the result */
|
|
45
|
+
message: string;
|
|
46
|
+
/** Machine-readable status code (e.g., "SUCCESS", "NOT_FOUND", "BAD_REQUEST") */
|
|
47
|
+
code: string;
|
|
48
|
+
/** HTTP status code */
|
|
49
|
+
status: number;
|
|
50
|
+
/** Response payload for success responses, null for errors */
|
|
51
|
+
data: T | null;
|
|
52
|
+
/** Error details for error responses, null for success */
|
|
53
|
+
error: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Framework-agnostic response class.
|
|
57
|
+
* Use `json()` method to convert to standard Web Response, or use a transformer
|
|
58
|
+
* for framework-specific responses (NextResponse, Express, etc.)
|
|
59
|
+
*
|
|
60
|
+
* @template T - The type of the response data
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* // Direct usage with standard Response
|
|
65
|
+
* const coreResponse = new CoreResponse(body, 200, "OK");
|
|
66
|
+
* return coreResponse.json(); // Returns standard Response
|
|
67
|
+
*
|
|
68
|
+
* // In Application options (Next.js transformer)
|
|
69
|
+
* import { NextResponse } from "next/server";
|
|
70
|
+
*
|
|
71
|
+
* const app = Application.create({
|
|
72
|
+
* responseTransformer: (coreResponse) => {
|
|
73
|
+
* return CoreResponse.json(coreResponse.body, {
|
|
74
|
+
* status: coreResponse.status,
|
|
75
|
+
* headers: coreResponse.headers,
|
|
76
|
+
* });
|
|
77
|
+
* },
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class CoreResponse<T = unknown> {
|
|
82
|
+
readonly body: CoreResponseBody<T>;
|
|
83
|
+
readonly status: number;
|
|
84
|
+
readonly statusText: string;
|
|
85
|
+
/** Response headers */
|
|
86
|
+
readonly headers: Headers;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new CoreResponse instance.
|
|
89
|
+
*
|
|
90
|
+
* @param body - The structured response body
|
|
91
|
+
* @param status - HTTP status code
|
|
92
|
+
* @param statusText - HTTP status text (e.g., "OK", "Not Found")
|
|
93
|
+
* @param headers - Optional additional headers
|
|
94
|
+
*/
|
|
95
|
+
constructor(body: CoreResponseBody<T>, status: number, statusText: string, headers?: HeadersInit);
|
|
96
|
+
/**
|
|
97
|
+
* Returns the response body as a plain object.
|
|
98
|
+
* Use this to get the standardized schema for custom response handling.
|
|
99
|
+
*
|
|
100
|
+
* @returns The CoreResponseBody object
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const coreResponse = new CoreResponse(body, 200, "OK");
|
|
105
|
+
* const schema = coreResponse.json();
|
|
106
|
+
* // { success: true, message: "...", code: "SUCCESS", status: 200, data: ..., error: null }
|
|
107
|
+
*
|
|
108
|
+
* // Next.js
|
|
109
|
+
* return NextResponse.json(schema, { status: coreResponse.status });
|
|
110
|
+
*
|
|
111
|
+
* // Express
|
|
112
|
+
* res.status(coreResponse.status).json(schema);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
json(): CoreResponseBody<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a CoreResponse from a body object and options.
|
|
118
|
+
*
|
|
119
|
+
* @param body - The response body
|
|
120
|
+
* @param init - Response init options (status, statusText, headers)
|
|
121
|
+
* @returns A new CoreResponse instance
|
|
122
|
+
*/
|
|
123
|
+
static json<T = unknown>(body: CoreResponseBody<T>, init?: {
|
|
124
|
+
status?: number;
|
|
125
|
+
statusText?: string;
|
|
126
|
+
headers?: HeadersInit;
|
|
127
|
+
}): CoreResponse<T>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Interface for response classes that have a static json() method.
|
|
131
|
+
* This allows passing NextResponse, Response, or custom response classes directly.
|
|
132
|
+
*
|
|
133
|
+
* @template R - The type of response instance returned by json()
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* // NextResponse is compatible
|
|
138
|
+
* import { NextResponse } from "next/server";
|
|
139
|
+
* // NextResponse.json(body, init) returns NextResponse
|
|
140
|
+
*
|
|
141
|
+
* // Standard Response is also compatible
|
|
142
|
+
* Response.json(body, init) // returns Response
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export interface ResponseClass<R = Response> {
|
|
146
|
+
json(body: unknown, init?: ResponseInit): R;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Type for response transformer.
|
|
150
|
+
* Can be either:
|
|
151
|
+
* 1. A response class with static json() method (NextResponse, Response)
|
|
152
|
+
* 2. A custom function that transforms CoreResponse
|
|
153
|
+
*
|
|
154
|
+
* @template R - The type of the final response
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* // Option 1: Pass class directly (recommended for Next.js)
|
|
159
|
+
* import { NextResponse } from "next/server";
|
|
160
|
+
*
|
|
161
|
+
* Application.create({
|
|
162
|
+
* responseTransformer: NextResponse, // Just pass the class!
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Option 2: Custom transformer function
|
|
166
|
+
* Application.create({
|
|
167
|
+
* responseTransformer: (coreResponse) => {
|
|
168
|
+
* // Custom logic
|
|
169
|
+
* return new Response(JSON.stringify(coreResponse.body), {
|
|
170
|
+
* status: coreResponse.status,
|
|
171
|
+
* headers: coreResponse.headers,
|
|
172
|
+
* });
|
|
173
|
+
* },
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Option 3: Express/Fastify adapter (external package)
|
|
177
|
+
* Application.create({
|
|
178
|
+
* responseTransformer: (coreResponse, res) => {
|
|
179
|
+
* res.status(coreResponse.status).json(coreResponse.body);
|
|
180
|
+
* return res;
|
|
181
|
+
* },
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export type ResponseTransformer<R = Response> = ResponseClass<R> | ((response: CoreResponse) => R);
|
|
186
|
+
/**
|
|
187
|
+
* Helper to apply a response transformer to a CoreResponse.
|
|
188
|
+
* Handles both class-based and function-based transformers.
|
|
189
|
+
*
|
|
190
|
+
* @param transformer - The transformer (class or function)
|
|
191
|
+
* @param response - The CoreResponse to transform
|
|
192
|
+
* @returns The transformed response
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* import { NextResponse } from "next/server";
|
|
197
|
+
*
|
|
198
|
+
* const coreResponse = new CoreResponse(body, 200, "OK");
|
|
199
|
+
*
|
|
200
|
+
* // With class
|
|
201
|
+
* const nextRes = applyTransformer(NextResponse, coreResponse);
|
|
202
|
+
*
|
|
203
|
+
* // With function
|
|
204
|
+
* const customRes = applyTransformer(
|
|
205
|
+
* (r) => new Response(JSON.stringify(r.body)),
|
|
206
|
+
* coreResponse
|
|
207
|
+
* );
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function applyTransformer<R = Response>(transformer: ResponseTransformer<R>, response: CoreResponse): R;
|
|
211
|
+
/**
|
|
212
|
+
* Type for response interceptor function.
|
|
213
|
+
* Interceptors receive a CoreResponse and can transform it (add headers, modify body, etc.)
|
|
214
|
+
* The interceptor is called AFTER the handler returns, allowing post-processing.
|
|
215
|
+
*
|
|
216
|
+
* @template T - The type of the response data
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* // Add custom header
|
|
221
|
+
* const addTimestamp: ResponseInterceptor = async (response) => {
|
|
222
|
+
* response.headers.set("X-Timestamp", Date.now().toString());
|
|
223
|
+
* return response;
|
|
224
|
+
* };
|
|
225
|
+
*
|
|
226
|
+
* // Transform response body
|
|
227
|
+
* const wrapResponse: ResponseInterceptor = async (response) => {
|
|
228
|
+
* const newBody = {
|
|
229
|
+
* ...response.body,
|
|
230
|
+
* metadata: { version: "1.0" },
|
|
231
|
+
* };
|
|
232
|
+
* return CoreResponse.json(newBody, {
|
|
233
|
+
* status: response.status,
|
|
234
|
+
* statusText: response.statusText,
|
|
235
|
+
* headers: response.headers,
|
|
236
|
+
* });
|
|
237
|
+
* };
|
|
238
|
+
*
|
|
239
|
+
* // Logging interceptor
|
|
240
|
+
* const logResponse: ResponseInterceptor = async (response) => {
|
|
241
|
+
* console.log(`Response: ${response.status} ${response.body.message}`);
|
|
242
|
+
* return response;
|
|
243
|
+
* };
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export type ResponseInterceptor<T = unknown> = (response: CoreResponse<T>) => CoreResponse<T> | Promise<CoreResponse<T>>;
|
|
247
|
+
/**
|
|
248
|
+
* Interface for class-based response interceptors.
|
|
249
|
+
* Provides more flexibility than function interceptors with access to instance state.
|
|
250
|
+
*
|
|
251
|
+
* @template T - The type of the response data
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* class LoggingInterceptor implements ResponseInterceptorHandler {
|
|
256
|
+
* transform(response: CoreResponse): CoreResponse {
|
|
257
|
+
* console.log(`[${response.status}] ${response.body.message}`);
|
|
258
|
+
* return response;
|
|
259
|
+
* }
|
|
260
|
+
* }
|
|
261
|
+
*
|
|
262
|
+
* class CacheHeaderInterceptor implements ResponseInterceptorHandler {
|
|
263
|
+
* transform(response: CoreResponse): CoreResponse {
|
|
264
|
+
* if (response.status >= 200 && response.status < 300) {
|
|
265
|
+
* response.headers.set("Cache-Control", "max-age=3600");
|
|
266
|
+
* }
|
|
267
|
+
* return response;
|
|
268
|
+
* }
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export interface ResponseInterceptorHandler<T = unknown> {
|
|
273
|
+
/**
|
|
274
|
+
* Transforms the response.
|
|
275
|
+
* Called after the handler returns, allowing post-processing of the response.
|
|
276
|
+
*
|
|
277
|
+
* @param response - The CoreResponse to transform
|
|
278
|
+
* @returns The transformed CoreResponse (can be the same instance or a new one)
|
|
279
|
+
*/
|
|
280
|
+
transform(response: CoreResponse<T>): CoreResponse<T> | Promise<CoreResponse<T>>;
|
|
281
|
+
}
|
|
38
282
|
/**
|
|
39
283
|
* A utility class for building standardized HTTP responses.
|
|
40
284
|
*
|
|
41
285
|
* `ServerResponse` provides methods for all common HTTP status codes,
|
|
42
286
|
* ensuring consistent response structure across your API. Each method
|
|
43
|
-
* returns a `
|
|
287
|
+
* returns a `CoreResponse` that can be transformed to any framework's response.
|
|
44
288
|
*
|
|
45
289
|
* @remarks
|
|
46
290
|
* - Success responses (2xx) have `success: true` and `error: null`
|
|
47
291
|
* - Error responses (4xx, 5xx) have `success: false` and `data: null`
|
|
48
292
|
* - All responses include a human-readable `message` and machine-readable `code`
|
|
293
|
+
* - Use `responseTransformer` in Application options to customize output format
|
|
49
294
|
*
|
|
50
295
|
* @example
|
|
51
296
|
* ```ts
|
|
@@ -85,7 +330,7 @@ export declare class ServerResponse {
|
|
|
85
330
|
* Creates a response for HTTP OPTIONS preflight requests.
|
|
86
331
|
* Returns a 200 OK response, typically used for CORS.
|
|
87
332
|
*
|
|
88
|
-
* @returns
|
|
333
|
+
* @returns CoreResponse with 200 status
|
|
89
334
|
*
|
|
90
335
|
* @example
|
|
91
336
|
* ```ts
|
|
@@ -95,20 +340,13 @@ export declare class ServerResponse {
|
|
|
95
340
|
* }
|
|
96
341
|
* ```
|
|
97
342
|
*/
|
|
98
|
-
static options():
|
|
99
|
-
success: boolean;
|
|
100
|
-
message: string;
|
|
101
|
-
code: string;
|
|
102
|
-
status: number;
|
|
103
|
-
data: unknown;
|
|
104
|
-
error: unknown;
|
|
105
|
-
}>;
|
|
343
|
+
static options(): CoreResponse<unknown>;
|
|
106
344
|
/**
|
|
107
345
|
* Returns a 200 OK response with optional data.
|
|
108
346
|
*
|
|
109
347
|
* @param data - The response payload
|
|
110
348
|
* @param message - Custom success message (default: "Successfully")
|
|
111
|
-
* @returns
|
|
349
|
+
* @returns CoreResponse with 200 status
|
|
112
350
|
*
|
|
113
351
|
* @example
|
|
114
352
|
* ```ts
|
|
@@ -116,20 +354,13 @@ export declare class ServerResponse {
|
|
|
116
354
|
* return response.success({ token: "..." });
|
|
117
355
|
* ```
|
|
118
356
|
*/
|
|
119
|
-
success(data?: unknown, message?: string):
|
|
120
|
-
success: boolean;
|
|
121
|
-
message: string;
|
|
122
|
-
code: string;
|
|
123
|
-
status: number;
|
|
124
|
-
data: unknown;
|
|
125
|
-
error: unknown;
|
|
126
|
-
}>;
|
|
357
|
+
success(data?: unknown, message?: string): CoreResponse<unknown>;
|
|
127
358
|
/**
|
|
128
359
|
* Returns a 201 Created response for newly created resources.
|
|
129
360
|
*
|
|
130
361
|
* @param data - The created resource
|
|
131
362
|
* @param message - Custom message (default: "Resource created successfully")
|
|
132
|
-
* @returns
|
|
363
|
+
* @returns CoreResponse with 201 status
|
|
133
364
|
*
|
|
134
365
|
* @example
|
|
135
366
|
* ```ts
|
|
@@ -137,21 +368,14 @@ export declare class ServerResponse {
|
|
|
137
368
|
* return response.created(newUser, "User registered successfully");
|
|
138
369
|
* ```
|
|
139
370
|
*/
|
|
140
|
-
created(data?: unknown, message?: string):
|
|
141
|
-
success: boolean;
|
|
142
|
-
message: string;
|
|
143
|
-
code: string;
|
|
144
|
-
status: number;
|
|
145
|
-
data: unknown;
|
|
146
|
-
error: unknown;
|
|
147
|
-
}>;
|
|
371
|
+
created(data?: unknown, message?: string): CoreResponse<unknown>;
|
|
148
372
|
/**
|
|
149
373
|
* Returns a 202 Accepted response for async operations.
|
|
150
374
|
* Used when the request has been accepted but processing is not complete.
|
|
151
375
|
*
|
|
152
376
|
* @param data - Optional data (e.g., job ID for tracking)
|
|
153
377
|
* @param message - Custom message (default: "Request accepted successfully")
|
|
154
|
-
* @returns
|
|
378
|
+
* @returns CoreResponse with 202 status
|
|
155
379
|
*
|
|
156
380
|
* @example
|
|
157
381
|
* ```ts
|
|
@@ -159,20 +383,13 @@ export declare class ServerResponse {
|
|
|
159
383
|
* return response.accepted({ jobId }, "Email will be sent shortly");
|
|
160
384
|
* ```
|
|
161
385
|
*/
|
|
162
|
-
accepted(data?: unknown, message?: string):
|
|
163
|
-
success: boolean;
|
|
164
|
-
message: string;
|
|
165
|
-
code: string;
|
|
166
|
-
status: number;
|
|
167
|
-
data: unknown;
|
|
168
|
-
error: unknown;
|
|
169
|
-
}>;
|
|
386
|
+
accepted(data?: unknown, message?: string): CoreResponse<unknown>;
|
|
170
387
|
/**
|
|
171
388
|
* Returns a 204 No Content response.
|
|
172
389
|
* Typically used after DELETE operations.
|
|
173
390
|
*
|
|
174
391
|
* @param message - Custom message (default: "No content")
|
|
175
|
-
* @returns
|
|
392
|
+
* @returns CoreResponse with 204 status
|
|
176
393
|
*
|
|
177
394
|
* @example
|
|
178
395
|
* ```ts
|
|
@@ -180,19 +397,12 @@ export declare class ServerResponse {
|
|
|
180
397
|
* return response.noContent("User deleted successfully");
|
|
181
398
|
* ```
|
|
182
399
|
*/
|
|
183
|
-
noContent(message?: string):
|
|
184
|
-
success: boolean;
|
|
185
|
-
message: string;
|
|
186
|
-
code: string;
|
|
187
|
-
status: number;
|
|
188
|
-
data: unknown;
|
|
189
|
-
error: unknown;
|
|
190
|
-
}>;
|
|
400
|
+
noContent(message?: string): CoreResponse<null>;
|
|
191
401
|
/**
|
|
192
402
|
* Returns a 301 Moved Permanently response.
|
|
193
403
|
* Indicates the resource has been permanently moved to a new URL.
|
|
194
404
|
*
|
|
195
|
-
* @returns
|
|
405
|
+
* @returns CoreResponse with 301 status
|
|
196
406
|
*
|
|
197
407
|
* @example
|
|
198
408
|
* ```ts
|
|
@@ -200,19 +410,12 @@ export declare class ServerResponse {
|
|
|
200
410
|
* return response.resourceMovedPermanently();
|
|
201
411
|
* ```
|
|
202
412
|
*/
|
|
203
|
-
resourceMovedPermanently():
|
|
204
|
-
success: boolean;
|
|
205
|
-
message: string;
|
|
206
|
-
code: string;
|
|
207
|
-
status: number;
|
|
208
|
-
data: unknown;
|
|
209
|
-
error: unknown;
|
|
210
|
-
}>;
|
|
413
|
+
resourceMovedPermanently(): CoreResponse<null>;
|
|
211
414
|
/**
|
|
212
415
|
* Returns a 302 Found (Temporary Redirect) response.
|
|
213
416
|
* Indicates the resource has been temporarily moved.
|
|
214
417
|
*
|
|
215
|
-
* @returns
|
|
418
|
+
* @returns CoreResponse with 302 status
|
|
216
419
|
*
|
|
217
420
|
* @example
|
|
218
421
|
* ```ts
|
|
@@ -220,21 +423,14 @@ export declare class ServerResponse {
|
|
|
220
423
|
* return response.resourceMovedTemporarily();
|
|
221
424
|
* ```
|
|
222
425
|
*/
|
|
223
|
-
resourceMovedTemporarily():
|
|
224
|
-
success: boolean;
|
|
225
|
-
message: string;
|
|
226
|
-
code: string;
|
|
227
|
-
status: number;
|
|
228
|
-
data: unknown;
|
|
229
|
-
error: unknown;
|
|
230
|
-
}>;
|
|
426
|
+
resourceMovedTemporarily(): CoreResponse<null>;
|
|
231
427
|
/**
|
|
232
428
|
* Returns a 400 Bad Request response.
|
|
233
429
|
* Used when the request syntax is invalid or malformed.
|
|
234
430
|
*
|
|
235
431
|
* @param message - Error message (default: "Bad Request")
|
|
236
432
|
* @param error - Detailed error information (e.g., validation errors)
|
|
237
|
-
* @returns
|
|
433
|
+
* @returns CoreResponse with 400 status
|
|
238
434
|
*
|
|
239
435
|
* @example
|
|
240
436
|
* ```ts
|
|
@@ -246,21 +442,14 @@ export declare class ServerResponse {
|
|
|
246
442
|
* }
|
|
247
443
|
* ```
|
|
248
444
|
*/
|
|
249
|
-
badRequest(message?: string, error?: unknown):
|
|
250
|
-
success: boolean;
|
|
251
|
-
message: string;
|
|
252
|
-
code: string;
|
|
253
|
-
status: number;
|
|
254
|
-
data: unknown;
|
|
255
|
-
error: unknown;
|
|
256
|
-
}>;
|
|
445
|
+
badRequest(message?: string, error?: unknown): CoreResponse<null>;
|
|
257
446
|
/**
|
|
258
447
|
* Returns a 401 Unauthorized response.
|
|
259
448
|
* Used when authentication is required but missing or invalid.
|
|
260
449
|
*
|
|
261
450
|
* @param message - Error message (default: "Unauthorized")
|
|
262
451
|
* @param error - Detailed error information
|
|
263
|
-
* @returns
|
|
452
|
+
* @returns CoreResponse with 401 status
|
|
264
453
|
*
|
|
265
454
|
* @example
|
|
266
455
|
* ```ts
|
|
@@ -272,21 +461,14 @@ export declare class ServerResponse {
|
|
|
272
461
|
* }
|
|
273
462
|
* ```
|
|
274
463
|
*/
|
|
275
|
-
unauthorized(message?: string, error?: unknown):
|
|
276
|
-
success: boolean;
|
|
277
|
-
message: string;
|
|
278
|
-
code: string;
|
|
279
|
-
status: number;
|
|
280
|
-
data: unknown;
|
|
281
|
-
error: unknown;
|
|
282
|
-
}>;
|
|
464
|
+
unauthorized(message?: string, error?: unknown): CoreResponse<null>;
|
|
283
465
|
/**
|
|
284
466
|
* Returns a 403 Forbidden response.
|
|
285
467
|
* Used when the user is authenticated but lacks permission.
|
|
286
468
|
*
|
|
287
469
|
* @param message - Error message (default: "Forbidden")
|
|
288
470
|
* @param error - Detailed error information
|
|
289
|
-
* @returns
|
|
471
|
+
* @returns CoreResponse with 403 status
|
|
290
472
|
*
|
|
291
473
|
* @example
|
|
292
474
|
* ```ts
|
|
@@ -295,21 +477,14 @@ export declare class ServerResponse {
|
|
|
295
477
|
* }
|
|
296
478
|
* ```
|
|
297
479
|
*/
|
|
298
|
-
forbidden(message?: string, error?: unknown):
|
|
299
|
-
success: boolean;
|
|
300
|
-
message: string;
|
|
301
|
-
code: string;
|
|
302
|
-
status: number;
|
|
303
|
-
data: unknown;
|
|
304
|
-
error: unknown;
|
|
305
|
-
}>;
|
|
480
|
+
forbidden(message?: string, error?: unknown): CoreResponse<null>;
|
|
306
481
|
/**
|
|
307
482
|
* Returns a 404 Not Found response.
|
|
308
483
|
* Used when the requested resource does not exist.
|
|
309
484
|
*
|
|
310
485
|
* @param message - Error message (default: "Not Found")
|
|
311
486
|
* @param error - Detailed error information
|
|
312
|
-
* @returns
|
|
487
|
+
* @returns CoreResponse with 404 status
|
|
313
488
|
*
|
|
314
489
|
* @example
|
|
315
490
|
* ```ts
|
|
@@ -319,21 +494,14 @@ export declare class ServerResponse {
|
|
|
319
494
|
* }
|
|
320
495
|
* ```
|
|
321
496
|
*/
|
|
322
|
-
notFound(message?: string, error?: unknown):
|
|
323
|
-
success: boolean;
|
|
324
|
-
message: string;
|
|
325
|
-
code: string;
|
|
326
|
-
status: number;
|
|
327
|
-
data: unknown;
|
|
328
|
-
error: unknown;
|
|
329
|
-
}>;
|
|
497
|
+
notFound(message?: string, error?: unknown): CoreResponse<null>;
|
|
330
498
|
/**
|
|
331
499
|
* Returns a 405 Method Not Allowed response.
|
|
332
500
|
* Used when the HTTP method is not supported for the resource.
|
|
333
501
|
*
|
|
334
502
|
* @param message - Error message (default: "Method Not Allowed")
|
|
335
503
|
* @param error - Detailed error information
|
|
336
|
-
* @returns
|
|
504
|
+
* @returns CoreResponse with 405 status
|
|
337
505
|
*
|
|
338
506
|
* @example
|
|
339
507
|
* ```ts
|
|
@@ -343,21 +511,14 @@ export declare class ServerResponse {
|
|
|
343
511
|
* }
|
|
344
512
|
* ```
|
|
345
513
|
*/
|
|
346
|
-
methodNotAllowed(message?: string, error?: unknown):
|
|
347
|
-
success: boolean;
|
|
348
|
-
message: string;
|
|
349
|
-
code: string;
|
|
350
|
-
status: number;
|
|
351
|
-
data: unknown;
|
|
352
|
-
error: unknown;
|
|
353
|
-
}>;
|
|
514
|
+
methodNotAllowed(message?: string, error?: unknown): CoreResponse<null>;
|
|
354
515
|
/**
|
|
355
516
|
* Returns a 406 Not Acceptable response.
|
|
356
517
|
* Used when the server cannot produce content matching Accept headers.
|
|
357
518
|
*
|
|
358
519
|
* @param message - Error message (default: "Not Acceptable")
|
|
359
520
|
* @param error - Detailed error information
|
|
360
|
-
* @returns
|
|
521
|
+
* @returns CoreResponse with 406 status
|
|
361
522
|
*
|
|
362
523
|
* @example
|
|
363
524
|
* ```ts
|
|
@@ -366,21 +527,14 @@ export declare class ServerResponse {
|
|
|
366
527
|
* }
|
|
367
528
|
* ```
|
|
368
529
|
*/
|
|
369
|
-
notAcceptable(message?: string, error?: unknown):
|
|
370
|
-
success: boolean;
|
|
371
|
-
message: string;
|
|
372
|
-
code: string;
|
|
373
|
-
status: number;
|
|
374
|
-
data: unknown;
|
|
375
|
-
error: unknown;
|
|
376
|
-
}>;
|
|
530
|
+
notAcceptable(message?: string, error?: unknown): CoreResponse<null>;
|
|
377
531
|
/**
|
|
378
532
|
* Returns a 408 Request Timeout response.
|
|
379
533
|
* Used when the server timed out waiting for the request.
|
|
380
534
|
*
|
|
381
535
|
* @param message - Error message (default: "Request Timeout")
|
|
382
536
|
* @param error - Detailed error information
|
|
383
|
-
* @returns
|
|
537
|
+
* @returns CoreResponse with 408 status
|
|
384
538
|
*
|
|
385
539
|
* @example
|
|
386
540
|
* ```ts
|
|
@@ -391,21 +545,14 @@ export declare class ServerResponse {
|
|
|
391
545
|
* }
|
|
392
546
|
* ```
|
|
393
547
|
*/
|
|
394
|
-
requestTimeout(message?: string, error?: unknown):
|
|
395
|
-
success: boolean;
|
|
396
|
-
message: string;
|
|
397
|
-
code: string;
|
|
398
|
-
status: number;
|
|
399
|
-
data: unknown;
|
|
400
|
-
error: unknown;
|
|
401
|
-
}>;
|
|
548
|
+
requestTimeout(message?: string, error?: unknown): CoreResponse<null>;
|
|
402
549
|
/**
|
|
403
550
|
* Returns a 409 Conflict response.
|
|
404
551
|
* Used when the request conflicts with the current state of the resource.
|
|
405
552
|
*
|
|
406
553
|
* @param message - Error message (default: "Conflict")
|
|
407
554
|
* @param error - Detailed error information
|
|
408
|
-
* @returns
|
|
555
|
+
* @returns CoreResponse with 409 status
|
|
409
556
|
*
|
|
410
557
|
* @example
|
|
411
558
|
* ```ts
|
|
@@ -415,21 +562,14 @@ export declare class ServerResponse {
|
|
|
415
562
|
* }
|
|
416
563
|
* ```
|
|
417
564
|
*/
|
|
418
|
-
conflict(message?: string, error?: unknown):
|
|
419
|
-
success: boolean;
|
|
420
|
-
message: string;
|
|
421
|
-
code: string;
|
|
422
|
-
status: number;
|
|
423
|
-
data: unknown;
|
|
424
|
-
error: unknown;
|
|
425
|
-
}>;
|
|
565
|
+
conflict(message?: string, error?: unknown): CoreResponse<null>;
|
|
426
566
|
/**
|
|
427
567
|
* Returns a 410 Gone response.
|
|
428
568
|
* Used when a resource has been permanently deleted.
|
|
429
569
|
*
|
|
430
570
|
* @param message - Error message (default: "Gone")
|
|
431
571
|
* @param error - Detailed error information
|
|
432
|
-
* @returns
|
|
572
|
+
* @returns CoreResponse with 410 status
|
|
433
573
|
*
|
|
434
574
|
* @example
|
|
435
575
|
* ```ts
|
|
@@ -438,21 +578,14 @@ export declare class ServerResponse {
|
|
|
438
578
|
* }
|
|
439
579
|
* ```
|
|
440
580
|
*/
|
|
441
|
-
gone(message?: string, error?: unknown):
|
|
442
|
-
success: boolean;
|
|
443
|
-
message: string;
|
|
444
|
-
code: string;
|
|
445
|
-
status: number;
|
|
446
|
-
data: unknown;
|
|
447
|
-
error: unknown;
|
|
448
|
-
}>;
|
|
581
|
+
gone(message?: string, error?: unknown): CoreResponse<null>;
|
|
449
582
|
/**
|
|
450
583
|
* Returns a 413 Payload Too Large response.
|
|
451
584
|
* Used when the request body exceeds the server limit.
|
|
452
585
|
*
|
|
453
586
|
* @param message - Error message (default: "Payload Too Large")
|
|
454
587
|
* @param error - Detailed error information
|
|
455
|
-
* @returns
|
|
588
|
+
* @returns CoreResponse with 413 status
|
|
456
589
|
*
|
|
457
590
|
* @example
|
|
458
591
|
* ```ts
|
|
@@ -461,21 +594,14 @@ export declare class ServerResponse {
|
|
|
461
594
|
* }
|
|
462
595
|
* ```
|
|
463
596
|
*/
|
|
464
|
-
payloadTooLarge(message?: string, error?: unknown):
|
|
465
|
-
success: boolean;
|
|
466
|
-
message: string;
|
|
467
|
-
code: string;
|
|
468
|
-
status: number;
|
|
469
|
-
data: unknown;
|
|
470
|
-
error: unknown;
|
|
471
|
-
}>;
|
|
597
|
+
payloadTooLarge(message?: string, error?: unknown): CoreResponse<null>;
|
|
472
598
|
/**
|
|
473
599
|
* Returns a 415 Unsupported Media Type response.
|
|
474
600
|
* Used when the request Content-Type is not supported.
|
|
475
601
|
*
|
|
476
602
|
* @param message - Error message (default: "Unsupported Media Type")
|
|
477
603
|
* @param error - Detailed error information
|
|
478
|
-
* @returns
|
|
604
|
+
* @returns CoreResponse with 415 status
|
|
479
605
|
*
|
|
480
606
|
* @example
|
|
481
607
|
* ```ts
|
|
@@ -484,21 +610,14 @@ export declare class ServerResponse {
|
|
|
484
610
|
* }
|
|
485
611
|
* ```
|
|
486
612
|
*/
|
|
487
|
-
unsupportedMediaType(message?: string, error?: unknown):
|
|
488
|
-
success: boolean;
|
|
489
|
-
message: string;
|
|
490
|
-
code: string;
|
|
491
|
-
status: number;
|
|
492
|
-
data: unknown;
|
|
493
|
-
error: unknown;
|
|
494
|
-
}>;
|
|
613
|
+
unsupportedMediaType(message?: string, error?: unknown): CoreResponse<null>;
|
|
495
614
|
/**
|
|
496
615
|
* Returns a 422 Unprocessable Entity response.
|
|
497
616
|
* Used when the request is syntactically correct but semantically invalid.
|
|
498
617
|
*
|
|
499
618
|
* @param message - Error message (default: "Unprocessable Entity")
|
|
500
619
|
* @param error - Detailed error information (e.g., validation errors)
|
|
501
|
-
* @returns
|
|
620
|
+
* @returns CoreResponse with 422 status
|
|
502
621
|
*
|
|
503
622
|
* @example
|
|
504
623
|
* ```ts
|
|
@@ -508,21 +627,14 @@ export declare class ServerResponse {
|
|
|
508
627
|
* }
|
|
509
628
|
* ```
|
|
510
629
|
*/
|
|
511
|
-
unprocessableEntity(message?: string, error?: unknown):
|
|
512
|
-
success: boolean;
|
|
513
|
-
message: string;
|
|
514
|
-
code: string;
|
|
515
|
-
status: number;
|
|
516
|
-
data: unknown;
|
|
517
|
-
error: unknown;
|
|
518
|
-
}>;
|
|
630
|
+
unprocessableEntity(message?: string, error?: unknown): CoreResponse<null>;
|
|
519
631
|
/**
|
|
520
632
|
* Returns a 429 Too Many Requests response.
|
|
521
633
|
* Used for rate limiting.
|
|
522
634
|
*
|
|
523
635
|
* @param message - Error message (default: "Too Many Requests")
|
|
524
636
|
* @param error - Detailed error information (e.g., retry-after time)
|
|
525
|
-
* @returns
|
|
637
|
+
* @returns CoreResponse with 429 status
|
|
526
638
|
*
|
|
527
639
|
* @example
|
|
528
640
|
* ```ts
|
|
@@ -535,20 +647,13 @@ export declare class ServerResponse {
|
|
|
535
647
|
* }
|
|
536
648
|
* ```
|
|
537
649
|
*/
|
|
538
|
-
tooManyRequests(message?: string, error?: unknown):
|
|
539
|
-
success: boolean;
|
|
540
|
-
message: string;
|
|
541
|
-
code: string;
|
|
542
|
-
status: number;
|
|
543
|
-
data: unknown;
|
|
544
|
-
error: unknown;
|
|
545
|
-
}>;
|
|
650
|
+
tooManyRequests(message?: string, error?: unknown): CoreResponse<null>;
|
|
546
651
|
/**
|
|
547
652
|
* Returns a 500 Internal Server Error response.
|
|
548
653
|
* Used for unexpected server-side errors.
|
|
549
654
|
*
|
|
550
655
|
* @param error - Error details (be careful not to expose sensitive info)
|
|
551
|
-
* @returns
|
|
656
|
+
* @returns CoreResponse with 500 status
|
|
552
657
|
*
|
|
553
658
|
* @example
|
|
554
659
|
* ```ts
|
|
@@ -560,42 +665,28 @@ export declare class ServerResponse {
|
|
|
560
665
|
* }
|
|
561
666
|
* ```
|
|
562
667
|
*/
|
|
563
|
-
internalServer(error?: unknown):
|
|
564
|
-
success: boolean;
|
|
565
|
-
message: string;
|
|
566
|
-
code: string;
|
|
567
|
-
status: number;
|
|
568
|
-
data: unknown;
|
|
569
|
-
error: unknown;
|
|
570
|
-
}>;
|
|
668
|
+
internalServer(error?: unknown): CoreResponse<null>;
|
|
571
669
|
/**
|
|
572
670
|
* Returns a 501 Not Implemented response.
|
|
573
671
|
* Used when a feature is not yet implemented.
|
|
574
672
|
*
|
|
575
673
|
* @param message - Error message (default: "Not Implemented")
|
|
576
674
|
* @param error - Detailed error information
|
|
577
|
-
* @returns
|
|
675
|
+
* @returns CoreResponse with 501 status
|
|
578
676
|
*
|
|
579
677
|
* @example
|
|
580
678
|
* ```ts
|
|
581
679
|
* return response.notImplemented("This feature is coming soon");
|
|
582
680
|
* ```
|
|
583
681
|
*/
|
|
584
|
-
notImplemented(message?: string, error?: unknown):
|
|
585
|
-
success: boolean;
|
|
586
|
-
message: string;
|
|
587
|
-
code: string;
|
|
588
|
-
status: number;
|
|
589
|
-
data: unknown;
|
|
590
|
-
error: unknown;
|
|
591
|
-
}>;
|
|
682
|
+
notImplemented(message?: string, error?: unknown): CoreResponse<null>;
|
|
592
683
|
/**
|
|
593
684
|
* Returns a 502 Bad Gateway response.
|
|
594
685
|
* Used when an upstream server returned an invalid response.
|
|
595
686
|
*
|
|
596
687
|
* @param message - Error message (default: "Bad Gateway")
|
|
597
688
|
* @param error - Detailed error information
|
|
598
|
-
* @returns
|
|
689
|
+
* @returns CoreResponse with 502 status
|
|
599
690
|
*
|
|
600
691
|
* @example
|
|
601
692
|
* ```ts
|
|
@@ -606,21 +697,14 @@ export declare class ServerResponse {
|
|
|
606
697
|
* }
|
|
607
698
|
* ```
|
|
608
699
|
*/
|
|
609
|
-
badGateway(message?: string, error?: unknown):
|
|
610
|
-
success: boolean;
|
|
611
|
-
message: string;
|
|
612
|
-
code: string;
|
|
613
|
-
status: number;
|
|
614
|
-
data: unknown;
|
|
615
|
-
error: unknown;
|
|
616
|
-
}>;
|
|
700
|
+
badGateway(message?: string, error?: unknown): CoreResponse<null>;
|
|
617
701
|
/**
|
|
618
702
|
* Returns a 503 Service Unavailable response.
|
|
619
703
|
* Used during maintenance or overload conditions.
|
|
620
704
|
*
|
|
621
705
|
* @param message - Error message (default: "Service Unavailable")
|
|
622
706
|
* @param error - Detailed error information
|
|
623
|
-
* @returns
|
|
707
|
+
* @returns CoreResponse with 503 status
|
|
624
708
|
*
|
|
625
709
|
* @example
|
|
626
710
|
* ```ts
|
|
@@ -629,21 +713,14 @@ export declare class ServerResponse {
|
|
|
629
713
|
* }
|
|
630
714
|
* ```
|
|
631
715
|
*/
|
|
632
|
-
serviceUnavailable(message?: string, error?: unknown):
|
|
633
|
-
success: boolean;
|
|
634
|
-
message: string;
|
|
635
|
-
code: string;
|
|
636
|
-
status: number;
|
|
637
|
-
data: unknown;
|
|
638
|
-
error: unknown;
|
|
639
|
-
}>;
|
|
716
|
+
serviceUnavailable(message?: string, error?: unknown): CoreResponse<null>;
|
|
640
717
|
/**
|
|
641
718
|
* Returns a 504 Gateway Timeout response.
|
|
642
719
|
* Used when an upstream server did not respond in time.
|
|
643
720
|
*
|
|
644
721
|
* @param message - Error message (default: "Gateway Timeout")
|
|
645
722
|
* @param error - Detailed error information
|
|
646
|
-
* @returns
|
|
723
|
+
* @returns CoreResponse with 504 status
|
|
647
724
|
*
|
|
648
725
|
* @example
|
|
649
726
|
* ```ts
|
|
@@ -654,12 +731,5 @@ export declare class ServerResponse {
|
|
|
654
731
|
* }
|
|
655
732
|
* ```
|
|
656
733
|
*/
|
|
657
|
-
gatewayTimeout(message?: string, error?: unknown):
|
|
658
|
-
success: boolean;
|
|
659
|
-
message: string;
|
|
660
|
-
code: string;
|
|
661
|
-
status: number;
|
|
662
|
-
data: unknown;
|
|
663
|
-
error: unknown;
|
|
664
|
-
}>;
|
|
734
|
+
gatewayTimeout(message?: string, error?: unknown): CoreResponse<null>;
|
|
665
735
|
}
|