Finished schema refactoring
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export type JsonifiedBigIntBrand = "@thilawyn/zod-schema-class/JsonifiedBigInt"
|
||||
type JsonifiedBigIntBrand = "@thilawyn/zod-schema-class/JsonifiedBigInt"
|
||||
|
||||
|
||||
export function jsonifyBigIntSchema<S extends z.ZodType<bigint>>(schema: S) {
|
||||
export function jsonify<S extends z.ZodType<bigint>>(schema: S) {
|
||||
return schema
|
||||
.transform(v => v.toString())
|
||||
.brand<JsonifiedBigIntBrand>()
|
||||
}
|
||||
|
||||
export function dejsonifyBigIntSchema<S extends z.ZodType<bigint>>(schema: S) {
|
||||
export function dejsonify<S extends z.ZodType<bigint>>(schema: S) {
|
||||
return z
|
||||
.custom<string & z.BRAND<JsonifiedBigIntBrand>>()
|
||||
.pipe(z.string())
|
||||
@@ -1,16 +1,16 @@
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export type JsonifiedDateBrand = "@thilawyn/zod-schema-class/JsonifiedDate"
|
||||
type JsonifiedDateBrand = "@thilawyn/zod-schema-class/JsonifiedDate"
|
||||
|
||||
|
||||
export function jsonifyDateSchema<S extends z.ZodType<Date>>(schema: S) {
|
||||
export function jsonify<S extends z.ZodType<Date>>(schema: S) {
|
||||
return schema
|
||||
.transform(v => v.toString())
|
||||
.brand<JsonifiedDateBrand>()
|
||||
}
|
||||
|
||||
export function dejsonifyDateSchema<S extends z.ZodType<Date>>(schema: S) {
|
||||
export function dejsonify<S extends z.ZodType<Date>>(schema: S) {
|
||||
return z
|
||||
.custom<string & z.BRAND<JsonifiedDateBrand>>()
|
||||
.pipe(z.string())
|
||||
@@ -1,13 +0,0 @@
|
||||
import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./bigint"
|
||||
import { dejsonifyDateSchema, jsonifyDateSchema } from "./date"
|
||||
|
||||
|
||||
export const jsonify = {
|
||||
bigint: jsonifyBigIntSchema,
|
||||
date: jsonifyDateSchema,
|
||||
} as const
|
||||
|
||||
export const dejsonify = {
|
||||
bigint: dejsonifyBigIntSchema,
|
||||
date: dejsonifyDateSchema,
|
||||
} as const
|
||||
@@ -1,11 +1,12 @@
|
||||
import * as bigint from "./bigint"
|
||||
import * as date from "./date"
|
||||
import { decimal } from "./decimal"
|
||||
import * as effect from "./effect"
|
||||
import { dejsonify, jsonify } from "./jsonified"
|
||||
|
||||
|
||||
export const s = {
|
||||
bigint,
|
||||
date,
|
||||
decimal,
|
||||
effect,
|
||||
jsonify,
|
||||
dejsonify,
|
||||
} as const
|
||||
|
||||
@@ -31,11 +31,11 @@ const userInstEffect = User.createEffect({ id: Option.some(1n), name: "User" })
|
||||
|
||||
const jsonifiedUserExp = JsonifiedZodSchemaClass(User, {
|
||||
jsonifySchema: schema => schema.extend({
|
||||
id: s.effect.option.jsonify(schema.shape.id, s.jsonify.bigint)
|
||||
id: s.effect.option.jsonify(schema.shape.id, s.bigint.jsonify)
|
||||
}),
|
||||
|
||||
dejsonifySchema: schema => schema.extend({
|
||||
id: s.effect.option.dejsonify(schema.shape.id, s.dejsonify.bigint)
|
||||
id: s.effect.option.dejsonify(schema.shape.id, s.bigint.dejsonify)
|
||||
}),
|
||||
}).build()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user