0.1.11 (#12)
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import { Schema } from "@effect/schema"
|
||||
import type { Jsonifiable as TJsonifiable } from "type-fest"
|
||||
|
||||
|
||||
export const Jsonifiable = <
|
||||
JsonifiableA,
|
||||
JsonifiableI extends TJsonifiable,
|
||||
JsonifiableR,
|
||||
>(
|
||||
jsonifiable: Schema.Schema<JsonifiableA, JsonifiableI, JsonifiableR>
|
||||
) =>
|
||||
<A, R>(schema: Schema.Schema<A, JsonifiableA, R>) =>
|
||||
jsonifiable.pipe(Schema.compose(schema))
|
||||
13
src/Schema/composeJsonifiable.ts
Normal file
13
src/Schema/composeJsonifiable.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Schema } from "@effect/schema"
|
||||
import type { JsonValue } from "type-fest"
|
||||
|
||||
|
||||
export const composeJsonifiable = <
|
||||
JsonifiableA,
|
||||
JsonifiableI extends JsonValue,
|
||||
JsonifiableR,
|
||||
>(
|
||||
jsonifiableSchema: Schema.Schema<JsonifiableA, JsonifiableI, JsonifiableR>
|
||||
) =>
|
||||
<A, R>(decodedSchema: Schema.Schema<A, JsonifiableA, R>) =>
|
||||
Schema.compose(jsonifiableSchema, decodedSchema)
|
||||
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'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>
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from "./Class"
|
||||
export * from "./composeJsonifiable"
|
||||
export * from "./DateTime"
|
||||
export * from "./Jsonifiable"
|
||||
export * from "./encodedAsPrismaJsonValue"
|
||||
export * from "./Kind"
|
||||
export * as MobX from "./MobX"
|
||||
export * from "./MutableClass"
|
||||
|
||||
Reference in New Issue
Block a user