react-query-lightbase-codegen 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/import-open-api.js +16 -6
- package/lib/esm/import-open-api.js +16 -6
- package/package.json +2 -2
|
@@ -345,12 +345,20 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
345
345
|
}), 'in');
|
|
346
346
|
const headerParams = header.filter((p) => !headerFilters?.includes(p.name));
|
|
347
347
|
let enabled = [];
|
|
348
|
+
// TODO: extract all requestBody or remove useQuery variants
|
|
349
|
+
let enabledParam = '!!props';
|
|
348
350
|
[...queryParams, ...pathParams, ...headerParams].forEach((item) => {
|
|
349
351
|
if (item.required) {
|
|
350
352
|
enabled.push(`["${item.name}"]`);
|
|
353
|
+
if (enabledParam && enabledParam !== '!!props') {
|
|
354
|
+
enabledParam += `&& props['${item.name}'] != null`;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
enabledParam = `props['${item.name}'] != null`;
|
|
358
|
+
}
|
|
351
359
|
}
|
|
352
360
|
});
|
|
353
|
-
|
|
361
|
+
// `!props${enabled.join('== null && !props')}`;
|
|
354
362
|
const paramsTypes = paramsInPath
|
|
355
363
|
.map((p) => {
|
|
356
364
|
try {
|
|
@@ -904,8 +912,8 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
904
912
|
type ${componentName}QueryProps<T = ${componentName}Return> = ${componentName}Variables & {
|
|
905
913
|
options?: UseQueryOptions<${componentName}Return, AxiosError, T, any>
|
|
906
914
|
}
|
|
907
|
-
export function use${componentName}Query<T = ${componentName}Return>({ options = {}, ...
|
|
908
|
-
return useQuery(use${componentName}Query.queryKey(
|
|
915
|
+
export function use${componentName}Query<T = ${componentName}Return>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
916
|
+
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
909
917
|
{ enabled: ${enabledParam}, ...options }
|
|
910
918
|
);}
|
|
911
919
|
|
|
@@ -960,14 +968,16 @@ const importOpenApi = async ({ data, format, apiDirectory, queryClientDir, heade
|
|
|
960
968
|
UseMutationOptions,
|
|
961
969
|
QueryKey,
|
|
962
970
|
SetDataOptions,
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
971
|
+
QueryFilters
|
|
972
|
+
} from '@tanstack/react-query';
|
|
973
|
+
|
|
966
974
|
import queryString from 'query-string';
|
|
967
975
|
import { AxiosError } from 'axios';
|
|
968
976
|
import { api } from '${apiDirectory}';
|
|
969
977
|
import { queryClient } from '${queryClientDir}';
|
|
970
978
|
|
|
979
|
+
type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
|
|
980
|
+
|
|
971
981
|
// SCEHMAS
|
|
972
982
|
${(0, exports.generateSchemasDefinition)(specs.components?.schemas)}
|
|
973
983
|
|
|
@@ -325,12 +325,20 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
325
325
|
}), 'in');
|
|
326
326
|
const headerParams = header.filter((p) => !headerFilters?.includes(p.name));
|
|
327
327
|
let enabled = [];
|
|
328
|
+
// TODO: extract all requestBody or remove useQuery variants
|
|
329
|
+
let enabledParam = '!!props';
|
|
328
330
|
[...queryParams, ...pathParams, ...headerParams].forEach((item) => {
|
|
329
331
|
if (item.required) {
|
|
330
332
|
enabled.push(`["${item.name}"]`);
|
|
333
|
+
if (enabledParam && enabledParam !== '!!props') {
|
|
334
|
+
enabledParam += `&& props['${item.name}'] != null`;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
enabledParam = `props['${item.name}'] != null`;
|
|
338
|
+
}
|
|
331
339
|
}
|
|
332
340
|
});
|
|
333
|
-
|
|
341
|
+
// `!props${enabled.join('== null && !props')}`;
|
|
334
342
|
const paramsTypes = paramsInPath
|
|
335
343
|
.map((p) => {
|
|
336
344
|
try {
|
|
@@ -884,8 +892,8 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
884
892
|
type ${componentName}QueryProps<T = ${componentName}Return> = ${componentName}Variables & {
|
|
885
893
|
options?: UseQueryOptions<${componentName}Return, AxiosError, T, any>
|
|
886
894
|
}
|
|
887
|
-
export function use${componentName}Query<T = ${componentName}Return>({ options = {}, ...
|
|
888
|
-
return useQuery(use${componentName}Query.queryKey(
|
|
895
|
+
export function use${componentName}Query<T = ${componentName}Return>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
896
|
+
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
889
897
|
{ enabled: ${enabledParam}, ...options }
|
|
890
898
|
);}
|
|
891
899
|
|
|
@@ -939,14 +947,16 @@ export const importOpenApi = async ({ data, format, apiDirectory, queryClientDir
|
|
|
939
947
|
UseMutationOptions,
|
|
940
948
|
QueryKey,
|
|
941
949
|
SetDataOptions,
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
950
|
+
QueryFilters
|
|
951
|
+
} from '@tanstack/react-query';
|
|
952
|
+
|
|
945
953
|
import queryString from 'query-string';
|
|
946
954
|
import { AxiosError } from 'axios';
|
|
947
955
|
import { api } from '${apiDirectory}';
|
|
948
956
|
import { queryClient } from '${queryClientDir}';
|
|
949
957
|
|
|
958
|
+
type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
|
|
959
|
+
|
|
950
960
|
// SCEHMAS
|
|
951
961
|
${generateSchemasDefinition(specs.components?.schemas)}
|
|
952
962
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-query-lightbase-codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"test": "yarn tsc && node test/script.mjs && eslint . --ext .js,.jsx,.ts,.tsx --fix"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@tanstack/react-query": "^4.0.9",
|
|
16
17
|
"axios": "0.27.2",
|
|
17
18
|
"case": "1.6.3",
|
|
18
19
|
"chalk": "4.1.0",
|
|
@@ -21,7 +22,6 @@
|
|
|
21
22
|
"openapi3-ts": "2.0.2",
|
|
22
23
|
"qs": "6.10.3",
|
|
23
24
|
"query-string": "7.1.1",
|
|
24
|
-
"react-query": "3.39.0",
|
|
25
25
|
"swagger2openapi": "7.0.8",
|
|
26
26
|
"yamljs": "0.3.0"
|
|
27
27
|
},
|