@prismicio/client 7.14.0-alpha.1 → 7.14.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/Migration.cjs +9 -6
  2. package/dist/Migration.cjs.map +1 -1
  3. package/dist/Migration.js +9 -6
  4. package/dist/Migration.js.map +1 -1
  5. package/dist/lib/getOptionalLinkProperties.cjs +14 -0
  6. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -0
  7. package/dist/lib/getOptionalLinkProperties.d.ts +12 -0
  8. package/dist/lib/getOptionalLinkProperties.js +14 -0
  9. package/dist/lib/getOptionalLinkProperties.js.map +1 -0
  10. package/dist/lib/isMigrationValue.cjs.map +1 -1
  11. package/dist/lib/isMigrationValue.d.ts +11 -2
  12. package/dist/lib/isMigrationValue.js.map +1 -1
  13. package/dist/lib/isValue.cjs.map +1 -1
  14. package/dist/lib/isValue.d.ts +7 -1
  15. package/dist/lib/isValue.js.map +1 -1
  16. package/dist/lib/resolveMigrationDocumentData.cjs +22 -11
  17. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  18. package/dist/lib/resolveMigrationDocumentData.d.ts +4 -2
  19. package/dist/lib/resolveMigrationDocumentData.js +22 -11
  20. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  21. package/dist/package.json.cjs +1 -1
  22. package/dist/package.json.js +1 -1
  23. package/dist/types/migration/Asset.cjs.map +1 -1
  24. package/dist/types/migration/Asset.d.ts +2 -3
  25. package/dist/types/migration/Asset.js.map +1 -1
  26. package/dist/types/migration/ContentRelationship.d.ts +3 -4
  27. package/dist/types/migration/Link.d.ts +19 -0
  28. package/dist/types/model/contentRelationship.d.ts +0 -1
  29. package/dist/types/model/linkToMedia.d.ts +1 -0
  30. package/dist/types/value/contentRelationship.d.ts +5 -5
  31. package/dist/types/value/link.cjs.map +1 -1
  32. package/dist/types/value/link.d.ts +39 -22
  33. package/dist/types/value/link.js.map +1 -1
  34. package/dist/types/value/linkToMedia.d.ts +9 -7
  35. package/dist/types/value/richText.cjs.map +1 -1
  36. package/dist/types/value/richText.d.ts +3 -5
  37. package/dist/types/value/richText.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/Migration.ts +8 -3
  40. package/src/lib/getOptionalLinkProperties.ts +27 -0
  41. package/src/lib/isMigrationValue.ts +11 -2
  42. package/src/lib/isValue.ts +7 -1
  43. package/src/lib/resolveMigrationDocumentData.ts +32 -13
  44. package/src/types/migration/Asset.ts +9 -11
  45. package/src/types/migration/ContentRelationship.ts +11 -9
  46. package/src/types/migration/Link.ts +19 -0
  47. package/src/types/model/contentRelationship.ts +0 -1
  48. package/src/types/model/linkToMedia.ts +1 -0
  49. package/src/types/value/contentRelationship.ts +6 -5
  50. package/src/types/value/link.ts +63 -33
  51. package/src/types/value/linkToMedia.ts +9 -9
  52. package/src/types/value/richText.ts +3 -11
@@ -6,25 +6,32 @@ const link = require("../types/value/link.cjs");
6
6
  const richText = require("../types/value/richText.cjs");
7
7
  const isFilled = require("../helpers/isFilled.cjs");
8
8
  const isMigrationValue = require("./isMigrationValue.cjs");
