@naturalcycles/js-lib 14.132.0 → 14.133.1
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/dist/error/app.error.d.ts +1 -1
- package/dist/error/app.error.js +9 -2
- package/dist/error/assert.d.ts +1 -0
- package/dist/error/assert.js +3 -0
- package/dist/error/error.util.js +6 -0
- package/dist/error/http.error.js +1 -1
- package/dist/http/fetcher.js +2 -1
- package/dist/http/fetcher.model.d.ts +2 -1
- package/dist/promise/pTimeout.d.ts +1 -0
- package/dist/promise/pTimeout.js +3 -0
- package/dist-esm/error/app.error.js +9 -2
- package/dist-esm/error/assert.js +3 -0
- package/dist-esm/error/error.util.js +6 -0
- package/dist-esm/error/http.error.js +1 -1
- package/dist-esm/http/fetcher.js +2 -1
- package/dist-esm/promise/pTimeout.js +3 -0
- package/package.json +1 -1
- package/src/error/app.error.ts +10 -2
- package/src/error/assert.ts +5 -1
- package/src/error/error.util.ts +7 -0
- package/src/error/http.error.ts +1 -1
- package/src/http/fetcher.model.ts +4 -1
- package/src/http/fetcher.ts +1 -1
- package/src/http/http.model.ts +1 -0
- package/src/promise/pTimeout.ts +5 -1
|
@@ -14,5 +14,5 @@ export declare class AppError<DATA_TYPE extends ErrorData = ErrorData> extends E
|
|
|
14
14
|
* cause here is normalized to be instance of Error
|
|
15
15
|
*/
|
|
16
16
|
cause?: Error;
|
|
17
|
-
constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions);
|
|
17
|
+
constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions, name?: string);
|
|
18
18
|
}
|
package/dist/error/app.error.js
CHANGED
|
@@ -11,11 +11,18 @@ exports.AppError = void 0;
|
|
|
11
11
|
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
12
12
|
*/
|
|
13
13
|
class AppError extends Error {
|
|
14
|
-
constructor(message, data = {}, opt) {
|
|
14
|
+
constructor(message, data = {}, opt, name) {
|
|
15
15
|
super(message);
|
|
16
16
|
Object.defineProperty(this, 'name', {
|
|
17
|
-
value: this.constructor.name,
|
|
17
|
+
value: name || this.constructor.name,
|
|
18
18
|
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
});
|
|
21
|
+
// this is to allow changing this.constuctor.name to a non-minified version
|
|
22
|
+
Object.defineProperty(this.constructor, 'name', {
|
|
23
|
+
value: name || this.constructor.name,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
19
26
|
});
|
|
20
27
|
Object.defineProperty(this, 'data', {
|
|
21
28
|
value: data,
|
package/dist/error/assert.d.ts
CHANGED
|
@@ -36,4 +36,5 @@ export declare function _assertIsString(v: any, message?: string): asserts v is
|
|
|
36
36
|
export declare function _assertIsNumber(v: any, message?: string): asserts v is number;
|
|
37
37
|
export declare function _assertTypeOf<T>(v: any, expectedType: string, message?: string): asserts v is T;
|
|
38
38
|
export declare class AssertionError extends AppError {
|
|
39
|
+
constructor(message: string, data?: {}, opt?: ErrorOptions);
|
|
39
40
|
}
|
package/dist/error/assert.js
CHANGED
|
@@ -103,5 +103,8 @@ function _assertTypeOf(v, expectedType, message) {
|
|
|
103
103
|
}
|
|
104
104
|
exports._assertTypeOf = _assertTypeOf;
|
|
105
105
|
class AssertionError extends app_error_1.AppError {
|
|
106
|
+
constructor(message, data = {}, opt) {
|
|
107
|
+
super(message, data, opt, 'AssertionError');
|
|
108
|
+
}
|
|
106
109
|
}
|
|
107
110
|
exports.AssertionError = AssertionError;
|
package/dist/error/error.util.js
CHANGED
|
@@ -88,6 +88,12 @@ function _errorObjectToError(o, errorClass = Error) {
|
|
|
88
88
|
Object.defineProperty(err, 'name', {
|
|
89
89
|
value: o.name,
|
|
90
90
|
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(err.constructor, 'name', {
|
|
94
|
+
value: o.name,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
91
97
|
});
|
|
92
98
|
Object.defineProperty(err, 'data', {
|
|
93
99
|
value: o.data,
|
package/dist/error/http.error.js
CHANGED
package/dist/http/fetcher.js
CHANGED
|
@@ -345,7 +345,7 @@ class Fetcher {
|
|
|
345
345
|
return norm;
|
|
346
346
|
}
|
|
347
347
|
normalizeOptions(url, opt) {
|
|
348
|
-
const {
|
|
348
|
+
const { timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
|
|
349
349
|
const req = {
|
|
350
350
|
mode,
|
|
351
351
|
url,
|
|
@@ -370,6 +370,7 @@ class Fetcher {
|
|
|
370
370
|
}),
|
|
371
371
|
};
|
|
372
372
|
// setup url
|
|
373
|
+
const baseUrl = opt.baseUrl || this.cfg.baseUrl;
|
|
373
374
|
if (baseUrl) {
|
|
374
375
|
if (url.startsWith('/')) {
|
|
375
376
|
console.warn(`Fetcher: url should not start with / when baseUrl is specified`);
|
|
@@ -68,7 +68,7 @@ export interface FetcherRetryOptions {
|
|
|
68
68
|
timeoutMax: number;
|
|
69
69
|
timeoutMultiplier: number;
|
|
70
70
|
}
|
|
71
|
-
export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers'> {
|
|
71
|
+
export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers' | 'baseUrl'> {
|
|
72
72
|
url: string;
|
|
73
73
|
init: RequestInitNormalized;
|
|
74
74
|
mode: FetcherMode;
|
|
@@ -81,6 +81,7 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
|
|
|
81
81
|
}
|
|
82
82
|
export interface FetcherOptions {
|
|
83
83
|
method?: HttpMethod;
|
|
84
|
+
baseUrl?: string;
|
|
84
85
|
throwHttpErrors?: boolean;
|
|
85
86
|
/**
|
|
86
87
|
* Default: 30.
|
|
@@ -2,6 +2,7 @@ import { AppError } from '../error/app.error';
|
|
|
2
2
|
import type { ErrorData } from '../error/error.model';
|
|
3
3
|
import type { AnyAsyncFunction } from '../types';
|
|
4
4
|
export declare class TimeoutError extends AppError {
|
|
5
|
+
constructor(message: string, data?: {}, opt?: ErrorOptions);
|
|
5
6
|
}
|
|
6
7
|
export interface PTimeoutOptions {
|
|
7
8
|
/**
|
package/dist/promise/pTimeout.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pTimeout = exports.pTimeoutFn = exports.TimeoutError = void 0;
|
|
4
4
|
const app_error_1 = require("../error/app.error");
|
|
5
5
|
class TimeoutError extends app_error_1.AppError {
|
|
6
|
+
constructor(message, data = {}, opt) {
|
|
7
|
+
super(message, data, opt, 'TimeoutError');
|
|
8
|
+
}
|
|
6
9
|
}
|
|
7
10
|
exports.TimeoutError = TimeoutError;
|
|
8
11
|
/**
|
|
@@ -8,11 +8,18 @@
|
|
|
8
8
|
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
9
9
|
*/
|
|
10
10
|
export class AppError extends Error {
|
|
11
|
-
constructor(message, data = {}, opt) {
|
|
11
|
+
constructor(message, data = {}, opt, name) {
|
|
12
12
|
super(message);
|
|
13
13
|
Object.defineProperty(this, 'name', {
|
|
14
|
-
value: this.constructor.name,
|
|
14
|
+
value: name || this.constructor.name,
|
|
15
15
|
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
});
|
|
18
|
+
// this is to allow changing this.constuctor.name to a non-minified version
|
|
19
|
+
Object.defineProperty(this.constructor, 'name', {
|
|
20
|
+
value: name || this.constructor.name,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
16
23
|
});
|
|
17
24
|
Object.defineProperty(this, 'data', {
|
|
18
25
|
value: data,
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -79,6 +79,12 @@ export function _errorObjectToError(o, errorClass = Error) {
|
|
|
79
79
|
Object.defineProperty(err, 'name', {
|
|
80
80
|
value: o.name,
|
|
81
81
|
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(err.constructor, 'name', {
|
|
85
|
+
value: o.name,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
82
88
|
});
|
|
83
89
|
Object.defineProperty(err, 'data', {
|
|
84
90
|
value: o.data,
|
package/dist-esm/http/fetcher.js
CHANGED
|
@@ -387,7 +387,7 @@ export class Fetcher {
|
|
|
387
387
|
}
|
|
388
388
|
normalizeOptions(url, opt) {
|
|
389
389
|
var _a, _b;
|
|
390
|
-
const {
|
|
390
|
+
const { timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
|
|
391
391
|
const req = Object.assign(Object.assign({ mode,
|
|
392
392
|
url,
|
|
393
393
|
timeoutSeconds,
|
|
@@ -399,6 +399,7 @@ export class Fetcher {
|
|
|
399
399
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
|
400
400
|
}) });
|
|
401
401
|
// setup url
|
|
402
|
+
const baseUrl = opt.baseUrl || this.cfg.baseUrl;
|
|
402
403
|
if (baseUrl) {
|
|
403
404
|
if (url.startsWith('/')) {
|
|
404
405
|
console.warn(`Fetcher: url should not start with / when baseUrl is specified`);
|
package/package.json
CHANGED
package/src/error/app.error.ts
CHANGED
|
@@ -17,12 +17,20 @@ export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
|
17
17
|
*/
|
|
18
18
|
override cause?: Error
|
|
19
19
|
|
|
20
|
-
constructor(message: string, data = {} as DATA_TYPE, opt?: ErrorOptions) {
|
|
20
|
+
constructor(message: string, data = {} as DATA_TYPE, opt?: ErrorOptions, name?: string) {
|
|
21
21
|
super(message)
|
|
22
22
|
|
|
23
23
|
Object.defineProperty(this, 'name', {
|
|
24
|
-
value: this.constructor.name,
|
|
24
|
+
value: name || this.constructor.name,
|
|
25
25
|
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// this is to allow changing this.constuctor.name to a non-minified version
|
|
30
|
+
Object.defineProperty(this.constructor, 'name', {
|
|
31
|
+
value: name || this.constructor.name,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
26
34
|
})
|
|
27
35
|
|
|
28
36
|
Object.defineProperty(this, 'data', {
|
package/src/error/assert.ts
CHANGED
|
@@ -123,4 +123,8 @@ export function _assertTypeOf<T>(v: any, expectedType: string, message?: string)
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export class AssertionError extends AppError {
|
|
126
|
+
export class AssertionError extends AppError {
|
|
127
|
+
constructor(message: string, data = {}, opt?: ErrorOptions) {
|
|
128
|
+
super(message, data, opt, 'AssertionError')
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/error/error.util.ts
CHANGED
|
@@ -105,6 +105,13 @@ export function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE exte
|
|
|
105
105
|
Object.defineProperty(err, 'name', {
|
|
106
106
|
value: o.name,
|
|
107
107
|
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
Object.defineProperty(err.constructor, 'name', {
|
|
112
|
+
value: o.name,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
108
115
|
})
|
|
109
116
|
|
|
110
117
|
Object.defineProperty(err, 'data', {
|
package/src/error/http.error.ts
CHANGED
|
@@ -79,7 +79,7 @@ export interface FetcherRetryOptions {
|
|
|
79
79
|
timeoutMultiplier: number
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers'> {
|
|
82
|
+
export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers' | 'baseUrl'> {
|
|
83
83
|
url: string
|
|
84
84
|
init: RequestInitNormalized
|
|
85
85
|
mode: FetcherMode
|
|
@@ -93,6 +93,9 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
|
|
|
93
93
|
|
|
94
94
|
export interface FetcherOptions {
|
|
95
95
|
method?: HttpMethod
|
|
96
|
+
|
|
97
|
+
baseUrl?: string
|
|
98
|
+
|
|
96
99
|
throwHttpErrors?: boolean
|
|
97
100
|
/**
|
|
98
101
|
* Default: 30.
|
package/src/http/fetcher.ts
CHANGED
|
@@ -436,7 +436,6 @@ export class Fetcher {
|
|
|
436
436
|
|
|
437
437
|
private normalizeOptions(url: string, opt: FetcherOptions): FetcherRequest {
|
|
438
438
|
const {
|
|
439
|
-
baseUrl,
|
|
440
439
|
timeoutSeconds,
|
|
441
440
|
throwHttpErrors,
|
|
442
441
|
retryPost,
|
|
@@ -475,6 +474,7 @@ export class Fetcher {
|
|
|
475
474
|
}
|
|
476
475
|
|
|
477
476
|
// setup url
|
|
477
|
+
const baseUrl = opt.baseUrl || this.cfg.baseUrl
|
|
478
478
|
if (baseUrl) {
|
|
479
479
|
if (url.startsWith('/')) {
|
|
480
480
|
console.warn(`Fetcher: url should not start with / when baseUrl is specified`)
|
package/src/http/http.model.ts
CHANGED
package/src/promise/pTimeout.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { AppError } from '../error/app.error'
|
|
|
2
2
|
import type { ErrorData } from '../error/error.model'
|
|
3
3
|
import type { AnyAsyncFunction } from '../types'
|
|
4
4
|
|
|
5
|
-
export class TimeoutError extends AppError {
|
|
5
|
+
export class TimeoutError extends AppError {
|
|
6
|
+
constructor(message: string, data = {}, opt?: ErrorOptions) {
|
|
7
|
+
super(message, data, opt, 'TimeoutError')
|
|
8
|
+
}
|
|
9
|
+
}
|
|
6
10
|
|
|
7
11
|
export interface PTimeoutOptions {
|
|
8
12
|
/**
|