// Dependencies
//const modules = require('./lib/modules');
//const instances = require('./lib/instances');
//const events = require('./lib/events');
const cayley = require('./lib/cayley');
const sequence = require('./lib/sequence');
const utils = require('./lib/utils');

// export API methods
module.exports = {
    connect: cayley.connect,
    get: {
        flow: sequence.flow,
        networks: sequence.networks,
        entrypoints: sequence.entrypoints,
        entrypoint: sequence.entrypoint,
        sequence: sequence.sequence,
        handler: sequence.handler
    },
    set: {},
    del: {},
    utils: utils
    /*vis: {
        modules: {
            get: modules.get,
            details: modules.details
        },
        instances: {
            get: instances.get,
            create: instances.create,
            getOne: instances.getOne,
            details: instances.details
        },
        events: {
            getOne: events.getOne,
            create: events.create,
            details: events.details,
            handler: events.handler,
            handlerDetails: events.handlerDetails
        }
    },*/
};

@@ -193,315 +193,609 @@
 nst 
-sequence = require('./lib/sequence');%0Aconst utils = require('./lib/utils');%0A%0A// export API methods%0Amodule.exports = %7B%0A    connect: cayley.connect,%0A    get: %7B%0A        flow: sequence.flow,%0A        networks: sequence.networks,%0A        entrypoints: sequence.entrypoints,%0A        entrypoint: sequence.entrypoint,
+utils = require('./lib/utils');%0A%0Afunction getHandler (method, params) %7B%0A%0A    if (typeof cayley%5Bmethod%5D !== 'function') %7B%0A        throw new Error('Flow-api.cayley: Method %22' + method + '%22 doesn%5C' exists.');%0A    %7D%0A%0A    return (scope, state, args, data, next) =%3E %7B %0A%0A        let query_args = %5Bstate.g%5D;%0A        for (let i = 0, l = params.length; i %3C l; ++i) %7B%0A%0A            if (typeof data%5Bparams%5Bi%5D%5D === 'undefined') %7B%0A                return next(new Error('Flow-api.get.' + method  + ': Missing parameter %22' + params%5Bi%5D  + '%22.'));%0A            %7D%0A%0A            query_args.push(data%5Bparams%5Bi%5D%5D);%0A        %7D;%0A
 %0A   
@@ -803,228 +803,364 @@
     
-se
 que
-nce: sequence.sequence,%0A        handler: sequence.handler
+ry_args.push(!data.session %7C%7C !data.session.role ? scope.env.role : data.session.role);%0A%0A        data.readable = cayley%5Bmethod%5D.apply(null, query_args);%0A
 %0A    
-%7D,%0A
     
-set: %7B%7D,%0A    del: %7B%7D,%0A    utils: utils%0A    /*vis: %7B%0A        modules: %7B%0A            get: modules.get,%0A            details: modules.details%0A
+try %7B%0A            if (data.readable instanceof Array) %7B%0A                data.readable.forEach(stream =%3E stream.pause());%0A            %7D else %7B%0A                data.readable.pause();%0A  
         
 %7D,%0A 
@@ -1147,34 +1147,35 @@
 se();%0A          
+  
 %7D
-,
 %0A        instanc
@@ -1171,18 +1171,21 @@
     
-instances:
+%7D catch (err)
  %7B%0A 
@@ -1199,277 +1199,471 @@
     
-get: instances.get,%0A            create: instances.create,%0A            getOne: instances.getOne,%0A            details: instances.details%0A        %7D,%0A        events: %7B%0A            getOne: events.getOne,%0A            create: events.create,%0A            details: events.details
+return next(err);%0A        %7D%0A%0A        data.resume = data.readable;%0A        next(null, data);%0A    %7D%0A%7D %0A%0A// export API methods%0Amodule.exports = %7B%0A    connect: cayley.connect,%0A    utils: utils,%0A    flow: getHandler('flow', %5B'id'%5D),%0A    vis: %7B%0A        networks: getHandler('vis_networks', %5B'id'%5D),%0A        entrypoints: getHandler('vis_entrypoints', %5B'id'%5D),%0A        entrypoint: getHandler('vis_entrypoint', %5B'id'%5D),%0A        sequence: getHandler('vis_sequence', %5B'id'%5D)
 ,%0A  
@@ -1664,28 +1664,24 @@
 %5D),%0A        
-    
 handler: eve
@@ -1681,92 +1681,117 @@
 er: 
-events.handler,
+getHandler('vis_handler', %5B'id'%5D)
 %0A    
+%7D,%0A
     
-    handlerDetails: events.handlerDetails%0A        %7D%0A    %7D,*/
+get: getHandler('get', %5B'id', 'type'%5D),%0A    set: %7B%7D,%0A    del: %7B%7D
 %0A%7D;%0A

create handler dynamically