Git Product home page Git Product logo

ipfs-observed-remove-level's Introduction

IPFS Observed-Remove Set and Map

CircleCI npm version codecov

Eventually-consistent, conflict-free replicated data types (CRDT) implemented using IPFS and LevelDB.

This module and the IPFS PubSub system are experimental. If you encounter an issue, fork the repository, write tests demonstrating the issue, and create a pull request.

const os = require('os');
const path = require('path');
const uuid = require('uuid');
const level = require('level');
const ipfsAPI = require('ipfs-http-client');
const { IpfsObservedRemoveMap } = require('ipfs-observed-remove-level');

const run = async () => {

  const location = path.join(os.tmpdir(), uuid.v4());
  const db = level(location, { valueEncoding: 'json' });
  // IPFS nodes with PubSub enabled
  const ipfs1 = ipfsAPI('/ip4/127.0.0.1/tcp/5001'); 
  const ipfs2 = ipfsAPI('/ip4/127.0.0.1/tcp/5002');

  const topic = "CRDT_MAP";

  const alice = new IpfsObservedRemoveMap(db, ipfs1, topic, [], { namespace:'alice' });
  const bob = new IpfsObservedRemoveMap(db, ipfs2, topic, [], { namespace:'bob' });

  alice.on('set', (key, value) => {
    console.log(key, value); // logs [a, 1], [b, 2]
  });

  await alice.set('a', 1);
  await bob.set('b', 2);

  // Later

  await alice.get('b'); // 2
  await bob.get('a'); // 1
}

Install

yarn add ipfs-observed-remove-level

Table of Contents

Map API

Table of Contents

constructor

Create an observed-remove CRDT.

Parameters

  • db Object

  • ipfs Object? Object implementing the core IPFS API, most likely a js-ipfs or ipfs-http-client object.

  • topic String? IPFS pubub topic to use in synchronizing the CRDT.

  • entries Iterable<V> Iterable of initial values (optional, default [])

  • options Object (optional, default {})

    • options.maxAge String Max age of insertion/deletion identifiers (optional, default 5000)
    • options.bufferPublishing String Interval by which to buffer 'publish' events (optional, default 20)
    • options.chunkPubSub boolean Chunk pubsub messages for values greater than 1 MB (optional, default false)

ipfsSync

Publish an IPFS hash of an array containing all of the object's insertions and deletions.

Returns Array<Array<any>>

getIpfsHash

Stores and returns an IPFS hash of the current insertions and deletions

Returns Promise<string>

getIpfsHashes

Stores and returns an IPFS hash of the current insertions and deletions

Returns Promise<string>

ipfsPeerCount

Current number of IPFS pubsub peers.

Returns number

shutdown

Gracefully shutdown

Returns void

IpfsObservedRemoveSet#readyPromise

Resolves when IPFS topic subscriptions are confirmed.

Type: Promise<void>

Signed Map API

Table of Contents

constructor

Create an observed-remove CRDT.

Parameters

  • db Object

  • ipfs Object? Object implementing the core IPFS API, most likely a js-ipfs or ipfs-http-client object.

  • topic String? IPFS pubub topic to use in synchronizing the CRDT.

  • entries Iterable<V> Iterable of initial values (optional, default [])

  • options Object (optional, default {})

    • options.maxAge String Max age of insertion/deletion identifiers (optional, default 5000)
    • options.bufferPublishing String Interval by which to buffer 'publish' events (optional, default 20)
    • options.chunkPubSub boolean Chunk pubsub messages for values greater than 1 MB (optional, default false)

ipfsSync

Publish an IPFS hash of an array containing all of the object's insertions and deletions.

Returns Array<Array<any>>

getIpfsHash

Stores and returns an IPFS hash of the current insertions and deletions

Returns Promise<string>

ipfsPeerCount

Current number of IPFS pubsub peers.

Returns number

shutdown

Gracefully shutdown

Returns void

IpfsObservedRemoveSet#readyPromise

Resolves when IPFS topic subscriptions are confirmed.

Type: Promise<void>

ipfs-observed-remove-level's People

Watchers

 avatar  avatar

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.