react-query-lightbase-codegen 1.0.5 → 1.1.1
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/README.md +1 -1
- package/lib/cjs/convertSwaggerFile.js +32 -0
- package/lib/cjs/generateHooks.js +368 -0
- package/lib/cjs/generateImports.js +26 -0
- package/lib/cjs/generateSchemas.js +104 -0
- package/lib/cjs/importSpecs.js +46 -0
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/utils.js +165 -0
- package/{dist → lib/esm}/convertSwaggerFile.js +0 -1
- package/lib/esm/generateHooks.js +360 -0
- package/lib/esm/generateImports.js +22 -0
- package/{dist → lib/esm}/generateSchemas.js +7 -7
- package/lib/esm/importSpecs.js +39 -0
- package/{dist/index.d.ts → lib/esm/index.js} +0 -0
- package/{dist → lib/esm}/utils.js +18 -22
- package/package.json +5 -5
- package/src/importSpecs.ts +17 -7
- package/dist/convertSwaggerFile.d.ts +0 -5
- package/dist/convertSwaggerFile.js.map +0 -1
- package/dist/generateHooks.d.ts +0 -25
- package/dist/generateHooks.js +0 -393
- package/dist/generateHooks.js.map +0 -1
- package/dist/generateImports.d.ts +0 -7
- package/dist/generateImports.js +0 -28
- package/dist/generateImports.js.map +0 -1
- package/dist/generateSchemas.d.ts +0 -7
- package/dist/generateSchemas.js.map +0 -1
- package/dist/importSpecs.d.ts +0 -15
- package/dist/importSpecs.js +0 -81
- package/dist/importSpecs.js.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/utils.d.ts +0 -24
- package/dist/utils.js.map +0 -1
|
@@ -122,10 +122,9 @@ export const resolveValue = (schema) => isReference(schema) ? getRef(schema.$ref
|
|
|
122
122
|
* Format a description to code documentation.
|
|
123
123
|
*/
|
|
124
124
|
export const formatDescription = (description) => {
|
|
125
|
-
if (!description)
|
|
125
|
+
if (!description)
|
|
126
126
|
return '';
|
|
127
|
-
|
|
128
|
-
return `\n/**\n${description
|
|
127
|
+
return `/**\n${description
|
|
129
128
|
.split('\n')
|
|
130
129
|
.map((i) => `* ${i}`)
|
|
131
130
|
.join('\n')}\n */`;
|
|
@@ -133,25 +132,22 @@ export const formatDescription = (description) => {
|
|
|
133
132
|
/**
|
|
134
133
|
* Extract responses / request types from open-api specs
|
|
135
134
|
*/
|
|
136
|
-
export const getResReqTypes = (responsesOrRequests) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return resolveValue(schema);
|
|
150
|
-
}
|
|
135
|
+
export const getResReqTypes = (responsesOrRequests) => uniq(responsesOrRequests.map(([_, res]) => {
|
|
136
|
+
if (!res) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isReference(res)) {
|
|
140
|
+
return getRef(res.$ref);
|
|
141
|
+
}
|
|
142
|
+
if (res.content) {
|
|
143
|
+
for (let contentType of Object.keys(res.content)) {
|
|
144
|
+
if (contentType.startsWith('application/json') ||
|
|
145
|
+
contentType.startsWith('application/octet-stream')) {
|
|
146
|
+
const schema = res.content[contentType].schema;
|
|
147
|
+
return resolveValue(schema);
|
|
151
148
|
}
|
|
152
|
-
return;
|
|
153
149
|
}
|
|
154
150
|
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
})).join(' | ');
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-query-lightbase-codegen",
|
|
3
3
|
"description": "Fully typed react query code generation tool based on openApi specifications",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"exports": "./
|
|
7
|
+
"exports": "./lib/index.js",
|
|
8
8
|
"files": [
|
|
9
9
|
"src",
|
|
10
|
-
"
|
|
10
|
+
"lib"
|
|
11
11
|
],
|
|
12
12
|
"keywords": [
|
|
13
13
|
"rest",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/lightbasenl/react-query-codegen"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=14.16"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
39
39
|
"tsc": "tsc -p tsconfig.json",
|
|
40
|
-
"test": "yarn tsc && node test/script.mjs
|
|
40
|
+
"test": "yarn tsc && node test/script.mjs",
|
|
41
41
|
"deploy": "tsc && semantic-release --no-ci",
|
|
42
42
|
"prepare": "husky install"
|
|
43
43
|
},
|
package/src/importSpecs.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Case from 'case';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
3
|
import { readFileSync, writeFileSync, readdir, mkdirSync } from 'fs';
|
|
3
4
|
import { OperationObject, PathItemObject } from 'openapi3-ts';
|
|
@@ -6,6 +7,7 @@ import { convertSwaggerFile } from './convertSwaggerFile.js';
|
|
|
6
7
|
import { createHook } from './generateHooks.js';
|
|
7
8
|
import { generateImports } from './generateImports.js';
|
|
8
9
|
import { generateSchemas } from './generateSchemas.js';
|
|
10
|
+
import execa from 'execa';
|
|
9
11
|
|
|
10
12
|
export function importSpecs({
|
|
11
13
|
sourceDirectory,
|
|
@@ -25,20 +27,21 @@ export function importSpecs({
|
|
|
25
27
|
{ type: 'query' } | { type: 'mutation' } | { type: 'infiniteQuery'; infiniteQueryParm: string }
|
|
26
28
|
>;
|
|
27
29
|
}) {
|
|
28
|
-
readdir(sourceDirectory,
|
|
30
|
+
readdir(sourceDirectory, async (err, filenames) => {
|
|
29
31
|
if (err) {
|
|
30
32
|
console.log(err);
|
|
31
33
|
throw err;
|
|
32
34
|
}
|
|
33
|
-
filenames.
|
|
35
|
+
filenames.forEach(async (filename) => {
|
|
34
36
|
try {
|
|
35
37
|
const data = readFileSync(join(process.cwd(), sourceDirectory + '/' + filename), 'utf-8');
|
|
36
38
|
const { ext } = parse(sourceDirectory + '/' + filename);
|
|
37
39
|
const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
|
|
38
40
|
let spec = await convertSwaggerFile(data, format);
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
+
const formattedFileName = Case.camel(`useQueries, ${filename.split('.')[0]}`);
|
|
43
|
+
const schemaName = `${formattedFileName}.schema`;
|
|
44
|
+
const hooksName = `${formattedFileName}`;
|
|
42
45
|
const name = filename.split('.')[0];
|
|
43
46
|
mkdirSync(join(process.cwd(), `${exportDirectory}/${name}`), { recursive: true });
|
|
44
47
|
|
|
@@ -92,12 +95,19 @@ export function importSpecs({
|
|
|
92
95
|
|
|
93
96
|
writeFileSync(join(process.cwd(), `${exportDirectory}/${name}/${hooksName}.tsx`), imports + hooks);
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
writeFileSync(
|
|
99
|
+
join(process.cwd(), `${exportDirectory}/${name}/${schemaName}.tsx`),
|
|
100
|
+
generateSchemas({ spec })
|
|
101
|
+
);
|
|
98
102
|
console.log(
|
|
99
103
|
chalk.green(`🎉 [${filename}] Your OpenAPI spec has been converted into react query hooks`)
|
|
100
104
|
);
|
|
105
|
+
try {
|
|
106
|
+
execa.sync('prettier', ['--write', `./${exportDirectory}/${name}/*.tsx`]);
|
|
107
|
+
console.log(chalk.blue(`⚙️ Running prettier`));
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.log(chalk.yellow(`⚠️ Prettier not found`));
|
|
110
|
+
}
|
|
101
111
|
} catch (error) {
|
|
102
112
|
if ((error as any).code === 'EISDIR') {
|
|
103
113
|
console.log(chalk.red('nested folder structure not supported'));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertSwaggerFile.js","sourceRoot":"","sources":["../src/convertSwaggerFile.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAC9C,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,SAA0B,EAA0B,EAAE;IACrG,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACvD,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE;gBAC3D,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC,CAAC;iBACb;qBAAM;oBACL,aAAa;oBACb,YAAY,CAAC,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBAC/D,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;iBAC/B;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,CAAC,MAAM,CAAC,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/generateHooks.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ComponentsObject, OperationObject, ParameterObject, ReferenceObject } from 'openapi3-ts';
|
|
2
|
-
/**
|
|
3
|
-
* Generate a react-query component from openapi operation specs
|
|
4
|
-
*/
|
|
5
|
-
export declare const createHook: ({ operation, verb, route, operationIds, parameters, schemasComponents, headerFilters, overrides, }: {
|
|
6
|
-
operation: OperationObject;
|
|
7
|
-
verb: string;
|
|
8
|
-
route: string;
|
|
9
|
-
operationIds: string[];
|
|
10
|
-
parameters: (ReferenceObject | ParameterObject)[] | undefined;
|
|
11
|
-
schemasComponents?: ComponentsObject | undefined;
|
|
12
|
-
headerFilters?: string[] | undefined;
|
|
13
|
-
overrides?: Record<string, {
|
|
14
|
-
type: 'query';
|
|
15
|
-
} | {
|
|
16
|
-
type: 'mutation';
|
|
17
|
-
} | {
|
|
18
|
-
type: 'infiniteQuery';
|
|
19
|
-
infiniteQueryParm: string;
|
|
20
|
-
}> | undefined;
|
|
21
|
-
}) => {
|
|
22
|
-
implementation: string;
|
|
23
|
-
imports: string[];
|
|
24
|
-
queryImports: ("query" | "mutation" | "infiniteQuery")[];
|
|
25
|
-
};
|
package/dist/generateHooks.js
DELETED
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
import lodash from 'lodash';
|
|
2
|
-
const { get, groupBy } = lodash;
|
|
3
|
-
import { formatDescription, getResReqTypes, isReference, resolveValue } from './utils.js';
|
|
4
|
-
import pasCase from 'case';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
const { pascal, camel } = pasCase;
|
|
7
|
-
const IdentifierRegexp = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
8
|
-
/**
|
|
9
|
-
* Return every params in a path
|
|
10
|
-
*/
|
|
11
|
-
const getParamsInPath = (path) => {
|
|
12
|
-
let n;
|
|
13
|
-
const output = [];
|
|
14
|
-
const templatePathRegex = /\{(\w+)}/g;
|
|
15
|
-
while ((n = templatePathRegex.exec(path)) !== null) {
|
|
16
|
-
output.push(n[1]);
|
|
17
|
-
}
|
|
18
|
-
return output;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Generate a react-query component from openapi operation specs
|
|
22
|
-
*/
|
|
23
|
-
export const createHook = ({ operation, verb, route, operationIds, parameters, schemasComponents, headerFilters, overrides, }) => {
|
|
24
|
-
const { operationId = route.replace('/', '') } = operation;
|
|
25
|
-
if (operationId === '*') {
|
|
26
|
-
throw new Error(`Invalid operationId/Route set for ${verb} ${route}`);
|
|
27
|
-
}
|
|
28
|
-
if (operationIds.includes(operationId)) {
|
|
29
|
-
return { implementation: '', imports: [], queryImports: [] };
|
|
30
|
-
}
|
|
31
|
-
operationIds.push(operationId);
|
|
32
|
-
route = route.replace(/\{/g, '${').replace('//', '/'); // `/pet/{id}` => `/pet/${id}`
|
|
33
|
-
// Remove the last param of the route if we are in the DELETE case
|
|
34
|
-
let lastParamInTheRoute = null;
|
|
35
|
-
const componentName = pascal(operationId);
|
|
36
|
-
const isOk = ([statusCode]) => statusCode.toString().startsWith('2');
|
|
37
|
-
const responseTypes = getResReqTypes(Object.entries(operation.responses).filter(isOk)) || 'void';
|
|
38
|
-
const requestBodyTypes = getResReqTypes([['body', operation.requestBody]]);
|
|
39
|
-
let imports = [responseTypes];
|
|
40
|
-
let queryImports = [];
|
|
41
|
-
const paramsInPath = getParamsInPath(route).filter((param) => !(verb === 'delete' && param === lastParamInTheRoute));
|
|
42
|
-
const { query: queryParams = [], path: pathParams = [], header = [], } = groupBy([...(parameters || []), ...(operation.parameters || [])].map((p) => {
|
|
43
|
-
if (isReference(p)) {
|
|
44
|
-
return get(schemasComponents, p.$ref.replace('#/components/', '').replace('/', '.'));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return p;
|
|
48
|
-
}
|
|
49
|
-
}), 'in');
|
|
50
|
-
const headerParams = header.filter((p) => !headerFilters?.includes(p.name));
|
|
51
|
-
let enabled = [];
|
|
52
|
-
// TODO: extract all requestBody or remove useQuery variants
|
|
53
|
-
let enabledParam = '!!params';
|
|
54
|
-
[...queryParams, ...pathParams, ...headerParams].forEach((item) => {
|
|
55
|
-
if (item.required) {
|
|
56
|
-
enabled.push(`["${item.name}"]`);
|
|
57
|
-
if (enabledParam && enabledParam !== '!!params') {
|
|
58
|
-
enabledParam += `&& params['${item.name}'] != null`;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
enabledParam = `params['${item.name}'] != null`;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
// `!props${enabled.join('== null && !props')}`;
|
|
66
|
-
const paramsTypes = paramsInPath
|
|
67
|
-
.map((p) => {
|
|
68
|
-
try {
|
|
69
|
-
const { name, required, schema } = pathParams.find((i) => i.name === p);
|
|
70
|
-
return `${name}${required ? '' : '?'}: ${resolveValue(schema)}`;
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
.join('; ');
|
|
77
|
-
const queryParamsType = queryParams
|
|
78
|
-
.map((p) => {
|
|
79
|
-
const processedName = IdentifierRegexp.test(p.name) ? p.name : `"${p.name}"`;
|
|
80
|
-
return `${formatDescription(p.description)}
|
|
81
|
-
${processedName}${p.required ? '' : '?'}: ${resolveValue(p.schema)}`;
|
|
82
|
-
})
|
|
83
|
-
.join(';\n ');
|
|
84
|
-
const headerType = headerParams
|
|
85
|
-
.map((p) => {
|
|
86
|
-
try {
|
|
87
|
-
const { name, required, schema } = headerParams.find((i) => i.name === p.name);
|
|
88
|
-
return `"${name}"${required ? '' : '?'}: ${resolveValue(schema)}`;
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
throw new Error(`The path params ${p} can't be found in parameters (${operationId})`);
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
.join('; ');
|
|
95
|
-
// Retrieve the type of the param for delete verb
|
|
96
|
-
const lastParamInTheRouteDefinition = operation.parameters && lastParamInTheRoute
|
|
97
|
-
? operation.parameters.find((p) => {
|
|
98
|
-
if (isReference(p)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return p.name === lastParamInTheRoute;
|
|
102
|
-
}) // Reference is not possible
|
|
103
|
-
: { schema: { type: 'string' } };
|
|
104
|
-
if (!lastParamInTheRouteDefinition) {
|
|
105
|
-
throw new Error(`The path params ${lastParamInTheRoute} can't be found in parameters (${operationId})`);
|
|
106
|
-
}
|
|
107
|
-
const defaultDescription = `type: ${verb}\noperationId: ${operationId}\nurl: ${route}`;
|
|
108
|
-
const description = formatDescription(operation.summary && operation.description
|
|
109
|
-
? `${defaultDescription}\n\n${operation.summary}\n\n${operation.description}`
|
|
110
|
-
: `${defaultDescription}`);
|
|
111
|
-
let output = `\n\n${description}`;
|
|
112
|
-
const headerParam = headerType && headerType !== 'void' ? `${headerType};` : '';
|
|
113
|
-
const queryParam = queryParamsType && queryParamsType !== 'void' ? `${queryParamsType}` : '';
|
|
114
|
-
const requestBodyComponent = requestBodyTypes && requestBodyTypes !== 'void' ? `${requestBodyTypes}` : '';
|
|
115
|
-
if (requestBodyComponent) {
|
|
116
|
-
imports.push(requestBodyComponent);
|
|
117
|
-
}
|
|
118
|
-
const isUpdateRequest = ['post', 'patch', 'put'].includes(verb);
|
|
119
|
-
const fetchName = camel(componentName);
|
|
120
|
-
const createQueryHooks = (emptyParams) => {
|
|
121
|
-
const params = emptyParams ? '' : `params: ${componentName}Params,`;
|
|
122
|
-
const key = emptyParams ? '' : `params`;
|
|
123
|
-
const mutationParams = emptyParams ? 'void' : `${componentName}Params`;
|
|
124
|
-
const queryParamType = emptyParams ? '' : `${componentName}Params &`;
|
|
125
|
-
const filterParams = emptyParams
|
|
126
|
-
? '{ filters }: { filters?: QueryFilters }'
|
|
127
|
-
: `{ params, filters }: { params: ${componentName}Params, filters?: QueryFilters }`;
|
|
128
|
-
const cacheParams = emptyParams
|
|
129
|
-
? `{updater, options}: {updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}`
|
|
130
|
-
: `{params, updater, options}: {params: ${componentName}Params, updater: Updater<${responseTypes} | undefined, ${responseTypes} | undefined>, options?: SetDataOptions | undefined}`;
|
|
131
|
-
const queryKey = emptyParams
|
|
132
|
-
? `use${componentName}Query.baseKey()`
|
|
133
|
-
: `[...use${componentName}Query.baseKey(), params]`;
|
|
134
|
-
const createQuery = () => `
|
|
135
|
-
type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {
|
|
136
|
-
options?: UseQueryOptions<${responseTypes}, AxiosError, T, any>
|
|
137
|
-
}
|
|
138
|
-
export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) {
|
|
139
|
-
return useQuery(use${componentName}Query.queryKey(${key}), async () => ${fetchName}(${key}), { enabled: ${enabledParam}, ...options });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
143
|
-
|
|
144
|
-
use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};
|
|
145
|
-
|
|
146
|
-
use${componentName}Query.updateCache = (${cacheParams}) => queryClient.setQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), updater, options);
|
|
147
|
-
|
|
148
|
-
use${componentName}Query.getQueryState = (${filterParams})=> queryClient.getQueryState<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);
|
|
149
|
-
|
|
150
|
-
use${componentName}Query.getQueryData = (${filterParams})=> queryClient.getQueryData<${responseTypes}>(use${componentName}Query.queryKey(${key}), filters);
|
|
151
|
-
|
|
152
|
-
use${componentName}Query.prefetch = (${params}) => queryClient.prefetchQuery<${responseTypes}>(use${componentName}Query.queryKey(${key}), ()=> ${fetchName}(${key}));
|
|
153
|
-
|
|
154
|
-
use${componentName}Query.cancelQueries = (${params}) => queryClient.cancelQueries(use${componentName}Query.queryKey(${key}))
|
|
155
|
-
|
|
156
|
-
use${componentName}Query.invalidate = (${params}) => queryClient.invalidateQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}));
|
|
157
|
-
|
|
158
|
-
use${componentName}Query.refetchStale = (${params}) => queryClient.refetchQueries<${responseTypes}>(use${componentName}Query.queryKey(${key}), { stale: true });
|
|
159
|
-
`;
|
|
160
|
-
const getInfiniteQuery = ({ pageParam }) => `
|
|
161
|
-
type ${componentName}QueryProps<T = ${responseTypes}> = ${queryParamType} {
|
|
162
|
-
options: UseInfiniteQueryOptions<${responseTypes}, AxiosError, T, any>
|
|
163
|
-
}
|
|
164
|
-
export function use${componentName}Query<T = ${responseTypes}>({ options = {}, ...params }: ${componentName}QueryProps<T>) {
|
|
165
|
-
return useInfiniteQuery(use${componentName}Query.queryKey(${key}), async ({ pageParam = 0 }) => ${fetchName}({${pageParam}: pageParam, ...params}), { enabled: ${enabledParam}, ...options });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
169
|
-
|
|
170
|
-
use${componentName}Query.queryKey = (${params}): QueryKey => ${queryKey};
|
|
171
|
-
|
|
172
|
-
`;
|
|
173
|
-
const createMutation = () => `
|
|
174
|
-
type ${componentName}MutationProps<T> = {
|
|
175
|
-
options?: UseMutationOptions<${responseTypes}, AxiosError, ${mutationParams}, T>
|
|
176
|
-
}
|
|
177
|
-
export function use${componentName}Mutation<T = ${responseTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
178
|
-
return useMutation(async (${key}) => ${fetchName}(${key}), props?.options)
|
|
179
|
-
};
|
|
180
|
-
`;
|
|
181
|
-
const override = overrides?.[operationId];
|
|
182
|
-
if (override?.type === 'query') {
|
|
183
|
-
console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useQuery hook`));
|
|
184
|
-
queryImports.push('query');
|
|
185
|
-
return createQuery();
|
|
186
|
-
}
|
|
187
|
-
if (override?.type === 'mutation') {
|
|
188
|
-
queryImports.push('mutation');
|
|
189
|
-
console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useMutation hook`));
|
|
190
|
-
return createMutation();
|
|
191
|
-
}
|
|
192
|
-
if (override?.type === 'infiniteQuery') {
|
|
193
|
-
console.log(chalk.blue(`⚙️ [${operationId}] has been changed to a useInfiniteQuery hook`));
|
|
194
|
-
queryImports.push('infiniteQuery');
|
|
195
|
-
return getInfiniteQuery({ pageParam: override.infiniteQueryParm });
|
|
196
|
-
}
|
|
197
|
-
if (verb === 'get') {
|
|
198
|
-
queryImports.push('query');
|
|
199
|
-
return createQuery();
|
|
200
|
-
}
|
|
201
|
-
queryImports.push('mutation');
|
|
202
|
-
return createMutation();
|
|
203
|
-
};
|
|
204
|
-
output += createQueryHooks(!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam);
|
|
205
|
-
const hasRequestBodyArrray = requestBodyComponent && requestBodyComponent.includes('[]');
|
|
206
|
-
const body = hasRequestBodyArrray ? `{body: ${requestBodyComponent}}` : `${requestBodyComponent}`;
|
|
207
|
-
const bodyProps = hasRequestBodyArrray ? `{body, ...props}` : '{props}';
|
|
208
|
-
const generateProps = (props) => {
|
|
209
|
-
return props.map((item) => `["${item.name}"]: props["${item.name}"]`).join(',');
|
|
210
|
-
};
|
|
211
|
-
const generateBodyProps = () => {
|
|
212
|
-
const definitionKey = Object.keys(schemasComponents?.schemas || {}).find((key) => pascal(key) === requestBodyComponent);
|
|
213
|
-
if (definitionKey && !hasRequestBodyArrray) {
|
|
214
|
-
const scheme = schemasComponents?.schemas?.[definitionKey];
|
|
215
|
-
const generatedBodyProps = Object.keys(scheme.properties)
|
|
216
|
-
.map((item) => `["${item}"]: props["${item}"]`)
|
|
217
|
-
.join(',');
|
|
218
|
-
return `const body = {${generatedBodyProps}}`;
|
|
219
|
-
}
|
|
220
|
-
return '';
|
|
221
|
-
};
|
|
222
|
-
if (!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
223
|
-
output += `
|
|
224
|
-
const ${fetchName} = async () => {
|
|
225
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`);
|
|
226
|
-
return result.data;
|
|
227
|
-
}
|
|
228
|
-
`;
|
|
229
|
-
}
|
|
230
|
-
if (!requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
231
|
-
const config = isUpdateRequest ? 'body,{params}' : '{params}';
|
|
232
|
-
output += `
|
|
233
|
-
type ${componentName}Params = {
|
|
234
|
-
${paramsTypes}
|
|
235
|
-
${queryParamsType};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const ${fetchName} = async (props:${componentName}Params) => {
|
|
239
|
-
const {${paramsInPath.join(', ')}, ...params} = props
|
|
240
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
241
|
-
return result.data;
|
|
242
|
-
}`;
|
|
243
|
-
}
|
|
244
|
-
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
245
|
-
output += `
|
|
246
|
-
type ${componentName}Params = {
|
|
247
|
-
${paramsTypes}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const ${fetchName} = async (props: ${componentName}Params ) => {
|
|
251
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`);
|
|
252
|
-
return result.data;
|
|
253
|
-
}
|
|
254
|
-
`;
|
|
255
|
-
}
|
|
256
|
-
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
257
|
-
const config = isUpdateRequest ? 'null,{params}' : '{params}';
|
|
258
|
-
output += `
|
|
259
|
-
type ${componentName}Params = {
|
|
260
|
-
${queryParamsType}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const ${fetchName} = async (params: ${componentName}Params) => {
|
|
264
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
265
|
-
return result.data;
|
|
266
|
-
}
|
|
267
|
-
`;
|
|
268
|
-
}
|
|
269
|
-
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
270
|
-
const config = isUpdateRequest ? 'null,{headers, params: queryParams}' : '{headers, params: queryParams}';
|
|
271
|
-
output += `
|
|
272
|
-
type ${componentName}Params = {
|
|
273
|
-
${headerParam}
|
|
274
|
-
${queryParamsType}
|
|
275
|
-
}
|
|
276
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
277
|
-
const headers = {${generateProps(header)}}
|
|
278
|
-
const queryParams = {${generateProps(queryParams)}}
|
|
279
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config})
|
|
280
|
-
return result.data
|
|
281
|
-
}`;
|
|
282
|
-
}
|
|
283
|
-
if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
284
|
-
const config = isUpdateRequest ? 'null,{headers}' : '{headers}';
|
|
285
|
-
output += `
|
|
286
|
-
type ${componentName}Params = {
|
|
287
|
-
${headerParam}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
const ${fetchName} = async (headers: ${componentName}Params) => {
|
|
291
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, ${config});
|
|
292
|
-
return result.data;
|
|
293
|
-
}
|
|
294
|
-
`;
|
|
295
|
-
}
|
|
296
|
-
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
297
|
-
output += `
|
|
298
|
-
type ${componentName}Params = ${requestBodyComponent}
|
|
299
|
-
|
|
300
|
-
const ${fetchName} = async (body: ${componentName}Params) => {
|
|
301
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body)
|
|
302
|
-
return result.data
|
|
303
|
-
}
|
|
304
|
-
`;
|
|
305
|
-
}
|
|
306
|
-
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
307
|
-
output += `
|
|
308
|
-
type ${componentName}Params = ${body} & {
|
|
309
|
-
${queryParamsType}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const ${fetchName} = async (${bodyProps}: ${componentName}Params) => {
|
|
313
|
-
${generateBodyProps()}
|
|
314
|
-
const params = {${generateProps(queryParams)}}
|
|
315
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body, {params})
|
|
316
|
-
return result.data
|
|
317
|
-
}
|
|
318
|
-
`;
|
|
319
|
-
}
|
|
320
|
-
if (requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
321
|
-
output += `
|
|
322
|
-
type ${componentName}Params = ${body} & {
|
|
323
|
-
${headerParam}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
const ${fetchName} = async (${bodyProps}: ${componentName}Params) => {
|
|
327
|
-
${generateBodyProps()}
|
|
328
|
-
const headers = {${generateProps(header)}}
|
|
329
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body, {headers})
|
|
330
|
-
return result.data
|
|
331
|
-
}
|
|
332
|
-
`;
|
|
333
|
-
}
|
|
334
|
-
if (requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
335
|
-
output += `
|
|
336
|
-
type ${componentName}Params = ${body} & {
|
|
337
|
-
${headerParam}
|
|
338
|
-
${paramsTypes}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const ${fetchName} = async (${bodyProps}: ${componentName}Params) => {
|
|
342
|
-
${generateBodyProps()}
|
|
343
|
-
const headers = {${generateProps(header)}}
|
|
344
|
-
const params = {${generateProps(queryParams)}}
|
|
345
|
-
const result = await api.${verb}<${responseTypes}>(\`${route}\`, body, {headers, params})
|
|
346
|
-
return result.data
|
|
347
|
-
}
|
|
348
|
-
`;
|
|
349
|
-
}
|
|
350
|
-
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
351
|
-
output += `
|
|
352
|
-
type ${componentName}Params = ${body} & {
|
|
353
|
-
${headerParam}
|
|
354
|
-
${paramsTypes}
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
const ${fetchName} = async (${bodyProps}: ${componentName}Params) => {
|
|
358
|
-
${generateBodyProps()}
|
|
359
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`, body)
|
|
360
|
-
return result.data
|
|
361
|
-
}
|
|
362
|
-
`;
|
|
363
|
-
}
|
|
364
|
-
if (requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
365
|
-
output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam)`;
|
|
366
|
-
}
|
|
367
|
-
if (requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
368
|
-
output += `// TODO: NOT SUPPORTED requestBodyComponent && paramsInPath && queryParam && headerParam)`;
|
|
369
|
-
}
|
|
370
|
-
if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
371
|
-
const config = isUpdateRequest ? 'null,{headers}' : '{headers}';
|
|
372
|
-
output += `
|
|
373
|
-
type ${componentName}Params = {
|
|
374
|
-
${headerParam}
|
|
375
|
-
${paramsTypes}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
const ${fetchName} = async (props: ${componentName}Params) => {
|
|
379
|
-
const headers = {${generateProps(header)}}
|
|
380
|
-
const result = await api.${verb}<${responseTypes}>(\`${route.replace(/\{/g, '{props.')}\`, ${config})
|
|
381
|
-
return result.data
|
|
382
|
-
}
|
|
383
|
-
`;
|
|
384
|
-
}
|
|
385
|
-
if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
386
|
-
output += `// TODO: NOT SUPPORTED (paramsInPath && queryParam && headerParam)`;
|
|
387
|
-
}
|
|
388
|
-
if (requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
389
|
-
output += `// TODO: NOT SUPPORTED (requestBodyComponent && paramsInPath && headerParam)`;
|
|
390
|
-
}
|
|
391
|
-
return { implementation: output, imports, queryImports };
|
|
392
|
-
};
|
|
393
|
-
//# sourceMappingURL=generateHooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateHooks.js","sourceRoot":"","sources":["../src/generateHooks.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;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AoE,CAAC;KAChF;IAED,IAAI,oBAAoB,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,UAAU,IAAI,WAAW,EAAE;QAC7E,MAAM,IAAI,8EAA8E,CAAC;KAC1F;IAED,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAC3D,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const generateImports: ({ schemaName, apiDirectory, queryClientDir, schemaImports, queryImports, }: {
|
|
2
|
-
apiDirectory: string;
|
|
3
|
-
queryClientDir: string;
|
|
4
|
-
schemaName: string;
|
|
5
|
-
schemaImports: string[];
|
|
6
|
-
queryImports: ('query' | 'mutation' | 'infiniteQuery')[];
|
|
7
|
-
}) => string;
|
package/dist/generateImports.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const generateImports = ({ schemaName, apiDirectory, queryClientDir, schemaImports, queryImports, }) => {
|
|
2
|
-
const importTypes = schemaImports.join(',');
|
|
3
|
-
let imports = [];
|
|
4
|
-
if (queryImports.includes('query')) {
|
|
5
|
-
imports = [...imports, 'useQuery', 'UseQueryOptions', 'QueryKey', 'SetDataOptions', 'QueryFilters'];
|
|
6
|
-
}
|
|
7
|
-
if (queryImports.includes('infiniteQuery')) {
|
|
8
|
-
imports = [...imports, 'useInfiniteQuery', 'UseInfiniteQueryOptions', 'QueryKey'];
|
|
9
|
-
}
|
|
10
|
-
if (queryImports.includes('mutation')) {
|
|
11
|
-
imports = [...imports, 'UseMutationOptions', 'useMutation'];
|
|
12
|
-
}
|
|
13
|
-
const importString = [...new Set(imports)].join(',');
|
|
14
|
-
return `
|
|
15
|
-
import {
|
|
16
|
-
${importString}
|
|
17
|
-
} from '@tanstack/react-query';
|
|
18
|
-
|
|
19
|
-
import { AxiosError } from 'axios';
|
|
20
|
-
import { api } from '${apiDirectory}';
|
|
21
|
-
import { queryClient } from '${queryClientDir}';
|
|
22
|
-
|
|
23
|
-
import {${importTypes}} from './${schemaName}'
|
|
24
|
-
|
|
25
|
-
type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
|
|
26
|
-
`;
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=generateImports.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateImports.js","sourceRoot":"","sources":["../src/generateImports.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,UAAU,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,YAAY,GAOb,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAc,CAAC;IAC7B,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClC,OAAO,GAAG,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;KACrG;IACD,IAAI,YAAY,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAC1C,OAAO,GAAG,CAAC,GAAG,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,UAAU,CAAC,CAAC;KACnF;IACD,IAAI,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACrC,OAAO,GAAG,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,aAAa,CAAC,CAAC;KAC7D;IAED,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAErD,OAAO;;MAEH,YAAY;;;;yBAIO,YAAY;iCACJ,cAAc;;YAEnC,WAAW,aAAa,UAAU;;;GAG3C,CAAC;AACJ,CAAC,CAAC"}
|