agora-foundation 3.8.2 → 3.9.0-alpha
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/lib/decorator/log/handler.d.ts +1 -1
- package/lib/decorator/log/handler.js +57 -64
- package/lib/decorator/log/index.d.ts +26 -1
- package/lib/decorator/log/index.js +50 -5
- package/lib/decorator/log/log-serializer.d.ts +1 -1
- package/lib/decorator/log/log-serializer.js +15 -2
- package/lib/decorator/proxy.d.ts +1 -1
- package/lib/decorator/proxy.js +16 -16
- package/lib/decorator/type.d.ts +3 -2
- package/lib/decorator/type.js +2 -2
- package/lib/utilities/desc-type.d.ts +1 -0
- package/lib/utilities/desc-type.js +1 -1
- package/lib/utilities/env.d.ts +2 -1
- package/lib/utilities/env.js +1 -0
- package/lib/utilities/{agora-error.d.ts → error/agora-error.d.ts} +5 -11
- package/lib/utilities/error/agora-error.js +148 -0
- package/lib/utilities/error/error-code.d.ts +69 -0
- package/lib/utilities/error/error-code.js +81 -0
- package/lib/utilities/logger.d.ts +13 -1
- package/lib/utilities/logger.js +103 -13
- package/lib/utilities/observable.js +1 -0
- package/lib/utilities/package-info.d.ts +8 -0
- package/lib/utilities/package-info.js +85 -0
- package/lib/utilities/regex.d.ts +1 -0
- package/lib/utilities/regex.js +14 -0
- package/lib/utilities/tools.d.ts +28 -0
- package/lib/utilities/tools.js +154 -0
- package/lib-es/decorator/log/handler.js +56 -64
- package/lib-es/decorator/log/index.js +49 -4
- package/lib-es/decorator/log/log-serializer.js +15 -2
- package/lib-es/decorator/proxy.js +16 -16
- package/lib-es/decorator/type.js +2 -2
- package/lib-es/utilities/desc-type.js +1 -1
- package/lib-es/utilities/env.js +1 -0
- package/lib-es/utilities/error/agora-error.js +140 -0
- package/lib-es/utilities/error/error-code.js +74 -0
- package/lib-es/utilities/logger.js +102 -12
- package/lib-es/utilities/observable.js +1 -0
- package/lib-es/utilities/package-info.js +78 -0
- package/lib-es/utilities/regex.js +7 -0
- package/lib-es/utilities/tools.js +144 -0
- package/package.json +2 -2
- package/lib/utilities/agora-error.js +0 -128
- package/lib-es/utilities/agora-error.js +0 -120
|
@@ -4,5 +4,5 @@ import { InvocationEvent } from '../type';
|
|
|
4
4
|
type LoggerHolder = {
|
|
5
5
|
logger: Logger;
|
|
6
6
|
};
|
|
7
|
-
export declare const createLogHandler: (holder: LoggerHolder) => (evt: InvocationEvent) => Result;
|
|
7
|
+
export declare const createLogHandler: (holder: LoggerHolder, isErrorCodeByReturnValue?: boolean) => (evt: InvocationEvent) => Result;
|
|
8
8
|
export {};
|
|
@@ -1,84 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.createLogHandler = void 0;
|
|
8
9
|
require("core-js/modules/es.array.concat.js");
|
|
9
|
-
require("core-js/modules/es.date.
|
|
10
|
-
require("
|
|
10
|
+
require("core-js/modules/es.date.now.js");
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
12
|
var _interceptor = require("../../utilities/interceptor");
|
|
12
|
-
var _misc = require("../../utilities/misc");
|
|
13
13
|
var _type = require("../type");
|
|
14
14
|
var _logSerializer = require("./log-serializer");
|
|
15
|
-
var
|
|
16
|
-
|
|
15
|
+
var InvocationEventTypeToString = (0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, _type.InvocationEventType.API_CALL, '[API Call]'), _type.InvocationEventType.API_RETURN, '[API Return]');
|
|
16
|
+
|
|
17
|
+
// 方法返回错误码时对应的描述
|
|
18
|
+
var ReasonCodeToString = (0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, -1, 'FAILED'), 0, 'SUCCESS');
|
|
19
|
+
var formatLogHead = function formatLogHead(identifier, tag, args, argsNames) {
|
|
20
|
+
var elapsed = Date.now() - identifier.startTs;
|
|
21
|
+
var parameters = '[parameters: []]';
|
|
22
|
+
var duration = "[duration: ".concat(elapsed, "ms]");
|
|
17
23
|
if (args !== null && args !== void 0 && args.length) {
|
|
18
|
-
|
|
24
|
+
parameters = "[parameters: [".concat((0, _logSerializer.serializeArgs)(args, argsNames), "]]");
|
|
19
25
|
}
|
|
20
|
-
return "".concat(identifier.methodName, "
|
|
26
|
+
return "".concat(identifier.methodName, ": ").concat(tag, " ").concat(parameters, " ").concat(duration);
|
|
21
27
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// return `${identifier.methodName} [API Call]${msg}[elapsed: ${elapsed}ms]`;
|
|
43
|
-
// };
|
|
44
|
-
|
|
45
|
-
var createLogHandler = exports.createLogHandler = function createLogHandler(holder) {
|
|
28
|
+
var formatLogReturn = function formatLogReturn(returnValue) {
|
|
29
|
+
return "[message: { return: ".concat((0, _logSerializer.serialize)(returnValue), " }]");
|
|
30
|
+
};
|
|
31
|
+
var formatLogReason = function formatLogReason(reasonCode) {
|
|
32
|
+
return "[message: { reason: ".concat(reasonCode, ": ").concat(ReasonCodeToString[reasonCode] || 'UNKNOWN', " }]");
|
|
33
|
+
};
|
|
34
|
+
var formatLogError = function formatLogError(error) {
|
|
35
|
+
return "[message: { error: { code: ".concat(error.code, ", message: ").concat(error.message, " } }]");
|
|
36
|
+
};
|
|
37
|
+
var printReturnOrReason = function printReturnOrReason(logger, returnValue, getMsg, isShowReasonCode) {
|
|
38
|
+
if (isShowReasonCode && typeof returnValue === 'number' && returnValue !== 0) {
|
|
39
|
+
var msgBody = " ".concat(formatLogReason(returnValue));
|
|
40
|
+
logger.warn(getMsg(msgBody));
|
|
41
|
+
} else {
|
|
42
|
+
var _msgBody = " ".concat(formatLogReturn(returnValue));
|
|
43
|
+
logger.info(getMsg(_msgBody));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var createLogHandler = exports.createLogHandler = function createLogHandler(holder, isErrorCodeByReturnValue) {
|
|
46
47
|
return function (evt) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
evt
|
|
50
|
-
evt.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// evt.error,
|
|
69
|
-
// );
|
|
70
|
-
// if (evt.error) {
|
|
71
|
-
// holder.logger.error(msg);
|
|
72
|
-
// } else {
|
|
73
|
-
// holder.logger.info(msg);
|
|
74
|
-
// }
|
|
75
|
-
|
|
48
|
+
var _evt$arguments, _evt$argumentNames;
|
|
49
|
+
var msgHead = formatLogHead({
|
|
50
|
+
className: evt["class"],
|
|
51
|
+
methodName: evt.method,
|
|
52
|
+
startTs: evt.context.start,
|
|
53
|
+
isThenable: evt.context.isThenable
|
|
54
|
+
}, InvocationEventTypeToString[evt.type], (_evt$arguments = evt.arguments) !== null && _evt$arguments !== void 0 ? _evt$arguments : [], (_evt$argumentNames = evt.argumentNames) !== null && _evt$argumentNames !== void 0 ? _evt$argumentNames : []);
|
|
55
|
+
var msgFoot = " [traceId: ".concat(evt.context.traceId, "]");
|
|
56
|
+
var getMsg = function getMsg() {
|
|
57
|
+
var msgBody = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
58
|
+
return "".concat(msgHead).concat(msgBody).concat(msgFoot);
|
|
59
|
+
};
|
|
60
|
+
if (evt.type === _type.InvocationEventType.API_CALL) {
|
|
61
|
+
if (evt.context.isThenable === true) {
|
|
62
|
+
// 异步方法只打印调用信息, 在 API_RETURN 时打印返回值等信息
|
|
63
|
+
holder.logger.info(getMsg());
|
|
64
|
+
} else {
|
|
65
|
+
// 同步方法的打印内容包含返回值, 错误码等信息(如果有的话)
|
|
66
|
+
printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
|
|
67
|
+
}
|
|
68
|
+
} else if (evt.type === _type.InvocationEventType.API_RETURN) {
|
|
76
69
|
if (evt.error) {
|
|
77
|
-
var
|
|
78
|
-
holder.logger.error(
|
|
70
|
+
var msgBody = " ".concat(formatLogError(evt.error));
|
|
71
|
+
holder.logger.error(getMsg(msgBody));
|
|
79
72
|
} else {
|
|
80
|
-
|
|
81
|
-
holder.logger
|
|
73
|
+
// 异步方法在此处打印返回值, 错误码等信息(如果有的话)
|
|
74
|
+
printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
return _interceptor.Result.CONTINUE;
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
type ClassMethodDecorator = (originalMethod: any, context: ClassMethodDecoratorContext) => undefined;
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* 函数入参使用参数范型, 支持以下三种用法:
|
|
5
|
+
* 1. 直接作为装饰器使用: `@trace method() {}`
|
|
6
|
+
* 2. 作为工厂函数使用, 支持传入参数名称数组, 标识返回值是否是错误码(可选), 返回装饰器函数 `@trace(['param1', 'param2'], bolean?)`
|
|
7
|
+
* 3. 作为工厂函数使用, 仅标识返回值是否是错误码, 返回装饰器函数 `@trace(boolean)`
|
|
8
|
+
* @example
|
|
9
|
+
* `@trace method() {}`
|
|
10
|
+
* `@trace(['name1', 'name2']) method(name1: string, name2: number) {}`
|
|
11
|
+
* `@trace(['name1', 'name2'], true) method(name1: string, name2: number) {}`
|
|
12
|
+
* `@trace(true) method() {}`
|
|
13
|
+
*/
|
|
14
|
+
declare function trace(originalMethod: any, context: ClassMethodDecoratorContext): undefined;
|
|
15
|
+
/**
|
|
16
|
+
* @description 仅标识返回值是否是错误码, 返回装饰器函数 `@trace(boolean)`
|
|
17
|
+
* @param isErrorCodeByReturnValue - 返回值是否是错误码
|
|
18
|
+
*/
|
|
19
|
+
declare function trace(isErrorCodeByReturnValue: boolean): ClassMethodDecorator;
|
|
20
|
+
/**
|
|
21
|
+
* @description 作为工厂函数使用, 支持传入参数名称数组, 标识返回值是否是错误码(可选), 返回装饰器函数 `@trace(['param1', 'param2'], bolean?)`
|
|
22
|
+
* @param paramNames - 参数名称数组
|
|
23
|
+
* @param [isErrorCodeByReturnValue] - 返回值是否是错误码(可选)
|
|
24
|
+
*/
|
|
25
|
+
declare function trace(paramNames: string[], isErrorCodeByReturnValue?: boolean): ClassMethodDecorator;
|
|
26
|
+
export { trace };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
|
-
exports.trace =
|
|
8
|
+
exports.trace = trace;
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
8
10
|
require("core-js/modules/es.function.name.js");
|
|
9
11
|
var _proxy = require("../proxy");
|
|
10
12
|
var _handler = require("./handler");
|
|
@@ -14,7 +16,7 @@ var _logger = require("../../logger");
|
|
|
14
16
|
* @param targetOrProto The class or prototype that the method belongs to.
|
|
15
17
|
* @param methodName The name of the method.
|
|
16
18
|
*/
|
|
17
|
-
var _trace = function _trace(originalMethod, context) {
|
|
19
|
+
var _trace = function _trace(originalMethod, context, paramNames, isErrorCodeByReturnValue) {
|
|
18
20
|
var methodName = String(context.name);
|
|
19
21
|
if (context.kind === 'method') {
|
|
20
22
|
context.addInitializer(function () {
|
|
@@ -26,9 +28,52 @@ var _trace = function _trace(originalMethod, context) {
|
|
|
26
28
|
if (!this.logger) {
|
|
27
29
|
this.logger = logger;
|
|
28
30
|
}
|
|
29
|
-
var handler = (0, _handler.createLogHandler)(this);
|
|
30
|
-
this[context.name] = (0, _proxy.proxyMethod)(this[context.name], this, methodName, handler);
|
|
31
|
+
var handler = (0, _handler.createLogHandler)(this, isErrorCodeByReturnValue);
|
|
32
|
+
this[context.name] = (0, _proxy.proxyMethod)(this[context.name], this, methodName, handler, paramNames);
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
|
-
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description
|
|
39
|
+
* 函数入参使用参数范型, 支持以下三种用法:
|
|
40
|
+
* 1. 直接作为装饰器使用: `@trace method() {}`
|
|
41
|
+
* 2. 作为工厂函数使用, 支持传入参数名称数组, 标识返回值是否是错误码(可选), 返回装饰器函数 `@trace(['param1', 'param2'], bolean?)`
|
|
42
|
+
* 3. 作为工厂函数使用, 仅标识返回值是否是错误码, 返回装饰器函数 `@trace(boolean)`
|
|
43
|
+
* @example
|
|
44
|
+
* `@trace method() {}`
|
|
45
|
+
* `@trace(['name1', 'name2']) method(name1: string, name2: number) {}`
|
|
46
|
+
* `@trace(['name1', 'name2'], true) method(name1: string, name2: number) {}`
|
|
47
|
+
* `@trace(true) method() {}`
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description 仅标识返回值是否是错误码, 返回装饰器函数 `@trace(boolean)`
|
|
52
|
+
* @param isErrorCodeByReturnValue - 返回值是否是错误码
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description 作为工厂函数使用, 支持传入参数名称数组, 标识返回值是否是错误码(可选), 返回装饰器函数 `@trace(['param1', 'param2'], bolean?)`
|
|
57
|
+
* @param paramNames - 参数名称数组
|
|
58
|
+
* @param [isErrorCodeByReturnValue] - 返回值是否是错误码(可选)
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
function trace() {
|
|
62
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
63
|
+
args[_key] = arguments[_key];
|
|
64
|
+
}
|
|
65
|
+
if (args.length === 2 && (0, _typeof2["default"])(args[1]) === 'object') {
|
|
66
|
+
// 直接作为装饰器使用
|
|
67
|
+
_trace(args[0], args[1]);
|
|
68
|
+
} else if (args.length === 1 && typeof args[0] === 'boolean') {
|
|
69
|
+
// 作为工厂函数使用, 仅标识返回值是否是错误码
|
|
70
|
+
return function (originalMethod, context) {
|
|
71
|
+
_trace(originalMethod, context, undefined, args[0]);
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
// 作为工厂函数使用, 支持传入参数名称数组, 标识返回值是否是错误码(可选)
|
|
75
|
+
return function (originalMethod, context) {
|
|
76
|
+
_trace(originalMethod, context, args[0], args[1]);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const serialize: (data: unknown) => string;
|
|
2
|
-
export declare const serializeArgs: (args: unknown[]) => string;
|
|
2
|
+
export declare const serializeArgs: (args: unknown[], argsNames?: string[]) => string;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.serializeArgs = exports.serialize = void 0;
|
|
8
|
+
require("core-js/modules/es.array.concat.js");
|
|
8
9
|
require("core-js/modules/es.array.join.js");
|
|
9
10
|
require("core-js/modules/es.array.map.js");
|
|
10
11
|
require("core-js/modules/es.object.to-string.js");
|
|
@@ -17,6 +18,18 @@ var serialize = exports.serialize = function serialize(data) {
|
|
|
17
18
|
}
|
|
18
19
|
return "".concat((0, _misc.jsonstring)(data));
|
|
19
20
|
};
|
|
20
|
-
var serializeArgs = exports.serializeArgs = function serializeArgs(args) {
|
|
21
|
-
|
|
21
|
+
var serializeArgs = exports.serializeArgs = function serializeArgs(args, argsNames) {
|
|
22
|
+
if (argsNames) {
|
|
23
|
+
var lastIndex = args.length - 1;
|
|
24
|
+
var str = '';
|
|
25
|
+
for (var i = 0; i < args.length; i++) {
|
|
26
|
+
var key = argsNames[i] ? "".concat(argsNames[i], ": ") : '';
|
|
27
|
+
str += "".concat(key).concat(serialize(args[i]));
|
|
28
|
+
if (i < lastIndex) {
|
|
29
|
+
str += ', ';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return str;
|
|
33
|
+
}
|
|
34
|
+
return "".concat(args.map(serialize).join(', '));
|
|
22
35
|
};
|
package/lib/decorator/proxy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyFunction, InvocationHandler } from './type';
|
|
2
|
-
export declare const proxyMethod: (method: AnyFunction, proto: any, propertyName: string, handler: InvocationHandler) => (this: any, ...args: any[]) => any;
|
|
2
|
+
export declare const proxyMethod: (method: AnyFunction, proto: any, propertyName: string, handler: InvocationHandler, paramNames?: string[]) => (this: any, ...args: any[]) => any;
|
|
3
3
|
export declare const extendConstructor: (constructor: any, handler: InvocationHandler, extendProps?: any, proxyMethods?: boolean) => {
|
|
4
4
|
new (...args: unknown[]): {
|
|
5
5
|
[x: string]: any;
|
package/lib/decorator/proxy.js
CHANGED
|
@@ -10,6 +10,7 @@ require("core-js/modules/es.array.concat.js");
|
|
|
10
10
|
require("core-js/modules/es.array.for-each.js");
|
|
11
11
|
require("core-js/modules/es.array.index-of.js");
|
|
12
12
|
require("core-js/modules/es.array.push.js");
|
|
13
|
+
require("core-js/modules/es.date.now.js");
|
|
13
14
|
require("core-js/modules/es.function.name.js");
|
|
14
15
|
require("core-js/modules/es.object.define-property.js");
|
|
15
16
|
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
@@ -29,6 +30,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
29
30
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
30
31
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
31
32
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
33
|
+
var _misc = require("../utilities/misc");
|
|
32
34
|
var _type = require("./type");
|
|
33
35
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
34
36
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
@@ -37,22 +39,20 @@ var failQuitely = function failQuitely(func, args) {
|
|
|
37
39
|
return func.apply(void 0, (0, _toConsumableArray2["default"])(args));
|
|
38
40
|
} catch (e) {}
|
|
39
41
|
};
|
|
40
|
-
var invokeMethod = function invokeMethod(instance, method, proto, propertyName, args, hanlder) {
|
|
42
|
+
var invokeMethod = function invokeMethod(instance, method, proto, propertyName, args, hanlder, paramNames) {
|
|
41
43
|
var context = {};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
arguments: args,
|
|
45
|
-
method: propertyName,
|
|
46
|
-
"class": proto.constructor.__$$className || proto.constructor.name,
|
|
47
|
-
context: context
|
|
48
|
-
}]);
|
|
44
|
+
context.start = Date.now();
|
|
45
|
+
context.traceId = (0, _misc.randomString)(5);
|
|
49
46
|
|
|
50
47
|
// provide a way for invoking method regardless it is async or sync function, attach the return value and the error(if it occurred) to the event object
|
|
51
48
|
var returnVal = method.apply(instance, args);
|
|
52
|
-
var
|
|
49
|
+
var isThenable = returnVal && !!returnVal.then;
|
|
50
|
+
context.isThenable = isThenable;
|
|
51
|
+
var post = function post(type, val, error) {
|
|
53
52
|
failQuitely(hanlder, [{
|
|
54
|
-
type:
|
|
53
|
+
type: type,
|
|
55
54
|
arguments: args,
|
|
55
|
+
argumentNames: paramNames,
|
|
56
56
|
"return": val,
|
|
57
57
|
method: propertyName,
|
|
58
58
|
"class": proto.constructor.__$$className || proto.constructor.name,
|
|
@@ -60,7 +60,9 @@ var invokeMethod = function invokeMethod(instance, method, proto, propertyName,
|
|
|
60
60
|
error: error
|
|
61
61
|
}]);
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
// 同步/异步函数调用结束时输出日志,(异步函数函数不等待异步结束)
|
|
65
|
+
post(_type.InvocationEventType.API_CALL, returnVal);
|
|
64
66
|
if (isThenable) {
|
|
65
67
|
// capture async return and potential error
|
|
66
68
|
var rtnTemp, errTemp;
|
|
@@ -69,19 +71,17 @@ var invokeMethod = function invokeMethod(instance, method, proto, propertyName,
|
|
|
69
71
|
})["catch"](function (e) {
|
|
70
72
|
errTemp = e;
|
|
71
73
|
})["finally"](function () {
|
|
72
|
-
post(rtnTemp, errTemp);
|
|
74
|
+
post(_type.InvocationEventType.API_RETURN, rtnTemp, errTemp);
|
|
73
75
|
});
|
|
74
|
-
} else {
|
|
75
|
-
post(returnVal);
|
|
76
76
|
}
|
|
77
77
|
return returnVal;
|
|
78
78
|
};
|
|
79
|
-
var proxyMethod = exports.proxyMethod = function proxyMethod(method, proto, propertyName, handler) {
|
|
79
|
+
var proxyMethod = exports.proxyMethod = function proxyMethod(method, proto, propertyName, handler, paramNames) {
|
|
80
80
|
return function () {
|
|
81
81
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
82
82
|
args[_key] = arguments[_key];
|
|
83
83
|
}
|
|
84
|
-
return invokeMethod(this, method, proto, propertyName, args, handler);
|
|
84
|
+
return invokeMethod(this, method, proto, propertyName, args, handler, paramNames);
|
|
85
85
|
};
|
|
86
86
|
};
|
|
87
87
|
var getMethods = function getMethods(target) {
|
package/lib/decorator/type.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Interceptor } from '../utilities/interceptor';
|
|
2
2
|
export declare enum InvocationEventType {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
API_CALL = 0,
|
|
4
|
+
API_RETURN = 1
|
|
5
5
|
}
|
|
6
6
|
export type InvocationEvent = {
|
|
7
7
|
type: InvocationEventType;
|
|
@@ -9,6 +9,7 @@ export type InvocationEvent = {
|
|
|
9
9
|
class: string;
|
|
10
10
|
method: string;
|
|
11
11
|
arguments?: any[];
|
|
12
|
+
argumentNames?: string[];
|
|
12
13
|
return?: any;
|
|
13
14
|
error?: Error;
|
|
14
15
|
};
|
package/lib/decorator/type.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.InvocationEventType = void 0;
|
|
8
8
|
var InvocationEventType = exports.InvocationEventType = /*#__PURE__*/function (InvocationEventType) {
|
|
9
|
-
InvocationEventType[InvocationEventType["
|
|
10
|
-
InvocationEventType[InvocationEventType["
|
|
9
|
+
InvocationEventType[InvocationEventType["API_CALL"] = 0] = "API_CALL";
|
|
10
|
+
InvocationEventType[InvocationEventType["API_RETURN"] = 1] = "API_RETURN";
|
|
11
11
|
return InvocationEventType;
|
|
12
12
|
}({}); // make it interceptable
|
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.FcrApplicationPlatformDescType = void 0;
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _env = require("./env");
|
|
11
|
-
var FcrApplicationPlatformDescType = exports.FcrApplicationPlatformDescType = (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, _env.FcrApplicationPlatform.WEB_DESKTOP, 'webDesktop'), _env.FcrApplicationPlatform.MACOS, 'macOS'), _env.FcrApplicationPlatform.WINDOWS, 'windows'), _env.FcrApplicationPlatform.WEB_MOBILE, 'webMobile');
|
|
11
|
+
var FcrApplicationPlatformDescType = exports.FcrApplicationPlatformDescType = (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, _env.FcrApplicationPlatform.WEB_DESKTOP, 'webDesktop'), _env.FcrApplicationPlatform.MACOS, 'macOS'), _env.FcrApplicationPlatform.WINDOWS, 'windows'), _env.FcrApplicationPlatform.WEB_MOBILE, 'webMobile'), _env.FcrApplicationPlatform.HARMONY, 'harmony');
|
package/lib/utilities/env.d.ts
CHANGED
package/lib/utilities/env.js
CHANGED
|
@@ -25,6 +25,7 @@ var FcrApplicationPlatform = exports.FcrApplicationPlatform = /*#__PURE__*/funct
|
|
|
25
25
|
FcrApplicationPlatform[FcrApplicationPlatform["MACOS"] = 2] = "MACOS";
|
|
26
26
|
FcrApplicationPlatform[FcrApplicationPlatform["WINDOWS"] = 3] = "WINDOWS";
|
|
27
27
|
FcrApplicationPlatform[FcrApplicationPlatform["WEB_MOBILE"] = 6] = "WEB_MOBILE";
|
|
28
|
+
FcrApplicationPlatform[FcrApplicationPlatform["HARMONY"] = 7] = "HARMONY";
|
|
28
29
|
return FcrApplicationPlatform;
|
|
29
30
|
}({});
|
|
30
31
|
var getPlatform = exports.getPlatform = function getPlatform() {
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { positiveIntegerSchema, z } from '
|
|
1
|
+
import { positiveIntegerSchema, z } from '../schema';
|
|
2
|
+
import { DetailErrorCode, ErrorModuleCode, ErrorServiceType } from './error-code';
|
|
2
3
|
type PositiveInteger = z.infer<typeof positiveIntegerSchema>;
|
|
3
4
|
interface CreateCodeParams {
|
|
4
5
|
serviceCode: PositiveInteger;
|
|
5
6
|
moduleCode: PositiveInteger;
|
|
6
7
|
detailCode: PositiveInteger;
|
|
7
8
|
}
|
|
8
|
-
interface AgoraErrorOptions extends CreateCodeParams {
|
|
9
|
-
message: string;
|
|
10
|
-
cause: string;
|
|
11
|
-
}
|
|
12
9
|
export declare class AgoraError extends Error {
|
|
13
10
|
private _code;
|
|
14
11
|
private _message;
|
|
@@ -16,16 +13,13 @@ export declare class AgoraError extends Error {
|
|
|
16
13
|
get code(): number;
|
|
17
14
|
get message(): string;
|
|
18
15
|
constructor(params: {
|
|
19
|
-
message: string;
|
|
20
16
|
code: number;
|
|
17
|
+
message: string;
|
|
21
18
|
cause?: string;
|
|
22
19
|
});
|
|
23
|
-
toString(): string;
|
|
24
20
|
static createCode({ serviceCode, moduleCode, detailCode }: CreateCodeParams): number;
|
|
25
|
-
static
|
|
26
|
-
static
|
|
27
|
-
static createWithOptions(options: AgoraErrorOptions): AgoraError;
|
|
28
|
-
static createWithError(error: Error): AgoraError;
|
|
21
|
+
static getServiceType(errorCode: number): ErrorServiceType | undefined;
|
|
22
|
+
static create(service: ErrorServiceType, module: ErrorModuleCode, errorCode: DetailErrorCode, message: string, cause?: unknown): AgoraError;
|
|
29
23
|
static createWithAny(error: any, message: string): AgoraError;
|
|
30
24
|
}
|
|
31
25
|
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
require("core-js/modules/es.reflect.construct.js");
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.AgoraError = void 0;
|
|
10
|
+
require("core-js/modules/es.error.cause.js");
|
|
11
|
+
require("core-js/modules/es.error.to-string.js");
|
|
12
|
+
require("core-js/modules/es.array.concat.js");
|
|
13
|
+
require("core-js/modules/es.array.filter.js");
|
|
14
|
+
require("core-js/modules/es.array.find.js");
|
|
15
|
+
require("core-js/modules/es.array.slice.js");
|
|
16
|
+
require("core-js/modules/es.number.constructor.js");
|
|
17
|
+
require("core-js/modules/es.object.to-string.js");
|
|
18
|
+
require("core-js/modules/es.object.values.js");
|
|
19
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
20
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
21
|
+
require("core-js/modules/esnext.iterator.find.js");
|
|
22
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
23
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
24
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
25
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
26
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
27
|
+
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
28
|
+
var _padStart = _interopRequireDefault(require("lodash/padStart"));
|
|
29
|
+
var _padEnd = _interopRequireDefault(require("lodash/padEnd"));
|
|
30
|
+
var _errorCode = require("./error-code");
|
|
31
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
32
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
33
|
+
var AgoraError = exports.AgoraError = /*#__PURE__*/function (_Error) {
|
|
34
|
+
function AgoraError(params) {
|
|
35
|
+
var _this;
|
|
36
|
+
(0, _classCallCheck2["default"])(this, AgoraError);
|
|
37
|
+
_this = _callSuper(this, AgoraError, [params.message]);
|
|
38
|
+
_this._code = params.code;
|
|
39
|
+
_this._message = params.message;
|
|
40
|
+
_this._cause = params.cause || '';
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
(0, _inherits2["default"])(AgoraError, _Error);
|
|
44
|
+
return (0, _createClass2["default"])(AgoraError, [{
|
|
45
|
+
key: "code",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return this._code;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "message",
|
|
51
|
+
get: function get() {
|
|
52
|
+
return this._message;
|
|
53
|
+
}
|
|
54
|
+
}], [{
|
|
55
|
+
key: "createCode",
|
|
56
|
+
value: function createCode(_ref) {
|
|
57
|
+
var serviceCode = _ref.serviceCode,
|
|
58
|
+
moduleCode = _ref.moduleCode,
|
|
59
|
+
detailCode = _ref.detailCode;
|
|
60
|
+
// 生成9位数错误代码:前3位是错误类型,中间3位是模块代码,后3位是具体错误代码
|
|
61
|
+
var errorType = (0, _padEnd["default"])(String(serviceCode), 3, '0'); // 如:'100'
|
|
62
|
+
var moduleStr = (0, _padStart["default"])(String(moduleCode), 3, '0'); // 如:'020'
|
|
63
|
+
var errorCode = (0, _padStart["default"])(String(detailCode), 3, '0'); // 如:'001'
|
|
64
|
+
|
|
65
|
+
return Number("".concat(errorType).concat(moduleStr).concat(errorCode)); // 如:'100020001'
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "getServiceType",
|
|
69
|
+
value: function getServiceType(errorCode) {
|
|
70
|
+
var str = String(errorCode);
|
|
71
|
+
if (str.length !== 9) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
var servicePrefix = str.slice(0, 3);
|
|
75
|
+
var serviceTypes = Object.values(_errorCode.ErrorServiceType).filter(function (v) {
|
|
76
|
+
return typeof v === 'number';
|
|
77
|
+
});
|
|
78
|
+
return serviceTypes.find(function (type) {
|
|
79
|
+
return (0, _padEnd["default"])(String(type), 3, '0') === servicePrefix;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "create",
|
|
84
|
+
value: function create(service, module, errorCode, message, cause) {
|
|
85
|
+
var domain = getDomain(service);
|
|
86
|
+
var fullMessage = "domain: ".concat(domain, ", info: ").concat(message);
|
|
87
|
+
var fullCode = AgoraError.createCode({
|
|
88
|
+
serviceCode: service,
|
|
89
|
+
moduleCode: module,
|
|
90
|
+
detailCode: errorCode
|
|
91
|
+
});
|
|
92
|
+
var causeMessage = '';
|
|
93
|
+
if (cause instanceof Error) {
|
|
94
|
+
causeMessage = cause.message;
|
|
95
|
+
} else if (cause) {
|
|
96
|
+
causeMessage = String(cause);
|
|
97
|
+
}
|
|
98
|
+
return new AgoraError({
|
|
99
|
+
code: fullCode,
|
|
100
|
+
message: fullMessage,
|
|
101
|
+
cause: causeMessage
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "createWithAny",
|
|
106
|
+
value: function createWithAny(error, message) {
|
|
107
|
+
if (error instanceof AgoraError) {
|
|
108
|
+
return error;
|
|
109
|
+
} else {
|
|
110
|
+
var code = _errorCode.DetailErrorCode.UNDEFINED_ERROR;
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
if (error.cause) {
|
|
113
|
+
message = message + ", error cause: ".concat(error.cause);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
var agoraError = new AgoraError({
|
|
117
|
+
code: code,
|
|
118
|
+
message: message
|
|
119
|
+
});
|
|
120
|
+
return agoraError;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}]);
|
|
124
|
+
}(/*#__PURE__*/(0, _wrapNativeSuper2["default"])(Error));
|
|
125
|
+
var getDomain = function getDomain(service) {
|
|
126
|
+
switch (service) {
|
|
127
|
+
case _errorCode.ErrorServiceType.RTE_CLIENT:
|
|
128
|
+
return 'RTE-CLIENT';
|
|
129
|
+
case _errorCode.ErrorServiceType.RTE_SERVER:
|
|
130
|
+
return 'RTE-SRV';
|
|
131
|
+
case _errorCode.ErrorServiceType.NATIVE_RTC:
|
|
132
|
+
return 'RTC';
|
|
133
|
+
case _errorCode.ErrorServiceType.WEB_RTC:
|
|
134
|
+
return 'WebRTC';
|
|
135
|
+
case _errorCode.ErrorServiceType.RTM_SDK:
|
|
136
|
+
return 'RTM';
|
|
137
|
+
case _errorCode.ErrorServiceType.FCR_CLIENT:
|
|
138
|
+
return 'CORE-CLIENT';
|
|
139
|
+
case _errorCode.ErrorServiceType.FCR_SERVER:
|
|
140
|
+
return 'CORE-SRV';
|
|
141
|
+
case _errorCode.ErrorServiceType.FCR_UI_SCENE:
|
|
142
|
+
return 'UI-SCENE';
|
|
143
|
+
case _errorCode.ErrorServiceType.DEMO_SERVER:
|
|
144
|
+
return 'DEMO-SRV';
|
|
145
|
+
default:
|
|
146
|
+
return 'UNDEFINED';
|
|
147
|
+
}
|
|
148
|
+
};
|