File tree Expand file tree Collapse file tree
packages/base-data-service/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Messenger } from '@metamask/messenger' ;
22import { Json } from '@metamask/utils' ;
33import {
4+ DehydratedState ,
45 InfiniteData ,
56 InfiniteQueryObserver ,
67 QueryClient ,
@@ -15,6 +16,7 @@ import {
1516 ExampleDataServiceActions ,
1617 ExampleMessenger ,
1718 GetActivityResponse ,
19+ GetAssetsResponse ,
1820} from '../tests/ExampleDataService' ;
1921import {
2022 mockAssets ,
@@ -33,9 +35,11 @@ function createClient(serviceMessenger: ExampleMessenger): QueryClient {
3335
3436 const messengerAdapter = {
3537 call : async (
36- method : ExampleDataServiceActions [ 'type' ] ,
38+ method : string ,
3739 ...params : Json [ ]
38- ) => {
40+ ) : Promise <
41+ void | DehydratedState | GetActivityResponse | GetAssetsResponse
42+ > => {
3943 if ( method === 'ExampleDataService:subscribe' ) {
4044 return serviceMessenger . call (
4145 method ,
@@ -49,7 +53,11 @@ function createClient(serviceMessenger: ExampleMessenger): QueryClient {
4953 subscription ,
5054 ) ;
5155 }
52- return serviceMessenger . call ( method , ...params ) ;
56+ return serviceMessenger . call (
57+ method as ExampleDataServiceActions [ 'type' ] ,
58+ // @ts -expect-error TODO.
59+ ...params ,
60+ ) ;
5361 } ,
5462 subscribe : async (
5563 _method : string ,
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ function getServiceFromQueryKey(queryKey: QueryKey): string {
1212 return queryKey [ 0 ] . split ( ':' ) [ 0 ] ;
1313}
1414
15+ // When UI messengers are available this should simply be a proper messenger that allows access to DataServiceActions
1516type MessengerAdapter = {
16- call : ( method : string , ...params : Json [ ] ) => Promise < Json > ;
17+ call : ( method : string , ...params : Json [ ] ) => Promise < Json | void > ;
1718 subscribe : ( method : string , callback : ( data : Json ) => void ) => void ;
1819} ;
1920
@@ -47,11 +48,11 @@ export function createUIQueryClient(
4748 'Queries must use data service actions.' ,
4849 ) ;
4950
50- return await messenger . call (
51+ return ( await messenger . call (
5152 action ,
5253 ...( options . queryKey . slice ( 1 ) as Json [ ] ) ,
5354 options . pageParam ,
54- ) ;
55+ ) ) as Json ;
5556 } ,
5657 // TODO: Decide on values for these.
5758 staleTime : Infinity ,
You can’t perform that action at this time.
0 commit comments