@kubb/plugin-react-query 4.14.1 → 4.15.1
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-CO636qn3.cjs → components-6nRaAppd.cjs} +19 -13
- package/dist/components-6nRaAppd.cjs.map +1 -0
- package/dist/{components-DQHnoHX_.js → components-B6lqcqgn.js} +18 -12
- package/dist/components-B6lqcqgn.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +15 -5
- package/dist/components.d.ts +15 -5
- package/dist/components.js +1 -1
- package/dist/{generators-BNtUetHy.cjs → generators-CYoqgYAV.cjs} +331 -6
- package/dist/generators-CYoqgYAV.cjs.map +1 -0
- package/dist/{generators-Cz0OG9Qu.js → generators-cZao868O.js} +320 -8
- package/dist/generators-cZao868O.js.map +1 -0
- package/dist/generators.cjs +3 -1
- package/dist/generators.d.cts +8 -2
- package/dist/generators.d.ts +8 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +10 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-Cli5EJ4L.d.ts → types-B9xv5S0R.d.cts} +35 -2
- package/dist/{types-B2aUnqdY.d.cts → types-BAEc42Ae.d.ts} +35 -2
- package/package.json +7 -7
- package/src/components/InfiniteQuery.tsx +4 -1
- package/src/components/Mutation.tsx +4 -1
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +4 -1
- package/src/components/SuspenseInfiniteQuery.tsx +4 -1
- package/src/components/SuspenseQuery.tsx +4 -1
- package/src/generators/__snapshots__/clientPostImportPath.ts +4 -2
- package/src/generators/__snapshots__/findByTagsWithCustomOptions.ts +89 -0
- package/src/generators/__snapshots__/findInfiniteByTagsWithCustomOptions.ts +103 -0
- package/src/generators/__snapshots__/findSuspenseByTagsWithCustomOptions.ts +83 -0
- package/src/generators/__snapshots__/findSuspenseInfiniteByTagsWithCustomOptions.ts +103 -0
- package/src/generators/__snapshots__/updatePetById.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdWithCustomOptions.ts +107 -0
- package/src/generators/customHookOptionsFileGenerator.tsx +98 -0
- package/src/generators/hookOptionsGenerator.tsx +196 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/infiniteQueryGenerator.tsx +2 -0
- package/src/generators/mutationGenerator.tsx +2 -0
- package/src/generators/queryGenerator.tsx +2 -0
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +2 -0
- package/src/generators/suspenseQueryGenerator.tsx +2 -0
- package/src/plugin.ts +20 -2
- package/src/types.ts +21 -0
- package/dist/components-CO636qn3.cjs.map +0 -1
- package/dist/components-DQHnoHX_.js.map +0 -1
- package/dist/generators-BNtUetHy.cjs.map +0 -1
- package/dist/generators-Cz0OG9Qu.js.map +0 -1
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { a as ReactGenerator, r as PluginReactQuery } from "./types-
|
|
1
|
+
import { a as ReactGenerator, r as PluginReactQuery } from "./types-BAEc42Ae.js";
|
|
2
2
|
|
|
3
|
+
//#region src/generators/customHookOptionsFileGenerator.d.ts
|
|
4
|
+
declare const customHookOptionsFileGenerator: ReactGenerator<PluginReactQuery>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/generators/hookOptionsGenerator.d.ts
|
|
7
|
+
declare const hookOptionsGenerator: ReactGenerator<PluginReactQuery>;
|
|
8
|
+
//#endregion
|
|
3
9
|
//#region src/generators/infiniteQueryGenerator.d.ts
|
|
4
10
|
declare const infiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
5
11
|
//#endregion
|
|
@@ -15,5 +21,5 @@ declare const suspenseInfiniteQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
|
15
21
|
//#region src/generators/suspenseQueryGenerator.d.ts
|
|
16
22
|
declare const suspenseQueryGenerator: ReactGenerator<PluginReactQuery>;
|
|
17
23
|
//#endregion
|
|
18
|
-
export { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
|
24
|
+
export { customHookOptionsFileGenerator, hookOptionsGenerator, infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
|
19
25
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, r as queryGenerator, t as suspenseQueryGenerator } from "./generators-
|
|
1
|
+
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-cZao868O.js";
|
|
2
2
|
|
|
3
|
-
export { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
|
3
|
+
export { customHookOptionsFileGenerator, hookOptionsGenerator, infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_generators = require('./generators-
|
|
2
|
-
const require_components = require('./components-
|
|
1
|
+
const require_generators = require('./generators-CYoqgYAV.cjs');
|
|
2
|
+
const require_components = require('./components-6nRaAppd.cjs');
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_generators.__toESM(node_path);
|
|
5
5
|
let _kubb_core = require("@kubb/core");
|
|
@@ -21,8 +21,10 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
21
21
|
require_generators.suspenseQueryGenerator,
|
|
22
22
|
require_generators.infiniteQueryGenerator,
|
|
23
23
|
require_generators.suspenseInfiniteQueryGenerator,
|
|
24
|
-
require_generators.mutationGenerator
|
|
25
|
-
|
|
24
|
+
require_generators.mutationGenerator,
|
|
25
|
+
require_generators.hookOptionsGenerator,
|
|
26
|
+
require_generators.customHookOptionsFileGenerator
|
|
27
|
+
].filter(Boolean), mutation = {}, query = {}, mutationKey = require_components.MutationKey.getTransformer, queryKey = require_components.QueryKey.getTransformer, customOptions, paramsCasing, contentType, client } = options;
|
|
26
28
|
const clientName = client?.client ?? "axios";
|
|
27
29
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
28
30
|
return {
|
|
@@ -63,6 +65,10 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
63
65
|
importPath: "@tanstack/react-query",
|
|
64
66
|
...mutation
|
|
65
67
|
},
|
|
68
|
+
customOptions: customOptions ? {
|
|
69
|
+
name: "useCustomHookOptions",
|
|
70
|
+
...customOptions
|
|
71
|
+
} : void 0,
|
|
66
72
|
paramsType,
|
|
67
73
|
pathParamsType,
|
|
68
74
|
parser,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, suspenseInfiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,uBAAuB;AAEpC,MAAa,iDAAmD,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa;EAACA;EAAgBC;EAAwBC;EAAwBC;EAAgCC;EAAkB,CAAC,OAAO,QAAQ,EAChJ,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAcC,+BAAY,gBAC1B,WAAWC,4BAAS,gBACpB,cACA,aACA,WACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe;AAEhH,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,GAAG,QAAQ;IACX,QAAQ;IACR,YAAY,QAAQ,cAAc;IAClC,gBAAgB,QAAQ,kBAAkB;IAC1C;IACA,YAAY;IACb;GACD,UAAU,WACN;IACE,YAAY;IACZ,kBAAkB;IAClB,aAAa;IACb,WAAW;IACX,eAAe;IACf,GAAG;IACJ,GACD;GACJ;GACA;GACA,OACE,UAAU,QACN,QACA;IACE,SAAS,CAAC,MAAM;IAChB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ueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAa,uBAAuB;AAEpC,MAAa,iDAAmD,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAA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H,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAMA,kBAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,iDAA2B,uCAAuC,CAAC;KACnE,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAII,oCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,qCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-
|
|
1
|
+
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-B9xv5S0R.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-
|
|
1
|
+
import { n as Options, r as PluginReactQuery, s as UserPluginWithLifeCycle } from "./types-BAEc42Ae.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as QueryKey, s as MutationKey } from "./components-
|
|
2
|
-
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, r as queryGenerator, t as suspenseQueryGenerator } from "./generators-
|
|
1
|
+
import { d as QueryKey, s as MutationKey } from "./components-B6lqcqgn.js";
|
|
2
|
+
import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-cZao868O.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
@@ -20,8 +20,10 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
20
20
|
suspenseQueryGenerator,
|
|
21
21
|
infiniteQueryGenerator,
|
|
22
22
|
suspenseInfiniteQueryGenerator,
|
|
23
|
-
mutationGenerator
|
|
24
|
-
|
|
23
|
+
mutationGenerator,
|
|
24
|
+
hookOptionsGenerator,
|
|
25
|
+
customHookOptionsFileGenerator
|
|
26
|
+
].filter(Boolean), mutation = {}, query = {}, mutationKey = MutationKey.getTransformer, queryKey = QueryKey.getTransformer, customOptions, paramsCasing, contentType, client } = options;
|
|
25
27
|
const clientName = client?.client ?? "axios";
|
|
26
28
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
27
29
|
return {
|
|
@@ -62,6 +64,10 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
62
64
|
importPath: "@tanstack/react-query",
|
|
63
65
|
...mutation
|
|
64
66
|
},
|
|
67
|
+
customOptions: customOptions ? {
|
|
68
|
+
name: "useCustomHookOptions",
|
|
69
|
+
...customOptions
|
|
70
|
+
} : void 0,
|
|
65
71
|
paramsType,
|
|
66
72
|
pathParamsType,
|
|
67
73
|
parser,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseInfiniteQueryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, suspenseInfiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,uBAAuB;AAEpC,MAAa,mBAAmB,cAAgC,YAAY;CAC1E,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,WAAW,EAAE,EACb,WAAW,OACX,eAAe,EAAE,EACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa;EAAC;EAAgB;EAAwB;EAAwB;EAAgC;EAAkB,CAAC,OAAO,QAAQ,EAChJ,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,cACA,aACA,WACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,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ACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport {\n customHookOptionsFileGenerator,\n hookOptionsGenerator,\n infiniteQueryGenerator,\n mutationGenerator,\n queryGenerator,\n suspenseInfiniteQueryGenerator,\n suspenseQueryGenerator,\n} from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = definePlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n generators = [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n contentType,\n client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query:\n query === false\n ? false\n : {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n paramsType,\n pathParamsType,\n parser,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.upsertFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAqBA,MAAa,uBAAuB;AAEpC,MAAa,mBAAmB,cAAgC,YAA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AAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAO,oBACL,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAU,gDAAgD,8CACjG,CAAC;KACF,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAO,oBAAoB,uCAAuC,CAAC;KACnE,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
1
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
3
2
|
import BaseOas from "oas";
|
|
4
3
|
import { Operation } from "oas/operation";
|
|
5
4
|
import { DiscriminatorObject, HttpMethods, OASDocument, SchemaObject } from "oas/types";
|
|
6
5
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
6
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
7
7
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
8
8
|
|
|
9
9
|
//#region ../oas/src/types.d.ts
|
|
@@ -391,6 +391,13 @@ type Config<TInput = Input> = {
|
|
|
391
391
|
* @default 'simple'
|
|
392
392
|
*/
|
|
393
393
|
defaultBanner?: 'simple' | 'full' | false;
|
|
394
|
+
/**
|
|
395
|
+
* Whether to override existing external files if they already exist.
|
|
396
|
+
* When setting the option in the global configuration, all plugins inherit the same behavior by default.
|
|
397
|
+
* However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
|
|
398
|
+
* @default false
|
|
399
|
+
*/
|
|
400
|
+
override?: boolean;
|
|
394
401
|
};
|
|
395
402
|
/**
|
|
396
403
|
* An array of Kubb plugins that will be used in the generation.
|
|
@@ -578,6 +585,11 @@ type Output<TOptions> = {
|
|
|
578
585
|
* Add a footer text in the beginning of every file
|
|
579
586
|
*/
|
|
580
587
|
footer?: string | ((options: TOptions) => string);
|
|
588
|
+
/**
|
|
589
|
+
* Whether to override existing external files if they already exist.
|
|
590
|
+
* @default false
|
|
591
|
+
*/
|
|
592
|
+
override?: boolean;
|
|
581
593
|
};
|
|
582
594
|
type GroupContext = {
|
|
583
595
|
group: string;
|
|
@@ -831,6 +843,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
831
843
|
};
|
|
832
844
|
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
833
845
|
#private;
|
|
846
|
+
getOptions(operation: Operation$1, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
|
|
834
847
|
getSchemas(operation: Operation$1, {
|
|
835
848
|
resolveName
|
|
836
849
|
}?: {
|
|
@@ -1367,6 +1380,20 @@ type Infinite = {
|
|
|
1367
1380
|
*/
|
|
1368
1381
|
initialPageParam: unknown;
|
|
1369
1382
|
};
|
|
1383
|
+
type CustomOptions = {
|
|
1384
|
+
/**
|
|
1385
|
+
* Path to the hook that will be used to customize the hook options.
|
|
1386
|
+
* It will be used as `import ${customOptions.name} from '${customOptions.importPath}'`.
|
|
1387
|
+
* It allows both relative and absolute paths but be aware that we will not change the path.
|
|
1388
|
+
*/
|
|
1389
|
+
importPath: string;
|
|
1390
|
+
/**
|
|
1391
|
+
* Name of the exported hook that will be used to customize the hook options.
|
|
1392
|
+
* It will be used as `import ${customOptions.name} from '${customOptions.importPath}'`.
|
|
1393
|
+
* @default 'useCustomHookOptions'
|
|
1394
|
+
*/
|
|
1395
|
+
name?: string;
|
|
1396
|
+
};
|
|
1370
1397
|
type Options = {
|
|
1371
1398
|
/**
|
|
1372
1399
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -1432,6 +1459,11 @@ type Options = {
|
|
|
1432
1459
|
* Override some useMutation behaviours.
|
|
1433
1460
|
*/
|
|
1434
1461
|
mutation?: Partial<Mutation> | false;
|
|
1462
|
+
/**
|
|
1463
|
+
* When set, a custom hook will be used to customize the options of the generated hooks.
|
|
1464
|
+
* It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
|
|
1465
|
+
*/
|
|
1466
|
+
customOptions?: CustomOptions;
|
|
1435
1467
|
/**
|
|
1436
1468
|
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
1437
1469
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
@@ -1465,8 +1497,9 @@ type ResolvedOptions = {
|
|
|
1465
1497
|
query: NonNullable<Required<Query>> | false;
|
|
1466
1498
|
mutationKey: MutationKey | undefined;
|
|
1467
1499
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
1500
|
+
customOptions: NonNullable<Required<CustomOptions>> | undefined;
|
|
1468
1501
|
};
|
|
1469
1502
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1470
1503
|
//#endregion
|
|
1471
1504
|
export { ReactGenerator as a, Operation$1 as c, Transformer as i, Options as n, OperationSchemas as o, PluginReactQuery as r, UserPluginWithLifeCycle as s, Infinite as t };
|
|
1472
|
-
//# sourceMappingURL=types-
|
|
1505
|
+
//# sourceMappingURL=types-B9xv5S0R.d.cts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
1
2
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
2
3
|
import BaseOas from "oas";
|
|
3
4
|
import { Operation } from "oas/operation";
|
|
4
5
|
import { DiscriminatorObject, HttpMethods, OASDocument, SchemaObject } from "oas/types";
|
|
5
6
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
6
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
7
7
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
8
8
|
|
|
9
9
|
//#region ../oas/src/types.d.ts
|
|
@@ -391,6 +391,13 @@ type Config<TInput = Input> = {
|
|
|
391
391
|
* @default 'simple'
|
|
392
392
|
*/
|
|
393
393
|
defaultBanner?: 'simple' | 'full' | false;
|
|
394
|
+
/**
|
|
395
|
+
* Whether to override existing external files if they already exist.
|
|
396
|
+
* When setting the option in the global configuration, all plugins inherit the same behavior by default.
|
|
397
|
+
* However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
|
|
398
|
+
* @default false
|
|
399
|
+
*/
|
|
400
|
+
override?: boolean;
|
|
394
401
|
};
|
|
395
402
|
/**
|
|
396
403
|
* An array of Kubb plugins that will be used in the generation.
|
|
@@ -578,6 +585,11 @@ type Output<TOptions> = {
|
|
|
578
585
|
* Add a footer text in the beginning of every file
|
|
579
586
|
*/
|
|
580
587
|
footer?: string | ((options: TOptions) => string);
|
|
588
|
+
/**
|
|
589
|
+
* Whether to override existing external files if they already exist.
|
|
590
|
+
* @default false
|
|
591
|
+
*/
|
|
592
|
+
override?: boolean;
|
|
581
593
|
};
|
|
582
594
|
type GroupContext = {
|
|
583
595
|
group: string;
|
|
@@ -831,6 +843,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
831
843
|
};
|
|
832
844
|
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
833
845
|
#private;
|
|
846
|
+
getOptions(operation: Operation$1, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
|
|
834
847
|
getSchemas(operation: Operation$1, {
|
|
835
848
|
resolveName
|
|
836
849
|
}?: {
|
|
@@ -1367,6 +1380,20 @@ type Infinite = {
|
|
|
1367
1380
|
*/
|
|
1368
1381
|
initialPageParam: unknown;
|
|
1369
1382
|
};
|
|
1383
|
+
type CustomOptions = {
|
|
1384
|
+
/**
|
|
1385
|
+
* Path to the hook that will be used to customize the hook options.
|
|
1386
|
+
* It will be used as `import ${customOptions.name} from '${customOptions.importPath}'`.
|
|
1387
|
+
* It allows both relative and absolute paths but be aware that we will not change the path.
|
|
1388
|
+
*/
|
|
1389
|
+
importPath: string;
|
|
1390
|
+
/**
|
|
1391
|
+
* Name of the exported hook that will be used to customize the hook options.
|
|
1392
|
+
* It will be used as `import ${customOptions.name} from '${customOptions.importPath}'`.
|
|
1393
|
+
* @default 'useCustomHookOptions'
|
|
1394
|
+
*/
|
|
1395
|
+
name?: string;
|
|
1396
|
+
};
|
|
1370
1397
|
type Options = {
|
|
1371
1398
|
/**
|
|
1372
1399
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -1432,6 +1459,11 @@ type Options = {
|
|
|
1432
1459
|
* Override some useMutation behaviours.
|
|
1433
1460
|
*/
|
|
1434
1461
|
mutation?: Partial<Mutation> | false;
|
|
1462
|
+
/**
|
|
1463
|
+
* When set, a custom hook will be used to customize the options of the generated hooks.
|
|
1464
|
+
* It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
|
|
1465
|
+
*/
|
|
1466
|
+
customOptions?: CustomOptions;
|
|
1435
1467
|
/**
|
|
1436
1468
|
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
1437
1469
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
@@ -1465,8 +1497,9 @@ type ResolvedOptions = {
|
|
|
1465
1497
|
query: NonNullable<Required<Query>> | false;
|
|
1466
1498
|
mutationKey: MutationKey | undefined;
|
|
1467
1499
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
1500
|
+
customOptions: NonNullable<Required<CustomOptions>> | undefined;
|
|
1468
1501
|
};
|
|
1469
1502
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1470
1503
|
//#endregion
|
|
1471
1504
|
export { ReactGenerator as a, Operation$1 as c, Transformer as i, Options as n, OperationSchemas as o, PluginReactQuery as r, UserPluginWithLifeCycle as s, Infinite as t };
|
|
1472
|
-
//# sourceMappingURL=types-
|
|
1505
|
+
//# sourceMappingURL=types-BAEc42Ae.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.1",
|
|
4
4
|
"description": "React Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for React applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-query",
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@kubb/react-fabric": "0.9.2",
|
|
71
71
|
"remeda": "^2.33.1",
|
|
72
|
-
"@kubb/core": "4.
|
|
73
|
-
"@kubb/oas": "4.
|
|
74
|
-
"@kubb/plugin-client": "4.
|
|
75
|
-
"@kubb/plugin-oas": "4.
|
|
76
|
-
"@kubb/plugin-ts": "4.
|
|
77
|
-
"@kubb/plugin-zod": "4.
|
|
72
|
+
"@kubb/core": "4.15.1",
|
|
73
|
+
"@kubb/oas": "4.15.1",
|
|
74
|
+
"@kubb/plugin-client": "4.15.1",
|
|
75
|
+
"@kubb/plugin-oas": "4.15.1",
|
|
76
|
+
"@kubb/plugin-ts": "4.15.1",
|
|
77
|
+
"@kubb/plugin-zod": "4.15.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@kubb/react-fabric": "0.9.2"
|
|
@@ -23,6 +23,7 @@ type Props = {
|
|
|
23
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
24
|
initialPageParam: Infinite['initialPageParam']
|
|
25
25
|
queryParam?: Infinite['queryParam']
|
|
26
|
+
customOptions: PluginReactQuery['resolvedOptions']['customOptions']
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
type GetParamsProps = {
|
|
@@ -129,6 +130,7 @@ export function InfiniteQuery({
|
|
|
129
130
|
operation,
|
|
130
131
|
initialPageParam,
|
|
131
132
|
queryParam,
|
|
133
|
+
customOptions,
|
|
132
134
|
}: Props): KubbNode {
|
|
133
135
|
const responseType = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
134
136
|
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
@@ -193,9 +195,10 @@ export function InfiniteQuery({
|
|
|
193
195
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
194
196
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
195
197
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
198
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ''}
|
|
196
199
|
|
|
197
200
|
const query = useInfiniteQuery({
|
|
198
|
-
...${queryOptions},
|
|
201
|
+
...${queryOptions},${customOptions ? '\n...customOptions,' : ''}
|
|
199
202
|
queryKey,
|
|
200
203
|
...queryOptions
|
|
201
204
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -20,6 +20,7 @@ type Props = {
|
|
|
20
20
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
21
21
|
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
22
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
|
+
customOptions: PluginReactQuery['resolvedOptions']['customOptions']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
@@ -78,6 +79,7 @@ export function Mutation({
|
|
|
78
79
|
typeSchemas,
|
|
79
80
|
operation,
|
|
80
81
|
mutationKeyName,
|
|
82
|
+
customOptions,
|
|
81
83
|
}: Props): KubbNode {
|
|
82
84
|
const mutationKeyParams = MutationKey.getParams({
|
|
83
85
|
pathParamsType,
|
|
@@ -140,9 +142,10 @@ export function Mutation({
|
|
|
140
142
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
141
143
|
|
|
142
144
|
const baseOptions = ${mutationOptions} as UseMutationOptions<${generics}>
|
|
145
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' }) as UseMutationOptions<${generics}>` : ''}
|
|
143
146
|
|
|
144
147
|
return useMutation<${generics}>({
|
|
145
|
-
...baseOptions,
|
|
148
|
+
...baseOptions,${customOptions ? '\n...customOptions,' : ''}
|
|
146
149
|
mutationKey,
|
|
147
150
|
...mutationOptions,
|
|
148
151
|
}, queryClient) as ${returnType}
|
|
@@ -95,10 +95,10 @@ export function MutationOptions({ name, clientName, dataReturnType, typeSchemas,
|
|
|
95
95
|
|
|
96
96
|
return (
|
|
97
97
|
<File.Source name={name} isExportable isIndexable>
|
|
98
|
-
<Function name={name} export params={params.toConstructor()}>
|
|
98
|
+
<Function name={name} export params={params.toConstructor()} generics={['TContext = unknown']}>
|
|
99
99
|
{`
|
|
100
100
|
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
101
|
-
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : 'void'},
|
|
101
|
+
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : 'void'}, TContext>({
|
|
102
102
|
mutationKey,
|
|
103
103
|
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
104
104
|
return ${clientName}(${clientParams.toCall()})
|
package/src/components/Query.tsx
CHANGED
|
@@ -21,6 +21,7 @@ type Props = {
|
|
|
21
21
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
|
+
customOptions: PluginReactQuery['resolvedOptions']['customOptions']
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type GetParamsProps = {
|
|
@@ -122,6 +123,7 @@ export function Query({
|
|
|
122
123
|
dataReturnType,
|
|
123
124
|
typeSchemas,
|
|
124
125
|
operation,
|
|
126
|
+
customOptions,
|
|
125
127
|
}: Props): KubbNode {
|
|
126
128
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
127
129
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
@@ -164,9 +166,10 @@ export function Query({
|
|
|
164
166
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
165
167
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
166
168
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
169
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ''}
|
|
167
170
|
|
|
168
171
|
const query = useQuery({
|
|
169
|
-
...${queryOptions},
|
|
172
|
+
...${queryOptions},${customOptions ? '\n...customOptions,' : ''}
|
|
170
173
|
queryKey,
|
|
171
174
|
...queryOptions
|
|
172
175
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -21,6 +21,7 @@ type Props = {
|
|
|
21
21
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
|
+
customOptions: PluginReactQuery['resolvedOptions']['customOptions']
|
|
24
25
|
initialPageParam: Infinite['initialPageParam']
|
|
25
26
|
queryParam?: Infinite['queryParam']
|
|
26
27
|
}
|
|
@@ -127,6 +128,7 @@ export function SuspenseInfiniteQuery({
|
|
|
127
128
|
dataReturnType,
|
|
128
129
|
typeSchemas,
|
|
129
130
|
operation,
|
|
131
|
+
customOptions,
|
|
130
132
|
initialPageParam,
|
|
131
133
|
queryParam,
|
|
132
134
|
}: Props): KubbNode {
|
|
@@ -193,9 +195,10 @@ export function SuspenseInfiniteQuery({
|
|
|
193
195
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
194
196
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
195
197
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
198
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ''}
|
|
196
199
|
|
|
197
200
|
const query = useSuspenseInfiniteQuery({
|
|
198
|
-
...${queryOptions},
|
|
201
|
+
...${queryOptions},${customOptions ? '\n...customOptions,' : ''}
|
|
199
202
|
queryKey,
|
|
200
203
|
...queryOptions
|
|
201
204
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -21,6 +21,7 @@ type Props = {
|
|
|
21
21
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
|
+
customOptions: PluginReactQuery['resolvedOptions']['customOptions']
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type GetParamsProps = {
|
|
@@ -129,6 +130,7 @@ export function SuspenseQuery({
|
|
|
129
130
|
dataReturnType,
|
|
130
131
|
typeSchemas,
|
|
131
132
|
operation,
|
|
133
|
+
customOptions,
|
|
132
134
|
}: Props): KubbNode {
|
|
133
135
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
134
136
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
@@ -171,9 +173,10 @@ export function SuspenseQuery({
|
|
|
171
173
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
172
174
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
173
175
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
176
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ''}
|
|
174
177
|
|
|
175
178
|
const query = useSuspenseQuery({
|
|
176
|
-
...${queryOptions},
|
|
179
|
+
...${queryOptions},${customOptions ? '\n...customOptions,' : ''}
|
|
177
180
|
queryKey,
|
|
178
181
|
...queryOptions
|
|
179
182
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -35,13 +35,15 @@ export async function updatePetWithForm(
|
|
|
35
35
|
return updatePetWithFormMutationResponse.parse(res.data)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function updatePetWithFormMutationOptions
|
|
38
|
+
export function updatePetWithFormMutationOptions<TContext = unknown>(
|
|
39
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
40
|
+
) {
|
|
39
41
|
const mutationKey = updatePetWithFormMutationKey()
|
|
40
42
|
return mutationOptions<
|
|
41
43
|
UpdatePetWithFormMutationResponse,
|
|
42
44
|
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
43
45
|
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
44
|
-
|
|
46
|
+
TContext
|
|
45
47
|
>({
|
|
46
48
|
mutationKey,
|
|
47
49
|
mutationFn: async ({ petId, data, params }) => {
|