@kubb/plugin-swr 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.
Files changed (61) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-4EGGCGSE.js +217 -0
  3. package/dist/chunk-4EGGCGSE.js.map +1 -0
  4. package/dist/chunk-H23WKEYP.js +243 -0
  5. package/dist/chunk-H23WKEYP.js.map +1 -0
  6. package/dist/chunk-JWGWABV5.cjs +249 -0
  7. package/dist/chunk-JWGWABV5.cjs.map +1 -0
  8. package/dist/chunk-PTOQHHST.cjs +220 -0
  9. package/dist/chunk-PTOQHHST.cjs.map +1 -0
  10. package/dist/components.cjs +23 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +88 -6
  13. package/dist/components.d.ts +88 -6
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +11 -0
  19. package/dist/generators.d.ts +11 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +93 -123
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +2 -4
  25. package/dist/index.d.ts +2 -4
  26. package/dist/index.js +77 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DaH2Sc1M.d.cts +103 -0
  29. package/dist/types-DaH2Sc1M.d.ts +103 -0
  30. package/package.json +23 -17
  31. package/src/components/Mutation.tsx +93 -227
  32. package/src/components/MutationKey.tsx +48 -0
  33. package/src/components/Query.tsx +93 -259
  34. package/src/components/QueryKey.tsx +73 -0
  35. package/src/components/QueryOptions.tsx +54 -177
  36. package/src/components/index.ts +2 -0
  37. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
  38. package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
  39. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  40. package/src/generators/__snapshots__/findByTags.ts +43 -0
  41. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
  43. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  44. package/src/generators/__snapshots__/postAsQuery.ts +41 -0
  45. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  46. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
  47. package/src/generators/index.ts +2 -0
  48. package/src/generators/mutationGenerator.tsx +109 -0
  49. package/src/generators/queryGenerator.tsx +114 -0
  50. package/src/plugin.ts +71 -52
  51. package/src/types.ts +62 -78
  52. package/dist/chunk-TGLXUPN4.cjs +0 -536
  53. package/dist/chunk-TGLXUPN4.cjs.map +0 -1
  54. package/dist/chunk-XWXMQJD6.js +0 -536
  55. package/dist/chunk-XWXMQJD6.js.map +0 -1
  56. package/dist/index-B3C-JOIU.d.cts +0 -299
  57. package/dist/index-B3C-JOIU.d.ts +0 -299
  58. package/src/OperationGenerator.tsx +0 -75
  59. package/src/components/SchemaType.tsx +0 -63
  60. package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
  61. package/src/components/__snapshots__/Query/showPetById.ts +0 -59
@@ -1,7 +1,89 @@
1
- export { M as Mutation, Q as Query, a as QueryOptions } from './index-B3C-JOIU.cjs';
2
- import '@kubb/core/utils';
3
- import '@kubb/oas';
4
- import 'react';
1
+ import { Operation } from '@kubb/oas';
2
+ import { OperationSchemas } from '@kubb/plugin-oas';
3
+ import { ReactNode } from 'react';
4
+ import { P as PluginSwr } from './types-DaH2Sc1M.cjs';
5
+ import { FunctionParams } from '@kubb/react';
5
6
  import '@kubb/core';
