react-query-lightbase-codegen 0.0.12 → 0.0.15
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 +66 -33
- package/lib/esm/import-open-api.js +66 -33
- package/package.json +1 -1
|
@@ -401,7 +401,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
401
401
|
${paramsTypes}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
use${componentName}Query.fetch = async (props:
|
|
404
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables ) => {
|
|
405
405
|
const result = await api.${verb}<${genericsTypes}>(\`${route.replace(/\{/g, '{props.')}\`);
|
|
406
406
|
return result.data;
|
|
407
407
|
}
|
|
@@ -417,7 +417,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
417
417
|
);}
|
|
418
418
|
|
|
419
419
|
type ${componentName}MutationProps<T> = {
|
|
420
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
420
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
421
421
|
}
|
|
422
422
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
423
423
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -431,7 +431,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
431
431
|
${queryParamsType};
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
-
use${componentName}Query.fetch = async (props
|
|
434
|
+
use${componentName}Query.fetch = async (props:${componentName}Variables) => {
|
|
435
435
|
const {${paramsInPath.join(', ')}, ...queryParams} = props
|
|
436
436
|
const params = queryString.stringify(queryParams);
|
|
437
437
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`)
|
|
@@ -439,7 +439,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
442
|
-
use${componentName}Query.queryKey = (params
|
|
442
|
+
use${componentName}Query.queryKey = (params:${componentName}Variables): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
443
443
|
|
|
444
444
|
|
|
445
445
|
type ${componentName}QueryProps<T = ${genericsTypes}> ${componentName}Variables & {
|
|
@@ -483,7 +483,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
483
483
|
}
|
|
484
484
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
485
485
|
output += `
|
|
486
|
-
// USE AS EXAMPLE
|
|
487
486
|
type ${componentName}Variables = {
|
|
488
487
|
${queryParamsType}
|
|
489
488
|
}
|
|
@@ -492,7 +491,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
492
491
|
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
493
492
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
494
493
|
const params = queryString.stringify({${queryParams
|
|
495
|
-
.map((param) =>
|
|
494
|
+
.map((param) => `"${param.name}": props["${param.name}"]`)
|
|
496
495
|
.join(',')}});
|
|
497
496
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`)
|
|
498
497
|
return result.data;
|
|
@@ -511,28 +510,25 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
511
510
|
}
|
|
512
511
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
513
512
|
output += `
|
|
514
|
-
type ${componentName}
|
|
513
|
+
type ${componentName}Variables = ${requestBodyComponent};
|
|
515
514
|
|
|
516
|
-
use${componentName}Query.fetch = async (body:
|
|
515
|
+
use${componentName}Query.fetch = async (body: ${componentName}Variables) => {
|
|
517
516
|
const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
|
|
518
517
|
return result.data
|
|
519
518
|
}
|
|
520
519
|
|
|
521
520
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
522
|
-
use${componentName}Query.queryKey = (params:
|
|
521
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
523
522
|
|
|
524
|
-
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}
|
|
523
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
525
524
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
526
525
|
}
|
|
527
526
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
528
527
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
|
|
529
528
|
);}
|
|
530
529
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
type ${componentName}MutationVariables = ${requestBodyComponent};
|
|
534
530
|
type ${componentName}MutationProps<T> = {
|
|
535
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
531
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
536
532
|
}
|
|
537
533
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
538
534
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -541,49 +537,89 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
541
537
|
}
|
|
542
538
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
543
539
|
output += `
|
|
544
|
-
type ${componentName}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
${paramsTypes};
|
|
540
|
+
type ${componentName}Variables = ${requestBodyComponent} & {${paramsTypes}}
|
|
541
|
+
|
|
542
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
548
543
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
549
544
|
}
|
|
550
545
|
|
|
551
|
-
use${componentName}Query.fetch = async (props:
|
|
546
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
552
547
|
const {${paramsInPath.join(', ')}, ...body} = props
|
|
553
548
|
const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
|
|
554
549
|
return result.data
|
|
555
550
|
}
|
|
556
551
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
557
|
-
use${componentName}Query.queryKey = (params:
|
|
552
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
558
553
|
|
|
559
554
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
560
555
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
|
|
561
556
|
);}
|
|
562
557
|
|
|
563
|
-
type ${componentName}MutationVariables = {${paramsTypes}} & ${requestBodyComponent}
|
|
564
558
|
type ${componentName}MutationProps<T> = {
|
|
565
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
559
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
566
560
|
}
|
|
567
561
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
568
562
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
569
563
|
props?.options
|
|
570
564
|
)};`;
|
|
571
565
|
}
|
|
572
|
-
if (requestBodyComponent && queryParam && !headerParam) {
|
|
573
|
-
output +=
|
|
566
|
+
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
567
|
+
output += `
|
|
568
|
+
type ${componentName}Variables = ${requestBodyComponent} & {
|
|
569
|
+
${queryParamsType}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
573
|
+
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
574
574
|
}
|
|
575
|
-
|
|
576
|
-
|
|
575
|
+
|
|
576
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
577
|
+
const {${queryParams
|
|
578
|
+
.map((param) => `["${param.name}"]: ${param.name.replaceAll('-', '')}`)
|
|
579
|
+
.join(',')}, ...body} = props
|
|
580
|
+
const params = queryString.stringify({
|
|
581
|
+
${queryParams.map((param) => `["${param.name}"]: props["${param.name}"]`).join(',')}
|
|
582
|
+
});
|
|
583
|
+
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`, body)
|
|
584
|
+
return result.data
|
|
585
|
+
}
|
|
586
|
+
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
587
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
588
|
+
|
|
589
|
+
// TODO: CHECK
|
|
590
|
+
|
|
591
|
+
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
592
|
+
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props${queryParams
|
|
593
|
+
.map((param) => `["${param.name}"]`)
|
|
594
|
+
.join(' && !!props')}, ...options }
|
|
595
|
+
);}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
type ${componentName}MutationProps<T> = {
|
|
599
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
600
|
+
}
|
|
601
|
+
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
602
|
+
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
603
|
+
props?.options
|
|
604
|
+
)};`;
|
|
605
|
+
}
|
|
606
|
+
if (requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
607
|
+
output += `// TODO: NOT SUPPORTED 2`;
|
|
608
|
+
}
|
|
609
|
+
if (requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
610
|
+
output += `// TODO: NOT SUPPORTED 3`;
|
|
611
|
+
}
|
|
612
|
+
if (requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
613
|
+
output += `// TODO: NOT SUPPORTED 4`;
|
|
577
614
|
}
|
|
578
615
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
579
|
-
output += `// TODO:
|
|
616
|
+
output += `// TODO: NOT SUPPORTED 5`;
|
|
580
617
|
}
|
|
581
618
|
if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
582
|
-
output += `// TODO:
|
|
619
|
+
output += `// TODO: NOT SUPPORTED 6`;
|
|
583
620
|
}
|
|
584
621
|
if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
585
622
|
output += `
|
|
586
|
-
// DONE
|
|
587
623
|
type ${componentName}Variables = {
|
|
588
624
|
${headerParam}
|
|
589
625
|
};
|
|
@@ -617,7 +653,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
617
653
|
}
|
|
618
654
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
619
655
|
output += `
|
|
620
|
-
// DONE
|
|
621
656
|
type ${componentName}Variables = {
|
|
622
657
|
${headerParam}
|
|
623
658
|
${queryParamsType};
|
|
@@ -630,12 +665,11 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
630
665
|
const headers = {
|
|
631
666
|
${headerParams.map((param) => `"${param.name}": data["${param.name}"]`).join(',')}
|
|
632
667
|
}
|
|
633
|
-
// HIHI
|
|
634
668
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`, {headers})
|
|
635
669
|
return result.data;
|
|
636
670
|
}
|
|
637
671
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
638
|
-
use${componentName}Query.queryKey = (params:
|
|
672
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
639
673
|
|
|
640
674
|
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
641
675
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
@@ -658,7 +692,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
658
692
|
}
|
|
659
693
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
660
694
|
output += `
|
|
661
|
-
// HEHEHEHEHE
|
|
662
695
|
type ${componentName}Variables = ${requestBodyComponent} & {
|
|
663
696
|
${headerParam}
|
|
664
697
|
};
|
|
@@ -381,7 +381,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
381
381
|
${paramsTypes}
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
use${componentName}Query.fetch = async (props:
|
|
384
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables ) => {
|
|
385
385
|
const result = await api.${verb}<${genericsTypes}>(\`${route.replace(/\{/g, '{props.')}\`);
|
|
386
386
|
return result.data;
|
|
387
387
|
}
|
|
@@ -397,7 +397,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
397
397
|
);}
|
|
398
398
|
|
|
399
399
|
type ${componentName}MutationProps<T> = {
|
|
400
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
400
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
401
401
|
}
|
|
402
402
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
403
403
|
return useMutation(async (data) => use${componentName}Query.fetch(data),
|
|
@@ -411,7 +411,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
411
411
|
${queryParamsType};
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
-
use${componentName}Query.fetch = async (props
|
|
414
|
+
use${componentName}Query.fetch = async (props:${componentName}Variables) => {
|
|
415
415
|
const {${paramsInPath.join(', ')}, ...queryParams} = props
|
|
416
416
|
const params = queryString.stringify(queryParams);
|
|
417
417
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`)
|
|
@@ -419,7 +419,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
422
|
-
use${componentName}Query.queryKey = (params
|
|
422
|
+
use${componentName}Query.queryKey = (params:${componentName}Variables): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
423
423
|
|
|
424
424
|
|
|
425
425
|
type ${componentName}QueryProps<T = ${genericsTypes}> ${componentName}Variables & {
|
|
@@ -463,7 +463,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
463
463
|
}
|
|
464
464
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
465
465
|
output += `
|
|
466
|
-
// USE AS EXAMPLE
|
|
467
466
|
type ${componentName}Variables = {
|
|
468
467
|
${queryParamsType}
|
|
469
468
|
}
|
|
@@ -472,7 +471,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
472
471
|
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
473
472
|
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
474
473
|
const params = queryString.stringify({${queryParams
|
|
475
|
-
.map((param) =>
|
|
474
|
+
.map((param) => `"${param.name}": props["${param.name}"]`)
|
|
476
475
|
.join(',')}});
|
|
477
476
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`)
|
|
478
477
|
return result.data;
|
|
@@ -491,28 +490,25 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
491
490
|
}
|
|
492
491
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
493
492
|
output += `
|
|
494
|
-
type ${componentName}
|
|
493
|
+
type ${componentName}Variables = ${requestBodyComponent};
|
|
495
494
|
|
|
496
|
-
use${componentName}Query.fetch = async (body:
|
|
495
|
+
use${componentName}Query.fetch = async (body: ${componentName}Variables) => {
|
|
497
496
|
const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
|
|
498
497
|
return result.data
|
|
499
498
|
}
|
|
500
499
|
|
|
501
500
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
502
|
-
use${componentName}Query.queryKey = (params:
|
|
501
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
503
502
|
|
|
504
|
-
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}
|
|
503
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
505
504
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
506
505
|
}
|
|
507
506
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
|
|
508
507
|
return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
|
|
509
508
|
);}
|
|
510
509
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
type ${componentName}MutationVariables = ${requestBodyComponent};
|
|
514
510
|
type ${componentName}MutationProps<T> = {
|
|
515
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
511
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
516
512
|
}
|
|
517
513
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
518
514
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
@@ -521,49 +517,89 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
521
517
|
}
|
|
522
518
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
523
519
|
output += `
|
|
524
|
-
type ${componentName}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
${paramsTypes};
|
|
520
|
+
type ${componentName}Variables = ${requestBodyComponent} & {${paramsTypes}}
|
|
521
|
+
|
|
522
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
528
523
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
529
524
|
}
|
|
530
525
|
|
|
531
|
-
use${componentName}Query.fetch = async (props:
|
|
526
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
532
527
|
const {${paramsInPath.join(', ')}, ...body} = props
|
|
533
528
|
const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
|
|
534
529
|
return result.data
|
|
535
530
|
}
|
|
536
531
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
537
|
-
use${componentName}Query.queryKey = (params:
|
|
532
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
538
533
|
|
|
539
534
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
540
535
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
|
|
541
536
|
);}
|
|
542
537
|
|
|
543
|
-
type ${componentName}MutationVariables = {${paramsTypes}} & ${requestBodyComponent}
|
|
544
538
|
type ${componentName}MutationProps<T> = {
|
|
545
|
-
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}
|
|
539
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
546
540
|
}
|
|
547
541
|
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
548
542
|
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
549
543
|
props?.options
|
|
550
544
|
)};`;
|
|
551
545
|
}
|
|
552
|
-
if (requestBodyComponent && queryParam && !headerParam) {
|
|
553
|
-
output +=
|
|
546
|
+
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
547
|
+
output += `
|
|
548
|
+
type ${componentName}Variables = ${requestBodyComponent} & {
|
|
549
|
+
${queryParamsType}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
553
|
+
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
554
554
|
}
|
|
555
|
-
|
|
556
|
-
|
|
555
|
+
|
|
556
|
+
use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
|
|
557
|
+
const {${queryParams
|
|
558
|
+
.map((param) => `["${param.name}"]: ${param.name.replaceAll('-', '')}`)
|
|
559
|
+
.join(',')}, ...body} = props
|
|
560
|
+
const params = queryString.stringify({
|
|
561
|
+
${queryParams.map((param) => `["${param.name}"]: props["${param.name}"]`).join(',')}
|
|
562
|
+
});
|
|
563
|
+
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`, body)
|
|
564
|
+
return result.data
|
|
565
|
+
}
|
|
566
|
+
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
567
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
568
|
+
|
|
569
|
+
// TODO: CHECK
|
|
570
|
+
|
|
571
|
+
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
572
|
+
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props${queryParams
|
|
573
|
+
.map((param) => `["${param.name}"]`)
|
|
574
|
+
.join(' && !!props')}, ...options }
|
|
575
|
+
);}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
type ${componentName}MutationProps<T> = {
|
|
579
|
+
options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
|
|
580
|
+
}
|
|
581
|
+
export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
|
|
582
|
+
return useMutation(async (body) => use${componentName}Query.fetch(body),
|
|
583
|
+
props?.options
|
|
584
|
+
)};`;
|
|
585
|
+
}
|
|
586
|
+
if (requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
587
|
+
output += `// TODO: NOT SUPPORTED 2`;
|
|
588
|
+
}
|
|
589
|
+
if (requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
590
|
+
output += `// TODO: NOT SUPPORTED 3`;
|
|
591
|
+
}
|
|
592
|
+
if (requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
593
|
+
output += `// TODO: NOT SUPPORTED 4`;
|
|
557
594
|
}
|
|
558
595
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
|
|
559
|
-
output += `// TODO:
|
|
596
|
+
output += `// TODO: NOT SUPPORTED 5`;
|
|
560
597
|
}
|
|
561
598
|
if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
|
|
562
|
-
output += `// TODO:
|
|
599
|
+
output += `// TODO: NOT SUPPORTED 6`;
|
|
563
600
|
}
|
|
564
601
|
if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
565
602
|
output += `
|
|
566
|
-
// DONE
|
|
567
603
|
type ${componentName}Variables = {
|
|
568
604
|
${headerParam}
|
|
569
605
|
};
|
|
@@ -597,7 +633,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
597
633
|
}
|
|
598
634
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
599
635
|
output += `
|
|
600
|
-
// DONE
|
|
601
636
|
type ${componentName}Variables = {
|
|
602
637
|
${headerParam}
|
|
603
638
|
${queryParamsType};
|
|
@@ -610,12 +645,11 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
610
645
|
const headers = {
|
|
611
646
|
${headerParams.map((param) => `"${param.name}": data["${param.name}"]`).join(',')}
|
|
612
647
|
}
|
|
613
|
-
// HIHI
|
|
614
648
|
const result = await api.${verb}<${genericsTypes}>(\`${route}?\${params}\`, {headers})
|
|
615
649
|
return result.data;
|
|
616
650
|
}
|
|
617
651
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
618
|
-
use${componentName}Query.queryKey = (params:
|
|
652
|
+
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
619
653
|
|
|
620
654
|
type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
|
|
621
655
|
options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
|
|
@@ -638,7 +672,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
638
672
|
}
|
|
639
673
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
|
|
640
674
|
output += `
|
|
641
|
-
// HEHEHEHEHE
|
|
642
675
|
type ${componentName}Variables = ${requestBodyComponent} & {
|
|
643
676
|
${headerParam}
|
|
644
677
|
};
|