UNPKG

@prismicio/types-internal

Version:
46 lines (37 loc) 983 B
import { either } from "fp-ts" import { pipe } from "fp-ts/lib/function" import * as t from "io-ts" import type { FieldOrSliceType } from "../LegacyContentCtx" import { hasContentType } from "../utils" export const EmptyContentType = "EmptyContent" export const isEmptyContent = (u: unknown): u is EmptyContent => hasContentType(u) && u.__TYPE__ === EmptyContentType const legacyReader = t.union([ t.null, t.type({ value: t.null, }), ]) type EmptyLegacy = t.TypeOf<typeof legacyReader> export const EmptyLegacy = (type: FieldOrSliceType) => new t.Type<EmptyContent, unknown, unknown>( "EmptyLegacy", isEmptyContent, (content) => { return pipe( legacyReader.decode(content), either.map(() => { return { type, __TYPE__: EmptyContentType, } }), ) }, () => null, ) export const EmptyContent = t.strict({ type: t.string, __TYPE__: t.literal(EmptyContentType), }) export type EmptyContent = t.TypeOf<typeof EmptyContent>