import { Prisma } from "@prisma/client"; type func = (...args: any[]) => any | Function; export type replaceJsonUnparsableToString = T extends Array ? Array> : { [K in keyof T]: T[K] extends null ? null : T[K] extends func ? never : T[K] extends Prisma.Decimal ? `${number}` : T[K] extends Array ? Array> : T[K] extends object ? replaceJsonUnparsableToString : T[K] extends bigint ? `${bigint}` : T[K] }; type exactToInterface = (...args: any[]) => any extends Function ? true : false; function arrayPrismaToWeb(array: Array) { return array.reduce( (pV, cV) => { pV.push(prismaToWeb(cV)); return pV; }, [] as Array>, ); } export function prismaToWeb(ivalue: T): replaceJsonUnparsableToString { const rvalue: any = ivalue instanceof Array ? [] : {}; for (const i in ivalue) { const current = ivalue[i]; if (current === null) rvalue[i] = null; else if (typeof current === 'function') continue; else if (current instanceof Prisma.Decimal) rvalue[i] = current.toString(); else if (current instanceof Array) rvalue[i] = arrayPrismaToWeb(current); else if (typeof current === 'object') rvalue[i] = prismaToWeb(current); else if (typeof current === 'bigint') rvalue[i] = current.toString(); else rvalue[i] = current; } return rvalue; }