@scrypted/nvr 0.11.70 → 0.11.72
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/CHANGELOG.md +19 -0
- package/dist/724 +239 -239
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
<details>
|
|
2
2
|
<summary>Changelog</summary>
|
|
3
3
|
|
|
4
|
+
### 0.11.71
|
|
5
|
+
|
|
6
|
+
new vector search util
|
|
7
|
+
perform clip on objects of interest
|
|
8
|
+
day of week scheduling support and dst handling
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 0.11.70
|
|
12
|
+
|
|
13
|
+
respect time zone daylight savings
|
|
14
|
+
purge empty names
|
|
15
|
+
remove legacy training mode
|
|
16
|
+
more zone/ai settings
|
|
17
|
+
day filtering
|
|
18
|
+
time zone for days
|
|
19
|
+
schedule day persistent
|
|
20
|
+
add support for heterogenous classifier in cluster mode
|
|
21
|
+
|
|
22
|
+
|
|
4
23
|
### 0.11.69
|
|
5
24
|
|
|
6
25
|
add support for custom classifier in nvr object detection
|
package/dist/724
CHANGED
|
@@ -3,6 +3,94 @@ exports.id = 724;
|
|
|
3
3
|
exports.ids = [724];
|
|
4
4
|
exports.modules = {
|
|
5
5
|
|
|
6
|
+
/***/ 1845:
|
|
7
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
8
|
+
|
|
9
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
10
|
+
/* harmony export */ $: () => (/* binding */ buildHTTPHeadersQuotedKeyValueSet),
|
|
11
|
+
/* harmony export */ parseHTTPHeadersQuotedKeyValueSet: () => (/* binding */ parseHTTPHeadersQuotedKeyValueSet)
|
|
12
|
+
/* harmony export */ });
|
|
13
|
+
/* harmony import */ var yerror__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9126);
|
|
14
|
+
|
|
15
|
+
const QUOTE = '"';
|
|
16
|
+
const EQUAL = '=';
|
|
17
|
+
const SEPARATOR = ', ';
|
|
18
|
+
/*
|
|
19
|
+
* Regular expression for matching the key-value pairs
|
|
20
|
+
* \w+ = The key
|
|
21
|
+
* = = The equal sign
|
|
22
|
+
* ".*?" = Value option 1: A double-quoted value (using the non-greedy *? to stop at the first doublequote)
|
|
23
|
+
* [^",]+ = Value option 2: A string without commas or double-quotes
|
|
24
|
+
* (?=,|$) = Zero-width (as in not captured) positive lookahead assertion.
|
|
25
|
+
* The previous match will only be valid if it's followed by a " literal
|
|
26
|
+
* or the end of the string
|
|
27
|
+
*/
|
|
28
|
+
const KEYVALUE_REGEXP = /\w+=(".*?"|[^",]+)(?=,|$)/g;
|
|
29
|
+
// FIXME: Create a real parser
|
|
30
|
+
function parseHTTPHeadersQuotedKeyValueSet(contents, authorizedKeys, requiredKeys = [], valuesToNormalize = []) {
|
|
31
|
+
const matches = contents.trim().match(KEYVALUE_REGEXP);
|
|
32
|
+
if (!matches)
|
|
33
|
+
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_MALFORMED_QUOTEDKEYVALUE', contents);
|
|
34
|
+
const data = matches
|
|
35
|
+
.map((part, partPosition) => {
|
|
36
|
+
const [key, ...rest] = part.split(EQUAL);
|
|
37
|
+
const value = rest.join(EQUAL);
|
|
38
|
+
if (0 === rest.length) {
|
|
39
|
+
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_MALFORMED_QUOTEDKEYVALUE', partPosition, part);
|
|
40
|
+
}
|
|
41
|
+
return [key, value];
|
|
42
|
+
})
|
|
43
|
+
.reduce(function (parsedValues, [name, value], valuePosition) {
|
|
44
|
+
const normalizedName = name.toLowerCase();
|
|
45
|
+
if (-1 === authorizedKeys.indexOf(normalizedName)) {
|
|
46
|
+
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_UNAUTHORIZED_KEY', valuePosition, normalizedName);
|
|
47
|
+
}
|
|
48
|
+
/*
|
|
49
|
+
* Regular expression for stripping paired starting and ending double quotes off the value:
|
|
50
|
+
* ^ = The beginning of the string
|
|
51
|
+
* " = The first double quote
|
|
52
|
+
* .+ = One or more characters of any kind
|
|
53
|
+
* (?="$) = Zero-width (as in not captured) positive lookahead assertion.
|
|
54
|
+
* The previous match will only be valid if it's followed by a " literal
|
|
55
|
+
* or the end of the string
|
|
56
|
+
* " = The ending double quote
|
|
57
|
+
* $ = The end of the string
|
|
58
|
+
*/
|
|
59
|
+
const strippedValue = value.replace(/^"(.+(?="$))"$/, '$1');
|
|
60
|
+
parsedValues[normalizedName] = valuesToNormalize.includes(normalizedName)
|
|
61
|
+
? strippedValue.toLowerCase()
|
|
62
|
+
: strippedValue;
|
|
63
|
+
return parsedValues;
|
|
64
|
+
}, {});
|
|
65
|
+
_checkRequiredKeys(requiredKeys, data);
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
function buildHTTPHeadersQuotedKeyValueSet(data, authorizedKeys, requiredKeys = []) {
|
|
69
|
+
_checkRequiredKeys(requiredKeys, data);
|
|
70
|
+
return authorizedKeys.reduce(function (contents, key) {
|
|
71
|
+
if (data[key]) {
|
|
72
|
+
return (contents +
|
|
73
|
+
(contents ? SEPARATOR : '') +
|
|
74
|
+
key +
|
|
75
|
+
EQUAL +
|
|
76
|
+
QUOTE +
|
|
77
|
+
data[key] +
|
|
78
|
+
QUOTE);
|
|
79
|
+
}
|
|
80
|
+
return contents;
|
|
81
|
+
}, '');
|
|
82
|
+
}
|
|
83
|
+
function _checkRequiredKeys(requiredKeys, data) {
|
|
84
|
+
requiredKeys.forEach((name) => {
|
|
85
|
+
if ('undefined' === typeof data[name]) {
|
|
86
|
+
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_REQUIRED_KEY', name);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=utils.js.map
|
|
91
|
+
|
|
92
|
+
/***/ }),
|
|
93
|
+
|
|
6
94
|
/***/ 7529:
|
|
7
95
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
8
96
|
|
|
@@ -636,245 +724,6 @@ function buildAuthorizationHeader(authMechanism, data) {
|
|
|
636
724
|
|
|
637
725
|
/***/ }),
|
|
638
726
|
|
|
639
|
-
/***/ 1845:
|
|
640
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
641
|
-
|
|
642
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
643
|
-
/* harmony export */ $: () => (/* binding */ buildHTTPHeadersQuotedKeyValueSet),
|
|
644
|
-
/* harmony export */ parseHTTPHeadersQuotedKeyValueSet: () => (/* binding */ parseHTTPHeadersQuotedKeyValueSet)
|
|
645
|
-
/* harmony export */ });
|
|
646
|
-
/* harmony import */ var yerror__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9126);
|
|
647
|
-
|
|
648
|
-
const QUOTE = '"';
|
|
649
|
-
const EQUAL = '=';
|
|
650
|
-
const SEPARATOR = ', ';
|
|
651
|
-
/*
|
|
652
|
-
* Regular expression for matching the key-value pairs
|
|
653
|
-
* \w+ = The key
|
|
654
|
-
* = = The equal sign
|
|
655
|
-
* ".*?" = Value option 1: A double-quoted value (using the non-greedy *? to stop at the first doublequote)
|
|
656
|
-
* [^",]+ = Value option 2: A string without commas or double-quotes
|
|
657
|
-
* (?=,|$) = Zero-width (as in not captured) positive lookahead assertion.
|
|
658
|
-
* The previous match will only be valid if it's followed by a " literal
|
|
659
|
-
* or the end of the string
|
|
660
|
-
*/
|
|
661
|
-
const KEYVALUE_REGEXP = /\w+=(".*?"|[^",]+)(?=,|$)/g;
|
|
662
|
-
// FIXME: Create a real parser
|
|
663
|
-
function parseHTTPHeadersQuotedKeyValueSet(contents, authorizedKeys, requiredKeys = [], valuesToNormalize = []) {
|
|
664
|
-
const matches = contents.trim().match(KEYVALUE_REGEXP);
|
|
665
|
-
if (!matches)
|
|
666
|
-
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_MALFORMED_QUOTEDKEYVALUE', contents);
|
|
667
|
-
const data = matches
|
|
668
|
-
.map((part, partPosition) => {
|
|
669
|
-
const [key, ...rest] = part.split(EQUAL);
|
|
670
|
-
const value = rest.join(EQUAL);
|
|
671
|
-
if (0 === rest.length) {
|
|
672
|
-
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_MALFORMED_QUOTEDKEYVALUE', partPosition, part);
|
|
673
|
-
}
|
|
674
|
-
return [key, value];
|
|
675
|
-
})
|
|
676
|
-
.reduce(function (parsedValues, [name, value], valuePosition) {
|
|
677
|
-
const normalizedName = name.toLowerCase();
|
|
678
|
-
if (-1 === authorizedKeys.indexOf(normalizedName)) {
|
|
679
|
-
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_UNAUTHORIZED_KEY', valuePosition, normalizedName);
|
|
680
|
-
}
|
|
681
|
-
/*
|
|
682
|
-
* Regular expression for stripping paired starting and ending double quotes off the value:
|
|
683
|
-
* ^ = The beginning of the string
|
|
684
|
-
* " = The first double quote
|
|
685
|
-
* .+ = One or more characters of any kind
|
|
686
|
-
* (?="$) = Zero-width (as in not captured) positive lookahead assertion.
|
|
687
|
-
* The previous match will only be valid if it's followed by a " literal
|
|
688
|
-
* or the end of the string
|
|
689
|
-
* " = The ending double quote
|
|
690
|
-
* $ = The end of the string
|
|
691
|
-
*/
|
|
692
|
-
const strippedValue = value.replace(/^"(.+(?="$))"$/, '$1');
|
|
693
|
-
parsedValues[normalizedName] = valuesToNormalize.includes(normalizedName)
|
|
694
|
-
? strippedValue.toLowerCase()
|
|
695
|
-
: strippedValue;
|
|
696
|
-
return parsedValues;
|
|
697
|
-
}, {});
|
|
698
|
-
_checkRequiredKeys(requiredKeys, data);
|
|
699
|
-
return data;
|
|
700
|
-
}
|
|
701
|
-
function buildHTTPHeadersQuotedKeyValueSet(data, authorizedKeys, requiredKeys = []) {
|
|
702
|
-
_checkRequiredKeys(requiredKeys, data);
|
|
703
|
-
return authorizedKeys.reduce(function (contents, key) {
|
|
704
|
-
if (data[key]) {
|
|
705
|
-
return (contents +
|
|
706
|
-
(contents ? SEPARATOR : '') +
|
|
707
|
-
key +
|
|
708
|
-
EQUAL +
|
|
709
|
-
QUOTE +
|
|
710
|
-
data[key] +
|
|
711
|
-
QUOTE);
|
|
712
|
-
}
|
|
713
|
-
return contents;
|
|
714
|
-
}, '');
|
|
715
|
-
}
|
|
716
|
-
function _checkRequiredKeys(requiredKeys, data) {
|
|
717
|
-
requiredKeys.forEach((name) => {
|
|
718
|
-
if ('undefined' === typeof data[name]) {
|
|
719
|
-
throw new yerror__WEBPACK_IMPORTED_MODULE_0__/* .YError */ .w('E_REQUIRED_KEY', name);
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
//# sourceMappingURL=utils.js.map
|
|
724
|
-
|
|
725
|
-
/***/ }),
|
|
726
|
-
|
|
727
|
-
/***/ 9126:
|
|
728
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
729
|
-
|
|
730
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
731
|
-
/* harmony export */ w: () => (/* binding */ YError)
|
|
732
|
-
/* harmony export */ });
|
|
733
|
-
/* unused harmony export printStackTrace */
|
|
734
|
-
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(857);
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* A YError class able to contain some params and
|
|
738
|
-
* print better stack traces
|
|
739
|
-
* @extends Error
|
|
740
|
-
*/
|
|
741
|
-
class YError extends Error {
|
|
742
|
-
code;
|
|
743
|
-
params;
|
|
744
|
-
wrappedErrors;
|
|
745
|
-
constructor(wrappedErrors, errorCode, ...params) {
|
|
746
|
-
// Detecting if wrappedErrors are passed
|
|
747
|
-
if (!(wrappedErrors instanceof Array)) {
|
|
748
|
-
params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(params);
|
|
749
|
-
errorCode = wrappedErrors;
|
|
750
|
-
wrappedErrors = [];
|
|
751
|
-
}
|
|
752
|
-
// Call the parent constructor
|
|
753
|
-
super(errorCode);
|
|
754
|
-
// Filling error
|
|
755
|
-
this.code = errorCode || 'E_UNEXPECTED';
|
|
756
|
-
this.params = params;
|
|
757
|
-
this.wrappedErrors = wrappedErrors;
|
|
758
|
-
this.name = this.toString();
|
|
759
|
-
if (Error.captureStackTrace) {
|
|
760
|
-
Error.captureStackTrace(this, this.constructor);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Wraps any error and output a YError with an error
|
|
765
|
-
* code and some params as debug values.
|
|
766
|
-
* @param {Error} err
|
|
767
|
-
* The error to wrap
|
|
768
|
-
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
769
|
-
* The error code corresponding to the actual error
|
|
770
|
-
* @param {...YErrorParams} [params]
|
|
771
|
-
* Some additional debugging values
|
|
772
|
-
* @return {YError}
|
|
773
|
-
* The wrapped error
|
|
774
|
-
*/
|
|
775
|
-
static wrap(err, errorCode, ...params) {
|
|
776
|
-
const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
|
|
777
|
-
const wrappedErrors = ('wrappedErrors' in err ? err.wrappedErrors : []).concat(err);
|
|
778
|
-
if (!errorCode) {
|
|
779
|
-
if (wrappedErrorIsACode) {
|
|
780
|
-
errorCode = err.message;
|
|
781
|
-
}
|
|
782
|
-
else {
|
|
783
|
-
errorCode = 'E_UNEXPECTED';
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
if (err.message && !wrappedErrorIsACode) {
|
|
787
|
-
params.push(err.message);
|
|
788
|
-
}
|
|
789
|
-
return new YError(wrappedErrors, errorCode, ...params);
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Return a YError as is or wraps any other error and output
|
|
793
|
-
* a YError with a code and some params as debug values.
|
|
794
|
-
* @param {Error} err
|
|
795
|
-
* The error to cast
|
|
796
|
-
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
797
|
-
* The error code corresponding to the actual error
|
|
798
|
-
* @param {...YErrorParams} [params]
|
|
799
|
-
* Some additional debugging values
|
|
800
|
-
* @return {YError}
|
|
801
|
-
* The wrapped error
|
|
802
|
-
*/
|
|
803
|
-
static cast(err, errorCode, ...params) {
|
|
804
|
-
if (_looksLikeAYError(err)) {
|
|
805
|
-
return err;
|
|
806
|
-
}
|
|
807
|
-
return YError.wrap(err, errorCode, ...params);
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* Same than `YError.wrap()` but preserves the code
|
|
811
|
-
* and the debug values of the error if it is
|
|
812
|
-
* already an instance of the YError constructor.
|
|
813
|
-
* @param {Error} err
|
|
814
|
-
* The error to bump
|
|
815
|
-
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
816
|
-
* The error code corresponding to the actual error
|
|
817
|
-
* @param {...YErrorParams} [params]
|
|
818
|
-
* Some additional debugging values
|
|
819
|
-
* @return {YError}
|
|
820
|
-
* The wrapped error
|
|
821
|
-
*/
|
|
822
|
-
static bump(err, errorCode, ...params) {
|
|
823
|
-
if (_looksLikeAYError(err)) {
|
|
824
|
-
return YError.wrap(err, err.code, ...err.params);
|
|
825
|
-
}
|
|
826
|
-
return YError.wrap(err, errorCode, ...params);
|
|
827
|
-
}
|
|
828
|
-
toString() {
|
|
829
|
-
return ((this.wrappedErrors.length
|
|
830
|
-
? // eslint-disable-next-line
|
|
831
|
-
this.wrappedErrors[this.wrappedErrors.length - 1].stack + os__WEBPACK_IMPORTED_MODULE_0__.EOL
|
|
832
|
-
: '') +
|
|
833
|
-
this.constructor.name +
|
|
834
|
-
': ' +
|
|
835
|
-
this.code +
|
|
836
|
-
' (' +
|
|
837
|
-
this.params.join(', ') +
|
|
838
|
-
')');
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Allow to print a stack from anything (especially catched
|
|
843
|
-
* errors that may or may not contain errors 🤷).
|
|
844
|
-
* @param {Error} err
|
|
845
|
-
* The error to print
|
|
846
|
-
* @return {string}
|
|
847
|
-
* The stack trace if any
|
|
848
|
-
*/
|
|
849
|
-
function printStackTrace(err) {
|
|
850
|
-
return typeof err === 'object' && typeof err.stack === 'string'
|
|
851
|
-
? err.stack
|
|
852
|
-
: `[no_stack_trace]: error is ${err != null && typeof err.toString === 'function'
|
|
853
|
-
? err.toString()
|
|
854
|
-
: typeof err}`;
|
|
855
|
-
}
|
|
856
|
-
// In order to keep compatibility through major versions
|
|
857
|
-
// we have to make kind of an cross major version instanceof
|
|
858
|
-
function _looksLikeAYError(err) {
|
|
859
|
-
return (!!(err instanceof YError) ||
|
|
860
|
-
!!(err.constructor &&
|
|
861
|
-
err.constructor.name &&
|
|
862
|
-
err.constructor.name.endsWith('Error') &&
|
|
863
|
-
'code' in err &&
|
|
864
|
-
'string' === typeof err.code &&
|
|
865
|
-
_looksLikeAYErrorCode(err.code) &&
|
|
866
|
-
'params' in err &&
|
|
867
|
-
err.params &&
|
|
868
|
-
err.params instanceof Array));
|
|
869
|
-
}
|
|
870
|
-
function _looksLikeAYErrorCode(str) {
|
|
871
|
-
return /^([A-Z0-9_]+)$/.test(str);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
//# sourceMappingURL=index.js.map
|
|
875
|
-
|
|
876
|
-
/***/ }),
|
|
877
|
-
|
|
878
727
|
/***/ 8188:
|
|
879
728
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
880
729
|
|
|
@@ -1726,6 +1575,157 @@ function buildAuthorizationHeader(authMechanism, data) {
|
|
|
1726
1575
|
}
|
|
1727
1576
|
//# sourceMappingURL=index.js.map
|
|
1728
1577
|
|
|
1578
|
+
/***/ }),
|
|
1579
|
+
|
|
1580
|
+
/***/ 9126:
|
|
1581
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1582
|
+
|
|
1583
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1584
|
+
/* harmony export */ w: () => (/* binding */ YError)
|
|
1585
|
+
/* harmony export */ });
|
|
1586
|
+
/* unused harmony export printStackTrace */
|
|
1587
|
+
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(857);
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* A YError class able to contain some params and
|
|
1591
|
+
* print better stack traces
|
|
1592
|
+
* @extends Error
|
|
1593
|
+
*/
|
|
1594
|
+
class YError extends Error {
|
|
1595
|
+
code;
|
|
1596
|
+
params;
|
|
1597
|
+
wrappedErrors;
|
|
1598
|
+
constructor(wrappedErrors, errorCode, ...params) {
|
|
1599
|
+
// Detecting if wrappedErrors are passed
|
|
1600
|
+
if (!(wrappedErrors instanceof Array)) {
|
|
1601
|
+
params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(params);
|
|
1602
|
+
errorCode = wrappedErrors;
|
|
1603
|
+
wrappedErrors = [];
|
|
1604
|
+
}
|
|
1605
|
+
// Call the parent constructor
|
|
1606
|
+
super(errorCode);
|
|
1607
|
+
// Filling error
|
|
1608
|
+
this.code = errorCode || 'E_UNEXPECTED';
|
|
1609
|
+
this.params = params;
|
|
1610
|
+
this.wrappedErrors = wrappedErrors;
|
|
1611
|
+
this.name = this.toString();
|
|
1612
|
+
if (Error.captureStackTrace) {
|
|
1613
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Wraps any error and output a YError with an error
|
|
1618
|
+
* code and some params as debug values.
|
|
1619
|
+
* @param {Error} err
|
|
1620
|
+
* The error to wrap
|
|
1621
|
+
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
1622
|
+
* The error code corresponding to the actual error
|
|
1623
|
+
* @param {...YErrorParams} [params]
|
|
1624
|
+
* Some additional debugging values
|
|
1625
|
+
* @return {YError}
|
|
1626
|
+
* The wrapped error
|
|
1627
|
+
*/
|
|
1628
|
+
static wrap(err, errorCode, ...params) {
|
|
1629
|
+
const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
|
|
1630
|
+
const wrappedErrors = ('wrappedErrors' in err ? err.wrappedErrors : []).concat(err);
|
|
1631
|
+
if (!errorCode) {
|
|
1632
|
+
if (wrappedErrorIsACode) {
|
|
1633
|
+
errorCode = err.message;
|
|
1634
|
+
}
|
|
1635
|
+
else {
|
|
1636
|
+
errorCode = 'E_UNEXPECTED';
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
if (err.message && !wrappedErrorIsACode) {
|
|
1640
|
+
params.push(err.message);
|
|
1641
|
+
}
|
|
1642
|
+
return new YError(wrappedErrors, errorCode, ...params);
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Return a YError as is or wraps any other error and output
|
|
1646
|
+
* a YError with a code and some params as debug values.
|
|
1647
|
+
* @param {Error} err
|
|
1648
|
+
* The error to cast
|
|
1649
|
+
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
1650
|
+
* The error code corresponding to the actual error
|
|
1651
|
+
* @param {...YErrorParams} [params]
|
|
1652
|
+
* Some additional debugging values
|
|
1653
|
+
* @return {YError}
|
|
1654
|
+
* The wrapped error
|
|
1655
|
+
*/
|
|
1656
|
+
static cast(err, errorCode, ...params) {
|
|
1657
|
+
if (_looksLikeAYError(err)) {
|
|
1658
|
+
return err;
|
|
1659
|
+
}
|
|
1660
|
+
return YError.wrap(err, errorCode, ...params);
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Same than `YError.wrap()` but preserves the code
|
|
1664
|
+
* and the debug values of the error if it is
|
|
1665
|
+
* already an instance of the YError constructor.
|
|
1666
|
+
* @param {Error} err
|
|
1667
|
+
* The error to bump
|
|
1668
|
+
* @param {string} [errorCode = 'E_UNEXPECTED']
|
|
1669
|
+
* The error code corresponding to the actual error
|
|
1670
|
+
* @param {...YErrorParams} [params]
|
|
1671
|
+
* Some additional debugging values
|
|
1672
|
+
* @return {YError}
|
|
1673
|
+
* The wrapped error
|
|
1674
|
+
*/
|
|
1675
|
+
static bump(err, errorCode, ...params) {
|
|
1676
|
+
if (_looksLikeAYError(err)) {
|
|
1677
|
+
return YError.wrap(err, err.code, ...err.params);
|
|
1678
|
+
}
|
|
1679
|
+
return YError.wrap(err, errorCode, ...params);
|
|
1680
|
+
}
|
|
1681
|
+
toString() {
|
|
1682
|
+
return ((this.wrappedErrors.length
|
|
1683
|
+
? // eslint-disable-next-line
|
|
1684
|
+
this.wrappedErrors[this.wrappedErrors.length - 1].stack + os__WEBPACK_IMPORTED_MODULE_0__.EOL
|
|
1685
|
+
: '') +
|
|
1686
|
+
this.constructor.name +
|
|
1687
|
+
': ' +
|
|
1688
|
+
this.code +
|
|
1689
|
+
' (' +
|
|
1690
|
+
this.params.join(', ') +
|
|
1691
|
+
')');
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Allow to print a stack from anything (especially catched
|
|
1696
|
+
* errors that may or may not contain errors 🤷).
|
|
1697
|
+
* @param {Error} err
|
|
1698
|
+
* The error to print
|
|
1699
|
+
* @return {string}
|
|
1700
|
+
* The stack trace if any
|
|
1701
|
+
*/
|
|
1702
|
+
function printStackTrace(err) {
|
|
1703
|
+
return typeof err === 'object' && typeof err.stack === 'string'
|
|
1704
|
+
? err.stack
|
|
1705
|
+
: `[no_stack_trace]: error is ${err != null && typeof err.toString === 'function'
|
|
1706
|
+
? err.toString()
|
|
1707
|
+
: typeof err}`;
|
|
1708
|
+
}
|
|
1709
|
+
// In order to keep compatibility through major versions
|
|
1710
|
+
// we have to make kind of an cross major version instanceof
|
|
1711
|
+
function _looksLikeAYError(err) {
|
|
1712
|
+
return (!!(err instanceof YError) ||
|
|
1713
|
+
!!(err.constructor &&
|
|
1714
|
+
err.constructor.name &&
|
|
1715
|
+
err.constructor.name.endsWith('Error') &&
|
|
1716
|
+
'code' in err &&
|
|
1717
|
+
'string' === typeof err.code &&
|
|
1718
|
+
_looksLikeAYErrorCode(err.code) &&
|
|
1719
|
+
'params' in err &&
|
|
1720
|
+
err.params &&
|
|
1721
|
+
err.params instanceof Array));
|
|
1722
|
+
}
|
|
1723
|
+
function _looksLikeAYErrorCode(str) {
|
|
1724
|
+
return /^([A-Z0-9_]+)$/.test(str);
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
//# sourceMappingURL=index.js.map
|
|
1728
|
+
|
|
1729
1729
|
/***/ })
|
|
1730
1730
|
|
|
1731
1731
|
};
|
package/dist/plugin.zip
CHANGED
|
Binary file
|