diff --git a/src/api/api.ts b/src/api/api.ts index b36992f..989093d 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,5 +1,6 @@ import axios, { type AxiosRequestConfig, isAxiosError } from "axios"; import { toast } from "sonner"; +import type { DefaultResponseDTOAuthenticationResponseDTO } from "@/api/generated/api.schemas.ts"; import type { User } from "@/contexts/AuthContext.tsx"; export const Api = axios.create({ @@ -12,6 +13,10 @@ interface ErrorResponseDTO { message: string; } +interface CustomAxiosRequestConfig extends AxiosRequestConfig { + _retry?: boolean; +} + Api.interceptors.request.use(async (config) => { const jsonString = localStorage.getItem("userData"); if (jsonString) { @@ -22,19 +27,117 @@ Api.interceptors.request.use(async (config) => { return config; }); +let isRefreshing = false; +let failedQueue: Array<{ + resolve: (token: string) => void; + reject: (error: unknown) => void; +}> = []; + +const processQueue = (error: unknown, token: string | null = null) => { + failedQueue.forEach((promise) => { + if (error) { + promise.reject(error); + } else if (token) { + promise.resolve(token); + } + }); + + failedQueue = []; +}; + Api.interceptors.response.use( (response) => response, - (error) => { + async (error) => { if (!isAxiosError(error)) { console.log(error); - return; + return Promise.reject(error); + } + + const originalRequest = error.config as CustomAxiosRequestConfig; + + if (error.response?.status === 401 && !originalRequest._retry) { + const userDataStr = localStorage.getItem("userData"); + if (!userDataStr) { + handleLogout(); + return Promise.reject(error); + } + + const userData: User = JSON.parse(userDataStr); + + // Prevent multiple simultaneous refreshes + if (isRefreshing) { + return new Promise((resolve, reject) => { + failedQueue.push({ + resolve: (token) => { + originalRequest.headers = { + ...originalRequest.headers, + Authorization: `Bearer ${token}`, + }; + resolve(Api(originalRequest)); + }, + reject, + }); + }); + } + + originalRequest._retry = true; + isRefreshing = true; + + try { + const response = + await axios.post( + `${import.meta.env.VITE_API_BASE_URL}/auth/refresh`, + { refreshToken: userData.refreshToken }, + ); + + const { accessToken, refreshToken } = response.data.data!; + + const newUserData = { + ...userData, + token: accessToken, + refreshToken: refreshToken, + }; + localStorage.setItem("userData", JSON.stringify(newUserData)); + + Api.defaults.headers.common.Authorization = `Bearer ${accessToken}`; + + processQueue(null, accessToken); + + originalRequest.headers = { + ...originalRequest.headers, + Authorization: `Bearer ${accessToken}`, + }; + + return Api(originalRequest); + } catch (refreshError) { + processQueue(refreshError, null); + handleLogout("Session expired. Please log in again."); + + return Promise.reject(refreshError); + } finally { + isRefreshing = false; + } } const errorDTO = error.response?.data as ErrorResponseDTO; - toast.error(errorDTO.message); + if (errorDTO?.message) { + toast.error(errorDTO.message); + } + + return Promise.reject(errorDTO); }, ); +const handleLogout = (message?: string) => { + localStorage.removeItem("userData"); + + if (message) { + toast.error(message); + } + + window.location.href = "/"; +}; + export const customInstance = ( config: AxiosRequestConfig, options?: AxiosRequestConfig, diff --git a/src/api/generated/api.schemas.ts b/src/api/generated/api.schemas.ts index 46551c3..1b18d87 100644 --- a/src/api/generated/api.schemas.ts +++ b/src/api/generated/api.schemas.ts @@ -5,245 +5,251 @@ * OpenAPI spec version: v0 */ export interface UpdateMangaDataCommand { - mangaId?: number; + mangaId?: number; } export interface DefaultResponseDTOVoid { - timestamp?: string; - data?: unknown; - message?: string; + timestamp?: string; + data?: unknown; + message?: string; } export interface ImportMangaDexRequestDTO { - id: string; + id: string; } export interface DefaultResponseDTOImportMangaDexResponseDTO { - timestamp?: string; - data?: ImportMangaDexResponseDTO; - message?: string; + timestamp?: string; + data?: ImportMangaDexResponseDTO; + message?: string; } export interface ImportMangaDexResponseDTO { - id: number; + id: number; } export interface RegistrationRequestDTO { - name?: string; - email?: string; - password?: string; + name?: string; + email?: string; + password?: string; } -export interface AuthenticationRequestDTO { - email: string; - password: string; +export interface RefreshTokenRequestDTO { + refreshToken: string; } -export type AuthenticationResponseDTORole = - (typeof AuthenticationResponseDTORole)[keyof typeof AuthenticationResponseDTORole]; +export type AuthenticationResponseDTORole = typeof AuthenticationResponseDTORole[keyof typeof AuthenticationResponseDTORole]; + // eslint-disable-next-line @typescript-eslint/no-redeclare export const AuthenticationResponseDTORole = { - USER: "USER", + USER: 'USER', } as const; export interface AuthenticationResponseDTO { - id: number; - token: string; - email: string; - name: string; - role: AuthenticationResponseDTORole; + id: number; + accessToken: string; + refreshToken: string; + email: string; + name: string; + role: AuthenticationResponseDTORole; } export interface DefaultResponseDTOAuthenticationResponseDTO { - timestamp?: string; - data?: AuthenticationResponseDTO; - message?: string; + timestamp?: string; + data?: AuthenticationResponseDTO; + message?: string; +} + +export interface AuthenticationRequestDTO { + email: string; + password: string; } export interface DefaultResponseDTOPageMangaListDTO { - timestamp?: string; - data?: PageMangaListDTO; - message?: string; + timestamp?: string; + data?: PageMangaListDTO; + message?: string; } export interface MangaListDTO { - id: number; - /** @minLength 1 */ - title: string; - coverImageKey?: string; - status?: string; - publishedFrom?: string; - publishedTo?: string; - providerCount?: number; - genres: string[]; - authors: string[]; - score: number; - favorite: boolean; + id: number; + /** @minLength 1 */ + title: string; + coverImageKey?: string; + status?: string; + publishedFrom?: string; + publishedTo?: string; + providerCount?: number; + genres: string[]; + authors: string[]; + score: number; + favorite: boolean; } export interface PageMangaListDTO { - totalPages?: number; - totalElements?: number; - size?: number; - content?: MangaListDTO[]; - number?: number; - pageable?: PageableObject; - first?: boolean; - last?: boolean; - sort?: SortObject; - numberOfElements?: number; - empty?: boolean; + totalPages?: number; + totalElements?: number; + size?: number; + content?: MangaListDTO[]; + number?: number; + pageable?: PageableObject; + first?: boolean; + last?: boolean; + sort?: SortObject; + numberOfElements?: number; + empty?: boolean; } export interface PageableObject { - offset?: number; - pageNumber?: number; - pageSize?: number; - paged?: boolean; - sort?: SortObject; - unpaged?: boolean; + offset?: number; + pageNumber?: number; + pageSize?: number; + paged?: boolean; + sort?: SortObject; + unpaged?: boolean; } export interface SortObject { - empty?: boolean; - sorted?: boolean; - unsorted?: boolean; + empty?: boolean; + sorted?: boolean; + unsorted?: boolean; } export interface DefaultResponseDTOListMangaChapterDTO { - timestamp?: string; - data?: MangaChapterDTO[]; - message?: string; + timestamp?: string; + data?: MangaChapterDTO[]; + message?: string; } export interface MangaChapterDTO { - id: number; - /** @minLength 1 */ - title: string; - downloaded: boolean; - isRead: boolean; + id: number; + /** @minLength 1 */ + title: string; + downloaded: boolean; + isRead: boolean; } export interface DefaultResponseDTOMangaDTO { - timestamp?: string; - data?: MangaDTO; - message?: string; + timestamp?: string; + data?: MangaDTO; + message?: string; } export interface MangaDTO { - id: number; - /** @minLength 1 */ - title: string; - coverImageKey?: string; - status?: string; - publishedFrom?: string; - publishedTo?: string; - synopsis?: string; - providerCount?: number; - alternativeTitles: string[]; - genres: string[]; - authors: string[]; - score: number; - providers: MangaProviderDTO[]; - chapterCount: number; + id: number; + /** @minLength 1 */ + title: string; + coverImageKey?: string; + status?: string; + publishedFrom?: string; + publishedTo?: string; + synopsis?: string; + providerCount?: number; + alternativeTitles: string[]; + genres: string[]; + authors: string[]; + score: number; + providers: MangaProviderDTO[]; + chapterCount: number; } export interface MangaProviderDTO { - id: number; - /** @minLength 1 */ - providerName: string; - chaptersAvailable: number; - chaptersDownloaded: number; - supportsChapterFetch: boolean; + id: number; + /** @minLength 1 */ + providerName: string; + chaptersAvailable: number; + chaptersDownloaded: number; + supportsChapterFetch: boolean; } export interface DefaultResponseDTOMangaChapterImagesDTO { - timestamp?: string; - data?: MangaChapterImagesDTO; - message?: string; + timestamp?: string; + data?: MangaChapterImagesDTO; + message?: string; } export interface MangaChapterImagesDTO { - id: number; - /** @minLength 1 */ - mangaTitle: string; - chapterImageKeys: string[]; + id: number; + /** @minLength 1 */ + mangaTitle: string; + chapterImageKeys: string[]; } export interface DefaultResponseDTOListImportReviewDTO { - timestamp?: string; - data?: ImportReviewDTO[]; - message?: string; + timestamp?: string; + data?: ImportReviewDTO[]; + message?: string; } export interface ImportReviewDTO { - id: number; - /** @minLength 1 */ - title: string; - /** @minLength 1 */ - providerName: string; - externalUrl?: string; - /** @minLength 1 */ - reason: string; - createdAt: string; + id: number; + /** @minLength 1 */ + title: string; + /** @minLength 1 */ + providerName: string; + externalUrl?: string; + /** @minLength 1 */ + reason: string; + createdAt: string; } export interface DefaultResponseDTOListGenreDTO { - timestamp?: string; - data?: GenreDTO[]; - message?: string; + timestamp?: string; + data?: GenreDTO[]; + message?: string; } export interface GenreDTO { - id: number; - /** @minLength 1 */ - name: string; + id: number; + /** @minLength 1 */ + name: string; } export type DownloadChapterArchiveParams = { - archiveFileType: DownloadChapterArchiveArchiveFileType; +archiveFileType: DownloadChapterArchiveArchiveFileType; }; -export type DownloadChapterArchiveArchiveFileType = - (typeof DownloadChapterArchiveArchiveFileType)[keyof typeof DownloadChapterArchiveArchiveFileType]; +export type DownloadChapterArchiveArchiveFileType = typeof DownloadChapterArchiveArchiveFileType[keyof typeof DownloadChapterArchiveArchiveFileType]; + // eslint-disable-next-line @typescript-eslint/no-redeclare export const DownloadChapterArchiveArchiveFileType = { - CBZ: "CBZ", - CBR: "CBR", + CBZ: 'CBZ', + CBR: 'CBR', } as const; export type ImportMultipleFilesBody = { - /** @minLength 1 */ - malId: string; - /** List of files to upload */ - files: Blob[]; + /** @minLength 1 */ + malId: string; + /** List of files to upload */ + files: Blob[]; }; export type ResolveImportReviewParams = { - importReviewId: number; - malId: string; +importReviewId: number; +malId: string; }; export type GetMangasParams = { - searchQuery?: string; - genreIds?: number[]; - statuses?: string[]; - userFavorites?: boolean; - score?: number; - /** - * Zero-based page index (0..N) - * @minimum 0 - */ - page?: number; - /** - * The size of the page to be returned - * @minimum 1 - */ - size?: number; - /** - * Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported. - */ - sort?: string[]; +searchQuery?: string; +genreIds?: number[]; +statuses?: string[]; +userFavorites?: boolean; +score?: number; +/** + * Zero-based page index (0..N) + * @minimum 0 + */ +page?: number; +/** + * The size of the page to be returned + * @minimum 1 + */ +size?: number; +/** + * Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported. + */ +sort?: string[]; }; + diff --git a/src/api/generated/auth/auth.ts b/src/api/generated/auth/auth.ts index 634e812..32f2dc0 100644 --- a/src/api/generated/auth/auth.ts +++ b/src/api/generated/auth/auth.ts @@ -4,199 +4,224 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation +} from '@tanstack/react-query'; +import type { + MutationFunction, + QueryClient, + UseMutationOptions, + UseMutationResult +} from '@tanstack/react-query'; import type { - MutationFunction, - QueryClient, - UseMutationOptions, - UseMutationResult, -} from "@tanstack/react-query"; -import { useMutation } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { - AuthenticationRequestDTO, - DefaultResponseDTOAuthenticationResponseDTO, - DefaultResponseDTOVoid, - RegistrationRequestDTO, -} from "../api.schemas"; + AuthenticationRequestDTO, + DefaultResponseDTOAuthenticationResponseDTO, + DefaultResponseDTOVoid, + RefreshTokenRequestDTO, + RegistrationRequestDTO +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Register a new user. * @summary Register user */ export const registerUser = ( - registrationRequestDTO: RegistrationRequestDTO, - options?: SecondParameter, - signal?: AbortSignal, + registrationRequestDTO: RegistrationRequestDTO, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/auth/register`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: registrationRequestDTO, - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/auth/register`, method: 'POST', + headers: {'Content-Type': 'application/json', }, + data: registrationRequestDTO, signal + }, + options); + } + -export const getRegisterUserMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: RegistrationRequestDTO }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: RegistrationRequestDTO }, - TContext -> => { - const mutationKey = ["registerUser"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { data: RegistrationRequestDTO } - > = (props) => { - const { data } = props ?? {}; +export const getRegisterUserMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: RegistrationRequestDTO}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: RegistrationRequestDTO}, TContext> => { - return registerUser(data, requestOptions); - }; +const mutationKey = ['registerUser']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type RegisterUserMutationResult = NonNullable< - Awaited> ->; -export type RegisterUserMutationBody = RegistrationRequestDTO; -export type RegisterUserMutationError = unknown; -/** + const mutationFn: MutationFunction>, {data: RegistrationRequestDTO}> = (props) => { + const {data} = props ?? {}; + + return registerUser(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type RegisterUserMutationResult = NonNullable>> + export type RegisterUserMutationBody = RegistrationRequestDTO + export type RegisterUserMutationError = unknown + + /** * @summary Register user */ -export const useRegisterUser = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: RegistrationRequestDTO }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { data: RegistrationRequestDTO }, - TContext -> => { - const mutationOptions = getRegisterUserMutationOptions(options); +export const useRegisterUser = (options?: { mutation?:UseMutationOptions>, TError,{data: RegistrationRequestDTO}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: RegistrationRequestDTO}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getRegisterUserMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** + * Refresh the authentication token + * @summary Refresh authentication token + */ +export const refreshAuthToken = ( + refreshTokenRequestDTO: RefreshTokenRequestDTO, + options?: SecondParameter,signal?: AbortSignal +) => { + + + return customInstance( + {url: `/auth/refresh`, method: 'POST', + headers: {'Content-Type': 'application/json', }, + data: refreshTokenRequestDTO, signal + }, + options); + } + + + +export const getRefreshAuthTokenMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: RefreshTokenRequestDTO}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: RefreshTokenRequestDTO}, TContext> => { + +const mutationKey = ['refreshAuthToken']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; + + + + + const mutationFn: MutationFunction>, {data: RefreshTokenRequestDTO}> = (props) => { + const {data} = props ?? {}; + + return refreshAuthToken(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type RefreshAuthTokenMutationResult = NonNullable>> + export type RefreshAuthTokenMutationBody = RefreshTokenRequestDTO + export type RefreshAuthTokenMutationError = unknown + + /** + * @summary Refresh authentication token + */ +export const useRefreshAuthToken = (options?: { mutation?:UseMutationOptions>, TError,{data: RefreshTokenRequestDTO}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: RefreshTokenRequestDTO}, + TContext + > => { + + const mutationOptions = getRefreshAuthTokenMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Authenticate user with email and password. * @summary Authenticate user */ export const authenticateUser = ( - authenticationRequestDTO: AuthenticationRequestDTO, - options?: SecondParameter, - signal?: AbortSignal, + authenticationRequestDTO: AuthenticationRequestDTO, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/auth/login`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: authenticationRequestDTO, - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/auth/login`, method: 'POST', + headers: {'Content-Type': 'application/json', }, + data: authenticationRequestDTO, signal + }, + options); + } + -export const getAuthenticateUserMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: AuthenticationRequestDTO }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: AuthenticationRequestDTO }, - TContext -> => { - const mutationKey = ["authenticateUser"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { data: AuthenticationRequestDTO } - > = (props) => { - const { data } = props ?? {}; +export const getAuthenticateUserMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: AuthenticationRequestDTO}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: AuthenticationRequestDTO}, TContext> => { - return authenticateUser(data, requestOptions); - }; +const mutationKey = ['authenticateUser']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type AuthenticateUserMutationResult = NonNullable< - Awaited> ->; -export type AuthenticateUserMutationBody = AuthenticationRequestDTO; -export type AuthenticateUserMutationError = unknown; -/** + const mutationFn: MutationFunction>, {data: AuthenticationRequestDTO}> = (props) => { + const {data} = props ?? {}; + + return authenticateUser(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type AuthenticateUserMutationResult = NonNullable>> + export type AuthenticateUserMutationBody = AuthenticationRequestDTO + export type AuthenticateUserMutationError = unknown + + /** * @summary Authenticate user */ -export const useAuthenticateUser = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: AuthenticationRequestDTO }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { data: AuthenticationRequestDTO }, - TContext -> => { - const mutationOptions = getAuthenticateUserMutationOptions(options); +export const useAuthenticateUser = (options?: { mutation?:UseMutationOptions>, TError,{data: AuthenticationRequestDTO}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: AuthenticationRequestDTO}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; + const mutationOptions = getAuthenticateUserMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + \ No newline at end of file diff --git a/src/api/generated/dev-controller/dev-controller.ts b/src/api/generated/dev-controller/dev-controller.ts index 7ed4de0..54d2356 100644 --- a/src/api/generated/dev-controller/dev-controller.ts +++ b/src/api/generated/dev-controller/dev-controller.ts @@ -4,98 +4,83 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation +} from '@tanstack/react-query'; +import type { + MutationFunction, + QueryClient, + UseMutationOptions, + UseMutationResult +} from '@tanstack/react-query'; import type { - MutationFunction, - QueryClient, - UseMutationOptions, - UseMutationResult, -} from "@tanstack/react-query"; -import { useMutation } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { UpdateMangaDataCommand } from "../api.schemas"; + UpdateMangaDataCommand +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + export const sendRecord = ( - updateMangaDataCommand: UpdateMangaDataCommand, - options?: SecondParameter, - signal?: AbortSignal, + updateMangaDataCommand: UpdateMangaDataCommand, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/records`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: updateMangaDataCommand, - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/records`, method: 'POST', + headers: {'Content-Type': 'application/json', }, + data: updateMangaDataCommand, signal + }, + options); + } + -export const getSendRecordMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: UpdateMangaDataCommand }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: UpdateMangaDataCommand }, - TContext -> => { - const mutationKey = ["sendRecord"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { data: UpdateMangaDataCommand } - > = (props) => { - const { data } = props ?? {}; +export const getSendRecordMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: UpdateMangaDataCommand}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: UpdateMangaDataCommand}, TContext> => { - return sendRecord(data, requestOptions); - }; +const mutationKey = ['sendRecord']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type SendRecordMutationResult = NonNullable< - Awaited> ->; -export type SendRecordMutationBody = UpdateMangaDataCommand; -export type SendRecordMutationError = unknown; -export const useSendRecord = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: UpdateMangaDataCommand }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { data: UpdateMangaDataCommand }, - TContext -> => { - const mutationOptions = getSendRecordMutationOptions(options); + const mutationFn: MutationFunction>, {data: UpdateMangaDataCommand}> = (props) => { + const {data} = props ?? {}; - return useMutation(mutationOptions, queryClient); -}; + return sendRecord(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type SendRecordMutationResult = NonNullable>> + export type SendRecordMutationBody = UpdateMangaDataCommand + export type SendRecordMutationError = unknown + + export const useSendRecord = (options?: { mutation?:UseMutationOptions>, TError,{data: UpdateMangaDataCommand}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: UpdateMangaDataCommand}, + TContext + > => { + + const mutationOptions = getSendRecordMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + \ No newline at end of file diff --git a/src/api/generated/favorite-mangas/favorite-mangas.ts b/src/api/generated/favorite-mangas/favorite-mangas.ts index bd706af..ca9074a 100644 --- a/src/api/generated/favorite-mangas/favorite-mangas.ts +++ b/src/api/generated/favorite-mangas/favorite-mangas.ts @@ -4,190 +4,151 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation +} from '@tanstack/react-query'; +import type { + MutationFunction, + QueryClient, + UseMutationOptions, + UseMutationResult +} from '@tanstack/react-query'; import type { - MutationFunction, - QueryClient, - UseMutationOptions, - UseMutationResult, -} from "@tanstack/react-query"; -import { useMutation } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { DefaultResponseDTOVoid } from "../api.schemas"; + DefaultResponseDTOVoid +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Remove a manga from favorites for the logged user. * @summary Unfavorite a manga */ export const setUnfavorite = ( - id: number, - options?: SecondParameter, - signal?: AbortSignal, + id: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(id))}/unfavorite`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(id))}/unfavorite`, method: 'POST', signal + }, + options); + } + -export const getSetUnfavoriteMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationKey = ["setUnfavorite"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { id: number } - > = (props) => { - const { id } = props ?? {}; +export const getSetUnfavoriteMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{id: number}, TContext> => { - return setUnfavorite(id, requestOptions); - }; +const mutationKey = ['setUnfavorite']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type SetUnfavoriteMutationResult = NonNullable< - Awaited> ->; -export type SetUnfavoriteMutationError = unknown; + const mutationFn: MutationFunction>, {id: number}> = (props) => { + const {id} = props ?? {}; -/** + return setUnfavorite(id,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type SetUnfavoriteMutationResult = NonNullable>> + + export type SetUnfavoriteMutationError = unknown + + /** * @summary Unfavorite a manga */ -export const useSetUnfavorite = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationOptions = getSetUnfavoriteMutationOptions(options); +export const useSetUnfavorite = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {id: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getSetUnfavoriteMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Set a manga as favorite for the logged user. * @summary Favorite a manga */ export const setFavorite = ( - id: number, - options?: SecondParameter, - signal?: AbortSignal, + id: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(id))}/favorite`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(id))}/favorite`, method: 'POST', signal + }, + options); + } + -export const getSetFavoriteMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationKey = ["setFavorite"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { id: number } - > = (props) => { - const { id } = props ?? {}; +export const getSetFavoriteMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{id: number}, TContext> => { - return setFavorite(id, requestOptions); - }; +const mutationKey = ['setFavorite']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type SetFavoriteMutationResult = NonNullable< - Awaited> ->; -export type SetFavoriteMutationError = unknown; + const mutationFn: MutationFunction>, {id: number}> = (props) => { + const {id} = props ?? {}; -/** + return setFavorite(id,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type SetFavoriteMutationResult = NonNullable>> + + export type SetFavoriteMutationError = unknown + + /** * @summary Favorite a manga */ -export const useSetFavorite = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationOptions = getSetFavoriteMutationOptions(options); +export const useSetFavorite = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {id: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; + const mutationOptions = getSetFavoriteMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + \ No newline at end of file diff --git a/src/api/generated/genre/genre.ts b/src/api/generated/genre/genre.ts index a690098..68e7f0c 100644 --- a/src/api/generated/genre/genre.ts +++ b/src/api/generated/genre/genre.ts @@ -4,155 +4,122 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useQuery +} from '@tanstack/react-query'; +import type { + DataTag, + DefinedInitialDataOptions, + DefinedUseQueryResult, + QueryClient, + QueryFunction, + QueryKey, + UndefinedInitialDataOptions, + UseQueryOptions, + UseQueryResult +} from '@tanstack/react-query'; import type { - DataTag, - DefinedInitialDataOptions, - DefinedUseQueryResult, - QueryClient, - QueryFunction, - QueryKey, - UndefinedInitialDataOptions, - UseQueryOptions, - UseQueryResult, -} from "@tanstack/react-query"; -import { useQuery } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { DefaultResponseDTOListGenreDTO } from "../api.schemas"; + DefaultResponseDTOListGenreDTO +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Retrieve a list of genres. * @summary Get a list of genres */ export const getGenres = ( - options?: SecondParameter, - signal?: AbortSignal, + + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { url: `/genres`, method: "GET", signal }, - options, - ); -}; + + + return customInstance( + {url: `/genres`, method: 'GET', signal + }, + options); + } + + + export const getGetGenresQueryKey = () => { - return [`/genres`] as const; -}; + return [ + `/genres` + ] as const; + } -export const getGetGenresQueryOptions = < - TData = Awaited>, - TError = unknown, ->(options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; -}) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; + +export const getGetGenresQueryOptions = >, TError = unknown>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +) => { - const queryKey = queryOptions?.queryKey ?? getGetGenresQueryKey(); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction>> = ({ - signal, - }) => getGenres(requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetGenresQueryKey(); - return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; -}; + -export type GetGenresQueryResult = NonNullable< - Awaited> ->; -export type GetGenresQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getGenres(requestOptions, signal); -export function useGetGenres< - TData = Awaited>, - TError = unknown, ->( - options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetGenres< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetGenres< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetGenresQueryResult = NonNullable>> +export type GetGenresQueryError = unknown + + +export function useGetGenres>, TError = unknown>( + options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetGenres>, TError = unknown>( + options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetGenres>, TError = unknown>( + options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get a list of genres */ -export function useGetGenres< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetGenresQueryOptions(options); +export function useGetGenres>, TError = unknown>( + options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetGenresQueryOptions(options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + + diff --git a/src/api/generated/manga-chapter/manga-chapter.ts b/src/api/generated/manga-chapter/manga-chapter.ts index ea5f4e6..cc7e7d5 100644 --- a/src/api/generated/manga-chapter/manga-chapter.ts +++ b/src/api/generated/manga-chapter/manga-chapter.ts @@ -4,551 +4,383 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation, + useQuery +} from '@tanstack/react-query'; +import type { + DataTag, + DefinedInitialDataOptions, + DefinedUseQueryResult, + MutationFunction, + QueryClient, + QueryFunction, + QueryKey, + UndefinedInitialDataOptions, + UseMutationOptions, + UseMutationResult, + UseQueryOptions, + UseQueryResult +} from '@tanstack/react-query'; import type { - DataTag, - DefinedInitialDataOptions, - DefinedUseQueryResult, - MutationFunction, - QueryClient, - QueryFunction, - QueryKey, - UndefinedInitialDataOptions, - UseMutationOptions, - UseMutationResult, - UseQueryOptions, - UseQueryResult, -} from "@tanstack/react-query"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { - DefaultResponseDTOMangaChapterImagesDTO, - DefaultResponseDTOVoid, - DownloadChapterArchiveParams, -} from "../api.schemas"; + DefaultResponseDTOMangaChapterImagesDTO, + DefaultResponseDTOVoid, + DownloadChapterArchiveParams +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Fetch all not yet downloaded chapters from the provider * @summary Fetch all chapters */ export const fetchAllChapters = ( - mangaProviderId: number, - options?: SecondParameter, - signal?: AbortSignal, + mangaProviderId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/fetch-all-chapters`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/fetch-all-chapters`, method: 'POST', signal + }, + options); + } + -export const getFetchAllChaptersMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext -> => { - const mutationKey = ["fetchAllChapters"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { mangaProviderId: number } - > = (props) => { - const { mangaProviderId } = props ?? {}; +export const getFetchAllChaptersMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{mangaProviderId: number}, TContext> => { - return fetchAllChapters(mangaProviderId, requestOptions); - }; +const mutationKey = ['fetchAllChapters']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type FetchAllChaptersMutationResult = NonNullable< - Awaited> ->; -export type FetchAllChaptersMutationError = unknown; + const mutationFn: MutationFunction>, {mangaProviderId: number}> = (props) => { + const {mangaProviderId} = props ?? {}; -/** + return fetchAllChapters(mangaProviderId,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type FetchAllChaptersMutationResult = NonNullable>> + + export type FetchAllChaptersMutationError = unknown + + /** * @summary Fetch all chapters */ -export const useFetchAllChapters = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { mangaProviderId: number }, - TContext -> => { - const mutationOptions = getFetchAllChaptersMutationOptions(options); +export const useFetchAllChapters = (options?: { mutation?:UseMutationOptions>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {mangaProviderId: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getFetchAllChaptersMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Mark a chapter as read by its ID. * @summary Mark a chapter as read */ export const markAsRead = ( - chapterId: number, - options?: SecondParameter, - signal?: AbortSignal, + chapterId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/mark-as-read`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/mark-as-read`, method: 'POST', signal + }, + options); + } + -export const getMarkAsReadMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext -> => { - const mutationKey = ["markAsRead"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { chapterId: number } - > = (props) => { - const { chapterId } = props ?? {}; +export const getMarkAsReadMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{chapterId: number}, TContext> => { - return markAsRead(chapterId, requestOptions); - }; +const mutationKey = ['markAsRead']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type MarkAsReadMutationResult = NonNullable< - Awaited> ->; -export type MarkAsReadMutationError = unknown; + const mutationFn: MutationFunction>, {chapterId: number}> = (props) => { + const {chapterId} = props ?? {}; -/** + return markAsRead(chapterId,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type MarkAsReadMutationResult = NonNullable>> + + export type MarkAsReadMutationError = unknown + + /** * @summary Mark a chapter as read */ -export const useMarkAsRead = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { chapterId: number }, - TContext -> => { - const mutationOptions = getMarkAsReadMutationOptions(options); +export const useMarkAsRead = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {chapterId: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getMarkAsReadMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Fetch the chapter from the provider * @summary Fetch chapter */ export const fetchChapter = ( - chapterId: number, - options?: SecondParameter, - signal?: AbortSignal, + chapterId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/fetch`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/fetch`, method: 'POST', signal + }, + options); + } + -export const getFetchChapterMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext -> => { - const mutationKey = ["fetchChapter"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { chapterId: number } - > = (props) => { - const { chapterId } = props ?? {}; +export const getFetchChapterMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{chapterId: number}, TContext> => { - return fetchChapter(chapterId, requestOptions); - }; +const mutationKey = ['fetchChapter']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type FetchChapterMutationResult = NonNullable< - Awaited> ->; -export type FetchChapterMutationError = unknown; + const mutationFn: MutationFunction>, {chapterId: number}> = (props) => { + const {chapterId} = props ?? {}; -/** + return fetchChapter(chapterId,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type FetchChapterMutationResult = NonNullable>> + + export type FetchChapterMutationError = unknown + + /** * @summary Fetch chapter */ -export const useFetchChapter = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { chapterId: number }, - TContext -> => { - const mutationOptions = getFetchChapterMutationOptions(options); +export const useFetchChapter = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {chapterId: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getFetchChapterMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Download a chapter as a compressed file by its ID. * @summary Download chapter archive */ export const downloadChapterArchive = ( - chapterId: number, - params: DownloadChapterArchiveParams, - options?: SecondParameter, - signal?: AbortSignal, + chapterId: number, + params: DownloadChapterArchiveParams, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/download`, - method: "POST", - params, - responseType: "blob", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/download`, method: 'POST', + params, + responseType: 'blob', signal + }, + options); + } + -export const getDownloadChapterArchiveMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number; params: DownloadChapterArchiveParams }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { chapterId: number; params: DownloadChapterArchiveParams }, - TContext -> => { - const mutationKey = ["downloadChapterArchive"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { chapterId: number; params: DownloadChapterArchiveParams } - > = (props) => { - const { chapterId, params } = props ?? {}; +export const getDownloadChapterArchiveMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number;params: DownloadChapterArchiveParams}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{chapterId: number;params: DownloadChapterArchiveParams}, TContext> => { - return downloadChapterArchive(chapterId, params, requestOptions); - }; +const mutationKey = ['downloadChapterArchive']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type DownloadChapterArchiveMutationResult = NonNullable< - Awaited> ->; -export type DownloadChapterArchiveMutationError = unknown; + const mutationFn: MutationFunction>, {chapterId: number;params: DownloadChapterArchiveParams}> = (props) => { + const {chapterId,params} = props ?? {}; -/** + return downloadChapterArchive(chapterId,params,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type DownloadChapterArchiveMutationResult = NonNullable>> + + export type DownloadChapterArchiveMutationError = unknown + + /** * @summary Download chapter archive */ -export const useDownloadChapterArchive = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { chapterId: number; params: DownloadChapterArchiveParams }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { chapterId: number; params: DownloadChapterArchiveParams }, - TContext -> => { - const mutationOptions = getDownloadChapterArchiveMutationOptions(options); +export const useDownloadChapterArchive = (options?: { mutation?:UseMutationOptions>, TError,{chapterId: number;params: DownloadChapterArchiveParams}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {chapterId: number;params: DownloadChapterArchiveParams}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getDownloadChapterArchiveMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Retrieve a list of manga chapter images for a specific manga/provider combination. * @summary Get the images for a specific manga/provider combination */ export const getMangaChapterImages = ( - chapterId: number, - options?: SecondParameter, - signal?: AbortSignal, + chapterId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/images`, - method: "GET", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/chapters/${encodeURIComponent(String(chapterId))}/images`, method: 'GET', signal + }, + options); + } + -export const getGetMangaChapterImagesQueryKey = (chapterId?: number) => { - return [`/mangas/chapters/${chapterId}/images`] as const; -}; -export const getGetMangaChapterImagesQueryOptions = < - TData = Awaited>, - TError = unknown, ->( - chapterId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, + +export const getGetMangaChapterImagesQueryKey = (chapterId?: number,) => { + return [ + `/mangas/chapters/${chapterId}/images` + ] as const; + } + + +export const getGetMangaChapterImagesQueryOptions = >, TError = unknown>(chapterId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; - const queryKey = - queryOptions?.queryKey ?? getGetMangaChapterImagesQueryKey(chapterId); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction< - Awaited> - > = ({ signal }) => getMangaChapterImages(chapterId, requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetMangaChapterImagesQueryKey(chapterId); - return { - queryKey, - queryFn, - enabled: !!chapterId, - ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; -}; + -export type GetMangaChapterImagesQueryResult = NonNullable< - Awaited> ->; -export type GetMangaChapterImagesQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getMangaChapterImages(chapterId, requestOptions, signal); -export function useGetMangaChapterImages< - TData = Awaited>, - TError = unknown, ->( - chapterId: number, - options: { - query: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangaChapterImages< - TData = Awaited>, - TError = unknown, ->( - chapterId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangaChapterImages< - TData = Awaited>, - TError = unknown, ->( - chapterId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, enabled: !!(chapterId), ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetMangaChapterImagesQueryResult = NonNullable>> +export type GetMangaChapterImagesQueryError = unknown + + +export function useGetMangaChapterImages>, TError = unknown>( + chapterId: number, options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetMangaChapterImages>, TError = unknown>( + chapterId: number, options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetMangaChapterImages>, TError = unknown>( + chapterId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get the images for a specific manga/provider combination */ -export function useGetMangaChapterImages< - TData = Awaited>, - TError = unknown, ->( - chapterId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetMangaChapterImagesQueryOptions(chapterId, options); +export function useGetMangaChapterImages>, TError = unknown>( + chapterId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetMangaChapterImagesQueryOptions(chapterId,options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + + diff --git a/src/api/generated/manga-import-review/manga-import-review.ts b/src/api/generated/manga-import-review/manga-import-review.ts index 3e0997c..722f4d8 100644 --- a/src/api/generated/manga-import-review/manga-import-review.ts +++ b/src/api/generated/manga-import-review/manga-import-review.ts @@ -4,347 +4,255 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation, + useQuery +} from '@tanstack/react-query'; +import type { + DataTag, + DefinedInitialDataOptions, + DefinedUseQueryResult, + MutationFunction, + QueryClient, + QueryFunction, + QueryKey, + UndefinedInitialDataOptions, + UseMutationOptions, + UseMutationResult, + UseQueryOptions, + UseQueryResult +} from '@tanstack/react-query'; import type { - DataTag, - DefinedInitialDataOptions, - DefinedUseQueryResult, - MutationFunction, - QueryClient, - QueryFunction, - QueryKey, - UndefinedInitialDataOptions, - UseMutationOptions, - UseMutationResult, - UseQueryOptions, - UseQueryResult, -} from "@tanstack/react-query"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { - DefaultResponseDTOListImportReviewDTO, - DefaultResponseDTOVoid, - ResolveImportReviewParams, -} from "../api.schemas"; + DefaultResponseDTOListImportReviewDTO, + DefaultResponseDTOVoid, + ResolveImportReviewParams +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Get list of pending import reviews. * @summary Get list of pending import reviews */ export const getImportReviews = ( - options?: SecondParameter, - signal?: AbortSignal, + + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { url: `/manga/import/review`, method: "GET", signal }, - options, - ); -}; + + + return customInstance( + {url: `/manga/import/review`, method: 'GET', signal + }, + options); + } + + + export const getGetImportReviewsQueryKey = () => { - return [`/manga/import/review`] as const; -}; + return [ + `/manga/import/review` + ] as const; + } -export const getGetImportReviewsQueryOptions = < - TData = Awaited>, - TError = unknown, ->(options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; -}) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; + +export const getGetImportReviewsQueryOptions = >, TError = unknown>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +) => { - const queryKey = queryOptions?.queryKey ?? getGetImportReviewsQueryKey(); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction< - Awaited> - > = ({ signal }) => getImportReviews(requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetImportReviewsQueryKey(); - return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; -}; + -export type GetImportReviewsQueryResult = NonNullable< - Awaited> ->; -export type GetImportReviewsQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getImportReviews(requestOptions, signal); -export function useGetImportReviews< - TData = Awaited>, - TError = unknown, ->( - options: { - query: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetImportReviews< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetImportReviews< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetImportReviewsQueryResult = NonNullable>> +export type GetImportReviewsQueryError = unknown + + +export function useGetImportReviews>, TError = unknown>( + options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetImportReviews>, TError = unknown>( + options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetImportReviews>, TError = unknown>( + options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get list of pending import reviews */ -export function useGetImportReviews< - TData = Awaited>, - TError = unknown, ->( - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetImportReviewsQueryOptions(options); +export function useGetImportReviews>, TError = unknown>( + options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetImportReviewsQueryOptions(options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + /** * Resolve import review by ID. * @summary Resolve import review */ export const resolveImportReview = ( - params: ResolveImportReviewParams, - options?: SecondParameter, - signal?: AbortSignal, + params: ResolveImportReviewParams, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { url: `/manga/import/review`, method: "POST", params, signal }, - options, - ); -}; + + + return customInstance( + {url: `/manga/import/review`, method: 'POST', + params, signal + }, + options); + } + -export const getResolveImportReviewMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { params: ResolveImportReviewParams }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { params: ResolveImportReviewParams }, - TContext -> => { - const mutationKey = ["resolveImportReview"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { params: ResolveImportReviewParams } - > = (props) => { - const { params } = props ?? {}; +export const getResolveImportReviewMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{params: ResolveImportReviewParams}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{params: ResolveImportReviewParams}, TContext> => { - return resolveImportReview(params, requestOptions); - }; +const mutationKey = ['resolveImportReview']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type ResolveImportReviewMutationResult = NonNullable< - Awaited> ->; -export type ResolveImportReviewMutationError = unknown; + const mutationFn: MutationFunction>, {params: ResolveImportReviewParams}> = (props) => { + const {params} = props ?? {}; -/** + return resolveImportReview(params,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type ResolveImportReviewMutationResult = NonNullable>> + + export type ResolveImportReviewMutationError = unknown + + /** * @summary Resolve import review */ -export const useResolveImportReview = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { params: ResolveImportReviewParams }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { params: ResolveImportReviewParams }, - TContext -> => { - const mutationOptions = getResolveImportReviewMutationOptions(options); +export const useResolveImportReview = (options?: { mutation?:UseMutationOptions>, TError,{params: ResolveImportReviewParams}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {params: ResolveImportReviewParams}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getResolveImportReviewMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Delete pending import review by ID. * @summary Delete pending import review */ export const deleteImportReview = ( - id: number, - options?: SecondParameter, -) => { - return customInstance( - { - url: `/manga/import/review/${encodeURIComponent(String(id))}`, - method: "DELETE", - }, - options, - ); -}; + id: number, + options?: SecondParameter,) => { + + + return customInstance( + {url: `/manga/import/review/${encodeURIComponent(String(id))}`, method: 'DELETE' + }, + options); + } + -export const getDeleteImportReviewMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationKey = ["deleteImportReview"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { id: number } - > = (props) => { - const { id } = props ?? {}; +export const getDeleteImportReviewMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{id: number}, TContext> => { - return deleteImportReview(id, requestOptions); - }; +const mutationKey = ['deleteImportReview']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type DeleteImportReviewMutationResult = NonNullable< - Awaited> ->; -export type DeleteImportReviewMutationError = unknown; + const mutationFn: MutationFunction>, {id: number}> = (props) => { + const {id} = props ?? {}; -/** + return deleteImportReview(id,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type DeleteImportReviewMutationResult = NonNullable>> + + export type DeleteImportReviewMutationError = unknown + + /** * @summary Delete pending import review */ -export const useDeleteImportReview = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { id: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { id: number }, - TContext -> => { - const mutationOptions = getDeleteImportReviewMutationOptions(options); +export const useDeleteImportReview = (options?: { mutation?:UseMutationOptions>, TError,{id: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {id: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; + const mutationOptions = getDeleteImportReviewMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + \ No newline at end of file diff --git a/src/api/generated/manga-import/manga-import.ts b/src/api/generated/manga-import/manga-import.ts index 4e17c7c..e9cf95b 100644 --- a/src/api/generated/manga-import/manga-import.ts +++ b/src/api/generated/manga-import/manga-import.ts @@ -4,205 +4,161 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation +} from '@tanstack/react-query'; +import type { + MutationFunction, + QueryClient, + UseMutationOptions, + UseMutationResult +} from '@tanstack/react-query'; import type { - MutationFunction, - QueryClient, - UseMutationOptions, - UseMutationResult, -} from "@tanstack/react-query"; -import { useMutation } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { - DefaultResponseDTOImportMangaDexResponseDTO, - DefaultResponseDTOVoid, - ImportMangaDexRequestDTO, - ImportMultipleFilesBody, -} from "../api.schemas"; + DefaultResponseDTOImportMangaDexResponseDTO, + DefaultResponseDTOVoid, + ImportMangaDexRequestDTO, + ImportMultipleFilesBody +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Accepts multiple files via multipart/form-data and processes them. * @summary Upload multiple files */ export const importMultipleFiles = ( - importMultipleFilesBody: ImportMultipleFilesBody, - options?: SecondParameter, - signal?: AbortSignal, + importMultipleFilesBody: ImportMultipleFilesBody, + options?: SecondParameter,signal?: AbortSignal ) => { - const formData = new FormData(); - formData.append(`malId`, importMultipleFilesBody.malId); - importMultipleFilesBody.files.forEach((value) => - formData.append(`files`, value), - ); + + const formData = new FormData(); +formData.append(`malId`, importMultipleFilesBody.malId) +importMultipleFilesBody.files.forEach(value => formData.append(`files`, value)); - return customInstance( - { - url: `/manga/import/upload`, - method: "POST", - headers: { "Content-Type": "multipart/form-data" }, - data: formData, - signal, - }, - options, - ); -}; + return customInstance( + {url: `/manga/import/upload`, method: 'POST', + headers: {'Content-Type': 'multipart/form-data', }, + data: formData, signal + }, + options); + } + -export const getImportMultipleFilesMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: ImportMultipleFilesBody }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: ImportMultipleFilesBody }, - TContext -> => { - const mutationKey = ["importMultipleFiles"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { data: ImportMultipleFilesBody } - > = (props) => { - const { data } = props ?? {}; +export const getImportMultipleFilesMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: ImportMultipleFilesBody}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: ImportMultipleFilesBody}, TContext> => { - return importMultipleFiles(data, requestOptions); - }; +const mutationKey = ['importMultipleFiles']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type ImportMultipleFilesMutationResult = NonNullable< - Awaited> ->; -export type ImportMultipleFilesMutationBody = ImportMultipleFilesBody; -export type ImportMultipleFilesMutationError = unknown; -/** + const mutationFn: MutationFunction>, {data: ImportMultipleFilesBody}> = (props) => { + const {data} = props ?? {}; + + return importMultipleFiles(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type ImportMultipleFilesMutationResult = NonNullable>> + export type ImportMultipleFilesMutationBody = ImportMultipleFilesBody + export type ImportMultipleFilesMutationError = unknown + + /** * @summary Upload multiple files */ -export const useImportMultipleFiles = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: ImportMultipleFilesBody }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { data: ImportMultipleFilesBody }, - TContext -> => { - const mutationOptions = getImportMultipleFilesMutationOptions(options); +export const useImportMultipleFiles = (options?: { mutation?:UseMutationOptions>, TError,{data: ImportMultipleFilesBody}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: ImportMultipleFilesBody}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getImportMultipleFilesMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Imports manga data from MangaDex into the local database. * @summary Import manga from MangaDex */ export const importFromMangaDex = ( - importMangaDexRequestDTO: ImportMangaDexRequestDTO, - options?: SecondParameter, - signal?: AbortSignal, + importMangaDexRequestDTO: ImportMangaDexRequestDTO, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/manga/import/manga-dex`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: importMangaDexRequestDTO, - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/manga/import/manga-dex`, method: 'POST', + headers: {'Content-Type': 'application/json', }, + data: importMangaDexRequestDTO, signal + }, + options); + } + -export const getImportFromMangaDexMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: ImportMangaDexRequestDTO }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: ImportMangaDexRequestDTO }, - TContext -> => { - const mutationKey = ["importFromMangaDex"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { data: ImportMangaDexRequestDTO } - > = (props) => { - const { data } = props ?? {}; +export const getImportFromMangaDexMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: ImportMangaDexRequestDTO}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{data: ImportMangaDexRequestDTO}, TContext> => { - return importFromMangaDex(data, requestOptions); - }; +const mutationKey = ['importFromMangaDex']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type ImportFromMangaDexMutationResult = NonNullable< - Awaited> ->; -export type ImportFromMangaDexMutationBody = ImportMangaDexRequestDTO; -export type ImportFromMangaDexMutationError = unknown; -/** + const mutationFn: MutationFunction>, {data: ImportMangaDexRequestDTO}> = (props) => { + const {data} = props ?? {}; + + return importFromMangaDex(data,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type ImportFromMangaDexMutationResult = NonNullable>> + export type ImportFromMangaDexMutationBody = ImportMangaDexRequestDTO + export type ImportFromMangaDexMutationError = unknown + + /** * @summary Import manga from MangaDex */ -export const useImportFromMangaDex = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { data: ImportMangaDexRequestDTO }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { data: ImportMangaDexRequestDTO }, - TContext -> => { - const mutationOptions = getImportFromMangaDexMutationOptions(options); +export const useImportFromMangaDex = (options?: { mutation?:UseMutationOptions>, TError,{data: ImportMangaDexRequestDTO}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {data: ImportMangaDexRequestDTO}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; + const mutationOptions = getImportFromMangaDexMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + \ No newline at end of file diff --git a/src/api/generated/manga/manga.ts b/src/api/generated/manga/manga.ts index 599f82b..58a9e7f 100644 --- a/src/api/generated/manga/manga.ts +++ b/src/api/generated/manga/manga.ts @@ -4,585 +4,380 @@ * OpenAPI definition * OpenAPI spec version: v0 */ +import { + useMutation, + useQuery +} from '@tanstack/react-query'; +import type { + DataTag, + DefinedInitialDataOptions, + DefinedUseQueryResult, + MutationFunction, + QueryClient, + QueryFunction, + QueryKey, + UndefinedInitialDataOptions, + UseMutationOptions, + UseMutationResult, + UseQueryOptions, + UseQueryResult +} from '@tanstack/react-query'; import type { - DataTag, - DefinedInitialDataOptions, - DefinedUseQueryResult, - MutationFunction, - QueryClient, - QueryFunction, - QueryKey, - UndefinedInitialDataOptions, - UseMutationOptions, - UseMutationResult, - UseQueryOptions, - UseQueryResult, -} from "@tanstack/react-query"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import { customInstance } from "../../api"; -import type { - DefaultResponseDTOListMangaChapterDTO, - DefaultResponseDTOMangaDTO, - DefaultResponseDTOPageMangaListDTO, - DefaultResponseDTOVoid, - GetMangasParams, -} from "../api.schemas"; + DefaultResponseDTOListMangaChapterDTO, + DefaultResponseDTOMangaDTO, + DefaultResponseDTOPageMangaListDTO, + DefaultResponseDTOVoid, + GetMangasParams +} from '../api.schemas'; + +import { customInstance } from '../../api'; + type SecondParameter unknown> = Parameters[1]; + + /** * Fetch a list of manga chapters for a specific manga/provider combination. * @summary Fetch the available chapters for a specific manga/provider combination */ export const fetchMangaChapters = ( - mangaProviderId: number, - options?: SecondParameter, - signal?: AbortSignal, + mangaProviderId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/fetch-chapters`, - method: "POST", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/fetch-chapters`, method: 'POST', signal + }, + options); + } + -export const getFetchMangaChaptersMutationOptions = < - TError = unknown, - TContext = unknown, ->(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext - >; - request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext -> => { - const mutationKey = ["fetchMangaChapters"]; - const { mutation: mutationOptions, request: requestOptions } = options - ? options.mutation && - "mutationKey" in options.mutation && - options.mutation.mutationKey - ? options - : { ...options, mutation: { ...options.mutation, mutationKey } } - : { mutation: { mutationKey }, request: undefined }; - const mutationFn: MutationFunction< - Awaited>, - { mangaProviderId: number } - > = (props) => { - const { mangaProviderId } = props ?? {}; +export const getFetchMangaChaptersMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter} +): UseMutationOptions>, TError,{mangaProviderId: number}, TContext> => { - return fetchMangaChapters(mangaProviderId, requestOptions); - }; +const mutationKey = ['fetchMangaChapters']; +const {mutation: mutationOptions, request: requestOptions} = options ? + options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ? + options + : {...options, mutation: {...options.mutation, mutationKey}} + : {mutation: { mutationKey, }, request: undefined}; - return { mutationFn, ...mutationOptions }; -}; + -export type FetchMangaChaptersMutationResult = NonNullable< - Awaited> ->; -export type FetchMangaChaptersMutationError = unknown; + const mutationFn: MutationFunction>, {mangaProviderId: number}> = (props) => { + const {mangaProviderId} = props ?? {}; -/** + return fetchMangaChapters(mangaProviderId,requestOptions) + } + + + + + return { mutationFn, ...mutationOptions }} + + export type FetchMangaChaptersMutationResult = NonNullable>> + + export type FetchMangaChaptersMutationError = unknown + + /** * @summary Fetch the available chapters for a specific manga/provider combination */ -export const useFetchMangaChapters = ( - options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - { mangaProviderId: number }, - TContext - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseMutationResult< - Awaited>, - TError, - { mangaProviderId: number }, - TContext -> => { - const mutationOptions = getFetchMangaChaptersMutationOptions(options); +export const useFetchMangaChapters = (options?: { mutation?:UseMutationOptions>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter} + , queryClient?: QueryClient): UseMutationResult< + Awaited>, + TError, + {mangaProviderId: number}, + TContext + > => { - return useMutation(mutationOptions, queryClient); -}; -/** + const mutationOptions = getFetchMangaChaptersMutationOptions(options); + + return useMutation(mutationOptions, queryClient); + } + /** * Retrieve a list of mangas with their details. * @summary Get a list of mangas */ export const getMangas = ( - params?: GetMangasParams, - options?: SecondParameter, - signal?: AbortSignal, + params?: GetMangasParams, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { url: `/mangas`, method: "GET", params, signal }, - options, - ); -}; + + + return customInstance( + {url: `/mangas`, method: 'GET', + params, signal + }, + options); + } + -export const getGetMangasQueryKey = (params?: GetMangasParams) => { - return [`/mangas`, ...(params ? [params] : [])] as const; -}; -export const getGetMangasQueryOptions = < - TData = Awaited>, - TError = unknown, ->( - params?: GetMangasParams, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, + +export const getGetMangasQueryKey = (params?: GetMangasParams,) => { + return [ + `/mangas`, ...(params ? [params]: []) + ] as const; + } + + +export const getGetMangasQueryOptions = >, TError = unknown>(params?: GetMangasParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getGetMangasQueryKey(params); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction>> = ({ - signal, - }) => getMangas(params, requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetMangasQueryKey(params); - return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; -}; + -export type GetMangasQueryResult = NonNullable< - Awaited> ->; -export type GetMangasQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getMangas(params, requestOptions, signal); -export function useGetMangas< - TData = Awaited>, - TError = unknown, ->( - params: undefined | GetMangasParams, - options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangas< - TData = Awaited>, - TError = unknown, ->( - params?: GetMangasParams, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangas< - TData = Awaited>, - TError = unknown, ->( - params?: GetMangasParams, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetMangasQueryResult = NonNullable>> +export type GetMangasQueryError = unknown + + +export function useGetMangas>, TError = unknown>( + params: undefined | GetMangasParams, options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetMangas>, TError = unknown>( + params?: GetMangasParams, options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetMangas>, TError = unknown>( + params?: GetMangasParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get a list of mangas */ -export function useGetMangas< - TData = Awaited>, - TError = unknown, ->( - params?: GetMangasParams, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetMangasQueryOptions(params, options); +export function useGetMangas>, TError = unknown>( + params?: GetMangasParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetMangasQueryOptions(params,options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + /** * Retrieve a list of manga chapters for a specific manga/provider combination. * @summary Get the available chapters for a specific manga/provider combination */ export const getMangaChapters = ( - mangaProviderId: number, - options?: SecondParameter, - signal?: AbortSignal, + mangaProviderId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/chapters`, - method: "GET", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/chapters`, method: 'GET', signal + }, + options); + } + -export const getGetMangaChaptersQueryKey = (mangaProviderId?: number) => { - return [`/mangas/${mangaProviderId}/chapters`] as const; -}; -export const getGetMangaChaptersQueryOptions = < - TData = Awaited>, - TError = unknown, ->( - mangaProviderId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, + +export const getGetMangaChaptersQueryKey = (mangaProviderId?: number,) => { + return [ + `/mangas/${mangaProviderId}/chapters` + ] as const; + } + + +export const getGetMangaChaptersQueryOptions = >, TError = unknown>(mangaProviderId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; - const queryKey = - queryOptions?.queryKey ?? getGetMangaChaptersQueryKey(mangaProviderId); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction< - Awaited> - > = ({ signal }) => getMangaChapters(mangaProviderId, requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetMangaChaptersQueryKey(mangaProviderId); - return { - queryKey, - queryFn, - enabled: !!mangaProviderId, - ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; -}; + -export type GetMangaChaptersQueryResult = NonNullable< - Awaited> ->; -export type GetMangaChaptersQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getMangaChapters(mangaProviderId, requestOptions, signal); -export function useGetMangaChapters< - TData = Awaited>, - TError = unknown, ->( - mangaProviderId: number, - options: { - query: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangaChapters< - TData = Awaited>, - TError = unknown, ->( - mangaProviderId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetMangaChapters< - TData = Awaited>, - TError = unknown, ->( - mangaProviderId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, enabled: !!(mangaProviderId), ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetMangaChaptersQueryResult = NonNullable>> +export type GetMangaChaptersQueryError = unknown + + +export function useGetMangaChapters>, TError = unknown>( + mangaProviderId: number, options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetMangaChapters>, TError = unknown>( + mangaProviderId: number, options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetMangaChapters>, TError = unknown>( + mangaProviderId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get the available chapters for a specific manga/provider combination */ -export function useGetMangaChapters< - TData = Awaited>, - TError = unknown, ->( - mangaProviderId: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetMangaChaptersQueryOptions( - mangaProviderId, - options, - ); +export function useGetMangaChapters>, TError = unknown>( + mangaProviderId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetMangaChaptersQueryOptions(mangaProviderId,options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + /** * Get the details of a manga by its ID * @summary Get the details of a manga */ export const getManga = ( - mangaId: number, - options?: SecondParameter, - signal?: AbortSignal, + mangaId: number, + options?: SecondParameter,signal?: AbortSignal ) => { - return customInstance( - { - url: `/mangas/${encodeURIComponent(String(mangaId))}`, - method: "GET", - signal, - }, - options, - ); -}; + + + return customInstance( + {url: `/mangas/${encodeURIComponent(String(mangaId))}`, method: 'GET', signal + }, + options); + } + -export const getGetMangaQueryKey = (mangaId?: number) => { - return [`/mangas/${mangaId}`] as const; -}; -export const getGetMangaQueryOptions = < - TData = Awaited>, - TError = unknown, ->( - mangaId: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, + +export const getGetMangaQueryKey = (mangaId?: number,) => { + return [ + `/mangas/${mangaId}` + ] as const; + } + + +export const getGetMangaQueryOptions = >, TError = unknown>(mangaId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { - const { query: queryOptions, request: requestOptions } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getGetMangaQueryKey(mangaId); +const {query: queryOptions, request: requestOptions} = options ?? {}; - const queryFn: QueryFunction>> = ({ - signal, - }) => getManga(mangaId, requestOptions, signal); + const queryKey = queryOptions?.queryKey ?? getGetMangaQueryKey(mangaId); - return { - queryKey, - queryFn, - enabled: !!mangaId, - ...queryOptions, - } as UseQueryOptions>, TError, TData> & { - queryKey: DataTag; - }; -}; + -export type GetMangaQueryResult = NonNullable< - Awaited> ->; -export type GetMangaQueryError = unknown; + const queryFn: QueryFunction>> = ({ signal }) => getManga(mangaId, requestOptions, signal); -export function useGetManga< - TData = Awaited>, - TError = unknown, ->( - mangaId: number, - options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): DefinedUseQueryResult & { - queryKey: DataTag; -}; -export function useGetManga< - TData = Awaited>, - TError = unknown, ->( - mangaId: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - Awaited> - >, - "initialData" - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; -export function useGetManga< - TData = Awaited>, - TError = unknown, ->( - mangaId: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -}; + + + + + return { queryKey, queryFn, enabled: !!(mangaId), ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: DataTag } +} + +export type GetMangaQueryResult = NonNullable>> +export type GetMangaQueryError = unknown + + +export function useGetManga>, TError = unknown>( + mangaId: number, options: { query:Partial>, TError, TData>> & Pick< + DefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): DefinedUseQueryResult & { queryKey: DataTag } +export function useGetManga>, TError = unknown>( + mangaId: number, options?: { query?:Partial>, TError, TData>> & Pick< + UndefinedInitialDataOptions< + Awaited>, + TError, + Awaited> + > , 'initialData' + >, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } +export function useGetManga>, TError = unknown>( + mangaId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } /** * @summary Get the details of a manga */ -export function useGetManga< - TData = Awaited>, - TError = unknown, ->( - mangaId: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - request?: SecondParameter; - }, - queryClient?: QueryClient, -): UseQueryResult & { - queryKey: DataTag; -} { - const queryOptions = getGetMangaQueryOptions(mangaId, options); +export function useGetManga>, TError = unknown>( + mangaId: number, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + , queryClient?: QueryClient + ): UseQueryResult & { queryKey: DataTag } { - const query = useQuery(queryOptions, queryClient) as UseQueryResult< - TData, - TError - > & { queryKey: DataTag }; + const queryOptions = getGetMangaQueryOptions(mangaId,options) - query.queryKey = queryOptions.queryKey; + const query = useQuery(queryOptions, queryClient) as UseQueryResult & { queryKey: DataTag }; - return query; + query.queryKey = queryOptions.queryKey ; + + return query; } + + + + diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index cfbfdc2..4d2c288 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -22,6 +22,7 @@ export interface User { email: string; name: string; token: string; + refreshToken: string; role: string; } @@ -65,7 +66,8 @@ export function AuthProvider({ children }: { children: ReactNode }) { id: response.data.id, email: response.data.email, name: response.data.name, - token: response.data.token, + token: response.data.accessToken, + refreshToken: response.data.refreshToken, role: response.data.role, };