@rabstack/rab-api 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 +393 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +1105 -0
- package/index.esm.d.ts +966 -0
- package/index.esm.js +1070 -0
- package/package.json +30 -0
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
import { Container } from 'typedi';
|
|
4
|
+
import { ErrorRequestHandler } from 'express';
|
|
5
|
+
import { Express as Express_2 } from 'express';
|
|
6
|
+
import { IncomingMessage } from 'http';
|
|
7
|
+
import type Joi from 'joi';
|
|
8
|
+
import { NextFunction } from 'express';
|
|
9
|
+
import { Request as Request_2 } from 'express';
|
|
10
|
+
import { Response as Response_2 } from 'express';
|
|
11
|
+
import { Server } from 'http';
|
|
12
|
+
import { ServerResponse } from 'http';
|
|
13
|
+
import { Service } from 'typedi';
|
|
14
|
+
|
|
15
|
+
export declare interface AbstractBloc<Params, ResultType> {
|
|
16
|
+
execute(params: Params): Promise<ResultType> | ResultType;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare type AliveKeep = boolean;
|
|
20
|
+
|
|
21
|
+
export declare type AppRoute<CreateControllerOptions extends InjectorsMetadata = any> = ControllerClassType | CreateRouterProps<CreateControllerOptions>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* AtomApi DELETE controller interface.
|
|
25
|
+
* Alias for RabApiDelete for backward compatibility.
|
|
26
|
+
*
|
|
27
|
+
* @template T - Controller type (usually DeleteController<...>)
|
|
28
|
+
*/
|
|
29
|
+
export declare type AtomApiDelete<T extends IControllerClass = any> = RabApiDelete<T>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* AtomApi GET controller interface.
|
|
33
|
+
* Alias for RabApiGet for backward compatibility.
|
|
34
|
+
*
|
|
35
|
+
* @template T - Controller type (usually GetController<...>)
|
|
36
|
+
*/
|
|
37
|
+
export declare type AtomApiGet<T extends IControllerClass = any> = RabApiGet<T>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* AtomApi PATCH controller interface.
|
|
41
|
+
* Alias for RabApiPatch for backward compatibility.
|
|
42
|
+
*
|
|
43
|
+
* @template T - Controller type (usually PatchController<...>)
|
|
44
|
+
*/
|
|
45
|
+
export declare type AtomApiPatch<T extends IControllerClass = any> = RabApiPatch<T>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* AtomApi POST controller interface.
|
|
49
|
+
* Alias for RabApiPost for backward compatibility.
|
|
50
|
+
*
|
|
51
|
+
* @template T - Controller type (usually PostController<...>)
|
|
52
|
+
*/
|
|
53
|
+
export declare type AtomApiPost<T extends IControllerClass = any> = RabApiPost<T>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* AtomApi PUT controller interface.
|
|
57
|
+
* Alias for RabApiPut for backward compatibility.
|
|
58
|
+
*
|
|
59
|
+
* @template T - Controller type (usually PutController<...>)
|
|
60
|
+
*/
|
|
61
|
+
export declare type AtomApiPut<T extends IControllerClass = any> = RabApiPut<T>;
|
|
62
|
+
|
|
63
|
+
export declare class AtomExpressApp {
|
|
64
|
+
app: Express_2;
|
|
65
|
+
private collectedRoutes;
|
|
66
|
+
private readonly options;
|
|
67
|
+
constructor(options: AtomExpressOptions);
|
|
68
|
+
use(...middleware: any): void;
|
|
69
|
+
private resolvePipes;
|
|
70
|
+
private setupRouteController;
|
|
71
|
+
private buildRouter;
|
|
72
|
+
route(routerParams: CreateRouterProps): void;
|
|
73
|
+
listen(port: number | string, callback?: () => void): Server<IncomingMessage, ServerResponse>;
|
|
74
|
+
getCollectedRoutes(): CollectedRoute[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare type AtomExpressOptions = {
|
|
78
|
+
errorHandler?: (err: any, req: Request_2, res: Response_2, next: NextFunction) => any;
|
|
79
|
+
enforceBodyValidation?: boolean;
|
|
80
|
+
enforceRouteProtection?: boolean;
|
|
81
|
+
auth?: AuthHandlerOptions;
|
|
82
|
+
openapi?: {
|
|
83
|
+
enabled?: boolean;
|
|
84
|
+
path?: string;
|
|
85
|
+
info?: {
|
|
86
|
+
title?: string;
|
|
87
|
+
version?: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
};
|
|
90
|
+
servers?: Array<{
|
|
91
|
+
url: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
variables?: Record<string, {
|
|
94
|
+
default: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
enum?: string[];
|
|
97
|
+
}>;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export declare namespace AtomHelpers {
|
|
103
|
+
export {
|
|
104
|
+
joiValidator,
|
|
105
|
+
validateJoiSchema,
|
|
106
|
+
retrieveRouteMetaData
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Core route decorator factory.
|
|
112
|
+
* Creates route decorators for different HTTP methods.
|
|
113
|
+
*
|
|
114
|
+
* @param method - HTTP method for this route
|
|
115
|
+
* @param path - URL path pattern (supports Express-style params like ':id')
|
|
116
|
+
* @param options - Route configuration options
|
|
117
|
+
* @returns Class decorator function
|
|
118
|
+
*/
|
|
119
|
+
export declare function AtomRoute(method: HttpMethod, path: string, options?: ControllerRouteDefinitionOptions): (target: any) => void;
|
|
120
|
+
|
|
121
|
+
export declare const authHandler: (isProtected: boolean, config: AuthHandlerOptions) => (req: any, res: Response_2, next: NextFunction) => void;
|
|
122
|
+
|
|
123
|
+
export declare type AuthHandlerOptions = {
|
|
124
|
+
jwt: {
|
|
125
|
+
secret_key: string;
|
|
126
|
+
algorithms: any;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Represents a 400 Bad Request error.
|
|
132
|
+
* Use this for client-side validation failures or malformed requests.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* throw new BadRequestException(
|
|
137
|
+
* 'Invalid email format',
|
|
138
|
+
* ['Email must be a valid email address'],
|
|
139
|
+
* 'INVALID_EMAIL'
|
|
140
|
+
* );
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare class BadRequestException extends RabApiError {
|
|
144
|
+
/**
|
|
145
|
+
* @param message - Human-readable error message
|
|
146
|
+
* @param errors - Optional array of detailed validation errors
|
|
147
|
+
* @param errorCode - Optional machine-readable error code for client handling
|
|
148
|
+
*/
|
|
149
|
+
constructor(message: string, errors?: string[], errorCode?: string);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export declare const bodyValidatorWithContext: (config: RouteHandleOptions) => (req: any, res: Response_2, next: NextFunction) => Promise<void>;
|
|
153
|
+
|
|
154
|
+
export declare type BuildRouterProps = CreateRouterProps & {
|
|
155
|
+
fullPath?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export declare interface CollectedRoute {
|
|
159
|
+
method: string;
|
|
160
|
+
path: string;
|
|
161
|
+
fullPath: string;
|
|
162
|
+
controller: ControllerClassType;
|
|
163
|
+
metadata: any;
|
|
164
|
+
options?: InjectorsMetadata;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Represents a 409 Conflict error.
|
|
169
|
+
* Use this when a request conflicts with the current state (e.g., duplicate resources).
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* throw new ConflictException('Email already exists', 'EMAIL_CONFLICT');
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare class ConflictException extends RabApiError {
|
|
177
|
+
/**
|
|
178
|
+
* @param message - Human-readable error message
|
|
179
|
+
* @param errorCode - Optional machine-readable error code
|
|
180
|
+
*/
|
|
181
|
+
constructor(message: string, errorCode?: string);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Controller decorator - marks a class as an injectable controller.
|
|
186
|
+
* Alias for TypeDI's @Service decorator.
|
|
187
|
+
*/
|
|
188
|
+
export declare const Controller: typeof Service;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Metadata key used to store route information via reflect-metadata.
|
|
192
|
+
*/
|
|
193
|
+
export declare const CONTROLLER_ROUTE_KEY = "controller:route";
|
|
194
|
+
|
|
195
|
+
export declare type ControllerClassType = new (...dependencies: any) => RabApiController<any, any, any>;
|
|
196
|
+
|
|
197
|
+
export declare const controllerHandler: (controller: RabApiController, config: RouteHandleOptions) => (req: any, res: any, next: any) => Promise<any>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Metadata definition for a controller route.
|
|
201
|
+
* Contains HTTP method, path, handler name, and additional options.
|
|
202
|
+
*/
|
|
203
|
+
export declare interface ControllerRouteDefinition {
|
|
204
|
+
method: HttpMethod;
|
|
205
|
+
path: string;
|
|
206
|
+
handlerName: string;
|
|
207
|
+
options?: ControllerRouteDefinitionOptions;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Options for configuring controller routes.
|
|
212
|
+
* Includes validation, permissions, middleware, and more.
|
|
213
|
+
*/
|
|
214
|
+
export declare type ControllerRouteDefinitionOptions = InjectorsMetadata;
|
|
215
|
+
|
|
216
|
+
export declare type CreateRouterProps<CreateControllerOptions extends InjectorsMetadata = any> = {
|
|
217
|
+
controllers: AppRoute<CreateControllerOptions>[];
|
|
218
|
+
basePath?: string;
|
|
219
|
+
tags?: string[];
|
|
220
|
+
} & InjectorsMetadata;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Enhanced Express Request with strongly-typed properties.
|
|
224
|
+
* Extends Express Request with type-safe query, body, params, and auth.
|
|
225
|
+
*
|
|
226
|
+
* @template TQuery - Query parameter type
|
|
227
|
+
* @template TBody - Request body type
|
|
228
|
+
* @template TParams - Route parameter type
|
|
229
|
+
* @template TUser - Authenticated user/token payload type
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* type MyRequest = CTRLRequest<
|
|
234
|
+
* { page: number }, // Query
|
|
235
|
+
* { name: string }, // Body
|
|
236
|
+
* { id: string }, // Params
|
|
237
|
+
* { userId: string } // Auth
|
|
238
|
+
* >;
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export declare interface CTRLRequest<TQuery = any, TBody = any, TParams = any, TUser = any> extends Omit<Request_2, 'body' | 'params' | 'query'> {
|
|
242
|
+
/** Parsed query parameters */
|
|
243
|
+
query: TQuery;
|
|
244
|
+
/** Parsed request body */
|
|
245
|
+
body: TBody;
|
|
246
|
+
/** Route parameters */
|
|
247
|
+
params: TParams;
|
|
248
|
+
/** Authenticated user data (from JWT token) */
|
|
249
|
+
auth: TUser;
|
|
250
|
+
/** Uploaded file (from multer or similar) */
|
|
251
|
+
file?: any;
|
|
252
|
+
/** Access grant from permission system */
|
|
253
|
+
accessGrant?: any;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Controller response type.
|
|
258
|
+
* Can be either direct data or a structured response object.
|
|
259
|
+
*
|
|
260
|
+
* @template Data - The response data type
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* // Direct response
|
|
265
|
+
* return { id: '123', name: 'John' };
|
|
266
|
+
*
|
|
267
|
+
* // Structured response
|
|
268
|
+
* return {
|
|
269
|
+
* statusCode: 201,
|
|
270
|
+
* message: 'User created',
|
|
271
|
+
* data: { id: '123', name: 'John' }
|
|
272
|
+
* };
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export declare type CTRLResponse<Data> = Data | {
|
|
276
|
+
/** HTTP status code (optional, defaults to 200) */
|
|
277
|
+
statusCode?: number;
|
|
278
|
+
/** Response message */
|
|
279
|
+
message?: string;
|
|
280
|
+
/** Response data */
|
|
281
|
+
data: Data;
|
|
282
|
+
/** If true, only data will be returned (no metadata wrapper) */
|
|
283
|
+
excludeMetaData?: boolean;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* DELETE route decorator.
|
|
288
|
+
* Registers a controller class as a DELETE endpoint handler.
|
|
289
|
+
*
|
|
290
|
+
* @param path - URL path pattern (e.g., '/users/:id')
|
|
291
|
+
* @param options - Route configuration options (validation, permissions, etc.)
|
|
292
|
+
* @returns Class decorator
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* @Delete('/users/:id', {
|
|
297
|
+
* permission: 'canDeleteUser',
|
|
298
|
+
* })
|
|
299
|
+
* export class DeleteUserController implements AtomApiDelete<T> {
|
|
300
|
+
* execute = async (request) => {
|
|
301
|
+
* await this.userService.delete(request.params.id);
|
|
302
|
+
* return { success: true };
|
|
303
|
+
* };
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export declare function Delete(path: string, options?: ControllerRouteDefinitionOptions): ClassDecorator;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* DELETE controller type.
|
|
311
|
+
* Used for endpoints that delete resources.
|
|
312
|
+
*
|
|
313
|
+
* @template TParams - Route parameter type (default: any)
|
|
314
|
+
* @template TUser - Authenticated user type (default: any)
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* type ControllerT = DeleteController<{ id: string }, TokenPayload>;
|
|
319
|
+
*
|
|
320
|
+
* @Delete('/users/:id')
|
|
321
|
+
* export class DeleteUser implements AtomApiDelete<ControllerT> {
|
|
322
|
+
* handler: ControllerT['request'] = async (request) => {
|
|
323
|
+
* await this.userBloc.delete(request.params.id);
|
|
324
|
+
* return { message: 'User deleted' };
|
|
325
|
+
* };
|
|
326
|
+
* }
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export declare type DeleteController<TParams = any, TUser = any> = IControllerClass<any, any, any, TParams, TUser>;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Dependency injection container.
|
|
333
|
+
* Provides access to TypeDI's Container for manual service retrieval.
|
|
334
|
+
*/
|
|
335
|
+
export declare const DiContainer: typeof Container;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Global error handler middleware for Express.
|
|
339
|
+
* Handles RabApiError instances with proper status codes and error formatting.
|
|
340
|
+
* Falls back to 500 Internal Server Error for unexpected errors.
|
|
341
|
+
*
|
|
342
|
+
* @param err - The error object
|
|
343
|
+
* @param req - Express request object
|
|
344
|
+
* @param res - Express response object
|
|
345
|
+
* @param next - Express next function
|
|
346
|
+
*/
|
|
347
|
+
export declare const errorHandler: ErrorRequestHandler;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Extracts the Bearer token from the Authorization header
|
|
351
|
+
*
|
|
352
|
+
* @param request - Express request object
|
|
353
|
+
* @returns The extracted token or undefined if not found or not a Bearer token
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```typescript
|
|
357
|
+
* const token = extractTokenFromHeader(req);
|
|
358
|
+
* if (!token) {
|
|
359
|
+
* throw new UnauthorizedException();
|
|
360
|
+
* }
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
export declare const extractTokenFromHeader: (request: Request_2) => string | undefined;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Represents a 403 Forbidden error.
|
|
367
|
+
* Use this when the user is authenticated but lacks permission.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* throw new ForbiddenException('You do not have permission to access this resource', 'INSUFFICIENT_PERMISSIONS');
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
export declare class ForbiddenException extends RabApiError {
|
|
375
|
+
/**
|
|
376
|
+
* @param message - Human-readable error message (default: 'Forbidden')
|
|
377
|
+
* @param errorCode - Optional machine-readable error code
|
|
378
|
+
*/
|
|
379
|
+
constructor(message?: string, errorCode?: string);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* GET route decorator.
|
|
384
|
+
* Registers a controller class as a GET endpoint handler.
|
|
385
|
+
*
|
|
386
|
+
* @param path - URL path pattern (e.g., '/users' or '/users/:id')
|
|
387
|
+
* @param options - Route configuration options (validation, permissions, etc.)
|
|
388
|
+
* @returns Class decorator
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* @Get('/users/:id', {
|
|
393
|
+
* permission: 'canReadUser',
|
|
394
|
+
* })
|
|
395
|
+
* export class GetUserController implements AtomApiGet<T> {
|
|
396
|
+
* execute = async (request) => {
|
|
397
|
+
* return this.userService.findById(request.params.id);
|
|
398
|
+
* };
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
export declare function Get(path: string, options?: ControllerRouteDefinitionOptions): ClassDecorator;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* GET controller type.
|
|
406
|
+
* Used for endpoints that retrieve data.
|
|
407
|
+
*
|
|
408
|
+
* @template TResponse - Response data type
|
|
409
|
+
* @template TQuery - Query parameter type (default: any)
|
|
410
|
+
* @template TParams - Route parameter type (default: any)
|
|
411
|
+
* @template TUser - Authenticated user type (default: any)
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* type ControllerT = GetController<User, never, { id: string }, TokenPayload>;
|
|
416
|
+
*
|
|
417
|
+
* @Get('/users/:id')
|
|
418
|
+
* export class GetUser implements RabApiGet<ControllerT> {
|
|
419
|
+
* handler: ControllerT['request'] = async (request) => {
|
|
420
|
+
* return await this.userBloc.getById(request.params.id);
|
|
421
|
+
* };
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
export declare type GetController<TResponse, TQuery = any, TParams = any, TUser = any> = IControllerClass<TQuery, any, TResponse, TParams, TUser>;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Supported HTTP methods for route decorators.
|
|
429
|
+
*/
|
|
430
|
+
export declare type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Controller class type definition.
|
|
434
|
+
* Used to define the type shape for controller implementations.
|
|
435
|
+
*
|
|
436
|
+
* @template TQuery - Query parameter type
|
|
437
|
+
* @template TBody - Request body type
|
|
438
|
+
* @template TResponse - Response data type
|
|
439
|
+
* @template TParams - Route parameter type
|
|
440
|
+
* @template TUser - Authenticated user type
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* type MyControllerT = IControllerClass<
|
|
445
|
+
* never, // No query params
|
|
446
|
+
* { name: string }, // Body type
|
|
447
|
+
* { id: string }, // Response type
|
|
448
|
+
* { id: string }, // Params type
|
|
449
|
+
* TokenPayload // User type
|
|
450
|
+
* >;
|
|
451
|
+
*
|
|
452
|
+
* class MyController implements RabApiPost<MyControllerT> {
|
|
453
|
+
* handler: MyControllerT['request'] = async (req) => {
|
|
454
|
+
* // Implementation
|
|
455
|
+
* };
|
|
456
|
+
* }
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
export declare type IControllerClass<TQuery = any, TBody = any, TResponse = any, TParams = any, TUser = any> = {
|
|
460
|
+
/** The request handler function signature */
|
|
461
|
+
request: (req: CTRLRequest<TQuery, TBody, TParams, TUser>) => Promise<CTRLResponse<TResponse>>;
|
|
462
|
+
/** Type marker for response type (not used at runtime) */
|
|
463
|
+
response: TResponse;
|
|
464
|
+
/** Type marker for body type (not used at runtime) */
|
|
465
|
+
body: TBody;
|
|
466
|
+
/** Type marker for params type (not used at runtime) */
|
|
467
|
+
params: TParams;
|
|
468
|
+
/** Type marker for user type (not used at runtime) */
|
|
469
|
+
user: TUser;
|
|
470
|
+
/** Type marker for query type (not used at runtime) */
|
|
471
|
+
query: TQuery;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
export declare type IDParams = {
|
|
475
|
+
id: string;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Injectable decorator - marks a class as injectable via dependency injection.
|
|
480
|
+
* Alias for TypeDI's @Service decorator.
|
|
481
|
+
*/
|
|
482
|
+
export declare const Injectable: typeof Service;
|
|
483
|
+
|
|
484
|
+
export declare type InjectorsMetadata<TQuery = any, TBody = any, TResponse = any, TParams = any, TParsedParams = any> = {
|
|
485
|
+
isProtected?: boolean;
|
|
486
|
+
permission?: string;
|
|
487
|
+
pipes?: PipeInjector;
|
|
488
|
+
validateResponse?: (res: TResponse) => asserts res is TResponse;
|
|
489
|
+
validateQuery?: (queryParameters: TQuery) => Promise<TQuery>;
|
|
490
|
+
validateBody?: (body: TBody) => Promise<TBody>;
|
|
491
|
+
disableBodyValidation?: boolean;
|
|
492
|
+
parseQueryParams?: (query: any) => TParsedParams;
|
|
493
|
+
bodySchema?: Joi.ObjectSchema<TBody>;
|
|
494
|
+
querySchema?: Joi.ObjectSchema<TParams>;
|
|
495
|
+
excludeFromDocs?: boolean;
|
|
496
|
+
docs?: OpenApiDocsMetadata;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Represents a 500 Internal Server Error.
|
|
501
|
+
* Use this for unexpected server-side errors.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* throw new InternalServerErrorException('Database connection failed', 'DB_ERROR');
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
export declare class InternalServerErrorException extends RabApiError {
|
|
509
|
+
/**
|
|
510
|
+
* @param message - Human-readable error message (default: 'Internal Server Error')
|
|
511
|
+
* @param errorCode - Optional machine-readable error code
|
|
512
|
+
*/
|
|
513
|
+
constructor(message?: string, errorCode?: string);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export declare const isCallBackPipe: (pipe: PipeFn | PipeFnCallBack) => pipe is PipeFnCallBack;
|
|
517
|
+
|
|
518
|
+
export declare function isRouteAController(value: AppRoute): value is ControllerClassType;
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Validates data against a Joi schema.
|
|
522
|
+
* Throws a BadRequestException with detailed error messages if validation fails.
|
|
523
|
+
*
|
|
524
|
+
* @param schema - The Joi schema to validate against
|
|
525
|
+
* @param payload - The data to validate
|
|
526
|
+
* @param options - Optional Joi validation options
|
|
527
|
+
* @returns The validated and potentially transformed data
|
|
528
|
+
* @throws {BadRequestException} When validation fails
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* const schema = Joi.object({ email: Joi.string().email().required() });
|
|
533
|
+
* const validated = await joiValidator(schema, { email: 'test@example.com' });
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
declare function joiValidator<T = any>(schema: Joi.ObjectSchema<any>, payload: T, options?: Joi.ValidationOptions): Promise<T>;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Represents a 405 Method Not Allowed error.
|
|
540
|
+
* Use this when an HTTP method is not supported for a resource.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```typescript
|
|
544
|
+
* throw new MethodNotAllowedException('DELETE method not allowed on this resource');
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
export declare class MethodNotAllowedException extends RabApiError {
|
|
548
|
+
/**
|
|
549
|
+
* @param message - Human-readable error message (default: 'Method Not Allowed')
|
|
550
|
+
* @param errorCode - Optional machine-readable error code
|
|
551
|
+
*/
|
|
552
|
+
constructor(message?: string, errorCode?: string);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Represents a 404 Not Found error.
|
|
557
|
+
* Use this when a requested resource does not exist.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* throw new NotFoundException('User not found', 'USER_NOT_FOUND');
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
export declare class NotFoundException extends RabApiError {
|
|
565
|
+
/**
|
|
566
|
+
* @param message - Human-readable error message (default: 'Not Found')
|
|
567
|
+
* @param errorCode - Optional machine-readable error code
|
|
568
|
+
*/
|
|
569
|
+
constructor(message?: string, errorCode?: string);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export declare type OpenApiDocsMetadata = {
|
|
573
|
+
summary?: string;
|
|
574
|
+
description?: string;
|
|
575
|
+
tags?: string[];
|
|
576
|
+
operationId?: string;
|
|
577
|
+
responses?: Record<string, {
|
|
578
|
+
description: string;
|
|
579
|
+
content?: Record<string, any>;
|
|
580
|
+
}>;
|
|
581
|
+
deprecated?: boolean;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
export declare class OpenApiGenerator {
|
|
585
|
+
private routes;
|
|
586
|
+
private options;
|
|
587
|
+
constructor(routes: CollectedRoute[], options: AtomExpressOptions);
|
|
588
|
+
generate(): OpenApiSpec;
|
|
589
|
+
private joiToOpenApiSchema;
|
|
590
|
+
private convertJoiDescriptionToOpenApi;
|
|
591
|
+
private generateDefaultTag;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export declare interface OpenApiSpec {
|
|
595
|
+
openapi: string;
|
|
596
|
+
info: {
|
|
597
|
+
title: string;
|
|
598
|
+
version: string;
|
|
599
|
+
description: string;
|
|
600
|
+
};
|
|
601
|
+
servers?: Array<{
|
|
602
|
+
url: string;
|
|
603
|
+
description?: string;
|
|
604
|
+
variables?: Record<string, any>;
|
|
605
|
+
}>;
|
|
606
|
+
paths: Record<string, any>;
|
|
607
|
+
components: {
|
|
608
|
+
schemas: Record<string, any>;
|
|
609
|
+
securitySchemes: Record<string, any>;
|
|
610
|
+
};
|
|
611
|
+
security?: Array<Record<string, any>>;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export declare type PagingResult<Data> = {
|
|
615
|
+
page: number;
|
|
616
|
+
pageSize: number;
|
|
617
|
+
total: number;
|
|
618
|
+
totalPages: number;
|
|
619
|
+
results: Data[];
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* PATCH route decorator.
|
|
624
|
+
* Registers a controller class as a PATCH endpoint handler.
|
|
625
|
+
* Use for partial resource updates.
|
|
626
|
+
*
|
|
627
|
+
* @param path - URL path pattern (e.g., '/users/:id')
|
|
628
|
+
* @param options - Route configuration options (validation, permissions, etc.)
|
|
629
|
+
* @returns Class decorator
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* @Patch('/users/:id', {
|
|
634
|
+
* bodySchema: patchUserSchema,
|
|
635
|
+
* permission: 'canUpdateUser',
|
|
636
|
+
* })
|
|
637
|
+
* export class PatchUserController implements AtomApiPatch<T> {
|
|
638
|
+
* execute = async (request) => {
|
|
639
|
+
* return this.userService.patch(request.params.id, request.body);
|
|
640
|
+
* };
|
|
641
|
+
* }
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
export declare function Patch(path: string, options?: ControllerRouteDefinitionOptions): ClassDecorator;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* PATCH controller type.
|
|
648
|
+
* Alias for PostController since PATCH has the same signature.
|
|
649
|
+
*/
|
|
650
|
+
export declare type PatchController<TBody = any, TResponse = any, TParams = any, TUser = any, TQuery = any> = PostController<TBody, TResponse, TParams, TUser, TQuery>;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Represents a 413 Payload Too Large error.
|
|
654
|
+
* Use this when the request payload exceeds size limits.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* throw new PayloadTooLargeException('File size exceeds 10MB limit', 'FILE_TOO_LARGE');
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
export declare class PayloadTooLargeException extends RabApiError {
|
|
662
|
+
/**
|
|
663
|
+
* @param message - Human-readable error message (default: 'Payload Too Large')
|
|
664
|
+
* @param errorCode - Optional machine-readable error code
|
|
665
|
+
*/
|
|
666
|
+
constructor(message?: string, errorCode?: string);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Request type for permission validators.
|
|
671
|
+
* Used in RAB-Access permission validation functions.
|
|
672
|
+
*
|
|
673
|
+
* @template TUser - Authenticated user type
|
|
674
|
+
* @template TParams - Route parameter type
|
|
675
|
+
* @template TBody - Request body type
|
|
676
|
+
* @template TQuery - Query parameter type
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* async function canAccessResource(
|
|
681
|
+
* request: PermissionRequest<TokenPayload, { resourceId: string }>
|
|
682
|
+
* ): Promise<boolean> {
|
|
683
|
+
* return request.auth.userId === request.params.resourceId;
|
|
684
|
+
* }
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
export declare type PermissionRequest<TUser = any, TParams = any, TBody = any, TQuery = any> = CTRLRequest<TQuery, TBody, TParams, TUser>;
|
|
688
|
+
|
|
689
|
+
export declare type PipeFn = (req: any, res: any, next: any, error?: any) => void;
|
|
690
|
+
|
|
691
|
+
export declare type PipeFnCallBack = (route: Omit<InjectorsMetadata, 'pipes'>) => PipeFn[];
|
|
692
|
+
|
|
693
|
+
export declare type PipeInjector = Array<PipeFn | PipeFnCallBack>;
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* POST route decorator.
|
|
697
|
+
* Registers a controller class as a POST endpoint handler.
|
|
698
|
+
*
|
|
699
|
+
* @param path - URL path pattern (e.g., '/users' or '/users/:id')
|
|
700
|
+
* @param options - Route configuration options (validation, permissions, etc.)
|
|
701
|
+
* @returns Class decorator
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* @Post('/users', {
|
|
706
|
+
* bodySchema: createUserSchema,
|
|
707
|
+
* permission: 'canCreateUser',
|
|
708
|
+
* })
|
|
709
|
+
* export class CreateUserController implements AtomApiPost<T> {
|
|
710
|
+
* execute = async (request) => {
|
|
711
|
+
* return this.userService.create(request.body);
|
|
712
|
+
* };
|
|
713
|
+
* }
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
export declare function Post(path: string, options?: ControllerRouteDefinitionOptions): ClassDecorator;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* POST/PUT/PATCH controller type.
|
|
720
|
+
* Used for endpoints that accept a request body.
|
|
721
|
+
*
|
|
722
|
+
* @template TBody - Request body type
|
|
723
|
+
* @template TResponse - Response data type
|
|
724
|
+
* @template TParams - Route parameter type (default: any)
|
|
725
|
+
* @template TUser - Authenticated user type (default: any)
|
|
726
|
+
* @template TQuery - Query parameter type (default: any)
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* ```typescript
|
|
730
|
+
* type ControllerT = PostController<CreateUserBody, User, never, TokenPayload>;
|
|
731
|
+
*
|
|
732
|
+
* @Post('/users', { bodySchema: createUserSchema })
|
|
733
|
+
* export class CreateUser implements RabApiPost<ControllerT> {
|
|
734
|
+
* handler: ControllerT['request'] = async (request) => {
|
|
735
|
+
* return await this.userBloc.create(request.body);
|
|
736
|
+
* };
|
|
737
|
+
* }
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
740
|
+
export declare type PostController<TBody = any, TResponse = any, TParams = any, TUser = any, TQuery = any> = IControllerClass<TQuery, TBody, TResponse, TParams, TUser>;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* PUT route decorator.
|
|
744
|
+
* Registers a controller class as a PUT endpoint handler.
|
|
745
|
+
* Use for full resource replacement.
|
|
746
|
+
*
|
|
747
|
+
* @param path - URL path pattern (e.g., '/users/:id')
|
|
748
|
+
* @param options - Route configuration options (validation, permissions, etc.)
|
|
749
|
+
* @returns Class decorator
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```typescript
|
|
753
|
+
* @Put('/users/:id', {
|
|
754
|
+
* bodySchema: updateUserSchema,
|
|
755
|
+
* permission: 'canUpdateUser',
|
|
756
|
+
* })
|
|
757
|
+
* export class UpdateUserController implements AtomApiPut<T> {
|
|
758
|
+
* execute = async (request) => {
|
|
759
|
+
* return this.userService.update(request.params.id, request.body);
|
|
760
|
+
* };
|
|
761
|
+
* }
|
|
762
|
+
* ```
|
|
763
|
+
*/
|
|
764
|
+
export declare function Put(path: string, options?: ControllerRouteDefinitionOptions): ClassDecorator;
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* PUT controller type.
|
|
768
|
+
* Alias for PostController since PUT has the same signature.
|
|
769
|
+
*/
|
|
770
|
+
export declare type PutController<TBody = any, TResponse = any, TParams = any, TUser = any, TQuery = any> = PostController<TBody, TResponse, TParams, TUser, TQuery>;
|
|
771
|
+
|
|
772
|
+
export declare class RabApi {
|
|
773
|
+
static createRouter<CreateControllerOptions extends InjectorsMetadata = any>(props: CreateRouterProps<CreateControllerOptions>): CreateRouterProps<CreateControllerOptions>;
|
|
774
|
+
static createApp(props: AtomExpressOptions): AtomExpressApp;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Base controller interface that all HTTP method controllers implement.
|
|
779
|
+
* Defines the contract for request handlers.
|
|
780
|
+
*
|
|
781
|
+
* @template TQuery - Query parameter type
|
|
782
|
+
* @template TBody - Request body type
|
|
783
|
+
* @template TResponse - Response data type
|
|
784
|
+
* @template TParams - Route parameter type
|
|
785
|
+
* @template TUser - Authenticated user type
|
|
786
|
+
*/
|
|
787
|
+
export declare interface RabApiController<TQuery = any, TBody = any, TResponse = any, TParams = any, TUser = any> {
|
|
788
|
+
/**
|
|
789
|
+
* Request handler function that processes the request and returns a response.
|
|
790
|
+
*/
|
|
791
|
+
handler: (request: CTRLRequest<TQuery, TBody, TParams, TUser>) => Promise<CTRLResponse<TResponse>>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* RabApi DELETE controller interface.
|
|
796
|
+
* Implement this interface in controller classes decorated with @Delete.
|
|
797
|
+
*
|
|
798
|
+
* @template T - Controller type (usually DeleteController<...>)
|
|
799
|
+
*/
|
|
800
|
+
export declare type RabApiDelete<T extends IControllerClass = any> = RabApiController<T['query'], T['body'], T['response'], T['params'], T['user']>;
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Base class for all RabAPI errors.
|
|
804
|
+
* Extends the native Error class with additional HTTP context.
|
|
805
|
+
*/
|
|
806
|
+
export declare class RabApiError extends Error {
|
|
807
|
+
message: string;
|
|
808
|
+
readonly statusCode: number;
|
|
809
|
+
readonly errorCode?: string;
|
|
810
|
+
readonly errors?: string[];
|
|
811
|
+
/**
|
|
812
|
+
* @param message - Human-readable error message
|
|
813
|
+
* @param statusCode - HTTP status code
|
|
814
|
+
* @param errorCode - Optional machine-readable error code
|
|
815
|
+
* @param errors - Optional array of detailed error messages
|
|
816
|
+
*/
|
|
817
|
+
constructor(message: string, statusCode: number, errorCode?: string, errors?: string[]);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* RabApi GET controller interface.
|
|
822
|
+
* Implement this interface in controller classes decorated with @Get.
|
|
823
|
+
*
|
|
824
|
+
* @template T - Controller type (usually GetController<...>)
|
|
825
|
+
*/
|
|
826
|
+
export declare type RabApiGet<T extends IControllerClass = any> = RabApiController<T['query'], T['body'], T['response'], T['params'], T['user']>;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* RabApi PATCH controller interface.
|
|
830
|
+
* Implement this interface in controller classes decorated with @Patch.
|
|
831
|
+
*
|
|
832
|
+
* @template T - Controller type (usually PatchController<...>)
|
|
833
|
+
*/
|
|
834
|
+
export declare type RabApiPatch<T extends IControllerClass = any> = RabApiController<T['query'], T['body'], T['response'], T['params'], T['user']>;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* RabApi POST controller interface.
|
|
838
|
+
* Implement this interface in controller classes decorated with @Post.
|
|
839
|
+
*
|
|
840
|
+
* @template T - Controller type (usually PostController<...>)
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* type ControllerT = PostController<CreateUserBody, User>;
|
|
845
|
+
*
|
|
846
|
+
* @Post('/users')
|
|
847
|
+
* export class CreateUser implements RabApiPost<ControllerT> {
|
|
848
|
+
* handler: ControllerT['request'] = async (req) => {...};
|
|
849
|
+
* }
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
export declare type RabApiPost<T extends IControllerClass = any> = RabApiController<T['query'], T['body'], T['response'], T['params'], T['user']>;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* RabApi PUT controller interface.
|
|
856
|
+
* Implement this interface in controller classes decorated with @Put.
|
|
857
|
+
*
|
|
858
|
+
* @template T - Controller type (usually PutController<...>)
|
|
859
|
+
*/
|
|
860
|
+
export declare type RabApiPut<T extends IControllerClass = any> = RabApiController<T['query'], T['body'], T['response'], T['params'], T['user']>;
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Represents a 408 Request Timeout error.
|
|
864
|
+
* Use this when the server times out waiting for a request.
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* ```typescript
|
|
868
|
+
* throw new RequestTimeoutException('Request took too long to complete', 'REQUEST_TIMEOUT');
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
export declare class RequestTimeoutException extends RabApiError {
|
|
872
|
+
/**
|
|
873
|
+
* @param message - Human-readable error message (default: 'Request Timeout')
|
|
874
|
+
* @param errorCode - Optional machine-readable error code
|
|
875
|
+
*/
|
|
876
|
+
constructor(message?: string, errorCode?: string);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
declare function retrieveRouteMetaData(route: ControllerClassType): ControllerRouteDefinition;
|
|
880
|
+
|
|
881
|
+
export declare type RouteHandleOptions = InjectorsMetadata & Pick<AtomExpressOptions, 'enforceBodyValidation'>;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Represents a 503 Service Unavailable error.
|
|
885
|
+
* Use this when the server is temporarily unable to handle requests.
|
|
886
|
+
*
|
|
887
|
+
* @example
|
|
888
|
+
* ```typescript
|
|
889
|
+
* throw new ServiceUnavailableException('System maintenance in progress', 'MAINTENANCE');
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
export declare class ServiceUnavailableException extends RabApiError {
|
|
893
|
+
/**
|
|
894
|
+
* @param message - Human-readable error message (default: 'Service Unavailable')
|
|
895
|
+
* @param errorCode - Optional machine-readable error code
|
|
896
|
+
*/
|
|
897
|
+
constructor(message?: string, errorCode?: string);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Represents a 429 Too Many Requests error.
|
|
902
|
+
* Use this when rate limiting is exceeded.
|
|
903
|
+
*
|
|
904
|
+
* @example
|
|
905
|
+
* ```typescript
|
|
906
|
+
* throw new TooManyRequestsException('Rate limit exceeded. Try again in 60 seconds', 'RATE_LIMIT_EXCEEDED');
|
|
907
|
+
* ```
|
|
908
|
+
*/
|
|
909
|
+
export declare class TooManyRequestsException extends RabApiError {
|
|
910
|
+
/**
|
|
911
|
+
* @param message - Human-readable error message (default: 'Too Many Requests')
|
|
912
|
+
* @param errorCode - Optional machine-readable error code
|
|
913
|
+
*/
|
|
914
|
+
constructor(message?: string, errorCode?: string);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Represents a 401 Unauthorized error.
|
|
919
|
+
* Use this when authentication is required but missing or invalid.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* throw new UnauthorizedException('Invalid token', 'TOKEN_EXPIRED');
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
export declare class UnauthorizedException extends RabApiError {
|
|
927
|
+
/**
|
|
928
|
+
* @param message - Human-readable error message (default: 'Unauthorized')
|
|
929
|
+
* @param errorCode - Optional machine-readable error code
|
|
930
|
+
*/
|
|
931
|
+
constructor(message?: string, errorCode?: string);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Represents a 422 Unprocessable Entity error.
|
|
936
|
+
* Use this for semantic validation errors (valid syntax but invalid semantics).
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```typescript
|
|
940
|
+
* throw new UnprocessableEntityException(
|
|
941
|
+
* 'Validation failed',
|
|
942
|
+
* ['Age must be at least 18', 'Email domain not allowed'],
|
|
943
|
+
* 'VALIDATION_FAILED'
|
|
944
|
+
* );
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
export declare class UnprocessableEntityException extends RabApiError {
|
|
948
|
+
/**
|
|
949
|
+
* @param message - Human-readable error message (default: 'Unprocessable Entity')
|
|
950
|
+
* @param errors - Optional array of detailed validation errors
|
|
951
|
+
* @param errorCode - Optional machine-readable error code
|
|
952
|
+
*/
|
|
953
|
+
constructor(message?: string, errors?: string[], errorCode?: string);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
export declare interface UseCase<Params, ResultType> {
|
|
957
|
+
execute(params: Params): Promise<ResultType> | ResultType;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Validates data against a Joi schema (wrapper for joiValidator).
|
|
962
|
+
* @deprecated Use joiValidator directly
|
|
963
|
+
*/
|
|
964
|
+
declare function validateJoiSchema<T>(scheme: Joi.ObjectSchema<any>, data: any): Promise<T>;
|
|
965
|
+
|
|
966
|
+
export { }
|