Notable Pottery Manufacturer
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    mw-clspublic

    mw-cls Build Status

    Advanced CLS (continuation local storage) middleware (for express, restify, ...)

    Namespace middleware

    var session = cls.createNamespaceMiddleware('session');

    .run()

    run the following middleware within the namespace

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run());

    .set(key, val [, forceCreateKeypath=true])

    set the namespace key with a value

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run()); # required
    app.get('/',
      session.set('foo.bar.baz', 'value'),
      ...);

    .asyncSet(key, val [, opts={forceCreateKeypath:true, includeError:false}])

    set the namespace key as the result of an async function

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run()); # required
    app.get('/',
      session.asyncSet('foo.bar.baz', asyncValue),
      ...); // session.get('foo').bar.baz becomes 'value' 
     
    function asyncValue (cb) {
      setTimeout(function () {
        cb(null, 'value');
      }, 100);
    }

    includeError option

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run()); # required
    app.get('/',
      session.asyncSet('foo.bar.baz', asyncValue, { includeError:true }),
      ...); // session.get('foo').bar.baz becomes [null, 'value'] 
     
    function asyncValue (cb) {
      setTimeout(function () {
        cb(null, 'value');
      }, 100);
    }

    .send([code, ]key [, forceReturnKeypath=true])

    // forceReturnKeypath means no errors if keypath DNE

    res.send the value for the namespace key

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run()); # required
    app.get('/',
      session.set('foo.bar.baz', 'value'), // session.get('foo').bar.baz becomes 'value' 
      session.send('foo.bar.baz')); // res.sends 'value', code defaults to 200 

    .json([code, ]key [, forceReturnKeypath=true])

    // forceReturnKeypath means no errors if keypath DNE

    res.json the value for the namespace key

    var cls = require('mw-cls');
    var session = cls.createNamespaceMiddleware('session');
     
    app.use(session.run()); # required
    app.get('/',
      session.set('foo.bar.baz', 'value'), // session.get('foo').bar.baz becomes 'value' 
      session.json('foo.bar')); // res.sends { bar: 'value' }, code defaults to 200 

    TODO methods

    mv, cp, del, unset, setFromReq

    License

    MIT

    install

    npm i mw-cls

    Downloadslast 7 days

    1

    version

    0.3.1

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar