Skip to content

Commit

Permalink
Merge pull request #96 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update type
  • Loading branch information
GuoXiCheng authored Feb 3, 2024
2 parents c358cfd + d11639c commit ed128a8
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

6 changes: 0 additions & 6 deletions src/request-lib/axios/axios-options.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/request-lib/axios/axios-request.ts
Original file line number Diff line number Diff line change
@@ -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<T>(method: RequestMethods, url: string, body?: string, params?: any): Promise<T> {
const response = await this.axios.request<T>({
const response = await this.axios.request({
url,
method,
headers: {
Expand Down
8 changes: 4 additions & 4 deletions src/request-lib/base/request-options.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
9 changes: 4 additions & 5 deletions src/request-lib/create-request.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'
Expand All @@ -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';
}
7 changes: 0 additions & 7 deletions src/request-lib/interfaces.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/request-lib/wx/wx-options.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/request-lib/wx/wx-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(method: RequestMethods, url: string, body?: string, params?: any): Promise<T> {
return new Promise((resolve, reject) => {
const options: WechatMiniprogram.RequestOption = {
const options = {
url,
method,
...(body && { data: { body } }),
Expand Down

0 comments on commit ed128a8

Please sign in to comment.