UNPKG

@prismicio/types-internal

Version:
36 lines (35 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BooleanContentDefaultValue = exports.BooleanContent = exports.BooleanLegacy = exports.isBooleanContent = exports.BooleanContentType = 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.BooleanContentType = "BooleanContent"; const isBooleanContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.BooleanContentType; exports.isBooleanContent = isBooleanContent; const BooleanLegacy = (ctx) => new t.Type("BooleanLegacy", exports.isBooleanContent, (u) => { return (0, function_1.pipe)(t.boolean.decode(u), fp_ts_1.either.map((b) => exports.BooleanContent.encode({ value: b, __TYPE__: exports.BooleanContentType }))); }, (b) => { return { content: b.value, types: { [ctx.keyOfType]: "Boolean" }, keys: {}, }; }); exports.BooleanLegacy = BooleanLegacy; exports.BooleanContent = t.strict({ __TYPE__: t.literal(exports.BooleanContentType), value: t.boolean, }); const BooleanContentDefaultValue = (field) => { var _a; return ((_a = field.config) === null || _a === void 0 ? void 0 : _a.default_value) !== undefined ? { __TYPE__: exports.BooleanContentType, value: field.config.default_value || false, } : undefined; }; exports.BooleanContentDefaultValue = BooleanContentDefaultValue;