@midwayjs/axios 3.19.2 → 3.20.1-beta.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/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} +6 -13
- 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 -3
- package/dist/index.js +2 -1
- package/dist/interface.d.ts +5 -20
- package/index.d.ts +1 -1
- package/package.json +4 -5
- package/LICENSE +0 -21
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,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 } from 'axios';
|
|
2
|
+
import { MidwayAxiosRequestConfig as AxiosRequestConfig, MidwayAxiosResponse as AxiosResponse } from './interface';
|
|
3
|
+
export declare class HttpService implements Axios {
|
|
11
4
|
private instance;
|
|
12
5
|
private serviceFactory;
|
|
6
|
+
protected init(): Promise<void>;
|
|
13
7
|
get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
14
8
|
headers: import("axios").HeadersDefaults & {
|
|
15
9
|
[key: string]: import("axios").AxiosHeaderValue;
|
|
@@ -17,9 +11,8 @@ export declare class HttpService implements AxiosHttpService {
|
|
|
17
11
|
};
|
|
18
12
|
get interceptors(): {
|
|
19
13
|
request: import("axios").AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig<any>>;
|
|
20
|
-
response: import("axios").AxiosInterceptorManager<AxiosResponse<any, any>>;
|
|
14
|
+
response: import("axios").AxiosInterceptorManager<import("axios").AxiosResponse<any, any>>;
|
|
21
15
|
};
|
|
22
|
-
protected init(): Promise<void>;
|
|
23
16
|
getUri(config?: AxiosRequestConfig): string;
|
|
24
17
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
25
18
|
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
@@ -33,4 +26,4 @@ export declare class HttpService implements AxiosHttpService {
|
|
|
33
26
|
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
34
27
|
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
35
28
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
29
|
+
//# 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,12 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import * as Axios from 'axios';
|
|
3
3
|
export { AxiosConfiguration as Configuration } from './configuration';
|
|
4
|
+
export * from './http-service.factory';
|
|
5
|
+
export * from './http-service';
|
|
4
6
|
export * from './interface';
|
|
5
|
-
export * from './serviceManager';
|
|
6
7
|
export {
|
|
7
8
|
/**
|
|
8
9
|
* @deprecated Use `Axios` directly
|
|
9
10
|
*/
|
|
10
|
-
axios, };
|
|
11
|
-
export { Axios };
|
|
11
|
+
axios, Axios, };
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ 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("./http-service.factory"), exports);
|
|
25
|
+
__exportStar(require("./http-service"), exports);
|
|
24
26
|
__exportStar(require("./interface"), exports);
|
|
25
|
-
__exportStar(require("./serviceManager"), exports);
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
export type MidwayAxiosRequestConfig<D = any, CONFIG = any> = AxiosRequestConfig<D> & CONFIG;
|
|
3
|
+
export type MidwayAxiosResponse<T = any, D = any, CONFIG = any> = AxiosResponse<T, D> & {
|
|
4
|
+
config: MidwayAxiosRequestConfig<D, CONFIG>;
|
|
5
|
+
};
|
|
21
6
|
//# sourceMappingURL=interface.d.ts.map
|
package/index.d.ts
CHANGED
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.1-beta.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -10,8 +10,8 @@
|
|
|
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": {
|
|
@@ -36,6 +36,5 @@
|
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
38
|
"url": "https://github.com/midwayjs/midway.git"
|
|
39
|
-
}
|
|
40
|
-
"gitHead": "57fd034be94897fb819b0d9ef776de0b9923ab0f"
|
|
39
|
+
}
|
|
41
40
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|