9
+ const getOptionalLinkProperties = require("./getOptionalLinkProperties.cjs");
9
10
  async function resolveMigrationContentRelationship(relation) {
10
11
  if (typeof relation === "function") {
11
12
  return resolveMigrationContentRelationship(await relation());
12
13
  }
13
14
  if (relation instanceof Document.PrismicMigrationDocument) {
14
- return relation.document.id ? { link_type: link.LinkType.Document, id: relation.document.id } : { link_type: link.LinkType.Document };
15
+ return relation.document.id ? { link_type: link.LinkType.Document, id: relation.document.id } : { link_type: link.LinkType.Any };
15
16
  }
17
+ const optionalLinkProperties = relation && "link_type" in relation ? getOptionalLinkProperties.getOptionalLinkProperties(relation) : void 0;
16
18
  if (relation) {
17
- if (isMigrationValue.contentRelationship(relation.id) || typeof relation.id === "function") {
19
+ if (isMigrationValue.contentRelationship(relation.id) || typeof relation.id !== "string") {
18
20
  return {
19
- ...await resolveMigrationContentRelationship(relation.id),
20
- // TODO: Remove when link text PR is merged
21
- // @ts-expect-error - Future-proofing for link text
22
- text: relation.text
21
+ ...optionalLinkProperties,
22
+ ...await resolveMigrationContentRelationship(relation.id)
23
23
  };
24
24
  }
25
- return { link_type: link.LinkType.Document, id: relation.id };
25
+ return {
26
+ ...optionalLinkProperties,
27
+ link_type: link.LinkType.Document,
28
+ id: relation.id
29
+ };
26
30
  }
27
- return { link_type: link.LinkType.Document };
31
+ return {
32
+ ...optionalLinkProperties,
33
+ link_type: link.LinkType.Any
34
+ };
28
35
  }
29
36
  const resolveMigrationImage = (image, migration, withThumbnails) => {
30
37
  var _a;
@@ -74,14 +81,18 @@ const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
74
81
  const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
75
82
  var _a;
76
83
  const asset = (_a = migration._assets.get(linkToMedia.id.config.id)) == null ? void 0 : _a.asset;
84
+ const optionalLinkProperties = getOptionalLinkProperties.getOptionalLinkProperties(linkToMedia);
77
85
  if (asset) {
78
86
  return {
87
+ ...optionalLinkProperties,
79
88
  id: asset.id,
80
- link_type: link.LinkType.Media,
81
- text: linkToMedia.text
89
+ link_type: link.LinkType.Media
82
90
  };
83
91
  }
84
- return { link_type: link.LinkType.Media };
92
+ return {
93
+ ...optionalLinkProperties,
94
+ link_type: link.LinkType.Any
95
+ };
85
96
  };
86
97
  async function resolveMigrationDocumentData(input, migration) {
87
98
  if (isMigrationValue.contentRelationship(input)) {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMigrationDocumentData.cjs","sources":["../../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MigrationContentRelationship,\n): Promise<MigrationContentRelationshipField> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Document }\n\t}\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id === \"function\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t\t// TODO: Remove when link text PR is merged\n\t\t\t\t// @ts-expect-error - Future-proofing for link text\n\t\t\t\ttext: relation.text,\n\t\t\t}\n\t\t}\n\n\t\treturn { link_type: LinkType.Document, id: relation.id }\n\t}\n\n\treturn { link_type: LinkType.Document }\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MigrationLinkToMedia,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\n\tif (asset) {\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t\ttext: linkToMedia.text,\n\t\t}\n\t}\n\n\treturn { link_type: LinkType.Media }\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"names":["PrismicMigrationDocument","LinkType","isMigration.contentRelationship","PrismicMigrationAsset","RichTextNodeType","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;;;AA8BA,eAAsB,oCACrB,UAAsC;AAElC,MAAA,OAAO,aAAa,YAAY;AAC5B,WAAA,oCAAoC,MAAM,SAAA,CAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoBA,SAAAA,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAWC,KAAS,SAAA,UAAU,IAAI,SAAS,SAAS,GAAI,IAC1D,EAAE,WAAWA,KAAAA,SAAS;EAC1B;AAEA,MAAI,UAAU;AAEZ,QAAAC,iBAAAA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,YACtB;AACM,aAAA;AAAA,QACN,GAAI,MAAM,oCAAoC,SAAS,EAAE;AAAA;AAAA;AAAA,QAGzD,MAAM,SAAS;AAAA,MAAA;AAAA,IAEjB;AAEA,WAAO,EAAE,WAAWD,cAAS,UAAU,IAAI,SAAS;EACrD;AAEO,SAAA,EAAE,WAAWA,cAAS;AAC9B;AAWO,MAAM,wBAAwB,CACpC,OACA,WACA,mBACsC;;AAChC,QAAA,EAAE,IAAI,QAAQ,GAAG,WACtB,IAAA,iBAAiBE,MAAAA,wBAAwB,EAAE,IAAI,MAAA,IAAU;AAE1D,QAAM,SAAQ,eAAU,QAAQ,IAAI,OAAO,OAAO,EAAE,MAAtC,mBAAyC;AACvD,QAAM,oBAAoB,OAAO;AAEjC,MAAI,OAAO;AACJ,UAAA,eAAc,uDAAmB,QAAO,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC;AACrE,UAAM,MAAM,GAAG,MAAM,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,IAAI,UAAU,KAAK,EAAE;AAC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B;AAGhB,MAAAC,iBAAAA,oBAAgC,KAAK,GAAG;AAC3C,WAAO,oCAAoC,KAAK;AAAA,EACjD;AAEI,MAAAI,iBAAAA,MAAkB,KAAK,GAAG;AACtB,WAAA,sBAAsB,OAAO,WAAW,IAAI;AAAA,EACpD;AAEI,MAAAC,iBAAAA,YAAwB,KAAK,GAAG;AAC5B,WAAA,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEI,MAAAC,iBAAAA,YAAwB,KAAK,GAAG;AAC5B,WAAA,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEI,MAAA,OAAO,UAAU,YAAY;AAChC,WAAO,MAAM,6BAA6B,MAAM,SAAS,SAAS;AAAA,EACnE;AAGI,MAAA,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,MAAM,CAAA;AAEZ,eAAW,WAAW,OAAO;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAChE;AAEO,WAAA,IAAI,OAAO,OAAO;AAAA,EAC1B;AAEI,MAAA,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAEX;AAEO,WAAA;AAAA,EACR;AAGO,SAAA;AACR;;;;;;"}
