ipfs-observed-remove-level v2.3.3
IPFS Observed-Remove Set and Map
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
Objectipfs
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\ Iterable of initial values (optional, default[]
)options
Object (optional, default{}
)
ipfsSync
Publish an IPFS hash of an array containing all of the object's insertions and deletions.
Returns Array[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>
getIpfsHash
Stores and returns an IPFS hash of the current insertions and deletions
Returns Promise[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
getIpfsHashes
Stores and returns an IPFS hash of the current insertions and deletions
Returns Promise[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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\
Signed Map API
Table of Contents
constructor
Create an observed-remove CRDT.
Parameters
db
Objectipfs
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\ Iterable of initial values (optional, default[]
)options
Object (optional, default{}
)
ipfsSync
Publish an IPFS hash of an array containing all of the object's insertions and deletions.
Returns Array[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>
getIpfsHash
Stores and returns an IPFS hash of the current insertions and deletions
Returns Promise[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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\
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago