Inline borsh, make is-my-json-valid optional#1894
Inline borsh, make is-my-json-valid optional#1894mikedotexe wants to merge 3 commits intonear:masterfrom
Conversation
Replace the borsh npm dependency with a lean 289-line zero-dep serializer/deserializer tailored to NEAR's schema needs. Move is-my-json-valid to optionalDependencies and dynamically import it with a try/catch fallback, so environments without it still work. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 1d0942f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This allows downstream consumers (e.g. near-connect) to import serialize, deserialize, and the Schema type directly from near-api-js instead of depending on the borsh package separately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
will address these failed CI tests 🫡 |
actually, looks like |
Respect to borsh.jsHow much does it impact removing borsh?
Respect to
|
Toward the goal described in #1876
I've tried to create a couple PRs for ease of review, and this is the first one. It's making some efficiency gains that will be used and leveraged in the two PRs following this. (those have linked to these with decent explanation)
This is the first one that's best to review and consider.
Sidenote, it's interesting that the npm package for borsh is so good it can be serialization for just about anything. What we found here was that it can be much smaller if it's just for the NEAR Protocol side, so that's the idea.
Summary
borshnpm dependency with a lean 289-line zero-dep serializer/deserializer tailored to NEAR's schema needs. Eliminates a transitive dependency tree.is-my-json-validtooptionalDependenciesand dynamically import it with try/catch fallback. Environments without it still work; ABI schema validation is skipped gracefully..claude/to.gitignoreChanges
src/borsh.tssrc/transactions/schema.tsimport from 'borsh'→import from '../borsh.js'src/nep413/schema.tsimport from 'borsh'→import from '../borsh.js'test/unit/signers/key_pair_signer.test.tsimport from 'borsh'→import from '../../../src/borsh.js'test/unit/transactions/serialize.test.tsimport from 'borsh'→import from '../../../src/borsh.js'src/accounts/errors.tsValidationErrortype (was imported from is-my-json-valid)src/accounts/typed_contract.tsimport('is-my-json-valid')with try/catch;validateArguments→ asyncpackage.jsonborshfrom deps; moveis-my-json-validtooptionalDependenciesTest plan
pnpm compile(tsc) — no errorspnpm test— all 27 test files, 346 tests pass🤖 Generated with Claude Code