@celljs/core 3.6.4 → 3.6.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.
Files changed (33) hide show
  1. package/lib/common/error/custom-error.d.ts +25 -2
  2. package/lib/common/error/custom-error.d.ts.map +1 -1
  3. package/lib/common/error/custom-error.js +38 -2
  4. package/lib/common/error/custom-error.js.map +1 -1
  5. package/lib/common/logger/abstract-logger.d.ts +9 -3
  6. package/lib/common/logger/abstract-logger.d.ts.map +1 -1
  7. package/lib/common/logger/abstract-logger.js +29 -1
  8. package/lib/common/logger/abstract-logger.js.map +1 -1
  9. package/lib/common/logger/logger-protocol.d.ts +11 -0
  10. package/lib/common/logger/logger-protocol.d.ts.map +1 -1
  11. package/lib/common/logger/logger-protocol.js.map +1 -1
  12. package/lib/common/logger/logger.js +4 -4
  13. package/lib/common/logger/logger.js.map +1 -1
  14. package/lib/common/test/mock-logger.d.ts +7 -1
  15. package/lib/common/test/mock-logger.d.ts.map +1 -1
  16. package/lib/common/test/mock-logger.js +12 -0
  17. package/lib/common/test/mock-logger.js.map +1 -1
  18. package/lib/common/utils/error-util.d.ts +20 -0
  19. package/lib/common/utils/error-util.d.ts.map +1 -0
  20. package/lib/common/utils/error-util.js +39 -0
  21. package/lib/common/utils/error-util.js.map +1 -0
  22. package/lib/common/utils/index.d.ts +1 -0
  23. package/lib/common/utils/index.d.ts.map +1 -1
  24. package/lib/common/utils/index.js +1 -0
  25. package/lib/common/utils/index.js.map +1 -1
  26. package/package.json +3 -4
  27. package/src/common/error/custom-error.ts +43 -2
  28. package/src/common/logger/abstract-logger.ts +31 -4
  29. package/src/common/logger/logger-protocol.ts +12 -0
  30. package/src/common/logger/logger.ts +4 -4
  31. package/src/common/test/mock-logger.ts +11 -1
  32. package/src/common/utils/error-util.ts +34 -0
  33. package/src/common/utils/index.ts +1 -0
