import { z } from "zod/mini" import { EmptyContentSchema, EmptyContentType } from "../empty" import type { EmptyContent } from "../empty" import { EmptyLegacySchema } from "../legacy/empty" import type { EmptyLegacy } from "../legacy/empty" import type { LegacyContentCtx, LegacyCodec } from "./legacyContentCtx" const UnsupportedEmptyLegacySchema = z.never() export const EmptyLegacyCodec = ( ctx: LegacyContentCtx, ): LegacyCodec => ({ name: "EmptyLegacy", is(input): input is EmptyContent { return EmptyContentSchema.safeParse(input).success }, toContent(input) { if (!ctx.fieldType) { return UnsupportedEmptyLegacySchema.safeParse( input, ) as z.core.util.SafeParseError } const parsed = EmptyLegacySchema.safeParse(input) if (!parsed.success) { return parsed } return { success: true, data: { __TYPE__: EmptyContentType, type: ctx.fieldType, }, } }, fromContent(input) { const type = ctx.fieldType ?? input.type return { content: null, types: { [ctx.keyOfType]: type }, keys: {}, } as ReturnType["fromContent"]> }, })