Skip to content

Commit d30e72f

Browse files
committed
Remove Driver interface abstraction
1 parent 5c7face commit d30e72f

File tree

5 files changed

+45
-122
lines changed

5 files changed

+45
-122
lines changed

src/driver/BaseDriver.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import {ValidatorOptions} from "class-validator";
2-
import {HttpError} from "../http-error/HttpError";
32
import {ClassTransformOptions} from "class-transformer";
3+
4+
import {HttpError} from "../http-error/HttpError";
45
import {CurrentUserChecker} from "../CurrentUserChecker";
56
import {AuthorizationChecker} from "../AuthorizationChecker";
7+
import {ActionMetadata} from "../metadata/ActionMetadata";
8+
import {ParamMetadata} from "../metadata/ParamMetadata";
9+
import {MiddlewareMetadata} from "../metadata/MiddlewareMetadata";
10+
import {Action} from "../Action";
611

712
/**
813
* Base driver functionality for all other drivers.
14+
* Abstract layer to organize controllers integration with different http server implementations.
915
*/
10-
export class BaseDriver {
16+
export abstract class BaseDriver {
1117

1218
// -------------------------------------------------------------------------
1319
// Public Properties
@@ -77,6 +83,41 @@ export class BaseDriver {
7783
*/
7884
currentUserChecker?: CurrentUserChecker;
7985

86+
/**
87+
* Initializes the things driver needs before routes and middleware registration.
88+
*/
89+
abstract initialize(): void;
90+
91+
/**
92+
* Registers given middleware.
93+
*/
94+
abstract registerMiddleware(middleware: MiddlewareMetadata): void;
95+
96+
/**
97+
* Registers action in the driver.
98+
*/
99+
abstract registerAction(action: ActionMetadata, executeCallback: (options: Action) => any): void;
100+
101+
/**
102+
* Registers all routes in the framework.
103+
*/
104+
abstract registerRoutes(): void;
105+
106+
/**
107+
* Gets param from the request.
108+
*/
109+
abstract getParamFromRequest(actionOptions: Action, param: ParamMetadata): any;
110+
111+
/**
112+
* Defines an algorithm of how to handle error during executing controller action.
113+
*/
114+
abstract handleError(error: any, action: ActionMetadata, options: Action): any;
115+
116+
/**
117+
* Defines an algorithm of how to handle success result of executing controller action.
118+
*/
119+
abstract handleSuccess(result: any, action: ActionMetadata, options: Action): void;
120+
80121
// -------------------------------------------------------------------------
81122
// Protected Methods
82123
// -------------------------------------------------------------------------

src/driver/Driver.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/driver/express/ExpressDriver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {MiddlewareMetadata} from "../../metadata/MiddlewareMetadata";
33
import {ActionMetadata} from "../../metadata/ActionMetadata";
44
import {Action} from "../../Action";
55
import {classToPlain} from "class-transformer";
6-
import {Driver} from "../Driver";
76
import {ParamMetadata} from "../../metadata/ParamMetadata";
87
import {BaseDriver} from "../BaseDriver";
98
import {ExpressMiddlewareInterface} from "./ExpressMiddlewareInterface";
@@ -20,7 +19,7 @@ const templateUrl = require("template-url");
2019
/**
2120
* Integration with express framework.
2221
*/
23-
export class ExpressDriver extends BaseDriver implements Driver {
22+
export class ExpressDriver extends BaseDriver {
2423

2524
// -------------------------------------------------------------------------
2625
// Constructor

src/driver/koa/KoaDriver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Action} from "../../Action";
22
import {ActionMetadata} from "../../metadata/ActionMetadata";
33
import {BaseDriver} from "../BaseDriver";
4-
import {Driver} from "../Driver";
54
import {MiddlewareMetadata} from "../../metadata/MiddlewareMetadata";
65
import {ParamMetadata} from "../../metadata/ParamMetadata";
76
import {UseMetadata} from "../../metadata/UseMetadata";
@@ -20,7 +19,7 @@ const templateUrl = require("template-url");
2019
/**
2120
* Integration with koa framework.
2221
*/
23-
export class KoaDriver extends BaseDriver implements Driver {
22+
export class KoaDriver extends BaseDriver {
2423

2524
// -------------------------------------------------------------------------
2625
// Constructor

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {CustomParameterDecorator} from "./CustomParameterDecorator";
2-
import {Driver} from "./driver/Driver";
32
import {ExpressDriver} from "./driver/express/ExpressDriver";
43
import {KoaDriver} from "./driver/koa/KoaDriver";
54
import {MetadataArgsStorage} from "./metadata-builder/MetadataArgsStorage";
@@ -88,7 +87,6 @@ export * from "./RoleChecker";
8887
export * from "./Action";
8988
export * from "./InterceptorInterface";
9089

91-
export * from "./driver/Driver";
9290
export * from "./driver/BaseDriver";
9391
export * from "./driver/express/ExpressDriver";
9492
export * from "./driver/koa/KoaDriver";

0 commit comments

Comments
 (0)