Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export low level functions for feeds and soc #379

Open
r0qs opened this issue Jul 28, 2021 · 5 comments
Open

Export low level functions for feeds and soc #379

r0qs opened this issue Jul 28, 2021 · 5 comments

Comments

@r0qs
Copy link

r0qs commented Jul 28, 2021

Hi, currently some very useful low level functions are not exported. To list few: makeSingleOwnerChunkFromData, uploadSingleOwnerChunkData, recoverChunkOwner and downloadSingleOwnerChunk from the soc api, and makeFeedIdentifier, uploadFeedUpdate, downloadFeedUpdate, etc, from the feeds api.

Have those functions exported could allow developers to create more powerful dapps using bee-js. For instance, I want to control the index of a feed, but I cannot do that with the current api. On the other hand, if functions like findNextIndex and uploadFeedUpdate were exported I could do that.

Some dapps will have a different way to create and manage chunks and would be nice if bee-js was flexible enough to allow that.

So I'm wondering if these functions can be exported. Currently, I'm forced to basically replicate most of the feed and soc functions in my own code just to be able to manipulate few parameters like the index since most of these functions have a high level of dependencies between themselves and they are not exported. This seems to remove the necessity to use bee-js as a library for my app.

There is any way that I can manipulate the index of a feed for example? Or get the owner of a soc in the current api?

@agazso
Copy link
Member

agazso commented Jul 28, 2021

Indeed the low-level details of soc and feeds are not exposed because we did not see clearly how people would use them and what would be a good level of abstraction.

Could you please share an example of what exactly you are trying to do?

Without knowing that I can suggest that manipulating the index of a feed can be done by writing single owner chunks with the SOCWriter interface because that is the underlying primitive for feeds. The owner of a soc can be get by invoking owner() on the SingleOwnerChunk interface, but I assume you need something else.

@r0qs
Copy link
Author

r0qs commented Jul 28, 2021

Could you please share an example of what exactly you are trying to do?

Sure, I want to download a feed update at a specific index. I know that it is possible to do using the downloadFeedUpdate method, but it is not exposed.
This function would allow me to do range queries in my feeds, which are necessary for my application to fetch a list of "email chunks" (each one is a feed update) in a specific interval.

Without knowing that I can suggest that manipulating the index of a feed can be done by writing single owner chunks with the SOCWriter interface because that is the underlying primitive for feeds.

Hum... so if I understand it correctly, I could read a feed update in a specific index using the SOCReader, since I can control the identifier and thus the index, right?
Like, to read a interval using the SOCReader I would need to retrieve the feed update in the last index in my interval, and incrementally query each previous update until the beginning of the interval.
There is any plans to support stream of feed updates?

The owner of a soc can be get by invoking owner() on the SingleOwnerChunk interface, but I assume you need something else.

But given that I have the data of a chunk how to get the owner? I would need to create a SingleOwnerChunk type from this data to use the owner method, but makeSingleOwnerChunkFromData is not exposed, so I cannot create one.

@agazso
Copy link
Member

agazso commented Jul 30, 2021

Hum... so if I understand it correctly, I could read a feed update in a specific index using the SOCReader, since I can control the identifier and thus the index, right?
Like, to read a interval using the SOCReader I would need to retrieve the feed update in the last index in my interval, and incrementally query each previous update until the beginning of the interval.

Right now the only type of feeds that are implemented in Bee are sequential type, meaning that if you know the index of the latest feed update you will immediately know how many updates were and can easily fetch any of them by using their numeric id.

In bee-js there is only one utility function regarding working with sequential feed indexes (makeSequentialFeedIdentifier), but if you want to do the above functionality for incrementing/decrementing for now maybe it's better to roll your own.

There is any plans to support stream of feed updates?

There is ongoing work to add stream uploading of chunks but not downloading them as far as I know. The best option right now is to issue multiple requests parallely.

But given that I have the data of a chunk how to get the owner? I would need to create a SingleOwnerChunk type from this data to use the owner method, but makeSingleOwnerChunkFromData is not exposed, so I cannot create one.

That's correct, this functionality is not yet exposed. We are currently researching how it would be best to expose this functionality, we are considering creating separating packages that could be possibly used without even using bee-js. Stay tuned!

@r0qs
Copy link
Author

r0qs commented Aug 2, 2021

Thank you very much. Yeah, I just started to do my own implementation of it here, but I'll definitely keep a eye on the next releases.

@AuHau
Copy link
Contributor

AuHau commented Sep 20, 2021

@r0qs we plan splitting of bee-js into several modules to better support low level operations as you would need. Please have a look #413 and leave your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants