@kubb/plugin-react-query 5.0.0-alpha.8 → 5.0.0-beta.3

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.
Files changed (52) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-DTGLu4UV.js +1451 -0
  4. package/dist/components-DTGLu4UV.js.map +1 -0
  5. package/dist/components-dAKJEn9b.cjs +1571 -0
  6. package/dist/components-dAKJEn9b.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +105 -161
  9. package/dist/components.js +1 -1
  10. package/dist/generators-CWEQsdO9.cjs +1502 -0
  11. package/dist/generators-CWEQsdO9.cjs.map +1 -0
  12. package/dist/generators-C_fbcjpG.js +1460 -0
  13. package/dist/generators-C_fbcjpG.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +9 -476
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +114 -126
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +110 -126
  21. package/dist/index.js.map +1 -1
  22. package/dist/{types-D5S7Ny9r.d.ts → types-DfaFRSBf.d.ts} +100 -86
  23. package/package.json +59 -62
  24. package/src/components/InfiniteQuery.tsx +75 -139
  25. package/src/components/InfiniteQueryOptions.tsx +62 -164
  26. package/src/components/Mutation.tsx +58 -113
  27. package/src/components/MutationOptions.tsx +61 -80
  28. package/src/components/Query.tsx +67 -140
  29. package/src/components/QueryOptions.tsx +75 -135
  30. package/src/components/SuspenseInfiniteQuery.tsx +75 -139
  31. package/src/components/SuspenseInfiniteQueryOptions.tsx +62 -164
  32. package/src/components/SuspenseQuery.tsx +67 -150
  33. package/src/generators/customHookOptionsFileGenerator.tsx +33 -45
  34. package/src/generators/hookOptionsGenerator.tsx +115 -175
  35. package/src/generators/infiniteQueryGenerator.tsx +183 -176
  36. package/src/generators/mutationGenerator.tsx +127 -138
  37. package/src/generators/queryGenerator.tsx +141 -141
  38. package/src/generators/suspenseInfiniteQueryGenerator.tsx +175 -155
  39. package/src/generators/suspenseQueryGenerator.tsx +149 -148
  40. package/src/index.ts +1 -1
  41. package/src/plugin.ts +133 -183
  42. package/src/resolvers/resolverReactQuery.ts +22 -0
  43. package/src/types.ts +67 -45
  44. package/src/utils.ts +40 -0
  45. package/dist/components-BHQT9ZLc.cjs +0 -1634
  46. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  47. package/dist/components-CpyHYGOw.js +0 -1520
  48. package/dist/components-CpyHYGOw.js.map +0 -1
  49. package/dist/generators-DP07m3rH.cjs +0 -1469
  50. package/dist/generators-DP07m3rH.cjs.map +0 -1
  51. package/dist/generators-DkQwKTc2.js +0 -1427
  52. package/dist/generators-DkQwKTc2.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } 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 { 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 = createPlugin<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 bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n dataReturnType: client?.dataReturnType ?? 'data',\n pathParamsType,\n importPath: clientImportPath,\n paramsCasing,\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.driver.getPluginByName(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: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\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: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\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 pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAuBA,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;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,OAAO,QAAQ,EACjB,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,eACA,cACA,aACA,WACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe,KAAA;AAEhH,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,QAAQ,QAAQ;IAChB,SAAS,QAAQ;IACjB,QAAQ;IACR,YAAY,QAAQ,cAAc;IAClC,gBAAgB,QAAQ,kBAAkB;IAC1C;IACA,YAAY;IACZ;IACD;GACD,UAAU,WACN;IACE,YAAY;IACZ,kBAAkB;IAClB,aAAa,KAAA;IACb,WAAW,KAAA;IACX,eAAe,KAAA;IACf,GAAG;IACJ,GACD;GACJ;GACA;GACA,OACE,UAAU,QACN,QACA;IACE,SAAS,CAAC,MAAM;IAChB,YAAY;IACZ,GAAG;IACJ;GACP;GAC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"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverReactQuery.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginReactQuery } from '../types.ts'\n\n/**\n * Naming convention resolver for React Query plugin.\n *\n * Provides default naming helpers using camelCase for functions and file paths.\n *\n * @example\n * `resolverReactQuery.default('list pets', 'function') // → 'listPets'`\n */\nexport const resolverReactQuery = defineResolver<PluginReactQuery>((ctx) => ({\n name: 'default',\n pluginName: 'plugin-react-query',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return ctx.default(name, 'function')\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 { MutationKey } from './components/MutationKey.tsx'\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 { resolverReactQuery } from './resolvers/resolverReactQuery.ts'\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 mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n customOptions,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ??\n [\n queryGenerator,\n suspenseQueryGenerator,\n infiniteQueryGenerator,\n suspenseInfiniteQueryGenerator,\n mutationGenerator,\n hookOptionsGenerator,\n customHookOptionsFileGenerator,\n ].filter(Boolean)\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 : undefined\n\n return {\n name: pluginReactQueryName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverReactQuery, ...userResolver } : resolverReactQuery\n\n ctx.setOptions({\n output,\n transformers,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: '@tanstack/react-query',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n nextParam: undefined,\n previousParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n ast.createSource({\n name: 'fetch',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginReactQuery\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYA,MAAa,qBAAqB,gBAAkC,SAAS;CAC3E,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;AAClB,SAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;AAChB,SAAO,IAAI,QAAQ,MAAM,WAAW;;CAEvC,EAAE;;;ACEH,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,kBAAk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ACA,eAAe,gBAAgB;KAAE,MAAM;KAAwB,GAAG;KAAe,GAAG,KAAA;IACpF;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,YAAY,SAAS;AACzB,OAAI,gBACF,KAAI,eAAe,gBAAgB;AAGrC,QAAK,MAAM,OAAO,mBAChB,KAAI,aAAa,IAAI;AAEvB,QAAK,MAAM,OAAO,eAChB,KAAI,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;AAE7G,OAAI,QAAQ,UAAU,CAAC,mBAAmB,CAAC,iBACzC,KAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,eAAe,UAAUA,WAAoBC,OAAkB,CAAC;KACvF,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;AAGJ,OAAI,CAAC,gBACH,KAAI,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,47 +1,32 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
2
+ import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
3
3
  import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
4
- import { Exclude, Include, OperationSchemas, Override, ResolvePathOptions } from "@kubb/plugin-oas";
5
- import { HttpMethod, Oas, Operation, contentType } from "@kubb/oas";
6
- import { FunctionParams } from "@kubb/react-fabric";
7
- import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
8
- import { FabricReactNode } from "@kubb/react-fabric/types";
4
+ import { PluginTs } from "@kubb/plugin-ts";
5
+ import { KubbReactNode } from "@kubb/renderer-jsx/types";
9
6
 
10
7
  //#region ../../internals/tanstack-query/src/types.d.ts
11
8
  type ParamsCasing = 'camelcase' | undefined;
12
- type PathParamsType = 'object' | 'inline';
13
- type TransformerProps = {
14
- operation: Operation;
15
- schemas: OperationSchemas;
9
+ type Transformer = (props: {
10
+ node: ast.OperationNode;
16
11
  casing: ParamsCasing;
17
- };
18
- type Transformer = (props: TransformerProps) => unknown[];
12
+ }) => unknown[];
19
13
  //#endregion
20
14
  //#region ../../internals/tanstack-query/src/components/MutationKey.d.ts
21
15
  type Props$1 = {
22
16
  name: string;
23
- typeName: string;
24
- typeSchemas: OperationSchemas;
25
- operation: Operation;
26
- paramsCasing: ParamsCasing;
27
- pathParamsType: PathParamsType;
17
+ node: ast.OperationNode;
18
+ paramsCasing: 'camelcase' | undefined;
19
+ pathParamsType: 'object' | 'inline';
28
20
  transformer: Transformer | undefined;
29
21
  };
30
- type GetParamsProps$1 = {
31
- pathParamsType: PathParamsType;
32
- typeSchemas: OperationSchemas;
33
- };
34
22
  declare function MutationKey$1({
35
23
  name,
36
- typeSchemas,
37
- pathParamsType,
38
24
  paramsCasing,
39
- operation,
40
- typeName,
25
+ node,
41
26
  transformer
42
- }: Props$1): FabricReactNode;
27
+ }: Props$1): KubbReactNode;
43
28
  declare namespace MutationKey$1 {
44
- var getParams: ({}: GetParamsProps$1) => FunctionParams;
29
+ var getParams: () => ast.FunctionParametersNode;
45
30
  var getTransformer: Transformer;
46
31
  }
