Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 9a37fb9

Browse files
committed
feat: dag-api (WIP)
1 parent fc3f216 commit 9a37fb9

File tree

2 files changed

+98
-9
lines changed

2 files changed

+98
-9
lines changed

API/dag/README.md

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
dag API
22
=======
33

4+
> The dag API comes to replace the `object API`, it support the creation and manipulation of dag-pb object, as well as other IPLD formats (i.e dag-cbor, ethereum-block, git, etc)
5+
46
#### `dag.put`
57

68
> Store an IPLD format node
@@ -9,13 +11,10 @@ dag API
911

1012
##### `JavaScript` - ipfs.dag.put(dagNode, formatMulticodec, hashAlg, callback)
1113

12-
`dagNode` - a DAG node that follows one of the supported IPLD formats.
13-
14-
`formatMulticodec` - The IPLD format multicodec.
15-
16-
`hashAlg` - The hash algorithm to be used over the serialized dagNode.
17-
18-
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
14+
- `dagNode` - a DAG node that follows one of the supported IPLD formats.
15+
- `formatMulticodec` - The IPLD format multicodec.
16+
- `hashAlg` - The hash algorithm to be used over the serialized dagNode.
17+
- `callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
1918

2019
If no `callback` is passed, a [promise][] is returned.
2120

@@ -25,10 +24,39 @@ If no `callback` is passed, a [promise][] is returned.
2524
2625
##### `Go` **WIP**
2726

28-
##### `JavaScript` - ipfs.object.get(cid, callback)
27+
##### `JavaScript` - ipfs.dag.get(cid, callback)
2928

30-
`cid` is a [CID][https://github.com./ipfs/js-cid] instance.
29+
- `cid` is a [CID][https://github.com./ipfs/js-cid] instance.
3130

3231
`callback` must follow `function (err, dagNode) {}` signature, where `err` is an error if the operation was not successful and `dagNode` is the IPLD format DAG node retrieved.
3332

3433
If no `callback` is passed, a [promise][] is returned.
34+
35+
#### `dag.resolve`
36+
37+
> Resolves an IPLD path
38+
39+
##### `Go` **WIP**
40+
41+
##### `JavaScript` - ipfs.dag.resolve(cid, path, callback)
42+
43+
- `cid` is a [CID][https://github.com./ipfs/js-cid] instance.
44+
- `path` is a String that represents a valid path to be resolved
45+
46+
`callback` must follow `function (err, value) {}` signature, where `err` is an error if the operation was not successful and `value` is the value it was retrieved.
47+
48+
If no `callback` is passed, a [promise][] is returned.
49+
50+
#### `dag.remove`
51+
52+
> Deletes an IPLD node
53+
54+
##### `Go` **WIP**
55+
56+
##### `JavaScript` - ipfs.dag.rm(cid, callback)
57+
58+
- `cid` is a [CID][https://github.com./ipfs/js-cid] instance.
59+
60+
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
61+
62+
If no `callback` is passed, a [promise][] is returned.

src/dag.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 8] */
3+
4+
'use strict'
5+
6+
const expect = require('chai').expect
7+
// const dagPB = require('ipld-dag-pb')
8+
// const dagCBOR = require('ipld-dag-pb')
9+
// const series = require('async/series')
10+
11+
module.exports = (common) => {
12+
describe('.dag', () => {
13+
let ipfs
14+
15+
before(function (done) {
16+
// CI is slow
17+
this.timeout(20 * 1000)
18+
19+
common.setup((err, factory) => {
20+
expect(err).to.not.exist
21+
factory.spawnNode((err, node) => {
22+
expect(err).to.not.exist
23+
ipfs = node
24+
done()
25+
})
26+
})
27+
})
28+
29+
after((done) => {
30+
common.teardown(done)
31+
})
32+
33+
describe('callback API', () => {
34+
describe('.put', () => {
35+
it.skip('dag-pb with default hash func (sha2-256)', (done) => {})
36+
it.skip('dag-pb with custom hash func (sha3-512)', (done) => {})
37+
it.skip('dag-pb node with wrong multicodec', (done) => {})
38+
39+
it.skip('dag-cbor with default hash func (sha2-256)', (done) => {})
40+
it.skip('dag-cbor with custom hash func (sha3-512)', (done) => {})
41+
it.skip('dag-cbor node with wrong multicodec', (done) => {})
42+
})
43+
44+
describe('.get', () => {
45+
before((done) => {})
46+
it.skip('dag-pb node', (done) => {})
47+
it.skip('dag-cbor node', (done) => {})
48+
})
49+
50+
describe('.resolve', () => {})
51+
describe('.rm', () => {})
52+
})
53+
54+
describe('promise API', () => {
55+
describe('.put', () => {})
56+
describe('.get', () => {})
57+
describe('.resolve', () => {})
58+
describe('.rm', () => {})
59+
})
60+
})
61+
}

0 commit comments

Comments
 (0)