-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
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.
I'm not deep enough into this code base. Why did you do the switch from the Block API to raw { cid, data }
?
lib/util.js
Outdated
return typeof block === 'object' && isCID(block.cid) && isBuffer(block.binary) | ||
} | ||
|
||
function isCID (key) { |
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.
Shouldn't the isCID()
check from CID
just pass with old and new CIDs?
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.
no, I think it uses a symbol check still
So in this case, the latest iteration on my computer even drops the codec
check so it's basically checking for new CIDs only and old CIDs won't pass. So I should probably drop this function entirely and use multiformats.CID.isCID()
instead. In most places it's used it falls back to attempting a new multiformats.CID(thing.toString())
so that should be fine for converting old CIDs.
Trying to mix the two just doesn't work, it's like playing wac-a-mole with errors. I'm discovering that you need to be fully in either ecosystem for any of this to work. Code my my computer has dropped ipld-dag-cbor for the multiformats branch of @ipld/dag-cbor which seems to be working well but it's still using ipld-dag-pb and that gets very awkward as you should be able to see in fixture-data.js. If I was using more complex linking within those PB blocks then I'd be in real trouble but the simplicity of my graphs is saving me.
Things to either fix or document very well.
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.
no, I think it uses a symbol check still
Yes. @mikeal's plan was to use the same symbol for the new version. I also don't know if that's a good idea.
Good question with a potentially interesting answer. First: because I need this code to work now with my ipld-bitcoin code, and js-block hasn't had its makeover yet so I don't have an option to even use it and I don't want to rush Mikeal to get around to it. But also, looping back around to our discussions previously about needing a better blockstore interface for IPLD, this library (and zipcar too) stretches the I'd like to change this and bring
Something like that, simple but enough primitives to build useful things. I'm sure Mikeal's work on dagdb could inform some of this too. |
Thanks for the detailed answer. So the tl;dr is that it's easier like this for now, but in the future the Block API should be used. |
Tests all passing on Node.js and browser. Introduced a top-level factory: Needs docs but I think think this is otherwise done. |
docs done this will have to sit and wait though, it's got two dependencies pointing to github |
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.
Just one minor comment that does not block merging.
Latest commit adds a Pretty neat for interacting with large files and wanting to do arbitrary |
Updated to latest multiformats with the ESM+CJS exports but poledina now fails to run. I'm guessing this is because of the self-referencing used in multiformats now which isn't supported by Webpack. I don't know if it's possible to sort that out at the top-level though. The hack used in multiformats/js-multiformats#22 probably isn't going to work here ( |
Webpack shouldn’t even be finding the CJS exports since the version in polendina doesn’t look at export maps. That’s why we keep the exported names identical to the module’s file layout, so the old webpack algorithms find the correct files without parsing the export map. |
ESM is still a very sad land to live in. @mikeal the root cause is this: webpack/webpack#3929
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./node_modules/multiformats/index.js");
...
const multiformats = Object(_index_js__WEBPACK_IMPORTED_MODULE_0__["create"])()
multiformats.multihash.add(_hashes_sha2_js__WEBPACK_IMPORTED_MODULE_5__["default"])
...
__webpack_exports__["default"] = (multiformats);
/***/ }), And when I const multiformats = __webpack_require__(/*! multiformats/basics.js */ "./node_modules/multiformats/basics.js") But then I just get an object that has a single So your mapping works OK (ish) on Node, but in Webpack you get a different behaviour still. I now have to either:
Again, I think ESM is too new, this stuff is too immature and this is begging to take on more work than is necessary right now. ESM should still be considered broken until all of the tooling has a consistent story about how the pieces fit together. |
and I can't bypass this crazyness with |
I've removed browser support. We just have to make sure this doesn't leak into the browser version of js-ipfs if we add cmdline |
looks like webpack has slightly different behavior here than I thought. webpack merged support for package exports a few weeks ago, if you can update |
this is actually a rather contentious issue in i’m pretty sure rollup doesn’t do this because we’re using rollup to do the CJS compile and it’s doing what you’d expect instead of this weird webpack thing. |
if I do that then I have to deal with the missing node_libs support and everything that's bundled needs to have explicit |
This is very user-hostile and is not a good path to encouraging adoption. Maybe experimenting with ESM in a library that is optional and/or toward the edge of our stack would be a good idea, but this is imposing very large costs on anyone that wants to adopt our stuff. I'm not keen on saying that to potential users. There's also no good reason for this, at all. ESM provides us and our users with zero real benefits today. Yeah, there's some future utopia where we're serving all our files directly, but that future isn't soon and people are going to be bundling for a long time to come until the whole stack is solid and proven - from server to browser (I'd also like to place a bet on people still bundling for performance reasons even in the utopian parallel download http/2&3 world). |
d88bb07
to
c58509c
Compare
Massive changes in here now! Full ESM support, using the latest Also pulled in the changes in #8 to here. Good to merge and release I think, although very breaking so will be a 2.0.0. The next major change (later) I think might be to extract the pieces of this that aren't needed for interface-datastore and move to a simpler API that isn't trying to be like a datastore, and use the |
I added a verify-car.js executable in here, didn't add it to a |
Some more refactoring to clean up the I'm going to merge this but not release, I think I want to attempt to replace interface-datastore with something better, it's getting too frustrating. |
The
Uint8Array
thing in multiformats.CID is really getting in the way of compatibility unfortunately, this conversion has to be all-or-nothing.Currently not passing in the browser because it's still using ipld-dag-cbor which is having trouble covering CIDs to tags because of the
Buffer
/Uint8Array
thing. When @ipld/dag-cbor is done this might help.One interesting problem area is in constructing a CID from a parsed form. I'm using
Buffer
here for decoding and encoding and don't plan to switch from that because of the utility of it, but if I take aBuffer
slice and feed it tonew multiformats.CID()
I get an error, so I have to wrap it:new Uint8Array(slice)
. This might be something we can handle in multiformats/bytes.js#coerce automatically.