{"version":3,"file":"isValue.cjs","names":["LinkType","RichTextNodeType"],"sources":["../../src/lib/isValue.ts"],"sourcesContent":["import type { InjectMigrationSpecificTypes } from \"../types/migration/Document\"\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { GroupField } from \"../types/value/group\"\nimport type { ImageField } from \"../types/value/image\"\nimport { LinkType } from \"../types/value/link\"\nimport type { OptionalLinkProperties } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\nimport { type RTImageNode, RichTextNodeType } from \"../types/value/richText\"\nimport type { SliceZone } from \"../types/value/sliceZone\"\nimport type { AnyRegularField } from \"../types/value/types\"\n\n/**\n * Unknown value to check if it's a specific field type.\n *\n * @remarks\n *   Explicit types are added to help ensure narrowing is done effectively.\n */\ntype UnknownValue =\n\t| PrismicDocument\n\t| InjectMigrationSpecificTypes<AnyRegularField | GroupField | SliceZone>\n\t| unknown\n\n/**\n * Checks if a value is a link to media field.\n *\n * @param value - Value to check.\n * @returns `true` if `value` is a link to media field, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nexport const filledLinkToMedia = (value: UnknownValue): value is FilledLinkToMediaField => {\n\tif (value && typeof value === \"object\" && !(\"version\" in value)) {\n\t\tif (\n\t\t\t\"link_type\" in value &&\n\t\t\tvalue.link_type === LinkType.Media &&\n\t\t\t\"id\" in value &&\n\t\t\t\"name\" in value &&\n\t\t\t\"kind\" in value &&\n\t\t\t\"url\" in value &&\n\t\t\t\"size\" in value\n\t\t) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n\n/**\n * Checks if a value is like an image field.\n *\n * @param value - Value to check.\n * @returns `true` if `value` is like an image field, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nconst imageLike = (value: UnknownValue): value is ImageField<string, \"filled\"> | RTImageNode => {\n\tif (\n\t\tvalue &&\n\t\ttypeof value === \"object\" &&\n\t\t(!(\"version\" in value) || typeof value.version === \"object\")\n\t) {\n\t\tif (\n\t\t\t\"id\" in value &&\n\t\t\t\"url\" in value &&\n\t\t\ttypeof value.url === \"string\" &&\n\t\t\t\"dimensions\" in value &&\n\t\t\t\"edit\" in value &&\n\t\t\t\"alt\" in value &&\n\t\t\t\"copyright\" in value\n\t\t) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n\n/**\n * Checks if a value is an image field.\n *\n * @param value - Value to check.\n * @returns `true` if `value` is an image field, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nexport const filledImage = (value: UnknownValue): value is ImageField<string, \"filled\"> => {\n\tif (imageLike(value) && (!(\"type\" in value) || value.type !== RichTextNodeType.image)) {\n\t\treturn true\n\t}\n\n\treturn false\n}\n\n/**\n * Checks if a value is a rich text image node.\n *\n * @param value - Value to check.\n * @returns `true` if `value` is a rich text image node, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nexport const rtImageNode = (value: UnknownValue): value is RTImageNode => {\n\tif (imageLike(value) && \"type\" in value && value.type === RichTextNodeType.image) {\n\t\treturn true\n\t}\n\n\treturn false\n}\n\n/**\n * Checks if a value is a content relationship field.\n *\n * @remarks\n *   The return value includes `OptionalLinkProperties` because `FilledContentRelationshipField` may\n *   be a link field, not strictly a content relationship field.\n * @param value - Value to check.\n * @returns `true` if `value` is a content relationship, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nexport const filledContentRelationship = (\n\tvalue: UnknownValue,\n): value is FilledContentRelationshipField & OptionalLinkProperties => {\n\tif (value && typeof value === \"object\" && !(\"version\" in value)) {\n\t\tif (\n\t\t\t\"link_type\" in value &&\n\t\t\tvalue.link_type === LinkType.Document &&\n\t\t\t\"id\" in value &&\n\t\t\t\"type\" in value &&\n\t\t\t\"tags\" in value &&\n\t\t\t\"lang\" in value\n\t\t) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n\n/**\n * Checks if a value is a Prismic document.\n *\n * @param value - Value to check.\n * @returns `true` if `value` is a Prismic document, `false` otherwise.\n * @internal\n * This is not an official helper function and it's only designed to work with internal processes.\n */\nexport const prismicDocument = (value: UnknownValue): value is PrismicDocument => {\n\ttry {\n\t\treturn (\n\t\t\ttypeof value === \"object\" &&\n\t\t\tvalue !== null &&\n\t\t\t\"id\" in value &&\n\t\t\t\"href\" in value &&\n\t\t\ttypeof value.href === \"string\" &&\n\t\t\tnew URL(value.href) &&\n\t\t\t\"type\" in value &&\n\t\t\t\"lang\" in value &&\n\t\t\t\"tags\" in value &&\n\t\t\tArray.isArray(value.tags)\n\t\t)\n\t} catch {\n\t\treturn false\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAa,qBAAqB,UAAyD;AAC1F,KAAI,SAAS,OAAO,UAAU,YAAY,EAAE,aAAa;MAEvD,eAAe,SACf,MAAM,cAAcA,aAAAA,SAAS,SAC7B,QAAQ,SACR,UAAU,SACV,UAAU,SACV,SAAS,SACT,UAAU,MAEV,QAAO;;AAIT,QAAO;;;;;;;;;;AAWR,MAAM,aAAa,UAA6E;AAC/F,KACC,SACA,OAAO,UAAU,aAChB,EAAE,aAAa,UAAU,OAAO,MAAM,YAAY;MAGlD,QAAQ,SACR,SAAS,SACT,OAAO,MAAM,QAAQ,YACrB,gBAAgB,SAChB,UAAU,SACV,SAAS,SACT,eAAe,MAEf,QAAO;;AAIT,QAAO;;;;;;;;;;AAWR,MAAa,eAAe,UAA+D;AAC1F,KAAI,UAAU,MAAM,KAAK,EAAE,UAAU,UAAU,MAAM,SAASC,iBAAAA,iBAAiB,OAC9E,QAAO;AAGR,QAAO;;;;;;;;;;AAWR,MAAa,eAAe,UAA8C;AACzE,KAAI,UAAU,MAAM,IAAI,UAAU,SAAS,MAAM,SAASA,iBAAAA,iBAAiB,MAC1E,QAAO;AAGR,QAAO;;;;;;;;;;;;;AAcR,MAAa,6BACZ,UACsE;AACtE,KAAI,SAAS,OAAO,UAAU,YAAY,EAAE,aAAa;MAEvD,eAAe,SACf,MAAM,cAAcD,aAAAA,SAAS,YAC7B,QAAQ,SACR,UAAU,SACV,UAAU,SACV,UAAU,MAEV,QAAO;;AAIT,QAAO;;;;;;;;;;AAWR,MAAa,mBAAmB,UAAkD;AACjF,KAAI;AACH,SACC,OAAO,UAAU,YACjB,UAAU,QACV,QAAQ,SACR,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,IAAI,IAAI,MAAM,KAAK,IACnB,UAAU,SACV,UAAU,SACV,UAAU,SACV,MAAM,QAAQ,MAAM,KAAK;SAEnB;AACP,SAAO"}