6
- import '@kubb/fs/types';
7
- import '@kubb/plugin-oas';
7
+ import '@kubb/plugin-client';
8
+
9
+ type Props$4 = {
10
+ /**
11
+ * Name of the function
12
+ */
13
+ name: string;
14
+ typeName: string;
15
+ clientName: string;
16
+ mutationKeyName: string;
17
+ mutationKeyTypeName: string;
18
+ typeSchemas: OperationSchemas;
19
+ operation: Operation;
20
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
21
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
22
+ };
23
+ declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, pathParamsType, dataReturnType, typeSchemas, operation }: Props$4): ReactNode;
24
+
25
+ type Props$3 = {
26
+ /**
27
+ * Name of the function
28
+ */
29
+ name: string;
30
+ queryOptionsName: string;
31
+ queryKeyName: string;
32
+ queryKeyTypeName: string;
33
+ typeSchemas: OperationSchemas;
34
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
35
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
36
+ operation: Operation;
37
+ };
38
+ declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, pathParamsType }: Props$3): ReactNode;
39
+
40
+ type Props$2 = {
41
+ name: string;
42
+ clientName: string;
43
+ typeSchemas: OperationSchemas;
44
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
45
+ };
46
+ type GetParamsProps$2 = {
47
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
48
+ typeSchemas: OperationSchemas;
49
+ };
50
+ declare function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props$2): ReactNode;
51
+ declare namespace QueryOptions {
52
+ var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
53
+ }
54
+
55
+ type Props$1 = {
56
+ name: string;
57
+ typeName: string;
58
+ typeSchemas: OperationSchemas;
59
+ operation: Operation;
60
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
61
+ keysFn: ((keys: unknown[]) => unknown[]) | undefined;
62
+ };
63
+ type GetParamsProps$1 = {
64
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
65
+ typeSchemas: OperationSchemas;
66
+ };
67
+ declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn }: Props$1): ReactNode;
68
+ declare namespace QueryKey {
69
+ var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
70
+ }
71
+
72
+ type Props = {
73
+ name: string;
74
+ typeName: string;
75
+ typeSchemas: OperationSchemas;
76
+ operation: Operation;
77
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
78
+ keysFn: ((keys: unknown[]) => unknown[]) | undefined;
79
+ };
80
+ type GetParamsProps = {
81
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
82
+ typeSchemas: OperationSchemas;
83
+ };
84
+ declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn }: Props): ReactNode;
85
+ declare namespace MutationKey {
86
+ var getParams: ({}: GetParamsProps) => FunctionParams;
87
+ }
88
+
89
+ export { Mutation, MutationKey, Query, QueryKey, QueryOptions };
@@ -1,7 +1,89 @@
1
- export { M as Mutation, Q as Query, a as QueryOptions } from './index-B3C-JOIU.js';
2
- import '@kubb/core/utils';
3
- import '@kubb/oas';
4
- import 'react';
1
+ import { Operation } from '@kubb/oas';
2
+ import { OperationSchemas } from '@kubb/plugin-oas';
3
+ import { ReactNode } from 'react';
4
+ import { P as PluginSwr } from './types-DaH2Sc1M.js';
5
+ import { FunctionParams } from '@kubb/react';
5
6
  import '@kubb/core';
