oox 0.3.0-beta2 → 0.3.0-beta5
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 +32 -32
- package/app.js +142 -142
- package/bin/argv.js +70 -70
- package/bin/cli.js +43 -43
- package/bin/configurer.js +49 -49
- package/bin/proxyer.js +61 -61
- package/bin/register.js +55 -55
- package/bin/starter.js +81 -81
- package/index.js +144 -144
- package/index.mjs +3 -3
- package/modules/http/index.js +180 -180
- package/modules/http/utils.js +73 -73
- package/modules/index.js +81 -68
- package/modules/module.js +16 -16
- package/package.json +2 -2
- package/types/app.d.ts +37 -37
- package/types/bin/argv.d.ts +8 -8
- package/types/bin/cli.d.ts +2 -2
- package/types/bin/configurer.d.ts +1 -1
- package/types/bin/proxyer.d.ts +1 -1
- package/types/bin/register.d.ts +1 -1
- package/types/bin/starter.d.ts +1 -1
- package/types/index.d.ts +70 -70
- package/types/modules/http/index.d.ts +47 -47
- package/types/modules/http/utils.d.ts +17 -17
- package/types/modules/index.d.ts +22 -21
- package/types/modules/module.d.ts +13 -13
- package/types/utils.d.ts +6 -6
- package/utils.js +63 -63
package/modules/http/utils.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.httpRequest = exports.parseHTTPBody = exports.stream2buffer = void 0;
|
|
4
|
-
const http = require("node:http");
|
|
5
|
-
/**
|
|
6
|
-
* Stream => Buffer
|
|
7
|
-
*/
|
|
8
|
-
function stream2buffer(stream, totalLength = 0) {
|
|
9
|
-
return new Promise(function (resolve, reject) {
|
|
10
|
-
let buffers = [];
|
|
11
|
-
stream.on('error', reject);
|
|
12
|
-
if (totalLength) {
|
|
13
|
-
stream.on('data', function (data) { buffers.push(data); });
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
stream.on('data', function (data) {
|
|
17
|
-
buffers.push(data);
|
|
18
|
-
totalLength += data.length;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
stream.on('end', function () { resolve(Buffer.concat(buffers, totalLength)); });
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.stream2buffer = stream2buffer;
|
|
25
|
-
/**
|
|
26
|
-
* Request => JSONObject
|
|
27
|
-
*/
|
|
28
|
-
async function parseHTTPBody(request) {
|
|
29
|
-
if (request.method === 'GET')
|
|
30
|
-
return null;
|
|
31
|
-
let contentType = request.headers['content-type'];
|
|
32
|
-
// application/json; charset=utf-8
|
|
33
|
-
if (contentType)
|
|
34
|
-
contentType = contentType.split(';')[0].trim();
|
|
35
|
-
const contentSize = request.headers['content-length'];
|
|
36
|
-
const buffer = await stream2buffer(request, +contentSize || 0);
|
|
37
|
-
if (contentSize && buffer.length !== +contentSize)
|
|
38
|
-
throw new Error('Content-Length Incorrect');
|
|
39
|
-
const bodyString = buffer.toString();
|
|
40
|
-
if ('application/json' === contentType) {
|
|
41
|
-
return JSON.parse(bodyString);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
return bodyString;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.parseHTTPBody = parseHTTPBody;
|
|
48
|
-
/**
|
|
49
|
-
* http request
|
|
50
|
-
*/
|
|
51
|
-
function httpRequest(url, options, body) {
|
|
52
|
-
return new Promise(function (resolve, reject) {
|
|
53
|
-
const request = http.request(url, options, async function (response) {
|
|
54
|
-
try {
|
|
55
|
-
const result = await parseHTTPBody(response);
|
|
56
|
-
resolve(result);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
const decoration = new Error(`${response.statusCode} - ${error.message}`);
|
|
60
|
-
reject(decoration);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
request.on('error', reject);
|
|
64
|
-
if (body) {
|
|
65
|
-
request.method = 'POST';
|
|
66
|
-
request.setHeader('Content-Type', 'application/json');
|
|
67
|
-
request.setHeader('Content-Length', Buffer.byteLength(body));
|
|
68
|
-
request.write(body);
|
|
69
|
-
}
|
|
70
|
-
request.end();
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
exports.httpRequest = httpRequest;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpRequest = exports.parseHTTPBody = exports.stream2buffer = void 0;
|
|
4
|
+
const http = require("node:http");
|
|
5
|
+
/**
|
|
6
|
+
* Stream => Buffer
|
|
7
|
+
*/
|
|
8
|
+
function stream2buffer(stream, totalLength = 0) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
let buffers = [];
|
|
11
|
+
stream.on('error', reject);
|
|
12
|
+
if (totalLength) {
|
|
13
|
+
stream.on('data', function (data) { buffers.push(data); });
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
stream.on('data', function (data) {
|
|
17
|
+
buffers.push(data);
|
|
18
|
+
totalLength += data.length;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
stream.on('end', function () { resolve(Buffer.concat(buffers, totalLength)); });
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.stream2buffer = stream2buffer;
|
|
25
|
+
/**
|
|
26
|
+
* Request => JSONObject
|
|
27
|
+
*/
|
|
28
|
+
async function parseHTTPBody(request) {
|
|
29
|
+
if (request.method === 'GET')
|
|
30
|
+
return null;
|
|
31
|
+
let contentType = request.headers['content-type'];
|
|
32
|
+
// application/json; charset=utf-8
|
|
33
|
+
if (contentType)
|
|
34
|
+
contentType = contentType.split(';')[0].trim();
|
|
35
|
+
const contentSize = request.headers['content-length'];
|
|
36
|
+
const buffer = await stream2buffer(request, +contentSize || 0);
|
|
37
|
+
if (contentSize && buffer.length !== +contentSize)
|
|
38
|
+
throw new Error('Content-Length Incorrect');
|
|
39
|
+
const bodyString = buffer.toString();
|
|
40
|
+
if ('application/json' === contentType) {
|
|
41
|
+
return JSON.parse(bodyString);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return bodyString;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.parseHTTPBody = parseHTTPBody;
|
|
48
|
+
/**
|
|
49
|
+
* http request
|
|
50
|
+
*/
|
|
51
|
+
function httpRequest(url, options, body) {
|
|
52
|
+
return new Promise(function (resolve, reject) {
|
|
53
|
+
const request = http.request(url, options, async function (response) {
|
|
54
|
+
try {
|
|
55
|
+
const result = await parseHTTPBody(response);
|
|
56
|
+
resolve(result);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const decoration = new Error(`${response.statusCode} - ${error.message}`);
|
|
60
|
+
reject(decoration);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
request.on('error', reject);
|
|
64
|
+
if (body) {
|
|
65
|
+
request.method = 'POST';
|
|
66
|
+
request.setHeader('Content-Type', 'application/json');
|
|
67
|
+
request.setHeader('Content-Length', Buffer.byteLength(body));
|
|
68
|
+
request.write(body);
|
|
69
|
+
}
|
|
70
|
+
request.end();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.httpRequest = httpRequest;
|
package/modules/index.js
CHANGED
|
@@ -1,68 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const module_1 = require("./module");
|
|
4
|
-
const http_1 = require("./http");
|
|
5
|
-
class Modules extends module_1.default {
|
|
6
|
-
/**
|
|
7
|
-
* the module unique name
|
|
8
|
-
*/
|
|
9
|
-
name = 'oox:modules';
|
|
10
|
-
/**
|
|
11
|
-
* FIFO queue for modules starting
|
|
12
|
-
*/
|
|
13
|
-
#queue = [];
|
|
14
|
-
/**
|
|
15
|
-
* all modules map
|
|
16
|
-
*/
|
|
17
|
-
#map = new Map();
|
|
18
|
-
/**
|
|
19
|
-
* all builtin modules
|
|
20
|
-
*/
|
|
21
|
-
builtins = {
|
|
22
|
-
http: new http_1.default,
|
|
23
|
-
};
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this.add(this.builtins.http);
|
|
27
|
-
}
|
|
28
|
-
add(module) {
|
|
29
|
-
if (!module.name || 'string' !== typeof module.name)
|
|
30
|
-
throw new Error(`Module<${module.name}> has noname`);
|
|
31
|
-
if (this.#map.has(module.name))
|
|
32
|
-
throw new Error(`Module<${module.name}> has exists`);
|
|
33
|
-
this.#map.set(module.name, module);
|
|
34
|
-
this.#queue.push(module);
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
get(name) {
|
|
38
|
-
return this.#map.get(name);
|
|
39
|
-
}
|
|
40
|
-
async remove(name) {
|
|
41
|
-
const module = this.get(name);
|
|
42
|
-
if (!module)
|
|
43
|
-
return;
|
|
44
|
-
await module.stop();
|
|
45
|
-
const index = this.#queue.indexOf(module);
|
|
46
|
-
this.#queue.splice(index, 1);
|
|
47
|
-
this.#map.delete(name);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const module_1 = require("./module");
|
|
4
|
+
const http_1 = require("./http");
|
|
5
|
+
class Modules extends module_1.default {
|
|
6
|
+
/**
|
|
7
|
+
* the module unique name
|
|
8
|
+
*/
|
|
9
|
+
name = 'oox:modules';
|
|
10
|
+
/**
|
|
11
|
+
* FIFO queue for modules starting
|
|
12
|
+
*/
|
|
13
|
+
#queue = [];
|
|
14
|
+
/**
|
|
15
|
+
* all modules map
|
|
16
|
+
*/
|
|
17
|
+
#map = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* all builtin modules
|
|
20
|
+
*/
|
|
21
|
+
builtins = {
|
|
22
|
+
http: new http_1.default,
|
|
23
|
+
};
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.add(this.builtins.http);
|
|
27
|
+
}
|
|
28
|
+
add(module) {
|
|
29
|
+
if (!module.name || 'string' !== typeof module.name)
|
|
30
|
+
throw new Error(`Module<${module.name}> has noname`);
|
|
31
|
+
if (this.#map.has(module.name))
|
|
32
|
+
throw new Error(`Module<${module.name}> has exists`);
|
|
33
|
+
this.#map.set(module.name, module);
|
|
34
|
+
this.#queue.push(module);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
get(name) {
|
|
38
|
+
return this.#map.get(name);
|
|
39
|
+
}
|
|
40
|
+
async remove(name) {
|
|
41
|
+
const module = this.get(name);
|
|
42
|
+
if (!module)
|
|
43
|
+
return;
|
|
44
|
+
await module.stop();
|
|
45
|
+
const index = this.#queue.indexOf(module);
|
|
46
|
+
this.#queue.splice(index, 1);
|
|
47
|
+
this.#map.delete(name);
|
|
48
|
+
}
|
|
49
|
+
setConfig(config) {
|
|
50
|
+
for (const module of this.#queue) {
|
|
51
|
+
if (module.name in config) {
|
|
52
|
+
const moduleConfig = config[module.name];
|
|
53
|
+
if (moduleConfig) {
|
|
54
|
+
module.setConfig(moduleConfig);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
module.setConfig({ disabled: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async serve() {
|
|
63
|
+
try {
|
|
64
|
+
for (const module of this.#queue) {
|
|
65
|
+
if (!module.getConfig().disabled) {
|
|
66
|
+
await module.serve();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
await this.stop();
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async stop() {
|
|
76
|
+
for (const module of this.#queue) {
|
|
77
|
+
await module.stop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = Modules;
|
package/modules/module.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModuleConfig = void 0;
|
|
4
|
-
class ModuleConfig {
|
|
5
|
-
disabled = false;
|
|
6
|
-
}
|
|
7
|
-
exports.ModuleConfig = ModuleConfig;
|
|
8
|
-
class Module {
|
|
9
|
-
config;
|
|
10
|
-
name;
|
|
11
|
-
setConfig(config) { }
|
|
12
|
-
getConfig() { return this.config; }
|
|
13
|
-
async serve() { }
|
|
14
|
-
async stop() { }
|
|
15
|
-
}
|
|
16
|
-
exports.default = Module;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleConfig = void 0;
|
|
4
|
+
class ModuleConfig {
|
|
5
|
+
disabled = false;
|
|
6
|
+
}
|
|
7
|
+
exports.ModuleConfig = ModuleConfig;
|
|
8
|
+
class Module {
|
|
9
|
+
config;
|
|
10
|
+
name;
|
|
11
|
+
setConfig(config) { }
|
|
12
|
+
getConfig() { return this.config; }
|
|
13
|
+
async serve() { }
|
|
14
|
+
async stop() { }
|
|
15
|
+
}
|
|
16
|
+
exports.default = Module;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oox",
|
|
3
|
-
"version": "0.3.0-
|
|
3
|
+
"version": "0.3.0-beta5",
|
|
4
4
|
"description": "Graceful NodeJS distributed application solution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"homepage": "https://github.com/lipingruan/oox",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@oox/module-socketio": "^0.0.
|
|
29
|
+
"@oox/module-socketio": "^0.0.3",
|
|
30
30
|
"chalk": "^4.1.0"
|
|
31
31
|
},
|
|
32
32
|
"engines": {
|
package/types/app.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { EventEmitter } from 'node:events';
|
|
4
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
-
export interface ReturnsBody {
|
|
6
|
-
traceId: string;
|
|
7
|
-
success: boolean;
|
|
8
|
-
body?: any;
|
|
9
|
-
error?: {
|
|
10
|
-
message: string;
|
|
11
|
-
stack: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare class Context {
|
|
15
|
-
traceId?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare const asyncStore: AsyncLocalStorage<Context>;
|
|
18
|
-
export declare const eventHub: EventEmitter;
|
|
19
|
-
/**
|
|
20
|
-
* the kvMethods is all actions refs [has bind this]
|
|
21
|
-
*/
|
|
22
|
-
export declare const kvMethods: Map<string, Function>;
|
|
23
|
-
export declare const sourceKVMethods: Map<string, Function>;
|
|
24
|
-
export declare function setMethods(methods: any): void;
|
|
25
|
-
export declare function getMethods(): any;
|
|
26
|
-
export declare function on(event: 'request', listener: (action: string, params: any[], context: Context) => void): void;
|
|
27
|
-
export declare function on(event: 'success', listener: (action: string, params: any[], context: Context, result: ReturnsBody) => void): void;
|
|
28
|
-
export declare function on(event: 'fail', listener: (action: string, params: any[], context: Context, error: Error) => void): void;
|
|
29
|
-
/**
|
|
30
|
-
* Call an Function on RPC server
|
|
31
|
-
* @param action
|
|
32
|
-
* @param params
|
|
33
|
-
* @param context
|
|
34
|
-
* @returns
|
|
35
|
-
*/
|
|
36
|
-
export declare function call(action: string, params: any[], context: Context): Promise<ReturnsBody>;
|
|
37
|
-
export declare function execute(action: string, params: Array<any>, context: Context): Promise<any>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
+
export interface ReturnsBody {
|
|
6
|
+
traceId: string;
|
|
7
|
+
success: boolean;
|
|
8
|
+
body?: any;
|
|
9
|
+
error?: {
|
|
10
|
+
message: string;
|
|
11
|
+
stack: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare class Context {
|
|
15
|
+
traceId?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const asyncStore: AsyncLocalStorage<Context>;
|
|
18
|
+
export declare const eventHub: EventEmitter;
|
|
19
|
+
/**
|
|
20
|
+
* the kvMethods is all actions refs [has bind this]
|
|
21
|
+
*/
|
|
22
|
+
export declare const kvMethods: Map<string, Function>;
|
|
23
|
+
export declare const sourceKVMethods: Map<string, Function>;
|
|
24
|
+
export declare function setMethods(methods: any): void;
|
|
25
|
+
export declare function getMethods(): any;
|
|
26
|
+
export declare function on(event: 'request', listener: (action: string, params: any[], context: Context) => void): void;
|
|
27
|
+
export declare function on(event: 'success', listener: (action: string, params: any[], context: Context, result: ReturnsBody) => void): void;
|
|
28
|
+
export declare function on(event: 'fail', listener: (action: string, params: any[], context: Context, error: Error) => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* Call an Function on RPC server
|
|
31
|
+
* @param action
|
|
32
|
+
* @param params
|
|
33
|
+
* @param context
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function call(action: string, params: any[], context: Context): Promise<ReturnsBody>;
|
|
37
|
+
export declare function execute(action: string, params: Array<any>, context: Context): Promise<any>;
|
package/types/bin/argv.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare function getAllEnvArgs(): {
|
|
2
|
-
[x: string]: any;
|
|
3
|
-
};
|
|
4
|
-
export declare function getEnvArgs(names: string[]): {
|
|
5
|
-
[x: string]: any;
|
|
6
|
-
};
|
|
7
|
-
export declare function getEnvArg(name: string): any;
|
|
8
|
-
export declare function parseEnvArg(value: string): any;
|
|
1
|
+
export declare function getAllEnvArgs(): {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export declare function getEnvArgs(names: string[]): {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare function getEnvArg(name: string): any;
|
|
8
|
+
export declare function parseEnvArg(value: string): any;
|
package/types/bin/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function configure(): any;
|
|
1
|
+
export declare function configure(): any;
|
package/types/bin/proxyer.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function proxyGroup(groupDirectory: string, excludes?: any[]): void;
|
|
1
|
+
export declare function proxyGroup(groupDirectory: string, excludes?: any[]): void;
|
package/types/bin/register.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function registry(urls: string | string[]): Promise<void>;
|
|
1
|
+
export declare function registry(urls: string | string[]): Promise<void>;
|
package/types/bin/starter.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function startup(): Promise<void>;
|
|
1
|
+
export declare function startup(): Promise<void>;
|
package/types/index.d.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as app from './app';
|
|
3
|
-
import Module, { ModuleConfig } from './modules/module';
|
|
4
|
-
import Modules from './modules';
|
|
5
|
-
export { ReturnsBody } from './app';
|
|
6
|
-
export { Module, ModuleConfig };
|
|
7
|
-
export declare const modules: Modules;
|
|
8
|
-
export declare const asyncStore: import("async_hooks").AsyncLocalStorage<app.Context>, setMethods: typeof app.setMethods, getMethods: typeof app.getMethods, kvMethods: Map<string, Function>, sourceKVMethods: Map<string, Function>, call: typeof app.call, execute: typeof app.execute, on: typeof app.on;
|
|
9
|
-
export declare class Context extends app.Context {
|
|
10
|
-
sourceIP: string;
|
|
11
|
-
ip: string;
|
|
12
|
-
caller: string;
|
|
13
|
-
callerId: string;
|
|
14
|
-
connection?: RPCKeepAliveConnection;
|
|
15
|
-
toJSON?(): string;
|
|
16
|
-
}
|
|
17
|
-
export declare class Config {
|
|
18
|
-
[x: string]: any;
|
|
19
|
-
name: string;
|
|
20
|
-
host: string;
|
|
21
|
-
}
|
|
22
|
-
export declare const config: Config;
|
|
23
|
-
export declare function getConfig(): void;
|
|
24
|
-
export declare function setGenTraceIdFunction(fn: () => string): void;
|
|
25
|
-
/**
|
|
26
|
-
* 生成随机不重复id
|
|
27
|
-
*/
|
|
28
|
-
export declare function genTraceId(): string;
|
|
29
|
-
/**
|
|
30
|
-
* 获取链路跟踪上下文
|
|
31
|
-
*/
|
|
32
|
-
export declare function genContext(context?: Context): Context;
|
|
33
|
-
export declare function getContext(): Context;
|
|
34
|
-
export declare function serve(): Promise<void>;
|
|
35
|
-
export declare function stop(): Promise<void>;
|
|
36
|
-
export interface RPCConnectionAdapter {
|
|
37
|
-
rpc(connection: any, action: string, params: any[], context: Context): Promise<any>;
|
|
38
|
-
}
|
|
39
|
-
export interface RPCKeepAliveConnectionData {
|
|
40
|
-
/**
|
|
41
|
-
* 是否连接成功
|
|
42
|
-
*/
|
|
43
|
-
connected: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* 连接主机地址
|
|
46
|
-
*/
|
|
47
|
-
host: string;
|
|
48
|
-
/**
|
|
49
|
-
* 连接服务名称
|
|
50
|
-
*/
|
|
51
|
-
name: string;
|
|
52
|
-
/**
|
|
53
|
-
* 目标服务网络唯一ID
|
|
54
|
-
*/
|
|
55
|
-
id: string;
|
|
56
|
-
}
|
|
57
|
-
export declare class RPCKeepAliveConnection {
|
|
58
|
-
data: RPCKeepAliveConnectionData;
|
|
59
|
-
nativeConnection: any;
|
|
60
|
-
adapter: RPCConnectionAdapter;
|
|
61
|
-
constructor(adapter: RPCConnectionAdapter, nativeConnection: any, data?: RPCKeepAliveConnectionData);
|
|
62
|
-
}
|
|
63
|
-
export declare const keepAliveConnections: Map<string, Map<string, RPCKeepAliveConnection>>;
|
|
64
|
-
export declare function getKeepAliveConnections(name: string): Map<string, RPCKeepAliveConnection>;
|
|
65
|
-
export declare function getKeepAliveConnection(name: string, id: string): RPCKeepAliveConnection | null;
|
|
66
|
-
export declare function addKeepAliveConnection(connection: RPCKeepAliveConnection): void;
|
|
67
|
-
export declare function removeKeepAliveConnection(connection: RPCKeepAliveConnection): void;
|
|
68
|
-
export declare function removeKeepAliveConnection(name: string, id: string): void;
|
|
69
|
-
export declare function rpc(appName: string, action: string, params: any[], context?: Context): Promise<any>;
|
|
70
|
-
export declare function rpc(connection: RPCKeepAliveConnection, action: string, params: any[], context?: Context): Promise<any>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as app from './app';
|
|
3
|
+
import Module, { ModuleConfig } from './modules/module';
|
|
4
|
+
import Modules from './modules';
|
|
5
|
+
export { ReturnsBody } from './app';
|
|
6
|
+
export { Module, ModuleConfig };
|
|
7
|
+
export declare const modules: Modules;
|
|
8
|
+
export declare const asyncStore: import("async_hooks").AsyncLocalStorage<app.Context>, setMethods: typeof app.setMethods, getMethods: typeof app.getMethods, kvMethods: Map<string, Function>, sourceKVMethods: Map<string, Function>, call: typeof app.call, execute: typeof app.execute, on: typeof app.on;
|
|
9
|
+
export declare class Context extends app.Context {
|
|
10
|
+
sourceIP: string;
|
|
11
|
+
ip: string;
|
|
12
|
+
caller: string;
|
|
13
|
+
callerId: string;
|
|
14
|
+
connection?: RPCKeepAliveConnection;
|
|
15
|
+
toJSON?(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class Config {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
name: string;
|
|
20
|
+
host: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const config: Config;
|
|
23
|
+
export declare function getConfig(): void;
|
|
24
|
+
export declare function setGenTraceIdFunction(fn: () => string): void;
|
|
25
|
+
/**
|
|
26
|
+
* 生成随机不重复id
|
|
27
|
+
*/
|
|
28
|
+
export declare function genTraceId(): string;
|
|
29
|
+
/**
|
|
30
|
+
* 获取链路跟踪上下文
|
|
31
|
+
*/
|
|
32
|
+
export declare function genContext(context?: Context): Context;
|
|
33
|
+
export declare function getContext(): Context;
|
|
34
|
+
export declare function serve(): Promise<void>;
|
|
35
|
+
export declare function stop(): Promise<void>;
|
|
36
|
+
export interface RPCConnectionAdapter {
|
|
37
|
+
rpc(connection: any, action: string, params: any[], context: Context): Promise<any>;
|
|
38
|
+
}
|
|
39
|
+
export interface RPCKeepAliveConnectionData {
|
|
40
|
+
/**
|
|
41
|
+
* 是否连接成功
|
|
42
|
+
*/
|
|
43
|
+
connected: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 连接主机地址
|
|
46
|
+
*/
|
|
47
|
+
host: string;
|
|
48
|
+
/**
|
|
49
|
+
* 连接服务名称
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* 目标服务网络唯一ID
|
|
54
|
+
*/
|
|
55
|
+
id: string;
|
|
56
|
+
}
|
|
57
|
+
export declare class RPCKeepAliveConnection {
|
|
58
|
+
data: RPCKeepAliveConnectionData;
|
|
59
|
+
nativeConnection: any;
|
|
60
|
+
adapter: RPCConnectionAdapter;
|
|
61
|
+
constructor(adapter: RPCConnectionAdapter, nativeConnection: any, data?: RPCKeepAliveConnectionData);
|
|
62
|
+
}
|
|
63
|
+
export declare const keepAliveConnections: Map<string, Map<string, RPCKeepAliveConnection>>;
|
|
64
|
+
export declare function getKeepAliveConnections(name: string): Map<string, RPCKeepAliveConnection>;
|
|
65
|
+
export declare function getKeepAliveConnection(name: string, id: string): RPCKeepAliveConnection | null;
|
|
66
|
+
export declare function addKeepAliveConnection(connection: RPCKeepAliveConnection): void;
|
|
67
|
+
export declare function removeKeepAliveConnection(connection: RPCKeepAliveConnection): void;
|
|
68
|
+
export declare function removeKeepAliveConnection(name: string, id: string): void;
|
|
69
|
+
export declare function rpc(appName: string, action: string, params: any[], context?: Context): Promise<any>;
|
|
70
|
+
export declare function rpc(connection: RPCKeepAliveConnection, action: string, params: any[], context?: Context): Promise<any>;
|