@kubb/plugin-swr 3.0.0-alpha.0

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.
@@ -0,0 +1,304 @@
1
+ import { URLPath } from '@kubb/core/utils';
2
+ import { HttpMethod } from '@kubb/oas';
3
+ import { ReactNode } from 'react';
4
+ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
5
+ import * as KubbFile from '@kubb/fs/types';
6
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
7
+
8
+ type TemplateProps$2 = {
9
+ /**
10
+ * Name of the function
11
+ */
12
+ name: string;
13
+ /**
14
+ * Parameters/options/props that need to be used
15
+ */
16
+ params: string;
17
+ /**
18
+ * Generics that needs to be added for TypeScript
19
+ */
20
+ generics?: string;
21
+ /**
22
+ * ReturnType(see async for adding Promise type)
23
+ */
24
+ returnType?: string;
25
+ /**
26
+ * Options for JSdocs
27
+ */
28
+ JSDoc?: {
29
+ comments: string[];
30
+ };
31
+ hook: {
32
+ name: string;
33
+ generics?: string;
34
+ };
35
+ client: {
36
+ method: HttpMethod;
37
+ generics: string;
38
+ withQueryParams: boolean;
39
+ withPathParams: boolean;
40
+ withData: boolean;
41
+ withHeaders: boolean;
42
+ path: URLPath;
43
+ };
44
+ dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>;
45
+ };
46
+ declare function Template$2({ name, generics, returnType, params, JSDoc, client, hook, dataReturnType }: TemplateProps$2): ReactNode;
47
+ declare const defaultTemplates$1: {
48
+ readonly default: typeof Template$2;
49
+ };
50
+ type Props$2 = {
51
+ factory: {
52
+ name: string;
53
+ };
54
+ /**
55
+ * This will make it possible to override the default behaviour.
56
+ */
57
+ Template?: React.ComponentType<TemplateProps$2>;
58
+ };
59
+ declare function Mutation({ factory, Template }: Props$2): ReactNode;
60
+ declare namespace Mutation {
61
+ var File: ({ templates }: FileProps$1) => ReactNode;
62
+ var templates: {
63
+ readonly default: typeof Template$2;
64
+ };
65
+ }
66
+ type FileProps$1 = {
67
+ /**
68
+ * This will make it possible to override the default behaviour.
69
+ */
70
+ templates?: typeof defaultTemplates$1;
71
+ };
72
+
73
+ type TemplateProps$1 = {
74
+ /**
75
+ * Name of the function
76
+ */
77
+ name: string;
78
+ /**
79
+ * Parameters/options/props that need to be used
80
+ */
81
+ params: string;
82
+ /**
83
+ * Generics that needs to be added for TypeScript
84
+ */
85
+ generics?: string;
86
+ /**
87
+ * ReturnType(see async for adding Promise type)
88
+ */
89
+ returnType?: string;
90
+ /**
91
+ * Options for JSdocs
92
+ */
93
+ JSDoc?: {
94
+ comments: string[];
95
+ };
96
+ client: {
97
+ generics: string;
98
+ method: HttpMethod;
99
+ path: URLPath;
100
+ withQueryParams: boolean;
101
+ withPathParams: boolean;
102
+ withData: boolean;
103
+ withHeaders: boolean;
104
+ contentType: string;
105
+ };
106
+ dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>;
107
+ parser: string | undefined;
108
+ };
109
+ declare function Template$1({ name, params, generics, returnType, JSDoc, client, dataReturnType, parser }: TemplateProps$1): ReactNode;
110
+ type Props$1 = {
111
+ factory: {
112
+ name: string;
113
+ };
114
+ dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>;
115
+ /**
116
+ * This will make it possible to override the default behaviour.
117
+ */
118
+ Template?: React.ComponentType<TemplateProps$1>;
119
+ };
120
+ declare function QueryOptions({ factory, dataReturnType, Template }: Props$1): ReactNode;
121
+ declare namespace QueryOptions {
122
+ var templates: {
123
+ readonly default: typeof Template$1;
124
+ };
125
+ }
126
+
127
+ type TemplateProps = {
128
+ /**
129
+ * Name of the function
130
+ */
131
+ name: string;
132
+ /**
133
+ * Parameters/options/props that need to be used
134
+ */
135
+ params: string;
136
+ /**
137
+ * Generics that needs to be added for TypeScript
138
+ */
139
+ generics?: string;
140
+ /**
141
+ * ReturnType(see async for adding Promise type)
142
+ */
143
+ returnType?: string;
144
+ /**
145
+ * Options for JSdocs
146
+ */
147
+ JSDoc?: {
148
+ comments: string[];
149
+ };
150
+ hook: {
151
+ name: string;
152
+ generics?: string;
153
+ queryOptions: string;
154
+ };
155
+ client: {
156
+ path: URLPath;
157
+ withQueryParams: boolean;
158
+ };
159
+ };
160
+ declare function Template({ name, generics, returnType, params, JSDoc, hook, client }: TemplateProps): ReactNode;
161
+ declare const defaultTemplates: {
162
+ readonly default: typeof Template;
163
+ };
164
+ type Props = {
165
+ factory: {
166
+ name: string;
167
+ };
168
+ /**
169
+ * This will make it possible to override the default behaviour.
170
+ */
171
+ Template?: React.ComponentType<TemplateProps>;
172
+ /**
173
+ * This will make it possible to override the default behaviour.
174
+ */
175
+ QueryOptionsTemplate?: React.ComponentType<React.ComponentProps<typeof QueryOptions.templates.default>>;
176
+ };
177
+ declare function Query({ factory, Template, QueryOptionsTemplate }: Props): ReactNode;
178
+ declare namespace Query {
179
+ var File: ({ templates }: FileProps) => ReactNode;
180
+ var templates: {
181
+ readonly default: typeof Template;
182
+ };
183
+ }
184
+ type FileProps = {
185
+ /**
186
+ * This will make it possible to override the default behaviour.
187
+ */
188
+ templates?: {
189
+ query: typeof defaultTemplates;
190
+ queryOptions: typeof QueryOptions.templates;
191
+ };
192
+ };
193
+
194
+ type Templates = {
195
+ mutation?: typeof Mutation.templates | false;
196
+ query?: typeof Query.templates | false;
197
+ queryOptions?: typeof QueryOptions.templates | false;
198
+ };
199
+ type Options = {
200
+ output?: {
201
+ /**
202
+ * Output to save the SWR hooks.
203
+ * @default `"hooks"`
204
+ */
205
+ path: string;
206
+ /**
207
+ * Name to be used for the `export * as {{exportAs}} from './'`
208
+ */
209
+ exportAs?: string;
210
+ /**
211
+ * Add an extension to the generated imports and exports, default it will not use an extension
212
+ */
213
+ extName?: KubbFile.Extname;
214
+ /**
215
+ * Define what needs to exported, here you can also disable the export of barrel files
216
+ * @default `'barrel'`
217
+ */
218
+ exportType?: 'barrel' | 'barrelNamed' | false;
219
+ };
220
+ /**
221
+ * Group the SWR hooks based on the provided name.
222
+ */
223
+ group?: {
224
+ /**
225
+ * Tag will group based on the operation tag inside the Swagger file
226
+ */
227
+ type: 'tag';
228
+ /**
229
+ * Relative path to save the grouped SWR hooks.
230
+ *
231
+ * `{{tag}}` will be replaced by the current tagName.
232
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
233
+ * @default `${output}/{{tag}}Controller`
234
+ */
235
+ output?: string;
236
+ /**
237
+ * Name to be used for the `export * as {{exportAs}} from './`
238
+ * @default `"{{tag}}SWRHooks"`
239
+ */
240
+ exportAs?: string;
241
+ };
242
+ /**
243
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
244
+ */
245
+ exclude?: Array<Exclude>;
246
+ /**
247
+ * Array containing include parameters to include tags/operations/methods/paths.
248
+ */
249
+ include?: Array<Include>;
250
+ /**
251
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
252
+ */
253
+ override?: Array<Override<ResolvedOptions>>;
254
+ client?: {
255
+ /**
256
+ * Path to the client import path that will be used to do the API calls.
257
+ * It will be used as `import client from '${client.importPath}'`.
258
+ * It allow both relative and absolute path.
259
+ * the path will be applied as is, so relative path shoule be based on the file being generated.
260
+ * @default '@kubb/plugin-client/client'
261
+ */
262
+ importPath?: string;
263
+ };
264
+ /**
265
+ * ReturnType that needs to be used when calling client().
266
+ *
267
+ * `Data` will return ResponseConfig[data].
268
+ *
269
+ * `Full` will return ResponseConfig.
270
+ * @default `'data'`
271
+ * @private
272
+ */
273
+ dataReturnType?: 'data' | 'full';
274
+ transformers?: {
275
+ /**
276
+ * Customize the names based on the type that is provided by the plugin.
277
+ */
278
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
279
+ };
280
+ /**
281
+ * Which parser can be used before returning the data to `@tanstack/query`.
282
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
283
+ */
284
+ parser?: 'zod';
285
+ /**
286
+ * Make it possible to override one of the templates
287
+ */
288
+ templates?: Partial<Templates>;
289
+ };
290
+ type ResolvedOptions = {
291
+ extName: KubbFile.Extname | undefined;
292
+ client: Required<NonNullable<Options['client']>>;
293
+ dataReturnType: NonNullable<Options['dataReturnType']>;
294
+ templates: NonNullable<Templates>;
295
+ parser: Options['parser'];
296
+ };
297
+ type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>;
298
+ declare module '@kubb/core' {
299
+ interface _Register {
300
+ ['@kubb/plugin-swr']: PluginSwr;
301
+ }
302
+ }
303
+
304
+ export { Mutation as M, type Options as O, type PluginSwr as P, Query as Q, QueryOptions as a };
package/dist/index.cjs ADDED
@@ -0,0 +1,180 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkH4LHXYRJcjs = require('./chunk-H4LHXYRJ.cjs');
6
+
7
+ // src/plugin.ts
8
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
9
+ var _core = require('@kubb/core');
10
+ var _transformers = require('@kubb/core/transformers');
11
+ var _utils = require('@kubb/core/utils');
12
+ var _pluginoas = require('@kubb/plugin-oas');
13
+ var _utils3 = require('@kubb/plugin-oas/utils');
14
+ var _plugints = require('@kubb/plugin-ts');
15
+ var _pluginzod = require('@kubb/plugin-zod');
16
+
17
+ // src/OperationGenerator.tsx
18
+
19
+ var _components = require('@kubb/plugin-oas/components');
20
+ var _react = require('@kubb/react');
21
+ var _jsxruntime = require('@kubb/react/jsx-runtime');
22
+ var OperationGenerator = class extends _pluginoas.OperationGenerator {
23
+ async get(operation, options) {
24
+ const { oas, pluginManager, plugin, mode } = this.context;
25
+ const root = _react.createRoot.call(void 0, {
26
+ logger: pluginManager.logger
27
+ });
28
+ if (!_optionalChain([options, 'access', _ => _.templates, 'optionalAccess', _2 => _2.query]) || !_optionalChain([options, 'access', _3 => _3.templates, 'optionalAccess', _4 => _4.queryOptions])) {
29
+ return [];
30
+ }
31
+ root.render(
32
+ /* @__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.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
33
+ _chunkH4LHXYRJcjs.Query.File,
34
+ {
35
+ templates: {
36
+ query: options.templates.query,
37
+ queryOptions: options.templates.queryOptions
38
+ }
39
+ }
40
+ ) }) }) })
41
+ );
42
+ return root.files;
43
+ }
44
+ async post(operation, options) {
45
+ const { oas, pluginManager, plugin, mode } = this.context;
46
+ const root = _react.createRoot.call(void 0, {
47
+ logger: pluginManager.logger
48
+ });
49
+ if (!_optionalChain([options, 'access', _5 => _5.templates, 'optionalAccess', _6 => _6.mutation])) {
50
+ return [];
51
+ }
52
+ root.render(
53
+ /* @__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.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkH4LHXYRJcjs.Mutation.File, { templates: options.templates.mutation }) }) }) })
54
+ );
55
+ return root.files;
56
+ }
57
+ async put(operation, options) {
58
+ return this.post(operation, options);
59
+ }
60
+ async patch(operation, options) {
61
+ return this.post(operation, options);
62
+ }
63
+ async delete(operation, options) {
64
+ return this.post(operation, options);
65
+ }
66
+ };
67
+
68
+ // src/plugin.ts
69
+ var pluginSwrName = "plugin-swr";
70
+ var pluginSwr = _core.createPlugin.call(void 0, (options) => {
71
+ const { output = { path: "hooks" }, group, exclude = [], include, override = [], parser, transformers = {}, templates, dataReturnType = "data" } = options;
72
+ const template = _optionalChain([group, 'optionalAccess', _7 => _7.output]) ? group.output : `${output.path}/{{tag}}SWRController`;
73
+ return {
74
+ name: pluginSwrName,
75
+ options: {
76
+ extName: output.extName,
77
+ templates: {
78
+ mutation: _chunkH4LHXYRJcjs.Mutation.templates,
79
+ query: _chunkH4LHXYRJcjs.Query.templates,
80
+ queryOptions: _chunkH4LHXYRJcjs.QueryOptions.templates,
81
+ ...templates
82
+ },
83
+ client: {
84
+ importPath: "@kubb/plugin-client/client",
85
+ ...options.client
86
+ },
87
+ dataReturnType,
88
+ parser
89
+ },
90
+ pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, parser === "zod" ? _pluginzod.pluginZodName : void 0].filter(Boolean),
91
+ resolvePath(baseName, pathMode, options2) {
92
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
93
+ const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
94
+ if (mode === "single") {
95
+ return _path2.default.resolve(root, output.path);
96
+ }
97
+ if (_optionalChain([options2, 'optionalAccess', _8 => _8.tag]) && _optionalChain([group, 'optionalAccess', _9 => _9.type]) === "tag") {
98
+ const tag = _transformers.camelCase.call(void 0, options2.tag);
99
+ return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
100
+ }
101
+ return _path2.default.resolve(root, output.path, baseName);
102
+ },
103
+ resolveName(name, type) {
104
+ let resolvedName = _transformers.camelCase.call(void 0, name);
105
+ if (type === "file" || type === "function") {
106
+ resolvedName = _transformers.camelCase.call(void 0, name, {
107
+ prefix: "use",
108
+ isFile: type === "file"
109
+ });
110
+ }
111
+ if (type === "type") {
112
+ resolvedName = _transformers.pascalCase.call(void 0, name);
113
+ }
114
+ if (type) {
115
+ return _optionalChain([transformers, 'optionalAccess', _10 => _10.name, 'optionalCall', _11 => _11(resolvedName, type)]) || resolvedName;
116
+ }
117
+ return resolvedName;
118
+ },
119
+ async buildStart() {
120
+ const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
121
+ const oas = await swaggerPlugin.api.getOas();
122
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
123
+ const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
124
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
125
+ oas,
126
+ pluginManager: this.pluginManager,
127
+ plugin: this.plugin,
128
+ contentType: swaggerPlugin.api.contentType,
129
+ exclude,
130
+ include,
131
+ override,
132
+ mode
133
+ });
134
+ const files = await operationGenerator.build();
135
+ await this.addFile(...files);
136
+ },
137
+ async writeFile(path2, source) {
138
+ if (!path2.endsWith(".ts") || !source) {
139
+ return;
140
+ }
141
+ return this.fileManager.write(path2, source, { sanity: false });
142
+ },
143
+ async buildEnd() {
144
+ if (this.config.output.write === false) {
145
+ return;
146
+ }
147
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
148
+ if (_optionalChain([group, 'optionalAccess', _12 => _12.type]) === "tag") {
149
+ const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
150
+ logger: this.logger,
151
+ files: this.fileManager.files,
152
+ plugin: this.plugin,
153
+ template,
154
+ exportAs: group.exportAs || "{{tag}}SWRHooks",
155
+ root,
156
+ output
157
+ });
158
+ await this.addFile(...rootFiles);
159
+ }
160
+ await this.fileManager.addIndexes({
161
+ root,
162
+ output,
163
+ meta: { pluginKey: this.plugin.key },
164
+ logger: this.logger
165
+ });
166
+ }
167
+ };
168
+ });
169
+
170
+ // src/index.ts
171
+ var definePluginDefault = pluginSwr;
172
+ var definePlugin = pluginSwr;
173
+ var src_default = definePluginDefault;
174
+
175
+
176
+
177
+
178
+
179
+ exports.default = src_default; exports.definePlugin = definePlugin; exports.pluginSwr = pluginSwr; exports.pluginSwrName = pluginSwrName;
180
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-swr/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACNA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAAsC;AACtC,yCAA+B;AAC/B,6CAA8B;AAC9B,gDAAqC;AACrC,2CAA6B;AAC7B,6CAA8B;ADO9B;AACA;AEhBA;AACA,yDAAoB;AACpB,oCAAgC;AAyBpB,qDAAA;AAhBL,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAA6D;AAAA,EACnG,MAAM,GAAA,CAAI,SAAA,EAAsB,OAAA,EAAwE;AACtG,IAAA,MAAM,EAAE,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,KAAK,EAAA,EAAI,IAAA,CAAK,OAAA;AAElD,IAAA,MAAM,KAAA,EAAO,+BAAA;AAAW,MACtB,MAAA,EAAQ,aAAA,CAAc;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,GAAA,CAAI,iBAAC,OAAA,mBAAQ,SAAA,6BAAW,QAAA,GAAS,iBAAC,OAAA,qBAAQ,SAAA,6BAAW,cAAA,EAAc;AACjE,MAAA,OAAO,CAAC,CAAA;AAAA,IACV;AAEA,IAAA,IAAA,CAAK,MAAA;AAAA,sBACH,6BAAA,UAAC,EAAA,EAAI,aAAA,EAA8B,MAAA,EAAQ,EAAE,GAAG,MAAA,EAAQ,QAAQ,CAAA,EAAG,IAAA,EACjE,QAAA,kBAAA,6BAAA,eAAC,EAAA,EAAI,GAAA,EAAU,UAAA,EAAY,CAAC,SAAS,CAAA,EAAG,SAAA,EAAW,IAAA,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MAAA;AACzC,IAAA;AACwB,IAAA;AACW,MAAA;AAEW,MAAA;AACX,QAAA;AACrB,UAAA;AACS,UAAA;AAClB,QAAA;AACH,MAAA;AAEqB,MAAA;AACW,QAAA;AAChC,MAAA;AAEU,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AACmB,IAAA;AACqD,MAAA;AAE3B,MAAA;AACC,MAAA;AACN,MAAA;AAEP,MAAA;AAC7B,QAAA;AACoB,QAAA;AACP,QAAA;AACkB,QAAA;AAC/B,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACD,MAAA;AAE4C,MAAA;AAClB,MAAA;AAC7B,IAAA;AAC8B,IAAA;AACU,MAAA;AACpC,QAAA;AACF,MAAA;AAE4C,MAAA;AAC9C,IAAA;AACiB,IAAA;AACyB,MAAA;AACtC,QAAA;AACF,MAAA;AAE4C,MAAA;AAEjB,MAAA;AACD,QAAA;AACT,UAAA;AACW,UAAA;AACX,UAAA;AACb,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACA,UAAA;AACD,QAAA;AAE8B,QAAA;AACjC,MAAA;AAEkC,MAAA;AAChC,QAAA;AACA,QAAA;AACmC,QAAA;AACtB,QAAA;AACd,MAAA;AACH,IAAA;AACF,EAAA;AACD;AD8BkD;AACA;AGjKvB;AAIA;AAEb;AH+JoC;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-swr/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'\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, Query, QueryOptions } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const { output = { path: 'hooks' }, group, exclude = [], include, override = [], parser, transformers = {}, templates, dataReturnType = 'data' } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}SWRController`\n\n return {\n name: pluginSwrName,\n options: {\n extName: output.extName,\n templates: {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n ...templates,\n },\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n dataReturnType,\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\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<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.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 writeFile(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\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}}SWRHooks',\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 { Query } from './components/Query.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginSwr } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginSwr['resolvedOptions'], PluginSwr, FileMeta> {\n async get(operation: Operation, options: PluginSwr['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n if (!options.templates?.query || !options.templates?.queryOptions) {\n return []\n }\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 <Query.File\n templates={{\n query: options.templates.query,\n queryOptions: options.templates.queryOptions,\n }}\n />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async post(operation: Operation, options: PluginSwr['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n if (!options.templates?.mutation) {\n return []\n }\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 <Mutation.File templates={options.templates.mutation} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async put(operation: Operation, options: PluginSwr['resolvedOptions']): OperationMethodResult<FileMeta> {\n return this.post(operation, options)\n }\n async patch(operation: Operation, options: PluginSwr['resolvedOptions']): OperationMethodResult<FileMeta> {\n return this.post(operation, options)\n }\n async delete(operation: Operation, options: PluginSwr['resolvedOptions']): OperationMethodResult<FileMeta> {\n return this.post(operation, options)\n }\n}\n","import { pluginSwr } from './plugin.ts'\n\nexport { pluginSwr, pluginSwrName } from './plugin.ts'\nexport type { PluginSwr } from './types.ts'\n\n/**\n * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead\n */\nconst definePluginDefault = pluginSwr\n/**\n * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead\n */\nexport const definePlugin = pluginSwr\n\nexport default definePluginDefault\n"]}
@@ -0,0 +1,21 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { O as Options, P as PluginSwr } from './index-Ca8KyrCA.cjs';
3
+ import '@kubb/core/utils';
4
+ import '@kubb/oas';
5
+ import 'react';
6
+ import '@kubb/fs/types';
7
+ import '@kubb/plugin-oas';
8
+
9
+ declare const pluginSwrName = "plugin-swr";
10
+ declare const pluginSwr: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
11
+
12
+ /**
13
+ * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead
14
+ */
15
+ declare const definePluginDefault: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
16
+ /**
17
+ * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead
18
+ */
19
+ declare const definePlugin: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
20
+
21
+ export { PluginSwr, definePluginDefault as default, definePlugin, pluginSwr, pluginSwrName };
@@ -0,0 +1,21 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { O as Options, P as PluginSwr } from './index-Ca8KyrCA.js';
3
+ import '@kubb/core/utils';
4
+ import '@kubb/oas';
5
+ import 'react';
6
+ import '@kubb/fs/types';
7
+ import '@kubb/plugin-oas';
8
+
9
+ declare const pluginSwrName = "plugin-swr";
10
+ declare const pluginSwr: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
11
+
12
+ /**
13
+ * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead
14
+ */
15
+ declare const definePluginDefault: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
16
+ /**
17
+ * @deprecated Use `import { pluginSwr } from '@kubb/plugin-swr'` instead
18
+ */
19
+ declare const definePlugin: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
20
+
21
+ export { PluginSwr, definePluginDefault as default, definePlugin, pluginSwr, pluginSwrName };