react-query-lightbase-codegen 0.1.9 → 0.2.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/lib/cjs/import-open-api.js +24 -14
- package/lib/esm/import-open-api.js +24 -14
- 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 {
|
|
@@ -424,7 +432,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
424
432
|
use${componentName}Query.updateCache = (
|
|
425
433
|
{params, updater, options}:
|
|
426
434
|
{params: ${componentName}Variables,
|
|
427
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
435
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
428
436
|
options?: SetDataOptions | undefined}
|
|
429
437
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
430
438
|
|
|
@@ -475,7 +483,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
475
483
|
use${componentName}Query.updateCache = (
|
|
476
484
|
{params, updater, options}:
|
|
477
485
|
{params: ${componentName}Variables,
|
|
478
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
486
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
479
487
|
options?: SetDataOptions | undefined}
|
|
480
488
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
481
489
|
|
|
@@ -516,7 +524,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
516
524
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
517
525
|
|
|
518
526
|
use${componentName}Query.updateCache = ({updater, options}:
|
|
519
|
-
{updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
527
|
+
{updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
520
528
|
options?: SetDataOptions | undefined}
|
|
521
529
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(), updater, options);
|
|
522
530
|
|
|
@@ -568,7 +576,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
568
576
|
use${componentName}Query.updateCache = (
|
|
569
577
|
{params, updater, options}:
|
|
570
578
|
{params: ${componentName}Variables,
|
|
571
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
579
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
572
580
|
options?: SetDataOptions | undefined}
|
|
573
581
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
574
582
|
|
|
@@ -609,7 +617,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
609
617
|
use${componentName}Query.updateCache = (
|
|
610
618
|
{params, updater, options}:
|
|
611
619
|
{params: ${componentName}Variables,
|
|
612
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
620
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
613
621
|
options?: SetDataOptions | undefined}
|
|
614
622
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
615
623
|
|
|
@@ -662,7 +670,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
662
670
|
use${componentName}Query.updateCache = (
|
|
663
671
|
{params, updater, options}:
|
|
664
672
|
{params: ${componentName}Variables,
|
|
665
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
673
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
666
674
|
options?: SetDataOptions | undefined}
|
|
667
675
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
668
676
|
|
|
@@ -715,7 +723,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
715
723
|
use${componentName}Query.updateCache = (
|
|
716
724
|
{params, updater, options}:
|
|
717
725
|
{params: ${componentName}Variables,
|
|
718
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
726
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
719
727
|
options?: SetDataOptions | undefined}
|
|
720
728
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
721
729
|
|
|
@@ -777,7 +785,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
777
785
|
use${componentName}Query.updateCache = (
|
|
778
786
|
{params, updater, options}:
|
|
779
787
|
{params: ${componentName}Variables,
|
|
780
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
788
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
781
789
|
options?: SetDataOptions | undefined}
|
|
782
790
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
783
791
|
|
|
@@ -833,7 +841,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
833
841
|
use${componentName}Query.updateCache = (
|
|
834
842
|
{params, updater, options}:
|
|
835
843
|
{params: ${componentName}Variables,
|
|
836
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
844
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
837
845
|
options?: SetDataOptions | undefined}
|
|
838
846
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
839
847
|
|
|
@@ -887,7 +895,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
887
895
|
use${componentName}Query.updateCache = (
|
|
888
896
|
{params, updater, options}:
|
|
889
897
|
{params: ${componentName}Variables,
|
|
890
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
898
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
891
899
|
options?: SetDataOptions | undefined}
|
|
892
900
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
893
901
|
|
|
@@ -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 {
|
|
@@ -404,7 +412,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
404
412
|
use${componentName}Query.updateCache = (
|
|
405
413
|
{params, updater, options}:
|
|
406
414
|
{params: ${componentName}Variables,
|
|
407
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
415
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
408
416
|
options?: SetDataOptions | undefined}
|
|
409
417
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
410
418
|
|
|
@@ -455,7 +463,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
455
463
|
use${componentName}Query.updateCache = (
|
|
456
464
|
{params, updater, options}:
|
|
457
465
|
{params: ${componentName}Variables,
|
|
458
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
466
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
459
467
|
options?: SetDataOptions | undefined}
|
|
460
468
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
461
469
|
|
|
@@ -496,7 +504,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
496
504
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
497
505
|
|
|
498
506
|
use${componentName}Query.updateCache = ({updater, options}:
|
|
499
|
-
{updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
507
|
+
{updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
500
508
|
options?: SetDataOptions | undefined}
|
|
501
509
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(), updater, options);
|
|
502
510
|
|
|
@@ -548,7 +556,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
548
556
|
use${componentName}Query.updateCache = (
|
|
549
557
|
{params, updater, options}:
|
|
550
558
|
{params: ${componentName}Variables,
|
|
551
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
559
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
552
560
|
options?: SetDataOptions | undefined}
|
|
553
561
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
554
562
|
|
|
@@ -589,7 +597,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
589
597
|
use${componentName}Query.updateCache = (
|
|
590
598
|
{params, updater, options}:
|
|
591
599
|
{params: ${componentName}Variables,
|
|
592
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
600
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
593
601
|
options?: SetDataOptions | undefined}
|
|
594
602
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
595
603
|
|
|
@@ -642,7 +650,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
642
650
|
use${componentName}Query.updateCache = (
|
|
643
651
|
{params, updater, options}:
|
|
644
652
|
{params: ${componentName}Variables,
|
|
645
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
653
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
646
654
|
options?: SetDataOptions | undefined}
|
|
647
655
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
648
656
|
|
|
@@ -695,7 +703,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
695
703
|
use${componentName}Query.updateCache = (
|
|
696
704
|
{params, updater, options}:
|
|
697
705
|
{params: ${componentName}Variables,
|
|
698
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
706
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
699
707
|
options?: SetDataOptions | undefined}
|
|
700
708
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
701
709
|
|
|
@@ -757,7 +765,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
757
765
|
use${componentName}Query.updateCache = (
|
|
758
766
|
{params, updater, options}:
|
|
759
767
|
{params: ${componentName}Variables,
|
|
760
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
768
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
761
769
|
options?: SetDataOptions | undefined}
|
|
762
770
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
763
771
|
|
|
@@ -813,7 +821,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
813
821
|
use${componentName}Query.updateCache = (
|
|
814
822
|
{params, updater, options}:
|
|
815
823
|
{params: ${componentName}Variables,
|
|
816
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
824
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
817
825
|
options?: SetDataOptions | undefined}
|
|
818
826
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
819
827
|
|
|
@@ -867,7 +875,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
867
875
|
use${componentName}Query.updateCache = (
|
|
868
876
|
{params, updater, options}:
|
|
869
877
|
{params: ${componentName}Variables,
|
|
870
|
-
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
878
|
+
updater: Updater<${componentName}Return | undefined, ${componentName}Return | undefined>,
|
|
871
879
|
options?: SetDataOptions | undefined}
|
|
872
880
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(params), updater, options);
|
|
873
881
|
|
|
@@ -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.1
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
},
|