react-query-lightbase-codegen 1.0.1 → 1.0.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/{lib/typescript → dist}/convertSwaggerFile.d.ts +0 -0
- package/{lib/src → dist}/convertSwaggerFile.js +7 -10
- package/dist/convertSwaggerFile.js.map +1 -0
- package/{lib/typescript → dist}/generateHooks.d.ts +0 -0
- package/dist/generateHooks.js +395 -0
- package/dist/generateHooks.js.map +1 -0
- package/{lib/typescript → dist}/generateImports.d.ts +0 -0
- package/dist/generateImports.js +28 -0
- package/dist/generateImports.js.map +1 -0
- package/{lib/typescript → dist}/generateSchemas.d.ts +0 -0
- package/dist/generateSchemas.js +97 -0
- package/dist/generateSchemas.js.map +1 -0
- package/{lib/typescript → dist}/importSpecs.d.ts +0 -0
- package/dist/importSpecs.js +81 -0
- package/dist/importSpecs.js.map +1 -0
- package/{lib/typescript → dist}/index.d.ts +0 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/{lib/typescript → dist}/utils.d.ts +0 -0
- package/{lib/src → dist}/utils.js +38 -53
- package/dist/utils.js.map +1 -0
- package/package.json +9 -27
- package/lib/commonjs/convertSwaggerFile.js +0 -37
- package/lib/commonjs/convertSwaggerFile.js.map +0 -1
- package/lib/commonjs/generateHooks.js +0 -492
- package/lib/commonjs/generateHooks.js.map +0 -1
- package/lib/commonjs/generateImports.js +0 -48
- package/lib/commonjs/generateImports.js.map +0 -1
- package/lib/commonjs/generateSchemas.js +0 -119
- package/lib/commonjs/generateSchemas.js.map +0 -1
- package/lib/commonjs/importSpecs.js +0 -117
- package/lib/commonjs/importSpecs.js.map +0 -1
- package/lib/commonjs/index.js +0 -22
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/utils.js +0 -212
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/src/generateHooks.js +0 -249
- package/lib/src/generateImports.js +0 -29
- package/lib/src/generateSchemas.js +0 -108
- package/lib/src/importSpecs.js +0 -134
- package/lib/src/index.js +0 -7
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHook = void 0;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils.js");
|
|
11
|
-
|
|
12
|
-
var _case = _interopRequireDefault(require("case"));
|
|
13
|
-
|
|
14
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
get,
|
|
20
|
-
groupBy
|
|
21
|
-
} = _lodash.default;
|
|
22
|
-
const {
|
|
23
|
-
pascal,
|
|
24
|
-
camel
|
|
25
|
-
} = _case.default;
|
|
26
|
-
const IdentifierRegexp = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
27
|
-
/**
|
|
28
|
-
* Return every params in a path
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
const getParamsInPath = path => {
|
|
32
|
-
let n;
|
|
33
|
-
const output = [];
|
|
34
|
-
const templatePathRegex = /\{(\w+)}/g;
|
|
35
|
-
|
|
36
|
-
while ((n = templatePathRegex.exec(path)) !== null) {
|
|
37
|
-
output.push(n[1]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return output;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Generate a react-query component from openapi operation specs
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const createHook = _ref => {
|
|
48
|
-
let {
|
|
49
|
-
operation,
|
|
50
|
-
verb,
|
|
51
|
-
route,
|
|
52
|
-
operationIds,
|
|
53
|
-
parameters,
|
|
54
|
-
schemasComponents,
|
|
55
|
-
headerFilters,
|
|
56
|
-
overrides
|
|
57
|
-
} = _ref;
|
|
58
|
-
const {
|
|
59
|
-
operationId = route.replace('/', '')
|
|
60
|
-
} = operation;
|
|
61
|
-
|
|
62
|
-
if (operationId === '*') {
|
|
63
|
-
throw new Error(`Invalid operationId/Route set for ${verb} ${route}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (operationIds.includes(operationId)) {
|
|
67
|
-
return {
|
|
68
|
-
implementation: '',
|
|
69
|
-
imports: [],
|
|
70
|
-
queryImports: []
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
operationIds.push(operationId);
|
|
75
|
-
route = route.replace(/\{/g, '${').replace('//', '/'); // `/pet/{id}` => `/pet/${id}`
|
|
76
|
-
// Remove the last param of the route if we are in the DELETE case
|
|
77
|
-
|
|
78
|
-
let lastParamInTheRoute = null;
|
|
79
|
-
const componentName = pascal(operationId);
|
|
80
|
-
|
|
81
|
-
const isOk = _ref2 => {
|
|
82
|
-
let [statusCode] = _ref2;
|
|
83
|
-
return statusCode.toString().startsWith('2');
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const responseTypes = (0, _utils.getResReqTypes)(Object.entries(operation.responses).filter(isOk)) || 'void';
|
|
87
|
-
const requestBodyTypes = (0, _utils.getResReqTypes)([['body', operation.requestBody]]);
|
|
88
|
-
let imports = [responseTypes];
|
|
89
|
-
let queryImports = [];
|
|
90
|
-
const paramsInPath = getParamsInPath(route).filter(param => !(verb === 'delete' && param === lastParamInTheRoute));
|
|
91
|
-
const {
|
|
92
|
-
query: queryParams = [],
|
|
93
|
-
path: pathParams = [],
|
|
94
|
-
header = []
|
|
95
|
-
} = groupBy([...(parameters || []), ...(operation.parameters || [])].map(p => {
|
|
96
|
-
if ((0, _utils.isReference)(p)) {
|
|
97
|
-
return get(schemasComponents, p.$ref.replace('#/components/', '').replace('/', '.'));
|
|
98
|
-
} else {
|
|
99
|
-
return p;
|
|
100
|
-
}
|
|
101
|
-
}), 'in');
|
|
102
|
-
const headerParams = header.filter(p => !(headerFilters !== null && headerFilters !== void 0 && headerFilters.includes(p.name)));
|
|
103
|
-
let enabled = []; // TODO: extract all requestBody or remove useQuery variants
|
|
104
|
-
|
|
105
|
-
let enabledParam = '!!params';
|
|
106
|
-
[...queryParams, ...pathParams, ...headerParams].forEach(item => {
|
|
107
|
-
if (item.required) {
|
|
108
|
-
enabled.push(`["${item.name}"]`);
|
|
109
|
-
|
|
110
|
-
if (enabledParam && enabledParam !== '!!params') {
|
|
111
|
-
enabledParam += `&& params['${item.name}'] != null`;
|
|
112
|
-
} else {
|
|
113
|
-
enabledParam = `params['${item.name}'] != null`;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}); // `!props${enabled.join('== null && !props')}`;
|
|
117
|
-
|
|
118
|
-
const paramsTypes = paramsInPath.map(p => {
|
|
119
|
-
try {
|
|
120
|
-
const {
|
|
121
|
-
name,
|
|
122
|
-
required,
|
|
123
|
-
schema
|
|
124
|
-
} = pathParams.find(i => i.name === p);
|
|
125
|
-
return `${name}${required ? '' : '?'}: ${(0, _utils.resolveValue)(schema)}`;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);
|
|
128
|
-
}
|
|
129
|
-
}).join('; ');
|
|
130
|
-
const queryParamsType = queryParams.map(p => {
|
|
131
|
-
const processedName = IdentifierRegexp.test(p.name) ? p.name : `"${p.name}"`;
|
|
132
|
-
return `${(0, _utils.formatDescription)(p.description)}
|
|
133
|
-
${processedName}${p.required ? '' : '?'}: ${(0, _utils.resolveValue)(p.schema)}`;
|
|
134
|
-
}).join(';\n ');
|
|
135
|
-
const headerType = headerParams.map(p => {
|
|
136
|
-
try {
|
|
137
|
-
const {
|
|
138
|
-
name,
|
|
139
|
-
required,
|
|
140
|
-
schema
|
|
141
|
-
} = headerParams.find(i => i.name === p.name);
|
|
142
|
-
return `"${name}"${required ? '' : '?'}: ${(0, _utils.resolveValue)(schema)}`;
|
|
143
|
-
} catch (err) {
|
|
144
|
-
throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);
|
|
145
|
-
}
|
|
146
|
-
}).join('; '); // Retrieve the type of the param for delete verb
|
|
147
|
-
|
|
148
|
-
const lastParamInTheRouteDefinition = operation.parameters && lastParamInTheRoute ? operation.parameters.find(p => {
|
|
149
|
-
if ((0, _utils.isReference)(p)) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return p.name === lastParamInTheRoute;
|
|
154
|
-
}) // Reference is not possible
|
|
155
|
-
: {
|
|
156
|
-
schema: {
|
|
157
|
-
type: 'string'
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
if (!lastParamInTheRouteDefinition) {
|
|
162
|
-
throw new Error(`The path params ${lastParamInTheRoute} can't be found in parameters (${operationId})`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const defaultDescription = `type: ${verb}\noperationId: ${operationId}\nurl: ${route}`;
|
|
166
|
-
const description = (0, _utils.formatDescription)(operation.summary && operation.description ? `${defaultDescription}\n\n${operation.summary}\n\n${operation.description}` : `${defaultDescription}`);
|
|
167
|
-
let output = `\n\n${description}`;
|
|
168
|
-
const headerParam = headerType && headerType !== 'void' ? `${headerType};` : '';
|
|
169
|
-
const queryParam = queryParamsType && queryParamsType !== 'void' ? `${queryParamsType}` : '';
|
|
170
|
-
const requestBodyComponent = requestBodyTypes && requestBodyTypes !== 'void' ? `${requestBodyTypes}` : '';
|
|
171
|
-
|
|
172
|
-
if (requestBodyComponent) {
|
|
173
|
-
imports.push(requestBodyComponent);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const isUpdateRequest = ['post', 'patch', 'put'].includes(verb);
|
|
177
|
-
|
|
178
|
-
const generateProps = props => {
|
|
179
|
-
return props.map(item => `["${item.name}"]: props["${item.name}"]`).join(',');
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const generateBodyProps = () => {
|
|
183
|
-
const definitionKey = Object.keys((schemasComponents === null || schemasComponents === void 0 ? void 0 : schemasComponents.schemas) || {}).find(key => pascal(key) === requestBodyComponent);
|
|
184
|
-
|
|
185
|
-
if (definitionKey) {
|
|
186
|
-
var _schemasComponents$sc;
|
|
187
|
-
|
|
188
|
-
const scheme = schemasComponents === null || schemasComponents === void 0 ? void 0 : (_schemasComponents$sc = schemasComponents.schemas) === null || _schemasComponents$sc === void 0 ? void 0 : _schemasComponents$sc[definitionKey];
|
|
189
|
-
return Object.keys(scheme.properties).map(item => `["${item}"]: props["${item}"]`).join(',');
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const fetchName = camel(componentName);
|
|
194
|
-
|
|
195
|
-
const createQueryHooks = emptyParams => {
|
|
196
|
-
const params = emptyParams ? '' : `params: ${componentName}Params,`;
|
|
197
|
-
const key = emptyParams ? '' : `params`;
|
|
198
|
-
const mutationParams = emptyParams ? 'void' : `${componentName}Params`;
|
|
199
|
-
const queryParamType = emptyParams ? '' : `${componentName}Params &`;
|
|
200
|
-
const filterParams = emptyParams ? '{ filters }: { filters?: QueryFilters }' : `{ params, filters }: { params: ${componentName}Params, filters?: QueryFilters }`;
|
|
201
|
-
const cacheParams = emptyParams ? `{updater, options}: {updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}` : `{params, updater, options}: {params: ${componentName}Params, updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}`;
|
|
202
|
-
const queryKey = emptyParams ? `use${componentName}Query.baseKey()` : `[...use${componentName}Query.baseKey(), params]`;
|
|
203
|
-
|
|
204
|
-
const createQuery = () => `
|
|
205
|
-
type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {
|
|
206
|
-
options?: UseQueryOptions<${responseTypes}, AxiosError, T, any>
|
|
207
|
-
}
|
|
208
|
-
export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) {
|
|
209
|
-
return useQuery(use${componentName}Query.queryKey(${key}), async () => ${fetchName}(${key}), { enabled: ${enabledParam}, ...options });
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
213
|
-
|
|
214
|
-
use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};
|
|
215
|
-
|
|
216
|
-
use${componentName}Query.updateCache = (${cacheParams}) => queryClient.setQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), updater, options);
|
|
217
|
-
|
|
218
|
-
use${componentName}Query.getQueryState = (${filterParams})=> queryClient.getQueryState<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);
|
|
219
|
-
|
|
220
|
-
use${componentName}Query.getQueryData = (${filterParams})=> queryClient.getQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);
|
|
221
|
-
|
|
222
|
-
use${componentName}Query.prefetch = (${params}) => queryClient.prefetchQuery<${responseTypes}>(use${componentName}Query.queryKey(${key}), ()=> ${fetchName}(${key}));
|
|
223
|
-
|
|
224
|
-
use${componentName}Query.cancelQueries = (${params}) => queryClient.cancelQueries(use${componentName}Query.queryKey(${key}))
|
|
225
|
-
|
|
226
|
-
use${componentName}Query.invalidate = (${params}) => queryClient.invalidateQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}));
|
|
227
|
-
|
|
228
|
-
use${componentName}Query.refetchStale = (${params}) => queryClient.refetchQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}), { stale: true });
|
|
229
|
-
`;
|
|
230
|
-
|
|
231
|
-
const getInfiniteQuery = _ref3 => {
|
|
232
|
-
let {
|
|
233
|
-
pageParam
|
|
234
|
-
} = _ref3;
|
|
235
|
-
return `
|
|
236
|
-
type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {
|
|
237
|
-
options: UseInfiniteQueryOptions<${responseTypes}, AxiosError, T, any>
|
|
238
|
-
}
|
|
239
|
-
export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) {
|
|
240
|
-
return useInfiniteQuery(use${componentName}Query.queryKey(${key}), async ({ pageParam = 0 }) => ${fetchName}({${pageParam}: pageParam, ...params}), { enabled: ${enabledParam}, ...options });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
244
|
-
|
|
245
|
-
use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};
|
|
246
|
-
|
|
247
|
-
`;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const createMutation = () => `
|
|
251
|
-
type ${componentName}MutationProps<T> = {
|
|
252
|
-
options?: UseMutationOptions<${responseTypes}, AxiosError, ${mutationParams}, T>
|
|
253
|
-
}
|
|
254
|
-
export function use${componentName}Mutation<T = ${responseTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
255
|
-
return useMutation(async (${key}) => ${fetchName}(${key}), props?.options)
|
|
256
|
-
};
|
|
257
|
-
`;
|
|
258
|
-
|
|
259
|
-
const override = overrides === null || overrides === void 0 ? void 0 : overrides[operationId];
|
|
260
|
-
|
|
261
|
-
if ((override === null || override === void 0 ? void 0 : override.type) === 'query') {
|
|
262
|
-
console.log(_chalk.default.blue(`⚙️ [${operationId}] has been changed to a useQuery hook`));
|
|
263
|
-
queryImports.push('query');
|
|
264
|
-
return createQuery();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if ((override === null || override === void 0 ? void 0 : override.type) === 'mutation') {
|
|
268
|
-
queryImports.push('mutation');
|
|
269
|
-
console.log(_chalk.default.blue(`⚙️ [${operationId}] has been changed to a useMutation hook`));
|
|
270
|
-
return createMutation();
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if ((override === null || override === void 0 ? void 0 : override.type) === 'infiniteQuery') {
|
|
274
|
-
console.log(_chalk.default.blue(`⚙️ [${operationId}] has been changed to a useInfiniteQuery hook`));
|
|
275
|
-
queryImports.push('infiniteQuery');
|
|
276
|
-
return getInfiniteQuery({
|
|
277
|
-
pageParam: override.infiniteQueryParm
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (verb === 'get') {
|
|
282
|
-
queryImports.push('query');
|
|
283
|
-
return createQuery();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
queryImports.push('mutation');
|
|
287
|
-
return createMutation();
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
output += createQueryHooks(!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam);
|
|
291
|
-
|
|
292
|
-
if (!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
293
|
-
output += `
|
|
294
|
-
const ${fetchName} = async () => {
|
|
295
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`);
|
|
296
|
-
return result.data;
|
|
297
|
-
}
|
|
298
|
-
`;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (!requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
302
|
-
const config = isUpdateRequest ? 'body,{params}' : '{params}';
|
|
303
|
-
output += `
|
|
304
|
-
type ${componentName}Params = {
|
|
305
|
-
${paramsTypes}
|
|
306
|
-
${queryParamsType};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const ${fetchName} = async (props:${componentName}Params) => {
|
|
310
|
-
const {${paramsInPath.join(', ')}, ...params} = props
|
|
311
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
312
|
-
return result.data;
|
|
313
|
-
}`;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
317
|
-
output += `
|
|
318
|
-
type ${componentName}Params = {
|
|
319
|
-
${paramsTypes}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const ${fetchName} = async (props: ${componentName}Params ) => {
|
|
323
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`);
|
|
324
|
-
return result.data;
|
|
325
|
-
}
|
|
326
|
-
`;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
330
|
-
const config = isUpdateRequest ? 'null,{params}' : '{params}';
|
|
331
|
-
output += `
|
|
332
|
-
type ${componentName}Params = {
|
|
333
|
-
${queryParamsType}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const ${fetchName} = async (params: ${componentName}Params) => {
|
|
337
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
338
|
-
return result.data;
|
|
339
|
-
}
|
|
340
|
-
`;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
344
|
-
const config = isUpdateRequest ? 'null,{headers, params: queryParams}' : '{headers, params: queryParams}';
|
|
345
|
-
output += `
|
|
346
|
-
type ${componentName}Params = {
|
|
347
|
-
${headerParam}
|
|
348
|
-
${queryParamsType}
|
|
349
|
-
}
|
|
350
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
351
|
-
const headers = {${generateProps(header)}}
|
|
352
|
-
const queryParams = {${generateProps(queryParams)}}
|
|
353
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
354
|
-
return result.data
|
|
355
|
-
}`;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
359
|
-
const config = isUpdateRequest ? 'null,{headers}' : '{headers}';
|
|
360
|
-
output += `
|
|
361
|
-
type ${componentName}Params = {
|
|
362
|
-
${headerParam}
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
const ${fetchName} = async (headers: ${componentName}Params) => {
|
|
366
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config});
|
|
367
|
-
return result.data;
|
|
368
|
-
}
|
|
369
|
-
`;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
373
|
-
output += `
|
|
374
|
-
type ${componentName}Params = ${requestBodyComponent}
|
|
375
|
-
|
|
376
|
-
const ${fetchName} = async (body: ${componentName}Params) => {
|
|
377
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body)
|
|
378
|
-
return result.data
|
|
379
|
-
}
|
|
380
|
-
`;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
384
|
-
const config = isUpdateRequest ? 'null,{headers, params: queryParams}' : '{headers, params: queryParams}';
|
|
385
|
-
const queryParamsProps = queryParams.map(item => `["${item.name}"]: props["${item.name}"]`);
|
|
386
|
-
output += `
|
|
387
|
-
type ${componentName}Params = ${requestBodyComponent} & {
|
|
388
|
-
${queryParamsType}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
type ${componentName}QueryProps<T = ${responseTypes}> = ${componentName}Params & {
|
|
392
|
-
const body = {${generateBodyProps()}}
|
|
393
|
-
const params = {${generateProps(queryParams)}}
|
|
394
|
-
options?: UseQueryOptions<${responseTypes}, AxiosError, T, any>
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const ${fetchName} = async ({body, params}: ${componentName}Params) => {
|
|
398
|
-
const queryParams = {${queryParamsProps.join(',')}}
|
|
399
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
400
|
-
return result.data
|
|
401
|
-
}
|
|
402
|
-
`;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
406
|
-
output += `
|
|
407
|
-
type ${componentName}Params = ${requestBodyComponent} & {
|
|
408
|
-
${headerParam}
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
412
|
-
const headers = {${generateProps(header)}}
|
|
413
|
-
const body = {${generateBodyProps()}}
|
|
414
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body, {headers})
|
|
415
|
-
return result.data
|
|
416
|
-
}
|
|
417
|
-
`;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
421
|
-
output += `
|
|
422
|
-
type ${componentName}Params = ${requestBodyComponent} & {
|
|
423
|
-
${headerParam}
|
|
424
|
-
${paramsTypes}
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
428
|
-
const body = {${generateBodyProps()}}
|
|
429
|
-
const headers = {${generateProps(header)}}
|
|
430
|
-
const params = {${generateProps(queryParams)}}
|
|
431
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body, {headers, params})
|
|
432
|
-
return result.data
|
|
433
|
-
}
|
|
434
|
-
`;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
438
|
-
output += `
|
|
439
|
-
type ${componentName}Params = ${requestBodyComponent} & {
|
|
440
|
-
${headerParam}
|
|
441
|
-
${paramsTypes}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
445
|
-
const body = {${generateBodyProps()}}
|
|
446
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`, body)
|
|
447
|
-
return result.data
|
|
448
|
-
}
|
|
449
|
-
`;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
453
|
-
output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam)`;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
457
|
-
output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam && headerParam)`;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
461
|
-
const config = isUpdateRequest ? 'null,{headers}' : '{headers}';
|
|
462
|
-
output += `
|
|
463
|
-
type ${componentName}Params = {
|
|
464
|
-
${headerParam}
|
|
465
|
-
${paramsTypes}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
469
|
-
const headers = {${generateProps(header)}}
|
|
470
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`, ${config})
|
|
471
|
-
return result.data
|
|
472
|
-
}
|
|
473
|
-
`;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
477
|
-
output += `// TODO: NOT SUPPORTED (paramsInPath && queryParam && headerParam)`;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
481
|
-
output += `// TODO: NOT SUPPORTED (requestBodyComponent && paramsInPath && headerParam)`;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
return {
|
|
485
|
-
implementation: output,
|
|
486
|
-
imports,
|
|
487
|
-
queryImports
|
|
488
|
-
};
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
exports.createHook = createHook;
|
|
492
|
-
//# sourceMappingURL=generateHooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["get","groupBy","lodash","pascal","camel","pasCase","IdentifierRegexp","getParamsInPath","path","n","output","templatePathRegex","exec","push","createHook","operation","verb","route","operationIds","parameters","schemasComponents","headerFilters","overrides","operationId","replace","Error","includes","implementation","imports","queryImports","lastParamInTheRoute","componentName","isOk","statusCode","toString","startsWith","responseTypes","getResReqTypes","Object","entries","responses","filter","requestBodyTypes","requestBody","paramsInPath","param","query","queryParams","pathParams","header","map","p","isReference","$ref","headerParams","name","enabled","enabledParam","forEach","item","required","paramsTypes","schema","find","i","resolveValue","err","join","queryParamsType","processedName","test","formatDescription","description","headerType","lastParamInTheRouteDefinition","type","defaultDescription","summary","headerParam","queryParam","requestBodyComponent","isUpdateRequest","generateProps","props","generateBodyProps","definitionKey","keys","schemas","key","scheme","properties","fetchName","createQueryHooks","emptyParams","params","mutationParams","queryParamType","filterParams","cacheParams","queryKey","createQuery","toLowerCase","getInfiniteQuery","pageParam","createMutation","override","console","log","chalk","blue","infiniteQueryParm","length","config","queryParamsProps"],"sources":["generateHooks.ts"],"sourcesContent":["import lodash from 'lodash';\nconst { get, groupBy } = lodash;\nimport {\n ComponentsObject,\n OperationObject,\n ParameterObject,\n ReferenceObject,\n ResponseObject,\n SchemaObject,\n} from 'openapi3-ts';\nimport { formatDescription, getResReqTypes, isReference, resolveValue } from './utils.js';\nimport pasCase from 'case';\nimport chalk from 'chalk';\n\nconst { pascal, camel } = pasCase;\n\nconst IdentifierRegexp = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\n/**\n * Return every params in a path\n */\nconst getParamsInPath = (path: string) => {\n let n;\n const output = [];\n const templatePathRegex = /\\{(\\w+)}/g;\n while ((n = templatePathRegex.exec(path)) !== null) {\n output.push(n[1]);\n }\n\n return output;\n};\n\n/**\n * Generate a react-query component from openapi operation specs\n */\nexport const createHook = ({\n operation,\n verb,\n route,\n operationIds,\n parameters,\n schemasComponents,\n headerFilters,\n overrides,\n}: {\n operation: OperationObject;\n verb: string;\n route: string;\n operationIds: string[];\n parameters: (ReferenceObject | ParameterObject)[] | undefined;\n schemasComponents?: ComponentsObject;\n headerFilters?: string[];\n overrides?: Record<\n string,\n { type: 'query' } | { type: 'mutation' } | { type: 'infiniteQuery'; infiniteQueryParm: string }\n >;\n}) => {\n const { operationId = route.replace('/', '') } = operation;\n if (operationId === '*') {\n throw new Error(`Invalid operationId/Route set for ${verb} ${route}`);\n }\n if (operationIds.includes(operationId)) {\n return { implementation: '', imports: [], queryImports: [] };\n }\n operationIds.push(operationId);\n\n route = route.replace(/\\{/g, '${').replace('//', '/'); // `/pet/{id}` => `/pet/${id}`\n\n // Remove the last param of the route if we are in the DELETE case\n let lastParamInTheRoute: string | null = null;\n\n const componentName = pascal(operationId!);\n\n const isOk = ([statusCode]: [string, ResponseObject | ReferenceObject]) =>\n statusCode.toString().startsWith('2');\n\n const responseTypes = getResReqTypes(Object.entries(operation.responses).filter(isOk)) || 'void';\n const requestBodyTypes = getResReqTypes([['body', operation.requestBody!]]);\n\n let imports = [responseTypes];\n let queryImports = [] as Array<'mutation' | 'query' | 'infiniteQuery'>;\n\n const paramsInPath = getParamsInPath(route).filter(\n (param) => !(verb === 'delete' && param === lastParamInTheRoute)\n );\n\n const {\n query: queryParams = [],\n path: pathParams = [],\n header = [],\n } = groupBy(\n [...(parameters || []), ...(operation.parameters || [])].map<ParameterObject>((p) => {\n if (isReference(p)) {\n return get(schemasComponents, p.$ref.replace('#/components/', '').replace('/', '.'));\n } else {\n return p;\n }\n }),\n 'in'\n );\n\n const headerParams = header.filter((p) => !headerFilters?.includes(p.name));\n\n let enabled = [] as any;\n\n // TODO: extract all requestBody or remove useQuery variants\n let enabledParam = '!!params';\n [...queryParams, ...pathParams, ...headerParams].forEach((item) => {\n if (item.required) {\n enabled.push(`[\"${item.name}\"]`);\n if (enabledParam && enabledParam !== '!!params') {\n enabledParam += `&& params['${item.name}'] != null`;\n } else {\n enabledParam = `params['${item.name}'] != null`;\n }\n }\n });\n\n // `!props${enabled.join('== null && !props')}`;\n\n const paramsTypes = paramsInPath\n .map((p) => {\n try {\n const { name, required, schema } = pathParams.find((i) => i.name === p)!;\n return `${name}${required ? '' : '?'}: ${resolveValue(schema!)}`;\n } catch (err) {\n throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);\n }\n })\n .join('; ');\n\n const queryParamsType = queryParams\n .map((p) => {\n const processedName = IdentifierRegexp.test(p.name) ? p.name : `\"${p.name}\"`;\n return `${formatDescription(p.description)}\n ${processedName}${p.required ? '' : '?'}: ${resolveValue(p.schema!)}`;\n })\n .join(';\\n ');\n\n const headerType = headerParams\n .map((p) => {\n try {\n const { name, required, schema } = headerParams.find((i) => i.name === p.name)!;\n return `\"${name}\"${required ? '' : '?'}: ${resolveValue(schema!)}`;\n } catch (err) {\n throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);\n }\n })\n .join('; ');\n\n // Retrieve the type of the param for delete verb\n const lastParamInTheRouteDefinition =\n operation.parameters && lastParamInTheRoute\n ? (operation.parameters.find((p) => {\n if (isReference(p)) {\n return false;\n }\n return p.name === lastParamInTheRoute;\n }) as ParameterObject | undefined) // Reference is not possible\n : { schema: { type: 'string' } };\n\n if (!lastParamInTheRouteDefinition) {\n throw new Error(`The path params ${lastParamInTheRoute} can't be found in parameters (${operationId})`);\n }\n\n const defaultDescription = `type: ${verb}\\noperationId: ${operationId}\\nurl: ${route}`;\n\n const description = formatDescription(\n operation.summary && operation.description\n ? `${defaultDescription}\\n\\n${operation.summary}\\n\\n${operation.description}`\n : `${defaultDescription}`\n );\n\n let output = `\\n\\n${description}`;\n\n const headerParam = headerType && headerType !== 'void' ? `${headerType};` : '';\n const queryParam = queryParamsType && queryParamsType !== 'void' ? `${queryParamsType}` : '';\n const requestBodyComponent = requestBodyTypes && requestBodyTypes !== 'void' ? `${requestBodyTypes}` : '';\n\n if (requestBodyComponent) {\n imports.push(requestBodyComponent);\n }\n\n const isUpdateRequest = ['post', 'patch', 'put'].includes(verb);\n\n const generateProps = (props: ParameterObject[]) => {\n return props.map((item) => `[\"${item.name}\"]: props[\"${item.name}\"]`).join(',');\n };\n\n const generateBodyProps = () => {\n const definitionKey = Object.keys(schemasComponents?.schemas || {}).find(\n (key) => pascal(key) === requestBodyComponent\n );\n if (definitionKey) {\n const scheme = schemasComponents?.schemas?.[definitionKey] as SchemaObject;\n return Object.keys(scheme.properties as SchemaObject)\n .map((item: string) => `[\"${item}\"]: props[\"${item}\"]`)\n .join(',');\n }\n };\n\n const fetchName = camel(componentName);\n\n const createQueryHooks = (emptyParams?: boolean) => {\n const params = emptyParams ? '' : `params: ${componentName}Params,`;\n const key = emptyParams ? '' : `params`;\n const mutationParams = emptyParams ? 'void' : `${componentName}Params`;\n const queryParamType = emptyParams ? '' : `${componentName}Params &`;\n const filterParams = emptyParams\n ? '{ filters }: { filters?: QueryFilters }'\n : `{ params, filters }: { params: ${componentName}Params, filters?: QueryFilters }`;\n const cacheParams = emptyParams\n ? `{updater, options}: {updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}`\n : `{params, updater, options}: {params: ${componentName}Params, updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}`;\n const queryKey = emptyParams\n ? `use${componentName}Query.baseKey()`\n : `[...use${componentName}Query.baseKey(), params]`;\n\n const createQuery = () => `\n type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {\n options?: UseQueryOptions<${responseTypes}, AxiosError, T, any> \n }\n export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) { \n return useQuery(use${componentName}Query.queryKey(${key}), async () => ${fetchName}(${key}), { enabled: ${enabledParam}, ...options });\n }\n\n use${componentName}Query.baseKey = (): QueryKey => [\"${componentName.toLowerCase()}\"];\n \n use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};\n \n use${componentName}Query.updateCache = (${cacheParams}) => queryClient.setQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), updater, options);\n \n use${componentName}Query.getQueryState = (${filterParams})=> queryClient.getQueryState<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);\n \n use${componentName}Query.getQueryData = (${filterParams})=> queryClient.getQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);\n \n use${componentName}Query.prefetch = (${params}) => queryClient.prefetchQuery<${responseTypes}>(use${componentName}Query.queryKey(${key}), ()=> ${fetchName}(${key}));\n \n use${componentName}Query.cancelQueries = (${params}) => queryClient.cancelQueries(use${componentName}Query.queryKey(${key}))\n \n use${componentName}Query.invalidate = (${params}) => queryClient.invalidateQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}));\n \n use${componentName}Query.refetchStale = (${params}) => queryClient.refetchQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}), { stale: true });\n `;\n\n const getInfiniteQuery = ({ pageParam }: { pageParam: string }) => `\n type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {\n options: UseInfiniteQueryOptions<${responseTypes}, AxiosError, T, any> \n }\n export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) { \n return useInfiniteQuery(use${componentName}Query.queryKey(${key}), async ({ pageParam = 0 }) => ${fetchName}({${pageParam}: pageParam, ...params}), { enabled: ${enabledParam}, ...options });\n }\n\n use${componentName}Query.baseKey = (): QueryKey => [\"${componentName.toLowerCase()}\"];\n \n use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};\n \n `;\n\n const createMutation = () => `\n type ${componentName}MutationProps<T> = {\n options?: UseMutationOptions<${responseTypes}, AxiosError, ${mutationParams}, T> \n }\n export function use${componentName}Mutation<T = ${responseTypes}>(props?: ${componentName}MutationProps<T>) { \n return useMutation(async (${key}) => ${fetchName}(${key}), props?.options)\n };\n `;\n\n const override = overrides?.[operationId];\n if (override?.type === 'query') {\n console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useQuery hook`));\n queryImports.push('query');\n return createQuery();\n }\n\n if (override?.type === 'mutation') {\n queryImports.push('mutation');\n console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useMutation hook`));\n return createMutation();\n }\n\n if (override?.type === 'infiniteQuery') {\n console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useInfiniteQuery hook`));\n queryImports.push('infiniteQuery');\n return getInfiniteQuery({ pageParam: override.infiniteQueryParm });\n }\n\n if (verb === 'get') {\n queryImports.push('query');\n return createQuery();\n }\n\n queryImports.push('mutation');\n return createMutation();\n };\n\n output += createQueryHooks(!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam);\n\n if (!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {\n output += `\n const ${fetchName} = async () => {\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`);\n return result.data;\n }\n `;\n }\n\n if (!requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {\n const config = isUpdateRequest ? 'body,{params}' : '{params}';\n output += `\n type ${componentName}Params = {\n ${paramsTypes}\n ${queryParamsType}; \n }\n\n const ${fetchName} = async (props:${componentName}Params) => {\n const {${paramsInPath.join(', ')}, ...params} = props\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, ${config})\n return result.data;\n }`;\n }\n\n if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {\n output += `\n type ${componentName}Params = {\n ${paramsTypes}\n }\n\n const ${fetchName} = async (props: ${componentName}Params ) => {\n const result = await api.${verb}<${responseTypes}>(\\`${route.replace(/\\{/g, '{props.')}\\`);\n return result.data;\n }\n `;\n }\n\n if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {\n const config = isUpdateRequest ? 'null,{params}' : '{params}';\n output += `\n type ${componentName}Params = { \n ${queryParamsType} \n }\n\n const ${fetchName} = async (params: ${componentName}Params) => {\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, ${config})\n return result.data;\n }\n `;\n }\n if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {\n const config = isUpdateRequest ? 'null,{headers, params: queryParams}' : '{headers, params: queryParams}';\n output += `\n type ${componentName}Params = {\n ${headerParam}\n ${queryParamsType}\n }\n const ${fetchName} = async (props: ${componentName}Params) => {\n const headers = {${generateProps(header)}}\n const queryParams = {${generateProps(queryParams)}}\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, ${config})\n return result.data\n }`;\n }\n if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {\n const config = isUpdateRequest ? 'null,{headers}' : '{headers}';\n output += `\n type ${componentName}Params = {\n ${headerParam}\n };\n \n const ${fetchName} = async (headers: ${componentName}Params) => {\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, ${config});\n return result.data;\n }\n `;\n }\n\n if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {\n output += `\n type ${componentName}Params = ${requestBodyComponent}\n\n const ${fetchName} = async (body: ${componentName}Params) => {\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, body)\n return result.data\n } \n `;\n }\n\n if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {\n const config = isUpdateRequest ? 'null,{headers, params: queryParams}' : '{headers, params: queryParams}';\n const queryParamsProps = queryParams.map((item) => `[\"${item.name}\"]: props[\"${item.name}\"]`);\n output += `\n type ${componentName}Params = ${requestBodyComponent} & {\n ${queryParamsType}\n }\n\n type ${componentName}QueryProps<T = ${responseTypes}> = ${componentName}Params & {\n const body = {${generateBodyProps()}}\n const params = {${generateProps(queryParams)}}\n options?: UseQueryOptions<${responseTypes}, AxiosError, T, any> \n }\n\n const ${fetchName} = async ({body, params}: ${componentName}Params) => { \n const queryParams = {${queryParamsProps.join(',')}}\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, ${config})\n return result.data\n }\n `;\n }\n\n if (requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {\n output += `\n type ${componentName}Params = ${requestBodyComponent} & {\n ${headerParam}\n };\n\n const ${fetchName} = async (props: ${componentName}Params) => {\n const headers = {${generateProps(header)}}\n const body = {${generateBodyProps()}}\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, body, {headers})\n return result.data\n }\n `;\n }\n\n if (requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {\n output += `\n type ${componentName}Params = ${requestBodyComponent} & {\n ${headerParam}\n ${paramsTypes}\n };\n\n const ${fetchName} = async (props: ${componentName}Params) => {\n const body = {${generateBodyProps()}}\n const headers = {${generateProps(header)}}\n const params = {${generateProps(queryParams)}}\n const result = await api.${verb}<${responseTypes}>(\\`${route}\\`, body, {headers, params})\n return result.data\n }\n `;\n }\n\n if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {\n output += `\n type ${componentName}Params = ${requestBodyComponent} & {\n ${headerParam}\n ${paramsTypes}\n };\n\n const ${fetchName} = async (props: ${componentName}Params) => {\n const body = {${generateBodyProps()}}\n const result = await api.${verb}<${responseTypes}>(\\`${route.replace(/\\{/g, '{props.')}\\`, body)\n return result.data\n }\n `;\n }\n\n if (requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {\n output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam)`;\n }\n\n if (requestBodyComponent && paramsInPath.length && queryParam && headerParam) {\n output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam && headerParam)`;\n }\n\n if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {\n const config = isUpdateRequest ? 'null,{headers}' : '{headers}';\n output += `\n type ${componentName}Params = {\n ${headerParam}\n ${paramsTypes}\n };\n\n const ${fetchName} = async (props: ${componentName}Params) => {\n const headers = {${generateProps(header)}}\n const result = await api.${verb}<${responseTypes}>(\\`${route.replace(/\\{/g, '{props.')}\\`, ${config})\n return result.data\n }\n `;\n }\n\n if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {\n output += `// TODO: NOT SUPPORTED (paramsInPath && queryParam && headerParam)`;\n }\n\n if (requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {\n output += `// TODO: NOT SUPPORTED (requestBodyComponent && paramsInPath && headerParam)`;\n }\n\n return { implementation: output, imports, queryImports };\n};\n"],"mappings":";;;;;;;AAAA;;AAUA;;AACA;;AACA;;;;AAXA,MAAM;EAAEA,GAAF;EAAOC;AAAP,IAAmBC,eAAzB;AAaA,MAAM;EAAEC,MAAF;EAAUC;AAAV,IAAoBC,aAA1B;AAEA,MAAMC,gBAAgB,GAAG,4BAAzB;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B,IAAIpC,YAAY,CAACmE,MAArC,IAA+ChC,UAA/C,IAA6DD,WAAjE,EAA8E;IAC5EpE,MAAM,IAAK,2FAAX;EACD;;EAED,IAAI,CAACsE,oBAAD,IAAyBpC,YAAY,CAACmE,MAAtC,IAAgD,CAAChC,UAAjD,IAA+DD,WAAnE,EAAgF;IAC9E,MAAMkC,MAAM,GAAG/B,eAAe,GAAG,gBAAH,GAAsB,WAApD;IACAvE,MAAM,IAAK;AACf,WAAWqB,aAAc;AACzB,QAAQ+C,WAAY;AACpB,QAAQjB,WAAY;AACpB;AACA;AACA,YAAY8B,SAAU,oBAAmB5D,aAAc;AACvD,yBAAyBmD,aAAa,CAACjC,MAAD,CAAS;AAC/C,iCAAiCjC,IAAK,IAAGoB,aAAc,OAAMnB,KAAK,CAACO,OAAN,CAAc,KAAd,EAAqB,SAArB,CAAgC,OAAMwF,MAAO;AAC1G;AACA;AACA,KAXI;EAYD;;EAED,IAAI,CAAChC,oBAAD,IAAyBpC,YAAY,CAACmE,MAAtC,IAAgDhC,UAAhD,IAA8DD,WAAlE,EAA+E;IAC7EpE,MAAM,IAAK,oEAAX;EACD;;EAED,IAAIsE,oBAAoB,IAAIpC,YAAY,CAACmE,MAArC,IAA+C,CAAChC,UAAhD,IAA8DD,WAAlE,EAA+E;IAC7EpE,MAAM,IAAK,8EAAX;EACD;;EAED,OAAO;IAAEiB,cAAc,EAAEjB,MAAlB;IAA0BkB,OAA1B;IAAmCC;EAAnC,CAAP;AACD,CAtcM"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.generateImports = void 0;
|
|
7
|
-
|
|
8
|
-
const generateImports = _ref => {
|
|
9
|
-
let {
|
|
10
|
-
schemaName,
|
|
11
|
-
apiDirectory,
|
|
12
|
-
queryClientDir,
|
|
13
|
-
schemaImports,
|
|
14
|
-
queryImports
|
|
15
|
-
} = _ref;
|
|
16
|
-
const importTypes = schemaImports.join(',');
|
|
17
|
-
let imports = [];
|
|
18
|
-
|
|
19
|
-
if (queryImports.includes('query')) {
|
|
20
|
-
imports = [...imports, 'useQuery', 'UseQueryOptions', 'QueryKey', 'SetDataOptions', 'QueryFilters'];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (queryImports.includes('infiniteQuery')) {
|
|
24
|
-
imports = [...imports, 'useInfiniteQuery', 'UseInfiniteQueryOptions', 'QueryKey'];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (queryImports.includes('mutation')) {
|
|
28
|
-
imports = [...imports, 'UseMutationOptions', 'useMutation'];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const importString = [...new Set(imports)].join(',');
|
|
32
|
-
return `
|
|
33
|
-
import {
|
|
34
|
-
${importString}
|
|
35
|
-
} from '@tanstack/react-query';
|
|
36
|
-
|
|
37
|
-
import { AxiosError } from 'axios';
|
|
38
|
-
import { api } from '${apiDirectory}';
|
|
39
|
-
import { queryClient } from '${queryClientDir}';
|
|
40
|
-
|
|
41
|
-
import {${importTypes}} from './${schemaName}'
|
|
42
|
-
|
|
43
|
-
type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
|
|
44
|
-
`;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exports.generateImports = generateImports;
|
|
48
|
-
//# sourceMappingURL=generateImports.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["generateImports","schemaName","apiDirectory","queryClientDir","schemaImports","queryImports","importTypes","join","imports","includes","importString","Set"],"sources":["generateImports.ts"],"sourcesContent":["export const generateImports = ({\n schemaName,\n apiDirectory,\n queryClientDir,\n schemaImports,\n queryImports,\n}: {\n apiDirectory: string;\n queryClientDir: string;\n schemaName: string;\n schemaImports: string[];\n queryImports: ('query' | 'mutation' | 'infiniteQuery')[];\n}) => {\n const importTypes = schemaImports.join(',');\n let imports = [] as string[];\n if (queryImports.includes('query')) {\n imports = [...imports, 'useQuery', 'UseQueryOptions', 'QueryKey', 'SetDataOptions', 'QueryFilters'];\n }\n if (queryImports.includes('infiniteQuery')) {\n imports = [...imports, 'useInfiniteQuery', 'UseInfiniteQueryOptions', 'QueryKey'];\n }\n if (queryImports.includes('mutation')) {\n imports = [...imports, 'UseMutationOptions', 'useMutation'];\n }\n\n const importString = [...new Set(imports)].join(',');\n\n return `\n import {\n ${importString}\n } from '@tanstack/react-query';\n \n import { AxiosError } from 'axios';\n import { api } from '${apiDirectory}';\n import { queryClient } from '${queryClientDir}';\n\n import {${importTypes}} from './${schemaName}'\n\n type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput); \n `;\n};\n"],"mappings":";;;;;;;AAAO,MAAMA,eAAe,GAAG,QAYzB;EAAA,IAZ0B;IAC9BC,UAD8B;IAE9BC,YAF8B;IAG9BC,cAH8B;IAI9BC,aAJ8B;IAK9BC;EAL8B,CAY1B;EACJ,MAAMC,WAAW,GAAGF,aAAa,CAACG,IAAd,CAAmB,GAAnB,CAApB;EACA,IAAIC,OAAO,GAAG,EAAd;;EACA,IAAIH,YAAY,CAACI,QAAb,CAAsB,OAAtB,CAAJ,EAAoC;IAClCD,OAAO,GAAG,CAAC,GAAGA,OAAJ,EAAa,UAAb,EAAyB,iBAAzB,EAA4C,UAA5C,EAAwD,gBAAxD,EAA0E,cAA1E,CAAV;EACD;;EACD,IAAIH,YAAY,CAACI,QAAb,CAAsB,eAAtB,CAAJ,EAA4C;IAC1CD,OAAO,GAAG,CAAC,GAAGA,OAAJ,EAAa,kBAAb,EAAiC,yBAAjC,EAA4D,UAA5D,CAAV;EACD;;EACD,IAAIH,YAAY,CAACI,QAAb,CAAsB,UAAtB,CAAJ,EAAuC;IACrCD,OAAO,GAAG,CAAC,GAAGA,OAAJ,EAAa,oBAAb,EAAmC,aAAnC,CAAV;EACD;;EAED,MAAME,YAAY,GAAG,CAAC,GAAG,IAAIC,GAAJ,CAAQH,OAAR,CAAJ,EAAsBD,IAAtB,CAA2B,GAA3B,CAArB;EAEA,OAAQ;AACV;AACA,MAAMG,YAAa;AACnB;AACA;AACA;AACA,yBAAyBR,YAAa;AACtC,iCAAiCC,cAAe;AAChD;AACA,YAAYG,WAAY,aAAYL,UAAW;AAC/C;AACA;AACA,GAZE;AAaD,CAxCM"}
|