This commit is contained in:
12
src/Schema/encodedAsJsonValue.ts
Normal file
12
src/Schema/encodedAsJsonValue.ts
Normal 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>
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from "./Class"
|
||||
export * from "./DateTime"
|
||||
export * from "./encodedAsJsonValue"
|
||||
export * from "./Jsonifiable"
|
||||
export * from "./Kind"
|
||||
export * as MobX from "./MobX"
|
||||
|
||||
Reference in New Issue
Block a user