6
- import '@kubb/fs/types';
7
- import '@kubb/plugin-oas';
7
+ import '@kubb/plugin-client';
8
+
9
+ type Props$4 = {
10
+ /**
11
+ * Name of the function
12
+ */
13
+ name: string;
14
+ typeName: string;
15
+ clientName: string;
16
+ mutationKeyName: string;
17
+ mutationKeyTypeName: string;
18
+ typeSchemas: OperationSchemas;
19
+ operation: Operation;
20
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
21
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
22
+ };
23
+ declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, pathParamsType, dataReturnType, typeSchemas, operation }: Props$4): ReactNode;
24
+
25
+ type Props$3 = {
26
+ /**
27
+ * Name of the function
28
+ */
29
+ name: string;
30
+ queryOptionsName: string;
31
+ queryKeyName: string;
32
+ queryKeyTypeName: string;
33
+ typeSchemas: OperationSchemas;
34
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
35
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
36
+ operation: Operation;
37
+ };
38
+ declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, pathParamsType }: Props$3): ReactNode;
39
+
40
+ type Props$2 = {
41
+ name: string;
42
+ clientName: string;
43
+ typeSchemas: OperationSchemas;
44
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
45
+ };
46
+ type GetParamsProps$2 = {
47
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
48
+ typeSchemas: OperationSchemas;
49
+ };
50
+ declare function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props$2): ReactNode;
51
+ declare namespace QueryOptions {
52
+ var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
53
+ }
54
+
55
+ type Props$1 = {
56
+ name: string;
57
+ typeName: string;
58
+ typeSchemas: OperationSchemas;
59
+ operation: Operation;
60
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
61
+ keysFn: ((keys: unknown[]) => unknown[]) | undefined;
62
+ };
63
+ type GetParamsProps$1 = {
64
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
65
+ typeSchemas: OperationSchemas;
66
+ };
67
+ declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn }: Props$1): ReactNode;
68
+ declare namespace QueryKey {
69
+ var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
70
+ }
71
+
72
+ type Props = {
73
+ name: string;
74
+ typeName: string;
75
+ typeSchemas: OperationSchemas;
76
+ operation: Operation;
77
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
78
+ keysFn: ((keys: unknown[]) => unknown[]) | undefined;
79
+ };
80
+ type GetParamsProps = {
81
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
82
+ typeSchemas: OperationSchemas;
83
+ };
84
+ declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn }: Props): ReactNode;
85
+ declare namespace MutationKey {
86
+ var getParams: ({}: GetParamsProps) => FunctionParams;
87
+ }
88
+
89
+ export { Mutation, MutationKey, Query, QueryKey, QueryOptions };
@@ -1,11 +1,3 @@
1
- import {
2
- Mutation,
3
- Query,
4
- QueryOptions
5
- } from "./chunk-XWXMQJD6.js";
6
- export {
7
- Mutation,
8
- Query,
9
- QueryOptions
10
- };
1
+ export { Mutation, MutationKey, Query, QueryKey, QueryOptions } from './chunk-H23WKEYP.js';
2
+ //# sourceMappingURL=components.js.map
11
3
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var chunkPTOQHHST_cjs = require('./chunk-PTOQHHST.cjs');
4
+ require('./chunk-JWGWABV5.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "mutationGenerator", {
9
+ enumerable: true,
10
+ get: function () { return chunkPTOQHHST_cjs.mutationGenerator; }
11
+ });
12
+ Object.defineProperty(exports, "queryGenerator", {
13
+ enumerable: true,
14
+ get: function () { return chunkPTOQHHST_cjs.queryGenerator; }
15
+ });
16
+ //# sourceMappingURL=generators.cjs.map
17
+ //# sourceMappingURL=generators.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
@@ -0,0 +1,11 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginSwr } from './types-DaH2Sc1M.cjs';
3
+ import '@kubb/core';
4
+ import '@kubb/oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const queryGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
8
+
9
+ declare const mutationGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
10
+
11
+ export { mutationGenerator, queryGenerator };
@@ -0,0 +1,11 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginSwr } from './types-DaH2Sc1M.js';
3
+ import '@kubb/core';
4
+ import '@kubb/oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const queryGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
8
+
9
+ declare const mutationGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
10
+
11
+ export { mutationGenerator, queryGenerator };
@@ -0,0 +1,4 @@
1
+ export { mutationGenerator, queryGenerator } from './chunk-4EGGCGSE.js';
2
+ import './chunk-H23WKEYP.js';
3
+ //# sourceMappingURL=generators.js.map
4
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
package/dist/index.cjs CHANGED
@@ -1,158 +1,128 @@
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; }
1
+ 'use strict';
2
2
 
