Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nj-request-scope

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nj-request-scope

Performant express request scope dependency injection for NestJS framework

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-18.93%
Maintainers
1
Weekly downloads
 
Created
Source

nj-request-scope

Performant request scope dependency injection for NestJS framework using express server

Description

nj-request-scope library solves NestJs request-scope dependency injection problems:

  • bubbling up the injection chain - NestJS documentation
  • request-scope performance issues - NestJS documentation

This solution is based on the build-in javascript Proxy design pattern. For every request, only the proxy's target object is changed to the new request-scope instance instead of creating all injection chain objects.

Installation

npm install nj-request-scope

nj-request-scope was tested with NestJs 8.x & 9.x

Usage

To use nj-request-scope in NestJS module you have to add import of RequestScopeModule in the module class decorator:

import { RequestScopeModule } from 'nj-request-scope';

@Module({
    imports: [RequestScopeModule],
})

Next, there are two ways of using nj-request-scope.

  1. Inject express request object into class constructor with NJRS_REQUEST token:
import { NJRS_REQUEST } from 'nj-request-scope';
[...]
constructor(@Inject(NJRS_REQUEST) private readonly request: Request) {}
  1. Change class inject scope to request-scope with @RequestScope() decorator:
import { RequestScope } from 'nj-request-scope';

@Injectable()
@RequestScope()
export class RequestScopeService {

Limitations

Proxy handler implements only most common methods:

  • get
  • has
  • set
  • getPrototypeOf
  • getOwnPropertyDescriptor
  • ownKeys

If you need other methods implemented please feel free to contribute. ProxyHandler implementation

Example project

https://github.com/kugacz/nj-request-scope-example

License

nj-request-scope is MIT licensed.

Keywords

FAQs

Package last updated on 06 Apr 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc