1- import  {  type  LogType  }  from  "../interfaces" ; 
1+ import  { 
2+   type  ActionDispatcherHook , 
3+   combine , 
4+   type  Hook , 
5+   type  HttpHook , 
6+   type  LogType , 
7+ }  from  "../interfaces" ; 
28import  {  type  mastodon  }  from  "../mastodon" ; 
39import  { 
410  createActionProxy , 
511  HttpActionDispatcher , 
612  WebSocketActionDispatcher , 
713}  from  "./action" ; 
8- import  {  HttpActionDispatcherHookMastodon  }  from  "./action/dispatcher-http-hook-mastodon" ; 
914import  { 
1015  HttpConfigImpl , 
1116  type  MastoHttpConfigProps , 
1217  WebSocketConfigImpl , 
1318  type  WebSocketConfigProps , 
1419}  from  "./config" ; 
20+ import  {  ActionDispatcherHookMastodon ,  HttpHookMastodon  }  from  "./hook" ; 
1521import  {  HttpNativeImpl  }  from  "./http" ; 
1622import  {  createLogger  }  from  "./logger" ; 
1723import  {  SerializerNativeImpl  }  from  "./serializers" ; 
@@ -31,15 +37,40 @@ interface LogConfigProps {
3137  readonly  log ?: LogType ; 
3238} 
3339
40+ interface  HookProps  { 
41+   readonly  use ?: readonly  Hook [ ] ; 
42+ } 
43+ 
3444export  const  createRestAPIClient  =  ( 
35-   props : MastoHttpConfigProps  &  LogConfigProps , 
45+   props : MastoHttpConfigProps  &  LogConfigProps   &   HookProps , 
3646) : mastodon . rest . Client  =>  { 
47+   const  use  =  props . use  ??  [ ] ; 
48+ 
3749  const  serializer  =  new  SerializerNativeImpl ( ) ; 
3850  const  config  =  new  HttpConfigImpl ( props ,  serializer ) ; 
3951  const  logger  =  createLogger ( props . log ) ; 
40-   const  http  =  new  HttpNativeImpl ( serializer ,  config ,  logger ) ; 
41-   const  hook  =  new  HttpActionDispatcherHookMastodon ( http ) ; 
42-   const  actionDispatcher  =  new  HttpActionDispatcher ( http ,  hook ) ; 
52+ 
53+   const  http  =  new  HttpNativeImpl ( 
54+     serializer , 
55+     config , 
56+     logger , 
57+     combine ( [ 
58+       ...use . filter ( ( hook ) : hook  is HttpHook  =>  hook . type  ===  "Http" ) , 
59+       new  HttpHookMastodon ( ) , 
60+     ] ) , 
61+   ) ; 
62+ 
63+   const  actionDispatcher  =  new  HttpActionDispatcher ( 
64+     http , 
65+     combine ( [ 
66+       ...use . filter ( 
67+         ( hook ) : hook  is ActionDispatcherHook  => 
68+           hook . type  ===  "ActionDispatcher" , 
69+       ) , 
70+       new  ActionDispatcherHookMastodon ( http ) , 
71+     ] ) , 
72+   ) ; 
73+ 
4374  const  actionProxy  =  createActionProxy ( actionDispatcher ,  { 
4475    context : [ "api" ] , 
4576  } )  as  mastodon . rest . Client ; 
@@ -53,8 +84,8 @@ export const createOAuthAPIClient = (
5384  const  config  =  new  HttpConfigImpl ( props ,  serializer ) ; 
5485  const  logger  =  createLogger ( props . log ) ; 
5586  const  http  =  new  HttpNativeImpl ( serializer ,  config ,  logger ) ; 
56-   const  hook  =  new  HttpActionDispatcherHookMastodon ( http ) ; 
57-   const  actionDispatcher  =  new  HttpActionDispatcher ( http ,  hook ) ; 
87+   const  actionDispatcherHook  =  new  ActionDispatcherHookMastodon ( http ) ; 
88+   const  actionDispatcher  =  new  HttpActionDispatcher ( http ,  actionDispatcherHook ) ; 
5889  const  actionProxy  =  createActionProxy ( actionDispatcher ,  { 
5990    context : [ "oauth" ] , 
6091  } )  as  mastodon . oauth . Client ; 
0 commit comments