Spaces:
Sleeping
Sleeping
| /** | |
| * Generated by orval v8.5.3 🍺 | |
| * Do not edit manually. | |
| * Api | |
| * RAQIM — Document to Markdown conversion platform API | |
| * OpenAPI spec version: 0.1.0 | |
| */ | |
| import { useMutation, useQuery } from "@tanstack/react-query"; | |
| import type { | |
| MutationFunction, | |
| QueryFunction, | |
| QueryKey, | |
| UseMutationOptions, | |
| UseMutationResult, | |
| UseQueryOptions, | |
| UseQueryResult, | |
| } from "@tanstack/react-query"; | |
| import type { | |
| AdminCreateUserBody, | |
| AdminListUsersParams, | |
| AdminUpdateUserBody, | |
| AdminUser, | |
| AuthResponse, | |
| ConversionJob, | |
| CreateFolderBody, | |
| CreateShareBody, | |
| ErrorResponse, | |
| ExportBody, | |
| ExportResponse, | |
| FileContent, | |
| FileItem, | |
| Folder, | |
| ForgotPasswordBody, | |
| HealthStatus, | |
| JoinRequest, | |
| ListFilesParams, | |
| ListFoldersParams, | |
| LoginBody, | |
| MessageResponse, | |
| PlatformStats, | |
| ProcessJoinRequestBody, | |
| RegisterBody, | |
| ResetPasswordBody, | |
| SearchUsersForSharingParams, | |
| Share, | |
| StartConversionBody, | |
| TrashItems, | |
| UpdateContentBody, | |
| UpdateFileBody, | |
| UpdateFolderBody, | |
| UpdateShareBody, | |
| User, | |
| UserSummary, | |
| } from "./api.schemas"; | |
| import { customFetch } from "../custom-fetch"; | |
| import type { ErrorType, BodyType } from "../custom-fetch"; | |
| type AwaitedInput<T> = PromiseLike<T> | T; | |
| type Awaited<O> = O extends AwaitedInput<infer T> ? T : never; | |
| type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1]; | |
| /** | |
| * @summary Health check | |
| */ | |
| export const getHealthCheckUrl = () => { | |
| return `/api/healthz`; | |
| }; | |
| export const healthCheck = async ( | |
| options?: RequestInit, | |
| ): Promise<HealthStatus> => { | |
| return customFetch<HealthStatus>(getHealthCheckUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getHealthCheckQueryKey = () => { | |
| return [`/api/healthz`] as const; | |
| }; | |
| export const getHealthCheckQueryOptions = < | |
| TData = Awaited<ReturnType<typeof healthCheck>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof healthCheck>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getHealthCheckQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof healthCheck>>> = ({ | |
| signal, | |
| }) => healthCheck({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof healthCheck>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type HealthCheckQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof healthCheck>> | |
| >; | |
| export type HealthCheckQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Health check | |
| */ | |
| export function useHealthCheck< | |
| TData = Awaited<ReturnType<typeof healthCheck>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof healthCheck>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getHealthCheckQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Submit a join request (creates pending account) | |
| */ | |
| export const getRegisterUserUrl = () => { | |
| return `/api/auth/register`; | |
| }; | |
| export const registerUser = async ( | |
| registerBody: RegisterBody, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getRegisterUserUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(registerBody), | |
| }); | |
| }; | |
| export const getRegisterUserMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof registerUser>>, | |
| TError, | |
| { data: BodyType<RegisterBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof registerUser>>, | |
| TError, | |
| { data: BodyType<RegisterBody> }, | |
| 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<ReturnType<typeof registerUser>>, | |
| { data: BodyType<RegisterBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return registerUser(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type RegisterUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof registerUser>> | |
| >; | |
| export type RegisterUserMutationBody = BodyType<RegisterBody>; | |
| export type RegisterUserMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Submit a join request (creates pending account) | |
| */ | |
| export const useRegisterUser = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof registerUser>>, | |
| TError, | |
| { data: BodyType<RegisterBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof registerUser>>, | |
| TError, | |
| { data: BodyType<RegisterBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getRegisterUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Login with email and password | |
| */ | |
| export const getLoginUserUrl = () => { | |
| return `/api/auth/login`; | |
| }; | |
| export const loginUser = async ( | |
| loginBody: LoginBody, | |
| options?: RequestInit, | |
| ): Promise<AuthResponse> => { | |
| return customFetch<AuthResponse>(getLoginUserUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(loginBody), | |
| }); | |
| }; | |
| export const getLoginUserMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof loginUser>>, | |
| TError, | |
| { data: BodyType<LoginBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof loginUser>>, | |
| TError, | |
| { data: BodyType<LoginBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["loginUser"]; | |
| 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<ReturnType<typeof loginUser>>, | |
| { data: BodyType<LoginBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return loginUser(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type LoginUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof loginUser>> | |
| >; | |
| export type LoginUserMutationBody = BodyType<LoginBody>; | |
| export type LoginUserMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Login with email and password | |
| */ | |
| export const useLoginUser = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof loginUser>>, | |
| TError, | |
| { data: BodyType<LoginBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof loginUser>>, | |
| TError, | |
| { data: BodyType<LoginBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getLoginUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Logout and invalidate refresh token | |
| */ | |
| export const getLogoutUserUrl = () => { | |
| return `/api/auth/logout`; | |
| }; | |
| export const logoutUser = async ( | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getLogoutUserUrl(), { | |
| ...options, | |
| method: "POST", | |
| }); | |
| }; | |
| export const getLogoutUserMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof logoutUser>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof logoutUser>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| const mutationKey = ["logoutUser"]; | |
| 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<ReturnType<typeof logoutUser>>, | |
| void | |
| > = () => { | |
| return logoutUser(requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type LogoutUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof logoutUser>> | |
| >; | |
| export type LogoutUserMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Logout and invalidate refresh token | |
| */ | |
| export const useLogoutUser = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof logoutUser>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof logoutUser>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| return useMutation(getLogoutUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Refresh access token | |
| */ | |
| export const getRefreshTokenUrl = () => { | |
| return `/api/auth/refresh`; | |
| }; | |
| export const refreshToken = async ( | |
| options?: RequestInit, | |
| ): Promise<AuthResponse> => { | |
| return customFetch<AuthResponse>(getRefreshTokenUrl(), { | |
| ...options, | |
| method: "POST", | |
| }); | |
| }; | |
| export const getRefreshTokenMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof refreshToken>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof refreshToken>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| const mutationKey = ["refreshToken"]; | |
| 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<ReturnType<typeof refreshToken>>, | |
| void | |
| > = () => { | |
| return refreshToken(requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type RefreshTokenMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof refreshToken>> | |
| >; | |
| export type RefreshTokenMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Refresh access token | |
| */ | |
| export const useRefreshToken = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof refreshToken>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof refreshToken>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| return useMutation(getRefreshTokenMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Get current authenticated user | |
| */ | |
| export const getGetCurrentUserUrl = () => { | |
| return `/api/auth/me`; | |
| }; | |
| export const getCurrentUser = async (options?: RequestInit): Promise<User> => { | |
| return customFetch<User>(getGetCurrentUserUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetCurrentUserQueryKey = () => { | |
| return [`/api/auth/me`] as const; | |
| }; | |
| export const getGetCurrentUserQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getCurrentUser>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getCurrentUser>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetCurrentUserQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getCurrentUser>>> = ({ | |
| signal, | |
| }) => getCurrentUser({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getCurrentUser>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetCurrentUserQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getCurrentUser>> | |
| >; | |
| export type GetCurrentUserQueryError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Get current authenticated user | |
| */ | |
| export function useGetCurrentUser< | |
| TData = Awaited<ReturnType<typeof getCurrentUser>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getCurrentUser>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetCurrentUserQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Request password reset email | |
| */ | |
| export const getForgotPasswordUrl = () => { | |
| return `/api/auth/forgot-password`; | |
| }; | |
| export const forgotPassword = async ( | |
| forgotPasswordBody: ForgotPasswordBody, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getForgotPasswordUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(forgotPasswordBody), | |
| }); | |
| }; | |
| export const getForgotPasswordMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof forgotPassword>>, | |
| TError, | |
| { data: BodyType<ForgotPasswordBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof forgotPassword>>, | |
| TError, | |
| { data: BodyType<ForgotPasswordBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["forgotPassword"]; | |
| 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<ReturnType<typeof forgotPassword>>, | |
| { data: BodyType<ForgotPasswordBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return forgotPassword(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type ForgotPasswordMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof forgotPassword>> | |
| >; | |
| export type ForgotPasswordMutationBody = BodyType<ForgotPasswordBody>; | |
| export type ForgotPasswordMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Request password reset email | |
| */ | |
| export const useForgotPassword = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof forgotPassword>>, | |
| TError, | |
| { data: BodyType<ForgotPasswordBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof forgotPassword>>, | |
| TError, | |
| { data: BodyType<ForgotPasswordBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getForgotPasswordMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Reset password using token | |
| */ | |
| export const getResetPasswordUrl = () => { | |
| return `/api/auth/reset-password`; | |
| }; | |
| export const resetPassword = async ( | |
| resetPasswordBody: ResetPasswordBody, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getResetPasswordUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(resetPasswordBody), | |
| }); | |
| }; | |
| export const getResetPasswordMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof resetPassword>>, | |
| TError, | |
| { data: BodyType<ResetPasswordBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof resetPassword>>, | |
| TError, | |
| { data: BodyType<ResetPasswordBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["resetPassword"]; | |
| 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<ReturnType<typeof resetPassword>>, | |
| { data: BodyType<ResetPasswordBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return resetPassword(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type ResetPasswordMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof resetPassword>> | |
| >; | |
| export type ResetPasswordMutationBody = BodyType<ResetPasswordBody>; | |
| export type ResetPasswordMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Reset password using token | |
| */ | |
| export const useResetPassword = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof resetPassword>>, | |
| TError, | |
| { data: BodyType<ResetPasswordBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof resetPassword>>, | |
| TError, | |
| { data: BodyType<ResetPasswordBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getResetPasswordMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary List folders for current user | |
| */ | |
| export const getListFoldersUrl = (params?: ListFoldersParams) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/folders?${stringifiedParams}` | |
| : `/api/folders`; | |
| }; | |
| export const listFolders = async ( | |
| params?: ListFoldersParams, | |
| options?: RequestInit, | |
| ): Promise<Folder[]> => { | |
| return customFetch<Folder[]>(getListFoldersUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListFoldersQueryKey = (params?: ListFoldersParams) => { | |
| return [`/api/folders`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getListFoldersQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listFolders>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListFoldersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listFolders>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListFoldersQueryKey(params); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof listFolders>>> = ({ | |
| signal, | |
| }) => listFolders(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listFolders>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListFoldersQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listFolders>> | |
| >; | |
| export type ListFoldersQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List folders for current user | |
| */ | |
| export function useListFolders< | |
| TData = Awaited<ReturnType<typeof listFolders>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListFoldersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listFolders>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListFoldersQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Create a new folder | |
| */ | |
| export const getCreateFolderUrl = () => { | |
| return `/api/folders`; | |
| }; | |
| export const createFolder = async ( | |
| createFolderBody: CreateFolderBody, | |
| options?: RequestInit, | |
| ): Promise<Folder> => { | |
| return customFetch<Folder>(getCreateFolderUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(createFolderBody), | |
| }); | |
| }; | |
| export const getCreateFolderMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createFolder>>, | |
| TError, | |
| { data: BodyType<CreateFolderBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof createFolder>>, | |
| TError, | |
| { data: BodyType<CreateFolderBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["createFolder"]; | |
| 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<ReturnType<typeof createFolder>>, | |
| { data: BodyType<CreateFolderBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return createFolder(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type CreateFolderMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof createFolder>> | |
| >; | |
| export type CreateFolderMutationBody = BodyType<CreateFolderBody>; | |
| export type CreateFolderMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Create a new folder | |
| */ | |
| export const useCreateFolder = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createFolder>>, | |
| TError, | |
| { data: BodyType<CreateFolderBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof createFolder>>, | |
| TError, | |
| { data: BodyType<CreateFolderBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getCreateFolderMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Rename or move a folder | |
| */ | |
| export const getUpdateFolderUrl = (id: string) => { | |
| return `/api/folders/${id}`; | |
| }; | |
| export const updateFolder = async ( | |
| id: string, | |
| updateFolderBody: UpdateFolderBody, | |
| options?: RequestInit, | |
| ): Promise<Folder> => { | |
| return customFetch<Folder>(getUpdateFolderUrl(id), { | |
| ...options, | |
| method: "PATCH", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(updateFolderBody), | |
| }); | |
| }; | |
| export const getUpdateFolderMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFolder>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFolderBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFolder>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFolderBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["updateFolder"]; | |
| 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<ReturnType<typeof updateFolder>>, | |
| { id: string; data: BodyType<UpdateFolderBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return updateFolder(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UpdateFolderMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof updateFolder>> | |
| >; | |
| export type UpdateFolderMutationBody = BodyType<UpdateFolderBody>; | |
| export type UpdateFolderMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Rename or move a folder | |
| */ | |
| export const useUpdateFolder = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFolder>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFolderBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof updateFolder>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFolderBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getUpdateFolderMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Move folder to trash | |
| */ | |
| export const getDeleteFolderUrl = (id: string) => { | |
| return `/api/folders/${id}`; | |
| }; | |
| export const deleteFolder = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getDeleteFolderUrl(id), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getDeleteFolderMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFolder>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFolder>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| const mutationKey = ["deleteFolder"]; | |
| 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<ReturnType<typeof deleteFolder>>, | |
| { id: string } | |
| > = (props) => { | |
| const { id } = props ?? {}; | |
| return deleteFolder(id, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DeleteFolderMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof deleteFolder>> | |
| >; | |
| export type DeleteFolderMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Move folder to trash | |
| */ | |
| export const useDeleteFolder = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFolder>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof deleteFolder>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| return useMutation(getDeleteFolderMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary List files for current user | |
| */ | |
| export const getListFilesUrl = (params?: ListFilesParams) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/files?${stringifiedParams}` | |
| : `/api/files`; | |
| }; | |
| export const listFiles = async ( | |
| params?: ListFilesParams, | |
| options?: RequestInit, | |
| ): Promise<FileItem[]> => { | |
| return customFetch<FileItem[]>(getListFilesUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListFilesQueryKey = (params?: ListFilesParams) => { | |
| return [`/api/files`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getListFilesQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listFiles>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListFilesParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listFiles>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListFilesQueryKey(params); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof listFiles>>> = ({ | |
| signal, | |
| }) => listFiles(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listFiles>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListFilesQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listFiles>> | |
| >; | |
| export type ListFilesQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List files for current user | |
| */ | |
| export function useListFiles< | |
| TData = Awaited<ReturnType<typeof listFiles>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListFilesParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listFiles>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListFilesQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Get file metadata | |
| */ | |
| export const getGetFileUrl = (id: string) => { | |
| return `/api/files/${id}`; | |
| }; | |
| export const getFile = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<FileItem> => { | |
| return customFetch<FileItem>(getGetFileUrl(id), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetFileQueryKey = (id: string) => { | |
| return [`/api/files/${id}`] as const; | |
| }; | |
| export const getGetFileQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getFile>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| id: string, | |
| options?: { | |
| query?: UseQueryOptions<Awaited<ReturnType<typeof getFile>>, TError, TData>; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetFileQueryKey(id); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getFile>>> = ({ | |
| signal, | |
| }) => getFile(id, { signal, ...requestOptions }); | |
| return { | |
| queryKey, | |
| queryFn, | |
| enabled: !!id, | |
| ...queryOptions, | |
| } as UseQueryOptions<Awaited<ReturnType<typeof getFile>>, TError, TData> & { | |
| queryKey: QueryKey; | |
| }; | |
| }; | |
| export type GetFileQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getFile>> | |
| >; | |
| export type GetFileQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get file metadata | |
| */ | |
| export function useGetFile< | |
| TData = Awaited<ReturnType<typeof getFile>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| id: string, | |
| options?: { | |
| query?: UseQueryOptions<Awaited<ReturnType<typeof getFile>>, TError, TData>; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetFileQueryOptions(id, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Rename or move a file | |
| */ | |
| export const getUpdateFileUrl = (id: string) => { | |
| return `/api/files/${id}`; | |
| }; | |
| export const updateFile = async ( | |
| id: string, | |
| updateFileBody: UpdateFileBody, | |
| options?: RequestInit, | |
| ): Promise<FileItem> => { | |
| return customFetch<FileItem>(getUpdateFileUrl(id), { | |
| ...options, | |
| method: "PATCH", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(updateFileBody), | |
| }); | |
| }; | |
| export const getUpdateFileMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFile>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFileBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFile>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFileBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["updateFile"]; | |
| 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<ReturnType<typeof updateFile>>, | |
| { id: string; data: BodyType<UpdateFileBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return updateFile(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UpdateFileMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof updateFile>> | |
| >; | |
| export type UpdateFileMutationBody = BodyType<UpdateFileBody>; | |
| export type UpdateFileMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Rename or move a file | |
| */ | |
| export const useUpdateFile = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFile>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFileBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof updateFile>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateFileBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getUpdateFileMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Move file to trash | |
| */ | |
| export const getDeleteFileUrl = (id: string) => { | |
| return `/api/files/${id}`; | |
| }; | |
| export const deleteFile = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getDeleteFileUrl(id), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getDeleteFileMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| const mutationKey = ["deleteFile"]; | |
| 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<ReturnType<typeof deleteFile>>, | |
| { id: string } | |
| > = (props) => { | |
| const { id } = props ?? {}; | |
| return deleteFile(id, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DeleteFileMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof deleteFile>> | |
| >; | |
| export type DeleteFileMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Move file to trash | |
| */ | |
| export const useDeleteFile = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof deleteFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| return useMutation(getDeleteFileMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Get file markdown content | |
| */ | |
| export const getGetFileContentUrl = (id: string) => { | |
| return `/api/files/${id}/content`; | |
| }; | |
| export const getFileContent = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<FileContent> => { | |
| return customFetch<FileContent>(getGetFileContentUrl(id), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetFileContentQueryKey = (id: string) => { | |
| return [`/api/files/${id}/content`] as const; | |
| }; | |
| export const getGetFileContentQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getFileContent>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| id: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getFileContent>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetFileContentQueryKey(id); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getFileContent>>> = ({ | |
| signal, | |
| }) => getFileContent(id, { signal, ...requestOptions }); | |
| return { | |
| queryKey, | |
| queryFn, | |
| enabled: !!id, | |
| ...queryOptions, | |
| } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getFileContent>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetFileContentQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getFileContent>> | |
| >; | |
| export type GetFileContentQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get file markdown content | |
| */ | |
| export function useGetFileContent< | |
| TData = Awaited<ReturnType<typeof getFileContent>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| id: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getFileContent>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetFileContentQueryOptions(id, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Update file markdown content (auto-save) | |
| */ | |
| export const getUpdateFileContentUrl = (id: string) => { | |
| return `/api/files/${id}/content`; | |
| }; | |
| export const updateFileContent = async ( | |
| id: string, | |
| updateContentBody: UpdateContentBody, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getUpdateFileContentUrl(id), { | |
| ...options, | |
| method: "PUT", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(updateContentBody), | |
| }); | |
| }; | |
| export const getUpdateFileContentMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFileContent>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateContentBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFileContent>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateContentBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["updateFileContent"]; | |
| 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<ReturnType<typeof updateFileContent>>, | |
| { id: string; data: BodyType<UpdateContentBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return updateFileContent(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UpdateFileContentMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof updateFileContent>> | |
| >; | |
| export type UpdateFileContentMutationBody = BodyType<UpdateContentBody>; | |
| export type UpdateFileContentMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Update file markdown content (auto-save) | |
| */ | |
| export const useUpdateFileContent = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateFileContent>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateContentBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof updateFileContent>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateContentBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getUpdateFileContentMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Restore file from trash | |
| */ | |
| export const getRestoreFileUrl = (id: string) => { | |
| return `/api/files/${id}/restore`; | |
| }; | |
| export const restoreFile = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getRestoreFileUrl(id), { | |
| ...options, | |
| method: "POST", | |
| }); | |
| }; | |
| export const getRestoreFileMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof restoreFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof restoreFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| const mutationKey = ["restoreFile"]; | |
| 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<ReturnType<typeof restoreFile>>, | |
| { id: string } | |
| > = (props) => { | |
| const { id } = props ?? {}; | |
| return restoreFile(id, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type RestoreFileMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof restoreFile>> | |
| >; | |
| export type RestoreFileMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Restore file from trash | |
| */ | |
| export const useRestoreFile = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof restoreFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof restoreFile>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| return useMutation(getRestoreFileMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Export file as DOCX or PDF | |
| */ | |
| export const getExportFileUrl = (id: string) => { | |
| return `/api/files/${id}/export`; | |
| }; | |
| export const exportFile = async ( | |
| id: string, | |
| exportBody: ExportBody, | |
| options?: RequestInit, | |
| ): Promise<ExportResponse> => { | |
| return customFetch<ExportResponse>(getExportFileUrl(id), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(exportBody), | |
| }); | |
| }; | |
| export const getExportFileMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof exportFile>>, | |
| TError, | |
| { id: string; data: BodyType<ExportBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof exportFile>>, | |
| TError, | |
| { id: string; data: BodyType<ExportBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["exportFile"]; | |
| 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<ReturnType<typeof exportFile>>, | |
| { id: string; data: BodyType<ExportBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return exportFile(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type ExportFileMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof exportFile>> | |
| >; | |
| export type ExportFileMutationBody = BodyType<ExportBody>; | |
| export type ExportFileMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Export file as DOCX or PDF | |
| */ | |
| export const useExportFile = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof exportFile>>, | |
| TError, | |
| { id: string; data: BodyType<ExportBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof exportFile>>, | |
| TError, | |
| { id: string; data: BodyType<ExportBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getExportFileMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Start document conversion job | |
| */ | |
| export const getStartConversionUrl = () => { | |
| return `/api/convert`; | |
| }; | |
| export const startConversion = async ( | |
| startConversionBody: StartConversionBody, | |
| options?: RequestInit, | |
| ): Promise<ConversionJob> => { | |
| return customFetch<ConversionJob>(getStartConversionUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(startConversionBody), | |
| }); | |
| }; | |
| export const getStartConversionMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof startConversion>>, | |
| TError, | |
| { data: BodyType<StartConversionBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof startConversion>>, | |
| TError, | |
| { data: BodyType<StartConversionBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["startConversion"]; | |
| 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<ReturnType<typeof startConversion>>, | |
| { data: BodyType<StartConversionBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return startConversion(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type StartConversionMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof startConversion>> | |
| >; | |
| export type StartConversionMutationBody = BodyType<StartConversionBody>; | |
| export type StartConversionMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Start document conversion job | |
| */ | |
| export const useStartConversion = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof startConversion>>, | |
| TError, | |
| { data: BodyType<StartConversionBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof startConversion>>, | |
| TError, | |
| { data: BodyType<StartConversionBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getStartConversionMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Get conversion job status and progress | |
| */ | |
| export const getGetConversionStatusUrl = (jobId: string) => { | |
| return `/api/convert/${jobId}`; | |
| }; | |
| export const getConversionStatus = async ( | |
| jobId: string, | |
| options?: RequestInit, | |
| ): Promise<ConversionJob> => { | |
| return customFetch<ConversionJob>(getGetConversionStatusUrl(jobId), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetConversionStatusQueryKey = (jobId: string) => { | |
| return [`/api/convert/${jobId}`] as const; | |
| }; | |
| export const getGetConversionStatusQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getConversionStatus>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| jobId: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getConversionStatus>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = | |
| queryOptions?.queryKey ?? getGetConversionStatusQueryKey(jobId); | |
| const queryFn: QueryFunction< | |
| Awaited<ReturnType<typeof getConversionStatus>> | |
| > = ({ signal }) => getConversionStatus(jobId, { signal, ...requestOptions }); | |
| return { | |
| queryKey, | |
| queryFn, | |
| enabled: !!jobId, | |
| ...queryOptions, | |
| } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getConversionStatus>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetConversionStatusQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getConversionStatus>> | |
| >; | |
| export type GetConversionStatusQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get conversion job status and progress | |
| */ | |
| export function useGetConversionStatus< | |
| TData = Awaited<ReturnType<typeof getConversionStatus>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| jobId: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getConversionStatus>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetConversionStatusQueryOptions(jobId, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Upload file and start conversion | |
| */ | |
| export const getUploadAndConvertUrl = () => { | |
| return `/api/convert/upload`; | |
| }; | |
| export const uploadAndConvert = async ( | |
| options?: RequestInit, | |
| ): Promise<ConversionJob> => { | |
| return customFetch<ConversionJob>(getUploadAndConvertUrl(), { | |
| ...options, | |
| method: "POST", | |
| }); | |
| }; | |
| export const getUploadAndConvertMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof uploadAndConvert>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof uploadAndConvert>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| const mutationKey = ["uploadAndConvert"]; | |
| 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<ReturnType<typeof uploadAndConvert>>, | |
| void | |
| > = () => { | |
| return uploadAndConvert(requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UploadAndConvertMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof uploadAndConvert>> | |
| >; | |
| export type UploadAndConvertMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Upload file and start conversion | |
| */ | |
| export const useUploadAndConvert = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof uploadAndConvert>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof uploadAndConvert>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| return useMutation(getUploadAndConvertMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary List shares for current user (owned + shared with me) | |
| */ | |
| export const getListSharesUrl = () => { | |
| return `/api/shares`; | |
| }; | |
| export const listShares = async (options?: RequestInit): Promise<Share[]> => { | |
| return customFetch<Share[]>(getListSharesUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListSharesQueryKey = () => { | |
| return [`/api/shares`] as const; | |
| }; | |
| export const getListSharesQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listShares>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listShares>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListSharesQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof listShares>>> = ({ | |
| signal, | |
| }) => listShares({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listShares>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListSharesQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listShares>> | |
| >; | |
| export type ListSharesQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List shares for current user (owned + shared with me) | |
| */ | |
| export function useListShares< | |
| TData = Awaited<ReturnType<typeof listShares>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listShares>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListSharesQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Share a file or folder with a user | |
| */ | |
| export const getCreateShareUrl = () => { | |
| return `/api/shares`; | |
| }; | |
| export const createShare = async ( | |
| createShareBody: CreateShareBody, | |
| options?: RequestInit, | |
| ): Promise<Share> => { | |
| return customFetch<Share>(getCreateShareUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(createShareBody), | |
| }); | |
| }; | |
| export const getCreateShareMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createShare>>, | |
| TError, | |
| { data: BodyType<CreateShareBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof createShare>>, | |
| TError, | |
| { data: BodyType<CreateShareBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["createShare"]; | |
| 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<ReturnType<typeof createShare>>, | |
| { data: BodyType<CreateShareBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return createShare(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type CreateShareMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof createShare>> | |
| >; | |
| export type CreateShareMutationBody = BodyType<CreateShareBody>; | |
| export type CreateShareMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Share a file or folder with a user | |
| */ | |
| export const useCreateShare = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createShare>>, | |
| TError, | |
| { data: BodyType<CreateShareBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof createShare>>, | |
| TError, | |
| { data: BodyType<CreateShareBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getCreateShareMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Update share permission | |
| */ | |
| export const getUpdateShareUrl = (id: string) => { | |
| return `/api/shares/${id}`; | |
| }; | |
| export const updateShare = async ( | |
| id: string, | |
| updateShareBody: UpdateShareBody, | |
| options?: RequestInit, | |
| ): Promise<Share> => { | |
| return customFetch<Share>(getUpdateShareUrl(id), { | |
| ...options, | |
| method: "PATCH", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(updateShareBody), | |
| }); | |
| }; | |
| export const getUpdateShareMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateShare>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateShareBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof updateShare>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateShareBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["updateShare"]; | |
| 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<ReturnType<typeof updateShare>>, | |
| { id: string; data: BodyType<UpdateShareBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return updateShare(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UpdateShareMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof updateShare>> | |
| >; | |
| export type UpdateShareMutationBody = BodyType<UpdateShareBody>; | |
| export type UpdateShareMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Update share permission | |
| */ | |
| export const useUpdateShare = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof updateShare>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateShareBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof updateShare>>, | |
| TError, | |
| { id: string; data: BodyType<UpdateShareBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getUpdateShareMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Remove a share | |
| */ | |
| export const getDeleteShareUrl = (id: string) => { | |
| return `/api/shares/${id}`; | |
| }; | |
| export const deleteShare = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getDeleteShareUrl(id), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getDeleteShareMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteShare>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteShare>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| const mutationKey = ["deleteShare"]; | |
| 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<ReturnType<typeof deleteShare>>, | |
| { id: string } | |
| > = (props) => { | |
| const { id } = props ?? {}; | |
| return deleteShare(id, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DeleteShareMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof deleteShare>> | |
| >; | |
| export type DeleteShareMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Remove a share | |
| */ | |
| export const useDeleteShare = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof deleteShare>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof deleteShare>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| return useMutation(getDeleteShareMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Search users by email or username for sharing | |
| */ | |
| export const getSearchUsersForSharingUrl = ( | |
| params: SearchUsersForSharingParams, | |
| ) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/shares/search-users?${stringifiedParams}` | |
| : `/api/shares/search-users`; | |
| }; | |
| export const searchUsersForSharing = async ( | |
| params: SearchUsersForSharingParams, | |
| options?: RequestInit, | |
| ): Promise<UserSummary[]> => { | |
| return customFetch<UserSummary[]>(getSearchUsersForSharingUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getSearchUsersForSharingQueryKey = ( | |
| params?: SearchUsersForSharingParams, | |
| ) => { | |
| return [`/api/shares/search-users`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getSearchUsersForSharingQueryOptions = < | |
| TData = Awaited<ReturnType<typeof searchUsersForSharing>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params: SearchUsersForSharingParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof searchUsersForSharing>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = | |
| queryOptions?.queryKey ?? getSearchUsersForSharingQueryKey(params); | |
| const queryFn: QueryFunction< | |
| Awaited<ReturnType<typeof searchUsersForSharing>> | |
| > = ({ signal }) => | |
| searchUsersForSharing(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof searchUsersForSharing>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type SearchUsersForSharingQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof searchUsersForSharing>> | |
| >; | |
| export type SearchUsersForSharingQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Search users by email or username for sharing | |
| */ | |
| export function useSearchUsersForSharing< | |
| TData = Awaited<ReturnType<typeof searchUsersForSharing>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params: SearchUsersForSharingParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof searchUsersForSharing>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getSearchUsersForSharingQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary List all users | |
| */ | |
| export const getAdminListUsersUrl = (params?: AdminListUsersParams) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/admin/users?${stringifiedParams}` | |
| : `/api/admin/users`; | |
| }; | |
| export const adminListUsers = async ( | |
| params?: AdminListUsersParams, | |
| options?: RequestInit, | |
| ): Promise<AdminUser[]> => { | |
| return customFetch<AdminUser[]>(getAdminListUsersUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getAdminListUsersQueryKey = (params?: AdminListUsersParams) => { | |
| return [`/api/admin/users`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getAdminListUsersQueryOptions = < | |
| TData = Awaited<ReturnType<typeof adminListUsers>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: AdminListUsersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListUsers>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getAdminListUsersQueryKey(params); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof adminListUsers>>> = ({ | |
| signal, | |
| }) => adminListUsers(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListUsers>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type AdminListUsersQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof adminListUsers>> | |
| >; | |
| export type AdminListUsersQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List all users | |
| */ | |
| export function useAdminListUsers< | |
| TData = Awaited<ReturnType<typeof adminListUsers>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: AdminListUsersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListUsers>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getAdminListUsersQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Admin creates user directly (active status) | |
| */ | |
| export const getAdminCreateUserUrl = () => { | |
| return `/api/admin/users`; | |
| }; | |
| export const adminCreateUser = async ( | |
| adminCreateUserBody: AdminCreateUserBody, | |
| options?: RequestInit, | |
| ): Promise<AdminUser> => { | |
| return customFetch<AdminUser>(getAdminCreateUserUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(adminCreateUserBody), | |
| }); | |
| }; | |
| export const getAdminCreateUserMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminCreateUser>>, | |
| TError, | |
| { data: BodyType<AdminCreateUserBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof adminCreateUser>>, | |
| TError, | |
| { data: BodyType<AdminCreateUserBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["adminCreateUser"]; | |
| 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<ReturnType<typeof adminCreateUser>>, | |
| { data: BodyType<AdminCreateUserBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return adminCreateUser(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type AdminCreateUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof adminCreateUser>> | |
| >; | |
| export type AdminCreateUserMutationBody = BodyType<AdminCreateUserBody>; | |
| export type AdminCreateUserMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Admin creates user directly (active status) | |
| */ | |
| export const useAdminCreateUser = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminCreateUser>>, | |
| TError, | |
| { data: BodyType<AdminCreateUserBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof adminCreateUser>>, | |
| TError, | |
| { data: BodyType<AdminCreateUserBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getAdminCreateUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Update user role or status | |
| */ | |
| export const getAdminUpdateUserUrl = (id: string) => { | |
| return `/api/admin/users/${id}`; | |
| }; | |
| export const adminUpdateUser = async ( | |
| id: string, | |
| adminUpdateUserBody: AdminUpdateUserBody, | |
| options?: RequestInit, | |
| ): Promise<AdminUser> => { | |
| return customFetch<AdminUser>(getAdminUpdateUserUrl(id), { | |
| ...options, | |
| method: "PATCH", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(adminUpdateUserBody), | |
| }); | |
| }; | |
| export const getAdminUpdateUserMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminUpdateUser>>, | |
| TError, | |
| { id: string; data: BodyType<AdminUpdateUserBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof adminUpdateUser>>, | |
| TError, | |
| { id: string; data: BodyType<AdminUpdateUserBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["adminUpdateUser"]; | |
| 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<ReturnType<typeof adminUpdateUser>>, | |
| { id: string; data: BodyType<AdminUpdateUserBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return adminUpdateUser(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type AdminUpdateUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof adminUpdateUser>> | |
| >; | |
| export type AdminUpdateUserMutationBody = BodyType<AdminUpdateUserBody>; | |
| export type AdminUpdateUserMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Update user role or status | |
| */ | |
| export const useAdminUpdateUser = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminUpdateUser>>, | |
| TError, | |
| { id: string; data: BodyType<AdminUpdateUserBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof adminUpdateUser>>, | |
| TError, | |
| { id: string; data: BodyType<AdminUpdateUserBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getAdminUpdateUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Permanently delete a user | |
| */ | |
| export const getAdminDeleteUserUrl = (id: string) => { | |
| return `/api/admin/users/${id}`; | |
| }; | |
| export const adminDeleteUser = async ( | |
| id: string, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getAdminDeleteUserUrl(id), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getAdminDeleteUserMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminDeleteUser>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof adminDeleteUser>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| const mutationKey = ["adminDeleteUser"]; | |
| 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<ReturnType<typeof adminDeleteUser>>, | |
| { id: string } | |
| > = (props) => { | |
| const { id } = props ?? {}; | |
| return adminDeleteUser(id, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type AdminDeleteUserMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof adminDeleteUser>> | |
| >; | |
| export type AdminDeleteUserMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Permanently delete a user | |
| */ | |
| export const useAdminDeleteUser = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminDeleteUser>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof adminDeleteUser>>, | |
| TError, | |
| { id: string }, | |
| TContext | |
| > => { | |
| return useMutation(getAdminDeleteUserMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary List pending join requests | |
| */ | |
| export const getListJoinRequestsUrl = () => { | |
| return `/api/admin/join-requests`; | |
| }; | |
| export const listJoinRequests = async ( | |
| options?: RequestInit, | |
| ): Promise<JoinRequest[]> => { | |
| return customFetch<JoinRequest[]>(getListJoinRequestsUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListJoinRequestsQueryKey = () => { | |
| return [`/api/admin/join-requests`] as const; | |
| }; | |
| export const getListJoinRequestsQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listJoinRequests>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listJoinRequests>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListJoinRequestsQueryKey(); | |
| const queryFn: QueryFunction< | |
| Awaited<ReturnType<typeof listJoinRequests>> | |
| > = ({ signal }) => listJoinRequests({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listJoinRequests>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListJoinRequestsQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listJoinRequests>> | |
| >; | |
| export type ListJoinRequestsQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List pending join requests | |
| */ | |
| export function useListJoinRequests< | |
| TData = Awaited<ReturnType<typeof listJoinRequests>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listJoinRequests>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListJoinRequestsQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Approve or reject a join request | |
| */ | |
| export const getProcessJoinRequestUrl = (id: string) => { | |
| return `/api/admin/join-requests/${id}`; | |
| }; | |
| export const processJoinRequest = async ( | |
| id: string, | |
| processJoinRequestBody: ProcessJoinRequestBody, | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getProcessJoinRequestUrl(id), { | |
| ...options, | |
| method: "PATCH", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(processJoinRequestBody), | |
| }); | |
| }; | |
| export const getProcessJoinRequestMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof processJoinRequest>>, | |
| TError, | |
| { id: string; data: BodyType<ProcessJoinRequestBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof processJoinRequest>>, | |
| TError, | |
| { id: string; data: BodyType<ProcessJoinRequestBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["processJoinRequest"]; | |
| 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<ReturnType<typeof processJoinRequest>>, | |
| { id: string; data: BodyType<ProcessJoinRequestBody> } | |
| > = (props) => { | |
| const { id, data } = props ?? {}; | |
| return processJoinRequest(id, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type ProcessJoinRequestMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof processJoinRequest>> | |
| >; | |
| export type ProcessJoinRequestMutationBody = BodyType<ProcessJoinRequestBody>; | |
| export type ProcessJoinRequestMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Approve or reject a join request | |
| */ | |
| export const useProcessJoinRequest = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof processJoinRequest>>, | |
| TError, | |
| { id: string; data: BodyType<ProcessJoinRequestBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof processJoinRequest>>, | |
| TError, | |
| { id: string; data: BodyType<ProcessJoinRequestBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getProcessJoinRequestMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Get platform statistics | |
| */ | |
| export const getGetAdminStatsUrl = () => { | |
| return `/api/admin/stats`; | |
| }; | |
| export const getAdminStats = async ( | |
| options?: RequestInit, | |
| ): Promise<PlatformStats> => { | |
| return customFetch<PlatformStats>(getGetAdminStatsUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetAdminStatsQueryKey = () => { | |
| return [`/api/admin/stats`] as const; | |
| }; | |
| export const getGetAdminStatsQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getAdminStats>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getAdminStats>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetAdminStatsQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getAdminStats>>> = ({ | |
| signal, | |
| }) => getAdminStats({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getAdminStats>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetAdminStatsQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getAdminStats>> | |
| >; | |
| export type GetAdminStatsQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get platform statistics | |
| */ | |
| export function useGetAdminStats< | |
| TData = Awaited<ReturnType<typeof getAdminStats>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getAdminStats>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetAdminStatsQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary List trashed files and folders for current user | |
| */ | |
| export const getListUserTrashUrl = () => { | |
| return `/api/trash`; | |
| }; | |
| export const listUserTrash = async ( | |
| options?: RequestInit, | |
| ): Promise<TrashItems> => { | |
| return customFetch<TrashItems>(getListUserTrashUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListUserTrashQueryKey = () => { | |
| return [`/api/trash`] as const; | |
| }; | |
| export const getListUserTrashQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listUserTrash>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listUserTrash>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListUserTrashQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof listUserTrash>>> = ({ | |
| signal, | |
| }) => listUserTrash({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listUserTrash>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListUserTrashQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listUserTrash>> | |
| >; | |
| export type ListUserTrashQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List trashed files and folders for current user | |
| */ | |
| export function useListUserTrash< | |
| TData = Awaited<ReturnType<typeof listUserTrash>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listUserTrash>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListUserTrashQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Permanently delete all current user's trashed items | |
| */ | |
| export const getEmptyUserTrashUrl = () => { | |
| return `/api/trash/empty`; | |
| }; | |
| export const emptyUserTrash = async ( | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getEmptyUserTrashUrl(), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getEmptyUserTrashMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof emptyUserTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof emptyUserTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| const mutationKey = ["emptyUserTrash"]; | |
| 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<ReturnType<typeof emptyUserTrash>>, | |
| void | |
| > = () => { | |
| return emptyUserTrash(requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type EmptyUserTrashMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof emptyUserTrash>> | |
| >; | |
| export type EmptyUserTrashMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Permanently delete all current user's trashed items | |
| */ | |
| export const useEmptyUserTrash = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof emptyUserTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof emptyUserTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| return useMutation(getEmptyUserTrashMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary List ALL users' trashed files/folders (admin only) | |
| */ | |
| export const getAdminListTrashUrl = () => { | |
| return `/api/admin/trash`; | |
| }; | |
| export const adminListTrash = async ( | |
| options?: RequestInit, | |
| ): Promise<TrashItems> => { | |
| return customFetch<TrashItems>(getAdminListTrashUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getAdminListTrashQueryKey = () => { | |
| return [`/api/admin/trash`] as const; | |
| }; | |
| export const getAdminListTrashQueryOptions = < | |
| TData = Awaited<ReturnType<typeof adminListTrash>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListTrash>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getAdminListTrashQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof adminListTrash>>> = ({ | |
| signal, | |
| }) => adminListTrash({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListTrash>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type AdminListTrashQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof adminListTrash>> | |
| >; | |
| export type AdminListTrashQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List ALL users' trashed files/folders (admin only) | |
| */ | |
| export function useAdminListTrash< | |
| TData = Awaited<ReturnType<typeof adminListTrash>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof adminListTrash>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getAdminListTrashQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * @summary Permanently delete all trashed items for current admin user | |
| */ | |
| export const getAdminEmptyTrashUrl = () => { | |
| return `/api/admin/trash/empty`; | |
| }; | |
| export const adminEmptyTrash = async ( | |
| options?: RequestInit, | |
| ): Promise<MessageResponse> => { | |
| return customFetch<MessageResponse>(getAdminEmptyTrashUrl(), { | |
| ...options, | |
| method: "DELETE", | |
| }); | |
| }; | |
| export const getAdminEmptyTrashMutationOptions = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminEmptyTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof adminEmptyTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| const mutationKey = ["adminEmptyTrash"]; | |
| 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<ReturnType<typeof adminEmptyTrash>>, | |
| void | |
| > = () => { | |
| return adminEmptyTrash(requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type AdminEmptyTrashMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof adminEmptyTrash>> | |
| >; | |
| export type AdminEmptyTrashMutationError = ErrorType<unknown>; | |
| /** | |
| * @summary Permanently delete all trashed items for current admin user | |
| */ | |
| export const useAdminEmptyTrash = < | |
| TError = ErrorType<unknown>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof adminEmptyTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof adminEmptyTrash>>, | |
| TError, | |
| void, | |
| TContext | |
| > => { | |
| return useMutation(getAdminEmptyTrashMutationOptions(options)); | |
| }; | |