react-query-lightbase-codegen 0.0.14 → 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.
@@ -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: Omit<${componentName}QueryProps, 'options'> ) => {
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}MutationVariables, T>
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: Omit<${componentName}QueryProps, 'options'>) => {
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: Omit<${componentName}QueryProps, 'options'>): QueryKey => [...use${componentName}Query.baseKey(), 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 & {
@@ -510,28 +510,25 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
510
510
  }
511
511
  if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
512
512
  output += `
513
- type ${componentName}QueryVariables = ${requestBodyComponent};
513
+ type ${componentName}Variables = ${requestBodyComponent};
514
514
 
515
- use${componentName}Query.fetch = async (body: Omit<${componentName}QueryProps, 'options'>) => {
515
+ use${componentName}Query.fetch = async (body: ${componentName}Variables) => {
516
516
  const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
517
517
  return result.data
518
518
  }
519
519
 
520
520
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
521
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
521
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
522
522
 
523
- type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}QueryVariables & {
523
+ type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
524
524
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
525
525
  }
526
526
  export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
527
527
  return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
528
528
  );}
529
529
 
530
-
531
-
532
- type ${componentName}MutationVariables = ${requestBodyComponent};
533
530
  type ${componentName}MutationProps<T> = {
534
- options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}MutationVariables, T>
531
+ options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
535
532
  }
536
533
  export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
537
534
  return useMutation(async (body) => use${componentName}Query.fetch(body),
@@ -540,45 +537,86 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
540
537
  }
541
538
  if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
542
539
  output += `
543
- type ${componentName}QueryProps<T = ${genericsTypes}> = ${requestBodyComponent
544
- .replace('{', '')
545
- .replace('}', '')} & {
546
- ${paramsTypes};
540
+ type ${componentName}Variables = ${requestBodyComponent} & {${paramsTypes}}
541
+
542
+ type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
547
543
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
548
544
  }
549
545
 
550
- use${componentName}Query.fetch = async (props: Omit<${componentName}QueryProps, 'options'>) => {
546
+ use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
551
547
  const {${paramsInPath.join(', ')}, ...body} = props
552
548
  const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
553
549
  return result.data
554
550
  }
555
551
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
556
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
552
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
557
553
 
558
554
  export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
559
555
  return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
560
556
  );}
561
557
 
562
- type ${componentName}MutationVariables = {${paramsTypes}} & ${requestBodyComponent}
563
558
  type ${componentName}MutationProps<T> = {
564
- options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}MutationVariables, T>
559
+ options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
565
560
  }
566
561
  export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
567
562
  return useMutation(async (body) => use${componentName}Query.fetch(body),
568
563
  props?.options
569
564
  )};`;
570
565
  }
571
- if (requestBodyComponent && queryParam && !headerParam) {
572
- output += `// TODO: CODEGEN DOES NOT SUPPORT QUERYPARAM AND REQUESTBODY`;
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>
573
574
  }
574
- if (requestBodyComponent && queryParam && headerParam) {
575
- output += `// TODO: CODEGEN DOES NOT SUPPORT QUERYPARAM AND REQUESTBODY`;
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`;
576
614
  }
577
615
  if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
578
- output += `// TODO: CODEGEN DOES NOT SUPPORT paramsInPath AND headerParam`;
616
+ output += `// TODO: NOT SUPPORTED 5`;
579
617
  }
580
618
  if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
581
- output += `// TODO: CODEGEN DOES NOT SUPPORT paramsInPath AND headerParam AND headerParam`;
619
+ output += `// TODO: NOT SUPPORTED 6`;
582
620
  }
583
621
  if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
584
622
  output += `
@@ -631,7 +669,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
631
669
  return result.data;
632
670
  }
633
671
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
634
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
672
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
635
673
 
636
674
  type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
637
675
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
@@ -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: Omit<${componentName}QueryProps, 'options'> ) => {
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}MutationVariables, T>
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: Omit<${componentName}QueryProps, 'options'>) => {
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: Omit<${componentName}QueryProps, 'options'>): QueryKey => [...use${componentName}Query.baseKey(), 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 & {
@@ -490,28 +490,25 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
490
490
  }
491
491
  if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
492
492
  output += `
493
- type ${componentName}QueryVariables = ${requestBodyComponent};
493
+ type ${componentName}Variables = ${requestBodyComponent};
494
494
 
