@@ -5,7 +5,7 @@ const transports = require('./transports');
55function rawr ( { transport, timeout = 0 , handlers = { } , methods, idGenerator } ) {
66 let callId = 0 ;
77 // eslint-disable-next-line no-param-reassign
8- methods = methods || handlers ; // backwards compat
8+ methods = methods || handlers || { } ; // backwards compat
99 const pendingCalls = { } ;
1010 const methodHandlers = { } ;
1111 const notificationEvents = new EventEmitter ( ) ;
@@ -112,6 +112,8 @@ function rawr({ transport, timeout = 0, handlers = {}, methods, idGenerator }) {
112112 const testArg = args . pop ( ) ;
113113 if ( testArg && typeof testArg === 'object' && ! Array . isArray ( testArg ) ) {
114114 config = testArg ;
115+ } else {
116+ args . push ( testArg ) ;
115117 }
116118 }
117119 return sendMessage ( name , args , config || { } ) ;
@@ -133,6 +135,28 @@ function rawr({ transport, timeout = 0, handlers = {}, methods, idGenerator }) {
133135 }
134136 } ) ;
135137
138+ const configurableNotifiersProxy = new Proxy ( { } , {
139+ get : ( target , name ) => {
140+ return ( ...args ) => {
141+ let config ;
142+ if ( args . length ) {
143+ const testArg = args . pop ( ) ;
144+ if ( testArg && typeof testArg === 'object' && ! Array . isArray ( testArg ) ) {
145+ config = testArg ;
146+ } else {
147+ args . push ( testArg ) ;
148+ }
149+ }
150+ const msg = {
151+ jsonrpc : '2.0' ,
152+ method : name ,
153+ params : args
154+ } ;
155+ transport . send ( msg , config || { } ) ;
156+ } ;
157+ }
158+ } ) ;
159+
136160 const notifications = new Proxy ( { } , {
137161 get : ( target , name ) => {
138162 return ( callback ) => {
@@ -149,6 +173,7 @@ function rawr({ transport, timeout = 0, handlers = {}, methods, idGenerator }) {
149173 addHandler,
150174 notifications,
151175 notifiers,
176+ notifiersExt : configurableNotifiersProxy ,
152177 transport,
153178 } ;
154179}
0 commit comments