Skip to content

Commit

Permalink
style: fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chloeelim committed Sep 22, 2024
1 parent 4a0ae3d commit 73fca5d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 96 deletions.
27 changes: 14 additions & 13 deletions frontend/client/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { AxiosError } from 'axios';
import axios from 'axios';
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { AxiosError } from "axios";
import axios from "axios";

import type { Client, Config, RequestOptions } from './types';
import { createConfig, getUrl, mergeConfigs, mergeHeaders } from './utils';
import type { Client, Config, RequestOptions } from "./types";
import { createConfig, getUrl, mergeConfigs, mergeHeaders } from "./utils";

export const createClient = (config: Config): Client => {
let _config = mergeConfigs(createConfig(), config);
Expand All @@ -23,7 +24,7 @@ export const createClient = (config: Config): Client => {
};

// @ts-expect-error
const request: Client['request'] = async (options) => {
const request: Client["request"] = async (options) => {
const opts: RequestOptions = {
..._config,
...options,
Expand Down Expand Up @@ -51,7 +52,7 @@ export const createClient = (config: Config): Client => {

let { data } = response;

if (opts.responseType === 'json' && opts.responseTransformer) {
if (opts.responseType === "json" && opts.responseTransformer) {
data = await opts.responseTransformer(data);
}

Expand All @@ -71,15 +72,15 @@ export const createClient = (config: Config): Client => {
};

return {
delete: (options) => request({ ...options, method: 'delete' }),
get: (options) => request({ ...options, method: 'get' }),
delete: (options) => request({ ...options, method: "delete" }),
get: (options) => request({ ...options, method: "get" }),
getConfig,
head: (options) => request({ ...options, method: 'head' }),
head: (options) => request({ ...options, method: "head" }),
instance,
options: (options) => request({ ...options, method: 'options' }),
patch: (options) => request({ ...options, method: 'patch' }),
post: (options) => request({ ...options, method: 'post' }),
put: (options) => request({ ...options, method: 'put' }),
options: (options) => request({ ...options, method: "options" }),
patch: (options) => request({ ...options, method: "patch" }),
post: (options) => request({ ...options, method: "post" }),
put: (options) => request({ ...options, method: "put" }),
request,
setConfig,
} as Client;
Expand Down
47 changes: 24 additions & 23 deletions frontend/client/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type {
AxiosError,
AxiosInstance,
AxiosRequestConfig,
AxiosResponse,
AxiosStatic,
CreateAxiosDefaults,
} from 'axios';
} from "axios";

import type { BodySerializer } from './utils';
import type { BodySerializer } from "./utils";

type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;

export interface Config<ThrowOnError extends boolean = boolean>
extends Omit<CreateAxiosDefaults, 'headers'> {
extends Omit<CreateAxiosDefaults, "headers"> {
/**
* Axios implementation. You can use this option to provide a custom
* Axios instance.
Expand All @@ -37,7 +38,7 @@ export interface Config<ThrowOnError extends boolean = boolean>
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
*/
headers?:
| CreateAxiosDefaults['headers']
| CreateAxiosDefaults["headers"]
| Record<
string,
| string
Expand All @@ -54,15 +55,15 @@ export interface Config<ThrowOnError extends boolean = boolean>
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
*/
method?:
| 'connect'
| 'delete'
| 'get'
| 'head'
| 'options'
| 'patch'
| 'post'
| 'put'
| 'trace';
| "connect"
| "delete"
| "get"
| "head"
| "options"
| "patch"
| "post"
| "put"
| "trace";
/**
* A function for transforming response data before it's returned to the
* caller function. This is an ideal place to post-process server data,
Expand Down Expand Up @@ -99,16 +100,16 @@ type MethodFn = <
TError = unknown,
ThrowOnError extends boolean = false,
>(
options: Omit<RequestOptionsBase<ThrowOnError>, 'method'>,
options: Omit<RequestOptionsBase<ThrowOnError>, "method">,
) => RequestResult<Data, TError, ThrowOnError>;

type RequestFn = <
Data = unknown,
TError = unknown,
ThrowOnError extends boolean = false,
>(
options: Omit<RequestOptionsBase<ThrowOnError>, 'method'> &
Pick<Required<RequestOptionsBase<ThrowOnError>>, 'method'>,
options: Omit<RequestOptionsBase<ThrowOnError>, "method"> &
Pick<Required<RequestOptionsBase<ThrowOnError>>, "method">,
) => RequestResult<Data, TError, ThrowOnError>;

export interface Client {
Expand All @@ -127,12 +128,12 @@ export interface Client {

export type RequestOptions = RequestOptionsBase<false> &
Config<false> & {
headers: AxiosRequestConfig['headers'];
headers: AxiosRequestConfig["headers"];
};

type OptionsBase<ThrowOnError extends boolean> = Omit<
RequestOptionsBase<ThrowOnError>,
'url'
"url"
> & {
/**
* You can provide a client instance returned by `createClient()` instead of
Expand All @@ -147,12 +148,12 @@ export type Options<
ThrowOnError extends boolean = boolean,
> = T extends { body?: any }
? T extends { headers?: any }
? OmitKeys<OptionsBase<ThrowOnError>, 'body' | 'headers'> & T
: OmitKeys<OptionsBase<ThrowOnError>, 'body'> &
? OmitKeys<OptionsBase<ThrowOnError>, "body" | "headers"> & T
: OmitKeys<OptionsBase<ThrowOnError>, "body"> &
T &
Pick<OptionsBase<ThrowOnError>, 'headers'>
Pick<OptionsBase<ThrowOnError>, "headers">
: T extends { headers?: any }
? OmitKeys<OptionsBase<ThrowOnError>, 'headers'> &
? OmitKeys<OptionsBase<ThrowOnError>, "headers"> &
T &
Pick<OptionsBase<ThrowOnError>, 'body'>
Pick<OptionsBase<ThrowOnError>, "body">
: OptionsBase<ThrowOnError> & T;
Loading

0 comments on commit 73fca5d

Please sign in to comment.