standard-log 11.4.0 → 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 +5 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +1 -1
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +4 -4
- package/cjs/logger.js.map +1 -1
- package/cjs/standardLog.ctx.d.ts +10 -0
- package/cjs/standardLog.ctx.d.ts.map +1 -0
- package/cjs/standardLog.ctx.js +6 -0
- package/cjs/standardLog.ctx.js.map +1 -0
- package/cjs/standardLog.d.ts +1 -15
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +14 -14
- package/cjs/standardLog.js.map +1 -1
- package/cjs/types.d.ts +9 -2
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +201 -269
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +200 -163
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +4 -4
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.ctx.d.ts +10 -0
- package/esm/standardLog.ctx.d.ts.map +1 -0
- package/esm/standardLog.ctx.js +3 -0
- package/esm/standardLog.ctx.js.map +1 -0
- package/esm/standardLog.d.ts +1 -15
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +1 -1
- package/esm/standardLog.js.map +1 -1
- package/esm/types.d.ts +9 -2
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +3 -3
- package/ts/index.ts +7 -2
- package/ts/logger.ts +3 -4
- package/ts/standardLog.ctx.ts +8 -0
- package/ts/standardLog.ts +2 -14
- package/ts/types.ts +10 -2
|
Binary file
|
package/dist/standard-log.esm.js
CHANGED
|
@@ -267,7 +267,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
267
267
|
/* harmony export */ "InvalidId": function() { return /* binding */ InvalidId; },
|
|
268
268
|
/* harmony export */ "StandardLogError": function() { return /* binding */ StandardLogError; }
|
|
269
269
|
/* harmony export */ });
|
|
270
|
-
/* harmony import */ var iso_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! iso-error */ "../../node_modules/.pnpm/iso-error@
|
|
270
|
+
/* harmony import */ var iso_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! iso-error */ "../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/esm/index.js");
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
273
|
* @deprecated No longer used since 11.2.0
|
|
@@ -582,11 +582,10 @@ function createLogger(store, id, options) {
|
|
|
582
582
|
count: {
|
|
583
583
|
writable: false,
|
|
584
584
|
value: ((counter) => (...args) => {
|
|
585
|
-
|
|
586
|
-
if (shouldLog(store, level, logger.level))
|
|
585
|
+
if (shouldLog(store, _logLevels_js__WEBPACK_IMPORTED_MODULE_0__.logLevels.debug, logger.level))
|
|
587
586
|
write({
|
|
588
587
|
id,
|
|
589
|
-
level,
|
|
588
|
+
level: _logLevels_js__WEBPACK_IMPORTED_MODULE_0__.logLevels.debug,
|
|
590
589
|
args: [++counter, ...args],
|
|
591
590
|
timestamp: new Date()
|
|
592
591
|
});
|
|
@@ -595,11 +594,12 @@ function createLogger(store, id, options) {
|
|
|
595
594
|
on: {
|
|
596
595
|
writable: false,
|
|
597
596
|
value: (level, logFn) => {
|
|
597
|
+
var _a;
|
|
598
598
|
const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
|
|
599
599
|
if (shouldLog(store, logLevel, logger.level)) {
|
|
600
600
|
const methodName = store.logLevelStore.getName(logLevel);
|
|
601
601
|
const bindedMethod = logger[methodName].bind(logger);
|
|
602
|
-
const result = logFn(bindedMethod);
|
|
602
|
+
const result = logFn(bindedMethod, (_a = logger.level) !== null && _a !== void 0 ? _a : store.logLevel);
|
|
603
603
|
if (result)
|
|
604
604
|
bindedMethod(result);
|
|
605
605
|
}
|
|
@@ -729,6 +729,24 @@ const toInspectLogEntry = (e) => e;
|
|
|
729
729
|
const polyfill = (0,type_plus__WEBPACK_IMPORTED_MODULE_0__.record)();
|
|
730
730
|
|
|
731
731
|
|
|
732
|
+
/***/ }),
|
|
733
|
+
|
|
734
|
+
/***/ "./ts/standardLog.ctx.ts":
|
|
735
|
+
/*!*******************************!*\
|
|
736
|
+
!*** ./ts/standardLog.ctx.ts ***!
|
|
737
|
+
\*******************************/
|
|
738
|
+
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
739
|
+
|
|
740
|
+
"use strict";
|
|
741
|
+
__webpack_require__.r(__webpack_exports__);
|
|
742
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
743
|
+
/* harmony export */ "ctx": function() { return /* binding */ ctx; }
|
|
744
|
+
/* harmony export */ });
|
|
745
|
+
/* harmony import */ var type_plus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! type-plus */ "../../node_modules/.pnpm/type-plus@4.16.0/node_modules/type-plus/esm/object/record.js");
|
|
746
|
+
|
|
747
|
+
const ctx = (0,type_plus__WEBPACK_IMPORTED_MODULE_0__.record)();
|
|
748
|
+
|
|
749
|
+
|
|
732
750
|
/***/ }),
|
|
733
751
|
|
|
734
752
|
/***/ "./ts/standardLog.ts":
|
|
@@ -744,16 +762,17 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
744
762
|
/* harmony export */ "createStandardLog": function() { return /* binding */ createStandardLog; },
|
|
745
763
|
/* harmony export */ "createStandardLogClosure": function() { return /* binding */ createStandardLogClosure; },
|
|
746
764
|
/* harmony export */ "createStandardLogForTest": function() { return /* binding */ createStandardLogForTest; },
|
|
747
|
-
/* harmony export */ "ctx": function() { return /* binding */ ctx; },
|
|
748
765
|
/* harmony export */ "getLogger": function() { return /* binding */ getLogger; },
|
|
749
766
|
/* harmony export */ "suppressLogs": function() { return /* binding */ suppressLogs; }
|
|
750
767
|
/* harmony export */ });
|
|
751
|
-
/* harmony import */ var
|
|
752
|
-
/* harmony import */ var
|
|
753
|
-
/* harmony import */ var
|
|
754
|
-
/* harmony import */ var
|
|
755
|
-
/* harmony import */ var
|
|
756
|
-
/* harmony import */ var
|
|
768
|
+
/* harmony import */ var type_plus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! type-plus */ "../../node_modules/.pnpm/unpartial@1.0.4/node_modules/unpartial/esm/index.js");
|
|
769
|
+
/* harmony import */ var type_plus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! type-plus */ "../../node_modules/.pnpm/type-plus@4.16.0/node_modules/type-plus/esm/object/record.js");
|
|
770
|
+
/* harmony import */ var _logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./logger.js */ "./ts/logger.ts");
|
|
771
|
+
/* harmony import */ var _logLevels_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./logLevels.js */ "./ts/logLevels.ts");
|
|
772
|
+
/* harmony import */ var _logStore_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./logStore.js */ "./ts/logStore.ts");
|
|
773
|
+
/* harmony import */ var _memory_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./memory.js */ "./ts/memory.ts");
|
|
774
|
+
/* harmony import */ var _standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./standardLog.ctx.js */ "./ts/standardLog.ctx.ts");
|
|
775
|
+
|
|
757
776
|
|
|
758
777
|
|
|
759
778
|
|
|
@@ -766,17 +785,17 @@ function createStandardLog(options) {
|
|
|
766
785
|
const log = closure.standardLog.getLogger('standard-log');
|
|
767
786
|
log.critical(`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`);
|
|
768
787
|
}
|
|
769
|
-
if (!ctx.gsl)
|
|
770
|
-
ctx.gsl = closure;
|
|
788
|
+
if (!_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl)
|
|
789
|
+
_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl = closure;
|
|
771
790
|
return closure.standardLog;
|
|
772
791
|
}
|
|
773
792
|
function noop() { }
|
|
774
793
|
function createStandardLogClosure(options) {
|
|
775
794
|
var _a, _b, _c;
|
|
776
795
|
// TODO reporter.id must not be empty
|
|
777
|
-
const store = (0,
|
|
796
|
+
const store = (0,_logStore_js__WEBPACK_IMPORTED_MODULE_1__.createLogStore)((0,type_plus__WEBPACK_IMPORTED_MODULE_2__.required)({ logLevel: _logLevels_js__WEBPACK_IMPORTED_MODULE_3__.logLevels.info }, options));
|
|
778
797
|
const nonConsoleReporters = (_b = (_a = options === null || options === void 0 ? void 0 : options.reporters) === null || _a === void 0 ? void 0 : _a.filter(r => !r.isConsoleReporter).map(r => r.id)) !== null && _b !== void 0 ? _b : [];
|
|
779
|
-
const logMethods =
|
|
798
|
+
const logMethods = _logLevels_js__WEBPACK_IMPORTED_MODULE_3__.DEFAULT_LOG_METHOD_NAMES.concat(Object.keys((_c = options === null || options === void 0 ? void 0 : options.customLevels) !== null && _c !== void 0 ? _c : {}))
|
|
780
799
|
.concat(['on', 'count', 'write']);
|
|
781
800
|
return {
|
|
782
801
|
store,
|
|
@@ -791,7 +810,7 @@ function createStandardLogClosure(options) {
|
|
|
791
810
|
getLogger(id, options) {
|
|
792
811
|
if (store.loggers[id])
|
|
793
812
|
return store.loggers[id];
|
|
794
|
-
return store.loggers[id] = (0,
|
|
813
|
+
return store.loggers[id] = (0,_logger_js__WEBPACK_IMPORTED_MODULE_4__.createLogger)(store, id, { ssf: this.getLogger, ...options });
|
|
795
814
|
},
|
|
796
815
|
getNonConsoleLogger(id, options) {
|
|
797
816
|
if (store.nonConsoleLoggers[id])
|
|
@@ -803,7 +822,7 @@ function createStandardLogClosure(options) {
|
|
|
803
822
|
}
|
|
804
823
|
return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0
|
|
805
824
|
? createDummyLogger(logMethods)
|
|
806
|
-
: (0,
|
|
825
|
+
: (0,_logger_js__WEBPACK_IMPORTED_MODULE_4__.createLogger)(store, id, {
|
|
807
826
|
ssf: this.getNonConsoleLogger,
|
|
808
827
|
...options,
|
|
809
828
|
writeTo(reporterId) {
|
|
@@ -818,16 +837,16 @@ function createDummyLogger(logMethods) {
|
|
|
818
837
|
return logMethods.reduce((p, m) => {
|
|
819
838
|
p[m] = noop;
|
|
820
839
|
return p;
|
|
821
|
-
}, (0,
|
|
840
|
+
}, (0,type_plus__WEBPACK_IMPORTED_MODULE_5__.record)());
|
|
822
841
|
}
|
|
823
|
-
function createStandardLogForTest(logLevel =
|
|
824
|
-
const reporter = (0,
|
|
842
|
+
function createStandardLogForTest(logLevel = _logLevels_js__WEBPACK_IMPORTED_MODULE_3__.logLevels.debug) {
|
|
843
|
+
const reporter = (0,_memory_js__WEBPACK_IMPORTED_MODULE_6__.createMemoryLogReporter)();
|
|
825
844
|
const closure = createStandardLogClosure({ reporters: [reporter], logLevel });
|
|
826
845
|
return { ...closure.standardLog, reporter };
|
|
827
846
|
}
|
|
828
847
|
function suppressLogs(block, ...logs) {
|
|
829
848
|
const origLevels = logs.map(l => l.level);
|
|
830
|
-
logs.forEach(l => l.level =
|
|
849
|
+
logs.forEach(l => l.level = _logLevels_js__WEBPACK_IMPORTED_MODULE_3__.logLevels.none);
|
|
831
850
|
const result = block();
|
|
832
851
|
logs.forEach((l, i) => l.level = origLevels[i]);
|
|
833
852
|
return result;
|
|
@@ -835,31 +854,30 @@ function suppressLogs(block, ...logs) {
|
|
|
835
854
|
function getLogger(id, options) {
|
|
836
855
|
return getGlobalSL().getLogger(id, options);
|
|
837
856
|
}
|
|
838
|
-
const ctx = (0,type_plus__WEBPACK_IMPORTED_MODULE_4__.record)();
|
|
839
857
|
function getGlobalSL() {
|
|
840
|
-
if (!ctx.gsl)
|
|
841
|
-
ctx.gsl = createStandardLogClosure();
|
|
842
|
-
return ctx.gsl.standardLog;
|
|
858
|
+
if (!_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl)
|
|
859
|
+
_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl = createStandardLogClosure();
|
|
860
|
+
return _standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl.standardLog;
|
|
843
861
|
}
|
|
844
862
|
function configGlobal(options) {
|
|
845
|
-
if (ctx.configured) {
|
|
846
|
-
const log = ctx.gsl.standardLog.getLogger('standard-log');
|
|
863
|
+
if (_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.configured) {
|
|
864
|
+
const log = _standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl.standardLog.getLogger('standard-log');
|
|
847
865
|
log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
|
|
848
866
|
}
|
|
849
|
-
if (ctx.gsl) {
|
|
867
|
+
if (_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl) {
|
|
850
868
|
if (options.logLevel) {
|
|
851
|
-
ctx.gsl.store.logLevel = options.logLevel;
|
|
869
|
+
_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl.store.logLevel = options.logLevel;
|
|
852
870
|
}
|
|
853
871
|
if (options.reporters) {
|
|
854
|
-
const reporters = ctx.gsl.store.reporters;
|
|
872
|
+
const reporters = _standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl.store.reporters;
|
|
855
873
|
reporters.length = 0;
|
|
856
874
|
reporters.push(...options.reporters);
|
|
857
875
|
}
|
|
858
876
|
}
|
|
859
877
|
else {
|
|
860
|
-
ctx.gsl = createStandardLogClosure(options);
|
|
878
|
+
_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.gsl = createStandardLogClosure(options);
|
|
861
879
|
}
|
|
862
|
-
ctx.configured = true;
|
|
880
|
+
_standardLog_ctx_js__WEBPACK_IMPORTED_MODULE_0__.ctx.configured = true;
|
|
863
881
|
}
|
|
864
882
|
|
|
865
883
|
|
|
@@ -924,9 +942,9 @@ exports.upperCase = upperCase;
|
|
|
924
942
|
|
|
925
943
|
/***/ }),
|
|
926
944
|
|
|
927
|
-
/***/ "../../node_modules/.pnpm/iso-error@
|
|
945
|
+
/***/ "../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/esm/index.js":
|
|
928
946
|
/*!************************************************************************************!*\
|
|
929
|
-
!*** ../../node_modules/.pnpm/iso-error@
|
|
947
|
+
!*** ../../node_modules/.pnpm/iso-error@5.0.0/node_modules/iso-error/esm/index.js ***!
|
|
930
948
|
\************************************************************************************/
|
|
931
949
|
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
932
950
|
|
|
@@ -935,9 +953,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
935
953
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
936
954
|
/* harmony export */ "IsoError": function() { return /* binding */ IsoError; },
|
|
937
955
|
/* harmony export */ "ModuleError": function() { return /* binding */ ModuleError; },
|
|
956
|
+
/* harmony export */ "SerializableConverter": function() { return /* binding */ SerializableConverter; },
|
|
938
957
|
/* harmony export */ "isAggregateError": function() { return /* binding */ isAggregateError; }
|
|
939
958
|
/* harmony export */ });
|
|
940
959
|
/* eslint-disable @typescript-eslint/unbound-method */
|
|
960
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
961
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
962
|
+
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");
|
|
963
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
964
|
+
};
|
|
965
|
+
var _SerializableConverter_instances, _SerializableConverter_plugins, _SerializableConverter_fromSerializable, _SerializableConverter_deserializeError, _SerializableConverter_toSerializable, _a, _IsoError_hasCause, _IsoError_toIsoError;
|
|
941
966
|
//#region captureStackTrace polyfill
|
|
942
967
|
// istanbul ignore next
|
|
943
968
|
if (!Error.captureStackTrace) {
|
|
@@ -962,116 +987,34 @@ function defineStack(target, value) {
|
|
|
962
987
|
writable: true,
|
|
963
988
|
});
|
|
964
989
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
*/
|
|
970
|
-
class IsoError extends Error {
|
|
971
|
-
constructor(message, options) {
|
|
972
|
-
super(message);
|
|
973
|
-
/**
|
|
974
|
-
* Name of the error
|
|
975
|
-
*/
|
|
976
|
-
Object.defineProperty(this, "name", {
|
|
977
|
-
enumerable: true,
|
|
978
|
-
configurable: true,
|
|
979
|
-
writable: true,
|
|
980
|
-
value: void 0
|
|
981
|
-
});
|
|
982
|
-
/**
|
|
983
|
-
* Error cause
|
|
984
|
-
*/
|
|
985
|
-
Object.defineProperty(this, "cause", {
|
|
986
|
-
enumerable: true,
|
|
987
|
-
configurable: true,
|
|
988
|
-
writable: true,
|
|
989
|
-
value: void 0
|
|
990
|
-
});
|
|
991
|
-
//restore prototype chain
|
|
992
|
-
const actualProto = new.target.prototype;
|
|
993
|
-
this.name = actualProto.constructor.name;
|
|
994
|
-
// istanbul ignore next
|
|
995
|
-
if (Object.setPrototypeOf)
|
|
996
|
-
Object.setPrototypeOf(this, actualProto);
|
|
997
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
998
|
-
else
|
|
999
|
-
this.__proto__ = actualProto;
|
|
1000
|
-
if (options?.cause)
|
|
1001
|
-
this.cause = toIsoError(options.cause);
|
|
1002
|
-
if (options?.ssf)
|
|
1003
|
-
Error.captureStackTrace(this, options.ssf);
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Create an IsoError with additional properties without the need to create a new class.
|
|
1007
|
-
* @param props properties of the IsoError
|
|
1008
|
-
*/
|
|
1009
|
-
static create(props) {
|
|
1010
|
-
const { message, cause, ...rest } = props;
|
|
1011
|
-
const err = new IsoError(message, { cause, ssf: IsoError.create });
|
|
1012
|
-
return Object.assign(err, rest);
|
|
1013
|
-
}
|
|
1014
|
-
static stringify(err) {
|
|
1015
|
-
return this.serialize(err);
|
|
990
|
+
class SerializableConverter {
|
|
991
|
+
constructor() {
|
|
992
|
+
_SerializableConverter_instances.add(this);
|
|
993
|
+
_SerializableConverter_plugins.set(this, []);
|
|
1016
994
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* @type P Additional properties of the IsoError
|
|
1022
|
-
* @param text Json representation of a IsoError
|
|
1023
|
-
*/
|
|
1024
|
-
static parse(text) {
|
|
1025
|
-
return deserialize(IsoError.parse, text);
|
|
995
|
+
addPlugin(plugin) {
|
|
996
|
+
__classPrivateFieldGet(this, _SerializableConverter_plugins, "f").unshift(plugin);
|
|
1026
997
|
}
|
|
1027
998
|
/**
|
|
1028
|
-
*
|
|
1029
|
-
* @param text Json representation of a IsoError
|
|
999
|
+
* Deserialize an `Error` from `Serializable`
|
|
1030
1000
|
*/
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
static toSerializable(err) {
|
|
1035
|
-
return serializers.reduce((p, s) => p || s(err), undefined)
|
|
1036
|
-
|| toSerializableError(err);
|
|
1037
|
-
}
|
|
1038
|
-
static fromSerializable(json) {
|
|
1039
|
-
const err = deserializeError(json);
|
|
1040
|
-
Error.captureStackTrace(err, IsoError.fromSerializable);
|
|
1001
|
+
fromSerializable(json, options) {
|
|
1002
|
+
const err = __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_deserializeError).call(this, json);
|
|
1003
|
+
Error.captureStackTrace(err, options?.ssf);
|
|
1041
1004
|
return err;
|
|
1042
1005
|
}
|
|
1043
1006
|
/**
|
|
1044
|
-
*
|
|
1007
|
+
* Serialize `Error` to `Serializable`
|
|
1045
1008
|
*/
|
|
1046
|
-
|
|
1047
|
-
return
|
|
1048
|
-
}
|
|
1049
|
-
static addPlugin({ toSerializable, fromSerializable }) {
|
|
1050
|
-
serializers.unshift(toSerializable);
|
|
1051
|
-
deserializers.unshift(fromSerializable);
|
|
1009
|
+
toSerializable(err) {
|
|
1010
|
+
return __classPrivateFieldGet(this, _SerializableConverter_plugins, "f").reduce((p, s) => p || s.toSerializable(err), undefined) || __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable).call(this, err);
|
|
1052
1011
|
}
|
|
1053
|
-
toString() { return IsoError.serialize(this); }
|
|
1054
|
-
trace() { return IsoError.trace(this); }
|
|
1055
|
-
}
|
|
1056
|
-
function deserialize(fn, text) {
|
|
1057
|
-
const json = JSON.parse(text);
|
|
1058
|
-
const err = deserializeError(json);
|
|
1059
|
-
Error.captureStackTrace(err, fn);
|
|
1060
|
-
return err;
|
|
1061
|
-
}
|
|
1062
|
-
function deserializeError(json) {
|
|
1063
|
-
let err = undefined;
|
|
1064
|
-
for (const d of deserializers) {
|
|
1065
|
-
err = d(json);
|
|
1066
|
-
if (err)
|
|
1067
|
-
break;
|
|
1068
|
-
}
|
|
1069
|
-
return err || defaultDeserializeError(json);
|
|
1070
1012
|
}
|
|
1071
|
-
function
|
|
1013
|
+
_SerializableConverter_plugins = new WeakMap(), _SerializableConverter_instances = new WeakSet(), _SerializableConverter_fromSerializable = function _SerializableConverter_fromSerializable(json) {
|
|
1072
1014
|
if (json.name === 'AggregateError') {
|
|
1073
1015
|
const { message, errors, ...rest } = json;
|
|
1074
1016
|
// @ts-ignore
|
|
1017
|
+
// istanbul ignore next
|
|
1075
1018
|
if (global.AggregateError) {
|
|
1076
1019
|
return Object.assign(new AggregateError(errors, message), rest);
|
|
1077
1020
|
}
|
|
@@ -1083,60 +1026,155 @@ function defaultDeserializeError(json) {
|
|
|
1083
1026
|
}
|
|
1084
1027
|
}
|
|
1085
1028
|
const { message, cause, ...rest } = json;
|
|
1086
|
-
const causeError = cause ?
|
|
1029
|
+
const causeError = cause ? __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_deserializeError).call(this, cause) : undefined;
|
|
1087
1030
|
if (json.name === 'Error') {
|
|
1088
1031
|
return Object.assign(new Error(message), causeError ? { ...rest, cause: causeError } : rest);
|
|
1089
1032
|
}
|
|
1090
1033
|
// @ts-ignore
|
|
1091
1034
|
return Object.assign(new IsoError(message, causeError ? { cause: causeError } : undefined), rest);
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1035
|
+
}, _SerializableConverter_deserializeError = function _SerializableConverter_deserializeError(json) {
|
|
1036
|
+
let err = undefined;
|
|
1037
|
+
for (const { fromSerializable } of __classPrivateFieldGet(this, _SerializableConverter_plugins, "f")) {
|
|
1038
|
+
err = fromSerializable(json);
|
|
1039
|
+
if (err)
|
|
1040
|
+
break;
|
|
1041
|
+
}
|
|
1042
|
+
return err || __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_fromSerializable).call(this, json);
|
|
1043
|
+
}, _SerializableConverter_toSerializable = function _SerializableConverter_toSerializable(err) {
|
|
1094
1044
|
if (isAggregateError(err)) {
|
|
1095
1045
|
return {
|
|
1096
1046
|
...err, name: err.constructor.name, message: err.message,
|
|
1097
|
-
errors: err.errors.map(
|
|
1047
|
+
errors: err.errors.map(__classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable))
|
|
1098
1048
|
};
|
|
1099
1049
|
}
|
|
1100
1050
|
if (err instanceof Error) {
|
|
1101
1051
|
const { message, cause } = err;
|
|
1102
1052
|
return cause
|
|
1103
|
-
? { ...err, name: err.constructor.name, message, cause:
|
|
1053
|
+
? { ...err, name: err.constructor.name, message, cause: __classPrivateFieldGet(this, _SerializableConverter_instances, "m", _SerializableConverter_toSerializable).call(this, cause) }
|
|
1104
1054
|
: { ...err, name: err.constructor.name, message };
|
|
1105
1055
|
}
|
|
1106
1056
|
return err;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1057
|
+
};
|
|
1058
|
+
/**
|
|
1059
|
+
* Isomorphic Error that works across physical boundary.
|
|
1060
|
+
*/
|
|
1061
|
+
class IsoError extends Error {
|
|
1062
|
+
/**
|
|
1063
|
+
* Create an IsoError with additional properties without the need to create a new class.
|
|
1064
|
+
* @param props properties of the IsoError
|
|
1065
|
+
*/
|
|
1066
|
+
static create(props) {
|
|
1067
|
+
const { message, cause, ...rest } = props;
|
|
1068
|
+
const err = new IsoError(message, { cause, ssf: IsoError.create });
|
|
1069
|
+
return Object.assign(err, rest);
|
|
1070
|
+
}
|
|
1071
|
+
static stringify(err) {
|
|
1072
|
+
return this.serialize(err);
|
|
1120
1073
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1074
|
+
static serialize(err) {
|
|
1075
|
+
return JSON.stringify(this.toSerializable(err));
|
|
1123
1076
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1077
|
+
static toSerializable(err) {
|
|
1078
|
+
return this.converter.toSerializable(err);
|
|
1126
1079
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1080
|
+
/**
|
|
1081
|
+
* @type P Additional properties of the IsoError
|
|
1082
|
+
* @param text Json representation of a IsoError
|
|
1083
|
+
*/
|
|
1084
|
+
static parse(text) {
|
|
1085
|
+
const json = JSON.parse(text);
|
|
1086
|
+
return this.converter.fromSerializable(json, { ssf: IsoError.parse });
|
|
1130
1087
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1088
|
+
/**
|
|
1089
|
+
* @type P Additional properties of the IsoError
|
|
1090
|
+
* @param text Json representation of a IsoError
|
|
1091
|
+
*/
|
|
1092
|
+
static deserialize(text) {
|
|
1093
|
+
const json = JSON.parse(text);
|
|
1094
|
+
return this.converter.fromSerializable(json, { ssf: IsoError.deserialize });
|
|
1095
|
+
}
|
|
1096
|
+
static fromSerializable(json) {
|
|
1097
|
+
return this.converter.fromSerializable(json, { ssf: IsoError.fromSerializable });
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* returns the error message including the error causes.
|
|
1101
|
+
*/
|
|
1102
|
+
static trace(err) {
|
|
1103
|
+
const messages = [];
|
|
1104
|
+
if (err instanceof ModuleError) {
|
|
1105
|
+
messages.push(`${err.name}(${err.module}): ${err.message}`);
|
|
1106
|
+
}
|
|
1107
|
+
else if (err instanceof Error) {
|
|
1108
|
+
messages.push(`${err.name}: ${err.message}`);
|
|
1109
|
+
}
|
|
1110
|
+
if (isAggregateError(err)) {
|
|
1111
|
+
err.errors.forEach(e => messages.push(...this.trace(e).split('\n').map(s => ' ' + s)));
|
|
1112
|
+
}
|
|
1113
|
+
if (err instanceof Error) {
|
|
1114
|
+
if (__classPrivateFieldGet(this, _a, "m", _IsoError_hasCause).call(this, err))
|
|
1115
|
+
messages.push(...this.trace(err.cause).split('\n').map(s => ' ' + s));
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
messages.push(typeof err === 'string' ? err : JSON.stringify(err));
|
|
1119
|
+
}
|
|
1120
|
+
return messages.join('\n');
|
|
1121
|
+
}
|
|
1122
|
+
static addPlugin(plugin) {
|
|
1123
|
+
this.converter.addPlugin(plugin);
|
|
1124
|
+
}
|
|
1125
|
+
constructor(message, options) {
|
|
1126
|
+
super(message);
|
|
1127
|
+
/**
|
|
1128
|
+
* Name of the error
|
|
1129
|
+
*/
|
|
1130
|
+
Object.defineProperty(this, "name", {
|
|
1131
|
+
enumerable: true,
|
|
1132
|
+
configurable: true,
|
|
1133
|
+
writable: true,
|
|
1134
|
+
value: void 0
|
|
1135
|
+
});
|
|
1136
|
+
/**
|
|
1137
|
+
* Error cause
|
|
1138
|
+
*/
|
|
1139
|
+
Object.defineProperty(this, "cause", {
|
|
1140
|
+
enumerable: true,
|
|
1141
|
+
configurable: true,
|
|
1142
|
+
writable: true,
|
|
1143
|
+
value: void 0
|
|
1144
|
+
});
|
|
1145
|
+
// restore prototype chain
|
|
1146
|
+
const actualProto = new.target.prototype;
|
|
1147
|
+
this.name = actualProto.constructor.name;
|
|
1148
|
+
// istanbul ignore next
|
|
1149
|
+
if (Object.setPrototypeOf)
|
|
1150
|
+
Object.setPrototypeOf(this, actualProto);
|
|
1151
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1152
|
+
else
|
|
1153
|
+
this.__proto__ = actualProto;
|
|
1154
|
+
if (options?.cause)
|
|
1155
|
+
this.cause = __classPrivateFieldGet(IsoError, _a, "m", _IsoError_toIsoError).call(IsoError, options.cause);
|
|
1156
|
+
if (options?.ssf)
|
|
1157
|
+
Error.captureStackTrace(this, options.ssf);
|
|
1133
1158
|
}
|
|
1134
|
-
return
|
|
1159
|
+
toString() { return IsoError.serialize(this); }
|
|
1160
|
+
trace() { return IsoError.trace(this); }
|
|
1135
1161
|
}
|
|
1136
|
-
function
|
|
1162
|
+
_a = IsoError, _IsoError_hasCause = function _IsoError_hasCause(x) {
|
|
1137
1163
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1138
1164
|
return !!x.cause;
|
|
1139
|
-
}
|
|
1165
|
+
}, _IsoError_toIsoError = function _IsoError_toIsoError(err) {
|
|
1166
|
+
if (err instanceof IsoError)
|
|
1167
|
+
return err;
|
|
1168
|
+
// When the error is an internal error from deserialization,
|
|
1169
|
+
// the err.constructor.name is object
|
|
1170
|
+
return Object.assign(err, { name: err.constructor.name !== 'Object' ? err.constructor.name : err.name });
|
|
1171
|
+
};
|
|
1172
|
+
Object.defineProperty(IsoError, "converter", {
|
|
1173
|
+
enumerable: true,
|
|
1174
|
+
configurable: true,
|
|
1175
|
+
writable: true,
|
|
1176
|
+
value: new SerializableConverter()
|
|
1177
|
+
});
|
|
1140
1178
|
/**
|
|
1141
1179
|
* An IsoError with a module property.
|
|
1142
1180
|
*/
|
|
@@ -1409,7 +1447,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1409
1447
|
|
|
1410
1448
|
|
|
1411
1449
|
|
|
1412
|
-
|
|
1413
1450
|
}();
|
|
1414
1451
|
StandardLog = __webpack_exports__;
|
|
1415
1452
|
/******/ })()
|
|
Binary file
|