How to use the cls-hooked.getNamespace function in cls-hooked

To help you get started, we’ve selected a few cls-hooked examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages-api / webiny-api / src / auth / auth.js View on Github external
return new Promise(resolve => {
            const session = getNamespace('webiny-api');
            const req = session.get('req');
            const token = req.get('Webiny-Authorization');

            if (!token) {
                resolve(null);
            }

            jwt.verify(token, this.config.jwtSecret, (err, decoded) => {
                if (err) {
                    // TODO: check if token is expired
                    resolve(null);
                } else {
                    this.config.entity.findById(decoded.id).then(user => {
                        this.user = user;
                        resolve(user);
                    }).catch(e => {
github BMalaichik / nestjs-starter-kit / packages / backend / src / modules / shared / cls / index.ts View on Github external
export function getNamespace() {
    return getClsNamespace(APP_CONTINUATION_KEY);
}
github charjac / nest-boilerplate / src / common / context / context.component.ts View on Github external
public get store() {
    return getNamespace(ContextTypes.ROOT);
  }
}
github xmlking / ngx-starter-kit / apps / api / src / app / core / context / request-context.ts View on Github external
static currentRequestContext(): RequestContext {
    const session = cls.getNamespace(RequestContext.name);
    if (session && session.active) {
      return session.get(RequestContext.name);
    }

    return null;
  }
github odavid / typeorm-transactional-cls-hooked / src / hook.ts View on Github external
export const getTransactionalContextHook = () => {
  const ctx = getNamespace(NAMESPACE_NAME)
  const emitter = getHookInContext(ctx)
  if (!emitter) {
    throw new Error('No hook manager found in context. Are you using @Transactional()?')
  }
  return emitter
}
github odavid / typeorm-transactional-cls-hooked / src / Transactional.ts View on Github external
descriptor.value = function(...args: any[]) {
      const context = getNamespace(NAMESPACE_NAME)
      if (!context) {
        throw new Error(
          'No CLS namespace defined in your app ... please call initializeTransactionalContext() before application start.'
        )
      }

      const runOriginal = async () => originalMethod.apply(this, [...args])
      const runWithNewHook = async () => runInNewHookContext(context, runOriginal)

      const runWithNewTransaction = async () => {
        const transactionCallback = async (entityManager: EntityManager) => {
          setEntityManagerForConnection(connectionName, context, entityManager)
          const result = await originalMethod.apply(this, [...args])
          setEntityManagerForConnection(connectionName, context, null)
          return result
        }
github xmlking / ngx-starter-kit / apps / api / src / app / core / context / request-context.middleware.ts View on Github external
use(req, res, next) {
    const requestContext = new RequestContext(req, res);
    const session = cls.getNamespace(RequestContext.name) || cls.createNamespace(RequestContext.name);

    session.run(async () => {
      session.set(RequestContext.name, requestContext);
      next();
    });
  }
}
github odavid / typeorm-transactional-cls-hooked / src / common.ts View on Github external
export const getEntityManagerOrTransactionManager = (
  connectionName: string,
  entityManager: EntityManager | undefined
): EntityManager => {
  const context = getNamespace(NAMESPACE_NAME)

  if (context && context.active) {
    const transactionalEntityManager = getEntityManagerForConnection(connectionName, context)

    if (transactionalEntityManager) {
      return transactionalEntityManager
    }
  }
  return entityManager || getManager(connectionName)
}
github odavid / typeorm-transactional-cls-hooked / src / common.ts View on Github external
export const initializeTransactionalContext = () =>
  getNamespace(NAMESPACE_NAME) || createNamespace(NAMESPACE_NAME)

cls-hooked

CLS using AsynWrap instead of async-listener - Node >= 4.7.0

BSD-2-Clause
Latest version published 7 years ago

Package Health Score

70 / 100
Full package analysis