@kubb/plugin-react-query 5.0.0-beta.42 → 5.0.0-beta.56
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/{components-IArDg-DO.js → components-DL0Cai7l.js} +211 -255
- package/dist/components-DL0Cai7l.js.map +1 -0
- package/dist/{components-DQAYLQW0.cjs → components-yMQOuFmI.cjs} +215 -259
- package/dist/components-yMQOuFmI.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-B86BJkmW.js → generators-BG-Vcvfg.js} +151 -231
- package/dist/generators-BG-Vcvfg.js.map +1 -0
- package/dist/{generators-BqGaMUH6.cjs → generators-zGKP8yII.cjs} +149 -229
- package/dist/generators-zGKP8yII.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +35 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/dist/{types-Dh4HNR9K.d.ts → types-X7D0NSvJ.d.ts} +11 -15
- package/package.json +10 -17
- package/src/components/InfiniteQuery.tsx +4 -5
- package/src/components/InfiniteQueryOptions.tsx +24 -27
- package/src/components/Mutation.tsx +5 -6
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +5 -6
- package/src/components/QueryOptions.tsx +6 -25
- package/src/components/SuspenseInfiniteQuery.tsx +4 -5
- package/src/components/SuspenseInfiniteQueryOptions.tsx +24 -25
- package/src/components/SuspenseQuery.tsx +5 -6
- package/src/generators/customHookOptionsFileGenerator.tsx +2 -2
- package/src/generators/hookOptionsGenerator.tsx +2 -2
- package/src/generators/infiniteQueryGenerator.tsx +5 -9
- package/src/generators/mutationGenerator.tsx +8 -9
- package/src/generators/queryGenerator.tsx +5 -9
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +5 -9
- package/src/generators/suspenseQueryGenerator.tsx +5 -9
- package/src/plugin.ts +4 -4
- package/src/resolvers/resolverReactQuery.ts +2 -2
- package/src/types.ts +9 -13
- package/src/utils.ts +1 -0
- package/dist/components-DQAYLQW0.cjs.map +0 -1
- package/dist/components-IArDg-DO.js.map +0 -1
- package/dist/generators-B86BJkmW.js.map +0 -1
- package/dist/generators-BqGaMUH6.cjs.map +0 -1
- package/extension.yaml +0 -1484
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../../../internals/shared/src/group.ts","../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport type { Group } from '@kubb/core'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n * @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.\n *\n * @example\n * ```ts\n * createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-client, …\n * createGroupConfig(group, { suffix: 'Requests' }) // plugin-cypress, plugin-mcp\n * ```\n */\nexport function createGroupConfig(group: Group | undefined, options: { suffix: string }): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return `${camelCase(ctx.group)}${options.suffix}`\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","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 { createGroupConfig } from '@internals/shared'\nimport { ast, definePlugin } 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 = false,\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 = createGroupConfig(group, { suffix: 'Controller' })\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBAAkB,OAA0B,SAA2C;CACrG,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,eAAe,QAAmC;EACtD,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,GAAG,EAAE;EAGjC,OAAO,GAAG,UAAU,IAAI,KAAK,IAAI,QAAQ;CAC3C;CAEA,OAAO;EACL,GAAG;EACH,MAAM,MAAM,OAAO,MAAM,OAAO;CAClC;AACF;;;ACpCA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AACvD;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,qBAAqB,sBAAwC;CACxE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC;CACpD;CACA,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,UAAU;CACtC;CACA,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,IAAI;CAChC;CACA,iBAAiB,MAAM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,IAAI,OAAO,SAAS,MAAM,MAAO,EAAwB,SAAS,gBAAgB;GAE5G,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,MAAiB,CAAC;KACtF,cAAc;KACd,aAAa;IACf,CAAC,CACH;GACF,CAAC;GAGH,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAWC,QAAY,CAAC;KACpC,cAAc;KACd,aAAa;IACf,CAAC,CACH;GACF,CAAC;EAEL,EACF;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../../../internals/utils/src/fs.ts","../../../internals/shared/src/group.ts","../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { posix } from 'node:path'\nimport { camelCase } from './casing.ts'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","import { camelCase } from '@internals/utils'\nimport type { Group } from '@kubb/core'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { camelCase, toFilePath } 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 type === 'file' ? toFilePath(name) : camelCase(name)\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 { createGroupConfig } from '@internals/shared'\nimport { ast, definePlugin } from '@kubb/core'\nimport { isParserEnabled, 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', barrel: { type: 'named' } },\n group,\n exclude = [],\n include,\n override = [],\n parser = false,\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 = createGroupConfig(group)\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, isParserEnabled(parser) ? 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,WAAW,MAAc,WAAqC,WAAmB;CAC/F,MAAM,QAAQ,KAAK,MAAM,gBAAgB;CACzC,OAAO,MACJ,KAAK,MAAM,MAAO,MAAM,MAAM,SAAS,IAAI,SAAS,IAAI,IAAI,UAAU,IAAI,CAAE,CAAC,CAC7E,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;AACb;;;;;;;;;;;;;;;;;;;;;AChCA,SAAgB,kBAAkB,OAAwC;CACxE,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,eAAe,QAAmC;EACtD,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC;EAGjC,OAAO,UAAU,IAAI,KAAK;CAC5B;CAEA,OAAO;EACL,GAAG;EACH,MAAM,MAAM,OAAO,MAAM,OAAO;CAClC;AACF;;;AClCA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC;AACvD;;;;;;;;;;;;;;;;;;;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AAO;IACP;IACA;IACA;IACA;GACF,CAAC;GACD,IAAI,YAAY,QAAQ;GACxB,IAAI,iBACF,IAAI,eAAe,eAAe;GAGpC,KAAK,MAAM,OAAO,oBAChB,IAAI,aAAa,GAAG;GAEtB,KAAK,MAAM,OAAO,gBAChB,IAAI,aAAa,GAAG;GAGtB,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,kBAAkB,CAAC,CAAC,IAAI,OAAO,SAAS,MAAM,MAAO,EAAwB,SAAS,gBAAgB;GAE5G,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,MAAiB,CAAC;KACtF,cAAc;KACd,aAAa;IACf,CAAC,CACH;GACF,CAAC;GAGH,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAWC,QAAY,CAAC;KACpC,cAAc;KACd,aAAa;IACf,CAAC,CACH;GACF,CAAC;EAEL,EACF;CACF;AACF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
2
|
+
import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
3
3
|
import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
|
|
4
|
-
import { PluginTs } from "@kubb/plugin-ts";
|
|
4
|
+
import { PluginTs, ResolverTs } from "@kubb/plugin-ts";
|
|
5
5
|
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
6
6
|
|
|
7
7
|
//#region ../../internals/tanstack-query/src/types.d.ts
|
|
@@ -259,17 +259,13 @@ type CustomOptions = {
|
|
|
259
259
|
*/
|
|
260
260
|
name?: string;
|
|
261
261
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Split generated files into subfolders based on the operation's tag.
|
|
271
|
-
*/
|
|
272
|
-
group?: Group;
|
|
262
|
+
/**
|
|
263
|
+
* Where the generated hooks are written and how they are exported, plus the optional `group`
|
|
264
|
+
* strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
265
|
+
*
|
|
266
|
+
* @default { path: 'hooks', barrel: { type: 'named' } }
|
|
267
|
+
*/
|
|
268
|
+
type Options = OutputOptions & {
|
|
273
269
|
/**
|
|
274
270
|
* HTTP client used inside every generated hook. Mirrors a subset of
|
|
275
271
|
* `pluginClient` options.
|
|
@@ -371,7 +367,7 @@ type ResolvedOptions = {
|
|
|
371
367
|
include: Options['include'];
|
|
372
368
|
override: NonNullable<Options['override']>;
|
|
373
369
|
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
|
|
374
|
-
parser:
|
|
370
|
+
parser: NonNullable<Options['parser']>;
|
|
375
371
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
376
372
|
paramsCasing: Options['paramsCasing'];
|
|
377
373
|
paramsType: NonNullable<Options['paramsType']>;
|
|
@@ -397,4 +393,4 @@ declare global {
|
|
|
397
393
|
}
|
|
398
394
|
//#endregion
|
|
399
395
|
export { MutationKey$1 as a, QueryKey$1 as i, Options as n, PluginReactQuery as r, Infinite as t };
|
|
400
|
-
//# sourceMappingURL=types-
|
|
396
|
+
//# sourceMappingURL=types-X7D0NSvJ.d.ts.map
|
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.56",
|
|
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",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"src",
|
|
30
30
|
"dist",
|
|
31
|
-
"extension.yaml",
|
|
32
31
|
"!/**/**.test.**",
|
|
33
32
|
"!/**/__tests__/**",
|
|
34
33
|
"!/**/__snapshots__/**"
|
|
@@ -68,11 +67,12 @@
|
|
|
68
67
|
"registry": "https://registry.npmjs.org/"
|
|
69
68
|
},
|
|
70
69
|
"dependencies": {
|
|
71
|
-
"@kubb/
|
|
72
|
-
"@kubb/
|
|
73
|
-
"@kubb/
|
|
74
|
-
"@kubb/plugin-
|
|
75
|
-
"@kubb/plugin-
|
|
70
|
+
"@kubb/ast": "5.0.0-beta.55",
|
|
71
|
+
"@kubb/core": "5.0.0-beta.55",
|
|
72
|
+
"@kubb/renderer-jsx": "5.0.0-beta.55",
|
|
73
|
+
"@kubb/plugin-client": "5.0.0-beta.56",
|
|
74
|
+
"@kubb/plugin-ts": "5.0.0-beta.56",
|
|
75
|
+
"@kubb/plugin-zod": "5.0.0-beta.56"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@internals/shared": "0.0.0",
|
|
@@ -80,21 +80,14 @@
|
|
|
80
80
|
"@internals/utils": "0.0.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
83
|
+
"@kubb/renderer-jsx": "5.0.0-beta.55"
|
|
84
84
|
},
|
|
85
|
-
"size-limit": [
|
|
86
|
-
{
|
|
87
|
-
"path": "./dist/*.js",
|
|
88
|
-
"limit": "510 KiB",
|
|
89
|
-
"gzip": true
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
85
|
"engines": {
|
|
93
86
|
"node": ">=22"
|
|
94
87
|
},
|
|
95
88
|
"scripts": {
|
|
96
|
-
"build": "tsdown
|
|
97
|
-
"clean": "
|
|
89
|
+
"build": "tsdown",
|
|
90
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
98
91
|
"lint": "oxlint .",
|
|
99
92
|
"lint:fix": "oxlint --fix .",
|
|
100
93
|
"release": "pnpm publish --no-git-check",
|
|
@@ -6,7 +6,7 @@ import { File, Function } from '@kubb/renderer-jsx'
|
|
|
6
6
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
7
7
|
import type { Infinite, PluginReactQuery } from '../types.ts'
|
|
8
8
|
import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
9
|
-
import { buildQueryKeyParams, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
|
+
import { buildQueryKeyParams, buildStatusUnionType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
10
10
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
@@ -82,7 +82,7 @@ export function InfiniteQuery({
|
|
|
82
82
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
83
83
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
84
84
|
|
|
85
|
-
const responseType = dataReturnType === 'data' ? responseName :
|
|
85
|
+
const responseType = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
86
86
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
87
87
|
|
|
88
88
|
const isInitialPageParamDefined = initialPageParam !== undefined && initialPageParam !== null
|
|
@@ -148,11 +148,10 @@ export function InfiniteQuery({
|
|
|
148
148
|
{`
|
|
149
149
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
150
150
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
151
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
152
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
151
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
153
152
|
|
|
154
153
|
const query = useInfiniteQuery({
|
|
155
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n...customOptions,' : ''}
|
|
154
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n ...customOptions,' : ''}
|
|
156
155
|
...resolvedOptions,
|
|
157
156
|
queryKey,
|
|
158
157
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getOperationParameters } from '@internals/shared'
|
|
2
|
-
import { getNestedAccessor } from '@
|
|
2
|
+
import { getNestedAccessor } from '@kubb/ast/utils'
|
|
3
3
|
import type { ast } from '@kubb/core'
|
|
4
4
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
5
5
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
6
6
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
7
7
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
8
8
|
import type { Infinite, PluginReactQuery } from '../types.ts'
|
|
9
|
-
import { buildQueryKeyParams, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
|
+
import { buildQueryKeyParams, buildStatusUnionType, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
10
10
|
import { getEnabledParamNames, injectNonNullAssertions, markParamsOptional } from '@internals/tanstack-query'
|
|
11
11
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
12
12
|
|
|
@@ -48,7 +48,7 @@ export function InfiniteQueryOptions({
|
|
|
48
48
|
}: Props): KubbReactNode {
|
|
49
49
|
const successNames = resolveSuccessNames(node, tsResolver)
|
|
50
50
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
51
|
-
const queryFnDataType = dataReturnType === 'data' ? responseName :
|
|
51
|
+
const queryFnDataType = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
52
52
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
53
53
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
54
54
|
|
|
@@ -121,11 +121,10 @@ export function InfiniteQueryOptions({
|
|
|
121
121
|
|
|
122
122
|
const infiniteOverrideParams =
|
|
123
123
|
queryParam && queryParamsTypeName
|
|
124
|
-
? `
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} as ${queryParamsTypeName}`
|
|
124
|
+
? `params = {
|
|
125
|
+
...(params ?? {}),
|
|
126
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
127
|
+
} as ${queryParamsTypeName}`
|
|
129
128
|
: ''
|
|
130
129
|
|
|
131
130
|
if (infiniteOverrideParams) {
|
|
@@ -133,16 +132,15 @@ export function InfiniteQueryOptions({
|
|
|
133
132
|
<File.Source name={name} isExportable isIndexable>
|
|
134
133
|
<Function name={name} export params={paramsSignature}>
|
|
135
134
|
{`
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
})
|
|
135
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
136
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ''}
|
|
137
|
+
queryKey,
|
|
138
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
139
|
+
${infiniteOverrideParams}
|
|
140
|
+
return ${clientName}(${clientCallStr})
|
|
141
|
+
},
|
|
142
|
+
${queryOptionsArr.join(',\n ')}
|
|
143
|
+
})
|
|
146
144
|
`}
|
|
147
145
|
</Function>
|
|
148
146
|
</File.Source>
|
|
@@ -153,15 +151,14 @@ export function InfiniteQueryOptions({
|
|
|
153
151
|
<File.Source name={name} isExportable isIndexable>
|
|
154
152
|
<Function name={name} export params={paramsSignature}>
|
|
155
153
|
{`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
})
|
|
154
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
155
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ''}
|
|
156
|
+
queryKey,
|
|
157
|
+
queryFn: async ({ signal }) => {
|
|
158
|
+
return ${clientName}(${clientCallStr})
|
|
159
|
+
},
|
|
160
|
+
${queryOptionsArr.join(',\n ')}
|
|
161
|
+
})
|
|
165
162
|
`}
|
|
166
163
|
</Function>
|
|
167
164
|
</File.Source>
|
|
@@ -4,7 +4,7 @@ import { functionPrinter } from '@kubb/plugin-ts'
|
|
|
4
4
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import type { PluginReactQuery } from '../types.ts'
|
|
7
|
-
import { buildRequestConfigType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
7
|
+
import { buildRequestConfigType, buildStatusUnionType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
8
8
|
import { buildMutationConfigParamsNode } from './MutationOptions.tsx'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
@@ -51,7 +51,7 @@ function buildMutationParamsNode(
|
|
|
51
51
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : resolver.resolveResponseName(node)
|
|
52
52
|
const errorNames = resolveErrorNames(node, resolver)
|
|
53
53
|
|
|
54
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
54
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, resolver)
|
|
55
55
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
56
56
|
|
|
57
57
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
@@ -83,7 +83,7 @@ export function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnTy
|
|
|
83
83
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
84
84
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
85
85
|
|
|
86
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
86
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
87
87
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
88
88
|
|
|
89
89
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
@@ -108,11 +108,10 @@ export function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnTy
|
|
|
108
108
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
109
109
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
110
110
|
|
|
111
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
112
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ''}
|
|
111
|
+
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ''}
|
|
113
112
|
|
|
114
113
|
return useMutation<${generics}>({
|
|
115
|
-
...baseOptions,${customOptions ? '\n...customOptions,' : ''}
|
|
114
|
+
...baseOptions,${customOptions ? '\n ...customOptions,' : ''}
|
|
116
115
|
mutationKey,
|
|
117
116
|
...mutationOptions,
|
|
118
117
|
}, queryClient) as ${returnType}
|
|
@@ -4,7 +4,7 @@ import { functionPrinter } from '@kubb/plugin-ts'
|
|
|
4
4
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import type { PluginReactQuery } from '../types.ts'
|
|
7
|
-
import { buildRequestConfigType, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
7
|
+
import { buildRequestConfigType, buildStatusUnionType, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
10
|
name: string
|
|
@@ -50,7 +50,7 @@ export function MutationOptions({
|
|
|
50
50
|
}: Props): KubbReactNode {
|
|
51
51
|
const successNames = resolveSuccessNames(node, tsResolver)
|
|
52
52
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
53
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
53
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
54
54
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
55
55
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
56
56
|
|
package/src/components/Query.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { File, Function } from '@kubb/renderer-jsx'
|
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import type { PluginReactQuery } from '../types.ts'
|
|
7
7
|
import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
8
|
-
import { buildQueryKeyParams, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
8
|
+
import { buildQueryKeyParams, buildStatusUnionType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
9
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
10
10
|
|
|
11
11
|
type Props = {
|
|
@@ -41,7 +41,7 @@ function buildQueryParamsNode(
|
|
|
41
41
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
|
|
42
42
|
const errorNames = resolveErrorNames(node, resolver)
|
|
43
43
|
|
|
44
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
44
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, resolver)
|
|
45
45
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
46
46
|
|
|
47
47
|
const optionsParam = ast.createFunctionParameter({
|
|
@@ -82,7 +82,7 @@ export function Query({
|
|
|
82
82
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
83
83
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
84
84
|
|
|
85
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
85
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
86
86
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
87
87
|
const returnType = `UseQueryResult<${'TData'}, ${TError}> & { queryKey: TQueryKey }`
|
|
88
88
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
@@ -106,11 +106,10 @@ export function Query({
|
|
|
106
106
|
{`
|
|
107
107
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
108
108
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
109
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
110
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
109
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
111
110
|
|
|
112
111
|
const query = useQuery({
|
|
113
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n...customOptions,' : ''}
|
|
112
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n ...customOptions,' : ''}
|
|
114
113
|
...resolvedOptions,
|
|
115
114
|
queryKey,
|
|
116
115
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ast } from '@kubb/core'
|
|
1
|
+
import type { ast } from '@kubb/core'
|
|
2
2
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
3
3
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
4
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
|
-
import { getEnabledParamNames, injectNonNullAssertions, markParamsOptional } from '@internals/tanstack-query'
|
|
6
|
+
import { buildQueryOptionsParams, getEnabledParamNames, injectNonNullAssertions, markParamsOptional } from '@internals/tanstack-query'
|
|
7
7
|
import type { PluginReactQuery } from '../types.ts'
|
|
8
|
-
import { buildQueryKeyParams, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
8
|
+
import { buildQueryKeyParams, buildStatusUnionType, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
name: string
|
|
@@ -32,25 +32,7 @@ export function getQueryOptionsParams(
|
|
|
32
32
|
resolver: ResolverTs
|
|
33
33
|
},
|
|
34
34
|
): ast.FunctionParametersNode {
|
|
35
|
-
|
|
36
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
|
|
37
|
-
|
|
38
|
-
return ast.createOperationParams(node, {
|
|
39
|
-
paramsType,
|
|
40
|
-
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType === 'object' ? 'object' : 'inline',
|
|
41
|
-
paramsCasing,
|
|
42
|
-
resolver,
|
|
43
|
-
extraParams: [
|
|
44
|
-
ast.createFunctionParameter({
|
|
45
|
-
name: 'config',
|
|
46
|
-
type: ast.createParamsType({
|
|
47
|
-
variant: 'reference',
|
|
48
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }',
|
|
49
|
-
}),
|
|
50
|
-
default: '{}',
|
|
51
|
-
}),
|
|
52
|
-
],
|
|
53
|
-
})
|
|
35
|
+
return buildQueryOptionsParams(node, options)
|
|
54
36
|
}
|
|
55
37
|
|
|
56
38
|
export function QueryOptions({
|
|
@@ -69,7 +51,7 @@ export function QueryOptions({
|
|
|
69
51
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
70
52
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
71
53
|
|
|
72
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
54
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
73
55
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
74
56
|
|
|
75
57
|
const queryKeyParamsNode = buildQueryKeyParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
@@ -90,8 +72,7 @@ export function QueryOptions({
|
|
|
90
72
|
<Function name={name} export params={paramsSignature}>
|
|
91
73
|
{`
|
|
92
74
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
93
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
94
|
-
${enabledText}
|
|
75
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ''}
|
|
95
76
|
queryKey,
|
|
96
77
|
queryFn: async ({ signal }) => {
|
|
97
78
|
return ${clientName}(${clientCallStr})
|
|
@@ -5,7 +5,7 @@ import { functionPrinter } from '@kubb/plugin-ts'
|
|
|
5
5
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
6
6
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
7
7
|
import type { Infinite, PluginReactQuery } from '../types.ts'
|
|
8
|
-
import { buildQueryKeyParams, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
8
|
+
import { buildQueryKeyParams, buildStatusUnionType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
9
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
10
10
|
|
|
11
11
|
type Props = {
|
|
@@ -81,7 +81,7 @@ export function SuspenseInfiniteQuery({
|
|
|
81
81
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
82
82
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
83
83
|
|
|
84
|
-
const responseType = dataReturnType === 'data' ? responseName :
|
|
84
|
+
const responseType = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
85
85
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
86
86
|
|
|
87
87
|
const isInitialPageParamDefined = initialPageParam !== undefined && initialPageParam !== null
|
|
@@ -143,11 +143,10 @@ export function SuspenseInfiniteQuery({
|
|
|
143
143
|
{`
|
|
144
144
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
145
145
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
146
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
147
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
146
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
148
147
|
|
|
149
148
|
const query = useSuspenseInfiniteQuery({
|
|
150
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n...customOptions,' : ''}
|
|
149
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n ...customOptions,' : ''}
|
|
151
150
|
...resolvedOptions,
|
|
152
151
|
queryKey,
|
|
153
152
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getOperationParameters } from '@internals/shared'
|
|
2
|
-
import { getNestedAccessor } from '@
|
|
2
|
+
import { getNestedAccessor } from '@kubb/ast/utils'
|
|
3
3
|
import type { ast } from '@kubb/core'
|
|
4
4
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
5
5
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
6
6
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
7
7
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
8
8
|
import type { Infinite, PluginReactQuery } from '../types.ts'
|
|
9
|
-
import { buildQueryKeyParams, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
9
|
+
import { buildQueryKeyParams, buildStatusUnionType, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
10
10
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
@@ -47,7 +47,7 @@ export function SuspenseInfiniteQueryOptions({
|
|
|
47
47
|
}: Props): KubbReactNode {
|
|
48
48
|
const successNames = resolveSuccessNames(node, tsResolver)
|
|
49
49
|
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
50
|
-
const queryFnDataType = dataReturnType === 'data' ? responseName :
|
|
50
|
+
const queryFnDataType = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
51
51
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
52
52
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
53
53
|
|
|
@@ -117,11 +117,10 @@ export function SuspenseInfiniteQueryOptions({
|
|
|
117
117
|
|
|
118
118
|
const infiniteOverrideParams =
|
|
119
119
|
queryParam && queryParamsTypeName
|
|
120
|
-
? `
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
} as ${queryParamsTypeName}`
|
|
120
|
+
? `params = {
|
|
121
|
+
...(params ?? {}),
|
|
122
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
123
|
+
} as ${queryParamsTypeName}`
|
|
125
124
|
: ''
|
|
126
125
|
|
|
127
126
|
if (infiniteOverrideParams) {
|
|
@@ -129,15 +128,15 @@ export function SuspenseInfiniteQueryOptions({
|
|
|
129
128
|
<File.Source name={name} isExportable isIndexable>
|
|
130
129
|
<Function name={name} export params={paramsSignature}>
|
|
131
130
|
{`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
132
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
133
|
+
queryKey,
|
|
134
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
135
|
+
${infiniteOverrideParams}
|
|
136
|
+
return ${clientName}(${clientCallStr})
|
|
137
|
+
},
|
|
138
|
+
${queryOptionsArr.join(',\n ')}
|
|
139
|
+
})
|
|
141
140
|
`}
|
|
142
141
|
</Function>
|
|
143
142
|
</File.Source>
|
|
@@ -148,14 +147,14 @@ export function SuspenseInfiniteQueryOptions({
|
|
|
148
147
|
<File.Source name={name} isExportable isIndexable>
|
|
149
148
|
<Function name={name} export params={paramsSignature}>
|
|
150
149
|
{`
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
151
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
152
|
+
queryKey,
|
|
153
|
+
queryFn: async ({ signal }) => {
|
|
154
|
+
return ${clientName}(${clientCallStr})
|
|
155
|
+
},
|
|
156
|
+
${queryOptionsArr.join(',\n ')}
|
|
157
|
+
})
|
|
159
158
|
`}
|
|
160
159
|
</Function>
|
|
161
160
|
</File.Source>
|