1 | ClientLinker-Core
|
2 | ==================
|
3 |
|
4 | Linker all clients whether rpc, addon, http request, mock data, local file ...
|
5 |
|
6 | A solution to break out of network and OS.
|
7 |
|
8 | [![NPM Version][npm-image]][npm-url]
|
9 | [![NPM Downloads][downloads-image]][npm-url]
|
10 | [![NPM License][license-image]][npm-url]
|
11 | [![Install Size][install-size-image]][install-size-url]
|
12 |
|
13 | # Install
|
14 |
|
15 | ```shell
|
16 | npm install clientlinker-core --save
|
17 | ```
|
18 |
|
19 | # Usage
|
20 |
|
21 | ## Options
|
22 |
|
23 | Linker Options Exmaple, see [Optons](https://github.com/Bacra/node-clientlinker/wiki/Linker-Options)
|
24 | or [Self Flows Options](https://github.com/Bacra/node-clientlinker/wiki/Self-Flows-Options)
|
25 |
|
26 | ```javascript
|
27 | {
|
28 | flows: ['logger', 'pkghandler', 'httpproxy'],
|
29 | defaults: {
|
30 | timeout: 4000
|
31 | },
|
32 | clients: {
|
33 | mail: {
|
34 | // modify defaults flows
|
35 | flows: ['confighandler', 'httpproxy'],
|
36 | confighandler: {
|
37 | read: function(query, body, callback, options) {
|
38 | callback(null, {content: 'hi,'});
|
39 | },
|
40 | send: function(query, body, callback, options) {
|
41 | return Promise.resolve({id: 'xxxx'});
|
42 | }
|
43 | }
|
44 | },
|
45 |
|
46 | // use defaults
|
47 | profile: {
|
48 | pkghandler: __dirname+'/clients/profile.js'
|
49 | }
|
50 | }
|
51 | }
|
52 | ```
|
53 |
|
54 | ## Initialize
|
55 |
|
56 | ```javascript
|
57 | // `clientlinker.conf.js` file content
|
58 |
|
59 | var clientlinker = require('clientlinker-core');
|
60 | var linker = clientlinker(options);
|
61 |
|
62 | // Register flows
|
63 | linker.flow('confighandler', require('clientlinker-flow-confighandler'));
|
64 | linker.flow('logger', require('clientlinker-flow-logger'));
|
65 | linker.flow('httpproxy', require('clientlinker-flow-httpproxy'));
|
66 | linker.flow('pkghandler', require('clientlinker-flow-pkghandler'));
|
67 |
|
68 | // Add clients outsid of config step
|
69 | linker.client(name, clientOptions);
|
70 |
|
71 | module.exports = linker;
|
72 | ```
|
73 |
|
74 | ## Run
|
75 |
|
76 | ### Run in Server
|
77 |
|
78 | ```javascript
|
79 | var linker = require('./clientlinker.conf.js');
|
80 |
|
81 | linker.run('mail.read', userid, {mailid: 'xxxx'}, callback, options);
|
82 |
|
83 | // or use promise
|
84 | linker.run('mail.read', userid, {mailid: 'xxxx'}, options)
|
85 | .then(function(data){});
|
86 | ```
|
87 |
|
88 | ## Upgrade
|
89 |
|
90 | ### 10x
|
91 |
|
92 | Remove deps handlers
|
93 |
|
94 | `runtime.runOptions` `runtime.methodKey` `runtime.lastFlow`
|
95 | `flow.register`
|
96 | `runtime.getRunnedFlowByName` `runtime.runnedFlows` `runtime.isFinished` `runtime.isStarted`
|
97 | `linker.add` `linker.addClient` `linker.parseMethodKey` `linker.getFlow` `linker.runByKey` `linker.bindFlow` `linker.loadFlow`
|
98 | `linker.onInit` `linker.runInShell`
|
99 |
|
100 | Remove attrs
|
101 | `runtime.promise`
|
102 |
|
103 | Remove options
|
104 | `option.clientDefaultOptions`
|
105 |
|
106 | Flow not support `init` callback.
|
107 |
|
108 | Remove callback handlers of `flow.run(runtime, callback)`
|
109 |
|
110 | `callback.toFuncCallback`
|
111 | `callback.reject` `callback.resolve` `callback.callback` `callback.nextAndResolve` `callback.promise` `callback.nextRunner`
|
112 |
|
113 | `flow.run` ret switch to Promise always.
|
114 |
|
115 | Remove `retry` event of `runtime`. Add `retry` event of `linker`.
|
116 |
|
117 |
|
118 | [npm-image]: https://img.shields.io/npm/v/clientlinker-core.svg
|
119 | [downloads-image]: https://img.shields.io/npm/dm/clientlinker-core.svg
|
120 | [npm-url]: https://www.npmjs.org/package/clientlinker-core
|
121 | [license-image]: https://img.shields.io/npm/l/clientlinker-core.svg
|
122 | [install-size-url]: https://packagephobia.now.sh/result?p=clientlinker-core
|
123 | [install-size-image]: https://packagephobia.now.sh/badge?p=clientlinker-core
|