Skip to content

Commit

Permalink
export clientlinker.util
Browse files Browse the repository at this point in the history
  • Loading branch information
Bacra committed Jul 7, 2019
1 parent eb6a6b2 commit 18ae750
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
59 changes: 4 additions & 55 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
'use strict';

var _ = require('lodash');
var Linker = require('./lib/linker').Linker;
var debug = require('debug')('clientlinker');
var deprecate = require('depd')('clientlinker');


/**
* [options]
* flows
* httpproxy
* clients
* defaults
*/
exports = module.exports = clientlinker;
function clientlinker(options)
{
options || (options = {});
var defaults = options.defaults || options.clientDefaultOptions || (options.defaults = {});
!defaults.flows && options.flows && (defaults.flows = options.flows.slice());

var linker = new Linker(options);
// client options
if (options.clients)
{
_.each(options.clients, function(handler, name)
{
linker.client(name, handler);
});
}

if (options.customFlows)
{
deprecate('`options.customFlows` will not be supported.');

_.each(options.customFlows, function(handler, name)
{
linker.flow(name, function(flow)
{
flow.register(handler);
if (handler.methods)
{
flow.register('methods', handler.methods);
}
});
});
}

linker.clients()
.then(function(clients)
{
debug('init clients:%s', Object.keys(clients));
});

return linker;
}
exports = module.exports = require('./lib/main');
exports.util = {
parseAction: require('./lib/utils').parseAction
};
57 changes: 57 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

var _ = require('lodash');
var Linker = require('./linker').Linker;
var debug = require('debug')('clientlinker');
var deprecate = require('depd')('clientlinker');


/**
* [options]
* flows
* httpproxy
* clients
* defaults
*/
exports = module.exports = clientlinker;
function clientlinker(options)
{
options || (options = {});
var defaults = options.defaults || options.clientDefaultOptions || (options.defaults = {});
!defaults.flows && options.flows && (defaults.flows = options.flows.slice());

var linker = new Linker(options);
// client options
if (options.clients)
{
_.each(options.clients, function(handler, name)
{
linker.client(name, handler);
});
}

if (options.customFlows)
{
deprecate('`options.customFlows` will not be supported.');

_.each(options.customFlows, function(handler, name)
{
linker.flow(name, function(flow)
{
flow.register(handler);
if (handler.methods)
{
flow.register('methods', handler.methods);
}
});
});
}

linker.clients()
.then(function(clients)
{
debug('init clients:%s', Object.keys(clients));
});

return linker;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clientlinker-core",
"version": "1.0.0",
"version": "1.1.0",
"description": "Linker all clients whether rpc, addon, http request, mock data, local file ...",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 18ae750

Please sign in to comment.