@midwayjs/axios 3.19.1 → 3.20.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 +1 -1
- package/dist/config.default.d.ts +8 -0
- package/dist/config.default.js +9 -0
- package/dist/configuration.d.ts +2 -1
- package/dist/configuration.js +4 -5
- package/dist/{serviceManager.d.ts → http-service.d.ts} +4 -12
- package/dist/http-service.factory.d.ts +9 -0
- package/dist/http-service.factory.js +50 -0
- package/dist/{serviceManager.js → http-service.js} +9 -44
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -2
- package/package.json +5 -5
- package/dist/interface.d.ts +0 -21
- package/dist/interface.js +0 -3
package/README.md
CHANGED
package/dist/configuration.d.ts
CHANGED
package/dist/configuration.js
CHANGED
|
@@ -8,10 +8,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AxiosConfiguration = void 0;
|
|
10
10
|
const core_1 = require("@midwayjs/core");
|
|
11
|
-
const
|
|
11
|
+
const config_default_1 = require("./config.default");
|
|
12
|
+
const http_service_factory_1 = require("./http-service.factory");
|
|
12
13
|
let AxiosConfiguration = class AxiosConfiguration {
|
|
13
14
|
async onReady(container) {
|
|
14
|
-
await container.getAsync(
|
|
15
|
+
await container.getAsync(http_service_factory_1.HttpServiceFactory);
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
AxiosConfiguration = __decorate([
|
|
@@ -19,9 +20,7 @@ AxiosConfiguration = __decorate([
|
|
|
19
20
|
namespace: 'axios',
|
|
20
21
|
importConfigs: [
|
|
21
22
|
{
|
|
22
|
-
default:
|
|
23
|
-
axios: {},
|
|
24
|
-
},
|
|
23
|
+
default: config_default_1.default,
|
|
25
24
|
},
|
|
26
25
|
],
|
|
27
26
|
importConfigFilter: config => {
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { AxiosHttpService } from './interface';
|
|
4
|
-
export declare class HttpServiceFactory extends ServiceFactory<AxiosInstance> {
|
|
5
|
-
axiosConfig: any;
|
|
6
|
-
init(): Promise<void>;
|
|
7
|
-
protected createClient(config: CreateAxiosDefaults, clientName: any): Promise<AxiosInstance>;
|
|
8
|
-
getName(): string;
|
|
9
|
-
}
|
|
10
|
-
export declare class HttpService implements AxiosHttpService {
|
|
1
|
+
import { Axios, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
export declare class HttpService implements Axios {
|
|
11
3
|
private instance;
|
|
12
4
|
private serviceFactory;
|
|
5
|
+
protected init(): Promise<void>;
|
|
13
6
|
get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
14
7
|
headers: import("axios").HeadersDefaults & {
|
|
15
8
|
[key: string]: import("axios").AxiosHeaderValue;
|
|
@@ -19,7 +12,6 @@ export declare class HttpService implements AxiosHttpService {
|
|
|
19
12
|
request: import("axios").AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig<any>>;
|
|
20
13
|
response: import("axios").AxiosInterceptorManager<AxiosResponse<any, any>>;
|
|
21
14
|
};
|
|
22
|
-
protected init(): Promise<void>;
|
|
23
15
|
getUri(config?: AxiosRequestConfig): string;
|
|
24
16
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
25
17
|
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
@@ -33,4 +25,4 @@ export declare class HttpService implements AxiosHttpService {
|
|
|
33
25
|
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
34
26
|
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
35
27
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=http-service.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ServiceFactory } from '@midwayjs/core';
|
|
2
|
+
import { AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
3
|
+
export declare class HttpServiceFactory extends ServiceFactory<AxiosInstance> {
|
|
4
|
+
axiosConfig: any;
|
|
5
|
+
init(): Promise<void>;
|
|
6
|
+
getName(): string;
|
|
7
|
+
protected createClient(config: CreateAxiosDefaults, clientName: string): Promise<AxiosInstance>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=http-service.factory.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpServiceFactory = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
|
+
const axios_1 = require("axios");
|
|
15
|
+
let HttpServiceFactory = class HttpServiceFactory extends core_1.ServiceFactory {
|
|
16
|
+
async init() {
|
|
17
|
+
let axiosConfig = this.axiosConfig;
|
|
18
|
+
if (!this.axiosConfig['clients']) {
|
|
19
|
+
axiosConfig = {
|
|
20
|
+
default: {},
|
|
21
|
+
clients: {
|
|
22
|
+
default: this.axiosConfig,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
await this.initClients(axiosConfig);
|
|
27
|
+
}
|
|
28
|
+
getName() {
|
|
29
|
+
return 'axios';
|
|
30
|
+
}
|
|
31
|
+
async createClient(config, clientName) {
|
|
32
|
+
return axios_1.default.create(config);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, core_1.Config)('axios'),
|
|
37
|
+
__metadata("design:type", Object)
|
|
38
|
+
], HttpServiceFactory.prototype, "axiosConfig", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, core_1.Init)(),
|
|
41
|
+
__metadata("design:type", Function),
|
|
42
|
+
__metadata("design:paramtypes", []),
|
|
43
|
+
__metadata("design:returntype", Promise)
|
|
44
|
+
], HttpServiceFactory.prototype, "init", null);
|
|
45
|
+
HttpServiceFactory = __decorate([
|
|
46
|
+
(0, core_1.Provide)(),
|
|
47
|
+
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
48
|
+
], HttpServiceFactory);
|
|
49
|
+
exports.HttpServiceFactory = HttpServiceFactory;
|
|
50
|
+
//# sourceMappingURL=http-service.factory.js.map
|
|
@@ -9,58 +9,23 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.HttpService =
|
|
13
|
-
const axios_1 = require("axios");
|
|
12
|
+
exports.HttpService = void 0;
|
|
14
13
|
const core_1 = require("@midwayjs/core");
|
|
15
|
-
|
|
14
|
+
const http_service_factory_1 = require("./http-service.factory");
|
|
15
|
+
let HttpService = class HttpService {
|
|
16
16
|
async init() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
clients: {
|
|
22
|
-
default: this.axiosConfig,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
17
|
+
const clientName = this.serviceFactory.getDefaultClientName() || 'default';
|
|
18
|
+
this.instance = this.serviceFactory.get(clientName);
|
|
19
|
+
if (!this.instance) {
|
|
20
|
+
throw new core_1.MidwayCommonError('axios default instance not found.');
|
|
25
21
|
}
|
|
26
|
-
await this.initClients(axiosConfig);
|
|
27
|
-
}
|
|
28
|
-
async createClient(config, clientName) {
|
|
29
|
-
return axios_1.default.create(config);
|
|
30
|
-
}
|
|
31
|
-
getName() {
|
|
32
|
-
return 'axios';
|
|
33
22
|
}
|
|
34
|
-
};
|
|
35
|
-
__decorate([
|
|
36
|
-
(0, core_1.Config)('axios'),
|
|
37
|
-
__metadata("design:type", Object)
|
|
38
|
-
], HttpServiceFactory.prototype, "axiosConfig", void 0);
|
|
39
|
-
__decorate([
|
|
40
|
-
(0, core_1.Init)(),
|
|
41
|
-
__metadata("design:type", Function),
|
|
42
|
-
__metadata("design:paramtypes", []),
|
|
43
|
-
__metadata("design:returntype", Promise)
|
|
44
|
-
], HttpServiceFactory.prototype, "init", null);
|
|
45
|
-
HttpServiceFactory = __decorate([
|
|
46
|
-
(0, core_1.Provide)(),
|
|
47
|
-
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
48
|
-
], HttpServiceFactory);
|
|
49
|
-
exports.HttpServiceFactory = HttpServiceFactory;
|
|
50
|
-
let HttpService = class HttpService {
|
|
51
23
|
get defaults() {
|
|
52
24
|
return this.instance.defaults;
|
|
53
25
|
}
|
|
54
26
|
get interceptors() {
|
|
55
27
|
return this.instance.interceptors;
|
|
56
28
|
}
|
|
57
|
-
async init() {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
this.instance = this.serviceFactory.get(((_b = (_a = this.serviceFactory).getDefaultClientName) === null || _b === void 0 ? void 0 : _b.call(_a)) || 'default');
|
|
60
|
-
if (!this.instance) {
|
|
61
|
-
throw new core_1.MidwayCommonError('axios default instance not found.');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
29
|
getUri(config) {
|
|
65
30
|
return this.instance.getUri(config);
|
|
66
31
|
}
|
|
@@ -100,7 +65,7 @@ let HttpService = class HttpService {
|
|
|
100
65
|
};
|
|
101
66
|
__decorate([
|
|
102
67
|
(0, core_1.Inject)(),
|
|
103
|
-
__metadata("design:type", HttpServiceFactory)
|
|
68
|
+
__metadata("design:type", http_service_factory_1.HttpServiceFactory)
|
|
104
69
|
], HttpService.prototype, "serviceFactory", void 0);
|
|
105
70
|
__decorate([
|
|
106
71
|
(0, core_1.Init)(),
|
|
@@ -113,4 +78,4 @@ HttpService = __decorate([
|
|
|
113
78
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
114
79
|
], HttpService);
|
|
115
80
|
exports.HttpService = HttpService;
|
|
116
|
-
//# sourceMappingURL=
|
|
81
|
+
//# sourceMappingURL=http-service.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import * as Axios from 'axios';
|
|
3
3
|
export { AxiosConfiguration as Configuration } from './configuration';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './http-service.factory';
|
|
5
|
+
export * from './http-service';
|
|
6
6
|
export {
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated Use `Axios` directly
|
|
9
9
|
*/
|
|
10
|
-
axios, };
|
|
11
|
-
export { Axios };
|
|
10
|
+
axios, Axios, };
|
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,6 @@ const Axios = require("axios");
|
|
|
21
21
|
exports.Axios = Axios;
|
|
22
22
|
var configuration_1 = require("./configuration");
|
|
23
23
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.AxiosConfiguration; } });
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./http-service.factory"), exports);
|
|
25
|
+
__exportStar(require("./http-service"), exports);
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/axios",
|
|
3
3
|
"description": "midway http client with axios",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.20.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"index.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@midwayjs/core": "^3.
|
|
14
|
-
"@midwayjs/mock": "^3.
|
|
13
|
+
"@midwayjs/core": "^3.20.0",
|
|
14
|
+
"@midwayjs/mock": "^3.20.0",
|
|
15
15
|
"nock": "13.5.6"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"axios": "1.7.
|
|
18
|
+
"axios": "1.7.9"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"http client",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"type": "git",
|
|
38
38
|
"url": "https://github.com/midwayjs/midway.git"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5bf838ec6054f6e1e983664b0456a975db795932"
|
|
41
41
|
}
|
package/dist/interface.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { AxiosRequestConfig, AxiosResponse, AxiosInterceptorManager, AxiosDefaults } from 'axios';
|
|
2
|
-
export interface AxiosHttpService {
|
|
3
|
-
defaults: AxiosDefaults;
|
|
4
|
-
interceptors: {
|
|
5
|
-
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
|
6
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
7
|
-
};
|
|
8
|
-
getUri(config?: AxiosRequestConfig): string;
|
|
9
|
-
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
10
|
-
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
11
|
-
delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
12
|
-
head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
13
|
-
options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
14
|
-
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
15
|
-
put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
16
|
-
patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
17
|
-
postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
18
|
-
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
19
|
-
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=interface.d.ts.map
|
package/dist/interface.js
DELETED