oox 0.3.0-beta9 → 0.3.1
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/LICENSE +21 -21
- package/README.md +29 -32
- package/app.js +131 -143
- package/bin/argv.js +63 -70
- package/bin/cli.js +57 -43
- package/bin/configurer.js +60 -62
- package/bin/loader.mjs +392 -279
- package/bin/proxy-import.js +12 -0
- package/bin/proxy-require.js +88 -0
- package/bin/register.js +46 -55
- package/bin/starter.js +63 -66
- package/index.js +155 -168
- package/index.mjs +4 -4
- package/logger.js +25 -40
- package/modules/http/index.js +234 -192
- package/modules/http/utils.js +74 -73
- package/modules/index.js +86 -88
- package/modules/module.js +11 -16
- package/modules/socketio/client.js +97 -101
- package/modules/socketio/index.js +171 -168
- package/modules/socketio/server.js +188 -136
- package/modules/socketio/socket.js +1 -4
- package/package.json +14 -12
- package/types/app.d.ts +50 -51
- package/types/bin/argv.d.ts +8 -8
- package/types/bin/cli.d.ts +6 -2
- package/types/bin/configurer.d.ts +3 -1
- package/types/bin/proxy-import.d.ts +4 -0
- package/types/bin/proxy-require.d.ts +5 -0
- package/types/bin/register.d.ts +1 -1
- package/types/bin/starter.d.ts +5 -1
- package/types/index.d.ts +78 -76
- package/types/logger.d.ts +5 -4
- package/types/modules/http/index.d.ts +58 -47
- package/types/modules/http/utils.d.ts +14 -17
- package/types/modules/index.d.ts +24 -24
- package/types/modules/module.d.ts +11 -13
- package/types/modules/socketio/client.d.ts +23 -23
- package/types/modules/socketio/index.d.ts +37 -37
- package/types/modules/socketio/server.d.ts +44 -35
- package/types/modules/socketio/socket.d.ts +11 -11
- package/types/utils.d.ts +6 -6
- package/utils.js +57 -63
- package/bin/proxyer.js +0 -61
- package/types/bin/proxyer.d.ts +0 -1
package/utils.js
CHANGED
|
@@ -1,63 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
sourceKVMethods.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
genKVMethods(val, kvMethods, sourceKVMethods, nameStack.concat(key));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return { kvMethods, sourceKVMethods };
|
|
62
|
-
}
|
|
63
|
-
exports.genKVMethods = genKVMethods;
|
|
1
|
+
import { networkInterfaces } from 'os';
|
|
2
|
+
export function getIPAddress(version = 4) {
|
|
3
|
+
const interfaces = networkInterfaces();
|
|
4
|
+
const ip = [];
|
|
5
|
+
for (const name of Object.keys(interfaces))
|
|
6
|
+
for (const intf of interfaces[name])
|
|
7
|
+
if (intf.mac !== '00:00:00:00:00:00')
|
|
8
|
+
if ((version !== 4 && version !== 6) || 'IPv' + version === intf.family)
|
|
9
|
+
ip.push(intf.address);
|
|
10
|
+
if (!ip.length) {
|
|
11
|
+
if (version !== 6)
|
|
12
|
+
ip.push('127.0.0.1');
|
|
13
|
+
if (version !== 4)
|
|
14
|
+
ip.push('::1');
|
|
15
|
+
}
|
|
16
|
+
return ip;
|
|
17
|
+
}
|
|
18
|
+
export function getAllCallablePropertyNames(obj) {
|
|
19
|
+
if (!obj)
|
|
20
|
+
return [];
|
|
21
|
+
let props = [], tmpProps = [], index = 0, size = 0, tmpProp = '';
|
|
22
|
+
const bans = ["constructor", "__defineGetter__", "__defineSetter__",
|
|
23
|
+
"hasOwnProperty", "__lookupGetter__", "__lookupSetter__",
|
|
24
|
+
"isPrototypeOf", "propertyIsEnumerable", "toString",
|
|
25
|
+
"valueOf", "__proto__", "toLocaleString"];
|
|
26
|
+
do {
|
|
27
|
+
tmpProps = Object.getOwnPropertyNames(obj);
|
|
28
|
+
index = -1, size = tmpProps.length;
|
|
29
|
+
while (++index < size) {
|
|
30
|
+
tmpProp = tmpProps[index];
|
|
31
|
+
if (!props.includes(tmpProp) && !bans.includes(tmpProp)) {
|
|
32
|
+
props.push(tmpProp);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} while (obj = Object.getPrototypeOf(obj));
|
|
36
|
+
return props;
|
|
37
|
+
}
|
|
38
|
+
export function genKVMethods(methods, kvMethods = new Map(), sourceKVMethods = new Map(), nameStack = []) {
|
|
39
|
+
let keys = getAllCallablePropertyNames(methods);
|
|
40
|
+
for (const key of keys) {
|
|
41
|
+
/**
|
|
42
|
+
* @type {Function}
|
|
43
|
+
*/
|
|
44
|
+
let val = methods[key];
|
|
45
|
+
if ('function' === typeof val) {
|
|
46
|
+
const action = nameStack.concat(key).join('.');
|
|
47
|
+
// 原函数绑定
|
|
48
|
+
sourceKVMethods.set(action, val);
|
|
49
|
+
// 壳函数绑定
|
|
50
|
+
kvMethods.set(action, val.bind(methods));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
genKVMethods(val, kvMethods, sourceKVMethods, nameStack.concat(key));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { kvMethods, sourceKVMethods };
|
|
57
|
+
}
|
package/bin/proxyer.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.proxyGroup = void 0;
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const oox = require("../index");
|
|
7
|
-
const node_module_1 = require("node:module");
|
|
8
|
-
/**
|
|
9
|
-
* 重写 require 缓存
|
|
10
|
-
*/
|
|
11
|
-
function rewriteModuleCache(id, exports) {
|
|
12
|
-
const pathname = id.split(path.sep).slice(0, -1).join(path.sep);
|
|
13
|
-
const pathSplit = pathname.split(path.sep);
|
|
14
|
-
const paths = pathSplit.map((v, i, a) => a.slice(0, i + 1).concat('node_modules').join(path.sep)).reverse();
|
|
15
|
-
const m = new node_module_1.Module(id, null);
|
|
16
|
-
m.path = pathname;
|
|
17
|
-
m.exports = exports;
|
|
18
|
-
m.filename = m.id;
|
|
19
|
-
m.loaded = true;
|
|
20
|
-
m.children = [];
|
|
21
|
-
m.paths = paths;
|
|
22
|
-
require.cache[id] = m;
|
|
23
|
-
}
|
|
24
|
-
function dotCall(name, action) {
|
|
25
|
-
return new Proxy(function () { }, {
|
|
26
|
-
get(target, key) {
|
|
27
|
-
return dotCall(name, action ? action + '.' + key : key);
|
|
28
|
-
},
|
|
29
|
-
has(target, key) { return true; },
|
|
30
|
-
apply(target, thisArg, args) {
|
|
31
|
-
return oox.rpc(name, action, args);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function proxyGroup(groupDirectory, excludes = []) {
|
|
36
|
-
if (!groupDirectory)
|
|
37
|
-
return;
|
|
38
|
-
const directory = path.resolve(groupDirectory);
|
|
39
|
-
const stat = fs.statSync(directory);
|
|
40
|
-
if (!stat.isDirectory())
|
|
41
|
-
throw new Error('group must be directory');
|
|
42
|
-
const subs = fs.readdirSync(directory);
|
|
43
|
-
for (const filename of subs) {
|
|
44
|
-
const fullPath = path.resolve(directory + path.sep + filename);
|
|
45
|
-
const stat = fs.statSync(fullPath);
|
|
46
|
-
let id = '', name = '';
|
|
47
|
-
if (stat.isDirectory() && fs.existsSync(fullPath + '/index.js')) {
|
|
48
|
-
id = fullPath + '/index.js';
|
|
49
|
-
name = filename;
|
|
50
|
-
}
|
|
51
|
-
else if (filename.endsWith('.js')) {
|
|
52
|
-
id = fullPath;
|
|
53
|
-
name = filename.split('.js')[0];
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
continue;
|
|
57
|
-
if (!excludes.includes(name))
|
|
58
|
-
rewriteModuleCache(id, dotCall(name, ''));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.proxyGroup = proxyGroup;
|
package/types/bin/proxyer.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function proxyGroup(groupDirectory: string, excludes?: any[]): void;
|