`multicodec` v4.0.0: generate JavaScript exports from CSV
Revives the previously deprecated multicodec npm package as discussed here.
-
Include https://github.com/multiformats/multicodec as a Git submodule
-
npm run generate:json– usecsvtojsonto generate a JSON filemulticodecs.jsonfromtable.csv -
npm run generate:typescript– usequicktypeto generate inferred TypeScript types frommulticodecs.json -
Export multicodec data and TypeScript types from the
multicodecpackage- Default export /
multicodecs: JavaScript array ofMulticodecs -
multicodecsByName: JavaScript object indexed byname -
multicodecsByCode: JavaScript object indexed bycode(base 10)
- Default export /
-
Add workflow to automatically update submodule, re-generate, and publish
Thanks for PR @darrylyeo I am not sure if I am understanding this correctly, is this something that is not offered by https://github.com/multiformats/js-multiformats at the moment? Also, why not improve https://github.com/multiformats/js-multiformats as this package has been deprecated?
@whizzzkid as mentioned in description, this PR was triggered by https://github.com/multiformats/multicodec/issues/327#issuecomment-1583902359.
@vmx understood, however I still feel reviving this repo will create a fork in the initial thought process. Won't making this part of https://github.com/multiformats/js-multiformats/tree/master#implementations make this a lot more simpler and maintainable?
Which has been addressed by:
However, with the growth of the table, we've mostly been recommending people use separate packages just for the codecs (addrs, etc.) that they need, rather than consume the entire table since it can really bloat dependency trees and bundles. It's typically much better to just target what you need for an application
But if the team feels it's the right way, I'm not opposed to this!
@whizzzkid can you explain a bit more about why you think this might be a problem? My thought here is that there is a genuine use-case to having a JavaScript consumable form of the table. Just the table, no other frills. And it looks to me like that's what @darrylyeo has done here. Documentation here should be very clear that this is not a common use-case, that people should not reach for this unless they need access to the whole table, or large slabs of it.
I think we hit the right approach with js-multiformats, keeping it lean and minimal, but we do have a problem of codes being scattered and you have to trust the package that you're importing that it's doing the codes right; this isn't normally a problem, but there are cases where a stronger relationship to the multicodec table is very helpful. It's kind of like having applications deal with their own mime type—both publishing and consuming their narrow concern, but a /etc/mime.types sure is helpful sometimes when you have cross-cutting use cases.
Lastly, to anticipate a possible suggested approach - I don't support a version of this where the table goes in to js-multiformats. Bloat in that package is something I feel fairly strongly about, it's at the core of our JS stack and needs to stay light and lean, not just in someone's direct require/import path to make their bundles small, but also on-disk since it shows up in everyone's node_modules for every single JS package. js-multiformats has its genesis in bloated core packages, where the majority of people were burdened with code they never touched (both on disk and in bundles!). The table is not a majority concern, so it makes sense to shunt it off to the side I think.
Thanks for the insights @rvagg, there are multiple reasons why I feel this is not the right approach.
- Legacy, there are multiple articles/tutorials/historical examples that point to multicodec, which promises it does one thing, but after this it does not do those things. The burden transfers over to the developer to validate from the documentation on what this package does. The state of js package managers is always, weird, some random project that always like to update to latest might break because we changed this.
-
Overloading, As you said, this is not a common use-case if that's correct and this is seldom needed, then I'd prefer this to exist as a new package
multiformats-lookupormultiformats-table. Repurposing existing package for this may not be ideal, the deprecation notice will now have to exist inside the documentation and js package managers will not notify users about deprecation. -
Contradictory sources of truths,
you have to trust the package that you're importing that it's doing the codes rightwell if we can't trust the package to do the codes right, then can we even trust the package? If the devs need one package to validate another package, that will only create dissonance. Which package is in the right? If the dev needs to override something that's not done correctly in one package, I'd assume they'd do it themselves instead of equipping them with another source of truth that they now have to trust. There should only be a single source of truth.
Then again, personally I feel it should be ok as I know this change happened, but this might have a larger impact on the community which is not measurable at this point, and may set a bad precedent.
I'd also let @hacdias chime in to see what are their thoughts about this.
Yeah, I buy the argument re package naming and all the existing documentation that points to this package being a problem. Let's just do this under a different name then. I'll make a js-multicodec-table repo and we could publish it as @multiformats/multicodec-table, nice and verbose and unfriendly to the uninitiated.
@darrylyeo see https://github.com/multiformats/js-multicodec-table, I've added you as a maintainer so just open this PR (ideally without the js-multicodec history) over there and we'll get it rolling. Make the package name @multiformats/multicodec-table.
@darrylyeo: are you going to finish this off by renaming the package?