47
32
  //#endregion
@@ -49,51 +34,69 @@ declare namespace MutationKey$1 {
49
34
  type Props = {
50
35
  name: string;
51
36
  typeName: string;
52
- typeSchemas: OperationSchemas;
53
- operation: Operation;
54
- paramsCasing: ParamsCasing;
55
- pathParamsType: PathParamsType;
37
+ node: ast.OperationNode;
38
+ tsResolver: PluginTs['resolver'];
39
+ paramsCasing: 'camelcase' | undefined;
40
+ pathParamsType: 'object' | 'inline';
56
41
  transformer: Transformer | undefined;
57
42
  };
58
- type GetParamsProps = {
59
- paramsCasing: ParamsCasing;
60
- pathParamsType: PathParamsType;
61
- typeSchemas: OperationSchemas;
62
- };
63
43
  declare function QueryKey$1({
64
44
  name,
65
- typeSchemas,
45
+ node,
46
+ tsResolver,
66
47
  paramsCasing,
67
48
  pathParamsType,
68
- operation,
69
49
  typeName,
70
50
  transformer
71
- }: Props): FabricReactNode;
51
+ }: Props): KubbReactNode;
72
52
  declare namespace QueryKey$1 {
73
- var getParams: ({
74
- pathParamsType,
75
- paramsCasing,
76
- typeSchemas
77
- }: GetParamsProps) => FunctionParams;
53
+ var getParams: (node: ast.OperationNode, options: {
54
+ pathParamsType: "object" | "inline";
55
+ paramsCasing: "camelcase" | undefined;
56
+ resolver: PluginTs["resolver"];
57
+ }) => ast.FunctionParametersNode;
78
58
  var getTransformer: Transformer;
59
+ var callPrinter: {
60
+ name: "functionParameters";
61
+ options: {
62
+ mode: "declaration" | "call" | "keys" | "values";
63
+ transformName?: (name: string) => string;
64
+ transformType?: (type: string) => string;
65
+ };
66
+ transform: (node: ast.FunctionParamNode) => string | null | undefined;
67
+ print: (node: ast.FunctionParamNode) => string | null | undefined;
68
+ };
79
69
  }
