@kubb/plugin-react-query 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (80) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-ESENIDWJ.js +608 -0
  3. package/dist/chunk-ESENIDWJ.js.map +1 -0
  4. package/dist/chunk-HAC4WPCC.js +608 -0
  5. package/dist/chunk-HAC4WPCC.js.map +1 -0
  6. package/dist/chunk-JQEH3UHY.cjs +618 -0
  7. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  8. package/dist/chunk-JYBGTT23.cjs +618 -0
  9. package/dist/chunk-JYBGTT23.cjs.map +1 -0
  10. package/dist/components.cjs +35 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +143 -7
  13. package/dist/components.d.ts +143 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +77 -154
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +56 -140
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DFHc63S9.d.cts +179 -0
  29. package/dist/types-DFHc63S9.d.ts +179 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +121 -0
  33. package/src/components/Mutation.tsx +113 -321
  34. package/src/components/Query.tsx +91 -598
  35. package/src/components/QueryKey.tsx +51 -178
  36. package/src/components/QueryOptions.tsx +65 -468
  37. package/src/components/SuspenseQuery.tsx +129 -0
  38. package/src/components/index.ts +3 -1
  39. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +50 -0
  40. package/src/generators/__snapshots__/clientGetImportPath.ts +50 -0
  41. package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
  42. package/src/generators/__snapshots__/findByTags.ts +50 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +50 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +50 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +50 -0
  46. package/src/generators/__snapshots__/findInfiniteByTags.ts +56 -0
  47. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +56 -0
  48. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  49. package/src/generators/__snapshots__/postAsQuery.ts +48 -0
  50. package/src/generators/__snapshots__/updatePetById.ts +38 -0
  51. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
  52. package/src/generators/index.ts +4 -0
  53. package/src/generators/infiniteQueryGenerator.tsx +125 -0
  54. package/src/generators/mutationGenerator.tsx +96 -0
  55. package/src/generators/queryGenerator.tsx +122 -0
  56. package/src/generators/suspenseQueryGenerator.tsx +121 -0
  57. package/src/plugin.ts +51 -73
  58. package/src/types.ts +43 -91
  59. package/dist/chunk-5IL6M74X.js +0 -1504
  60. package/dist/chunk-5IL6M74X.js.map +0 -1
  61. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  62. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  63. package/dist/index-C9fwRDH7.d.cts +0 -579
  64. package/dist/index-C9fwRDH7.d.ts +0 -579
  65. package/src/OperationGenerator.tsx +0 -86
  66. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  67. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  68. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  69. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  70. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  71. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  72. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  73. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  74. package/src/components/Operations.tsx +0 -74
  75. package/src/components/QueryImports.tsx +0 -167
  76. package/src/components/SchemaType.tsx +0 -55
  77. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  78. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  79. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  80. package/src/utils.ts +0 -96
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, Operations, Query, QueryKey, QueryOptions } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\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' },\n group,\n exclude = [],\n include,\n override = [],\n parser,\n suspense = {},\n infinite,\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n mutate = {},\n query = {},\n queryOptions = {},\n templates,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n options: {\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n dataReturnType,\n pathParamsType,\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: query\n ? {\n queryKey: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n }\n : false,\n queryOptions,\n mutate: mutate\n ? {\n variablesType: 'hook',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutate,\n }\n : false,\n templates: {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n operations: Operations.templates,\n ...templates,\n },\n parser,\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 ?? FileManager.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 (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\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 prefix: 'use',\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 buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Hooks',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mutation } from './components/Mutation.tsx'\nimport { Operations } from './components/Operations.tsx'\nimport { Query } from './components/Query.tsx'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { QueryOptions } from './components/QueryOptions.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\nimport type { FileMeta, PluginReactQuery } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginReactQuery['resolvedOptions'], PluginReactQuery, FileMeta> {\n async all(operations: Operation[]): OperationMethodResult<FileMeta> {\n const { pluginManager, oas, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n operations: Operations.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n ...options.templates,\n }\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method)\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n {isMutate && templates?.mutation && <Mutation.File templates={templates.mutation} />}\n {isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && (\n <Query.File\n templates={{\n query: templates.query,\n queryKey: templates.queryKey,\n queryOptions: templates.queryOptions,\n queryImports: templates.queryImports,\n }}\n />\n )}\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,WAAW,kBAAkB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;;;ACR9B,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AAkCG,cA8BzB,YA9ByB;AArB5B,IAAM,qBAAN,cAAiC,UAA2E;AAAA,EACjH,MAAM,IAAI,YAA0D;AAClE,UAAM,EAAE,eAAe,KAAK,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;AAED,UAAM,YAAY;AAAA,MAChB,UAAU,SAAS;AAAA,MACnB,OAAO,MAAM;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K,CAAA,MAAA;AAAA,UACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,SACF;AAAA,OACF,CAAA;AAEA,MAAA,MAAM,QAAQ,MAAM,kBAAA,CAAmB,MAAM,cAAgB,EAAA,sBAAA,EAAwB,wBAAwB,iBAAiB,CAAA,CAAA;AAC9H,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } 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' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite,\n transformers = {},\n pathParamsType = 'inline',\n mutation = {},\n query = {},\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n options: {\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n pathParamsType: 'inline',\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: {\n key: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutation: {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n pathParamsType,\n parser,\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 ?? FileManager.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 (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\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 buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator)\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n"]}
@@ -0,0 +1,179 @@
1
+ import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
4
+
5
+ type Suspense = object;
6
+ type Query = {
7
+ /**
8
+ * Customize the queryKey, here you can specify a suffix.
9
+ */
10
+ key: (key: unknown[]) => unknown[];
11
+ /**
12
+ * Define which HttpMethods can be used for queries
13
+ * @default ['get']
14
+ */
15
+ methods: Array<HttpMethod>;
16
+ /**
17
+ * Path to the useQuery that will be used to do the useQuery functionality.
18
+ * It will be used as `import { useQuery } from '${importPath}'`.
19
+ * It allows both relative and absolute path.
20
+ * the path will be applied as is, so relative path should be based on the file being generated.
21
+ * @default '@tanstack/react-query'
22
+ */
23
+ importPath?: string;
24
+ };
25
+ type Mutation = {
26
+ /**
27
+ * Define which HttpMethods can be used for mutations
28
+ * @default ['post', 'put', 'delete']
29
+ */
30
+ methods: Array<HttpMethod>;
31
+ /**
32
+ * Path to the useQuery that will be used to do the useQuery functionality.
33
+ * It will be used as `import { useQuery } from '${importPath}'`.
34
+ * It allows both relative and absolute path.
35
+ * the path will be applied as is, so relative path should be based on the file being generated.
36
+ * @default '@tanstack/react-query'
37
+ */
38
+ importPath?: string;
39
+ };
40
+ type Infinite = {
41
+ /**
42
+ * Specify the params key used for `pageParam`.
43
+ * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
44
+ * @default `'id'`
45
+ */
46
+ queryParam: string;
47
+ /**
48
+ * Which field of the data will be used, set it to undefined when no cursor is known.
49
+ */
50
+ cursorParam?: string | undefined;
51
+ /**
52
+ * The initial value, the value of the first page.
53
+ * @default `0`
54
+ */
55
+ initialPageParam: unknown;
56
+ };
57
+ type Options = {
58
+ /**
59
+ * @default 'hooks'
60
+ */
61
+ output?: Output;
62
+ /**
63
+ * Group the @tanstack/query hooks based on the provided name.
64
+ */
65
+ group?: {
66
+ /**
67
+ * Tag will group based on the operation tag inside the Swagger file
68
+ */
69
+ type: 'tag';
70
+ /**
71
+ * Relative path to save the grouped @tanstack/query hooks.
72
+ *
73
+ * `{{tag}}` will be replaced by the current tagName.
74
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
75
+ * @default `${output}/{{tag}}Controller`
76
+ */
77
+ output?: string;
78
+ /**
79
+ * Name to be used for the `export * as {{exportAs}} from './`
80
+ * @default `"{{tag}}Hooks"`
81
+ */
82
+ exportAs?: string;
83
+ };
84
+ client?: {
85
+ /**
86
+ * Path to the client that will be used to do the API calls.
87
+ * It will be used as `import client from '${client.importPath}'`.
88
+ * It allows both relative and absolute path.
89
+ * the path will be applied as is, so relative path should be based on the file being generated.
90
+ * @default '@kubb/plugin-client/client'
91
+ */
92
+ importPath?: string;
93
+ /**
94
+ * ReturnType that needs to be used when calling client().
95
+ *
96
+ * `Data` will return ResponseConfig[data].
97
+ *
98
+ * `Full` will return ResponseConfig.
99
+ * @default `'data'`
100
+ * @private
101
+ */
102
+ dataReturnType?: 'data' | 'full';
103
+ };
104
+ /**
105
+ * ReturnType that needs to be used when calling client().
106
+ *
107
+ * `Data` will return ResponseConfig[data].
108
+ *
109
+ * `Full` will return ResponseConfig.
110
+ * @default `'data'`
111
+ * @private
112
+ */
113
+ /**
114
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
115
+ */
116
+ exclude?: Array<Exclude>;
117
+ /**
118
+ * Array containing include parameters to include tags/operations/methods/paths.
119
+ */
120
+ include?: Array<Include>;
121
+ /**
122
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
123
+ */
124
+ override?: Array<Override<ResolvedOptions>>;
125
+ /**
126
+ * How to pass your pathParams.
127
+ *
128
+ * `object` will return the pathParams as an object.
129
+ *
130
+ * `inline` will return the pathParams as comma separated params.
131
+ * @default `'inline'`
132
+ * @private
133
+ */
134
+ pathParamsType?: 'object' | 'inline';
135
+ /**
136
+ * When set, an infiniteQuery hooks will be added.
137
+ */
138
+ infinite?: Partial<Infinite> | false;
139
+ /**
140
+ * When set, a suspenseQuery hooks will be added.
141
+ */
142
+ suspense?: Partial<Suspense> | false;
143
+ /**
144
+ * Override some useQuery behaviours.
145
+ */
146
+ query?: Partial<Query> | false;
147
+ /**
148
+ * Override some useMutation behaviours.
149
+ */
150
+ mutation?: Mutation | false;
151
+ /**
152
+ * Which parser can be used before returning the data to `@tanstack/query`.
153
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
154
+ */
155
+ parser?: 'client' | 'zod';
156
+ transformers?: {
157
+ /**
158
+ * Customize the names based on the type that is provided by the plugin.
159
+ */
160
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
161
+ };
162
+ };
163
+ type ResolvedOptions = {
164
+ output: Output;
165
+ baseURL: string | undefined;
166
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
167
+ parser: Required<NonNullable<Options['parser']>>;
168
+ pathParamsType: NonNullable<Options['pathParamsType']>;
169
+ /**
170
+ * Only used of infinite
171
+ */
172
+ infinite: NonNullable<Infinite> | false;
173
+ suspense: Suspense | false;
174
+ query: NonNullable<Required<Query>> | false;
175
+ mutation: NonNullable<Required<Mutation>> | false;
176
+ };
177
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
178
+
179
+ export type { Infinite as I, Options as O, PluginReactQuery as P };
@@ -0,0 +1,179 @@
1
+ import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
4
+
5
+ type Suspense = object;
6
+ type Query = {
7
+ /**
8
+ * Customize the queryKey, here you can specify a suffix.
9
+ */
10
+ key: (key: unknown[]) => unknown[];
11
+ /**
12
+ * Define which HttpMethods can be used for queries
13
+ * @default ['get']
14
+ */
15
+ methods: Array<HttpMethod>;
16
+ /**
17
+ * Path to the useQuery that will be used to do the useQuery functionality.
18
+ * It will be used as `import { useQuery } from '${importPath}'`.
19
+ * It allows both relative and absolute path.
20
+ * the path will be applied as is, so relative path should be based on the file being generated.
21
+ * @default '@tanstack/react-query'
22
+ */
23
+ importPath?: string;
24
+ };
25
+ type Mutation = {
26
+ /**
27
+ * Define which HttpMethods can be used for mutations
28
+ * @default ['post', 'put', 'delete']
29
+ */
30
+ methods: Array<HttpMethod>;
31
+ /**
32
+ * Path to the useQuery that will be used to do the useQuery functionality.
33
+ * It will be used as `import { useQuery } from '${importPath}'`.
34
+ * It allows both relative and absolute path.
35
+ * the path will be applied as is, so relative path should be based on the file being generated.
36
+ * @default '@tanstack/react-query'
37
+ */
38
+ importPath?: string;
39
+ };
40
+ type Infinite = {
41
+ /**
42
+ * Specify the params key used for `pageParam`.
43
+ * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
44
+ * @default `'id'`
45
+ */
46
+ queryParam: string;
47
+ /**
48
+ * Which field of the data will be used, set it to undefined when no cursor is known.
49
+ */
50
+ cursorParam?: string | undefined;
51
+ /**
52
+ * The initial value, the value of the first page.
53
+ * @default `0`
54
+ */
55
+ initialPageParam: unknown;
56
+ };
57
+ type Options = {
58
+ /**
59
+ * @default 'hooks'
60
+ */
61
+ output?: Output;
62
+ /**
63
+ * Group the @tanstack/query hooks based on the provided name.
64
+ */
65
+ group?: {
66
+ /**
67
+ * Tag will group based on the operation tag inside the Swagger file
68
+ */
69
+ type: 'tag';
70
+ /**
71
+ * Relative path to save the grouped @tanstack/query hooks.
72
+ *
73
+ * `{{tag}}` will be replaced by the current tagName.
74
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
75
+ * @default `${output}/{{tag}}Controller`
76
+ */
77
+ output?: string;
78
+ /**
79
+ * Name to be used for the `export * as {{exportAs}} from './`
80
+ * @default `"{{tag}}Hooks"`
81
+ */
82
+ exportAs?: string;
83
+ };
84
+ client?: {
85
+ /**
86
+ * Path to the client that will be used to do the API calls.
87
+ * It will be used as `import client from '${client.importPath}'`.
88
+ * It allows both relative and absolute path.
89
+ * the path will be applied as is, so relative path should be based on the file being generated.
90
+ * @default '@kubb/plugin-client/client'
91
+ */
92
+ importPath?: string;
93
+ /**
94
+ * ReturnType that needs to be used when calling client().
95
+ *
96
+ * `Data` will return ResponseConfig[data].
97
+ *
98
+ * `Full` will return ResponseConfig.
99
+ * @default `'data'`
100
+ * @private
101
+ */
102
+ dataReturnType?: 'data' | 'full';
103
+ };
104
+ /**
105
+ * ReturnType that needs to be used when calling client().
106
+ *
107
+ * `Data` will return ResponseConfig[data].
108
+ *
109
+ * `Full` will return ResponseConfig.
110
+ * @default `'data'`
111
+ * @private
112
+ */
113
+ /**
114
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
115
+ */
116
+ exclude?: Array<Exclude>;
117
+ /**
118
+ * Array containing include parameters to include tags/operations/methods/paths.
119
+ */
120
+ include?: Array<Include>;
121
+ /**
122
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
123
+ */
124
+ override?: Array<Override<ResolvedOptions>>;
125
+ /**
126
+ * How to pass your pathParams.
127
+ *
128
+ * `object` will return the pathParams as an object.
129
+ *
130
+ * `inline` will return the pathParams as comma separated params.
131
+ * @default `'inline'`
132
+ * @private
133
+ */
134
+ pathParamsType?: 'object' | 'inline';
135
+ /**
136
+ * When set, an infiniteQuery hooks will be added.
137
+ */
138
+ infinite?: Partial<Infinite> | false;
139
+ /**
140
+ * When set, a suspenseQuery hooks will be added.
141
+ */
142
+ suspense?: Partial<Suspense> | false;
143
+ /**
144
+ * Override some useQuery behaviours.
145
+ */
146
+ query?: Partial<Query> | false;
147
+ /**
148
+ * Override some useMutation behaviours.
149
+ */
150
+ mutation?: Mutation | false;
151
+ /**
152
+ * Which parser can be used before returning the data to `@tanstack/query`.
153
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
154
+ */
155
+ parser?: 'client' | 'zod';
156
+ transformers?: {
157
+ /**
158
+ * Customize the names based on the type that is provided by the plugin.
159
+ */
160
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
161
+ };
162
+ };
163
+ type ResolvedOptions = {
164
+ output: Output;
165
+ baseURL: string | undefined;
166
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
167
+ parser: Required<NonNullable<Options['parser']>>;
168
+ pathParamsType: NonNullable<Options['pathParamsType']>;
169
+ /**
170
+ * Only used of infinite
171
+ */
172
+ infinite: NonNullable<Infinite> | false;
173
+ suspense: Suspense | false;
174
+ query: NonNullable<Required<Query>> | false;
175
+ mutation: NonNullable<Required<Mutation>> | false;
176
+ };
177
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
178
+
179
+ export type { Infinite as I, Options as O, PluginReactQuery as P };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.21",
4
4
  "description": "Generator react-query hooks",
5
5
  "keywords": [
6
6
  "faker",
@@ -29,6 +29,11 @@
29
29
  "require": "./dist/index.cjs",
30
30
  "default": "./dist/index.cjs"
31
31
  },
32
+ "./generators": {
33
+ "import": "./dist/generators.js",
34
+ "require": "./dist/generators.cjs",
35
+ "default": "./dist/generators.cjs"
36
+ },
32
37
  "./components": {
33
38
  "import": "./dist/components.js",
34
39
  "require": "./dist/components.cjs",
@@ -44,6 +49,9 @@
44
49
  "*": {
45
50
  "components": [
46
51
  "./dist/components.d.ts"
52
+ ],
53
+ "generators": [
54
+ "./dist/generators.d.ts"
47
55
  ]
48
56
  }
49
57
  },
@@ -54,27 +62,24 @@
54
62
  "!/**/__tests__/**"
55
63
  ],
56
64
  "dependencies": {
57
- "@kubb/core": "3.0.0-alpha.2",
58
- "@kubb/fs": "3.0.0-alpha.2",
59
- "@kubb/oas": "3.0.0-alpha.2",
60
- "@kubb/parser-ts": "3.0.0-alpha.2",
61
- "@kubb/plugin-faker": "3.0.0-alpha.2",
62
- "@kubb/plugin-oas": "3.0.0-alpha.2",
63
- "@kubb/plugin-ts": "3.0.0-alpha.2",
64
- "@kubb/plugin-zod": "3.0.0-alpha.2",
65
- "@kubb/react": "3.0.0-alpha.2"
65
+ "@kubb/core": "3.0.0-alpha.21",
66
+ "@kubb/fs": "3.0.0-alpha.21",
67
+ "@kubb/oas": "3.0.0-alpha.21",
68
+ "@kubb/plugin-oas": "3.0.0-alpha.21",
69
+ "@kubb/plugin-ts": "3.0.0-alpha.21",
70
+ "@kubb/plugin-zod": "3.0.0-alpha.21",
71
+ "@kubb/react": "3.0.0-alpha.21"
66
72
  },
67
73
  "devDependencies": {
68
- "@types/react": "^18.3.4",
74
+ "@types/react": "^18.3.8",
69
75
  "react": "^18.3.1",
70
- "tsup": "^8.2.4",
71
- "typescript": "^5.5.4",
72
- "@kubb/config-biome": "3.0.0-alpha.2",
73
- "@kubb/config-ts": "3.0.0-alpha.2",
74
- "@kubb/config-tsup": "3.0.0-alpha.2"
76
+ "tsup": "^8.3.0",
77
+ "typescript": "^5.6.2",
78
+ "@kubb/config-ts": "3.0.0-alpha.21",
79
+ "@kubb/config-tsup": "3.0.0-alpha.21"
75
80
  },
76
81
  "peerDependencies": {
77
- "@kubb/react": "3.0.0-alpha.2"
82
+ "@kubb/react": "3.0.0-alpha.21"
78
83
  },
79
84
  "engines": {
80
85
  "node": ">=20"
@@ -0,0 +1,129 @@
1
+ import { File, Function, FunctionParams } from '@kubb/react'
2
+
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import type { OperationSchemas } from '@kubb/plugin-oas'
5
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
+ import type { ReactNode } from 'react'
7
+ import type { PluginReactQuery } from '../types.ts'
8
+ import { QueryKey } from './QueryKey.tsx'
9
+ import { QueryOptions } from './QueryOptions.tsx'
10
+
11
+ type Props = {
12
+ /**
13
+ * Name of the function
14
+ */
15
+ name: string
16
+ queryOptionsName: string
17
+ queryKeyName: string
18
+ queryKeyTypeName: string
19
+ typeSchemas: OperationSchemas
20
+ operation: Operation
21
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
22
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
23
+ }
24
+
25
+ type GetParamsProps = {
26
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
27
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
28
+ typeSchemas: OperationSchemas
29
+ }
30
+
31
+ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
32
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
33
+
34
+ return FunctionParams.factory({
35
+ pathParams: {
36
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
37
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
38
+ },
39
+ data: typeSchemas.request?.name
40
+ ? {
41
+ type: typeSchemas.request?.name,
42
+ optional: isOptional(typeSchemas.request?.schema),
43
+ }
44
+ : undefined,
45
+ params: typeSchemas.queryParams?.name
46
+ ? {
47
+ type: typeSchemas.queryParams?.name,
48
+ optional: isOptional(typeSchemas.queryParams?.schema),
49
+ }
50
+ : undefined,
51
+ headers: typeSchemas.headerParams?.name
52
+ ? {
53
+ type: typeSchemas.headerParams?.name,
54
+ optional: isOptional(typeSchemas.headerParams?.schema),
55
+ }
56
+ : undefined,
57
+ options: {
58
+ type: `
59
+ {
60
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
61
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
62
+ }
63
+ `,
64
+ default: '{}',
65
+ },
66
+ })
67
+ }
68
+
69
+ export function InfiniteQuery({
70
+ name,
71
+ queryKeyTypeName,
72
+ queryOptionsName,
73
+ queryKeyName,
74
+ pathParamsType,
75
+ dataReturnType,
76
+ typeSchemas,
77
+ operation,
78
+ }: Props): ReactNode {
79
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
80
+ const returnType = `UseInfiniteQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown'].join(', ')}> & { queryKey: TQueryKey }`
81
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
82
+
83
+ const queryKeyParams = QueryKey.getParams({
84
+ pathParamsType,
85
+ typeSchemas,
86
+ })
87
+ const queryOptionsParams = QueryOptions.getParams({
88
+ pathParamsType,
89
+ typeSchemas,
90
+ })
91
+ const params = getParams({
92
+ pathParamsType,
93
+ dataReturnType,
94
+ typeSchemas,
95
+ })
96
+
97
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as InfiniteQueryObserverOptions`
98
+
99
+ return (
100
+ <File.Source name={name} isExportable isIndexable>
101
+ <Function
102
+ name={name}
103
+ export
104
+ generics={generics.join(', ')}
105
+ params={params.toConstructor()}
106
+ JSDoc={{
107
+ comments: getComments(operation),
108
+ }}
109
+ >
110
+ {`
111
+ const { query: queryOptions, client: config = {} } = options ?? {}
112
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
113
+
114
+ const query = useInfiniteQuery({
115
+ ...${queryOptions},
116
+ queryKey,
117
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
118
+ }) as ${returnType}
119
+
120
+ query.queryKey = queryKey as TQueryKey
121
+
122
+ return query
123
+ `}
124
+ </Function>
125
+ </File.Source>
126
+ )
127
+ }
128
+
129
+ InfiniteQuery.getParams = getParams