@kubb/plugin-react-query 3.0.0-beta.8 → 3.0.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.
- package/dist/{chunk-C2H3KPHM.cjs → chunk-EOG7AHFO.cjs} +276 -44
- package/dist/chunk-EOG7AHFO.cjs.map +1 -0
- package/dist/{chunk-Y3DM2P6L.js → chunk-EY5KE7R7.js} +276 -44
- package/dist/chunk-EY5KE7R7.js.map +1 -0
- package/dist/{chunk-3U5EOLDD.cjs → chunk-NBC6BPMV.cjs} +141 -110
- package/dist/chunk-NBC6BPMV.cjs.map +1 -0
- package/dist/{chunk-ES4YRHDI.js → chunk-NZKAIPYC.js} +130 -99
- package/dist/chunk-NZKAIPYC.js.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +29 -16
- package/dist/components.d.ts +29 -16
- package/dist/components.js +1 -1
- package/dist/generators.cjs +6 -6
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +24 -24
- 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 +23 -23
- package/dist/index.js.map +1 -1
- package/dist/{types-LhwfnVo7.d.cts → types-IuxCCG1K.d.cts} +46 -16
- package/dist/{types-LhwfnVo7.d.ts → types-IuxCCG1K.d.ts} +46 -16
- package/package.json +13 -13
- package/src/components/InfiniteQuery.tsx +52 -5
- package/src/components/InfiniteQueryOptions.tsx +62 -7
- package/src/components/Mutation.tsx +9 -3
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryKey.tsx +17 -7
- package/src/components/QueryOptions.tsx +47 -7
- package/src/components/SuspenseQuery.tsx +52 -5
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTags.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +1 -1
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/infiniteQueryGenerator.tsx +40 -28
- package/src/generators/mutationGenerator.tsx +25 -16
- package/src/generators/queryGenerator.tsx +24 -17
- package/src/generators/suspenseQueryGenerator.tsx +26 -16
- package/src/plugin.ts +23 -20
- package/src/types.ts +35 -15
- package/dist/chunk-3U5EOLDD.cjs.map +0 -1
- package/dist/chunk-C2H3KPHM.cjs.map +0 -1
- package/dist/chunk-ES4YRHDI.js.map +0 -1
- package/dist/chunk-Y3DM2P6L.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkNBC6BPMV_cjs = require('./chunk-NBC6BPMV.cjs');
|
|
4
|
+
var chunkEOG7AHFO_cjs = require('./chunk-EOG7AHFO.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
@@ -25,16 +25,18 @@ var pluginReactQuery = core.createPlugin((options) => {
|
|
|
25
25
|
suspense = {},
|
|
26
26
|
infinite = false,
|
|
27
27
|
transformers: transformers$1 = {},
|
|
28
|
+
paramsType = "inline",
|
|
28
29
|
pathParamsType = "inline",
|
|
29
|
-
generators = [
|
|
30
|
+
generators = [chunkNBC6BPMV_cjs.queryGenerator, chunkNBC6BPMV_cjs.suspenseQueryGenerator, chunkNBC6BPMV_cjs.infiniteQueryGenerator, chunkNBC6BPMV_cjs.mutationGenerator].filter(Boolean),
|
|
30
31
|
mutation = {},
|
|
31
|
-
query = {}
|
|
32
|
+
query = {},
|
|
33
|
+
mutationKey = chunkEOG7AHFO_cjs.MutationKey.getTransformer,
|
|
34
|
+
queryKey = chunkEOG7AHFO_cjs.QueryKey.getTransformer
|
|
32
35
|
} = options;
|
|
33
36
|
return {
|
|
34
37
|
name: pluginReactQueryName,
|
|
35
38
|
options: {
|
|
36
39
|
output,
|
|
37
|
-
baseURL: void 0,
|
|
38
40
|
client: {
|
|
39
41
|
importPath: "@kubb/plugin-client/client",
|
|
40
42
|
dataReturnType: "data",
|
|
@@ -47,19 +49,20 @@ var pluginReactQuery = core.createPlugin((options) => {
|
|
|
47
49
|
...infinite
|
|
48
50
|
} : false,
|
|
49
51
|
suspense,
|
|
52
|
+
queryKey,
|
|
50
53
|
query: {
|
|
51
|
-
key: (key) => key,
|
|
52
54
|
methods: ["get"],
|
|
53
55
|
importPath: "@tanstack/react-query",
|
|
54
56
|
...query
|
|
55
57
|
},
|
|
58
|
+
mutationKey,
|
|
56
59
|
mutation: {
|
|
57
|
-
key: (key) => key,
|
|
58
60
|
methods: ["post", "put", "patch", "delete"],
|
|
59
61
|
importPath: "@tanstack/react-query",
|
|
60
62
|
...mutation
|
|
61
63
|
},
|
|
62
|
-
|
|
64
|
+
paramsType,
|
|
65
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType,
|
|
63
66
|
parser
|
|
64
67
|
},
|
|
65
68
|
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
|
|
@@ -96,22 +99,19 @@ var pluginReactQuery = core.createPlugin((options) => {
|
|
|
96
99
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
97
100
|
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
98
101
|
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
mode
|
|
113
|
-
}
|
|
114
|
-
);
|
|
102
|
+
if (baseURL) {
|
|
103
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
104
|
+
}
|
|
105
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
106
|
+
oas,
|
|
107
|
+
pluginManager: this.pluginManager,
|
|
108
|
+
plugin: this.plugin,
|
|
109
|
+
contentType: swaggerPlugin.context.contentType,
|
|
110
|
+
exclude,
|
|
111
|
+
include,
|
|
112
|
+
override,
|
|
113
|
+
mode
|
|
114
|
+
});
|
|
115
115
|
const files = await operationGenerator.build(...generators);
|
|
116
116
|
await this.addFile(...files);
|
|
117
117
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","MutationKey","QueryKey","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAgBO,IAAM,oBAAuB,GAAA;AAEvB,IAAA,gBAAA,GAAmBA,iBAA+B,CAAA,CAAC,OAAY,KAAA;AAC1E,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,O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AK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,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;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query: {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation: {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : 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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\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(...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,5 +1,5 @@
|
|
|
1
|
-
import { queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
import { queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator } from './chunk-NZKAIPYC.js';
|
|
2
|
+
import { MutationKey, QueryKey } from './chunk-EY5KE7R7.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';
|
|
@@ -19,16 +19,18 @@ var pluginReactQuery = createPlugin((options) => {
|
|
|
19
19
|
suspense = {},
|
|
20
20
|
infinite = false,
|
|
21
21
|
transformers = {},
|
|
22
|
+
paramsType = "inline",
|
|
22
23
|
pathParamsType = "inline",
|
|
23
24
|
generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
|
|
24
25
|
mutation = {},
|
|
25
|
-
query = {}
|
|
26
|
+
query = {},
|
|
27
|
+
mutationKey = MutationKey.getTransformer,
|
|
28
|
+
queryKey = QueryKey.getTransformer
|
|
26
29
|
} = options;
|
|
27
30
|
return {
|
|
28
31
|
name: pluginReactQueryName,
|
|
29
32
|
options: {
|
|
30
33
|
output,
|
|
31
|
-
baseURL: void 0,
|
|
32
34
|
client: {
|
|
33
35
|
importPath: "@kubb/plugin-client/client",
|
|
34
36
|
dataReturnType: "data",
|
|
@@ -41,19 +43,20 @@ var pluginReactQuery = createPlugin((options) => {
|
|
|
41
43
|
...infinite
|
|
42
44
|
} : false,
|
|
43
45
|
suspense,
|
|
46
|
+
queryKey,
|
|
44
47
|
query: {
|
|
45
|
-
key: (key) => key,
|
|
46
48
|
methods: ["get"],
|
|
47
49
|
importPath: "@tanstack/react-query",
|
|
48
50
|
...query
|
|
49
51
|
},
|
|
52
|
+
mutationKey,
|
|
50
53
|
mutation: {
|
|
51
|
-
key: (key) => key,
|
|
52
54
|
methods: ["post", "put", "patch", "delete"],
|
|
53
55
|
importPath: "@tanstack/react-query",
|
|
54
56
|
...mutation
|
|
55
57
|
},
|
|
56
|
-
|
|
58
|
+
paramsType,
|
|
59
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType,
|
|
57
60
|
parser
|
|
58
61
|
},
|
|
59
62
|
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
@@ -90,22 +93,19 @@ var pluginReactQuery = createPlugin((options) => {
|
|
|
90
93
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
91
94
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
92
95
|
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
mode
|
|
107
|
-
}
|
|
108
|
-
);
|
|
96
|
+
if (baseURL) {
|
|
97
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
98
|
+
}
|
|
99
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
100
|
+
oas,
|
|
101
|
+
pluginManager: this.pluginManager,
|
|
102
|
+
plugin: this.plugin,
|
|
103
|
+
contentType: swaggerPlugin.context.contentType,
|
|
104
|
+
exclude,
|
|
105
|
+
include,
|
|
106
|
+
override,
|
|
107
|
+
mode
|
|
108
|
+
});
|
|
109
109
|
const files = await operationGenerator.build(...generators);
|
|
110
110
|
await this.addFile(...files);
|
|
111
111
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAgBO,IAAM,oBAAuB,GAAA;AAEvB,IAAA,gBAAA,GAAmB,YAA+B,CAAA,CAAC,OAAY,KAAA;AAC1E,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,IACT,WAAW,EAAC;AAAA,IACZ,QAAW,GAAA,KAAA;AAAA,IACX,eAAe,EAAC;AAAA,IAChB,UAAa,GAAA,QAAA;AAAA,IACb,cAAiB,GAAA,QAAA;AAAA,IACjB,UAAA,GAAa,CAAC,cAAgB,EAAA,sBAAA,EAAwB,wBAAwB,iBAAiB,CAAA,CAAE,OAAO,OAAO,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AA,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;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { MutationKey } from './components'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite = false,\n transformers = {},\n paramsType = 'inline',\n pathParamsType = 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n queryKey,\n query: {\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutationKey,\n mutation: {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : 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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\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(...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,6 +1,6 @@
|
|
|
1
1
|
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
-
import { HttpMethod } from '@kubb/oas';
|
|
3
|
-
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
2
|
+
import { Operation, HttpMethod } from '@kubb/oas';
|
|
3
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
5
5
|
type Options$1 = {
|
|
6
6
|
/**
|
|
@@ -36,6 +36,10 @@ type Options$1 = {
|
|
|
36
36
|
* @default '@kubb/plugin-client/client'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Allows you to set a custom base url for all generated calls.
|
|
41
|
+
*/
|
|
42
|
+
baseURL?: string;
|
|
39
43
|
/**
|
|
40
44
|
* ReturnType that will be used when calling the client.
|
|
41
45
|
* - 'data' will return ResponseConfig[data].
|
|
@@ -43,6 +47,13 @@ type Options$1 = {
|
|
|
43
47
|
* @default 'data'
|
|
44
48
|
*/
|
|
45
49
|
dataReturnType?: 'data' | 'full';
|
|
50
|
+
/**
|
|
51
|
+
* How to pass your params
|
|
52
|
+
* - 'object' will return the params and pathParams as an object.
|
|
53
|
+
* - 'inline' will return the params as comma separated params.
|
|
54
|
+
* @default 'inline'
|
|
55
|
+
*/
|
|
56
|
+
paramsType?: 'object' | 'inline';
|
|
46
57
|
/**
|
|
47
58
|
* How to pass your pathParams.
|
|
48
59
|
* - 'object' will return the pathParams as an object.
|
|
@@ -75,15 +86,25 @@ type ResolvedOptions$1 = {
|
|
|
75
86
|
importPath: NonNullable<Options$1['importPath']>;
|
|
76
87
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
77
88
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
89
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
78
90
|
};
|
|
79
91
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
80
92
|
|
|
93
|
+
type TransformerProps = {
|
|
94
|
+
operation: Operation;
|
|
95
|
+
schemas: OperationSchemas;
|
|
96
|
+
};
|
|
97
|
+
type Transformer = (props: TransformerProps) => unknown[];
|
|
81
98
|
type Suspense = object;
|
|
99
|
+
/**
|
|
100
|
+
* Customize the queryKey
|
|
101
|
+
*/
|
|
102
|
+
type QueryKey = Transformer;
|
|
103
|
+
/**
|
|
104
|
+
* Customize the mutationKey
|
|
105
|
+
*/
|
|
106
|
+
type MutationKey = Transformer;
|
|
82
107
|
type Query = {
|
|
83
|
-
/**
|
|
84
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
85
|
-
*/
|
|
86
|
-
key: (key: unknown[]) => unknown[];
|
|
87
108
|
/**
|
|
88
109
|
* Define which HttpMethods can be used for queries
|
|
89
110
|
* @default ['get']
|
|
@@ -99,10 +120,6 @@ type Query = {
|
|
|
99
120
|
importPath?: string;
|
|
100
121
|
};
|
|
101
122
|
type Mutation = {
|
|
102
|
-
/**
|
|
103
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
104
|
-
*/
|
|
105
|
-
key: (key: unknown[]) => unknown[];
|
|
106
123
|
/**
|
|
107
124
|
* Define which HttpMethods can be used for mutations
|
|
108
125
|
* @default ['post', 'put', 'delete']
|
|
@@ -143,7 +160,7 @@ type Options = {
|
|
|
143
160
|
* Group the @tanstack/query hooks based on the provided name.
|
|
144
161
|
*/
|
|
145
162
|
group?: Group;
|
|
146
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
|
|
163
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
147
164
|
/**
|
|
148
165
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
149
166
|
*/
|
|
@@ -156,6 +173,13 @@ type Options = {
|
|
|
156
173
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
157
174
|
*/
|
|
158
175
|
override?: Array<Override<ResolvedOptions>>;
|
|
176
|
+
/**
|
|
177
|
+
* How to pass your params
|
|
178
|
+
* - 'object' will return the params and pathParams as an object.
|
|
179
|
+
* - 'inline' will return the params as comma separated params.
|
|
180
|
+
* @default 'inline'
|
|
181
|
+
*/
|
|
182
|
+
paramsType?: 'object' | 'inline';
|
|
159
183
|
/**
|
|
160
184
|
* How to pass your pathParams.
|
|
161
185
|
* - 'object' will return the pathParams as an object.
|
|
@@ -171,16 +195,18 @@ type Options = {
|
|
|
171
195
|
* When set, a suspenseQuery hooks will be added.
|
|
172
196
|
*/
|
|
173
197
|
suspense?: Partial<Suspense> | false;
|
|
198
|
+
queryKey?: QueryKey;
|
|
174
199
|
/**
|
|
175
200
|
* Override some useQuery behaviours.
|
|
176
201
|
*/
|
|
177
202
|
query?: Partial<Query> | false;
|
|
203
|
+
mutationKey?: MutationKey;
|
|
178
204
|
/**
|
|
179
205
|
* Override some useMutation behaviours.
|
|
180
206
|
*/
|
|
181
|
-
mutation?: Mutation | false;
|
|
207
|
+
mutation?: Partial<Mutation> | false;
|
|
182
208
|
/**
|
|
183
|
-
* Which parser
|
|
209
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
184
210
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
185
211
|
*/
|
|
186
212
|
parser?: PluginClient['options']['parser'];
|
|
@@ -197,18 +223,22 @@ type Options = {
|
|
|
197
223
|
};
|
|
198
224
|
type ResolvedOptions = {
|
|
199
225
|
output: Output;
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
227
|
+
baseURL?: string;
|
|
228
|
+
};
|
|
202
229
|
parser: Required<NonNullable<Options['parser']>>;
|
|
203
230
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
231
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
204
232
|
/**
|
|
205
233
|
* Only used of infinite
|
|
206
234
|
*/
|
|
207
235
|
infinite: NonNullable<Infinite> | false;
|
|
208
236
|
suspense: Suspense | false;
|
|
237
|
+
queryKey: QueryKey | undefined;
|
|
209
238
|
query: NonNullable<Required<Query>> | false;
|
|
239
|
+
mutationKey: MutationKey | undefined;
|
|
210
240
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
211
241
|
};
|
|
212
242
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
213
243
|
|
|
214
|
-
export type { Infinite as I, Options as O, PluginReactQuery as P };
|
|
244
|
+
export type { Infinite as I, Options as O, PluginReactQuery as P, Transformer as T };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
-
import { HttpMethod } from '@kubb/oas';
|
|
3
|
-
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
2
|
+
import { Operation, HttpMethod } from '@kubb/oas';
|
|
3
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
5
5
|
type Options$1 = {
|
|
6
6
|
/**
|
|
@@ -36,6 +36,10 @@ type Options$1 = {
|
|
|
36
36
|
* @default '@kubb/plugin-client/client'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Allows you to set a custom base url for all generated calls.
|
|
41
|
+
*/
|
|
42
|
+
baseURL?: string;
|
|
39
43
|
/**
|
|
40
44
|
* ReturnType that will be used when calling the client.
|
|
41
45
|
* - 'data' will return ResponseConfig[data].
|
|
@@ -43,6 +47,13 @@ type Options$1 = {
|
|
|
43
47
|
* @default 'data'
|
|
44
48
|
*/
|
|
45
49
|
dataReturnType?: 'data' | 'full';
|
|
50
|
+
/**
|
|
51
|
+
* How to pass your params
|
|
52
|
+
* - 'object' will return the params and pathParams as an object.
|
|
53
|
+
* - 'inline' will return the params as comma separated params.
|
|
54
|
+
* @default 'inline'
|
|
55
|
+
*/
|
|
56
|
+
paramsType?: 'object' | 'inline';
|
|
46
57
|
/**
|
|
47
58
|
* How to pass your pathParams.
|
|
48
59
|
* - 'object' will return the pathParams as an object.
|
|
@@ -75,15 +86,25 @@ type ResolvedOptions$1 = {
|
|
|
75
86
|
importPath: NonNullable<Options$1['importPath']>;
|
|
76
87
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
77
88
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
89
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
78
90
|
};
|
|
79
91
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
80
92
|
|
|
93
|
+
type TransformerProps = {
|
|
94
|
+
operation: Operation;
|
|
95
|
+
schemas: OperationSchemas;
|
|
96
|
+
};
|
|
97
|
+
type Transformer = (props: TransformerProps) => unknown[];
|
|
81
98
|
type Suspense = object;
|
|
99
|
+
/**
|
|
100
|
+
* Customize the queryKey
|
|
101
|
+
*/
|
|
102
|
+
type QueryKey = Transformer;
|
|
103
|
+
/**
|
|
104
|
+
* Customize the mutationKey
|
|
105
|
+
*/
|
|
106
|
+
type MutationKey = Transformer;
|
|
82
107
|
type Query = {
|
|
83
|
-
/**
|
|
84
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
85
|
-
*/
|
|
86
|
-
key: (key: unknown[]) => unknown[];
|
|
87
108
|
/**
|
|
88
109
|
* Define which HttpMethods can be used for queries
|
|
89
110
|
* @default ['get']
|
|
@@ -99,10 +120,6 @@ type Query = {
|
|
|
99
120
|
importPath?: string;
|
|
100
121
|
};
|
|
101
122
|
type Mutation = {
|
|
102
|
-
/**
|
|
103
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
104
|
-
*/
|
|
105
|
-
key: (key: unknown[]) => unknown[];
|
|
106
123
|
/**
|
|
107
124
|
* Define which HttpMethods can be used for mutations
|
|
108
125
|
* @default ['post', 'put', 'delete']
|
|
@@ -143,7 +160,7 @@ type Options = {
|
|
|
143
160
|
* Group the @tanstack/query hooks based on the provided name.
|
|
144
161
|
*/
|
|
145
162
|
group?: Group;
|
|
146
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
|
|
163
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
147
164
|
/**
|
|
148
165
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
149
166
|
*/
|
|
@@ -156,6 +173,13 @@ type Options = {
|
|
|
156
173
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
157
174
|
*/
|
|
158
175
|
override?: Array<Override<ResolvedOptions>>;
|
|
176
|
+
/**
|
|
177
|
+
* How to pass your params
|
|
178
|
+
* - 'object' will return the params and pathParams as an object.
|
|
179
|
+
* - 'inline' will return the params as comma separated params.
|
|
180
|
+
* @default 'inline'
|
|
181
|
+
*/
|
|
182
|
+
paramsType?: 'object' | 'inline';
|
|
159
183
|
/**
|
|
160
184
|
* How to pass your pathParams.
|
|
161
185
|
* - 'object' will return the pathParams as an object.
|
|
@@ -171,16 +195,18 @@ type Options = {
|
|
|
171
195
|
* When set, a suspenseQuery hooks will be added.
|
|
172
196
|
*/
|
|
173
197
|
suspense?: Partial<Suspense> | false;
|
|
198
|
+
queryKey?: QueryKey;
|
|
174
199
|
/**
|
|
175
200
|
* Override some useQuery behaviours.
|
|
176
201
|
*/
|
|
177
202
|
query?: Partial<Query> | false;
|
|
203
|
+
mutationKey?: MutationKey;
|
|
178
204
|
/**
|
|
179
205
|
* Override some useMutation behaviours.
|
|
180
206
|
*/
|
|
181
|
-
mutation?: Mutation | false;
|
|
207
|
+
mutation?: Partial<Mutation> | false;
|
|
182
208
|
/**
|
|
183
|
-
* Which parser
|
|
209
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
184
210
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
185
211
|
*/
|
|
186
212
|
parser?: PluginClient['options']['parser'];
|
|
@@ -197,18 +223,22 @@ type Options = {
|
|
|
197
223
|
};
|
|
198
224
|
type ResolvedOptions = {
|
|
199
225
|
output: Output;
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
227
|
+
baseURL?: string;
|
|
228
|
+
};
|
|
202
229
|
parser: Required<NonNullable<Options['parser']>>;
|
|
203
230
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
231
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
204
232
|
/**
|
|
205
233
|
* Only used of infinite
|
|
206
234
|
*/
|
|
207
235
|
infinite: NonNullable<Infinite> | false;
|
|
208
236
|
suspense: Suspense | false;
|
|
237
|
+
queryKey: QueryKey | undefined;
|
|
209
238
|
query: NonNullable<Required<Query>> | false;
|
|
239
|
+
mutationKey: MutationKey | undefined;
|
|
210
240
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
211
241
|
};
|
|
212
242
|
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
213
243
|
|
|
214
|
-
export type { Infinite as I, Options as O, PluginReactQuery as P };
|
|
244
|
+
export type { Infinite as I, Options as O, PluginReactQuery as P, Transformer as T };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Generator react-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
|
|
66
|
-
"@kubb/fs": "3.0.0
|
|
67
|
-
"@kubb/oas": "3.0.0
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0
|
|
70
|
-
"@kubb/plugin-zod": "3.0.0
|
|
71
|
-
"@kubb/react": "3.0.0
|
|
65
|
+
"@kubb/core": "3.0.0",
|
|
66
|
+
"@kubb/fs": "3.0.0",
|
|
67
|
+
"@kubb/oas": "3.0.0",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0",
|
|
71
|
+
"@kubb/react": "3.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/react": "^18.3.
|
|
74
|
+
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
|
-
"tsup": "^8.3.
|
|
76
|
+
"tsup": "^8.3.5",
|
|
77
77
|
"typescript": "^5.6.3",
|
|
78
|
-
"@kubb/config-ts": "3.0.0
|
|
79
|
-
"@kubb/config-tsup": "3.0.0
|
|
78
|
+
"@kubb/config-ts": "3.0.0",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0
|
|
82
|
+
"@kubb/react": "3.0.0"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|