Socket
Socket
Sign inDemoInstall

routing-controllers

Package Overview
Dependencies
19
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.1 to 0.9.0-alpha.1

decorator-options/ControllerOptions.d.ts

1

ActionParameterHandler.js

@@ -245,2 +245,3 @@ "use strict";

if (this.driver.useClassTransformer &&
paramMetadata.actionMetadata.options.transformRequest !== false &&
paramMetadata.targetType &&

@@ -247,0 +248,0 @@ paramMetadata.targetType !== Object &&

4

decorator/Controller.d.ts

@@ -0,1 +1,2 @@

import { ControllerOptions } from "../decorator-options/ControllerOptions";
/**

@@ -7,3 +8,4 @@ * Defines a class as a controller.

* @param baseRoute Extra path you can apply as a base route to all controller actions
* @param options Extra options that apply to all controller actions
*/
export declare function Controller(baseRoute?: string): Function;
export declare function Controller(baseRoute?: string, options?: ControllerOptions): Function;

@@ -10,4 +10,5 @@ "use strict";

* @param baseRoute Extra path you can apply as a base route to all controller actions
* @param options Extra options that apply to all controller actions
*/
function Controller(baseRoute) {
function Controller(baseRoute, options) {
return function (object) {

@@ -17,3 +18,4 @@ index_1.getMetadataArgsStorage().controllers.push({

target: object,
route: baseRoute
route: baseRoute,
options: options
});

@@ -20,0 +22,0 @@ };

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers a controller method to be executed when DELETE request comes on a given route.

*/
export declare function Delete(route?: RegExp): Function;
export declare function Delete(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers a controller method to be executed when DELETE request comes on a given route.

*/
export declare function Delete(route?: string): Function;
export declare function Delete(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Delete(route) {
function Delete(route, options) {
return function (object, methodName) {

@@ -15,3 +15,4 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
route: route
route: route,
options: options
});

@@ -18,0 +19,0 @@ };

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers an action to be executed when GET request comes on a given route.

*/
export declare function Get(route?: RegExp): Function;
export declare function Get(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers an action to be executed when GET request comes on a given route.

*/
export declare function Get(route?: string): Function;
export declare function Get(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Get(route) {
function Get(route, options) {
return function (object, methodName) {

@@ -15,2 +15,3 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
options: options,
route: route

@@ -17,0 +18,0 @@ });

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers an action to be executed when HEAD request comes on a given route.

*/
export declare function Head(route?: RegExp): Function;
export declare function Head(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers an action to be executed when HEAD request comes on a given route.

*/
export declare function Head(route?: string): Function;
export declare function Head(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Head(route) {
function Head(route, options) {
return function (object, methodName) {

@@ -15,2 +15,3 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
options: options,
route: route

@@ -17,0 +18,0 @@ });

@@ -0,1 +1,2 @@

import { ControllerOptions } from "../decorator-options/ControllerOptions";
/**

@@ -6,3 +7,4 @@ * Defines a class as a JSON controller. If JSON controller is used, then all controller actions will return

* @param baseRoute Extra path you can apply as a base route to all controller actions
* @param options Extra options that apply to all controller actions
*/
export declare function JsonController(baseRoute?: string): (object: Function) => void;
export declare function JsonController(baseRoute?: string, options?: ControllerOptions): (object: Function) => void;

@@ -9,4 +9,5 @@ "use strict";

* @param baseRoute Extra path you can apply as a base route to all controller actions
* @param options Extra options that apply to all controller actions
*/
function JsonController(baseRoute) {
function JsonController(baseRoute, options) {
return function (object) {

@@ -16,3 +17,4 @@ index_1.getMetadataArgsStorage().controllers.push({

target: object,
route: baseRoute
route: baseRoute,
options: options
});

@@ -19,0 +21,0 @@ };

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
import { ActionType } from "../metadata/types/ActionType";

@@ -6,3 +7,3 @@ /**

*/
export declare function Method(method: ActionType, route?: RegExp): Function;
export declare function Method(method: ActionType, route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -12,2 +13,2 @@ * Registers an action to be executed when request with specified method comes on a given route.

*/
export declare function Method(method: ActionType, route?: string): Function;
export declare function Method(method: ActionType, route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Method(method, route) {
function Method(method, route, options) {
return function (object, methodName) {

@@ -15,2 +15,3 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
options: options,
route: route

@@ -17,0 +18,0 @@ });

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers an action to be executed when PATCH request comes on a given route.

*/
export declare function Patch(route?: RegExp): Function;
export declare function Patch(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers an action to be executed when PATCH request comes on a given route.

*/
export declare function Patch(route?: string): Function;
export declare function Patch(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Patch(route) {
function Patch(route, options) {
return function (object, methodName) {

@@ -15,3 +15,4 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
route: route
route: route,
options: options
});

@@ -18,0 +19,0 @@ };

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers an action to be executed when POST request comes on a given route.

*/
export declare function Post(route?: RegExp): Function;
export declare function Post(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers an action to be executed when POST request comes on a given route.

*/
export declare function Post(route?: string): Function;
export declare function Post(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Post(route) {
function Post(route, options) {
return function (object, methodName) {

@@ -15,2 +15,3 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
options: options,
route: route

@@ -17,0 +18,0 @@ });

@@ -0,1 +1,2 @@

import { HandlerOptions } from "../decorator-options/HandlerOptions";
/**

@@ -5,3 +6,3 @@ * Registers an action to be executed when PUT request comes on a given route.

*/
export declare function Put(route?: RegExp): Function;
export declare function Put(route?: RegExp, options?: HandlerOptions): Function;
/**

@@ -11,2 +12,2 @@ * Registers an action to be executed when POST request comes on a given route.

*/
export declare function Put(route?: string): Function;
export declare function Put(route?: string, options?: HandlerOptions): Function;

@@ -8,3 +8,3 @@ "use strict";

*/
function Put(route) {
function Put(route, options) {
return function (object, methodName) {

@@ -15,3 +15,4 @@ index_1.getMetadataArgsStorage().actions.push({

method: methodName,
route: route
route: route,
options: options
});

@@ -18,0 +19,0 @@ };

@@ -24,3 +24,4 @@ "use strict";

// check if we need to transform result
var shouldTransform = (this.useClassTransformer && result != null) // transform only if enabled and value exist
var shouldTransform = this.useClassTransformer // transform only if class-transformer is enabled
&& action.options.transformResponse !== false // don't transform if action response transform is disabled
&& result instanceof Object // don't transform primitive types (string/number/boolean)

@@ -27,0 +28,0 @@ && !(result instanceof Uint8Array // don't transform binary data

@@ -174,3 +174,3 @@ "use strict";

// The following line skips action processing when the request method does not match the action method.
if (request.method.toLowerCase() !== actionMetadata.type)
if (actionMetadata.type !== "all" && request.method.toLowerCase() !== actionMetadata.type)
return next();

@@ -177,0 +177,0 @@ return executeCallback({ request: request, response: response, next: next });

@@ -292,8 +292,3 @@ "use strict";

else { // send regular result
if (result instanceof Object) {
options.response.body = result;
}
else {
options.response.body = result;
}
options.response.body = result;
}

@@ -362,27 +357,23 @@ // set http status code

if (use.middleware.prototype && use.middleware.prototype.use) { // if this is function instance of MiddlewareInterface
middlewareFunctions.push(function (context, next) {
try {
var useResult = container_1.getFromContainer(use.middleware, { context: context }).use(context, next);
if (isPromiseLike_1.isPromiseLike(useResult)) {
useResult.catch(function (error) {
_this.handleError(error, undefined, {
request: context.req,
response: context.res,
context: context,
next: next
});
return error;
});
middlewareFunctions.push(function (context, next) { return __awaiter(_this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 4]);
return [4 /*yield*/, container_1.getFromContainer(use.middleware).use(context, next)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
error_1 = _a.sent();
return [4 /*yield*/, this.handleError(error_1, undefined, {
request: context.request,
response: context.response,
context: context,
next: next
})];
case 3: return [2 /*return*/, _a.sent()];
case 4: return [2 /*return*/];
}
return useResult;
}
catch (error) {
_this.handleError(error, undefined, {
request: context.request,
response: context.response,
context: context,
next: next
});
}
});
});
}); });
}

@@ -389,0 +380,0 @@ else {

@@ -6,2 +6,3 @@ import { CustomParameterDecorator } from "./CustomParameterDecorator";

export * from "./container";
export * from "./decorator/All";
export * from "./decorator/Authorized";

@@ -8,0 +9,0 @@ export * from "./decorator/Body";

@@ -15,2 +15,3 @@ "use strict";

__export(require("./container"));
__export(require("./decorator/All"));
__export(require("./decorator/Authorized"));

@@ -17,0 +18,0 @@ __export(require("./decorator/Body"));

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -54,7 +65,3 @@ var ActionMetadata_1 = require("../metadata/ActionMetadata");

var interceptors = !classes ? index_1.getMetadataArgsStorage().interceptors : index_1.getMetadataArgsStorage().filterInterceptorMetadatasForClasses(classes);
return interceptors.map(function (interceptorArgs) { return new InterceptorMetadata_1.InterceptorMetadata({
target: interceptorArgs.target,
method: undefined,
interceptor: interceptorArgs.target
}); });
return interceptors.map(function (interceptorArgs) { return new InterceptorMetadata_1.InterceptorMetadata(__assign(__assign({}, interceptorArgs), { interceptor: interceptorArgs.target })); });
};

@@ -70,2 +77,3 @@ /**

controller.build(_this.createControllerResponseHandlers(controller));
controller.options = controllerArgs.options;
controller.actions = _this.createActions(controller);

@@ -82,6 +90,18 @@ controller.uses = _this.createControllerUses(controller);

var _this = this;
return index_1.getMetadataArgsStorage()
.filterActionsWithTarget(controller.target)
var target = controller.target;
var actionsWithTarget = [];
while (target) {
actionsWithTarget.push.apply(actionsWithTarget, index_1.getMetadataArgsStorage()
.filterActionsWithTarget(target)
.filter(function (action) {
return actionsWithTarget
.map(function (a) { return a.method; })
.indexOf(action.method) === -1;
}));
target = Object.getPrototypeOf(target);
}
return actionsWithTarget
.map(function (actionArgs) {
var action = new ActionMetadata_1.ActionMetadata(controller, actionArgs, _this.options);
action.options = __assign(__assign({}, controller.options), actionArgs.options);
action.params = _this.createParams(action);

@@ -88,0 +108,0 @@ action.uses = _this.createActionUses(action);

@@ -9,2 +9,3 @@ import { Action } from "../Action";

import { ResponseHandlerMetadata } from "./ResponseHandleMetadata";
import { HandlerOptions } from "../decorator-options/HandlerOptions";
import { RoutingControllersOptions } from "../RoutingControllersOptions";

@@ -16,3 +17,3 @@ import { UseMetadata } from "./UseMetadata";

export declare class ActionMetadata {
private options;
private globalOptions;
/**

@@ -43,2 +44,6 @@ * Action's controller.

/**
* Action-specific options.
*/
options: HandlerOptions;
/**
* Action type represents http method used for the registered route. Can be one of the value defined in ActionTypes

@@ -122,3 +127,3 @@ * class.

methodOverride?: (actionMetadata: ActionMetadata, action: Action, params: any[]) => Promise<any> | any;
constructor(controllerMetadata: ControllerMetadata, args: ActionMetadataArgs, options: RoutingControllersOptions);
constructor(controllerMetadata: ControllerMetadata, args: ActionMetadataArgs, globalOptions: RoutingControllersOptions);
/**

@@ -125,0 +130,0 @@ * Builds everything action metadata needs.

@@ -10,4 +10,4 @@ "use strict";

// -------------------------------------------------------------------------
function ActionMetadata(controllerMetadata, args, options) {
this.options = options;
function ActionMetadata(controllerMetadata, args, globalOptions) {
this.globalOptions = globalOptions;
this.controllerMetadata = controllerMetadata;

@@ -17,2 +17,3 @@ this.route = args.route;

this.method = args.method;
this.options = args.options;
this.type = args.type;

@@ -43,6 +44,6 @@ this.appendParams = args.appendParams;

? undefinedResultHandler.value
: this.options.defaults && this.options.defaults.undefinedResultCode;
: this.globalOptions.defaults && this.globalOptions.defaults.undefinedResultCode;
this.nullResultCode = nullResultHandler
? nullResultHandler.value
: this.options.defaults && this.options.defaults.nullResultCode;
: this.globalOptions.defaults && this.globalOptions.defaults.nullResultCode;
if (successCodeHandler)

@@ -49,0 +50,0 @@ this.successHttpCode = successCodeHandler.value;

import { ActionType } from "../types/ActionType";
import { Action } from "../../Action";
import { ActionMetadata } from "../ActionMetadata";
import { HandlerOptions } from "../../decorator-options/HandlerOptions";
/**

@@ -21,2 +22,6 @@ * Action metadata used to storage information about registered action.

/**
* Action-specific options.
*/
options: HandlerOptions;
/**
* Action type represents http method used for the registered route. Can be one of the value defined in ActionTypes

@@ -23,0 +28,0 @@ * class.

@@ -0,1 +1,2 @@

import { ControllerOptions } from "../../decorator-options/ControllerOptions";
/**

@@ -17,2 +18,6 @@ * Controller metadata used to storage information about registered controller.

type: "default" | "json";
/**
* Options that apply to all controller actions.
*/
options: ControllerOptions;
}
import { ActionMetadata } from "./ActionMetadata";
import { ControllerMetadataArgs } from "./args/ControllerMetadataArgs";
import { UseMetadata } from "./UseMetadata";
import { ControllerOptions } from "../decorator-options/ControllerOptions";
import { ResponseHandlerMetadata } from "./ResponseHandleMetadata";

@@ -28,2 +29,6 @@ import { InterceptorMetadata } from "./InterceptorMetadata";

/**
* Options that apply to all controller actions.
*/
options: ControllerOptions;
/**
* Middleware "use"-s applied to a whole controller.

@@ -30,0 +35,0 @@ */

@@ -15,2 +15,3 @@ "use strict";

this.type = args.type;
this.options = args.options;
}

@@ -17,0 +18,0 @@ // -------------------------------------------------------------------------

/**
* Controller action type.
*/
export declare type ActionType = "checkout" | "connect" | "copy" | "delete" | "get" | "head" | "lock" | "merge" | "mkactivity" | "mkcol" | "move" | "m-search" | "notify" | "options" | "patch" | "post" | "propfind" | "proppatch" | "purge" | "put" | "report" | "search" | "subscribe" | "trace" | "unlock" | "unsubscribe";
export declare type ActionType = "all" | "checkout" | "connect" | "copy" | "delete" | "get" | "head" | "lock" | "merge" | "mkactivity" | "mkcol" | "move" | "m-search" | "notify" | "options" | "patch" | "post" | "propfind" | "proppatch" | "purge" | "put" | "report" | "search" | "subscribe" | "trace" | "unlock" | "unsubscribe";
{
"name": "routing-controllers",
"private": false,
"version": "0.8.1",
"version": "0.9.0-alpha.1",
"description": "Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage for Express / Koa using TypeScript.",

@@ -6,0 +6,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with âšĄïž by Socket Inc