PrismaJson
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2024-08-20 05:22:19 +02:00
parent 4b8a83bc46
commit 21d1ede3c8
3 changed files with 55 additions and 2 deletions

View File

@@ -1,12 +1,13 @@
import type { Schema } from "@effect/schema"
import type { Jsonifiable } from "type-fest"
import type { PrismaJson } from "../Types"
/**
* Takes a schema of which the encoded value satisfies `Jsonifiable` 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 type-fest's `Jsonifiable` and `JsonValue` types do not satisfy Prisma's `JsonValue`, and as such we need to perform an unsafe cast.
* This is needed because type-fest's `Jsonifiable` and `JsonValue` types do not satisfy Prisma's `JsonValue`, and as such we need to perform a cast.
*/
export const encodedAsJsonValue = <A, R>(schema: Schema.Schema<A, Jsonifiable, R>) =>
schema as Schema.Schema<A, Jsonifiable, R>
schema as Schema.Schema<A, PrismaJson.JsonValue, R>