This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Refactor feat/immutable PR #7
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b56d797
feat(refactor): new API proposal
haadcode ea904a7
feat: refactor, structure code, make DAGNode funcs inside the same fo…
daviddias 6a3531d
feat: add a same create pattern api for DAGLink
daviddias 301d0b0
fix: that linting
daviddias 6e3ab23
docs: revamp README documentation to the new API
daviddias eec00da
fix: DAGLink tests
daviddias 710e53f
feat+fix: complete addLink and rmLink functions + fix their tests and…
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const DAGLink = require('./index.js') | ||
|
||
function create (name, size, multihash, callback) { | ||
const link = new DAGLink(name, size, multihash) | ||
callback(null, link) | ||
} | ||
|
||
module.exports = create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
|
||
const mh = require('multihashes') | ||
const assert = require('assert') | ||
|
||
// Link represents an IPFS Merkle DAG Link between Nodes. | ||
class DAGLink { | ||
constructor (name, size, multihash) { | ||
assert(multihash, 'A link requires a multihash to point to') | ||
assert(size, 'A link requires a size') | ||
|
||
this._name = name | ||
this._size = size | ||
|
||
if (typeof multihash === 'string') { | ||
this._multihash = mh.fromB58String(multihash) | ||
} else if (Buffer.isBuffer(multihash)) { | ||
this._multihash = multihash | ||
} | ||
} | ||
|
||
toString () { | ||
const mhStr = mh.toB58String(this.multihash) | ||
return `DAGLink <${mhStr} - name: "${this.name}", size: ${this.size}>` | ||
} | ||
|
||
toJSON () { | ||
return { | ||
name: this.name, | ||
size: this.size, | ||
hash: this.multihash ? mh.toB58String(this.multihash) : undefined | ||
} | ||
} | ||
|
||
get name () { | ||
return this._name | ||
} | ||
|
||
set name (name) { | ||
throw new Error("Can't set property: 'name' is immutable") | ||
} | ||
|
||
get size () { | ||
return this._size | ||
} | ||
|
||
set size (size) { | ||
throw new Error("Can't set property: 'size' is immutable") | ||
} | ||
|
||
get multihash () { | ||
return this._multihash | ||
} | ||
|
||
set multihash (multihash) { | ||
throw new Error("Can't set property: 'multihash' is immutable") | ||
} | ||
} | ||
|
||
exports = module.exports = DAGLink | ||
exports.create = require('./create') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs to be updated