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.
Files changed (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +29 -32
  3. package/app.js +131 -143
  4. package/bin/argv.js +63 -70
  5. package/bin/cli.js +57 -43
  6. package/bin/configurer.js +60 -62
  7. package/bin/loader.mjs +392 -279
  8. package/bin/proxy-import.js +12 -0
  9. package/bin/proxy-require.js +88 -0
  10. package/bin/register.js +46 -55
  11. package/bin/starter.js +63 -66
  12. package/index.js +155 -168
  13. package/index.mjs +4 -4
  14. package/logger.js +25 -40
  15. package/modules/http/index.js +234 -192
  16. package/modules/http/utils.js +74 -73
  17. package/modules/index.js +86 -88
  18. package/modules/module.js +11 -16
  19. package/modules/socketio/client.js +97 -101
  20. package/modules/socketio/index.js +171 -168
  21. package/modules/socketio/server.js +188 -136
  22. package/modules/socketio/socket.js +1 -4
  23. package/package.json +14 -12
  24. package/types/app.d.ts +50 -51
  25. package/types/bin/argv.d.ts +8 -8
  26. package/types/bin/cli.d.ts +6 -2
  27. package/types/bin/configurer.d.ts +3 -1
  28. package/types/bin/proxy-import.d.ts +4 -0
  29. package/types/bin/proxy-require.d.ts +5 -0
  30. package/types/bin/register.d.ts +1 -1
  31. package/types/bin/starter.d.ts +5 -1
  32. package/types/index.d.ts +78 -76
  33. package/types/logger.d.ts +5 -4
  34. package/types/modules/http/index.d.ts +58 -47
  35. package/types/modules/http/utils.d.ts +14 -17
  36. package/types/modules/index.d.ts +24 -24
  37. package/types/modules/module.d.ts +11 -13
  38. package/types/modules/socketio/client.d.ts +23 -23
  39. package/types/modules/socketio/index.d.ts +37 -37
  40. package/types/modules/socketio/server.d.ts +44 -35
  41. package/types/modules/socketio/socket.d.ts +11 -11
  42. package/types/utils.d.ts +6 -6
  43. package/utils.js +57 -63
  44. package/bin/proxyer.js +0 -61
  45. package/types/bin/proxyer.d.ts +0 -1
package/utils.js CHANGED
@@ -1,63 +1,57 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genKVMethods = exports.getAllCallablePropertyNames = exports.getIPAddress = void 0;
4
- const os_1 = require("os");
5
- function getIPAddress(version = 4) {
6
- const interfaces = (0, os_1.networkInterfaces)();
7
- const ip = [];
8
- for (const name of Object.keys(interfaces))
9
- for (const intf of interfaces[name])
10
- if (intf.mac !== '00:00:00:00:00:00')
11
- if ((version !== 4 && version !== 6) || 'IPv' + version === intf.family)
12
- ip.push(intf.address);
13
- if (!ip.length) {
14
- if (version !== 6)
15
- ip.push('127.0.0.1');
16
- if (version !== 4)
17
- ip.push('::1');
18
- }
19
- return ip;
20
- }
21
- exports.getIPAddress = getIPAddress;
22
- function getAllCallablePropertyNames(obj) {
23
- if (!obj)
24
- return [];
25
- let props = [], tmpProps = [], index = 0, size = 0, tmpProp = '';
26
- const bans = ["constructor", "__defineGetter__", "__defineSetter__",
27
- "hasOwnProperty", "__lookupGetter__", "__lookupSetter__",
28
- "isPrototypeOf", "propertyIsEnumerable", "toString",
29
- "valueOf", "__proto__", "toLocaleString"];
30
- do {
31
- tmpProps = Object.getOwnPropertyNames(obj);
32
- index = -1, size = tmpProps.length;
33
- while (++index < size) {
34
- tmpProp = tmpProps[index];
35
- if (!props.includes(tmpProp) && !bans.includes(tmpProp)) {
36
- props.push(tmpProp);
37
- }
38
- }
39
- } while (obj = Object.getPrototypeOf(obj));
40
- return props;
41
- }
42
- exports.getAllCallablePropertyNames = getAllCallablePropertyNames;
43
- function genKVMethods(methods, kvMethods = new Map(), sourceKVMethods = new Map(), nameStack = []) {
44
- let keys = getAllCallablePropertyNames(methods);
45
- for (const key of keys) {
46
- /**
47
- * @type {Function}
48
- */
49
- let val = methods[key];
50
- if ('function' === typeof val) {
51
- const action = nameStack.concat(key).join('.');
52
- // 原函数绑定
53
- sourceKVMethods.set(action, val);
54
- // 壳函数绑定
55
- kvMethods.set(action, val.bind(methods));
56
- }
57
- else {
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;
@@ -1 +0,0 @@
1
- export declare function proxyGroup(groupDirectory: string, excludes?: any[]): void;