diff --git a/frontend/client/core/index.ts b/frontend/client/core/index.ts index afe16e6a..76dca954 100644 --- a/frontend/client/core/index.ts +++ b/frontend/client/core/index.ts @@ -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); @@ -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, @@ -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); } @@ -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; diff --git a/frontend/client/core/types.ts b/frontend/client/core/types.ts index 98db41f5..18a974f1 100644 --- a/frontend/client/core/types.ts +++ b/frontend/client/core/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { AxiosError, AxiosInstance, @@ -5,14 +6,14 @@ import type { AxiosResponse, AxiosStatic, CreateAxiosDefaults, -} from 'axios'; +} from "axios"; -import type { BodySerializer } from './utils'; +import type { BodySerializer } from "./utils"; type OmitKeys = Pick>; export interface Config - extends Omit { + extends Omit { /** * Axios implementation. You can use this option to provide a custom * Axios instance. @@ -37,7 +38,7 @@ export interface Config * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} */ headers?: - | CreateAxiosDefaults['headers'] + | CreateAxiosDefaults["headers"] | Record< string, | string @@ -54,15 +55,15 @@ export interface Config * {@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, @@ -99,7 +100,7 @@ type MethodFn = < TError = unknown, ThrowOnError extends boolean = false, >( - options: Omit, 'method'>, + options: Omit, "method">, ) => RequestResult; type RequestFn = < @@ -107,8 +108,8 @@ type RequestFn = < TError = unknown, ThrowOnError extends boolean = false, >( - options: Omit, 'method'> & - Pick>, 'method'>, + options: Omit, "method"> & + Pick>, "method">, ) => RequestResult; export interface Client { @@ -127,12 +128,12 @@ export interface Client { export type RequestOptions = RequestOptionsBase & Config & { - headers: AxiosRequestConfig['headers']; + headers: AxiosRequestConfig["headers"]; }; type OptionsBase = Omit< RequestOptionsBase, - 'url' + "url" > & { /** * You can provide a client instance returned by `createClient()` instead of @@ -147,12 +148,12 @@ export type Options< ThrowOnError extends boolean = boolean, > = T extends { body?: any } ? T extends { headers?: any } - ? OmitKeys, 'body' | 'headers'> & T - : OmitKeys, 'body'> & + ? OmitKeys, "body" | "headers"> & T + : OmitKeys, "body"> & T & - Pick, 'headers'> + Pick, "headers"> : T extends { headers?: any } - ? OmitKeys, 'headers'> & + ? OmitKeys, "headers"> & T & - Pick, 'body'> + Pick, "body"> : OptionsBase & T; diff --git a/frontend/client/core/utils.ts b/frontend/client/core/utils.ts index 2d3e8a8e..309135e0 100644 --- a/frontend/client/core/utils.ts +++ b/frontend/client/core/utils.ts @@ -1,4 +1,6 @@ -import type { Config } from './types'; +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { Config } from "./types"; interface PathSerializer { path: Record; @@ -7,10 +9,10 @@ interface PathSerializer { const PATH_PARAM_RE = /\{[^{}]+\}/g; -type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; -type MatrixStyle = 'label' | 'matrix' | 'simple'; +type ArrayStyle = "form" | "spaceDelimited" | "pipeDelimited"; +type MatrixStyle = "label" | "matrix" | "simple"; type ArraySeparatorStyle = ArrayStyle | MatrixStyle; -type ObjectStyle = 'form' | 'deepObject'; +type ObjectStyle = "form" | "deepObject"; type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; export type BodySerializer = (body: any) => any; @@ -40,12 +42,12 @@ const serializePrimitiveParam = ({ value, }: SerializePrimitiveParam) => { if (value === undefined || value === null) { - return ''; + return ""; } - if (typeof value === 'object') { + if (typeof value === "object") { throw new Error( - 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.", ); } @@ -54,40 +56,40 @@ const serializePrimitiveParam = ({ const separatorArrayExplode = (style: ArraySeparatorStyle) => { switch (style) { - case 'label': - return '.'; - case 'matrix': - return ';'; - case 'simple': - return ','; + case "label": + return "."; + case "matrix": + return ";"; + case "simple": + return ","; default: - return '&'; + return "&"; } }; const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { switch (style) { - case 'form': - return ','; - case 'pipeDelimited': - return '|'; - case 'spaceDelimited': - return '%20'; + case "form": + return ","; + case "pipeDelimited": + return "|"; + case "spaceDelimited": + return "%20"; default: - return ','; + return ","; } }; const separatorObjectExplode = (style: ObjectSeparatorStyle) => { switch (style) { - case 'label': - return '.'; - case 'matrix': - return ';'; - case 'simple': - return ','; + case "label": + return "."; + case "matrix": + return ";"; + case "simple": + return ","; default: - return '&'; + return "&"; } }; @@ -105,11 +107,11 @@ const serializeArrayParam = ({ allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) ).join(separatorArrayNoExplode(style)); switch (style) { - case 'label': + case "label": return `.${joinedValues}`; - case 'matrix': + case "matrix": return `;${name}=${joinedValues}`; - case 'simple': + case "simple": return joinedValues; default: return `${name}=${joinedValues}`; @@ -119,7 +121,7 @@ const serializeArrayParam = ({ const separator = separatorArrayExplode(style); const joinedValues = value .map((v) => { - if (style === 'label' || style === 'simple') { + if (style === "label" || style === "simple") { return allowReserved ? v : encodeURIComponent(v as string); } @@ -130,7 +132,7 @@ const serializeArrayParam = ({ }); }) .join(separator); - return style === 'label' || style === 'matrix' + return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues; }; @@ -144,7 +146,7 @@ const serializeObjectParam = ({ }: SerializeOptions & { value: Record; }) => { - if (style !== 'deepObject' && !explode) { + if (style !== "deepObject" && !explode) { let values: string[] = []; Object.entries(value).forEach(([key, v]) => { values = [ @@ -153,13 +155,13 @@ const serializeObjectParam = ({ allowReserved ? (v as string) : encodeURIComponent(v as string), ]; }); - const joinedValues = values.join(','); + const joinedValues = values.join(","); switch (style) { - case 'form': + case "form": return `${name}=${joinedValues}`; - case 'label': + case "label": return `.${joinedValues}`; - case 'matrix': + case "matrix": return `;${name}=${joinedValues}`; default: return joinedValues; @@ -171,12 +173,12 @@ const serializeObjectParam = ({ .map(([key, v]) => serializePrimitiveParam({ allowReserved, - name: style === 'deepObject' ? `${name}[${key}]` : key, + name: style === "deepObject" ? `${name}[${key}]` : key, value: v as string, }), ) .join(separator); - return style === 'label' || style === 'matrix' + return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues; }; @@ -188,19 +190,19 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { for (const match of matches) { let explode = false; let name = match.substring(1, match.length - 1); - let style: ArraySeparatorStyle = 'simple'; + let style: ArraySeparatorStyle = "simple"; - if (name.endsWith('*')) { + if (name.endsWith("*")) { explode = true; name = name.substring(0, name.length - 1); } - if (name.startsWith('.')) { + if (name.startsWith(".")) { name = name.substring(1); - style = 'label'; - } else if (name.startsWith(';')) { + style = "label"; + } else if (name.startsWith(";")) { name = name.substring(1); - style = 'matrix'; + style = "matrix"; } const value = path[name]; @@ -217,7 +219,7 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { continue; } - if (typeof value === 'object') { + if (typeof value === "object") { url = url.replace( match, serializeObjectParam({ @@ -230,7 +232,7 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { continue; } - if (style === 'matrix') { + if (style === "matrix") { url = url.replace( match, `;${serializePrimitiveParam({ @@ -242,7 +244,7 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { } const replaceValue = encodeURIComponent( - style === 'label' ? `.${value as string}` : (value as string), + style === "label" ? `.${value as string}` : (value as string), ); url = url.replace(match, replaceValue); } @@ -263,7 +265,7 @@ const serializeFormDataPair = ( key: string, value: unknown, ) => { - if (typeof value === 'string' || value instanceof Blob) { + if (typeof value === "string" || value instanceof Blob) { formData.append(key, value); } else { formData.append(key, JSON.stringify(value)); @@ -277,11 +279,11 @@ export const mergeConfigs = (a: Config, b: Config): Config => { }; export const mergeHeaders = ( - ...headers: Array['headers'] | undefined> -): Required['headers'] => { - const mergedHeaders: Required['headers'] = {}; + ...headers: Array["headers"] | undefined> +): Required["headers"] => { + const mergedHeaders: Required["headers"] = {}; for (const header of headers) { - if (!header || typeof header !== 'object') { + if (!header || typeof header !== "object") { continue; } @@ -301,7 +303,7 @@ export const mergeHeaders = ( // content value in OpenAPI specification is 'application/json' // @ts-expect-error mergedHeaders[key] = - typeof value === 'object' ? JSON.stringify(value) : (value as string); + typeof value === "object" ? JSON.stringify(value) : (value as string); } } } @@ -338,7 +340,7 @@ const serializeUrlSearchParamsPair = ( key: string, value: unknown, ) => { - if (typeof value === 'string') { + if (typeof value === "string") { data.append(key, value); } else { data.append(key, JSON.stringify(value)); @@ -367,6 +369,6 @@ export const urlSearchParamsBodySerializer = { }; export const createConfig = (override: Config = {}): Config => ({ - baseURL: '', + baseURL: "", ...override, }); diff --git a/frontend/client/index.ts b/frontend/client/index.ts index 0a2b84ba..1cb041de 100644 --- a/frontend/client/index.ts +++ b/frontend/client/index.ts @@ -1,4 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts -export * from './schemas.gen'; -export * from './services.gen'; -export * from './types.gen'; \ No newline at end of file +export * from "./schemas.gen"; +export * from "./services.gen"; +export * from "./types.gen";