@7nohe/openapi-react-query-codegen
Version:
OpenAPI React Query Codegen
67 lines (66 loc) • 3.45 kB
text/typescript
import { type TypeAliasDeclarationStructure, type VariableStatementStructure } from "ts-morph";
import type { GenerationContext, OperationInfo } from "../types.mjs";
/**
* Build the default response type alias.
* Example: export type FindPetsDefaultResponse = Awaited<ReturnType<typeof findPets>>["data"];
*/
export declare function buildDefaultResponseType(op: OperationInfo): TypeAliasDeclarationStructure;
/**
* Build the query result type alias.
* Example: export type FindPetsQueryResult<TData = FindPetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
*/
export declare function buildQueryResultType(op: OperationInfo): TypeAliasDeclarationStructure;
/**
* Build the mutation result type alias.
* Example: export type AddPetMutationResult = Awaited<ReturnType<typeof addPet>>;
*/
export declare function buildMutationResultType(op: OperationInfo): TypeAliasDeclarationStructure;
/**
* Build query key constant.
* Example: export const useFindPetsKey = "FindPets";
*/
export declare function buildQueryKeyConst(op: OperationInfo): VariableStatementStructure;
/**
* Build mutation key constant.
* Example: export const useAddPetKey = "AddPet";
*/
export declare function buildMutationKeyConst(op: OperationInfo): VariableStatementStructure;
/**
* Build query key function.
* Example: export const UseFindPetsKeyFn = (clientOptions: Options<FindPetsData, true> = {}, queryKey?: Array<unknown>) =>
* [useFindPetsKey, ...(queryKey ?? [clientOptions])];
*/
export declare function buildQueryKeyFn(op: OperationInfo): VariableStatementStructure;
/**
* Build mutation key function.
* Example: export const UseAddPetKeyFn = (mutationKey?: Array<unknown>) =>
* [useAddPetKey, ...(mutationKey ?? [])];
*/
export declare function buildMutationKeyFn(op: OperationInfo): VariableStatementStructure;
/**
* Build the client options type for infinite queries.
* The page parameter is excluded because TanStack Query supplies it via the
* pageParam mechanism (#140).
* Example:
* export type FindPaginatedPetsInfiniteClientOptions = Omit<Options<FindPaginatedPetsData, true>, "query"> &
* { query?: Omit<NonNullable<FindPaginatedPetsData["query"]>, "page"> };
*/
export declare function buildInfiniteClientOptionsType(op: OperationInfo, ctx: GenerationContext): TypeAliasDeclarationStructure;
/**
* Build the infinite query key constant.
* Shares the plain query key as its first segment so a single
* `invalidateQueries({ queryKey: [useXKey] })` matches both the plain and the
* infinite cache entries of an operation (#174), while the extra "infinite"
* segment keeps cached InfiniteData from colliding with plain query data (#140).
* Example: export const useFindPaginatedPetsInfiniteKey = [useFindPaginatedPetsKey, "infinite"] as const;
*/
export declare function buildInfiniteQueryKeyConst(op: OperationInfo): VariableStatementStructure;
/**
* Build the infinite query key function.
* The custom queryKey argument only replaces the params segment — the
* hierarchical [opKey, "infinite"] prefix is always preserved so
* prefix-based invalidation keeps working.
* Example: export const UseFindPaginatedPetsInfiniteKeyFn = (clientOptions: FindPaginatedPetsInfiniteClientOptions = {}, queryKey?: Array<unknown>) =>
* [...useFindPaginatedPetsInfiniteKey, ...(queryKey ?? [clientOptions])];
*/
export declare function buildInfiniteQueryKeyFn(op: OperationInfo): VariableStatementStructure;