zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

Decimal.js-light is not compatible with Prisma.Decimal

Open sarioglu opened this issue 1 year ago • 2 comments

Description and expected behavior I saw that @zenstackhq/runtime replaced decimal.js with its light version. This breaks the compatibility with Prisma. I use nextjs app router with prisma on server-side and zenstack with swr on client-side for things like modals, etc. For some scenarios I use a conversion like new Prisma.Decimal(someDecimalComingFromZenstack ?? aNumber). With 2.5.0 such conversions does not work because decimal.js checks if input to constructor is instanceof Decimal.

Environment (please complete the following information):

  • ZenStack version: [e.g., 2.5.0]
  • Prisma version: [e.g., 5.19.1]
  • Database type: [e.g. MySQL]

Additional context Add any other context about the problem here.

sarioglu avatar Sep 16 '24 15:09 sarioglu

Hi @sarioglu , I understand it's not ideal, but feel that over all it's worth the reduced bundle size. A workaround could be use the string constructor?

new Prisma.Decimal(someDecimalComingFromZenstack?.toString() ?? aNumber)

ymc9 avatar Nov 01 '24 22:11 ymc9

Hi 👋 Thank you for your response. I did that as an interim solution. But it won't prevent us from having the same issue in the future. I wonder if there's another way to make sure Decimal-light works with Decimal.

sarioglu avatar Nov 04 '24 13:11 sarioglu