-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: typo, specify the function return type. (#87)
* fix: typo * fix: vercel build * chore: stylelint
- Loading branch information
Showing
6 changed files
with
43 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
import { inject, singleton } from '@difizen/mana-app'; | ||
import type { AxiosRequestConfig } from 'axios'; | ||
import type { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import qs from 'query-string'; | ||
|
||
import { AxiosClient } from './protocol.js'; | ||
|
||
export type FecterResponse<T = any, D = any> = AxiosResponse<T, D>; | ||
|
||
@singleton() | ||
export class Fetcher { | ||
@inject(AxiosClient) axios: AxiosClient; | ||
get = <T>( | ||
basePath: string, | ||
params?: Record<string, any>, | ||
config?: AxiosRequestConfig<any>, | ||
) => { | ||
): Promise<FecterResponse<T, any>> => { | ||
let url = basePath; | ||
if (params) { | ||
url = `${url}?${qs.stringify(params)}`; | ||
} | ||
return this.axios.get<T>(url, config); | ||
}; | ||
|
||
post = async <T>(url: string, data: any, config?: AxiosRequestConfig<any>) => { | ||
post = async <T>( | ||
url: string, | ||
data: any, | ||
config?: AxiosRequestConfig<any>, | ||
): Promise<FecterResponse<T, any>> => { | ||
return this.axios.post<T>(url, data, config); | ||
}; | ||
|
||
put = async <T>(url: string, data: any, config?: AxiosRequestConfig<any>) => { | ||
put = async <T>( | ||
url: string, | ||
data: any, | ||
config?: AxiosRequestConfig<any>, | ||
): Promise<FecterResponse<T, any>> => { | ||
return this.axios.put<T>(url, data, config); | ||
}; | ||
delete = async <T>(url: string, config?: AxiosRequestConfig<any>) => { | ||
delete = async <T>( | ||
url: string, | ||
config?: AxiosRequestConfig<any>, | ||
): Promise<FecterResponse<T, any>> => { | ||
return this.axios.delete<T>(url, config); | ||
}; | ||
} |