Comparing version 1.0.0 to 1.0.1
@@ -29,3 +29,2 @@ 'use strict'; | ||
// Insert to the log right after the latest parent | ||
_insert(node) { | ||
@@ -60,6 +59,2 @@ let indices = Lazy(node.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next.hash)) // Find the item's parent's indices | ||
return new Promise((resolve, reject) => { | ||
// const current = _.differenceWith(this._currentBatch, this._items, Node.equals); | ||
// const others = _.differenceWith(other.items, this._items, Node.equals); | ||
// const final = _.unionWith(current, others, Node.equals); | ||
const current = Lazy(this._currentBatch).difference(this._items).toArray(); | ||
@@ -75,3 +70,3 @@ const others = _.differenceWith(other.items, this._items, Node.equals); | ||
Log.fetchHistory(this._ipfs, other.items, allHashes).then((history) => { | ||
history.forEach((f) => this._insert(f)) // Insert to the list | ||
history.forEach((f) => this._insert(f)) // Insert to the log | ||
resolve(final); | ||
@@ -89,4 +84,4 @@ }).catch(reject); | ||
static create(ipfs, id, items) { | ||
if(!ipfs) throw new Error("Log requires ipfs instance") | ||
if(!id) throw new Error("Log requires an id") | ||
if(!ipfs) throw new Error("Ipfs instance not defined") | ||
if(!id) throw new Error("id is not defined") | ||
return new Promise((resolve, reject) => { | ||
@@ -118,3 +113,3 @@ const list = new Log(ipfs, id, items); | ||
static fromIpfsHash(ipfs, hash) { | ||
if(!ipfs) throw new Error("Node requires ipfs instance") | ||
if(!ipfs) throw new Error("Ipfs instance not defined") | ||
if(!hash) throw new Error("Invalid hash: " + hash) | ||
@@ -121,0 +116,0 @@ return new Promise((resolve, reject) => { |
@@ -33,12 +33,8 @@ 'use strict'; | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const node = new Node(ipfs, data, next); | ||
Node.getIpfsHash(ipfs, node) | ||
.then((hash) => { | ||
node.hash = hash; | ||
resolve(node); | ||
}).catch(reject) | ||
} catch(e) { | ||
reject(e); | ||
} | ||
const node = new Node(ipfs, data, next); | ||
Node.getIpfsHash(ipfs, node) | ||
.then((hash) => { | ||
node.hash = hash; | ||
resolve(node); | ||
}).catch(reject) | ||
}); | ||
@@ -45,0 +41,0 @@ } |
{ | ||
"name": "ipfs-log", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Append-only log for IPFS", | ||
@@ -14,3 +14,4 @@ "main": "lib/log.js", | ||
"asyncawait": "^1.0.3", | ||
"ipfsd-ctl": "^0.8.3" | ||
"ipfsd-ctl": "^0.8.3", | ||
"mocha": "^2.4.5" | ||
}, | ||
@@ -17,0 +18,0 @@ "scripts": { |
@@ -5,5 +5,5 @@ # ipfs-log | ||
`ipfs-log` uses a linked list of [IPFS](https://github.com/ipfs/ipfs) hashes (Merkle Tree) where each entry in the log points to the previous entry. The items are ordered on join based on the parent nodes and time of reception. | ||
`ipfs-log` is a partially ordered linked list of [IPFS](https://github.com/ipfs/ipfs) hashes where each entry in the log points to all known heads (a head is a node that is not referenced by other nodes in the log). | ||
Use cases: | ||
### Use cases | ||
- Track a version of a file | ||
@@ -37,10 +37,9 @@ - Create a feed of IPFS hashes | ||
### Tests | ||
### API | ||
```javascript | ||
const Log = require('ipfs-log'); | ||
``` | ||
npm install | ||
npm test | ||
``` | ||
### API | ||
### Class methods | ||
All class methods take an `ipfs-api` instance as the first parameter. See https://github.com/ipfs/js-ipfs-api for documentation. | ||
@@ -56,7 +55,7 @@ | ||
```javascript | ||
const ipfs = require('ipfs-api')(); | ||
const Log = require('ipfs-log'); | ||
Log.create(ipfs, 'id').then((log) => console.log(log)); | ||
``` | ||
*See [Instance methods](https://github.com/haadcode/ipfs-log#instance-methods) on how to use the log instance* | ||
#### getIpfsHash(ipfs, log) | ||
@@ -129,2 +128,8 @@ Get the IPFS hash of this log. Returns a `Promise` that resolves to an IPFS `hash`. | ||
### Tests | ||
``` | ||
npm install | ||
npm test | ||
``` | ||
### TODO | ||
@@ -131,0 +136,0 @@ - Node.js Stream API |
@@ -49,3 +49,3 @@ 'use strict'; | ||
} catch(e) { | ||
assert.equal(e.message, 'Log requires ipfs instance'); | ||
assert.equal(e.message, 'Ipfs instance not defined'); | ||
} | ||
@@ -59,3 +59,3 @@ done(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Log requires an id'); | ||
assert.equal(e.message, 'id is not defined'); | ||
} | ||
@@ -197,3 +197,3 @@ done(); | ||
describe('add', () => { | ||
it('adds an item to an empty list', async((done) => { | ||
it('adds an item to an empty log', async((done) => { | ||
const log = await(Log.create(ipfs, 'A')); | ||
@@ -210,3 +210,3 @@ await(log.add("hello1")); | ||
it('adds 100 items to a list', async((done) => { | ||
it('adds 100 items to a log', async((done) => { | ||
const log = await(Log.create(ipfs, 'A')); | ||
@@ -227,3 +227,3 @@ const amount = 100; | ||
it('commits a list after batch size was reached', async((done) => { | ||
it('commits the log after batch size was reached', async((done) => { | ||
const log = await(Log.create(ipfs, 'A')); | ||
@@ -279,3 +279,3 @@ | ||
it('joins lists two ways', async((done) => { | ||
it('joins logs two ways', async((done) => { | ||
await(log1.add("helloA1")); | ||
@@ -300,3 +300,3 @@ await(log1.add("helloA2")); | ||
it('joins lists twice', async((done) => { | ||
it('joins logs twice', async((done) => { | ||
await(log1.add("helloA1")); | ||
@@ -319,3 +319,3 @@ await(log2.add("helloB1")); | ||
it('joins 4 lists to one', async((done) => { | ||
it('joins 4 logs to one', async((done) => { | ||
await(log1.add("helloA1")); | ||
@@ -343,3 +343,3 @@ await(log1.add("helloA2")); | ||
it('joins lists from 4 lists', async((done) => { | ||
it('joins logs from 4 logs', async((done) => { | ||
await(log1.add("helloA1")); | ||
@@ -627,3 +627,3 @@ await(log1.join(log2)); | ||
describe('clear', () => { | ||
it('clears the list', async((done) => { | ||
it('clears the log', async((done) => { | ||
const log1 = await(Log.create(ipfs, 'A')); | ||
@@ -630,0 +630,0 @@ await(log1.add("helloA1")); |
@@ -18,3 +18,3 @@ 'use strict'; | ||
describe('OrbitNode', function() { | ||
describe('Node', function() { | ||
this.timeout(15000); | ||
@@ -21,0 +21,0 @@ before(async((done) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135
47592
3
1150