-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Major Update of Borsh #65
Conversation
@gagdiez Could you also config this to build both commonjs and esm? Because near-sdk-js can only take esm modules. Here is a configuration that probably works: https://thesametech.com/how-to-build-typescript-project/ |
@ailisp build now compiles both |
Hi @gagdiez Thanks for your update. For esm I'd suggest to add an minimal test to ensure the packaging works. Because we're testing esm (and maybe also cjs and ts) packaging, not the functionality correctness, which you already covered in unit test. This minimal test may look like this: have a dir and a package.json that declares as an ESM module and depends on packaged borsh-js. Test it can correctly import the API. |
@ailisp I fixed the errors that did not allow to import it as a
|
Thanks @gagdiez ! We'll test again in near-sdk-js side |
Hi @gagdiez ! We tested your latest commit in near-sdk-js, now it can import borsh, but cannot import bn. I guess it will also not able to import bs58 but it only gives one error message at a time: fospring/near-sdk-js#1 (comment) I think why it works in your test (run with nodejs) is because nodejs support both commonjs and esm, so an esm dependency (borsh) depends on a commonjs (bn) is still working. However, near-sdk-js's setup only support pure esm modules: means all dependency and the dependency of dependency has to be esm. I look at your code, I think we're not using some advanced feature of bn, so replacing it with native JS int could be fine? |
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.
Hi @gagdiez! Thank you so much for this great job! Besides the other benefits you mentioned, We're able to run borsh in near-sdk-js and I think the new API is much cleaner, easier to use than 0.7. There is some minor things to address, and then ready to merge & release!
This is a complete rewrite of the library which includes multiple advantages over the current
v0.7.0
:Buffer
, for which it is compatible with a greater number of environments.objects
and instances ofClasses
. Previously we were only able to (de)serialize specific instances of classes.Schema
is consistent across types, and a thoughtful validation of the Schema is in place.serialize/deserialize
relies on a singleSchema
, solving some longstanding problems with the previous "Indexing by Class" approach.Since this is a full rewrite, I would recommend to directly look at the origin repository