1
+ {"version":3,"file":"resolveMigrationDocumentData.cjs","sources":["../../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"names":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","isMigration.contentRelationship","PrismicMigrationAsset","RichTextNodeType","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;;;;AAgCA,eAAsB,oCACrB,UAAiD;AAE7C,MAAA,OAAO,aAAa,YAAY;AAC5B,WAAA,oCAAoC,MAAM,SAAA,CAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoBA,SAAAA,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAWC,KAAS,SAAA,UAAU,IAAI,SAAS,SAAS,GAAI,IAC1D,EAAE,WAAWA,KAAAA,SAAS;EAC1B;AAEA,QAAM,yBACL,YAAY,eAAe,WACxBC,0BAAAA,0BAA0B,QAAQ,IAClC;AAEJ,MAAI,UAAU;AAEZ,QAAAC,iBAAAA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,UACtB;AACM,aAAA;AAAA,QACN,GAAG;AAAA,QACH,GAAI,MAAM,oCAAoC,SAAS,EAAE;AAAA,MAAA;AAAA,IAE3D;AAKO,WAAA;AAAA,MACN,GAAG;AAAA,MACH,WAAWF,KAAS,SAAA;AAAA,MACpB,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf;AAEO,SAAA;AAAA,IACN,GAAG;AAAA,IACH,WAAWA,KAAS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AAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAEX;AAEO,WAAA;AAAA,EACR;AAGO,SAAA;AACR;;;;;;"}
@@ -1,7 +1,9 @@
1
1
  import type { MigrationLinkToMediaField } from "../types/migration/Asset";
2
2
  import { type MigrationImage, type MigrationLinkToMedia, type MigrationRTImageNode } from "../types/migration/Asset";
3
3
  import type { MigrationContentRelationship, MigrationContentRelationshipField } from "../types/migration/ContentRelationship";
4
+ import type { MaybeLink } from "../types/migration/Link";
4
5
  import type { FilledImageFieldImage } from "../types/value/image";
6
+ import type { OptionalLinkProperties } from "../types/value/link";
5
7
  import type { RTImageNode } from "../types/value/richText";
6
8
  import type { Migration } from "../Migration";
7
9
  /**
@@ -11,7 +13,7 @@ import type { Migration } from "../Migration";
11
13
  *
12
14
  * @returns Resolved content relationship field.
13
15
  */
14
- export declare function resolveMigrationContentRelationship(relation: MigrationContentRelationship): Promise<MigrationContentRelationshipField>;
16
+ export declare function resolveMigrationContentRelationship(relation: MaybeLink<MigrationContentRelationship>): Promise<MigrationContentRelationshipField & OptionalLinkProperties>;
15
17
  /**
16
18
  * Resolves a migration image to an image field.
17
19
  *
@@ -39,7 +41,7 @@ export declare const resolveMigrationRTImageNode: (rtImageNode: MigrationRTImage
39
41
  *
40
42
  * @returns Resolved link to media field.
41
43
  */
42
- export declare const resolveMigrationLinkToMedia: (linkToMedia: MigrationLinkToMedia, migration: Migration) => MigrationLinkToMediaField;
44
+ export declare const resolveMigrationLinkToMedia: (linkToMedia: MaybeLink<MigrationLinkToMedia>, migration: Migration) => MigrationLinkToMediaField;
43
45
  /**
44
46
  * Resolves a migration document data to actual data ready to be sent to the
45
47
  * Migration API.
@@ -4,25 +4,32 @@ import { LinkType } from "../types/value/link.js";
4
4
  import { RichTextNodeType } from "../types/value/richText.js";
5
5
  import { link } from "../helpers/isFilled.js";
6
6
  import { contentRelationship, image, linkToMedia, rtImageNode } from "./isMigrationValue.js";
7
+ import { getOptionalLinkProperties } from "./getOptionalLinkProperties.js";
7
8
  async function resolveMigrationContentRelationship(relation) {
8
9
  if (typeof relation === "function") {
9
10
  return resolveMigrationContentRelationship(await relation());
10
11
  }
11
12
  if (relation instanceof PrismicMigrationDocument) {
12
- return relation.document.id ? { link_type: LinkType.Document, id: relation.document.id } : { link_type: LinkType.Document };
13
+ return relation.document.id ? { link_type: LinkType.Document, id: relation.document.id } : { link_type: LinkType.Any };
13
14
  }
15
+ const optionalLinkProperties = relation && "link_type" in relation ? getOptionalLinkProperties(relation) : void 0;
14
16
  if (relation) {
15
- if (contentRelationship(relation.id) || typeof relation.id === "function") {
17
+ if (contentRelationship(relation.id) || typeof relation.id !== "string") {
16
18
  return {
17
- ...await resolveMigrationContentRelationship(relation.id),
18
- // TODO: Remove when link text PR is merged
19
- // @ts-expect-error - Future-proofing for link text
20
- text: relation.text
19
+ ...optionalLinkProperties,
20
+ ...await resolveMigrationContentRelationship(relation.id)
21
21
  };
22
22
  }
23
- return { link_type: LinkType.Document, id: relation.id };
23
+ return {
24
+ ...optionalLinkProperties,
25
+ link_type: LinkType.Document,
26
+ id: relation.id
27
+ };
24
28
  }
25
- return { link_type: LinkType.Document };
29
+ return {
30
+ ...optionalLinkProperties,
31
+ link_type: LinkType.Any
32
+ };
26
33
  }
27
34
  const resolveMigrationImage = (image2, migration, withThumbnails) => {
28
35
  var _a;
@@ -72,14 +79,18 @@ const resolveMigrationRTImageNode = async (rtImageNode2, migration) => {
72
79
  const resolveMigrationLinkToMedia = (linkToMedia2, migration) => {
73
80
  var _a;
74
81
  const asset = (_a = migration._assets.get(linkToMedia2.id.config.id)) == null ? void 0 : _a.asset;
82
+ const optionalLinkProperties = getOptionalLinkProperties(linkToMedia2);
75
83
  if (asset) {
76
84
  return {
85
+ ...optionalLinkProperties,
77
86
  id: asset.id,
78
- link_type: LinkType.Media,
79
- text: linkToMedia2.text
87
+ link_type: LinkType.Media
80
88
  };
81
89
  }
82
- return { link_type: LinkType.Media };
90
+ return {
91
+ ...optionalLinkProperties,
92
+ link_type: LinkType.Any
93
+ };
83
94
  };
84
95
  async function resolveMigrationDocumentData(input, migration) {
85
96
  if (contentRelationship(input)) {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMigrationDocumentData.js","sources":["../../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MigrationContentRelationship,\n): Promise<MigrationContentRelationshipField> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Document }\n\t}\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id === \"function\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t\t// TODO: Remove when link text PR is merged\n\t\t\t\t// @ts-expect-error - Future-proofing for link text\n\t\t\t\ttext: relation.text,\n\t\t\t}\n\t\t}\n\n\t\treturn { link_type: LinkType.Document, id: relation.id }\n\t}\n\n\treturn { link_type: LinkType.Document }\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MigrationLinkToMedia,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\n\tif (asset) {\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t\ttext: linkToMedia.text,\n\t\t}\n\t}\n\n\treturn { link_type: LinkType.Media }\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"names":["isMigration.contentRelationship","image","rtImageNode","isFilled.link","linkToMedia","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;AA8BA,eAAsB,oCACrB,UAAsC;AAElC,MAAA,OAAO,aAAa,YAAY;AAC5B,WAAA,oCAAoC,MAAM,SAAA,CAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoB,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAW,SAAS,UAAU,IAAI,SAAS,SAAS,GAAI,IAC1D,EAAE,WAAW,SAAS;EAC1B;AAEA,MAAI,UAAU;AAEZ,QAAAA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,YACtB;AACM,aAAA;AAAA,QACN,GAAI,MAAM,oCAAoC,SAAS,EAAE;AAAA;AAAA;AAAA,QAGzD,MAAM,SAAS;AAAA,MAAA;AAAA,IAEjB;AAEA,WAAO,EAAE,WAAW,SAAS,UAAU,IAAI,SAAS;EACrD;AAEO,SAAA,EAAE,WAAW,SAAS;AAC9B;AAWO,MAAM,wBAAwB,CACpCC,QACA,WACA,mBACs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veMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"names":["isMigration.contentRelationship","image","rtImageNode","isFilled.link","linkToMedia","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;;AAgCA,eAAsB,oCACrB,UAAiD;AAE7C,MAAA,OAAO,aAAa,YAAY;AAC5B,WAAA,oCAAoC,MAAM,SAAA,CAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoB,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAW,SAAS,UAAU,IAAI,SAAS,SAAS,GAAI,IAC1D,EAAE,WAAW,SAAS;EAC1B;AAEA,QAAM,yBACL,YAAY,eAAe,WACxB,0BAA0B,QAAQ,IAClC;AAEJ,MAAI,UAAU;AAEZ,QAAAA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,UACtB;AACM,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;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAChE;AAEO,WAAA,IAAI,OAAO,OAAO;AAAA,EAC1B;AAEI,MAAA,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAEX;AAEO,WAAA;AAAA,EACR;AAGO,SAAA;AACR;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "7.14.0-alpha.1";
3
+ const version = "7.14.0-alpha.2";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.json.cjs.map
@@ -1,4 +1,4 @@
1
- const version = "7.14.0-alpha.1";
1
+ const version = "7.14.0-alpha.2";
2
2
  export {
3
3
  version
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Asset.cjs","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { EmptyLinkField } from \"../value/link\"\nimport type { LinkToMediaField } from \"../value/linkToMedia\"\nimport { type RTImageNode } from \"../value/richText\"\n\nimport type { InjectMigrationSpecificTypes } from \"./Document\"\n\n/**\n * An asset to be uploaded to Prismic media library.\n */\nexport type MigrationAssetConfig = {\n\t/**\n\t * ID the assets is indexed with on the migration instance.\n\t *\n\t * @remarks\n\t * This property's value is not necessarily the same as the as the one in the\n\t * `file` property. It is mainly used for deduplication within a `Migration`\n\t * instance.\n\t */\n\tid: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * File to be uploaded as an asset.\n\t */\n\tfile: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * Filename of the asset.\n\t */\n\tfilename: string\n\n\t/**\n\t * Notes about the asset. Notes are private and only visible in Prismic media\n\t * library.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Credits and copyright for the asset if any.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Alternate text for the asset.\n\t */\n\talt?: string\n\n\t/**\n\t * Tags associated with the asset.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t */\n\ttags?: string[]\n}\n\n/**\n * An image field in a migration.\n */\nexport type MigrationImage =\n\t| PrismicMigrationAsset\n\t| ({\n\t\t\t/**\n\t\t\t * A reference to the migration asset used to resolve the image field's\n\t\t\t * value.\n\t\t\t */\n\t\t\tid: PrismicMigrationAsset\n\t } & Record<string, PrismicMigrationAsset>)\n\n/**\n * A link to media field in a migration.\n */\nexport type MigrationLinkToMedia = Pick<\n\tLinkToMediaField<\"filled\">,\n\t\"link_type\"\n> &\n\tPartial<Pick<LinkToMediaField<\"filled\">, \"text\">> & {\n\t\t/**\n\t\t * A reference to the migration asset used to resolve the link to media\n\t\t * field's value.\n\t\t */\n\t\tid: PrismicMigrationAsset\n\t}\n\n/**\n * The minimum amount of information needed to represent a link to media field\n * with the migration API.\n */\nexport type MigrationLinkToMediaField =\n\t| Pick<LinkToMediaField<\"filled\">, \"link_type\" | \"id\" | \"text\">\n\t| EmptyLinkField<\"Media\">\n\n/**\n * A rich text image node in a migration.\n */\nexport type MigrationRTImageNode = InjectMigrationSpecificTypes<\n\tPick<RTImageNode, \"type\" | \"linkTo\">\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the rich text image\n\t * node's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * A migration asset used with the Prismic Migration API.\n */\nexport class PrismicMigrationAsset {\n\t/**\n\t * Asset object from Prismic, available once created.\n\t */\n\tasset?: Asset\n\n\t/**\n\t * Configuration of the asset.\n\t */\n\tconfig: MigrationAssetConfig\n\n\t/**\n\t * The initial field value this migration field was created with.\n\t */\n\toriginalField?:\n\t\t| FilledImageFieldImage\n\t\t| LinkToMediaField<\"filled\">\n\t\t| RTImageNode\n\n\t/**\n\t * Creates a migration asset used with the Prismic Migration API.\n\t *\n\t * @param config - Configuration of the asset.\n\t * @param initialField - The initial field value if any.\n\t *\n\t * @returns A migration asset instance.\n\t */\n\tconstructor(\n\t\tconfig: MigrationAssetConfig,\n\t\tinitialField?:\n\t\t\t| FilledImageFieldImage\n\t\t\t| LinkToMediaField<\"filled\">\n\t\t\t| RTImageNode,\n\t) {\n\t\tthis.config = config\n\t\tthis.originalField = initialField\n\t}\n}\n"],"names":[],"mappings":";;;;;MA6Ga,sBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjC,YACC,QACA,cAGc;AA5Bf;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAoBC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACtB;AACA;;"}
1
+ {"version":3,"file":"Asset.cjs","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { LinkToMediaField } from \"../value/linkToMedia\"\nimport { type RTImageNode } from \"../value/richText\"\n\nimport type { InjectMigrationSpecificTypes } from \"./Document\"\n\n/**\n * An asset to be uploaded to Prismic media library.\n */\nexport type MigrationAssetConfig = {\n\t/**\n\t * ID the assets is indexed with on the migration instance.\n\t *\n\t * @remarks\n\t * This property's value is not necessarily the same as the as the one in the\n\t * `file` property. It is mainly used for deduplication within a `Migration`\n\t * instance.\n\t */\n\tid: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * File to be uploaded as an asset.\n\t */\n\tfile: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * Filename of the asset.\n\t */\n\tfilename: string\n\n\t/**\n\t * Notes about the asset. Notes are private and only visible in Prismic media\n\t * library.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Credits and copyright for the asset if any.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Alternate text for the asset.\n\t */\n\talt?: string\n\n\t/**\n\t * Tags associated with the asset.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t */\n\ttags?: string[]\n}\n\n/**\n * An image field in a migration.\n */\nexport type MigrationImage =\n\t| PrismicMigrationAsset\n\t| ({\n\t\t\t/**\n\t\t\t * A reference to the migration asset used to resolve the image field's\n\t\t\t * value.\n\t\t\t */\n\t\t\tid: PrismicMigrationAsset\n\t } & Record<string, PrismicMigrationAsset>)\n\n/**\n * A link to media field in a migration.\n */\nexport type MigrationLinkToMedia = Pick<\n\tLinkToMediaField<\"filled\">,\n\t\"link_type\" | \"text\"\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the link to media\n\t * field's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * The minimum amount of information needed to represent a link to media field\n * with the migration API.\n */\nexport type MigrationLinkToMediaField =\n\t| Pick<LinkToMediaField<\"filled\">, \"link_type\" | \"id\" | \"text\">\n\t| LinkToMediaField<\"empty\">\n\n/**\n * A rich text image node in a migration.\n */\nexport type MigrationRTImageNode = InjectMigrationSpecificTypes<\n\tPick<RTImageNode, \"type\" | \"linkTo\">\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the rich text image\n\t * node's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * A migration asset used with the Prismic Migration API.\n */\nexport class PrismicMigrationAsset {\n\t/**\n\t * Asset object from Prismic, available once created.\n\t */\n\tasset?: Asset\n\n\t/**\n\t * Configuration of the asset.\n\t */\n\tconfig: MigrationAssetConfig\n\n\t/**\n\t * The initial field value this migration field was created with.\n\t */\n\toriginalField?:\n\t\t| FilledImageFieldImage\n\t\t| LinkToMediaField<\"filled\">\n\t\t| RTImageNode\n\n\t/**\n\t * Creates a migration asset used with the Prismic Migration API.\n\t *\n\t * @param config - Configuration of the asset.\n\t * @param initialField - The initial field value if any.\n\t *\n\t * @returns A migration asset instance.\n\t */\n\tconstructor(\n\t\tconfig: MigrationAssetConfig,\n\t\tinitialField?:\n\t\t\t| FilledImageFieldImage\n\t\t\t| LinkToMediaField<\"filled\">\n\t\t\t| RTImageNode,\n\t) {\n\t\tthis.config = config\n\t\tthis.originalField = initialField\n\t}\n}\n"],"names":[],"mappings":";;;;;MA2Ga,sBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjC,YACC,QACA,cAGc;AA5Bf;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAoBC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACtB;AACA;;"}
@@ -1,6 +1,5 @@
1
1
  import type { Asset } from "../api/asset/asset";
