{"version":3,"file":"callQueryClientMethodWithQueryKey.cjs","sources":["../../../src/lib/callQueryClientMethodWithQueryKey.ts"],"sourcesContent":["import type { QueryClient } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport type { OperationSchema } from './requestFn.js';\nimport { composeInfiniteQueryKey } from './composeInfiniteQueryKey.js';\nimport { composeQueryKey } from './composeQueryKey.js';\n\n/**\n * Calls a query client method with parameters and options,\n * and automatically composes the `QueryKey` based on the schema and parameters.\n */\nexport function callQueryClientMethodWithQueryKey<\n  QFMethod extends QueryKeyMethods,\n>(\n  qraftOptions: CreateAPIQueryClientOptions,\n  queryClientMethod: QFMethod,\n  schema: OperationSchema,\n  infinite: boolean,\n  args: [...Parameters<(typeof QueryClient.prototype)[QFMethod]>, QueryClient]\n): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {\n  const parameters = args[0];\n\n  const queryKey = Array.isArray(parameters)\n    ? parameters\n    : infinite\n      ? composeInfiniteQueryKey(schema, parameters)\n      : composeQueryKey(schema, parameters);\n\n  const queryClient = qraftOptions.queryClient;\n\n  // @ts-expect-error - Too complex to type\n  return queryClient[queryClientMethod](\n    queryKey,\n    ...args.slice(1, args.length)\n  );\n}\n\ntype QueryKeyMethod<QFMethod extends keyof typeof QueryClient.prototype> =\n  QFMethod;\n\ntype QueryKeyMethods =\n  | QueryKeyMethod<'setQueryData'>\n  | QueryKeyMethod<'getQueryData'>\n  | QueryKeyMethod<'getQueryState'>\n  | QueryKeyMethod<'setQueryDefaults'>\n  | QueryKeyMethod<'getQueryDefaults'>;\n"],"names":["callQueryClientMethodWithQueryKey","qraftOptions","queryClientMethod","schema","infinite","args","parameters","queryKey","Array","isArray","composeInfiniteQueryKey","composeQueryKey","queryClient","slice","length"],"mappings":";;;;;AAMA;;;IAIO,SAASA,iCAAAA,CAGdC,YAAyC,EACzCC,iBAA2B,EAC3BC,MAAuB,EACvBC,QAAiB,EACjBC,IAA4E,EAAA;IAE5E,MAAMC,UAAAA,GAAaD,IAAI,CAAC,CAAE,CAAA,CAAA;IAE1B,MAAME,QAAAA,GAAWC,KAAMC,CAAAA,OAAO,CAACH,UAAAA,CAAAA,GAC3BA,UACAF,GAAAA,QAAAA,GACEM,+CAAwBP,CAAAA,MAAAA,EAAQG,UAChCK,CAAAA,GAAAA,+BAAAA,CAAgBR,MAAQG,EAAAA,UAAAA,CAAAA,CAAAA;IAE9B,MAAMM,WAAAA,GAAcX,aAAaW,WAAW,CAAA;;IAG5C,OAAOA,WAAW,CAACV,iBAAAA,CAAkB,CACnCK,QAAAA,EAAAA,GACGF,KAAKQ,KAAK,CAAC,CAAGR,EAAAA,IAAAA,CAAKS,MAAM,CAAA,CAAA,CAAA;AAEhC;;;;"}