inversify-express-utils
Advanced tools
Comparing version 4.2.2 to 5.0.0-beta.1
@@ -21,3 +21,4 @@ declare const TYPE: { | ||
} | ||
export declare const DUPLICATED_CONTROLLER_NAME: (name: string) => string; | ||
declare const DEFAULT_ROUTING_ROOT_PATH = "/"; | ||
export { TYPE, METADATA_KEY, DEFAULT_ROUTING_ROOT_PATH }; |
@@ -6,2 +6,3 @@ import { InversifyExpressServer } from "./server"; | ||
import { BaseHttpController } from "./base_http_controller"; | ||
export { interfaces, InversifyExpressServer, controller, httpMethod, httpGet, httpPut, httpPost, httpPatch, httpHead, all, httpDelete, TYPE, request, response, requestParam, queryParam, requestBody, requestHeaders, cookies, next, BaseHttpController, httpContext }; | ||
import { cleanUpMetadata } from "./utils"; | ||
export { cleanUpMetadata, interfaces, InversifyExpressServer, controller, httpMethod, httpGet, httpPut, httpPost, httpPatch, httpHead, all, httpDelete, TYPE, request, response, requestParam, queryParam, requestBody, requestHeaders, cookies, next, BaseHttpController, httpContext }; |
@@ -22,3 +22,4 @@ var TYPE = { | ||
})(PARAMETER_TYPE || (PARAMETER_TYPE = {})); | ||
export var DUPLICATED_CONTROLLER_NAME = function (name) { return "Two controllers cannot have the same name: " + name; }; | ||
var DEFAULT_ROUTING_ROOT_PATH = "/"; | ||
export { TYPE, METADATA_KEY, DEFAULT_ROUTING_ROOT_PATH }; |
@@ -0,3 +1,3 @@ | ||
import { inject, injectable, decorate } from "inversify"; | ||
import { TYPE, METADATA_KEY, PARAMETER_TYPE } from "./constants"; | ||
import { inject } from "inversify"; | ||
export var httpContext = inject(TYPE.HttpContext); | ||
@@ -10,4 +10,18 @@ export function controller(path) { | ||
return function (target) { | ||
var metadata = { path: path, middleware: middleware, target: target }; | ||
Reflect.defineMetadata(METADATA_KEY.controller, metadata, target); | ||
var currentMetadata = { | ||
middleware: middleware, | ||
path: path, | ||
target: target | ||
}; | ||
decorate(injectable(), target); | ||
Reflect.defineMetadata(METADATA_KEY.controller, currentMetadata, target); | ||
// We need to create an array that contains the metadata of all | ||
// the controllers in the application, the metadata cannot be | ||
// attached to a controller. It needs to be attached to a global | ||
// We attach metadata to the Reflect object itself to avoid | ||
// declaring additonal globals. Also, the Reflect is avaiable | ||
// in both node and web browsers. | ||
var previousMetadata = Reflect.getMetadata(METADATA_KEY.controller, Reflect) || []; | ||
var newMetadata = [currentMetadata].concat(previousMetadata); | ||
Reflect.defineMetadata(METADATA_KEY.controller, newMetadata, Reflect); | ||
}; | ||
@@ -14,0 +28,0 @@ } |
@@ -5,2 +5,3 @@ import { InversifyExpressServer } from "./server"; | ||
import { BaseHttpController } from "./base_http_controller"; | ||
export { InversifyExpressServer, controller, httpMethod, httpGet, httpPut, httpPost, httpPatch, httpHead, all, httpDelete, TYPE, request, response, requestParam, queryParam, requestBody, requestHeaders, cookies, next, BaseHttpController, httpContext }; | ||
import { cleanUpMetadata } from "./utils"; | ||
export { cleanUpMetadata, InversifyExpressServer, controller, httpMethod, httpGet, httpPut, httpPost, httpPatch, httpHead, all, httpDelete, TYPE, request, response, requestParam, queryParam, requestBody, requestHeaders, cookies, next, BaseHttpController, httpContext }; |
@@ -37,3 +37,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import * as express from "express"; | ||
import { TYPE, METADATA_KEY, DEFAULT_ROUTING_ROOT_PATH, PARAMETER_TYPE } from "./constants"; | ||
import { TYPE, METADATA_KEY, DEFAULT_ROUTING_ROOT_PATH, PARAMETER_TYPE, DUPLICATED_CONTROLLER_NAME } from "./constants"; | ||
/** | ||
@@ -104,2 +104,12 @@ * Wrapper for the express server. | ||
this._container.bind(TYPE.HttpContext).toConstantValue({}); | ||
var arrayOfControllerMetadata = Reflect.getMetadata(METADATA_KEY.controller, Reflect) || []; | ||
arrayOfControllerMetadata.forEach(function (metadata) { | ||
var constructor = metadata.target; | ||
if (_this._container.isBoundNamed(TYPE.Controller, metadata.target.name)) { | ||
throw new Error(DUPLICATED_CONTROLLER_NAME(metadata.target.name)); | ||
} | ||
_this._container.bind(TYPE.Controller) | ||
.to(constructor) | ||
.whenTargetNamed(metadata.target.name); | ||
}); | ||
var controllers = this._container.getAll(TYPE.Controller); | ||
@@ -106,0 +116,0 @@ controllers.forEach(function (controller) { |
@@ -26,3 +26,4 @@ "use strict"; | ||
})(PARAMETER_TYPE = exports.PARAMETER_TYPE || (exports.PARAMETER_TYPE = {})); | ||
exports.DUPLICATED_CONTROLLER_NAME = function (name) { return "Two controllers cannot have the same name: " + name; }; | ||
var DEFAULT_ROUTING_ROOT_PATH = "/"; | ||
exports.DEFAULT_ROUTING_ROOT_PATH = DEFAULT_ROUTING_ROOT_PATH; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var inversify_1 = require("inversify"); | ||
var constants_1 = require("./constants"); | ||
var inversify_1 = require("inversify"); | ||
exports.httpContext = inversify_1.inject(constants_1.TYPE.HttpContext); | ||
@@ -12,4 +12,18 @@ function controller(path) { | ||
return function (target) { | ||
var metadata = { path: path, middleware: middleware, target: target }; | ||
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, metadata, target); | ||
var currentMetadata = { | ||
middleware: middleware, | ||
path: path, | ||
target: target | ||
}; | ||
inversify_1.decorate(inversify_1.injectable(), target); | ||
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, currentMetadata, target); | ||
// We need to create an array that contains the metadata of all | ||
// the controllers in the application, the metadata cannot be | ||
// attached to a controller. It needs to be attached to a global | ||
// We attach metadata to the Reflect object itself to avoid | ||
// declaring additonal globals. Also, the Reflect is avaiable | ||
// in both node and web browsers. | ||
var previousMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || []; | ||
var newMetadata = [currentMetadata].concat(previousMetadata); | ||
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, newMetadata, Reflect); | ||
}; | ||
@@ -16,0 +30,0 @@ } |
@@ -28,1 +28,3 @@ "use strict"; | ||
exports.BaseHttpController = base_http_controller_1.BaseHttpController; | ||
var utils_1 = require("./utils"); | ||
exports.cleanUpMetadata = utils_1.cleanUpMetadata; |
@@ -105,2 +105,12 @@ "use strict"; | ||
this._container.bind(constants_1.TYPE.HttpContext).toConstantValue({}); | ||
var arrayOfControllerMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || []; | ||
arrayOfControllerMetadata.forEach(function (metadata) { | ||
var constructor = metadata.target; | ||
if (_this._container.isBoundNamed(constants_1.TYPE.Controller, metadata.target.name)) { | ||
throw new Error(constants_1.DUPLICATED_CONTROLLER_NAME(metadata.target.name)); | ||
} | ||
_this._container.bind(constants_1.TYPE.Controller) | ||
.to(constructor) | ||
.whenTargetNamed(metadata.target.name); | ||
}); | ||
var controllers = this._container.getAll(constants_1.TYPE.Controller); | ||
@@ -107,0 +117,0 @@ controllers.forEach(function (controller) { |
{ | ||
"name": "inversify-express-utils", | ||
"version": "4.2.2", | ||
"version": "5.0.0-beta.1", | ||
"description": "Some utilities for the development of express applications with Inversify", | ||
@@ -30,8 +30,8 @@ "main": "lib/index.js", | ||
"@types/body-parser": "1.16.8", | ||
"@types/chai": "4.0.4", | ||
"@types/chai": "4.0.5", | ||
"@types/cookie-parser": "1.4.1", | ||
"@types/express": "4.0.39", | ||
"@types/mocha": "2.2.44", | ||
"@types/sinon": "2.3.7", | ||
"@types/supertest": "2.0.3", | ||
"@types/sinon": "4.0.0", | ||
"@types/supertest": "2.0.4", | ||
"bluebird": "3.5.1", | ||
@@ -46,3 +46,3 @@ "body-parser": "1.18.2", | ||
"gulp-typescript": "3.2.3", | ||
"inversify": "4.5.1", | ||
"inversify": "4.5.2", | ||
"mocha": "4.0.1", | ||
@@ -49,0 +49,0 @@ "publish-please": "2.3.1", |
@@ -41,3 +41,2 @@ # inversify-express-utils | ||
@controller("/foo") | ||
@injectable() | ||
export class FooController implements interfaces.Controller { | ||
@@ -97,4 +96,2 @@ | ||
// note that you *must* bind your controllers to Controller | ||
container.bind<interfaces.Controller>(TYPE.Controller).to(FooController).whenTargetNamed('FooController'); | ||
container.bind<FooService>('FooService').to(FooService); | ||
@@ -260,3 +257,2 @@ | ||
@injectable() | ||
@controller("/") | ||
@@ -286,3 +282,2 @@ class UserPreferencesController extends BaseHttpController { | ||
@injectable() | ||
@controller("/") | ||
@@ -371,3 +366,2 @@ class UserPreferencesController { | ||
```ts | ||
@injectable() | ||
@controller("/") | ||
@@ -381,3 +375,3 @@ class UserDetailsController extends BaseHttpController { | ||
if (this.httpContext.user.isAuthenticated()) { | ||
return this.httpContext.user.details; | ||
return this._authService.getUserDetails(this.httpContext.user.details.id); | ||
} else { | ||
@@ -384,0 +378,0 @@ throw new Error(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71647
26
1118
1
395