dinoloop
Advanced tools
Comparing version 0.1.2 to 1.0.0
@@ -1,2 +0,2 @@ | ||
import { IControllerAttribute, IBindModelAttribute } from './index'; | ||
import { IControllerAttribute } from '../modules/types'; | ||
/** | ||
@@ -42,5 +42,1 @@ * Decorate on API actions that sends response using response object | ||
export declare function Controller(prefix: string, attr?: IControllerAttribute): any; | ||
/** | ||
* Decorate on API actions to bind HttpBody to the model | ||
*/ | ||
export declare function BindModel(type: Function, options?: IBindModelAttribute): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("./index"); | ||
var metadata_1 = require("../modules/metadata"); | ||
// if an API action wants to send response on its own, decorate @SendsResponse() | ||
// this is used when action method directly sends response using response object. | ||
// this is used when action method directly sends response using express response object. | ||
// ex: like read, download file contents must be decorated with @SendsResponse | ||
@@ -12,3 +12,3 @@ // actions having @SendsResponse recommended to have void return type since return value is ignored | ||
function SendsResponse() { | ||
return index_1.AttributeMetadata.sendsResponse(); | ||
return metadata_1.AttributeMetadata.sendsResponse(); | ||
} | ||
@@ -22,3 +22,3 @@ exports.SendsResponse = SendsResponse; | ||
function Async() { | ||
return index_1.AttributeMetadata.asyncAttr(); | ||
return metadata_1.AttributeMetadata.asyncAttr(); | ||
} | ||
@@ -30,3 +30,3 @@ exports.Async = Async; | ||
function HttpGet(route) { | ||
return index_1.AttributeMetadata.httpGet(route); | ||
return metadata_1.AttributeMetadata.httpGet(route); | ||
} | ||
@@ -38,3 +38,3 @@ exports.HttpGet = HttpGet; | ||
function HttpPost(route) { | ||
return index_1.AttributeMetadata.httpPost(route); | ||
return metadata_1.AttributeMetadata.httpPost(route); | ||
} | ||
@@ -46,3 +46,3 @@ exports.HttpPost = HttpPost; | ||
function HttpDelete(route) { | ||
return index_1.AttributeMetadata.httpDelete(route); | ||
return metadata_1.AttributeMetadata.httpDelete(route); | ||
} | ||
@@ -54,3 +54,3 @@ exports.HttpDelete = HttpDelete; | ||
function HttpPatch(route) { | ||
return index_1.AttributeMetadata.httpPatch(route); | ||
return metadata_1.AttributeMetadata.httpPatch(route); | ||
} | ||
@@ -62,3 +62,3 @@ exports.HttpPatch = HttpPatch; | ||
function HttpPut(route) { | ||
return index_1.AttributeMetadata.httpPut(route); | ||
return metadata_1.AttributeMetadata.httpPut(route); | ||
} | ||
@@ -70,3 +70,3 @@ exports.HttpPut = HttpPut; | ||
function HttpHead(route) { | ||
return index_1.AttributeMetadata.httpHead(route); | ||
return metadata_1.AttributeMetadata.httpHead(route); | ||
} | ||
@@ -78,3 +78,3 @@ exports.HttpHead = HttpHead; | ||
function HttpAll(route) { | ||
return index_1.AttributeMetadata.httpAll(route); | ||
return metadata_1.AttributeMetadata.httpAll(route); | ||
} | ||
@@ -86,14 +86,4 @@ exports.HttpAll = HttpAll; | ||
function Controller(prefix, attr) { | ||
return index_1.AttributeMetadata.controller(prefix, attr); | ||
return metadata_1.AttributeMetadata.controller(prefix, attr); | ||
} | ||
exports.Controller = Controller; | ||
// Use this attribute on the action method that typically has http request body. | ||
// It reads the http request body and tries to validate the body against the provided model. | ||
// accordingly, sets the validation errors on the model instance of the controller | ||
/** | ||
* Decorate on API actions to bind HttpBody to the model | ||
*/ | ||
function BindModel(type, options) { | ||
return index_1.AttributeMetadata.bindModel(type, options); | ||
} | ||
exports.BindModel = BindModel; |
@@ -1,2 +0,3 @@ | ||
import { IDino, Express } from './index'; | ||
import { IDino } from '../modules/interfaces'; | ||
import { Express } from '../modules/types'; | ||
/** | ||
@@ -56,9 +57,5 @@ * Creates dino instance | ||
/** | ||
* Globally sets up to raise InvalidModelException | ||
*/ | ||
raiseModelError(): void; | ||
/** | ||
* Configures Dino to use DIFramework | ||
*/ | ||
dependencyInjectionResolver<T>(injector: T, cb: (injector: T, type: any) => any): void; | ||
dependencyResolver<T>(injector: T, cb: (injector: T, type: any) => any): void; | ||
/** | ||
@@ -65,0 +62,0 @@ * Binds the dino instance to express app |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("./index"); | ||
var utility_1 = require("../modules/utility"); | ||
var constants_1 = require("../modules/constants"); | ||
var middlewares_1 = require("../modules/builtin/middlewares"); | ||
var core_1 = require("../modules/core"); | ||
/** | ||
@@ -14,5 +17,5 @@ * Creates dino instance | ||
this.isBinded = false; | ||
this.appContainer = index_1.AppContainer.create(app); | ||
this.appContainer = core_1.AppContainer.create(app); | ||
this.appContainer.baseUri = baseUri; | ||
this.appContainer.routeNotFoundMiddleware = index_1.RouteNotFoundMiddleware; | ||
this.appContainer.routeNotFoundMiddleware = middlewares_1.RouteNotFoundMiddleware; | ||
} | ||
@@ -78,10 +81,2 @@ /** | ||
}; | ||
// While binding the http request body to given model, if it is invalid model | ||
// following property decides whether to trigger InvalidModelException or continue silently. | ||
/** | ||
* Globally sets up to raise InvalidModelException | ||
*/ | ||
Dino.prototype.raiseModelError = function () { | ||
this.appContainer.raiseModelError = true; | ||
}; | ||
// This method lets us choose between different di containers, | ||
@@ -93,3 +88,3 @@ // We can use angular di or inversify which are popular di containers for typescript. | ||
*/ | ||
Dino.prototype.dependencyInjectionResolver = function (injector, cb) { | ||
Dino.prototype.dependencyResolver = function (injector, cb) { | ||
this.appContainer.diContainer = injector; | ||
@@ -105,5 +100,5 @@ this.appContainer.diResolveCallback = cb; | ||
if (this.isBinded) | ||
throw new Error(index_1.Errors.dinoAlreadyBinded); | ||
if (index_1.DataUtility.isUndefinedOrNull(this.appContainer.useRouter)) { | ||
throw new Error(index_1.Errors.routerNotRegistered); | ||
throw new Error(constants_1.Errors.dinoAlreadyBinded); | ||
if (utility_1.DataUtility.isUndefinedOrNull(this.appContainer.useRouter)) { | ||
throw new Error(constants_1.Errors.routerNotRegistered); | ||
} | ||
@@ -110,0 +105,0 @@ this.isBinded = true; |
@@ -1,10 +0,2 @@ | ||
export { RouteNotFoundMiddleware } from '../modules/builtin/middlewares/route.notfound.middleware'; | ||
export { Attribute } from '../modules/constants/constants'; | ||
export { Errors } from '../modules/constants/errors'; | ||
export { AppContainer } from '../modules/core/app.container'; | ||
export { IAppContainer, IDino } from '../modules/interfaces/idino'; | ||
export { Reflector } from '../modules/lib/reflector'; | ||
export { AttributeMetadata } from '../modules/metadata/attribute'; | ||
export { DataUtility } from '../modules/utility/data.utility'; | ||
export { IControllerAttribute, IControllerAttributeExtended, IBindModelAttribute, IBindModelAttributeExtended } from '../modules/types/attribute'; | ||
export { Express } from '../modules/types/express'; | ||
export * from './dino'; | ||
export * from './attributes'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var route_notfound_middleware_1 = require("../modules/builtin/middlewares/route.notfound.middleware"); | ||
exports.RouteNotFoundMiddleware = route_notfound_middleware_1.RouteNotFoundMiddleware; | ||
var constants_1 = require("../modules/constants/constants"); | ||
exports.Attribute = constants_1.Attribute; | ||
var errors_1 = require("../modules/constants/errors"); | ||
exports.Errors = errors_1.Errors; | ||
var app_container_1 = require("../modules/core/app.container"); | ||
exports.AppContainer = app_container_1.AppContainer; | ||
var reflector_1 = require("../modules/lib/reflector"); | ||
exports.Reflector = reflector_1.Reflector; | ||
var attribute_1 = require("../modules/metadata/attribute"); | ||
exports.AttributeMetadata = attribute_1.AttributeMetadata; | ||
var data_utility_1 = require("../modules/utility/data.utility"); | ||
exports.DataUtility = data_utility_1.DataUtility; | ||
__export(require("./dino")); | ||
__export(require("./attributes")); |
@@ -5,2 +5,3 @@ export * from './api/attributes'; | ||
export * from './modules/builtin/providers/user.identity'; | ||
export * from './modules/constants/http.status.code'; | ||
export { ApiController } from './modules/controller/api.controller'; | ||
@@ -13,7 +14,4 @@ export { ErrorController } from './modules/controller/error.controller'; | ||
export * from './modules/sequence/deferrer'; | ||
export * from './modules/providers/providers'; | ||
export * from './modules/providers/iuser.identity'; | ||
export * from './modules/types/attribute'; | ||
export * from './modules/types/express'; | ||
export * from './modules/validations/types/ivalidator'; | ||
export * from './modules/validations/attributes'; | ||
export * from './modules/validations/validator'; |
@@ -6,2 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Everywhere else we are referring to export by directory level. | ||
// However, here export only specific types/files | ||
// because these are consumed by end user | ||
__export(require("./api/attributes")); | ||
@@ -12,2 +15,3 @@ var dino_1 = require("./api/dino"); | ||
__export(require("./modules/builtin/providers/user.identity")); | ||
__export(require("./modules/constants/http.status.code")); | ||
var api_controller_1 = require("./modules/controller/api.controller"); | ||
@@ -23,4 +27,2 @@ exports.ApiController = api_controller_1.ApiController; | ||
__export(require("./modules/sequence/deferrer")); | ||
__export(require("./modules/providers/providers")); | ||
__export(require("./modules/validations/attributes")); | ||
__export(require("./modules/validations/validator")); | ||
__export(require("./modules/providers/iuser.identity")); |
@@ -1,4 +0,4 @@ | ||
import { UserException } from '../../exception/user.exception'; | ||
import { UserException } from '../../exception'; | ||
/** | ||
* Typically passing null/undefined as arguments invokes this exception | ||
* Passing Invalid values for arguments invokes this exception | ||
*/ | ||
@@ -5,0 +5,0 @@ export declare class InvalidArgumentException extends UserException { |
@@ -13,6 +13,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var user_exception_1 = require("../../exception/user.exception"); | ||
var data_utility_1 = require("../../utility/data.utility"); | ||
var exception_1 = require("../../exception"); | ||
var utility_1 = require("../../utility"); | ||
/** | ||
* Typically passing null/undefined as arguments invokes this exception | ||
* Passing Invalid values for arguments invokes this exception | ||
*/ | ||
@@ -25,3 +25,3 @@ var InvalidArgumentException = (function (_super) { | ||
_this.type = InvalidArgumentException.name; | ||
_this.message = data_utility_1.DataUtility.isEmpty(msg) | ||
_this.message = utility_1.DataUtility.isEmpty(msg) | ||
? InvalidArgumentException.name : msg; | ||
@@ -31,3 +31,3 @@ return _this; | ||
return InvalidArgumentException; | ||
}(user_exception_1.UserException)); | ||
}(exception_1.UserException)); | ||
exports.InvalidArgumentException = InvalidArgumentException; | ||
@@ -46,3 +46,3 @@ /** | ||
_this.type = InvalidRouteException.name; | ||
_this.message = data_utility_1.DataUtility.isEmpty(msg) | ||
_this.message = utility_1.DataUtility.isEmpty(msg) | ||
? InvalidRouteException.name : msg; | ||
@@ -52,3 +52,3 @@ return _this; | ||
return InvalidRouteException; | ||
}(user_exception_1.UserException)); | ||
}(exception_1.UserException)); | ||
exports.InvalidRouteException = InvalidRouteException; | ||
@@ -65,3 +65,3 @@ /** | ||
_this.type = RouteNotFoundException.name; | ||
_this.message = data_utility_1.DataUtility.isEmpty(msg) | ||
_this.message = utility_1.DataUtility.isEmpty(msg) | ||
? RouteNotFoundException.name : msg; | ||
@@ -71,3 +71,3 @@ return _this; | ||
return RouteNotFoundException; | ||
}(user_exception_1.UserException)); | ||
}(exception_1.UserException)); | ||
exports.RouteNotFoundException = RouteNotFoundException; | ||
@@ -85,3 +85,3 @@ /** | ||
_this.type = InvalidModelException.name; | ||
_this.message = data_utility_1.DataUtility.isEmpty(msg) | ||
_this.message = utility_1.DataUtility.isEmpty(msg) | ||
? InvalidModelException.name : msg; | ||
@@ -91,3 +91,3 @@ return _this; | ||
return InvalidModelException; | ||
}(user_exception_1.UserException)); | ||
}(exception_1.UserException)); | ||
exports.InvalidModelException = InvalidModelException; |
@@ -1,2 +0,3 @@ | ||
import { RequestStartMiddleware } from '../../filter/filter'; | ||
import { RequestStartMiddleware } from '../../filter'; | ||
import { Response } from '../../types'; | ||
/** | ||
@@ -7,3 +8,3 @@ * initializes dino property on express response.locals for every request start. | ||
export declare class DinoStartMiddleware extends RequestStartMiddleware { | ||
invoke(req: any, res: any, next: any): void; | ||
invoke(req: any, res: Response, next: any): void; | ||
} |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var filter_1 = require("../../filter/filter"); | ||
var filter_1 = require("../../filter"); | ||
/** | ||
@@ -16,0 +16,0 @@ * initializes dino property on express response.locals for every request start. |
@@ -1,2 +0,3 @@ | ||
import { RequestEndMiddleware } from '../../filter/filter'; | ||
import { RequestEndMiddleware } from '../../filter'; | ||
import { Response } from '../../types'; | ||
/** | ||
@@ -6,3 +7,3 @@ * Formats result as JSON response | ||
export declare class ResponseEndMiddleware extends RequestEndMiddleware { | ||
invoke(request: any, response: any, next: any, result: any): void; | ||
invoke(request: any, response: Response, next: any, result: any): void; | ||
} |
@@ -13,3 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var filter_1 = require("../../filter/filter"); | ||
var filter_1 = require("../../filter"); | ||
var utility_1 = require("../../utility"); | ||
var constants_1 = require("../../constants"); | ||
// If user did not configure requestEnd middleware to send response | ||
@@ -27,3 +29,8 @@ // then ResponseMiddleware is the last requestEnd middleware that gets fired, | ||
ResponseEndMiddleware.prototype.invoke = function (request, response, next, result) { | ||
response.json(result); | ||
if (utility_1.DataUtility.isUndefined(result)) { | ||
response.status(constants_1.HttpStatusCode.NoContent).json(); | ||
} | ||
else { | ||
response.status(constants_1.HttpStatusCode.OK).json(result); | ||
} | ||
}; | ||
@@ -30,0 +37,0 @@ return ResponseEndMiddleware; |
@@ -1,2 +0,2 @@ | ||
import { ErrorMiddleware } from '../../filter/filter'; | ||
import { ErrorMiddleware } from '../../filter'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Handles RouteNotFoundException thrown by RouteNotFoundMiddleware |
@@ -13,4 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var filter_1 = require("../../filter/filter"); | ||
var exceptions_1 = require("../exceptions/exceptions"); | ||
var filter_1 = require("../../filter"); | ||
var exceptions_1 = require("../exceptions"); | ||
var constants_1 = require("../../constants"); | ||
/** | ||
@@ -27,3 +28,5 @@ * Handles RouteNotFoundException thrown by RouteNotFoundMiddleware | ||
var ex = err; | ||
response.json("Cannot " + ex.httpVerb + " " + ex.requestUrl); | ||
response | ||
.status(constants_1.HttpStatusCode.NotFound) | ||
.json("Cannot " + ex.httpVerb + " " + ex.requestUrl); | ||
} | ||
@@ -30,0 +33,0 @@ else { |
@@ -1,4 +0,4 @@ | ||
import { RequestStartMiddleware } from '../../filter/filter'; | ||
import { Response, Request } from '../../types/express'; | ||
import { IRouteTable } from '../../interfaces/idino'; | ||
import { RequestStartMiddleware } from '../../filter'; | ||
import { Response, Request } from '../../types'; | ||
import { IRouteTable } from '../../interfaces'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Compares the requested route against the registered routes |
@@ -14,5 +14,5 @@ "use strict"; | ||
// tslint:disable-next-line:no-require-imports | ||
var UrlParser = require("url-pattern"); | ||
var filter_1 = require("../../filter/filter"); | ||
var exceptions_1 = require("../exceptions/exceptions"); | ||
var pathToRegexp = require("path-to-regexp"); | ||
var filter_1 = require("../../filter"); | ||
var exceptions_1 = require("../exceptions"); | ||
// it would proceed to next handler only if valid route is matched | ||
@@ -38,3 +38,3 @@ // if valid route is not found, it fires error middleware chain | ||
var route = routes_1[_i]; | ||
this.routes.push(new UrlParser(route)); | ||
this.routes.push(pathToRegexp(route)); | ||
} | ||
@@ -49,4 +49,3 @@ this.isRouteTableLoaded = true; | ||
var route = _b[_a]; | ||
var values = route.match(requestUrl); | ||
if (values !== null) { | ||
if (route.test(requestUrl)) { | ||
isRouteMatched = true; | ||
@@ -53,0 +52,0 @@ break; |
@@ -1,2 +0,3 @@ | ||
import { RequestStartMiddleware } from '../../filter/filter'; | ||
import { RequestStartMiddleware } from '../../filter'; | ||
import { Response } from '../../types'; | ||
/** | ||
@@ -7,3 +8,3 @@ * Sets context property to UserIdentity instance for every request start. | ||
export declare class TaskContextMiddleware extends RequestStartMiddleware { | ||
invoke(req: any, res: any, next: any): void; | ||
invoke(req: any, res: Response, next: any): void; | ||
} |
@@ -13,4 +13,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var filter_1 = require("../../filter/filter"); | ||
var user_identity_1 = require("../providers/user.identity"); | ||
var filter_1 = require("../../filter"); | ||
var providers_1 = require("../providers"); | ||
/** | ||
@@ -27,3 +27,3 @@ * Sets context property to UserIdentity instance for every request start. | ||
var dinoProperties = res.locals.dino; | ||
dinoProperties.context = new user_identity_1.UserIdentity(); | ||
dinoProperties.context = new providers_1.UserIdentity(); | ||
next(); | ||
@@ -30,0 +30,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { IUserIdentity } from '../../providers/providers'; | ||
import { IUserIdentity } from '../../providers'; | ||
/** | ||
@@ -3,0 +3,0 @@ * UserIdentity principal context object |
@@ -13,4 +13,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var providers_1 = require("../../providers/providers"); | ||
var data_utility_1 = require("../../utility/data.utility"); | ||
var providers_1 = require("../../providers"); | ||
var utility_1 = require("../../utility"); | ||
/** | ||
@@ -33,3 +33,3 @@ * UserIdentity principal context object | ||
UserIdentity.prototype.contains = function (key) { | ||
return !(data_utility_1.DataUtility.isUndefined(this.data[key]) && | ||
return !(utility_1.DataUtility.isUndefined(this.data[key]) && | ||
this.data.hasOwnProperty(key) === false); | ||
@@ -36,0 +36,0 @@ }; |
@@ -8,3 +8,3 @@ "use strict"; | ||
bindModel: 'bindModelAttribute', | ||
errorControllerDefaultMethod: 'write', | ||
errorControllerDefaultMethod: 'internalServerError', | ||
httpGet: 'httpGetAttribute', | ||
@@ -11,0 +11,0 @@ httpPost: 'httpPostAttribute', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Errors = { | ||
dinoAlreadyBinded: 'dino.bind: Already invoked', | ||
routerNotRegistered: 'Express router is not registered with dino' | ||
dinoAlreadyBinded: 'dino.bind(): Already invoked.', | ||
routerNotRegistered: 'Express router is not registered with dino.' | ||
}; |
@@ -1,4 +0,3 @@ | ||
import { Request, Response, NextFunction } from '../types/express'; | ||
import { DinoResponse } from '../entities/dino.response'; | ||
import { DinoModel } from '../entities/dino.model'; | ||
import { Request, Response, NextFunction } from '../types'; | ||
import { DinoResponse, DinoModel } from '../entities'; | ||
/** | ||
@@ -21,3 +20,6 @@ * Every API Controller must extend this class | ||
dino: DinoResponse; | ||
/** | ||
* Reserved for future | ||
*/ | ||
model: DinoModel; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { IBindModelAttributeExtended } from '../types/attribute'; | ||
import { IBindModelAttributeExtended } from '../types'; | ||
export declare class ControllerAction { | ||
@@ -3,0 +3,0 @@ sendsResponse?: boolean; |
@@ -1,2 +0,2 @@ | ||
import { Request, Response, NextFunction } from '../types/express'; | ||
import { Request, Response, NextFunction } from '../types'; | ||
/** | ||
@@ -22,3 +22,3 @@ * ApplicationError controller must extend this class | ||
*/ | ||
abstract write(): void; | ||
abstract internalServerError(): void; | ||
} |
@@ -1,4 +0,3 @@ | ||
import { Express } from '../types/express'; | ||
import { IAppContainer } from '../interfaces/idino'; | ||
import { IRouterCallBack } from '../types/attribute'; | ||
import { Express, IRouterCallBack } from '../types'; | ||
import { IAppContainer } from '../interfaces'; | ||
export declare class AppContainer implements IAppContainer { | ||
@@ -5,0 +4,0 @@ private app; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dino_container_1 = require("./dino.container"); | ||
var data_utility_1 = require("../utility/data.utility"); | ||
var dino_start_middleware_1 = require("../builtin/middlewares/dino.start.middleware"); | ||
var task_context_middleware_1 = require("../builtin/middlewares/task.context.middleware"); | ||
var response_end_middleware_1 = require("../builtin/middlewares/response.end.middleware"); | ||
var route_exception_middleware_1 = require("../builtin/middlewares/route.exception.middleware"); | ||
var utility_1 = require("../utility"); | ||
var middlewares_1 = require("../builtin/middlewares"); | ||
var AppContainer = (function () { | ||
@@ -31,7 +28,7 @@ function AppContainer(app) { | ||
// attach dino property to response object on every request start | ||
dinoContainer.builtInRequestStartMiddleware(dino_start_middleware_1.DinoStartMiddleware); | ||
dinoContainer.builtInRequestStartMiddleware(middlewares_1.DinoStartMiddleware); | ||
if (this.enableTaskContext) { | ||
dinoContainer.builtInRequestStartMiddleware(task_context_middleware_1.TaskContextMiddleware); | ||
dinoContainer.builtInRequestStartMiddleware(middlewares_1.TaskContextMiddleware); | ||
} | ||
if (!data_utility_1.DataUtility.isUndefinedOrNull(this.routeNotFoundMiddleware)) { | ||
if (!utility_1.DataUtility.isUndefinedOrNull(this.routeNotFoundMiddleware)) { | ||
dinoContainer.routeNotFoundMiddleware(this.routeNotFoundMiddleware); | ||
@@ -53,3 +50,3 @@ } | ||
// must be registered after registering user requestEndMiddlewares | ||
dinoContainer.builtInRequestEndMiddleware(response_end_middleware_1.ResponseEndMiddleware); | ||
dinoContainer.builtInRequestEndMiddleware(middlewares_1.ResponseEndMiddleware); | ||
for (var _f = 0, _g = this.errorMiddleware; _f < _g.length; _f++) { | ||
@@ -62,3 +59,3 @@ var middleware = _g[_f]; | ||
// make sure to register only after registering ErrorMiddleWares | ||
if (!data_utility_1.DataUtility.isUndefinedOrNull(this.errorController)) { | ||
if (!utility_1.DataUtility.isUndefinedOrNull(this.errorController)) { | ||
dinoContainer.registerErrorController(this.errorController); | ||
@@ -68,3 +65,3 @@ } | ||
// must be registered after registering user ErrorMiddlewares | ||
dinoContainer.builtInErrorMiddleware(route_exception_middleware_1.RouteExceptionMiddleware); | ||
dinoContainer.builtInErrorMiddleware(middlewares_1.RouteExceptionMiddleware); | ||
}; | ||
@@ -71,0 +68,0 @@ AppContainer.create = function (app) { |
@@ -1,2 +0,2 @@ | ||
import { IDIContainer } from '../interfaces/idino'; | ||
import { IDIContainer } from '../interfaces'; | ||
export declare class DIContainer implements IDIContainer { | ||
@@ -3,0 +3,0 @@ private injector; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var data_utility_1 = require("../utility/data.utility"); | ||
var utility_1 = require("../utility"); | ||
var DIContainer = (function () { | ||
@@ -14,3 +14,3 @@ function DIContainer(injector, cb) { | ||
DIContainer.prototype.resolve = function (type) { | ||
return (!data_utility_1.DataUtility.isUndefinedOrNull(this.cb)) ? | ||
return (!utility_1.DataUtility.isUndefinedOrNull(this.cb)) ? | ||
this.cb(this.injector, type) : new type(); | ||
@@ -17,0 +17,0 @@ }; |
@@ -1,7 +0,5 @@ | ||
import { Response } from '../types/express'; | ||
import { ApiController } from '../controller/api.controller'; | ||
import { DinoController } from '../core/dino.controller'; | ||
import { IDinoContainer } from '../interfaces/idino'; | ||
import { IDinoContainerConfig, IDinoProperties } from '../types/dino.types'; | ||
import { IControllerAttributeProvider, IBindModelAttributeExtended, IActionMethodAttribute } from '../types/attribute'; | ||
import { DinoController } from './dino.controller'; | ||
import { ApiController } from '../controller'; | ||
import { IDinoContainer } from '../interfaces'; | ||
import { IControllerAttributeProvider, IBindModelAttributeExtended, IActionMethodAttribute, IDinoContainerConfig, IDinoProperties, Response } from '../types'; | ||
export declare class DinoContainer implements IDinoContainer { | ||
@@ -8,0 +6,0 @@ private diContainer; |
@@ -39,13 +39,10 @@ "use strict"; | ||
var dicontainer_1 = require("./dicontainer"); | ||
var dino_utility_1 = require("../utility/dino.utility"); | ||
var dino_controller_1 = require("../core/dino.controller"); | ||
var dino_router_1 = require("../router/dino.router"); | ||
var dino_controller_1 = require("./dino.controller"); | ||
var dino_error_controller_1 = require("./dino.error.controller"); | ||
var route_table_1 = require("../router/route.table"); | ||
var data_utility_1 = require("../utility/data.utility"); | ||
var controller_action_1 = require("../controller/controller.action"); | ||
var reflector_1 = require("../lib/reflector"); | ||
var object_utility_1 = require("../utility/object.utility"); | ||
var constants_1 = require("../constants/constants"); | ||
var providers_1 = require("../providers/providers"); | ||
var router_1 = require("../router"); | ||
var controller_1 = require("../controller"); | ||
var lib_1 = require("../lib"); | ||
var utility_1 = require("../utility"); | ||
var constants_1 = require("../constants"); | ||
var providers_1 = require("../providers"); | ||
var DinoContainer = (function () { | ||
@@ -59,3 +56,3 @@ function DinoContainer(config) { | ||
this.diContainer = dicontainer_1.DIContainer.create(config.diContainer, config.diResolveCb); | ||
this.routeTable = route_table_1.RouteTable.create(); | ||
this.routeTable = router_1.RouteTable.create(); | ||
} | ||
@@ -67,6 +64,6 @@ // made public for unit test and not available on interface contract | ||
return this.enableTaskContext ? | ||
object_utility_1.ObjectUtility.replaceObjectReferences(o, dino.context, providers_1.IUserIdentity) : o; | ||
utility_1.ObjectUtility.replaceObjectReferences(o, dino.context, providers_1.IUserIdentity) : o; | ||
}; | ||
DinoContainer.prototype.routeNotFoundMiddleware = function (middleware) { | ||
if (dino_utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
// created as singleton object | ||
@@ -82,3 +79,3 @@ var mw_1 = new middleware(this.routeTable); | ||
DinoContainer.prototype.builtInRequestStartMiddleware = function (middleware) { | ||
if (dino_utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
var mw_2 = new middleware(); | ||
@@ -92,3 +89,3 @@ this.app.use(this.baseUri, function (req, res, next) { | ||
DinoContainer.prototype.builtInRequestEndMiddleware = function (middleware) { | ||
if (dino_utility_1.DinoUtility.isSyncRequestEndMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncRequestEndMiddleware(middleware)) { | ||
var mw_3 = new middleware(); | ||
@@ -102,3 +99,3 @@ this.app.use(this.baseUri, function (req, res, next) { | ||
DinoContainer.prototype.builtInErrorMiddleware = function (middleware) { | ||
if (dino_utility_1.DinoUtility.isSyncErrorMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncErrorMiddleware(middleware)) { | ||
var mw_4 = new middleware(); | ||
@@ -112,3 +109,3 @@ this.app.use(this.baseUri, function (err, req, res, next) { | ||
var _this = this; | ||
if (dino_utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncRequestStartMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (req, res, next) { | ||
@@ -119,3 +116,3 @@ var mw = _this.resolve(middleware, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncRequestStartMiddleware(middleware)) { | ||
else if (utility_1.DinoUtility.isAsyncRequestStartMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -144,3 +141,3 @@ var mw, err_1; | ||
var _this = this; | ||
if (dino_utility_1.DinoUtility.isSyncRequestEndMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncRequestEndMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (req, res, next) { | ||
@@ -151,3 +148,3 @@ var mw = _this.resolve(middleware, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncRequestEndMiddleware(middleware)) { | ||
else if (utility_1.DinoUtility.isAsyncRequestEndMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -177,3 +174,3 @@ var mw, err_2; | ||
var _this = this; | ||
if (dino_utility_1.DinoUtility.isSyncErrorMiddleware(middleware)) { | ||
if (utility_1.DinoUtility.isSyncErrorMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (err, req, res, next) { | ||
@@ -184,3 +181,3 @@ var mw = _this.resolve(middleware, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncErrorMiddleware(middleware)) { | ||
else if (utility_1.DinoUtility.isAsyncErrorMiddleware(middleware)) { | ||
this.app.use(this.baseUri, function (err, req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -213,3 +210,3 @@ var mw, err_3; | ||
var _this = this; | ||
if (dino_utility_1.DinoUtility.isErrorController(type)) { | ||
if (utility_1.DinoUtility.isErrorController(type)) { | ||
this.app.use(this.baseUri, function (err, req, res, next) { | ||
@@ -226,3 +223,3 @@ var api = _this.resolve(type, res.locals.dino); | ||
var api = this.resolve(type, res.locals.dino); | ||
var action = controller_action_1.ControllerAction.create(sendsResponse, bindsModel); | ||
var action = controller_1.ControllerAction.create(sendsResponse, bindsModel); | ||
var ctx = dino_controller_1.DinoController.create(api, action); | ||
@@ -234,4 +231,4 @@ return ctx; | ||
DinoContainer.prototype.populateControllerMiddlewares = function (obj) { | ||
var objProto = object_utility_1.ObjectUtility.getPrototypeOf(obj); | ||
var metadata = reflector_1.Reflector.getMetadata(constants_1.Attribute.controller, obj); | ||
var objProto = utility_1.ObjectUtility.getPrototypeOf(obj); | ||
var metadata = lib_1.Reflector.getMetadata(constants_1.Attribute.controller, obj); | ||
var exceptionFilters = []; | ||
@@ -244,3 +241,3 @@ var resultFilters = []; | ||
var expressWares = []; | ||
while (!(data_utility_1.DataUtility.isUndefinedOrNull(metadata))) { | ||
while (!(utility_1.DataUtility.isUndefinedOrNull(metadata))) { | ||
var reverseFilters = metadata.filters.slice().reverse(); | ||
@@ -277,4 +274,4 @@ metadata.middlewares.reverse(); | ||
} | ||
objProto = object_utility_1.ObjectUtility.getPrototypeOf(objProto); | ||
metadata = reflector_1.Reflector.getOwnMetadata(constants_1.Attribute.controller, objProto); | ||
objProto = utility_1.ObjectUtility.getPrototypeOf(objProto); | ||
metadata = lib_1.Reflector.getOwnMetadata(constants_1.Attribute.controller, objProto); | ||
} | ||
@@ -302,10 +299,10 @@ expressWares.reverse(); | ||
DinoContainer.prototype.getActionMethodMetadata = function (httpAttribute, actionName, controller) { | ||
var route = reflector_1.Reflector.getMetadata(httpAttribute, controller, actionName); | ||
var bindsModel = reflector_1.Reflector.getMetadata(constants_1.Attribute.bindModel, controller, actionName); | ||
var route = lib_1.Reflector.getMetadata(httpAttribute, controller, actionName); | ||
var bindsModel = lib_1.Reflector.getMetadata(constants_1.Attribute.bindModel, controller, actionName); | ||
var httpVerb = constants_1.RouteAttribute[httpAttribute]; | ||
var isAsync = reflector_1.Reflector.hasMetadata(constants_1.Attribute.asyncAttr, controller, actionName); | ||
var sendsResponse = reflector_1.Reflector.hasMetadata(constants_1.Attribute.sendsResponse, controller, actionName); | ||
if (!data_utility_1.DataUtility.isUndefinedOrNull(bindsModel)) { | ||
var isAsync = lib_1.Reflector.hasMetadata(constants_1.Attribute.asyncAttr, controller, actionName); | ||
var sendsResponse = lib_1.Reflector.hasMetadata(constants_1.Attribute.sendsResponse, controller, actionName); | ||
if (!utility_1.DataUtility.isUndefinedOrNull(bindsModel)) { | ||
bindsModel.options.raiseModelError = | ||
data_utility_1.DataUtility.isUndefinedOrNull(bindsModel.options.raiseModelError) | ||
utility_1.DataUtility.isUndefinedOrNull(bindsModel.options.raiseModelError) | ||
? this.raiseModelError : bindsModel.options.raiseModelError; | ||
@@ -324,9 +321,9 @@ } | ||
var _this = this; | ||
if (!dino_utility_1.DinoUtility.isApiController(type)) | ||
if (!utility_1.DinoUtility.isApiController(type)) | ||
return; | ||
var controller = object_utility_1.ObjectUtility.create(type.prototype); | ||
var controller = utility_1.ObjectUtility.create(type.prototype); | ||
// validate if the controller has @Controller attribute | ||
if (reflector_1.Reflector.hasMetadata(constants_1.Attribute.controller, controller)) { | ||
if (lib_1.Reflector.hasMetadata(constants_1.Attribute.controller, controller)) { | ||
var metadata_1 = this.populateControllerMiddlewares(controller); | ||
var dinoRoute = dino_router_1.DinoRouter.create({ | ||
var dinoRoute = router_1.DinoRouter.create({ | ||
enableTaskContext: this.enableTaskContext, | ||
@@ -336,3 +333,3 @@ routerCb: this.useRouterCb, | ||
}); | ||
var router_1 = dinoRoute.expressRouter(); | ||
var router_2 = dinoRoute.expressRouter(); | ||
// Register expresswares before anything else gets registered on the router | ||
@@ -342,3 +339,3 @@ // expresswares are the native express middleware handlers. | ||
var expressWare = _a[_i]; | ||
router_1.use(expressWare); | ||
router_2.use(expressWare); | ||
} | ||
@@ -349,5 +346,5 @@ dinoRoute.registerMiddlewares(metadata_1.middlewares); | ||
// loop through every HttpVerb key i.e. get, post ... | ||
object_utility_1.ObjectUtility.keys(constants_1.RouteAttribute).forEach(function (httpAttribute) { | ||
utility_1.ObjectUtility.keys(constants_1.RouteAttribute).forEach(function (httpAttribute) { | ||
// Check if the controller action has HttpVerb (get, post ...) attribute | ||
if (reflector_1.Reflector.hasMetadata(httpAttribute, controller, actionName)) { | ||
if (lib_1.Reflector.hasMetadata(httpAttribute, controller, actionName)) { | ||
var action_1 = _this.getActionMethodMetadata(httpAttribute, actionName, controller); | ||
@@ -357,3 +354,3 @@ _this.routeTable | ||
if (action_1.isAsync) { | ||
router_1[action_1.httpVerb](action_1.route, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
router_2[action_1.httpVerb](action_1.route, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var ctx; | ||
@@ -369,3 +366,3 @@ return __generator(this, function (_a) { | ||
else { | ||
router_1[action_1.httpVerb](action_1.route, function (req, res, next) { | ||
router_2[action_1.httpVerb](action_1.route, function (req, res, next) { | ||
var ctx = _this.setUpDinoController(type, action_1.sendsResponse, action_1.bindsModel, res); | ||
@@ -387,3 +384,3 @@ ctx.patch(req, res, next); | ||
// Register the router on the app instance | ||
this.app.use(this.baseUri + metadata_1.prefix, router_1); | ||
this.app.use(this.baseUri + metadata_1.prefix, router_2); | ||
// Note: router specific Error middlewares must be registered, | ||
@@ -390,0 +387,0 @@ // only after registering the router with the express.app instance. |
@@ -1,6 +0,5 @@ | ||
import { ApiController } from '../controller/api.controller'; | ||
import { Request, Response, NextFunction } from '../types/express'; | ||
import { ControllerAction } from '../controller/controller.action'; | ||
import { DinoModel } from '../entities/dino.model'; | ||
import { IDinoController } from '../interfaces/idino'; | ||
import { ApiController, ControllerAction } from '../controller'; | ||
import { Request, Response, NextFunction } from '../types'; | ||
import { DinoModel } from '../entities'; | ||
import { IDinoController } from '../interfaces'; | ||
export declare class DinoController implements IDinoController { | ||
@@ -7,0 +6,0 @@ private controller; |
@@ -38,8 +38,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var route_utility_1 = require("../utility/route.utility"); | ||
var http_utility_1 = require("../utility/http.utility"); | ||
var data_utility_1 = require("../utility/data.utility"); | ||
var validator_1 = require("../validations/validator"); | ||
var dino_model_1 = require("../entities/dino.model"); | ||
var exceptions_1 = require("../builtin/exceptions/exceptions"); | ||
var utility_1 = require("../utility"); | ||
var entities_1 = require("../entities"); | ||
var DinoController = (function () { | ||
@@ -53,3 +49,3 @@ function DinoController(controller, controllerAction) { | ||
var req = this.controller.request; | ||
return route_utility_1.RouteUtility.mapSegmentsAndQueryToActionArguments(requestUrl, req.path, req.query, action); | ||
return utility_1.RouteUtility.mapSegmentsAndQueryToActionArguments(requestUrl, req.path, req.query, action); | ||
}; | ||
@@ -75,12 +71,15 @@ // made public for unit test and not available on interface contract | ||
var bModel = this.controllerAction.bindsModel; | ||
var dinoModel = new dino_model_1.DinoModel(); | ||
if (http_utility_1.HttpUtility.hasBody(httpVerb) && !data_utility_1.DataUtility.isUndefinedOrNull(bModel)) { | ||
dinoModel.type = bModel.model; | ||
dinoModel.value = ctx.request.body; | ||
dinoModel.errors = validator_1.Validator.tryValidateWithType(ctx.request.body, bModel.model, bModel.options.stopOnError); | ||
dinoModel.isValid = dinoModel.errors.length === 0; | ||
if (bModel.options.raiseModelError) { | ||
ctx.next(new exceptions_1.InvalidModelException(dinoModel.value, dinoModel.errors, dinoModel.type)); | ||
} | ||
} | ||
var dinoModel = new entities_1.DinoModel(); | ||
// TODO when @ModelBinder is added | ||
// if (HttpUtility.hasBody(httpVerb) && !DataUtility.isUndefinedOrNull(bModel)) { | ||
// dinoModel.type = bModel.model; | ||
// dinoModel.value = ctx.request.body; | ||
// dinoModel.errors = Validator.tryValidateWithType(ctx.request.body, | ||
// bModel.model, bModel.options.stopOnError); | ||
// dinoModel.isValid = dinoModel.errors.length === 0; | ||
// if (bModel.options.raiseModelError) { | ||
// ctx.next(new InvalidModelException(dinoModel.value, dinoModel.errors, | ||
// dinoModel.type)); | ||
// } | ||
// } | ||
return dinoModel; | ||
@@ -94,3 +93,3 @@ }; | ||
this.controller.dino = res.locals.dino; | ||
this.controller.model = new dino_model_1.DinoModel(); | ||
this.controller.model = new entities_1.DinoModel(); | ||
// typically when action is decorated with @SendsResponse | ||
@@ -124,3 +123,3 @@ // and if any error occurred inside the callback processing handler, | ||
// gets request-body injected | ||
if (http_utility_1.HttpUtility.hasBody(httpVerb)) | ||
if (utility_1.HttpUtility.hasBody(httpVerb)) | ||
values[0] = ctx.request.body; | ||
@@ -146,3 +145,3 @@ var result = values.length > 0 ? ctx[actionName].apply(ctx, values) : ctx[actionName](); | ||
// gets request-body injected | ||
if (http_utility_1.HttpUtility.hasBody(httpVerb)) | ||
if (utility_1.HttpUtility.hasBody(httpVerb)) | ||
values[0] = ctx.request.body; | ||
@@ -149,0 +148,0 @@ if (!(values.length > 0)) return [3 /*break*/, 3]; |
@@ -1,4 +0,4 @@ | ||
import { Request, Response, NextFunction } from '../types/express'; | ||
import { ErrorController } from '../controller/error.controller'; | ||
import { IDinoErrorController } from '../interfaces/idino'; | ||
import { Request, Response, NextFunction } from '../types'; | ||
import { ErrorController } from '../controller'; | ||
import { IDinoErrorController } from '../interfaces'; | ||
export declare class DinoErrorController implements IDinoErrorController { | ||
@@ -5,0 +5,0 @@ private controller; |
@@ -1,2 +0,2 @@ | ||
import { Request, Response, NextFunction } from '../types/express'; | ||
import { Request, Response, NextFunction } from '../types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Extend this class to create ErrorMiddleware |
@@ -1,3 +0,2 @@ | ||
import { IRouterCallBack, IMiddlewareProvider } from '../types/attribute'; | ||
import { Express, Request, Response, NextFunction } from '../types/express'; | ||
import { IRouterCallBack, IMiddlewareProvider, Express, Request, Response, NextFunction } from '../types'; | ||
export interface IDino { | ||
@@ -21,4 +20,3 @@ registerController<T>(controller: Function & { | ||
}): void; | ||
raiseModelError(): void; | ||
dependencyInjectionResolver<T>(injector: T, cb: (injector: T, type: any) => any): void; | ||
dependencyResolver<T>(injector: T, cb: (injector: T, type: any) => any): void; | ||
bind(): void; | ||
@@ -25,0 +23,0 @@ useRouter(cb: () => any): void; |
@@ -1,2 +0,2 @@ | ||
import { IControllerAttribute, IBindModelAttribute } from '../types/attribute'; | ||
import { IControllerAttribute, IBindModelAttribute } from '../types'; | ||
export declare abstract class AttributeMetadata { | ||
@@ -3,0 +3,0 @@ private static defineHttpVerbMetadata(route, verb, target, property); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var reflector_1 = require("../lib/reflector"); | ||
var constants_1 = require("../constants/constants"); | ||
var data_utility_1 = require("../utility/data.utility"); | ||
var exceptions_1 = require("../builtin/exceptions/exceptions"); | ||
var lib_1 = require("../lib"); | ||
var constants_1 = require("../constants"); | ||
var utility_1 = require("../utility"); | ||
var exceptions_1 = require("../builtin/exceptions"); | ||
var AttributeMetadata = (function () { | ||
@@ -11,10 +11,10 @@ function AttributeMetadata() { | ||
AttributeMetadata.defineHttpVerbMetadata = function (route, verb, target, property) { | ||
if (data_utility_1.DataUtility.isUndefinedOrNull(route)) { | ||
if (utility_1.DataUtility.isUndefinedOrNull(route)) { | ||
throw new exceptions_1.InvalidRouteException(route, verb, property, target.constructor.name); | ||
} | ||
reflector_1.Reflector.defineMetadata(verb, route, target.constructor.prototype, property); | ||
lib_1.Reflector.defineMetadata(verb, route, target.constructor.prototype, property); | ||
}; | ||
AttributeMetadata.sendsResponse = function () { | ||
return function (target, propertyKey) { | ||
reflector_1.Reflector.defineMetadata(constants_1.Attribute.sendsResponse, 'sendsResponse', target.constructor.prototype, propertyKey); | ||
lib_1.Reflector.defineMetadata(constants_1.Attribute.sendsResponse, 'sendsResponse', target.constructor.prototype, propertyKey); | ||
}; | ||
@@ -24,3 +24,3 @@ }; | ||
return function (target, propertyKey) { | ||
reflector_1.Reflector.defineMetadata(constants_1.Attribute.asyncAttr, 'asyncAttr', target.constructor.prototype, propertyKey); | ||
lib_1.Reflector.defineMetadata(constants_1.Attribute.asyncAttr, 'asyncAttr', target.constructor.prototype, propertyKey); | ||
}; | ||
@@ -30,3 +30,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpGet, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpGet, target, propertyKey); | ||
}; | ||
@@ -36,3 +37,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpPost, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpPost, target, propertyKey); | ||
}; | ||
@@ -42,3 +44,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpDelete, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpDelete, target, propertyKey); | ||
}; | ||
@@ -48,3 +51,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpPatch, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpPatch, target, propertyKey); | ||
}; | ||
@@ -54,3 +58,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpPut, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpPut, target, propertyKey); | ||
}; | ||
@@ -60,3 +65,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpHead, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpHead, target, propertyKey); | ||
}; | ||
@@ -66,3 +72,4 @@ }; | ||
return function (target, propertyKey) { | ||
AttributeMetadata.defineHttpVerbMetadata(route, constants_1.Attribute.httpAll, target, propertyKey); | ||
AttributeMetadata | ||
.defineHttpVerbMetadata(route, constants_1.Attribute.httpAll, target, propertyKey); | ||
}; | ||
@@ -73,4 +80,4 @@ }; | ||
return function (target, propertyKey) { | ||
var attrs = data_utility_1.DataUtility.isUndefinedOrNull(attr) ? {} : attr; | ||
if (data_utility_1.DataUtility.isUndefinedOrNull(prefix)) { | ||
var attrs = utility_1.DataUtility.isUndefinedOrNull(attr) ? {} : attr; | ||
if (utility_1.DataUtility.isUndefinedOrNull(prefix)) { | ||
throw new exceptions_1.InvalidRouteException(prefix, undefined, undefined, target.constructor.name); | ||
@@ -80,9 +87,9 @@ } | ||
prefix: prefix, | ||
middlewares: data_utility_1.DataUtility.isUndefinedOrNull(attrs.middlewares) ? [] : attrs.middlewares, | ||
filters: data_utility_1.DataUtility.isUndefinedOrNull(attrs.filters) ? [] : attrs.filters, | ||
exceptions: data_utility_1.DataUtility.isUndefinedOrNull(attrs.exceptions) ? [] : attrs.exceptions, | ||
result: data_utility_1.DataUtility.isUndefinedOrNull(attrs.result) ? [] : attrs.result, | ||
use: data_utility_1.DataUtility.isUndefinedOrNull(attrs.use) ? [] : attrs.use | ||
middlewares: utility_1.DataUtility.isUndefinedOrNull(attrs.middlewares) ? [] : attrs.middlewares, | ||
filters: utility_1.DataUtility.isUndefinedOrNull(attrs.filters) ? [] : attrs.filters, | ||
exceptions: utility_1.DataUtility.isUndefinedOrNull(attrs.exceptions) ? [] : attrs.exceptions, | ||
result: utility_1.DataUtility.isUndefinedOrNull(attrs.result) ? [] : attrs.result, | ||
use: utility_1.DataUtility.isUndefinedOrNull(attrs.use) ? [] : attrs.use | ||
}; | ||
reflector_1.Reflector.defineMetadata(constants_1.Attribute.controller, val, target.prototype); | ||
lib_1.Reflector.defineMetadata(constants_1.Attribute.controller, val, target.prototype); | ||
}; | ||
@@ -92,3 +99,3 @@ }; | ||
return function (target, propertyKey) { | ||
if (data_utility_1.DataUtility.isUndefinedOrNull(type)) { | ||
if (utility_1.DataUtility.isUndefinedOrNull(type)) { | ||
throw new exceptions_1.InvalidArgumentException(type, "bindModel(" + type + ") is not valid"); | ||
@@ -100,4 +107,4 @@ } | ||
// However we are initializing stopOnError to false because we dont have global flag for this. | ||
var opts = data_utility_1.DataUtility.isUndefinedOrNull(options) ? {} : options; | ||
var stop = data_utility_1.DataUtility.isUndefinedOrNull(opts.stopOnError) ? false : opts.stopOnError; | ||
var opts = utility_1.DataUtility.isUndefinedOrNull(options) ? {} : options; | ||
var stop = utility_1.DataUtility.isUndefinedOrNull(opts.stopOnError) ? false : opts.stopOnError; | ||
var val = { | ||
@@ -110,3 +117,3 @@ model: type, | ||
}; | ||
reflector_1.Reflector.defineMetadata(constants_1.Attribute.bindModel, val, target.constructor.prototype, propertyKey); | ||
lib_1.Reflector.defineMetadata(constants_1.Attribute.bindModel, val, target.constructor.prototype, propertyKey); | ||
}; | ||
@@ -113,0 +120,0 @@ }; |
@@ -1,5 +0,3 @@ | ||
import { Router, Express } from '../types/express'; | ||
import { IMiddlewareProvider } from '../types/attribute'; | ||
import { IDinoRouter } from '../interfaces/idino'; | ||
import { IRouterConfig, IDinoProperties } from '../types/dino.types'; | ||
import { Router, Express, IRouterConfig, IDinoProperties, IMiddlewareProvider } from '../types'; | ||
import { IDinoRouter } from '../interfaces'; | ||
export declare class DinoRouter implements IDinoRouter { | ||
@@ -6,0 +4,0 @@ private router; |
@@ -38,6 +38,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dino_utility_1 = require("../utility/dino.utility"); | ||
var object_utility_1 = require("../utility/object.utility"); | ||
var dino_parser_1 = require("../utility/dino.parser"); | ||
var providers_1 = require("../providers/providers"); | ||
var utility_1 = require("../utility"); | ||
var providers_1 = require("../providers"); | ||
// Each controller gets an instance of router | ||
@@ -57,3 +55,3 @@ // Register middlewares on the router level | ||
return this.enableTaskContext ? | ||
object_utility_1.ObjectUtility.replaceObjectReferences(o, dino.context, providers_1.IUserIdentity) : o; | ||
utility_1.ObjectUtility.replaceObjectReferences(o, dino.context, providers_1.IUserIdentity) : o; | ||
}; | ||
@@ -63,4 +61,4 @@ // made public for unit test and not available on interface contract | ||
var _this = this; | ||
var provider = dino_parser_1.DinoParser.parseMiddlewareProvider(middleware); | ||
if (dino_utility_1.DinoUtility.isSyncMiddleWare(provider.useClass)) { | ||
var provider = utility_1.DinoParser.parseMiddlewareProvider(middleware); | ||
if (utility_1.DinoUtility.isSyncMiddleWare(provider.useClass)) { | ||
this.router.use(function (req, res, next) { | ||
@@ -71,3 +69,3 @@ var mware = _this.resolve(provider.useClass, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncMiddleWare(provider.useClass)) { | ||
else if (utility_1.DinoUtility.isAsyncMiddleWare(provider.useClass)) { | ||
this.router.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -99,4 +97,4 @@ var mware, err_1; | ||
var _this = this; | ||
var provider = dino_parser_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (dino_utility_1.DinoUtility.isSyncActionFilter(provider.useClass)) { | ||
var provider = utility_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (utility_1.DinoUtility.isSyncActionFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { | ||
@@ -107,3 +105,3 @@ var mware = _this.resolve(provider.useClass, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncActionFilter(provider.useClass)) { | ||
else if (utility_1.DinoUtility.isAsyncActionFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -135,4 +133,4 @@ var mware, err_2; | ||
var _this = this; | ||
var provider = dino_parser_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (dino_utility_1.DinoUtility.isSyncActionFilter(provider.useClass)) { | ||
var provider = utility_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (utility_1.DinoUtility.isSyncActionFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { | ||
@@ -143,3 +141,3 @@ var mware = _this.resolve(provider.useClass, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncActionFilter(provider.useClass)) { | ||
else if (utility_1.DinoUtility.isAsyncActionFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -171,4 +169,4 @@ var mware, err_3; | ||
var _this = this; | ||
var provider = dino_parser_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (dino_utility_1.DinoUtility.isSyncResultFilter(provider.useClass)) { | ||
var provider = utility_1.DinoParser.parseMiddlewareProvider(filter); | ||
if (utility_1.DinoUtility.isSyncResultFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { | ||
@@ -179,3 +177,3 @@ var mware = _this.resolve(provider.useClass, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncResultFilter(provider.useClass)) { | ||
else if (utility_1.DinoUtility.isAsyncResultFilter(provider.useClass)) { | ||
this.router.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -207,4 +205,4 @@ var mware, err_4; | ||
var _this = this; | ||
var provider = dino_parser_1.DinoParser.parseMiddlewareProvider(middleware); | ||
if (dino_utility_1.DinoUtility.isSyncExceptionFilter(provider.useClass)) { | ||
var provider = utility_1.DinoParser.parseMiddlewareProvider(middleware); | ||
if (utility_1.DinoUtility.isSyncExceptionFilter(provider.useClass)) { | ||
app.use(uri, function (err, req, res, next) { | ||
@@ -215,3 +213,3 @@ var mware = _this.resolve(provider.useClass, res.locals.dino); | ||
} | ||
else if (dino_utility_1.DinoUtility.isAsyncExceptionFilter(provider.useClass)) { | ||
else if (utility_1.DinoUtility.isAsyncExceptionFilter(provider.useClass)) { | ||
app.use(uri, function (err, req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -218,0 +216,0 @@ var mware, err_5; |
@@ -1,2 +0,2 @@ | ||
import { IRouteTable } from '../interfaces/idino'; | ||
import { IRouteTable } from '../interfaces'; | ||
export declare class RouteTable implements IRouteTable { | ||
@@ -3,0 +3,0 @@ private routes; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("../constants/constants"); | ||
var constants_1 = require("../constants"); | ||
// RouteTable has the list of routes registered with dino | ||
@@ -5,0 +5,0 @@ // but these routes are only registered only after invoking .bind() on dino instance. |
import { IRouterCallBack } from './attribute'; | ||
import { IDIContainer } from '../interfaces/idino'; | ||
import { IDIContainer } from '../interfaces'; | ||
import { Express } from './express'; | ||
@@ -4,0 +4,0 @@ export interface IDinoProperties { |
"use strict"; | ||
/**** Comment these exports while publishing to NPM ****/ | ||
// tslint:disable-next-line:no-implicit-dependencies | ||
// import { Express, Router, Request, Response, NextFunction } from 'express'; | ||
@@ -4,0 +5,0 @@ // export type Express = Express; |
@@ -1,2 +0,2 @@ | ||
import { IMiddlewareProvider, IMiddlewareClass } from '../types/attribute'; | ||
import { IMiddlewareProvider, IMiddlewareClass } from '../types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * ParserUtility functions to parse dino objects |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var filter_1 = require("../filter/filter"); | ||
var error_controller_1 = require("../controller/error.controller"); | ||
var filter_1 = require("../filter"); | ||
var controller_1 = require("../controller"); | ||
var object_utility_1 = require("./object.utility"); | ||
var api_controller_1 = require("../controller/api.controller"); | ||
/** | ||
@@ -66,6 +65,6 @@ * Wrapper methods to test the datatype of the components registered with Dino instance | ||
DinoUtility.isErrorController = function (type) { | ||
return object_utility_1.ObjectUtility.create(type.prototype) instanceof error_controller_1.ErrorController; | ||
return object_utility_1.ObjectUtility.create(type.prototype) instanceof controller_1.ErrorController; | ||
}; | ||
DinoUtility.isApiController = function (type) { | ||
return object_utility_1.ObjectUtility.create(type.prototype) instanceof api_controller_1.ApiController; | ||
return object_utility_1.ObjectUtility.create(type.prototype) instanceof controller_1.ApiController; | ||
}; | ||
@@ -72,0 +71,0 @@ return DinoUtility; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("../constants/constants"); | ||
var constants_1 = require("../constants"); | ||
var HttpUtility = (function () { | ||
@@ -5,0 +5,0 @@ function HttpUtility() { |
@@ -8,8 +8,14 @@ "use strict"; | ||
// tslint:disable-next-line:no-require-imports | ||
var UrlParser = require("url-pattern"); | ||
// import UrlParser = require('url-pattern'); | ||
// Refer: https://github.com/pillarjs/path-to-regexp | ||
// tslint:disable-next-line:no-require-imports | ||
var pathToRegexp = require("path-to-regexp"); | ||
var function_utility_1 = require("./function.utility"); | ||
var object_utility_1 = require("./object.utility"); | ||
var data_utility_1 = require("./data.utility"); | ||
var RouteUtility = (function () { | ||
function RouteUtility() { | ||
} | ||
// @returns {} when no segmented values are matched | ||
// @returns { key1: value1, key2: value2 } for the matched segments values | ||
// parses the named segment values in the url | ||
@@ -23,5 +29,17 @@ RouteUtility.getNamedSegmentKeyValues = function ( | ||
requestedUrl) { | ||
var route = new UrlParser(originalUri); | ||
var values = route.match(requestedUrl); | ||
return values; | ||
var keys = []; | ||
var route = pathToRegexp(originalUri, keys); | ||
var values = route.exec(requestedUrl); | ||
if (!data_utility_1.DataUtility.isArray(values)) { | ||
return {}; | ||
} | ||
// matched values start from index: 1 | ||
var i = 1; | ||
var obj = {}; | ||
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { | ||
var key = keys_1[_i]; | ||
obj[key.name] = values[i]; | ||
i++; | ||
} | ||
return obj; | ||
}; | ||
@@ -37,3 +55,3 @@ // map the segmented values and query strings to action arguments | ||
var val = RouteUtility.getNamedSegmentKeyValues(originalUri, requestedUri); | ||
if (val) { | ||
if (!data_utility_1.DataUtility.isUndefinedOrNull(val)) { | ||
var values_1 = Object.assign(queryString, val); | ||
@@ -40,0 +58,0 @@ // map the action argument and its value from url |
{ | ||
"name": "dinoloop", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "open-source nodejs framework, completely written in typescript project designed to build REST APIs", | ||
@@ -23,12 +23,10 @@ "main": "index.js", | ||
"express", | ||
"expressjs", | ||
"framework", | ||
"web", | ||
"rest", | ||
"restful", | ||
"typescript" | ||
"restful" | ||
], | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.12", | ||
"url-pattern": "^1.0.3" | ||
"path-to-regexp": "^2.2.1" | ||
}, | ||
@@ -35,0 +33,0 @@ "engines": { |
@@ -26,2 +26,4 @@ [![npm version](https://img.shields.io/npm/v/dinoloop.svg)](https://www.npmjs.com/package/dinoloop) | ||
Without Dependency Injection framework | ||
``` | ||
@@ -33,2 +35,11 @@ git clone https://github.com/ParallelTask/dinoloop-starter.git | ||
``` | ||
With Dependency Injection framework | ||
``` | ||
git clone https://github.com/ParallelTask/dinoloop-inversify-starter.git | ||
cd dinoloop-inversify-starter | ||
npm install | ||
npm start | ||
``` | ||
Navigate to [http:localhost:8088/api/home/get](http:localhost:8088/api/home/get) in browser | ||
@@ -38,6 +49,9 @@ | ||
* Super easy set-up. | ||
* Isolation of controllers and services. | ||
* Supports express middlewares, completely express compatible. | ||
* Zero configuration to switch from express to dinoloop. | ||
* Heavily influenced by MVC pattern. | ||
* Proper isolation of controllers and services. | ||
* Dependency injection support. | ||
* Middlewares, ActionFilters, ExceptionFilters, ResultFilters at controller level. | ||
* Robust Sync/Async middlewares to handle async-await pattern. | ||
* Robust Sync/Async middlewares to handle es6 async-await pattern. | ||
* UserIdentity principal across request. | ||
@@ -53,2 +67,5 @@ | ||
## Motivation | ||
Typescript (*Javascript now*) supports object oriented programming, these features are great with SOLID design principles. Dinoloop is a tool that helps node developers to write Restful APIs with SOLID principles similar to JAVA and C# coding skills. | ||
## Community | ||
@@ -55,0 +72,0 @@ Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our [CONTRIBUTING.md](https://github.com/ParallelTask/dinoloop/blob/master/CONTRIBUTING.md) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
140335
120
3187
1
74
+ Addedpath-to-regexp@^2.2.1
+ Addedpath-to-regexp@2.4.0(transitive)
- Removedurl-pattern@^1.0.3
- Removedurl-pattern@1.0.3(transitive)