Repository navigation
fix: preserve numeric BSON types in Document View - #1148
Open
Alok Pandey (alok-108) wants to merge 1 commit into
Open
Alok Pandey (alok-108) wants to merge 1 commit into
Alok Pandey (alok-108) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1145
Problem
Document View previously read documents using the driver's default
promoteValues/promoteLongsbehavior and serialized/parsed them with relaxed Extended JSON (EJSON.stringify/EJSON.parse). As a result:Longvalues (including values > 2^53) and integralDoublevalues were written as plain JSON numbers, losing their BSON types (turning intoInt32orDoubleon save) and rounding 64-bit integers above 2^53.EJSON.parse(defaultrelaxed: true) also relaxed explicit$numberLongand integral$numberDoublewrappers back into plain numbers.Changes
src/documentdb/ClustersClient.ts: Pass{ promoteValues: false }tofindOneinpointReadandupsertDocumentso BSON numeric wrappers (Int32,Long,Double, etc.) are preserved when reading documents for Document View.src/webviews/documentdb/documentView/documentEjson.ts:stringifyDocumentForEditor: Keeps relaxed Extended JSON formatting for ordinaryInt32and non-integralDoublevalues so documents remain readable, while preserving explicit$numberLongwrappers forLongand$numberDoublewrappers for integralDoublevalues (including-0).parseDocumentFromEditor: Parses editor text withEJSON.parse(documentContent, { relaxed: false })so explicit$numberLong,$numberDouble, and$numberIntwrappers are preserved when saving.src/webviews/documentdb/documentView/documentsViewRouter.ts: UsestringifyDocumentForEditorandparseDocumentFromEditoringetDocumentByIdandsaveDocument.src/webviews/documentdb/documentView/documentEjson.test.ts: Added unit tests verifying BSON round-trip preservation forLong(small and > 2^53),Double(integral, large integral,-0, fractional,NaN/Infinity),Int32,Decimal128, andObjectId.Verification
npx vitest run src/webviews/documentdb/documentView/documentEjson.test.ts src/documentdb/ClustersClient.test.ts: 46 passed (2 + 44)npm run build: passednpx prettier -con the 4 changed files: passednpx eslinton the 4 changed files: 0 errors