oox 0.3.0-beta5 → 0.3.0-beta6
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/app.js +3 -1
- package/bin/loader.mjs +279 -0
- package/bin/starter.js +11 -24
- package/index.js +12 -4
- package/index.mjs +1 -0
- package/logger.js +20 -0
- package/modules/http/index.js +6 -0
- package/modules/index.js +4 -0
- package/package.json +8 -5
- package/types/app.d.ts +3 -0
- package/types/index.d.ts +6 -1
- package/types/logger.d.ts +3 -0
package/app.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.execute = exports.call = exports.on = exports.getMethods = exports.setMethods = exports.sourceKVMethods = exports.kvMethods = exports.eventHub = exports.asyncStore = exports.Context = void 0;
|
|
3
|
+
exports.execute = exports.call = exports.on = exports.getMethods = exports.setMethods = exports.sourceKVMethods = exports.kvMethods = exports.eventHub = exports.asyncStore = exports.Context = exports.logger = void 0;
|
|
4
4
|
const node_events_1 = require("node:events");
|
|
5
5
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
// import { wrappedActions, actionMiddlewares, middlewares } from './middleware'
|
|
8
|
+
exports.logger = require("./logger");
|
|
7
9
|
class Context {
|
|
8
10
|
// 请求溯源ID
|
|
9
11
|
traceId = '';
|
package/bin/loader.mjs
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs'
|
|
7
|
+
|
|
8
|
+
import { get as httpGet } from 'node:http'
|
|
9
|
+
|
|
10
|
+
import { get as httpsGet } from 'node:https'
|
|
11
|
+
|
|
12
|
+
import oox from '../index.mjs'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function generateRPCProxyScript ( name, attributes = [ ] ) {
|
|
17
|
+
|
|
18
|
+
let attrExports = ''
|
|
19
|
+
|
|
20
|
+
for ( const attr of attributes ) {
|
|
21
|
+
|
|
22
|
+
attrExports += `\nexport const ${attr} = proxyer.${attr}\n`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const script = `
|
|
26
|
+
import oox from 'oox'
|
|
27
|
+
function RPC_${name} ( ) { }
|
|
28
|
+
function dotCall ( name, action ) {
|
|
29
|
+
|
|
30
|
+
return new Proxy ( RPC_${name}, {
|
|
31
|
+
|
|
32
|
+
get ( target, key ) {
|
|
33
|
+
|
|
34
|
+
return dotCall ( name, action ? action + '.' + key : key )
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
has ( target, key ) { return true },
|
|
38
|
+
|
|
39
|
+
apply ( target, thisArg, args ) {
|
|
40
|
+
|
|
41
|
+
return oox.rpc ( name, action, args )
|
|
42
|
+
}
|
|
43
|
+
} )
|
|
44
|
+
}
|
|
45
|
+
const proxyer = dotCall ( '${name}', '' )
|
|
46
|
+
export default proxyer
|
|
47
|
+
${attrExports}
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
return script
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function generateRPCProxyURL ( name, attributes ) {
|
|
56
|
+
|
|
57
|
+
let searchText = ''
|
|
58
|
+
|
|
59
|
+
if ( attributes.length ) {
|
|
60
|
+
|
|
61
|
+
const search = new URLSearchParams ( )
|
|
62
|
+
|
|
63
|
+
for ( const attr of attributes ) {
|
|
64
|
+
|
|
65
|
+
search.append ( 'attr', attr )
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
searchText = '?' + search.toString ( )
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return `oox://rpc/${name}.mjs${searchText}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function isWebURL ( url ) {
|
|
77
|
+
|
|
78
|
+
return url && ( url.startsWith ( 'https://' ) || url.startsWith ( 'http://' ) )
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
function isOOXURL ( url ) {
|
|
84
|
+
|
|
85
|
+
return url && url.startsWith ( 'oox://' )
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* make ESModule support dynamic <export *> attributes import
|
|
92
|
+
* @param {string} importerSpecifier the import url
|
|
93
|
+
* @param {string} specifier parentURL
|
|
94
|
+
* @returns {string[]}
|
|
95
|
+
*/
|
|
96
|
+
function getImportAttributes ( importerSpecifier, specifier ) {
|
|
97
|
+
|
|
98
|
+
const attributes = [ ]
|
|
99
|
+
|
|
100
|
+
const contents = fs.readFileSync ( importerSpecifier, 'utf-8' )
|
|
101
|
+
|
|
102
|
+
// import * as xxx from "xxx"
|
|
103
|
+
const mergeImport = contents.match ( new RegExp ( `import.+\\*\\s*as\\s+(\\w+)\\s+from\\s*["']${specifier}["']` ) )
|
|
104
|
+
|
|
105
|
+
if ( mergeImport ) {
|
|
106
|
+
|
|
107
|
+
const mergeName = mergeImport [ 1 ]
|
|
108
|
+
|
|
109
|
+
const attributesIterator = contents.matchAll ( new RegExp ( `${mergeName}\\s*\\.\\s*(\\w+)`, 'g' ) )
|
|
110
|
+
|
|
111
|
+
for ( const caseItem of attributesIterator ) {
|
|
112
|
+
|
|
113
|
+
attributes.push ( caseItem [ 1 ] )
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// import { a, b, c } from 'xxx'
|
|
118
|
+
const attributeImport = contents.match ( new RegExp ( `import.+{(.+)}\\s*from\\s*["']${specifier}["']` ) )
|
|
119
|
+
|
|
120
|
+
if ( attributeImport ) {
|
|
121
|
+
|
|
122
|
+
const definedAttributes = attributeImport [ 1 ].split ( ',' ).map ( v => v.trim ( ) ).filter ( v => !v.startsWith ( 'default' ) )
|
|
123
|
+
|
|
124
|
+
attributes.push ( ...definedAttributes )
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return Array.from ( new Set ( attributes ) )
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {string} specifier
|
|
134
|
+
* @param {{
|
|
135
|
+
* conditions: string[],
|
|
136
|
+
* parentURL: string | undefined,
|
|
137
|
+
* }} context
|
|
138
|
+
* @param {Function} defaultResolve
|
|
139
|
+
* @returns {Promise<{ url: string }>}
|
|
140
|
+
*/
|
|
141
|
+
export async function resolve ( specifier, context, defaultResolve ) {
|
|
142
|
+
|
|
143
|
+
const defaultSpecifer = specifier
|
|
144
|
+
|
|
145
|
+
const { parentURL } = context
|
|
146
|
+
|
|
147
|
+
// HTTP & HTTPS
|
|
148
|
+
if ( isWebURL ( specifier ) ) {
|
|
149
|
+
|
|
150
|
+
return { url: specifier }
|
|
151
|
+
} else if ( isWebURL ( parentURL ) && ( specifier.startsWith ( '.' ) || specifier.startsWith ( '/' ) ) ) {
|
|
152
|
+
|
|
153
|
+
return { url: new URL ( specifier, parentURL ).href }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// OOX special alias for web package
|
|
157
|
+
if ( specifier === 'oox' ) {
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
url: 'file://' + path.resolve ( './node_modules/oox/index.mjs' )
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const { entryFile } = oox.config
|
|
165
|
+
|
|
166
|
+
// Relative specifier concat to absolute path
|
|
167
|
+
if ( specifier.startsWith ( '.' ) && parentURL ) {
|
|
168
|
+
|
|
169
|
+
specifier = path.posix.join ( path.dirname ( parentURL.replace ( 'file://', '' ) ), specifier )
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Windows pathname remove root sep
|
|
173
|
+
if ( os.platform ( ) === 'win32' && specifier.startsWith ( '/' ) ) {
|
|
174
|
+
|
|
175
|
+
specifier = specifier.replace ( '/', '' )
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// OOX RPC Proxy URL generation
|
|
179
|
+
if ( !specifier.endsWith ( entryFile.path ) && entryFile.group && specifier.startsWith ( entryFile.group ) ) {
|
|
180
|
+
|
|
181
|
+
const subSpecifier = specifier.slice ( entryFile.group.length )
|
|
182
|
+
|
|
183
|
+
const matchResult = subSpecifier.match ( /^\/?([\w-]+)(\/index)?(\.m?js)?$/ )
|
|
184
|
+
|
|
185
|
+
if ( matchResult ) {
|
|
186
|
+
|
|
187
|
+
const importerSpecifier = parentURL.replace ( os.platform ( ) === 'win32' ? /file:\/+/ : 'file://', '' )
|
|
188
|
+
|
|
189
|
+
const attributes = getImportAttributes ( importerSpecifier, defaultSpecifer )
|
|
190
|
+
|
|
191
|
+
return { url: generateRPCProxyURL ( matchResult [ 1 ], attributes ) }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// restore Windows specifier protocol
|
|
196
|
+
if ( os.platform ( ) === 'win32' && specifier.includes ( '/' ) && !specifier.startsWith ( 'file://' ) ) {
|
|
197
|
+
|
|
198
|
+
specifier = 'file://' + specifier
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return defaultResolve ( specifier, context, defaultResolve )
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @param {string} url
|
|
208
|
+
* @param {{
|
|
209
|
+
* format: string,
|
|
210
|
+
* }} context If resolve settled with a `format`, that value is included here.
|
|
211
|
+
* @param {Function} defaultLoad
|
|
212
|
+
* @returns {Promise<{
|
|
213
|
+
* format: string,
|
|
214
|
+
* source: string | ArrayBuffer | SharedArrayBuffer | Uint8Array,
|
|
215
|
+
* }>}
|
|
216
|
+
*/
|
|
217
|
+
export async function load ( url, context, defaultLoad ) {
|
|
218
|
+
|
|
219
|
+
if ( isWebURL ( url ) || isOOXURL ( url ) ) {
|
|
220
|
+
|
|
221
|
+
return getSource ( url, context, defaultLoad )
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return defaultLoad ( url, context, defaultLoad )
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
export function getFormat ( url, context, defaultGetFormat ) {
|
|
230
|
+
|
|
231
|
+
if ( isWebURL ( url ) || isOOXURL ( url ) ) {
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
format: 'module'
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return defaultGetFormat ( url, context, defaultGetFormat )
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
export function getSource ( url, context, defaultGetSource ) {
|
|
244
|
+
|
|
245
|
+
if ( isWebURL ( url ) ) {
|
|
246
|
+
|
|
247
|
+
const getMethod = url.startsWith ( 'https://' ) ? httpsGet : httpGet
|
|
248
|
+
|
|
249
|
+
return new Promise ( ( resolve, reject ) => getMethod ( url, res => {
|
|
250
|
+
let source = ''
|
|
251
|
+
res
|
|
252
|
+
.on ( 'data', chunk => source += chunk )
|
|
253
|
+
.on ( 'end', () => resolve ( { format: 'module', source } ) )
|
|
254
|
+
} ).on ( 'error', reject ) )
|
|
255
|
+
} else if ( isOOXURL ( url ) ) {
|
|
256
|
+
|
|
257
|
+
const mURL = new URL ( url )
|
|
258
|
+
|
|
259
|
+
if ( mURL.host === 'rpc' ) {
|
|
260
|
+
|
|
261
|
+
const regexp = /\/([\w-]+)\.mjs$/
|
|
262
|
+
|
|
263
|
+
const matchResult = mURL.pathname.match ( regexp )
|
|
264
|
+
|
|
265
|
+
// read all import attributes
|
|
266
|
+
const attributes = mURL.searchParams.getAll ( 'attr' )
|
|
267
|
+
|
|
268
|
+
const source = generateRPCProxyScript ( matchResult [ 1 ], attributes )
|
|
269
|
+
|
|
270
|
+
return { format: 'module', source }
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return defaultGetSource ( url, context, defaultGetSource )
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
process.on ( 'unhandledRejection', console.error )
|
package/bin/starter.js
CHANGED
|
@@ -24,10 +24,11 @@ function getEntryFile(env) {
|
|
|
24
24
|
var name = filename === 'index.js' && groupFullDirectory !== fullDirectory ? directory : filename.split('.js')[0];
|
|
25
25
|
return { name, path: fullPath, group: groupFullDirectory };
|
|
26
26
|
}
|
|
27
|
-
function loadEntry(name, entryPath) {
|
|
27
|
+
async function loadEntry(name, entryPath) {
|
|
28
28
|
oox.config.name = name;
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Typescript 4.7.3, not supported import() expression
|
|
30
|
+
const methods = await eval(`import('file://${entryPath.replace(/\\/g, '/')}')`);
|
|
31
|
+
oox.setMethods(methods.default || methods);
|
|
31
32
|
}
|
|
32
33
|
async function startup() {
|
|
33
34
|
// 加载环境变量
|
|
@@ -35,6 +36,10 @@ async function startup() {
|
|
|
35
36
|
Object.assign(oox.config, env);
|
|
36
37
|
// 获取服务入口地址
|
|
37
38
|
const entryFile = getEntryFile(env);
|
|
39
|
+
oox.config.entryFile = {
|
|
40
|
+
path: entryFile.path.replace(/\\/g, '/'),
|
|
41
|
+
group: entryFile.group.replace(/\\/g, '/'),
|
|
42
|
+
};
|
|
38
43
|
// 代理<服务间调用>
|
|
39
44
|
if (env.group) {
|
|
40
45
|
const excludes = [entryFile.name];
|
|
@@ -43,28 +48,10 @@ async function startup() {
|
|
|
43
48
|
(0, proxyer_1.proxyGroup)(entryFile.group, excludes);
|
|
44
49
|
}
|
|
45
50
|
// 加载服务
|
|
46
|
-
loadEntry(entryFile.name, entryFile.path);
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
env.port = 0;
|
|
51
|
+
await loadEntry(entryFile.name, entryFile.path);
|
|
52
|
+
// 模块配置
|
|
53
|
+
oox.modules.setConfig(oox.config);
|
|
50
54
|
const httpConfig = oox.modules.builtins.http.config, socketioConfig = socketio.config;
|
|
51
|
-
if ('number' === typeof env.port) {
|
|
52
|
-
httpConfig.port = socketioConfig.port = env.port;
|
|
53
|
-
}
|
|
54
|
-
if (env.origin)
|
|
55
|
-
httpConfig.origin = env.origin;
|
|
56
|
-
if ('http' in env) {
|
|
57
|
-
if (env.http)
|
|
58
|
-
Object.assign(httpConfig, env.http);
|
|
59
|
-
else
|
|
60
|
-
httpConfig.disabled = true;
|
|
61
|
-
}
|
|
62
|
-
if ('socketio' in env) {
|
|
63
|
-
if (env.socketio)
|
|
64
|
-
Object.assign(socketioConfig, env.socketio);
|
|
65
|
-
else
|
|
66
|
-
socketioConfig.disabled = true;
|
|
67
|
-
}
|
|
68
55
|
// 服务启动
|
|
69
56
|
await oox.serve();
|
|
70
57
|
console.log();
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc = exports.removeKeepAliveConnection = exports.addKeepAliveConnection = exports.getKeepAliveConnection = exports.getKeepAliveConnections = exports.keepAliveConnections = exports.RPCKeepAliveConnection = exports.stop = exports.serve = exports.getContext = exports.genContext = exports.genTraceId = exports.setGenTraceIdFunction = exports.
|
|
3
|
+
exports.rpc = exports.removeKeepAliveConnection = exports.addKeepAliveConnection = exports.getKeepAliveConnection = exports.getKeepAliveConnections = exports.keepAliveConnections = exports.RPCKeepAliveConnection = exports.stop = exports.serve = exports.getContext = exports.genContext = exports.genTraceId = exports.setGenTraceIdFunction = exports.config = exports.Config = exports.Context = exports.on = exports.execute = exports.call = exports.sourceKVMethods = exports.kvMethods = exports.getMethods = exports.setMethods = exports.asyncStore = exports.modules = exports.ModuleConfig = exports.Module = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const app = require("./app");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
@@ -31,14 +31,22 @@ exports.Context = Context;
|
|
|
31
31
|
class Config {
|
|
32
32
|
// 服务名称
|
|
33
33
|
name = 'local';
|
|
34
|
+
// 启动文件
|
|
35
|
+
entryFile = {
|
|
36
|
+
// 启动文件路径
|
|
37
|
+
path: '',
|
|
38
|
+
// 服务列表路径
|
|
39
|
+
group: '',
|
|
40
|
+
};
|
|
34
41
|
// 主机地址
|
|
35
42
|
host = (0, utils_1.getIPAddress)(4)[0];
|
|
43
|
+
// 默认监听端口
|
|
44
|
+
port = 0;
|
|
45
|
+
// 默认跨域设置
|
|
46
|
+
origin = '';
|
|
36
47
|
}
|
|
37
48
|
exports.Config = Config;
|
|
38
49
|
exports.config = new Config();
|
|
39
|
-
function getConfig() {
|
|
40
|
-
}
|
|
41
|
-
exports.getConfig = getConfig;
|
|
42
50
|
let genTraceIdFunction = () => (0, node_crypto_1.randomUUID)();
|
|
43
51
|
function setGenTraceIdFunction(fn) {
|
|
44
52
|
genTraceIdFunction = fn;
|
package/index.mjs
CHANGED
package/logger.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.error = exports.warning = exports.info = void 0;
|
|
4
|
+
const app_1 = require("./app");
|
|
5
|
+
function log(tag, ...msgs) {
|
|
6
|
+
const context = app_1.asyncStore.getStore();
|
|
7
|
+
app_1.eventHub.emit('log', context, { tag, msgs });
|
|
8
|
+
}
|
|
9
|
+
function info(...msgs) {
|
|
10
|
+
return log('info', ...msgs);
|
|
11
|
+
}
|
|
12
|
+
exports.info = info;
|
|
13
|
+
function warning(...msgs) {
|
|
14
|
+
return log('warning', ...msgs);
|
|
15
|
+
}
|
|
16
|
+
exports.warning = warning;
|
|
17
|
+
function error(...msgs) {
|
|
18
|
+
return log('error', ...msgs);
|
|
19
|
+
}
|
|
20
|
+
exports.error = error;
|
package/modules/http/index.js
CHANGED
|
@@ -20,6 +20,12 @@ class HTTPModule extends module_1.default {
|
|
|
20
20
|
server = null;
|
|
21
21
|
setConfig(config) {
|
|
22
22
|
Object.assign(this.config, config);
|
|
23
|
+
if (!config.hasOwnProperty('port')) {
|
|
24
|
+
this.config.port = oox.config.port;
|
|
25
|
+
}
|
|
26
|
+
if (!config.hasOwnProperty('origin')) {
|
|
27
|
+
this.config.origin = oox.config.origin;
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
getConfig() {
|
|
25
31
|
return this.config;
|
package/modules/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oox",
|
|
3
|
-
"version": "0.3.0-
|
|
3
|
+
"version": "0.3.0-beta6",
|
|
4
4
|
"description": "Graceful NodeJS distributed application solution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http",
|
|
7
7
|
"websocket",
|
|
8
8
|
"socket.io",
|
|
9
9
|
"rpc",
|
|
10
|
+
"framework",
|
|
10
11
|
"microservice",
|
|
11
12
|
"distributed",
|
|
12
13
|
"tracing"
|
|
@@ -15,9 +16,11 @@
|
|
|
15
16
|
"main": "index.js",
|
|
16
17
|
"types": "types/index.d.ts",
|
|
17
18
|
"exports": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./index.mjs",
|
|
21
|
+
"require": "./index.js"
|
|
22
|
+
},
|
|
23
|
+
"./loader": "./bin/loader.mjs"
|
|
21
24
|
},
|
|
22
25
|
"bin": {
|
|
23
26
|
"oox": "bin/cli.js"
|
|
@@ -26,7 +29,7 @@
|
|
|
26
29
|
"homepage": "https://github.com/lipingruan/oox",
|
|
27
30
|
"license": "MIT",
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@oox/module-socketio": "
|
|
32
|
+
"@oox/module-socketio": "../oox-module-socketio/dist/",
|
|
30
33
|
"chalk": "^4.1.0"
|
|
31
34
|
},
|
|
32
35
|
"engines": {
|
package/types/app.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
+
export * as logger from './logger';
|
|
5
6
|
export interface ReturnsBody {
|
|
6
7
|
traceId: string;
|
|
7
8
|
success: boolean;
|
|
@@ -12,6 +13,7 @@ export interface ReturnsBody {
|
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
export declare class Context {
|
|
16
|
+
[x: string]: any;
|
|
15
17
|
traceId?: string;
|
|
16
18
|
}
|
|
17
19
|
export declare const asyncStore: AsyncLocalStorage<Context>;
|
|
@@ -26,6 +28,7 @@ export declare function getMethods(): any;
|
|
|
26
28
|
export declare function on(event: 'request', listener: (action: string, params: any[], context: Context) => void): void;
|
|
27
29
|
export declare function on(event: 'success', listener: (action: string, params: any[], context: Context, result: ReturnsBody) => void): void;
|
|
28
30
|
export declare function on(event: 'fail', listener: (action: string, params: any[], context: Context, error: Error) => void): void;
|
|
31
|
+
export declare function on(event: 'log', listener: (context: Context, ...msgs: any[]) => void): void;
|
|
29
32
|
/**
|
|
30
33
|
* Call an Function on RPC server
|
|
31
34
|
* @param action
|
package/types/index.d.ts
CHANGED
|
@@ -17,10 +17,15 @@ export declare class Context extends app.Context {
|
|
|
17
17
|
export declare class Config {
|
|
18
18
|
[x: string]: any;
|
|
19
19
|
name: string;
|
|
20
|
+
entryFile: {
|
|
21
|
+
path: string;
|
|
22
|
+
group: string;
|
|
23
|
+
};
|
|
20
24
|
host: string;
|
|
25
|
+
port: number;
|
|
26
|
+
origin: string;
|
|
21
27
|
}
|
|
22
28
|
export declare const config: Config;
|
|
23
|
-
export declare function getConfig(): void;
|
|
24
29
|
export declare function setGenTraceIdFunction(fn: () => string): void;
|
|
25
30
|
/**
|
|
26
31
|
* 生成随机不重复id
|