Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Decimal data type #308

Closed

Conversation

Royal-lobster
Copy link

Fixes #152

Add support for serialization of Decimal data type.

  • src/transformer.ts

    • Import the Decimal class from the decimal.js library.
    • Add a transformation rule for the Decimal data type.
    • Update the compositeRules array to include the new Decimal transformation rule.
  • src/index.ts

    • Register a custom transformer for the Decimal data type in the SuperJSON class constructor.
  • src/index.test.ts

    • Update the test case for Decimal.js to use the built-in transformer.

Fixes flightcontrolhq#152

Add support for serialization of Decimal data type.

* **src/transformer.ts**
  - Import the Decimal class from the `decimal.js` library.
  - Add a transformation rule for the Decimal data type.
  - Update the `compositeRules` array to include the new Decimal transformation rule.

* **src/index.ts**
  - Register a custom transformer for the Decimal data type in the `SuperJSON` class constructor.

* **src/index.test.ts**
  - Update the test case for Decimal.js to use the built-in transformer.
@Royal-lobster Royal-lobster marked this pull request as draft December 30, 2024 05:04
@Royal-lobster Royal-lobster marked this pull request as ready for review December 30, 2024 05:05
@Skn0tt
Copy link
Collaborator

Skn0tt commented Dec 30, 2024

Hi there, thanks for your contribution! Adding a polyfill as a dependency to SuperJSON isn't the right route for this, it'll make all users of SuperJSON download it, even though very few use it. I'm open to adding support for this once https://github.com/tc39/proposal-decimal advances.

@Skn0tt Skn0tt closed this Dec 30, 2024
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.

issue with Next.js Decimal data type (data fetched from prisma/postgres)
2 participants