@biorate/axios 0.28.0 → 0.29.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.28.0",
3
+ "version": "0.29.1",
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.28.0",
33
- "@biorate/inversion": "0.28.0"
32
+ "@biorate/config": "0.29.1",
33
+ "@biorate/inversion": "0.29.1"
34
34
  },
35
- "gitHead": "4857311a7f3664a01bc1a1142f46b4ed5e632efd"
35
+ "gitHead": "5b2e555c3d82c8d276aa9385ebc0eff28c68db33"
36
36
  }
package/dist/src/index.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- 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");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var _Axios_client;
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Axios = void 0;
30
- const lodash_1 = require("lodash");
31
- const axios_1 = require("axios");
32
- const axios_retry_1 = require("axios-retry");
33
- const pathToUrl = require("path-to-url");
34
- __exportStar(require("./interfaces"), exports);
35
- const axiosRetryConfigKeys = [
36
- 'retries',
37
- 'retryDelay',
38
- 'shouldResetTimeout',
39
- 'retryCondition',
40
- ];
41
- const axiosExcludeKeys = ['path', 'config'];
42
- class Axios {
43
- constructor() {
44
- _Axios_client.set(this, void 0);
45
- }
46
- static fetch(...args) {
47
- return this._fetch(...args);
48
- }
49
- static _fetch(options) {
50
- if (!this.cache.has(this))
51
- this.cache.set(this, new this());
52
- return this.cache.get(this).fetch(options);
53
- }
54
- async fetch(options) {
55
- if (!__classPrivateFieldGet(this, _Axios_client, "f")) {
56
- __classPrivateFieldSet(this, _Axios_client, axios_1.default.create(), "f");
57
- (0, axios_retry_1.default)(__classPrivateFieldGet(this, _Axios_client, "f"), (0, lodash_1.pick)(this, axiosRetryConfigKeys));
58
- }
59
- const settings = Object.assign(Object.assign({}, this), options);
60
- if (settings.baseURL && settings.path)
61
- settings.baseURL = pathToUrl(settings.baseURL, settings.path);
62
- if (settings.url && settings.path)
63
- settings.url = pathToUrl(settings.url, settings.path);
64
- const params = Object.assign({}, (0, lodash_1.omit)(settings, axiosRetryConfigKeys.concat(axiosExcludeKeys)));
65
- try {
66
- await this.before(params);
67
- return await __classPrivateFieldGet(this, _Axios_client, "f").call(this, params);
68
- }
69
- catch (e) {
70
- await this.catch(e);
71
- }
72
- finally {
73
- await this.finally();
74
- }
75
- }
76
- async before(params) { }
77
- async catch(e) {
78
- throw e;
79
- }
80
- async finally() { }
81
- }
82
- exports.Axios = Axios;
83
- _Axios_client = new WeakMap();
84
- Axios.cache = new WeakMap();
85
- //# sourceMappingURL=index.js.map
@@ -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QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChE,IAAI,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,IAAI;YAC/B,QAAQ,CAAC,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,MAAM,qBACP,IAAA,aAAI,EAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CACjE,CAAC;QACF,IAAI;YACF,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1B,OAAO,MAAM,uBAAA,IAAI,qBAAQ,MAAZ,IAAI,EAAS,MAAM,CAAC,CAAC;SACnC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACrB;gBAAS;YACR,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;SACtB;IACH,CAAC;IAIS,KAAK,CAAC,MAAM,CAAC,MAA0B,IAAG,CAAC;IAK3C,KAAK,CAAC,KAAK,CAAC,CAAQ;QAC5B,MAAM,CAAC,CAAC;IACV,CAAC;IAIS,KAAK,CAAC,OAAO,KAAI,CAAC;;AA/D9B,sBAgEC;;AA5DkB,WAAK,GAAG,IAAI,OAAO,EAAiB,CAAC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":""}
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
- }
package/src/interfaces.ts DELETED
@@ -1,5 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
-
3
- export type IAxiosFetchOptions = AxiosRequestConfig & {
4
- path?: Record<string, string | number>;
5
- };
@@ -1,15 +0,0 @@
1
- import { Axios } from '../../src';
2
- import { inject, container, Types } from '@biorate/inversion';
3
- import { IConfig, Config } from '@biorate/config';
4
-
5
- export class Yandex extends Axios {
6
- @inject(Types.Config) public config: IConfig;
7
- // @ts-ignore
8
- public baseURL = this.config.get<string>('baseURL');
9
- }
10
-
11
- container.bind(Types.Config).to(Config).inSingletonScope();
12
-
13
- container.get<IConfig>(Types.Config).merge({
14
- baseURL: 'https://google.com',
15
- });