Skip to content

Add xsd:decimal support to vocab runtime and codegen#640

Merged
dahlia merged 5 commits intofedify-dev:mainfrom
dahlia:decimal
Mar 23, 2026
Merged

Add xsd:decimal support to vocab runtime and codegen#640
dahlia merged 5 commits intofedify-dev:mainfrom
dahlia:decimal

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Mar 22, 2026

This PR factors out the xsd:decimal support needed by #579 into a separate foundational change, as discussed in #617, so the broader FEP-0837 vocabulary work in #578 can use a semantically correct and precision-safe type. It provides the runtime and code generation support first, without changing @fedify/vocab to use xsd:decimal yet. See also FEP-0837.

Summary

  • Added Decimal as a public branded string type in @fedify/vocab-runtime.
  • Added isDecimal() and parseDecimal() for validating and parsing xsd:decimal lexical values.
  • Updated @fedify/vocab-tools so properties with the xsd:decimal range are generated as Decimal.
  • Updated generated runtime checks to use isDecimal() and decoders to use parseDecimal().
  • Updated docs/manual/vocab.md and CHANGES.md.

Why

The immediate motivation for this change came from the review of #579, where Measure.hasNumericalValue had to use xsd:string as a stopgap because the vocabulary type system did not support xsd:decimal yet. That workaround is safe in the sense that it avoids binary floating-point rounding problems, but it loses the semantic distinction between arbitrary strings and decimal literals and pushes validation onto downstream users.

Supporting xsd:decimal directly fixes that gap at the right layer. JavaScript number is not suitable here because xsd:decimal is expected to preserve decimal precision exactly, which matters for marketplace and monetary values in FEP-0837. A branded string representation keeps the exact lexical value intact at runtime, avoids adding a decimal arithmetic dependency, and still gives generated APIs a dedicated type instead of a plain string.

This also follows the direction discussed in #617: keep the runtime representation simple and dependency-free for now, but expose a clear Decimal type and parsing API so Fedify can grow into proper xsd:decimal support incrementally. That makes this PR a small, focused prerequisite for the vocabulary work in #578 and #579 rather than mixing type-system groundwork with the vocabulary addition itself.

Testing

  • Added tests first for decimal parsing and generated code behavior.
  • Ran pnpm --filter @fedify/vocab-runtime test.
  • Ran pnpm --filter @fedify/vocab-tools test.
  • Ran deno test in packages/vocab-runtime/.
  • Ran deno test -A in packages/vocab-tools/.

Add the branded Decimal runtime type with isDecimal() and
parseDecimal() so exact xsd:decimal values can be validated
without introducing a decimal arithmetic dependency.

Teach the vocabulary code generator to map xsd:decimal to
Decimal, use the shared runtime predicate in generated guards,
and decode typed literals through parseDecimal().

Update the vocabulary manual and changelog to document the new
runtime APIs and the xsd:decimal code generation support.

fedify-dev#617

Co-Authored-By: OpenAI Codex <codex@openai.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request lays foundational groundwork for handling xsd:decimal values with precision and semantic correctness across the Fedify ecosystem. By introducing a dedicated Decimal branded string type and integrating it into both the runtime and code generation tools, it ensures that applications can accurately represent and process decimal data, such as monetary values or measurements, without encountering floating-point inaccuracies. This change is a prerequisite for broader vocabulary enhancements, providing a robust and dependency-free solution for exact decimal representation.

Highlights

  • New Decimal Type for xsd:decimal: Introduced a Decimal branded string type in @fedify/vocab-runtime to represent xsd:decimal values, ensuring precision without relying on JavaScript's number type or external decimal arithmetic libraries. This type is validated using isDecimal() and parseDecimal() functions.
  • Code Generation Support for xsd:decimal: Updated @fedify/vocab-tools to correctly generate Decimal types for properties with an xsd:decimal range. The generated code now includes runtime checks using isDecimal() and decoding logic using parseDecimal().
  • Documentation and Changelog Updates: The CHANGES.md and docs/manual/vocab.md files have been updated to reflect the new Decimal type, its usage, and the rationale behind its implementation for precision-sensitive values.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@issues-auto-labeler issues-auto-labeler bot added breaking change Breaking change component/build Build system and packaging component/federation Federation object related labels Mar 22, 2026
@dahlia dahlia linked an issue Mar 22, 2026 that may be closed by this pull request
@dahlia dahlia added this to the Fedify 2.1 milestone Mar 22, 2026
@dahlia dahlia self-assigned this Mar 22, 2026
@dahlia
Copy link
Member Author

