Mobile friendly, lint correction, typescript error clear

This commit is contained in:
Marcelo
2026-01-16 22:39:16 +00:00
parent 0f88207f3f
commit c183dda383
58 changed files with 7199 additions and 2714 deletions

33
lib/prismaJson.ts Normal file
View File

@@ -0,0 +1,33 @@
import { Prisma } from "@prisma/client";
function isRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
export function toJsonValue(value: unknown): Prisma.InputJsonValue {
if (value === null || value === undefined) {
return Prisma.JsonNull as unknown as Prisma.InputJsonValue;
}
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
return value;
}
if (Array.isArray(value)) {
return value.map((item) => (item === undefined ? (Prisma.JsonNull as unknown as Prisma.InputJsonValue) : toJsonValue(item)));
}
if (isRecord(value)) {
const out: Record<string, Prisma.InputJsonValue> = {};
for (const [key, val] of Object.entries(value)) {
if (val === undefined) continue;
out[key] = toJsonValue(val);
}
return out;
}
return String(value);
}
export function toNullableJsonValue(
value: unknown
): Prisma.NullableJsonNullValueInput | Prisma.InputJsonValue {
if (value === null || value === undefined) return Prisma.DbNull;
return toJsonValue(value);
}