standard-log 11.4.1 → 11.5.0

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/README.md CHANGED
@@ -41,6 +41,11 @@ log.info('info message')
41
41
  // by default debug() will not be printed
42
42
  // because production mode defaults log level to `info`
43
43
  log.debug('debug message')
44
+
45
+ // If the message is consume resource to generage,
46
+ // you can use `log.on()` so that it will be called only
47
+ // if the level is met.
48
+ log.on(logLevels.trace, () => prettify(someValue))
44
49
  ```
45
50
 
46
51
  ![Rendering example][rendering-example]
package/cjs/logger.js CHANGED
@@ -50,11 +50,12 @@ function createLogger(store, id, options) {
50
50
  on: {
51
51
  writable: false,
52
52
  value: function (level, logFn) {
53
+ var _a;
53
54
  var logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
54
55
  if (shouldLog(store, logLevel, logger.level)) {
55
56
  var methodName = store.logLevelStore.getName(logLevel);
56
57
  var bindedMethod = logger[methodName].bind(logger);
57
- var result = logFn(bindedMethod);
58
+ var result = logFn(bindedMethod, (_a = logger.level) !== null && _a !== void 0 ? _a : store.logLevel);
58
59
  if (result)
59
60
  bindedMethod(result);
60
61
  }
package/cjs/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,KAAe,EAAE,EAAU,EAAE,OAAuB;;IAEpD,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAC1C,IAAA,KAAwE,OAAO,OAAO,KAAK,QAAQ;QACvG,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,EAAE,KAAK,OAAO,EAAd,CAAc,EAAE,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AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,EAAE,CAAC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAwB,EAAE,QAAkB,EAAE,MAAuC;IAC7G,SAAS,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,EAAlB,CAAkB,CAAC,CAAA;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC1F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC","sourcesContent":["import { logLevels } from './logLevels.js'\nimport { LogStore } from './logStore.js'\nimport type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<N extends string = LogMethodNames>(\n store: LogStore, id: string, options?: LoggerOptions\n): Logger<N | LogMethodNames> {\n id = sanitizeId(id)\n const writeTo = options?.writeTo ?? (() => true)\n const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'\n ? [id => id === writeTo, store.reporters]\n : writeTo instanceof RegExp\n ? [id => writeTo.test(id), store.reporters]\n : typeof writeTo === 'function'\n ? [writeTo, store.reporters]\n : [() => true, [writeTo]]\n\n function write(entry: LogEntry) {\n writeToReporters(reporters, entry, filter)\n }\n\n const logger = {\n level: options?.level,\n write\n } as any\n\n Object.defineProperties(logger, {\n id: { value: id, writable: false },\n count: {\n writable: false,\n value: ((counter) => (...args: any[]) => {\n if (shouldLog(store, logLevels.debug, logger.level))\n write({\n id,\n level: logLevels.debug,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n if (shouldLog(store, logLevel, logger.level)) {\n const methodName = store.logLevelStore.getName(logLevel)\n const bindedMethod = logger[methodName].bind(logger)\n const result = logFn(bindedMethod)\n if (result) bindedMethod(result)\n }\n }\n }\n })\n store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n Object.defineProperty(logger, name, {\n writable: false,\n value: (...args: any[]) => {\n if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n }\n })\n })\n return logger\n}\n\nfunction sanitizeId(id: string) {\n return id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {\n reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,KAAe,EAAE,EAAU,EAAE,OAAuB;;IAEpD,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAC1C,IAAA,KAAwE,OAAO,OAAO,KAAK,QAAQ;QACvG,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,O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F,CAAC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AA1DD,oCA0DC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,EAAE,CAAC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAwB,EAAE,QAAkB,EAAE,MAAuC;IAC7G,SAAS,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,EAAlB,CAAkB,CAAC,CAAA;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC1F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC","sourcesContent":["import { logLevels } from './logLevels.js'\nimport { LogStore } from './logStore.js'\nimport type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<N extends string = LogMethodNames>(\n store: LogStore, id: string, options?: LoggerOptions\n): Logger<N | LogMethodNames> {\n id = sanitizeId(id)\n const writeTo = options?.writeTo ?? (() => true)\n const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'\n ? [id => id === writeTo, store.reporters]\n : writeTo instanceof RegExp\n ? [id => writeTo.test(id), store.reporters]\n : typeof writeTo === 'function'\n ? [writeTo, store.reporters]\n : [() => true, [writeTo]]\n\n function write(entry: LogEntry) {\n writeToReporters(reporters, entry, filter)\n }\n\n const logger = {\n level: options?.level,\n write\n } as any\n\n Object.defineProperties(logger, {\n id: { value: id, writable: false },\n count: {\n writable: false,\n value: ((counter) => (...args: any[]) => {\n if (shouldLog(store, logLevels.debug, logger.level))\n write({\n id,\n level: logLevels.debug,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n if (shouldLog(store, logLevel, logger.level)) {\n const methodName = store.logLevelStore.getName(logLevel)\n const bindedMethod = logger[methodName].bind(logger)\n const result = logFn(bindedMethod, logger.level ?? store.logLevel)\n if (result) bindedMethod(result)\n }\n }\n }\n })\n store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n Object.defineProperty(logger, name, {\n writable: false,\n value: (...args: any[]) => {\n if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n }\n })\n })\n return logger\n}\n\nfunction sanitizeId(id: string) {\n return id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {\n reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
package/cjs/types.d.ts CHANGED
@@ -38,7 +38,7 @@ export declare type LogEntry = {
38
38
  timestamp: Date;
39
39
  };
40
40
  export declare type LogMethod = (...args: any[]) => void;
41
- export declare type LogFunction = ((log: LogMethod) => void) | (() => string);
41
+ export declare type LogFunction = (log: LogMethod, logLevel: number) => string | void;
42
42
  export declare type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
43
43
  export interface StandardLogInstance<N extends string = LogMethodNames> {
44
44
  logLevel: number;
@@ -1 +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AG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7B"}
package/cjs/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n customLevels?: Record<CustomLevelNames, number>,\n logLevel?: number,\n reporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n level?: number,\n writeTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | N, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = ((log: LogMethod) => void) | (() => string)\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,\n getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string, level: number }\n\nexport interface LogReporter<T = any> {\n readonly id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n readonly formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n readonly filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n */\n readonly isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n debug(...args: any[]): void,\n info(...args: any[]): void,\n warn(...args: any[]): void,\n error(...args: any[]): void,\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n customLevels?: Record<CustomLevelNames, number>,\n logLevel?: number,\n reporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n level?: number,\n writeTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | N, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,\n getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string, level: number }\n\nexport interface LogReporter<T = any> {\n readonly id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n readonly formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n readonly filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n */\n readonly isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n debug(...args: any[]): void,\n info(...args: any[]): void,\n warn(...args: any[]): void,\n error(...args: any[]): void,\n}\n"]}
@@ -5918,7 +5918,7 @@ var __extends = (this && this.__extends) || (function () {
5918
5918
  })();
5919
5919
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5920
5920
  exports.InvalidId = exports.StandardLogError = void 0;
5921
- var iso_error_1 = __webpack_require__(/*! iso-error */ "../../node_modules/.pnpm/iso-error@4.4.0/node_modules/iso-error/cjs/index.js");
5921
+ var iso_error_1 = __webpack_require__(/*! iso-error */ "../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/cjs/index.js");
5922
5922
  /**
5923
5923
  * @deprecated No longer used since 11.2.0
5924
5924
  */
@@ -6304,11 +6304,12 @@ function createLogger(store, id, options) {
6304
6304
  on: {
6305
6305
  writable: false,
6306
6306
  value: function (level, logFn) {
6307
+ var _a;
6307
6308
  var logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
6308
6309
  if (shouldLog(store, logLevel, logger.level)) {
6309
6310
  var methodName = store.logLevelStore.getName(logLevel);
6310
6311
  var bindedMethod = logger[methodName].bind(logger);
6311
- var result = logFn(bindedMethod);
6312
+ var result = logFn(bindedMethod, (_a = logger.level) !== null && _a !== void 0 ? _a : store.logLevel);
6312
6313
  if (result)
6313
6314
  bindedMethod(result);
6314
6315
  }
@@ -6655,40 +6656,19 @@ exports.upperCase = upperCase;
6655
6656
 
6656
6657
  /***/ }),
6657
6658
 
6658
- /***/ "../../node_modules/.pnpm/iso-error@4.4.0/node_modules/iso-error/cjs/index.js":
6659
+ /***/ "../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/cjs/index.js":
6659
6660
  /*!************************************************************************************!*\
6660
- !*** ../../node_modules/.pnpm/iso-error@4.4.0/node_modules/iso-error/cjs/index.js ***!
6661
+ !*** ../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/cjs/index.js ***!
6661
6662
  \************************************************************************************/
6662
6663
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
6663
6664
 
6664
6665
  "use strict";
6665
6666
 
6666
6667
  /* eslint-disable @typescript-eslint/unbound-method */
6667
- var __extends = (this && this.__extends) || (function () {
6668
- var extendStatics = function (d, b) {
6669
- extendStatics = Object.setPrototypeOf ||
6670
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6671
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6672
- return extendStatics(d, b);
6673
- };
6674
- return function (d, b) {
6675
- if (typeof b !== "function" && b !== null)
6676
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
6677
- extendStatics(d, b);
6678
- function __() { this.constructor = d; }
6679
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6680
- };
6681
- })();
6682
- var __assign = (this && this.__assign) || function () {
6683
- __assign = Object.assign || function(t) {
6684
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6685
- s = arguments[i];
6686
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6687
- t[p] = s[p];
6688
- }
6689
- return t;
6690
- };
6691
- return __assign.apply(this, arguments);
6668
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
6669
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
6670
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
6671
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6692
6672
  };
6693
6673
  var __rest = (this && this.__rest) || function (s, e) {
6694
6674
  var t = {};
@@ -6701,13 +6681,14 @@ var __rest = (this && this.__rest) || function (s, e) {
6701
6681
  }
6702
6682
  return t;
6703
6683
  };
6684
+ var _SerializableConverter_instances, _SerializableConverter_plugins, _SerializableConverter_fromSerializable, _SerializableConverter_deserializeError, _SerializableConverter_toSerializable, _a, _IsoError_hasCause, _IsoError_toIsoError;
6704
6685
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6705
- exports.isAggregateError = exports.ModuleError = exports.IsoError = void 0;
6686
+ exports.isAggregateError = exports.ModuleError = exports.IsoError = exports.SerializableConverter = void 0;
6706
6687
  //#region captureStackTrace polyfill
6707
6688
  // istanbul ignore next
6708
6689
  if (!Error.captureStackTrace) {
6709
6690
  Error.captureStackTrace = function (error) {
6710
- var container = new Error();
6691
+ const container = new Error();
6711
6692
  Object.defineProperty(error, 'stack', {
6712
6693
  configurable: true,
6713
6694
  get: function () {
@@ -6723,260 +6704,210 @@ if (!Error.captureStackTrace) {
6723
6704
  function defineStack(target, value) {
6724
6705
  Object.defineProperty(target, 'stack', {
6725
6706
  configurable: true,
6726
- value: value,
6707
+ value,
6727
6708
  writable: true,
6728
6709
  });
6729
6710
  }
6730
- var serializers = [];
6731
- var deserializers = [];
6732
- /**
6733
- * Isomorphic Error that works across physical boundary.
6734
- */
6735
- var IsoError = /** @class */ (function (_super) {
6736
- __extends(IsoError, _super);
6737
- function IsoError(message, options) {
6738
- var _newTarget = this.constructor;
6739
- var _this = _super.call(this, message) || this;
6740
- /**
6741
- * Name of the error
6742
- */
6743
- Object.defineProperty(_this, "name", {
6744
- enumerable: true,
6745
- configurable: true,
6746
- writable: true,
6747
- value: void 0
6748
- });
6749
- /**
6750
- * Error cause
6751
- */
6752
- Object.defineProperty(_this, "cause", {
6753
- enumerable: true,
6754
- configurable: true,
6755
- writable: true,
6756
- value: void 0
6757
- });
6758
- //restore prototype chain
6759
- var actualProto = _newTarget.prototype;
6760
- _this.name = actualProto.constructor.name;
6761
- // istanbul ignore next
6762
- if (Object.setPrototypeOf)
6763
- Object.setPrototypeOf(_this, actualProto);
6764
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6765
- else
6766
- _this.__proto__ = actualProto;
6767
- if (options === null || options === void 0 ? void 0 : options.cause)
6768
- _this.cause = toIsoError(options.cause);
6769
- if (options === null || options === void 0 ? void 0 : options.ssf)
6770
- Error.captureStackTrace(_this, options.ssf);
6771
- return _this;
6711
+ class SerializableConverter {
6712
+ constructor() {
6713
+ _SerializableConverter_instances.add(this);
6714
+ _SerializableConverter_plugins.set(this, []);
6715
+ }
6716
+ addPlugin(plugin) {
6717
+ __classPrivateFieldGet(this, _SerializableConverter_plugins, "f").unshift(plugin);
6772
6718
  }
6773
6719
  /**
6774
- * Create an IsoError with additional properties without the need to create a new class.
6775
- * @param props properties of the IsoError
6776
- */
6777
- Object.defineProperty(IsoError, "create", {
6778
- enumerable: false,
6779
- configurable: true,
6780
- writable: true,
6781
- value: function (props) {
6782
- var message = props.message, cause = props.cause, rest = __rest(props, ["message", "cause"]);
6783
- var err = new IsoError(message, { cause: cause, ssf: IsoError.create });
6784
- return Object.assign(err, rest);
6785
- }
6786
- });
6787
- Object.defineProperty(IsoError, "stringify", {
6788
- enumerable: false,
6789
- configurable: true,
6790
- writable: true,
6791
- value: function (err) {
6792
- return this.serialize(err);
6793
- }
6794
- });
6795
- Object.defineProperty(IsoError, "serialize", {
6796
- enumerable: false,
6797
- configurable: true,
6798
- writable: true,
6799
- value: function (err) {
6800
- return JSON.stringify(this.toSerializable(err));
6801
- }
6802
- });
6803
- /**
6804
- * @type P Additional properties of the IsoError
6805
- * @param text Json representation of a IsoError
6806
- */
6807
- Object.defineProperty(IsoError, "parse", {
6808
- enumerable: false,
6809
- configurable: true,
6810
- writable: true,
6811
- value: function (text) {
6812
- return deserialize(IsoError.parse, text);
6813
- }
6814
- });
6815
- /**
6816
- * @type P Additional properties of the IsoError
6817
- * @param text Json representation of a IsoError
6720
+ * Deserialize an `Error` from `Serializable`
6818
6721
  */
6819
- Object.defineProperty(IsoError, "deserialize", {
6820
- enumerable: false,
6821
- configurable: true,
6822
- writable: true,
6823
- value: function (text) {
6824
- return deserialize(IsoError.deserialize, text);
6825
- }
6826
- });
6827
- Object.defineProperty(IsoError, "toSerializable", {
6828
- enumerable: false,
6829
- configurable: true,
6830
- writable: true,
6831
- value: function (err) {
6832
- return serializers.reduce(function (p, s) { return p || s(err); }, undefined)
6833
- || toSerializableError(err);
6834
- }
6835
- });
6836
- Object.defineProperty(IsoError, "fromSerializable", {
6837
- enumerable: false,
6838
- configurable: true,
6839
- writable: true,
6840
- value: function (json) {
6841
- var err = deserializeError(json);
6842
- Error.captureStackTrace(err, IsoError.fromSerializable);
6843
- return err;
6844
- }
6845
- });
6722
+ fromSerializable(json, options) {
6723
+ const err = __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_deserializeError).call(this, json);
6724
+ Error.captureStackTrace(err, options === null || options === void 0 ? void 0 : options.ssf);
6725
+ return err;
6726
+ }
6846
6727
  /**
6847
- * returns the error message including the error causes.
6728
+ * Serialize `Error` to `Serializable`
6848
6729
  */
6849
- Object.defineProperty(IsoError, "trace", {
6850
- enumerable: false,
6851
- configurable: true,
6852
- writable: true,
6853
- value: function (err) {
6854
- return trace(err);
6855
- }
6856
- });
6857
- Object.defineProperty(IsoError, "addPlugin", {
6858
- enumerable: false,
6859
- configurable: true,
6860
- writable: true,
6861
- value: function (_a) {
6862
- var toSerializable = _a.toSerializable, fromSerializable = _a.fromSerializable;
6863
- serializers.unshift(toSerializable);
6864
- deserializers.unshift(fromSerializable);
6865
- }
6866
- });
6867
- Object.defineProperty(IsoError.prototype, "toString", {
6868
- enumerable: false,
6869
- configurable: true,
6870
- writable: true,
6871
- value: function () { return IsoError.serialize(this); }
6872
- });
6873
- Object.defineProperty(IsoError.prototype, "trace", {
6874
- enumerable: false,
6875
- configurable: true,
6876
- writable: true,
6877
- value: function () { return IsoError.trace(this); }
6878
- });
6879
- return IsoError;
6880
- }(Error));
6881
- exports.IsoError = IsoError;
6882
- function deserialize(fn, text) {
6883
- var json = JSON.parse(text);
6884
- var err = deserializeError(json);
6885
- Error.captureStackTrace(err, fn);
6886
- return err;
6887
- }
6888
- function deserializeError(json) {
6889
- var err = undefined;
6890
- for (var _i = 0, deserializers_1 = deserializers; _i < deserializers_1.length; _i++) {
6891
- var d = deserializers_1[_i];
6892
- err = d(json);
6893
- if (err)
6894
- break;
6730
+ toSerializable(err) {
6731
+ return __classPrivateFieldGet(this, _SerializableConverter_plugins, "f").reduce((p, s) => p || s.toSerializable(err), undefined) || __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable).call(this, err);
6895
6732
  }
6896
- return err || defaultDeserializeError(json);
6897
6733
  }
6898
- function defaultDeserializeError(json) {
6734
+ exports.SerializableConverter = SerializableConverter;
6735
+ _SerializableConverter_plugins = new WeakMap(), _SerializableConverter_instances = new WeakSet(), _SerializableConverter_fromSerializable = function _SerializableConverter_fromSerializable(json) {
6899
6736
  if (json.name === 'AggregateError') {
6900
- var _a = json, message_1 = _a.message, errors = _a.errors, rest_1 = __rest(_a, ["message", "errors"]);
6737
+ const _b = json, { message, errors } = _b, rest = __rest(_b, ["message", "errors"]);
6901
6738
  // @ts-ignore
6739
+ // istanbul ignore next
6902
6740
  if (__webpack_require__.g.AggregateError) {
6903
- return Object.assign(new AggregateError(errors, message_1), rest_1);
6741
+ return Object.assign(new AggregateError(errors, message), rest);
6904
6742
  }
6905
6743
  else {
6906
- return Object.assign(new Error(message_1), __assign(__assign({}, rest_1), { errors: errors }));
6744
+ return Object.assign(new Error(message), Object.assign(Object.assign({}, rest), { errors }));
6907
6745
  }
6908
6746
  }
6909
- var _b = json, message = _b.message, cause = _b.cause, rest = __rest(_b, ["message", "cause"]);
6910
- var causeError = cause ? deserializeError(cause) : undefined;
6747
+ const { message, cause } = json, rest = __rest(json, ["message", "cause"]);
6748
+ const causeError = cause ? __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_deserializeError).call(this, cause) : undefined;
6911
6749
  if (json.name === 'Error') {
6912
- return Object.assign(new Error(message), causeError ? __assign(__assign({}, rest), { cause: causeError }) : rest);
6750
+ return Object.assign(new Error(message), causeError ? Object.assign(Object.assign({}, rest), { cause: causeError }) : rest);
6913
6751
  }
6914
6752
  // @ts-ignore
6915
6753
  return Object.assign(new IsoError(message, causeError ? { cause: causeError } : undefined), rest);
6916
- }
6917
- function toSerializableError(err) {
6754
+ }, _SerializableConverter_deserializeError = function _SerializableConverter_deserializeError(json) {
6755
+ let err = undefined;
6756
+ for (const { fromSerializable } of __classPrivateFieldGet(this, _SerializableConverter_plugins, "f")) {
6757
+ err = fromSerializable(json);
6758
+ if (err)
6759
+ break;
6760
+ }
6761
+ return err || __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_fromSerializable).call(this, json);
6762
+ }, _SerializableConverter_toSerializable = function _SerializableConverter_toSerializable(err) {
6918
6763
  if (isAggregateError(err)) {
6919
- return __assign(__assign({}, err), { name: err.constructor.name, message: err.message, errors: err.errors.map(toSerializableError) });
6764
+ return Object.assign(Object.assign({}, err), { name: err.constructor.name, message: err.message, errors: err.errors.map(__classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable)) });
6920
6765
  }
6921
6766
  if (err instanceof Error) {
6922
- var message = err.message, cause = err.cause;
6767
+ const { message, cause } = err;
6923
6768
  return cause
6924
- ? __assign(__assign({}, err), { name: err.constructor.name, message: message, cause: toSerializableError(cause) }) : __assign(__assign({}, err), { name: err.constructor.name, message: message });
6769
+ ? Object.assign(Object.assign({}, err), { name: err.constructor.name, message, cause: __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable).call(this, cause) }) : Object.assign(Object.assign({}, err), { name: err.constructor.name, message });
6925
6770
  }
6926
6771
  return err;
6927
- }
6928
- // NOTE: In this function I have to to Object.assign to keep the err instance and its stack trace.
6929
- function toIsoError(err) {
6930
- if (err instanceof IsoError)
6931
- return err;
6932
- // When the error is an internal error from deserialzation,
6933
- // the err.constructor.name is object
6934
- return Object.assign(err, { name: err.constructor.name !== 'Object' ? err.constructor.name : err.name });
6935
- }
6936
- function trace(err) {
6937
- var messages = [];
6938
- if (err instanceof ModuleError) {
6939
- messages.push("".concat(err.name, "(").concat(err.module, "): ").concat(err.message));
6772
+ };
6773
+ /**
6774
+ * Isomorphic Error that works across physical boundary.
6775
+ */
6776
+ class IsoError extends Error {
6777
+ /**
6778
+ * Create an IsoError with additional properties without the need to create a new class.
6779
+ * @param props properties of the IsoError
6780
+ */
6781
+ static create(props) {
6782
+ const { message, cause } = props, rest = __rest(props, ["message", "cause"]);
6783
+ const err = new IsoError(message, { cause, ssf: IsoError.create });
6784
+ return Object.assign(err, rest);
6940
6785
  }
6941
- else if (err instanceof Error) {
6942
- messages.push("".concat(err.name, ": ").concat(err.message));
6786
+ static stringify(err) {
6787
+ return this.serialize(err);
6943
6788
  }
6944
- if (isAggregateError(err)) {
6945
- err.errors.forEach(function (e) { return messages.push.apply(messages, trace(e).split('\n').map(function (s) { return ' ' + s; })); });
6789
+ static serialize(err) {
6790
+ return JSON.stringify(this.toSerializable(err));
6946
6791
  }
6947
- if (err instanceof Error) {
6948
- if (hasCause(err))
6949
- messages.push.apply(messages, trace(err.cause).split('\n').map(function (s) { return ' ' + s; }));
6792
+ static toSerializable(err) {
6793
+ return this.converter.toSerializable(err);
6950
6794
  }
6951
- else {
6952
- messages.push(typeof err === 'string' ? err : JSON.stringify(err));
6795
+ /**
6796
+ * @type P Additional properties of the IsoError
6797
+ * @param text Json representation of a IsoError
6798
+ */
6799
+ static parse(text) {
6800
+ const json = JSON.parse(text);
6801
+ return this.converter.fromSerializable(json, { ssf: IsoError.parse });
6953
6802
  }
6954
- return messages.join('\n');
6803
+ /**
6804
+ * @type P Additional properties of the IsoError
6805
+ * @param text Json representation of a IsoError
6806
+ */
6807
+ static deserialize(text) {
6808
+ const json = JSON.parse(text);
6809
+ return this.converter.fromSerializable(json, { ssf: IsoError.deserialize });
6810
+ }
6811
+ static fromSerializable(json) {
6812
+ return this.converter.fromSerializable(json, { ssf: IsoError.fromSerializable });
6813
+ }
6814
+ /**
6815
+ * returns the error message including the error causes.
6816
+ */
6817
+ static trace(err) {
6818
+ const messages = [];
6819
+ if (err instanceof ModuleError) {
6820
+ messages.push(`${err.name}(${err.module}): ${err.message}`);
6821
+ }
6822
+ else if (err instanceof Error) {
6823
+ messages.push(`${err.name}: ${err.message}`);
6824
+ }
6825
+ if (isAggregateError(err)) {
6826
+ err.errors.forEach(e => messages.push(...this.trace(e).split('\n').map(s => ' ' + s)));
6827
+ }
6828
+ if (err instanceof Error) {
6829
+ if (__classPrivateFieldGet(this, _a, "m", _IsoError_hasCause).call(this, err))
6830
+ messages.push(...this.trace(err.cause).split('\n').map(s => ' ' + s));
6831
+ }
6832
+ else {
6833
+ messages.push(typeof err === 'string' ? err : JSON.stringify(err));
6834
+ }
6835
+ return messages.join('\n');
6836
+ }
6837
+ static addPlugin(plugin) {
6838
+ this.converter.addPlugin(plugin);
6839
+ }
6840
+ constructor(message, options) {
6841
+ super(message);
6842
+ /**
6843
+ * Name of the error
6844
+ */
6845
+ Object.defineProperty(this, "name", {
6846
+ enumerable: true,
6847
+ configurable: true,
6848
+ writable: true,
6849
+ value: void 0
6850
+ });
6851
+ /**
6852
+ * Error cause
6853
+ */
6854
+ Object.defineProperty(this, "cause", {
6855
+ enumerable: true,
6856
+ configurable: true,
6857
+ writable: true,
6858
+ value: void 0
6859
+ });
6860
+ // restore prototype chain
6861
+ const actualProto = new.target.prototype;
6862
+ this.name = actualProto.constructor.name;
6863
+ // istanbul ignore next
6864
+ if (Object.setPrototypeOf)
6865
+ Object.setPrototypeOf(this, actualProto);
6866
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6867
+ else
6868
+ this.__proto__ = actualProto;
6869
+ if (options === null || options === void 0 ? void 0 : options.cause)
6870
+ this.cause = __classPrivateFieldGet(IsoError, _a, "m", _IsoError_toIsoError).call(IsoError, options.cause);
6871
+ if (options === null || options === void 0 ? void 0 : options.ssf)
6872
+ Error.captureStackTrace(this, options.ssf);
6873
+ }
6874
+ toString() { return IsoError.serialize(this); }
6875
+ trace() { return IsoError.trace(this); }
6955
6876
  }
6956
- function hasCause(x) {
6877
+ exports.IsoError = IsoError;
6878
+ _a = IsoError, _IsoError_hasCause = function _IsoError_hasCause(x) {
6957
6879
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6958
6880
  return !!x.cause;
6959
- }
6881
+ }, _IsoError_toIsoError = function _IsoError_toIsoError(err) {
6882
+ if (err instanceof IsoError)
6883
+ return err;
6884
+ // When the error is an internal error from deserialization,
6885
+ // the err.constructor.name is object
6886
+ return Object.assign(err, { name: err.constructor.name !== 'Object' ? err.constructor.name : err.name });
6887
+ };
6888
+ Object.defineProperty(IsoError, "converter", {
6889
+ enumerable: true,
6890
+ configurable: true,
6891
+ writable: true,
6892
+ value: new SerializableConverter()
6893
+ });
6960
6894
  /**
6961
6895
  * An IsoError with a module property.
6962
6896
  */
6963
- var ModuleError = /** @class */ (function (_super) {
6964
- __extends(ModuleError, _super);
6897
+ class ModuleError extends IsoError {
6965
6898
  /**
6966
6899
  * @param module The module that defines this error.
6967
6900
  */
6968
- function ModuleError(module, message, options) {
6969
- var _this = _super.call(this, message, options) || this;
6970
- Object.defineProperty(_this, "module", {
6901
+ constructor(module, message, options) {
6902
+ super(message, options);
6903
+ Object.defineProperty(this, "module", {
6971
6904
  enumerable: true,
6972
6905
  configurable: true,
6973
6906
  writable: true,
6974
6907
  value: module
6975
6908
  });
6976
- return _this;
6977
6909
  }
6978
- return ModuleError;
6979
- }(IsoError));
6910
+ }
6980
6911
  exports.ModuleError = ModuleError;
6981
6912
  function isAggregateError(error) {
6982
6913
  return error instanceof Error && Array.isArray(error.errors);
Binary file