Giter Club home page Giter Club logo

Comments (3)

str4d avatar str4d commented on August 24, 2024 1

Sure, atrium-repo sounds good. I'll open a PR with the initial implementation.

from atrium.

str4d avatar str4d commented on August 24, 2024

I've written code for MST and repo parsing myself for a CAR viewer project, on top of atrium-api and libipld (but will be migrating it to ipld-core soon). I'd be happy to upstream it here if we can decide where it should go.

The current APIs I have are:

struct Repository<R: tokio::io::AsyncRead + tokio::io::AsyncSeek> { .. }

impl<R: AsyncRead + AsyncSeek + Unpin + Send> Repository<R> {
    async fn load(reader: R) -> Result<Self, _> { .. }

    fn did(&self) -> &Did { .. }
    fn keys<'a>(&'a mut self) -> impl Stream<Item = Result<String, _>> + 'a { .. }

    fn get_collection<'a, C: Collection + 'a>(
        &'a mut self,
    ) -> impl futures::Stream<Item = Result<(RecordKey, C::Record), _>> + 'a { .. }

    fn get_collection_reversed<'a, C: Collection + 'a>(
        &'a mut self,
    ) -> impl futures::Stream<Item = Result<(RecordKey, C::Record), _>> + 'a { .. }

    async fn get<C: Collection>(
        &mut self,
        rkey: &RecordKey,
    ) -> Result<Option<C::Record>, _> { .. }
}

mod mst {
    enum Located<E> {
        Entry(E),
        InSubtree(Cid),
    }

    struct Node { .. }

    impl Node {
        fn parse(bytes: &[u8]) -> Result<Option<Self>, _> { .. }
        fn get(&self, key: &[u8]) -> Option<Located<Cid>> { .. }

        fn entries_with_prefix<'a>(
            &'a self,
            prefix: &'a [u8],
        ) -> impl Iterator<Item = Located<(&[u8], Cid)>> + 'a { .. }

        fn reversed_entries_with_prefix<'a>(
            &'a self,
            prefix: &'a [u8],
        ) -> impl Iterator<Item = Located<(&[u8], Cid)>> + 'a { .. }
    }
}

I went with async APIs because I'm reading a CAR file from disk. For firehose subscribers maybe sync APIs would be fine, but given that the crates in this repo already have async APIs, I figure this works fine as a starting point.

from atrium.

sugyan avatar sugyan commented on August 24, 2024

Thanks for the suggestion!
I hadn't considered implementing something about that yet, but if you would like to add it, Iā€™m very welcome to merge them.

Would it be better to add it as a new package, like atrium-repo (named from @atporoto/repo in reference to the original TypeScript implementation)?
Also, as you may have noticed, we are trying to add some new libraries in atrium-libs in #166, but this is still a draft. I am adding implementations little by little now and may eventually split each into separate packages.

from atrium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.