@kubb/plugin-react-query 5.0.0-alpha.9 → 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 -505
  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.cjs CHANGED
@@ -1,23 +1,48 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_components = require("./components-BHQT9ZLc.cjs");
3
- const require_generators = require("./generators-DP07m3rH.cjs");
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_components = require("./components-dAKJEn9b.cjs");
6
+ const require_generators = require("./generators-CWEQsdO9.cjs");
4
7
  let node_path = require("node:path");
5
- node_path = require_components.__toESM(node_path);
8
+ node_path = require_components.__toESM(node_path, 1);
6
9
  let _kubb_core = require("@kubb/core");
7
10
  let _kubb_plugin_client = require("@kubb/plugin-client");
8
11
  let _kubb_plugin_client_templates_clients_axios_source = require("@kubb/plugin-client/templates/clients/axios.source");
9
12
  let _kubb_plugin_client_templates_clients_fetch_source = require("@kubb/plugin-client/templates/clients/fetch.source");
10
13
  let _kubb_plugin_client_templates_config_source = require("@kubb/plugin-client/templates/config.source");
11
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
12
14
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
13
15
  let _kubb_plugin_zod = require("@kubb/plugin-zod");
16
+ //#region src/resolvers/resolverReactQuery.ts
17
+ /**
18
+ * Naming convention resolver for React Query plugin.
19
+ *
20
+ * Provides default naming helpers using camelCase for functions and file paths.
21
+ *
22
+ * @example
23
+ * `resolverReactQuery.default('list pets', 'function') // → 'listPets'`
24
+ */
25
+ const resolverReactQuery = (0, _kubb_core.defineResolver)((ctx) => ({
26
+ name: "default",
27
+ pluginName: "plugin-react-query",
28
+ default(name, type) {
29
+ return require_components.camelCase(name, { isFile: type === "file" });
30
+ },
31
+ resolveName(name) {
32
+ return ctx.default(name, "function");
33
+ }
34
+ }));
35
+ //#endregion
14
36
  //#region src/plugin.ts
15
37
  const pluginReactQueryName = "plugin-react-query";
