@kubb/plugin-react-query 3.1.0 → 3.3.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-PBJIUPCN.cjs → chunk-4I6UYXEA.cjs} +33 -18
- package/dist/chunk-4I6UYXEA.cjs.map +1 -0
- package/dist/{chunk-YGWYQQ6H.js → chunk-JICGDXHM.js} +86 -55
- package/dist/chunk-JICGDXHM.js.map +1 -0
- package/dist/{chunk-GMONUHPD.js → chunk-QFITPKDT.js} +18 -3
- package/dist/chunk-QFITPKDT.js.map +1 -0
- package/dist/{chunk-WOYQTGDC.cjs → chunk-YNY2PBUX.cjs} +86 -55
- package/dist/chunk-YNY2PBUX.cjs.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +29 -15
- package/dist/components.d.ts +29 -15
- 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 +8 -6
- 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 +6 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-BBt81Oun.d.cts → types-DbdPn2MA.d.cts} +22 -2
- package/dist/{types-BBt81Oun.d.ts → types-DbdPn2MA.d.ts} +22 -2
- package/package.json +11 -11
- package/src/components/InfiniteQuery.tsx +9 -3
- package/src/components/InfiniteQueryOptions.tsx +25 -13
- package/src/components/Mutation.tsx +18 -4
- package/src/components/MutationKey.tsx +5 -4
- package/src/components/Query.tsx +9 -3
- package/src/components/QueryKey.tsx +9 -6
- package/src/components/QueryOptions.tsx +9 -5
- package/src/components/SuspenseQuery.tsx +9 -3
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +49 -34
- package/src/generators/__snapshots__/clientGetImportPath.ts +49 -34
- package/src/generators/__snapshots__/clientPostImportPath.ts +48 -34
- package/src/generators/__snapshots__/findByTags.ts +49 -34
- package/src/generators/__snapshots__/findByTagsObject.ts +55 -44
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +49 -34
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +49 -34
- package/src/generators/__snapshots__/findByTagsWithZod.ts +49 -34
- package/src/generators/__snapshots__/findInfiniteByTags.ts +60 -40
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +60 -40
- package/src/generators/__snapshots__/getAsMutation.ts +2 -2
- package/src/generators/__snapshots__/getPetIdCamelCase.ts +56 -0
- package/src/generators/__snapshots__/postAsQuery.ts +68 -38
- package/src/generators/__snapshots__/updatePetById.ts +48 -34
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +48 -36
- package/src/generators/infiniteQueryGenerator.tsx +4 -1
- package/src/generators/mutationGenerator.tsx +3 -0
- package/src/generators/queryGenerator.tsx +4 -0
- package/src/generators/suspenseQueryGenerator.tsx +4 -0
- package/src/plugin.ts +3 -1
- package/src/types.ts +7 -0
- package/dist/chunk-GMONUHPD.js.map +0 -1
- package/dist/chunk-PBJIUPCN.cjs.map +0 -1
- package/dist/chunk-WOYQTGDC.cjs.map +0 -1
- package/dist/chunk-YGWYQQ6H.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,I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AAA,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 paramsCasing,\n } = options\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/clients/axios',\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 query === false\n ? false\n : {\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 paramsCasing,\n group,\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?.group && group) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(root, output.path, groupName({ group: options.group }), 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 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"]}
|
|
@@ -33,7 +33,7 @@ type Options$1 = {
|
|
|
33
33
|
* Path to the client import path that will be used to do the API calls.
|
|
34
34
|
* It will be used as `import client from '${client.importPath}'`.
|
|
35
35
|
* It allows both relative and absolute path but be aware that we will not change the path.
|
|
36
|
-
* @default '@kubb/plugin-client/
|
|
36
|
+
* @default '@kubb/plugin-client/clients/axios'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
39
|
/**
|
|
@@ -47,6 +47,11 @@ type Options$1 = {
|
|
|
47
47
|
* @default 'data'
|
|
48
48
|
*/
|
|
49
49
|
dataReturnType?: 'data' | 'full';
|
|
50
|
+
/**
|
|
51
|
+
* How to style your params, by default no casing is applied
|
|
52
|
+
* - 'camelcase' will use camelcase for the params names
|
|
53
|
+
*/
|
|
54
|
+
paramsCasing?: 'camelcase';
|
|
50
55
|
/**
|
|
51
56
|
* How to pass your params
|
|
52
57
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -63,10 +68,17 @@ type Options$1 = {
|
|
|
63
68
|
pathParamsType?: 'object' | 'inline';
|
|
64
69
|
/**
|
|
65
70
|
* Which parser can be used before returning the data
|
|
66
|
-
* - 'zod'
|
|
71
|
+
* - 'zod' will use `@kubb/plugin-zod` to parse the data.
|
|
67
72
|
* @default 'client'
|
|
68
73
|
*/
|
|
69
74
|
parser?: 'client' | 'zod';
|
|
75
|
+
/**
|
|
76
|
+
* Which client should be used to do the HTTP calls
|
|
77
|
+
* - 'axios' will use `@kubb/plugin-client/clients/axios` to fetch data.
|
|
78
|
+
* - 'fetch' will use `@kubb/plugin-client/clients/fetch` to fetch data.
|
|
79
|
+
* @default 'axios'
|
|
80
|
+
*/
|
|
81
|
+
client?: 'axios' | 'fetch';
|
|
70
82
|
transformers?: {
|
|
71
83
|
/**
|
|
72
84
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -87,12 +99,14 @@ type ResolvedOptions$1 = {
|
|
|
87
99
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
88
100
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
89
101
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
102
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
90
103
|
};
|
|
91
104
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
92
105
|
|
|
93
106
|
type TransformerProps = {
|
|
94
107
|
operation: Operation;
|
|
95
108
|
schemas: OperationSchemas;
|
|
109
|
+
casing: 'camelcase' | undefined;
|
|
96
110
|
};
|
|
97
111
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
98
112
|
type Suspense = object;
|
|
@@ -173,6 +187,11 @@ type Options = {
|
|
|
173
187
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
174
188
|
*/
|
|
175
189
|
override?: Array<Override<ResolvedOptions>>;
|
|
190
|
+
/**
|
|
191
|
+
* How to style your params, by default no casing is applied
|
|
192
|
+
* - 'camelcase' will use camelcase for the params names
|
|
193
|
+
*/
|
|
194
|
+
paramsCasing?: 'camelcase';
|
|
176
195
|
/**
|
|
177
196
|
* How to pass your params
|
|
178
197
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -229,6 +248,7 @@ type ResolvedOptions = {
|
|
|
229
248
|
};
|
|
230
249
|
parser: Required<NonNullable<Options['parser']>>;
|
|
231
250
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
251
|
+
paramsCasing: Options['paramsCasing'];
|
|
232
252
|
paramsType: NonNullable<Options['paramsType']>;
|
|
233
253
|
/**
|
|
234
254
|
* Only used of infinite
|
|
@@ -33,7 +33,7 @@ type Options$1 = {
|
|
|
33
33
|
* Path to the client import path that will be used to do the API calls.
|
|
34
34
|
* It will be used as `import client from '${client.importPath}'`.
|
|
35
35
|
* It allows both relative and absolute path but be aware that we will not change the path.
|
|
36
|
-
* @default '@kubb/plugin-client/
|
|
36
|
+
* @default '@kubb/plugin-client/clients/axios'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
39
|
/**
|
|
@@ -47,6 +47,11 @@ type Options$1 = {
|
|
|
47
47
|
* @default 'data'
|
|
48
48
|
*/
|
|
49
49
|
dataReturnType?: 'data' | 'full';
|
|
50
|
+
/**
|
|
51
|
+
* How to style your params, by default no casing is applied
|
|
52
|
+
* - 'camelcase' will use camelcase for the params names
|
|
53
|
+
*/
|
|
54
|
+
paramsCasing?: 'camelcase';
|
|
50
55
|
/**
|
|
51
56
|
* How to pass your params
|
|
52
57
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -63,10 +68,17 @@ type Options$1 = {
|
|
|
63
68
|
pathParamsType?: 'object' | 'inline';
|
|
64
69
|
/**
|
|
65
70
|
* Which parser can be used before returning the data
|
|
66
|
-
* - 'zod'
|
|
71
|
+
* - 'zod' will use `@kubb/plugin-zod` to parse the data.
|
|
67
72
|
* @default 'client'
|
|
68
73
|
*/
|
|
69
74
|
parser?: 'client' | 'zod';
|
|
75
|
+
/**
|
|
76
|
+
* Which client should be used to do the HTTP calls
|
|
77
|
+
* - 'axios' will use `@kubb/plugin-client/clients/axios` to fetch data.
|
|
78
|
+
* - 'fetch' will use `@kubb/plugin-client/clients/fetch` to fetch data.
|
|
79
|
+
* @default 'axios'
|
|
80
|
+
*/
|
|
81
|
+
client?: 'axios' | 'fetch';
|
|
70
82
|
transformers?: {
|
|
71
83
|
/**
|
|
72
84
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -87,12 +99,14 @@ type ResolvedOptions$1 = {
|
|
|
87
99
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
88
100
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
89
101
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
102
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
90
103
|
};
|
|
91
104
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
92
105
|
|
|
93
106
|
type TransformerProps = {
|
|
94
107
|
operation: Operation;
|
|
95
108
|
schemas: OperationSchemas;
|
|
109
|
+
casing: 'camelcase' | undefined;
|
|
96
110
|
};
|
|
97
111
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
98
112
|
type Suspense = object;
|
|
@@ -173,6 +187,11 @@ type Options = {
|
|
|
173
187
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
174
188
|
*/
|
|
175
189
|
override?: Array<Override<ResolvedOptions>>;
|
|
190
|
+
/**
|
|
191
|
+
* How to style your params, by default no casing is applied
|
|
192
|
+
* - 'camelcase' will use camelcase for the params names
|
|
193
|
+
*/
|
|
194
|
+
paramsCasing?: 'camelcase';
|
|
176
195
|
/**
|
|
177
196
|
* How to pass your params
|
|
178
197
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -229,6 +248,7 @@ type ResolvedOptions = {
|
|
|
229
248
|
};
|
|
230
249
|
parser: Required<NonNullable<Options['parser']>>;
|
|
231
250
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
251
|
+
paramsCasing: Options['paramsCasing'];
|
|
232
252
|
paramsType: NonNullable<Options['paramsType']>;
|
|
233
253
|
/**
|
|
234
254
|
* Only used of infinite
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Generator react-query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -63,21 +63,21 @@
|
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"remeda": "^2.17.4",
|
|
66
|
-
"@kubb/core": "3.
|
|
67
|
-
"@kubb/fs": "3.
|
|
68
|
-
"@kubb/oas": "3.
|
|
69
|
-
"@kubb/plugin-oas": "3.
|
|
70
|
-
"@kubb/plugin-ts": "3.
|
|
71
|
-
"@kubb/plugin-zod": "3.
|
|
72
|
-
"@kubb/react": "3.
|
|
66
|
+
"@kubb/core": "3.3.0",
|
|
67
|
+
"@kubb/fs": "3.3.0",
|
|
68
|
+
"@kubb/oas": "3.3.0",
|
|
69
|
+
"@kubb/plugin-oas": "3.3.0",
|
|
70
|
+
"@kubb/plugin-ts": "3.3.0",
|
|
71
|
+
"@kubb/plugin-zod": "3.3.0",
|
|
72
|
+
"@kubb/react": "3.3.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@types/react": "^18.3.
|
|
75
|
+
"@types/react": "^18.3.16",
|
|
76
76
|
"react": "^18.3.1",
|
|
77
77
|
"tsup": "^8.3.5",
|
|
78
78
|
"typescript": "^5.7.2",
|
|
79
|
-
"@kubb/config-ts": "3.
|
|
80
|
-
"@kubb/config-tsup": "3.
|
|
79
|
+
"@kubb/config-ts": "3.3.0",
|
|
80
|
+
"@kubb/config-tsup": "3.3.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@kubb/react": "^3.0.0"
|
|
@@ -18,6 +18,7 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
21
22
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
23
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
24
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
@@ -25,12 +26,13 @@ type Props = {
|
|
|
25
26
|
|
|
26
27
|
type GetParamsProps = {
|
|
27
28
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
29
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
28
30
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
29
31
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
30
32
|
typeSchemas: OperationSchemas
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
35
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
34
36
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
35
37
|
|
|
36
38
|
if (paramsType === 'object') {
|
|
@@ -38,7 +40,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }:
|
|
|
38
40
|
data: {
|
|
39
41
|
mode: 'object',
|
|
40
42
|
children: {
|
|
41
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
43
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
42
44
|
data: typeSchemas.request?.name
|
|
43
45
|
? {
|
|
44
46
|
type: typeSchemas.request?.name,
|
|
@@ -75,7 +77,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }:
|
|
|
75
77
|
pathParams: typeSchemas.pathParams?.name
|
|
76
78
|
? {
|
|
77
79
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
80
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
79
81
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
80
82
|
}
|
|
81
83
|
: undefined,
|
|
@@ -115,6 +117,7 @@ export function InfiniteQuery({
|
|
|
115
117
|
queryOptionsName,
|
|
116
118
|
queryKeyName,
|
|
117
119
|
paramsType,
|
|
120
|
+
paramsCasing,
|
|
118
121
|
pathParamsType,
|
|
119
122
|
dataReturnType,
|
|
120
123
|
typeSchemas,
|
|
@@ -127,13 +130,16 @@ export function InfiniteQuery({
|
|
|
127
130
|
const queryKeyParams = QueryKey.getParams({
|
|
128
131
|
pathParamsType,
|
|
129
132
|
typeSchemas,
|
|
133
|
+
paramsCasing,
|
|
130
134
|
})
|
|
131
135
|
const queryOptionsParams = QueryOptions.getParams({
|
|
132
136
|
paramsType,
|
|
133
137
|
pathParamsType,
|
|
134
138
|
typeSchemas,
|
|
139
|
+
paramsCasing,
|
|
135
140
|
})
|
|
136
141
|
const params = getParams({
|
|
142
|
+
paramsCasing,
|
|
137
143
|
paramsType,
|
|
138
144
|
pathParamsType,
|
|
139
145
|
dataReturnType,
|
|
@@ -14,6 +14,7 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
17
18
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
18
19
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
19
20
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
@@ -23,18 +24,19 @@ type Props = {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
26
28
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
27
29
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
28
30
|
typeSchemas: OperationSchemas
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
32
34
|
if (paramsType === 'object') {
|
|
33
35
|
return FunctionParams.factory({
|
|
34
36
|
data: {
|
|
35
37
|
mode: 'object',
|
|
36
38
|
children: {
|
|
37
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
39
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
38
40
|
data: typeSchemas.request?.name
|
|
39
41
|
? {
|
|
40
42
|
type: typeSchemas.request?.name,
|
|
@@ -66,7 +68,7 @@ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps)
|
|
|
66
68
|
pathParams: typeSchemas.pathParams?.name
|
|
67
69
|
? {
|
|
68
70
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
69
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
71
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
70
72
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
71
73
|
}
|
|
72
74
|
: undefined,
|
|
@@ -101,14 +103,16 @@ export function InfiniteQueryOptions({
|
|
|
101
103
|
initialPageParam,
|
|
102
104
|
cursorParam,
|
|
103
105
|
typeSchemas,
|
|
106
|
+
paramsCasing,
|
|
104
107
|
paramsType,
|
|
105
108
|
dataReturnType,
|
|
106
109
|
pathParamsType,
|
|
107
110
|
queryParam,
|
|
108
111
|
queryKeyName,
|
|
109
112
|
}: Props): ReactNode {
|
|
110
|
-
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
113
|
+
const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
111
114
|
const clientParams = Client.getParams({
|
|
115
|
+
paramsCasing,
|
|
112
116
|
typeSchemas,
|
|
113
117
|
paramsType,
|
|
114
118
|
pathParamsType,
|
|
@@ -116,6 +120,7 @@ export function InfiniteQueryOptions({
|
|
|
116
120
|
const queryKeyParams = QueryKey.getParams({
|
|
117
121
|
pathParamsType,
|
|
118
122
|
typeSchemas,
|
|
123
|
+
paramsCasing,
|
|
119
124
|
})
|
|
120
125
|
|
|
121
126
|
const queryOptions = [
|
|
@@ -146,11 +151,11 @@ export function InfiniteQueryOptions({
|
|
|
146
151
|
|
|
147
152
|
const enabledText = enabled ? `enabled: !!(${enabled}),` : ''
|
|
148
153
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
<
|
|
152
|
-
{
|
|
153
|
-
`
|
|
154
|
+
if (infiniteOverrideParams) {
|
|
155
|
+
return (
|
|
156
|
+
<File.Source name={name} isExportable isIndexable>
|
|
157
|
+
<Function name={name} export params={params.toConstructor()}>
|
|
158
|
+
{`
|
|
154
159
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
155
160
|
return infiniteQueryOptions({
|
|
156
161
|
${enabledText}
|
|
@@ -163,17 +168,24 @@ export function InfiniteQueryOptions({
|
|
|
163
168
|
${queryOptions.join(',\n')}
|
|
164
169
|
})
|
|
165
170
|
`}
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
</Function>
|
|
172
|
+
</File.Source>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<File.Source name={name} isExportable isIndexable>
|
|
178
|
+
<Function name={name} export params={params.toConstructor()}>
|
|
179
|
+
{`
|
|
168
180
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
169
181
|
return infiniteQueryOptions({
|
|
170
|
-
${enabledText}
|
|
182
|
+
${enabledText}
|
|
171
183
|
queryKey,
|
|
172
184
|
queryFn: async ({ signal }) => {
|
|
173
185
|
config.signal = signal
|
|
174
186
|
return ${clientName}(${clientParams.toCall()})
|
|
175
187
|
},
|
|
176
|
-
${queryOptions.join('
|
|
188
|
+
${queryOptions.join(',\n')}
|
|
177
189
|
})
|
|
178
190
|
`}
|
|
179
191
|
</Function>
|
|
@@ -20,20 +20,22 @@ type Props = {
|
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
22
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
23
24
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
24
25
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type GetParamsProps = {
|
|
29
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
28
30
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
29
31
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
30
32
|
typeSchemas: OperationSchemas
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
35
|
+
function getParams({ paramsCasing, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
34
36
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
35
37
|
const mutationParams = FunctionParams.factory({
|
|
36
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
38
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
37
39
|
data: typeSchemas.request?.name
|
|
38
40
|
? {
|
|
39
41
|
type: typeSchemas.request?.name,
|
|
@@ -71,26 +73,38 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
71
73
|
})
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
export function Mutation({
|
|
76
|
+
export function Mutation({
|
|
77
|
+
name,
|
|
78
|
+
clientName,
|
|
79
|
+
paramsCasing,
|
|
80
|
+
paramsType,
|
|
81
|
+
pathParamsType,
|
|
82
|
+
dataReturnType,
|
|
83
|
+
typeSchemas,
|
|
84
|
+
operation,
|
|
85
|
+
mutationKeyName,
|
|
86
|
+
}: Props): ReactNode {
|
|
75
87
|
const mutationKeyParams = MutationKey.getParams({
|
|
76
88
|
pathParamsType,
|
|
77
89
|
typeSchemas,
|
|
78
90
|
})
|
|
79
91
|
|
|
80
92
|
const params = getParams({
|
|
93
|
+
paramsCasing,
|
|
81
94
|
pathParamsType,
|
|
82
95
|
dataReturnType,
|
|
83
96
|
typeSchemas,
|
|
84
97
|
})
|
|
85
98
|
|
|
86
99
|
const clientParams = Client.getParams({
|
|
100
|
+
paramsCasing,
|
|
87
101
|
paramsType,
|
|
88
102
|
typeSchemas,
|
|
89
103
|
pathParamsType,
|
|
90
104
|
})
|
|
91
105
|
|
|
92
106
|
const mutationParams = FunctionParams.factory({
|
|
93
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
107
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
94
108
|
data: typeSchemas.request?.name
|
|
95
109
|
? {
|
|
96
110
|
type: typeSchemas.request?.name,
|
|
@@ -11,6 +11,7 @@ type Props = {
|
|
|
11
11
|
typeName: string
|
|
12
12
|
typeSchemas: OperationSchemas
|
|
13
13
|
operation: Operation
|
|
14
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
14
15
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
15
16
|
transformer: Transformer | undefined
|
|
16
17
|
}
|
|
@@ -24,15 +25,15 @@ function getParams({}: GetParamsProps) {
|
|
|
24
25
|
return FunctionParams.factory({})
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const getTransformer: Transformer = ({ operation }) => {
|
|
28
|
-
const path = new URLPath(operation.path)
|
|
28
|
+
const getTransformer: Transformer = ({ operation, casing }) => {
|
|
29
|
+
const path = new URLPath(operation.path, { casing })
|
|
29
30
|
|
|
30
31
|
return [JSON.stringify({ url: path.path })].filter(Boolean)
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
|
+
export function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
35
|
const params = getParams({ pathParamsType, typeSchemas })
|
|
35
|
-
const keys = transformer({ operation, schemas: typeSchemas })
|
|
36
|
+
const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing })
|
|
36
37
|
|
|
37
38
|
return (
|
|
38
39
|
<>
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,19 +18,21 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
21
22
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
23
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
23
24
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type GetParamsProps = {
|
|
28
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
27
29
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
28
30
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
29
31
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
30
32
|
typeSchemas: OperationSchemas
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
35
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
34
36
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
35
37
|
|
|
36
38
|
if (paramsType === 'object') {
|
|
@@ -38,7 +40,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }:
|
|
|
38
40
|
data: {
|
|
39
41
|
mode: 'object',
|
|
40
42
|
children: {
|
|
41
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
43
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
42
44
|
data: typeSchemas.request?.name
|
|
43
45
|
? {
|
|
44
46
|
type: typeSchemas.request?.name,
|
|
@@ -75,7 +77,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }:
|
|
|
75
77
|
pathParams: typeSchemas.pathParams?.name
|
|
76
78
|
? {
|
|
77
79
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
80
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
79
81
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
80
82
|
}
|
|
81
83
|
: undefined,
|
|
@@ -115,6 +117,7 @@ export function Query({
|
|
|
115
117
|
queryOptionsName,
|
|
116
118
|
queryKeyName,
|
|
117
119
|
paramsType,
|
|
120
|
+
paramsCasing,
|
|
118
121
|
pathParamsType,
|
|
119
122
|
dataReturnType,
|
|
120
123
|
typeSchemas,
|
|
@@ -127,13 +130,16 @@ export function Query({
|
|
|
127
130
|
const queryKeyParams = QueryKey.getParams({
|
|
128
131
|
pathParamsType,
|
|
129
132
|
typeSchemas,
|
|
133
|
+
paramsCasing,
|
|
130
134
|
})
|
|
131
135
|
const queryOptionsParams = QueryOptions.getParams({
|
|
132
136
|
paramsType,
|
|
133
137
|
pathParamsType,
|
|
134
138
|
typeSchemas,
|
|
139
|
+
paramsCasing,
|
|
135
140
|
})
|
|
136
141
|
const params = getParams({
|
|
142
|
+
paramsCasing,
|
|
137
143
|
paramsType,
|
|
138
144
|
pathParamsType,
|
|
139
145
|
dataReturnType,
|
|
@@ -12,20 +12,22 @@ type Props = {
|
|
|
12
12
|
typeName: string
|
|
13
13
|
typeSchemas: OperationSchemas
|
|
14
14
|
operation: Operation
|
|
15
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
15
16
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
16
17
|
transformer: Transformer | undefined
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
type GetParamsProps = {
|
|
21
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
20
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
21
23
|
typeSchemas: OperationSchemas
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
26
|
+
function getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {
|
|
25
27
|
return FunctionParams.factory({
|
|
26
28
|
pathParams: {
|
|
27
29
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
28
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
30
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
29
31
|
},
|
|
30
32
|
data: typeSchemas.request?.name
|
|
31
33
|
? {
|
|
@@ -42,8 +44,8 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
42
44
|
})
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
46
|
-
const path = new URLPath(operation.path)
|
|
47
|
+
const getTransformer: Transformer = ({ operation, schemas, casing }) => {
|
|
48
|
+
const path = new URLPath(operation.path, { casing })
|
|
47
49
|
const keys = [
|
|
48
50
|
path.toObject({
|
|
49
51
|
type: 'path',
|
|
@@ -56,11 +58,12 @@ const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
|
56
58
|
return keys
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
60
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
61
|
+
export function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
62
|
+
const params = getParams({ pathParamsType, typeSchemas, paramsCasing })
|
|
61
63
|
const keys = transformer({
|
|
62
64
|
operation,
|
|
63
65
|
schemas: typeSchemas,
|
|
66
|
+
casing: paramsCasing,
|
|
64
67
|
})
|
|
65
68
|
|
|
66
69
|
return (
|