@toktokhan-dev/cli-plugin-gen-api-react-query 0.0.9 → 0.0.11
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/index.d.ts +1 -1
- package/dist/index.doc.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/templates/custom-axios/api.eta +5 -5
- package/templates/custom-axios/procedure-call.eta +2 -2
- package/templates/custom-fetch/api.eta +3 -3
- package/templates/custom-fetch/procedure-call.eta +2 -2
- package/templates/my/react-query-hook.eta +2 -2
- package/templates/my/react-query-key.eta +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.doc.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -158,7 +158,7 @@ const genApi = defineCommand({
|
|
|
158
158
|
includeReactInfiniteQuery: true,
|
|
159
159
|
httpClientType: 'axios',
|
|
160
160
|
instancePath: GENERATE_SWAGGER_DATA.AXIOS_DEFAULT_INSTANCE_PATH,
|
|
161
|
-
|
|
161
|
+
paginationSets: [
|
|
162
162
|
{
|
|
163
163
|
keywords: ['cursor'],
|
|
164
164
|
nextKey: 'cursor',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toktokhan-dev/cli-plugin-gen-api-react-query",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
28
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
29
29
|
"swagger-typescript-api": "^13.0.3",
|
|
30
|
-
"@toktokhan-dev/
|
|
31
|
-
"@toktokhan-dev/
|
|
30
|
+
"@toktokhan-dev/node": "0.0.5",
|
|
31
|
+
"@toktokhan-dev/cli": "0.0.6"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rollup -c",
|
|
@@ -13,7 +13,7 @@ const reactQueryTemplatePath = `${myTemeplatePath}/react-query-hook.eta`
|
|
|
13
13
|
const reactQuerKeyTemplatePath = `${myTemeplatePath}/react-query-key.eta`
|
|
14
14
|
|
|
15
15
|
const apiClassName = classNameCase(route.moduleName) + 'Api';
|
|
16
|
-
const
|
|
16
|
+
const paginationSets = myConfig?.paginationSets
|
|
17
17
|
const instancePath = myConfig?.instancePath
|
|
18
18
|
|
|
19
19
|
const apiInstanceName =route.moduleName + "Api";
|
|
@@ -78,17 +78,17 @@ const getConfigByRoute = (route) => {
|
|
|
78
78
|
const hookVariant = _.upperCase(method) === "GET" ? "Query" : "Mutation"
|
|
79
79
|
const key = upperSnakeCase(functionName);
|
|
80
80
|
const methodKey = upperSnakeCase(removeModuleName(functionName));
|
|
81
|
-
const pagination =
|
|
81
|
+
const pagination = paginationSets.find(d => !!query?.type && hasPaginationKeyword(query?.type.split("\n").join(""), d.keywords));
|
|
82
82
|
|
|
83
83
|
const isQuery = hookVariant === "Query";
|
|
84
84
|
const isMutation = hookVariant === "Mutation";
|
|
85
85
|
const hasPagination = !!pagination;
|
|
86
86
|
|
|
87
|
-
const
|
|
87
|
+
const isOptionalVariables = _
|
|
88
88
|
// Find optional value
|
|
89
89
|
.filter(rawWrapperArgs, o => o.optional).length === rawWrapperArgs.length;
|
|
90
90
|
|
|
91
|
-
const conditionalVriablesText =
|
|
91
|
+
const conditionalVriablesText = isOptionalVariables? "variables?" : "variables";
|
|
92
92
|
const repalceTarget = "${" + conditionalVriablesText + ".";
|
|
93
93
|
|
|
94
94
|
|
|
@@ -97,7 +97,7 @@ const getConfigByRoute = (route) => {
|
|
|
97
97
|
hasPagination,
|
|
98
98
|
isQuery,
|
|
99
99
|
isMutation,
|
|
100
|
-
|
|
100
|
+
isOptionalVariables,
|
|
101
101
|
},
|
|
102
102
|
data: {
|
|
103
103
|
rawWrapperArgs,
|
|
@@ -48,11 +48,11 @@ const wrapperArgs = _
|
|
|
48
48
|
.map(argToTmpl)
|
|
49
49
|
.join('; ');
|
|
50
50
|
|
|
51
|
-
const
|
|
51
|
+
const isOptionalVariables = _
|
|
52
52
|
// Find optional value
|
|
53
53
|
.filter(rawWrapperArgs, o => o.optional).length === rawWrapperArgs.length;
|
|
54
54
|
|
|
55
|
-
const conditionalVriablesText =
|
|
55
|
+
const conditionalVriablesText = isOptionalVariables? "variables?" : "variables";
|
|
56
56
|
const repalceTarget = "${" + conditionalVriablesText + ".";
|
|
57
57
|
const pathWithVariables = path.replace(/\$\{/g, repalceTarget);
|
|
58
58
|
|
|
@@ -80,11 +80,11 @@ const getConfigByRoute = (route) => {
|
|
|
80
80
|
const isMutation = hookVariant === "Mutation";
|
|
81
81
|
const hasPagination = !!pagination;
|
|
82
82
|
|
|
83
|
-
const
|
|
83
|
+
const isOptionalVariables = _
|
|
84
84
|
// Find optional value
|
|
85
85
|
.filter(rawWrapperArgs, o => o.optional).length === rawWrapperArgs.length;
|
|
86
86
|
|
|
87
|
-
const conditionalVriablesText =
|
|
87
|
+
const conditionalVriablesText = isOptionalVariables ? "variables?" : "variables";
|
|
88
88
|
const repalceTarget = "${" + conditionalVriablesText + ".";
|
|
89
89
|
|
|
90
90
|
return {
|
|
@@ -92,7 +92,7 @@ const getConfigByRoute = (route) => {
|
|
|
92
92
|
hasPagination,
|
|
93
93
|
isQuery,
|
|
94
94
|
isMutation,
|
|
95
|
-
|
|
95
|
+
isOptionalVariables,
|
|
96
96
|
},
|
|
97
97
|
data: {
|
|
98
98
|
rawWrapperArgs,
|
|
@@ -47,11 +47,11 @@ const wrapperArgs = _
|
|
|
47
47
|
.map(argToTmpl)
|
|
48
48
|
.join('; ');
|
|
49
49
|
|
|
50
|
-
const
|
|
50
|
+
const isOptionalVariables = _
|
|
51
51
|
// Find optional value
|
|
52
52
|
.filter(rawWrapperArgs, o => o.optional).length === rawWrapperArgs.length;
|
|
53
53
|
|
|
54
|
-
const conditionalVriablesText =
|
|
54
|
+
const conditionalVriablesText = isOptionalVariables? "variables?" : "variables";
|
|
55
55
|
const repalceTarget = "${" + conditionalVriablesText + ".";
|
|
56
56
|
const pathWithVariables = path.replace(/\$\{/g, repalceTarget);
|
|
57
57
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
hasPagination,
|
|
11
11
|
isQuery,
|
|
12
12
|
isMutation,
|
|
13
|
-
|
|
13
|
+
isOptionalVariables,
|
|
14
14
|
},
|
|
15
15
|
data: {
|
|
16
16
|
rawWrapperArgs,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
const { _, classNameCase } = utils;
|
|
35
35
|
|
|
36
|
-
const conditionalParamsText =
|
|
36
|
+
const conditionalParamsText = isOptionalVariables ? "params?" : "params"
|
|
37
37
|
const conditionCallWithVariabels = isQuery ? `(${conditionalParamsText}.variables)` : "";
|
|
38
38
|
const conditionParamQueryKey = isQuery ? `,${conditionalParamsText}.variables` : "";
|
|
39
39
|
const conditionWrapFunc = isQuery ? "() =>" : "";
|