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

fix: updates ipld-dag-pb dep to version without .cid or .multihash properties #388

Merged
merged 1 commit into from
Nov 12, 2018

Conversation

achingbrain
Copy link
Collaborator

Follows on from ipld/js-ipld-dag-pb#99 and updates this module to not rely on DAGNodes having knowledge of their CIDs.

@ghost ghost assigned achingbrain Nov 8, 2018
@ghost ghost added the in progress label Nov 8, 2018
@achingbrain achingbrain changed the title fix: updates ipld-dag-pb dep to version without .cid properties fix: updates ipld-dag-pb dep to version without .cid or .multihash properties Nov 9, 2018
@achingbrain achingbrain force-pushed the update-dag-pb-to-not-have-cid-property branch from 9b868e6 to 5c718a6 Compare November 12, 2018 10:36
@@ -6,6 +6,9 @@
"main": "js/src/index.js",
"scripts": {
"test": "exit 0",
"test:node": "exit 0",
"test:browser": "exit 0",
"test:webworker": "exit 0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM. Can we talk about the ramifications of this on the object API?

@achingbrain observed that by not having a cid/multihash property on a DAGNode the object API is significantly less useful for writes - you get basically get back the data you put in (which you aready have), but have no way to address it without calculating the CID yourself.

This means people using the object API will now need to depend on the ipld-dag-pb module and use the util.cid to calculate it.

@diasdavid I don't know how legacy we consider the object API to be - do you think this is this an acceptable breaking change since it's effectively a deprecated API anyway? I really don't want to stand in the way of these changes because of the perf gains they'll bring but this is a big breaking change with a difficult workaround.

As a suggestion, (still a breaking change) but why don't we change the write methods of the object API to return a CID? Then at least users can retrieve a DAGNode using object.get without having to require 'ipld-dag-pb' and calculate their own CID...

Presumably this would still allow reads to be fast (no recalc the CID for get) but would retain some usefulness in the object API.

@daviddias
Copy link
Contributor

I believe that (unfortunately) there are a considerable number of users using this API, perhaps due to a lack of "deprecation warning"

As a suggestion, (still a breaking change) but why don't we change the write methods of the object API to return a CID? Then at least users can retrieve a DAGNode using object.get without having to require 'ipld-dag-pb' and calculate their own CID...

It seems to me that this approach + a good deprecation plan is the way to go.

@achingbrain
Copy link
Collaborator Author

I believe that (unfortunately) there are a considerable number of users using this API, perhaps due to a lack of "deprecation warning"

Also because the DAG API isn't implemented over http so you can only use it in JS if you are calling directly into core.

@daviddias
Copy link
Contributor

Also because the DAG API isn't implemented over http so you can only use it in JS if you are calling directly into core.

There is a way to overcome this - ipfs-inactive/js-ipfs-http-client#755 (comment)

@alanshaw
Copy link
Contributor

It seems to me that this approach + a good deprecation plan is the way to go.

Sounds good?

@achingbrain
Copy link
Collaborator Author

Can we merge this one & I'll put a PR together for returning CIDs from the Object APIs?

@achingbrain
Copy link
Collaborator Author

..The reason is I'd like to use a pre-release IPFS on npm-on-ipfs in order to verify that this alleviates the CPU pressure.

@alanshaw alanshaw merged commit b8f7b9a into master Nov 12, 2018
@alanshaw alanshaw deleted the update-dag-pb-to-not-have-cid-property branch November 12, 2018 16:08
@ghost ghost removed the in progress label Nov 12, 2018
alanshaw added a commit that referenced this pull request Nov 26, 2018
Since `ipld-dag-pb` removed `multihash` and `cid` properties, the Object API became less useful, returning the data you provided it when you call methods that write DAG nodes. This meant the user had to calculate the CID manually.

This PR updates the Object API so that write methods return CID instances instead of DAG nodes.

See discussion here for more context: #388 (review)

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit that referenced this pull request Nov 27, 2018
Since `ipld-dag-pb` removed `multihash` and `cid` properties, the Object API became less useful, returning the data you provided it when you call methods that write DAG nodes. This meant the user had to calculate the CID manually.

This PR updates the Object API so that write methods return CID instances instead of DAG nodes.

See discussion here for more context: #388 (review)

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit that referenced this pull request Nov 27, 2018
Since `ipld-dag-pb` removed `multihash` and `cid` properties, the Object API became less useful, returning the data you provided it when you call methods that write DAG nodes. This meant the user had to calculate the CID manually.

This PR updates the Object API so that write methods return CID instances instead of DAG nodes.

See discussion here for more context: #388 (review)

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit to ipfs/js-ipfs that referenced this pull request Nov 27, 2018
For the back story on this change, please see: ipfs-inactive/interface-js-ipfs-core#388 (review)

BREAKING CHANGE: Object API refactor.

Object API methods that write DAG nodes now return a [CID](https://www.npmjs.com/package/cids) instead of a DAG node. Affected methods:

* `ipfs.object.new`
* `ipfs.object.patch.addLink`
* `ipfs.object.patch.appendData`
* `ipfs.object.patch.rmLink`
* `ipfs.object.patch.setData`
* `ipfs.object.put`

Example:

```js
// Before
const dagNode = await ipfs.object.new()
```

```js
// After
const cid = await ipfs.object.new() // now returns a CID
const dagNode = await ipfs.object.get(cid) // fetch the DAG node that was created
```

IMPORTANT: `DAGNode` instances, which are part of the IPLD dag-pb format have been refactored.

These instances no longer have `multihash`, `cid` or `serialized` properties.

This effects the following API methods that return these types of objects:

* `ipfs.object.get`
* `ipfs.dag.get`

See ipld/js-ipld-dag-pb#99 for more information.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit to ipfs/js-ipfs that referenced this pull request Nov 28, 2018
For the back story on this change, please see: ipfs-inactive/interface-js-ipfs-core#388 (review)

BREAKING CHANGE: Object API refactor.

Object API methods that write DAG nodes now return a [CID](https://www.npmjs.com/package/cids) instead of a DAG node. Affected methods:

* `ipfs.object.new`
* `ipfs.object.patch.addLink`
* `ipfs.object.patch.appendData`
* `ipfs.object.patch.rmLink`
* `ipfs.object.patch.setData`
* `ipfs.object.put`

Example:

```js
// Before
const dagNode = await ipfs.object.new()
```

```js
// After
const cid = await ipfs.object.new() // now returns a CID
const dagNode = await ipfs.object.get(cid) // fetch the DAG node that was created
```

IMPORTANT: `DAGNode` instances, which are part of the IPLD dag-pb format have been refactored.

These instances no longer have `multihash`, `cid` or `serialized` properties.

This effects the following API methods that return these types of objects:

* `ipfs.object.get`
* `ipfs.dag.get`

See ipld/js-ipld-dag-pb#99 for more information.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants