Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit bfc7141

Browse files
committed
Encapsulate endpoints
1 parent b53e327 commit bfc7141

32 files changed

+1062
-825
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"main": "dist/streamr-client.nodejs.js",
1010
"browser": "dist/streamr-client.web.min.js",
11-
"types": "dist/types/src/index.d.ts",
11+
"types": "dist/types/src/StreamrClient.d.ts",
1212
"directories": {
1313
"example": "examples",
1414
"test": "test"

src/StreamrClient.ts

Lines changed: 204 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import Publisher from './publish'
1313
import Subscriber from './subscribe'
1414
import { getUserId } from './user'
1515
import { Todo } from './types'
16+
import { StreamEndpoints } from './rest/StreamEndpoints'
17+
import { LoginEndpoints } from './rest/LoginEndpoints'
18+
import { DataUnionEndpoints } from './rest/DataUnionEndpoints'
1619

1720
/**
1821
* Wrap connection message events with message parsing.
@@ -61,7 +64,6 @@ class StreamrCached {
6164
constructor(client: StreamrClient) {
6265
this.client = client
6366
const cacheOptions = client.options.cache
64-
// @ts-expect-error
6567
this.getStream = CacheAsyncFn(client.getStream.bind(client), {
6668
...cacheOptions,
6769
cacheKey([maybeStreamId]: Todo) {
@@ -70,7 +72,6 @@ class StreamrCached {
7072
}
7173
})
7274
this.getUserInfo = CacheAsyncFn(client.getUserInfo.bind(client), cacheOptions)
73-
// @ts-expect-error
7475
this.isStreamPublisher = CacheAsyncFn(client.isStreamPublisher.bind(client), {
7576
...cacheOptions,
7677
cacheKey([maybeStreamId, ethAddress]: Todo) {
@@ -79,7 +80,6 @@ class StreamrCached {
7980
}
8081
})
8182

82-
// @ts-expect-error
8383
this.isStreamSubscriber = CacheAsyncFn(client.isStreamSubscriber.bind(client), {
8484
...cacheOptions,
8585
cacheKey([maybeStreamId, ethAddress]: Todo) {
@@ -117,13 +117,15 @@ export default class StreamrClient extends EventEmitter {
117117
id: string
118118
debug: Debug.Debugger
119119
options: Todo
120-
getUserInfo: Todo
121120
session: Session
122121
connection: StreamrConnection
123122
publisher: Todo
124123
subscriber: Subscriber
125124
cached: StreamrCached
126125
ethereum: StreamrEthereum
126+
streamEndpoints: StreamEndpoints
127+
loginEndpoints: LoginEndpoints
128+
dataUnionEndpoints: DataUnionEndpoints
127129

128130
constructor(options: Todo = {}, connection?: StreamrConnection) {
129131
super()
@@ -144,7 +146,6 @@ export default class StreamrClient extends EventEmitter {
144146
})
145147

146148
// bind event handlers
147-
this.getUserInfo = this.getUserInfo.bind(this)
148149
this.onConnectionConnected = this.onConnectionConnected.bind(this)
149150
this.onConnectionDisconnected = this.onConnectionDisconnected.bind(this)
150151
this._onError = this._onError.bind(this)
@@ -166,6 +167,10 @@ export default class StreamrClient extends EventEmitter {
166167
this.subscriber = new Subscriber(this)
167168
this.cached = new StreamrCached(this)
168169
this.ethereum = new StreamrEthereum(this)
170+
171+
this.streamEndpoints = new StreamEndpoints(this)
172+
this.loginEndpoints = new LoginEndpoints(this)
173+
this.dataUnionEndpoints = new DataUnionEndpoints(this)
169174
}
170175

171176
async onConnectionConnected() {
@@ -352,4 +357,198 @@ export default class StreamrClient extends EventEmitter {
352357
static generateEthereumAccount() {
353358
return StreamrEthereum.generateEthereumAccount()
354359
}
360+
361+
// TODO many of these methods that use streamEndpoints/loginEndpoints/dataUnionEndpoints are private: remove those
362+
363+
async getStream(streamId: Todo) {
364+
return this.streamEndpoints.getStream(streamId)
365+
}
366+
367+
async listStreams(query: Todo = {}) {
368+
return this.streamEndpoints.listStreams(query)
369+
}
370+
371+
async getStreamByName(name: string) {
372+
return this.streamEndpoints.getStreamByName(name)
373+
}
374+
375+
async createStream(props: Todo) {
376+
return this.streamEndpoints.createStream(props)
377+
}
378+
379+
async getOrCreateStream(props: Todo) {
380+
return this.streamEndpoints.getOrCreateStream(props)
381+
}
382+
383+
async getStreamPublishers(streamId: Todo) {
384+
return this.streamEndpoints.getStreamPublishers(streamId)
385+
}
386+
387+
async isStreamPublisher(streamId: Todo, ethAddress: Todo) {
388+
return this.streamEndpoints.isStreamPublisher(streamId, ethAddress)
389+
}
390+
391+
async getStreamSubscribers(streamId: Todo) {
392+
return this.streamEndpoints.getStreamSubscribers(streamId)
393+
}
394+
395+
async isStreamSubscriber(streamId: Todo, ethAddress: Todo) {
396+
return this.streamEndpoints.isStreamSubscriber(streamId, ethAddress)
397+
}
398+
399+
async getStreamValidationInfo(streamId: Todo) {
400+
return this.streamEndpoints.getStreamValidationInfo(streamId)
401+
}
402+
403+
async getStreamLast(streamObjectOrId: Todo) {
404+
return this.streamEndpoints.getStreamLast(streamObjectOrId)
405+
}
406+
407+
async getStreamPartsByStorageNode(address: Todo) {
408+
return this.streamEndpoints.getStreamPartsByStorageNode(address)
409+
}
410+
411+
async publishHttp(streamObjectOrId: Todo, data: Todo, requestOptions: Todo = {}, keepAlive: Todo = true) {
412+
return this.streamEndpoints.publishHttp(streamObjectOrId, data, requestOptions, keepAlive)
413+
}
414+
415+
async getChallenge(address: Todo) {
416+
return this.loginEndpoints.getChallenge(address)
417+
}
418+
419+
async sendChallengeResponse(challenge: Todo, signature: Todo, address: Todo) {
420+
return this.loginEndpoints.sendChallengeResponse(challenge, signature, address)
421+
}
422+
423+
async loginWithChallengeResponse(signingFunction: Todo, address: Todo) {
424+
return this.loginEndpoints.loginWithChallengeResponse(signingFunction, address)
425+
}
426+
427+
async loginWithApiKey(apiKey: Todo) {
428+
return this.loginEndpoints.loginWithApiKey(apiKey)
429+
}
430+
431+
async loginWithUsernamePassword(username: Todo, password: Todo) {
432+
return this.loginEndpoints.loginWithUsernamePassword(username, password)
433+
}
434+
435+
async getUserInfo() {
436+
return this.loginEndpoints.getUserInfo()
437+
}
438+
439+
async logoutEndpoint() {
440+
return this.loginEndpoints.logoutEndpoint()
441+
}
442+
443+
async calculateDataUnionMainnetAddress(dataUnionName: Todo, deployerAddress: Todo, options: Todo) {
444+
return this.dataUnionEndpoints.calculateDataUnionMainnetAddress(dataUnionName, deployerAddress, options)
445+
}
446+
447+
async calculateDataUnionSidechainAddress(duMainnetAddress: Todo, options: Todo) {
448+
return this.dataUnionEndpoints.calculateDataUnionSidechainAddress(duMainnetAddress, options)
449+
}
450+
451+
async deployDataUnion(options: Todo = {}) {
452+
return this.dataUnionEndpoints.deployDataUnion(options)
453+
}
454+
455+
async getDataUnionContract(options: Todo = {}) {
456+
return this.dataUnionEndpoints.getDataUnionContract(options)
457+
}
458+
459+
async createSecret(dataUnionMainnetAddress: Todo, name: string = 'Untitled Data Union Secret') {
460+
return this.dataUnionEndpoints.createSecret(dataUnionMainnetAddress, name)
461+
}
462+
463+
async kick(memberAddressList: Todo, options: Todo = {}) {
464+
return this.dataUnionEndpoints.kick(memberAddressList, options)
465+
}
466+
467+
async addMembers(memberAddressList: Todo, options: Todo = {}) {
468+
return this.dataUnionEndpoints.addMembers(memberAddressList, options)
469+
}
470+
471+
async withdrawMember(memberAddress: Todo, options: Todo) {
472+
return this.dataUnionEndpoints.withdrawMember(memberAddress, options)
473+
}
474+
475+
async getWithdrawMemberTx(memberAddress: Todo, options: Todo) {
476+
return this.dataUnionEndpoints.getWithdrawMemberTx(memberAddress, options)
477+
}
478+
479+
async withdrawToSigned(memberAddress: Todo, recipientAddress: Todo, signature: Todo, options: Todo) {
480+
return this.dataUnionEndpoints.withdrawToSigned(memberAddress, recipientAddress, signature, options)
481+
}
482+
483+
async getWithdrawToSignedTx(memberAddress: Todo, recipientAddress: Todo, signature: Todo, options: Todo) {
484+
return this.dataUnionEndpoints.getWithdrawToSignedTx(memberAddress, recipientAddress, signature, options)
485+
}
486+
487+
async setAdminFee(newFeeFraction: Todo, options: Todo) {
488+
return this.dataUnionEndpoints.setAdminFee(newFeeFraction, options)
489+
}
490+
491+
async getAdminFee(options: Todo) {
492+
return this.dataUnionEndpoints.getAdminFee(options)
493+
}
494+
495+
async getAdminAddress(options: Todo) {
496+
return this.dataUnionEndpoints.getAdminAddress(options)
497+
}
498+
499+
async joinDataUnion(options: Todo = {}) {
500+
return this.dataUnionEndpoints.joinDataUnion(options)
501+
}
502+
503+
async hasJoined(memberAddress: Todo, options: Todo = {}) {
504+
return this.dataUnionEndpoints.hasJoined(memberAddress, options)
505+
}
506+
507+
async getMembers(options: Todo) {
508+
return this.dataUnionEndpoints.getMembers(options)
509+
}
510+
511+
async getDataUnionStats(options: Todo) {
512+
return this.dataUnionEndpoints.getDataUnionStats(options)
513+
}
514+
515+
async getMemberStats(memberAddress: Todo, options: Todo) {
516+
return this.dataUnionEndpoints.getMemberStats(memberAddress, options)
517+
}
518+
519+
async getMemberBalance(memberAddress: Todo, options: Todo) {
520+
return this.dataUnionEndpoints.getMemberBalance(memberAddress, options)
521+
}
522+
523+
async getTokenBalance(address: Todo, options: Todo) {
524+
return this.dataUnionEndpoints.getTokenBalance(address, options)
525+
}
526+
527+
async getDataUnionVersion(contractAddress: Todo) {
528+
return this.dataUnionEndpoints.getDataUnionVersion(contractAddress)
529+
}
530+
531+
async withdraw(options: Todo = {}) {
532+
return this.dataUnionEndpoints.withdraw(options)
533+
}
534+
535+
async getWithdrawTx(options: Todo) {
536+
return this.dataUnionEndpoints.getWithdrawTx(options)
537+
}
538+
539+
async withdrawTo(recipientAddress: Todo, options = {}) {
540+
return this.dataUnionEndpoints.withdrawTo(recipientAddress, options)
541+
}
542+
543+
async getWithdrawTxTo(recipientAddress: Todo, options: Todo) {
544+
return this.dataUnionEndpoints.getWithdrawTxTo(recipientAddress, options)
545+
}
546+
547+
async signWithdrawTo(recipientAddress: Todo, options: Todo) {
548+
return this.dataUnionEndpoints.signWithdrawTo(recipientAddress, options)
549+
}
550+
551+
async signWithdrawAmountTo(recipientAddress: Todo, amountTokenWei: Todo, options: Todo) {
552+
return this.dataUnionEndpoints.signWithdrawAmountTo(recipientAddress, amountTokenWei, options)
553+
}
355554
}

src/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)