495
- use${componentName}Query.fetch = async (body: Omit<${componentName}QueryProps, 'options'>) => {
495
+ use${componentName}Query.fetch = async (body: ${componentName}Variables) => {
496
496
  const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
497
497
  return result.data
498
498
  }
499
499
 
500
500
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
501
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
501
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
502
502
 
503
- type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}QueryVariables & {
503
+ type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
504
504
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
505
505
  }
506
506
  export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...body }: ${componentName}QueryProps<T>) {
507
507
  return useQuery(use${componentName}Query.queryKey(body), async () => use${componentName}Query.fetch(body), options
508
508
  );}
509
509
 
510
-
511
-
512
- type ${componentName}MutationVariables = ${requestBodyComponent};
513
510
  type ${componentName}MutationProps<T> = {
514
- options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}MutationVariables, T>
511
+ options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
515
512
  }
516
513
  export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
517
514
  return useMutation(async (body) => use${componentName}Query.fetch(body),
@@ -520,45 +517,86 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
520
517
  }
521
518
  if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
522
519
  output += `
523
- type ${componentName}QueryProps<T = ${genericsTypes}> = ${requestBodyComponent
524
- .replace('{', '')
525
- .replace('}', '')} & {
526
- ${paramsTypes};
520
+ type ${componentName}Variables = ${requestBodyComponent} & {${paramsTypes}}
521
+
522
+ type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
527
523
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
528
524
  }
529
525
 
530
- use${componentName}Query.fetch = async (props: Omit<${componentName}QueryProps, 'options'>) => {
526
+ use${componentName}Query.fetch = async (props: ${componentName}Variables) => {
531
527
  const {${paramsInPath.join(', ')}, ...body} = props
532
528
  const result = await api.${verb}<${genericsTypes}>(\`${route}\`, body)
533
529
  return result.data
534
530
  }
535
531
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
536
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
532
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
537
533
 
538
534
  export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
539
535
  return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props.${paramsInPath.join(' && !!props.')}, ...options }
540
536
  );}
541
537
 
542
- type ${componentName}MutationVariables = {${paramsTypes}} & ${requestBodyComponent}
543
538
  type ${componentName}MutationProps<T> = {
544
- options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}MutationVariables, T>
539
+ options?: UseMutationOptions<${genericsTypes}, AxiosError, ${componentName}Variables, T>
545
540
  }
546
541
  export function use${componentName}Mutation<T = ${genericsTypes}>(props?: ${componentName}MutationProps<T>) {
547
542
  return useMutation(async (body) => use${componentName}Query.fetch(body),
548
543
  props?.options
549
544
  )};`;
550
545
  }
551
- if (requestBodyComponent && queryParam && !headerParam) {
552
- output += `// TODO: CODEGEN DOES NOT SUPPORT QUERYPARAM AND REQUESTBODY`;
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>
553
554
  }
554
- if (requestBodyComponent && queryParam && headerParam) {
555
- output += `// TODO: CODEGEN DOES NOT SUPPORT QUERYPARAM AND REQUESTBODY`;
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`;
556
594
  }
557
595
  if (!requestBodyComponent && paramsInPath.length && !queryParam && headerParam) {
558
- output += `// TODO: CODEGEN DOES NOT SUPPORT paramsInPath AND headerParam`;
596
+ output += `// TODO: NOT SUPPORTED 5`;
559
597
  }
560
598
  if (!requestBodyComponent && paramsInPath.length && queryParam && headerParam) {
561
- output += `// TODO: CODEGEN DOES NOT SUPPORT paramsInPath AND headerParam AND headerParam`;
599
+ output += `// TODO: NOT SUPPORTED 6`;
562
600
  }
563
601
  if (!requestBodyComponent && !paramsInPath.length && !queryParam && headerParam) {
564
602
  output += `
@@ -611,7 +649,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
611
649
  return result.data;
612
650
  }
613
651
  use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
614
- use${componentName}Query.queryKey = (params: Omit<${componentName}QueryProps, 'options'> ): QueryKey => [...use${componentName}Query.baseKey(), params];
652
+ use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
615
653
 
616
654
  type ${componentName}QueryProps<T = ${genericsTypes}> = ${componentName}Variables & {
617
655
  options?: UseQueryOptions<${genericsTypes}, AxiosError, T, any>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-lightbase-codegen",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "license": "MIT",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",