import { URLPath } from '@kubb/core/utils' import type { Operation } from '@kubb/oas' import type { OperationSchemas } from '@kubb/plugin-oas' import { File, Function, FunctionParams, Type } from '@kubb/react-fabric' import type { KubbNode } from '@kubb/react-fabric/types' import type { PluginSvelteQuery, Transformer } from '../types' type Props = { name: string typeName: string typeSchemas: OperationSchemas operation: Operation paramsCasing: PluginSvelteQuery['resolvedOptions']['paramsCasing'] pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType'] transformer: Transformer | undefined } type GetParamsProps = { pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType'] typeSchemas: OperationSchemas } function getParams({}: GetParamsProps) { return FunctionParams.factory({}) } const getTransformer: Transformer = ({ operation, casing }) => { const path = new URLPath(operation.path, { casing }) return [`{ url: '${path.toURLPath()}' }`] } export function MutationKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): KubbNode { const params = getParams({ pathParamsType, typeSchemas }) const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing }) return ( <> {`[${keys.join(', ')}] as const`} {`ReturnType`} ) } MutationKey.getParams = getParams MutationKey.getTransformer = getTransformer