2
2
  import type { FilledImageFieldImage } from "../value/image";
3
- import type { EmptyLinkField } from "../value/link";
4
3
  import type { LinkToMediaField } from "../value/linkToMedia";
5
4
  import { type RTImageNode } from "../value/richText";
6
5
  import type { InjectMigrationSpecificTypes } from "./Document";
@@ -59,7 +58,7 @@ export type MigrationImage = PrismicMigrationAsset | ({
59
58
  /**
60
59
  * A link to media field in a migration.
61
60
  */
62
- export type MigrationLinkToMedia = Pick<LinkToMediaField<"filled">, "link_type"> & Partial<Pick<LinkToMediaField<"filled">, "text">> & {
61
+ export type MigrationLinkToMedia = Pick<LinkToMediaField<"filled">, "link_type" | "text"> & {
63
62
  /**
64
63
  * A reference to the migration asset used to resolve the link to media
65
64
  * field's value.
@@ -70,7 +69,7 @@ export type MigrationLinkToMedia = Pick<LinkToMediaField<"filled">, "link_type">
70
69
  * The minimum amount of information needed to represent a link to media field
71
70
  * with the migration API.
72
71
  */
73
- export type MigrationLinkToMediaField = Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text"> | EmptyLinkField<"Media">;
72
+ export type MigrationLinkToMediaField = Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text"> | LinkToMediaField<"empty">;
74
73
  /**
75
74
  * A rich text image node in a migration.
76
75
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Asset.js","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { EmptyLinkField } from \"../value/link\"\nimport type { LinkToMediaField } from \"../value/linkToMedia\"\nimport { type RTImageNode } from \"../value/richText\"\n\nimport type { InjectMigrationSpecificTypes } from \"./Document\"\n\n/**\n * An asset to be uploaded to Prismic media library.\n */\nexport type MigrationAssetConfig = {\n\t/**\n\t * ID the assets is indexed with on the migration instance.\n\t *\n\t * @remarks\n\t * This property's value is not necessarily the same as the as the one in the\n\t * `file` property. It is mainly used for deduplication within a `Migration`\n\t * instance.\n\t */\n\tid: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * File to be uploaded as an asset.\n\t */\n\tfile: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * Filename of the asset.\n\t */\n\tfilename: string\n\n\t/**\n\t * Notes about the asset. Notes are private and only visible in Prismic media\n\t * library.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Credits and copyright for the asset if any.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Alternate text for the asset.\n\t */\n\talt?: string\n\n\t/**\n\t * Tags associated with the asset.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t */\n\ttags?: string[]\n}\n\n/**\n * An image field in a migration.\n */\nexport type MigrationImage =\n\t| PrismicMigrationAsset\n\t| ({\n\t\t\t/**\n\t\t\t * A reference to the migration asset used to resolve the image field's\n\t\t\t * value.\n\t\t\t */\n\t\t\tid: PrismicMigrationAsset\n\t } & Record<string, PrismicMigrationAsset>)\n\n/**\n * A link to media field in a migration.\n */\nexport type MigrationLinkToMedia = Pick<\n\tLinkToMediaField<\"filled\">,\n\t\"link_type\"\n> &\n\tPartial<Pick<LinkToMediaField<\"filled\">, \"text\">> & {\n\t\t/**\n\t\t * A reference to the migration asset used to resolve the link to media\n\t\t * field's value.\n\t\t */\n\t\tid: PrismicMigrationAsset\n\t}\n\n/**\n * The minimum amount of information needed to represent a link to media field\n * with the migration API.\n */\nexport type MigrationLinkToMediaField =\n\t| Pick<LinkToMediaField<\"filled\">, \"link_type\" | \"id\" | \"text\">\n\t| EmptyLinkField<\"Media\">\n\n/**\n * A rich text image node in a migration.\n */\nexport type MigrationRTImageNode = InjectMigrationSpecificTypes<\n\tPick<RTImageNode, \"type\" | \"linkTo\">\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the rich text image\n\t * node's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * A migration asset used with the Prismic Migration API.\n */\nexport class PrismicMigrationAsset {\n\t/**\n\t * Asset object from Prismic, available once created.\n\t */\n\tasset?: Asset\n\n\t/**\n\t * Configuration of the asset.\n\t */\n\tconfig: MigrationAssetConfig\n\n\t/**\n\t * The initial field value this migration field was created with.\n\t */\n\toriginalField?:\n\t\t| FilledImageFieldImage\n\t\t| LinkToMediaField<\"filled\">\n\t\t| RTImageNode\n\n\t/**\n\t * Creates a migration asset used with the Prismic Migration API.\n\t *\n\t * @param config - Configuration of the asset.\n\t * @param initialField - The initial field value if any.\n\t *\n\t * @returns A migration asset instance.\n\t */\n\tconstructor(\n\t\tconfig: MigrationAssetConfig,\n\t\tinitialField?:\n\t\t\t| FilledImageFieldImage\n\t\t\t| LinkToMediaField<\"filled\">\n\t\t\t| RTImageNode,\n\t) {\n\t\tthis.config = config\n\t\tthis.originalField = initialField\n\t}\n}\n"],"names":[],"mappings":";;;MA6Ga,sBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjC,YACC,QACA,cAGc;AA5Bf;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAoBC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACtB;AACA;"}
1
+ {"version":3,"file":"Asset.js","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { LinkToMediaField } from \"../value/linkToMedia\"\nimport { type RTImageNode } from \"../value/richText\"\n\nimport type { InjectMigrationSpecificTypes } from \"./Document\"\n\n/**\n * An asset to be uploaded to Prismic media library.\n */\nexport type MigrationAssetConfig = {\n\t/**\n\t * ID the assets is indexed with on the migration instance.\n\t *\n\t * @remarks\n\t * This property's value is not necessarily the same as the as the one in the\n\t * `file` property. It is mainly used for deduplication within a `Migration`\n\t * instance.\n\t */\n\tid: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * File to be uploaded as an asset.\n\t */\n\tfile: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * Filename of the asset.\n\t */\n\tfilename: string\n\n\t/**\n\t * Notes about the asset. Notes are private and only visible in Prismic media\n\t * library.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Credits and copyright for the asset if any.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Alternate text for the asset.\n\t */\n\talt?: string\n\n\t/**\n\t * Tags associated with the asset.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t */\n\ttags?: string[]\n}\n\n/**\n * An image field in a migration.\n */\nexport type MigrationImage =\n\t| PrismicMigrationAsset\n\t| ({\n\t\t\t/**\n\t\t\t * A reference to the migration asset used to resolve the image field's\n\t\t\t * value.\n\t\t\t */\n\t\t\tid: PrismicMigrationAsset\n\t } & Record<string, PrismicMigrationAsset>)\n\n/**\n * A link to media field in a migration.\n */\nexport type MigrationLinkToMedia = Pick<\n\tLinkToMediaField<\"filled\">,\n\t\"link_type\" | \"text\"\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the link to media\n\t * field's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * The minimum amount of information needed to represent a link to media field\n * with the migration API.\n */\nexport type MigrationLinkToMediaField =\n\t| Pick<LinkToMediaField<\"filled\">, \"link_type\" | \"id\" | \"text\">\n\t| LinkToMediaField<\"empty\">\n\n/**\n * A rich text image node in a migration.\n */\nexport type MigrationRTImageNode = InjectMigrationSpecificTypes<\n\tPick<RTImageNode, \"type\" | \"linkTo\">\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the rich text image\n\t * node's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * A migration asset used with the Prismic Migration API.\n */\nexport class PrismicMigrationAsset {\n\t/**\n\t * Asset object from Prismic, available once created.\n\t */\n\tasset?: Asset\n\n\t/**\n\t * Configuration of the asset.\n\t */\n\tconfig: MigrationAssetConfig\n\n\t/**\n\t * The initial field value this migration field was created with.\n\t */\n\toriginalField?:\n\t\t| FilledImageFieldImage\n\t\t| LinkToMediaField<\"filled\">\n\t\t| RTImageNode\n\n\t/**\n\t * Creates a migration asset used with the Prismic Migration API.\n\t *\n\t * @param config - Configuration of the asset.\n\t * @param initialField - The initial field value if any.\n\t *\n\t * @returns A migration asset instance.\n\t */\n\tconstructor(\n\t\tconfig: MigrationAssetConfig,\n\t\tinitialField?:\n\t\t\t| FilledImageFieldImage\n\t\t\t| LinkToMediaField<\"filled\">\n\t\t\t| RTImageNode,\n\t) {\n\t\tthis.config = config\n\t\tthis.originalField = initialField\n\t}\n}\n"],"names":[],"mappings":";;;MA2Ga,sBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjC,YACC,QACA,cAGc;AA5Bf;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAoBC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACtB;AACA;"}
@@ -1,17 +1,16 @@
1
- import type { FilledContentRelationshipField } from "../value/contentRelationship";
1
+ import type { ContentRelationshipField, EmptyContentRelationshipField, FilledContentRelationshipField } from "../value/contentRelationship";
2
2
  import type { PrismicDocument } from "../value/document";
3
- import type { EmptyLinkField } from "../value/link";
4
3
  import type { PrismicMigrationDocument } from "./Document";
5
4
  type ValueOrThunk<T> = T | (() => Promise<T> | T);
6
5
  /**
7
6
  * A content relationship field in a migration.
8
7
  */
9
- export type MigrationContentRelationship<TDocuments extends PrismicDocument = PrismicDocument> = ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined> | (Pick<FilledContentRelationshipField, "link_type"> & Partial<Pick<FilledContentRelationshipField, "text">> & {
8
+ export type MigrationContentRelationship<TDocuments extends PrismicDocument = PrismicDocument> = ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined> | (Pick<ContentRelationshipField, "link_type"> & {
10
9
  id: ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>;
11
10
  });
12
11
  /**
13
12
  * The minimum amount of information needed to represent a content relationship
14
13
  * field with the migration API.
15
14
  */
16
- export type MigrationContentRelationshipField = Pick<FilledContentRelationshipField, "link_type" | "id"> | EmptyLinkField<"Document">;
15
+ export type MigrationContentRelationshipField = Pick<FilledContentRelationshipField, "link_type" | "id"> | EmptyContentRelationshipField;
17
16
  export {};
@@ -0,0 +1,19 @@
1
+ import type { LinkType, OptionalLinkProperties } from "../value/link";
2
+ /**
3
+ * Adds `OptionalLinkProperties` to any type that looks like a link object (one
4
+ * that includes a valid `link_type` property).
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * type Example = MaybeLink<PrismicDocument | LinkField>
10
+ * // PrismicDocument | (LinkField & OptionalLinkProperties)
11
+ * ```
12
+ *
13
+ * @typeParam T - The type to augment.
14
+ */
15
+ export type MaybeLink<T> = Exclude<T, {
16
+ link_type: (typeof LinkType)[keyof typeof LinkType];
17
+ }> | (Extract<T, {
18
+ link_type: (typeof LinkType)[keyof typeof LinkType];
19
+ }> & OptionalLinkProperties);
@@ -13,6 +13,5 @@ export interface CustomTypeModelContentRelationshipField<CustomTypeIDs extends s
13
13
  select: typeof CustomTypeModelLinkSelectType.Document;
14
14
  customtypes?: readonly CustomTypeIDs[];
15
15
  tags?: readonly Tags[];
16
- allowText?: boolean;
17
16
  };
18
17
  }
@@ -12,5 +12,6 @@ export interface CustomTypeModelLinkToMediaField {
12
12
  placeholder?: string;
13
13
  select: typeof CustomTypeModelLinkSelectType.Media;
14
14
  allowText?: boolean;
15
+ variants?: string[];
15
16
  };
16
17
  }
