@toktokhan-dev/cli-plugin-gen-api-react-query 0.1.2 → 0.1.4

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 CHANGED
@@ -56,4 +56,5 @@ interface GenerateSwaggerApiConfig {
56
56
  */
57
57
  declare const genApi: _toktokhan_dev_cli.MyCommand<GenerateSwaggerApiConfig, "gen:api">;
58
58
 
59
- export { type GenerateFn, type GenerateSwaggerApiConfig, type PaginationConfig, genApi };
59
+ export { genApi };
60
+ export type { GenerateFn, GenerateSwaggerApiConfig, PaginationConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toktokhan-dev/cli-plugin-gen-api-react-query",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A CLI plugin for generating API hooks with React Query built by TOKTOKHAN.DEV",
5
5
  "author": "TOKTOKHAN.DEV <fe-system@toktokhan.dev>",
6
6
  "license": "ISC",
@@ -40,7 +40,16 @@
40
40
 
41
41
  },
42
42
  interface: (contract) => {
43
- return `interface ${contract.name} {\r\n${contract.content}}`;
43
+ let content = contract.content;
44
+
45
+ const nullalbeEnums = contract.rawContent.filter((c) => !!c.enum?.length && c.isNullable )
46
+
47
+ nullalbeEnums.forEach((c) => {
48
+ const { field } = c
49
+ content = content.replace(field, `${field} | null`)
50
+ })
51
+
52
+ return `interface ${contract.name} {\r\n${content}}`;
44
53
  },
45
54
  type: (contract) => {
46
55
  return `type ${contract.name} = ${contract.content}`;
@@ -131,7 +131,7 @@ const dataForReactHookTemplate = {
131
131
  import { useQuery, useMutation, useInfiniteQuery, useSuspenseQuery, useSuspenseInfiniteQuery, InfiniteData } from '@tanstack/react-query';
132
132
  import { QueryHookParams, InfiniteQueryHookParams, MutationHookParams, Parameter, RequestFnReturn, SuspenseInfiniteQueryHookParams, SuspenseQueryHookParams } from "../@types/react-query-type";
133
133
  import { paramsSerializerBy } from "../@utils/param-serializer-by";
134
- import fetchExtended from "<%= instancePath %>";
134
+ import { fetchExtended } from "<%= instancePath %>";
135
135
 
136
136
  import { HttpClient, RequestParams, ContentType, HttpResponse } from "../@<%~ config.fileNames.httpClient %>";
137
137
  import { DeepOmitReadOnly } from '../@types/util-types';
@@ -40,7 +40,16 @@
40
40
 
41
41
  },
42
42
  interface: (contract) => {
43
- return `interface ${contract.name} {\r\n${contract.content}}`;
43
+ let content = contract.content;
44
+
45
+ const nullalbeEnums = contract.rawContent.filter((c) => !!c.enum?.length && c.isNullable )
46
+
47
+ nullalbeEnums.forEach((c) => {
48
+ const { field } = c
49
+ content = content.replace(field, `${field} | null`)
50
+ })
51
+
52
+ return `interface ${contract.name} {\r\n${content}}`;
44
53
  },
45
54
  type: (contract) => {
46
55
  return `type ${contract.name} = ${contract.content}`;
@@ -184,7 +184,11 @@ export class HttpClient<SecurityDataType = unknown> {
184
184
  <% } %>
185
185
  const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) && this.securityWorker && await this.securityWorker(this.securityData)) || {};
186
186
  const requestParams = this.mergeRequestParams(params, secureParams);
187
- const queryString = query && this.toQueryString(query);
187
+ const queryString =
188
+ query &&
189
+ (params.paramsSerializer ?
190
+ params.paramsSerializer(query)
191
+ : this.toQueryString(query))
188
192
  const payloadFormatter = this.contentFormatters[type || ContentType.Json];
189
193
  const responseFormat = format || requestParams.format;
190
194
 
@@ -108,21 +108,6 @@ const describeReturnType = () => {
108
108
  }
109
109
  }
110
110
 
111
- const generatePathSegments = (path) => {
112
- const segments = [];
113
- const parts = path.split('/').filter(part => part.length > 0);
114
-
115
- let currentPath = '';
116
- for (const part of parts) {
117
- currentPath += `/${part}`;
118
- segments.push(`${currentPath}`);
119
- }
120
-
121
- return segments;
122
- }
123
-
124
- const pathSegments = generatePathSegments(pathWithVariables).map(segment => `\`${segment}\``).join(', ');
125
-
126
111
  %>
127
112
  /**
128
113
  <%~ routeDocs.description %>
@@ -144,8 +129,4 @@ const pathSegments = generatePathSegments(pathWithVariables).map(segment => `\`$
144
129
  <%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
145
130
  <%~ paramsSerializerTmpl ? `paramsSerializer: ${paramsSerializerTmpl},` : '' %>
146
131
  ...<%~ `${conditionalVriablesText}`%>.<%~ _.get(requestConfigParam, "name") %>,
147
- next: {
148
- ...<%~ `${conditionalVriablesText}`%>.<%~ _.get(requestConfigParam, "name") %>?.next,
149
- tags: [<%= pathSegments %>],
150
- },
151
132
  })