react-query-lightbase-codegen 0.0.20 → 0.0.21
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 +35 -36
- package/lib/esm/import-open-api.js +35 -36
- package/package.json +1 -1
|
@@ -396,7 +396,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
396
396
|
const headerParam = headerType && headerType !== 'void' ? `${headerType};` : '';
|
|
397
397
|
const queryParam = queryParamsType && queryParamsType !== 'void' ? `${queryParamsType}` : '';
|
|
398
398
|
const requestBodyComponent = requestBodyTypes && requestBodyTypes !== 'void' ? `${requestBodyTypes}` : '';
|
|
399
|
-
let AxiosErrorType = true ? 'AxiosError<AxiosErrorType | unknown>' : `AxiosError<any>`;
|
|
400
399
|
// QUERIES
|
|
401
400
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
402
401
|
output += `
|
|
@@ -425,7 +424,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
425
424
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
426
425
|
|
|
427
426
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
428
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
427
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
429
428
|
}
|
|
430
429
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
431
430
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -433,7 +432,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
433
432
|
);}
|
|
434
433
|
|
|
435
434
|
type ${componentName}MutationProps<T> = {
|
|
436
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
435
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
437
436
|
}
|
|
438
437
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
439
438
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -471,14 +470,14 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
471
470
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
472
471
|
|
|
473
472
|
type ${componentName}QueryProps<T = ${componentName}Response> ${componentName}Variables & {
|
|
474
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
473
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
475
474
|
}
|
|
476
475
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
477
476
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
|
|
478
477
|
);}
|
|
479
478
|
|
|
480
479
|
type ${componentName}MutationProps<T> = {
|
|
481
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
480
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
482
481
|
}
|
|
483
482
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
484
483
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -496,27 +495,27 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
496
495
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
497
496
|
|
|
498
497
|
use${componentName}Query.updateCache = (
|
|
499
|
-
params:
|
|
498
|
+
params: undefined,
|
|
500
499
|
updater: Updater<${componentName}Response | undefined, ${componentName}Response>,
|
|
501
500
|
options?: SetDataOptions | undefined
|
|
502
|
-
) => queryClient.setQueryData<${componentName}Response>(use${componentName}Query.queryKey(
|
|
501
|
+
) => queryClient.setQueryData<${componentName}Response>(use${componentName}Query.queryKey(), updater, options);
|
|
503
502
|
|
|
504
|
-
use${componentName}Query.prefetch = (
|
|
505
|
-
queryClient.prefetchQuery<${componentName}Response>(use${componentName}Query.queryKey(
|
|
503
|
+
use${componentName}Query.prefetch = () =>
|
|
504
|
+
queryClient.prefetchQuery<${componentName}Response>(use${componentName}Query.queryKey(), ()=> use${componentName}Query.fetch());
|
|
506
505
|
|
|
507
|
-
use${componentName}Query.invalidate = (
|
|
508
|
-
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(
|
|
506
|
+
use${componentName}Query.invalidate = () =>
|
|
507
|
+
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey());
|
|
509
508
|
|
|
510
509
|
|
|
511
510
|
type ${componentName}QueryProps<T = ${componentName}Response> = {
|
|
512
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
511
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
513
512
|
}
|
|
514
513
|
export function use${componentName}Query<T = ${componentName}Response>(props?: ${componentName}QueryProps<T>) {
|
|
515
514
|
return useQuery(use${componentName}Query.queryKey(), use${componentName}Query.fetch, props?.options
|
|
516
515
|
);}
|
|
517
516
|
|
|
518
517
|
type ${componentName}MutationProps<T> = {
|
|
519
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
518
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, void, T>
|
|
520
519
|
}
|
|
521
520
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
522
521
|
return useMutation(async () => use${componentName}Query.fetch(),
|
|
@@ -553,12 +552,12 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
553
552
|
use${componentName}Query.invalidate = (params: ${componentName}Variables) =>
|
|
554
553
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
555
554
|
|
|
556
|
-
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}Variables & { options?: UseQueryOptions<${componentName}Response,
|
|
555
|
+
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}Variables & { options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>}) {
|
|
557
556
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
558
557
|
{ enabled: !!props${queryParams.map((param) => `["${param.name}"]`).join(' && !!props')}, ...options }
|
|
559
558
|
);}
|
|
560
559
|
|
|
561
|
-
export function use${componentName}Mutation<T = ${componentName}Response>(props?: { options?: UseMutationOptions<${componentName}Response,
|
|
560
|
+
export function use${componentName}Mutation<T = ${componentName}Response>(props?: { options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>}) {
|
|
562
561
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
563
562
|
props?.options
|
|
564
563
|
)};
|
|
@@ -591,14 +590,14 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
591
590
|
|
|
592
591
|
|
|
593
592
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
594
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
593
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
595
594
|
}
|
|
596
595
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
597
596
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
|
|
598
597
|
);}
|
|
599
598
|
|
|
600
599
|
type ${componentName}MutationProps<T> = {
|
|
601
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
600
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
602
601
|
}
|
|
603
602
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
604
603
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -608,10 +607,11 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
608
607
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
609
608
|
output += `
|
|
610
609
|
type ${componentName}Response = ${genericsTypes}
|
|
611
|
-
type ${componentName}Variables =
|
|
610
|
+
type ${componentName}Variables = {
|
|
611
|
+
body: ${requestBodyComponent}${paramsTypes}}
|
|
612
612
|
|
|
613
613
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
614
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
614
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
@@ -640,7 +640,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
640
640
|
);}
|
|
641
641
|
|
|
642
642
|
type ${componentName}MutationProps<T> = {
|
|
643
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
643
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
644
644
|
}
|
|
645
645
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
646
646
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -650,22 +650,20 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
650
650
|
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
651
651
|
output += `
|
|
652
652
|
type ${componentName}Response = ${genericsTypes}
|
|
653
|
-
type ${componentName}Variables =
|
|
653
|
+
type ${componentName}Variables = {
|
|
654
|
+
body: ${requestBodyComponent}
|
|
654
655
|
${queryParamsType}
|
|
655
656
|
}
|
|
656
657
|
|
|
657
658
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
658
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
659
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
659
660
|
}
|
|
660
661
|
|
|
661
662
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
662
|
-
const {${queryParams
|
|
663
|
-
.map((param) => `["${param.name}"]: ${param.name.replaceAll('-', '')}`)
|
|
664
|
-
.join(',')}, ...body} = props
|
|
665
663
|
const params = queryString.stringify({
|
|
666
664
|
${queryParams.map((param) => `["${param.name}"]: props["${param.name}"]`).join(',')}
|
|
667
665
|
});
|
|
668
|
-
const result = await api.${verb}<${componentName}Response>(\`${route}?\${params}\`, body)
|
|
666
|
+
const result = await api.${verb}<${componentName}Response>(\`${route}?\${params}\`, props.body)
|
|
669
667
|
return result.data
|
|
670
668
|
}
|
|
671
669
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
@@ -692,7 +690,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
692
690
|
|
|
693
691
|
|
|
694
692
|
type ${componentName}MutationProps<T> = {
|
|
695
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
693
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
696
694
|
}
|
|
697
695
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
698
696
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -743,7 +741,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
743
741
|
|
|
744
742
|
|
|
745
743
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
746
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
744
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
747
745
|
}
|
|
748
746
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
749
747
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -753,7 +751,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
753
751
|
|
|
754
752
|
|
|
755
753
|
type ${componentName}MutationProps<T> = {
|
|
756
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
754
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
757
755
|
}
|
|
758
756
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
759
757
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -795,7 +793,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
795
793
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
796
794
|
|
|
797
795
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
798
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
796
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
799
797
|
}
|
|
800
798
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
801
799
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -805,7 +803,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
805
803
|
);}
|
|
806
804
|
|
|
807
805
|
type ${componentName}MutationProps<T> = {
|
|
808
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
806
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
809
807
|
}
|
|
810
808
|
|
|
811
809
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
@@ -817,7 +815,8 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
817
815
|
output += `
|
|
818
816
|
type ${componentName}Response = ${genericsTypes}
|
|
819
817
|
|
|
820
|
-
type ${componentName}Variables =
|
|
818
|
+
type ${componentName}Variables = {
|
|
819
|
+
body: ${requestBodyComponent}
|
|
821
820
|
${headerParam}
|
|
822
821
|
};
|
|
823
822
|
|
|
@@ -845,7 +844,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
845
844
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
846
845
|
|
|
847
846
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
848
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
847
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
849
848
|
}
|
|
850
849
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
851
850
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body),{ enabled: !!body${headerParams
|
|
@@ -855,7 +854,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
855
854
|
|
|
856
855
|
|
|
857
856
|
type ${componentName}MutationProps<T> = {
|
|
858
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
857
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
859
858
|
}
|
|
860
859
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
861
860
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -908,8 +907,8 @@ const importOpenApi = async ({ data, format, apiDirectory, queryClientDir, heade
|
|
|
908
907
|
import { Updater } from 'react-query/types/core/utils';
|
|
909
908
|
|
|
910
909
|
import queryString from 'query-string';
|
|
911
|
-
import {AxiosError} from 'axios';
|
|
912
|
-
import { api
|
|
910
|
+
import { AxiosError } from 'axios';
|
|
911
|
+
import { api } from '${apiDirectory}';
|
|
913
912
|
import { queryClient } from '${queryClientDir}';
|
|
914
913
|
|
|
915
914
|
// SCEHMAS
|
|
@@ -376,7 +376,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
376
376
|
const headerParam = headerType && headerType !== 'void' ? `${headerType};` : '';
|
|
377
377
|
const queryParam = queryParamsType && queryParamsType !== 'void' ? `${queryParamsType}` : '';
|
|
378
378
|
const requestBodyComponent = requestBodyTypes && requestBodyTypes !== 'void' ? `${requestBodyTypes}` : '';
|
|
379
|
-
let AxiosErrorType = true ? 'AxiosError<AxiosErrorType | unknown>' : `AxiosError<any>`;
|
|
380
379
|
// QUERIES
|
|
381
380
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
382
381
|
output += `
|
|
@@ -405,7 +404,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
405
404
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
406
405
|
|
|
407
406
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
408
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
407
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
409
408
|
}
|
|
410
409
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
411
410
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -413,7 +412,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
413
412
|
);}
|
|
414
413
|
|
|
415
414
|
type ${componentName}MutationProps<T> = {
|
|
416
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
415
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
417
416
|
}
|
|
418
417
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
419
418
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -451,14 +450,14 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
451
450
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
452
451
|
|
|
453
452
|
type ${componentName}QueryProps<T = ${componentName}Response> ${componentName}Variables & {
|
|
454
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
453
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
455
454
|
}
|
|
456
455
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
457
456
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
|
|
458
457
|
);}
|
|
459
458
|
|
|
460
459
|
type ${componentName}MutationProps<T> = {
|
|
461
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
460
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
462
461
|
}
|
|
463
462
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
464
463
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -476,27 +475,27 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
476
475
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
477
476
|
|
|
478
477
|
use${componentName}Query.updateCache = (
|
|
479
|
-
params:
|
|
478
|
+
params: undefined,
|
|
480
479
|
updater: Updater<${componentName}Response | undefined, ${componentName}Response>,
|
|
481
480
|
options?: SetDataOptions | undefined
|
|
482
|
-
) => queryClient.setQueryData<${componentName}Response>(use${componentName}Query.queryKey(
|
|
481
|
+
) => queryClient.setQueryData<${componentName}Response>(use${componentName}Query.queryKey(), updater, options);
|
|
483
482
|
|
|
484
|
-
use${componentName}Query.prefetch = (
|
|
485
|
-
queryClient.prefetchQuery<${componentName}Response>(use${componentName}Query.queryKey(
|
|
483
|
+
use${componentName}Query.prefetch = () =>
|
|
484
|
+
queryClient.prefetchQuery<${componentName}Response>(use${componentName}Query.queryKey(), ()=> use${componentName}Query.fetch());
|
|
486
485
|
|
|
487
|
-
use${componentName}Query.invalidate = (
|
|
488
|
-
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(
|
|
486
|
+
use${componentName}Query.invalidate = () =>
|
|
487
|
+
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey());
|
|
489
488
|
|
|
490
489
|
|
|
491
490
|
type ${componentName}QueryProps<T = ${componentName}Response> = {
|
|
492
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
491
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
493
492
|
}
|
|
494
493
|
export function use${componentName}Query<T = ${componentName}Response>(props?: ${componentName}QueryProps<T>) {
|
|
495
494
|
return useQuery(use${componentName}Query.queryKey(), use${componentName}Query.fetch, props?.options
|
|
496
495
|
);}
|
|
497
496
|
|
|
498
497
|
type ${componentName}MutationProps<T> = {
|
|
499
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
498
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, void, T>
|
|
500
499
|
}
|
|
501
500
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
502
501
|
return useMutation(async () => use${componentName}Query.fetch(),
|
|
@@ -533,12 +532,12 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
533
532
|
use${componentName}Query.invalidate = (params: ${componentName}Variables) =>
|
|
534
533
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
535
534
|
|
|
536
|
-
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}Variables & { options?: UseQueryOptions<${componentName}Response,
|
|
535
|
+
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}Variables & { options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>}) {
|
|
537
536
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
538
537
|
{ enabled: !!props${queryParams.map((param) => `["${param.name}"]`).join(' && !!props')}, ...options }
|
|
539
538
|
);}
|
|
540
539
|
|
|
541
|
-
export function use${componentName}Mutation<T = ${componentName}Response>(props?: { options?: UseMutationOptions<${componentName}Response,
|
|
540
|
+
export function use${componentName}Mutation<T = ${componentName}Response>(props?: { options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>}) {
|
|
542
541
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
543
542
|
props?.options
|
|
544
543
|
)};
|
|
@@ -571,14 +570,14 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
571
570
|
|
|
572
571
|
|
|
573
572
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
574
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
573
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
575
574
|
}
|
|
576
575
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
577
576
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
|
|
578
577
|
);}
|
|
579
578
|
|
|
580
579
|
type ${componentName}MutationProps<T> = {
|
|
581
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
580
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
582
581
|
}
|
|
583
582
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
584
583
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -588,10 +587,11 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
588
587
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
589
588
|
output += `
|
|
590
589
|
type ${componentName}Response = ${genericsTypes}
|
|
591
|
-
type ${componentName}Variables =
|
|
590
|
+
type ${componentName}Variables = {
|
|
591
|
+
body: ${requestBodyComponent}${paramsTypes}}
|
|
592
592
|
|
|
593
593
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
594
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
594
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
@@ -620,7 +620,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
620
620
|
);}
|
|
621
621
|
|
|
622
622
|
type ${componentName}MutationProps<T> = {
|
|
623
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
623
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
624
624
|
}
|
|
625
625
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
626
626
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -630,22 +630,20 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
630
630
|
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
631
631
|
output += `
|
|
632
632
|
type ${componentName}Response = ${genericsTypes}
|
|
633
|
-
type ${componentName}Variables =
|
|
633
|
+
type ${componentName}Variables = {
|
|
634
|
+
body: ${requestBodyComponent}
|
|
634
635
|
${queryParamsType}
|
|
635
636
|
}
|
|
636
637
|
|
|
637
638
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
638
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
639
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
639
640
|
}
|
|
640
641
|
|
|
641
642
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
642
|
-
const {${queryParams
|
|
643
|
-
.map((param) => `["${param.name}"]: ${param.name.replaceAll('-', '')}`)
|
|
644
|
-
.join(',')}, ...body} = props
|
|
645
643
|
const params = queryString.stringify({
|
|
646
644
|
${queryParams.map((param) => `["${param.name}"]: props["${param.name}"]`).join(',')}
|
|
647
645
|
});
|
|
648
|
-
const result = await api.${verb}<${componentName}Response>(\`${route}?\${params}\`, body)
|
|
646
|
+
const result = await api.${verb}<${componentName}Response>(\`${route}?\${params}\`, props.body)
|
|
649
647
|
return result.data
|
|
650
648
|
}
|
|
651
649
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
@@ -672,7 +670,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
672
670
|
|
|
673
671
|
|
|
674
672
|
type ${componentName}MutationProps<T> = {
|
|
675
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
673
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
676
674
|
}
|
|
677
675
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
678
676
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -723,7 +721,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
723
721
|
|
|
724
722
|
|
|
725
723
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
726
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
724
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
727
725
|
}
|
|
728
726
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
729
727
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -733,7 +731,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
733
731
|
|
|
734
732
|
|
|
735
733
|
type ${componentName}MutationProps<T> = {
|
|
736
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
734
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
737
735
|
}
|
|
738
736
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
739
737
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -775,7 +773,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
775
773
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
776
774
|
|
|
777
775
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
778
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
776
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
779
777
|
}
|
|
780
778
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
781
779
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props),
|
|
@@ -785,7 +783,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
785
783
|
);}
|
|
786
784
|
|
|
787
785
|
type ${componentName}MutationProps<T> = {
|
|
788
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
786
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
789
787
|
}
|
|
790
788
|
|
|
791
789
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
@@ -797,7 +795,8 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
797
795
|
output += `
|
|
798
796
|
type ${componentName}Response = ${genericsTypes}
|
|
799
797
|
|
|
800
|
-
type ${componentName}Variables =
|
|
798
|
+
type ${componentName}Variables = {
|
|
799
|
+
body: ${requestBodyComponent}
|
|
801
800
|
${headerParam}
|
|
802
801
|
};
|
|
803
802
|
|
|
@@ -825,7 +824,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
825
824
|
queryClient.invalidateQueries<${componentName}Response>(use${componentName}Query.queryKey(params));
|
|
826
825
|
|
|
827
826
|
type ${componentName}QueryProps<T = ${componentName}Response> = ${componentName}Variables & {
|
|
828
|
-
options?: UseQueryOptions<${componentName}Response,
|
|
827
|
+
options?: UseQueryOptions<${componentName}Response, AxiosError, T, any>
|
|
829
828
|
}
|
|
830
829
|
export function use${componentName}Query<T = ${componentName}Response>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
831
830
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body),{ enabled: !!body${headerParams
|
|
@@ -835,7 +834,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
835
834
|
|
|
836
835
|
|
|
837
836
|
type ${componentName}MutationProps<T> = {
|
|
838
|
-
options?: UseMutationOptions<${componentName}Response,
|
|
837
|
+
options?: UseMutationOptions<${componentName}Response, AxiosError, ${componentName}Variables, T>
|
|
839
838
|
}
|
|
840
839
|
export function use${componentName}Mutation<T = ${componentName}Response>(props?: ${componentName}MutationProps<T>) {
|
|
841
840
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -887,8 +886,8 @@ export const importOpenApi = async ({ data, format, apiDirectory, queryClientDir
|
|
|
887
886
|
import { Updater } from 'react-query/types/core/utils';
|
|
888
887
|
|
|
889
888
|
import queryString from 'query-string';
|
|
890
|
-
import {AxiosError} from 'axios';
|
|
891
|
-
import { api
|
|
889
|
+
import { AxiosError } from 'axios';
|
|
890
|
+
import { api } from '${apiDirectory}';
|
|
892
891
|
import { queryClient } from '${queryClientDir}';
|
|
893
892
|
|
|
894
893
|
// SCEHMAS
|