Files
thilalib/src/Schema/encodedAsPrismaJsonValue.ts
Julien Valverdé 95db23b2be
All checks were successful
Publish / publish (push) Successful in 15s
Lint / lint (push) Successful in 11s
0.1.11 (#12)
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #12
2024-08-20 22:17:43 +02:00

14 lines
711 B
TypeScript

import type { Schema } from "@effect/schema"
import type { JsonValue } from "type-fest"
import type { PrismaJson } from "../Types"
/**
* Takes a schema of which the encoded value satisfies type-fest's `JsonValue` and returns the same schema with Prisma's `JsonValue` as its encoded type instead.
* This allows you use to use jsonifiable schemas to strongly type `Json` database fields in Prisma.
*
* This is needed because Prisma's `JsonValue` is poorly implemented and does not work well with some types, such as readonly arrays.
*/
export const encodedAsPrismaJsonValue = <A, E extends JsonValue, R>(schema: Schema.Schema<A, E, R>) =>
schema as unknown as Schema.Schema<A, PrismaJson.JsonValue, R>