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
fix!: refactor bindgen and update node versions #581
Conversation
Other small fixes
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.
See some notes below. I think there's at least some minor cleanup & issues to address prior to merging. I also don't see any doc updates, and some changes aren't mentioned in the PR description (which seems like a good place to "stage" release notes, and we'll definitely want this stuff mentioned in the release notes with the next major version).
@@ -28,3 +28,4 @@ build/ | |||
sim-ffi/sim-ffi/target/ | |||
|
|||
sim-ffi/sim-ffi/index.node | |||
sim-ffi |
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.
nit: could remove the previous two file patterns here
// " is required but missing" | ||
// ); | ||
// return __defaultValue<T>(); | ||
// } |
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.
should we remove the comments before merge?
// } | ||
// if (isString<T>()) return ""; | ||
// return changetype<T>(0); | ||
// } |
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.
can rm comment?
@@ -35,6 +35,10 @@ | |||
"assembly/index.ts" | |||
], | |||
"devDependencies": { | |||
"near-sdk-core": "^3.2.1" | |||
"near-sdk-core": "^3.2.0" |
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.
reverting to an older version of sdk-core?
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.
"near-sdk-core": "^3.2.0" | |
"near-sdk-core": "^3.2.1" |
// builder.visit(sources); | ||
// return sources; | ||
// } | ||
// } |
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.
can rm comments (whole file)?
import { JSONBindingsBuilder, isEntry } from "./JSONBuilder"; | ||
import { TypeChecker } from "./typeChecker"; | ||
import { Transform, Parser, Program, Module, SourceKind } from "visitor-as/as"; | ||
// import { JSONBindingsBuilder } from "./JSONBuilder"; |
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.
can rm comment?
@@ -9,5 +9,8 @@ export * from "./logging"; | |||
export * from "./math"; | |||
export * from "./promise"; | |||
export * from "./datetime"; | |||
import * as JSON from "@serial-as/json"; | |||
export { JSON }; | |||
export * from "@serial-as/borsh"; |
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.
What are the implications of this change? I didn't see it mentioned in any updated docs or in the PR description (do we use the PR description to create release notes? might be useful)
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.
In the future branch this isn't needed because we have a serializer.ts
which exports a simplified serializer. So I think I'll add that to this PR. And add to PR description. I also think we should make a CHANGELOG.md to formalize this.
@@ -1,18 +1,22 @@ | |||
import { u128 } from ".."; | |||
|
|||
// TODO: findout why the commented lines below fail |
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.
I assume this TODO comment needs to be addressed prior to merge?
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.
Yeah good point. bignum didn't fail in any of the other tests so I saw this as a future work to understand this edge case.
This PR updates the bindings generation for contracts to use the new and improved serialization framework
serial-as
. The steps of the transform are now broken up into their steps. It also opens up the use of borsh serialization.Changes
Initialization check required
One big change that
serial-as
makes is to the semantics of class declarations. Assemblyscript like Typescript requires that fields that are not nullable (e.i.string | null
) to be initialized. Previously the bindgen code got around this requirement but calling adefaultValue<T>()
function which would get around this check and allow non-nullables to be set as zero.For example,
This original transform was there for backwards compatibility to previous versions of AS which didn't have the initialization check.
However, this led to encouraging bad and unsafe practices and thus now all fields are required to be initialized.
Node versions
This PR also removes compatibility to node versions
12
and13
. The former does not support optional chainingx?.foo()
, and the later is dropped by newer versions of jest.