Commit d6e6704
committed
Give records a reference to the model manager which loaded them
We have a few upcoming things that require records to be able to do stuff to themselves -- reload, select new fields from the backend, maybe `record.save` or similar, and I suspect more in the future. I still think they should act mostly as DTOs that don't have a lot of business logic on them, but if we want to be able to even know what model they are for, we need a reference to the thing that produced them! This passes along the model manager which instantiated a record to the record in both imperative API land and in React land.
In order to make this change work in React land, we need a new little bit of metadata exported from the generated client. Our React hooks get passed functions from the api client like `useAction(api.post.create)`, so we need to be able to hop back from the `create` function that we get by reference to the `api.post` object. The generated client will need to decorate the `create` function with a reference, which is not super hard, but means that we have a backwards compatibility issue. `@gadgetinc/react` can't assume that it is upgraded at the same time as the api client, so it can't assume it is working against a newly generated api client that has this metadata.
For this reason, the model manager property on `GadgetRecord` is optional, which reflects the way it will be used in the real world without necessarily having that metadata available. When we go to build things like `record.reload()`, we can make that fail at runtime with a message saying "regenerate your client to get this to work!", instead of just assuming it is present.1 parent b689df5 commit d6e6704
File tree
25 files changed
+216
-128
lines changed- packages
- api-client-core
- spec
- src
- react/src
- auth
- auto
- shadcn/table
25 files changed
+216
-128
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| |||
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
51 | 66 | | |
52 | 67 | | |
53 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | | - | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
173 | | - | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| |||
240 | 242 | | |
241 | 243 | | |
242 | 244 | | |
243 | | - | |
| 245 | + | |
244 | 246 | | |
245 | 247 | | |
246 | 248 | | |
| |||
316 | 318 | | |
317 | 319 | | |
318 | 320 | | |
319 | | - | |
| 321 | + | |
320 | 322 | | |
321 | 323 | | |
322 | 324 | | |
| |||
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | | - | |
| 342 | + | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| |||
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
372 | | - | |
| 374 | + | |
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
| |||
400 | 402 | | |
401 | 403 | | |
402 | 404 | | |
403 | | - | |
| 405 | + | |
404 | 406 | | |
405 | 407 | | |
406 | 408 | | |
| |||
436 | 438 | | |
437 | 439 | | |
438 | 440 | | |
439 | | - | |
| 441 | + | |
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
| |||
466 | 468 | | |
467 | 469 | | |
468 | 470 | | |
469 | | - | |
| 471 | + | |
470 | 472 | | |
471 | 473 | | |
472 | 474 | | |
| |||
502 | 504 | | |
503 | 505 | | |
504 | 506 | | |
505 | | - | |
506 | | - | |
507 | | - | |
| 507 | + | |
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| |||
544 | 544 | | |
545 | 545 | | |
546 | 546 | | |
547 | | - | |
548 | | - | |
549 | | - | |
| 547 | + | |
550 | 548 | | |
551 | 549 | | |
552 | 550 | | |
| |||
591 | 589 | | |
592 | 590 | | |
593 | 591 | | |
594 | | - | |
595 | | - | |
596 | | - | |
| 592 | + | |
597 | 593 | | |
598 | 594 | | |
599 | 595 | | |
| |||
646 | 642 | | |
647 | 643 | | |
648 | 644 | | |
649 | | - | |
650 | | - | |
651 | | - | |
| 645 | + | |
652 | 646 | | |
653 | 647 | | |
654 | 648 | | |
| |||
693 | 687 | | |
694 | 688 | | |
695 | 689 | | |
696 | | - | |
697 | | - | |
698 | | - | |
| 690 | + | |
699 | 691 | | |
700 | 692 | | |
701 | 693 | | |
| |||
733 | 725 | | |
734 | 726 | | |
735 | 727 | | |
736 | | - | |
737 | | - | |
738 | | - | |
| 728 | + | |
739 | 729 | | |
740 | 730 | | |
741 | 731 | | |
| |||
780 | 770 | | |
781 | 771 | | |
782 | 772 | | |
783 | | - | |
784 | | - | |
785 | | - | |
| 773 | + | |
786 | 774 | | |
787 | 775 | | |
788 | 776 | | |
| |||
830 | 818 | | |
831 | 819 | | |
832 | 820 | | |
833 | | - | |
834 | | - | |
835 | | - | |
| 821 | + | |
836 | 822 | | |
837 | 823 | | |
838 | 824 | | |
| |||
880 | 866 | | |
881 | 867 | | |
882 | 868 | | |
883 | | - | |
884 | | - | |
885 | | - | |
| 869 | + | |
886 | 870 | | |
887 | 871 | | |
888 | 872 | | |
| |||
921 | 905 | | |
922 | 906 | | |
923 | 907 | | |
924 | | - | |
925 | | - | |
926 | | - | |
| 908 | + | |
927 | 909 | | |
928 | 910 | | |
929 | 911 | | |
| |||
970 | 952 | | |
971 | 953 | | |
972 | 954 | | |
973 | | - | |
974 | | - | |
975 | | - | |
| 955 | + | |
976 | 956 | | |
977 | 957 | | |
978 | 958 | | |
| |||
1010 | 990 | | |
1011 | 991 | | |
1012 | 992 | | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
| 993 | + | |
1016 | 994 | | |
1017 | 995 | | |
1018 | 996 | | |
| |||
1057 | 1035 | | |
1058 | 1036 | | |
1059 | 1037 | | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
| 1038 | + | |
1063 | 1039 | | |
1064 | 1040 | | |
1065 | 1041 | | |
| |||
1958 | 1934 | | |
1959 | 1935 | | |
1960 | 1936 | | |
1961 | | - | |
| 1937 | + | |
1962 | 1938 | | |
1963 | 1939 | | |
1964 | 1940 | | |
| |||
Lines changed: 26 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
0 commit comments