Skip to content

Inline borsh, make is-my-json-valid optional#1894

Open
mikedotexe wants to merge 3 commits intonear:masterfrom
mikedotexe:pr/inline-deps
Open

Inline borsh, make is-my-json-valid optional#1894
mikedotexe wants to merge 3 commits intonear:masterfrom
mikedotexe:pr/inline-deps

Conversation

@mikedotexe
Copy link
Copy Markdown
Contributor

@mikedotexe mikedotexe commented Mar 11, 2026

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

  • Inline borsh serializer — Replace the borsh npm dependency with a lean 289-line zero-dep serializer/deserializer tailored to NEAR's schema needs. Eliminates a transitive dependency tree.
  • Make is-my-json-valid optional — Move is-my-json-valid to optionalDependencies and dynamically import it with try/catch fallback. Environments without it still work; ABI schema validation is skipped gracefully.
  • Add .claude/ to .gitignore

Changes

File Change
src/borsh.ts New — 289-line zero-dep borsh serializer/deserializer
src/transactions/schema.ts import from 'borsh'import from '../borsh.js'
src/nep413/schema.ts import from 'borsh'import from '../borsh.js'
test/unit/signers/key_pair_signer.test.ts import from 'borsh'import from '../../../src/borsh.js'
test/unit/transactions/serialize.test.ts import from 'borsh'import from '../../../src/borsh.js'
src/accounts/errors.ts Inline ValidationError type (was imported from is-my-json-valid)
src/accounts/typed_contract.ts Dynamic import('is-my-json-valid') with try/catch; validateArguments → async
package.json Remove borsh from deps; move is-my-json-valid to optionalDependencies

Test plan

  • pnpm compile (tsc) — no errors
  • pnpm test — all 27 test files, 346 tests pass
  • Borsh round-trip coverage: serialize/deserialize for all NEAR transaction types

🤖 Generated with Claude Code

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-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: 1d0942f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
near-api-js Minor

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

Volya and others added 2 commits March 11, 2026 07:22
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>
@mikedotexe
Copy link
Copy Markdown
Contributor Author

will address these failed CI tests 🫡

@mikedotexe
Copy link
Copy Markdown
Contributor Author

will address these failed CI tests 🫡

actually, looks like master has CI issues. Thought i'd throw this one-liner PR up, but no worries if it's not the path the team would like to go on: #1897 my thought was just to exclude the e2e side or punt it until later so CI is working on current and incoming PRs

@gagdiez
Copy link
Copy Markdown
Contributor

gagdiez commented Mar 17, 2026

Respect to borsh.js

How much does it impact removing borsh?

borsh is already quite small, dependency-free, and thoroughly tested. By inlining it here we would lose not only the tests, but also create redundancy just to save a couple bytes. I would rather not inline it to be honest.

Respect to my-json-valid optional

We might want to consider how useful it actually is, if we can make it optional then maybe we can just delete it? Users that want to use it could simply validate the input by themselves. Because right now we are "silently skipping it", which to me sounds like unexpected behavior more than a feature. cc @denbite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: NEW❗

Development

Successfully merging this pull request may close these issues.

3 participants