16
- const pluginReactQuery = (0, _kubb_core.createPlugin)((options) => {
38
+ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
17
39
  const { output = {
18
40
  path: "hooks",
19
41
  barrelType: "named"
20
- }, group, exclude = [], include, override = [], parser = "client", suspense = {}, infinite = false, transformers = {}, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", generators = [
42
+ }, group, exclude = [], include, override = [], parser = "client", suspense = {}, infinite = false, transformers = {}, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = require_components.MutationKey.getTransformer, queryKey = require_components.QueryKey.getTransformer, customOptions, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
43
+ const clientName = client?.client ?? "axios";
44
+ const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
45
+ const selectedGenerators = options.generators ?? [
21
46
  require_generators.queryGenerator,
22
47
  require_generators.suspenseQueryGenerator,
23
48
  require_generators.infiniteQueryGenerator,
@@ -25,143 +50,106 @@ const pluginReactQuery = (0, _kubb_core.createPlugin)((options) => {
25
50
  require_generators.mutationGenerator,
26
51
  require_generators.hookOptionsGenerator,
27
52
  require_generators.customHookOptionsFileGenerator
28
- ].filter(Boolean), mutation = {}, query = {}, mutationKey = require_components.MutationKey.getTransformer, queryKey = require_components.QueryKey.getTransformer, customOptions, paramsCasing, contentType, client } = options;
29
- const clientName = client?.client ?? "axios";
30
- const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
53
+ ].filter(Boolean);
54
+ const groupConfig = group ? {
55
+ ...group,
56
+ name: group.name ? group.name : (ctx) => {
57
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
58
+ return `${require_components.camelCase(ctx.group)}Controller`;
59
+ }
60
+ } : void 0;
31
61
  return {
32
62
  name: pluginReactQueryName,
33
- options: {
34
- output,
35
- client: {
36
- bundle: client?.bundle,
37
- baseURL: client?.baseURL,
38
- client: clientName,
39
- clientType: client?.clientType ?? "function",
40
- dataReturnType: client?.dataReturnType ?? "data",
63
+ options,
64
+ dependencies: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
65
+ hooks: { "kubb:plugin:setup"(ctx) {
66
+ const resolver = userResolver ? {
67
+ ...resolverReactQuery,
68
+ ...userResolver
69
+ } : resolverReactQuery;
70
+ ctx.setOptions({
71
+ output,
72
+ transformers,
73
+ client: {
74
+ bundle: client?.bundle,
75
+ baseURL: client?.baseURL,
76
+ client: clientName,
77
+ clientType: client?.clientType ?? "function",
78
+ importPath: clientImportPath,
79
+ dataReturnType: client?.dataReturnType ?? "data",
80
+ paramsCasing
81
+ },
82
+ queryKey,
83
+ query: query === false ? false : {
84
+ importPath: "@tanstack/react-query",
85
+ methods: ["get"],
86
+ ...query
87
+ },
88
+ mutationKey,
89
+ mutation: mutation === false ? false : {
90
+ importPath: "@tanstack/react-query",
91
+ methods: [
92
+ "post",
93
+ "put",
94
+ "patch",
95
+ "delete"
96
+ ],
97
+ ...mutation
98
+ },
99
+ infinite: infinite ? {
100
+ queryParam: "id",
101
+ initialPageParam: 0,
102
+ cursorParam: void 0,
103
+ nextParam: void 0,
104
+ previousParam: void 0,
105
+ ...infinite
106
+ } : false,
107
+ suspense,
108
+ customOptions: customOptions ? {
109
+ name: "useCustomHookOptions",
110
+ ...customOptions
111
+ } : void 0,
112
+ parser,
113
+ paramsType,
41
114
  pathParamsType,
42
- importPath: clientImportPath,
43
- paramsCasing
44
- },
45
- infinite: infinite ? {
46
- queryParam: "id",
47
- initialPageParam: 0,
48
- cursorParam: void 0,
49
- nextParam: void 0,
50
- previousParam: void 0,
51
- ...infinite
52
- } : false,
53
- suspense,
54
- queryKey,
55
- query: query === false ? false : {
56
- methods: ["get"],
57
- importPath: "@tanstack/react-query",
58
- ...query
59
- },
60
- mutationKey,
61
- mutation: mutation === false ? false : {
62
- methods: [
63
- "post",
64
- "put",
65
- "patch",
66
- "delete"
67
- ],
68
- importPath: "@tanstack/react-query",
69
- ...mutation
70
- },
71
- customOptions: customOptions ? {
72
- name: "useCustomHookOptions",
73
- ...customOptions
74
- } : void 0,
75
- paramsType,
76
- pathParamsType,
77
- parser,
78
- paramsCasing,
79
- group
80
- },
81
- pre: [
82
- _kubb_plugin_oas.pluginOasName,
83
- _kubb_plugin_ts.pluginTsName,
84
- parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0
85
- ].filter(Boolean),
86
- resolvePath(baseName, pathMode, options) {
87
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
88
- if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
89
- /**
90
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
91
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
92
- */
93
- return node_path.default.resolve(root, output.path);
94
- if (group && (options?.group?.path || options?.group?.tag)) {
95
- const groupName = group?.name ? group.name : (ctx) => {
96
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
97
- return `${require_components.camelCase(ctx.group)}Controller`;
98
- };
99
- return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
100
- }
101
- return node_path.default.resolve(root, output.path, baseName);
102
- },
103
- resolveName(name, type) {
104
- let resolvedName = require_components.camelCase(name);
105
- if (type === "file" || type === "function") resolvedName = require_components.camelCase(name, { isFile: type === "file" });
106
- if (type === "type") resolvedName = require_components.pascalCase(name);
107
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
108
- return resolvedName;
109
- },
110
- async install() {
111
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
112
- const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
113
- const oas = await this.getOas();
114
- const baseURL = await this.getBaseURL();
115
- if (baseURL) this.plugin.options.client.baseURL = baseURL;
116
- const hasClientPlugin = !!this.driver.getPluginByName(_kubb_plugin_client.pluginClientName);
117
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
115
+ paramsCasing,
116
+ group: groupConfig,
117
+ exclude,
118
+ include,
119
+ override,
120
+ resolver
121
+ });
122
+ ctx.setResolver(resolver);
123
+ if (userTransformer) ctx.setTransformer(userTransformer);
124
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
125
+ for (const gen of userGenerators) ctx.addGenerator(gen);
126
+ const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
127
+ const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === _kubb_plugin_client.pluginClientName);
128
+ if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
118
129
  baseName: "fetch.ts",
119
130
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
120
- sources: [{
131
+ sources: [_kubb_core.ast.createSource({
121
132
  name: "fetch",
122
- value: this.plugin.options.client.client === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source,
133
+ nodes: [_kubb_core.ast.createText(clientName === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source)],
123
134
  isExportable: true,
124
135
  isIndexable: true
125
- }],
126
- imports: [],
127
- exports: []
136
+ })]
128
137
  });
129
- if (!hasClientPlugin) await this.upsertFile({
138
+ if (!hasClientPlugin) ctx.injectFile({
130
139
  baseName: "config.ts",
131
140
  path: node_path.default.resolve(root, ".kubb/config.ts"),
132
- sources: [{
141
+ sources: [_kubb_core.ast.createSource({
133
142
  name: "config",
134
- value: _kubb_plugin_client_templates_config_source.source,
143
+ nodes: [_kubb_core.ast.createText(_kubb_plugin_client_templates_config_source.source)],
135
144
  isExportable: false,
136
145
  isIndexable: false
137
- }],
138
- imports: [],
139
- exports: []
146
+ })]
140
147
  });
141
- const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
142
- fabric: this.fabric,
143
- oas,
144
- driver: this.driver,
145
- events: this.events,
146
- plugin: this.plugin,
147
- contentType,
148
- exclude,
149
- include,
150
- override,
151
- mode
152
- }).build(...generators);
153
- await this.upsertFile(...files);
154
- const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
155
- type: output.barrelType ?? "named",
156
- root,
157
- output,
158
- meta: { pluginName: this.plugin.name }
159
- });
160
- await this.upsertFile(...barrelFiles);
161
- }
148
+ } }
162
149
  };
