@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/chunk-37VO6QXJ.cjs +669 -0
- package/dist/chunk-37VO6QXJ.cjs.map +1 -0
- package/dist/chunk-C2H3KPHM.cjs +658 -0
- package/dist/chunk-C2H3KPHM.cjs.map +1 -0
- package/dist/chunk-IRW2Y3EC.js +660 -0
- package/dist/chunk-IRW2Y3EC.js.map +1 -0
- package/dist/chunk-Y3DM2P6L.js +647 -0
- package/dist/chunk-Y3DM2P6L.js.map +1 -0
- package/dist/components.cjs +39 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +161 -6
- package/dist/components.d.ts +161 -6
- package/dist/components.js +2 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +25 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +14 -0
- package/dist/generators.d.ts +14 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +78 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +61 -120
- package/dist/index.js.map +1 -1
- package/dist/types-5pnOmDmM.d.cts +231 -0
- package/dist/types-5pnOmDmM.d.ts +231 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +130 -0
- package/src/components/Mutation.tsx +137 -321
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +91 -594
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +71 -473
- package/src/components/SuspenseQuery.tsx +129 -0
- package/src/components/index.ts +4 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
- package/src/generators/__snapshots__/findByTags.ts +51 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +44 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +124 -0
- package/src/generators/mutationGenerator.tsx +108 -0
- package/src/generators/queryGenerator.tsx +121 -0
- package/src/generators/suspenseQueryGenerator.tsx +120 -0
- package/src/plugin.ts +60 -76
- package/src/types.ts +42 -115
- package/dist/chunk-7ZODZVKP.cjs +0 -1470
- package/dist/chunk-7ZODZVKP.cjs.map +0 -1
- package/dist/chunk-ZYTZV43V.js +0 -1470
- package/dist/chunk-ZYTZV43V.js.map +0 -1
- package/dist/index-5kpkk-7M.d.cts +0 -545
- package/dist/index-5kpkk-7M.d.ts +0 -545
- package/src/OperationGenerator.tsx +0 -57
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -59
- package/src/components/__snapshots__/gen/showPetById.ts +0 -67
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
- package/src/utils.ts +0 -96
package/dist/index.cjs
CHANGED
|
@@ -1,95 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk37VO6QXJ_cjs = require('./chunk-37VO6QXJ.cjs');
|
|
4
|
+
require('./chunk-C2H3KPHM.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers = require('@kubb/core/transformers');
|
|
8
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
9
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
10
|
+
var pluginZod = require('@kubb/plugin-zod');
|
|
3
11
|
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
4
13
|
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
5
15
|
|
|
6
|
-
|
|
7
|
-
var _chunk7ZODZVKPcjs = require('./chunk-7ZODZVKP.cjs');
|
|
8
|
-
|
|
9
|
-
// src/plugin.ts
|
|
10
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
11
|
-
var _core = require('@kubb/core');
|
|
12
|
-
var _transformers = require('@kubb/core/transformers');
|
|
13
|
-
var _utils = require('@kubb/core/utils');
|
|
14
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
15
|
-
var _plugints = require('@kubb/plugin-ts');
|
|
16
|
-
var _pluginzod = require('@kubb/plugin-zod');
|
|
17
|
-
|
|
18
|
-
// src/OperationGenerator.tsx
|
|
19
|
-
|
|
20
|
-
var _components = require('@kubb/plugin-oas/components');
|
|
21
|
-
var _react = require('@kubb/react');
|
|
22
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
23
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
24
|
-
async operation(operation, options) {
|
|
25
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
26
|
-
const root = _react.createRoot.call(void 0, {
|
|
27
|
-
logger: pluginManager.logger
|
|
28
|
-
});
|
|
29
|
-
const templates = {
|
|
30
|
-
mutation: _chunk7ZODZVKPcjs.Mutation.templates,
|
|
31
|
-
query: _chunk7ZODZVKPcjs.Query.templates,
|
|
32
|
-
queryOptions: _chunk7ZODZVKPcjs.QueryOptions.templates,
|
|
33
|
-
queryKey: _chunk7ZODZVKPcjs.QueryKey.templates,
|
|
34
|
-
queryImports: _chunk7ZODZVKPcjs.QueryImports.templates,
|
|
35
|
-
...options.templates
|
|
36
|
-
};
|
|
37
|
-
const isQuery = typeof options.query === "boolean" ? true : _optionalChain([options, 'access', _ => _.query, 'optionalAccess', _2 => _2.methods, 'access', _3 => _3.some, 'call', _4 => _4((method) => operation.method === method)]);
|
|
38
|
-
const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
|
|
39
|
-
root.render(
|
|
40
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Operation, { operation, children: [
|
|
41
|
-
isMutate && _optionalChain([templates, 'optionalAccess', _5 => _5.mutation]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk7ZODZVKPcjs.Mutation.File, { templates: templates.mutation }),
|
|
42
|
-
isQuery && _optionalChain([templates, 'optionalAccess', _6 => _6.query]) && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
43
|
-
_chunk7ZODZVKPcjs.Query.File,
|
|
44
|
-
{
|
|
45
|
-
templates: {
|
|
46
|
-
query: templates.query,
|
|
47
|
-
queryKey: templates.queryKey,
|
|
48
|
-
queryOptions: templates.queryOptions,
|
|
49
|
-
queryImports: templates.queryImports
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
] }) }) })
|
|
54
|
-
);
|
|
55
|
-
return root.files;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/plugin.ts
|
|
60
16
|
var pluginReactQueryName = "plugin-react-query";
|
|
61
|
-
var pluginReactQuery =
|
|
17
|
+
var pluginReactQuery = core.createPlugin((options) => {
|
|
62
18
|
const {
|
|
63
|
-
output = { path: "hooks" },
|
|
19
|
+
output = { path: "hooks", barrelType: "named" },
|
|
64
20
|
group,
|
|
65
21
|
exclude = [],
|
|
66
22
|
include,
|
|
67
23
|
override = [],
|
|
68
|
-
parser,
|
|
24
|
+
parser = "client",
|
|
69
25
|
suspense = {},
|
|
70
|
-
infinite,
|
|
71
|
-
transformers = {},
|
|
72
|
-
dataReturnType = "data",
|
|
26
|
+
infinite = false,
|
|
27
|
+
transformers: transformers$1 = {},
|
|
73
28
|
pathParamsType = "inline",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
templates
|
|
29
|
+
generators = [chunk37VO6QXJ_cjs.queryGenerator, chunk37VO6QXJ_cjs.suspenseQueryGenerator, chunk37VO6QXJ_cjs.infiniteQueryGenerator, chunk37VO6QXJ_cjs.mutationGenerator].filter(Boolean),
|
|
30
|
+
mutation = {},
|
|
31
|
+
query = {}
|
|
78
32
|
} = options;
|
|
79
|
-
const template = _optionalChain([group, 'optionalAccess', _7 => _7.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
80
33
|
return {
|
|
81
34
|
name: pluginReactQueryName,
|
|
82
|
-
output: {
|
|
83
|
-
exportType: "barrelNamed",
|
|
84
|
-
...output
|
|
85
|
-
},
|
|
86
35
|
options: {
|
|
36
|
+
output,
|
|
37
|
+
baseURL: void 0,
|
|
87
38
|
client: {
|
|
88
39
|
importPath: "@kubb/plugin-client/client",
|
|
40
|
+
dataReturnType: "data",
|
|
89
41
|
...options.client
|
|
90
42
|
},
|
|
91
|
-
dataReturnType,
|
|
92
|
-
pathParamsType,
|
|
93
43
|
infinite: infinite ? {
|
|
94
44
|
queryParam: "id",
|
|
95
45
|
initialPageParam: 0,
|
|
@@ -97,91 +47,89 @@ var pluginReactQuery = _core.createPlugin.call(void 0, (options) => {
|
|
|
97
47
|
...infinite
|
|
98
48
|
} : false,
|
|
99
49
|
suspense,
|
|
100
|
-
query:
|
|
101
|
-
|
|
50
|
+
query: {
|
|
51
|
+
key: (key) => key,
|
|
102
52
|
methods: ["get"],
|
|
103
53
|
importPath: "@tanstack/react-query",
|
|
104
54
|
...query
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
variablesType: "hook",
|
|
55
|
+
},
|
|
56
|
+
mutation: {
|
|
57
|
+
key: (key) => key,
|
|
109
58
|
methods: ["post", "put", "patch", "delete"],
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
templates: {
|
|
113
|
-
mutation: _chunk7ZODZVKPcjs.Mutation.templates,
|
|
114
|
-
query: _chunk7ZODZVKPcjs.Query.templates,
|
|
115
|
-
queryOptions: _chunk7ZODZVKPcjs.QueryOptions.templates,
|
|
116
|
-
queryKey: _chunk7ZODZVKPcjs.QueryKey.templates,
|
|
117
|
-
queryImports: _chunk7ZODZVKPcjs.QueryImports.templates,
|
|
118
|
-
...templates
|
|
59
|
+
importPath: "@tanstack/react-query",
|
|
60
|
+
...mutation
|
|
119
61
|
},
|
|
62
|
+
pathParamsType,
|
|
120
63
|
parser
|
|
121
64
|
},
|
|
122
|
-
pre: [
|
|
65
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
|
|
123
66
|
resolvePath(baseName, pathMode, options2) {
|
|
124
|
-
const root =
|
|
125
|
-
const mode =
|
|
126
|
-
if (
|
|
127
|
-
|
|
67
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
68
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
69
|
+
if (options2?.tag && group?.type === "tag") {
|
|
70
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
71
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
128
72
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
73
|
+
if (mode === "single") {
|
|
74
|
+
return path__default.default.resolve(root, output.path);
|
|
132
75
|
}
|
|
133
|
-
return
|
|
76
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
134
77
|
},
|
|
135
78
|
resolveName(name, type) {
|
|
136
|
-
let resolvedName =
|
|
79
|
+
let resolvedName = transformers.camelCase(name);
|
|
137
80
|
if (type === "file" || type === "function") {
|
|
138
|
-
resolvedName =
|
|
139
|
-
prefix: "use",
|
|
81
|
+
resolvedName = transformers.camelCase(name, {
|
|
140
82
|
isFile: type === "file"
|
|
141
83
|
});
|
|
142
84
|
}
|
|
143
85
|
if (type === "type") {
|
|
144
|
-
resolvedName =
|
|
86
|
+
resolvedName = transformers.pascalCase(name);
|
|
145
87
|
}
|
|
146
88
|
if (type) {
|
|
147
|
-
return
|
|
89
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
148
90
|
}
|
|
149
91
|
return resolvedName;
|
|
150
92
|
},
|
|
151
93
|
async buildStart() {
|
|
152
|
-
const [swaggerPlugin] =
|
|
94
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
153
95
|
const oas = await swaggerPlugin.context.getOas();
|
|
154
|
-
const root =
|
|
155
|
-
const mode =
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
96
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
97
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
98
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
99
|
+
const operationGenerator = new pluginOas.OperationGenerator(
|
|
100
|
+
{
|
|
101
|
+
...this.plugin.options,
|
|
102
|
+
baseURL
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
oas,
|
|
106
|
+
pluginManager: this.pluginManager,
|
|
107
|
+
plugin: this.plugin,
|
|
108
|
+
contentType: swaggerPlugin.context.contentType,
|
|
109
|
+
exclude,
|
|
110
|
+
include,
|
|
111
|
+
override,
|
|
112
|
+
mode
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
const files = await operationGenerator.build(...generators);
|
|
167
116
|
await this.addFile(...files);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
117
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
118
|
+
type: output.barrelType ?? "named",
|
|
119
|
+
root,
|
|
120
|
+
output,
|
|
121
|
+
files: this.fileManager.files,
|
|
122
|
+
meta: {
|
|
123
|
+
pluginKey: this.plugin.key
|
|
124
|
+
},
|
|
125
|
+
logger: this.logger
|
|
126
|
+
});
|
|
127
|
+
await this.addFile(...barrelFiles);
|
|
180
128
|
}
|
|
181
129
|
};
|
|
182
130
|
});
|
|
183
131
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
132
|
+
exports.pluginReactQuery = pluginReactQuery;
|
|
133
|
+
exports.pluginReactQueryName = pluginReactQueryName;
|
|
134
|
+
//# sourceMappingURL=index.cjs.map
|
|
187
135
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-react-query/dist/index.cjs","../src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U,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AACmB,IAAA;AAC0C,MAAA;AAEnB,MAAA;AACI,MAAA;AACN,MAAA;AAEP,MAAA;AAC7B,QAAA;AACoB,QAAA;AACP,QAAA;AACsB,QAAA;AACnC,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACD,MAAA;AAE4C,MAAA;AAClB,MAAA;AAEQ,MAAA;AACU,QAAA;AACzC,UAAA;AACA,UAAA;AACwB,UAAA;AAClB,UAAA;AACmB,YAAA;AACzB,UAAA;AACa,UAAA;AACd,QAAA;AAEgC,QAAA;AACnC,MAAA;AACF,IAAA;AACF,EAAA;AACD;ADkBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-react-query/dist/index.cjs","sourcesContent":[null,"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'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, 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 output: {\n exportType: 'barrelNamed',\n ...output,\n },\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 ...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 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","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 { 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 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"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAcO,IAAM,oBAAuB,GAAA,qBAAA;AAEvB,IAAA,gBAAA,GAAmBA,iBAA+B,CAAA,CAAC,OAAY,KAAA;AAC1E,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,IACT,WAAW,EAAC;AAAA,IACZ,QAAW,GAAA,KAAA;AAAA,kBACXC,iBAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,QAAA;AAAA,IACjB,UAAA,GAAa,CAACC,gCAAgB,EAAAC,wCAAA,EAAwBC,0CAAwBC,mCAAiB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IAC/G,WAAW,EAAC;AAAA,IACZ,QAAQ,EAAC;AAAA,GACP,GAAA,OAAA,CAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,oBAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,OAAS,EAAA,KAAA,CAAA;AAAA,MACT,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,4BAAA;AAAA,QACZ,cAAgB,EAAA,MAAA;AAAA,QAChB,GAAG,OAAQ,C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AAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA,MAAA;AAAA,OACd,CAAA,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,KACnC;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\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', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n pathParamsType = 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\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 key: (key: unknown[]) => key,\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import { O as Options, P as PluginReactQuery } from './
|
|
3
|
-
import '@kubb/core/utils';
|
|
2
|
+
import { O as Options, P as PluginReactQuery } from './types-5pnOmDmM.cjs';
|
|
4
3
|
import '@kubb/oas';
|
|
5
|
-
import 'react';
|
|
6
|
-
import '@kubb/fs/types';
|
|
7
4
|
import '@kubb/plugin-oas';
|
|
8
5
|
|
|
9
6
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import { O as Options, P as PluginReactQuery } from './
|
|
3
|
-
import '@kubb/core/utils';
|
|
2
|
+
import { O as Options, P as PluginReactQuery } from './types-5pnOmDmM.js';
|
|
4
3
|
import '@kubb/oas';
|
|
5
|
-
import 'react';
|
|
6
|
-
import '@kubb/fs/types';
|
|
7
4
|
import '@kubb/plugin-oas';
|
|
8
5
|
|
|
9
6
|
declare const pluginReactQueryName = "plugin-react-query";
|
package/dist/index.js
CHANGED
|
@@ -1,95 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
1
|
+
import { queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator } from './chunk-IRW2Y3EC.js';
|
|
2
|
+
import './chunk-Y3DM2P6L.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
|
+
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
+
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
8
|
+
import { pluginZodName } from '@kubb/plugin-zod';
|
|
8
9
|
|
|
9
|
-
// src/plugin.ts
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
12
|
-
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
13
|
-
import { renderTemplate } from "@kubb/core/utils";
|
|
14
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
15
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
16
|
-
import { pluginZodName } from "@kubb/plugin-zod";
|
|
17
|
-
|
|
18
|
-
// src/OperationGenerator.tsx
|
|
19
|
-
import { OperationGenerator as Generator } from "@kubb/plugin-oas";
|
|
20
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
21
|
-
import { App, createRoot } from "@kubb/react";
|
|
22
|
-
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
23
|
-
var OperationGenerator = class extends Generator {
|
|
24
|
-
async operation(operation, options) {
|
|
25
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
26
|
-
const root = createRoot({
|
|
27
|
-
logger: pluginManager.logger
|
|
28
|
-
});
|
|
29
|
-
const templates = {
|
|
30
|
-
mutation: Mutation.templates,
|
|
31
|
-
query: Query.templates,
|
|
32
|
-
queryOptions: QueryOptions.templates,
|
|
33
|
-
queryKey: QueryKey.templates,
|
|
34
|
-
queryImports: QueryImports.templates,
|
|
35
|
-
...options.templates
|
|
36
|
-
};
|
|
37
|
-
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
38
|
-
const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
|
|
39
|
-
root.render(
|
|
40
|
-
/* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxs(Oas.Operation, { operation, children: [
|
|
41
|
-
isMutate && templates?.mutation && /* @__PURE__ */ jsx(Mutation.File, { templates: templates.mutation }),
|
|
42
|
-
isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ jsx(
|
|
43
|
-
Query.File,
|
|
44
|
-
{
|
|
45
|
-
templates: {
|
|
46
|
-
query: templates.query,
|
|
47
|
-
queryKey: templates.queryKey,
|
|
48
|
-
queryOptions: templates.queryOptions,
|
|
49
|
-
queryImports: templates.queryImports
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
] }) }) })
|
|
54
|
-
);
|
|
55
|
-
return root.files;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/plugin.ts
|
|
60
10
|
var pluginReactQueryName = "plugin-react-query";
|
|
61
11
|
var pluginReactQuery = createPlugin((options) => {
|
|
62
12
|
const {
|
|
63
|
-
output = { path: "hooks" },
|
|
13
|
+
output = { path: "hooks", barrelType: "named" },
|
|
64
14
|
group,
|
|
65
15
|
exclude = [],
|
|
66
16
|
include,
|
|
67
17
|
override = [],
|
|
68
|
-
parser,
|
|
18
|
+
parser = "client",
|
|
69
19
|
suspense = {},
|
|
70
|
-
infinite,
|
|
20
|
+
infinite = false,
|
|
71
21
|
transformers = {},
|
|
72
|
-
dataReturnType = "data",
|
|
73
22
|
pathParamsType = "inline",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
templates
|
|
23
|
+
generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
|
|
24
|
+
mutation = {},
|
|
25
|
+
query = {}
|
|
78
26
|
} = options;
|
|
79
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
80
27
|
return {
|
|
81
28
|
name: pluginReactQueryName,
|
|
82
|
-
output: {
|
|
83
|
-
exportType: "barrelNamed",
|
|
84
|
-
...output
|
|
85
|
-
},
|
|
86
29
|
options: {
|
|
30
|
+
output,
|
|
31
|
+
baseURL: void 0,
|
|
87
32
|
client: {
|
|
88
33
|
importPath: "@kubb/plugin-client/client",
|
|
34
|
+
dataReturnType: "data",
|
|
89
35
|
...options.client
|
|
90
36
|
},
|
|
91
|
-
dataReturnType,
|
|
92
|
-
pathParamsType,
|
|
93
37
|
infinite: infinite ? {
|
|
94
38
|
queryParam: "id",
|
|
95
39
|
initialPageParam: 0,
|
|
@@ -97,46 +41,38 @@ var pluginReactQuery = createPlugin((options) => {
|
|
|
97
41
|
...infinite
|
|
98
42
|
} : false,
|
|
99
43
|
suspense,
|
|
100
|
-
query:
|
|
101
|
-
|
|
44
|
+
query: {
|
|
45
|
+
key: (key) => key,
|
|
102
46
|
methods: ["get"],
|
|
103
47
|
importPath: "@tanstack/react-query",
|
|
104
48
|
...query
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
variablesType: "hook",
|
|
49
|
+
},
|
|
50
|
+
mutation: {
|
|
51
|
+
key: (key) => key,
|
|
109
52
|
methods: ["post", "put", "patch", "delete"],
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
templates: {
|
|
113
|
-
mutation: Mutation.templates,
|
|
114
|
-
query: Query.templates,
|
|
115
|
-
queryOptions: QueryOptions.templates,
|
|
116
|
-
queryKey: QueryKey.templates,
|
|
117
|
-
queryImports: QueryImports.templates,
|
|
118
|
-
...templates
|
|
53
|
+
importPath: "@tanstack/react-query",
|
|
54
|
+
...mutation
|
|
119
55
|
},
|
|
56
|
+
pathParamsType,
|
|
120
57
|
parser
|
|
121
58
|
},
|
|
122
59
|
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
123
60
|
resolvePath(baseName, pathMode, options2) {
|
|
124
61
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
125
62
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
63
|
+
if (options2?.tag && group?.type === "tag") {
|
|
64
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
65
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
66
|
+
}
|
|
126
67
|
if (mode === "single") {
|
|
127
68
|
return path.resolve(root, output.path);
|
|
128
69
|
}
|
|
129
|
-
if (options2?.tag && group?.type === "tag") {
|
|
130
|
-
const tag = camelCase(options2.tag);
|
|
131
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
132
|
-
}
|
|
133
70
|
return path.resolve(root, output.path, baseName);
|
|
134
71
|
},
|
|
135
72
|
resolveName(name, type) {
|
|
136
73
|
let resolvedName = camelCase(name);
|
|
137
74
|
if (type === "file" || type === "function") {
|
|
138
75
|
resolvedName = camelCase(name, {
|
|
139
|
-
prefix: "use",
|
|
140
76
|
isFile: type === "file"
|
|
141
77
|
});
|
|
142
78
|
}
|
|
@@ -153,35 +89,40 @@ var pluginReactQuery = createPlugin((options) => {
|
|
|
153
89
|
const oas = await swaggerPlugin.context.getOas();
|
|
154
90
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
155
91
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
92
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
93
|
+
const operationGenerator = new OperationGenerator(
|
|
94
|
+
{
|
|
95
|
+
...this.plugin.options,
|
|
96
|
+
baseURL
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
oas,
|
|
100
|
+
pluginManager: this.pluginManager,
|
|
101
|
+
plugin: this.plugin,
|
|
102
|
+
contentType: swaggerPlugin.context.contentType,
|
|
103
|
+
exclude,
|
|
104
|
+
include,
|
|
105
|
+
override,
|
|
106
|
+
mode
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
const files = await operationGenerator.build(...generators);
|
|
167
110
|
await this.addFile(...files);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
111
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
112
|
+
type: output.barrelType ?? "named",
|
|
113
|
+
root,
|
|
114
|
+
output,
|
|
115
|
+
files: this.fileManager.files,
|
|
116
|
+
meta: {
|
|
117
|
+
pluginKey: this.plugin.key
|
|
118
|
+
},
|
|
119
|
+
logger: this.logger
|
|
120
|
+
});
|
|
121
|
+
await this.addFile(...barrelFiles);
|
|
180
122
|
}
|
|
181
123
|
};
|
|
182
124
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
125
|
+
|
|
126
|
+
export { pluginReactQuery, pluginReactQueryName };
|
|
127
|
+
//# sourceMappingURL=index.js.map
|
|
187
128
|
//# sourceMappingURL=index.js.map
|
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'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, 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 output: {\n exportType: 'barrelNamed',\n ...output,\n },\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 ...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 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","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 { 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 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;AAE9B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;;;ACR9B,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AAmCtB,SACsC,KADtC;AAvBH,IAAM,qBAAN,cAAiC,UAA2E;AAAA,EACjH,MAAM,UAAU,WAAsB,SAA+E;AACnH,UAAM,EAAE,KAAK,eAAe,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;AAAA,MACb,cAAc,aAAa;AAAA,MAC3B,UAAU,SAAS;AAAA,MACnB,cAAc,aAAa;AAAA,MAC3B,GAAG,QAAQ;AAAA,IACb;AAEA,UAAM,UAAU,OAAO,QAAQ,UAAU,YAAY,OAAO,QAAQ,OAAO,QAAQ,KAAK,CAAC,WAAW,UAAU,WAAW,MAAM;AAC/H,UAAM,WAAW,CAAC,WAAW,QAAQ,UAAU,QAAQ,OAAO,QAAQ,KAAK,CAAC,WAAW,UAAU,WAAW,MAAM;AAElH,SAAK;AAAA,MACH,oBAAC,OAAI,eAA8B,QAAQ,EAAE,G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OAAA;AAAA,UACf,OAAA;AAAA,SACF;AAAA,QACA;AAAA,UACE,GAAA;AAAA,UACA,eAAe,IAAK,CAAA,aAAA;AAAA,UACpB,QAAQ,IAAK,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,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA,MAAA;AAAA,OACd,CAAA,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,KACnC;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\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', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n pathParamsType = 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\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 key: (key: unknown[]) => key,\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\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"]}
|