@midwayjs/axios 4.0.0-alpha.1 → 4.0.0-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} +12 -18
- 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 -43
- package/dist/index.d.ts +3 -8
- package/dist/index.js +4 -4
- package/dist/interface.d.ts +9 -18
- package/index.d.ts +1 -1
- package/package.json +5 -5
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
|
exports.AxiosConfiguration = AxiosConfiguration;
|
|
@@ -20,9 +21,7 @@ exports.AxiosConfiguration = AxiosConfiguration = __decorate([
|
|
|
20
21
|
namespace: 'axios',
|
|
21
22
|
importConfigs: [
|
|
22
23
|
{
|
|
23
|
-
default:
|
|
24
|
-
axios: {},
|
|
25
|
-
},
|
|
24
|
+
default: config_default_1.default,
|
|
26
25
|
},
|
|
27
26
|
],
|
|
28
27
|
importConfigFilter: config => {
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { AxiosHttpService } from './interface';
|
|
5
|
-
export declare class HttpServiceFactory extends ServiceFactory<AxiosInstance> {
|
|
6
|
-
axiosConfig: any;
|
|
7
|
-
init(): Promise<void>;
|
|
8
|
-
protected createClient(config: CreateAxiosDefaults, clientName: any): Promise<AxiosInstance>;
|
|
9
|
-
getName(): string;
|
|
10
|
-
}
|
|
11
|
-
export declare class HttpService implements AxiosHttpService {
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { AxiosRequestConfig, AxiosResponse } from './interface';
|
|
3
|
+
export declare class HttpService {
|
|
12
4
|
private instance;
|
|
13
5
|
private serviceFactory;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
protected init(): Promise<void>;
|
|
7
|
+
get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
8
|
+
headers: import("axios").HeadersDefaults & {
|
|
9
|
+
[key: string]: import("axios").AxiosHeaderValue;
|
|
17
10
|
};
|
|
18
11
|
};
|
|
19
12
|
get interceptors(): {
|
|
20
|
-
request: axios.AxiosInterceptorManager<axios.InternalAxiosRequestConfig<any>>;
|
|
21
|
-
response: axios.AxiosInterceptorManager<AxiosResponse<any, any>>;
|
|
13
|
+
request: import("axios").AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig<any>>;
|
|
14
|
+
response: import("axios").AxiosInterceptorManager<import("axios").AxiosResponse<any, any>>;
|
|
22
15
|
};
|
|
23
|
-
protected init(): Promise<void>;
|
|
24
16
|
getUri(config?: AxiosRequestConfig): string;
|
|
25
17
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
26
18
|
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
@@ -34,4 +26,6 @@ export declare class HttpService implements AxiosHttpService {
|
|
|
34
26
|
putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
35
27
|
patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
36
28
|
}
|
|
37
|
-
|
|
29
|
+
export interface HttpService extends AxiosInstance {
|
|
30
|
+
}
|
|
31
|
+
//# 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 = 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.create(config);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.HttpServiceFactory = HttpServiceFactory;
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, core_1.Config)('axios'),
|
|
38
|
+
__metadata("design:type", Object)
|
|
39
|
+
], HttpServiceFactory.prototype, "axiosConfig", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, core_1.Init)(),
|
|
42
|
+
__metadata("design:type", Function),
|
|
43
|
+
__metadata("design:paramtypes", []),
|
|
44
|
+
__metadata("design:returntype", Promise)
|
|
45
|
+
], HttpServiceFactory.prototype, "init", null);
|
|
46
|
+
exports.HttpServiceFactory = HttpServiceFactory = __decorate([
|
|
47
|
+
(0, core_1.Provide)(),
|
|
48
|
+
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
49
|
+
], HttpServiceFactory);
|
|
50
|
+
//# sourceMappingURL=http-service.factory.js.map
|
|
@@ -9,57 +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 = 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.create(config);
|
|
30
|
-
}
|
|
31
|
-
getName() {
|
|
32
|
-
return 'axios';
|
|
33
22
|
}
|
|
34
|
-
};
|
|
35
|
-
exports.HttpServiceFactory = HttpServiceFactory;
|
|
36
|
-
__decorate([
|
|
37
|
-
(0, core_1.Config)('axios'),
|
|
38
|
-
__metadata("design:type", Object)
|
|
39
|
-
], HttpServiceFactory.prototype, "axiosConfig", void 0);
|
|
40
|
-
__decorate([
|
|
41
|
-
(0, core_1.Init)(),
|
|
42
|
-
__metadata("design:type", Function),
|
|
43
|
-
__metadata("design:paramtypes", []),
|
|
44
|
-
__metadata("design:returntype", Promise)
|
|
45
|
-
], HttpServiceFactory.prototype, "init", null);
|
|
46
|
-
exports.HttpServiceFactory = HttpServiceFactory = __decorate([
|
|
47
|
-
(0, core_1.Provide)(),
|
|
48
|
-
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
49
|
-
], 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
|
-
this.instance = this.serviceFactory.get(this.serviceFactory.getDefaultClientName?.() || 'default');
|
|
59
|
-
if (!this.instance) {
|
|
60
|
-
throw new core_1.MidwayCommonError('axios default instance not found.');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
29
|
getUri(config) {
|
|
64
30
|
return this.instance.getUri(config);
|
|
65
31
|
}
|
|
@@ -100,7 +66,7 @@ let HttpService = class HttpService {
|
|
|
100
66
|
exports.HttpService = HttpService;
|
|
101
67
|
__decorate([
|
|
102
68
|
(0, core_1.Inject)(),
|
|
103
|
-
__metadata("design:type", HttpServiceFactory)
|
|
69
|
+
__metadata("design:type", http_service_factory_1.HttpServiceFactory)
|
|
104
70
|
], HttpService.prototype, "serviceFactory", void 0);
|
|
105
71
|
__decorate([
|
|
106
72
|
(0, core_1.Init)(),
|
|
@@ -112,4 +78,4 @@ exports.HttpService = HttpService = __decorate([
|
|
|
112
78
|
(0, core_1.Provide)(),
|
|
113
79
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
114
80
|
], HttpService);
|
|
115
|
-
//# sourceMappingURL=
|
|
81
|
+
//# sourceMappingURL=http-service.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Axios from 'axios';
|
|
1
|
+
declare const Axios: any;
|
|
3
2
|
export { AxiosConfiguration as Configuration } from './configuration';
|
|
3
|
+
export * from './http-service.factory';
|
|
4
|
+
export * from './http-service';
|
|
4
5
|
export * from './interface';
|
|
5
|
-
export * from './serviceManager';
|
|
6
|
-
export {
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use `Axios` directly
|
|
9
|
-
*/
|
|
10
|
-
axios, };
|
|
11
6
|
export { Axios };
|
|
12
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,13 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Axios = exports.
|
|
17
|
+
exports.Axios = exports.Configuration = void 0;
|
|
18
18
|
const axios = require("axios");
|
|
19
|
-
|
|
20
|
-
const Axios = require("axios");
|
|
19
|
+
const Axios = axios['default'];
|
|
21
20
|
exports.Axios = Axios;
|
|
22
21
|
var configuration_1 = require("./configuration");
|
|
23
22
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.AxiosConfiguration; } });
|
|
23
|
+
__exportStar(require("./http-service.factory"), exports);
|
|
24
|
+
__exportStar(require("./http-service"), exports);
|
|
24
25
|
__exportStar(require("./interface"), exports);
|
|
25
|
-
__exportStar(require("./serviceManager"), exports);
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { AxiosRequestConfig as OriginAxiosRequestConfig, AxiosRequestHeaders, AxiosResponse as OriginAxiosResponse } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for custom axios request config merging.
|
|
4
|
+
*/
|
|
5
|
+
export interface AxiosRequestConfig<D = any> extends OriginAxiosRequestConfig<D> {
|
|
6
|
+
}
|
|
7
|
+
export interface AxiosResponse<T = any, D = any> extends OriginAxiosResponse<T, D> {
|
|
8
|
+
config: AxiosRequestConfig<D> & {
|
|
9
|
+
headers: AxiosRequestHeaders;
|
|
7
10
|
};
|
|
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
11
|
}
|
|
21
12
|
//# 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": "4.0.0-
|
|
4
|
+
"version": "4.0.0-beta.1",
|
|
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": "^4.0.0-
|
|
14
|
-
"@midwayjs/mock": "^4.0.0-
|
|
13
|
+
"@midwayjs/core": "^4.0.0-beta.1",
|
|
14
|
+
"@midwayjs/mock": "^4.0.0-beta.1",
|
|
15
15
|
"nock": "13.5.6"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"axios": "1.
|
|
18
|
+
"axios": "1.8.4"
|
|
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": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
41
41
|
}
|