Skip to content

Add typed numeric wrappers and precise number mode to gremlin-javascript#3427

Open
kirill-stepanishin wants to merge 1 commit into
apache:masterfrom
kirill-stepanishin:js-precise-numbers
Open

Add typed numeric wrappers and precise number mode to gremlin-javascript#3427
kirill-stepanishin wants to merge 1 commit into
apache:masterfrom
kirill-stepanishin:js-precise-numbers

Conversation

@kirill-stepanishin
Copy link
Copy Markdown
Contributor

Summary

JavaScript's single Number type (IEEE 754 double) loses the distinction between JVM numeric types like int, float, long, and double. This PR gives gremlin-javascript users explicit control over numeric type fidelity on both sides of the wire.

Serialization — New wrapper classes and factory functions (toInt, toFloat, toDouble, toLong, toShort, toByte) control the exact GraphBinary type code and GremlinLang suffix sent to the server. Without wrappers, existing type-inference behavior is unchanged.

Deserialization — A new numberMode: 'precise' connection option wraps incoming numeric values in the same typed wrappers, preserving the server's original type information. Wrappers support transparent arithmetic via valueOf/Symbol.toPrimitive, and an unwrap() helper extracts raw values.

Implementation — Refactored GraphBinary.js IoC initialization into a createIoc() factory so precise mode can inject a postDeserialize hook via AnySerializer. Extended NumberSerializationStrategy and GremlinLang to route wrapper instances to the correct serializers/suffixes. Enhanced Long to accept bigint with full int64 range validation.

Tests

  • Unit: type-code routing, byte-level verification, round-trip serialize/deserialize for all six types, precise-mode coverage (nulls, nested structures, non-numeric passthrough), GremlinLang emission for all wrappers including edge cases (NaN, ±Infinity, boundary values, predicates, collections)
  • Integration: precise mode against a live server verifying Int/Double wrappers on vertex properties and edge weights
  • Export verification for all new public API symbols

Documentation

  • Reference docs: new "Numeric Types" section, updated connection options table and limitations
  • Upgrade guide: new "JavaScript Typed Numeric Wrappers" section
  • CHANGELOG entry

Assisted-by: Claude Code:claude-opus-4-6
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.32%. Comparing base (cfd6889) to head (9dd3304).
⚠️ Report is 1051 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3427      +/-   ##
============================================
- Coverage     77.87%   76.32%   -1.55%     
+ Complexity    13578    13439     -139     
============================================
  Files          1015     1013       -2     
  Lines         59308    60417    +1109     
  Branches       6835     7091     +256     
============================================
- Hits          46184    46113      -71     
- Misses        10817    11583     +766     
- Partials       2307     2721     +414     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

|options.traversalSource |String |The traversal source. |'g'
|options.headers |Object |Additional HTTP header key/values included with each request. |undefined
|options.interceptors |RequestInterceptor/RequestInterceptor[] |One or more functions that can modify the HTTP request before it is sent. |undefined
|options.numberMode |String |Set to `'precise'` to wrap deserialized numbers in typed wrappers that preserve the server's original type. |undefined
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.

How many modes are there? If it's only precise or not can we rename the option and make it a boolean?

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.

3 participants