@biorate/axios 0.27.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.nyc_output/5c81a657-24fa-496a-9a7b-e0e9761a8dfe.json +1 -0
- package/.nyc_output/processinfo/5c81a657-24fa-496a-9a7b-e0e9761a8dfe.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/CHANGELOG.md +38 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +116 -0
- package/coverage/lcov-report/index.ts.html +400 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +63 -0
- package/package.json +4 -4
- package/index.ts +0 -1
- package/src/index.ts +0 -105
- package/src/interfaces.ts +0 -5
@@ -0,0 +1,63 @@
|
|
1
|
+
TN:
|
2
|
+
SF:src/index.ts
|
3
|
+
FN:41,(anonymous_6)
|
4
|
+
FN:49,(anonymous_7)
|
5
|
+
FN:55,(anonymous_8)
|
6
|
+
FN:68,(anonymous_9)
|
7
|
+
FN:93,(anonymous_10)
|
8
|
+
FN:98,(anonymous_11)
|
9
|
+
FN:104,(anonymous_12)
|
10
|
+
FNF:7
|
11
|
+
FNH:7
|
12
|
+
FNDA:3,(anonymous_6)
|
13
|
+
FNDA:3,(anonymous_7)
|
14
|
+
FNDA:3,(anonymous_8)
|
15
|
+
FNDA:3,(anonymous_9)
|
16
|
+
FNDA:3,(anonymous_10)
|
17
|
+
FNDA:1,(anonymous_11)
|
18
|
+
FNDA:2,(anonymous_12)
|
19
|
+
DA:1,1
|
20
|
+
DA:2,1
|
21
|
+
DA:3,1
|
22
|
+
DA:4,1
|
23
|
+
DA:7,1
|
24
|
+
DA:9,1
|
25
|
+
DA:16,1
|
26
|
+
DA:41,1
|
27
|
+
DA:45,1
|
28
|
+
DA:50,3
|
29
|
+
DA:58,3
|
30
|
+
DA:59,3
|
31
|
+
DA:64,3
|
32
|
+
DA:69,3
|
33
|
+
DA:70,3
|
34
|
+
DA:71,3
|
35
|
+
DA:73,3
|
36
|
+
DA:74,3
|
37
|
+
DA:75,0
|
38
|
+
DA:76,3
|
39
|
+
DA:77,0
|
40
|
+
DA:78,3
|
41
|
+
DA:81,3
|
42
|
+
DA:82,3
|
43
|
+
DA:83,3
|
44
|
+
DA:85,2
|
45
|
+
DA:87,3
|
46
|
+
DA:99,1
|
47
|
+
LF:28
|
48
|
+
LH:26
|
49
|
+
BRDA:58,0,0,3
|
50
|
+
BRDA:58,0,1,0
|
51
|
+
BRDA:69,1,0,3
|
52
|
+
BRDA:69,1,1,0
|
53
|
+
BRDA:74,2,0,0
|
54
|
+
BRDA:74,2,1,3
|
55
|
+
BRDA:74,3,0,3
|
56
|
+
BRDA:74,3,1,3
|
57
|
+
BRDA:76,4,0,0
|
58
|
+
BRDA:76,4,1,3
|
59
|
+
BRDA:76,5,0,3
|
60
|
+
BRDA:76,5,1,0
|
61
|
+
BRF:12
|
62
|
+
BRH:7
|
63
|
+
end_of_record
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@biorate/axios",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.30.0",
|
4
4
|
"description": "Axios OOP static interface",
|
5
5
|
"main": "dist",
|
6
6
|
"scripts": {
|
@@ -29,8 +29,8 @@
|
|
29
29
|
"path-to-url": "^0.1.0"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
|
-
"@biorate/config": "0.
|
33
|
-
"@biorate/inversion": "0.
|
32
|
+
"@biorate/config": "0.30.0",
|
33
|
+
"@biorate/inversion": "0.30.0"
|
34
34
|
},
|
35
|
-
"gitHead": "
|
35
|
+
"gitHead": "4e2b75f1a37d93bfb4854bd64ed9691781c2b800"
|
36
36
|
}
|
package/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './src';
|
package/src/index.ts
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
import { omit, pick } from 'lodash';
|
2
|
-
import axios, { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
3
|
-
import retry, { IAxiosRetryConfig } from 'axios-retry';
|
4
|
-
import * as pathToUrl from 'path-to-url';
|
5
|
-
import { IAxiosFetchOptions } from './interfaces';
|
6
|
-
|
7
|
-
export * from './interfaces';
|
8
|
-
|
9
|
-
const axiosRetryConfigKeys = [
|
10
|
-
'retries',
|
11
|
-
'retryDelay',
|
12
|
-
'shouldResetTimeout',
|
13
|
-
'retryCondition',
|
14
|
-
];
|
15
|
-
|
16
|
-
const axiosExcludeKeys = ['path', 'config'];
|
17
|
-
|
18
|
-
/**
|
19
|
-
* @description
|
20
|
-
* Axios OOP static interface
|
21
|
-
*
|
22
|
-
* ### Features:
|
23
|
-
* - OOP
|
24
|
-
* - DI
|
25
|
-
*
|
26
|
-
* @example
|
27
|
-
* ```
|
28
|
-
* import { Axios } from '@biorate/axios';
|
29
|
-
*
|
30
|
-
* class Yandex extends Axios {
|
31
|
-
* public baseURL = 'https://yandex.ru';
|
32
|
-
* }
|
33
|
-
*
|
34
|
-
* (async () => {
|
35
|
-
* const response = await Yandex.fetch<string>();
|
36
|
-
* console.log(response.status); // 200
|
37
|
-
* console.log(response.data); // <!DOCTYPE html><html ...
|
38
|
-
* })();
|
39
|
-
* ```
|
40
|
-
*/
|
41
|
-
export class Axios {
|
42
|
-
/**
|
43
|
-
* @description Axios instance cache
|
44
|
-
*/
|
45
|
-
protected static cache = new WeakMap<Object, Axios>();
|
46
|
-
/**
|
47
|
-
* @description Fetch static method
|
48
|
-
*/
|
49
|
-
public static fetch(...args: unknown[]) {
|
50
|
-
return this._fetch(...args);
|
51
|
-
}
|
52
|
-
/**
|
53
|
-
* @description Protected fetch static method
|
54
|
-
*/
|
55
|
-
protected static _fetch<D = any>(
|
56
|
-
options?: IAxiosFetchOptions,
|
57
|
-
): Promise<AxiosResponse<D>> {
|
58
|
-
if (!this.cache.has(this)) this.cache.set(this, new this());
|
59
|
-
return this.cache.get(this).fetch<D>(options);
|
60
|
-
}
|
61
|
-
/**
|
62
|
-
* @description Axios client cache
|
63
|
-
*/
|
64
|
-
#client: AxiosInstance;
|
65
|
-
/**
|
66
|
-
* @description Fetch method
|
67
|
-
*/
|
68
|
-
protected async fetch<D>(options?: IAxiosFetchOptions): Promise<AxiosResponse<D>> {
|
69
|
-
if (!this.#client) {
|
70
|
-
this.#client = axios.create();
|
71
|
-
retry(this.#client, <IAxiosRetryConfig>pick(this, axiosRetryConfigKeys));
|
72
|
-
}
|
73
|
-
const settings = { ...this, ...options };
|
74
|
-
if (settings.baseURL && settings.path)
|
75
|
-
settings.baseURL = pathToUrl(settings.baseURL, settings.path);
|
76
|
-
if (settings.url && settings.path)
|
77
|
-
settings.url = pathToUrl(settings.url, settings.path);
|
78
|
-
const params = {
|
79
|
-
...omit(settings, axiosRetryConfigKeys.concat(axiosExcludeKeys)),
|
80
|
-
};
|
81
|
-
try {
|
82
|
-
await this.before(params);
|
83
|
-
return await this.#client(params);
|
84
|
-
} catch (e) {
|
85
|
-
await this.catch(e);
|
86
|
-
} finally {
|
87
|
-
await this.finally();
|
88
|
-
}
|
89
|
-
}
|
90
|
-
/**
|
91
|
-
* @description Before hook
|
92
|
-
*/
|
93
|
-
protected async before(params: IAxiosFetchOptions) {}
|
94
|
-
|
95
|
-
/**
|
96
|
-
* @description Catch hook
|
97
|
-
*/
|
98
|
-
protected async catch(e: Error) {
|
99
|
-
throw e;
|
100
|
-
}
|
101
|
-
/**
|
102
|
-
* @description Finally hook
|
103
|
-
*/
|
104
|
-
protected async finally() {}
|
105
|
-
}
|