import { UIDLegacySchema } from "../legacy/uid" import type { UIDLegacy } from "../legacy/uid" import { UIDContentSchema, UIDContentType } from "../uid" import type { UIDContent } from "../uid" import type { LegacyContentCtx, LegacyCodec } from "./legacyContentCtx" export const UIDLegacyCodec = (ctx: LegacyContentCtx): LegacyCodec => ({ name: "UIDLegacy", is(input): input is UIDContent { return UIDContentSchema.safeParse(input).success }, toContent(input) { const parsed = UIDLegacySchema.safeParse(input) if (!parsed.success) { return parsed } return { success: true, data: { __TYPE__: UIDContentType, value: parsed.data, }, } }, fromContent(input) { return { content: input.value, types: { [ctx.keyOfType]: "UID" }, keys: {}, } }, })