This repository was 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: `DAGNode.clone()` is removed from public API without any replacement. Also the API for `rmLink()` and `addLink()` changed. They no longer return a new node, but just remove/add the links to/from the current node. Prior to this change: const lessLinks = DAGNode.rmLink(node1, 'Link1') node1 = lessLinks const moreLinks = await DAGNode.addLink(node2, link) node2 = moreLinks Now: DAGNode.rmLink(node, 'Link1') await DAGNode.addLink(node2, link)
- Loading branch information
Showing
7 changed files
with
67 additions
and
127 deletions.
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
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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
'use strict' | ||
|
||
const dagNodeUtil = require('./util') | ||
const cloneLinks = dagNodeUtil.cloneLinks | ||
const cloneData = dagNodeUtil.cloneData | ||
const create = require('./create') | ||
const CID = require('cids') | ||
|
||
const rmLink = (dagNode, nameOrCid) => { | ||
const data = cloneData(dagNode) | ||
let links = cloneLinks(dagNode) | ||
|
||
// It's a name | ||
if (typeof nameOrCid === 'string') { | ||
links = links.filter((link) => link.Name !== nameOrCid) | ||
dagNode._links = dagNode._links.filter((link) => link.Name !== nameOrCid) | ||
} else if (Buffer.isBuffer(nameOrCid) || CID.isCID(nameOrCid)) { | ||
links = links.filter((link) => !link.Hash.equals(nameOrCid)) | ||
dagNode._links = dagNode._links.filter( | ||
(link) => !link.Hash.equals(nameOrCid)) | ||
} else { | ||
throw new Error('second arg needs to be a name or CID') | ||
} | ||
|
||
return create(data, links) | ||
} | ||
|
||
module.exports = rmLink |
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