UNPKG

3.25 kBMarkdownView Raw
1ClientLinker-Core
2==================
3
4Linker all clients whether rpc, addon, http request, mock data, local file ...
5
6A 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
16npm install clientlinker-core --save
17```
18
19# Usage
20
21## Options
22
23Linker Options Exmaple, see [Optons](https://github.com/Bacra/node-clientlinker/wiki/Linker-Options)
24or [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
60var clientlinker = require('clientlinker-core');
61var linker = clientlinker(options);
62
63// Register flows
64linker.flow('confighandler', require('clientlinker-flow-confighandler'));
65linker.flow('logger', require('clientlinker-flow-logger'));
66linker.flow('httpproxy', require('clientlinker-flow-httpproxy'));
67linker.flow('pkghandler', require('clientlinker-flow-pkghandler'));
68
69// Add clients outsid of config step
70linker.client(name, clientOptions);
71
72module.exports = linker;
73```
74
75## Run
76
77### Run in Server
78
79```javascript
80var linker = require('./clientlinker.conf.js');
81
82linker.run('mail.read', userid, {mailid: 'xxxx'}, callback, options);
83
84// or use promise
85linker.run('mail.read', userid, {mailid: 'xxxx'}, options)
86 .then(function(data){});
87```
88
89## Upgrade
90
91### 10x
92
93Remove 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
101Remove attrs
102`runtime.promise`
103
104Remove options
105`option.clientDefaultOptions`
106
107Flow not support `init` callback.
108
109Remove 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
116Remove `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