flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.14k stars 91 forks source link

issue with Next.js Decimal data type (data fetched from prisma/postgres) #152

Open krthush opened 3 years ago

krthush commented 3 years ago

tried to use superjson as a solution for this issue https://github.com/vercel/next.js/issues/11993, as suggested in https://github.com/blitz-js/superjson#using-with-nextjs

unfortunatly ran into issue with serialization of the Decimal data type as shown by the below error:

image

would be great if superjson supported this? or am I doing something wrong?

I'd rather not resort to have to using maps as shown in this fix https://github.com/prisma/prisma-examples/issues/3047 and our current fallback of JSON.parse(JSON.stringify(result) is somewhat inefficient I imagine

Skn0tt commented 3 years ago

Hi @krthush, thank you for reporting this! Decimals are indeed not supported at the moment, but should be relatively straight-forward to add by adding a new entry to this file: https://github.com/blitz-js/superjson/blob/main/src/transformer.ts

Would you be interested in contributing a PR for this? Would love your help on it :)

krthush commented 3 years ago

Hi @Skn0tt , sounds good - a bit tight with time at the moment (since this issue isn't our highest priority atm) but yeah this is something I'll likely look into - will try to contribute a PR when I can!