← 返回首页
BSON Int32 Increment Support by dlarocque · Pull Request #10132 · firebase/firebase-js-sdk · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

BSON Int32 Increment Support#10132

Open
dlarocque wants to merge 5 commits into
dl/bson-typesfrom
dl/bson-int32-increment-fix
Open

BSON Int32 Increment Support#10132
dlarocque wants to merge 5 commits into
dl/bson-typesfrom
dl/bson-int32-increment-fix

Conversation

dlarocque commented Jul 6, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Fixes local evaluation of numeric transforms (increment, min, max) when mixing BSON (Int32Value / Decimal128Value) and standard JS numbers.

Bug: BSON operands failed constructor checks ("transform requires a NumberValue"), and BSON base values were unrecognized by isNumber() (returning the operand directly).
Fix: Unpacked BSON values in asNumber(), updated isNumber() to support BSON maps, and implemented precision promotion.

Before:

Int32(10) + Int32(5) => Throws error Int32(10) + 5 (std) => 5 (returned operand directly) Int32(10) + 1.5 (std) => 1.5 (returned operand directly) 10 (std) + Int32(5) => Throws error Decimal128(10) + 5 (std) => 5 (returned operand directly) Decimal128(10) + Decimal128(5) => Throws error 10 (std) + Decimal128(5) => Throws error

After:

Int32(10) + Int32(5) => Int32(15) Int32(10) + 5 (std) => Int32(15) Int32(10) + 1.5 (std) => Decimal128(11.5) 10 (std) + Int32(5) => 15 (std) Decimal128(10) + 5 (std) => Decimal128(15) Decimal128(10) + Decimal128(5) => Decimal128(15) 10 (std) + Decimal128(5) => Decimal128(15)

Note: While the SDK doesn't support BSON types as arguments to increment(), the local evaluation layer still supports it, for the sake of robustness.

dlarocque requested review from a team as code owners July 6, 2026 20:12

changeset-bot Bot commented Jul 6, 2026
edited
Loading

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1d12eef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Code Review

This pull request adds support for local evaluation of numeric transforms on BSON Int32Value and Decimal128Value types. While the changes successfully introduce these types to the local evaluation pipeline, the review highlights critical issues with type promotion. Specifically, if the operand is an Int32Value, it is not correctly treated as an integer type, causing incorrect promotion to Decimal128Value. Additionally, the code should ensure proper Decimal128Value promotion if either operand is a Decimal128Value. Finally, replacing unsafe non-null assertions with optional chaining in asNumber is recommended to prevent potential runtime crashes.

Comment thread packages/firestore/src/model/transform_operation.ts Show resolved Hide resolved
Comment thread packages/firestore/src/model/transform_operation.ts Show resolved Hide resolved
Comment thread packages/firestore/src/model/transform_operation.ts Show resolved Hide resolved
dlarocque force-pushed the dl/bson-int32-increment-fix branch from 6287d97 to 5aa1e84 Compare July 7, 2026 15:18

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Code Review

This pull request introduces support for local evaluation of numeric transform and increment operations on BSON types, specifically Int32Value and Decimal128Value. It updates the transform operations to handle mixed-type math, type promotion, and representation using reserved map keys, and includes comprehensive unit tests to verify these behaviors. There are no review comments, so I have no feedback to provide.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Footer

© 2026 GitHub, Inc.