encodedAsJsonValue
All checks were successful
Lint / lint (push) Successful in 12s

This commit is contained in:
Julien Valverdé
2024-08-20 05:14:42 +02:00
parent cfb3d20d44
commit 4b8a83bc46
2 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import type { Schema } from "@effect/schema"
import type { Jsonifiable } from "type-fest"
/**
* 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.
*/
export const encodedAsJsonValue = <A, R>(schema: Schema.Schema<A, Jsonifiable, R>) =>
schema as Schema.Schema<A, Jsonifiable, R>

View File

@@ -1,5 +1,6 @@
export * from "./Class" export * from "./Class"
export * from "./DateTime" export * from "./DateTime"
export * from "./encodedAsJsonValue"
export * from "./Jsonifiable" export * from "./Jsonifiable"
export * from "./Kind" export * from "./Kind"
export * as MobX from "./MobX" export * as MobX from "./MobX"