@@ -1,6 +1,5 @@
1
1
  import type { AnyRegularField, FieldState } from "./types";
2
2
  import type { GroupField } from "./group";
3
- import type { EmptyLinkField, LinkType } from "./link";
4
3
  import type { SliceZone } from "./sliceZone";
5
4
  /**
6
5
  * Field for related documents
@@ -11,12 +10,15 @@ import type { SliceZone } from "./sliceZone";
11
10
  * GraphQuery of `fetchLinks`).
12
11
  * @typeParam State - State of the field which determines its shape.
13
12
  */
14
- export type ContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Document> : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
13
+ export type ContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyContentRelationshipField : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
14
+ export type EmptyContentRelationshipField = {
15
+ link_type: "Any";
16
+ };
15
17
  /**
16
18
  * Links that refer to documents
17
19
  */
18
20
  export interface FilledContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown> {
19
- link_type: typeof LinkType.Document;
21
+ link_type: "Document";
20
22
  id: string;
21
23
  uid?: string;
22
24
  type: TypeEnum;
@@ -26,6 +28,4 @@ export interface FilledContentRelationshipField<TypeEnum = string, LangEnum = st
26
28
  slug?: string;
27
29
  isBroken?: boolean;
28
30
  data?: DataInterface;
29
- text?: string;
30
- variant?: string;
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"link.cjs","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { ContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { LinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * For link fields that haven't been filled\n *\n * @typeParam Type - The type of link.\n */\nexport type EmptyLinkField<\n\tType extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: Type | string\n\ttext?: string\n\tvariant?: string\n}\n\n/**\n * Link that points to external website\n */\nexport interface FilledLinkToWebField {\n\tlink_type: typeof LinkType.Web\n\turl: string\n\ttarget?: string\n\ttext?: string\n\tvariant?: string\n}\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled in via\n * GraphQuery of `fetchLinks`).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField<typeof LinkType.Any>\n\t:\n\t\t\t| ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| LinkToMediaField<State>\n"],"names":[],"mappings":";;AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;;"}
1
+ {"version":3,"file":"link.cjs","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { FilledLinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled via the\n * `fetchLinks` or `graphQuery` query parameter).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField\n\t: FilledLinkField<TypeEnum, LangEnum, DataInterface>\n\n/**\n * A link field that is filled.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled via the\n * `fetchLinks` or `graphQuery` query parameter).\n */\nexport type FilledLinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n> = (\n\t| FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>\n\t| FilledLinkToMediaField\n\t| FilledLinkToWebField\n) &\n\tOptionalLinkProperties\n\n/**\n * A link field that is not filled.\n *\n * @typeParam _Unused - THIS PARAMETER IS NOT USED. If you are passing a type,\n * **please remove it**.\n */\nexport type EmptyLinkField<\n\t_Unused extends\n\t\t(typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: \"Any\"\n} & OptionalLinkProperties\n\n/**\n * A link field pointing to a relative or absolute URL.\n */\nexport type FilledLinkToWebField = {\n\tlink_type: \"Web\"\n\turl: string\n\ttarget?: string\n} & OptionalLinkProperties\n\n/**\n * Optional properties available to link fields. It is used to augment existing\n * link-like fields (like content relationship fields) with field-specific\n * properties.\n *\n * @internal\n */\n// Remember to update the `getOptionalLinkProperties()` function when updating\n// this type. The function should check for every property.\nexport type OptionalLinkProperties = {\n\ttext?: string\n\tvariant?: string\n}\n"],"names":[],"mappings":";;AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;;"}
@@ -1,7 +1,7 @@
1
1
  import type { AnyRegularField, FieldState } from "./types";
