@kubb/plugin-svelte-query 3.0.0-alpha.29 → 3.0.0-alpha.31
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/dist/{chunk-FXHTVRAH.cjs → chunk-DUG3WM5P.cjs} +76 -39
- package/dist/chunk-DUG3WM5P.cjs.map +1 -0
- package/dist/{chunk-A6W23SCP.js → chunk-TZ5HDOZR.js} +78 -40
- package/dist/chunk-TZ5HDOZR.js.map +1 -0
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +20 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -24
- package/dist/index.js.map +1 -1
- package/dist/{types-FkBg-Xsz.d.cts → types-s0tn0Q8J.d.cts} +2 -20
- package/dist/{types-FkBg-Xsz.d.ts → types-s0tn0Q8J.d.ts} +2 -20
- package/package.json +12 -12
- package/src/generators/mutationGenerator.tsx +3 -6
- package/src/generators/queryGenerator.tsx +4 -5
- package/src/plugin.ts +20 -25
- package/src/types.ts +2 -20
- package/dist/chunk-A6W23SCP.js.map +0 -1
- package/dist/chunk-FXHTVRAH.cjs.map +0 -1
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSvelteQuery } from './types-
|
|
4
|
+
import { P as PluginSvelteQuery } from './types-s0tn0Q8J.cjs';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSvelteQuery } from './types-
|
|
4
|
+
import { P as PluginSvelteQuery } from './types-s0tn0Q8J.js';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
|
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDUG3WM5P_cjs = require('./chunk-DUG3WM5P.cjs');
|
|
4
4
|
require('./chunk-WAAKXO6O.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "mutationGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkDUG3WM5P_cjs.mutationGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "queryGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkDUG3WM5P_cjs.queryGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDUG3WM5P_cjs = require('./chunk-DUG3WM5P.cjs');
|
|
4
4
|
require('./chunk-WAAKXO6O.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
8
|
-
|
|
8
|
+
require('@kubb/core/utils');
|
|
9
9
|
var pluginOas = require('@kubb/plugin-oas');
|
|
10
10
|
var pluginTs = require('@kubb/plugin-ts');
|
|
11
11
|
var pluginZod = require('@kubb/plugin-zod');
|
|
@@ -17,7 +17,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
17
17
|
var pluginSvelteQueryName = "plugin-svelte-query";
|
|
18
18
|
var pluginSvelteQuery = core.createPlugin((options) => {
|
|
19
19
|
const {
|
|
20
|
-
output = { path: "hooks" },
|
|
20
|
+
output = { path: "hooks", barrelType: "named" },
|
|
21
21
|
group,
|
|
22
22
|
exclude = [],
|
|
23
23
|
include,
|
|
@@ -27,16 +27,12 @@ var pluginSvelteQuery = core.createPlugin((options) => {
|
|
|
27
27
|
pathParamsType = "inline",
|
|
28
28
|
mutation = {},
|
|
29
29
|
query = {},
|
|
30
|
-
generators = [
|
|
30
|
+
generators = [chunkDUG3WM5P_cjs.queryGenerator, chunkDUG3WM5P_cjs.mutationGenerator].filter(Boolean)
|
|
31
31
|
} = options;
|
|
32
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
33
32
|
return {
|
|
34
33
|
name: pluginSvelteQueryName,
|
|
35
34
|
options: {
|
|
36
|
-
output
|
|
37
|
-
exportType: "barrelNamed",
|
|
38
|
-
...output
|
|
39
|
-
},
|
|
35
|
+
output,
|
|
40
36
|
baseURL: void 0,
|
|
41
37
|
client: {
|
|
42
38
|
importPath: "@kubb/plugin-client/client",
|
|
@@ -63,13 +59,13 @@ var pluginSvelteQuery = core.createPlugin((options) => {
|
|
|
63
59
|
resolvePath(baseName, pathMode, options2) {
|
|
64
60
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
65
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);
|
|
65
|
+
}
|
|
66
66
|
if (mode === "single") {
|
|
67
67
|
return path__default.default.resolve(root, output.path);
|
|
68
68
|
}
|
|
69
|
-
if (options2?.tag && group?.type === "tag") {
|
|
70
|
-
const tag = transformers.camelCase(options2.tag);
|
|
71
|
-
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
72
|
-
}
|
|
73
69
|
return path__default.default.resolve(root, output.path, baseName);
|
|
74
70
|
},
|
|
75
71
|
resolveName(name, type) {
|
|
@@ -111,18 +107,17 @@ var pluginSvelteQuery = core.createPlugin((options) => {
|
|
|
111
107
|
);
|
|
112
108
|
const files = await operationGenerator.build(...generators);
|
|
113
109
|
await this.addFile(...files);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
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);
|
|
126
121
|
}
|
|
127
122
|
};
|
|
128
123
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","
|
|
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,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AAA,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.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 } from '@kubb/plugin-oas'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSvelteQuery } from './types.ts'\n\nexport const pluginSvelteQueryName = 'plugin-svelte-query' satisfies PluginSvelteQuery['name']\n\nexport const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n pathParamsType = 'inline',\n mutation = {},\n query = {},\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSvelteQueryName,\n options: {\n output,\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n pathParamsType: 'inline',\n ...options.client,\n },\n query: {\n key: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/svelte-query',\n ...query,\n },\n mutation: {\n key: (key: unknown[]) => key,\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/svelte-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
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { queryGenerator, mutationGenerator } from './chunk-
|
|
1
|
+
import { queryGenerator, mutationGenerator } from './chunk-TZ5HDOZR.js';
|
|
2
2
|
import './chunk-B7GVNGYU.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
-
import
|
|
6
|
+
import '@kubb/core/utils';
|
|
7
7
|
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
8
8
|
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
9
|
import { pluginZodName } from '@kubb/plugin-zod';
|
|
@@ -11,7 +11,7 @@ import { pluginZodName } from '@kubb/plugin-zod';
|
|
|
11
11
|
var pluginSvelteQueryName = "plugin-svelte-query";
|
|
12
12
|
var pluginSvelteQuery = createPlugin((options) => {
|
|
13
13
|
const {
|
|
14
|
-
output = { path: "hooks" },
|
|
14
|
+
output = { path: "hooks", barrelType: "named" },
|
|
15
15
|
group,
|
|
16
16
|
exclude = [],
|
|
17
17
|
include,
|
|
@@ -23,14 +23,10 @@ var pluginSvelteQuery = createPlugin((options) => {
|
|
|
23
23
|
query = {},
|
|
24
24
|
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
25
25
|
} = options;
|
|
26
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
27
26
|
return {
|
|
28
27
|
name: pluginSvelteQueryName,
|
|
29
28
|
options: {
|
|
30
|
-
output
|
|
31
|
-
exportType: "barrelNamed",
|
|
32
|
-
...output
|
|
33
|
-
},
|
|
29
|
+
output,
|
|
34
30
|
baseURL: void 0,
|
|
35
31
|
client: {
|
|
36
32
|
importPath: "@kubb/plugin-client/client",
|
|
@@ -57,13 +53,13 @@ var pluginSvelteQuery = createPlugin((options) => {
|
|
|
57
53
|
resolvePath(baseName, pathMode, options2) {
|
|
58
54
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
59
55
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
56
|
+
if (options2?.tag && group?.type === "tag") {
|
|
57
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
58
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
59
|
+
}
|
|
60
60
|
if (mode === "single") {
|
|
61
61
|
return path.resolve(root, output.path);
|
|
62
62
|
}
|
|
63
|
-
if (options2?.tag && group?.type === "tag") {
|
|
64
|
-
const tag = camelCase(options2.tag);
|
|
65
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
66
|
-
}
|
|
67
63
|
return path.resolve(root, output.path, baseName);
|
|
68
64
|
},
|
|
69
65
|
resolveName(name, type) {
|
|
@@ -105,18 +101,17 @@ var pluginSvelteQuery = createPlugin((options) => {
|
|
|
105
101
|
);
|
|
106
102
|
const files = await operationGenerator.build(...generators);
|
|
107
103
|
await this.addFile(...files);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
104
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
105
|
+
type: output.barrelType ?? "named",
|
|
106
|
+
root,
|
|
107
|
+
output,
|
|
108
|
+
files: this.fileManager.files,
|
|
109
|
+
meta: {
|
|
110
|
+
pluginKey: this.plugin.key
|
|
111
|
+
},
|
|
112
|
+
logger: this.logger
|
|
113
|
+
});
|
|
114
|
+
await this.addFile(...barrelFiles);
|
|
120
115
|
}
|
|
121
116
|
};
|
|
122
117
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;;AAeO,IAAM,qBAAwB,GAAA,sBAAA;AAExB,IAAA,iBAAA,GAAoB,YAAgC,CAAA,CAAC,OAAY,KAAA;AAC5E,EAAM,MAAA;AAAA,IACJ,
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;;AAeO,IAAM,qBAAwB,GAAA,sBAAA;AAExB,IAAA,iBAAA,GAAoB,YAAgC,CAAA,CAAC,OAAY,KAAA;AAC5E,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,eAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,QAAA;AAAA,IACjB,WAAW,EAAC;AAAA,IACZ,QAAQ,EAAC;AAAA,IACT,aAAa,CAAC,cAAA,EAAgB,iBAAiB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,GAC7D,GAAA,OAAA,CAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,qBAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;A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ACd,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 { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSvelteQuery } from './types.ts'\n\nexport const pluginSvelteQueryName = 'plugin-svelte-query' satisfies PluginSvelteQuery['name']\n\nexport const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n pathParamsType = 'inline',\n mutation = {},\n query = {},\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSvelteQueryName,\n options: {\n output,\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n pathParamsType: 'inline',\n ...options.client,\n },\n query: {\n key: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/svelte-query',\n ...query,\n },\n mutation: {\n key: (key: unknown[]) => key,\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/svelte-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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import { HttpMethod } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
@@ -48,25 +48,7 @@ type Options = {
|
|
|
48
48
|
/**
|
|
49
49
|
* Group the @tanstack/query hooks based on the provided name.
|
|
50
50
|
*/
|
|
51
|
-
group?:
|
|
52
|
-
/**
|
|
53
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
54
|
-
*/
|
|
55
|
-
type: 'tag';
|
|
56
|
-
/**
|
|
57
|
-
* Relative path to save the grouped @tanstack/query hooks.
|
|
58
|
-
*
|
|
59
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
60
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
61
|
-
* @default `${output}/{{tag}}Controller`
|
|
62
|
-
*/
|
|
63
|
-
output?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
66
|
-
* @default `"{{tag}}Hooks"`
|
|
67
|
-
*/
|
|
68
|
-
exportAs?: string;
|
|
69
|
-
};
|
|
51
|
+
group?: Group;
|
|
70
52
|
client?: {
|
|
71
53
|
/**
|
|
72
54
|
* Path to the client that will be used to do the API calls.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import { HttpMethod } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
@@ -48,25 +48,7 @@ type Options = {
|
|
|
48
48
|
/**
|
|
49
49
|
* Group the @tanstack/query hooks based on the provided name.
|
|
50
50
|
*/
|
|
51
|
-
group?:
|
|
52
|
-
/**
|
|
53
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
54
|
-
*/
|
|
55
|
-
type: 'tag';
|
|
56
|
-
/**
|
|
57
|
-
* Relative path to save the grouped @tanstack/query hooks.
|
|
58
|
-
*
|
|
59
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
60
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
61
|
-
* @default `${output}/{{tag}}Controller`
|
|
62
|
-
*/
|
|
63
|
-
output?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
66
|
-
* @default `"{{tag}}Hooks"`
|
|
67
|
-
*/
|
|
68
|
-
exportAs?: string;
|
|
69
|
-
};
|
|
51
|
+
group?: Group;
|
|
70
52
|
client?: {
|
|
71
53
|
/**
|
|
72
54
|
* Path to the client that will be used to do the API calls.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-svelte-query",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.31",
|
|
4
4
|
"description": "Generator svelte-query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
"!/**/__tests__/**"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@kubb/core": "3.0.0-alpha.
|
|
66
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
67
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
70
|
-
"@kubb/plugin-zod": "3.0.0-alpha.
|
|
71
|
-
"@kubb/react": "3.0.0-alpha.
|
|
65
|
+
"@kubb/core": "3.0.0-alpha.31",
|
|
66
|
+
"@kubb/fs": "3.0.0-alpha.31",
|
|
67
|
+
"@kubb/oas": "3.0.0-alpha.31",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-alpha.31",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-alpha.31",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-alpha.31",
|
|
71
|
+
"@kubb/react": "3.0.0-alpha.31"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/react": "^18.3.
|
|
74
|
+
"@types/react": "^18.3.10",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
76
|
"tsup": "^8.3.0",
|
|
77
77
|
"typescript": "^5.6.2",
|
|
78
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
79
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
78
|
+
"@kubb/config-ts": "3.0.0-alpha.31",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-alpha.31"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-alpha.
|
|
82
|
+
"@kubb/react": "3.0.0-alpha.31"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -44,8 +44,8 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const mutationKey = {
|
|
47
|
-
name:
|
|
48
|
-
typeName:
|
|
47
|
+
name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
|
|
48
|
+
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (!isMutation || typeof options.mutation === 'boolean') {
|
|
@@ -54,15 +54,12 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
54
54
|
|
|
55
55
|
return (
|
|
56
56
|
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
57
|
-
{options.parser === 'zod' &&
|
|
58
|
-
<File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />
|
|
59
|
-
)}
|
|
57
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
60
58
|
<File.Import name={['createMutation']} path={options.mutation.importPath} />
|
|
61
59
|
<File.Import name={['CreateMutationOptions', 'CreateMutationResult']} path={options.mutation.importPath} isTypeOnly />
|
|
62
60
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
63
61
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
64
62
|
<File.Import
|
|
65
|
-
extName={output?.extName}
|
|
66
63
|
name={[
|
|
67
64
|
type.schemas.request?.name,
|
|
68
65
|
type.schemas.response.name,
|
|
@@ -33,12 +33,12 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const queryOptions = {
|
|
36
|
-
name:
|
|
36
|
+
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const queryKey = {
|
|
40
|
-
name:
|
|
41
|
-
typeName:
|
|
40
|
+
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
41
|
+
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const type = {
|
|
@@ -58,14 +58,13 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
61
|
-
{options.parser === 'zod' && <File.Import
|
|
61
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
62
62
|
<File.Import name={['createQuery', 'queryOptions']} path={options.query.importPath} />
|
|
63
63
|
<File.Import name={['QueryKey', 'WithRequired', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
64
64
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
65
65
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
66
66
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
67
67
|
<File.Import
|
|
68
|
-
extName={output?.extName}
|
|
69
68
|
name={[
|
|
70
69
|
type.schemas.request?.name,
|
|
71
70
|
type.schemas.response.name,
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
3
|
+
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
6
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
@@ -17,7 +17,7 @@ export const pluginSvelteQueryName = 'plugin-svelte-query' satisfies PluginSvelt
|
|
|
17
17
|
|
|
18
18
|
export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
19
19
|
const {
|
|
20
|
-
output = { path: 'hooks' },
|
|
20
|
+
output = { path: 'hooks', barrelType: 'named' },
|
|
21
21
|
group,
|
|
22
22
|
exclude = [],
|
|
23
23
|
include,
|
|
@@ -29,15 +29,11 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
29
29
|
query = {},
|
|
30
30
|
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
31
31
|
} = options
|
|
32
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
33
32
|
|
|
34
33
|
return {
|
|
35
34
|
name: pluginSvelteQueryName,
|
|
36
35
|
options: {
|
|
37
|
-
output
|
|
38
|
-
exportType: 'barrelNamed',
|
|
39
|
-
...output,
|
|
40
|
-
},
|
|
36
|
+
output,
|
|
41
37
|
baseURL: undefined,
|
|
42
38
|
client: {
|
|
43
39
|
importPath: '@kubb/plugin-client/client',
|
|
@@ -65,6 +61,12 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
65
61
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
66
62
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
67
63
|
|
|
64
|
+
if (options?.tag && group?.type === 'tag') {
|
|
65
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
66
|
+
|
|
67
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
68
|
+
}
|
|
69
|
+
|
|
68
70
|
if (mode === 'single') {
|
|
69
71
|
/**
|
|
70
72
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -73,12 +75,6 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
73
75
|
return path.resolve(root, output.path)
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
if (options?.tag && group?.type === 'tag') {
|
|
77
|
-
const tag = camelCase(options.tag)
|
|
78
|
-
|
|
79
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
78
|
return path.resolve(root, output.path, baseName)
|
|
83
79
|
},
|
|
84
80
|
resolveName(name, type) {
|
|
@@ -127,19 +123,18 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
127
123
|
const files = await operationGenerator.build(...generators)
|
|
128
124
|
await this.addFile(...files)
|
|
129
125
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
127
|
+
type: output.barrelType ?? 'named',
|
|
128
|
+
root,
|
|
129
|
+
output,
|
|
130
|
+
files: this.fileManager.files,
|
|
131
|
+
meta: {
|
|
132
|
+
pluginKey: this.plugin.key,
|
|
133
|
+
},
|
|
134
|
+
logger: this.logger,
|
|
135
|
+
})
|
|
140
136
|
|
|
141
|
-
|
|
142
|
-
}
|
|
137
|
+
await this.addFile(...barrelFiles)
|
|
143
138
|
},
|
|
144
139
|
}
|
|
145
140
|
})
|