80
70
  //#endregion
81
71
  //#region src/types.d.ts
72
+ /**
73
+ * Resolver for React Query that provides naming methods for hook functions.
74
+ */
75
+ type ResolverReactQuery = Resolver & {
76
+ /**
77
+ * Resolves the hook function name for an operation.
78
+ *
79
+ * @example Resolving hook names
80
+ * `resolver.resolveName('show pet by id') // -> 'showPetById'`
81
+ */
82
+ resolveName(this: ResolverReactQuery, name: string): string;
83
+ };
82
84
  type Suspense = object;
83
85
  /**
84
- * Customize the queryKey
86
+ * Customize the queryKey.
85
87
  */
86
88
  type QueryKey = Transformer;
87
89
  /**
88
- * Customize the mutationKey
90
+ * Customize the mutationKey.
89
91
  */
90
92
  type MutationKey = Transformer;
91
93
  type Query = {
92
94
  /**
93
- * Define which HttpMethods can be used for queries
95
+ * HTTP methods to use for queries.
96
+ *
94
97
  * @default ['get']
95
98
  */
96
- methods: Array<HttpMethod>;
99
+ methods?: Array<string>;
97
100
  /**
98
101
  * Path to the useQuery hook for useQuery functionality.
99
102
  * Used as `import { useQuery } from '${importPath}'`.
@@ -105,13 +108,14 @@ type Query = {
105
108
  };
106
109
  type Mutation = {
107
110
  /**
108
- * Define which HttpMethods can be used for mutations
111
+ * HTTP methods to use for mutations.
112
+ *
109
113
  * @default ['post', 'put', 'delete']
110
114
  */
111
- methods: Array<HttpMethod>;
115
+ methods?: Array<string>;
112
116
  /**
113
- * Path to the useQuery hook for useQuery functionality.
114
- * Used as `import { useQuery } from '${importPath}'`.
117
+ * Path to the useMutation hook for useMutation functionality.
118
+ * Used as `import { useMutation } from '${importPath}'`.
115
119
  * Accepts relative and absolute paths.
116
120
  * Path is used as-is; relative paths are based on the generated file location.
117
121
  * @default '@tanstack/react-query'
@@ -164,97 +168,98 @@ type Options = {
164
168
  * Specify the export location for the files and define the behavior of the output
165
169
  * @default { path: 'hooks', barrelType: 'named' }
166
170
  */
167
- output?: Output<Oas>;
168
- /**
169
- * Define which contentType should be used.
170
- * By default, the first JSON valid mediaType is used
171
- */
172
- contentType?: contentType;
171
+ output?: Output;
173
172
  /**
174
173
  * Group the @tanstack/query hooks based on the provided name.
175
174
  */
176
175
  group?: Group;
177
176
  client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>;
178
177
  /**
179
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
178
+ * Tags, operations, or paths to exclude from generation.
180
179
  */
181
180
  exclude?: Array<Exclude>;
182
181
  /**
183
- * Array containing include parameters to include tags/operations/methods/paths.
182
+ * Tags, operations, or paths to include in generation.
184
183
  */
185
184
  include?: Array<Include>;
186
185
  /**
187
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
186
+ * Override options for specific tags, operations, or paths.
188
187
  */
189
188
  override?: Array<Override<ResolvedOptions>>;
190
189
  /**
191
- * How to style your params, by default no casing is applied
192
- * - 'camelcase' uses camelcase for the params names
190
+ * Apply casing to parameter names.
193
191
  */
194
192
  paramsCasing?: 'camelcase';
195
193
  /**
196
- * How to pass your params.
197
- * - 'object' returns the params and pathParams as an object.
198
- * - 'inline' returns the params as comma separated params.
194
+ * How parameters are passed: grouped in an object or spread inline.
195
+ *
199
196
  * @default 'inline'
200
197
  */
201
198
  paramsType?: 'object' | 'inline';
202
199
  /**
203
- * How to pass your pathParams.
204
- * - 'object' returns the pathParams as an object.
205
- * - 'inline': returns the pathParams as comma separated params.
200
+ * How path parameters are passed: grouped in an object or spread inline.
201
+ *
206
202
  * @default 'inline'
207
203
  */
208
204
  pathParamsType?: PluginClient['options']['pathParamsType'];
209
205
  /**
210
- * When set, an infiniteQuery hooks is added.
206
+ * Add infinite query hooks.
211
207
  */
212
208
  infinite?: Partial<Infinite> | false;
213
209
  /**
214
- * When set, a suspenseQuery hooks is added.
210
+ * Add suspense query hooks.
215
211
  */
216
212
  suspense?: Partial<Suspense> | false;
217
213
  queryKey?: QueryKey;
218
214
  /**
219
- * Override some useQuery behaviors.
215
+ * Configure useQuery behavior.
220
216
  */
221
217
  query?: Partial<Query> | false;
222
218
  mutationKey?: MutationKey;
223
219
  /**
224
- * Override some useMutation behaviors.
220
+ * Configure useMutation behavior.
225
221
  */
226
222
  mutation?: Partial<Mutation> | false;
227
223
  /**
228
- * When set, a custom hook is used to customize the options of the generated hooks.
229
- * It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
224
+ * Use a custom hook to customize hook options and generate a HookOptions type.
230
225
  */
231
226
  customOptions?: CustomOptions;
232
227
  /**
233
- * Which parser should be used before returning the data to `@tanstack/query`.
234
- * `'zod'` uses `@kubb/plugin-zod` to parse the data.
228
+ * Parser to use for validating response data.
235
229
  */
236
230
  parser?: PluginClient['options']['parser'];
237
231
  transformers?: {
238
232
  /**
239
- * Customize the names based on the type that is provided by the plugin.
233
+ * Override the default naming for hooks.
240
234
  */
241
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
235
+ name?: (name: string, type?: string) => string;
242
236
  };
243
237
  /**
244
- * Define some generators next to the react-query generators
238
+ * Override naming conventions for function names and types.
245
239
  */
246
- generators?: Array<Generator$1<PluginReactQuery>>;
240
+ resolver?: Partial<ResolverReactQuery> & ThisType<ResolverReactQuery>;
241
+ /**
242
+ * AST visitor to transform generated nodes.
243
+ */
244
+ transformer?: ast.Visitor;
245
+ /**
246
+ * Additional generators alongside the default generators.
247
+ */
248
+ generators?: Array<Generator<PluginReactQuery>>;
247
249
  };
