mesg-foundation / js-sdk

Javascript mono-repo with all the tools to interact with MESG
https://mesg.com
4 stars 4 forks source link

Create "wrapper" type for service #59

Closed NicolasMahe closed 4 years ago

NicolasMahe commented 5 years ago

We need to create new type for the wrapper function to use. The generated type are not js developer friendly at all.

For example, https://github.com/mesg-foundation/mesg-js/pull/28/files#diff-ef7fcd1152991311bd36314bc5c76f17R24:

listenTask({ ...tasks }: Tasks): ResponseStream<TaskData>

should not use TaskData from the generated pb files but use a JS friendly type like:

interface TaskData {    
     executionID: string    
     taskKey: string    
     inputData: string  
 }

We can actually keep the interface from https://github.com/mesg-foundation/mesg-js/blob/master/src/client/service-client.ts

ilgooz commented 5 years ago

I updated API like below:

listenTask({ ...tasks }: Tasks): TaskStream
emitEvent(event: string, data: any): Promise<grpc.ServiceError|null>

listenTask() now returns a TaskStream. It has task, end events and cancel() method to cancel the stream.

let stream = listenTask({ ...tasks }: Tasks): TaskStream
stream.on('task', (task: Task) => {} )
stream.on('end', (err) => {} ) // err can be null when stream ended without an error
stream.cancel()
NicolasMahe commented 5 years ago

Please implement also the feedback from https://github.com/mesg-foundation/mesg-js/issues/40.

Does passing tasks to listenTask call automatically the task when the service receive it? Does listenTask accept no argument and in this case, the developer has to use stream.on('task',...?


What is grpc.ServiceError? if it an error it doesn't need to be in the return type of the promise.

ilgooz commented 5 years ago

Please implement also the feedback from mesg-foundation/js-sdk#58.

Does passing tasks to listenTask call automatically the task when the service receive it? Does listenTask accept no argument and in this case, the developer has to use stream.on('task',...?

What is grpc.ServiceError? if it an error it doesn't need to be in the return type of the promise.

ilgooz commented 5 years ago

solved by https://github.com/mesg-foundation/mesg-js/pull/49

ilgooz commented 5 years ago

We decided to change public APIs again so this changes will not be reflected to master branch. However we’ll keep this implementation in another branch called generated-and-high-level-apis for future attention.