Code Monkey home page Code Monkey logo

orbit-db-eventstore's Introduction

orbit-db-eventstore

npm version Gitter Matrix

Append-Only Log database for orbit-db

An append-only log with traversable history. Useful for "latest N" use cases or as a message queue.

Used in orbit-db.

Table of Contents

Install

This project uses npm and nodejs

npm install orbit-db ipfs

Usage

First, create an instance of OrbitDB:

import * as IPFS from 'ipfs'
import OrbitDB from 'orbit-db'

const ipfs = new IPFS()
const orbitdb = await OrbitDB.createInstance(ipfs)

Get a log database and add an entry to it:

const log = await orbitdb.eventlog('haad.posts')
log.add({ name: 'hello world' })
  .then(() => {
    const items = log.iterator().collect().map(e => e.payload.value)
    items.forEach(e => console.log(e.name))
    // "hello world"
  })

Later, when the database contains data, load the history and query when ready:

const log = await orbitdb.eventlog('haad.posts')
log.events.on('ready', () => {
  const items = log.iterator().collect().map(e => e.payload.value)
  items.forEach(e => console.log(e.name))
  // "hello world"
})

See example/index.html for a detailed example. Note that to run this example, you need to have a local IPFS daemon running at port 5001.

API

See orbit-db's API Documenations for full details.

Contributing

If you think this could be better, please open an issue!

Please note that all interactions in @orbitdb fall under our Code of Conduct.

Note that tests for this module are in the orbit-db repository.

License

MIT © 2016-2020 Protocol Labs Inc., Haja Networks Oy

orbit-db-eventstore's People

Contributors

adam-palazzo avatar aphelionz avatar greenkeeperio-bot avatar haadcode avatar haydenyoung avatar richardlitt avatar shamb0t avatar vaultec81 avatar xmader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

orbit-db-eventstore's Issues

If hash is not present, get() returns element at 0th index

This is the get() method in EventStore:

get (hash) {
    return this.iterator({ gte: hash, limit: 1 }).collect()[0]
}

The get() method indirectly calls _read method:

 _read (ops, hash, amount, inclusive) {
    // Find the index of the gt/lt hash, or start from the beginning of the array if not found
    const index = ops.map((e) => e.hash).indexOf(hash)
    let startIndex = Math.max(index, 0)
    // If gte/lte is set, we include the given hash, if not, start from the next element
    startIndex += inclusive ? 0 : 1
    // Slice the array to its requested size
    const res = ops.slice(startIndex).slice(0, amount)
    return res
  }

If you call this method with a hash (let's say "foobar") that's not present in the EventStore, you'll notice that _read still returns the element at 0th index. We noticed this while using get() method in the FeedStore (https://github.com/orbitdb/orbit-db-feedstore/blob/main/src/FeedStore.js).

Add topics

There's no topics in this repo and it could use some! I recommend at least:
orbitdb
orbit-db
eventstore

Use lodash instead of lazy.js

All of orbit-db's code is transitioning to use lodash as their only collection library. EventStore should also use lodash and remove the dependency on lazy.js

Ordering

Will everyone see the same order? as in, are these events ordered? I'm thinking about writing a custom store but it relies on knowing the order of events that occurred.

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.