248
250
  type ResolvedOptions = {
249
- output: Output<Oas>;
250
- group: Options['group'];
251
+ output: Output;
252
+ group: Group | undefined;
253
+ exclude: NonNullable<Options['exclude']>;
254
+ include: Options['include'];
255
+ override: NonNullable<Options['override']>;
251
256
  client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
252
257
  parser: Required<NonNullable<Options['parser']>>;
253
258
  pathParamsType: NonNullable<Options['pathParamsType']>;
254
259
  paramsCasing: Options['paramsCasing'];
255
260
  paramsType: NonNullable<Options['paramsType']>;
256
261
  /**
257
- * Only used of infinite
262
+ * Only used for infinite
258
263
  */
259
264
  infinite: NonNullable<Infinite> | false;
260
265
  suspense: Suspense | false;
@@ -263,8 +268,17 @@ type ResolvedOptions = {
263
268
  mutationKey: MutationKey | undefined;
264
269
  mutation: NonNullable<Required<Mutation>> | false;
265
270
  customOptions: NonNullable<Required<CustomOptions>> | undefined;
271
+ resolver: ResolverReactQuery;
272
+ transformers: NonNullable<Options['transformers']>;
266
273
  };
267
- type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
274
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>;
275
+ declare global {
276
+ namespace Kubb {
277
+ interface PluginRegistry {
278
+ 'plugin-react-query': PluginReactQuery;
279
+ }
280
+ }
281
+ }
268
282
  //#endregion
269
283
  export { MutationKey$1 as a, QueryKey$1 as i, Options as n, PluginReactQuery as r, Infinite as t };
270
- //# sourceMappingURL=types-D5S7Ny9r.d.ts.map
284
+ //# sourceMappingURL=types-DfaFRSBf.d.ts.map
package/package.json CHANGED
@@ -1,35 +1,56 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "5.0.0-alpha.8",
3
+ "version": "5.0.0-beta.3",
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
- "react-query",
7
- "tanstack-query",
8
- "react",
9
- "react-hooks",
10
- "hooks",
11
- "data-fetching",
12
6
  "api-client",
13
- "sdk-generator",
14
- "typescript",
15
- "type-safe",
16
- "openapi",
17
- "swagger",
18
- "oas",
19
7
  "code-generator",
20
8
  "codegen",
9
+ "data-fetching",
10
+ "hooks",
11
+ "kubb",
12
+ "oas",
13
+ "openapi",
21
14
  "plugins",
22
- "kubb"
15
+ "react",
16
+ "react-hooks",
17
+ "react-query",
18
+ "sdk-generator",
19
+ "swagger",
20
+ "tanstack-query",
21
+ "type-safe",
22
+ "typescript"
23
23
  ],
