@midwayjs/axios 3.0.2 → 3.0.4-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/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@midwayjs/axios",
3
3
  "description": "midway http client with axios",
4
- "version": "3.0.2",
4
+ "version": "3.0.4-beta.1",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist/**/*.js",
9
- "dist/**/*.d.ts",
10
- "dist/**/*.js.map"
9
+ "dist/**/*.d.ts"
11
10
  ],
12
11
  "devDependencies": {
13
- "@midwayjs/core": "^3.0.2",
14
- "@midwayjs/decorator": "^3.0.2",
15
- "@midwayjs/mock": "^3.0.2"
12
+ "@midwayjs/core": "^3.0.4-beta.1",
13
+ "@midwayjs/decorator": "^3.0.4-beta.1",
14
+ "@midwayjs/mock": "^3.0.4-beta.1"
16
15
  },
17
16
  "dependencies": {
18
17
  "axios": "^0.25.0"
@@ -37,5 +36,5 @@
37
36
  "type": "git",
38
37
  "url": "https://github.com/midwayjs/midway.git"
39
38
  },
40
- "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
39
+ "gitHead": "52bc37e7a570806c121b33a0e8ac1cd084445f5d"
41
40
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAoD;AACpD,qDAA+C;AAY/C,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAC7B,KAAK,CAAC,OAAO,CAAC,SAAS;QACrB,MAAM,SAAS,CAAC,QAAQ,CAAC,4BAAW,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,kBAAkB;IAV9B,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE;oBACP,KAAK,EAAE,EAAE;iBACV;aACF;SACF;KACF,CAAC;GACW,kBAAkB,CAI9B;AAJY,gDAAkB","sourcesContent":["import { Configuration } from '@midwayjs/decorator';\nimport { HttpService } from './serviceManager';\n\n@Configuration({\n namespace: 'axios',\n importConfigs: [\n {\n default: {\n axios: {},\n },\n },\n ],\n})\nexport class AxiosConfiguration {\n async onReady(container) {\n await container.getAsync(HttpService);\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAAsE;AAA7D,8GAAA,kBAAkB,OAAiB;AAC5C,8CAA4B;AAC5B,mDAAiC","sourcesContent":["export { AxiosConfiguration as Configuration } from './configuration';\nexport * from './interface';\nexport * from './serviceManager';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AAMa,QAAA,kBAAkB,GAAG,gBAAgB,CAAC","sourcesContent":["import {\n AxiosRequestConfig,\n AxiosResponse,\n AxiosInterceptorManager,\n} from 'axios';\n\nexport const AXIOS_INSTANCE_KEY = 'axios:instance';\n\nexport interface AxiosHttpService {\n interceptors: {\n request: AxiosInterceptorManager<AxiosRequestConfig>;\n response: AxiosInterceptorManager<AxiosResponse>;\n };\n getUri(config?: AxiosRequestConfig): string;\n request<T = any, R = AxiosResponse<T>>(\n config: AxiosRequestConfig\n ): Promise<R>;\n get<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R>;\n delete<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R>;\n head<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R>;\n options<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R>;\n post<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R>;\n put<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R>;\n patch<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R>;\n}\n\ndeclare module '@midwayjs/core/dist/interface' {\n interface MidwayConfig {\n axios?: AxiosRequestConfig;\n }\n}\n\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"serviceManager.js","sourceRoot":"","sources":["../src/serviceManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAgF;AAChF,mDAAyE;AAEzE,2CAAmE;AAGnE,IAAa,WAAW,GAAxB,MAAa,WAAW;IAYtB,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAGS,KAAK,CAAC,IAAI;;QAClB,IACE,CAAC,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,8BAAkB,CAAC,EACxE;YACA,iBAAiB;YACjB,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAC,MAAA,IAAI,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC;YAErD,4BAA4B;YAC5B,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAC/B,MAAM,CAAC,EAAE;gBACP,sCAAsC;gBACtC,OAAO,MAAM,CAAC;YAChB,CAAC,EACD,KAAK,CAAC,EAAE;gBACN,kCAAkC;gBAClC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC,CACF,CAAC;YAEF,6BAA6B;YAC7B,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,QAAQ,CAAC,EAAE;gBACT,kFAAkF;gBAClF,kCAAkC;gBAClC,OAAO,QAAQ,CAAC;YAClB,CAAC,EACD,KAAK,CAAC,EAAE;gBACN,sFAAsF;gBACtF,mCAAmC;gBACnC,OAA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AE3B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CACH,GAAW,EACX,IAAU,EACV,MAA2B;QAE3B,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF,CAAA;AArHC;IADC,IAAA,kBAAM,GAAE;;wCACU;AAGnB;IADC,IAAA,eAAG,GAAE;;wCAC4B;AAGlC;IADC,IAAA,kBAAM,EAAC,OAAO,CAAC;;+CACyB;AAOzC;IADC,IAAA,gBAAI,GAAE;;;;uCA0CN;AA1DU,WAAW;IADvB,IAAA,mBAAO,GAAE;GACG,WAAW,CAyHvB;AAzHY,kCAAW","sourcesContent":["import axios, { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios';\nimport { Provide, Inject, Init, Config, App } from '@midwayjs/decorator';\nimport { IMidwayApplication } from '@midwayjs/core';\nimport { AXIOS_INSTANCE_KEY, AxiosHttpService } from './interface';\n\n@Provide()\nexport class HttpService implements AxiosHttpService {\n private instance: AxiosInstance;\n\n @Inject()\n protected ctx: any;\n\n @App()\n protected app: IMidwayApplication;\n\n @Config('axios')\n protected httpConfig: AxiosRequestConfig;\n\n get interceptors() {\n return this.instance.interceptors;\n }\n\n @Init()\n protected async init() {\n if (\n !this.app.getApplicationContext().registry.hasObject(AXIOS_INSTANCE_KEY)\n ) {\n // 动态往全局容器中创建一个单例\n const instance = axios.create(this.httpConfig ?? {});\n\n // Add a request interceptor\n instance.interceptors.request.use(\n config => {\n // Do something before request is sent\n return config;\n },\n error => {\n // Do something with request error\n return Promise.reject(error);\n }\n );\n\n // Add a response interceptor\n instance.interceptors.response.use(\n response => {\n // Any status code that lie within the range of 2xx cause this function to trigger\n // Do something with response data\n return response;\n },\n error => {\n // Any status codes that falls outside the range of 2xx cause this function to trigger\n // Do something with response error\n return Promise.reject(error);\n }\n );\n\n this.app\n .getApplicationContext()\n .registry.registerObject(AXIOS_INSTANCE_KEY, instance);\n }\n\n this.instance = this.app\n .getApplicationContext()\n .registry.getObject(AXIOS_INSTANCE_KEY);\n }\n\n getUri(config?: AxiosRequestConfig): string {\n return this.instance.getUri(config);\n }\n\n request<T = any, R = AxiosResponse<T>>(\n config: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.request(config);\n }\n\n get<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.get(url, config);\n }\n\n delete<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.delete(url, config);\n }\n\n head<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.head(url, config);\n }\n\n options<T = any, R = AxiosResponse<T>>(\n url: string,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.options(url, config);\n }\n\n post<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.post(url, data, config);\n }\n\n put<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.put(url, data, config);\n }\n\n patch<T = any, R = AxiosResponse<T>>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig\n ): Promise<R> {\n return this.instance.patch(url, data, config);\n }\n}\n"]}