0.1.11 #12
@@ -1,13 +0,0 @@
|
||||
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 a cast.
|
||||
*/
|
||||
export const encodedAsJsonValue = <A, R>(schema: Schema.Schema<A, Jsonifiable, R>) =>
|
||||
schema as Schema.Schema<A, PrismaJson.JsonValue, R>
|
||||
13
src/Schema/encodedAsPrismaJsonValue.ts
Normal file
13
src/Schema/encodedAsPrismaJsonValue.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
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 `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, R>(schema: Schema.Schema<A, JsonValue, R>) =>
|
||||
schema as Schema.Schema<A, PrismaJson.JsonValue, R>
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from "./Class"
|
||||
export * from "./DateTime"
|
||||
export * from "./encodedAsJsonValue"
|
||||
export * from "./encodedAsPrismaJsonValue"
|
||||
export * from "./Jsonifiable"
|
||||
export * from "./Kind"
|
||||
export * from "./makeJsonifiable"
|
||||
|
||||
Reference in New Issue
Block a user