2
- import type { ContentRelationshipField } from "./contentRelationship";
2
+ import type { FilledContentRelationshipField } from "./contentRelationship";
3
3
  import type { GroupField } from "./group";
4
- import type { LinkToMediaField } from "./linkToMedia";
4
+ import type { FilledLinkToMediaField } from "./linkToMedia";
5
5
  import type { SliceZone } from "./sliceZone";
6
6
  /**
7
7
  * Link types
@@ -13,32 +13,49 @@ export declare const LinkType: {
13
13
  readonly Web: "Web";
14
14
  };
15
15
  /**
16
- * For link fields that haven't been filled
16
+ * A link field.
17
17
  *
18
- * @typeParam Type - The type of link.
18
+ * @typeParam TypeEnum - Type API ID of the document.
19
+ * @typeParam LangEnum - Language API ID of the document.
20
+ * @typeParam DataInterface - Data fields for the document (filled via the
21
+ * `fetchLinks` or `graphQuery` query parameter).
22
+ * @typeParam State - State of the field which determines its shape.
19
23
  */
20
- export type EmptyLinkField<Type extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any> = {
21
- link_type: Type | string;
22
- text?: string;
23
- variant?: string;
24
- };
24
+ export type LinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField : FilledLinkField<TypeEnum, LangEnum, DataInterface>;
25
+ /**
26
+ * A link field that is filled.
27
+ *
28
+ * @typeParam TypeEnum - Type API ID of the document.
29
+ * @typeParam LangEnum - Language API ID of the document.
30
+ * @typeParam DataInterface - Data fields for the document (filled via the
31
+ * `fetchLinks` or `graphQuery` query parameter).
32
+ */
33
+ export type FilledLinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown> = (FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface> | FilledLinkToMediaField | FilledLinkToWebField) & OptionalLinkProperties;
25
34
  /**
26
- * Link that points to external website
35
+ * A link field that is not filled.
36
+ *
37
+ * @typeParam _Unused - THIS PARAMETER IS NOT USED. If you are passing a type,
38
+ * **please remove it**.
39
+ */
40
+ export type EmptyLinkField<_Unused extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any> = {
41
+ link_type: "Any";
42
+ } & OptionalLinkProperties;
43
+ /**
44
+ * A link field pointing to a relative or absolute URL.
27
45
  */
