1 | import { ValidatorOptions } from 'class-validator';
|
2 | import { ClassTransformOptions } from 'class-transformer';
|
3 | import { CurrentUserChecker } from '../CurrentUserChecker';
|
4 | import { AuthorizationChecker } from '../AuthorizationChecker';
|
5 | import { ActionMetadata } from '../metadata/ActionMetadata';
|
6 | import { ParamMetadata } from '../metadata/ParamMetadata';
|
7 | import { MiddlewareMetadata } from '../metadata/MiddlewareMetadata';
|
8 | import { Action } from '../Action';
|
9 | /**
|
10 | * Base driver functionality for all other drivers.
|
11 | * Abstract layer to organize controllers integration with different http server implementations.
|
12 | */
|
13 | export declare abstract class BaseDriver {
|
14 | /**
|
15 | * Reference to the underlying framework app object.
|
16 | */
|
17 | app: any;
|
18 | /**
|
19 | * Indicates if class-transformer should be used or not.
|
20 | */
|
21 | useClassTransformer: boolean;
|
22 | /**
|
23 | * Indicates if class-validator should be used or not.
|
24 | */
|
25 | enableValidation: boolean;
|
26 | /**
|
27 | * Global class transformer options passed to class-transformer during classToPlain operation.
|
28 | * This operation is being executed when server returns response to user.
|
29 | */
|
30 | classToPlainTransformOptions: ClassTransformOptions;
|
31 | /**
|
32 | * Global class-validator options passed during validate operation.
|
33 | */
|
34 | validationOptions: ValidatorOptions;
|
35 | /**
|
36 | * Global class transformer options passed to class-transformer during plainToClass operation.
|
37 | * This operation is being executed when parsing user parameters.
|
38 | */
|
39 | plainToClassTransformOptions: ClassTransformOptions;
|
40 | /**
|
41 | * Indicates if default routing-controllers error handler should be used or not.
|
42 | */
|
43 | isDefaultErrorHandlingEnabled: boolean;
|
44 | /**
|
45 | * Indicates if routing-controllers should operate in development mode.
|
46 | */
|
47 | developmentMode: boolean;
|
48 | /**
|
49 | * Global application prefix.
|
50 | */
|
51 | routePrefix: string;
|
52 | /**
|
53 | * Indicates if cors are enabled.
|
54 | * This requires installation of additional module (cors for express and kcors for koa).
|
55 | */
|
56 | cors?: boolean | Object;
|
57 | /**
|
58 | * Map of error overrides.
|
59 | */
|
60 | errorOverridingMap: {
|
61 | [key: string]: any;
|
62 | };
|
63 | /**
|
64 | * Special function used to check user authorization roles per request.
|
65 | * Must return true or promise with boolean true resolved for authorization to succeed.
|
66 | */
|
67 | authorizationChecker?: AuthorizationChecker;
|
68 | /**
|
69 | * Special function used to get currently authorized user.
|
70 | */
|
71 | currentUserChecker?: CurrentUserChecker;
|
72 | protected transformResult(result: any, action: ActionMetadata, options: Action): any;
|
73 | protected processJsonError(error: any): any;
|
74 | protected processTextError(error: any): any;
|
75 | protected merge(obj1: any, obj2: any): any;
|
76 | /**
|
77 | * Initializes the things driver needs before routes and middleware registration.
|
78 | */
|
79 | abstract initialize(): void;
|
80 | /**
|
81 | * Registers given middleware.
|
82 | */
|
83 | abstract registerMiddleware(middleware: MiddlewareMetadata): void;
|
84 | /**
|
85 | * Registers action in the driver.
|
86 | */
|
87 | abstract registerAction(action: ActionMetadata, executeCallback: (options: Action) => any): void;
|
88 | /**
|
89 | * Registers all routes in the framework.
|
90 | */
|
91 | abstract registerRoutes(): void;
|
92 | /**
|
93 | * Gets param from the request.
|
94 | */
|
95 | abstract getParamFromRequest(actionOptions: Action, param: ParamMetadata): any;
|
96 | /**
|
97 | * Defines an algorithm of how to handle error during executing controller action.
|
98 | */
|
99 | abstract handleError(error: any, action: ActionMetadata, options: Action): any;
|
100 | /**
|
101 | * Defines an algorithm of how to handle success result of executing controller action.
|
102 | */
|
103 | abstract handleSuccess(result: any, action: ActionMetadata, options: Action): void;
|
104 | }
|