UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

74 lines (72 loc) 2.97 kB
import { RichTextNodeType } from "../types/value/richText.js"; import { LinkType } from "../types/value/link.js"; import { PrismicMigrationAsset } from "../types/migration/Asset.js"; import { PrismicMigrationDocument } from "../types/migration/Document.js"; import { prismicDocument } from "./isValue.js"; //#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 PrismicMigrationDocument || prismicDocument(value) || typeof value === "object" && value !== null && "link_type" in value && value.link_type === 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 PrismicMigrationAsset || typeof value === "object" && value !== null && "id" in value && Object.values(value).every((maybeThumbnail) => maybeThumbnail instanceof 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 PrismicMigrationAsset && "link_type" in value && value.link_type === 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 PrismicMigrationAsset && "type" in value && value.type === RichTextNodeType.image; }; //#endregion export { contentRelationship, image, linkToMedia, rtImageNode }; //# sourceMappingURL=isMigrationValue.js.map