oox 0.0.7 → 0.2.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 CHANGED
@@ -1,2 +1,2 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 lipingruan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 lipingruan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # OOX
2
- graceful microservice framework.
3
-
4
- ### Features
5
- - [x] HTTP & socket.io support (native SSL coming soon)
6
- - [x] Zero configure startup
7
- - [x] Non-invasive coding style
8
- - [x] Intuitive route style
9
- - [x] Intuitive RPC style
10
- - [x] Anywhere interceptor
11
- - [x] Distributed tracing
12
- - [x] Service nodes expand infinitely
13
- - [x] Automatic service discovery (P2P)
14
- - [x] Automatic load balancing (support customization)
15
- - [x] `Distributed / Standalone` seamless handoff
16
- - [x] Highly customizable
17
-
18
- ### Installation
19
- ```bash
20
- npm install -g oox
21
- ```
22
-
23
- ### Usage
24
- ```bash
25
- oox --help
26
- ```
27
-
28
- ### Documentation
29
- [oox.js.org](https://oox.js.org/)
1
+ # OOX
2
+ graceful microservice framework.
3
+
4
+ ### Features
5
+ - [x] HTTP & socket.io support (native SSL coming soon)
6
+ - [x] Zero configure startup
7
+ - [x] Non-invasive coding style
8
+ - [x] Intuitive route style
9
+ - [x] Intuitive RPC style
10
+ - [x] Anywhere interceptor
11
+ - [x] Distributed tracing
12
+ - [x] Service nodes expand infinitely
13
+ - [x] Automatic service discovery (P2P)
14
+ - [x] Automatic load balancing (support customization)
15
+ - [x] `Distributed / Standalone` seamless handoff
16
+ - [x] Highly customizable
17
+
18
+ ### Installation
19
+ ```bash
20
+ npm install -g oox
21
+ ```
22
+
23
+ ### Usage
24
+ ```bash
25
+ oox --help
26
+ ```
27
+
28
+ ### Documentation
29
+ [oox.js.org](https://oox.js.org/)
package/bin/argv.js CHANGED
@@ -1,95 +1,95 @@
1
-
2
-
3
-
4
- exports.getAllEnvArgs = function ( ) {
5
-
6
- const args = process.argv.slice ( 2 )
7
-
8
- const env = { }
9
-
10
- for ( const arg of args ) {
11
-
12
- if ( arg.startsWith ( '--' ) ) {
13
-
14
- env [ arg.slice ( 2 ) ] = true
15
- } else if ( arg.startsWith ( '-' ) ) {
16
-
17
- env [ arg.slice ( 1 ) ] = true
18
- } else if ( !arg.includes ( '=' ) ) {
19
-
20
- env [ arg ] = true
21
- } else {
22
-
23
- const index = arg.indexOf ( '=' )
24
-
25
- const key = arg.slice ( 0, index )
26
-
27
- const val = arg.slice ( index + 1 )
28
-
29
- env [ key ] = exports.parseEnvArg ( val )
30
- }
31
- }
32
-
33
- return env
34
- }
35
-
36
-
37
-
38
- exports.getEnvArgs = function ( names ) {
39
-
40
- const env = { }
41
-
42
- for ( let name of names ) {
43
-
44
- env [ name ] = exports.getEnvArg ( name )
45
- }
46
-
47
- return env
48
- }
49
-
50
-
51
-
52
- // 从命令行参数列表中获取参数值
53
- exports.getEnvArg = function ( name ) {
54
-
55
- if (
56
- process.argv.includes ( name ) ||
57
- process.argv.includes ( '-' + name ) ||
58
- process.argv.includes ( '--' + name )
59
- ) {
60
-
61
- return true
62
- } else {
63
-
64
- const prefix = name + '='
65
-
66
- const [ argv ] = process.argv.filter ( arg => arg.startsWith ( prefix ) )
67
-
68
- if ( !argv ) return null
69
-
70
- const arg = argv.slice ( prefix.length )
71
-
72
- return exports.parseEnvArg ( arg )
73
- }
74
- }
75
-
76
-
77
-
78
- exports.parseEnvArg = function ( value ) {
79
-
80
- switch ( value ) {
81
- case 'no': return false
82
- case 'yes': return true
83
- case 'nil': return null
84
- default:
85
- try {
86
-
87
- return JSON.parse ( value )
88
- } catch ( error ) {
89
-
90
- if ( value.includes ( ',' ) ) return value.split ( ',' )
91
-
92
- return value
93
- }
94
- }
95
- }
1
+
2
+
3
+
4
+ exports.getAllEnvArgs = function ( ) {
5
+
6
+ const args = process.argv.slice ( 2 )
7
+
8
+ const env = { }
9
+
10
+ for ( const arg of args ) {
11
+
12
+ if ( arg.startsWith ( '--' ) ) {
13
+
14
+ env [ arg.slice ( 2 ) ] = true
15
+ } else if ( arg.startsWith ( '-' ) ) {
16
+
17
+ env [ arg.slice ( 1 ) ] = true
18
+ } else if ( !arg.includes ( '=' ) ) {
19
+
20
+ env [ arg ] = true
21
+ } else {
22
+
23
+ const index = arg.indexOf ( '=' )
24
+
25
+ const key = arg.slice ( 0, index )
26
+
27
+ const val = arg.slice ( index + 1 )
28
+
29
+ env [ key ] = exports.parseEnvArg ( val )
30
+ }
31
+ }
32
+
33
+ return env
34
+ }
35
+
36
+
37
+
38
+ exports.getEnvArgs = function ( names ) {
39
+
40
+ const env = { }
41
+
42
+ for ( let name of names ) {
43
+
44
+ env [ name ] = exports.getEnvArg ( name )
45
+ }
46
+
47
+ return env
48
+ }
49
+
50
+
51
+
52
+ // 从命令行参数列表中获取参数值
53
+ exports.getEnvArg = function ( name ) {
54
+
55
+ if (
56
+ process.argv.includes ( name ) ||
57
+ process.argv.includes ( '-' + name ) ||
58
+ process.argv.includes ( '--' + name )
59
+ ) {
60
+
61
+ return true
62
+ } else {
63
+
64
+ const prefix = name + '='
65
+
66
+ const [ argv ] = process.argv.filter ( arg => arg.startsWith ( prefix ) )
67
+
68
+ if ( !argv ) return null
69
+
70
+ const arg = argv.slice ( prefix.length )
71
+
72
+ return exports.parseEnvArg ( arg )
73
+ }
74
+ }
75
+
76
+
77
+
78
+ exports.parseEnvArg = function ( value ) {
79
+
80
+ switch ( value ) {
81
+ case 'no': return false
82
+ case 'yes': return true
83
+ case 'nil': return null
84
+ default:
85
+ try {
86
+
87
+ return JSON.parse ( value )
88
+ } catch ( error ) {
89
+
90
+ if ( value.includes ( ',' ) ) return value.split ( ',' )
91
+
92
+ return value
93
+ }
94
+ }
95
+ }
package/bin/cli.js CHANGED
@@ -1,58 +1,58 @@
1
- #! /usr/bin/env node
2
-
3
- const chalk = require ( 'chalk' )
4
-
5
- const starter = require ( './starter' )
6
-
7
- const args = process.argv.slice ( 2 )
8
-
9
- const command = args [ 0 ]
10
-
11
- var startup = true
12
-
13
- if ( !command || [ 'help', '-h', '-help', '--help', 'version', '-v', '-version', '--version' ].includes ( command ) ) {
14
-
15
- startup = false
16
-
17
- const pkg = require ( '../package.json' )
18
-
19
- console.log ( )
20
- console.log ( 'OOX Service' )
21
- console.log ( chalk.bold`version`, chalk.bold.green`${pkg.version}` )
22
- console.log ( chalk.underline`${pkg.homepage}` )
23
- console.log ( )
24
- }
25
-
26
- if ( [ 'help', '-h', '-help', '--help' ].includes ( command ) ) {
27
-
28
- console.log ( chalk.bold`Usage:` )
29
- console.log ( ' oox entry.js' )
30
- console.log ( )
31
- console.log ( ' oox entry.js port=8080' )
32
- console.log ( )
33
- console.log ( ' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core' )
34
-
35
- console.log ( )
36
- console.log ( chalk.bold`Params:` )
37
-
38
- const params = [
39
- [ ' default-env [ file ] ', '.js or .json file, merge to global.oox' ],
40
- [ ' env [ file ] ', '.js or .json file, merge to global.oox', chalk.bold`(after default-env)` ],
41
- [ ' port [ int ] ', 'set', chalk.bold`0` ,'for random port, or any integer > 0' ],
42
- [ ' group [ dir ] ', 'service group directory, all LocalCall transform to RPC' ],
43
- [ ' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>' ],
44
- [ ' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api' ],
45
- [ ' socketio [ json ] ', 'SocketIO server options, support flat name' ],
46
- [ ' registry [ urls ] ', 'registry service url, support string | array<string>' ],
47
- [ ' template [ file ] ', 'custom Service class file path' ],
48
- [ ' origin [ urls ] ', 'set', chalk.bold`*`, 'allow any connections <Access-Control-Allow-Origin>' ],
49
- [ ' ... ', 'set params as', chalk.bold`foo=bar`+',', 'usage as', chalk.bold`global.oox.foo` ]
50
- ]
51
-
52
- params.forEach ( row => console.log ( ...row, '\n' ) )
53
-
54
- console.log ( )
55
- }
56
-
57
-
1
+ #! /usr/bin/env node
2
+
3
+ const chalk = require ( 'chalk' )
4
+
5
+ const starter = require ( './starter' )
6
+
7
+ const args = process.argv.slice ( 2 )
8
+
9
+ const command = args [ 0 ]
10
+
11
+ var startup = true
12
+
13
+ if ( !command || [ 'help', '-h', '-help', '--help', 'version', '-v', '-version', '--version' ].includes ( command ) ) {
14
+
15
+ startup = false
16
+
17
+ const pkg = require ( '../package.json' )
18
+
19
+ console.log ( )
20
+ console.log ( 'OOX Service' )
21
+ console.log ( chalk.bold`version`, chalk.bold.green`${pkg.version}` )
22
+ console.log ( chalk.underline`${pkg.homepage}` )
23
+ console.log ( )
24
+ }
25
+
26
+ if ( [ 'help', '-h', '-help', '--help' ].includes ( command ) ) {
27
+
28
+ console.log ( chalk.bold`Usage:` )
29
+ console.log ( ' oox entry.js' )
30
+ console.log ( )
31
+ console.log ( ' oox entry.js port=8080' )
32
+ console.log ( )
33
+ console.log ( ' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core' )
34
+
35
+ console.log ( )
36
+ console.log ( chalk.bold`Params:` )
37
+
38
+ const params = [
39
+ [ ' default-env [ file ] ', '.js or .json file, merge to global.oox' ],
40
+ [ ' env [ file ] ', '.js or .json file, merge to global.oox', chalk.bold`(after default-env)` ],
41
+ [ ' port [ int ] ', 'set', chalk.bold`0` ,'for random port, or any integer > 0' ],
42
+ [ ' group [ dir ] ', 'service group directory, all LocalCall transform to RPC' ],
43
+ [ ' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>' ],
44
+ [ ' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api' ],
45
+ [ ' socketio [ json ] ', 'SocketIO server options, support flat name' ],
46
+ [ ' registry [ urls ] ', 'registry service url, support string | array<string>' ],
47
+ [ ' template [ file ] ', 'custom Service class file path' ],
48
+ [ ' origin [ urls ] ', 'set', chalk.bold`*`, 'allow any connections <Access-Control-Allow-Origin>' ],
49
+ [ ' ... ', 'set params as', chalk.bold`foo=bar`+',', 'usage as', chalk.bold`global.oox.foo` ]
50
+ ]
51
+
52
+ params.forEach ( row => console.log ( ...row, '\n' ) )
53
+
54
+ console.log ( )
55
+ }
56
+
57
+
58
58
  if ( startup ) starter.startup ( )
package/bin/configurer.js CHANGED
@@ -1,78 +1,78 @@
1
-
2
- const fs = require ( 'fs' )
3
-
4
- const path = require ( 'path' )
5
-
6
- const argv = require ( './argv' )
7
-
8
-
9
-
10
- /**
11
- * x.y=1 => { x: { y: 1 } }
12
- * @param {*} env
13
- */
14
- function mergeFlatEnv ( env ) {
15
-
16
- for ( const key of Object.keys ( env ) ) {
17
-
18
- // x.y.z
19
- if ( key.includes ( '.' ) && !key.startsWith ( '.' ) && !key.endsWith ( '.' ) ) {
20
-
21
- const subKeys = key.split ( '.' )
22
-
23
- const valueKey = subKeys.pop ( )
24
-
25
- let tmpEnv = env
26
-
27
- for ( subKey of subKeys ) {
28
-
29
- if ( subKey in tmpEnv ) { } else {
30
-
31
- tmpEnv [ subKey ] = { }
32
- }
33
-
34
- tmpEnv = tmpEnv [ subKey ]
35
- }
36
-
37
- tmpEnv [ valueKey ] = env [ key ]
38
- }
39
- }
40
- }
41
-
42
-
43
-
44
- exports.configure = ( ) => {
45
-
46
- let env = Object.create ( null )
47
-
48
- const defaultEnvPath = argv.getEnvArg ( 'default-env' )
49
-
50
- if ( defaultEnvPath && fs.existsSync ( defaultEnvPath ) ) {
51
-
52
- Object.assign ( env, require ( path.resolve ( defaultEnvPath ) ) )
53
- }
54
-
55
-
56
-
57
- const envPath = argv.getEnvArg ( 'env' )
58
-
59
- if ( envPath && fs.existsSync ( envPath ) ) {
60
-
61
- Object.assign ( env, require ( path.resolve ( envPath ) ) )
62
- }
63
-
64
- Object.assign ( env, argv.getAllEnvArgs ( ) )
65
-
66
- mergeFlatEnv ( env )
67
-
68
- if ( 'string' === typeof env.ignore ) env.ignore = env.ignore.split ( ',' )
69
-
70
- if ( 'string' === typeof env.registry ) env.registry = env.registry.split ( ',' )
71
-
72
- if ( 'string' === typeof env.origin && env.origin.includes ( ',' ) ) {
73
-
74
- env.origin = env.origin.split ( ',' )
75
- }
76
-
77
- return env
1
+
2
+ const fs = require ( 'fs' )
3
+
4
+ const path = require ( 'path' )
5
+
6
+ const argv = require ( './argv' )
7
+
8
+
9
+
10
+ /**
11
+ * x.y=1 => { x: { y: 1 } }
12
+ * @param {*} env
13
+ */
14
+ function mergeFlatEnv ( env ) {
15
+
16
+ for ( const key of Object.keys ( env ) ) {
17
+
18
+ // x.y.z
19
+ if ( key.includes ( '.' ) && !key.startsWith ( '.' ) && !key.endsWith ( '.' ) ) {
20
+
21
+ const subKeys = key.split ( '.' )
22
+
23
+ const valueKey = subKeys.pop ( )
24
+
25
+ let tmpEnv = env
26
+
27
+ for ( subKey of subKeys ) {
28
+
29
+ if ( subKey in tmpEnv ) { } else {
30
+
31
+ tmpEnv [ subKey ] = { }
32
+ }
33
+
34
+ tmpEnv = tmpEnv [ subKey ]
35
+ }
36
+
37
+ tmpEnv [ valueKey ] = env [ key ]
38
+ }
39
+ }
40
+ }
41
+
42
+
43
+
44
+ exports.configure = ( ) => {
45
+
46
+ let env = Object.create ( null )
47
+
48
+ const defaultEnvPath = argv.getEnvArg ( 'default-env' )
49
+
50
+ if ( defaultEnvPath && fs.existsSync ( defaultEnvPath ) ) {
51
+
52
+ Object.assign ( env, require ( path.resolve ( defaultEnvPath ) ) )
53
+ }
54
+
55
+
56
+
57
+ const envPath = argv.getEnvArg ( 'env' )
58
+
59
+ if ( envPath && fs.existsSync ( envPath ) ) {
60
+
61
+ Object.assign ( env, require ( path.resolve ( envPath ) ) )
62
+ }
63
+
64
+ Object.assign ( env, argv.getAllEnvArgs ( ) )
65
+
66
+ mergeFlatEnv ( env )
67
+
68
+ if ( 'string' === typeof env.ignore ) env.ignore = env.ignore.split ( ',' )
69
+
70
+ if ( 'string' === typeof env.registry ) env.registry = env.registry.split ( ',' )
71
+
72
+ if ( 'string' === typeof env.origin && env.origin.includes ( ',' ) ) {
73
+
74
+ env.origin = env.origin.split ( ',' )
75
+ }
76
+
77
+ return env
78
78
  }