refactor: use rr actions/loader

refactor: use rr actions
This commit is contained in:
Nicolas Meienberger
2025-08-31 19:22:55 +02:00
parent 23f47bbb6b
commit 37effcb4e3
21 changed files with 454 additions and 219 deletions

View File

@@ -1,8 +1,16 @@
// This file is auto-generated by @hey-api/openapi-ts
import { type Options, getApiV1Volumes } from "../sdk.gen";
import { queryOptions } from "@tanstack/react-query";
import type { GetApiV1VolumesData } from "../types.gen";
import { type Options, listVolumes, createVolume } from "../sdk.gen";
import {
queryOptions,
type UseMutationOptions,
type DefaultError,
} from "@tanstack/react-query";
import type {
ListVolumesData,
CreateVolumeData,
CreateVolumeResponse,
} from "../types.gen";
import { client as _heyApiClient } from "../client.gen";
export type QueryKey<TOptions extends Options> = [
@@ -46,19 +54,16 @@ const createQueryKey = <TOptions extends Options>(
return [params];
};
export const getApiV1VolumesQueryKey = (
options?: Options<GetApiV1VolumesData>,
) => createQueryKey("getApiV1Volumes", options);
export const listVolumesQueryKey = (options?: Options<ListVolumesData>) =>
createQueryKey("listVolumes", options);
/**
* List all volumes
*/
export const getApiV1VolumesOptions = (
options?: Options<GetApiV1VolumesData>,
) => {
export const listVolumesOptions = (options?: Options<ListVolumesData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await getApiV1Volumes({
const { data } = await listVolumes({
...options,
...queryKey[0],
signal,
@@ -66,6 +71,54 @@ export const getApiV1VolumesOptions = (
});
return data;
},
queryKey: getApiV1VolumesQueryKey(options),
queryKey: listVolumesQueryKey(options),
});
};
export const createVolumeQueryKey = (options?: Options<CreateVolumeData>) =>
createQueryKey("createVolume", options);
/**
* Create a new volume
*/
export const createVolumeOptions = (options?: Options<CreateVolumeData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await createVolume({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: createVolumeQueryKey(options),
});
};
/**
* Create a new volume
*/
export const createVolumeMutation = (
options?: Partial<Options<CreateVolumeData>>,
): UseMutationOptions<
CreateVolumeResponse,
DefaultError,
Options<CreateVolumeData>
> => {
const mutationOptions: UseMutationOptions<
CreateVolumeResponse,
DefaultError,
Options<CreateVolumeData>
> = {
mutationFn: async (localOptions) => {
const { data } = await createVolume({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};

View File

@@ -2,8 +2,10 @@
import type { Options as ClientOptions, TDataShape, Client } from "./client";
import type {
GetApiV1VolumesData,
GetApiV1VolumesResponses,
ListVolumesData,
ListVolumesResponses,
CreateVolumeData,
CreateVolumeResponses,
} from "./types.gen";
import { client as _heyApiClient } from "./client.gen";
@@ -27,11 +29,11 @@ export type Options<
/**
* List all volumes
*/
export const getApiV1Volumes = <ThrowOnError extends boolean = false>(
options?: Options<GetApiV1VolumesData, ThrowOnError>,
export const listVolumes = <ThrowOnError extends boolean = false>(
options?: Options<ListVolumesData, ThrowOnError>,
) => {
return (options?.client ?? _heyApiClient).get<
GetApiV1VolumesResponses,
ListVolumesResponses,
unknown,
ThrowOnError
>({
@@ -39,3 +41,23 @@ export const getApiV1Volumes = <ThrowOnError extends boolean = false>(
...options,
});
};
/**
* Create a new volume
*/
export const createVolume = <ThrowOnError extends boolean = false>(
options?: Options<CreateVolumeData, ThrowOnError>,
) => {
return (options?.client ?? _heyApiClient).post<
CreateVolumeResponses,
unknown,
ThrowOnError
>({
url: "/api/v1/volumes",
...options,
headers: {
"Content-Type": "application/json",
...options?.headers,
},
});
};

View File

@@ -1,27 +1,64 @@
// This file is auto-generated by @hey-api/openapi-ts
export type GetApiV1VolumesData = {
export type ListVolumesData = {
body?: never;
path?: never;
query?: never;
url: "/api/v1/volumes";
};
export type GetApiV1VolumesResponses = {
export type ListVolumesResponses = {
/**
* A list of volumes
*/
200: {
volumes: Array<{
createdAt: string;
createdAt: number;
mountpoint: string;
name: string;
}>;
};
};
export type GetApiV1VolumesResponse =
GetApiV1VolumesResponses[keyof GetApiV1VolumesResponses];
export type ListVolumesResponse =
ListVolumesResponses[keyof ListVolumesResponses];
export type CreateVolumeData = {
body?: {
config:
| {
backend: "directory";
}
| {
backend: "nfs";
exportPath: string;
port: number;
server: string;
version: string;
}
| {
backend: "smb";
};
name: string;
};
path?: never;
query?: never;
url: "/api/v1/volumes";
};
export type CreateVolumeResponses = {
/**
* Volume created successfully
*/
201: {
createdAt: number;
mountpoint: string;
name: string;
};
};
export type CreateVolumeResponse =
CreateVolumeResponses[keyof CreateVolumeResponses];
export type ClientOptions = {
baseUrl: "http://localhost:3000" | (string & {});