Closed andy-haynes closed 1 month ago
Latest commit: f027f1bdbbd21122a5922cccbc30d76139eae479
The changes in this PR will be included in the next version bump.
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
Pre-flight checklist
pnpm changeset
to create achangeset
JSON document appropriate for this change.Motivation
This PR contains several enhancements intended to modernize and simplify usage of the
@near-js
packages:@near-js
packages only,near-api-js
was too much of a headache)One of the more substantial changes required to target
es2022
was the removal of theAssignable
class and modification of theEnum
class, both used primarily in@near-js/transactions
for (de)serialization of actions. With public class fields, the behavior around setting class fields from the base constructor has changed and the dynamic setting logic inAssignable
is no longer valid. However, this provides a good opportunity to define class properties per action, which while redundant, provides more intuitive typing support. See relevant SO question.While
Assignable
could be removed*, I effectively ran into the opposite problem withEnum
. Serialization breaks if any of the following are violated:Enum
-derived classes must inherit fromEnum
, so we can't just deleteEnum
and implement same logic in the classesenum
field cannot be defined as a public field onEnum
nor set from within theEnum
constructor - the inheriting class must set it, so I've updated it to beabstract enum: string;
Enum
constructor must still take the properties and set them on itself, despite the class constructor explicitly setting them... this is what appeared to breakAssignable
-derived classes 😑I'd need to look into this further to understand what's exactly going on, but the current implementation works and is only a little less confusing than the existing one. *
Assignable
will remain for backward compatibility reasons, as outdated NAJ peer dependencies in Wallet Selector dependencies break otherwise.Test Plan
Due to the scope of these changes, a
next
(near-api-js@next) tag has been created in NPM referencing packages built from this branch. Long term thenext
tag will require a dedicated build step in order to remain current. Wallet Selector update looks good (React example works): https://github.com/near/wallet-selector/pull/1183The attempt at an
esbuild
bundle was missing some functionality and will require further debugging to get working (see branchfeat/dist-bundling
for original implementation). For now we will be deprecating as part of this major release in favor of using ES modules in browser.So going from supporting this:
To relying on modern (starting ~2017-18) browsers supporting modules:
This will reduce bundle size substantially for most use cases and is expected to be an easy lift for applications using the old format.
Related issues/PRs