163
150
  });
164
151
  //#endregion
152
+ exports.default = pluginReactQuery;
165
153
  exports.pluginReactQuery = pluginReactQuery;
166
154
  exports.pluginReactQueryName = pluginReactQueryName;
167
155
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","path","camelCase","pascalCase","pluginClientName","fetchClientSource","axiosClientSource","configSource","OperationGenerator"],"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,oBAAA,GAAA,WAAA,eAAmD,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;EACXA,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA;EACAC,mBAAAA;EACD,CAAC,OAAO,QAAQ,EACjB,WAAW,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,OAAO,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAUI,mDAAAA,SAAoBC,mDAAAA;KAC3E,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAML,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAOM,4CAAAA;KACP,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,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,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["camelCase","MutationKey","QueryKey","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","suspenseInfiniteQueryGenerator","mutationGenerator","hookOptionsGenerator","customHookOptionsFileGenerator","camelCase","pluginTsName","pluginZodName","path","pluginClientName","ast","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,sBAAA,GAAA,WAAA,iBAAuD,SAAS;CAC3E,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;AAClB,SAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;AAChB,SAAO,IAAI,QAAQ,MAAM,WAAW;;CAEvC,EAAE;;;ACEH,MAAa,uBAAuB;AAEpC,MAAa,oBAAA,GAAA,WAAA,eAAmD,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,WAAW,EAAE,EACb,QAAQ,EAAE,EACV,cAAcC,mBAAAA,YAAY,gBAC1B,WAAWC,mBAAAA,SAAS,gBACpB,eACA,cACA,QACA,UAAU,cACV,aAAa,iBACb,YAAY,iBAAiB,EAAE,KAC7B;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,M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ACP;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,OAAOC,UAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,kBAAkB,CAAC,CAAC,IAAI,OAAO,SAAS,MAAM,MAAO,EAAwB,SAASC,oBAAAA,iBAAiB;AAE7G,OAAI,QAAQ,UAAU,CAAC,mBAAmB,CAAC,iBACzC,KAAI,WAAW;IACb,UAAU;IACV,MAAMD,UAAAA,QAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,eAAe,UAAUC,mDAAAA,SAAoBC,mDAAAA,OAAkB,CAAC;KACvF,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;AAGJ,OAAI,CAAC,gBACH,KAAI,WAAW;IACb,UAAU;IACV,MAAMJ,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAWG,4CAAAA,OAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as Options, r as PluginReactQuery } from "./types-D5S7Ny9r.js";
3
- import * as _kubb_core0 from "@kubb/core";
2
+ import { n as Options, r as PluginReactQuery } from "./types-DfaFRSBf.js";
3
+ import * as _$_kubb_core0 from "@kubb/core";
4
4
 
5
5
  //#region src/plugin.d.ts
6
6
  declare const pluginReactQueryName = "plugin-react-query";
7
- declare const pluginReactQuery: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginReactQuery>;
7
+ declare const pluginReactQuery: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginReactQuery>;
8
8
  //#endregion
9
- export { type PluginReactQuery, pluginReactQuery, pluginReactQueryName };
9
+ export { type PluginReactQuery, pluginReactQuery as default, pluginReactQuery, pluginReactQueryName };
10
10
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,22 +1,44 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { d as MutationKey, f as camelCase, p as pascalCase, u as QueryKey } from "./components-CpyHYGOw.js";
3
- import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-DkQwKTc2.js";
2
+ import { f as QueryKey, m as camelCase, p as MutationKey } from "./components-DTGLu4UV.js";
3
+ import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-C_fbcjpG.js";
4
4
  import path from "node:path";
5
- import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
5
+ import { ast, definePlugin, defineResolver } from "@kubb/core";
6
6
  import { pluginClientName } from "@kubb/plugin-client";
7
7
  import { source } from "@kubb/plugin-client/templates/clients/axios.source";
8
8
  import { source as source$1 } from "@kubb/plugin-client/templates/clients/fetch.source";
9
9
  import { source as source$2 } from "@kubb/plugin-client/templates/config.source";
10
- import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
11
10
  import { pluginTsName } from "@kubb/plugin-ts";
12
11
  import { pluginZodName } from "@kubb/plugin-zod";
12
+ //#region src/resolvers/resolverReactQuery.ts
13
+ /**
14
+ * Naming convention resolver for React Query plugin.
15
+ *
16
+ * Provides default naming helpers using camelCase for functions and file paths.
17
+ *
18
+ * @example
19
+ * `resolverReactQuery.default('list pets', 'function') // → 'listPets'`
20
+ */
21
+ const resolverReactQuery = defineResolver((ctx) => ({
22
+ name: "default",
23
+ pluginName: "plugin-react-query",
24
+ default(name, type) {
25
+ return camelCase(name, { isFile: type === "file" });
26
+ },
27
+ resolveName(name) {
28
+ return ctx.default(name, "function");
29
+ }
30
+ }));
31
+ //#endregion
13
32
  //#region src/plugin.ts
14
33
  const pluginReactQueryName = "plugin-react-query";
15
- const pluginReactQuery = createPlugin((options) => {
34
+ const pluginReactQuery = definePlugin((options) => {
16
35
  const { output = {
17
36
  path: "hooks",
18
37
  barrelType: "named"
19
- }, group, exclude = [], include, override = [], parser = "client", suspense = {}, infinite = false, transformers = {}, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", generators = [
38
+ }, group, exclude = [], include, override = [], parser = "client", suspense = {}, infinite = false, transformers = {}, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = MutationKey.getTransformer, queryKey = QueryKey.getTransformer, customOptions, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
39
+ const clientName = client?.client ?? "axios";
40
+ const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
41
+ const selectedGenerators = options.generators ?? [
20
42
  queryGenerator,
21
43
  suspenseQueryGenerator,
22
44
  infiniteQueryGenerator,
@@ -24,143 +46,105 @@ const pluginReactQuery = createPlugin((options) => {
24
46
  mutationGenerator,
25
47
  hookOptionsGenerator,
26
48
  customHookOptionsFileGenerator
27
- ].filter(Boolean), mutation = {}, query = {}, mutationKey = MutationKey.getTransformer, queryKey = QueryKey.getTransformer, customOptions, paramsCasing, contentType, client } = options;
28
- const clientName = client?.client ?? "axios";
29
- const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
49
+ ].filter(Boolean);
50
+ const groupConfig = group ? {
51
+ ...group,
52
+ name: group.name ? group.name : (ctx) => {
53
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
54
+ return `${camelCase(ctx.group)}Controller`;
55
+ }
56
+ } : void 0;
30
57
  return {
31
58
  name: pluginReactQueryName,
32
- options: {
33
- output,
34
- client: {
35
- bundle: client?.bundle,
36
- baseURL: client?.baseURL,
37
- client: clientName,
38
- clientType: client?.clientType ?? "function",
39
- dataReturnType: client?.dataReturnType ?? "data",
59
+ options,
60
+ dependencies: [pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
61
+ hooks: { "kubb:plugin:setup"(ctx) {
62
+ const resolver = userResolver ? {
63
+ ...resolverReactQuery,
64
+ ...userResolver
65
+ } : resolverReactQuery;
66
+ ctx.setOptions({
67
+ output,
68
+ transformers,
69
+ client: {
70
+ bundle: client?.bundle,
71
+ baseURL: client?.baseURL,
72
+ client: clientName,
73
+ clientType: client?.clientType ?? "function",
74
+ importPath: clientImportPath,
75
+ dataReturnType: client?.dataReturnType ?? "data",
76
+ paramsCasing
77
+ },
78
+ queryKey,
79
+ query: query === false ? false : {
80
+ importPath: "@tanstack/react-query",
81
+ methods: ["get"],
82
+ ...query
83
+ },
84
+ mutationKey,
85
+ mutation: mutation === false ? false : {
86
+ importPath: "@tanstack/react-query",
87
+ methods: [
88
+ "post",
89
+ "put",
90
+ "patch",
91
+ "delete"
92
+ ],
93
+ ...mutation
94
+ },
95
+ infinite: infinite ? {
96
+ queryParam: "id",
97
+ initialPageParam: 0,
98
+ cursorParam: void 0,
99
+ nextParam: void 0,
100
+ previousParam: void 0,
101
+ ...infinite
102
+ } : false,
103
+ suspense,
104
+ customOptions: customOptions ? {
105
+ name: "useCustomHookOptions",
106
+ ...customOptions
107
+ } : void 0,
108
+ parser,
109
+ paramsType,
40
110
  pathParamsType,
41
- importPath: clientImportPath,
42
- paramsCasing
43
- },
44
- infinite: infinite ? {
45
- queryParam: "id",
46
- initialPageParam: 0,
47
- cursorParam: void 0,
48
- nextParam: void 0,
49
- previousParam: void 0,
50
- ...infinite
51
- } : false,
52
- suspense,
53
- queryKey,
54
- query: query === false ? false : {
55
- methods: ["get"],
56
- importPath: "@tanstack/react-query",
57
- ...query
58
- },
59
- mutationKey,
60
- mutation: mutation === false ? false : {
61
- methods: [
62
- "post",
63
- "put",
64
- "patch",
65
- "delete"
66
- ],
67
- importPath: "@tanstack/react-query",
68
- ...mutation
69
- },
70
- customOptions: customOptions ? {
71
- name: "useCustomHookOptions",
72
- ...customOptions
73
- } : void 0,
74
- paramsType,
75
- pathParamsType,
76
- parser,
77
- paramsCasing,
78
- group
79
- },
80
- pre: [
81
- pluginOasName,
82
- pluginTsName,
83
- parser === "zod" ? pluginZodName : void 0
84
- ].filter(Boolean),
85
- resolvePath(baseName, pathMode, options) {
86
- const root = path.resolve(this.config.root, this.config.output.path);
87
- if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
88
- /**
89
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
90
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
91
- */
92
- return path.resolve(root, output.path);
93
- if (group && (options?.group?.path || options?.group?.tag)) {
94
- const groupName = group?.name ? group.name : (ctx) => {
95
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
96
- return `${camelCase(ctx.group)}Controller`;
97
- };
98
- return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
99
- }
100
- return path.resolve(root, output.path, baseName);
101
- },
102
- resolveName(name, type) {
103
- let resolvedName = camelCase(name);
104
- if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
105
- if (type === "type") resolvedName = pascalCase(name);
106
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
107
- return resolvedName;
108
- },
109
- async install() {
110
- const root = path.resolve(this.config.root, this.config.output.path);
111
- const mode = getMode(path.resolve(root, output.path));
112
- const oas = await this.getOas();
113
- const baseURL = await this.getBaseURL();
114
- if (baseURL) this.plugin.options.client.baseURL = baseURL;
115
- const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName);
116
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
111
+ paramsCasing,
112
+ group: groupConfig,
113
+ exclude,
114
+ include,
115
+ override,
116
+ resolver
117
+ });
118
+ ctx.setResolver(resolver);
119
+ if (userTransformer) ctx.setTransformer(userTransformer);
120
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
121
+ for (const gen of userGenerators) ctx.addGenerator(gen);
122
+ const root = path.resolve(ctx.config.root, ctx.config.output.path);
123
+ const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === pluginClientName);
124
+ if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
117
125
  baseName: "fetch.ts",
118
126
  path: path.resolve(root, ".kubb/fetch.ts"),
119
- sources: [{
127
+ sources: [ast.createSource({
120
128
  name: "fetch",
121
- value: this.plugin.options.client.client === "fetch" ? source$1 : source,
129
+ nodes: [ast.createText(clientName === "fetch" ? source$1 : source)],
122
130
  isExportable: true,
123
131
  isIndexable: true
124
- }],
125
- imports: [],
126
- exports: []
132
+ })]
127
133
  });
128
- if (!hasClientPlugin) await this.upsertFile({
134
+ if (!hasClientPlugin) ctx.injectFile({
129
135
  baseName: "config.ts",
130
136
  path: path.resolve(root, ".kubb/config.ts"),
131
- sources: [{
137
+ sources: [ast.createSource({
132
138
  name: "config",
133
- value: source$2,
139
+ nodes: [ast.createText(source$2)],
134
140
  isExportable: false,
135
141
  isIndexable: false
136
- }],
137
- imports: [],
138
- exports: []
139
- });
140
- const files = await new OperationGenerator(this.plugin.options, {
141
- fabric: this.fabric,
142
- oas,
143
- driver: this.driver,
144
- events: this.events,
145
- plugin: this.plugin,
146
- contentType,
147
- exclude,
148
- include,
149
- override,
150
- mode
151
- }).build(...generators);
152
- await this.upsertFile(...files);
153
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
154
- type: output.barrelType ?? "named",
155
- root,
156
- output,
157
- meta: { pluginName: this.plugin.name }
142
+ })]
158
143
  });
159
- await this.upsertFile(...barrelFiles);
160
- }
144
+ } }
161
145
  };
162
146
  });
163
147
  //#endregion
164
- export { pluginReactQuery, pluginReactQueryName };
148
+ export { pluginReactQuery as default, pluginReactQuery, pluginReactQueryName };
165
149
 
166
150
  //# sourceMappingURL=index.js.map