mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: mount / unmount
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
deleteVolume,
|
||||
getVolume,
|
||||
updateVolume,
|
||||
mountVolume,
|
||||
unmountVolume,
|
||||
} from "../sdk.gen";
|
||||
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
|
||||
import type {
|
||||
@@ -21,6 +23,10 @@ import type {
|
||||
GetVolumeData,
|
||||
UpdateVolumeData,
|
||||
UpdateVolumeResponse,
|
||||
MountVolumeData,
|
||||
MountVolumeResponse,
|
||||
UnmountVolumeData,
|
||||
UnmountVolumeResponse,
|
||||
} from "../types.gen";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
|
||||
@@ -219,3 +225,81 @@ export const updateVolumeMutation = (
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const mountVolumeQueryKey = (options: Options<MountVolumeData>) => createQueryKey("mountVolume", options);
|
||||
|
||||
/**
|
||||
* Mount a volume
|
||||
*/
|
||||
export const mountVolumeOptions = (options: Options<MountVolumeData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await mountVolume({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: mountVolumeQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Mount a volume
|
||||
*/
|
||||
export const mountVolumeMutation = (
|
||||
options?: Partial<Options<MountVolumeData>>,
|
||||
): UseMutationOptions<MountVolumeResponse, DefaultError, Options<MountVolumeData>> => {
|
||||
const mutationOptions: UseMutationOptions<MountVolumeResponse, DefaultError, Options<MountVolumeData>> = {
|
||||
mutationFn: async (localOptions) => {
|
||||
const { data } = await mountVolume({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const unmountVolumeQueryKey = (options: Options<UnmountVolumeData>) => createQueryKey("unmountVolume", options);
|
||||
|
||||
/**
|
||||
* Unmount a volume
|
||||
*/
|
||||
export const unmountVolumeOptions = (options: Options<UnmountVolumeData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await unmountVolume({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: unmountVolumeQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Unmount a volume
|
||||
*/
|
||||
export const unmountVolumeMutation = (
|
||||
options?: Partial<Options<UnmountVolumeData>>,
|
||||
): UseMutationOptions<UnmountVolumeResponse, DefaultError, Options<UnmountVolumeData>> => {
|
||||
const mutationOptions: UseMutationOptions<UnmountVolumeResponse, DefaultError, Options<UnmountVolumeData>> = {
|
||||
mutationFn: async (localOptions) => {
|
||||
const { data } = await unmountVolume({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,12 @@ import type {
|
||||
UpdateVolumeData,
|
||||
UpdateVolumeResponses,
|
||||
UpdateVolumeErrors,
|
||||
MountVolumeData,
|
||||
MountVolumeResponses,
|
||||
MountVolumeErrors,
|
||||
UnmountVolumeData,
|
||||
UnmountVolumeResponses,
|
||||
UnmountVolumeErrors,
|
||||
} from "./types.gen";
|
||||
import { client as _heyApiClient } from "./client.gen";
|
||||
|
||||
@@ -115,3 +121,25 @@ export const updateVolume = <ThrowOnError extends boolean = false>(
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Mount a volume
|
||||
*/
|
||||
export const mountVolume = <ThrowOnError extends boolean = false>(options: Options<MountVolumeData, ThrowOnError>) => {
|
||||
return (options.client ?? _heyApiClient).post<MountVolumeResponses, MountVolumeErrors, ThrowOnError>({
|
||||
url: "/api/v1/volumes/{name}/mount",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Unmount a volume
|
||||
*/
|
||||
export const unmountVolume = <ThrowOnError extends boolean = false>(
|
||||
options: Options<UnmountVolumeData, ThrowOnError>,
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).post<UnmountVolumeResponses, UnmountVolumeErrors, ThrowOnError>({
|
||||
url: "/api/v1/volumes/{name}/unmount",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -245,6 +245,60 @@ export type UpdateVolumeResponses = {
|
||||
|
||||
export type UpdateVolumeResponse = UpdateVolumeResponses[keyof UpdateVolumeResponses];
|
||||
|
||||
export type MountVolumeData = {
|
||||
body?: never;
|
||||
path: {
|
||||
name: string;
|
||||
};
|
||||
query?: never;
|
||||
url: "/api/v1/volumes/{name}/mount";
|
||||
};
|
||||
|
||||
export type MountVolumeErrors = {
|
||||
/**
|
||||
* Volume not found
|
||||
*/
|
||||
404: unknown;
|
||||
};
|
||||
|
||||
export type MountVolumeResponses = {
|
||||
/**
|
||||
* Volume mounted successfully
|
||||
*/
|
||||
200: {
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type MountVolumeResponse = MountVolumeResponses[keyof MountVolumeResponses];
|
||||
|
||||
export type UnmountVolumeData = {
|
||||
body?: never;
|
||||
path: {
|
||||
name: string;
|
||||
};
|
||||
query?: never;
|
||||
url: "/api/v1/volumes/{name}/unmount";
|
||||
};
|
||||
|
||||
export type UnmountVolumeErrors = {
|
||||
/**
|
||||
* Volume not found
|
||||
*/
|
||||
404: unknown;
|
||||
};
|
||||
|
||||
export type UnmountVolumeResponses = {
|
||||
/**
|
||||
* Volume unmounted successfully
|
||||
*/
|
||||
200: {
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type UnmountVolumeResponse = UnmountVolumeResponses[keyof UnmountVolumeResponses];
|
||||
|
||||
export type ClientOptions = {
|
||||
baseUrl: "http://localhost:3000" | (string & {});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user