@kubb/plugin-react-query 5.0.0-beta.27 → 5.0.0-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{generators-C-cwJah8.js → generators-Bma51Uar.js} +86 -38
- package/dist/generators-Bma51Uar.js.map +1 -0
- package/dist/{generators-DozEZKwy.cjs → generators-BtsWNz-6.cjs} +86 -38
- package/dist/generators-BtsWNz-6.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/extension.yaml +5 -5
- package/package.json +7 -7
- package/src/generators/hookOptionsGenerator.tsx +2 -2
- package/src/generators/infiniteQueryGenerator.tsx +6 -6
- package/src/generators/mutationGenerator.tsx +6 -6
- package/src/generators/queryGenerator.tsx +6 -6
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +6 -6
- package/src/generators/suspenseQueryGenerator.tsx +6 -6
- package/src/plugin.ts +3 -3
- package/dist/generators-C-cwJah8.js.map +0 -1
- package/dist/generators-DozEZKwy.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["camelCase","mutationKeyTransformer","queryKeyTransformer","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","camelCase","pluginTsName","pluginZodName","path","pluginClientName","ast","fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginReactQuery } from '../types.ts'\n\nfunction capitalize(name: string): string {\n return `${name.charAt(0).toUpperCase()}${name.slice(1)}`\n}\n\n/**\n * Default resolver used by `@kubb/plugin-react-query`. Decides the names and\n * file paths for every generated TanStack Query hook (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`, ...) and its companion helpers\n * (`fooQueryKey`, `fooQueryOptions`).\n *\n * Functions and files use camelCase; hooks get the `use` prefix; suspense and\n * infinite variants are suffixed with `Suspense`/`Infinite`.\n *\n * @example Resolve hook and helper names\n * ```ts\n * import { resolverReactQuery } from '@kubb/plugin-react-query'\n *\n * resolverReactQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverReactQuery.resolveMutationName(operationNode) // 'useUpdatePet'\n * resolverReactQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverReactQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverReactQuery = defineResolver<PluginReactQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-react-query',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveSuspenseQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Suspense`\n },\n resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\n },\n resolveSuspenseInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`\n },\n resolveMutationName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}QueryOptions`\n },\n resolveSuspenseQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryOptions`\n },\n resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveSuspenseInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`\n },\n resolveMutationOptionsName(node) {\n return `${this.resolveName(node.operationId)}MutationOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveSuspenseQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`\n },\n resolveMutationKeyName(node) {\n return `${this.resolveName(node.operationId)}MutationKey`\n },\n resolveQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}QueryKey`\n },\n resolveSuspenseQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveSuspenseClientName(node) {\n return `${this.resolveName(node.operationId)}Suspense`\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\n },\n resolveSuspenseInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfinite`\n },\n resolveHookOptionsName() {\n return 'HookOptions'\n },\n resolveCustomHookOptionsName() {\n return 'getCustomHookOptions'\n },\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mutationKeyTransformer, queryKeyTransformer } from '@internals/tanstack-query'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport { resolverReactQuery } from './resolvers/resolverReactQuery.ts'\nimport type { PluginReactQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\n/**\n * Generates one TanStack Query hook per OpenAPI operation for React. Queries\n * become `useFooQuery`/`useFooSuspenseQuery`/`useFooInfiniteQuery`; mutations\n * become `useFooMutation`. Each hook is fully typed: query keys, input\n * variables, response data, and error shape all come from the spec.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginReactQuery } from '@kubb/plugin-react-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginReactQuery({\n * output: { path: './hooks' },\n * suspense: {},\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutation = {},\n query = {},\n mutationKey = mutationKeyTransformer,\n queryKey = queryKeyTransformer,\n customOptions,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ??\n [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverReactQuery, ...userResolver } : resolverReactQuery\n\n ctx.setOptions({\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: null,\n nextParam: null,\n previousParam: null,\n ...infinite,\n }\n : false,\n suspense,\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : null,\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n ast.createSource({\n name: 'fetch',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginReactQuery\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;AAsBxD,MAAa,sBAAA,GAAA,WAAA,uBAA6D;CACxE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,WAAW;;CAEvC,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,iBAAiB,MAAM;EACrB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,iCAAiC,MAAM;EACrC,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,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AC,kBACzC,IAAI,WAAW;IACb,UAAU;IACV,MAAMD,UAAAA,QAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,eAAe,UAAUC,mDAAAA,SAAoBC,mDAAAA,OAAkB,CAAC;KACvF,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;GAGJ,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAMJ,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAWG,4CAAAA,OAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["camelCase","mutationKeyTransformer","queryKeyTransformer","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","camelCase","pluginTsName","pluginZodName","path","pluginClientName","ast","fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginReactQuery } from '../types.ts'\n\nfunction capitalize(name: string): string {\n return `${name.charAt(0).toUpperCase()}${name.slice(1)}`\n}\n\n/**\n * Default resolver used by `@kubb/plugin-react-query`. Decides the names and\n * file paths for every generated TanStack Query hook (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`, ...) and its companion helpers\n * (`fooQueryKey`, `fooQueryOptions`).\n *\n * Functions and files use camelCase; hooks get the `use` prefix; suspense and\n * infinite variants are suffixed with `Suspense`/`Infinite`.\n *\n * @example Resolve hook and helper names\n * ```ts\n * import { resolverReactQuery } from '@kubb/plugin-react-query'\n *\n * resolverReactQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverReactQuery.resolveMutationName(operationNode) // 'useUpdatePet'\n * resolverReactQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverReactQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverReactQuery = defineResolver<PluginReactQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-react-query',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveSuspenseQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Suspense`\n },\n resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\n },\n resolveSuspenseInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`\n },\n resolveMutationName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}QueryOptions`\n },\n resolveSuspenseQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryOptions`\n },\n resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveSuspenseInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`\n },\n resolveMutationOptionsName(node) {\n return `${this.resolveName(node.operationId)}MutationOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveSuspenseQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`\n },\n resolveMutationKeyName(node) {\n return `${this.resolveName(node.operationId)}MutationKey`\n },\n resolveQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}QueryKey`\n },\n resolveSuspenseQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveSuspenseClientName(node) {\n return `${this.resolveName(node.operationId)}Suspense`\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\n },\n resolveSuspenseInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfinite`\n },\n resolveHookOptionsName() {\n return 'HookOptions'\n },\n resolveCustomHookOptionsName() {\n return 'getCustomHookOptions'\n },\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mutationKeyTransformer, queryKeyTransformer } from '@internals/tanstack-query'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport { resolverReactQuery } from './resolvers/resolverReactQuery.ts'\nimport type { PluginReactQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\n/**\n * Generates one TanStack Query hook per OpenAPI operation for React. Queries\n * become `useFooQuery`/`useFooSuspenseQuery`/`useFooInfiniteQuery`; mutations\n * become `useFooMutation`. Each hook is fully typed: query keys, input\n * variables, response data, and error shape all come from the spec.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginReactQuery } from '@kubb/plugin-react-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginReactQuery({\n * output: { path: './hooks' },\n * suspense: {},\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutation = {},\n query = {},\n mutationKey = mutationKeyTransformer,\n queryKey = queryKeyTransformer,\n customOptions,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ??\n [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverReactQuery, ...userResolver } : resolverReactQuery\n\n ctx.setOptions({\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: null,\n nextParam: null,\n previousParam: null,\n ...infinite,\n }\n : false,\n suspense,\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : null,\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'client.ts',\n path: path.resolve(root, '.kubb/client.ts'),\n sources: [\n ast.createSource({\n name: 'client',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginReactQuery\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;AAsBxD,MAAa,sBAAA,GAAA,WAAA,uBAA6D;CACxE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,WAAW;;CAEvC,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,iBAAiB,MAAM;EACrB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,iCAAiC,MAAM;EACrC,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,oBAAoB,MAAM;EACxB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,wBAAwB,MAAM;EAC5B,OAAO,GAAG,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE/C,gCAAgC,MAAM;EACpC,OAAO,GAAG,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE/C,gCAAgC,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C,CACH;IACF,CAAC;GAGJ,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAMJ,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAWG,4CAAAA,OAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { _ as mutationKeyTransformer, d as queryKeyTransformer, v as camelCase } from "./components-CDmg-RPi.js";
|
|
3
|
-
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-
|
|
3
|
+
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-Bma51Uar.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { ast, definePlugin, defineResolver } from "@kubb/core";
|
|
6
6
|
import { pluginClientName } from "@kubb/plugin-client";
|
|
@@ -245,10 +245,10 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
245
245
|
const root = path.resolve(ctx.config.root, ctx.config.output.path);
|
|
246
246
|
const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === pluginClientName);
|
|
247
247
|
if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
|
|
248
|
-
baseName: "
|
|
249
|
-
path: path.resolve(root, ".kubb/
|
|
248
|
+
baseName: "client.ts",
|
|
249
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
250
250
|
sources: [ast.createSource({
|
|
251
|
-
name: "
|
|
251
|
+
name: "client",
|
|
252
252
|
nodes: [ast.createText(clientName === "fetch" ? source$1 : source)],
|
|
253
253
|
isExportable: true,
|
|
254
254
|
isIndexable: true
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginReactQuery } from '../types.ts'\n\nfunction capitalize(name: string): string {\n return `${name.charAt(0).toUpperCase()}${name.slice(1)}`\n}\n\n/**\n * Default resolver used by `@kubb/plugin-react-query`. Decides the names and\n * file paths for every generated TanStack Query hook (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`, ...) and its companion helpers\n * (`fooQueryKey`, `fooQueryOptions`).\n *\n * Functions and files use camelCase; hooks get the `use` prefix; suspense and\n * infinite variants are suffixed with `Suspense`/`Infinite`.\n *\n * @example Resolve hook and helper names\n * ```ts\n * import { resolverReactQuery } from '@kubb/plugin-react-query'\n *\n * resolverReactQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverReactQuery.resolveMutationName(operationNode) // 'useUpdatePet'\n * resolverReactQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverReactQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverReactQuery = defineResolver<PluginReactQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-react-query',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveSuspenseQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Suspense`\n },\n resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\n },\n resolveSuspenseInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`\n },\n resolveMutationName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}QueryOptions`\n },\n resolveSuspenseQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryOptions`\n },\n resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveSuspenseInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`\n },\n resolveMutationOptionsName(node) {\n return `${this.resolveName(node.operationId)}MutationOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveSuspenseQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`\n },\n resolveMutationKeyName(node) {\n return `${this.resolveName(node.operationId)}MutationKey`\n },\n resolveQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}QueryKey`\n },\n resolveSuspenseQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveSuspenseClientName(node) {\n return `${this.resolveName(node.operationId)}Suspense`\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\n },\n resolveSuspenseInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfinite`\n },\n resolveHookOptionsName() {\n return 'HookOptions'\n },\n resolveCustomHookOptionsName() {\n return 'getCustomHookOptions'\n },\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mutationKeyTransformer, queryKeyTransformer } from '@internals/tanstack-query'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport { resolverReactQuery } from './resolvers/resolverReactQuery.ts'\nimport type { PluginReactQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\n/**\n * Generates one TanStack Query hook per OpenAPI operation for React. Queries\n * become `useFooQuery`/`useFooSuspenseQuery`/`useFooInfiniteQuery`; mutations\n * become `useFooMutation`. Each hook is fully typed: query keys, input\n * variables, response data, and error shape all come from the spec.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginReactQuery } from '@kubb/plugin-react-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginReactQuery({\n * output: { path: './hooks' },\n * suspense: {},\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutation = {},\n query = {},\n mutationKey = mutationKeyTransformer,\n queryKey = queryKeyTransformer,\n customOptions,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ??\n [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverReactQuery, ...userResolver } : resolverReactQuery\n\n ctx.setOptions({\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: null,\n nextParam: null,\n previousParam: null,\n ...infinite,\n }\n : false,\n suspense,\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : null,\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n ast.createSource({\n name: 'fetch',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginReactQuery\n"],"mappings":";;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;AAsBxD,MAAa,qBAAqB,sBAAwC;CACxE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,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vB,KAAK,MAAM,OAAO,gBAChB,IAAI,aAAa,IAAI;GAGvB,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,kBAAkB,CAAC,CAAC,IAAI,OAAO,SAAS,MAAM,MAAO,EAAwB,SAAS,iBAAiB;GAE7G,IAAI,QAAQ,UAAU,CAAC,mBAAmB,CAAC,kBACzC,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,eAAe,UAAUA,WAAoBC,OAAkB,CAAC;KACvF,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;GAGJ,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAWC,SAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginReactQuery } from '../types.ts'\n\nfunction capitalize(name: string): string {\n return `${name.charAt(0).toUpperCase()}${name.slice(1)}`\n}\n\n/**\n * Default resolver used by `@kubb/plugin-react-query`. Decides the names and\n * file paths for every generated TanStack Query hook (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`, ...) and its companion helpers\n * (`fooQueryKey`, `fooQueryOptions`).\n *\n * Functions and files use camelCase; hooks get the `use` prefix; suspense and\n * infinite variants are suffixed with `Suspense`/`Infinite`.\n *\n * @example Resolve hook and helper names\n * ```ts\n * import { resolverReactQuery } from '@kubb/plugin-react-query'\n *\n * resolverReactQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverReactQuery.resolveMutationName(operationNode) // 'useUpdatePet'\n * resolverReactQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverReactQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverReactQuery = defineResolver<PluginReactQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-react-query',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveSuspenseQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Suspense`\n },\n resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\n },\n resolveSuspenseInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`\n },\n resolveMutationName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}QueryOptions`\n },\n resolveSuspenseQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryOptions`\n },\n resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveSuspenseInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`\n },\n resolveMutationOptionsName(node) {\n return `${this.resolveName(node.operationId)}MutationOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveSuspenseQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`\n },\n resolveMutationKeyName(node) {\n return `${this.resolveName(node.operationId)}MutationKey`\n },\n resolveQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}QueryKey`\n },\n resolveSuspenseQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`\n },\n resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveSuspenseInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveSuspenseClientName(node) {\n return `${this.resolveName(node.operationId)}Suspense`\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\n },\n resolveSuspenseInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}SuspenseInfinite`\n },\n resolveHookOptionsName() {\n return 'HookOptions'\n },\n resolveCustomHookOptionsName() {\n return 'getCustomHookOptions'\n },\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mutationKeyTransformer, queryKeyTransformer } from '@internals/tanstack-query'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport { resolverReactQuery } from './resolvers/resolverReactQuery.ts'\nimport type { PluginReactQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\n/**\n * Generates one TanStack Query hook per OpenAPI operation for React. Queries\n * become `useFooQuery`/`useFooSuspenseQuery`/`useFooInfiniteQuery`; mutations\n * become `useFooMutation`. Each hook is fully typed: query keys, input\n * variables, response data, and error shape all come from the spec.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginReactQuery } from '@kubb/plugin-react-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginReactQuery({\n * output: { path: './hooks' },\n * suspense: {},\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutation = {},\n query = {},\n mutationKey = mutationKeyTransformer,\n queryKey = queryKeyTransformer,\n customOptions,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ??\n [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverReactQuery, ...userResolver } : resolverReactQuery\n\n ctx.setOptions({\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: null,\n nextParam: null,\n previousParam: null,\n ...infinite,\n }\n : false,\n suspense,\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : null,\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'client.ts',\n path: path.resolve(root, '.kubb/client.ts'),\n sources: [\n ast.createSource({\n name: 'client',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginReactQuery\n"],"mappings":";;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;AAsBxD,MAAa,qBAAqB,sBAAwC;CACxE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,WAAW;;CAEvC,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,iBAAiB,MAAM;EACrB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,yBAAyB,MAAM;EAC7B,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,iCAAiC,MAAM;EACrC,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC,CAAC;;CAE9D,oBAAoB,MAAM;EACxB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,wBAAwB,MAAM;EAC5B,OAAO,GAAG,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE/C,gCAAgC,MAAM;EACpC,OAAO,GAAG,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE/C,gCAAgC,MAAM;EACpC,OAAO,G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ACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
package/extension.yaml
CHANGED
|
@@ -428,7 +428,7 @@ options:
|
|
|
428
428
|
Without `importPath`:
|
|
429
429
|
|
|
430
430
|
- `bundle: false` (default) — generated code imports from `@kubb/plugin-client/clients/{axios|fetch}`.
|
|
431
|
-
- `bundle: true` — Kubb writes `.kubb/
|
|
431
|
+
- `bundle: true` — Kubb writes `.kubb/client.ts` and generated code imports from there.
|
|
432
432
|
- title: Required exports
|
|
433
433
|
body: |
|
|
434
434
|
The module pointed to by `importPath` must satisfy the same shape as the built-in client. At minimum:
|
|
@@ -440,7 +440,7 @@ options:
|
|
|
440
440
|
When used together with a query plugin (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`), it must also export a `Client` type alias.
|
|
441
441
|
- title: How generated files import it
|
|
442
442
|
body: |
|
|
443
|
-
Generated code imports the client as a default import and the runtime types as named type imports:
|
|
443
|
+
Generated code imports the client as a default import (bound to the local name `client`) and the runtime types as named type imports:
|
|
444
444
|
codeBlock:
|
|
445
445
|
lang: typescript
|
|
446
446
|
code: |
|
|
@@ -602,7 +602,7 @@ options:
|
|
|
602
602
|
Copies the HTTP client runtime into the generated output, so the consuming app does not need `@kubb/plugin-client` installed at runtime.
|
|
603
603
|
|
|
604
604
|
- `false` (default) — generated files import from `@kubb/plugin-client/clients/{client}`. Smaller diff, but the package must be a runtime dependency.
|
|
605
|
-
- `true` — Kubb writes a `.kubb/
|
|
605
|
+
- `true` — Kubb writes a `.kubb/client.ts` file with the client implementation. Generated code imports from that local file and the project no longer pulls `@kubb/plugin-client` at runtime.
|
|
606
606
|
- Setting `client.importPath` overrides both behaviors and uses your custom client instead.
|
|
607
607
|
examples:
|
|
608
608
|
- name: Bundle the runtime
|
|
@@ -701,7 +701,7 @@ options:
|
|
|
701
701
|
// ...mapped back to the original API name internally
|
|
702
702
|
const pet_id = petId
|
|
703
703
|
|
|
704
|
-
return
|
|
704
|
+
return client({
|
|
705
705
|
method: 'DELETE',
|
|
706
706
|
url: `/pet/${pet_id}`,
|
|
707
707
|
...config,
|
|
@@ -724,7 +724,7 @@ options:
|
|
|
724
724
|
headers?: DeletePetHeaderParams,
|
|
725
725
|
config: Partial<RequestConfig> = {},
|
|
726
726
|
) {
|
|
727
|
-
return
|
|
727
|
+
return client({
|
|
728
728
|
method: 'DELETE',
|
|
729
729
|
url: `/pet/${pet_id}`,
|
|
730
730
|
...config,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.28",
|
|
4
4
|
"description": "Generate type-safe TanStack Query (React Query) hooks from your OpenAPI specification. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with full TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"registry": "https://registry.npmjs.org/"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@kubb/core": "5.0.0-beta.
|
|
72
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
71
|
+
"@kubb/core": "5.0.0-beta.28",
|
|
72
|
+
"@kubb/renderer-jsx": "5.0.0-beta.28",
|
|
73
73
|
"remeda": "^2.34.1",
|
|
74
|
-
"@kubb/plugin-client": "5.0.0-beta.
|
|
75
|
-
"@kubb/plugin-ts": "5.0.0-beta.
|
|
76
|
-
"@kubb/plugin-zod": "5.0.0-beta.
|
|
74
|
+
"@kubb/plugin-client": "5.0.0-beta.28",
|
|
75
|
+
"@kubb/plugin-ts": "5.0.0-beta.28",
|
|
76
|
+
"@kubb/plugin-zod": "5.0.0-beta.28"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@internals/shared": "0.0.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@internals/utils": "0.0.0"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
84
|
+
"@kubb/renderer-jsx": "5.0.0-beta.28"
|
|
85
85
|
},
|
|
86
86
|
"size-limit": [
|
|
87
87
|
{
|
|
@@ -122,8 +122,8 @@ export const hookOptionsGenerator = defineGenerator<PluginReactQuery>({
|
|
|
122
122
|
baseName={hookOptionsFile.baseName}
|
|
123
123
|
path={hookOptionsFile.path}
|
|
124
124
|
meta={hookOptionsFile.meta}
|
|
125
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
126
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
125
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: hookOptionsFile.path, baseName: hookOptionsFile.baseName } })}
|
|
126
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: hookOptionsFile.path, baseName: hookOptionsFile.baseName } })}
|
|
127
127
|
>
|
|
128
128
|
{imports}
|
|
129
129
|
<File.Source name={name} isExportable isIndexable isTypeOnly>
|
|
@@ -103,27 +103,27 @@ export const infiniteQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
|
103
103
|
baseName={meta.file.baseName}
|
|
104
104
|
path={meta.file.path}
|
|
105
105
|
meta={meta.file.meta}
|
|
106
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
107
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
106
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
107
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
108
108
|
>
|
|
109
109
|
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
110
110
|
{clientOptions.importPath ? (
|
|
111
111
|
<>
|
|
112
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
112
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
113
113
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
114
114
|
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
115
115
|
</>
|
|
116
116
|
) : (
|
|
117
117
|
<>
|
|
118
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
118
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
119
119
|
<File.Import
|
|
120
120
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
121
121
|
root={meta.file.path}
|
|
122
|
-
path={path.resolve(root, '.kubb/
|
|
122
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
123
123
|
isTypeOnly
|
|
124
124
|
/>
|
|
125
125
|
{clientOptions.dataReturnType === 'full' && (
|
|
126
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/
|
|
126
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
127
127
|
)}
|
|
128
128
|
</>
|
|
129
129
|
)}
|
|
@@ -88,27 +88,27 @@ export const mutationGenerator = defineGenerator<PluginReactQuery>({
|
|
|
88
88
|
baseName={meta.file.baseName}
|
|
89
89
|
path={meta.file.path}
|
|
90
90
|
meta={meta.file.meta}
|
|
91
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
92
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
91
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
92
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
93
93
|
>
|
|
94
94
|
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
95
95
|
{clientOptions.importPath ? (
|
|
96
96
|
<>
|
|
97
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
97
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
98
98
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
99
99
|
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
100
100
|
</>
|
|
101
101
|
) : (
|
|
102
102
|
<>
|
|
103
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
103
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
104
104
|
<File.Import
|
|
105
105
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
106
106
|
root={meta.file.path}
|
|
107
|
-
path={path.resolve(root, '.kubb/
|
|
107
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
108
108
|
isTypeOnly
|
|
109
109
|
/>
|
|
110
110
|
{clientOptions.dataReturnType === 'full' && (
|
|
111
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/
|
|
111
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
112
112
|
)}
|
|
113
113
|
</>
|
|
114
114
|
)}
|
|
@@ -93,27 +93,27 @@ export const queryGenerator = defineGenerator<PluginReactQuery>({
|
|
|
93
93
|
baseName={meta.file.baseName}
|
|
94
94
|
path={meta.file.path}
|
|
95
95
|
meta={meta.file.meta}
|
|
96
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
97
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
96
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
97
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
98
98
|
>
|
|
99
99
|
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
100
100
|
{clientOptions.importPath ? (
|
|
101
101
|
<>
|
|
102
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
102
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
103
103
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
104
104
|
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
105
105
|
</>
|
|
106
106
|
) : (
|
|
107
107
|
<>
|
|
108
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
108
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
109
109
|
<File.Import
|
|
110
110
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
111
111
|
root={meta.file.path}
|
|
112
|
-
path={path.resolve(root, '.kubb/
|
|
112
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
113
113
|
isTypeOnly
|
|
114
114
|
/>
|
|
115
115
|
{clientOptions.dataReturnType === 'full' && (
|
|
116
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/
|
|
116
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
117
117
|
)}
|
|
118
118
|
</>
|
|
119
119
|
)}
|
|
@@ -112,27 +112,27 @@ export const suspenseInfiniteQueryGenerator = defineGenerator<PluginReactQuery>(
|
|
|
112
112
|
baseName={meta.file.baseName}
|
|
113
113
|
path={meta.file.path}
|
|
114
114
|
meta={meta.file.meta}
|
|
115
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
116
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
115
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
116
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
117
117
|
>
|
|
118
118
|
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
119
119
|
{clientOptions.importPath ? (
|
|
120
120
|
<>
|
|
121
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
121
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
122
122
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
123
123
|
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
124
124
|
</>
|
|
125
125
|
) : (
|
|
126
126
|
<>
|
|
127
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
127
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
128
128
|
<File.Import
|
|
129
129
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
130
130
|
root={meta.file.path}
|
|
131
|
-
path={path.resolve(root, '.kubb/
|
|
131
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
132
132
|
isTypeOnly
|
|
133
133
|
/>
|
|
134
134
|
{clientOptions.dataReturnType === 'full' && (
|
|
135
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/
|
|
135
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
136
136
|
)}
|
|
137
137
|
</>
|
|
138
138
|
)}
|
|
@@ -95,27 +95,27 @@ export const suspenseQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
|
95
95
|
baseName={meta.file.baseName}
|
|
96
96
|
path={meta.file.path}
|
|
97
97
|
meta={meta.file.meta}
|
|
98
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config })}
|
|
99
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config })}
|
|
98
|
+
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
99
|
+
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
100
100
|
>
|
|
101
101
|
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
102
102
|
{clientOptions.importPath ? (
|
|
103
103
|
<>
|
|
104
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
104
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
105
105
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
106
106
|
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
107
107
|
</>
|
|
108
108
|
) : (
|
|
109
109
|
<>
|
|
110
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
110
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
111
111
|
<File.Import
|
|
112
112
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
113
113
|
root={meta.file.path}
|
|
114
|
-
path={path.resolve(root, '.kubb/
|
|
114
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
115
115
|
isTypeOnly
|
|
116
116
|
/>
|
|
117
117
|
{clientOptions.dataReturnType === 'full' && (
|
|
118
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/
|
|
118
|
+
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
119
119
|
)}
|
|
120
120
|
</>
|
|
121
121
|
)}
|
package/src/plugin.ts
CHANGED
|
@@ -180,11 +180,11 @@ export const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {
|
|
|
180
180
|
|
|
181
181
|
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
182
182
|
ctx.injectFile({
|
|
183
|
-
baseName: '
|
|
184
|
-
path: path.resolve(root, '.kubb/
|
|
183
|
+
baseName: 'client.ts',
|
|
184
|
+
path: path.resolve(root, '.kubb/client.ts'),
|
|
185
185
|
sources: [
|
|
186
186
|
ast.createSource({
|
|
187
|
-
name: '
|
|
187
|
+
name: 'client',
|
|
188
188
|
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
189
189
|
isExportable: true,
|
|
190
190
|
isIndexable: true,
|