import { UID } from "@prismicio/types-internal/lib/customtypes" import { either } from "fp-ts" import { pipe } from "fp-ts/lib/function" import * as t from "io-ts" import { isFieldDef, WithKey } from "../utils" const codec = t.strict({ uid: t.string, }) export const UIDDef = new t.Type>( "UID", (u: unknown): u is WithKey => isFieldDef(u) && UID.is(u.def), (u: unknown) => { return pipe( codec.decode(u), either.map( ({ uid }): WithKey => ({ key: uid, def: { type: "UID", }, }), ), ) }, (n) => n, )