oox 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/LICENSE +21 -21
- package/README.md +29 -29
- package/bin/argv.js +95 -95
- package/bin/cli.js +57 -57
- package/bin/configurer.js +77 -77
- package/bin/proxyer.js +94 -94
- package/bin/register.js +104 -104
- package/bin/starter.js +139 -139
- package/global.js +143 -13
- package/index.js +5 -8
- package/middleware.js +167 -0
- package/package.json +17 -17
- package/rpc/config.class.js +47 -47
- package/rpc/context.class.js +14 -14
- package/rpc/http.class.js +326 -326
- package/rpc/rpc.class.js +128 -130
- package/rpc/rpc.interface.class.js +119 -121
- package/rpc/socketio.class.js +230 -230
- package/service/service.class.js +81 -85
- package/service/socketio.class.js +144 -187
- package/setMap.class.js +67 -67
- package/socketio/client.class.js +189 -189
- package/socketio/server.class.js +221 -221
- package/socketio/socket.class.js +22 -22
- package/util.js +373 -352
- package/global.class.js +0 -124
package/rpc/rpc.class.js
CHANGED
|
@@ -1,130 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
const { genOOXTrace } = require ( '../util' )
|
|
3
|
-
|
|
4
|
-
const Context = require ( './context.class' )
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
static
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
isShareServer
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
* @param {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
format.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
delete
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
1
|
+
|
|
2
|
+
const { genOOXTrace } = require ( '../util' )
|
|
3
|
+
|
|
4
|
+
const Context = require ( './context.class' )
|
|
5
|
+
|
|
6
|
+
const HTTP = require ( './http.class' )
|
|
7
|
+
|
|
8
|
+
const SocketIO = require ( './socketio.class' )
|
|
9
|
+
|
|
10
|
+
const Global = require ( '../global' )
|
|
11
|
+
|
|
12
|
+
const RPCInterface = require ( './rpc.interface.class' )
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module.exports = class RPC extends RPCInterface {
|
|
17
|
+
|
|
18
|
+
static Context = Context
|
|
19
|
+
|
|
20
|
+
static HTTP = HTTP
|
|
21
|
+
static SocketIO = SocketIO
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type {HTTP}
|
|
27
|
+
*/
|
|
28
|
+
http = new this.constructor.HTTP ( this )
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @type {SocketIO}
|
|
34
|
+
*/
|
|
35
|
+
socketio = new this.constructor.SocketIO ( this )
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* new RPC service
|
|
41
|
+
* @param {*} methods
|
|
42
|
+
*/
|
|
43
|
+
constructor ( name, methods ) {
|
|
44
|
+
super ( name, methods )
|
|
45
|
+
|
|
46
|
+
Global.instances.push ( this )
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async serve ( ) {
|
|
52
|
+
|
|
53
|
+
let isShareServer = false
|
|
54
|
+
|
|
55
|
+
if ( this.http.config && this.socketio.config ) {
|
|
56
|
+
|
|
57
|
+
isShareServer = !this.http.config.port && !this.socketio.config.port
|
|
58
|
+
|
|
59
|
+
isShareServer |= this.http.config.port === this.socketio.config.port
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await this.http.serve ( )
|
|
63
|
+
|
|
64
|
+
if ( isShareServer ) this.socketio.server = this.http.server
|
|
65
|
+
|
|
66
|
+
await this.socketio.serve ( )
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
async stop ( ) {
|
|
72
|
+
|
|
73
|
+
await this.http.stop ( )
|
|
74
|
+
await this.socketio.stop ( )
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 通用RPC调用方法
|
|
81
|
+
* @param {String} action
|
|
82
|
+
* @param {[]} params
|
|
83
|
+
* @param {Context} context
|
|
84
|
+
*/
|
|
85
|
+
async call ( action, params=[], context ) {
|
|
86
|
+
|
|
87
|
+
if ( !Array.isArray ( params ) ) params = [ params ]
|
|
88
|
+
|
|
89
|
+
const { traceId } = context
|
|
90
|
+
|
|
91
|
+
Global.contexts.set ( traceId, context )
|
|
92
|
+
|
|
93
|
+
this.emit ( 'request', action, params, context )
|
|
94
|
+
|
|
95
|
+
const format = {
|
|
96
|
+
traceId,
|
|
97
|
+
success: false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const OOXTrace = genOOXTrace ( traceId, this.kvMethods )
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
|
|
104
|
+
const result = await OOXTrace [ traceId ] ( action, [ ...params ], context )
|
|
105
|
+
|
|
106
|
+
format.body = result
|
|
107
|
+
|
|
108
|
+
format.success = true
|
|
109
|
+
|
|
110
|
+
this.emit ( 'success', action, params, context, result )
|
|
111
|
+
} catch ( error ) {
|
|
112
|
+
|
|
113
|
+
format.error = {
|
|
114
|
+
message: error.message,
|
|
115
|
+
stack: error.stack
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this.emit ( 'fail', action, params, context, error )
|
|
119
|
+
} finally {
|
|
120
|
+
|
|
121
|
+
delete OOXTrace [ traceId ]
|
|
122
|
+
|
|
123
|
+
Global.contexts.delete ( traceId )
|
|
124
|
+
|
|
125
|
+
return format
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,121 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
const { EventEmitter } = require ( 'events' )
|
|
3
|
-
|
|
4
|
-
const { genKVMethods, getIPAddress } = require ( '../util' )
|
|
5
|
-
|
|
6
|
-
const Context = require ( './context.class' )
|
|
7
|
-
|
|
8
|
-
const Config = require ( './config.class' )
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
this.kvMethods
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.config.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
* @param {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
async call ( action, params=[], context ) { }
|
|
121
|
-
}
|
|
1
|
+
|
|
2
|
+
const { EventEmitter } = require ( 'events' )
|
|
3
|
+
|
|
4
|
+
const { genKVMethods, getIPAddress } = require ( '../util' )
|
|
5
|
+
|
|
6
|
+
const Context = require ( './context.class' )
|
|
7
|
+
|
|
8
|
+
const Config = require ( './config.class' )
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module.exports = class RPC extends EventEmitter {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* refMethods => methods
|
|
18
|
+
*/
|
|
19
|
+
refMethods = { }
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* the kvMethods is all actions refs
|
|
25
|
+
* @type {Map<String,Function>}
|
|
26
|
+
*/
|
|
27
|
+
kvMethods = new Map ( )
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
set methods ( methods ) {
|
|
32
|
+
|
|
33
|
+
this.refMethods = methods
|
|
34
|
+
|
|
35
|
+
this.kvMethods.clear ( )
|
|
36
|
+
|
|
37
|
+
genKVMethods ( methods, this.kvMethods )
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
appendMethods ( methods ) {
|
|
43
|
+
|
|
44
|
+
genKVMethods ( methods, this.kvMethods )
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
get methods ( ) {
|
|
50
|
+
|
|
51
|
+
return this.refMethods
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* RPC Node Name
|
|
58
|
+
*/
|
|
59
|
+
name = ''
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
config = new Config
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* new RPC service
|
|
69
|
+
* @param {*} methods
|
|
70
|
+
*/
|
|
71
|
+
constructor ( name, methods ) {
|
|
72
|
+
super ( )
|
|
73
|
+
|
|
74
|
+
this.name = name
|
|
75
|
+
|
|
76
|
+
if ( methods )
|
|
77
|
+
this.methods = methods
|
|
78
|
+
|
|
79
|
+
const [ host ] = getIPAddress ( 4 )
|
|
80
|
+
|
|
81
|
+
this.config.host = host
|
|
82
|
+
|
|
83
|
+
this.config.name = name
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async serve ( ) { }
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async stop ( ) { }
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* RPC事件监听
|
|
98
|
+
* @param {'request'|'success'|'fail'} event
|
|
99
|
+
* @param {(action: String, params: [], context: Context, result: {
|
|
100
|
+
* traceId: String,
|
|
101
|
+
* success: Boolean,
|
|
102
|
+
* body: any,
|
|
103
|
+
* error: Error
|
|
104
|
+
* } | Error) => void} listener
|
|
105
|
+
*/
|
|
106
|
+
on ( event, listener ) {
|
|
107
|
+
return super.on ( event, listener )
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 通用RPC调用方法
|
|
114
|
+
* @param {String} action
|
|
115
|
+
* @param {[]} params
|
|
116
|
+
* @param {Context} context
|
|
117
|
+
*/
|
|
118
|
+
async call ( action, params=[], context ) { }
|
|
119
|
+
}
|