import type { ObjectId } from "mongodb"; export type Serialize = T extends ObjectId | Date ? string : T extends Array ? Array> : T extends object ? { [K in keyof T]: Serialize } : T; export function jsonSerialize(data: T): Serialize { return JSON.parse(JSON.stringify(data)) as Serialize; }