New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cls-class-proxy

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cls-class-proxy

A Proxy-based lightweight library to add [Continuation-Local Storage aka (CLS)](https://github.com/jeff-lewis/cls-hooked) to class contructor, method calls, getters and setters

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cls-class-proxy Build Status

A Proxy-based lightweight library to add Continuation-Local Storage aka (CLS) to class contructor, method calls, getters and setters.

Installation

  1. Install libraries

    npm i cls-class-proxy cls-hooked
    
  2. Install typings if you use typescript

    npm i -D @types/cls-hooked
    

Quick start

Decorator-based

  1. Set in your tsconfig.json

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
    
  2. In your code

    import { getNamespace } from 'cls-hooked'
    import { proxify, CLS_CLASS_PROXY_NAMESPACE_NAME } from 'cls-class-proxy'
    
    @proxify()
    class Example {
      constructor() {
        const namespace = getNamespace(CLS_CLASS_PROXY_NAMESPACE_NAME)
        // At this point the namespace has an active contex (namspace.active returns the context)
        // You can set and get data for the context
      }
      method1() {
        const namespace = getNamespace(CLS_CLASS_PROXY_NAMESPACE_NAME)
        // At this point the namespace has an active contex (namspace.active returns the context)
        // You can set and get data for the context
      }
      get prop1() {
        const namespace = getNamespace(CLS_CLASS_PROXY_NAMESPACE_NAME)
        // At this point the namespace has an active contex (namspace.active returns the context)
        // You can set and get data for the context
      }
      set prop2() {
        const namespace = getNamespace(CLS_CLASS_PROXY_NAMESPACE_NAME)
        // At this point the namespace has an active contex (namspace.active returns the context)
        // You can set and get data for the context
      }
    }
    

Non-decorator based

import { getNamespace } from 'cls-hooked'
import { proxify, CLS_CLASS_PROXY_NAMESPACE_NAME } from 'cls-class-proxy'

class Example {}
const ExampleProxified = proxify()(Example)

Options

proxify accepts an optional object with options:

  • namespace: string - custom namespace name to use instead of default CLS_CLASS_PROXY_NAMESPACE_NAME
  • cache: boolean - to wrap method, getter and setter calls in a CLS context cls-class-proxy recursively looks up property descriptors on a target object and its prototype chain. To avoid doing that for every call cls-class-proxy caches property descriptors in a Map. It's enabled by default.

Keywords

FAQs

Package last updated on 09 Feb 2019

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