@prismicio/types-internal
Version:
Prismic types for Custom Types and Prismic Data
26 lines (25 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIDContent = exports.UIDLegacy = exports.isUIDContent = exports.UIDContentType = 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 utils_1 = require("../utils");
exports.UIDContentType = "UIDContent";
const isUIDContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.UIDContentType;
exports.isUIDContent = isUIDContent;
const UIDLegacy = (ctx) => new t.Type("UIDLegacy", exports.isUIDContent, (u) => {
return (0, function_1.pipe)(t.string.decode(u), fp_ts_1.either.map((uid) => exports.UIDContent.encode({ value: uid, __TYPE__: exports.UIDContentType })));
}, (uid) => {
return {
content: uid.value,
types: { [ctx.keyOfType]: "UID" },
keys: {},
};
});
exports.UIDLegacy = UIDLegacy;
exports.UIDContent = t.type({
__TYPE__: t.literal(exports.UIDContentType),
value: t.string,
});