
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
routing-controllers-multiparam
Advanced tools
A simple plugin for routing-controller which allows to inject param from multiple sources.
A simple plugin for routing-controller which allows to inject param from multiple sources.
npm install routing-controllers-multiparam --save
(or the short way with NPM v5):
npm i routing-controllers-multiparam
This package is only a simple plugin, so you have to install the routing-controllers
package because it can't work without them.
The usage of this module is very simple. All you need is:
import { JsonController, Post, createExpressServer } from "routing-controllers";
// import the `@MultiParam` decorator and `ParamType` enum from the module
import { MultiParam, ParamType } from "routing-controllers-multiparam";
// declare the controller class using routing-controller decorators
@JsonController()
class SampleController {
@Post("/sample")
multipleObjects(
// use the `@MultiParam` decorator to define the sources of the param to inject
@MultiParam({ allow: {
[ParamType.QueryParam]: "roleQuery",
[ParamType.BodyParam]: "roleBody",
}})
role: string,
) {
return {
role,
};
}
}
// start the server
createExpressServer({ controllers: [SampleController]}).listen(3000);
And that's it! This will lead to inject the first non-undefined value from the list of sources, so when you specify roleBody
param in body but not roleQuery
inside path (query string) it will be injected. It works just like switch-case!
The @MultiParam
decorator has two overloads:
export function MultiParam(options: NamedParamOptions): ParameterDecorator;
export function MultiParam(paramName: string, options: UnamedParamOptions): ParameterDecorator;
NamedParamOptions
- a type of object that property allow
can be a dictionary of allowed types:export type MultiParamDecoratorNamedOptions = {
required?: boolean;
allow: {
[P in ParamType]?: string | string[];
};
};
So the usage is just like in the example:
@MultiParam({ allow: {
[ParamType.QueryParam]: ["role", "roleFromQuery"],
[ParamType.BodyParam]: "roleFromBody",
}})
UnamedParamOptions
- a type of object that property allow
can be ParamType
or array of ParamType
export type MultiParamDecoratorUnnamedOptions = {
required?: boolean;
allow: ParamType | ParamType[];
};
It can be used only with paramName
parameter when you want to get the param from multiple source but which is avaible on the same name:
@MultiParam("api", { allow: [ParamType.QueryParam, ParamType.HeaderParam] })
If you need more examples of usage, go to the sources and check unit tests file - /src/decorators/MultiParam.ts
. If you have questions or new features/ideas, feel free to open an issue on GitHub repository.
0.1.0
@MultiParam
decorator supportFAQs
A simple plugin for routing-controller which allows to inject param from multiple sources.
The npm package routing-controllers-multiparam receives a total of 1 weekly downloads. As such, routing-controllers-multiparam popularity was classified as not popular.
We found that routing-controllers-multiparam demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.