@kubb/plugin-vue-query 5.0.0-beta.30 → 5.0.0-beta.33
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-CIedagno.cjs → components-B6lPYyOP.cjs} +134 -63
- package/dist/components-B6lPYyOP.cjs.map +1 -0
- package/dist/{components-B4IlVmNa.js → components-BZqujNQv.js} +129 -64
- package/dist/components-BZqujNQv.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-ClYptnDj.js → generators-C-3isXzW.js} +18 -75
- package/dist/generators-C-3isXzW.js.map +1 -0
- package/dist/{generators-D7kNtBBo.cjs → generators-QHQkbNnm.cjs} +17 -74
- package/dist/generators-QHQkbNnm.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +40 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -10
- package/dist/index.js.map +1 -1
- package/extension.yaml +7 -32
- package/package.json +8 -8
- package/src/components/InfiniteQuery.tsx +6 -1
- package/src/components/InfiniteQueryOptions.tsx +15 -18
- package/src/components/Query.tsx +6 -1
- package/src/components/QueryKey.tsx +3 -2
- package/src/components/QueryOptions.tsx +14 -17
- package/src/generators/infiniteQueryGenerator.tsx +19 -22
- package/src/generators/mutationGenerator.tsx +19 -22
- package/src/generators/queryGenerator.tsx +19 -22
- package/src/plugin.ts +4 -16
- package/dist/components-B4IlVmNa.js.map +0 -1
- package/dist/components-CIedagno.cjs.map +0 -1
- package/dist/generators-ClYptnDj.js.map +0 -1
- package/dist/generators-D7kNtBBo.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_components = require("./components-
|
|
6
|
-
const require_generators = require("./generators-
|
|
5
|
+
const require_components = require("./components-B6lPYyOP.cjs");
|
|
6
|
+
const require_generators = require("./generators-QHQkbNnm.cjs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_components.__toESM(node_path, 1);
|
|
9
9
|
let _kubb_core = require("@kubb/core");
|
|
@@ -13,6 +13,39 @@ let _kubb_plugin_client_templates_clients_fetch_source = require("@kubb/plugin-c
|
|
|
13
13
|
let _kubb_plugin_client_templates_config_source = require("@kubb/plugin-client/templates/config.source");
|
|
14
14
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
15
15
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
16
|
+
//#region ../../internals/shared/src/group.ts
|
|
17
|
+
/**
|
|
18
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
19
|
+
* shared default naming so every plugin groups output consistently:
|
|
20
|
+
*
|
|
21
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
22
|
+
* - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).
|
|
23
|
+
*
|
|
24
|
+
* Returns `null` when grouping is disabled, matching the per-plugin convention.
|
|
25
|
+
*
|
|
26
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
27
|
+
* @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.
|
|
28
|
+
* @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod
|
|
33
|
+
* createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …
|
|
34
|
+
* createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function createGroupConfig(group, options) {
|
|
38
|
+
if (!group) return null;
|
|
39
|
+
const defaultName = (ctx) => {
|
|
40
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
41
|
+
return `${require_components.camelCase(ctx.group)}${options.suffix}`;
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
...group,
|
|
45
|
+
name: options.honorName && group.name ? group.name : defaultName
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
16
49
|
//#region src/resolvers/resolverVueQuery.ts
|
|
17
50
|
function capitalize(name) {
|
|
18
51
|
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
@@ -120,7 +153,7 @@ const pluginVueQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
120
153
|
const { output = {
|
|
121
154
|
path: "hooks",
|
|
122
155
|
barrelType: "named"
|
|
123
|
-
}, group, exclude = [], include, override = [], parser =
|
|
156
|
+
}, group, exclude = [], include, override = [], parser = false, infinite = false, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = require_components.mutationKeyTransformer, queryKey = require_components.queryKeyTransformer, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
124
157
|
const clientName = client?.client ?? "axios";
|
|
125
158
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
126
159
|
const selectedGenerators = options.generators ?? [
|
|
@@ -128,13 +161,10 @@ const pluginVueQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
128
161
|
require_generators.infiniteQueryGenerator,
|
|
129
162
|
require_generators.mutationGenerator
|
|
130
163
|
].filter((generator) => Boolean(generator));
|
|
131
|
-
const groupConfig = group
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return `${require_components.camelCase(ctx.group)}Controller`;
|
|
136
|
-
}
|
|
137
|
-
} : null;
|
|
164
|
+
const groupConfig = createGroupConfig(group, {
|
|
165
|
+
suffix: "Controller",
|
|
166
|
+
honorName: true
|
|
167
|
+
});
|
|
138
168
|
return {
|
|
139
169
|
name: pluginVueQueryName,
|
|
140
170
|
options,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["camelCase","mutationKeyTransformer","queryKeyTransformer","queryGenerator","infiniteQueryGenerator","mutationGenerator","camelCase","pluginTsName","pluginZodName","path","pluginClientName","ast","fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverVueQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginVueQuery } 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-vue-query`. Decides the names and\n * file paths for every generated TanStack Query composable (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`) and its companion helpers.\n *\n * Functions and files use camelCase; composables get the `use` prefix.\n *\n * @example Resolve composable and helper names\n * ```ts\n * import { resolverVueQuery } from '@kubb/plugin-vue-query'\n *\n * resolverVueQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverVueQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverVueQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-vue-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 resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\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 resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\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 resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\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 } from '@internals/tanstack-query'\nimport { queryKeyTransformer } from '@internals/tanstack-query'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'\nimport { resolverVueQuery } from './resolvers/resolverVueQuery.ts'\nimport type { PluginVueQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']\n\n/**\n * Generates one TanStack Query composable per OpenAPI operation for Vue's\n * Composition API. Queries become `useFooQuery` (and optionally\n * `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable\n * is fully typed end to end.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginVueQuery } from '@kubb/plugin-vue-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginVueQuery({\n * output: { path: './hooks' },\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\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 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 [queryGenerator, infiniteQueryGenerator, mutationGenerator].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: pluginVueQueryName,\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 ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery\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/vue-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/vue-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 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 pluginVueQuery\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;AAmBxD,MAAa,oBAAA,GAAA,WAAA,uBAAyD;CACpE,MAAM;CACN,Y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Aa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["camelCase","camelCase","mutationKeyTransformer","queryKeyTransformer","queryGenerator","infiniteQueryGenerator","mutationGenerator","pluginTsName","pluginZodName","path","pluginClientName","ast","fetchClientSource","axiosClientSource","configSource"],"sources":["../../../internals/shared/src/group.ts","../src/resolvers/resolverVueQuery.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 * Returns `null` when grouping is disabled, matching the 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 * @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.\n *\n * @example\n * ```ts\n * createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod\n * createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …\n * createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp\n * ```\n */\nexport function createGroupConfig(group: Group | undefined, options: { suffix: string; honorName?: boolean }): 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: options.honorName && group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginVueQuery } 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-vue-query`. Decides the names and\n * file paths for every generated TanStack Query composable (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`) and its companion helpers.\n *\n * Functions and files use camelCase; composables get the `use` prefix.\n *\n * @example Resolve composable and helper names\n * ```ts\n * import { resolverVueQuery } from '@kubb/plugin-vue-query'\n *\n * resolverVueQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverVueQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverVueQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-vue-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 resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\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 resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\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 resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\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 } from '@internals/tanstack-query'\nimport { queryKeyTransformer } from '@internals/tanstack-query'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'\nimport { resolverVueQuery } from './resolvers/resolverVueQuery.ts'\nimport type { PluginVueQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']\n\n/**\n * Generates one TanStack Query composable per OpenAPI operation for Vue's\n * Composition API. Queries become `useFooQuery` (and optionally\n * `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable\n * is fully typed end to end.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginVueQuery } from '@kubb/plugin-vue-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginVueQuery({\n * output: { path: './hooks' },\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = false,\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 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 [queryGenerator, infiniteQueryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = createGroupConfig(group, { suffix: 'Controller', honorName: true })\n\n return {\n name: pluginVueQueryName,\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 ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery\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/vue-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/vue-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 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 pluginVueQuery\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBAAkB,OAA0B,SAAgE;CAC1H,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,eAAe,QAAmC;EACtD,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;EAGjC,OAAO,GAAGA,mBAAAA,UAAU,IAAI,MAAM,GAAG,QAAQ;;CAG3C,OAAO;EACL,GAAG;EACH,MAAM,QAAQ,aAAa,MAAM,OAAO,MAAM,OAAO;EACtD;;;;ACnCH,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;AAmBxD,MAAa,oBAAA,GAAA,WAAA,uBAAyD;CACpE,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAOC,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,KA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,gBAAgB;GAGrC,KAAK,MAAM,OAAO,oBAChB,IAAI,aAAa,IAAI;GAEvB,KAAK,MAAM,OAAO,gBAChB,IAAI,aAAa,IAAI;GAGvB,MAAM,OAAOC,UAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,kBAAkB,CAAC,CAAC,IAAI,OAAO,SAAS,MAAM,MAAO,EAAwB,SAASC,oBAAAA,iBAAiB;GAE7G,IAAI,QAAQ,UAAU,CAAC,mBAAmB,CAAC,kBACzC,IAAI,WAAW;IACb,UAAU;IACV,MAAMD,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as mutationGenerator, r as infiniteQueryGenerator, t as queryGenerator } from "./generators-
|
|
2
|
+
import { m as camelCase, s as queryKeyTransformer, u as mutationKeyTransformer } from "./components-BZqujNQv.js";
|
|
3
|
+
import { n as mutationGenerator, r as infiniteQueryGenerator, t as queryGenerator } from "./generators-C-3isXzW.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";
|
|
@@ -9,6 +9,39 @@ import { source as source$1 } from "@kubb/plugin-client/templates/clients/fetch.
|
|
|
9
9
|
import { source as source$2 } from "@kubb/plugin-client/templates/config.source";
|
|
10
10
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
11
11
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
12
|
+
//#region ../../internals/shared/src/group.ts
|
|
13
|
+
/**
|
|
14
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
15
|
+
* shared default naming so every plugin groups output consistently:
|
|
16
|
+
*
|
|
17
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
18
|
+
* - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).
|
|
19
|
+
*
|
|
20
|
+
* Returns `null` when grouping is disabled, matching the per-plugin convention.
|
|
21
|
+
*
|
|
22
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
23
|
+
* @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.
|
|
24
|
+
* @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod
|
|
29
|
+
* createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …
|
|
30
|
+
* createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function createGroupConfig(group, options) {
|
|
34
|
+
if (!group) return null;
|
|
35
|
+
const defaultName = (ctx) => {
|
|
36
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
37
|
+
return `${camelCase(ctx.group)}${options.suffix}`;
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...group,
|
|
41
|
+
name: options.honorName && group.name ? group.name : defaultName
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
12
45
|
//#region src/resolvers/resolverVueQuery.ts
|
|
13
46
|
function capitalize(name) {
|
|
14
47
|
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
@@ -116,7 +149,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
116
149
|
const { output = {
|
|
117
150
|
path: "hooks",
|
|
118
151
|
barrelType: "named"
|
|
119
|
-
}, group, exclude = [], include, override = [], parser =
|
|
152
|
+
}, group, exclude = [], include, override = [], parser = false, infinite = false, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
120
153
|
const clientName = client?.client ?? "axios";
|
|
121
154
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
122
155
|
const selectedGenerators = options.generators ?? [
|
|
@@ -124,13 +157,10 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
124
157
|
infiniteQueryGenerator,
|
|
125
158
|
mutationGenerator
|
|
126
159
|
].filter((generator) => Boolean(generator));
|
|
127
|
-
const groupConfig = group
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
132
|
-
}
|
|
133
|
-
} : null;
|
|
160
|
+
const groupConfig = createGroupConfig(group, {
|
|
161
|
+
suffix: "Controller",
|
|
162
|
+
honorName: true
|
|
163
|
+
});
|
|
134
164
|
return {
|
|
135
165
|
name: pluginVueQueryName,
|
|
136
166
|
options,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverVueQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginVueQuery } 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-vue-query`. Decides the names and\n * file paths for every generated TanStack Query composable (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`) and its companion helpers.\n *\n * Functions and files use camelCase; composables get the `use` prefix.\n *\n * @example Resolve composable and helper names\n * ```ts\n * import { resolverVueQuery } from '@kubb/plugin-vue-query'\n *\n * resolverVueQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverVueQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverVueQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-vue-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 resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\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 resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\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 resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\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 } from '@internals/tanstack-query'\nimport { queryKeyTransformer } from '@internals/tanstack-query'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'\nimport { resolverVueQuery } from './resolvers/resolverVueQuery.ts'\nimport type { PluginVueQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']\n\n/**\n * Generates one TanStack Query composable per OpenAPI operation for Vue's\n * Composition API. Queries become `useFooQuery` (and optionally\n * `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable\n * is fully typed end to end.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginVueQuery } from '@kubb/plugin-vue-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginVueQuery({\n * output: { path: './hooks' },\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\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 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 [queryGenerator, infiniteQueryGenerator, mutationGenerator].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: pluginVueQueryName,\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 ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery\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/vue-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/vue-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 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 pluginVueQuery\n"],"mappings":";;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;;;;;;;;;AAmBxD,MAAa,mBAAmB,sBAAsC;CACpE,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,WA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rC,KAAK,MAAM,OAAO,oBAChB,IAAI,aAAa,IAAI;GAEvB,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,kBAAkB;IAC3C,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":["../../../internals/shared/src/group.ts","../src/resolvers/resolverVueQuery.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 * Returns `null` when grouping is disabled, matching the 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 * @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.\n *\n * @example\n * ```ts\n * createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod\n * createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …\n * createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp\n * ```\n */\nexport function createGroupConfig(group: Group | undefined, options: { suffix: string; honorName?: boolean }): 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: options.honorName && group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginVueQuery } 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-vue-query`. Decides the names and\n * file paths for every generated TanStack Query composable (`useFooQuery`,\n * `useFooMutation`, `useFooInfiniteQuery`) and its companion helpers.\n *\n * Functions and files use camelCase; composables get the `use` prefix.\n *\n * @example Resolve composable and helper names\n * ```ts\n * import { resolverVueQuery } from '@kubb/plugin-vue-query'\n *\n * resolverVueQuery.resolveQueryName(operationNode) // 'useGetPetById'\n * resolverVueQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'\n * resolverVueQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'\n * ```\n */\nexport const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({\n name: 'default',\n pluginName: 'plugin-vue-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 resolveInfiniteQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}Infinite`\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 resolveInfiniteQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveInfiniteQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}InfiniteQueryKey`\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 resolveInfiniteQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`\n },\n resolveMutationTypeName(node) {\n return capitalize(this.resolveName(node.operationId))\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n resolveInfiniteClientName(node) {\n return `${this.resolveName(node.operationId)}Infinite`\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 } from '@internals/tanstack-query'\nimport { queryKeyTransformer } from '@internals/tanstack-query'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'\nimport { resolverVueQuery } from './resolvers/resolverVueQuery.ts'\nimport type { PluginVueQuery } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups\n * and cross-plugin dependency references.\n */\nexport const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']\n\n/**\n * Generates one TanStack Query composable per OpenAPI operation for Vue's\n * Composition API. Queries become `useFooQuery` (and optionally\n * `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable\n * is fully typed end to end.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginVueQuery } from '@kubb/plugin-vue-query'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginVueQuery({\n * output: { path: './hooks' },\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = false,\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 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 [queryGenerator, infiniteQueryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = createGroupConfig(group, { suffix: 'Controller', honorName: true })\n\n return {\n name: pluginVueQueryName,\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 ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery\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/vue-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/vue-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 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 pluginVueQuery\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBAAkB,OAA0B,SAAgE;CAC1H,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,eAAe,QAAmC;EACtD,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAA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;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
|
package/extension.yaml
CHANGED
|
@@ -317,31 +317,6 @@ options:
|
|
|
317
317
|
}),
|
|
318
318
|
],
|
|
319
319
|
})
|
|
320
|
-
- name: contentType
|
|
321
|
-
type: "'application/json' | (string & {})"
|
|
322
|
-
required: false
|
|
323
|
-
description: |
|
|
324
|
-
Selects which request/response media type the generator reads from the OpenAPI spec.
|
|
325
|
-
|
|
326
|
-
When omitted, Kubb picks the first JSON-compatible media type it finds (`application/json`, `application/vnd.api+json`, anything ending in `+json`). Set this when your spec defines multiple media types for the same operation and you want a non-default one.
|
|
327
|
-
examples:
|
|
328
|
-
- name: JSON API media type
|
|
329
|
-
files:
|
|
330
|
-
- lang: typescript
|
|
331
|
-
twoslash: false
|
|
332
|
-
code: |
|
|
333
|
-
import { defineConfig } from 'kubb'
|
|
334
|
-
import { pluginTs } from '@kubb/plugin-ts'
|
|
335
|
-
|
|
336
|
-
export default defineConfig({
|
|
337
|
-
input: { path: './petStore.yaml' },
|
|
338
|
-
output: { path: './src/gen' },
|
|
339
|
-
plugins: [
|
|
340
|
-
pluginTs({
|
|
341
|
-
contentType: 'application/vnd.api+json',
|
|
342
|
-
}),
|
|
343
|
-
],
|
|
344
|
-
})
|
|
345
320
|
- name: group
|
|
346
321
|
type: Group
|
|
347
322
|
required: false
|
|
@@ -763,13 +738,13 @@ options:
|
|
|
763
738
|
// ...
|
|
764
739
|
}
|
|
765
740
|
- name: parser
|
|
766
|
-
type:
|
|
741
|
+
type: false | 'zod'
|
|
767
742
|
required: false
|
|
768
|
-
default:
|
|
743
|
+
default: 'false'
|
|
769
744
|
description: |
|
|
770
745
|
Runtime validator applied to the response body before it is returned to the caller.
|
|
771
746
|
|
|
772
|
-
- `
|
|
747
|
+
- `false` (default) — no validation. The client has no runtime parser; the response is cast to the generated TypeScript type and returned as-is. Fastest path, trusts the API.
|
|
773
748
|
- `'zod'` — pipes the response through the Zod schema produced by `@kubb/plugin-zod`. Catches mismatches between spec and API at runtime, at the cost of a parse on every call.
|
|
774
749
|
|
|
775
750
|
Use `'zod'` when you want a defensive boundary against drift between your OpenAPI spec and the live API. Requires `@kubb/plugin-zod` in the plugins list.
|
|
@@ -1002,13 +977,13 @@ options:
|
|
|
1002
977
|
- name: methods
|
|
1003
978
|
type: Array<HttpMethod>
|
|
1004
979
|
required: false
|
|
1005
|
-
default: "['post', 'put', 'delete']"
|
|
980
|
+
default: "['post', 'put', 'patch', 'delete']"
|
|
1006
981
|
description: |
|
|
1007
982
|
HTTP methods treated as mutations. Operations using one of these methods generate a `useMutation`-style hook instead of a query.
|
|
1008
983
|
|
|
1009
|
-
Defaults to `['post', 'put', 'delete']`.
|
|
984
|
+
Defaults to `['post', 'put', 'patch', 'delete']`. Narrow the list if your API uses one of these methods for reads.
|
|
1010
985
|
examples:
|
|
1011
|
-
- name:
|
|
986
|
+
- name: Treat only POST and PUT as mutations
|
|
1012
987
|
files:
|
|
1013
988
|
- lang: typescript
|
|
1014
989
|
twoslash: false
|
|
@@ -1021,7 +996,7 @@ options:
|
|
|
1021
996
|
output: { path: './src/gen' },
|
|
1022
997
|
plugins: [
|
|
1023
998
|
pluginReactQuery({
|
|
1024
|
-
mutation: { methods: ['post', 'put'
|
|
999
|
+
mutation: { methods: ['post', 'put'] },
|
|
1025
1000
|
}),
|
|
1026
1001
|
],
|
|
1027
1002
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-vue-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.33",
|
|
4
4
|
"description": "Generate type-safe TanStack Query (Vue Query) composables from your OpenAPI specification. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with Vue 3 Composition API support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"registry": "https://registry.npmjs.org/"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@kubb/core": "5.0.0-beta.
|
|
74
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
75
|
-
"remeda": "^2.
|
|
76
|
-
"@kubb/plugin-client": "5.0.0-beta.
|
|
77
|
-
"@kubb/plugin-ts": "5.0.0-beta.
|
|
78
|
-
"@kubb/plugin-zod": "5.0.0-beta.
|
|
73
|
+
"@kubb/core": "5.0.0-beta.33",
|
|
74
|
+
"@kubb/renderer-jsx": "5.0.0-beta.33",
|
|
75
|
+
"remeda": "^2.36.0",
|
|
76
|
+
"@kubb/plugin-client": "5.0.0-beta.33",
|
|
77
|
+
"@kubb/plugin-ts": "5.0.0-beta.33",
|
|
78
|
+
"@kubb/plugin-zod": "5.0.0-beta.33"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@internals/shared": "0.0.0",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@internals/utils": "0.0.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
86
|
+
"@kubb/renderer-jsx": "5.0.0-beta.33"
|
|
87
87
|
},
|
|
88
88
|
"size-limit": [
|
|
89
89
|
{
|
|
@@ -4,6 +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 { Infinite, PluginVueQuery } from '../types.ts'
|
|
7
|
+
import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
7
8
|
import { getComments, resolveErrorNames, resolveSuccessNames, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
8
9
|
import { buildQueryKeyParamsNode } from './QueryKey.tsx'
|
|
9
10
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
@@ -91,11 +92,15 @@ export function InfiniteQuery({
|
|
|
91
92
|
|
|
92
93
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
93
94
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
95
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode)
|
|
94
96
|
|
|
95
97
|
const queryOptionsParamsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
96
98
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? ''
|
|
97
99
|
|
|
98
|
-
const paramsNode =
|
|
100
|
+
const paramsNode = markParamsOptional(
|
|
101
|
+
buildInfiniteQueryParamsNode(node, { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver: tsResolver }),
|
|
102
|
+
enabledNames,
|
|
103
|
+
)
|
|
99
104
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
100
105
|
|
|
101
106
|
return (
|
|
@@ -8,7 +8,7 @@ import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
|
8
8
|
import type { Infinite, PluginVueQuery } from '../types.ts'
|
|
9
9
|
import { resolveErrorNames, resolveSuccessNames } from '../utils.ts'
|
|
10
10
|
import { buildQueryKeyParamsNode } from './QueryKey.tsx'
|
|
11
|
-
import {
|
|
11
|
+
import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
12
12
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
13
13
|
|
|
14
14
|
type Props = {
|
|
@@ -81,21 +81,16 @@ export function InfiniteQueryOptions({
|
|
|
81
81
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null
|
|
82
82
|
const pageParamType = queryParamType ? (isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType) : fallbackPageParamType
|
|
83
83
|
|
|
84
|
-
const paramsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
85
|
-
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
86
|
-
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
87
|
-
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
88
|
-
|
|
89
84
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
90
85
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
91
86
|
|
|
92
|
-
const
|
|
93
|
-
const enabledText =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode)
|
|
88
|
+
const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(' && ')},` : ''
|
|
89
|
+
|
|
90
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver }), enabledNames)
|
|
91
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
92
|
+
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
93
|
+
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
99
94
|
|
|
100
95
|
const hasNewParams = nextParam != null || previousParam != null
|
|
101
96
|
|
|
@@ -145,7 +140,7 @@ export function InfiniteQueryOptions({
|
|
|
145
140
|
queryKey,
|
|
146
141
|
queryFn: async ({ signal, pageParam }) => {
|
|
147
142
|
${infiniteOverrideParams}
|
|
148
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
143
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
149
144
|
},
|
|
150
145
|
${queryOptionsArr.join(',\n')}
|
|
151
146
|
})
|
|
@@ -164,7 +159,7 @@ export function InfiniteQueryOptions({
|
|
|
164
159
|
${enabledText}
|
|
165
160
|
queryKey,
|
|
166
161
|
queryFn: async ({ signal }) => {
|
|
167
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
162
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
168
163
|
},
|
|
169
164
|
${queryOptionsArr.join(',\n')}
|
|
170
165
|
})
|
|
@@ -174,15 +169,17 @@ export function InfiniteQueryOptions({
|
|
|
174
169
|
)
|
|
175
170
|
}
|
|
176
171
|
|
|
177
|
-
function addToValueCalls(callStr: string): string {
|
|
172
|
+
function addToValueCalls(callStr: string, enabledNames: ReadonlyArray<string> = []): string {
|
|
173
|
+
const optional = new Set(enabledNames)
|
|
178
174
|
// Step 1: Transform shorthand object params like { petId } → { petId: toValue(petId) }
|
|
175
|
+
// Params that drive the `enabled` guard are optional, so assert non-null: toValue(petId!)
|
|
179
176
|
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner: string) => {
|
|
180
177
|
if (inner.includes(':') || inner.includes('...')) return match
|
|
181
178
|
const keys = inner
|
|
182
179
|
.split(',')
|
|
183
180
|
.map((k: string) => k.trim())
|
|
184
181
|
.filter(Boolean)
|
|
185
|
-
const wrapped = keys.map((k: string) => `${k}: toValue(${k})`).join(', ')
|
|
182
|
+
const wrapped = keys.map((k: string) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(', ')
|
|
186
183
|
return `{ ${wrapped} }`
|
|
187
184
|
})
|
|
188
185
|
|
|
@@ -190,7 +187,7 @@ function addToValueCalls(callStr: string): string {
|
|
|
190
187
|
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name: string) => {
|
|
191
188
|
if (name === 'config' || name === 'signal' || name === 'undefined') return match
|
|
192
189
|
if (match.includes('toValue(')) return match
|
|
193
|
-
return `toValue(${name})`
|
|
190
|
+
return `toValue(${optional.has(name) ? `${name}!` : name})`
|
|
194
191
|
})
|
|
195
192
|
|
|
196
193
|
return result
|
package/src/components/Query.tsx
CHANGED
|
@@ -4,6 +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 { PluginVueQuery } from '../types.ts'
|
|
7
|
+
import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
7
8
|
import { getComments, resolveErrorNames, resolveSuccessNames, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
8
9
|
import { buildQueryKeyParamsNode } from './QueryKey.tsx'
|
|
9
10
|
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
@@ -90,11 +91,15 @@ export function Query({
|
|
|
90
91
|
|
|
91
92
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
92
93
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
94
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode)
|
|
93
95
|
|
|
94
96
|
const queryOptionsParamsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
95
97
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? ''
|
|
96
98
|
|
|
97
|
-
const paramsNode =
|
|
99
|
+
const paramsNode = markParamsOptional(
|
|
100
|
+
buildQueryParamsNode(node, { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver: tsResolver }),
|
|
101
|
+
enabledNames,
|
|
102
|
+
)
|
|
98
103
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
99
104
|
|
|
100
105
|
return (
|
|
@@ -3,7 +3,7 @@ import type { ResolverTs } from '@kubb/plugin-ts'
|
|
|
3
3
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
4
|
import { File, Function, Type } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
|
-
import { queryKeyTransformer } from '@internals/tanstack-query'
|
|
6
|
+
import { getEnabledParamNames, markParamsOptional, queryKeyTransformer } from '@internals/tanstack-query'
|
|
7
7
|
import type { Transformer } from '../types.ts'
|
|
8
8
|
import { buildQueryKeyParams, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
9
9
|
|
|
@@ -27,7 +27,8 @@ export function buildQueryKeyParamsNode(
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }: Props): KubbReactNode {
|
|
30
|
-
const
|
|
30
|
+
const baseParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
31
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode))
|
|
31
32
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
32
33
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
33
34
|
node,
|