24
+ "license": "MIT",
25
+ "author": "stijnvanhulle",
24
26
  "repository": {
25
27
  "type": "git",
26
- "url": "git+https://github.com/kubb-labs/kubb.git",
28
+ "url": "git+https://github.com/kubb-labs/plugins.git",
27
29
  "directory": "packages/plugin-react-query"
28
30
  },
29
- "license": "MIT",
30
- "author": "stijnvanhulle",
31
- "sideEffects": false,
31
+ "files": [
32
+ "src",
33
+ "dist",
34
+ "plugin.json",
35
+ "!/**/**.test.**",
36
+ "!/**/__tests__/**",
37
+ "!/**/__snapshots__/**"
38
+ ],
32
39
  "type": "module",
40
+ "sideEffects": false,
41
+ "main": "./dist/index.cjs",
42
+ "module": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "typesVersions": {
45
+ "*": {
46
+ "components": [
47
+ "./dist/components.d.ts"
48
+ ],
49
+ "generators": [
50
+ "./dist/generators.d.ts"
51
+ ]
52
+ }
53
+ },
33
54
  "exports": {
34
55
  ".": {
35
56
  "import": "./dist/index.js",
@@ -45,24 +66,25 @@
45
66
  },
46
67
  "./package.json": "./package.json"
47
68
  },
