UNPKG

@prismicio/types-internal

Version:
57 lines (56 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbedContent = exports.EmbedLegacy = exports.EmbedContentLegacy = exports.isEmbedContent = exports.EmbedContentType = void 0; const tslib_1 = require("tslib"); const fp_ts_1 = require("fp-ts"); const function_1 = require("fp-ts/lib/function"); const t = (0, tslib_1.__importStar)(require("io-ts")); const validators_1 = require("../../../validators"); const utils_1 = require("../../utils"); exports.EmbedContentType = "EmbedContent"; const isEmbedContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.EmbedContentType; exports.isEmbedContent = isEmbedContent; exports.EmbedContentLegacy = t.exact(t.intersection([ t.type({ embed_url: t.string, type: t.string, }), t.partial({ version: t.union([t.string, t.number, t.null]), title: validators_1.StringOrNull, author_name: validators_1.StringOrNull, author_url: validators_1.StringOrNull, provider_name: validators_1.StringOrNull, provider_url: validators_1.StringOrNull, cache_age: t.union([t.string, t.number, t.null]), thumbnail_url: validators_1.StringOrNull, thumbnail_width: validators_1.NumberOrNull, thumbnail_height: validators_1.NumberOrNull, html: validators_1.StringOrNull, }), ])); const EmbedLegacy = (ctx) => new t.Type("EmbedLegacy", exports.isEmbedContent, (u) => { return (0, function_1.pipe)(exports.EmbedContentLegacy.decode(u), fp_ts_1.either.map((embed) => ({ ...embed, all: u, __TYPE__: exports.EmbedContentType, }))); }, (embed) => { return { /** * we cast here because actually in the all property * we can have extra keys that are never parsed and we don't want to loose them. **/ content: embed.all, types: { [ctx.keyOfType]: "Embed" }, keys: {}, }; }); exports.EmbedLegacy = EmbedLegacy; exports.EmbedContent = t.intersection([ exports.EmbedContentLegacy, t.strict({ __TYPE__: t.literal(exports.EmbedContentType), all: t.unknown, }), ]);