Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
routing-controllers-multiparam
Advanced tools
Readme
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 2 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.