@openapi-qraft/react
Version:
OpenAPI client for React, providing type-safe requests and dynamic TanStack Query React Hooks via a modular, Proxy-based architecture.
35 lines (33 loc) • 1.19 kB
text/typescript
import type {
ServiceOperationInfiniteQueryKey,
ServiceOperationQueryKey,
} from '@openapi-qraft/tanstack-query-react-types';
import type { OperationSchema } from './requestFn.js';
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
schema: TSchema,
parameters: TParams | undefined,
infinite: undefined
): [TSchema, TParams];
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
schema: TSchema,
parameters: TParams | undefined,
infinite: true
): ServiceOperationInfiniteQueryKey<TSchema, TParams>;
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
schema: TSchema,
parameters: TParams | undefined,
infinite: false
): ServiceOperationQueryKey<TSchema, TParams>;
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
schema: TSchema,
parameters: TParams | undefined,
infinite: boolean | undefined
):
| ServiceOperationQueryKey<TSchema, TParams>
| ServiceOperationInfiniteQueryKey<TSchema, TParams>
| [TSchema, TParams] {
return [
typeof infinite === 'boolean' ? { ...schema, infinite } : schema,
parameters ?? ({} as TParams),
];
}