From 487d135609b6279946931460dfd68432a5922f44 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Wed, 6 Nov 2024 21:48:01 +0100 Subject: [PATCH] Fix/disable use query generation (#1374) * fix: allow disabling `useQuery` * fix: InfiniteData for react-query v5(disabled for v4) * chore: update examples * chore: upgrade packages * chore: update test cases --- .changeset/serious-bottles-drum.md | 6 + .changeset/stupid-trees-sip.md | 5 + docs/.vitepress/config.ts | 2 +- docs/blog/v3.md | 2 +- docs/changelog.md | 5 + e2e/package.json | 8 +- examples/advanced/package.json | 10 +- .../useFindPetsByTagsInfinite.ts | 4 +- examples/react-query/kubb.config.ts | 4 + examples/react-query/package.json | 4 +- examples/react-query/src/gen/hooks/index.ts | 2 + .../hooks/useFindPetsByTagsInfiniteHook.ts | 4 +- .../gen/hooks/useGetInventorySuspenseHook.ts | 58 ++++++ examples/react-query/src/gen/index.ts | 2 + examples/simple-single/package.json | 2 +- examples/simple-single/src/gen2/index.ts | 1 + examples/solid-query/kubb.config.js | 1 + examples/solid-query/package.json | 2 +- .../src/gen/hooks/createFindPetsByStatus.ts | 33 +--- .../src/gen/hooks/createFindPetsByTags.ts | 35 +--- .../src/gen/hooks/createGetInventory.ts | 32 +--- .../src/gen/hooks/createGetOrderById.ts | 33 +--- .../src/gen/hooks/createGetPetById.ts | 29 +-- .../src/gen/hooks/createGetUserByName.ts | 32 +--- .../src/gen/hooks/createLoginUser.ts | 28 +-- .../src/gen/hooks/createLogoutUser.ts | 27 +-- examples/solid-query/src/gen/hooks/index.ts | 16 +- examples/solid-query/src/gen/index.ts | 16 +- examples/svelte-query/package.json | 2 +- examples/vue-query/package.json | 2 +- packages/plugin-react-query/package.json | 3 +- .../src/components/InfiniteQuery.tsx | 2 +- .../__snapshots__/findInfiniteByTags.ts | 4 +- .../__snapshots__/findInfiniteByTagsCursor.ts | 4 +- .../src/generators/infiniteQueryGenerator.tsx | 12 +- .../src/generators/mutationGenerator.tsx | 7 +- .../src/generators/queryGenerator.tsx | 7 +- .../src/generators/suspenseQueryGenerator.tsx | 13 +- packages/plugin-react-query/src/plugin.ts | 13 +- packages/plugin-solid-query/package.json | 3 +- .../src/generators/queryGenerator.tsx | 4 +- packages/plugin-solid-query/src/plugin.ts | 13 +- packages/plugin-svelte-query/package.json | 3 +- .../src/generators/mutationGenerator.tsx | 7 +- .../src/generators/queryGenerator.tsx | 6 +- packages/plugin-svelte-query/src/plugin.ts | 13 +- packages/plugin-swr/package.json | 3 +- .../src/generators/mutationGenerator.tsx | 7 +- .../src/generators/queryGenerator.tsx | 8 +- packages/plugin-swr/src/plugin.ts | 13 +- packages/plugin-vue-query/package.json | 3 +- .../src/components/InfiniteQuery.tsx | 2 +- .../__snapshots__/findInfiniteByTags.ts | 4 +- .../__snapshots__/findInfiniteByTagsCursor.ts | 4 +- .../src/generators/infiniteQueryGenerator.tsx | 10 +- .../src/generators/mutationGenerator.tsx | 7 +- .../src/generators/queryGenerator.tsx | 6 +- packages/plugin-vue-query/src/plugin.ts | 13 +- packages/unplugin-kubb/package.json | 4 +- pnpm-lock.yaml | 165 ++++++++++-------- 60 files changed, 353 insertions(+), 417 deletions(-) create mode 100644 .changeset/serious-bottles-drum.md create mode 100644 .changeset/stupid-trees-sip.md create mode 100644 examples/react-query/src/gen/hooks/useGetInventorySuspenseHook.ts diff --git a/.changeset/serious-bottles-drum.md b/.changeset/serious-bottles-drum.md new file mode 100644 index 000000000..63249ea32 --- /dev/null +++ b/.changeset/serious-bottles-drum.md @@ -0,0 +1,6 @@ +--- +"@kubb/plugin-react-query": patch +"@kubb/plugin-vue-query": patch +--- + +InfiniteData for react-query v5(disabled for v4) diff --git a/.changeset/stupid-trees-sip.md b/.changeset/stupid-trees-sip.md new file mode 100644 index 000000000..ce3d5ea2c --- /dev/null +++ b/.changeset/stupid-trees-sip.md @@ -0,0 +1,5 @@ +--- +"@kubb/plugin-react-query": patch +--- + +allow disabling `useQuery` diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 694a90d7b..addf10397 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -45,7 +45,7 @@ const knowledgeBaseSidebar = [ { text: 'Kubb Plugins', link: '/knowledge-base/plugins/', - } + }, // { // text: 'Plugins', // collapsed: false, diff --git a/docs/blog/v3.md b/docs/blog/v3.md index 4aace7bb1..d14cd5697 100644 --- a/docs/blog/v3.md +++ b/docs/blog/v3.md @@ -31,7 +31,7 @@ We’re excited to announce the release of Kubb v3, a major update that brings s In this post, we’ll dive into the key features of Kubb v3 and explore what’s new. ## What is Kubb? -For those unfamiliar with Kubb, it’s a flexible framework built to automate code generation based on Swagger/OpenApi spec file. Kubb simplifies your workflow by creating API clients, generating type-safe code, Zod schema's, React-Query code, ... +For those unfamiliar with Kubb, it’s a flexible framework built to automate code generation based on Swagger/OpenAPI spec file. Kubb simplifies your workflow by creating API clients, generating type-safe code, Zod schema's, React-Query code, ... By integrating with tools like OpenAPI, Kubb ensures that your code remains aligned with your API specifications, reducing the risk of errors and improving maintainability. diff --git a/docs/changelog.md b/docs/changelog.md index 020e3dc44..839a4afe5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ title: Changelog # Changelog +## 3.0.1 +- [`plugin-react-query`](/plugins/plugin-react-query/): allow disabling `useQuery` +- [`plugin-react-query`](/plugins/plugin-react-query/): use of `InfiniteData` TypeScript helper for infiniteQueries +- [`plugin-vue-query`](/plugins/plugin-vue-query/): use of `InfiniteData` TypeScript helper for infiniteQueries + ## 3.0.0-beta.12 - [`plugin-react-query`](/plugins/plugin-react-query/): allow to disable the generation of useQuery or createQuery hooks. - [`plugin-svelte-query`](/plugins/plugin-svelte-query/): allow to disable the generation of useQuery or createQuery hooks. diff --git a/e2e/package.json b/e2e/package.json index 62a81790d..2c970a25a 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -32,10 +32,10 @@ "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", "@kubb/react": "workspace:*", - "@tanstack/react-query": "^5.59.19", - "@tanstack/solid-query": "^5.59.17", - "@tanstack/svelte-query": "^5.59.17", - "@tanstack/vue-query": "^5.59.17", + "@tanstack/react-query": "^5.59.20", + "@tanstack/solid-query": "^5.59.20", + "@tanstack/svelte-query": "^5.59.20", + "@tanstack/vue-query": "^5.59.20", "axios": "^1.7.7", "msw": "^2.6.0", "react": "^18.3.1", diff --git a/examples/advanced/package.json b/examples/advanced/package.json index ad5860421..1766ef5a5 100644 --- a/examples/advanced/package.json +++ b/examples/advanced/package.json @@ -38,11 +38,11 @@ "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", "@kubb/react": "workspace:*", - "@tanstack/query-core": "^5.59.17", - "@tanstack/react-query": "^5.59.19", - "@tanstack/solid-query": "^5.59.17", - "@tanstack/svelte-query": "^5.59.17", - "@tanstack/vue-query": "^5.59.17", + "@tanstack/query-core": "^5.59.20", + "@tanstack/react-query": "^5.59.20", + "@tanstack/solid-query": "^5.59.20", + "@tanstack/svelte-query": "^5.59.20", + "@tanstack/vue-query": "^5.59.20", "axios": "^1.7.7", "msw": "^2.6.0", "react": "^18.3.1", diff --git a/examples/advanced/src/gen/clients/hooks/petController/useFindPetsByTagsInfinite.ts b/examples/advanced/src/gen/clients/hooks/petController/useFindPetsByTagsInfinite.ts index 6d57c1122..600bf35fe 100644 --- a/examples/advanced/src/gen/clients/hooks/petController/useFindPetsByTagsInfinite.ts +++ b/examples/advanced/src/gen/clients/hooks/petController/useFindPetsByTagsInfinite.ts @@ -1,6 +1,6 @@ import client from '../../../../tanstack-query-client.ts' import type { RequestConfig, ResponseConfig } from '../../../../tanstack-query-client.ts' -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from '../../../../tanstack-query-hook.ts' +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from '../../../../tanstack-query-hook.ts' import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, @@ -71,7 +71,7 @@ export function findPetsByTagsInfiniteQueryOptions( * @link /pet/findByTags */ export function useFindPetsByTagsInfinite< - TData = ResponseConfig, + TData = InfiniteData>, TQueryData = ResponseConfig, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey, >( diff --git a/examples/react-query/kubb.config.ts b/examples/react-query/kubb.config.ts index 5fe734bf7..8db408806 100644 --- a/examples/react-query/kubb.config.ts +++ b/examples/react-query/kubb.config.ts @@ -74,6 +74,10 @@ export const config = { importPath: '@tanstack/react-query', methods: ['post'], }, + mutation: { + importPath: '@tanstack/react-query', + methods: ['put', 'delete'], + }, pathParamsType: 'inline', }, }, diff --git a/examples/react-query/package.json b/examples/react-query/package.json index a0b9f6ae7..213ff8df6 100644 --- a/examples/react-query/package.json +++ b/examples/react-query/package.json @@ -29,8 +29,8 @@ "@kubb/plugin-react-query": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/react": "workspace:*", - "@tanstack/react-query": "^5.59.19", - "@tanstack/react-query-devtools": "^5.59.19", + "@tanstack/react-query": "^5.59.20", + "@tanstack/react-query-devtools": "^5.59.20", "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/examples/react-query/src/gen/hooks/index.ts b/examples/react-query/src/gen/hooks/index.ts index 4728984fa..2d940c575 100644 --- a/examples/react-query/src/gen/hooks/index.ts +++ b/examples/react-query/src/gen/hooks/index.ts @@ -10,6 +10,7 @@ export type { FindPetsByTagsQueryKey } from './useFindPetsByTagsHook.ts' export type { FindPetsByTagsInfiniteQueryKey } from './useFindPetsByTagsInfiniteHook.ts' export type { FindPetsByTagsSuspenseQueryKey } from './useFindPetsByTagsSuspenseHook.ts' export type { GetInventoryQueryKey } from './useGetInventoryHook.ts' +export type { GetInventorySuspenseQueryKey } from './useGetInventorySuspenseHook.ts' export type { GetOrderByIdQueryKey } from './useGetOrderByIdHook.ts' export type { GetOrderByIdSuspenseQueryKey } from './useGetOrderByIdSuspenseHook.ts' export type { GetPetByIdQueryKey } from './useGetPetByIdHook.ts' @@ -43,6 +44,7 @@ export { findPetsByTagsQueryKey, findPetsByTagsQueryOptionsHook, useFindPetsByTa export { findPetsByTagsInfiniteQueryKey, findPetsByTagsInfiniteQueryOptionsHook, useFindPetsByTagsInfiniteHook } from './useFindPetsByTagsInfiniteHook.ts' export { findPetsByTagsSuspenseQueryKey, findPetsByTagsSuspenseQueryOptionsHook, useFindPetsByTagsSuspenseHook } from './useFindPetsByTagsSuspenseHook.ts' export { getInventoryQueryKey, getInventoryQueryOptionsHook } from './useGetInventoryHook.ts' +export { getInventorySuspenseQueryKey, getInventorySuspenseQueryOptionsHook, useGetInventorySuspenseHook } from './useGetInventorySuspenseHook.ts' export { getOrderByIdQueryKey, getOrderByIdQueryOptionsHook, useGetOrderByIdHook } from './useGetOrderByIdHook.ts' export { getOrderByIdSuspenseQueryKey, getOrderByIdSuspenseQueryOptionsHook, useGetOrderByIdSuspenseHook } from './useGetOrderByIdSuspenseHook.ts' export { getPetByIdQueryKey, getPetByIdQueryOptionsHook, useGetPetByIdHook } from './useGetPetByIdHook.ts' diff --git a/examples/react-query/src/gen/hooks/useFindPetsByTagsInfiniteHook.ts b/examples/react-query/src/gen/hooks/useFindPetsByTagsInfiniteHook.ts index b6650d2f2..0507bc08a 100644 --- a/examples/react-query/src/gen/hooks/useFindPetsByTagsInfiniteHook.ts +++ b/examples/react-query/src/gen/hooks/useFindPetsByTagsInfiniteHook.ts @@ -1,7 +1,7 @@ import client from '@kubb/plugin-client/client' import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from '../models/FindPetsByTags.ts' import type { RequestConfig, ResponseConfig } from '@kubb/plugin-client/client' -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from '@tanstack/react-query' +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from '@tanstack/react-query' import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query' export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => ['v5', { url: '/pet/findByTags' }, ...(params ? [params] : [])] as const @@ -41,7 +41,7 @@ export function findPetsByTagsInfiniteQueryOptionsHook(params?: FindPetsByTagsQu * @link /pet/findByTags */ export function useFindPetsByTagsInfiniteHook< - TData = ResponseConfig, + TData = InfiniteData>, TQueryData = ResponseConfig, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey, >( diff --git a/examples/react-query/src/gen/hooks/useGetInventorySuspenseHook.ts b/examples/react-query/src/gen/hooks/useGetInventorySuspenseHook.ts new file mode 100644 index 000000000..77db433c7 --- /dev/null +++ b/examples/react-query/src/gen/hooks/useGetInventorySuspenseHook.ts @@ -0,0 +1,58 @@ +import client from '@kubb/plugin-client/client' +import type { GetInventoryQueryResponse } from '../models/GetInventory.ts' +import type { RequestConfig } from '@kubb/plugin-client/client' +import type { QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' +import { queryOptions, useSuspenseQuery } from '@tanstack/react-query' + +export const getInventorySuspenseQueryKey = () => ['v5', { url: '/store/inventory' }] as const + +export type GetInventorySuspenseQueryKey = ReturnType + +/** + * @description Returns a map of status codes to quantities + * @summary Returns pet inventories by status + * @link /store/inventory + */ +async function getInventory(config: Partial = {}) { + const res = await client({ method: 'GET', url: '/store/inventory', ...config }) + return res.data +} + +export function getInventorySuspenseQueryOptionsHook(config: Partial = {}) { + const queryKey = getInventorySuspenseQueryKey() + return queryOptions({ + queryKey, + queryFn: async ({ signal }) => { + config.signal = signal + return getInventory(config) + }, + }) +} + +/** + * @description Returns a map of status codes to quantities + * @summary Returns pet inventories by status + * @link /store/inventory + */ +export function useGetInventorySuspenseHook< + TData = GetInventoryQueryResponse, + TQueryData = GetInventoryQueryResponse, + TQueryKey extends QueryKey = GetInventorySuspenseQueryKey, +>( + options: { + query?: Partial> + client?: Partial + } = {}, +) { + const { query: queryOptions, client: config = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getInventorySuspenseQueryKey() + const query = useSuspenseQuery({ + ...(getInventorySuspenseQueryOptionsHook(config) as unknown as UseSuspenseQueryOptions), + queryKey, + ...(queryOptions as unknown as Omit), + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query/src/gen/index.ts b/examples/react-query/src/gen/index.ts index d1c97db85..278a11ff8 100644 --- a/examples/react-query/src/gen/index.ts +++ b/examples/react-query/src/gen/index.ts @@ -10,6 +10,7 @@ export type { FindPetsByTagsQueryKey } from './hooks/useFindPetsByTagsHook.ts' export type { FindPetsByTagsInfiniteQueryKey } from './hooks/useFindPetsByTagsInfiniteHook.ts' export type { FindPetsByTagsSuspenseQueryKey } from './hooks/useFindPetsByTagsSuspenseHook.ts' export type { GetInventoryQueryKey } from './hooks/useGetInventoryHook.ts' +export type { GetInventorySuspenseQueryKey } from './hooks/useGetInventorySuspenseHook.ts' export type { GetOrderByIdQueryKey } from './hooks/useGetOrderByIdHook.ts' export type { GetOrderByIdSuspenseQueryKey } from './hooks/useGetOrderByIdSuspenseHook.ts' export type { GetPetByIdQueryKey } from './hooks/useGetPetByIdHook.ts' @@ -134,6 +135,7 @@ export { findPetsByTagsQueryKey, findPetsByTagsQueryOptionsHook, useFindPetsByTa export { findPetsByTagsInfiniteQueryKey, findPetsByTagsInfiniteQueryOptionsHook, useFindPetsByTagsInfiniteHook } from './hooks/useFindPetsByTagsInfiniteHook.ts' export { findPetsByTagsSuspenseQueryKey, findPetsByTagsSuspenseQueryOptionsHook, useFindPetsByTagsSuspenseHook } from './hooks/useFindPetsByTagsSuspenseHook.ts' export { getInventoryQueryKey, getInventoryQueryOptionsHook } from './hooks/useGetInventoryHook.ts' +export { getInventorySuspenseQueryKey, getInventorySuspenseQueryOptionsHook, useGetInventorySuspenseHook } from './hooks/useGetInventorySuspenseHook.ts' export { getOrderByIdQueryKey, getOrderByIdQueryOptionsHook, useGetOrderByIdHook } from './hooks/useGetOrderByIdHook.ts' export { getOrderByIdSuspenseQueryKey, getOrderByIdSuspenseQueryOptionsHook, useGetOrderByIdSuspenseHook } from './hooks/useGetOrderByIdSuspenseHook.ts' export { getPetByIdQueryKey, getPetByIdQueryOptionsHook, useGetPetByIdHook } from './hooks/useGetPetByIdHook.ts' diff --git a/examples/simple-single/package.json b/examples/simple-single/package.json index 2cc78c841..fd51dc3da 100644 --- a/examples/simple-single/package.json +++ b/examples/simple-single/package.json @@ -31,7 +31,7 @@ "@kubb/plugin-redoc": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@tanstack/react-query": "^5.59.19", + "@tanstack/react-query": "^5.59.20", "axios": "^1.7.7", "react": "^18.3.1", "tsup": "^8.3.5", diff --git a/examples/simple-single/src/gen2/index.ts b/examples/simple-single/src/gen2/index.ts index 5c7302033..6e3340fdf 100644 --- a/examples/simple-single/src/gen2/index.ts +++ b/examples/simple-single/src/gen2/index.ts @@ -540,6 +540,7 @@ export const machinesListQueryParamsSchema = z .object({ include_deleted: z.boolean().describe('Include deleted machines').optional(), region: z.string().describe('Region filter').optional(), + state: z.string().describe('comma separated list of states to filter (created, started, stopped, suspended)').optional(), summary: z.boolean().describe('Only return summary info about machines (omit config, checks, events, host_status, nonce, etc.)').optional(), }) .optional() diff --git a/examples/solid-query/kubb.config.js b/examples/solid-query/kubb.config.js index 9535b1895..85eff7c43 100644 --- a/examples/solid-query/kubb.config.js +++ b/examples/solid-query/kubb.config.js @@ -26,6 +26,7 @@ export default defineConfig({ output: { path: './hooks', }, + query: false, override: [ { type: 'operationId', diff --git a/examples/solid-query/package.json b/examples/solid-query/package.json index 176d999c9..89820aeb7 100644 --- a/examples/solid-query/package.json +++ b/examples/solid-query/package.json @@ -27,7 +27,7 @@ "@kubb/plugin-solid-query": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@tanstack/solid-query": "^5.59.17", + "@tanstack/solid-query": "^5.59.20", "axios": "^1.7.7", "solid-js": "^1.9.3", "tsup": "^8.3.5" diff --git a/examples/solid-query/src/gen/hooks/createFindPetsByStatus.ts b/examples/solid-query/src/gen/hooks/createFindPetsByStatus.ts index 2bdb61399..7a5d22b3c 100644 --- a/examples/solid-query/src/gen/hooks/createFindPetsByStatus.ts +++ b/examples/solid-query/src/gen/hooks/createFindPetsByStatus.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../models/FindPetsByStatus.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const findPetsByStatusQueryKey = (params?: FindPetsByStatusQueryParams) => [{ url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const @@ -28,33 +27,3 @@ export function findPetsByStatusQueryOptions(params?: FindPetsByStatusQueryParam }, }) } - -/** - * @description Multiple status values can be provided with comma separated strings - * @summary Finds Pets by status - * @link /pet/findByStatus - */ -export function createFindPetsByStatus< - TData = FindPetsByStatusQueryResponse, - TQueryData = FindPetsByStatusQueryResponse, - TQueryKey extends QueryKey = FindPetsByStatusQueryKey, ->( - params?: FindPetsByStatusQueryParams, - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? findPetsByStatusQueryKey(params) - const query = createQuery(() => ({ - ...(findPetsByStatusQueryOptions(params, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createFindPetsByTags.ts b/examples/solid-query/src/gen/hooks/createFindPetsByTags.ts index e87435e24..b1db185a4 100644 --- a/examples/solid-query/src/gen/hooks/createFindPetsByTags.ts +++ b/examples/solid-query/src/gen/hooks/createFindPetsByTags.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from '../models/FindPetsByTags.ts' -import type { RequestConfig, ResponseConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import type { RequestConfig } from '@kubb/plugin-client/client' +import { queryOptions } from '@tanstack/solid-query' export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const @@ -28,33 +27,3 @@ export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, c }, }) } - -/** - * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @link /pet/findByTags - */ -export function createFindPetsByTags< - TData = ResponseConfig, - TQueryData = ResponseConfig, - TQueryKey extends QueryKey = FindPetsByTagsQueryKey, ->( - params?: FindPetsByTagsQueryParams, - options: { - query?: Partial, FindPetsByTags400, TData, TQueryData, TQueryKey>> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) - const query = createQuery(() => ({ - ...(findPetsByTagsQueryOptions(params, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createGetInventory.ts b/examples/solid-query/src/gen/hooks/createGetInventory.ts index bf7b8b06d..3b9aa0682 100644 --- a/examples/solid-query/src/gen/hooks/createGetInventory.ts +++ b/examples/solid-query/src/gen/hooks/createGetInventory.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { GetInventoryQueryResponse } from '../models/GetInventory.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const getInventoryQueryKey = () => [{ url: '/store/inventory' }] as const @@ -28,32 +27,3 @@ export function getInventoryQueryOptions(config: Partial = {}) { }, }) } - -/** - * @description Returns a map of status codes to quantities - * @summary Returns pet inventories by status - * @link /store/inventory - */ -export function createGetInventory< - TData = GetInventoryQueryResponse, - TQueryData = GetInventoryQueryResponse, - TQueryKey extends QueryKey = GetInventoryQueryKey, ->( - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? getInventoryQueryKey() - const query = createQuery(() => ({ - ...(getInventoryQueryOptions(config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createGetOrderById.ts b/examples/solid-query/src/gen/hooks/createGetOrderById.ts index d53838bf6..10b325e8a 100644 --- a/examples/solid-query/src/gen/hooks/createGetOrderById.ts +++ b/examples/solid-query/src/gen/hooks/createGetOrderById.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from '../models/GetOrderById.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const getOrderByIdQueryKey = (orderId: GetOrderByIdPathParams['orderId']) => [{ url: '/store/order/:orderId', params: { orderId: orderId } }] as const @@ -29,33 +28,3 @@ export function getOrderByIdQueryOptions(orderId: GetOrderByIdPathParams['orderI }, }) } - -/** - * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. - * @summary Find purchase order by ID - * @link /store/order/:orderId - */ -export function createGetOrderById< - TData = GetOrderByIdQueryResponse, - TQueryData = GetOrderByIdQueryResponse, - TQueryKey extends QueryKey = GetOrderByIdQueryKey, ->( - orderId: GetOrderByIdPathParams['orderId'], - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? getOrderByIdQueryKey(orderId) - const query = createQuery(() => ({ - ...(getOrderByIdQueryOptions(orderId, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createGetPetById.ts b/examples/solid-query/src/gen/hooks/createGetPetById.ts index ed47b718e..e05b10d2b 100644 --- a/examples/solid-query/src/gen/hooks/createGetPetById.ts +++ b/examples/solid-query/src/gen/hooks/createGetPetById.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../models/GetPetById.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const getPetByIdQueryKey = (petId: GetPetByIdPathParams['petId']) => [{ url: '/pet/:petId', params: { petId: petId } }] as const @@ -29,29 +28,3 @@ export function getPetByIdQueryOptions(petId: GetPetByIdPathParams['petId'], con }, }) } - -/** - * @description Returns a single pet - * @summary Find pet by ID - * @link /pet/:petId - */ -export function createGetPetById( - petId: GetPetByIdPathParams['petId'], - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey(petId) - const query = createQuery(() => ({ - ...(getPetByIdQueryOptions(petId, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createGetUserByName.ts b/examples/solid-query/src/gen/hooks/createGetUserByName.ts index 2e20b5d15..aeecad985 100644 --- a/examples/solid-query/src/gen/hooks/createGetUserByName.ts +++ b/examples/solid-query/src/gen/hooks/createGetUserByName.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { GetUserByNameQueryResponse, GetUserByNamePathParams, GetUserByName400, GetUserByName404 } from '../models/GetUserByName.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const getUserByNameQueryKey = (username: GetUserByNamePathParams['username']) => [{ url: '/user/:username', params: { username: username } }] as const @@ -28,32 +27,3 @@ export function getUserByNameQueryOptions(username: GetUserByNamePathParams['use }, }) } - -/** - * @summary Get user by user name - * @link /user/:username - */ -export function createGetUserByName< - TData = GetUserByNameQueryResponse, - TQueryData = GetUserByNameQueryResponse, - TQueryKey extends QueryKey = GetUserByNameQueryKey, ->( - username: GetUserByNamePathParams['username'], - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? getUserByNameQueryKey(username) - const query = createQuery(() => ({ - ...(getUserByNameQueryOptions(username, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createLoginUser.ts b/examples/solid-query/src/gen/hooks/createLoginUser.ts index 87665e3c5..61c7cd0ad 100644 --- a/examples/solid-query/src/gen/hooks/createLoginUser.ts +++ b/examples/solid-query/src/gen/hooks/createLoginUser.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from '../models/LoginUser.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const loginUserQueryKey = (params?: LoginUserQueryParams) => [{ url: '/user/login' }, ...(params ? [params] : [])] as const @@ -27,28 +26,3 @@ export function loginUserQueryOptions(params?: LoginUserQueryParams, config: Par }, }) } - -/** - * @summary Logs user into the system - * @link /user/login - */ -export function createLoginUser( - params?: LoginUserQueryParams, - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? loginUserQueryKey(params) - const query = createQuery(() => ({ - ...(loginUserQueryOptions(params, config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/createLogoutUser.ts b/examples/solid-query/src/gen/hooks/createLogoutUser.ts index a14004b01..07181a88f 100644 --- a/examples/solid-query/src/gen/hooks/createLogoutUser.ts +++ b/examples/solid-query/src/gen/hooks/createLogoutUser.ts @@ -1,8 +1,7 @@ import client from '@kubb/plugin-client/client' import type { LogoutUserQueryResponse } from '../models/LogoutUser.ts' import type { RequestConfig } from '@kubb/plugin-client/client' -import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from '@tanstack/solid-query' -import { queryOptions, createQuery } from '@tanstack/solid-query' +import { queryOptions } from '@tanstack/solid-query' export const logoutUserQueryKey = () => [{ url: '/user/logout' }] as const @@ -27,27 +26,3 @@ export function logoutUserQueryOptions(config: Partial = {}) { }, }) } - -/** - * @summary Logs out current logged in user session - * @link /user/logout - */ -export function createLogoutUser( - options: { - query?: Partial> - client?: Partial - } = {}, -) { - const { query: queryOptions, client: config = {} } = options ?? {} - const queryKey = queryOptions?.queryKey ?? logoutUserQueryKey() - const query = createQuery(() => ({ - ...(logoutUserQueryOptions(config) as unknown as CreateBaseQueryOptions), - queryKey, - initialData: null, - ...(queryOptions as unknown as Omit), - })) as CreateQueryResult & { - queryKey: TQueryKey - } - query.queryKey = queryKey as TQueryKey - return query -} diff --git a/examples/solid-query/src/gen/hooks/index.ts b/examples/solid-query/src/gen/hooks/index.ts index 1824b2482..4616de452 100644 --- a/examples/solid-query/src/gen/hooks/index.ts +++ b/examples/solid-query/src/gen/hooks/index.ts @@ -7,12 +7,12 @@ export type { GetUserByNameQueryKey } from './createGetUserByName.ts' export type { LoginUserQueryKey } from './createLoginUser.ts' export type { LogoutUserQueryKey } from './createLogoutUser.ts' export type { UpdatePetWithFormQueryKey } from './createUpdatePetWithForm.ts' -export { findPetsByStatusQueryKey, findPetsByStatusQueryOptions, createFindPetsByStatus } from './createFindPetsByStatus.ts' -export { findPetsByTagsQueryKey, findPetsByTagsQueryOptions, createFindPetsByTags } from './createFindPetsByTags.ts' -export { getInventoryQueryKey, getInventoryQueryOptions, createGetInventory } from './createGetInventory.ts' -export { getOrderByIdQueryKey, getOrderByIdQueryOptions, createGetOrderById } from './createGetOrderById.ts' -export { getPetByIdQueryKey, getPetByIdQueryOptions, createGetPetById } from './createGetPetById.ts' -export { getUserByNameQueryKey, getUserByNameQueryOptions, createGetUserByName } from './createGetUserByName.ts' -export { loginUserQueryKey, loginUserQueryOptions, createLoginUser } from './createLoginUser.ts' -export { logoutUserQueryKey, logoutUserQueryOptions, createLogoutUser } from './createLogoutUser.ts' +export { findPetsByStatusQueryKey, findPetsByStatusQueryOptions } from './createFindPetsByStatus.ts' +export { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from './createFindPetsByTags.ts' +export { getInventoryQueryKey, getInventoryQueryOptions } from './createGetInventory.ts' +export { getOrderByIdQueryKey, getOrderByIdQueryOptions } from './createGetOrderById.ts' +export { getPetByIdQueryKey, getPetByIdQueryOptions } from './createGetPetById.ts' +export { getUserByNameQueryKey, getUserByNameQueryOptions } from './createGetUserByName.ts' +export { loginUserQueryKey, loginUserQueryOptions } from './createLoginUser.ts' +export { logoutUserQueryKey, logoutUserQueryOptions } from './createLogoutUser.ts' export { updatePetWithFormQueryKey, updatePetWithFormQueryOptions, createUpdatePetWithForm } from './createUpdatePetWithForm.ts' diff --git a/examples/solid-query/src/gen/index.ts b/examples/solid-query/src/gen/index.ts index 44fba80ea..0547d23d0 100644 --- a/examples/solid-query/src/gen/index.ts +++ b/examples/solid-query/src/gen/index.ts @@ -98,14 +98,14 @@ export type { } from './models/UploadFile.ts' export type { User } from './models/User.ts' export type { UserArray } from './models/UserArray.ts' -export { findPetsByStatusQueryKey, findPetsByStatusQueryOptions, createFindPetsByStatus } from './hooks/createFindPetsByStatus.ts' -export { findPetsByTagsQueryKey, findPetsByTagsQueryOptions, createFindPetsByTags } from './hooks/createFindPetsByTags.ts' -export { getInventoryQueryKey, getInventoryQueryOptions, createGetInventory } from './hooks/createGetInventory.ts' -export { getOrderByIdQueryKey, getOrderByIdQueryOptions, createGetOrderById } from './hooks/createGetOrderById.ts' -export { getPetByIdQueryKey, getPetByIdQueryOptions, createGetPetById } from './hooks/createGetPetById.ts' -export { getUserByNameQueryKey, getUserByNameQueryOptions, createGetUserByName } from './hooks/createGetUserByName.ts' -export { loginUserQueryKey, loginUserQueryOptions, createLoginUser } from './hooks/createLoginUser.ts' -export { logoutUserQueryKey, logoutUserQueryOptions, createLogoutUser } from './hooks/createLogoutUser.ts' +export { findPetsByStatusQueryKey, findPetsByStatusQueryOptions } from './hooks/createFindPetsByStatus.ts' +export { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from './hooks/createFindPetsByTags.ts' +export { getInventoryQueryKey, getInventoryQueryOptions } from './hooks/createGetInventory.ts' +export { getOrderByIdQueryKey, getOrderByIdQueryOptions } from './hooks/createGetOrderById.ts' +export { getPetByIdQueryKey, getPetByIdQueryOptions } from './hooks/createGetPetById.ts' +export { getUserByNameQueryKey, getUserByNameQueryOptions } from './hooks/createGetUserByName.ts' +export { loginUserQueryKey, loginUserQueryOptions } from './hooks/createLoginUser.ts' +export { logoutUserQueryKey, logoutUserQueryOptions } from './hooks/createLogoutUser.ts' export { updatePetWithFormQueryKey, updatePetWithFormQueryOptions, createUpdatePetWithForm } from './hooks/createUpdatePetWithForm.ts' export { addPetRequestStatusEnum } from './models/AddPetRequest.ts' export { findPetsByStatusQueryParamsStatusEnum } from './models/FindPetsByStatus.ts' diff --git a/examples/svelte-query/package.json b/examples/svelte-query/package.json index 6ed22d2b2..88abce4e6 100644 --- a/examples/svelte-query/package.json +++ b/examples/svelte-query/package.json @@ -27,7 +27,7 @@ "@kubb/plugin-svelte-query": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@tanstack/svelte-query": "^5.59.17", + "@tanstack/svelte-query": "^5.59.20", "axios": "^1.7.7", "svelte": "^3.59.2", "tsup": "^8.3.5" diff --git a/examples/vue-query/package.json b/examples/vue-query/package.json index 4b1325389..b175acc4c 100644 --- a/examples/vue-query/package.json +++ b/examples/vue-query/package.json @@ -29,7 +29,7 @@ "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-vue-query": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@tanstack/vue-query": "^5.59.17", + "@tanstack/vue-query": "^5.59.20", "axios": "^1.7.7", "unplugin-kubb": "workspace:*", "vue": "^3.5.12" diff --git a/packages/plugin-react-query/package.json b/packages/plugin-react-query/package.json index 586281387..4b54ccacc 100644 --- a/packages/plugin-react-query/package.json +++ b/packages/plugin-react-query/package.json @@ -79,7 +79,8 @@ "@kubb/plugin-oas": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@kubb/react": "workspace:*" + "@kubb/react": "workspace:*", + "remeda": "^2.16.0" }, "devDependencies": { "@kubb/config-ts": "workspace:*", diff --git a/packages/plugin-react-query/src/components/InfiniteQuery.tsx b/packages/plugin-react-query/src/components/InfiniteQuery.tsx index d1b3ed451..212f07549 100644 --- a/packages/plugin-react-query/src/components/InfiniteQuery.tsx +++ b/packages/plugin-react-query/src/components/InfiniteQuery.tsx @@ -123,7 +123,7 @@ export function InfiniteQuery({ }: Props): ReactNode { const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>` const returnType = `UseInfiniteQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }` - const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] + const generics = [`TData = InfiniteData<${TData}>`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] const queryKeyParams = QueryKey.getParams({ pathParamsType, diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTags.ts b/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTags.ts index 240a090a2..76d865063 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTags.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTags.ts @@ -1,6 +1,6 @@ import client from "@kubb/plugin-client/client"; import type { RequestConfig } from "@kubb/plugin-client/client"; -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query"; +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query"; import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query"; export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const; @@ -39,7 +39,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find * @summary Finds Pets by tags * @link /pet/findByTags */ -export function useFindPetsByTagsInfinite(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: { +export function useFindPetsByTagsInfinite, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: { query?: Partial>; client?: Partial; } = {}) { diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts b/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts index ee1500d06..fdd71c31e 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts @@ -1,6 +1,6 @@ import client from "@kubb/plugin-client/client"; import type { RequestConfig } from "@kubb/plugin-client/client"; -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query"; +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query"; import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query"; export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const; @@ -39,7 +39,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find * @summary Finds Pets by tags * @link /pet/findByTags */ -export function useFindPetsByTagsInfinite(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: { +export function useFindPetsByTagsInfinite, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: { query?: Partial>; client?: Partial; } = {}) { diff --git a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx index ca9d6306d..43df643f1 100644 --- a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components' import type { PluginReactQuery } from '../types' @@ -17,8 +18,12 @@ export const infiniteQueryGenerator = createReactGenerator({ }, } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method) - const isInfinite = isQuery && !!options.infinite + + const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) + const isInfinite = !!options.infinite const importPath = options.query ? options.query.importPath : '@tanstack/react-query' @@ -52,7 +57,7 @@ export const infiniteQueryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery || !isInfinite) { + if (!isQuery || isMutation || !isInfinite) { return null } @@ -98,6 +103,7 @@ export const infiniteQueryGenerator = createReactGenerator({ /> {options.infinite && ( <> + ({ } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) - const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method) + const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) + const isMutation = + !isQuery && + difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method) const importPath = options.mutation ? options.mutation.importPath : '@tanstack/react-query' diff --git a/packages/plugin-react-query/src/generators/queryGenerator.tsx b/packages/plugin-react-query/src/generators/queryGenerator.tsx index 9bf63e8dc..6ad17a454 100644 --- a/packages/plugin-react-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/queryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Query, QueryKey, QueryOptions } from '../components' import type { PluginReactQuery } from '../types' @@ -19,6 +20,10 @@ export const queryGenerator = createReactGenerator({ const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) + const importPath = options.query ? options.query.importPath : '@tanstack/react-query' const query = { @@ -51,7 +56,7 @@ export const queryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery) { + if (!isQuery || isMutation) { return null } diff --git a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx index aa9370142..ff3b87146 100644 --- a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx @@ -1,4 +1,3 @@ -import transformers from '@kubb/core/transformers' import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' @@ -6,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { QueryKey, QueryOptions, SuspenseQuery } from '../components' import type { PluginReactQuery } from '../types' @@ -18,8 +18,13 @@ export const suspenseQueryGenerator = createReactGenerator({ }, } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method) - const isSuspense = isQuery && !!options.suspense + + const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) + + const isSuspense = !!options.suspense const importPath = options.query ? options.query.importPath : '@tanstack/react-query' @@ -53,7 +58,7 @@ export const suspenseQueryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery || !isSuspense) { + if (!isQuery || isMutation || !isSuspense) { return null } diff --git a/packages/plugin-react-query/src/plugin.ts b/packages/plugin-react-query/src/plugin.ts index e9cf026cb..14ed6f703 100644 --- a/packages/plugin-react-query/src/plugin.ts +++ b/packages/plugin-react-query/src/plugin.ts @@ -55,11 +55,14 @@ export const pluginReactQuery = createPlugin((options) => { : false, suspense, queryKey, - query: { - methods: ['get'], - importPath: '@tanstack/react-query', - ...query, - }, + query: + query === false + ? false + : { + methods: ['get'], + importPath: '@tanstack/react-query', + ...query, + }, mutationKey, mutation: { methods: ['post', 'put', 'patch', 'delete'], diff --git a/packages/plugin-solid-query/package.json b/packages/plugin-solid-query/package.json index 6990f2dbc..99f9a2a8e 100644 --- a/packages/plugin-solid-query/package.json +++ b/packages/plugin-solid-query/package.json @@ -79,7 +79,8 @@ "@kubb/plugin-oas": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@kubb/react": "workspace:*" + "@kubb/react": "workspace:*", + "remeda": "^2.16.0" }, "devDependencies": { "@kubb/config-ts": "workspace:*", diff --git a/packages/plugin-solid-query/src/generators/queryGenerator.tsx b/packages/plugin-solid-query/src/generators/queryGenerator.tsx index b08d1df22..2dd662550 100644 --- a/packages/plugin-solid-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-solid-query/src/generators/queryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Query, QueryKey, QueryOptions } from '../components' import type { PluginSolidQuery } from '../types' @@ -19,6 +20,7 @@ export const queryGenerator = createReactGenerator({ const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method) const importPath = options.query ? options.query.importPath : '@tanstack/solid-query' const query = { @@ -51,7 +53,7 @@ export const queryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery) { + if (!isQuery || isMutation) { return null } diff --git a/packages/plugin-solid-query/src/plugin.ts b/packages/plugin-solid-query/src/plugin.ts index 4c9dc7f9b..d20259c90 100644 --- a/packages/plugin-solid-query/src/plugin.ts +++ b/packages/plugin-solid-query/src/plugin.ts @@ -42,11 +42,14 @@ export const pluginSolidQuery = createPlugin((options) => { ...options.client, }, queryKey, - query: { - methods: ['get'], - importPath: '@tanstack/solid-query', - ...query, - }, + query: + query === false + ? false + : { + methods: ['get'], + importPath: '@tanstack/solid-query', + ...query, + }, paramsType, pathParamsType: paramsType === 'object' ? 'object' : pathParamsType, parser, diff --git a/packages/plugin-svelte-query/package.json b/packages/plugin-svelte-query/package.json index 6aa95d567..11c066194 100644 --- a/packages/plugin-svelte-query/package.json +++ b/packages/plugin-svelte-query/package.json @@ -79,7 +79,8 @@ "@kubb/plugin-oas": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@kubb/react": "workspace:*" + "@kubb/react": "workspace:*", + "remeda": "^2.16.0" }, "devDependencies": { "@kubb/config-ts": "workspace:*", diff --git a/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx b/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx index 8a124d741..5951bead5 100644 --- a/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx +++ b/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Mutation, MutationKey } from '../components' import type { PluginSvelteQuery } from '../types' @@ -18,8 +19,10 @@ export const mutationGenerator = createReactGenerator({ } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) - const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method) + const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) + const isMutation = + !isQuery && + difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method) const importPath = options.mutation ? options.mutation.importPath : '@tanstack/svelte-query' diff --git a/packages/plugin-svelte-query/src/generators/queryGenerator.tsx b/packages/plugin-svelte-query/src/generators/queryGenerator.tsx index 99f3e6704..6a9765bfd 100644 --- a/packages/plugin-svelte-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-svelte-query/src/generators/queryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Query, QueryKey, QueryOptions } from '../components' import type { PluginSvelteQuery } from '../types' @@ -19,6 +20,9 @@ export const queryGenerator = createReactGenerator({ const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) const importPath = options.query ? options.query.importPath : '@tanstack/svelte-query' const query = { @@ -51,7 +55,7 @@ export const queryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery) { + if (!isQuery || isMutation) { return null } diff --git a/packages/plugin-svelte-query/src/plugin.ts b/packages/plugin-svelte-query/src/plugin.ts index c46ee263d..9b6357b9d 100644 --- a/packages/plugin-svelte-query/src/plugin.ts +++ b/packages/plugin-svelte-query/src/plugin.ts @@ -44,11 +44,14 @@ export const pluginSvelteQuery = createPlugin((options) => { ...options.client, }, queryKey, - query: { - methods: ['get'], - importPath: '@tanstack/svelte-query', - ...query, - }, + query: + query === false + ? false + : { + methods: ['get'], + importPath: '@tanstack/svelte-query', + ...query, + }, mutationKey, mutation: { methods: ['post', 'put', 'patch', 'delete'], diff --git a/packages/plugin-swr/package.json b/packages/plugin-swr/package.json index fc25595c8..25b390fcd 100644 --- a/packages/plugin-swr/package.json +++ b/packages/plugin-swr/package.json @@ -81,7 +81,8 @@ "@kubb/plugin-oas": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@kubb/react": "workspace:*" + "@kubb/react": "workspace:*", + "remeda": "^2.16.0" }, "devDependencies": { "@kubb/config-ts": "workspace:*", diff --git a/packages/plugin-swr/src/generators/mutationGenerator.tsx b/packages/plugin-swr/src/generators/mutationGenerator.tsx index 335821be5..3a618d332 100644 --- a/packages/plugin-swr/src/generators/mutationGenerator.tsx +++ b/packages/plugin-swr/src/generators/mutationGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { MutationKey } from '../components' import { Mutation } from '../components' import type { PluginSwr } from '../types' @@ -19,8 +20,10 @@ export const mutationGenerator = createReactGenerator({ } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) - const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method) + const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) + const isMutation = + !isQuery && + difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method) const importPath = options.mutation ? options.mutation.importPath : 'swr' diff --git a/packages/plugin-swr/src/generators/queryGenerator.tsx b/packages/plugin-swr/src/generators/queryGenerator.tsx index 53d0266ec..e4f166b01 100644 --- a/packages/plugin-swr/src/generators/queryGenerator.tsx +++ b/packages/plugin-swr/src/generators/queryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Query, QueryOptions } from '../components' import { QueryKey } from '../components' import type { PluginSwr } from '../types' @@ -19,7 +20,10 @@ export const queryGenerator = createReactGenerator({ } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method) + const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) const importPath = options.query ? options.query.importPath : 'swr/mutation' const query = { @@ -51,7 +55,7 @@ export const queryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery) { + if (!isQuery || isMutation) { return null } diff --git a/packages/plugin-swr/src/plugin.ts b/packages/plugin-swr/src/plugin.ts index 26e42160d..73a586a67 100644 --- a/packages/plugin-swr/src/plugin.ts +++ b/packages/plugin-swr/src/plugin.ts @@ -44,11 +44,14 @@ export const pluginSwr = createPlugin((options) => { ...client, }, queryKey, - query: { - importPath: 'swr', - methods: ['get'], - ...query, - }, + query: + query === false + ? false + : { + importPath: 'swr', + methods: ['get'], + ...query, + }, mutationKey, mutation: { importPath: 'swr/mutation', diff --git a/packages/plugin-vue-query/package.json b/packages/plugin-vue-query/package.json index 3b890546e..2af45bbe8 100644 --- a/packages/plugin-vue-query/package.json +++ b/packages/plugin-vue-query/package.json @@ -79,7 +79,8 @@ "@kubb/plugin-oas": "workspace:*", "@kubb/plugin-ts": "workspace:*", "@kubb/plugin-zod": "workspace:*", - "@kubb/react": "workspace:*" + "@kubb/react": "workspace:*", + "remeda": "^2.16.0" }, "devDependencies": { "@kubb/config-ts": "workspace:*", diff --git a/packages/plugin-vue-query/src/components/InfiniteQuery.tsx b/packages/plugin-vue-query/src/components/InfiniteQuery.tsx index acd13e688..5b119e4f6 100644 --- a/packages/plugin-vue-query/src/components/InfiniteQuery.tsx +++ b/packages/plugin-vue-query/src/components/InfiniteQuery.tsx @@ -137,7 +137,7 @@ export function InfiniteQuery({ }: Props): ReactNode { const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>` const returnType = `UseInfiniteQueryReturnType<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }` - const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] + const generics = [`TData = InfiniteData<${TData}>`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] const queryKeyParams = QueryKey.getParams({ pathParamsType, diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags.ts index 6739b9ba2..72eabdc7c 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags.ts @@ -1,6 +1,6 @@ import client from "@kubb/plugin-client/client"; import type { RequestConfig } from "@kubb/plugin-client/client"; -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query"; +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query"; import type { MaybeRef } from "vue"; import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query"; @@ -40,7 +40,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find * @summary Finds Pets by tags * @link /pet/findByTags */ -export function useFindPetsByTagsInfinite(headers: MaybeRef, params?: MaybeRef, options: { +export function useFindPetsByTagsInfinite, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef, params?: MaybeRef, options: { query?: Partial>; client?: Partial; } = {}) { diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts index fa58e3d26..0cf425cae 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor.ts @@ -1,6 +1,6 @@ import client from "@kubb/plugin-client/client"; import type { RequestConfig } from "@kubb/plugin-client/client"; -import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query"; +import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query"; import type { MaybeRef } from "vue"; import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query"; @@ -40,7 +40,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find * @summary Finds Pets by tags * @link /pet/findByTags */ -export function useFindPetsByTagsInfinite(headers: MaybeRef, params?: MaybeRef, options: { +export function useFindPetsByTagsInfinite, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef, params?: MaybeRef, options: { query?: Partial>; client?: Partial; } = {}) { diff --git a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx index 01f5face2..9f72bae97 100644 --- a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx +++ b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components' import type { PluginVueQuery } from '../types' @@ -17,7 +18,11 @@ export const infiniteQueryGenerator = createReactGenerator({ }, } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method) + + const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) const isInfinite = isQuery && !!options.infinite const importPath = options.query ? options.query.importPath : '@tanstack/vue-query' @@ -51,7 +56,7 @@ export const infiniteQueryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery || !isInfinite) { + if (!isQuery || isMutation || !isInfinite) { return null } @@ -99,6 +104,7 @@ export const infiniteQueryGenerator = createReactGenerator({ /> {options.infinite && ( <> + ({ } = useApp() const { getSchemas, getName, getFile } = useOperationManager() - const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) - const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method) + const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) + const isMutation = + !isQuery && + difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method) const importPath = options.mutation ? options.mutation.importPath : '@tanstack/vue-query' diff --git a/packages/plugin-vue-query/src/generators/queryGenerator.tsx b/packages/plugin-vue-query/src/generators/queryGenerator.tsx index ecca44920..da5552bf0 100644 --- a/packages/plugin-vue-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-vue-query/src/generators/queryGenerator.tsx @@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File, useApp } from '@kubb/react' +import { difference } from 'remeda' import { Query, QueryKey, QueryOptions } from '../components' import type { PluginVueQuery } from '../types' @@ -19,6 +20,9 @@ export const queryGenerator = createReactGenerator({ const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) + const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some( + (method) => operation.method === method, + ) const importPath = options.query ? options.query.importPath : '@tanstack/vue-query' const query = { @@ -51,7 +55,7 @@ export const queryGenerator = createReactGenerator({ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } - if (!isQuery) { + if (!isQuery || isMutation) { return null } diff --git a/packages/plugin-vue-query/src/plugin.ts b/packages/plugin-vue-query/src/plugin.ts index 14eda67ca..a3a8b8d8a 100644 --- a/packages/plugin-vue-query/src/plugin.ts +++ b/packages/plugin-vue-query/src/plugin.ts @@ -53,11 +53,14 @@ export const pluginVueQuery = createPlugin((options) => { } : false, queryKey, - query: { - methods: ['get'], - importPath: '@tanstack/vue-query', - ...query, - }, + query: + query === false + ? false + : { + methods: ['get'], + importPath: '@tanstack/vue-query', + ...query, + }, mutationKey, mutation: { methods: ['post', 'put', 'patch', 'delete'], diff --git a/packages/unplugin-kubb/package.json b/packages/unplugin-kubb/package.json index b2cdd985e..9105657b3 100644 --- a/packages/unplugin-kubb/package.json +++ b/packages/unplugin-kubb/package.json @@ -110,8 +110,8 @@ "@kubb/config-ts": "workspace:*", "@kubb/config-tsup": "workspace:*", "@kubb/core": "workspace:*", - "@nuxt/kit": "^3.14.0", - "@nuxt/schema": "^3.14.0", + "@nuxt/kit": "^3.14.159", + "@nuxt/schema": "^3.14.159", "@types/node": "^20.17.6", "rimraf": "^5.0.10", "rollup": "^4.24.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b39db6b2..1ae70b2d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,7 +66,7 @@ importers: dependencies: '@shikijs/vitepress-twoslash': specifier: ^1.22.2 - version: 1.22.2(@nuxt/kit@3.14.0(magicast@0.3.5)(webpack-sources@3.2.3))(typescript@5.6.3) + version: 1.22.2(@nuxt/kit@3.14.159(magicast@0.3.5)(webpack-sources@3.2.3))(typescript@5.6.3) mermaid: specifier: ^11.4.0 version: 11.4.0 @@ -186,17 +186,17 @@ importers: specifier: workspace:* version: link:../packages/react '@tanstack/react-query': - specifier: ^5.59.19 - version: 5.59.19(react@18.3.1) + specifier: ^5.59.20 + version: 5.59.20(react@18.3.1) '@tanstack/solid-query': - specifier: ^5.59.17 - version: 5.59.17(solid-js@1.9.3) + specifier: ^5.59.20 + version: 5.59.20(solid-js@1.9.3) '@tanstack/svelte-query': - specifier: ^5.59.17 - version: 5.59.17(svelte@3.59.2) + specifier: ^5.59.20 + version: 5.59.20(svelte@3.59.2) '@tanstack/vue-query': - specifier: ^5.59.17 - version: 5.59.17(vue@3.5.12(typescript@5.6.3)) + specifier: ^5.59.20 + version: 5.59.20(vue@3.5.12(typescript@5.6.3)) axios: specifier: ^1.7.7 version: 1.7.7 @@ -277,20 +277,20 @@ importers: specifier: workspace:* version: link:../../packages/react '@tanstack/query-core': - specifier: ^5.59.17 - version: 5.59.17 + specifier: ^5.59.20 + version: 5.59.20 '@tanstack/react-query': - specifier: ^5.59.19 - version: 5.59.19(react@18.3.1) + specifier: ^5.59.20 + version: 5.59.20(react@18.3.1) '@tanstack/solid-query': - specifier: ^5.59.17 - version: 5.59.17(solid-js@1.9.3) + specifier: ^5.59.20 + version: 5.59.20(solid-js@1.9.3) '@tanstack/svelte-query': - specifier: ^5.59.17 - version: 5.59.17(svelte@3.59.2) + specifier: ^5.59.20 + version: 5.59.20(svelte@3.59.2) '@tanstack/vue-query': - specifier: ^5.59.17 - version: 5.59.17(vue@3.5.12(typescript@5.6.3)) + specifier: ^5.59.20 + version: 5.59.20(vue@3.5.12(typescript@5.6.3)) axios: specifier: ^1.7.7 version: 1.7.7 @@ -553,11 +553,11 @@ importers: specifier: workspace:* version: link:../../packages/react '@tanstack/react-query': - specifier: ^5.59.19 - version: 5.59.19(react@18.3.1) + specifier: ^5.59.20 + version: 5.59.20(react@18.3.1) '@tanstack/react-query-devtools': - specifier: ^5.59.19 - version: 5.59.19(@tanstack/react-query@5.59.19(react@18.3.1))(react@18.3.1) + specifier: ^5.59.20 + version: 5.59.20(@tanstack/react-query@5.59.20(react@18.3.1))(react@18.3.1) axios: specifier: ^1.7.7 version: 1.7.7 @@ -620,8 +620,8 @@ importers: specifier: workspace:* version: link:../../packages/plugin-zod '@tanstack/react-query': - specifier: ^5.59.19 - version: 5.59.19(react@18.3.1) + specifier: ^5.59.20 + version: 5.59.20(react@18.3.1) axios: specifier: ^1.7.7 version: 1.7.7 @@ -659,8 +659,8 @@ importers: specifier: workspace:* version: link:../../packages/plugin-zod '@tanstack/solid-query': - specifier: ^5.59.17 - version: 5.59.17(solid-js@1.9.3) + specifier: ^5.59.20 + version: 5.59.20(solid-js@1.9.3) axios: specifier: ^1.7.7 version: 1.7.7 @@ -699,8 +699,8 @@ importers: specifier: workspace:* version: link:../../packages/plugin-zod '@tanstack/svelte-query': - specifier: ^5.59.17 - version: 5.59.17(svelte@3.59.2) + specifier: ^5.59.20 + version: 5.59.20(svelte@3.59.2) axios: specifier: ^1.7.7 version: 1.7.7 @@ -803,8 +803,8 @@ importers: specifier: workspace:* version: link:../../packages/plugin-zod '@tanstack/vue-query': - specifier: ^5.59.17 - version: 5.59.17(vue@3.5.12(typescript@5.6.3)) + specifier: ^5.59.20 + version: 5.59.20(vue@3.5.12(typescript@5.6.3)) axios: specifier: ^1.7.7 version: 1.7.7 @@ -1330,6 +1330,9 @@ importers: '@kubb/react': specifier: workspace:* version: link:../react + remeda: + specifier: ^2.16.0 + version: 2.16.0 devDependencies: '@kubb/config-ts': specifier: workspace:* @@ -1425,6 +1428,9 @@ importers: '@kubb/react': specifier: workspace:* version: link:../react + remeda: + specifier: ^2.16.0 + version: 2.16.0 devDependencies: '@kubb/config-ts': specifier: workspace:* @@ -1468,6 +1474,9 @@ importers: '@kubb/react': specifier: workspace:* version: link:../react + remeda: + specifier: ^2.16.0 + version: 2.16.0 devDependencies: '@kubb/config-ts': specifier: workspace:* @@ -1514,6 +1523,9 @@ importers: '@kubb/react': specifier: workspace:* version: link:../react + remeda: + specifier: ^2.16.0 + version: 2.16.0 devDependencies: '@kubb/config-ts': specifier: workspace:* @@ -1597,6 +1609,9 @@ importers: '@kubb/react': specifier: workspace:* version: link:../react + remeda: + specifier: ^2.16.0 + version: 2.16.0 devDependencies: '@kubb/config-ts': specifier: workspace:* @@ -1749,11 +1764,11 @@ importers: specifier: workspace:* version: link:../core '@nuxt/kit': - specifier: ^3.14.0 - version: 3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) + specifier: ^3.14.159 + version: 3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) '@nuxt/schema': - specifier: ^3.14.0 - version: 3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) + specifier: ^3.14.159 + version: 3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) '@types/node': specifier: ^20.17.6 version: 20.17.6 @@ -2918,12 +2933,12 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@nuxt/kit@3.14.0': - resolution: {integrity: sha512-Gl30WrzX7YSJqkTyOJlG4LkErShkGoHigWF/htFt9Q27Lx9JNCkOpXlEf+rA/vsDlXJeo8mVNRoMhS4Q+0d1Kg==} + '@nuxt/kit@3.14.159': + resolution: {integrity: sha512-ZqxsCI1NKV/gjfEUUZjMcr82sg0MKYZOuyB6bu9QY5Zr7NGpfIZY/z5Z822AKTmFxKGChnuz9M0UaS4ze6p42g==} engines: {node: ^14.18.0 || >=16.10.0} - '@nuxt/schema@3.14.0': - resolution: {integrity: sha512-uLAAS7Za7+JXJg6phAjUecqBUfON/WZN/NbYic7uCM+4LUT8B4M/5WM9zFCZJi1g9Krns5Wr5GmJJPIfaYt0eQ==} + '@nuxt/schema@3.14.159': + resolution: {integrity: sha512-ggXA3F2f9udQoEy5WwrY6bTMvpDaErUYRLSEzdMqqCqjOQ5manfFgfuScGj3ooZiXLIX2TGLVTzcll4nnpDlnQ==} engines: {node: ^14.18.0 || >=16.10.0} '@open-draft/deferred-promise@2.2.0': @@ -3418,35 +3433,35 @@ packages: resolution: {integrity: sha512-PnVV3d2poenUM31ZbZi/yXkBu3J7kd5k2u51CGwwNojag451AjTH9N6n41yjXz2fpLeewleyLBmNS6+HcGDlXw==} engines: {node: '>=12'} - '@tanstack/query-core@5.59.17': - resolution: {integrity: sha512-jWdDiif8kaqnRGHNXAa9CnudtxY5v9DUxXhodgqX2Rwzj+1UwStDHEbBd9IA5C7VYAaJ2s+BxFR6PUBs8ERorA==} + '@tanstack/query-core@5.59.20': + resolution: {integrity: sha512-e8vw0lf7KwfGe1if4uPFhvZRWULqHjFcz3K8AebtieXvnMOz5FSzlZe3mTLlPuUBcydCnBRqYs2YJ5ys68wwLg==} - '@tanstack/query-devtools@5.59.19': - resolution: {integrity: sha512-Gw+3zsADpqiYgx/6MMr9bP1+x2LR8vOuGjo5Un/89qwwP3z7WAHPWFagLFDYkLq68NX7ekUpW/EOYlUMugMXGA==} + '@tanstack/query-devtools@5.59.20': + resolution: {integrity: sha512-vxhuQ+8VV4YWQSFxQLsuM+dnEKRY7VeRzpNabFXdhEwsBYLrjXlF1pM38A8WyKNLqZy8JjyRO8oP4Wd/oKHwuQ==} - '@tanstack/react-query-devtools@5.59.19': - resolution: {integrity: sha512-mYFWTHLtJr2HdyYPZPzzvQ2ksCsSL6L04fCtusPFD3waskXrtmvWvyuDIGeEGdVAYS0Urwxw/0sYvcTVQZH+zQ==} + '@tanstack/react-query-devtools@5.59.20': + resolution: {integrity: sha512-AL/eQS1NFZhwwzq2Bq9Gd8wTTH+XhPNOJlDFpzPMu9NC5CQVgA0J8lWrte/sXpdWNo5KA4hgHnEdImZsF4h6Lw==} peerDependencies: - '@tanstack/react-query': ^5.59.19 + '@tanstack/react-query': ^5.59.20 react: ^18 || ^19 - '@tanstack/react-query@5.59.19': - resolution: {integrity: sha512-xLRfyFyQOFcLltKCds0LijfC6/HQJrrTTnZB8ciyn74LIkVAm++vZJ6eUVG20RmJtdP8REdy7vSOYW4M3//XLA==} + '@tanstack/react-query@5.59.20': + resolution: {integrity: sha512-Zly0egsK0tFdfSbh5/mapSa+Zfc3Et0Zkar7Wo5sQkFzWyB3p3uZWOHR2wrlAEEV2L953eLuDBtbgFvMYiLvUw==} peerDependencies: react: ^18 || ^19 - '@tanstack/solid-query@5.59.17': - resolution: {integrity: sha512-fUypay1MrMJk3fcIXQG6RK2VfpEO6oxQGUeHBD8vUczTQnc0P7gZAQnHeD2KdcnEUC5Bnfe25cq0auymL2A8Ow==} + '@tanstack/solid-query@5.59.20': + resolution: {integrity: sha512-pawItVLVj/4DPVcjRC4slMMEJvuXBHjkHPVViDeezNc4QHZFCPJ5sa30WIZlCahSoqKtplcjdB6oK8BvoZQgSA==} peerDependencies: solid-js: ^1.6.0 - '@tanstack/svelte-query@5.59.17': - resolution: {integrity: sha512-1nJw29NyVgTIrlIC3X1PtQsxE4ecBkYNkq/1OOaYKofc7Q3aXbvC8KOdoyzPSk/pUKj0LJl7tKfRRTvB3l+YGA==} + '@tanstack/svelte-query@5.59.20': + resolution: {integrity: sha512-DFRTz9i6OXIF+o4GFDRF4g3Q6BSBKWxoahZPcPbCAdXAS4NRhTnVFR4HgEtzlhfoQx8yMJsLXMhDiGUw365HsA==} peerDependencies: svelte: ^3.54.0 || ^4.0.0 || ^5.0.0-next.0 - '@tanstack/vue-query@5.59.17': - resolution: {integrity: sha512-113b6ITbiNMrzZIybVRIbvNIiVRCIdWzSfZbXBNa+WIjDto/xdR2NnMZrNe2wtUActzC1cArAlGM2CFH1SR11Q==} + '@tanstack/vue-query@5.59.20': + resolution: {integrity: sha512-kIs1GfXh7jVLycbnQDghfdrcvrZz5fxnMF7eAAp8O3ZfhHQWfP57DBXbOvww4Y+TI0EvVoh+hihX+LNFBGFKLg==} peerDependencies: '@vue/composition-api': ^1.1.2 vue: ^2.6.0 || ^3.3.0 @@ -9080,9 +9095,9 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@nuxt/kit@3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': + '@nuxt/kit@3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': dependencies: - '@nuxt/schema': 3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) + '@nuxt/schema': 3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) c12: 2.0.1(magicast@0.3.5) consola: 3.2.3 defu: 6.1.4 @@ -9108,7 +9123,7 @@ snapshots: - supports-color - webpack-sources - '@nuxt/schema@3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': + '@nuxt/schema@3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': dependencies: c12: 2.0.1(magicast@0.3.5) compatx: 0.1.8 @@ -9477,10 +9492,10 @@ snapshots: '@shikijs/vscode-textmate': 9.3.0 '@types/hast': 3.0.4 - '@shikijs/vitepress-twoslash@1.22.2(@nuxt/kit@3.14.0(magicast@0.3.5)(webpack-sources@3.2.3))(typescript@5.6.3)': + '@shikijs/vitepress-twoslash@1.22.2(@nuxt/kit@3.14.159(magicast@0.3.5)(webpack-sources@3.2.3))(typescript@5.6.3)': dependencies: '@shikijs/twoslash': 1.22.2(typescript@5.6.3) - floating-vue: 5.2.2(@nuxt/kit@3.14.0(magicast@0.3.5)(webpack-sources@3.2.3))(vue@3.5.12(typescript@5.6.3)) + floating-vue: 5.2.2(@nuxt/kit@3.14.159(magicast@0.3.5)(webpack-sources@3.2.3))(vue@3.5.12(typescript@5.6.3)) mdast-util-from-markdown: 2.0.2 mdast-util-gfm: 3.0.0 mdast-util-to-hast: 13.2.0 @@ -9574,35 +9589,35 @@ snapshots: dependencies: remove-accents: 0.5.0 - '@tanstack/query-core@5.59.17': {} + '@tanstack/query-core@5.59.20': {} - '@tanstack/query-devtools@5.59.19': {} + '@tanstack/query-devtools@5.59.20': {} - '@tanstack/react-query-devtools@5.59.19(@tanstack/react-query@5.59.19(react@18.3.1))(react@18.3.1)': + '@tanstack/react-query-devtools@5.59.20(@tanstack/react-query@5.59.20(react@18.3.1))(react@18.3.1)': dependencies: - '@tanstack/query-devtools': 5.59.19 - '@tanstack/react-query': 5.59.19(react@18.3.1) + '@tanstack/query-devtools': 5.59.20 + '@tanstack/react-query': 5.59.20(react@18.3.1) react: 18.3.1 - '@tanstack/react-query@5.59.19(react@18.3.1)': + '@tanstack/react-query@5.59.20(react@18.3.1)': dependencies: - '@tanstack/query-core': 5.59.17 + '@tanstack/query-core': 5.59.20 react: 18.3.1 - '@tanstack/solid-query@5.59.17(solid-js@1.9.3)': + '@tanstack/solid-query@5.59.20(solid-js@1.9.3)': dependencies: - '@tanstack/query-core': 5.59.17 + '@tanstack/query-core': 5.59.20 solid-js: 1.9.3 - '@tanstack/svelte-query@5.59.17(svelte@3.59.2)': + '@tanstack/svelte-query@5.59.20(svelte@3.59.2)': dependencies: - '@tanstack/query-core': 5.59.17 + '@tanstack/query-core': 5.59.20 svelte: 3.59.2 - '@tanstack/vue-query@5.59.17(vue@3.5.12(typescript@5.6.3))': + '@tanstack/vue-query@5.59.20(vue@3.5.12(typescript@5.6.3))': dependencies: '@tanstack/match-sorter-utils': 8.15.1 - '@tanstack/query-core': 5.59.17 + '@tanstack/query-core': 5.59.20 '@vue/devtools-api': 6.6.3 vue: 3.5.12(typescript@5.6.3) vue-demi: 0.14.10(vue@3.5.12(typescript@5.6.3)) @@ -10542,7 +10557,7 @@ snapshots: c12@2.0.1(magicast@0.3.5): dependencies: chokidar: 4.0.1 - confbox: 0.1.7 + confbox: 0.1.8 defu: 6.1.4 dotenv: 16.4.5 giget: 1.2.3 @@ -11647,13 +11662,13 @@ snapshots: flatted@3.3.1: {} - floating-vue@5.2.2(@nuxt/kit@3.14.0(magicast@0.3.5)(webpack-sources@3.2.3))(vue@3.5.12(typescript@5.6.3)): + floating-vue@5.2.2(@nuxt/kit@3.14.159(magicast@0.3.5)(webpack-sources@3.2.3))(vue@3.5.12(typescript@5.6.3)): dependencies: '@floating-ui/dom': 1.1.1 vue: 3.5.12(typescript@5.6.3) vue-resize: 2.0.0-alpha.1(vue@3.5.12(typescript@5.6.3)) optionalDependencies: - '@nuxt/kit': 3.14.0(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) + '@nuxt/kit': 3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) focus-trap@7.6.0: dependencies: