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 | anyToError: true,
|
31 | timeout: 4000
|
32 | },
|
33 | clients: {
|
34 | mail: {
|
35 | // modify defaults flows
|
36 | flows: ['confighandler', 'httpproxy'],
|
37 | confighandler: {
|
38 | read: function(query, body, callback, options) {
|
39 | callback(null, {content: 'hi,'});
|
40 | },
|
41 | send: function(query, body, callback, options) {
|
42 | return Promise.resolve({id: 'xxxx'});
|
43 | }
|
44 | }
|
45 | },
|
46 |
|
47 | // use defaults
|
48 | profile: {
|
49 | pkghandler: __dirname+'/clients/profile.js'
|
50 | }
|
51 | }
|
52 | }
|
53 | ```
|
54 |
|
55 | ## Initialize
|
56 |
|
57 | ```javascript
|
58 | // `clientlinker.conf.js` file content
|
59 |
|
60 | var clientlinker = require('clientlinker-core');
|
61 | var linker = clientlinker(options);
|
62 |
|
63 | // Register flows
|
64 | linker.flow('confighandler', require('clientlinker-flow-confighandler'));
|
65 | linker.flow('logger', require('clientlinker-flow-logger'));
|
66 | linker.flow('httpproxy', require('clientlinker-flow-httpproxy'));
|
67 | linker.flow('pkghandler', require('clientlinker-flow-pkghandler'));
|
68 |
|
69 | // Add clients outsid of config step
|
70 | linker.client(name, clientOptions);
|
71 |
|
72 | module.exports = linker;
|
73 | ```
|
74 |
|
75 | ## Run
|
76 |
|
77 | ### Run in Server
|
78 |
|
79 | ```javascript
|
80 | var linker = require('./clientlinker.conf.js');
|
81 |
|
82 | linker.run('mail.read', userid, {mailid: 'xxxx'}, callback, options);
|
83 |
|
84 | // or use promise
|
85 | linker.run('mail.read', userid, {mailid: 'xxxx'}, options)
|
86 | .then(function(data){});
|
87 | ```
|
88 |
|
89 | ## Upgrade
|
90 |
|
91 | ### 10x
|
92 |
|
93 | Remove deps handlers
|
94 |
|
95 | `runtime.runOptions` `runtime.methodKey` `runtime.lastFlow`
|
96 | `flow.register`
|
97 | `runtime.getRunnedFlowByName` `runtime.runnedFlows` `runtime.isFinished` `runtime.isStarted`
|
98 | `linker.add` `linker.addClient` `linker.parseMethodKey` `linker.getFlow` `linker.runByKey` `linker.bindFlow` `linker.loadFlow`
|
99 | `linker.onInit` `linker.runInShell`
|
100 |
|
101 | Remove attrs
|
102 | `runtime.promise`
|
103 |
|
104 | Remove options
|
105 | `option.clientDefaultOptions`
|
106 |
|
107 | Flow not support `init` callback.
|
108 |
|
109 | Remove callback handlers of `flow.run(runtime, callback)`
|
110 |
|
111 | `callback.toFuncCallback`
|
112 | `callback.reject` `callback.resolve` `callback.callback` `callback.nextAndResolve` `callback.promise` `callback.nextRunner`
|
113 |
|
114 | `flow.run` ret switch to Promise always.
|
115 |
|
116 | Remove `retry` event of `runtime`. Add `retry` event of `linker`.
|
117 |
|
118 |
|
119 | [npm-image]: https://img.shields.io/npm/v/clientlinker-core.svg
|
120 | [downloads-image]: https://img.shields.io/npm/dm/clientlinker-core.svg
|
121 | [npm-url]: https://www.npmjs.org/package/clientlinker-core
|
122 | [license-image]: https://img.shields.io/npm/l/clientlinker-core.svg
|
123 | [install-size-url]: https://packagephobia.now.sh/result?p=clientlinker-core
|
124 | [install-size-image]: https://packagephobia.now.sh/badge?p=clientlinker-core
|