UNPKG

3.14 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 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
59var clientlinker = require('clientlinker-core');
60var linker = clientlinker(options);
61
62// Register flows
63linker.flow('confighandler', require('clientlinker-flow-confighandler'));
64linker.flow('logger', require('clientlinker-flow-logger'));
65linker.flow('httpproxy', require('clientlinker-flow-httpproxy'));
66linker.flow('pkghandler', require('clientlinker-flow-pkghandler'));
67
68// Add clients outsid of config step
69linker.client(name, clientOptions);
70
71module.exports = linker;
72```
73
74## Run
75
76### Run in Server
77
78```javascript
79var linker = require('./clientlinker.conf.js');
80
81linker.run('mail.read', userid, {mailid: 'xxxx'}, options)
82 .then(function(data){});
83```
84
85## Upgrade
86
87### 10x
88
89Remove deps handlers
90
91`runtime.runOptions` `runtime.methodKey` `runtime.lastFlow`
92`flow.register`
93`runtime.getRunnedFlowByName` `runtime.runnedFlows` `runtime.isFinished` `runtime.isStarted`
94`linker.add` `linker.addClient` `linker.parseMethodKey` `linker.getFlow` `linker.runByKey` `linker.bindFlow` `linker.loadFlow`
95`linker.onInit` `linker.runInShell`
96
97Remove attrs
98`runtime.promise`
99
100Remove options
101`option.clientDefaultOptions`
102
103Flow not support `init` callback.
104
105Remove callback handlers of `flow.run(runtime, callback)`
106
107`callback.toFuncCallback`
108`callback.reject` `callback.resolve` `callback.callback` `callback.nextAndResolve` `callback.promise` `callback.nextRunner`
109
110`flow.run` ret switch to Promise always.
111
112Remove `retry` event of `runtime`. Add `retry` event of `linker`.
113
114
115[npm-image]: https://img.shields.io/npm/v/clientlinker-core.svg
116[downloads-image]: https://img.shields.io/npm/dm/clientlinker-core.svg
117[npm-url]: https://www.npmjs.org/package/clientlinker-core
118[license-image]: https://img.shields.io/npm/l/clientlinker-core.svg
119[install-size-url]: https://packagephobia.now.sh/result?p=clientlinker-core
120[install-size-image]: https://packagephobia.now.sh/badge?p=clientlinker-core