48
- "types": "./dist/index.d.ts",
49
- "typesVersions": {
50
- "*": {
51
- "components": [
52
- "./dist/components.d.ts"
53
- ],
54
- "generators": [
55
- "./dist/generators.d.ts"
56
- ]
57
- }
69
+ "publishConfig": {
70
+ "access": "public",
71
+ "registry": "https://registry.npmjs.org/"
72
+ },
73
+ "dependencies": {
74
+ "@kubb/core": "5.0.0-beta.3",
75
+ "@kubb/renderer-jsx": "5.0.0-beta.3",
76
+ "remeda": "^2.34.0",
77
+ "@kubb/plugin-client": "5.0.0-beta.3",
78
+ "@kubb/plugin-ts": "5.0.0-beta.3",
79
+ "@kubb/plugin-zod": "5.0.0-beta.3"
80
+ },
81
+ "devDependencies": {
82
+ "@internals/tanstack-query": "0.0.0",
83
+ "@internals/utils": "0.0.0"
84
+ },
85
+ "peerDependencies": {
86
+ "@kubb/renderer-jsx": "5.0.0-beta.3"
58
87
  },
59
- "files": [
60
- "src",
61
- "dist",
62
- "!/**/**.test.**",
63
- "!/**/__tests__/**",
64
- "!/**/__snapshots__/**"
65
- ],
66
88
  "size-limit": [
67
89
  {
68
90
  "path": "./dist/*.js",
@@ -70,39 +92,14 @@
70
92
  "gzip": true
71
93
  }
72
94
  ],
73
- "dependencies": {
74
- "@kubb/fabric-core": "0.14.0",
75
- "@kubb/react-fabric": "0.14.0",
76
- "remeda": "^2.33.6",
77
- "@kubb/core": "5.0.0-alpha.8",
78
- "@kubb/oas": "5.0.0-alpha.8",
79
- "@kubb/plugin-client": "5.0.0-alpha.8",
80
- "@kubb/plugin-oas": "5.0.0-alpha.8",
81
- "@kubb/plugin-ts": "5.0.0-alpha.8",
82
- "@kubb/plugin-zod": "5.0.0-alpha.8"
83
- },
84
- "peerDependencies": {
85
- "@kubb/fabric-core": "0.14.0",
86
- "@kubb/react-fabric": "0.14.0"
87
- },
88
95
  "engines": {
89
96
  "node": ">=22"
90
97
  },
91
- "publishConfig": {
92
- "access": "public",
93
- "registry": "https://registry.npmjs.org/"
94
- },
95
- "main": "./dist/index.cjs",
96
- "module": "./dist/index.js",
97
- "devDependencies": {
98
- "@internals/tanstack-query": "0.0.0",
99
- "@internals/utils": "0.0.0"
100
- },
101
98
  "scripts": {
102
99
  "build": "tsdown && size-limit",
103
100
  "clean": "npx rimraf ./dist",
104
- "lint": "bun biome lint .",
105
- "lint:fix": "bun biome lint --fix --unsafe .",
101
+ "lint": "oxlint .",
102
+ "lint:fix": "oxlint --fix .",
106
103
  "release": "pnpm publish --no-git-check",
107
104
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
108
105
  "start": "tsdown --watch",