diff --git a/package.json b/package.json index 1be8986..01692bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tiny-crud", - "version": "1.1.2", + "version": "1.1.3", "description": "Lightweight Data Repository Based on Git Issue API", "main": "dist/bundle.cjs.js", "module": "dist/bundle.esm.js", diff --git a/src/index.ts b/src/index.ts index b500ee5..a4b62d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,5 @@ export { GithubUser } from './repository-lib/github/github-user'; export { GiteeUser } from './repository-lib/gitee/gitee-user'; -export { AxiosRequest } from './request-lib/axios/axios-request'; - -export { WxRequest } from './request-lib/wx/wx-request'; +export { BaseRequest } from './request-lib/base/base-request'; diff --git a/src/request-lib/axios/axios-options.ts b/src/request-lib/axios/axios-options.ts deleted file mode 100644 index 359ccc7..0000000 --- a/src/request-lib/axios/axios-options.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { AxiosInstance } from "axios"; - -export type AxiosOptions = { - httpLib: 'axios'; - httpClient: AxiosInstance; -} \ No newline at end of file diff --git a/src/request-lib/axios/axios-request.ts b/src/request-lib/axios/axios-request.ts index 49ec6d1..f11143e 100644 --- a/src/request-lib/axios/axios-request.ts +++ b/src/request-lib/axios/axios-request.ts @@ -1,19 +1,18 @@ -import { AxiosInstance } from 'axios'; import { BaseRequest } from '../base/base-request'; import { RequestOptions } from '../base/request-options'; import { RequestMethods } from '../base/request-methods'; export class AxiosRequest extends BaseRequest { - private axios: AxiosInstance; + private axios: any; constructor( public options: RequestOptions ) { super(options); - this.axios = options.httpClient as AxiosInstance; + this.axios = options.httpClient; } protected async sendRequest(method: RequestMethods, url: string, body?: string, params?: any): Promise { - const response = await this.axios.request({ + const response = await this.axios.request({ url, method, headers: { diff --git a/src/request-lib/base/request-options.ts b/src/request-lib/base/request-options.ts index 3e1594a..24d44a5 100644 --- a/src/request-lib/base/request-options.ts +++ b/src/request-lib/base/request-options.ts @@ -1,16 +1,16 @@ import { GiteeOptions } from "../../repository-lib/gitee/gitee-options"; import { GithubOptions } from "../../repository-lib/github/github-options"; import { GitlabOptions } from "../../repository-lib/gitlab/gitlab-options"; -import { AxiosOptions } from "../axios/axios-options"; -import { WxOptions } from "../wx/wx-options"; export type RequestOptions = { + httpLib: "axios" | "wx"; + httpClient: any; + accessToken: string; + baseURL?: string; issueNumber?: string; - accessToken: string; } & (GiteeOptions | GithubOptions | GitlabOptions) - & (AxiosOptions | WxOptions) & (RequestWithEncrypt | RequestWithoutEncrypt); type RequestWithEncrypt = { diff --git a/src/request-lib/create-request.ts b/src/request-lib/create-request.ts index bdf3d5e..d346f1c 100644 --- a/src/request-lib/create-request.ts +++ b/src/request-lib/create-request.ts @@ -1,12 +1,11 @@ -import { AxiosInstance } from "axios"; import { RequestType } from "../enums"; import { AxiosRequest } from "./axios/axios-request"; import { WxRequest } from "./wx/wx-request"; -import { WxInstance } from "./wx/wx-interface"; import { RequestOptions } from "./base/request-options"; +import { BaseRequest } from "./base/base-request"; -export function createRequest(options: RequestOptions) { +export function createRequest(options: RequestOptions): BaseRequest { const { httpLib, httpClient } = options; switch (httpLib) { case RequestType.axios: @@ -23,7 +22,7 @@ export function createRequest(options: RequestOptions) { } -function isAxiosInstance(instance: any): instance is AxiosInstance { +function isAxiosInstance(instance: any): Boolean { return instance && typeof instance.get === 'function' && typeof instance.post === 'function' @@ -32,6 +31,6 @@ function isAxiosInstance(instance: any): instance is AxiosInstance { && typeof instance.patch === 'function'; } -function isWxInstance(instance: any): instance is WxInstance { +function isWxInstance(instance: any): Boolean { return instance && typeof instance.request === 'function'; } diff --git a/src/request-lib/interfaces.ts b/src/request-lib/interfaces.ts deleted file mode 100644 index 2dacb49..0000000 --- a/src/request-lib/interfaces.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { AxiosInstance } from "axios"; -import { WxInstance } from "./wx/wx-interface"; - -export type RequestInstance = WxInstance | AxiosInstance; - - - diff --git a/src/request-lib/wx/wx-options.ts b/src/request-lib/wx/wx-options.ts deleted file mode 100644 index d06be1e..0000000 --- a/src/request-lib/wx/wx-options.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type WxOptions = { - httpLib: 'wx'; - httpClient: WechatMiniprogram.Wx -} \ No newline at end of file diff --git a/src/request-lib/wx/wx-request.ts b/src/request-lib/wx/wx-request.ts index c3eeea1..fd49529 100644 --- a/src/request-lib/wx/wx-request.ts +++ b/src/request-lib/wx/wx-request.ts @@ -3,17 +3,17 @@ import { RequestMethods } from '../base/request-methods'; import { RequestOptions } from '../base/request-options'; export class WxRequest extends BaseRequest { - private wx: WechatMiniprogram.Wx; + private wx: any; constructor( public options: RequestOptions ) { super(options); - this.wx = options.httpClient as WechatMiniprogram.Wx; + this.wx = options.httpClient; } protected async sendRequest(method: RequestMethods, url: string, body?: string, params?: any): Promise { return new Promise((resolve, reject) => { - const options: WechatMiniprogram.RequestOption = { + const options = { url, method, ...(body && { data: { body } }),