diff --git a/.evergreen/config.yml b/.evergreen/config.yml index d17941be..605e8404 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -131,8 +131,10 @@ tasks: - func: fetch source vars: NODE_LTS_VERSION: 16 + NPM_VERSION: 9 - func: install dependencies vars: + NODE_LTS_VERSION: 16 NPM_VERSION: 9 - func: run tests vars: @@ -143,6 +145,7 @@ tasks: - func: fetch source vars: NODE_LTS_VERSION: 18 + NPM_VERSION: 10 - func: install dependencies - func: run tests vars: @@ -246,6 +249,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 9 - func: install dependencies vars: NPM_VERSION: 9 @@ -262,6 +266,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 9 - func: install dependencies vars: NPM_VERSION: 9 @@ -275,6 +280,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 9 - func: install dependencies vars: NPM_VERSION: 9 diff --git a/.evergreen/prepare-shell.sh b/.evergreen/prepare-shell.sh index 094becbf..ab6970d5 100644 --- a/.evergreen/prepare-shell.sh +++ b/.evergreen/prepare-shell.sh @@ -33,12 +33,14 @@ cat < expansion.yml CURRENT_VERSION: "$CURRENT_VERSION" PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" NODE_LTS_VERSION: "$NODE_LTS_VERSION" +NPM_VERSION: "$NPM_VERSION" DRIVERS_TOOLS: "$DRIVERS_TOOLS" PREPARE_SHELL: | set -o errexit set -o xtrace export PROJECT_DIRECTORY="$PROJECT_DIRECTORY" export NODE_LTS_VERSION="$NODE_LTS_VERSION" + export NPM_VERSION="$NPM_VERSION" export DRIVERS_TOOLS="$DRIVERS_TOOLS" EOT # See what we've done diff --git a/src/parser/calculate_size.ts b/src/parser/calculate_size.ts index 923beeb0..557d15a8 100644 --- a/src/parser/calculate_size.ts +++ b/src/parser/calculate_size.ts @@ -1,6 +1,6 @@ import { Binary } from '../binary'; import type { Document } from '../bson'; -import { BSONVersionError } from '../error'; +import { BSONError, BSONVersionError } from '../error'; import * as constants from '../constants'; import { ByteUtils } from '../utils/byte_utils'; import { isAnyArrayBuffer, isDate, isRegExp } from './utils'; @@ -205,6 +205,13 @@ function calculateElement( 1 ); } + return 0; + case 'bigint': + return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1); + case 'symbol': + return 0; + default: + throw new BSONError(`Unrecognized JS type: ${typeof value}`); } return 0; diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 3ebccd16..62c7852b 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -24,4 +24,26 @@ describe('calculateSize()', () => { }) ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); + + describe('when given a bigint value with a single character key', function () { + beforeEach(function () { + if (BSON.__noBigInt__) { + this.currentTest?.skip(); + } + }); + + it('returns 8 bytes (+4 bytes for document size + 1 type byte + 1 byte for "a" + 2 null terminators)', function () { + const doc = { a: BigInt(1) }; + expect(BSON.calculateObjectSize(doc)).to.equal(8 + 4 + 1 + 1 + 1 + 1); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); + }); + + describe('when given a symbol value with a single character key', function () { + it('returns 0 bytes (+4 bytes for document size + 1 null terminator)', function () { + const doc = { a: Symbol() }; + expect(BSON.calculateObjectSize(doc)).to.equal(4 + 1); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); + }); });