3
+ var chunkPTOQHHST_cjs = require('./chunk-PTOQHHST.cjs');
4
+ require('./chunk-JWGWABV5.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ require('@kubb/core/utils');
9
+ var pluginOas = require('@kubb/plugin-oas');
10
+ var pluginTs = require('@kubb/plugin-ts');
11
+ var pluginZod = require('@kubb/plugin-zod');
3
12
 
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
4
14
 
5
- var _chunkTGLXUPN4cjs = require('./chunk-TGLXUPN4.cjs');
15
+ var path__default = /*#__PURE__*/_interopDefault(path);
6
16
 
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 _plugints = require('@kubb/plugin-ts');
14
- var _pluginzod = require('@kubb/plugin-zod');
15
-
16
- // src/OperationGenerator.tsx
17
-
18
- var _components = require('@kubb/plugin-oas/components');
19
- var _react = require('@kubb/react');
20
- var _jsxruntime = require('@kubb/react/jsx-runtime');
21
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
22
- async get(operation, options) {
23
- const { oas, pluginManager, plugin, mode } = this.context;
24
- const root = _react.createRoot.call(void 0, {
25
- logger: pluginManager.logger
26
- });
27
- if (!_optionalChain([options, 'access', _ => _.templates, 'optionalAccess', _2 => _2.query]) || !_optionalChain([options, 'access', _3 => _3.templates, 'optionalAccess', _4 => _4.queryOptions])) {
28
- return [];
29
- }
30
- root.render(
31
- /* @__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,
32
- _chunkTGLXUPN4cjs.Query.File,
33
- {
34
- templates: {
35
- query: options.templates.query,
36
- queryOptions: options.templates.queryOptions
37
- }
38
- }
39
- ) }) }) })
40
- );
41
- return root.files;
42
- }
43
- async post(operation, options) {
44
- const { oas, pluginManager, plugin, mode } = this.context;
45
- const root = _react.createRoot.call(void 0, {
46
- logger: pluginManager.logger
47
- });
48
- if (!_optionalChain([options, 'access', _5 => _5.templates, 'optionalAccess', _6 => _6.mutation])) {
49
- return [];
50
- }
51
- root.render(
52
- /* @__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, _chunkTGLXUPN4cjs.Mutation.File, { templates: options.templates.mutation }) }) }) })
53
- );
54
- return root.files;
55
- }
56
- async put(operation, options) {
57
- return this.post(operation, options);
58
- }
59
- async patch(operation, options) {
60
- return this.post(operation, options);
61
- }
62
- async delete(operation, options) {
63
- return this.post(operation, options);
64
- }
65
- };
66
-
67
- // src/plugin.ts
68
17
  var pluginSwrName = "plugin-swr";
69
- var pluginSwr = _core.createPlugin.call(void 0, (options) => {
70
- const { output = { path: "hooks" }, group, exclude = [], include, override = [], parser, transformers = {}, templates, dataReturnType = "data" } = options;
71
- const template = _optionalChain([group, 'optionalAccess', _7 => _7.output]) ? group.output : `${output.path}/{{tag}}SWRController`;
18
+ var pluginSwr = core.createPlugin((options) => {
19
+ const {
20
+ output = { path: "hooks", barrelType: "named" },
21
+ group,
22
+ exclude = [],
23
+ include,
24
+ override = [],
25
+ parser = "client",
26
+ transformers: transformers$1 = {},
27
+ query,
28
+ mutation,
29
+ client,
30
+ pathParamsType = "inline",
31
+ generators = [chunkPTOQHHST_cjs.queryGenerator, chunkPTOQHHST_cjs.mutationGenerator].filter(Boolean)
32
+ } = options;
72
33
  return {
73
34
  name: pluginSwrName,
74
- output: {
75
- exportType: "barrelNamed",
76
- ...output
77
- },
78
35
  options: {
79
- extName: output.extName,
80
- templates: {
81
- mutation: _chunkTGLXUPN4cjs.Mutation.templates,
82
- query: _chunkTGLXUPN4cjs.Query.templates,
83
- queryOptions: _chunkTGLXUPN4cjs.QueryOptions.templates,
84
- ...templates
85
- },
36
+ output,
37
+ pathParamsType,
86
38
  client: {
87
39
  importPath: "@kubb/plugin-client/client",
88
- ...options.client
40
+ dataReturnType: "data",
41
+ ...client
42
+ },
43
+ query: {
44
+ key: (key) => key,
45
+ importPath: "swr",
46
+ methods: ["get"],
47
+ ...query
48
+ },
49
+ mutation: {
50
+ key: (key) => key,
51
+ importPath: "swr/mutation",
52
+ methods: ["post", "put", "delete", "patch"],
53
+ ...mutation
89
54
  },
90
- dataReturnType,
91
- parser
55
+ parser,
56
+ baseURL: void 0
92
57
  },
93
- pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, parser === "zod" ? _pluginzod.pluginZodName : void 0].filter(Boolean),
58
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
94
59
  resolvePath(baseName, pathMode, options2) {
95
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
96
- const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
97
- if (mode === "single") {
98
- return _path2.default.resolve(root, output.path);
60
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
61
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
62
+ if (options2?.tag && group?.type === "tag") {
63
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
64
+ return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
99
65
  }
100
- if (_optionalChain([options2, 'optionalAccess', _8 => _8.tag]) && _optionalChain([group, 'optionalAccess', _9 => _9.type]) === "tag") {
101
- const tag = _transformers.camelCase.call(void 0, options2.tag);
102
- return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
66
+ if (mode === "single") {
67
+ return path__default.default.resolve(root, output.path);
103
68
  }
104
- return _path2.default.resolve(root, output.path, baseName);
69
+ return path__default.default.resolve(root, output.path, baseName);
105
70
  },
106
71
  resolveName(name, type) {
107
- let resolvedName = _transformers.camelCase.call(void 0, name);
72
+ let resolvedName = transformers.camelCase(name);
108
73
  if (type === "file" || type === "function") {
109
- resolvedName = _transformers.camelCase.call(void 0, name, {
110
- prefix: "use",
74
+ resolvedName = transformers.camelCase(name, {
111
75
  isFile: type === "file"
112
76
  });
113
77
  }
114
78
  if (type === "type") {
115
- resolvedName = _transformers.pascalCase.call(void 0, name);
79
+ resolvedName = transformers.pascalCase(name);
116
80
  }
117
81
  if (type) {
118
- return _optionalChain([transformers, 'optionalAccess', _10 => _10.name, 'optionalCall', _11 => _11(resolvedName, type)]) || resolvedName;
82
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
119
83
  }
120
84
  return resolvedName;
121
85
  },
122
86
  async buildStart() {
123
- const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
87
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
124
88
  const oas = await swaggerPlugin.context.getOas();
125
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
126
- const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
127
- const operationGenerator = new OperationGenerator(this.plugin.options, {
128
- oas,
129
- pluginManager: this.pluginManager,
130
- plugin: this.plugin,
131
- contentType: swaggerPlugin.context.contentType,
132
- exclude,
133
- include,
134
- override,
135
- mode
136
- });
137
- const files = await operationGenerator.build();
89
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
90
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
91
+ const baseURL = await swaggerPlugin.context.getBaseURL();
92
+ const operationGenerator = new pluginOas.OperationGenerator(
93
+ {
94
+ ...this.plugin.options,
95
+ baseURL
96
+ },
97
+ {
98
+ oas,
99
+ pluginManager: this.pluginManager,
100
+ plugin: this.plugin,
101
+ contentType: swaggerPlugin.context.contentType,
102
+ exclude,
103
+ include,
104
+ override,
105
+ mode
106
+ }
107
+ );
108
+ const files = await operationGenerator.build(...generators);
138
109
  await this.addFile(...files);
139
- if (this.config.output.exportType) {
140
- const barrelFiles = await this.fileManager.getBarrelFiles({
141
- root,
142
- output,
143
- files: this.fileManager.files,
144
- meta: {
145
- pluginKey: this.plugin.key
146
- },
147
- logger: this.logger
148
- });
149
- await this.addFile(...barrelFiles);
150
- }
110
+ const barrelFiles = await this.fileManager.getBarrelFiles({
111
+ type: output.barrelType ?? "named",
112
+ root,
113
+ output,
114
+ files: this.fileManager.files,
115
+ meta: {
116
+ pluginKey: this.plugin.key
117
+ },
118
+ logger: this.logger
119
+ });
120
+ await this.addFile(...barrelFiles);
151
121
  }
152
122
  };
153
123
  });
154
124
 
155
-
156
-
157
- exports.pluginSwr = pluginSwr; exports.pluginSwrName = pluginSwrName;
125
+ exports.pluginSwr = pluginSwr;
126
+ exports.pluginSwrName = pluginSwrName;
127
+ //# sourceMappingURL=index.cjs.map
158
128
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-swr/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACNA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAAsC;AACtC,yCAA+B;AAC/B,6CAA8B;AAE9B,2CAA6B;AAC7B,6CAA8B;ADM9B;AACA;AEfA;AACA,yDAAoB;AACpB,oCAAgC;AAyBpB,qDAAA;AAhBL,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAA6D;AAAA,EACnG,MAAM,GAAA,CAAI,SAAA,EAAsB,OAAA,EAAwE;AACtG,IAAA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A;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'\n\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 output: {\n exportType: 'barrelNamed',\n ...output,\n },\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.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'\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"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA,aAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,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,kBACTC,iBAAe,EAAC;AAAA,IAChB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AA;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.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 { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n pathParamsType = 'inline',\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n pathParamsType,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n query: {\n key: (key: unknown[]) => key,\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutation: {\n key: (key: unknown[]) => key,\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n baseURL: undefined,\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\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.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,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginSwr } from './index-B3C-JOIU.cjs';
3
- import '@kubb/core/utils';
2
+ import { O as Options, P as PluginSwr } from './types-DaH2Sc1M.cjs';
4
3
  import '@kubb/oas';
5
- import 'react';
6
- import '@kubb/fs/types';
4
+ import '@kubb/plugin-client';
7
5
  import '@kubb/plugin-oas';
8
6
 
9
7
  declare const pluginSwrName = "plugin-swr";
package/dist/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginSwr } from './index-B3C-JOIU.js';
3
- import '@kubb/core/utils';
2
+ import { O as Options, P as PluginSwr } from './types-DaH2Sc1M.js';
4
3
  import '@kubb/oas';
5
- import 'react';
6
- import '@kubb/fs/types';
4
+ import '@kubb/plugin-client';
7
5
  import '@kubb/plugin-oas';
8
6
 
9
7
  declare const pluginSwrName = "plugin-swr";