oox 0.3.0-beta2 → 0.3.0-beta3

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.
@@ -1,47 +1,47 @@
1
- /// <reference types="node" />
2
- import * as http from 'node:http';
3
- import * as oox from '../../index';
4
- import Module, { ModuleConfig } from '../module';
5
- export declare class HTTPConfig extends ModuleConfig {
6
- port: number;
7
- path: string;
8
- origin: string;
9
- }
10
- export default class HTTPModule extends Module {
11
- name: string;
12
- config: HTTPConfig;
13
- server: http.Server;
14
- setConfig(config: HTTPConfig): void;
15
- getConfig(): HTTPConfig;
16
- /**
17
- * start http service
18
- */
19
- serve(): Promise<void>;
20
- /**
21
- * stop http service
22
- */
23
- stop(): Promise<void>;
24
- /**
25
- * browser cross origin
26
- */
27
- cors(request: http.IncomingMessage, response: http.ServerResponse): boolean;
28
- /**
29
- * HTTP-RPC服务器请求监听方法
30
- */
31
- call(request: http.IncomingMessage, response: http.ServerResponse): Promise<void>;
32
- /**
33
- * HTTP Response Catch
34
- */
35
- respond(request: http.IncomingMessage, response: http.ServerResponse, format: {
36
- body?: any;
37
- success: boolean;
38
- error?: {
39
- message: any;
40
- stack: any;
41
- };
42
- }): void;
43
- /**
44
- * HTTP RPC
45
- */
46
- rpc(url: string | URL, action: string, params: Array<any>, context?: oox.Context): Promise<any>;
47
- }
1
+ /// <reference types="node" />
2
+ import * as http from 'node:http';
3
+ import * as oox from '../../index';
4
+ import Module, { ModuleConfig } from '../module';
5
+ export declare class HTTPConfig extends ModuleConfig {
6
+ port: number;
7
+ path: string;
8
+ origin: string;
9
+ }
10
+ export default class HTTPModule extends Module {
11
+ name: string;
12
+ config: HTTPConfig;
13
+ server: http.Server;
14
+ setConfig(config: HTTPConfig): void;
15
+ getConfig(): HTTPConfig;
16
+ /**
17
+ * start http service
18
+ */
19
+ serve(): Promise<void>;
20
+ /**
21
+ * stop http service
22
+ */
23
+ stop(): Promise<void>;
24
+ /**
25
+ * browser cross origin
26
+ */
27
+ cors(request: http.IncomingMessage, response: http.ServerResponse): boolean;
28
+ /**
29
+ * HTTP-RPC服务器请求监听方法
30
+ */
31
+ call(request: http.IncomingMessage, response: http.ServerResponse): Promise<void>;
32
+ /**
33
+ * HTTP Response Catch
34
+ */
35
+ respond(request: http.IncomingMessage, response: http.ServerResponse, format: {
36
+ body?: any;
37
+ success: boolean;
38
+ error?: {
39
+ message: any;
40
+ stack: any;
41
+ };
42
+ }): void;
43
+ /**
44
+ * HTTP RPC
45
+ */
46
+ rpc(url: string | URL, action: string, params: Array<any>, context?: oox.Context): Promise<any>;
47
+ }
@@ -1,17 +1,17 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import * as http from 'node:http';
5
- import * as stream from 'node:stream';
6
- /**
7
- * Stream => Buffer
8
- */
9
- export declare function stream2buffer(stream: stream.Readable, totalLength?: number): Promise<Buffer>;
10
- /**
11
- * Request => JSONObject
12
- */
13
- export declare function parseHTTPBody(request: http.IncomingMessage): Promise<any>;
14
- /**
15
- * http request
16
- */
17
- export declare function httpRequest(url: URL | string, options: http.RequestOptions, body: string): Promise<any>;
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import * as http from 'node:http';
5
+ import * as stream from 'node:stream';
6
+ /**
7
+ * Stream => Buffer
8
+ */
9
+ export declare function stream2buffer(stream: stream.Readable, totalLength?: number): Promise<Buffer>;
10
+ /**
11
+ * Request => JSONObject
12
+ */
13
+ export declare function parseHTTPBody(request: http.IncomingMessage): Promise<any>;
14
+ /**
15
+ * http request
16
+ */
17
+ export declare function httpRequest(url: URL | string, options: http.RequestOptions, body: string): Promise<any>;
@@ -1,21 +1,22 @@
1
- import Module from './module';
2
- import HTTP from './http';
3
- export default class Modules extends Module {
4
- #private;
5
- /**
6
- * the module unique name
7
- */
8
- name: string;
9
- /**
10
- * all builtin modules
11
- */
12
- builtins: {
13
- http: HTTP;
14
- };
15
- constructor();
16
- add(module: Module): this;
17
- get(name: string): Module;
18
- remove(name: string): Promise<void>;
19
- serve(): Promise<void>;
20
- stop(): Promise<void>;
21
- }
1
+ import Module from './module';
2
+ import HTTP from './http';
3
+ export default class Modules extends Module {
4
+ #private;
5
+ /**
6
+ * the module unique name
7
+ */
8
+ name: string;
9
+ /**
10
+ * all builtin modules
11
+ */
12
+ builtins: {
13
+ http: HTTP;
14
+ };
15
+ constructor();
16
+ add(module: Module): this;
17
+ get(name: string): Module;
18
+ remove(name: string): Promise<void>;
19
+ setConfig(config: any): void;
20
+ serve(): Promise<void>;
21
+ stop(): Promise<void>;
22
+ }
@@ -1,13 +1,13 @@
1
- export declare class ModuleConfig {
2
- [x: string]: any;
3
- disabled: boolean;
4
- }
5
- export default class Module {
6
- [x: string]: any;
7
- config: ModuleConfig;
8
- name: string;
9
- setConfig(config: any): void;
10
- getConfig(): ModuleConfig;
11
- serve(): Promise<void>;
12
- stop(): Promise<void>;
13
- }
1
+ export declare class ModuleConfig {
2
+ [x: string]: any;
3
+ disabled: boolean;
4
+ }
5
+ export default class Module {
6
+ [x: string]: any;
7
+ config: ModuleConfig;
8
+ name: string;
9
+ setConfig(config: any): void;
10
+ getConfig(): ModuleConfig;
11
+ serve(): Promise<void>;
12
+ stop(): Promise<void>;
13
+ }
package/types/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export declare function getIPAddress(version?: number): string[];
2
- export declare function getAllCallablePropertyNames(obj: any): string[];
3
- export declare function genKVMethods(methods: any, kvMethods?: Map<string, Function>, sourceKVMethods?: Map<string, Function>, nameStack?: string[]): {
4
- kvMethods: Map<string, Function>;
5
- sourceKVMethods: Map<string, Function>;
6
- };
1
+ export declare function getIPAddress(version?: number): string[];
2
+ export declare function getAllCallablePropertyNames(obj: any): string[];
3
+ export declare function genKVMethods(methods: any, kvMethods?: Map<string, Function>, sourceKVMethods?: Map<string, Function>, nameStack?: string[]): {
4
+ kvMethods: Map<string, Function>;
5
+ sourceKVMethods: Map<string, Function>;
6
+ };
package/utils.js CHANGED
@@ -1,63 +1,63 @@
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
+ "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;