@celljs/core 3.6.5 → 3.6.7
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/common/error/custom-error.d.ts +25 -2
- package/lib/common/error/custom-error.d.ts.map +1 -1
- package/lib/common/error/custom-error.js +38 -2
- package/lib/common/error/custom-error.js.map +1 -1
- package/lib/common/logger/abstract-logger.d.ts +5 -2
- package/lib/common/logger/abstract-logger.d.ts.map +1 -1
- package/lib/common/logger/abstract-logger.js +26 -1
- package/lib/common/logger/abstract-logger.js.map +1 -1
- package/lib/common/logger/index.d.ts +1 -0
- package/lib/common/logger/index.d.ts.map +1 -1
- package/lib/common/logger/index.js +1 -0
- package/lib/common/logger/index.js.map +1 -1
- package/lib/common/logger/logger-protocol.d.ts +14 -0
- package/lib/common/logger/logger-protocol.d.ts.map +1 -1
- package/lib/common/logger/logger-protocol.js +4 -1
- package/lib/common/logger/logger-protocol.js.map +1 -1
- package/lib/common/logger/logger-service.d.ts +5 -0
- package/lib/common/logger/logger-service.d.ts.map +1 -0
- package/lib/common/logger/logger-service.js +21 -0
- package/lib/common/logger/logger-service.js.map +1 -0
- package/lib/common/logger/logger.js +4 -4
- package/lib/common/logger/logger.js.map +1 -1
- package/lib/common/test/mock-logger.d.ts +7 -1
- package/lib/common/test/mock-logger.d.ts.map +1 -1
- package/lib/common/test/mock-logger.js +12 -0
- package/lib/common/test/mock-logger.js.map +1 -1
- package/lib/common/utils/error-util.d.ts +20 -0
- package/lib/common/utils/error-util.d.ts.map +1 -0
- package/lib/common/utils/error-util.js +39 -0
- package/lib/common/utils/error-util.js.map +1 -0
- package/lib/common/utils/index.d.ts +1 -0
- package/lib/common/utils/index.d.ts.map +1 -1
- package/lib/common/utils/index.js +1 -0
- package/lib/common/utils/index.js.map +1 -1
- package/package.json +3 -4
- package/src/common/error/custom-error.ts +43 -2
- package/src/common/logger/abstract-logger.ts +28 -4
- package/src/common/logger/index.ts +1 -0
- package/src/common/logger/logger-protocol.ts +17 -0
- package/src/common/logger/logger-service.ts +7 -0
- package/src/common/logger/logger.ts +4 -4
- package/src/common/test/mock-logger.ts +11 -1
- package/src/common/utils/error-util.ts +34 -0
- package/src/common/utils/index.ts +1 -0
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface ErrorOptions {
|
|
2
|
+
cause?: unknown;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Allows to easily extend a base class to create custom applicative errors.
|
|
6
|
+
*
|
|
7
|
+
* example:
|
|
8
|
+
* ```
|
|
9
|
+
* class HttpError extends CustomError {
|
|
10
|
+
* public constructor(
|
|
11
|
+
* public code: number,
|
|
12
|
+
* message?: string,
|
|
13
|
+
* cause?: Error,
|
|
14
|
+
* ) {
|
|
15
|
+
* super(message, { cause })
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* new HttpError(404, 'Not found')
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class CustomError extends Error {
|
|
23
|
+
name: string;
|
|
24
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
4
27
|
//# sourceMappingURL=custom-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../../src/common/error/custom-error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../../src/common/error/custom-error.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACzB,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAkBvD"}
|
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomError = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
/**
|
|
6
|
+
* Allows to easily extend a base class to create custom applicative errors.
|
|
7
|
+
*
|
|
8
|
+
* example:
|
|
9
|
+
* ```
|
|
10
|
+
* class HttpError extends CustomError {
|
|
11
|
+
* public constructor(
|
|
12
|
+
* public code: number,
|
|
13
|
+
* message?: string,
|
|
14
|
+
* cause?: Error,
|
|
15
|
+
* ) {
|
|
16
|
+
* super(message, { cause })
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* new HttpError(404, 'Not found')
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class CustomError extends Error {
|
|
24
|
+
constructor(message, options) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
super(message, options);
|
|
28
|
+
// set error name as constructor name, make it not enumerable to keep native Error behavior
|
|
29
|
+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target#new.target_in_constructors
|
|
30
|
+
Object.defineProperty(this, 'name', {
|
|
31
|
+
value: new.target.name,
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true,
|
|
34
|
+
});
|
|
35
|
+
// fix the extended error prototype chain
|
|
36
|
+
// because typescript __extends implementation can't
|
|
37
|
+
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
38
|
+
utils_1.ErrorUtil.fixProto(this, new.target.prototype);
|
|
39
|
+
// try to remove contructor from stack trace
|
|
40
|
+
utils_1.ErrorUtil.fixStack(this);
|
|
41
|
+
}
|
|
6
42
|
}
|
|
7
43
|
exports.CustomError = CustomError;
|
|
8
44
|
//# sourceMappingURL=custom-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../../src/common/error/custom-error.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../../src/common/error/custom-error.ts"],"names":[],"mappings":";;;AAAA,oCAAqC;AAMrC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,WAAY,SAAQ,KAAK;IAGlC,YAAY,OAAgB,EAAE,OAAsB;QAChD,6DAA6D;QAC7D,aAAa;QACb,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,2FAA2F;QAC3F,wHAAwH;QACxH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;YAChC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;YACtB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,yCAAyC;QACzC,oDAAoD;QACpD,mJAAmJ;QACnJ,iBAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/C,4CAA4C;QAC5C,iBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACJ;AArBD,kCAqBC"}
|
|
@@ -2,10 +2,13 @@ import { Logger, LogLevel, TraceIdProvider } from './logger-protocol';
|
|
|
2
2
|
export declare abstract class AbstractLogger implements Logger {
|
|
3
3
|
protected instance: Logger;
|
|
4
4
|
protected context?: string;
|
|
5
|
-
|
|
5
|
+
level: LogLevel;
|
|
6
6
|
protected readonly traceIdProvider?: TraceIdProvider;
|
|
7
|
+
protected timeRecords: Map<string, number>;
|
|
7
8
|
setContext(context?: string): void;
|
|
8
|
-
protected
|
|
9
|
+
protected log(message: any, context?: string, logFn?: (...args: any[]) => void): void;
|
|
10
|
+
time(label: string): void;
|
|
11
|
+
timeEnd(label: string, context?: string): number | undefined;
|
|
9
12
|
abstract info(message: any, context?: string | undefined): void;
|
|
10
13
|
abstract error(message: any, context?: string | undefined): void;
|
|
11
14
|
abstract warn(message: any, context?: string | undefined): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-logger.d.ts","sourceRoot":"","sources":["../../../src/common/logger/abstract-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,QAAQ,
|
|
1
|
+
{"version":3,"file":"abstract-logger.d.ts","sourceRoot":"","sources":["../../../src/common/logger/abstract-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,QAAQ,EAAgB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAElG,8BAAsB,cAAe,YAAW,MAAM;IAClD,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAG3B,KAAK,EAAE,QAAQ,CAAC;IAGhB,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAErD,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAEvD,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAmB,GAAG,IAAI;IAenG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAa5D,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAC/D,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAChE,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAC/D,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CACnE"}
|
|
@@ -13,10 +13,13 @@ exports.AbstractLogger = void 0;
|
|
|
13
13
|
const annotation_1 = require("../annotation");
|
|
14
14
|
const logger_protocol_1 = require("./logger-protocol");
|
|
15
15
|
class AbstractLogger {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.timeRecords = new Map();
|
|
18
|
+
}
|
|
16
19
|
setContext(context) {
|
|
17
20
|
this.context = context;
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
log(message, context, logFn = console.info) {
|
|
20
23
|
var _a;
|
|
21
24
|
context = context !== null && context !== void 0 ? context : this.context;
|
|
22
25
|
const time = new Date().toISOString();
|
|
@@ -24,6 +27,28 @@ class AbstractLogger {
|
|
|
24
27
|
const traceStr = traceId ? ` [trace: ${traceId}]` : '';
|
|
25
28
|
const contextStr = this.context ? ` [${this.context}]` : '';
|
|
26
29
|
logFn(`${time} [${this.level}]${traceStr}${contextStr} ${message}`);
|
|
30
|
+
logger_protocol_1.onLogEmitter.fire({
|
|
31
|
+
level: this.level,
|
|
32
|
+
traceId,
|
|
33
|
+
context,
|
|
34
|
+
message
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
time(label) {
|
|
38
|
+
this.timeRecords.set(label, Date.now());
|
|
39
|
+
}
|
|
40
|
+
timeEnd(label, context) {
|
|
41
|
+
const start = this.timeRecords.get(label);
|
|
42
|
+
if (start !== undefined) {
|
|
43
|
+
const duration = Date.now() - start;
|
|
44
|
+
this.timeRecords.delete(label);
|
|
45
|
+
this.log(`${label}: ${duration}ms`, context);
|
|
46
|
+
return duration;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.log(`No such label: ${label} for timeEnd`, context);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
27
52
|
}
|
|
28
53
|
}
|
|
29
54
|
exports.AbstractLogger = AbstractLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-logger.js","sourceRoot":"","sources":["../../../src/common/logger/abstract-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"abstract-logger.js","sourceRoot":"","sources":["../../../src/common/logger/abstract-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2D;AAC3D,uDAAkG;AAElG,MAAsB,cAAc;IAApC;QAUc,gBAAW,GAAwB,IAAI,GAAG,EAAE,CAAC;IA0C3D,CAAC;IAxCG,UAAU,CAAC,OAAgB;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAES,GAAG,CAAC,OAAY,EAAE,OAAgB,EAAE,QAAkC,OAAO,CAAC,IAAI;;QACxF,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,eAAe,0CAAE,OAAO,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,YAAY,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,KAAK,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,KAAK,IAAI,QAAQ,GAAG,UAAU,IAAI,OAAO,EAAE,CAAC,CAAC;QACpE,8BAAY,CAAC,IAAI,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO;YACP,OAAO;YACP,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED,IAAI,CAAC,KAAa;QACd,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,CAAC,KAAa,EAAE,OAAgB;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;YACpC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,KAAK,QAAQ,IAAI,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,QAAQ,CAAC;QACpB,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,GAAG,CAAC,kBAAkB,KAAK,cAAc,EAAE,OAAO,CAAC,CAAC;YACzD,OAAO;QACX,CAAC;IACL,CAAC;CAMJ;AApDD,wCAoDC;AA/CG;IADC,IAAA,kBAAK,EAAC,GAAG,8BAAY,YAAY,CAAC;;6CACnB;AAGG;IADlB,IAAA,sBAAS,EAAC,iCAAe,CAAC;IAAE,IAAA,qBAAQ,GAAE;;uDACc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./logger-protocol"), exports);
|
|
18
18
|
__exportStar(require("./logger"), exports);
|
|
19
19
|
__exportStar(require("./abstract-logger"), exports);
|
|
20
|
+
__exportStar(require("./logger-service"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2CAAyB;AACzB,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2CAAyB;AACzB,oDAAkC;AAClC,mDAAiC"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
import { Emitter, Event } from '../utils';
|
|
1
2
|
export declare const LOGGER_CONFIG = "cell.logger";
|
|
2
3
|
export declare const LOGGER_LEVEL = "cell.logger.level";
|
|
3
4
|
export declare const Logger: unique symbol;
|
|
4
5
|
export declare const TraceIdProvider: unique symbol;
|
|
6
|
+
export declare const LoggerService: unique symbol;
|
|
5
7
|
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
|
|
8
|
+
export interface LogMessage {
|
|
9
|
+
level: LogLevel;
|
|
10
|
+
traceId?: string;
|
|
11
|
+
context?: string;
|
|
12
|
+
message: any;
|
|
13
|
+
}
|
|
6
14
|
export interface Logger {
|
|
7
15
|
setContext(context?: string): void;
|
|
8
16
|
info(message: any, context?: string): void;
|
|
9
17
|
error(message: any, context?: string): void;
|
|
10
18
|
warn(message: any, context?: string): void;
|
|
11
19
|
debug(message: any, context?: string): void;
|
|
20
|
+
time(label: string): void;
|
|
21
|
+
timeEnd(label: string, context?: string): number | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare const onLogEmitter: Emitter<LogMessage>;
|
|
24
|
+
export interface LoggerService {
|
|
25
|
+
readonly onLog: Event<LogMessage>;
|
|
12
26
|
}
|
|
13
27
|
export interface TraceIdProvider {
|
|
14
28
|
provide(): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAC3C,eAAO,MAAM,YAAY,sBAA2B,CAAC;AAErD,eAAO,MAAM,MAAM,eAAmB,CAAC;AACvC,eAAO,MAAM,eAAe,eAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"logger-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC1C,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAC3C,eAAO,MAAM,YAAY,sBAA2B,CAAC;AAErD,eAAO,MAAM,MAAM,eAAmB,CAAC;AACvC,eAAO,MAAM,eAAe,eAA4B,CAAC;AACzD,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACvE,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,MAAM;IAKnB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAEhE;AAED,eAAO,MAAM,YAAY,qBAA4B,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,eAAe;IAC5B,OAAO,IAAI,MAAM,GAAG,SAAS,CAAC;CACjC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TraceIdProvider = exports.Logger = exports.LOGGER_LEVEL = exports.LOGGER_CONFIG = void 0;
|
|
3
|
+
exports.onLogEmitter = exports.LoggerService = exports.TraceIdProvider = exports.Logger = exports.LOGGER_LEVEL = exports.LOGGER_CONFIG = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
exports.LOGGER_CONFIG = 'cell.logger';
|
|
5
6
|
exports.LOGGER_LEVEL = `${exports.LOGGER_CONFIG}.level`;
|
|
6
7
|
exports.Logger = Symbol('Logger');
|
|
7
8
|
exports.TraceIdProvider = Symbol('TraceIdProvider');
|
|
9
|
+
exports.LoggerService = Symbol('LoggerService');
|
|
10
|
+
exports.onLogEmitter = new utils_1.Emitter();
|
|
8
11
|
//# sourceMappingURL=logger-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-protocol.js","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"logger-protocol.js","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":";;;AAAA,oCAA0C;AAC7B,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,YAAY,GAAG,GAAG,qBAAa,QAAQ,CAAC;AAExC,QAAA,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,QAAA,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC5C,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAyBxC,QAAA,YAAY,GAAG,IAAI,eAAO,EAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-service.d.ts","sourceRoot":"","sources":["../../../src/common/logger/logger-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAgB,MAAM,mBAAmB,CAAC;AAEhE,qBACa,iBAAkB,YAAW,aAAa;IACnD,QAAQ,CAAC,KAAK,6DAAsB;CACvC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoggerServiceImpl = void 0;
|
|
10
|
+
const annotation_1 = require("../annotation");
|
|
11
|
+
const logger_protocol_1 = require("./logger-protocol");
|
|
12
|
+
let LoggerServiceImpl = class LoggerServiceImpl {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.onLog = logger_protocol_1.onLogEmitter.event;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.LoggerServiceImpl = LoggerServiceImpl;
|
|
18
|
+
exports.LoggerServiceImpl = LoggerServiceImpl = __decorate([
|
|
19
|
+
(0, annotation_1.Component)(logger_protocol_1.LoggerService)
|
|
20
|
+
], LoggerServiceImpl);
|
|
21
|
+
//# sourceMappingURL=logger-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-service.js","sourceRoot":"","sources":["../../../src/common/logger/logger-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA0C;AAC1C,uDAAgE;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAAvB;QACM,UAAK,GAAG,8BAAY,CAAC,KAAK,CAAC;IACxC,CAAC;CAAA,CAAA;AAFY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAS,EAAC,+BAAa,CAAC;GACZ,iBAAiB,CAE7B"}
|
|
@@ -13,21 +13,21 @@ const abstract_logger_1 = require("./abstract-logger");
|
|
|
13
13
|
const logger_protocol_1 = require("./logger-protocol");
|
|
14
14
|
let LoggerImpl = class LoggerImpl extends abstract_logger_1.AbstractLogger {
|
|
15
15
|
error(message, context) {
|
|
16
|
-
this.
|
|
16
|
+
this.log(message, context, console.error.bind(console));
|
|
17
17
|
}
|
|
18
18
|
info(message, context) {
|
|
19
19
|
if (['info', 'debug'].includes(this.level)) {
|
|
20
|
-
this.
|
|
20
|
+
this.log(message, context);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
warn(message, context) {
|
|
24
24
|
if (['info', 'debug', 'warn'].includes(this.level)) {
|
|
25
|
-
this.
|
|
25
|
+
this.log(message, context, console.warn.bind(console));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
debug(message, context) {
|
|
29
29
|
if (this.level === 'debug') {
|
|
30
|
-
this.
|
|
30
|
+
this.log(message, context, console.debug.bind(console));
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/logger/logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA0C;AAC1C,4CAAqC;AACrC,uDAAmD;AACnD,uDAA2C;AAGpC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gCAAc;IAE1C,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/logger/logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA0C;AAC1C,4CAAqC;AACrC,uDAAmD;AACnD,uDAA2C;AAGpC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gCAAc;IAE1C,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,CAAC,OAAY,EAAE,OAAgB;QAC/B,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAY,EAAE,OAAgB;QAC/B,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CAEJ,CAAA;AAxBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,sBAAS,EAAC,EAAE,EAAE,EAAE,wBAAM,EAAE,KAAK,EAAE,iBAAK,CAAC,SAAS,EAAE,CAAC;GACrC,UAAU,CAwBtB"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { Logger } from '../logger/logger-protocol';
|
|
1
|
+
import { Logger, LogLevel, LogMessage } from '../logger/logger-protocol';
|
|
2
|
+
import { Emitter } from '../utils';
|
|
2
3
|
export declare class MockLogger implements Logger {
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
protected readonly onLogEmitter: Emitter<LogMessage>;
|
|
6
|
+
onLog: import("../utils").Event<LogMessage>;
|
|
7
|
+
time(label: string): void;
|
|
8
|
+
timeEnd(label: string, context?: string): number | undefined;
|
|
3
9
|
setContext(context?: string): void;
|
|
4
10
|
info(message: any, context?: string): void;
|
|
5
11
|
error(message: any, context?: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-logger.d.ts","sourceRoot":"","sources":["../../../src/common/test/mock-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"mock-logger.d.ts","sourceRoot":"","sources":["../../../src/common/test/mock-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,qBACa,UAAW,YAAW,MAAM;IACrC,KAAK,EAAE,QAAQ,CAAU;IACzB,SAAS,CAAC,QAAQ,CAAC,YAAY,sBAA6B;IAC5D,KAAK,uCAA2B;IAChC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAGzB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAG5D,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAGlC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAG1C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAG3C,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAG1C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAG9C"}
|
|
@@ -8,7 +8,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.MockLogger = void 0;
|
|
10
10
|
const annotation_1 = require("../annotation");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
11
12
|
let MockLogger = class MockLogger {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.level = 'info';
|
|
15
|
+
this.onLogEmitter = new utils_1.Emitter();
|
|
16
|
+
this.onLog = this.onLogEmitter.event;
|
|
17
|
+
}
|
|
18
|
+
time(label) {
|
|
19
|
+
// do nothing
|
|
20
|
+
}
|
|
21
|
+
timeEnd(label, context) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
12
24
|
setContext(context) {
|
|
13
25
|
// do nothing
|
|
14
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-logger.js","sourceRoot":"","sources":["../../../src/common/test/mock-logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA2C;
|
|
1
|
+
{"version":3,"file":"mock-logger.js","sourceRoot":"","sources":["../../../src/common/test/mock-logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA2C;AAE3C,oCAAmC;AAG5B,IAAM,UAAU,GAAhB,MAAM,UAAU;IAAhB;QACH,UAAK,GAAa,MAAM,CAAC;QACN,iBAAY,GAAG,IAAI,eAAO,EAAc,CAAC;QAC5D,UAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IAsBpC,CAAC;IArBG,IAAI,CAAC,KAAa;QACd,aAAa;IACjB,CAAC;IACD,OAAO,CAAC,KAAa,EAAE,OAAgB;QACnC,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,UAAU,CAAC,OAAgB;QACvB,aAAa;IACjB,CAAC;IACD,IAAI,CAAC,OAAY,EAAE,OAAgB;QAC/B,aAAa;IACjB,CAAC;IACD,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,aAAa;IACjB,CAAC;IACD,IAAI,CAAC,OAAY,EAAE,OAAgB;QAC/B,aAAa;IACjB,CAAC;IACD,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,aAAa;IACjB,CAAC;CACJ,CAAA;AAzBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,uBAAU,GAAE;GACA,UAAU,CAyBtB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare abstract class ErrorUtil {
|
|
2
|
+
/**
|
|
3
|
+
* Fix the prototype chain of the error
|
|
4
|
+
*
|
|
5
|
+
* Use Object.setPrototypeOf
|
|
6
|
+
* Support ES6 environments
|
|
7
|
+
*
|
|
8
|
+
* Fallback setting __proto__
|
|
9
|
+
* Support IE11+, see https://docs.microsoft.com/en-us/scripting/javascript/reference/javascript-version-information
|
|
10
|
+
*/
|
|
11
|
+
static fixProto(target: Error, prototype: {}): void;
|
|
12
|
+
/**
|
|
13
|
+
* Capture and fix the error stack when available
|
|
14
|
+
*
|
|
15
|
+
* Use Error.captureStackTrace
|
|
16
|
+
* Support v8 environments
|
|
17
|
+
*/
|
|
18
|
+
static fixStack(target: Error, fn?: Function): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=error-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-util.d.ts","sourceRoot":"","sources":["../../../src/common/utils/error-util.ts"],"names":[],"mappings":"AAAA,8BAAsB,SAAS;IAC3B;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;IAW5C;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAE,QAA6B;CAMnE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorUtil = void 0;
|
|
4
|
+
class ErrorUtil {
|
|
5
|
+
/**
|
|
6
|
+
* Fix the prototype chain of the error
|
|
7
|
+
*
|
|
8
|
+
* Use Object.setPrototypeOf
|
|
9
|
+
* Support ES6 environments
|
|
10
|
+
*
|
|
11
|
+
* Fallback setting __proto__
|
|
12
|
+
* Support IE11+, see https://docs.microsoft.com/en-us/scripting/javascript/reference/javascript-version-information
|
|
13
|
+
*/
|
|
14
|
+
static fixProto(target, prototype) {
|
|
15
|
+
const setPrototypeOf = Object.setPrototypeOf;
|
|
16
|
+
if (setPrototypeOf) {
|
|
17
|
+
setPrototypeOf(target, prototype);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
target.__proto__ = prototype;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Capture and fix the error stack when available
|
|
27
|
+
*
|
|
28
|
+
* Use Error.captureStackTrace
|
|
29
|
+
* Support v8 environments
|
|
30
|
+
*/
|
|
31
|
+
static fixStack(target, fn = target.constructor) {
|
|
32
|
+
const captureStackTrace = Error.captureStackTrace;
|
|
33
|
+
if (captureStackTrace) {
|
|
34
|
+
captureStackTrace(target, fn);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ErrorUtil = ErrorUtil;
|
|
39
|
+
//# sourceMappingURL=error-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-util.js","sourceRoot":"","sources":["../../../src/common/utils/error-util.ts"],"names":[],"mappings":";;;AAAA,MAAsB,SAAS;IAC3B;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAa,EAAE,SAAa;QACxC,MAAM,cAAc,GAAc,MAAc,CAAC,cAAc,CAAC;QAChE,IAAI,cAAc,EAAE,CAAC;YACjB,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACJ,6DAA6D;YAC7D,aAAa;YACb,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;QACjC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAa,EAAE,KAAe,MAAM,CAAC,WAAW;QAC5D,MAAM,iBAAiB,GAAc,KAAa,CAAC,iBAAiB,CAAC;QACrE,IAAI,iBAAiB,EAAE,CAAC;YACpB,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;IACL,CAAC;CACJ;AAjCD,8BAiCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -34,4 +34,5 @@ __exportStar(require("./assert"), exports);
|
|
|
34
34
|
__exportStar(require("./mime-type-util"), exports);
|
|
35
35
|
__exportStar(require("./mime-type"), exports);
|
|
36
36
|
__exportStar(require("./byte-util"), exports);
|
|
37
|
+
__exportStar(require("./error-util"), exports);
|
|
37
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;AAC7B,uCAAqB;AACrB,+CAA6B;AAC7B,oDAAkC;AAClC,iDAA+B;AAC/B,0CAAwB;AACxB,4CAA0B;AAC1B,gDAA8B;AAC9B,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,mDAAiC;AACjC,8CAA4B;AAC5B,8CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;AAC7B,uCAAqB;AACrB,+CAA6B;AAC7B,oDAAkC;AAClC,iDAA+B;AAC/B,0CAAwB;AACxB,4CAA0B;AAC1B,gDAA8B;AAC9B,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,mDAAiC;AACjC,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/core",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -41,16 +41,15 @@
|
|
|
41
41
|
"setimmediate": "^1.0.5",
|
|
42
42
|
"source-map-support": "^0.5.13",
|
|
43
43
|
"traverse": "^0.6.7",
|
|
44
|
-
"ts-custom-error": "^3.1.1",
|
|
45
44
|
"tslib": "^2.8.0"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@celljs/component": "3.6.
|
|
47
|
+
"@celljs/component": "3.6.7",
|
|
49
48
|
"@types/jexl": "^2.2.0",
|
|
50
49
|
"@types/traverse": "^0.6.32"
|
|
51
50
|
},
|
|
52
51
|
"publishConfig": {
|
|
53
52
|
"access": "public"
|
|
54
53
|
},
|
|
55
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "03357e0a34278297a42c279b9ad74ae7c29a7cab"
|
|
56
55
|
}
|
|
@@ -1,5 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorUtil } from '../utils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface ErrorOptions {
|
|
4
|
+
cause?: unknown
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Allows to easily extend a base class to create custom applicative errors.
|
|
9
|
+
*
|
|
10
|
+
* example:
|
|
11
|
+
* ```
|
|
12
|
+
* class HttpError extends CustomError {
|
|
13
|
+
* public constructor(
|
|
14
|
+
* public code: number,
|
|
15
|
+
* message?: string,
|
|
16
|
+
* cause?: Error,
|
|
17
|
+
* ) {
|
|
18
|
+
* super(message, { cause })
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* new HttpError(404, 'Not found')
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class CustomError extends Error {
|
|
26
|
+
override name: string;
|
|
4
27
|
|
|
28
|
+
constructor(message?: string, options?: ErrorOptions) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
super(message, options);
|
|
32
|
+
// set error name as constructor name, make it not enumerable to keep native Error behavior
|
|
33
|
+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target#new.target_in_constructors
|
|
34
|
+
Object.defineProperty(this, 'name', {
|
|
35
|
+
value: new.target.name,
|
|
36
|
+
enumerable: false,
|
|
37
|
+
configurable: true,
|
|
38
|
+
});
|
|
39
|
+
// fix the extended error prototype chain
|
|
40
|
+
// because typescript __extends implementation can't
|
|
41
|
+
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
42
|
+
ErrorUtil.fixProto(this, new.target.prototype);
|
|
43
|
+
// try to remove contructor from stack trace
|
|
44
|
+
ErrorUtil.fixStack(this);
|
|
45
|
+
}
|
|
5
46
|
}
|
|
@@ -1,32 +1,56 @@
|
|
|
1
1
|
import { Autowired, Optional, Value } from '../annotation';
|
|
2
|
-
import { Logger, LOGGER_LEVEL, LogLevel, TraceIdProvider } from './logger-protocol';
|
|
2
|
+
import { Logger, LOGGER_LEVEL, LogLevel, onLogEmitter, TraceIdProvider } from './logger-protocol';
|
|
3
3
|
|
|
4
4
|
export abstract class AbstractLogger implements Logger {
|
|
5
5
|
protected instance: Logger;
|
|
6
6
|
protected context?: string;
|
|
7
7
|
|
|
8
8
|
@Value(`${LOGGER_LEVEL} ?: 'info'`)
|
|
9
|
-
|
|
9
|
+
level: LogLevel;
|
|
10
10
|
|
|
11
11
|
@Autowired(TraceIdProvider) @Optional()
|
|
12
12
|
protected readonly traceIdProvider?: TraceIdProvider;
|
|
13
13
|
|
|
14
|
+
protected timeRecords: Map<string, number> = new Map();
|
|
15
|
+
|
|
14
16
|
setContext(context?: string): void {
|
|
15
17
|
this.context = context;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
protected
|
|
20
|
+
protected log(message: any, context?: string, logFn: (...args: any[]) => void = console.info): void {
|
|
19
21
|
context = context ?? this.context;
|
|
20
22
|
const time = new Date().toISOString();
|
|
21
23
|
const traceId = this.traceIdProvider?.provide();
|
|
22
24
|
const traceStr = traceId ? ` [trace: ${traceId}]` : '';
|
|
23
25
|
const contextStr = this.context ? ` [${this.context}]` : '';
|
|
24
26
|
logFn(`${time} [${this.level}]${traceStr}${contextStr} ${message}`);
|
|
27
|
+
onLogEmitter.fire({
|
|
28
|
+
level: this.level,
|
|
29
|
+
traceId,
|
|
30
|
+
context,
|
|
31
|
+
message
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
time(label: string): void {
|
|
36
|
+
this.timeRecords.set(label, Date.now());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
timeEnd(label: string, context?: string): number | undefined {
|
|
40
|
+
const start = this.timeRecords.get(label);
|
|
41
|
+
if (start !== undefined) {
|
|
42
|
+
const duration = Date.now() - start;
|
|
43
|
+
this.timeRecords.delete(label);
|
|
44
|
+
this.log(`${label}: ${duration}ms`, context);
|
|
45
|
+
return duration;
|
|
46
|
+
} else {
|
|
47
|
+
this.log(`No such label: ${label} for timeEnd`, context);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
25
50
|
}
|
|
26
51
|
|
|
27
52
|
abstract info(message: any, context?: string | undefined): void;
|
|
28
53
|
abstract error(message: any, context?: string | undefined): void;
|
|
29
54
|
abstract warn(message: any, context?: string | undefined): void;
|
|
30
55
|
abstract debug(message: any, context?: string | undefined): void;
|
|
31
|
-
|
|
32
56
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { Emitter, Event } from '../utils';
|
|
1
2
|
export const LOGGER_CONFIG = 'cell.logger';
|
|
2
3
|
export const LOGGER_LEVEL = `${LOGGER_CONFIG}.level`;
|
|
3
4
|
|
|
4
5
|
export const Logger = Symbol('Logger');
|
|
5
6
|
export const TraceIdProvider = Symbol('TraceIdProvider');
|
|
7
|
+
export const LoggerService = Symbol('LoggerService');
|
|
6
8
|
|
|
7
9
|
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
export interface LogMessage {
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
traceId?: string;
|
|
13
|
+
context?: string;
|
|
14
|
+
message: any;
|
|
15
|
+
}
|
|
8
16
|
|
|
9
17
|
export interface Logger {
|
|
10
18
|
/*
|
|
@@ -16,6 +24,15 @@ export interface Logger {
|
|
|
16
24
|
error(message: any, context?: string): void;
|
|
17
25
|
warn(message: any, context?: string): void;
|
|
18
26
|
debug(message: any, context?: string): void;
|
|
27
|
+
time(label: string): void;
|
|
28
|
+
timeEnd(label: string, context?: string): number | undefined;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const onLogEmitter = new Emitter<LogMessage>();
|
|
33
|
+
|
|
34
|
+
export interface LoggerService {
|
|
35
|
+
readonly onLog: Event<LogMessage>;
|
|
19
36
|
}
|
|
20
37
|
|
|
21
38
|
export interface TraceIdProvider {
|
|
@@ -7,24 +7,24 @@ import { Logger } from './logger-protocol';
|
|
|
7
7
|
export class LoggerImpl extends AbstractLogger {
|
|
8
8
|
|
|
9
9
|
error(message: any, context?: string): void {
|
|
10
|
-
this.
|
|
10
|
+
this.log(message, context, console.error.bind(console));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
info(message: any, context?: string): void {
|
|
14
14
|
if (['info', 'debug'].includes(this.level)) {
|
|
15
|
-
this.
|
|
15
|
+
this.log(message, context);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
warn(message: any, context?: string): void {
|
|
20
20
|
if (['info', 'debug', 'warn'].includes(this.level)) {
|
|
21
|
-
this.
|
|
21
|
+
this.log(message, context, console.warn.bind(console));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
debug(message: any, context?: string): void {
|
|
26
26
|
if (this.level === 'debug') {
|
|
27
|
-
this.
|
|
27
|
+
this.log(message, context, console.debug.bind(console));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Injectable } from '../annotation';
|
|
2
|
-
import { Logger } from '../logger/logger-protocol';
|
|
2
|
+
import { Logger, LogLevel, LogMessage } from '../logger/logger-protocol';
|
|
3
|
+
import { Emitter } from '../utils';
|
|
3
4
|
|
|
4
5
|
@Injectable()
|
|
5
6
|
export class MockLogger implements Logger {
|
|
7
|
+
level: LogLevel = 'info';
|
|
8
|
+
protected readonly onLogEmitter = new Emitter<LogMessage>();
|
|
9
|
+
onLog = this.onLogEmitter.event;
|
|
10
|
+
time(label: string): void {
|
|
11
|
+
// do nothing
|
|
12
|
+
}
|
|
13
|
+
timeEnd(label: string, context?: string): number | undefined {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
6
16
|
setContext(context?: string): void {
|
|
7
17
|
// do nothing
|
|
8
18
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export abstract class ErrorUtil {
|
|
2
|
+
/**
|
|
3
|
+
* Fix the prototype chain of the error
|
|
4
|
+
*
|
|
5
|
+
* Use Object.setPrototypeOf
|
|
6
|
+
* Support ES6 environments
|
|
7
|
+
*
|
|
8
|
+
* Fallback setting __proto__
|
|
9
|
+
* Support IE11+, see https://docs.microsoft.com/en-us/scripting/javascript/reference/javascript-version-information
|
|
10
|
+
*/
|
|
11
|
+
static fixProto(target: Error, prototype: {}) {
|
|
12
|
+
const setPrototypeOf: Function = (Object as any).setPrototypeOf;
|
|
13
|
+
if (setPrototypeOf) {
|
|
14
|
+
setPrototypeOf(target, prototype);
|
|
15
|
+
} else {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
target.__proto__ = prototype;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Capture and fix the error stack when available
|
|
24
|
+
*
|
|
25
|
+
* Use Error.captureStackTrace
|
|
26
|
+
* Support v8 environments
|
|
27
|
+
*/
|
|
28
|
+
static fixStack(target: Error, fn: Function = target.constructor) {
|
|
29
|
+
const captureStackTrace: Function = (Error as any).captureStackTrace;
|
|
30
|
+
if (captureStackTrace) {
|
|
31
|
+
captureStackTrace(target, fn);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|