@@ -1,4 +1,27 @@
1
- import { CustomError as BaseCustomError } from 'ts-custom-error';
2
- export declare class CustomError extends BaseCustomError {
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":"AAAA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEjE,qBAAa,WAAY,SAAQ,eAAe;CAE/C"}
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 ts_custom_error_1 = require("ts-custom-error");
5
- class CustomError extends ts_custom_error_1.CustomError {
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,qDAAiE;AAEjE,MAAa,WAAY,SAAQ,6BAAe;CAE/C;AAFD,kCAEC"}
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"}
@@ -1,11 +1,17 @@
1
- import { Logger, LogLevel, TraceIdProvider } from './logger-protocol';
1
+ import { Emitter } from '../utils';
2
+ import { Logger, LogLevel, LogMessage, TraceIdProvider } from './logger-protocol';
2
3
  export declare abstract class AbstractLogger implements Logger {
4
+ protected readonly onLogEmitter: Emitter<LogMessage>;
5
+ readonly onLog: import("../utils").Event<LogMessage>;
3
6
  protected instance: Logger;
4
7
  protected context?: string;
5
- protected level: LogLevel;
8
+ level: LogLevel;
6
9
  protected readonly traceIdProvider?: TraceIdProvider;
10
+ protected timeRecords: Map<string, number>;
7
11
  setContext(context?: string): void;
8
- protected call(logFn: (...args: any[]) => void, message: any, context?: string): void;
12
+ protected log(message: any, context?: string, logFn?: (...args: any[]) => void): void;
13
+ time(label: string): void;
14
+ timeEnd(label: string, context?: string): number | undefined;
9
15
  abstract info(message: any, context?: string | undefined): void;
10
16
  abstract error(message: any, context?: string | undefined): void;
11
17
  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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpF,8BAAsB,cAAe,YAAW,MAAM;IAClD,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAG3B,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC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AAS,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"}
@@ -11,12 +11,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AbstractLogger = void 0;
13
13
  const annotation_1 = require("../annotation");
14
+ const utils_1 = require("../utils");
14
15
  const logger_protocol_1 = require("./logger-protocol");
15
16
  class AbstractLogger {
17
+ constructor() {
18
+ this.onLogEmitter = new utils_1.Emitter();
19
+ this.onLog = this.onLogEmitter.event;
20
+ this.timeRecords = new Map();
21
+ }
16
22
  setContext(context) {
17
23
  this.context = context;
18
24
  }
19
- call(logFn, message, context) {
25
+ log(message, context, logFn = console.info) {
20
26
  var _a;
21
27
  context = context !== null && context !== void 0 ? context : this.context;
22
28
  const time = new Date().toISOString();
@@ -24,6 +30,28 @@ class AbstractLogger {
24
30
  const traceStr = traceId ? ` [trace: ${traceId}]` : '';
25
31
  const contextStr = this.context ? ` [${this.context}]` : '';
26
32
  logFn(`${time} [${this.level}]${traceStr}${contextStr} ${message}`);
33
+ this.onLogEmitter.fire({
34
+ level: this.level,
35
+ traceId,
36
+ context,
37
+ message
38
+ });
39
+ }
40
+ time(label) {
41
+ this.timeRecords.set(label, Date.now());
42
+ }
43
+ timeEnd(label, context) {
44
+ const start = this.timeRecords.get(label);
45
+ if (start !== undefined) {
46
+ const duration = Date.now() - start;
47
+ this.timeRecords.delete(label);
48
+ this.log(`${label}: ${duration}ms`, context);
49
+ return duration;
50
+ }
51
+ else {
52
+ this.log(`No such label: ${label} for timeEnd`, context);
53
+ return;
54
+ }
27
55
  }
28
56
  }
29
57
  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,uDAAoF;AAEpF,MAAsB,cAAc;IAUhC,UAAU,CAAC,OAAgB;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAES,IAAI,CAAC,KAA+B,EAAE,OAAY,EAAE,OAAgB;;QAC1E,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,I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EL = "cell.logger.level";
3
4
  export declare const Logger: unique symbol;
4
5
  export declare const TraceIdProvider: unique symbol;
5
6
  export type LogLevel = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
7
+ export interface LogMessage {
8
+ level: LogLevel;
9
+ traceId?: string;
10
+ context?: string;
11
+ message: any;
12
+ }
6
13
  export interface Logger {
14
+ level: LogLevel;
15
+ readonly onLog: Event<LogMessage>;
7
16
  setContext(context?: string): void;
8
17
  info(message: any, context?: string): void;
9
18
  error(message: any, context?: string): void;
10
19
  warn(message: any, context?: string): void;
11
20
  debug(message: any, context?: string): void;
21
+ time(label: string): void;
22
+ timeEnd(label: string, context?: string): number | undefined;
12
23
  }
13
24
  export interface TraceIdProvider {
14
25
  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;AAEzD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvE,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,C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,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAEhE;AAED,MAAM,WAAW,eAAe;IAC5B,OAAO,IAAI,MAAM,GAAG,SAAS,CAAC;CACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger-protocol.js","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":";;;AAAa,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"}
1
+ {"version":3,"file":"logger-protocol.js","sourceRoot":"","sources":["../../../src/common/logger/logger-protocol.ts"],"names":[],"mappings":";;;AACa,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"}
@@ -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.call(console.error.bind(console), message, context);
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.call(console.info.bind(console), message, context);
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.call(console.warn.bind(console), message, context);
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.call(console.debug.bind(console), message, context);
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,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7D,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,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,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,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAY,EAAE,OAAgB;QAChC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;CAEJ,CAAA;AA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L,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;AAEnD,qBACa,UAAW,YAAW,MAAM;IACrC,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"}
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;AAIpC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACnB,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;AAhBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,uBAAU,GAAE;GACA,UAAU,CAgBtB"}
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"}
@@ -18,4 +18,5 @@ export * from './assert';
18
18
  export * from './mime-type-util';
19
19
  export * from './mime-type';
20
20
  export * from './byte-util';
21
+ export * from './error-util';
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -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.4",
3
+ "version": "3.6.6",
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.4",
47
+ "@celljs/component": "3.6.6",
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": "136649727fd8ca2c3c982dce6c5066805c88ac56"
54
+ "gitHead": "d07565d0b4ef172b52bbdfb9c780fdf73015feac"
56
55
  }
@@ -1,5 +1,46 @@
1
- import { CustomError as BaseCustomError } from 'ts-custom-error';
1
+ import { ErrorUtil } from '../utils';
2
2
 
3
- export class CustomError extends BaseCustomError {
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,59 @@
1
1
  import { Autowired, Optional, Value } from '../annotation';
2
- import { Logger, LOGGER_LEVEL, LogLevel, TraceIdProvider } from './logger-protocol';
2
+ import { Emitter } from '../utils';
3
+ import { Logger, LOGGER_LEVEL, LogLevel, LogMessage, TraceIdProvider } from './logger-protocol';
3
4
 
4
5
  export abstract class AbstractLogger implements Logger {
6
+ protected readonly onLogEmitter = new Emitter<LogMessage>();
7
+ readonly onLog = this.onLogEmitter.event;
5
8
  protected instance: Logger;
6
9
  protected context?: string;
7
10
 
8
11
  @Value(`${LOGGER_LEVEL} ?: 'info'`)
9
- protected level: LogLevel;
12
+ level: LogLevel;
10
13
 
11
14
  @Autowired(TraceIdProvider) @Optional()
12
15
  protected readonly traceIdProvider?: TraceIdProvider;
13
16
 
17
+ protected timeRecords: Map<string, number> = new Map();
18
+
14
19
  setContext(context?: string): void {
15
20
  this.context = context;
16
21
  }
17
22
 
18
- protected call(logFn: (...args: any[]) => void, message: any, context?: string): void {
23
+ protected log(message: any, context?: string, logFn: (...args: any[]) => void = console.info): void {
19
24
  context = context ?? this.context;
20
25
  const time = new Date().toISOString();
21
26
  const traceId = this.traceIdProvider?.provide();
22
27
  const traceStr = traceId ? ` [trace: ${traceId}]` : '';
23
28
  const contextStr = this.context ? ` [${this.context}]` : '';
24
29
  logFn(`${time} [${this.level}]${traceStr}${contextStr} ${message}`);
30
+ this.onLogEmitter.fire({
31
+ level: this.level,
32
+ traceId,
33
+ context,
34
+ message
35
+ });
36
+ }
37
+
38
+ time(label: string): void {
39
+ this.timeRecords.set(label, Date.now());
40
+ }
41
+
42
+ timeEnd(label: string, context?: string): number | undefined {
43
+ const start = this.timeRecords.get(label);
44
+ if (start !== undefined) {
45
+ const duration = Date.now() - start;
46
+ this.timeRecords.delete(label);
47
+ this.log(`${label}: ${duration}ms`, context);
48
+ return duration;
49
+ } else {
50
+ this.log(`No such label: ${label} for timeEnd`, context);
51
+ return;
52
+ }
25
53
  }
26
54
 
27
55
  abstract info(message: any, context?: string | undefined): void;
28
56
  abstract error(message: any, context?: string | undefined): void;
29
57
  abstract warn(message: any, context?: string | undefined): void;
30
58
  abstract debug(message: any, context?: string | undefined): void;
31
-
32
59
  }
@@ -1,3 +1,4 @@
1
+ import { Event } from '../utils';
1
2
  export const LOGGER_CONFIG = 'cell.logger';
2
3
  export const LOGGER_LEVEL = `${LOGGER_CONFIG}.level`;
3
4
 
@@ -5,8 +6,16 @@ export const Logger = Symbol('Logger');
5
6
  export const TraceIdProvider = Symbol('TraceIdProvider');
6
7
 
7
8
  export type LogLevel = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
9
+ export interface LogMessage {
10
+ level: LogLevel;
11
+ traceId?: string;
12
+ context?: string;
13
+ message: any;
14
+ }
8
15
 
9
16
  export interface Logger {
17
+ level: LogLevel;
18
+ readonly onLog: Event<LogMessage>;
10
19
  /*
11
20
  * Set the context information of the log object level. When printing the log, the context will be carried.
12
21
  * If the context of the log method level is additionally specified when printing the log, the occlusion overrides the context of the log object level
@@ -16,6 +25,9 @@ export interface Logger {
16
25
  error(message: any, context?: string): void;
17
26
  warn(message: any, context?: string): void;
18
27
  debug(message: any, context?: string): void;
28
+ time(label: string): void;
29
+ timeEnd(label: string, context?: string): number | undefined;
30
+
19
31
  }
20
32
 
21
33
  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.call(console.error.bind(console), message, context);
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.call(console.info.bind(console), message, context);
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.call(console.warn.bind(console), message, context);
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.call(console.debug.bind(console), message, context);
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
+ }
@@ -18,3 +18,4 @@ export * from './assert';
18
18
  export * from './mime-type-util';
19
19
  export * from './mime-type';
20
20
  export * from './byte-util';
21
+ export * from './error-util';