melo-example-robot 1.7.6
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 +22 -0
- package/README.md +6 -0
- package/app/script/ByteArray.ts +1188 -0
- package/app/script/Client.ts +93 -0
- package/app/script/MeloForEgret.ts +911 -0
- package/app.ts +34 -0
- package/dist/app/config/dev/config.json +3 -0
- package/dist/app/config/env.json +4 -0
- package/dist/app/config/prod/config.json +3 -0
- package/dist/app/script/ByteArray.js +1103 -0
- package/dist/app/script/Client.js +83 -0
- package/dist/app/script/MeloForEgret.js +741 -0
- package/dist/app.js +33 -0
- package/dist/http.js +66 -0
- package/dist/nodejs-ts-client/cacheClass.js +19 -0
- package/dist/nodejs-ts-client/client.js +396 -0
- package/dist/nodejs-ts-client/logger.service.js +59 -0
- package/dist/nodejs-ts-client/my.logger.js +49 -0
- package/http.ts +64 -0
- package/nodejs-ts-client/README.md +3 -0
- package/nodejs-ts-client/cacheClass.ts +21 -0
- package/nodejs-ts-client/client.ts +475 -0
- package/nodejs-ts-client/logger.service.ts +107 -0
- package/nodejs-ts-client/my.logger.ts +61 -0
- package/package.json +35 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as clc from 'cli-color';
|
|
2
|
+
|
|
3
|
+
declare const process;
|
|
4
|
+
|
|
5
|
+
export interface LoggerService {
|
|
6
|
+
log(message: string): void;
|
|
7
|
+
error(message: string, trace: string): void;
|
|
8
|
+
warn(message: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Logger implements LoggerService {
|
|
12
|
+
private static prevTimestamp = null;
|
|
13
|
+
private static logger: typeof Logger | LoggerService = Logger;
|
|
14
|
+
|
|
15
|
+
private static readonly yellow = clc.xterm(3);
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
private readonly context: string,
|
|
19
|
+
private readonly isTimeDiffEnabled = false,
|
|
20
|
+
) { }
|
|
21
|
+
|
|
22
|
+
log(message: string) {
|
|
23
|
+
const { logger } = Logger;
|
|
24
|
+
(logger as typeof Logger).log.call(
|
|
25
|
+
logger,
|
|
26
|
+
message,
|
|
27
|
+
this.context,
|
|
28
|
+
this.isTimeDiffEnabled,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
error(message: string, trace = '') {
|
|
33
|
+
const { logger } = Logger;
|
|
34
|
+
(logger as typeof Logger).error.call(
|
|
35
|
+
logger,
|
|
36
|
+
message,
|
|
37
|
+
trace,
|
|
38
|
+
this.context,
|
|
39
|
+
this.isTimeDiffEnabled,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
warn(message: string) {
|
|
44
|
+
const { logger } = Logger;
|
|
45
|
+
(logger as typeof Logger).warn.call(
|
|
46
|
+
logger,
|
|
47
|
+
message,
|
|
48
|
+
this.context,
|
|
49
|
+
this.isTimeDiffEnabled,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static overrideLogger(logger: LoggerService) {
|
|
54
|
+
this.logger = logger;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
static log(message: string, context = '', isTimeDiffEnabled = true) {
|
|
59
|
+
this.printMessage(message, clc.green, context, isTimeDiffEnabled);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static error(
|
|
63
|
+
message: string,
|
|
64
|
+
trace = '',
|
|
65
|
+
context = '',
|
|
66
|
+
isTimeDiffEnabled = true,
|
|
67
|
+
) {
|
|
68
|
+
this.printMessage(message, clc.red, context, isTimeDiffEnabled);
|
|
69
|
+
this.printStackTrace(trace);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static warn(message: string, context = '', isTimeDiffEnabled = true) {
|
|
73
|
+
this.printMessage(message, clc.yellow, context, isTimeDiffEnabled);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private static printMessage(
|
|
77
|
+
message: string,
|
|
78
|
+
color: (msg: string) => string,
|
|
79
|
+
context: string = '',
|
|
80
|
+
isTimeDiffEnabled?: boolean,
|
|
81
|
+
) {
|
|
82
|
+
|
|
83
|
+
process.stdout.write(color(`${process.pid} - `));
|
|
84
|
+
process.stdout.write(`${new Date().toLocaleString()} `);
|
|
85
|
+
process.stdout.write(this.yellow(`[${context}] `));
|
|
86
|
+
process.stdout.write(color(message));
|
|
87
|
+
|
|
88
|
+
this.printTimestamp(isTimeDiffEnabled);
|
|
89
|
+
process.stdout.write(`\n`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private static printTimestamp(isTimeDiffEnabled?: boolean) {
|
|
93
|
+
const includeTimestamp = Logger.prevTimestamp && isTimeDiffEnabled;
|
|
94
|
+
if (includeTimestamp) {
|
|
95
|
+
process.stdout.write(
|
|
96
|
+
this.yellow(` +${Date.now() - Logger.prevTimestamp}ms`),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
Logger.prevTimestamp = Date.now();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private static printStackTrace(trace: string) {
|
|
103
|
+
|
|
104
|
+
process.stdout.write(trace);
|
|
105
|
+
process.stdout.write(`\n`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as util from 'util';
|
|
2
|
+
import { Logger } from './logger.service';
|
|
3
|
+
|
|
4
|
+
export const enum MyLogLevel {
|
|
5
|
+
ERROR = 1,
|
|
6
|
+
WARN = 2,
|
|
7
|
+
INFO = 3,
|
|
8
|
+
DEBUG = 4
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class MyLogger extends Logger {
|
|
13
|
+
constructor(context: string,
|
|
14
|
+
isTimeDiffEnabled = false,
|
|
15
|
+
) {
|
|
16
|
+
super(MyLogger.LogPrefix + context, isTimeDiffEnabled);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static LogPrefix: string = '';
|
|
20
|
+
public static level = MyLogLevel.DEBUG;
|
|
21
|
+
|
|
22
|
+
log(message, ...args) {
|
|
23
|
+
if (MyLogger.level >= MyLogLevel.INFO) {
|
|
24
|
+
message = 'LOG<><>' + message;
|
|
25
|
+
message = util.format(message, ...args);
|
|
26
|
+
super.log(message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
info(message, ...args) {
|
|
31
|
+
if (MyLogger.level >= MyLogLevel.INFO) {
|
|
32
|
+
message = 'INFO<><>' + message;
|
|
33
|
+
message = util.format(message, ...args);
|
|
34
|
+
super.log(message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
debug(message, ...args) {
|
|
39
|
+
if (MyLogger.level >= MyLogLevel.DEBUG) {
|
|
40
|
+
message = 'DEBUG<><>' + message;
|
|
41
|
+
message = util.format(message, ...args);
|
|
42
|
+
super.warn(message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
error(message, ...args) {
|
|
47
|
+
if (MyLogger.level >= MyLogLevel.ERROR) {
|
|
48
|
+
message = 'ERROR<><>' + message;
|
|
49
|
+
message = util.format(message, ...args);
|
|
50
|
+
super.error(message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
warn(message, ...args) {
|
|
55
|
+
if (MyLogger.level >= MyLogLevel.WARN) {
|
|
56
|
+
message = 'WARN<><>' + message;
|
|
57
|
+
message = util.format(message, ...args);
|
|
58
|
+
super.warn(message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "melo-example-robot",
|
|
3
|
+
"version": "1.7.6",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A distributed load test framework",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/node-melo/melo"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=12.9.0"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"start": "yarn run build && cd dist && node app",
|
|
16
|
+
"test": "yarn run build",
|
|
17
|
+
"cov": "nyc mocha",
|
|
18
|
+
"ci": "yarn run test",
|
|
19
|
+
"gen-api-ref": "node ../../node_modules/typedoc/bin/typedoc --mode file --hideGenerator --excludeExternals --ignoreCompilerErrors --out ../../run/site/public/api-reference/melo-loader lib/"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@bigtyphoon/melo-protobuf": "^1.7.6",
|
|
23
|
+
"@bigtyphoon/melo-protocol": "^1.7.6",
|
|
24
|
+
"@bigtyphoon/melo-robot": "^1.7.6",
|
|
25
|
+
"@types/node": "^16.3.3",
|
|
26
|
+
"@types/ws": "^8.5.4",
|
|
27
|
+
"cli-color": "^2.0.0",
|
|
28
|
+
"ws": "^8.12.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tslint": "^6.1.3",
|
|
32
|
+
"typescript": "^4.3.5"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "7dfd3ca78ed6b051e34da595269efb623cd58d1b"
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"skipLibCheck": true,
|
|
4
|
+
// types option has been previously configured
|
|
5
|
+
"types": [
|
|
6
|
+
// add node as an option
|
|
7
|
+
"node"
|
|
8
|
+
],
|
|
9
|
+
"module": "commonjs", //指定生成哪个模块系统代码
|
|
10
|
+
"target": "es2017",
|
|
11
|
+
"lib": [
|
|
12
|
+
"es2015",
|
|
13
|
+
"es2016",
|
|
14
|
+
"esnext.asynciterable"
|
|
15
|
+
],
|
|
16
|
+
"noImplicitAny": false, //在表达式和声明上有隐含的'any'类型时报错。
|
|
17
|
+
"noImplicitThis": false,
|
|
18
|
+
"inlineSourceMap": true,
|
|
19
|
+
"newLine": "lf", // 统一跨平台下编译文件的换行符
|
|
20
|
+
|
|
21
|
+
"rootDirs": ["."], //仅用来控制输出的目录结构--outDir。
|
|
22
|
+
"outDir": "./dist", //重定向输出目录。
|
|
23
|
+
"experimentalDecorators": true,
|
|
24
|
+
"emitDecoratorMetadata": true,
|
|
25
|
+
"moduleResolution": "node"
|
|
26
|
+
},
|
|
27
|
+
"include": [
|
|
28
|
+
"./**/*.ts"
|
|
29
|
+
],
|
|
30
|
+
"exclude": [
|
|
31
|
+
"./dist/**/*.*"
|
|
32
|
+
]
|
|
33
|
+
}
|