feat: hey-api and projects fetch
This commit is contained in:
63
src/client/@tanstack/react-query.gen.ts
Normal file
63
src/client/@tanstack/react-query.gen.ts
Normal file
@ -0,0 +1,63 @@
|
||||
// This file is auto-generated by @hey-api/openapi-ts
|
||||
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
import { getProjects, type Options } from "../sdk.gen";
|
||||
import type { GetProjectsData } from "../types.gen";
|
||||
|
||||
export type QueryKey<TOptions extends Options> = [
|
||||
Pick<TOptions, "baseURL" | "body" | "headers" | "path" | "query"> & {
|
||||
_id: string;
|
||||
_infinite?: boolean;
|
||||
},
|
||||
];
|
||||
|
||||
const createQueryKey = <TOptions extends Options>(
|
||||
id: string,
|
||||
options?: TOptions,
|
||||
infinite?: boolean
|
||||
): [QueryKey<TOptions>[0]] => {
|
||||
const params: QueryKey<TOptions>[0] = {
|
||||
_id: id,
|
||||
baseURL:
|
||||
options?.baseURL ||
|
||||
(options?.client ?? _heyApiClient).getConfig().baseURL,
|
||||
} as QueryKey<TOptions>[0];
|
||||
if (infinite) {
|
||||
params._infinite = infinite;
|
||||
}
|
||||
if (options?.body) {
|
||||
params.body = options.body;
|
||||
}
|
||||
if (options?.headers) {
|
||||
params.headers = options.headers;
|
||||
}
|
||||
if (options?.path) {
|
||||
params.path = options.path;
|
||||
}
|
||||
if (options?.query) {
|
||||
params.query = options.query;
|
||||
}
|
||||
return [params];
|
||||
};
|
||||
|
||||
export const getProjectsQueryKey = (options?: Options<GetProjectsData>) =>
|
||||
createQueryKey("getProjects", options);
|
||||
|
||||
/**
|
||||
* Get Projects
|
||||
*/
|
||||
export const getProjectsOptions = (options?: Options<GetProjectsData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await getProjects({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: getProjectsQueryKey(options),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user