nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

Change default behavior of Int and Double decoding to not convert to native javascript Number

Open crwilcox opened this issue 3 years ago • 0 comments

Currently the entityFromEntityProto/decodeValueProto method, which is used to cast datastore entities into Javascript objects, converts DatastoreInt and DatastoreDouble to Number by default. While this was done to make the surface ergonomic for node programmers, there exists a case where a Double is indistinguishable from an int (3.0) in javascript. This results in a situation where a user changes a column type accidentally. Consider the following

Upload entity {description: 'a', rank: double("4.0")}
get entity
change description to 'b'
upload.
get.

The final get, due to auto unboxing, will be an int as on the retrieval 4.0 is seen to be the number 4, which is uploaded as an int.

I think we should support configuring wrapNumbers, but moving to default it to wrapping seems sensible.

Also, doubles should have the same option available.

related to #773

crwilcox avatar Dec 11 '20 01:12 crwilcox