28
- export interface FilledLinkToWebField {
29
- link_type: typeof LinkType.Web;
46
+ export type FilledLinkToWebField = {
47
+ link_type: "Web";
30
48
  url: string;
31
49
  target?: string;
32
- text?: string;
33
- variant?: string;
34
- }
50
+ } & OptionalLinkProperties;
35
51
  /**
36
- * A link field.
52
+ * Optional properties available to link fields. It is used to augment existing
53
+ * link-like fields (like content relationship fields) with field-specific
54
+ * properties.
37
55
  *
38
- * @typeParam TypeEnum - Type API ID of the document.
39
- * @typeParam LangEnum - Language API ID of the document.
40
- * @typeParam DataInterface - Data fields for the document (filled in via
41
- * GraphQuery of `fetchLinks`).
42
- * @typeParam State - State of the field which determines its shape.
56
+ * @internal
43
57
  */
44
- export type LinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Any> : ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State> | FilledLinkToWebField | LinkToMediaField<State>;
58
+ export type OptionalLinkProperties = {
59
+ text?: string;
60
+ variant?: string;
61
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"link.js","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { ContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { LinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * For link fields that haven't been filled\n *\n * @typeParam Type - The type of link.\n */\nexport type EmptyLinkField<\n\tType extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: Type | string\n\ttext?: string\n\tvariant?: string\n}\n\n/**\n * Link that points to external website\n */\nexport interface FilledLinkToWebField {\n\tlink_type: typeof LinkType.Web\n\turl: string\n\ttarget?: string\n\ttext?: string\n\tvariant?: string\n}\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled in via\n * GraphQuery of `fetchLinks`).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField<typeof LinkType.Any>\n\t:\n\t\t\t| ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| LinkToMediaField<State>\n"],"names":[],"mappings":"AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;"}
1
+ {"version":3,"file":"link.js","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { FilledLinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled via the\n * `fetchLinks` or `graphQuery` query parameter).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField\n\t: FilledLinkField<TypeEnum, LangEnum, DataInterface>\n\n/**\n * A link field that is filled.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled via the\n * `fetchLinks` or `graphQuery` query parameter).\n */\nexport type FilledLinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n> = (\n\t| FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>\n\t| FilledLinkToMediaField\n\t| FilledLinkToWebField\n) &\n\tOptionalLinkProperties\n\n/**\n * A link field that is not filled.\n *\n * @typeParam _Unused - THIS PARAMETER IS NOT USED. If you are passing a type,\n * **please remove it**.\n */\nexport type EmptyLinkField<\n\t_Unused extends\n\t\t(typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: \"Any\"\n} & OptionalLinkProperties\n\n/**\n * A link field pointing to a relative or absolute URL.\n */\nexport type FilledLinkToWebField = {\n\tlink_type: \"Web\"\n\turl: string\n\ttarget?: string\n} & OptionalLinkProperties\n\n/**\n * Optional properties available to link fields. It is used to augment existing\n * link-like fields (like content relationship fields) with field-specific\n * properties.\n *\n * @internal\n */\n// Remember to update the `getOptionalLinkProperties()` function when updating\n// this type. The function should check for every property.\nexport type OptionalLinkProperties = {\n\ttext?: string\n\tvariant?: string\n}\n"],"names":[],"mappings":"AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;"}
@@ -1,23 +1,25 @@
1
1
  import type { FieldState } from "./types";
2
- import type { EmptyLinkField, LinkType } from "./link";
2
+ import type { OptionalLinkProperties } from "./link";
3
3
  /**
4
4
  * A link field that points to media.
5
5
  *
6
6
  * @typeParam State - State of the field which determines its shape.
7
7
  */
8
- export type LinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Media> : FilledLinkToMediaField;
8
+ export type LinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkToMediaField : FilledLinkToMediaField;
9
+ type EmptyLinkToMediaField = {
10
+ link_type: "Any";
11
+ } & OptionalLinkProperties;
9
12
  /**
10
13
  * A link that points to media.
11
14
  */
12
- export interface FilledLinkToMediaField {
15
+ export type FilledLinkToMediaField = {
13
16
  id: string;
14
- link_type: typeof LinkType.Media;
17
+ link_type: "Media";
15
18
  name: string;
16
19
  kind: string;
17
20
  url: string;
18
21
  size: string;
19
22
  height?: string | null;
20
23
  width?: string | null;
21
- text?: string;
22
- variant?: string;
23
- }
24
+ } & OptionalLinkProperties;
25
+ export {};