Skip to content

feat(js): add schema-based per-field nullable support for xlang#3100

Merged
chaokunyang merged 6 commits intoapache:mainfrom
theharsh999:js-schema-nullable-xlang
Jan 4, 2026
Merged

feat(js): add schema-based per-field nullable support for xlang#3100
chaokunyang merged 6 commits intoapache:mainfrom
theharsh999:js-schema-nullable-xlang

Conversation

@theharsh999
Copy link
Contributor

@theharsh999 theharsh999 commented Dec 30, 2025

Why?

JavaScript xlang schema-based struct serialization currently treats all fields as nullable and always writes a per-field null flag.
This introduces unnecessary overhead when a field is known to be non-nullable by schema design.

What does this PR do?

  • Adds schema-based per-field nullable support for JS xlang struct serialization.
  • Preserves backward compatibility by treating fields as nullable by default.
  • When nullable: false is explicitly specified:
    • Skips writing the per-field null flag.
    • Throws a clear runtime error if the field value is null or undefined (includes field name).
  • Extends StructTypeInfo field schema typing to allow nullable?: boolean.
  • Adds a minimal unit test verifying:
    • Non-nullable fields throw on null.
    • Fields without nullable keep existing behavior.

Related issues

#3007

Does this PR introduce any user-facing change?

Yes.
This PR introduces an opt-in schema-level configuration (nullable: false) for JS xlang serialization.
Existing schemas are unaffected unless nullable: false is explicitly set.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

This change is opt-in and only affects schema-based fields explicitly marked as nullable: false.
No performance regression is expected for existing schemas.

@theharsh999 theharsh999 changed the title JS xlang: add schema-based per-field nullable support (backward compatible) feat(js): add schema-based per-field nullable support for xlang Dec 30, 2025
@theharsh999
Copy link
Contributor Author

Hi @chaokunyang
All CI checks are green now.
Whenever you have time, I’d appreciate a quick review. Thanks!

@chaokunyang
Copy link
Collaborator

chaokunyang commented Jan 1, 2026

@theharsh999 Could you add some tests for this? you can take #3104 as reference

@theharsh999
Copy link
Contributor Author

Added schema-consistent nullable tests following #3104 as reference.
All checks are green now. Please take a look. Thanks!

Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

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

LGTM

@chaokunyang chaokunyang merged commit fb002e2 into apache:main Jan 4, 2026
53 checks passed
@theharsh999 theharsh999 deleted the js-schema-nullable-xlang branch January 5, 2026 07:27
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.

2 participants