11import EventEmitter from 'eventemitter3'
2+ // @ts -expect-error
23import { ControlLayer } from 'streamr-client-protocol'
34import Debug from 'debug'
45
@@ -11,23 +12,24 @@ import Connection from './Connection'
1112import Publisher from './publish'
1213import Subscriber from './subscribe'
1314import { getUserId } from './user'
15+ import { Todo } from './types'
1416
1517/**
1618 * Wrap connection message events with message parsing.
1719 */
1820
1921class StreamrConnection extends Connection {
20- constructor ( ...args ) {
22+ constructor ( ...args : Todo ) {
2123 super ( ...args )
2224 this . on ( 'message' , this . onConnectionMessage )
2325 }
2426
2527 // eslint-disable-next-line class-methods-use-this
26- parse ( messageEvent ) {
28+ parse ( messageEvent : Todo ) {
2729 return ControlLayer . ControlMessage . deserialize ( messageEvent . data )
2830 }
2931
30- onConnectionMessage ( messageEvent ) {
32+ onConnectionMessage ( messageEvent : Todo ) {
3133 let controlMessage
3234 try {
3335 controlMessage = this . parse ( messageEvent )
@@ -48,28 +50,39 @@ class StreamrConnection extends Connection {
4850}
4951
5052class StreamrCached {
51- constructor ( client ) {
53+
54+ client : Todo
55+ getStream : Todo
56+ getUserInfo : Todo
57+ isStreamPublisher : Todo
58+ isStreamSubscriber : Todo
59+ getUserId : Todo
60+
61+ constructor ( client : StreamrClient ) {
5262 this . client = client
5363 const cacheOptions = client . options . cache
64+ // @ts -expect-error
5465 this . getStream = CacheAsyncFn ( client . getStream . bind ( client ) , {
5566 ...cacheOptions ,
56- cacheKey ( [ maybeStreamId ] ) {
67+ cacheKey ( [ maybeStreamId ] : Todo ) {
5768 const { streamId } = validateOptions ( maybeStreamId )
5869 return streamId
5970 }
6071 } )
6172 this . getUserInfo = CacheAsyncFn ( client . getUserInfo . bind ( client ) , cacheOptions )
73+ // @ts -expect-error
6274 this . isStreamPublisher = CacheAsyncFn ( client . isStreamPublisher . bind ( client ) , {
6375 ...cacheOptions ,
64- cacheKey ( [ maybeStreamId , ethAddress ] ) {
76+ cacheKey ( [ maybeStreamId , ethAddress ] : Todo ) {
6577 const { streamId } = validateOptions ( maybeStreamId )
6678 return `${ streamId } |${ ethAddress } `
6779 }
6880 } )
6981
82+ // @ts -expect-error
7083 this . isStreamSubscriber = CacheAsyncFn ( client . isStreamSubscriber . bind ( client ) , {
7184 ...cacheOptions ,
72- cacheKey ( [ maybeStreamId , ethAddress ] ) {
85+ cacheKey ( [ maybeStreamId , ethAddress ] : Todo ) {
7386 const { streamId } = validateOptions ( maybeStreamId )
7487 return `${ streamId } |${ ethAddress } `
7588 }
@@ -78,10 +91,10 @@ class StreamrCached {
7891 this . getUserId = CacheAsyncFn ( client . getUserId . bind ( client ) , cacheOptions )
7992 }
8093
81- clearStream ( streamId ) {
94+ clearStream ( streamId : Todo ) {
8295 this . getStream . clear ( )
83- this . isStreamPublisher . clearMatching ( ( s ) => s . startsWith ( streamId ) )
84- this . isStreamSubscriber . clearMatching ( ( s ) => s . startsWith ( streamId ) )
96+ this . isStreamPublisher . clearMatching ( ( s : Todo ) => s . startsWith ( streamId ) )
97+ this . isStreamSubscriber . clearMatching ( ( s : Todo ) => s . startsWith ( streamId ) )
8598 }
8699
87100 clearUser ( ) {
@@ -91,6 +104,7 @@ class StreamrCached {
91104
92105 clear ( ) {
93106 this . clearUser ( )
107+ // @ts -expect-error
94108 this . clearStream ( )
95109 }
96110}
@@ -99,7 +113,19 @@ class StreamrCached {
99113const uid = process . pid != null ? process . pid : `${ uuid ( ) . slice ( - 4 ) } ${ uuid ( ) . slice ( 0 , 4 ) } `
100114
101115export default class StreamrClient extends EventEmitter {
102- constructor ( options = { } , connection ) {
116+
117+ id : string
118+ debug : Debug . Debugger
119+ options : Todo
120+ getUserInfo : Todo
121+ session : Session
122+ connection : StreamrConnection
123+ publisher : Todo
124+ subscriber : Subscriber
125+ cached : StreamrCached
126+ ethereum : StreamrEthereum
127+
128+ constructor ( options : Todo = { } , connection ?: StreamrConnection ) {
103129 super ( )
104130 this . id = counterId ( `${ this . constructor . name } :${ uid } ` )
105131 this . debug = Debug ( this . id )
@@ -135,6 +161,7 @@ export default class StreamrClient extends EventEmitter {
135161 . on ( 'disconnected' , this . onConnectionDisconnected )
136162 . on ( 'error' , this . onConnectionError )
137163
164+ // @ts -expect-error
138165 this . publisher = new Publisher ( this )
139166 this . subscriber = new Subscriber ( this )
140167 this . cached = new StreamrCached ( this )
@@ -151,12 +178,12 @@ export default class StreamrClient extends EventEmitter {
151178 this . emit ( 'disconnected' )
152179 }
153180
154- onConnectionError ( err ) {
181+ onConnectionError ( err : Todo ) {
155182 this . emit ( 'error' , new Connection . ConnectionError ( err ) )
156183 }
157184
158- getErrorEmitter ( source ) {
159- return ( err ) => {
185+ getErrorEmitter ( source : Todo ) {
186+ return ( err : Todo ) => {
160187 if ( ! ( err instanceof Connection . ConnectionError || err . reason instanceof Connection . ConnectionError ) ) {
161188 // emit non-connection errors
162189 this . emit ( 'error' , err )
@@ -166,19 +193,20 @@ export default class StreamrClient extends EventEmitter {
166193 }
167194 }
168195
169- _onError ( err , ...args ) {
196+ _onError ( err : Todo , ...args : Todo ) {
197+ // @ts -expect-error
170198 this . onError ( err , ...args )
171199 }
172200
173- async send ( request ) {
201+ async send ( request : Todo ) {
174202 return this . connection . send ( request )
175203 }
176204
177205 /**
178206 * Override to control output
179207 */
180208
181- onError ( error ) { // eslint-disable-line class-methods-use-this
209+ onError ( error : Todo ) { // eslint-disable-line class-methods-use-this
182210 console . error ( error )
183211 }
184212
@@ -214,11 +242,12 @@ export default class StreamrClient extends EventEmitter {
214242 ] )
215243 }
216244
217- getSubscriptions ( ...args ) {
245+ getSubscriptions ( ...args : Todo ) {
218246 return this . subscriber . getAll ( ...args )
219247 }
220248
221- getSubscription ( ...args ) {
249+ getSubscription ( ...args : Todo ) {
250+ // @ts -expect-error
222251 return this . subscriber . get ( ...args )
223252 }
224253
@@ -234,25 +263,25 @@ export default class StreamrClient extends EventEmitter {
234263 return this . session . logout ( )
235264 }
236265
237- async publish ( ...args ) {
266+ async publish ( ...args : Todo ) {
238267 return this . publisher . publish ( ...args )
239268 }
240269
241270 async getUserId ( ) {
242271 return getUserId ( this )
243272 }
244273
245- setNextGroupKey ( ...args ) {
274+ setNextGroupKey ( ...args : Todo ) {
246275 return this . publisher . setNextGroupKey ( ...args )
247276 }
248277
249- rotateGroupKey ( ...args ) {
278+ rotateGroupKey ( ...args : Todo ) {
250279 return this . publisher . rotateGroupKey ( ...args )
251280 }
252281
253- async subscribe ( opts , onMessage ) {
254- let subTask
255- let sub
282+ async subscribe ( opts : Todo , onMessage : Todo ) {
283+ let subTask : Todo
284+ let sub : Todo
256285 const hasResend = ! ! ( opts . resend || opts . from || opts . to || opts . last )
257286 const onEnd = ( ) => {
258287 if ( sub && typeof onMessage === 'function' ) {
@@ -281,11 +310,11 @@ export default class StreamrClient extends EventEmitter {
281310 return subTask
282311 }
283312
284- async unsubscribe ( opts ) {
313+ async unsubscribe ( opts : Todo ) {
285314 await this . subscriber . unsubscribe ( opts )
286315 }
287316
288- async resend ( opts , onMessage ) {
317+ async resend ( opts : Todo , onMessage : Todo ) {
289318 const task = this . subscriber . resend ( opts )
290319 if ( typeof onMessage !== 'function' ) {
291320 return task
@@ -304,11 +333,11 @@ export default class StreamrClient extends EventEmitter {
304333 return task
305334 }
306335
307- enableAutoConnect ( ...args ) {
336+ enableAutoConnect ( ...args : Todo ) {
308337 return this . connection . enableAutoConnect ( ...args )
309338 }
310339
311- enableAutoDisconnect ( ...args ) {
340+ enableAutoDisconnect ( ...args : Todo ) {
312341 return this . connection . enableAutoDisconnect ( ...args )
313342 }
314343
0 commit comments