UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

77 lines (75 loc) 3.18 kB
const require_richText = require('../types/value/richText.cjs'); const require_link = require('../types/value/link.cjs'); const require_Asset = require('../types/migration/Asset.cjs'); const require_Document = require('../types/migration/Document.cjs'); const require_isValue = require('./isValue.cjs'); //#region src/lib/isMigrationValue.ts /** * Checks if a value is a migration content relationship field. * * @remarks * `OptionalLinkProperties` is included because `MigrationContentRelationship` * may be a link field, not strictly a content relationship field. * * @param value - Value to check. * * @returns `true` if `value` is a migration content relationship field, `false` * otherwise. * * @internal * This is not an official helper function and it's only designed to work with internal processes. */ const contentRelationship = (value) => { return value instanceof require_Document.PrismicMigrationDocument || require_isValue.prismicDocument(value) || typeof value === "object" && value !== null && "link_type" in value && value.link_type === require_link.LinkType.Document && "id" in value && (contentRelationship(value.id) || typeof value.id === "function"); }; /** * Checks if a value is a migration image field. * * @param value - Value to check. * * @returns `true` if `value` is a migration image field, `false` otherwise. * * @internal * This is not an official helper function and it's only designed to work with internal processes. */ const image = (value) => { return value instanceof require_Asset.PrismicMigrationAsset || typeof value === "object" && value !== null && "id" in value && Object.values(value).every((maybeThumbnail) => maybeThumbnail instanceof require_Asset.PrismicMigrationAsset); }; /** * Checks if a value is a migration link to media field. * * - @remarks `OptionalLinkProperties` is included because * `MigrationContentRelationship` may be a link field, not strictly a content * relationship field. * * @param value - Value to check. * * @returns `true` if `value` is a migration link to media field, `false` * otherwise. * * @internal * This is not an official helper function and it's only designed to work with internal processes. */ const linkToMedia = (value) => { return typeof value === "object" && value !== null && "id" in value && value.id instanceof require_Asset.PrismicMigrationAsset && "link_type" in value && value.link_type === require_link.LinkType.Media; }; /** * Checks if a value is a migration rich text image node. * * @param value - Value to check. * * @returns `true` if `value` is a migration rich text image node, `false` * otherwise. * * @internal * This is not an official helper function and it's only designed to work with internal processes. */ const rtImageNode = (value) => { return typeof value === "object" && value !== null && "id" in value && value.id instanceof require_Asset.PrismicMigrationAsset && "type" in value && value.type === require_richText.RichTextNodeType.image; }; //#endregion exports.contentRelationship = contentRelationship; exports.image = image; exports.linkToMedia = linkToMedia; exports.rtImageNode = rtImageNode; //# sourceMappingURL=isMigrationValue.cjs.map