dahlia commented Mar 22, 2026

@codex review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for the xsd:decimal type, which is a crucial foundational change for handling precision-safe values like prices and measurements. The changes are well-structured, adding a new Decimal branded string type and validation helpers (isDecimal, parseDecimal) to @fedify/vocab-runtime, and updating the code generator in @fedify/vocab-tools to correctly handle this new type. The implementation is robust, with a correct regular expression for validation and comprehensive unit tests covering both valid and invalid lexical forms. The documentation in CHANGES.md and the manual has also been updated accordingly. The code quality is excellent, and I have no further suggestions for improvement.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce09b5522f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

dahlia and others added 2 commits March 23, 2026 01:47
Suppress no-unused-vars and verbatim-module-syntax in generated
vocabulary files so the unconditional Decimal helper imports do not
break linting before any schema actually uses xsd:decimal.

Keep the generated snapshots in sync with the updated file header.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Rewrite the throwing parseDecimal() JSDoc example so it catches
the expected TypeError instead of failing when doctests execute
the snippet directly.

Co-Authored-By: OpenAI Codex <codex@openai.com>
@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 96.51163% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/vocab-tools/src/type.ts 86.95% 3 Missing ⚠️
Files with missing lines Coverage Δ
packages/vocab-runtime/src/decimal.ts 100.00% <100.00%> (ø)
packages/vocab-runtime/src/mod.ts 100.00% <100.00%> (ø)
packages/vocab-tools/src/class.ts 97.82% <100.00%> (+0.56%) ⬆️
packages/vocab-tools/src/schema.ts 70.10% <100.00%> (+6.35%) ⬆️
packages/vocab-tools/src/type.ts 84.36% <86.95%> (+0.10%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add canParseDecimal() alongside the strict isDecimal() guard so
xsd:decimal parsing can follow XML Schema whitespace normalization
without weakening the Decimal type guard.

Update parseDecimal() to normalize XML Schema whitespace before
validation, adjust generated decimal data checks to use
canParseDecimal(), and refresh the related tests and documentation.

fedify-dev#640 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia
Copy link
Member Author

dahlia commented Mar 22, 2026

@codex review

@dahlia
Copy link
Member Author

dahlia commented Mar 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for xsd:decimal by adding a Decimal branded string type and associated helper functions (isDecimal, canParseDecimal, parseDecimal) to @fedify/vocab-runtime. The code generation in @fedify/vocab-tools is updated to use this new type for properties with an xsd:decimal range. The changes are well-implemented, with thorough JSDoc documentation and comprehensive unit tests. The documentation in docs/manual/vocab.md and the CHANGES.md file have also been updated accordingly. The implementation is solid and I have no specific feedback for improvement.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05d793d481

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Reject property ranges that mix xsd:string and xsd:decimal during
code generation, since both map to runtime strings and the generated
encoder cannot disambiguate them reliably.

Update the vocab-tools tests to cover the rejection path directly,
and document the restriction in the manual and changelog.

fedify-dev#640 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia
Copy link
Member Author

dahlia commented Mar 22, 2026

@codex review

@dahlia
Copy link
Member Author

dahlia commented Mar 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive support for the xsd:decimal type. A new Decimal branded string type and associated helper functions (isDecimal, canParseDecimal, parseDecimal) have been added to @fedify/vocab-runtime, complete with thorough unit tests. The code generation process in @fedify/vocab-tools has been updated to utilize this new type and to prevent schema ambiguities by disallowing properties that mix xsd:string and xsd:decimal. The changes are well-documented in both the changelog and the manual. The implementation is robust, well-tested, and aligns with the project's coding standards.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af8de5a4d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

@sij411 sij411 left a comment

Choose a reason for hiding this comment

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

I tested the following edge cases locally against this branch and all
passed:

  1. Precision preservation for very long decimals —
    parseDecimal("99999999999999999999.99999999999999999999") round-trips
    correctly through parseDecimal, isDecimal, and canParseDecimal
    without truncation or loss.
  2. Empty string rejection via canParseDecimal — canParseDecimal("")
    returns false.
  3. Empty string rejection via isDecimal — isDecimal("") returns
    false.

I didn't add the tests.

@dahlia dahlia merged commit 04d792b into fedify-dev:main Mar 23, 2026
16 checks passed
@dahlia dahlia deleted the decimal branch March 23, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Breaking change component/build Build system and packaging component/federation Federation object related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add xsd:decimal support to the vocabulary type system

2 participants